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

gpio: i8255: Remove unused legacy interface

All i8255 library consumers have migrated to the new interface
leveraging the gpio-regmap API. Legacy interface functions and code are
removed as no longer needed.

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
6ecb741e 1c05004f

+1 -282
+1 -242
drivers/gpio/gpio-i8255.c
··· 3 3 * Intel 8255 Programmable Peripheral Interface 4 4 * Copyright (C) 2022 William Breathitt Gray 5 5 */ 6 - #include <linux/bitmap.h> 6 + #include <linux/bits.h> 7 7 #include <linux/device.h> 8 8 #include <linux/err.h> 9 9 #include <linux/export.h> 10 10 #include <linux/gpio/regmap.h> 11 - #include <linux/io.h> 12 11 #include <linux/module.h> 13 12 #include <linux/regmap.h> 14 - #include <linux/spinlock.h> 15 - #include <linux/types.h> 16 13 17 14 #include "gpio-i8255.h" 18 15 ··· 26 29 #define I8255_CONTROL 0x3 27 30 #define I8255_REG_DAT_BASE I8255_PORTA 28 31 #define I8255_REG_DIR_IN_BASE I8255_CONTROL 29 - 30 - static int i8255_get_port(struct i8255 __iomem *const ppi, 31 - const unsigned long io_port, const unsigned long mask) 32 - { 33 - const unsigned long bank = io_port / 3; 34 - const unsigned long ppi_port = io_port % 3; 35 - 36 - return ioread8(&ppi[bank].port[ppi_port]) & mask; 37 - } 38 32 39 33 static int i8255_direction_mask(const unsigned int offset) 40 34 { ··· 90 102 return -EINVAL; 91 103 } 92 104 } 93 - 94 - static void i8255_set_port(struct i8255 __iomem *const ppi, 95 - struct i8255_state *const state, 96 - const unsigned long io_port, 97 - const unsigned long mask, const unsigned long bits) 98 - { 99 - const unsigned long bank = io_port / 3; 100 - const unsigned long ppi_port = io_port % 3; 101 - unsigned long flags; 102 - unsigned long out_state; 103 - 104 - spin_lock_irqsave(&state[bank].lock, flags); 105 - 106 - out_state = ioread8(&ppi[bank].port[ppi_port]); 107 - out_state = (out_state & ~mask) | (bits & mask); 108 - iowrite8(out_state, &ppi[bank].port[ppi_port]); 109 - 110 - spin_unlock_irqrestore(&state[bank].lock, flags); 111 - } 112 - 113 - /** 114 - * i8255_direction_input - configure signal offset as input 115 - * @ppi: Intel 8255 Programmable Peripheral Interface banks 116 - * @state: devices states of the respective PPI banks 117 - * @offset: signal offset to configure as input 118 - * 119 - * Configures a signal @offset as input for the respective Intel 8255 120 - * Programmable Peripheral Interface (@ppi) banks. The @state control_state 121 - * values are updated to reflect the new configuration. 122 - */ 123 - void i8255_direction_input(struct i8255 __iomem *const ppi, 124 - struct i8255_state *const state, 125 - const unsigned long offset) 126 - { 127 - const unsigned long io_port = offset / 8; 128 - const unsigned long bank = io_port / 3; 129 - unsigned long flags; 130 - 131 - spin_lock_irqsave(&state[bank].lock, flags); 132 - 133 - state[bank].control_state |= I8255_CONTROL_MODE_SET; 134 - state[bank].control_state |= i8255_direction_mask(offset % 24); 135 - 136 - iowrite8(state[bank].control_state, &ppi[bank].control); 137 - 138 - spin_unlock_irqrestore(&state[bank].lock, flags); 139 - } 140 - EXPORT_SYMBOL_NS_GPL(i8255_direction_input, I8255); 141 - 142 - /** 143 - * i8255_direction_output - configure signal offset as output 144 - * @ppi: Intel 8255 Programmable Peripheral Interface banks 145 - * @state: devices states of the respective PPI banks 146 - * @offset: signal offset to configure as output 147 - * @value: signal value to output 148 - * 149 - * Configures a signal @offset as output for the respective Intel 8255 150 - * Programmable Peripheral Interface (@ppi) banks and sets the respective signal 151 - * output to the desired @value. The @state control_state values are updated to 152 - * reflect the new configuration. 153 - */ 154 - void i8255_direction_output(struct i8255 __iomem *const ppi, 155 - struct i8255_state *const state, 156 - const unsigned long offset, 157 - const unsigned long value) 158 - { 159 - const unsigned long io_port = offset / 8; 160 - const unsigned long bank = io_port / 3; 161 - unsigned long flags; 162 - 163 - spin_lock_irqsave(&state[bank].lock, flags); 164 - 165 - state[bank].control_state |= I8255_CONTROL_MODE_SET; 166 - state[bank].control_state &= ~i8255_direction_mask(offset % 24); 167 - 168 - iowrite8(state[bank].control_state, &ppi[bank].control); 169 - 170 - spin_unlock_irqrestore(&state[bank].lock, flags); 171 - 172 - i8255_set(ppi, state, offset, value); 173 - } 174 - EXPORT_SYMBOL_NS_GPL(i8255_direction_output, I8255); 175 - 176 - /** 177 - * i8255_get - get signal value at signal offset 178 - * @ppi: Intel 8255 Programmable Peripheral Interface banks 179 - * @offset: offset of signal to get 180 - * 181 - * Returns the signal value (0=low, 1=high) for the signal at @offset for the 182 - * respective Intel 8255 Programmable Peripheral Interface (@ppi) banks. 183 - */ 184 - int i8255_get(struct i8255 __iomem *const ppi, const unsigned long offset) 185 - { 186 - const unsigned long io_port = offset / 8; 187 - const unsigned long offset_mask = BIT(offset % 8); 188 - 189 - return !!i8255_get_port(ppi, io_port, offset_mask); 190 - } 191 - EXPORT_SYMBOL_NS_GPL(i8255_get, I8255); 192 - 193 - /** 194 - * i8255_get_direction - get the I/O direction for a signal offset 195 - * @state: devices states of the respective PPI banks 196 - * @offset: offset of signal to get direction 197 - * 198 - * Returns the signal direction (0=output, 1=input) for the signal at @offset. 199 - */ 200 - int i8255_get_direction(const struct i8255_state *const state, 201 - const unsigned long offset) 202 - { 203 - const unsigned long io_port = offset / 8; 204 - const unsigned long bank = io_port / 3; 205 - 206 - return !!(state[bank].control_state & i8255_direction_mask(offset % 24)); 207 - } 208 - EXPORT_SYMBOL_NS_GPL(i8255_get_direction, I8255); 209 - 210 - /** 211 - * i8255_get_multiple - get multiple signal values at multiple signal offsets 212 - * @ppi: Intel 8255 Programmable Peripheral Interface banks 213 - * @mask: mask of signals to get 214 - * @bits: bitmap to store signal values 215 - * @ngpio: number of GPIO signals of the respective PPI banks 216 - * 217 - * Stores in @bits the values (0=low, 1=high) for the signals defined by @mask 218 - * for the respective Intel 8255 Programmable Peripheral Interface (@ppi) banks. 219 - */ 220 - void i8255_get_multiple(struct i8255 __iomem *const ppi, 221 - const unsigned long *const mask, 222 - unsigned long *const bits, const unsigned long ngpio) 223 - { 224 - unsigned long offset; 225 - unsigned long port_mask; 226 - unsigned long io_port; 227 - unsigned long port_state; 228 - 229 - bitmap_zero(bits, ngpio); 230 - 231 - for_each_set_clump8(offset, port_mask, mask, ngpio) { 232 - io_port = offset / 8; 233 - port_state = i8255_get_port(ppi, io_port, port_mask); 234 - 235 - bitmap_set_value8(bits, port_state, offset); 236 - } 237 - } 238 - EXPORT_SYMBOL_NS_GPL(i8255_get_multiple, I8255); 239 - 240 - /** 241 - * i8255_mode0_output - configure all PPI ports to MODE 0 output mode 242 - * @ppi: Intel 8255 Programmable Peripheral Interface bank 243 - * 244 - * Configures all Intel 8255 Programmable Peripheral Interface (@ppi) ports to 245 - * MODE 0 (Basic Input/Output) output mode. 246 - */ 247 - void i8255_mode0_output(struct i8255 __iomem *const ppi) 248 - { 249 - iowrite8(I8255_CONTROL_MODE_SET, &ppi->control); 250 - } 251 - EXPORT_SYMBOL_NS_GPL(i8255_mode0_output, I8255); 252 - 253 - /** 254 - * i8255_set - set signal value at signal offset 255 - * @ppi: Intel 8255 Programmable Peripheral Interface banks 256 - * @state: devices states of the respective PPI banks 257 - * @offset: offset of signal to set 258 - * @value: value of signal to set 259 - * 260 - * Assigns output @value for the signal at @offset for the respective Intel 8255 261 - * Programmable Peripheral Interface (@ppi) banks. 262 - */ 263 - void i8255_set(struct i8255 __iomem *const ppi, struct i8255_state *const state, 264 - const unsigned long offset, const unsigned long value) 265 - { 266 - const unsigned long io_port = offset / 8; 267 - const unsigned long port_offset = offset % 8; 268 - const unsigned long mask = BIT(port_offset); 269 - const unsigned long bits = value << port_offset; 270 - 271 - i8255_set_port(ppi, state, io_port, mask, bits); 272 - } 273 - EXPORT_SYMBOL_NS_GPL(i8255_set, I8255); 274 - 275 - /** 276 - * i8255_set_multiple - set signal values at multiple signal offsets 277 - * @ppi: Intel 8255 Programmable Peripheral Interface banks 278 - * @state: devices states of the respective PPI banks 279 - * @mask: mask of signals to set 280 - * @bits: bitmap of signal output values 281 - * @ngpio: number of GPIO signals of the respective PPI banks 282 - * 283 - * Assigns output values defined by @bits for the signals defined by @mask for 284 - * the respective Intel 8255 Programmable Peripheral Interface (@ppi) banks. 285 - */ 286 - void i8255_set_multiple(struct i8255 __iomem *const ppi, 287 - struct i8255_state *const state, 288 - const unsigned long *const mask, 289 - const unsigned long *const bits, 290 - const unsigned long ngpio) 291 - { 292 - unsigned long offset; 293 - unsigned long port_mask; 294 - unsigned long io_port; 295 - unsigned long value; 296 - 297 - for_each_set_clump8(offset, port_mask, mask, ngpio) { 298 - io_port = offset / 8; 299 - value = bitmap_get_value8(bits, offset); 300 - i8255_set_port(ppi, state, io_port, port_mask, value); 301 - } 302 - } 303 - EXPORT_SYMBOL_NS_GPL(i8255_set_multiple, I8255); 304 - 305 - /** 306 - * i8255_state_init - initialize i8255_state structure 307 - * @state: devices states of the respective PPI banks 308 - * @nbanks: number of Intel 8255 Programmable Peripheral Interface banks 309 - * 310 - * Initializes the @state of each Intel 8255 Programmable Peripheral Interface 311 - * bank for use in i8255 library functions. 312 - */ 313 - void i8255_state_init(struct i8255_state *const state, 314 - const unsigned long nbanks) 315 - { 316 - unsigned long bank; 317 - 318 - for (bank = 0; bank < nbanks; bank++) 319 - spin_lock_init(&state[bank].lock); 320 - } 321 - EXPORT_SYMBOL_NS_GPL(i8255_state_init, I8255); 322 105 323 106 /** 324 107 * devm_i8255_regmap_register - Register an i8255 GPIO controller
-40
drivers/gpio/gpio-i8255.h
··· 3 3 #ifndef _I8255_H_ 4 4 #define _I8255_H_ 5 5 6 - #include <linux/spinlock.h> 7 - #include <linux/types.h> 8 - 9 - /** 10 - * struct i8255 - Intel 8255 register structure 11 - * @port: Port A, B, and C 12 - * @control: Control register 13 - */ 14 - struct i8255 { 15 - u8 port[3]; 16 - u8 control; 17 - }; 18 - 19 - /** 20 - * struct i8255_state - Intel 8255 state structure 21 - * @lock: synchronization lock for accessing device state 22 - * @control_state: Control register state 23 - */ 24 - struct i8255_state { 25 - spinlock_t lock; 26 - u8 control_state; 27 - }; 28 - 29 6 struct device; 30 7 struct irq_domain; 31 8 struct regmap; ··· 30 53 31 54 int devm_i8255_regmap_register(struct device *dev, 32 55 const struct i8255_regmap_config *config); 33 - 34 - void i8255_direction_input(struct i8255 __iomem *ppi, struct i8255_state *state, 35 - unsigned long offset); 36 - void i8255_direction_output(struct i8255 __iomem *ppi, 37 - struct i8255_state *state, unsigned long offset, 38 - unsigned long value); 39 - int i8255_get(struct i8255 __iomem *ppi, unsigned long offset); 40 - int i8255_get_direction(const struct i8255_state *state, unsigned long offset); 41 - void i8255_get_multiple(struct i8255 __iomem *ppi, const unsigned long *mask, 42 - unsigned long *bits, unsigned long ngpio); 43 - void i8255_mode0_output(struct i8255 __iomem *const ppi); 44 - void i8255_set(struct i8255 __iomem *ppi, struct i8255_state *state, 45 - unsigned long offset, unsigned long value); 46 - void i8255_set_multiple(struct i8255 __iomem *ppi, struct i8255_state *state, 47 - const unsigned long *mask, const unsigned long *bits, 48 - unsigned long ngpio); 49 - void i8255_state_init(struct i8255_state *const state, unsigned long nbanks); 50 56 51 57 #endif /* _I8255_H_ */