Skip to contentSkip to conversation

Enable Bluetooth functionality for WCN3990

PATCH Superseded Balakrishna Godavarthi 3 participants 14 messages May 24, 2018 – Jun 4, 2018

Subsystems (4)

v6 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v6 cover Enable Bluetooth functionality for WCN3990

v6:
* Hooked up qca_power to qca_serdev.
* renamed all the naming inconsistency functions with qca_*
* leveraged common code of ROME for wcn3990.
* created wrapper functions for re-usable blocks.
* updated function of _*regulator_enable and _*regualtor_disable.
* removed redundant comments and functions.
* add code to derive the firmware files based on ROM Version.
* created new patch for common function of ROME and wcn3990.
* enables Qualcomm chip to operate at 3.2Mbps.
* updated names of functions that are used for both the chips to keep this generic.

v5:
* updated with review comments for hci_qca and btqca

v4:
* rebased all changes on top of bluetooth-next.
* addressed review comments.
* New patch created for firmware download.

v3:
* Rebased all changes on top of bluetooth-next.
* dt-bindings: net: bluetooth: Add device tree bindings for QTI chip wcn3990
- added dt-binding snippet for bluetooth chip wcn3990.
* Bluetooth: Add support for wcn3990 soc.
- updated BT_INFO with bt_dev_info, where ever necessary.

v2:
* Add support for wcn3990:
These changes are aligned as per serdev frame work.
We implemented these changes on top of https://patchwork.kernel.org/patch/10316093/
As this patch enable serdev for one of the Qualcomm BT chip.

The changes in the patch include.
- Adding support to voting up/down regulators for WCN3990.
- Bluetooth firmware download for wcn3990.

* Add device tree bindings for Atheros chips:
These changes are on top of https://patchwork.kernel.org/patch/10316097/.
- Description of device tree bindings.

Balakrishna Godavarthi (5):
dt-bindings: net: bluetooth: Add device tree bindings for QTI chip

    wcn3990

Bluetooth: btqca: Rename ROME related functions to Generic functions
Bluetooth: hci_qca: Enable 3.2 Mbps operating speed.
Bluetooth: btqca: Add wcn3990 firmware download support.
Bluetooth: hci_qca: Add support for Qualcomm Bluetooth chip wcn3990.

 .../bindings/net/qualcomm-bluetooth.txt       |  31 +-
 drivers/bluetooth/btqca.c                     |  59 ++-
 drivers/bluetooth/btqca.h                     |  20 +
 drivers/bluetooth/hci_qca.c                   | 423 ++++++++++++++++--
 4 files changed, 479 insertions(+), 54 deletions(-)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw

PATCH v6 1/5 dt-bindings: net: bluetooth: Add device tree bindings for QTI chip wcn3990

---
Canges in v6:

* Changed the oper-speed to max-speed.

Canges in v5:

* Added entry for oper-speed and init-speed.

---
 .../bindings/net/qualcomm-bluetooth.txt       | 31 +++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/net/qualcomm-bluetooth.txt +29 -2
index 0ea18a53cc29..c4590bc87390 100644
@@ -10,12 +10,24 @@ device the slave device is attached to.
 Required properties:
  - compatible: should contain one of the following:
    * "qcom,qca6174-bt"
+   * "qcom,wcn3990-bt"
 
 Optional properties:
  - enable-gpios: gpio specifier used to enable chip
  - clocks: clock provided to the controller (SUSCLK_32KHZ)
-
-Example:
+ - vddpa-supply: Bluetooth VDD PA regulator handle
+ - vddio-supply: Bluetooth VDD IO regulator handle
+ - vddldo-supply: Bluetooth VDD LDO regulator handle. Kept under optional
+		  parameters as some of the chipsets doesn't require ldo or
+		  it may use from same vddio.
+ - vddxtal-supply: Bluetooth VDD XTAL regulator handle
+ - vddcore-supply: Bluetooth VDD CORE regulator handle
+ - vddpwd-supply: Chip power down gpio is required when bluetooth module
+		  and other modules like wifi co-exist in a singe chip and
+		  shares a common gpio to bring chip out of reset.
+ - max-speed: operating speed of the chip.
+
+Examples:
 
 serial@7570000 {
 	label = "BT-UART";
@@ -28,3 +40,18 @@ serial@7570000 {
 		clocks = <&divclk4>;
 	};
 };
+
+serial@898000 {
+	label = "BT-UART";
+	status = "okay";
+
+	bluetooth: bt_wcn3990 {
+		compatible = "qcom,wcn3990-bt";
+		vddio-supply = <&pm8998_s3>;
+		vddxtal-supply = <&pm8998_s5>;
+		vddcore-supply = <&pm8998_l7>;
+		vddpa-supply = <&pm8998_l17>;
+		vddldo-supply = <&pm8998_l25>;
+		max-speed = <3200000>;
+	};
+};
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#2 lore raw

PATCH v6 2/5 Bluetooth: btqca: Rename ROME related functions to Generic functions

In reply to Balakrishna Godavarthi

Some of the QCA BTSoC ROME functions, are used for different versions or different make of BTSoC's. Instead of duplicating the same functions for new chip, updating names of the functions that are used for both chip's to keep this generic and would help in future when we would have new BT SoC.

---

Changes in v6:
* initial patch
* updated names of functions that are used for both the chips to keep this generic and would help in future when we would have new BT SoC.

---
 drivers/bluetooth/btqca.c | 14 +++++++-------
 drivers/bluetooth/btqca.h |  6 ++++++
 2 files changed, 13 insertions(+), 7 deletions(-)
drivers/bluetooth/btqca.c +7 -7
index 8219816c54a0..5c3551239b12 100644
@@ -27,7 +27,7 @@
 
 #define VERSION "0.1"
 
-static int rome_patch_ver_req(struct hci_dev *hdev, u32 *rome_version)
+int qca_patch_ver_req(struct hci_dev *hdev, u32 *rome_version)
 {
 	struct sk_buff *skb;
 	struct edl_event_hdr *edl;
@@ -35,15 +35,14 @@ static int rome_patch_ver_req(struct hci_dev *hdev, u32 *rome_version)
 	char cmd;
 	int err = 0;
 
-	BT_DBG("%s: ROME Patch Version Request", hdev->name);
+	bt_dev_dbg(hdev, "QCA BTSoC Patch Version Request");
 
 	cmd = EDL_PATCH_VER_REQ_CMD;
 	skb = __hci_cmd_sync_ev(hdev, EDL_PATCH_CMD_OPCODE, EDL_PATCH_CMD_LEN,
 				&cmd, HCI_VENDOR_PKT, HCI_INIT_TIMEOUT);
 	if (IS_ERR(skb)) {
 		err = PTR_ERR(skb);
-		BT_ERR("%s: Failed to read version of ROME (%d)", hdev->name,
-		       err);
+		bt_dev_err(hdev, "Failed to read version of BTSoC (%d)", err);
 		return err;
 	}
 
@@ -88,13 +87,14 @@ static int rome_patch_ver_req(struct hci_dev *hdev, u32 *rome_version)
 
 	return err;
 }
