From: Linus Walleij <linus.walleij@linaro.org>
To: Jonas Gorski <jonas.gorski@gmail.com>
Cc: "linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"Rob Herring" <robh+dt@kernel.org>,
"Mark Rutland" <mark.rutland@arm.com>,
"Kevin Cernekee" <cernekee@gmail.com>,
"Florian Fainelli" <f.fainelli@gmail.com>,
"Álvaro Fernández Rojas" <noltari@gmail.com>
Subject: Re: [PATCH 01/13] pinctrl: add bcm63xx base code
Date: Mon, 22 Aug 2016 14:46:00 +0200 [thread overview]
Message-ID: <CACRpkdbAWJruB=4rv_SoPZ5D5XgWjebK_Qmv2GLgOOrSyqXcDA@mail.gmail.com> (raw)
In-Reply-To: <1471604025-21575-2-git-send-email-jonas.gorski@gmail.com>
On Fri, Aug 19, 2016 at 12:53 PM, Jonas Gorski <jonas.gorski@gmail.com> wrote:
> Setup directory and add a helper for bcm63xx pinctrl support.
>
> Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
> drivers/pinctrl/bcm63xx/Kconfig | 3 +
> drivers/pinctrl/bcm63xx/Makefile | 1 +
Why not just put it in the existing pinctrl/bcm directory?
The drivers in there share nothing but being Broadcom
anyways. And when you're at it, do take a look at the
other Broadcom drivers to check if they would
happen to share something with your hardware, I find
it dazzling that hardware engineers repeatedly reinvents
pin controllers but what can I do.
> +config PINCTRL_BCM63XX
> + bool
> + select GPIO_GENERIC
depends on ARCH_****?
depends on OF_GPIO?
Will it really be used on non-DT systems?
> +#define BANK_SIZE sizeof(u32)
> +#define PINS_PER_BANK (BANK_SIZE * BITS_PER_BYTE)
> +
> +#ifdef CONFIG_OF
> +static int bcm63xx_gpio_of_xlate(struct gpio_chip *gc,
> + const struct of_phandle_args *gpiospec,
> + u32 *flags)
> +{
> + struct gpio_chip *base = gpiochip_get_data(gc);
> + int pin = gpiospec->args[0];
> +
> + if (gc != &base[pin / PINS_PER_BANK])
> + return -EINVAL;
> +
> + pin = pin % PINS_PER_BANK;
> +
> + if (pin >= gc->ngpio)
> + return -EINVAL;
> +
> + if (flags)
> + *flags = gpiospec->args[1];
> +
> + return pin;
> +}
> +#endif
- Do you really have to support the !OF_GPIO case? (depend in Kconfig,
get rid of #ifdef)
- The only reason for not using of_gpio_simple_xlate() seems to be that
you have several GPIO banks. So why not model every bank as a
separate device? Or did you consider this already?
> + gc[i].request = gpiochip_generic_request;
> + gc[i].free = gpiochip_generic_free;
> +
> +#ifdef CONFIG_OF
> + gc[i].of_gpio_n_cells = 2;
> + gc[i].of_xlate = bcm63xx_gpio_of_xlate;
> +#endif
> +
> + gc[i].label = label;
> + gc[i].ngpio = pins;
> +
> + devm_gpiochip_add_data(dev, &gc[i], gc);
Because this also gets pretty hairy... since you don't have one device
per gpiochip.
> +static void bcm63xx_setup_pinranges(struct gpio_chip *gc, const char *name,
> + int ngpio)
> +{
> + int i, chips = DIV_ROUND_UP(ngpio, PINS_PER_BANK);
> +
> + for (i = 0; i < chips; i++) {
> + int offset, pins;
> +
> + offset = i * PINS_PER_BANK;
> + pins = min_t(int, ngpio - offset, PINS_PER_BANK);
> +
> + gpiochip_add_pin_range(&gc[i], name, 0, offset, pins);
> + }
> +}
And this, same thing. Could be so much easier if it was just the same
driver instantiated twice for two banks.
> + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dirout");
> + dirout = devm_ioremap_resource(&pdev->dev, res);
> + if (IS_ERR(dirout))
> + return ERR_CAST(dirout);
> +
> + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
> + data = devm_ioremap_resource(&pdev->dev, res);
> + if (IS_ERR(data))
> + return ERR_CAST(data);
> +
> + sz = resource_size(res);
> +
> + ret = bcm63xx_setup_gpio(&pdev->dev, gc, dirout, data, sz, ngpio);
> + if (ret)
> + return ERR_PTR(ret);
> +
> + pctldev = devm_pinctrl_register(&pdev->dev, desc, priv);
> + if (IS_ERR(pctldev))
> + return pctldev;
> +
> + bcm63xx_setup_pinranges(gc, pinctrl_dev_get_devname(pctldev), ngpio);
> +
> + dev_info(&pdev->dev, "registered at mmio %p\n", dirout);
> +
> + return pctldev;
A current trend in simple MMIO devices is to simply add themselves as a
compatible string in drivers/gpio/gpio-mmio.c. Example:
https://git.kernel.org/cgit/linux/kernel/git/linusw/linux-gpio.git/commit/drivers/gpio/gpio-mmio.c?h=devel&id=05cc995f4d44c2b14a1f15f3271cc9715cb81099
This could be a viable approach if you find a way to flag that such a GPIO
has a pin control backend.
Yours,
Linus Walleij
next prev parent reply other threads:[~2016-08-22 12:46 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-19 10:53 [PATCH 00/13] pinctrl: add BCM63XX pincontrol support Jonas Gorski
2016-08-19 10:53 ` [PATCH 03/13] pinctrl: add a pincontrol driver for BCM6328 Jonas Gorski
2016-08-22 13:15 ` Linus Walleij
[not found] ` <CACRpkdbZDmHimo9K1rUcs-4MyOSZH5SHUD3kuSYANppLUU0WwQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-08-22 13:54 ` Jonas Gorski
2016-08-23 8:57 ` Linus Walleij
2016-08-19 10:53 ` [PATCH 04/13] Documentation: add BCM6348 pincontroller binding documentation Jonas Gorski
2016-08-22 13:17 ` Linus Walleij
2016-08-19 10:53 ` [PATCH 07/13] pinctrl: add a pincontrol driver for BCM6358 Jonas Gorski
2016-08-22 13:21 ` Linus Walleij
2016-08-22 13:57 ` Jonas Gorski
2016-08-23 9:18 ` Linus Walleij
2016-08-23 15:43 ` Re[2]: " Alexander Shiyan
2016-08-19 10:53 ` [PATCH 08/13] Documentation: add BCM6362 pincontroller binding documentation Jonas Gorski
[not found] ` <1471604025-21575-9-git-send-email-jonas.gorski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-08-22 13:22 ` Linus Walleij
2016-08-19 10:53 ` [PATCH 09/13] pinctrl: add a pincontrol driver for BCM6362 Jonas Gorski
[not found] ` <1471604025-21575-10-git-send-email-jonas.gorski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-08-22 13:23 ` Linus Walleij
2016-08-19 10:53 ` [PATCH 10/13] Documentation: add BCM6368 pincontroller binding documentation Jonas Gorski
[not found] ` <1471604025-21575-11-git-send-email-jonas.gorski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-08-22 13:24 ` Linus Walleij
[not found] ` <1471604025-21575-1-git-send-email-jonas.gorski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-08-19 10:53 ` [PATCH 01/13] pinctrl: add bcm63xx base code Jonas Gorski
2016-08-22 12:46 ` Linus Walleij [this message]
[not found] ` <CACRpkdbAWJruB=4rv_SoPZ5D5XgWjebK_Qmv2GLgOOrSyqXcDA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-08-22 13:44 ` Jonas Gorski
2016-08-23 9:15 ` Linus Walleij
2016-08-19 10:53 ` [PATCH 02/13] Documentation: add BCM6328 pincontroller binding documentation Jonas Gorski
2016-08-19 14:14 ` Rob Herring
2016-08-19 14:30 ` Jonas Gorski
[not found] ` <CAOiHx=mLgZ6Q3tBY3zYkCpMX09Kv54OQQoAXAdP16D_xoXO3mg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-08-22 12:51 ` Linus Walleij
2016-08-19 10:53 ` [PATCH 05/13] pinctrl: add a pincontrol driver for BCM6348 Jonas Gorski
[not found] ` <1471604025-21575-6-git-send-email-jonas.gorski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-08-22 13:19 ` Linus Walleij
2016-08-19 10:53 ` [PATCH 06/13] Documentation: add BCM6358 pincontroller binding documentation Jonas Gorski
[not found] ` <1471604025-21575-7-git-send-email-jonas.gorski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-08-22 13:20 ` Linus Walleij
2016-08-19 10:53 ` [PATCH 11/13] pinctrl: add a pincontrol driver for BCM6368 Jonas Gorski
[not found] ` <1471604025-21575-12-git-send-email-jonas.gorski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-08-22 13:25 ` Linus Walleij
2016-08-19 10:53 ` [PATCH 13/13] pinctrl: add a pincontrol driver for BCM63268 Jonas Gorski
[not found] ` <1471604025-21575-14-git-send-email-jonas.gorski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-08-22 13:26 ` Linus Walleij
2016-08-19 10:53 ` [PATCH 12/13] Documentation: add BCM63268 pincontroller binding documentation Jonas Gorski
2016-08-22 13:25 ` Linus Walleij
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='CACRpkdbAWJruB=4rv_SoPZ5D5XgWjebK_Qmv2GLgOOrSyqXcDA@mail.gmail.com' \
--to=linus.walleij@linaro.org \
--cc=cernekee@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=f.fainelli@gmail.com \
--cc=jonas.gorski@gmail.com \
--cc=linux-gpio@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=noltari@gmail.com \
--cc=robh+dt@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).