Revert "ALSA: hda: Flush interrupts on disabling"
[linux/fpc-iii.git] / drivers / bluetooth / btqcomsmd.c
blob3aac78a5091b6bd1d58055f05d861ae53dfafaae
1 /*
2 * Copyright (c) 2016, Linaro Ltd.
3 * Copyright (c) 2015, Sony Mobile Communications Inc.
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.
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.
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>
21 #include <net/bluetooth/bluetooth.h>
22 #include <net/bluetooth/hci_core.h>
24 #include "btqca.h"
26 struct btqcomsmd {
27 struct hci_dev *hdev;
29 struct qcom_smd_channel *acl_channel;
30 struct qcom_smd_channel *cmd_channel;
33 static int btqcomsmd_recv(struct hci_dev *hdev, unsigned int type,
34 const void *data, size_t count)
36 struct sk_buff *skb;
38 /* Use GFP_ATOMIC as we're in IRQ context */
39 skb = bt_skb_alloc(count, GFP_ATOMIC);
40 if (!skb) {
41 hdev->stat.err_rx++;
42 return -ENOMEM;
45 hci_skb_pkt_type(skb) = type;
46 memcpy(skb_put(skb, count), data, count);
48 return hci_recv_frame(hdev, skb);
51 static int btqcomsmd_acl_callback(struct qcom_smd_channel *channel,
52 const void *data, size_t count)
54 struct btqcomsmd *btq = qcom_smd_get_drvdata(channel);
56 btq->hdev->stat.byte_rx += count;
57 return btqcomsmd_recv(btq->hdev, HCI_ACLDATA_PKT, data, count);
60 static int btqcomsmd_cmd_callback(struct qcom_smd_channel *channel,
61 const void *data, size_t count)
63 struct btqcomsmd *btq = qcom_smd_get_drvdata(channel);
65 return btqcomsmd_recv(btq->hdev, HCI_EVENT_PKT, data, count);
68 static int btqcomsmd_send(struct hci_dev *hdev, struct sk_buff *skb)
70 struct btqcomsmd *btq = hci_get_drvdata(hdev);
71 int ret;
73 switch (hci_skb_pkt_type(skb)) {
74 case HCI_ACLDATA_PKT:
75 ret = qcom_smd_send(btq->acl_channel, skb->data, skb->len);
76 hdev->stat.acl_tx++;
77 hdev->stat.byte_tx += skb->len;
78 break;
79 case HCI_COMMAND_PKT:
80 ret = qcom_smd_send(btq->cmd_channel, skb->data, skb->len);
81 hdev->stat.cmd_tx++;
82 break;
83 default:
84 ret = -EILSEQ;
85 break;
88 if (!ret)
89 kfree_skb(skb);
91 return ret;
94 static int btqcomsmd_open(struct hci_dev *hdev)
96 return 0;
99 static int btqcomsmd_close(struct hci_dev *hdev)
101 return 0;
104 static int btqcomsmd_probe(struct platform_device *pdev)
106 struct btqcomsmd *btq;
107 struct hci_dev *hdev;
108 void *wcnss;
109 int ret;
111 btq = devm_kzalloc(&pdev->dev, sizeof(*btq), GFP_KERNEL);
112 if (!btq)
113 return -ENOMEM;
115 wcnss = dev_get_drvdata(pdev->dev.parent);
117 btq->acl_channel = qcom_wcnss_open_channel(wcnss, "APPS_RIVA_BT_ACL",
118 btqcomsmd_acl_callback);
119 if (IS_ERR(btq->acl_channel))
120 return PTR_ERR(btq->acl_channel);
122 btq->cmd_channel = qcom_wcnss_open_channel(wcnss, "APPS_RIVA_BT_CMD",
123 btqcomsmd_cmd_callback);
124 if (IS_ERR(btq->cmd_channel))
125 return PTR_ERR(btq->cmd_channel);
127 qcom_smd_set_drvdata(btq->acl_channel, btq);
128 qcom_smd_set_drvdata(btq->cmd_channel, btq);
130 hdev = hci_alloc_dev();
131 if (!hdev)
132 return -ENOMEM;
134 hci_set_drvdata(hdev, btq);
135 btq->hdev = hdev;
136 SET_HCIDEV_DEV(hdev, &pdev->dev);
138 hdev->bus = HCI_SMD;
139 hdev->open = btqcomsmd_open;
140 hdev->close = btqcomsmd_close;
141 hdev->send = btqcomsmd_send;
142 hdev->set_bdaddr = qca_set_bdaddr_rome;
144 ret = hci_register_dev(hdev);
145 if (ret < 0) {
146 hci_free_dev(hdev);
147 return ret;
150 platform_set_drvdata(pdev, btq);
152 return 0;
155 static int btqcomsmd_remove(struct platform_device *pdev)
157 struct btqcomsmd *btq = platform_get_drvdata(pdev);
159 hci_unregister_dev(btq->hdev);
160 hci_free_dev(btq->hdev);
162 return 0;
165 static const struct of_device_id btqcomsmd_of_match[] = {
166 { .compatible = "qcom,wcnss-bt", },
167 { },
170 static struct platform_driver btqcomsmd_driver = {
171 .probe = btqcomsmd_probe,
172 .remove = btqcomsmd_remove,
173 .driver = {
174 .name = "btqcomsmd",
175 .of_match_table = btqcomsmd_of_match,
179 module_platform_driver(btqcomsmd_driver);
181 MODULE_AUTHOR("Bjorn Andersson <bjorn.andersson@sonymobile.com>");
182 MODULE_DESCRIPTION("Qualcomm SMD HCI driver");
183 MODULE_LICENSE("GPL v2");