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 v2] serial: bcm283x_mu: Detect disabled serial device
Date: Fri, 12 Aug 2016 07:27:38 +0200	[thread overview]
Message-ID: <FDC03238-9876-4B26-AD9A-4D2875E80154@suse.de> (raw)
In-Reply-To: <CAPnjgZ1V0STQGBTC2CVSoCuVLvWFG9RHBF+kztEfhp+KRfizgQ@mail.gmail.com>



> Am 12.08.2016 um 00:38 schrieb Simon Glass <sjg@chromium.org>:
> 
> Hi Alex,
> 
>> On 11 August 2016 at 05:33, Alexander Graf <agraf@suse.de> wrote:
>> 
>> 
>>> On 09.08.16 06:28, Stephen Warren wrote:
>>>> On 08/04/2016 05:15 PM, Alexander Graf wrote:
>>>> 
>>>>> On 04 Aug 2016, at 20:11, Stephen Warren <swarren@wwwdotorg.org> wrote:
>>>>> 
>>>>> 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.
>>>> 
>>>> I guess I should?ve put that in a comment somewhere. Unfortunately we
>>>> can?t. If I just return an error on probe, U-Boot will panic because
>>>> we tell it in a CONFIG define that we require a serial port (grep for
>>>> CONFIG_REQUIRE_SERIAL_CONSOLE).
>>>> 
>>>> We could maybe try to unset that define instead?
>>> 
>>> Yes, assuming that U-Boot runs just fine with HDMI console only, I think
>>> it's fine to unset CONFIG_REQUIRE_SERIAL_CONSOLE.
>>> 
>>>>> 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.
>>>> 
>>>> We can do that if we can fail at probe time. If we absolutely must
>>>> have a serial driver to work in the first place, that doesn?t work. I
>>>> can try to poke at it, but it?ll be a few days I think :).
>> 
>> So I couldn't find a sane way to fail probing based on something defined
>> in the board file, reusing the existing gpio device.
> 
> Would it be possible to move this code into the serial driver?

You mean like in v2 which Stephen nacked? :)

> 
>> 
>> However, there's an easy alternative. We can make the console code just
>> ignore our serial device if we set its pointer to NULL. That way we
>> still have the device, but can contain all logic to disable usage of the
>> mini uart to the board file.
> 
> I'm not very keen on that - feels like a hack.  What is stopping
> Stephen's idea from working? I could perhaps help with dm plumbing is
> that is the issue...

The problem is that we need the gpio device to determine whether the pin is muxed. There is no temporal control that I could see that would allow me to be in a place where the gpio device exists, the serial device does not exist, and where I could then not spawn the serial device based on board logic.


Alex

  reply	other threads:[~2016-08-12  5:27 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
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 [this message]
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=FDC03238-9876-4B26-AD9A-4D2875E80154@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.