All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Warren <swarren@wwwdotorg.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] serial: bcm283x_mu: Detect disabled serial device
Date: Thu, 4 Aug 2016 13:11:13 -0600	[thread overview]
Message-ID: <b5dc50bf-d5a0-9928-a6d7-fcad192aea0f@wwwdotorg.org> (raw)
In-Reply-To: <1470294682-159882-1-git-send-email-agraf@suse.de>

On 08/04/2016 01:11 AM, Alexander Graf wrote:
> 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.

> diff --git a/drivers/serial/serial_bcm283x_mu.c b/drivers/serial/serial_bcm283x_mu.c

> @@ -72,9 +87,18 @@ 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);
> +	struct bcm283x_gpio_regs *gpio = (struct bcm283x_gpio_regs *)plat->gpio;
>
>  	priv->regs = (struct bcm283x_mu_regs *)plat->base;
>
> +	/*
> +	 * 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 (((readl(&gpio->gpfsel1) >> BCM283X_GPIO_GPFSEL1_F15_SHIFT) &
> +	    BCM283X_GPIO_ALTFUNC_MASK) != BCM283X_GPIO_ALTFUNC_5)
> +		priv->disabled = true;
> +
>  	return 0;

Comment on the current implementation: Can't probe() return an error if 
the device should be disabled? That would avoid the need to check 
priv->disabled in all the other functions.

Overall comment: I'd rather not put this logic into the UART driver 
itself; it is system-specific rather than device-specific. I'd also 
rather not have the UART driver touching GPIO registers; that's not very 
modular, and could cause problems if the Pi is converted to use DT to 
instantiate devices.

Instead, can we put the logic into board/raspberrypi/rpi/rpi.c? I.e. 
have some early function come along and enable/disable the 
bcm2837_serials device object as appropriate? That way it isolates the 
code to the Pi specifically, and not any other bcm283x board. We'd want 
to wrap that code in #ifdef CONFIG_PL01X_SERIAL.

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

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-04  7:11 [U-Boot] [PATCH v2] serial: bcm283x_mu: Detect disabled serial device Alexander Graf
2016-08-04 19:11 ` Stephen Warren [this message]
2016-08-04 23:15   ` Alexander Graf
2016-08-09  4:28     ` Stephen Warren
2016-08-11 11:33       ` Alexander Graf
2016-08-11 22:38         ` Simon Glass
2016-08-12  5:27           ` Alexander Graf
2016-08-12 17:21             ` Simon Glass
2016-08-12 18:38               ` Alexander Graf
2016-08-12 20:07                 ` Simon Glass
2016-08-12 21:03                   ` Alexander Graf
2016-08-12 22:02                     ` Simon Glass

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=b5dc50bf-d5a0-9928-a6d7-fcad192aea0f@wwwdotorg.org \
    --to=swarren@wwwdotorg.org \
    --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.