Lines Matching refs:h5
63 struct h5 { struct
110 int (*setup)(struct h5 *h5); argument
111 void (*open)(struct h5 *h5);
112 void (*close)(struct h5 *h5);
113 int (*suspend)(struct h5 *h5);
114 int (*resume)(struct h5 *h5);
123 static void h5_reset_rx(struct h5 *h5);
127 struct h5 *h5 = hu->priv; in h5_link_control() local
138 skb_queue_tail(&h5->unrel, nskb); in h5_link_control()
141 static u8 h5_cfg_field(struct h5 *h5) in h5_cfg_field() argument
144 return h5->tx_win & 0x07; in h5_cfg_field()
151 struct h5 *h5 = from_timer(h5, t, timer); in h5_timed_event() local
152 struct hci_uart *hu = h5->hu; in h5_timed_event()
158 if (h5->state == H5_UNINITIALIZED) in h5_timed_event()
161 if (h5->state == H5_INITIALIZED) { in h5_timed_event()
162 conf_req[2] = h5_cfg_field(h5); in h5_timed_event()
166 if (h5->state != H5_ACTIVE) { in h5_timed_event()
167 mod_timer(&h5->timer, jiffies + H5_SYNC_TIMEOUT); in h5_timed_event()
171 if (h5->sleep != H5_AWAKE) { in h5_timed_event()
172 h5->sleep = H5_SLEEPING; in h5_timed_event()
176 BT_DBG("hu %p retransmitting %u pkts", hu, h5->unack.qlen); in h5_timed_event()
178 spin_lock_irqsave_nested(&h5->unack.lock, flags, SINGLE_DEPTH_NESTING); in h5_timed_event()
180 while ((skb = __skb_dequeue_tail(&h5->unack)) != NULL) { in h5_timed_event()
181 h5->tx_seq = (h5->tx_seq - 1) & 0x07; in h5_timed_event()
182 skb_queue_head(&h5->rel, skb); in h5_timed_event()
185 spin_unlock_irqrestore(&h5->unack.lock, flags); in h5_timed_event()
193 struct h5 *h5 = hu->priv; in h5_peer_reset() local
197 h5->state = H5_UNINITIALIZED; in h5_peer_reset()
199 del_timer(&h5->timer); in h5_peer_reset()
201 skb_queue_purge(&h5->rel); in h5_peer_reset()
202 skb_queue_purge(&h5->unrel); in h5_peer_reset()
203 skb_queue_purge(&h5->unack); in h5_peer_reset()
205 h5->tx_seq = 0; in h5_peer_reset()
206 h5->tx_ack = 0; in h5_peer_reset()
214 struct h5 *h5; in h5_open() local
220 h5 = serdev_device_get_drvdata(hu->serdev); in h5_open()
222 h5 = kzalloc(sizeof(*h5), GFP_KERNEL); in h5_open()
223 if (!h5) in h5_open()
227 hu->priv = h5; in h5_open()
228 h5->hu = hu; in h5_open()
230 skb_queue_head_init(&h5->unack); in h5_open()
231 skb_queue_head_init(&h5->rel); in h5_open()
232 skb_queue_head_init(&h5->unrel); in h5_open()
234 h5_reset_rx(h5); in h5_open()
236 timer_setup(&h5->timer, h5_timed_event, 0); in h5_open()
238 h5->tx_win = H5_TX_WIN_MAX; in h5_open()
240 if (h5->vnd && h5->vnd->open) in h5_open()
241 h5->vnd->open(h5); in h5_open()
247 mod_timer(&h5->timer, jiffies + H5_SYNC_TIMEOUT); in h5_open()
254 struct h5 *h5 = hu->priv; in h5_close() local
256 del_timer_sync(&h5->timer); in h5_close()
258 skb_queue_purge(&h5->unack); in h5_close()
259 skb_queue_purge(&h5->rel); in h5_close()
260 skb_queue_purge(&h5->unrel); in h5_close()
262 kfree_skb(h5->rx_skb); in h5_close()
263 h5->rx_skb = NULL; in h5_close()
265 if (h5->vnd && h5->vnd->close) in h5_close()
266 h5->vnd->close(h5); in h5_close()
269 kfree(h5); in h5_close()
276 struct h5 *h5 = hu->priv; in h5_setup() local
278 if (h5->vnd && h5->vnd->setup) in h5_setup()
279 return h5->vnd->setup(h5); in h5_setup()
284 static void h5_pkt_cull(struct h5 *h5) in h5_pkt_cull() argument
291 spin_lock_irqsave(&h5->unack.lock, flags); in h5_pkt_cull()
293 to_remove = skb_queue_len(&h5->unack); in h5_pkt_cull()
297 seq = h5->tx_seq; in h5_pkt_cull()
300 if (h5->rx_ack == seq) in h5_pkt_cull()
307 if (seq != h5->rx_ack) in h5_pkt_cull()
311 skb_queue_walk_safe(&h5->unack, skb, tmp) { in h5_pkt_cull()
315 __skb_unlink(skb, &h5->unack); in h5_pkt_cull()
319 if (skb_queue_empty(&h5->unack)) in h5_pkt_cull()
320 del_timer(&h5->timer); in h5_pkt_cull()
323 spin_unlock_irqrestore(&h5->unack.lock, flags); in h5_pkt_cull()
328 struct h5 *h5 = hu->priv; in h5_handle_internal_rx() local
336 const unsigned char *hdr = h5->rx_skb->data; in h5_handle_internal_rx()
337 const unsigned char *data = &h5->rx_skb->data[4]; in h5_handle_internal_rx()
347 conf_req[2] = h5_cfg_field(h5); in h5_handle_internal_rx()
350 if (h5->state == H5_ACTIVE) in h5_handle_internal_rx()
354 if (h5->state == H5_ACTIVE) in h5_handle_internal_rx()
356 h5->state = H5_INITIALIZED; in h5_handle_internal_rx()
363 h5->tx_win = (data[2] & 0x07); in h5_handle_internal_rx()
364 BT_DBG("Three-wire init complete. tx_win %u", h5->tx_win); in h5_handle_internal_rx()
365 h5->state = H5_ACTIVE; in h5_handle_internal_rx()
370 h5->sleep = H5_SLEEPING; in h5_handle_internal_rx()
374 h5->sleep = H5_AWAKE; in h5_handle_internal_rx()
378 h5->sleep = H5_AWAKE; in h5_handle_internal_rx()
389 struct h5 *h5 = hu->priv; in h5_complete_rx_pkt() local
390 const unsigned char *hdr = h5->rx_skb->data; in h5_complete_rx_pkt()
393 h5->tx_ack = (h5->tx_ack + 1) % 8; in h5_complete_rx_pkt()
394 set_bit(H5_TX_ACK_REQ, &h5->flags); in h5_complete_rx_pkt()
398 h5->rx_ack = H5_HDR_ACK(hdr); in h5_complete_rx_pkt()
400 h5_pkt_cull(h5); in h5_complete_rx_pkt()
407 hci_skb_pkt_type(h5->rx_skb) = H5_HDR_PKT_TYPE(hdr); in h5_complete_rx_pkt()
410 skb_pull(h5->rx_skb, 4); in h5_complete_rx_pkt()
412 hci_recv_frame(hu->hdev, h5->rx_skb); in h5_complete_rx_pkt()
413 h5->rx_skb = NULL; in h5_complete_rx_pkt()
422 h5_reset_rx(h5); in h5_complete_rx_pkt()
434 struct h5 *h5 = hu->priv; in h5_rx_payload() local
435 const unsigned char *hdr = h5->rx_skb->data; in h5_rx_payload()
438 h5->rx_func = h5_rx_crc; in h5_rx_payload()
439 h5->rx_pending = 2; in h5_rx_payload()
449 struct h5 *h5 = hu->priv; in h5_rx_3wire_hdr() local
450 const unsigned char *hdr = h5->rx_skb->data; in h5_rx_3wire_hdr()
459 h5_reset_rx(h5); in h5_rx_3wire_hdr()
463 if (H5_HDR_RELIABLE(hdr) && H5_HDR_SEQ(hdr) != h5->tx_ack) { in h5_rx_3wire_hdr()
465 H5_HDR_SEQ(hdr), h5->tx_ack); in h5_rx_3wire_hdr()
466 h5_reset_rx(h5); in h5_rx_3wire_hdr()
470 if (h5->state != H5_ACTIVE && in h5_rx_3wire_hdr()
473 h5_reset_rx(h5); in h5_rx_3wire_hdr()
477 h5->rx_func = h5_rx_payload; in h5_rx_3wire_hdr()
478 h5->rx_pending = H5_HDR_LEN(hdr); in h5_rx_3wire_hdr()
485 struct h5 *h5 = hu->priv; in h5_rx_pkt_start() local
490 h5->rx_func = h5_rx_3wire_hdr; in h5_rx_pkt_start()
491 h5->rx_pending = 4; in h5_rx_pkt_start()
493 h5->rx_skb = bt_skb_alloc(H5_MAX_LEN, GFP_ATOMIC); in h5_rx_pkt_start()
494 if (!h5->rx_skb) { in h5_rx_pkt_start()
496 h5_reset_rx(h5); in h5_rx_pkt_start()
500 h5->rx_skb->dev = (void *)hu->hdev; in h5_rx_pkt_start()
507 struct h5 *h5 = hu->priv; in h5_rx_delimiter() local
510 h5->rx_func = h5_rx_pkt_start; in h5_rx_delimiter()
515 static void h5_unslip_one_byte(struct h5 *h5, unsigned char c) in h5_unslip_one_byte() argument
520 if (!test_bit(H5_RX_ESC, &h5->flags) && c == SLIP_ESC) { in h5_unslip_one_byte()
521 set_bit(H5_RX_ESC, &h5->flags); in h5_unslip_one_byte()
525 if (test_and_clear_bit(H5_RX_ESC, &h5->flags)) { in h5_unslip_one_byte()
535 h5_reset_rx(h5); in h5_unslip_one_byte()
540 skb_put_data(h5->rx_skb, byte, 1); in h5_unslip_one_byte()
541 h5->rx_pending--; in h5_unslip_one_byte()
543 BT_DBG("unslipped 0x%02hhx, rx_pending %zu", *byte, h5->rx_pending); in h5_unslip_one_byte()
546 static void h5_reset_rx(struct h5 *h5) in h5_reset_rx() argument
548 if (h5->rx_skb) { in h5_reset_rx()
549 kfree_skb(h5->rx_skb); in h5_reset_rx()
550 h5->rx_skb = NULL; in h5_reset_rx()
553 h5->rx_func = h5_rx_delimiter; in h5_reset_rx()
554 h5->rx_pending = 0; in h5_reset_rx()
555 clear_bit(H5_RX_ESC, &h5->flags); in h5_reset_rx()
560 struct h5 *h5 = hu->priv; in h5_recv() local
563 BT_DBG("%s pending %zu count %d", hu->hdev->name, h5->rx_pending, in h5_recv()
569 if (h5->rx_pending > 0) { in h5_recv()
572 h5_reset_rx(h5); in h5_recv()
576 h5_unslip_one_byte(h5, *ptr); in h5_recv()
582 processed = h5->rx_func(hu, *ptr); in h5_recv()
601 struct h5 *h5 = hu->priv; in h5_enqueue() local
609 if (h5->state != H5_ACTIVE) { in h5_enqueue()
618 skb_queue_tail(&h5->rel, skb); in h5_enqueue()
623 skb_queue_tail(&h5->unrel, skb); in h5_enqueue()
683 struct h5 *h5 = hu->priv; in h5_prepare_pkt() local
707 hdr[0] = h5->tx_ack << 3; in h5_prepare_pkt()
708 clear_bit(H5_TX_ACK_REQ, &h5->flags); in h5_prepare_pkt()
713 hdr[0] |= h5->tx_seq; in h5_prepare_pkt()
714 h5->tx_seq = (h5->tx_seq + 1) % 8; in h5_prepare_pkt()
739 struct h5 *h5 = hu->priv; in h5_dequeue() local
743 if (h5->sleep != H5_AWAKE) { in h5_dequeue()
746 if (h5->sleep == H5_WAKING_UP) in h5_dequeue()
749 h5->sleep = H5_WAKING_UP; in h5_dequeue()
752 mod_timer(&h5->timer, jiffies + HZ / 100); in h5_dequeue()
756 skb = skb_dequeue(&h5->unrel); in h5_dequeue()
765 skb_queue_head(&h5->unrel, skb); in h5_dequeue()
769 spin_lock_irqsave_nested(&h5->unack.lock, flags, SINGLE_DEPTH_NESTING); in h5_dequeue()
771 if (h5->unack.qlen >= h5->tx_win) in h5_dequeue()
774 skb = skb_dequeue(&h5->rel); in h5_dequeue()
779 __skb_queue_tail(&h5->unack, skb); in h5_dequeue()
780 mod_timer(&h5->timer, jiffies + H5_ACK_TIMEOUT); in h5_dequeue()
781 spin_unlock_irqrestore(&h5->unack.lock, flags); in h5_dequeue()
785 skb_queue_head(&h5->rel, skb); in h5_dequeue()
790 spin_unlock_irqrestore(&h5->unack.lock, flags); in h5_dequeue()
792 if (test_bit(H5_TX_ACK_REQ, &h5->flags)) in h5_dequeue()
819 struct h5 *h5; in h5_serdev_probe() local
822 h5 = devm_kzalloc(dev, sizeof(*h5), GFP_KERNEL); in h5_serdev_probe()
823 if (!h5) in h5_serdev_probe()
826 h5->hu = &h5->serdev_hu; in h5_serdev_probe()
827 h5->serdev_hu.serdev = serdev; in h5_serdev_probe()
828 serdev_device_set_drvdata(serdev, h5); in h5_serdev_probe()
838 h5->vnd = data->vnd; in h5_serdev_probe()
839 h5->id = (char *)match->id; in h5_serdev_probe()
841 if (h5->vnd->acpi_gpio_map) in h5_serdev_probe()
843 h5->vnd->acpi_gpio_map); in h5_serdev_probe()
849 h5->vnd = data->vnd; in h5_serdev_probe()
853 set_bit(H5_WAKEUP_DISABLE, &h5->flags); in h5_serdev_probe()
855 h5->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW); in h5_serdev_probe()
856 if (IS_ERR(h5->enable_gpio)) in h5_serdev_probe()
857 return PTR_ERR(h5->enable_gpio); in h5_serdev_probe()
859 h5->device_wake_gpio = devm_gpiod_get_optional(dev, "device-wake", in h5_serdev_probe()
861 if (IS_ERR(h5->device_wake_gpio)) in h5_serdev_probe()
862 return PTR_ERR(h5->device_wake_gpio); in h5_serdev_probe()
864 return hci_uart_register_device(&h5->serdev_hu, &h5p); in h5_serdev_probe()
869 struct h5 *h5 = serdev_device_get_drvdata(serdev); in h5_serdev_remove() local
871 hci_uart_unregister_device(&h5->serdev_hu); in h5_serdev_remove()
876 struct h5 *h5 = dev_get_drvdata(dev); in h5_serdev_suspend() local
879 if (h5->vnd && h5->vnd->suspend) in h5_serdev_suspend()
880 ret = h5->vnd->suspend(h5); in h5_serdev_suspend()
887 struct h5 *h5 = dev_get_drvdata(dev); in h5_serdev_resume() local
890 if (h5->vnd && h5->vnd->resume) in h5_serdev_resume()
891 ret = h5->vnd->resume(h5); in h5_serdev_resume()
897 static int h5_btrtl_setup(struct h5 *h5) in h5_btrtl_setup() argument
907 btrtl_dev = btrtl_initialize(h5->hu->hdev, h5->id); in h5_btrtl_setup()
911 err = btrtl_get_uart_settings(h5->hu->hdev, btrtl_dev, in h5_btrtl_setup()
918 skb = __hci_cmd_sync(h5->hu->hdev, 0xfc17, sizeof(baudrate_data), in h5_btrtl_setup()
921 rtl_dev_err(h5->hu->hdev, "set baud rate command failed\n"); in h5_btrtl_setup()
930 serdev_device_set_baudrate(h5->hu->serdev, controller_baudrate); in h5_btrtl_setup()
931 serdev_device_set_flow_control(h5->hu->serdev, flow_control); in h5_btrtl_setup()
934 set_bit(H5_HW_FLOW_CONTROL, &h5->flags); in h5_btrtl_setup()
936 err = btrtl_download_firmware(h5->hu->hdev, btrtl_dev); in h5_btrtl_setup()
940 btrtl_set_quirks(h5->hu->hdev, btrtl_dev); in h5_btrtl_setup()
948 static void h5_btrtl_open(struct h5 *h5) in h5_btrtl_open() argument
955 if (test_bit(H5_WAKEUP_DISABLE, &h5->flags)) in h5_btrtl_open()
956 set_bit(HCI_UART_NO_SUSPEND_NOTIFIER, &h5->hu->flags); in h5_btrtl_open()
959 serdev_device_set_flow_control(h5->hu->serdev, false); in h5_btrtl_open()
960 serdev_device_set_parity(h5->hu->serdev, SERDEV_PARITY_EVEN); in h5_btrtl_open()
961 serdev_device_set_baudrate(h5->hu->serdev, 115200); in h5_btrtl_open()
963 if (!test_bit(H5_WAKEUP_DISABLE, &h5->flags)) { in h5_btrtl_open()
964 pm_runtime_set_active(&h5->hu->serdev->dev); in h5_btrtl_open()
965 pm_runtime_use_autosuspend(&h5->hu->serdev->dev); in h5_btrtl_open()
966 pm_runtime_set_autosuspend_delay(&h5->hu->serdev->dev, in h5_btrtl_open()
968 pm_runtime_enable(&h5->hu->serdev->dev); in h5_btrtl_open()
972 gpiod_set_value_cansleep(h5->enable_gpio, 0); in h5_btrtl_open()
973 gpiod_set_value_cansleep(h5->device_wake_gpio, 0); in h5_btrtl_open()
977 gpiod_set_value_cansleep(h5->enable_gpio, 1); in h5_btrtl_open()
978 gpiod_set_value_cansleep(h5->device_wake_gpio, 1); in h5_btrtl_open()
982 static void h5_btrtl_close(struct h5 *h5) in h5_btrtl_close() argument
984 if (!test_bit(H5_WAKEUP_DISABLE, &h5->flags)) in h5_btrtl_close()
985 pm_runtime_disable(&h5->hu->serdev->dev); in h5_btrtl_close()
987 gpiod_set_value_cansleep(h5->device_wake_gpio, 0); in h5_btrtl_close()
988 gpiod_set_value_cansleep(h5->enable_gpio, 0); in h5_btrtl_close()
997 static int h5_btrtl_suspend(struct h5 *h5) in h5_btrtl_suspend() argument
999 serdev_device_set_flow_control(h5->hu->serdev, false); in h5_btrtl_suspend()
1000 gpiod_set_value_cansleep(h5->device_wake_gpio, 0); in h5_btrtl_suspend()
1002 if (test_bit(H5_WAKEUP_DISABLE, &h5->flags)) in h5_btrtl_suspend()
1003 gpiod_set_value_cansleep(h5->enable_gpio, 0); in h5_btrtl_suspend()
1028 static int h5_btrtl_resume(struct h5 *h5) in h5_btrtl_resume() argument
1030 if (test_bit(H5_WAKEUP_DISABLE, &h5->flags)) { in h5_btrtl_resume()
1040 reprobe->dev = get_device(&h5->hu->serdev->dev); in h5_btrtl_resume()
1043 gpiod_set_value_cansleep(h5->device_wake_gpio, 1); in h5_btrtl_resume()
1045 if (test_bit(H5_HW_FLOW_CONTROL, &h5->flags)) in h5_btrtl_resume()
1046 serdev_device_set_flow_control(h5->hu->serdev, true); in h5_btrtl_resume()