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

Configure Feed

Select the types of activity you want to include in your feed.

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

Pull gpio updates from Bartosz Golaszewski:
"Core GPIOLIB:
- provide and add users for a macro allowing to iterate over accepted
GPIO property names of consumer device nodes
- remove legacy definitions that are no longer used
- put legacy GPIO devres helpers together with the rest of the
deprecated code
- implement and use swnode_gpio_get_reference(): a wrapper
simplifying the underlying calls to
fwnode_property_get_reference_args()
- use IS_ERR_OR_NULL() where it makes sense
- replace of_find_property() with of_property_present()
- simplify code with the scoped variant of OF-node children iterator

Documentation:
- update GPIO kerneldocs with Return sections
- fix "Excess struct member description" warnings now being triggered
with W=1

New drivers:
- add support for Analog Devices ADP5585

Driver improvements:
- add support for wake-on-GPIO to gpio-mpc8xxx
- use GPIO_LOOKUP_IDX() in gpio-virtuser
- use devm_clk_get_[optional_]enabled() where applicable in several
drivers
- replace OF-specific functions with provider-agnostic alternatives
where possible
- drop support for legacy platform data from gpio-ath79 and
gpio-davinci
- refactor gpio-stmpe
- improve error reporting in gpio-pca953x
- add support for reading the direction of pins for some models to
gpio-vf610

DT bindings:
- convert the bindings for nxp,lpc3220 to YAML
- add gpio-reserved-ranges to gpio-davinci
- simplify the GPIO hog schema
- fix a GPIO hog issue in bindings for fcs,fxl6408

Other:
- fix format specifiers in user-space tools
- remove leftover files on make clean in tools/gpio/"

* tag 'gpio-updates-for-v6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: (54 commits)
gpio: mpc8xxx: switch to using DEFINE_RUNTIME_DEV_PM_OPS()
gpio: xilinx: Use helper function devm_clk_get_optional_enabled()
gpio: mb86s7x: Use helper function devm_clk_get_optional_enabled()
gpio: lpc18xx: Use helper function devm_clk_get_enabled()
gpio: cadence: Use helper function devm_clk_get_enabled()
gpio: sama5d2-piobu: convert comma to semicolon
gpio: mpc8xxx: order headers alphabetically
gpio: davinci: use devm_clk_get_enabled()
gpio: davinci: drop platform data support
gpio: stmpe: Sort headers
gpio: stmpe: Make use of device properties
gpio: stmpe: Utilise temporary variable for struct device
gpio: stmpe: Remove unused 'dev' member of struct stmpe_gpio
gpio: stmpe: Fix IRQ related error messages
gpio: pch: kerneldoc fixes for excess members
gpio: zynq: Simplify using devm_clk_get_enabled()
gpio: mpc8xxx: Add wake on GPIO support
gpio: syscon: fix excess struct member build warning
gpio: stp-xway: Simplify using devm_clk_get_enabled()
gpiolib: legacy: Consolidate devm_gpio_*() with other legacy APIs
...

