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

Merge tag 'gpio-updates-for-v6.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux

Pull gpio updates from Bartosz Golaszewski:
"There's one new driver, lots of various updates to existing ones, some
refactoring support for new models and misc tweaks and fixes.

The biggest new feature in GPIO core is adding support for managed,
enable-counted sharing of GPIO pins, something that - until now - was
only hacked around with the GPIOD_FLAGS_BIT_NONEXCLUSIVE request flag
which basically allowed drivers to "fight it out" for the descriptor
and provided no synchronization. It was enabled on Qualcomm platforms
(and thus is enabled on arm64 defconfig) and I plan on removing
GPIOD_FLAGS_BIT_NONEXCLUSIVE once all drivers using it are switched to
the new mechanism.

GPIO core:
- add proper support for shared GPIOs that's aiming to replace the
current sharing mechanism (which provides no synchronization ot
enable counting) and enable it for Qualcomm platforms
- improve the software node GPIO lookup by using the fwnode
representation instead of the software node's name which was prone
to bugs (GPIO controllers don't have to use the software node's
name as their kernel label)
- remove the last user of legacy-of-mm-gpiochip.h and drop the header
- move closer to removing the legacy gpio_request_one() routine
- rename some symbols for consistency
- shrink GPIO printk() helpers by reusing existing code
- remove some redundant kernel messages
- use min() instead of min_t() in GPIO ACPI code
- use system_percpu_wq instead of system_wq in GPIO character device
code

New drivers:
- add a driver for the QIXIS FPGA GPIO controller

Driver improvements:
- use modernized variants of power management macros across a wide
array of drivers in order to avoid having to use the __maybe_unused
attribute
- convert gpio-elkhartlake and reset-gpio to using the auxiliary bus
instead of the platform bus as they are not really described in
firmware
- use lock guards and update symbol prefixes in gpio-mmio
- support the bryx radio interface kit in gpio-mpsse + refactor the
driver
- use software nodes for configuring the reset-gpio driver, including
setting up the reference to the shared "reset" pin
- check and propagate the return value of gpiod_set_value() to
user-space in gpio-virtuser (this was previously not possible as
this function returned void)
- extend the gpio-regmap helper with more features (bypass cache for
aliased inputs, force writes for aliased data registers, add a new
configuration parameter)
- remove unneeded includes from gpio-aspeed and gpio-latch
- add support for Tegra410 to gpio-tegra186
- replace PCI-specific PM with generic device-level PM in gpio-bt8xx
- use dynamic GPIO range allocation in gpio-loongson-64bit
- improve handling of level-triggered interrupts in gpio-pca953x
- add suspend/resume support to gpio-fxl6408
- add support for more models to gpio-menz127
- optimize gpio-mvebu interrupt handling by avoiding unnecessary
calls to mvebu_gpio_irq_handler()
- make locking more consistent in gpio-grgpio

Device-tree bindings:
- document new NXP and Microchip models

Documentation:
- add a comprehensive compatibility and feature list for
gpio-pca953x, which is a great addition as it's probably the most
commonly used GPIO expander driver
- kernel-doc tweaks

Late fixes:
- use BYTE_CTRL_MODE for 2K2000/3000 models in gpio-loongson"

* tag 'gpio-updates-for-v6.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: (80 commits)
gpio: loongson: Switch 2K2000/3000 GPIO to BYTE_CTRL_MODE
gpio: regmap: fix kernel-doc notation
gpio: shared: fix a deadlock
gpio: shared-proxy: set suppress_bind_attrs
gpio: shared: ignore GPIO hogs when traversing the device tree
gpio: shared: ignore special __symbols__ node when traversing device tree
gpio: shared: handle the reset-gpios corner case
gpio: zynq: Use modern PM macros
gpio: xilinx: Use modern PM macros
gpio: xgene: Use modern PM macros
gpio: uniphier: Use modern PM macros
gpio: tqmx86: Use modern PM macros
gpio: pch: Use modern PM macros
gpio: omap: Use modern PM macros
gpio: msc313: Use modern PM macros
gpio: mlxbf2: Use modern PM macros
gpio: ml-ioh: Use modern PM macros
gpio: pl061: Use modern PM macros
gpio: htc-egpio: Use modern PM macros
gpio: brcmstb: Use modern PM macros
...

