All of lore.kernel.org
 help / color / mirror / Atom feed
* RE: Add support for Amlogic HCI UART
  2024-07-05 11:20 [PATCH 1/4] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth Yang Li
@ 2024-07-05 11:57 ` bluez.test.bot
  0 siblings, 0 replies; 19+ messages in thread
From: bluez.test.bot @ 2024-07-05 11:57 UTC (permalink / raw)
  To: linux-bluetooth, devnull+yang.li.amlogic.com

[-- Attachment #1: Type: text/plain, Size: 3676 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=868771

---Test result---

Test Summary:
CheckPatch                    FAIL      3.93 seconds
GitLint                       PASS      1.09 seconds
SubjectPrefix                 FAIL      0.62 seconds
BuildKernel                   PASS      29.63 seconds
CheckAllWarning               PASS      31.70 seconds
CheckSparse                   PASS      37.61 seconds
CheckSmatch                   PASS      102.57 seconds
BuildKernel32                 PASS      28.14 seconds
TestRunnerSetup               PASS      516.65 seconds
TestRunner_l2cap-tester       PASS      24.03 seconds
TestRunner_iso-tester         PASS      36.81 seconds
TestRunner_bnep-tester        PASS      4.73 seconds
TestRunner_mgmt-tester        PASS      114.97 seconds
TestRunner_rfcomm-tester      PASS      7.36 seconds
TestRunner_sco-tester         PASS      15.02 seconds
TestRunner_ioctl-tester       PASS      7.77 seconds
TestRunner_mesh-tester        PASS      7.94 seconds
TestRunner_smp-tester         PASS      6.88 seconds
TestRunner_userchan-tester    PASS      4.92 seconds
IncrementalBuild              PASS      43.79 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[1/4] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#93: 
new file mode 100644

total: 0 errors, 1 warnings, 62 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13724976.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


[2/4] Bluetooth: hci_uart: Add support for Amlogic HCI UART
WARNING: Co-developed-by and Signed-off-by: name/email do not match
#90: 
Co-developed-by: Ye He <ye.he@amlogic.com>
Signed-off-by: Yang Li <yang.li@amlogic.com>

WARNING: please write a help paragraph that fully describes the config symbol
#108: FILE: drivers/bluetooth/Kconfig:276:
+config BT_HCIUART_AML
+	bool "Amlogic protocol support"
+	depends on BT_HCIUART
+	depends on BT_HCIUART_SERDEV
+	select BT_HCIUART_H4
+	select FW_LOADER
+	select POWER_SEQUENCING_AML_WCN
+	help
+	  The Amlogic protocol support enables Bluetooth HCI over serial
+	  port interface for Amlogic Bluetooth controllers.
+
+	  Say Y here to compile support for HCI AML protocol.
+

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#135: 
new file mode 100644

total: 0 errors, 3 warnings, 816 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13724978.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
Test: SubjectPrefix - FAIL
Desc: Check subject contains "Bluetooth" prefix
Output:
"Bluetooth: " prefix is not specified in the subject
"Bluetooth: " prefix is not specified in the subject
"Bluetooth: " prefix is not specified in the subject


---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: Add support for Amlogic HCI UART
  2024-07-18  7:42 [PATCH v2 1/3] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth Yang Li
@ 2024-07-18  8:38 ` bluez.test.bot
  0 siblings, 0 replies; 19+ messages in thread
From: bluez.test.bot @ 2024-07-18  8:38 UTC (permalink / raw)
  To: linux-bluetooth, devnull+yang.li.amlogic.com

[-- Attachment #1: Type: text/plain, Size: 3966 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=872164

---Test result---

Test Summary:
CheckPatch                    FAIL      3.75 seconds
GitLint                       PASS      0.97 seconds
SubjectPrefix                 FAIL      0.59 seconds
BuildKernel                   PASS      30.89 seconds
CheckAllWarning               PASS      32.22 seconds
CheckSparse                   PASS      37.88 seconds
CheckSmatch                   PASS      102.54 seconds
BuildKernel32                 PASS      28.77 seconds
TestRunnerSetup               PASS      526.54 seconds
TestRunner_l2cap-tester       PASS      20.09 seconds
TestRunner_iso-tester         FAIL      35.18 seconds
TestRunner_bnep-tester        PASS      4.87 seconds
TestRunner_mgmt-tester        FAIL      118.20 seconds
TestRunner_rfcomm-tester      PASS      7.56 seconds
TestRunner_sco-tester         PASS      51.38 seconds
TestRunner_ioctl-tester       PASS      7.97 seconds
TestRunner_mesh-tester        PASS      6.00 seconds
TestRunner_smp-tester         PASS      6.94 seconds
TestRunner_userchan-tester    PASS      5.06 seconds
IncrementalBuild              PASS      40.47 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[v2,1/3] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#93: 
new file mode 100644

total: 0 errors, 1 warnings, 66 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13736148.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


[v2,2/3] Bluetooth: hci_uart: Add support for Amlogic HCI UART
WARNING: please write a help paragraph that fully describes the config symbol
#110: FILE: drivers/bluetooth/Kconfig:277:
+config BT_HCIUART_AML
+	bool "Amlogic protocol support"
+	depends on BT_HCIUART
+	depends on BT_HCIUART_SERDEV
+	select BT_HCIUART_H4
+	select FW_LOADER
+	help
+	  The Amlogic protocol support enables Bluetooth HCI over serial
+	  port interface for Amlogic Bluetooth controllers.
+
+	  Say Y here to compile support for HCI AML protocol.
+

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#136: 
new file mode 100644

total: 0 errors, 2 warnings, 838 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13736147.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
Test: SubjectPrefix - FAIL
Desc: Check subject contains "Bluetooth" prefix
Output:
"Bluetooth: " prefix is not specified in the subject
"Bluetooth: " prefix is not specified in the subject
##############################
Test: TestRunner_iso-tester - FAIL
Desc: Run iso-tester with test-runner
Output:
Total: 122, Passed: 117 (95.9%), Failed: 1, Not Run: 4

Failed Test Cases
ISO Connect2 Suspend - Success                       Failed       6.236 seconds
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 492, Passed: 489 (99.4%), Failed: 1, Not Run: 2

Failed Test Cases
Pairing Acceptor - SMP over BR/EDR 1                 Timed out    2.712 seconds


---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v3 0/3] Add support for Amlogic HCI UART
@ 2024-08-02  9:39 ` Yang Li via B4 Relay
  0 siblings, 0 replies; 19+ messages in thread
From: Yang Li @ 2024-08-02  9:39 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Catalin Marinas, Will Deacon
  Cc: linux-bluetooth, netdev, devicetree, linux-kernel,
	linux-arm-kernel, Yang Li, Ye He

Add support for Amlogic HCI UART, including dt-binding,
and Amlogic Bluetooth driver.

Signed-off-by: Yang Li <yang.li@amlogic.com>
---
Changes in v3:
- Updated the properties within the device tree binding file.
- Remove the "antenna-number" property.
- Performed code optimization for improved efficiency and readability.
- Link to v2: https://lore.kernel.org/r/20240718-btaml-v2-0-1392b2e21183@amlogic.com

Changes in v2:
- Introduce a regulator for powering up the Bluetooth chip instead of power sequencing.
- Use the GPIO Consumer API to manipulate the GPIO pins instead of the legacy API.
- Minor fixes.
- Link to v1: https://lore.kernel.org/r/20240705-btaml-v1-0-7f1538f98cef@amlogic.com

---
Yang Li (3):
      dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth
      Bluetooth: hci_uart: Add support for Amlogic HCI UART
      MAINTAINERS: Add an entry for Amlogic HCI UART (M: Yang Li)

 .../bindings/net/bluetooth/amlogic,w155s2-bt.yaml  |  62 ++
 MAINTAINERS                                        |   7 +
 drivers/bluetooth/Kconfig                          |  12 +
 drivers/bluetooth/Makefile                         |   1 +
 drivers/bluetooth/hci_aml.c                        | 756 +++++++++++++++++++++
 drivers/bluetooth/hci_ldisc.c                      |   8 +-
 drivers/bluetooth/hci_uart.h                       |   8 +-
 7 files changed, 851 insertions(+), 3 deletions(-)
---
base-commit: 2360f368524bb817b71bdd2efed53d0c3c3929ad
change-id: 20240418-btaml-f9d7b19724ab

Best regards,
-- 
Yang Li <yang.li@amlogic.com>


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v3 0/3] Add support for Amlogic HCI UART
@ 2024-08-02  9:39 ` Yang Li via B4 Relay
  0 siblings, 0 replies; 19+ messages in thread
From: Yang Li via B4 Relay @ 2024-08-02  9:39 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Catalin Marinas, Will Deacon
  Cc: linux-bluetooth, netdev, devicetree, linux-kernel,
	linux-arm-kernel, Yang Li, Ye He

Add support for Amlogic HCI UART, including dt-binding,
and Amlogic Bluetooth driver.

Signed-off-by: Yang Li <yang.li@amlogic.com>
---
Changes in v3:
- Updated the properties within the device tree binding file.
- Remove the "antenna-number" property.
- Performed code optimization for improved efficiency and readability.
- Link to v2: https://lore.kernel.org/r/20240718-btaml-v2-0-1392b2e21183@amlogic.com

Changes in v2:
- Introduce a regulator for powering up the Bluetooth chip instead of power sequencing.
- Use the GPIO Consumer API to manipulate the GPIO pins instead of the legacy API.
- Minor fixes.
- Link to v1: https://lore.kernel.org/r/20240705-btaml-v1-0-7f1538f98cef@amlogic.com

---
Yang Li (3):
      dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth
      Bluetooth: hci_uart: Add support for Amlogic HCI UART
      MAINTAINERS: Add an entry for Amlogic HCI UART (M: Yang Li)

 .../bindings/net/bluetooth/amlogic,w155s2-bt.yaml  |  62 ++
 MAINTAINERS                                        |   7 +
 drivers/bluetooth/Kconfig                          |  12 +
 drivers/bluetooth/Makefile                         |   1 +
 drivers/bluetooth/hci_aml.c                        | 756 +++++++++++++++++++++
 drivers/bluetooth/hci_ldisc.c                      |   8 +-
 drivers/bluetooth/hci_uart.h                       |   8 +-
 7 files changed, 851 insertions(+), 3 deletions(-)
---
base-commit: 2360f368524bb817b71bdd2efed53d0c3c3929ad
change-id: 20240418-btaml-f9d7b19724ab

Best regards,
-- 
Yang Li <yang.li@amlogic.com>



^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v3 1/3] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth
  2024-08-02  9:39 ` Yang Li via B4 Relay
@ 2024-08-02  9:39   ` Yang Li via B4 Relay
  -1 siblings, 0 replies; 19+ messages in thread
From: Yang Li @ 2024-08-02  9:39 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Catalin Marinas, Will Deacon
  Cc: linux-bluetooth, netdev, devicetree, linux-kernel,
	linux-arm-kernel, Yang Li

Add binding document for Amlogic Bluetooth chipsets attached over UART.

Signed-off-by: Yang Li <yang.li@amlogic.com>
---
 .../bindings/net/bluetooth/amlogic,w155s2-bt.yaml  | 62 ++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/bluetooth/amlogic,w155s2-bt.yaml b/Documentation/devicetree/bindings/net/bluetooth/amlogic,w155s2-bt.yaml
new file mode 100644
index 000000000000..c0c4209cd687
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/bluetooth/amlogic,w155s2-bt.yaml
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) 2024 Amlogic, Inc. All rights reserved
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/bluetooth/amlogic,w155s2-bt.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Amlogic Bluetooth chips
+
+description:
+  The W155S2 is an Amlogic Bluetooth and Wi-Fi combo chip. It works on
+  the standard H4 protocol via a 4-wire UART interface, with baud rates
+  up to 4 Mbps.
+
+maintainers:
+  - Yang Li <yang.li@amlogic.com>
+
+properties:
+  compatible:
+    oneOf:
+      - const: amlogic,w155s2-bt
+      - items:
+          - enum:
+              - amlogic,w265s1-bt
+              - amlogic,w265p1-bt
+              - amlogic,w265s2-bt
+          - const: amlogic,w155s2-bt
+
+  clocks:
+    maxItems: 1
+    description: clock provided to the controller (32.768KHz)
+
+  enable-gpios:
+    maxItems: 1
+
+  vddio-supply:
+    description: VDD_IO supply regulator handle
+
+  firmware-name:
+    maxItems: 1
+    description: specify the path of firmware bin to load
+
+required:
+  - compatible
+  - enable-gpios
+  - vddio-supply
+  - clocks
+  - firmware-name
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    bluetooth {
+        compatible = "amlogic,w155s2-bt";
+        clocks = <&extclk>;
+        enable-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
+        vddio-supply = <&wcn_3v3>;
+        firmware-name = "amlogic/aml_w155s2_bt_uart.bin";
+    };
+

-- 
2.42.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 1/3] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth
@ 2024-08-02  9:39   ` Yang Li via B4 Relay
  0 siblings, 0 replies; 19+ messages in thread
From: Yang Li via B4 Relay @ 2024-08-02  9:39 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Catalin Marinas, Will Deacon
  Cc: linux-bluetooth, netdev, devicetree, linux-kernel,
	linux-arm-kernel, Yang Li

From: Yang Li <yang.li@amlogic.com>

Add binding document for Amlogic Bluetooth chipsets attached over UART.

Signed-off-by: Yang Li <yang.li@amlogic.com>
---
 .../bindings/net/bluetooth/amlogic,w155s2-bt.yaml  | 62 ++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/bluetooth/amlogic,w155s2-bt.yaml b/Documentation/devicetree/bindings/net/bluetooth/amlogic,w155s2-bt.yaml
new file mode 100644
index 000000000000..c0c4209cd687
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/bluetooth/amlogic,w155s2-bt.yaml
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) 2024 Amlogic, Inc. All rights reserved
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/bluetooth/amlogic,w155s2-bt.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Amlogic Bluetooth chips
+
+description:
+  The W155S2 is an Amlogic Bluetooth and Wi-Fi combo chip. It works on
+  the standard H4 protocol via a 4-wire UART interface, with baud rates
+  up to 4 Mbps.
+
+maintainers:
+  - Yang Li <yang.li@amlogic.com>
+
+properties:
+  compatible:
+    oneOf:
+      - const: amlogic,w155s2-bt
+      - items:
+          - enum:
+              - amlogic,w265s1-bt
+              - amlogic,w265p1-bt
+              - amlogic,w265s2-bt
+          - const: amlogic,w155s2-bt
+
+  clocks:
+    maxItems: 1
+    description: clock provided to the controller (32.768KHz)
+
+  enable-gpios:
+    maxItems: 1
+
+  vddio-supply:
+    description: VDD_IO supply regulator handle
+
+  firmware-name:
+    maxItems: 1
+    description: specify the path of firmware bin to load
+
+required:
+  - compatible
+  - enable-gpios
+  - vddio-supply
+  - clocks
+  - firmware-name
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    bluetooth {
+        compatible = "amlogic,w155s2-bt";
+        clocks = <&extclk>;
+        enable-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
+        vddio-supply = <&wcn_3v3>;
+        firmware-name = "amlogic/aml_w155s2_bt_uart.bin";
+    };
+

-- 
2.42.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 2/3] Bluetooth: hci_uart: Add support for Amlogic HCI UART
  2024-08-02  9:39 ` Yang Li via B4 Relay
