]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/bluetooth/btqcomsmd.c
drivers: bluetooth: fix btqcomsmd driver compatible name
[karo-tx-linux.git] / drivers / bluetooth / btqcomsmd.c
1 /*
2  * Copyright (c) 2016, Linaro Ltd.
3  * Copyright (c) 2015, Sony Mobile Communications Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 and
7  * only version 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/soc/qcom/smd.h>
18 #include <linux/soc/qcom/wcnss_ctrl.h>
19 #include <linux/platform_device.h>
20 #include <net/bluetooth/bluetooth.h>
21 #include <net/bluetooth/hci_core.h>
22 #include <net/bluetooth/hci.h>
23 #include "btqca.h"
24
25 struct btqcomsmd {
26         struct hci_dev *hdev;
27
28         struct qcom_smd_channel *acl_channel;
29         struct qcom_smd_channel *cmd_channel;
30 };
31
32 static int btqcomsmd_recv(struct hci_dev *hdev, unsigned type, const void *data,
33                           size_t count)
34 {
35         struct sk_buff *skb;
36
37         /* Use GFP_ATOMIC as we're in IRQ context */
38         skb = bt_skb_alloc(count, GFP_ATOMIC);
39         if (!skb) {
40                 hdev->stat.err_rx++;
41                 return -ENOMEM;
42         }
43
44         bt_cb(skb)->pkt_type = type;
45         memcpy(skb_put(skb, count), data, count);
46
47         return hci_recv_frame(hdev, skb);
48 }
49
50 static int btqcomsmd_acl_callback(struct qcom_smd_channel *channel,
51                                   const void *data,
52                                   size_t count)
53 {
54         struct btqcomsmd *btq = qcom_smd_get_drvdata(channel);
55
56         btq->hdev->stat.byte_rx += count;
57         return btqcomsmd_recv(btq->hdev, HCI_ACLDATA_PKT, data, count);
58 }
59
60 static int btqcomsmd_cmd_callback(struct qcom_smd_channel *channel,
61                                   const void *data,
62                                   size_t count)
63 {
64         struct btqcomsmd *btq = qcom_smd_get_drvdata(channel);
65
66         return btqcomsmd_recv(btq->hdev, HCI_EVENT_PKT, data, count);
67 }
68
69 static int btqcomsmd_send(struct hci_dev *hdev, struct sk_buff *skb)
70 {
71         struct btqcomsmd *btq = hci_get_drvdata(hdev);
72         int ret;
73
74         switch (bt_cb(skb)->pkt_type) {
75         case HCI_ACLDATA_PKT:
76                 ret = qcom_smd_send(btq->acl_channel, skb->data, skb->len);
77                 hdev->stat.acl_tx++;
78                 hdev->stat.byte_tx += skb->len;
79                 break;
80         case HCI_COMMAND_PKT:
81                 ret = qcom_smd_send(btq->cmd_channel, skb->data, skb->len);
82                 hdev->stat.cmd_tx++;
83                 break;
84         default:
85                 ret = -EILSEQ;
86                 break;
87         }
88
89         return ret;
90 }
91
92 static int btqcomsmd_open(struct hci_dev *hdev)
93 {
94         return 0;
95 }
96
97 static int btqcomsmd_close(struct hci_dev *hdev)
98 {
99         return 0;
100 }
101
102 static int btqcomsmd_probe(struct platform_device *pdev)
103 {
104         struct btqcomsmd *btq;
105         struct hci_dev *hdev;
106         void *wcnss;
107         int ret;
108
109         btq = devm_kzalloc(&pdev->dev, sizeof(*btq), GFP_KERNEL);
110         if (!btq)
111                 return -ENOMEM;
112
113         wcnss = dev_get_drvdata(pdev->dev.parent);
114
115         btq->acl_channel = qcom_wcnss_open_channel(wcnss, "APPS_RIVA_BT_ACL",
116                                                    btqcomsmd_acl_callback);
117         if (IS_ERR(btq->acl_channel))
118                 return PTR_ERR(btq->acl_channel);
119
120         btq->cmd_channel = qcom_wcnss_open_channel(wcnss, "APPS_RIVA_BT_CMD",
121                                                    btqcomsmd_cmd_callback);
122         if (IS_ERR(btq->cmd_channel))
123                 return PTR_ERR(btq->cmd_channel);
124
125         qcom_smd_set_drvdata(btq->acl_channel, btq);
126         qcom_smd_set_drvdata(btq->cmd_channel, btq);
127
128         hdev = hci_alloc_dev();
129         if (!hdev)
130                 return -ENOMEM;
131
132         hci_set_drvdata(hdev, btq);
133         btq->hdev = hdev;
134         SET_HCIDEV_DEV(hdev, &pdev->dev);
135
136         hdev->bus = HCI_SMD;
137         hdev->open = btqcomsmd_open;
138         hdev->close = btqcomsmd_close;
139         hdev->send = btqcomsmd_send;
140         hdev->set_bdaddr = qca_set_bdaddr_rome;
141
142         ret = hci_register_dev(hdev);
143         if (ret < 0) {
144                 hci_free_dev(hdev);
145                 return ret;
146         }
147
148         platform_set_drvdata(pdev, btq);
149
150         return 0;
151 }
152
153 static int btqcomsmd_remove(struct platform_device *pdev)
154 {
155         struct btqcomsmd *btq = platform_get_drvdata(pdev);
156
157         hci_unregister_dev(btq->hdev);
158         hci_free_dev(btq->hdev);
159
160         return 0;
161 }
162
163 static const struct of_device_id btqcomsmd_of_match[] = {
164         { .compatible = "qcom,wcnss-bt", },
165         { },
166 };
167
168 static struct platform_driver btqcomsmd_driver = {
169         .probe = btqcomsmd_probe,
170         .remove = btqcomsmd_remove,
171         .driver  = {
172                 .name  = "btqcomsmd",
173                 .of_match_table = btqcomsmd_of_match,
174         },
175 };
176
177 module_platform_driver(btqcomsmd_driver);
178
179 MODULE_AUTHOR("Bjorn Andersson <bjorn.andersson@sonymobile.com>");
180 MODULE_DESCRIPTION("Qualcomm SMD HCI driver");
181 MODULE_LICENSE("GPL v2");