Migrate ACCES and WinSystems drivers to the regmap API
Subsystems (7)
cover Migrate ACCES and WinSystems drivers to the regmap API
This patchset is a collection and resend of the lingering GPIO patches for the regmap migration of the ACCES and WinSystems drivers.[^1][^2] Previously, these patches were postponed due to pending dependency patches that have since been merged into mainline. Now that those dependencies are present in the GPIO tree, this patchset can be merged without incident. An IRQ handling fix for the ws16c48 driver is also included at the end.[^3]
[^1] https://lore.kernel.org/all/[email protected]/
[^2] https://lore.kernel.org/all/[email protected]/
[^3] https://lore.kernel.org/all/[email protected]/
William Breathitt Gray (7):
gpio: idio-16: Migrate to the regmap API
gpio: 104-idio-16: Migrate to the regmap API
gpio: pci-idio-16: Migrate to the regmap API
gpio: idio-16: Remove unused legacy interface
gpio: pcie-idio-24: Migrate to the regmap API
gpio: ws16c48: Migrate to the regmap API
gpio: ws16c48: Fix off-by-one error in WS16C48 resource region extent
drivers/gpio/Kconfig | 13 +- drivers/gpio/gpio-104-idio-16.c | 286 +++---------- drivers/gpio/gpio-idio-16.c | 254 ++++++------ drivers/gpio/gpio-idio-16.h | 79 +--- drivers/gpio/gpio-pci-idio-16.c | 294 +++----------- drivers/gpio/gpio-pcie-idio-24.c | 677 +++++++++++-------------------- drivers/gpio/gpio-ws16c48.c | 554 +++++++++---------------- 7 files changed, 728 insertions(+), 1429 deletions(-)
base-commit: 87d0688483f56c748b37a5298bdc382df5cf8f74
Signature · 1 line
2.41.0
PATCH RESEND 1/7 gpio: idio-16: Migrate to the regmap API
The regmap API supports IO port accessors so we can take advantage of regmap abstractions rather than handling access to the device registers directly in the driver.
By leveraging the regmap API, the idio-16 library is reduced to simply a devm_idio_16_regmap_register() function and a configuration structure struct idio_16_regmap_config.
Legacy functions and code will be removed once all consumers have migrated to the new idio-16 library interface.
For IDIO-16 devices we have the following IRQ registers:
Base Address +1 (Write): Clear Interrupt
Base Address +2 (Read): Enable Interrupt
Base Address +2 (Write): Disable Interrupt
An interrupt is asserted whenever a change-of-state is detected on any of the inputs. Any write to 0x2 will disable interrupts, while any read will enable interrupts. Interrupts are cleared by a write to 0x1.
For 104-IDIO-16 devices, there is no IRQ status register, so software has to assume that if an interrupt is raised then it was for the 104-IDIO-16 device.
For PCI-IDIO-16 devices, there is an additional IRQ register:
Base Address +6 (Read): Interrupt Status
Interrupt status can be read from 0x6 where bit 2 set indicates that an IRQ has been generated.
--- drivers/gpio/Kconfig | 3 + drivers/gpio/gpio-idio-16.c | 155 ++++++++++++++++++++++++++++++++++++ drivers/gpio/gpio-idio-16.h | 26 ++++++ 3 files changed, 184 insertions(+)
drivers/gpio/Kconfig +3 -0
@@ -111,6 +111,9 @@ config GPIO_MAX730X config GPIO_IDIO_16 tristate + select REGMAP_IRQ + select GPIOLIB_IRQCHIP + select GPIO_REGMAP help Enables support for the idio-16 library functions. The idio-16 library provides functions to facilitate communication with devices within the
drivers/gpio/gpio-idio-16.c +155 -0
170 lines not on this page · raw message
drivers/gpio/gpio-idio-16.h +26 -0
@@ -6,6 +6,30 @@#include <linux/spinlock.h> #include <linux/types.h> +struct device ; +struct regmap ; +struct regmap_irq ; + +/** +* struct idio_16_regmap_config - Configuration for the IDIO-16 register map +* @parent: parent device +* @map: regmap for the IDIO-16 device +* @regmap_irqs: descriptors for individual IRQs +* @num_regmap_irqs: number of IRQ descriptors +* @irq: IRQ number for the IDIO-16 device +* @no_status: device has no status register +* @filters: device has input filters +*/ +struct idio_16_regmap_config { +struct device *parent; +struct regmap *map; +const struct regmap_irq *regmap_irqs; +int num_regmap_irqs; +unsigned int irq; +bool no_status; +bool filters; +}; +/** * struct idio_16 - IDIO-16 registers structure * @out0_7: Read: FET Drive Outputs 0-7
@@ -68,4 +92,6 @@ void idio_16_set_multiple(struct idio_16 __iomem *reg, const unsigned long *mask, const unsigned long *bits);void idio_16_state_init (struct idio_16_state *state); +int devm_idio_16_regmap_register (struct device *dev,const struct idio_16_regmap_config *config); +#endif /* _IDIO_16_H_ */
Signature · 1 line
2.41.0
PATCH RESEND 2/7 gpio: 104-idio-16: Migrate to the regmap API
In reply to William Breathitt GrayThe regmap API supports IO port accessors so we can take advantage of regmap abstractions rather than handling access to the device registers directly in the driver. Migrate the 104-idio-16 module to the new idio-16 library interface leveraging the gpio-regmap API.
--- drivers/gpio/Kconfig | 2 +- drivers/gpio/gpio-104-idio-16.c | 286 +++++++------------------------- 2 files changed, 64 insertions(+), 224 deletions(-)
drivers/gpio/Kconfig +1 -1
@@ -872,7 +872,7 @@ config GPIO_104_IDIO_16 tristate "ACCES 104-IDIO-16 GPIO support" depends on PC104 select ISA_BUS_API - select GPIOLIB_IRQCHIP + select REGMAP_MMIO select GPIO_IDIO_16 help Enables GPIO support for the ACCES 104-IDIO-16 family (104-IDIO-16,
drivers/gpio/gpio-104-idio-16.c +63 -223
323 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH RESEND 3/7 gpio: pci-idio-16: Migrate to the regmap API
In reply to William Breathitt GrayThe regmap API supports IO port accessors so we can take advantage of regmap abstractions rather than handling access to the device registers directly in the driver. Migrate the pci-idio-16 module to the new idio-16 library interface leveraging the gpio-regmap API.
--- drivers/gpio/Kconfig | 2 +- drivers/gpio/gpio-pci-idio-16.c | 294 +++++++------------------------- 2 files changed, 62 insertions(+), 234 deletions(-)
drivers/gpio/Kconfig +1 -1
@@ -1655,7 +1655,7 @@ config GPIO_PCH config GPIO_PCI_IDIO_16 tristate "ACCES PCI-IDIO-16 GPIO support" - select GPIOLIB_IRQCHIP + select REGMAP_MMIO select GPIO_IDIO_16 help Enables GPIO support for the ACCES PCI-IDIO-16. An interrupt is
drivers/gpio/gpio-pci-idio-16.c +61 -233
328 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH RESEND 4/7 gpio: idio-16: Remove unused legacy interface
In reply to William Breathitt GrayAll idio-16 library consumers have migrated to the new interface leveraging the gpio-regmap API. Legacy interface functions and code are removed as no longer needed.
--- drivers/gpio/gpio-idio-16.c | 131 +----------------------------------- drivers/gpio/gpio-idio-16.h | 65 ------------------ 2 files changed, 1 insertion(+), 195 deletions(-)
drivers/gpio/gpio-idio-16.c +1 -130
@@ -3,15 +3,13 @@* GPIO library for the ACCES IDIO-16 family * Copyright (C) 2022 William Breathitt Gray */ -#include <linux/bitmap.h> +#include <linux/bits.h> #include <linux/device.h> #include <linux/err.h> #include <linux/export.h> #include <linux/gpio/regmap.h> -#include <linux/io.h> #include <linux/module.h> #include <linux/regmap.h> -#include <linux/spinlock.h> #include <linux/types.h> #include "gpio-idio-16.h"
@@ -169,133 +167,6 @@ int devm_idio_16_regmap_register(struct device *const dev, }EXPORT_SYMBOL_GPL (devm_idio_16_regmap_register); -/** -* idio_16_get - get signal value at signal offset -* @reg: ACCES IDIO-16 device registers -* @state: ACCES IDIO-16 device state -* @offset: offset of signal to get -* -* Returns the signal value (0=low, 1=high) for the signal at @offset. -*/ -int idio_16_get (struct idio_16 __iomem *const reg, -struct idio_16_state *const state,const unsigned long offset) -{ -const unsigned long mask =BIT (offset); - -if (offset <IDIO_16_NOUT ) -return test_bit (offset, state->out_state); - -if (offset <24 ) -return !!(ioread8 (®->in0_7) & (mask >>IDIO_16_NOUT )); - -if (offset <32 ) -return !!(ioread8 (®->in8_15) & (mask >>24 )); - -return -EINVAL ; -} -EXPORT_SYMBOL_GPL (idio_16_get); - -/** -* idio_16_get_multiple - get multiple signal values at multiple signal offsets -* @reg: ACCES IDIO-16 device registers -* @state: ACCES IDIO-16 device state -* @mask: mask of signals to get -* @bits: bitmap to store signal values -* -* Stores in @bits the values (0=low, 1=high) for the signals defined by @mask. -*/ -void idio_16_get_multiple (struct idio_16 __iomem *const reg, -struct idio_16_state *const state, -const unsigned long *const mask, -unsigned long *const bits) -{ -unsigned long flags; -const unsigned long out_mask =GENMASK (IDIO_16_NOUT -1 ,0 ); - -spin_lock_irqsave (&state->lock, flags); - -bitmap_replace (bits, bits, state->out_state, &out_mask,IDIO_16_NOUT ); -if (*mask &GENMASK (23 ,16 )) -bitmap_set_value8 (bits,ioread8 (®->in0_7),16 ); -if (*mask &GENMASK (31 ,24 )) -bitmap_set_value8 (bits,ioread8 (®->in8_15),24 ); - -spin_unlock_irqrestore (&state->lock, flags); -} -EXPORT_SYMBOL_GPL (idio_16_get_multiple); - -/** -* idio_16_set - set signal value at signal offset -* @reg: ACCES IDIO-16 device registers -* @state: ACCES IDIO-16 device state -* @offset: offset of signal to set -* @value: value of signal to set -* -* Assigns output @value for the signal at @offset. -*/ -void idio_16_set (struct idio_16 __iomem *const reg, -struct idio_16_state *const state,const unsigned long offset, -const unsigned long value) -{ -unsigned long flags; - -if (offset >=IDIO_16_NOUT ) -return ; - -spin_lock_irqsave (&state->lock, flags); - -__assign_bit (offset, state->out_state, value); -if (offset <8 ) -iowrite8 (bitmap_get_value8 (state->out_state,0 ), ®->out0_7); -else -iowrite8 (bitmap_get_value8 (state->out_state,8 ), ®->out8_15); - -spin_unlock_irqrestore (&state->lock, flags); -} -EXPORT_SYMBOL_GPL (idio_16_set); - -/** -* idio_16_set_multiple - set signal values at multiple signal offsets -* @reg: ACCES IDIO-16 device registers -* @state: ACCES IDIO-16 device state -* @mask: mask of signals to set -* @bits: bitmap of signal output values -* -* Assigns output values defined by @bits for the signals defined by @mask. -*/ -void idio_16_set_multiple (struct idio_16 __iomem *const reg, -struct idio_16_state *const state, -const unsigned long *const mask, -const unsigned long *const bits) -{ -unsigned long flags; - -spin_lock_irqsave (&state->lock, flags); - -bitmap_replace (state->out_state, state->out_state, bits, mask, -IDIO_16_NOUT ); -if (*mask &GENMASK (7 ,0 )) -iowrite8 (bitmap_get_value8 (state->out_state,0 ), ®->out0_7); -if (*mask &GENMASK (15 ,8 )) -iowrite8 (bitmap_get_value8 (state->out_state,8 ), ®->out8_15); - -spin_unlock_irqrestore (&state->lock, flags); -} -EXPORT_SYMBOL_GPL (idio_16_set_multiple); - -/** -* idio_16_state_init - initialize idio_16_state structure -* @state: ACCES IDIO-16 device state -* -* Initializes the ACCES IDIO-16 device @state for use in idio-16 library -* functions. -*/ -void idio_16_state_init (struct idio_16_state *const state) -{ -spin_lock_init (&state->lock); -} -EXPORT_SYMBOL_GPL (idio_16_state_init); -MODULE_AUTHOR ("William Breathitt Gray" );MODULE_DESCRIPTION ("ACCES IDIO-16 GPIO Library" );MODULE_LICENSE ("GPL" );
drivers/gpio/gpio-idio-16.h +0 -65
77 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH RESEND 5/7 gpio: pcie-idio-24: Migrate to the regmap API
In reply to William Breathitt GrayThe regmap API supports IO port accessors so we can take advantage of regmap abstractions rather than handling access to the device registers directly in the driver.
For the PCIe-IDIO-24 series of devices, the following BARs are available:
BAR[0]: memory mapped PEX8311
BAR[1]: I/O mapped PEX8311
BAR[2]: I/O mapped card registersThere are 24 FET Output lines, 24 Isolated Input lines, and 8 TTL/CMOS lines (which may be configured for either output or input). The GPIO lines are exposed by the following card registers:
Base +0x0-0x2 (Read/Write): FET Outputs
Base +0xB (Read/Write): TTL/CMOS
Base +0x4-0x6 (Read): Isolated Inputs
Base +0x7 (Read): TTL/CMOSIn order for the device to support interrupts, the PLX PEX8311 internal PCI wire interrupt and local interrupt input must first be enabled.
The following card registers for Change-Of-State may be used:
Base +0x8-0xA (Read): COS Status Inputs
Base +0x8-0xA (Write): COS Clear Inputs
Base +0xB (Read): COS Status TTL/CMOS
Base +0xB (Write): COS Clear TTL/CMOS
Base +0xE (Read/Write): COS EnableThe COS Enable register is used to enable/disable interrupts and configure the interrupt levels; each bit maps to a group of eight inputs as described below:
Bit 0: IRQ EN Rising Edge IN0-7
Bit 1: IRQ EN Rising Edge IN8-15
Bit 2: IRQ EN Rising Edge IN16-23
Bit 3: IRQ EN Rising Edge TTL0-7
Bit 4: IRQ EN Falling Edge IN0-7
Bit 5: IRQ EN Falling Edge IN8-15
Bit 6: IRQ EN Falling Edge IN16-23
Bit 7: IRQ EN Falling Edge TTL0-7
An interrupt is asserted when a change-of-state matching the interrupt level configuration respective for a particular group of eight inputs with enabled COS is detected.
The COS Status registers may be read to determine which inputs have changed; if interrupts were enabled, an IRQ will be generated for the set bits in these registers. Writing the value read from the COS Status register back to the respective COS Clear register will clear just those interrupts.
--- drivers/gpio/Kconfig | 3 + drivers/gpio/gpio-pcie-idio-24.c | 677 +++++++++++-------------------- 2 files changed, 250 insertions(+), 430 deletions(-)
drivers/gpio/Kconfig +3 -0
@@ -1665,7 +1665,10 @@ config GPIO_PCI_IDIO_16 config GPIO_PCIE_IDIO_24 tristate "ACCES PCIe-IDIO-24 GPIO support" + select REGMAP_IRQ + select REGMAP_MMIO select GPIOLIB_IRQCHIP + select GPIO_REGMAP help Enables GPIO support for the ACCES PCIe-IDIO-24 family (PCIe-IDIO-24, PCIe-IDI-24, PCIe-IDO-24, PCIe-IDIO-12). An interrupt is generated
drivers/gpio/gpio-pcie-idio-24.c +247 -430
753 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH RESEND 6/7 gpio: ws16c48: Migrate to the regmap API
In reply to William Breathitt GrayThe regmap API supports IO port accessors so we can take advantage of regmap abstractions rather than handling access to the device registers directly in the driver.
The WinSystems WS16C48 provides the following registers:
Offset 0x0-0x5: Port 0-5 I/O
Offset 0x6: Int_Pending
Offset 0x7: Page/Lock
Offset 0x8-0xA (Page 1): Pol_0-Pol_2
Offset 0x8-0xA (Page 2): Enab_0-Enab_2
Offset 0x8-0xA (Page 3): Int_ID0-Int_ID2Port 0-5 I/O provides access to 48 lines of digital I/O across six registers, each bit position corresponding to the respective line. Writing a 1 to a respective bit position causes that output pin to sink current, while writing a 0 to the same bit position causes that output pin to go to a high-impedance state and allows it to be used an input. Reads on a port report the inverted state (0 = high, 1 = low) of an I/O pin when used in input mode. Interrupts are supported on Port 0-2.
Int_Pending is a read-only register that reports the combined state of the INT_ID0 through INT_ID2 registers; an interrupt pending is indicated when any of the low three bits are set.
The Page/Lock register provides the following bits:
Bit 0-5: Port 0-5 I/O Lock
Bit 6-7: Page 0-3 SelectionFor Bits 0-5, writing a 1 to a respective bit position locks the output state of the corresponding I/O port. Writing the page number to Bits 6-7 selects that respective register page for use.
Pol_0-Pol_2 are accessible when Page 1 is selected. Writing a 1 to a respective bit position selects the rising edge detection interrupts for that input line, while writing a 0 to the same bit position selects the falling edge detection interrupts.
Enab_0-Enab_2 are accessible when Page 2 is selected. Writing a 1 to a respective bit position enables interrupts for that input line, while writing a 0 to that same bit position clears and disables interrupts for that input line.
Int_ID0-Int_ID2 are accessible when Page 3 is selected. A respective bit when read as a 1 indicates that an edge of the polarity set in the corresponding polarity register was detected for the corresponding input line. Writing any value to this register clears all pending interrupts for the register.
--- drivers/gpio/Kconfig | 3 + drivers/gpio/gpio-ws16c48.c | 552 ++++++++++++------------------------ 2 files changed, 188 insertions(+), 367 deletions(-)
drivers/gpio/Kconfig +3 -0
@@ -998,7 +998,10 @@ config GPIO_WINBOND config GPIO_WS16C48 tristate "WinSystems WS16C48 GPIO support" select ISA_BUS_API + select REGMAP_IRQ + select REGMAP_MMIO select GPIOLIB_IRQCHIP + select GPIO_REGMAP help Enables GPIO support for the WinSystems WS16C48. The base port addresses for the devices may be configured via the base module
drivers/gpio/gpio-ws16c48.c +185 -367
655 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH RESEND 7/7 gpio: ws16c48: Fix off-by-one error in WS16C48 resource region extent
In reply to William Breathitt GrayThe WinSystems WS16C48 I/O address region spans offsets 0x0 through 0xA, which is a total of 11 bytes. Fix the WS16C48_EXTENT define to the correct value of 11 so that access to necessary device registers is properly requested in the ws16c48_probe() callback by the devm_request_region() function call.
--- drivers/gpio/gpio-ws16c48.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-ws16c48.c +1 -1
@@ -17,7 +17,7 @@#include <linux/regmap.h> #include <linux/types.h> -#define WS16C48_EXTENT 10 +#define WS16C48_EXTENT 11#define MAX_NUM_WS16C48 max_num_isa_dev(WS16C48_EXTENT)static unsigned int base[MAX_NUM_WS16C48 ];
Signature · 1 line
2.41.0
Re: [RESEND PATCH 7/7] gpio: ws16c48: Fix off-by-one error in WS16C48 resource region extent
Quoted 7 lines · William Breathitt Gray
The WinSystems WS16C48 I/O address region spans offsets
0x0through0xA, which is a total of 11 bytes. Fix theWS16C48_EXTENTdefine to the correct value of 11 so that access to necessary device registers is properly requested in thews16c48_probe()callback by thedevm_request_region()function call.Fixes 2c05a0f29f41 ("gpio: ws16c48: Implement and utilize register structures")
Fixes should go first in the series, but I see no conflict here, I hope Bart can manage this when applying.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RESEND PATCH 7/7] gpio: ws16c48: Fix off-by-one error in WS16C48 resource region extent
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · William Breathitt Gray
The WinSystems WS16C48 I/O address region spans offsets
0x0through0xA, which is a total of 11 bytes. Fix theWS16C48_EXTENTdefine to the correct value of 11 so that access to necessary device registers is properly requested in thews16c48_probe()callback by thedevm_request_region()function call.
Quoted 10 lines
Quoted 1 line
Fixes 2c05a0f29f41 ("gpio: ws16c48: Implement and utilize register structures")Fixes should go first in the series, but I see no conflict here, I hope Bart can manage this when applying.
Reviewed-by Andy Shevchenko <[email protected]>Signature · 2 lines
With Best Regards, Andy Shevchenko
Bart, if you encounter any issues reordering this patch first before the others, just let me know and I'll send a rebased version with the appropriate context adjustments.
Thanks,
William Breathitt Gray
Quoted 7 lines · William Breathitt Gray
This patchset is a collection and resend of the lingering GPIO patches for the regmap migration of the ACCES and WinSystems drivers.[^1][^2] Previously, these patches were postponed due to pending dependency patches that have since been merged into mainline. Now that those dependencies are present in the GPIO tree, this patchset can be merged without incident. An IRQ handling fix for the ws16c48 driver is also included at the end.[^3]
The series:
The result is really nice!
Yours,
Linus Walleij
Quoted 32 lines · William Breathitt Gray
This patchset is a collection and resend of the lingering GPIO patches for the regmap migration of the ACCES and WinSystems drivers.[^1][^2] Previously, these patches were postponed due to pending dependency patches that have since been merged into mainline. Now that those dependencies are present in the GPIO tree, this patchset can be merged without incident. An IRQ handling fix for the ws16c48 driver is also included at the end.[^3]
[^1] https://lore.kernel.org/all/[email protected]/
[^2] https://lore.kernel.org/all/[email protected]/
[^3] https://lore.kernel.org/all/[email protected]/William Breathitt Gray (7):
gpio: idio-16: Migrate to the regmap API
gpio: 104-idio-16: Migrate to the regmap API
gpio: pci-idio-16: Migrate to the regmap API
gpio: idio-16: Remove unused legacy interface
gpio: pcie-idio-24: Migrate to the regmap API
gpio: ws16c48: Migrate to the regmap API
gpio: ws16c48: Fix off-by-one error in WS16C48 resource region extentdrivers/gpio/Kconfig | 13 +- drivers/gpio/gpio-104-idio-16.c | 286 +++---------- drivers/gpio/gpio-idio-16.c | 254 ++++++------ drivers/gpio/gpio-idio-16.h | 79 +--- drivers/gpio/gpio-pci-idio-16.c | 294 +++----------- drivers/gpio/gpio-pcie-idio-24.c | 677 +++++++++++-------------------- drivers/gpio/gpio-ws16c48.c | 554 +++++++++---------------- 7 files changed, 728 insertions(+), 1429 deletions(-)
Quoted 4 lines
base-commit:
87d0688483f56c748b37a5298bdc382df5cf8f74--
2.41.0
Queued the last patch for fixes and the rest for v6.6.
Bart