Lines Matching refs:bdev
144 #define btmtkuart_is_standalone(bdev) \ argument
145 ((bdev)->data->flags & BTMTKUART_FLAG_STANDALONE_HW)
146 #define btmtkuart_is_builtin_soc(bdev) \ argument
147 !((bdev)->data->flags & BTMTKUART_FLAG_STANDALONE_HW)
152 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in mtk_hci_wmt_sync() local
173 set_bit(BTMTKUART_TX_WAIT_VND_EVT, &bdev->tx_state); in mtk_hci_wmt_sync()
177 clear_bit(BTMTKUART_TX_WAIT_VND_EVT, &bdev->tx_state); in mtk_hci_wmt_sync()
190 err = wait_on_bit_timeout(&bdev->tx_state, BTMTKUART_TX_WAIT_VND_EVT, in mtk_hci_wmt_sync()
194 clear_bit(BTMTKUART_TX_WAIT_VND_EVT, &bdev->tx_state); in mtk_hci_wmt_sync()
200 clear_bit(BTMTKUART_TX_WAIT_VND_EVT, &bdev->tx_state); in mtk_hci_wmt_sync()
206 wmt_evt = (struct btmtk_hci_wmt_evt *)bdev->evt_skb->data; in mtk_hci_wmt_sync()
236 kfree_skb(bdev->evt_skb); in mtk_hci_wmt_sync()
237 bdev->evt_skb = NULL; in mtk_hci_wmt_sync()
320 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_recv_event() local
334 if (test_bit(BTMTKUART_TX_WAIT_VND_EVT, &bdev->tx_state)) { in btmtkuart_recv_event()
335 bdev->evt_skb = skb_clone(skb, GFP_KERNEL); in btmtkuart_recv_event()
336 if (!bdev->evt_skb) { in btmtkuart_recv_event()
348 &bdev->tx_state)) { in btmtkuart_recv_event()
351 wake_up_bit(&bdev->tx_state, BTMTKUART_TX_WAIT_VND_EVT); in btmtkuart_recv_event()
358 kfree_skb(bdev->evt_skb); in btmtkuart_recv_event()
359 bdev->evt_skb = NULL; in btmtkuart_recv_event()
373 struct btmtkuart_dev *bdev = container_of(work, struct btmtkuart_dev, in btmtkuart_tx_work() local
375 struct serdev_device *serdev = bdev->serdev; in btmtkuart_tx_work()
376 struct hci_dev *hdev = bdev->hdev; in btmtkuart_tx_work()
379 clear_bit(BTMTKUART_TX_STATE_WAKEUP, &bdev->tx_state); in btmtkuart_tx_work()
382 struct sk_buff *skb = skb_dequeue(&bdev->txq); in btmtkuart_tx_work()
394 skb_queue_head(&bdev->txq, skb); in btmtkuart_tx_work()
413 if (!test_bit(BTMTKUART_TX_STATE_WAKEUP, &bdev->tx_state)) in btmtkuart_tx_work()
417 clear_bit(BTMTKUART_TX_STATE_ACTIVE, &bdev->tx_state); in btmtkuart_tx_work()
420 static void btmtkuart_tx_wakeup(struct btmtkuart_dev *bdev) in btmtkuart_tx_wakeup() argument
422 if (test_and_set_bit(BTMTKUART_TX_STATE_ACTIVE, &bdev->tx_state)) in btmtkuart_tx_wakeup()
423 set_bit(BTMTKUART_TX_STATE_WAKEUP, &bdev->tx_state); in btmtkuart_tx_wakeup()
425 schedule_work(&bdev->tx_work); in btmtkuart_tx_wakeup()
429 mtk_stp_split(struct btmtkuart_dev *bdev, const unsigned char *data, int count, in mtk_stp_split() argument
435 if (!bdev->stp_dlen && bdev->stp_cursor >= 6) in mtk_stp_split()
436 bdev->stp_cursor = 0; in mtk_stp_split()
439 while (bdev->stp_cursor < 6 && count > 0) { in mtk_stp_split()
440 bdev->stp_pad[bdev->stp_cursor] = *data; in mtk_stp_split()
441 bdev->stp_cursor++; in mtk_stp_split()
447 if (!bdev->stp_dlen && bdev->stp_cursor >= 6) { in mtk_stp_split()
448 shdr = (struct mtk_stp_hdr *)&bdev->stp_pad[2]; in mtk_stp_split()
449 bdev->stp_dlen = be16_to_cpu(shdr->dlen) & 0x0fff; in mtk_stp_split()
452 if (shdr->prefix != 0x80 || bdev->stp_dlen > 2048) { in mtk_stp_split()
453 bt_dev_err(bdev->hdev, "stp format unexpect (%d, %d)", in mtk_stp_split()
454 shdr->prefix, bdev->stp_dlen); in mtk_stp_split()
455 bdev->stp_cursor = 2; in mtk_stp_split()
456 bdev->stp_dlen = 0; in mtk_stp_split()
465 *sz_h4 = min_t(int, count, bdev->stp_dlen); in mtk_stp_split()
468 bdev->stp_dlen -= *sz_h4; in mtk_stp_split()
476 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_recv() local
497 p_h4 = mtk_stp_split(bdev, p_left, sz_left, &sz_h4); in btmtkuart_recv()
505 bdev->rx_skb = h4_recv_buf(bdev->hdev, bdev->rx_skb, p_h4, in btmtkuart_recv()
508 if (IS_ERR(bdev->rx_skb)) { in btmtkuart_recv()
509 err = PTR_ERR(bdev->rx_skb); in btmtkuart_recv()
510 bt_dev_err(bdev->hdev, in btmtkuart_recv()
512 bdev->rx_skb = NULL; in btmtkuart_recv()
526 struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev); in btmtkuart_receive_buf() local
529 err = btmtkuart_recv(bdev->hdev, data, count); in btmtkuart_receive_buf()
533 bdev->hdev->stat.byte_rx += count; in btmtkuart_receive_buf()
540 struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev); in btmtkuart_write_wakeup() local
542 btmtkuart_tx_wakeup(bdev); in btmtkuart_write_wakeup()
552 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_open() local
556 err = serdev_device_open(bdev->serdev); in btmtkuart_open()
559 dev_name(&bdev->serdev->dev)); in btmtkuart_open()
563 if (btmtkuart_is_standalone(bdev)) { in btmtkuart_open()
564 if (bdev->curr_speed != bdev->desired_speed) in btmtkuart_open()
565 err = serdev_device_set_baudrate(bdev->serdev, in btmtkuart_open()
568 err = serdev_device_set_baudrate(bdev->serdev, in btmtkuart_open()
569 bdev->desired_speed); in btmtkuart_open()
573 dev_name(&bdev->serdev->dev)); in btmtkuart_open()
577 serdev_device_set_flow_control(bdev->serdev, false); in btmtkuart_open()
580 bdev->stp_cursor = 2; in btmtkuart_open()
581 bdev->stp_dlen = 0; in btmtkuart_open()
583 dev = &bdev->serdev->dev; in btmtkuart_open()
591 err = clk_prepare_enable(bdev->clk); in btmtkuart_open()
602 serdev_device_close(bdev->serdev); in btmtkuart_open()
609 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_close() local
610 struct device *dev = &bdev->serdev->dev; in btmtkuart_close()
613 clk_disable_unprepare(bdev->clk); in btmtkuart_close()
617 serdev_device_close(bdev->serdev); in btmtkuart_close()
624 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_flush() local
627 serdev_device_write_flush(bdev->serdev); in btmtkuart_flush()
628 skb_queue_purge(&bdev->txq); in btmtkuart_flush()
630 cancel_work_sync(&bdev->tx_work); in btmtkuart_flush()
632 kfree_skb(bdev->rx_skb); in btmtkuart_flush()
633 bdev->rx_skb = NULL; in btmtkuart_flush()
635 bdev->stp_cursor = 2; in btmtkuart_flush()
636 bdev->stp_dlen = 0; in btmtkuart_flush()
665 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_change_baudrate() local
674 baudrate = cpu_to_le32(bdev->desired_speed); in btmtkuart_change_baudrate()
687 err = serdev_device_set_baudrate(bdev->serdev, in btmtkuart_change_baudrate()
688 bdev->desired_speed); in btmtkuart_change_baudrate()
695 serdev_device_set_flow_control(bdev->serdev, false); in btmtkuart_change_baudrate()
699 err = serdev_device_write_buf(bdev->serdev, ¶m, sizeof(param)); in btmtkuart_change_baudrate()
703 serdev_device_wait_until_sent(bdev->serdev, 0); in btmtkuart_change_baudrate()
722 bdev->curr_speed = bdev->desired_speed; in btmtkuart_change_baudrate()
729 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_setup() local
743 if (test_bit(BTMTKUART_REQUIRED_WAKEUP, &bdev->tx_state)) { in btmtkuart_setup()
756 clear_bit(BTMTKUART_REQUIRED_WAKEUP, &bdev->tx_state); in btmtkuart_setup()
759 if (btmtkuart_is_standalone(bdev)) in btmtkuart_setup()
781 err = mtk_setup_firmware(hdev, bdev->data->fwname); in btmtkuart_setup()
866 struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); in btmtkuart_send_frame() local
892 skb_queue_tail(&bdev->txq, skb); in btmtkuart_send_frame()
894 btmtkuart_tx_wakeup(bdev); in btmtkuart_send_frame()
900 struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev); in btmtkuart_parse_dt() local
905 if (btmtkuart_is_standalone(bdev)) { in btmtkuart_parse_dt()
908 bdev->desired_speed = speed; in btmtkuart_parse_dt()
910 bdev->vcc = devm_regulator_get(&serdev->dev, "vcc"); in btmtkuart_parse_dt()
911 if (IS_ERR(bdev->vcc)) { in btmtkuart_parse_dt()
912 err = PTR_ERR(bdev->vcc); in btmtkuart_parse_dt()
916 bdev->osc = devm_clk_get_optional(&serdev->dev, "osc"); in btmtkuart_parse_dt()
917 if (IS_ERR(bdev->osc)) { in btmtkuart_parse_dt()
918 err = PTR_ERR(bdev->osc); in btmtkuart_parse_dt()
922 bdev->boot = devm_gpiod_get_optional(&serdev->dev, "boot", in btmtkuart_parse_dt()
924 if (IS_ERR(bdev->boot)) { in btmtkuart_parse_dt()
925 err = PTR_ERR(bdev->boot); in btmtkuart_parse_dt()
929 bdev->pinctrl = devm_pinctrl_get(&serdev->dev); in btmtkuart_parse_dt()
930 if (IS_ERR(bdev->pinctrl)) { in btmtkuart_parse_dt()
931 err = PTR_ERR(bdev->pinctrl); in btmtkuart_parse_dt()
935 bdev->pins_boot = pinctrl_lookup_state(bdev->pinctrl, in btmtkuart_parse_dt()
937 if (IS_ERR(bdev->pins_boot) && !bdev->boot) { in btmtkuart_parse_dt()
938 err = PTR_ERR(bdev->pins_boot); in btmtkuart_parse_dt()
944 bdev->pins_runtime = pinctrl_lookup_state(bdev->pinctrl, in btmtkuart_parse_dt()
946 if (IS_ERR(bdev->pins_runtime)) { in btmtkuart_parse_dt()
947 err = PTR_ERR(bdev->pins_runtime); in btmtkuart_parse_dt()
951 bdev->reset = devm_gpiod_get_optional(&serdev->dev, "reset", in btmtkuart_parse_dt()
953 if (IS_ERR(bdev->reset)) { in btmtkuart_parse_dt()
954 err = PTR_ERR(bdev->reset); in btmtkuart_parse_dt()
957 } else if (btmtkuart_is_builtin_soc(bdev)) { in btmtkuart_parse_dt()
958 bdev->clk = devm_clk_get(&serdev->dev, "ref"); in btmtkuart_parse_dt()
959 if (IS_ERR(bdev->clk)) in btmtkuart_parse_dt()
960 return PTR_ERR(bdev->clk); in btmtkuart_parse_dt()
968 struct btmtkuart_dev *bdev; in btmtkuart_probe() local
972 bdev = devm_kzalloc(&serdev->dev, sizeof(*bdev), GFP_KERNEL); in btmtkuart_probe()
973 if (!bdev) in btmtkuart_probe()
976 bdev->data = of_device_get_match_data(&serdev->dev); in btmtkuart_probe()
977 if (!bdev->data) in btmtkuart_probe()
980 bdev->serdev = serdev; in btmtkuart_probe()
981 serdev_device_set_drvdata(serdev, bdev); in btmtkuart_probe()
989 INIT_WORK(&bdev->tx_work, btmtkuart_tx_work); in btmtkuart_probe()
990 skb_queue_head_init(&bdev->txq); in btmtkuart_probe()
999 bdev->hdev = hdev; in btmtkuart_probe()
1002 hci_set_drvdata(hdev, bdev); in btmtkuart_probe()
1015 if (btmtkuart_is_standalone(bdev)) { in btmtkuart_probe()
1016 err = clk_prepare_enable(bdev->osc); in btmtkuart_probe()
1020 if (bdev->boot) { in btmtkuart_probe()
1021 gpiod_set_value_cansleep(bdev->boot, 1); in btmtkuart_probe()
1026 pinctrl_select_state(bdev->pinctrl, bdev->pins_boot); in btmtkuart_probe()
1030 err = regulator_enable(bdev->vcc); in btmtkuart_probe()
1037 if (bdev->reset) { in btmtkuart_probe()
1038 gpiod_set_value_cansleep(bdev->reset, 1); in btmtkuart_probe()
1040 gpiod_set_value_cansleep(bdev->reset, 0); in btmtkuart_probe()
1048 if (bdev->boot) in btmtkuart_probe()
1049 devm_gpiod_put(&serdev->dev, bdev->boot); in btmtkuart_probe()
1051 pinctrl_select_state(bdev->pinctrl, bdev->pins_runtime); in btmtkuart_probe()
1058 set_bit(BTMTKUART_REQUIRED_WAKEUP, &bdev->tx_state); in btmtkuart_probe()
1070 if (btmtkuart_is_standalone(bdev)) in btmtkuart_probe()
1071 regulator_disable(bdev->vcc); in btmtkuart_probe()
1073 if (btmtkuart_is_standalone(bdev)) in btmtkuart_probe()
1074 clk_disable_unprepare(bdev->osc); in btmtkuart_probe()
1083 struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev); in btmtkuart_remove() local
1084 struct hci_dev *hdev = bdev->hdev; in btmtkuart_remove()
1086 if (btmtkuart_is_standalone(bdev)) { in btmtkuart_remove()
1087 regulator_disable(bdev->vcc); in btmtkuart_remove()
1088 clk_disable_unprepare(bdev->osc); in btmtkuart_remove()