All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dr. Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v1 02/11] sunxi: add pinctrl (UCLASS_PINCTRL) support for sunxi and tie back into GPIO
Date: Tue, 21 Feb 2017 10:39:34 +0100	[thread overview]
Message-ID: <8AE58EED-65DC-4779-A09C-230B587B55B2@theobroma-systems.com> (raw)
In-Reply-To: <CAGb2v66=4_Xt2kR7xnny3poPS52Y7XRucOrCTwJnB0GVZ3Y5=A@mail.gmail.com>

Chen,

> On 21 Feb 2017, at 04:48, Chen-Yu Tsai <wens@csie.org> wrote:
> 
> On Sat, Feb 18, 2017 at 1:52 AM, Philipp Tomsich
> <philipp.tomsich at theobroma-systems.com <mailto:philipp.tomsich@theobroma-systems.com>> wrote:
>> This change adds a full device-model pinctrl driver for sunxi (tested with
>> sun50iw1p1) based on the support available in Linux.
>> 
>> Details are:
>> * implements a driver for pinctrl devices and assigns sun50i-a64-pinctrl
>>   and sun50i-a64-r-pinctrl to it
>> * defines and implements a binding for sunxi-style GPIO banks (to make it
>>   easier to describe controllers like the A64 which may not start at 'A')
>>   and provide the necessary translation mechanisms:
>>   - As all our gpio-reference point back to either <&pio ..> or <&r_pio ..>
>>     the device framework will try to access a UCLASS_GPIO device bound to
>>     the same node id as the pinctrl device to perform it's of_xlate lookup.
>>     For this, we provide a 'gpiobridge' driver (which needs to access the
>>     platdata of the pinctrl device) and which can then map accesses to an
>>     actual GPIO bank device.
>>   - For the individual GPIO banks, we use a new driver (which shares most
>>     of its ops with the existing sunxi_gpio driver, except probe and bind)
>>     and provides configuration without any platdata structure.
> 
> Why is the new binding and driver necessary? The existing driver in U-boot is
> already DM enabled and properly xlates GPIO phandles to its child GPIO banks.
> I specifically fixed this in commit 4694dc56e974 ("sunxi: gpio: Add .xlate
> function for gpio phandle resolution?).

The problem is that all GPIO is referenced to the pinctrl-node.  As we need to
provide a pinctrl driver (so the configuration of pins can go through that) for
the pinconfig to work, the GPIOs are then referenced to that node.

We had considered multiple solutions
(a)	the one we?ve chosen, which avoids having to provide additional data
	outside the device-tree to track the number of banks and bank-size
(b)	binding the existing gpio driver to the same node (but as the driverdata
	needs to be matched as well, we?d need to select this based on the
	compatible string and have a tighter coupling between the drivers than
	strictly necessary)
(c)	dynamically creating gpio subnodes (just as done by the top-level
	sunxi_gpio instances) for each of the banks from within the pinctrl driver

Another reason why we felt the gpiobank to be helpful is that it allows us to
easily describe where the register sets (i.e. PIO and IRQ) are for each bank.

> You are also not using the new gpiobank nodes anywhere in your dts changes.

The DTS change is in the same patch as the the pinctrl driver:
	http://lists.denx.de/pipermail/u-boot/2017-February/281637.html <http://lists.denx.de/pipermail/u-boot/2017-February/281637.html>

I had generated this with full function context, which makes the diff in the DTS
hard to spot.