@ 2024-08-02  9:39   ` Yang Li via B4 Relay
  -1 siblings, 0 replies; 19+ messages in thread
From: Yang Li @ 2024-08-02  9:39 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Catalin Marinas, Will Deacon
  Cc: linux-bluetooth, netdev, devicetree, linux-kernel,
	linux-arm-kernel, Yang Li, Ye He

Add support for Amlogic Bluetooth controller over HCI UART.
In order to send the final firmware at full speed(4Mbps).

Co-developed-by: Ye He <ye.he@amlogic.com>
Signed-off-by: Ye He <ye.he@amlogic.com>
Signed-off-by: Yang Li <yang.li@amlogic.com>
---
 drivers/bluetooth/Kconfig     |  12 +
 drivers/bluetooth/Makefile    |   1 +
 drivers/bluetooth/hci_aml.c   | 756 ++++++++++++++++++++++++++++++++++++++++++
 drivers/bluetooth/hci_ldisc.c |   8 +-
 drivers/bluetooth/hci_uart.h  |   8 +-
 5 files changed, 782 insertions(+), 3 deletions(-)

diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index 769fa288179d..18767b54df35 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -274,6 +274,18 @@ config BT_HCIUART_MRVL
 
 	  Say Y here to compile support for HCI MRVL protocol.
 
+config BT_HCIUART_AML
+	bool "Amlogic protocol support"
+	depends on BT_HCIUART
+	depends on BT_HCIUART_SERDEV
+	select BT_HCIUART_H4
+	select FW_LOADER
+	help
+	  The Amlogic protocol support enables Bluetooth HCI over serial
+	  port interface for Amlogic Bluetooth controllers.
+
+	  Say Y here to compile support for HCI AML protocol.
+
 config BT_HCIBCM203X
 	tristate "HCI BCM203x USB driver"
 	depends on USB
diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
index 0730d6684d1a..81856512ddd0 100644
--- a/drivers/bluetooth/Makefile
+++ b/drivers/bluetooth/Makefile
@@ -51,4 +51,5 @@ hci_uart-$(CONFIG_BT_HCIUART_BCM)	+= hci_bcm.o
 hci_uart-$(CONFIG_BT_HCIUART_QCA)	+= hci_qca.o
 hci_uart-$(CONFIG_BT_HCIUART_AG6XX)	+= hci_ag6xx.o
 hci_uart-$(CONFIG_BT_HCIUART_MRVL)	+= hci_mrvl.o
+hci_uart-$(CONFIG_BT_HCIUART_AML)	+= hci_aml.o
 hci_uart-objs				:= $(hci_uart-y)
diff --git a/drivers/bluetooth/hci_aml.c b/drivers/bluetooth/hci_aml.c
new file mode 100644
index 000000000000..cc6627788611
--- /dev/null
+++ b/drivers/bluetooth/hci_aml.c
@@ -0,0 +1,756 @@
+// SPDX-License-Identifier: (GPL-2.0-only OR MIT)
+/*
+ * Copyright (C) 2024 Amlogic, Inc. All rights reserved
+ */
+
+#include <linux/kernel.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/property.h>
+#include <linux/of.h>
+#include <linux/serdev.h>
+#include <linux/clk.h>
+#include <linux/firmware.h>
+#include <linux/gpio/consumer.h>
+#include <linux/regulator/consumer.h>
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+#include <net/bluetooth/hci.h>
+
+#include "hci_uart.h"
+
+#define AML_EVT_HEAD_SIZE		4
+#define AML_BDADDR_DEFAULT (&(bdaddr_t) {{ 0x00, 0xff, 0x00, 0x22, 0x2d, 0xae }})
+
+#define AML_FIRMWARE_OPERATION_SIZE		(248)
+#define AML_FIRMWARE_MAX_SIZE			(512 * 1024)
+
+/* TCI command */
+#define AML_TCI_CMD_READ			0xFEF0
+#define AML_TCI_CMD_WRITE			0xFEF1
+#define AML_TCI_CMD_UPDATE_BAUDRATE		0xFEF2
+#define AML_TCI_CMD_HARDWARE_RESET		0xFEF2
+#define AML_TCI_CMD_DOWNLOAD_BT_FW		0xFEF3
+#define AML_BT_HCI_VENDOR_CMD			0xFC1A
+
+/* TCI operation parameter in controller chip */
+#define AML_OP_UART_MODE			0x00A30128
+#define AML_OP_EVT_ENABLE			0x00A70014
+#define AML_OP_MEM_HARD_TRANS_EN		0x00A7000C
+#define AML_OP_RF_CFG				0x00F03040
+#define AML_OP_RAM_POWER_CTR			0x00F03050
+#define AML_OP_HARDWARE_RST			0x00F03058
+#define AML_OP_ICCM_RAM_BASE			0x00000000
+#define AML_OP_DCCM_RAM_BASE			0x00D00000
+
+/* UART configuration */
+#define AML_UART_XMIT_EN			BIT(12)
+#define AML_UART_RECV_EN			BIT(13)
+#define AML_UART_TIMEOUT_INT_EN			BIT(14)
+#define AML_UART_CLK_SOURCE			40000000
+
+/* Controller event */
+#define AML_EVT_EN				BIT(24)
+
+/* RAM power control */
+#define AML_RAM_POWER_ON			(0)
+#define AML_RAM_POWER_OFF			(1)
+
+/* RF configuration */
+#define AML_RF_ANT_SINGLE			BIT(28)
+#define AML_RF_ANT_DOUBLE			BIT(29)
+
+/* Memory transaction */
+#define AML_MM_CTR_HARD_TRAS_EN			BIT(27)
+
+/* Controller reset */
+#define AML_CTR_CPU_RESET			BIT(8)
+#define AML_CTR_MAC_RESET			BIT(9)
+#define AML_CTR_PHY_RESET			BIT(10)
+
+enum {
+	FW_ICCM,
+	FW_DCCM
+};
+
+struct aml_fw_len {
+	u32 iccm_len;
+	u32 dccm_len;
+};
+
+struct aml_tci_rsp {
+	u8 num_cmd_packet;
+	u16 opcode;
+	u8 status;
+} __packed;
+
+struct aml_device_data {
+	int iccm_offset;
+	int dccm_offset;
+	bool is_coex;
+};
+
+struct aml_serdev {
+	struct hci_uart serdev_hu;
+	struct device *dev;
+	struct gpio_desc *bt_en_gpio;
+	struct regulator *bt_supply;
+	struct clk *lpo_clk;
+	const struct aml_device_data *aml_dev_data;
+	const char *firmware_name;
+};
+
+struct aml_data {
+	struct sk_buff *rx_skb;
+	struct sk_buff_head txq;
+};
+
+static const struct h4_recv_pkt aml_recv_pkts[] = {
+	{ H4_RECV_ACL, .recv = hci_recv_frame },
+	{ H4_RECV_SCO, .recv = hci_recv_frame },
+	{ H4_RECV_EVENT, .recv = hci_recv_frame },
+	{ H4_RECV_ISO, .recv = hci_recv_frame },
+};
+
+/* The TCI command is private command, which is used to configure before BT
+ * chip startup, contains update baudrate, update firmware, set public addr.
+ *
+ * op_code |      op_len           | op_addr | parameter   |
+ * --------|-----------------------|---------|-------------|
+ *   2B    | 1B len(addr+param)    |    4B   |  len(param) |
+ */
+static int aml_send_tci_cmd(struct hci_dev *hdev, u16 op_code, u32 op_addr,
+			    u32 *param, u32 param_len)
+{
+	struct aml_tci_rsp *rsp = NULL;
+	struct sk_buff *skb = NULL;
+	u32 buf_len = 0;
+	u8 *buf = NULL;
+	int err = 0;
+
+	buf_len = sizeof(op_addr) + param_len;
+	buf = kmalloc(buf_len, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	memcpy(buf, &op_addr, sizeof(op_addr));
+	if (param && param_len > 0)
+		memcpy(buf + sizeof(op_addr), param, param_len);
+
+	skb = __hci_cmd_sync_ev(hdev, op_code, buf_len, buf,
+				HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb)) {
+		err = PTR_ERR(skb);
+		bt_dev_err(hdev, "Failed to send TCI cmd:(%d)", err);
+		goto exit;
+	}
+
+	rsp = skb_pull_data(skb, sizeof(struct aml_tci_rsp));
+	if (!rsp)
+		goto skb_free;
+
+	if (rsp->opcode != op_code || rsp->status != 0x00) {
+		bt_dev_err(hdev, "send TCI cmd(0x%04X), response(0x%04X):(%d)",
+		       op_code, rsp->opcode, rsp->status);
+		err = -EINVAL;
+		goto skb_free;
+	}
+
+skb_free:
+	kfree_skb(skb);
+
+exit:
+	kfree(buf);
+	return err;
+}
+
+static int aml_update_chip_baudrate(struct hci_dev *hdev, u32 baud)
+{
+	u32 value;
+
+	value = ((AML_UART_CLK_SOURCE / baud) - 1) & 0x0FFF;
+	value |= AML_UART_XMIT_EN | AML_UART_RECV_EN | AML_UART_TIMEOUT_INT_EN;
+
+	return aml_send_tci_cmd(hdev, AML_TCI_CMD_UPDATE_BAUDRATE,
+				  AML_OP_UART_MODE, &value, sizeof(value));
+}
+
+static int aml_start_chip(struct hci_dev *hdev)
+{
+	u32 value = 0;
+	int ret;
+
+	value = AML_MM_CTR_HARD_TRAS_EN;
+	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
+			       AML_OP_MEM_HARD_TRANS_EN,
+			       &value, sizeof(value));
+	if (ret)
+		return ret;
+
+	/* controller hardware reset. */
+	value = AML_CTR_CPU_RESET | AML_CTR_MAC_RESET | AML_CTR_PHY_RESET;
+	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_HARDWARE_RESET,
+			       AML_OP_HARDWARE_RST,
+			       &value, sizeof(value));
+	return ret;
+}
+
+static int aml_send_firmware_segment(struct hci_dev *hdev,
+				     u8 fw_type,
+				     u8 *seg,
+				     u32 seg_size,
+				     u32 offset)
+{
+	u32 op_addr = 0;
+
+	if (fw_type == FW_ICCM)
+		op_addr = AML_OP_ICCM_RAM_BASE  + offset;
+	else if (fw_type == FW_DCCM)
+		op_addr = AML_OP_DCCM_RAM_BASE + offset;
+
+	return aml_send_tci_cmd(hdev, AML_TCI_CMD_DOWNLOAD_BT_FW,
+			     op_addr, (u32 *)seg, seg_size);
+}
+
+static int aml_send_firmware(struct hci_dev *hdev, u8 fw_type,
+			     u8 *fw, u32 fw_size, u32 offset)
+{
+	u32 seg_size = 0;
+	u32 seg_off = 0;
+
+	if (fw_size > AML_FIRMWARE_MAX_SIZE) {
+		bt_dev_err(hdev, "fw_size error, fw_size:%d, max_size: 512K",
+		       fw_size);
+		return -EINVAL;
+	}
+	while (fw_size > 0) {
+		seg_size = (fw_size > AML_FIRMWARE_OPERATION_SIZE) ?
+			   AML_FIRMWARE_OPERATION_SIZE : fw_size;
+		if (aml_send_firmware_segment(hdev, fw_type, (fw + seg_off),
+					      seg_size, offset)) {
+			bt_dev_err(hdev, "Failed send firmware, type:%d, offset:0x%x",
+			       fw_type, offset);
+			return -EINVAL;
+		}
+		seg_off += seg_size;
+		fw_size -= seg_size;
+		offset += seg_size;
+	}
+	return 0;
+}
+
+static int aml_download_firmware(struct hci_dev *hdev, const char *fw_name)
+{
+	struct hci_uart *hu = hci_get_drvdata(hdev);
+	struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
+	const struct firmware *firmware = NULL;
+	struct aml_fw_len *fw_len = NULL;
+	u8 *iccm_start = NULL, *dccm_start = NULL;
+	u32 iccm_len, dccm_len;
+	u32 value = 0;
+	int ret = 0;
+
+	/* Enable firmware download event. */
+	value = AML_EVT_EN;
+	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
+			       AML_OP_EVT_ENABLE,
+			       &value, sizeof(value));
+	if (ret)
+		goto exit;
+
+	/* RAM power on */
+	value = AML_RAM_POWER_ON;
+	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
+			       AML_OP_RAM_POWER_CTR,
+			       &value, sizeof(value));
+	if (ret)
+		goto exit;
+
+	/* Check RAM power status */
+	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_READ,
+			       AML_OP_RAM_POWER_CTR, NULL, 0);
+	if (ret)
+		goto exit;
+
+	ret = request_firmware(&firmware, fw_name, &hdev->dev);
+	if (ret < 0) {
+		bt_dev_err(hdev, "Failed to load <%s>:(%d)", fw_name, ret);
+		goto exit;
+	}
+
+	fw_len = (struct aml_fw_len *)firmware->data;
+
+	/* Download ICCM */
+	iccm_start = (u8 *)(firmware->data) + sizeof(struct aml_fw_len)
+			+ amldev->aml_dev_data->iccm_offset;
+	iccm_len = fw_len->iccm_len - amldev->aml_dev_data->iccm_offset;
+	ret = aml_send_firmware(hdev, FW_ICCM, iccm_start, iccm_len,
+				amldev->aml_dev_data->iccm_offset);
+	if (ret) {
+		bt_dev_err(hdev, "Failed to send FW_ICCM (%d)", ret);
+		goto exit;
+	}
+
+	/* Download DCCM */
+	dccm_start = (u8 *)(firmware->data) + sizeof(struct aml_fw_len) + fw_len->iccm_len;
+	dccm_len = fw_len->dccm_len;
+	ret = aml_send_firmware(hdev, FW_DCCM, dccm_start, dccm_len,
+				amldev->aml_dev_data->dccm_offset);
+	if (ret) {
+		bt_dev_err(hdev, "Failed to send FW_DCCM (%d)", ret);
+		goto exit;
+	}
+
+	/* Disable firmware download event. */
+	value = 0;
+	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
+			       AML_OP_EVT_ENABLE,
+			       &value, sizeof(value));
+	if (ret)
+		goto exit;
+
+exit:
+	if (firmware)
+		release_firmware(firmware);
+	return ret;
+}
+
+static int aml_send_reset(struct hci_dev *hdev)
+{
+	struct sk_buff *skb;
+	int err;
+
+	skb = __hci_cmd_sync_ev(hdev, HCI_OP_RESET, 0, NULL,
+				HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb)) {
+		err = PTR_ERR(skb);
+		bt_dev_err(hdev, "Failed to send hci reset cmd(%d)", err);
+		return err;
+	}
+
+	kfree_skb(skb);
+	return 0;
+}
+
+static int aml_dump_fw_version(struct hci_dev *hdev)
+{
+	struct aml_tci_rsp *rsp = NULL;
+	struct sk_buff *skb;
+	u8 value[6] = {0};
+	u8 *fw_ver = NULL;
+	int err = 0;
+
+	skb = __hci_cmd_sync_ev(hdev, AML_BT_HCI_VENDOR_CMD, sizeof(value), value,
+				HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb)) {
+		err = PTR_ERR(skb);
+		bt_dev_err(hdev, "Failed get fw version:(%d)", err);
+		return err;
+	}
+
+	rsp = skb_pull_data(skb, sizeof(struct aml_tci_rsp));
+	if (!rsp)
+		goto exit;
+
+	if (rsp->opcode != AML_BT_HCI_VENDOR_CMD || rsp->status != 0x00) {
+		bt_dev_err(hdev, "dump version, error response (0x%04X):(%d)",
+		       rsp->opcode, rsp->status);
+		err = -EINVAL;
+		goto exit;
+	}
+
+	fw_ver = (u8 *)rsp + AML_EVT_HEAD_SIZE;
+	bt_dev_info(hdev, "fw_version: date = %02x.%02x, number = 0x%02x%02x",
+		*(fw_ver + 1), *fw_ver, *(fw_ver + 3), *(fw_ver + 2));
+
+exit:
+	kfree_skb(skb);
+	return err;
+}
+
+static int aml_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
+{
+	struct aml_tci_rsp *rsp = NULL;
+	struct sk_buff *skb;
+	int err = 0;
+
+	bt_dev_info(hdev, "set bdaddr (%pM)", bdaddr);
+	skb = __hci_cmd_sync_ev(hdev, AML_BT_HCI_VENDOR_CMD,
+				sizeof(bdaddr_t), bdaddr,
+				HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb)) {
+		err = PTR_ERR(skb);
+		bt_dev_err(hdev, "Failed to set bdaddr:(%d)", err);
+		return err;
+	}
+
+	rsp = skb_pull_data(skb, sizeof(struct aml_tci_rsp));
+	if (!rsp)
+		goto exit;
+
+	if (rsp->opcode != AML_BT_HCI_VENDOR_CMD || rsp->status != 0x00) {
+		bt_dev_err(hdev, "error response (0x%x):(%d)", rsp->opcode, rsp->status);
+		err = -EINVAL;
+		goto exit;
+	}
+
+exit:
+	kfree_skb(skb);
+	return err;
+}
+
+static int aml_check_bdaddr(struct hci_dev *hdev)
+{
+	struct hci_rp_read_bd_addr *paddr;
+	struct sk_buff *skb;
+	int err;
+
+	if (bacmp(&hdev->public_addr, BDADDR_ANY))
+		return 0;
+
+	skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
+			     HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb)) {
+		err = PTR_ERR(skb);
+		bt_dev_err(hdev, "Failed to read bdaddr:(%d)", err);
+		return err;
+	}
+
+	paddr = skb_pull_data(skb, sizeof(struct hci_rp_read_bd_addr));
+	if (!paddr)
+		goto exit;
+
+	if (!bacmp(&paddr->bdaddr, AML_BDADDR_DEFAULT)) {
+		bt_dev_info(hdev, "amlbt using default bdaddr (%pM)", &paddr->bdaddr);
+		set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+	}
+
+exit:
+	kfree_skb(skb);
+	return 0;
+}
+
+static int aml_config_rf(struct hci_dev *hdev, bool is_coex)
+{
+	u32 value = AML_RF_ANT_DOUBLE;
+
+	/* Use a single antenna when co-existing with wifi. */
+	if (is_coex)
+		value = AML_RF_ANT_SINGLE;
+
+	return aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
+				AML_OP_RF_CFG,
+				&value, sizeof(value));
+}
+
+static int aml_parse_dt(struct aml_serdev *amldev)
+{
+	struct device *pdev = amldev->dev;
+
+	amldev->bt_en_gpio = devm_gpiod_get(pdev, "enable",
+					GPIOD_OUT_LOW);
+	if (IS_ERR(amldev->bt_en_gpio)) {
+		dev_err(pdev, "Failed to acquire enable gpios");
+		return PTR_ERR(amldev->bt_en_gpio);
+	}
+
+	if (device_property_read_string(pdev, "firmware-name",
+					&amldev->firmware_name)) {
+		dev_err(pdev, "Failed to acquire firmware path");
+		return -ENODEV;
+	}
+
+	amldev->bt_supply = devm_regulator_get(pdev, "vddio");
+	if (IS_ERR(amldev->bt_supply)) {
+		dev_err(pdev, "Failed to acquire regulator");
+		return PTR_ERR(amldev->bt_supply);
+	}
+
+	amldev->lpo_clk = devm_clk_get(pdev, NULL);
+	if (IS_ERR(amldev->lpo_clk)) {
+		dev_err(pdev, "Failed to acquire clock source");
+		return PTR_ERR(amldev->lpo_clk);
+	}
+
+	return 0;
+}
+
+static int aml_power_on(struct aml_serdev *amldev)
+{
+	int err;
+
+	err = regulator_enable(amldev->bt_supply);
+	if (err) {
+		dev_err(amldev->dev, "Failed to enable regulator: (%d)", err);
+		return err;
+	}
+
+	err = clk_prepare_enable(amldev->lpo_clk);
+	if (err) {
+		dev_err(amldev->dev, "Failed to enable lpo clock: (%d)", err);
+		return err;
+	}
+
+	gpiod_set_value_cansleep(amldev->bt_en_gpio, 1);
+
+	/* wait 100ms for bluetooth controller power on  */
+	msleep(100);
+	return 0;
+}
+
+static int aml_power_off(struct aml_serdev *amldev)
+{
+	gpiod_set_value_cansleep(amldev->bt_en_gpio, 0);
+
+	clk_disable_unprepare(amldev->lpo_clk);
+
+	regulator_disable(amldev->bt_supply);
+
+	return 0;
+}
+
+static int aml_set_baudrate(struct hci_uart *hu, unsigned int speed)
+{
+	/* update controller baudrate*/
+	if (aml_update_chip_baudrate(hu->hdev, speed) != 0) {
+		bt_dev_err(hu->hdev, "Failed to update baud rate");
+		return -EINVAL;
+	}
+
+	/* update local baudrate*/
+	serdev_device_set_baudrate(hu->serdev, speed);
+
+	return 0;
+}
+
+/* Initialize protocol */
+static int aml_open(struct hci_uart *hu)
+{
+	struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
+	struct aml_data *aml_data;
+	int err;
+
+	err = aml_parse_dt(amldev);
+	if (err)
+		return err;
+
+	if (!hci_uart_has_flow_control(hu)) {
+		bt_dev_err(hu->hdev, "no flow control");
+		return -EOPNOTSUPP;
+	}
+
+	aml_data = kzalloc(sizeof(*aml_data), GFP_KERNEL);
+	if (!aml_data)
+		return -ENOMEM;
+
+	skb_queue_head_init(&aml_data->txq);
+
+	hu->priv = aml_data;
+
+	return 0;
+}
+
+static int aml_close(struct hci_uart *hu)
+{
+	struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
+	struct aml_data *aml_data = hu->priv;
+
+	if (hu->serdev)
+		serdev_device_close(hu->serdev);
+
+	skb_queue_purge(&aml_data->txq);
+	kfree_skb(aml_data->rx_skb);
+	kfree(aml_data);
+
+	hu->priv = NULL;
+
+	return aml_power_off(amldev);
+}
+
+static int aml_flush(struct hci_uart *hu)
+{
+	struct aml_data *aml_data = hu->priv;
+
+	skb_queue_purge(&aml_data->txq);
+
+	return 0;
+}
+
+static int aml_setup(struct hci_uart *hu)
+{
+	struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
+	struct hci_dev *hdev = amldev->serdev_hu.hdev;
+	int err;
+
+	/* Setup bdaddr */
+	hdev->set_bdaddr = aml_set_bdaddr;
+
+	err = aml_power_on(amldev);
+	if (err)
+		return err;
+
+	err = aml_set_baudrate(hu, amldev->serdev_hu.proto->oper_speed);
+	if (err)
+		return err;
+
+	err = aml_download_firmware(hdev, amldev->firmware_name);
+	if (err)
+		return err;
+
+	err = aml_config_rf(hdev, amldev->aml_dev_data->is_coex);
+	if (err)
+		return err;
+
+	err = aml_start_chip(hdev);
+	if (err)
+		return err;
+
+	/* wait 350ms for controller start up*/
+	msleep(350);
+
+	err = aml_dump_fw_version(hdev);
+	if (err)
+		return err;
+
+	err = aml_send_reset(hdev);
+	if (err)
+		return err;
+
+	err = aml_check_bdaddr(hdev);
+	if (err)
+		return err;
+
+	return 0;
+}
+
+static int aml_enqueue(struct hci_uart *hu, struct sk_buff *skb)
+{
+	struct aml_data *aml_data = hu->priv;
+
+	skb_queue_tail(&aml_data->txq, skb);
+
+	return 0;
+}
+
+static struct sk_buff *aml_dequeue(struct hci_uart *hu)
+{
+	struct aml_data *aml_data = hu->priv;
+	struct sk_buff *skb;
+
+	skb = skb_dequeue(&aml_data->txq);
+
+	/* Prepend skb with frame type */
+	if (skb)
+		memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
+
+	return skb;
+}
+
+static int aml_recv(struct hci_uart *hu, const void *data, int count)
+{
+	struct aml_data *aml_data = hu->priv;
+	int err;
+
+	aml_data->rx_skb = h4_recv_buf(hu->hdev, aml_data->rx_skb, data, count,
+				       aml_recv_pkts,
+				       ARRAY_SIZE(aml_recv_pkts));
+	if (IS_ERR(aml_data->rx_skb)) {
+		err = PTR_ERR(aml_data->rx_skb);
+		bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err);
+		aml_data->rx_skb = NULL;
+		return err;
+	}
+
+	return count;
+}
+
+static const struct hci_uart_proto aml_hci_proto = {
+	.id		= HCI_UART_AML,
+	.name		= "AML",
+	.manufacturer	= 50,
+	.init_speed	= 115200,
+	.oper_speed	= 4000000,
+	.open		= aml_open,
+	.close		= aml_close,
+	.setup		= aml_setup,
+	.flush		= aml_flush,
+	.recv		= aml_recv,
+	.enqueue	= aml_enqueue,
+	.dequeue	= aml_dequeue,
+};
+
+static void aml_device_driver_shutdown(struct device *dev)
+{
+	struct aml_serdev *amldev = dev_get_drvdata(dev);
+
+	aml_power_off(amldev);
+}
+
+static int aml_serdev_probe(struct serdev_device *serdev)
+{
+	struct aml_serdev *amldev;
+	int err;
+
+	amldev = devm_kzalloc(&serdev->dev, sizeof(*amldev), GFP_KERNEL);
+	if (!amldev)
+		return -ENOMEM;
+
+	amldev->serdev_hu.serdev = serdev;
+	amldev->dev = &serdev->dev;
+	serdev_device_set_drvdata(serdev, amldev);
+
+	err = hci_uart_register_device(&amldev->serdev_hu, &aml_hci_proto);
+	if (err)
+		return dev_err_probe(amldev->dev, err,
+			      "Failed to register hci uart device");
+
+	amldev->aml_dev_data = device_get_match_data(&serdev->dev);
+
+	return 0;
+}
+
+static void aml_serdev_remove(struct serdev_device *serdev)
+{
+	struct aml_serdev *amldev = serdev_device_get_drvdata(serdev);
+
+	hci_uart_unregister_device(&amldev->serdev_hu);
+}
+
+static const struct aml_device_data data_w155s2 = {
+	.iccm_offset = 256 * 1024,
+};
+
+static const struct aml_device_data data_w265s2 = {
+	.iccm_offset = 384 * 1024,
+};
+
+static const struct of_device_id aml_bluetooth_of_match[] = {
+	{ .compatible = "amlogic,w155s2-bt", .data = &data_w155s2 },
+	{ .compatible = "amlogic,w265s2-bt", .data = &data_w265s2 },
+	{ /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, aml_bluetooth_of_match);
+
+static struct serdev_device_driver aml_serdev_driver = {
+	.probe = aml_serdev_probe,
+	.remove = aml_serdev_remove,
+	.driver = {
+		.name = "hci_uart_aml",
+		.of_match_table = aml_bluetooth_of_match,
+		.shutdown = aml_device_driver_shutdown,
+	},
+};
+
+int __init aml_init(void)
+{
+	serdev_device_driver_register(&aml_serdev_driver);
+
+	return hci_uart_register_proto(&aml_hci_proto);
+}
+
+int __exit aml_deinit(void)
+{
+	serdev_device_driver_unregister(&aml_serdev_driver);
+
+	return hci_uart_unregister_proto(&aml_hci_proto);
+}
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 30192bb08354..d307c41a5470 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -870,7 +870,9 @@ static int __init hci_uart_init(void)
 #ifdef CONFIG_BT_HCIUART_MRVL
 	mrvl_init();
 #endif
-
+#ifdef CONFIG_BT_HCIUART_AML
+	aml_init();
+#endif
 	return 0;
 }
 
@@ -906,7 +908,9 @@ static void __exit hci_uart_exit(void)
 #ifdef CONFIG_BT_HCIUART_MRVL
 	mrvl_deinit();
 #endif
-
+#ifdef CONFIG_BT_HCIUART_AML
+	aml_deinit();
+#endif
 	tty_unregister_ldisc(&hci_uart_ldisc);
 }
 
diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h
index 00bf7ae82c5b..fbf3079b92a5 100644
--- a/drivers/bluetooth/hci_uart.h
+++ b/drivers/bluetooth/hci_uart.h
@@ -20,7 +20,7 @@
 #define HCIUARTGETFLAGS		_IOR('U', 204, int)
 
 /* UART protocols */
-#define HCI_UART_MAX_PROTO	12
+#define HCI_UART_MAX_PROTO	13
 
 #define HCI_UART_H4	0
 #define HCI_UART_BCSP	1
@@ -34,6 +34,7 @@
 #define HCI_UART_AG6XX	9
 #define HCI_UART_NOKIA	10
 #define HCI_UART_MRVL	11
+#define HCI_UART_AML	12
 
 #define HCI_UART_RAW_DEVICE	0
 #define HCI_UART_RESET_ON_INIT	1
@@ -209,3 +210,8 @@ int ag6xx_deinit(void);
 int mrvl_init(void);
 int mrvl_deinit(void);
 #endif
+
+#ifdef CONFIG_BT_HCIUART_AML
+int aml_init(void);
+int aml_deinit(void);
+#endif

-- 
2.42.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 2/3] Bluetooth: hci_uart: Add support for Amlogic HCI UART
@ 2024-08-02  9:39   ` Yang Li via B4 Relay
  0 siblings, 0 replies; 19+ messages in thread
