hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/bluetooth/hci_ll.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Texas Instruments' Bluetooth HCILL UART protocol
34 *
....@@ -11,20 +12,6 @@
1112 * Acknowledgements:
1213 * This file is based on hci_h4.c, which was written
1314 * by Maxim Krasnyansky and Marcel Holtmann.
14
- *
15
- * This program is free software; you can redistribute it and/or modify
16
- * it under the terms of the GNU General Public License version 2
17
- * as published by the Free Software Foundation
18
- *
19
- * This program is distributed in the hope that it will be useful,
20
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
- * GNU General Public License for more details.
23
- *
24
- * You should have received a copy of the GNU General Public License
25
- * along with this program; if not, write to the Free Software
26
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
- *
2815 */
2916
3017 #include <linux/module.h>
....@@ -141,6 +128,7 @@
141128
142129 if (hu->serdev) {
143130 struct ll_device *lldev = serdev_device_get_drvdata(hu->serdev);
131
+
144132 if (!IS_ERR(lldev->ext_clk))
145133 clk_prepare_enable(lldev->ext_clk);
146134 }
....@@ -175,6 +163,7 @@
175163
176164 if (hu->serdev) {
177165 struct ll_device *lldev = serdev_device_get_drvdata(hu->serdev);
166
+
178167 gpiod_set_value_cansleep(lldev->enable_gpio, 0);
179168
180169 clk_disable_unprepare(lldev->ext_clk);
....@@ -230,7 +219,7 @@
230219 * perfectly safe to always send one.
231220 */
232221 BT_DBG("dual wake-up-indication");
233
- /* fall through */
222
+ fallthrough;
234223 case HCILL_ASLEEP:
235224 /* acknowledge device wake up */
236225 if (send_hcill_cmd(HCILL_WAKE_UP_ACK, hu) < 0) {
....@@ -240,7 +229,8 @@
240229 break;
241230 default:
242231 /* any other state is illegal */
243
- BT_ERR("received HCILL_WAKE_UP_IND in state %ld", ll->hcill_state);
232
+ BT_ERR("received HCILL_WAKE_UP_IND in state %ld",
233
+ ll->hcill_state);
244234 break;
245235 }
246236
....@@ -269,7 +259,8 @@
269259
270260 /* sanity check */
271261 if (ll->hcill_state != HCILL_AWAKE)
272
- BT_ERR("ERR: HCILL_GO_TO_SLEEP_IND in state %ld", ll->hcill_state);
262
+ BT_ERR("ERR: HCILL_GO_TO_SLEEP_IND in state %ld",
263
+ ll->hcill_state);
273264
274265 /* acknowledge device sleep */
275266 if (send_hcill_cmd(HCILL_GO_TO_SLEEP_ACK, hu) < 0) {
....@@ -302,7 +293,8 @@
302293
303294 /* sanity check */
304295 if (ll->hcill_state != HCILL_ASLEEP_TO_AWAKE)
305
- BT_ERR("received HCILL_WAKE_UP_ACK in state %ld", ll->hcill_state);
296
+ BT_ERR("received HCILL_WAKE_UP_ACK in state %ld",
297
+ ll->hcill_state);
306298
307299 /* send pending packets and change state to HCILL_AWAKE */
308300 __ll_do_awake(ll);
....@@ -351,8 +343,9 @@
351343 skb_queue_tail(&ll->tx_wait_q, skb);
352344 break;
353345 default:
354
- BT_ERR("illegal hcill state: %ld (losing packet)", ll->hcill_state);
355
- kfree_skb(skb);
346
+ BT_ERR("illegal hcill state: %ld (losing packet)",
347
+ ll->hcill_state);
348
+ dev_kfree_skb_irq(skb);
356349 break;
357350 }
358351
....@@ -451,6 +444,7 @@
451444 static struct sk_buff *ll_dequeue(struct hci_uart *hu)
452445 {
453446 struct ll_struct *ll = hu->priv;
447
+
454448 return skb_dequeue(&ll->txq);
455449 }
456450
....@@ -462,7 +456,8 @@
462456 struct sk_buff *skb;
463457 struct hci_rp_read_local_version *ver;
464458
465
- skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL, HCI_INIT_TIMEOUT);
459
+ skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
460
+ HCI_INIT_TIMEOUT);
466461 if (IS_ERR(skb)) {
467462 bt_dev_err(hdev, "Reading TI version information failed (%ld)",
468463 PTR_ERR(skb));
....@@ -482,9 +477,36 @@
482477 version = le16_to_cpu(ver->lmp_subver);
483478
484479 out:
485
- if (err) bt_dev_err(hdev, "Failed to read TI version info: %d", err);
480
+ if (err)
481
+ bt_dev_err(hdev, "Failed to read TI version info: %d", err);
486482 kfree_skb(skb);
487483 return err ? err : version;
484
+}
485
+
486
+static int send_command_from_firmware(struct ll_device *lldev,
487
+ struct hci_command *cmd)
488
+{
489
+ struct sk_buff *skb;
490
+
491
+ if (cmd->opcode == HCI_VS_UPDATE_UART_HCI_BAUDRATE) {
492
+ /* ignore remote change
493
+ * baud rate HCI VS command
494
+ */
495
+ bt_dev_warn(lldev->hu.hdev,
496
+ "change remote baud rate command in firmware");
497
+ return 0;
498
+ }
499
+ if (cmd->prefix != 1)
500
+ bt_dev_dbg(lldev->hu.hdev, "command type %d", cmd->prefix);
501
+
502
+ skb = __hci_cmd_sync(lldev->hu.hdev, cmd->opcode, cmd->plen,
503
+ &cmd->speed, HCI_INIT_TIMEOUT);
504
+ if (IS_ERR(skb)) {
505
+ bt_dev_err(lldev->hu.hdev, "send command failed");
506
+ return PTR_ERR(skb);
507
+ }
508
+ kfree_skb(skb);
509
+ return 0;
488510 }
489511
490512 /**
....@@ -499,7 +521,6 @@
499521 unsigned char *ptr, *action_ptr;
500522 unsigned char bts_scr_name[40]; /* 40 char long bts scr name? */
501523 const struct firmware *fw;
502
- struct sk_buff *skb;
503524 struct hci_command *cmd;
504525
505526 version = read_local_version(lldev->hu.hdev);
....@@ -541,23 +562,9 @@
541562 case ACTION_SEND_COMMAND: /* action send */
542563 bt_dev_dbg(lldev->hu.hdev, "S");
543564 cmd = (struct hci_command *)action_ptr;
544
- if (cmd->opcode == HCI_VS_UPDATE_UART_HCI_BAUDRATE) {
545
- /* ignore remote change
546
- * baud rate HCI VS command
547
- */
548
- bt_dev_warn(lldev->hu.hdev, "change remote baud rate command in firmware");
549
- break;
550
- }
551
- if (cmd->prefix != 1)
552
- bt_dev_dbg(lldev->hu.hdev, "command type %d", cmd->prefix);
553
-
554
- skb = __hci_cmd_sync(lldev->hu.hdev, cmd->opcode, cmd->plen, &cmd->speed, HCI_INIT_TIMEOUT);
555
- if (IS_ERR(skb)) {
556
- bt_dev_err(lldev->hu.hdev, "send command failed");
557
- err = PTR_ERR(skb);
565
+ err = send_command_from_firmware(lldev, cmd);
566
+ if (err)
558567 goto out_rel_fw;
559
- }
560
- kfree_skb(skb);
561568 break;
562569 case ACTION_WAIT_EVENT: /* wait */
563570 /* no need to wait as command was synchronous */
....@@ -689,7 +696,9 @@
689696 serdev_device_set_drvdata(serdev, lldev);
690697 lldev->serdev = hu->serdev = serdev;
691698
692
- lldev->enable_gpio = devm_gpiod_get_optional(&serdev->dev, "enable", GPIOD_OUT_LOW);
699
+ lldev->enable_gpio = devm_gpiod_get_optional(&serdev->dev,
700
+ "enable",
701
+ GPIOD_OUT_LOW);
693702 if (IS_ERR(lldev->enable_gpio))
694703 return PTR_ERR(lldev->enable_gpio);
695704