Skip to contentSkip to conversation

add support for Bluetooth on MT7622 SoC

PATCH In review [email protected] 3 participants 6 messages Aug 7, 2018 – Aug 8, 2018

Subsystems (5)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

v10 cover add support for Bluetooth on MT7622 SoC

From: Sean Wang <[email protected]>

v10 and changes since v9:
- Add a fixup that is __be16 is required instead of dlen1 + dlen2 in STP header.
- Align a few one-line comments style as they're made in v9
- Fix two warnings catched by checkpatch.pl

	WARNING:TYPO_SPELLING: 'specifc' may be misspelled - perhaps 'specific'?
	at 248: FILE: drivers/bluetooth/btmtkuart.c:186:

	WARNING:MEMORY_BARRIER: memory barrier without comment
	at 260: FILE: drivers/bluetooth/btmtkuart.c:198:

v9 and changes since v8:
- Marcel Holtmann helps to add v9, which includes did a bunch of cosmetic minor cleanup, spelling correction and added __hci_cmd_send and its event synchronization scheme. For details, they can be found in [1].

[1] http://lists.infradead.org/pipermail/linux-mediatek/2018-August/014587.html

v8 and changes since v7:
- add updates per these suggestions mentioned in [1][2]
- remove the hack atomic_inc(&hdev->cmd_cnt) mentioned in [2] because it should be better to be considered in the core

[1] http://lists.infradead.org/pipermail/linux-mediatek/2018-August/014516.html
[2] http://lists.infradead.org/pipermail/linux-mediatek/2018-August/014518.html

v7 and changes since v6:
- drop already applied patches
- move clk_* and pm_* operation to ->open and ->close
- label this driver as BT_MTKUART
- make code style aligned with the other drivers and code better to read as these suggestions and fixes are mentioned in [1]

[1] http://lists.infradead.org/pipermail/linux-mediatek/2018-July/014458.html

v6 and changes since v5:
- make btmtkuart become a separate driver.
- drop already applied patches and the patch for btuart driver
- refine comments in driver allowing people know that mtk extra header
+ length doesn't indicate a full H:4 frame, things can fragment.
- enhance dt-binding document with removing mistaken added " and improve English sentence.
- remove unnecessary '\n' with bt_dev_err.
- refine code style.
- set hdev->manufacturer as mtk id.

v5 and changes since v4:
- add Reviewed-by Tag from Ulf Hansson for patch 2
- remove default y in Kconfig for btmtkuart selection to avoid overkill for users which would like to have less an amount on stuff in kernel.
- list header declarations in alphabetical order and add a proper blank line within.
- remove unused macro.
- use sizeof to calculate structure size instead of an aextra macro to hardcode.
- use struct hci_dev * as input paraments for mtk_hci_wmt_sync and mtk_setup_fw for that can be reused in mtk bluetooth with other interfaces.
- remove unused local variabled in mtk_btuart_recv.
- remove superfluous :8 for dlen2 in struct mtk_stp_hdr definition.
- give a reasonable naming for these labels and add a pm_runtime_put_noidle() in the path undoing failing pm_runtime_get_sync().
- Turn __u8 into u8 in struct mtk_stp_hdr.

Really thanks for these reviews by Johan Hovold and Andy Shevchenko

v4 and changes since v3:
- refine patch 2 based on commit 919b7308fcc4 to allow that dev_pm_domain_attach() will return better error codes.

v3 and changes since v2
* all changes happen on patch 6
- fix up SPDX license style for btmtkuart.h.
- change firmware download from in ACL data to in HCI commands and then remove unused mtk_acl_wmt_sync and related code.
- add a workaround replacing bad vendor event id 0xe4 with 0xff every vendor should use.
- add a sanity check for mtk_hci_wmt_sync to verifying if input parameters are valid.
- add an atomic_inc(&bdev->hdev->cmd_cnt) for __hci_cmd_sync_ev.
- be changed to use firmware with a header called mt7622pr2h.bin.

v2 and changes since v1
- Dropped patches already being applied
- Rewirte the whole driver using btuart [1], and add slight extension of btuart to fit into btmtkuart driver. Beware that [1] is also pulled into one part of the series for avoiding any breakage when the patchset is being compiled.

[1] btuart

	https://www.spinics.net/lists/linux-bluetooth/msg74918.html