+EXPORT_SYMBOL_GPL(qca_patch_ver_req);
 
 static int rome_reset(struct hci_dev *hdev)
 {
 	struct sk_buff *skb;
 	int err;
 
-	BT_DBG("%s: ROME HCI_RESET", hdev->name);
+	bt_dev_dbg(hdev, "QCA BTSoC HCI_RESET");
 
 	skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
 	if (IS_ERR(skb)) {
@@ -267,7 +267,7 @@ static int rome_download_firmware(struct hci_dev *hdev,
 	const u8 *segment;
 	int ret, remain, i = 0;
 
-	bt_dev_info(hdev, "ROME Downloading %s", config->fwname);
+	bt_dev_info(hdev, "QCA BTSoC Downloading %s", config->fwname);
 
 	ret = request_firmware(&fw, config->fwname, &hdev->dev);
 	if (ret) {
@@ -339,7 +339,7 @@ int qca_uart_setup_rome(struct hci_dev *hdev, uint8_t baudrate)
 	config.user_baud_rate = baudrate;
 
 	/* Get ROME version information */
-	err = rome_patch_ver_req(hdev, &rome_ver);
+	err = qca_patch_ver_req(hdev, &rome_ver);
 	if (err < 0 || rome_ver == 0) {
 		BT_ERR("%s: Failed to get version 0x%x", hdev->name, err);
 		return err;
drivers/bluetooth/btqca.h +6 -0
index 13d77fd873b6..c1504a49fd79 100644
@@ -128,6 +128,7 @@ struct tlv_type_hdr {
 
 int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr);
 int qca_uart_setup_rome(struct hci_dev *hdev, uint8_t baudrate);
+int qca_patch_ver_req(struct hci_dev *hdev, u32 *rome_version);
 
 #else
 
@@ -141,4 +142,9 @@ static inline int qca_uart_setup_rome(struct hci_dev *hdev, int speed)
 	return -EOPNOTSUPP;
 }
 
+static inline int qca_patch_ver_req(struct hci_dev *hdev, u32 *rome_version)
+{
+	return -EOPNOTSUPP;
+}
+
 #endif
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#6 lore raw

PATCH v6 3/5 Bluetooth: hci_qca: Enable 3.2 Mbps operating speed.

In reply to Balakrishna Godavarthi

---

Changes in v6:
* initial patch
* enables Qualcomm chip to operate at 3.2Mbps.

---
 drivers/bluetooth/hci_qca.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/bluetooth/hci_qca.c +3 -1
index f05382b5a65d..cb1034998040 100644
@@ -872,6 +872,8 @@ static uint8_t qca_get_baudrate_value(int speed)
 		return QCA_BAUDRATE_2000000;
 	case 3000000:
 		return QCA_BAUDRATE_3000000;
+	case 3200000:
+		return QCA_BAUDRATE_3200000;
 	case 3500000:
 		return QCA_BAUDRATE_3500000;
 	default:
@@ -886,7 +888,7 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
 	struct sk_buff *skb;
 	u8 cmd[] = { 0x01, 0x48, 0xFC, 0x01, 0x00 };
 
-	if (baudrate > QCA_BAUDRATE_3000000)
+	if (baudrate > QCA_BAUDRATE_3200000)
 		return -EINVAL;
 
 	cmd[4] = baudrate;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#8 lore raw

PATCH v6 4/5 Bluetooth: btqca: Add wcn3990 firmware download support.

In reply to Balakrishna Godavarthi

This patch enables the RAM and NV patch download for wcn3990.

---
Changes in v6:
* add code to derive the firmware files based on ROM Version.
* created new patch for common function of ROME and wcn3990.

Changes in v5:
* moved changes related to hci_qca.
* addressed review comments.

Changes in v4:
* initial patch.

---
 drivers/bluetooth/btqca.c | 45 +++++++++++++++++++++++++++++++++++++++
 drivers/bluetooth/btqca.h |  8 +++++++
 2 files changed, 53 insertions(+)
drivers/bluetooth/btqca.c +45 -0
index 5c3551239b12..cef3daf3285b 100644
@@ -380,6 +380,51 @@ int qca_uart_setup_rome(struct hci_dev *hdev, uint8_t baudrate)
 }
 EXPORT_SYMBOL_GPL(qca_uart_setup_rome);
 
+int qca_uart_setup_cherokee(struct hci_dev *hdev, uint8_t baudrate,
+			    u32 *soc_ver)
+{
+	struct rome_config config;
+	int err;
+	u8 rom_ver;
+
+	/* Which firmware files to download are based on ROM version.
+	 * ROM version is derived from last two bytes of soc_ver.
+	 */
+	rom_ver = ((*soc_ver & 0x00000f00) >> 0x04) | (*soc_ver & 0x0000000f);
+	config.user_baud_rate = baudrate;
+	/* Download rampatch file */
+	config.type = TLV_TYPE_PATCH;
+	snprintf(config.fwname, sizeof(config.fwname), "qca/crbtfw%02x.tlv",
+		 rom_ver);
+	err = rome_download_firmware(hdev, &config);
+	if (err < 0) {
+		BT_ERR("%s: Failed to download patch (%d)", hdev->name, err);
+		return err;
+	}
+
+	/* Download NVM configuration */
+	config.type = TLV_TYPE_NVM;
+	snprintf(config.fwname, sizeof(config.fwname), "qca/crnv%02x.bin",
+		 rom_ver);
+	err = rome_download_firmware(hdev, &config);
+	if (err < 0) {
+		BT_ERR("%s: Failed to download NVM (%d)", hdev->name, err);
+		return err;
+	}
+
+	/* Perform HCI reset */
+	err = rome_reset(hdev);
+	if (err < 0) {
+		BT_ERR("%s: Failed to run HCI_RESET (%d)", hdev->name, err);
+		return err;
+	}
+
+	bt_dev_info(hdev, "wcn3990 setup on UART is completed");
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(qca_uart_setup_cherokee);
+
 MODULE_AUTHOR("Ben Young Tae Kim <[email protected]>");
 MODULE_DESCRIPTION("Bluetooth support for Qualcomm Atheros family ver " VERSION);
 MODULE_VERSION(VERSION);
drivers/bluetooth/btqca.h +8 -0
index c1504a49fd79..e93e0660cf6c 100644
@@ -129,6 +129,8 @@ struct tlv_type_hdr {
 int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr);
 int qca_uart_setup_rome(struct hci_dev *hdev, uint8_t baudrate);
 int qca_patch_ver_req(struct hci_dev *hdev, u32 *rome_version);
+int qca_uart_setup_cherokee(struct hci_dev *hdev, uint8_t baudrate,
+			    u32 *soc_ver);
 
 #else
 
@@ -147,4 +149,10 @@ static inline int qca_patch_ver_req(struct hci_dev *hdev, u32 *rome_version)
 	return -EOPNOTSUPP;
 }
 
+static int qca_uart_setup_cherokee(struct hci_dev *hdev, uint8_t baudrate,
+				   u32 *soc_ver)
+{
+	return -EOPNOTSUPP;
+}
+
 #endif
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#9 lore raw

PATCH v6 5/5 Bluetooth: hci_qca: Add support for Qualcomm Bluetooth chip wcn3990.

In reply to Balakrishna Godavarthi

Add support to set voltage/current of various regulators to power up/down Bluetooth chip wcn3990.

---

Changes in v6:
* Hooked up qca_power to qca_serdev.
* renamed all the naming inconsistency functions with qca_*
* leveraged common code of ROME for wcn3990.
* created wrapper functions for re-usable blocks.
* updated function of _*regulator_enable and _*regualtor_disable.
* removed redundant comments and functions.
* addressed review comments.

Changes in v5:
* updated regulator vddpa min_uV to 1304000.
* addressed review comments.

Changes in v4:
* Segregated the changes of btqca from hci_qca
* rebased all changes on top of bluetooth-next.
* addressed review comments.

---
 drivers/bluetooth/btqca.h   |   6 +
 drivers/bluetooth/hci_qca.c | 419 ++++++++++++++++++++++++++++++++----
 2 files changed, 381 insertions(+), 44 deletions(-)
drivers/bluetooth/btqca.h +6 -0
index e93e0660cf6c..2e551b029970 100644
@@ -37,6 +37,9 @@
 #define EDL_TAG_ID_HCI			(17)
 #define EDL_TAG_ID_DEEP_SLEEP		(27)
 
+#define CHEROKEE_POWERON_PULSE          0xFC
+#define CHEROKEE_POWEROFF_PULSE         0xC0
+
 enum qca_bardrate {
 	QCA_BAUDRATE_115200 	= 0,
 	QCA_BAUDRATE_57600,
@@ -124,6 +127,9 @@ struct tlv_type_hdr {
 	__u8   data[0];
 } __packed;
 
+int qca_btsoc_power_setup(struct hci_uart *hu, bool on);
+int qca_btsoc_shutdown(struct hci_dev *hdev);
+
 #if IS_ENABLED(CONFIG_BT_QCA)
 
 int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr);
drivers/bluetooth/hci_qca.c +375 -44

530 lines not on this page · raw message

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#3 lore raw

Re: [PATCH v6 2/5] Bluetooth: btqca: Rename ROME related functions to Generic functions

In reply to Balakrishna Godavarthi
Quoted 5 lines · Balakrishna Godavarthi

Some of the QCA BTSoC ROME functions, are used for different versions or different make of BTSoC's. Instead of duplicating the same functions for new chip, updating names of the functions that are used for both chip's to keep this generic and would help in future when we would have new BT SoC.

The commit message talks about 'functions', however only the name of one function (rome_patch_ver_req()) has changed. From the changes in log messages I assume you also intended to rename rome_reset() and rome_download_firmware().

Quoted 19 lines

---

Changes in v6:
* initial patch
* updated names of functions that are used for both the chips to keep this generic and would help in future when we would have new BT SoC.

---
 drivers/bluetooth/btqca.c | 14 +++++++-------
 drivers/bluetooth/btqca.h |  6 ++++++
 2 files changed, 13 insertions(+), 7 deletions(-)
drivers/bluetooth/btqca.c +0 -0
index 8219816c54a0..5c3551239b12 100644

drivers/bluetooth/btqca.c line 30

Quoted 5 lines
drivers/bluetooth/btqca.c +1 -1
@@ -27,7 +27,7 @@
 
 #define VERSION "0.1"
 
-static int rome_patch_ver_req(struct hci_dev *hdev, u32 *rome_version)
+int qca_patch_ver_req(struct hci_dev *hdev, u32 *rome_version)

The different version names are confusing. The name of the function calls it 'patch version', the parameter 'rome_version' and the callers vary between 'soc_version' and 'rome_version'.

It would be unfair to ask you to 'fix the world' in this patch series, but please stick at least to a consistent naming scheme in the code you change. Obviously feel free to squeeze in another cleanup patch :)

Quoted 20 lines
drivers/bluetooth/btqca.c +0 -0
 static int rome_reset(struct hci_dev *hdev)
 {
 	struct sk_buff *skb;
drivers/bluetooth/btqca.c +2 -2
 	int err;
 
-	BT_DBG("%s: ROME HCI_RESET", hdev->name);
+	bt_dev_dbg(hdev, "QCA BTSoC HCI_RESET");
 
 	skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
 	if (IS_ERR(skb)) {
@@ -267,7 +267,7 @@ static int rome_download_firmware(struct hci_dev *hdev,
 	const u8 *segment;
 	int ret, remain, i = 0;
 
-	bt_dev_info(hdev, "ROME Downloading %s", config->fwname);
+	bt_dev_info(hdev, "QCA BTSoC Downloading %s", config->fwname);
 
 	ret = request_firmware(&fw, config->fwname, &hdev->dev);
 	if (ret) {

drivers/bluetooth/btqca.c int qca_uart_setup_rome(struct hci_dev *hdev, uint8_t baudrate) · line 341

Quoted 3 lines
drivers/bluetooth/btqca.c +0 -0
@@ -339,7 +339,7 @@ int qca_uart_setup_rome(struct hci_dev *hdev, uint8_t baudrate)
 	config.user_baud_rate = baudrate;
 
 	/* Get ROME version information */

'patch version'/'SoC version'/... , whatever the chosen consistent name is.

drivers/bluetooth/btqca.c int qca_uart_setup_rome(struct hci_dev *hdev, uint8_t baudrate) · line 342

Quoted 2 lines
drivers/bluetooth/btqca.c +1 -1
-	err = rome_patch_ver_req(hdev, &rome_ver);
+	err = qca_patch_ver_req(hdev, &rome_ver);

rome_ver => ${consistent_name}_ver

Thanks

Matthias

Reviewed-by on v6 3/5
#7 lore raw

Re: [PATCH v6 3/5] Bluetooth: hci_qca: Enable 3.2 Mbps operating speed.

In reply to Balakrishna Godavarthi
Quoted 6 lines · Balakrishna Godavarthi

---

Changes in v6:
* initial patch
* enables Qualcomm chip to operate at 3.2Mbps.

The second point should be rather part of the commit message, but since the summary basically states the same I guess it's fine to omit it.

Quoted 19 lines
---
 drivers/bluetooth/hci_qca.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/bluetooth/hci_qca.c +2 -0
index f05382b5a65d..cb1034998040 100644
@@ -872,6 +872,8 @@ static uint8_t qca_get_baudrate_value(int speed)
 		return QCA_BAUDRATE_2000000;
 	case 3000000:
 		return QCA_BAUDRATE_3000000;
+	case 3200000:
+		return QCA_BAUDRATE_3200000;
 	case 3500000:
 		return QCA_BAUDRATE_3500000;
 	default:

drivers/bluetooth/hci_qca.c static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate) · line 894

Quoted 8 lines
drivers/bluetooth/hci_qca.c +1 -1
@@ -886,7 +888,7 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
 	struct sk_buff *skb;
 	u8 cmd[] = { 0x01, 0x48, 0xFC, 0x01, 0x00 };
 
-	if (baudrate > QCA_BAUDRATE_3000000)
+	if (baudrate > QCA_BAUDRATE_3200000)
 		return -EINVAL;
 
 	cmd[4] = baudrate;
#10 lore raw

Re: [PATCH v6 5/5] Bluetooth: hci_qca: Add support for Qualcomm Bluetooth chip wcn3990.

In reply to Balakrishna Godavarthi
Thank you for the patch! Perhaps something to improve:

Hi Balakrishna,

Thank you for the patch! Perhaps something to improve:

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

url:    https://github.com/0day-ci/linux/commits/Balakrishna-Godavarthi/Enable-Bluetooth-functionality-for-WCN3990/20180527-135618
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: x86_64-randconfig-x005-201821 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

In file included from drivers/bluetooth/btqca.c:26:0:

>> drivers/bluetooth/btqca.h:130:34: warning: 'struct hci_uart' declared inside parameter list will not be visible outside of this definition or declaration
    int qca_btsoc_power_setup(struct hci_uart *hu, bool on);
                                     ^~~~~~~~

vim +130 drivers/bluetooth/btqca.h

129

 > 130	int qca_btsoc_power_setup(struct hci_uart *hu, bool on);

131 int qca_btsoc_shutdown(struct hci_dev *hdev);
132

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#11 lore raw

Re: [PATCH v6 5/5] Bluetooth: hci_qca: Add support for Qualcomm Bluetooth chip wcn3990.

In reply to Balakrishna Godavarthi
Thank you for the patch! Perhaps something to improve:

Hi Balakrishna,

Thank you for the patch! Perhaps something to improve:

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

url:    https://github.com/0day-ci/linux/commits/Balakrishna-Godavarthi/Enable-Bluetooth-functionality-for-WCN3990/20180527-135618
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: i386-randconfig-b0-05271406 (attached as .config)
compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

In file included from drivers/bluetooth/btqca.c:26:0:

>> drivers/bluetooth/btqca.h:130:34: warning: 'struct hci_uart' declared inside parameter list
    int qca_btsoc_power_setup(struct hci_uart *hu, bool on);
                                     ^
>> drivers/bluetooth/btqca.h:130:34: warning: its scope is only this definition or declaration, which is probably not what you want

vim +130 drivers/bluetooth/btqca.h

129

 > 130	int qca_btsoc_power_setup(struct hci_uart *hu, bool on);

131 int qca_btsoc_shutdown(struct hci_dev *hdev);
132

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#4 lore raw

Re: [PATCH v6 2/5] Bluetooth: btqca: Rename ROME related functions to Generic functions

In reply to Matthias Kaehlcke

Hi Matthias,

Quoted 7 lines · Matthias Kaehlcke
Quoted 5 lines · Balakrishna Godavarthi

Some of the QCA BTSoC ROME functions, are used for different versions or different make of BTSoC's. Instead of duplicating the same functions for new chip, updating names of the functions that are used for both chip's to keep this generic and would help in future when we would have new BT SoC.

Quoted 5 lines

The commit message talks about 'functions', however only the name of one function (rome_patch_ver_req()) has changed. From the changes in log messages I assume you also intended to rename rome_reset() and rome_download_firmware().

[Bala]: may be commit message is confusing, my initial intention in changing function names are restricted to functions which are exported to hci_qca.c and logs.
But as per your suggestion i can also change the rome_reset()
(qca_send_reset) and rome_download_firmware() (qca_download_firmware()) too.
Will update the max possible function names in next incremental
patch.
But i will restrict my changes to only required function names.
will not change the function names related to ROME (common to wnc3990) which are called in other files (some function are used in btusb.c)and also
the structure defined with name rome_.*. Changing these name
could break some functionalities of already available code.

Quoted 30 lines
Quoted 19 lines

---

Changes in v6:
* initial patch
* updated names of functions that are used for both the chips to keep this generic and would help in future when we would have new BT SoC.

---
 drivers/bluetooth/btqca.c | 14 +++++++-------
 drivers/bluetooth/btqca.h |  6 ++++++
 2 files changed, 13 insertions(+), 7 deletions(-)
drivers/bluetooth/btqca.c +0 -0
index 8219816c54a0..5c3551239b12 100644

drivers/bluetooth/btqca.c line 31

Quoted 6 lines
drivers/bluetooth/btqca.c +1 -1
@@ -27,7 +27,7 @@
 
 #define VERSION "0.1"
 
-static int rome_patch_ver_req(struct hci_dev *hdev, u32 
 *rome_version)
+int qca_patch_ver_req(struct hci_dev *hdev, u32 *rome_version)

The different version names are confusing. The name of the function calls it 'patch version', the parameter 'rome_version' and the callers vary between 'soc_version' and 'rome_version'.

Quoted 4 lines

It would be unfair to ask you to 'fix the world' in this patch series, but please stick at least to a consistent naming scheme in the code you change. Obviously feel free to squeeze in another cleanup patch :)

[Bala]: will update function and argument names.

Quoted 29 lines
Quoted 21 lines
drivers/bluetooth/btqca.c +0 -0
 static int rome_reset(struct hci_dev *hdev)
 {
drivers/bluetooth/btqca.c +2 -2
 	struct sk_buff *skb;
 	int err;
 
-	BT_DBG("%s: ROME HCI_RESET", hdev->name);
+	bt_dev_dbg(hdev, "QCA BTSoC HCI_RESET");
 
 	skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
 	if (IS_ERR(skb)) {
@@ -267,7 +267,7 @@ static int rome_download_firmware(struct hci_dev 
 *hdev,
 	const u8 *segment;
 	int ret, remain, i = 0;
 
-	bt_dev_info(hdev, "ROME Downloading %s", config->fwname);
+	bt_dev_info(hdev, "QCA BTSoC Downloading %s", config->fwname);
 
 	ret = request_firmware(&fw, config->fwname, &hdev->dev);
drivers/bluetooth/btqca.c +0 -0
 	if (ret) {

drivers/bluetooth/btqca.c int qca_uart_setup_rome(struct hci_dev *hdev, · line 342

Quoted 4 lines
drivers/bluetooth/btqca.c +0 -0
@@ -339,7 +339,7 @@ int qca_uart_setup_rome(struct hci_dev *hdev, 
 uint8_t baudrate)
 	config.user_baud_rate = baudrate;
 
 	/* Get ROME version information */

'patch version'/'SoC version'/... , whatever the chosen consistent name is.

Quoted 8 lines

drivers/bluetooth/btqca.c int qca_uart_setup_rome(struct hci_dev *hdev, uint8_t baudrate) · line 342

Quoted 2 lines
drivers/bluetooth/btqca.c +1 -1
-	err = rome_patch_ver_req(hdev, &rome_ver);
+	err = qca_patch_ver_req(hdev, &rome_ver);

rome_ver => ${consistent_name}_ver

Thanks

Matthias

Can you please review other patches too so that i can address review comments in next patch set.

Signature · 2 lines
Regards
Balakrishna.
#12 lore raw

Re: [PATCH v6 5/5] Bluetooth: hci_qca: Add support for Qualcomm Bluetooth chip wcn3990.

In reply to Balakrishna Godavarthi
Quoted 42 lines · Balakrishna Godavarthi

Add support to set voltage/current of various regulators to power up/down Bluetooth chip wcn3990.

---

Changes in v6:
* Hooked up qca_power to qca_serdev.
* renamed all the naming inconsistency functions with qca_*
* leveraged common code of ROME for wcn3990.
* created wrapper functions for re-usable blocks.
* updated function of _*regulator_enable and _*regualtor_disable.
* removed redundant comments and functions.
* addressed review comments.

Changes in v5:
* updated regulator vddpa min_uV to 1304000.
* addressed review comments.

Changes in v4:
* Segregated the changes of btqca from hci_qca
* rebased all changes on top of bluetooth-next.
* addressed review comments.
---

...

drivers/bluetooth/hci_qca.c +3 -2
index cb1034998040..e235be0e5202 100644
...
+static void qca_set_init_speed(struct hci_uart *hu)
+{
+	unsigned int speed = 0;
 
-	/* Setup initial baudrate */
-	speed = 0;
 	if (hu->init_speed)
 		speed = hu->init_speed;
 	else if (hu->proto->init_speed)

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1021

Quoted 7 lines
drivers/bluetooth/hci_qca.c +4 -0
@@ -946,29 +1015,136 @@ static int qca_setup(struct hci_uart *hu)
 
 	if (speed)
 		host_set_baudrate(hu, speed);
+}
+
+static int qca_set_operating_speed(struct hci_uart *hu, u32 *qca_baudrate)
+{

This is a bit convoluted, with the function setting the speed and returning it. I would suggest a qca_get_oper_speed() and qca_get_init_speed(), and just have them return the value instead of passing it through a pointer. You could then have a qca_set_speed() which converts the baudrate to the value the chip understands, calls qca_set_baudrate() and host_set_baudrate()

Quoted 15 lines
drivers/bluetooth/hci_qca.c +15 -0
+static int qca_setup(struct hci_uart *hu)
+{
+	struct hci_dev *hdev = hu->hdev;
+	struct qca_data *qca = hu->priv;
+	struct qca_serdev *qcadev;
+	unsigned int speed, qca_baudrate = QCA_BAUDRATE_115200;
+	int ret;
+	int soc_ver;
+
+	qcadev = serdev_device_get_drvdata(hu->serdev);
+
+	switch (qcadev->btsoc_type) {
+	case BTQCA_CHEROKEE:
+		bt_dev_dbg(hdev, "setting up wcn3990");
+		/* Patch downloading has to be done without IBS mode */

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1080

Quoted 10 lines
drivers/bluetooth/hci_qca.c +10 -0
+		clear_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags);
+		qca_set_init_speed(hu);
+		hci_uart_set_flow_control(hu, true);
+		ret = qca_send_vendor_cmd(hdev, CHEROKEE_POWERON_PULSE);
+		if (ret) {
+			bt_dev_err(hdev, "failed to send power on command");
+			return ret;
+		}
+
+		/* Close and re-open the port */

As mentioned earlier, this comment doesn't provide any useful information, it's evident from the code. Rather explain *why* the close/open is needed.

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1090

Quoted 10 lines
drivers/bluetooth/hci_qca.c +10 -0
+		serdev_device_close(hu->serdev);
+		ret = serdev_device_open(hu->serdev);
+		if (ret) {
+			bt_dev_err(hdev, "failed to open port");
+			return ret;
+		}
+
+		qca_set_init_speed(hu);
+		hci_uart_set_flow_control(hu, false);
+		msleep(100);

Which step makes the delay necessary? I guess it's not enabling flow control but probably sending the power on command. If that is correct the delay should be done after the corresponding command.

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1093

Quoted 3 lines
drivers/bluetooth/hci_qca.c +3 -0
+		ret = qca_patch_ver_req(hdev, &soc_ver);
+		if (ret < 0 || soc_ver == 0) {
+			bt_dev_err(hdev, "Failed to get version 0x%x", ret);

Probably better: "Failed to get version: %d" since ret contains an errno and the problem wasn't that we couldn't get "version 0x<errno>".

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1098

Quoted 5 lines
drivers/bluetooth/hci_qca.c +5 -0
+			return ret;
+		}
+
+		bt_dev_info(hdev, "wcn3990 controller version 0x%08x", soc_ver);
+		hci_uart_set_flow_control(hu, true);

Repeatedly switching on and off of flow control is a bit noisy, I wonder if it could be hidden in a wrapper. From the code it seems that flow control is disabled (true) for init speed and and enabled (false) for operating speed. If this is correct the hci_uart_set_flow_control() calls could be moved inside qca_set_oper/init_speed(). struct qca_serdev could have a flag indicating if flow control is supported at all to skip the hci_uart_set_flow_control() calls for Rome.

Just an idea, no objections if you prefer to leave it as is and Marcel is ok with it.

Quoted 11 lines
drivers/bluetooth/hci_qca.c +11 -0
+		ret = qca_set_operating_speed(hu, &qca_baudrate);
+		if (ret)
+			return ret;
+		hci_uart_set_flow_control(hu, false);
+		/* Setup patch and NVM configurations */
+		ret = qca_uart_setup_cherokee(hdev, qca_baudrate, &soc_ver);
+
+		break;
+
+	default:
+		bt_dev_info(hdev, "ROME setup");

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1119

Quoted 10 lines
drivers/bluetooth/hci_qca.c +10 -0
+
+		/* Patch downloading has to be done without IBS mode */
+		clear_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags);
+
+		/* Setup initial baudrate */
+		speed = 0;
+		if (hu->init_speed)
+			speed = hu->init_speed;
+		else if (hu->proto->init_speed)
+			speed = hu->proto->init_speed;

If you introduce helpers to determine the init/oper speed these should also be used here. Probably best to do this in a separate patch.

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1129

Quoted 10 lines
drivers/bluetooth/hci_qca.c +10 -0
+
+		if (speed)
+			host_set_baudrate(hu, speed);
+
+		/* Setup user speed if needed */
+		speed = 0;
+		if (hu->oper_speed)
+			speed = hu->oper_speed;
+		else if (hu->proto->oper_speed)
+			speed = hu->proto->oper_speed;

ditto

drivers/bluetooth/hci_qca.c static struct hci_uart_proto qca_proto = { · line 1224

Quoted 6 lines
drivers/bluetooth/hci_qca.c +6 -0
+static void qca_disable_regulator(struct qca_vreg vregs,
+				  struct regulator *regulator)
+{
+	/* Disable the regulator if requested by user
+	 * or when fault to enable any regulator.
+	 */

This comment is not useful. The following code simply disables the regulator, why this is done is a question of the caller.

Quoted 21 lines
drivers/bluetooth/hci_qca.c +21 -0
+	regulator_disable(regulator);
+	regulator_set_voltage(regulator, 0, vregs.max_uV);
+	if (vregs.load_uA)
+		regulator_set_load(regulator, 0);
+
+}
+
+int qca_btsoc_power_setup(struct hci_uart *hu, bool on)
+{
+	struct qca_vreg *vregs;
+	struct regulator_bulk_data *vreg_bulk;
+	struct qca_serdev *qcadev;
+	int i, num_vregs, ret = 0;
+
+	qcadev = serdev_device_get_drvdata(hu->serdev);
+	if (!qcadev || !qcadev->bt_power || !qcadev->bt_power->vreg_data ||
+	    !qcadev->bt_power->vreg_bulk)
+		return -EINVAL;
+
+	vregs = qcadev->bt_power->vreg_data->vregs;
+	vreg_bulk = qcadev->bt_power->vreg_bulk;

drivers/bluetooth/hci_qca.c static struct hci_uart_proto qca_proto = { · line 1255

Quoted 10 lines
drivers/bluetooth/hci_qca.c +10 -0
+	num_vregs = qcadev->bt_power->vreg_data->num_vregs;
+	BT_DBG("on: %d", on);
+	if (on  && !qcadev->bt_power->vregs_on) {
+		for (i = 0; i < num_vregs; i++) {
+			ret = qca_enable_regulator(vregs[i],
+						   vreg_bulk[i].consumer);
+			if (ret)
+				break;
+		}
+		/* regulators failed */

Comment is not useful, BT_ERR below leaves things clear.

Quoted 60 lines
drivers/bluetooth/hci_qca.c +49 -0
+		if (ret) {
+			BT_ERR("failed to enable regulator:%s", vregs[i].name);
+			/* turn off regulators which are enabled */
+			for (i = i - 1; i >= 0; i--)
+				qca_disable_regulator(vregs[i],
+						      vreg_bulk[i].consumer);
+		} else {
+			qcadev->bt_power->vregs_on = true;
+		}
+	} else if (!on && qcadev->bt_power->vregs_on) {
+		/* turn off regulator in reverse order */
+		i = qcadev->bt_power->vreg_data->num_vregs - 1;
+		for ( ; i >= 0; i--)
+			qca_disable_regulator(vregs[i], vreg_bulk[i].consumer);
+		qcadev->bt_power->vregs_on = false;
+	}
+
+	return ret;
+}
+
+static int qca_init_regulators(struct qca_power *qca,
+			       const struct qca_vreg *vregs, size_t num_vregs)
+{
+	int i;
+
+	qca->vreg_bulk = devm_kzalloc(qca->dev, num_vregs *
+				      sizeof(struct regulator_bulk_data),
+				      GFP_KERNEL);
+	if (!qca->vreg_bulk)
+		return -ENOMEM;
+
+	for (i = 0; i < num_vregs; i++)
+		qca->vreg_bulk[i].supply = vregs[i].name;
+
+	return devm_regulator_bulk_get(qca->dev, num_vregs, qca->vreg_bulk);
+}
+
 static int qca_serdev_probe(struct serdev_device *serdev)
 {
 	struct qca_serdev *qcadev;
+	const struct qca_vreg_data *data;
 	int err;
 
 	qcadev = devm_kzalloc(&serdev->dev, sizeof(*qcadev), GFP_KERNEL);
@@ -1014,34 +1301,72 @@ static int qca_serdev_probe(struct serdev_device *serdev)
 		return -ENOMEM;
 
 	qcadev->serdev_hu.serdev = serdev;
+	data = of_device_get_match_data(&serdev->dev);
+	if (data && data->soc_type == BTQCA_CHEROKEE)
+		qcadev->btsoc_type = BTQCA_CHEROKEE;
+	else
+		qcadev->btsoc_type = BTQCA_ROME;
+
 	serdev_device_set_drvdata(serdev, qcadev);
+	if (qcadev->btsoc_type == BTQCA_CHEROKEE) {
+		qcadev->bt_power = devm_kzalloc(&serdev->dev,
+						sizeof(struct qca_power),
+						GFP_KERNEL);
+		if (!qcadev->bt_power)

drivers/bluetooth/hci_qca.c static int qca_serdev_probe(struct serdev_device *serdev) · line 1325

Quoted 10 lines
drivers/bluetooth/hci_qca.c +10 -0
+			return -ENOMEM;
+
+		qcadev->bt_power->dev = &serdev->dev;
+		qcadev->bt_power->vreg_data = data;
+		err = qca_init_regulators(qcadev->bt_power, data->vregs,
+					  data->num_vregs);
+		if (err) {
+			BT_ERR("Failed to init regulators:%d", err);
+			devm_kfree(&serdev->dev, qcadev->bt_power->vreg_bulk);
+			devm_kfree(&serdev->dev, qcadev->bt_power);

Not necessary, the memory is allocated with devm_kzalloc(&serdev->dev, ...), therefore it is freed if probe() fails.

Quoted 9 lines
drivers/bluetooth/hci_qca.c +2 -6
+			goto out;
+		}
 
-	qcadev->bt_en = devm_gpiod_get(&serdev->dev, "enable",
-				       GPIOD_OUT_LOW);
-	if (IS_ERR(qcadev->bt_en)) {
-		dev_err(&serdev->dev, "failed to acquire enable gpio\n");
-		return PTR_ERR(qcadev->bt_en);
-	}

drivers/bluetooth/hci_qca.c static int qca_serdev_probe(struct serdev_device *serdev) · line 1338

Quoted 10 lines
drivers/bluetooth/hci_qca.c +10 -0
+		qcadev->bt_power->vregs_on = false;
+		device_property_read_u32(&serdev->dev, "max-speed",
+					 &qcadev->oper_speed);
+		if (!qcadev->oper_speed)
+			BT_INFO("UART will pick default operating speed");
+		err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto);
+		if (err) {
+			BT_ERR("wcn3990 serdev registration failed");
+			devm_kfree(&serdev->dev, qcadev->bt_power->vreg_bulk);
+			devm_kfree(&serdev->dev, qcadev->bt_power);

no need to free memory.

Quoted 50 lines
drivers/bluetooth/hci_qca.c +26 -15
+			goto out;
+		}
+	} else {
+		qcadev->bt_en = devm_gpiod_get(&serdev->dev, "enable",
+					       GPIOD_OUT_LOW);
+		if (IS_ERR(qcadev->bt_en)) {
+			dev_err(&serdev->dev, "failed to acquire enable gpio\n");
+			return PTR_ERR(qcadev->bt_en);
+		}
 
-	qcadev->susclk = devm_clk_get(&serdev->dev, NULL);
-	if (IS_ERR(qcadev->susclk)) {
-		dev_err(&serdev->dev, "failed to acquire clk\n");
-		return PTR_ERR(qcadev->susclk);
-	}
+		qcadev->susclk = devm_clk_get(&serdev->dev, NULL);
+		if (IS_ERR(qcadev->susclk)) {
+			dev_err(&serdev->dev, "failed to acquire clk\n");
+			return PTR_ERR(qcadev->susclk);
+		}
 
-	err = clk_set_rate(qcadev->susclk, SUSCLK_RATE_32KHZ);
-	if (err)
-		return err;
+		err = clk_set_rate(qcadev->susclk, SUSCLK_RATE_32KHZ);
+		if (err)
+			return err;
 
-	err = clk_prepare_enable(qcadev->susclk);
-	if (err)
-		return err;
+		err = clk_prepare_enable(qcadev->susclk);
+		if (err)
+			return err;
 
-	err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto);
-	if (err)
-		clk_disable_unprepare(qcadev->susclk);
+		err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto);
+		if (err)
+			clk_disable_unprepare(qcadev->susclk);
+	}
+
+out:	return err;
 
-	return err;
 }
 
 static void qca_serdev_remove(struct serdev_device *serdev)

drivers/bluetooth/hci_qca.c static void qca_serdev_remove(struct serdev_device *serdev) · line 1380

Quoted 7 lines
drivers/bluetooth/hci_qca.c +3 -1
@@ -1050,11 +1375,17 @@ static void qca_serdev_remove(struct serdev_device *serdev)
 
 	hci_uart_unregister_device(&qcadev->serdev_hu);
 
-	clk_disable_unprepare(qcadev->susclk);
+	if (qcadev->btsoc_type == BTQCA_CHEROKEE) {
+		devm_kfree(&serdev->dev, qcadev->bt_power->vreg_bulk);
+		devm_kfree(&serdev->dev, qcadev->bt_power);

no need to free memory

#5 lore raw

Re: [PATCH v6 2/5] Bluetooth: btqca: Rename ROME related functions to Generic functions

In reply to Balakrishna Godavarthi
Quoted 101 lines · Balakrishna Godavarthi

Hi Matthias,

Quoted 9 lines · Matthias Kaehlcke
Quoted 7 lines · Balakrishna Godavarthi

Some of the QCA BTSoC ROME functions, are used for different versions or different make of BTSoC's. Instead of duplicating the same functions
for new chip, updating names of the functions that are used for both chip's to keep this generic and would help in future when we would have
new BT SoC.

Quoted 5 lines

The commit message talks about 'functions', however only the name of one function (rome_patch_ver_req()) has changed. From the changes in log messages I assume you also intended to rename rome_reset() and rome_download_firmware().

[Bala]: may be commit message is confusing, my initial intention in changing function names are restricted to functions which are exported to hci_qca.c and logs.
But as per your suggestion i can also change the rome_reset()
(qca_send_reset) and rome_download_firmware() (qca_download_firmware()) too.
Will update the max possible function names in next incremental
patch.
But i will restrict my changes to only required function names. will
not change the function names related to ROME (common to wnc3990) which are called in other files (some function are used in btusb.c)and also
the structure defined with name rome_.*. Changing these name could
break some functionalities of already available code.

Quoted 30 lines
Quoted 19 lines

---

Changes in v6:
* initial patch
* updated names of functions that are used for both the chips to keep this generic and would help in future when we would have new BT SoC.

---
 drivers/bluetooth/btqca.c | 14 +++++++-------
 drivers/bluetooth/btqca.h |  6 ++++++
 2 files changed, 13 insertions(+), 7 deletions(-)
drivers/bluetooth/btqca.c +0 -0
index 8219816c54a0..5c3551239b12 100644

drivers/bluetooth/btqca.c line 31

Quoted 6 lines
drivers/bluetooth/btqca.c +1 -1
@@ -27,7 +27,7 @@
 
 #define VERSION "0.1"
 
-static int rome_patch_ver_req(struct hci_dev *hdev, u32
 *rome_version)
+int qca_patch_ver_req(struct hci_dev *hdev, u32 *rome_version)

The different version names are confusing. The name of the function calls it 'patch version', the parameter 'rome_version' and the callers vary between 'soc_version' and 'rome_version'.

Quoted 4 lines

It would be unfair to ask you to 'fix the world' in this patch series, but please stick at least to a consistent naming scheme in the code you change. Obviously feel free to squeeze in another cleanup patch :)

[Bala]: will update function and argument names.

Quoted 34 lines
Quoted 21 lines
drivers/bluetooth/btqca.c +0 -0
 static int rome_reset(struct hci_dev *hdev)
 {
drivers/bluetooth/btqca.c +2 -2
 	struct sk_buff *skb;
 	int err;
 
-	BT_DBG("%s: ROME HCI_RESET", hdev->name);
+	bt_dev_dbg(hdev, "QCA BTSoC HCI_RESET");
 
 	skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
 	if (IS_ERR(skb)) {
@@ -267,7 +267,7 @@ static int rome_download_firmware(struct hci_dev
 *hdev,
 	const u8 *segment;
 	int ret, remain, i = 0;
 
-	bt_dev_info(hdev, "ROME Downloading %s", config->fwname);
+	bt_dev_info(hdev, "QCA BTSoC Downloading %s", config->fwname);
 
 	ret = request_firmware(&fw, config->fwname, &hdev->dev);
drivers/bluetooth/btqca.c +0 -0
 	if (ret) {

drivers/bluetooth/btqca.c int qca_uart_setup_rome(struct hci_dev *hdev, · line 342

Quoted 4 lines
drivers/bluetooth/btqca.c +0 -0
@@ -339,7 +339,7 @@ int qca_uart_setup_rome(struct hci_dev *hdev,
 uint8_t baudrate)
 	config.user_baud_rate = baudrate;
 
 	/* Get ROME version information */

'patch version'/'SoC version'/... , whatever the chosen consistent name is.

drivers/bluetooth/btqca.c int qca_uart_setup_rome(struct hci_dev *hdev, uint8_t baudrate) · line 342

Quoted 2 lines
drivers/bluetooth/btqca.c +1 -1
-	err = rome_patch_ver_req(hdev, &rome_ver);
+	err = qca_patch_ver_req(hdev, &rome_ver);

rome_ver => ${consistent_name}_ver

Quoted 6 lines
Quoted 3 lines

Thanks

Matthias

Can you please review other patches too so that i can address review comments in next patch set.

Done

Sorry, for the delay, reviews can be time intensive and I have a limited bandwidth for it. In any case it's good to also give Marcel and Johan some time to look at it before respinning, after all it's their opinion what counts most, I'm just trying to (hopefully) help a bit.

#13 lore raw

Re: [PATCH v6 5/5] Bluetooth: hci_qca: Add support for Qualcomm Bluetooth chip wcn3990.

In reply to Matthias Kaehlcke

HI Matthias,

Pls find my comments inline.

Quoted 44 lines · Matthias Kaehlcke
Quoted 43 lines · Balakrishna Godavarthi

Add support to set voltage/current of various regulators to power up/down Bluetooth chip wcn3990.

---

Changes in v6:
* Hooked up qca_power to qca_serdev.
* renamed all the naming inconsistency functions with qca_*
* leveraged common code of ROME for wcn3990.
* created wrapper functions for re-usable blocks.
* updated function of _*regulator_enable and _*regualtor_disable.
* removed redundant comments and functions.
* addressed review comments.

Changes in v5:
* updated regulator vddpa min_uV to 1304000.
* addressed review comments.

Changes in v4:
* Segregated the changes of btqca from hci_qca
* rebased all changes on top of bluetooth-next.
* addressed review comments.
---

...

drivers/bluetooth/hci_qca.c +3 -2
index cb1034998040..e235be0e5202 100644
...
+static void qca_set_init_speed(struct hci_uart *hu)
+{
+	unsigned int speed = 0;
 
-	/* Setup initial baudrate */
-	speed = 0;
 	if (hu->init_speed)
 		speed = hu->init_speed;
 	else if (hu->proto->init_speed)
@@ -946,29 +1015,136 @@ static int qca_setup(struct hci_uart *hu)
 
Quoted 15 lines

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1021

Quoted 7 lines
drivers/bluetooth/hci_qca.c +4 -0
 	if (speed)
 		host_set_baudrate(hu, speed);
+}
+
+static int qca_set_operating_speed(struct hci_uart *hu, u32 
 *qca_baudrate)
+{

This is a bit convoluted, with the function setting the speed and returning it. I would suggest a qca_get_oper_speed() and qca_get_init_speed(), and just have them return the value instead of passing it through a pointer. You could then have a qca_set_speed() which converts the baudrate to the value the chip understands, calls qca_set_baudrate() and host_set_baudrate()

[Bala]: will update.

Quoted 66 lines
Quoted 15 lines
drivers/bluetooth/hci_qca.c +15 -0
+static int qca_setup(struct hci_uart *hu)
+{
+	struct hci_dev *hdev = hu->hdev;
+	struct qca_data *qca = hu->priv;
+	struct qca_serdev *qcadev;
+	unsigned int speed, qca_baudrate = QCA_BAUDRATE_115200;
+	int ret;
+	int soc_ver;
+
+	qcadev = serdev_device_get_drvdata(hu->serdev);
+
+	switch (qcadev->btsoc_type) {
+	case BTQCA_CHEROKEE:
+		bt_dev_dbg(hdev, "setting up wcn3990");
+		/* Patch downloading has to be done without IBS mode */

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1080

Quoted 10 lines
drivers/bluetooth/hci_qca.c +10 -0
+		clear_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags);
+		qca_set_init_speed(hu);
+		hci_uart_set_flow_control(hu, true);
+		ret = qca_send_vendor_cmd(hdev, CHEROKEE_POWERON_PULSE);
+		if (ret) {
+			bt_dev_err(hdev, "failed to send power on command");
+			return ret;
+		}
+
+		/* Close and re-open the port */

As mentioned earlier, this comment doesn't provide any useful information, it's evident from the code. Rather explain *why* the close/open is needed.

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1090

Quoted 10 lines
drivers/bluetooth/hci_qca.c +10 -0
+		serdev_device_close(hu->serdev);
+		ret = serdev_device_open(hu->serdev);
+		if (ret) {
+			bt_dev_err(hdev, "failed to open port");
+			return ret;
+		}
+
+		qca_set_init_speed(hu);
+		hci_uart_set_flow_control(hu, false);
+		msleep(100);

Which step makes the delay necessary? I guess it's not enabling flow control but probably sending the power on command. If that is correct the delay should be done after the corresponding command.

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1093

Quoted 3 lines
drivers/bluetooth/hci_qca.c +3 -0
+		ret = qca_patch_ver_req(hdev, &soc_ver);
+		if (ret < 0 || soc_ver == 0) {
+			bt_dev_err(hdev, "Failed to get version 0x%x", ret);

Probably better: "Failed to get version: %d" since ret contains an errno and the problem wasn't that we couldn't get "version 0x<errno>".

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1098

Quoted 5 lines
drivers/bluetooth/hci_qca.c +5 -0
+			return ret;
+		}
+
+		bt_dev_info(hdev, "wcn3990 controller version 0x%08x", soc_ver);
+		hci_uart_set_flow_control(hu, true);

Repeatedly switching on and off of flow control is a bit noisy, I wonder if it could be hidden in a wrapper. From the code it seems that flow control is disabled (true) for init speed and and enabled (false) for operating speed. If this is correct the hci_uart_set_flow_control() calls could be moved inside qca_set_oper/init_speed(). struct qca_serdev could have a flag indicating if flow control is supported at all to skip the hci_uart_set_flow_control() calls for Rome.

Quoted 3 lines

Just an idea, no objections if you prefer to leave it as is and Marcel is ok with it.

[Bala]: will update.

Quoted 16 lines
Quoted 16 lines
drivers/bluetooth/hci_qca.c +16 -0
+		ret = qca_set_operating_speed(hu, &qca_baudrate);
+		if (ret)
+			return ret;
+		hci_uart_set_flow_control(hu, false);
+		/* Setup patch and NVM configurations */
+		ret = qca_uart_setup_cherokee(hdev, qca_baudrate, &soc_ver);
+
+		break;
+
+	default:
+		bt_dev_info(hdev, "ROME setup");
+
+		/* Patch downloading has to be done without IBS mode */
+		clear_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags);
+
+		/* Setup initial baudrate */
Quoted 9 lines

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1119

Quoted 5 lines
drivers/bluetooth/hci_qca.c +5 -0
+		speed = 0;
+		if (hu->init_speed)
+			speed = hu->init_speed;
+		else if (hu->proto->init_speed)
+			speed = hu->proto->init_speed;

If you introduce helpers to determine the init/oper speed these should also be used here. Probably best to do this in a separate patch.

[Bala]: will update ROME related stuff in other patch.

Quoted 4 lines
Quoted 4 lines
drivers/bluetooth/hci_qca.c +4 -0
+
+		if (speed)
+			host_set_baudrate(hu, speed);
+
Quoted 9 lines

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1129

Quoted 6 lines
drivers/bluetooth/hci_qca.c +6 -0
+		/* Setup user speed if needed */
+		speed = 0;
+		if (hu->oper_speed)
+			speed = hu->oper_speed;
+		else if (hu->proto->oper_speed)
+			speed = hu->proto->oper_speed;

ditto

[Bala]: will update.

Quoted 10 lines

drivers/bluetooth/hci_qca.c static struct hci_uart_proto qca_proto = { · line 1224

Quoted 6 lines
drivers/bluetooth/hci_qca.c +6 -0
+static void qca_disable_regulator(struct qca_vreg vregs,
+				  struct regulator *regulator)
+{
+	/* Disable the regulator if requested by user
+	 * or when fault to enable any regulator.
+	 */

This comment is not useful. The following code simply disables the regulator, why this is done is a question of the caller.

[Bala]: will update.

Quoted 25 lines
Quoted 25 lines
drivers/bluetooth/hci_qca.c +25 -0
+	regulator_disable(regulator);
+	regulator_set_voltage(regulator, 0, vregs.max_uV);
+	if (vregs.load_uA)
+		regulator_set_load(regulator, 0);
+
+}
+
+int qca_btsoc_power_setup(struct hci_uart *hu, bool on)
+{
+	struct qca_vreg *vregs;
+	struct regulator_bulk_data *vreg_bulk;
+	struct qca_serdev *qcadev;
+	int i, num_vregs, ret = 0;
+
+	qcadev = serdev_device_get_drvdata(hu->serdev);
+	if (!qcadev || !qcadev->bt_power || !qcadev->bt_power->vreg_data ||
+	    !qcadev->bt_power->vreg_bulk)
+		return -EINVAL;
+
+	vregs = qcadev->bt_power->vreg_data->vregs;
+	vreg_bulk = qcadev->bt_power->vreg_bulk;
+	num_vregs = qcadev->bt_power->vreg_data->num_vregs;
+	BT_DBG("on: %d", on);
+	if (on  && !qcadev->bt_power->vregs_on) {
+		for (i = 0; i < num_vregs; i++) {
Quoted 8 lines

drivers/bluetooth/hci_qca.c static struct hci_uart_proto qca_proto = { · line 1255

Quoted 6 lines
drivers/bluetooth/hci_qca.c +6 -0
+			ret = qca_enable_regulator(vregs[i],
+						   vreg_bulk[i].consumer);
+			if (ret)
+				break;
+		}
+		/* regulators failed */

Comment is not useful, BT_ERR below leaves things clear.

[Bala]: will update.

Quoted 67 lines
Quoted 67 lines
drivers/bluetooth/hci_qca.c +54 -0
+		if (ret) {
+			BT_ERR("failed to enable regulator:%s", vregs[i].name);
+			/* turn off regulators which are enabled */
+			for (i = i - 1; i >= 0; i--)
+				qca_disable_regulator(vregs[i],
+						      vreg_bulk[i].consumer);
+		} else {
+			qcadev->bt_power->vregs_on = true;
+		}
+	} else if (!on && qcadev->bt_power->vregs_on) {
+		/* turn off regulator in reverse order */
+		i = qcadev->bt_power->vreg_data->num_vregs - 1;
+		for ( ; i >= 0; i--)
+			qca_disable_regulator(vregs[i], vreg_bulk[i].consumer);
+		qcadev->bt_power->vregs_on = false;
+	}
+
+	return ret;
+}
+
+static int qca_init_regulators(struct qca_power *qca,
+			       const struct qca_vreg *vregs, size_t num_vregs)
+{
+	int i;
+
+	qca->vreg_bulk = devm_kzalloc(qca->dev, num_vregs *
+				      sizeof(struct regulator_bulk_data),
+				      GFP_KERNEL);
+	if (!qca->vreg_bulk)
+		return -ENOMEM;
+
+	for (i = 0; i < num_vregs; i++)
+		qca->vreg_bulk[i].supply = vregs[i].name;
+
+	return devm_regulator_bulk_get(qca->dev, num_vregs, qca->vreg_bulk);
+}
+
 static int qca_serdev_probe(struct serdev_device *serdev)
 {
 	struct qca_serdev *qcadev;
+	const struct qca_vreg_data *data;
 	int err;
 
 	qcadev = devm_kzalloc(&serdev->dev, sizeof(*qcadev), GFP_KERNEL);
@@ -1014,34 +1301,72 @@ static int qca_serdev_probe(struct 
 serdev_device *serdev)
 		return -ENOMEM;
 
 	qcadev->serdev_hu.serdev = serdev;
+	data = of_device_get_match_data(&serdev->dev);
+	if (data && data->soc_type == BTQCA_CHEROKEE)
+		qcadev->btsoc_type = BTQCA_CHEROKEE;
+	else
+		qcadev->btsoc_type = BTQCA_ROME;
+
 	serdev_device_set_drvdata(serdev, qcadev);
+	if (qcadev->btsoc_type == BTQCA_CHEROKEE) {
+		qcadev->bt_power = devm_kzalloc(&serdev->dev,
+						sizeof(struct qca_power),
+						GFP_KERNEL);
+		if (!qcadev->bt_power)
+			return -ENOMEM;
+
+		qcadev->bt_power->dev = &serdev->dev;
+		qcadev->bt_power->vreg_data = data;
+		err = qca_init_regulators(qcadev->bt_power, data->vregs,
Quoted 8 lines

drivers/bluetooth/hci_qca.c static int qca_serdev_probe(struct serdev_device *serdev) · line 1325

Quoted 5 lines
drivers/bluetooth/hci_qca.c +5 -0
+					  data->num_vregs);
+		if (err) {
+			BT_ERR("Failed to init regulators:%d", err);
+			devm_kfree(&serdev->dev, qcadev->bt_power->vreg_bulk);
+			devm_kfree(&serdev->dev, qcadev->bt_power);

Not necessary, the memory is allocated with devm_kzalloc(&serdev->dev, ...), therefore it is freed if probe() fails.

[Bala]: will update.

Quoted 14 lines
Quoted 14 lines
drivers/bluetooth/hci_qca.c +6 -6
+			goto out;
+		}
 
-	qcadev->bt_en = devm_gpiod_get(&serdev->dev, "enable",
-				       GPIOD_OUT_LOW);
-	if (IS_ERR(qcadev->bt_en)) {
-		dev_err(&serdev->dev, "failed to acquire enable gpio\n");
-		return PTR_ERR(qcadev->bt_en);
-	}
+		qcadev->bt_power->vregs_on = false;
+		device_property_read_u32(&serdev->dev, "max-speed",
+					 &qcadev->oper_speed);
+		if (!qcadev->oper_speed)
Quoted 8 lines

drivers/bluetooth/hci_qca.c static int qca_serdev_probe(struct serdev_device *serdev) · line 1338

Quoted 6 lines
drivers/bluetooth/hci_qca.c +6 -0
+			BT_INFO("UART will pick default operating speed");
+		err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto);
+		if (err) {
+			BT_ERR("wcn3990 serdev registration failed");
+			devm_kfree(&serdev->dev, qcadev->bt_power->vreg_bulk);
+			devm_kfree(&serdev->dev, qcadev->bt_power);

no need to free memory.

[Bala]: will update.

Quoted 53 lines
Quoted 53 lines
drivers/bluetooth/hci_qca.c +26 -15
+			goto out;
+		}
+	} else {
+		qcadev->bt_en = devm_gpiod_get(&serdev->dev, "enable",
+					       GPIOD_OUT_LOW);
+		if (IS_ERR(qcadev->bt_en)) {
+			dev_err(&serdev->dev, "failed to acquire enable gpio\n");
+			return PTR_ERR(qcadev->bt_en);
+		}
 
-	qcadev->susclk = devm_clk_get(&serdev->dev, NULL);
-	if (IS_ERR(qcadev->susclk)) {
-		dev_err(&serdev->dev, "failed to acquire clk\n");
-		return PTR_ERR(qcadev->susclk);
-	}
+		qcadev->susclk = devm_clk_get(&serdev->dev, NULL);
+		if (IS_ERR(qcadev->susclk)) {
+			dev_err(&serdev->dev, "failed to acquire clk\n");
+			return PTR_ERR(qcadev->susclk);
+		}
 
-	err = clk_set_rate(qcadev->susclk, SUSCLK_RATE_32KHZ);
-	if (err)
-		return err;
+		err = clk_set_rate(qcadev->susclk, SUSCLK_RATE_32KHZ);
+		if (err)
+			return err;
 
-	err = clk_prepare_enable(qcadev->susclk);
-	if (err)
-		return err;
+		err = clk_prepare_enable(qcadev->susclk);
+		if (err)
+			return err;
 
-	err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto);
-	if (err)
-		clk_disable_unprepare(qcadev->susclk);
+		err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto);
+		if (err)
+			clk_disable_unprepare(qcadev->susclk);
+	}
+
+out:	return err;
 
-	return err;
 }
 

static void qca_serdev_remove(struct serdev_device *serdev)

drivers/bluetooth/hci_qca.c +0 -0
@@ -1050,11 +1375,17 @@ static void qca_serdev_remove(struct 
 serdev_device *serdev)
 
Quoted 8 lines

drivers/bluetooth/hci_qca.c static void qca_serdev_remove(struct serdev_device *serdev) · line 1380

Quoted 6 lines
drivers/bluetooth/hci_qca.c +3 -1
 	hci_uart_unregister_device(&qcadev->serdev_hu);
 
-	clk_disable_unprepare(qcadev->susclk);
+	if (qcadev->btsoc_type == BTQCA_CHEROKEE) {
+		devm_kfree(&serdev->dev, qcadev->bt_power->vreg_bulk);
+		devm_kfree(&serdev->dev, qcadev->bt_power);

no need to free memory

[Bala]: will update.

Thanks for reviewing will update the about comments in next patch set.

Signature · 2 lines
Regards
Balakrishna.