]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
serial: bcm283x_mu: Detect disabled serial device
authorAlexander Graf <agraf@suse.de>
Mon, 15 Aug 2016 15:48:51 +0000 (17:48 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 6 Sep 2016 17:18:19 +0000 (13:18 -0400)
On the raspberry pi, you can disable the serial port to gain dynamic frequency
scaling which can get handy at times.

However, in such a configuration the serial controller gets its rx queue filled
up with zero bytes which then happily get transmitted on to whoever calls
getc() today.

This patch adds detection logic for that case by checking whether the RX pin is
mapped to GPIO15 and disables the mini uart if it is not mapped properly.

That way we can leave the driver enabled in the tree and can determine during
runtime whether serial is usable or not, having a single binary that allows for
uart and non-uart operation.

Signed-off-by: Alexander Graf <agraf@suse.de>
Acked-by: Stephen Warren <swarren@wwwdotorg.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
board/raspberrypi/rpi/rpi.c
configs/rpi_3_32b_defconfig
configs/rpi_3_defconfig
drivers/gpio/bcm2835_gpio.c
drivers/serial/serial_bcm283x_mu.c
include/configs/rpi.h
include/dm/platform_data/serial_bcm283x_mu.h

index fbfbf6cbbc64282c222a7047ed3c5e609f70b4c3..6245b3678f15ae31b2073f6be4b3cc59a6e326e9 100644 (file)
@@ -50,7 +50,7 @@ U_BOOT_DEVICE(bcm2835_serials) = {
        .platdata = &serial_platdata,
 };
 #else
-static const struct bcm283x_mu_serial_platdata serial_platdata = {
+static struct bcm283x_mu_serial_platdata serial_platdata = {
        .base = 0x3f215040,
        .clock = 250000000,
        .skip_init = true,
@@ -452,6 +452,38 @@ int board_init(void)
        return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
 }
 
+#ifndef CONFIG_PL01X_SERIAL
+static bool rpi_is_serial_active(void)
+{
+       int serial_gpio = 15;
+       struct udevice *dev;
+
+       /*
+        * The RPi3 disables the mini uart by default. The easiest way to find
+        * out whether it is available is to check if the RX pin is muxed.
+        */
+
+       if (uclass_first_device(UCLASS_GPIO, &dev) || !dev)
+               return true;
+
+       if (bcm2835_gpio_get_func_id(dev, serial_gpio) != BCM2835_GPIO_ALT5)
+               return false;
+
+       return true;
+}
+#endif
+
+int board_early_init_f(void)
+{
+#ifndef CONFIG_PL01X_SERIAL
+       /* Disable mini-UART I/O if it's not pinmuxed to our pins */
+       if (!rpi_is_serial_active())
+               serial_platdata.disabled = true;
+#endif
+
+       return 0;
+}
+
 int board_mmc_init(bd_t *bis)
 {
        ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1);
index 922e01bfcbb62a386a80f8b10a40179d7b4d7950..c59474cdf0a8fe0ad2284e6f9102da9921ca8923 100644 (file)
@@ -20,3 +20,5 @@ CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
 CONFIG_PHYS_TO_BUS=y
 CONFIG_OF_LIBFDT=y
+# CONFIG_REQUIRE_SERIAL_CONSOLE is not set
+CONFIG_SYS_MALLOC_F_LEN=0x2000
index bff92df9d9963531215b6b33d9a898a88e8a43c5..67c4a0cbe6a002f1caa40323c0b4f308971e8bb8 100644 (file)
@@ -19,3 +19,5 @@ CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
 CONFIG_PHYS_TO_BUS=y
 CONFIG_OF_LIBFDT=y
+# CONFIG_REQUIRE_SERIAL_CONSOLE is not set
+CONFIG_SYS_MALLOC_F_LEN=0x2000
index 8b88d7956e72e62d54ef4e4cd63ac857a4586331..8dd7a28e2670c98492078e4bcd52be56ac2d6164 100644 (file)
@@ -123,5 +123,6 @@ U_BOOT_DRIVER(gpio_bcm2835) = {
        .id     = UCLASS_GPIO,
        .ops    = &gpio_bcm2835_ops,
        .probe  = bcm2835_gpio_probe,
+       .flags  = DM_FLAG_PRE_RELOC,
        .priv_auto_alloc_size = sizeof(struct bcm2835_gpios),
 };
index 7357bbfb26798ade1fb228140bcfd7f6e25bf052..f4e062f0c4e18b2581ca73ce4d5ff0fb7c510ae3 100644 (file)
@@ -73,6 +73,9 @@ static int bcm283x_mu_serial_probe(struct udevice *dev)
        struct bcm283x_mu_serial_platdata *plat = dev_get_platdata(dev);
        struct bcm283x_mu_priv *priv = dev_get_priv(dev);
 
+       if (plat->disabled)
+               return -ENODEV;
+
        priv->regs = (struct bcm283x_mu_regs *)plat->base;
 
        return 0;
index 752cc319fceb3e4e141268ed9927691b32889ef3..e34814bd5e32bb7e2e39dc601e8c1ad4e95fc107 100644 (file)
@@ -16,6 +16,7 @@
 
 /* Architecture, CPU, etc.*/
 #define CONFIG_ARCH_CPU_INIT
+#define CONFIG_BOARD_EARLY_INIT_F
 
 /* Use SoC timer for AArch32, but architected timer for AArch64 */
 #ifndef CONFIG_ARM64
index 57ae6adc0538ae6198c7218906c7579ade4569c4..c47d3c0e60e9d29bb929fa3116f333ec79fea3da 100644 (file)
@@ -19,6 +19,7 @@ struct bcm283x_mu_serial_platdata {
        unsigned long base;
        unsigned int clock;
        bool skip_init;
+       bool disabled;
 };
 
 #endif