v1:

Hi,

This patchset introduces built-in Bluetooth support on MT7622 SoC. And, it should be simple to make an extension to support other MediaTek SoCs with adjusting a few of changes on the initialization sequence of the device.

Before the main driver is being introduced, a few of things about power-domain management should be re-worked for serdev core and MediaTek SCPSYS to allow the Bluetooth to properly power up.

Patch 2: add a generic way attaching power domain to serdev Patch 3 and 4: add cleanups with reuse APIs from Linux core Patch 5: fix a limitation about power enablement Bluetooth depends on Patch 1, 6 and 7: the major part of adding Bluetooth support to MT7622

Sean

Sean Wang (3):
dt-bindings: net: bluetooth: Add mediatek-bluetooth
Bluetooth: mediatek: Add protocol support for MediaTek serial devices
MAINTAINERS: add an entry for MediaTek Bluetooth driver

 .../devicetree/bindings/net/mediatek-bluetooth.txt |  35 ++
 MAINTAINERS                                        |   8 +
 drivers/bluetooth/Kconfig                          |  11 +
 drivers/bluetooth/Makefile                         |   1 +
 drivers/bluetooth/btmtkuart.c                      | 629 +++++++++++++++++++++
 5 files changed, 684 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
 create mode 100644 drivers/bluetooth/btmtkuart.c
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH v10 1/3 dt-bindings: net: bluetooth: Add mediatek-bluetooth

From: Sean Wang <[email protected]>

Add binding document for a SoC built-in device using MediaTek protocol. Which could be found on MT7622 SoC or other similar MediaTek SoCs.

---
 .../devicetree/bindings/net/mediatek-bluetooth.txt | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
Documentation/devicetree/bindings/net/mediatek-bluetooth.txt new file +35 -0
new file mode 100644
index 0000000..14ceb2a
@@ -0,0 +1,35 @@
+MediaTek SoC built-in Bluetooth Devices
+==================================
+
+This device is a serial attached device to BTIF device and thus it must be a
+child node of the serial node with BTIF. The dt-bindings details for BTIF
+device can be known via Documentation/devicetree/bindings/serial/8250.txt.
+
+Required properties:
+
+- compatible:	Must be
+		  "mediatek,mt7622-bluetooth": for MT7622 SoC
+- clocks:	Should be the clock specifiers corresponding to the entry in
+		clock-names property.
+- clock-names:	Should contain "ref" entries.
+- power-domains: Phandle to the power domain that the device is part of
+
+Example:
+
+	btif: serial at 1100c000 {
+		compatible = "mediatek,mt7622-btif",
+			     "mediatek,mtk-btif";
+		reg = <0 0x1100c000 0 0x1000>;
+		interrupts = <GIC_SPI 90 IRQ_TYPE_LEVEL_LOW>;
+		clocks = <&pericfg CLK_PERI_BTIF_PD>;
+		clock-names = "main";
+		reg-shift = <2>;
+		reg-io-width = <4>;
+
+		bluetooth {
+			compatible = "mediatek,mt7622-bluetooth";
+			power-domains = <&scpsys MT7622_POWER_DOMAIN_WB>;
+			clocks = <&clk25m>;
+			clock-names = "ref";
+		};
+	};
Signature · 1 line
2.7.4
author maintainer
#2 lore raw

PATCH v10 2/3 Bluetooth: mediatek: Add protocol support for MediaTek serial devices

In reply to [email protected]

From: Sean Wang <[email protected]>

This adds a driver based on serdev driver for the MediaTek serial protocol based on running H:4, which can enable the built-in Bluetooth device inside MT7622 SoC.

---
 drivers/bluetooth/Kconfig     |  11 +
 drivers/bluetooth/Makefile    |   1 +
 drivers/bluetooth/btmtkuart.c | 629 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 641 insertions(+)
 create mode 100644 drivers/bluetooth/btmtkuart.c
drivers/bluetooth/Kconfig +11 -0
index f3c643a..eaee8b0 100644
@@ -364,6 +364,17 @@ config BT_WILINK
 	  Say Y here to compile support for Texas Instrument's WiLink7 driver
 	  into the kernel or say M to compile it as module (btwilink).
 
