pinctrl: Add Intel Cherryview/Braswell pin controller support
A message that is not in the archive (sent off-list or not yet received): 1414153014-152246-1-git-send-email-mika.westerberg@linux.intel.com
A message that is not in the archive (sent off-list or not yet received): 1414153014-152246-5-git-send-email-mika.westerberg@linux.intel.com
Quoted 8 lines · Mika Westerberg
This 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.
Signed-off-by Mika Westerberg <[email protected]>
*VERY* nice work Mika! Just minor nitpicks...
(...)
Quoted 20 lines
(quoted diff) +20
-0+static int chv_config_get(struct pinctrl_dev *pctldev, unsigned pin, + unsigned long *config) +{ + struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); + enum pin_config_param param = pinconf_to_config_param(*config); + unsigned long flags; + u32 ctrl0, ctrl1; + u16 arg = 0; + u32 term; + + spin_lock_irqsave(&pctrl->lock, flags); + ctrl0 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); + ctrl1 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL1)); + spin_unlock_irqrestore(&pctrl->lock, flags); + + term = (ctrl0 & CHV_PADCTRL0_TERM_MASK) >> CHV_PADCTRL0_TERM_SHIFT; + + switch (param) { + case PIN_CONFIG_BIAS_DISABLE: + if (term)
Review
Quoted 10 lines
(quoted diff) +10
-0+ return -EINVAL; + break; + + case PIN_CONFIG_BIAS_PULL_UP: + if (!(ctrl0 & CHV_PADCTRL0_TERM_UP)) + return -EINVAL; + + switch (term) { + case CHV_PADCTRL0_TERM_20K: + arg = 20;
These are in Ohms IIRC so should be 20000
Review
Quoted 3 lines
(quoted diff) +3
-0+ break; + case CHV_PADCTRL0_TERM_5K: + arg = 5;
5000
Review
Quoted 3 lines
(quoted diff) +3
-0+ break; + case CHV_PADCTRL0_TERM_1K: + arg = 1;
1000
Review
Quoted 12 lines
(quoted diff) +12
-0+ break; + } + + break; + + case PIN_CONFIG_BIAS_PULL_DOWN: + if (!term || (ctrl0 & CHV_PADCTRL0_TERM_UP)) + return -EINVAL; + + switch (term) { + case CHV_PADCTRL0_TERM_20K: + arg = 20;
20000
Review
Quoted 3 lines
(quoted diff) +3
-0+ break; + case CHV_PADCTRL0_TERM_5K: + arg = 5;
5000
(...)
Review
Quoted 12 lines
(quoted diff) +12
-0+static int chv_config_set_pull(struct chv_pinctrl *pctrl, unsigned pin, + enum pin_config_param param, u16 arg) +{ + void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL0); + unsigned long flags; + u32 ctrl0, pull; + + spin_lock_irqsave(&pctrl->lock, flags); + ctrl0 = readl(reg); + + pull = CHV_PADCTRL0_TERM_20K << CHV_PADCTRL0_TERM_SHIFT; + switch (arg) {
This looks seriously convoluted: you can't inspect an argument before checking what parameter you're dealing with. This should be under a case PIN_CONFIG_BIAS_PULL_UP in the switch (param) below I think?
Quoted 1 line
+ case 1:
case 1000
Review
Quoted 3 lines
(quoted diff) +3
-0+ /* For 1k there is only pull up */ + if (param == PIN_CONFIG_BIAS_PULL_UP) + pull = CHV_PADCTRL0_TERM_1K << CHV_PADCTRL0_TERM_SHIFT;
Well you do check it here but...0
Review
Quoted 2 lines
(quoted diff) +2
-0+ break; + case 5:
case 5000
Quoted 1 line
+ pull =
CHV_PADCTRL0_TERM_5K<<CHV_PADCTRL0_TERM_SHIFT;
This will be applied to whatever config with arg == 5000 comes here!
(...)
Review
Quoted 5 lines
(quoted diff) +5
-0+static unsigned chv_gpio_offset_to_pin(struct chv_pinctrl *pctrl, + unsigned offset) +{ + return pctrl->community->pins[offset].number; +}
I'm a bit worried about the massive pin<->offsets<->gpio# translations happening in this and patch 1/4 etc. It's a bit unsettling. Are you sure we are translating in the simplest way?
Review
Quoted 10 lines
(quoted diff) +10
-0+static int chv_gpio_get(struct gpio_chip *chip, unsigned offset) +{ + struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(chip); + int pin = chv_gpio_offset_to_pin(pctrl, offset); + unsigned long flags; + u32 ctrl0, cfg; + + spin_lock_irqsave(&pctrl->lock, flags); + ctrl0 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); + spin_unlock_irqrestore(&pctrl->lock, flags);
If you need a lock before and after reading every register in this range, consider regmap-mmio, because that is part of what it does. Just a hint...
(...)
Quoted 7 lines
(quoted diff) +7
-0+static void chv_gpio_irq_mask_unmask(struct irq_data *d, bool mask) +{ + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); + struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(gc); + int pin = chv_gpio_offset_to_pin(pctrl, irqd_to_hwirq(d)); + u32 value, intr_line; + unsigned long flags;
Review
Quoted 10 lines
(quoted diff) +10
-0+ + spin_lock_irqsave(&pctrl->lock, flags); + + intr_line = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); + intr_line &= CHV_PADCTRL0_INTSEL_MASK; + intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT; + + value = readl(pctrl->regs + CHV_INTMASK); + if (mask) + value &= ~(1 << intr_line);
I usually do this kind of stuff with
#include <linux/bitops.h>
value &= ~BIT(intr_line);
Review
Quoted 2 lines
(quoted diff) +2
-0+ else + value |= (1 << intr_line);
value |= BIT(intr_line);
(probably a few more occasions in the driver)
Yours,
Linus Walleij
Quoted 75 lines · Linus Walleij
Quoted 8 lines · Mika Westerberg
This 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.
Signed-off-by Mika Westerberg <[email protected]>*VERY* nice work Mika! Just minor nitpicks...
(...)
Quoted 20 lines
(quoted diff) +20
-0+static int chv_config_get(struct pinctrl_dev *pctldev, unsigned pin, + unsigned long *config) +{ + struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); + enum pin_config_param param = pinconf_to_config_param(*config); + unsigned long flags; + u32 ctrl0, ctrl1; + u16 arg = 0; + u32 term; + + spin_lock_irqsave(&pctrl->lock, flags); + ctrl0 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); + ctrl1 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL1)); + spin_unlock_irqrestore(&pctrl->lock, flags); + + term = (ctrl0 & CHV_PADCTRL0_TERM_MASK) >> CHV_PADCTRL0_TERM_SHIFT; + + switch (param) { + case PIN_CONFIG_BIAS_DISABLE: + if (term)Review
Quoted 10 lines
(quoted diff) +10
-0+ return -EINVAL; + break; + + case PIN_CONFIG_BIAS_PULL_UP: + if (!(ctrl0 & CHV_PADCTRL0_TERM_UP)) + return -EINVAL; + + switch (term) { + case CHV_PADCTRL0_TERM_20K: + arg = 20;These are in Ohms IIRC so should be 20000
Review
Quoted 3 lines
(quoted diff) +3
-0+ break; + case CHV_PADCTRL0_TERM_5K: + arg = 5;5000
Review
Quoted 3 lines
(quoted diff) +3
-0+ break; + case CHV_PADCTRL0_TERM_1K: + arg = 1;1000
Review
Quoted 12 lines
(quoted diff) +12
-0+ break; + } + + break; + + case PIN_CONFIG_BIAS_PULL_DOWN: + if (!term || (ctrl0 & CHV_PADCTRL0_TERM_UP)) + return -EINVAL; + + switch (term) { + case CHV_PADCTRL0_TERM_20K: + arg = 20;20000
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ break; + case CHV_PADCTRL0_TERM_5K: + arg = 5;5000
Right, I'll change them.
Quoted 10 lines
(...)
Quoted 9 lines
(quoted diff) +9
-0+static int chv_config_set_pull(struct chv_pinctrl *pctrl, unsigned pin, + enum pin_config_param param, u16 arg) +{ + void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL0); + unsigned long flags; + u32 ctrl0, pull; + + spin_lock_irqsave(&pctrl->lock, flags); + ctrl0 = readl(reg);
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ + pull = CHV_PADCTRL0_TERM_20K << CHV_PADCTRL0_TERM_SHIFT; + switch (arg) {This looks seriously convoluted: you can't inspect an argument before checking what parameter you're dealing with. This should be under a case
PIN_CONFIG_BIAS_PULL_UPin the switch (param) below I think?
OK.
Quoted 21 lines
Quoted 2 lines
+ case 1:
case 1000
Review
Quoted 3 lines
(quoted diff) +3
-0+ /* For 1k there is only pull up */ + if (param == PIN_CONFIG_BIAS_PULL_UP) + pull = CHV_PADCTRL0_TERM_1K << CHV_PADCTRL0_TERM_SHIFT;Well you do check it here but...0
Review
Quoted 2 lines
(quoted diff) +2
-0+ break; + case 5:case 5000
Quoted 1 line
+ pull =
CHV_PADCTRL0_TERM_5K<<CHV_PADCTRL0_TERM_SHIFT;This will be applied to whatever config with arg == 5000 comes here!
(...)
Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+static unsigned chv_gpio_offset_to_pin(struct chv_pinctrl *pctrl, + unsigned offset) +{ + return pctrl->community->pins[offset].number; +}I'm a bit worried about the massive pin<->offsets<->gpio# translations happening in this and patch 1/4 etc. It's a bit unsettling. Are you sure we are translating in the simplest way?
We are translating from ACPI GPIO number, which is relative to the GPIO controller in question to pin controller space (which is not 1:1 in this driver).
I'll double check this, just in case.
Quoted 6 lines
Quoted 6 lines
(quoted diff) +6
-0+static int chv_gpio_get(struct gpio_chip *chip, unsigned offset) +{ + struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(chip); + int pin = chv_gpio_offset_to_pin(pctrl, offset); + unsigned long flags; + u32 ctrl0, cfg;
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ + spin_lock_irqsave(&pctrl->lock, flags); + ctrl0 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); + spin_unlock_irqrestore(&pctrl->lock, flags);If you need a lock before and after reading every register in this range, consider regmap-mmio, because that is part of what it does. Just a hint...
Yeah, I don't think we need a lock for reading simple registers so I'll remove such usage from the driver.
Quoted 23 lines
(...)
Quoted 7 lines
(quoted diff) +7
-0+static void chv_gpio_irq_mask_unmask(struct irq_data *d, bool mask) +{ + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); + struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(gc); + int pin = chv_gpio_offset_to_pin(pctrl, irqd_to_hwirq(d)); + u32 value, intr_line; + unsigned long flags;Review
Quoted 10 lines
(quoted diff) +10
-0+ + spin_lock_irqsave(&pctrl->lock, flags); + + intr_line = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); + intr_line &= CHV_PADCTRL0_INTSEL_MASK; + intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT; + + value = readl(pctrl->regs + CHV_INTMASK); + if (mask) + value &= ~(1 << intr_line);I usually do this kind of stuff with
#include <
linux/bitops.h>
Quoted 8 lines
value &= ~BIT(intr_line);
Review
Quoted 2 lines
(quoted diff) +2
-0+ else + value |= (1 << intr_line);value |=
BIT(intr_line);(probably a few more occasions in the driver)
OK, will fix.
A message that is not in the archive (sent off-list or not yet received): 1414153014-152246-2-git-send-email-mika.westerberg@linux.intel.com
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 6 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]>
I'm not sure what this patch does so I try to rely on you guys here. I would strongly like to have Rafael's ACK before proceeding.
Trying to get the GPIO offsets to map 1:1 to Linux GPIO numbers is something that should be avoided since we want to get rid of the GPIO number space altogether. GPIO chips should try to register with .base = -1 so that the gpiolib just assigns some random GPIO numbers to the lines.
What does actually exist?
- GPIO offsets for a certain gpio_chip 0..N
- Pin offsets for a certain pin controller 0..N
GPIO ranges are for translating between these two.
But I have a vague idea that there is something like a numberspace concept inside ACPI as well, and that is all magic to me... mixing that into this is a bit scary to me.
Review
Quoted 5 lines
(quoted diff) +5
-0+#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
So I guess I'm curious about this Gpiolo/GpioInt resource number space...
Yours,
Linus Walleij
Re: [PATCH 1/4] gpio / ACPI: Add knowledge about pin controllers to acpi_get_gpiod()
Quoted 30 lines · Linus Walleij
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 6 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]>I'm not sure what this patch does so I try to rely on you guys here. I would strongly like to have Rafael's ACK before proceeding.
Trying to get the GPIO offsets to map 1:1 to Linux GPIO numbers is something that should be avoided since we want to get rid of the GPIO number space altogether. GPIO chips should try to register with .base = -1 so that the gpiolib just assigns some random GPIO numbers to the lines.
What does actually exist?
Quoted 8 lines
- GPIO offsets for a certain
gpio_chip0..N
- Pin offsets for a certain pin controller 0..NGPIO ranges are for translating between these two.
But I have a vague idea that there is something like a numberspace concept inside ACPI as well, and that is all magic to me... mixing that into this is a bit scary to me.
Let me try to explain.
As an example, we have touch panel that has GPIO interrupt declared in ACPI like this:
GpioInt (Level, ActiveLow, Shared, PullDefault, 0x0000,
"\\_SB.GPO0", 0x00, ResourceConsumer)
{ // Pin list
76
}The number 76 in this case is GPIO controller relative GPIO number.
Now, we have pinctrl-cherryview.c which has gaps in the pin space (some of the pins are not available to the OS at all). So for this particular pin we have:
# grep SATA_GP1 pins pin 76 (SATA_GP1) mode 1 ctrl0 0x00010200 ctrl1 0x04c00000
# cat gpio-ranges GPIO ranges handled: 0: INT33FF:00 GPIOS [456 - 463] PINS [0 - 7] 8: INT33FF:00 GPIOS [464 - 471] PINS [15 - 22] 16: INT33FF:00 GPIOS [472 - 479] PINS [30 - 37] 24: INT33FF:00 GPIOS [480 - 487] PINS [45 - 52] 32: INT33FF:00 GPIOS [488 - 495] PINS [60 - 67] 40: INT33FF:00 GPIOS [496 - 503] PINS [75 - 82] 48: INT33FF:00 GPIOS [504 - 511] PINS [90 - 97]
In other words GPIO number for pin 76 is 496 (in Linux global number space) and 41 in the GPIO driver local number space.
In order to translate the ACPI GPIO number 76 to the right GPIO number we iterate over each range in the GPIO driver and look for the match. Note that it actually uses the local number (41) here:
...
offset = acpi_gpiochip_pin_to_gpio_offset(chip, pin);
if (offset < 0)
return ERR_PTR(offset);
return gpiochip_get_desc(chip, (u16)offset);However, if you or others have better ideas how to do this I'm all ears :-)
Quoted 7 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+#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 resourceSo I guess I'm curious about this Gpiolo/GpioInt resource number space...
In the above example:
GpioInt (Level, ActiveLow, Shared, PullDefault, 0x0000,
"\\_SB.GPO0", 0x00, ResourceConsumer)
{ // Pin list
76
}The GPIO number (76) is relative to the GPIO controller in question (\_SB.GPO0). 0 would be the first GPIO and so on...
Re: [PATCH 1/4] gpio / ACPI: Add knowledge about pin controllers to acpi_get_gpiod()
Quoted 5 lines · Mika Westerberg
Quoted 3 lines · Linus Walleij
But I have a vague idea that there is something like a numberspace concept inside ACPI as well, and that is all magic to me... mixing that into this is a bit scary to me.
(...)
Quoted 13 lines
# grep SATA_GP1 pins pin 76 (SATA_GP1) mode 1 ctrl0 0x00010200 ctrl1 0x04c00000# cat gpio-ranges GPIO ranges handled: 0: INT33FF:00 GPIOS [456 - 463] PINS [0 - 7] 8: INT33FF:00 GPIOS [464 - 471] PINS [15 - 22] 16: INT33FF:00 GPIOS [472 - 479] PINS [30 - 37] 24: INT33FF:00 GPIOS [480 - 487] PINS [45 - 52] 32: INT33FF:00 GPIOS [488 - 495] PINS [60 - 67] 40: INT33FF:00 GPIOS [496 - 503] PINS [75 - 82] 48: INT33FF:00 GPIOS [504 - 511] PINS [90 - 97]
Quoted 6 lines
In other words GPIO number for pin 76 is 496 (in Linux global number space) and 41 in the GPIO driver local number space.
In order to translate the ACPI GPIO number 76 to the right GPIO number we iterate over each range in the GPIO driver and look for the match. Note that it actually uses the local number (41) here:
OK what I was mainly worrying about was that it would go and use the Linux GPIO numbers in any way. As long as the mechanism relies on the local pin controller or GPIO chip offsets I'm happy.
Yours,
Linus Walleij
A message that is not in the archive (sent off-list or not yet received): 1414153014-152246-3-git-send-email-mika.westerberg@linux.intel.com
Re: [PATCH 2/4] pinctrl: Move Intel Baytrail pinctrl driver under intel directory
Quoted 4 lines · Mika Westerberg
We are going to have more pinctrl drivers for Intel hardware so separate all our pin controller drivers to own directory.
Signed-off-by Mika Westerberg <[email protected]>
Patch applied.
Yours,
Linus Walleij
A message that is not in the archive (sent off-list or not yet received): 1414153014-152246-4-git-send-email-mika.westerberg@linux.intel.com
Re: [PATCH 3/4] MAINTAINERS: Add entry for Intel pin controller drivers
Quoted 5 lines · Mika Westerberg
Add
MAINTAINERSentry for Intel pin controller drivers. I will be maintaining them with Heikki, who kindly promised to help me with this.Signed-off-by Heikki Krogerus <[email protected]>Signed-off-by Mika Westerberg <[email protected]>
Patch applied.
Yours,
Linus Walleij