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

Merge tag 'gpio-v3.17-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio

Pull GPIO update from Linus Walleij:
"This is the bulk of GPIO changes for the v3.17 development cycle, and
this time we got a lot of action going on and it will continue:

- The core GPIO library implementation has been split up in three
different files:
- gpiolib.c for the latest and greatest and shiny GPIO library code
using GPIO descriptors only
- gpiolib-legacy.c for the old integer number space API that we are
phasing out gradually
- gpiolib-sysfs.c for the sysfs interface that we are not entirely
happy with, but has to live on for ABI compatibility

- Add a flags argument to *gpiod_get* functions, with some
backward-compatibility macros to ease transitions. We should have
had the flags there from the beginning it seems, now we need to
clean up the mess. There is a plan on how to move forward here
devised by Alexandre Courbot and Mark Brown

- Split off a special <linux/gpio/machine.h> header for the board
gpio table registration, as per example from the regulator
subsystem

- Start to kill off the return value from gpiochip_remove() by
removing the __must_check attribute and removing all checks inside
the drivers/gpio directory. The rationale is: well what were we
supposed to do if there is an error code? Not much: print an error
message. And gpiolib already does that. So make this function
return void eventually

- Some cleanups of hairy gpiolib code, make some functions not to be
used outside the library private and make sure they are not
exported, remove gpiod_lock/unlock_as_irq() as the existing
function is for driver-internal use and fine as it is, delete
gpio_ensure_requested() as it is not meaningful anymore

- Support the GPIOF_ACTIVE_LOW flag from gpio_request_one() function
calls, which is logical since this is already supported when
referencing GPIOs from e.g. device trees

- Switch STMPE, intel-mid, lynxpoint and ACPI (!) to use the gpiolib
irqchip helpers cutting down on GPIO irqchip boilerplate a bit more

- New driver for the Zynq GPIO block

- The usual incremental improvements around a bunch of drivers

- Janitorial syntactic and semantic cleanups by Jingoo Han, and
Rickard Strandqvist especially"

* tag 'gpio-v3.17-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (37 commits)
MAINTAINERS: update GPIO include files
gpio: add missing includes in machine.h
gpio: add flags argument to gpiod_get*() functions
MAINTAINERS: Update Samsung pin control entry
gpio / ACPI: Move event handling registration to gpiolib irqchip helpers
gpio: lynxpoint: Convert to use gpiolib irqchip
gpio: split gpiod board registration into machine header
gpio: remove gpio_ensure_requested()
gpio: remove useless check in gpiolib_sysfs_init()
gpiolib: Export gpiochip_request_own_desc and gpiochip_free_own_desc
gpio: move gpio_ensure_requested() into legacy C file
gpio: remove gpiod_lock/unlock_as_irq()
gpio: make gpiochip_get_desc() gpiolib-private
gpio: simplify gpiochip_export()
gpio: remove export of private of_get_named_gpio_flags()
gpio: Add support for GPIOF_ACTIVE_LOW to gpio_request_one functions
gpio: zynq: Clear pending interrupt when enabling a IRQ
gpio: drop retval check enforcing from gpiochip_remove()
gpio: remove all usage of gpio_remove retval in driver/gpio
devicetree: Add Zynq GPIO devicetree bindings documentation
...