From: Yang Li via B4 Relay @ 2024-08-02  9:39 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Catalin Marinas, Will Deacon
  Cc: linux-bluetooth, netdev, devicetree, linux-kernel,
	linux-arm-kernel, Yang Li, Ye He

From: Yang Li <yang.li@amlogic.com>

Add support for Amlogic Bluetooth controller over HCI UART.
In order to send the final firmware at full speed(4Mbps).

Co-developed-by: Ye He <ye.he@amlogic.com>
Signed-off-by: Ye He <ye.he@amlogic.com>
Signed-off-by: Yang Li <yang.li@amlogic.com>
---
 drivers/bluetooth/Kconfig     |  12 +
 drivers/bluetooth/Makefile    |   1 +
 drivers/bluetooth/hci_aml.c   | 756 ++++++++++++++++++++++++++++++++++++++++++
 drivers/bluetooth/hci_ldisc.c |   8 +-
 drivers/bluetooth/hci_uart.h  |   8 +-
 5 files changed, 782 insertions(+), 3 deletions(-)

diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index 769fa288179d..18767b54df35 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -274,6 +274,18 @@ config BT_HCIUART_MRVL
 
 	  Say Y here to compile support for HCI MRVL protocol.
 
+config BT_HCIUART_AML
+	bool "Amlogic protocol support"
+	depends on BT_HCIUART
+	depends on BT_HCIUART_SERDEV
+	select BT_HCIUART_H4
+	select FW_LOADER
+	help
+	  The Amlogic protocol support enables Bluetooth HCI over serial
+	  port interface for Amlogic Bluetooth controllers.
+
+	  Say Y here to compile support for HCI AML protocol.
+
 config BT_HCIBCM203X
 	tristate "HCI BCM203x USB driver"
 	depends on USB
diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
index 0730d6684d1a..81856512ddd0 100644
--- a/drivers/bluetooth/Makefile
+++ b/drivers/bluetooth/Makefile
@@ -51,4 +51,5 @@ hci_uart-$(CONFIG_BT_HCIUART_BCM)	+= hci_bcm.o
 hci_uart-$(CONFIG_BT_HCIUART_QCA)	+= hci_qca.o
 hci_uart-$(CONFIG_BT_HCIUART_AG6XX)	+= hci_ag6xx.o
 hci_uart-$(CONFIG_BT_HCIUART_MRVL)	+= hci_mrvl.o
+hci_uart-$(CONFIG_BT_HCIUART_AML)	+= hci_aml.o
 hci_uart-objs				:= $(hci_uart-y)
