Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: 104-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. Migrate the 104-idio-16 module to the new
idio-16 library interface leveraging the gpio-regmap API.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/1f24a1f18c9a9daa4983713e0a5b53e838d624a8.1680618405.git.william.gray@linaro.org/
Signed-off-by: William Breathitt Gray <william.gray@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

authored by

William Breathitt Gray and committed by
Bartosz Golaszewski
2c210c9a db022478

+64 -224
+1 -1
drivers/gpio/Kconfig
··· 872 872 tristate "ACCES 104-IDIO-16 GPIO support" 873 873 depends on PC104 874 874 select ISA_BUS_API 875 - select GPIOLIB_IRQCHIP 875 + select REGMAP_MMIO 876 876 select GPIO_IDIO_16 877 877 help 878 878 Enables GPIO support for the ACCES 104-IDIO-16 family (104-IDIO-16,
+63 -223
drivers/gpio/gpio-104-idio-16.c
··· 6 6 * This driver supports the following ACCES devices: 104-IDIO-16, 7 7 * 104-IDIO-16E, 104-IDO-16, 104-IDIO-8, 104-IDIO-8E, and 104-IDO-8. 8 8 */ 9 - #include <linux/bitmap.h> 9 + #include <linux/bits.h> 10 10 #include <linux/device.h> 11 - #include <linux/errno.h> 12 - #include <linux/gpio/driver.h> 13 - #include <linux/io.h> 11 + #include <linux/err.h> 14 12 #include <linux/ioport.h> 15 - #include <linux/interrupt.h> 16 - #include <linux/irqdesc.h> 13 + #include <linux/irq.h> 17 14 #include <linux/isa.h> 18 15 #include <linux/kernel.h> 19 16 #include <linux/module.h> 20 17 #include <linux/moduleparam.h> 21 - #include <linux/spinlock.h> 18 + #include <linux/regmap.h> 22 19 #include <linux/types.h> 23 20 24 21 #include "gpio-idio-16.h" ··· 33 36 module_param_hw_array(irq, uint, irq, &num_irq, 0); 34 37 MODULE_PARM_DESC(irq, "ACCES 104-IDIO-16 interrupt line numbers"); 35 38 36 - /** 37 - * struct idio_16_gpio - GPIO device private data structure 38 - * @chip: instance of the gpio_chip 39 - * @lock: synchronization lock to prevent I/O race conditions 40 - * @irq_mask: I/O bits affected by interrupts 41 - * @reg: I/O address offset for the device registers 42 - * @state: ACCES IDIO-16 device state 43 - */ 44 - struct idio_16_gpio { 45 - struct gpio_chip chip; 46 - raw_spinlock_t lock; 47 - unsigned long irq_mask; 48 - struct idio_16 __iomem *reg; 49 - struct idio_16_state state; 39 + static const struct regmap_range idio_16_wr_ranges[] = { 40 + regmap_reg_range(0x0, 0x2), regmap_reg_range(0x4, 0x4), 41 + }; 42 + static const struct regmap_range idio_16_rd_ranges[] = { 43 + regmap_reg_range(0x1, 0x2), regmap_reg_range(0x5, 0x5), 44 + }; 45 + static const struct regmap_range idio_16_precious_ranges[] = { 46 + regmap_reg_range(0x2, 0x2), 47 + }; 48 + static const struct regmap_access_table idio_16_wr_table = { 49 + .yes_ranges = idio_16_wr_ranges, 50 + .n_yes_ranges = ARRAY_SIZE(idio_16_wr_ranges), 51 + }; 52 + static const struct regmap_access_table idio_16_rd_table = { 53 + .yes_ranges = idio_16_rd_ranges, 54 + .n_yes_ranges = ARRAY_SIZE(idio_16_rd_ranges), 55 + }; 56 + static const struct regmap_access_table idio_16_precious_table = { 57 + .yes_ranges = idio_16_precious_ranges, 58 + .n_yes_ranges = ARRAY_SIZE(idio_16_precious_ranges), 59 + }; 60 + static const struct regmap_config idio_16_regmap_config = { 61 + .reg_bits = 8, 62 + .reg_stride = 1, 63 + .val_bits = 8, 64 + .io_port = true, 65 + .wr_table = &idio_16_wr_table, 66 + .rd_table = &idio_16_rd_table, 67 + .volatile_table = &idio_16_rd_table, 68 + .precious_table = &idio_16_precious_table, 69 + .cache_type = REGCACHE_FLAT, 70 + .use_raw_spinlock = true, 50 71 }; 51 72 52 - static int idio_16_gpio_get_direction(struct gpio_chip *chip, 53 - unsigned int offset) 54 - { 55 - if (idio_16_get_direction(offset)) 56 - return GPIO_LINE_DIRECTION_IN; 57 - 58 - return GPIO_LINE_DIRECTION_OUT; 59 - } 60 - 61 - static int idio_16_gpio_direction_input(struct gpio_chip *chip, 62 - unsigned int offset) 63 - { 64 - return 0; 65 - } 66 - 67 - static int idio_16_gpio_direction_output(struct gpio_chip *chip, 68 - unsigned int offset, int value) 69 - { 70 - chip->set(chip, offset, value); 71 - return 0; 72 - } 73 - 74 - static int idio_16_gpio_get(struct gpio_chip *chip, unsigned int offset) 75 - { 76 - struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); 77 - 78 - return idio_16_get(idio16gpio->reg, &idio16gpio->state, offset); 79 - } 80 - 81 - static int idio_16_gpio_get_multiple(struct gpio_chip *chip, 82 - unsigned long *mask, unsigned long *bits) 83 - { 84 - struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); 85 - 86 - idio_16_get_multiple(idio16gpio->reg, &idio16gpio->state, mask, bits); 87 - 88 - return 0; 89 - } 90 - 91 - static void idio_16_gpio_set(struct gpio_chip *chip, unsigned int offset, 92 - int value) 93 - { 94 - struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); 95 - 96 - idio_16_set(idio16gpio->reg, &idio16gpio->state, offset, value); 97 - } 98 - 99 - static void idio_16_gpio_set_multiple(struct gpio_chip *chip, 100 - unsigned long *mask, unsigned long *bits) 101 - { 102 - struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); 103 - 104 - idio_16_set_multiple(idio16gpio->reg, &idio16gpio->state, mask, bits); 105 - } 106 - 107 - static void idio_16_irq_ack(struct irq_data *data) 108 - { 109 - } 110 - 111 - static void idio_16_irq_mask(struct irq_data *data) 112 - { 113 - struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 114 - struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); 115 - const unsigned long offset = irqd_to_hwirq(data); 116 - unsigned long flags; 117 - 118 - idio16gpio->irq_mask &= ~BIT(offset); 119 - gpiochip_disable_irq(chip, offset); 120 - 121 - if (!idio16gpio->irq_mask) { 122 - raw_spin_lock_irqsave(&idio16gpio->lock, flags); 123 - 124 - iowrite8(0, &idio16gpio->reg->irq_ctl); 125 - 126 - raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); 73 + /* Only input lines (GPIO 16-31) support interrupts */ 74 + #define IDIO_16_REGMAP_IRQ(_id) \ 75 + [16 + _id] = { \ 76 + .mask = BIT(_id), \ 77 + .type = { .types_supported = IRQ_TYPE_EDGE_BOTH }, \ 127 78 } 128 - } 129 79 130 - static void idio_16_irq_unmask(struct irq_data *data) 131 - { 132 - struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 133 - struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip); 134 - const unsigned long offset = irqd_to_hwirq(data); 135 - const unsigned long prev_irq_mask = idio16gpio->irq_mask; 136 - unsigned long flags; 137 - 138 - gpiochip_enable_irq(chip, offset); 139 - idio16gpio->irq_mask |= BIT(offset); 140 - 141 - if (!prev_irq_mask) { 142 - raw_spin_lock_irqsave(&idio16gpio->lock, flags); 143 - 144 - ioread8(&idio16gpio->reg->irq_ctl); 145 - 146 - raw_spin_unlock_irqrestore(&idio16gpio->lock, flags); 147 - } 148 - } 149 - 150 - static int idio_16_irq_set_type(struct irq_data *data, unsigned int flow_type) 151 - { 152 - /* The only valid irq types are none and both-edges */ 153 - if (flow_type != IRQ_TYPE_NONE && 154 - (flow_type & IRQ_TYPE_EDGE_BOTH) != IRQ_TYPE_EDGE_BOTH) 155 - return -EINVAL; 156 - 157 - return 0; 158 - } 159 - 160 - static const struct irq_chip idio_16_irqchip = { 161 - .name = "104-idio-16", 162 - .irq_ack = idio_16_irq_ack, 163 - .irq_mask = idio_16_irq_mask, 164 - .irq_unmask = idio_16_irq_unmask, 165 - .irq_set_type = idio_16_irq_set_type, 166 - .flags = IRQCHIP_IMMUTABLE, 167 - GPIOCHIP_IRQ_RESOURCE_HELPERS, 80 + static const struct regmap_irq idio_16_regmap_irqs[] = { 81 + IDIO_16_REGMAP_IRQ(0), IDIO_16_REGMAP_IRQ(1), IDIO_16_REGMAP_IRQ(2), /* 0-2 */ 82 + IDIO_16_REGMAP_IRQ(3), IDIO_16_REGMAP_IRQ(4), IDIO_16_REGMAP_IRQ(5), /* 3-5 */ 83 + IDIO_16_REGMAP_IRQ(6), IDIO_16_REGMAP_IRQ(7), IDIO_16_REGMAP_IRQ(8), /* 6-8 */ 84 + IDIO_16_REGMAP_IRQ(9), IDIO_16_REGMAP_IRQ(10), IDIO_16_REGMAP_IRQ(11), /* 9-11 */ 85 + IDIO_16_REGMAP_IRQ(12), IDIO_16_REGMAP_IRQ(13), IDIO_16_REGMAP_IRQ(14), /* 12-14 */ 86 + IDIO_16_REGMAP_IRQ(15), /* 15 */ 168 87 }; 169 - 170 - static irqreturn_t idio_16_irq_handler(int irq, void *dev_id) 171 - { 172 - struct idio_16_gpio *const idio16gpio = dev_id; 173 - struct gpio_chip *const chip = &idio16gpio->chip; 174 - int gpio; 175 - 176 - for_each_set_bit(gpio, &idio16gpio->irq_mask, chip->ngpio) 177 - generic_handle_domain_irq(chip->irq.domain, gpio); 178 - 179 - raw_spin_lock(&idio16gpio->lock); 180 - 181 - iowrite8(0, &idio16gpio->reg->in0_7); 182 - 183 - raw_spin_unlock(&idio16gpio->lock); 184 - 185 - return IRQ_HANDLED; 186 - } 187 - 188 - #define IDIO_16_NGPIO 32 189 - static const char *idio_16_names[IDIO_16_NGPIO] = { 190 - "OUT0", "OUT1", "OUT2", "OUT3", "OUT4", "OUT5", "OUT6", "OUT7", 191 - "OUT8", "OUT9", "OUT10", "OUT11", "OUT12", "OUT13", "OUT14", "OUT15", 192 - "IIN0", "IIN1", "IIN2", "IIN3", "IIN4", "IIN5", "IIN6", "IIN7", 193 - "IIN8", "IIN9", "IIN10", "IIN11", "IIN12", "IIN13", "IIN14", "IIN15" 194 - }; 195 - 196 - static int idio_16_irq_init_hw(struct gpio_chip *gc) 197 - { 198 - struct idio_16_gpio *const idio16gpio = gpiochip_get_data(gc); 199 - 200 - /* Disable IRQ by default */ 201 - iowrite8(0, &idio16gpio->reg->irq_ctl); 202 - iowrite8(0, &idio16gpio->reg->in0_7); 203 - 204 - return 0; 205 - } 206 88 207 89 static int idio_16_probe(struct device *dev, unsigned int id) 208 90 { 209 - struct idio_16_gpio *idio16gpio; 210 91 const char *const name = dev_name(dev); 211 - struct gpio_irq_chip *girq; 212 - int err; 213 - 214 - idio16gpio = devm_kzalloc(dev, sizeof(*idio16gpio), GFP_KERNEL); 215 - if (!idio16gpio) 216 - return -ENOMEM; 92 + struct idio_16_regmap_config config = {}; 93 + void __iomem *regs; 94 + struct regmap *map; 217 95 218 96 if (!devm_request_region(dev, base[id], IDIO_16_EXTENT, name)) { 219 97 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", ··· 96 224 return -EBUSY; 97 225 } 98 226 99 - idio16gpio->reg = devm_ioport_map(dev, base[id], IDIO_16_EXTENT); 100 - if (!idio16gpio->reg) 227 + regs = devm_ioport_map(dev, base[id], IDIO_16_EXTENT); 228 + if (!regs) 101 229 return -ENOMEM; 102 230 103 - idio16gpio->chip.label = name; 104 - idio16gpio->chip.parent = dev; 105 - idio16gpio->chip.owner = THIS_MODULE; 106 - idio16gpio->chip.base = -1; 107 - idio16gpio->chip.ngpio = IDIO_16_NGPIO; 108 - idio16gpio->chip.names = idio_16_names; 109 - idio16gpio->chip.get_direction = idio_16_gpio_get_direction; 110 - idio16gpio->chip.direction_input = idio_16_gpio_direction_input; 111 - idio16gpio->chip.direction_output = idio_16_gpio_direction_output; 112 - idio16gpio->chip.get = idio_16_gpio_get; 113 - idio16gpio->chip.get_multiple = idio_16_gpio_get_multiple; 114 - idio16gpio->chip.set = idio_16_gpio_set; 115 - idio16gpio->chip.set_multiple = idio_16_gpio_set_multiple; 231 + map = devm_regmap_init_mmio(dev, regs, &idio_16_regmap_config); 232 + if (IS_ERR(map)) 233 + return dev_err_probe(dev, PTR_ERR(map), "Unable to initialize register map\n"); 116 234 117 - idio_16_state_init(&idio16gpio->state); 118 - /* FET off states are represented by bit values of "1" */ 119 - bitmap_fill(idio16gpio->state.out_state, IDIO_16_NOUT); 235 + config.parent = dev; 236 + config.map = map; 237 + config.regmap_irqs = idio_16_regmap_irqs; 238 + config.num_regmap_irqs = ARRAY_SIZE(idio_16_regmap_irqs); 239 + config.irq = irq[id]; 240 + config.no_status = true; 120 241 121 - girq = &idio16gpio->chip.irq; 122 - gpio_irq_chip_set_chip(girq, &idio_16_irqchip); 123 - /* This will let us handle the parent IRQ in the driver */ 124 - girq->parent_handler = NULL; 125 - girq->num_parents = 0; 126 - girq->parents = NULL; 127 - girq->default_type = IRQ_TYPE_NONE; 128 - girq->handler = handle_edge_irq; 129 - girq->init_hw = idio_16_irq_init_hw; 130 - 131 - raw_spin_lock_init(&idio16gpio->lock); 132 - 133 - err = devm_gpiochip_add_data(dev, &idio16gpio->chip, idio16gpio); 134 - if (err) { 135 - dev_err(dev, "GPIO registering failed (%d)\n", err); 136 - return err; 137 - } 138 - 139 - err = devm_request_irq(dev, irq[id], idio_16_irq_handler, 0, name, 140 - idio16gpio); 141 - if (err) { 142 - dev_err(dev, "IRQ handler registering failed (%d)\n", err); 143 - return err; 144 - } 145 - 146 - return 0; 242 + return devm_idio_16_regmap_register(dev, &config); 147 243 } 148 244 149 245 static struct isa_driver idio_16_driver = {