All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: btbcm: Support per-board firmware variants
@ 2022-03-11  0:17 Linus Walleij
  2022-03-11  2:16 ` bluez.test.bot
  2022-03-14 15:18 ` [PATCH] " Marcel Holtmann
  0 siblings, 2 replies; 3+ messages in thread
From: Linus Walleij @ 2022-03-11  0:17 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz
  Cc: linux-bluetooth, Linus Walleij, phone-devel, Markuss Broks,
	Stephan Gerhold

There are provedly different firmware variants for the different
phones using some of these chips. These were extracted from a few
Samsung phones:

37446 BCM4334B0.samsung,codina-tmo.hcd
37366 BCM4334B0.samsung,golden.hcd
37403 BCM4334B0.samsung,kyle.hcd
37366 BCM4334B0.samsung,skomer.hcd

This patch supports the above naming schedule with inserting
[.board_name] between the firmware name and ".hcd". This scheme
is the same as used by the companion BRCM wireless chips
as can be seen in
drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
or just by looking at the firmwares in linux-firmware/brcm.

Currently we only support board variants using the device
tree compatible string as board type, but other schemes are
possible.

This makes it possible to successfully load a few unique
firmware variants for some Samsung phones.

Cc: phone-devel@vger.kernel.org
Cc: Markuss Broks <markuss.broks@gmail.com>
Cc: Stephan Gerhold <stephan@gerhold.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/bluetooth/btbcm.c | 55 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c
index d9ceca7a7935..9d1a8d80a8cd 100644
--- a/drivers/bluetooth/btbcm.c
+++ b/drivers/bluetooth/btbcm.c
@@ -9,6 +9,7 @@
 #include <linux/module.h>
 #include <linux/firmware.h>
 #include <linux/dmi.h>
+#include <linux/of.h>
 #include <asm/unaligned.h>
 
 #include <net/bluetooth/bluetooth.h>
@@ -29,7 +30,7 @@
 #define BDADDR_BCM43341B (&(bdaddr_t) {{0xac, 0x1f, 0x00, 0x1b, 0x34, 0x43}})
 
 #define BCM_FW_NAME_LEN			64
-#define BCM_FW_NAME_COUNT_MAX		2
+#define BCM_FW_NAME_COUNT_MAX		4
 /* For kmalloc-ing the fw-name array instead of putting it on the stack */
 typedef char bcm_fw_name[BCM_FW_NAME_LEN];
 
@@ -476,6 +477,45 @@ static const struct bcm_subver_table bcm_usb_subver_table[] = {
 	{ }
 };
 
+/*
+ * This currently only looks up the device tree board appendix,
+ * but can be expanded to other mechanisms.
+ */
+#ifdef CONFIG_OF
+static const char *btbcm_get_board_name(struct device *dev)
+{
+	struct device_node *root;
+	char *board_type;
+	const char *tmp;
+	int len;
+	int i;
+
+	root = of_find_node_by_path("/");
+	if (!root)
+		return NULL;
+
+	if (of_property_read_string_index(root, "compatible", 0, &tmp))
+		return NULL;
+
+	/* get rid of any '/' in the compatible string */
+	len = strlen(tmp) + 1;
+	board_type = devm_kzalloc(dev, len, GFP_KERNEL);
+	strscpy(board_type, tmp, len);
+	for (i = 0; i < board_type[i]; i++) {
+		if (board_type[i] == '/')
+			board_type[i] = '-';
+	}
+	of_node_put(root);
+
+	return board_type;
+}
+#else
+static const char *btbcm_get_board_name(struct device *dev)
+{
+	return NULL;
+}
+#endif
+
 int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done)
 {
 	u16 subver, rev, pid, vid;
@@ -483,12 +523,15 @@ int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done)
 	struct hci_rp_read_local_version *ver;
 	const struct bcm_subver_table *bcm_subver_table;
 	const char *hw_name = NULL;
+	const char *board_name = NULL;
 	char postfix[16] = "";
 	int fw_name_count = 0;
 	bcm_fw_name *fw_name;
 	const struct firmware *fw;
 	int i, err;
 
+	board_name = btbcm_get_board_name(&hdev->dev);
+
 	/* Reset */
 	err = btbcm_reset(hdev);
 	if (err)