diff --git a/drivers/bluetooth/hci_aml.c b/drivers/bluetooth/hci_aml.c
new file mode 100644
index 000000000000..cc6627788611
--- /dev/null
+++ b/drivers/bluetooth/hci_aml.c
@@ -0,0 +1,756 @@
+// SPDX-License-Identifier: (GPL-2.0-only OR MIT)
+/*
+ * Copyright (C) 2024 Amlogic, Inc. All rights reserved
+ */
+
+#include <linux/kernel.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/property.h>
+#include <linux/of.h>
+#include <linux/serdev.h>
+#include <linux/clk.h>
+#include <linux/firmware.h>
+#include <linux/gpio/consumer.h>
+#include <linux/regulator/consumer.h>
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+#include <net/bluetooth/hci.h>
+
+#include "hci_uart.h"
+
+#define AML_EVT_HEAD_SIZE		4
+#define AML_BDADDR_DEFAULT (&(bdaddr_t) {{ 0x00, 0xff, 0x00, 0x22, 0x2d, 0xae }})
+
+#define AML_FIRMWARE_OPERATION_SIZE		(248)
+#define AML_FIRMWARE_MAX_SIZE			(512 * 1024)
+
+/* TCI command */
+#define AML_TCI_CMD_READ			0xFEF0
+#define AML_TCI_CMD_WRITE			0xFEF1
+#define AML_TCI_CMD_UPDATE_BAUDRATE		0xFEF2
+#define AML_TCI_CMD_HARDWARE_RESET		0xFEF2
+#define AML_TCI_CMD_DOWNLOAD_BT_FW		0xFEF3
+#define AML_BT_HCI_VENDOR_CMD			0xFC1A
+
+/* TCI operation parameter in controller chip */
+#define AML_OP_UART_MODE			0x00A30128
+#define AML_OP_EVT_ENABLE			0x00A70014
+#define AML_OP_MEM_HARD_TRANS_EN		0x00A7000C
+#define AML_OP_RF_CFG				0x00F03040
+#define AML_OP_RAM_POWER_CTR			0x00F03050
+#define AML_OP_HARDWARE_RST			0x00F03058
+#define AML_OP_ICCM_RAM_BASE			0x00000000
+#define AML_OP_DCCM_RAM_BASE			0x00D00000
+
+/* UART configuration */
+#define AML_UART_XMIT_EN			BIT(12)
+#define AML_UART_RECV_EN			BIT(13)
+#define AML_UART_TIMEOUT_INT_EN			BIT(14)
+#define AML_UART_CLK_SOURCE			40000000
+
+/* Controller event */
+#define AML_EVT_EN				BIT(24)
+
+/* RAM power control */
+#define AML_RAM_POWER_ON			(0)
+#define AML_RAM_POWER_OFF			(1)
+
+/* RF configuration */
+#define AML_RF_ANT_SINGLE			BIT(28)
+#define AML_RF_ANT_DOUBLE			BIT(29)
+
+/* Memory transaction */
+#define AML_MM_CTR_HARD_TRAS_EN			BIT(27)
+
+/* Controller reset */
+#define AML_CTR_CPU_RESET			BIT(8)
+#define AML_CTR_MAC_RESET			BIT(9)
+#define AML_CTR_PHY_RESET			BIT(10)
+
+enum {
+	FW_ICCM,
+	FW_DCCM
+};
+
+struct aml_fw_len {
+	u32 iccm_len;
+	u32 dccm_len;
+};
+
+struct aml_tci_rsp {
+	u8 num_cmd_packet;
+	u16 opcode;
+	u8 status;
+} __packed;
+
+struct aml_device_data {
+	int iccm_offset;
+	int dccm_offset;
+	bool is_coex;
+};
+
+struct aml_serdev {
+	struct hci_uart serdev_hu;
+	struct device *dev;
+	struct gpio_desc *bt_en_gpio;
+	struct regulator *bt_supply;
+	struct clk *lpo_clk;
+	const struct aml_device_data *aml_dev_data;
+	const char *firmware_name;
+};
+
+struct aml_data {
+	struct sk_buff *rx_skb;
+	struct sk_buff_head txq;
+};
+
+static const struct h4_recv_pkt aml_recv_pkts[] = {
+	{ H4_RECV_ACL, .recv = hci_recv_frame },
+	{ H4_RECV_SCO, .recv = hci_recv_frame },
+	{ H4_RECV_EVENT, .recv = hci_recv_frame },
+	{ H4_RECV_ISO, .recv = hci_recv_frame },
+};
+
+/* The TCI command is private command, which is used to configure before BT
+ * chip startup, contains update baudrate, update firmware, set public addr.
+ *
+ * op_code |      op_len           | op_addr | parameter   |
+ * --------|-----------------------|---------|-------------|
+ *   2B    | 1B len(addr+param)    |    4B   |  len(param) |
+ */
+static int aml_send_tci_cmd(struct hci_dev *hdev, u16 op_code, u32 op_addr,
+			    u32 *param, u32 param_len)
+{
+	struct aml_tci_rsp *rsp = NULL;
+	struct sk_buff *skb = NULL;
+	u32 buf_len = 0;
+	u8 *buf = NULL;
+	int err = 0;
+
+	buf_len = sizeof(op_addr) + param_len;
+	buf = kmalloc(buf_len, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	memcpy(buf, &op_addr, sizeof(op_addr));
+	if (param && param_len > 0)
+		memcpy(buf + sizeof(op_addr), param, param_len);
+
+	skb = __hci_cmd_sync_ev(hdev, op_code, buf_len, buf,
+				HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb)) {
+		err = PTR_ERR(skb);
+		bt_dev_err(hdev, "Failed to send TCI cmd:(%d)", err);
+		goto exit;
+	}
+
+	rsp = skb_pull_data(skb, sizeof(struct aml_tci_rsp));
+	if (!rsp)
+		goto skb_free;
+
+	if (rsp->opcode != op_code || rsp->status != 0x00) {
+		bt_dev_err(hdev, "send TCI cmd(0x%04X), response(0x%04X):(%d)",
+		       op_code, rsp->opcode, rsp->status);
+		err = -EINVAL;
+		goto skb_free;
+	}
+
+skb_free:
+	kfree_skb(skb);
+
+exit:
+	kfree(buf);
+	return err;
+}
+
+static int aml_update_chip_baudrate(struct hci_dev *hdev, u32 baud)
+{
+	u32 value;
+
+	value = ((AML_UART_CLK_SOURCE / baud) - 1) & 0x0FFF;
+	value |= AML_UART_XMIT_EN | AML_UART_RECV_EN | AML_UART_TIMEOUT_INT_EN;
+
+	return aml_send_tci_cmd(hdev, AML_TCI_CMD_UPDATE_BAUDRATE,
+				  AML_OP_UART_MODE, &value, sizeof(value));
+}
+
+static int aml_start_chip(struct hci_dev *hdev)
+{
+	u32 value = 0;
+	int ret;
+
+	value = AML_MM_CTR_HARD_TRAS_EN;
+	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
+			       AML_OP_MEM_HARD_TRANS_EN,
+			       &value, sizeof(value));
+	if (ret)
+		return ret;
+
+	/* controller hardware reset. */
+	value = AML_CTR_CPU_RESET | AML_CTR_MAC_RESET | AML_CTR_PHY_RESET;
+	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_HARDWARE_RESET,
+			       AML_OP_HARDWARE_RST,
+			       &value, sizeof(value));
+	return ret;
+}
+
+static int aml_send_firmware_segment(struct hci_dev *hdev,
+				     u8 fw_type,
+				     u8 *seg,
+				     u32 seg_size,
+				     u32 offset)
+{
+	u32 op_addr = 0;
+
+	if (fw_type == FW_ICCM)
+		op_addr = AML_OP_ICCM_RAM_BASE  + offset;
+	else if (fw_type == FW_DCCM)
+		op_addr = AML_OP_DCCM_RAM_BASE + offset;
+
+	return aml_send_tci_cmd(hdev, AML_TCI_CMD_DOWNLOAD_BT_FW,
+			     op_addr, (u32 *)seg, seg_size);
+}
+
+static int aml_send_firmware(struct hci_dev *hdev, u8 fw_type,
+			     u8 *fw, u32 fw_size, u32 offset)
+{
+	u32 seg_size = 0;
+	u32 seg_off = 0;
+
+	if (fw_size > AML_FIRMWARE_MAX_SIZE) {
+		bt_dev_err(hdev, "fw_size error, fw_size:%d, max_size: 512K",
+		       fw_size);
+		return -EINVAL;
+	}
+	while (fw_size > 0) {
+		seg_size = (fw_size > AML_FIRMWARE_OPERATION_SIZE) ?
+			   AML_FIRMWARE_OPERATION_SIZE : fw_size;
+		if (aml_send_firmware_segment(hdev, fw_type, (fw + seg_off),
+					      seg_size, offset)) {
+			bt_dev_err(hdev, "Failed send firmware, type:%d, offset:0x%x",
+			       fw_type, offset);
+			return -EINVAL;
+		}
+		seg_off += seg_size;
+		fw_size -= seg_size;
+		offset += seg_size;
+	}
+	return 0;
+}
+
+static int aml_download_firmware(struct hci_dev *hdev, const char *fw_name)
+{
+	struct hci_uart *hu = hci_get_drvdata(hdev);
+	struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
+	const struct firmware *firmware = NULL;
+	struct aml_fw_len *fw_len = NULL;
+	u8 *iccm_start = NULL, *dccm_start = NULL;
+	u32 iccm_len, dccm_len;
+	u32 value = 0;
+	int ret = 0;
+
+	/* Enable firmware download event. */
+	value = AML_EVT_EN;
+	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
+			       AML_OP_EVT_ENABLE,
+			       &value, sizeof(value));
+	if (ret)
+		goto exit;
+
+	/* RAM power on */
+	value = AML_RAM_POWER_ON;
+	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
+			       AML_OP_RAM_POWER_CTR,
+			       &value, sizeof(value));
+	if (ret)
+		goto exit;
+
+	/* Check RAM power status */
+	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_READ,
+			       AML_OP_RAM_POWER_CTR, NULL, 0);
+	if (ret)
+		goto exit;
+
+	ret = request_firmware(&firmware, fw_name, &hdev->dev);
+	if (ret < 0) {
+		bt_dev_err(hdev, "Failed to load <%s>:(%d)", fw_name, ret);
+		goto exit;
+	}
+
+	fw_len = (struct aml_fw_len *)firmware->data;
+
+	/* Download ICCM */
+	iccm_start = (u8 *)(firmware->data) + sizeof(struct aml_fw_len)
+			+ amldev->aml_dev_data->iccm_offset;
+	iccm_len = fw_len->iccm_len - amldev->aml_dev_data->iccm_offset;
+	ret = aml_send_firmware(hdev, FW_ICCM, iccm_start, iccm_len,
+				amldev->aml_dev_data->iccm_offset);
+	if (ret) {
+		bt_dev_err(hdev, "Failed to send FW_ICCM (%d)", ret);
+		goto exit;
+	}
+
+	/* Download DCCM */
+	dccm_start = (u8 *)(firmware->data) + sizeof(struct aml_fw_len) + fw_len->iccm_len;
+	dccm_len = fw_len->dccm_len;
+	ret = aml_send_firmware(hdev, FW_DCCM, dccm_start, dccm_len,
+				amldev->aml_dev_data->dccm_offset);
+	if (ret) {
+		bt_dev_err(hdev, "Failed to send FW_DCCM (%d)", ret);
+		goto exit;
+	}
+
+	/* Disable firmware download event. */
+	value = 0;
+	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
+			       AML_OP_EVT_ENABLE,
+			       &value, sizeof(value));
+	if (ret)
+		goto exit;
+
+exit:
+	if (firmware)
+		release_firmware(firmware);
+	return ret;
+}
+
+static int aml_send_reset(struct hci_dev *hdev)
+{
+	struct sk_buff *skb;
+	int err;
+
+	skb = __hci_cmd_sync_ev(hdev, HCI_OP_RESET, 0, NULL,
+				HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb)) {
+		err = PTR_ERR(skb);
+		bt_dev_err(hdev, "Failed to send hci reset cmd(%d)", err);
+		return err;
+	}
+
+	kfree_skb(skb);
+	return 0;
+}
+
+static int aml_dump_fw_version(struct hci_dev *hdev)
+{
+	struct aml_tci_rsp *rsp = NULL;
+	struct sk_buff *skb;
+	u8 value[6] = {0};
+	u8 *fw_ver = NULL;
+	int err = 0;
+
+	skb = __hci_cmd_sync_ev(hdev, AML_BT_HCI_VENDOR_CMD, sizeof(value), value,
+				HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb)) {
+		err = PTR_ERR(skb);
+		bt_dev_err(hdev, "Failed get fw version:(%d)", err);
+		return err;
+	}
+
+	rsp = skb_pull_data(skb, sizeof(struct aml_tci_rsp));
+	if (!rsp)
+		goto exit;
+
+	if (rsp->opcode != AML_BT_HCI_VENDOR_CMD || rsp->status != 0x00) {
+		bt_dev_err(hdev, "dump version, error response (0x%04X):(%d)",
+		       rsp->opcode, rsp->status);
+		err = -EINVAL;
+		goto exit;
+	}
+
+	fw_ver = (u8 *)rsp + AML_EVT_HEAD_SIZE;
+	bt_dev_info(hdev, "fw_version: date = %02x.%02x, number = 0x%02x%02x",
+		*(fw_ver + 1), *fw_ver, *(fw_ver + 3), *(fw_ver + 2));
+
+exit:
+	kfree_skb(skb);
+	return err;
+}
+
+static int aml_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
+{
+	struct aml_tci_rsp *rsp = NULL;
+	struct sk_buff *skb;
+	int err = 0;
+
+	bt_dev_info(hdev, "set bdaddr (%pM)", bdaddr);
+	skb = __hci_cmd_sync_ev(hdev, AML_BT_HCI_VENDOR_CMD,
+				sizeof(bdaddr_t), bdaddr,
+				HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb)) {
+		err = PTR_ERR(skb);
+		bt_dev_err(hdev, "Failed to set bdaddr:(%d)", err);
+		return err;
+	}
+
+	rsp = skb_pull_data(skb, sizeof(struct aml_tci_rsp));
+	if (!rsp)
+		goto exit;
+
+	if (rsp->opcode != AML_BT_HCI_VENDOR_CMD || rsp->status != 0x00) {
+		bt_dev_err(hdev, "error response (0x%x):(%d)", rsp->opcode, rsp->status);
+		err = -EINVAL;
+		goto exit;
+	}
+
+exit:
+	kfree_skb(skb);
+	return err;
+}
+
+static int aml_check_bdaddr(struct hci_dev *hdev)
+{
+	struct hci_rp_read_bd_addr *paddr;
+	struct sk_buff *skb;
+	int err;
+
+	if (bacmp(&hdev->public_addr, BDADDR_ANY))
+		return 0;
+
+	skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
+			     HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb)) {
+		err = PTR_ERR(skb);
+		bt_dev_err(hdev, "Failed to read bdaddr:(%d)", err);
+		return err;
+	}
+
+	paddr = skb_pull_data(skb, sizeof(struct hci_rp_read_bd_addr));
+	if (!paddr)
+		goto exit;
+
+	if (!bacmp(&paddr->bdaddr, AML_BDADDR_DEFAULT)) {
+		bt_dev_info(hdev, "amlbt using default bdaddr (%pM)", &paddr->bdaddr);
+		set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
+	}
+
+exit:
+	kfree_skb(skb);
+	return 0;
+}
+
+static int aml_config_rf(struct hci_dev *hdev, bool is_coex)
+{
+	u32 value = AML_RF_ANT_DOUBLE;
+
+	/* Use a single antenna when co-existing with wifi. */
+	if (is_coex)
+		value = AML_RF_ANT_SINGLE;
+
+	return aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
+				AML_OP_RF_CFG,
+				&value, sizeof(value));
+}
+
+static int aml_parse_dt(struct aml_serdev *amldev)
+{
+	struct device *pdev = amldev->dev;
+
+	amldev->bt_en_gpio = devm_gpiod_get(pdev, "enable",
+					GPIOD_OUT_LOW);
+	if (IS_ERR(amldev->bt_en_gpio)) {
+		dev_err(pdev, "Failed to acquire enable gpios");
+		return PTR_ERR(amldev->bt_en_gpio);
+	}
+
+	if (device_property_read_string(pdev, "firmware-name",
+					&amldev->firmware_name)) {
+		dev_err(pdev, "Failed to acquire firmware path");
+		return -ENODEV;
+	}
+
+	amldev->bt_supply = devm_regulator_get(pdev, "vddio");
+	if (IS_ERR(amldev->bt_supply)) {
+		dev_err(pdev, "Failed to acquire regulator");
+		return PTR_ERR(amldev->bt_supply);
+	}
+
+	amldev->lpo_clk = devm_clk_get(pdev, NULL);
+	if (IS_ERR(amldev->lpo_clk)) {
+		dev_err(pdev, "Failed to acquire clock source");
+		return PTR_ERR(amldev->lpo_clk);
+	}
+
+	return 0;
+}
+
+static int aml_power_on(struct aml_serdev *amldev)
+{
+	int err;
+
+	err = regulator_enable(amldev->bt_supply);
+	if (err) {
+		dev_err(amldev->dev, "Failed to enable regulator: (%d)", err);
+		return err;
+	}
+
+	err = clk_prepare_enable(amldev->lpo_clk);
+	if (err) {
+		dev_err(amldev->dev, "Failed to enable lpo clock: (%d)", err);
+		return err;
+	}
+
+	gpiod_set_value_cansleep(amldev->bt_en_gpio, 1);
+
+	/* wait 100ms for bluetooth controller power on  */
+	msleep(100);
+	return 0;
+}
+
+static int aml_power_off(struct aml_serdev *amldev)
+{
+	gpiod_set_value_cansleep(amldev->bt_en_gpio, 0);
+
+	clk_disable_unprepare(amldev->lpo_clk);
+
+	regulator_disable(amldev->bt_supply);
+
+	return 0;
+}
+
+static int aml_set_baudrate(struct hci_uart *hu, unsigned int speed)
+{
+	/* update controller baudrate*/
+	if (aml_update_chip_baudrate(hu->hdev, speed) != 0) {
+		bt_dev_err(hu->hdev, "Failed to update baud rate");
+		return -EINVAL;
+	}
+
+	/* update local baudrate*/
+	serdev_device_set_baudrate(hu->serdev, speed);
+
+	return 0;
+}
+
+/* Initialize protocol */
+static int aml_open(struct hci_uart *hu)
+{
+	struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
+	struct aml_data *aml_data;
+	int err;
+
+	err = aml_parse_dt(amldev);
+	if (err)
+		return err;
+
+	if (!hci_uart_has_flow_control(hu)) {
+		bt_dev_err(hu->hdev, "no flow control");
+		return -EOPNOTSUPP;
+	}
+
+	aml_data = kzalloc(sizeof(*aml_data), GFP_KERNEL);
+	if (!aml_data)
+		return -ENOMEM;
+
+	skb_queue_head_init(&aml_data->txq);
+
+	hu->priv = aml_data;
+
+	return 0;
+}
+
+static int aml_close(struct hci_uart *hu)
+{
+	struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
+	struct aml_data *aml_data = hu->priv;
+
+	if (hu->serdev)
+		serdev_device_close(hu->serdev);
+
+	skb_queue_purge(&aml_data->txq);
+	kfree_skb(aml_data->rx_skb);
+	kfree(aml_data);
+
+	hu->priv = NULL;
+
+	return aml_power_off(amldev);
+}
+
+static int aml_flush(struct hci_uart *hu)
+{
+	struct aml_data *aml_data = hu->priv;
+
+	skb_queue_purge(&aml_data->txq);
+
+	return 0;
+}
+
+static int aml_setup(struct hci_uart *hu)
+{
+	struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
+	struct hci_dev *hdev = amldev->serdev_hu.hdev;
+	int err;
+
+	/* Setup bdaddr */
+	hdev->set_bdaddr = aml_set_bdaddr;
+
+	err = aml_power_on(amldev);
+	if (err)
+		return err;
+
+	err = aml_set_baudrate(hu, amldev->serdev_hu.proto->oper_speed);
+	if (err)
+		return err;
+
+	err = aml_download_firmware(hdev, amldev->firmware_name);
+	if (err)
+		return err;
+
+	err = aml_config_rf(hdev, amldev->aml_dev_data->is_coex);
+	if (err)
+		return err;
+
+	err = aml_start_chip(hdev);
+	if (err)
+		return err;
+
+	/* wait 350ms for controller start up*/
+	msleep(350);
+
+	err = aml_dump_fw_version(hdev);
+	if (err)
+		return err;
+
+	err = aml_send_reset(hdev);
+	if (err)
+		return err;
+
+	err = aml_check_bdaddr(hdev);
+	if (err)
+		return err;
+
+	return 0;
+}
+
+static int aml_enqueue(struct hci_uart *hu, struct sk_buff *skb)
+{
+	struct aml_data *aml_data = hu->priv;
+
+	skb_queue_tail(&aml_data->txq, skb);
+
+	return 0;
+}
+
+static struct sk_buff *aml_dequeue(struct hci_uart *hu)
+{
+	struct aml_data *aml_data = hu->priv;
+	struct sk_buff *skb;
+
+	skb = skb_dequeue(&aml_data->txq);
+
+	/* Prepend skb with frame type */
+	if (skb)
+		memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
+
+	return skb;
+}
+
+static int aml_recv(struct hci_uart *hu, const void *data, int count)
+{
+	struct aml_data *aml_data = hu->priv;
+	int err;
+
+	aml_data->rx_skb = h4_recv_buf(hu->hdev, aml_data->rx_skb, data, count,
+				       aml_recv_pkts,
+				       ARRAY_SIZE(aml_recv_pkts));
+	if (IS_ERR(aml_data->rx_skb)) {
+		err = PTR_ERR(aml_data->rx_skb);
+		bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err);
+		aml_data->rx_skb = NULL;
+		return err;
+	}
+
+	return count;
+}
+
+static const struct hci_uart_proto aml_hci_proto = {
+	.id		= HCI_UART_AML,
+	.name		= "AML",
+	.manufacturer	= 50,
+	.init_speed	= 115200,
+	.oper_speed	= 4000000,
+	.open		= aml_open,
+	.close		= aml_close,
+	.setup		= aml_setup,
+	.flush		= aml_flush,
+	.recv		= aml_recv,
+	.enqueue	= aml_enqueue,
+	.dequeue	= aml_dequeue,
+};
+
+static void aml_device_driver_shutdown(struct device *dev)
+{
+	struct aml_serdev *amldev = dev_get_drvdata(dev);
+
+	aml_power_off(amldev);
+}
+
+static int aml_serdev_probe(struct serdev_device *serdev)
+{
+	struct aml_serdev *amldev;
+	int err;
+
+	amldev = devm_kzalloc(&serdev->dev, sizeof(*amldev), GFP_KERNEL);
+	if (!amldev)
+		return -ENOMEM;
+
+	amldev->serdev_hu.serdev = serdev;
+	amldev->dev = &serdev->dev;
+	serdev_device_set_drvdata(serdev, amldev);
+
+	err = hci_uart_register_device(&amldev->serdev_hu, &aml_hci_proto);
+	if (err)
+		return dev_err_probe(amldev->dev, err,
+			      "Failed to register hci uart device");
+
+	amldev->aml_dev_data = device_get_match_data(&serdev->dev);
+
+	return 0;
+}
+
+static void aml_serdev_remove(struct serdev_device *serdev)
+{
+	struct aml_serdev *amldev = serdev_device_get_drvdata(serdev);
+
+	hci_uart_unregister_device(&amldev->serdev_hu);
+}
+
+static const struct aml_device_data data_w155s2 = {
+	.iccm_offset = 256 * 1024,
+};
+
+static const struct aml_device_data data_w265s2 = {
+	.iccm_offset = 384 * 1024,
+};
+
+static const struct of_device_id aml_bluetooth_of_match[] = {
+	{ .compatible = "amlogic,w155s2-bt", .data = &data_w155s2 },
+	{ .compatible = "amlogic,w265s2-bt", .data = &data_w265s2 },
+	{ /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, aml_bluetooth_of_match);
+
+static struct serdev_device_driver aml_serdev_driver = {
+	.probe = aml_serdev_probe,
+	.remove = aml_serdev_remove,
+	.driver = {
+		.name = "hci_uart_aml",
+		.of_match_table = aml_bluetooth_of_match,
+		.shutdown = aml_device_driver_shutdown,
+	},
+};
+
+int __init aml_init(void)
+{
+	serdev_device_driver_register(&aml_serdev_driver);
+
+	return hci_uart_register_proto(&aml_hci_proto);
+}
+
+int __exit aml_deinit(void)
+{
+	serdev_device_driver_unregister(&aml_serdev_driver);
+
+	return hci_uart_unregister_proto(&aml_hci_proto);
+}
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 30192bb08354..d307c41a5470 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -870,7 +870,9 @@ static int __init hci_uart_init(void)
 #ifdef CONFIG_BT_HCIUART_MRVL
 	mrvl_init();
 #endif
-
+#ifdef CONFIG_BT_HCIUART_AML
+	aml_init();
+#endif
 	return 0;
 }
 
