Lines Matching refs:bdev

83 #define btmtkuart_is_standalone(bdev)	\  argument
84 ((bdev)->data->flags & BTMTKUART_FLAG_STANDALONE_HW)
85 #define btmtkuart_is_builtin_soc(bdev) \ argument
86 !((bdev)->data->flags & BTMTKUART_FLAG_STANDALONE_HW)
91 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in mtk_hci_wmt_sync() local
119 set_bit(BTMTKUART_TX_WAIT_VND_EVT, &bdev->tx_state); in mtk_hci_wmt_sync()
123 clear_bit(BTMTKUART_TX_WAIT_VND_EVT, &bdev->tx_state); in mtk_hci_wmt_sync()
136 err = wait_on_bit_timeout(&bdev->tx_state, BTMTKUART_TX_WAIT_VND_EVT, in mtk_hci_wmt_sync()
140 clear_bit(BTMTKUART_TX_WAIT_VND_EVT, &bdev->tx_state); in mtk_hci_wmt_sync()
146 clear_bit(BTMTKUART_TX_WAIT_VND_EVT, &bdev->tx_state); in mtk_hci_wmt_sync()
152 wmt_evt = (struct btmtk_hci_wmt_evt *)bdev->evt_skb->data; in mtk_hci_wmt_sync()
184 kfree_skb(bdev->evt_skb); in mtk_hci_wmt_sync()
185 bdev->evt_skb = NULL; in mtk_hci_wmt_sync()
192 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_recv_event() local
199 if (test_bit(BTMTKUART_TX_WAIT_VND_EVT, &bdev->tx_state)) { in btmtkuart_recv_event()
200 bdev->evt_skb = skb_clone(skb, GFP_KERNEL); in btmtkuart_recv_event()
201 if (!bdev->evt_skb) { in btmtkuart_recv_event()
213 &bdev->tx_state)) { in btmtkuart_recv_event()
216 wake_up_bit(&bdev->tx_state, BTMTKUART_TX_WAIT_VND_EVT); in btmtkuart_recv_event()
223 kfree_skb(bdev->evt_skb); in btmtkuart_recv_event()
224 bdev->evt_skb = NULL; in btmtkuart_recv_event()
238 struct btmtkuart_dev *bdev = container_of(work, struct btmtkuart_dev, in btmtkuart_tx_work() local
240 struct serdev_device *serdev = bdev->serdev; in btmtkuart_tx_work()
241 struct hci_dev *hdev = bdev->hdev; in btmtkuart_tx_work()
244 clear_bit(BTMTKUART_TX_STATE_WAKEUP, &bdev->tx_state); in btmtkuart_tx_work()
247 struct sk_buff *skb = skb_dequeue(&bdev->txq); in btmtkuart_tx_work()
259 skb_queue_head(&bdev->txq, skb); in btmtkuart_tx_work()
278 if (!test_bit(BTMTKUART_TX_STATE_WAKEUP, &bdev->tx_state)) in btmtkuart_tx_work()
282 clear_bit(BTMTKUART_TX_STATE_ACTIVE, &bdev->tx_state); in btmtkuart_tx_work()
285 static void btmtkuart_tx_wakeup(struct btmtkuart_dev *bdev) in btmtkuart_tx_wakeup() argument
287 if (test_and_set_bit(BTMTKUART_TX_STATE_ACTIVE, &bdev->tx_state)) in btmtkuart_tx_wakeup()
288 set_bit(BTMTKUART_TX_STATE_WAKEUP, &bdev->tx_state); in btmtkuart_tx_wakeup()
290 schedule_work(&bdev->tx_work); in btmtkuart_tx_wakeup()
294 mtk_stp_split(struct btmtkuart_dev *bdev, const unsigned char *data, int count, in mtk_stp_split() argument
300 if (!bdev->stp_dlen && bdev->stp_cursor >= 6) in mtk_stp_split()
301 bdev->stp_cursor = 0; in mtk_stp_split()
304 while (bdev->stp_cursor < 6 && count > 0) { in mtk_stp_split()
305 bdev->stp_pad[bdev->stp_cursor] = *data; in mtk_stp_split()
306 bdev->stp_cursor++; in mtk_stp_split()
312 if (!bdev->stp_dlen && bdev->stp_cursor >= 6) { in mtk_stp_split()
313 shdr = (struct mtk_stp_hdr *)&bdev->stp_pad[2]; in mtk_stp_split()
314 bdev->stp_dlen = be16_to_cpu(shdr->dlen) & 0x0fff; in mtk_stp_split()
317 if (shdr->prefix != 0x80 || bdev->stp_dlen > 2048) { in mtk_stp_split()
318 bt_dev_err(bdev->hdev, "stp format unexpect (%d, %d)", in mtk_stp_split()
319 shdr->prefix, bdev->stp_dlen); in mtk_stp_split()
320 bdev->stp_cursor = 2; in mtk_stp_split()
321 bdev->stp_dlen = 0; in mtk_stp_split()
330 *sz_h4 = min_t(int, count, bdev->stp_dlen); in mtk_stp_split()
333 bdev->stp_dlen -= *sz_h4; in mtk_stp_split()
341 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_recv() local
362 p_h4 = mtk_stp_split(bdev, p_left, sz_left, &sz_h4); in btmtkuart_recv()
370 bdev->rx_skb = h4_recv_buf(bdev->hdev, bdev->rx_skb, p_h4, in btmtkuart_recv()
373 if (IS_ERR(bdev->rx_skb)) { in btmtkuart_recv()
374 err = PTR_ERR(bdev->rx_skb); in btmtkuart_recv()
375 bt_dev_err(bdev->hdev, in btmtkuart_recv()
377 bdev->rx_skb = NULL; in btmtkuart_recv()
389 struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev); in btmtkuart_receive_buf() local
391 btmtkuart_recv(bdev->hdev, data, count); in btmtkuart_receive_buf()
393 bdev->hdev->stat.byte_rx += count; in btmtkuart_receive_buf()
400 struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev); in btmtkuart_write_wakeup() local
402 btmtkuart_tx_wakeup(bdev); in btmtkuart_write_wakeup()
412 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_open() local
416 err = serdev_device_open(bdev->serdev); in btmtkuart_open()
419 dev_name(&bdev->serdev->dev)); in btmtkuart_open()
423 if (btmtkuart_is_standalone(bdev)) { in btmtkuart_open()
424 if (bdev->curr_speed != bdev->desired_speed) in btmtkuart_open()
425 err = serdev_device_set_baudrate(bdev->serdev, in btmtkuart_open()
428 err = serdev_device_set_baudrate(bdev->serdev, in btmtkuart_open()
429 bdev->desired_speed); in btmtkuart_open()
433 dev_name(&bdev->serdev->dev)); in btmtkuart_open()
437 serdev_device_set_flow_control(bdev->serdev, false); in btmtkuart_open()
440 bdev->stp_cursor = 2; in btmtkuart_open()
441 bdev->stp_dlen = 0; in btmtkuart_open()
443 dev = &bdev->serdev->dev; in btmtkuart_open()
451 err = clk_prepare_enable(bdev->clk); in btmtkuart_open()
462 serdev_device_close(bdev->serdev); in btmtkuart_open()
469 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_close() local
470 struct device *dev = &bdev->serdev->dev; in btmtkuart_close()
473 clk_disable_unprepare(bdev->clk); in btmtkuart_close()
477 serdev_device_close(bdev->serdev); in btmtkuart_close()
484 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_flush() local
487 serdev_device_write_flush(bdev->serdev); in btmtkuart_flush()
488 skb_queue_purge(&bdev->txq); in btmtkuart_flush()
490 cancel_work_sync(&bdev->tx_work); in btmtkuart_flush()
492 kfree_skb(bdev->rx_skb); in btmtkuart_flush()
493 bdev->rx_skb = NULL; in btmtkuart_flush()
495 bdev->stp_cursor = 2; in btmtkuart_flush()
496 bdev->stp_dlen = 0; in btmtkuart_flush()
525 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_change_baudrate() local
534 baudrate = cpu_to_le32(bdev->desired_speed); in btmtkuart_change_baudrate()
547 err = serdev_device_set_baudrate(bdev->serdev, in btmtkuart_change_baudrate()
548 bdev->desired_speed); in btmtkuart_change_baudrate()
555 serdev_device_set_flow_control(bdev->serdev, false); in btmtkuart_change_baudrate()
559 err = serdev_device_write_buf(bdev->serdev, &param, sizeof(param)); in btmtkuart_change_baudrate()
563 serdev_device_wait_until_sent(bdev->serdev, 0); in btmtkuart_change_baudrate()
582 bdev->curr_speed = bdev->desired_speed; in btmtkuart_change_baudrate()
589 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_setup() local
603 if (test_bit(BTMTKUART_REQUIRED_WAKEUP, &bdev->tx_state)) { in btmtkuart_setup()
616 clear_bit(BTMTKUART_REQUIRED_WAKEUP, &bdev->tx_state); in btmtkuart_setup()
619 if (btmtkuart_is_standalone(bdev)) in btmtkuart_setup()
641 err = btmtk_setup_firmware(hdev, bdev->data->fwname, mtk_hci_wmt_sync); in btmtkuart_setup()
726 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_send_frame() local
752 skb_queue_tail(&bdev->txq, skb); in btmtkuart_send_frame()
754 btmtkuart_tx_wakeup(bdev); in btmtkuart_send_frame()
760 struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev); in btmtkuart_parse_dt() local
765 if (btmtkuart_is_standalone(bdev)) { in btmtkuart_parse_dt()
768 bdev->desired_speed = speed; in btmtkuart_parse_dt()
770 bdev->vcc = devm_regulator_get(&serdev->dev, "vcc"); in btmtkuart_parse_dt()
771 if (IS_ERR(bdev->vcc)) { in btmtkuart_parse_dt()
772 err = PTR_ERR(bdev->vcc); in btmtkuart_parse_dt()
776 bdev->osc = devm_clk_get_optional(&serdev->dev, "osc"); in btmtkuart_parse_dt()
777 if (IS_ERR(bdev->osc)) { in btmtkuart_parse_dt()
778 err = PTR_ERR(bdev->osc); in btmtkuart_parse_dt()
782 bdev->boot = devm_gpiod_get_optional(&serdev->dev, "boot", in btmtkuart_parse_dt()
784 if (IS_ERR(bdev->boot)) { in btmtkuart_parse_dt()
785 err = PTR_ERR(bdev->boot); in btmtkuart_parse_dt()
789 bdev->pinctrl = devm_pinctrl_get(&serdev->dev); in btmtkuart_parse_dt()
790 if (IS_ERR(bdev->pinctrl)) { in btmtkuart_parse_dt()
791 err = PTR_ERR(bdev->pinctrl); in btmtkuart_parse_dt()
795 bdev->pins_boot = pinctrl_lookup_state(bdev->pinctrl, in btmtkuart_parse_dt()
797 if (IS_ERR(bdev->pins_boot) && !bdev->boot) { in btmtkuart_parse_dt()
798 err = PTR_ERR(bdev->pins_boot); in btmtkuart_parse_dt()
804 bdev->pins_runtime = pinctrl_lookup_state(bdev->pinctrl, in btmtkuart_parse_dt()
806 if (IS_ERR(bdev->pins_runtime)) { in btmtkuart_parse_dt()
807 err = PTR_ERR(bdev->pins_runtime); in btmtkuart_parse_dt()
811 bdev->reset = devm_gpiod_get_optional(&serdev->dev, "reset", in btmtkuart_parse_dt()
813 if (IS_ERR(bdev->reset)) { in btmtkuart_parse_dt()
814 err = PTR_ERR(bdev->reset); in btmtkuart_parse_dt()
817 } else if (btmtkuart_is_builtin_soc(bdev)) { in btmtkuart_parse_dt()
818 bdev->clk = devm_clk_get(&serdev->dev, "ref"); in btmtkuart_parse_dt()
819 if (IS_ERR(bdev->clk)) in btmtkuart_parse_dt()
820 return PTR_ERR(bdev->clk); in btmtkuart_parse_dt()
828 struct btmtkuart_dev *bdev; in btmtkuart_probe() local
832 bdev = devm_kzalloc(&serdev->dev, sizeof(*bdev), GFP_KERNEL); in btmtkuart_probe()
833 if (!bdev) in btmtkuart_probe()
836 bdev->data = of_device_get_match_data(&serdev->dev); in btmtkuart_probe()
837 if (!bdev->data) in btmtkuart_probe()
840 bdev->serdev = serdev; in btmtkuart_probe()
841 serdev_device_set_drvdata(serdev, bdev); in btmtkuart_probe()
849 INIT_WORK(&bdev->tx_work, btmtkuart_tx_work); in btmtkuart_probe()
850 skb_queue_head_init(&bdev->txq); in btmtkuart_probe()
859 bdev->hdev = hdev; in btmtkuart_probe()
862 hci_set_drvdata(hdev, bdev); in btmtkuart_probe()
876 if (btmtkuart_is_standalone(bdev)) { in btmtkuart_probe()
877 err = clk_prepare_enable(bdev->osc); in btmtkuart_probe()
881 if (bdev->boot) { in btmtkuart_probe()
882 gpiod_set_value_cansleep(bdev->boot, 1); in btmtkuart_probe()
887 pinctrl_select_state(bdev->pinctrl, bdev->pins_boot); in btmtkuart_probe()
891 err = regulator_enable(bdev->vcc); in btmtkuart_probe()
898 if (bdev->reset) { in btmtkuart_probe()
899 gpiod_set_value_cansleep(bdev->reset, 1); in btmtkuart_probe()
901 gpiod_set_value_cansleep(bdev->reset, 0); in btmtkuart_probe()
909 if (bdev->boot) in btmtkuart_probe()
910 devm_gpiod_put(&serdev->dev, bdev->boot); in btmtkuart_probe()
912 pinctrl_select_state(bdev->pinctrl, bdev->pins_runtime); in btmtkuart_probe()
919 set_bit(BTMTKUART_REQUIRED_WAKEUP, &bdev->tx_state); in btmtkuart_probe()
931 if (btmtkuart_is_standalone(bdev)) in btmtkuart_probe()
932 regulator_disable(bdev->vcc); in btmtkuart_probe()
934 if (btmtkuart_is_standalone(bdev)) in btmtkuart_probe()
935 clk_disable_unprepare(bdev->osc); in btmtkuart_probe()
944 struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev); in btmtkuart_remove() local
945 struct hci_dev *hdev = bdev->hdev; in btmtkuart_remove()
947 if (btmtkuart_is_standalone(bdev)) { in btmtkuart_remove()
948 regulator_disable(bdev->vcc); in btmtkuart_remove()
949 clk_disable_unprepare(bdev->osc); in btmtkuart_remove()