linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/4] Bluetooth: hci_bcm: Disallow set_baudrate for BCM4354
@ 2019-11-26  7:17 Marcel Holtmann
  2019-11-27  7:11 ` Johan Hedberg
  0 siblings, 1 reply; 4+ messages in thread
From: Marcel Holtmann @ 2019-11-26  7:17 UTC (permalink / raw)
  To: linux-bluetooth

From: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>

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, don't set the operating speed before patchram.

Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 drivers/bluetooth/hci_bcm.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
index d2a6a4afdbbb..0200eff12bc9 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
+ * @no_early_set_baudrate: don't set_baudrate before setup()
  */
 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			no_early_set_baudrate;
 };
 
 /* generic bcm uart resources */
@@ -447,7 +457,13 @@ static int bcm_open(struct hci_uart *hu)
 	if (bcm->dev) {
 		hci_uart_set_flow_control(hu, true);
 		hu->init_speed = bcm->dev->init_speed;
-		hu->oper_speed = bcm->dev->oper_speed;
+
+		/* If oper_speed is set, ldisc/serdev will set the baudrate
+		 * before calling setup()
+		 */
+		if (!bcm->dev->no_early_set_baudrate)
+			hu->oper_speed = bcm->dev->oper_speed;
+
 		err = bcm_gpio_set_power(bcm->dev, true);
 		hci_uart_set_flow_control(hu, false);
 		if (err)
@@ -565,6 +581,8 @@ static int bcm_setup(struct hci_uart *hu)
 	/* Operational speed if any */
 	if (hu->oper_speed)
 		speed = hu->oper_speed;
+	else if (bcm->dev && bcm->dev->oper_speed)
+		speed = bcm->dev->oper_speed;
 	else if (hu->proto->oper_speed)
 		speed = hu->proto->oper_speed;
 	else
@@ -1374,6 +1392,7 @@ static struct platform_driver bcm_driver = {
 static int bcm_serdev_probe(struct serdev_device *serdev)
 {
 	struct bcm_device *bcmdev;
+	const struct bcm_device_data *data;
 	int err;
 
 	bcmdev = devm_kzalloc(&serdev->dev, sizeof(*bcmdev), GFP_KERNEL);
@@ -1408,6 +1427,10 @@ static int bcm_serdev_probe(struct serdev_device *serdev)
 	if (err)
 		dev_err(&serdev->dev, "Failed to power down\n");
 
+	data = device_get_match_data(bcmdev->dev);
+	if (data)
+		bcmdev->no_early_set_baudrate = data->no_early_set_baudrate;
+
 	return hci_uart_register_device(&bcmdev->serdev_hu, &bcm_proto);
 }
 
@@ -1419,12 +1442,16 @@ static void bcm_serdev_remove(struct serdev_device *serdev)
 }
 
 #ifdef CONFIG_OF
+static 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 },
 	{ .compatible = "brcm,bcm4335a0" },
 	{ },
 };
-- 
2.23.0


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

* Re: [PATCH v2 1/4] Bluetooth: hci_bcm: Disallow set_baudrate for BCM4354
  2019-11-26  7:17 [PATCH v2 1/4] Bluetooth: hci_bcm: Disallow set_baudrate for BCM4354 Marcel Holtmann
@ 2019-11-27  7:11 ` Johan Hedberg
  0 siblings, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2019-11-27  7:11 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth

Hi Marcel,

On Tue, Nov 26, 2019, Marcel Holtmann wrote:
> 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, don't set the operating speed before patchram.
> 
> Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  drivers/bluetooth/hci_bcm.c | 31 +++++++++++++++++++++++++++++--
>  1 file changed, 29 insertions(+), 2 deletions(-)

All four patches have been applied to bluetooth-next. Thanks.

Johan

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

