Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bluetooth overlays #3682

Merged
merged 2 commits into from
Jul 1, 2020
Merged

Add Bluetooth overlays #3682

merged 2 commits into from
Jul 1, 2020

Conversation

gentoo-root
Copy link
Contributor

As a follow-up for #3675, this pull request adds device tree overlays to give users an option to configure Bluetooth without hciattach/btattach, and changes the defconfigs to make this way work.

@pelwell
Copy link
Contributor

pelwell commented Jun 21, 2020

All overlays require documentation in the README file - if you add that now I can review it all together.

@macmpi
Copy link

macmpi commented Jun 21, 2020

Nice.
You may want to add reference to PiZeroW in bt-overlay.dts , and also do similar for bcm2708 (bcm2835 in upstream DTBs).
@pelwell could that eventually be merged into 5.4.y too? That would really be sweet.

@pelwell
Copy link
Contributor

pelwell commented Jun 21, 2020

Anything merged is eventually ported to all current branches (where possible).

@gentoo-root
Copy link
Contributor Author

You may want to add reference to PiZeroW in bt-overlay.dts

Sure, I can mention it. Just to clarify (because I don't have one for tests), does Zero W support flow control (so that bt-overlay.dts is the right one)?

also do similar for bcm2708 (bcm2835 in upstream DTBs).

Sorry, I didn't get it... Do you mean I need to add some different overlay for bcm2708?

@pelwell
Copy link
Contributor

pelwell commented Jun 21, 2020

I have no problem with what you've done so far, but I think we can do better from a user's perspective. I don't like the fact that they have to know whether their Pi supports BT flow control - it would be better that enabling Bluetooth in a common way (i.e. one overlay, or one parameter) automatically chose the default baud rate, but with an override to change it.

The serdev enumeration that enables the Bluetooth support checks for enabled nodes, which means the bluetooth nodes can appear in the base DTBs by default, with the correct baud rates, but disabled, with an overlay or (better) dtparam to enable it. If we ever switch over so that this method is used by default we could just change the default state and keep the parameter as a way to disable it.

What do you think?

@gentoo-root
Copy link
Contributor Author

Sounds great! Basically, I can add the bluetooth nodes to the main trees, disabled by default, and with correct baud rates for different boards (i.e. 3000000 for Pi4, 921600 for Pi3), and a dtparam to enable Bluetooth — I think, I can do that.

However, there is this Pi3 rev 1.2/1.3 difference in flow control support, and both of them share the same device tree. Do you have an idea how to handle it with your approach? I can only think of another dtparam to force baud rate, but it means the user will have to set it manually on Pi3 rev 1.3.

@pelwell
Copy link
Contributor

pelwell commented Jun 21, 2020

Hmm - okay then, in that case it makes sense for the firmware to set a sensible baud rate using the parameter before any user settings are applied. Until the firmware is updated, users of the 3B <= rev 1.2 will have to set the baud rate manually.

@pelwell
Copy link
Contributor

pelwell commented Jun 21, 2020

Which (I think) means the bluetooth node just needs to go in bcm270x-rpi.dtsi.

@macmpi
Copy link

macmpi commented Jun 26, 2020

What's the final take on this?
bluetooth node in bcm270x-rpi.dtsi, and dtparam to activate & eventually set custom baud rate (particularly for Pi3 rev 1.2)?

(@gentoo-root yes indeed, PiZeroW does support HW flowcontrol)

The next patch adds a device tree overlay for Bluetooth. The Bluetooth
device node is a child of uart0 (pl011). The children of pl011 are not
registered as platform devices by of_platform_bus_create, because they
fall into `of_device_is_compatible(bus, "arm,primecell")` check. These
children are registered by of_serdev_register_devices, called through
this chain of calls:

  - uart_add_one_port (drivers/tty/serial/amba-pl011.c)
  - tty_port_register_device_attr_serdev
  - serdev_tty_port_register
  - serdev_controller_add
  - of_serdev_register_devices

serdev_tty_port_register depends on CONFIG_SERIAL_DEV_CTRL_TTYPORT,
which in turn depends on CONFIG_SERIAL_DEV_BUS=y. This patch modifies
the defconfigs of Raspberry Pi devices to set these options and allow
to bind drivers to subnodes of UART devices that can be added by device
tree overlays.

Signed-off-by: Maxim Mikityanskiy <[email protected]>
@gentoo-root
Copy link
Contributor Author

bluetooth node in bcm270x-rpi.dtsi

bcm270x-rpi.dtsi is too generic, it's included by the boards without Bluetooth, too. I was planning to patch the concrete boards with Bluetooth: bcm2708-rpi-zero-w.dts, bcm2710-rpi-3-b.dts, bcm2710-rpi-3-b-plus.dts, bcm2711-rpi-4-b.dts (I hope the list is complete), because *.dtsi files are always shared with some non-Bluetooth boards. Probably it makes sense to add a new bcm27xx-rpi-bt.dtsi and include it from those four *.dts files.

dtparam to activate & eventually set custom baud rate (particularly for Pi3 rev 1.2)?

Yes.

BTW, adding the bluetooth node to the main tree will require changes to disable-bt-overlay.dts and miniuart-bt-overlay.dts.

I'm on it currently.

@gentoo-root
Copy link
Contributor Author

I updated the patch, tested the following combinations on Pi3B rev 1.2 and got the expected results:

# Probes at 3 Mbaud.
dtparam=bluetooth=on
# Probes at 921600 baud.
dtparam=bluetooth=on
dtparam=bluetooth_baudrate=921600
# Doesn't probe.
dtparam=bluetooth=on
dtparam=bluetooth_baudrate=921600
dtoverlay=disable-bt
# Doesn't autoprobe; `btattach -B /dev/ttyS0 -P bcm -S 460800 -N` works.
dtparam=bluetooth=on
dtparam=bluetooth_baudrate=921600
dtoverlay=miniuart-bt
# Probes at 460800 on miniUART, /dev/ttyS0 doesn't appear.
dtoverlay=miniuart-bt,probe=on

Copy link
Contributor

@pelwell pelwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from addressing the line comments I'm going to need some entries in the README file for the new parameter, but we're nearly there.

arch/arm/boot/dts/bcm2708-rpi-zero-w.dts Show resolved Hide resolved
arch/arm/boot/dts/bcm27xx-rpi-bt.dtsi Outdated Show resolved Hide resolved
target-path = "/aliases";
__overlay__ {
serial0 = "/soc/serial@7e201000";
serial1 = "/soc/serial@7e215040";
};
};

