Migrate i8255 GPIO drivers to regmap API
Subsystems (5)
cover Migrate i8255 GPIO drivers to 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.
Precursor patches are provided for 104-dio-48e and 104-idi-48 to migrate their respective device-specific registers first in order to simplify the subsequent patch migrating the i8255 library and its dependents.
The struct i8255 control_state member serves as a cache of the i8255 device's control register. Does the regmap API support caching such that we won't need to manually update a control_state member?
William Breathitt Gray (3):
gpio: 104-dio-48e: Migrate to regmap API
gpio: 104-idi-48: Migrate to regmap API
gpio: i8255: Migrate to regmap API
drivers/gpio/gpio-104-dio-48e.c | 200 +++++++++++++++++++---------- drivers/gpio/gpio-104-idi-48.c | 110 +++++++++++----- drivers/gpio/gpio-gpio-mm.c | 97 ++++++++++---- drivers/gpio/gpio-i8255.c | 218 +++++++++++++++++++++----------- drivers/gpio/gpio-i8255.h | 54 ++++---- 5 files changed, 451 insertions(+), 228 deletions(-)
base-commit: b8b80348c57b360019071e17380298619c5d8066
Signature · 1 line
2.37.3
PATCH 1/3 gpio: 104-dio-48e: Migrate to 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.
--- drivers/gpio/gpio-104-dio-48e.c | 95 ++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 31 deletions(-)
drivers/gpio/gpio-104-dio-48e.c +64 -31
@@ -8,9 +8,9 @@*/ #include <linux/bits.h> #include <linux/device.h> +#include <linux/err.h> #include <linux/errno.h> #include <linux/gpio/driver.h> -#include <linux/io.h> #include <linux/ioport.h> #include <linux/interrupt.h> #include <linux/irqdesc.h>
@@ -18,6 +18,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/moduleparam.h> +#include <linux/regmap.h> #include <linux/spinlock.h> #include <linux/types.h>
@@ -38,30 +39,25 @@ static unsigned int num_irq;module_param_hw_array (irq, uint, irq, &num_irq,0 );MODULE_PARM_DESC (irq,"ACCES 104-DIO-48E interrupt line numbers" ); +#define DIO48E_NAME "104-dio-48e" + +#define DIO48E_REGS_OFFSET 0x8 +#define DIO48E_ENABLE_BUFFER_GRP0 0x0 +#define DIO48E_ENABLE_BUFFER_GRP1 0x1 +#define DIO48E_ENABLE_INTERRUPT 0x3 +#define DIO48E_DISABLE_INTERRUPT 0x3 +#define DIO48E_ENABLE_COUNTER 0x5 +#define DIO48E_DISABLE_COUNTER 0x5 +#define DIO48E_CLEAR_INTERRUPT 0x7 +#define DIO48E_NUM_PPI 2/** * struct dio48e_reg - device register structure * @ppi: Programmable Peripheral Interface groups -* @enable_buffer: Enable/Disable Buffer groups -* @unused1: Unused -* @enable_interrupt: Write: Enable Interrupt -* Read: Disable Interrupt -* @unused2: Unused -* @enable_counter: Write: Enable Counter/Timer Addressing -* Read: Disable Counter/Timer Addressing -* @unused3: Unused -* @clear_interrupt: Clear Interrupt */ struct dio48e_reg {struct i8255 ppi[DIO48E_NUM_PPI ]; -u8 enable_buffer[DIO48E_NUM_PPI ]; -u8 unused1; -u8 enable_interrupt; -u8 unused2; -u8 enable_counter; -u8 unused3; -u8 clear_interrupt; };/**
@@ -70,6 +66,7 @@ struct dio48e_reg {* @ppi_state: PPI device states * @lock: synchronization lock to prevent I/O race conditions * @reg: I/O address offset for the device registers +* @map: device register map * @irq_mask: I/O bits affected by interrupts */ struct dio48e_gpio {
@@ -77,6 +74,7 @@ struct dio48e_gpio {struct i8255_state ppi_state[DIO48E_NUM_PPI ];raw_spinlock_t lock;struct dio48e_reg __iomem *reg; +struct regmap *map;unsigned char irq_mask; };
@@ -154,6 +152,7 @@ static void dio48e_irq_mask(struct irq_data *data)struct dio48e_gpio *const dio48egpio =gpiochip_get_data (chip);const unsigned long offset =irqd_to_hwirq (data);unsigned long flags; +unsigned int val;/* only bit 3 on each respective Port C supports interrupts */ if (offset !=19 && offset !=43 )
@@ -168,8 +167,7 @@ static void dio48e_irq_mask(struct irq_data *data)gpiochip_disable_irq (chip, offset);if (!dio48egpio->irq_mask) -/* disable interrupts */ -ioread8 (&dio48egpio->reg->enable_interrupt); +regmap_read (dio48egpio->map,DIO48E_DISABLE_INTERRUPT , &val);raw_spin_unlock_irqrestore (&dio48egpio->lock, flags); }
@@ -188,9 +186,8 @@ static void dio48e_irq_unmask(struct irq_data *data)raw_spin_lock_irqsave (&dio48egpio->lock, flags);if (!dio48egpio->irq_mask) { -/* enable interrupts */ -iowrite8 (0x00 , &dio48egpio->reg->clear_interrupt); -iowrite8 (0x00 , &dio48egpio->reg->enable_interrupt); +regmap_write (dio48egpio->map,DIO48E_CLEAR_INTERRUPT ,0x00 ); +regmap_write (dio48egpio->map,DIO48E_ENABLE_INTERRUPT ,0x00 ); }gpiochip_enable_irq (chip, offset);
@@ -217,7 +214,7 @@ static int dio48e_irq_set_type(struct irq_data *data, unsigned int flow_type) }static const struct irq_chip dio48e_irqchip = { - .name ="104-dio-48e" , + .name =DIO48E_NAME , .irq_ack = dio48e_irq_ack, .irq_mask = dio48e_irq_mask, .irq_unmask = dio48e_irq_unmask,
@@ -239,7 +236,7 @@ static irqreturn_t dio48e_irq_handler(int irq, void *dev_id)raw_spin_lock (&dio48egpio->lock); -iowrite8 (0x00 , &dio48egpio->reg->clear_interrupt); +regmap_write (dio48egpio->map,DIO48E_CLEAR_INTERRUPT ,0x00 );raw_spin_unlock (&dio48egpio->lock);
@@ -269,11 +266,9 @@ static const char *dio48e_names[DIO48E_NGPIO] = {static int dio48e_irq_init_hw (struct gpio_chip *gc) {struct dio48e_gpio *const dio48egpio =gpiochip_get_data (gc); +unsigned int val; -/* Disable IRQ by default */ -ioread8 (&dio48egpio->reg->enable_interrupt); - -return 0 ; +return regmap_read (dio48egpio->map,DIO48E_DISABLE_INTERRUPT , &val); } static void dio48e_init_ppi(struct i8255 __iomem *const ppi,
@@ -291,10 +286,42 @@ static void dio48e_init_ppi(struct i8255 __iomem *const ppi, } } +static const struct regmap_range dio48e_wr_ranges[] = { +regmap_reg_range (0x0 ,0x1 ), +regmap_reg_range (0x3 ,0x3 ), +regmap_reg_range (0x5 ,0x5 ), +regmap_reg_range (0x7 ,0x7 ), +}; +static const struct regmap_range dio48e_rd_ranges[] = { +regmap_reg_range (0x3 ,0x3 ), +regmap_reg_range (0x5 ,0x5 ), +regmap_reg_range (0x7 ,0x7 ), +}; +static const struct regmap_access_table dio48e_wr_table = { + .yes_ranges = dio48e_wr_ranges, + .n_yes_ranges =ARRAY_SIZE (dio48e_wr_ranges), +}; +static const struct regmap_access_table dio48e_rd_table = { + .yes_ranges = dio48e_rd_ranges, + .n_yes_ranges =ARRAY_SIZE (dio48e_rd_ranges), +}; + +static const struct regmap_config dio48e_regmap_config = { + .name =DIO48E_NAME , + .reg_bits =8 , + .val_bits =8 , + .reg_stride =1 , + .io_port = true, + .max_register =0x7 , + .wr_table = &dio48e_wr_table, + .rd_table = &dio48e_rd_table, +}; +static int dio48e_probe (struct device *dev,unsigned int id) {struct dio48e_gpio *dio48egpio;const char *const name =dev_name (dev); +void __iomem *regs;struct gpio_irq_chip *girq;int err;
@@ -308,9 +335,15 @@ static int dio48e_probe(struct device *dev, unsigned int id)return -EBUSY ; } - dio48egpio->reg =devm_ioport_map (dev, base[id],DIO48E_EXTENT ); -if (!dio48egpio->reg) + regs =devm_ioport_map (dev, base[id],DIO48E_EXTENT ); +if (!regs)return -ENOMEM ; + dio48egpio->reg = regs; + + dio48egpio->map =devm_regmap_init_mmio (dev, regs +DIO48E_REGS_OFFSET , + &dio48e_regmap_config); +if (IS_ERR (dio48egpio->map)) +return PTR_ERR (dio48egpio->map); dio48egpio->chip.label = name; dio48egpio->chip.parent = dev;
@@ -360,7 +393,7 @@ static int dio48e_probe(struct device *dev, unsigned int id)static struct isa_driver dio48e_driver = { .probe = dio48e_probe, .driver = { - .name ="104-dio-48e" + .name =DIO48E_NAME , }, };module_isa_driver_with_irq (dio48e_driver, num_dio48e, num_irq);
Signature · 1 line
2.37.3
Re: [PATCH 1/3] gpio: 104-dio-48e: Migrate to regmap API
Quoted 3 lines · William Breathitt Gray
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.
I'm wondering if gpio-regmap can be used for these...
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 1/3] gpio: 104-dio-48e: Migrate to regmap API
Quoted 10 lines · Andy Shevchenko
Quoted 3 lines · William Breathitt Gray
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.
I'm wondering if gpio-regmap can be used for these...
Signature · 2 lines
With Best Regards, Andy Shevchenko
I might be able to update the gpio-i8255 functions to take advantage of gpio-regmap, but the changes in the precursor patches are primarily to handle the device interrupts. Currently, I call gpio_irq_chip_set_chip() to assign the struct irq_chip structure to the struct gpio_irq_chip structure. What would be the equivalent for gpio-regmap?
William Breathitt Gray
PATCH 2/3 gpio: 104-idi-48: Migrate to 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.
--- drivers/gpio/gpio-104-idi-48.c | 54 ++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 15 deletions(-)
drivers/gpio/gpio-104-idi-48.c +39 -15
@@ -8,9 +8,9 @@*/ #include <linux/bits.h> #include <linux/device.h> +#include <linux/err.h> #include <linux/errno.h> #include <linux/gpio/driver.h> -#include <linux/io.h> #include <linux/ioport.h> #include <linux/interrupt.h> #include <linux/irqdesc.h>
@@ -18,6 +18,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/moduleparam.h> +#include <linux/regmap.h> #include <linux/spinlock.h> #include <linux/types.h>
@@ -43,22 +44,27 @@ MODULE_PARM_DESC(irq, "ACCES 104-IDI-48 interrupt line numbers");* @port0: Port 0 Inputs * @unused: Unused * @port1: Port 1 Inputs -* @irq: Read: IRQ Status Register/IRQ Clear -* Write: IRQ Enable/Disable */ struct idi_48_reg {u8 port0[3 ];u8 unused;u8 port1[3 ]; -u8 irq; }; +#define IDI48_NAME "104-idi-48" + +#define IDI48_REGS_OFFSET 0x3 +#define IDI48_IRQ_STATUS 0x0 +#define IDI48_IRQ_CLEAR 0x0 +#define IDI48_IRQ_ENABLE 0x0 +/** * struct idi_48_gpio - GPIO device private data structure * @chip: instance of the gpio_chip * @lock: synchronization lock to prevent I/O race conditions * @irq_mask: input bits affected by interrupts * @reg: I/O address offset for the device registers +* @map: device register map * @cos_enb: Change-Of-State IRQ enable boundaries mask */ struct idi_48_gpio {
@@ -66,6 +72,7 @@ struct idi_48_gpio {spinlock_t lock;unsigned char irq_mask[6 ];struct idi_48_reg __iomem *reg; +struct regmap *map;unsigned char cos_enb; };
@@ -122,7 +129,7 @@ static void idi_48_irq_mask(struct irq_data *data) idi48gpio->cos_enb &= ~BIT (boundary); -iowrite8 (idi48gpio->cos_enb, &idi48gpio->reg->irq); +regmap_write (idi48gpio->map,IDI48_IRQ_ENABLE , idi48gpio->cos_enb); exit:spin_unlock_irqrestore (&idi48gpio->lock, flags);
@@ -151,7 +158,7 @@ static void idi_48_irq_unmask(struct irq_data *data) idi48gpio->cos_enb |=BIT (boundary); -iowrite8 (idi48gpio->cos_enb, &idi48gpio->reg->irq); +regmap_write (idi48gpio->map,IDI48_IRQ_ENABLE , idi48gpio->cos_enb); exit:spin_unlock_irqrestore (&idi48gpio->lock, flags);
@@ -168,7 +175,7 @@ static int idi_48_irq_set_type(struct irq_data *data, unsigned int flow_type) }static const struct irq_chip idi_48_irqchip = { - .name ="104-idi-48" , + .name =IDI48_NAME , .irq_ack = idi_48_irq_ack, .irq_mask = idi_48_irq_mask, .irq_unmask = idi_48_irq_unmask,
@@ -180,6 +187,7 @@ static const struct irq_chip idi_48_irqchip = {static irqreturn_t idi_48_irq_handler (int irq,void *dev_id) {struct idi_48_gpio *const idi48gpio = dev_id; +unsigned int irq_status;unsigned long cos_status;unsigned long boundary;unsigned long irq_mask;
@@ -189,7 +197,8 @@ static irqreturn_t idi_48_irq_handler(int irq, void *dev_id)spin_lock (&idi48gpio->lock); - cos_status =ioread8 (&idi48gpio->reg->irq); +regmap_read (idi48gpio->map,IDI48_IRQ_STATUS , &irq_status); + cos_status = irq_status;/* IRQ Status (bit 6) is active low (0 = IRQ generated by device) */ if (cos_status &BIT (6 )) {
@@ -231,18 +240,27 @@ static const char *idi48_names[IDI48_NGPIO] = {static int idi_48_irq_init_hw (struct gpio_chip *gc) {struct idi_48_gpio *const idi48gpio =gpiochip_get_data (gc); +unsigned int val;/* Disable IRQ by default */ -iowrite8 (0 , &idi48gpio->reg->irq); -ioread8 (&idi48gpio->reg->irq); - -return 0 ; +regmap_write (idi48gpio->map,IDI48_IRQ_ENABLE ,0x00 ); +return regmap_read (idi48gpio->map,IDI48_IRQ_CLEAR , &val); } +static const struct regmap_config idi48_regmap_config = { + .name =IDI48_NAME , + .reg_bits =8 , + .val_bits =8 , + .reg_stride =1 , + .io_port = true, + .max_register =0x0 , +}; +static int idi_48_probe (struct device *dev,unsigned int id) {struct idi_48_gpio *idi48gpio;const char *const name =dev_name (dev); +void __iomem *regs;struct gpio_irq_chip *girq;int err;
@@ -256,9 +274,15 @@ static int idi_48_probe(struct device *dev, unsigned int id)return -EBUSY ; } - idi48gpio->reg =devm_ioport_map (dev, base[id],IDI_48_EXTENT ); -if (!idi48gpio->reg) + regs =devm_ioport_map (dev, base[id],IDI_48_EXTENT ); +if (!regs)return -ENOMEM ; + idi48gpio->reg = regs; + + idi48gpio->map =devm_regmap_init_mmio (dev, regs +IDI48_REGS_OFFSET , + &idi48_regmap_config); +if (IS_ERR (idi48gpio->map)) +return PTR_ERR (idi48gpio->map); idi48gpio->chip.label = name; idi48gpio->chip.parent = dev;
@@ -302,7 +326,7 @@ static int idi_48_probe(struct device *dev, unsigned int id)static struct isa_driver idi_48_driver = { .probe = idi_48_probe, .driver = { - .name ="104-idi-48" + .name =IDI48_NAME , }, };module_isa_driver_with_irq (idi_48_driver, num_idi_48, num_irq);
Signature · 1 line
2.37.3
PATCH 3/3 gpio: i8255: Migrate to 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 104-dio-48e, 104-idi-48, and gpio-mm modules depend on the i8255 library and are thus updated accordingly.
The struct i8255_state data structure is removed and its role merged into the struct i8255 data structure which is updated to hold regmap register maps. Similarly, the i8255_state_init() function is repurposed to the i8255_init() function; the other i8255 library functions are adjusted to utilize the regmap API. The I8255_REGMAP_CONFIG macro is introduced to facilitate the initialization of struct regmap_config data structures for i8255 register mappings.
--- drivers/gpio/gpio-104-dio-48e.c | 111 ++++++++++------ drivers/gpio/gpio-104-idi-48.c | 60 ++++++--- drivers/gpio/gpio-gpio-mm.c | 97 ++++++++++---- drivers/gpio/gpio-i8255.c | 218 +++++++++++++++++++++----------- drivers/gpio/gpio-i8255.h | 54 ++++---- 5 files changed, 353 insertions(+), 187 deletions(-)
drivers/gpio/gpio-104-dio-48e.c +75 -36
@@ -52,28 +52,18 @@ MODULE_PARM_DESC(irq, "ACCES 104-DIO-48E interrupt line numbers");#define DIO48E_NUM_PPI 2 -/** -* struct dio48e_reg - device register structure -* @ppi: Programmable Peripheral Interface groups -*/ -struct dio48e_reg { -struct i8255 ppi[DIO48E_NUM_PPI ]; -}; -/** * struct dio48e_gpio - GPIO device private data structure * @chip: instance of the gpio_chip -* @ppi_state: PPI device states +* @ppi: Programmable Peripheral Interface device structures * @lock: synchronization lock to prevent I/O race conditions -* @reg: I/O address offset for the device registers * @map: device register map * @irq_mask: I/O bits affected by interrupts */ struct dio48e_gpio {struct gpio_chip chip; -struct i8255_state ppi_state[DIO48E_NUM_PPI ]; +struct i8255 ppi[DIO48E_NUM_PPI ];raw_spinlock_t lock; -struct dio48e_reg __iomem *reg;struct regmap *map;unsigned char irq_mask; };
@@ -82,7 +72,7 @@ static int dio48e_gpio_get_direction(struct gpio_chip *chip, unsigned int offset {struct dio48e_gpio *const dio48egpio =gpiochip_get_data (chip); -if (i8255_get_direction (dio48egpio->ppi_state, offset)) +if (i8255_get_direction (dio48egpio->ppi, offset))return GPIO_LINE_DIRECTION_IN ;return GPIO_LINE_DIRECTION_OUT ;
@@ -92,10 +82,7 @@ static int dio48e_gpio_direction_input(struct gpio_chip *chip, unsigned int offs {struct dio48e_gpio *const dio48egpio =gpiochip_get_data (chip); -i8255_direction_input (dio48egpio->reg->ppi, dio48egpio->ppi_state, - offset); - -return 0 ; +return i8255_direction_input (dio48egpio->ppi, offset); } static int dio48e_gpio_direction_output(struct gpio_chip *chip, unsigned int offset,
@@ -103,17 +90,20 @@ static int dio48e_gpio_direction_output(struct gpio_chip *chip, unsigned int off {struct dio48e_gpio *const dio48egpio =gpiochip_get_data (chip); -i8255_direction_output (dio48egpio->reg->ppi, dio48egpio->ppi_state, - offset, value); - -return 0 ; +return i8255_direction_output (dio48egpio->ppi, offset, value); }static int dio48e_gpio_get (struct gpio_chip *chip,unsigned int offset) {struct dio48e_gpio *const dio48egpio =gpiochip_get_data (chip); +bool value; +int err; -return i8255_get (dio48egpio->reg->ppi, offset); + err =i8255_get (dio48egpio->ppi, offset, &value); +if (err) +return err; + +return value; } static int dio48e_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
@@ -121,25 +111,32 @@ static int dio48e_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, {struct dio48e_gpio *const dio48egpio =gpiochip_get_data (chip); -i8255_get_multiple (dio48egpio->reg->ppi, mask, bits, chip->ngpio); - -return 0 ; +return i8255_get_multiple (dio48egpio->ppi, mask, bits, chip->ngpio); }static void dio48e_gpio_set (struct gpio_chip *chip,unsigned int offset,int value) {struct dio48e_gpio *const dio48egpio =gpiochip_get_data (chip); +int err; -i8255_set (dio48egpio->reg->ppi, dio48egpio->ppi_state, offset, value); + err =i8255_set (dio48egpio->ppi, offset, value); +if (err) +dev_warn (chip->parent, +"Unable to set GPIO offset %u to value %d (errno %d)\n" , + offset, value, err); }static void dio48e_gpio_set_multiple (struct gpio_chip *chip,unsigned long *mask,unsigned long *bits) {struct dio48e_gpio *const dio48egpio =gpiochip_get_data (chip); +int err; -i8255_set_multiple (dio48egpio->reg->ppi, dio48egpio->ppi_state, mask, - bits, chip->ngpio); + err =i8255_set_multiple (dio48egpio->ppi, mask, bits, chip->ngpio); +if (err) +dev_warn (chip->parent, +"Unable to set GPIO with mask %lu and bits %lu (errno %d)\n" , + *mask, *bits, err); }static void dio48e_irq_ack (struct irq_data *data)
@@ -271,19 +268,52 @@ static int dio48e_irq_init_hw(struct gpio_chip *gc)return regmap_read (dio48egpio->map,DIO48E_DISABLE_INTERRUPT , &val); } -static void dio48e_init_ppi (struct i8255 __iomem *const ppi, -struct i8255_state *const ppi_state) +static const struct regmap_range dio48e_ppi_rd_ranges[] = { +regmap_reg_range (0x0 ,0x2 ), +}; +static const struct regmap_access_table dio48e_ppi_rd_table = { + .yes_ranges = dio48e_ppi_rd_ranges, + .n_yes_ranges =ARRAY_SIZE (dio48e_ppi_rd_ranges), +}; + +static int devm_dio48e_init_ppi_maps (struct device *const dev, +struct regmap **const maps, +void __iomem *const regs) +{ +struct regmap_config config =I8255_REGMAP_CONFIG ; +unsigned long i; + + config.io_port = true; + config.rd_table = &dio48e_ppi_rd_table; + +for (i =0 ; i <DIO48E_NUM_PPI ; i++) { + maps[i] =devm_regmap_init_mmio (dev, regs + i *4 , &config); +if (IS_ERR (maps[i])) +return PTR_ERR (maps[i]); + } + +return 0 ; +} + +static int dio48e_init_ppi (struct i8255 *const ppi) {const unsigned long ngpio =24 ;const unsigned long mask =GENMASK (ngpio -1 ,0 );const unsigned long bits =0 ;unsigned long i; +int err;/* Initialize all GPIO to output 0 */ for (i =0 ; i <DIO48E_NUM_PPI ; i++) { -i8255_mode0_output (&ppi[i]); -i8255_set_multiple (&ppi[i], &ppi_state[i], &mask, &bits, ngpio); + err =i8255_mode0_output (&ppi[i]); +if (err) +return err; + err =i8255_set_multiple (&ppi[i], &mask, &bits, ngpio); +if (err) +return err; } + +return 0 ; }static const struct regmap_range dio48e_wr_ranges[] = {
@@ -322,6 +352,7 @@ static int dio48e_probe(struct device *dev, unsigned int id)struct dio48e_gpio *dio48egpio;const char *const name =dev_name (dev);void __iomem *regs; +struct regmap *ppi_maps[DIO48E_NUM_PPI ];struct gpio_irq_chip *girq;int err;
@@ -338,7 +369,18 @@ static int dio48e_probe(struct device *dev, unsigned int id) regs =devm_ioport_map (dev, base[id],DIO48E_EXTENT );if (!regs)return -ENOMEM ; - dio48egpio->reg = regs; + + err =devm_dio48e_init_ppi_maps (dev, ppi_maps, regs); +if (err) { +dev_err (dev,"Regmaps initialization failed (%d)\n" , err); +return err; + } +i8255_init (dio48egpio->ppi,DIO48E_NUM_PPI , ppi_maps); + err =dio48e_init_ppi (dio48egpio->ppi); +if (err) { +dev_err (dev,"PPI initialization failed (%d)\n" , err); +return err; + } dio48egpio->map =devm_regmap_init_mmio (dev, regs +DIO48E_REGS_OFFSET , &dio48e_regmap_config);
@@ -371,9 +413,6 @@ static int dio48e_probe(struct device *dev, unsigned int id)raw_spin_lock_init (&dio48egpio->lock); -i8255_state_init (dio48egpio->ppi_state,DIO48E_NUM_PPI ); -dio48e_init_ppi (dio48egpio->reg->ppi, dio48egpio->ppi_state); - err =devm_gpiochip_add_data (dev, &dio48egpio->chip, dio48egpio);if (err) {dev_err (dev,"GPIO registering failed (%d)\n" , err);
drivers/gpio/gpio-104-idi-48.c +39 -21
115 lines not on this page · raw message
drivers/gpio/gpio-gpio-mm.c +69 -28
185 lines not on this page · raw message
drivers/gpio/gpio-i8255.c +144 -74
387 lines not on this page · raw message
drivers/gpio/gpio-i8255.h +26 -28
70 lines not on this page · raw message
Signature · 1 line
2.37.3
Quoted 11 lines · William Breathitt Gray
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.
Precursor patches are provided for 104-dio-48e and 104-idi-48 to migrate their respective device-specific registers first in order to simplify the subsequent patch migrating the i8255 library and its dependents.
The struct i8255
control_statemember serves as a cache of the i8255 device's control register. Does the regmap API support caching such that we won't need to manually update acontrol_statemember?
Yes, regmap supports caching and IIRC it's opt-out.
Quoted 17 lines
William Breathitt Gray (3):
gpio: 104-dio-48e: Migrate to regmap API
gpio: 104-idi-48: Migrate to regmap API
gpio: i8255: Migrate to regmap APIdrivers/gpio/gpio-104-dio-48e.c | 200 +++++++++++++++++++---------- drivers/gpio/gpio-104-idi-48.c | 110 +++++++++++----- drivers/gpio/gpio-gpio-mm.c | 97 ++++++++++---- drivers/gpio/gpio-i8255.c | 218 +++++++++++++++++++++----------- drivers/gpio/gpio-i8255.h | 54 ++++---- 5 files changed, 451 insertions(+), 228 deletions(-)base-commit:
b8b80348c57b360019071e17380298619c5d8066Signature · 1 line
2.37.3
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 9 lines · Andy Shevchenko
Quoted 8 lines · William Breathitt Gray
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.
Precursor patches are provided for 104-dio-48e and 104-idi-48 to migrate their respective device-specific registers first in order to simplify the subsequent patch migrating the i8255 library and its dependents.
Quoted 5 lines
Quoted 3 lines
The struct i8255
control_statemember serves as a cache of the i8255 device's control register. Does the regmap API support caching such that we won't need to manually update acontrol_statemember?Yes, regmap supports caching and IIRC it's opt-out.
Looks like it's disabled by default if I understand correctly: the cache_type member of struct regmap_config has a default value of REGCACHE_NONE if not explicitly set. I'll set cache_type to enable caching and remove the control_state member in v2 then.
William Breathitt Gray