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 v4:
- Fix incorrect function name in hci_bcm
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 | 69 ++++++++++++++++++-
4 files changed, 105 insertions(+), 1 deletion(-)
--
2.24.0.rc1.363.gb1bccd3e3d-goog
Without updating the patchram, the BCM4354 does not support a higher
operating speed. The normal bcm_setup follows the correct order
(init_speed, patchram and then oper_speed) but the serdev driver will
set the operating speed before calling the hu->setup function. Thus,
for the BCM4354, disallow setting the operating speed before patchram.
If set_baudrate is called before setup, it will return -EBUSY.
Signed-off-by: Abhishek Pandit-Subedi <[email protected]>
---
Changes in v4: None
Changes in v3: None
Changes in v2: None
drivers/bluetooth/hci_bcm.c | 37 ++++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
index 0f851c0dde7f..6134bff58748 100644
--- a/drivers/bluetooth/hci_bcm.c
+++ b/drivers/bluetooth/hci_bcm.c
@@ -47,6 +47,14 @@
#define BCM_NUM_SUPPLIES 2
+/**
+ * struct bcm_device_data - device specific data
+ * @no_early_set_baudrate: Disallow set baudrate before driver setup()
+ */
+struct bcm_device_data {
+ bool no_early_set_baudrate;
+};
+
/**
* struct bcm_device - device driver resources
* @serdev_hu: HCI UART controller struct
@@ -79,6 +87,7 @@
* @hu: pointer to HCI UART controller struct,
* 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
*/
struct bcm_device {
/* Must be the first member, hci_serdev.c expects this. */
@@ -112,6 +121,7 @@ struct bcm_device {
struct hci_uart *hu;
bool is_suspended;
#endif
+ bool disallow_set_baudrate;
};
/* generic bcm uart resources */
@@ -141,9 +151,13 @@ static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed)
static int bcm_set_baudrate(struct hci_uart *hu, unsigned int speed)
{
struct hci_dev *hdev = hu->hdev;
+ struct bcm_data *bcm = hu->priv;
struct sk_buff *skb;
struct bcm_update_uart_baud_rate param;
+ if (bcm && bcm->dev && bcm->dev->disallow_set_baudrate)
+ return -EBUSY;
+
if (speed > 3000000) {
struct bcm_write_uart_clock_setting clock;
@@ -551,6 +565,12 @@ static int bcm_setup(struct hci_uart *hu)
goto finalize;
}
+ /* If we disallow early set baudrate, we can re-enable it now that
+ * patchram is done
+ */
+ if (bcm->dev && bcm->dev->disallow_set_baudrate)
+ bcm->dev->disallow_set_baudrate = false;
+
/* Init speed if any */
if (hu->init_speed)
speed = hu->init_speed;
@@ -1371,6 +1391,15 @@ static struct platform_driver bcm_driver = {
},
};
+static void bcm_configure_device_data(struct bcm_device *bdev)
+{
+ const struct bcm_device_data *data = device_get_match_data(bdev->dev);
+
+ if (data) {
+ bdev->disallow_set_baudrate = data->no_early_set_baudrate;
+ }
+}
+
static int bcm_serdev_probe(struct serdev_device *serdev)
{
struct bcm_device *bcmdev;
@@ -1408,6 +1437,8 @@ static int bcm_serdev_probe(struct serdev_device *serdev)
if (err)
dev_err(&serdev->dev, "Failed to power down\n");
+ bcm_configure_device_data(bcmdev);
+
return hci_uart_register_device(&bcmdev->serdev_hu, &bcm_proto);
}
@@ -1419,12 +1450,16 @@ static void bcm_serdev_remove(struct serdev_device *serdev)
}
#ifdef CONFIG_OF
+struct bcm_device_data bcm4354_device_data = {
+ .no_early_set_baudrate = true,
+};
+
static const struct of_device_id bcm_bluetooth_of_match[] = {
{ .compatible = "brcm,bcm20702a1" },
{ .compatible = "brcm,bcm4345c5" },
{ .compatible = "brcm,bcm4330-bt" },
{ .compatible = "brcm,bcm43438-bt" },
- { .compatible = "brcm,bcm43540-bt" },
+ { .compatible = "brcm,bcm43540-bt", .data = &bcm4354_device_data },
{ },
};
MODULE_DEVICE_TABLE(of, bcm_bluetooth_of_match);
--
2.24.0.rc1.363.gb1bccd3e3d-goog
Add documentation for pcm parameters.
Signed-off-by: Abhishek Pandit-Subedi <[email protected]>
---
Changes in v4:
- Fix incorrect function name in hci_bcm
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
.../devicetree/bindings/net/broadcom-bluetooth.txt | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt b/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt
index c749dc297624..42fb2fa8143d 100644
--- a/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt
+++ b/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt
@@ -29,6 +29,11 @@ Optional properties:
- "lpo": external low power 32.768 kHz clock
- vbat-supply: phandle to regulator supply for VBAT
- vddio-supply: phandle to regulator supply for VDDIO
+ - brcm,bt-sco-routing: 0-3 (PCM, Transport, Codec, I2S)
+ - brcm,pcm-interface-rate: 0-4 (128KBps, 256KBps, 512KBps, 1024KBps, 2048KBps)
+ - brcm,pcm-frame-type: 0-1 (short, long)
+ - brcm,pcm-sync-mode: 0-1 (slave, master)
+ - brcm,pcm-clock-mode: 0-1 (slave, master)
Example:
@@ -40,5 +45,11 @@ Example:
bluetooth {
compatible = "brcm,bcm43438-bt";
max-speed = <921600>;
+
+ brcm,bt-sco-routing = [01];
+ brcm,pcm-interface-rate = [02];
+ brcm,pcm-frame-type = [00];
+ brcm,pcm-sync-mode = [01];
+ brcm,pcm-clock-mode = [01];
};
};
--
2.24.0.rc1.363.gb1bccd3e3d-goog
Hi Abhishek,
> Without updating the patchram, the BCM4354 does not support a higher
> operating speed. The normal bcm_setup follows the correct order
> (init_speed, patchram and then oper_speed) but the serdev driver will
> set the operating speed before calling the hu->setup function. Thus,
> for the BCM4354, disallow setting the operating speed before patchram.
> If set_baudrate is called before setup, it will return -EBUSY.
>
> Signed-off-by: Abhishek Pandit-Subedi <[email protected]>
> ---
>
> Changes in v4: None
> Changes in v3: None
> Changes in v2: None
>
> drivers/bluetooth/hci_bcm.c | 37 ++++++++++++++++++++++++++++++++++++-
> 1 file changed, 36 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
> index 0f851c0dde7f..6134bff58748 100644
> --- a/drivers/bluetooth/hci_bcm.c
> +++ b/drivers/bluetooth/hci_bcm.c
> @@ -47,6 +47,14 @@
>
> #define BCM_NUM_SUPPLIES 2
>
> +/**
> + * struct bcm_device_data - device specific data
> + * @no_early_set_baudrate: Disallow set baudrate before driver setup()
> + */
> +struct bcm_device_data {
> + bool no_early_set_baudrate;
> +};
> +
> /**
> * struct bcm_device - device driver resources
> * @serdev_hu: HCI UART controller struct
> @@ -79,6 +87,7 @@
> * @hu: pointer to HCI UART controller struct,
> * 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
> */
> struct bcm_device {
> /* Must be the first member, hci_serdev.c expects this. */
> @@ -112,6 +121,7 @@ struct bcm_device {
> struct hci_uart *hu;
> bool is_suspended;
> #endif
> + bool disallow_set_baudrate;
> };
call it no_early_set_baudrate here as well.
>
> /* generic bcm uart resources */
> @@ -141,9 +151,13 @@ static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed)
> static int bcm_set_baudrate(struct hci_uart *hu, unsigned int speed)
> {
> struct hci_dev *hdev = hu->hdev;
> + struct bcm_data *bcm = hu->priv;
> struct sk_buff *skb;
> struct bcm_update_uart_baud_rate param;
>
> + if (bcm && bcm->dev && bcm->dev->disallow_set_baudrate)
> + return -EBUSY;
> +
> if (speed > 3000000) {
> struct bcm_write_uart_clock_setting clock;
>
> @@ -551,6 +565,12 @@ static int bcm_setup(struct hci_uart *hu)
> goto finalize;
> }
>
> + /* If we disallow early set baudrate, we can re-enable it now that
> + * patchram is done
> + */
> + if (bcm->dev && bcm->dev->disallow_set_baudrate)
> + bcm->dev->disallow_set_baudrate = false;
> +
Lets not hack a different behavior of bcm_set_baudrate that magically changes based on a bool.
Actually wouldn’t be setting hu->oper_speed to 0 have the same affect and bcm_set_baudrate will not be called after setting the init speed. We should be ensuring that in the case where we do not want the baudrate change before calling ->setup() is somehow covered in hci_ldisc directly and not hacked into the ->set_baudrate callback.
> /* Init speed if any */
> if (hu->init_speed)
> speed = hu->init_speed;
> @@ -1371,6 +1391,15 @@ static struct platform_driver bcm_driver = {
> },
> };
>
> +static void bcm_configure_device_data(struct bcm_device *bdev)
> +{
> + const struct bcm_device_data *data = device_get_match_data(bdev->dev);
> +
> + if (data) {
> + bdev->disallow_set_baudrate = data->no_early_set_baudrate;
> + }
> +}
> +
> static int bcm_serdev_probe(struct serdev_device *serdev)
> {
> struct bcm_device *bcmdev;
> @@ -1408,6 +1437,8 @@ static int bcm_serdev_probe(struct serdev_device *serdev)
> if (err)
> dev_err(&serdev->dev, "Failed to power down\n");
>
> + bcm_configure_device_data(bcmdev);
> +
I would not split this out into a separate function. Lets do this in probe() right here.
> return hci_uart_register_device(&bcmdev->serdev_hu, &bcm_proto);
> }
>
> @@ -1419,12 +1450,16 @@ static void bcm_serdev_remove(struct serdev_device *serdev)
> }
>
> #ifdef CONFIG_OF
> +struct bcm_device_data bcm4354_device_data = {
> + .no_early_set_baudrate = true,
> +};
> +
> static const struct of_device_id bcm_bluetooth_of_match[] = {
> { .compatible = "brcm,bcm20702a1" },
> { .compatible = "brcm,bcm4345c5" },
> { .compatible = "brcm,bcm4330-bt" },
> { .compatible = "brcm,bcm43438-bt" },
> - { .compatible = "brcm,bcm43540-bt" },
> + { .compatible = "brcm,bcm43540-bt", .data = &bcm4354_device_data },
> { },
> };
> MODULE_DEVICE_TABLE(of, bcm_bluetooth_of_match);
Regards
Marcel
On Wed, Nov 13, 2019 at 01:21:06AM +0100, Marcel Holtmann wrote:
> Hi Abhishek,
>
> > Add documentation for pcm parameters.
> >
> > Signed-off-by: Abhishek Pandit-Subedi <[email protected]>
> >
> > ---
> >
> > Changes in v4:
> > - Fix incorrect function name in hci_bcm
> >
> > 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
> >
> > .../devicetree/bindings/net/broadcom-bluetooth.txt | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt b/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt
> > index c749dc297624..42fb2fa8143d 100644
> > --- a/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt
> > +++ b/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt
> > @@ -29,6 +29,11 @@ Optional properties:
> > - "lpo": external low power 32.768 kHz clock
> > - vbat-supply: phandle to regulator supply for VBAT
> > - vddio-supply: phandle to regulator supply for VDDIO
> > + - brcm,bt-sco-routing: 0-3 (PCM, Transport, Codec, I2S)
> > + - brcm,pcm-interface-rate: 0-4 (128KBps, 256KBps, 512KBps, 1024KBps, 2048KBps)
> > + - brcm,pcm-frame-type: 0-1 (short, long)
> > + - brcm,pcm-sync-mode: 0-1 (slave, master)
> > + - brcm,pcm-clock-mode: 0-1 (slave, master)
>
> I think that all of them need to start with brcm,bt- prefix since it is rather Bluetooth specific.
>
> >
> >
> > Example:
> > @@ -40,5 +45,11 @@ Example:
> > bluetooth {
> > compatible = "brcm,bcm43438-bt";
> > max-speed = <921600>;
> > +
> > + brcm,bt-sco-routing = [01];
> > + brcm,pcm-interface-rate = [02];
> > + brcm,pcm-frame-type = [00];
> > + brcm,pcm-sync-mode = [01];
> > + brcm,pcm-clock-mode = [01];
> > };
>
> My personal taste would be to add a comment after each entry that gives the human readable setting.
I'd suggest to define constants in include/dt-bindings/bluetooth/brcm.h
and use them instead of literals, with this we wouldn't rely on (optional)
comments to make the configuration human readable.
On Thu, Nov 14, 2019 at 9:29 AM Doug Anderson <[email protected]> wrote:
>
> Hi,
>
> On Tue, Nov 12, 2019 at 3:10 PM Abhishek Pandit-Subedi
> <[email protected]> wrote:
> >
> > Add documentation for pcm parameters.
> >
> > Signed-off-by: Abhishek Pandit-Subedi <[email protected]>
> >
> > ---
> >
> > Changes in v4:
> > - Fix incorrect function name in hci_bcm
> >
> > 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
> >
> > .../devicetree/bindings/net/broadcom-bluetooth.txt | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt b/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt
> > index c749dc297624..42fb2fa8143d 100644
> > --- a/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt
> > +++ b/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt
> > @@ -29,6 +29,11 @@ Optional properties:
> > - "lpo": external low power 32.768 kHz clock
> > - vbat-supply: phandle to regulator supply for VBAT
> > - vddio-supply: phandle to regulator supply for VDDIO
> > + - brcm,bt-sco-routing: 0-3 (PCM, Transport, Codec, I2S)
> > + - brcm,pcm-interface-rate: 0-4 (128KBps, 256KBps, 512KBps, 1024KBps, 2048KBps)
> > + - brcm,pcm-frame-type: 0-1 (short, long)
> > + - brcm,pcm-sync-mode: 0-1 (slave, master)
> > + - brcm,pcm-clock-mode: 0-1 (slave, master)
>
> Since these are optional your patch should describe what happens if
> they are not present. I think in patch #3 of the series you guys are
> discussing it, but whatever you end up with should be documented here.
>
Yes, I think I will document the default values here as well.
> That actually made me realize that this is patch #4 in the series. To
> be pedantic, bindings are supposed to be _earlier_ in the series than
> the code that implements them.
>
>
> > Example:
> > @@ -40,5 +45,11 @@ Example:
> > bluetooth {
> > compatible = "brcm,bcm43438-bt";
> > max-speed = <921600>;
> > +
> > + brcm,bt-sco-routing = [01];
> > + brcm,pcm-interface-rate = [02];
> > + brcm,pcm-frame-type = [00];
> > + brcm,pcm-sync-mode = [01];
> > + brcm,pcm-clock-mode = [01];
>
> I'm at least marginally curious why your example has a leading 0 for
> all numbers. It makes me think you intend them to be represented in
> octal, though I don't know offhand if dtc uses that format for octal.
> I guess it doesn't matter since all your numbers are between 0 and 5,
> but it does seem strange.
It's a bytestring with a length of 1. See bytestrings under
https://devicetree-specification.readthedocs.io/en/latest/source-language.html#node-and-property-definitions
>
> -Doug
On Thu, Nov 14, 2019 at 9:58 AM Matthias Kaehlcke <[email protected]> wrote:
>
> On Wed, Nov 13, 2019 at 01:21:06AM +0100, Marcel Holtmann wrote:
> > Hi Abhishek,
> >
> > > Add documentation for pcm parameters.
> > >
> > > Signed-off-by: Abhishek Pandit-Subedi <[email protected]>
> > >
> > > ---
> > >
> > > Changes in v4:
> > > - Fix incorrect function name in hci_bcm
> > >
> > > 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
> > >
> > > .../devicetree/bindings/net/broadcom-bluetooth.txt | 11 +++++++++++
> > > 1 file changed, 11 insertions(+)
> > >
> > > diff --git a/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt b/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt
> > > index c749dc297624..42fb2fa8143d 100644
> > > --- a/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt
> > > +++ b/Documentation/devicetree/bindings/net/broadcom-bluetooth.txt
> > > @@ -29,6 +29,11 @@ Optional properties:
> > > - "lpo": external low power 32.768 kHz clock
> > > - vbat-supply: phandle to regulator supply for VBAT
> > > - vddio-supply: phandle to regulator supply for VDDIO
> > > + - brcm,bt-sco-routing: 0-3 (PCM, Transport, Codec, I2S)
> > > + - brcm,pcm-interface-rate: 0-4 (128KBps, 256KBps, 512KBps, 1024KBps, 2048KBps)
> > > + - brcm,pcm-frame-type: 0-1 (short, long)
> > > + - brcm,pcm-sync-mode: 0-1 (slave, master)
> > > + - brcm,pcm-clock-mode: 0-1 (slave, master)
> >
> > I think that all of them need to start with brcm,bt- prefix since it is rather Bluetooth specific.
> >
> > >
> > >
> > > Example:
> > > @@ -40,5 +45,11 @@ Example:
> > > bluetooth {
> > > compatible = "brcm,bcm43438-bt";
> > > max-speed = <921600>;
> > > +
> > > + brcm,bt-sco-routing = [01];
> > > + brcm,pcm-interface-rate = [02];
> > > + brcm,pcm-frame-type = [00];
> > > + brcm,pcm-sync-mode = [01];
> > > + brcm,pcm-clock-mode = [01];
> > > };
> >
> > My personal taste would be to add a comment after each entry that gives the human readable setting.
>
> I'd suggest to define constants in include/dt-bindings/bluetooth/brcm.h
> and use them instead of literals, with this we wouldn't rely on (optional)
> comments to make the configuration human readable.
:+1: Sounds like a good idea; expect it in next patch revision