pinctrl: Intel Cherryview/Braswell support
Subsystems (3)
Mika Westerberg
maintainercover pinctrl: Intel Cherryview/Braswell support
[The previous series never reached LKML to misconfiguration in my mailer.
Resending the whole series with LKML included.]
Hi,
This is a complete rewrite of the GPIO driver patch I sent previously. The mail thread can be found here:
http://marc.info/?l=linux-gpio&m=141079024403000&w=2
Outcome of that discussion was that instead of GPIO driver, we should have a combined pinctrl/GPIO driver.
This patch series implements pinctrl/GPIO driver for Intel Cherryview/Braswell. While there we decided to put all Intel pinctrl drivers under drivers/pinctrl/intel/* and add an entry to MAINTAINERS. We are expecting to have more pinctrl drivers in future for Intel hardware.
Mika Westerberg (4):
gpio / ACPI: Add knowledge about pin controllers to acpi_get_gpiod()
pinctrl: Move Intel Baytrail pinctrl driver under intel directory
MAINTAINERS: Add entry for Intel pin controller drivers
pinctrl: Add Intel Cherryview/Braswell pin controller support
MAINTAINERS | 6 +
drivers/gpio/gpiolib-acpi.c | 62 +-
drivers/pinctrl/Kconfig | 13 +-
drivers/pinctrl/Makefile | 2 +-
drivers/pinctrl/intel/Kconfig | 27 +
drivers/pinctrl/intel/Makefile | 4 +
drivers/pinctrl/{ => intel}/pinctrl-baytrail.c | 0
drivers/pinctrl/intel/pinctrl-cherryview.c | 1507 ++++++++++++++++++++++++
8 files changed, 1605 insertions(+), 16 deletions(-)
create mode 100644 drivers/pinctrl/intel/Kconfig
create mode 100644 drivers/pinctrl/intel/Makefile
rename drivers/pinctrl/{ => intel}/pinctrl-baytrail.c (100%)
create mode 100644 drivers/pinctrl/intel/pinctrl-cherryview.cSignature · 1 line
2.1.1
Mika Westerberg
maintainerPATCH 1/4 gpio / ACPI: Add knowledge about pin controllers to acpi_get_gpiod()
The GPIO resources (GpioIo/GpioInt) used in ACPI contain a GPIO number which is relative to the hardware GPIO controller. Typically this number can be translated directly to Linux GPIO number because the mapping is pretty much 1:1.
However, when the GPIO driver is using pins exported by a pin controller driver via set of GPIO ranges, the mapping might not be 1:1 anymore and direct translation does not work.
In such cases we need to translate the ACPI GPIO number to be suitable for the GPIO controller driver in question by checking all the pin controller GPIO ranges under the given device and using those to get the proper GPIO number.
---
Rafael, are you OK with this change?
drivers/gpio/gpiolib-acpi.c | 62 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-)
drivers/gpio/gpiolib-acpi.c +59 -3
@@ -11,12 +11,14 @@*/ #include <linux/errno.h> +#include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/gpio/driver.h> #include <linux/export.h> #include <linux/acpi.h> #include <linux/interrupt.h> #include <linux/mutex.h> +#include <linux/pinctrl/pinctrl.h> #include "gpiolib.h"
@@ -55,6 +57,58 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)return ACPI_HANDLE (gc->dev) == data; } +#ifdef CONFIG_PINCTRL +/** +* acpi_gpiochip_pin_to_gpio_offset() - translates ACPI GPIO to Linux GPIO +* @chip: GPIO chip +* @pin: ACPI GPIO pin number from GpioIo/GpioInt resource +* +* Function takes ACPI GpioIo/GpioInt pin number as a parameter and +* translates it to a corresponding offset suitable to be passed to a +* GPIO controller driver. +* +* Typically the returned offset is same as @pin, but if the GPIO +* controller uses pin controller and the mapping is not contigous the +* offset might be different. +*/ +static int acpi_gpiochip_pin_to_gpio_offset (struct gpio_chip *chip,int pin) +{ +struct gpio_pin_range *pin_range; + +/* If there are no ranges in this chip, use 1:1 mapping */ +if (list_empty (&chip->pin_ranges)) +return pin; + +list_for_each_entry (pin_range, &chip->pin_ranges, node) { +const struct pinctrl_gpio_range *range = &pin_range->range; +int i; + +if (range->pins) { +for (i =0 ; i < range->npins; i++) { +if (range->pins[i] == pin) +return range->base + i - chip->base; + } + }else { +if (pin >= range->pin_base && + pin < range->pin_base + range->npins) { +unsigned gpio_base; + + gpio_base = range->base - chip->base; +return gpio_base + pin - range->pin_base; + } + } + } + +return -EINVAL ; +} +#else +static inline int acpi_gpiochip_pin_to_gpio_offset (struct gpio_chip *chip, +int pin) +{ +return pin; +} +#endif +/** * acpi_get_gpiod() - Translate ACPI GPIO pin to GPIO descriptor usable with GPIO API * @path: ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1")
@@ -69,6 +123,7 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)struct gpio_chip *chip;acpi_handle handle;acpi_status status; +int offset; status =acpi_get_handle (NULL , path, &handle);if (ACPI_FAILURE (status))
@@ -78,10 +133,11 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)if (!chip)return ERR_PTR (-ENODEV ); -if (pin <0 || pin > chip->ngpio) -return ERR_PTR (-EINVAL ); + offset =acpi_gpiochip_pin_to_gpio_offset (chip, pin); +if (offset <0 ) +return ERR_PTR (offset); -return gpiochip_get_desc (chip, pin); +return gpiochip_get_desc (chip, (u16 )offset); }static irqreturn_t acpi_gpio_irq_handler (int irq,void *data)
Signature · 1 line
2.1.1
Re: [PATCH 1/4] gpio / ACPI: Add knowledge about pin controllers to acpi_get_gpiod()
Quoted 9 lines · Mika Westerberg
The GPIO resources (GpioIo/GpioInt) used in ACPI contain a GPIO number which is relative to the hardware GPIO controller. Typically this number can be translated directly to Linux GPIO number because the mapping is pretty much 1:1.
However, when the GPIO driver is using pins exported by a pin controller driver via set of GPIO ranges, the mapping might not be 1:1 anymore and direct translation does not work.
Quoted 8 lines
In such cases we need to translate the ACPI GPIO number to be suitable for the GPIO controller driver in question by checking all the pin controller GPIO ranges under the given device and using those to get the proper GPIO number.
Signed-off-by Mika Westerberg <[email protected]>---
Rafael, are you OK with this change?
Yes, I am, so
And I have no idea how to do that in a more straightforward way.
Of course ->
Quoted 57 lines
drivers/gpio/gpiolib-acpi.c | 62 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-)drivers/gpio/gpiolib-acpi.c +32
-0@@ -11,12 +11,14 @@*/ #include <linux/errno.h> +#include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/gpio/driver.h> #include <linux/export.h> #include <linux/acpi.h> #include <linux/interrupt.h> #include <linux/mutex.h> +#include <linux/pinctrl/pinctrl.h> #include "gpiolib.h" @@ -55,6 +57,58 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)return ACPI_HANDLE (gc->dev) == data; } +#ifdef CONFIG_PINCTRL +/** +* acpi_gpiochip_pin_to_gpio_offset() - translates ACPI GPIO to Linux GPIO +* @chip: GPIO chip +* @pin: ACPI GPIO pin number from GpioIo/GpioInt resource +* +* Function takes ACPI GpioIo/GpioInt pin number as a parameter and +* translates it to a corresponding offset suitable to be passed to a +* GPIO controller driver. +* +* Typically the returned offset is same as @pin, but if the GPIO +* controller uses pin controller and the mapping is not contigous the +* offset might be different. +*/ +static int acpi_gpiochip_pin_to_gpio_offset (struct gpio_chip *chip,int pin) +{ +struct gpio_pin_range *pin_range; + +/* If there are no ranges in this chip, use 1:1 mapping */ +if (list_empty (&chip->pin_ranges)) +return pin; + +list_for_each_entry (pin_range, &chip->pin_ranges, node) { +const struct pinctrl_gpio_range *range = &pin_range->range; +int i; + +if (range->pins) { +for (i =0 ; i < range->npins; i++) { +if (range->pins[i] == pin) +return range->base + i - chip->base;
drivers/gpio/gpiolib-acpi.c static int acpi_gpiochip_find(struct gpio_chip *gc, void *data) · line 99
Quoted 10 lines
drivers/gpio/gpiolib-acpi.c +10
-0+ } + }else { +if (pin >= range->pin_base && + pin < range->pin_base + range->npins) { +unsigned gpio_base; + + gpio_base = range->base - chip->base; +return gpio_base + pin - range->pin_base; + } + }
-> this is only going to work if the pin mapping in chip->pin_ranges doesn't change after it has returned the offset, but I'm assiming that this is the case.
Quoted 25 lines
drivers/gpio/gpiolib-acpi.c +13
-0+ } + +return -EINVAL ; +} +#else +static inline int acpi_gpiochip_pin_to_gpio_offset (struct gpio_chip *chip, +int pin) +{ +return pin; +} +#endif +/** * acpi_get_gpiod() - Translate ACPI GPIO pin to GPIO descriptor usable with GPIO API * @path: ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1") @@ -69,6 +123,7 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)struct gpio_chip *chip;acpi_handle handle;acpi_status status; +int offset; status =acpi_get_handle (NULL , path, &handle);if (ACPI_FAILURE (status))@@ -78,10 +133,11 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)if (!chip)
drivers/gpio/gpiolib-acpi.c static struct gpio_desc *acpi_get_gpiod(char *path, int pin) · line 140
Quoted 10 lines
drivers/gpio/gpiolib-acpi.c +4
-3return ERR_PTR (-ENODEV ); -if (pin <0 || pin > chip->ngpio) -return ERR_PTR (-EINVAL ); + offset =acpi_gpiochip_pin_to_gpio_offset (chip, pin); +if (offset <0 ) +return ERR_PTR (offset); -return gpiochip_get_desc (chip, pin); +return gpiochip_get_desc (chip, (u16 )offset);
Silly question: Why do we need the explicit u16 cast now?
Quoted 4 lines
drivers/gpio/gpiolib-acpi.c +0
-0}static irqreturn_t acpi_gpio_irq_handler (int irq,void *data)
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Mika Westerberg
maintainerRe: [PATCH 1/4] gpio / ACPI: Add knowledge about pin controllers to acpi_get_gpiod()
Quoted 15 lines · Rafael J. Wysocki
Quoted 14 lines · Mika Westerberg
The GPIO resources (GpioIo/GpioInt) used in ACPI contain a GPIO number which is relative to the hardware GPIO controller. Typically this number can be translated directly to Linux GPIO number because the mapping is pretty much 1:1.
However, when the GPIO driver is using pins exported by a pin controller driver via set of GPIO ranges, the mapping might not be 1:1 anymore and direct translation does not work.
In such cases we need to translate the ACPI GPIO number to be suitable for the GPIO controller driver in question by checking all the pin controller GPIO ranges under the given device and using those to get the proper GPIO number.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Mika Westerberg <[email protected]>---
Rafael, are you OK with this change?Yes, I am, so
Thanks.
Quoted 66 lines
And I have no idea how to do that in a more straightforward way.
Of course ->
Quoted 62 lines
drivers/gpio/gpiolib-acpi.c | 62 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-)drivers/gpio/gpiolib-acpi.c +37
-0@@ -11,12 +11,14 @@*/ #include <linux/errno.h> +#include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/gpio/driver.h> #include <linux/export.h> #include <linux/acpi.h> #include <linux/interrupt.h> #include <linux/mutex.h> +#include <linux/pinctrl/pinctrl.h> #include "gpiolib.h" @@ -55,6 +57,58 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)return ACPI_HANDLE (gc->dev) == data; } +#ifdef CONFIG_PINCTRL +/** +* acpi_gpiochip_pin_to_gpio_offset() - translates ACPI GPIO to Linux GPIO +* @chip: GPIO chip +* @pin: ACPI GPIO pin number from GpioIo/GpioInt resource +* +* Function takes ACPI GpioIo/GpioInt pin number as a parameter and +* translates it to a corresponding offset suitable to be passed to a +* GPIO controller driver. +* +* Typically the returned offset is same as @pin, but if the GPIO +* controller uses pin controller and the mapping is not contigous the +* offset might be different. +*/ +static int acpi_gpiochip_pin_to_gpio_offset (struct gpio_chip *chip,int pin) +{ +struct gpio_pin_range *pin_range; + +/* If there are no ranges in this chip, use 1:1 mapping */ +if (list_empty (&chip->pin_ranges)) +return pin; + +list_for_each_entry (pin_range, &chip->pin_ranges, node) { +const struct pinctrl_gpio_range *range = &pin_range->range; +int i; + +if (range->pins) { +for (i =0 ; i < range->npins; i++) { +if (range->pins[i] == pin) +return range->base + i - chip->base; + } + }else { +if (pin >= range->pin_base && + pin < range->pin_base + range->npins) { +unsigned gpio_base;
Quoted 8 lines
drivers/gpio/gpiolib-acpi.c static int acpi_gpiochip_find(struct gpio_chip *gc, void *data) · line 99
Quoted 5 lines
drivers/gpio/gpiolib-acpi.c +5
-0+ + gpio_base = range->base - chip->base; +return gpio_base + pin - range->pin_base; + } + }-> this is only going to work if the pin mapping in
chip->pin_rangesdoesn't change after it has returned the offset, but I'm assiming that this is the case.
I think that is the case here. At least the pinctrl-cherryview.c sets up GPIO <-> pin mappings only once in probe().
Quoted 33 lines
Quoted 33 lines
drivers/gpio/gpiolib-acpi.c +16
-2+ } + +return -EINVAL ; +} +#else +static inline int acpi_gpiochip_pin_to_gpio_offset (struct gpio_chip *chip, +int pin) +{ +return pin; +} +#endif +/** * acpi_get_gpiod() - Translate ACPI GPIO pin to GPIO descriptor usable with GPIO API * @path: ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1") @@ -69,6 +123,7 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)struct gpio_chip *chip;acpi_handle handle;acpi_status status; +int offset; status =acpi_get_handle (NULL , path, &handle);if (ACPI_FAILURE (status))@@ -78,10 +133,11 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)if (!chip)return ERR_PTR (-ENODEV ); -if (pin <0 || pin > chip->ngpio) -return ERR_PTR (-EINVAL ); + offset =acpi_gpiochip_pin_to_gpio_offset (chip, pin); +if (offset <0 ) +return ERR_PTR (offset);
Quoted 4 lines
drivers/gpio/gpiolib-acpi.c static struct gpio_desc *acpi_get_gpiod(char *path, int pin) · line 140
Quoted 2 lines
drivers/gpio/gpiolib-acpi.c +1
-1-return gpiochip_get_desc (chip, pin); +return gpiochip_get_desc (chip, (u16 )offset);Silly question: Why do we need the explicit u16 cast now?
It seems that we don't need it after all.
I'll fix this up in the next version, given that Linus W. is happy about the approach I'm using here.
Quoted 9 lines
Quoted 5 lines
drivers/gpio/gpiolib-acpi.c +0
-0}static irqreturn_t acpi_gpio_irq_handler (int irq,void *data)Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Mika Westerberg
maintainerPATCH 2/4 pinctrl: Move Intel Baytrail pinctrl driver under intel directory
In reply to Mika WesterbergWe are going to have more pinctrl drivers for Intel hardware so separate all our pin controller drivers to own directory.
---
Mathias, can you ACK this if you are happy with the change?
drivers/pinctrl/Kconfig | 13 +------------
drivers/pinctrl/Makefile | 2 +-
drivers/pinctrl/intel/Kconfig | 15 +++++++++++++++
drivers/pinctrl/intel/Makefile | 3 +++
drivers/pinctrl/{ => intel}/pinctrl-baytrail.c | 0
5 files changed, 20 insertions(+), 13 deletions(-)
create mode 100644 drivers/pinctrl/intel/Kconfig
create mode 100644 drivers/pinctrl/intel/Makefile
rename drivers/pinctrl/{ => intel}/pinctrl-baytrail.c (100%)drivers/pinctrl/Kconfig +1 -12
@@ -67,18 +67,6 @@ config PINCTRL_AT91 help Say Y here to enable the at91 pinctrl driver -config PINCTRL_BAYTRAIL - bool "Intel Baytrail GPIO pin control" - depends on GPIOLIB && ACPI && X86 - select GPIOLIB_IRQCHIP - help - driver for memory mapped GPIO functionality on Intel Baytrail - platforms. Supports 3 banks with 102, 28 and 44 gpios. - Most pins are usually muxed to some other functionality by firmware, - so only a small amount is available for gpio use. - - Requires ACPI device enumeration code to set up a platform device. - config PINCTRL_BCM2835 bool select PINMUX
@@ -205,6 +193,7 @@ config PINCTRL_PALMAS source "drivers/pinctrl/berlin/Kconfig" source "drivers/pinctrl/freescale/Kconfig" +source "drivers/pinctrl/intel/Kconfig" source "drivers/pinctrl/mvebu/Kconfig" source "drivers/pinctrl/nomadik/Kconfig" source "drivers/pinctrl/qcom/Kconfig"
drivers/pinctrl/Makefile +1 -1
@@ -15,7 +15,6 @@ obj-$(CONFIG_PINCTRL_BF54x) += pinctrl-adi2-bf54x.o obj-$(CONFIG_PINCTRL_BF60x) += pinctrl-adi2-bf60x.o obj-$(CONFIG_PINCTRL_AT91) += pinctrl-at91.o obj-$(CONFIG_PINCTRL_BCM2835) += pinctrl-bcm2835.o -obj-$(CONFIG_PINCTRL_BAYTRAIL) += pinctrl-baytrail.o obj-$(CONFIG_PINCTRL_BCM281XX) += pinctrl-bcm281xx.o obj-$(CONFIG_PINCTRL_FALCON) += pinctrl-falcon.o obj-$(CONFIG_PINCTRL_PALMAS) += pinctrl-palmas.o
@@ -39,6 +38,7 @@ obj-$(CONFIG_PINCTRL_ST) += pinctrl-st.o obj-$(CONFIG_ARCH_BERLIN) += berlin/ obj-y += freescale/ +obj-$(CONFIG_X86) += intel/ obj-$(CONFIG_PLAT_ORION) += mvebu/ obj-y += nomadik/ obj-$(CONFIG_ARCH_QCOM) += qcom/
drivers/pinctrl/intel/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +# +# Intel pin control drivers +# + +config PINCTRL_BAYTRAIL + bool "Intel Baytrail GPIO pin control" + depends on GPIOLIB && ACPI + select GPIOLIB_IRQCHIP + help + driver for memory mapped GPIO functionality on Intel Baytrail + platforms. Supports 3 banks with 102, 28 and 44 gpios. + Most pins are usually muxed to some other functionality by firmware, + so only a small amount is available for gpio use. + + Requires ACPI device enumeration code to set up a platform device.
drivers/pinctrl/intel/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# Intel pin control drivers + +obj-$(CONFIG_PINCTRL_BAYTRAIL) += pinctrl-baytrail.o
drivers/pinctrl/intel/pinctrl-baytrail.c renamed from drivers/pinctrl/pinctrl-baytrail.c +0 -0
Signature · 1 line
2.1.1
Mika Westerberg
maintainerPATCH 3/4 MAINTAINERS: Add entry for Intel pin controller drivers
In reply to Mika WesterbergAdd MAINTAINERS entry for Intel pin controller drivers. I will be maintaining them with Heikki, who kindly promised to help me with this.
--- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
@@ -7163,6 +7163,12 @@ L: [email protected] (moderated for non-subscribers) S: Maintained F: drivers/pinctrl/pinctrl-at91.c +PIN CONTROLLER - INTEL +M: Mika Westerberg <[email protected]> +M: Heikki Krogerus <[email protected]> +S: Maintained +F: drivers/pinctrl/intel/ + PIN CONTROLLER - RENESAS M: Laurent Pinchart <[email protected]> L: [email protected]
Signature · 1 line
2.1.1
Mika Westerberg
maintainerPATCH 4/4 pinctrl: Add Intel Cherryview/Braswell pin controller support
In reply to Mika WesterbergThis driver supports the pin/GPIO controllers found in newer Intel SoCs like Cherryview and Braswell. The driver provides full GPIO support and minimal set of pin controlling funtionality.
The driver is based on the original Cherryview GPIO driver authored by Ning Li and Alan Cox.
--- drivers/pinctrl/intel/Kconfig | 12 + drivers/pinctrl/intel/Makefile | 1 + drivers/pinctrl/intel/pinctrl-cherryview.c | 1507 ++++++++++++++++++++++++++++ 3 files changed, 1520 insertions(+) create mode 100644 drivers/pinctrl/intel/pinctrl-cherryview.c
drivers/pinctrl/intel/Kconfig +12 -0
@@ -13,3 +13,15 @@ config PINCTRL_BAYTRAIL so only a small amount is available for gpio use. Requires ACPI device enumeration code to set up a platform device. + +config PINCTRL_CHERRYVIEW + tristate "Intel Cherryview/Braswell pinctrl and GPIO driver" + depends on ACPI + select PINMUX + select PINCONF + select GENERIC_PINCONF + select GPIOLIB + select GPIOLIB_IRQCHIP + help + Cherryview/Braswell pinctrl driver provides an interface that + allows configuring of SoC pins and using them as GPIOs.
drivers/pinctrl/intel/Makefile +1 -0
@@ -1,3 +1,4 @@ # Intel pin control drivers obj-$(CONFIG_PINCTRL_BAYTRAIL) += pinctrl-baytrail.o +obj-$(CONFIG_PINCTRL_CHERRYVIEW) += pinctrl-cherryview.o
drivers/pinctrl/intel/pinctrl-cherryview.c new file +1507 -0
1,507 lines not on this page · raw message
Signature · 1 line
2.1.1