+2413 -1931
+26
Documentation/devicetree/bindings/gpio/gpio-zynq.txt
··· 1 + Xilinx Zynq GPIO controller Device Tree Bindings 2 + ------------------------------------------- 3 + 4 + Required properties: 5 + - #gpio-cells : Should be two 6 + - First cell is the GPIO line number 7 + - Second cell is used to specify optional 8 + parameters (unused) 9 + - compatible : Should be "xlnx,zynq-gpio-1.0" 10 + - clocks : Clock specifier (see clock bindings for details) 11 + - gpio-controller : Marks the device node as a GPIO controller. 12 + - interrupts : Interrupt specifier (see interrupt bindings for 13 + details) 14 + - interrupt-parent : Must be core interrupt controller 15 + - reg : Address and length of the register set for the device 16 + 17 + Example: 18 + gpio@e000a000 { 19 + #gpio-cells = <2>; 20 + compatible = "xlnx,zynq-gpio-1.0"; 21 + clocks = <&clkc 42>; 22 + gpio-controller; 23 + interrupt-parent = <&intc>; 24 + interrupts = <0 20 4>; 25 + reg = <0xe000a000 0x1000>; 26 + };
+1 -1
Documentation/gpio/board.txt
··· 60 60 Finally, GPIOs can be bound to devices and functions using platform data. Board 61 61 files that desire to do so need to include the following header: 62 62 63 - #include <linux/gpio/driver.h> 63 + #include <linux/gpio/machine.h> 64 64 65 65 GPIOs are mapped by the means of tables of lookups, containing instances of the 66 66 gpiod_lookup structure. Two macros are defined to help declaring such mappings:
+20 -6
Documentation/gpio/consumer.txt
··· 29 29 device that will use the GPIO and the function the requested GPIO is supposed to 30 30 fulfill: 31 31 32 - struct gpio_desc *gpiod_get(struct device *dev, const char *con_id) 32 + struct gpio_desc *gpiod_get(struct device *dev, const char *con_id, 33 + enum gpiod_flags flags) 33 34 34 35 If a function is implemented by using several GPIOs together (e.g. a simple LED 35 36 device that displays digits), an additional index argument can be specified: 36 37 37 38 struct gpio_desc *gpiod_get_index(struct device *dev, 38 - const char *con_id, unsigned int idx) 39 + const char *con_id, unsigned int idx, 40 + enum gpiod_flags flags) 41 + 42 + The flags parameter is used to optionally specify a direction and initial value 43 + for the GPIO. Values can be: 44 + 45 + * GPIOD_ASIS or 0 to not initialize the GPIO at all. The direction must be set 46 + later with one of the dedicated functions. 47 + * GPIOD_IN to initialize the GPIO as input. 48 + * GPIOD_OUT_LOW to initialize the GPIO as output with a value of 0. 49 + * GPIOD_OUT_HIGH to initialize the GPIO as output with a value of 1. 39 50 40 51 Both functions return either a valid GPIO descriptor, or an error code checkable 41 52 with IS_ERR() (they will never return a NULL pointer). -ENOENT will be returned ··· 57 46 58 47 Device-managed variants of these functions are also defined: 59 48 60 - struct gpio_desc *devm_gpiod_get(struct device *dev, const char *con_id) 49 + struct gpio_desc *devm_gpiod_get(struct device *dev, const char *con_id, 50 + enum gpiod_flags flags) 61 51 62 52 struct gpio_desc *devm_gpiod_get_index(struct device *dev, 63 53 const char *con_id, 64 - unsigned int idx) 54 + unsigned int idx, 55 + enum gpiod_flags flags) 65 56 66 57 A GPIO descriptor can be disposed of using the gpiod_put() function: 67 58 ··· 80 67 81 68 Setting Direction 82 69 ----------------- 83 - The first thing a driver must do with a GPIO is setting its direction. This is 84 - done by invoking one of the gpiod_direction_*() functions: 70 + The first thing a driver must do with a GPIO is setting its direction. If no 71 + direction-setting flags have been given to gpiod_get*(), this is done by 72 + invoking one of the gpiod_direction_*() functions: 85 73 86 74 int gpiod_direction_input(struct gpio_desc *desc) 87 75 int gpiod_direction_output(struct gpio_desc *desc, int value)
+23 -2
Documentation/gpio/driver.txt
··· 157 157 Input GPIOs can be used as IRQ signals. When this happens, a driver is requested 158 158 to mark the GPIO as being used as an IRQ: 159 159 160 - int gpiod_lock_as_irq(struct gpio_desc *desc) 160 + int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset) 161 161 162 162 This will prevent the use of non-irq related GPIO APIs until the GPIO IRQ lock 163 163 is released: 164 164 165 - void gpiod_unlock_as_irq(struct gpio_desc *desc) 165 + void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset) 166 166 167 167 When implementing an irqchip inside a GPIO driver, these two functions should 168 168 typically be called in the .startup() and .shutdown() callbacks from the 169 169 irqchip. 170 + 171 + 172 + Requesting self-owned GPIO pins 173 + ------------------------------- 174 + 175 + Sometimes it is useful to allow a GPIO chip driver to request its own GPIO 176 + descriptors through the gpiolib API. Using gpio_request() for this purpose 177 + does not help since it pins the module to the kernel forever (it calls 178 + try_module_get()). A GPIO driver can use the following functions instead 179 + to request and free descriptors without being pinned to the kernel forever. 180 + 181 + int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label) 182 + 183 + void gpiochip_free_own_desc(struct gpio_desc *desc) 184 + 185 + Descriptors requested with gpiochip_request_own_desc() must be released with 186 + gpiochip_free_own_desc(). 187 + 188 + These functions must be used with care since they do not affect module use 189 + count. Do not use the functions to request gpio descriptors not owned by the 190 + calling driver.
+3 -4
MAINTAINERS
··· 4031 4031 S: Maintained 4032 4032 F: Documentation/gpio/ 4033 4033 F: drivers/gpio/ 4034 - F: include/linux/gpio* 4034 + F: include/linux/gpio/ 4035 + F: include/linux/gpio.h 4035 4036 F: include/asm-generic/gpio.h 4036 4037 4037 4038 GRE DEMULTIPLEXER DRIVER ··· 7003 7002 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 7004 7003 L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers) 7005 7004 S: Maintained 7006 - F: drivers/pinctrl/pinctrl-exynos.* 7007 - F: drivers/pinctrl/pinctrl-s3c* 7008 - F: drivers/pinctrl/pinctrl-samsung.* 7005 + F: drivers/pinctrl/samsung/ 7009 7006 7010 7007 PIN CONTROLLER - ST SPEAR 7011 7008 M: Viresh Kumar <viresh.linux@gmail.com>
+1 -1
arch/arm/mach-at91/at91rm9200_devices.c
··· 15 15 16 16 #include <linux/dma-mapping.h> 17 17 #include <linux/gpio.h> 18 - #include <linux/gpio/driver.h> 18 + #include <linux/gpio/machine.h> 19 19 #include <linux/platform_device.h> 20 20 #include <linux/i2c-gpio.h> 21 21
+1 -1
arch/arm/mach-tegra/board-paz00.c
··· 17 17 * 18 18 */ 19 19 20 - #include <linux/gpio/driver.h> 20 + #include <linux/gpio/machine.h> 21 21 #include <linux/platform_device.h> 22 22 #include <linux/rfkill-gpio.h> 23 23
+1
arch/mips/jz4740/board-qi_lb60.c
··· 15 15 #include <linux/kernel.h> 16 16 #include <linux/init.h> 17 17 #include <linux/gpio.h> 18 + #include <linux/gpio/machine.h> 18 19 19 20 #include <linux/input.h> 20 21 #include <linux/gpio_keys.h>
+9 -1
drivers/gpio/Kconfig
··· 340 340 help 341 341 Say yes here to support the Xilinx FPGA GPIO device 342 342 343 + config GPIO_ZYNQ 344 + tristate "Xilinx Zynq GPIO support" 345 + depends on ARCH_ZYNQ 346 + select GPIOLIB_IRQCHIP 347 + help 348 + Say yes here to support Xilinx Zynq GPIO controller. 349 + 343 350 config GPIO_XTENSA 344 351 bool "Xtensa GPIO32 support" 345 352 depends on XTENSA ··· 430 423 config GPIO_LYNXPOINT 431 424 tristate "Intel Lynxpoint GPIO support" 432 425 depends on ACPI && X86 433 - select IRQ_DOMAIN 426 + select GPIOLIB_IRQCHIP 434 427 help 435 428 driver for GPIO functionality on Intel Lynxpoint PCH chipset 436 429 Requires ACPI device enumeration code to set up a platform device. ··· 593 586 config GPIO_STMPE 594 587 bool "STMPE GPIOs" 595 588 depends on MFD_STMPE 589 + select GPIOLIB_IRQCHIP 596 590 help 597 591 This enables support for the GPIOs found on the STMPE I/O 598 592 Expanders.
+3
drivers/gpio/Makefile
··· 4 4 5 5 obj-$(CONFIG_GPIO_DEVRES) += devres.o 6 6 obj-$(CONFIG_GPIOLIB) += gpiolib.o 7 + obj-$(CONFIG_GPIOLIB) += gpiolib-legacy.o 7 8 obj-$(CONFIG_OF_GPIO) += gpiolib-of.o 9 + obj-$(CONFIG_GPIO_SYSFS) += gpiolib-sysfs.o 8 10 obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o 9 11 10 12 # Device drivers. Generally keep list sorted alphabetically ··· 104 102 obj-$(CONFIG_GPIO_XILINX) += gpio-xilinx.o 105 103 obj-$(CONFIG_GPIO_XTENSA) += gpio-xtensa.o 106 104 obj-$(CONFIG_GPIO_ZEVIO) += gpio-zevio.o 105 + obj-$(CONFIG_GPIO_ZYNQ) += gpio-zynq.o
+24 -16
drivers/gpio/devres.c
··· 39 39 * devm_gpiod_get - Resource-managed gpiod_get() 40 40 * @dev: GPIO consumer 41 41 * @con_id: function within the GPIO consumer 42 + * @flags: optional GPIO initialization flags 42 43 * 43 44 * Managed gpiod_get(). GPIO descriptors returned from this function are 44 45 * automatically disposed on driver detach. See gpiod_get() for detailed 45 46 * information about behavior and return values. 46 47 */ 47 - struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, 48 - const char *con_id) 48 + struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, 49 + const char *con_id, 50 + enum gpiod_flags flags) 49 51 { 50 - return devm_gpiod_get_index(dev, con_id, 0); 52 + return devm_gpiod_get_index(dev, con_id, 0, flags); 51 53 } 52 - EXPORT_SYMBOL(devm_gpiod_get); 54 + EXPORT_SYMBOL(__devm_gpiod_get); 53 55 54 56 /** 55 57 * devm_gpiod_get_optional - Resource-managed gpiod_get_optional() 56 58 * @dev: GPIO consumer 57 59 * @con_id: function within the GPIO consumer 60 + * @flags: optional GPIO initialization flags 58 61 * 59 62 * Managed gpiod_get_optional(). GPIO descriptors returned from this function 60 63 * are automatically disposed on driver detach. See gpiod_get_optional() for 61 64 * detailed information about behavior and return values. 62 65 */ 63 - struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev, 64 - const char *con_id) 66 + struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev, 67 + const char *con_id, 68 + enum gpiod_flags flags) 65 69 { 66 - return devm_gpiod_get_index_optional(dev, con_id, 0); 70 + return devm_gpiod_get_index_optional(dev, con_id, 0, flags); 67 71 } 68 - EXPORT_SYMBOL(devm_gpiod_get_optional); 72 + EXPORT_SYMBOL(__devm_gpiod_get_optional); 69 73 70 74 /** 71 75 * devm_gpiod_get_index - Resource-managed gpiod_get_index() 72 76 * @dev: GPIO consumer 73 77 * @con_id: function within the GPIO consumer 74 78 * @idx: index of the GPIO to obtain in the consumer 79 + * @flags: optional GPIO initialization flags 75 80 * 76 81 * Managed gpiod_get_index(). GPIO descriptors returned from this function are 77 82 * automatically disposed on driver detach. See gpiod_get_index() for detailed 78 83 * information about behavior and return values. 79 84 */ 80 - struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, 85 + struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev, 81 86 const char *con_id, 82 - unsigned int idx) 87 + unsigned int idx, 88 + enum gpiod_flags flags) 83 89 { 84 90 struct gpio_desc **dr; 85 91 struct gpio_desc *desc; ··· 95 89 if (!dr) 96 90 return ERR_PTR(-ENOMEM); 97 91 98 - desc = gpiod_get_index(dev, con_id, idx); 92 + desc = gpiod_get_index(dev, con_id, idx, flags); 99 93 if (IS_ERR(desc)) { 100 94 devres_free(dr); 101 95 return desc; ··· 106 100 107 101 return desc; 108 102 } 109 - EXPORT_SYMBOL(devm_gpiod_get_index); 103 + EXPORT_SYMBOL(__devm_gpiod_get_index); 110 104 111 105 /** 112 106 * devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional() 113 107 * @dev: GPIO consumer 114 108 * @con_id: function within the GPIO consumer 115 109 * @index: index of the GPIO to obtain in the consumer 110 + * @flags: optional GPIO initialization flags 116 111 * 117 112 * Managed gpiod_get_index_optional(). GPIO descriptors returned from this 118 113 * function are automatically disposed on driver detach. See 119 114 * gpiod_get_index_optional() for detailed information about behavior and 120 115 * return values. 121 116 */ 122 - struct gpio_desc *__must_check devm_gpiod_get_index_optional(struct device *dev, 117 + struct gpio_desc *__must_check __devm_gpiod_get_index_optional(struct device *dev, 123 118 const char *con_id, 124 - unsigned int index) 119 + unsigned int index, 120 + enum gpiod_flags flags) 125 121 { 126 122 struct gpio_desc *desc; 127 123 128 - desc = devm_gpiod_get_index(dev, con_id, index); 124 + desc = devm_gpiod_get_index(dev, con_id, index, flags); 129 125 if (IS_ERR(desc)) { 130 126 if (PTR_ERR(desc) == -ENOENT) 131 127 return NULL; ··· 135 127 136 128 return desc; 137 129 } 138 - EXPORT_SYMBOL(devm_gpiod_get_index_optional); 130 + EXPORT_SYMBOL(__devm_gpiod_get_index_optional); 139 131 140 132 /** 141 133 * devm_gpiod_put - Resource-managed gpiod_put()
+3 -5
drivers/gpio/gpio-74x164.c
··· 167 167 static int gen_74x164_remove(struct spi_device *spi) 168 168 { 169 169 struct gen_74x164_chip *chip = spi_get_drvdata(spi); 170 - int ret; 171 170 172 - ret = gpiochip_remove(&chip->gpio_chip); 173 - if (!ret) 174 - mutex_destroy(&chip->lock); 171 + gpiochip_remove(&chip->gpio_chip); 172 + mutex_destroy(&chip->lock); 175 173 176 - return ret; 174 + return 0; 177 175 } 178 176 179 177 static const struct of_device_id gen_74x164_dt_ids[] = {
+1 -8
drivers/gpio/gpio-adnp.c
··· 585 585 { 586 586 struct adnp *adnp = i2c_get_clientdata(client); 587 587 struct device_node *np = client->dev.of_node; 588 - int err; 589 588 590 - err = gpiochip_remove(&adnp->gpio); 591 - if (err < 0) { 592 - dev_err(&client->dev, "%s failed: %d\n", "gpiochip_remove()", 593 - err); 594 - return err; 595 - } 596 - 589 + gpiochip_remove(&adnp->gpio); 597 590 if (of_find_property(np, "interrupt-controller", NULL)) 598 591 adnp_irq_teardown(adnp); 599 592
+1 -7
drivers/gpio/gpio-adp5520.c
··· 167 167 static int adp5520_gpio_remove(struct platform_device *pdev) 168 168 { 169 169 struct adp5520_gpio *dev; 170 - int ret; 171 170 172 171 dev = platform_get_drvdata(pdev); 173 - ret = gpiochip_remove(&dev->gpio_chip); 174 - if (ret) { 175 - dev_err(&pdev->dev, "%s failed, %d\n", 176 - "gpiochip_remove()", ret); 177 - return ret; 178 - } 172 + gpiochip_remove(&dev->gpio_chip); 179 173 180 174 return 0; 181 175 }
+1 -5
drivers/gpio/gpio-adp5588.c
··· 470 470 if (dev->irq_base) 471 471 free_irq(dev->client->irq, dev); 472 472 473 - ret = gpiochip_remove(&dev->gpio_chip); 474 - if (ret) { 475 - dev_err(&client->dev, "gpiochip_remove failed %d\n", ret); 476 - return ret; 477 - } 473 + gpiochip_remove(&dev->gpio_chip); 478 474 479 475 kfree(dev); 480 476 return 0;
+1 -2
drivers/gpio/gpio-amd8111.c
··· 232 232 233 233 static void __exit amd_gpio_exit(void) 234 234 { 235 - int err = gpiochip_remove(&gp.chip); 236 - WARN_ON(err); 235 + gpiochip_remove(&gp.chip); 237 236 ioport_unmap(gp.pm); 238 237 release_region(gp.pmbase + PMBASE_OFFSET, PMBASE_SIZE); 239 238 }
+2 -1
drivers/gpio/gpio-arizona.c
··· 149 149 { 150 150 struct arizona_gpio *arizona_gpio = platform_get_drvdata(pdev); 151 151 152 - return gpiochip_remove(&arizona_gpio->gpio_chip); 152 + gpiochip_remove(&arizona_gpio->gpio_chip); 153 + return 0; 153 154 } 154 155 155 156 static struct platform_driver arizona_gpio_driver = {
+1 -7
drivers/gpio/gpio-cs5535.c
··· 358 358 static int cs5535_gpio_remove(struct platform_device *pdev) 359 359 { 360 360 struct resource *r; 361 - int err; 362 361 363 - err = gpiochip_remove(&cs5535_gpio_chip.chip); 364 - if (err) { 365 - /* uhh? */ 366 - dev_err(&pdev->dev, "unable to remove gpio_chip?\n"); 367 - return err; 368 - } 362 + gpiochip_remove(&cs5535_gpio_chip.chip); 369 363 370 364 r = platform_get_resource(pdev, IORESOURCE_IO, 0); 371 365 release_region(r->start, resource_size(r));
+2 -1
drivers/gpio/gpio-da9052.c
··· 237 237 { 238 238 struct da9052_gpio *gpio = platform_get_drvdata(pdev); 239 239 240 - return gpiochip_remove(&gpio->gp); 240 + gpiochip_remove(&gpio->gp); 241 + return 0; 241 242 } 242 243 243 244 static struct platform_driver da9052_gpio_driver = {
+2 -1
drivers/gpio/gpio-da9055.c
··· 174 174 { 175 175 struct da9055_gpio *gpio = platform_get_drvdata(pdev); 176 176 177 - return gpiochip_remove(&gpio->gp); 177 + gpiochip_remove(&gpio->gp); 178 + return 0; 178 179 } 179 180 180 181 static struct platform_driver da9055_gpio_driver = {
+1 -1
drivers/gpio/gpio-dwapb.c
··· 359 359 360 360 for (m = 0; m < gpio->nr_ports; ++m) 361 361 if (gpio->ports[m].is_registered) 362 - WARN_ON(gpiochip_remove(&gpio->ports[m].bgc.gc)); 362 + gpiochip_remove(&gpio->ports[m].bgc.gc); 363 363 } 364 364 365 365 static int dwapb_gpio_probe(struct platform_device *pdev)
+1 -4
drivers/gpio/gpio-em.c
··· 409 409 static int em_gio_remove(struct platform_device *pdev) 410 410 { 411 411 struct em_gio_priv *p = platform_get_drvdata(pdev); 412 - int ret; 413 412 414 - ret = gpiochip_remove(&p->gpio_chip); 415 - if (ret) 416 - return ret; 413 + gpiochip_remove(&p->gpio_chip); 417 414 418 415 irq_domain_remove(p->irq_domain); 419 416 return 0;
+2 -16
drivers/gpio/gpio-f7188x.c
··· 317 317 err_gpiochip: 318 318 for (i = i - 1; i >= 0; i--) { 319 319 struct f7188x_gpio_bank *bank = &data->bank[i]; 320 - int tmp; 321 - 322 - tmp = gpiochip_remove(&bank->chip); 323 - if (tmp < 0) 324 - dev_err(&pdev->dev, 325 - "Failed to remove gpiochip %d: %d\n", 326 - i, tmp); 320 + gpiochip_remove(&bank->chip); 327 321 } 328 322 329 323 return err; ··· 325 331 326 332 static int f7188x_gpio_remove(struct platform_device *pdev) 327 333 { 328 - int err; 329 334 int i; 330 335 struct f7188x_gpio_data *data = platform_get_drvdata(pdev); 331 336 332 337 for (i = 0; i < data->nr_bank; i++) { 333 338 struct f7188x_gpio_bank *bank = &data->bank[i]; 334 - 335 - err = gpiochip_remove(&bank->chip); 336 - if (err) { 337 - dev_err(&pdev->dev, 338 - "Failed to remove GPIO gpiochip %d: %d\n", 339 - i, err); 340 - return err; 341 - } 339 + gpiochip_remove(&bank->chip); 342 340 } 343 341 344 342 return 0;
+2 -1
drivers/gpio/gpio-generic.c
··· 398 398 399 399 int bgpio_remove(struct bgpio_chip *bgc) 400 400 { 401 - return gpiochip_remove(&bgc->gc); 401 + gpiochip_remove(&bgc->gc); 402 + return 0; 402 403 } 403 404 EXPORT_SYMBOL_GPL(bgpio_remove); 404 405
+1 -3
drivers/gpio/gpio-grgpio.c
··· 468 468 } 469 469 } 470 470 471 - ret = gpiochip_remove(&priv->bgc.gc); 472 - if (ret) 473 - goto out; 471 + gpiochip_remove(&priv->bgc.gc); 474 472 475 473 if (priv->domain) 476 474 irq_domain_remove(priv->domain);
+1 -8
drivers/gpio/gpio-ich.c
··· 514 514 515 515 static int ichx_gpio_remove(struct platform_device *pdev) 516 516 { 517 - int err; 518 - 519 - err = gpiochip_remove(&ichx_priv.chip); 520 - if (err) { 521 - dev_err(&pdev->dev, "%s failed, %d\n", 522 - "gpiochip_remove()", err); 523 - return err; 524 - } 517 + gpiochip_remove(&ichx_priv.chip); 525 518 526 519 ichx_gpio_release_regions(ichx_priv.gpio_base, ichx_priv.use_gpio); 527 520 if (ichx_priv.pm_base)
+25 -61
drivers/gpio/gpio-intel-mid.c
··· 28 28 #include <linux/stddef.h> 29 29 #include <linux/interrupt.h> 30 30 #include <linux/init.h> 31 - #include <linux/irq.h> 32 31 #include <linux/io.h> 33 - #include <linux/gpio.h> 32 + #include <linux/gpio/driver.h> 34 33 #include <linux/slab.h> 35 34 #include <linux/pm_runtime.h> 36 - #include <linux/irqdomain.h> 37 35 38 36 #define INTEL_MID_IRQ_TYPE_EDGE (1 << 0) 39 37 #define INTEL_MID_IRQ_TYPE_LEVEL (1 << 1) ··· 76 78 void __iomem *reg_base; 77 79 spinlock_t lock; 78 80 struct pci_dev *pdev; 79 - struct irq_domain *domain; 80 81 }; 81 82 82 - #define to_intel_gpio_priv(chip) container_of(chip, struct intel_mid_gpio, chip) 83 + static inline struct intel_mid_gpio *to_intel_gpio_priv(struct gpio_chip *gc) 84 + { 85 + return container_of(gc, struct intel_mid_gpio, chip); 86 + } 83 87 84 88 static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset, 85 89 enum GPIO_REG reg_type) ··· 182 182 return 0; 183 183 } 184 184 185 - static int intel_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 186 - { 187 - struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); 188 - return irq_create_mapping(priv->domain, offset); 189 - } 190 - 191 185 static int intel_mid_irq_type(struct irq_data *d, unsigned type) 192 186 { 193 - struct intel_mid_gpio *priv = irq_data_get_irq_chip_data(d); 187 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 188 + struct intel_mid_gpio *priv = to_intel_gpio_priv(gc); 194 189 u32 gpio = irqd_to_hwirq(d); 195 190 unsigned long flags; 196 191 u32 value; ··· 226 231 { 227 232 } 228 233 229 - static int intel_mid_irq_reqres(struct irq_data *d) 230 - { 231 - struct intel_mid_gpio *priv = irq_data_get_irq_chip_data(d); 232 - 233 - if (gpio_lock_as_irq(&priv->chip, irqd_to_hwirq(d))) { 234 - dev_err(priv->chip.dev, 235 - "unable to lock HW IRQ %lu for IRQ\n", 236 - irqd_to_hwirq(d)); 237 - return -EINVAL; 238 - } 239 - return 0; 240 - } 241 - 242 - static void intel_mid_irq_relres(struct irq_data *d) 243 - { 244 - struct intel_mid_gpio *priv = irq_data_get_irq_chip_data(d); 245 - 246 - gpio_unlock_as_irq(&priv->chip, irqd_to_hwirq(d)); 247 - } 248 - 249 234 static struct irq_chip intel_mid_irqchip = { 250 235 .name = "INTEL_MID-GPIO", 251 236 .irq_mask = intel_mid_irq_mask, 252 237 .irq_unmask = intel_mid_irq_unmask, 253 238 .irq_set_type = intel_mid_irq_type, 254 - .irq_request_resources = intel_mid_irq_reqres, 255 - .irq_release_resources = intel_mid_irq_relres, 256 239 }; 257 240 258 241 static const struct intel_mid_gpio_ddata gpio_lincroft = { ··· 303 330 304 331 static void intel_mid_irq_handler(unsigned irq, struct irq_desc *desc) 305 332 { 333 + struct gpio_chip *gc = irq_desc_get_handler_data(desc); 334 + struct intel_mid_gpio *priv = to_intel_gpio_priv(gc); 306 335 struct irq_data *data = irq_desc_get_irq_data(desc); 307 - struct intel_mid_gpio *priv = irq_data_get_irq_handler_data(data); 308 336 struct irq_chip *chip = irq_data_get_irq_chip(data); 309 337 u32 base, gpio, mask; 310 338 unsigned long pending; ··· 319 345 mask = BIT(gpio); 320 346 /* Clear before handling so we can't lose an edge */ 321 347 writel(mask, gedr); 322 - generic_handle_irq(irq_find_mapping(priv->domain, 348 + generic_handle_irq(irq_find_mapping(gc->irqdomain, 323 349 base + gpio)); 324 350 } 325 351 } ··· 344 370 writel(~0, reg); 345 371 } 346 372 } 347 - 348 - static int intel_gpio_irq_map(struct irq_domain *d, unsigned int irq, 349 - irq_hw_number_t hwirq) 350 - { 351 - struct intel_mid_gpio *priv = d->host_data; 352 - 353 - irq_set_chip_and_handler(irq, &intel_mid_irqchip, handle_simple_irq); 354 - irq_set_chip_data(irq, priv); 355 - irq_set_irq_type(irq, IRQ_TYPE_NONE); 356 - 357 - return 0; 358 - } 359 - 360 - static const struct irq_domain_ops intel_gpio_irq_ops = { 361 - .map = intel_gpio_irq_map, 362 - .xlate = irq_domain_xlate_twocell, 363 - }; 364 373 365 374 static int intel_gpio_runtime_idle(struct device *dev) 366 375 { ··· 398 441 priv->chip.direction_output = intel_gpio_direction_output; 399 442 priv->chip.get = intel_gpio_get; 400 443 priv->chip.set = intel_gpio_set; 401 - priv->chip.to_irq = intel_gpio_to_irq; 402 444 priv->chip.base = gpio_base; 403 445 priv->chip.ngpio = ddata->ngpio; 404 446 priv->chip.can_sleep = false; 405 447 priv->pdev = pdev; 406 448 407 449 spin_lock_init(&priv->lock); 408 - 409 - priv->domain = irq_domain_add_simple(pdev->dev.of_node, ddata->ngpio, 410 - irq_base, &intel_gpio_irq_ops, priv); 411 - if (!priv->domain) 412 - return -ENOMEM; 413 450 414 451 pci_set_drvdata(pdev, priv); 415 452 retval = gpiochip_add(&priv->chip); ··· 412 461 return retval; 413 462 } 414 463 464 + retval = gpiochip_irqchip_add(&priv->chip, 465 + &intel_mid_irqchip, 466 + irq_base, 467 + handle_simple_irq, 468 + IRQ_TYPE_NONE); 469 + if (retval) { 470 + dev_err(&pdev->dev, 471 + "could not connect irqchip to gpiochip\n"); 472 + return retval; 473 + } 474 + 415 475 intel_mid_irq_init_hw(priv); 416 476 417 - irq_set_handler_data(pdev->irq, priv); 418 - irq_set_chained_handler(pdev->irq, intel_mid_irq_handler); 477 + gpiochip_set_chained_irqchip(&priv->chip, 478 + &intel_mid_irqchip, 479 + pdev->irq, 480 + intel_mid_irq_handler); 419 481 420 482 pm_runtime_put_noidle(&pdev->dev); 421 483 pm_runtime_allow(&pdev->dev);
+1 -5
drivers/gpio/gpio-it8761e.c
··· 217 217 static void __exit it8761e_gpio_exit(void) 218 218 { 219 219 if (gpio_ba) { 220 - int ret = gpiochip_remove(&it8761e_gpio_chip); 221 - 222 - WARN(ret, "%s(): gpiochip_remove() failed, ret=%d\n", 223 - __func__, ret); 224 - 220 + gpiochip_remove(&it8761e_gpio_chip); 225 221 release_region(gpio_ba, GPIO_IOSIZE); 226 222 gpio_ba = 0; 227 223 }
+1 -7
drivers/gpio/gpio-janz-ttl.c
··· 194 194 static int ttl_remove(struct platform_device *pdev) 195 195 { 196 196 struct ttl_module *mod = platform_get_drvdata(pdev); 197 - struct device *dev = &pdev->dev; 198 - int ret; 199 197 200 - ret = gpiochip_remove(&mod->gpio); 201 - if (ret) { 202 - dev_err(dev, "unable to remove GPIO chip\n"); 203 - return ret; 204 - } 198 + gpiochip_remove(&mod->gpio); 205 199 206 200 return 0; 207 201 }
+2 -1
drivers/gpio/gpio-kempld.c
··· 199 199 { 200 200 struct kempld_gpio_data *gpio = platform_get_drvdata(pdev); 201 201 202 - return gpiochip_remove(&gpio->chip); 202 + gpiochip_remove(&gpio->chip); 203 + return 0; 203 204 } 204 205 205 206 static struct platform_driver kempld_gpio_driver = {
+2 -1
drivers/gpio/gpio-lp3943.c
··· 216 216 { 217 217 struct lp3943_gpio *lp3943_gpio = platform_get_drvdata(pdev); 218 218 219 - return gpiochip_remove(&lp3943_gpio->chip); 219 + gpiochip_remove(&lp3943_gpio->chip); 220 + return 0; 220 221 } 221 222 222 223 static const struct of_device_id lp3943_gpio_of_match[] = {
+1 -1
drivers/gpio/gpio-lpc32xx.c
··· 560 560 } 561 561 562 562 #ifdef CONFIG_OF 563 - static struct of_device_id lpc32xx_gpio_of_match[] = { 563 + static const struct of_device_id lpc32xx_gpio_of_match[] = { 564 564 { .compatible = "nxp,lpc3220-gpio", }, 565 565 { }, 566 566 };
+27 -73
drivers/gpio/gpio-lynxpoint.c
··· 25 25 #include <linux/types.h> 26 26 #include <linux/bitops.h> 27 27 #include <linux/interrupt.h> 28 - #include <linux/irq.h> 29 28 #include <linux/gpio.h> 30 - #include <linux/irqdomain.h> 31 29 #include <linux/slab.h> 32 30 #include <linux/acpi.h> 33 31 #include <linux/platform_device.h> ··· 60 62 61 63 struct lp_gpio { 62 64 struct gpio_chip chip; 63 - struct irq_domain *domain; 64 65 struct platform_device *pdev; 65 66 spinlock_t lock; 66 67 unsigned long reg_base; ··· 148 151 149 152 static int lp_irq_type(struct irq_data *d, unsigned type) 150 153 { 151 - struct lp_gpio *lg = irq_data_get_irq_chip_data(d); 154 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 155 + struct lp_gpio *lg = container_of(gc, struct lp_gpio, chip); 152 156 u32 hwirq = irqd_to_hwirq(d); 153 157 unsigned long flags; 154 158 u32 value; ··· 234 236 return 0; 235 237 } 236 238 237 - static int lp_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 238 - { 239 - struct lp_gpio *lg = container_of(chip, struct lp_gpio, chip); 240 - return irq_create_mapping(lg->domain, offset); 241 - } 242 - 243 239 static void lp_gpio_irq_handler(unsigned hwirq, struct irq_desc *desc) 244 240 { 245 241 struct irq_data *data = irq_desc_get_irq_data(desc); 246 - struct lp_gpio *lg = irq_data_get_irq_handler_data(data); 242 + struct gpio_chip *gc = irq_desc_get_handler_data(desc); 243 + struct lp_gpio *lg = container_of(gc, struct lp_gpio, chip); 247 244 struct irq_chip *chip = irq_data_get_irq_chip(data); 248 245 u32 base, pin, mask; 249 246 unsigned long reg, ena, pending; ··· 255 262 mask = BIT(pin); 256 263 /* Clear before handling so we don't lose an edge */ 257 264 outl(mask, reg); 258 - irq = irq_find_mapping(lg->domain, base + pin); 265 + irq = irq_find_mapping(lg->chip.irqdomain, base + pin); 259 266 generic_handle_irq(irq); 260 267 } 261 268 } ··· 272 279 273 280 static void lp_irq_enable(struct irq_data *d) 274 281 { 275 - struct lp_gpio *lg = irq_data_get_irq_chip_data(d); 282 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 283 + struct lp_gpio *lg = container_of(gc, struct lp_gpio, chip); 276 284 u32 hwirq = irqd_to_hwirq(d); 277 285 unsigned long reg = lp_gpio_reg(&lg->chip, hwirq, LP_INT_ENABLE); 278 286 unsigned long flags; ··· 285 291 286 292 static void lp_irq_disable(struct irq_data *d) 287 293 { 288 - struct lp_gpio *lg = irq_data_get_irq_chip_data(d); 294 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 295 + struct lp_gpio *lg = container_of(gc, struct lp_gpio, chip); 289 296 u32 hwirq = irqd_to_hwirq(d); 290 297 unsigned long reg = lp_gpio_reg(&lg->chip, hwirq, LP_INT_ENABLE); 291 298 unsigned long flags; ··· 296 301 spin_unlock_irqrestore(&lg->lock, flags); 297 302 } 298 303 299 - static int lp_irq_reqres(struct irq_data *d) 300 - { 301 - struct lp_gpio *lg = irq_data_get_irq_chip_data(d); 302 - 303 - if (gpio_lock_as_irq(&lg->chip, irqd_to_hwirq(d))) { 304 - dev_err(lg->chip.dev, 305 - "unable to lock HW IRQ %lu for IRQ\n", 306 - irqd_to_hwirq(d)); 307 - return -EINVAL; 308 - } 309 - return 0; 310 - } 311 - 312 - static void lp_irq_relres(struct irq_data *d) 313 - { 314 - struct lp_gpio *lg = irq_data_get_irq_chip_data(d); 315 - 316 - gpio_unlock_as_irq(&lg->chip, irqd_to_hwirq(d)); 317 - } 318 - 319 304 static struct irq_chip lp_irqchip = { 320 305 .name = "LP-GPIO", 321 306 .irq_mask = lp_irq_mask, ··· 303 328 .irq_enable = lp_irq_enable, 304 329 .irq_disable = lp_irq_disable, 305 330 .irq_set_type = lp_irq_type, 306 - .irq_request_resources = lp_irq_reqres, 307 - .irq_release_resources = lp_irq_relres, 308 331 .flags = IRQCHIP_SKIP_SET_WAKE, 309 332 }; 310 333 ··· 321 348 } 322 349 } 323 350 324 - static int lp_gpio_irq_map(struct irq_domain *d, unsigned int irq, 325 - irq_hw_number_t hwirq) 326 - { 327 - struct lp_gpio *lg = d->host_data; 328 - 329 - irq_set_chip_and_handler(irq, &lp_irqchip, handle_simple_irq); 330 - irq_set_chip_data(irq, lg); 331 - irq_set_irq_type(irq, IRQ_TYPE_NONE); 332 - 333 - return 0; 334 - } 335 - 336 - static const struct irq_domain_ops lp_gpio_irq_ops = { 337 - .map = lp_gpio_irq_map, 338 - }; 339 - 340 351 static int lp_gpio_probe(struct platform_device *pdev) 341 352 { 342 353 struct lp_gpio *lg; ··· 328 371 struct resource *io_rc, *irq_rc; 329 372 struct device *dev = &pdev->dev; 330 373 unsigned long reg_len; 331 - unsigned hwirq; 332 374 int ret = -ENODEV; 333 375 334 376 lg = devm_kzalloc(dev, sizeof(struct lp_gpio), GFP_KERNEL); ··· 370 414 gc->can_sleep = false; 371 415 gc->dev = dev; 372 416 373 - /* set up interrupts */ 374 - if (irq_rc && irq_rc->start) { 375 - hwirq = irq_rc->start; 376 - gc->to_irq = lp_gpio_to_irq; 377 - 378 - lg->domain = irq_domain_add_linear(NULL, LP_NUM_GPIO, 379 - &lp_gpio_irq_ops, lg); 380 - if (!lg->domain) 381 - return -ENXIO; 382 - 383 - lp_gpio_irq_init_hw(lg); 384 - 385 - irq_set_handler_data(hwirq, lg); 386 - irq_set_chained_handler(hwirq, lp_gpio_irq_handler); 387 - } 388 - 389 417 ret = gpiochip_add(gc); 390 418 if (ret) { 391 419 dev_err(dev, "failed adding lp-gpio chip\n"); 392 420 return ret; 393 421 } 422 + 423 + /* set up interrupts */ 424 + if (irq_rc && irq_rc->start) { 425 + lp_gpio_irq_init_hw(lg); 426 + ret = gpiochip_irqchip_add(gc, &lp_irqchip, 0, 427 + handle_simple_irq, IRQ_TYPE_NONE); 428 + if (ret) { 429 + dev_err(dev, "failed to add irqchip\n"); 430 + gpiochip_remove(gc); 431 + return ret; 432 + } 433 + 434 + gpiochip_set_chained_irqchip(gc, &lp_irqchip, 435 + (unsigned)irq_rc->start, 436 + lp_gpio_irq_handler); 437 + } 438 + 394 439 pm_runtime_enable(dev); 395 440 396 441 return 0; ··· 422 465 static int lp_gpio_remove(struct platform_device *pdev) 423 466 { 424 467 struct lp_gpio *lg = platform_get_drvdata(pdev); 425 - int err; 426 468 pm_runtime_disable(&pdev->dev); 427 - err = gpiochip_remove(&lg->chip); 428 - if (err) 429 - dev_warn(&pdev->dev, "failed to remove gpio_chip.\n"); 469 + gpiochip_remove(&lg->chip); 430 470 return 0; 431 471 } 432 472
+4 -9
drivers/gpio/gpio-max730x.c
··· 228 228 int __max730x_remove(struct device *dev) 229 229 { 230 230 struct max7301 *ts = dev_get_drvdata(dev); 231 - int ret; 232 231 233 232 if (ts == NULL) 234 233 return -ENODEV; 235 234 236 235 /* Power down the chip and disable IRQ output */ 237 236 ts->write(dev, 0x04, 0x00); 238 - 239 - ret = gpiochip_remove(&ts->chip); 240 - if (!ret) 241 - mutex_destroy(&ts->lock); 242 - else 243 - dev_err(dev, "Failed to remove GPIO controller: %d\n", ret); 244 - 245 - return ret; 237 + gpiochip_remove(&ts->chip); 238 + mutex_destroy(&ts->lock); 239 + kfree(ts); 240 + return 0; 246 241 } 247 242 EXPORT_SYMBOL_GPL(__max730x_remove); 248 243
+1 -6
drivers/gpio/gpio-max732x.c
··· 676 676 } 677 677 } 678 678 679 - ret = gpiochip_remove(&chip->gpio_chip); 680 - if (ret) { 681 - dev_err(&client->dev, "%s failed, %d\n", 682 - "gpiochip_remove()", ret); 683 - return ret; 684 - } 679 + gpiochip_remove(&chip->gpio_chip); 685 680 686 681 max732x_irq_teardown(chip); 687 682
+3 -8
drivers/gpio/gpio-mc33880.c
··· 149 149 static int mc33880_remove(struct spi_device *spi) 150 150 { 151 151 struct mc33880 *mc; 152 - int ret; 153 152 154 153 mc = spi_get_drvdata(spi); 155 154 if (mc == NULL) 156 155 return -ENODEV; 157 156 158 - ret = gpiochip_remove(&mc->chip); 159 - if (!ret) 160 - mutex_destroy(&mc->lock); 161 - else 162 - dev_err(&spi->dev, "Failed to remove the GPIO controller: %d\n", 163 - ret); 157 + gpiochip_remove(&mc->chip); 158 + mutex_destroy(&mc->lock); 164 159 165 - return ret; 160 + return 0; 166 161 } 167 162 168 163 static struct spi_driver mc33880_driver = {
+2 -1
drivers/gpio/gpio-mc9s08dz60.c
··· 118 118 119 119 mc9s = i2c_get_clientdata(client); 120 120 121 - return gpiochip_remove(&mc9s->chip); 121 + gpiochip_remove(&mc9s->chip); 122 + return 0; 122 123 } 123 124 124 125 static const struct i2c_device_id mc9s08dz60_id[] = {
+7 -19
drivers/gpio/gpio-mcp23s08.c
··· 812 812 static int mcp230xx_remove(struct i2c_client *client) 813 813 { 814 814 struct mcp23s08 *mcp = i2c_get_clientdata(client); 815 - int status; 816 815 817 816 if (client->irq && mcp->irq_controller) 818 817 mcp23s08_irq_teardown(mcp); 819 818 820 - status = gpiochip_remove(&mcp->chip); 821 - if (status == 0) 822 - kfree(mcp); 819 + gpiochip_remove(&mcp->chip); 820 + kfree(mcp); 823 821 824 - return status; 822 + return 0; 825 823 } 826 824 827 825 static const struct i2c_device_id mcp230xx_id[] = { ··· 958 960 959 961 fail: 960 962 for (addr = 0; addr < ARRAY_SIZE(data->mcp); addr++) { 961 - int tmp; 962 963 963 964 if (!data->mcp[addr]) 964 965 continue; 965 - tmp = gpiochip_remove(&data->mcp[addr]->chip); 966 - if (tmp < 0) 967 - dev_err(&spi->dev, "%s --> %d\n", "remove", tmp); 966 + gpiochip_remove(&data->mcp[addr]->chip); 968 967 } 969 968 kfree(data); 970 969 return status; ··· 971 976 { 972 977 struct mcp23s08_driver_data *data = spi_get_drvdata(spi); 973 978 unsigned addr; 974 - int status = 0; 975 979 976 980 for (addr = 0; addr < ARRAY_SIZE(data->mcp); addr++) { 977 - int tmp; 978 981 979 982 if (!data->mcp[addr]) 980 983 continue; 981 984 982 - tmp = gpiochip_remove(&data->mcp[addr]->chip); 983 - if (tmp < 0) { 984 - dev_err(&spi->dev, "%s --> %d\n", "remove", tmp); 985 - status = tmp; 986 - } 985 + gpiochip_remove(&data->mcp[addr]->chip); 987 986 } 988 - if (status == 0) 989 - kfree(data); 990 - return status; 987 + kfree(data); 988 + return 0; 991 989 } 992 990 993 991 static const struct spi_device_id mcp23s08_ids[] = {
+2 -6
drivers/gpio/gpio-ml-ioh.c
··· 497 497 err_gpiochip_add: 498 498 while (--i >= 0) { 499 499 chip--; 500 - if (gpiochip_remove(&chip->gpio)) 501 - dev_err(&pdev->dev, "Failed gpiochip_remove(%d)\n", i); 500 + gpiochip_remove(&chip->gpio); 502 501 } 503 502 kfree(chip_save); 504 503 ··· 518 519 519 520 static void ioh_gpio_remove(struct pci_dev *pdev) 520 521 { 521 - int err; 522 522 int i; 523 523 struct ioh_gpio *chip = pci_get_drvdata(pdev); 524 524 void *chip_save; ··· 528 530 529 531 for (i = 0; i < 8; i++, chip++) { 530 532 irq_free_descs(chip->irq_base, num_ports[i]); 531 - err = gpiochip_remove(&chip->gpio); 532 - if (err) 533 - dev_err(&pdev->dev, "Failed gpiochip_remove\n"); 533 + gpiochip_remove(&chip->gpio); 534 534 } 535 535 536 536 chip = chip_save;
+1 -4
drivers/gpio/gpio-msm-v2.c
··· 438 438 439 439 static int msm_gpio_remove(struct platform_device *dev) 440 440 { 441 - int ret = gpiochip_remove(&msm_gpio.gpio_chip); 442 - 443 - if (ret < 0) 444 - return ret; 441 + gpiochip_remove(&msm_gpio.gpio_chip); 445 442 446 443 irq_set_handler(msm_gpio.summary_irq, NULL); 447 444
+1 -1
drivers/gpio/gpio-mxc.c
··· 485 485 out_irqdesc_free: 486 486 irq_free_descs(irq_base, 32); 487 487 out_gpiochip_remove: 488 - WARN_ON(gpiochip_remove(&port->bgc.gc) < 0); 488 + gpiochip_remove(&port->bgc.gc); 489 489 out_bgpio_remove: 490 490 bgpio_remove(&port->bgc); 491 491 out_bgio:
+2 -1
drivers/gpio/gpio-octeon.c
··· 129 129 static int octeon_gpio_remove(struct platform_device *pdev) 130 130 { 131 131 struct gpio_chip *chip = pdev->dev.platform_data; 132 - return gpiochip_remove(chip); 132 + gpiochip_remove(chip); 133 + return 0; 133 134 } 134 135 135 136 static struct of_device_id octeon_gpio_match[] = {
+137 -138
drivers/gpio/gpio-omap.c
··· 24 24 #include <linux/pm.h> 25 25 #include <linux/of.h> 26 26 #include <linux/of_device.h> 27 - #include <linux/irqchip/chained_irq.h> 28 27 #include <linux/gpio.h> 29 28 #include <linux/bitops.h> 30 29 #include <linux/platform_data/gpio-omap.h> ··· 88 89 #define BANK_USED(bank) (bank->mod_usage || bank->irq_usage) 89 90 #define LINE_USED(line, offset) (line & (BIT(offset))) 90 91 91 - static int irq_to_gpio(struct gpio_bank *bank, unsigned int gpio_irq) 92 + static int omap_irq_to_gpio(struct gpio_bank *bank, unsigned int gpio_irq) 92 93 { 93 94 return bank->chip.base + gpio_irq; 94 95 } 95 96 96 - static inline struct gpio_bank *_irq_data_get_bank(struct irq_data *d) 97 + static inline struct gpio_bank *omap_irq_data_get_bank(struct irq_data *d) 97 98 { 98 99 struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 99 100 return container_of(chip, struct gpio_bank, chip); 100 101 } 101 102 102 - static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) 103 + static void omap_set_gpio_direction(struct gpio_bank *bank, int gpio, 104 + int is_input) 103 105 { 104 106 void __iomem *reg = bank->base; 105 107 u32 l; ··· 117 117 118 118 119 119 /* set data out value using dedicate set/clear register */ 120 - static void _set_gpio_dataout_reg(struct gpio_bank *bank, int gpio, int enable) 120 + static void omap_set_gpio_dataout_reg(struct gpio_bank *bank, int gpio, 121 + int enable) 121 122 { 122 123 void __iomem *reg = bank->base; 123 124 u32 l = GPIO_BIT(bank, gpio); ··· 135 134 } 136 135 137 136 /* set data out value using mask register */ 138 - static void _set_gpio_dataout_mask(struct gpio_bank *bank, int gpio, int enable) 137 + static void omap_set_gpio_dataout_mask(struct gpio_bank *bank, int gpio, 138 + int enable) 139 139 { 140 140 void __iomem *reg = bank->base + bank->regs->dataout; 141 141 u32 gpio_bit = GPIO_BIT(bank, gpio); ··· 151 149 bank->context.dataout = l; 152 150 } 153 151 154 - static int _get_gpio_datain(struct gpio_bank *bank, int offset) 152 + static int omap_get_gpio_datain(struct gpio_bank *bank, int offset) 155 153 { 156 154 void __iomem *reg = bank->base + bank->regs->datain; 157 155 158 156 return (readl_relaxed(reg) & (BIT(offset))) != 0; 159 157 } 160 158 161 - static int _get_gpio_dataout(struct gpio_bank *bank, int offset) 159 + static int omap_get_gpio_dataout(struct gpio_bank *bank, int offset) 162 160 { 163 161 void __iomem *reg = bank->base + bank->regs->dataout; 164 162 165 163 return (readl_relaxed(reg) & (BIT(offset))) != 0; 166 164 } 167 165 168 - static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set) 166 + static inline void omap_gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set) 169 167 { 170 168 int l = readl_relaxed(base + reg); 171 169 ··· 177 175 writel_relaxed(l, base + reg); 178 176 } 179 177 180 - static inline void _gpio_dbck_enable(struct gpio_bank *bank) 178 + static inline void omap_gpio_dbck_enable(struct gpio_bank *bank) 181 179 { 182 180 if (bank->dbck_enable_mask && !bank->dbck_enabled) { 183 181 clk_prepare_enable(bank->dbck); ··· 188 186 } 189 187 } 190 188 191 - static inline void _gpio_dbck_disable(struct gpio_bank *bank) 189 + static inline void omap_gpio_dbck_disable(struct gpio_bank *bank) 192 190 { 193 191 if (bank->dbck_enable_mask && bank->dbck_enabled) { 194 192 /* ··· 204 202 } 205 203 206 204 /** 207 - * _set_gpio_debounce - low level gpio debounce time 205 + * omap2_set_gpio_debounce - low level gpio debounce time 208 206 * @bank: the gpio bank we're acting upon 209 207 * @gpio: the gpio number on this @gpio 210 208 * @debounce: debounce time to use ··· 212 210 * OMAP's debounce time is in 31us steps so we need 213 211 * to convert and round up to the closest unit. 214 212 */ 215 - static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio, 216 - unsigned debounce) 213 + static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned gpio, 214 + unsigned debounce) 217 215 { 218 216 void __iomem *reg; 219 217 u32 val; ··· 254 252 * used within _gpio_dbck_enable() is still not initialized at 255 253 * that point. Therefore we have to enable dbck here. 256 254 */ 257 - _gpio_dbck_enable(bank); 255 + omap_gpio_dbck_enable(bank); 258 256 if (bank->dbck_enable_mask) { 259 257 bank->context.debounce = debounce; 260 258 bank->context.debounce_en = val; ··· 262 260 } 263 261 264 262 /** 265 - * _clear_gpio_debounce - clear debounce settings for a gpio 263 + * omap_clear_gpio_debounce - clear debounce settings for a gpio 266 264 * @bank: the gpio bank we're acting upon 267 265 * @gpio: the gpio number on this @gpio 268 266 * ··· 271 269 * time too. The debounce clock will also be disabled when calling this function 272 270 * if this is the only gpio in the bank using debounce. 273 271 */ 274 - static void _clear_gpio_debounce(struct gpio_bank *bank, unsigned gpio) 272 + static void omap_clear_gpio_debounce(struct gpio_bank *bank, unsigned gpio) 275 273 { 276 274 u32 gpio_bit = GPIO_BIT(bank, gpio); 277 275 ··· 295 293 } 296 294 } 297 295 298 - static inline void set_gpio_trigger(struct gpio_bank *bank, int gpio, 296 + static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio, 299 297 unsigned trigger) 300 298 { 301 299 void __iomem *base = bank->base; 302 300 u32 gpio_bit = BIT(gpio); 303 301 304 - _gpio_rmw(base, bank->regs->leveldetect0, gpio_bit, 305 - trigger & IRQ_TYPE_LEVEL_LOW); 306 - _gpio_rmw(base, bank->regs->leveldetect1, gpio_bit, 307 - trigger & IRQ_TYPE_LEVEL_HIGH); 308 - _gpio_rmw(base, bank->regs->risingdetect, gpio_bit, 309 - trigger & IRQ_TYPE_EDGE_RISING); 310 - _gpio_rmw(base, bank->regs->fallingdetect, gpio_bit, 311 - trigger & IRQ_TYPE_EDGE_FALLING); 302 + omap_gpio_rmw(base, bank->regs->leveldetect0, gpio_bit, 303 + trigger & IRQ_TYPE_LEVEL_LOW); 304 + omap_gpio_rmw(base, bank->regs->leveldetect1, gpio_bit, 305 + trigger & IRQ_TYPE_LEVEL_HIGH); 306 + omap_gpio_rmw(base, bank->regs->risingdetect, gpio_bit, 307 + trigger & IRQ_TYPE_EDGE_RISING); 308 + omap_gpio_rmw(base, bank->regs->fallingdetect, gpio_bit, 309 + trigger & IRQ_TYPE_EDGE_FALLING); 312 310 313 311 bank->context.leveldetect0 = 314 312 readl_relaxed(bank->base + bank->regs->leveldetect0); ··· 320 318 readl_relaxed(bank->base + bank->regs->fallingdetect); 321 319 322 320 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) { 323 - _gpio_rmw(base, bank->regs->wkup_en, gpio_bit, trigger != 0); 321 + omap_gpio_rmw(base, bank->regs->wkup_en, gpio_bit, trigger != 0); 324 322 bank->context.wake_en = 325 323 readl_relaxed(bank->base + bank->regs->wkup_en); 326 324 } ··· 356 354 * This only applies to chips that can't do both rising and falling edge 357 355 * detection at once. For all other chips, this function is a noop. 358 356 */ 359 - static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) 357 + static void omap_toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) 360 358 { 361 359 void __iomem *reg = bank->base; 362 360 u32 l = 0; ··· 375 373 writel_relaxed(l, reg); 376 374 } 377 375 #else 378 - static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) {} 376 + static void omap_toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) {} 379 377 #endif 380 378 381 - static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, 382 - unsigned trigger) 379 + static int omap_set_gpio_triggering(struct gpio_bank *bank, int gpio, 380 + unsigned trigger) 383 381 { 384 382 void __iomem *reg = bank->base; 385 383 void __iomem *base = bank->base; 386 384 u32 l = 0; 387 385 388 386 if (bank->regs->leveldetect0 && bank->regs->wkup_en) { 389 - set_gpio_trigger(bank, gpio, trigger); 387 + omap_set_gpio_trigger(bank, gpio, trigger); 390 388 } else if (bank->regs->irqctrl) { 391 389 reg += bank->regs->irqctrl; 392 390 ··· 416 414 l |= BIT(gpio << 1); 417 415 418 416 /* Enable wake-up during idle for dynamic tick */ 419 - _gpio_rmw(base, bank->regs->wkup_en, BIT(gpio), trigger); 417 + omap_gpio_rmw(base, bank->regs->wkup_en, BIT(gpio), trigger); 420 418 bank->context.wake_en = 421 419 readl_relaxed(bank->base + bank->regs->wkup_en); 422 420 writel_relaxed(l, reg); ··· 424 422 return 0; 425 423 } 426 424 427 - static void _enable_gpio_module(struct gpio_bank *bank, unsigned offset) 425 + static void omap_enable_gpio_module(struct gpio_bank *bank, unsigned offset) 428 426 { 429 427 if (bank->regs->pinctrl) { 430 428 void __iomem *reg = bank->base + bank->regs->pinctrl; ··· 445 443 } 446 444 } 447 445 448 - static void _disable_gpio_module(struct gpio_bank *bank, unsigned offset) 446 + static void omap_disable_gpio_module(struct gpio_bank *bank, unsigned offset) 449 447 { 450 448 void __iomem *base = bank->base; 451 449 ··· 453 451 !LINE_USED(bank->mod_usage, offset) && 454 452 !LINE_USED(bank->irq_usage, offset)) { 455 453 /* Disable wake-up during idle for dynamic tick */ 456 - _gpio_rmw(base, bank->regs->wkup_en, BIT(offset), 0); 454 + omap_gpio_rmw(base, bank->regs->wkup_en, BIT(offset), 0); 457 455 bank->context.wake_en = 458 456 readl_relaxed(bank->base + bank->regs->wkup_en); 459 457 } ··· 470 468 } 471 469 } 472 470 473 - static int gpio_is_input(struct gpio_bank *bank, int mask) 471 + static int omap_gpio_is_input(struct gpio_bank *bank, int mask) 474 472 { 475 473 void __iomem *reg = bank->base + bank->regs->direction; 476 474 477 475 return readl_relaxed(reg) & mask; 478 476 } 479 477 480 - static int gpio_irq_type(struct irq_data *d, unsigned type) 478 + static int omap_gpio_irq_type(struct irq_data *d, unsigned type) 481 479 { 482 - struct gpio_bank *bank = _irq_data_get_bank(d); 480 + struct gpio_bank *bank = omap_irq_data_get_bank(d); 483 481 unsigned gpio = 0; 484 482 int retval; 485 483 unsigned long flags; ··· 494 492 #endif 495 493 496 494 if (!gpio) 497 - gpio = irq_to_gpio(bank, d->hwirq); 495 + gpio = omap_irq_to_gpio(bank, d->hwirq); 498 496 499 497 if (type & ~IRQ_TYPE_SENSE_MASK) 500 498 return -EINVAL; ··· 505 503 506 504 spin_lock_irqsave(&bank->lock, flags); 507 505 offset = GPIO_INDEX(bank, gpio); 508 - retval = _set_gpio_triggering(bank, offset, type); 506 + retval = omap_set_gpio_triggering(bank, offset, type); 509 507 if (!LINE_USED(bank->mod_usage, offset)) { 510 - _enable_gpio_module(bank, offset); 511 - _set_gpio_direction(bank, offset, 1); 512 - } else if (!gpio_is_input(bank, BIT(offset))) { 508 + omap_enable_gpio_module(bank, offset); 509 + omap_set_gpio_direction(bank, offset, 1); 510 + } else if (!omap_gpio_is_input(bank, BIT(offset))) { 513 511 spin_unlock_irqrestore(&bank->lock, flags); 514 512 return -EINVAL; 515 513 } ··· 525 523 return retval; 526 524 } 527 525 528 - static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) 526 + static void omap_clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) 529 527 { 530 528 void __iomem *reg = bank->base; 531 529 ··· 542 540 readl_relaxed(reg); 543 541 } 544 542 545 - static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio) 543 + static inline void omap_clear_gpio_irqstatus(struct gpio_bank *bank, int gpio) 546 544 { 547 - _clear_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); 545 + omap_clear_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); 548 546 } 549 547 550 - static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank) 548 + static u32 omap_get_gpio_irqbank_mask(struct gpio_bank *bank) 551 549 { 552 550 void __iomem *reg = bank->base; 553 551 u32 l; ··· 561 559 return l; 562 560 } 563 561 564 - static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) 562 + static void omap_enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) 565 563 { 566 564 void __iomem *reg = bank->base; 567 565 u32 l; ··· 583 581 writel_relaxed(l, reg); 584 582 } 585 583 586 - static void _disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) 584 + static void omap_disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) 587 585 { 588 586 void __iomem *reg = bank->base; 589 587 u32 l; ··· 605 603 writel_relaxed(l, reg); 606 604 } 607 605 608 - static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable) 606 + static inline void omap_set_gpio_irqenable(struct gpio_bank *bank, int gpio, 607 + int enable) 609 608 { 610 609 if (enable) 611 - _enable_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); 610 + omap_enable_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); 612 611 else 613 - _disable_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); 612 + omap_disable_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); 614 613 } 615 614 616 615 /* ··· 622 619 * enabled. When system is suspended, only selected GPIO interrupts need 623 620 * to have wake-up enabled. 624 621 */ 625 - static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable) 622 + static int omap_set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable) 626 623 { 627 624 u32 gpio_bit = GPIO_BIT(bank, gpio); 628 625 unsigned long flags; ··· 645 642 return 0; 646 643 } 647 644 648 - static void _reset_gpio(struct gpio_bank *bank, int gpio) 645 + static void omap_reset_gpio(struct gpio_bank *bank, int gpio) 649 646 { 650 - _set_gpio_direction(bank, GPIO_INDEX(bank, gpio), 1); 651 - _set_gpio_irqenable(bank, gpio, 0); 652 - _clear_gpio_irqstatus(bank, gpio); 653 - _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE); 654 - _clear_gpio_debounce(bank, gpio); 647 + omap_set_gpio_direction(bank, GPIO_INDEX(bank, gpio), 1); 648 + omap_set_gpio_irqenable(bank, gpio, 0); 649 + omap_clear_gpio_irqstatus(bank, gpio); 650 + omap_set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE); 651 + omap_clear_gpio_debounce(bank, gpio); 655 652 } 656 653 657 654 /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ 658 - static int gpio_wake_enable(struct irq_data *d, unsigned int enable) 655 + static int omap_gpio_wake_enable(struct irq_data *d, unsigned int enable) 659 656 { 660 - struct gpio_bank *bank = _irq_data_get_bank(d); 661 - unsigned int gpio = irq_to_gpio(bank, d->hwirq); 657 + struct gpio_bank *bank = omap_irq_data_get_bank(d); 658 + unsigned int gpio = omap_irq_to_gpio(bank, d->hwirq); 662 659 663 - return _set_gpio_wakeup(bank, gpio, enable); 660 + return omap_set_gpio_wakeup(bank, gpio, enable); 664 661 } 665 662 666 663 static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) ··· 681 678 * not already been requested. 682 679 */ 683 680 if (!LINE_USED(bank->irq_usage, offset)) { 684 - _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); 685 - _enable_gpio_module(bank, offset); 681 + omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); 682 + omap_enable_gpio_module(bank, offset); 686 683 } 687 684 bank->mod_usage |= BIT(offset); 688 685 spin_unlock_irqrestore(&bank->lock, flags); ··· 697 694 698 695 spin_lock_irqsave(&bank->lock, flags); 699 696 bank->mod_usage &= ~(BIT(offset)); 700 - _disable_gpio_module(bank, offset); 701 - _reset_gpio(bank, bank->chip.base + offset); 697 + omap_disable_gpio_module(bank, offset); 698 + omap_reset_gpio(bank, bank->chip.base + offset); 702 699 spin_unlock_irqrestore(&bank->lock, flags); 703 700 704 701 /* ··· 718 715 * line's interrupt handler has been run, we may miss some nested 719 716 * interrupts. 720 717 */ 721 - static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc) 718 + static void omap_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) 722 719 { 723 720 void __iomem *isr_reg = NULL; 724 721 u32 isr; ··· 741 738 u32 isr_saved, level_mask = 0; 742 739 u32 enabled; 743 740 744 - enabled = _get_gpio_irqbank_mask(bank); 741 + enabled = omap_get_gpio_irqbank_mask(bank); 745 742 isr_saved = isr = readl_relaxed(isr_reg) & enabled; 746 743 747 744 if (bank->level_mask) ··· 750 747 /* clear edge sensitive interrupts before handler(s) are 751 748 called so that we don't miss any interrupt occurred while 752 749 executing them */ 753 - _disable_gpio_irqbank(bank, isr_saved & ~level_mask); 754 - _clear_gpio_irqbank(bank, isr_saved & ~level_mask); 755 - _enable_gpio_irqbank(bank, isr_saved & ~level_mask); 750 + omap_disable_gpio_irqbank(bank, isr_saved & ~level_mask); 751 + omap_clear_gpio_irqbank(bank, isr_saved & ~level_mask); 752 + omap_enable_gpio_irqbank(bank, isr_saved & ~level_mask); 756 753 757 754 /* if there is only edge sensitive GPIO pin interrupts 758 755 configured, we could unmask GPIO bank interrupt immediately */ ··· 776 773 * This will be indicated in the bank toggle_mask. 777 774 */ 778 775 if (bank->toggle_mask & (BIT(bit))) 779 - _toggle_gpio_edge_triggering(bank, bit); 776 + omap_toggle_gpio_edge_triggering(bank, bit); 780 777 781 778 generic_handle_irq(irq_find_mapping(bank->chip.irqdomain, 782 779 bit)); ··· 792 789 pm_runtime_put(bank->dev); 793 790 } 794 791 795 - static void gpio_irq_shutdown(struct irq_data *d) 792 + static void omap_gpio_irq_shutdown(struct irq_data *d) 796 793 { 797 - struct gpio_bank *bank = _irq_data_get_bank(d); 798 - unsigned int gpio = irq_to_gpio(bank, d->hwirq); 794 + struct gpio_bank *bank = omap_irq_data_get_bank(d); 795 + unsigned int gpio = omap_irq_to_gpio(bank, d->hwirq); 799 796 unsigned long flags; 800 797 unsigned offset = GPIO_INDEX(bank, gpio); 801 798 802 799 spin_lock_irqsave(&bank->lock, flags); 803 800 gpio_unlock_as_irq(&bank->chip, offset); 804 801 bank->irq_usage &= ~(BIT(offset)); 805 - _disable_gpio_module(bank, offset); 806 - _reset_gpio(bank, gpio); 802 + omap_disable_gpio_module(bank, offset); 803 + omap_reset_gpio(bank, gpio); 807 804 spin_unlock_irqrestore(&bank->lock, flags); 808 805 809 806 /* ··· 814 811 pm_runtime_put(bank->dev); 815 812 } 816 813 817 - static void gpio_ack_irq(struct irq_data *d) 814 + static void omap_gpio_ack_irq(struct irq_data *d) 818 815 { 819 - struct gpio_bank *bank = _irq_data_get_bank(d); 820 - unsigned int gpio = irq_to_gpio(bank, d->hwirq); 816 + struct gpio_bank *bank = omap_irq_data_get_bank(d); 817 + unsigned int gpio = omap_irq_to_gpio(bank, d->hwirq); 821 818 822 - _clear_gpio_irqstatus(bank, gpio); 819 + omap_clear_gpio_irqstatus(bank, gpio); 823 820 } 824 821 825 - static void gpio_mask_irq(struct irq_data *d) 822 + static void omap_gpio_mask_irq(struct irq_data *d) 826 823 { 827 - struct gpio_bank *bank = _irq_data_get_bank(d); 828 - unsigned int gpio = irq_to_gpio(bank, d->hwirq); 824 + struct gpio_bank *bank = omap_irq_data_get_bank(d); 825 + unsigned int gpio = omap_irq_to_gpio(bank, d->hwirq); 829 826 unsigned long flags; 830 827 831 828 spin_lock_irqsave(&bank->lock, flags); 832 - _set_gpio_irqenable(bank, gpio, 0); 833 - _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE); 829 + omap_set_gpio_irqenable(bank, gpio, 0); 830 + omap_set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE); 834 831 spin_unlock_irqrestore(&bank->lock, flags); 835 832 } 836 833 837 - static void gpio_unmask_irq(struct irq_data *d) 834 + static void omap_gpio_unmask_irq(struct irq_data *d) 838 835 { 839 - struct gpio_bank *bank = _irq_data_get_bank(d); 840 - unsigned int gpio = irq_to_gpio(bank, d->hwirq); 836 + struct gpio_bank *bank = omap_irq_data_get_bank(d); 837 + unsigned int gpio = omap_irq_to_gpio(bank, d->hwirq); 841 838 unsigned int irq_mask = GPIO_BIT(bank, gpio); 842 839 u32 trigger = irqd_get_trigger_type(d); 843 840 unsigned long flags; 844 841 845 842 spin_lock_irqsave(&bank->lock, flags); 846 843 if (trigger) 847 - _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), trigger); 844 + omap_set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), trigger); 848 845 849 846 /* For level-triggered GPIOs, the clearing must be done after 850 847 * the HW source is cleared, thus after the handler has run */ 851 848 if (bank->level_mask & irq_mask) { 852 - _set_gpio_irqenable(bank, gpio, 0); 853 - _clear_gpio_irqstatus(bank, gpio); 849 + omap_set_gpio_irqenable(bank, gpio, 0); 850 + omap_clear_gpio_irqstatus(bank, gpio); 854 851 } 855 852 856 - _set_gpio_irqenable(bank, gpio, 1); 853 + omap_set_gpio_irqenable(bank, gpio, 1); 857 854 spin_unlock_irqrestore(&bank->lock, flags); 858 855 } 859 856 860 857 static struct irq_chip gpio_irq_chip = { 861 858 .name = "GPIO", 862 - .irq_shutdown = gpio_irq_shutdown, 863 - .irq_ack = gpio_ack_irq, 864 - .irq_mask = gpio_mask_irq, 865 - .irq_unmask = gpio_unmask_irq, 866 - .irq_set_type = gpio_irq_type, 867 - .irq_set_wake = gpio_wake_enable, 859 + .irq_shutdown = omap_gpio_irq_shutdown, 860 + .irq_ack = omap_gpio_ack_irq, 861 + .irq_mask = omap_gpio_mask_irq, 862 + .irq_unmask = omap_gpio_unmask_irq, 863 + .irq_set_type = omap_gpio_irq_type, 864 + .irq_set_wake = omap_gpio_wake_enable, 868 865 }; 869 866 870 867 /*---------------------------------------------------------------------*/ ··· 921 918 /* could list the /proc/iomem resources */ 922 919 }; 923 920 924 - static inline void mpuio_init(struct gpio_bank *bank) 921 + static inline void omap_mpuio_init(struct gpio_bank *bank) 925 922 { 926 923 platform_set_drvdata(&omap_mpuio_device, bank); 927 924 ··· 931 928 932 929 /*---------------------------------------------------------------------*/ 933 930 934 - static int gpio_get_direction(struct gpio_chip *chip, unsigned offset) 931 + static int omap_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 935 932 { 936 933 struct gpio_bank *bank; 937 934 unsigned long flags; ··· 946 943 return dir; 947 944 } 948 945 949 - static int gpio_input(struct gpio_chip *chip, unsigned offset) 946 + static int omap_gpio_input(struct gpio_chip *chip, unsigned offset) 950 947 { 951 948 struct gpio_bank *bank; 952 949 unsigned long flags; 953 950 954 951 bank = container_of(chip, struct gpio_bank, chip); 955 952 spin_lock_irqsave(&bank->lock, flags); 956 - _set_gpio_direction(bank, offset, 1); 953 + omap_set_gpio_direction(bank, offset, 1); 957 954 spin_unlock_irqrestore(&bank->lock, flags); 958 955 return 0; 959 956 } 960 957 961 - static int gpio_get(struct gpio_chip *chip, unsigned offset) 958 + static int omap_gpio_get(struct gpio_chip *chip, unsigned offset) 962 959 { 963 960 struct gpio_bank *bank; 964 961 u32 mask; ··· 966 963 bank = container_of(chip, struct gpio_bank, chip); 967 964 mask = (BIT(offset)); 968 965 969 - if (gpio_is_input(bank, mask)) 970 - return _get_gpio_datain(bank, offset); 966 + if (omap_gpio_is_input(bank, mask)) 967 + return omap_get_gpio_datain(bank, offset); 971 968 else 972 - return _get_gpio_dataout(bank, offset); 969 + return omap_get_gpio_dataout(bank, offset); 973 970 } 974 971 975 - static int gpio_output(struct gpio_chip *chip, unsigned offset, int value) 972 + static int omap_gpio_output(struct gpio_chip *chip, unsigned offset, int value) 976 973 { 977 974 struct gpio_bank *bank; 978 975 unsigned long flags; ··· 980 977 bank = container_of(chip, struct gpio_bank, chip); 981 978 spin_lock_irqsave(&bank->lock, flags); 982 979 bank->set_dataout(bank, offset, value); 983 - _set_gpio_direction(bank, offset, 0); 980 + omap_set_gpio_direction(bank, offset, 0); 984 981 spin_unlock_irqrestore(&bank->lock, flags); 985 982 return 0; 986 983 } 987 984 988 - static int gpio_debounce(struct gpio_chip *chip, unsigned offset, 989 - unsigned debounce) 985 + static int omap_gpio_debounce(struct gpio_chip *chip, unsigned offset, 986 + unsigned debounce) 990 987 { 991 988 struct gpio_bank *bank; 992 989 unsigned long flags; ··· 994 991 bank = container_of(chip, struct gpio_bank, chip); 995 992 996 993 spin_lock_irqsave(&bank->lock, flags); 997 - _set_gpio_debounce(bank, offset, debounce); 994 + omap2_set_gpio_debounce(bank, offset, debounce); 998 995 spin_unlock_irqrestore(&bank->lock, flags); 999 996 1000 997 return 0; 1001 998 } 1002 999 1003 - static void gpio_set(struct gpio_chip *chip, unsigned offset, int value) 1000 + static void omap_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 1004 1001 { 1005 1002 struct gpio_bank *bank; 1006 1003 unsigned long flags; ··· 1028 1025 called = true; 1029 1026 } 1030 1027 1031 - /* This lock class tells lockdep that GPIO irqs are in a different 1032 - * category than their parents, so it won't report false recursion. 1033 - */ 1034 - static struct lock_class_key gpio_lock_class; 1035 - 1036 1028 static void omap_gpio_mod_init(struct gpio_bank *bank) 1037 1029 { 1038 1030 void __iomem *base = bank->base; ··· 1041 1043 return; 1042 1044 } 1043 1045 1044 - _gpio_rmw(base, bank->regs->irqenable, l, bank->regs->irqenable_inv); 1045 - _gpio_rmw(base, bank->regs->irqstatus, l, !bank->regs->irqenable_inv); 1046 + omap_gpio_rmw(base, bank->regs->irqenable, l, 1047 + bank->regs->irqenable_inv); 1048 + omap_gpio_rmw(base, bank->regs->irqstatus, l, 1049 + !bank->regs->irqenable_inv); 1046 1050 if (bank->regs->debounce_en) 1047 1051 writel_relaxed(0, base + bank->regs->debounce_en); 1048 1052 ··· 1078 1078 /* NOTE: No ack required, reading IRQ status clears it. */ 1079 1079 ct->chip.irq_mask = irq_gc_mask_set_bit; 1080 1080 ct->chip.irq_unmask = irq_gc_mask_clr_bit; 1081 - ct->chip.irq_set_type = gpio_irq_type; 1081 + ct->chip.irq_set_type = omap_gpio_irq_type; 1082 1082 1083 1083 if (bank->regs->wkup_en) 1084 - ct->chip.irq_set_wake = gpio_wake_enable; 1084 + ct->chip.irq_set_wake = omap_gpio_wake_enable; 1085 1085 1086 1086 ct->regs.mask = OMAP_MPUIO_GPIO_INT / bank->stride; 1087 1087 irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE, ··· 1101 1101 */ 1102 1102 bank->chip.request = omap_gpio_request; 1103 1103 bank->chip.free = omap_gpio_free; 1104 - bank->chip.get_direction = gpio_get_direction; 1105 - bank->chip.direction_input = gpio_input; 1106 - bank->chip.get = gpio_get; 1107 - bank->chip.direction_output = gpio_output; 1108 - bank->chip.set_debounce = gpio_debounce; 1109 - bank->chip.set = gpio_set; 1104 + bank->chip.get_direction = omap_gpio_get_direction; 1105 + bank->chip.direction_input = omap_gpio_input; 1106 + bank->chip.get = omap_gpio_get; 1107 + bank->chip.direction_output = omap_gpio_output; 1108 + bank->chip.set_debounce = omap_gpio_debounce; 1109 + bank->chip.set = omap_gpio_set; 1110 1110 if (bank->is_mpuio) { 1111 1111 bank->chip.label = "mpuio"; 1112 1112 if (bank->regs->wkup_en) ··· 1138 1138 #endif 1139 1139 1140 1140 ret = gpiochip_irqchip_add(&bank->chip, &gpio_irq_chip, 1141 - irq_base, gpio_irq_handler, 1141 + irq_base, omap_gpio_irq_handler, 1142 1142 IRQ_TYPE_NONE); 1143 1143 1144 1144 if (ret) { ··· 1148 1148 } 1149 1149 1150 1150 gpiochip_set_chained_irqchip(&bank->chip, &gpio_irq_chip, 1151 - bank->irq, gpio_irq_handler); 1151 + bank->irq, omap_gpio_irq_handler); 1152 1152 1153 1153 for (j = 0; j < bank->width; j++) { 1154 1154 int irq = irq_find_mapping(bank->chip.irqdomain, j); 1155 - irq_set_lockdep_class(irq, &gpio_lock_class); 1156 1155 if (bank->is_mpuio) { 1157 1156 omap_mpuio_alloc_gc(bank, irq, bank->width); 1158 1157 irq_set_chip_and_handler(irq, NULL, NULL); ··· 1216 1217 } 1217 1218 1218 1219 if (bank->regs->set_dataout && bank->regs->clr_dataout) 1219 - bank->set_dataout = _set_gpio_dataout_reg; 1220 + bank->set_dataout = omap_set_gpio_dataout_reg; 1220 1221 else 1221 - bank->set_dataout = _set_gpio_dataout_mask; 1222 + bank->set_dataout = omap_set_gpio_dataout_mask; 1222 1223 1223 1224 spin_lock_init(&bank->lock); 1224 1225 ··· 1237 1238 pm_runtime_get_sync(bank->dev); 1238 1239 1239 1240 if (bank->is_mpuio) 1240 - mpuio_init(bank); 1241 + omap_mpuio_init(bank); 1241 1242 1242 1243 omap_gpio_mod_init(bank); 1243 1244 ··· 1319 1320 bank->context_loss_count = 1320 1321 bank->get_context_loss_count(bank->dev); 1321 1322 1322 - _gpio_dbck_disable(bank); 1323 + omap_gpio_dbck_disable(bank); 1323 1324 spin_unlock_irqrestore(&bank->lock, flags); 1324 1325 1325 1326 return 0; ··· 1350 1351 bank->get_context_loss_count(bank->dev); 1351 1352 } 1352 1353 1353 - _gpio_dbck_enable(bank); 1354 + omap_gpio_dbck_enable(bank); 1354 1355 1355 1356 /* 1356 1357 * In ->runtime_suspend(), level-triggered, wakeup-enabled
+2 -1
drivers/gpio/gpio-palmas.c
··· 210 210 { 211 211 struct palmas_gpio *palmas_gpio = platform_get_drvdata(pdev); 212 212 213 - return gpiochip_remove(&palmas_gpio->gpio_chip); 213 + gpiochip_remove(&palmas_gpio->gpio_chip); 214 + return 0; 214 215 } 215 216 216 217 static struct platform_driver palmas_gpio_driver = {
+1 -6
drivers/gpio/gpio-pca953x.c
··· 765 765 } 766 766 } 767 767 768 - ret = gpiochip_remove(&chip->gpio_chip); 769 - if (ret) { 770 - dev_err(&client->dev, "%s failed, %d\n", 771 - "gpiochip_remove()", ret); 772 - return ret; 773 - } 768 + gpiochip_remove(&chip->gpio_chip); 774 769 775 770 return 0; 776 771 }
+1 -3
drivers/gpio/gpio-pcf857x.c
··· 444 444 if (client->irq) 445 445 pcf857x_irq_domain_cleanup(gpio); 446 446 447 - status = gpiochip_remove(&gpio->chip); 448 - if (status) 449 - dev_err(&client->dev, "%s --> %d\n", "remove", status); 447 + gpiochip_remove(&gpio->chip); 450 448 return status; 451 449 } 452 450
+2 -8
drivers/gpio/gpio-pch.c
··· 426 426 427 427 err_request_irq: 428 428 irq_free_descs(irq_base, gpio_pins[chip->ioh]); 429 - 430 - if (gpiochip_remove(&chip->gpio)) 431 - dev_err(&pdev->dev, "%s gpiochip_remove failed\n", __func__); 429 + gpiochip_remove(&chip->gpio); 432 430 433 431 err_gpiochip_add: 434 432 pci_iounmap(pdev, chip->base); ··· 445 447 446 448 static void pch_gpio_remove(struct pci_dev *pdev) 447 449 { 448 - int err; 449 450 struct pch_gpio *chip = pci_get_drvdata(pdev); 450 451 451 452 if (chip->irq_base != -1) { ··· 453 456 irq_free_descs(chip->irq_base, gpio_pins[chip->ioh]); 454 457 } 455 458 456 - err = gpiochip_remove(&chip->gpio); 457 - if (err) 458 - dev_err(&pdev->dev, "Failed gpiochip_remove\n"); 459 - 459 + gpiochip_remove(&chip->gpio); 460 460 pci_iounmap(pdev, chip->base); 461 461 pci_release_regions(pdev); 462 462 pci_disable_device(pdev);
+6 -1
drivers/gpio/gpio-pxa.c
··· 498 498 } 499 499 500 500 #ifdef CONFIG_OF 501 - static struct of_device_id pxa_gpio_dt_ids[] = { 501 + static const struct of_device_id pxa_gpio_dt_ids[] = { 502 502 { .compatible = "intel,pxa25x-gpio", .data = &pxa25x_id, }, 503 503 { .compatible = "intel,pxa26x-gpio", .data = &pxa26x_id, }, 504 504 { .compatible = "intel,pxa27x-gpio", .data = &pxa27x_id, }, ··· 649 649 handle_edge_irq); 650 650 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); 651 651 } 652 + } else { 653 + if (irq0 > 0) 654 + irq_set_chained_handler(irq0, pxa_gpio_demux_handler); 655 + if (irq1 > 0) 656 + irq_set_chained_handler(irq1, pxa_gpio_demux_handler); 652 657 } 653 658 654 659 irq_set_chained_handler(irq_mux, pxa_gpio_demux_handler);
+2 -1
drivers/gpio/gpio-rc5t583.c
··· 148 148 { 149 149 struct rc5t583_gpio *rc5t583_gpio = platform_get_drvdata(pdev); 150 150 151 - return gpiochip_remove(&rc5t583_gpio->gpio_chip); 151 + gpiochip_remove(&rc5t583_gpio->gpio_chip); 152 + return 0; 152 153 } 153 154 154 155 static struct platform_driver rc5t583_gpio_driver = {
+3 -6
drivers/gpio/gpio-rcar.c
··· 240 240 /* testing on r8a7790 shows that INDT does not show correct pin state 241 241 * when configured as output, so use OUTDT in case of output pins */ 242 242 if (gpio_rcar_read(gpio_to_priv(chip), INOUTSEL) & bit) 243 - return (int)(gpio_rcar_read(gpio_to_priv(chip), OUTDT) & bit); 243 + return !!(gpio_rcar_read(gpio_to_priv(chip), OUTDT) & bit); 244 244 else 245 - return (int)(gpio_rcar_read(gpio_to_priv(chip), INDT) & bit); 245 + return !!(gpio_rcar_read(gpio_to_priv(chip), INDT) & bit); 246 246 } 247 247 248 248 static void gpio_rcar_set(struct gpio_chip *chip, unsigned offset, int value) ··· 472 472 static int gpio_rcar_remove(struct platform_device *pdev) 473 473 { 474 474 struct gpio_rcar_priv *p = platform_get_drvdata(pdev); 475 - int ret; 476 475 477 - ret = gpiochip_remove(&p->gpio_chip); 478 - if (ret) 479 - return ret; 476 + gpiochip_remove(&p->gpio_chip); 480 477 481 478 irq_domain_remove(p->irq_domain); 482 479 pm_runtime_put(&pdev->dev);
+2 -5
drivers/gpio/gpio-rdc321x.c
··· 199 199 200 200 static int rdc321x_gpio_remove(struct platform_device *pdev) 201 201 { 202 - int ret; 203 202 struct rdc321x_gpio *rdc321x_gpio_dev = platform_get_drvdata(pdev); 204 203 205 - ret = gpiochip_remove(&rdc321x_gpio_dev->chip); 206 - if (ret) 207 - dev_err(&pdev->dev, "failed to unregister chip\n"); 204 + gpiochip_remove(&rdc321x_gpio_dev->chip); 208 205 209 - return ret; 206 + return 0; 210 207 } 211 208 212 209 static struct platform_driver rdc321x_gpio_driver = {
+3 -13
drivers/gpio/gpio-sch.c
··· 290 290 return 0; 291 291 292 292 err_sch_gpio_resume: 293 - if (gpiochip_remove(&sch_gpio_core)) 294 - dev_err(&pdev->dev, "%s gpiochip_remove failed\n", __func__); 293 + gpiochip_remove(&sch_gpio_core); 295 294 296 295 err_sch_gpio_core: 297 296 release_region(res->start, resource_size(res)); ··· 303 304 { 304 305 struct resource *res; 305 306 if (gpio_ba) { 306 - int err; 307 307 308 - err = gpiochip_remove(&sch_gpio_core); 309 - if (err) 310 - dev_err(&pdev->dev, "%s failed, %d\n", 311 - "gpiochip_remove()", err); 312 - err = gpiochip_remove(&sch_gpio_resume); 313 - if (err) 314 - dev_err(&pdev->dev, "%s failed, %d\n", 315 - "gpiochip_remove()", err); 308 + gpiochip_remove(&sch_gpio_core); 309 + gpiochip_remove(&sch_gpio_resume); 316 310 317 311 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 318 312 319 313 release_region(res->start, resource_size(res)); 320 314 gpio_ba = 0; 321 - 322 - return err; 323 315 } 324 316 325 317 return 0;
+2 -4
drivers/gpio/gpio-sch311x.c
··· 291 291 { 292 292 struct sch311x_pdev_data *pdata = pdev->dev.platform_data; 293 293 struct sch311x_gpio_priv *priv = platform_get_drvdata(pdev); 294 - int err, i; 294 + int i; 295 295 296 296 release_region(pdata->runtime_reg + GP1, 6); 297 297 298 298 for (i = 0; i < ARRAY_SIZE(priv->blocks); i++) { 299 - err = gpiochip_remove(&priv->blocks[i].chip); 300 - if (err) 301 - return err; 299 + gpiochip_remove(&priv->blocks[i].chip); 302 300 dev_info(&pdev->dev, 303 301 "SMSC SCH311x GPIO block %d unregistered.\n", i); 304 302 }
+1 -3
drivers/gpio/gpio-sodaville.c
··· 265 265 free_irq(pdev->irq, sd); 266 266 irq_free_descs(sd->irq_base, SDV_NUM_PUB_GPIOS); 267 267 268 - if (gpiochip_remove(&sd->bgpio.gc)) 269 - dev_err(&pdev->dev, "gpiochip_remove() failed.\n"); 270 - 268 + gpiochip_remove(&sd->bgpio.gc); 271 269 pci_release_region(pdev, GPIO_BAR); 272 270 iounmap(sd->gpio_pub_base); 273 271 pci_disable_device(pdev);
+28 -91
drivers/gpio/gpio-stmpe.c
··· 10 10 #include <linux/platform_device.h> 11 11 #include <linux/slab.h> 12 12 #include <linux/gpio.h> 13 - #include <linux/irq.h> 14 - #include <linux/irqdomain.h> 15 13 #include <linux/interrupt.h> 16 14 #include <linux/of.h> 17 15 #include <linux/mfd/stmpe.h> ··· 29 31 struct stmpe *stmpe; 30 32 struct device *dev; 31 33 struct mutex irq_lock; 32 - struct irq_domain *domain; 33 34 unsigned norequest_mask; 34 - 35 35 /* Caches of interrupt control registers for bus_lock */ 36 36 u8 regs[CACHE_NR_REGS][CACHE_NR_BANKS]; 37 37 u8 oldregs[CACHE_NR_REGS][CACHE_NR_BANKS]; ··· 97 101 return stmpe_set_bits(stmpe, reg, mask, 0); 98 102 } 99 103 100 - static int stmpe_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 101 - { 102 - struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip); 103 - 104 - return irq_create_mapping(stmpe_gpio->domain, offset); 105 - } 106 - 107 104 static int stmpe_gpio_request(struct gpio_chip *chip, unsigned offset) 108 105 { 109 106 struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip); ··· 115 126 .get = stmpe_gpio_get, 116 127 .direction_output = stmpe_gpio_direction_output, 117 128 .set = stmpe_gpio_set, 118 - .to_irq = stmpe_gpio_to_irq, 119 129 .request = stmpe_gpio_request, 120 130 .can_sleep = true, 121 131 }; 122 132 123 133 static int stmpe_gpio_irq_set_type(struct irq_data *d, unsigned int type) 124 134 { 125 - struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d); 135 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 136 + struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(gc); 126 137 int offset = d->hwirq; 127 138 int regoffset = offset / 8; 128 139 int mask = 1 << (offset % 8); ··· 149 160 150 161 static void stmpe_gpio_irq_lock(struct irq_data *d) 151 162 { 152 - struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d); 163 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 164 + struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(gc); 153 165 154 166 mutex_lock(&stmpe_gpio->irq_lock); 155 167 } 156 168 157 169 static void stmpe_gpio_irq_sync_unlock(struct irq_data *d) 158 170 { 159 - struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d); 171 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 172 + struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(gc); 160 173 struct stmpe *stmpe = stmpe_gpio->stmpe; 161 174 int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8); 162 175 static const u8 regmap[] = { ··· 191 200 192 201 static void stmpe_gpio_irq_mask(struct irq_data *d) 193 202 { 194 - struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d); 203 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 204 + struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(gc); 195 205 int offset = d->hwirq; 196 206 int regoffset = offset / 8; 197 207 int mask = 1 << (offset % 8); ··· 202 210 203 211 static void stmpe_gpio_irq_unmask(struct irq_data *d) 204 212 { 205 - struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d); 213 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 214 + struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(gc); 206 215 int offset = d->hwirq; 207 216 int regoffset = offset / 8; 208 217 int mask = 1 << (offset % 8); ··· 246 253 while (stat) { 247 254 int bit = __ffs(stat); 248 255 int line = bank * 8 + bit; 249 - int child_irq = irq_find_mapping(stmpe_gpio->domain, 256 + int child_irq = irq_find_mapping(stmpe_gpio->chip.irqdomain, 250 257 line); 251 258 252 259 handle_nested_irq(child_irq); ··· 262 269 } 263 270 264 271 return IRQ_HANDLED; 265 - } 266 - 267 - static int stmpe_gpio_irq_map(struct irq_domain *d, unsigned int irq, 268 - irq_hw_number_t hwirq) 269 - { 270 - struct stmpe_gpio *stmpe_gpio = d->host_data; 271 - 272 - if (!stmpe_gpio) 273 - return -EINVAL; 274 - 275 - irq_set_chip_data(irq, stmpe_gpio); 276 - irq_set_chip_and_handler(irq, &stmpe_gpio_irq_chip, 277 - handle_simple_irq); 278 - irq_set_nested_thread(irq, 1); 279 - #ifdef CONFIG_ARM 280 - set_irq_flags(irq, IRQF_VALID); 281 - #else 282 - irq_set_noprobe(irq); 283 - #endif 284 - 285 - return 0; 286 - } 287 - 288 - static void stmpe_gpio_irq_unmap(struct irq_domain *d, unsigned int irq) 289 - { 290 - #ifdef CONFIG_ARM 291 - set_irq_flags(irq, 0); 292 - #endif 293 - irq_set_chip_and_handler(irq, NULL, NULL); 294 - irq_set_chip_data(irq, NULL); 295 - } 296 - 297 - static const struct irq_domain_ops stmpe_gpio_irq_simple_ops = { 298 - .unmap = stmpe_gpio_irq_unmap, 299 - .map = stmpe_gpio_irq_map, 300 - .xlate = irq_domain_xlate_twocell, 301 - }; 302 - 303 - static int stmpe_gpio_irq_init(struct stmpe_gpio *stmpe_gpio, 304 - struct device_node *np) 305 - { 306 - stmpe_gpio->domain = irq_domain_add_simple(np, 307 - stmpe_gpio->chip.ngpio, 0, 308 - &stmpe_gpio_irq_simple_ops, stmpe_gpio); 309 - if (!stmpe_gpio->domain) { 310 - dev_err(stmpe_gpio->dev, "failed to create irqdomain\n"); 311 - return -ENOSYS; 312 - } 313 - 314 - return 0; 315 272 } 316 273 317 274 static int stmpe_gpio_probe(struct platform_device *pdev) ··· 301 358 302 359 if (irq < 0) 303 360 dev_info(&pdev->dev, 304 - "device configured in no-irq mode; " 361 + "device configured in no-irq mode: " 305 362 "irqs are not available\n"); 306 363 307 364 ret = stmpe_enable(stmpe, STMPE_BLOCK_GPIO); 308 365 if (ret) 309 366 goto out_free; 310 367 311 - if (irq >= 0) { 312 - ret = stmpe_gpio_irq_init(stmpe_gpio, np); 313 - if (ret) 314 - goto out_disable; 315 - 316 - ret = request_threaded_irq(irq, NULL, stmpe_gpio_irq, 317 - IRQF_ONESHOT, "stmpe-gpio", stmpe_gpio); 368 + if (irq > 0) { 369 + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 370 + stmpe_gpio_irq, IRQF_ONESHOT, 371 + "stmpe-gpio", stmpe_gpio); 318 372 if (ret) { 319 373 dev_err(&pdev->dev, "unable to get irq: %d\n", ret); 320 374 goto out_disable; 375 + } 376 + ret = gpiochip_irqchip_add(&stmpe_gpio->chip, 377 + &stmpe_gpio_irq_chip, 378 + 0, 379 + handle_simple_irq, 380 + IRQ_TYPE_NONE); 381 + if (ret) { 382 + dev_err(&pdev->dev, 383 + "could not connect irqchip to gpiochip\n"); 384 + return ret; 321 385 } 322 386 } 323 387 324 388 ret = gpiochip_add(&stmpe_gpio->chip); 325 389 if (ret) { 326 390 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); 327 - goto out_freeirq; 391 + goto out_disable; 328 392 } 329 393 330 394 if (pdata && pdata->setup) ··· 341 391 342 392 return 0; 343 393 344 - out_freeirq: 345 - if (irq >= 0) 346 - free_irq(irq, stmpe_gpio); 347 394 out_disable: 348 395 stmpe_disable(stmpe, STMPE_BLOCK_GPIO); 349 396 out_free: ··· 353 406 struct stmpe_gpio *stmpe_gpio = platform_get_drvdata(pdev); 354 407 struct stmpe *stmpe = stmpe_gpio->stmpe; 355 408 struct stmpe_gpio_platform_data *pdata = stmpe->pdata->gpio; 356 - int irq = platform_get_irq(pdev, 0); 357 - int ret; 358 409 359 410 if (pdata && pdata->remove) 360 411 pdata->remove(stmpe, stmpe_gpio->chip.base); 361 412 362 - ret = gpiochip_remove(&stmpe_gpio->chip); 363 - if (ret < 0) { 364 - dev_err(stmpe_gpio->dev, 365 - "unable to remove gpiochip: %d\n", ret); 366 - return ret; 367 - } 413 + gpiochip_remove(&stmpe_gpio->chip); 368 414 369 415 stmpe_disable(stmpe, STMPE_BLOCK_GPIO); 370 - 371 - if (irq >= 0) 372 - free_irq(irq, stmpe_gpio); 373 416 374 417 kfree(stmpe_gpio); 375 418
+2 -5
drivers/gpio/gpio-sx150x.c
··· 615 615 616 616 return 0; 617 617 probe_fail_post_gpiochip_add: 618 - WARN_ON(gpiochip_remove(&chip->gpio_chip) < 0); 618 + gpiochip_remove(&chip->gpio_chip); 619 619 return rc; 620 620 } 621 621 622 622 static int sx150x_remove(struct i2c_client *client) 623 623 { 624 624 struct sx150x_chip *chip; 625 - int rc; 626 625 627 626 chip = i2c_get_clientdata(client); 628 - rc = gpiochip_remove(&chip->gpio_chip); 629 - if (rc < 0) 630 - return rc; 627 + gpiochip_remove(&chip->gpio_chip); 631 628 632 629 if (chip->irq_summary >= 0) 633 630 sx150x_remove_irq_chip(chip);
+2 -1
drivers/gpio/gpio-syscon.c
··· 172 172 { 173 173 struct syscon_gpio_priv *priv = platform_get_drvdata(pdev); 174 174 175 - return gpiochip_remove(&priv->chip); 175 + gpiochip_remove(&priv->chip); 176 + return 0; 176 177 } 177 178 178 179 static struct platform_driver syscon_gpio_driver = {
+1 -4
drivers/gpio/gpio-tb10x.c
··· 291 291 static int __exit tb10x_gpio_remove(struct platform_device *pdev) 292 292 { 293 293 struct tb10x_gpio *tb10x_gpio = platform_get_drvdata(pdev); 294 - int ret; 295 294 296 295 if (tb10x_gpio->gc.to_irq) { 297 296 irq_remove_generic_chip(tb10x_gpio->domain->gc->gc[0], ··· 299 300 irq_domain_remove(tb10x_gpio->domain); 300 301 free_irq(tb10x_gpio->irq, tb10x_gpio); 301 302 } 302 - ret = gpiochip_remove(&tb10x_gpio->gc); 303 - if (ret) 304 - return ret; 303 + gpiochip_remove(&tb10x_gpio->gc); 305 304 306 305 return 0; 307 306 }
+1 -7
drivers/gpio/gpio-tc3589x.c
··· 313 313 struct tc3589x_gpio *tc3589x_gpio = platform_get_drvdata(pdev); 314 314 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; 315 315 struct tc3589x_gpio_platform_data *pdata = tc3589x->pdata->gpio; 316 - int ret; 317 316 318 317 if (pdata && pdata->remove) 319 318 pdata->remove(tc3589x, tc3589x_gpio->chip.base); 320 319 321 - ret = gpiochip_remove(&tc3589x_gpio->chip); 322 - if (ret < 0) { 323 - dev_err(tc3589x_gpio->dev, 324 - "unable to remove gpiochip: %d\n", ret); 325 - return ret; 326 - } 320 + gpiochip_remove(&tc3589x_gpio->chip); 327 321 328 322 return 0; 329 323 }
+1 -4
drivers/gpio/gpio-timberdale.c
··· 307 307 308 308 static int timbgpio_remove(struct platform_device *pdev) 309 309 { 310 - int err; 311 310 struct timbgpio_platform_data *pdata = dev_get_platdata(&pdev->dev); 312 311 struct timbgpio *tgpio = platform_get_drvdata(pdev); 313 312 int irq = platform_get_irq(pdev, 0); ··· 322 323 irq_set_handler_data(irq, NULL); 323 324 } 324 325 325 - err = gpiochip_remove(&tgpio->gpio); 326 - if (err) 327 - printk(KERN_ERR DRIVER_NAME": failed to remove gpio_chip\n"); 326 + gpiochip_remove(&tgpio->gpio); 328 327 329 328 return 0; 330 329 }
+2 -1
drivers/gpio/gpio-tps6586x.c
··· 137 137 { 138 138 struct tps6586x_gpio *tps6586x_gpio = platform_get_drvdata(pdev); 139 139 140 - return gpiochip_remove(&tps6586x_gpio->gpio_chip); 140 + gpiochip_remove(&tps6586x_gpio->gpio_chip); 141 + return 0; 141 142 } 142 143 143 144 static struct platform_driver tps6586x_gpio_driver = {
+2 -1
drivers/gpio/gpio-tps65910.c
··· 190 190 { 191 191 struct tps65910_gpio *tps65910_gpio = platform_get_drvdata(pdev); 192 192 193 - return gpiochip_remove(&tps65910_gpio->gpio_chip); 193 + gpiochip_remove(&tps65910_gpio->gpio_chip); 194 + return 0; 194 195 } 195 196 196 197 static struct platform_driver tps65910_gpio_driver = {
+2 -1
drivers/gpio/gpio-tps65912.c
··· 117 117 { 118 118 struct tps65912_gpio_data *tps65912_gpio = platform_get_drvdata(pdev); 119 119 120 - return gpiochip_remove(&tps65912_gpio->gpio_chip); 120 + gpiochip_remove(&tps65912_gpio->gpio_chip); 121 + return 0; 121 122 } 122 123 123 124 static struct platform_driver tps65912_gpio_driver = {
+3 -3
drivers/gpio/gpio-ts5500.c
··· 427 427 428 428 return 0; 429 429 cleanup: 430 - if (gpiochip_remove(&priv->gpio_chip)) 431 - dev_err(dev, "failed to remove gpio chip\n"); 430 + gpiochip_remove(&priv->gpio_chip); 432 431 return ret; 433 432 } 434 433 ··· 436 437 struct ts5500_priv *priv = platform_get_drvdata(pdev); 437 438 438 439 ts5500_disable_irq(priv); 439 - return gpiochip_remove(&priv->gpio_chip); 440 + gpiochip_remove(&priv->gpio_chip); 441 + return 0; 440 442 } 441 443 442 444 static struct platform_device_id ts5500_dio_ids[] = {
+2 -4
drivers/gpio/gpio-twl4030.c
··· 554 554 555 555 platform_set_drvdata(pdev, priv); 556 556 557 - if (pdata && pdata->setup) { 557 + if (pdata->setup) { 558 558 int status; 559 559 560 560 status = pdata->setup(&pdev->dev, priv->gpio_chip.base, ··· 583 583 } 584 584 } 585 585 586 - status = gpiochip_remove(&priv->gpio_chip); 587 - if (status < 0) 588 - return status; 586 + gpiochip_remove(&priv->gpio_chip); 589 587 590 588 if (is_module()) 591 589 return 0;
+2 -1
drivers/gpio/gpio-twl6040.c
··· 111 111 112 112 static int gpo_twl6040_remove(struct platform_device *pdev) 113 113 { 114 - return gpiochip_remove(&twl6040gpo_chip); 114 + gpiochip_remove(&twl6040gpo_chip); 115 + return 0; 115 116 } 116 117 117 118 /* Note: this hardware lives inside an I2C-based multi-function device. */
+2 -2
drivers/gpio/gpio-ucb1400.c
··· 70 70 if (err) 71 71 goto err; 72 72 73 - if (ucb && ucb->gpio_setup) 73 + if (ucb->gpio_setup) 74 74 err = ucb->gpio_setup(&dev->dev, ucb->gc.ngpio); 75 75 76 76 err: ··· 89 89 return err; 90 90 } 91 91 92 - err = gpiochip_remove(&ucb->gc); 92 + gpiochip_remove(&ucb->gc); 93 93 return err; 94 94 } 95 95
+3 -7
drivers/gpio/gpio-viperboard.c
··· 446 446 return ret; 447 447 448 448 err_gpiob: 449 - if (gpiochip_remove(&vb_gpio->gpioa)) 450 - dev_err(&pdev->dev, "%s gpiochip_remove failed\n", __func__); 449 + gpiochip_remove(&vb_gpio->gpioa); 451 450 452 451 err_gpioa: 453 452 return ret; ··· 455 456 static int vprbrd_gpio_remove(struct platform_device *pdev) 456 457 { 457 458 struct vprbrd_gpio *vb_gpio = platform_get_drvdata(pdev); 458 - int ret; 459 459 460 - ret = gpiochip_remove(&vb_gpio->gpiob); 461 - if (ret == 0) 462 - ret = gpiochip_remove(&vb_gpio->gpioa); 460 + gpiochip_remove(&vb_gpio->gpiob); 463 461 464 - return ret; 462 + return 0; 465 463 } 466 464 467 465 static struct platform_driver vprbrd_gpio_driver = {
+6 -2
drivers/gpio/gpio-vr41xx.c
··· 515 515 struct resource *res; 516 516 unsigned int trigger, i, pin; 517 517 struct irq_chip *chip; 518 - int irq, retval; 518 + int irq, ret; 519 519 520 520 switch (pdev->id) { 521 521 case GPIO_50PINS_PULLUPDOWN: ··· 544 544 545 545 vr41xx_gpio_chip.dev = &pdev->dev; 546 546 547 - retval = gpiochip_add(&vr41xx_gpio_chip); 547 + ret = gpiochip_add(&vr41xx_gpio_chip); 548 + if (!ret) { 549 + iounmap(giu_base); 550 + return -ENODEV; 551 + } 548 552 549 553 giu_write(GIUINTENL, 0); 550 554 giu_write(GIUINTENH, 0);
+1 -2
drivers/gpio/gpio-vx855.c
··· 288 288 struct vx855_gpio *vg = platform_get_drvdata(pdev); 289 289 struct resource *res; 290 290 291 - if (gpiochip_remove(&vg->gpio)) 292 - dev_err(&pdev->dev, "unable to remove gpio_chip?\n"); 291 + gpiochip_remove(&vg->gpio); 293 292 294 293 if (vg->gpi_reserved) { 295 294 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
+2 -1
drivers/gpio/gpio-wm831x.c
··· 279 279 { 280 280 struct wm831x_gpio *wm831x_gpio = platform_get_drvdata(pdev); 281 281 282 - return gpiochip_remove(&wm831x_gpio->gpio_chip); 282 + gpiochip_remove(&wm831x_gpio->gpio_chip); 283 + return 0; 283 284 } 284 285 285 286 static struct platform_driver wm831x_gpio_driver = {
+2 -1
drivers/gpio/gpio-wm8350.c
··· 145 145 { 146 146 struct wm8350_gpio_data *wm8350_gpio = platform_get_drvdata(pdev); 147 147 148 - return gpiochip_remove(&wm8350_gpio->gpio_chip); 148 + gpiochip_remove(&wm8350_gpio->gpio_chip); 149 + return 0; 149 150 } 150 151 151 152 static struct platform_driver wm8350_gpio_driver = {
+2 -1
drivers/gpio/gpio-wm8994.c
··· 285 285 { 286 286 struct wm8994_gpio *wm8994_gpio = platform_get_drvdata(pdev); 287 287 288 - return gpiochip_remove(&wm8994_gpio->gpio_chip); 288 + gpiochip_remove(&wm8994_gpio->gpio_chip); 289 + return 0; 289 290 } 290 291 291 292 static struct platform_driver wm8994_gpio_driver = {
+692
drivers/gpio/gpio-zynq.c
··· 1 + /* 2 + * Xilinx Zynq GPIO device driver 3 + * 4 + * Copyright (C) 2009 - 2014 Xilinx, Inc. 5 + * 6 + * This program is free software; you can redistribute it and/or modify it under 7 + * the terms of the GNU General Public License as published by the Free Software 8 + * Foundation; either version 2 of the License, or (at your option) any later 9 + * version. 10 + */ 11 + 12 + #include <linux/bitops.h> 13 + #include <linux/clk.h> 14 + #include <linux/gpio/driver.h> 15 + #include <linux/init.h> 16 + #include <linux/interrupt.h> 17 + #include <linux/io.h> 18 + #include <linux/module.h> 19 + #include <linux/platform_device.h> 20 + #include <linux/pm_runtime.h> 21 + 22 + #define DRIVER_NAME "zynq-gpio" 23 + 24 + /* Maximum banks */ 25 + #define ZYNQ_GPIO_MAX_BANK 4 26 + 27 + #define ZYNQ_GPIO_BANK0_NGPIO 32 28 + #define ZYNQ_GPIO_BANK1_NGPIO 22 29 + #define ZYNQ_GPIO_BANK2_NGPIO 32 30 + #define ZYNQ_GPIO_BANK3_NGPIO 32 31 + 32 + #define ZYNQ_GPIO_NR_GPIOS (ZYNQ_GPIO_BANK0_NGPIO + \ 33 + ZYNQ_GPIO_BANK1_NGPIO + \ 34 + ZYNQ_GPIO_BANK2_NGPIO + \ 35 + ZYNQ_GPIO_BANK3_NGPIO) 36 + 37 + #define ZYNQ_GPIO_BANK0_PIN_MIN 0 38 + #define ZYNQ_GPIO_BANK0_PIN_MAX (ZYNQ_GPIO_BANK0_PIN_MIN + \ 39 + ZYNQ_GPIO_BANK0_NGPIO - 1) 40 + #define ZYNQ_GPIO_BANK1_PIN_MIN (ZYNQ_GPIO_BANK0_PIN_MAX + 1) 41 + #define ZYNQ_GPIO_BANK1_PIN_MAX (ZYNQ_GPIO_BANK1_PIN_MIN + \ 42 + ZYNQ_GPIO_BANK1_NGPIO - 1) 43 + #define ZYNQ_GPIO_BANK2_PIN_MIN (ZYNQ_GPIO_BANK1_PIN_MAX + 1) 44 + #define ZYNQ_GPIO_BANK2_PIN_MAX (ZYNQ_GPIO_BANK2_PIN_MIN + \ 45 + ZYNQ_GPIO_BANK2_NGPIO - 1) 46 + #define ZYNQ_GPIO_BANK3_PIN_MIN (ZYNQ_GPIO_BANK2_PIN_MAX + 1) 47 + #define ZYNQ_GPIO_BANK3_PIN_MAX (ZYNQ_GPIO_BANK3_PIN_MIN + \ 48 + ZYNQ_GPIO_BANK3_NGPIO - 1) 49 + 50 + 51 + /* Register offsets for the GPIO device */ 52 + /* LSW Mask & Data -WO */ 53 + #define ZYNQ_GPIO_DATA_LSW_OFFSET(BANK) (0x000 + (8 * BANK)) 54 + /* MSW Mask & Data -WO */ 55 + #define ZYNQ_GPIO_DATA_MSW_OFFSET(BANK) (0x004 + (8 * BANK)) 56 + /* Data Register-RW */ 57 + #define ZYNQ_GPIO_DATA_RO_OFFSET(BANK) (0x060 + (4 * BANK)) 58 + /* Direction mode reg-RW */ 59 + #define ZYNQ_GPIO_DIRM_OFFSET(BANK) (0x204 + (0x40 * BANK)) 60 + /* Output enable reg-RW */ 61 + #define ZYNQ_GPIO_OUTEN_OFFSET(BANK) (0x208 + (0x40 * BANK)) 62 + /* Interrupt mask reg-RO */ 63 + #define ZYNQ_GPIO_INTMASK_OFFSET(BANK) (0x20C + (0x40 * BANK)) 64 + /* Interrupt enable reg-WO */ 65 + #define ZYNQ_GPIO_INTEN_OFFSET(BANK) (0x210 + (0x40 * BANK)) 66 + /* Interrupt disable reg-WO */ 67 + #define ZYNQ_GPIO_INTDIS_OFFSET(BANK) (0x214 + (0x40 * BANK)) 68 + /* Interrupt status reg-RO */ 69 + #define ZYNQ_GPIO_INTSTS_OFFSET(BANK) (0x218 + (0x40 * BANK)) 70 + /* Interrupt type reg-RW */ 71 + #define ZYNQ_GPIO_INTTYPE_OFFSET(BANK) (0x21C + (0x40 * BANK)) 72 + /* Interrupt polarity reg-RW */ 73 + #define ZYNQ_GPIO_INTPOL_OFFSET(BANK) (0x220 + (0x40 * BANK)) 74 + /* Interrupt on any, reg-RW */ 75 + #define ZYNQ_GPIO_INTANY_OFFSET(BANK) (0x224 + (0x40 * BANK)) 76 + 77 + /* Disable all interrupts mask */ 78 + #define ZYNQ_GPIO_IXR_DISABLE_ALL 0xFFFFFFFF 79 + 80 + /* Mid pin number of a bank */ 81 + #define ZYNQ_GPIO_MID_PIN_NUM 16 82 + 83 + /* GPIO upper 16 bit mask */ 84 + #define ZYNQ_GPIO_UPPER_MASK 0xFFFF0000 85 + 86 + /** 87 + * struct zynq_gpio - gpio device private data structure 88 + * @chip: instance of the gpio_chip 89 + * @base_addr: base address of the GPIO device 90 + * @clk: clock resource for this controller 91 + */ 92 + struct zynq_gpio { 93 + struct gpio_chip chip; 94 + void __iomem *base_addr; 95 + struct clk *clk; 96 + }; 97 + 98 + /** 99 + * zynq_gpio_get_bank_pin - Get the bank number and pin number within that bank 100 + * for a given pin in the GPIO device 101 + * @pin_num: gpio pin number within the device 102 + * @bank_num: an output parameter used to return the bank number of the gpio 103 + * pin 104 + * @bank_pin_num: an output parameter used to return pin number within a bank 105 + * for the given gpio pin 106 + * 107 + * Returns the bank number and pin offset within the bank. 108 + */ 109 + static inline void zynq_gpio_get_bank_pin(unsigned int pin_num, 110 + unsigned int *bank_num, 111 + unsigned int *bank_pin_num) 112 + { 113 + switch (pin_num) { 114 + case ZYNQ_GPIO_BANK0_PIN_MIN ... ZYNQ_GPIO_BANK0_PIN_MAX: 115 + *bank_num = 0; 116 + *bank_pin_num = pin_num; 117 + break; 118 + case ZYNQ_GPIO_BANK1_PIN_MIN ... ZYNQ_GPIO_BANK1_PIN_MAX: 119 + *bank_num = 1; 120 + *bank_pin_num = pin_num - ZYNQ_GPIO_BANK1_PIN_MIN; 121 + break; 122 + case ZYNQ_GPIO_BANK2_PIN_MIN ... ZYNQ_GPIO_BANK2_PIN_MAX: 123 + *bank_num = 2; 124 + *bank_pin_num = pin_num - ZYNQ_GPIO_BANK2_PIN_MIN; 125 + break; 126 + case ZYNQ_GPIO_BANK3_PIN_MIN ... ZYNQ_GPIO_BANK3_PIN_MAX: 127 + *bank_num = 3; 128 + *bank_pin_num = pin_num - ZYNQ_GPIO_BANK3_PIN_MIN; 129 + break; 130 + default: 131 + WARN(true, "invalid GPIO pin number: %u", pin_num); 132 + *bank_num = 0; 133 + *bank_pin_num = 0; 134 + break; 135 + } 136 + } 137 + 138 + /** 139 + * zynq_gpio_get_value - Get the state of the specified pin of GPIO device 140 + * @chip: gpio_chip instance to be worked on 141 + * @pin: gpio pin number within the device 142 + * 143 + * This function reads the state of the specified pin of the GPIO device. 144 + * 145 + * Return: 0 if the pin is low, 1 if pin is high. 146 + */ 147 + static int zynq_gpio_get_value(struct gpio_chip *chip, unsigned int pin) 148 + { 149 + u32 data; 150 + unsigned int bank_num, bank_pin_num; 151 + struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); 152 + 153 + zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num); 154 + 155 + data = readl_relaxed(gpio->base_addr + 156 + ZYNQ_GPIO_DATA_RO_OFFSET(bank_num)); 157 + 158 + return (data >> bank_pin_num) & 1; 159 + } 160 + 161 + /** 162 + * zynq_gpio_set_value - Modify the state of the pin with specified value 163 + * @chip: gpio_chip instance to be worked on 164 + * @pin: gpio pin number within the device 165 + * @state: value used to modify the state of the specified pin 166 + * 167 + * This function calculates the register offset (i.e to lower 16 bits or 168 + * upper 16 bits) based on the given pin number and sets the state of a 169 + * gpio pin to the specified value. The state is either 0 or non-zero. 170 + */ 171 + static void zynq_gpio_set_value(struct gpio_chip *chip, unsigned int pin, 172 + int state) 173 + { 174 + unsigned int reg_offset, bank_num, bank_pin_num; 175 + struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); 176 + 177 + zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num); 178 + 179 + if (bank_pin_num >= ZYNQ_GPIO_MID_PIN_NUM) { 180 + /* only 16 data bits in bit maskable reg */ 181 + bank_pin_num -= ZYNQ_GPIO_MID_PIN_NUM; 182 + reg_offset = ZYNQ_GPIO_DATA_MSW_OFFSET(bank_num); 183 + } else { 184 + reg_offset = ZYNQ_GPIO_DATA_LSW_OFFSET(bank_num); 185 + } 186 + 187 + /* 188 + * get the 32 bit value to be written to the mask/data register where 189 + * the upper 16 bits is the mask and lower 16 bits is the data 190 + */ 191 + state = !!state; 192 + state = ~(1 << (bank_pin_num + ZYNQ_GPIO_MID_PIN_NUM)) & 193 + ((state << bank_pin_num) | ZYNQ_GPIO_UPPER_MASK); 194 + 195 + writel_relaxed(state, gpio->base_addr + reg_offset); 196 + } 197 + 198 + /** 199 + * zynq_gpio_dir_in - Set the direction of the specified GPIO pin as input 200 + * @chip: gpio_chip instance to be worked on 201 + * @pin: gpio pin number within the device 202 + * 203 + * This function uses the read-modify-write sequence to set the direction of 204 + * the gpio pin as input. 205 + * 206 + * Return: 0 always 207 + */ 208 + static int zynq_gpio_dir_in(struct gpio_chip *chip, unsigned int pin) 209 + { 210 + u32 reg; 211 + unsigned int bank_num, bank_pin_num; 212 + struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); 213 + 214 + zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num); 215 + 216 + /* bank 0 pins 7 and 8 are special and cannot be used as inputs */ 217 + if (bank_num == 0 && (bank_pin_num == 7 || bank_pin_num == 8)) 218 + return -EINVAL; 219 + 220 + /* clear the bit in direction mode reg to set the pin as input */ 221 + reg = readl_relaxed(gpio->base_addr + ZYNQ_GPIO_DIRM_OFFSET(bank_num)); 222 + reg &= ~BIT(bank_pin_num); 223 + writel_relaxed(reg, gpio->base_addr + ZYNQ_GPIO_DIRM_OFFSET(bank_num)); 224 + 225 + return 0; 226 + } 227 + 228 + /** 229 + * zynq_gpio_dir_out - Set the direction of the specified GPIO pin as output 230 + * @chip: gpio_chip instance to be worked on 231 + * @pin: gpio pin number within the device 232 + * @state: value to be written to specified pin 233 + * 234 + * This function sets the direction of specified GPIO pin as output, configures 235 + * the Output Enable register for the pin and uses zynq_gpio_set to set 236 + * the state of the pin to the value specified. 237 + * 238 + * Return: 0 always 239 + */ 240 + static int zynq_gpio_dir_out(struct gpio_chip *chip, unsigned int pin, 241 + int state) 242 + { 243 + u32 reg; 244 + unsigned int bank_num, bank_pin_num; 245 + struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); 246 + 247 + zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num); 248 + 249 + /* set the GPIO pin as output */ 250 + reg = readl_relaxed(gpio->base_addr + ZYNQ_GPIO_DIRM_OFFSET(bank_num)); 251 + reg |= BIT(bank_pin_num); 252 + writel_relaxed(reg, gpio->base_addr + ZYNQ_GPIO_DIRM_OFFSET(bank_num)); 253 + 254 + /* configure the output enable reg for the pin */ 255 + reg = readl_relaxed(gpio->base_addr + ZYNQ_GPIO_OUTEN_OFFSET(bank_num)); 256 + reg |= BIT(bank_pin_num); 257 + writel_relaxed(reg, gpio->base_addr + ZYNQ_GPIO_OUTEN_OFFSET(bank_num)); 258 + 259 + /* set the state of the pin */ 260 + zynq_gpio_set_value(chip, pin, state); 261 + return 0; 262 + } 263 + 264 + /** 265 + * zynq_gpio_irq_mask - Disable the interrupts for a gpio pin 266 + * @irq_data: per irq and chip data passed down to chip functions 267 + * 268 + * This function calculates gpio pin number from irq number and sets the 269 + * bit in the Interrupt Disable register of the corresponding bank to disable 270 + * interrupts for that pin. 271 + */ 272 + static void zynq_gpio_irq_mask(struct irq_data *irq_data) 273 + { 274 + unsigned int device_pin_num, bank_num, bank_pin_num; 275 + struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); 276 + 277 + device_pin_num = irq_data->hwirq; 278 + zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num); 279 + writel_relaxed(BIT(bank_pin_num), 280 + gpio->base_addr + ZYNQ_GPIO_INTDIS_OFFSET(bank_num)); 281 + } 282 + 283 + /** 284 + * zynq_gpio_irq_unmask - Enable the interrupts for a gpio pin 285 + * @irq_data: irq data containing irq number of gpio pin for the interrupt 286 + * to enable 287 + * 288 + * This function calculates the gpio pin number from irq number and sets the 289 + * bit in the Interrupt Enable register of the corresponding bank to enable 290 + * interrupts for that pin. 291 + */ 292 + static void zynq_gpio_irq_unmask(struct irq_data *irq_data) 293 + { 294 + unsigned int device_pin_num, bank_num, bank_pin_num; 295 + struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); 296 + 297 + device_pin_num = irq_data->hwirq; 298 + zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num); 299 + writel_relaxed(BIT(bank_pin_num), 300 + gpio->base_addr + ZYNQ_GPIO_INTEN_OFFSET(bank_num)); 301 + } 302 + 303 + /** 304 + * zynq_gpio_irq_ack - Acknowledge the interrupt of a gpio pin 305 + * @irq_data: irq data containing irq number of gpio pin for the interrupt 306 + * to ack 307 + * 308 + * This function calculates gpio pin number from irq number and sets the bit 309 + * in the Interrupt Status Register of the corresponding bank, to ACK the irq. 310 + */ 311 + static void zynq_gpio_irq_ack(struct irq_data *irq_data) 312 + { 313 + unsigned int device_pin_num, bank_num, bank_pin_num; 314 + struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); 315 + 316 + device_pin_num = irq_data->hwirq; 317 + zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num); 318 + writel_relaxed(BIT(bank_pin_num), 319 + gpio->base_addr + ZYNQ_GPIO_INTSTS_OFFSET(bank_num)); 320 + } 321 + 322 + /** 323 + * zynq_gpio_irq_enable - Enable the interrupts for a gpio pin 324 + * @irq_data: irq data containing irq number of gpio pin for the interrupt 325 + * to enable 326 + * 327 + * Clears the INTSTS bit and unmasks the given interrrupt. 328 + */ 329 + static void zynq_gpio_irq_enable(struct irq_data *irq_data) 330 + { 331 + /* 332 + * The Zynq GPIO controller does not disable interrupt detection when 333 + * the interrupt is masked and only disables the propagation of the 334 + * interrupt. This means when the controller detects an interrupt 335 + * condition while the interrupt is logically disabled it will propagate 336 + * that interrupt event once the interrupt is enabled. This will cause 337 + * the interrupt consumer to see spurious interrupts to prevent this 338 + * first make sure that the interrupt is not asserted and then enable 339 + * it. 340 + */ 341 + zynq_gpio_irq_ack(irq_data); 342 + zynq_gpio_irq_unmask(irq_data); 343 + } 344 + 345 + /** 346 + * zynq_gpio_set_irq_type - Set the irq type for a gpio pin 347 + * @irq_data: irq data containing irq number of gpio pin 348 + * @type: interrupt type that is to be set for the gpio pin 349 + * 350 + * This function gets the gpio pin number and its bank from the gpio pin number 351 + * and configures the INT_TYPE, INT_POLARITY and INT_ANY registers. 352 + * 353 + * Return: 0, negative error otherwise. 354 + * TYPE-EDGE_RISING, INT_TYPE - 1, INT_POLARITY - 1, INT_ANY - 0; 355 + * TYPE-EDGE_FALLING, INT_TYPE - 1, INT_POLARITY - 0, INT_ANY - 0; 356 + * TYPE-EDGE_BOTH, INT_TYPE - 1, INT_POLARITY - NA, INT_ANY - 1; 357 + * TYPE-LEVEL_HIGH, INT_TYPE - 0, INT_POLARITY - 1, INT_ANY - NA; 358 + * TYPE-LEVEL_LOW, INT_TYPE - 0, INT_POLARITY - 0, INT_ANY - NA 359 + */ 360 + static int zynq_gpio_set_irq_type(struct irq_data *irq_data, unsigned int type) 361 + { 362 + u32 int_type, int_pol, int_any; 363 + unsigned int device_pin_num, bank_num, bank_pin_num; 364 + struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); 365 + 366 + device_pin_num = irq_data->hwirq; 367 + zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num); 368 + 369 + int_type = readl_relaxed(gpio->base_addr + 370 + ZYNQ_GPIO_INTTYPE_OFFSET(bank_num)); 371 + int_pol = readl_relaxed(gpio->base_addr + 372 + ZYNQ_GPIO_INTPOL_OFFSET(bank_num)); 373 + int_any = readl_relaxed(gpio->base_addr + 374 + ZYNQ_GPIO_INTANY_OFFSET(bank_num)); 375 + 376 + /* 377 + * based on the type requested, configure the INT_TYPE, INT_POLARITY 378 + * and INT_ANY registers 379 + */ 380 + switch (type) { 381 + case IRQ_TYPE_EDGE_RISING: 382 + int_type |= BIT(bank_pin_num); 383 + int_pol |= BIT(bank_pin_num); 384 + int_any &= ~BIT(bank_pin_num); 385 + break; 386 + case IRQ_TYPE_EDGE_FALLING: 387 + int_type |= BIT(bank_pin_num); 388 + int_pol &= ~BIT(bank_pin_num); 389 + int_any &= ~BIT(bank_pin_num); 390 + break; 391 + case IRQ_TYPE_EDGE_BOTH: 392 + int_type |= BIT(bank_pin_num); 393 + int_any |= BIT(bank_pin_num); 394 + break; 395 + case IRQ_TYPE_LEVEL_HIGH: 396 + int_type &= ~BIT(bank_pin_num); 397 + int_pol |= BIT(bank_pin_num); 398 + break; 399 + case IRQ_TYPE_LEVEL_LOW: 400 + int_type &= ~BIT(bank_pin_num); 401 + int_pol &= ~BIT(bank_pin_num); 402 + break; 403 + default: 404 + return -EINVAL; 405 + } 406 + 407 + writel_relaxed(int_type, 408 + gpio->base_addr + ZYNQ_GPIO_INTTYPE_OFFSET(bank_num)); 409 + writel_relaxed(int_pol, 410 + gpio->base_addr + ZYNQ_GPIO_INTPOL_OFFSET(bank_num)); 411 + writel_relaxed(int_any, 412 + gpio->base_addr + ZYNQ_GPIO_INTANY_OFFSET(bank_num)); 413 + return 0; 414 + } 415 + 416 + static int zynq_gpio_set_wake(struct irq_data *data, unsigned int on) 417 + { 418 + if (on) 419 + zynq_gpio_irq_unmask(data); 420 + else 421 + zynq_gpio_irq_mask(data); 422 + 423 + return 0; 424 + } 425 + 426 + /* irq chip descriptor */ 427 + static struct irq_chip zynq_gpio_irqchip = { 428 + .name = DRIVER_NAME, 429 + .irq_enable = zynq_gpio_irq_enable, 430 + .irq_mask = zynq_gpio_irq_mask, 431 + .irq_unmask = zynq_gpio_irq_unmask, 432 + .irq_set_type = zynq_gpio_set_irq_type, 433 + .irq_set_wake = zynq_gpio_set_wake, 434 + }; 435 + 436 + /** 437 + * zynq_gpio_irqhandler - IRQ handler for the gpio banks of a gpio device 438 + * @irq: irq number of the gpio bank where interrupt has occurred 439 + * @desc: irq descriptor instance of the 'irq' 440 + * 441 + * This function reads the Interrupt Status Register of each bank to get the 442 + * gpio pin number which has triggered an interrupt. It then acks the triggered 443 + * interrupt and calls the pin specific handler set by the higher layer 444 + * application for that pin. 445 + * Note: A bug is reported if no handler is set for the gpio pin. 446 + */ 447 + static void zynq_gpio_irqhandler(unsigned int irq, struct irq_desc *desc) 448 + { 449 + u32 int_sts, int_enb; 450 + unsigned int bank_num; 451 + struct zynq_gpio *gpio = irq_get_handler_data(irq); 452 + struct irq_chip *irqchip = irq_desc_get_chip(desc); 453 + 454 + chained_irq_enter(irqchip, desc); 455 + 456 + for (bank_num = 0; bank_num < ZYNQ_GPIO_MAX_BANK; bank_num++) { 457 + int_sts = readl_relaxed(gpio->base_addr + 458 + ZYNQ_GPIO_INTSTS_OFFSET(bank_num)); 459 + int_enb = readl_relaxed(gpio->base_addr + 460 + ZYNQ_GPIO_INTMASK_OFFSET(bank_num)); 461 + int_sts &= ~int_enb; 462 + if (int_sts) { 463 + int offset; 464 + unsigned long pending = int_sts; 465 + 466 + for_each_set_bit(offset, &pending, 32) { 467 + unsigned int gpio_irq = 468 + irq_find_mapping(gpio->chip.irqdomain, 469 + offset); 470 + generic_handle_irq(gpio_irq); 471 + } 472 + 473 + /* clear IRQ in HW */ 474 + writel_relaxed(int_sts, gpio->base_addr + 475 + ZYNQ_GPIO_INTSTS_OFFSET(bank_num)); 476 + } 477 + } 478 + 479 + chained_irq_exit(irqchip, desc); 480 + } 481 + 482 + static int __maybe_unused zynq_gpio_suspend(struct device *dev) 483 + { 484 + if (!device_may_wakeup(dev)) 485 + return pm_runtime_force_suspend(dev); 486 + 487 + return 0; 488 + } 489 + 490 + static int __maybe_unused zynq_gpio_resume(struct device *dev) 491 + { 492 + if (!device_may_wakeup(dev)) 493 + return pm_runtime_force_resume(dev); 494 + 495 + return 0; 496 + } 497 + 498 + static int __maybe_unused zynq_gpio_runtime_suspend(struct device *dev) 499 + { 500 + struct platform_device *pdev = to_platform_device(dev); 501 + struct zynq_gpio *gpio = platform_get_drvdata(pdev); 502 + 503 + clk_disable_unprepare(gpio->clk); 504 + 505 + return 0; 506 + } 507 + 508 + static int __maybe_unused zynq_gpio_runtime_resume(struct device *dev) 509 + { 510 + struct platform_device *pdev = to_platform_device(dev); 511 + struct zynq_gpio *gpio = platform_get_drvdata(pdev); 512 + 513 + return clk_prepare_enable(gpio->clk); 514 + } 515 + 516 + static int zynq_gpio_request(struct gpio_chip *chip, unsigned offset) 517 + { 518 + int ret; 519 + 520 + ret = pm_runtime_get_sync(chip->dev); 521 + 522 + /* 523 + * If the device is already active pm_runtime_get() will return 1 on 524 + * success, but gpio_request still needs to return 0. 525 + */ 526 + return ret < 0 ? ret : 0; 527 + } 528 + 529 + static void zynq_gpio_free(struct gpio_chip *chip, unsigned offset) 530 + { 531 + pm_runtime_put(chip->dev); 532 + } 533 + 534 + static const struct dev_pm_ops zynq_gpio_dev_pm_ops = { 535 + SET_SYSTEM_SLEEP_PM_OPS(zynq_gpio_suspend, zynq_gpio_resume) 536 + SET_PM_RUNTIME_PM_OPS(zynq_gpio_runtime_suspend, 537 + zynq_gpio_runtime_resume, NULL) 538 + }; 539 + 540 + /** 541 + * zynq_gpio_probe - Initialization method for a zynq_gpio device 542 + * @pdev: platform device instance 543 + * 544 + * This function allocates memory resources for the gpio device and registers 545 + * all the banks of the device. It will also set up interrupts for the gpio 546 + * pins. 547 + * Note: Interrupts are disabled for all the banks during initialization. 548 + * 549 + * Return: 0 on success, negative error otherwise. 550 + */ 551 + static int zynq_gpio_probe(struct platform_device *pdev) 552 + { 553 + int ret, bank_num, irq; 554 + struct zynq_gpio *gpio; 555 + struct gpio_chip *chip; 556 + struct resource *res; 557 + 558 + gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); 559 + if (!gpio) 560 + return -ENOMEM; 561 + 562 + platform_set_drvdata(pdev, gpio); 563 + 564 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 565 + gpio->base_addr = devm_ioremap_resource(&pdev->dev, res); 566 + if (IS_ERR(gpio->base_addr)) 567 + return PTR_ERR(gpio->base_addr); 568 + 569 + irq = platform_get_irq(pdev, 0); 570 + if (irq < 0) { 571 + dev_err(&pdev->dev, "invalid IRQ\n"); 572 + return irq; 573 + } 574 + 575 + /* configure the gpio chip */ 576 + chip = &gpio->chip; 577 + chip->label = "zynq_gpio"; 578 + chip->owner = THIS_MODULE; 579 + chip->dev = &pdev->dev; 580 + chip->get = zynq_gpio_get_value; 581 + chip->set = zynq_gpio_set_value; 582 + chip->request = zynq_gpio_request; 583 + chip->free = zynq_gpio_free; 584 + chip->direction_input = zynq_gpio_dir_in; 585 + chip->direction_output = zynq_gpio_dir_out; 586 + chip->base = -1; 587 + chip->ngpio = ZYNQ_GPIO_NR_GPIOS; 588 + 589 + /* Enable GPIO clock */ 590 + gpio->clk = devm_clk_get(&pdev->dev, NULL); 591 + if (IS_ERR(gpio->clk)) { 592 + dev_err(&pdev->dev, "input clock not found.\n"); 593 + return PTR_ERR(gpio->clk); 594 + } 595 + ret = clk_prepare_enable(gpio->clk); 596 + if (ret) { 597 + dev_err(&pdev->dev, "Unable to enable clock.\n"); 598 + return ret; 599 + } 600 + 601 + /* report a bug if gpio chip registration fails */ 602 + ret = gpiochip_add(chip); 603 + if (ret) { 604 + dev_err(&pdev->dev, "Failed to add gpio chip\n"); 605 + goto err_disable_clk; 606 + } 607 + 608 + /* disable interrupts for all banks */ 609 + for (bank_num = 0; bank_num < ZYNQ_GPIO_MAX_BANK; bank_num++) 610 + writel_relaxed(ZYNQ_GPIO_IXR_DISABLE_ALL, gpio->base_addr + 611 + ZYNQ_GPIO_INTDIS_OFFSET(bank_num)); 612 + 613 + ret = gpiochip_irqchip_add(chip, &zynq_gpio_irqchip, 0, 614 + handle_simple_irq, IRQ_TYPE_NONE); 615 + if (ret) { 616 + dev_err(&pdev->dev, "Failed to add irq chip\n"); 617 + goto err_rm_gpiochip; 618 + } 619 + 620 + gpiochip_set_chained_irqchip(chip, &zynq_gpio_irqchip, irq, 621 + zynq_gpio_irqhandler); 622 + 623 + pm_runtime_set_active(&pdev->dev); 624 + pm_runtime_enable(&pdev->dev); 625 + 626 + device_set_wakeup_capable(&pdev->dev, 1); 627 + 628 + return 0; 629 + 630 + err_rm_gpiochip: 631 + if (gpiochip_remove(chip)) 632 + dev_err(&pdev->dev, "Failed to remove gpio chip\n"); 633 + err_disable_clk: 634 + clk_disable_unprepare(gpio->clk); 635 + 636 + return ret; 637 + } 638 + 639 + /** 640 + * zynq_gpio_remove - Driver removal function 641 + * @pdev: platform device instance 642 + * 643 + * Return: 0 always 644 + */ 645 + static int zynq_gpio_remove(struct platform_device *pdev) 646 + { 647 + int ret; 648 + struct zynq_gpio *gpio = platform_get_drvdata(pdev); 649 + 650 + pm_runtime_get_sync(&pdev->dev); 651 + 652 + ret = gpiochip_remove(&gpio->chip); 653 + if (ret) { 654 + dev_err(&pdev->dev, "Failed to remove gpio chip\n"); 655 + return ret; 656 + } 657 + clk_disable_unprepare(gpio->clk); 658 + device_set_wakeup_capable(&pdev->dev, 0); 659 + return 0; 660 + } 661 + 662 + static struct of_device_id zynq_gpio_of_match[] = { 663 + { .compatible = "xlnx,zynq-gpio-1.0", }, 664 + { /* end of table */ } 665 + }; 666 + MODULE_DEVICE_TABLE(of, zynq_gpio_of_match); 667 + 668 + static struct platform_driver zynq_gpio_driver = { 669 + .driver = { 670 + .name = DRIVER_NAME, 671 + .owner = THIS_MODULE, 672 + .pm = &zynq_gpio_dev_pm_ops, 673 + .of_match_table = zynq_gpio_of_match, 674 + }, 675 + .probe = zynq_gpio_probe, 676 + .remove = zynq_gpio_remove, 677 + }; 678 + 679 + /** 680 + * zynq_gpio_init - Initial driver registration call 681 + * 682 + * Return: value from platform_driver_register 683 + */ 684 + static int __init zynq_gpio_init(void) 685 + { 686 + return platform_driver_register(&zynq_gpio_driver); 687 + } 688 + postcore_initcall(zynq_gpio_init); 689 + 690 + MODULE_AUTHOR("Xilinx Inc."); 691 + MODULE_DESCRIPTION("Zynq GPIO driver"); 692 + MODULE_LICENSE("GPL");
+31 -13
drivers/gpio/gpiolib-acpi.c
··· 157 157 158 158 gpiod_direction_input(desc); 159 159 160 - ret = gpiod_lock_as_irq(desc); 160 + ret = gpio_lock_as_irq(chip, pin); 161 161 if (ret) { 162 162 dev_err(chip->dev, "Failed to lock GPIO as interrupt\n"); 163 163 goto fail_free_desc; ··· 212 212 fail_free_event: 213 213 kfree(event); 214 214 fail_unlock_irq: 215 - gpiod_unlock_as_irq(desc); 215 + gpio_unlock_as_irq(chip, pin); 216 216 fail_free_desc: 217 217 gpiochip_free_own_desc(desc); 218 218 ··· 221 221 222 222 /** 223 223 * acpi_gpiochip_request_interrupts() - Register isr for gpio chip ACPI events 224 - * @acpi_gpio: ACPI GPIO chip 224 + * @chip: GPIO chip 225 225 * 226 226 * ACPI5 platforms can use GPIO signaled ACPI events. These GPIO interrupts are 227 227 * handled by ACPI event methods which need to be called from the GPIO ··· 229 229 * gpio pins have acpi event methods and assigns interrupt handlers that calls 230 230 * the acpi event methods for those pins. 231 231 */ 232 - static void acpi_gpiochip_request_interrupts(struct acpi_gpio_chip *acpi_gpio) 232 + void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) 233 233 { 234 - struct gpio_chip *chip = acpi_gpio->chip; 234 + struct acpi_gpio_chip *acpi_gpio; 235 + acpi_handle handle; 236 + acpi_status status; 235 237 236 - if (!chip->to_irq) 238 + if (!chip->dev || !chip->to_irq) 239 + return; 240 + 241 + handle = ACPI_HANDLE(chip->dev); 242 + if (!handle) 243 + return; 244 + 245 + status = acpi_get_data(handle, acpi_gpio_chip_dh, (void **)&acpi_gpio); 246 + if (ACPI_FAILURE(status)) 237 247 return; 238 248 239 249 INIT_LIST_HEAD(&acpi_gpio->events); ··· 253 243 254 244 /** 255 245 * acpi_gpiochip_free_interrupts() - Free GPIO ACPI event interrupts. 256 - * @acpi_gpio: ACPI GPIO chip 246 + * @chip: GPIO chip 257 247 * 258 248 * Free interrupts associated with GPIO ACPI event method for the given 259 249 * GPIO chip. 260 250 */ 261 - static void acpi_gpiochip_free_interrupts(struct acpi_gpio_chip *acpi_gpio) 251 + void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) 262 252 { 253 + struct acpi_gpio_chip *acpi_gpio; 263 254 struct acpi_gpio_event *event, *ep; 264 - struct gpio_chip *chip = acpi_gpio->chip; 255 + acpi_handle handle; 256 + acpi_status status; 265 257 266 - if (!chip->to_irq) 258 + if (!chip->dev || !chip->to_irq) 259 + return; 260 + 261 + handle = ACPI_HANDLE(chip->dev); 262 + if (!handle) 263 + return; 264 + 265 + status = acpi_get_data(handle, acpi_gpio_chip_dh, (void **)&acpi_gpio); 266 + if (ACPI_FAILURE(status)) 267 267 return; 268 268 269 269 list_for_each_entry_safe_reverse(event, ep, &acpi_gpio->events, node) { ··· 283 263 desc = gpiochip_get_desc(chip, event->pin); 284 264 if (WARN_ON(IS_ERR(desc))) 285 265 continue; 286 - gpiod_unlock_as_irq(desc); 266 + gpio_unlock_as_irq(chip, event->pin); 287 267 gpiochip_free_own_desc(desc); 288 268 list_del(&event->node); 289 269 kfree(event); ··· 545 525 return; 546 526 } 547 527 548 - acpi_gpiochip_request_interrupts(acpi_gpio); 549 528 acpi_gpiochip_request_regions(acpi_gpio); 550 529 } 551 530 ··· 568 549 } 569 550 570 551 acpi_gpiochip_free_regions(acpi_gpio); 571 - acpi_gpiochip_free_interrupts(acpi_gpio); 572 552 573 553 acpi_detach_data(handle, acpi_gpio_chip_dh); 574 554 kfree(acpi_gpio);
+102
drivers/gpio/gpiolib-legacy.c
··· 1 + #include <linux/gpio/consumer.h> 2 + #include <linux/gpio/driver.h> 3 + 4 + #include <linux/gpio.h> 5 + 6 + #include "gpiolib.h" 7 + 8 + void gpio_free(unsigned gpio) 9 + { 10 + gpiod_free(gpio_to_desc(gpio)); 11 + } 12 + EXPORT_SYMBOL_GPL(gpio_free); 13 + 14 + /** 15 + * gpio_request_one - request a single GPIO with initial configuration 16 + * @gpio: the GPIO number 17 + * @flags: GPIO configuration as specified by GPIOF_* 18 + * @label: a literal description string of this GPIO 19 + */ 20 + int gpio_request_one(unsigned gpio, unsigned long flags, const char *label) 21 + { 22 + struct gpio_desc *desc; 23 + int err; 24 + 25 + desc = gpio_to_desc(gpio); 26 + 27 + err = gpiod_request(desc, label); 28 + if (err) 29 + return err; 30 + 31 + if (flags & GPIOF_OPEN_DRAIN) 32 + set_bit(FLAG_OPEN_DRAIN, &desc->flags); 33 + 34 + if (flags & GPIOF_OPEN_SOURCE) 35 + set_bit(FLAG_OPEN_SOURCE, &desc->flags); 36 + 37 + if (flags & GPIOF_ACTIVE_LOW) 38 + set_bit(FLAG_ACTIVE_LOW, &desc->flags); 39 + 40 + if (flags & GPIOF_DIR_IN) 41 + err = gpiod_direction_input(desc); 42 + else 43 + err = gpiod_direction_output_raw(desc, 44 + (flags & GPIOF_INIT_HIGH) ? 1 : 0); 45 + 46 + if (err) 47 + goto free_gpio; 48 + 49 + if (flags & GPIOF_EXPORT) { 50 + err = gpiod_export(desc, flags & GPIOF_EXPORT_CHANGEABLE); 51 + if (err) 52 + goto free_gpio; 53 + } 54 + 55 + return 0; 56 + 57 + free_gpio: 58 + gpiod_free(desc); 59 + return err; 60 + } 61 + EXPORT_SYMBOL_GPL(gpio_request_one); 62 + 63 + int gpio_request(unsigned gpio, const char *label) 64 + { 65 + return gpiod_request(gpio_to_desc(gpio), label); 66 + } 67 + EXPORT_SYMBOL_GPL(gpio_request); 68 + 69 + /** 70 + * gpio_request_array - request multiple GPIOs in a single call 71 + * @array: array of the 'struct gpio' 72 + * @num: how many GPIOs in the array 73 + */ 74 + int gpio_request_array(const struct gpio *array, size_t num) 75 + { 76 + int i, err; 77 + 78 + for (i = 0; i < num; i++, array++) { 79 + err = gpio_request_one(array->gpio, array->flags, array->label); 80 + if (err) 81 + goto err_free; 82 + } 83 + return 0; 84 + 85 + err_free: 86 + while (i--) 87 + gpio_free((--array)->gpio); 88 + return err; 89 + } 90 + EXPORT_SYMBOL_GPL(gpio_request_array); 91 + 92 + /** 93 + * gpio_free_array - release multiple GPIOs in a single call 94 + * @array: array of the 'struct gpio' 95 + * @num: how many GPIOs in the array 96 + */ 97 + void gpio_free_array(const struct gpio *array, size_t num) 98 + { 99 + while (num--) 100 + gpio_free((array++)->gpio); 101 + } 102 + EXPORT_SYMBOL_GPL(gpio_free_array);
+5 -5
drivers/gpio/gpiolib-of.c
··· 23 23 #include <linux/pinctrl/pinctrl.h> 24 24 #include <linux/slab.h> 25 25 26 - struct gpio_desc; 26 + #include "gpiolib.h" 27 27 28 28 /* Private data structure for of_gpiochip_find_and_xlate */ 29 29 struct gg_data { ··· 82 82 ret = of_parse_phandle_with_args(np, propname, "#gpio-cells", index, 83 83 &gg_data.gpiospec); 84 84 if (ret) { 85 - pr_debug("%s: can't parse gpios property of node '%s[%d]'\n", 86 - __func__, np->full_name, index); 85 + pr_debug("%s: can't parse '%s' property of node '%s[%d]'\n", 86 + __func__, propname, np->full_name, index); 87 87 return ERR_PTR(ret); 88 88 } 89 89 90 90 gpiochip_find(&gg_data, of_gpiochip_find_and_xlate); 91 91 92 92 of_node_put(gg_data.gpiospec.np); 93 - pr_debug("%s exited with status %d\n", __func__, 93 + pr_debug("%s: parsed '%s' property of node '%s[%d]' - status (%d)\n", 94 + __func__, propname, np->full_name, index, 94 95 PTR_ERR_OR_ZERO(gg_data.out_gpio)); 95 96 return gg_data.out_gpio; 96 97 } 97 - EXPORT_SYMBOL(of_get_named_gpiod_flags); 98 98 99 99 int of_get_named_gpio_flags(struct device_node *np, const char *list_name, 100 100 int index, enum of_gpio_flags *flags)
+827
drivers/gpio/gpiolib-sysfs.c
··· 1 + #include <linux/idr.h> 2 + #include <linux/mutex.h> 3 + #include <linux/device.h> 4 + #include <linux/sysfs.h> 5 + #include <linux/gpio/consumer.h> 6 + #include <linux/gpio/driver.h> 7 + #include <linux/interrupt.h> 8 + #include <linux/kdev_t.h> 9 + 10 + #include "gpiolib.h" 11 + 12 + static DEFINE_IDR(dirent_idr); 13 + 14 + 15 + /* lock protects against unexport_gpio() being called while 16 + * sysfs files are active. 17 + */ 18 + static DEFINE_MUTEX(sysfs_lock); 19 + 20 + /* 21 + * /sys/class/gpio/gpioN... only for GPIOs that are exported 22 + * /direction 23 + * * MAY BE OMITTED if kernel won't allow direction changes 24 + * * is read/write as "in" or "out" 25 + * * may also be written as "high" or "low", initializing 26 + * output value as specified ("out" implies "low") 27 + * /value 28 + * * always readable, subject to hardware behavior 29 + * * may be writable, as zero/nonzero 30 + * /edge 31 + * * configures behavior of poll(2) on /value 32 + * * available only if pin can generate IRQs on input 33 + * * is read/write as "none", "falling", "rising", or "both" 34 + * /active_low 35 + * * configures polarity of /value 36 + * * is read/write as zero/nonzero 37 + * * also affects existing and subsequent "falling" and "rising" 38 + * /edge configuration 39 + */ 40 + 41 + static ssize_t gpio_direction_show(struct device *dev, 42 + struct device_attribute *attr, char *buf) 43 + { 44 + const struct gpio_desc *desc = dev_get_drvdata(dev); 45 + ssize_t status; 46 + 47 + mutex_lock(&sysfs_lock); 48 + 49 + if (!test_bit(FLAG_EXPORT, &desc->flags)) { 50 + status = -EIO; 51 + } else { 52 + gpiod_get_direction(desc); 53 + status = sprintf(buf, "%s\n", 54 + test_bit(FLAG_IS_OUT, &desc->flags) 55 + ? "out" : "in"); 56 + } 57 + 58 + mutex_unlock(&sysfs_lock); 59 + return status; 60 + } 61 + 62 + static ssize_t gpio_direction_store(struct device *dev, 63 + struct device_attribute *attr, const char *buf, size_t size) 64 + { 65 + struct gpio_desc *desc = dev_get_drvdata(dev); 66 + ssize_t status; 67 + 68 + mutex_lock(&sysfs_lock); 69 + 70 + if (!test_bit(FLAG_EXPORT, &desc->flags)) 71 + status = -EIO; 72 + else if (sysfs_streq(buf, "high")) 73 + status = gpiod_direction_output_raw(desc, 1); 74 + else if (sysfs_streq(buf, "out") || sysfs_streq(buf, "low")) 75 + status = gpiod_direction_output_raw(desc, 0); 76 + else if (sysfs_streq(buf, "in")) 77 + status = gpiod_direction_input(desc); 78 + else 79 + status = -EINVAL; 80 + 81 + mutex_unlock(&sysfs_lock); 82 + return status ? : size; 83 + } 84 + 85 + static /* const */ DEVICE_ATTR(direction, 0644, 86 + gpio_direction_show, gpio_direction_store); 87 + 88 + static ssize_t gpio_value_show(struct device *dev, 89 + struct device_attribute *attr, char *buf) 90 + { 91 + struct gpio_desc *desc = dev_get_drvdata(dev); 92 + ssize_t status; 93 + 94 + mutex_lock(&sysfs_lock); 95 + 96 + if (!test_bit(FLAG_EXPORT, &desc->flags)) 97 + status = -EIO; 98 + else 99 + status = sprintf(buf, "%d\n", gpiod_get_value_cansleep(desc)); 100 + 101 + mutex_unlock(&sysfs_lock); 102 + return status; 103 + } 104 + 105 + static ssize_t gpio_value_store(struct device *dev, 106 + struct device_attribute *attr, const char *buf, size_t size) 107 + { 108 + struct gpio_desc *desc = dev_get_drvdata(dev); 109 + ssize_t status; 110 + 111 + mutex_lock(&sysfs_lock); 112 + 113 + if (!test_bit(FLAG_EXPORT, &desc->flags)) 114 + status = -EIO; 115 + else if (!test_bit(FLAG_IS_OUT, &desc->flags)) 116 + status = -EPERM; 117 + else { 118 + long value; 119 + 120 + status = kstrtol(buf, 0, &value); 121 + if (status == 0) { 122 + gpiod_set_value_cansleep(desc, value); 123 + status = size; 124 + } 125 + } 126 + 127 + mutex_unlock(&sysfs_lock); 128 + return status; 129 + } 130 + 131 + static const DEVICE_ATTR(value, 0644, 132 + gpio_value_show, gpio_value_store); 133 + 134 + static irqreturn_t gpio_sysfs_irq(int irq, void *priv) 135 + { 136 + struct kernfs_node *value_sd = priv; 137 + 138 + sysfs_notify_dirent(value_sd); 139 + return IRQ_HANDLED; 140 + } 141 + 142 + static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev, 143 + unsigned long gpio_flags) 144 + { 145 + struct kernfs_node *value_sd; 146 + unsigned long irq_flags; 147 + int ret, irq, id; 148 + 149 + if ((desc->flags & GPIO_TRIGGER_MASK) == gpio_flags) 150 + return 0; 151 + 152 + irq = gpiod_to_irq(desc); 153 + if (irq < 0) 154 + return -EIO; 155 + 156 + id = desc->flags >> ID_SHIFT; 157 + value_sd = idr_find(&dirent_idr, id); 158 + if (value_sd) 159 + free_irq(irq, value_sd); 160 + 161 + desc->flags &= ~GPIO_TRIGGER_MASK; 162 + 163 + if (!gpio_flags) { 164 + gpio_unlock_as_irq(desc->chip, gpio_chip_hwgpio(desc)); 165 + ret = 0; 166 + goto free_id; 167 + } 168 + 169 + irq_flags = IRQF_SHARED; 170 + if (test_bit(FLAG_TRIG_FALL, &gpio_flags)) 171 + irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? 172 + IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING; 173 + if (test_bit(FLAG_TRIG_RISE, &gpio_flags)) 174 + irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? 175 + IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; 176 + 177 + if (!value_sd) { 178 + value_sd = sysfs_get_dirent(dev->kobj.sd, "value"); 179 + if (!value_sd) { 180 + ret = -ENODEV; 181 + goto err_out; 182 + } 183 + 184 + ret = idr_alloc(&dirent_idr, value_sd, 1, 0, GFP_KERNEL); 185 + if (ret < 0) 186 + goto free_sd; 187 + id = ret; 188 + 189 + desc->flags &= GPIO_FLAGS_MASK; 190 + desc->flags |= (unsigned long)id << ID_SHIFT; 191 + 192 + if (desc->flags >> ID_SHIFT != id) { 193 + ret = -ERANGE; 194 + goto free_id; 195 + } 196 + } 197 + 198 + ret = request_any_context_irq(irq, gpio_sysfs_irq, irq_flags, 199 + "gpiolib", value_sd); 200 + if (ret < 0) 201 + goto free_id; 202 + 203 + ret = gpio_lock_as_irq(desc->chip, gpio_chip_hwgpio(desc)); 204 + if (ret < 0) { 205 + gpiod_warn(desc, "failed to flag the GPIO for IRQ\n"); 206 + goto free_id; 207 + } 208 + 209 + desc->flags |= gpio_flags; 210 + return 0; 211 + 212 + free_id: 213 + idr_remove(&dirent_idr, id); 214 + desc->flags &= GPIO_FLAGS_MASK; 215 + free_sd: 216 + if (value_sd) 217 + sysfs_put(value_sd); 218 + err_out: 219 + return ret; 220 + } 221 + 222 + static const struct { 223 + const char *name; 224 + unsigned long flags; 225 + } trigger_types[] = { 226 + { "none", 0 }, 227 + { "falling", BIT(FLAG_TRIG_FALL) }, 228 + { "rising", BIT(FLAG_TRIG_RISE) }, 229 + { "both", BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE) }, 230 + }; 231 + 232 + static ssize_t gpio_edge_show(struct device *dev, 233 + struct device_attribute *attr, char *buf) 234 + { 235 + const struct gpio_desc *desc = dev_get_drvdata(dev); 236 + ssize_t status; 237 + 238 + mutex_lock(&sysfs_lock); 239 + 240 + if (!test_bit(FLAG_EXPORT, &desc->flags)) 241 + status = -EIO; 242 + else { 243 + int i; 244 + 245 + status = 0; 246 + for (i = 0; i < ARRAY_SIZE(trigger_types); i++) 247 + if ((desc->flags & GPIO_TRIGGER_MASK) 248 + == trigger_types[i].flags) { 249 + status = sprintf(buf, "%s\n", 250 + trigger_types[i].name); 251 + break; 252 + } 253 + } 254 + 255 + mutex_unlock(&sysfs_lock); 256 + return status; 257 + } 258 + 259 + static ssize_t gpio_edge_store(struct device *dev, 260 + struct device_attribute *attr, const char *buf, size_t size) 261 + { 262 + struct gpio_desc *desc = dev_get_drvdata(dev); 263 + ssize_t status; 264 + int i; 265 + 266 + for (i = 0; i < ARRAY_SIZE(trigger_types); i++) 267 + if (sysfs_streq(trigger_types[i].name, buf)) 268 + goto found; 269 + return -EINVAL; 270 + 271 + found: 272 + mutex_lock(&sysfs_lock); 273 + 274 + if (!test_bit(FLAG_EXPORT, &desc->flags)) 275 + status = -EIO; 276 + else { 277 + status = gpio_setup_irq(desc, dev, trigger_types[i].flags); 278 + if (!status) 279 + status = size; 280 + } 281 + 282 + mutex_unlock(&sysfs_lock); 283 + 284 + return status; 285 + } 286 + 287 + static DEVICE_ATTR(edge, 0644, gpio_edge_show, gpio_edge_store); 288 + 289 + static int sysfs_set_active_low(struct gpio_desc *desc, struct device *dev, 290 + int value) 291 + { 292 + int status = 0; 293 + 294 + if (!!test_bit(FLAG_ACTIVE_LOW, &desc->flags) == !!value) 295 + return 0; 296 + 297 + if (value) 298 + set_bit(FLAG_ACTIVE_LOW, &desc->flags); 299 + else 300 + clear_bit(FLAG_ACTIVE_LOW, &desc->flags); 301 + 302 + /* reconfigure poll(2) support if enabled on one edge only */ 303 + if (dev != NULL && (!!test_bit(FLAG_TRIG_RISE, &desc->flags) ^ 304 + !!test_bit(FLAG_TRIG_FALL, &desc->flags))) { 305 + unsigned long trigger_flags = desc->flags & GPIO_TRIGGER_MASK; 306 + 307 + gpio_setup_irq(desc, dev, 0); 308 + status = gpio_setup_irq(desc, dev, trigger_flags); 309 + } 310 + 311 + return status; 312 + } 313 + 314 + static ssize_t gpio_active_low_show(struct device *dev, 315 + struct device_attribute *attr, char *buf) 316 + { 317 + const struct gpio_desc *desc = dev_get_drvdata(dev); 318 + ssize_t status; 319 + 320 + mutex_lock(&sysfs_lock); 321 + 322 + if (!test_bit(FLAG_EXPORT, &desc->flags)) 323 + status = -EIO; 324 + else 325 + status = sprintf(buf, "%d\n", 326 + !!test_bit(FLAG_ACTIVE_LOW, &desc->flags)); 327 + 328 + mutex_unlock(&sysfs_lock); 329 + 330 + return status; 331 + } 332 + 333 + static ssize_t gpio_active_low_store(struct device *dev, 334 + struct device_attribute *attr, const char *buf, size_t size) 335 + { 336 + struct gpio_desc *desc = dev_get_drvdata(dev); 337 + ssize_t status; 338 + 339 + mutex_lock(&sysfs_lock); 340 + 341 + if (!test_bit(FLAG_EXPORT, &desc->flags)) { 342 + status = -EIO; 343 + } else { 344 + long value; 345 + 346 + status = kstrtol(buf, 0, &value); 347 + if (status == 0) 348 + status = sysfs_set_active_low(desc, dev, value != 0); 349 + } 350 + 351 + mutex_unlock(&sysfs_lock); 352 + 353 + return status ? : size; 354 + } 355 + 356 + static const DEVICE_ATTR(active_low, 0644, 357 + gpio_active_low_show, gpio_active_low_store); 358 + 359 + static const struct attribute *gpio_attrs[] = { 360 + &dev_attr_value.attr, 361 + &dev_attr_active_low.attr, 362 + NULL, 363 + }; 364 + 365 + static const struct attribute_group gpio_attr_group = { 366 + .attrs = (struct attribute **) gpio_attrs, 367 + }; 368 + 369 + /* 370 + * /sys/class/gpio/gpiochipN/ 371 + * /base ... matching gpio_chip.base (N) 372 + * /label ... matching gpio_chip.label 373 + * /ngpio ... matching gpio_chip.ngpio 374 + */ 375 + 376 + static ssize_t chip_base_show(struct device *dev, 377 + struct device_attribute *attr, char *buf) 378 + { 379 + const struct gpio_chip *chip = dev_get_drvdata(dev); 380 + 381 + return sprintf(buf, "%d\n", chip->base); 382 + } 383 + static DEVICE_ATTR(base, 0444, chip_base_show, NULL); 384 + 385 + static ssize_t chip_label_show(struct device *dev, 386 + struct device_attribute *attr, char *buf) 387 + { 388 + const struct gpio_chip *chip = dev_get_drvdata(dev); 389 + 390 + return sprintf(buf, "%s\n", chip->label ? : ""); 391 + } 392 + static DEVICE_ATTR(label, 0444, chip_label_show, NULL); 393 + 394 + static ssize_t chip_ngpio_show(struct device *dev, 395 + struct device_attribute *attr, char *buf) 396 + { 397 + const struct gpio_chip *chip = dev_get_drvdata(dev); 398 + 399 + return sprintf(buf, "%u\n", chip->ngpio); 400 + } 401 + static DEVICE_ATTR(ngpio, 0444, chip_ngpio_show, NULL); 402 + 403 + static const struct attribute *gpiochip_attrs[] = { 404 + &dev_attr_base.attr, 405 + &dev_attr_label.attr, 406 + &dev_attr_ngpio.attr, 407 + NULL, 408 + }; 409 + 410 + static const struct attribute_group gpiochip_attr_group = { 411 + .attrs = (struct attribute **) gpiochip_attrs, 412 + }; 413 + 414 + /* 415 + * /sys/class/gpio/export ... write-only 416 + * integer N ... number of GPIO to export (full access) 417 + * /sys/class/gpio/unexport ... write-only 418 + * integer N ... number of GPIO to unexport 419 + */ 420 + static ssize_t export_store(struct class *class, 421 + struct class_attribute *attr, 422 + const char *buf, size_t len) 423 + { 424 + long gpio; 425 + struct gpio_desc *desc; 426 + int status; 427 + 428 + status = kstrtol(buf, 0, &gpio); 429 + if (status < 0) 430 + goto done; 431 + 432 + desc = gpio_to_desc(gpio); 433 + /* reject invalid GPIOs */ 434 + if (!desc) { 435 + pr_warn("%s: invalid GPIO %ld\n", __func__, gpio); 436 + return -EINVAL; 437 + } 438 + 439 + /* No extra locking here; FLAG_SYSFS just signifies that the 440 + * request and export were done by on behalf of userspace, so 441 + * they may be undone on its behalf too. 442 + */ 443 + 444 + status = gpiod_request(desc, "sysfs"); 445 + if (status < 0) { 446 + if (status == -EPROBE_DEFER) 447 + status = -ENODEV; 448 + goto done; 449 + } 450 + status = gpiod_export(desc, true); 451 + if (status < 0) 452 + gpiod_free(desc); 453 + else 454 + set_bit(FLAG_SYSFS, &desc->flags); 455 + 456 + done: 457 + if (status) 458 + pr_debug("%s: status %d\n", __func__, status); 459 + return status ? : len; 460 + } 461 + 462 + static ssize_t unexport_store(struct class *class, 463 + struct class_attribute *attr, 464 + const char *buf, size_t len) 465 + { 466 + long gpio; 467 + struct gpio_desc *desc; 468 + int status; 469 + 470 + status = kstrtol(buf, 0, &gpio); 471 + if (status < 0) 472 + goto done; 473 + 474 + desc = gpio_to_desc(gpio); 475 + /* reject bogus commands (gpio_unexport ignores them) */ 476 + if (!desc) { 477 + pr_warn("%s: invalid GPIO %ld\n", __func__, gpio); 478 + return -EINVAL; 479 + } 480 + 481 + status = -EINVAL; 482 + 483 + /* No extra locking here; FLAG_SYSFS just signifies that the 484 + * request and export were done by on behalf of userspace, so 485 + * they may be undone on its behalf too. 486 + */ 487 + if (test_and_clear_bit(FLAG_SYSFS, &desc->flags)) { 488 + status = 0; 489 + gpiod_free(desc); 490 + } 491 + done: 492 + if (status) 493 + pr_debug("%s: status %d\n", __func__, status); 494 + return status ? : len; 495 + } 496 + 497 + static struct class_attribute gpio_class_attrs[] = { 498 + __ATTR(export, 0200, NULL, export_store), 499 + __ATTR(unexport, 0200, NULL, unexport_store), 500 + __ATTR_NULL, 501 + }; 502 + 503 + static struct class gpio_class = { 504 + .name = "gpio", 505 + .owner = THIS_MODULE, 506 + 507 + .class_attrs = gpio_class_attrs, 508 + }; 509 + 510 + 511 + /** 512 + * gpiod_export - export a GPIO through sysfs 513 + * @gpio: gpio to make available, already requested 514 + * @direction_may_change: true if userspace may change gpio direction 515 + * Context: arch_initcall or later 516 + * 517 + * When drivers want to make a GPIO accessible to userspace after they 518 + * have requested it -- perhaps while debugging, or as part of their 519 + * public interface -- they may use this routine. If the GPIO can 520 + * change direction (some can't) and the caller allows it, userspace 521 + * will see "direction" sysfs attribute which may be used to change 522 + * the gpio's direction. A "value" attribute will always be provided. 523 + * 524 + * Returns zero on success, else an error. 525 + */ 526 + int gpiod_export(struct gpio_desc *desc, bool direction_may_change) 527 + { 528 + unsigned long flags; 529 + int status; 530 + const char *ioname = NULL; 531 + struct device *dev; 532 + int offset; 533 + 534 + /* can't export until sysfs is available ... */ 535 + if (!gpio_class.p) { 536 + pr_debug("%s: called too early!\n", __func__); 537 + return -ENOENT; 538 + } 539 + 540 + if (!desc) { 541 + pr_debug("%s: invalid gpio descriptor\n", __func__); 542 + return -EINVAL; 543 + } 544 + 545 + mutex_lock(&sysfs_lock); 546 + 547 + spin_lock_irqsave(&gpio_lock, flags); 548 + if (!test_bit(FLAG_REQUESTED, &desc->flags) || 549 + test_bit(FLAG_EXPORT, &desc->flags)) { 550 + spin_unlock_irqrestore(&gpio_lock, flags); 551 + gpiod_dbg(desc, "%s: unavailable (requested=%d, exported=%d)\n", 552 + __func__, 553 + test_bit(FLAG_REQUESTED, &desc->flags), 554 + test_bit(FLAG_EXPORT, &desc->flags)); 555 + status = -EPERM; 556 + goto fail_unlock; 557 + } 558 + 559 + if (!desc->chip->direction_input || !desc->chip->direction_output) 560 + direction_may_change = false; 561 + spin_unlock_irqrestore(&gpio_lock, flags); 562 + 563 + offset = gpio_chip_hwgpio(desc); 564 + if (desc->chip->names && desc->chip->names[offset]) 565 + ioname = desc->chip->names[offset]; 566 + 567 + dev = device_create(&gpio_class, desc->chip->dev, MKDEV(0, 0), 568 + desc, ioname ? ioname : "gpio%u", 569 + desc_to_gpio(desc)); 570 + if (IS_ERR(dev)) { 571 + status = PTR_ERR(dev); 572 + goto fail_unlock; 573 + } 574 + 575 + status = sysfs_create_group(&dev->kobj, &gpio_attr_group); 576 + if (status) 577 + goto fail_unregister_device; 578 + 579 + if (direction_may_change) { 580 + status = device_create_file(dev, &dev_attr_direction); 581 + if (status) 582 + goto fail_unregister_device; 583 + } 584 + 585 + if (gpiod_to_irq(desc) >= 0 && (direction_may_change || 586 + !test_bit(FLAG_IS_OUT, &desc->flags))) { 587 + status = device_create_file(dev, &dev_attr_edge); 588 + if (status) 589 + goto fail_unregister_device; 590 + } 591 + 592 + set_bit(FLAG_EXPORT, &desc->flags); 593 + mutex_unlock(&sysfs_lock); 594 + return 0; 595 + 596 + fail_unregister_device: 597 + device_unregister(dev); 598 + fail_unlock: 599 + mutex_unlock(&sysfs_lock); 600 + gpiod_dbg(desc, "%s: status %d\n", __func__, status); 601 + return status; 602 + } 603 + EXPORT_SYMBOL_GPL(gpiod_export); 604 + 605 + static int match_export(struct device *dev, const void *data) 606 + { 607 + return dev_get_drvdata(dev) == data; 608 + } 609 + 610 + /** 611 + * gpiod_export_link - create a sysfs link to an exported GPIO node 612 + * @dev: device under which to create symlink 613 + * @name: name of the symlink 614 + * @gpio: gpio to create symlink to, already exported 615 + * 616 + * Set up a symlink from /sys/.../dev/name to /sys/class/gpio/gpioN 617 + * node. Caller is responsible for unlinking. 618 + * 619 + * Returns zero on success, else an error. 620 + */ 621 + int gpiod_export_link(struct device *dev, const char *name, 622 + struct gpio_desc *desc) 623 + { 624 + int status = -EINVAL; 625 + 626 + if (!desc) { 627 + pr_warn("%s: invalid GPIO\n", __func__); 628 + return -EINVAL; 629 + } 630 + 631 + mutex_lock(&sysfs_lock); 632 + 633 + if (test_bit(FLAG_EXPORT, &desc->flags)) { 634 + struct device *tdev; 635 + 636 + tdev = class_find_device(&gpio_class, NULL, desc, match_export); 637 + if (tdev != NULL) { 638 + status = sysfs_create_link(&dev->kobj, &tdev->kobj, 639 + name); 640 + } else { 641 + status = -ENODEV; 642 + } 643 + } 644 + 645 + mutex_unlock(&sysfs_lock); 646 + 647 + if (status) 648 + gpiod_dbg(desc, "%s: status %d\n", __func__, status); 649 + 650 + return status; 651 + } 652 + EXPORT_SYMBOL_GPL(gpiod_export_link); 653 + 654 + /** 655 + * gpiod_sysfs_set_active_low - set the polarity of gpio sysfs value 656 + * @gpio: gpio to change 657 + * @value: non-zero to use active low, i.e. inverted values 658 + * 659 + * Set the polarity of /sys/class/gpio/gpioN/value sysfs attribute. 660 + * The GPIO does not have to be exported yet. If poll(2) support has 661 + * been enabled for either rising or falling edge, it will be 662 + * reconfigured to follow the new polarity. 663 + * 664 + * Returns zero on success, else an error. 665 + */ 666 + int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value) 667 + { 668 + struct device *dev = NULL; 669 + int status = -EINVAL; 670 + 671 + if (!desc) { 672 + pr_warn("%s: invalid GPIO\n", __func__); 673 + return -EINVAL; 674 + } 675 + 676 + mutex_lock(&sysfs_lock); 677 + 678 + if (test_bit(FLAG_EXPORT, &desc->flags)) { 679 + dev = class_find_device(&gpio_class, NULL, desc, match_export); 680 + if (dev == NULL) { 681 + status = -ENODEV; 682 + goto unlock; 683 + } 684 + } 685 + 686 + status = sysfs_set_active_low(desc, dev, value); 687 + 688 + unlock: 689 + mutex_unlock(&sysfs_lock); 690 + 691 + if (status) 692 + gpiod_dbg(desc, "%s: status %d\n", __func__, status); 693 + 694 + return status; 695 + } 696 + EXPORT_SYMBOL_GPL(gpiod_sysfs_set_active_low); 697 + 698 + /** 699 + * gpiod_unexport - reverse effect of gpio_export() 700 + * @gpio: gpio to make unavailable 701 + * 702 + * This is implicit on gpio_free(). 703 + */ 704 + void gpiod_unexport(struct gpio_desc *desc) 705 + { 706 + int status = 0; 707 + struct device *dev = NULL; 708 + 709 + if (!desc) { 710 + pr_warn("%s: invalid GPIO\n", __func__); 711 + return; 712 + } 713 + 714 + mutex_lock(&sysfs_lock); 715 + 716 + if (test_bit(FLAG_EXPORT, &desc->flags)) { 717 + 718 + dev = class_find_device(&gpio_class, NULL, desc, match_export); 719 + if (dev) { 720 + gpio_setup_irq(desc, dev, 0); 721 + clear_bit(FLAG_EXPORT, &desc->flags); 722 + } else 723 + status = -ENODEV; 724 + } 725 + 726 + mutex_unlock(&sysfs_lock); 727 + 728 + if (dev) { 729 + device_unregister(dev); 730 + put_device(dev); 731 + } 732 + 733 + if (status) 734 + gpiod_dbg(desc, "%s: status %d\n", __func__, status); 735 + } 736 + EXPORT_SYMBOL_GPL(gpiod_unexport); 737 + 738 + int gpiochip_export(struct gpio_chip *chip) 739 + { 740 + int status; 741 + struct device *dev; 742 + 743 + /* Many systems register gpio chips for SOC support very early, 744 + * before driver model support is available. In those cases we 745 + * export this later, in gpiolib_sysfs_init() ... here we just 746 + * verify that _some_ field of gpio_class got initialized. 747 + */ 748 + if (!gpio_class.p) 749 + return 0; 750 + 751 + /* use chip->base for the ID; it's already known to be unique */ 752 + mutex_lock(&sysfs_lock); 753 + dev = device_create(&gpio_class, chip->dev, MKDEV(0, 0), chip, 754 + "gpiochip%d", chip->base); 755 + if (!IS_ERR(dev)) { 756 + status = sysfs_create_group(&dev->kobj, 757 + &gpiochip_attr_group); 758 + } else 759 + status = PTR_ERR(dev); 760 + chip->exported = (status == 0); 761 + mutex_unlock(&sysfs_lock); 762 + 763 + if (status) 764 + chip_dbg(chip, "%s: status %d\n", __func__, status); 765 + 766 + return status; 767 + } 768 + 769 + void gpiochip_unexport(struct gpio_chip *chip) 770 + { 771 + int status; 772 + struct device *dev; 773 + 774 + mutex_lock(&sysfs_lock); 775 + dev = class_find_device(&gpio_class, NULL, chip, match_export); 776 + if (dev) { 777 + put_device(dev); 778 + device_unregister(dev); 779 + chip->exported = false; 780 + status = 0; 781 + } else 782 + status = -ENODEV; 783 + mutex_unlock(&sysfs_lock); 784 + 785 + if (status) 786 + chip_dbg(chip, "%s: status %d\n", __func__, status); 787 + } 788 + 789 + static int __init gpiolib_sysfs_init(void) 790 + { 791 + int status; 792 + unsigned long flags; 793 + struct gpio_chip *chip; 794 + 795 + status = class_register(&gpio_class); 796 + if (status < 0) 797 + return status; 798 + 799 + /* Scan and register the gpio_chips which registered very 800 + * early (e.g. before the class_register above was called). 801 + * 802 + * We run before arch_initcall() so chip->dev nodes can have 803 + * registered, and so arch_initcall() can always gpio_export(). 804 + */ 805 + spin_lock_irqsave(&gpio_lock, flags); 806 + list_for_each_entry(chip, &gpio_chips, list) { 807 + if (chip->exported) 808 + continue; 809 + 810 + /* 811 + * TODO we yield gpio_lock here because gpiochip_export() 812 + * acquires a mutex. This is unsafe and needs to be fixed. 813 + * 814 + * Also it would be nice to use gpiochip_find() here so we 815 + * can keep gpio_chips local to gpiolib.c, but the yield of 816 + * gpio_lock prevents us from doing this. 817 + */ 818 + spin_unlock_irqrestore(&gpio_lock, flags); 819 + status = gpiochip_export(chip); 820 + spin_lock_irqsave(&gpio_lock, flags); 821 + } 822 + spin_unlock_irqrestore(&gpio_lock, flags); 823 + 824 + 825 + return status; 826 + } 827 + postcore_initcall(gpiolib_sysfs_init);
+78 -1197
drivers/gpio/gpiolib.c
··· 14 14 #include <linux/slab.h> 15 15 #include <linux/acpi.h> 16 16 #include <linux/gpio/driver.h> 17 + #include <linux/gpio/machine.h> 17 18 18 19 #include "gpiolib.h" 19 20 ··· 45 44 * While any GPIO is requested, its gpio_chip is not removable; 46 45 * each GPIO's "requested" flag serves as a lock and refcount. 47 46 */ 48 - static DEFINE_SPINLOCK(gpio_lock); 47 + DEFINE_SPINLOCK(gpio_lock); 49 48 50 - struct gpio_desc { 51 - struct gpio_chip *chip; 52 - unsigned long flags; 53 - /* flag symbols are bit numbers */ 54 - #define FLAG_REQUESTED 0 55 - #define FLAG_IS_OUT 1 56 - #define FLAG_EXPORT 2 /* protected by sysfs_lock */ 57 - #define FLAG_SYSFS 3 /* exported via /sys/class/gpio/control */ 58 - #define FLAG_TRIG_FALL 4 /* trigger on falling edge */ 59 - #define FLAG_TRIG_RISE 5 /* trigger on rising edge */ 60 - #define FLAG_ACTIVE_LOW 6 /* value has active low */ 61 - #define FLAG_OPEN_DRAIN 7 /* Gpio is open drain type */ 62 - #define FLAG_OPEN_SOURCE 8 /* Gpio is open source type */ 63 - #define FLAG_USED_AS_IRQ 9 /* GPIO is connected to an IRQ */ 64 - 65 - #define ID_SHIFT 16 /* add new flags before this one */ 66 - 67 - #define GPIO_FLAGS_MASK ((1 << ID_SHIFT) - 1) 68 - #define GPIO_TRIGGER_MASK (BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE)) 69 - 70 - #ifdef CONFIG_DEBUG_FS 71 - const char *label; 72 - #endif 73 - }; 74 49 static struct gpio_desc gpio_desc[ARCH_NR_GPIOS]; 75 50 76 51 #define GPIO_OFFSET_VALID(chip, offset) (offset >= 0 && offset < chip->ngpio) 77 52 78 53 static DEFINE_MUTEX(gpio_lookup_lock); 79 54 static LIST_HEAD(gpio_lookup_list); 80 - static LIST_HEAD(gpio_chips); 81 - 82 - #ifdef CONFIG_GPIO_SYSFS 83 - static DEFINE_IDR(dirent_idr); 84 - #endif 85 - 86 - static int gpiod_request(struct gpio_desc *desc, const char *label); 87 - static void gpiod_free(struct gpio_desc *desc); 88 - 89 - /* With descriptor prefix */ 90 - 91 - #ifdef CONFIG_DEBUG_FS 92 - #define gpiod_emerg(desc, fmt, ...) \ 93 - pr_emerg("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\ 94 - ##__VA_ARGS__) 95 - #define gpiod_crit(desc, fmt, ...) \ 96 - pr_crit("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ 97 - ##__VA_ARGS__) 98 - #define gpiod_err(desc, fmt, ...) \ 99 - pr_err("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ 100 - ##__VA_ARGS__) 101 - #define gpiod_warn(desc, fmt, ...) \ 102 - pr_warn("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ 103 - ##__VA_ARGS__) 104 - #define gpiod_info(desc, fmt, ...) \ 105 - pr_info("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ 106 - ##__VA_ARGS__) 107 - #define gpiod_dbg(desc, fmt, ...) \ 108 - pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\ 109 - ##__VA_ARGS__) 110 - #else 111 - #define gpiod_emerg(desc, fmt, ...) \ 112 - pr_emerg("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) 113 - #define gpiod_crit(desc, fmt, ...) \ 114 - pr_crit("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) 115 - #define gpiod_err(desc, fmt, ...) \ 116 - pr_err("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) 117 - #define gpiod_warn(desc, fmt, ...) \ 118 - pr_warn("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) 119 - #define gpiod_info(desc, fmt, ...) \ 120 - pr_info("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) 121 - #define gpiod_dbg(desc, fmt, ...) \ 122 - pr_debug("gpio-%d: " fmt, desc_to_gpio(desc), ##__VA_ARGS__) 123 - #endif 124 - 125 - /* With chip prefix */ 126 - 127 - #define chip_emerg(chip, fmt, ...) \ 128 - pr_emerg("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__) 129 - #define chip_crit(chip, fmt, ...) \ 130 - pr_crit("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__) 131 - #define chip_err(chip, fmt, ...) \ 132 - pr_err("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__) 133 - #define chip_warn(chip, fmt, ...) \ 134 - pr_warn("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__) 135 - #define chip_info(chip, fmt, ...) \ 136 - pr_info("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__) 137 - #define chip_dbg(chip, fmt, ...) \ 138 - pr_debug("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__) 55 + LIST_HEAD(gpio_chips); 139 56 140 57 static inline void desc_set_label(struct gpio_desc *d, const char *label) 141 58 { 142 - #ifdef CONFIG_DEBUG_FS 143 59 d->label = label; 144 - #endif 145 - } 146 - 147 - /* 148 - * Return the GPIO number of the passed descriptor relative to its chip 149 - */ 150 - static int gpio_chip_hwgpio(const struct gpio_desc *desc) 151 - { 152 - return desc - &desc->chip->desc[0]; 153 60 } 154 61 155 62 /** ··· 83 174 84 175 return &chip->desc[hwnum]; 85 176 } 86 - EXPORT_SYMBOL_GPL(gpiochip_get_desc); 87 177 88 178 /** 89 179 * Convert a GPIO descriptor to the integer namespace. ··· 95 187 } 96 188 EXPORT_SYMBOL_GPL(desc_to_gpio); 97 189 98 - 99 - /* Warn when drivers omit gpio_request() calls -- legal but ill-advised 100 - * when setting direction, and otherwise illegal. Until board setup code 101 - * and drivers use explicit requests everywhere (which won't happen when 102 - * those calls have no teeth) we can't avoid autorequesting. This nag 103 - * message should motivate switching to explicit requests... so should 104 - * the weaker cleanup after faults, compared to gpio_request(). 105 - * 106 - * NOTE: the autorequest mechanism is going away; at this point it's 107 - * only "legal" in the sense that (old) code using it won't break yet, 108 - * but instead only triggers a WARN() stack dump. 109 - */ 110 - static int gpio_ensure_requested(struct gpio_desc *desc) 111 - { 112 - const struct gpio_chip *chip = desc->chip; 113 - const int gpio = desc_to_gpio(desc); 114 - 115 - if (WARN(test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0, 116 - "autorequest GPIO-%d\n", gpio)) { 117 - if (!try_module_get(chip->owner)) { 118 - gpiod_err(desc, "%s: module can't be gotten\n", 119 - __func__); 120 - clear_bit(FLAG_REQUESTED, &desc->flags); 121 - /* lose */ 122 - return -EIO; 123 - } 124 - desc_set_label(desc, "[auto]"); 125 - /* caller must chip->request() w/o spinlock */ 126 - if (chip->request) 127 - return 1; 128 - } 129 - return 0; 130 - } 131 190 132 191 /** 133 192 * gpiod_to_chip - Return the GPIO chip to which a GPIO descriptor belongs ··· 165 290 return status; 166 291 } 167 292 EXPORT_SYMBOL_GPL(gpiod_get_direction); 168 - 169 - #ifdef CONFIG_GPIO_SYSFS 170 - 171 - /* lock protects against unexport_gpio() being called while 172 - * sysfs files are active. 173 - */ 174 - static DEFINE_MUTEX(sysfs_lock); 175 - 176 - /* 177 - * /sys/class/gpio/gpioN... only for GPIOs that are exported 178 - * /direction 179 - * * MAY BE OMITTED if kernel won't allow direction changes 180 - * * is read/write as "in" or "out" 181 - * * may also be written as "high" or "low", initializing 182 - * output value as specified ("out" implies "low") 183 - * /value 184 - * * always readable, subject to hardware behavior 185 - * * may be writable, as zero/nonzero 186 - * /edge 187 - * * configures behavior of poll(2) on /value 188 - * * available only if pin can generate IRQs on input 189 - * * is read/write as "none", "falling", "rising", or "both" 190 - * /active_low 191 - * * configures polarity of /value 192 - * * is read/write as zero/nonzero 193 - * * also affects existing and subsequent "falling" and "rising" 194 - * /edge configuration 195 - */ 196 - 197 - static ssize_t gpio_direction_show(struct device *dev, 198 - struct device_attribute *attr, char *buf) 199 - { 200 - const struct gpio_desc *desc = dev_get_drvdata(dev); 201 - ssize_t status; 202 - 203 - mutex_lock(&sysfs_lock); 204 - 205 - if (!test_bit(FLAG_EXPORT, &desc->flags)) { 206 - status = -EIO; 207 - } else { 208 - gpiod_get_direction(desc); 209 - status = sprintf(buf, "%s\n", 210 - test_bit(FLAG_IS_OUT, &desc->flags) 211 - ? "out" : "in"); 212 - } 213 - 214 - mutex_unlock(&sysfs_lock); 215 - return status; 216 - } 217 - 218 - static ssize_t gpio_direction_store(struct device *dev, 219 - struct device_attribute *attr, const char *buf, size_t size) 220 - { 221 - struct gpio_desc *desc = dev_get_drvdata(dev); 222 - ssize_t status; 223 - 224 - mutex_lock(&sysfs_lock); 225 - 226 - if (!test_bit(FLAG_EXPORT, &desc->flags)) 227 - status = -EIO; 228 - else if (sysfs_streq(buf, "high")) 229 - status = gpiod_direction_output_raw(desc, 1); 230 - else if (sysfs_streq(buf, "out") || sysfs_streq(buf, "low")) 231 - status = gpiod_direction_output_raw(desc, 0); 232 - else if (sysfs_streq(buf, "in")) 233 - status = gpiod_direction_input(desc); 234 - else 235 - status = -EINVAL; 236 - 237 - mutex_unlock(&sysfs_lock); 238 - return status ? : size; 239 - } 240 - 241 - static /* const */ DEVICE_ATTR(direction, 0644, 242 - gpio_direction_show, gpio_direction_store); 243 - 244 - static ssize_t gpio_value_show(struct device *dev, 245 - struct device_attribute *attr, char *buf) 246 - { 247 - struct gpio_desc *desc = dev_get_drvdata(dev); 248 - ssize_t status; 249 - 250 - mutex_lock(&sysfs_lock); 251 - 252 - if (!test_bit(FLAG_EXPORT, &desc->flags)) 253 - status = -EIO; 254 - else 255 - status = sprintf(buf, "%d\n", gpiod_get_value_cansleep(desc)); 256 - 257 - mutex_unlock(&sysfs_lock); 258 - return status; 259 - } 260 - 261 - static ssize_t gpio_value_store(struct device *dev, 262 - struct device_attribute *attr, const char *buf, size_t size) 263 - { 264 - struct gpio_desc *desc = dev_get_drvdata(dev); 265 - ssize_t status; 266 - 267 - mutex_lock(&sysfs_lock); 268 - 269 - if (!test_bit(FLAG_EXPORT, &desc->flags)) 270 - status = -EIO; 271 - else if (!test_bit(FLAG_IS_OUT, &desc->flags)) 272 - status = -EPERM; 273 - else { 274 - long value; 275 - 276 - status = kstrtol(buf, 0, &value); 277 - if (status == 0) { 278 - gpiod_set_value_cansleep(desc, value); 279 - status = size; 280 - } 281 - } 282 - 283 - mutex_unlock(&sysfs_lock); 284 - return status; 285 - } 286 - 287 - static const DEVICE_ATTR(value, 0644, 288 - gpio_value_show, gpio_value_store); 289 - 290 - static irqreturn_t gpio_sysfs_irq(int irq, void *priv) 291 - { 292 - struct kernfs_node *value_sd = priv; 293 - 294 - sysfs_notify_dirent(value_sd); 295 - return IRQ_HANDLED; 296 - } 297 - 298 - static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev, 299 - unsigned long gpio_flags) 300 - { 301 - struct kernfs_node *value_sd; 302 - unsigned long irq_flags; 303 - int ret, irq, id; 304 - 305 - if ((desc->flags & GPIO_TRIGGER_MASK) == gpio_flags) 306 - return 0; 307 - 308 - irq = gpiod_to_irq(desc); 309 - if (irq < 0) 310 - return -EIO; 311 - 312 - id = desc->flags >> ID_SHIFT; 313 - value_sd = idr_find(&dirent_idr, id); 314 - if (value_sd) 315 - free_irq(irq, value_sd); 316 - 317 - desc->flags &= ~GPIO_TRIGGER_MASK; 318 - 319 - if (!gpio_flags) { 320 - gpiod_unlock_as_irq(desc); 321 - ret = 0; 322 - goto free_id; 323 - } 324 - 325 - irq_flags = IRQF_SHARED; 326 - if (test_bit(FLAG_TRIG_FALL, &gpio_flags)) 327 - irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? 328 - IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING; 329 - if (test_bit(FLAG_TRIG_RISE, &gpio_flags)) 330 - irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? 331 - IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; 332 - 333 - if (!value_sd) { 334 - value_sd = sysfs_get_dirent(dev->kobj.sd, "value"); 335 - if (!value_sd) { 336 - ret = -ENODEV; 337 - goto err_out; 338 - } 339 - 340 - ret = idr_alloc(&dirent_idr, value_sd, 1, 0, GFP_KERNEL); 341 - if (ret < 0) 342 - goto free_sd; 343 - id = ret; 344 - 345 - desc->flags &= GPIO_FLAGS_MASK; 346 - desc->flags |= (unsigned long)id << ID_SHIFT; 347 - 348 - if (desc->flags >> ID_SHIFT != id) { 349 - ret = -ERANGE; 350 - goto free_id; 351 - } 352 - } 353 - 354 - ret = request_any_context_irq(irq, gpio_sysfs_irq, irq_flags, 355 - "gpiolib", value_sd); 356 - if (ret < 0) 357 - goto free_id; 358 - 359 - ret = gpiod_lock_as_irq(desc); 360 - if (ret < 0) { 361 - gpiod_warn(desc, "failed to flag the GPIO for IRQ\n"); 362 - goto free_id; 363 - } 364 - 365 - desc->flags |= gpio_flags; 366 - return 0; 367 - 368 - free_id: 369 - idr_remove(&dirent_idr, id); 370 - desc->flags &= GPIO_FLAGS_MASK; 371 - free_sd: 372 - if (value_sd) 373 - sysfs_put(value_sd); 374 - err_out: 375 - return ret; 376 - } 377 - 378 - static const struct { 379 - const char *name; 380 - unsigned long flags; 381 - } trigger_types[] = { 382 - { "none", 0 }, 383 - { "falling", BIT(FLAG_TRIG_FALL) }, 384 - { "rising", BIT(FLAG_TRIG_RISE) }, 385 - { "both", BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE) }, 386 - }; 387 - 388 - static ssize_t gpio_edge_show(struct device *dev, 389 - struct device_attribute *attr, char *buf) 390 - { 391 - const struct gpio_desc *desc = dev_get_drvdata(dev); 392 - ssize_t status; 393 - 394 - mutex_lock(&sysfs_lock); 395 - 396 - if (!test_bit(FLAG_EXPORT, &desc->flags)) 397 - status = -EIO; 398 - else { 399 - int i; 400 - 401 - status = 0; 402 - for (i = 0; i < ARRAY_SIZE(trigger_types); i++) 403 - if ((desc->flags & GPIO_TRIGGER_MASK) 404 - == trigger_types[i].flags) { 405 - status = sprintf(buf, "%s\n", 406 - trigger_types[i].name); 407 - break; 408 - } 409 - } 410 - 411 - mutex_unlock(&sysfs_lock); 412 - return status; 413 - } 414 - 415 - static ssize_t gpio_edge_store(struct device *dev, 416 - struct device_attribute *attr, const char *buf, size_t size) 417 - { 418 - struct gpio_desc *desc = dev_get_drvdata(dev); 419 - ssize_t status; 420 - int i; 421 - 422 - for (i = 0; i < ARRAY_SIZE(trigger_types); i++) 423 - if (sysfs_streq(trigger_types[i].name, buf)) 424 - goto found; 425 - return -EINVAL; 426 - 427 - found: 428 - mutex_lock(&sysfs_lock); 429 - 430 - if (!test_bit(FLAG_EXPORT, &desc->flags)) 431 - status = -EIO; 432 - else { 433 - status = gpio_setup_irq(desc, dev, trigger_types[i].flags); 434 - if (!status) 435 - status = size; 436 - } 437 - 438 - mutex_unlock(&sysfs_lock); 439 - 440 - return status; 441 - } 442 - 443 - static DEVICE_ATTR(edge, 0644, gpio_edge_show, gpio_edge_store); 444 - 445 - static int sysfs_set_active_low(struct gpio_desc *desc, struct device *dev, 446 - int value) 447 - { 448 - int status = 0; 449 - 450 - if (!!test_bit(FLAG_ACTIVE_LOW, &desc->flags) == !!value) 451 - return 0; 452 - 453 - if (value) 454 - set_bit(FLAG_ACTIVE_LOW, &desc->flags); 455 - else 456 - clear_bit(FLAG_ACTIVE_LOW, &desc->flags); 457 - 458 - /* reconfigure poll(2) support if enabled on one edge only */ 459 - if (dev != NULL && (!!test_bit(FLAG_TRIG_RISE, &desc->flags) ^ 460 - !!test_bit(FLAG_TRIG_FALL, &desc->flags))) { 461 - unsigned long trigger_flags = desc->flags & GPIO_TRIGGER_MASK; 462 - 463 - gpio_setup_irq(desc, dev, 0); 464 - status = gpio_setup_irq(desc, dev, trigger_flags); 465 - } 466 - 467 - return status; 468 - } 469 - 470 - static ssize_t gpio_active_low_show(struct device *dev, 471 - struct device_attribute *attr, char *buf) 472 - { 473 - const struct gpio_desc *desc = dev_get_drvdata(dev); 474 - ssize_t status; 475 - 476 - mutex_lock(&sysfs_lock); 477 - 478 - if (!test_bit(FLAG_EXPORT, &desc->flags)) 479 - status = -EIO; 480 - else 481 - status = sprintf(buf, "%d\n", 482 - !!test_bit(FLAG_ACTIVE_LOW, &desc->flags)); 483 - 484 - mutex_unlock(&sysfs_lock); 485 - 486 - return status; 487 - } 488 - 489 - static ssize_t gpio_active_low_store(struct device *dev, 490 - struct device_attribute *attr, const char *buf, size_t size) 491 - { 492 - struct gpio_desc *desc = dev_get_drvdata(dev); 493 - ssize_t status; 494 - 495 - mutex_lock(&sysfs_lock); 496 - 497 - if (!test_bit(FLAG_EXPORT, &desc->flags)) { 498 - status = -EIO; 499 - } else { 500 - long value; 501 - 502 - status = kstrtol(buf, 0, &value); 503 - if (status == 0) 504 - status = sysfs_set_active_low(desc, dev, value != 0); 505 - } 506 - 507 - mutex_unlock(&sysfs_lock); 508 - 509 - return status ? : size; 510 - } 511 - 512 - static const DEVICE_ATTR(active_low, 0644, 513 - gpio_active_low_show, gpio_active_low_store); 514 - 515 - static const struct attribute *gpio_attrs[] = { 516 - &dev_attr_value.attr, 517 - &dev_attr_active_low.attr, 518 - NULL, 519 - }; 520 - 521 - static const struct attribute_group gpio_attr_group = { 522 - .attrs = (struct attribute **) gpio_attrs, 523 - }; 524 - 525 - /* 526 - * /sys/class/gpio/gpiochipN/ 527 - * /base ... matching gpio_chip.base (N) 528 - * /label ... matching gpio_chip.label 529 - * /ngpio ... matching gpio_chip.ngpio 530 - */ 531 - 532 - static ssize_t chip_base_show(struct device *dev, 533 - struct device_attribute *attr, char *buf) 534 - { 535 - const struct gpio_chip *chip = dev_get_drvdata(dev); 536 - 537 - return sprintf(buf, "%d\n", chip->base); 538 - } 539 - static DEVICE_ATTR(base, 0444, chip_base_show, NULL); 540 - 541 - static ssize_t chip_label_show(struct device *dev, 542 - struct device_attribute *attr, char *buf) 543 - { 544 - const struct gpio_chip *chip = dev_get_drvdata(dev); 545 - 546 - return sprintf(buf, "%s\n", chip->label ? : ""); 547 - } 548 - static DEVICE_ATTR(label, 0444, chip_label_show, NULL); 549 - 550 - static ssize_t chip_ngpio_show(struct device *dev, 551 - struct device_attribute *attr, char *buf) 552 - { 553 - const struct gpio_chip *chip = dev_get_drvdata(dev); 554 - 555 - return sprintf(buf, "%u\n", chip->ngpio); 556 - } 557 - static DEVICE_ATTR(ngpio, 0444, chip_ngpio_show, NULL); 558 - 559 - static const struct attribute *gpiochip_attrs[] = { 560 - &dev_attr_base.attr, 561 - &dev_attr_label.attr, 562 - &dev_attr_ngpio.attr, 563 - NULL, 564 - }; 565 - 566 - static const struct attribute_group gpiochip_attr_group = { 567 - .attrs = (struct attribute **) gpiochip_attrs, 568 - }; 569 - 570 - /* 571 - * /sys/class/gpio/export ... write-only 572 - * integer N ... number of GPIO to export (full access) 573 - * /sys/class/gpio/unexport ... write-only 574 - * integer N ... number of GPIO to unexport 575 - */ 576 - static ssize_t export_store(struct class *class, 577 - struct class_attribute *attr, 578 - const char *buf, size_t len) 579 - { 580 - long gpio; 581 - struct gpio_desc *desc; 582 - int status; 583 - 584 - status = kstrtol(buf, 0, &gpio); 585 - if (status < 0) 586 - goto done; 587 - 588 - desc = gpio_to_desc(gpio); 589 - /* reject invalid GPIOs */ 590 - if (!desc) { 591 - pr_warn("%s: invalid GPIO %ld\n", __func__, gpio); 592 - return -EINVAL; 593 - } 594 - 595 - /* No extra locking here; FLAG_SYSFS just signifies that the 596 - * request and export were done by on behalf of userspace, so 597 - * they may be undone on its behalf too. 598 - */ 599 - 600 - status = gpiod_request(desc, "sysfs"); 601 - if (status < 0) { 602 - if (status == -EPROBE_DEFER) 603 - status = -ENODEV; 604 - goto done; 605 - } 606 - status = gpiod_export(desc, true); 607 - if (status < 0) 608 - gpiod_free(desc); 609 - else 610 - set_bit(FLAG_SYSFS, &desc->flags); 611 - 612 - done: 613 - if (status) 614 - pr_debug("%s: status %d\n", __func__, status); 615 - return status ? : len; 616 - } 617 - 618 - static ssize_t unexport_store(struct class *class, 619 - struct class_attribute *attr, 620 - const char *buf, size_t len) 621 - { 622 - long gpio; 623 - struct gpio_desc *desc; 624 - int status; 625 - 626 - status = kstrtol(buf, 0, &gpio); 627 - if (status < 0) 628 - goto done; 629 - 630 - desc = gpio_to_desc(gpio); 631 - /* reject bogus commands (gpio_unexport ignores them) */ 632 - if (!desc) { 633 - pr_warn("%s: invalid GPIO %ld\n", __func__, gpio); 634 - return -EINVAL; 635 - } 636 - 637 - status = -EINVAL; 638 - 639 - /* No extra locking here; FLAG_SYSFS just signifies that the 640 - * request and export were done by on behalf of userspace, so 641 - * they may be undone on its behalf too. 642 - */ 643 - if (test_and_clear_bit(FLAG_SYSFS, &desc->flags)) { 644 - status = 0; 645 - gpiod_free(desc); 646 - } 647 - done: 648 - if (status) 649 - pr_debug("%s: status %d\n", __func__, status); 650 - return status ? : len; 651 - } 652 - 653 - static struct class_attribute gpio_class_attrs[] = { 654 - __ATTR(export, 0200, NULL, export_store), 655 - __ATTR(unexport, 0200, NULL, unexport_store), 656 - __ATTR_NULL, 657 - }; 658 - 659 - static struct class gpio_class = { 660 - .name = "gpio", 661 - .owner = THIS_MODULE, 662 - 663 - .class_attrs = gpio_class_attrs, 664 - }; 665 - 666 - 667 - /** 668 - * gpiod_export - export a GPIO through sysfs 669 - * @gpio: gpio to make available, already requested 670 - * @direction_may_change: true if userspace may change gpio direction 671 - * Context: arch_initcall or later 672 - * 673 - * When drivers want to make a GPIO accessible to userspace after they 674 - * have requested it -- perhaps while debugging, or as part of their 675 - * public interface -- they may use this routine. If the GPIO can 676 - * change direction (some can't) and the caller allows it, userspace 677 - * will see "direction" sysfs attribute which may be used to change 678 - * the gpio's direction. A "value" attribute will always be provided. 679 - * 680 - * Returns zero on success, else an error. 681 - */ 682 - int gpiod_export(struct gpio_desc *desc, bool direction_may_change) 683 - { 684 - unsigned long flags; 685 - int status; 686 - const char *ioname = NULL; 687 - struct device *dev; 688 - int offset; 689 - 690 - /* can't export until sysfs is available ... */ 691 - if (!gpio_class.p) { 692 - pr_debug("%s: called too early!\n", __func__); 693 - return -ENOENT; 694 - } 695 - 696 - if (!desc) { 697 - pr_debug("%s: invalid gpio descriptor\n", __func__); 698 - return -EINVAL; 699 - } 700 - 701 - mutex_lock(&sysfs_lock); 702 - 703 - spin_lock_irqsave(&gpio_lock, flags); 704 - if (!test_bit(FLAG_REQUESTED, &desc->flags) || 705 - test_bit(FLAG_EXPORT, &desc->flags)) { 706 - spin_unlock_irqrestore(&gpio_lock, flags); 707 - gpiod_dbg(desc, "%s: unavailable (requested=%d, exported=%d)\n", 708 - __func__, 709 - test_bit(FLAG_REQUESTED, &desc->flags), 710 - test_bit(FLAG_EXPORT, &desc->flags)); 711 - status = -EPERM; 712 - goto fail_unlock; 713 - } 714 - 715 - if (!desc->chip->direction_input || !desc->chip->direction_output) 716 - direction_may_change = false; 717 - spin_unlock_irqrestore(&gpio_lock, flags); 718 - 719 - offset = gpio_chip_hwgpio(desc); 720 - if (desc->chip->names && desc->chip->names[offset]) 721 - ioname = desc->chip->names[offset]; 722 - 723 - dev = device_create(&gpio_class, desc->chip->dev, MKDEV(0, 0), 724 - desc, ioname ? ioname : "gpio%u", 725 - desc_to_gpio(desc)); 726 - if (IS_ERR(dev)) { 727 - status = PTR_ERR(dev); 728 - goto fail_unlock; 729 - } 730 - 731 - status = sysfs_create_group(&dev->kobj, &gpio_attr_group); 732 - if (status) 733 - goto fail_unregister_device; 734 - 735 - if (direction_may_change) { 736 - status = device_create_file(dev, &dev_attr_direction); 737 - if (status) 738 - goto fail_unregister_device; 739 - } 740 - 741 - if (gpiod_to_irq(desc) >= 0 && (direction_may_change || 742 - !test_bit(FLAG_IS_OUT, &desc->flags))) { 743 - status = device_create_file(dev, &dev_attr_edge); 744 - if (status) 745 - goto fail_unregister_device; 746 - } 747 - 748 - set_bit(FLAG_EXPORT, &desc->flags); 749 - mutex_unlock(&sysfs_lock); 750 - return 0; 751 - 752 - fail_unregister_device: 753 - device_unregister(dev); 754 - fail_unlock: 755 - mutex_unlock(&sysfs_lock); 756 - gpiod_dbg(desc, "%s: status %d\n", __func__, status); 757 - return status; 758 - } 759 - EXPORT_SYMBOL_GPL(gpiod_export); 760 - 761 - static int match_export(struct device *dev, const void *data) 762 - { 763 - return dev_get_drvdata(dev) == data; 764 - } 765 - 766 - /** 767 - * gpiod_export_link - create a sysfs link to an exported GPIO node 768 - * @dev: device under which to create symlink 769 - * @name: name of the symlink 770 - * @gpio: gpio to create symlink to, already exported 771 - * 772 - * Set up a symlink from /sys/.../dev/name to /sys/class/gpio/gpioN 773 - * node. Caller is responsible for unlinking. 774 - * 775 - * Returns zero on success, else an error. 776 - */ 777 - int gpiod_export_link(struct device *dev, const char *name, 778 - struct gpio_desc *desc) 779 - { 780 - int status = -EINVAL; 781 - 782 - if (!desc) { 783 - pr_warn("%s: invalid GPIO\n", __func__); 784 - return -EINVAL; 785 - } 786 - 787 - mutex_lock(&sysfs_lock); 788 - 789 - if (test_bit(FLAG_EXPORT, &desc->flags)) { 790 - struct device *tdev; 791 - 792 - tdev = class_find_device(&gpio_class, NULL, desc, match_export); 793 - if (tdev != NULL) { 794 - status = sysfs_create_link(&dev->kobj, &tdev->kobj, 795 - name); 796 - } else { 797 - status = -ENODEV; 798 - } 799 - } 800 - 801 - mutex_unlock(&sysfs_lock); 802 - 803 - if (status) 804 - gpiod_dbg(desc, "%s: status %d\n", __func__, status); 805 - 806 - return status; 807 - } 808 - EXPORT_SYMBOL_GPL(gpiod_export_link); 809 - 810 - /** 811 - * gpiod_sysfs_set_active_low - set the polarity of gpio sysfs value 812 - * @gpio: gpio to change 813 - * @value: non-zero to use active low, i.e. inverted values 814 - * 815 - * Set the polarity of /sys/class/gpio/gpioN/value sysfs attribute. 816 - * The GPIO does not have to be exported yet. If poll(2) support has 817 - * been enabled for either rising or falling edge, it will be 818 - * reconfigured to follow the new polarity. 819 - * 820 - * Returns zero on success, else an error. 821 - */ 822 - int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value) 823 - { 824 - struct device *dev = NULL; 825 - int status = -EINVAL; 826 - 827 - if (!desc) { 828 - pr_warn("%s: invalid GPIO\n", __func__); 829 - return -EINVAL; 830 - } 831 - 832 - mutex_lock(&sysfs_lock); 833 - 834 - if (test_bit(FLAG_EXPORT, &desc->flags)) { 835 - dev = class_find_device(&gpio_class, NULL, desc, match_export); 836 - if (dev == NULL) { 837 - status = -ENODEV; 838 - goto unlock; 839 - } 840 - } 841 - 842 - status = sysfs_set_active_low(desc, dev, value); 843 - 844 - unlock: 845 - mutex_unlock(&sysfs_lock); 846 - 847 - if (status) 848 - gpiod_dbg(desc, "%s: status %d\n", __func__, status); 849 - 850 - return status; 851 - } 852 - EXPORT_SYMBOL_GPL(gpiod_sysfs_set_active_low); 853 - 854 - /** 855 - * gpiod_unexport - reverse effect of gpio_export() 856 - * @gpio: gpio to make unavailable 857 - * 858 - * This is implicit on gpio_free(). 859 - */ 860 - void gpiod_unexport(struct gpio_desc *desc) 861 - { 862 - int status = 0; 863 - struct device *dev = NULL; 864 - 865 - if (!desc) { 866 - pr_warn("%s: invalid GPIO\n", __func__); 867 - return; 868 - } 869 - 870 - mutex_lock(&sysfs_lock); 871 - 872 - if (test_bit(FLAG_EXPORT, &desc->flags)) { 873 - 874 - dev = class_find_device(&gpio_class, NULL, desc, match_export); 875 - if (dev) { 876 - gpio_setup_irq(desc, dev, 0); 877 - clear_bit(FLAG_EXPORT, &desc->flags); 878 - } else 879 - status = -ENODEV; 880 - } 881 - 882 - mutex_unlock(&sysfs_lock); 883 - 884 - if (dev) { 885 - device_unregister(dev); 886 - put_device(dev); 887 - } 888 - 889 - if (status) 890 - gpiod_dbg(desc, "%s: status %d\n", __func__, status); 891 - } 892 - EXPORT_SYMBOL_GPL(gpiod_unexport); 893 - 894 - static int gpiochip_export(struct gpio_chip *chip) 895 - { 896 - int status; 897 - struct device *dev; 898 - 899 - /* Many systems register gpio chips for SOC support very early, 900 - * before driver model support is available. In those cases we 901 - * export this later, in gpiolib_sysfs_init() ... here we just 902 - * verify that _some_ field of gpio_class got initialized. 903 - */ 904 - if (!gpio_class.p) 905 - return 0; 906 - 907 - /* use chip->base for the ID; it's already known to be unique */ 908 - mutex_lock(&sysfs_lock); 909 - dev = device_create(&gpio_class, chip->dev, MKDEV(0, 0), chip, 910 - "gpiochip%d", chip->base); 911 - if (!IS_ERR(dev)) { 912 - status = sysfs_create_group(&dev->kobj, 913 - &gpiochip_attr_group); 914 - } else 915 - status = PTR_ERR(dev); 916 - chip->exported = (status == 0); 917 - mutex_unlock(&sysfs_lock); 918 - 919 - if (status) { 920 - unsigned long flags; 921 - unsigned gpio; 922 - 923 - spin_lock_irqsave(&gpio_lock, flags); 924 - gpio = 0; 925 - while (gpio < chip->ngpio) 926 - chip->desc[gpio++].chip = NULL; 927 - spin_unlock_irqrestore(&gpio_lock, flags); 928 - 929 - chip_dbg(chip, "%s: status %d\n", __func__, status); 930 - } 931 - 932 - return status; 933 - } 934 - 935 - static void gpiochip_unexport(struct gpio_chip *chip) 936 - { 937 - int status; 938 - struct device *dev; 939 - 940 - mutex_lock(&sysfs_lock); 941 - dev = class_find_device(&gpio_class, NULL, chip, match_export); 942 - if (dev) { 943 - put_device(dev); 944 - device_unregister(dev); 945 - chip->exported = false; 946 - status = 0; 947 - } else 948 - status = -ENODEV; 949 - mutex_unlock(&sysfs_lock); 950 - 951 - if (status) 952 - chip_dbg(chip, "%s: status %d\n", __func__, status); 953 - } 954 - 955 - static int __init gpiolib_sysfs_init(void) 956 - { 957 - int status; 958 - unsigned long flags; 959 - struct gpio_chip *chip; 960 - 961 - status = class_register(&gpio_class); 962 - if (status < 0) 963 - return status; 964 - 965 - /* Scan and register the gpio_chips which registered very 966 - * early (e.g. before the class_register above was called). 967 - * 968 - * We run before arch_initcall() so chip->dev nodes can have 969 - * registered, and so arch_initcall() can always gpio_export(). 970 - */ 971 - spin_lock_irqsave(&gpio_lock, flags); 972 - list_for_each_entry(chip, &gpio_chips, list) { 973 - if (!chip || chip->exported) 974 - continue; 975 - 976 - spin_unlock_irqrestore(&gpio_lock, flags); 977 - status = gpiochip_export(chip); 978 - spin_lock_irqsave(&gpio_lock, flags); 979 - } 980 - spin_unlock_irqrestore(&gpio_lock, flags); 981 - 982 - 983 - return status; 984 - } 985 - postcore_initcall(gpiolib_sysfs_init); 986 - 987 - #else 988 - static inline int gpiochip_export(struct gpio_chip *chip) 989 - { 990 - return 0; 991 - } 992 - 993 - static inline void gpiochip_unexport(struct gpio_chip *chip) 994 - { 995 - } 996 - 997 - #endif /* CONFIG_GPIO_SYSFS */ 998 293 999 294 /* 1000 295 * Add a new chip to the global chips list, keeping the list of chips sorted ··· 519 1474 { 520 1475 unsigned int offset; 521 1476 1477 + acpi_gpiochip_free_interrupts(gpiochip); 1478 + 522 1479 /* Remove all IRQ mappings and delete the domain */ 523 1480 if (gpiochip->irqdomain) { 524 1481 for (offset = 0; offset < gpiochip->ngpio; offset++) ··· 613 1566 */ 614 1567 gpiochip->irq_base = irq_base; 615 1568 } 1569 + 1570 + acpi_gpiochip_request_interrupts(gpiochip); 616 1571 617 1572 return 0; 618 1573 } ··· 789 1740 return status; 790 1741 } 791 1742 792 - static int gpiod_request(struct gpio_desc *desc, const char *label) 1743 + int gpiod_request(struct gpio_desc *desc, const char *label) 793 1744 { 794 1745 int status = -EPROBE_DEFER; 795 1746 struct gpio_chip *chip; ··· 815 1766 816 1767 return status; 817 1768 } 818 - 819 - int gpio_request(unsigned gpio, const char *label) 820 - { 821 - return gpiod_request(gpio_to_desc(gpio), label); 822 - } 823 - EXPORT_SYMBOL_GPL(gpio_request); 824 1769 825 1770 static bool __gpiod_free(struct gpio_desc *desc) 826 1771 { ··· 848 1805 return ret; 849 1806 } 850 1807 851 - static void gpiod_free(struct gpio_desc *desc) 1808 + void gpiod_free(struct gpio_desc *desc) 852 1809 { 853 1810 if (desc && __gpiod_free(desc)) 854 1811 module_put(desc->chip->owner); ··· 856 1813 WARN_ON(extra_checks); 857 1814 } 858 1815 859 - void gpio_free(unsigned gpio) 860 - { 861 - gpiod_free(gpio_to_desc(gpio)); 862 - } 863 - EXPORT_SYMBOL_GPL(gpio_free); 864 - 865 - /** 866 - * gpio_request_one - request a single GPIO with initial configuration 867 - * @gpio: the GPIO number 868 - * @flags: GPIO configuration as specified by GPIOF_* 869 - * @label: a literal description string of this GPIO 870 - */ 871 - int gpio_request_one(unsigned gpio, unsigned long flags, const char *label) 872 - { 873 - struct gpio_desc *desc; 874 - int err; 875 - 876 - desc = gpio_to_desc(gpio); 877 - 878 - err = gpiod_request(desc, label); 879 - if (err) 880 - return err; 881 - 882 - if (flags & GPIOF_OPEN_DRAIN) 883 - set_bit(FLAG_OPEN_DRAIN, &desc->flags); 884 - 885 - if (flags & GPIOF_OPEN_SOURCE) 886 - set_bit(FLAG_OPEN_SOURCE, &desc->flags); 887 - 888 - if (flags & GPIOF_DIR_IN) 889 - err = gpiod_direction_input(desc); 890 - else 891 - err = gpiod_direction_output_raw(desc, 892 - (flags & GPIOF_INIT_HIGH) ? 1 : 0); 893 - 894 - if (err) 895 - goto free_gpio; 896 - 897 - if (flags & GPIOF_EXPORT) { 898 - err = gpiod_export(desc, flags & GPIOF_EXPORT_CHANGEABLE); 899 - if (err) 900 - goto free_gpio; 901 - } 902 - 903 - return 0; 904 - 905 - free_gpio: 906 - gpiod_free(desc); 907 - return err; 908 - } 909 - EXPORT_SYMBOL_GPL(gpio_request_one); 910 - 911 - /** 912 - * gpio_request_array - request multiple GPIOs in a single call 913 - * @array: array of the 'struct gpio' 914 - * @num: how many GPIOs in the array 915 - */ 916 - int gpio_request_array(const struct gpio *array, size_t num) 917 - { 918 - int i, err; 919 - 920 - for (i = 0; i < num; i++, array++) { 921 - err = gpio_request_one(array->gpio, array->flags, array->label); 922 - if (err) 923 - goto err_free; 924 - } 925 - return 0; 926 - 927 - err_free: 928 - while (i--) 929 - gpio_free((--array)->gpio); 930 - return err; 931 - } 932 - EXPORT_SYMBOL_GPL(gpio_request_array); 933 - 934 - /** 935 - * gpio_free_array - release multiple GPIOs in a single call 936 - * @array: array of the 'struct gpio' 937 - * @num: how many GPIOs in the array 938 - */ 939 - void gpio_free_array(const struct gpio *array, size_t num) 940 - { 941 - while (num--) 942 - gpio_free((array++)->gpio); 943 - } 944 - EXPORT_SYMBOL_GPL(gpio_free_array); 945 - 946 1816 /** 947 1817 * gpiochip_is_requested - return string iff signal was requested 948 1818 * @chip: controller managing the signal 949 1819 * @offset: of signal within controller's 0..(ngpio - 1) range 950 1820 * 951 1821 * Returns NULL if the GPIO is not currently requested, else a string. 952 - * If debugfs support is enabled, the string returned is the label passed 953 - * to gpio_request(); otherwise it is a meaningless constant. 1822 + * The string returned is the label passed to gpio_request(); if none has been 1823 + * passed it is a meaningless, non-NULL constant. 954 1824 * 955 1825 * This function is for use by GPIO controller drivers. The label can 956 1826 * help with diagnostics, and knowing that the signal is used as a GPIO ··· 880 1924 881 1925 if (test_bit(FLAG_REQUESTED, &desc->flags) == 0) 882 1926 return NULL; 883 - #ifdef CONFIG_DEBUG_FS 884 1927 return desc->label; 885 - #else 886 - return "?"; 887 - #endif 888 1928 } 889 1929 EXPORT_SYMBOL_GPL(gpiochip_is_requested); 890 1930 ··· 902 1950 903 1951 return __gpiod_request(desc, label); 904 1952 } 1953 + EXPORT_SYMBOL_GPL(gpiochip_request_own_desc); 905 1954 906 1955 /** 907 1956 * gpiochip_free_own_desc - Free GPIO requested by the chip driver ··· 916 1963 if (desc) 917 1964 __gpiod_free(desc); 918 1965 } 1966 + EXPORT_SYMBOL_GPL(gpiochip_free_own_desc); 919 1967 920 1968 /* Drivers MUST set GPIO direction before making get/set calls. In 921 1969 * some cases this is done in early boot, before IRQs are enabled. ··· 938 1984 */ 939 1985 int gpiod_direction_input(struct gpio_desc *desc) 940 1986 { 941 - unsigned long flags; 942 1987 struct gpio_chip *chip; 943 1988 int status = -EINVAL; 944 - int offset; 945 1989 946 1990 if (!desc || !desc->chip) { 947 1991 pr_warn("%s: invalid GPIO\n", __func__); ··· 954 2002 return -EIO; 955 2003 } 956 2004 957 - spin_lock_irqsave(&gpio_lock, flags); 958 - 959 - status = gpio_ensure_requested(desc); 960 - if (status < 0) 961 - goto fail; 962 - 963 - /* now we know the gpio is valid and chip won't vanish */ 964 - 965 - spin_unlock_irqrestore(&gpio_lock, flags); 966 - 967 - might_sleep_if(chip->can_sleep); 968 - 969 - offset = gpio_chip_hwgpio(desc); 970 - if (status) { 971 - status = chip->request(chip, offset); 972 - if (status < 0) { 973 - gpiod_dbg(desc, "%s: chip request fail, %d\n", 974 - __func__, status); 975 - /* and it's not available to anyone else ... 976 - * gpio_request() is the fully clean solution. 977 - */ 978 - goto lose; 979 - } 980 - } 981 - 982 - status = chip->direction_input(chip, offset); 2005 + status = chip->direction_input(chip, gpio_chip_hwgpio(desc)); 983 2006 if (status == 0) 984 2007 clear_bit(FLAG_IS_OUT, &desc->flags); 985 2008 986 2009 trace_gpio_direction(desc_to_gpio(desc), 1, status); 987 - lose: 988 - return status; 989 - fail: 990 - spin_unlock_irqrestore(&gpio_lock, flags); 991 - if (status) 992 - gpiod_dbg(desc, "%s: status %d\n", __func__, status); 2010 + 993 2011 return status; 994 2012 } 995 2013 EXPORT_SYMBOL_GPL(gpiod_direction_input); 996 2014 997 2015 static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value) 998 2016 { 999 - unsigned long flags; 1000 2017 struct gpio_chip *chip; 1001 2018 int status = -EINVAL; 1002 - int offset; 1003 2019 1004 2020 /* GPIOs used for IRQs shall not be set as output */ 1005 2021 if (test_bit(FLAG_USED_AS_IRQ, &desc->flags)) { ··· 993 2073 return -EIO; 994 2074 } 995 2075 996 - spin_lock_irqsave(&gpio_lock, flags); 997 - 998 - status = gpio_ensure_requested(desc); 999 - if (status < 0) 1000 - goto fail; 1001 - 1002 - /* now we know the gpio is valid and chip won't vanish */ 1003 - 1004 - spin_unlock_irqrestore(&gpio_lock, flags); 1005 - 1006 - might_sleep_if(chip->can_sleep); 1007 - 1008 - offset = gpio_chip_hwgpio(desc); 1009 - if (status) { 1010 - status = chip->request(chip, offset); 1011 - if (status < 0) { 1012 - gpiod_dbg(desc, "%s: chip request fail, %d\n", 1013 - __func__, status); 1014 - /* and it's not available to anyone else ... 1015 - * gpio_request() is the fully clean solution. 1016 - */ 1017 - goto lose; 1018 - } 1019 - } 1020 - 1021 - status = chip->direction_output(chip, offset, value); 2076 + status = chip->direction_output(chip, gpio_chip_hwgpio(desc), value); 1022 2077 if (status == 0) 1023 2078 set_bit(FLAG_IS_OUT, &desc->flags); 1024 2079 trace_gpio_value(desc_to_gpio(desc), 0, value); 1025 2080 trace_gpio_direction(desc_to_gpio(desc), 0, status); 1026 - lose: 1027 - return status; 1028 - fail: 1029 - spin_unlock_irqrestore(&gpio_lock, flags); 1030 - if (status) 1031 - gpiod_dbg(desc, "%s: gpio status %d\n", __func__, status); 1032 2081 return status; 1033 2082 } 1034 2083 ··· 1056 2167 */ 1057 2168 int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) 1058 2169 { 1059 - unsigned long flags; 1060 2170 struct gpio_chip *chip; 1061 - int status = -EINVAL; 1062 - int offset; 1063 2171 1064 2172 if (!desc || !desc->chip) { 1065 2173 pr_warn("%s: invalid GPIO\n", __func__); ··· 1071 2185 return -ENOTSUPP; 1072 2186 } 1073 2187 1074 - spin_lock_irqsave(&gpio_lock, flags); 1075 - 1076 - status = gpio_ensure_requested(desc); 1077 - if (status < 0) 1078 - goto fail; 1079 - 1080 - /* now we know the gpio is valid and chip won't vanish */ 1081 - 1082 - spin_unlock_irqrestore(&gpio_lock, flags); 1083 - 1084 - might_sleep_if(chip->can_sleep); 1085 - 1086 - offset = gpio_chip_hwgpio(desc); 1087 - return chip->set_debounce(chip, offset, debounce); 1088 - 1089 - fail: 1090 - spin_unlock_irqrestore(&gpio_lock, flags); 1091 - if (status) 1092 - gpiod_dbg(desc, "%s: status %d\n", __func__, status); 1093 - 1094 - return status; 2188 + return chip->set_debounce(chip, gpio_chip_hwgpio(desc), debounce); 1095 2189 } 1096 2190 EXPORT_SYMBOL_GPL(gpiod_set_debounce); 1097 2191 ··· 1314 2448 EXPORT_SYMBOL_GPL(gpiod_to_irq); 1315 2449 1316 2450 /** 1317 - * gpiod_lock_as_irq() - lock a GPIO to be used as IRQ 1318 - * @gpio: the GPIO line to lock as used for IRQ 2451 + * gpio_lock_as_irq() - lock a GPIO to be used as IRQ 2452 + * @chip: the chip the GPIO to lock belongs to 2453 + * @offset: the offset of the GPIO to lock as IRQ 1319 2454 * 1320 2455 * This is used directly by GPIO drivers that want to lock down 1321 2456 * a certain GPIO line to be used for IRQs. 1322 2457 */ 1323 - int gpiod_lock_as_irq(struct gpio_desc *desc) 2458 + int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset) 1324 2459 { 1325 - if (!desc) 2460 + if (offset >= chip->ngpio) 1326 2461 return -EINVAL; 1327 2462 1328 - if (test_bit(FLAG_IS_OUT, &desc->flags)) { 1329 - gpiod_err(desc, 2463 + if (test_bit(FLAG_IS_OUT, &chip->desc[offset].flags)) { 2464 + chip_err(chip, 1330 2465 "%s: tried to flag a GPIO set as output for IRQ\n", 1331 2466 __func__); 1332 2467 return -EIO; 1333 2468 } 1334 2469 1335 - set_bit(FLAG_USED_AS_IRQ, &desc->flags); 2470 + set_bit(FLAG_USED_AS_IRQ, &chip->desc[offset].flags); 1336 2471 return 0; 1337 - } 1338 - EXPORT_SYMBOL_GPL(gpiod_lock_as_irq); 1339 - 1340 - int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset) 1341 - { 1342 - return gpiod_lock_as_irq(gpiochip_get_desc(chip, offset)); 1343 2472 } 1344 2473 EXPORT_SYMBOL_GPL(gpio_lock_as_irq); 1345 2474 1346 2475 /** 1347 - * gpiod_unlock_as_irq() - unlock a GPIO used as IRQ 1348 - * @gpio: the GPIO line to unlock from IRQ usage 2476 + * gpio_unlock_as_irq() - unlock a GPIO used as IRQ 2477 + * @chip: the chip the GPIO to lock belongs to 2478 + * @offset: the offset of the GPIO to lock as IRQ 1349 2479 * 1350 2480 * This is used directly by GPIO drivers that want to indicate 1351 2481 * that a certain GPIO is no longer used exclusively for IRQ. 1352 2482 */ 1353 - void gpiod_unlock_as_irq(struct gpio_desc *desc) 1354 - { 1355 - if (!desc) 1356 - return; 1357 - 1358 - clear_bit(FLAG_USED_AS_IRQ, &desc->flags); 1359 - } 1360 - EXPORT_SYMBOL_GPL(gpiod_unlock_as_irq); 1361 - 1362 2483 void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset) 1363 2484 { 1364 - return gpiod_unlock_as_irq(gpiochip_get_desc(chip, offset)); 2485 + if (offset >= chip->ngpio) 2486 + return; 2487 + 2488 + clear_bit(FLAG_USED_AS_IRQ, &chip->desc[offset].flags); 1365 2489 } 1366 2490 EXPORT_SYMBOL_GPL(gpio_unlock_as_irq); 1367 2491 ··· 1582 2726 * gpiod_get - obtain a GPIO for a given GPIO function 1583 2727 * @dev: GPIO consumer, can be NULL for system-global GPIOs 1584 2728 * @con_id: function within the GPIO consumer 2729 + * @flags: optional GPIO initialization flags 1585 2730 * 1586 2731 * Return the GPIO descriptor corresponding to the function con_id of device 1587 2732 * dev, -ENOENT if no GPIO has been assigned to the requested function, or 1588 2733 * another IS_ERR() code if an error occured while trying to acquire the GPIO. 1589 2734 */ 1590 - struct gpio_desc *__must_check gpiod_get(struct device *dev, const char *con_id) 2735 + struct gpio_desc *__must_check __gpiod_get(struct device *dev, const char *con_id, 2736 + enum gpiod_flags flags) 1591 2737 { 1592 - return gpiod_get_index(dev, con_id, 0); 2738 + return gpiod_get_index(dev, con_id, 0, flags); 1593 2739 } 1594 - EXPORT_SYMBOL_GPL(gpiod_get); 2740 + EXPORT_SYMBOL_GPL(__gpiod_get); 1595 2741 1596 2742 /** 1597 2743 * gpiod_get_optional - obtain an optional GPIO for a given GPIO function 1598 2744 * @dev: GPIO consumer, can be NULL for system-global GPIOs 1599 2745 * @con_id: function within the GPIO consumer 2746 + * @flags: optional GPIO initialization flags 1600 2747 * 1601 2748 * This is equivalent to gpiod_get(), except that when no GPIO was assigned to 1602 2749 * the requested function it will return NULL. This is convenient for drivers 1603 2750 * that need to handle optional GPIOs. 1604 2751 */ 1605 - struct gpio_desc *__must_check gpiod_get_optional(struct device *dev, 1606 - const char *con_id) 2752 + struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev, 2753 + const char *con_id, 2754 + enum gpiod_flags flags) 1607 2755 { 1608 - return gpiod_get_index_optional(dev, con_id, 0); 2756 + return gpiod_get_index_optional(dev, con_id, 0, flags); 1609 2757 } 1610 - EXPORT_SYMBOL_GPL(gpiod_get_optional); 2758 + EXPORT_SYMBOL_GPL(__gpiod_get_optional); 1611 2759 1612 2760 /** 1613 2761 * gpiod_get_index - obtain a GPIO from a multi-index GPIO function 1614 2762 * @dev: GPIO consumer, can be NULL for system-global GPIOs 1615 2763 * @con_id: function within the GPIO consumer 1616 2764 * @idx: index of the GPIO to obtain in the consumer 2765 + * @flags: optional GPIO initialization flags 1617 2766 * 1618 2767 * This variant of gpiod_get() allows to access GPIOs other than the first 1619 2768 * defined one for functions that define several GPIOs. ··· 1627 2766 * requested function and/or index, or another IS_ERR() code if an error 1628 2767 * occured while trying to acquire the GPIO. 1629 2768 */ 1630 - struct gpio_desc *__must_check gpiod_get_index(struct device *dev, 2769 + struct gpio_desc *__must_check __gpiod_get_index(struct device *dev, 1631 2770 const char *con_id, 1632 - unsigned int idx) 2771 + unsigned int idx, 2772 + enum gpiod_flags flags) 1633 2773 { 1634 2774 struct gpio_desc *desc = NULL; 1635 2775 int status; 1636 - enum gpio_lookup_flags flags = 0; 2776 + enum gpio_lookup_flags lookupflags = 0; 1637 2777 1638 2778 dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id); 1639 2779 1640 2780 /* Using device tree? */ 1641 2781 if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) { 1642 2782 dev_dbg(dev, "using device tree for GPIO lookup\n"); 1643 - desc = of_find_gpio(dev, con_id, idx, &flags); 2783 + desc = of_find_gpio(dev, con_id, idx, &lookupflags); 1644 2784 } else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev)) { 1645 2785 dev_dbg(dev, "using ACPI for GPIO lookup\n"); 1646 - desc = acpi_find_gpio(dev, con_id, idx, &flags); 2786 + desc = acpi_find_gpio(dev, con_id, idx, &lookupflags); 1647 2787 } 1648 2788 1649 2789 /* ··· 1653 2791 */ 1654 2792 if (!desc || desc == ERR_PTR(-ENOENT)) { 1655 2793 dev_dbg(dev, "using lookup tables for GPIO lookup"); 1656 - desc = gpiod_find(dev, con_id, idx, &flags); 2794 + desc = gpiod_find(dev, con_id, idx, &lookupflags); 1657 2795 } 1658 2796 1659 2797 if (IS_ERR(desc)) { ··· 1666 2804 if (status < 0) 1667 2805 return ERR_PTR(status); 1668 2806 1669 - if (flags & GPIO_ACTIVE_LOW) 2807 + if (lookupflags & GPIO_ACTIVE_LOW) 1670 2808 set_bit(FLAG_ACTIVE_LOW, &desc->flags); 1671 - if (flags & GPIO_OPEN_DRAIN) 2809 + if (lookupflags & GPIO_OPEN_DRAIN) 1672 2810 set_bit(FLAG_OPEN_DRAIN, &desc->flags); 1673 - if (flags & GPIO_OPEN_SOURCE) 2811 + if (lookupflags & GPIO_OPEN_SOURCE) 1674 2812 set_bit(FLAG_OPEN_SOURCE, &desc->flags); 2813 + 2814 + /* No particular flag request, return here... */ 2815 + if (flags & GPIOD_FLAGS_BIT_DIR_SET) 2816 + return desc; 2817 + 2818 + /* Process flags */ 2819 + if (flags & GPIOD_FLAGS_BIT_DIR_OUT) 2820 + status = gpiod_direction_output(desc, 2821 + flags & GPIOD_FLAGS_BIT_DIR_VAL); 2822 + else 2823 + status = gpiod_direction_input(desc); 2824 + 2825 + if (status < 0) { 2826 + dev_dbg(dev, "setup of GPIO %s failed\n", con_id); 2827 + gpiod_put(desc); 2828 + return ERR_PTR(status); 2829 + } 1675 2830 1676 2831 return desc; 1677 2832 } 1678 - EXPORT_SYMBOL_GPL(gpiod_get_index); 2833 + EXPORT_SYMBOL_GPL(__gpiod_get_index); 1679 2834 1680 2835 /** 1681 2836 * gpiod_get_index_optional - obtain an optional GPIO from a multi-index GPIO ··· 1700 2821 * @dev: GPIO consumer, can be NULL for system-global GPIOs 1701 2822 * @con_id: function within the GPIO consumer 1702 2823 * @index: index of the GPIO to obtain in the consumer 2824 + * @flags: optional GPIO initialization flags 1703 2825 * 1704 2826 * This is equivalent to gpiod_get_index(), except that when no GPIO with the 1705 2827 * specified index was assigned to the requested function it will return NULL. 1706 2828 * This is convenient for drivers that need to handle optional GPIOs. 1707 2829 */ 1708 - struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev, 2830 + struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev, 1709 2831 const char *con_id, 1710 - unsigned int index) 2832 + unsigned int index, 2833 + enum gpiod_flags flags) 1711 2834 { 1712 2835 struct gpio_desc *desc; 1713 2836 1714 - desc = gpiod_get_index(dev, con_id, index); 2837 + desc = gpiod_get_index(dev, con_id, index, flags); 1715 2838 if (IS_ERR(desc)) { 1716 2839 if (PTR_ERR(desc) == -ENOENT) 1717 2840 return NULL; ··· 1721 2840 1722 2841 return desc; 1723 2842 } 1724 - EXPORT_SYMBOL_GPL(gpiod_get_index_optional); 2843 + EXPORT_SYMBOL_GPL(__gpiod_get_index_optional); 1725 2844 1726 2845 /** 1727 2846 * gpiod_put - dispose of a GPIO descriptor
+102 -3
drivers/gpio/gpiolib.h
··· 31 31 void acpi_gpiochip_add(struct gpio_chip *chip); 32 32 void acpi_gpiochip_remove(struct gpio_chip *chip); 33 33 34 + void acpi_gpiochip_request_interrupts(struct gpio_chip *chip); 35 + void acpi_gpiochip_free_interrupts(struct gpio_chip *chip); 36 + 34 37 struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index, 35 38 struct acpi_gpio_info *info); 36 39 #else 37 40 static inline void acpi_gpiochip_add(struct gpio_chip *chip) { } 38 41 static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { } 42 + 43 + static inline void 44 + acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { } 45 + 46 + static inline void 47 + acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { } 39 48 40 49 static inline struct gpio_desc * 41 50 acpi_get_gpiod_by_index(struct device *dev, int index, ··· 54 45 } 55 46 #endif 56 47 57 - int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label); 58 - void gpiochip_free_own_desc(struct gpio_desc *desc); 59 - 60 48 struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, 61 49 const char *list_name, int index, enum of_gpio_flags *flags); 50 + 51 + struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, u16 hwnum); 52 + 53 + extern struct spinlock gpio_lock; 54 + extern struct list_head gpio_chips; 55 + 56 + struct gpio_desc { 57 + struct gpio_chip *chip; 58 + unsigned long flags; 59 + /* flag symbols are bit numbers */ 60 + #define FLAG_REQUESTED 0 61 + #define FLAG_IS_OUT 1 62 + #define FLAG_EXPORT 2 /* protected by sysfs_lock */ 63 + #define FLAG_SYSFS 3 /* exported via /sys/class/gpio/control */ 64 + #define FLAG_TRIG_FALL 4 /* trigger on falling edge */ 65 + #define FLAG_TRIG_RISE 5 /* trigger on rising edge */ 66 + #define FLAG_ACTIVE_LOW 6 /* value has active low */ 67 + #define FLAG_OPEN_DRAIN 7 /* Gpio is open drain type */ 68 + #define FLAG_OPEN_SOURCE 8 /* Gpio is open source type */ 69 + #define FLAG_USED_AS_IRQ 9 /* GPIO is connected to an IRQ */ 70 + 71 + #define ID_SHIFT 16 /* add new flags before this one */ 72 + 73 + #define GPIO_FLAGS_MASK ((1 << ID_SHIFT) - 1) 74 + #define GPIO_TRIGGER_MASK (BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE)) 75 + 76 + const char *label; 77 + }; 78 + 79 + int gpiod_request(struct gpio_desc *desc, const char *label); 80 + void gpiod_free(struct gpio_desc *desc); 81 + 82 + /* 83 + * Return the GPIO number of the passed descriptor relative to its chip 84 + */ 85 + static int __maybe_unused gpio_chip_hwgpio(const struct gpio_desc *desc) 86 + { 87 + return desc - &desc->chip->desc[0]; 88 + } 89 + 90 + /* With descriptor prefix */ 91 + 92 + #define gpiod_emerg(desc, fmt, ...) \ 93 + pr_emerg("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\ 94 + ##__VA_ARGS__) 95 + #define gpiod_crit(desc, fmt, ...) \ 96 + pr_crit("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ 97 + ##__VA_ARGS__) 98 + #define gpiod_err(desc, fmt, ...) \ 99 + pr_err("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ 100 + ##__VA_ARGS__) 101 + #define gpiod_warn(desc, fmt, ...) \ 102 + pr_warn("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ 103 + ##__VA_ARGS__) 104 + #define gpiod_info(desc, fmt, ...) \ 105 + pr_info("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?", \ 106 + ##__VA_ARGS__) 107 + #define gpiod_dbg(desc, fmt, ...) \ 108 + pr_debug("gpio-%d (%s): " fmt, desc_to_gpio(desc), desc->label ? : "?",\ 109 + ##__VA_ARGS__) 110 + 111 + /* With chip prefix */ 112 + 113 + #define chip_emerg(chip, fmt, ...) \ 114 + pr_emerg("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__) 115 + #define chip_crit(chip, fmt, ...) \ 116 + pr_crit("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__) 117 + #define chip_err(chip, fmt, ...) \ 118 + pr_err("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__) 119 + #define chip_warn(chip, fmt, ...) \ 120 + pr_warn("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__) 121 + #define chip_info(chip, fmt, ...) \ 122 + pr_info("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__) 123 + #define chip_dbg(chip, fmt, ...) \ 124 + pr_debug("GPIO chip %s: " fmt, chip->label, ##__VA_ARGS__) 125 + 126 + #ifdef CONFIG_GPIO_SYSFS 127 + 128 + int gpiochip_export(struct gpio_chip *chip); 129 + void gpiochip_unexport(struct gpio_chip *chip); 130 + 131 + #else 132 + 133 + static inline int gpiochip_export(struct gpio_chip *chip) 134 + { 135 + return 0; 136 + } 137 + 138 + static inline void gpiochip_unexport(struct gpio_chip *chip) 139 + { 140 + } 141 + 142 + #endif /* CONFIG_GPIO_SYSFS */ 62 143 63 144 #endif /* GPIOLIB_H */
-3
include/asm-generic/gpio.h
··· 110 110 return gpiod_to_irq(gpio_to_desc(gpio)); 111 111 } 112 112 113 - extern int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset); 114 - extern void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset); 115 - 116 113 extern int gpio_request_one(unsigned gpio, unsigned long flags, const char *label); 117 114 extern int gpio_request_array(const struct gpio *array, size_t num); 118 115 extern void gpio_free_array(const struct gpio *array, size_t num);
+65 -16
include/linux/gpio/consumer.h
··· 18 18 19 19 #ifdef CONFIG_GPIOLIB 20 20 21 + #define GPIOD_FLAGS_BIT_DIR_SET BIT(0) 22 + #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) 23 + #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) 24 + 25 + /** 26 + * Optional flags that can be passed to one of gpiod_* to configure direction 27 + * and output value. These values cannot be OR'd. 28 + */ 29 + enum gpiod_flags { 30 + GPIOD_ASIS = 0, 31 + GPIOD_IN = GPIOD_FLAGS_BIT_DIR_SET, 32 + GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, 33 + GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | 34 + GPIOD_FLAGS_BIT_DIR_VAL, 35 + }; 36 + 21 37 /* Acquire and dispose GPIOs */ 22 - struct gpio_desc *__must_check gpiod_get(struct device *dev, 23 - const char *con_id); 24 - struct gpio_desc *__must_check gpiod_get_index(struct device *dev, 38 + struct gpio_desc *__must_check __gpiod_get(struct device *dev, 39 + const char *con_id, 40 + enum gpiod_flags flags); 41 + #define __gpiod_get(dev, con_id, flags, ...) __gpiod_get(dev, con_id, flags) 42 + #define gpiod_get(varargs...) __gpiod_get(varargs, 0) 43 + struct gpio_desc *__must_check __gpiod_get_index(struct device *dev, 25 44 const char *con_id, 26 - unsigned int idx); 27 - struct gpio_desc *__must_check gpiod_get_optional(struct device *dev, 28 - const char *con_id); 29 - struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev, 45 + unsigned int idx, 46 + enum gpiod_flags flags); 47 + #define __gpiod_get_index(dev, con_id, index, flags, ...) \ 48 + __gpiod_get_index(dev, con_id, index, flags) 49 + #define gpiod_get_index(varargs...) __gpiod_get_index(varargs, 0) 50 + struct gpio_desc *__must_check __gpiod_get_optional(struct device *dev, 51 + const char *con_id, 52 + enum gpiod_flags flags); 53 + #define __gpiod_get_optional(dev, con_id, flags, ...) \ 54 + __gpiod_get_optional(dev, con_id, flags) 55 + #define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, 0) 56 + struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev, 30 57 const char *con_id, 31 - unsigned int index); 58 + unsigned int index, 59 + enum gpiod_flags flags); 60 + #define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \ 61 + __gpiod_get_index_optional(dev, con_id, index, flags) 62 + #define gpiod_get_index_optional(varargs...) \ 63 + __gpiod_get_index_optional(varargs, 0) 32 64 33 65 void gpiod_put(struct gpio_desc *desc); 34 66 35 - struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, 36 - const char *con_id); 37 - struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, 67 + struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, 68 + const char *con_id, 69 + enum gpiod_flags flags); 70 + #define __devm_gpiod_get(dev, con_id, flags, ...) \ 71 + __devm_gpiod_get(dev, con_id, flags) 72 + #define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, 0) 73 + struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev, 38 74 const char *con_id, 39 - unsigned int idx); 40 - struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev, 41 - const char *con_id); 75 + unsigned int idx, 76 + enum gpiod_flags flags); 77 + #define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \ 78 + __devm_gpiod_get_index(dev, con_id, index, flags) 79 + #define devm_gpiod_get_index(varargs...) __devm_gpiod_get_index(varargs, 0) 80 + struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev, 81 + const char *con_id, 82 + enum gpiod_flags flags); 83 + #define __devm_gpiod_get_optional(dev, con_id, flags, ...) \ 84 + __devm_gpiod_get_optional(dev, con_id, flags) 85 + #define devm_gpiod_get_optional(varargs...) \ 86 + __devm_gpiod_get_optional(varargs, 0) 42 87 struct gpio_desc *__must_check 43 - devm_gpiod_get_index_optional(struct device *dev, const char *con_id, 44 - unsigned int index); 88 + __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, 89 + unsigned int index, enum gpiod_flags flags); 90 + #define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \ 91 + __devm_gpiod_get_index_optional(dev, con_id, index, flags) 92 + #define devm_gpiod_get_index_optional(varargs...) \ 93 + __devm_gpiod_get_index_optional(varargs, 0) 45 94 46 95 void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); 47 96
+6 -60
include/linux/gpio/driver.h
··· 141 141 142 142 /* add/remove chips */ 143 143 extern int gpiochip_add(struct gpio_chip *chip); 144 - extern int __must_check gpiochip_remove(struct gpio_chip *chip); 144 + extern int gpiochip_remove(struct gpio_chip *chip); 145 145 extern struct gpio_chip *gpiochip_find(void *data, 146 146 int (*match)(struct gpio_chip *chip, void *data)); 147 147 148 148 /* lock/unlock as IRQ */ 149 - int gpiod_lock_as_irq(struct gpio_desc *desc); 150 - void gpiod_unlock_as_irq(struct gpio_desc *desc); 149 + int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset); 150 + void gpio_unlock_as_irq(struct gpio_chip *chip, unsigned int offset); 151 151 152 152 struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); 153 - 154 - struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, 155 - u16 hwnum); 156 - 157 - enum gpio_lookup_flags { 158 - GPIO_ACTIVE_HIGH = (0 << 0), 159 - GPIO_ACTIVE_LOW = (1 << 0), 160 - GPIO_OPEN_DRAIN = (1 << 1), 161 - GPIO_OPEN_SOURCE = (1 << 2), 162 - }; 163 - 164 - /** 165 - * struct gpiod_lookup - lookup table 166 - * @chip_label: name of the chip the GPIO belongs to 167 - * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO 168 - * @con_id: name of the GPIO from the device's point of view 169 - * @idx: index of the GPIO in case several GPIOs share the same name 170 - * @flags: mask of GPIO_* values 171 - * 172 - * gpiod_lookup is a lookup table for associating GPIOs to specific devices and 173 - * functions using platform data. 174 - */ 175 - struct gpiod_lookup { 176 - const char *chip_label; 177 - u16 chip_hwnum; 178 - const char *con_id; 179 - unsigned int idx; 180 - enum gpio_lookup_flags flags; 181 - }; 182 - 183 - struct gpiod_lookup_table { 184 - struct list_head list; 185 - const char *dev_id; 186 - struct gpiod_lookup table[]; 187 - }; 188 - 189 - /* 190 - * Simple definition of a single GPIO under a con_id 191 - */ 192 - #define GPIO_LOOKUP(_chip_label, _chip_hwnum, _con_id, _flags) \ 193 - GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, 0, _flags) 194 - 195 - /* 196 - * Use this macro if you need to have several GPIOs under the same con_id. 197 - * Each GPIO needs to use a different index and can be accessed using 198 - * gpiod_get_index() 199 - */ 200 - #define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, _idx, _flags) \ 201 - { \ 202 - .chip_label = _chip_label, \ 203 - .chip_hwnum = _chip_hwnum, \ 204 - .con_id = _con_id, \ 205 - .idx = _idx, \ 206 - .flags = _flags, \ 207 - } 208 - 209 - void gpiod_add_lookup_table(struct gpiod_lookup_table *table); 210 153 211 154 #ifdef CONFIG_GPIOLIB_IRQCHIP 212 155 ··· 165 222 unsigned int type); 166 223 167 224 #endif /* CONFIG_GPIO_IRQCHIP */ 225 + 226 + int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label); 227 + void gpiochip_free_own_desc(struct gpio_desc *desc); 168 228 169 229 #else /* CONFIG_GPIOLIB */ 170 230
+61
include/linux/gpio/machine.h
··· 1 + #ifndef __LINUX_GPIO_MACHINE_H 2 + #define __LINUX_GPIO_MACHINE_H 3 + 4 + #include <linux/types.h> 5 + #include <linux/list.h> 6 + 7 + enum gpio_lookup_flags { 8 + GPIO_ACTIVE_HIGH = (0 << 0), 9 + GPIO_ACTIVE_LOW = (1 << 0), 10 + GPIO_OPEN_DRAIN = (1 << 1), 11 + GPIO_OPEN_SOURCE = (1 << 2), 12 + }; 13 + 14 + /** 15 + * struct gpiod_lookup - lookup table 16 + * @chip_label: name of the chip the GPIO belongs to 17 + * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO 18 + * @con_id: name of the GPIO from the device's point of view 19 + * @idx: index of the GPIO in case several GPIOs share the same name 20 + * @flags: mask of GPIO_* values 21 + * 22 + * gpiod_lookup is a lookup table for associating GPIOs to specific devices and 23 + * functions using platform data. 24 + */ 25 + struct gpiod_lookup { 26 + const char *chip_label; 27 + u16 chip_hwnum; 28 + const char *con_id; 29 + unsigned int idx; 30 + enum gpio_lookup_flags flags; 31 + }; 32 + 33 + struct gpiod_lookup_table { 34 + struct list_head list; 35 + const char *dev_id; 36 + struct gpiod_lookup table[]; 37 + }; 38 + 39 + /* 40 + * Simple definition of a single GPIO under a con_id 41 + */ 42 + #define GPIO_LOOKUP(_chip_label, _chip_hwnum, _con_id, _flags) \ 43 + GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, 0, _flags) 44 + 45 + /* 46 + * Use this macro if you need to have several GPIOs under the same con_id. 47 + * Each GPIO needs to use a different index and can be accessed using 48 + * gpiod_get_index() 49 + */ 50 + #define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, _idx, _flags) \ 51 + { \ 52 + .chip_label = _chip_label, \ 53 + .chip_hwnum = _chip_hwnum, \ 54 + .con_id = _con_id, \ 55 + .idx = _idx, \ 56 + .flags = _flags, \ 57 + } 58 + 59 + void gpiod_add_lookup_table(struct gpiod_lookup_table *table); 60 + 61 + #endif /* __LINUX_GPIO_MACHINE_H */