__overrides__ {
probe = <&minibt>,"status";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probe is a bit vague - I suggest re-using the same name used with the base DTBS, e.g. knlbt.

arch/arm/configs/bcm2709_defconfig Show resolved Hide resolved
@gentoo-root
Copy link
Contributor Author

I updated the patch, addressing all the comments above. I'll retest it one more time after we are done with the review.

Add device tree nodes for Bluetooth on supported Raspberry Pi boards.
It's disabled by default and can be enabled by `krnbt=on` dtparam. It's
an alternative way of configuring Bluetooth, as compared to hciattach or
btattach. When the dtparam is enabled, the Bluetooth driver is probed
automatically and doesn't require any additional bring-up scripts.

Note that Raspberry Pi 3 B rev 1.2 doesn't have the required hardware
flow control pins of UART0 connected to the Bluetooth module, so the
user should decrease the baudrate by passing `krnbt_baudrate=921600`
dtparam to make it more stable. It resembles the behavior of the btuart
script from Raspbian.

The miniuart-bt overlay was modified to support Bluetooth probing with
device tree, too. It's disabled by default and can be enabled by
`krnbt=on` parameter of the miniuart-bt overlay.

Signed-off-by: Maxim Mikityanskiy <[email protected]>
@pelwell
Copy link
Contributor

pelwell commented Jun 30, 2020

That looks good - I'll test it in the morning.

@pelwell
Copy link
Contributor

pelwell commented Jul 1, 2020

Thanks - that works as expected. It doesn't solve the problem of Pis which haven't had their BDADDR written to OTP, but as this is an opt-in change I can live with that.

@pelwell pelwell merged commit 856dd81 into raspberrypi:rpi-5.7.y Jul 1, 2020
@macmpi
Copy link

macmpi commented Jul 1, 2020

Great!Tthanks so much @gentoo-root and @pelwell
Phil, can merge in 5.4.y too, please?

@pelwell
Copy link
Contributor

pelwell commented Jul 1, 2020

Your wish is my command.

popcornmix added a commit to raspberrypi/firmware that referenced this pull request Jul 2, 2020
kernel: drm/vc4: Allow interlaced HDMI modes from FKMS
See: raspberrypi/linux#3698

kernel: Isp driver fixes
See: raspberrypi/linux#3695

kernel: Add Bluetooth overlays
See: raspberrypi/linux#3682

firmware: arm_loader: Allow interlaced HDMI modes from FKMS
See: raspberrypi/linux#3698

firmware: arm_loader: Limit rather than reject boosts with disable_auto_turbo

firmware: i2c: Clearing the TA bit may time out
See: #1422

firmware: arm_loader: Add an accelerated memmove
firmware: arm_loader: memmove kernel to preferred text_offset
See: #1421

firmware: filesystem: Fix GPT regression on USB after SD fix
See: #1420

firmware: bootloader: Some tweaks for LED, UART, USB timeouts
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this pull request Jul 2, 2020
kernel: drm/vc4: Allow interlaced HDMI modes from FKMS
See: raspberrypi/linux#3698

kernel: Isp driver fixes
See: raspberrypi/linux#3695

kernel: Add Bluetooth overlays
See: raspberrypi/linux#3682

firmware: arm_loader: Allow interlaced HDMI modes from FKMS
See: raspberrypi/linux#3698

firmware: arm_loader: Limit rather than reject boosts with disable_auto_turbo

firmware: i2c: Clearing the TA bit may time out
See: raspberrypi/firmware#1422

firmware: arm_loader: Add an accelerated memmove
firmware: arm_loader: memmove kernel to preferred text_offset
See: raspberrypi/firmware#1421

firmware: filesystem: Fix GPT regression on USB after SD fix
See: raspberrypi/firmware#1420

firmware: bootloader: Some tweaks for LED, UART, USB timeouts
@pelwell
Copy link
Contributor

pelwell commented Jul 2, 2020

Just a note to say that the krnbt parameter of the miniuart-bt overlay won't apply as it was written - it was an overlay parameter that tried to directly modify a node in the base DTB, and that's not currently supported. The workaround is to add another fragment, which can be initially empty, targetting the node in the base DTB, and modify the parameter to update the fragment. The fixed version is in rpi-5.4.y now (and will be copied to the others...) but just missed the firmware release.

Having said that, I can't make miniuart-bt,kernbt work at the moment, for reasons I haven't figured out. The kernel claims the uart1 (/dev/ttyS0 disappears) and attempts to bring up the HCI interface, but it times out on the baudrate change:

[    5.716118] Bluetooth: HCI device and connection manager initialized
[    5.716143] Bluetooth: HCI socket layer initialized
[    5.751398] Bluetooth: HCI UART driver ver 2.3
[    5.751417] Bluetooth: HCI UART protocol H4 registered
[    5.751507] Bluetooth: HCI UART protocol Three-wire (H5) registered
[    5.751857] Bluetooth: HCI UART protocol Broadcom registered
[    5.753400] hci_uart_bcm serial0-0: serial0-0 supply vbat not found, using dummy regulator
[    5.753529] hci_uart_bcm serial0-0: serial0-0 supply vddio not found, using dummy regulator
[    8.031745] Bluetooth: hci0: command 0xfc18 tx timeout
[   16.095674] Bluetooth: hci0: BCM: failed to write update baudrate (-110)
[   16.095682] Bluetooth: hci0: Failed to set baudrate
[   18.111671] Bluetooth: hci0: command 0x0c03 tx timeout
[   26.335699] Bluetooth: hci0: BCM: Reset failed (-110)

@pelwell
Copy link
Contributor

pelwell commented Jul 29, 2020

This change has caused additional serial ports to no longer appear as character devices - see https://github.com/raspberrypi/firmware/issues/1438 for the report.
Do you know how to solve that problem without reverting this PR?

@gearhead
Copy link
Contributor

gearhead commented Jul 31, 2020

Thanks for doing this. It is a big help. Are there specific kernel config parameters which need to be set to make this work? Any specific packages which need to be installed?
I confirm it works for my PiZero and a B3 with the current 5.4.51-1 kernel on Arch Arm for armv6 and armv7. Trying to get it going on aarch64 and have had no joy, yet. Re-building 5.4.51-1 for it right now. To get it to work on my B3, I had to install firmware-brcm43xx. This package is not available for armv6 on arch, though, but it still works on my PiZero.
Update: Re-built kernel with slightly different configs and still no onboard bluetooth.
Do I need to do something with the cmdline.txt?

@gearhead
Copy link
Contributor

gearhead commented Aug 2, 2020

Fixed it. I meandered around the kernel config and changed a bunch of things but did not change it. I then went and grabbed the raspberry kernel source from Rpi and made a new config and rebuilt and now this config.txt setting works on aarch64 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants