diff mbox series

[v3,07/15] serial_bcm283x_mu: Fail loading if not muxed

Message ID 20180125110556.76352-8-agraf@suse.de
State Accepted
Commit 9dfeffe2f9f57e0ae254b1305f3fafb801a8b24a
Headers show
Series RPi: Properly handle dynamic serial configuration | expand

Commit Message

Alexander Graf Jan. 25, 2018, 11:05 a.m. UTC
The bcm283x mini-uart is only really usable as U-Boot serial output
when it is muxed to the UART pins of the RPi pin header.

So fail probing in case it is not muxed correctly, as in that case
firmware did not initialize it properly either.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 drivers/serial/serial_bcm283x_mu.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Comments

Tom Rini Jan. 28, 2018, 6:55 p.m. UTC | #1
On Thu, Jan 25, 2018 at 12:05:48PM +0100, Alexander Graf wrote:

> The bcm283x mini-uart is only really usable as U-Boot serial output

> when it is muxed to the UART pins of the RPi pin header.

> 

> So fail probing in case it is not muxed correctly, as in that case

> firmware did not initialize it properly either.

> 

> Signed-off-by: Alexander Graf <agraf@suse.de>


Applied to u-boot/master, thanks!

-- 
Tom
diff mbox series

Patch

diff --git a/drivers/serial/serial_bcm283x_mu.c b/drivers/serial/serial_bcm283x_mu.c
index c6132b4463..40029fadbc 100644
--- a/drivers/serial/serial_bcm283x_mu.c
+++ b/drivers/serial/serial_bcm283x_mu.c
@@ -19,9 +19,11 @@ 
 #include <dm.h>
 #include <errno.h>
 #include <watchdog.h>
+#include <asm/gpio.h>
 #include <asm/io.h>
 #include <serial.h>
 #include <dm/platform_data/serial_bcm283x_mu.h>
+#include <dm/pinctrl.h>
 #include <linux/compiler.h>
 
 struct bcm283x_mu_regs {
@@ -136,11 +138,37 @@  static const struct udevice_id bcm283x_mu_serial_id[] = {
 	{}
 };
 
+/*
+ * Check if this serial device is muxed
+ *
+ * The serial device will only work properly if it has been muxed to the serial
+ * pins by firmware. Check whether that happened here.
+ *
+ * @return true if serial device is muxed, false if not
+ */
+static bool bcm283x_is_serial_muxed(void)
+{
+	int serial_gpio = 15;
+	struct udevice *dev;
+
+	if (uclass_first_device(UCLASS_PINCTRL, &dev) || !dev)
+		return false;
+
+	if (pinctrl_get_gpio_mux(dev, 0, serial_gpio) != BCM2835_GPIO_ALT5)
+		return false;
+
+	return true;
+}
+
 static int bcm283x_mu_serial_ofdata_to_platdata(struct udevice *dev)
 {
 	struct bcm283x_mu_serial_platdata *plat = dev_get_platdata(dev);
 	fdt_addr_t addr;
 
+	/* Don't spawn the device if it's not muxed */
+	if (!bcm283x_is_serial_muxed())
+		return -ENODEV;
+
 	addr = devfdt_get_addr(dev);
 	if (addr == FDT_ADDR_T_NONE)
 		return -EINVAL;