* Re: [PATCH v2 1/4] Bluetooth: hci_bcm: Disallow set_baudrate for BCM4354
  2019-11-07 23:27 ` [PATCH v2 1/4] Bluetooth: hci_bcm: Disallow set_baudrate for BCM4354 Abhishek Pandit-Subedi
@ 2019-11-08  6:08   ` Marcel Holtmann
  0 siblings, 0 replies; 4+ messages in thread
From: Marcel Holtmann @ 2019-11-08  6:08 UTC (permalink / raw)
  To: Abhishek Pandit-Subedi
  Cc: Johan Hedberg, Rob Herring, linux-bluetooth, dianders, linux-kernel

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.
> 
> Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
> ---
> 
> Changes in v2: None
> 
> drivers/bluetooth/hci_bcm.c | 25 +++++++++++++++++++++++--
> 1 file changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
> index 0f851c0dde7f..2114df607cb3 100644
> --- a/drivers/bluetooth/hci_bcm.c
> +++ b/drivers/bluetooth/hci_bcm.c
> @@ -1167,7 +1167,7 @@ static int bcm_remove(struct platform_device *pdev)
> 	return 0;
> }
> 
> -static const struct hci_uart_proto bcm_proto = {
> +static struct hci_uart_proto bcm_proto = {
> 	.id		= HCI_UART_BCM,
> 	.name		= "Broadcom",
> 	.manufacturer	= 15,
> @@ -1371,6 +1371,24 @@ static struct platform_driver bcm_driver = {
> 	},
> };
> 
> +#define BCM_QUIRK_DISALLOW_SET_BAUDRATE (1 << 0)
> +const u32 disallow_set_baudrate = BCM_QUIRK_DISALLOW_SET_BAUDRATE;
> +
> +static int bcm_check_disallow_set_baudrate(struct serdev_device *serdev)
> +{
> +	const u32 *quirks = device_get_match_data(&serdev->dev);
> +
> +	if (quirks) {
> +		/* BCM4354 can't run at full speed before patchram. Disallow
> +		 * externally setting operating speed.
> +		 */
> +		if (*quirks & BCM_QUIRK_DISALLOW_SET_BAUDRATE)
> +			return 1;
> +	}
> +
> +	return 0;
> +}
> +
> static int bcm_serdev_probe(struct serdev_device *serdev)
> {
> 	struct bcm_device *bcmdev;
> @@ -1408,6 +1426,9 @@ static int bcm_serdev_probe(struct serdev_device *serdev)
> 	if (err)
> 		dev_err(&serdev->dev, "Failed to power down\n");
> 
> +	if (bcm_check_disallow_set_baudrate(serdev))
> +		bcm_proto.set_baudrate = NULL;
> +

this change is not allowed since bcm_proto is on purpose const.

> 	return hci_uart_register_device(&bcmdev->serdev_hu, &bcm_proto);
> }
> 
> @@ -1424,7 +1445,7 @@ static const struct of_device_id bcm_bluetooth_of_match[] = {
> 	{ .compatible = "brcm,bcm4345c5" },
> 	{ .compatible = "brcm,bcm4330-bt" },
> 	{ .compatible = "brcm,bcm43438-bt" },
> -	{ .compatible = "brcm,bcm43540-bt" },
> +	{ .compatible = "brcm,bcm43540-bt", .data = &disallow_set_baudrate },
> 	{ },
> };
> MODULE_DEVICE_TABLE(of, bcm_bluetooth_of_match);

So I would prefer if we do this in a more generic from that will make this easy to extend in the future. Similar to what hci_qca.c does actually with defining a separate struct for the module differences.

struct bcm_device_data (
	bool no_early_oper_speed;
};

static const struct bcm_device_data bcm43540_device {
	.no_early_oper_speed = true,
};

static const struct of_device_id bcm_bluetooth_of_match[] = {
	..
	{ .compatible = "brcm,bcm43540-bt", .data = &bcm43540_device },
	( },
};

And then load the struct in serdev probe as pointer and check its existence and add the struct bcm_device_data to struct bcm_device so it can be referenced when you change the baudrate.

Regards

Marcel


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

* [PATCH v2 1/4] Bluetooth: hci_bcm: Disallow set_baudrate for BCM4354
  2019-11-07 23:27 [PATCH v2 0/4] Bluetooth: hci_bcm: Additional changes for BCM4354 support Abhishek Pandit-Subedi
@ 2019-11-07 23:27 ` Abhishek Pandit-Subedi
  2019-11-08  6:08   ` Marcel Holtmann
  0 siblings, 1 reply; 4+ messages in thread
From: Abhishek Pandit-Subedi @ 2019-11-07 23:27 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Rob Herring
  Cc: linux-bluetooth, dianders, Abhishek Pandit-Subedi, linux-kernel

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.

Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
---

Changes in v2: None

 drivers/bluetooth/hci_bcm.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
index 0f851c0dde7f..2114df607cb3 100644
--- a/drivers/bluetooth/hci_bcm.c
+++ b/drivers/bluetooth/hci_bcm.c
@@ -1167,7 +1167,7 @@ static int bcm_remove(struct platform_device *pdev)
 	return 0;
 }
 