@@ -906,7 +908,9 @@ static void __exit hci_uart_exit(void)
 #ifdef CONFIG_BT_HCIUART_MRVL
 	mrvl_deinit();
 #endif
-
+#ifdef CONFIG_BT_HCIUART_AML
+	aml_deinit();
+#endif
 	tty_unregister_ldisc(&hci_uart_ldisc);
 }
 
diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h
index 00bf7ae82c5b..fbf3079b92a5 100644
--- a/drivers/bluetooth/hci_uart.h
+++ b/drivers/bluetooth/hci_uart.h
@@ -20,7 +20,7 @@
 #define HCIUARTGETFLAGS		_IOR('U', 204, int)
 
 /* UART protocols */
-#define HCI_UART_MAX_PROTO	12
+#define HCI_UART_MAX_PROTO	13
 
 #define HCI_UART_H4	0
 #define HCI_UART_BCSP	1
@@ -34,6 +34,7 @@
 #define HCI_UART_AG6XX	9
 #define HCI_UART_NOKIA	10
 #define HCI_UART_MRVL	11
+#define HCI_UART_AML	12
 
 #define HCI_UART_RAW_DEVICE	0
 #define HCI_UART_RESET_ON_INIT	1
@@ -209,3 +210,8 @@ int ag6xx_deinit(void);
 int mrvl_init(void);
 int mrvl_deinit(void);
 #endif
+
+#ifdef CONFIG_BT_HCIUART_AML
+int aml_init(void);
+int aml_deinit(void);
+#endif

-- 
2.42.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 3/3] MAINTAINERS: Add an entry for Amlogic HCI UART (M: Yang Li)
  2024-08-02  9:39 ` Yang Li via B4 Relay
@ 2024-08-02  9:39   ` Yang Li via B4 Relay
  -1 siblings, 0 replies; 19+ messages in thread
From: Yang Li @ 2024-08-02  9:39 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Catalin Marinas, Will Deacon
  Cc: linux-bluetooth, netdev, devicetree, linux-kernel,
	linux-arm-kernel, Yang Li

Add Amlogic Bluetooth entry to MAINTAINERS to clarify the maintainers

Signed-off-by: Yang Li <yang.li@amlogic.com>
---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 0b73a6e2d78c..b106217933b2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1149,6 +1149,13 @@ S:	Supported
 F:	arch/arm64/boot/dts/amd/amd-seattle-xgbe*.dtsi
 F:	drivers/net/ethernet/amd/xgbe/
 
+AMLOGIC BLUETOOTH DRIVER
+M:	Yang Li <yang.li@amlogic.com>
+L:	linux-bluetooth@vger.kernel.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/net/bluetooth/amlogic,w155s2-bt.yaml
+F:	drivers/bluetooth/hci_aml.c
+
 AMLOGIC DDR PMU DRIVER
 M:	Jiucheng Xu <jiucheng.xu@amlogic.com>
 L:	linux-amlogic@lists.infradead.org

-- 
2.42.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 3/3] MAINTAINERS: Add an entry for Amlogic HCI UART (M: Yang Li)
@ 2024-08-02  9:39   ` Yang Li via B4 Relay
  0 siblings, 0 replies; 19+ messages in thread
From: Yang Li via B4 Relay @ 2024-08-02  9:39 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Catalin Marinas, Will Deacon
  Cc: linux-bluetooth, netdev, devicetree, linux-kernel,
	linux-arm-kernel, Yang Li

From: Yang Li <yang.li@amlogic.com>

Add Amlogic Bluetooth entry to MAINTAINERS to clarify the maintainers

Signed-off-by: Yang Li <yang.li@amlogic.com>
---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 0b73a6e2d78c..b106217933b2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1149,6 +1149,13 @@ S:	Supported
 F:	arch/arm64/boot/dts/amd/amd-seattle-xgbe*.dtsi
 F:	drivers/net/ethernet/amd/xgbe/
 
+AMLOGIC BLUETOOTH DRIVER
+M:	Yang Li <yang.li@amlogic.com>
+L:	linux-bluetooth@vger.kernel.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/net/bluetooth/amlogic,w155s2-bt.yaml
+F:	drivers/bluetooth/hci_aml.c
+
 AMLOGIC DDR PMU DRIVER
 M:	Jiucheng Xu <jiucheng.xu@amlogic.com>
 L:	linux-amlogic@lists.infradead.org

-- 
2.42.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* RE: Add support for Amlogic HCI UART
  2024-08-02  9:39   ` Yang Li via B4 Relay
  (?)
@ 2024-08-02 10:36   ` bluez.test.bot
  -1 siblings, 0 replies; 19+ messages in thread
From: bluez.test.bot @ 2024-08-02 10:36 UTC (permalink / raw)
  To: linux-bluetooth, devnull+yang.li.amlogic.com

[-- Attachment #1: Type: text/plain, Size: 3433 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=876189

---Test result---

Test Summary:
CheckPatch                    FAIL      3.83 seconds
GitLint                       PASS      1.01 seconds
SubjectPrefix                 FAIL      0.63 seconds
BuildKernel                   PASS      29.87 seconds
CheckAllWarning               PASS      32.17 seconds
CheckSparse                   PASS      37.72 seconds
CheckSmatch                   PASS      104.87 seconds
BuildKernel32                 PASS      28.88 seconds
TestRunnerSetup               PASS      527.54 seconds
TestRunner_l2cap-tester       PASS      20.20 seconds
TestRunner_iso-tester         PASS      37.42 seconds
TestRunner_bnep-tester        PASS      5.01 seconds
TestRunner_mgmt-tester        PASS      121.51 seconds
TestRunner_rfcomm-tester      PASS      29.14 seconds
TestRunner_sco-tester         PASS      43.15 seconds
TestRunner_ioctl-tester       PASS      7.97 seconds
TestRunner_mesh-tester        PASS      8.22 seconds
TestRunner_smp-tester         PASS      6.98 seconds
TestRunner_userchan-tester    PASS      5.09 seconds
IncrementalBuild              PASS      40.27 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[v3,1/3] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#93: 
new file mode 100644

total: 0 errors, 1 warnings, 62 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13751350.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


[v3,2/3] Bluetooth: hci_uart: Add support for Amlogic HCI UART
WARNING: please write a help paragraph that fully describes the config symbol
#108: FILE: drivers/bluetooth/Kconfig:277:
+config BT_HCIUART_AML
+	bool "Amlogic protocol support"
+	depends on BT_HCIUART
+	depends on BT_HCIUART_SERDEV
+	select BT_HCIUART_H4
+	select FW_LOADER
+	help
+	  The Amlogic protocol support enables Bluetooth HCI over serial
+	  port interface for Amlogic Bluetooth controllers.
+
+	  Say Y here to compile support for HCI AML protocol.
+

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#134: 
new file mode 100644

total: 0 errors, 2 warnings, 822 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13751352.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
Test: SubjectPrefix - FAIL
Desc: Check subject contains "Bluetooth" prefix
Output:
"Bluetooth: " prefix is not specified in the subject
"Bluetooth: " prefix is not specified in the subject


---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 2/3] Bluetooth: hci_uart: Add support for Amlogic HCI UART
  2024-08-02  9:39   ` Yang Li via B4 Relay
  (?)
@ 2024-08-02 11:02   ` Paul Menzel
  2024-08-06  6:27     ` Yang Li
  -1 siblings, 1 reply; 19+ messages in thread
From: Paul Menzel @ 2024-08-02 11:02 UTC (permalink / raw)
  To: Yang Li, Ye He
  Cc: Marcel Holtmann, Luiz Augusto von Dentz, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Catalin Marinas, Will Deacon,
	linux-bluetooth, netdev, devicetree, linux-kernel,
	linux-arm-kernel

Dear Yang,


Thank you for the patch. Some nits and formal things.

Am 02.08.24 um 11:39 schrieb Yang Li via B4 Relay:
> From: Yang Li <yang.li@amlogic.com>
> 
> Add support for Amlogic Bluetooth controller over HCI UART.
> In order to send the final firmware at full speed(4Mbps).

I’d add a space before (. What is the current speed without the patch? 
Maybe also document, what firmware file took how lang.

I’d welcome a more elaborate commit message for a diffstat with almost 
800 lines. What datasheet did you use? Maybe paste the new log messages 
and document your test system.

> Co-developed-by: Ye He <ye.he@amlogic.com>
> Signed-off-by: Ye He <ye.he@amlogic.com>
> Signed-off-by: Yang Li <yang.li@amlogic.com>
> ---
>   drivers/bluetooth/Kconfig     |  12 +
>   drivers/bluetooth/Makefile    |   1 +
>   drivers/bluetooth/hci_aml.c   | 756 ++++++++++++++++++++++++++++++++++++++++++
>   drivers/bluetooth/hci_ldisc.c |   8 +-
>   drivers/bluetooth/hci_uart.h  |   8 +-
>   5 files changed, 782 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
> index 769fa288179d..18767b54df35 100644
> --- a/drivers/bluetooth/Kconfig
> +++ b/drivers/bluetooth/Kconfig
> @@ -274,6 +274,18 @@ config BT_HCIUART_MRVL
>   
>   	  Say Y here to compile support for HCI MRVL protocol.
>   
> +config BT_HCIUART_AML
> +	bool "Amlogic protocol support"
> +	depends on BT_HCIUART
> +	depends on BT_HCIUART_SERDEV
> +	select BT_HCIUART_H4
> +	select FW_LOADER
> +	help
> +	  The Amlogic protocol support enables Bluetooth HCI over serial
> +	  port interface for Amlogic Bluetooth controllers.
> +
> +	  Say Y here to compile support for HCI AML protocol.
> +
>   config BT_HCIBCM203X
>   	tristate "HCI BCM203x USB driver"
>   	depends on USB
> diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
> index 0730d6684d1a..81856512ddd0 100644
> --- a/drivers/bluetooth/Makefile
> +++ b/drivers/bluetooth/Makefile
> @@ -51,4 +51,5 @@ hci_uart-$(CONFIG_BT_HCIUART_BCM)	+= hci_bcm.o
>   hci_uart-$(CONFIG_BT_HCIUART_QCA)	+= hci_qca.o
>   hci_uart-$(CONFIG_BT_HCIUART_AG6XX)	+= hci_ag6xx.o
>   hci_uart-$(CONFIG_BT_HCIUART_MRVL)	+= hci_mrvl.o
> +hci_uart-$(CONFIG_BT_HCIUART_AML)	+= hci_aml.o
>   hci_uart-objs				:= $(hci_uart-y)
> diff --git a/drivers/bluetooth/hci_aml.c b/drivers/bluetooth/hci_aml.c
> new file mode 100644
> index 000000000000..cc6627788611
> --- /dev/null
> +++ b/drivers/bluetooth/hci_aml.c
> @@ -0,0 +1,756 @@
> +// SPDX-License-Identifier: (GPL-2.0-only OR MIT)
> +/*
> + * Copyright (C) 2024 Amlogic, Inc. All rights reserved
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/delay.h>
> +#include <linux/device.h>
> +#include <linux/property.h>
> +#include <linux/of.h>
> +#include <linux/serdev.h>
> +#include <linux/clk.h>
> +#include <linux/firmware.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/regulator/consumer.h>
> +#include <net/bluetooth/bluetooth.h>
> +#include <net/bluetooth/hci_core.h>
> +#include <net/bluetooth/hci.h>
> +
> +#include "hci_uart.h"

[…]

> +/* The TCI command is private command, which is used to configure before BT

Used to configure what? Maybe:

… is *a* private, executed(?) before BT chip startup …

> + * chip startup, contains update baudrate, update firmware, set public addr.

s/, contains/ to/

> + *
> + * op_code |      op_len           | op_addr | parameter   |
> + * --------|-----------------------|---------|-------------|
> + *   2B    | 1B len(addr+param)    |    4B   |  len(param) |
> + */
> +static int aml_send_tci_cmd(struct hci_dev *hdev, u16 op_code, u32 op_addr,
> +			    u32 *param, u32 param_len)
> +{
> +	struct aml_tci_rsp *rsp = NULL;
> +	struct sk_buff *skb = NULL;
> +	u32 buf_len = 0;

size_t?

> +	u8 *buf = NULL;
> +	int err = 0;
> +
> +	buf_len = sizeof(op_addr) + param_len;
> +	buf = kmalloc(buf_len, GFP_KERNEL);
> +	if (!buf)
> +		return -ENOMEM;
> +
> +	memcpy(buf, &op_addr, sizeof(op_addr));
> +	if (param && param_len > 0)
> +		memcpy(buf + sizeof(op_addr), param, param_len);
> +
> +	skb = __hci_cmd_sync_ev(hdev, op_code, buf_len, buf,
> +				HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
> +	if (IS_ERR(skb)) {
> +		err = PTR_ERR(skb);
> +		bt_dev_err(hdev, "Failed to send TCI cmd:(%d)", err);
> +		goto exit;
> +	}
> +
> +	rsp = skb_pull_data(skb, sizeof(struct aml_tci_rsp));
> +	if (!rsp)
> +		goto skb_free;
> +
> +	if (rsp->opcode != op_code || rsp->status != 0x00) {
> +		bt_dev_err(hdev, "send TCI cmd(0x%04X), response(0x%04X):(%d)",
> +		       op_code, rsp->opcode, rsp->status);
> +		err = -EINVAL;
> +		goto skb_free;
> +	}
> +
> +skb_free:
> +	kfree_skb(skb);
> +
> +exit:
> +	kfree(buf);
> +	return err;
> +}
> +
> +static int aml_update_chip_baudrate(struct hci_dev *hdev, u32 baud)
> +{
> +	u32 value;
> +
> +	value = ((AML_UART_CLK_SOURCE / baud) - 1) & 0x0FFF;
> +	value |= AML_UART_XMIT_EN | AML_UART_RECV_EN | AML_UART_TIMEOUT_INT_EN;
> +
> +	return aml_send_tci_cmd(hdev, AML_TCI_CMD_UPDATE_BAUDRATE,
> +				  AML_OP_UART_MODE, &value, sizeof(value));
> +}
> +
> +static int aml_start_chip(struct hci_dev *hdev)
> +{
> +	u32 value = 0;
> +	int ret;
> +
> +	value = AML_MM_CTR_HARD_TRAS_EN;
> +	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
> +			       AML_OP_MEM_HARD_TRANS_EN,
> +			       &value, sizeof(value));
> +	if (ret)
> +		return ret;
> +
> +	/* controller hardware reset. */
> +	value = AML_CTR_CPU_RESET | AML_CTR_MAC_RESET | AML_CTR_PHY_RESET;
> +	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_HARDWARE_RESET,
> +			       AML_OP_HARDWARE_RST,
> +			       &value, sizeof(value));
> +	return ret;
> +}
> +
> +static int aml_send_firmware_segment(struct hci_dev *hdev,
> +				     u8 fw_type,
> +				     u8 *seg,
> +				     u32 seg_size,
> +				     u32 offset)
> +{
> +	u32 op_addr = 0;
> +
> +	if (fw_type == FW_ICCM)
> +		op_addr = AML_OP_ICCM_RAM_BASE  + offset;
> +	else if (fw_type == FW_DCCM)
> +		op_addr = AML_OP_DCCM_RAM_BASE + offset;
> +
> +	return aml_send_tci_cmd(hdev, AML_TCI_CMD_DOWNLOAD_BT_FW,
> +			     op_addr, (u32 *)seg, seg_size);
> +}
> +
> +static int aml_send_firmware(struct hci_dev *hdev, u8 fw_type,
> +			     u8 *fw, u32 fw_size, u32 offset)
> +{
> +	u32 seg_size = 0;
> +	u32 seg_off = 0;
> +
> +	if (fw_size > AML_FIRMWARE_MAX_SIZE) {
> +		bt_dev_err(hdev, "fw_size error, fw_size:%d, max_size: 512K",

I’d add a space after the colon. Maybe more presize:

Firmware size %d kB is larger than the maximum of 512 kB. Aborting.

> +		       fw_size);
> +		return -EINVAL;
> +	}
> +	while (fw_size > 0) {
> +		seg_size = (fw_size > AML_FIRMWARE_OPERATION_SIZE) ?
> +			   AML_FIRMWARE_OPERATION_SIZE : fw_size;
> +		if (aml_send_firmware_segment(hdev, fw_type, (fw + seg_off),
> +					      seg_size, offset)) {
> +			bt_dev_err(hdev, "Failed send firmware, type:%d, offset:0x%x",

I’d add spaces after the colons.

> +			       fw_type, offset);
> +			return -EINVAL;
> +		}
> +		seg_off += seg_size;
> +		fw_size -= seg_size;
> +		offset += seg_size;
> +	}
> +	return 0;
> +}
> +
> +static int aml_download_firmware(struct hci_dev *hdev, const char *fw_name)
> +{
> +	struct hci_uart *hu = hci_get_drvdata(hdev);
> +	struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
> +	const struct firmware *firmware = NULL;
> +	struct aml_fw_len *fw_len = NULL;
> +	u8 *iccm_start = NULL, *dccm_start = NULL;
> +	u32 iccm_len, dccm_len;
> +	u32 value = 0;
> +	int ret = 0;
> +
> +	/* Enable firmware download event. */
> +	value = AML_EVT_EN;
> +	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
> +			       AML_OP_EVT_ENABLE,
> +			       &value, sizeof(value));
> +	if (ret)
> +		goto exit;
> +
> +	/* RAM power on */
> +	value = AML_RAM_POWER_ON;
> +	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
> +			       AML_OP_RAM_POWER_CTR,
> +			       &value, sizeof(value));
> +	if (ret)
> +		goto exit;
> +
> +	/* Check RAM power status */
> +	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_READ,
> +			       AML_OP_RAM_POWER_CTR, NULL, 0);
> +	if (ret)
> +		goto exit;
> +
> +	ret = request_firmware(&firmware, fw_name, &hdev->dev);
> +	if (ret < 0) {
> +		bt_dev_err(hdev, "Failed to load <%s>:(%d)", fw_name, ret);
> +		goto exit;
> +	}
> +
> +	fw_len = (struct aml_fw_len *)firmware->data;
> +
> +	/* Download ICCM */
> +	iccm_start = (u8 *)(firmware->data) + sizeof(struct aml_fw_len)
> +			+ amldev->aml_dev_data->iccm_offset;
> +	iccm_len = fw_len->iccm_len - amldev->aml_dev_data->iccm_offset;
> +	ret = aml_send_firmware(hdev, FW_ICCM, iccm_start, iccm_len,
> +				amldev->aml_dev_data->iccm_offset);
> +	if (ret) {
> +		bt_dev_err(hdev, "Failed to send FW_ICCM (%d)", ret);
> +		goto exit;
> +	}
> +
> +	/* Download DCCM */
> +	dccm_start = (u8 *)(firmware->data) + sizeof(struct aml_fw_len) + fw_len->iccm_len;
> +	dccm_len = fw_len->dccm_len;
> +	ret = aml_send_firmware(hdev, FW_DCCM, dccm_start, dccm_len,
> +				amldev->aml_dev_data->dccm_offset);
> +	if (ret) {
> +		bt_dev_err(hdev, "Failed to send FW_DCCM (%d)", ret);
> +		goto exit;
> +	}
> +
> +	/* Disable firmware download event. */