@@ -549,11 +592,21 @@ int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done)
 		return -ENOMEM;
 
 	if (hw_name) {
+		if (board_name) {
+			snprintf(fw_name[fw_name_count], BCM_FW_NAME_LEN,
+				 "brcm/%s%s.%s.hcd", hw_name, postfix, board_name);
+			fw_name_count++;
+		}
 		snprintf(fw_name[fw_name_count], BCM_FW_NAME_LEN,
 			 "brcm/%s%s.hcd", hw_name, postfix);
 		fw_name_count++;
 	}
 
+	if (board_name) {
+		snprintf(fw_name[fw_name_count], BCM_FW_NAME_LEN,
+			 "brcm/BCM%s.%s.hcd", postfix, board_name);
+		fw_name_count++;
+	}
 	snprintf(fw_name[fw_name_count], BCM_FW_NAME_LEN,
 		 "brcm/BCM%s.hcd", postfix);
 	fw_name_count++;
-- 
2.35.1


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

* RE: Bluetooth: btbcm: Support per-board firmware variants
  2022-03-11  0:17 [PATCH] Bluetooth: btbcm: Support per-board firmware variants Linus Walleij
@ 2022-03-11  2:16 ` bluez.test.bot
  2022-03-14 15:18 ` [PATCH] " Marcel Holtmann
  1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2022-03-11  2:16 UTC (permalink / raw)
  To: linux-bluetooth, linus.walleij

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

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

Dear submitter,

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

---Test result---

Test Summary:
CheckPatch                    PASS      1.70 seconds
GitLint                       PASS      1.06 seconds
SubjectPrefix                 PASS      0.90 seconds
BuildKernel                   PASS      32.01 seconds
BuildKernel32                 PASS      27.92 seconds
Incremental Build with patchesPASS      37.70 seconds
TestRunner: Setup             PASS      469.59 seconds
TestRunner: l2cap-tester      PASS      15.30 seconds
TestRunner: bnep-tester       PASS      6.07 seconds
TestRunner: mgmt-tester       PASS      99.47 seconds
TestRunner: rfcomm-tester     PASS      7.85 seconds
TestRunner: sco-tester        PASS      7.51 seconds
TestRunner: smp-tester        PASS      7.56 seconds
TestRunner: userchan-tester   PASS      6.29 seconds



---
Regards,
Linux Bluetooth


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

* Re: [PATCH] Bluetooth: btbcm: Support per-board firmware variants
  2022-03-11  0:17 [PATCH] Bluetooth: btbcm: Support per-board firmware variants Linus Walleij
  2022-03-11  2:16 ` bluez.test.bot
@ 2022-03-14 15:18 ` Marcel Holtmann
  1 sibling, 0 replies; 3+ messages in thread
From: Marcel Holtmann @ 2022-03-14 15:18 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Johan Hedberg, Luiz Augusto von Dentz, BlueZ, phone-devel,
	Markuss Broks, Stephan Gerhold

Hi Linus,