-static const struct hci_uart_proto bcm_proto = {
+static struct hci_uart_proto bcm_proto = {
 	.id		= HCI_UART_BCM,
 	.name		= "Broadcom",
 	.manufacturer	= 15,
@@ -1371,6 +1371,24 @@ static struct platform_driver bcm_driver = {
 	},
 };
 
+#define BCM_QUIRK_DISALLOW_SET_BAUDRATE (1 << 0)
+const u32 disallow_set_baudrate = BCM_QUIRK_DISALLOW_SET_BAUDRATE;
+
+static int bcm_check_disallow_set_baudrate(struct serdev_device *serdev)
+{
+	const u32 *quirks = device_get_match_data(&serdev->dev);
+
+	if (quirks) {
+		/* BCM4354 can't run at full speed before patchram. Disallow
+		 * externally setting operating speed.
+		 */
+		if (*quirks & BCM_QUIRK_DISALLOW_SET_BAUDRATE)
+			return 1;
+	}
+
+	return 0;
+}
+
 static int bcm_serdev_probe(struct serdev_device *serdev)
 {
 	struct bcm_device *bcmdev;
@@ -1408,6 +1426,9 @@ static int bcm_serdev_probe(struct serdev_device *serdev)
 	if (err)
 		dev_err(&serdev->dev, "Failed to power down\n");
 
+	if (bcm_check_disallow_set_baudrate(serdev))
+		bcm_proto.set_baudrate = NULL;
+
 	return hci_uart_register_device(&bcmdev->serdev_hu, &bcm_proto);
 }
 
@@ -1424,7 +1445,7 @@ static const struct of_device_id bcm_bluetooth_of_match[] = {
 	{ .compatible = "brcm,bcm4345c5" },
 	{ .compatible = "brcm,bcm4330-bt" },
 	{ .compatible = "brcm,bcm43438-bt" },
-	{ .compatible = "brcm,bcm43540-bt" },
+	{ .compatible = "brcm,bcm43540-bt", .data = &disallow_set_baudrate },
 	{ },
 };
 MODULE_DEVICE_TABLE(of, bcm_bluetooth_of_match);
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog


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

end of thread, other threads:[~2019-11-27  7:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-26  7:17 [PATCH v2 1/4] Bluetooth: hci_bcm: Disallow set_baudrate for BCM4354 Marcel Holtmann
2019-11-27  7:11 ` Johan Hedberg
  -- strict thread matches above, loose matches on Subject: below --
2019-11-07 23:27 [PATCH v2 0/4] Bluetooth: hci_bcm: Additional changes for BCM4354 support Abhishek Pandit-Subedi
2019-11-07 23:27 ` [PATCH v2 1/4] Bluetooth: hci_bcm: Disallow set_baudrate for BCM4354 Abhishek Pandit-Subedi
2019-11-08  6:08   ` Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).