diff mbox series

[U-Boot,4/4] sunxi: board: fixup the BT address for Orange Pi 3

Message ID 20191122130400.2155457-4-a.heider@gmail.com
State Superseded
Delegated to: Jagannadha Sutradharudu Teki
Headers show
Series [U-Boot,1/4] arm64: dts: sync Allwinner H6 files | expand

Commit Message

Andre Heider Nov. 22, 2019, 1:04 p.m. UTC
The BCM4345C5 of the Orange Pi 3 ships with the controller default
address. Fix it up so it can function properly.

The used address is "ethaddr" with the LSB flipped.

Signed-off-by: Andre Heider <a.heider@gmail.com>
---

NOTE:
 "local-bd-address" is a universal property, the kernel patch for
 btbcm to use that is in bluetooth-next.

 board/sunxi/board.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Comments

Ondřej Jirman Nov. 22, 2019, 2:23 p.m. UTC | #1
Hello,

On Fri, Nov 22, 2019 at 02:04:00PM +0100, Andre Heider wrote:
> The BCM4345C5 of the Orange Pi 3 ships with the controller default
> address. Fix it up so it can function properly.

This is very nice!

> The used address is "ethaddr" with the LSB flipped.
> 
> Signed-off-by: Andre Heider <a.heider@gmail.com>
> ---
> 
> NOTE:
>  "local-bd-address" is a universal property, the kernel patch for
>  btbcm to use that is in bluetooth-next.
> 
>  board/sunxi/board.c | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 
> diff --git a/board/sunxi/board.c b/board/sunxi/board.c
> index bb35d6b66e..2897bf45e1 100644
> --- a/board/sunxi/board.c
> +++ b/board/sunxi/board.c
> @@ -856,6 +856,32 @@ int misc_init_r(void)
>  	return 0;
>  }
>  
> +static void fixup_bd_address(void *blob)
> +{
> +#if defined(CONFIG_MACH_SUN50I_H6)

This sounds useful for other sunxi boards too (many ship with broadcom
BT chips with unassigned addresses), can we have a generic config for 
the fixup?

Something like CONFIG_SUNXI_BTADDR_FIXUP that can be enabled in defconfig
files, or pre-selected/implied by CONFIG_MACH_SUN* that may want it on
by default?

> +	/* Some devices ship with the controller default address.
> +	 * Set a valid address through the device tree.
> +	 */
> +	uchar mac[ETH_ALEN], bdaddr[ETH_ALEN];
> +	int i;
> +
> +	if (!of_machine_is_compatible("xunlong,orangepi-3"))
> +		return;

You don't need to limit this to opi3 only.

thank you and regards,
	o.

> +
> +	if (!eth_env_get_enetaddr("ethaddr", mac))
> +		return;
> +
> +	/* Addresses need to be in the binary format of the corresponding stack */
> +	for (i = 0; i < ETH_ALEN; ++i)
> +		bdaddr[i] = mac[ETH_ALEN - i - 1];
> +
> +	bdaddr[0] ^= 1;
> +
> +	do_fixup_by_compat(blob, "brcm,bcm4345c5",
> +			   "local-bd-address", bdaddr, ETH_ALEN, 1);
> +#endif
> +}
> +
>  int ft_board_setup(void *blob, bd_t *bd)
>  {
>  	int __maybe_unused r;
> @@ -866,6 +892,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
>
Andre Heider Nov. 22, 2019, 2:41 p.m. UTC | #2
Hey Ondřej,

On 22/11/2019 15:23, Ondřej Jirman wrote:
> Hello,
> 
> On Fri, Nov 22, 2019 at 02:04:00PM +0100, Andre Heider wrote:
>> The BCM4345C5 of the Orange Pi 3 ships with the controller default
>> address. Fix it up so it can function properly.
> 
> This is very nice!
> 
>> The used address is "ethaddr" with the LSB flipped.
>>
>> Signed-off-by: Andre Heider <a.heider@gmail.com>
>> ---
>>
>> NOTE:
>>   "local-bd-address" is a universal property, the kernel patch for
>>   btbcm to use that is in bluetooth-next.
>>
>>   board/sunxi/board.c | 28 ++++++++++++++++++++++++++++
>>   1 file changed, 28 insertions(+)
>>
>> diff --git a/board/sunxi/board.c b/board/sunxi/board.c
>> index bb35d6b66e..2897bf45e1 100644
>> --- a/board/sunxi/board.c
>> +++ b/board/sunxi/board.c
>> @@ -856,6 +856,32 @@ int misc_init_r(void)
>>   	return 0;
>>   }
>>   
>> +static void fixup_bd_address(void *blob)
>> +{
>> +#if defined(CONFIG_MACH_SUN50I_H6)
> 
> This sounds useful for other sunxi boards too (many ship with broadcom
> BT chips with unassigned addresses), can we have a generic config for
> the fixup?
> 
> Something like CONFIG_SUNXI_BTADDR_FIXUP that can be enabled in defconfig
> files, or pre-selected/implied by CONFIG_MACH_SUN* that may want it on
> by default?

sure, we can do that, but note there's "brcm,bcm4345c5" used below, 
hence me limiting it to opi3 for now.

So we either need to have something like
CONFIG_SUNXI_BTADDR_FIXUP="brcm,bcm4345c5"
or a dts "bluetooth" alias we can refer to.

I'd go for the former, would that be an acceptable solution?

Thanks,
Andre

> 
>> +	/* Some devices ship with the controller default address.
>> +	 * Set a valid address through the device tree.
>> +	 */
>> +	uchar mac[ETH_ALEN], bdaddr[ETH_ALEN];
>> +	int i;
>> +
>> +	if (!of_machine_is_compatible("xunlong,orangepi-3"))
>> +		return;
> 
> You don't need to limit this to opi3 only.
> 
> thank you and regards,
> 	o.
> 
>> +
>> +	if (!eth_env_get_enetaddr("ethaddr", mac))
>> +		return;
>> +
>> +	/* Addresses need to be in the binary format of the corresponding stack */
>> +	for (i = 0; i < ETH_ALEN; ++i)
>> +		bdaddr[i] = mac[ETH_ALEN - i - 1];
>> +
>> +	bdaddr[0] ^= 1;
>> +
>> +	do_fixup_by_compat(blob, "brcm,bcm4345c5",
>> +			   "local-bd-address", bdaddr, ETH_ALEN, 1);
>> +#endif
>> +}
>> +
>>   int ft_board_setup(void *blob, bd_t *bd)
>>   {
>>   	int __maybe_unused r;
>> @@ -866,6 +892,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
>>
Chen-Yu Tsai Nov. 23, 2019, 3:24 a.m. UTC | #3
On Fri, Nov 22, 2019 at 9:05 PM Andre Heider <a.heider@gmail.com> wrote:
>
> The BCM4345C5 of the Orange Pi 3 ships with the controller default
> address. Fix it up so it can function properly.
>
> The used address is "ethaddr" with the LSB flipped.
>
> Signed-off-by: Andre Heider <a.heider@gmail.com>
> ---
>
> NOTE:
>  "local-bd-address" is a universal property, the kernel patch for
>  btbcm to use that is in bluetooth-next.
>
>  board/sunxi/board.c | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
>
> diff --git a/board/sunxi/board.c b/board/sunxi/board.c
> index bb35d6b66e..2897bf45e1 100644
> --- a/board/sunxi/board.c
> +++ b/board/sunxi/board.c
> @@ -856,6 +856,32 @@ int misc_init_r(void)
>         return 0;
>  }
>
> +static void fixup_bd_address(void *blob)
> +{
> +#if defined(CONFIG_MACH_SUN50I_H6)
> +       /* Some devices ship with the controller default address.
> +        * Set a valid address through the device tree.
> +        */
> +       uchar mac[ETH_ALEN], bdaddr[ETH_ALEN];
> +       int i;
> +
> +       if (!of_machine_is_compatible("xunlong,orangepi-3"))
> +               return;
> +
> +       if (!eth_env_get_enetaddr("ethaddr", mac))
> +               return;
> +
> +       /* Addresses need to be in the binary format of the corresponding stack */
> +       for (i = 0; i < ETH_ALEN; ++i)
> +               bdaddr[i] = mac[ETH_ALEN - i - 1];
> +
> +       bdaddr[0] ^= 1;

IIRC someone mentioned before that unlike Ethernet and WiFi,
Bluetooth does not have a "locally administered" address space,
so any address used could possibly collide with other devices.

ChenYu


> +
> +       do_fixup_by_compat(blob, "brcm,bcm4345c5",
> +                          "local-bd-address", bdaddr, ETH_ALEN, 1);
> +#endif
> +}
> +
>  int ft_board_setup(void *blob, bd_t *bd)
>  {
>         int __maybe_unused r;
> @@ -866,6 +892,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
>
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
Andre Heider Nov. 23, 2019, 7:42 a.m. UTC | #4
On 23/11/2019 04:24, Chen-Yu Tsai wrote:
> On Fri, Nov 22, 2019 at 9:05 PM Andre Heider <a.heider@gmail.com> wrote:
>>
>> The BCM4345C5 of the Orange Pi 3 ships with the controller default
>> address. Fix it up so it can function properly.
>>
>> The used address is "ethaddr" with the LSB flipped.
>>
>> Signed-off-by: Andre Heider <a.heider@gmail.com>
>> ---
>>
>> NOTE:
>>   "local-bd-address" is a universal property, the kernel patch for
>>   btbcm to use that is in bluetooth-next.
>>
>>   board/sunxi/board.c | 28 ++++++++++++++++++++++++++++
>>   1 file changed, 28 insertions(+)
>>
>> diff --git a/board/sunxi/board.c b/board/sunxi/board.c
>> index bb35d6b66e..2897bf45e1 100644
>> --- a/board/sunxi/board.c
>> +++ b/board/sunxi/board.c
>> @@ -856,6 +856,32 @@ int misc_init_r(void)
>>          return 0;
>>   }
>>
>> +static void fixup_bd_address(void *blob)
>> +{
>> +#if defined(CONFIG_MACH_SUN50I_H6)
>> +       /* Some devices ship with the controller default address.
>> +        * Set a valid address through the device tree.
>> +        */
>> +       uchar mac[ETH_ALEN], bdaddr[ETH_ALEN];
>> +       int i;
>> +
>> +       if (!of_machine_is_compatible("xunlong,orangepi-3"))
>> +               return;
>> +
>> +       if (!eth_env_get_enetaddr("ethaddr", mac))
>> +               return;
>> +
>> +       /* Addresses need to be in the binary format of the corresponding stack */
>> +       for (i = 0; i < ETH_ALEN; ++i)
>> +               bdaddr[i] = mac[ETH_ALEN - i - 1];
>> +
>> +       bdaddr[0] ^= 1;
> 
> IIRC someone mentioned before that unlike Ethernet and WiFi,
> Bluetooth does not have a "locally administered" address space,
> so any address used could possibly collide with other devices.

The kernel even refuses to use the controller default address, likely 
because of collisions. While this patch obviously doesn't guarantee a 
unique address, I guess it's in the same ballpark as "ethaddr" for 
sunxi. This at least gets BT working out of the box.

But I guess we should give the user an option to set a bdaddr of her/his 
choosing. I'll add support for reading the env var "bdaddr" and fall 
back to this address generation if that wasn't successful.

Or do you think we can do better?

Regards,
Andre
Ondřej Jirman Nov. 23, 2019, 2:24 p.m. UTC | #5
Hi,

On Fri, Nov 22, 2019 at 03:41:52PM +0100, Andre Heider wrote:
> Hey Ondřej,
> 
> On 22/11/2019 15:23, Ondřej Jirman wrote:
> > Hello,
> > 
> > On Fri, Nov 22, 2019 at 02:04:00PM +0100, Andre Heider wrote:
> > > The BCM4345C5 of the Orange Pi 3 ships with the controller default
> > > address. Fix it up so it can function properly.
> > 
> > This is very nice!
> > 
> > > The used address is "ethaddr" with the LSB flipped.
> > > 
> > > Signed-off-by: Andre Heider <a.heider@gmail.com>
> > > ---
> > > 
> > > NOTE:
> > >   "local-bd-address" is a universal property, the kernel patch for
> > >   btbcm to use that is in bluetooth-next.
> > > 
> > >   board/sunxi/board.c | 28 ++++++++++++++++++++++++++++
> > >   1 file changed, 28 insertions(+)
> > > 
> > > diff --git a/board/sunxi/board.c b/board/sunxi/board.c
> > > index bb35d6b66e..2897bf45e1 100644
> > > --- a/board/sunxi/board.c
> > > +++ b/board/sunxi/board.c
> > > @@ -856,6 +856,32 @@ int misc_init_r(void)
> > >   	return 0;
> > >   }
> > > +static void fixup_bd_address(void *blob)
> > > +{
> > > +#if defined(CONFIG_MACH_SUN50I_H6)
> > 
> > This sounds useful for other sunxi boards too (many ship with broadcom
> > BT chips with unassigned addresses), can we have a generic config for
> > the fixup?
> > 
> > Something like CONFIG_SUNXI_BTADDR_FIXUP that can be enabled in defconfig
> > files, or pre-selected/implied by CONFIG_MACH_SUN* that may want it on
> > by default?
> 
> sure, we can do that, but note there's "brcm,bcm4345c5" used below, hence me
> limiting it to opi3 for now.
> 
> So we either need to have something like
> CONFIG_SUNXI_BTADDR_FIXUP="brcm,bcm4345c5"
> or a dts "bluetooth" alias we can refer to.
> 
> I'd go for the former, would that be an acceptable solution?

I'm not the maintainer, so I don't know what will be acceptable. Alias solution
is used for ethernet, so I think that may be more acceptable, as it's already
used in u-boot. It can also be more precise, as you can point to a specific node
with the alias.

OTOH, I'm not aware of any sunxi board with multiple BT chips and alias solution
will also need modification of DTS files for all boards that will want to opt in
into this, instead of just having to switch on a config in u-boot.

regards,
	o.

> Thanks,
> Andre
> 
> > 
> > > +	/* Some devices ship with the controller default address.
> > > +	 * Set a valid address through the device tree.
> > > +	 */
> > > +	uchar mac[ETH_ALEN], bdaddr[ETH_ALEN];
> > > +	int i;
> > > +
> > > +	if (!of_machine_is_compatible("xunlong,orangepi-3"))
> > > +		return;
> > 
> > You don't need to limit this to opi3 only.
> > 
> > thank you and regards,
> > 	o.
> > 
> > > +
> > > +	if (!eth_env_get_enetaddr("ethaddr", mac))
> > > +		return;
> > > +
> > > +	/* Addresses need to be in the binary format of the corresponding stack */
> > > +	for (i = 0; i < ETH_ALEN; ++i)
> > > +		bdaddr[i] = mac[ETH_ALEN - i - 1];
> > > +
> > > +	bdaddr[0] ^= 1;
> > > +
> > > +	do_fixup_by_compat(blob, "brcm,bcm4345c5",
> > > +			   "local-bd-address", bdaddr, ETH_ALEN, 1);
> > > +#endif
> > > +}
> > > +
> > >   int ft_board_setup(void *blob, bd_t *bd)
> > >   {
> > >   	int __maybe_unused r;
> > > @@ -866,6 +892,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
> > > 
> 
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
diff mbox series

Patch

diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index bb35d6b66e..2897bf45e1 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -856,6 +856,32 @@  int misc_init_r(void)
 	return 0;
 }
 
+static void fixup_bd_address(void *blob)
+{
+#if defined(CONFIG_MACH_SUN50I_H6)
+	/* Some devices ship with the controller default address.
+	 * Set a valid address through the device tree.
+	 */
+	uchar mac[ETH_ALEN], bdaddr[ETH_ALEN];
+	int i;
+
+	if (!of_machine_is_compatible("xunlong,orangepi-3"))
+		return;
+
+	if (!eth_env_get_enetaddr("ethaddr", mac))
+		return;
+
+	/* Addresses need to be in the binary format of the corresponding stack */
+	for (i = 0; i < ETH_ALEN; ++i)
+		bdaddr[i] = mac[ETH_ALEN - i - 1];
+
+	bdaddr[0] ^= 1;
+
+	do_fixup_by_compat(blob, "brcm,bcm4345c5",
+			   "local-bd-address", bdaddr, ETH_ALEN, 1);
+#endif
+}
+
 int ft_board_setup(void *blob, bd_t *bd)
 {
 	int __maybe_unused r;
@@ -866,6 +892,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)