Lines Matching full:h5

52 /* H5 state flags */
58 struct h5 { struct
101 int (*setup)(struct h5 *h5); argument
102 void (*open)(struct h5 *h5);
103 void (*close)(struct h5 *h5);
104 int (*suspend)(struct h5 *h5);
105 int (*resume)(struct h5 *h5);
109 static void h5_reset_rx(struct h5 *h5);
113 struct h5 *h5 = hu->priv; in h5_link_control() local
124 skb_queue_tail(&h5->unrel, nskb); in h5_link_control()
127 static u8 h5_cfg_field(struct h5 *h5) in h5_cfg_field() argument
130 return h5->tx_win & 0x07; in h5_cfg_field()
137 struct h5 *h5 = from_timer(h5, t, timer); in h5_timed_event() local
138 struct hci_uart *hu = h5->hu; in h5_timed_event()
144 if (h5->state == H5_UNINITIALIZED) in h5_timed_event()
147 if (h5->state == H5_INITIALIZED) { in h5_timed_event()
148 conf_req[2] = h5_cfg_field(h5); in h5_timed_event()
152 if (h5->state != H5_ACTIVE) { in h5_timed_event()
153 mod_timer(&h5->timer, jiffies + H5_SYNC_TIMEOUT); in h5_timed_event()
157 if (h5->sleep != H5_AWAKE) { in h5_timed_event()
158 h5->sleep = H5_SLEEPING; in h5_timed_event()
162 BT_DBG("hu %p retransmitting %u pkts", hu, h5->unack.qlen); in h5_timed_event()
164 spin_lock_irqsave_nested(&h5->unack.lock, flags, SINGLE_DEPTH_NESTING); in h5_timed_event()
166 while ((skb = __skb_dequeue_tail(&h5->unack)) != NULL) { in h5_timed_event()
167 h5->tx_seq = (h5->tx_seq - 1) & 0x07; in h5_timed_event()
168 skb_queue_head(&h5->rel, skb); in h5_timed_event()
171 spin_unlock_irqrestore(&h5->unack.lock, flags); in h5_timed_event()
179 struct h5 *h5 = hu->priv; in h5_peer_reset() local
183 h5->state = H5_UNINITIALIZED; in h5_peer_reset()
185 del_timer(&h5->timer); in h5_peer_reset()
187 skb_queue_purge(&h5->rel); in h5_peer_reset()
188 skb_queue_purge(&h5->unrel); in h5_peer_reset()
189 skb_queue_purge(&h5->unack); in h5_peer_reset()
191 h5->tx_seq = 0; in h5_peer_reset()
192 h5->tx_ack = 0; in h5_peer_reset()
200 struct h5 *h5; in h5_open() local
206 h5 = serdev_device_get_drvdata(hu->serdev); in h5_open()
208 h5 = kzalloc(sizeof(*h5), GFP_KERNEL); in h5_open()
209 if (!h5) in h5_open()
213 hu->priv = h5; in h5_open()
214 h5->hu = hu; in h5_open()
216 skb_queue_head_init(&h5->unack); in h5_open()
217 skb_queue_head_init(&h5->rel); in h5_open()
218 skb_queue_head_init(&h5->unrel); in h5_open()
220 h5_reset_rx(h5); in h5_open()
222 timer_setup(&h5->timer, h5_timed_event, 0); in h5_open()
224 h5->tx_win = H5_TX_WIN_MAX; in h5_open()
226 if (h5->vnd && h5->vnd->open) in h5_open()
227 h5->vnd->open(h5); in h5_open()
233 mod_timer(&h5->timer, jiffies + H5_SYNC_TIMEOUT); in h5_open()
240 struct h5 *h5 = hu->priv; in h5_close() local
242 del_timer_sync(&h5->timer); in h5_close()
244 skb_queue_purge(&h5->unack); in h5_close()
245 skb_queue_purge(&h5->rel); in h5_close()
246 skb_queue_purge(&h5->unrel); in h5_close()
248 if (h5->vnd && h5->vnd->close) in h5_close()
249 h5->vnd->close(h5); in h5_close()
252 kfree(h5); in h5_close()
259 struct h5 *h5 = hu->priv; in h5_setup() local
261 if (h5->vnd && h5->vnd->setup) in h5_setup()
262 return h5->vnd->setup(h5); in h5_setup()
267 static void h5_pkt_cull(struct h5 *h5) in h5_pkt_cull() argument
274 spin_lock_irqsave(&h5->unack.lock, flags); in h5_pkt_cull()
276 to_remove = skb_queue_len(&h5->unack); in h5_pkt_cull()
280 seq = h5->tx_seq; in h5_pkt_cull()
283 if (h5->rx_ack == seq) in h5_pkt_cull()
290 if (seq != h5->rx_ack) in h5_pkt_cull()
294 skb_queue_walk_safe(&h5->unack, skb, tmp) { in h5_pkt_cull()
298 __skb_unlink(skb, &h5->unack); in h5_pkt_cull()
302 if (skb_queue_empty(&h5->unack)) in h5_pkt_cull()
303 del_timer(&h5->timer); in h5_pkt_cull()
306 spin_unlock_irqrestore(&h5->unack.lock, flags); in h5_pkt_cull()
311 struct h5 *h5 = hu->priv; in h5_handle_internal_rx() local
319 const unsigned char *hdr = h5->rx_skb->data; in h5_handle_internal_rx()
320 const unsigned char *data = &h5->rx_skb->data[4]; in h5_handle_internal_rx()
330 conf_req[2] = h5_cfg_field(h5); in h5_handle_internal_rx()
333 if (h5->state == H5_ACTIVE) in h5_handle_internal_rx()
337 if (h5->state == H5_ACTIVE) in h5_handle_internal_rx()
339 h5->state = H5_INITIALIZED; in h5_handle_internal_rx()
346 h5->tx_win = (data[2] & 0x07); in h5_handle_internal_rx()
347 BT_DBG("Three-wire init complete. tx_win %u", h5->tx_win); in h5_handle_internal_rx()
348 h5->state = H5_ACTIVE; in h5_handle_internal_rx()
353 h5->sleep = H5_SLEEPING; in h5_handle_internal_rx()
357 h5->sleep = H5_AWAKE; in h5_handle_internal_rx()
361 h5->sleep = H5_AWAKE; in h5_handle_internal_rx()
372 struct h5 *h5 = hu->priv; in h5_complete_rx_pkt() local
373 const unsigned char *hdr = h5->rx_skb->data; in h5_complete_rx_pkt()
376 h5->tx_ack = (h5->tx_ack + 1) % 8; in h5_complete_rx_pkt()
377 set_bit(H5_TX_ACK_REQ, &h5->flags); in h5_complete_rx_pkt()
381 h5->rx_ack = H5_HDR_ACK(hdr); in h5_complete_rx_pkt()
383 h5_pkt_cull(h5); in h5_complete_rx_pkt()
390 hci_skb_pkt_type(h5->rx_skb) = H5_HDR_PKT_TYPE(hdr); in h5_complete_rx_pkt()
393 skb_pull(h5->rx_skb, 4); in h5_complete_rx_pkt()
395 hci_recv_frame(hu->hdev, h5->rx_skb); in h5_complete_rx_pkt()
396 h5->rx_skb = NULL; in h5_complete_rx_pkt()
405 h5_reset_rx(h5); in h5_complete_rx_pkt()
417 struct h5 *h5 = hu->priv; in h5_rx_payload() local
418 const unsigned char *hdr = h5->rx_skb->data; in h5_rx_payload()
421 h5->rx_func = h5_rx_crc; in h5_rx_payload()
422 h5->rx_pending = 2; in h5_rx_payload()
432 struct h5 *h5 = hu->priv; in h5_rx_3wire_hdr() local
433 const unsigned char *hdr = h5->rx_skb->data; in h5_rx_3wire_hdr()
442 h5_reset_rx(h5); in h5_rx_3wire_hdr()
446 if (H5_HDR_RELIABLE(hdr) && H5_HDR_SEQ(hdr) != h5->tx_ack) { in h5_rx_3wire_hdr()
448 H5_HDR_SEQ(hdr), h5->tx_ack); in h5_rx_3wire_hdr()
449 h5_reset_rx(h5); in h5_rx_3wire_hdr()
453 if (h5->state != H5_ACTIVE && in h5_rx_3wire_hdr()
456 h5_reset_rx(h5); in h5_rx_3wire_hdr()
460 h5->rx_func = h5_rx_payload; in h5_rx_3wire_hdr()
461 h5->rx_pending = H5_HDR_LEN(hdr); in h5_rx_3wire_hdr()
468 struct h5 *h5 = hu->priv; in h5_rx_pkt_start() local
473 h5->rx_func = h5_rx_3wire_hdr; in h5_rx_pkt_start()
474 h5->rx_pending = 4; in h5_rx_pkt_start()
476 h5->rx_skb = bt_skb_alloc(H5_MAX_LEN, GFP_ATOMIC); in h5_rx_pkt_start()
477 if (!h5->rx_skb) { in h5_rx_pkt_start()
479 h5_reset_rx(h5); in h5_rx_pkt_start()
483 h5->rx_skb->dev = (void *)hu->hdev; in h5_rx_pkt_start()
490 struct h5 *h5 = hu->priv; in h5_rx_delimiter() local
493 h5->rx_func = h5_rx_pkt_start; in h5_rx_delimiter()
498 static void h5_unslip_one_byte(struct h5 *h5, unsigned char c) in h5_unslip_one_byte() argument
503 if (!test_bit(H5_RX_ESC, &h5->flags) && c == SLIP_ESC) { in h5_unslip_one_byte()
504 set_bit(H5_RX_ESC, &h5->flags); in h5_unslip_one_byte()
508 if (test_and_clear_bit(H5_RX_ESC, &h5->flags)) { in h5_unslip_one_byte()
518 h5_reset_rx(h5); in h5_unslip_one_byte()
523 skb_put_data(h5->rx_skb, byte, 1); in h5_unslip_one_byte()
524 h5->rx_pending--; in h5_unslip_one_byte()
526 BT_DBG("unslipped 0x%02hhx, rx_pending %zu", *byte, h5->rx_pending); in h5_unslip_one_byte()
529 static void h5_reset_rx(struct h5 *h5) in h5_reset_rx() argument
531 if (h5->rx_skb) { in h5_reset_rx()
532 kfree_skb(h5->rx_skb); in h5_reset_rx()
533 h5->rx_skb = NULL; in h5_reset_rx()
536 h5->rx_func = h5_rx_delimiter; in h5_reset_rx()
537 h5->rx_pending = 0; in h5_reset_rx()
538 clear_bit(H5_RX_ESC, &h5->flags); in h5_reset_rx()
543 struct h5 *h5 = hu->priv; in h5_recv() local
546 BT_DBG("%s pending %zu count %d", hu->hdev->name, h5->rx_pending, in h5_recv()
552 if (h5->rx_pending > 0) { in h5_recv()
554 bt_dev_err(hu->hdev, "Too short H5 packet"); in h5_recv()
555 h5_reset_rx(h5); in h5_recv()
559 h5_unslip_one_byte(h5, *ptr); in h5_recv()
565 processed = h5->rx_func(hu, *ptr); in h5_recv()
578 struct h5 *h5 = hu->priv; in h5_enqueue() local
586 if (h5->state != H5_ACTIVE) { in h5_enqueue()
595 skb_queue_tail(&h5->rel, skb); in h5_enqueue()
600 skb_queue_tail(&h5->unrel, skb); in h5_enqueue()
654 struct h5 *h5 = hu->priv; in h5_prepare_pkt() local
665 * Max len of packet: (original len + 4 (H5 hdr) + 2 (crc)) * 2 in h5_prepare_pkt()
678 hdr[0] = h5->tx_ack << 3; in h5_prepare_pkt()
679 clear_bit(H5_TX_ACK_REQ, &h5->flags); in h5_prepare_pkt()
684 hdr[0] |= h5->tx_seq; in h5_prepare_pkt()
685 h5->tx_seq = (h5->tx_seq + 1) % 8; in h5_prepare_pkt()
710 struct h5 *h5 = hu->priv; in h5_dequeue() local
714 if (h5->sleep != H5_AWAKE) { in h5_dequeue()
717 if (h5->sleep == H5_WAKING_UP) in h5_dequeue()
720 h5->sleep = H5_WAKING_UP; in h5_dequeue()
723 mod_timer(&h5->timer, jiffies + HZ / 100); in h5_dequeue()
727 skb = skb_dequeue(&h5->unrel); in h5_dequeue()
736 skb_queue_head(&h5->unrel, skb); in h5_dequeue()
740 spin_lock_irqsave_nested(&h5->unack.lock, flags, SINGLE_DEPTH_NESTING); in h5_dequeue()
742 if (h5->unack.qlen >= h5->tx_win) in h5_dequeue()
745 skb = skb_dequeue(&h5->rel); in h5_dequeue()
750 __skb_queue_tail(&h5->unack, skb); in h5_dequeue()
751 mod_timer(&h5->timer, jiffies + H5_ACK_TIMEOUT); in h5_dequeue()
752 spin_unlock_irqrestore(&h5->unack.lock, flags); in h5_dequeue()
756 skb_queue_head(&h5->rel, skb); in h5_dequeue()
761 spin_unlock_irqrestore(&h5->unack.lock, flags); in h5_dequeue()
763 if (test_bit(H5_TX_ACK_REQ, &h5->flags)) in h5_dequeue()
777 .name = "Three-wire (H5)",
790 struct h5 *h5; in h5_serdev_probe() local
792 h5 = devm_kzalloc(dev, sizeof(*h5), GFP_KERNEL); in h5_serdev_probe()
793 if (!h5) in h5_serdev_probe()
796 h5->hu = &h5->serdev_hu; in h5_serdev_probe()
797 h5->serdev_hu.serdev = serdev; in h5_serdev_probe()
798 serdev_device_set_drvdata(serdev, h5); in h5_serdev_probe()
807 h5->vnd = (const struct h5_vnd *)match->driver_data; in h5_serdev_probe()
808 h5->id = (char *)match->id; in h5_serdev_probe()
810 if (h5->vnd->acpi_gpio_map) in h5_serdev_probe()
812 h5->vnd->acpi_gpio_map); in h5_serdev_probe()
820 h5->vnd = (const struct h5_vnd *)data; in h5_serdev_probe()
824 h5->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW); in h5_serdev_probe()
825 if (IS_ERR(h5->enable_gpio)) in h5_serdev_probe()
826 return PTR_ERR(h5->enable_gpio); in h5_serdev_probe()
828 h5->device_wake_gpio = devm_gpiod_get_optional(dev, "device-wake", in h5_serdev_probe()
830 if (IS_ERR(h5->device_wake_gpio)) in h5_serdev_probe()
831 return PTR_ERR(h5->device_wake_gpio); in h5_serdev_probe()
833 return hci_uart_register_device(&h5->serdev_hu, &h5p); in h5_serdev_probe()
838 struct h5 *h5 = serdev_device_get_drvdata(serdev); in h5_serdev_remove() local
840 hci_uart_unregister_device(&h5->serdev_hu); in h5_serdev_remove()
845 struct h5 *h5 = dev_get_drvdata(dev); in h5_serdev_suspend() local
848 if (h5->vnd && h5->vnd->suspend) in h5_serdev_suspend()
849 ret = h5->vnd->suspend(h5); in h5_serdev_suspend()
856 struct h5 *h5 = dev_get_drvdata(dev); in h5_serdev_resume() local
859 if (h5->vnd && h5->vnd->resume) in h5_serdev_resume()
860 ret = h5->vnd->resume(h5); in h5_serdev_resume()
866 static int h5_btrtl_setup(struct h5 *h5) in h5_btrtl_setup() argument
876 btrtl_dev = btrtl_initialize(h5->hu->hdev, h5->id); in h5_btrtl_setup()
880 err = btrtl_get_uart_settings(h5->hu->hdev, btrtl_dev, in h5_btrtl_setup()
887 skb = __hci_cmd_sync(h5->hu->hdev, 0xfc17, sizeof(baudrate_data), in h5_btrtl_setup()
890 rtl_dev_err(h5->hu->hdev, "set baud rate command failed\n"); in h5_btrtl_setup()
899 serdev_device_set_baudrate(h5->hu->serdev, controller_baudrate); in h5_btrtl_setup()
900 serdev_device_set_flow_control(h5->hu->serdev, flow_control); in h5_btrtl_setup()
902 err = btrtl_download_firmware(h5->hu->hdev, btrtl_dev); in h5_btrtl_setup()
912 static void h5_btrtl_open(struct h5 *h5) in h5_btrtl_open() argument
915 serdev_device_set_flow_control(h5->hu->serdev, false); in h5_btrtl_open()
916 serdev_device_set_parity(h5->hu->serdev, SERDEV_PARITY_EVEN); in h5_btrtl_open()
917 serdev_device_set_baudrate(h5->hu->serdev, 115200); in h5_btrtl_open()
920 gpiod_set_value_cansleep(h5->enable_gpio, 1); in h5_btrtl_open()
921 gpiod_set_value_cansleep(h5->device_wake_gpio, 1); in h5_btrtl_open()
925 static void h5_btrtl_close(struct h5 *h5) in h5_btrtl_close() argument
927 gpiod_set_value_cansleep(h5->device_wake_gpio, 0); in h5_btrtl_close()
928 gpiod_set_value_cansleep(h5->enable_gpio, 0); in h5_btrtl_close()
937 static int h5_btrtl_suspend(struct h5 *h5) in h5_btrtl_suspend() argument
939 serdev_device_set_flow_control(h5->hu->serdev, false); in h5_btrtl_suspend()
940 gpiod_set_value_cansleep(h5->device_wake_gpio, 0); in h5_btrtl_suspend()
941 gpiod_set_value_cansleep(h5->enable_gpio, 0); in h5_btrtl_suspend()
965 static int h5_btrtl_resume(struct h5 *h5) in h5_btrtl_resume() argument
976 reprobe->dev = get_device(&h5->hu->serdev->dev); in h5_btrtl_resume()