+config BT_MTKUART
+	tristate "MediaTek HCI UART driver"
+	depends on SERIAL_DEV_BUS
+	help
+	  MediaTek Bluetooth HCI UART driver.
+	  This driver is required if you want to use MediaTek Bluetooth
+	  with serial interface.
+
+	  Say Y here to compile support for MediaTek Bluetooth UART devices
+	  into the kernel or say M to compile it as module (btmtkuart).
+
 config BT_QCOMSMD
 	tristate "Qualcomm SMD based HCI support"
 	depends on RPMSG || (COMPILE_TEST && RPMSG=n)
drivers/bluetooth/Makefile +1 -0
index ec16c55..b7e393c 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_BT_ATH3K)		+= ath3k.o
 obj-$(CONFIG_BT_MRVL)		+= btmrvl.o
 obj-$(CONFIG_BT_MRVL_SDIO)	+= btmrvl_sdio.o
 obj-$(CONFIG_BT_WILINK)		+= btwilink.o
+obj-$(CONFIG_BT_MTKUART)	+= btmtkuart.o
 obj-$(CONFIG_BT_QCOMSMD)	+= btqcomsmd.o
 obj-$(CONFIG_BT_BCM)		+= btbcm.o
 obj-$(CONFIG_BT_RTL)		+= btrtl.o
drivers/bluetooth/btmtkuart.c new file +629 -0

629 lines not on this page · raw message

Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH v10 2/3] Bluetooth: mediatek: Add protocol support for MediaTek serial devices

I love your patch! Perhaps something to improve:

Hi Sean,

I love your patch! Perhaps something to improve:

[auto build test WARNING on bluetooth/master]
[also build test WARNING on v4.18-rc8]
[cannot apply to next-20180808]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/linux-kernel-owner-vger-kernel-org/dt-bindings-net-bluetooth-Add-mediatek-bluetooth/20180808-132732
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git master
config: arm-allmodconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.2.0 make.cross ARCH=arm

All warnings (new ones prefixed by >>):

drivers/bluetooth/btmtkuart.c: In function 'mtk_hci_wmt_sync':
drivers/bluetooth/btmtkuart.c:99:8: error: implicit declaration of function '__hci_cmd_send'; did you mean '__hci_cmd_sync'? [-Werror=implicit-function-declaration]

     err = __hci_cmd_send(hdev, 0xfc6f, hlen, &wc);
           ^~~~~~~~~~~~~~
           __hci_cmd_sync
   In file included from include/linux/bitops.h:38:0,
                    from include/linux/kernel.h:11,
                    from include/linux/unaligned/packed_struct.h:4,
                    from include/linux/unaligned/be_struct.h:5,
                    from arch/arm/include/asm/unaligned.h:18,
                    from drivers/bluetooth/btmtkuart.c:11:
   drivers/bluetooth/btmtkuart.c: In function 'btmtkuart_probe':
   drivers/bluetooth/btmtkuart.c:586:10: error: 'HCI_QUIRK_NON_PERSISTENT_SETUP' undeclared (first use in this function); did you mean 'HCI_QUIRK_NON_PERSISTENT_DIAG'?
     set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
             ^
   arch/arm/include/asm/bitops.h:183:42: note: in definition of macro 'ATOMIC_BITOP'
    #define ATOMIC_BITOP(name,nr,p)  _##name(nr,p)
                                             ^~
>> drivers/bluetooth/btmtkuart.c:586:2: note: in expansion of macro 'set_bit'
     set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
     ^~~~~~~
   drivers/bluetooth/btmtkuart.c:586:10: note: each undeclared identifier is reported only once for each function it appears in
     set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
             ^
   arch/arm/include/asm/bitops.h:183:42: note: in definition of macro 'ATOMIC_BITOP'
    #define ATOMIC_BITOP(name,nr,p)  _##name(nr,p)
                                             ^~
>> drivers/bluetooth/btmtkuart.c:586:2: note: in expansion of macro 'set_bit'
     set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
     ^~~~~~~

cc1: some warnings being treated as errors

vim +/set_bit +586 drivers/bluetooth/btmtkuart.c

