public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Andre Heider <a.heider@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/4] arm: sunxi: add a config option to fixup a Bluetooth address
Date: Tue, 26 Nov 2019 09:16:00 +0100	[thread overview]
Message-ID: <20191126081602.2264519-3-a.heider@gmail.com> (raw)
In-Reply-To: <20191126081602.2264519-1-a.heider@gmail.com>

Some Bluetooth controllers, like the BCM4345C5 of the Orange Pi 3,
ship with the controller default address.

Add a config option to fix it up so it can function properly.

Signed-off-by: Andre Heider <a.heider@gmail.com>
---
 arch/arm/mach-sunxi/Kconfig | 12 ++++++++++++
 board/sunxi/board.c         | 30 ++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index 16d41b83af..b41c64870e 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -1009,4 +1009,16 @@ config PINE64_DT_SELECTION
 	  option, the device tree selection code specific to Pine64 which
 	  utilizes the DRAM size will be enabled.
 
+config FIXUP_BDADDR
+	string "Fixup the Bluetooth controller address"
+	depends on MACH_SUN50I_H6
+	default ""
+	help
+	  This option specifies the DT compatible name of the Bluetooth
+	  controller for which to set the "local-bd-address" property.
+	  Set this option if your device ships with the Bluetooth controller
+	  default address.
+	  The used address is "bdaddr" if set, and "ethaddr" with the LSB
+	  flipped elsewise.
+
 endif
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index bb35d6b66e..89851102d1 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -856,6 +856,34 @@ int misc_init_r(void)
 	return 0;
 }
 
+static void fixup_bd_address(void *blob)
+{
+#ifdef CONFIG_FIXUP_BDADDR
+	/* Some devices ship with a Bluetooth controller default address.
+	 * Set a valid address through the device tree.
+	 */
+	uchar tmp[ETH_ALEN], bdaddr[ETH_ALEN];
+	int i;
+
+	if (strlen(CONFIG_FIXUP_BDADDR) < 1)
+		return;
+
+	if (!eth_env_get_enetaddr("bdaddr", tmp)) {
+		if (!eth_env_get_enetaddr("ethaddr", tmp))
+			return;
+
+		tmp[ETH_ALEN - 1] ^= 1;
+	}
+
+	/* Addresses need to be in the binary format of the corresponding stack */
+	for (i = 0; i < ETH_ALEN; ++i)
+		bdaddr[i] = tmp[ETH_ALEN - i - 1];
+
+	do_fixup_by_compat(blob, CONFIG_FIXUP_BDADDR,
+			   "local-bd-address", bdaddr, ETH_ALEN, 1);
+#endif
+}
+
 int ft_board_setup(void *blob, bd_t *bd)
 {
 	int __maybe_unused r;
@@ -866,6 +894,8 @@ int ft_board_setup(void *blob, bd_t *bd)
 	 */
 	setup_environment(blob);
 
+	fixup_bd_address(blob);
+
 #ifdef CONFIG_VIDEO_DT_SIMPLEFB
 	r = sunxi_simplefb_setup(blob);
 	if (r)
-- 
2.24.0

  parent reply	other threads:[~2019-11-26  8:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-26  8:15 [U-Boot] [PATCH v2 0/4] arm64: dts: sun50i: Add support for Orange Pi 3 Andre Heider
2019-11-26  8:15 ` [U-Boot] [PATCH v2 1/4] sunxi: board: Use eth_env_set_enetaddr_by_index() Andre Heider
2019-11-26 10:22   ` Ondřej Jirman
2019-11-26 12:12     ` Andre Heider
2019-11-26  8:16 ` Andre Heider [this message]
2019-11-26 10:46   ` [U-Boot] [PATCH v2 2/4] arm: sunxi: add a config option to fixup a Bluetooth address Ondřej Jirman
2019-11-26 10:50     ` Ondřej Jirman
2019-11-26 12:15     ` Andre Heider
2019-11-26 12:40       ` Ondřej Jirman
2019-11-26 14:08         ` Andre Heider
2019-11-26  8:16 ` [U-Boot] [PATCH v2 3/4] arm64: dts: sync Allwinner H6 files Andre Heider
2019-11-26  8:16 ` [U-Boot] [PATCH v2 4/4] arm64: dts: sun50i: Add support for Orange Pi 3 Andre Heider

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191126081602.2264519-3-a.heider@gmail.com \
    --to=a.heider@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox