gpio: add Lynxpoint chipset gpio driver
cover gpio: add Lynxpoint chipset gpio driver
This gpio controller driver for the Intel Lynxpoint LP PCH chipset is designed to work with the new ACPI 5 enumeration model and ACPI 5 GpioIo/GpioInt resource translation recently added to linux-acpi.
Mathias Nyman (1):
gpio: add Lynxpoint chipset gpio driver.
drivers/gpio/Kconfig | 7 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-lynxpoint.c | 406 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 414 insertions(+), 0 deletions(-) create mode 100644 drivers/gpio/gpio-lynxpoint.c
Signature · 1 line
1.7.4.1
PATCH 1/1 gpio: add Lynxpoint chipset gpio driver.
Add gpio support for Intel Lynxpoint chipset.
Lynxpoint supports 94 gpio pins which can generate interrupts. Driver will fail requests for pins that are marked as owned by ACPI, or set in an alternate mode (non-gpio).
--- drivers/gpio/Kconfig | 7 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-lynxpoint.c | 406 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 414 insertions(+), 0 deletions(-) create mode 100644 drivers/gpio/gpio-lynxpoint.c
drivers/gpio/Kconfig +7 -0
@@ -267,6 +267,13 @@ config GPIO_GE_FPGA and write pin state) for GPIO implemented in a number of GE single board computers. +config GPIO_LYNXPOINT + bool "Intel Lynxpoint GPIO support" + select IRQ_DOMAIN + help + driver for GPIO functionality on Intel Lynxpoint PCH chipset + Requires platform or ACPI code to set up a platform device. + comment "I2C GPIO expanders:" config GPIO_ARIZONA
drivers/gpio/Makefile +1 -0
@@ -29,6 +29,7 @@ obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o obj-$(CONFIG_ARCH_KS8695) += gpio-ks8695.o obj-$(CONFIG_GPIO_LANGWELL) += gpio-langwell.o obj-$(CONFIG_ARCH_LPC32XX) += gpio-lpc32xx.o +obj-$(CONFIG_GPIO_LYNXPOINT) += gpio-lynxpoint.o obj-$(CONFIG_GPIO_MAX730X) += gpio-max730x.o obj-$(CONFIG_GPIO_MAX7300) += gpio-max7300.o obj-$(CONFIG_GPIO_MAX7301) += gpio-max7301.o
drivers/gpio/gpio-lynxpoint.c new file +406 -0
406 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Re: [PATCH 1/1] gpio: add Lynxpoint chipset gpio driver.
Quoted 6 lines · Mathias Nyman
Add gpio support for Intel Lynxpoint chipset.
Lynxpoint supports 94 gpio pins which can generate interrupts. Driver will fail requests for pins that are marked as owned by ACPI, or set in an alternate mode (non-gpio).Signed-off-by Mathias Nyman <[email protected]>
Nice shape on this patch, makes it easy to focus the review on the important stuff, thanks Magnus!
drivers/gpio/Kconfig config GPIO_GE_FPGA · line 271
Quoted 2 lines
drivers/gpio/Kconfig +2
-0+config GPIO_LYNXPOINT + bool "Intel Lynxpoint GPIO support"
So you don't want to be able to build it as module? (OK just odd on Intel systems.)
Quoted 4 lines
drivers/gpio/Kconfig +4
-0+ select IRQ_DOMAIN + help + driver for GPIO functionality on Intel Lynxpoint PCH chipset + Requires platform or ACPI code to set up a platform device.
(...)
Quoted 1 line
+++
b/drivers/gpio/gpio-lynxpoint.c
(...)
Quoted 15 lines
drivers/gpio/gpio-lynxpoint.c new file +15
-0+/* LynxPoint chipset has support for 94 gpio pins */ + +#define LP_NUM_GPIO 94 + +/* Register offsets */ +#define LP_ACPI_OWNED 0x00/* Bitmap, set by bios, 0: pin reserved for ACPI */ +#define LP_GC 0x7C/* set APIC IRQ to IRQ14 or IRQ15 for all pins */ +#define LP_INT_STAT 0x80 +#define LP_INT_ENABLE 0x90 + +/* Each pin has two 32 bit config registers, starting at 0x100 */ +#define LP_CONFIG1 0x100 +#define LP_CONFIG2 0x104 + +/* LP_CONFIG1 reg bits */
drivers/gpio/gpio-lynxpoint.c line 59
Quoted 10 lines
drivers/gpio/gpio-lynxpoint.c new file +10
-0+#define OUT_LVL_BIT BIT(31) +#define IN_LVL_BIT BIT(30) +#define TRIG_SEL_BIT BIT(4)/* 0: Edge, 1: Level */ +#define INT_INV_BIT BIT(3)/* Invert interrupt triggering */ +#define DIR_BIT BIT(2)/* 0: Output, 1: Input */ +#define USE_SEL_BIT BIT(0)/* 0: Native, 1: GPIO */ + +/* LP_CONFIG2 reg bits */ +#define GPINDIS_BIT BIT(2)/* disable input sensing */ +#define GPIWP_BIT (BIT(0) | BIT(1))/* weak pull options */
Kudos for using BIT() macros, very readable, thanks!
drivers/gpio/gpio-lynxpoint.c line 66
Quoted 6 lines
drivers/gpio/gpio-lynxpoint.c new file +6
-0+struct lp_gpio { +struct gpio_chip chip; +struct irq_domain *domain; +struct platform_device *pdev; +spinlock_t lock; +unsigned hwirq;
This struct member is only used in probe() so make it a local variable there and cut it from the struct.
drivers/gpio/gpio-lynxpoint.c line 68
Quoted 2 lines
drivers/gpio/gpio-lynxpoint.c new file +2
-0+unsigned long reg_base; +unsigned long reg_len;
Same comment for reg_len.
drivers/gpio/gpio-lynxpoint.c line 71
Quoted 3 lines
drivers/gpio/gpio-lynxpoint.c new file +3
-0+}; + +static unsigned long gpio_reg (struct gpio_chip *chip,unsigned gpio,int reg)
Rename lp_gpio_reg() so as to match the family.
Rename the argument "gpio" to "offset" since it's a local number, not in the global GPIO numberspace. (Please change this everywhere a local index is used.)
drivers/gpio/gpio-lynxpoint.c line 79
Quoted 8 lines
drivers/gpio/gpio-lynxpoint.c new file +8
-0+{ + struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); +int offset; + +if (reg ==LP_CONFIG1 || reg ==LP_CONFIG2 ) + offset = gpio *8 ; +else + offset = (gpio /32 ) *4 ;
Put in some comment above this explaining the layout of the offsets for these two cases so we understand what's happening here.
Quoted 5 lines
drivers/gpio/gpio-lynxpoint.c new file +5
-0+return lg->reg_base + reg + offset; +} + +static int lp_gpio_request (struct gpio_chip *chip,unsigned gpio) +{
drivers/gpio/gpio-lynxpoint.c line 95
Quoted 10 lines
drivers/gpio/gpio-lynxpoint.c new file +10
-0+ struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); +unsigned long reg =gpio_reg (chip, gpio,LP_CONFIG1 ); +unsigned long conf2 =gpio_reg (chip, gpio,LP_CONFIG2 ); +unsigned long acpi_use =gpio_reg (chip, gpio,LP_ACPI_OWNED ); + +/* Fail if BIOS reserved pin for ACPI use */ +if (!(inl (acpi_use) &BIT (gpio %32 ))) { +dev_err (&lg->pdev->dev,"gpio %d reserved for ACPI\n" , gpio); +return -EBUSY ; + }
This %32 magic only seems to consider the latter part of the if() statement in the gpio_reg() function. It's like you assume only the (gpio / 32) * 4 path to be taken. It seems that for the two models handled there this should be %8 or something. Or I'm getting it wrong, which is an indication that something is pretty unclear here...
Quoted 9 lines
drivers/gpio/gpio-lynxpoint.c new file +9
-0+/* Fail if pin is in alternate function mode (not GPIO mode) */ +if (!(inl (reg) &USE_SEL_BIT )) +return -ENODEV ; + +/* enable input sensing */ +outl (inl (conf2) & ~GPINDIS_BIT , conf2); + +return 0 ; +}
(...)
drivers/gpio/gpio-lynxpoint.c line 235
Quoted 4 lines
drivers/gpio/gpio-lynxpoint.c new file +4
-0+static void lp_irq_enable (struct irq_data *d) +{ +struct lp_gpio *lg =irq_data_get_irq_chip_data (d); +u32 gpio =irqd_to_hwirq (d);
That variable is confusingly named. It's not a global gpio number, it's a local offset, so please rename it "offset".
drivers/gpio/gpio-lynxpoint.c line 247
Quoted 12 lines
drivers/gpio/gpio-lynxpoint.c new file +12
-0+unsigned long reg =gpio_reg (&lg->chip, gpio,LP_INT_ENABLE ); +unsigned long flags; + +spin_lock_irqsave (&lg->lock, flags); +outl (inl (reg) |BIT (gpio %32 ), reg); +spin_unlock_irqrestore (&lg->lock, flags); +} + +static void lp_irq_disable (struct irq_data *d) +{ +struct lp_gpio *lg =irq_data_get_irq_chip_data (d); +u32 gpio =irqd_to_hwirq (d);
Dito.
Quoted 7 lines
drivers/gpio/gpio-lynxpoint.c new file +7
-0+unsigned long reg =gpio_reg (&lg->chip, gpio,LP_INT_ENABLE ); +unsigned long flags; + +spin_lock_irqsave (&lg->lock, flags); +outl (inl (reg) & ~BIT (gpio %32 ), reg); +spin_unlock_irqrestore (&lg->lock, flags); +}
(...)
drivers/gpio/gpio-lynxpoint.c line 378
Quoted 7 lines
drivers/gpio/gpio-lynxpoint.c new file +7
-0+#ifdef CONFIG_ACPI +static const struct acpi_device_id lynxpoint_gpio_acpi_match[] = { + {"INT33C7" ,0 }, + { } +}; +MODULE_DEVICE_TABLE (acpi, lynxpoint_gpio_acpi_match); +#endif
Aha so how many users are there of this driver which are not using ACPI?
If zero, why not just depend on ACPI in Kconfig?
Quoted 1 line
+static int
__devexitlp_gpio_remove(struct platform_device *pdev)
All __devinit/__devexit macros are going away in v3.8 so delete them everywhere.
drivers/gpio/gpio-lynxpoint.c line 393
Quoted 13 lines
drivers/gpio/gpio-lynxpoint.c new file +13
-0+{ +struct lp_gpio *lg =platform_get_drvdata (pdev); +int err; + err =gpiochip_remove (&lg->chip); +if (err) +dev_warn (&pdev->dev,"failed to remove gpio_chip.\n" ); +platform_set_drvdata (pdev,NULL ); +return 0 ; +} + +static struct platform_driver lp_gpio_driver = { + .probe = lp_gpio_probe, + .remove =__devexit_p (lp_gpio_remove),
Delete that __devexit_p() too I suppose.
drivers/gpio/gpio-lynxpoint.c line 406
Quoted 13 lines
drivers/gpio/gpio-lynxpoint.c new file +13
-0+ .driver = { + .name = "lp_gpio", + .owner = THIS_MODULE, + .acpi_match_table = ACPI_PTR(lynxpoint_gpio_acpi_match), + }, +}; + +static int __init lp_gpio_init (void ) +{ +return platform_driver_register (&lp_gpio_driver); +} + +subsys_initcall (lp_gpio_init);
Yours,
Linus Walleij
Re: [PATCH 1/1] gpio: add Lynxpoint chipset gpio driver.
Quoted 10 lines · Linus Walleij
Quoted 6 lines · Mathias Nyman
Add gpio support for Intel Lynxpoint chipset.
Lynxpoint supports 94 gpio pins which can generate interrupts. Driver will fail requests for pins that are marked as owned by ACPI, or set in an alternate mode (non-gpio).Signed-off-by Mathias Nyman<[email protected]>
Quoted 8 lines
Nice shape on this patch, makes it easy to focus the review on the important stuff, thanks Magnus!
drivers/gpio/Kconfig config GPIO_GE_FPGA · line 271
Quoted 2 lines
drivers/gpio/Kconfig +2
-0+config GPIO_LYNXPOINT + bool "Intel Lynxpoint GPIO support"So you don't want to be able to build it as module? (OK just odd on Intel systems.)
Reason for having it as bool was the subsys_initcall() got degraded
to something like module_init() if built as module. This was not good because the IO port ranges used for gpios were specified in ACPI tables both in the gpio device, and as a part of a motherboard device. Pnpacpi code would then reserve all the IO port ranges in the motherboard device before this gpio driver had a chance to take reserve them.
I have to re-check if this is still the case.
Quoted 7 lines
drivers/gpio/gpio-lynxpoint.c line 66
Quoted 6 lines
drivers/gpio/gpio-lynxpoint.c new file +6
-0+struct lp_gpio { +struct gpio_chip chip; +struct irq_domain *domain; +struct platform_device *pdev; +spinlock_t lock; +unsigned hwirq;
Quoted 7 lines
This struct member is only used in
probe()so make it a local variable there and cut it from the struct.drivers/gpio/gpio-lynxpoint.c line 68
Quoted 2 lines
drivers/gpio/gpio-lynxpoint.c new file +2
-0+unsigned long reg_base; +unsigned long reg_len;Same comment for
reg_len.
Will fix
Quoted 10 lines
drivers/gpio/gpio-lynxpoint.c line 71
Quoted 4 lines
drivers/gpio/gpio-lynxpoint.c new file +3
-0+}; + +static unsigned long gpio_reg (struct gpio_chip *chip,unsigned gpio,int reg)Rename
lp_gpio_reg()so as to match the family.Rename the argument "gpio" to "offset" since it's a local number, not in the global GPIO numberspace. (Please change this everywhere a local index is used.)
Sure.
Quoted 26 lines
drivers/gpio/gpio-lynxpoint.c line 79
Quoted 9 lines
drivers/gpio/gpio-lynxpoint.c new file +8
-0+{ + struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); +int offset; + +if (reg ==LP_CONFIG1 || reg ==LP_CONFIG2 ) + offset = gpio *8 ; +else + offset = (gpio /32 ) *4 ;Put in some comment above this explaining the layout of the offsets for these two cases so we understand what's happening here.
Quoted 13 lines
drivers/gpio/gpio-lynxpoint.c new file +13
-0+return lg->reg_base + reg + offset; +} + +static int lp_gpio_request (struct gpio_chip *chip,unsigned gpio) +{ + struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); +unsigned long reg =gpio_reg (chip, gpio,LP_CONFIG1 ); +unsigned long conf2 =gpio_reg (chip, gpio,LP_CONFIG2 ); +unsigned long acpi_use =gpio_reg (chip, gpio,LP_ACPI_OWNED ); + +/* Fail if BIOS reserved pin for ACPI use */ +if (!(inl (acpi_use)&BIT (gpio %32 ))) { +dev_err (&lg->pdev->dev,"gpio %d reserved for ACPI\n" , gpio);
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ return -EBUSY; + }This %32 magic only seems to consider the latter part of the
if()statement in thegpio_reg()function. It's like you assume only the (gpio / 32) * 4 path to be taken. It seems that for the two models handled there this should be %8 or something. Or I'm getting it wrong, which is an indication that something is pretty unclear here...
I should document the register layout better. It's a bit messy because in some cases a register represents a functionality where each bit stands for a gpio (bitmapped) (each register is 32 bit, so to cover all 94 gpios three 32bit registers are needed).
In other cases a register represent a gpio, and each bit a functionality. This is the case with LP_CONFIGx registers. So we got 94 LP_CONFIG1 registers and 94 LP_CONFIG2 registers.
In the case of acpi_use & BIT(gpio % 32) I know that acpi_used is pointing to one of the three LP_ACPI_OWNED bitmapped registers, and the (gpio / 32 * 4) path is taken, and % 32 will work.
I'll add better description of the register layout as a comment
Quoted 7 lines
drivers/gpio/gpio-lynxpoint.c line 235
Quoted 4 lines
drivers/gpio/gpio-lynxpoint.c new file +4
-0+static void lp_irq_enable (struct irq_data *d) +{ +struct lp_gpio *lg =irq_data_get_irq_chip_data (d); +u32 gpio =irqd_to_hwirq (d);That variable is confusingly named. It's not a global gpio number, it's a local offset, so please rename it "offset".
sure, (is "pin" ok? "offset" is already used in may places)
Quoted 11 lines
drivers/gpio/gpio-lynxpoint.c line 378
Quoted 7 lines
drivers/gpio/gpio-lynxpoint.c new file +7
-0+#ifdef CONFIG_ACPI +static const struct acpi_device_id lynxpoint_gpio_acpi_match[] = { + {"INT33C7" ,0 }, + { } +}; +MODULE_DEVICE_TABLE (acpi, lynxpoint_gpio_acpi_match); +#endif Aha so how many users are there of this driver which are not using ACPI?
Quoted 2 lines
If zero, why not just depend on ACPI in
Kconfig?
Only ACPI support for now.
Will remove ifdefs and add dependency.
Quoted 4 lines
Quoted 1 line
+static int
__devexitlp_gpio_remove(struct platform_device *pdev)All __devinit/__devexit macros are going away in v3.8 so delete them everywhere.
Ah, Ok.
Quoted 3 lines
Yours,
Linus Walleij
Thanks for taking the time to review this, I'll make the suggested changes.
I also got some offline comments about adding runtime pm/system suspend code to this driver.
-Mathias
Re: [PATCH 1/1] gpio: add Lynxpoint chipset gpio driver.
Quoted 10 lines · Mathias Nyman
Quoted 8 lines
drivers/gpio/gpio-lynxpoint.c line 235
Quoted 4 lines
drivers/gpio/gpio-lynxpoint.c new file +4
-0+static void lp_irq_enable (struct irq_data *d) +{ +struct lp_gpio *lg =irq_data_get_irq_chip_data (d); +u32 gpio =irqd_to_hwirq (d);That variable is confusingly named. It's not a global gpio number, it's a local offset, so please rename it "offset".
sure, (is "pin" ok? "offset" is already used in may places)
pin will confuse things to the pinctrl subsystem ... offset is really nice. But no super-big deal.
Yours,
Linus Walleij
Re: [PATCH 1/1] gpio: add Lynxpoint chipset gpio driver.
In reply to Mathias NymanQuoted 12 lines · Mathias Nyman
Add gpio support for Intel Lynxpoint chipset.
Lynxpoint supports 94 gpio pins which can generate interrupts. Driver will fail requests for pins that are marked as owned by ACPI, or set in an alternate mode (non-gpio).Signed-off-by Mathias Nyman <[email protected]>---
drivers/gpio/gpio-lynxpoint.c new file +5
-0+static void lp_gpio_set (struct gpio_chip *chip,unsigned gpio,int value) +{ + struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); +unsigned long reg =gpio_reg (chip, gpio,LP_CONFIG1 ); +unsigned long flags;
drivers/gpio/gpio-lynxpoint.c line 162
Quoted 10 lines
drivers/gpio/gpio-lynxpoint.c new file +10
-0+ +spin_lock_irqsave (&lg->lock, flags); + +if (value) +outl (inl (reg) |OUT_LVL_BIT , reg); +else +outl (inl (reg) & ~OUT_LVL_BIT , reg); + +spin_unlock_irqrestore (&lg->lock, flags); +}
A *lot* of drivers implement their own GPIO ops like this, and they all end up looking the same. Please take a look at drivers/gpio/gpio-generic.c and see if you can use the stock operations provided there.
g.
Re: [PATCH 1/1] gpio: add Lynxpoint chipset gpio driver.
Quoted 20 lines · Grant Likely
Quoted 19 lines · Mathias Nyman
Add gpio support for Intel Lynxpoint chipset.
Lynxpoint supports 94 gpio pins which can generate interrupts. Driver will fail requests for pins that are marked as owned by ACPI, or set in an alternate mode (non-gpio).Signed-off-by Mathias Nyman <[email protected]>---
drivers/gpio/gpio-lynxpoint.c new file +12
-0+static void lp_gpio_set (struct gpio_chip *chip,unsigned gpio,int value) +{ + struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); +unsigned long reg =gpio_reg (chip, gpio,LP_CONFIG1 ); +unsigned long flags; + +spin_lock_irqsave (&lg->lock, flags); + +if (value) +outl (inl (reg) |OUT_LVL_BIT , reg); +else +outl (inl (reg) & ~OUT_LVL_BIT , reg);
Quoted 8 lines
drivers/gpio/gpio-lynxpoint.c line 140
Quoted 3 lines
drivers/gpio/gpio-lynxpoint.c new file +3
-0+ +spin_unlock_irqrestore (&lg->lock, flags); +}A *lot* of drivers implement their own GPIO ops like this, and they all end up looking the same. Please take a look at
drivers/gpio/gpio-generic.cand see if you can use the stock operations provided there.
I was under the impression that the generic code could not be used off-the-shelf for drivers doing irqchips (like this one).
But maybe I'm mistaken or it's trivial to fix?
Yours,
Linus Walleij
Re: [PATCH 1/1] gpio: add Lynxpoint chipset gpio driver.
In reply to Grant LikelyQuoted 29 lines · Grant Likely
Quoted 12 lines · Mathias Nyman
Add gpio support for Intel Lynxpoint chipset.
Lynxpoint supports 94 gpio pins which can generate interrupts. Driver will fail requests for pins that are marked as owned by ACPI, or set in an alternate mode (non-gpio).Signed-off-by Mathias Nyman<[email protected]>---
drivers/gpio/gpio-lynxpoint.c new file +5
-0+static void lp_gpio_set (struct gpio_chip *chip,unsigned gpio,int value) +{ + struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); +unsigned long reg =gpio_reg (chip, gpio,LP_CONFIG1 ); +unsigned long flags;drivers/gpio/gpio-lynxpoint.c line 162
Quoted 10 lines
drivers/gpio/gpio-lynxpoint.c new file +10
-0+ +spin_lock_irqsave (&lg->lock, flags); + +if (value) +outl (inl (reg) |OUT_LVL_BIT , reg); +else +outl (inl (reg)& ~OUT_LVL_BIT , reg); + +spin_unlock_irqrestore (&lg->lock, flags); +}A *lot* of drivers implement their own GPIO ops like this, and they all end up looking the same. Please take a look at
drivers/gpio/gpio-generic.cand see if you can use the stock operations provided there.
Quoted 2 lines
g.
Look quite similar but turns out the only potential generic ones which could be used are the bgpio_set() and bgpio_get() funtions. Using them would require custom pin2mask, write_reg, read_reg, etc functions. bgpio_set_direction
I guess using gpio-generic code fits memory mapped devices better. Trying to use it for io port devices would require a lot of code mangling.
-Mathias
Re: [PATCH 1/1] gpio: add Lynxpoint chipset gpio driver.
In reply to Linus WalleijQuoted 31 lines · Linus Walleij
Quoted 20 lines · Grant Likely
Quoted 19 lines · Mathias Nyman
Add gpio support for Intel Lynxpoint chipset.
Lynxpoint supports 94 gpio pins which can generate interrupts. Driver will fail requests for pins that are marked as owned by ACPI, or set in an alternate mode (non-gpio).Signed-off-by Mathias Nyman <[email protected]>---
drivers/gpio/gpio-lynxpoint.c new file +12
-0+static void lp_gpio_set (struct gpio_chip *chip,unsigned gpio,int value) +{ + struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); +unsigned long reg =gpio_reg (chip, gpio,LP_CONFIG1 ); +unsigned long flags; + +spin_lock_irqsave (&lg->lock, flags); + +if (value) +outl (inl (reg) |OUT_LVL_BIT , reg); +else +outl (inl (reg) & ~OUT_LVL_BIT , reg);Quoted 8 lines
drivers/gpio/gpio-lynxpoint.c line 140
Quoted 3 lines
drivers/gpio/gpio-lynxpoint.c new file +3
-0+ +spin_unlock_irqrestore (&lg->lock, flags); +}A *lot* of drivers implement their own GPIO ops like this, and they all end up looking the same. Please take a look at
drivers/gpio/gpio-generic.cand see if you can use the stock operations provided there.
Quoted 4 lines
I was under the impression that the generic code could not be used off-the-shelf for drivers doing irqchips (like this one).
But maybe I'm mistaken or it's trivial to fix?
There's two parts to the generic code, a library of helper ops and a full fledged platform driver. The library can be used without the platform driver bit.
g.
Re: [PATCH 1/1] gpio: add Lynxpoint chipset gpio driver.
In reply to Mathias NymanQuoted 30 lines · Mathias Nyman
Quoted 29 lines · Grant Likely
Quoted 12 lines · Mathias Nyman
Add gpio support for Intel Lynxpoint chipset.
Lynxpoint supports 94 gpio pins which can generate interrupts. Driver will fail requests for pins that are marked as owned by ACPI, or set in an alternate mode (non-gpio).Signed-off-by Mathias Nyman<[email protected]>---
drivers/gpio/gpio-lynxpoint.c new file +5
-0+static void lp_gpio_set (struct gpio_chip *chip,unsigned gpio,int value) +{ + struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); +unsigned long reg =gpio_reg (chip, gpio,LP_CONFIG1 ); +unsigned long flags;drivers/gpio/gpio-lynxpoint.c line 162
Quoted 10 lines
drivers/gpio/gpio-lynxpoint.c new file +10
-0+ +spin_lock_irqsave (&lg->lock, flags); + +if (value) +outl (inl (reg) |OUT_LVL_BIT , reg); +else +outl (inl (reg)& ~OUT_LVL_BIT , reg); + +spin_unlock_irqrestore (&lg->lock, flags); +}A *lot* of drivers implement their own GPIO ops like this, and they all end up looking the same. Please take a look at
drivers/gpio/gpio-generic.cand see if you can use the stock operations provided there.
Quoted 7 lines
Quoted 2 lines
g.
Look quite similar but turns out the only potential generic ones which could be used are the
bgpio_set()andbgpio_get()funtions. Using them would require custom pin2mask,write_reg,read_reg, etc functions.bgpio_set_direction
You would need new write_reg and read_reg, but they'd just become part of the library. Ah, but I see now that each GPIO has a separate register, and not a bitmask for multiple gpio lines. Fair enough.
g.