hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/bluetooth/btqcomsmd.c
....@@ -1,15 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2016, Linaro Ltd.
34 * 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.
135 */
146
157 #include <linux/module.h>
....@@ -28,7 +20,6 @@
2820 struct btqcomsmd {
2921 struct hci_dev *hdev;
3022
31
- bdaddr_t bdaddr;
3223 struct rpmsg_endpoint *acl_channel;
3324 struct rpmsg_endpoint *cmd_channel;
3425 };
....@@ -116,33 +107,33 @@
116107
117108 static int btqcomsmd_setup(struct hci_dev *hdev)
118109 {
119
- struct btqcomsmd *btq = hci_get_drvdata(hdev);
120110 struct sk_buff *skb;
121
- int err;
122111
123112 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
124113 if (IS_ERR(skb))
125114 return PTR_ERR(skb);
126115 kfree_skb(skb);
127116
128
- /* Devices do not have persistent storage for BD address. If no
129
- * BD address has been retrieved during probe, mark the device
130
- * as having an invalid BD address.
117
+ /* Devices do not have persistent storage for BD address. Retrieve
118
+ * it from the firmware node property.
131119 */
132
- if (!bacmp(&btq->bdaddr, BDADDR_ANY)) {
133
- set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
134
- return 0;
135
- }
120
+ set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks);
136121
137
- /* When setting a configured BD address fails, mark the device
138
- * as having an invalid BD address.
122
+ return 0;
123
+}
124
+
125
+static int btqcomsmd_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
126
+{
127
+ int ret;
128
+
129
+ ret = qca_set_bdaddr_rome(hdev, bdaddr);
130
+ if (ret)
131
+ return ret;
132
+
133
+ /* The firmware stops responding for a while after setting the bdaddr,
134
+ * causing timeouts for subsequent commands. Sleep a bit to avoid this.
139135 */
140
- err = qca_set_bdaddr_rome(hdev, &btq->bdaddr);
141
- if (err) {
142
- set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
143
- return 0;
144
- }
145
-
136
+ usleep_range(1000, 10000);
146137 return 0;
147138 }
148139
....@@ -171,15 +162,6 @@
171162 goto destroy_acl_channel;
172163 }
173164
174
- /* The local-bd-address property is usually injected by the
175
- * bootloader which has access to the allocated BD address.
176
- */
177
- if (!of_property_read_u8_array(pdev->dev.of_node, "local-bd-address",
178
- (u8 *)&btq->bdaddr, sizeof(bdaddr_t))) {
179
- dev_info(&pdev->dev, "BD address %pMR retrieved from device-tree",
180
- &btq->bdaddr);
181
- }
182
-
183165 hdev = hci_alloc_dev();
184166 if (!hdev) {
185167 ret = -ENOMEM;
....@@ -195,7 +177,7 @@
195177 hdev->close = btqcomsmd_close;
196178 hdev->send = btqcomsmd_send;
197179 hdev->setup = btqcomsmd_setup;
198
- hdev->set_bdaddr = qca_set_bdaddr_rome;
180
+ hdev->set_bdaddr = btqcomsmd_set_bdaddr;
199181
200182 ret = hci_register_dev(hdev);
201183 if (ret < 0)