1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
7 #include <linux/mod_devicetable.h>
8 #include <linux/module.h>
9 #include <linux/skbuff.h>
15 struct qrtr_endpoint ep;
16 struct mhi_device *mhi_dev;
20 /* From MHI to QRTR */
21 static void qcom_mhi_qrtr_dl_callback(struct mhi_device *mhi_dev,
22 struct mhi_result *mhi_res)
24 struct qrtr_mhi_dev *qdev = dev_get_drvdata(&mhi_dev->dev);
27 if (!qdev || mhi_res->transaction_status)
30 rc = qrtr_endpoint_post(&qdev->ep, mhi_res->buf_addr,
31 mhi_res->bytes_xferd);
33 dev_err(qdev->dev, "invalid ipcrouter packet\n");
36 /* From QRTR to MHI */
37 static void qcom_mhi_qrtr_ul_callback(struct mhi_device *mhi_dev,
38 struct mhi_result *mhi_res)
40 struct sk_buff *skb = mhi_res->buf_addr;
47 /* Send data over MHI */
48 static int qcom_mhi_qrtr_send(struct qrtr_endpoint *ep, struct sk_buff *skb)
50 struct qrtr_mhi_dev *qdev = container_of(ep, struct qrtr_mhi_dev, ep);
56 rc = skb_linearize(skb);
60 rc = mhi_queue_skb(qdev->mhi_dev, DMA_TO_DEVICE, skb, skb->len,
75 static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,
76 const struct mhi_device_id *id)
78 struct qrtr_mhi_dev *qdev;
81 qdev = devm_kzalloc(&mhi_dev->dev, sizeof(*qdev), GFP_KERNEL);
85 qdev->mhi_dev = mhi_dev;
86 qdev->dev = &mhi_dev->dev;
87 qdev->ep.xmit = qcom_mhi_qrtr_send;
89 dev_set_drvdata(&mhi_dev->dev, qdev);
90 rc = qrtr_endpoint_register(&qdev->ep, QRTR_EP_NID_AUTO);
95 rc = mhi_prepare_for_transfer_autoqueue(mhi_dev);
97 qrtr_endpoint_unregister(&qdev->ep);
101 dev_dbg(qdev->dev, "Qualcomm MHI QRTR driver probed\n");
106 static void qcom_mhi_qrtr_remove(struct mhi_device *mhi_dev)
108 struct qrtr_mhi_dev *qdev = dev_get_drvdata(&mhi_dev->dev);
110 qrtr_endpoint_unregister(&qdev->ep);
111 mhi_unprepare_from_transfer(mhi_dev);
112 dev_set_drvdata(&mhi_dev->dev, NULL);
115 static const struct mhi_device_id qcom_mhi_qrtr_id_table[] = {
119 MODULE_DEVICE_TABLE(mhi, qcom_mhi_qrtr_id_table);
121 static struct mhi_driver qcom_mhi_qrtr_driver = {
122 .probe = qcom_mhi_qrtr_probe,
123 .remove = qcom_mhi_qrtr_remove,
124 .dl_xfer_cb = qcom_mhi_qrtr_dl_callback,
125 .ul_xfer_cb = qcom_mhi_qrtr_ul_callback,
126 .id_table = qcom_mhi_qrtr_id_table,
128 .name = "qcom_mhi_qrtr",
132 module_mhi_driver(qcom_mhi_qrtr_driver);
134 MODULE_AUTHOR("Chris Lew <clew@codeaurora.org>");
135 MODULE_AUTHOR("Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>");
136 MODULE_DESCRIPTION("Qualcomm IPC-Router MHI interface driver");
137 MODULE_LICENSE("GPL v2");