All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/2] serial: bcm283x_mu: Detect disabled serial device
Date: Thu, 11 Aug 2016 13:38:32 +0200	[thread overview]
Message-ID: <1470915512-40855-2-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1470915512-40855-1-git-send-email-agraf@suse.de>

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>

---

v2 -> v3:

  - Disable and detect pinmux in board file
---
 board/raspberrypi/rpi/rpi.c | 29 +++++++++++++++++++++++++++++
 configs/rpi_3_32b_defconfig |  1 +
 configs/rpi_3_defconfig     |  1 +
 include/configs/rpi.h       |  1 +
 4 files changed, 32 insertions(+)

diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
index 4c8253d..20b0d1b 100644
--- a/board/raspberrypi/rpi/rpi.c
+++ b/board/raspberrypi/rpi/rpi.c
@@ -453,6 +453,35 @@ int board_init(void)
 	return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
 }
 
+static bool rpi_is_serial_active(void)
+{
+#ifndef CONFIG_PL01X_SERIAL
+	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 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;
+#endif
+
+	return true;
+}
+
+int board_late_init(void)
+{
+	/* Disable mini-UART I/O if it's not pinmuxed to our pins */
+	if (!rpi_is_serial_active())
+		gd->cur_serial_dev = NULL;
+
+	return 0;
+}
+
 int board_mmc_init(bd_t *bis)
 {
 	ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1);
diff --git a/configs/rpi_3_32b_defconfig b/configs/rpi_3_32b_defconfig
index 922e01b..4c2f106 100644
--- a/configs/rpi_3_32b_defconfig
+++ b/configs/rpi_3_32b_defconfig
@@ -20,3 +20,4 @@ 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
diff --git a/configs/rpi_3_defconfig b/configs/rpi_3_defconfig
index bff92df..288214c 100644
--- a/configs/rpi_3_defconfig
+++ b/configs/rpi_3_defconfig
@@ -19,3 +19,4 @@ 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
diff --git a/include/configs/rpi.h b/include/configs/rpi.h
index b5543f4..e3b890a 100644
--- a/include/configs/rpi.h
+++ b/include/configs/rpi.h
@@ -22,6 +22,7 @@
 
 /* Architecture, CPU, etc.*/
 #define CONFIG_ARCH_CPU_INIT
+#define CONFIG_BOARD_LATE_INIT
 
 /* Use SoC timer for AArch32, but architected timer for AArch64 */
 #ifndef CONFIG_ARM64
-- 
1.8.5.6

  reply	other threads:[~2016-08-11 11:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-11 11:38 [U-Boot] [PATCH 1/2] bcm2835_gpio: Implement GPIOF_FUNC Alexander Graf
2016-08-11 11:38 ` Alexander Graf [this message]
2016-08-11 22:38   ` [U-Boot] [PATCH 2/2] serial: bcm283x_mu: Detect disabled serial device Simon Glass
2016-08-12  5:24     ` Alexander Graf
2016-08-15 15:48   ` [U-Boot] [PATCH v4 " Alexander Graf
2016-08-16  3:30     ` Stephen Warren
2016-08-16  4:52       ` Simon Glass
2016-08-16  5:55       ` Alexander Graf
2016-09-07 17:57     ` [U-Boot] [U-Boot, v4, " Tom Rini
2016-08-11 22:37 ` [U-Boot] [PATCH 1/2] bcm2835_gpio: Implement GPIOF_FUNC Simon Glass
2016-08-13  2:16 ` Stephen Warren
2016-09-07 17:57 ` [U-Boot] [U-Boot,1/2] " Tom Rini

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=1470915512-40855-2-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.