public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Stephen Warren <swarren@wwwdotorg.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH v2 13/13] tegra: Convert tegra GPIO driver to use driver model
Date: Mon, 05 May 2014 16:07:28 -0600	[thread overview]
Message-ID: <53680BA0.5080802@wwwdotorg.org> (raw)
In-Reply-To: <CAPnjgZ0EuJf_O1f8gUbJG_LyrVh4bn0MhtiP4mhEQ2VTdKhkSQ@mail.gmail.com>

On 05/05/2014 03:30 PM, Simon Glass wrote:
...
> I think you have it backwards...the current implementation has a
> single level of hierarchy. Each driver handles one bank (or 'port' in
> the case of Tegra). What you are talking about is having a single
> driver handle multiple banks, thus requiring that the driver have a
> second level to deal with banks, over and above the device. We might
> end up with that, but I would prefer to move to it when we have
> evidence that it is a general need.

Sigh. This is getting silly. All the APIs in SW need to just take a GPIO
ID in the flat range 0..N (N==223 for Tegra20) and deal with it.
Anything that expose banks anywhere, either as a parameter to public
functions exported from the GPIO controller driver, or as the existence
of separate drivers for separate banks, or as a command-line argument
that the user sees, or ..., whether it be the U-Boot GPIO core or the
Tegra GPIO driver itself that causes this, is just pointless.

Please take a look at what the Linux driver does, and just model that.
It's very trivial. The following is the entire implementation of gpio_set():

> // helper macros used by all register accesses:
> #define GPIO_BANK(x)            ((x) >> 5)
> #define GPIO_PORT(x)            (((x) >> 3) & 0x3)
> #define GPIO_BIT(x)             ((x) & 0x7)
> 
> #define GPIO_REG(x)             (GPIO_BANK(x) * tegra_gpio_bank_stride + \
>                                         GPIO_PORT(x) * 4)
> 
> // one define per register
> #define GPIO_MSK_OUT(x)         (GPIO_REG(x) + tegra_gpio_upper_offset + 0x20)
>
> // helper used by a lot of set/clear functions
> static void tegra_gpio_mask_write(u32 reg, int gpio, int value)
> {
>         u32 val;
> 
>         val = 0x100 << GPIO_BIT(gpio);
>         if (value)
>                 val |= 1 << GPIO_BIT(gpio);
>         tegra_gpio_writel(val, reg);
> }
> 
> static void tegra_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
> {
>         tegra_gpio_mask_write(GPIO_MSK_OUT(offset), offset, value);
> }

i.e. a single register write with a calculated register address, using
just a few shifts/masks.

>>>> It seems like this should be statically allocated (e.g. as part of *plat
>>>> in gpio_tegra_bind() or something?). Still, if we stop splitting things
>>>> into banks, we can completely get rid of this.
>>>
>>> No, we still need the name so that 'gpio input T3' works corrrectly.
>>
>> Why do we need GPIO names at all? "gpio input 155" works just as well,
>> and to be honest is often a lot more convenient that trying to maps
>> things back to a name.
> 
> Eh? We need to support named GPIOs in U-Boot. 155 is a meaningless
> number which drivers people back and forth to the datasheets, their
> calculators, a long table, etc. Even the Tegra device tree has moved
> away from numbers to GPIO names, I notice.

The GPIO names are meaningless. I say this because all the Tegra
schematics (and documentation that drives them) use the pin/pad name,
which is almost always entirely different from the GPIO name. You have
to map the pin name back to either the GPIO name or ID using a lookup
table (such as the kernel's drivers/pinctrl/pinctrl-tegra20.c). Given
the need for a lookup table, we should just use the simpler GPIO ID and
not worry about GPIO names. There's no point screwing around with text
names when we can just use simple numbers.

In DT, GPIOs are specified by integer ID too. Admittedly we have macros
that calculate those IDs from the bank/port/offset, but that was
probably a mistake, since the bank/port/offset names aren't meaningful.

  reply	other threads:[~2014-05-05 22:07 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-05 16:08 [U-Boot] [RFC PATCH v2 0/13] Enable driver model for GPIOs on Tegra Simon Glass
2014-05-05 16:08 ` [U-Boot] [RFC PATCH v2 01/13] Add an I/O tracing feature Simon Glass
2014-05-05 16:08 ` [U-Boot] [RFC PATCH v2 02/13] arm: Support iotrace feature Simon Glass
2014-05-05 16:09 ` [U-Boot] [RFC PATCH v2 03/13] sandbox: " Simon Glass
2014-05-05 16:09 ` [U-Boot] [RFC PATCH v2 04/13] Makefile: Support include files for .dts files Simon Glass
2014-05-05 16:54   ` Stephen Warren
2014-05-07  2:15     ` Masahiro Yamada
2014-05-07 22:37       ` Simon Glass
2014-05-05 16:09 ` [U-Boot] [RFC PATCH v2 05/13] tegra: dts: Bring in GPIO bindings from linux Simon Glass
2014-05-05 16:57   ` Stephen Warren
2014-05-07 23:11     ` Simon Glass
2014-05-05 16:09 ` [U-Boot] [RFC PATCH v2 06/13] dm: Update README to encourage conversion to driver model Simon Glass
2014-05-05 16:09 ` [U-Boot] [RFC PATCH v2 07/13] dm: Use case-insensitive comparison for GPIO banks Simon Glass
2014-05-05 16:09 ` [U-Boot] [RFC PATCH v2 08/13] dm: Add missing header files in lists and root Simon Glass
2014-05-05 16:09 ` [U-Boot] [RFC PATCH v2 09/13] dm: Case away the const-ness of the global_data pointer Simon Glass
2014-05-05 16:09 ` [U-Boot] [RFC PATCH v2 10/13] dm: Allow driver model tests only for sandbox Simon Glass
2014-05-05 16:09 ` [U-Boot] [RFC PATCH v2 11/13] dm: Fix printf() strings in the 'dm' command Simon Glass
2014-05-05 16:09 ` [U-Boot] [RFC PATCH v2 12/13] tegra: Enable driver model Simon Glass
2014-05-05 16:58   ` Stephen Warren
2014-05-05 19:01     ` Simon Glass
2014-05-05 16:09 ` [U-Boot] [RFC PATCH v2 13/13] tegra: Convert tegra GPIO driver to use " Simon Glass
2014-05-05 17:29   ` Stephen Warren
2014-05-05 19:53     ` Simon Glass
2014-05-05 21:14       ` Stephen Warren
2014-05-05 21:30         ` Simon Glass
2014-05-05 22:07           ` Stephen Warren [this message]
2014-05-05 23:00             ` Simon Glass
2014-05-06 17:34               ` Stephen Warren
2014-05-06 20:28                 ` Simon Glass
2014-05-06 20:37                   ` Stephen Warren
2014-05-06 20:41                     ` Simon Glass
  -- strict thread matches above, loose matches on Subject: below --
2014-05-09 17:28 [U-Boot] [RFC PATCH v2 0/13] Enable driver model for GPIOs on Tegra Simon Glass
2014-05-09 17:28 ` [U-Boot] [RFC PATCH v2 13/13] tegra: Convert tegra GPIO driver to use driver model Simon Glass
2014-05-13 19:30   ` Stephen Warren
2014-05-22  1:25     ` 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=53680BA0.5080802@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox