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

gpio: gpio-mm: 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. The gpio-mm module is migrated to the new i8255
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>
Signed-off-by: William Breathitt Gray <william.gray@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

authored by

William Breathitt Gray and committed by
Bartosz Golaszewski
1c05004f 0b424340

+30 -123
+1
drivers/gpio/Kconfig
··· 898 898 tristate "Diamond Systems GPIO-MM GPIO support" 899 899 depends on PC104 900 900 select ISA_BUS_API 901 + select REGMAP_MMIO 901 902 select GPIO_I8255 902 903 help 903 904 Enables GPIO support for the Diamond Systems GPIO-MM and GPIO-MM-12.
+29 -123
drivers/gpio/gpio-gpio-mm.c
··· 8 8 */ 9 9 #include <linux/device.h> 10 10 #include <linux/errno.h> 11 - #include <linux/gpio/driver.h> 12 - #include <linux/io.h> 13 11 #include <linux/ioport.h> 14 12 #include <linux/isa.h> 15 13 #include <linux/kernel.h> 16 14 #include <linux/module.h> 17 15 #include <linux/moduleparam.h> 16 + #include <linux/regmap.h> 17 + #include <linux/types.h> 18 18 19 19 #include "gpio-i8255.h" 20 20 ··· 30 30 31 31 #define GPIOMM_NUM_PPI 2 32 32 33 - /** 34 - * struct gpiomm_gpio - GPIO device private data structure 35 - * @chip: instance of the gpio_chip 36 - * @ppi_state: Programmable Peripheral Interface group states 37 - * @ppi: Programmable Peripheral Interface groups 38 - */ 39 - struct gpiomm_gpio { 40 - struct gpio_chip chip; 41 - struct i8255_state ppi_state[GPIOMM_NUM_PPI]; 42 - struct i8255 __iomem *ppi; 33 + static const struct regmap_range gpiomm_volatile_ranges[] = { 34 + i8255_volatile_regmap_range(0x0), i8255_volatile_regmap_range(0x4), 43 35 }; 44 - 45 - static int gpiomm_gpio_get_direction(struct gpio_chip *chip, 46 - unsigned int offset) 47 - { 48 - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); 49 - 50 - if (i8255_get_direction(gpiommgpio->ppi_state, offset)) 51 - return GPIO_LINE_DIRECTION_IN; 52 - 53 - return GPIO_LINE_DIRECTION_OUT; 54 - } 55 - 56 - static int gpiomm_gpio_direction_input(struct gpio_chip *chip, 57 - unsigned int offset) 58 - { 59 - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); 60 - 61 - i8255_direction_input(gpiommgpio->ppi, gpiommgpio->ppi_state, offset); 62 - 63 - return 0; 64 - } 65 - 66 - static int gpiomm_gpio_direction_output(struct gpio_chip *chip, 67 - unsigned int offset, int value) 68 - { 69 - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); 70 - 71 - i8255_direction_output(gpiommgpio->ppi, gpiommgpio->ppi_state, offset, 72 - value); 73 - 74 - return 0; 75 - } 76 - 77 - static int gpiomm_gpio_get(struct gpio_chip *chip, unsigned int offset) 78 - { 79 - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); 80 - 81 - return i8255_get(gpiommgpio->ppi, offset); 82 - } 83 - 84 - static int gpiomm_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, 85 - unsigned long *bits) 86 - { 87 - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); 88 - 89 - i8255_get_multiple(gpiommgpio->ppi, mask, bits, chip->ngpio); 90 - 91 - return 0; 92 - } 93 - 94 - static void gpiomm_gpio_set(struct gpio_chip *chip, unsigned int offset, 95 - int value) 96 - { 97 - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); 98 - 99 - i8255_set(gpiommgpio->ppi, gpiommgpio->ppi_state, offset, value); 100 - } 101 - 102 - static void gpiomm_gpio_set_multiple(struct gpio_chip *chip, 103 - unsigned long *mask, unsigned long *bits) 104 - { 105 - struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip); 106 - 107 - i8255_set_multiple(gpiommgpio->ppi, gpiommgpio->ppi_state, mask, bits, 108 - chip->ngpio); 109 - } 36 + static const struct regmap_access_table gpiomm_volatile_table = { 37 + .yes_ranges = gpiomm_volatile_ranges, 38 + .n_yes_ranges = ARRAY_SIZE(gpiomm_volatile_ranges), 39 + }; 40 + static const struct regmap_config gpiomm_regmap_config = { 41 + .reg_bits = 8, 42 + .reg_stride = 1, 43 + .val_bits = 8, 44 + .io_port = true, 45 + .max_register = 0x7, 46 + .volatile_table = &gpiomm_volatile_table, 47 + .cache_type = REGCACHE_FLAT, 48 + }; 110 49 111 50 #define GPIOMM_NGPIO 48 112 51 static const char *gpiomm_names[GPIOMM_NGPIO] = { ··· 59 120 "Port 2C2", "Port 2C3", "Port 2C4", "Port 2C5", "Port 2C6", "Port 2C7", 60 121 }; 61 122 62 - static void gpiomm_init_dio(struct i8255 __iomem *const ppi, 63 - struct i8255_state *const ppi_state) 64 - { 65 - const unsigned long ngpio = 24; 66 - const unsigned long mask = GENMASK(ngpio - 1, 0); 67 - const unsigned long bits = 0; 68 - unsigned long i; 69 - 70 - /* Initialize all GPIO to output 0 */ 71 - for (i = 0; i < GPIOMM_NUM_PPI; i++) { 72 - i8255_mode0_output(&ppi[i]); 73 - i8255_set_multiple(&ppi[i], &ppi_state[i], &mask, &bits, ngpio); 74 - } 75 - } 76 - 77 123 static int gpiomm_probe(struct device *dev, unsigned int id) 78 124 { 79 - struct gpiomm_gpio *gpiommgpio; 80 125 const char *const name = dev_name(dev); 81 - int err; 82 - 83 - gpiommgpio = devm_kzalloc(dev, sizeof(*gpiommgpio), GFP_KERNEL); 84 - if (!gpiommgpio) 85 - return -ENOMEM; 126 + struct i8255_regmap_config config = {}; 127 + void __iomem *regs; 86 128 87 129 if (!devm_request_region(dev, base[id], GPIOMM_EXTENT, name)) { 88 130 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", ··· 71 151 return -EBUSY; 72 152 } 73 153 74 - gpiommgpio->ppi = devm_ioport_map(dev, base[id], GPIOMM_EXTENT); 75 - if (!gpiommgpio->ppi) 154 + regs = devm_ioport_map(dev, base[id], GPIOMM_EXTENT); 155 + if (!regs) 76 156 return -ENOMEM; 77 157 78 - gpiommgpio->chip.label = name; 79 - gpiommgpio->chip.parent = dev; 80 - gpiommgpio->chip.owner = THIS_MODULE; 81 - gpiommgpio->chip.base = -1; 82 - gpiommgpio->chip.ngpio = GPIOMM_NGPIO; 83 - gpiommgpio->chip.names = gpiomm_names; 84 - gpiommgpio->chip.get_direction = gpiomm_gpio_get_direction; 85 - gpiommgpio->chip.direction_input = gpiomm_gpio_direction_input; 86 - gpiommgpio->chip.direction_output = gpiomm_gpio_direction_output; 87 - gpiommgpio->chip.get = gpiomm_gpio_get; 88 - gpiommgpio->chip.get_multiple = gpiomm_gpio_get_multiple; 89 - gpiommgpio->chip.set = gpiomm_gpio_set; 90 - gpiommgpio->chip.set_multiple = gpiomm_gpio_set_multiple; 158 + config.map = devm_regmap_init_mmio(dev, regs, &gpiomm_regmap_config); 159 + if (IS_ERR(config.map)) 160 + return dev_err_probe(dev, PTR_ERR(config.map), 161 + "Unable to initialize register map\n"); 91 162 92 - i8255_state_init(gpiommgpio->ppi_state, GPIOMM_NUM_PPI); 93 - gpiomm_init_dio(gpiommgpio->ppi, gpiommgpio->ppi_state); 163 + config.parent = dev; 164 + config.num_ppi = GPIOMM_NUM_PPI; 165 + config.names = gpiomm_names; 94 166 95 - err = devm_gpiochip_add_data(dev, &gpiommgpio->chip, gpiommgpio); 96 - if (err) { 97 - dev_err(dev, "GPIO registering failed (%d)\n", err); 98 - return err; 99 - } 100 - 101 - return 0; 167 + return devm_i8255_regmap_register(dev, &config); 102 168 } 103 169 104 170 static struct isa_driver gpiomm_driver = {