>> +#if defined(CONFIG_SUNXI_PINCTRL)
>> +
>> +/* When we use the sunxi pinctrl infrastructure, we have two issues that
>> + * are resolved by the gpiobank and gpiobrige drivers:
>> + *
>> + *  - We need to have a UCLASS_GPIO device bound to the pinctrl-nodes for
>> + *    translating between gpio entries (e.g. <&pio 3 24 GPIO_ACTIVE_LOW>;)
>> + *    in the DT and actual gpio banks. This is done using the gpiobridge
>> + *    driver, which provides only a lookup/translation mechanism.
>> + *    This mechanism lives in pinctrl-sunxi.c
>> + *
>> + *  - We introduce a generic gpiobank device, which resolves the need to
>> + *    have distinct soc_data structure for each device and avoids having
>> + *    to share data structures and config data between this file and the
>> + *    sunxi pinctrl (the other option would be to have the soc_data info
>> + *    visible in pinctrl-sunxi.c (or merge it into this file) and bind a
>> + *    gpio_sunxi device that is set up with the appropriate soc_data) to
>> + *    the same node as the pinctrl device.
> 
> Pushing hardware internals into the DT is not preferred.

That?s exactly the point: the current DT format encapsulates the internal
grouping of the hardware blocks into larger address-decoding groups. For
the case of pinctrl and GPIO, the actual structure looks as follows:
	+ ?bunch of registers?
			+ N x [pinctrl functionality for a pin-group]
			+ N x [irq-control for a pin-group]
			+ N x [GPIO functionality for a pin-group]

So if I were asked to model this from scratch, I?d use a regmap-device for
the PIO and R_PIO address spaces and then reference the pinctrl and gpio
functionality back to it (hiding the internals of how each bank assigns bits
and where).

> Since the pinctrl and gpio drivers actually driver the same hardware block,
> just in different ways, and there should be some locking between the two,
> I think it would make sense to merge the two.
> 
> You can also get away with not having soc_data by just registering the full
> set of GPIO banks and pins (we aren't counting extra pins anyway).

Merging the pinctrl and gpio drivers is going to be tricky, as a driver can only
have a single class.

The more immediate solution would be to simply derive the appropriate driver
data for the existing gpio class and manually bind a driver to the node (see 
option ?b? from above).

This will then require sharing the (internal) driver data structure from the
gpio-driver with pinctrl and populating it from the pinctrl probe? i.e. we had
this in an earlier version of the changes, but it looked messy.

Before we revert to this model, I?ll wait if a consensus emerges from the
discussion here.


Regards,
Philipp.

  reply	other threads:[~2017-02-21  9:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-17 17:52 [U-Boot] [PATCH v1 00/11] sunxi: DM drivers for CLK, RESET and PINCTRL Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 01/11] spl: dm: Undefine DM_MMC, DM_MMC_OPS and BLK, if SPL_DM is not defined Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 02/11] sunxi: add pinctrl (UCLASS_PINCTRL) support for sunxi and tie back into GPIO Philipp Tomsich
2017-02-21  3:48   ` Chen-Yu Tsai
2017-02-21  9:39     ` Dr. Philipp Tomsich [this message]
2017-02-22  6:07       ` Chen-Yu Tsai
2017-02-22  9:26         ` Dr. Philipp Tomsich
2017-02-21 20:14   ` Maxime Ripard
2017-02-17 17:52 ` [U-Boot] [PATCH v1 03/11] sun50i: dts: add gpiobank nodes to the pinctrl nodes Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 04/11] sun50i: dts: update DTS to avoid warnings Philipp Tomsich
2017-02-21 20:15   ` Maxime Ripard
2017-02-17 17:52 ` [U-Boot] [PATCH v1 05/11] sunxi: add module reset (UCLASS_RESET) support for sunxi Philipp Tomsich
2017-02-21 20:16   ` Maxime Ripard
2017-02-17 17:52 ` [U-Boot] [PATCH v1 06/11] sunxi: add clock driver (UCLASS_CLK) " Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 07/11] sunxi: Scan DT tree node '/clocks' on sunxi boards Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 08/11] sun8i_emac: update to work with pinctrl-sunxi, reset-sunxi and clk-sunxi Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 09/11] sunxi_mmc: convert to a device-model driver Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 10/11] dts: sun50i: update mmc pin configuration and add mmc2_8bit_pins Philipp Tomsich
2017-02-17 17:52 ` [U-Boot] [PATCH v1 11/11] sun50i: dts: add spi0 and spi1 nodes and pinconfig Philipp Tomsich

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=8AE58EED-65DC-4779-A09C-230B587B55B2@theobroma-systems.com \
    --to=philipp.tomsich@theobroma-systems.com \
    --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.