+627 -639
-11
Documentation/devicetree/bindings/gpio/fairchild,74hc595.yaml
··· 36 36 patternProperties: 37 37 "^(hog-[0-9]+|.+-hog(-[0-9]+)?)$": 38 38 type: object 39 - 40 - properties: 41 - gpio-hog: true 42 - gpios: true 43 - output-high: true 44 - output-low: true 45 - line-name: true 46 - 47 39 required: 48 40 - gpio-hog 49 - - gpios 50 - 51 - additionalProperties: false 52 41 53 42 required: 54 43 - compatible
+1
Documentation/devicetree/bindings/gpio/fcs,fxl6408.yaml
··· 28 28 29 29 patternProperties: 30 30 "^(hog-[0-9]+|.+-hog(-[0-9]+)?)$": 31 + type: object 31 32 required: 32 33 - gpio-hog 33 34
-11
Documentation/devicetree/bindings/gpio/fsl-imx-gpio.yaml
··· 85 85 patternProperties: 86 86 "^(hog-[0-9]+|.+-hog(-[0-9]+)?)$": 87 87 type: object 88 - properties: 89 - gpio-hog: true 90 - gpios: true 91 - input: true 92 - output-high: true 93 - output-low: true 94 - line-name: true 95 - 96 88 required: 97 89 - gpio-hog 98 - - gpios 99 - 100 - additionalProperties: false 101 90 102 91 required: 103 92 - compatible
+2
Documentation/devicetree/bindings/gpio/gpio-davinci.yaml
··· 32 32 33 33 gpio-ranges: true 34 34 35 + gpio-reserved-ranges: true 36 + 35 37 gpio-line-names: 36 38 description: strings describing the names of each gpio line. 37 39 minItems: 1
-11
Documentation/devicetree/bindings/gpio/gpio-pca95xx.yaml
··· 107 107 patternProperties: 108 108 "^(hog-[0-9]+|.+-hog(-[0-9]+)?)$": 109 109 type: object 110 - properties: 111 - gpio-hog: true 112 - gpios: true 113 - input: true 114 - output-high: true 115 - output-low: true 116 - line-name: true 117 - 118 110 required: 119 111 - gpio-hog 120 - - gpios 121 - 122 - additionalProperties: false 123 112 124 113 required: 125 114 - compatible
-43
Documentation/devicetree/bindings/gpio/gpio_lpc32xx.txt
··· 1 - NXP LPC32xx SoC GPIO controller 2 - 3 - Required properties: 4 - - compatible: must be "nxp,lpc3220-gpio" 5 - - reg: Physical base address and length of the controller's registers. 6 - - gpio-controller: Marks the device node as a GPIO controller. 7 - - #gpio-cells: Should be 3: 8 - 1) bank: 9 - 0: GPIO P0 10 - 1: GPIO P1 11 - 2: GPIO P2 12 - 3: GPIO P3 13 - 4: GPI P3 14 - 5: GPO P3 15 - 2) pin number 16 - 3) optional parameters: 17 - - bit 0 specifies polarity (0 for normal, 1 for inverted) 18 - - reg: Index of the GPIO group 19 - 20 - Example: 21 - 22 - gpio: gpio@40028000 { 23 - compatible = "nxp,lpc3220-gpio"; 24 - reg = <0x40028000 0x1000>; 25 - gpio-controller; 26 - #gpio-cells = <3>; /* bank, pin, flags */ 27 - }; 28 - 29 - leds { 30 - compatible = "gpio-leds"; 31 - 32 - led0 { 33 - gpios = <&gpio 5 1 1>; /* GPO_P3 1, active low */ 34 - linux,default-trigger = "heartbeat"; 35 - default-state = "off"; 36 - }; 37 - 38 - led1 { 39 - gpios = <&gpio 5 14 1>; /* GPO_P3 14, active low */ 40 - linux,default-trigger = "timer"; 41 - default-state = "off"; 42 - }; 43 - };
-12
Documentation/devicetree/bindings/gpio/microchip,mpfs-gpio.yaml
··· 49 49 patternProperties: 50 50 "^.+-hog(-[0-9]+)?$": 51 51 type: object 52 - 53 - additionalProperties: false 54 - 55 - properties: 56 - gpio-hog: true 57 - gpios: true 58 - input: true 59 - output-high: true 60 - output-low: true 61 - line-name: true 62 - 63 52 required: 64 53 - gpio-hog 65 - - gpios 66 54 67 55 allOf: 68 56 - if:
+50
Documentation/devicetree/bindings/gpio/nxp,lpc3220-gpio.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/gpio/nxp,lpc3220-gpio.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: NXP LPC3220 SoC GPIO controller 8 + 9 + maintainers: 10 + - Animesh Agarwal <animeshagarwal28@gmail.com> 11 + 12 + properties: 13 + compatible: 14 + const: nxp,lpc3220-gpio 15 + 16 + reg: 17 + maxItems: 1 18 + 19 + gpio-controller: true 20 + 21 + '#gpio-cells': 22 + const: 3 23 + description: | 24 + 1) bank: 25 + 0: GPIO P0 26 + 1: GPIO P1 27 + 2: GPIO P2 28 + 3: GPIO P3 29 + 4: GPI P3 30 + 5: GPO P3 31 + 2) pin number 32 + 3) flags: 33 + - bit 0 specifies polarity (0 for normal, 1 for inverted) 34 + 35 + required: 36 + - compatible 37 + - reg 38 + - gpio-controller 39 + - '#gpio-cells' 40 + 41 + additionalProperties: false 42 + 43 + examples: 44 + - | 45 + gpio@40028000 { 46 + compatible = "nxp,lpc3220-gpio"; 47 + reg = <0x40028000 0x1000>; 48 + gpio-controller; 49 + #gpio-cells = <3>; /* bank, pin, flags */ 50 + };
-11
Documentation/devicetree/bindings/gpio/socionext,uniphier-gpio.yaml
··· 55 55 patternProperties: 56 56 "^.+-hog(-[0-9]+)?$": 57 57 type: object 58 - properties: 59 - gpio-hog: true 60 - gpios: true 61 - input: true 62 - output-high: true 63 - output-low: true 64 - line-name: true 65 - 66 58 required: 67 59 - gpio-hog 68 - - gpios 69 - 70 - additionalProperties: false 71 60 72 61 required: 73 62 - compatible
+2 -4
arch/arm/mach-ep93xx/vision_ep9307.c
··· 76 76 { 77 77 int err; 78 78 79 - err = gpio_request_one(VISION_LCD_ENABLE, GPIOF_INIT_HIGH, 80 - dev_name(&pdev->dev)); 79 + err = gpio_request_one(VISION_LCD_ENABLE, GPIOF_OUT_INIT_HIGH, dev_name(&pdev->dev)); 81 80 if (err) 82 81 return err; 83 82 ··· 292 293 * Request the gpio expander's interrupt gpio line now to prevent 293 294 * the kernel from doing a WARN in gpiolib:gpio_ensure_requested(). 294 295 */ 295 - if (gpio_request_one(EP93XX_GPIO_LINE_F(7), GPIOF_DIR_IN, 296 - "pca9539:74")) 296 + if (gpio_request_one(EP93XX_GPIO_LINE_F(7), GPIOF_IN, "pca9539:74")) 297 297 pr_warn("cannot request interrupt gpio for pca9539:74\n"); 298 298 299 299 vision_i2c_info[1].irq = gpio_to_irq(EP93XX_GPIO_LINE_F(7));
+1 -1
arch/mips/bcm63xx/boards/board_bcm963xx.c
··· 42 42 .expected_cpu_id = 0x3368, 43 43 44 44 .ephy_reset_gpio = 36, 45 - .ephy_reset_gpio_flags = GPIOF_INIT_HIGH, 45 + .ephy_reset_gpio_flags = GPIOF_OUT_INIT_HIGH, 46 46 .has_pci = 1, 47 47 .has_uart0 = 1, 48 48 .has_uart1 = 1,
+11 -20
drivers/gpio/gpio-ath79.c
··· 8 8 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org> 9 9 */ 10 10 11 + #include <linux/device.h> 11 12 #include <linux/gpio/driver.h> 12 - #include <linux/platform_device.h> 13 - #include <linux/platform_data/gpio-ath79.h> 14 - #include <linux/of.h> 15 13 #include <linux/interrupt.h> 16 - #include <linux/module.h> 17 14 #include <linux/irq.h> 15 + #include <linux/mod_devicetable.h> 16 + #include <linux/module.h> 17 + #include <linux/platform_device.h> 18 18 19 19 #define AR71XX_GPIO_REG_OE 0x00 20 20 #define AR71XX_GPIO_REG_IN 0x04 ··· 224 224 225 225 static int ath79_gpio_probe(struct platform_device *pdev) 226 226 { 227 - struct ath79_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev); 228 227 struct device *dev = &pdev->dev; 229 - struct device_node *np = dev->of_node; 230 228 struct ath79_gpio_ctrl *ctrl; 231 229 struct gpio_irq_chip *girq; 232 230 u32 ath79_gpio_count; ··· 235 237 if (!ctrl) 236 238 return -ENOMEM; 237 239 238 - if (np) { 239 - err = of_property_read_u32(np, "ngpios", &ath79_gpio_count); 240 - if (err) { 241 - dev_err(dev, "ngpios property is not valid\n"); 242 - return err; 243 - } 244 - oe_inverted = of_device_is_compatible(np, "qca,ar9340-gpio"); 245 - } else if (pdata) { 246 - ath79_gpio_count = pdata->ngpios; 247 - oe_inverted = pdata->oe_inverted; 248 - } else { 249 - dev_err(dev, "No DT node or platform data found\n"); 250 - return -EINVAL; 240 + err = device_property_read_u32(dev, "ngpios", &ath79_gpio_count); 241 + if (err) { 242 + dev_err(dev, "ngpios property is not valid\n"); 243 + return err; 251 244 } 245 + 246 + oe_inverted = device_is_compatible(dev, "qca,ar9340-gpio"); 252 247 253 248 if (ath79_gpio_count >= 32) { 254 249 dev_err(dev, "ngpios must be less than 32\n"); ··· 266 275 } 267 276 268 277 /* Optional interrupt setup */ 269 - if (!np || of_property_read_bool(np, "interrupt-controller")) { 278 + if (device_property_read_bool(dev, "interrupt-controller")) { 270 279 girq = &ctrl->gc.irq; 271 280 gpio_irq_chip_set_chip(girq, &ath79_gpio_irqchip); 272 281 girq->parent_handler = ath79_gpio_irq_handler;
+6 -17
drivers/gpio/gpio-cadence.c
··· 31 31 32 32 struct cdns_gpio_chip { 33 33 struct gpio_chip gc; 34 - struct clk *pclk; 35 34 void __iomem *regs; 36 35 u32 bypass_orig; 37 36 }; ··· 154 155 int ret, irq; 155 156 u32 dir_prev; 156 157 u32 num_gpios = 32; 158 + struct clk *clk; 157 159 158 160 cgpio = devm_kzalloc(&pdev->dev, sizeof(*cgpio), GFP_KERNEL); 159 161 if (!cgpio) ··· 203 203 cgpio->gc.request = cdns_gpio_request; 204 204 cgpio->gc.free = cdns_gpio_free; 205 205 206 - cgpio->pclk = devm_clk_get(&pdev->dev, NULL); 207 - if (IS_ERR(cgpio->pclk)) { 208 - ret = PTR_ERR(cgpio->pclk); 206 + clk = devm_clk_get_enabled(&pdev->dev, NULL); 207 + if (IS_ERR(clk)) { 208 + ret = PTR_ERR(clk); 209 209 dev_err(&pdev->dev, 210 210 "Failed to retrieve peripheral clock, %d\n", ret); 211 - goto err_revert_dir; 212 - } 213 - 214 - ret = clk_prepare_enable(cgpio->pclk); 215 - if (ret) { 216 - dev_err(&pdev->dev, 217 - "Failed to enable the peripheral clock, %d\n", ret); 218 211 goto err_revert_dir; 219 212 } 220 213 ··· 227 234 GFP_KERNEL); 228 235 if (!girq->parents) { 229 236 ret = -ENOMEM; 230 - goto err_disable_clk; 237 + goto err_revert_dir; 231 238 } 232 239 girq->parents[0] = irq; 233 240 girq->default_type = IRQ_TYPE_NONE; ··· 237 244 ret = devm_gpiochip_add_data(&pdev->dev, &cgpio->gc, cgpio); 238 245 if (ret < 0) { 239 246 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 240 - goto err_disable_clk; 247 + goto err_revert_dir; 241 248 } 242 249 243 250 cgpio->bypass_orig = ioread32(cgpio->regs + CDNS_GPIO_BYPASS_MODE); ··· 252 259 platform_set_drvdata(pdev, cgpio); 253 260 return 0; 254 261 255 - err_disable_clk: 256 - clk_disable_unprepare(cgpio->pclk); 257 - 258 262 err_revert_dir: 259 263 iowrite32(dir_prev, cgpio->regs + CDNS_GPIO_DIRECTION_MODE); 260 264 ··· 263 273 struct cdns_gpio_chip *cgpio = platform_get_drvdata(pdev); 264 274 265 275 iowrite32(cgpio->bypass_orig, cgpio->regs + CDNS_GPIO_BYPASS_MODE); 266 - clk_disable_unprepare(cgpio->pclk); 267 276 } 268 277 269 278 static const struct of_device_id cdns_of_ids[] = {
+27 -75
drivers/gpio/gpio-davinci.c
··· 18 18 #include <linux/of.h> 19 19 #include <linux/pinctrl/consumer.h> 20 20 #include <linux/platform_device.h> 21 - #include <linux/platform_data/gpio-davinci.h> 22 21 #include <linux/property.h> 23 22 #include <linux/irqchip/chained_irq.h> 24 23 #include <linux/spinlock.h> ··· 153 154 value ? &g->set_data : &g->clr_data); 154 155 } 155 156 156 - static struct davinci_gpio_platform_data * 157 - davinci_gpio_get_pdata(struct platform_device *pdev) 158 - { 159 - struct device_node *dn = pdev->dev.of_node; 160 - struct davinci_gpio_platform_data *pdata; 161 - int ret; 162 - u32 val; 163 - 164 - if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) 165 - return dev_get_platdata(&pdev->dev); 166 - 167 - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 168 - if (!pdata) 169 - return NULL; 170 - 171 - ret = of_property_read_u32(dn, "ti,ngpio", &val); 172 - if (ret) 173 - goto of_err; 174 - 175 - pdata->ngpio = val; 176 - 177 - ret = of_property_read_u32(dn, "ti,davinci-gpio-unbanked", &val); 178 - if (ret) 179 - goto of_err; 180 - 181 - pdata->gpio_unbanked = val; 182 - 183 - return pdata; 184 - 185 - of_err: 186 - dev_err(&pdev->dev, "Populating pdata from DT failed: err %d\n", ret); 187 - return NULL; 188 - } 189 - 190 157 static int davinci_gpio_probe(struct platform_device *pdev) 191 158 { 192 159 int bank, i, ret = 0; 193 - unsigned int ngpio, nbank, nirq; 160 + unsigned int ngpio, nbank, nirq, gpio_unbanked; 194 161 struct davinci_gpio_controller *chips; 195 - struct davinci_gpio_platform_data *pdata; 196 162 struct device *dev = &pdev->dev; 197 - 198 - pdata = davinci_gpio_get_pdata(pdev); 199 - if (!pdata) { 200 - dev_err(dev, "No platform data found\n"); 201 - return -EINVAL; 202 - } 203 - 204 - dev->platform_data = pdata; 163 + struct device_node *dn = dev_of_node(dev); 205 164 206 165 /* 207 166 * The gpio banks conceptually expose a segmented bitmap, 208 167 * and "ngpio" is one more than the largest zero-based 209 168 * bit index that's valid. 210 169 */ 211 - ngpio = pdata->ngpio; 212 - if (ngpio == 0) { 213 - dev_err(dev, "How many GPIOs?\n"); 214 - return -EINVAL; 215 - } 170 + ret = of_property_read_u32(dn, "ti,ngpio", &ngpio); 171 + if (ret) 172 + return dev_err_probe(dev, ret, "Failed to get the number of GPIOs\n"); 173 + if (ngpio == 0) 174 + return dev_err_probe(dev, -EINVAL, "How many GPIOs?\n"); 216 175 217 176 /* 218 177 * If there are unbanked interrupts then the number of 219 178 * interrupts is equal to number of gpios else all are banked so 220 179 * number of interrupts is equal to number of banks(each with 16 gpios) 221 180 */ 222 - if (pdata->gpio_unbanked) 223 - nirq = pdata->gpio_unbanked; 181 + ret = of_property_read_u32(dn, "ti,davinci-gpio-unbanked", 182 + &gpio_unbanked); 183 + if (ret) 184 + return dev_err_probe(dev, ret, "Failed to get the unbanked GPIOs property\n"); 185 + 186 + if (gpio_unbanked) 187 + nirq = gpio_unbanked; 224 188 else 225 189 nirq = DIV_ROUND_UP(ngpio, 16); 226 190 ··· 214 252 chips->chip.set = davinci_gpio_set; 215 253 216 254 chips->chip.ngpio = ngpio; 217 - chips->chip.base = pdata->no_auto_base ? pdata->base : -1; 255 + chips->chip.base = -1; 218 256 219 257 #ifdef CONFIG_OF_GPIO 220 258 chips->chip.parent = dev; ··· 222 260 chips->chip.free = gpiochip_generic_free; 223 261 #endif 224 262 spin_lock_init(&chips->lock); 263 + 264 + chips->gpio_unbanked = gpio_unbanked; 225 265 226 266 nbank = DIV_ROUND_UP(ngpio, 32); 227 267 for (bank = 0; bank < nbank; bank++) ··· 446 482 { 447 483 unsigned gpio, bank; 448 484 int irq; 449 - int ret; 450 485 struct clk *clk; 451 486 u32 binten = 0; 452 487 unsigned ngpio; 453 488 struct device *dev = &pdev->dev; 454 489 struct davinci_gpio_controller *chips = platform_get_drvdata(pdev); 455 - struct davinci_gpio_platform_data *pdata = dev->platform_data; 456 490 struct davinci_gpio_regs __iomem *g; 457 491 struct irq_domain *irq_domain = NULL; 458 492 struct irq_chip *irq_chip; ··· 464 502 if (dev->of_node) 465 503 gpio_get_irq_chip = (gpio_get_irq_chip_cb_t)device_get_match_data(dev); 466 504 467 - ngpio = pdata->ngpio; 505 + ngpio = chips->chip.ngpio; 468 506 469 - clk = devm_clk_get(dev, "gpio"); 507 + clk = devm_clk_get_enabled(dev, "gpio"); 470 508 if (IS_ERR(clk)) { 471 509 dev_err(dev, "Error %ld getting gpio clock\n", PTR_ERR(clk)); 472 510 return PTR_ERR(clk); 473 511 } 474 512 475 - ret = clk_prepare_enable(clk); 476 - if (ret) 477 - return ret; 478 - 479 - if (!pdata->gpio_unbanked) { 513 + if (chips->gpio_unbanked) { 480 514 irq = devm_irq_alloc_descs(dev, -1, 0, ngpio, 0); 481 515 if (irq < 0) { 482 516 dev_err(dev, "Couldn't allocate IRQ numbers\n"); 483 - clk_disable_unprepare(clk); 484 517 return irq; 485 518 } 486 519 ··· 484 527 chips); 485 528 if (!irq_domain) { 486 529 dev_err(dev, "Couldn't register an IRQ domain\n"); 487 - clk_disable_unprepare(clk); 488 530 return -ENODEV; 489 531 } 490 532 } ··· 502 546 * controller only handling trigger modes. We currently assume no 503 547 * IRQ mux conflicts; gpio_irq_type_unbanked() is only for GPIOs. 504 548 */ 505 - if (pdata->gpio_unbanked) { 549 + if (chips->gpio_unbanked) { 506 550 /* pass "bank 0" GPIO IRQs to AINTC */ 507 551 chips->chip.to_irq = gpio_to_irq_unbanked; 508 - chips->gpio_unbanked = pdata->gpio_unbanked; 509 - binten = GENMASK(pdata->gpio_unbanked / 16, 0); 552 + 553 + binten = GENMASK(chips->gpio_unbanked / 16, 0); 510 554 511 555 /* AINTC handles mask/unmask; GPIO handles triggering */ 512 556 irq = chips->irqs[0]; ··· 520 564 writel_relaxed(~0, &g->set_rising); 521 565 522 566 /* set the direct IRQs up to use that irqchip */ 523 - for (gpio = 0; gpio < pdata->gpio_unbanked; gpio++) { 567 + for (gpio = 0; gpio < chips->gpio_unbanked; gpio++) { 524 568 irq_set_chip(chips->irqs[gpio], irq_chip); 525 569 irq_set_handler_data(chips->irqs[gpio], chips); 526 570 irq_set_status_flags(chips->irqs[gpio], ··· 552 596 sizeof(struct 553 597 davinci_gpio_irq_data), 554 598 GFP_KERNEL); 555 - if (!irqdata) { 556 - clk_disable_unprepare(clk); 599 + if (!irqdata) 557 600 return -ENOMEM; 558 - } 559 601 560 602 irqdata->regs = g; 561 603 irqdata->bank_num = bank; ··· 629 675 static int davinci_gpio_suspend(struct device *dev) 630 676 { 631 677 struct davinci_gpio_controller *chips = dev_get_drvdata(dev); 632 - struct davinci_gpio_platform_data *pdata = dev_get_platdata(dev); 633 - u32 nbank = DIV_ROUND_UP(pdata->ngpio, 32); 678 + u32 nbank = DIV_ROUND_UP(chips->chip.ngpio, 32); 634 679 635 680 davinci_gpio_save_context(chips, nbank); 636 681 ··· 639 686 static int davinci_gpio_resume(struct device *dev) 640 687 { 641 688 struct davinci_gpio_controller *chips = dev_get_drvdata(dev); 642 - struct davinci_gpio_platform_data *pdata = dev_get_platdata(dev); 643 - u32 nbank = DIV_ROUND_UP(pdata->ngpio, 32); 689 + u32 nbank = DIV_ROUND_UP(chips->chip.ngpio, 32); 644 690 645 691 davinci_gpio_restore_context(chips, nbank); 646 692
+1 -1
drivers/gpio/gpio-fxl6408.c
··· 138 138 MODULE_DEVICE_TABLE(of, fxl6408_dt_ids); 139 139 140 140 static const struct i2c_device_id fxl6408_id[] = { 141 - { "fxl6408", 0 }, 141 + { "fxl6408" }, 142 142 { } 143 143 }; 144 144 MODULE_DEVICE_TABLE(i2c, fxl6408_id);
+4 -6
drivers/gpio/gpio-ixp4xx.c
··· 6 6 // based on previous work and know-how from: 7 7 // Deepak Saxena <dsaxena@plexity.net> 8 8 9 + #include <linux/bitops.h> 9 10 #include <linux/gpio/driver.h> 10 11 #include <linux/io.h> 11 12 #include <linux/irq.h> ··· 14 13 #include <linux/irqchip.h> 15 14 #include <linux/of_irq.h> 16 15 #include <linux/platform_device.h> 17 - #include <linux/bitops.h> 16 + #include <linux/property.h> 18 17 19 18 #define IXP4XX_REG_GPOUT 0x00 20 19 #define IXP4XX_REG_GPOE 0x04 ··· 54 53 /** 55 54 * struct ixp4xx_gpio - IXP4 GPIO state container 56 55 * @dev: containing device for this instance 57 - * @fwnode: the fwnode for this GPIO chip 58 56 * @gc: gpiochip for this instance 59 57 * @base: remapped I/O-memory base 60 58 * @irq_edge: Each bit represents an IRQ: 1: edge-triggered, 61 59 * 0: level triggered 62 60 */ 63 61 struct ixp4xx_gpio { 64 - struct device *dev; 65 - struct fwnode_handle *fwnode; 66 62 struct gpio_chip gc; 63 + struct device *dev; 67 64 void __iomem *base; 68 65 unsigned long long irq_edge; 69 66 }; ··· 236 237 dev_err(dev, "no IRQ parent domain\n"); 237 238 return -ENODEV; 238 239 } 239 - g->fwnode = of_node_to_fwnode(np); 240 240 241 241 /* 242 242 * If either clock output is enabled explicitly in the device tree ··· 320 322 321 323 girq = &g->gc.irq; 322 324 gpio_irq_chip_set_chip(girq, &ixp4xx_gpio_irqchip); 323 - girq->fwnode = g->fwnode; 325 + girq->fwnode = dev_fwnode(dev); 324 326 girq->parent_domain = parent; 325 327 girq->child_to_parent_hwirq = ixp4xx_gpio_child_to_parent_hwirq; 326 328 girq->handler = handle_bad_irq;
+6 -17
drivers/gpio/gpio-lpc18xx.c
··· 47 47 struct lpc18xx_gpio_chip { 48 48 struct gpio_chip gpio; 49 49 void __iomem *base; 50 - struct clk *clk; 51 50 struct lpc18xx_gpio_pin_ic *pin_ic; 52 51 spinlock_t lock; 53 52 }; ··· 327 328 struct device *dev = &pdev->dev; 328 329 struct lpc18xx_gpio_chip *gc; 329 330 int index, ret; 331 + struct clk *clk; 330 332 331 333 gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); 332 334 if (!gc) ··· 352 352 if (IS_ERR(gc->base)) 353 353 return PTR_ERR(gc->base); 354 354 355 - gc->clk = devm_clk_get(dev, NULL); 356 - if (IS_ERR(gc->clk)) { 355 + clk = devm_clk_get_enabled(dev, NULL); 356 + if (IS_ERR(clk)) { 357 357 dev_err(dev, "input clock not found\n"); 358 - return PTR_ERR(gc->clk); 359 - } 360 - 361 - ret = clk_prepare_enable(gc->clk); 362 - if (ret) { 363 - dev_err(dev, "unable to enable clock\n"); 364 - return ret; 358 + return PTR_ERR(clk); 365 359 } 366 360 367 361 spin_lock_init(&gc->lock); ··· 363 369 gc->gpio.parent = dev; 364 370 365 371 ret = devm_gpiochip_add_data(dev, &gc->gpio, gc); 366 - if (ret) { 367 - dev_err(dev, "failed to add gpio chip\n"); 368 - clk_disable_unprepare(gc->clk); 369 - return ret; 370 - } 372 + if (ret) 373 + return dev_err_probe(dev, ret, "failed to add gpio chip\n"); 371 374 372 375 /* On error GPIO pin interrupt controller just won't be registered */ 373 376 lpc18xx_gpio_pin_ic_probe(gc); ··· 378 387 379 388 if (gc->pin_ic) 380 389 irq_domain_remove(gc->pin_ic->domain); 381 - 382 - clk_disable_unprepare(gc->clk); 383 390 } 384 391 385 392 static const struct of_device_id lpc18xx_gpio_match[] = {
+1 -1
drivers/gpio/gpio-max7300.c
··· 53 53 } 54 54 55 55 static const struct i2c_device_id max7300_id[] = { 56 - { "max7300", 0 }, 56 + { "max7300" }, 57 57 { } 58 58 }; 59 59 MODULE_DEVICE_TABLE(i2c, max7300_id);
+7 -14
drivers/gpio/gpio-mb86s7x.c
··· 35 35 struct mb86s70_gpio_chip { 36 36 struct gpio_chip gc; 37 37 void __iomem *base; 38 - struct clk *clk; 39 38 spinlock_t lock; 40 39 }; 41 40 ··· 156 157 static int mb86s70_gpio_probe(struct platform_device *pdev) 157 158 { 158 159 struct mb86s70_gpio_chip *gchip; 160 + struct clk *clk; 159 161 int ret; 160 162 161 163 gchip = devm_kzalloc(&pdev->dev, sizeof(*gchip), GFP_KERNEL); ··· 169 169 if (IS_ERR(gchip->base)) 170 170 return PTR_ERR(gchip->base); 171 171 172 - gchip->clk = devm_clk_get_optional(&pdev->dev, NULL); 173 - if (IS_ERR(gchip->clk)) 174 - return PTR_ERR(gchip->clk); 175 - 176 - ret = clk_prepare_enable(gchip->clk); 177 - if (ret) 178 - return ret; 172 + clk = devm_clk_get_optional_enabled(&pdev->dev, NULL); 173 + if (IS_ERR(clk)) 174 + return PTR_ERR(clk); 179 175 180 176 spin_lock_init(&gchip->lock); 181 177 ··· 189 193 gchip->gc.base = -1; 190 194 191 195 ret = gpiochip_add_data(&gchip->gc, gchip); 192 - if (ret) { 193 - dev_err(&pdev->dev, "couldn't register gpio driver\n"); 194 - clk_disable_unprepare(gchip->clk); 195 - return ret; 196 - } 196 + if (ret) 197 + return dev_err_probe(&pdev->dev, ret, 198 + "couldn't register gpio driver\n"); 197 199 198 200 acpi_gpiochip_request_interrupts(&gchip->gc); 199 201 ··· 204 210 205 211 acpi_gpiochip_free_interrupts(&gchip->gc); 206 212 gpiochip_remove(&gchip->gc); 207 - clk_disable_unprepare(gchip->clk); 208 213 } 209 214 210 215 static const struct of_device_id mb86s70_gpio_dt_ids[] = {
+39 -11
drivers/gpio/gpio-mpc8xxx.c
··· 7 7 */ 8 8 9 9 #include <linux/acpi.h> 10 - #include <linux/kernel.h> 11 - #include <linux/init.h> 12 - #include <linux/platform_device.h> 13 - #include <linux/spinlock.h> 14 - #include <linux/io.h> 15 - #include <linux/of.h> 16 - #include <linux/property.h> 17 - #include <linux/mod_devicetable.h> 18 - #include <linux/slab.h> 19 - #include <linux/irq.h> 20 - #include <linux/gpio/driver.h> 21 10 #include <linux/bitops.h> 11 + #include <linux/gpio/driver.h> 12 + #include <linux/init.h> 22 13 #include <linux/interrupt.h> 14 + #include <linux/io.h> 15 + #include <linux/irq.h> 16 + #include <linux/kernel.h> 17 + #include <linux/mod_devicetable.h> 18 + #include <linux/of.h> 19 + #include <linux/platform_device.h> 20 + #include <linux/pm.h> 21 + #include <linux/pm_runtime.h> 22 + #include <linux/property.h> 23 + #include <linux/slab.h> 24 + #include <linux/spinlock.h> 23 25 24 26 #define MPC8XXX_GPIO_PINS 32 25 27 ··· 415 413 goto err; 416 414 } 417 415 416 + device_init_wakeup(&pdev->dev, true); 417 + 418 418 return 0; 419 419 err: 420 420 irq_domain_remove(mpc8xxx_gc->irq); ··· 433 429 } 434 430 } 435 431 432 + static int mpc8xxx_suspend(struct device *dev) 433 + { 434 + struct mpc8xxx_gpio_chip *mpc8xxx_gc = dev_get_drvdata(dev); 435 + 436 + if (mpc8xxx_gc->irqn && device_may_wakeup(dev)) 437 + enable_irq_wake(mpc8xxx_gc->irqn); 438 + 439 + return 0; 440 + } 441 + 442 + static int mpc8xxx_resume(struct device *dev) 443 + { 444 + struct mpc8xxx_gpio_chip *mpc8xxx_gc = dev_get_drvdata(dev); 445 + 446 + if (mpc8xxx_gc->irqn && device_may_wakeup(dev)) 447 + disable_irq_wake(mpc8xxx_gc->irqn); 448 + 449 + return 0; 450 + } 451 + 452 + static DEFINE_RUNTIME_DEV_PM_OPS(mpc8xx_pm_ops, 453 + mpc8xxx_suspend, mpc8xxx_resume, NULL); 454 + 436 455 #ifdef CONFIG_ACPI 437 456 static const struct acpi_device_id gpio_acpi_ids[] = { 438 457 {"NXP0031",}, ··· 471 444 .name = "gpio-mpc8xxx", 472 445 .of_match_table = mpc8xxx_gpio_ids, 473 446 .acpi_match_table = ACPI_PTR(gpio_acpi_ids), 447 + .pm = pm_ptr(&mpc8xx_pm_ops), 474 448 }, 475 449 }; 476 450
+3 -2
drivers/gpio/gpio-msc313.c
··· 3 3 4 4 #include <linux/bitops.h> 5 5 #include <linux/kernel.h> 6 - #include <linux/types.h> 7 6 #include <linux/io.h> 8 7 #include <linux/of.h> 9 8 #include <linux/of_irq.h> 10 9 #include <linux/gpio/driver.h> 11 10 #include <linux/module.h> 12 11 #include <linux/platform_device.h> 12 + #include <linux/property.h> 13 + #include <linux/types.h> 13 14 14 15 #include <dt-bindings/gpio/msc313-gpio.h> 15 16 #include <dt-bindings/interrupt-controller/arm-gic.h> ··· 663 662 664 663 gpioirqchip = &gpiochip->irq; 665 664 gpio_irq_chip_set_chip(gpioirqchip, &msc313_gpio_irqchip); 666 - gpioirqchip->fwnode = of_node_to_fwnode(dev->of_node); 665 + gpioirqchip->fwnode = dev_fwnode(dev); 667 666 gpioirqchip->parent_domain = parent_domain; 668 667 gpioirqchip->child_to_parent_hwirq = msc313e_gpio_child_to_parent_hwirq; 669 668 gpioirqchip->populate_parent_alloc_arg = msc313_gpio_populate_parent_fwspec;
+2 -2
drivers/gpio/gpio-pca953x.c
··· 498 498 499 499 ret = regmap_bulk_write(chip->regmap, regaddr, value, NBANK(chip)); 500 500 if (ret < 0) { 501 - dev_err(&chip->client->dev, "failed writing register\n"); 501 + dev_err(&chip->client->dev, "failed writing register: %d\n", ret); 502 502 return ret; 503 503 } 504 504 ··· 513 513 514 514 ret = regmap_bulk_read(chip->regmap, regaddr, value, NBANK(chip)); 515 515 if (ret < 0) { 516 - dev_err(&chip->client->dev, "failed reading register\n"); 516 + dev_err(&chip->client->dev, "failed reading register: %d\n", ret); 517 517 return ret; 518 518 } 519 519
-1
drivers/gpio/gpio-pch.c
··· 84 84 * @gpio: Data for GPIO infrastructure. 85 85 * @pch_gpio_reg: Memory mapped Register data is saved here 86 86 * when suspend. 87 - * @lock: Used for register access protection 88 87 * @irq_base: Save base of IRQ number for interrupt 89 88 * @ioh: IOH ID 90 89 * @spinlock: Used for register access protection
+9 -9
drivers/gpio/gpio-sama5d2-piobu.c
··· 191 191 192 192 piobu->chip.label = pdev->name; 193 193 piobu->chip.parent = &pdev->dev; 194 - piobu->chip.owner = THIS_MODULE, 195 - piobu->chip.get_direction = sama5d2_piobu_get_direction, 196 - piobu->chip.direction_input = sama5d2_piobu_direction_input, 197 - piobu->chip.direction_output = sama5d2_piobu_direction_output, 198 - piobu->chip.get = sama5d2_piobu_get, 199 - piobu->chip.set = sama5d2_piobu_set, 200 - piobu->chip.base = -1, 201 - piobu->chip.ngpio = PIOBU_NUM, 202 - piobu->chip.can_sleep = 0, 194 + piobu->chip.owner = THIS_MODULE; 195 + piobu->chip.get_direction = sama5d2_piobu_get_direction; 196 + piobu->chip.direction_input = sama5d2_piobu_direction_input; 197 + piobu->chip.direction_output = sama5d2_piobu_direction_output; 198 + piobu->chip.get = sama5d2_piobu_get; 199 + piobu->chip.set = sama5d2_piobu_set; 200 + piobu->chip.base = -1; 201 + piobu->chip.ngpio = PIOBU_NUM; 202 + piobu->chip.can_sleep = 0; 203 203 204 204 piobu->regmap = syscon_node_to_regmap(pdev->dev.of_node); 205 205 if (IS_ERR(piobu->regmap)) {
+22 -33
drivers/gpio/gpio-stmpe.c
··· 5 5 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson 6 6 */ 7 7 8 - #include <linux/cleanup.h> 9 - #include <linux/init.h> 10 - #include <linux/platform_device.h> 11 - #include <linux/slab.h> 12 - #include <linux/gpio/driver.h> 13 - #include <linux/interrupt.h> 14 - #include <linux/of.h> 15 - #include <linux/mfd/stmpe.h> 16 - #include <linux/seq_file.h> 17 8 #include <linux/bitops.h> 9 + #include <linux/cleanup.h> 10 + #include <linux/gpio/driver.h> 11 + #include <linux/init.h> 12 + #include <linux/interrupt.h> 13 + #include <linux/mfd/stmpe.h> 14 + #include <linux/property.h> 15 + #include <linux/platform_device.h> 16 + #include <linux/seq_file.h> 17 + #include <linux/slab.h> 18 18 19 19 /* 20 20 * These registers are modified under the irq bus lock and cached to avoid ··· 31 31 struct stmpe_gpio { 32 32 struct gpio_chip chip; 33 33 struct stmpe *stmpe; 34 - struct device *dev; 35 34 struct mutex irq_lock; 36 35 u32 norequest_mask; 37 36 /* Caches of interrupt control registers for bus_lock */ ··· 463 464 464 465 static int stmpe_gpio_probe(struct platform_device *pdev) 465 466 { 466 - struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); 467 - struct device_node *np = pdev->dev.of_node; 467 + struct device *dev = &pdev->dev; 468 + struct stmpe *stmpe = dev_get_drvdata(dev->parent); 468 469 struct stmpe_gpio *stmpe_gpio; 469 470 int ret, irq; 470 471 471 472 if (stmpe->num_gpios > MAX_GPIOS) { 472 - dev_err(&pdev->dev, "Need to increase maximum GPIO number\n"); 473 + dev_err(dev, "Need to increase maximum GPIO number\n"); 473 474 return -EINVAL; 474 475 } 475 476 476 - stmpe_gpio = devm_kzalloc(&pdev->dev, sizeof(*stmpe_gpio), GFP_KERNEL); 477 + stmpe_gpio = devm_kzalloc(dev, sizeof(*stmpe_gpio), GFP_KERNEL); 477 478 if (!stmpe_gpio) 478 479 return -ENOMEM; 479 480 480 481 mutex_init(&stmpe_gpio->irq_lock); 481 482 482 - stmpe_gpio->dev = &pdev->dev; 483 483 stmpe_gpio->stmpe = stmpe; 484 484 stmpe_gpio->chip = template_chip; 485 485 stmpe_gpio->chip.ngpio = stmpe->num_gpios; 486 - stmpe_gpio->chip.parent = &pdev->dev; 486 + stmpe_gpio->chip.parent = dev; 487 487 stmpe_gpio->chip.base = -1; 488 488 489 489 if (IS_ENABLED(CONFIG_DEBUG_FS)) 490 490 stmpe_gpio->chip.dbg_show = stmpe_dbg_show; 491 491 492 - of_property_read_u32(np, "st,norequest-mask", 493 - &stmpe_gpio->norequest_mask); 494 - 495 - irq = platform_get_irq(pdev, 0); 496 - if (irq < 0) 497 - dev_info(&pdev->dev, 498 - "device configured in no-irq mode: " 499 - "irqs are not available\n"); 492 + device_property_read_u32(dev, "st,norequest-mask", &stmpe_gpio->norequest_mask); 500 493 501 494 ret = stmpe_enable(stmpe, STMPE_BLOCK_GPIO); 502 495 if (ret) 503 496 return ret; 504 497 505 - ret = devm_add_action_or_reset(&pdev->dev, stmpe_gpio_disable, stmpe); 498 + ret = devm_add_action_or_reset(dev, stmpe_gpio_disable, stmpe); 506 499 if (ret) 507 500 return ret; 508 501 502 + irq = platform_get_irq(pdev, 0); 509 503 if (irq > 0) { 510 504 struct gpio_irq_chip *girq; 511 505 512 - ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 513 - stmpe_gpio_irq, IRQF_ONESHOT, 514 - "stmpe-gpio", stmpe_gpio); 515 - if (ret) { 516 - dev_err(&pdev->dev, "unable to get irq: %d\n", ret); 517 - return ret; 518 - } 506 + ret = devm_request_threaded_irq(dev, irq, NULL, stmpe_gpio_irq, 507 + IRQF_ONESHOT, "stmpe-gpio", stmpe_gpio); 508 + if (ret) 509 + return dev_err_probe(dev, ret, "unable to register IRQ handler\n"); 519 510 520 511 girq = &stmpe_gpio->chip.irq; 521 512 gpio_irq_chip_set_chip(girq, &stmpe_gpio_irq_chip); ··· 519 530 girq->init_valid_mask = stmpe_init_irq_valid_mask; 520 531 } 521 532 522 - return devm_gpiochip_add_data(&pdev->dev, &stmpe_gpio->chip, stmpe_gpio); 533 + return devm_gpiochip_add_data(dev, &stmpe_gpio->chip, stmpe_gpio); 523 534 } 524 535 525 536 static struct platform_driver stmpe_gpio_driver = {
+2 -8
drivers/gpio/gpio-stp-xway.c
··· 296 296 if (!of_property_read_bool(pdev->dev.of_node, "lantiq,rising")) 297 297 chip->edge = XWAY_STP_FALLING; 298 298 299 - clk = devm_clk_get(&pdev->dev, NULL); 299 + clk = devm_clk_get_enabled(&pdev->dev, NULL); 300 300 if (IS_ERR(clk)) { 301 301 dev_err(&pdev->dev, "Failed to get clock\n"); 302 302 return PTR_ERR(clk); 303 303 } 304 304 305 - ret = clk_prepare_enable(clk); 306 - if (ret) 307 - return ret; 308 - 309 305 xway_stp_hw_init(chip); 310 306 311 307 ret = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip); 312 - if (ret) { 313 - clk_disable_unprepare(clk); 308 + if (ret) 314 309 return ret; 315 - } 316 310 317 311 dev_info(&pdev->dev, "Init done\n"); 318 312
-1
drivers/gpio/gpio-syscon.c
··· 23 23 24 24 /** 25 25 * struct syscon_gpio_data - Configuration for the device. 26 - * @compatible: SYSCON driver compatible string. 27 26 * @flags: Set of GPIO_SYSCON_FEAT_ flags: 28 27 * GPIO_SYSCON_FEAT_IN: GPIOs supports input, 29 28 * GPIO_SYSCON_FEAT_OUT: GPIOs supports output,
+3 -2
drivers/gpio/gpio-tegra.c
··· 18 18 #include <linux/of.h> 19 19 #include <linux/platform_device.h> 20 20 #include <linux/module.h> 21 - #include <linux/seq_file.h> 22 21 #include <linux/irqdomain.h> 23 22 #include <linux/irqchip/chained_irq.h> 24 23 #include <linux/pinctrl/consumer.h> 25 24 #include <linux/pm.h> 25 + #include <linux/property.h> 26 + #include <linux/seq_file.h> 26 27 27 28 #define GPIO_BANK(x) ((x) >> 5) 28 29 #define GPIO_PORT(x) (((x) >> 3) & 0x3) ··· 756 755 } 757 756 758 757 irq = &tgi->gc.irq; 759 - irq->fwnode = of_node_to_fwnode(pdev->dev.of_node); 758 + irq->fwnode = dev_fwnode(&pdev->dev); 760 759 irq->child_to_parent_hwirq = tegra_gpio_child_to_parent_hwirq; 761 760 irq->populate_parent_alloc_arg = tegra_gpio_populate_parent_fwspec; 762 761 irq->handler = handle_simple_irq;
+2 -1
drivers/gpio/gpio-tegra186.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/of.h> 15 15 #include <linux/platform_device.h> 16 + #include <linux/property.h> 16 17 #include <linux/seq_file.h> 17 18 18 19 #include <dt-bindings/gpio/tegra186-gpio.h> ··· 929 928 930 929 irq = &gpio->gpio.irq; 931 930 gpio_irq_chip_set_chip(irq, &tegra186_gpio_irq_chip); 932 - irq->fwnode = of_node_to_fwnode(pdev->dev.of_node); 931 + irq->fwnode = dev_fwnode(&pdev->dev); 933 932 irq->child_to_parent_hwirq = tegra186_gpio_child_to_parent_hwirq; 934 933 irq->populate_parent_alloc_arg = tegra186_gpio_populate_parent_fwspec; 935 934 irq->child_offset_to_irq = tegra186_gpio_child_offset_to_irq;
+3 -2
drivers/gpio/gpio-thunderx.c
··· 14 14 #include <linux/kernel.h> 15 15 #include <linux/module.h> 16 16 #include <linux/pci.h> 17 + #include <linux/property.h> 17 18 #include <linux/spinlock.h> 18 19 19 20 #define GPIO_RX_DAT 0x0 ··· 534 533 chip->set_config = thunderx_gpio_set_config; 535 534 girq = &chip->irq; 536 535 gpio_irq_chip_set_chip(girq, &thunderx_gpio_irq_chip); 537 - girq->fwnode = of_node_to_fwnode(dev->of_node); 536 + girq->fwnode = dev_fwnode(dev); 538 537 girq->parent_domain = 539 538 irq_get_irq_data(txgpio->msix_entries[0].vector)->domain; 540 539 girq->child_to_parent_hwirq = thunderx_gpio_child_to_parent_hwirq; ··· 550 549 for (i = 0; i < ngpio; i++) { 551 550 struct irq_fwspec fwspec; 552 551 553 - fwspec.fwnode = of_node_to_fwnode(dev->of_node); 552 + fwspec.fwnode = dev_fwnode(dev); 554 553 fwspec.param_count = 2; 555 554 fwspec.param[0] = i; 556 555 fwspec.param[1] = IRQ_TYPE_NONE;
+3 -2
drivers/gpio/gpio-uniphier.c
··· 11 11 #include <linux/of.h> 12 12 #include <linux/of_irq.h> 13 13 #include <linux/platform_device.h> 14 + #include <linux/property.h> 14 15 #include <linux/spinlock.h> 15 16 #include <dt-bindings/gpio/uniphier-gpio.h> 16 17 ··· 165 164 if (offset < UNIPHIER_GPIO_IRQ_OFFSET) 166 165 return -ENXIO; 167 166 168 - fwspec.fwnode = of_node_to_fwnode(chip->parent->of_node); 167 + fwspec.fwnode = dev_fwnode(chip->parent); 169 168 fwspec.param_count = 2; 170 169 fwspec.param[0] = offset - UNIPHIER_GPIO_IRQ_OFFSET; 171 170 /* ··· 405 404 priv->domain = irq_domain_create_hierarchy( 406 405 parent_domain, 0, 407 406 UNIPHIER_GPIO_IRQ_MAX_NUM, 408 - of_node_to_fwnode(dev->of_node), 407 + dev_fwnode(dev), 409 408 &uniphier_gpio_irq_domain_ops, priv); 410 409 if (!priv->domain) 411 410 return -ENOMEM;
+25 -6
drivers/gpio/gpio-vf610.c
··· 97 97 static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio) 98 98 { 99 99 struct vf610_gpio_port *port = gpiochip_get_data(gc); 100 - unsigned long mask = BIT(gpio); 100 + u32 mask = BIT(gpio); 101 101 unsigned long offset = GPIO_PDIR; 102 102 103 103 if (port->sdata->have_paddr) { ··· 112 112 static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 113 113 { 114 114 struct vf610_gpio_port *port = gpiochip_get_data(gc); 115 - unsigned long mask = BIT(gpio); 115 + u32 mask = BIT(gpio); 116 116 unsigned long offset = val ? GPIO_PSOR : GPIO_PCOR; 117 117 118 118 vf610_gpio_writel(mask, port->gpio_base + offset); 119 119 } 120 120 121 - static int vf610_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 121 + static int vf610_gpio_direction_input(struct gpio_chip *chip, unsigned int gpio) 122 122 { 123 123 struct vf610_gpio_port *port = gpiochip_get_data(chip); 124 - unsigned long mask = BIT(gpio); 124 + u32 mask = BIT(gpio); 125 125 u32 val; 126 126 127 127 if (port->sdata->have_paddr) { ··· 133 133 return pinctrl_gpio_direction_input(chip, gpio); 134 134 } 135 135 136 - static int vf610_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, 136 + static int vf610_gpio_direction_output(struct gpio_chip *chip, unsigned int gpio, 137 137 int value) 138 138 { 139 139 struct vf610_gpio_port *port = gpiochip_get_data(chip); 140 - unsigned long mask = BIT(gpio); 140 + u32 mask = BIT(gpio); 141 141 u32 val; 142 142 143 143 vf610_gpio_set(chip, gpio, value); ··· 149 149 } 150 150 151 151 return pinctrl_gpio_direction_output(chip, gpio); 152 + } 153 + 154 + static int vf610_gpio_get_direction(struct gpio_chip *gc, unsigned int gpio) 155 + { 156 + struct vf610_gpio_port *port = gpiochip_get_data(gc); 157 + u32 mask = BIT(gpio); 158 + 159 + mask &= vf610_gpio_readl(port->gpio_base + GPIO_PDDR); 160 + 161 + if (mask) 162 + return GPIO_LINE_DIRECTION_OUT; 163 + 164 + return GPIO_LINE_DIRECTION_IN; 152 165 } 153 166 154 167 static void vf610_gpio_irq_handler(struct irq_desc *desc) ··· 375 362 gc->get = vf610_gpio_get; 376 363 gc->direction_output = vf610_gpio_direction_output; 377 364 gc->set = vf610_gpio_set; 365 + /* 366 + * only IP has Port Data Direction Register(PDDR) can 367 + * support get direction 368 + */ 369 + if (port->sdata->have_paddr) 370 + gc->get_direction = vf610_gpio_get_direction; 378 371 379 372 /* Mask all GPIO interrupts */ 380 373 for (i = 0; i < gc->ngpio; i++)
+4 -9
drivers/gpio/gpio-virtuser.c
··· 1410 1410 size_t num_entries = gpio_virtuser_get_lookup_count(dev); 1411 1411 struct gpio_virtuser_lookup_entry *entry; 1412 1412 struct gpio_virtuser_lookup *lookup; 1413 - struct gpiod_lookup *curr; 1414 1413 unsigned int i = 0; 1415 1414 1416 1415 lockdep_assert_held(&dev->lock); ··· 1425 1426 1426 1427 list_for_each_entry(lookup, &dev->lookup_list, siblings) { 1427 1428 list_for_each_entry(entry, &lookup->entry_list, siblings) { 1428 - curr = &table->table[i]; 1429 - 1430 - curr->con_id = lookup->con_id; 1431 - curr->idx = i; 1432 - curr->key = entry->key; 1433 - curr->chip_hwnum = entry->offset < 0 ? 1434 - U16_MAX : entry->offset; 1435 - curr->flags = entry->flags; 1429 + table->table[i] = 1430 + GPIO_LOOKUP_IDX(entry->key, 1431 + entry->offset < 0 ? U16_MAX : entry->offset, 1432 + lookup->con_id, i, entry->flags); 1436 1433 i++; 1437 1434 } 1438 1435 }
+3 -2
drivers/gpio/gpio-visconti.c
··· 8 8 * Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp> 9 9 */ 10 10 11 + #include <linux/bitops.h> 11 12 #include <linux/gpio/driver.h> 12 13 #include <linux/init.h> 13 14 #include <linux/interrupt.h> ··· 16 15 #include <linux/io.h> 17 16 #include <linux/of_irq.h> 18 17 #include <linux/platform_device.h> 18 + #include <linux/property.h> 19 19 #include <linux/seq_file.h> 20 - #include <linux/bitops.h> 21 20 22 21 /* register offset */ 23 22 #define GPIO_DIR 0x00 ··· 203 202 204 203 girq = &priv->gpio_chip.irq; 205 204 gpio_irq_chip_set_chip(girq, &visconti_gpio_irq_chip); 206 - girq->fwnode = of_node_to_fwnode(dev->of_node); 205 + girq->fwnode = dev_fwnode(dev); 207 206 girq->parent_domain = parent; 208 207 girq->child_to_parent_hwirq = visconti_gpio_child_to_parent_hwirq; 209 208 girq->populate_parent_alloc_arg = visconti_gpio_populate_parent_fwspec;
+1 -10
drivers/gpio/gpio-xilinx.c
··· 333 333 */ 334 334 static void xgpio_remove(struct platform_device *pdev) 335 335 { 336 - struct xgpio_instance *gpio = platform_get_drvdata(pdev); 337 - 338 336 pm_runtime_get_sync(&pdev->dev); 339 337 pm_runtime_put_noidle(&pdev->dev); 340 338 pm_runtime_disable(&pdev->dev); 341 - clk_disable_unprepare(gpio->clk); 342 339 } 343 340 344 341 /** ··· 641 644 return PTR_ERR(chip->regs); 642 645 } 643 646 644 - chip->clk = devm_clk_get_optional(&pdev->dev, NULL); 647 + chip->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL); 645 648 if (IS_ERR(chip->clk)) 646 649 return dev_err_probe(&pdev->dev, PTR_ERR(chip->clk), "input clock not found.\n"); 647 650 648 - status = clk_prepare_enable(chip->clk); 649 - if (status < 0) { 650 - dev_err(&pdev->dev, "Failed to prepare clk\n"); 651 - return status; 652 - } 653 651 pm_runtime_get_noresume(&pdev->dev); 654 652 pm_runtime_set_active(&pdev->dev); 655 653 pm_runtime_enable(&pdev->dev); ··· 691 699 err_pm_put: 692 700 pm_runtime_disable(&pdev->dev); 693 701 pm_runtime_put_noidle(&pdev->dev); 694 - clk_disable_unprepare(chip->clk); 695 702 return status; 696 703 } 697 704
+1 -9
drivers/gpio/gpio-zynq.c
··· 940 940 chip->ngpio = gpio->p_data->ngpio; 941 941 942 942 /* Retrieve GPIO clock */ 943 - gpio->clk = devm_clk_get(&pdev->dev, NULL); 943 + gpio->clk = devm_clk_get_enabled(&pdev->dev, NULL); 944 944 if (IS_ERR(gpio->clk)) 945 945 return dev_err_probe(&pdev->dev, PTR_ERR(gpio->clk), "input clock not found.\n"); 946 - 947 - ret = clk_prepare_enable(gpio->clk); 948 - if (ret) { 949 - dev_err(&pdev->dev, "Unable to enable clock.\n"); 950 - return ret; 951 - } 952 946 953 947 spin_lock_init(&gpio->dirlock); 954 948 ··· 993 999 pm_runtime_put(&pdev->dev); 994 1000 err_pm_dis: 995 1001 pm_runtime_disable(&pdev->dev); 996 - clk_disable_unprepare(gpio->clk); 997 1002 998 1003 return ret; 999 1004 } ··· 1012 1019 if (ret < 0) 1013 1020 dev_warn(&pdev->dev, "pm_runtime_get_sync() Failed\n"); 1014 1021 gpiochip_remove(&gpio->chip); 1015 - clk_disable_unprepare(gpio->clk); 1016 1022 device_set_wakeup_capable(&pdev->dev, 0); 1017 1023 pm_runtime_disable(&pdev->dev); 1018 1024 }
+19 -24
drivers/gpio/gpiolib-acpi.c
··· 153 153 * @path: ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1") 154 154 * @pin: ACPI GPIO pin number (0-based, controller-relative) 155 155 * 156 - * Return: GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR 157 - * error value. Specifically returns %-EPROBE_DEFER if the referenced GPIO 156 + * Returns: 157 + * GPIO descriptor to use with Linux generic GPIO API. 158 + * If the GPIO cannot be translated or there is an error an ERR_PTR is 159 + * returned. 160 + * 161 + * Specifically returns %-EPROBE_DEFER if the referenced GPIO 158 162 * controller does not have GPIO chip registered at the moment. This is to 159 163 * support probe deferral. 160 164 */ ··· 228 224 * I/O resource or return False if not. 229 225 * @ares: Pointer to the ACPI resource to fetch 230 226 * @agpio: Pointer to a &struct acpi_resource_gpio to store the output pointer 227 + * 228 + * Returns: 229 + * %true if GpioIo resource is found, %false otherwise. 231 230 */ 232 231 bool acpi_gpio_get_io_resource(struct acpi_resource *ares, 233 232 struct acpi_resource_gpio **agpio) ··· 883 876 * that case @index is used to select the GPIO entry in the property value 884 877 * (in case of multiple). 885 878 * 886 - * If the GPIO cannot be translated or there is an error, an ERR_PTR is 879 + * Returns: 880 + * GPIO descriptor to use with Linux generic GPIO API. 881 + * If the GPIO cannot be translated or there is an error an ERR_PTR is 887 882 * returned. 888 883 * 889 884 * Note: if the GPIO resource has multiple entries in the pin list, this ··· 933 924 * resource with the relevant information from a data-only ACPI firmware node 934 925 * and uses that to obtain the GPIO descriptor to return. 935 926 * 927 + * Returns: 928 + * GPIO descriptor to use with Linux generic GPIO API. 936 929 * If the GPIO cannot be translated or there is an error an ERR_PTR is 937 930 * returned. 938 931 */ ··· 984 973 struct acpi_device *adev = to_acpi_device_node(fwnode); 985 974 struct gpio_desc *desc; 986 975 char propname[32]; 987 - int i; 988 976 989 977 /* Try first from _DSD */ 990 - for (i = 0; i < gpio_suffix_count; i++) { 991 - if (con_id) { 992 - snprintf(propname, sizeof(propname), "%s-%s", 993 - con_id, gpio_suffixes[i]); 994 - } else { 995 - snprintf(propname, sizeof(propname), "%s", 996 - gpio_suffixes[i]); 997 - } 998 - 978 + for_each_gpio_property_name(propname, con_id) { 999 979 if (adev) 1000 980 desc = acpi_get_gpiod_by_index(adev, 1001 981 propname, idx, info); ··· 1053 1051 * The GPIO is considered wake capable if the GpioInt resource specifies 1054 1052 * SharedAndWake or ExclusiveAndWake. 1055 1053 * 1056 - * Return: Linux IRQ number (> %0) on success, negative errno on failure. 1054 + * Returns: 1055 + * Linux IRQ number (> 0) on success, negative errno on failure. 1057 1056 */ 1058 1057 int acpi_dev_gpio_irq_wake_get_by(struct acpi_device *adev, const char *con_id, int index, 1059 1058 bool *wake_capable) ··· 1441 1438 * @fwnode: firmware node of the GPIO consumer 1442 1439 * @con_id: function within the GPIO consumer 1443 1440 * 1444 - * Return: 1441 + * Returns: 1445 1442 * The number of GPIOs associated with a firmware node / function or %-ENOENT, 1446 1443 * if no GPIO has been assigned to the requested function. 1447 1444 */ ··· 1453 1450 int count = -ENOENT; 1454 1451 int ret; 1455 1452 char propname[32]; 1456 - unsigned int i; 1457 1453 1458 1454 /* Try first from _DSD */ 1459 - for (i = 0; i < gpio_suffix_count; i++) { 1460 - if (con_id) 1461 - snprintf(propname, sizeof(propname), "%s-%s", 1462 - con_id, gpio_suffixes[i]); 1463 - else 1464 - snprintf(propname, sizeof(propname), "%s", 1465 - gpio_suffixes[i]); 1466 - 1455 + for_each_gpio_property_name(propname, con_id) { 1467 1456 ret = acpi_dev_get_property(adev, propname, ACPI_TYPE_ANY, &obj); 1468 1457 if (ret == 0) { 1469 1458 if (obj->type == ACPI_TYPE_LOCAL_REFERENCE)
+6 -2
drivers/gpio/gpiolib-cdev.c
··· 2748 2748 * gpio_chrdev_open() - open the chardev for ioctl operations 2749 2749 * @inode: inode for this chardev 2750 2750 * @file: file struct for storing private data 2751 - * Returns 0 on success 2751 + * 2752 + * Returns: 2753 + * 0 on success, or negative errno on failure. 2752 2754 */ 2753 2755 static int gpio_chrdev_open(struct inode *inode, struct file *file) 2754 2756 { ··· 2816 2814 * gpio_chrdev_release() - close chardev after ioctl operations 2817 2815 * @inode: inode for this chardev 2818 2816 * @file: file struct for storing private data 2819 - * Returns 0 on success 2817 + * 2818 + * Returns: 2819 + * 0 on success, or negative errno on failure. 2820 2820 */ 2821 2821 static int gpio_chrdev_release(struct inode *inode, struct file *file) 2822 2822 {
+44 -76
drivers/gpio/gpiolib-devres.c
··· 6 6 * Copyright (c) 2011 John Crispin <john@phrozen.org> 7 7 */ 8 8 9 - #include <linux/module.h> 10 - #include <linux/err.h> 11 - #include <linux/gpio.h> 12 - #include <linux/gpio/consumer.h> 13 9 #include <linux/device.h> 10 + #include <linux/err.h> 11 + #include <linux/export.h> 14 12 #include <linux/gfp.h> 13 + #include <linux/types.h> 14 + 15 + #include <linux/gpio/consumer.h> 15 16 16 17 #include "gpiolib.h" 18 + 19 + struct fwnode_handle; 20 + struct lock_class_key; 17 21 18 22 static void devm_gpiod_release(struct device *dev, void *res) 19 23 { ··· 56 52 * Managed gpiod_get(). GPIO descriptors returned from this function are 57 53 * automatically disposed on driver detach. See gpiod_get() for detailed 58 54 * information about behavior and return values. 55 + * 56 + * Returns: 57 + * The GPIO descriptor corresponding to the function @con_id of device 58 + * dev, %-ENOENT if no GPIO has been assigned to the requested function, or 59 + * another IS_ERR() code if an error occurred while trying to acquire the GPIO. 59 60 */ 60 61 struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, 61 62 const char *con_id, ··· 79 70 * Managed gpiod_get_optional(). GPIO descriptors returned from this function 80 71 * are automatically disposed on driver detach. See gpiod_get_optional() for 81 72 * detailed information about behavior and return values. 73 + * 74 + * Returns: 75 + * The GPIO descriptor corresponding to the function @con_id of device 76 + * dev, NULL if no GPIO has been assigned to the requested function, or 77 + * another IS_ERR() code if an error occurred while trying to acquire the GPIO. 82 78 */ 83 79 struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev, 84 80 const char *con_id, ··· 103 89 * Managed gpiod_get_index(). GPIO descriptors returned from this function are 104 90 * automatically disposed on driver detach. See gpiod_get_index() for detailed 105 91 * information about behavior and return values. 92 + * 93 + * Returns: 94 + * The GPIO descriptor corresponding to the function @con_id of device 95 + * dev, %-ENOENT if no GPIO has been assigned to the requested function, or 96 + * another IS_ERR() code if an error occurred while trying to acquire the GPIO. 106 97 */ 107 98 struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, 108 99 const char *con_id, ··· 160 141 * GPIO descriptors returned from this function are automatically disposed on 161 142 * driver detach. 162 143 * 163 - * On successful request the GPIO pin is configured in accordance with 164 - * provided @flags. 144 + * Returns: 145 + * The GPIO descriptor corresponding to the function @con_id of device 146 + * dev, %-ENOENT if no GPIO has been assigned to the requested function, or 147 + * another IS_ERR() code if an error occurred while trying to acquire the GPIO. 165 148 */ 166 149 struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev, 167 150 struct fwnode_handle *fwnode, ··· 203 182 * function are automatically disposed on driver detach. See 204 183 * gpiod_get_index_optional() for detailed information about behavior and 205 184 * return values. 185 + * 186 + * Returns: 187 + * The GPIO descriptor corresponding to the function @con_id of device 188 + * dev, %NULL if no GPIO has been assigned to the requested function, or 189 + * another IS_ERR() code if an error occurred while trying to acquire the GPIO. 206 190 */ 207 191 struct gpio_desc *__must_check devm_gpiod_get_index_optional(struct device *dev, 208 192 const char *con_id, ··· 233 207 * Managed gpiod_get_array(). GPIO descriptors returned from this function are 234 208 * automatically disposed on driver detach. See gpiod_get_array() for detailed 235 209 * information about behavior and return values. 210 + * 211 + * Returns: 212 + * The GPIO descriptors corresponding to the function @con_id of device 213 + * dev, %-ENOENT if no GPIO has been assigned to the requested function, 214 + * or another IS_ERR() code if an error occurred while trying to acquire 215 + * the GPIOs. 236 216 */ 237 217 struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev, 238 218 const char *con_id, ··· 275 243 * function are automatically disposed on driver detach. 276 244 * See gpiod_get_array_optional() for detailed information about behavior and 277 245 * return values. 246 + * 247 + * Returns: 248 + * The GPIO descriptors corresponding to the function @con_id of device 249 + * dev, %NULL if no GPIO has been assigned to the requested function, 250 + * or another IS_ERR() code if an error occurred while trying to acquire 251 + * the GPIOs. 278 252 */ 279 253 struct gpio_descs *__must_check 280 254 devm_gpiod_get_array_optional(struct device *dev, const char *con_id, ··· 357 319 devm_gpiod_match_array, &descs)); 358 320 } 359 321 EXPORT_SYMBOL_GPL(devm_gpiod_put_array); 360 - 361 - static void devm_gpio_release(struct device *dev, void *res) 362 - { 363 - unsigned *gpio = res; 364 - 365 - gpio_free(*gpio); 366 - } 367 - 368 - /** 369 - * devm_gpio_request - request a GPIO for a managed device 370 - * @dev: device to request the GPIO for 371 - * @gpio: GPIO to allocate 372 - * @label: the name of the requested GPIO 373 - * 374 - * Except for the extra @dev argument, this function takes the 375 - * same arguments and performs the same function as 376 - * gpio_request(). GPIOs requested with this function will be 377 - * automatically freed on driver detach. 378 - */ 379 - int devm_gpio_request(struct device *dev, unsigned gpio, const char *label) 380 - { 381 - unsigned *dr; 382 - int rc; 383 - 384 - dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL); 385 - if (!dr) 386 - return -ENOMEM; 387 - 388 - rc = gpio_request(gpio, label); 389 - if (rc) { 390 - devres_free(dr); 391 - return rc; 392 - } 393 - 394 - *dr = gpio; 395 - devres_add(dev, dr); 396 - 397 - return 0; 398 - } 399 - EXPORT_SYMBOL_GPL(devm_gpio_request); 400 - 401 - /** 402 - * devm_gpio_request_one - request a single GPIO with initial setup 403 - * @dev: device to request for 404 - * @gpio: the GPIO number 405 - * @flags: GPIO configuration as specified by GPIOF_* 406 - * @label: a literal description string of this GPIO 407 - */ 408 - int devm_gpio_request_one(struct device *dev, unsigned gpio, 409 - unsigned long flags, const char *label) 410 - { 411 - unsigned *dr; 412 - int rc; 413 - 414 - dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL); 415 - if (!dr) 416 - return -ENOMEM; 417 - 418 - rc = gpio_request_one(gpio, flags, label); 419 - if (rc) { 420 - devres_free(dr); 421 - return rc; 422 - } 423 - 424 - *dr = gpio; 425 - devres_add(dev, dr); 426 - 427 - return 0; 428 - } 429 - EXPORT_SYMBOL_GPL(devm_gpio_request_one); 430 322 431 323 static void devm_gpio_chip_release(void *data) 432 324 {
+91 -3
drivers/gpio/gpiolib-legacy.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/bitops.h> 3 + #include <linux/device.h> 4 + #include <linux/errno.h> 5 + #include <linux/export.h> 6 + #include <linux/gfp.h> 7 + 2 8 #include <linux/gpio/consumer.h> 3 9 #include <linux/gpio/driver.h> 4 10 ··· 28 22 * @label: a literal description string of this GPIO 29 23 * 30 24 * **DEPRECATED** This function is deprecated and must not be used in new code. 25 + * 26 + * Returns: 27 + * 0 on success, or negative errno on failure. 31 28 */ 32 29 int gpio_request_one(unsigned gpio, unsigned long flags, const char *label) 33 30 { ··· 49 40 if (flags & GPIOF_ACTIVE_LOW) 50 41 set_bit(FLAG_ACTIVE_LOW, &desc->flags); 51 42 52 - if (flags & GPIOF_DIR_IN) 43 + if (flags & GPIOF_IN) 53 44 err = gpiod_direction_input(desc); 54 45 else 55 - err = gpiod_direction_output_raw(desc, 56 - (flags & GPIOF_INIT_HIGH) ? 1 : 0); 46 + err = gpiod_direction_output_raw(desc, !!(flags & GPIOF_OUT_INIT_HIGH)); 57 47 58 48 if (err) 59 49 goto free_gpio; ··· 80 72 return gpiod_request(desc, label); 81 73 } 82 74 EXPORT_SYMBOL_GPL(gpio_request); 75 + 76 + static void devm_gpio_release(struct device *dev, void *res) 77 + { 78 + unsigned *gpio = res; 79 + 80 + gpio_free(*gpio); 81 + } 82 + 83 + /** 84 + * devm_gpio_request - request a GPIO for a managed device 85 + * @dev: device to request the GPIO for 86 + * @gpio: GPIO to allocate 87 + * @label: the name of the requested GPIO 88 + * 89 + * Except for the extra @dev argument, this function takes the 90 + * same arguments and performs the same function as gpio_request(). 91 + * GPIOs requested with this function will be automatically freed 92 + * on driver detach. 93 + * 94 + * **DEPRECATED** This function is deprecated and must not be used in new code. 95 + * 96 + * Returns: 97 + * 0 on success, or negative errno on failure. 98 + */ 99 + int devm_gpio_request(struct device *dev, unsigned gpio, const char *label) 100 + { 101 + unsigned *dr; 102 + int rc; 103 + 104 + dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL); 105 + if (!dr) 106 + return -ENOMEM; 107 + 108 + rc = gpio_request(gpio, label); 109 + if (rc) { 110 + devres_free(dr); 111 + return rc; 112 + } 113 + 114 + *dr = gpio; 115 + devres_add(dev, dr); 116 + 117 + return 0; 118 + } 119 + EXPORT_SYMBOL_GPL(devm_gpio_request); 120 + 121 + /** 122 + * devm_gpio_request_one - request a single GPIO with initial setup 123 + * @dev: device to request for 124 + * @gpio: the GPIO number 125 + * @flags: GPIO configuration as specified by GPIOF_* 126 + * @label: a literal description string of this GPIO 127 + * 128 + * **DEPRECATED** This function is deprecated and must not be used in new code. 129 + * 130 + * Returns: 131 + * 0 on success, or negative errno on failure. 132 + */ 133 + int devm_gpio_request_one(struct device *dev, unsigned gpio, 134 + unsigned long flags, const char *label) 135 + { 136 + unsigned *dr; 137 + int rc; 138 + 139 + dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL); 140 + if (!dr) 141 + return -ENOMEM; 142 + 143 + rc = gpio_request_one(gpio, flags, label); 144 + if (rc) { 145 + devres_free(dr); 146 + return rc; 147 + } 148 + 149 + *dr = gpio; 150 + devres_add(dev, dr); 151 + 152 + return 0; 153 + } 154 + EXPORT_SYMBOL_GPL(devm_gpio_request_one);
+45 -47
drivers/gpio/gpiolib-of.c
··· 46 46 * @propname: property name containing gpio specifier(s) 47 47 * 48 48 * The function returns the count of GPIOs specified for a node. 49 - * Note that the empty GPIO specifiers count too. Returns either 50 - * Number of gpios defined in property, 51 - * -EINVAL for an incorrectly formed gpios property, or 52 - * -ENOENT for a missing gpios property 49 + * NOTE: The empty GPIO specifiers count too. 53 50 * 54 - * Example: 55 - * gpios = <0 56 - * &gpio1 1 2 57 - * 0 58 - * &gpio2 3 4>; 51 + * Returns: 52 + * Either number of GPIOs defined in the property, or 53 + * * %-EINVAL for an incorrectly formed "gpios" property, or 54 + * * %-ENOENT for a missing "gpios" property. 55 + * 56 + * Example:: 57 + * 58 + * gpios = <0 59 + * &gpio1 1 2 60 + * 0 61 + * &gpio2 3 4>; 59 62 * 60 63 * The above example defines four GPIOs, two of which are not specified. 61 64 * This function will return '4' ··· 80 77 * "gpios" for the chip select lines. If we detect this, we redirect 81 78 * the counting of "cs-gpios" to count "gpios" transparent to the 82 79 * driver. 80 + * 81 + * Returns: 82 + * Either number of GPIOs defined in the property, or 83 + * * %-EINVAL for an incorrectly formed "gpios" property, or 84 + * * %-ENOENT for a missing "gpios" property. 83 85 */ 84 86 static int of_gpio_spi_cs_get_count(const struct device_node *np, 85 87 const char *con_id) ··· 105 97 const struct device_node *np = to_of_node(fwnode); 106 98 int ret; 107 99 char propname[32]; 108 - unsigned int i; 109 100 110 101 ret = of_gpio_spi_cs_get_count(np, con_id); 111 102 if (ret > 0) 112 103 return ret; 113 104 114 - for (i = 0; i < gpio_suffix_count; i++) { 115 - if (con_id) 116 - snprintf(propname, sizeof(propname), "%s-%s", 117 - con_id, gpio_suffixes[i]); 118 - else 119 - snprintf(propname, sizeof(propname), "%s", 120 - gpio_suffixes[i]); 121 - 105 + for_each_gpio_property_name(propname, con_id) { 122 106 ret = of_gpio_named_count(np, propname); 123 107 if (ret > 0) 124 108 break; ··· 338 338 */ 339 339 if (IS_ENABLED(CONFIG_SPI_MASTER) && !strcmp(propname, "cs-gpios") && 340 340 of_property_read_bool(np, "cs-gpios")) { 341 - struct device_node *child; 342 341 u32 cs; 343 342 int ret; 344 343 345 - for_each_child_of_node(np, child) { 344 + for_each_child_of_node_scoped(np, child) { 346 345 ret = of_property_read_u32(child, "reg", &cs); 347 346 if (ret) 348 347 continue; ··· 362 363 "spi-cs-high"); 363 364 of_gpio_quirk_polarity(child, active_high, 364 365 flags); 365 - of_node_put(child); 366 366 break; 367 367 } 368 368 } ··· 381 383 * @index: index of the GPIO 382 384 * @flags: a flags pointer to fill in 383 385 * 384 - * Returns GPIO descriptor to use with Linux GPIO API, or one of the errno 386 + * Returns: 387 + * GPIO descriptor to use with Linux GPIO API, or one of the errno 385 388 * value on the error condition. If @flags is not NULL the function also fills 386 389 * in flags for the GPIO. 387 390 */ ··· 434 435 * 435 436 * **DEPRECATED** This function is deprecated and must not be used in new code. 436 437 * 437 - * Returns GPIO number to use with Linux generic GPIO API, or one of the errno 438 + * Returns: 439 + * GPIO number to use with Linux generic GPIO API, or one of the errno 438 440 * value on the error condition. 439 441 */ 440 442 int of_get_named_gpio(const struct device_node *np, const char *propname, ··· 687 687 struct gpio_desc *of_find_gpio(struct device_node *np, const char *con_id, 688 688 unsigned int idx, unsigned long *flags) 689 689 { 690 - char prop_name[32]; /* 32 is max size of property name */ 690 + char propname[32]; /* 32 is max size of property name */ 691 691 enum of_gpio_flags of_flags; 692 692 const of_find_gpio_quirk *q; 693 693 struct gpio_desc *desc; 694 - unsigned int i; 695 694 696 695 /* Try GPIO property "foo-gpios" and "foo-gpio" */ 697 - for (i = 0; i < gpio_suffix_count; i++) { 698 - if (con_id) 699 - snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id, 700 - gpio_suffixes[i]); 701 - else 702 - snprintf(prop_name, sizeof(prop_name), "%s", 703 - gpio_suffixes[i]); 704 - 705 - desc = of_get_named_gpiod_flags(np, prop_name, idx, &of_flags); 706 - 696 + for_each_gpio_property_name(propname, con_id) { 697 + desc = of_get_named_gpiod_flags(np, propname, idx, &of_flags); 707 698 if (!gpiod_not_found(desc)) 708 699 break; 709 700 } ··· 721 730 * of_find_gpio() or of_parse_own_gpio() 722 731 * @dflags: gpiod_flags - optional GPIO initialization flags 723 732 * 724 - * Returns GPIO descriptor to use with Linux GPIO API, or one of the errno 733 + * Returns: 734 + * GPIO descriptor to use with Linux GPIO API, or one of the errno 725 735 * value on the error condition. 726 736 */ 727 737 static struct gpio_desc *of_parse_own_gpio(struct device_node *np, ··· 790 798 * @chip: gpio chip to act on 791 799 * @hog: device node describing the hogs 792 800 * 793 - * Returns error if it fails otherwise 0 on success. 801 + * Returns: 802 + * 0 on success, or negative errno on failure. 794 803 */ 795 804 static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog) 796 805 { ··· 825 832 * 826 833 * This is only used by of_gpiochip_add to request/set GPIO initial 827 834 * configuration. 828 - * It returns error if it fails otherwise 0 on success. 835 + * 836 + * Returns: 837 + * 0 on success, or negative errno on failure. 829 838 */ 830 839 static int of_gpiochip_scan_gpios(struct gpio_chip *chip) 831 840 { 832 - struct device_node *np; 833 841 int ret; 834 842 835 - for_each_available_child_of_node(dev_of_node(&chip->gpiodev->dev), np) { 843 + for_each_available_child_of_node_scoped(dev_of_node(&chip->gpiodev->dev), np) { 836 844 if (!of_property_read_bool(np, "gpio-hog")) 837 845 continue; 838 846 839 847 ret = of_gpiochip_add_hog(chip, np); 840 - if (ret < 0) { 841 - of_node_put(np); 848 + if (ret < 0) 842 849 return ret; 843 - } 844 850 845 851 of_node_set_flag(np, OF_POPULATED); 846 852 } ··· 937 945 * This is simple translation function, suitable for the most 1:1 mapped 938 946 * GPIO chips. This function performs only one sanity check: whether GPIO 939 947 * is less than ngpios (that is specified in the gpio_chip). 948 + * 949 + * Returns: 950 + * GPIO number (>= 0) on success, negative errno on failure. 940 951 */ 941 952 static int of_gpio_simple_xlate(struct gpio_chip *gc, 942 953 const struct of_phandle_args *gpiospec, ··· 989 994 * If succeeded, this function will map bank's memory and will 990 995 * do all necessary work for you. Then you'll able to use .regs 991 996 * to manage GPIOs from the callbacks. 997 + * 998 + * Returns: 999 + * 0 on success, or negative errno on failure. 992 1000 */ 993 1001 int of_mm_gpiochip_add_data(struct device_node *np, 994 1002 struct of_mm_gpio_chip *mm_gc, ··· 1056 1058 int index = 0, ret, trim; 1057 1059 const char *name; 1058 1060 static const char group_names_propname[] = "gpio-ranges-group-names"; 1059 - struct property *group_names; 1061 + bool has_group_names; 1060 1062 1061 1063 np = dev_of_node(&chip->gpiodev->dev); 1062 1064 if (!np) 1063 1065 return 0; 1064 1066 1065 - group_names = of_find_property(np, group_names_propname, NULL); 1067 + has_group_names = of_property_present(np, group_names_propname); 1066 1068 1067 1069 for (;; index++) { 1068 1070 ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, ··· 1083 1085 1084 1086 if (pinspec.args[2]) { 1085 1087 /* npins != 0: linear range */ 1086 - if (group_names) { 1088 + if (has_group_names) { 1087 1089 of_property_read_string_index(np, 1088 1090 group_names_propname, 1089 1091 index, &name); ··· 1121 1123 break; 1122 1124 } 1123 1125 1124 - if (!group_names) { 1126 + if (!has_group_names) { 1125 1127 pr_err("%pOF: GPIO group range requested but no %s property.\n", 1126 1128 np, group_names_propname); 1127 1129 break;
+29 -33
drivers/gpio/gpiolib-swnode.c
··· 24 24 25 25 #define GPIOLIB_SWNODE_UNDEFINED_NAME "swnode-gpio-undefined" 26 26 27 - static void swnode_format_propname(const char *con_id, char *propname, 28 - size_t max_size) 29 - { 30 - /* 31 - * Note we do not need to try both -gpios and -gpio suffixes, 32 - * as, unlike OF and ACPI, we can fix software nodes to conform 33 - * to the proper binding. 34 - */ 35 - if (con_id) 36 - snprintf(propname, max_size, "%s-gpios", con_id); 37 - else 38 - strscpy(propname, "gpios", max_size); 39 - } 40 - 41 27 static struct gpio_device *swnode_get_gpio_device(struct fwnode_handle *fwnode) 42 28 { 43 29 const struct software_node *gdev_node; ··· 45 59 return gdev ?: ERR_PTR(-EPROBE_DEFER); 46 60 } 47 61 62 + static int swnode_gpio_get_reference(const struct fwnode_handle *fwnode, 63 + const char *propname, unsigned int idx, 64 + struct fwnode_reference_args *args) 65 + { 66 + /* 67 + * We expect all swnode-described GPIOs have GPIO number and 68 + * polarity arguments, hence nargs is set to 2. 69 + */ 70 + return fwnode_property_get_reference_args(fwnode, propname, NULL, 2, idx, args); 71 + } 72 + 48 73 struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode, 49 74 const char *con_id, unsigned int idx, 50 75 unsigned long *flags) ··· 64 67 struct fwnode_reference_args args; 65 68 struct gpio_desc *desc; 66 69 char propname[32]; /* 32 is max size of property name */ 67 - int error; 70 + int ret; 68 71 69 72 swnode = to_software_node(fwnode); 70 73 if (!swnode) 71 74 return ERR_PTR(-EINVAL); 72 75 73 - swnode_format_propname(con_id, propname, sizeof(propname)); 74 - 75 - /* 76 - * We expect all swnode-described GPIOs have GPIO number and 77 - * polarity arguments, hence nargs is set to 2. 78 - */ 79 - error = fwnode_property_get_reference_args(fwnode, propname, NULL, 2, idx, &args); 80 - if (error) { 76 + for_each_gpio_property_name(propname, con_id) { 77 + ret = swnode_gpio_get_reference(fwnode, propname, idx, &args); 78 + if (ret == 0) 79 + break; 80 + } 81 + if (ret) { 81 82 pr_debug("%s: can't parse '%s' property of node '%pfwP[%d]'\n", 82 83 __func__, propname, fwnode, idx); 83 - return ERR_PTR(error); 84 + return ERR_PTR(ret); 84 85 } 85 86 86 87 struct gpio_device *gdev __free(gpio_device_put) = ··· 106 111 * system-global GPIOs 107 112 * @con_id: function within the GPIO consumer 108 113 * 109 - * Return: 114 + * Returns: 110 115 * The number of GPIOs associated with a device / function or %-ENOENT, 111 116 * if no GPIO has been assigned to the requested function. 112 117 */ ··· 116 121 char propname[32]; 117 122 int count; 118 123 119 - swnode_format_propname(con_id, propname, sizeof(propname)); 120 - 121 124 /* 122 125 * This is not very efficient, but GPIO lists usually have only 123 126 * 1 or 2 entries. 124 127 */ 125 - count = 0; 126 - while (fwnode_property_get_reference_args(fwnode, propname, NULL, 0, 127 - count, &args) == 0) { 128 - fwnode_handle_put(args.fwnode); 129 - count++; 128 + for_each_gpio_property_name(propname, con_id) { 129 + count = 0; 130 + while (swnode_gpio_get_reference(fwnode, propname, count, &args) == 0) { 131 + fwnode_handle_put(args.fwnode); 132 + count++; 133 + } 134 + if (count) 135 + return count; 130 136 } 131 137 132 - return count ?: -ENOENT; 138 + return -ENOENT; 133 139 } 134 140 135 141 #if IS_ENABLED(CONFIG_GPIO_SWNODE_UNDEFINED)
+4 -2
drivers/gpio/gpiolib-sysfs.c
··· 568 568 * will see "direction" sysfs attribute which may be used to change 569 569 * the gpio's direction. A "value" attribute will always be provided. 570 570 * 571 - * Returns zero on success, else an error. 571 + * Returns: 572 + * 0 on success, or negative errno on failure. 572 573 */ 573 574 int gpiod_export(struct gpio_desc *desc, bool direction_may_change) 574 575 { ··· 668 667 * Set up a symlink from /sys/.../dev/name to /sys/class/gpio/gpioN 669 668 * node. Caller is responsible for unlinking. 670 669 * 671 - * Returns zero on success, else an error. 670 + * Returns: 671 + * 0 on success, or negative errno on failure. 672 672 */ 673 673 int gpiod_export_link(struct device *dev, const char *name, 674 674 struct gpio_desc *desc)
+128 -36
drivers/gpio/gpiolib.c
··· 90 90 static DEFINE_MUTEX(gpio_machine_hogs_mutex); 91 91 static LIST_HEAD(gpio_machine_hogs); 92 92 93 - const char *const gpio_suffixes[] = { "gpios", "gpio" }; 94 - const size_t gpio_suffix_count = ARRAY_SIZE(gpio_suffixes); 93 + const char *const gpio_suffixes[] = { "gpios", "gpio", NULL }; 95 94 96 95 static void gpiochip_free_hogs(struct gpio_chip *gc); 97 96 static int gpiochip_add_irqchip(struct gpio_chip *gc, ··· 230 231 * This function is unsafe and should not be used. Using the chip address 231 232 * without taking the SRCU read lock may result in dereferencing a dangling 232 233 * pointer. 234 + * 235 + * Returns: 236 + * Address of the GPIO chip backing this device. 233 237 */ 234 238 struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) 235 239 { ··· 345 343 * gpiod_get_direction - return the current direction of a GPIO 346 344 * @desc: GPIO to get the direction of 347 345 * 348 - * Returns 0 for output, 1 for input, or an error code in case of error. 346 + * Returns: 347 + * 0 for output, 1 for input, or an error code in case of error. 349 348 * 350 349 * This function may sleep if gpiod_cansleep() is true. 351 350 */ ··· 360 357 * We cannot use VALIDATE_DESC() as we must not return 0 for a NULL 361 358 * descriptor like we usually do. 362 359 */ 363 - if (!desc || IS_ERR(desc)) 360 + if (IS_ERR_OR_NULL(desc)) 364 361 return -EINVAL; 365 362 366 363 CLASS(gpio_chip_guard, guard)(desc); ··· 403 400 * Add a new chip to the global chips list, keeping the list of chips sorted 404 401 * by range(means [base, base + ngpio - 1]) order. 405 402 * 406 - * Return -EBUSY if the new chip overlaps with some other chip's integer 407 - * space. 403 + * Returns: 404 + * -EBUSY if the new chip overlaps with some other chip's integer space. 408 405 */ 409 406 static int gpiodev_add_to_list_unlocked(struct gpio_device *gdev) 410 407 { ··· 1520 1517 * This function is a wrapper that calls gpiochip_lock_as_irq() and is to be 1521 1518 * used as the activate function for the &struct irq_domain_ops. The host_data 1522 1519 * for the IRQ domain must be the &struct gpio_chip. 1520 + * 1521 + * Returns: 1522 + * 0 on success, or negative errno on failure. 1523 1523 */ 1524 1524 static int gpiochip_irq_domain_activate(struct irq_domain *domain, 1525 1525 struct irq_data *data, bool reserve) ··· 1667 1661 * This function will set up the mapping for a certain IRQ line on a 1668 1662 * gpiochip by assigning the gpiochip as chip data, and using the irqchip 1669 1663 * stored inside the gpiochip. 1664 + * 1665 + * Returns: 1666 + * 0 on success, or negative errno on failure. 1670 1667 */ 1671 1668 static int gpiochip_irq_map(struct irq_domain *d, unsigned int irq, 1672 1669 irq_hw_number_t hwirq) ··· 1904 1895 * @gc: the GPIO chip to add the IRQ chip to 1905 1896 * @lock_key: lockdep class for IRQ lock 1906 1897 * @request_key: lockdep class for IRQ request 1898 + * 1899 + * Returns: 1900 + * 0 on success, or a negative errno on failure. 1907 1901 */ 1908 1902 static int gpiochip_add_irqchip(struct gpio_chip *gc, 1909 1903 struct lock_class_key *lock_key, ··· 2042 2030 * @domain: the irqdomain to add to the gpiochip 2043 2031 * 2044 2032 * This function adds an IRQ domain to the gpiochip. 2033 + * 2034 + * Returns: 2035 + * 0 on success, or negative errno on failure. 2045 2036 */ 2046 2037 int gpiochip_irqchip_add_domain(struct gpio_chip *gc, 2047 2038 struct irq_domain *domain) ··· 2081 2066 * gpiochip_generic_request() - request the gpio function for a pin 2082 2067 * @gc: the gpiochip owning the GPIO 2083 2068 * @offset: the offset of the GPIO to request for GPIO function 2069 + * 2070 + * Returns: 2071 + * 0 on success, or negative errno on failure. 2084 2072 */ 2085 2073 int gpiochip_generic_request(struct gpio_chip *gc, unsigned int offset) 2086 2074 { ··· 2117 2099 * @gc: the gpiochip owning the GPIO 2118 2100 * @offset: the offset of the GPIO to apply the configuration 2119 2101 * @config: the configuration to be applied 2102 + * 2103 + * Returns: 2104 + * 0 on success, or negative errno on failure. 2120 2105 */ 2121 2106 int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset, 2122 2107 unsigned long config) ··· 2146 2125 * pinctrl driver is DEPRECATED. Please see Section 2.1 of 2147 2126 * Documentation/devicetree/bindings/gpio/gpio.txt on how to 2148 2127 * bind pinctrl and gpio drivers via the "gpio-ranges" property. 2128 + * 2129 + * Returns: 2130 + * 0 on success, or negative errno on failure. 2149 2131 */ 2150 2132 int gpiochip_add_pingroup_range(struct gpio_chip *gc, 2151 2133 struct pinctrl_dev *pctldev, ··· 2200 2176 * @npins: the number of pins from the offset of each pin space (GPIO and 2201 2177 * pin controller) to accumulate in this range 2202 2178 * 2203 - * Returns: 2204 - * 0 on success, or a negative error-code on failure. 2205 - * 2206 2179 * Calling this function directly from a DeviceTree-supported 2207 2180 * pinctrl driver is DEPRECATED. Please see Section 2.1 of 2208 2181 * Documentation/devicetree/bindings/gpio/gpio.txt on how to 2209 2182 * bind pinctrl and gpio drivers via the "gpio-ranges" property. 2183 + * 2184 + * Returns: 2185 + * 0 on success, or a negative errno on failure. 2210 2186 */ 2211 2187 int gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name, 2212 2188 unsigned int gpio_offset, unsigned int pin_offset, ··· 2610 2586 * The function calls the certain GPIO driver to set debounce timeout 2611 2587 * in the hardware. 2612 2588 * 2613 - * Returns 0 on success, or negative error code otherwise. 2589 + * Returns: 2590 + * 0 on success, or negative errno on failure. 2614 2591 */ 2615 2592 int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce) 2616 2593 { ··· 2627 2602 * Set the direction of the passed GPIO to input, such as gpiod_get_value() can 2628 2603 * be called safely on it. 2629 2604 * 2630 - * Return 0 in case of success, else an error code. 2605 + * Returns: 2606 + * 0 on success, or negative errno on failure. 2631 2607 */ 2632 2608 int gpiod_direction_input(struct gpio_desc *desc) 2633 2609 { ··· 2735 2709 * be called safely on it. The initial value of the output must be specified 2736 2710 * as raw value on the physical line without regard for the ACTIVE_LOW status. 2737 2711 * 2738 - * Return 0 in case of success, else an error code. 2712 + * Returns: 2713 + * 0 on success, or negative errno on failure. 2739 2714 */ 2740 2715 int gpiod_direction_output_raw(struct gpio_desc *desc, int value) 2741 2716 { ··· 2755 2728 * as the logical value of the GPIO, i.e. taking its ACTIVE_LOW status into 2756 2729 * account. 2757 2730 * 2758 - * Return 0 in case of success, else an error code. 2731 + * Returns: 2732 + * 0 on success, or negative errno on failure. 2759 2733 */ 2760 2734 int gpiod_direction_output(struct gpio_desc *desc, int value) 2761 2735 { ··· 2829 2801 * @desc: GPIO to enable. 2830 2802 * @flags: Flags related to GPIO edge. 2831 2803 * 2832 - * Return 0 in case of success, else negative error code. 2804 + * Returns: 2805 + * 0 on success, or negative errno on failure. 2833 2806 */ 2834 2807 int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags) 2835 2808 { ··· 2862 2833 * @desc: GPIO to disable. 2863 2834 * @flags: Flags related to GPIO edge, same value as used during enable call. 2864 2835 * 2865 - * Return 0 in case of success, else negative error code. 2836 + * Returns: 2837 + * 0 on success, or negative errno on failure. 2866 2838 */ 2867 2839 int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags) 2868 2840 { ··· 2955 2925 * gpiod_is_active_low - test whether a GPIO is active-low or not 2956 2926 * @desc: the gpio descriptor to test 2957 2927 * 2958 - * Returns 1 if the GPIO is active-low, 0 otherwise. 2928 + * Returns: 2929 + * 1 if the GPIO is active-low, 0 otherwise. 2959 2930 */ 2960 2931 int gpiod_is_active_low(const struct gpio_desc *desc) 2961 2932 { ··· 3171 3140 * gpiod_get_raw_value() - return a gpio's raw value 3172 3141 * @desc: gpio whose value will be returned 3173 3142 * 3174 - * Return the GPIO's raw value, i.e. the value of the physical line disregarding 3143 + * Returns: 3144 + * The GPIO's raw value, i.e. the value of the physical line disregarding 3175 3145 * its ACTIVE_LOW status, or negative errno on failure. 3176 3146 * 3177 3147 * This function can be called from contexts where we cannot sleep, and will ··· 3191 3159 * gpiod_get_value() - return a gpio's value 3192 3160 * @desc: gpio whose value will be returned 3193 3161 * 3194 - * Return the GPIO's logical value, i.e. taking the ACTIVE_LOW status into 3162 + * Returns: 3163 + * The GPIO's logical value, i.e. taking the ACTIVE_LOW status into 3195 3164 * account, or negative errno on failure. 3196 3165 * 3197 3166 * This function can be called from contexts where we cannot sleep, and will ··· 3225 3192 * @value_bitmap: bitmap to store the read values 3226 3193 * 3227 3194 * Read the raw values of the GPIOs, i.e. the values of the physical lines 3228 - * without regard for their ACTIVE_LOW status. Return 0 in case of success, 3229 - * else an error code. 3195 + * without regard for their ACTIVE_LOW status. 3230 3196 * 3231 3197 * This function can be called from contexts where we cannot sleep, 3232 3198 * and it will complain if the GPIO chip functions potentially sleep. 3199 + * 3200 + * Returns: 3201 + * 0 on success, or negative errno on failure. 3233 3202 */ 3234 3203 int gpiod_get_raw_array_value(unsigned int array_size, 3235 3204 struct gpio_desc **desc_array, ··· 3254 3219 * @value_bitmap: bitmap to store the read values 3255 3220 * 3256 3221 * Read the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status 3257 - * into account. Return 0 in case of success, else an error code. 3222 + * into account. 3258 3223 * 3259 3224 * This function can be called from contexts where we cannot sleep, 3260 3225 * and it will complain if the GPIO chip functions potentially sleep. 3226 + * 3227 + * Returns: 3228 + * 0 on success, or negative errno on failure. 3261 3229 */ 3262 3230 int gpiod_get_array_value(unsigned int array_size, 3263 3231 struct gpio_desc **desc_array, ··· 3548 3510 * 3549 3511 * This function can be called from contexts where we cannot sleep, and will 3550 3512 * complain if the GPIO chip functions potentially sleep. 3513 + * 3514 + * Returns: 3515 + * 0 on success, or negative errno on failure. 3551 3516 */ 3552 3517 int gpiod_set_raw_array_value(unsigned int array_size, 3553 3518 struct gpio_desc **desc_array, ··· 3576 3535 * 3577 3536 * This function can be called from contexts where we cannot sleep, and will 3578 3537 * complain if the GPIO chip functions potentially sleep. 3538 + * 3539 + * Returns: 3540 + * 0 on success, or negative errno on failure. 3579 3541 */ 3580 3542 int gpiod_set_array_value(unsigned int array_size, 3581 3543 struct gpio_desc **desc_array, ··· 3597 3553 * gpiod_cansleep() - report whether gpio value access may sleep 3598 3554 * @desc: gpio to check 3599 3555 * 3556 + * Returns: 3557 + * 0 for non-sleepable, 1 for sleepable, or an error code in case of error. 3600 3558 */ 3601 3559 int gpiod_cansleep(const struct gpio_desc *desc) 3602 3560 { ··· 3611 3565 * gpiod_set_consumer_name() - set the consumer name for the descriptor 3612 3566 * @desc: gpio to set the consumer name on 3613 3567 * @name: the new consumer name 3568 + * 3569 + * Returns: 3570 + * 0 on success, or negative errno on failure. 3614 3571 */ 3615 3572 int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name) 3616 3573 { ··· 3627 3578 * gpiod_to_irq() - return the IRQ corresponding to a GPIO 3628 3579 * @desc: gpio whose IRQ will be returned (already requested) 3629 3580 * 3630 - * Return the IRQ corresponding to the passed GPIO, or an error code in case of 3631 - * error. 3581 + * Returns: 3582 + * The IRQ corresponding to the passed GPIO, or an error code in case of error. 3632 3583 */ 3633 3584 int gpiod_to_irq(const struct gpio_desc *desc) 3634 3585 { ··· 3641 3592 * requires this function to not return zero on an invalid descriptor 3642 3593 * but rather a negative error number. 3643 3594 */ 3644 - if (!desc || IS_ERR(desc)) 3595 + if (IS_ERR_OR_NULL(desc)) 3645 3596 return -EINVAL; 3646 3597 3647 3598 gdev = desc->gdev; ··· 3682 3633 * 3683 3634 * This is used directly by GPIO drivers that want to lock down 3684 3635 * a certain GPIO line to be used for IRQs. 3636 + * 3637 + * Returns: 3638 + * 0 on success, or negative errno on failure. 3685 3639 */ 3686 3640 int gpiochip_lock_as_irq(struct gpio_chip *gc, unsigned int offset) 3687 3641 { ··· 3836 3784 * gpiod_get_raw_value_cansleep() - return a gpio's raw value 3837 3785 * @desc: gpio whose value will be returned 3838 3786 * 3839 - * Return the GPIO's raw value, i.e. the value of the physical line disregarding 3787 + * Returns: 3788 + * The GPIO's raw value, i.e. the value of the physical line disregarding 3840 3789 * its ACTIVE_LOW status, or negative errno on failure. 3841 3790 * 3842 3791 * This function is to be called from contexts that can sleep. ··· 3854 3801 * gpiod_get_value_cansleep() - return a gpio's value 3855 3802 * @desc: gpio whose value will be returned 3856 3803 * 3857 - * Return the GPIO's logical value, i.e. taking the ACTIVE_LOW status into 3804 + * Returns: 3805 + * The GPIO's logical value, i.e. taking the ACTIVE_LOW status into 3858 3806 * account, or negative errno on failure. 3859 3807 * 3860 3808 * This function is to be called from contexts that can sleep. ··· 3885 3831 * @value_bitmap: bitmap to store the read values 3886 3832 * 3887 3833 * Read the raw values of the GPIOs, i.e. the values of the physical lines 3888 - * without regard for their ACTIVE_LOW status. Return 0 in case of success, 3889 - * else an error code. 3834 + * without regard for their ACTIVE_LOW status. 3890 3835 * 3891 3836 * This function is to be called from contexts that can sleep. 3837 + * 3838 + * Returns: 3839 + * 0 on success, or negative errno on failure. 3892 3840 */ 3893 3841 int gpiod_get_raw_array_value_cansleep(unsigned int array_size, 3894 3842 struct gpio_desc **desc_array, ··· 3914 3858 * @value_bitmap: bitmap to store the read values 3915 3859 * 3916 3860 * Read the logical values of the GPIOs, i.e. taking their ACTIVE_LOW status 3917 - * into account. Return 0 in case of success, else an error code. 3861 + * into account. 3918 3862 * 3919 3863 * This function is to be called from contexts that can sleep. 3864 + * 3865 + * Returns: 3866 + * 0 on success, or negative errno on failure. 3920 3867 */ 3921 3868 int gpiod_get_array_value_cansleep(unsigned int array_size, 3922 3869 struct gpio_desc **desc_array, ··· 3982 3923 * without regard for their ACTIVE_LOW status. 3983 3924 * 3984 3925 * This function is to be called from contexts that can sleep. 3926 + * 3927 + * Returns: 3928 + * 0 on success, or negative errno on failure. 3985 3929 */ 3986 3930 int gpiod_set_raw_array_value_cansleep(unsigned int array_size, 3987 3931 struct gpio_desc **desc_array, ··· 4027 3965 * into account. 4028 3966 * 4029 3967 * This function is to be called from contexts that can sleep. 3968 + * 3969 + * Returns: 3970 + * 0 on success, or negative errno on failure. 4030 3971 */ 4031 3972 int gpiod_set_array_value_cansleep(unsigned int array_size, 4032 3973 struct gpio_desc **desc_array, ··· 4363 4298 4364 4299 /** 4365 4300 * gpiod_count - return the number of GPIOs associated with a device / function 4366 - * or -ENOENT if no GPIO has been assigned to the requested function 4367 4301 * @dev: GPIO consumer, can be NULL for system-global GPIOs 4368 4302 * @con_id: function within the GPIO consumer 4303 + * 4304 + * Returns: 4305 + * The number of GPIOs associated with a device / function or -ENOENT if no 4306 + * GPIO has been assigned to the requested function. 4369 4307 */ 4370 4308 int gpiod_count(struct device *dev, const char *con_id) 4371 4309 { ··· 4395 4327 * @con_id: function within the GPIO consumer 4396 4328 * @flags: optional GPIO initialization flags 4397 4329 * 4398 - * Return the GPIO descriptor corresponding to the function con_id of device 4330 + * Returns: 4331 + * The GPIO descriptor corresponding to the function @con_id of device 4399 4332 * dev, -ENOENT if no GPIO has been assigned to the requested function, or 4400 4333 * another IS_ERR() code if an error occurred while trying to acquire the GPIO. 4401 4334 */ ··· 4416 4347 * This is equivalent to gpiod_get(), except that when no GPIO was assigned to 4417 4348 * the requested function it will return NULL. This is convenient for drivers 4418 4349 * that need to handle optional GPIOs. 4350 + * 4351 + * Returns: 4352 + * The GPIO descriptor corresponding to the function @con_id of device 4353 + * dev, NULL if no GPIO has been assigned to the requested function, or 4354 + * another IS_ERR() code if an error occurred while trying to acquire the GPIO. 4419 4355 */ 4420 4356 struct gpio_desc *__must_check gpiod_get_optional(struct device *dev, 4421 4357 const char *con_id, ··· 4439 4365 * of_find_gpio() or of_get_gpio_hog() 4440 4366 * @dflags: gpiod_flags - optional GPIO initialization flags 4441 4367 * 4442 - * Return 0 on success, -ENOENT if no GPIO has been assigned to the 4368 + * Returns: 4369 + * 0 on success, -ENOENT if no GPIO has been assigned to the 4443 4370 * requested function and/or index, or another IS_ERR() code if an error 4444 4371 * occurred while trying to acquire the GPIO. 4445 4372 */ ··· 4515 4440 * This variant of gpiod_get() allows to access GPIOs other than the first 4516 4441 * defined one for functions that define several GPIOs. 4517 4442 * 4518 - * Return a valid GPIO descriptor, -ENOENT if no GPIO has been assigned to the 4443 + * Returns: 4444 + * A valid GPIO descriptor, -ENOENT if no GPIO has been assigned to the 4519 4445 * requested function and/or index, or another IS_ERR() code if an error 4520 4446 * occurred while trying to acquire the GPIO. 4521 4447 */ ··· 4544 4468 * This is equivalent to gpiod_get_index(), except that when no GPIO with the 4545 4469 * specified index was assigned to the requested function it will return NULL. 4546 4470 * This is convenient for drivers that need to handle optional GPIOs. 4471 + * 4472 + * Returns: 4473 + * A valid GPIO descriptor, NULL if no GPIO has been assigned to the 4474 + * requested function and/or index, or another IS_ERR() code if an error 4475 + * occurred while trying to acquire the GPIO. 4547 4476 */ 4548 4477 struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev, 4549 4478 const char *con_id, ··· 4572 4491 * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from 4573 4492 * of_find_gpio() or of_get_gpio_hog() 4574 4493 * @dflags: gpiod_flags - optional GPIO initialization flags 4494 + * 4495 + * Returns: 4496 + * 0 on success, or negative errno on failure. 4575 4497 */ 4576 4498 int gpiod_hog(struct gpio_desc *desc, const char *name, 4577 4499 unsigned long lflags, enum gpiod_flags dflags) ··· 4631 4547 * 4632 4548 * This function acquires all the GPIOs defined under a given function. 4633 4549 * 4634 - * Return a struct gpio_descs containing an array of descriptors, -ENOENT if 4635 - * no GPIO has been assigned to the requested function, or another IS_ERR() 4636 - * code if an error occurred while trying to acquire the GPIOs. 4550 + * Returns: 4551 + * The GPIO descriptors corresponding to the function @con_id of device 4552 + * dev, -ENOENT if no GPIO has been assigned to the requested function, 4553 + * or another IS_ERR() code if an error occurred while trying to acquire 4554 + * the GPIOs. 4637 4555 */ 4638 4556 struct gpio_descs *__must_check gpiod_get_array(struct device *dev, 4639 4557 const char *con_id, ··· 4761 4675 * 4762 4676 * This is equivalent to gpiod_get_array(), except that when no GPIO was 4763 4677 * assigned to the requested function it will return NULL. 4678 + * 4679 + * Returns: 4680 + * The GPIO descriptors corresponding to the function @con_id of device 4681 + * dev, NULL if no GPIO has been assigned to the requested function, 4682 + * or another IS_ERR() code if an error occurred while trying to acquire 4683 + * the GPIOs. 4764 4684 */ 4765 4685 struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev, 4766 4686 const char *con_id,
+14 -2
drivers/gpio/gpiolib.h
··· 89 89 return container_of(dev, struct gpio_device, dev); 90 90 } 91 91 92 - /* gpio suffixes used for ACPI and device tree lookup */ 92 + /* GPIO suffixes used for ACPI and device tree lookup */ 93 93 extern const char *const gpio_suffixes[]; 94 - extern const size_t gpio_suffix_count; 94 + 95 + #define for_each_gpio_property_name(propname, con_id) \ 96 + for (const char * const *__suffixes = gpio_suffixes; \ 97 + *__suffixes && ({ \ 98 + const char *__gs = *__suffixes; \ 99 + \ 100 + if (con_id) \ 101 + snprintf(propname, sizeof(propname), "%s-%s", con_id, __gs); \ 102 + else \ 103 + snprintf(propname, sizeof(propname), "%s", __gs); \ 104 + 1; \ 105 + }); \ 106 + __suffixes++) 95 107 96 108 /** 97 109 * struct gpio_array - Opaque descriptor for a structure of GPIO array attributes
+3 -9
include/linux/gpio.h
··· 17 17 struct device; 18 18 19 19 /* make these flag values available regardless of GPIO kconfig options */ 20 - #define GPIOF_DIR_OUT (0 << 0) 21 - #define GPIOF_DIR_IN (1 << 0) 22 - 23 - #define GPIOF_INIT_LOW (0 << 1) 24 - #define GPIOF_INIT_HIGH (1 << 1) 25 - 26 - #define GPIOF_IN (GPIOF_DIR_IN) 27 - #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW) 28 - #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH) 20 + #define GPIOF_IN ((1 << 0)) 21 + #define GPIOF_OUT_INIT_LOW ((0 << 0) | (0 << 1)) 22 + #define GPIOF_OUT_INIT_HIGH ((0 << 0) | (1 << 1)) 29 23 30 24 /* Gpio pin is active-low */ 31 25 #define GPIOF_ACTIVE_LOW (1 << 2)
-16
include/linux/platform_data/gpio-ath79.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Atheros AR7XXX/AR9XXX GPIO controller platform data 4 - * 5 - * Copyright (C) 2015 Alban Bedel <albeu@free.fr> 6 - */ 7 - 8 - #ifndef __LINUX_PLATFORM_DATA_GPIO_ATH79_H 9 - #define __LINUX_PLATFORM_DATA_GPIO_ATH79_H 10 - 11 - struct ath79_gpio_platform_data { 12 - unsigned ngpios; 13 - bool oe_inverted; 14 - }; 15 - 16 - #endif
-21
include/linux/platform_data/gpio-davinci.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * DaVinci GPIO Platform Related Defines 4 - * 5 - * Copyright (C) 2013 Texas Instruments Incorporated - https://www.ti.com/ 6 - */ 7 - 8 - #ifndef __DAVINCI_GPIO_PLATFORM_H 9 - #define __DAVINCI_GPIO_PLATFORM_H 10 - 11 - struct davinci_gpio_platform_data { 12 - bool no_auto_base; 13 - u32 base; 14 - u32 ngpio; 15 - u32 gpio_unbanked; 16 - }; 17 - 18 - /* Convert GPIO signal to GPIO pin number */ 19 - #define GPIO_TO_PIN(bank, gpio) (16 * (bank) + (gpio)) 20 - 21 - #endif
+1 -1
tools/gpio/Makefile
··· 78 78 clean: 79 79 rm -f $(ALL_PROGRAMS) 80 80 rm -f $(OUTPUT)include/linux/gpio.h 81 - find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete 81 + find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete -o -name '\.*.cmd' -delete 82 82 83 83 install: $(ALL_PROGRAMS) 84 84 install -d -m 755 $(DESTDIR)$(bindir); \
+2 -2
tools/gpio/gpio-hammer.c
··· 54 54 55 55 fprintf(stdout, "Hammer lines ["); 56 56 for (i = 0; i < num_lines; i++) { 57 - fprintf(stdout, "%d", lines[i]); 57 + fprintf(stdout, "%u", lines[i]); 58 58 if (i != (num_lines - 1)) 59 59 fprintf(stdout, ", "); 60 60 } ··· 89 89 90 90 fprintf(stdout, "["); 91 91 for (i = 0; i < num_lines; i++) { 92 - fprintf(stdout, "%d: %d", lines[i], 92 + fprintf(stdout, "%u: %d", lines[i], 93 93 gpiotools_test_bit(values.bits, i)); 94 94 if (i != (num_lines - 1)) 95 95 fprintf(stdout, ", ");