I’d remove the dot and the end.

> +	value = 0;
> +	ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
> +			       AML_OP_EVT_ENABLE,
> +			       &value, sizeof(value));
> +	if (ret)
> +		goto exit;
> +
> +exit:
> +	if (firmware)
> +		release_firmware(firmware);
> +	return ret;
> +}
> +
> +static int aml_send_reset(struct hci_dev *hdev)
> +{
> +	struct sk_buff *skb;
> +	int err;
> +
> +	skb = __hci_cmd_sync_ev(hdev, HCI_OP_RESET, 0, NULL,
> +				HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
> +	if (IS_ERR(skb)) {
> +		err = PTR_ERR(skb);
> +		bt_dev_err(hdev, "Failed to send hci reset cmd(%d)", err);
> +		return err;
> +	}
> +
> +	kfree_skb(skb);
> +	return 0;
> +}
> +
> +static int aml_dump_fw_version(struct hci_dev *hdev)
> +{
> +	struct aml_tci_rsp *rsp = NULL;
> +	struct sk_buff *skb;
> +	u8 value[6] = {0};
> +	u8 *fw_ver = NULL;
> +	int err = 0;
> +
> +	skb = __hci_cmd_sync_ev(hdev, AML_BT_HCI_VENDOR_CMD, sizeof(value), value,
> +				HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
> +	if (IS_ERR(skb)) {
> +		err = PTR_ERR(skb);
> +		bt_dev_err(hdev, "Failed get fw version:(%d)", err);

1.  Failed *to* get …
2.  I’d add a space after the colon, but would remove the colon, and 
maybe do:

         Failed to get fw version (error: %d)

> +		return err;
> +	}
> +
> +	rsp = skb_pull_data(skb, sizeof(struct aml_tci_rsp));
> +	if (!rsp)
> +		goto exit;
> +
> +	if (rsp->opcode != AML_BT_HCI_VENDOR_CMD || rsp->status != 0x00) {
> +		bt_dev_err(hdev, "dump version, error response (0x%04X):(%d)",
> +		       rsp->opcode, rsp->status);
> +		err = -EINVAL;
> +		goto exit;
> +	}
> +
> +	fw_ver = (u8 *)rsp + AML_EVT_HEAD_SIZE;
> +	bt_dev_info(hdev, "fw_version: date = %02x.%02x, number = 0x%02x%02x",
> +		*(fw_ver + 1), *fw_ver, *(fw_ver + 3), *(fw_ver + 2));
> +
> +exit:
> +	kfree_skb(skb);
> +	return err;
> +}
> +
> +static int aml_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
> +{
> +	struct aml_tci_rsp *rsp = NULL;
> +	struct sk_buff *skb;
> +	int err = 0;
> +
> +	bt_dev_info(hdev, "set bdaddr (%pM)", bdaddr);
> +	skb = __hci_cmd_sync_ev(hdev, AML_BT_HCI_VENDOR_CMD,
> +				sizeof(bdaddr_t), bdaddr,
> +				HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
> +	if (IS_ERR(skb)) {
> +		err = PTR_ERR(skb);
> +		bt_dev_err(hdev, "Failed to set bdaddr:(%d)", err);
> +		return err;
> +	}
> +
> +	rsp = skb_pull_data(skb, sizeof(struct aml_tci_rsp));
> +	if (!rsp)
> +		goto exit;
> +
> +	if (rsp->opcode != AML_BT_HCI_VENDOR_CMD || rsp->status != 0x00) {
> +		bt_dev_err(hdev, "error response (0x%x):(%d)", rsp->opcode, rsp->status);
> +		err = -EINVAL;
> +		goto exit;
> +	}
> +
> +exit:
> +	kfree_skb(skb);
> +	return err;
> +}
> +
> +static int aml_check_bdaddr(struct hci_dev *hdev)
> +{
> +	struct hci_rp_read_bd_addr *paddr;
> +	struct sk_buff *skb;
> +	int err;
> +
> +	if (bacmp(&hdev->public_addr, BDADDR_ANY))
> +		return 0;
> +
> +	skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
> +			     HCI_INIT_TIMEOUT);
> +	if (IS_ERR(skb)) {
> +		err = PTR_ERR(skb);
> +		bt_dev_err(hdev, "Failed to read bdaddr:(%d)", err);
> +		return err;
> +	}
> +
> +	paddr = skb_pull_data(skb, sizeof(struct hci_rp_read_bd_addr));
> +	if (!paddr)
> +		goto exit;
> +
> +	if (!bacmp(&paddr->bdaddr, AML_BDADDR_DEFAULT)) {
> +		bt_dev_info(hdev, "amlbt using default bdaddr (%pM)", &paddr->bdaddr);
> +		set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
> +	}
> +
> +exit:
> +	kfree_skb(skb);
> +	return 0;
> +}
> +
> +static int aml_config_rf(struct hci_dev *hdev, bool is_coex)
> +{
> +	u32 value = AML_RF_ANT_DOUBLE;
> +
> +	/* Use a single antenna when co-existing with wifi. */
> +	if (is_coex)
> +		value = AML_RF_ANT_SINGLE;
> +
> +	return aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
> +				AML_OP_RF_CFG,
> +				&value, sizeof(value));
> +}
> +
> +static int aml_parse_dt(struct aml_serdev *amldev)
> +{
> +	struct device *pdev = amldev->dev;
> +
> +	amldev->bt_en_gpio = devm_gpiod_get(pdev, "enable",
> +					GPIOD_OUT_LOW);
> +	if (IS_ERR(amldev->bt_en_gpio)) {
> +		dev_err(pdev, "Failed to acquire enable gpios");
> +		return PTR_ERR(amldev->bt_en_gpio);
> +	}
> +
> +	if (device_property_read_string(pdev, "firmware-name",
> +					&amldev->firmware_name)) {
> +		dev_err(pdev, "Failed to acquire firmware path");
> +		return -ENODEV;
> +	}
> +
> +	amldev->bt_supply = devm_regulator_get(pdev, "vddio");
> +	if (IS_ERR(amldev->bt_supply)) {
> +		dev_err(pdev, "Failed to acquire regulator");
> +		return PTR_ERR(amldev->bt_supply);
> +	}
> +
> +	amldev->lpo_clk = devm_clk_get(pdev, NULL);
> +	if (IS_ERR(amldev->lpo_clk)) {
> +		dev_err(pdev, "Failed to acquire clock source");
> +		return PTR_ERR(amldev->lpo_clk);
> +	}
> +
> +	return 0;
> +}
> +
> +static int aml_power_on(struct aml_serdev *amldev)
> +{
> +	int err;
> +
> +	err = regulator_enable(amldev->bt_supply);
> +	if (err) {
> +		dev_err(amldev->dev, "Failed to enable regulator: (%d)", err);
> +		return err;
> +	}
> +
> +	err = clk_prepare_enable(amldev->lpo_clk);
> +	if (err) {
> +		dev_err(amldev->dev, "Failed to enable lpo clock: (%d)", err);
> +		return err;
> +	}
> +
> +	gpiod_set_value_cansleep(amldev->bt_en_gpio, 1);
> +
> +	/* wait 100ms for bluetooth controller power on  */
> +	msleep(100);
> +	return 0;
> +}
> +
> +static int aml_power_off(struct aml_serdev *amldev)
> +{
> +	gpiod_set_value_cansleep(amldev->bt_en_gpio, 0);
> +
> +	clk_disable_unprepare(amldev->lpo_clk);
> +
> +	regulator_disable(amldev->bt_supply);
> +
> +	return 0;
> +}
> +
> +static int aml_set_baudrate(struct hci_uart *hu, unsigned int speed)
> +{
> +	/* update controller baudrate*/
> +	if (aml_update_chip_baudrate(hu->hdev, speed) != 0) {
> +		bt_dev_err(hu->hdev, "Failed to update baud rate");
> +		return -EINVAL;
> +	}
> +
> +	/* update local baudrate*/
> +	serdev_device_set_baudrate(hu->serdev, speed);
> +
> +	return 0;
> +}
> +
> +/* Initialize protocol */
> +static int aml_open(struct hci_uart *hu)
> +{
> +	struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
> +	struct aml_data *aml_data;
> +	int err;
> +
> +	err = aml_parse_dt(amldev);
> +	if (err)
> +		return err;
> +
> +	if (!hci_uart_has_flow_control(hu)) {
> +		bt_dev_err(hu->hdev, "no flow control");
> +		return -EOPNOTSUPP;
> +	}
> +
> +	aml_data = kzalloc(sizeof(*aml_data), GFP_KERNEL);
> +	if (!aml_data)
> +		return -ENOMEM;
> +
> +	skb_queue_head_init(&aml_data->txq);
> +
> +	hu->priv = aml_data;
> +
> +	return 0;
> +}
> +
> +static int aml_close(struct hci_uart *hu)
> +{
> +	struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
> +	struct aml_data *aml_data = hu->priv;
> +
> +	if (hu->serdev)
> +		serdev_device_close(hu->serdev);
> +
> +	skb_queue_purge(&aml_data->txq);
> +	kfree_skb(aml_data->rx_skb);
> +	kfree(aml_data);
> +
> +	hu->priv = NULL;
> +
> +	return aml_power_off(amldev);
> +}
> +
> +static int aml_flush(struct hci_uart *hu)
> +{
> +	struct aml_data *aml_data = hu->priv;
> +
> +	skb_queue_purge(&aml_data->txq);
> +
> +	return 0;
> +}
> +
> +static int aml_setup(struct hci_uart *hu)
> +{
> +	struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
> +	struct hci_dev *hdev = amldev->serdev_hu.hdev;
> +	int err;
> +
> +	/* Setup bdaddr */
> +	hdev->set_bdaddr = aml_set_bdaddr;
> +
> +	err = aml_power_on(amldev);
> +	if (err)
> +		return err;
> +
> +	err = aml_set_baudrate(hu, amldev->serdev_hu.proto->oper_speed);
> +	if (err)
> +		return err;
> +
> +	err = aml_download_firmware(hdev, amldev->firmware_name);
> +	if (err)
> +		return err;
> +
> +	err = aml_config_rf(hdev, amldev->aml_dev_data->is_coex);
> +	if (err)
> +		return err;
> +
> +	err = aml_start_chip(hdev);
> +	if (err)
> +		return err;
> +
> +	/* wait 350ms for controller start up*/

Missing space at the end.

Also, why 350 ms? That is pretty long.

> +	msleep(350);
> +
> +	err = aml_dump_fw_version(hdev);
> +	if (err)
> +		return err;
> +
> +	err = aml_send_reset(hdev);
> +	if (err)
> +		return err;
> +
> +	err = aml_check_bdaddr(hdev);
> +	if (err)
> +		return err;
> +
> +	return 0;
> +}

[…]


Kind regards,

Paul

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 1/3] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth
  2024-08-02  9:39   ` Yang Li via B4 Relay
  (?)
  (?)
@ 2024-08-05 17:27   ` Krzysztof Kozlowski
  2024-08-06  6:54     ` Yang Li
  -1 siblings, 1 reply; 19+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-05 17:27 UTC (permalink / raw)
  To: yang.li, Marcel Holtmann, Luiz Augusto von Dentz, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Catalin Marinas, Will Deacon
  Cc: linux-bluetooth, netdev, devicetree, linux-kernel,
	linux-arm-kernel

On 02/08/2024 11:39, Yang Li via B4 Relay wrote:
> From: Yang Li <yang.li@amlogic.com>
> 
> Add binding document for Amlogic Bluetooth chipsets attached over UART.
> 
> Signed-off-by: Yang Li <yang.li@amlogic.com>


> +  firmware-name:
> +    maxItems: 1
> +    description: specify the path of firmware bin to load
> +
> +required:
> +  - compatible
> +  - enable-gpios
> +  - vddio-supply
> +  - clocks
> +  - firmware-name

Keep the same order as listed in properties section. With this fixed:

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 2/3] Bluetooth: hci_uart: Add support for Amlogic HCI UART
  2024-08-02  9:39   ` Yang Li via B4 Relay
  (?)
  (?)
@ 2024-08-05 17:29   ` Krzysztof Kozlowski
  2024-08-06  8:33     ` Yang Li
  -1 siblings, 1 reply; 19+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-05 17:29 UTC (permalink / raw)
  To: yang.li, Marcel Holtmann, Luiz Augusto von Dentz, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Catalin Marinas, Will Deacon
  Cc: linux-bluetooth, netdev, devicetree, linux-kernel,
	linux-arm-kernel, Ye He

On 02/08/2024 11:39, Yang Li via B4 Relay wrote:
> From: Yang Li <yang.li@amlogic.com>
> 

...

> +
> +static const struct aml_device_data data_w155s2 = {
> +	.iccm_offset = 256 * 1024,
> +};
> +
> +static const struct aml_device_data data_w265s2 = {
> +	.iccm_offset = 384 * 1024,
> +};
> +
> +static const struct of_device_id aml_bluetooth_of_match[] = {
> +	{ .compatible = "amlogic,w155s2-bt", .data = &data_w155s2 },
> +	{ .compatible = "amlogic,w265s2-bt", .data = &data_w265s2 },

Your binding says these devices are compatible, but above suggests it is
not. Confusing.

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 2/3] Bluetooth: hci_uart: Add support for Amlogic HCI UART
  2024-08-02 11:02   ` Paul Menzel
@ 2024-08-06  6:27     ` Yang Li
  0 siblings, 0 replies; 19+ messages in thread