> There are provedly different firmware variants for the different
> phones using some of these chips. These were extracted from a few
> Samsung phones:
> 
> 37446 BCM4334B0.samsung,codina-tmo.hcd
> 37366 BCM4334B0.samsung,golden.hcd
> 37403 BCM4334B0.samsung,kyle.hcd
> 37366 BCM4334B0.samsung,skomer.hcd
> 
> This patch supports the above naming schedule with inserting
> [.board_name] between the firmware name and ".hcd". This scheme
> is the same as used by the companion BRCM wireless chips
> as can be seen in
> drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
> or just by looking at the firmwares in linux-firmware/brcm.
> 
> Currently we only support board variants using the device
> tree compatible string as board type, but other schemes are
> possible.
> 
> This makes it possible to successfully load a few unique
> firmware variants for some Samsung phones.
> 
> Cc: phone-devel@vger.kernel.org
> Cc: Markuss Broks <markuss.broks@gmail.com>
> Cc: Stephan Gerhold <stephan@gerhold.net>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> drivers/bluetooth/btbcm.c | 55 ++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 54 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c
> index d9ceca7a7935..9d1a8d80a8cd 100644
> --- a/drivers/bluetooth/btbcm.c
> +++ b/drivers/bluetooth/btbcm.c
> @@ -9,6 +9,7 @@
> #include <linux/module.h>
> #include <linux/firmware.h>
> #include <linux/dmi.h>
> +#include <linux/of.h>
> #include <asm/unaligned.h>
> 
> #include <net/bluetooth/bluetooth.h>
> @@ -29,7 +30,7 @@
> #define BDADDR_BCM43341B (&(bdaddr_t) {{0xac, 0x1f, 0x00, 0x1b, 0x34, 0x43}})
> 
> #define BCM_FW_NAME_LEN			64
> -#define BCM_FW_NAME_COUNT_MAX		2
> +#define BCM_FW_NAME_COUNT_MAX		4
> /* For kmalloc-ing the fw-name array instead of putting it on the stack */
> typedef char bcm_fw_name[BCM_FW_NAME_LEN];
> 
> @@ -476,6 +477,45 @@ static const struct bcm_subver_table bcm_usb_subver_table[] = {
> 	{ }
> };
> 
> +/*
> + * This currently only looks up the device tree board appendix,
> + * but can be expanded to other mechanisms.
> + */
> +#ifdef CONFIG_OF
> +static const char *btbcm_get_board_name(struct device *dev)
> +{
> +	struct device_node *root;
> +	char *board_type;
> +	const char *tmp;
> +	int len;
> +	int i;
> +
> +	root = of_find_node_by_path("/");
> +	if (!root)
> +		return NULL;
> +
> +	if (of_property_read_string_index(root, "compatible", 0, &tmp))
> +		return NULL;
> +
> +	/* get rid of any '/' in the compatible string */
> +	len = strlen(tmp) + 1;
> +	board_type = devm_kzalloc(dev, len, GFP_KERNEL);
> +	strscpy(board_type, tmp, len);
> +	for (i = 0; i < board_type[i]; i++) {
> +		if (board_type[i] == '/')
> +			board_type[i] = '-';
> +	}
> +	of_node_put(root);
> +
> +	return board_type;
> +}
> +#else
> +static const char *btbcm_get_board_name(struct device *dev)
> +{
> +	return NULL;
> +}
> +#endif
> +

can we please do the #ifdef magic inside the function.

static const char *btbcm_get_board_name(struct device *dev)
{
#ifdef
	..
	return board_type;
#else
	return NULL;
#endif
}


> int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done)
> {
> 	u16 subver, rev, pid, vid;
> @@ -483,12 +523,15 @@ int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done)
> 	struct hci_rp_read_local_version *ver;
> 	const struct bcm_subver_table *bcm_subver_table;
> 	const char *hw_name = NULL;
> +	const char *board_name = NULL;
> 	char postfix[16] = "";
> 	int fw_name_count = 0;
> 	bcm_fw_name *fw_name;
> 	const struct firmware *fw;
> 	int i, err;
> 
> +	board_name = btbcm_get_board_name(&hdev->dev);
> +

There is no point in assigning board_name to NULL at variable declaration.

> 	/* Reset */
> 	err = btbcm_reset(hdev);
> 	if (err)
> @@ -549,11 +592,21 @@ int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done)
> 		return -ENOMEM;
> 
> 	if (hw_name) {
> +		if (board_name) {
> +			snprintf(fw_name[fw_name_count], BCM_FW_NAME_LEN,
> +				 "brcm/%s%s.%s.hcd", hw_name, postfix, board_name);
> +			fw_name_count++;
> +		}
> 		snprintf(fw_name[fw_name_count], BCM_FW_NAME_LEN,
> 			 "brcm/%s%s.hcd", hw_name, postfix);
> 		fw_name_count++;
> 	}
> 
> +	if (board_name) {
> +		snprintf(fw_name[fw_name_count], BCM_FW_NAME_LEN,
> +			 "brcm/BCM%s.%s.hcd", postfix, board_name);
> +		fw_name_count++;
> +	}
> 	snprintf(fw_name[fw_name_count], BCM_FW_NAME_LEN,
> 		 "brcm/BCM%s.hcd", postfix);
> 	fw_name_count++;

Regards

Marcel


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

end of thread, other threads:[~2022-03-14 15:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-11  0:17 [PATCH] Bluetooth: btbcm: Support per-board firmware variants Linus Walleij
2022-03-11  2:16 ` bluez.test.bot
2022-03-14 15:18 ` [PATCH] " Marcel Holtmann

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