+1939 -921
+4 -1
Documentation/devicetree/bindings/gpio/microchip,mpfs-gpio.yaml
··· 11 11 12 12 properties: 13 13 compatible: 14 - items: 14 + oneOf: 15 + - items: 16 + - const: microchip,pic64gx-gpio 17 + - const: microchip,mpfs-gpio 15 18 - enum: 16 19 - microchip,mpfs-gpio 17 20 - microchip,coregpio-rtl-v3
+2
Documentation/devicetree/bindings/gpio/trivial-gpio.yaml
··· 22 22 - cznic,moxtet-gpio 23 23 - dlg,slg7xl45106 24 24 - fcs,fxl6408 25 + - fsl,ls1046aqds-fpga-gpio-stat-pres2 26 + - fsl,lx2160ardb-fpga-gpio-sfp 25 27 - gateworks,pld-gpio 26 28 - ibm,ppc4xx-gpio 27 29 - loongson,ls1x-gpio
+1
Documentation/driver-api/gpio/index.rst
··· 15 15 legacy-boards 16 16 drivers-on-gpio 17 17 bt8xxgpio 18 + pca953x 18 19 19 20 Core 20 21 ====
+552
Documentation/driver-api/gpio/pca953x.rst
··· 1 + ============================================ 2 + PCA953x I²C GPIO expander compatibility list 3 + ============================================ 4 + 5 + :Author: Levente Révész <levente.revesz@eilabs.com> 6 + 7 + I went through all the datasheets and created this note listing 8 + chip functions and register layouts. 9 + 10 + Overview of chips 11 + ================= 12 + 13 + Chips with the basic 4 registers 14 + -------------------------------- 15 + 16 + These chips have 4 register banks: input, output, invert and direction. 17 + Each of these banks contains (lines/8) registers, one for each GPIO port. 18 + 19 + Banks offset is always a power of 2: 20 + 21 + - 4 lines -> bank offset is 1 22 + - 8 lines -> bank offset is 1 23 + - 16 lines -> bank offset is 2 24 + - 24 lines -> bank offset is 4 25 + - 32 lines -> bank offset is 4 26 + - 40 lines -> bank offset is 8 27 + 28 + For example, register layout of GPIO expander with 24 lines: 29 + 30 + +------+-----------------+--------+ 31 + | addr | function | bank | 32 + +======+=================+========+ 33 + | 00 | input port0 | | 34 + +------+-----------------+ | 35 + | 01 | input port1 | bank 0 | 36 + +------+-----------------+ | 37 + | 02 | input port2 | | 38 + +------+-----------------+--------+ 39 + | 03 | n/a | | 40 + +------+-----------------+--------+ 41 + | 04 | output port0 | | 42 + +------+-----------------+ | 43 + | 05 | output port1 | bank 1 | 44 + +------+-----------------+ | 45 + | 06 | output port2 | | 46 + +------+-----------------+--------+ 47 + | 07 | n/a | | 48 + +------+-----------------+--------+ 49 + | 08 | invert port0 | | 50 + +------+-----------------+ | 51 + | 09 | invert port1 | bank 2 | 52 + +------+-----------------+ | 53 + | 0A | invert port2 | | 54 + +------+-----------------+--------+ 55 + | 0B | n/a | | 56 + +------+-----------------+--------+ 57 + | 0C | direction port0 | | 58 + +------+-----------------+ | 59 + | 0D | direction port1 | bank 3 | 60 + +------+-----------------+ | 61 + | 0E | direction port2 | | 62 + +------+-----------------+--------+ 63 + | 0F | n/a | | 64 + +------+-----------------+--------+ 65 + 66 + .. note:: 67 + This is followed by all supported chips, except by pcal6534. 68 + 69 + The table below shows the offsets for each of the compatible chips: 70 + 71 + ========== ===== ========= ===== ====== ====== ========= 72 + compatible lines interrupt input output invert direction 73 + ========== ===== ========= ===== ====== ====== ========= 74 + pca9536 4 no 00 01 02 03 75 + pca9537 4 yes 00 01 02 03 76 + pca6408 8 yes 00 01 02 03 77 + tca6408 8 yes 00 01 02 03 78 + pca9534 8 yes 00 01 02 03 79 + pca9538 8 yes 00 01 02 03 80 + pca9554 8 yes 00 01 02 03 81 + tca9554 8 yes 00 01 02 03 82 + pca9556 8 no 00 01 02 03 83 + pca9557 8 no 00 01 02 03 84 + pca6107 8 yes 00 01 02 03 85 + pca6416 16 yes 00 02 04 06 86 + tca6416 16 yes 00 02 04 06 87 + pca9535 16 yes 00 02 04 06 88 + pca9539 16 yes 00 02 04 06 89 + tca9539 16 yes 00 02 04 06 90 + pca9555 16 yes 00 02 04 06 91 + max7318 16 yes 00 02 04 06 92 + tca6424 24 yes 00 04 08 0C 93 + ========== ===== ========= ===== ====== ====== ========= 94 + 95 + Chips with additional timeout_en register 96 + ----------------------------------------- 97 + 98 + These Maxim chips have a bus timeout function which can be enabled in 99 + the timeout_en register. This is present in only two chips. Defaults to 100 + timeout disabled. 101 + 102 + ========== ===== ========= ===== ====== ====== ========= ========== 103 + compatible lines interrupt input output invert direction timeout_en 104 + ========== ===== ========= ===== ====== ====== ========= ========== 105 + max7310 8 no 00 01 02 03 04 106 + max7312 16 yes 00 02 04 06 08 107 + ========== ===== ========= ===== ====== ====== ========= ========== 108 + 109 + Chips with additional int_mask register 110 + --------------------------------------- 111 + 112 + These chips have an interrupt mask register in addition to the 4 basic 113 + registers. The interrupt masks default to all interrupts disabled. To 114 + use interrupts with these chips, the driver has to set the int_mask 115 + register. 116 + 117 + ========== ===== ========= ===== ====== ====== ========= ======== 118 + compatible lines interrupt input output invert direction int_mask 119 + ========== ===== ========= ===== ====== ====== ========= ======== 120 + pca9505 40 yes 00 08 10 18 20 121 + pca9506 40 yes 00 08 10 18 20 122 + ========== ===== ========= ===== ====== ====== ========= ======== 123 + 124 + Chips with additional int_mask and out_conf registers 125 + ----------------------------------------------------- 126 + 127 + This chip has an interrupt mask register, and an output port 128 + configuration register, which can select between push-pull and 129 + open-drain modes. Each bit controls two lines. Both of these registers 130 + are present in PCAL chips as well, albeit the out_conf works 131 + differently. 132 + 133 + ========== ===== ========= ===== ====== ====== ========= ======== ======== 134 + compatible lines interrupt input output invert direction int_mask out_conf 135 + ========== ===== ========= ===== ====== ====== ========= ======== ======== 136 + pca9698 40 yes 00 08 10 18 20 28 137 + ========== ===== ========= ===== ====== ====== ========= ======== ======== 138 + 139 + pca9698 also has a "master output" register for setting all outputs per 140 + port to the same value simultaneously, and a chip specific mode register 141 + for various additional chip settings. 142 + 143 + ========== ============= ==== 144 + compatible master_output mode 145 + ========== ============= ==== 146 + pca9698 29 2A 147 + ========== ============= ==== 148 + 149 + Chips with LED blink and intensity control 150 + ------------------------------------------ 151 + 152 + These Maxim chips have no invert register. 153 + 154 + They have two sets of output registers (output0 and output1). An internal 155 + timer alternates the effective output between the values set in these 156 + registers, if blink mode is enabled in the blink register. The 157 + master_intensity register and the intensity registers together define 158 + the PWM intensity value for each pair of outputs. 159 + 160 + These chips can be used as simple GPIO expanders if the driver handles the 161 + input, output0 and direction registers. 162 + 163 + ========== ===== ========= ===== ======= ========= ======= ================ ===== ========= 164 + compatible lines interrupt input output0 direction output1 master_intensity blink intensity 165 + ========== ===== ========= ===== ======= ========= ======= ================ ===== ========= 166 + max7315 8 yes 00 01 03 09 0E 0F 10 167 + max7313 16 yes 00 02 06 0A 0E 0F 10 168 + ========== ===== ========= ===== ======= ========= ======= ================ ===== ========= 169 + 170 + Basic PCAL chips 171 + ---------------- 172 + 173 + ========== ===== ========= ===== ====== ====== ========= 174 + compatible lines interrupt input output invert direction 175 + ========== ===== ========= ===== ====== ====== ========= 176 + pcal6408 8 yes 00 01 02 03 177 + pcal9554b 8 yes 00 01 02 03 178 + pcal6416 16 yes 00 02 04 06 179 + pcal9535 16 yes 00 02 04 06 180 + pcal9555a 16 yes 00 02 04 06 181 + ========== ===== ========= ===== ====== ====== ========= 182 + 183 + These chips have several additional features: 184 + 185 + 1. output drive strength setting (out_strength) 186 + 2. input latch (in_latch) 187 + 3. pull-up/pull-down (pull_in, pull_sel) 188 + 4. push-pull/open-drain outputs (out_conf) 189 + 5. interrupt mask and interrupt status (int_mask, int_status) 190 + 191 + ========== ============ ======== ======= ======== ======== ========== ======== 192 + compatible out_strength in_latch pull_en pull_sel int_mask int_status out_conf 193 + ========== ============ ======== ======= ======== ======== ========== ======== 194 + pcal6408 40 42 43 44 45 46 4F 195 + pcal9554b 40 42 43 44 45 46 4F 196 + pcal6416 40 44 46 48 4A 4C 4F 197 + pcal9535 40 44 46 48 4A 4C 4F 198 + pcal9555a 40 44 46 48 4A 4C 4F 199 + ========== ============ ======== ======= ======== ======== ========== ======== 200 + 201 + Currently the driver has support for the input latch, pull-up/pull-down 202 + and uses int_mask and int_status for interrupts. 203 + 204 + PCAL chips with extended interrupt and output configuration functions 205 + --------------------------------------------------------------------- 206 + 207 + ========== ===== ========= ===== ====== ====== ========= 208 + compatible lines interrupt input output invert direction 209 + ========== ===== ========= ===== ====== ====== ========= 210 + pcal6524 24 yes 00 04 08 0C 211 + pcal6534 34 yes 00 05 0A 0F 212 + ========== ===== ========= ===== ====== ====== ========= 213 + 214 + These chips have the full PCAL register set, plus the following functions: 215 + 216 + 1. interrupt event selection: level, rising, falling, any edge 217 + 2. clear interrupt status per line 218 + 3. read input without clearing interrupt status 219 + 4. individual output config (push-pull/open-drain) per output line 220 + 5. debounce inputs 221 + 222 + ========== ============ ======== ======= ======== ======== ========== ======== 223 + compatible out_strength in_latch pull_en pull_sel int_mask int_status out_conf 224 + ========== ============ ======== ======= ======== ======== ========== ======== 225 + pcal6524 40 48 4C 50 54 58 5C 226 + pcal6534 30 3A 3F 44 49 4E 53 227 + ========== ============ ======== ======= ======== ======== ========== ======== 228 + 229 + ========== ======== ========= ============ ============== ======== ============== 230 + compatible int_edge int_clear input_status indiv_out_conf debounce debounce_count 231 + ========== ======== ========= ============ ============== ======== ============== 232 + pcal6524 60 68 6C 70 74 76 233 + pcal6534 54 5E 63 68 6D 6F 234 + ========== ======== ========= ============ ============== ======== ============== 235 + 236 + As can be seen in the table above, pcal6534 does not follow the usual 237 + bank spacing rule. Its banks are closely packed instead. 238 + 239 + PCA957X chips with a completely different register layout 240 + --------------------------------------------------------- 241 + 242 + These chips have the basic 4 registers, but at unusual addresses. 243 + 244 + Additionally, they have: 245 + 246 + 1. pull-up/pull-down (pull_sel) 247 + 2. a global pull enable, defaults to disabled (config) 248 + 3. interrupt mask, interrupt status (int_mask, int_status) 249 + 250 + ========== ===== ========= ===== ====== ====== ======== ========= ====== ======== ========== 251 + compatible lines interrupt input invert config pull_sel direction output int_mask int_status 252 + ========== ===== ========= ===== ====== ====== ======== ========= ====== ======== ========== 253 + pca9574 8 yes 00 01 02 03 04 05 06 07 254 + pca9575 16 yes 00 02 04 06 08 0A 0C 0E 255 + ========== ===== ========= ===== ====== ====== ======== ========= ====== ======== ========== 256 + 257 + Currently the driver supports none of the advanced features. 258 + 259 + XRA1202 260 + ------- 261 + 262 + Basic 4 registers, plus advanced features: 263 + 264 + 1. interrupt mask, defaults to interrupts disabled 265 + 2. interrupt status 266 + 3. interrupt event selection, level, rising, falling, any edge 267 + (int_mask, rising_mask, falling_mask) 268 + 4. pull-up (no pull-down) 269 + 5. tri-state 270 + 6. debounce 271 + 272 + ========== ===== ========= ===== ====== ====== ========= ========= 273 + compatible lines interrupt input output invert direction pullup_en 274 + ========== ===== ========= ===== ====== ====== ========= ========= 275 + xra1202 8 yes 00 01 02 03 04 276 + ========== ===== ========= ===== ====== ====== ========= ========= 277 + 278 + ========== ======== ======== ========== =========== ============ ======== 279 + compatible int_mask tristate int_status rising_mask falling_mask debounce 280 + ========== ======== ======== ========== =========== ============ ======== 281 + xra1202 05 06 07 08 09 0A 282 + ========== ======== ======== ========== =========== ============ ======== 283 + 284 + Overview of functions 285 + ===================== 286 + 287 + This section lists chip functions that are supported by the driver 288 + already, or are at least common in multiple chips. 289 + 290 + Input, Output, Invert, Direction 291 + -------------------------------- 292 + 293 + The basic 4 GPIO functions are present in all but one chip category, i.e. 294 + `Chips with LED blink and intensity control`_ are missing the invert 295 + register. 296 + 297 + 3 different layouts are used for these registers: 298 + 299 + 1. banks 0, 1, 2, 3 with bank offsets of 2^n 300 + - all other chips 301 + 302 + 2. banks 0, 1, 2, 3 with closely packed banks 303 + - pcal6534 304 + 305 + 3. banks 0, 5, 1, 4 with bank offsets of 2^n 306 + - pca9574 307 + - pca9575 308 + 309 + Interrupts 310 + ---------- 311 + 312 + Only an interrupt mask register 313 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 314 + The same layout is used for all of these: 315 + 316 + 1. bank 5 with bank offsets of 2^n 317 + - pca9505 318 + - pca9506 319 + - pca9698 320 + 321 + Interrupt mask and interrupt status registers 322 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 323 + These work the same way in all of the chips: mask and status have 324 + one bit per line, 1 in the mask means interrupt enabled. 325 + 326 + Layouts: 327 + 328 + 1. base offset 0x40, bank 5 and bank 6, bank offsets of 2^n 329 + - pcal6408 330 + - pcal6416 331 + - pcal9535 332 + - pcal9554b 333 + - pcal9555a 334 + - pcal6524 335 + 336 + 2. base offset 0x30, bank 5 and 6, closely packed banks 337 + - pcal6534 338 + 339 + 3. bank 6 and 7, bank offsets of 2^n 340 + - pca9574 341 + - pca9575 342 + 343 + 4. bank 5 and 7, bank offsets of 2^n 344 + - xra1202 345 + 346 + Interrupt on specific edges 347 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 348 + `PCAL chips with extended interrupt and output configuration functions`_ 349 + have an int_edge register. This contains 2 bits per line, one of 4 events 350 + can be selected for each line: 351 + 352 + 0: level, 1: rising edge, 2: falling edge, 3: any edge 353 + 354 + Layouts: 355 + 356 + 1. base offset 0x40, bank 7, bank offsets of 2^n 357 + 358 + - pcal6524 359 + 360 + 2. base offset 0x30, bank 7 + offset 0x01, closely packed banks 361 + (out_conf is 1 byte, not (lines/8) bytes, hence the 0x01 offset) 362 + 363 + - pcal6534 364 + 365 + `XRA1202`_ chips have a different mechanism for the same thing: they have 366 + a rising mask and a falling mask, with one bit per line. 367 + 368 + Layout: 369 + 370 + 1. bank 5, bank offsets of 2^n 371 + 372 + Input latch 373 + ----------- 374 + 375 + Only `Basic PCAL chips`_ and 376 + `PCAL chips with extended interrupt and output configuration functions`_ 377 + have this function. When the latch is enabled, the interrupt is not cleared 378 + until the input port is read. When the latch is disabled, the interrupt 379 + is cleared even if the input register is not read, if the input pin returns 380 + to the logic value it had before generating the interrupt. Defaults to latch 381 + disabled. 382 + 383 + Currently the driver enables the latch for each line with interrupt 384 + enabled. 385 + 386 + 1. base offset 0x40, bank 2, bank offsets of 2^n 387 + - pcal6408 388 + - pcal6416 389 + - pcal9535 390 + - pcal9554b 391 + - pcal9555a 392 + - pcal6524 393 + 394 + 2. base offset 0x30, bank 2, closely packed banks 395 + - pcal6534 396 + 397 + Pull-up and pull-down 398 + --------------------- 399 + 400 + `Basic PCAL chips`_ and 401 + `PCAL chips with extended interrupt and output configuration functions`_ 402 + use the same mechanism: their pull_en register enables the pull-up or pull-down 403 + function, and their pull_sel register chooses the direction. They all use one 404 + bit per line. 405 + 406 + 0: pull-down, 1: pull-up 407 + 408 + Layouts: 409 + 410 + 1. base offset 0x40, bank 3 (en) and 4 (sel), bank offsets of 2^n 411 + - pcal6408 412 + - pcal6416 413 + - pcal9535 414 + - pcal9554b 415 + - pcal9555a 416 + - pcal6524 417 + 418 + 2. base offset 0x30, bank 3 (en) and 4 (sel), closely packed banks 419 + - pcal6534 420 + 421 + `PCA957X chips with a completely different register layout`_ have a pull_sel 422 + register with one bit per line, and a global pull_en bit in their config 423 + register. 424 + 425 + Layout: 426 + 427 + 1. bank 2 (config), bank 3 (sel), bank offsets of 2^n 428 + - pca9574 429 + - pca9575 430 + 431 + `XRA1202`_ chips can only pull-up. They have a pullup_en register. 432 + 433 + Layout: 434 + 435 + 1. bank 4, bank offsets of 2^n 436 + - xra1202 437 + 438 + Push-pull and open-drain 439 + ------------------------ 440 + 441 + `Chips with additional int_mask and out_conf registers`_ have this function, 442 + but only for select IO ports. Register has 1 bit per 2 lines. In pca9698, 443 + only port0 and port1 have this function. 444 + 445 + 0: open-drain, 1: push-pull 446 + 447 + Layout: 448 + 449 + 1. base offset 5*bankoffset 450 + - pca9698 451 + 452 + `Basic PCAL chips`_ have 1 bit per port in one single out_conf register. 453 + Only whole ports can be configured. 454 + 455 + 0: push-pull, 1: open-drain 456 + 457 + Layout: 458 + 459 + 1. base offset 0x4F 460 + - pcal6408 461 + - pcal6416 462 + - pcal9535 463 + - pcal9554b 464 + - pcal9555a 465 + 466 + `PCAL chips with extended interrupt and output configuration functions`_ 467 + can set this for each line individually. They have the same per-port out_conf 468 + register as `Basic PCAL chips`_, but they also have an indiv_out_conf register 469 + with one bit per line, which inverts the effect of the port-wise setting. 470 + 471 + 0: push-pull, 1: open-drain 472 + 473 + Layouts: 474 + 475 + 1. base offset 0x40 + 7*bankoffset (out_conf), 476 + base offset 0x60, bank 4 (indiv_out_conf) with bank offset of 2^n 477 + 478 + - pcal6524 479 + 480 + 2. base offset 0x30 + 7*banksize (out_conf), 481 + base offset 0x54, bank 4 (indiv_out_conf), closely packed banks 482 + 483 + - pcal6534 484 + 485 + This function is currently not supported by the driver. 486 + 487 + Output drive strength 488 + --------------------- 489 + 490 + Only PCAL chips have this function. 2 bits per line. 491 + 492 + ==== ============== 493 + bits drive strength 494 + ==== ============== 495 + 00 0.25x 496 + 01 0.50x 497 + 10 0.75x 498 + 11 1.00x 499 + ==== ============== 500 + 501 + 1. base offset 0x40, bank 0 and 1, bank offsets of 2^n 502 + - pcal6408 503 + - pcal6416 504 + - pcal9535 505 + - pcal9554b 506 + - pcal9555a 507 + - pcal6524 508 + 509 + 2. base offset 0x30, bank 0 and 1, closely packed banks 510 + - pcal6534 511 + 512 + Currently not supported by the driver. 513 + 514 + Datasheets 515 + ========== 516 + 517 + - MAX7310: https://datasheets.maximintegrated.com/en/ds/MAX7310.pdf 518 + - MAX7312: https://datasheets.maximintegrated.com/en/ds/MAX7312.pdf 519 + - MAX7313: https://datasheets.maximintegrated.com/en/ds/MAX7313.pdf 520 + - MAX7315: https://datasheets.maximintegrated.com/en/ds/MAX7315.pdf 521 + - MAX7318: https://datasheets.maximintegrated.com/en/ds/MAX7318.pdf 522 + - PCA6107: https://pdf1.alldatasheet.com/datasheet-pdf/view/161780/TI/PCA6107.html 523 + - PCA6408A: https://www.nxp.com/docs/en/data-sheet/PCA6408A.pdf 524 + - PCA6416A: https://www.nxp.com/docs/en/data-sheet/PCA6416A.pdf 525 + - PCA9505: https://www.nxp.com/docs/en/data-sheet/PCA9505_9506.pdf 526 + - PCA9505: https://www.nxp.com/docs/en/data-sheet/PCA9505_9506.pdf 527 + - PCA9534: https://www.nxp.com/docs/en/data-sheet/PCA9534.pdf 528 + - PCA9535: https://www.nxp.com/docs/en/data-sheet/PCA9535_PCA9535C.pdf 529 + - PCA9536: https://www.nxp.com/docs/en/data-sheet/PCA9536.pdf 530 + - PCA9537: https://www.nxp.com/docs/en/data-sheet/PCA9537.pdf 531 + - PCA9538: https://www.nxp.com/docs/en/data-sheet/PCA9538.pdf 532 + - PCA9539: https://www.nxp.com/docs/en/data-sheet/PCA9539_PCA9539R.pdf 533 + - PCA9554: https://www.nxp.com/docs/en/data-sheet/PCA9554_9554A.pdf 534 + - PCA9555: https://www.nxp.com/docs/en/data-sheet/PCA9555.pdf 535 + - PCA9556: https://www.nxp.com/docs/en/data-sheet/PCA9556.pdf 536 + - PCA9557: https://www.nxp.com/docs/en/data-sheet/PCA9557.pdf 537 + - PCA9574: https://www.nxp.com/docs/en/data-sheet/PCA9574.pdf 538 + - PCA9575: https://www.nxp.com/docs/en/data-sheet/PCA9575.pdf 539 + - PCA9698: https://www.nxp.com/docs/en/data-sheet/PCA9698.pdf 540 + - PCAL6408A: https://www.nxp.com/docs/en/data-sheet/PCAL6408A.pdf 541 + - PCAL6416A: https://www.nxp.com/docs/en/data-sheet/PCAL6416A.pdf 542 + - PCAL6524: https://www.nxp.com/docs/en/data-sheet/PCAL6524.pdf 543 + - PCAL6534: https://www.nxp.com/docs/en/data-sheet/PCAL6534.pdf 544 + - PCAL9535A: https://www.nxp.com/docs/en/data-sheet/PCAL9535A.pdf 545 + - PCAL9554B: https://www.nxp.com/docs/en/data-sheet/PCAL9554B_PCAL9554C.pdf 546 + - PCAL9555A: https://www.nxp.com/docs/en/data-sheet/PCAL9555A.pdf 547 + - TCA6408A: https://www.ti.com/lit/gpn/tca6408a 548 + - TCA6416: https://www.ti.com/lit/gpn/tca6416 549 + - TCA6424: https://www.ti.com/lit/gpn/tca6424 550 + - TCA9539: https://www.ti.com/lit/gpn/tca9539 551 + - TCA9554: https://www.ti.com/lit/gpn/tca9554 552 + - XRA1202: https://assets.maxlinear.com/web/documents/xra1202_1202p_101_042213.pdf
+7
MAINTAINERS
··· 12548 12548 F: include/drm/intel/ 12549 12549 F: include/uapi/drm/xe_drm.h 12550 12550 12551 + INTEL ELKHART LAKE PSE I/O DRIVER 12552 + M: Raag Jadav <raag.jadav@intel.com> 12553 + L: platform-driver-x86@vger.kernel.org 12554 + S: Supported 12555 + F: drivers/platform/x86/intel/ehl_pse_io.c 12556 + F: include/linux/ehl_pse_io_aux.h 12557 + 12551 12558 INTEL ETHERNET DRIVERS 12552 12559 M: Tony Nguyen <anthony.l.nguyen@intel.com> 12553 12560 M: Przemek Kitszel <przemyslaw.kitszel@intel.com>
+1
arch/arm64/Kconfig.platforms
··· 316 316 select GPIOLIB 317 317 select PINCTRL 318 318 select HAVE_PWRCTRL if PCI 319 + select HAVE_SHARED_GPIOS 319 320 help 320 321 This enables support for the ARMv8 based Qualcomm chipsets. 321 322
+24 -6
drivers/base/swnode.c
··· 535 535 ref_array = prop->pointer; 536 536 ref = &ref_array[index]; 537 537 538 - refnode = software_node_fwnode(ref->node); 538 + /* 539 + * A software node can reference other software nodes or firmware 540 + * nodes (which are the abstraction layer sitting on top of them). 541 + * This is done to ensure we can create references to static software 542 + * nodes before they're registered with the firmware node framework. 543 + * At the time the reference is being resolved, we expect the swnodes 544 + * in question to already have been registered and to be backed by 545 + * a firmware node. This is why we use the fwnode API below to read the 546 + * relevant properties and bump the reference count. 547 + */ 548 + 549 + if (ref->swnode) 550 + refnode = software_node_fwnode(ref->swnode); 551 + else if (ref->fwnode) 552 + refnode = ref->fwnode; 553 + else 554 + return -EINVAL; 555 + 539 556 if (!refnode) 540 557 return -ENOENT; 541 558 542 559 if (nargs_prop) { 543 - error = property_entry_read_int_array(ref->node->properties, 544 - nargs_prop, sizeof(u32), 545 - &nargs_prop_val, 1); 560 + error = fwnode_property_read_u32(refnode, nargs_prop, &nargs_prop_val); 546 561 if (error) 547 562 return error; 548 563 ··· 570 555 if (!args) 571 556 return 0; 572 557 573 - args->fwnode = software_node_get(refnode); 558 + args->fwnode = fwnode_handle_get(refnode); 574 559 args->nargs = nargs; 575 560 576 561 for (i = 0; i < nargs; i++) ··· 650 635 651 636 ref = prop->pointer; 652 637 653 - return software_node_get(software_node_fwnode(ref[0].node)); 638 + if (!ref->swnode) 639 + return NULL; 640 + 641 + return software_node_get(software_node_fwnode(ref->swnode)); 654 642 } 655 643 656 644 static struct fwnode_handle *
+10 -10
drivers/gpio/Kconfig
··· 45 45 select IRQ_DOMAIN 46 46 bool 47 47 48 - config OF_GPIO_MM_GPIOCHIP 49 - bool 50 - help 51 - This adds support for the legacy 'struct of_mm_gpio_chip' interface 52 - from PowerPC. Existing drivers using this interface need to select 53 - this symbol, but new drivers should use the generic gpio-regmap 54 - infrastructure instead. 55 - 56 48 config GPIO_SHARED 57 49 def_bool y 58 50 depends on HAVE_SHARED_GPIOS || COMPILE_TEST ··· 476 484 config GPIO_MM_LANTIQ 477 485 bool "Lantiq Memory mapped GPIOs" 478 486 depends on LANTIQ && SOC_XWAY 479 - select OF_GPIO_MM_GPIOCHIP 480 487 help 481 488 This enables support for memory mapped GPIOs on the External Bus Unit 482 489 (EBU) found on Lantiq SoCs. The GPIOs are output only as they are ··· 1412 1421 1413 1422 config GPIO_ELKHARTLAKE 1414 1423 tristate "Intel Elkhart Lake PSE GPIO support" 1415 - depends on X86 || COMPILE_TEST 1424 + depends on INTEL_EHL_PSE_IO 1416 1425 select GPIO_TANGIER 1417 1426 help 1418 1427 Select this option to enable GPIO support for Intel Elkhart Lake ··· 1563 1572 select GPIOLIB_IRQCHIP 1564 1573 help 1565 1574 Say yes here to support Spreadtrum PMIC EIC device. 1575 + 1576 + config GPIO_QIXIS_FPGA 1577 + tristate "NXP QIXIS FPGA GPIO support" 1578 + depends on MFD_SIMPLE_MFD_I2C || COMPILE_TEST 1579 + select GPIO_REGMAP 1580 + help 1581 + This enables support for the GPIOs found in the QIXIS FPGA which is 1582 + integrated on some NXP Layerscape boards such as LX2160ARDB and 1583 + LS1046AQDS. 1566 1584 1567 1585 config GPIO_RC5T583 1568 1586 bool "RICOH RC5T583 GPIO"
+1
drivers/gpio/Makefile
··· 147 147 obj-$(CONFIG_GPIO_PMIC_EIC_SPRD) += gpio-pmic-eic-sprd.o 148 148 obj-$(CONFIG_GPIO_POLARFIRE_SOC) += gpio-mpfs.o 149 149 obj-$(CONFIG_GPIO_PXA) += gpio-pxa.o 150 + obj-$(CONFIG_GPIO_QIXIS_FPGA) += gpio-qixis-fpga.o 150 151 obj-$(CONFIG_GPIO_RASPBERRYPI_EXP) += gpio-raspberrypi-exp.o 151 152 obj-$(CONFIG_GPIO_RC5T583) += gpio-rc5t583.o 152 153 obj-$(CONFIG_GPIO_RCAR) += gpio-rcar.o
-11
drivers/gpio/TODO
··· 86 86 87 87 ------------------------------------------------------------------------------- 88 88 89 - Get rid of <linux/gpio/legacy-of-mm-gpiochip.h> 90 - 91 - Work items: 92 - 93 - - Get rid of struct of_mm_gpio_chip altogether: use the generic MMIO 94 - GPIO for all current users (see below). Delete struct of_mm_gpio_chip, 95 - to_of_mm_gpio_chip(), of_mm_gpiochip_add_data(), of_mm_gpiochip_remove(), 96 - CONFIG_OF_GPIO_MM_GPIOCHIP from the kernel. 97 - 98 - ------------------------------------------------------------------------------- 99 - 100 89 Collect drivers 101 90 102 91 Collect GPIO drivers from arch/* and other places that should be placed
+3 -4
drivers/gpio/gpio-aspeed.c
··· 24 24 25 25 /* 26 26 * These two headers aren't meant to be used by GPIO drivers. We need 27 - * them in order to access gpio_chip_hwgpio() which we need to implement 27 + * them in order to access gpiod_hwgpio() which we need to implement 28 28 * the aspeed specific API which allows the coprocessor to request 29 29 * access to some GPIOs and to arbitrate between coprocessor and ARM. 30 30 */ 31 31 #include <linux/gpio/consumer.h> 32 - #include "gpiolib.h" 33 32 34 33 /* Non-constant mask variant of FIELD_GET() and FIELD_PREP() */ 35 34 #define field_get(_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) ··· 941 942 { 942 943 struct gpio_chip *chip = gpiod_to_chip(desc); 943 944 struct aspeed_gpio *gpio = gpiochip_get_data(chip); 944 - int rc = 0, bindex, offset = gpio_chip_hwgpio(desc); 945 + int rc = 0, bindex, offset = gpiod_hwgpio(desc); 945 946 const struct aspeed_gpio_bank *bank = to_bank(offset); 946 947 947 948 if (!aspeed_gpio_support_copro(gpio)) ··· 986 987 { 987 988 struct gpio_chip *chip = gpiod_to_chip(desc); 988 989 struct aspeed_gpio *gpio = gpiochip_get_data(chip); 989 - int rc = 0, bindex, offset = gpio_chip_hwgpio(desc); 990 + int rc = 0, bindex, offset = gpiod_hwgpio(desc); 990 991 991 992 if (!aspeed_gpio_support_copro(gpio)) 992 993 return -EOPNOTSUPP;
+3 -9
drivers/gpio/gpio-brcmstb.c
··· 533 533 brcmstb_gpio_quiesce(&pdev->dev, false); 534 534 } 535 535 536 - #ifdef CONFIG_PM_SLEEP 537 536 static void brcmstb_gpio_bank_restore(struct brcmstb_gpio_priv *priv, 538 537 struct brcmstb_gpio_bank *bank) 539 538 { ··· 571 572 return 0; 572 573 } 573 574 574 - #else 575 - #define brcmstb_gpio_suspend NULL 576 - #define brcmstb_gpio_resume NULL 577 - #endif /* CONFIG_PM_SLEEP */ 578 - 579 575 static const struct dev_pm_ops brcmstb_gpio_pm_ops = { 580 - .suspend_noirq = brcmstb_gpio_suspend, 581 - .resume_noirq = brcmstb_gpio_resume, 576 + .suspend_noirq = pm_sleep_ptr(brcmstb_gpio_suspend), 577 + .resume_noirq = pm_sleep_ptr(brcmstb_gpio_resume), 582 578 }; 583 579 584 580 static int brcmstb_gpio_probe(struct platform_device *pdev) ··· 749 755 .driver = { 750 756 .name = "brcmstb-gpio", 751 757 .of_match_table = brcmstb_gpio_of_match, 752 - .pm = &brcmstb_gpio_pm_ops, 758 + .pm = pm_sleep_ptr(&brcmstb_gpio_pm_ops), 753 759 }, 754 760 .probe = brcmstb_gpio_probe, 755 761 .remove = brcmstb_gpio_remove,
+8 -22
drivers/gpio/gpio-bt8xx.c
··· 52 52 struct pci_dev *pdev; 53 53 struct gpio_chip gpio; 54 54 55 - #ifdef CONFIG_PM 56 55 u32 saved_outen; 57 56 u32 saved_data; 58 - #endif 59 57 }; 60 58 61 59 #define bgwrite(dat, adr) writel((dat), bg->mmio+(adr)) ··· 222 224 pci_disable_device(pdev); 223 225 } 224 226 225 - #ifdef CONFIG_PM 226 - static int bt8xxgpio_suspend(struct pci_dev *pdev, pm_message_t state) 227 + 228 + static int bt8xxgpio_suspend(struct device *dev) 227 229 { 230 + struct pci_dev *pdev = to_pci_dev(dev); 228 231 struct bt8xxgpio *bg = pci_get_drvdata(pdev); 229 232 230 233 scoped_guard(spinlock_irqsave, &bg->lock) { ··· 237 238 bgwrite(0x0, BT848_GPIO_OUT_EN); 238 239 } 239 240 240 - pci_save_state(pdev); 241 - pci_disable_device(pdev); 242 - pci_set_power_state(pdev, pci_choose_state(pdev, state)); 243 - 244 241 return 0; 245 242 } 246 243 247 - static int bt8xxgpio_resume(struct pci_dev *pdev) 244 + static int bt8xxgpio_resume(struct device *dev) 248 245 { 246 + struct pci_dev *pdev = to_pci_dev(dev); 249 247 struct bt8xxgpio *bg = pci_get_drvdata(pdev); 250 - int err; 251 - 252 - pci_set_power_state(pdev, PCI_D0); 253 - err = pci_enable_device(pdev); 254 - if (err) 255 - return err; 256 - pci_restore_state(pdev); 257 248 258 249 guard(spinlock_irqsave)(&bg->lock); 259 250 ··· 256 267 257 268 return 0; 258 269 } 259 - #else 260 - #define bt8xxgpio_suspend NULL 261 - #define bt8xxgpio_resume NULL 262 - #endif /* CONFIG_PM */ 270 + 271 + static DEFINE_SIMPLE_DEV_PM_OPS(bt8xxgpio_pm_ops, bt8xxgpio_suspend, bt8xxgpio_resume); 263 272 264 273 static const struct pci_device_id bt8xxgpio_pci_tbl[] = { 265 274 { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT848) }, ··· 273 286 .id_table = bt8xxgpio_pci_tbl, 274 287 .probe = bt8xxgpio_probe, 275 288 .remove = bt8xxgpio_remove, 276 - .suspend = bt8xxgpio_suspend, 277 - .resume = bt8xxgpio_resume, 289 + .driver.pm = &bt8xxgpio_pm_ops, 278 290 }; 279 291 280 292 module_pci_driver(bt8xxgpio_pci_driver);
+4 -14
drivers/gpio/gpio-dwapb.c
··· 79 79 unsigned int nports; 80 80 }; 81 81 82 - #ifdef CONFIG_PM_SLEEP 83 82 /* Store GPIO context across system-wide suspend/resume transitions */ 84 83 struct dwapb_context { 85 84 u32 data; ··· 91 92 u32 int_deb; 92 93 u32 wake_en; 93 94 }; 94 - #endif 95 95 96 96 struct dwapb_gpio_port_irqchip { 97 97 unsigned int nr_irqs; ··· 101 103 struct gpio_generic_chip chip; 102 104 struct dwapb_gpio_port_irqchip *pirq; 103 105 struct dwapb_gpio *gpio; 104 - #ifdef CONFIG_PM_SLEEP 105 106 struct dwapb_context *ctx; 106 - #endif 107 107 unsigned int idx; 108 108 }; 109 109 ··· 359 363 return 0; 360 364 } 361 365 362 - #ifdef CONFIG_PM_SLEEP 363 366 static int dwapb_irq_set_wake(struct irq_data *d, unsigned int enable) 364 367 { 365 368 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); ··· 373 378 374 379 return 0; 375 380 } 376 - #else 377 - #define dwapb_irq_set_wake NULL 378 - #endif 379 381 380 382 static const struct irq_chip dwapb_irq_chip = { 381 383 .name = DWAPB_DRIVER_NAME, ··· 382 390 .irq_set_type = dwapb_irq_set_type, 383 391 .irq_enable = dwapb_irq_enable, 384 392 .irq_disable = dwapb_irq_disable, 385 - .irq_set_wake = dwapb_irq_set_wake, 393 + .irq_set_wake = pm_sleep_ptr(dwapb_irq_set_wake), 386 394 .flags = IRQCHIP_IMMUTABLE, 387 395 GPIOCHIP_IRQ_RESOURCE_HELPERS, 388 396 }; ··· 751 759 return 0; 752 760 } 753 761 754 - #ifdef CONFIG_PM_SLEEP 755 762 static int dwapb_gpio_suspend(struct device *dev) 756 763 { 757 764 struct dwapb_gpio *gpio = dev_get_drvdata(dev); ··· 835 844 836 845 return 0; 837 846 } 838 - #endif 839 847 840 - static SIMPLE_DEV_PM_OPS(dwapb_gpio_pm_ops, dwapb_gpio_suspend, 841 - dwapb_gpio_resume); 848 + static DEFINE_SIMPLE_DEV_PM_OPS(dwapb_gpio_pm_ops, 849 + dwapb_gpio_suspend, dwapb_gpio_resume); 842 850 843 851 static struct platform_driver dwapb_gpio_driver = { 844 852 .driver = { 845 853 .name = DWAPB_DRIVER_NAME, 846 - .pm = &dwapb_gpio_pm_ops, 854 + .pm = pm_sleep_ptr(&dwapb_gpio_pm_ops), 847 855 .of_match_table = dwapb_of_match, 848 856 .acpi_match_table = dwapb_acpi_match, 849 857 },
+19 -17
drivers/gpio/gpio-elkhartlake.c
··· 2 2 /* 3 3 * Intel Elkhart Lake PSE GPIO driver 4 4 * 5 - * Copyright (c) 2023 Intel Corporation. 5 + * Copyright (c) 2023, 2025 Intel Corporation. 6 6 * 7 7 * Authors: Pandith N <pandith.n@intel.com> 8 8 * Raag Jadav <raag.jadav@intel.com> 9 9 */ 10 10 11 + #include <linux/auxiliary_bus.h> 11 12 #include <linux/device.h> 12 13 #include <linux/err.h> 13 14 #include <linux/module.h> 14 - #include <linux/platform_device.h> 15 15 #include <linux/pm.h> 16 + 17 + #include <linux/ehl_pse_io_aux.h> 16 18 17 19 #include "gpio-tangier.h" 18 20 19 21 /* Each Intel EHL PSE GPIO Controller has 30 GPIO pins */ 20 22 #define EHL_PSE_NGPIO 30 21 23 22 - static int ehl_gpio_probe(struct platform_device *pdev) 24 + static int ehl_gpio_probe(struct auxiliary_device *adev, const struct auxiliary_device_id *id) 23 25 { 24 - struct device *dev = &pdev->dev; 26 + struct device *dev = &adev->dev; 27 + struct ehl_pse_io_data *data; 25 28 struct tng_gpio *priv; 26 - int irq, ret; 29 + int ret; 27 30 28 - irq = platform_get_irq(pdev, 0); 29 - if (irq < 0) 30 - return irq; 31 + data = dev_get_platdata(dev); 32 + if (!data) 33 + return -ENODATA; 31 34 32 35 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 33 36 if (!priv) 34 37 return -ENOMEM; 35 38 36 - priv->reg_base = devm_platform_ioremap_resource(pdev, 0); 39 + priv->reg_base = devm_ioremap_resource(dev, &data->mem); 37 40 if (IS_ERR(priv->reg_base)) 38 41 return PTR_ERR(priv->reg_base); 39 42 40 43 priv->dev = dev; 41 - priv->irq = irq; 44 + priv->irq = data->irq; 42 45 43 46 priv->info.base = -1; 44 47 priv->info.ngpio = EHL_PSE_NGPIO; ··· 54 51 if (ret) 55 52 return dev_err_probe(dev, ret, "tng_gpio_probe error\n"); 56 53 57 - platform_set_drvdata(pdev, priv); 54 + auxiliary_set_drvdata(adev, priv); 58 55 return 0; 59 56 } 60 57 61 - static const struct platform_device_id ehl_gpio_ids[] = { 62 - { "gpio-elkhartlake" }, 58 + static const struct auxiliary_device_id ehl_gpio_ids[] = { 59 + { EHL_PSE_IO_NAME "." EHL_PSE_GPIO_NAME }, 63 60 { } 64 61 }; 65 - MODULE_DEVICE_TABLE(platform, ehl_gpio_ids); 62 + MODULE_DEVICE_TABLE(auxiliary, ehl_gpio_ids); 66 63 67 - static struct platform_driver ehl_gpio_driver = { 64 + static struct auxiliary_driver ehl_gpio_driver = { 68 65 .driver = { 69 - .name = "gpio-elkhartlake", 70 66 .pm = pm_sleep_ptr(&tng_gpio_pm_ops), 71 67 }, 72 68 .probe = ehl_gpio_probe, 73 69 .id_table = ehl_gpio_ids, 74 70 }; 75 - module_platform_driver(ehl_gpio_driver); 71 + module_auxiliary_driver(ehl_gpio_driver); 76 72 77 73 MODULE_AUTHOR("Pandith N <pandith.n@intel.com>"); 78 74 MODULE_AUTHOR("Raag Jadav <raag.jadav@intel.com>");
+13
drivers/gpio/gpio-fxl6408.c
··· 123 123 if (ret) 124 124 return ret; 125 125 126 + i2c_set_clientdata(client, gpio_config.regmap); 127 + 126 128 /* Disable High-Z of outputs, so that our OUTPUT updates actually take effect. */ 127 129 ret = regmap_write(gpio_config.regmap, FXL6408_REG_OUTPUT_HIGH_Z, 0); 128 130 if (ret) ··· 132 130 133 131 return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(dev, &gpio_config)); 134 132 } 133 + 134 + static int fxl6408_resume(struct device *dev) 135 + { 136 + struct regmap *regmap = dev_get_drvdata(dev); 137 + 138 + regcache_mark_dirty(regmap); 139 + return regcache_sync(regmap); 140 + } 141 + 142 + static DEFINE_SIMPLE_DEV_PM_OPS(fxl6408_pm_ops, NULL, fxl6408_resume); 135 143 136 144 static const __maybe_unused struct of_device_id fxl6408_dt_ids[] = { 137 145 { .compatible = "fcs,fxl6408" }, ··· 158 146 static struct i2c_driver fxl6408_driver = { 159 147 .driver = { 160 148 .name = "fxl6408", 149 + .pm = pm_sleep_ptr(&fxl6408_pm_ops), 161 150 .of_match_table = fxl6408_dt_ids, 162 151 }, 163 152 .probe = fxl6408_probe,
+8 -16
drivers/gpio/gpio-grgpio.c
··· 46 46 47 47 /* Structure for an irq of the core - called an underlying irq */ 48 48 struct grgpio_uirq { 49 - u8 refcnt; /* Reference counter to manage requesting/freeing of uirq */ 49 + atomic_t refcnt; /* Reference counter to manage requesting/freeing of uirq */ 50 50 u8 uirq; /* Underlying irq of the gpio driver */ 51 51 }; 52 52 ··· 242 242 irq, offset); 243 243 244 244 gpio_generic_chip_lock_irqsave(&priv->chip, flags); 245 - 246 - /* Request underlying irq if not already requested */ 247 245 lirq->irq = irq; 248 246 uirq = &priv->uirqs[lirq->index]; 249 - if (uirq->refcnt == 0) { 250 - /* 251 - * FIXME: This is not how locking works at all, you can't just 252 - * release the lock for a moment to do something that can't 253 - * sleep... 254 - */ 255 - gpio_generic_chip_unlock_irqrestore(&priv->chip, flags); 247 + gpio_generic_chip_unlock_irqrestore(&priv->chip, flags); 248 + 249 + /* Request underlying irq if not already requested */ 250 + if (atomic_fetch_add(1, &uirq->refcnt) == 0) { 256 251 ret = request_irq(uirq->uirq, grgpio_irq_handler, 0, 257 252 dev_name(priv->dev), priv); 258 253 if (ret) { 259 254 dev_err(priv->dev, 260 255 "Could not request underlying irq %d\n", 261 256 uirq->uirq); 257 + atomic_dec(&uirq->refcnt); /* rollback */ 262 258 return ret; 263 259 } 264 - gpio_generic_chip_lock_irqsave(&priv->chip, flags); 265 260 } 266 - uirq->refcnt++; 267 - 268 - gpio_generic_chip_unlock_irqrestore(&priv->chip, flags); 269 261 270 262 /* Setup irq */ 271 263 irq_set_chip_data(irq, priv); ··· 298 306 299 307 if (index >= 0) { 300 308 uirq = &priv->uirqs[lirq->index]; 301 - uirq->refcnt--; 302 - if (uirq->refcnt == 0) { 309 + if (atomic_dec_and_test(&uirq->refcnt)) { 303 310 gpio_generic_chip_unlock_irqrestore(&priv->chip, flags); 304 311 free_irq(uirq->uirq, priv); 305 312 return; ··· 425 434 continue; 426 435 } 427 436 priv->uirqs[lirq->index].uirq = ret; 437 + atomic_set(&priv->uirqs[lirq->index].refcnt, 0); 428 438 } 429 439 } 430 440
+8 -13
drivers/gpio/gpio-htc-egpio.c
··· 364 364 return 0; 365 365 } 366 366 367 - #ifdef CONFIG_PM 368 - static int egpio_suspend(struct platform_device *pdev, pm_message_t state) 367 + static int egpio_suspend(struct device *dev) 369 368 { 370 - struct egpio_info *ei = platform_get_drvdata(pdev); 369 + struct egpio_info *ei = dev_get_drvdata(dev); 371 370 372 - if (ei->chained_irq && device_may_wakeup(&pdev->dev)) 371 + if (ei->chained_irq && device_may_wakeup(dev)) 373 372 enable_irq_wake(ei->chained_irq); 374 373 return 0; 375 374 } 376 375 377 - static int egpio_resume(struct platform_device *pdev) 376 + static int egpio_resume(struct device *dev) 378 377 { 379 - struct egpio_info *ei = platform_get_drvdata(pdev); 378 + struct egpio_info *ei = dev_get_drvdata(dev); 380 379 381 - if (ei->chained_irq && device_may_wakeup(&pdev->dev)) 380 + if (ei->chained_irq && device_may_wakeup(dev)) 382 381 disable_irq_wake(ei->chained_irq); 383 382 384 383 /* Update registers from the cache, in case ··· 385 386 egpio_write_cache(ei); 386 387 return 0; 387 388 } 388 - #else 389 - #define egpio_suspend NULL 390 - #define egpio_resume NULL 391 - #endif 392 389 390 + static DEFINE_SIMPLE_DEV_PM_OPS(egpio_pm_ops, egpio_suspend, egpio_resume); 393 391 394 392 static struct platform_driver egpio_driver = { 395 393 .driver = { 396 394 .name = "htc-egpio", 397 395 .suppress_bind_attrs = true, 396 + .pm = pm_sleep_ptr(&egpio_pm_ops), 398 397 }, 399 - .suspend = egpio_suspend, 400 - .resume = egpio_resume, 401 398 }; 402 399 403 400 static int __init egpio_init(void)
-2
drivers/gpio/gpio-latch.c
··· 48 48 #include <linux/property.h> 49 49 #include <linux/delay.h> 50 50 51 - #include "gpiolib.h" 52 - 53 51 struct gpio_latch_priv { 54 52 struct gpio_chip gc; 55 53 struct gpio_descs *clk_gpios;
+6 -5
drivers/gpio/gpio-loongson-64bit.c
··· 312 312 lgpio->chip.gc.direction_output = loongson_gpio_direction_output; 313 313 lgpio->chip.gc.set = loongson_gpio_set; 314 314 lgpio->chip.gc.parent = &pdev->dev; 315 + lgpio->chip.gc.base = -1; 315 316 spin_lock_init(&lgpio->lock); 316 317 } 317 318 ··· 408 407 409 408 static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data1 = { 410 409 .label = "ls2k2000_gpio", 411 - .mode = BIT_CTRL_MODE, 412 - .conf_offset = 0x0, 413 - .in_offset = 0x20, 414 - .out_offset = 0x10, 415 - .inten_offset = 0x30, 410 + .mode = BYTE_CTRL_MODE, 411 + .conf_offset = 0x800, 412 + .in_offset = 0xa00, 413 + .out_offset = 0x900, 414 + .inten_offset = 0xb00, 416 415 }; 417 416 418 417 static const struct loongson_gpio_chip_data loongson_gpio_ls2k2000_data2 = {
+23 -3
drivers/gpio/gpio-menz127.c
··· 24 24 #define MEN_Z127_ODER 0x1C 25 25 #define GPIO_TO_DBCNT_REG(gpio) ((gpio * 4) + 0x80) 26 26 27 + /* MEN Z127 supported model ids*/ 28 + #define MEN_Z127_ID 0x7f 29 + #define MEN_Z034_ID 0x22 30 + #define MEN_Z037_ID 0x25 31 + 27 32 #define MEN_Z127_DB_MIN_US 50 28 33 /* 16 bit compare register. Each bit represents 50us */ 29 34 #define MEN_Z127_DB_MAX_US (0xffff * MEN_Z127_DB_MIN_US) ··· 145 140 struct men_z127_gpio *men_z127_gpio; 146 141 struct device *dev = &mdev->dev; 147 142 int ret; 143 + unsigned long sz; 148 144 149 145 men_z127_gpio = devm_kzalloc(dev, sizeof(struct men_z127_gpio), 150 146 GFP_KERNEL); ··· 169 163 170 164 mcb_set_drvdata(mdev, men_z127_gpio); 171 165 166 + switch (mdev->id) { 167 + case MEN_Z127_ID: 168 + sz = 4; 169 + break; 170 + case MEN_Z034_ID: 171 + case MEN_Z037_ID: 172 + sz = 1; 173 + break; 174 + default: 175 + return dev_err_probe(&mdev->dev, -EINVAL, "no size found for id %d", mdev->id); 176 + } 177 + 172 178 config = (struct gpio_generic_chip_config) { 173 179 .dev = &mdev->dev, 174 - .sz = 4, 180 + .sz = sz, 175 181 .dat = men_z127_gpio->reg_base + MEN_Z127_PSR, 176 182 .set = men_z127_gpio->reg_base + MEN_Z127_CTRL, 177 183 .dirout = men_z127_gpio->reg_base + MEN_Z127_GPIODR, ··· 204 186 } 205 187 206 188 static const struct mcb_device_id men_z127_ids[] = { 207 - { .device = 0x7f }, 189 + { .device = MEN_Z127_ID }, 190 + { .device = MEN_Z034_ID }, 191 + { .device = MEN_Z037_ID }, 208 192 { } 209 193 }; 210 194 MODULE_DEVICE_TABLE(mcb, men_z127_ids); ··· 221 201 module_mcb_driver(men_z127_driver); 222 202 223 203 MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>"); 224 - MODULE_DESCRIPTION("MEN 16z127 GPIO Controller"); 204 + MODULE_DESCRIPTION("MEN GPIO Controller"); 225 205 MODULE_LICENSE("GPL v2"); 226 206 MODULE_ALIAS("mcb:16z127"); 227 207 MODULE_IMPORT_NS("MCB");
+6 -6
drivers/gpio/gpio-ml-ioh.c
··· 160 160 /* 161 161 * Save register configuration and disable interrupts. 162 162 */ 163 - static void __maybe_unused ioh_gpio_save_reg_conf(struct ioh_gpio *chip) 163 + static void ioh_gpio_save_reg_conf(struct ioh_gpio *chip) 164 164 { 165 165 int i; 166 166 ··· 186 186 /* 187 187 * This function restores the register configuration of the GPIO device. 188 188 */ 189 - static void __maybe_unused ioh_gpio_restore_reg_conf(struct ioh_gpio *chip) 189 + static void ioh_gpio_restore_reg_conf(struct ioh_gpio *chip) 190 190 { 191 191 int i; 192 192 ··· 479 479 return 0; 480 480 } 481 481 482 - static int __maybe_unused ioh_gpio_suspend(struct device *dev) 482 + static int ioh_gpio_suspend(struct device *dev) 483 483 { 484 484 struct ioh_gpio *chip = dev_get_drvdata(dev); 485 485 unsigned long flags; ··· 491 491 return 0; 492 492 } 493 493 494 - static int __maybe_unused ioh_gpio_resume(struct device *dev) 494 + static int ioh_gpio_resume(struct device *dev) 495 495 { 496 496 struct ioh_gpio *chip = dev_get_drvdata(dev); 497 497 unsigned long flags; ··· 505 505 return 0; 506 506 } 507 507 508 - static SIMPLE_DEV_PM_OPS(ioh_gpio_pm_ops, ioh_gpio_suspend, ioh_gpio_resume); 508 + static DEFINE_SIMPLE_DEV_PM_OPS(ioh_gpio_pm_ops, ioh_gpio_suspend, ioh_gpio_resume); 509 509 510 510 static const struct pci_device_id ioh_gpio_pcidev_id[] = { 511 511 { PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x802E) }, ··· 518 518 .id_table = ioh_gpio_pcidev_id, 519 519 .probe = ioh_gpio_probe, 520 520 .driver = { 521 - .pm = &ioh_gpio_pm_ops, 521 + .pm = pm_sleep_ptr(&ioh_gpio_pm_ops), 522 522 }, 523 523 }; 524 524
+4 -4
drivers/gpio/gpio-mlxbf2.c
··· 424 424 return 0; 425 425 } 426 426 427 - static int __maybe_unused mlxbf2_gpio_suspend(struct device *dev) 427 + static int mlxbf2_gpio_suspend(struct device *dev) 428 428 { 429 429 struct mlxbf2_gpio_context *gs = dev_get_drvdata(dev); 430 430 ··· 436 436 return 0; 437 437 } 438 438 439 - static int __maybe_unused mlxbf2_gpio_resume(struct device *dev) 439 + static int mlxbf2_gpio_resume(struct device *dev) 440 440 { 441 441 struct mlxbf2_gpio_context *gs = dev_get_drvdata(dev); 442 442 ··· 447 447 448 448 return 0; 449 449 } 450 - static SIMPLE_DEV_PM_OPS(mlxbf2_pm_ops, mlxbf2_gpio_suspend, mlxbf2_gpio_resume); 450 + static DEFINE_SIMPLE_DEV_PM_OPS(mlxbf2_pm_ops, mlxbf2_gpio_suspend, mlxbf2_gpio_resume); 451 451 452 452 static const struct acpi_device_id __maybe_unused mlxbf2_gpio_acpi_match[] = { 453 453 { "MLNXBF22", 0 }, ··· 459 459 .driver = { 460 460 .name = "mlxbf2_gpio", 461 461 .acpi_match_table = mlxbf2_gpio_acpi_match, 462 - .pm = &mlxbf2_pm_ops, 462 + .pm = pm_sleep_ptr(&mlxbf2_pm_ops), 463 463 }, 464 464 .probe = mlxbf2_gpio_probe, 465 465 };
+30 -27
drivers/gpio/gpio-mm-lantiq.c
··· 10 10 #include <linux/platform_device.h> 11 11 #include <linux/mutex.h> 12 12 #include <linux/gpio/driver.h> 13 - #include <linux/gpio/legacy-of-mm-gpiochip.h> 14 13 #include <linux/of.h> 15 14 #include <linux/io.h> 16 15 #include <linux/slab.h> ··· 26 27 #define LTQ_EBU_WP 0x80000000 /* write protect bit */ 27 28 28 29 struct ltq_mm { 29 - struct of_mm_gpio_chip mmchip; 30 + struct gpio_chip gc; 31 + void __iomem *regs; 30 32 u16 shadow; /* shadow the latches state */ 31 33 }; 32 34 ··· 44 44 45 45 spin_lock_irqsave(&ebu_lock, flags); 46 46 ltq_ebu_w32(LTQ_EBU_BUSCON, LTQ_EBU_BUSCON1); 47 - __raw_writew(chip->shadow, chip->mmchip.regs); 47 + __raw_writew(chip->shadow, chip->regs); 48 48 ltq_ebu_w32(LTQ_EBU_BUSCON | LTQ_EBU_WP, LTQ_EBU_BUSCON1); 49 49 spin_unlock_irqrestore(&ebu_lock, flags); 50 50 } ··· 52 52 /** 53 53 * ltq_mm_set() - gpio_chip->set - set gpios. 54 54 * @gc: Pointer to gpio_chip device structure. 55 - * @gpio: GPIO signal number. 56 - * @val: Value to be written to specified signal. 55 + * @offset: GPIO signal number. 56 + * @value: Value to be written to specified signal. 57 57 * 58 58 * Set the shadow value and call ltq_mm_apply. Always returns 0. 59 59 */ ··· 73 73 /** 74 74 * ltq_mm_dir_out() - gpio_chip->dir_out - set gpio direction. 75 75 * @gc: Pointer to gpio_chip device structure. 76 - * @gpio: GPIO signal number. 77 - * @val: Value to be written to specified signal. 76 + * @offset: GPIO signal number. 77 + * @value: Value to be written to specified signal. 78 78 * 79 79 * Same as ltq_mm_set, always returns 0. 80 80 */ ··· 85 85 86 86 /** 87 87 * ltq_mm_save_regs() - Set initial values of GPIO pins 88 - * @mm_gc: pointer to memory mapped GPIO chip structure 88 + * @chip: Pointer to our private data structure. 89 89 */ 90 - static void ltq_mm_save_regs(struct of_mm_gpio_chip *mm_gc) 90 + static void ltq_mm_save_regs(struct ltq_mm *chip) 91 91 { 92 - struct ltq_mm *chip = 93 - container_of(mm_gc, struct ltq_mm, mmchip); 94 - 95 92 /* tell the ebu controller which memory address we will be using */ 96 - ltq_ebu_w32(CPHYSADDR(chip->mmchip.regs) | 0x1, LTQ_EBU_ADDRSEL1); 93 + ltq_ebu_w32(CPHYSADDR((__force void *)chip->regs) | 0x1, LTQ_EBU_ADDRSEL1); 97 94 98 95 ltq_mm_apply(chip); 99 96 } 100 97 101 98 static int ltq_mm_probe(struct platform_device *pdev) 102 99 { 100 + struct device *dev = &pdev->dev; 101 + struct device_node *np = dev->of_node; 102 + struct gpio_chip *gc; 103 103 struct ltq_mm *chip; 104 104 u32 shadow; 105 105 ··· 107 107 if (!chip) 108 108 return -ENOMEM; 109 109 110 - platform_set_drvdata(pdev, chip); 110 + gc = &chip->gc; 111 111 112 - chip->mmchip.gc.ngpio = 16; 113 - chip->mmchip.gc.direction_output = ltq_mm_dir_out; 114 - chip->mmchip.gc.set = ltq_mm_set; 115 - chip->mmchip.save_regs = ltq_mm_save_regs; 112 + gc->base = -1; 113 + gc->ngpio = 16; 114 + gc->direction_output = ltq_mm_dir_out; 115 + gc->set = ltq_mm_set; 116 + gc->parent = dev; 117 + gc->owner = THIS_MODULE; 118 + gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pOF", np); 119 + if (!gc->label) 120 + return -ENOMEM; 121 + 122 + chip->regs = devm_of_iomap(dev, np, 0, NULL); 123 + if (IS_ERR(chip->regs)) 124 + return PTR_ERR(chip->regs); 125 + 126 + ltq_mm_save_regs(chip); 116 127 117 128 /* store the shadow value if one was passed by the devicetree */ 118 129 if (!of_property_read_u32(pdev->dev.of_node, "lantiq,shadow", &shadow)) 119 130 chip->shadow = shadow; 120 131 121 - return of_mm_gpiochip_add_data(pdev->dev.of_node, &chip->mmchip, chip); 122 - } 123 - 124 - static void ltq_mm_remove(struct platform_device *pdev) 125 - { 126 - struct ltq_mm *chip = platform_get_drvdata(pdev); 127 - 128 - of_mm_gpiochip_remove(&chip->mmchip); 132 + return devm_gpiochip_add_data(dev, gc, chip); 129 133 } 130 134 131 135 static const struct of_device_id ltq_mm_match[] = { ··· 140 136 141 137 static struct platform_driver ltq_mm_driver = { 142 138 .probe = ltq_mm_probe, 143 - .remove = ltq_mm_remove, 144 139 .driver = { 145 140 .name = "gpio-mm-ltq", 146 141 .of_match_table = ltq_mm_match,
+162 -173
drivers/gpio/gpio-mmio.c
··· 41 41 */ 42 42 43 43 #include <linux/bitops.h> 44 + #include <linux/cleanup.h> 44 45 #include <linux/compiler.h> 45 46 #include <linux/err.h> 46 47 #include <linux/init.h> ··· 62 61 63 62 #include "gpiolib.h" 64 63 65 - static void bgpio_write8(void __iomem *reg, unsigned long data) 64 + static void gpio_mmio_write8(void __iomem *reg, unsigned long data) 66 65 { 67 66 writeb(data, reg); 68 67 } 69 68 70 - static unsigned long bgpio_read8(void __iomem *reg) 69 + static unsigned long gpio_mmio_read8(void __iomem *reg) 71 70 { 72 71 return readb(reg); 73 72 } 74 73 75 - static void bgpio_write16(void __iomem *reg, unsigned long data) 74 + static void gpio_mmio_write16(void __iomem *reg, unsigned long data) 76 75 { 77 76 writew(data, reg); 78 77 } 79 78 80 - static unsigned long bgpio_read16(void __iomem *reg) 79 + static unsigned long gpio_mmio_read16(void __iomem *reg) 81 80 { 82 81 return readw(reg); 83 82 } 84 83 85 - static void bgpio_write32(void __iomem *reg, unsigned long data) 84 + static void gpio_mmio_write32(void __iomem *reg, unsigned long data) 86 85 { 87 86 writel(data, reg); 88 87 } 89 88 90 - static unsigned long bgpio_read32(void __iomem *reg) 89 + static unsigned long gpio_mmio_read32(void __iomem *reg) 91 90 { 92 91 return readl(reg); 93 92 } 94 93 95 94 #if BITS_PER_LONG >= 64 96 - static void bgpio_write64(void __iomem *reg, unsigned long data) 95 + static void gpio_mmio_write64(void __iomem *reg, unsigned long data) 97 96 { 98 97 writeq(data, reg); 99 98 } 100 99 101 - static unsigned long bgpio_read64(void __iomem *reg) 100 + static unsigned long gpio_mmio_read64(void __iomem *reg) 102 101 { 103 102 return readq(reg); 104 103 } 105 104 #endif /* BITS_PER_LONG >= 64 */ 106 105 107 - static void bgpio_write16be(void __iomem *reg, unsigned long data) 106 + static void gpio_mmio_write16be(void __iomem *reg, unsigned long data) 108 107 { 109 108 iowrite16be(data, reg); 110 109 } 111 110 112 - static unsigned long bgpio_read16be(void __iomem *reg) 111 + static unsigned long gpio_mmio_read16be(void __iomem *reg) 113 112 { 114 113 return ioread16be(reg); 115 114 } 116 115 117 - static void bgpio_write32be(void __iomem *reg, unsigned long data) 116 + static void gpio_mmio_write32be(void __iomem *reg, unsigned long data) 118 117 { 119 118 iowrite32be(data, reg); 120 119 } 121 120 122 - static unsigned long bgpio_read32be(void __iomem *reg) 121 + static unsigned long gpio_mmio_read32be(void __iomem *reg) 123 122 { 124 123 return ioread32be(reg); 125 124 } 126 125 127 - static unsigned long bgpio_line2mask(struct gpio_chip *gc, unsigned int line) 126 + static unsigned long gpio_mmio_line2mask(struct gpio_chip *gc, unsigned int line) 128 127 { 129 128 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 130 129 ··· 133 132 return BIT(line); 134 133 } 135 134 136 - static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio) 135 + static int gpio_mmio_get_set(struct gpio_chip *gc, unsigned int gpio) 137 136 { 138 137 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 139 - unsigned long pinmask = bgpio_line2mask(gc, gpio); 138 + unsigned long pinmask = gpio_mmio_line2mask(gc, gpio); 140 139 bool dir = !!(chip->sdir & pinmask); 141 140 142 141 if (dir) ··· 149 148 * This assumes that the bits in the GPIO register are in native endianness. 150 149 * We only assign the function pointer if we have that. 151 150 */ 152 - static int bgpio_get_set_multiple(struct gpio_chip *gc, unsigned long *mask, 153 - unsigned long *bits) 151 + static int gpio_mmio_get_set_multiple(struct gpio_chip *gc, unsigned long *mask, 152 + unsigned long *bits) 154 153 { 155 154 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 156 155 unsigned long get_mask = 0, set_mask = 0; ··· 169 168 return 0; 170 169 } 171 170 172 - static int bgpio_get(struct gpio_chip *gc, unsigned int gpio) 171 + static int gpio_mmio_get(struct gpio_chip *gc, unsigned int gpio) 173 172 { 174 173 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 175 174 176 - return !!(chip->read_reg(chip->reg_dat) & bgpio_line2mask(gc, gpio)); 175 + return !!(chip->read_reg(chip->reg_dat) & gpio_mmio_line2mask(gc, gpio)); 177 176 } 178 177 179 178 /* 180 179 * This only works if the bits in the GPIO register are in native endianness. 181 180 */ 182 - static int bgpio_get_multiple(struct gpio_chip *gc, unsigned long *mask, 183 - unsigned long *bits) 181 + static int gpio_mmio_get_multiple(struct gpio_chip *gc, unsigned long *mask, 182 + unsigned long *bits) 184 183 { 185 184 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 186 185 ··· 193 192 /* 194 193 * With big endian mirrored bit order it becomes more tedious. 195 194 */ 196 - static int bgpio_get_multiple_be(struct gpio_chip *gc, unsigned long *mask, 197 - unsigned long *bits) 195 + static int gpio_mmio_get_multiple_be(struct gpio_chip *gc, unsigned long *mask, 196 + unsigned long *bits) 198 197 { 199 198 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 200 199 unsigned long readmask = 0; ··· 206 205 207 206 /* Create a mirrored mask */ 208 207 for_each_set_bit(bit, mask, gc->ngpio) 209 - readmask |= bgpio_line2mask(gc, bit); 208 + readmask |= gpio_mmio_line2mask(gc, bit); 210 209 211 210 /* Read the register */ 212 211 val = chip->read_reg(chip->reg_dat) & readmask; ··· 216 215 * in bit 0 ... line 31 in bit 31 for a 32bit register. 217 216 */ 218 217 for_each_set_bit(bit, &val, gc->ngpio) 219 - *bits |= bgpio_line2mask(gc, bit); 218 + *bits |= gpio_mmio_line2mask(gc, bit); 220 219 221 220 return 0; 222 221 } 223 222 224 - static int bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val) 223 + static int gpio_mmio_set_none(struct gpio_chip *gc, unsigned int gpio, int val) 225 224 { 226 225 return 0; 227 226 } 228 227 229 - static int bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 228 + static int gpio_mmio_set(struct gpio_chip *gc, unsigned int gpio, int val) 230 229 { 231 230 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 232 - unsigned long mask = bgpio_line2mask(gc, gpio); 233 - unsigned long flags; 231 + unsigned long mask = gpio_mmio_line2mask(gc, gpio); 234 232 235 - raw_spin_lock_irqsave(&chip->lock, flags); 233 + guard(raw_spinlock)(&chip->lock); 236 234 237 235 if (val) 238 236 chip->sdata |= mask; ··· 240 240 241 241 chip->write_reg(chip->reg_dat, chip->sdata); 242 242 243 - raw_spin_unlock_irqrestore(&chip->lock, flags); 244 - 245 243 return 0; 246 244 } 247 245 248 - static int bgpio_set_with_clear(struct gpio_chip *gc, unsigned int gpio, 249 - int val) 246 + static int gpio_mmio_set_with_clear(struct gpio_chip *gc, unsigned int gpio, 247 + int val) 250 248 { 251 249 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 252 - unsigned long mask = bgpio_line2mask(gc, gpio); 250 + unsigned long mask = gpio_mmio_line2mask(gc, gpio); 253 251 254 252 if (val) 255 253 chip->write_reg(chip->reg_set, mask); ··· 257 259 return 0; 258 260 } 259 261 260 - static int bgpio_set_set(struct gpio_chip *gc, unsigned int gpio, int val) 262 + static int gpio_mmio_set_set(struct gpio_chip *gc, unsigned int gpio, int val) 261 263 { 262 264 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 263 - unsigned long mask = bgpio_line2mask(gc, gpio), flags; 265 + unsigned long mask = gpio_mmio_line2mask(gc, gpio); 264 266 265 - raw_spin_lock_irqsave(&chip->lock, flags); 267 + guard(raw_spinlock)(&chip->lock); 266 268 267 269 if (val) 268 270 chip->sdata |= mask; ··· 271 273 272 274 chip->write_reg(chip->reg_set, chip->sdata); 273 275 274 - raw_spin_unlock_irqrestore(&chip->lock, flags); 275 - 276 276 return 0; 277 277 } 278 278 279 - static void bgpio_multiple_get_masks(struct gpio_chip *gc, 280 - unsigned long *mask, unsigned long *bits, 281 - unsigned long *set_mask, 282 - unsigned long *clear_mask) 279 + static void gpio_mmio_multiple_get_masks(struct gpio_chip *gc, 280 + unsigned long *mask, 281 + unsigned long *bits, 282 + unsigned long *set_mask, 283 + unsigned long *clear_mask) 283 284 { 284 285 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 285 286 int i; ··· 288 291 289 292 for_each_set_bit(i, mask, chip->bits) { 290 293 if (test_bit(i, bits)) 291 - *set_mask |= bgpio_line2mask(gc, i); 294 + *set_mask |= gpio_mmio_line2mask(gc, i); 292 295 else 293 - *clear_mask |= bgpio_line2mask(gc, i); 296 + *clear_mask |= gpio_mmio_line2mask(gc, i); 294 297 } 295 298 } 296 299 297 - static void bgpio_set_multiple_single_reg(struct gpio_chip *gc, 298 - unsigned long *mask, 299 - unsigned long *bits, 300 - void __iomem *reg) 300 + static void gpio_mmio_set_multiple_single_reg(struct gpio_chip *gc, 301 + unsigned long *mask, 302 + unsigned long *bits, 303 + void __iomem *reg) 301 304 { 302 305 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 303 - unsigned long flags, set_mask, clear_mask; 306 + unsigned long set_mask, clear_mask; 304 307 305 - raw_spin_lock_irqsave(&chip->lock, flags); 308 + guard(raw_spinlock)(&chip->lock); 306 309 307 - bgpio_multiple_get_masks(gc, mask, bits, &set_mask, &clear_mask); 310 + gpio_mmio_multiple_get_masks(gc, mask, bits, &set_mask, &clear_mask); 308 311 309 312 chip->sdata |= set_mask; 310 313 chip->sdata &= ~clear_mask; 311 314 312 315 chip->write_reg(reg, chip->sdata); 313 - 314 - raw_spin_unlock_irqrestore(&chip->lock, flags); 315 316 } 316 317 317 - static int bgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, 318 - unsigned long *bits) 319 - { 320 - struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 321 - 322 - bgpio_set_multiple_single_reg(gc, mask, bits, chip->reg_dat); 323 - 324 - return 0; 325 - } 326 - 327 - static int bgpio_set_multiple_set(struct gpio_chip *gc, unsigned long *mask, 318 + static int gpio_mmio_set_multiple(struct gpio_chip *gc, unsigned long *mask, 328 319 unsigned long *bits) 329 320 { 330 321 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 331 322 332 - bgpio_set_multiple_single_reg(gc, mask, bits, chip->reg_set); 323 + gpio_mmio_set_multiple_single_reg(gc, mask, bits, chip->reg_dat); 333 324 334 325 return 0; 335 326 } 336 327 337 - static int bgpio_set_multiple_with_clear(struct gpio_chip *gc, 338 - unsigned long *mask, 339 - unsigned long *bits) 328 + static int gpio_mmio_set_multiple_set(struct gpio_chip *gc, unsigned long *mask, 329 + unsigned long *bits) 330 + { 331 + struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 332 + 333 + gpio_mmio_set_multiple_single_reg(gc, mask, bits, chip->reg_set); 334 + 335 + return 0; 336 + } 337 + 338 + static int gpio_mmio_set_multiple_with_clear(struct gpio_chip *gc, 339 + unsigned long *mask, 340 + unsigned long *bits) 340 341 { 341 342 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 342 343 unsigned long set_mask, clear_mask; 343 344 344 - bgpio_multiple_get_masks(gc, mask, bits, &set_mask, &clear_mask); 345 + gpio_mmio_multiple_get_masks(gc, mask, bits, &set_mask, &clear_mask); 345 346 346 347 if (set_mask) 347 348 chip->write_reg(chip->reg_set, set_mask); ··· 349 354 return 0; 350 355 } 351 356 352 - static int bgpio_dir_return(struct gpio_chip *gc, unsigned int gpio, bool dir_out) 357 + static int gpio_mmio_dir_return(struct gpio_chip *gc, unsigned int gpio, 358 + bool dir_out) 353 359 { 354 360 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 355 361 ··· 363 367 return pinctrl_gpio_direction_input(gc, gpio); 364 368 } 365 369 366 - static int bgpio_dir_in_err(struct gpio_chip *gc, unsigned int gpio) 370 + static int gpio_mmio_dir_in_err(struct gpio_chip *gc, unsigned int gpio) 367 371 { 368 372 return -EINVAL; 369 373 } 370 374 371 - static int bgpio_simple_dir_in(struct gpio_chip *gc, unsigned int gpio) 375 + static int gpio_mmio_simple_dir_in(struct gpio_chip *gc, unsigned int gpio) 372 376 { 373 - return bgpio_dir_return(gc, gpio, false); 377 + return gpio_mmio_dir_return(gc, gpio, false); 374 378 } 375 379 376 - static int bgpio_dir_out_err(struct gpio_chip *gc, unsigned int gpio, 377 - int val) 380 + static int gpio_mmio_dir_out_err(struct gpio_chip *gc, unsigned int gpio, 381 + int val) 378 382 { 379 383 return -EINVAL; 380 384 } 381 385 382 - static int bgpio_simple_dir_out(struct gpio_chip *gc, unsigned int gpio, 383 - int val) 386 + static int gpio_mmio_simple_dir_out(struct gpio_chip *gc, unsigned int gpio, 387 + int val) 384 388 { 385 389 gc->set(gc, gpio, val); 386 390 387 - return bgpio_dir_return(gc, gpio, true); 391 + return gpio_mmio_dir_return(gc, gpio, true); 388 392 } 389 393 390 - static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) 394 + static int gpio_mmio_dir_in(struct gpio_chip *gc, unsigned int gpio) 391 395 { 392 396 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 393 - unsigned long flags; 394 397 395 - raw_spin_lock_irqsave(&chip->lock, flags); 398 + scoped_guard(raw_spinlock, &chip->lock) { 399 + chip->sdir &= ~gpio_mmio_line2mask(gc, gpio); 396 400 397 - chip->sdir &= ~bgpio_line2mask(gc, gpio); 401 + if (chip->reg_dir_in) 402 + chip->write_reg(chip->reg_dir_in, ~chip->sdir); 403 + if (chip->reg_dir_out) 404 + chip->write_reg(chip->reg_dir_out, chip->sdir); 405 + } 398 406 399 - if (chip->reg_dir_in) 400 - chip->write_reg(chip->reg_dir_in, ~chip->sdir); 401 - if (chip->reg_dir_out) 402 - chip->write_reg(chip->reg_dir_out, chip->sdir); 403 - 404 - raw_spin_unlock_irqrestore(&chip->lock, flags); 405 - 406 - return bgpio_dir_return(gc, gpio, false); 407 + return gpio_mmio_dir_return(gc, gpio, false); 407 408 } 408 409 409 - static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio) 410 + static int gpio_mmio_get_dir(struct gpio_chip *gc, unsigned int gpio) 410 411 { 411 412 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 412 413 413 414 /* Return 0 if output, 1 if input */ 414 415 if (chip->dir_unreadable) { 415 - if (chip->sdir & bgpio_line2mask(gc, gpio)) 416 + if (chip->sdir & gpio_mmio_line2mask(gc, gpio)) 416 417 return GPIO_LINE_DIRECTION_OUT; 417 418 return GPIO_LINE_DIRECTION_IN; 418 419 } 419 420 420 421 if (chip->reg_dir_out) { 421 - if (chip->read_reg(chip->reg_dir_out) & bgpio_line2mask(gc, gpio)) 422 + if (chip->read_reg(chip->reg_dir_out) & gpio_mmio_line2mask(gc, gpio)) 422 423 return GPIO_LINE_DIRECTION_OUT; 423 424 return GPIO_LINE_DIRECTION_IN; 424 425 } 425 426 426 427 if (chip->reg_dir_in) 427 - if (!(chip->read_reg(chip->reg_dir_in) & bgpio_line2mask(gc, gpio))) 428 + if (!(chip->read_reg(chip->reg_dir_in) & gpio_mmio_line2mask(gc, gpio))) 428 429 return GPIO_LINE_DIRECTION_OUT; 429 430 430 431 return GPIO_LINE_DIRECTION_IN; 431 432 } 432 433 433 - static void bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 434 + static void gpio_mmio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 434 435 { 435 436 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 436 - unsigned long flags; 437 437 438 - raw_spin_lock_irqsave(&chip->lock, flags); 438 + guard(raw_spinlock)(&chip->lock); 439 439 440 - chip->sdir |= bgpio_line2mask(gc, gpio); 440 + chip->sdir |= gpio_mmio_line2mask(gc, gpio); 441 441 442 442 if (chip->reg_dir_in) 443 443 chip->write_reg(chip->reg_dir_in, ~chip->sdir); 444 444 if (chip->reg_dir_out) 445 445 chip->write_reg(chip->reg_dir_out, chip->sdir); 446 - 447 - raw_spin_unlock_irqrestore(&chip->lock, flags); 448 446 } 449 447 450 - static int bgpio_dir_out_dir_first(struct gpio_chip *gc, unsigned int gpio, 451 - int val) 448 + static int gpio_mmio_dir_out_dir_first(struct gpio_chip *gc, unsigned int gpio, 449 + int val) 452 450 { 453 - bgpio_dir_out(gc, gpio, val); 451 + gpio_mmio_dir_out(gc, gpio, val); 454 452 gc->set(gc, gpio, val); 455 - return bgpio_dir_return(gc, gpio, true); 453 + return gpio_mmio_dir_return(gc, gpio, true); 456 454 } 457 455 458 - static int bgpio_dir_out_val_first(struct gpio_chip *gc, unsigned int gpio, 459 - int val) 456 + static int gpio_mmio_dir_out_val_first(struct gpio_chip *gc, unsigned int gpio, 457 + int val) 460 458 { 461 459 gc->set(gc, gpio, val); 462 - bgpio_dir_out(gc, gpio, val); 463 - return bgpio_dir_return(gc, gpio, true); 460 + gpio_mmio_dir_out(gc, gpio, val); 461 + return gpio_mmio_dir_return(gc, gpio, true); 464 462 } 465 463 466 - static int bgpio_setup_accessors(struct device *dev, 467 - struct gpio_generic_chip *chip, 468 - bool byte_be) 464 + static int gpio_mmio_setup_accessors(struct device *dev, 465 + struct gpio_generic_chip *chip, 466 + bool byte_be) 469 467 { 470 468 switch (chip->bits) { 471 469 case 8: 472 - chip->read_reg = bgpio_read8; 473 - chip->write_reg = bgpio_write8; 470 + chip->read_reg = gpio_mmio_read8; 471 + chip->write_reg = gpio_mmio_write8; 474 472 break; 475 473 case 16: 476 474 if (byte_be) { 477 - chip->read_reg = bgpio_read16be; 478 - chip->write_reg = bgpio_write16be; 475 + chip->read_reg = gpio_mmio_read16be; 476 + chip->write_reg = gpio_mmio_write16be; 479 477 } else { 480 - chip->read_reg = bgpio_read16; 481 - chip->write_reg = bgpio_write16; 478 + chip->read_reg = gpio_mmio_read16; 479 + chip->write_reg = gpio_mmio_write16; 482 480 } 483 481 break; 484 482 case 32: 485 483 if (byte_be) { 486 - chip->read_reg = bgpio_read32be; 487 - chip->write_reg = bgpio_write32be; 484 + chip->read_reg = gpio_mmio_read32be; 485 + chip->write_reg = gpio_mmio_write32be; 488 486 } else { 489 - chip->read_reg = bgpio_read32; 490 - chip->write_reg = bgpio_write32; 487 + chip->read_reg = gpio_mmio_read32; 488 + chip->write_reg = gpio_mmio_write32; 491 489 } 492 490 break; 493 491 #if BITS_PER_LONG >= 64 ··· 491 501 "64 bit big endian byte order unsupported\n"); 492 502 return -EINVAL; 493 503 } else { 494 - chip->read_reg = bgpio_read64; 495 - chip->write_reg = bgpio_write64; 504 + chip->read_reg = gpio_mmio_read64; 505 + chip->write_reg = gpio_mmio_write64; 496 506 } 497 507 break; 498 508 #endif /* BITS_PER_LONG >= 64 */ ··· 526 536 * - an input direction register (named "dirin") where a 1 bit indicates 527 537 * the GPIO is an input. 528 538 */ 529 - static int bgpio_setup_io(struct gpio_generic_chip *chip, 530 - const struct gpio_generic_chip_config *cfg) 539 + static int gpio_mmio_setup_io(struct gpio_generic_chip *chip, 540 + const struct gpio_generic_chip_config *cfg) 531 541 { 532 542 struct gpio_chip *gc = &chip->gc; 533 543 ··· 538 548 if (cfg->set && cfg->clr) { 539 549 chip->reg_set = cfg->set; 540 550 chip->reg_clr = cfg->clr; 541 - gc->set = bgpio_set_with_clear; 542 - gc->set_multiple = bgpio_set_multiple_with_clear; 551 + gc->set = gpio_mmio_set_with_clear; 552 + gc->set_multiple = gpio_mmio_set_multiple_with_clear; 543 553 } else if (cfg->set && !cfg->clr) { 544 554 chip->reg_set = cfg->set; 545 - gc->set = bgpio_set_set; 546 - gc->set_multiple = bgpio_set_multiple_set; 555 + gc->set = gpio_mmio_set_set; 556 + gc->set_multiple = gpio_mmio_set_multiple_set; 547 557 } else if (cfg->flags & GPIO_GENERIC_NO_OUTPUT) { 548 - gc->set = bgpio_set_none; 558 + gc->set = gpio_mmio_set_none; 549 559 gc->set_multiple = NULL; 550 560 } else { 551 - gc->set = bgpio_set; 552 - gc->set_multiple = bgpio_set_multiple; 561 + gc->set = gpio_mmio_set; 562 + gc->set_multiple = gpio_mmio_set_multiple; 553 563 } 554 564 555 565 if (!(cfg->flags & GPIO_GENERIC_UNREADABLE_REG_SET) && 556 566 (cfg->flags & GPIO_GENERIC_READ_OUTPUT_REG_SET)) { 557 - gc->get = bgpio_get_set; 567 + gc->get = gpio_mmio_get_set; 558 568 if (!chip->be_bits) 559 - gc->get_multiple = bgpio_get_set_multiple; 569 + gc->get_multiple = gpio_mmio_get_set_multiple; 560 570 /* 561 571 * We deliberately avoid assigning the ->get_multiple() call 562 572 * for big endian mirrored registers which are ALSO reflecting ··· 565 575 * reading each line individually in that fringe case. 566 576 */ 567 577 } else { 568 - gc->get = bgpio_get; 578 + gc->get = gpio_mmio_get; 569 579 if (chip->be_bits) 570 - gc->get_multiple = bgpio_get_multiple_be; 580 + gc->get_multiple = gpio_mmio_get_multiple_be; 571 581 else 572 - gc->get_multiple = bgpio_get_multiple; 582 + gc->get_multiple = gpio_mmio_get_multiple; 573 583 } 574 584 575 585 return 0; 576 586 } 577 587 578 - static int bgpio_setup_direction(struct gpio_generic_chip *chip, 579 - const struct gpio_generic_chip_config *cfg) 588 + static int gpio_mmio_setup_direction(struct gpio_generic_chip *chip, 589 + const struct gpio_generic_chip_config *cfg) 580 590 { 581 591 struct gpio_chip *gc = &chip->gc; 582 592 ··· 584 594 chip->reg_dir_out = cfg->dirout; 585 595 chip->reg_dir_in = cfg->dirin; 586 596 if (cfg->flags & GPIO_GENERIC_NO_SET_ON_INPUT) 587 - gc->direction_output = bgpio_dir_out_dir_first; 597 + gc->direction_output = gpio_mmio_dir_out_dir_first; 588 598 else 589 - gc->direction_output = bgpio_dir_out_val_first; 590 - gc->direction_input = bgpio_dir_in; 591 - gc->get_direction = bgpio_get_dir; 599 + gc->direction_output = gpio_mmio_dir_out_val_first; 600 + gc->direction_input = gpio_mmio_dir_in; 601 + gc->get_direction = gpio_mmio_get_dir; 592 602 } else { 593 603 if (cfg->flags & GPIO_GENERIC_NO_OUTPUT) 594 - gc->direction_output = bgpio_dir_out_err; 604 + gc->direction_output = gpio_mmio_dir_out_err; 595 605 else 596 - gc->direction_output = bgpio_simple_dir_out; 606 + gc->direction_output = gpio_mmio_simple_dir_out; 597 607 598 608 if (cfg->flags & GPIO_GENERIC_NO_INPUT) 599 - gc->direction_input = bgpio_dir_in_err; 609 + gc->direction_input = gpio_mmio_dir_in_err; 600 610 else 601 - gc->direction_input = bgpio_simple_dir_in; 611 + gc->direction_input = gpio_mmio_simple_dir_in; 602 612 } 603 613 604 614 return 0; 605 615 } 606 616 607 - static int bgpio_request(struct gpio_chip *gc, unsigned int gpio_pin) 617 + static int gpio_mmio_request(struct gpio_chip *gc, unsigned int gpio_pin) 608 618 { 609 619 struct gpio_generic_chip *chip = to_gpio_generic_chip(gc); 610 620 ··· 643 653 gc->parent = dev; 644 654 gc->label = dev_name(dev); 645 655 gc->base = -1; 646 - gc->request = bgpio_request; 656 + gc->request = gpio_mmio_request; 647 657 chip->be_bits = !!(flags & GPIO_GENERIC_BIG_ENDIAN); 648 658 649 659 ret = gpiochip_get_ngpios(gc, dev); 650 660 if (ret) 651 661 gc->ngpio = chip->bits; 652 662 653 - ret = bgpio_setup_io(chip, cfg); 663 + ret = gpio_mmio_setup_io(chip, cfg); 654 664 if (ret) 655 665 return ret; 656 666 657 - ret = bgpio_setup_accessors(dev, chip, 667 + ret = gpio_mmio_setup_accessors(dev, chip, 658 668 flags & GPIO_GENERIC_BIG_ENDIAN_BYTE_ORDER); 659 669 if (ret) 660 670 return ret; 661 671 662 - ret = bgpio_setup_direction(chip, cfg); 672 + ret = gpio_mmio_setup_direction(chip, cfg); 663 673 if (ret) 664 674 return ret; 665 675 ··· 670 680 } 671 681 672 682 chip->sdata = chip->read_reg(chip->reg_dat); 673 - if (gc->set == bgpio_set_set && 683 + if (gc->set == gpio_mmio_set_set && 674 684 !(flags & GPIO_GENERIC_UNREADABLE_REG_SET)) 675 685 chip->sdata = chip->read_reg(chip->reg_set); 676 686 ··· 702 712 703 713 #if IS_ENABLED(CONFIG_GPIO_GENERIC_PLATFORM) 704 714 705 - static void __iomem *bgpio_map(struct platform_device *pdev, 706 - const char *name, 707 - resource_size_t sane_sz) 715 + static void __iomem *gpio_mmio_map(struct platform_device *pdev, 716 + const char *name, resource_size_t sane_sz) 708 717 { 709 718 struct resource *r; 710 719 resource_size_t sz; ··· 719 730 return devm_ioremap_resource(&pdev->dev, r); 720 731 } 721 732 722 - static const struct of_device_id bgpio_of_match[] = { 733 + static const struct of_device_id gpio_mmio_of_match[] = { 723 734 { .compatible = "brcm,bcm6345-gpio" }, 724 735 { .compatible = "wd,mbl-gpio" }, 725 736 { .compatible = "ni,169445-nand-gpio" }, 726 737 { .compatible = "intel,ixp4xx-expansion-bus-mmio-gpio" }, 727 738 { } 728 739 }; 729 - MODULE_DEVICE_TABLE(of, bgpio_of_match); 740 + MODULE_DEVICE_TABLE(of, gpio_mmio_of_match); 730 741 731 - static int bgpio_pdev_probe(struct platform_device *pdev) 742 + static int gpio_mmio_pdev_probe(struct platform_device *pdev) 732 743 { 733 744 struct gpio_generic_chip_config config; 734 745 struct gpio_generic_chip *gen_gc; ··· 751 762 752 763 sz = resource_size(r); 753 764 754 - dat = bgpio_map(pdev, "dat", sz); 765 + dat = gpio_mmio_map(pdev, "dat", sz); 755 766 if (IS_ERR(dat)) 756 767 return PTR_ERR(dat); 757 768 758 - set = bgpio_map(pdev, "set", sz); 769 + set = gpio_mmio_map(pdev, "set", sz); 759 770 if (IS_ERR(set)) 760 771 return PTR_ERR(set); 761 772 762 - clr = bgpio_map(pdev, "clr", sz); 773 + clr = gpio_mmio_map(pdev, "clr", sz); 763 774 if (IS_ERR(clr)) 764 775 return PTR_ERR(clr); 765 776 766 - dirout = bgpio_map(pdev, "dirout", sz); 777 + dirout = gpio_mmio_map(pdev, "dirout", sz); 767 778 if (IS_ERR(dirout)) 768 779 return PTR_ERR(dirout); 769 780 770 - dirin = bgpio_map(pdev, "dirin", sz); 781 + dirin = gpio_mmio_map(pdev, "dirin", sz); 771 782 if (IS_ERR(dirin)) 772 783 return PTR_ERR(dirin); 773 784 ··· 813 824 return devm_gpiochip_add_data(&pdev->dev, &gen_gc->gc, NULL); 814 825 } 815 826 816 - static const struct platform_device_id bgpio_id_table[] = { 827 + static const struct platform_device_id gpio_mmio_id_table[] = { 817 828 { 818 829 .name = "basic-mmio-gpio", 819 830 .driver_data = 0, 820 831 }, 821 832 { } 822 833 }; 823 - MODULE_DEVICE_TABLE(platform, bgpio_id_table); 834 + MODULE_DEVICE_TABLE(platform, gpio_mmio_id_table); 824 835 825 - static struct platform_driver bgpio_driver = { 836 + static struct platform_driver gpio_mmio_driver = { 826 837 .driver = { 827 838 .name = "basic-mmio-gpio", 828 - .of_match_table = bgpio_of_match, 839 + .of_match_table = gpio_mmio_of_match, 829 840 }, 830 - .id_table = bgpio_id_table, 831 - .probe = bgpio_pdev_probe, 841 + .id_table = gpio_mmio_id_table, 842 + .probe = gpio_mmio_pdev_probe, 832 843 }; 833 844 834 - module_platform_driver(bgpio_driver); 845 + module_platform_driver(gpio_mmio_driver); 835 846 836 847 #endif /* CONFIG_GPIO_GENERIC_PLATFORM */ 837 848
+217 -12
drivers/gpio/gpio-mpsse.c
··· 10 10 #include <linux/cleanup.h> 11 11 #include <linux/gpio/driver.h> 12 12 #include <linux/mutex.h> 13 + #include <linux/spinlock.h> 13 14 #include <linux/usb.h> 14 15 15 16 struct mpsse_priv { ··· 18 17 struct usb_device *udev; /* USB device encompassing all MPSSEs */ 19 18 struct usb_interface *intf; /* USB interface for this MPSSE */ 20 19 u8 intf_id; /* USB interface number for this MPSSE */ 21 - struct work_struct irq_work; /* polling work thread */ 20 + struct list_head workers; /* polling work threads */ 22 21 struct mutex irq_mutex; /* lock over irq_data */ 22 + struct mutex irq_race; /* race for polling worker teardown */ 23 + raw_spinlock_t irq_spin; /* protects worker list */ 23 24 atomic_t irq_type[16]; /* pin -> edge detection type */ 24 25 atomic_t irq_enabled; 25 26 int id; ··· 29 26 u8 gpio_outputs[2]; /* Output states for GPIOs [L, H] */ 30 27 u8 gpio_dir[2]; /* Directions for GPIOs [L, H] */ 31 28 29 + unsigned long dir_in; /* Bitmask of valid input pins */ 30 + unsigned long dir_out; /* Bitmask of valid output pins */ 31 + 32 32 u8 *bulk_in_buf; /* Extra recv buffer to grab status bytes */ 33 33 34 34 struct usb_endpoint_descriptor *bulk_in; 35 35 struct usb_endpoint_descriptor *bulk_out; 36 36 37 37 struct mutex io_mutex; /* sync I/O with disconnect */ 38 + }; 39 + 40 + struct mpsse_worker { 41 + struct mpsse_priv *priv; 42 + struct work_struct work; 43 + atomic_t cancelled; 44 + struct list_head list; /* linked list */ 45 + struct list_head destroy; /* teardown linked list */ 38 46 }; 39 47 40 48 struct bulk_desc { ··· 57 43 int timeout; 58 44 }; 59 45 46 + #define MPSSE_NGPIO 16 47 + 48 + struct mpsse_quirk { 49 + const char *names[MPSSE_NGPIO]; /* Pin names, if applicable */ 50 + unsigned long dir_in; /* Bitmask of valid input pins */ 51 + unsigned long dir_out; /* Bitmask of valid output pins */ 52 + }; 53 + 54 + static struct mpsse_quirk bryx_brik_quirk = { 55 + .names = { 56 + [3] = "Push to Talk", 57 + [5] = "Channel Activity", 58 + }, 59 + .dir_out = BIT(3), /* Push to Talk */ 60 + .dir_in = BIT(5), /* Channel Activity */ 61 + }; 62 + 60 63 static const struct usb_device_id gpio_mpsse_table[] = { 61 64 { USB_DEVICE(0x0c52, 0xa064) }, /* SeaLevel Systems, Inc. */ 65 + { USB_DEVICE(0x0403, 0x6988), /* FTDI, assigned to Bryx */ 66 + .driver_info = (kernel_ulong_t)&bryx_brik_quirk}, 62 67 { } /* Terminating entry */ 63 68 }; 64 69 ··· 193 160 return buf; 194 161 } 195 162 163 + static int mpsse_ensure_supported(struct gpio_chip *chip, 164 + unsigned long mask, int direction) 165 + { 166 + unsigned long supported, unsupported; 167 + char *type = "input"; 168 + struct mpsse_priv *priv = gpiochip_get_data(chip); 169 + 170 + supported = priv->dir_in; 171 + if (direction == GPIO_LINE_DIRECTION_OUT) { 172 + supported = priv->dir_out; 173 + type = "output"; 174 + } 175 + 176 + /* An invalid bit was in the provided mask */ 177 + unsupported = mask & ~supported; 178 + if (unsupported) { 179 + dev_err(&priv->udev->dev, 180 + "mpsse: GPIO %lu doesn't support %s\n", 181 + find_first_bit(&unsupported, sizeof(unsupported) * 8), 182 + type); 183 + return -EOPNOTSUPP; 184 + } 185 + 186 + return 0; 187 + } 188 + 196 189 static int gpio_mpsse_set_multiple(struct gpio_chip *chip, unsigned long *mask, 197 190 unsigned long *bits) 198 191 { 199 192 unsigned long i, bank, bank_mask, bank_bits; 200 193 int ret; 201 194 struct mpsse_priv *priv = gpiochip_get_data(chip); 195 + 196 + ret = mpsse_ensure_supported(chip, *mask, GPIO_LINE_DIRECTION_OUT); 197 + if (ret) 198 + return ret; 202 199 203 200 guard(mutex)(&priv->io_mutex); 204 201 for_each_set_clump8(i, bank_mask, mask, chip->ngpio) { ··· 256 193 unsigned long i, bank, bank_mask; 257 194 int ret; 258 195 struct mpsse_priv *priv = gpiochip_get_data(chip); 196 + 197 + ret = mpsse_ensure_supported(chip, *mask, GPIO_LINE_DIRECTION_IN); 198 + if (ret) 199 + return ret; 259 200 260 201 guard(mutex)(&priv->io_mutex); 261 202 for_each_set_clump8(i, bank_mask, mask, chip->ngpio) { ··· 309 242 static int gpio_mpsse_direction_output(struct gpio_chip *chip, 310 243 unsigned int offset, int value) 311 244 { 245 + int ret; 312 246 struct mpsse_priv *priv = gpiochip_get_data(chip); 313 247 int bank = (offset & 8) >> 3; 314 248 int bank_offset = offset & 7; 249 + 250 + ret = mpsse_ensure_supported(chip, BIT(offset), GPIO_LINE_DIRECTION_OUT); 251 + if (ret) 252 + return ret; 315 253 316 254 scoped_guard(mutex, &priv->io_mutex) 317 255 priv->gpio_dir[bank] |= BIT(bank_offset); ··· 327 255 static int gpio_mpsse_direction_input(struct gpio_chip *chip, 328 256 unsigned int offset) 329 257 { 258 + int ret; 330 259 struct mpsse_priv *priv = gpiochip_get_data(chip); 331 260 int bank = (offset & 8) >> 3; 332 261 int bank_offset = offset & 7; 333 262 263 + ret = mpsse_ensure_supported(chip, BIT(offset), GPIO_LINE_DIRECTION_IN); 264 + if (ret) 265 + return ret; 266 + 334 267 guard(mutex)(&priv->io_mutex); 335 268 priv->gpio_dir[bank] &= ~BIT(bank_offset); 336 - gpio_mpsse_set_bank(priv, bank); 337 269 338 - return 0; 270 + return gpio_mpsse_set_bank(priv, bank); 339 271 } 340 272 341 273 static int gpio_mpsse_get_direction(struct gpio_chip *chip, ··· 360 284 return ret; 361 285 } 362 286 363 - static void gpio_mpsse_poll(struct work_struct *work) 287 + /* 288 + * Stops all workers except `my_worker`. 289 + * Safe to call only when `irq_race` is held. 290 + */ 291 + static void gpio_mpsse_stop_all_except(struct mpsse_priv *priv, 292 + struct mpsse_worker *my_worker) 293 + { 294 + struct mpsse_worker *worker, *worker_tmp; 295 + struct list_head destructors = LIST_HEAD_INIT(destructors); 296 + 297 + scoped_guard(raw_spinlock_irqsave, &priv->irq_spin) { 298 + list_for_each_entry_safe(worker, worker_tmp, 299 + &priv->workers, list) { 300 + /* Don't stop ourselves */ 301 + if (worker == my_worker) 302 + continue; 303 + 304 + list_del(&worker->list); 305 + 306 + /* Give worker a chance to terminate itself */ 307 + atomic_set(&worker->cancelled, 1); 308 + /* Keep track of stuff to cancel */ 309 + INIT_LIST_HEAD(&worker->destroy); 310 + list_add(&worker->destroy, &destructors); 311 + } 312 + } 313 + 314 + list_for_each_entry_safe(worker, worker_tmp, 315 + &destructors, destroy) { 316 + list_del(&worker->destroy); 317 + cancel_work_sync(&worker->work); 318 + kfree(worker); 319 + } 320 + } 321 + 322 + static void gpio_mpsse_poll(struct work_struct *my_work) 364 323 { 365 324 unsigned long pin_mask, pin_states, flags; 366 325 int irq_enabled, offset, err, value, fire_irq, 367 326 irq, old_value[16], irq_type[16]; 368 - struct mpsse_priv *priv = container_of(work, struct mpsse_priv, 369 - irq_work); 327 + struct mpsse_worker *my_worker = container_of(my_work, struct mpsse_worker, work); 328 + struct mpsse_priv *priv = my_worker->priv; 370 329 371 330 for (offset = 0; offset < priv->gpio.ngpio; ++offset) 372 331 old_value[offset] = -1; 373 332 374 - while ((irq_enabled = atomic_read(&priv->irq_enabled))) { 333 + /* 334 + * We only want one worker. Workers race to acquire irq_race and tear 335 + * down all other workers. This is a cond guard so that we don't deadlock 336 + * trying to cancel a worker. 337 + */ 338 + scoped_cond_guard(mutex_try, return, &priv->irq_race) 339 + gpio_mpsse_stop_all_except(priv, my_worker); 340 + 341 + while ((irq_enabled = atomic_read(&priv->irq_enabled)) && 342 + !atomic_read(&my_worker->cancelled)) { 375 343 usleep_range(MPSSE_POLL_INTERVAL, MPSSE_POLL_INTERVAL + 1000); 376 344 /* Cleanup will trigger at the end of the loop */ 377 345 guard(mutex)(&priv->irq_mutex); ··· 490 370 491 371 static void gpio_mpsse_irq_disable(struct irq_data *irqd) 492 372 { 373 + struct mpsse_worker *worker; 493 374 struct mpsse_priv *priv = irq_data_get_irq_chip_data(irqd); 494 375 495 376 atomic_and(~BIT(irqd->hwirq), &priv->irq_enabled); 496 377 gpiochip_disable_irq(&priv->gpio, irqd->hwirq); 378 + 379 + /* 380 + * Can't actually do teardown in IRQ context (it blocks). 381 + * As a result, these workers will stick around until irq is reenabled 382 + * or device gets disconnected 383 + */ 384 + scoped_guard(raw_spinlock_irqsave, &priv->irq_spin) 385 + list_for_each_entry(worker, &priv->workers, list) 386 + atomic_set(&worker->cancelled, 1); 497 387 } 498 388 499 389 static void gpio_mpsse_irq_enable(struct irq_data *irqd) 500 390 { 391 + struct mpsse_worker *worker; 501 392 struct mpsse_priv *priv = irq_data_get_irq_chip_data(irqd); 502 393 503 394 gpiochip_enable_irq(&priv->gpio, irqd->hwirq); 504 395 /* If no-one else was using the IRQ, enable it */ 505 396 if (!atomic_fetch_or(BIT(irqd->hwirq), &priv->irq_enabled)) { 506 - INIT_WORK(&priv->irq_work, gpio_mpsse_poll); 507 - schedule_work(&priv->irq_work); 397 + /* 398 + * Can't be devm because it uses a non-raw spinlock (illegal in 399 + * this context, where a raw spinlock is held by our caller) 400 + */ 401 + worker = kzalloc(sizeof(*worker), GFP_NOWAIT); 402 + if (!worker) 403 + return; 404 + 405 + worker->priv = priv; 406 + INIT_LIST_HEAD(&worker->list); 407 + INIT_WORK(&worker->work, gpio_mpsse_poll); 408 + schedule_work(&worker->work); 409 + 410 + scoped_guard(raw_spinlock_irqsave, &priv->irq_spin) 411 + list_add(&worker->list, &priv->workers); 508 412 } 509 413 } 510 414 ··· 548 404 ida_free(&gpio_mpsse_ida, priv->id); 549 405 } 550 406 407 + static int mpsse_init_valid_mask(struct gpio_chip *chip, 408 + unsigned long *valid_mask, 409 + unsigned int ngpios) 410 + { 411 + struct mpsse_priv *priv = gpiochip_get_data(chip); 412 + 413 + if (WARN_ON(priv == NULL)) 414 + return -ENODEV; 415 + 416 + *valid_mask = priv->dir_in | priv->dir_out; 417 + 418 + return 0; 419 + } 420 + 421 + static void mpsse_irq_init_valid_mask(struct gpio_chip *chip, 422 + unsigned long *valid_mask, 423 + unsigned int ngpios) 424 + { 425 + struct mpsse_priv *priv = gpiochip_get_data(chip); 426 + 427 + if (WARN_ON(priv == NULL)) 428 + return; 429 + 430 + /* Can only use IRQ on input capable pins */ 431 + *valid_mask = priv->dir_in; 432 + } 433 + 551 434 static int gpio_mpsse_probe(struct usb_interface *interface, 552 435 const struct usb_device_id *id) 553 436 { 554 437 struct mpsse_priv *priv; 555 438 struct device *dev; 439 + char *serial; 556 440 int err; 441 + struct mpsse_quirk *quirk = (void *)id->driver_info; 557 442 558 443 dev = &interface->dev; 559 444 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 560 445 if (!priv) 561 446 return -ENOMEM; 447 + 448 + INIT_LIST_HEAD(&priv->workers); 562 449 563 450 priv->udev = usb_get_dev(interface_to_usbdev(interface)); 564 451 priv->intf = interface; ··· 611 436 if (err) 612 437 return err; 613 438 439 + err = devm_mutex_init(dev, &priv->irq_race); 440 + if (err) 441 + return err; 442 + 443 + raw_spin_lock_init(&priv->irq_spin); 444 + 445 + serial = priv->udev->serial; 446 + if (!serial) 447 + serial = "NONE"; 448 + 614 449 priv->gpio.label = devm_kasprintf(dev, GFP_KERNEL, 615 - "gpio-mpsse.%d.%d", 616 - priv->id, priv->intf_id); 450 + "MPSSE%04x:%04x.%d.%d.%s", 451 + id->idVendor, id->idProduct, 452 + priv->intf_id, priv->id, 453 + serial); 617 454 if (!priv->gpio.label) 618 455 return -ENOMEM; 619 456 ··· 639 452 priv->gpio.get_multiple = gpio_mpsse_get_multiple; 640 453 priv->gpio.set_multiple = gpio_mpsse_set_multiple; 641 454 priv->gpio.base = -1; 642 - priv->gpio.ngpio = 16; 455 + priv->gpio.ngpio = MPSSE_NGPIO; 643 456 priv->gpio.offset = priv->intf_id * priv->gpio.ngpio; 644 457 priv->gpio.can_sleep = 1; 458 + 459 + if (quirk) { 460 + priv->dir_out = quirk->dir_out; 461 + priv->dir_in = quirk->dir_in; 462 + priv->gpio.names = quirk->names; 463 + priv->gpio.init_valid_mask = mpsse_init_valid_mask; 464 + } else { 465 + priv->dir_in = U16_MAX; 466 + priv->dir_out = U16_MAX; 467 + } 645 468 646 469 err = usb_find_common_endpoints(interface->cur_altsetting, 647 470 &priv->bulk_in, &priv->bulk_out, ··· 691 494 priv->gpio.irq.parents = NULL; 692 495 priv->gpio.irq.default_type = IRQ_TYPE_NONE; 693 496 priv->gpio.irq.handler = handle_simple_irq; 497 + priv->gpio.irq.init_valid_mask = mpsse_irq_init_valid_mask; 694 498 695 499 err = devm_gpiochip_add_data(dev, &priv->gpio, priv); 696 500 if (err) ··· 703 505 static void gpio_mpsse_disconnect(struct usb_interface *intf) 704 506 { 705 507 struct mpsse_priv *priv = usb_get_intfdata(intf); 508 + 509 + /* 510 + * Lock prevents double-free of worker from here and the teardown 511 + * step at the beginning of gpio_mpsse_poll 512 + */ 513 + scoped_guard(mutex, &priv->irq_race) 514 + gpio_mpsse_stop_all_except(priv, NULL); 706 515 707 516 priv->intf = NULL; 708 517 usb_set_intfdata(intf, NULL);
+4 -4
drivers/gpio/gpio-msc313.c
··· 694 694 * SoC goes into suspend to memory mode so we need to save some 695 695 * of the register bits before suspending and put it back when resuming 696 696 */ 697 - static int __maybe_unused msc313_gpio_suspend(struct device *dev) 697 + static int msc313_gpio_suspend(struct device *dev) 698 698 { 699 699 struct msc313_gpio *gpio = dev_get_drvdata(dev); 700 700 int i; ··· 705 705 return 0; 706 706 } 707 707 708 - static int __maybe_unused msc313_gpio_resume(struct device *dev) 708 + static int msc313_gpio_resume(struct device *dev) 709 709 { 710 710 struct msc313_gpio *gpio = dev_get_drvdata(dev); 711 711 int i; ··· 716 716 return 0; 717 717 } 718 718 719 - static SIMPLE_DEV_PM_OPS(msc313_gpio_ops, msc313_gpio_suspend, msc313_gpio_resume); 719 + static DEFINE_SIMPLE_DEV_PM_OPS(msc313_gpio_ops, msc313_gpio_suspend, msc313_gpio_resume); 720 720 721 721 static struct platform_driver msc313_gpio_driver = { 722 722 .driver = { 723 723 .name = DRIVER_NAME, 724 724 .of_match_table = msc313_gpio_of_match, 725 - .pm = &msc313_gpio_ops, 725 + .pm = pm_sleep_ptr(&msc313_gpio_ops), 726 726 }, 727 727 .probe = msc313_gpio_probe, 728 728 };
+1 -2
drivers/gpio/gpio-mvebu.c
··· 573 573 for (i = 0; i < mvchip->chip.ngpio; i++) { 574 574 int irq; 575 575 576 - irq = irq_find_mapping(mvchip->domain, i); 577 - 578 576 if (!(cause & BIT(i))) 579 577 continue; 580 578 579 + irq = irq_find_mapping(mvchip->domain, i); 581 580 type = irq_get_trigger_type(irq); 582 581 if ((type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) { 583 582 /* Swap polarity (race with GPIO line) */
+7 -8
drivers/gpio/gpio-omap.c
··· 1503 1503 clk_unprepare(bank->dbck); 1504 1504 } 1505 1505 1506 - static int __maybe_unused omap_gpio_runtime_suspend(struct device *dev) 1506 + static int omap_gpio_runtime_suspend(struct device *dev) 1507 1507 { 1508 1508 struct gpio_bank *bank = dev_get_drvdata(dev); 1509 1509 unsigned long flags; ··· 1516 1516 return 0; 1517 1517 } 1518 1518 1519 - static int __maybe_unused omap_gpio_runtime_resume(struct device *dev) 1519 + static int omap_gpio_runtime_resume(struct device *dev) 1520 1520 { 1521 1521 struct gpio_bank *bank = dev_get_drvdata(dev); 1522 1522 unsigned long flags; ··· 1529 1529 return 0; 1530 1530 } 1531 1531 1532 - static int __maybe_unused omap_gpio_suspend(struct device *dev) 1532 + static int omap_gpio_suspend(struct device *dev) 1533 1533 { 1534 1534 struct gpio_bank *bank = dev_get_drvdata(dev); 1535 1535 ··· 1541 1541 return omap_gpio_runtime_suspend(dev); 1542 1542 } 1543 1543 1544 - static int __maybe_unused omap_gpio_resume(struct device *dev) 1544 + static int omap_gpio_resume(struct device *dev) 1545 1545 { 1546 1546 struct gpio_bank *bank = dev_get_drvdata(dev); 1547 1547 ··· 1554 1554 } 1555 1555 1556 1556 static const struct dev_pm_ops gpio_pm_ops = { 1557 - SET_RUNTIME_PM_OPS(omap_gpio_runtime_suspend, omap_gpio_runtime_resume, 1558 - NULL) 1559 - SET_LATE_SYSTEM_SLEEP_PM_OPS(omap_gpio_suspend, omap_gpio_resume) 1557 + RUNTIME_PM_OPS(omap_gpio_runtime_suspend, omap_gpio_runtime_resume, NULL) 1558 + LATE_SYSTEM_SLEEP_PM_OPS(omap_gpio_suspend, omap_gpio_resume) 1560 1559 }; 1561 1560 1562 1561 static struct platform_driver omap_gpio_driver = { ··· 1563 1564 .remove = omap_gpio_remove, 1564 1565 .driver = { 1565 1566 .name = "omap_gpio", 1566 - .pm = &gpio_pm_ops, 1567 + .pm = pm_ptr(&gpio_pm_ops), 1567 1568 .of_match_table = omap_gpio_match, 1568 1569 }, 1569 1570 };
+8 -5
drivers/gpio/gpio-pca953x.c
··· 306 306 * Interrupt mask register 0x40 + 5 * bank_size RW 307 307 * Interrupt status register 0x40 + 6 * bank_size R 308 308 * 309 - * - Registers with bit 0x80 set, the AI bit 309 + * - Registers with bit 0x80 set, the AI bit (auto increment) 310 310 * The bit is cleared and the registers fall into one of the 311 311 * categories above. 312 312 */ ··· 854 854 int level; 855 855 856 856 if (chip->driver_data & PCA_PCAL) { 857 + DECLARE_BITMAP(latched_inputs, MAX_LINE); 857 858 guard(mutex)(&chip->i2c_lock); 858 859 859 - /* Enable latch on interrupt-enabled inputs */ 860 - pca953x_write_regs(chip, PCAL953X_IN_LATCH, chip->irq_mask); 860 + /* Enable latch on edge-triggered interrupt-enabled inputs */ 861 + bitmap_or(latched_inputs, chip->irq_trig_fall, chip->irq_trig_raise, gc->ngpio); 862 + bitmap_and(latched_inputs, latched_inputs, chip->irq_mask, gc->ngpio); 863 + pca953x_write_regs(chip, PCAL953X_IN_LATCH, latched_inputs); 861 864 862 865 bitmap_complement(irq_mask, chip->irq_mask, gc->ngpio); 863 866 ··· 1206 1203 pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK); 1207 1204 1208 1205 if (NBANK(chip) > 2 || PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) { 1209 - dev_info(dev, "using AI\n"); 1206 + dev_info(dev, "using auto increment\n"); 1210 1207 regmap_config = &pca953x_ai_i2c_regmap; 1211 1208 } else { 1212 - dev_info(dev, "using no AI\n"); 1209 + dev_info(dev, "using no auto increment\n"); 1213 1210 regmap_config = &pca953x_i2c_regmap; 1214 1211 } 1215 1212
+6 -6
drivers/gpio/gpio-pch.c
··· 171 171 /* 172 172 * Save register configuration and disable interrupts. 173 173 */ 174 - static void __maybe_unused pch_gpio_save_reg_conf(struct pch_gpio *chip) 174 + static void pch_gpio_save_reg_conf(struct pch_gpio *chip) 175 175 { 176 176 chip->pch_gpio_reg.ien_reg = ioread32(&chip->reg->ien); 177 177 chip->pch_gpio_reg.imask_reg = ioread32(&chip->reg->imask); ··· 187 187 /* 188 188 * This function restores the register configuration of the GPIO device. 189 189 */ 190 - static void __maybe_unused pch_gpio_restore_reg_conf(struct pch_gpio *chip) 190 + static void pch_gpio_restore_reg_conf(struct pch_gpio *chip) 191 191 { 192 192 iowrite32(chip->pch_gpio_reg.ien_reg, &chip->reg->ien); 193 193 iowrite32(chip->pch_gpio_reg.imask_reg, &chip->reg->imask); ··· 402 402 return pch_gpio_alloc_generic_chip(chip, irq_base, gpio_pins[chip->ioh]); 403 403 } 404 404 405 - static int __maybe_unused pch_gpio_suspend(struct device *dev) 405 + static int pch_gpio_suspend(struct device *dev) 406 406 { 407 407 struct pch_gpio *chip = dev_get_drvdata(dev); 408 408 unsigned long flags; ··· 414 414 return 0; 415 415 } 416 416 417 - static int __maybe_unused pch_gpio_resume(struct device *dev) 417 + static int pch_gpio_resume(struct device *dev) 418 418 { 419 419 struct pch_gpio *chip = dev_get_drvdata(dev); 420 420 unsigned long flags; ··· 428 428 return 0; 429 429 } 430 430 431 - static SIMPLE_DEV_PM_OPS(pch_gpio_pm_ops, pch_gpio_suspend, pch_gpio_resume); 431 + static DEFINE_SIMPLE_DEV_PM_OPS(pch_gpio_pm_ops, pch_gpio_suspend, pch_gpio_resume); 432 432 433 433 static const struct pci_device_id pch_gpio_pcidev_id[] = { 434 434 { PCI_DEVICE_DATA(INTEL, EG20T_PCH, INTEL_EG20T_PCH) }, ··· 444 444 .id_table = pch_gpio_pcidev_id, 445 445 .probe = pch_gpio_probe, 446 446 .driver = { 447 - .pm = &pch_gpio_pm_ops, 447 + .pm = pm_sleep_ptr(&pch_gpio_pm_ops), 448 448 }, 449 449 }; 450 450
+2 -15
drivers/gpio/gpio-pl061.c
··· 37 37 38 38 #define PL061_GPIO_NR 8 39 39 40 - #ifdef CONFIG_PM 41 40 struct pl061_context_save_regs { 42 41 u8 gpio_data; 43 42 u8 gpio_dir; ··· 45 46 u8 gpio_iev; 46 47 u8 gpio_ie; 47 48 }; 48 - #endif 49 49 50 50 struct pl061 { 51 51 raw_spinlock_t lock; ··· 53 55 struct gpio_chip gc; 54 56 int parent_irq; 55 57 56 - #ifdef CONFIG_PM 57 58 struct pl061_context_save_regs csave_regs; 58 - #endif 59 59 }; 60 60 61 61 static int pl061_get_direction(struct gpio_chip *gc, unsigned offset) ··· 363 367 return 0; 364 368 } 365 369 366 - #ifdef CONFIG_PM 367 370 static int pl061_suspend(struct device *dev) 368 371 { 369 372 struct pl061 *pl061 = dev_get_drvdata(dev); ··· 406 411 return 0; 407 412 } 408 413 409 - static const struct dev_pm_ops pl061_dev_pm_ops = { 410 - .suspend = pl061_suspend, 411 - .resume = pl061_resume, 412 - .freeze = pl061_suspend, 413 - .restore = pl061_resume, 414 - }; 415 - #endif 414 + static DEFINE_SIMPLE_DEV_PM_OPS(pl061_dev_pm_ops, pl061_suspend, pl061_resume); 416 415 417 416 static const struct amba_id pl061_ids[] = { 418 417 { ··· 420 431 static struct amba_driver pl061_gpio_driver = { 421 432 .drv = { 422 433 .name = "pl061_gpio", 423 - #ifdef CONFIG_PM 424 - .pm = &pl061_dev_pm_ops, 425 - #endif 434 + .pm = pm_sleep_ptr(&pl061_dev_pm_ops), 426 435 }, 427 436 .id_table = pl061_ids, 428 437 .probe = pl061_probe,
+111
drivers/gpio/gpio-qixis-fpga.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Layerscape GPIO QIXIS FPGA driver 4 + * 5 + * Copyright 2025 NXP 6 + */ 7 + 8 + #include <linux/device.h> 9 + #include <linux/gpio/driver.h> 10 + #include <linux/gpio/regmap.h> 11 + #include <linux/kernel.h> 12 + #include <linux/mod_devicetable.h> 13 + #include <linux/module.h> 14 + #include <linux/platform_device.h> 15 + #include <linux/regmap.h> 16 + 17 + struct qixis_cpld_gpio_config { 18 + u64 output_lines; 19 + }; 20 + 21 + static const struct qixis_cpld_gpio_config lx2160ardb_sfp_cfg = { 22 + .output_lines = BIT(0), 23 + }; 24 + 25 + static const struct qixis_cpld_gpio_config ls1046aqds_stat_pres2_cfg = { 26 + .output_lines = 0x0, 27 + }; 28 + 29 + static const struct regmap_config regmap_config_8r_8v = { 30 + .reg_bits = 8, 31 + .val_bits = 8, 32 + }; 33 + 34 + static int qixis_cpld_gpio_probe(struct platform_device *pdev) 35 + { 36 + DECLARE_BITMAP(fixed_direction_output, 8); 37 + const struct qixis_cpld_gpio_config *cfg; 38 + struct gpio_regmap_config config = {0}; 39 + struct regmap *regmap; 40 + void __iomem *reg; 41 + u32 base; 42 + int ret; 43 + 44 + if (!pdev->dev.parent) 45 + return -ENODEV; 46 + 47 + cfg = device_get_match_data(&pdev->dev); 48 + 49 + ret = device_property_read_u32(&pdev->dev, "reg", &base); 50 + if (ret) 51 + return ret; 52 + 53 + regmap = dev_get_regmap(pdev->dev.parent, NULL); 54 + if (!regmap) { 55 + /* In case there is no regmap configured by the parent device, 56 + * create our own from the MMIO space. 57 + */ 58 + reg = devm_platform_ioremap_resource(pdev, 0); 59 + if (IS_ERR(reg)) 60 + return PTR_ERR(reg); 61 + 62 + regmap = devm_regmap_init_mmio(&pdev->dev, reg, &regmap_config_8r_8v); 63 + if (!regmap) 64 + return -ENODEV; 65 + 66 + /* In this case, the offset of our register is 0 inside the 67 + * regmap area that we just created. 68 + */ 69 + base = 0; 70 + } 71 + config.reg_dat_base = GPIO_REGMAP_ADDR(base); 72 + config.reg_set_base = GPIO_REGMAP_ADDR(base); 73 + 74 + config.drvdata = (void *)cfg; 75 + config.regmap = regmap; 76 + config.parent = &pdev->dev; 77 + config.ngpio_per_reg = 8; 78 + config.ngpio = 8; 79 + 80 + bitmap_from_u64(fixed_direction_output, cfg->output_lines); 81 + config.fixed_direction_output = fixed_direction_output; 82 + 83 + return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(&pdev->dev, &config)); 84 + } 85 + 86 + static const struct of_device_id qixis_cpld_gpio_of_match[] = { 87 + { 88 + .compatible = "fsl,lx2160ardb-fpga-gpio-sfp", 89 + .data = &lx2160ardb_sfp_cfg, 90 + }, 91 + { 92 + .compatible = "fsl,ls1046aqds-fpga-gpio-stat-pres2", 93 + .data = &ls1046aqds_stat_pres2_cfg, 94 + }, 95 + 96 + {} 97 + }; 98 + MODULE_DEVICE_TABLE(of, qixis_cpld_gpio_of_match); 99 + 100 + static struct platform_driver qixis_cpld_gpio_driver = { 101 + .probe = qixis_cpld_gpio_probe, 102 + .driver = { 103 + .name = "gpio-qixis-cpld", 104 + .of_match_table = qixis_cpld_gpio_of_match, 105 + }, 106 + }; 107 + module_platform_driver(qixis_cpld_gpio_driver); 108 + 109 + MODULE_LICENSE("GPL"); 110 + MODULE_AUTHOR("Ioana Ciornei <ioana.ciornei@nxp.com>"); 111 + MODULE_DESCRIPTION("Layerscape GPIO QIXIS FPGA driver");
+14 -4
drivers/gpio/gpio-regmap.c
··· 82 82 if (ret) 83 83 return ret; 84 84 85 - ret = regmap_read(gpio->regmap, reg, &val); 85 + /* ensure we don't spoil any register cache with pin input values */ 86 + if (gpio->reg_dat_base == gpio->reg_set_base) 87 + ret = regmap_read_bypassed(gpio->regmap, reg, &val); 88 + else 89 + ret = regmap_read(gpio->regmap, reg, &val); 86 90 if (ret) 87 91 return ret; 88 92 ··· 98 94 { 99 95 struct gpio_regmap *gpio = gpiochip_get_data(chip); 100 96 unsigned int base = gpio_regmap_addr(gpio->reg_set_base); 101 - unsigned int reg, mask; 97 + unsigned int reg, mask, mask_val; 102 98 int ret; 103 99 104 100 ret = gpio->reg_mask_xlate(gpio, base, offset, &reg, &mask); ··· 106 102 return ret; 107 103 108 104 if (val) 109 - ret = regmap_update_bits(gpio->regmap, reg, mask, mask); 105 + mask_val = mask; 110 106 else 111 - ret = regmap_update_bits(gpio->regmap, reg, mask, 0); 107 + mask_val = 0; 108 + 109 + /* ignore input values which shadow the old output value */ 110 + if (gpio->reg_dat_base == gpio->reg_set_base) 111 + ret = regmap_write_bits(gpio->regmap, reg, mask, mask_val); 112 + else 113 + ret = regmap_update_bits(gpio->regmap, reg, mask, mask_val); 112 114 113 115 return ret; 114 116 }
+1
drivers/gpio/gpio-shared-proxy.c
··· 322 322 static struct auxiliary_driver gpio_shared_proxy_driver = { 323 323 .driver = { 324 324 .name = "gpio-shared-proxy", 325 + .suppress_bind_attrs = true, 325 326 }, 326 327 .probe = gpio_shared_proxy_probe, 327 328 .id_table = gpio_shared_proxy_id_table,
+109 -65
drivers/gpio/gpio-tegra186.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 /* 3 - * Copyright (c) 2016-2022 NVIDIA Corporation 3 + * Copyright (c) 2016-2025 NVIDIA Corporation 4 4 * 5 5 * Author: Thierry Reding <treding@nvidia.com> 6 6 * Dipen Patel <dpatel@nvidia.com> ··· 69 69 70 70 #define TEGRA186_GPIO_INTERRUPT_STATUS(x) (0x100 + (x) * 4) 71 71 72 + /* Tegra410 GPIOs implemented by the COMPUTE GPIO controller */ 73 + #define TEGRA410_COMPUTE_GPIO_PORT_A 0 74 + #define TEGRA410_COMPUTE_GPIO_PORT_B 1 75 + #define TEGRA410_COMPUTE_GPIO_PORT_C 2 76 + #define TEGRA410_COMPUTE_GPIO_PORT_D 3 77 + #define TEGRA410_COMPUTE_GPIO_PORT_E 4 78 + 79 + /* Tegra410 GPIOs implemented by the SYSTEM GPIO controller */ 80 + #define TEGRA410_SYSTEM_GPIO_PORT_A 0 81 + #define TEGRA410_SYSTEM_GPIO_PORT_B 1 82 + #define TEGRA410_SYSTEM_GPIO_PORT_C 2 83 + #define TEGRA410_SYSTEM_GPIO_PORT_D 3 84 + #define TEGRA410_SYSTEM_GPIO_PORT_E 4 85 + #define TEGRA410_SYSTEM_GPIO_PORT_I 5 86 + #define TEGRA410_SYSTEM_GPIO_PORT_J 6 87 + #define TEGRA410_SYSTEM_GPIO_PORT_K 7 88 + #define TEGRA410_SYSTEM_GPIO_PORT_L 8 89 + #define TEGRA410_SYSTEM_GPIO_PORT_M 9 90 + #define TEGRA410_SYSTEM_GPIO_PORT_N 10 91 + #define TEGRA410_SYSTEM_GPIO_PORT_P 11 92 + #define TEGRA410_SYSTEM_GPIO_PORT_Q 12 93 + #define TEGRA410_SYSTEM_GPIO_PORT_R 13 94 + #define TEGRA410_SYSTEM_GPIO_PORT_V 14 95 + 72 96 struct tegra_gpio_port { 73 97 const char *name; 74 98 unsigned int bank; ··· 109 85 const struct tegra_gpio_port *ports; 110 86 unsigned int num_ports; 111 87 const char *name; 88 + const char *prefix; 112 89 unsigned int instance; 113 90 114 91 unsigned int num_irqs_per_bank; ··· 941 916 char *name; 942 917 943 918 for (j = 0; j < port->pins; j++) { 944 - name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, 945 - "P%s.%02x", port->name, j); 919 + if (gpio->soc->prefix) 920 + name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "%s-P%s.%02x", 921 + gpio->soc->prefix, port->name, j); 922 + else 923 + name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL, "P%s.%02x", 924 + port->name, j); 946 925 if (!name) 947 926 return -ENOMEM; 948 927 ··· 1031 1002 return devm_gpiochip_add_data(&pdev->dev, &gpio->gpio, gpio); 1032 1003 } 1033 1004 1034 - #define TEGRA186_MAIN_GPIO_PORT(_name, _bank, _port, _pins) \ 1035 - [TEGRA186_MAIN_GPIO_PORT_##_name] = { \ 1036 - .name = #_name, \ 1037 - .bank = _bank, \ 1038 - .port = _port, \ 1039 - .pins = _pins, \ 1005 + #define TEGRA_GPIO_PORT(_prefix, _name, _bank, _port, _pins) \ 1006 + [_prefix##_GPIO_PORT_##_name] = { \ 1007 + .name = #_name, \ 1008 + .bank = _bank, \ 1009 + .port = _port, \ 1010 + .pins = _pins, \ 1040 1011 } 1012 + 1013 + #define TEGRA186_MAIN_GPIO_PORT(_name, _bank, _port, _pins) \ 1014 + TEGRA_GPIO_PORT(TEGRA186_MAIN, _name, _bank, _port, _pins) 1041 1015 1042 1016 static const struct tegra_gpio_port tegra186_main_ports[] = { 1043 1017 TEGRA186_MAIN_GPIO_PORT( A, 2, 0, 7), ··· 1077 1045 .has_vm_support = false, 1078 1046 }; 1079 1047 1080 - #define TEGRA186_AON_GPIO_PORT(_name, _bank, _port, _pins) \ 1081 - [TEGRA186_AON_GPIO_PORT_##_name] = { \ 1082 - .name = #_name, \ 1083 - .bank = _bank, \ 1084 - .port = _port, \ 1085 - .pins = _pins, \ 1086 - } 1048 + #define TEGRA186_AON_GPIO_PORT(_name, _bank, _port, _pins) \ 1049 + TEGRA_GPIO_PORT(TEGRA186_AON, _name, _bank, _port, _pins) 1087 1050 1088 1051 static const struct tegra_gpio_port tegra186_aon_ports[] = { 1089 1052 TEGRA186_AON_GPIO_PORT( S, 0, 1, 5), ··· 1100 1073 .has_vm_support = false, 1101 1074 }; 1102 1075 1103 - #define TEGRA194_MAIN_GPIO_PORT(_name, _bank, _port, _pins) \ 1104 - [TEGRA194_MAIN_GPIO_PORT_##_name] = { \ 1105 - .name = #_name, \ 1106 - .bank = _bank, \ 1107 - .port = _port, \ 1108 - .pins = _pins, \ 1109 - } 1076 + #define TEGRA194_MAIN_GPIO_PORT(_name, _bank, _port, _pins) \ 1077 + TEGRA_GPIO_PORT(TEGRA194_MAIN, _name, _bank, _port, _pins) 1110 1078 1111 1079 static const struct tegra_gpio_port tegra194_main_ports[] = { 1112 1080 TEGRA194_MAIN_GPIO_PORT( A, 1, 2, 8), ··· 1151 1129 .has_vm_support = true, 1152 1130 }; 1153 1131 1154 - #define TEGRA194_AON_GPIO_PORT(_name, _bank, _port, _pins) \ 1155 - [TEGRA194_AON_GPIO_PORT_##_name] = { \ 1156 - .name = #_name, \ 1157 - .bank = _bank, \ 1158 - .port = _port, \ 1159 - .pins = _pins, \ 1160 - } 1132 + #define TEGRA194_AON_GPIO_PORT(_name, _bank, _port, _pins) \ 1133 + TEGRA_GPIO_PORT(TEGRA194_AON, _name, _bank, _port, _pins) 1161 1134 1162 1135 static const struct tegra_gpio_port tegra194_aon_ports[] = { 1163 1136 TEGRA194_AON_GPIO_PORT(AA, 0, 3, 8), ··· 1172 1155 .has_vm_support = false, 1173 1156 }; 1174 1157 1175 - #define TEGRA234_MAIN_GPIO_PORT(_name, _bank, _port, _pins) \ 1176 - [TEGRA234_MAIN_GPIO_PORT_##_name] = { \ 1177 - .name = #_name, \ 1178 - .bank = _bank, \ 1179 - .port = _port, \ 1180 - .pins = _pins, \ 1181 - } 1158 + #define TEGRA234_MAIN_GPIO_PORT(_name, _bank, _port, _pins) \ 1159 + TEGRA_GPIO_PORT(TEGRA234_MAIN, _name, _bank, _port, _pins) 1182 1160 1183 1161 static const struct tegra_gpio_port tegra234_main_ports[] = { 1184 1162 TEGRA234_MAIN_GPIO_PORT( A, 0, 0, 8), ··· 1212 1200 .has_vm_support = true, 1213 1201 }; 1214 1202 1215 - #define TEGRA234_AON_GPIO_PORT(_name, _bank, _port, _pins) \ 1216 - [TEGRA234_AON_GPIO_PORT_##_name] = { \ 1217 - .name = #_name, \ 1218 - .bank = _bank, \ 1219 - .port = _port, \ 1220 - .pins = _pins, \ 1221 - } 1203 + #define TEGRA234_AON_GPIO_PORT(_name, _bank, _port, _pins) \ 1204 + TEGRA_GPIO_PORT(TEGRA234_AON, _name, _bank, _port, _pins) 1222 1205 1223 1206 static const struct tegra_gpio_port tegra234_aon_ports[] = { 1224 1207 TEGRA234_AON_GPIO_PORT(AA, 0, 4, 8), ··· 1234 1227 .has_vm_support = false, 1235 1228 }; 1236 1229 1237 - #define TEGRA241_MAIN_GPIO_PORT(_name, _bank, _port, _pins) \ 1238 - [TEGRA241_MAIN_GPIO_PORT_##_name] = { \ 1239 - .name = #_name, \ 1240 - .bank = _bank, \ 1241 - .port = _port, \ 1242 - .pins = _pins, \ 1243 - } 1230 + #define TEGRA241_MAIN_GPIO_PORT(_name, _bank, _port, _pins) \ 1231 + TEGRA_GPIO_PORT(TEGRA241_MAIN, _name, _bank, _port, _pins) 1244 1232 1245 1233 static const struct tegra_gpio_port tegra241_main_ports[] = { 1246 1234 TEGRA241_MAIN_GPIO_PORT(A, 0, 0, 8), ··· 1260 1258 .has_vm_support = false, 1261 1259 }; 1262 1260 1263 - #define TEGRA241_AON_GPIO_PORT(_name, _bank, _port, _pins) \ 1264 - [TEGRA241_AON_GPIO_PORT_##_name] = { \ 1265 - .name = #_name, \ 1266 - .bank = _bank, \ 1267 - .port = _port, \ 1268 - .pins = _pins, \ 1269 - } 1261 + #define TEGRA241_AON_GPIO_PORT(_name, _bank, _port, _pins) \ 1262 + TEGRA_GPIO_PORT(TEGRA241_AON, _name, _bank, _port, _pins) 1270 1263 1271 1264 static const struct tegra_gpio_port tegra241_aon_ports[] = { 1272 1265 TEGRA241_AON_GPIO_PORT(AA, 0, 0, 8), ··· 1277 1280 .has_vm_support = false, 1278 1281 }; 1279 1282 1280 - #define TEGRA256_MAIN_GPIO_PORT(_name, _bank, _port, _pins) \ 1281 - [TEGRA256_MAIN_GPIO_PORT_##_name] = { \ 1282 - .name = #_name, \ 1283 - .bank = _bank, \ 1284 - .port = _port, \ 1285 - .pins = _pins, \ 1286 - } 1283 + #define TEGRA256_MAIN_GPIO_PORT(_name, _bank, _port, _pins) \ 1284 + TEGRA_GPIO_PORT(TEGRA256_MAIN, _name, _bank, _port, _pins) 1287 1285 1288 1286 static const struct tegra_gpio_port tegra256_main_ports[] = { 1289 1287 TEGRA256_MAIN_GPIO_PORT(A, 0, 0, 8), ··· 1294 1302 .instance = 1, 1295 1303 .num_irqs_per_bank = 8, 1296 1304 .has_vm_support = true, 1305 + }; 1306 + 1307 + #define TEGRA410_COMPUTE_GPIO_PORT(_name, _bank, _port, _pins) \ 1308 + TEGRA_GPIO_PORT(TEGRA410_COMPUTE, _name, _bank, _port, _pins) 1309 + 1310 + static const struct tegra_gpio_port tegra410_compute_ports[] = { 1311 + TEGRA410_COMPUTE_GPIO_PORT(A, 0, 0, 3), 1312 + TEGRA410_COMPUTE_GPIO_PORT(B, 1, 0, 8), 1313 + TEGRA410_COMPUTE_GPIO_PORT(C, 1, 1, 3), 1314 + TEGRA410_COMPUTE_GPIO_PORT(D, 2, 0, 8), 1315 + TEGRA410_COMPUTE_GPIO_PORT(E, 2, 1, 8), 1316 + }; 1317 + 1318 + static const struct tegra_gpio_soc tegra410_compute_soc = { 1319 + .num_ports = ARRAY_SIZE(tegra410_compute_ports), 1320 + .ports = tegra410_compute_ports, 1321 + .name = "tegra410-gpio-compute", 1322 + .prefix = "COMPUTE", 1323 + .num_irqs_per_bank = 8, 1324 + .instance = 0, 1325 + }; 1326 + 1327 + #define TEGRA410_SYSTEM_GPIO_PORT(_name, _bank, _port, _pins) \ 1328 + TEGRA_GPIO_PORT(TEGRA410_SYSTEM, _name, _bank, _port, _pins) 1329 + 1330 + static const struct tegra_gpio_port tegra410_system_ports[] = { 1331 + TEGRA410_SYSTEM_GPIO_PORT(A, 0, 0, 7), 1332 + TEGRA410_SYSTEM_GPIO_PORT(B, 0, 1, 8), 1333 + TEGRA410_SYSTEM_GPIO_PORT(C, 0, 2, 8), 1334 + TEGRA410_SYSTEM_GPIO_PORT(D, 0, 3, 8), 1335 + TEGRA410_SYSTEM_GPIO_PORT(E, 0, 4, 6), 1336 + TEGRA410_SYSTEM_GPIO_PORT(I, 1, 0, 8), 1337 + TEGRA410_SYSTEM_GPIO_PORT(J, 1, 1, 7), 1338 + TEGRA410_SYSTEM_GPIO_PORT(K, 1, 2, 7), 1339 + TEGRA410_SYSTEM_GPIO_PORT(L, 1, 3, 7), 1340 + TEGRA410_SYSTEM_GPIO_PORT(M, 2, 0, 7), 1341 + TEGRA410_SYSTEM_GPIO_PORT(N, 2, 1, 6), 1342 + TEGRA410_SYSTEM_GPIO_PORT(P, 2, 2, 8), 1343 + TEGRA410_SYSTEM_GPIO_PORT(Q, 2, 3, 3), 1344 + TEGRA410_SYSTEM_GPIO_PORT(R, 2, 4, 2), 1345 + TEGRA410_SYSTEM_GPIO_PORT(V, 1, 4, 2), 1346 + }; 1347 + 1348 + static const struct tegra_gpio_soc tegra410_system_soc = { 1349 + .num_ports = ARRAY_SIZE(tegra410_system_ports), 1350 + .ports = tegra410_system_ports, 1351 + .name = "tegra410-gpio-system", 1352 + .prefix = "SYSTEM", 1353 + .num_irqs_per_bank = 8, 1354 + .instance = 0, 1297 1355 }; 1298 1356 1299 1357 static const struct of_device_id tegra186_gpio_of_match[] = { ··· 1381 1339 { .id = "NVDA0408", .driver_data = (kernel_ulong_t)&tegra194_aon_soc }, 1382 1340 { .id = "NVDA0508", .driver_data = (kernel_ulong_t)&tegra241_main_soc }, 1383 1341 { .id = "NVDA0608", .driver_data = (kernel_ulong_t)&tegra241_aon_soc }, 1342 + { .id = "NVDA0708", .driver_data = (kernel_ulong_t)&tegra410_compute_soc }, 1343 + { .id = "NVDA0808", .driver_data = (kernel_ulong_t)&tegra410_system_soc }, 1384 1344 {} 1385 1345 }; 1386 1346 MODULE_DEVICE_TABLE(acpi, tegra186_gpio_acpi_match);
+4 -5
drivers/gpio/gpio-tqmx86.c
··· 279 279 } 280 280 281 281 /* Minimal runtime PM is needed by the IRQ subsystem */ 282 - static int __maybe_unused tqmx86_gpio_runtime_suspend(struct device *dev) 282 + static int tqmx86_gpio_runtime_suspend(struct device *dev) 283 283 { 284 284 return 0; 285 285 } 286 286 287 - static int __maybe_unused tqmx86_gpio_runtime_resume(struct device *dev) 287 + static int tqmx86_gpio_runtime_resume(struct device *dev) 288 288 { 289 289 return 0; 290 290 } 291 291 292 292 static const struct dev_pm_ops tqmx86_gpio_dev_pm_ops = { 293 - SET_RUNTIME_PM_OPS(tqmx86_gpio_runtime_suspend, 294 - tqmx86_gpio_runtime_resume, NULL) 293 + RUNTIME_PM_OPS(tqmx86_gpio_runtime_suspend, tqmx86_gpio_runtime_resume, NULL) 295 294 }; 296 295 297 296 static void tqmx86_init_irq_valid_mask(struct gpio_chip *chip, ··· 424 425 static struct platform_driver tqmx86_gpio_driver = { 425 426 .driver = { 426 427 .name = "tqmx86-gpio", 427 - .pm = &tqmx86_gpio_dev_pm_ops, 428 + .pm = pm_ptr(&tqmx86_gpio_dev_pm_ops), 428 429 }, 429 430 .probe = tqmx86_gpio_probe, 430 431 };
+4 -5
drivers/gpio/gpio-uniphier.c
··· 426 426 irq_domain_remove(priv->domain); 427 427 } 428 428 429 - static int __maybe_unused uniphier_gpio_suspend(struct device *dev) 429 + static int uniphier_gpio_suspend(struct device *dev) 430 430 { 431 431 struct uniphier_gpio_priv *priv = dev_get_drvdata(dev); 432 432 unsigned int nbanks = uniphier_gpio_get_nbanks(priv->chip.ngpio); ··· 448 448 return 0; 449 449 } 450 450 451 - static int __maybe_unused uniphier_gpio_resume(struct device *dev) 451 + static int uniphier_gpio_resume(struct device *dev) 452 452 { 453 453 struct uniphier_gpio_priv *priv = dev_get_drvdata(dev); 454 454 unsigned int nbanks = uniphier_gpio_get_nbanks(priv->chip.ngpio); ··· 473 473 } 474 474 475 475 static const struct dev_pm_ops uniphier_gpio_pm_ops = { 476 - SET_LATE_SYSTEM_SLEEP_PM_OPS(uniphier_gpio_suspend, 477 - uniphier_gpio_resume) 476 + LATE_SYSTEM_SLEEP_PM_OPS(uniphier_gpio_suspend, uniphier_gpio_resume) 478 477 }; 479 478 480 479 static const struct of_device_id uniphier_gpio_match[] = { ··· 488 489 .driver = { 489 490 .name = "uniphier-gpio", 490 491 .of_match_table = uniphier_gpio_match, 491 - .pm = &uniphier_gpio_pm_ops, 492 + .pm = pm_sleep_ptr(&uniphier_gpio_pm_ops), 492 493 }, 493 494 }; 494 495 module_platform_driver(uniphier_gpio_driver);
+3 -5
drivers/gpio/gpio-virtuser.c
··· 500 500 if (val > 1) 501 501 return -EINVAL; 502 502 503 - gpiod_set_value_cansleep(ld->ad.desc, (int)val); 504 - 505 - return 0; 503 + return gpiod_set_value_cansleep(ld->ad.desc, (int)val); 506 504 } 507 505 508 506 DEFINE_DEBUGFS_ATTRIBUTE(gpio_virtuser_value_fops, ··· 541 543 struct gpio_virtuser_irq_work_context *ctx = 542 544 to_gpio_virtuser_irq_work_context(work); 543 545 544 - gpiod_set_value(ctx->desc, ctx->val); 546 + ctx->ret = gpiod_set_value(ctx->desc, ctx->val); 545 547 complete(&ctx->work_completion); 546 548 } 547 549 ··· 560 562 561 563 gpio_virtuser_irq_work_queue_sync(&ctx); 562 564 563 - return 0; 565 + return ctx.ret; 564 566 } 565 567 566 568 DEFINE_DEBUGFS_ATTRIBUTE(gpio_virtuser_value_atomic_fops,
+4 -4
drivers/gpio/gpio-xgene.c
··· 130 130 return 0; 131 131 } 132 132 133 - static __maybe_unused int xgene_gpio_suspend(struct device *dev) 133 + static int xgene_gpio_suspend(struct device *dev) 134 134 { 135 135 struct xgene_gpio *gpio = dev_get_drvdata(dev); 136 136 unsigned long bank_offset; ··· 143 143 return 0; 144 144 } 145 145 146 - static __maybe_unused int xgene_gpio_resume(struct device *dev) 146 + static int xgene_gpio_resume(struct device *dev) 147 147 { 148 148 struct xgene_gpio *gpio = dev_get_drvdata(dev); 149 149 unsigned long bank_offset; ··· 156 156 return 0; 157 157 } 158 158 159 - static SIMPLE_DEV_PM_OPS(xgene_gpio_pm, xgene_gpio_suspend, xgene_gpio_resume); 159 + static DEFINE_SIMPLE_DEV_PM_OPS(xgene_gpio_pm, xgene_gpio_suspend, xgene_gpio_resume); 160 160 161 161 static int xgene_gpio_probe(struct platform_device *pdev) 162 162 { ··· 204 204 .name = "xgene-gpio", 205 205 .of_match_table = xgene_gpio_of_match, 206 206 .acpi_match_table = ACPI_PTR(xgene_gpio_acpi_match), 207 - .pm = &xgene_gpio_pm, 207 + .pm = pm_sleep_ptr(&xgene_gpio_pm), 208 208 }, 209 209 .probe = xgene_gpio_probe, 210 210 };
+7 -8
drivers/gpio/gpio-xilinx.c
··· 286 286 pm_runtime_put(chip->parent); 287 287 } 288 288 289 - static int __maybe_unused xgpio_suspend(struct device *dev) 289 + static int xgpio_suspend(struct device *dev) 290 290 { 291 291 struct xgpio_instance *gpio = dev_get_drvdata(dev); 292 292 struct irq_data *data = irq_get_irq_data(gpio->irq); ··· 327 327 { 328 328 } 329 329 330 - static int __maybe_unused xgpio_resume(struct device *dev) 330 + static int xgpio_resume(struct device *dev) 331 331 { 332 332 struct xgpio_instance *gpio = dev_get_drvdata(dev); 333 333 struct irq_data *data = irq_get_irq_data(gpio->irq); ··· 343 343 return 0; 344 344 } 345 345 346 - static int __maybe_unused xgpio_runtime_suspend(struct device *dev) 346 + static int xgpio_runtime_suspend(struct device *dev) 347 347 { 348 348 struct xgpio_instance *gpio = dev_get_drvdata(dev); 349 349 ··· 352 352 return 0; 353 353 } 354 354 355 - static int __maybe_unused xgpio_runtime_resume(struct device *dev) 355 + static int xgpio_runtime_resume(struct device *dev) 356 356 { 357 357 struct xgpio_instance *gpio = dev_get_drvdata(dev); 358 358 ··· 360 360 } 361 361 362 362 static const struct dev_pm_ops xgpio_dev_pm_ops = { 363 - SET_SYSTEM_SLEEP_PM_OPS(xgpio_suspend, xgpio_resume) 364 - SET_RUNTIME_PM_OPS(xgpio_runtime_suspend, 365 - xgpio_runtime_resume, NULL) 363 + SYSTEM_SLEEP_PM_OPS(xgpio_suspend, xgpio_resume) 364 + RUNTIME_PM_OPS(xgpio_runtime_suspend, xgpio_runtime_resume, NULL) 366 365 }; 367 366 368 367 /** ··· 681 682 .driver = { 682 683 .name = "gpio-xilinx", 683 684 .of_match_table = xgpio_of_match, 684 - .pm = &xgpio_dev_pm_ops, 685 + .pm = pm_ptr(&xgpio_dev_pm_ops), 685 686 }, 686 687 }; 687 688
+7 -8
drivers/gpio/gpio-zynq.c
··· 735 735 } 736 736 } 737 737 738 - static int __maybe_unused zynq_gpio_suspend(struct device *dev) 738 + static int zynq_gpio_suspend(struct device *dev) 739 739 { 740 740 struct zynq_gpio *gpio = dev_get_drvdata(dev); 741 741 struct irq_data *data = irq_get_irq_data(gpio->irq); ··· 756 756 return 0; 757 757 } 758 758 759 - static int __maybe_unused zynq_gpio_resume(struct device *dev) 759 + static int zynq_gpio_resume(struct device *dev) 760 760 { 761 761 struct zynq_gpio *gpio = dev_get_drvdata(dev); 762 762 struct irq_data *data = irq_get_irq_data(gpio->irq); ··· 779 779 return 0; 780 780 } 781 781 782 - static int __maybe_unused zynq_gpio_runtime_suspend(struct device *dev) 782 + static int zynq_gpio_runtime_suspend(struct device *dev) 783 783 { 784 784 struct zynq_gpio *gpio = dev_get_drvdata(dev); 785 785 ··· 788 788 return 0; 789 789 } 790 790 791 - static int __maybe_unused zynq_gpio_runtime_resume(struct device *dev) 791 + static int zynq_gpio_runtime_resume(struct device *dev) 792 792 { 793 793 struct zynq_gpio *gpio = dev_get_drvdata(dev); 794 794 ··· 814 814 } 815 815 816 816 static const struct dev_pm_ops zynq_gpio_dev_pm_ops = { 817 - SET_SYSTEM_SLEEP_PM_OPS(zynq_gpio_suspend, zynq_gpio_resume) 818 - SET_RUNTIME_PM_OPS(zynq_gpio_runtime_suspend, 819 - zynq_gpio_runtime_resume, NULL) 817 + SYSTEM_SLEEP_PM_OPS(zynq_gpio_suspend, zynq_gpio_resume) 818 + RUNTIME_PM_OPS(zynq_gpio_runtime_suspend, zynq_gpio_runtime_resume, NULL) 820 819 }; 821 820 822 821 static const struct zynq_platform_data versal_gpio_def = { ··· 1021 1022 static struct platform_driver zynq_gpio_driver = { 1022 1023 .driver = { 1023 1024 .name = DRIVER_NAME, 1024 - .pm = &zynq_gpio_dev_pm_ops, 1025 + .pm = pm_ptr(&zynq_gpio_dev_pm_ops), 1025 1026 .of_match_table = zynq_gpio_of_match, 1026 1027 }, 1027 1028 .probe = zynq_gpio_probe,
+1 -1
drivers/gpio/gpiolib-acpi-core.c
··· 1099 1099 return AE_BAD_PARAMETER; 1100 1100 } 1101 1101 1102 - length = min_t(u16, agpio->pin_table_length, pin_index + bits); 1102 + length = min(agpio->pin_table_length, pin_index + bits); 1103 1103 for (i = pin_index; i < length; ++i) { 1104 1104 unsigned int pin = agpio->pin_table[i]; 1105 1105 struct acpi_gpio_connection *conn;
+9 -9
drivers/gpio/gpiolib-cdev.c
··· 652 652 } 653 653 le.line_seqno = line->line_seqno; 654 654 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno; 655 - le.offset = gpio_chip_hwgpio(line->desc); 655 + le.offset = gpiod_hwgpio(line->desc); 656 656 657 657 linereq_put_event(lr, &le); 658 658 ··· 676 676 if (READ_ONCE(line->sw_debounced)) { 677 677 line->total_discard_seq++; 678 678 line->last_seqno = ts->seq; 679 - mod_delayed_work(system_wq, &line->work, 679 + mod_delayed_work(system_percpu_wq, &line->work, 680 680 usecs_to_jiffies(READ_ONCE(line->desc->debounce_period_us))); 681 681 } else { 682 682 if (unlikely(ts->seq < line->line_seqno)) ··· 769 769 line->line_seqno++; 770 770 le.line_seqno = line->line_seqno; 771 771 le.seqno = (lr->num_lines == 1) ? le.line_seqno : line->req_seqno; 772 - le.offset = gpio_chip_hwgpio(line->desc); 772 + le.offset = gpiod_hwgpio(line->desc); 773 773 774 774 linereq_put_event(lr, &le); 775 775 ··· 817 817 { 818 818 struct line *line = p; 819 819 820 - mod_delayed_work(system_wq, &line->work, 820 + mod_delayed_work(system_percpu_wq, &line->work, 821 821 usecs_to_jiffies(READ_ONCE(line->desc->debounce_period_us))); 822 822 823 823 return IRQ_HANDLED; ··· 867 867 868 868 lr = line->req; 869 869 le.timestamp_ns = line_event_timestamp(line); 870 - le.offset = gpio_chip_hwgpio(line->desc); 870 + le.offset = gpiod_hwgpio(line->desc); 871 871 #ifdef CONFIG_HTE 872 872 if (edflags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE) { 873 873 /* discard events except the last one */ ··· 1567 1567 1568 1568 for (i = 0; i < lr->num_lines; i++) 1569 1569 seq_printf(out, "gpio-line:\t%d\n", 1570 - gpio_chip_hwgpio(lr->lines[i].desc)); 1570 + gpiod_hwgpio(lr->lines[i].desc)); 1571 1571 } 1572 1572 #endif 1573 1573 ··· 2220 2220 return; 2221 2221 2222 2222 memset(info, 0, sizeof(*info)); 2223 - info->offset = gpio_chip_hwgpio(desc); 2223 + info->offset = gpiod_hwgpio(desc); 2224 2224 2225 2225 if (desc->name) 2226 2226 strscpy(info->name, desc->name, sizeof(info->name)); ··· 2526 2526 struct gpio_desc *desc = data; 2527 2527 struct file *fp; 2528 2528 2529 - if (!test_bit(gpio_chip_hwgpio(desc), cdev->watched_lines)) 2529 + if (!test_bit(gpiod_hwgpio(desc), cdev->watched_lines)) 2530 2530 return NOTIFY_DONE; 2531 2531 2532 2532 /* Keep the file descriptor alive for the duration of the notification. */ ··· 2804 2804 if (!gc) 2805 2805 return -ENODEV; 2806 2806 2807 - chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id); 2807 + gpiochip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id); 2808 2808 2809 2809 return 0; 2810 2810 }
+16 -28
drivers/gpio/gpiolib-legacy.c
··· 34 34 */ 35 35 int gpio_request_one(unsigned gpio, unsigned long flags, const char *label) 36 36 { 37 - struct gpio_desc *desc; 38 37 int err; 39 38 40 - /* Compatibility: assume unavailable "valid" GPIOs will appear later */ 41 - desc = gpio_to_desc(gpio); 42 - if (!desc) 43 - return -EPROBE_DEFER; 44 - 45 - err = gpiod_request(desc, label); 39 + err = gpio_request(gpio, label); 46 40 if (err) 47 41 return err; 48 42 49 43 if (flags & GPIOF_IN) 50 - err = gpiod_direction_input(desc); 44 + err = gpio_direction_input(gpio); 51 45 else 52 - err = gpiod_direction_output_raw(desc, !!(flags & GPIOF_OUT_INIT_HIGH)); 46 + err = gpio_direction_output(gpio, !!(flags & GPIOF_OUT_INIT_HIGH)); 53 47 54 48 if (err) 55 - goto free_gpio; 49 + gpio_free(gpio); 56 50 57 - return 0; 58 - 59 - free_gpio: 60 - gpiod_free(desc); 61 51 return err; 62 52 } 63 53 EXPORT_SYMBOL_GPL(gpio_request_one); ··· 68 78 } 69 79 EXPORT_SYMBOL_GPL(gpio_request); 70 80 71 - static void devm_gpio_release(struct device *dev, void *res) 81 + static void devm_gpio_release(void *gpio) 72 82 { 73 - unsigned *gpio = res; 74 - 75 - gpio_free(*gpio); 83 + gpio_free((unsigned)(unsigned long)gpio); 76 84 } 77 85 78 86 /** ··· 88 100 int devm_gpio_request_one(struct device *dev, unsigned gpio, 89 101 unsigned long flags, const char *label) 90 102 { 91 - unsigned *dr; 92 103 int rc; 93 104 94 - dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL); 95 - if (!dr) 96 - return -ENOMEM; 105 + rc = gpio_request(gpio, label); 106 + if (rc) 107 + return rc; 97 108 98 - rc = gpio_request_one(gpio, flags, label); 109 + if (flags & GPIOF_IN) 110 + rc = gpio_direction_input(gpio); 111 + else 112 + rc = gpio_direction_output(gpio, !!(flags & GPIOF_OUT_INIT_HIGH)); 113 + 99 114 if (rc) { 100 - devres_free(dr); 115 + gpio_free(gpio); 101 116 return rc; 102 117 } 103 118 104 - *dr = gpio; 105 - devres_add(dev, dr); 106 - 107 - return 0; 119 + return devm_add_action_or_reset(dev, devm_gpio_release, (void *)(unsigned long)gpio); 108 120 } 109 121 EXPORT_SYMBOL_GPL(devm_gpio_request_one);
-79
drivers/gpio/gpiolib-of.c
··· 1031 1031 return gpiospec->args[1]; 1032 1032 } 1033 1033 1034 - #if IS_ENABLED(CONFIG_OF_GPIO_MM_GPIOCHIP) 1035 - #include <linux/gpio/legacy-of-mm-gpiochip.h> 1036 - /** 1037 - * of_mm_gpiochip_add_data - Add memory mapped GPIO chip (bank) 1038 - * @np: device node of the GPIO chip 1039 - * @mm_gc: pointer to the of_mm_gpio_chip allocated structure 1040 - * @data: driver data to store in the struct gpio_chip 1041 - * 1042 - * To use this function you should allocate and fill mm_gc with: 1043 - * 1044 - * 1) In the gpio_chip structure: 1045 - * - all the callbacks 1046 - * - of_gpio_n_cells 1047 - * - of_xlate callback (optional) 1048 - * 1049 - * 3) In the of_mm_gpio_chip structure: 1050 - * - save_regs callback (optional) 1051 - * 1052 - * If succeeded, this function will map bank's memory and will 1053 - * do all necessary work for you. Then you'll able to use .regs 1054 - * to manage GPIOs from the callbacks. 1055 - * 1056 - * Returns: 1057 - * 0 on success, or negative errno on failure. 1058 - */ 1059 - int of_mm_gpiochip_add_data(struct device_node *np, 1060 - struct of_mm_gpio_chip *mm_gc, 1061 - void *data) 1062 - { 1063 - int ret = -ENOMEM; 1064 - struct gpio_chip *gc = &mm_gc->gc; 1065 - 1066 - gc->label = kasprintf(GFP_KERNEL, "%pOF", np); 1067 - if (!gc->label) 1068 - goto err0; 1069 - 1070 - mm_gc->regs = of_iomap(np, 0); 1071 - if (!mm_gc->regs) 1072 - goto err1; 1073 - 1074 - gc->base = -1; 1075 - 1076 - if (mm_gc->save_regs) 1077 - mm_gc->save_regs(mm_gc); 1078 - 1079 - fwnode_handle_put(mm_gc->gc.fwnode); 1080 - mm_gc->gc.fwnode = fwnode_handle_get(of_fwnode_handle(np)); 1081 - 1082 - ret = gpiochip_add_data(gc, data); 1083 - if (ret) 1084 - goto err2; 1085 - 1086 - return 0; 1087 - err2: 1088 - of_node_put(np); 1089 - iounmap(mm_gc->regs); 1090 - err1: 1091 - kfree(gc->label); 1092 - err0: 1093 - pr_err("%pOF: GPIO chip registration failed with status %d\n", np, ret); 1094 - return ret; 1095 - } 1096 - EXPORT_SYMBOL_GPL(of_mm_gpiochip_add_data); 1097 - 1098 - /** 1099 - * of_mm_gpiochip_remove - Remove memory mapped GPIO chip (bank) 1100 - * @mm_gc: pointer to the of_mm_gpio_chip allocated structure 1101 - */ 1102 - void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc) 1103 - { 1104 - struct gpio_chip *gc = &mm_gc->gc; 1105 - 1106 - gpiochip_remove(gc); 1107 - iounmap(mm_gc->regs); 1108 - kfree(gc->label); 1109 - } 1110 - EXPORT_SYMBOL_GPL(of_mm_gpiochip_remove); 1111 - #endif 1112 - 1113 1034 #ifdef CONFIG_PINCTRL 1114 1035 static int of_gpiochip_add_pin_range(struct gpio_chip *chip) 1115 1036 {
+136 -38
drivers/gpio/gpiolib-shared.c
··· 49 49 unsigned int offset; 50 50 /* Index in the property value array. */ 51 51 size_t index; 52 + struct mutex lock; 52 53 struct gpio_shared_desc *shared_desc; 53 54 struct kref ref; 54 55 struct list_head refs; ··· 59 58 static DEFINE_MUTEX(gpio_shared_lock); 60 59 static DEFINE_IDA(gpio_shared_ida); 61 60 61 + #if IS_ENABLED(CONFIG_OF) 62 62 static struct gpio_shared_entry * 63 63 gpio_shared_find_entry(struct fwnode_handle *controller_node, 64 64 unsigned int offset) ··· 74 72 return NULL; 75 73 } 76 74 77 - #if IS_ENABLED(CONFIG_OF) 75 + /* Handle all special nodes that we should ignore. */ 76 + static bool gpio_shared_of_node_ignore(struct device_node *node) 77 + { 78 + /* 79 + * __symbols__ is a special, internal node and should not be considered 80 + * when scanning for shared GPIOs. 81 + */ 82 + if (of_node_name_eq(node, "__symbols__")) 83 + return true; 84 + 85 + /* 86 + * GPIO hogs have a "gpios" property which is not a phandle and can't 87 + * possibly refer to a shared GPIO. 88 + */ 89 + if (of_property_present(node, "gpio-hog")) 90 + return true; 91 + 92 + return false; 93 + } 94 + 78 95 static int gpio_shared_of_traverse(struct device_node *curr) 79 96 { 80 97 struct gpio_shared_entry *entry; ··· 104 83 unsigned int offset; 105 84 const char *suffix; 106 85 int ret, count, i; 86 + 87 + if (gpio_shared_of_node_ignore(curr)) 88 + return 0; 107 89 108 90 for_each_property_of_node(curr, prop) { 109 91 /* ··· 171 147 entry->offset = offset; 172 148 entry->index = count; 173 149 INIT_LIST_HEAD(&entry->refs); 150 + mutex_init(&entry->lock); 174 151 175 152 list_add_tail(&entry->list, &gpio_shared_list); 176 153 } ··· 230 205 231 206 static int gpio_shared_of_scan(void) 232 207 { 233 - return gpio_shared_of_traverse(of_root); 208 + if (of_root) 209 + return gpio_shared_of_traverse(of_root); 210 + 211 + return 0; 234 212 } 235 213 #else 236 214 static int gpio_shared_of_scan(void) ··· 248 220 } 249 221 250 222 static int gpio_shared_make_adev(struct gpio_device *gdev, 223 + struct gpio_shared_entry *entry, 251 224 struct gpio_shared_ref *ref) 252 225 { 253 226 struct auxiliary_device *adev = &ref->adev; ··· 261 232 adev->id = ref->dev_id; 262 233 adev->name = "proxy"; 263 234 adev->dev.parent = gdev->dev.parent; 235 + adev->dev.platform_data = entry; 264 236 adev->dev.release = gpio_shared_adev_release; 265 237 266 238 ret = auxiliary_device_init(adev); ··· 280 250 return 0; 281 251 } 282 252 253 + #if IS_ENABLED(CONFIG_RESET_GPIO) 254 + /* 255 + * Special case: reset-gpio is an auxiliary device that's created dynamically 256 + * and put in between the GPIO controller and consumers of shared GPIOs 257 + * referred to by the "reset-gpios" property. 258 + * 259 + * If the supposed consumer of a shared GPIO didn't match any of the mappings 260 + * we created when scanning the firmware nodes, it's still possible that it's 261 + * the reset-gpio device which didn't exist at the time of the scan. 262 + * 263 + * This function verifies it an return true if it's the case. 264 + */ 265 + static bool gpio_shared_dev_is_reset_gpio(struct device *consumer, 266 + struct gpio_shared_entry *entry, 267 + struct gpio_shared_ref *ref) 268 + { 269 + struct fwnode_handle *reset_fwnode = dev_fwnode(consumer); 270 + struct fwnode_reference_args ref_args, aux_args; 271 + struct device *parent = consumer->parent; 272 + bool match; 273 + int ret; 274 + 275 + /* The reset-gpio device must have a parent AND a firmware node. */ 276 + if (!parent || !reset_fwnode) 277 + return false; 278 + 279 + /* 280 + * FIXME: use device_is_compatible() once the reset-gpio drivers gains 281 + * a compatible string which it currently does not have. 282 + */ 283 + if (!strstarts(dev_name(consumer), "reset.gpio.")) 284 + return false; 285 + 286 + /* 287 + * Parent of the reset-gpio auxiliary device is the GPIO chip whose 288 + * fwnode we stored in the entry structure. 289 + */ 290 + if (!device_match_fwnode(parent, entry->fwnode)) 291 + return false; 292 + 293 + /* 294 + * The device associated with the shared reference's firmware node is 295 + * the consumer of the reset control exposed by the reset-gpio device. 296 + * It must have a "reset-gpios" property that's referencing the entry's 297 + * firmware node. 298 + * 299 + * The reference args must agree between the real consumer and the 300 + * auxiliary reset-gpio device. 301 + */ 302 + ret = fwnode_property_get_reference_args(ref->fwnode, "reset-gpios", 303 + NULL, 2, 0, &ref_args); 304 + if (ret) 305 + return false; 306 + 307 + ret = fwnode_property_get_reference_args(reset_fwnode, "reset-gpios", 308 + NULL, 2, 0, &aux_args); 309 + if (ret) { 310 + fwnode_handle_put(ref_args.fwnode); 311 + return false; 312 + } 313 + 314 + match = ((ref_args.fwnode == entry->fwnode) && 315 + (aux_args.fwnode == entry->fwnode) && 316 + (ref_args.args[0] == aux_args.args[0])); 317 + 318 + fwnode_handle_put(ref_args.fwnode); 319 + fwnode_handle_put(aux_args.fwnode); 320 + return match; 321 + } 322 + #else 323 + static bool gpio_shared_dev_is_reset_gpio(struct device *consumer, 324 + struct gpio_shared_entry *entry, 325 + struct gpio_shared_ref *ref) 326 + { 327 + return false; 328 + } 329 + #endif /* CONFIG_RESET_GPIO */ 330 + 283 331 int gpio_shared_add_proxy_lookup(struct device *consumer, unsigned long lflags) 284 332 { 285 333 const char *dev_id = dev_name(consumer); ··· 373 265 374 266 list_for_each_entry(entry, &gpio_shared_list, list) { 375 267 list_for_each_entry(ref, &entry->refs, list) { 376 - if (!device_match_fwnode(consumer, ref->fwnode)) 268 + if (!device_match_fwnode(consumer, ref->fwnode) && 269 + !gpio_shared_dev_is_reset_gpio(consumer, entry, ref)) 377 270 continue; 378 271 379 272 /* We've already done that on a previous request. */ ··· 465 356 pr_debug("Setting up a shared GPIO entry for %s\n", 466 357 fwnode_get_name(ref->fwnode)); 467 358 468 - ret = gpio_shared_make_adev(gdev, ref); 359 + ret = gpio_shared_make_adev(gdev, entry, ref); 469 360 if (ret) 470 361 return ret; 471 362 } ··· 499 390 { 500 391 struct gpio_shared_entry *entry = 501 392 container_of(kref, struct gpio_shared_entry, ref); 502 - struct gpio_shared_desc *shared_desc = entry->shared_desc; 393 + struct gpio_shared_desc *shared_desc; 503 394 504 - guard(mutex)(&gpio_shared_lock); 395 + guard(mutex)(&entry->lock); 505 396 397 + shared_desc = entry->shared_desc; 506 398 gpio_device_put(shared_desc->desc->gdev); 507 399 if (shared_desc->can_sleep) 508 400 mutex_destroy(&shared_desc->mutex); ··· 526 416 struct gpio_shared_desc *shared_desc; 527 417 struct gpio_device *gdev; 528 418 419 + lockdep_assert_held(&entry->lock); 420 + 529 421 shared_desc = kzalloc(sizeof(*shared_desc), GFP_KERNEL); 530 422 if (!shared_desc) 531 423 return ERR_PTR(-ENOMEM); ··· 548 436 return shared_desc; 549 437 } 550 438 551 - static struct gpio_shared_entry *gpiod_shared_find(struct auxiliary_device *adev) 439 + struct gpio_shared_desc *devm_gpiod_shared_get(struct device *dev) 552 440 { 553 441 struct gpio_shared_desc *shared_desc; 554 442 struct gpio_shared_entry *entry; 555 - struct gpio_shared_ref *ref; 443 + int ret; 556 444 557 - guard(mutex)(&gpio_shared_lock); 445 + lockdep_assert_not_held(&gpio_shared_lock); 558 446 559 - list_for_each_entry(entry, &gpio_shared_list, list) { 560 - list_for_each_entry(ref, &entry->refs, list) { 561 - if (adev != &ref->adev) 562 - continue; 447 + entry = dev_get_platdata(dev); 448 + if (WARN_ON(!entry)) 449 + /* Programmer bug */ 450 + return ERR_PTR(-ENOENT); 563 451 564 - if (entry->shared_desc) { 565 - kref_get(&entry->ref); 566 - return entry; 567 - } 568 - 452 + scoped_guard(mutex, &entry->lock) { 453 + if (entry->shared_desc) { 454 + kref_get(&entry->ref); 455 + shared_desc = entry->shared_desc; 456 + } else { 569 457 shared_desc = gpiod_shared_desc_create(entry); 570 458 if (IS_ERR(shared_desc)) 571 459 return ERR_CAST(shared_desc); 572 460 573 461 kref_init(&entry->ref); 574 462 entry->shared_desc = shared_desc; 575 - 576 - pr_debug("Device %s acquired a reference to the shared GPIO %u owned by %s\n", 577 - dev_name(&adev->dev), gpio_chip_hwgpio(shared_desc->desc), 578 - gpio_device_get_label(shared_desc->desc->gdev)); 579 - 580 - 581 - return entry; 582 463 } 464 + 465 + pr_debug("Device %s acquired a reference to the shared GPIO %u owned by %s\n", 466 + dev_name(dev), gpiod_hwgpio(shared_desc->desc), 467 + gpio_device_get_label(shared_desc->desc->gdev)); 583 468 } 584 - 585 - return ERR_PTR(-ENOENT); 586 - } 587 - 588 - struct gpio_shared_desc *devm_gpiod_shared_get(struct device *dev) 589 - { 590 - struct gpio_shared_entry *entry; 591 - int ret; 592 - 593 - entry = gpiod_shared_find(to_auxiliary_dev(dev)); 594 - if (IS_ERR(entry)) 595 - return ERR_CAST(entry); 596 469 597 470 ret = devm_add_action_or_reset(dev, gpiod_shared_put, entry); 598 471 if (ret) 599 472 return ERR_PTR(ret); 600 473 601 - return entry->shared_desc; 474 + return shared_desc; 602 475 } 603 476 EXPORT_SYMBOL_GPL(devm_gpiod_shared_get); 604 477 ··· 599 502 static void gpio_shared_drop_entry(struct gpio_shared_entry *entry) 600 503 { 601 504 list_del(&entry->list); 505 + mutex_destroy(&entry->lock); 602 506 fwnode_handle_put(entry->fwnode); 603 507 kfree(entry); 604 508 }
+2 -1
drivers/gpio/gpiolib-swnode.c
··· 31 31 32 32 gdev_node = to_software_node(fwnode); 33 33 if (!gdev_node || !gdev_node->name) 34 - return ERR_PTR(-EINVAL); 34 + goto fwnode_lookup; 35 35 36 36 /* 37 37 * Check for a special node that identifies undefined GPIOs, this is ··· 41 41 !strcmp(gdev_node->name, GPIOLIB_SWNODE_UNDEFINED_NAME)) 42 42 return ERR_PTR(-ENOENT); 43 43 44 + fwnode_lookup: 44 45 gdev = gpio_device_find_by_fwnode(fwnode); 45 46 return gdev ?: ERR_PTR(-EPROBE_DEFER); 46 47 }
+8 -8
drivers/gpio/gpiolib-sysfs.c
··· 244 244 * Remove this redundant call (along with the corresponding unlock) 245 245 * when those drivers have been fixed. 246 246 */ 247 - ret = gpiochip_lock_as_irq(guard.gc, gpio_chip_hwgpio(desc)); 247 + ret = gpiochip_lock_as_irq(guard.gc, gpiod_hwgpio(desc)); 248 248 if (ret < 0) 249 249 goto err_clr_bits; 250 250 ··· 258 258 return 0; 259 259 260 260 err_unlock: 261 - gpiochip_unlock_as_irq(guard.gc, gpio_chip_hwgpio(desc)); 261 + gpiochip_unlock_as_irq(guard.gc, gpiod_hwgpio(desc)); 262 262 err_clr_bits: 263 263 clear_bit(GPIOD_FLAG_EDGE_RISING, &desc->flags); 264 264 clear_bit(GPIOD_FLAG_EDGE_FALLING, &desc->flags); ··· 280 280 281 281 data->irq_flags = 0; 282 282 free_irq(data->irq, data); 283 - gpiochip_unlock_as_irq(guard.gc, gpio_chip_hwgpio(desc)); 283 + gpiochip_unlock_as_irq(guard.gc, gpiod_hwgpio(desc)); 284 284 clear_bit(GPIOD_FLAG_EDGE_RISING, &desc->flags); 285 285 clear_bit(GPIOD_FLAG_EDGE_FALLING, &desc->flags); 286 286 } ··· 478 478 if (!guard.gc) 479 479 return -ENODEV; 480 480 481 - offset = gpio_chip_hwgpio(desc); 481 + offset = gpiod_hwgpio(desc); 482 482 if (!gpiochip_line_is_valid(guard.gc, offset)) { 483 483 pr_debug_ratelimited("%s: GPIO %d masked\n", __func__, 484 - gpio_chip_hwgpio(desc)); 484 + gpiod_hwgpio(desc)); 485 485 return -EINVAL; 486 486 } 487 487 ··· 823 823 } 824 824 825 825 desc_data->chip_attr_group.name = kasprintf(GFP_KERNEL, "gpio%u", 826 - gpio_chip_hwgpio(desc)); 826 + gpiod_hwgpio(desc)); 827 827 if (!desc_data->chip_attr_group.name) { 828 828 status = -ENOMEM; 829 829 goto err_put_dirent; ··· 843 843 if (status) 844 844 goto err_free_name; 845 845 846 - path = kasprintf(GFP_KERNEL, "gpio%u/value", gpio_chip_hwgpio(desc)); 846 + path = kasprintf(GFP_KERNEL, "gpio%u/value", gpiod_hwgpio(desc)); 847 847 if (!path) { 848 848 status = -ENOMEM; 849 849 goto err_remove_groups; ··· 1091 1091 1092 1092 ret = gpiochip_sysfs_register(gdev); 1093 1093 if (ret) 1094 - chip_err(gc, "failed to register the sysfs entry: %d\n", ret); 1094 + gpiochip_err(gc, "failed to register the sysfs entry: %d\n", ret); 1095 1095 1096 1096 return 0; 1097 1097 }
+77 -70
drivers/gpio/gpiolib.c
··· 236 236 } 237 237 EXPORT_SYMBOL_GPL(desc_to_gpio); 238 238 239 + /** 240 + * gpiod_hwgpio - Return the GPIO number of the passed descriptor relative to 241 + * its chip. 242 + * @desc: GPIO descriptor 243 + * 244 + * Returns: 245 + * Hardware offset of the GPIO represented by the descriptor. 246 + */ 247 + int gpiod_hwgpio(const struct gpio_desc *desc) 248 + { 249 + return desc - &desc->gdev->descs[0]; 250 + } 251 + EXPORT_SYMBOL_GPL(gpiod_hwgpio); 239 252 240 253 /** 241 254 * gpiod_to_chip - Return the GPIO chip to which a GPIO descriptor belongs ··· 457 444 if (!guard.gc) 458 445 return -ENODEV; 459 446 460 - offset = gpio_chip_hwgpio(desc); 447 + offset = gpiod_hwgpio(desc); 461 448 flags = READ_ONCE(desc->flags); 462 449 463 450 /* ··· 935 922 936 923 desc = gpiochip_get_desc(gc, hog->chip_hwnum); 937 924 if (IS_ERR(desc)) { 938 - chip_err(gc, "%s: unable to get GPIO desc: %ld\n", __func__, 939 - PTR_ERR(desc)); 925 + gpiochip_err(gc, "%s: unable to get GPIO desc: %ld\n", 926 + __func__, PTR_ERR(desc)); 940 927 return; 941 928 } 942 929 ··· 1138 1125 1139 1126 ret = gpiodev_add_to_list_unlocked(gdev); 1140 1127 if (ret) { 1141 - chip_err(gc, "GPIO integer space overlap, cannot add chip\n"); 1128 + gpiochip_err(gc, "GPIO integer space overlap, cannot add chip\n"); 1142 1129 goto err_free_label; 1143 1130 } 1144 1131 } ··· 1550 1537 &parent_hwirq, 1551 1538 &parent_type); 1552 1539 if (ret) { 1553 - chip_err(gc, "skip set-up on hwirq %d\n", 1554 - i); 1540 + gpiochip_err(gc, "skip set-up on hwirq %d\n", i); 1555 1541 continue; 1556 1542 } 1557 1543 ··· 1563 1551 ret = irq_domain_alloc_irqs(gc->irq.domain, 1, 1564 1552 NUMA_NO_NODE, &fwspec); 1565 1553 if (ret < 0) { 1566 - chip_err(gc, 1567 - "can not allocate irq for GPIO line %d parent hwirq %d in hierarchy domain: %d\n", 1568 - i, parent_hwirq, 1569 - ret); 1554 + gpiochip_err(gc, 1555 + "can not allocate irq for GPIO line %d parent hwirq %d in hierarchy domain: %d\n", 1556 + i, parent_hwirq, ret); 1570 1557 } 1571 1558 } 1572 1559 } 1573 1560 1574 - chip_err(gc, "%s unknown fwnode type proceed anyway\n", __func__); 1561 + gpiochip_err(gc, "%s unknown fwnode type proceed anyway\n", __func__); 1575 1562 1576 1563 return; 1577 1564 } ··· 1622 1611 if (ret) 1623 1612 return ret; 1624 1613 1625 - chip_dbg(gc, "allocate IRQ %d, hwirq %lu\n", irq, hwirq); 1614 + gpiochip_dbg(gc, "allocate IRQ %d, hwirq %lu\n", irq, hwirq); 1626 1615 1627 1616 ret = girq->child_to_parent_hwirq(gc, hwirq, type, 1628 1617 &parent_hwirq, &parent_type); 1629 1618 if (ret) { 1630 - chip_err(gc, "can't look up hwirq %lu\n", hwirq); 1619 + gpiochip_err(gc, "can't look up hwirq %lu\n", hwirq); 1631 1620 return ret; 1632 1621 } 1633 - chip_dbg(gc, "found parent hwirq %u\n", parent_hwirq); 1622 + gpiochip_dbg(gc, "found parent hwirq %u\n", parent_hwirq); 1634 1623 1635 1624 /* 1636 1625 * We set handle_bad_irq because the .set_type() should ··· 1651 1640 if (ret) 1652 1641 return ret; 1653 1642 1654 - chip_dbg(gc, "alloc_irqs_parent for %d parent hwirq %d\n", 1655 - irq, parent_hwirq); 1643 + gpiochip_dbg(gc, "alloc_irqs_parent for %d parent hwirq %d\n", 1644 + irq, parent_hwirq); 1656 1645 irq_set_lockdep_class(irq, gc->irq.lock_key, gc->irq.request_key); 1657 1646 ret = irq_domain_alloc_irqs_parent(d, irq, 1, &gpio_parent_fwspec); 1658 1647 /* ··· 1662 1651 if (irq_domain_is_msi(d->parent) && (ret == -EEXIST)) 1663 1652 ret = 0; 1664 1653 if (ret) 1665 - chip_err(gc, 1666 - "failed to allocate parent hwirq %d for hwirq %lu\n", 1667 - parent_hwirq, hwirq); 1654 + gpiochip_err(gc, 1655 + "failed to allocate parent hwirq %d for hwirq %lu\n", 1656 + parent_hwirq, hwirq); 1668 1657 1669 1658 return ret; 1670 1659 } ··· 1740 1729 1741 1730 if (!gc->irq.child_to_parent_hwirq || 1742 1731 !gc->irq.fwnode) { 1743 - chip_err(gc, "missing irqdomain vital data\n"); 1732 + gpiochip_err(gc, "missing irqdomain vital data\n"); 1744 1733 return ERR_PTR(-EINVAL); 1745 1734 } 1746 1735 ··· 2013 2002 if (irqchip->flags & IRQCHIP_IMMUTABLE) 2014 2003 return; 2015 2004 2016 - chip_warn(gc, "not an immutable chip, please consider fixing it!\n"); 2005 + gpiochip_warn(gc, "not an immutable chip, please consider fixing it!\n"); 2017 2006 2018 2007 if (!irqchip->irq_request_resources && 2019 2008 !irqchip->irq_release_resources) { ··· 2029 2018 * ...and if so, give a gentle warning that this is bad 2030 2019 * practice. 2031 2020 */ 2032 - chip_info(gc, 2033 - "detected irqchip that is shared with multiple gpiochips: please fix the driver.\n"); 2021 + gpiochip_info(gc, 2022 + "detected irqchip that is shared with multiple gpiochips: please fix the driver.\n"); 2034 2023 return; 2035 2024 } 2036 2025 ··· 2059 2048 return -EINVAL; 2060 2049 2061 2050 if (gc->to_irq) 2062 - chip_warn(gc, "to_irq is redefined in %s and you shouldn't rely on it\n", __func__); 2051 + gpiochip_warn(gc, "to_irq is redefined in %s and you shouldn't rely on it\n", 2052 + __func__); 2063 2053 2064 2054 gc->to_irq = gpiochip_to_irq; 2065 2055 gc->irq.domain = domain; ··· 2101 2089 return 0; 2102 2090 2103 2091 if (gc->irq.parent_handler && gc->can_sleep) { 2104 - chip_err(gc, "you cannot have chained interrupts on a chip that may sleep\n"); 2092 + gpiochip_err(gc, "you cannot have chained interrupts on a chip that may sleep\n"); 2105 2093 return -EINVAL; 2106 2094 } 2107 2095 ··· 2337 2325 int ret; 2338 2326 2339 2327 pin_range = kzalloc(sizeof(*pin_range), GFP_KERNEL); 2340 - if (!pin_range) { 2341 - chip_err(gc, "failed to allocate pin ranges\n"); 2328 + if (!pin_range) 2342 2329 return -ENOMEM; 2343 - } 2344 2330 2345 2331 /* Use local offset as range ID */ 2346 2332 pin_range->range.id = gpio_offset; ··· 2357 2347 2358 2348 pinctrl_add_gpio_range(pctldev, &pin_range->range); 2359 2349 2360 - chip_dbg(gc, "created GPIO range %d->%d ==> %s PINGRP %s\n", 2350 + gpiochip_dbg(gc, "created GPIO range %d->%d ==> %s PINGRP %s\n", 2361 2351 gpio_offset, gpio_offset + pin_range->range.npins - 1, 2362 2352 pinctrl_dev_get_devname(pctldev), pin_group); 2363 2353 ··· 2398 2388 int ret; 2399 2389 2400 2390 pin_range = kzalloc(sizeof(*pin_range), GFP_KERNEL); 2401 - if (!pin_range) { 2402 - chip_err(gc, "failed to allocate pin ranges\n"); 2391 + if (!pin_range) 2403 2392 return -ENOMEM; 2404 - } 2405 2393 2406 2394 /* Use local offset as range ID */ 2407 2395 pin_range->range.id = gpio_offset; ··· 2413 2405 &pin_range->range); 2414 2406 if (IS_ERR(pin_range->pctldev)) { 2415 2407 ret = PTR_ERR(pin_range->pctldev); 2416 - chip_err(gc, "could not create pin range\n"); 2408 + gpiochip_err(gc, "could not create pin range\n"); 2417 2409 kfree(pin_range); 2418 2410 return ret; 2419 2411 } 2420 2412 if (pin_range->range.pins) 2421 - chip_dbg(gc, "created GPIO range %d->%d ==> %s %d sparse PIN range { %d, ... }", 2422 - gpio_offset, gpio_offset + npins - 1, 2423 - pinctl_name, npins, pins[0]); 2413 + gpiochip_dbg(gc, "created GPIO range %d->%d ==> %s %d sparse PIN range { %d, ... }", 2414 + gpio_offset, gpio_offset + npins - 1, 2415 + pinctl_name, npins, pins[0]); 2424 2416 else 2425 - chip_dbg(gc, "created GPIO range %d->%d ==> %s PIN %d->%d\n", 2426 - gpio_offset, gpio_offset + npins - 1, 2427 - pinctl_name, 2428 - pin_offset, pin_offset + npins - 1); 2417 + gpiochip_dbg(gc, "created GPIO range %d->%d ==> %s PIN %d->%d\n", 2418 + gpio_offset, gpio_offset + npins - 1, pinctl_name, 2419 + pin_offset, pin_offset + npins - 1); 2429 2420 2430 2421 list_add_tail(&pin_range->node, &gdev->pin_ranges); 2431 2422 ··· 2468 2461 if (test_and_set_bit(GPIOD_FLAG_REQUESTED, &desc->flags)) 2469 2462 return -EBUSY; 2470 2463 2471 - offset = gpio_chip_hwgpio(desc); 2464 + offset = gpiod_hwgpio(desc); 2472 2465 if (!gpiochip_line_is_valid(guard.gc, offset)) 2473 2466 return -EINVAL; 2474 2467 ··· 2530 2523 2531 2524 if (guard.gc && test_bit(GPIOD_FLAG_REQUESTED, &flags)) { 2532 2525 if (guard.gc->free) 2533 - guard.gc->free(guard.gc, gpio_chip_hwgpio(desc)); 2526 + guard.gc->free(guard.gc, gpiod_hwgpio(desc)); 2534 2527 2535 2528 clear_bit(GPIOD_FLAG_ACTIVE_LOW, &flags); 2536 2529 clear_bit(GPIOD_FLAG_REQUESTED, &flags); ··· 2634 2627 int ret; 2635 2628 2636 2629 if (IS_ERR(desc)) { 2637 - chip_err(gc, "failed to get GPIO %s descriptor\n", name); 2630 + gpiochip_err(gc, "failed to get GPIO %s descriptor\n", name); 2638 2631 return desc; 2639 2632 } 2640 2633 ··· 2645 2638 ret = gpiod_configure_flags(desc, label, lflags, dflags); 2646 2639 if (ret) { 2647 2640 gpiod_free_commit(desc); 2648 - chip_err(gc, "setup of own GPIO %s failed\n", name); 2641 + gpiochip_err(gc, "setup of own GPIO %s failed\n", name); 2649 2642 return ERR_PTR(ret); 2650 2643 } 2651 2644 ··· 2690 2683 if (!guard.gc->set_config) 2691 2684 return -ENOTSUPP; 2692 2685 2693 - ret = guard.gc->set_config(guard.gc, gpio_chip_hwgpio(desc), config); 2686 + ret = guard.gc->set_config(guard.gc, gpiod_hwgpio(desc), config); 2694 2687 if (ret > 0) 2695 2688 ret = -EBADE; 2696 2689 ··· 2721 2714 u32 argument) 2722 2715 { 2723 2716 struct device *dev = &desc->gdev->dev; 2724 - int gpio = gpio_chip_hwgpio(desc); 2717 + int gpio = gpiod_hwgpio(desc); 2725 2718 int ret; 2726 2719 2727 2720 ret = gpio_set_config_with_argument(desc, mode, argument); ··· 2884 2877 */ 2885 2878 if (guard.gc->direction_input) { 2886 2879 ret = gpiochip_direction_input(guard.gc, 2887 - gpio_chip_hwgpio(desc)); 2880 + gpiod_hwgpio(desc)); 2888 2881 } else if (guard.gc->get_direction) { 2889 - dir = gpiochip_get_direction(guard.gc, gpio_chip_hwgpio(desc)); 2882 + dir = gpiochip_get_direction(guard.gc, gpiod_hwgpio(desc)); 2890 2883 if (dir < 0) 2891 2884 return dir; 2892 2885 ··· 2945 2938 2946 2939 if (guard.gc->direction_output) { 2947 2940 ret = gpiochip_direction_output(guard.gc, 2948 - gpio_chip_hwgpio(desc), val); 2941 + gpiod_hwgpio(desc), val); 2949 2942 } else { 2950 2943 /* Check that we are in output mode if we can */ 2951 2944 if (guard.gc->get_direction) { 2952 2945 dir = gpiochip_get_direction(guard.gc, 2953 - gpio_chip_hwgpio(desc)); 2946 + gpiod_hwgpio(desc)); 2954 2947 if (dir < 0) 2955 2948 return dir; 2956 2949 ··· 2965 2958 * If we can't actively set the direction, we are some 2966 2959 * output-only chip, so just drive the output as desired. 2967 2960 */ 2968 - ret = gpiochip_set(guard.gc, gpio_chip_hwgpio(desc), val); 2961 + ret = gpiochip_set(guard.gc, gpiod_hwgpio(desc), val); 2969 2962 if (ret) 2970 2963 return ret; 2971 2964 } ··· 3116 3109 } 3117 3110 3118 3111 ret = guard.gc->en_hw_timestamp(guard.gc, 3119 - gpio_chip_hwgpio(desc), flags); 3112 + gpiod_hwgpio(desc), flags); 3120 3113 if (ret) 3121 3114 gpiod_warn(desc, "%s: hw ts request failed\n", __func__); 3122 3115 ··· 3148 3141 return -ENOTSUPP; 3149 3142 } 3150 3143 3151 - ret = guard.gc->dis_hw_timestamp(guard.gc, gpio_chip_hwgpio(desc), 3144 + ret = guard.gc->dis_hw_timestamp(guard.gc, gpiod_hwgpio(desc), 3152 3145 flags); 3153 3146 if (ret) 3154 3147 gpiod_warn(desc, "%s: hw ts release failed\n", __func__); ··· 3279 3272 3280 3273 static int gpio_chip_get_value(struct gpio_chip *gc, const struct gpio_desc *desc) 3281 3274 { 3282 - return gc->get ? gpiochip_get(gc, gpio_chip_hwgpio(desc)) : -EIO; 3275 + return gc->get ? gpiochip_get(gc, gpiod_hwgpio(desc)) : -EIO; 3283 3276 } 3284 3277 3285 3278 /* I/O calls are only valid after configuration completed; the relevant ··· 3439 3432 first = i; 3440 3433 do { 3441 3434 const struct gpio_desc *desc = desc_array[i]; 3442 - int hwgpio = gpio_chip_hwgpio(desc); 3435 + int hwgpio = gpiod_hwgpio(desc); 3443 3436 3444 3437 __set_bit(hwgpio, mask); 3445 3438 i++; ··· 3461 3454 3462 3455 for (j = first; j < i; ) { 3463 3456 const struct gpio_desc *desc = desc_array[j]; 3464 - int hwgpio = gpio_chip_hwgpio(desc); 3457 + int hwgpio = gpiod_hwgpio(desc); 3465 3458 int value = test_bit(hwgpio, bits); 3466 3459 3467 3460 if (!raw && test_bit(GPIOD_FLAG_ACTIVE_LOW, &desc->flags)) ··· 3598 3591 */ 3599 3592 static int gpio_set_open_drain_value_commit(struct gpio_desc *desc, bool value) 3600 3593 { 3601 - int ret = 0, offset = gpio_chip_hwgpio(desc); 3594 + int ret = 0, offset = gpiod_hwgpio(desc); 3602 3595 3603 3596 CLASS(gpio_chip_guard, guard)(desc); 3604 3597 if (!guard.gc) ··· 3627 3620 */ 3628 3621 static int gpio_set_open_source_value_commit(struct gpio_desc *desc, bool value) 3629 3622 { 3630 - int ret = 0, offset = gpio_chip_hwgpio(desc); 3623 + int ret = 0, offset = gpiod_hwgpio(desc); 3631 3624 3632 3625 CLASS(gpio_chip_guard, guard)(desc); 3633 3626 if (!guard.gc) ··· 3659 3652 return -ENODEV; 3660 3653 3661 3654 trace_gpio_value(desc_to_gpio(desc), 0, value); 3662 - return gpiochip_set(guard.gc, gpio_chip_hwgpio(desc), value); 3655 + return gpiochip_set(guard.gc, gpiod_hwgpio(desc), value); 3663 3656 } 3664 3657 3665 3658 /* ··· 3782 3775 3783 3776 do { 3784 3777 struct gpio_desc *desc = desc_array[i]; 3785 - int hwgpio = gpio_chip_hwgpio(desc); 3778 + int hwgpio = gpiod_hwgpio(desc); 3786 3779 int value = test_bit(i, value_bitmap); 3787 3780 3788 3781 if (unlikely(!test_bit(GPIOD_FLAG_IS_OUT, &desc->flags))) ··· 4042 4035 if (!gc) 4043 4036 return -ENODEV; 4044 4037 4045 - offset = gpio_chip_hwgpio(desc); 4038 + offset = gpiod_hwgpio(desc); 4046 4039 if (gc->to_irq) { 4047 4040 ret = gc->to_irq(gc, offset); 4048 4041 if (ret) ··· 4092 4085 int dir = gpiod_get_direction(desc); 4093 4086 4094 4087 if (dir < 0) { 4095 - chip_err(gc, "%s: cannot get GPIO direction\n", 4096 - __func__); 4088 + gpiochip_err(gc, "%s: cannot get GPIO direction\n", 4089 + __func__); 4097 4090 return dir; 4098 4091 } 4099 4092 } ··· 4101 4094 /* To be valid for IRQ the line needs to be input or open drain */ 4102 4095 if (test_bit(GPIOD_FLAG_IS_OUT, &desc->flags) && 4103 4096 !test_bit(GPIOD_FLAG_OPEN_DRAIN, &desc->flags)) { 4104 - chip_err(gc, 4105 - "%s: tried to flag a GPIO set as output for IRQ\n", 4106 - __func__); 4097 + gpiochip_err(gc, 4098 + "%s: tried to flag a GPIO set as output for IRQ\n", 4099 + __func__); 4107 4100 return -EIO; 4108 4101 } 4109 4102 ··· 4180 4173 4181 4174 ret = gpiochip_lock_as_irq(gc, offset); 4182 4175 if (ret) { 4183 - chip_err(gc, "unable to lock HW IRQ %u for IRQ\n", offset); 4176 + gpiochip_err(gc, "unable to lock HW IRQ %u for IRQ\n", offset); 4184 4177 module_put(gc->gpiodev->owner); 4185 4178 return ret; 4186 4179 } ··· 5022 5015 if (test_and_set_bit(GPIOD_FLAG_IS_HOGGED, &desc->flags)) 5023 5016 return 0; 5024 5017 5025 - hwnum = gpio_chip_hwgpio(desc); 5018 + hwnum = gpiod_hwgpio(desc); 5026 5019 5027 5020 local_desc = gpiochip_request_own_desc(guard.gc, hwnum, name, 5028 5021 lflags, dflags); ··· 5103 5096 * If pin hardware number of array member 0 is also 0, select 5104 5097 * its chip as a candidate for fast bitmap processing path. 5105 5098 */ 5106 - if (descs->ndescs == 0 && gpio_chip_hwgpio(desc) == 0) { 5099 + if (descs->ndescs == 0 && gpiod_hwgpio(desc) == 0) { 5107 5100 struct gpio_descs *array; 5108 5101 5109 5102 bitmap_size = BITS_TO_LONGS(gdev->ngpio > count ? ··· 5148 5141 * Detect array members which belong to the 'fast' chip 5149 5142 * but their pins are not in hardware order. 5150 5143 */ 5151 - else if (gpio_chip_hwgpio(desc) != descs->ndescs) { 5144 + else if (gpiod_hwgpio(desc) != descs->ndescs) { 5152 5145 /* 5153 5146 * Don't use fast path if all array members processed so 5154 5147 * far belong to the same chip as this one but its pin
+15 -34
drivers/gpio/gpiolib.h
··· 275 275 struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, unsigned int hwnum); 276 276 const char *gpiod_get_label(struct gpio_desc *desc); 277 277 278 - /* 279 - * Return the GPIO number of the passed descriptor relative to its chip 280 - */ 281 - static inline int gpio_chip_hwgpio(const struct gpio_desc *desc) 282 - { 283 - return desc - &desc->gdev->descs[0]; 284 - } 285 - 286 278 /* With descriptor prefix */ 287 279 288 - #define gpiod_err(desc, fmt, ...) \ 280 + #define __gpiod_pr(level, desc, fmt, ...) \ 289 281 do { \ 290 282 scoped_guard(srcu, &desc->gdev->desc_srcu) { \ 291 - pr_err("gpio-%d (%s): " fmt, desc_to_gpio(desc), \ 292 - gpiod_get_label(desc) ? : "?", ##__VA_ARGS__); \ 283 + pr_##level("gpio-%d (%s): " fmt, desc_to_gpio(desc), \ 284 + gpiod_get_label(desc) ?: "?", ##__VA_ARGS__); \ 293 285 } \ 294 286 } while (0) 295 287 296 - #define gpiod_warn(desc, fmt, ...) \ 297 - do { \ 298 - scoped_guard(srcu, &desc->gdev->desc_srcu) { \ 299 - pr_warn("gpio-%d (%s): " fmt, desc_to_gpio(desc), \ 300 - gpiod_get_label(desc) ? : "?", ##__VA_ARGS__); \ 301 - } \ 302 - } while (0) 303 - 304 - #define gpiod_dbg(desc, fmt, ...) \ 305 - do { \ 306 - scoped_guard(srcu, &desc->gdev->desc_srcu) { \ 307 - pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), \ 308 - gpiod_get_label(desc) ? : "?", ##__VA_ARGS__); \ 309 - } \ 310 - } while (0) 288 + #define gpiod_err(desc, fmt, ...) __gpiod_pr(err, desc, fmt, ##__VA_ARGS__) 289 + #define gpiod_warn(desc, fmt, ...) __gpiod_pr(warn, desc, fmt, ##__VA_ARGS__) 290 + #define gpiod_dbg(desc, fmt, ...) __gpiod_pr(debug, desc, fmt, ##__VA_ARGS__) 311 291 312 292 /* With chip prefix */ 313 293 314 - #define chip_err(gc, fmt, ...) \ 315 - dev_err(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) 316 - #define chip_warn(gc, fmt, ...) \ 317 - dev_warn(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) 318 - #define chip_info(gc, fmt, ...) \ 319 - dev_info(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) 320 - #define chip_dbg(gc, fmt, ...) \ 321 - dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) 294 + #define __gpiochip_pr(level, gc, fmt, ...) \ 295 + do { \ 296 + dev_##level(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__); \ 297 + } while (0) 298 + 299 + #define gpiochip_err(gc, fmt, ...) __gpiochip_pr(err, gc, fmt, ##__VA_ARGS__) 300 + #define gpiochip_warn(gc, fmt, ...) __gpiochip_pr(warn, gc, fmt, ##__VA_ARGS__) 301 + #define gpiochip_info(gc, fmt, ...) __gpiochip_pr(info, gc, fmt, ##__VA_ARGS__) 302 + #define gpiochip_dbg(gc, fmt, ...) __gpiochip_pr(dbg, gc, fmt, ##__VA_ARGS__) 322 303 323 304 #endif /* GPIOLIB_H */
+13
drivers/platform/x86/intel/Kconfig
··· 41 41 To compile this driver as a module, choose M here: the module will 42 42 be called intel_vbtn. 43 43 44 + config INTEL_EHL_PSE_IO 45 + tristate "Intel Elkhart Lake PSE I/O driver" 46 + depends on PCI 47 + select AUXILIARY_BUS 48 + help 49 + Select this option to enable Intel Elkhart Lake PSE GPIO and Timed 50 + I/O support. This driver enumerates the PCI parent device and 51 + creates auxiliary child devices for these capabilities. The actual 52 + functionalities are provided by their respective auxiliary drivers. 53 + 54 + To compile this driver as a module, choose M here: the module will 55 + be called intel_ehl_pse_io. 56 + 44 57 config INTEL_INT0002_VGPIO 45 58 tristate "Intel ACPI INT0002 Virtual GPIO driver" 46 59 depends on GPIOLIB && ACPI && PM_SLEEP
+1
drivers/platform/x86/intel/Makefile
··· 21 21 intel-target-$(CONFIG_INTEL_VBTN) += vbtn.o 22 22 23 23 # Intel miscellaneous drivers 24 + intel-target-$(CONFIG_INTEL_EHL_PSE_IO) += ehl_pse_io.o 24 25 intel-target-$(CONFIG_INTEL_INT0002_VGPIO) += int0002_vgpio.o 25 26 intel-target-$(CONFIG_INTEL_ISHTP_ECLITE) += ishtp_eclite.o 26 27 intel-target-$(CONFIG_INTEL_OAKTRAIL) += oaktrail.o
+20 -9
drivers/platform/x86/intel/chtwc_int33fe.c
··· 77 77 * software node. 78 78 */ 79 79 static struct software_node_ref_args fusb302_mux_refs[] = { 80 - { .node = NULL }, 80 + SOFTWARE_NODE_REFERENCE(NULL), 81 81 }; 82 82 83 83 static const struct property_entry fusb302_properties[] = { ··· 190 190 { 191 191 software_node_unregister_node_group(node_group); 192 192 193 - if (fusb302_mux_refs[0].node) { 194 - fwnode_handle_put(software_node_fwnode(fusb302_mux_refs[0].node)); 195 - fusb302_mux_refs[0].node = NULL; 196 - } 197 - 198 193 if (data->dp) { 199 194 data->dp->secondary = NULL; 200 195 fwnode_handle_put(data->dp); ··· 197 202 } 198 203 } 199 204 200 - static int cht_int33fe_add_nodes(struct cht_int33fe_data *data) 205 + static void cht_int33fe_put_swnode(void *data) 206 + { 207 + struct fwnode_handle *fwnode = data; 208 + 209 + fwnode_handle_put(fwnode); 210 + fusb302_mux_refs[0] = SOFTWARE_NODE_REFERENCE(NULL); 211 + } 212 + 213 + static int cht_int33fe_add_nodes(struct device *dev, struct cht_int33fe_data *data) 201 214 { 202 215 const struct software_node *mux_ref_node; 203 216 int ret; ··· 215 212 * until the mux driver has created software node for the mux device. 216 213 * It means we depend on the mux driver. This function will return 217 214 * -EPROBE_DEFER until the mux device is registered. 215 + * 216 + * FIXME: the relevant software node exists in intel-xhci-usb-role-switch 217 + * and - if exported - could be used to set up a static reference. 218 218 */ 219 219 mux_ref_node = software_node_find_by_name(NULL, "intel-xhci-usb-sw"); 220 220 if (!mux_ref_node) 221 221 return -EPROBE_DEFER; 222 + 223 + ret = devm_add_action_or_reset(dev, cht_int33fe_put_swnode, 224 + software_node_fwnode(mux_ref_node)); 225 + if (ret) 226 + return ret; 222 227 223 228 /* 224 229 * Update node used in "usb-role-switch" property. Note that we 225 230 * rely on software_node_register_node_group() to use the original 226 231 * instance of properties instead of copying them. 227 232 */ 228 - fusb302_mux_refs[0].node = mux_ref_node; 233 + fusb302_mux_refs[0] = SOFTWARE_NODE_REFERENCE(mux_ref_node); 229 234 230 235 ret = software_node_register_node_group(node_group); 231 236 if (ret) ··· 356 345 return fusb302_irq; 357 346 } 358 347 359 - ret = cht_int33fe_add_nodes(data); 348 + ret = cht_int33fe_add_nodes(dev, data); 360 349 if (ret) 361 350 return ret; 362 351
+86
drivers/platform/x86/intel/ehl_pse_io.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Intel Elkhart Lake Programmable Service Engine (PSE) I/O 4 + * 5 + * Copyright (c) 2025 Intel Corporation. 6 + * 7 + * Author: Raag Jadav <raag.jadav@intel.com> 8 + */ 9 + 10 + #include <linux/auxiliary_bus.h> 11 + #include <linux/device/devres.h> 12 + #include <linux/errno.h> 13 + #include <linux/gfp_types.h> 14 + #include <linux/ioport.h> 15 + #include <linux/mod_devicetable.h> 16 + #include <linux/module.h> 17 + #include <linux/pci.h> 18 + #include <linux/sizes.h> 19 + #include <linux/types.h> 20 + 21 + #include <linux/ehl_pse_io_aux.h> 22 + 23 + #define EHL_PSE_IO_DEV_SIZE SZ_4K 24 + 25 + static int ehl_pse_io_dev_create(struct pci_dev *pci, const char *name, int idx) 26 + { 27 + struct device *dev = &pci->dev; 28 + struct auxiliary_device *adev; 29 + struct ehl_pse_io_data *data; 30 + resource_size_t start, offset; 31 + u32 id; 32 + 33 + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 34 + if (!data) 35 + return -ENOMEM; 36 + 37 + id = (pci_domain_nr(pci->bus) << 16) | pci_dev_id(pci); 38 + start = pci_resource_start(pci, 0); 39 + offset = EHL_PSE_IO_DEV_SIZE * idx; 40 + 41 + data->mem = DEFINE_RES_MEM(start + offset, EHL_PSE_IO_DEV_SIZE); 42 + data->irq = pci_irq_vector(pci, idx); 43 + 44 + adev = __devm_auxiliary_device_create(dev, EHL_PSE_IO_NAME, name, data, id); 45 + 46 + return adev ? 0 : -ENODEV; 47 + } 48 + 49 + static int ehl_pse_io_probe(struct pci_dev *pci, const struct pci_device_id *id) 50 + { 51 + int ret; 52 + 53 + ret = pcim_enable_device(pci); 54 + if (ret) 55 + return ret; 56 + 57 + pci_set_master(pci); 58 + 59 + ret = pci_alloc_irq_vectors(pci, 2, 2, PCI_IRQ_MSI); 60 + if (ret < 0) 61 + return ret; 62 + 63 + ret = ehl_pse_io_dev_create(pci, EHL_PSE_GPIO_NAME, 0); 64 + if (ret) 65 + return ret; 66 + 67 + return ehl_pse_io_dev_create(pci, EHL_PSE_TIO_NAME, 1); 68 + } 69 + 70 + static const struct pci_device_id ehl_pse_io_ids[] = { 71 + { PCI_VDEVICE(INTEL, 0x4b88) }, 72 + { PCI_VDEVICE(INTEL, 0x4b89) }, 73 + { } 74 + }; 75 + MODULE_DEVICE_TABLE(pci, ehl_pse_io_ids); 76 + 77 + static struct pci_driver ehl_pse_io_driver = { 78 + .name = EHL_PSE_IO_NAME, 79 + .id_table = ehl_pse_io_ids, 80 + .probe = ehl_pse_io_probe, 81 + }; 82 + module_pci_driver(ehl_pse_io_driver); 83 + 84 + MODULE_AUTHOR("Raag Jadav <raag.jadav@intel.com>"); 85 + MODULE_DESCRIPTION("Intel Elkhart Lake PSE I/O driver"); 86 + MODULE_LICENSE("GPL");
+1
drivers/reset/Kconfig
··· 89 89 config RESET_GPIO 90 90 tristate "GPIO reset controller" 91 91 depends on GPIOLIB 92 + select AUXILIARY_BUS 92 93 help 93 94 This enables a generic reset controller for resets attached via 94 95 GPIOs. Typically for OF platforms this driver expects "reset-gpios"
+84 -62
drivers/reset/core.c
··· 4 4 * 5 5 * Copyright 2013 Philipp Zabel, Pengutronix 6 6 */ 7 + 8 + #include <linux/acpi.h> 7 9 #include <linux/atomic.h> 10 + #include <linux/auxiliary_bus.h> 8 11 #include <linux/cleanup.h> 9 12 #include <linux/device.h> 10 13 #include <linux/err.h> 11 14 #include <linux/export.h> 12 - #include <linux/kernel.h> 13 - #include <linux/kref.h> 14 15 #include <linux/gpio/driver.h> 15 16 #include <linux/gpio/machine.h> 17 + #include <linux/gpio/property.h> 16 18 #include <linux/idr.h> 19 + #include <linux/kernel.h> 20 + #include <linux/kref.h> 17 21 #include <linux/module.h> 18 22 #include <linux/of.h> 19 - #include <linux/acpi.h> 20 - #include <linux/platform_device.h> 21 23 #include <linux/reset.h> 22 24 #include <linux/reset-controller.h> 23 25 #include <linux/slab.h> ··· 78 76 /** 79 77 * struct reset_gpio_lookup - lookup key for ad-hoc created reset-gpio devices 80 78 * @of_args: phandle to the reset controller with all the args like GPIO number 79 + * @swnode: Software node containing the reference to the GPIO provider 81 80 * @list: list entry for the reset_gpio_lookup_list 82 81 */ 83 82 struct reset_gpio_lookup { 84 83 struct of_phandle_args of_args; 84 + struct fwnode_handle *swnode; 85 85 struct list_head list; 86 86 }; 87 87 ··· 852 848 kref_put(&rstc->refcnt, __reset_control_release); 853 849 } 854 850 855 - static int __reset_add_reset_gpio_lookup(int id, struct device_node *np, 856 - unsigned int gpio, 857 - unsigned int of_flags) 851 + static void reset_gpio_aux_device_release(struct device *dev) 858 852 { 859 - const struct fwnode_handle *fwnode = of_fwnode_handle(np); 860 - unsigned int lookup_flags; 861 - const char *label_tmp; 853 + struct auxiliary_device *adev = to_auxiliary_dev(dev); 862 854 863 - /* 864 - * Later we map GPIO flags between OF and Linux, however not all 865 - * constants from include/dt-bindings/gpio/gpio.h and 866 - * include/linux/gpio/machine.h match each other. 867 - */ 868 - if (of_flags > GPIO_ACTIVE_LOW) { 869 - pr_err("reset-gpio code does not support GPIO flags %u for GPIO %u\n", 870 - of_flags, gpio); 871 - return -EINVAL; 855 + kfree(adev); 856 + } 857 + 858 + static int reset_add_gpio_aux_device(struct device *parent, 859 + struct fwnode_handle *swnode, 860 + int id, void *pdata) 861 + { 862 + struct auxiliary_device *adev; 863 + int ret; 864 + 865 + adev = kzalloc(sizeof(*adev), GFP_KERNEL); 866 + if (!adev) 867 + return -ENOMEM; 868 + 869 + adev->id = id; 870 + adev->name = "gpio"; 871 + adev->dev.parent = parent; 872 + adev->dev.platform_data = pdata; 873 + adev->dev.release = reset_gpio_aux_device_release; 874 + device_set_node(&adev->dev, swnode); 875 + 876 + ret = auxiliary_device_init(adev); 877 + if (ret) { 878 + kfree(adev); 879 + return ret; 872 880 } 873 881 874 - struct gpio_device *gdev __free(gpio_device_put) = gpio_device_find_by_fwnode(fwnode); 875 - if (!gdev) 876 - return -EPROBE_DEFER; 882 + ret = __auxiliary_device_add(adev, "reset"); 883 + if (ret) { 884 + auxiliary_device_uninit(adev); 885 + kfree(adev); 886 + return ret; 887 + } 877 888 878 - label_tmp = gpio_device_get_label(gdev); 879 - if (!label_tmp) 880 - return -EINVAL; 881 - 882 - char *label __free(kfree) = kstrdup(label_tmp, GFP_KERNEL); 883 - if (!label) 884 - return -ENOMEM; 885 - 886 - /* Size: one lookup entry plus sentinel */ 887 - struct gpiod_lookup_table *lookup __free(kfree) = kzalloc(struct_size(lookup, table, 2), 888 - GFP_KERNEL); 889 - if (!lookup) 890 - return -ENOMEM; 891 - 892 - lookup->dev_id = kasprintf(GFP_KERNEL, "reset-gpio.%d", id); 893 - if (!lookup->dev_id) 894 - return -ENOMEM; 895 - 896 - lookup_flags = GPIO_PERSISTENT; 897 - lookup_flags |= of_flags & GPIO_ACTIVE_LOW; 898 - lookup->table[0] = GPIO_LOOKUP(no_free_ptr(label), gpio, "reset", 899 - lookup_flags); 900 - 901 - /* Not freed on success, because it is persisent subsystem data. */ 902 - gpiod_add_lookup_table(no_free_ptr(lookup)); 903 - 904 - return 0; 889 + return ret; 905 890 } 906 891 907 892 /* ··· 898 905 */ 899 906 static int __reset_add_reset_gpio_device(const struct of_phandle_args *args) 900 907 { 908 + struct property_entry properties[2] = { }; 909 + unsigned int offset, of_flags, lflags; 901 910 struct reset_gpio_lookup *rgpio_dev; 902 - struct platform_device *pdev; 911 + struct device *parent; 903 912 int id, ret; 904 913 905 914 /* ··· 920 925 */ 921 926 lockdep_assert_not_held(&reset_list_mutex); 922 927 928 + offset = args->args[0]; 929 + of_flags = args->args[1]; 930 + 931 + /* 932 + * Later we map GPIO flags between OF and Linux, however not all 933 + * constants from include/dt-bindings/gpio/gpio.h and 934 + * include/linux/gpio/machine.h match each other. 935 + * 936 + * FIXME: Find a better way of translating OF flags to GPIO lookup 937 + * flags. 938 + */ 939 + if (of_flags > GPIO_ACTIVE_LOW) { 940 + pr_err("reset-gpio code does not support GPIO flags %u for GPIO %u\n", 941 + of_flags, offset); 942 + return -EINVAL; 943 + } 944 + 945 + struct gpio_device *gdev __free(gpio_device_put) = 946 + gpio_device_find_by_fwnode(of_fwnode_handle(args->np)); 947 + if (!gdev) 948 + return -EPROBE_DEFER; 949 + 923 950 guard(mutex)(&reset_gpio_lookup_mutex); 924 951 925 952 list_for_each_entry(rgpio_dev, &reset_gpio_lookup_list, list) { ··· 950 933 return 0; /* Already on the list, done */ 951 934 } 952 935 } 936 + 937 + lflags = GPIO_PERSISTENT | (of_flags & GPIO_ACTIVE_LOW); 938 + parent = gpio_device_to_device(gdev); 939 + properties[0] = PROPERTY_ENTRY_GPIO("reset-gpios", parent->fwnode, offset, lflags); 953 940 954 941 id = ida_alloc(&reset_gpio_ida, GFP_KERNEL); 955 942 if (id < 0) ··· 966 945 goto err_ida_free; 967 946 } 968 947 969 - ret = __reset_add_reset_gpio_lookup(id, args->np, args->args[0], 970 - args->args[1]); 971 - if (ret < 0) 972 - goto err_kfree; 973 - 974 948 rgpio_dev->of_args = *args; 975 949 /* 976 950 * We keep the device_node reference, but of_args.np is put at the end ··· 973 957 * Hold reference as long as rgpio_dev memory is valid. 974 958 */ 975 959 of_node_get(rgpio_dev->of_args.np); 976 - pdev = platform_device_register_data(NULL, "reset-gpio", id, 977 - &rgpio_dev->of_args, 978 - sizeof(rgpio_dev->of_args)); 979 - ret = PTR_ERR_OR_ZERO(pdev); 960 + 961 + rgpio_dev->swnode = fwnode_create_software_node(properties, NULL); 962 + if (IS_ERR(rgpio_dev->swnode)) { 963 + ret = PTR_ERR(rgpio_dev->swnode); 964 + goto err_put_of_node; 965 + } 966 + 967 + ret = reset_add_gpio_aux_device(parent, rgpio_dev->swnode, id, 968 + &rgpio_dev->of_args); 980 969 if (ret) 981 - goto err_put; 970 + goto err_del_swnode; 982 971 983 972 list_add(&rgpio_dev->list, &reset_gpio_lookup_list); 984 973 985 974 return 0; 986 975 987 - err_put: 976 + err_del_swnode: 977 + fwnode_remove_software_node(rgpio_dev->swnode); 978 + err_put_of_node: 988 979 of_node_put(rgpio_dev->of_args.np); 989 - err_kfree: 990 980 kfree(rgpio_dev); 991 981 err_ida_free: 992 982 ida_free(&reset_gpio_ida, id);
+10 -9
drivers/reset/reset-gpio.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 + #include <linux/auxiliary_bus.h> 3 4 #include <linux/gpio/consumer.h> 4 5 #include <linux/mod_devicetable.h> 5 6 #include <linux/module.h> 6 7 #include <linux/of.h> 7 - #include <linux/platform_device.h> 8 8 #include <linux/reset-controller.h> 9 9 10 10 struct reset_gpio_priv { ··· 61 61 of_node_put(data); 62 62 } 63 63 64 - static int reset_gpio_probe(struct platform_device *pdev) 64 + static int reset_gpio_probe(struct auxiliary_device *adev, 65 + const struct auxiliary_device_id *id) 65 66 { 66 - struct device *dev = &pdev->dev; 67 + struct device *dev = &adev->dev; 67 68 struct of_phandle_args *platdata = dev_get_platdata(dev); 68 69 struct reset_gpio_priv *priv; 69 70 int ret; ··· 76 75 if (!priv) 77 76 return -ENOMEM; 78 77 79 - platform_set_drvdata(pdev, &priv->rc); 78 + auxiliary_set_drvdata(adev, &priv->rc); 80 79 81 80 priv->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); 82 81 if (IS_ERR(priv->reset)) ··· 100 99 return devm_reset_controller_register(dev, &priv->rc); 101 100 } 102 101 103 - static const struct platform_device_id reset_gpio_ids[] = { 104 - { .name = "reset-gpio", }, 102 + static const struct auxiliary_device_id reset_gpio_ids[] = { 103 + { .name = "reset.gpio" }, 105 104 {} 106 105 }; 107 - MODULE_DEVICE_TABLE(platform, reset_gpio_ids); 106 + MODULE_DEVICE_TABLE(auxiliary, reset_gpio_ids); 108 107 109 - static struct platform_driver reset_gpio_driver = { 108 + static struct auxiliary_driver reset_gpio_driver = { 110 109 .probe = reset_gpio_probe, 111 110 .id_table = reset_gpio_ids, 112 111 .driver = { 113 112 .name = "reset-gpio", 114 113 }, 115 114 }; 116 - module_platform_driver(reset_gpio_driver); 115 + module_auxiliary_driver(reset_gpio_driver); 117 116 118 117 MODULE_AUTHOR("Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>"); 119 118 MODULE_DESCRIPTION("Generic GPIO reset driver");
+10 -30
drivers/spi/spi-cs42l43.c
··· 52 52 .mode = SPI_MODE_0, 53 53 }; 54 54 55 - static const struct software_node cs42l43_gpiochip_swnode = { 56 - .name = "cs42l43-pinctrl", 57 - }; 58 - 59 - static const struct software_node_ref_args cs42l43_cs_refs[] = { 60 - SOFTWARE_NODE_REFERENCE(&cs42l43_gpiochip_swnode, 0, GPIO_ACTIVE_LOW), 61 - SOFTWARE_NODE_REFERENCE(&swnode_gpio_undefined), 62 - }; 63 - 64 - static const struct property_entry cs42l43_cs_props[] = { 65 - PROPERTY_ENTRY_REF_ARRAY("cs-gpios", cs42l43_cs_refs), 66 - {} 67 - }; 68 - 69 55 static int cs42l43_spi_tx(struct regmap *regmap, const u8 *buf, unsigned int len) 70 56 { 71 57 const u8 *end = buf + len; ··· 310 324 fwnode_handle_put(data); 311 325 } 312 326 313 - static void cs42l43_release_sw_node(void *data) 314 - { 315 - software_node_unregister(&cs42l43_gpiochip_swnode); 316 - } 317 - 318 327 static int cs42l43_spi_probe(struct platform_device *pdev) 319 328 { 320 329 struct cs42l43 *cs42l43 = dev_get_drvdata(pdev->dev.parent); ··· 372 391 fwnode_property_read_u32(xu_fwnode, "01fa-sidecar-instances", &nsidecars); 373 392 374 393 if (nsidecars) { 394 + struct software_node_ref_args args[] = { 395 + SOFTWARE_NODE_REFERENCE(fwnode, 0, GPIO_ACTIVE_LOW), 396 + SOFTWARE_NODE_REFERENCE(&swnode_gpio_undefined), 397 + }; 398 + struct property_entry props[] = { 399 + PROPERTY_ENTRY_REF_ARRAY("cs-gpios", args), 400 + { } 401 + }; 402 + 375 403 ret = fwnode_property_read_u32(xu_fwnode, "01fa-spk-id-val", &spkid); 376 404 if (!ret) { 377 405 dev_dbg(priv->dev, "01fa-spk-id-val = %d\n", spkid); ··· 393 403 "Failed to get spk-id-gpios\n"); 394 404 } 395 405 396 - ret = software_node_register(&cs42l43_gpiochip_swnode); 397 - if (ret) 398 - return dev_err_probe(priv->dev, ret, 399 - "Failed to register gpio swnode\n"); 400 - 401 - ret = devm_add_action_or_reset(priv->dev, cs42l43_release_sw_node, NULL); 402 - if (ret) 403 - return ret; 404 - 405 - ret = device_create_managed_software_node(&priv->ctlr->dev, 406 - cs42l43_cs_props, NULL); 406 + ret = device_create_managed_software_node(&priv->ctlr->dev, props, NULL); 407 407 if (ret) 408 408 return dev_err_probe(priv->dev, ret, "Failed to add swnode\n"); 409 409 } else {
+24
include/linux/ehl_pse_io_aux.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Intel Elkhart Lake PSE I/O Auxiliary Device 4 + * 5 + * Copyright (c) 2025 Intel Corporation. 6 + * 7 + * Author: Raag Jadav <raag.jadav@intel.com> 8 + */ 9 + 10 + #ifndef _EHL_PSE_IO_AUX_H_ 11 + #define _EHL_PSE_IO_AUX_H_ 12 + 13 + #include <linux/ioport.h> 14 + 15 + #define EHL_PSE_IO_NAME "ehl_pse_io" 16 + #define EHL_PSE_GPIO_NAME "gpio" 17 + #define EHL_PSE_TIO_NAME "pps_tio" 18 + 19 + struct ehl_pse_io_data { 20 + struct resource mem; 21 + int irq; 22 + }; 23 + 24 + #endif /* _EHL_PSE_IO_AUX_H_ */
+2
include/linux/gpio/consumer.h
··· 173 173 struct gpio_desc *gpio_to_desc(unsigned gpio); 174 174 int desc_to_gpio(const struct gpio_desc *desc); 175 175 176 + int gpiod_hwgpio(const struct gpio_desc *desc); 177 + 176 178 struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode, 177 179 const char *con_id, int index, 178 180 enum gpiod_flags flags,
-36
include/linux/gpio/legacy-of-mm-gpiochip.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * OF helpers for the old of_mm_gpio_chip, used on ppc32 and nios2, 4 - * do not use in new code. 5 - * 6 - * Copyright (c) 2007-2008 MontaVista Software, Inc. 7 - * 8 - * Author: Anton Vorontsov <avorontsov@ru.mvista.com> 9 - */ 10 - 11 - #ifndef __LINUX_GPIO_LEGACY_OF_MM_GPIO_CHIP_H 12 - #define __LINUX_GPIO_LEGACY_OF_MM_GPIO_CHIP_H 13 - 14 - #include <linux/gpio/driver.h> 15 - #include <linux/of.h> 16 - 17 - /* 18 - * OF GPIO chip for memory mapped banks 19 - */ 20 - struct of_mm_gpio_chip { 21 - struct gpio_chip gc; 22 - void (*save_regs)(struct of_mm_gpio_chip *mm_gc); 23 - void __iomem *regs; 24 - }; 25 - 26 - static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc) 27 - { 28 - return container_of(gc, struct of_mm_gpio_chip, gc); 29 - } 30 - 31 - extern int of_mm_gpiochip_add_data(struct device_node *np, 32 - struct of_mm_gpio_chip *mm_gc, 33 - void *data); 34 - extern void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc); 35 - 36 - #endif /* __LINUX_GPIO_LEGACY_OF_MM_GPIO_CHIP_H */
+2 -2
include/linux/gpio/regmap.h
··· 50 50 * @regmap_irq_chip: (Optional) Pointer on an regmap_irq_chip structure. If 51 51 * set, a regmap-irq device will be created and the IRQ 52 52 * domain will be set accordingly. 53 - * @regmap_irq_line (Optional) The IRQ the device uses to signal interrupts. 54 - * @regmap_irq_flags (Optional) The IRQF_ flags to use for the interrupt. 53 + * @regmap_irq_line: (Optional) The IRQ the device uses to signal interrupts. 54 + * @regmap_irq_flags: (Optional) The IRQF_ flags to use for the interrupt. 55 55 * 56 56 * The ->reg_mask_xlate translates a given base address and GPIO offset to 57 57 * register and mask pair. The base address is one of the given register
+10 -3
include/linux/property.h
··· 355 355 356 356 /** 357 357 * struct software_node_ref_args - Reference property with additional arguments 358 - * @node: Reference to a software node 358 + * @swnode: Reference to a software node 359 + * @fwnode: Alternative reference to a firmware node handle 359 360 * @nargs: Number of elements in @args array 360 361 * @args: Integer arguments 361 362 */ 362 363 struct software_node_ref_args { 363 - const struct software_node *node; 364 + const struct software_node *swnode; 365 + struct fwnode_handle *fwnode; 364 366 unsigned int nargs; 365 367 u64 args[NR_FWNODE_REFERENCE_ARGS]; 366 368 }; 367 369 368 370 #define SOFTWARE_NODE_REFERENCE(_ref_, ...) \ 369 371 (const struct software_node_ref_args) { \ 370 - .node = _ref_, \ 372 + .swnode = _Generic(_ref_, \ 373 + const struct software_node *: _ref_, \ 374 + default: NULL), \ 375 + .fwnode = _Generic(_ref_, \ 376 + struct fwnode_handle *: _ref_, \ 377 + default: NULL), \ 371 378 .nargs = COUNT_ARGS(__VA_ARGS__), \ 372 379 .args = { __VA_ARGS__ }, \ 373 380 }
+4 -3
include/linux/string.h
··· 564 564 565 565 /** 566 566 * strends - Check if a string ends with another string. 567 - * @str - NULL-terminated string to check against @suffix 568 - * @suffix - NULL-terminated string defining the suffix to look for in @str 567 + * @str: NULL-terminated string to check against @suffix 568 + * @suffix: NULL-terminated string defining the suffix to look for in @str 569 569 * 570 570 * Returns: 571 571 * True if @str ends with @suffix. False in all other cases. 572 572 */ 573 - static inline bool strends(const char *str, const char *suffix) 573 + static inline bool __attribute__((nonnull(1, 2))) 574 + strends(const char *str, const char *suffix) 574 575 { 575 576 unsigned int str_len = strlen(str), suffix_len = strlen(suffix); 576 577