From: Yang Li @ 2024-08-06  6:27 UTC (permalink / raw)
  To: Paul Menzel, Ye He
  Cc: Marcel Holtmann, Luiz Augusto von Dentz, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Catalin Marinas, Will Deacon,
	linux-bluetooth, netdev, devicetree, linux-kernel,
	linux-arm-kernel

Dear Paul

Thank you for the review.

On 2024/8/2 19:02, Paul Menzel wrote:
>
> Dear Yang,
>
>
> Thank you for the patch. Some nits and formal things.
>
> Am 02.08.24 um 11:39 schrieb Yang Li via B4 Relay:
>> From: Yang Li <yang.li@amlogic.com>
>>
>> Add support for Amlogic Bluetooth controller over HCI UART.
>> In order to send the final firmware at full speed(4Mbps).
>
> I’d add a space before (. What is the current speed without the patch?
> Maybe also document, what firmware file took how lang.
>
> I’d welcome a more elaborate commit message for a diffstat with almost
> 800 lines. What datasheet did you use? Maybe paste the new log messages
> and document your test system.
>
Well, I will provide additional details in the next version.
>> Co-developed-by: Ye He <ye.he@amlogic.com>
>> Signed-off-by: Ye He <ye.he@amlogic.com>
>> Signed-off-by: Yang Li <yang.li@amlogic.com>
>> ---
>>   drivers/bluetooth/Kconfig     |  12 +
>>   drivers/bluetooth/Makefile    |   1 +
>>   drivers/bluetooth/hci_aml.c   | 756 
>> ++++++++++++++++++++++++++++++++++++++++++
>>   drivers/bluetooth/hci_ldisc.c |   8 +-
>>   drivers/bluetooth/hci_uart.h  |   8 +-
>>   5 files changed, 782 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
>> index 769fa288179d..18767b54df35 100644
>> --- a/drivers/bluetooth/Kconfig
>> +++ b/drivers/bluetooth/Kconfig
>> @@ -274,6 +274,18 @@ config BT_HCIUART_MRVL
>>
>>         Say Y here to compile support for HCI MRVL protocol.
>>
>> +config BT_HCIUART_AML
>> +     bool "Amlogic protocol support"
>> +     depends on BT_HCIUART
>> +     depends on BT_HCIUART_SERDEV
>> +     select BT_HCIUART_H4
>> +     select FW_LOADER
>> +     help
>> +       The Amlogic protocol support enables Bluetooth HCI over serial
>> +       port interface for Amlogic Bluetooth controllers.
>> +
>> +       Say Y here to compile support for HCI AML protocol.
>> +
>>   config BT_HCIBCM203X
>>       tristate "HCI BCM203x USB driver"
>>       depends on USB
>> diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
>> index 0730d6684d1a..81856512ddd0 100644
>> --- a/drivers/bluetooth/Makefile
>> +++ b/drivers/bluetooth/Makefile
>> @@ -51,4 +51,5 @@ hci_uart-$(CONFIG_BT_HCIUART_BCM)   += hci_bcm.o
>>   hci_uart-$(CONFIG_BT_HCIUART_QCA)   += hci_qca.o
>>   hci_uart-$(CONFIG_BT_HCIUART_AG6XX) += hci_ag6xx.o
>>   hci_uart-$(CONFIG_BT_HCIUART_MRVL)  += hci_mrvl.o
>> +hci_uart-$(CONFIG_BT_HCIUART_AML)    += hci_aml.o
>>   hci_uart-objs                               := $(hci_uart-y)
>> diff --git a/drivers/bluetooth/hci_aml.c b/drivers/bluetooth/hci_aml.c
>> new file mode 100644
>> index 000000000000..cc6627788611
>> --- /dev/null
>> +++ b/drivers/bluetooth/hci_aml.c
>> @@ -0,0 +1,756 @@
>> +// SPDX-License-Identifier: (GPL-2.0-only OR MIT)
>> +/*
>> + * Copyright (C) 2024 Amlogic, Inc. All rights reserved
>> + */
>> +
>> +#include <linux/kernel.h>
>> +#include <linux/delay.h>
>> +#include <linux/device.h>
>> +#include <linux/property.h>
>> +#include <linux/of.h>
>> +#include <linux/serdev.h>
>> +#include <linux/clk.h>
>> +#include <linux/firmware.h>
>> +#include <linux/gpio/consumer.h>
>> +#include <linux/regulator/consumer.h>
>> +#include <net/bluetooth/bluetooth.h>
>> +#include <net/bluetooth/hci_core.h>
>> +#include <net/bluetooth/hci.h>
>> +
>> +#include "hci_uart.h"
>
> […]
>
>> +/* The TCI command is private command, which is used to configure 
>> before BT
>
> Used to configure what? Maybe:
>
> … is *a* private, executed(?) before BT chip startup …
>
>> + * chip startup, contains update baudrate, update firmware, set 
>> public addr.
>
> s/, contains/ to/
>
Okay, I got it.
>> + *
>> + * op_code |      op_len           | op_addr | parameter   |
>> + * --------|-----------------------|---------|-------------|
>> + *   2B    | 1B len(addr+param)    |    4B   |  len(param) |
>> + */
>> +static int aml_send_tci_cmd(struct hci_dev *hdev, u16 op_code, u32 
>> op_addr,
>> +                         u32 *param, u32 param_len)
>> +{
>> +     struct aml_tci_rsp *rsp = NULL;
>> +     struct sk_buff *skb = NULL;
>> +     u32 buf_len = 0;
>
> size_t?
Will do.
>
>> +     u8 *buf = NULL;
>> +     int err = 0;
>> +
>> +     buf_len = sizeof(op_addr) + param_len;
>> +     buf = kmalloc(buf_len, GFP_KERNEL);
>> +     if (!buf)
>> +             return -ENOMEM;
>> +
>> +     memcpy(buf, &op_addr, sizeof(op_addr));
>> +     if (param && param_len > 0)
>> +             memcpy(buf + sizeof(op_addr), param, param_len);
>> +
>> +     skb = __hci_cmd_sync_ev(hdev, op_code, buf_len, buf,
>> +                             HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
>> +     if (IS_ERR(skb)) {
>> +             err = PTR_ERR(skb);
>> +             bt_dev_err(hdev, "Failed to send TCI cmd:(%d)", err);
>> +             goto exit;
>> +     }
>> +
>> +     rsp = skb_pull_data(skb, sizeof(struct aml_tci_rsp));
>> +     if (!rsp)
>> +             goto skb_free;
>> +
>> +     if (rsp->opcode != op_code || rsp->status != 0x00) {
>> +             bt_dev_err(hdev, "send TCI cmd(0x%04X), 
>> response(0x%04X):(%d)",
>> +                    op_code, rsp->opcode, rsp->status);
>> +             err = -EINVAL;
>> +             goto skb_free;
>> +     }
>> +
>> +skb_free:
>> +     kfree_skb(skb);
>> +
>> +exit:
>> +     kfree(buf);
>> +     return err;
>> +}
>> +
>> +static int aml_update_chip_baudrate(struct hci_dev *hdev, u32 baud)
>> +{
>> +     u32 value;
>> +
>> +     value = ((AML_UART_CLK_SOURCE / baud) - 1) & 0x0FFF;
>> +     value |= AML_UART_XMIT_EN | AML_UART_RECV_EN | 
>> AML_UART_TIMEOUT_INT_EN;
>> +
>> +     return aml_send_tci_cmd(hdev, AML_TCI_CMD_UPDATE_BAUDRATE,
>> +                               AML_OP_UART_MODE, &value, 
>> sizeof(value));
>> +}
>> +
>> +static int aml_start_chip(struct hci_dev *hdev)
>> +{
>> +     u32 value = 0;
>> +     int ret;
>> +
>> +     value = AML_MM_CTR_HARD_TRAS_EN;
>> +     ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
>> +                            AML_OP_MEM_HARD_TRANS_EN,
>> +                            &value, sizeof(value));
>> +     if (ret)
>> +             return ret;
>> +
>> +     /* controller hardware reset. */
>> +     value = AML_CTR_CPU_RESET | AML_CTR_MAC_RESET | AML_CTR_PHY_RESET;
>> +     ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_HARDWARE_RESET,
>> +                            AML_OP_HARDWARE_RST,
>> +                            &value, sizeof(value));
>> +     return ret;
>> +}
>> +
>> +static int aml_send_firmware_segment(struct hci_dev *hdev,
>> +                                  u8 fw_type,
>> +                                  u8 *seg,
>> +                                  u32 seg_size,
>> +                                  u32 offset)
>> +{
>> +     u32 op_addr = 0;
>> +
>> +     if (fw_type == FW_ICCM)
>> +             op_addr = AML_OP_ICCM_RAM_BASE  + offset;
>> +     else if (fw_type == FW_DCCM)
>> +             op_addr = AML_OP_DCCM_RAM_BASE + offset;
>> +
>> +     return aml_send_tci_cmd(hdev, AML_TCI_CMD_DOWNLOAD_BT_FW,
>> +                          op_addr, (u32 *)seg, seg_size);
>> +}
>> +
>> +static int aml_send_firmware(struct hci_dev *hdev, u8 fw_type,
>> +                          u8 *fw, u32 fw_size, u32 offset)
>> +{
>> +     u32 seg_size = 0;
>> +     u32 seg_off = 0;
>> +
>> +     if (fw_size > AML_FIRMWARE_MAX_SIZE) {
>> +             bt_dev_err(hdev, "fw_size error, fw_size:%d, max_size: 
>> 512K",
>
> I’d add a space after the colon. Maybe more presize:
>
> Firmware size %d kB is larger than the maximum of 512 kB. Aborting.
>
I will do.
>> +                    fw_size);
>> +             return -EINVAL;
>> +     }
>> +     while (fw_size > 0) {
>> +             seg_size = (fw_size > AML_FIRMWARE_OPERATION_SIZE) ?
>> +                        AML_FIRMWARE_OPERATION_SIZE : fw_size;
>> +             if (aml_send_firmware_segment(hdev, fw_type, (fw + 
>> seg_off),
>> +                                           seg_size, offset)) {
>> +                     bt_dev_err(hdev, "Failed send firmware, 
>> type:%d, offset:0x%x",
>
> I’d add spaces after the colons.
>
I will do.
>> +                            fw_type, offset);
>> +                     return -EINVAL;
>> +             }
>> +             seg_off += seg_size;
>> +             fw_size -= seg_size;
>> +             offset += seg_size;
>> +     }
>> +     return 0;
>> +}
>> +
>> +static int aml_download_firmware(struct hci_dev *hdev, const char 
>> *fw_name)
>> +{
>> +     struct hci_uart *hu = hci_get_drvdata(hdev);
>> +     struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
>> +     const struct firmware *firmware = NULL;
>> +     struct aml_fw_len *fw_len = NULL;
>> +     u8 *iccm_start = NULL, *dccm_start = NULL;
>> +     u32 iccm_len, dccm_len;
>> +     u32 value = 0;
>> +     int ret = 0;
>> +
>> +     /* Enable firmware download event. */
>> +     value = AML_EVT_EN;
>> +     ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
>> +                            AML_OP_EVT_ENABLE,
>> +                            &value, sizeof(value));
>> +     if (ret)
>> +             goto exit;
>> +
>> +     /* RAM power on */
>> +     value = AML_RAM_POWER_ON;
>> +     ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
>> +                            AML_OP_RAM_POWER_CTR,
>> +                            &value, sizeof(value));
>> +     if (ret)
>> +             goto exit;
>> +
>> +     /* Check RAM power status */
>> +     ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_READ,
>> +                            AML_OP_RAM_POWER_CTR, NULL, 0);
>> +     if (ret)
>> +             goto exit;
>> +
>> +     ret = request_firmware(&firmware, fw_name, &hdev->dev);
>> +     if (ret < 0) {
>> +             bt_dev_err(hdev, "Failed to load <%s>:(%d)", fw_name, 
>> ret);
>> +             goto exit;
>> +     }
>> +
>> +     fw_len = (struct aml_fw_len *)firmware->data;
>> +
>> +     /* Download ICCM */
>> +     iccm_start = (u8 *)(firmware->data) + sizeof(struct aml_fw_len)
>> +                     + amldev->aml_dev_data->iccm_offset;
>> +     iccm_len = fw_len->iccm_len - amldev->aml_dev_data->iccm_offset;
>> +     ret = aml_send_firmware(hdev, FW_ICCM, iccm_start, iccm_len,
>> + amldev->aml_dev_data->iccm_offset);
>> +     if (ret) {
>> +             bt_dev_err(hdev, "Failed to send FW_ICCM (%d)", ret);
>> +             goto exit;
>> +     }
>> +
>> +     /* Download DCCM */
>> +     dccm_start = (u8 *)(firmware->data) + sizeof(struct aml_fw_len) 
>> + fw_len->iccm_len;
>> +     dccm_len = fw_len->dccm_len;
>> +     ret = aml_send_firmware(hdev, FW_DCCM, dccm_start, dccm_len,
>> + amldev->aml_dev_data->dccm_offset);
>> +     if (ret) {
>> +             bt_dev_err(hdev, "Failed to send FW_DCCM (%d)", ret);
>> +             goto exit;
>> +     }
>> +
>> +     /* Disable firmware download event. */
>
> I’d remove the dot and the end.
>
I will do.
>> +     value = 0;
>> +     ret = aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
>> +                            AML_OP_EVT_ENABLE,
>> +                            &value, sizeof(value));
>> +     if (ret)
>> +             goto exit;
>> +
>> +exit:
>> +     if (firmware)
>> +             release_firmware(firmware);
>> +     return ret;
>> +}
>> +
>> +static int aml_send_reset(struct hci_dev *hdev)
>> +{
>> +     struct sk_buff *skb;
>> +     int err;
>> +
>> +     skb = __hci_cmd_sync_ev(hdev, HCI_OP_RESET, 0, NULL,
>> +                             HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
>> +     if (IS_ERR(skb)) {
>> +             err = PTR_ERR(skb);
>> +             bt_dev_err(hdev, "Failed to send hci reset cmd(%d)", err);
>> +             return err;
>> +     }
>> +
>> +     kfree_skb(skb);
>> +     return 0;
>> +}
>> +
>> +static int aml_dump_fw_version(struct hci_dev *hdev)
>> +{
>> +     struct aml_tci_rsp *rsp = NULL;
>> +     struct sk_buff *skb;
>> +     u8 value[6] = {0};
>> +     u8 *fw_ver = NULL;
>> +     int err = 0;
>> +
>> +     skb = __hci_cmd_sync_ev(hdev, AML_BT_HCI_VENDOR_CMD, 
>> sizeof(value), value,
>> +                             HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
>> +     if (IS_ERR(skb)) {
>> +             err = PTR_ERR(skb);
>> +             bt_dev_err(hdev, "Failed get fw version:(%d)", err);
>
> 1.  Failed *to* get …
> 2.  I’d add a space after the colon, but would remove the colon, and
> maybe do:
>
>         Failed to get fw version (error: %d)
>
  I will do.
>> +             return err;
>> +     }
>> +
>> +     rsp = skb_pull_data(skb, sizeof(struct aml_tci_rsp));
>> +     if (!rsp)
>> +             goto exit;
>> +
>> +     if (rsp->opcode != AML_BT_HCI_VENDOR_CMD || rsp->status != 0x00) {
>> +             bt_dev_err(hdev, "dump version, error response 
>> (0x%04X):(%d)",
>> +                    rsp->opcode, rsp->status);
>> +             err = -EINVAL;
>> +             goto exit;
>> +     }
>> +
>> +     fw_ver = (u8 *)rsp + AML_EVT_HEAD_SIZE;
>> +     bt_dev_info(hdev, "fw_version: date = %02x.%02x, number = 
>> 0x%02x%02x",
>> +             *(fw_ver + 1), *fw_ver, *(fw_ver + 3), *(fw_ver + 2));
>> +
>> +exit:
>> +     kfree_skb(skb);
>> +     return err;
>> +}
>> +
>> +static int aml_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
>> +{
>> +     struct aml_tci_rsp *rsp = NULL;
>> +     struct sk_buff *skb;
>> +     int err = 0;
>> +
>> +     bt_dev_info(hdev, "set bdaddr (%pM)", bdaddr);
>> +     skb = __hci_cmd_sync_ev(hdev, AML_BT_HCI_VENDOR_CMD,
>> +                             sizeof(bdaddr_t), bdaddr,
>> +                             HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
>> +     if (IS_ERR(skb)) {
>> +             err = PTR_ERR(skb);
>> +             bt_dev_err(hdev, "Failed to set bdaddr:(%d)", err);
>> +             return err;
>> +     }
>> +
>> +     rsp = skb_pull_data(skb, sizeof(struct aml_tci_rsp));
>> +     if (!rsp)
>> +             goto exit;
>> +
>> +     if (rsp->opcode != AML_BT_HCI_VENDOR_CMD || rsp->status != 0x00) {
>> +             bt_dev_err(hdev, "error response (0x%x):(%d)", 
>> rsp->opcode, rsp->status);
>> +             err = -EINVAL;
>> +             goto exit;
>> +     }
>> +
>> +exit:
>> +     kfree_skb(skb);
>> +     return err;
>> +}
>> +
>> +static int aml_check_bdaddr(struct hci_dev *hdev)
>> +{
>> +     struct hci_rp_read_bd_addr *paddr;
>> +     struct sk_buff *skb;
>> +     int err;
>> +
>> +     if (bacmp(&hdev->public_addr, BDADDR_ANY))
>> +             return 0;
>> +
>> +     skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
>> +                          HCI_INIT_TIMEOUT);
>> +     if (IS_ERR(skb)) {
>> +             err = PTR_ERR(skb);
>> +             bt_dev_err(hdev, "Failed to read bdaddr:(%d)", err);
>> +             return err;
>> +     }
>> +
>> +     paddr = skb_pull_data(skb, sizeof(struct hci_rp_read_bd_addr));
>> +     if (!paddr)
>> +             goto exit;
>> +
>> +     if (!bacmp(&paddr->bdaddr, AML_BDADDR_DEFAULT)) {
>> +             bt_dev_info(hdev, "amlbt using default bdaddr (%pM)", 
>> &paddr->bdaddr);
>> +             set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
>> +     }
>> +
>> +exit:
>> +     kfree_skb(skb);
>> +     return 0;
>> +}
>> +
>> +static int aml_config_rf(struct hci_dev *hdev, bool is_coex)
>> +{
>> +     u32 value = AML_RF_ANT_DOUBLE;
>> +
>> +     /* Use a single antenna when co-existing with wifi. */
>> +     if (is_coex)
>> +             value = AML_RF_ANT_SINGLE;
>> +
>> +     return aml_send_tci_cmd(hdev, AML_TCI_CMD_WRITE,
>> +                             AML_OP_RF_CFG,
>> +                             &value, sizeof(value));
>> +}
>> +
>> +static int aml_parse_dt(struct aml_serdev *amldev)
>> +{
>> +     struct device *pdev = amldev->dev;
>> +
>> +     amldev->bt_en_gpio = devm_gpiod_get(pdev, "enable",
>> +                                     GPIOD_OUT_LOW);
>> +     if (IS_ERR(amldev->bt_en_gpio)) {
>> +             dev_err(pdev, "Failed to acquire enable gpios");
>> +             return PTR_ERR(amldev->bt_en_gpio);
>> +     }
>> +
>> +     if (device_property_read_string(pdev, "firmware-name",
>> + &amldev->firmware_name)) {
>> +             dev_err(pdev, "Failed to acquire firmware path");
>> +             return -ENODEV;
>> +     }
>> +
>> +     amldev->bt_supply = devm_regulator_get(pdev, "vddio");
>> +     if (IS_ERR(amldev->bt_supply)) {
>> +             dev_err(pdev, "Failed to acquire regulator");
>> +             return PTR_ERR(amldev->bt_supply);
>> +     }
>> +
>> +     amldev->lpo_clk = devm_clk_get(pdev, NULL);
>> +     if (IS_ERR(amldev->lpo_clk)) {
>> +             dev_err(pdev, "Failed to acquire clock source");
>> +             return PTR_ERR(amldev->lpo_clk);
>> +     }
>> +
>> +     return 0;
>> +}
>> +
>> +static int aml_power_on(struct aml_serdev *amldev)
>> +{
>> +     int err;
>> +
>> +     err = regulator_enable(amldev->bt_supply);
>> +     if (err) {
>> +             dev_err(amldev->dev, "Failed to enable regulator: 
>> (%d)", err);
>> +             return err;
>> +     }
>> +
>> +     err = clk_prepare_enable(amldev->lpo_clk);
>> +     if (err) {
>> +             dev_err(amldev->dev, "Failed to enable lpo clock: 
>> (%d)", err);
>> +             return err;
>> +     }
>> +
>> +     gpiod_set_value_cansleep(amldev->bt_en_gpio, 1);
>> +
>> +     /* wait 100ms for bluetooth controller power on  */
>> +     msleep(100);
>> +     return 0;
>> +}
>> +
>> +static int aml_power_off(struct aml_serdev *amldev)
>> +{
>> +     gpiod_set_value_cansleep(amldev->bt_en_gpio, 0);
>> +
>> +     clk_disable_unprepare(amldev->lpo_clk);
>> +
>> +     regulator_disable(amldev->bt_supply);
>> +
>> +     return 0;
>> +}
>> +
>> +static int aml_set_baudrate(struct hci_uart *hu, unsigned int speed)
>> +{
>> +     /* update controller baudrate*/
>> +     if (aml_update_chip_baudrate(hu->hdev, speed) != 0) {
>> +             bt_dev_err(hu->hdev, "Failed to update baud rate");
>> +             return -EINVAL;
>> +     }
>> +
>> +     /* update local baudrate*/
>> +     serdev_device_set_baudrate(hu->serdev, speed);
>> +
>> +     return 0;
>> +}
>> +
>> +/* Initialize protocol */
>> +static int aml_open(struct hci_uart *hu)
>> +{
>> +     struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
>> +     struct aml_data *aml_data;
>> +     int err;
>> +
>> +     err = aml_parse_dt(amldev);
>> +     if (err)
>> +             return err;
>> +
>> +     if (!hci_uart_has_flow_control(hu)) {
>> +             bt_dev_err(hu->hdev, "no flow control");
>> +             return -EOPNOTSUPP;
>> +     }
>> +
>> +     aml_data = kzalloc(sizeof(*aml_data), GFP_KERNEL);
>> +     if (!aml_data)
>> +             return -ENOMEM;
>> +
>> +     skb_queue_head_init(&aml_data->txq);
>> +
>> +     hu->priv = aml_data;
>> +
>> +     return 0;
>> +}
>> +
>> +static int aml_close(struct hci_uart *hu)
>> +{
>> +     struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
>> +     struct aml_data *aml_data = hu->priv;
>> +
>> +     if (hu->serdev)
>> +             serdev_device_close(hu->serdev);
>> +
>> +     skb_queue_purge(&aml_data->txq);
>> +     kfree_skb(aml_data->rx_skb);
>> +     kfree(aml_data);
>> +
>> +     hu->priv = NULL;
>> +
>> +     return aml_power_off(amldev);
>> +}
>> +
>> +static int aml_flush(struct hci_uart *hu)
>> +{
>> +     struct aml_data *aml_data = hu->priv;
>> +
>> +     skb_queue_purge(&aml_data->txq);
>> +
>> +     return 0;
>> +}
>> +
>> +static int aml_setup(struct hci_uart *hu)
>> +{
>> +     struct aml_serdev *amldev = serdev_device_get_drvdata(hu->serdev);
>> +     struct hci_dev *hdev = amldev->serdev_hu.hdev;
>> +     int err;
>> +
>> +     /* Setup bdaddr */
>> +     hdev->set_bdaddr = aml_set_bdaddr;
>> +
>> +     err = aml_power_on(amldev);
>> +     if (err)
>> +             return err;
>> +
>> +     err = aml_set_baudrate(hu, amldev->serdev_hu.proto->oper_speed);
>> +     if (err)
>> +             return err;
>> +
>> +     err = aml_download_firmware(hdev, amldev->firmware_name);
>> +     if (err)
>> +             return err;
>> +
>> +     err = aml_config_rf(hdev, amldev->aml_dev_data->is_coex);
>> +     if (err)
>> +             return err;
>> +
>> +     err = aml_start_chip(hdev);
>> +     if (err)
>> +             return err;
>> +
>> +     /* wait 350ms for controller start up*/
>
> Missing space at the end.
>
> Also, why 350 ms? That is pretty long.

Yes, we conducted some experiments and tests, and the delay can be 
reduced to 60 milliseconds.

Thanks a lot.

>
>> +     msleep(350);
>> +
>> +     err = aml_dump_fw_version(hdev);
>> +     if (err)
>> +             return err;
>> +
>> +     err = aml_send_reset(hdev);
>> +     if (err)
>> +             return err;
>> +
>> +     err = aml_check_bdaddr(hdev);
>> +     if (err)
>> +             return err;
>> +
>> +     return 0;
>> +}
>
> […]
>
>
> Kind regards,
>
> Paul

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 1/3] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth
  2024-08-05 17:27   ` [PATCH v3 1/3] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth Krzysztof Kozlowski
@ 2024-08-06  6:54     ` Yang Li
  0 siblings, 0 replies; 19+ messages in thread
From: Yang Li @ 2024-08-06  6:54 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Marcel Holtmann, Luiz Augusto von Dentz,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Catalin Marinas,
	Will Deacon
  Cc: linux-bluetooth, netdev, devicetree, linux-kernel,
	linux-arm-kernel


On 2024/8/6 1:27, Krzysztof Kozlowski wrote:
> On 02/08/2024 11:39, Yang Li via B4 Relay wrote:
>> From: Yang Li <yang.li@amlogic.com>
>>
>> Add binding document for Amlogic Bluetooth chipsets attached over UART.
>>
>> Signed-off-by: Yang Li <yang.li@amlogic.com>
>
>> +  firmware-name:
>> +    maxItems: 1
>> +    description: specify the path of firmware bin to load
>> +
>> +required:
>> +  - compatible
>> +  - enable-gpios
>> +  - vddio-supply
>> +  - clocks
>> +  - firmware-name
> Keep the same order as listed in properties section. With this fixed:
Okay, I will do.
>
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>
> Best regards,
> Krzysztof
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 2/3] Bluetooth: hci_uart: Add support for Amlogic HCI UART
  2024-08-05 17:29   ` Krzysztof Kozlowski
@ 2024-08-06  8:33     ` Yang Li
  2024-08-06  8:37       ` Krzysztof Kozlowski
  0 siblings, 1 reply; 19+ messages in thread
From: Yang Li @ 2024-08-06  8:33 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Marcel Holtmann, Luiz Augusto von Dentz,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Catalin Marinas,
	Will Deacon
  Cc: linux-bluetooth, netdev, devicetree, linux-kernel,
	linux-arm-kernel, Ye He


On 2024/8/6 1:29, Krzysztof Kozlowski wrote:
> On 02/08/2024 11:39, Yang Li via B4 Relay wrote:
>> From: Yang Li <yang.li@amlogic.com>
>>
> ...
>
>> +
>> +static const struct aml_device_data data_w155s2 = {
>> +     .iccm_offset = 256 * 1024,
>> +};
>> +
>> +static const struct aml_device_data data_w265s2 = {
>> +     .iccm_offset = 384 * 1024,
>> +};
>> +
>> +static const struct of_device_id aml_bluetooth_of_match[] = {
>> +     { .compatible = "amlogic,w155s2-bt", .data = &data_w155s2 },
>> +     { .compatible = "amlogic,w265s2-bt", .data = &data_w265s2 },
> Your binding says these devices are compatible, but above suggests it is
> not. Confusing.

Yes, the DT binding is incorrect. I will refer to 
broadcom-bluetooth.yaml to make the modifications as follows:

properties:
   compatible:
     oneOf:
       - items:
           - enum:
               - amlogic,w265s1-bt
               - amlogic,w265p1-bt
           - const: amlogic,w155s2-bt
       - enum:
           - amlogic,w155s2-bt
           - amlogic,w265s2-bt

Please let me know if these changes are acceptable or if there are any 
further adjustments needed.

>
> Best regards,
> Krzysztof
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 2/3] Bluetooth: hci_uart: Add support for Amlogic HCI UART
  2024-08-06  8:33     ` Yang Li
@ 2024-08-06  8:37       ` Krzysztof Kozlowski
  0 siblings, 0 replies; 19+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-06  8:37 UTC (permalink / raw)
  To: Yang Li, Marcel Holtmann, Luiz Augusto von Dentz, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Catalin Marinas, Will Deacon
  Cc: linux-bluetooth, netdev, devicetree, linux-kernel,
	linux-arm-kernel, Ye He

On 06/08/2024 10:33, Yang Li wrote:
> 
> On 2024/8/6 1:29, Krzysztof Kozlowski wrote:
>> On 02/08/2024 11:39, Yang Li via B4 Relay wrote:
>>> From: Yang Li <yang.li@amlogic.com>
>>>
>> ...
>>
>>> +
>>> +static const struct aml_device_data data_w155s2 = {
>>> +     .iccm_offset = 256 * 1024,
>>> +};
>>> +
>>> +static const struct aml_device_data data_w265s2 = {
>>> +     .iccm_offset = 384 * 1024,
>>> +};
>>> +
>>> +static const struct of_device_id aml_bluetooth_of_match[] = {
>>> +     { .compatible = "amlogic,w155s2-bt", .data = &data_w155s2 },
>>> +     { .compatible = "amlogic,w265s2-bt", .data = &data_w265s2 },
>> Your binding says these devices are compatible, but above suggests it is
>> not. Confusing.
> 
> Yes, the DT binding is incorrect. I will refer to 
> broadcom-bluetooth.yaml to make the modifications as follows:
> 
> properties:
>    compatible:
>      oneOf:
>        - items:
>            - enum:
>                - amlogic,w265s1-bt
>                - amlogic,w265p1-bt
>            - const: amlogic,w155s2-bt
>        - enum:
>            - amlogic,w155s2-bt
>            - amlogic,w265s2-bt
> 
> Please let me know if these changes are acceptable or if there are any 
> further adjustments needed.

Looks good, just please check which devices are compatible with which.

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: Add support for Amlogic HCI UART
  2024-08-09  5:42 [PATCH v4 1/3] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth Yang Li
@ 2024-08-09  6:40 ` bluez.test.bot
  0 siblings, 0 replies; 19+ messages in thread
From: bluez.test.bot @ 2024-08-09  6:40 UTC (permalink / raw)
  To: linux-bluetooth, devnull+yang.li.amlogic.com

[-- Attachment #1: Type: text/plain, Size: 3698 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=878052

---Test result---

Test Summary:
CheckPatch                    FAIL      6.16 seconds
GitLint                       PASS      0.95 seconds
SubjectPrefix                 FAIL      0.72 seconds
BuildKernel                   PASS      29.97 seconds
CheckAllWarning               PASS      32.70 seconds
CheckSparse                   PASS      37.91 seconds
CheckSmatch                   PASS      103.23 seconds
BuildKernel32                 PASS      29.10 seconds
TestRunnerSetup               PASS      527.95 seconds
TestRunner_l2cap-tester       PASS      20.03 seconds
TestRunner_iso-tester         FAIL      37.09 seconds
TestRunner_bnep-tester        PASS      4.92 seconds
TestRunner_mgmt-tester        PASS      109.18 seconds
TestRunner_rfcomm-tester      PASS      7.48 seconds
TestRunner_sco-tester         PASS      15.05 seconds
TestRunner_ioctl-tester       PASS      7.98 seconds
TestRunner_mesh-tester        PASS      6.00 seconds
TestRunner_smp-tester         PASS      8.97 seconds
TestRunner_userchan-tester    PASS      5.08 seconds
IncrementalBuild              PASS      40.12 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[v4,1/3] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#95: 
new file mode 100644

total: 0 errors, 1 warnings, 63 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13758411.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


[v4,2/3] Bluetooth: hci_uart: Add support for Amlogic HCI UART
WARNING: please write a help paragraph that fully describes the config symbol
#123: FILE: drivers/bluetooth/Kconfig:277:
+config BT_HCIUART_AML
+	bool "Amlogic protocol support"
+	depends on BT_HCIUART
+	depends on BT_HCIUART_SERDEV
+	select BT_HCIUART_H4
+	select FW_LOADER
+	help
+	  The Amlogic protocol support enables Bluetooth HCI over serial
+	  port interface for Amlogic Bluetooth controllers.
+
+	  Say Y here to compile support for HCI AML protocol.
+

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#149: 
new file mode 100644

total: 0 errors, 2 warnings, 821 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13758410.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
Test: SubjectPrefix - FAIL
Desc: Check subject contains "Bluetooth" prefix
Output:
"Bluetooth: " prefix is not specified in the subject
"Bluetooth: " prefix is not specified in the subject
##############################
Test: TestRunner_iso-tester - FAIL
Desc: Run iso-tester with test-runner
Output:
Total: 122, Passed: 117 (95.9%), Failed: 1, Not Run: 4

Failed Test Cases
ISO Connect Suspend - Success                        Failed       8.212 seconds


---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2024-08-09  6:40 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-02  9:39 [PATCH v3 0/3] Add support for Amlogic HCI UART Yang Li
2024-08-02  9:39 ` Yang Li via B4 Relay
2024-08-02  9:39 ` [PATCH v3 1/3] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth Yang Li
2024-08-02  9:39   ` Yang Li via B4 Relay
2024-08-02 10:36   ` Add support for Amlogic HCI UART bluez.test.bot
2024-08-05 17:27   ` [PATCH v3 1/3] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth Krzysztof Kozlowski
2024-08-06  6:54     ` Yang Li
2024-08-02  9:39 ` [PATCH v3 2/3] Bluetooth: hci_uart: Add support for Amlogic HCI UART Yang Li
2024-08-02  9:39   ` Yang Li via B4 Relay
2024-08-02 11:02   ` Paul Menzel
2024-08-06  6:27     ` Yang Li
2024-08-05 17:29   ` Krzysztof Kozlowski
2024-08-06  8:33     ` Yang Li
2024-08-06  8:37       ` Krzysztof Kozlowski
2024-08-02  9:39 ` [PATCH v3 3/3] MAINTAINERS: Add an entry for Amlogic HCI UART (M: Yang Li) Yang Li
2024-08-02  9:39   ` Yang Li via B4 Relay
  -- strict thread matches above, loose matches on Subject: below --
2024-08-09  5:42 [PATCH v4 1/3] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth Yang Li
2024-08-09  6:40 ` Add support for Amlogic HCI UART bluez.test.bot
2024-07-18  7:42 [PATCH v2 1/3] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth Yang Li
2024-07-18  8:38 ` Add support for Amlogic HCI UART bluez.test.bot
2024-07-05 11:20 [PATCH 1/4] dt-bindings: net: bluetooth: Add support for Amlogic Bluetooth Yang Li
2024-07-05 11:57 ` Add support for Amlogic HCI UART bluez.test.bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.