While adding support for the BCM4354, I discovered a few more things
that weren't working as they should have.
First, we disallow serdev from setting the baudrate on BCM4354. Serdev
sets the oper_speed first before calling hu->setup() in
hci_uart_setup(). On the BCM4354, this results in bcm_setup() failing
when the hci reset times out.
Next, we add support for setting the PCM parameters, which consists of
a pair of vendor specific opcodes to set the pcm parameters. The
documentation for these params are available in the brcm_patchram_plus
package (i.e. https://github.com/balena-os/brcm_patchram_plus). This is
necessary for PCM to work properly.
All changes were tested with rk3288-veyron-minnie.dts.
Changes in v3:
- Change disallow baudrate setting to return -EBUSY if called before
ready. bcm_proto is no longer modified and is back to being const.
- Changed btbcm_set_pcm_params to btbcm_set_pcm_int_params
- Changed brcm,sco-routing to brcm,bt-sco-routing
Changes in v2:
- Use match data to disallow baudrate setting
- Parse pcm parameters by name instead of as a byte string
- Fix prefix for dt-bindings commit
Abhishek Pandit-Subedi (4):
Bluetooth: hci_bcm: Disallow set_baudrate for BCM4354
Bluetooth: btbcm: Support pcm configuration
Bluetooth: hci_bcm: Support pcm params in dts
dt-bindings: net: broadcom-bluetooth: Add pcm config
.../bindings/net/broadcom-bluetooth.txt | 11 +++
drivers/bluetooth/btbcm.c | 18 +++++
drivers/bluetooth/btbcm.h | 8 +++
drivers/bluetooth/hci_bcm.c | 70 ++++++++++++++++++-
4 files changed, 106 insertions(+), 1 deletion(-)
--
2.24.0.rc1.363.gb1bccd3e3d-goog
Add BCM vendor specific command to configure PCM parameters. The new
vendor opcode allows us to set the sco routing, the pcm interface rate,
and a few other pcm specific options (frame sync, sync mode, and clock
mode). See broadcom-bluetooth.txt in Documentation for more information
about valid values for those settings.
Here is an example trace where this opcode was used to configure
a BCM4354:
< HCI Command: Vendor (0x3f|0x001c) plen 5
01 02 00 01 01
> HCI Event: Command Complete (0x0e) plen 4
Vendor (0x3f|0x001c) ncmd 1
Status: Success (0x00)
Signed-off-by: Abhishek Pandit-Subedi <[email protected]>
---
Changes in v3: None
Changes in v2: None
drivers/bluetooth/btbcm.c | 18 ++++++++++++++++++
drivers/bluetooth/btbcm.h | 8 ++++++++
2 files changed, 26 insertions(+)
diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c
index 2d2e6d862068..d22a2025f7e1 100644
--- a/drivers/bluetooth/btbcm.c
+++ b/drivers/bluetooth/btbcm.c
@@ -105,6 +105,24 @@ int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
}
EXPORT_SYMBOL_GPL(btbcm_set_bdaddr);
+int btbcm_set_pcm_int_params(struct hci_dev *hdev,
+ const struct bcm_set_pcm_int_params *int_params)
+{
+ struct sk_buff *skb;
+ int err;
+
+ skb = __hci_cmd_sync(hdev, 0xfc1c, 5, int_params, HCI_INIT_TIMEOUT);
+ if (IS_ERR(skb)) {
+ err = PTR_ERR(skb);
+ bt_dev_err(hdev, "BCM: Set PCM int params failed (%d)", err);
+ return err;
+ }
+ kfree_skb(skb);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(btbcm_set_pcm_int_params);
+
int btbcm_patchram(struct hci_dev *hdev, const struct firmware *fw)
{
const struct hci_command_hdr *cmd;
diff --git a/drivers/bluetooth/btbcm.h b/drivers/bluetooth/btbcm.h
index d204be8a84bf..bf9d86924787 100644
--- a/drivers/bluetooth/btbcm.h
+++ b/drivers/bluetooth/btbcm.h
@@ -54,6 +54,8 @@ struct bcm_set_pcm_format_params {
int btbcm_check_bdaddr(struct hci_dev *hdev);
int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr);
int btbcm_patchram(struct hci_dev *hdev, const struct firmware *fw);
+int btbcm_set_pcm_int_params(struct hci_dev *hdev,
+ const struct bcm_set_pcm_int_params *int_params);
int btbcm_setup_patchram(struct hci_dev *hdev);
int btbcm_setup_apple(struct hci_dev *hdev);
@@ -74,6 +76,12 @@ static inline int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
return -EOPNOTSUPP;
}
+int btbcm_set_pcm_int_params(struct hci_dev *hdev,
+ const struct bcm_set_pcm_int_params *int_params)
+{
+ return -EOPNOTSUPP;
+}
+
static inline int btbcm_patchram(struct hci_dev *hdev, const struct firmware *fw)
{
return -EOPNOTSUPP;
--
2.24.0.rc1.363.gb1bccd3e3d-goog
BCM chips may require configuration of PCM to operate correctly and
there is a vendor specific HCI command to do this. Add support in the
hci_bcm driver to parse this from devicetree and configure the chip.
Signed-off-by: Abhishek Pandit-Subedi <[email protected]>
---
Changes in v3: None
Changes in v2: None
drivers/bluetooth/hci_bcm.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
index 6134bff58748..b7f47d9edb7d 100644
--- a/drivers/bluetooth/hci_bcm.c
+++ b/drivers/bluetooth/hci_bcm.c
@@ -88,6 +88,8 @@ struct bcm_device_data {
* used to disable flow control during runtime suspend and system sleep
* @is_suspended: whether flow control is currently disabled
* @disallow_set_baudrate: don't allow set_baudrate
+ * @has_pcm_params: whether PCM parameters need to be configured
+ * @pcm_params: PCM and routing parameters
*/
struct bcm_device {
/* Must be the first member, hci_serdev.c expects this. */
@@ -122,6 +124,9 @@ struct bcm_device {
bool is_suspended;
#endif
bool disallow_set_baudrate;
+
+ bool has_pcm_params;
+ struct bcm_set_pcm_int_params pcm_params;
};
/* generic bcm uart resources */
@@ -596,6 +601,17 @@ static int bcm_setup(struct hci_uart *hu)
host_set_baudrate(hu, speed);
}
+ /* PCM parameters if any*/
+ if (bcm->dev && bcm->dev->has_pcm_params) {
+ err = btbcm_set_pcm_params(hu->hdev, &bcm->dev->pcm_params,
+ NULL);
+
+ if (err) {
+ bt_dev_info(hu->hdev, "BCM: Set pcm params failed (%d)",
+ err);
+ }
+ }
+
finalize:
release_firmware(fw);
@@ -1132,7 +1148,24 @@ static int bcm_acpi_probe(struct bcm_device *dev)
static int bcm_of_probe(struct bcm_device *bdev)
{
+ int err;
+
device_property_read_u32(bdev->dev, "max-speed", &bdev->oper_speed);
+
+ err = device_property_read_u8(bdev->dev, "brcm,bt-sco-routing",
+ &bdev->pcm_params.routing);
+ if (!err)
+ bdev->has_pcm_params = true;
+
+ device_property_read_u8(bdev->dev, "brcm,pcm-interface-rate",
+ &bdev->pcm_params.rate);
+ device_property_read_u8(bdev->dev, "brcm,pcm-frame-type",
+ &bdev->pcm_params.frame_sync);
+ device_property_read_u8(bdev->dev, "brcm,pcm-sync-mode",
+ &bdev->pcm_params.sync_mode);
+ device_property_read_u8(bdev->dev, "brcm,pcm-clock-mode",
+ &bdev->pcm_params.clock_mode);
+
return 0;
}
--
2.24.0.rc1.363.gb1bccd3e3d-goog
Hi Abhishek,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on bluetooth-next/master]
[cannot apply to v5.4-rc7 next-20191112]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Abhishek-Pandit-Subedi/Bluetooth-hci_bcm-Additional-changes-for-BCM4354-support/20191113-053047
base: https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: sparc64-allmodconfig (attached as .config)
compiler: sparc64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=sparc64
If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <[email protected]>
All errors (new ones prefixed by >>):
drivers/bluetooth/hci_bcm.c: In function 'bcm_setup':
>> drivers/bluetooth/hci_bcm.c:606:9: error: implicit declaration of function 'btbcm_set_pcm_params'; did you mean 'btbcm_set_pcm_int_params'? [-Werror=implicit-function-declaration]
err = btbcm_set_pcm_params(hu->hdev, &bcm->dev->pcm_params,
^~~~~~~~~~~~~~~~~~~~
btbcm_set_pcm_int_params
cc1: some warnings being treated as errors
vim +606 drivers/bluetooth/hci_bcm.c
543
544 static int bcm_setup(struct hci_uart *hu)
545 {
546 struct bcm_data *bcm = hu->priv;
547 char fw_name[64];
548 const struct firmware *fw;
549 unsigned int speed;
550 int err;
551
552 bt_dev_dbg(hu->hdev, "hu %p", hu);
553
554 hu->hdev->set_diag = bcm_set_diag;
555 hu->hdev->set_bdaddr = btbcm_set_bdaddr;
556
557 err = btbcm_initialize(hu->hdev, fw_name, sizeof(fw_name), false);
558 if (err)
559 return err;
560
561 err = request_firmware(&fw, fw_name, &hu->hdev->dev);
562 if (err < 0) {
563 bt_dev_info(hu->hdev, "BCM: Patch %s not found", fw_name);
564 return 0;
565 }
566
567 err = btbcm_patchram(hu->hdev, fw);
568 if (err) {
569 bt_dev_info(hu->hdev, "BCM: Patch failed (%d)", err);
570 goto finalize;
571 }
572
573 /* If we disallow early set baudrate, we can re-enable it now that
574 * patchram is done
575 */
576 if (bcm->dev && bcm->dev->disallow_set_baudrate)
577 bcm->dev->disallow_set_baudrate = false;
578
579 /* Init speed if any */
580 if (hu->init_speed)
581 speed = hu->init_speed;
582 else if (hu->proto->init_speed)
583 speed = hu->proto->init_speed;
584 else
585 speed = 0;
586
587 if (speed)
588 host_set_baudrate(hu, speed);
589
590 /* Operational speed if any */
591 if (hu->oper_speed)
592 speed = hu->oper_speed;
593 else if (hu->proto->oper_speed)
594 speed = hu->proto->oper_speed;
595 else
596 speed = 0;
597
598 if (speed) {
599 err = bcm_set_baudrate(hu, speed);
600 if (!err)
601 host_set_baudrate(hu, speed);
602 }
603
604 /* PCM parameters if any*/
605 if (bcm->dev && bcm->dev->has_pcm_params) {
> 606 err = btbcm_set_pcm_params(hu->hdev, &bcm->dev->pcm_params,
607 NULL);
608
609 if (err) {
610 bt_dev_info(hu->hdev, "BCM: Set pcm params failed (%d)",
611 err);
612 }
613 }
614
615 finalize:
616 release_firmware(fw);
617
618 err = btbcm_finalize(hu->hdev);
619 if (err)
620 return err;
621
622 if (!bcm_request_irq(bcm))
623 err = bcm_setup_sleep(hu);
624
625 return err;
626 }
627
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/[email protected] Intel Corporation