543
544 static int btmtkuart_probe(struct serdev_device *serdev)
545 {
546 struct btmtkuart_dev *bdev;
547 struct hci_dev *hdev;
548
549 bdev = devm_kzalloc(&serdev->dev, sizeof(*bdev), GFP_KERNEL);
550 if (!bdev)
551 return -ENOMEM;
552
553 bdev->clk = devm_clk_get(&serdev->dev, "ref");
554 if (IS_ERR(bdev->clk))
555 return PTR_ERR(bdev->clk);
556
557 bdev->serdev = serdev;
558 serdev_device_set_drvdata(serdev, bdev);
559
560 serdev_device_set_client_ops(serdev, &btmtkuart_client_ops);
561
562 INIT_WORK(&bdev->tx_work, btmtkuart_tx_work);
563 skb_queue_head_init(&bdev->txq);
564
565 /* Initialize and register HCI device */
566 hdev = hci_alloc_dev();
567 if (!hdev) {
568 dev_err(&serdev->dev, "Can't allocate HCI device\n");
569 return -ENOMEM;
570 }
571
572 bdev->hdev = hdev;
573
574 hdev->bus = HCI_UART;
575 hci_set_drvdata(hdev, bdev);
576

   577		hdev->open     = btmtkuart_open;
   578		hdev->close    = btmtkuart_close;
   579		hdev->flush    = btmtkuart_flush;
   580		hdev->setup    = btmtkuart_setup;
   581		hdev->shutdown = btmtkuart_shutdown;
   582		hdev->send     = btmtkuart_send_frame;
   583		SET_HCIDEV_DEV(hdev, &serdev->dev);
   584	
   585		hdev->manufacturer = 70;
 > 586		set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);

587
588 if (hci_register_dev(hdev) < 0) {
589 dev_err(&serdev->dev, "Can't register HCI device\n");
590 hci_free_dev(hdev);
591 return -ENODEV;
592 }
593
594 return 0;
595 }
596

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/gzip
Size: 65165 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180808/4f994ef1/attachment-0001.gz>

author maintainer
#4 lore raw

PATCH v10 3/3 MAINTAINERS: add an entry for MediaTek Bluetooth driver

In reply to [email protected]

From: Sean Wang <[email protected]>

Add an entry for the MediaTek Bluetooth driver.

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 0f2cce4..e983d9e 100644
@@ -9144,6 +9144,14 @@ F:	include/uapi/linux/meye.h
 F:	include/uapi/linux/ivtv*
 F:	include/uapi/linux/uvcvideo.h
 
+MEDIATEK BLUETOOTH DRIVER
+M:	Sean Wang <[email protected]>
+L:	linux-bluetooth at vger.kernel.org
+L:	linux-mediatek at lists.infradead.org (moderated for non-subscribers)
+S:	Maintained
+F:	Documentation/devicetree/bindings/net/mediatek-bluetooth.txt
+F:	drivers/bluetooth/btmtkuart.c
+
 MEDIATEK CIR DRIVER
 M:	Sean Wang <[email protected]>
 S:	Maintained
Signature · 1 line
2.7.4
maintainer
#5 lore raw
In reply to [email protected]

Hi Sean,

Quoted 114 lines

v10 and changes since v9:
- Add a fixup that is __be16 is required instead of dlen1 + dlen2 in STP header.
- Align a few one-line comments style as they're made in v9
- Fix two warnings catched by checkpatch.pl

	WARNING:TYPO_SPELLING: 'specifc' may be misspelled - perhaps 'specific'?
	at 248: FILE: drivers/bluetooth/btmtkuart.c:186:

	WARNING:MEMORY_BARRIER: memory barrier without comment
	at 260: FILE: drivers/bluetooth/btmtkuart.c:198:

v9 and changes since v8:
- Marcel Holtmann helps to add v9, which includes did a bunch of cosmetic minor cleanup, spelling correction and added __hci_cmd_send and its event synchronization scheme. For details, they can be found in [1].

[1] http://lists.infradead.org/pipermail/linux-mediatek/2018-August/014587.html

v8 and changes since v7:
- add updates per these suggestions mentioned in [1][2]
- remove the hack atomic_inc(&hdev->cmd_cnt) mentioned in [2] because it should be better to be considered in the core

[1] http://lists.infradead.org/pipermail/linux-mediatek/2018-August/014516.html
[2] http://lists.infradead.org/pipermail/linux-mediatek/2018-August/014518.html

