Lines Matching refs:h5

72 struct h5 {  struct
115 int (*setup)(struct h5 *h5); argument
116 void (*open)(struct h5 *h5);
117 void (*close)(struct h5 *h5);
121 static void h5_reset_rx(struct h5 *h5);
125 struct h5 *h5 = hu->priv; in h5_link_control() local
136 skb_queue_tail(&h5->unrel, nskb); in h5_link_control()
139 static u8 h5_cfg_field(struct h5 *h5) in h5_cfg_field() argument
142 return h5->tx_win & 0x07; in h5_cfg_field()
149 struct h5 *h5 = from_timer(h5, t, timer); in h5_timed_event() local
150 struct hci_uart *hu = h5->hu; in h5_timed_event()
156 if (h5->state == H5_UNINITIALIZED) in h5_timed_event()
159 if (h5->state == H5_INITIALIZED) { in h5_timed_event()
160 conf_req[2] = h5_cfg_field(h5); in h5_timed_event()
164 if (h5->state != H5_ACTIVE) { in h5_timed_event()
165 mod_timer(&h5->timer, jiffies + H5_SYNC_TIMEOUT); in h5_timed_event()
169 if (h5->sleep != H5_AWAKE) { in h5_timed_event()
170 h5->sleep = H5_SLEEPING; in h5_timed_event()
174 BT_DBG("hu %p retransmitting %u pkts", hu, h5->unack.qlen); in h5_timed_event()
176 spin_lock_irqsave_nested(&h5->unack.lock, flags, SINGLE_DEPTH_NESTING); in h5_timed_event()
178 while ((skb = __skb_dequeue_tail(&h5->unack)) != NULL) { in h5_timed_event()
179 h5->tx_seq = (h5->tx_seq - 1) & 0x07; in h5_timed_event()
180 skb_queue_head(&h5->rel, skb); in h5_timed_event()
183 spin_unlock_irqrestore(&h5->unack.lock, flags); in h5_timed_event()
191 struct h5 *h5 = hu->priv; in h5_peer_reset() local
195 h5->state = H5_UNINITIALIZED; in h5_peer_reset()
197 del_timer(&h5->timer); in h5_peer_reset()
199 skb_queue_purge(&h5->rel); in h5_peer_reset()
200 skb_queue_purge(&h5->unrel); in h5_peer_reset()
201 skb_queue_purge(&h5->unack); in h5_peer_reset()
203 h5->tx_seq = 0; in h5_peer_reset()
204 h5->tx_ack = 0; in h5_peer_reset()
212 struct h5 *h5; in h5_open() local
218 h5 = serdev_device_get_drvdata(hu->serdev); in h5_open()
220 h5 = kzalloc(sizeof(*h5), GFP_KERNEL); in h5_open()
221 if (!h5) in h5_open()
225 hu->priv = h5; in h5_open()
226 h5->hu = hu; in h5_open()
228 skb_queue_head_init(&h5->unack); in h5_open()
229 skb_queue_head_init(&h5->rel); in h5_open()
230 skb_queue_head_init(&h5->unrel); in h5_open()
232 h5_reset_rx(h5); in h5_open()
234 timer_setup(&h5->timer, h5_timed_event, 0); in h5_open()
236 h5->tx_win = H5_TX_WIN_MAX; in h5_open()
238 if (h5->vnd && h5->vnd->open) in h5_open()
239 h5->vnd->open(h5); in h5_open()
245 mod_timer(&h5->timer, jiffies + H5_SYNC_TIMEOUT); in h5_open()
252 struct h5 *h5 = hu->priv; in h5_close() local
254 del_timer_sync(&h5->timer); in h5_close()
256 skb_queue_purge(&h5->unack); in h5_close()
257 skb_queue_purge(&h5->rel); in h5_close()
258 skb_queue_purge(&h5->unrel); in h5_close()
260 if (h5->vnd && h5->vnd->close) in h5_close()
261 h5->vnd->close(h5); in h5_close()
264 kfree(h5); in h5_close()
271 struct h5 *h5 = hu->priv; in h5_setup() local
273 if (h5->vnd && h5->vnd->setup) in h5_setup()
274 return h5->vnd->setup(h5); in h5_setup()
279 static void h5_pkt_cull(struct h5 *h5) in h5_pkt_cull() argument
286 spin_lock_irqsave(&h5->unack.lock, flags); in h5_pkt_cull()
288 to_remove = skb_queue_len(&h5->unack); in h5_pkt_cull()
292 seq = h5->tx_seq; in h5_pkt_cull()
295 if (h5->rx_ack == seq) in h5_pkt_cull()
302 if (seq != h5->rx_ack) in h5_pkt_cull()
306 skb_queue_walk_safe(&h5->unack, skb, tmp) { in h5_pkt_cull()
310 __skb_unlink(skb, &h5->unack); in h5_pkt_cull()
314 if (skb_queue_empty(&h5->unack)) in h5_pkt_cull()
315 del_timer(&h5->timer); in h5_pkt_cull()
318 spin_unlock_irqrestore(&h5->unack.lock, flags); in h5_pkt_cull()
323 struct h5 *h5 = hu->priv; in h5_handle_internal_rx() local
331 const unsigned char *hdr = h5->rx_skb->data; in h5_handle_internal_rx()
332 const unsigned char *data = &h5->rx_skb->data[4]; in h5_handle_internal_rx()
342 conf_req[2] = h5_cfg_field(h5); in h5_handle_internal_rx()
345 if (h5->state == H5_ACTIVE) in h5_handle_internal_rx()
349 if (h5->state == H5_ACTIVE) in h5_handle_internal_rx()
351 h5->state = H5_INITIALIZED; in h5_handle_internal_rx()
358 h5->tx_win = (data[2] & 0x07); in h5_handle_internal_rx()
359 BT_DBG("Three-wire init complete. tx_win %u", h5->tx_win); in h5_handle_internal_rx()
360 h5->state = H5_ACTIVE; in h5_handle_internal_rx()
365 h5->sleep = H5_SLEEPING; in h5_handle_internal_rx()
369 h5->sleep = H5_AWAKE; in h5_handle_internal_rx()
373 h5->sleep = H5_AWAKE; in h5_handle_internal_rx()
384 struct h5 *h5 = hu->priv; in h5_complete_rx_pkt() local
385 const unsigned char *hdr = h5->rx_skb->data; in h5_complete_rx_pkt()
388 h5->tx_ack = (h5->tx_ack + 1) % 8; in h5_complete_rx_pkt()
389 set_bit(H5_TX_ACK_REQ, &h5->flags); in h5_complete_rx_pkt()
393 h5->rx_ack = H5_HDR_ACK(hdr); in h5_complete_rx_pkt()
395 h5_pkt_cull(h5); in h5_complete_rx_pkt()
401 hci_skb_pkt_type(h5->rx_skb) = H5_HDR_PKT_TYPE(hdr); in h5_complete_rx_pkt()
404 skb_pull(h5->rx_skb, 4); in h5_complete_rx_pkt()
406 hci_recv_frame(hu->hdev, h5->rx_skb); in h5_complete_rx_pkt()
407 h5->rx_skb = NULL; in h5_complete_rx_pkt()
416 h5_reset_rx(h5); in h5_complete_rx_pkt()
428 struct h5 *h5 = hu->priv; in h5_rx_payload() local
429 const unsigned char *hdr = h5->rx_skb->data; in h5_rx_payload()
432 h5->rx_func = h5_rx_crc; in h5_rx_payload()
433 h5->rx_pending = 2; in h5_rx_payload()
443 struct h5 *h5 = hu->priv; in h5_rx_3wire_hdr() local
444 const unsigned char *hdr = h5->rx_skb->data; in h5_rx_3wire_hdr()
453 h5_reset_rx(h5); in h5_rx_3wire_hdr()
457 if (H5_HDR_RELIABLE(hdr) && H5_HDR_SEQ(hdr) != h5->tx_ack) { in h5_rx_3wire_hdr()
459 H5_HDR_SEQ(hdr), h5->tx_ack); in h5_rx_3wire_hdr()
460 h5_reset_rx(h5); in h5_rx_3wire_hdr()
464 if (h5->state != H5_ACTIVE && in h5_rx_3wire_hdr()
467 h5_reset_rx(h5); in h5_rx_3wire_hdr()
471 h5->rx_func = h5_rx_payload; in h5_rx_3wire_hdr()
472 h5->rx_pending = H5_HDR_LEN(hdr); in h5_rx_3wire_hdr()
479 struct h5 *h5 = hu->priv; in h5_rx_pkt_start() local
484 h5->rx_func = h5_rx_3wire_hdr; in h5_rx_pkt_start()
485 h5->rx_pending = 4; in h5_rx_pkt_start()
487 h5->rx_skb = bt_skb_alloc(H5_MAX_LEN, GFP_ATOMIC); in h5_rx_pkt_start()
488 if (!h5->rx_skb) { in h5_rx_pkt_start()
490 h5_reset_rx(h5); in h5_rx_pkt_start()
494 h5->rx_skb->dev = (void *)hu->hdev; in h5_rx_pkt_start()
501 struct h5 *h5 = hu->priv; in h5_rx_delimiter() local
504 h5->rx_func = h5_rx_pkt_start; in h5_rx_delimiter()
509 static void h5_unslip_one_byte(struct h5 *h5, unsigned char c) in h5_unslip_one_byte() argument
514 if (!test_bit(H5_RX_ESC, &h5->flags) && c == SLIP_ESC) { in h5_unslip_one_byte()
515 set_bit(H5_RX_ESC, &h5->flags); in h5_unslip_one_byte()
519 if (test_and_clear_bit(H5_RX_ESC, &h5->flags)) { in h5_unslip_one_byte()
529 h5_reset_rx(h5); in h5_unslip_one_byte()
534 skb_put_data(h5->rx_skb, byte, 1); in h5_unslip_one_byte()
535 h5->rx_pending--; in h5_unslip_one_byte()
537 BT_DBG("unsliped 0x%02hhx, rx_pending %zu", *byte, h5->rx_pending); in h5_unslip_one_byte()
540 static void h5_reset_rx(struct h5 *h5) in h5_reset_rx() argument
542 if (h5->rx_skb) { in h5_reset_rx()
543 kfree_skb(h5->rx_skb); in h5_reset_rx()
544 h5->rx_skb = NULL; in h5_reset_rx()
547 h5->rx_func = h5_rx_delimiter; in h5_reset_rx()
548 h5->rx_pending = 0; in h5_reset_rx()
549 clear_bit(H5_RX_ESC, &h5->flags); in h5_reset_rx()
554 struct h5 *h5 = hu->priv; in h5_recv() local
557 BT_DBG("%s pending %zu count %d", hu->hdev->name, h5->rx_pending, in h5_recv()
563 if (h5->rx_pending > 0) { in h5_recv()
566 h5_reset_rx(h5); in h5_recv()
570 h5_unslip_one_byte(h5, *ptr); in h5_recv()
576 processed = h5->rx_func(hu, *ptr); in h5_recv()
589 struct h5 *h5 = hu->priv; in h5_enqueue() local
597 if (h5->state != H5_ACTIVE) { in h5_enqueue()
606 skb_queue_tail(&h5->rel, skb); in h5_enqueue()
610 skb_queue_tail(&h5->unrel, skb); in h5_enqueue()
663 struct h5 *h5 = hu->priv; in h5_prepare_pkt() local
687 hdr[0] = h5->tx_ack << 3; in h5_prepare_pkt()
688 clear_bit(H5_TX_ACK_REQ, &h5->flags); in h5_prepare_pkt()
693 hdr[0] |= h5->tx_seq; in h5_prepare_pkt()
694 h5->tx_seq = (h5->tx_seq + 1) % 8; in h5_prepare_pkt()
719 struct h5 *h5 = hu->priv; in h5_dequeue() local
723 if (h5->sleep != H5_AWAKE) { in h5_dequeue()
726 if (h5->sleep == H5_WAKING_UP) in h5_dequeue()
729 h5->sleep = H5_WAKING_UP; in h5_dequeue()
732 mod_timer(&h5->timer, jiffies + HZ / 100); in h5_dequeue()
736 skb = skb_dequeue(&h5->unrel); in h5_dequeue()
745 skb_queue_head(&h5->unrel, skb); in h5_dequeue()
749 spin_lock_irqsave_nested(&h5->unack.lock, flags, SINGLE_DEPTH_NESTING); in h5_dequeue()
751 if (h5->unack.qlen >= h5->tx_win) in h5_dequeue()
754 skb = skb_dequeue(&h5->rel); in h5_dequeue()
759 __skb_queue_tail(&h5->unack, skb); in h5_dequeue()
760 mod_timer(&h5->timer, jiffies + H5_ACK_TIMEOUT); in h5_dequeue()
761 spin_unlock_irqrestore(&h5->unack.lock, flags); in h5_dequeue()
765 skb_queue_head(&h5->rel, skb); in h5_dequeue()
770 spin_unlock_irqrestore(&h5->unack.lock, flags); in h5_dequeue()
772 if (test_bit(H5_TX_ACK_REQ, &h5->flags)) in h5_dequeue()
800 struct h5 *h5; in h5_serdev_probe() local
802 h5 = devm_kzalloc(dev, sizeof(*h5), GFP_KERNEL); in h5_serdev_probe()
803 if (!h5) in h5_serdev_probe()
806 set_bit(HCI_UART_RESET_ON_INIT, &h5->serdev_hu.flags); in h5_serdev_probe()
808 h5->hu = &h5->serdev_hu; in h5_serdev_probe()
809 h5->serdev_hu.serdev = serdev; in h5_serdev_probe()
810 serdev_device_set_drvdata(serdev, h5); in h5_serdev_probe()
817 h5->vnd = (const struct h5_vnd *)match->driver_data; in h5_serdev_probe()
818 h5->id = (char *)match->id; in h5_serdev_probe()
820 if (h5->vnd->acpi_gpio_map) in h5_serdev_probe()
822 h5->vnd->acpi_gpio_map); in h5_serdev_probe()
825 h5->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW); in h5_serdev_probe()
826 if (IS_ERR(h5->enable_gpio)) in h5_serdev_probe()
827 return PTR_ERR(h5->enable_gpio); in h5_serdev_probe()
829 h5->device_wake_gpio = devm_gpiod_get_optional(dev, "device-wake", in h5_serdev_probe()
831 if (IS_ERR(h5->device_wake_gpio)) in h5_serdev_probe()
832 return PTR_ERR(h5->device_wake_gpio); in h5_serdev_probe()
834 return hci_uart_register_device(&h5->serdev_hu, &h5p); in h5_serdev_probe()
839 struct h5 *h5 = serdev_device_get_drvdata(serdev); in h5_serdev_remove() local
841 hci_uart_unregister_device(&h5->serdev_hu); in h5_serdev_remove()
845 static int h5_btrtl_setup(struct h5 *h5) in h5_btrtl_setup() argument
855 btrtl_dev = btrtl_initialize(h5->hu->hdev, h5->id); in h5_btrtl_setup()
859 err = btrtl_get_uart_settings(h5->hu->hdev, btrtl_dev, in h5_btrtl_setup()
866 skb = __hci_cmd_sync(h5->hu->hdev, 0xfc17, sizeof(baudrate_data), in h5_btrtl_setup()
869 rtl_dev_err(h5->hu->hdev, "set baud rate command failed\n"); in h5_btrtl_setup()
878 serdev_device_set_baudrate(h5->hu->serdev, controller_baudrate); in h5_btrtl_setup()
879 serdev_device_set_flow_control(h5->hu->serdev, flow_control); in h5_btrtl_setup()
881 err = btrtl_download_firmware(h5->hu->hdev, btrtl_dev); in h5_btrtl_setup()
891 static void h5_btrtl_open(struct h5 *h5) in h5_btrtl_open() argument
894 serdev_device_set_flow_control(h5->hu->serdev, false); in h5_btrtl_open()
895 serdev_device_set_parity(h5->hu->serdev, SERDEV_PARITY_EVEN); in h5_btrtl_open()
896 serdev_device_set_baudrate(h5->hu->serdev, 115200); in h5_btrtl_open()
899 gpiod_set_value_cansleep(h5->enable_gpio, 1); in h5_btrtl_open()
900 gpiod_set_value_cansleep(h5->device_wake_gpio, 1); in h5_btrtl_open()
904 static void h5_btrtl_close(struct h5 *h5) in h5_btrtl_close() argument
906 gpiod_set_value_cansleep(h5->device_wake_gpio, 0); in h5_btrtl_close()
907 gpiod_set_value_cansleep(h5->enable_gpio, 0); in h5_btrtl_close()