Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next

Johan Hedberg says:

====================
pull request: bluetooth-next 2019-03-02

Here's one more bluetooth-next pull request for the 5.1 kernel:

- Added support for MediaTek MT7663U and MT7668U UART devices
- Cleanups & fixes to the hci_qca driver
- Fixed wakeup pin behavior for QCA6174A controller

Please let me know if there are any issues pulling. Thanks.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+478 -97
+3
Documentation/devicetree/bindings/net/btusb.txt
··· 9 9 (more may be added later) are: 10 10 11 11 "usb1286,204e" (Marvell 8997) 12 + "usbcf3,e300" (Qualcomm QCA6174A) 13 + "usb4ca,301a" (Qualcomm QCA6174A (Lite-On)) 14 + 12 15 13 16 Also, vendors that use btusb may have device additional properties, e.g: 14 17 Documentation/devicetree/bindings/net/marvell-bt-8xxx.txt
+64
Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
··· 33 33 clock-names = "ref"; 34 34 }; 35 35 }; 36 + 37 + MediaTek UART based Bluetooth Devices 38 + ================================== 39 + 40 + This device is a serial attached device to UART device and thus it must be a 41 + child node of the serial node with UART. 42 + 43 + Please refer to the following documents for generic properties: 44 + 45 + Documentation/devicetree/bindings/serial/slave-device.txt 46 + 47 + Required properties: 48 + 49 + - compatible: Must be 50 + "mediatek,mt7663u-bluetooth": for MT7663U device 51 + "mediatek,mt7668u-bluetooth": for MT7668U device 52 + - vcc-supply: Main voltage regulator 53 + - pinctrl-names: Should be "default", "runtime" 54 + - pinctrl-0: Should contain UART RXD low when the device is powered up to 55 + enter proper bootstrap mode. 56 + - pinctrl-1: Should contain UART mode pin ctrl 57 + 58 + Optional properties: 59 + 60 + - reset-gpios: GPIO used to reset the device whose initial state keeps low, 61 + if the GPIO is missing, then board-level design should be 62 + guaranteed. 63 + - current-speed: Current baud rate of the device whose defaults to 921600 64 + 65 + Example: 66 + 67 + uart1_pins_boot: uart1-default { 68 + pins-dat { 69 + pinmux = <MT7623_PIN_81_URXD1_FUNC_GPIO81>; 70 + output-low; 71 + }; 72 + }; 73 + 74 + uart1_pins_runtime: uart1-runtime { 75 + pins-dat { 76 + pinmux = <MT7623_PIN_81_URXD1_FUNC_URXD1>, 77 + <MT7623_PIN_82_UTXD1_FUNC_UTXD1>; 78 + }; 79 + }; 80 + 81 + uart1: serial@11003000 { 82 + compatible = "mediatek,mt7623-uart", 83 + "mediatek,mt6577-uart"; 84 + reg = <0 0x11003000 0 0x400>; 85 + interrupts = <GIC_SPI 52 IRQ_TYPE_LEVEL_LOW>; 86 + clocks = <&pericfg CLK_PERI_UART1_SEL>, 87 + <&pericfg CLK_PERI_UART1>; 88 + clock-names = "baud", "bus"; 89 + 90 + bluetooth { 91 + compatible = "mediatek,mt7663u-bluetooth"; 92 + vcc-supply = <&reg_5v>; 93 + reset-gpios = <&pio 24 GPIO_ACTIVE_LOW>; 94 + pinctrl-names = "default", "runtime"; 95 + pinctrl-0 = <&uart1_pins_boot>; 96 + pinctrl-1 = <&uart1_pins_runtime>; 97 + current-speed = <921600>; 98 + }; 99 + };
+13
arch/arm64/boot/dts/rockchip/rk3399-gru-chromebook.dtsi
··· 200 200 pinctrl-0 = <&bl_en>; 201 201 pwm-delay-us = <10000>; 202 202 }; 203 + 204 + gpio_keys: gpio-keys { 205 + compatible = "gpio-keys"; 206 + pinctrl-names = "default"; 207 + pinctrl-0 = <&bt_host_wake_l>; 208 + 209 + wake_on_bt: wake-on-bt { 210 + label = "Wake-on-Bluetooth"; 211 + gpios = <&gpio0 3 GPIO_ACTIVE_LOW>; 212 + linux,code = <KEY_WAKEUP>; 213 + wakeup-source; 214 + }; 215 + }; 203 216 }; 204 217 205 218 &ppvar_bigcpu {
+29 -17
arch/arm64/boot/dts/rockchip/rk3399-gru-scarlet.dtsi
··· 175 175 pinctrl-0 = <&dmic_en>; 176 176 wakeup-delay-ms = <250>; 177 177 }; 178 + 179 + gpio_keys: gpio-keys { 180 + compatible = "gpio-keys"; 181 + pinctrl-names = "default"; 182 + pinctrl-0 = <&pen_eject_odl>; 183 + 184 + pen-insert { 185 + label = "Pen Insert"; 186 + /* Insert = low, eject = high */ 187 + gpios = <&gpio1 1 GPIO_ACTIVE_LOW>; 188 + linux,code = <SW_PEN_INSERTED>; 189 + linux,input-type = <EV_SW>; 190 + wakeup-source; 191 + }; 192 + }; 178 193 }; 179 194 180 195 /* pp900_s0 aliases */ ··· 343 328 <400000000>; 344 329 }; 345 330 346 - &gpio_keys { 347 - pinctrl-names = "default"; 348 - pinctrl-0 = <&bt_host_wake_l>, <&pen_eject_odl>; 349 - 350 - pen-insert { 351 - label = "Pen Insert"; 352 - /* Insert = low, eject = high */ 353 - gpios = <&gpio1 1 GPIO_ACTIVE_LOW>; 354 - linux,code = <SW_PEN_INSERTED>; 355 - linux,input-type = <EV_SW>; 356 - wakeup-source; 357 - }; 358 - }; 359 - 360 331 &i2c_tunnel { 361 332 google,remote-bus = <0>; 362 333 }; ··· 438 437 status = "okay"; 439 438 }; 440 439 441 - &wake_on_bt { 442 - gpios = <&gpio1 2 GPIO_ACTIVE_LOW>; 440 + &usb_host0_ohci { 441 + #address-cells = <1>; 442 + #size-cells = <0>; 443 + 444 + qca_bt: bluetooth@1 { 445 + compatible = "usbcf3,e300", "usb4ca,301a"; 446 + reg = <1>; 447 + pinctrl-names = "default"; 448 + pinctrl-0 = <&bt_host_wake_l>; 449 + interrupt-parent = <&gpio1>; 450 + interrupts = <2 IRQ_TYPE_LEVEL_HIGH>; 451 + interrupt-names = "wakeup"; 452 + }; 443 453 }; 444 454 445 455 /* PINCTRL OVERRIDES */ ··· 467 455 }; 468 456 469 457 &bt_host_wake_l { 470 - rockchip,pins = <1 2 RK_FUNC_GPIO &pcfg_pull_up>; 458 + rockchip,pins = <1 2 RK_FUNC_GPIO &pcfg_pull_none>; 471 459 }; 472 460 473 461 &ec_ap_int_l {
-13
arch/arm64/boot/dts/rockchip/rk3399-gru.dtsi
··· 269 269 #clock-cells = <0>; 270 270 }; 271 271 272 - gpio_keys: gpio-keys { 273 - compatible = "gpio-keys"; 274 - pinctrl-names = "default"; 275 - pinctrl-0 = <&bt_host_wake_l>; 276 - 277 - wake_on_bt: wake-on-bt { 278 - label = "Wake-on-Bluetooth"; 279 - gpios = <&gpio0 3 GPIO_ACTIVE_LOW>; 280 - linux,code = <KEY_WAKEUP>; 281 - wakeup-source; 282 - }; 283 - }; 284 - 285 272 max98357a: max98357a { 286 273 compatible = "maxim,max98357a"; 287 274 pinctrl-names = "default";
+271 -10
drivers/bluetooth/btmtkuart.c
··· 12 12 #include <linux/atomic.h> 13 13 #include <linux/clk.h> 14 14 #include <linux/firmware.h> 15 + #include <linux/gpio/consumer.h> 15 16 #include <linux/iopoll.h> 16 17 #include <linux/kernel.h> 17 18 #include <linux/module.h> 18 19 #include <linux/of.h> 20 + #include <linux/of_device.h> 21 + #include <linux/pinctrl/consumer.h> 19 22 #include <linux/pm_runtime.h> 23 + #include <linux/regulator/consumer.h> 20 24 #include <linux/serdev.h> 21 25 #include <linux/skbuff.h> 22 26 ··· 29 25 30 26 #include "h4_recv.h" 31 27 32 - #define VERSION "0.1" 28 + #define VERSION "0.2" 33 29 34 30 #define FIRMWARE_MT7622 "mediatek/mt7622pr2h.bin" 31 + #define FIRMWARE_MT7663 "mediatek/mt7663pr2h.bin" 32 + #define FIRMWARE_MT7668 "mediatek/mt7668pr2h.bin" 35 33 36 34 #define MTK_STP_TLR_SIZE 2 37 35 38 36 #define BTMTKUART_TX_STATE_ACTIVE 1 39 37 #define BTMTKUART_TX_STATE_WAKEUP 2 40 38 #define BTMTKUART_TX_WAIT_VND_EVT 3 39 + #define BTMTKUART_REQUIRED_WAKEUP 4 40 + 41 + #define BTMTKUART_FLAG_STANDALONE_HW BIT(0) 41 42 42 43 enum { 43 44 MTK_WMT_PATCH_DWNLD = 0x1, 45 + MTK_WMT_TEST = 0x2, 46 + MTK_WMT_WAKEUP = 0x3, 47 + MTK_WMT_HIF = 0x4, 44 48 MTK_WMT_FUNC_CTRL = 0x6, 45 49 MTK_WMT_RST = 0x7, 46 50 MTK_WMT_SEMAPHORE = 0x17, ··· 68 56 __be16 dlen; 69 57 u8 cs; 70 58 } __packed; 59 + 60 + struct btmtkuart_data { 61 + unsigned int flags; 62 + const char *fwname; 63 + }; 71 64 72 65 struct mtk_wmt_hdr { 73 66 u8 dir; ··· 117 100 struct serdev_device *serdev; 118 101 struct clk *clk; 119 102 103 + struct regulator *vcc; 104 + struct gpio_desc *reset; 105 + struct pinctrl *pinctrl; 106 + struct pinctrl_state *pins_runtime; 107 + struct pinctrl_state *pins_boot; 108 + speed_t desired_speed; 109 + speed_t curr_speed; 110 + 120 111 struct work_struct tx_work; 121 112 unsigned long tx_state; 122 113 struct sk_buff_head txq; ··· 135 110 u8 stp_pad[6]; 136 111 u8 stp_cursor; 137 112 u16 stp_dlen; 113 + 114 + const struct btmtkuart_data *data; 138 115 }; 116 + 117 + #define btmtkuart_is_standalone(bdev) \ 118 + ((bdev)->data->flags & BTMTKUART_FLAG_STANDALONE_HW) 119 + #define btmtkuart_is_builtin_soc(bdev) \ 120 + !((bdev)->data->flags & BTMTKUART_FLAG_STANDALONE_HW) 139 121 140 122 static int mtk_hci_wmt_sync(struct hci_dev *hdev, 141 123 struct btmtk_hci_wmt_params *wmt_params) ··· 234 202 return err; 235 203 } 236 204 237 - static int mtk_setup_fw(struct hci_dev *hdev) 205 + static int mtk_setup_firmware(struct hci_dev *hdev, const char *fwname) 238 206 { 239 207 struct btmtk_hci_wmt_params wmt_params; 240 208 const struct firmware *fw; ··· 243 211 int err, dlen; 244 212 u8 flag; 245 213 246 - err = request_firmware(&fw, FIRMWARE_MT7622, &hdev->dev); 214 + err = request_firmware(&fw, fwname, &hdev->dev); 247 215 if (err < 0) { 248 216 bt_dev_err(hdev, "Failed to load firmware file (%d)", err); 249 217 return err; ··· 555 523 goto err_open; 556 524 } 557 525 526 + if (btmtkuart_is_standalone(bdev)) { 527 + if (bdev->curr_speed != bdev->desired_speed) 528 + err = serdev_device_set_baudrate(bdev->serdev, 529 + 115200); 530 + else 531 + err = serdev_device_set_baudrate(bdev->serdev, 532 + bdev->desired_speed); 533 + 534 + if (err < 0) { 535 + bt_dev_err(hdev, "Unable to set baudrate UART device %s", 536 + dev_name(&bdev->serdev->dev)); 537 + goto err_serdev_close; 538 + } 539 + 540 + serdev_device_set_flow_control(bdev->serdev, false); 541 + } 542 + 558 543 bdev->stp_cursor = 2; 559 544 bdev->stp_dlen = 0; 560 545 ··· 595 546 pm_runtime_put_sync(dev); 596 547 err_disable_rpm: 597 548 pm_runtime_disable(dev); 549 + err_serdev_close: 550 + serdev_device_close(bdev->serdev); 598 551 err_open: 599 552 return err; 600 553 } ··· 657 606 return status; 658 607 } 659 608 609 + static int btmtkuart_change_baudrate(struct hci_dev *hdev) 610 + { 611 + struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); 612 + struct btmtk_hci_wmt_params wmt_params; 613 + u32 baudrate; 614 + u8 param; 615 + int err; 616 + 617 + /* Indicate the device to enter the probe state the host is 618 + * ready to change a new baudrate. 619 + */ 620 + baudrate = cpu_to_le32(bdev->desired_speed); 621 + wmt_params.op = MTK_WMT_HIF; 622 + wmt_params.flag = 1; 623 + wmt_params.dlen = 4; 624 + wmt_params.data = &baudrate; 625 + wmt_params.status = NULL; 626 + 627 + err = mtk_hci_wmt_sync(hdev, &wmt_params); 628 + if (err < 0) { 629 + bt_dev_err(hdev, "Failed to device baudrate (%d)", err); 630 + return err; 631 + } 632 + 633 + err = serdev_device_set_baudrate(bdev->serdev, 634 + bdev->desired_speed); 635 + if (err < 0) { 636 + bt_dev_err(hdev, "Failed to set up host baudrate (%d)", 637 + err); 638 + return err; 639 + } 640 + 641 + serdev_device_set_flow_control(bdev->serdev, false); 642 + 643 + /* Send a dummy byte 0xff to activate the new baudrate */ 644 + param = 0xff; 645 + err = serdev_device_write(bdev->serdev, &param, sizeof(param), 646 + MAX_SCHEDULE_TIMEOUT); 647 + if (err < 0 || err < sizeof(param)) 648 + return err; 649 + 650 + serdev_device_wait_until_sent(bdev->serdev, 0); 651 + 652 + /* Wait some time for the device changing baudrate done */ 653 + usleep_range(20000, 22000); 654 + 655 + /* Test the new baudrate */ 656 + wmt_params.op = MTK_WMT_TEST; 657 + wmt_params.flag = 7; 658 + wmt_params.dlen = 0; 659 + wmt_params.data = NULL; 660 + wmt_params.status = NULL; 661 + 662 + err = mtk_hci_wmt_sync(hdev, &wmt_params); 663 + if (err < 0) { 664 + bt_dev_err(hdev, "Failed to test new baudrate (%d)", 665 + err); 666 + return err; 667 + } 668 + 669 + bdev->curr_speed = bdev->desired_speed; 670 + 671 + return 0; 672 + } 673 + 660 674 static int btmtkuart_setup(struct hci_dev *hdev) 661 675 { 676 + struct btmtkuart_dev *bdev = hci_get_drvdata(hdev); 662 677 struct btmtk_hci_wmt_params wmt_params; 663 678 ktime_t calltime, delta, rettime; 664 679 struct btmtk_tci_sleep tci_sleep; ··· 734 617 u8 param = 0x1; 735 618 736 619 calltime = ktime_get(); 620 + 621 + /* Wakeup MCUSYS is required for certain devices before we start to 622 + * do any setups. 623 + */ 624 + if (test_bit(BTMTKUART_REQUIRED_WAKEUP, &bdev->tx_state)) { 625 + wmt_params.op = MTK_WMT_WAKEUP; 626 + wmt_params.flag = 3; 627 + wmt_params.dlen = 0; 628 + wmt_params.data = NULL; 629 + wmt_params.status = NULL; 630 + 631 + err = mtk_hci_wmt_sync(hdev, &wmt_params); 632 + if (err < 0) { 633 + bt_dev_err(hdev, "Failed to wakeup the chip (%d)", err); 634 + return err; 635 + } 636 + 637 + clear_bit(BTMTKUART_REQUIRED_WAKEUP, &bdev->tx_state); 638 + } 639 + 640 + if (btmtkuart_is_standalone(bdev)) 641 + btmtkuart_change_baudrate(hdev); 737 642 738 643 /* Query whether the firmware is already download */ 739 644 wmt_params.op = MTK_WMT_SEMAPHORE; ··· 776 637 } 777 638 778 639 /* Setup a firmware which the device definitely requires */ 779 - err = mtk_setup_fw(hdev); 640 + err = mtk_setup_firmware(hdev, bdev->data->fwname); 780 641 if (err < 0) 781 642 return err; 782 643 ··· 893 754 return 0; 894 755 } 895 756 757 + static int btmtkuart_parse_dt(struct serdev_device *serdev) 758 + { 759 + struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev); 760 + struct device_node *node = serdev->dev.of_node; 761 + u32 speed = 921600; 762 + int err; 763 + 764 + if (btmtkuart_is_standalone(bdev)) { 765 + of_property_read_u32(node, "current-speed", &speed); 766 + 767 + bdev->desired_speed = speed; 768 + 769 + bdev->vcc = devm_regulator_get(&serdev->dev, "vcc"); 770 + if (IS_ERR(bdev->vcc)) { 771 + err = PTR_ERR(bdev->vcc); 772 + return err; 773 + } 774 + 775 + bdev->pinctrl = devm_pinctrl_get(&serdev->dev); 776 + if (IS_ERR(bdev->pinctrl)) { 777 + err = PTR_ERR(bdev->pinctrl); 778 + return err; 779 + } 780 + 781 + bdev->pins_boot = pinctrl_lookup_state(bdev->pinctrl, 782 + "default"); 783 + if (IS_ERR(bdev->pins_boot)) { 784 + err = PTR_ERR(bdev->pins_boot); 785 + return err; 786 + } 787 + 788 + bdev->pins_runtime = pinctrl_lookup_state(bdev->pinctrl, 789 + "runtime"); 790 + if (IS_ERR(bdev->pins_runtime)) { 791 + err = PTR_ERR(bdev->pins_runtime); 792 + return err; 793 + } 794 + 795 + bdev->reset = devm_gpiod_get_optional(&serdev->dev, "reset", 796 + GPIOD_OUT_LOW); 797 + if (IS_ERR(bdev->reset)) { 798 + err = PTR_ERR(bdev->reset); 799 + return err; 800 + } 801 + } else if (btmtkuart_is_builtin_soc(bdev)) { 802 + bdev->clk = devm_clk_get(&serdev->dev, "ref"); 803 + if (IS_ERR(bdev->clk)) 804 + return PTR_ERR(bdev->clk); 805 + } 806 + 807 + return 0; 808 + } 809 + 896 810 static int btmtkuart_probe(struct serdev_device *serdev) 897 811 { 898 812 struct btmtkuart_dev *bdev; 899 813 struct hci_dev *hdev; 814 + int err; 900 815 901 816 bdev = devm_kzalloc(&serdev->dev, sizeof(*bdev), GFP_KERNEL); 902 817 if (!bdev) 903 818 return -ENOMEM; 904 819 905 - bdev->clk = devm_clk_get(&serdev->dev, "ref"); 906 - if (IS_ERR(bdev->clk)) 907 - return PTR_ERR(bdev->clk); 820 + bdev->data = of_device_get_match_data(&serdev->dev); 821 + if (!bdev->data) 822 + return -ENODEV; 908 823 909 824 bdev->serdev = serdev; 910 825 serdev_device_set_drvdata(serdev, bdev); 911 826 912 827 serdev_device_set_client_ops(serdev, &btmtkuart_client_ops); 828 + 829 + err = btmtkuart_parse_dt(serdev); 830 + if (err < 0) 831 + return err; 913 832 914 833 INIT_WORK(&bdev->tx_work, btmtkuart_tx_work); 915 834 skb_queue_head_init(&bdev->txq); ··· 995 798 hdev->manufacturer = 70; 996 799 set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks); 997 800 998 - if (hci_register_dev(hdev) < 0) { 801 + if (btmtkuart_is_standalone(bdev)) { 802 + /* Switch to the specific pin state for the booting requires */ 803 + pinctrl_select_state(bdev->pinctrl, bdev->pins_boot); 804 + 805 + /* Power on */ 806 + err = regulator_enable(bdev->vcc); 807 + if (err < 0) 808 + return err; 809 + 810 + /* Reset if the reset-gpios is available otherwise the board 811 + * -level design should be guaranteed. 812 + */ 813 + if (bdev->reset) { 814 + gpiod_set_value_cansleep(bdev->reset, 1); 815 + usleep_range(1000, 2000); 816 + gpiod_set_value_cansleep(bdev->reset, 0); 817 + } 818 + 819 + /* Wait some time until device got ready and switch to the pin 820 + * mode the device requires for UART transfers. 821 + */ 822 + msleep(50); 823 + pinctrl_select_state(bdev->pinctrl, bdev->pins_runtime); 824 + 825 + /* A standalone device doesn't depends on power domain on SoC, 826 + * so mark it as no callbacks. 827 + */ 828 + pm_runtime_no_callbacks(&serdev->dev); 829 + 830 + set_bit(BTMTKUART_REQUIRED_WAKEUP, &bdev->tx_state); 831 + } 832 + 833 + err = hci_register_dev(hdev); 834 + if (err < 0) { 999 835 dev_err(&serdev->dev, "Can't register HCI device\n"); 1000 836 hci_free_dev(hdev); 1001 - return -ENODEV; 837 + goto err_regulator_disable; 1002 838 } 1003 839 1004 840 return 0; 841 + 842 + err_regulator_disable: 843 + if (btmtkuart_is_standalone(bdev)) { 844 + pinctrl_select_state(bdev->pinctrl, bdev->pins_boot); 845 + regulator_disable(bdev->vcc); 846 + } 847 + 848 + return err; 1005 849 } 1006 850 1007 851 static void btmtkuart_remove(struct serdev_device *serdev) ··· 1050 812 struct btmtkuart_dev *bdev = serdev_device_get_drvdata(serdev); 1051 813 struct hci_dev *hdev = bdev->hdev; 1052 814 815 + if (btmtkuart_is_standalone(bdev)) { 816 + pinctrl_select_state(bdev->pinctrl, bdev->pins_boot); 817 + regulator_disable(bdev->vcc); 818 + } 819 + 1053 820 hci_unregister_dev(hdev); 1054 821 hci_free_dev(hdev); 1055 822 } 1056 823 824 + static const struct btmtkuart_data mt7622_data = { 825 + .fwname = FIRMWARE_MT7622, 826 + }; 827 + 828 + static const struct btmtkuart_data mt7663_data = { 829 + .flags = BTMTKUART_FLAG_STANDALONE_HW, 830 + .fwname = FIRMWARE_MT7663, 831 + }; 832 + 833 + static const struct btmtkuart_data mt7668_data = { 834 + .flags = BTMTKUART_FLAG_STANDALONE_HW, 835 + .fwname = FIRMWARE_MT7668, 836 + }; 837 + 1057 838 #ifdef CONFIG_OF 1058 839 static const struct of_device_id mtk_of_match_table[] = { 1059 - { .compatible = "mediatek,mt7622-bluetooth"}, 840 + { .compatible = "mediatek,mt7622-bluetooth", .data = &mt7622_data}, 841 + { .compatible = "mediatek,mt7663u-bluetooth", .data = &mt7663_data}, 842 + { .compatible = "mediatek,mt7668u-bluetooth", .data = &mt7668_data}, 1060 843 { } 1061 844 }; 1062 845 MODULE_DEVICE_TABLE(of, mtk_of_match_table); ··· 1099 840 MODULE_VERSION(VERSION); 1100 841 MODULE_LICENSE("GPL"); 1101 842 MODULE_FIRMWARE(FIRMWARE_MT7622); 843 + MODULE_FIRMWARE(FIRMWARE_MT7663); 844 + MODULE_FIRMWARE(FIRMWARE_MT7668);
+3 -28
drivers/bluetooth/btqcomsmd.c
··· 28 28 struct btqcomsmd { 29 29 struct hci_dev *hdev; 30 30 31 - bdaddr_t bdaddr; 32 31 struct rpmsg_endpoint *acl_channel; 33 32 struct rpmsg_endpoint *cmd_channel; 34 33 }; ··· 115 116 116 117 static int btqcomsmd_setup(struct hci_dev *hdev) 117 118 { 118 - struct btqcomsmd *btq = hci_get_drvdata(hdev); 119 119 struct sk_buff *skb; 120 - int err; 121 120 122 121 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); 123 122 if (IS_ERR(skb)) 124 123 return PTR_ERR(skb); 125 124 kfree_skb(skb); 126 125 127 - /* Devices do not have persistent storage for BD address. If no 128 - * BD address has been retrieved during probe, mark the device 129 - * as having an invalid BD address. 126 + /* Devices do not have persistent storage for BD address. Retrieve 127 + * it from the firmware node property. 130 128 */ 131 - if (!bacmp(&btq->bdaddr, BDADDR_ANY)) { 132 - set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); 133 - return 0; 134 - } 135 - 136 - /* When setting a configured BD address fails, mark the device 137 - * as having an invalid BD address. 138 - */ 139 - err = qca_set_bdaddr_rome(hdev, &btq->bdaddr); 140 - if (err) { 141 - set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); 142 - return 0; 143 - } 129 + set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks); 144 130 145 131 return 0; 146 132 } ··· 152 168 btqcomsmd_cmd_callback, btq); 153 169 if (IS_ERR(btq->cmd_channel)) 154 170 return PTR_ERR(btq->cmd_channel); 155 - 156 - /* The local-bd-address property is usually injected by the 157 - * bootloader which has access to the allocated BD address. 158 - */ 159 - if (!of_property_read_u8_array(pdev->dev.of_node, "local-bd-address", 160 - (u8 *)&btq->bdaddr, sizeof(bdaddr_t))) { 161 - dev_info(&pdev->dev, "BD address %pMR retrieved from device-tree", 162 - &btq->bdaddr); 163 - } 164 171 165 172 hdev = hci_alloc_dev(); 166 173 if (!hdev)
+2
drivers/bluetooth/btusb.c
··· 2917 2917 2918 2918 static const struct of_device_id btusb_match_table[] = { 2919 2919 { .compatible = "usb1286,204e" }, 2920 + { .compatible = "usbcf3,e300" }, /* QCA6174A */ 2921 + { .compatible = "usb4ca,301a" }, /* QCA6174A (Lite-On) */ 2920 2922 { } 2921 2923 }; 2922 2924 MODULE_DEVICE_TABLE(of, btusb_match_table);
+1 -2
drivers/bluetooth/hci_ldisc.c
··· 696 696 return -EPROTONOSUPPORT; 697 697 698 698 hu->proto = p; 699 - set_bit(HCI_UART_PROTO_READY, &hu->flags); 700 699 701 700 err = hci_uart_register_dev(hu); 702 701 if (err) { 703 - clear_bit(HCI_UART_PROTO_READY, &hu->flags); 704 702 return err; 705 703 } 706 704 705 + set_bit(HCI_UART_PROTO_READY, &hu->flags); 707 706 return 0; 708 707 } 709 708
+30 -20
drivers/bluetooth/hci_qca.c
··· 59 59 60 60 #define IBS_WAKE_RETRANS_TIMEOUT_MS 100 61 61 #define IBS_TX_IDLE_TIMEOUT_MS 2000 62 - #define BAUDRATE_SETTLE_TIMEOUT_MS 300 63 - #define POWER_PULSE_TRANS_TIMEOUT_MS 100 62 + #define CMD_TRANS_TIMEOUT_MS 100 64 63 65 64 /* susclk rate */ 66 65 #define SUSCLK_RATE_32KHZ 32768 ··· 963 964 { 964 965 struct hci_uart *hu = hci_get_drvdata(hdev); 965 966 struct qca_data *qca = hu->priv; 967 + struct qca_serdev *qcadev; 966 968 struct sk_buff *skb; 967 969 u8 cmd[] = { 0x01, 0x48, 0xFC, 0x01, 0x00 }; 968 970 ··· 985 985 skb_queue_tail(&qca->txq, skb); 986 986 hci_uart_tx_wakeup(hu); 987 987 988 - /* wait 300ms to change new baudrate on controller side 989 - * controller will come back after they receive this HCI command 990 - * then host can communicate with new baudrate to controller 991 - */ 992 - set_current_state(TASK_UNINTERRUPTIBLE); 993 - schedule_timeout(msecs_to_jiffies(BAUDRATE_SETTLE_TIMEOUT_MS)); 994 - set_current_state(TASK_RUNNING); 988 + qcadev = serdev_device_get_drvdata(hu->serdev); 989 + 990 + /* Wait for the baudrate change request to be sent */ 991 + 992 + while (!skb_queue_empty(&qca->txq)) 993 + usleep_range(100, 200); 994 + 995 + serdev_device_wait_until_sent(hu->serdev, 996 + msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS)); 997 + 998 + /* Give the controller time to process the request */ 999 + if (qcadev->btsoc_type == QCA_WCN3990) 1000 + msleep(10); 1001 + else 1002 + msleep(300); 995 1003 996 1004 return 0; 997 1005 } ··· 1012 1004 hci_uart_set_baudrate(hu, speed); 1013 1005 } 1014 1006 1015 - static int qca_send_power_pulse(struct hci_uart *hu, u8 cmd) 1007 + static int qca_send_power_pulse(struct hci_uart *hu, bool on) 1016 1008 { 1017 1009 int ret; 1018 - int timeout = msecs_to_jiffies(POWER_PULSE_TRANS_TIMEOUT_MS); 1010 + int timeout = msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS); 1011 + u8 cmd = on ? QCA_WCN3990_POWERON_PULSE : QCA_WCN3990_POWEROFF_PULSE; 1019 1012 1020 1013 /* These power pulses are single byte command which are sent 1021 1014 * at required baudrate to wcn3990. On wcn3990, we have an external ··· 1039 1030 } 1040 1031 1041 1032 serdev_device_wait_until_sent(hu->serdev, timeout); 1042 - 1043 - /* Wait for 100 uS for SoC to settle down */ 1044 - usleep_range(100, 200); 1045 1033 hci_uart_set_flow_control(hu, false); 1034 + 1035 + /* Give to controller time to boot/shutdown */ 1036 + if (on) 1037 + msleep(100); 1038 + else 1039 + msleep(10); 1046 1040 1047 1041 return 0; 1048 1042 } ··· 1150 1138 1151 1139 /* Forcefully enable wcn3990 to enter in to boot mode. */ 1152 1140 host_set_baudrate(hu, 2400); 1153 - ret = qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE); 1141 + ret = qca_send_power_pulse(hu, false); 1154 1142 if (ret) 1155 1143 return ret; 1156 1144 1157 1145 qca_set_speed(hu, QCA_INIT_SPEED); 1158 - ret = qca_send_power_pulse(hu, QCA_WCN3990_POWERON_PULSE); 1146 + ret = qca_send_power_pulse(hu, true); 1159 1147 if (ret) 1160 1148 return ret; 1161 - 1162 - /* Wait for 100 ms for SoC to boot */ 1163 - msleep(100); 1164 1149 1165 1150 /* Now the device is in ready state to communicate with host. 1166 1151 * To sync host with device we need to reopen port. ··· 1201 1192 * setup for every hci up. 1202 1193 */ 1203 1194 set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks); 1195 + set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks); 1204 1196 hu->hdev->shutdown = qca_power_off; 1205 1197 ret = qca_wcn3990_init(hu); 1206 1198 if (ret) ··· 1299 1289 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); 1300 1290 1301 1291 host_set_baudrate(hu, 2400); 1302 - qca_send_power_pulse(hu, QCA_WCN3990_POWEROFF_PULSE); 1292 + qca_send_power_pulse(hu, false); 1303 1293 qca_power_setup(hu, false); 1304 1294 } 1305 1295
+12
include/net/bluetooth/hci.h
··· 158 158 */ 159 159 HCI_QUIRK_INVALID_BDADDR, 160 160 161 + /* When this quirk is set, the public Bluetooth address 162 + * initially reported by HCI Read BD Address command 163 + * is considered invalid. The public BD Address can be 164 + * specified in the fwnode property 'local-bd-address'. 165 + * If this property does not exist or is invalid controller 166 + * configuration is required before this device can be used. 167 + * 168 + * This quirk can be set before hci_register_dev is called or 169 + * during the hdev->setup vendor callback. 170 + */ 171 + HCI_QUIRK_USE_BDADDR_PROPERTY, 172 + 161 173 /* When this quirk is set, the duplicate filtering during 162 174 * scanning is based on Bluetooth devices addresses. To allow 163 175 * RSSI based updates, restart scanning if needed.
+43
net/bluetooth/hci_core.c
··· 30 30 #include <linux/rfkill.h> 31 31 #include <linux/debugfs.h> 32 32 #include <linux/crypto.h> 33 + #include <linux/property.h> 33 34 #include <asm/unaligned.h> 34 35 35 36 #include <net/bluetooth/bluetooth.h> ··· 1356 1355 return err; 1357 1356 } 1358 1357 1358 + /** 1359 + * hci_dev_get_bd_addr_from_property - Get the Bluetooth Device Address 1360 + * (BD_ADDR) for a HCI device from 1361 + * a firmware node property. 1362 + * @hdev: The HCI device 1363 + * 1364 + * Search the firmware node for 'local-bd-address'. 1365 + * 1366 + * All-zero BD addresses are rejected, because those could be properties 1367 + * that exist in the firmware tables, but were not updated by the firmware. For 1368 + * example, the DTS could define 'local-bd-address', with zero BD addresses. 1369 + */ 1370 + static void hci_dev_get_bd_addr_from_property(struct hci_dev *hdev) 1371 + { 1372 + struct fwnode_handle *fwnode = dev_fwnode(hdev->dev.parent); 1373 + bdaddr_t ba; 1374 + int ret; 1375 + 1376 + ret = fwnode_property_read_u8_array(fwnode, "local-bd-address", 1377 + (u8 *)&ba, sizeof(ba)); 1378 + if (ret < 0 || !bacmp(&ba, BDADDR_ANY)) 1379 + return; 1380 + 1381 + bacpy(&hdev->public_addr, &ba); 1382 + } 1383 + 1359 1384 static int hci_dev_do_open(struct hci_dev *hdev) 1360 1385 { 1361 1386 int ret = 0; ··· 1449 1422 if (hdev->setup) 1450 1423 ret = hdev->setup(hdev); 1451 1424 1425 + if (ret) 1426 + goto setup_failed; 1427 + 1428 + if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) { 1429 + if (!bacmp(&hdev->public_addr, BDADDR_ANY)) 1430 + hci_dev_get_bd_addr_from_property(hdev); 1431 + 1432 + if (bacmp(&hdev->public_addr, BDADDR_ANY) && 1433 + hdev->set_bdaddr) 1434 + ret = hdev->set_bdaddr(hdev, 1435 + &hdev->public_addr); 1436 + else 1437 + ret = -EADDRNOTAVAIL; 1438 + } 1439 + 1440 + setup_failed: 1452 1441 /* The transport driver can set these quirks before 1453 1442 * creating the HCI device or in its setup callback. 1454 1443 *
+7 -7
net/bluetooth/mgmt.c
··· 474 474 { 475 475 struct mgmt_rp_read_ext_index_list *rp; 476 476 struct hci_dev *d; 477 - size_t rp_len; 478 477 u16 count; 479 478 int err; 480 479 ··· 487 488 count++; 488 489 } 489 490 490 - rp_len = sizeof(*rp) + (sizeof(rp->entry[0]) * count); 491 - rp = kmalloc(rp_len, GFP_ATOMIC); 491 + rp = kmalloc(struct_size(rp, entry, count), GFP_ATOMIC); 492 492 if (!rp) { 493 493 read_unlock(&hci_dev_list_lock); 494 494 return -ENOMEM; ··· 523 525 } 524 526 525 527 rp->num_controllers = cpu_to_le16(count); 526 - rp_len = sizeof(*rp) + (sizeof(rp->entry[0]) * count); 527 528 528 529 read_unlock(&hci_dev_list_lock); 529 530 ··· 535 538 hci_sock_clear_flag(sk, HCI_MGMT_UNCONF_INDEX_EVENTS); 536 539 537 540 err = mgmt_cmd_complete(sk, MGMT_INDEX_NONE, 538 - MGMT_OP_READ_EXT_INDEX_LIST, 0, rp, rp_len); 541 + MGMT_OP_READ_EXT_INDEX_LIST, 0, rp, 542 + struct_size(rp, entry, count)); 539 543 540 544 kfree(rp); 541 545 ··· 549 551 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) 550 552 return false; 551 553 552 - if (test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) && 554 + if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || 555 + test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && 553 556 !bacmp(&hdev->public_addr, BDADDR_ANY)) 554 557 return false; 555 558 ··· 565 566 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) 566 567 options |= MGMT_OPTION_EXTERNAL_CONFIG; 567 568 568 - if (test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) && 569 + if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || 570 + test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && 569 571 !bacmp(&hdev->public_addr, BDADDR_ANY)) 570 572 options |= MGMT_OPTION_PUBLIC_ADDRESS; 571 573