Lines Matching +full:llp +full:- +full:based
1 // SPDX-License-Identifier: GPL-2.0-only
10 * Written by Ohad Ben-Cohen <ohad@bencohen.org>
13 * This file is based on hci_h4.c, which was written
43 #include <linux/nvmem-consumer.h>
47 /* Vendor-specific HCI commands */
89 struct ll_struct *ll = hu->priv; in send_hcill_cmd()
97 err = -ENOMEM; in send_hcill_cmd()
105 skb_queue_tail(&ll->txq, skb); in send_hcill_cmd()
119 return -ENOMEM; in ll_open()
121 skb_queue_head_init(&ll->txq); in ll_open()
122 skb_queue_head_init(&ll->tx_wait_q); in ll_open()
123 spin_lock_init(&ll->hcill_lock); in ll_open()
125 ll->hcill_state = HCILL_AWAKE; in ll_open()
127 hu->priv = ll; in ll_open()
129 if (hu->serdev) { in ll_open()
130 struct ll_device *lldev = serdev_device_get_drvdata(hu->serdev); in ll_open()
132 if (!IS_ERR(lldev->ext_clk)) in ll_open()
133 clk_prepare_enable(lldev->ext_clk); in ll_open()
142 struct ll_struct *ll = hu->priv; in ll_flush()
146 skb_queue_purge(&ll->tx_wait_q); in ll_flush()
147 skb_queue_purge(&ll->txq); in ll_flush()
155 struct ll_struct *ll = hu->priv; in ll_close()
159 skb_queue_purge(&ll->tx_wait_q); in ll_close()
160 skb_queue_purge(&ll->txq); in ll_close()
162 kfree_skb(ll->rx_skb); in ll_close()
164 if (hu->serdev) { in ll_close()
165 struct ll_device *lldev = serdev_device_get_drvdata(hu->serdev); in ll_close()
167 gpiod_set_value_cansleep(lldev->enable_gpio, 0); in ll_close()
169 clk_disable_unprepare(lldev->ext_clk); in ll_close()
172 hu->priv = NULL; in ll_close()
190 while ((skb = skb_dequeue(&ll->tx_wait_q))) in __ll_do_awake()
191 skb_queue_tail(&ll->txq, skb); in __ll_do_awake()
193 ll->hcill_state = HCILL_AWAKE; in __ll_do_awake()
197 * Called upon a wake-up-indication from the device
202 struct ll_struct *ll = hu->priv; in ll_device_want_to_wakeup()
207 spin_lock_irqsave(&ll->hcill_lock, flags); in ll_device_want_to_wakeup()
209 switch (ll->hcill_state) { in ll_device_want_to_wakeup()
213 * have simultaneously sent a wake-up-indication packet. in ll_device_want_to_wakeup()
214 * Traditionally, in this case, receiving a wake-up-indication in ll_device_want_to_wakeup()
215 * was enough and an additional wake-up-ack wasn't needed. in ll_device_want_to_wakeup()
217 * explicit wake-up-ack. Other BRF versions, which do not in ll_device_want_to_wakeup()
221 BT_DBG("dual wake-up-indication"); in ll_device_want_to_wakeup()
233 ll->hcill_state); in ll_device_want_to_wakeup()
241 spin_unlock_irqrestore(&ll->hcill_lock, flags); in ll_device_want_to_wakeup()
248 * Called upon a sleep-indication from the device
253 struct ll_struct *ll = hu->priv; in ll_device_want_to_sleep()
258 spin_lock_irqsave(&ll->hcill_lock, flags); in ll_device_want_to_sleep()
261 if (ll->hcill_state != HCILL_AWAKE) in ll_device_want_to_sleep()
263 ll->hcill_state); in ll_device_want_to_sleep()
272 ll->hcill_state = HCILL_ASLEEP; in ll_device_want_to_sleep()
275 spin_unlock_irqrestore(&ll->hcill_lock, flags); in ll_device_want_to_sleep()
282 * Called upon wake-up-acknowledgement from the device
287 struct ll_struct *ll = hu->priv; in ll_device_woke_up()
292 spin_lock_irqsave(&ll->hcill_lock, flags); in ll_device_woke_up()
295 if (ll->hcill_state != HCILL_ASLEEP_TO_AWAKE) in ll_device_woke_up()
297 ll->hcill_state); in ll_device_woke_up()
302 spin_unlock_irqrestore(&ll->hcill_lock, flags); in ll_device_woke_up()
313 struct ll_struct *ll = hu->priv; in ll_enqueue()
321 spin_lock_irqsave(&ll->hcill_lock, flags); in ll_enqueue()
324 switch (ll->hcill_state) { in ll_enqueue()
327 skb_queue_tail(&ll->txq, skb); in ll_enqueue()
332 skb_queue_tail(&ll->tx_wait_q, skb); in ll_enqueue()
338 ll->hcill_state = HCILL_ASLEEP_TO_AWAKE; in ll_enqueue()
343 skb_queue_tail(&ll->tx_wait_q, skb); in ll_enqueue()
347 ll->hcill_state); in ll_enqueue()
352 spin_unlock_irqrestore(&ll->hcill_lock, flags); in ll_enqueue()
360 struct ll_struct *ll = hu->priv; in ll_recv_frame()
370 ll->hcill_state); in ll_recv_frame()
427 struct ll_struct *ll = hu->priv; in ll_recv()
429 if (!test_bit(HCI_UART_REGISTERED, &hu->flags)) in ll_recv()
430 return -EUNATCH; in ll_recv()
432 ll->rx_skb = h4_recv_buf(hu->hdev, ll->rx_skb, data, count, in ll_recv()
434 if (IS_ERR(ll->rx_skb)) { in ll_recv()
435 int err = PTR_ERR(ll->rx_skb); in ll_recv()
436 bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err); in ll_recv()
437 ll->rx_skb = NULL; in ll_recv()
446 struct ll_struct *ll = hu->priv; in ll_dequeue()
448 return skb_dequeue(&ll->txq); in ll_dequeue()
466 if (skb->len != sizeof(*ver)) { in read_local_version()
467 err = -EILSEQ; in read_local_version()
471 ver = (struct hci_rp_read_local_version *)skb->data; in read_local_version()
472 if (le16_to_cpu(ver->manufacturer) != 13) { in read_local_version()
473 err = -ENODEV; in read_local_version()
477 version = le16_to_cpu(ver->lmp_subver); in read_local_version()
491 if (cmd->opcode == HCI_VS_UPDATE_UART_HCI_BAUDRATE) { in send_command_from_firmware()
495 bt_dev_warn(lldev->hu.hdev, in send_command_from_firmware()
499 if (cmd->prefix != 1) in send_command_from_firmware()
500 bt_dev_dbg(lldev->hu.hdev, "command type %d", cmd->prefix); in send_command_from_firmware()
502 skb = __hci_cmd_sync(lldev->hu.hdev, cmd->opcode, cmd->plen, in send_command_from_firmware()
503 &cmd->speed, HCI_INIT_TIMEOUT); in send_command_from_firmware()
505 bt_dev_err(lldev->hu.hdev, "send command failed"); in send_command_from_firmware()
513 * download_firmware -
526 version = read_local_version(lldev->hu.hdev); in download_firmware()
537 "ti-connectivity/TIInit_%d.%d.%d.bts", in download_firmware()
540 err = request_firmware(&fw, bts_scr_name, &lldev->serdev->dev); in download_firmware()
541 if (err || !fw->data || !fw->size) { in download_firmware()
542 bt_dev_err(lldev->hu.hdev, "request_firmware failed(errno %d) for %s", in download_firmware()
544 return -EINVAL; in download_firmware()
546 ptr = (void *)fw->data; in download_firmware()
547 len = fw->size; in download_firmware()
552 len -= sizeof(struct bts_header); in download_firmware()
555 bt_dev_dbg(lldev->hu.hdev, " action size %d, type %d ", in download_firmware()
556 ((struct bts_action *)ptr)->size, in download_firmware()
557 ((struct bts_action *)ptr)->type); in download_firmware()
559 action_ptr = &(((struct bts_action *)ptr)->data[0]); in download_firmware()
561 switch (((struct bts_action *)ptr)->type) { in download_firmware()
563 bt_dev_dbg(lldev->hu.hdev, "S"); in download_firmware()
571 bt_dev_dbg(lldev->hu.hdev, "W"); in download_firmware()
574 bt_dev_info(lldev->hu.hdev, "sleep command in scr"); in download_firmware()
575 msleep(((struct bts_action_delay *)action_ptr)->msec); in download_firmware()
578 len -= (sizeof(struct bts_action) + in download_firmware()
579 ((struct bts_action *)ptr)->size); in download_firmware()
581 ((struct bts_action *)ptr)->size; in download_firmware()
612 struct serdev_device *serdev = hu->serdev; in ll_setup()
620 hu->hdev->set_bdaddr = ll_set_bdaddr; in ll_setup()
626 gpiod_set_value_cansleep(lldev->enable_gpio, 0); in ll_setup()
628 gpiod_set_value_cansleep(lldev->enable_gpio, 1); in ll_setup()
632 bt_dev_err(hu->hdev, "Failed to get CTS"); in ll_setup()
641 bt_dev_err(hu->hdev, "download firmware failed, retrying..."); in ll_setup()
642 } while (retry--); in ll_setup()
648 if (!bacmp(&lldev->bdaddr, BDADDR_NONE)) { in ll_setup()
652 set_bit(HCI_QUIRK_INVALID_BDADDR, &hu->hdev->quirks); in ll_setup()
653 } else if (bacmp(&lldev->bdaddr, BDADDR_ANY)) { in ll_setup()
654 err = ll_set_bdaddr(hu->hdev, &lldev->bdaddr); in ll_setup()
656 set_bit(HCI_QUIRK_INVALID_BDADDR, &hu->hdev->quirks); in ll_setup()
660 if (hu->oper_speed) in ll_setup()
661 speed = hu->oper_speed; in ll_setup()
662 else if (hu->proto->oper_speed) in ll_setup()
663 speed = hu->proto->oper_speed; in ll_setup()
671 skb = __hci_cmd_sync(hu->hdev, HCI_VS_UPDATE_UART_HCI_BAUDRATE, in ll_setup()
683 static const struct hci_uart_proto llp; variable
692 lldev = devm_kzalloc(&serdev->dev, sizeof(struct ll_device), GFP_KERNEL); in hci_ti_probe()
694 return -ENOMEM; in hci_ti_probe()
695 hu = &lldev->hu; in hci_ti_probe()
698 lldev->serdev = hu->serdev = serdev; in hci_ti_probe()
700 lldev->enable_gpio = devm_gpiod_get_optional(&serdev->dev, in hci_ti_probe()
703 if (IS_ERR(lldev->enable_gpio)) in hci_ti_probe()
704 return PTR_ERR(lldev->enable_gpio); in hci_ti_probe()
706 lldev->ext_clk = devm_clk_get(&serdev->dev, "ext_clock"); in hci_ti_probe()
707 if (IS_ERR(lldev->ext_clk) && PTR_ERR(lldev->ext_clk) != -ENOENT) in hci_ti_probe()
708 return PTR_ERR(lldev->ext_clk); in hci_ti_probe()
710 of_property_read_u32(serdev->dev.of_node, "max-speed", &max_speed); in hci_ti_probe()
714 bdaddr_cell = nvmem_cell_get(&serdev->dev, "bd-address"); in hci_ti_probe()
718 if (err == -EPROBE_DEFER) in hci_ti_probe()
724 if (err != -ENOENT && err != -ENOSYS) { in hci_ti_probe()
730 dev_warn(&serdev->dev, in hci_ti_probe()
731 "Failed to get \"bd-address\" nvmem cell (%d)\n", in hci_ti_probe()
733 bacpy(&lldev->bdaddr, BDADDR_NONE); in hci_ti_probe()
742 dev_err(&serdev->dev, "Failed to read nvmem bd-address\n"); in hci_ti_probe()
746 dev_err(&serdev->dev, "Invalid nvmem bd-address length\n"); in hci_ti_probe()
748 return -EINVAL; in hci_ti_probe()
755 baswap(&lldev->bdaddr, bdaddr); in hci_ti_probe()
759 return hci_uart_register_device(hu, &llp); in hci_ti_probe()
766 hci_uart_unregister_device(&lldev->hu); in hci_ti_remove()
771 { .compatible = "ti,wl1271-st" },
772 { .compatible = "ti,wl1273-st" },
773 { .compatible = "ti,wl1281-st" },
774 { .compatible = "ti,wl1283-st" },
775 { .compatible = "ti,wl1285-st" },
776 { .compatible = "ti,wl1801-st" },
777 { .compatible = "ti,wl1805-st" },
778 { .compatible = "ti,wl1807-st" },
779 { .compatible = "ti,wl1831-st" },
780 { .compatible = "ti,wl1835-st" },
781 { .compatible = "ti,wl1837-st" },
788 .name = "hci-ti",
798 static const struct hci_uart_proto llp = { variable
814 return hci_uart_register_proto(&llp); in ll_init()
821 return hci_uart_unregister_proto(&llp); in ll_deinit()