@@ -9,12 +9,15 @@ Three changes are needed to support MT6639:
99
10101. CHIPID workaround: On some boards the BT USB MMIO register reads
1111 0x0000 for dev_id, causing the driver to skip the 0x6639 init path.
12- Force dev_id to 0x6639 when it reads zero, matching the equivalent
13- WiFi-side workaround that forces chip=0x7927.
12+ Force dev_id to 0x6639 only when the USB VID/PID matches a known
13+ MT6639 device, avoiding misdetection if a future chip also reads
14+ zero. This follows the WiFi-side pattern that uses PCI device IDs
15+ to scope the same workaround.
1416
15172. Firmware naming: MT6639 uses firmware version prefix "2_1" instead of
1618 "1_1" used by MT7925 and other variants. The firmware path is
17- mediatek/mt6639/BT_RAM_CODE_MT6639_2_1_hdr.bin.
19+ mediatek/mt7927/BT_RAM_CODE_MT6639_2_1_hdr.bin, using the mt7927
20+ directory to match the WiFi firmware convention.
1821
19223. Section filtering: The MT6639 firmware binary contains 9 sections, but
2023 only sections with (dlmodecrctype & 0xff) == 0x01 are Bluetooth-related.
@@ -30,12 +33,31 @@ Link: https://github.com/openwrt/mt76/issues/927
3033Reported-by: Ryan Gilbert <xelnaga@gmail.com>
3134Signed-off-by: Javier Tia <floss@jetm.me>
3235
33- 519527132da41202bab85679ef03319e3aa8763a
36+ 4a0bc7139c3406b228e12f0e14963cdb59f908b6
3437diff --git a/btmtk.c b/btmtk.c
35- index a8c520d..e1193f9 100644
38+ index a8c520d..4df28a2 100644
3639--- a/btmtk.c
3740+++ b/btmtk.c
38- @@ -114,3 +114,7 @@ void btmtk_fw_get_filename(char *buf, size_t size, u32 dev_id, u32 fw_ver,
41+ @@ -27,2 +27,18 @@
42+
43+ + /* Known MT6639 (MT7927) Bluetooth USB devices.
44+ + * Used to scope the zero-CHIPID workaround to real MT6639 hardware,
45+ + * since some boards return 0x0000 from the MMIO chip ID register.
46+ + */
47+ + static const struct {
48+ + u16 vendor;
49+ + u16 product;
50+ + } btmtk_mt6639_devs[] = {
51+ + { 0x0489, 0xe13a }, /* ASUS ROG Crosshair X870E Hero */
52+ + { 0x0489, 0xe0fa }, /* Lenovo Legion Pro 7 16ARX9 */
53+ + { 0x0489, 0xe10f }, /* Gigabyte Z790 AORUS MASTER X */
54+ + { 0x0489, 0xe110 }, /* MSI X870E Ace Max */
55+ + { 0x0489, 0xe116 }, /* TP-Link Archer TBE550E */
56+ + { 0x13d3, 0x3588 }, /* ASUS ROG STRIX X870E-E */
57+ + };
58+ +
59+ struct btmtk_patch_header {
60+ @@ -114,3 +130,7 @@ void btmtk_fw_get_filename(char *buf, size_t size, u32 dev_id, u32 fw_ver,
3961 {
4062- if (dev_id == 0x7925)
4163+ if (dev_id == 0x6639)
@@ -44,11 +66,11 @@ index a8c520d..e1193f9 100644
4466+ dev_id & 0xffff, (fw_ver & 0xff) + 1);
4567+ else if (dev_id == 0x7925)
4668 snprintf(buf, size,
47- @@ -132,2 +136 ,3 @@ int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname,
69+ @@ -132,2 +152 ,3 @@ int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname,
4870 {
4971+ struct btmtk_data *data = hci_get_priv(hdev);
5072 struct btmtk_hci_wmt_params wmt_params;
51- @@ -168,2 +173 ,10 @@ int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname,
73+ @@ -168,2 +189 ,10 @@ int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname,
5274
5375+ /* MT6639: only download sections where dlmode byte0 == 0x01,
5476+ * matching the Windows driver behavior which skips WiFi/other
@@ -59,36 +81,21 @@ index a8c520d..e1193f9 100644
5981+ continue;
6082+
6183 if (dl_size > 0) {
62- @@ -842,3 +855 ,3 @@ int btmtk_usb_subsys_reset(struct hci_dev *hdev, u32 dev_id)
84+ @@ -842,3 +871 ,3 @@ int btmtk_usb_subsys_reset(struct hci_dev *hdev, u32 dev_id)
6385 msleep(100);
6486- } else if (dev_id == 0x7925) {
6587+ } else if (dev_id == 0x7925 || dev_id == 0x6639) {
6688 err = btmtk_usb_uhw_reg_read(hdev, MTK_BT_RESET_REG_CONNV3, &val);
67- @@ -1312,2 +1325,35 @@ int btmtk_usb_setup(struct hci_dev *hdev)
89+ @@ -1312,2 +1341,20 @@ int btmtk_usb_setup(struct hci_dev *hdev)
6890
69- + /* MT6639: some boards return CHIPID=0x0000 from the register read.
70- + * Only force dev_id for known MT6639 USB devices to avoid
71- + * misdetecting future chips that may also read zero.
72- + */
7391+ if (!dev_id) {
74- + static const struct {
75- + u16 vendor;
76- + u16 product;
77- + } mt6639_devs[] = {
78- + { 0x0489, 0xe13a },
79- + { 0x0489, 0xe0fa },
80- + { 0x0489, 0xe10f },
81- + { 0x0489, 0xe110 },
82- + { 0x0489, 0xe116 },
83- + { 0x13d3, 0x3588 },
84- + };
8592+ u16 vid = le16_to_cpu(btmtk_data->udev->descriptor.idVendor);
8693+ u16 pid = le16_to_cpu(btmtk_data->udev->descriptor.idProduct);
8794+ int i;
8895+
89- + for (i = 0; i < ARRAY_SIZE(mt6639_devs ); i++) {
90- + if (vid == mt6639_devs [i].vendor &&
91- + pid == mt6639_devs [i].product) {
96+ + for (i = 0; i < ARRAY_SIZE(btmtk_mt6639_devs ); i++) {
97+ + if (vid == btmtk_mt6639_devs [i].vendor &&
98+ + pid == btmtk_mt6639_devs [i].product) {
9299+ dev_id = 0x6639;
93100+ break;
94101+ }
@@ -100,11 +107,11 @@ index a8c520d..e1193f9 100644
100107+ }
101108+
102109 btmtk_data->dev_id = dev_id;
103- @@ -1328,2 +1374 ,3 @@ int btmtk_usb_setup(struct hci_dev *hdev)
110+ @@ -1328,2 +1375 ,3 @@ int btmtk_usb_setup(struct hci_dev *hdev)
104111 case 0x7961:
105112+ case 0x6639:
106113 btmtk_fw_get_filename(fw_bin_name, sizeof(fw_bin_name), dev_id,
107- @@ -1499 +1546 ,2 @@ MODULE_FIRMWARE(FIRMWARE_MT7961);
114+ @@ -1499 +1547 ,2 @@ MODULE_FIRMWARE(FIRMWARE_MT7961);
108115 MODULE_FIRMWARE(FIRMWARE_MT7925);
109116+ MODULE_FIRMWARE(FIRMWARE_MT7927);
110117diff --git a/btmtk.h b/btmtk.h
0 commit comments