v7 and changes since v6:
- drop already applied patches
- move clk_* and pm_* operation to ->open and ->close
- label this driver as BT_MTKUART
- make code style aligned with the other drivers and code better to read as these suggestions and fixes are mentioned in [1]

[1] http://lists.infradead.org/pipermail/linux-mediatek/2018-July/014458.html

v6 and changes since v5:
- make btmtkuart become a separate driver.
- drop already applied patches and the patch for btuart driver
- refine comments in driver allowing people know that mtk extra header
+ length doesn't indicate a full H:4 frame, things can fragment.
- enhance dt-binding document with removing mistaken added " and improve English sentence.
- remove unnecessary '\n' with bt_dev_err.
- refine code style.
- set hdev->manufacturer as mtk id.

v5 and changes since v4:
- add Reviewed-by Tag from Ulf Hansson for patch 2
- remove default y in Kconfig for btmtkuart selection to avoid overkill for users which would like to have less an amount on stuff in kernel.
- list header declarations in alphabetical order and add a proper blank line within.
- remove unused macro.
- use sizeof to calculate structure size instead of an aextra macro to hardcode.
- use struct hci_dev * as input paraments for mtk_hci_wmt_sync and mtk_setup_fw for that can be reused in mtk bluetooth with other interfaces.
- remove unused local variabled in mtk_btuart_recv.
- remove superfluous :8 for dlen2 in struct mtk_stp_hdr definition.
- give a reasonable naming for these labels and add a pm_runtime_put_noidle() in the path undoing failing pm_runtime_get_sync().
- Turn __u8 into u8 in struct mtk_stp_hdr.

Really thanks for these reviews by Johan Hovold and Andy Shevchenko

v4 and changes since v3:
- refine patch 2 based on commit 919b7308fcc4 to allow that dev_pm_domain_attach() will return better error codes.

v3 and changes since v2
* all changes happen on patch 6
- fix up SPDX license style for btmtkuart.h.
- change firmware download from in ACL data to in HCI commands and then remove unused mtk_acl_wmt_sync and related code.
- add a workaround replacing bad vendor event id 0xe4 with 0xff every vendor should use.
- add a sanity check for mtk_hci_wmt_sync to verifying if input parameters are valid.
- add an atomic_inc(&bdev->hdev->cmd_cnt) for __hci_cmd_sync_ev.
- be changed to use firmware with a header called mt7622pr2h.bin.

v2 and changes since v1
- Dropped patches already being applied
- Rewirte the whole driver using btuart [1], and add slight extension of btuart to fit into btmtkuart driver. Beware that [1] is also pulled into one part of the series for avoiding any breakage when the patchset is being compiled.

[1] btuart

	https://www.spinics.net/lists/linux-bluetooth/msg74918.html

v1:

Hi,

This patchset introduces built-in Bluetooth support on MT7622 SoC. And, it should be simple to make an extension to support other MediaTek SoCs with adjusting a few of changes on the initialization sequence of the device.

Before the main driver is being introduced, a few of things about power-domain management should be re-worked for serdev core and MediaTek SCPSYS to allow the Bluetooth to properly power up.

Patch 2: add a generic way attaching power domain to serdev Patch 3 and 4: add cleanups with reuse APIs from Linux core Patch 5: fix a limitation about power enablement Bluetooth depends on Patch 1, 6 and 7: the major part of adding Bluetooth support to MT7622

Sean

Sean Wang (3):
dt-bindings: net: bluetooth: Add mediatek-bluetooth
Bluetooth: mediatek: Add protocol support for MediaTek serial devices
MAINTAINERS: add an entry for MediaTek Bluetooth driver

Quoted 8 lines
.../devicetree/bindings/net/mediatek-bluetooth.txt |  35 ++
MAINTAINERS                                        |   8 +
drivers/bluetooth/Kconfig                          |  11 +
drivers/bluetooth/Makefile                         |   1 +
drivers/bluetooth/btmtkuart.c                      | 629 +++++++++++++++++++++
5 files changed, 684 insertions(+)

create mode 100644 Documentation/devicetree/bindings/net/mediatek-bluetooth.txt create mode 100644 drivers/bluetooth/btmtkuart.c

all 3 patches have been applied to bluetooth-next tree.

Regards

Marcel