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

Configure Feed

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

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

Pull GPIO updates from Linus Walleij:
"This is the bulk of GPIO development for the v5.7 kernel cycle.

Core and userspace API:

- The userspace API KFIFOs have been imoproved with locks that do not
block interrupts. This makes us better at getting events to
userspace without blocking or disturbing new events arriving in the
same time. This was reviewed by the KFIFO maintainer Stefani. This
is a generic improvement which paves the road for similar
improvements in other subsystems.

- We provide a new ioctl() for monitoring changes in the line
information, such as when multiple clients are taking lines and
giving them back, possibly reconfiguring them in the process: we
can now monitor that and not get stuck with stale static
information.

- An example tool 'gpio-watch' is provided to showcase this
functionality.

- Timestamps for events are switched to ktime_get_ns() which is
monotonic. We previously had a 'realtime' stamp which could move
forward and *backward* in time, which probably would just cause
silent bugs and weird behaviour. In the long run we see two
relevant timestamps: ktime_get_ns() or the timestamp sometimes
provided by the GPIO hardware itself, if that exists.

- Device Tree overlay support for GPIO hogs. On systems that load
overlays, these overlays can now contain hogs, and will then be
respected.

- Handle pin control interaction with nonexisting pin ranges in the
GPIO library core instead of in the individual drivers.

New drivers:

- New driver for the Mellanox BlueField 2 GPIO controller.

Driver improvements:

- Introduce the BGPIOF_NO_SET_ON_INPUT flag to the generic MMIO GPIO
library and use this flag in the MT7621 driver.

- Texas Instruments OMAP CPU power management improvements, such as
blocking of idle on pending GPIO interrupts"

* tag 'gpio-v5.7-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (59 commits)
Revert "gpio: eic-sprd: Use devm_platform_ioremap_resource()"
pinctrl: Unconditionally assign .request()/.free()
gpio: Unconditionally assign .request()/.free()
gpio: export of_pinctrl_get to modules
pinctrl: Define of_pinctrl_get() dummy for !PINCTRL
gpio: Rename variable in core APIs
gpio: Avoid using pin ranges with !PINCTRL
gpiolib: Remove unused gpio_chip parameter from gpio_set_bias()
gpiolib: Pass gpio_desc to gpio_set_config()
gpiolib: Introduce gpiod_set_config()
tools: gpio: Fix out-of-tree build regression
gpio: gpiolib: fix a doc warning
gpio: tegra186: Add Tegra194 pin ranges for GG.0 and GG.1
gpio: tegra186: Add support for pin ranges
gpio: Support GPIO controllers without pin-ranges
ARM: integrator: impd1: Use GPIO_LOOKUP() helper macro
gpio: brcmstb: support gpio-line-names property
tools: gpio: Fix typo in gpio-utils
tools: gpio-hammer: Apply scripts/Lindent and retain good changes
gpiolib: gpio_name_to_desc: factor out !name check
...

+1817 -777
+2 -2
Documentation/driver-api/gpio/driver.rst
··· 416 416 struct gpio_irq_chip inside struct gpio_chip before adding the gpio_chip. 417 417 If you do this, the additional irq_chip will be set up by gpiolib at the 418 418 same time as setting up the rest of the GPIO functionality. The following 419 - is a typical example of a cascaded interrupt handler using gpio_irq_chip:: 419 + is a typical example of a cascaded interrupt handler using gpio_irq_chip: 420 420 421 421 .. code-block:: c 422 422 ··· 453 453 return devm_gpiochip_add_data(dev, &g->gc, g); 454 454 455 455 The helper support using hierarchical interrupt controllers as well. 456 - In this case the typical set-up will look like this:: 456 + In this case the typical set-up will look like this: 457 457 458 458 .. code-block:: c 459 459
+4 -7
arch/arm/mach-integrator/impd1.c
··· 410 410 * 5 = Key lower right 411 411 */ 412 412 /* We need the two MMCI GPIO entries */ 413 - lookup->table[0].chip_label = chipname; 414 - lookup->table[0].chip_hwnum = 3; 415 - lookup->table[0].con_id = "wp"; 416 - lookup->table[1].chip_label = chipname; 417 - lookup->table[1].chip_hwnum = 4; 418 - lookup->table[1].con_id = "cd"; 419 - lookup->table[1].flags = GPIO_ACTIVE_LOW; 413 + lookup->table[0] = (struct gpiod_lookup) 414 + GPIO_LOOKUP(chipname, 3, "wp", 0); 415 + lookup->table[1] = (struct gpiod_lookup) 416 + GPIO_LOOKUP(chipname, 4, "cd", GPIO_ACTIVE_LOW); 420 417 gpiod_add_lookup_table(lookup); 421 418 } 422 419
+7 -2
arch/arm/mach-omap2/cpuidle34xx.c
··· 109 109 int index) 110 110 { 111 111 struct omap3_idle_statedata *cx = &omap3_idle_data[index]; 112 + int error; 112 113 113 114 if (omap_irq_pending() || need_resched()) 114 115 goto return_sleep_time; ··· 126 125 * Call idle CPU PM enter notifier chain so that 127 126 * VFP context is saved. 128 127 */ 129 - if (cx->mpu_state == PWRDM_POWER_OFF) 130 - cpu_pm_enter(); 128 + if (cx->mpu_state == PWRDM_POWER_OFF) { 129 + error = cpu_pm_enter(); 130 + if (error) 131 + goto out_clkdm_set; 132 + } 131 133 132 134 /* Execute ARM wfi */ 133 135 omap_sram_idle(); ··· 143 139 pwrdm_read_prev_pwrst(mpu_pd) == PWRDM_POWER_OFF) 144 140 cpu_pm_exit(); 145 141 142 + out_clkdm_set: 146 143 /* Re-allow idle for C1 */ 147 144 if (cx->flags & OMAP_CPUIDLE_CX_NO_CLKDM_IDLE) 148 145 clkdm_allow_idle(mpu_pd->pwrdm_clkdms[0]);
+17 -9
arch/arm/mach-omap2/cpuidle44xx.c
··· 122 122 { 123 123 struct idle_statedata *cx = state_ptr + index; 124 124 u32 mpuss_can_lose_context = 0; 125 + int error; 125 126 126 127 /* 127 128 * CPU0 has to wait and stay ON until CPU1 is OFF state. ··· 160 159 * Call idle CPU PM enter notifier chain so that 161 160 * VFP and per CPU interrupt context is saved. 162 161 */ 163 - cpu_pm_enter(); 162 + error = cpu_pm_enter(); 163 + if (error) 164 + goto cpu_pm_out; 164 165 165 166 if (dev->cpu == 0) { 166 167 pwrdm_set_logic_retst(mpu_pd, cx->mpu_logic_state); ··· 172 169 * Call idle CPU cluster PM enter notifier chain 173 170 * to save GIC and wakeupgen context. 174 171 */ 175 - if (mpuss_can_lose_context) 176 - cpu_cluster_pm_enter(); 172 + if (mpuss_can_lose_context) { 173 + error = cpu_cluster_pm_enter(); 174 + if (error) 175 + goto cpu_cluster_pm_out; 176 + } 177 177 } 178 178 179 179 omap4_enter_lowpower(dev->cpu, cx->cpu_state); 180 180 cpu_done[dev->cpu] = true; 181 181 182 + cpu_cluster_pm_out: 182 183 /* Wakeup CPU1 only if it is not offlined */ 183 184 if (dev->cpu == 0 && cpumask_test_cpu(1, cpu_online_mask)) { 184 185 ··· 205 198 } 206 199 207 200 /* 208 - * Call idle CPU PM exit notifier chain to restore 209 - * VFP and per CPU IRQ context. 210 - */ 211 - cpu_pm_exit(); 212 - 213 - /* 214 201 * Call idle CPU cluster PM exit notifier chain 215 202 * to restore GIC and wakeupgen context. 216 203 */ 217 204 if (dev->cpu == 0 && mpuss_can_lose_context) 218 205 cpu_cluster_pm_exit(); 219 206 207 + /* 208 + * Call idle CPU PM exit notifier chain to restore 209 + * VFP and per CPU IRQ context. 210 + */ 211 + cpu_pm_exit(); 212 + 213 + cpu_pm_out: 220 214 tick_broadcast_exit(); 221 215 222 216 fail:
+6 -2
arch/arm/mach-omap2/pm34xx.c
··· 191 191 int per_next_state = PWRDM_POWER_ON; 192 192 int core_next_state = PWRDM_POWER_ON; 193 193 u32 sdrc_pwr = 0; 194 + int error; 194 195 195 196 mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm); 196 197 switch (mpu_next_state) { ··· 220 219 pwrdm_pre_transition(NULL); 221 220 222 221 /* PER */ 223 - if (per_next_state == PWRDM_POWER_OFF) 224 - cpu_cluster_pm_enter(); 222 + if (per_next_state == PWRDM_POWER_OFF) { 223 + error = cpu_cluster_pm_enter(); 224 + if (error) 225 + return; 226 + } 225 227 226 228 /* CORE */ 227 229 if (core_next_state < PWRDM_POWER_ON) {
+9 -2
drivers/gpio/Kconfig
··· 394 394 395 395 config GPIO_MXC 396 396 def_bool y 397 - depends on ARCH_MXC 397 + depends on ARCH_MXC || COMPILE_TEST 398 398 select GPIO_GENERIC 399 399 select GENERIC_IRQ_CHIP 400 400 401 401 config GPIO_MXS 402 402 def_bool y 403 - depends on ARCH_MXS 403 + depends on ARCH_MXS || COMPILE_TEST 404 404 select GPIO_GENERIC 405 405 select GENERIC_IRQ_CHIP 406 406 ··· 1398 1398 select GPIO_GENERIC 1399 1399 help 1400 1400 Say Y here if you want GPIO support on Mellanox BlueField SoC. 1401 + 1402 + config GPIO_MLXBF2 1403 + tristate "Mellanox BlueField 2 SoC GPIO" 1404 + depends on (MELLANOX_PLATFORM && ARM64 && ACPI) || (64BIT && COMPILE_TEST) 1405 + select GPIO_GENERIC 1406 + help 1407 + Say Y here if you want GPIO support on Mellanox BlueField 2 SoC. 1401 1408 1402 1409 config GPIO_ML_IOH 1403 1410 tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support"
+1
drivers/gpio/Makefile
··· 93 93 obj-$(CONFIG_GPIO_MERRIFIELD) += gpio-merrifield.o 94 94 obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o 95 95 obj-$(CONFIG_GPIO_MLXBF) += gpio-mlxbf.o 96 + obj-$(CONFIG_GPIO_MLXBF2) += gpio-mlxbf2.o 96 97 obj-$(CONFIG_GPIO_MM_LANTIQ) += gpio-mm-lantiq.o 97 98 obj-$(CONFIG_GPIO_MOCKUP) += gpio-mockup.o 98 99 obj-$(CONFIG_GPIO_MOXTET) += gpio-moxtet.o
+44
drivers/gpio/gpio-brcmstb.c
··· 603 603 .resume_noirq = brcmstb_gpio_resume, 604 604 }; 605 605 606 + static void brcmstb_gpio_set_names(struct device *dev, 607 + struct brcmstb_gpio_bank *bank) 608 + { 609 + struct device_node *np = dev->of_node; 610 + const char **names; 611 + int nstrings, base; 612 + unsigned int i; 613 + 614 + base = bank->id * MAX_GPIO_PER_BANK; 615 + 616 + nstrings = of_property_count_strings(np, "gpio-line-names"); 617 + if (nstrings <= base) 618 + /* Line names not present */ 619 + return; 620 + 621 + names = devm_kcalloc(dev, MAX_GPIO_PER_BANK, sizeof(*names), 622 + GFP_KERNEL); 623 + if (!names) 624 + return; 625 + 626 + /* 627 + * Make sure to not index beyond the end of the number of descriptors 628 + * of the GPIO device. 629 + */ 630 + for (i = 0; i < bank->width; i++) { 631 + const char *name; 632 + int ret; 633 + 634 + ret = of_property_read_string_index(np, "gpio-line-names", 635 + base + i, &name); 636 + if (ret) { 637 + if (ret != -ENODATA) 638 + dev_err(dev, "unable to name line %d: %d\n", 639 + base + i, ret); 640 + break; 641 + } 642 + if (*name) 643 + names[i] = name; 644 + } 645 + 646 + bank->gc.names = names; 647 + } 648 + 606 649 static int brcmstb_gpio_probe(struct platform_device *pdev) 607 650 { 608 651 struct device *dev = &pdev->dev; ··· 769 726 need_wakeup_event |= !!__brcmstb_gpio_get_active_irqs(bank); 770 727 gc->write_reg(reg_base + GIO_MASK(bank->id), 0); 771 728 729 + brcmstb_gpio_set_names(dev, bank); 772 730 err = gpiochip_add_data(gc, bank); 773 731 if (err) { 774 732 dev_err(dev, "Could not add gpiochip for bank %d\n",
+2 -5
drivers/gpio/gpio-davinci.c
··· 259 259 chips->chip.of_gpio_n_cells = 2; 260 260 chips->chip.parent = dev; 261 261 chips->chip.of_node = dev->of_node; 262 - 263 - if (of_property_read_bool(dev->of_node, "gpio-ranges")) { 264 - chips->chip.request = gpiochip_generic_request; 265 - chips->chip.free = gpiochip_generic_free; 266 - } 262 + chips->chip.request = gpiochip_generic_request; 263 + chips->chip.free = gpiochip_generic_free; 267 264 #endif 268 265 spin_lock_init(&chips->lock); 269 266
+7 -2
drivers/gpio/gpio-eic-sprd.c
··· 569 569 const struct sprd_eic_variant_data *pdata; 570 570 struct gpio_irq_chip *irq; 571 571 struct sprd_eic *sprd_eic; 572 + struct resource *res; 572 573 int ret, i; 573 574 574 575 pdata = of_device_get_match_data(&pdev->dev); ··· 596 595 * have one bank EIC, thus base[1] and base[2] can be 597 596 * optional. 598 597 */ 599 - sprd_eic->base[i] = devm_platform_ioremap_resource(pdev, i); 600 - if (IS_ERR(sprd_eic->base[i])) 598 + res = platform_get_resource(pdev, IORESOURCE_MEM, i); 599 + if (!res) 601 600 continue; 601 + 602 + sprd_eic->base[i] = devm_ioremap_resource(&pdev->dev, res); 603 + if (IS_ERR(sprd_eic->base[i])) 604 + return PTR_ERR(sprd_eic->base[i]); 602 605 } 603 606 604 607 sprd_eic->chip.label = sprd_eic_label_name[sprd_eic->type];
+335
drivers/gpio/gpio-mlxbf2.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <linux/acpi.h> 4 + #include <linux/bitfield.h> 5 + #include <linux/bitops.h> 6 + #include <linux/device.h> 7 + #include <linux/gpio/driver.h> 8 + #include <linux/io.h> 9 + #include <linux/ioport.h> 10 + #include <linux/kernel.h> 11 + #include <linux/module.h> 12 + #include <linux/platform_device.h> 13 + #include <linux/pm.h> 14 + #include <linux/resource.h> 15 + #include <linux/spinlock.h> 16 + #include <linux/types.h> 17 + #include <linux/version.h> 18 + 19 + /* 20 + * There are 3 YU GPIO blocks: 21 + * gpio[0]: HOST_GPIO0->HOST_GPIO31 22 + * gpio[1]: HOST_GPIO32->HOST_GPIO63 23 + * gpio[2]: HOST_GPIO64->HOST_GPIO69 24 + */ 25 + #define MLXBF2_GPIO_MAX_PINS_PER_BLOCK 32 26 + 27 + /* 28 + * arm_gpio_lock register: 29 + * bit[31] lock status: active if set 30 + * bit[15:0] set lock 31 + * The lock is enabled only if 0xd42f is written to this field 32 + */ 33 + #define YU_ARM_GPIO_LOCK_ADDR 0x2801088 34 + #define YU_ARM_GPIO_LOCK_SIZE 0x8 35 + #define YU_LOCK_ACTIVE_BIT(val) (val >> 31) 36 + #define YU_ARM_GPIO_LOCK_ACQUIRE 0xd42f 37 + #define YU_ARM_GPIO_LOCK_RELEASE 0x0 38 + 39 + /* 40 + * gpio[x] block registers and their offset 41 + */ 42 + #define YU_GPIO_DATAIN 0x04 43 + #define YU_GPIO_MODE1 0x08 44 + #define YU_GPIO_MODE0 0x0c 45 + #define YU_GPIO_DATASET 0x14 46 + #define YU_GPIO_DATACLEAR 0x18 47 + #define YU_GPIO_MODE1_CLEAR 0x50 48 + #define YU_GPIO_MODE0_SET 0x54 49 + #define YU_GPIO_MODE0_CLEAR 0x58 50 + 51 + #ifdef CONFIG_PM 52 + struct mlxbf2_gpio_context_save_regs { 53 + u32 gpio_mode0; 54 + u32 gpio_mode1; 55 + }; 56 + #endif 57 + 58 + /* BlueField-2 gpio block context structure. */ 59 + struct mlxbf2_gpio_context { 60 + struct gpio_chip gc; 61 + 62 + /* YU GPIO blocks address */ 63 + void __iomem *gpio_io; 64 + 65 + #ifdef CONFIG_PM 66 + struct mlxbf2_gpio_context_save_regs *csave_regs; 67 + #endif 68 + }; 69 + 70 + /* BlueField-2 gpio shared structure. */ 71 + struct mlxbf2_gpio_param { 72 + void __iomem *io; 73 + struct resource *res; 74 + struct mutex *lock; 75 + }; 76 + 77 + static struct resource yu_arm_gpio_lock_res = { 78 + .start = YU_ARM_GPIO_LOCK_ADDR, 79 + .end = YU_ARM_GPIO_LOCK_ADDR + YU_ARM_GPIO_LOCK_SIZE - 1, 80 + .name = "YU_ARM_GPIO_LOCK", 81 + }; 82 + 83 + static DEFINE_MUTEX(yu_arm_gpio_lock_mutex); 84 + 85 + static struct mlxbf2_gpio_param yu_arm_gpio_lock_param = { 86 + .res = &yu_arm_gpio_lock_res, 87 + .lock = &yu_arm_gpio_lock_mutex, 88 + }; 89 + 90 + /* Request memory region and map yu_arm_gpio_lock resource */ 91 + static int mlxbf2_gpio_get_lock_res(struct platform_device *pdev) 92 + { 93 + struct device *dev = &pdev->dev; 94 + struct resource *res; 95 + resource_size_t size; 96 + int ret = 0; 97 + 98 + mutex_lock(yu_arm_gpio_lock_param.lock); 99 + 100 + /* Check if the memory map already exists */ 101 + if (yu_arm_gpio_lock_param.io) 102 + goto exit; 103 + 104 + res = yu_arm_gpio_lock_param.res; 105 + size = resource_size(res); 106 + 107 + if (!devm_request_mem_region(dev, res->start, size, res->name)) { 108 + ret = -EFAULT; 109 + goto exit; 110 + } 111 + 112 + yu_arm_gpio_lock_param.io = devm_ioremap(dev, res->start, size); 113 + if (IS_ERR(yu_arm_gpio_lock_param.io)) 114 + ret = PTR_ERR(yu_arm_gpio_lock_param.io); 115 + 116 + exit: 117 + mutex_unlock(yu_arm_gpio_lock_param.lock); 118 + 119 + return ret; 120 + } 121 + 122 + /* 123 + * Acquire the YU arm_gpio_lock to be able to change the direction 124 + * mode. If the lock_active bit is already set, return an error. 125 + */ 126 + static int mlxbf2_gpio_lock_acquire(struct mlxbf2_gpio_context *gs) 127 + { 128 + u32 arm_gpio_lock_val; 129 + 130 + spin_lock(&gs->gc.bgpio_lock); 131 + mutex_lock(yu_arm_gpio_lock_param.lock); 132 + 133 + arm_gpio_lock_val = readl(yu_arm_gpio_lock_param.io); 134 + 135 + /* 136 + * When lock active bit[31] is set, ModeX is write enabled 137 + */ 138 + if (YU_LOCK_ACTIVE_BIT(arm_gpio_lock_val)) { 139 + mutex_unlock(yu_arm_gpio_lock_param.lock); 140 + spin_unlock(&gs->gc.bgpio_lock); 141 + return -EINVAL; 142 + } 143 + 144 + writel(YU_ARM_GPIO_LOCK_ACQUIRE, yu_arm_gpio_lock_param.io); 145 + 146 + return 0; 147 + } 148 + 149 + /* 150 + * Release the YU arm_gpio_lock after changing the direction mode. 151 + */ 152 + static void mlxbf2_gpio_lock_release(struct mlxbf2_gpio_context *gs) 153 + { 154 + writel(YU_ARM_GPIO_LOCK_RELEASE, yu_arm_gpio_lock_param.io); 155 + mutex_unlock(yu_arm_gpio_lock_param.lock); 156 + spin_unlock(&gs->gc.bgpio_lock); 157 + } 158 + 159 + /* 160 + * mode0 and mode1 are both locked by the gpio_lock field. 161 + * 162 + * Together, mode0 and mode1 define the gpio Mode dependeing also 163 + * on Reg_DataOut. 164 + * 165 + * {mode1,mode0}:{Reg_DataOut=0,Reg_DataOut=1}->{DataOut=0,DataOut=1} 166 + * 167 + * {0,0}:Reg_DataOut{0,1}->{Z,Z} Input PAD 168 + * {0,1}:Reg_DataOut{0,1}->{0,1} Full drive Output PAD 169 + * {1,0}:Reg_DataOut{0,1}->{0,Z} 0-set PAD to low, 1-float 170 + * {1,1}:Reg_DataOut{0,1}->{Z,1} 0-float, 1-set PAD to high 171 + */ 172 + 173 + /* 174 + * Set input direction: 175 + * {mode1,mode0} = {0,0} 176 + */ 177 + static int mlxbf2_gpio_direction_input(struct gpio_chip *chip, 178 + unsigned int offset) 179 + { 180 + struct mlxbf2_gpio_context *gs = gpiochip_get_data(chip); 181 + int ret; 182 + 183 + /* 184 + * Although the arm_gpio_lock was set in the probe function, check again 185 + * if it is still enabled to be able to write to the ModeX registers. 186 + */ 187 + ret = mlxbf2_gpio_lock_acquire(gs); 188 + if (ret < 0) 189 + return ret; 190 + 191 + writel(BIT(offset), gs->gpio_io + YU_GPIO_MODE0_CLEAR); 192 + writel(BIT(offset), gs->gpio_io + YU_GPIO_MODE1_CLEAR); 193 + 194 + mlxbf2_gpio_lock_release(gs); 195 + 196 + return ret; 197 + } 198 + 199 + /* 200 + * Set output direction: 201 + * {mode1,mode0} = {0,1} 202 + */ 203 + static int mlxbf2_gpio_direction_output(struct gpio_chip *chip, 204 + unsigned int offset, 205 + int value) 206 + { 207 + struct mlxbf2_gpio_context *gs = gpiochip_get_data(chip); 208 + int ret = 0; 209 + 210 + /* 211 + * Although the arm_gpio_lock was set in the probe function, 212 + * check again it is still enabled to be able to write to the 213 + * ModeX registers. 214 + */ 215 + ret = mlxbf2_gpio_lock_acquire(gs); 216 + if (ret < 0) 217 + return ret; 218 + 219 + writel(BIT(offset), gs->gpio_io + YU_GPIO_MODE1_CLEAR); 220 + writel(BIT(offset), gs->gpio_io + YU_GPIO_MODE0_SET); 221 + 222 + mlxbf2_gpio_lock_release(gs); 223 + 224 + return ret; 225 + } 226 + 227 + /* BlueField-2 GPIO driver initialization routine. */ 228 + static int 229 + mlxbf2_gpio_probe(struct platform_device *pdev) 230 + { 231 + struct mlxbf2_gpio_context *gs; 232 + struct device *dev = &pdev->dev; 233 + struct gpio_chip *gc; 234 + struct resource *res; 235 + unsigned int npins; 236 + int ret; 237 + 238 + gs = devm_kzalloc(dev, sizeof(*gs), GFP_KERNEL); 239 + if (!gs) 240 + return -ENOMEM; 241 + 242 + /* YU GPIO block address */ 243 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 244 + if (!res) 245 + return -ENODEV; 246 + 247 + gs->gpio_io = devm_ioremap(dev, res->start, resource_size(res)); 248 + if (!gs->gpio_io) 249 + return -ENOMEM; 250 + 251 + ret = mlxbf2_gpio_get_lock_res(pdev); 252 + if (ret) { 253 + dev_err(dev, "Failed to get yu_arm_gpio_lock resource\n"); 254 + return ret; 255 + } 256 + 257 + if (device_property_read_u32(dev, "npins", &npins)) 258 + npins = MLXBF2_GPIO_MAX_PINS_PER_BLOCK; 259 + 260 + gc = &gs->gc; 261 + 262 + ret = bgpio_init(gc, dev, 4, 263 + gs->gpio_io + YU_GPIO_DATAIN, 264 + gs->gpio_io + YU_GPIO_DATASET, 265 + gs->gpio_io + YU_GPIO_DATACLEAR, 266 + NULL, 267 + NULL, 268 + 0); 269 + 270 + gc->direction_input = mlxbf2_gpio_direction_input; 271 + gc->direction_output = mlxbf2_gpio_direction_output; 272 + gc->ngpio = npins; 273 + gc->owner = THIS_MODULE; 274 + 275 + platform_set_drvdata(pdev, gs); 276 + 277 + ret = devm_gpiochip_add_data(dev, &gs->gc, gs); 278 + if (ret) { 279 + dev_err(dev, "Failed adding memory mapped gpiochip\n"); 280 + return ret; 281 + } 282 + 283 + return 0; 284 + } 285 + 286 + #ifdef CONFIG_PM 287 + static int mlxbf2_gpio_suspend(struct platform_device *pdev, 288 + pm_message_t state) 289 + { 290 + struct mlxbf2_gpio_context *gs = platform_get_drvdata(pdev); 291 + 292 + gs->csave_regs->gpio_mode0 = readl(gs->gpio_io + 293 + YU_GPIO_MODE0); 294 + gs->csave_regs->gpio_mode1 = readl(gs->gpio_io + 295 + YU_GPIO_MODE1); 296 + 297 + return 0; 298 + } 299 + 300 + static int mlxbf2_gpio_resume(struct platform_device *pdev) 301 + { 302 + struct mlxbf2_gpio_context *gs = platform_get_drvdata(pdev); 303 + 304 + writel(gs->csave_regs->gpio_mode0, gs->gpio_io + 305 + YU_GPIO_MODE0); 306 + writel(gs->csave_regs->gpio_mode1, gs->gpio_io + 307 + YU_GPIO_MODE1); 308 + 309 + return 0; 310 + } 311 + #endif 312 + 313 + static const struct acpi_device_id mlxbf2_gpio_acpi_match[] = { 314 + { "MLNXBF22", 0 }, 315 + {}, 316 + }; 317 + MODULE_DEVICE_TABLE(acpi, mlxbf2_gpio_acpi_match); 318 + 319 + static struct platform_driver mlxbf2_gpio_driver = { 320 + .driver = { 321 + .name = "mlxbf2_gpio", 322 + .acpi_match_table = ACPI_PTR(mlxbf2_gpio_acpi_match), 323 + }, 324 + .probe = mlxbf2_gpio_probe, 325 + #ifdef CONFIG_PM 326 + .suspend = mlxbf2_gpio_suspend, 327 + .resume = mlxbf2_gpio_resume, 328 + #endif 329 + }; 330 + 331 + module_platform_driver(mlxbf2_gpio_driver); 332 + 333 + MODULE_DESCRIPTION("Mellanox BlueField-2 GPIO Driver"); 334 + MODULE_AUTHOR("Mellanox Technologies"); 335 + MODULE_LICENSE("GPL v2");
+19 -4
drivers/gpio/gpio-mmio.c
··· 389 389 return GPIO_LINE_DIRECTION_IN; 390 390 } 391 391 392 - static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 392 + static void bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 393 393 { 394 394 unsigned long flags; 395 - 396 - gc->set(gc, gpio, val); 397 395 398 396 spin_lock_irqsave(&gc->bgpio_lock, flags); 399 397 ··· 403 405 gc->write_reg(gc->reg_dir_out, gc->bgpio_dir); 404 406 405 407 spin_unlock_irqrestore(&gc->bgpio_lock, flags); 408 + } 406 409 410 + static int bgpio_dir_out_dir_first(struct gpio_chip *gc, unsigned int gpio, 411 + int val) 412 + { 413 + bgpio_dir_out(gc, gpio, val); 414 + gc->set(gc, gpio, val); 415 + return 0; 416 + } 417 + 418 + static int bgpio_dir_out_val_first(struct gpio_chip *gc, unsigned int gpio, 419 + int val) 420 + { 421 + gc->set(gc, gpio, val); 422 + bgpio_dir_out(gc, gpio, val); 407 423 return 0; 408 424 } 409 425 ··· 550 538 if (dirout || dirin) { 551 539 gc->reg_dir_out = dirout; 552 540 gc->reg_dir_in = dirin; 553 - gc->direction_output = bgpio_dir_out; 541 + if (flags & BGPIOF_NO_SET_ON_INPUT) 542 + gc->direction_output = bgpio_dir_out_dir_first; 543 + else 544 + gc->direction_output = bgpio_dir_out_val_first; 554 545 gc->direction_input = bgpio_dir_in; 555 546 gc->get_direction = bgpio_get_dir; 556 547 } else {
+1 -1
drivers/gpio/gpio-mockup.c
··· 171 171 172 172 /* Change the value unless we're actively driving the line. */ 173 173 if (!test_bit(FLAG_REQUESTED, &desc->flags) || 174 - !test_bit(FLAG_IS_OUT, &desc->flags)) 174 + !test_bit(FLAG_IS_OUT, &desc->flags)) 175 175 __gpio_mockup_set(chip, offset, value); 176 176 177 177 out:
+2 -2
drivers/gpio/gpio-mt7621.c
··· 227 227 ctrl = mtk->base + GPIO_REG_DCLR + (rg->bank * GPIO_BANK_STRIDE); 228 228 diro = mtk->base + GPIO_REG_CTRL + (rg->bank * GPIO_BANK_STRIDE); 229 229 230 - ret = bgpio_init(&rg->chip, dev, 4, 231 - dat, set, ctrl, diro, NULL, 0); 230 + ret = bgpio_init(&rg->chip, dev, 4, dat, set, ctrl, diro, NULL, 231 + BGPIOF_NO_SET_ON_INPUT); 232 232 if (ret) { 233 233 dev_err(dev, "bgpio_init() failed\n"); 234 234 return ret;
+1 -1
drivers/gpio/gpio-mvebu.c
··· 1247 1247 * pins. 1248 1248 */ 1249 1249 for (i = 0; i < 4; i++) { 1250 - int irq = platform_get_irq(pdev, i); 1250 + int irq = platform_get_irq_optional(pdev, i); 1251 1251 1252 1252 if (irq < 0) 1253 1253 continue;
+2 -5
drivers/gpio/gpio-mxc.c
··· 485 485 if (err) 486 486 goto out_bgio; 487 487 488 - if (of_property_read_bool(np, "gpio-ranges")) { 489 - port->gc.request = gpiochip_generic_request; 490 - port->gc.free = gpiochip_generic_free; 491 - } 492 - 488 + port->gc.request = gpiochip_generic_request; 489 + port->gc.free = gpiochip_generic_free; 493 490 port->gc.to_irq = mxc_gpio_to_irq; 494 491 port->gc.base = (pdev->id < 0) ? of_alias_get_id(np, "gpio") * 32 : 495 492 pdev->id * 32;
+14 -15
drivers/gpio/gpio-omap.c
··· 1102 1102 { 1103 1103 struct device *dev = bank->chip.parent; 1104 1104 void __iomem *base = bank->base; 1105 - u32 mask, nowake; 1105 + u32 nowake; 1106 1106 1107 1107 bank->saved_datain = readl_relaxed(base + bank->regs->datain); 1108 1108 1109 1109 if (!bank->enabled_non_wakeup_gpios) 1110 1110 goto update_gpio_context_count; 1111 - 1112 - /* Check for pending EDGE_FALLING, ignore EDGE_BOTH */ 1113 - mask = bank->enabled_non_wakeup_gpios & bank->context.fallingdetect; 1114 - mask &= ~bank->context.risingdetect; 1115 - bank->saved_datain |= mask; 1116 - 1117 - /* Check for pending EDGE_RISING, ignore EDGE_BOTH */ 1118 - mask = bank->enabled_non_wakeup_gpios & bank->context.risingdetect; 1119 - mask &= ~bank->context.fallingdetect; 1120 - bank->saved_datain &= ~mask; 1121 1111 1122 1112 if (!may_lose_context) 1123 1113 goto update_gpio_context_count; ··· 1227 1237 { 1228 1238 struct gpio_bank *bank; 1229 1239 unsigned long flags; 1240 + int ret = NOTIFY_OK; 1241 + u32 isr, mask; 1230 1242 1231 1243 bank = container_of(nb, struct gpio_bank, nb); 1232 1244 1233 1245 raw_spin_lock_irqsave(&bank->lock, flags); 1246 + if (bank->is_suspended) 1247 + goto out_unlock; 1248 + 1234 1249 switch (cmd) { 1235 1250 case CPU_CLUSTER_PM_ENTER: 1236 - if (bank->is_suspended) 1251 + mask = omap_get_gpio_irqbank_mask(bank); 1252 + isr = readl_relaxed(bank->base + bank->regs->irqstatus) & mask; 1253 + if (isr) { 1254 + ret = NOTIFY_BAD; 1237 1255 break; 1256 + } 1238 1257 omap_gpio_idle(bank, true); 1239 1258 break; 1240 1259 case CPU_CLUSTER_PM_ENTER_FAILED: 1241 1260 case CPU_CLUSTER_PM_EXIT: 1242 - if (bank->is_suspended) 1243 - break; 1244 1261 omap_gpio_unidle(bank); 1245 1262 break; 1246 1263 } 1264 + 1265 + out_unlock: 1247 1266 raw_spin_unlock_irqrestore(&bank->lock, flags); 1248 1267 1249 - return NOTIFY_OK; 1268 + return ret; 1250 1269 } 1251 1270 1252 1271 static const struct omap_gpio_reg_offs omap2_gpio_regs = {
+4 -9
drivers/gpio/gpio-pl061.c
··· 298 298 return PTR_ERR(pl061->base); 299 299 300 300 raw_spin_lock_init(&pl061->lock); 301 - if (of_property_read_bool(dev->of_node, "gpio-ranges")) { 302 - pl061->gc.request = gpiochip_generic_request; 303 - pl061->gc.free = gpiochip_generic_free; 304 - } 305 - 301 + pl061->gc.request = gpiochip_generic_request; 302 + pl061->gc.free = gpiochip_generic_free; 306 303 pl061->gc.base = -1; 307 304 pl061->gc.get_direction = pl061_get_direction; 308 305 pl061->gc.direction_input = pl061_direction_input; ··· 323 326 324 327 writeb(0, pl061->base + GPIOIE); /* disable irqs */ 325 328 irq = adev->irq[0]; 326 - if (irq < 0) { 327 - dev_err(&adev->dev, "invalid IRQ\n"); 328 - return -ENODEV; 329 - } 329 + if (!irq) 330 + dev_warn(&adev->dev, "IRQ support disabled\n"); 330 331 pl061->parent_irq = irq; 331 332 332 333 girq = &pl061->gc.irq;
+4 -7
drivers/gpio/gpio-pxa.c
··· 361 361 pchip->chip.set = pxa_gpio_set; 362 362 pchip->chip.to_irq = pxa_gpio_to_irq; 363 363 pchip->chip.ngpio = ngpio; 364 - 365 - if (pxa_gpio_has_pinctrl()) { 366 - pchip->chip.request = gpiochip_generic_request; 367 - pchip->chip.free = gpiochip_generic_free; 368 - } 364 + pchip->chip.request = gpiochip_generic_request; 365 + pchip->chip.free = gpiochip_generic_free; 369 366 370 367 #ifdef CONFIG_OF_GPIO 371 368 pchip->chip.of_node = np; ··· 649 652 if (!pchip->irqdomain) 650 653 return -ENOMEM; 651 654 652 - irq0 = platform_get_irq_byname(pdev, "gpio0"); 653 - irq1 = platform_get_irq_byname(pdev, "gpio1"); 655 + irq0 = platform_get_irq_byname_optional(pdev, "gpio0"); 656 + irq1 = platform_get_irq_byname_optional(pdev, "gpio1"); 654 657 irq_mux = platform_get_irq_byname(pdev, "gpio_mux"); 655 658 if ((irq0 > 0 && irq1 <= 0) || (irq0 <= 0 && irq1 > 0) 656 659 || (irq_mux <= 0))
+2 -2
drivers/gpio/gpio-rcar.c
··· 116 116 117 117 spin_lock_irqsave(&p->lock, flags); 118 118 119 - /* Configure postive or negative logic in POSNEG */ 119 + /* Configure positive or negative logic in POSNEG */ 120 120 gpio_rcar_modify_bit(p, POSNEG, hwirq, !active_high_rising_edge); 121 121 122 122 /* Configure edge or level trigger in EDGLEVEL */ ··· 228 228 229 229 spin_lock_irqsave(&p->lock, flags); 230 230 231 - /* Configure postive logic in POSNEG */ 231 + /* Configure positive logic in POSNEG */ 232 232 gpio_rcar_modify_bit(p, POSNEG, gpio, false); 233 233 234 234 /* Select "General Input/Output Mode" in IOINTSEL */
+14 -14
drivers/gpio/gpio-siox.c
··· 15 15 u8 setdata[1]; 16 16 u8 getdata[3]; 17 17 18 - spinlock_t irqlock; 18 + raw_spinlock_t irqlock; 19 19 u32 irq_enable; 20 20 u32 irq_status; 21 21 u32 irq_type[20]; ··· 44 44 45 45 mutex_lock(&ddata->lock); 46 46 47 - spin_lock_irq(&ddata->irqlock); 47 + raw_spin_lock_irq(&ddata->irqlock); 48 48 49 49 for (offset = 0; offset < 12; ++offset) { 50 50 unsigned int bitpos = 11 - offset; ··· 66 66 67 67 trigger = ddata->irq_status & ddata->irq_enable; 68 68 69 - spin_unlock_irq(&ddata->irqlock); 69 + raw_spin_unlock_irq(&ddata->irqlock); 70 70 71 71 ddata->getdata[0] = buf[0]; 72 72 ddata->getdata[1] = buf[1]; ··· 84 84 * handler of the irq chip. But it doesn't, so we have 85 85 * to clean the irq_status here. 86 86 */ 87 - spin_lock_irq(&ddata->irqlock); 87 + raw_spin_lock_irq(&ddata->irqlock); 88 88 ddata->irq_status &= ~(1 << offset); 89 - spin_unlock_irq(&ddata->irqlock); 89 + raw_spin_unlock_irq(&ddata->irqlock); 90 90 91 91 handle_nested_irq(irq); 92 92 } ··· 101 101 struct gpio_siox_ddata *ddata = 102 102 container_of(ic, struct gpio_siox_ddata, ichip); 103 103 104 - spin_lock_irq(&ddata->irqlock); 104 + raw_spin_lock(&ddata->irqlock); 105 105 ddata->irq_status &= ~(1 << d->hwirq); 106 - spin_unlock_irq(&ddata->irqlock); 106 + raw_spin_unlock(&ddata->irqlock); 107 107 } 108 108 109 109 static void gpio_siox_irq_mask(struct irq_data *d) ··· 112 112 struct gpio_siox_ddata *ddata = 113 113 container_of(ic, struct gpio_siox_ddata, ichip); 114 114 115 - spin_lock_irq(&ddata->irqlock); 115 + raw_spin_lock(&ddata->irqlock); 116 116 ddata->irq_enable &= ~(1 << d->hwirq); 117 - spin_unlock_irq(&ddata->irqlock); 117 + raw_spin_unlock(&ddata->irqlock); 118 118 } 119 119 120 120 static void gpio_siox_irq_unmask(struct irq_data *d) ··· 123 123 struct gpio_siox_ddata *ddata = 124 124 container_of(ic, struct gpio_siox_ddata, ichip); 125 125 126 - spin_lock_irq(&ddata->irqlock); 126 + raw_spin_lock(&ddata->irqlock); 127 127 ddata->irq_enable |= 1 << d->hwirq; 128 - spin_unlock_irq(&ddata->irqlock); 128 + raw_spin_unlock(&ddata->irqlock); 129 129 } 130 130 131 131 static int gpio_siox_irq_set_type(struct irq_data *d, u32 type) ··· 134 134 struct gpio_siox_ddata *ddata = 135 135 container_of(ic, struct gpio_siox_ddata, ichip); 136 136 137 - spin_lock_irq(&ddata->irqlock); 137 + raw_spin_lock(&ddata->irqlock); 138 138 ddata->irq_type[d->hwirq] = type; 139 - spin_unlock_irq(&ddata->irqlock); 139 + raw_spin_unlock(&ddata->irqlock); 140 140 141 141 return 0; 142 142 } ··· 222 222 dev_set_drvdata(dev, ddata); 223 223 224 224 mutex_init(&ddata->lock); 225 - spin_lock_init(&ddata->irqlock); 225 + raw_spin_lock_init(&ddata->irqlock); 226 226 227 227 ddata->gchip.base = -1; 228 228 ddata->gchip.can_sleep = 1;
+64
drivers/gpio/gpio-tegra186.c
··· 58 58 unsigned int pins; 59 59 }; 60 60 61 + struct tegra186_pin_range { 62 + unsigned int offset; 63 + const char *group; 64 + }; 65 + 61 66 struct tegra_gpio_soc { 62 67 const struct tegra_gpio_port *ports; 63 68 unsigned int num_ports; 64 69 const char *name; 65 70 unsigned int instance; 71 + 72 + const struct tegra186_pin_range *pin_ranges; 73 + unsigned int num_pin_ranges; 74 + const char *pinmux; 66 75 }; 67 76 68 77 struct tegra_gpio { ··· 259 250 value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG); 260 251 value |= TEGRA186_GPIO_ENABLE_CONFIG_DEBOUNCE; 261 252 writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG); 253 + 254 + return 0; 255 + } 256 + 257 + static int tegra186_gpio_add_pin_ranges(struct gpio_chip *chip) 258 + { 259 + struct tegra_gpio *gpio = gpiochip_get_data(chip); 260 + struct pinctrl_dev *pctldev; 261 + struct device_node *np; 262 + unsigned int i, j; 263 + int err; 264 + 265 + if (!gpio->soc->pinmux || gpio->soc->num_pin_ranges == 0) 266 + return 0; 267 + 268 + np = of_find_compatible_node(NULL, NULL, gpio->soc->pinmux); 269 + if (!np) 270 + return -ENODEV; 271 + 272 + pctldev = of_pinctrl_get(np); 273 + of_node_put(np); 274 + if (!pctldev) 275 + return -EPROBE_DEFER; 276 + 277 + for (i = 0; i < gpio->soc->num_pin_ranges; i++) { 278 + unsigned int pin = gpio->soc->pin_ranges[i].offset, port; 279 + const char *group = gpio->soc->pin_ranges[i].group; 280 + 281 + port = pin / 8; 282 + pin = pin % 8; 283 + 284 + if (port >= gpio->soc->num_ports) { 285 + dev_warn(chip->parent, "invalid port %u for %s\n", 286 + port, group); 287 + continue; 288 + } 289 + 290 + for (j = 0; j < port; j++) 291 + pin += gpio->soc->ports[j].pins; 292 + 293 + err = gpiochip_add_pingroup_range(chip, pctldev, pin, group); 294 + if (err < 0) 295 + return err; 296 + } 262 297 263 298 return 0; 264 299 } ··· 631 578 gpio->gpio.label = gpio->soc->name; 632 579 gpio->gpio.parent = &pdev->dev; 633 580 581 + gpio->gpio.request = gpiochip_generic_request; 582 + gpio->gpio.free = gpiochip_generic_free; 634 583 gpio->gpio.get_direction = tegra186_gpio_get_direction; 635 584 gpio->gpio.direction_input = tegra186_gpio_direction_input; 636 585 gpio->gpio.direction_output = tegra186_gpio_direction_output; 637 586 gpio->gpio.get = tegra186_gpio_get, 638 587 gpio->gpio.set = tegra186_gpio_set; 639 588 gpio->gpio.set_config = tegra186_gpio_set_config; 589 + gpio->gpio.add_pin_ranges = tegra186_gpio_add_pin_ranges; 640 590 641 591 gpio->gpio.base = -1; 642 592 ··· 839 783 TEGRA194_MAIN_GPIO_PORT(GG, 0, 0, 2) 840 784 }; 841 785 786 + static const struct tegra186_pin_range tegra194_main_pin_ranges[] = { 787 + { TEGRA194_MAIN_GPIO(GG, 0), "pex_l5_clkreq_n_pgg0" }, 788 + { TEGRA194_MAIN_GPIO(GG, 1), "pex_l5_rst_n_pgg1" }, 789 + }; 790 + 842 791 static const struct tegra_gpio_soc tegra194_main_soc = { 843 792 .num_ports = ARRAY_SIZE(tegra194_main_ports), 844 793 .ports = tegra194_main_ports, 845 794 .name = "tegra194-gpio", 846 795 .instance = 0, 796 + .num_pin_ranges = ARRAY_SIZE(tegra194_main_pin_ranges), 797 + .pin_ranges = tegra194_main_pin_ranges, 798 + .pinmux = "nvidia,tegra194-pinmux", 847 799 }; 848 800 849 801 #define TEGRA194_AON_GPIO_PORT(_name, _bank, _port, _pins) \
+1 -1
drivers/gpio/gpio-uniphier.c
··· 30 30 struct irq_domain *domain; 31 31 void __iomem *regs; 32 32 spinlock_t lock; 33 - u32 saved_vals[0]; 33 + u32 saved_vals[]; 34 34 }; 35 35 36 36 static unsigned int uniphier_gpio_bank_to_reg(unsigned int bank)
+6 -3
drivers/gpio/gpio-wcd934x.c
··· 57 57 static int wcd_gpio_get(struct gpio_chip *chip, unsigned int pin) 58 58 { 59 59 struct wcd_gpio_data *data = gpiochip_get_data(chip); 60 - int value; 60 + unsigned int value; 61 61 62 62 regmap_read(data->map, WCD_REG_VAL_CTL_OFFSET, &value); 63 63 64 - return !!(value && WCD_PIN_MASK(pin)); 64 + return !!(value & WCD_PIN_MASK(pin)); 65 65 } 66 66 67 67 static void wcd_gpio_set(struct gpio_chip *chip, unsigned int pin, int val) 68 68 { 69 - wcd_gpio_direction_output(chip, pin, val); 69 + struct wcd_gpio_data *data = gpiochip_get_data(chip); 70 + 71 + regmap_update_bits(data->map, WCD_REG_VAL_CTL_OFFSET, 72 + WCD_PIN_MASK(pin), val ? WCD_PIN_MASK(pin) : 0); 70 73 } 71 74 72 75 static int wcd_gpio_probe(struct platform_device *pdev)
+4 -6
drivers/gpio/gpio-zx.c
··· 226 226 if (IS_ERR(chip->base)) 227 227 return PTR_ERR(chip->base); 228 228 229 - raw_spin_lock_init(&chip->lock); 230 - if (of_property_read_bool(dev->of_node, "gpio-ranges")) { 231 - chip->gc.request = gpiochip_generic_request; 232 - chip->gc.free = gpiochip_generic_free; 233 - } 234 - 235 229 id = of_alias_get_id(dev->of_node, "gpio"); 230 + 231 + raw_spin_lock_init(&chip->lock); 232 + chip->gc.request = gpiochip_generic_request; 233 + chip->gc.free = gpiochip_generic_free; 236 234 chip->gc.direction_input = zx_direction_input; 237 235 chip->gc.direction_output = zx_direction_output; 238 236 chip->gc.get = zx_get_value;
+46
drivers/gpio/gpiolib-devres.c
··· 478 478 &gpio)); 479 479 } 480 480 EXPORT_SYMBOL_GPL(devm_gpio_free); 481 + 482 + static void devm_gpio_chip_release(struct device *dev, void *res) 483 + { 484 + struct gpio_chip *gc = *(struct gpio_chip **)res; 485 + 486 + gpiochip_remove(gc); 487 + } 488 + 489 + /** 490 + * devm_gpiochip_add_data() - Resource managed gpiochip_add_data() 491 + * @dev: pointer to the device that gpio_chip belongs to. 492 + * @gc: the GPIO chip to register 493 + * @data: driver-private data associated with this chip 494 + * 495 + * Context: potentially before irqs will work 496 + * 497 + * The gpio chip automatically be released when the device is unbound. 498 + * 499 + * Returns: 500 + * A negative errno if the chip can't be registered, such as because the 501 + * gc->base is invalid or already associated with a different chip. 502 + * Otherwise it returns zero as a success code. 503 + */ 504 + int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *gc, 505 + void *data) 506 + { 507 + struct gpio_chip **ptr; 508 + int ret; 509 + 510 + ptr = devres_alloc(devm_gpio_chip_release, sizeof(*ptr), 511 + GFP_KERNEL); 512 + if (!ptr) 513 + return -ENOMEM; 514 + 515 + ret = gpiochip_add_data(gc, data); 516 + if (ret < 0) { 517 + devres_free(ptr); 518 + return ret; 519 + } 520 + 521 + *ptr = gc; 522 + devres_add(dev, ptr); 523 + 524 + return 0; 525 + } 526 + EXPORT_SYMBOL_GPL(devm_gpiochip_add_data);
+123 -16
drivers/gpio/gpiolib-of.c
··· 605 605 } 606 606 607 607 /** 608 + * of_gpiochip_add_hog - Add all hogs in a hog device node 609 + * @chip: gpio chip to act on 610 + * @hog: device node describing the hogs 611 + * 612 + * Returns error if it fails otherwise 0 on success. 613 + */ 614 + static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog) 615 + { 616 + enum gpiod_flags dflags; 617 + struct gpio_desc *desc; 618 + unsigned long lflags; 619 + const char *name; 620 + unsigned int i; 621 + int ret; 622 + 623 + for (i = 0;; i++) { 624 + desc = of_parse_own_gpio(hog, chip, i, &name, &lflags, &dflags); 625 + if (IS_ERR(desc)) 626 + break; 627 + 628 + ret = gpiod_hog(desc, name, lflags, dflags); 629 + if (ret < 0) 630 + return ret; 631 + 632 + #ifdef CONFIG_OF_DYNAMIC 633 + desc->hog = hog; 634 + #endif 635 + } 636 + 637 + return 0; 638 + } 639 + 640 + /** 608 641 * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions 609 642 * @chip: gpio chip to act on 610 643 * ··· 647 614 */ 648 615 static int of_gpiochip_scan_gpios(struct gpio_chip *chip) 649 616 { 650 - struct gpio_desc *desc = NULL; 651 617 struct device_node *np; 652 - const char *name; 653 - unsigned long lflags; 654 - enum gpiod_flags dflags; 655 - unsigned int i; 656 618 int ret; 657 619 658 620 for_each_available_child_of_node(chip->of_node, np) { 659 621 if (!of_property_read_bool(np, "gpio-hog")) 660 622 continue; 661 623 662 - for (i = 0;; i++) { 663 - desc = of_parse_own_gpio(np, chip, i, &name, &lflags, 664 - &dflags); 665 - if (IS_ERR(desc)) 666 - break; 667 - 668 - ret = gpiod_hog(desc, name, lflags, dflags); 669 - if (ret < 0) { 670 - of_node_put(np); 671 - return ret; 672 - } 624 + ret = of_gpiochip_add_hog(chip, np); 625 + if (ret < 0) { 626 + of_node_put(np); 627 + return ret; 673 628 } 629 + 630 + of_node_set_flag(np, OF_POPULATED); 674 631 } 675 632 676 633 return 0; 677 634 } 635 + 636 + #ifdef CONFIG_OF_DYNAMIC 637 + /** 638 + * of_gpiochip_remove_hog - Remove all hogs in a hog device node 639 + * @chip: gpio chip to act on 640 + * @hog: device node describing the hogs 641 + */ 642 + static void of_gpiochip_remove_hog(struct gpio_chip *chip, 643 + struct device_node *hog) 644 + { 645 + struct gpio_desc *descs = chip->gpiodev->descs; 646 + unsigned int i; 647 + 648 + for (i = 0; i < chip->ngpio; i++) { 649 + if (test_bit(FLAG_IS_HOGGED, &descs[i].flags) && 650 + descs[i].hog == hog) 651 + gpiochip_free_own_desc(&descs[i]); 652 + } 653 + } 654 + 655 + static int of_gpiochip_match_node(struct gpio_chip *chip, void *data) 656 + { 657 + return chip->gpiodev->dev.of_node == data; 658 + } 659 + 660 + static struct gpio_chip *of_find_gpiochip_by_node(struct device_node *np) 661 + { 662 + return gpiochip_find(np, of_gpiochip_match_node); 663 + } 664 + 665 + static int of_gpio_notify(struct notifier_block *nb, unsigned long action, 666 + void *arg) 667 + { 668 + struct of_reconfig_data *rd = arg; 669 + struct gpio_chip *chip; 670 + int ret; 671 + 672 + /* 673 + * This only supports adding and removing complete gpio-hog nodes. 674 + * Modifying an existing gpio-hog node is not supported (except for 675 + * changing its "status" property, which is treated the same as 676 + * addition/removal). 677 + */ 678 + switch (of_reconfig_get_state_change(action, arg)) { 679 + case OF_RECONFIG_CHANGE_ADD: 680 + if (!of_property_read_bool(rd->dn, "gpio-hog")) 681 + return NOTIFY_OK; /* not for us */ 682 + 683 + if (of_node_test_and_set_flag(rd->dn, OF_POPULATED)) 684 + return NOTIFY_OK; 685 + 686 + chip = of_find_gpiochip_by_node(rd->dn->parent); 687 + if (chip == NULL) 688 + return NOTIFY_OK; /* not for us */ 689 + 690 + ret = of_gpiochip_add_hog(chip, rd->dn); 691 + if (ret < 0) { 692 + pr_err("%s: failed to add hogs for %pOF\n", __func__, 693 + rd->dn); 694 + of_node_clear_flag(rd->dn, OF_POPULATED); 695 + return notifier_from_errno(ret); 696 + } 697 + break; 698 + 699 + case OF_RECONFIG_CHANGE_REMOVE: 700 + if (!of_node_check_flag(rd->dn, OF_POPULATED)) 701 + return NOTIFY_OK; /* already depopulated */ 702 + 703 + chip = of_find_gpiochip_by_node(rd->dn->parent); 704 + if (chip == NULL) 705 + return NOTIFY_OK; /* not for us */ 706 + 707 + of_gpiochip_remove_hog(chip, rd->dn); 708 + of_node_clear_flag(rd->dn, OF_POPULATED); 709 + break; 710 + } 711 + 712 + return NOTIFY_OK; 713 + } 714 + 715 + struct notifier_block gpio_of_notifier = { 716 + .notifier_call = of_gpio_notify, 717 + }; 718 + #endif /* CONFIG_OF_DYNAMIC */ 678 719 679 720 /** 680 721 * of_gpio_simple_xlate - translate gpiospec to the GPIO number and flags
+2
drivers/gpio/gpiolib-of.h
··· 35 35 } 36 36 #endif /* CONFIG_OF_GPIO */ 37 37 38 + extern struct notifier_block gpio_of_notifier; 39 + 38 40 #endif /* GPIOLIB_OF_H */
+737 -566
drivers/gpio/gpiolib.c
··· 81 81 static DEFINE_MUTEX(gpio_machine_hogs_mutex); 82 82 static LIST_HEAD(gpio_machine_hogs); 83 83 84 - static void gpiochip_free_hogs(struct gpio_chip *chip); 85 - static int gpiochip_add_irqchip(struct gpio_chip *gpiochip, 84 + static void gpiochip_free_hogs(struct gpio_chip *gc); 85 + static int gpiochip_add_irqchip(struct gpio_chip *gc, 86 86 struct lock_class_key *lock_key, 87 87 struct lock_class_key *request_key); 88 - static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip); 89 - static int gpiochip_irqchip_init_hw(struct gpio_chip *gpiochip); 90 - static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gpiochip); 91 - static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gpiochip); 88 + static void gpiochip_irqchip_remove(struct gpio_chip *gc); 89 + static int gpiochip_irqchip_init_hw(struct gpio_chip *gc); 90 + static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc); 91 + static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc); 92 92 93 93 static bool gpiolib_initialized; 94 94 ··· 132 132 /** 133 133 * gpiochip_get_desc - get the GPIO descriptor corresponding to the given 134 134 * hardware number for this chip 135 - * @chip: GPIO chip 135 + * @gc: GPIO chip 136 136 * @hwnum: hardware number of the GPIO for this chip 137 137 * 138 138 * Returns: 139 - * A pointer to the GPIO descriptor or %ERR_PTR(-EINVAL) if no GPIO exists 139 + * A pointer to the GPIO descriptor or ``ERR_PTR(-EINVAL)`` if no GPIO exists 140 140 * in the given chip for the specified hardware number. 141 141 */ 142 - struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, 142 + struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, 143 143 unsigned int hwnum) 144 144 { 145 - struct gpio_device *gdev = chip->gpiodev; 145 + struct gpio_device *gdev = gc->gpiodev; 146 146 147 147 if (hwnum >= gdev->ngpio) 148 148 return ERR_PTR(-EINVAL); ··· 214 214 */ 215 215 int gpiod_get_direction(struct gpio_desc *desc) 216 216 { 217 - struct gpio_chip *chip; 217 + struct gpio_chip *gc; 218 218 unsigned offset; 219 219 int ret; 220 220 221 - chip = gpiod_to_chip(desc); 221 + gc = gpiod_to_chip(desc); 222 222 offset = gpio_chip_hwgpio(desc); 223 223 224 224 /* ··· 229 229 test_bit(FLAG_IS_OUT, &desc->flags)) 230 230 return 0; 231 231 232 - if (!chip->get_direction) 232 + if (!gc->get_direction) 233 233 return -ENOTSUPP; 234 234 235 - ret = chip->get_direction(chip, offset); 235 + ret = gc->get_direction(gc, offset); 236 236 if (ret < 0) 237 237 return ret; 238 238 ··· 302 302 struct gpio_device *gdev; 303 303 unsigned long flags; 304 304 305 + if (!name) 306 + return NULL; 307 + 305 308 spin_lock_irqsave(&gpio_lock, flags); 306 309 307 310 list_for_each_entry(gdev, &gpio_devices, list) { ··· 313 310 for (i = 0; i != gdev->ngpio; ++i) { 314 311 struct gpio_desc *desc = &gdev->descs[i]; 315 312 316 - if (!desc->name || !name) 313 + if (!desc->name) 317 314 continue; 318 315 319 316 if (!strcmp(desc->name, name)) { ··· 360 357 return 0; 361 358 } 362 359 363 - static unsigned long *gpiochip_allocate_mask(struct gpio_chip *chip) 360 + static unsigned long *gpiochip_allocate_mask(struct gpio_chip *gc) 364 361 { 365 362 unsigned long *p; 366 363 367 - p = bitmap_alloc(chip->ngpio, GFP_KERNEL); 364 + p = bitmap_alloc(gc->ngpio, GFP_KERNEL); 368 365 if (!p) 369 366 return NULL; 370 367 371 368 /* Assume by default all GPIOs are valid */ 372 - bitmap_fill(p, chip->ngpio); 369 + bitmap_fill(p, gc->ngpio); 373 370 374 371 return p; 375 372 } ··· 396 393 return 0; 397 394 } 398 395 399 - static void gpiochip_free_valid_mask(struct gpio_chip *gpiochip) 396 + static void gpiochip_free_valid_mask(struct gpio_chip *gc) 400 397 { 401 - bitmap_free(gpiochip->valid_mask); 402 - gpiochip->valid_mask = NULL; 398 + bitmap_free(gc->valid_mask); 399 + gc->valid_mask = NULL; 403 400 } 404 401 405 402 static int gpiochip_add_pin_ranges(struct gpio_chip *gc) ··· 410 407 return 0; 411 408 } 412 409 413 - bool gpiochip_line_is_valid(const struct gpio_chip *gpiochip, 410 + bool gpiochip_line_is_valid(const struct gpio_chip *gc, 414 411 unsigned int offset) 415 412 { 416 413 /* No mask means all valid */ 417 - if (likely(!gpiochip->valid_mask)) 414 + if (likely(!gc->valid_mask)) 418 415 return true; 419 - return test_bit(offset, gpiochip->valid_mask); 416 + return test_bit(offset, gc->valid_mask); 420 417 } 421 418 EXPORT_SYMBOL_GPL(gpiochip_line_is_valid); 422 419 ··· 550 547 if (ret) 551 548 return ret; 552 549 } 550 + 551 + atomic_notifier_call_chain(&desc->gdev->notifier, 552 + GPIOLINE_CHANGED_CONFIG, desc); 553 553 } 554 554 return 0; 555 555 } ··· 794 788 * @irq: the interrupt that trigger in response to events on this GPIO 795 789 * @wait: wait queue that handles blocking reads of events 796 790 * @events: KFIFO for the GPIO events 797 - * @read_lock: mutex lock to protect reads from colliding with adding 798 - * new events to the FIFO 799 791 * @timestamp: cache for the timestamp storing it between hardirq 800 792 * and IRQ thread, used to bring the timestamp close to the actual 801 793 * event ··· 806 802 int irq; 807 803 wait_queue_head_t wait; 808 804 DECLARE_KFIFO(events, struct gpioevent_data, 16); 809 - struct mutex read_lock; 810 805 u64 timestamp; 811 806 }; 812 807 ··· 821 818 822 819 poll_wait(filep, &le->wait, wait); 823 820 824 - if (!kfifo_is_empty(&le->events)) 821 + if (!kfifo_is_empty_spinlocked_noirqsave(&le->events, &le->wait.lock)) 825 822 events = EPOLLIN | EPOLLRDNORM; 826 823 827 824 return events; ··· 834 831 loff_t *f_ps) 835 832 { 836 833 struct lineevent_state *le = filep->private_data; 837 - unsigned int copied; 834 + struct gpioevent_data ge; 835 + ssize_t bytes_read = 0; 838 836 int ret; 839 837 840 - if (count < sizeof(struct gpioevent_data)) 838 + if (count < sizeof(ge)) 841 839 return -EINVAL; 842 840 843 841 do { 842 + spin_lock(&le->wait.lock); 844 843 if (kfifo_is_empty(&le->events)) { 845 - if (filep->f_flags & O_NONBLOCK) 846 - return -EAGAIN; 844 + if (bytes_read) { 845 + spin_unlock(&le->wait.lock); 846 + return bytes_read; 847 + } 847 848 848 - ret = wait_event_interruptible(le->wait, 849 + if (filep->f_flags & O_NONBLOCK) { 850 + spin_unlock(&le->wait.lock); 851 + return -EAGAIN; 852 + } 853 + 854 + ret = wait_event_interruptible_locked(le->wait, 849 855 !kfifo_is_empty(&le->events)); 850 - if (ret) 856 + if (ret) { 857 + spin_unlock(&le->wait.lock); 851 858 return ret; 859 + } 852 860 } 853 861 854 - if (mutex_lock_interruptible(&le->read_lock)) 855 - return -ERESTARTSYS; 856 - ret = kfifo_to_user(&le->events, buf, count, &copied); 857 - mutex_unlock(&le->read_lock); 862 + ret = kfifo_out(&le->events, &ge, 1); 863 + spin_unlock(&le->wait.lock); 864 + if (ret != 1) { 865 + /* 866 + * This should never happen - we were holding the lock 867 + * from the moment we learned the fifo is no longer 868 + * empty until now. 869 + */ 870 + ret = -EIO; 871 + break; 872 + } 858 873 859 - if (ret) 860 - return ret; 874 + if (copy_to_user(buf + bytes_read, &ge, sizeof(ge))) 875 + return -EFAULT; 876 + bytes_read += sizeof(ge); 877 + } while (count >= bytes_read + sizeof(ge)); 861 878 862 - /* 863 - * If we couldn't read anything from the fifo (a different 864 - * thread might have been faster) we either return -EAGAIN if 865 - * the file descriptor is non-blocking, otherwise we go back to 866 - * sleep and wait for more data to arrive. 867 - */ 868 - if (copied == 0 && (filep->f_flags & O_NONBLOCK)) 869 - return -EAGAIN; 870 - 871 - } while (copied == 0); 872 - 873 - return copied; 879 + return bytes_read; 874 880 } 875 881 876 882 static int lineevent_release(struct inode *inode, struct file *filep) ··· 958 946 * we didn't get the timestamp from lineevent_irq_handler(). 959 947 */ 960 948 if (!le->timestamp) 961 - ge.timestamp = ktime_get_real_ns(); 949 + ge.timestamp = ktime_get_ns(); 962 950 else 963 951 ge.timestamp = le->timestamp; 964 952 ··· 981 969 return IRQ_NONE; 982 970 } 983 971 984 - ret = kfifo_put(&le->events, ge); 972 + ret = kfifo_in_spinlocked_noirqsave(&le->events, &ge, 973 + 1, &le->wait.lock); 985 974 if (ret) 986 975 wake_up_poll(&le->wait, EPOLLIN); 976 + else 977 + pr_debug_ratelimited("event FIFO is full - event dropped\n"); 987 978 988 979 return IRQ_HANDLED; 989 980 } ··· 999 984 * Just store the timestamp in hardirq context so we get it as 1000 985 * close in time as possible to the actual event. 1001 986 */ 1002 - le->timestamp = ktime_get_real_ns(); 987 + le->timestamp = ktime_get_ns(); 1003 988 1004 989 return IRQ_WAKE_THREAD; 1005 990 } ··· 1099 1084 1100 1085 INIT_KFIFO(le->events); 1101 1086 init_waitqueue_head(&le->wait); 1102 - mutex_init(&le->read_lock); 1103 1087 1104 1088 /* Request a thread to read the events */ 1105 1089 ret = request_threaded_irq(le->irq, ··· 1154 1140 return ret; 1155 1141 } 1156 1142 1143 + static void gpio_desc_to_lineinfo(struct gpio_desc *desc, 1144 + struct gpioline_info *info) 1145 + { 1146 + struct gpio_chip *gc = desc->gdev->chip; 1147 + unsigned long flags; 1148 + 1149 + spin_lock_irqsave(&gpio_lock, flags); 1150 + 1151 + if (desc->name) { 1152 + strncpy(info->name, desc->name, sizeof(info->name)); 1153 + info->name[sizeof(info->name) - 1] = '\0'; 1154 + } else { 1155 + info->name[0] = '\0'; 1156 + } 1157 + 1158 + if (desc->label) { 1159 + strncpy(info->consumer, desc->label, sizeof(info->consumer)); 1160 + info->consumer[sizeof(info->consumer) - 1] = '\0'; 1161 + } else { 1162 + info->consumer[0] = '\0'; 1163 + } 1164 + 1165 + /* 1166 + * Userspace only need to know that the kernel is using this GPIO so 1167 + * it can't use it. 1168 + */ 1169 + info->flags = 0; 1170 + if (test_bit(FLAG_REQUESTED, &desc->flags) || 1171 + test_bit(FLAG_IS_HOGGED, &desc->flags) || 1172 + test_bit(FLAG_USED_AS_IRQ, &desc->flags) || 1173 + test_bit(FLAG_EXPORT, &desc->flags) || 1174 + test_bit(FLAG_SYSFS, &desc->flags) || 1175 + !pinctrl_gpio_can_use_line(gc->base + info->line_offset)) 1176 + info->flags |= GPIOLINE_FLAG_KERNEL; 1177 + if (test_bit(FLAG_IS_OUT, &desc->flags)) 1178 + info->flags |= GPIOLINE_FLAG_IS_OUT; 1179 + if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) 1180 + info->flags |= GPIOLINE_FLAG_ACTIVE_LOW; 1181 + if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) 1182 + info->flags |= (GPIOLINE_FLAG_OPEN_DRAIN | 1183 + GPIOLINE_FLAG_IS_OUT); 1184 + if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) 1185 + info->flags |= (GPIOLINE_FLAG_OPEN_SOURCE | 1186 + GPIOLINE_FLAG_IS_OUT); 1187 + if (test_bit(FLAG_BIAS_DISABLE, &desc->flags)) 1188 + info->flags |= GPIOLINE_FLAG_BIAS_DISABLE; 1189 + if (test_bit(FLAG_PULL_DOWN, &desc->flags)) 1190 + info->flags |= GPIOLINE_FLAG_BIAS_PULL_DOWN; 1191 + if (test_bit(FLAG_PULL_UP, &desc->flags)) 1192 + info->flags |= GPIOLINE_FLAG_BIAS_PULL_UP; 1193 + 1194 + spin_unlock_irqrestore(&gpio_lock, flags); 1195 + } 1196 + 1197 + struct gpio_chardev_data { 1198 + struct gpio_device *gdev; 1199 + wait_queue_head_t wait; 1200 + DECLARE_KFIFO(events, struct gpioline_info_changed, 32); 1201 + struct notifier_block lineinfo_changed_nb; 1202 + unsigned long *watched_lines; 1203 + }; 1204 + 1157 1205 /* 1158 1206 * gpio_ioctl() - ioctl handler for the GPIO chardev 1159 1207 */ 1160 1208 static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 1161 1209 { 1162 - struct gpio_device *gdev = filp->private_data; 1163 - struct gpio_chip *chip = gdev->chip; 1210 + struct gpio_chardev_data *priv = filp->private_data; 1211 + struct gpio_device *gdev = priv->gdev; 1212 + struct gpio_chip *gc = gdev->chip; 1164 1213 void __user *ip = (void __user *)arg; 1214 + struct gpio_desc *desc; 1215 + __u32 offset; 1165 1216 1166 1217 /* We fail any subsequent ioctl():s when the chip is gone */ 1167 - if (!chip) 1218 + if (!gc) 1168 1219 return -ENODEV; 1169 1220 1170 1221 /* Fill in the struct and pass to userspace */ ··· 1248 1169 if (copy_to_user(ip, &chipinfo, sizeof(chipinfo))) 1249 1170 return -EFAULT; 1250 1171 return 0; 1251 - } else if (cmd == GPIO_GET_LINEINFO_IOCTL) { 1172 + } else if (cmd == GPIO_GET_LINEINFO_IOCTL || 1173 + cmd == GPIO_GET_LINEINFO_WATCH_IOCTL) { 1252 1174 struct gpioline_info lineinfo; 1253 - struct gpio_desc *desc; 1254 1175 1255 1176 if (copy_from_user(&lineinfo, ip, sizeof(lineinfo))) 1256 1177 return -EFAULT; 1257 1178 1258 - desc = gpiochip_get_desc(chip, lineinfo.line_offset); 1179 + desc = gpiochip_get_desc(gc, lineinfo.line_offset); 1259 1180 if (IS_ERR(desc)) 1260 1181 return PTR_ERR(desc); 1261 1182 1262 - if (desc->name) { 1263 - strncpy(lineinfo.name, desc->name, 1264 - sizeof(lineinfo.name)); 1265 - lineinfo.name[sizeof(lineinfo.name)-1] = '\0'; 1266 - } else { 1267 - lineinfo.name[0] = '\0'; 1268 - } 1269 - if (desc->label) { 1270 - strncpy(lineinfo.consumer, desc->label, 1271 - sizeof(lineinfo.consumer)); 1272 - lineinfo.consumer[sizeof(lineinfo.consumer)-1] = '\0'; 1273 - } else { 1274 - lineinfo.consumer[0] = '\0'; 1275 - } 1276 - 1277 - /* 1278 - * Userspace only need to know that the kernel is using 1279 - * this GPIO so it can't use it. 1280 - */ 1281 - lineinfo.flags = 0; 1282 - if (test_bit(FLAG_REQUESTED, &desc->flags) || 1283 - test_bit(FLAG_IS_HOGGED, &desc->flags) || 1284 - test_bit(FLAG_USED_AS_IRQ, &desc->flags) || 1285 - test_bit(FLAG_EXPORT, &desc->flags) || 1286 - test_bit(FLAG_SYSFS, &desc->flags) || 1287 - !pinctrl_gpio_can_use_line(chip->base + lineinfo.line_offset)) 1288 - lineinfo.flags |= GPIOLINE_FLAG_KERNEL; 1289 - if (test_bit(FLAG_IS_OUT, &desc->flags)) 1290 - lineinfo.flags |= GPIOLINE_FLAG_IS_OUT; 1291 - if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) 1292 - lineinfo.flags |= GPIOLINE_FLAG_ACTIVE_LOW; 1293 - if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) 1294 - lineinfo.flags |= (GPIOLINE_FLAG_OPEN_DRAIN | 1295 - GPIOLINE_FLAG_IS_OUT); 1296 - if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) 1297 - lineinfo.flags |= (GPIOLINE_FLAG_OPEN_SOURCE | 1298 - GPIOLINE_FLAG_IS_OUT); 1299 - if (test_bit(FLAG_BIAS_DISABLE, &desc->flags)) 1300 - lineinfo.flags |= GPIOLINE_FLAG_BIAS_DISABLE; 1301 - if (test_bit(FLAG_PULL_DOWN, &desc->flags)) 1302 - lineinfo.flags |= GPIOLINE_FLAG_BIAS_PULL_DOWN; 1303 - if (test_bit(FLAG_PULL_UP, &desc->flags)) 1304 - lineinfo.flags |= GPIOLINE_FLAG_BIAS_PULL_UP; 1183 + gpio_desc_to_lineinfo(desc, &lineinfo); 1305 1184 1306 1185 if (copy_to_user(ip, &lineinfo, sizeof(lineinfo))) 1307 1186 return -EFAULT; 1187 + 1188 + if (cmd == GPIO_GET_LINEINFO_WATCH_IOCTL) 1189 + set_bit(gpio_chip_hwgpio(desc), priv->watched_lines); 1190 + 1308 1191 return 0; 1309 1192 } else if (cmd == GPIO_GET_LINEHANDLE_IOCTL) { 1310 1193 return linehandle_create(gdev, ip); 1311 1194 } else if (cmd == GPIO_GET_LINEEVENT_IOCTL) { 1312 1195 return lineevent_create(gdev, ip); 1196 + } else if (cmd == GPIO_GET_LINEINFO_UNWATCH_IOCTL) { 1197 + if (copy_from_user(&offset, ip, sizeof(offset))) 1198 + return -EFAULT; 1199 + 1200 + desc = gpiochip_get_desc(gc, offset); 1201 + if (IS_ERR(desc)) 1202 + return PTR_ERR(desc); 1203 + 1204 + clear_bit(gpio_chip_hwgpio(desc), priv->watched_lines); 1205 + return 0; 1313 1206 } 1314 1207 return -EINVAL; 1315 1208 } ··· 1294 1243 } 1295 1244 #endif 1296 1245 1246 + static struct gpio_chardev_data * 1247 + to_gpio_chardev_data(struct notifier_block *nb) 1248 + { 1249 + return container_of(nb, struct gpio_chardev_data, lineinfo_changed_nb); 1250 + } 1251 + 1252 + static int lineinfo_changed_notify(struct notifier_block *nb, 1253 + unsigned long action, void *data) 1254 + { 1255 + struct gpio_chardev_data *priv = to_gpio_chardev_data(nb); 1256 + struct gpioline_info_changed chg; 1257 + struct gpio_desc *desc = data; 1258 + int ret; 1259 + 1260 + if (!test_bit(gpio_chip_hwgpio(desc), priv->watched_lines)) 1261 + return NOTIFY_DONE; 1262 + 1263 + memset(&chg, 0, sizeof(chg)); 1264 + chg.info.line_offset = gpio_chip_hwgpio(desc); 1265 + chg.event_type = action; 1266 + chg.timestamp = ktime_get_ns(); 1267 + gpio_desc_to_lineinfo(desc, &chg.info); 1268 + 1269 + ret = kfifo_in_spinlocked(&priv->events, &chg, 1, &priv->wait.lock); 1270 + if (ret) 1271 + wake_up_poll(&priv->wait, EPOLLIN); 1272 + else 1273 + pr_debug_ratelimited("lineinfo event FIFO is full - event dropped\n"); 1274 + 1275 + return NOTIFY_OK; 1276 + } 1277 + 1278 + static __poll_t lineinfo_watch_poll(struct file *filep, 1279 + struct poll_table_struct *pollt) 1280 + { 1281 + struct gpio_chardev_data *priv = filep->private_data; 1282 + __poll_t events = 0; 1283 + 1284 + poll_wait(filep, &priv->wait, pollt); 1285 + 1286 + if (!kfifo_is_empty_spinlocked_noirqsave(&priv->events, 1287 + &priv->wait.lock)) 1288 + events = EPOLLIN | EPOLLRDNORM; 1289 + 1290 + return events; 1291 + } 1292 + 1293 + static ssize_t lineinfo_watch_read(struct file *filep, char __user *buf, 1294 + size_t count, loff_t *off) 1295 + { 1296 + struct gpio_chardev_data *priv = filep->private_data; 1297 + struct gpioline_info_changed event; 1298 + ssize_t bytes_read = 0; 1299 + int ret; 1300 + 1301 + if (count < sizeof(event)) 1302 + return -EINVAL; 1303 + 1304 + do { 1305 + spin_lock(&priv->wait.lock); 1306 + if (kfifo_is_empty(&priv->events)) { 1307 + if (bytes_read) { 1308 + spin_unlock(&priv->wait.lock); 1309 + return bytes_read; 1310 + } 1311 + 1312 + if (filep->f_flags & O_NONBLOCK) { 1313 + spin_unlock(&priv->wait.lock); 1314 + return -EAGAIN; 1315 + } 1316 + 1317 + ret = wait_event_interruptible_locked(priv->wait, 1318 + !kfifo_is_empty(&priv->events)); 1319 + if (ret) { 1320 + spin_unlock(&priv->wait.lock); 1321 + return ret; 1322 + } 1323 + } 1324 + 1325 + ret = kfifo_out(&priv->events, &event, 1); 1326 + spin_unlock(&priv->wait.lock); 1327 + if (ret != 1) { 1328 + ret = -EIO; 1329 + break; 1330 + /* We should never get here. See lineevent_read(). */ 1331 + } 1332 + 1333 + if (copy_to_user(buf + bytes_read, &event, sizeof(event))) 1334 + return -EFAULT; 1335 + bytes_read += sizeof(event); 1336 + } while (count >= bytes_read + sizeof(event)); 1337 + 1338 + return bytes_read; 1339 + } 1340 + 1297 1341 /** 1298 1342 * gpio_chrdev_open() - open the chardev for ioctl operations 1299 1343 * @inode: inode for this chardev ··· 1399 1253 { 1400 1254 struct gpio_device *gdev = container_of(inode->i_cdev, 1401 1255 struct gpio_device, chrdev); 1256 + struct gpio_chardev_data *priv; 1257 + int ret = -ENOMEM; 1402 1258 1403 1259 /* Fail on open if the backing gpiochip is gone */ 1404 1260 if (!gdev->chip) 1405 1261 return -ENODEV; 1406 - get_device(&gdev->dev); 1407 - filp->private_data = gdev; 1408 1262 1409 - return nonseekable_open(inode, filp); 1263 + priv = kzalloc(sizeof(*priv), GFP_KERNEL); 1264 + if (!priv) 1265 + return -ENOMEM; 1266 + 1267 + priv->watched_lines = bitmap_zalloc(gdev->chip->ngpio, GFP_KERNEL); 1268 + if (!priv->watched_lines) 1269 + goto out_free_priv; 1270 + 1271 + init_waitqueue_head(&priv->wait); 1272 + INIT_KFIFO(priv->events); 1273 + priv->gdev = gdev; 1274 + 1275 + priv->lineinfo_changed_nb.notifier_call = lineinfo_changed_notify; 1276 + ret = atomic_notifier_chain_register(&gdev->notifier, 1277 + &priv->lineinfo_changed_nb); 1278 + if (ret) 1279 + goto out_free_bitmap; 1280 + 1281 + get_device(&gdev->dev); 1282 + filp->private_data = priv; 1283 + 1284 + ret = nonseekable_open(inode, filp); 1285 + if (ret) 1286 + goto out_unregister_notifier; 1287 + 1288 + return ret; 1289 + 1290 + out_unregister_notifier: 1291 + atomic_notifier_chain_unregister(&gdev->notifier, 1292 + &priv->lineinfo_changed_nb); 1293 + out_free_bitmap: 1294 + bitmap_free(priv->watched_lines); 1295 + out_free_priv: 1296 + kfree(priv); 1297 + return ret; 1410 1298 } 1411 1299 1412 1300 /** ··· 1451 1271 */ 1452 1272 static int gpio_chrdev_release(struct inode *inode, struct file *filp) 1453 1273 { 1454 - struct gpio_device *gdev = container_of(inode->i_cdev, 1455 - struct gpio_device, chrdev); 1274 + struct gpio_chardev_data *priv = filp->private_data; 1275 + struct gpio_device *gdev = priv->gdev; 1456 1276 1277 + bitmap_free(priv->watched_lines); 1278 + atomic_notifier_chain_unregister(&gdev->notifier, 1279 + &priv->lineinfo_changed_nb); 1457 1280 put_device(&gdev->dev); 1281 + kfree(priv); 1282 + 1458 1283 return 0; 1459 1284 } 1460 - 1461 1285 1462 1286 static const struct file_operations gpio_fileops = { 1463 1287 .release = gpio_chrdev_release, 1464 1288 .open = gpio_chrdev_open, 1289 + .poll = lineinfo_watch_poll, 1290 + .read = lineinfo_watch_read, 1465 1291 .owner = THIS_MODULE, 1466 1292 .llseek = no_llseek, 1467 1293 .unlocked_ioctl = gpio_ioctl, ··· 1519 1333 return ret; 1520 1334 } 1521 1335 1522 - static void gpiochip_machine_hog(struct gpio_chip *chip, struct gpiod_hog *hog) 1336 + static void gpiochip_machine_hog(struct gpio_chip *gc, struct gpiod_hog *hog) 1523 1337 { 1524 1338 struct gpio_desc *desc; 1525 1339 int rv; 1526 1340 1527 - desc = gpiochip_get_desc(chip, hog->chip_hwnum); 1341 + desc = gpiochip_get_desc(gc, hog->chip_hwnum); 1528 1342 if (IS_ERR(desc)) { 1529 1343 pr_err("%s: unable to get GPIO desc: %ld\n", 1530 1344 __func__, PTR_ERR(desc)); ··· 1537 1351 rv = gpiod_hog(desc, hog->line_name, hog->lflags, hog->dflags); 1538 1352 if (rv) 1539 1353 pr_err("%s: unable to hog GPIO line (%s:%u): %d\n", 1540 - __func__, chip->label, hog->chip_hwnum, rv); 1354 + __func__, gc->label, hog->chip_hwnum, rv); 1541 1355 } 1542 1356 1543 - static void machine_gpiochip_add(struct gpio_chip *chip) 1357 + static void machine_gpiochip_add(struct gpio_chip *gc) 1544 1358 { 1545 1359 struct gpiod_hog *hog; 1546 1360 1547 1361 mutex_lock(&gpio_machine_hogs_mutex); 1548 1362 1549 1363 list_for_each_entry(hog, &gpio_machine_hogs, list) { 1550 - if (!strcmp(chip->label, hog->chip_label)) 1551 - gpiochip_machine_hog(chip, hog); 1364 + if (!strcmp(gc->label, hog->chip_label)) 1365 + gpiochip_machine_hog(gc, hog); 1552 1366 } 1553 1367 1554 1368 mutex_unlock(&gpio_machine_hogs_mutex); ··· 1567 1381 } 1568 1382 } 1569 1383 1570 - int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, 1384 + int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, 1571 1385 struct lock_class_key *lock_key, 1572 1386 struct lock_class_key *request_key) 1573 1387 { 1574 1388 unsigned long flags; 1575 1389 int ret = 0; 1576 1390 unsigned i; 1577 - int base = chip->base; 1391 + int base = gc->base; 1578 1392 struct gpio_device *gdev; 1579 1393 1580 1394 /* ··· 1585 1399 if (!gdev) 1586 1400 return -ENOMEM; 1587 1401 gdev->dev.bus = &gpio_bus_type; 1588 - gdev->chip = chip; 1589 - chip->gpiodev = gdev; 1590 - if (chip->parent) { 1591 - gdev->dev.parent = chip->parent; 1592 - gdev->dev.of_node = chip->parent->of_node; 1402 + gdev->chip = gc; 1403 + gc->gpiodev = gdev; 1404 + if (gc->parent) { 1405 + gdev->dev.parent = gc->parent; 1406 + gdev->dev.of_node = gc->parent->of_node; 1593 1407 } 1594 1408 1595 1409 #ifdef CONFIG_OF_GPIO 1596 1410 /* If the gpiochip has an assigned OF node this takes precedence */ 1597 - if (chip->of_node) 1598 - gdev->dev.of_node = chip->of_node; 1411 + if (gc->of_node) 1412 + gdev->dev.of_node = gc->of_node; 1599 1413 else 1600 - chip->of_node = gdev->dev.of_node; 1414 + gc->of_node = gdev->dev.of_node; 1601 1415 #endif 1602 1416 1603 1417 gdev->id = ida_simple_get(&gpio_ida, 0, 0, GFP_KERNEL); ··· 1608 1422 dev_set_name(&gdev->dev, GPIOCHIP_NAME "%d", gdev->id); 1609 1423 device_initialize(&gdev->dev); 1610 1424 dev_set_drvdata(&gdev->dev, gdev); 1611 - if (chip->parent && chip->parent->driver) 1612 - gdev->owner = chip->parent->driver->owner; 1613 - else if (chip->owner) 1425 + if (gc->parent && gc->parent->driver) 1426 + gdev->owner = gc->parent->driver->owner; 1427 + else if (gc->owner) 1614 1428 /* TODO: remove chip->owner */ 1615 - gdev->owner = chip->owner; 1429 + gdev->owner = gc->owner; 1616 1430 else 1617 1431 gdev->owner = THIS_MODULE; 1618 1432 1619 - gdev->descs = kcalloc(chip->ngpio, sizeof(gdev->descs[0]), GFP_KERNEL); 1433 + gdev->descs = kcalloc(gc->ngpio, sizeof(gdev->descs[0]), GFP_KERNEL); 1620 1434 if (!gdev->descs) { 1621 1435 ret = -ENOMEM; 1622 1436 goto err_free_ida; 1623 1437 } 1624 1438 1625 - if (chip->ngpio == 0) { 1626 - chip_err(chip, "tried to insert a GPIO chip with zero lines\n"); 1439 + if (gc->ngpio == 0) { 1440 + chip_err(gc, "tried to insert a GPIO chip with zero lines\n"); 1627 1441 ret = -EINVAL; 1628 1442 goto err_free_descs; 1629 1443 } 1630 1444 1631 - if (chip->ngpio > FASTPATH_NGPIO) 1632 - chip_warn(chip, "line cnt %u is greater than fast path cnt %u\n", 1633 - chip->ngpio, FASTPATH_NGPIO); 1445 + if (gc->ngpio > FASTPATH_NGPIO) 1446 + chip_warn(gc, "line cnt %u is greater than fast path cnt %u\n", 1447 + gc->ngpio, FASTPATH_NGPIO); 1634 1448 1635 - gdev->label = kstrdup_const(chip->label ?: "unknown", GFP_KERNEL); 1449 + gdev->label = kstrdup_const(gc->label ?: "unknown", GFP_KERNEL); 1636 1450 if (!gdev->label) { 1637 1451 ret = -ENOMEM; 1638 1452 goto err_free_descs; 1639 1453 } 1640 1454 1641 - gdev->ngpio = chip->ngpio; 1455 + gdev->ngpio = gc->ngpio; 1642 1456 gdev->data = data; 1643 1457 1644 1458 spin_lock_irqsave(&gpio_lock, flags); ··· 1651 1465 * of the sysfs interface anyways. 1652 1466 */ 1653 1467 if (base < 0) { 1654 - base = gpiochip_find_base(chip->ngpio); 1468 + base = gpiochip_find_base(gc->ngpio); 1655 1469 if (base < 0) { 1656 1470 ret = base; 1657 1471 spin_unlock_irqrestore(&gpio_lock, flags); ··· 1663 1477 * see if anyone makes use of this, else drop this and assign 1664 1478 * a poison instead. 1665 1479 */ 1666 - chip->base = base; 1480 + gc->base = base; 1667 1481 } 1668 1482 gdev->base = base; 1669 1483 ··· 1673 1487 goto err_free_label; 1674 1488 } 1675 1489 1676 - for (i = 0; i < chip->ngpio; i++) 1490 + for (i = 0; i < gc->ngpio; i++) 1677 1491 gdev->descs[i].gdev = gdev; 1678 1492 1679 1493 spin_unlock_irqrestore(&gpio_lock, flags); 1494 + 1495 + ATOMIC_INIT_NOTIFIER_HEAD(&gdev->notifier); 1680 1496 1681 1497 #ifdef CONFIG_PINCTRL 1682 1498 INIT_LIST_HEAD(&gdev->pin_ranges); 1683 1499 #endif 1684 1500 1685 - ret = gpiochip_set_desc_names(chip); 1501 + ret = gpiochip_set_desc_names(gc); 1686 1502 if (ret) 1687 1503 goto err_remove_from_list; 1688 1504 1689 - ret = gpiochip_alloc_valid_mask(chip); 1505 + ret = gpiochip_alloc_valid_mask(gc); 1690 1506 if (ret) 1691 1507 goto err_remove_from_list; 1692 1508 1693 - ret = of_gpiochip_add(chip); 1509 + ret = of_gpiochip_add(gc); 1694 1510 if (ret) 1695 1511 goto err_free_gpiochip_mask; 1696 1512 1697 - ret = gpiochip_init_valid_mask(chip); 1513 + ret = gpiochip_init_valid_mask(gc); 1698 1514 if (ret) 1699 1515 goto err_remove_of_chip; 1700 1516 1701 - for (i = 0; i < chip->ngpio; i++) { 1517 + for (i = 0; i < gc->ngpio; i++) { 1702 1518 struct gpio_desc *desc = &gdev->descs[i]; 1703 1519 1704 - if (chip->get_direction && gpiochip_line_is_valid(chip, i)) { 1520 + if (gc->get_direction && gpiochip_line_is_valid(gc, i)) { 1705 1521 assign_bit(FLAG_IS_OUT, 1706 - &desc->flags, !chip->get_direction(chip, i)); 1522 + &desc->flags, !gc->get_direction(gc, i)); 1707 1523 } else { 1708 1524 assign_bit(FLAG_IS_OUT, 1709 - &desc->flags, !chip->direction_input); 1525 + &desc->flags, !gc->direction_input); 1710 1526 } 1711 1527 } 1712 1528 1713 - ret = gpiochip_add_pin_ranges(chip); 1529 + ret = gpiochip_add_pin_ranges(gc); 1714 1530 if (ret) 1715 1531 goto err_remove_of_chip; 1716 1532 1717 - acpi_gpiochip_add(chip); 1533 + acpi_gpiochip_add(gc); 1718 1534 1719 - machine_gpiochip_add(chip); 1535 + machine_gpiochip_add(gc); 1720 1536 1721 - ret = gpiochip_irqchip_init_valid_mask(chip); 1537 + ret = gpiochip_irqchip_init_valid_mask(gc); 1722 1538 if (ret) 1723 1539 goto err_remove_acpi_chip; 1724 1540 1725 - ret = gpiochip_irqchip_init_hw(chip); 1541 + ret = gpiochip_irqchip_init_hw(gc); 1726 1542 if (ret) 1727 1543 goto err_remove_acpi_chip; 1728 1544 1729 - ret = gpiochip_add_irqchip(chip, lock_key, request_key); 1545 + ret = gpiochip_add_irqchip(gc, lock_key, request_key); 1730 1546 if (ret) 1731 1547 goto err_remove_irqchip_mask; 1732 1548 ··· 1748 1560 return 0; 1749 1561 1750 1562 err_remove_irqchip: 1751 - gpiochip_irqchip_remove(chip); 1563 + gpiochip_irqchip_remove(gc); 1752 1564 err_remove_irqchip_mask: 1753 - gpiochip_irqchip_free_valid_mask(chip); 1565 + gpiochip_irqchip_free_valid_mask(gc); 1754 1566 err_remove_acpi_chip: 1755 - acpi_gpiochip_remove(chip); 1567 + acpi_gpiochip_remove(gc); 1756 1568 err_remove_of_chip: 1757 - gpiochip_free_hogs(chip); 1758 - of_gpiochip_remove(chip); 1569 + gpiochip_free_hogs(gc); 1570 + of_gpiochip_remove(gc); 1759 1571 err_free_gpiochip_mask: 1760 - gpiochip_remove_pin_ranges(chip); 1761 - gpiochip_free_valid_mask(chip); 1572 + gpiochip_remove_pin_ranges(gc); 1573 + gpiochip_free_valid_mask(gc); 1762 1574 err_remove_from_list: 1763 1575 spin_lock_irqsave(&gpio_lock, flags); 1764 1576 list_del(&gdev->list); ··· 1773 1585 /* failures here can mean systems won't boot... */ 1774 1586 pr_err("%s: GPIOs %d..%d (%s) failed to register, %d\n", __func__, 1775 1587 gdev->base, gdev->base + gdev->ngpio - 1, 1776 - chip->label ? : "generic", ret); 1588 + gc->label ? : "generic", ret); 1777 1589 kfree(gdev); 1778 1590 return ret; 1779 1591 } ··· 1781 1593 1782 1594 /** 1783 1595 * gpiochip_get_data() - get per-subdriver data for the chip 1784 - * @chip: GPIO chip 1596 + * @gc: GPIO chip 1785 1597 * 1786 1598 * Returns: 1787 1599 * The per-subdriver data for the chip. 1788 1600 */ 1789 - void *gpiochip_get_data(struct gpio_chip *chip) 1601 + void *gpiochip_get_data(struct gpio_chip *gc) 1790 1602 { 1791 - return chip->gpiodev->data; 1603 + return gc->gpiodev->data; 1792 1604 } 1793 1605 EXPORT_SYMBOL_GPL(gpiochip_get_data); 1794 1606 1795 1607 /** 1796 1608 * gpiochip_remove() - unregister a gpio_chip 1797 - * @chip: the chip to unregister 1609 + * @gc: the chip to unregister 1798 1610 * 1799 1611 * A gpio_chip with any GPIOs still requested may not be removed. 1800 1612 */ 1801 - void gpiochip_remove(struct gpio_chip *chip) 1613 + void gpiochip_remove(struct gpio_chip *gc) 1802 1614 { 1803 - struct gpio_device *gdev = chip->gpiodev; 1804 - struct gpio_desc *desc; 1615 + struct gpio_device *gdev = gc->gpiodev; 1805 1616 unsigned long flags; 1806 - unsigned i; 1807 - bool requested = false; 1617 + unsigned int i; 1808 1618 1809 1619 /* FIXME: should the legacy sysfs handling be moved to gpio_device? */ 1810 1620 gpiochip_sysfs_unregister(gdev); 1811 - gpiochip_free_hogs(chip); 1621 + gpiochip_free_hogs(gc); 1812 1622 /* Numb the device, cancelling all outstanding operations */ 1813 1623 gdev->chip = NULL; 1814 - gpiochip_irqchip_remove(chip); 1815 - acpi_gpiochip_remove(chip); 1816 - of_gpiochip_remove(chip); 1817 - gpiochip_remove_pin_ranges(chip); 1818 - gpiochip_free_valid_mask(chip); 1624 + gpiochip_irqchip_remove(gc); 1625 + acpi_gpiochip_remove(gc); 1626 + of_gpiochip_remove(gc); 1627 + gpiochip_remove_pin_ranges(gc); 1628 + gpiochip_free_valid_mask(gc); 1819 1629 /* 1820 1630 * We accept no more calls into the driver from this point, so 1821 1631 * NULL the driver data pointer ··· 1822 1636 1823 1637 spin_lock_irqsave(&gpio_lock, flags); 1824 1638 for (i = 0; i < gdev->ngpio; i++) { 1825 - desc = &gdev->descs[i]; 1826 - if (test_bit(FLAG_REQUESTED, &desc->flags)) 1827 - requested = true; 1639 + if (gpiochip_is_requested(gc, i)) 1640 + break; 1828 1641 } 1829 1642 spin_unlock_irqrestore(&gpio_lock, flags); 1830 1643 1831 - if (requested) 1644 + if (i != gdev->ngpio) 1832 1645 dev_crit(&gdev->dev, 1833 1646 "REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n"); 1834 1647 ··· 1842 1657 } 1843 1658 EXPORT_SYMBOL_GPL(gpiochip_remove); 1844 1659 1845 - static void devm_gpio_chip_release(struct device *dev, void *res) 1846 - { 1847 - struct gpio_chip *chip = *(struct gpio_chip **)res; 1848 - 1849 - gpiochip_remove(chip); 1850 - } 1851 - 1852 - /** 1853 - * devm_gpiochip_add_data() - Resource managed gpiochip_add_data() 1854 - * @dev: pointer to the device that gpio_chip belongs to. 1855 - * @chip: the chip to register, with chip->base initialized 1856 - * @data: driver-private data associated with this chip 1857 - * 1858 - * Context: potentially before irqs will work 1859 - * 1860 - * The gpio chip automatically be released when the device is unbound. 1861 - * 1862 - * Returns: 1863 - * A negative errno if the chip can't be registered, such as because the 1864 - * chip->base is invalid or already associated with a different chip. 1865 - * Otherwise it returns zero as a success code. 1866 - */ 1867 - int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *chip, 1868 - void *data) 1869 - { 1870 - struct gpio_chip **ptr; 1871 - int ret; 1872 - 1873 - ptr = devres_alloc(devm_gpio_chip_release, sizeof(*ptr), 1874 - GFP_KERNEL); 1875 - if (!ptr) 1876 - return -ENOMEM; 1877 - 1878 - ret = gpiochip_add_data(chip, data); 1879 - if (ret < 0) { 1880 - devres_free(ptr); 1881 - return ret; 1882 - } 1883 - 1884 - *ptr = chip; 1885 - devres_add(dev, ptr); 1886 - 1887 - return 0; 1888 - } 1889 - EXPORT_SYMBOL_GPL(devm_gpiochip_add_data); 1890 - 1891 1660 /** 1892 1661 * gpiochip_find() - iterator for locating a specific gpio_chip 1893 1662 * @data: data to pass to match function ··· 1854 1715 * more gpio_chips. 1855 1716 */ 1856 1717 struct gpio_chip *gpiochip_find(void *data, 1857 - int (*match)(struct gpio_chip *chip, 1718 + int (*match)(struct gpio_chip *gc, 1858 1719 void *data)) 1859 1720 { 1860 1721 struct gpio_device *gdev; 1861 - struct gpio_chip *chip = NULL; 1722 + struct gpio_chip *gc = NULL; 1862 1723 unsigned long flags; 1863 1724 1864 1725 spin_lock_irqsave(&gpio_lock, flags); 1865 1726 list_for_each_entry(gdev, &gpio_devices, list) 1866 1727 if (gdev->chip && match(gdev->chip, data)) { 1867 - chip = gdev->chip; 1728 + gc = gdev->chip; 1868 1729 break; 1869 1730 } 1870 1731 1871 1732 spin_unlock_irqrestore(&gpio_lock, flags); 1872 1733 1873 - return chip; 1734 + return gc; 1874 1735 } 1875 1736 EXPORT_SYMBOL_GPL(gpiochip_find); 1876 1737 1877 - static int gpiochip_match_name(struct gpio_chip *chip, void *data) 1738 + static int gpiochip_match_name(struct gpio_chip *gc, void *data) 1878 1739 { 1879 1740 const char *name = data; 1880 1741 1881 - return !strcmp(chip->label, name); 1742 + return !strcmp(gc->label, name); 1882 1743 } 1883 1744 1884 1745 static struct gpio_chip *find_chip_by_name(const char *name) ··· 1918 1779 return 0; 1919 1780 } 1920 1781 1921 - static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gpiochip) 1782 + static void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc) 1922 1783 { 1923 - bitmap_free(gpiochip->irq.valid_mask); 1924 - gpiochip->irq.valid_mask = NULL; 1784 + bitmap_free(gc->irq.valid_mask); 1785 + gc->irq.valid_mask = NULL; 1925 1786 } 1926 1787 1927 - bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gpiochip, 1788 + bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gc, 1928 1789 unsigned int offset) 1929 1790 { 1930 - if (!gpiochip_line_is_valid(gpiochip, offset)) 1791 + if (!gpiochip_line_is_valid(gc, offset)) 1931 1792 return false; 1932 1793 /* No mask means all valid */ 1933 - if (likely(!gpiochip->irq.valid_mask)) 1794 + if (likely(!gc->irq.valid_mask)) 1934 1795 return true; 1935 - return test_bit(offset, gpiochip->irq.valid_mask); 1796 + return test_bit(offset, gc->irq.valid_mask); 1936 1797 } 1937 1798 EXPORT_SYMBOL_GPL(gpiochip_irqchip_irq_valid); 1938 1799 ··· 1984 1845 1985 1846 /** 1986 1847 * gpiochip_set_nested_irqchip() - connects a nested irqchip to a gpiochip 1987 - * @gpiochip: the gpiochip to set the irqchip nested handler to 1848 + * @gc: the gpiochip to set the irqchip nested handler to 1988 1849 * @irqchip: the irqchip to nest to the gpiochip 1989 1850 * @parent_irq: the irq number corresponding to the parent IRQ for this 1990 1851 * nested irqchip 1991 1852 */ 1992 - void gpiochip_set_nested_irqchip(struct gpio_chip *gpiochip, 1853 + void gpiochip_set_nested_irqchip(struct gpio_chip *gc, 1993 1854 struct irq_chip *irqchip, 1994 1855 unsigned int parent_irq) 1995 1856 { 1996 - gpiochip_set_cascaded_irqchip(gpiochip, parent_irq, NULL); 1857 + gpiochip_set_cascaded_irqchip(gc, parent_irq, NULL); 1997 1858 } 1998 1859 EXPORT_SYMBOL_GPL(gpiochip_set_nested_irqchip); 1999 1860 ··· 2170 2031 return ret; 2171 2032 } 2172 2033 2173 - static unsigned int gpiochip_child_offset_to_irq_noop(struct gpio_chip *chip, 2034 + static unsigned int gpiochip_child_offset_to_irq_noop(struct gpio_chip *gc, 2174 2035 unsigned int offset) 2175 2036 { 2176 2037 return offset; ··· 2230 2091 return !!gc->irq.parent_domain; 2231 2092 } 2232 2093 2233 - void *gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *chip, 2094 + void *gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *gc, 2234 2095 unsigned int parent_hwirq, 2235 2096 unsigned int parent_type) 2236 2097 { ··· 2240 2101 if (!fwspec) 2241 2102 return NULL; 2242 2103 2243 - fwspec->fwnode = chip->irq.parent_domain->fwnode; 2104 + fwspec->fwnode = gc->irq.parent_domain->fwnode; 2244 2105 fwspec->param_count = 2; 2245 2106 fwspec->param[0] = parent_hwirq; 2246 2107 fwspec->param[1] = parent_type; ··· 2249 2110 } 2250 2111 EXPORT_SYMBOL_GPL(gpiochip_populate_parent_fwspec_twocell); 2251 2112 2252 - void *gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *chip, 2113 + void *gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *gc, 2253 2114 unsigned int parent_hwirq, 2254 2115 unsigned int parent_type) 2255 2116 { ··· 2259 2120 if (!fwspec) 2260 2121 return NULL; 2261 2122 2262 - fwspec->fwnode = chip->irq.parent_domain->fwnode; 2123 + fwspec->fwnode = gc->irq.parent_domain->fwnode; 2263 2124 fwspec->param_count = 4; 2264 2125 fwspec->param[0] = 0; 2265 2126 fwspec->param[1] = parent_hwirq; ··· 2297 2158 int gpiochip_irq_map(struct irq_domain *d, unsigned int irq, 2298 2159 irq_hw_number_t hwirq) 2299 2160 { 2300 - struct gpio_chip *chip = d->host_data; 2161 + struct gpio_chip *gc = d->host_data; 2301 2162 int ret = 0; 2302 2163 2303 - if (!gpiochip_irqchip_irq_valid(chip, hwirq)) 2164 + if (!gpiochip_irqchip_irq_valid(gc, hwirq)) 2304 2165 return -ENXIO; 2305 2166 2306 - irq_set_chip_data(irq, chip); 2167 + irq_set_chip_data(irq, gc); 2307 2168 /* 2308 2169 * This lock class tells lockdep that GPIO irqs are in a different 2309 2170 * category than their parents, so it won't report false recursion. 2310 2171 */ 2311 - irq_set_lockdep_class(irq, chip->irq.lock_key, chip->irq.request_key); 2312 - irq_set_chip_and_handler(irq, chip->irq.chip, chip->irq.handler); 2172 + irq_set_lockdep_class(irq, gc->irq.lock_key, gc->irq.request_key); 2173 + irq_set_chip_and_handler(irq, gc->irq.chip, gc->irq.handler); 2313 2174 /* Chips that use nested thread handlers have them marked */ 2314 - if (chip->irq.threaded) 2175 + if (gc->irq.threaded) 2315 2176 irq_set_nested_thread(irq, 1); 2316 2177 irq_set_noprobe(irq); 2317 2178 2318 - if (chip->irq.num_parents == 1) 2319 - ret = irq_set_parent(irq, chip->irq.parents[0]); 2320 - else if (chip->irq.map) 2321 - ret = irq_set_parent(irq, chip->irq.map[hwirq]); 2179 + if (gc->irq.num_parents == 1) 2180 + ret = irq_set_parent(irq, gc->irq.parents[0]); 2181 + else if (gc->irq.map) 2182 + ret = irq_set_parent(irq, gc->irq.map[hwirq]); 2322 2183 2323 2184 if (ret < 0) 2324 2185 return ret; ··· 2327 2188 * No set-up of the hardware will happen if IRQ_TYPE_NONE 2328 2189 * is passed as default type. 2329 2190 */ 2330 - if (chip->irq.default_type != IRQ_TYPE_NONE) 2331 - irq_set_irq_type(irq, chip->irq.default_type); 2191 + if (gc->irq.default_type != IRQ_TYPE_NONE) 2192 + irq_set_irq_type(irq, gc->irq.default_type); 2332 2193 2333 2194 return 0; 2334 2195 } ··· 2336 2197 2337 2198 void gpiochip_irq_unmap(struct irq_domain *d, unsigned int irq) 2338 2199 { 2339 - struct gpio_chip *chip = d->host_data; 2200 + struct gpio_chip *gc = d->host_data; 2340 2201 2341 - if (chip->irq.threaded) 2202 + if (gc->irq.threaded) 2342 2203 irq_set_nested_thread(irq, 0); 2343 2204 irq_set_chip_and_handler(irq, NULL, NULL); 2344 2205 irq_set_chip_data(irq, NULL); ··· 2370 2231 int gpiochip_irq_domain_activate(struct irq_domain *domain, 2371 2232 struct irq_data *data, bool reserve) 2372 2233 { 2373 - struct gpio_chip *chip = domain->host_data; 2234 + struct gpio_chip *gc = domain->host_data; 2374 2235 2375 - return gpiochip_lock_as_irq(chip, data->hwirq); 2236 + return gpiochip_lock_as_irq(gc, data->hwirq); 2376 2237 } 2377 2238 EXPORT_SYMBOL_GPL(gpiochip_irq_domain_activate); 2378 2239 ··· 2388 2249 void gpiochip_irq_domain_deactivate(struct irq_domain *domain, 2389 2250 struct irq_data *data) 2390 2251 { 2391 - struct gpio_chip *chip = domain->host_data; 2252 + struct gpio_chip *gc = domain->host_data; 2392 2253 2393 - return gpiochip_unlock_as_irq(chip, data->hwirq); 2254 + return gpiochip_unlock_as_irq(gc, data->hwirq); 2394 2255 } 2395 2256 EXPORT_SYMBOL_GPL(gpiochip_irq_domain_deactivate); 2396 2257 2397 - static int gpiochip_to_irq(struct gpio_chip *chip, unsigned offset) 2258 + static int gpiochip_to_irq(struct gpio_chip *gc, unsigned offset) 2398 2259 { 2399 - struct irq_domain *domain = chip->irq.domain; 2260 + struct irq_domain *domain = gc->irq.domain; 2400 2261 2401 - if (!gpiochip_irqchip_irq_valid(chip, offset)) 2262 + if (!gpiochip_irqchip_irq_valid(gc, offset)) 2402 2263 return -ENXIO; 2403 2264 2404 2265 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY ··· 2407 2268 2408 2269 spec.fwnode = domain->fwnode; 2409 2270 spec.param_count = 2; 2410 - spec.param[0] = chip->irq.child_offset_to_irq(chip, offset); 2271 + spec.param[0] = gc->irq.child_offset_to_irq(gc, offset); 2411 2272 spec.param[1] = IRQ_TYPE_NONE; 2412 2273 2413 2274 return irq_create_fwspec_mapping(&spec); ··· 2419 2280 2420 2281 static int gpiochip_irq_reqres(struct irq_data *d) 2421 2282 { 2422 - struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 2283 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 2423 2284 2424 - return gpiochip_reqres_irq(chip, d->hwirq); 2285 + return gpiochip_reqres_irq(gc, d->hwirq); 2425 2286 } 2426 2287 2427 2288 static void gpiochip_irq_relres(struct irq_data *d) 2428 2289 { 2429 - struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 2290 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 2430 2291 2431 - gpiochip_relres_irq(chip, d->hwirq); 2292 + gpiochip_relres_irq(gc, d->hwirq); 2432 2293 } 2433 2294 2434 2295 static void gpiochip_irq_enable(struct irq_data *d) 2435 2296 { 2436 - struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 2297 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 2437 2298 2438 - gpiochip_enable_irq(chip, d->hwirq); 2439 - if (chip->irq.irq_enable) 2440 - chip->irq.irq_enable(d); 2299 + gpiochip_enable_irq(gc, d->hwirq); 2300 + if (gc->irq.irq_enable) 2301 + gc->irq.irq_enable(d); 2441 2302 else 2442 - chip->irq.chip->irq_unmask(d); 2303 + gc->irq.chip->irq_unmask(d); 2443 2304 } 2444 2305 2445 2306 static void gpiochip_irq_disable(struct irq_data *d) 2446 2307 { 2447 - struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 2308 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 2448 2309 2449 2310 /* 2450 2311 * Since we override .irq_disable() we need to mimic the ··· 2453 2314 * behaviour of mask_irq() which calls .irq_mask() if 2454 2315 * it exists. 2455 2316 */ 2456 - if (chip->irq.irq_disable) 2457 - chip->irq.irq_disable(d); 2458 - else if (chip->irq.chip->irq_mask) 2459 - chip->irq.chip->irq_mask(d); 2460 - gpiochip_disable_irq(chip, d->hwirq); 2317 + if (gc->irq.irq_disable) 2318 + gc->irq.irq_disable(d); 2319 + else if (gc->irq.chip->irq_mask) 2320 + gc->irq.chip->irq_mask(d); 2321 + gpiochip_disable_irq(gc, d->hwirq); 2461 2322 } 2462 2323 2463 - static void gpiochip_set_irq_hooks(struct gpio_chip *gpiochip) 2324 + static void gpiochip_set_irq_hooks(struct gpio_chip *gc) 2464 2325 { 2465 - struct irq_chip *irqchip = gpiochip->irq.chip; 2326 + struct irq_chip *irqchip = gc->irq.chip; 2466 2327 2467 2328 if (!irqchip->irq_request_resources && 2468 2329 !irqchip->irq_release_resources) { 2469 2330 irqchip->irq_request_resources = gpiochip_irq_reqres; 2470 2331 irqchip->irq_release_resources = gpiochip_irq_relres; 2471 2332 } 2472 - if (WARN_ON(gpiochip->irq.irq_enable)) 2333 + if (WARN_ON(gc->irq.irq_enable)) 2473 2334 return; 2474 2335 /* Check if the irqchip already has this hook... */ 2475 2336 if (irqchip->irq_enable == gpiochip_irq_enable) { ··· 2477 2338 * ...and if so, give a gentle warning that this is bad 2478 2339 * practice. 2479 2340 */ 2480 - chip_info(gpiochip, 2341 + chip_info(gc, 2481 2342 "detected irqchip that is shared with multiple gpiochips: please fix the driver.\n"); 2482 2343 return; 2483 2344 } 2484 - gpiochip->irq.irq_enable = irqchip->irq_enable; 2485 - gpiochip->irq.irq_disable = irqchip->irq_disable; 2345 + gc->irq.irq_enable = irqchip->irq_enable; 2346 + gc->irq.irq_disable = irqchip->irq_disable; 2486 2347 irqchip->irq_enable = gpiochip_irq_enable; 2487 2348 irqchip->irq_disable = gpiochip_irq_disable; 2488 2349 } 2489 2350 2490 2351 /** 2491 2352 * gpiochip_add_irqchip() - adds an IRQ chip to a GPIO chip 2492 - * @gpiochip: the GPIO chip to add the IRQ chip to 2353 + * @gc: the GPIO chip to add the IRQ chip to 2493 2354 * @lock_key: lockdep class for IRQ lock 2494 2355 * @request_key: lockdep class for IRQ request 2495 2356 */ 2496 - static int gpiochip_add_irqchip(struct gpio_chip *gpiochip, 2357 + static int gpiochip_add_irqchip(struct gpio_chip *gc, 2497 2358 struct lock_class_key *lock_key, 2498 2359 struct lock_class_key *request_key) 2499 2360 { 2500 - struct irq_chip *irqchip = gpiochip->irq.chip; 2361 + struct irq_chip *irqchip = gc->irq.chip; 2501 2362 const struct irq_domain_ops *ops = NULL; 2502 2363 struct device_node *np; 2503 2364 unsigned int type; ··· 2506 2367 if (!irqchip) 2507 2368 return 0; 2508 2369 2509 - if (gpiochip->irq.parent_handler && gpiochip->can_sleep) { 2510 - chip_err(gpiochip, "you cannot have chained interrupts on a chip that may sleep\n"); 2370 + if (gc->irq.parent_handler && gc->can_sleep) { 2371 + chip_err(gc, "you cannot have chained interrupts on a chip that may sleep\n"); 2511 2372 return -EINVAL; 2512 2373 } 2513 2374 2514 - np = gpiochip->gpiodev->dev.of_node; 2515 - type = gpiochip->irq.default_type; 2375 + np = gc->gpiodev->dev.of_node; 2376 + type = gc->irq.default_type; 2516 2377 2517 2378 /* 2518 2379 * Specifying a default trigger is a terrible idea if DT or ACPI is ··· 2523 2384 "%s: Ignoring %u default trigger\n", np->full_name, type)) 2524 2385 type = IRQ_TYPE_NONE; 2525 2386 2526 - if (has_acpi_companion(gpiochip->parent) && type != IRQ_TYPE_NONE) { 2527 - acpi_handle_warn(ACPI_HANDLE(gpiochip->parent), 2387 + if (has_acpi_companion(gc->parent) && type != IRQ_TYPE_NONE) { 2388 + acpi_handle_warn(ACPI_HANDLE(gc->parent), 2528 2389 "Ignoring %u default trigger\n", type); 2529 2390 type = IRQ_TYPE_NONE; 2530 2391 } 2531 2392 2532 - gpiochip->to_irq = gpiochip_to_irq; 2533 - gpiochip->irq.default_type = type; 2534 - gpiochip->irq.lock_key = lock_key; 2535 - gpiochip->irq.request_key = request_key; 2393 + gc->to_irq = gpiochip_to_irq; 2394 + gc->irq.default_type = type; 2395 + gc->irq.lock_key = lock_key; 2396 + gc->irq.request_key = request_key; 2536 2397 2537 2398 /* If a parent irqdomain is provided, let's build a hierarchy */ 2538 - if (gpiochip_hierarchy_is_hierarchical(gpiochip)) { 2539 - int ret = gpiochip_hierarchy_add_domain(gpiochip); 2399 + if (gpiochip_hierarchy_is_hierarchical(gc)) { 2400 + int ret = gpiochip_hierarchy_add_domain(gc); 2540 2401 if (ret) 2541 2402 return ret; 2542 2403 } else { 2543 2404 /* Some drivers provide custom irqdomain ops */ 2544 - if (gpiochip->irq.domain_ops) 2545 - ops = gpiochip->irq.domain_ops; 2405 + if (gc->irq.domain_ops) 2406 + ops = gc->irq.domain_ops; 2546 2407 2547 2408 if (!ops) 2548 2409 ops = &gpiochip_domain_ops; 2549 - gpiochip->irq.domain = irq_domain_add_simple(np, 2550 - gpiochip->ngpio, 2551 - gpiochip->irq.first, 2552 - ops, gpiochip); 2553 - if (!gpiochip->irq.domain) 2410 + gc->irq.domain = irq_domain_add_simple(np, 2411 + gc->ngpio, 2412 + gc->irq.first, 2413 + ops, gc); 2414 + if (!gc->irq.domain) 2554 2415 return -EINVAL; 2555 2416 } 2556 2417 2557 - if (gpiochip->irq.parent_handler) { 2558 - void *data = gpiochip->irq.parent_handler_data ?: gpiochip; 2418 + if (gc->irq.parent_handler) { 2419 + void *data = gc->irq.parent_handler_data ?: gc; 2559 2420 2560 - for (i = 0; i < gpiochip->irq.num_parents; i++) { 2421 + for (i = 0; i < gc->irq.num_parents; i++) { 2561 2422 /* 2562 2423 * The parent IRQ chip is already using the chip_data 2563 2424 * for this IRQ chip, so our callbacks simply use the 2564 2425 * handler_data. 2565 2426 */ 2566 - irq_set_chained_handler_and_data(gpiochip->irq.parents[i], 2567 - gpiochip->irq.parent_handler, 2427 + irq_set_chained_handler_and_data(gc->irq.parents[i], 2428 + gc->irq.parent_handler, 2568 2429 data); 2569 2430 } 2570 2431 } 2571 2432 2572 - gpiochip_set_irq_hooks(gpiochip); 2433 + gpiochip_set_irq_hooks(gc); 2573 2434 2574 - acpi_gpiochip_request_interrupts(gpiochip); 2435 + acpi_gpiochip_request_interrupts(gc); 2575 2436 2576 2437 return 0; 2577 2438 } 2578 2439 2579 2440 /** 2580 2441 * gpiochip_irqchip_remove() - removes an irqchip added to a gpiochip 2581 - * @gpiochip: the gpiochip to remove the irqchip from 2442 + * @gc: the gpiochip to remove the irqchip from 2582 2443 * 2583 2444 * This is called only from gpiochip_remove() 2584 2445 */ 2585 - static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip) 2446 + static void gpiochip_irqchip_remove(struct gpio_chip *gc) 2586 2447 { 2587 - struct irq_chip *irqchip = gpiochip->irq.chip; 2448 + struct irq_chip *irqchip = gc->irq.chip; 2588 2449 unsigned int offset; 2589 2450 2590 - acpi_gpiochip_free_interrupts(gpiochip); 2451 + acpi_gpiochip_free_interrupts(gc); 2591 2452 2592 - if (irqchip && gpiochip->irq.parent_handler) { 2593 - struct gpio_irq_chip *irq = &gpiochip->irq; 2453 + if (irqchip && gc->irq.parent_handler) { 2454 + struct gpio_irq_chip *irq = &gc->irq; 2594 2455 unsigned int i; 2595 2456 2596 2457 for (i = 0; i < irq->num_parents; i++) ··· 2599 2460 } 2600 2461 2601 2462 /* Remove all IRQ mappings and delete the domain */ 2602 - if (gpiochip->irq.domain) { 2463 + if (gc->irq.domain) { 2603 2464 unsigned int irq; 2604 2465 2605 - for (offset = 0; offset < gpiochip->ngpio; offset++) { 2606 - if (!gpiochip_irqchip_irq_valid(gpiochip, offset)) 2466 + for (offset = 0; offset < gc->ngpio; offset++) { 2467 + if (!gpiochip_irqchip_irq_valid(gc, offset)) 2607 2468 continue; 2608 2469 2609 - irq = irq_find_mapping(gpiochip->irq.domain, offset); 2470 + irq = irq_find_mapping(gc->irq.domain, offset); 2610 2471 irq_dispose_mapping(irq); 2611 2472 } 2612 2473 2613 - irq_domain_remove(gpiochip->irq.domain); 2474 + irq_domain_remove(gc->irq.domain); 2614 2475 } 2615 2476 2616 2477 if (irqchip) { ··· 2619 2480 irqchip->irq_release_resources = NULL; 2620 2481 } 2621 2482 if (irqchip->irq_enable == gpiochip_irq_enable) { 2622 - irqchip->irq_enable = gpiochip->irq.irq_enable; 2623 - irqchip->irq_disable = gpiochip->irq.irq_disable; 2483 + irqchip->irq_enable = gc->irq.irq_enable; 2484 + irqchip->irq_disable = gc->irq.irq_disable; 2624 2485 } 2625 2486 } 2626 - gpiochip->irq.irq_enable = NULL; 2627 - gpiochip->irq.irq_disable = NULL; 2628 - gpiochip->irq.chip = NULL; 2487 + gc->irq.irq_enable = NULL; 2488 + gc->irq.irq_disable = NULL; 2489 + gc->irq.chip = NULL; 2629 2490 2630 - gpiochip_irqchip_free_valid_mask(gpiochip); 2491 + gpiochip_irqchip_free_valid_mask(gc); 2631 2492 } 2632 2493 2633 2494 /** 2634 2495 * gpiochip_irqchip_add_key() - adds an irqchip to a gpiochip 2635 - * @gpiochip: the gpiochip to add the irqchip to 2496 + * @gc: the gpiochip to add the irqchip to 2636 2497 * @irqchip: the irqchip to add to the gpiochip 2637 2498 * @first_irq: if not dynamically assigned, the base (first) IRQ to 2638 2499 * allocate gpiochip irqs from ··· 2657 2518 * the pins on the gpiochip can generate a unique IRQ. Everything else 2658 2519 * need to be open coded. 2659 2520 */ 2660 - int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip, 2521 + int gpiochip_irqchip_add_key(struct gpio_chip *gc, 2661 2522 struct irq_chip *irqchip, 2662 2523 unsigned int first_irq, 2663 2524 irq_flow_handler_t handler, ··· 2668 2529 { 2669 2530 struct device_node *of_node; 2670 2531 2671 - if (!gpiochip || !irqchip) 2532 + if (!gc || !irqchip) 2672 2533 return -EINVAL; 2673 2534 2674 - if (!gpiochip->parent) { 2535 + if (!gc->parent) { 2675 2536 pr_err("missing gpiochip .dev parent pointer\n"); 2676 2537 return -EINVAL; 2677 2538 } 2678 - gpiochip->irq.threaded = threaded; 2679 - of_node = gpiochip->parent->of_node; 2539 + gc->irq.threaded = threaded; 2540 + of_node = gc->parent->of_node; 2680 2541 #ifdef CONFIG_OF_GPIO 2681 2542 /* 2682 2543 * If the gpiochip has an assigned OF node this takes precedence 2683 - * FIXME: get rid of this and use gpiochip->parent->of_node 2544 + * FIXME: get rid of this and use gc->parent->of_node 2684 2545 * everywhere 2685 2546 */ 2686 - if (gpiochip->of_node) 2687 - of_node = gpiochip->of_node; 2547 + if (gc->of_node) 2548 + of_node = gc->of_node; 2688 2549 #endif 2689 2550 /* 2690 2551 * Specifying a default trigger is a terrible idea if DT or ACPI is ··· 2694 2555 if (WARN(of_node && type != IRQ_TYPE_NONE, 2695 2556 "%pOF: Ignoring %d default trigger\n", of_node, type)) 2696 2557 type = IRQ_TYPE_NONE; 2697 - if (has_acpi_companion(gpiochip->parent) && type != IRQ_TYPE_NONE) { 2698 - acpi_handle_warn(ACPI_HANDLE(gpiochip->parent), 2558 + if (has_acpi_companion(gc->parent) && type != IRQ_TYPE_NONE) { 2559 + acpi_handle_warn(ACPI_HANDLE(gc->parent), 2699 2560 "Ignoring %d default trigger\n", type); 2700 2561 type = IRQ_TYPE_NONE; 2701 2562 } 2702 2563 2703 - gpiochip->irq.chip = irqchip; 2704 - gpiochip->irq.handler = handler; 2705 - gpiochip->irq.default_type = type; 2706 - gpiochip->to_irq = gpiochip_to_irq; 2707 - gpiochip->irq.lock_key = lock_key; 2708 - gpiochip->irq.request_key = request_key; 2709 - gpiochip->irq.domain = irq_domain_add_simple(of_node, 2710 - gpiochip->ngpio, first_irq, 2711 - &gpiochip_domain_ops, gpiochip); 2712 - if (!gpiochip->irq.domain) { 2713 - gpiochip->irq.chip = NULL; 2564 + gc->irq.chip = irqchip; 2565 + gc->irq.handler = handler; 2566 + gc->irq.default_type = type; 2567 + gc->to_irq = gpiochip_to_irq; 2568 + gc->irq.lock_key = lock_key; 2569 + gc->irq.request_key = request_key; 2570 + gc->irq.domain = irq_domain_add_simple(of_node, 2571 + gc->ngpio, first_irq, 2572 + &gpiochip_domain_ops, gc); 2573 + if (!gc->irq.domain) { 2574 + gc->irq.chip = NULL; 2714 2575 return -EINVAL; 2715 2576 } 2716 2577 2717 - gpiochip_set_irq_hooks(gpiochip); 2578 + gpiochip_set_irq_hooks(gc); 2718 2579 2719 - acpi_gpiochip_request_interrupts(gpiochip); 2580 + acpi_gpiochip_request_interrupts(gc); 2720 2581 2721 2582 return 0; 2722 2583 } ··· 2724 2585 2725 2586 #else /* CONFIG_GPIOLIB_IRQCHIP */ 2726 2587 2727 - static inline int gpiochip_add_irqchip(struct gpio_chip *gpiochip, 2588 + static inline int gpiochip_add_irqchip(struct gpio_chip *gc, 2728 2589 struct lock_class_key *lock_key, 2729 2590 struct lock_class_key *request_key) 2730 2591 { 2731 2592 return 0; 2732 2593 } 2733 - static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip) {} 2594 + static void gpiochip_irqchip_remove(struct gpio_chip *gc) {} 2734 2595 2735 - static inline int gpiochip_irqchip_init_hw(struct gpio_chip *gpiochip) 2596 + static inline int gpiochip_irqchip_init_hw(struct gpio_chip *gc) 2736 2597 { 2737 2598 return 0; 2738 2599 } 2739 2600 2740 - static inline int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gpiochip) 2601 + static inline int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gc) 2741 2602 { 2742 2603 return 0; 2743 2604 } 2744 - static inline void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gpiochip) 2605 + static inline void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc) 2745 2606 { } 2746 2607 2747 2608 #endif /* CONFIG_GPIOLIB_IRQCHIP */ 2748 2609 2749 2610 /** 2750 2611 * gpiochip_generic_request() - request the gpio function for a pin 2751 - * @chip: the gpiochip owning the GPIO 2612 + * @gc: the gpiochip owning the GPIO 2752 2613 * @offset: the offset of the GPIO to request for GPIO function 2753 2614 */ 2754 - int gpiochip_generic_request(struct gpio_chip *chip, unsigned offset) 2615 + int gpiochip_generic_request(struct gpio_chip *gc, unsigned offset) 2755 2616 { 2756 - return pinctrl_gpio_request(chip->gpiodev->base + offset); 2617 + #ifdef CONFIG_PINCTRL 2618 + if (list_empty(&gc->gpiodev->pin_ranges)) 2619 + return 0; 2620 + #endif 2621 + 2622 + return pinctrl_gpio_request(gc->gpiodev->base + offset); 2757 2623 } 2758 2624 EXPORT_SYMBOL_GPL(gpiochip_generic_request); 2759 2625 2760 2626 /** 2761 2627 * gpiochip_generic_free() - free the gpio function from a pin 2762 - * @chip: the gpiochip to request the gpio function for 2628 + * @gc: the gpiochip to request the gpio function for 2763 2629 * @offset: the offset of the GPIO to free from GPIO function 2764 2630 */ 2765 - void gpiochip_generic_free(struct gpio_chip *chip, unsigned offset) 2631 + void gpiochip_generic_free(struct gpio_chip *gc, unsigned offset) 2766 2632 { 2767 - pinctrl_gpio_free(chip->gpiodev->base + offset); 2633 + pinctrl_gpio_free(gc->gpiodev->base + offset); 2768 2634 } 2769 2635 EXPORT_SYMBOL_GPL(gpiochip_generic_free); 2770 2636 2771 2637 /** 2772 2638 * gpiochip_generic_config() - apply configuration for a pin 2773 - * @chip: the gpiochip owning the GPIO 2639 + * @gc: the gpiochip owning the GPIO 2774 2640 * @offset: the offset of the GPIO to apply the configuration 2775 2641 * @config: the configuration to be applied 2776 2642 */ 2777 - int gpiochip_generic_config(struct gpio_chip *chip, unsigned offset, 2643 + int gpiochip_generic_config(struct gpio_chip *gc, unsigned offset, 2778 2644 unsigned long config) 2779 2645 { 2780 - return pinctrl_gpio_set_config(chip->gpiodev->base + offset, config); 2646 + return pinctrl_gpio_set_config(gc->gpiodev->base + offset, config); 2781 2647 } 2782 2648 EXPORT_SYMBOL_GPL(gpiochip_generic_config); 2783 2649 ··· 2790 2646 2791 2647 /** 2792 2648 * gpiochip_add_pingroup_range() - add a range for GPIO <-> pin mapping 2793 - * @chip: the gpiochip to add the range for 2649 + * @gc: the gpiochip to add the range for 2794 2650 * @pctldev: the pin controller to map to 2795 2651 * @gpio_offset: the start offset in the current gpio_chip number space 2796 2652 * @pin_group: name of the pin group inside the pin controller ··· 2800 2656 * Documentation/devicetree/bindings/gpio/gpio.txt on how to 2801 2657 * bind pinctrl and gpio drivers via the "gpio-ranges" property. 2802 2658 */ 2803 - int gpiochip_add_pingroup_range(struct gpio_chip *chip, 2659 + int gpiochip_add_pingroup_range(struct gpio_chip *gc, 2804 2660 struct pinctrl_dev *pctldev, 2805 2661 unsigned int gpio_offset, const char *pin_group) 2806 2662 { 2807 2663 struct gpio_pin_range *pin_range; 2808 - struct gpio_device *gdev = chip->gpiodev; 2664 + struct gpio_device *gdev = gc->gpiodev; 2809 2665 int ret; 2810 2666 2811 2667 pin_range = kzalloc(sizeof(*pin_range), GFP_KERNEL); 2812 2668 if (!pin_range) { 2813 - chip_err(chip, "failed to allocate pin ranges\n"); 2669 + chip_err(gc, "failed to allocate pin ranges\n"); 2814 2670 return -ENOMEM; 2815 2671 } 2816 2672 2817 2673 /* Use local offset as range ID */ 2818 2674 pin_range->range.id = gpio_offset; 2819 - pin_range->range.gc = chip; 2820 - pin_range->range.name = chip->label; 2675 + pin_range->range.gc = gc; 2676 + pin_range->range.name = gc->label; 2821 2677 pin_range->range.base = gdev->base + gpio_offset; 2822 2678 pin_range->pctldev = pctldev; 2823 2679 ··· 2831 2687 2832 2688 pinctrl_add_gpio_range(pctldev, &pin_range->range); 2833 2689 2834 - chip_dbg(chip, "created GPIO range %d->%d ==> %s PINGRP %s\n", 2690 + chip_dbg(gc, "created GPIO range %d->%d ==> %s PINGRP %s\n", 2835 2691 gpio_offset, gpio_offset + pin_range->range.npins - 1, 2836 2692 pinctrl_dev_get_devname(pctldev), pin_group); 2837 2693 ··· 2843 2699 2844 2700 /** 2845 2701 * gpiochip_add_pin_range() - add a range for GPIO <-> pin mapping 2846 - * @chip: the gpiochip to add the range for 2702 + * @gc: the gpiochip to add the range for 2847 2703 * @pinctl_name: the dev_name() of the pin controller to map to 2848 2704 * @gpio_offset: the start offset in the current gpio_chip number space 2849 2705 * @pin_offset: the start offset in the pin controller number space ··· 2858 2714 * Documentation/devicetree/bindings/gpio/gpio.txt on how to 2859 2715 * bind pinctrl and gpio drivers via the "gpio-ranges" property. 2860 2716 */ 2861 - int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name, 2717 + int gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name, 2862 2718 unsigned int gpio_offset, unsigned int pin_offset, 2863 2719 unsigned int npins) 2864 2720 { 2865 2721 struct gpio_pin_range *pin_range; 2866 - struct gpio_device *gdev = chip->gpiodev; 2722 + struct gpio_device *gdev = gc->gpiodev; 2867 2723 int ret; 2868 2724 2869 2725 pin_range = kzalloc(sizeof(*pin_range), GFP_KERNEL); 2870 2726 if (!pin_range) { 2871 - chip_err(chip, "failed to allocate pin ranges\n"); 2727 + chip_err(gc, "failed to allocate pin ranges\n"); 2872 2728 return -ENOMEM; 2873 2729 } 2874 2730 2875 2731 /* Use local offset as range ID */ 2876 2732 pin_range->range.id = gpio_offset; 2877 - pin_range->range.gc = chip; 2878 - pin_range->range.name = chip->label; 2733 + pin_range->range.gc = gc; 2734 + pin_range->range.name = gc->label; 2879 2735 pin_range->range.base = gdev->base + gpio_offset; 2880 2736 pin_range->range.pin_base = pin_offset; 2881 2737 pin_range->range.npins = npins; ··· 2883 2739 &pin_range->range); 2884 2740 if (IS_ERR(pin_range->pctldev)) { 2885 2741 ret = PTR_ERR(pin_range->pctldev); 2886 - chip_err(chip, "could not create pin range\n"); 2742 + chip_err(gc, "could not create pin range\n"); 2887 2743 kfree(pin_range); 2888 2744 return ret; 2889 2745 } 2890 - chip_dbg(chip, "created GPIO range %d->%d ==> %s PIN %d->%d\n", 2746 + chip_dbg(gc, "created GPIO range %d->%d ==> %s PIN %d->%d\n", 2891 2747 gpio_offset, gpio_offset + npins - 1, 2892 2748 pinctl_name, 2893 2749 pin_offset, pin_offset + npins - 1); ··· 2900 2756 2901 2757 /** 2902 2758 * gpiochip_remove_pin_ranges() - remove all the GPIO <-> pin mappings 2903 - * @chip: the chip to remove all the mappings for 2759 + * @gc: the chip to remove all the mappings for 2904 2760 */ 2905 - void gpiochip_remove_pin_ranges(struct gpio_chip *chip) 2761 + void gpiochip_remove_pin_ranges(struct gpio_chip *gc) 2906 2762 { 2907 2763 struct gpio_pin_range *pin_range, *tmp; 2908 - struct gpio_device *gdev = chip->gpiodev; 2764 + struct gpio_device *gdev = gc->gpiodev; 2909 2765 2910 2766 list_for_each_entry_safe(pin_range, tmp, &gdev->pin_ranges, node) { 2911 2767 list_del(&pin_range->node); ··· 2924 2780 */ 2925 2781 static int gpiod_request_commit(struct gpio_desc *desc, const char *label) 2926 2782 { 2927 - struct gpio_chip *chip = desc->gdev->chip; 2783 + struct gpio_chip *gc = desc->gdev->chip; 2928 2784 int ret; 2929 2785 unsigned long flags; 2930 2786 unsigned offset; ··· 2950 2806 goto done; 2951 2807 } 2952 2808 2953 - if (chip->request) { 2954 - /* chip->request may sleep */ 2809 + if (gc->request) { 2810 + /* gc->request may sleep */ 2955 2811 spin_unlock_irqrestore(&gpio_lock, flags); 2956 2812 offset = gpio_chip_hwgpio(desc); 2957 - if (gpiochip_line_is_valid(chip, offset)) 2958 - ret = chip->request(chip, offset); 2813 + if (gpiochip_line_is_valid(gc, offset)) 2814 + ret = gc->request(gc, offset); 2959 2815 else 2960 2816 ret = -EINVAL; 2961 2817 spin_lock_irqsave(&gpio_lock, flags); ··· 2967 2823 goto done; 2968 2824 } 2969 2825 } 2970 - if (chip->get_direction) { 2971 - /* chip->get_direction may sleep */ 2826 + if (gc->get_direction) { 2827 + /* gc->get_direction may sleep */ 2972 2828 spin_unlock_irqrestore(&gpio_lock, flags); 2973 2829 gpiod_get_direction(desc); 2974 2830 spin_lock_irqsave(&gpio_lock, flags); 2975 2831 } 2976 2832 done: 2977 2833 spin_unlock_irqrestore(&gpio_lock, flags); 2834 + atomic_notifier_call_chain(&desc->gdev->notifier, 2835 + GPIOLINE_CHANGED_REQUESTED, desc); 2978 2836 return ret; 2979 2837 } 2980 2838 ··· 3044 2898 { 3045 2899 bool ret = false; 3046 2900 unsigned long flags; 3047 - struct gpio_chip *chip; 2901 + struct gpio_chip *gc; 3048 2902 3049 2903 might_sleep(); 3050 2904 ··· 3052 2906 3053 2907 spin_lock_irqsave(&gpio_lock, flags); 3054 2908 3055 - chip = desc->gdev->chip; 3056 - if (chip && test_bit(FLAG_REQUESTED, &desc->flags)) { 3057 - if (chip->free) { 2909 + gc = desc->gdev->chip; 2910 + if (gc && test_bit(FLAG_REQUESTED, &desc->flags)) { 2911 + if (gc->free) { 3058 2912 spin_unlock_irqrestore(&gpio_lock, flags); 3059 - might_sleep_if(chip->can_sleep); 3060 - chip->free(chip, gpio_chip_hwgpio(desc)); 2913 + might_sleep_if(gc->can_sleep); 2914 + gc->free(gc, gpio_chip_hwgpio(desc)); 3061 2915 spin_lock_irqsave(&gpio_lock, flags); 3062 2916 } 3063 2917 kfree_const(desc->label); ··· 3070 2924 clear_bit(FLAG_PULL_DOWN, &desc->flags); 3071 2925 clear_bit(FLAG_BIAS_DISABLE, &desc->flags); 3072 2926 clear_bit(FLAG_IS_HOGGED, &desc->flags); 2927 + #ifdef CONFIG_OF_DYNAMIC 2928 + desc->hog = NULL; 2929 + #endif 3073 2930 ret = true; 3074 2931 } 3075 2932 3076 2933 spin_unlock_irqrestore(&gpio_lock, flags); 2934 + atomic_notifier_call_chain(&desc->gdev->notifier, 2935 + GPIOLINE_CHANGED_RELEASED, desc); 2936 + 3077 2937 return ret; 3078 2938 } 3079 2939 ··· 3095 2943 3096 2944 /** 3097 2945 * gpiochip_is_requested - return string iff signal was requested 3098 - * @chip: controller managing the signal 2946 + * @gc: controller managing the signal 3099 2947 * @offset: of signal within controller's 0..(ngpio - 1) range 3100 2948 * 3101 2949 * Returns NULL if the GPIO is not currently requested, else a string. ··· 3106 2954 * help with diagnostics, and knowing that the signal is used as a GPIO 3107 2955 * can help avoid accidentally multiplexing it to another controller. 3108 2956 */ 3109 - const char *gpiochip_is_requested(struct gpio_chip *chip, unsigned offset) 2957 + const char *gpiochip_is_requested(struct gpio_chip *gc, unsigned offset) 3110 2958 { 3111 2959 struct gpio_desc *desc; 3112 2960 3113 - if (offset >= chip->ngpio) 2961 + if (offset >= gc->ngpio) 3114 2962 return NULL; 3115 2963 3116 - desc = &chip->gpiodev->descs[offset]; 2964 + desc = gpiochip_get_desc(gc, offset); 2965 + if (IS_ERR(desc)) 2966 + return NULL; 3117 2967 3118 2968 if (test_bit(FLAG_REQUESTED, &desc->flags) == 0) 3119 2969 return NULL; ··· 3125 2971 3126 2972 /** 3127 2973 * gpiochip_request_own_desc - Allow GPIO chip to request its own descriptor 3128 - * @chip: GPIO chip 2974 + * @gc: GPIO chip 3129 2975 * @hwnum: hardware number of the GPIO for which to request the descriptor 3130 2976 * @label: label for the GPIO 3131 2977 * @lflags: lookup flags for this GPIO or 0 if default, this can be used to ··· 3144 2990 * A pointer to the GPIO descriptor, or an ERR_PTR()-encoded negative error 3145 2991 * code on failure. 3146 2992 */ 3147 - struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, 2993 + struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc, 3148 2994 unsigned int hwnum, 3149 2995 const char *label, 3150 2996 enum gpio_lookup_flags lflags, 3151 2997 enum gpiod_flags dflags) 3152 2998 { 3153 - struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum); 2999 + struct gpio_desc *desc = gpiochip_get_desc(gc, hwnum); 3154 3000 int ret; 3155 3001 3156 3002 if (IS_ERR(desc)) { 3157 - chip_err(chip, "failed to get GPIO descriptor\n"); 3003 + chip_err(gc, "failed to get GPIO descriptor\n"); 3158 3004 return desc; 3159 3005 } 3160 3006 ··· 3164 3010 3165 3011 ret = gpiod_configure_flags(desc, label, lflags, dflags); 3166 3012 if (ret) { 3167 - chip_err(chip, "setup of own GPIO %s failed\n", label); 3013 + chip_err(gc, "setup of own GPIO %s failed\n", label); 3168 3014 gpiod_free_commit(desc); 3169 3015 return ERR_PTR(ret); 3170 3016 } ··· 3206 3052 return gc->set_config(gc, offset, config); 3207 3053 } 3208 3054 3209 - static int gpio_set_config(struct gpio_chip *gc, unsigned int offset, 3210 - enum pin_config_param mode) 3055 + static int gpio_set_config(struct gpio_desc *desc, enum pin_config_param mode) 3211 3056 { 3057 + struct gpio_chip *gc = desc->gdev->chip; 3212 3058 unsigned long config; 3213 3059 unsigned arg; 3214 3060 ··· 3223 3069 } 3224 3070 3225 3071 config = PIN_CONF_PACKED(mode, arg); 3226 - return gpio_do_set_config(gc, offset, config); 3072 + return gpio_do_set_config(gc, gpio_chip_hwgpio(desc), config); 3227 3073 } 3228 3074 3229 - static int gpio_set_bias(struct gpio_chip *chip, struct gpio_desc *desc) 3075 + static int gpio_set_bias(struct gpio_desc *desc) 3230 3076 { 3231 3077 int bias = 0; 3232 3078 int ret = 0; ··· 3239 3085 bias = PIN_CONFIG_BIAS_PULL_DOWN; 3240 3086 3241 3087 if (bias) { 3242 - ret = gpio_set_config(chip, gpio_chip_hwgpio(desc), bias); 3088 + ret = gpio_set_config(desc, bias); 3243 3089 if (ret != -ENOTSUPP) 3244 3090 return ret; 3245 3091 } ··· 3257 3103 */ 3258 3104 int gpiod_direction_input(struct gpio_desc *desc) 3259 3105 { 3260 - struct gpio_chip *chip; 3106 + struct gpio_chip *gc; 3261 3107 int ret = 0; 3262 3108 3263 3109 VALIDATE_DESC(desc); 3264 - chip = desc->gdev->chip; 3110 + gc = desc->gdev->chip; 3265 3111 3266 3112 /* 3267 3113 * It is legal to have no .get() and .direction_input() specified if 3268 3114 * the chip is output-only, but you can't specify .direction_input() 3269 3115 * and not support the .get() operation, that doesn't make sense. 3270 3116 */ 3271 - if (!chip->get && chip->direction_input) { 3117 + if (!gc->get && gc->direction_input) { 3272 3118 gpiod_warn(desc, 3273 3119 "%s: missing get() but have direction_input()\n", 3274 3120 __func__); ··· 3281 3127 * direction (if .get_direction() is supported) else we silently 3282 3128 * assume we are in input mode after this. 3283 3129 */ 3284 - if (chip->direction_input) { 3285 - ret = chip->direction_input(chip, gpio_chip_hwgpio(desc)); 3286 - } else if (chip->get_direction && 3287 - (chip->get_direction(chip, gpio_chip_hwgpio(desc)) != 1)) { 3130 + if (gc->direction_input) { 3131 + ret = gc->direction_input(gc, gpio_chip_hwgpio(desc)); 3132 + } else if (gc->get_direction && 3133 + (gc->get_direction(gc, gpio_chip_hwgpio(desc)) != 1)) { 3288 3134 gpiod_warn(desc, 3289 3135 "%s: missing direction_input() operation and line is output\n", 3290 3136 __func__); ··· 3292 3138 } 3293 3139 if (ret == 0) { 3294 3140 clear_bit(FLAG_IS_OUT, &desc->flags); 3295 - ret = gpio_set_bias(chip, desc); 3141 + ret = gpio_set_bias(desc); 3296 3142 } 3297 3143 3298 3144 trace_gpio_direction(desc_to_gpio(desc), 1, ret); ··· 3376 3222 */ 3377 3223 int gpiod_direction_output(struct gpio_desc *desc, int value) 3378 3224 { 3379 - struct gpio_chip *gc; 3380 3225 int ret; 3381 3226 3382 3227 VALIDATE_DESC(desc); ··· 3393 3240 return -EIO; 3394 3241 } 3395 3242 3396 - gc = desc->gdev->chip; 3397 3243 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) { 3398 3244 /* First see if we can enable open drain in hardware */ 3399 - ret = gpio_set_config(gc, gpio_chip_hwgpio(desc), 3400 - PIN_CONFIG_DRIVE_OPEN_DRAIN); 3245 + ret = gpio_set_config(desc, PIN_CONFIG_DRIVE_OPEN_DRAIN); 3401 3246 if (!ret) 3402 3247 goto set_output_value; 3403 3248 /* Emulate open drain by not actively driving the line high */ ··· 3405 3254 } 3406 3255 } 3407 3256 else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) { 3408 - ret = gpio_set_config(gc, gpio_chip_hwgpio(desc), 3409 - PIN_CONFIG_DRIVE_OPEN_SOURCE); 3257 + ret = gpio_set_config(desc, PIN_CONFIG_DRIVE_OPEN_SOURCE); 3410 3258 if (!ret) 3411 3259 goto set_output_value; 3412 3260 /* Emulate open source by not actively driving the line low */ ··· 3414 3264 goto set_output_flag; 3415 3265 } 3416 3266 } else { 3417 - gpio_set_config(gc, gpio_chip_hwgpio(desc), 3418 - PIN_CONFIG_DRIVE_PUSH_PULL); 3267 + gpio_set_config(desc, PIN_CONFIG_DRIVE_PUSH_PULL); 3419 3268 } 3420 3269 3421 3270 set_output_value: 3422 - ret = gpio_set_bias(gc, desc); 3271 + ret = gpio_set_bias(desc); 3423 3272 if (ret) 3424 3273 return ret; 3425 3274 return gpiod_direction_output_raw_commit(desc, value); ··· 3437 3288 EXPORT_SYMBOL_GPL(gpiod_direction_output); 3438 3289 3439 3290 /** 3291 + * gpiod_set_config - sets @config for a GPIO 3292 + * @desc: descriptor of the GPIO for which to set the configuration 3293 + * @config: Same packed config format as generic pinconf 3294 + * 3295 + * Returns: 3296 + * 0 on success, %-ENOTSUPP if the controller doesn't support setting the 3297 + * configuration. 3298 + */ 3299 + int gpiod_set_config(struct gpio_desc *desc, unsigned long config) 3300 + { 3301 + struct gpio_chip *gc; 3302 + 3303 + VALIDATE_DESC(desc); 3304 + gc = desc->gdev->chip; 3305 + 3306 + return gpio_do_set_config(gc, gpio_chip_hwgpio(desc), config); 3307 + } 3308 + EXPORT_SYMBOL_GPL(gpiod_set_config); 3309 + 3310 + /** 3440 3311 * gpiod_set_debounce - sets @debounce time for a GPIO 3441 3312 * @desc: descriptor of the GPIO for which to set debounce time 3442 3313 * @debounce: debounce time in microseconds ··· 3467 3298 */ 3468 3299 int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) 3469 3300 { 3470 - struct gpio_chip *chip; 3471 - unsigned long config; 3472 - 3473 - VALIDATE_DESC(desc); 3474 - chip = desc->gdev->chip; 3301 + unsigned long config; 3475 3302 3476 3303 config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce); 3477 - return gpio_do_set_config(chip, gpio_chip_hwgpio(desc), config); 3304 + return gpiod_set_config(desc, config); 3478 3305 } 3479 3306 EXPORT_SYMBOL_GPL(gpiod_set_debounce); 3480 3307 ··· 3484 3319 */ 3485 3320 int gpiod_set_transitory(struct gpio_desc *desc, bool transitory) 3486 3321 { 3487 - struct gpio_chip *chip; 3322 + struct gpio_chip *gc; 3488 3323 unsigned long packed; 3489 3324 int gpio; 3490 3325 int rc; ··· 3497 3332 assign_bit(FLAG_TRANSITORY, &desc->flags, transitory); 3498 3333 3499 3334 /* If the driver supports it, set the persistence state now */ 3500 - chip = desc->gdev->chip; 3501 - if (!chip->set_config) 3335 + gc = desc->gdev->chip; 3336 + if (!gc->set_config) 3502 3337 return 0; 3503 3338 3504 3339 packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE, 3505 3340 !transitory); 3506 3341 gpio = gpio_chip_hwgpio(desc); 3507 - rc = gpio_do_set_config(chip, gpio, packed); 3342 + rc = gpio_do_set_config(gc, gpio, packed); 3508 3343 if (rc == -ENOTSUPP) { 3509 3344 dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n", 3510 3345 gpio); ··· 3563 3398 3564 3399 static int gpiod_get_raw_value_commit(const struct gpio_desc *desc) 3565 3400 { 3566 - struct gpio_chip *chip; 3401 + struct gpio_chip *gc; 3567 3402 int offset; 3568 3403 int value; 3569 3404 3570 - chip = desc->gdev->chip; 3405 + gc = desc->gdev->chip; 3571 3406 offset = gpio_chip_hwgpio(desc); 3572 - value = chip->get ? chip->get(chip, offset) : -EIO; 3407 + value = gc->get ? gc->get(gc, offset) : -EIO; 3573 3408 value = value < 0 ? value : !!value; 3574 3409 trace_gpio_value(desc_to_gpio(desc), 1, value); 3575 3410 return value; 3576 3411 } 3577 3412 3578 - static int gpio_chip_get_multiple(struct gpio_chip *chip, 3413 + static int gpio_chip_get_multiple(struct gpio_chip *gc, 3579 3414 unsigned long *mask, unsigned long *bits) 3580 3415 { 3581 - if (chip->get_multiple) { 3582 - return chip->get_multiple(chip, mask, bits); 3583 - } else if (chip->get) { 3416 + if (gc->get_multiple) { 3417 + return gc->get_multiple(gc, mask, bits); 3418 + } else if (gc->get) { 3584 3419 int i, value; 3585 3420 3586 - for_each_set_bit(i, mask, chip->ngpio) { 3587 - value = chip->get(chip, i); 3421 + for_each_set_bit(i, mask, gc->ngpio) { 3422 + value = gc->get(gc, i); 3588 3423 if (value < 0) 3589 3424 return value; 3590 3425 __assign_bit(i, bits, value); ··· 3632 3467 } 3633 3468 3634 3469 while (i < array_size) { 3635 - struct gpio_chip *chip = desc_array[i]->gdev->chip; 3470 + struct gpio_chip *gc = desc_array[i]->gdev->chip; 3636 3471 unsigned long fastpath[2 * BITS_TO_LONGS(FASTPATH_NGPIO)]; 3637 3472 unsigned long *mask, *bits; 3638 3473 int first, j, ret; 3639 3474 3640 - if (likely(chip->ngpio <= FASTPATH_NGPIO)) { 3475 + if (likely(gc->ngpio <= FASTPATH_NGPIO)) { 3641 3476 mask = fastpath; 3642 3477 } else { 3643 - mask = kmalloc_array(2 * BITS_TO_LONGS(chip->ngpio), 3478 + mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio), 3644 3479 sizeof(*mask), 3645 3480 can_sleep ? GFP_KERNEL : GFP_ATOMIC); 3646 3481 if (!mask) 3647 3482 return -ENOMEM; 3648 3483 } 3649 3484 3650 - bits = mask + BITS_TO_LONGS(chip->ngpio); 3651 - bitmap_zero(mask, chip->ngpio); 3485 + bits = mask + BITS_TO_LONGS(gc->ngpio); 3486 + bitmap_zero(mask, gc->ngpio); 3652 3487 3653 3488 if (!can_sleep) 3654 - WARN_ON(chip->can_sleep); 3489 + WARN_ON(gc->can_sleep); 3655 3490 3656 3491 /* collect all inputs belonging to the same chip */ 3657 3492 first = i; ··· 3666 3501 i = find_next_zero_bit(array_info->get_mask, 3667 3502 array_size, i); 3668 3503 } while ((i < array_size) && 3669 - (desc_array[i]->gdev->chip == chip)); 3504 + (desc_array[i]->gdev->chip == gc)); 3670 3505 3671 - ret = gpio_chip_get_multiple(chip, mask, bits); 3506 + ret = gpio_chip_get_multiple(gc, mask, bits); 3672 3507 if (ret) { 3673 3508 if (mask != fastpath) 3674 3509 kfree(mask); ··· 3806 3641 static void gpio_set_open_drain_value_commit(struct gpio_desc *desc, bool value) 3807 3642 { 3808 3643 int ret = 0; 3809 - struct gpio_chip *chip = desc->gdev->chip; 3644 + struct gpio_chip *gc = desc->gdev->chip; 3810 3645 int offset = gpio_chip_hwgpio(desc); 3811 3646 3812 3647 if (value) { 3813 - ret = chip->direction_input(chip, offset); 3648 + ret = gc->direction_input(gc, offset); 3814 3649 } else { 3815 - ret = chip->direction_output(chip, offset, 0); 3650 + ret = gc->direction_output(gc, offset, 0); 3816 3651 if (!ret) 3817 3652 set_bit(FLAG_IS_OUT, &desc->flags); 3818 3653 } ··· 3831 3666 static void gpio_set_open_source_value_commit(struct gpio_desc *desc, bool value) 3832 3667 { 3833 3668 int ret = 0; 3834 - struct gpio_chip *chip = desc->gdev->chip; 3669 + struct gpio_chip *gc = desc->gdev->chip; 3835 3670 int offset = gpio_chip_hwgpio(desc); 3836 3671 3837 3672 if (value) { 3838 - ret = chip->direction_output(chip, offset, 1); 3673 + ret = gc->direction_output(gc, offset, 1); 3839 3674 if (!ret) 3840 3675 set_bit(FLAG_IS_OUT, &desc->flags); 3841 3676 } else { 3842 - ret = chip->direction_input(chip, offset); 3677 + ret = gc->direction_input(gc, offset); 3843 3678 } 3844 3679 trace_gpio_direction(desc_to_gpio(desc), !value, ret); 3845 3680 if (ret < 0) ··· 3850 3685 3851 3686 static void gpiod_set_raw_value_commit(struct gpio_desc *desc, bool value) 3852 3687 { 3853 - struct gpio_chip *chip; 3688 + struct gpio_chip *gc; 3854 3689 3855 - chip = desc->gdev->chip; 3690 + gc = desc->gdev->chip; 3856 3691 trace_gpio_value(desc_to_gpio(desc), 0, value); 3857 - chip->set(chip, gpio_chip_hwgpio(desc), value); 3692 + gc->set(gc, gpio_chip_hwgpio(desc), value); 3858 3693 } 3859 3694 3860 3695 /* 3861 3696 * set multiple outputs on the same chip; 3862 3697 * use the chip's set_multiple function if available; 3863 3698 * otherwise set the outputs sequentially; 3699 + * @chip: the GPIO chip we operate on 3864 3700 * @mask: bit mask array; one bit per output; BITS_PER_LONG bits per word 3865 3701 * defines which outputs are to be changed 3866 3702 * @bits: bit value array; one bit per output; BITS_PER_LONG bits per word 3867 3703 * defines the values the outputs specified by mask are to be set to 3868 3704 */ 3869 - static void gpio_chip_set_multiple(struct gpio_chip *chip, 3705 + static void gpio_chip_set_multiple(struct gpio_chip *gc, 3870 3706 unsigned long *mask, unsigned long *bits) 3871 3707 { 3872 - if (chip->set_multiple) { 3873 - chip->set_multiple(chip, mask, bits); 3708 + if (gc->set_multiple) { 3709 + gc->set_multiple(gc, mask, bits); 3874 3710 } else { 3875 3711 unsigned int i; 3876 3712 3877 3713 /* set outputs if the corresponding mask bit is set */ 3878 - for_each_set_bit(i, mask, chip->ngpio) 3879 - chip->set(chip, i, test_bit(i, bits)); 3714 + for_each_set_bit(i, mask, gc->ngpio) 3715 + gc->set(gc, i, test_bit(i, bits)); 3880 3716 } 3881 3717 } 3882 3718 ··· 3916 3750 } 3917 3751 3918 3752 while (i < array_size) { 3919 - struct gpio_chip *chip = desc_array[i]->gdev->chip; 3753 + struct gpio_chip *gc = desc_array[i]->gdev->chip; 3920 3754 unsigned long fastpath[2 * BITS_TO_LONGS(FASTPATH_NGPIO)]; 3921 3755 unsigned long *mask, *bits; 3922 3756 int count = 0; 3923 3757 3924 - if (likely(chip->ngpio <= FASTPATH_NGPIO)) { 3758 + if (likely(gc->ngpio <= FASTPATH_NGPIO)) { 3925 3759 mask = fastpath; 3926 3760 } else { 3927 - mask = kmalloc_array(2 * BITS_TO_LONGS(chip->ngpio), 3761 + mask = kmalloc_array(2 * BITS_TO_LONGS(gc->ngpio), 3928 3762 sizeof(*mask), 3929 3763 can_sleep ? GFP_KERNEL : GFP_ATOMIC); 3930 3764 if (!mask) 3931 3765 return -ENOMEM; 3932 3766 } 3933 3767 3934 - bits = mask + BITS_TO_LONGS(chip->ngpio); 3935 - bitmap_zero(mask, chip->ngpio); 3768 + bits = mask + BITS_TO_LONGS(gc->ngpio); 3769 + bitmap_zero(mask, gc->ngpio); 3936 3770 3937 3771 if (!can_sleep) 3938 - WARN_ON(chip->can_sleep); 3772 + WARN_ON(gc->can_sleep); 3939 3773 3940 3774 do { 3941 3775 struct gpio_desc *desc = desc_array[i]; ··· 3971 3805 i = find_next_zero_bit(array_info->set_mask, 3972 3806 array_size, i); 3973 3807 } while ((i < array_size) && 3974 - (desc_array[i]->gdev->chip == chip)); 3808 + (desc_array[i]->gdev->chip == gc)); 3975 3809 /* push collected bits to outputs */ 3976 3810 if (count != 0) 3977 - gpio_chip_set_multiple(chip, mask, bits); 3811 + gpio_chip_set_multiple(gc, mask, bits); 3978 3812 3979 3813 if (mask != fastpath) 3980 3814 kfree(mask); ··· 4136 3970 */ 4137 3971 int gpiod_to_irq(const struct gpio_desc *desc) 4138 3972 { 4139 - struct gpio_chip *chip; 3973 + struct gpio_chip *gc; 4140 3974 int offset; 4141 3975 4142 3976 /* ··· 4147 3981 if (!desc || IS_ERR(desc) || !desc->gdev || !desc->gdev->chip) 4148 3982 return -EINVAL; 4149 3983 4150 - chip = desc->gdev->chip; 3984 + gc = desc->gdev->chip; 4151 3985 offset = gpio_chip_hwgpio(desc); 4152 - if (chip->to_irq) { 4153 - int retirq = chip->to_irq(chip, offset); 3986 + if (gc->to_irq) { 3987 + int retirq = gc->to_irq(gc, offset); 4154 3988 4155 3989 /* Zero means NO_IRQ */ 4156 3990 if (!retirq) ··· 4164 3998 4165 3999 /** 4166 4000 * gpiochip_lock_as_irq() - lock a GPIO to be used as IRQ 4167 - * @chip: the chip the GPIO to lock belongs to 4001 + * @gc: the chip the GPIO to lock belongs to 4168 4002 * @offset: the offset of the GPIO to lock as IRQ 4169 4003 * 4170 4004 * This is used directly by GPIO drivers that want to lock down 4171 4005 * a certain GPIO line to be used for IRQs. 4172 4006 */ 4173 - int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset) 4007 + int gpiochip_lock_as_irq(struct gpio_chip *gc, unsigned int offset) 4174 4008 { 4175 4009 struct gpio_desc *desc; 4176 4010 4177 - desc = gpiochip_get_desc(chip, offset); 4011 + desc = gpiochip_get_desc(gc, offset); 4178 4012 if (IS_ERR(desc)) 4179 4013 return PTR_ERR(desc); 4180 4014 ··· 4182 4016 * If it's fast: flush the direction setting if something changed 4183 4017 * behind our back 4184 4018 */ 4185 - if (!chip->can_sleep && chip->get_direction) { 4019 + if (!gc->can_sleep && gc->get_direction) { 4186 4020 int dir = gpiod_get_direction(desc); 4187 4021 4188 4022 if (dir < 0) { 4189 - chip_err(chip, "%s: cannot get GPIO direction\n", 4023 + chip_err(gc, "%s: cannot get GPIO direction\n", 4190 4024 __func__); 4191 4025 return dir; 4192 4026 } 4193 4027 } 4194 4028 4195 4029 if (test_bit(FLAG_IS_OUT, &desc->flags)) { 4196 - chip_err(chip, 4030 + chip_err(gc, 4197 4031 "%s: tried to flag a GPIO set as output for IRQ\n", 4198 4032 __func__); 4199 4033 return -EIO; ··· 4216 4050 4217 4051 /** 4218 4052 * gpiochip_unlock_as_irq() - unlock a GPIO used as IRQ 4219 - * @chip: the chip the GPIO to lock belongs to 4053 + * @gc: the chip the GPIO to lock belongs to 4220 4054 * @offset: the offset of the GPIO to lock as IRQ 4221 4055 * 4222 4056 * This is used directly by GPIO drivers that want to indicate 4223 4057 * that a certain GPIO is no longer used exclusively for IRQ. 4224 4058 */ 4225 - void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset) 4059 + void gpiochip_unlock_as_irq(struct gpio_chip *gc, unsigned int offset) 4226 4060 { 4227 4061 struct gpio_desc *desc; 4228 4062 4229 - desc = gpiochip_get_desc(chip, offset); 4063 + desc = gpiochip_get_desc(gc, offset); 4230 4064 if (IS_ERR(desc)) 4231 4065 return; 4232 4066 ··· 4239 4073 } 4240 4074 EXPORT_SYMBOL_GPL(gpiochip_unlock_as_irq); 4241 4075 4242 - void gpiochip_disable_irq(struct gpio_chip *chip, unsigned int offset) 4076 + void gpiochip_disable_irq(struct gpio_chip *gc, unsigned int offset) 4243 4077 { 4244 - struct gpio_desc *desc = gpiochip_get_desc(chip, offset); 4078 + struct gpio_desc *desc = gpiochip_get_desc(gc, offset); 4245 4079 4246 4080 if (!IS_ERR(desc) && 4247 4081 !WARN_ON(!test_bit(FLAG_USED_AS_IRQ, &desc->flags))) ··· 4249 4083 } 4250 4084 EXPORT_SYMBOL_GPL(gpiochip_disable_irq); 4251 4085 4252 - void gpiochip_enable_irq(struct gpio_chip *chip, unsigned int offset) 4086 + void gpiochip_enable_irq(struct gpio_chip *gc, unsigned int offset) 4253 4087 { 4254 - struct gpio_desc *desc = gpiochip_get_desc(chip, offset); 4088 + struct gpio_desc *desc = gpiochip_get_desc(gc, offset); 4255 4089 4256 4090 if (!IS_ERR(desc) && 4257 4091 !WARN_ON(!test_bit(FLAG_USED_AS_IRQ, &desc->flags))) { ··· 4261 4095 } 4262 4096 EXPORT_SYMBOL_GPL(gpiochip_enable_irq); 4263 4097 4264 - bool gpiochip_line_is_irq(struct gpio_chip *chip, unsigned int offset) 4098 + bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset) 4265 4099 { 4266 - if (offset >= chip->ngpio) 4100 + if (offset >= gc->ngpio) 4267 4101 return false; 4268 4102 4269 - return test_bit(FLAG_USED_AS_IRQ, &chip->gpiodev->descs[offset].flags); 4103 + return test_bit(FLAG_USED_AS_IRQ, &gc->gpiodev->descs[offset].flags); 4270 4104 } 4271 4105 EXPORT_SYMBOL_GPL(gpiochip_line_is_irq); 4272 4106 4273 - int gpiochip_reqres_irq(struct gpio_chip *chip, unsigned int offset) 4107 + int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset) 4274 4108 { 4275 4109 int ret; 4276 4110 4277 - if (!try_module_get(chip->gpiodev->owner)) 4111 + if (!try_module_get(gc->gpiodev->owner)) 4278 4112 return -ENODEV; 4279 4113 4280 - ret = gpiochip_lock_as_irq(chip, offset); 4114 + ret = gpiochip_lock_as_irq(gc, offset); 4281 4115 if (ret) { 4282 - chip_err(chip, "unable to lock HW IRQ %u for IRQ\n", offset); 4283 - module_put(chip->gpiodev->owner); 4116 + chip_err(gc, "unable to lock HW IRQ %u for IRQ\n", offset); 4117 + module_put(gc->gpiodev->owner); 4284 4118 return ret; 4285 4119 } 4286 4120 return 0; 4287 4121 } 4288 4122 EXPORT_SYMBOL_GPL(gpiochip_reqres_irq); 4289 4123 4290 - void gpiochip_relres_irq(struct gpio_chip *chip, unsigned int offset) 4124 + void gpiochip_relres_irq(struct gpio_chip *gc, unsigned int offset) 4291 4125 { 4292 - gpiochip_unlock_as_irq(chip, offset); 4293 - module_put(chip->gpiodev->owner); 4126 + gpiochip_unlock_as_irq(gc, offset); 4127 + module_put(gc->gpiodev->owner); 4294 4128 } 4295 4129 EXPORT_SYMBOL_GPL(gpiochip_relres_irq); 4296 4130 4297 - bool gpiochip_line_is_open_drain(struct gpio_chip *chip, unsigned int offset) 4131 + bool gpiochip_line_is_open_drain(struct gpio_chip *gc, unsigned int offset) 4298 4132 { 4299 - if (offset >= chip->ngpio) 4133 + if (offset >= gc->ngpio) 4300 4134 return false; 4301 4135 4302 - return test_bit(FLAG_OPEN_DRAIN, &chip->gpiodev->descs[offset].flags); 4136 + return test_bit(FLAG_OPEN_DRAIN, &gc->gpiodev->descs[offset].flags); 4303 4137 } 4304 4138 EXPORT_SYMBOL_GPL(gpiochip_line_is_open_drain); 4305 4139 4306 - bool gpiochip_line_is_open_source(struct gpio_chip *chip, unsigned int offset) 4140 + bool gpiochip_line_is_open_source(struct gpio_chip *gc, unsigned int offset) 4307 4141 { 4308 - if (offset >= chip->ngpio) 4142 + if (offset >= gc->ngpio) 4309 4143 return false; 4310 4144 4311 - return test_bit(FLAG_OPEN_SOURCE, &chip->gpiodev->descs[offset].flags); 4145 + return test_bit(FLAG_OPEN_SOURCE, &gc->gpiodev->descs[offset].flags); 4312 4146 } 4313 4147 EXPORT_SYMBOL_GPL(gpiochip_line_is_open_source); 4314 4148 4315 - bool gpiochip_line_is_persistent(struct gpio_chip *chip, unsigned int offset) 4149 + bool gpiochip_line_is_persistent(struct gpio_chip *gc, unsigned int offset) 4316 4150 { 4317 - if (offset >= chip->ngpio) 4151 + if (offset >= gc->ngpio) 4318 4152 return false; 4319 4153 4320 - return !test_bit(FLAG_TRANSITORY, &chip->gpiodev->descs[offset].flags); 4154 + return !test_bit(FLAG_TRANSITORY, &gc->gpiodev->descs[offset].flags); 4321 4155 } 4322 4156 EXPORT_SYMBOL_GPL(gpiochip_line_is_persistent); 4323 4157 ··· 4555 4389 */ 4556 4390 void gpiod_add_hogs(struct gpiod_hog *hogs) 4557 4391 { 4558 - struct gpio_chip *chip; 4392 + struct gpio_chip *gc; 4559 4393 struct gpiod_hog *hog; 4560 4394 4561 4395 mutex_lock(&gpio_machine_hogs_mutex); ··· 4567 4401 * The chip may have been registered earlier, so check if it 4568 4402 * exists and, if so, try to hog the line now. 4569 4403 */ 4570 - chip = find_chip_by_name(hog->chip_label); 4571 - if (chip) 4572 - gpiochip_machine_hog(chip, hog); 4404 + gc = find_chip_by_name(hog->chip_label); 4405 + if (gc) 4406 + gpiochip_machine_hog(gc, hog); 4573 4407 } 4574 4408 4575 4409 mutex_unlock(&gpio_machine_hogs_mutex); ··· 4619 4453 return desc; 4620 4454 4621 4455 for (p = &table->table[0]; p->chip_label; p++) { 4622 - struct gpio_chip *chip; 4456 + struct gpio_chip *gc; 4623 4457 4624 4458 /* idx must always match exactly */ 4625 4459 if (p->idx != idx) ··· 4629 4463 if (p->con_id && (!con_id || strcmp(p->con_id, con_id))) 4630 4464 continue; 4631 4465 4632 - chip = find_chip_by_name(p->chip_label); 4466 + gc = find_chip_by_name(p->chip_label); 4633 4467 4634 - if (!chip) { 4468 + if (!gc) { 4635 4469 /* 4636 4470 * As the lookup table indicates a chip with 4637 4471 * p->chip_label should exist, assume it may ··· 4644 4478 return ERR_PTR(-EPROBE_DEFER); 4645 4479 } 4646 4480 4647 - if (chip->ngpio <= p->chip_hwnum) { 4481 + if (gc->ngpio <= p->chip_hwnum) { 4648 4482 dev_err(dev, 4649 4483 "requested GPIO %u (%u) is out of range [0..%u] for chip %s\n", 4650 - idx, p->chip_hwnum, chip->ngpio - 1, 4651 - chip->label); 4484 + idx, p->chip_hwnum, gc->ngpio - 1, 4485 + gc->label); 4652 4486 return ERR_PTR(-EINVAL); 4653 4487 } 4654 4488 4655 - desc = gpiochip_get_desc(chip, p->chip_hwnum); 4489 + desc = gpiochip_get_desc(gc, p->chip_hwnum); 4656 4490 *flags = p->flags; 4657 4491 4658 4492 return desc; ··· 5047 4881 int gpiod_hog(struct gpio_desc *desc, const char *name, 5048 4882 unsigned long lflags, enum gpiod_flags dflags) 5049 4883 { 5050 - struct gpio_chip *chip; 4884 + struct gpio_chip *gc; 5051 4885 struct gpio_desc *local_desc; 5052 4886 int hwnum; 5053 4887 int ret; 5054 4888 5055 - chip = gpiod_to_chip(desc); 4889 + gc = gpiod_to_chip(desc); 5056 4890 hwnum = gpio_chip_hwgpio(desc); 5057 4891 5058 - local_desc = gpiochip_request_own_desc(chip, hwnum, name, 4892 + local_desc = gpiochip_request_own_desc(gc, hwnum, name, 5059 4893 lflags, dflags); 5060 4894 if (IS_ERR(local_desc)) { 5061 4895 ret = PTR_ERR(local_desc); 5062 4896 pr_err("requesting hog GPIO %s (chip %s, offset %d) failed, %d\n", 5063 - name, chip->label, hwnum, ret); 4897 + name, gc->label, hwnum, ret); 5064 4898 return ret; 5065 4899 } 5066 4900 ··· 5078 4912 5079 4913 /** 5080 4914 * gpiochip_free_hogs - Scan gpio-controller chip and release GPIO hog 5081 - * @chip: gpio chip to act on 4915 + * @gc: gpio chip to act on 5082 4916 */ 5083 - static void gpiochip_free_hogs(struct gpio_chip *chip) 4917 + static void gpiochip_free_hogs(struct gpio_chip *gc) 5084 4918 { 5085 4919 int id; 5086 4920 5087 - for (id = 0; id < chip->ngpio; id++) { 5088 - if (test_bit(FLAG_IS_HOGGED, &chip->gpiodev->descs[id].flags)) 5089 - gpiochip_free_own_desc(&chip->gpiodev->descs[id]); 4921 + for (id = 0; id < gc->ngpio; id++) { 4922 + if (test_bit(FLAG_IS_HOGGED, &gc->gpiodev->descs[id].flags)) 4923 + gpiochip_free_own_desc(&gc->gpiodev->descs[id]); 5090 4924 } 5091 4925 } 5092 4926 ··· 5109 4943 struct gpio_desc *desc; 5110 4944 struct gpio_descs *descs; 5111 4945 struct gpio_array *array_info = NULL; 5112 - struct gpio_chip *chip; 4946 + struct gpio_chip *gc; 5113 4947 int count, bitmap_size; 5114 4948 5115 4949 count = gpiod_count(dev, con_id); ··· 5129 4963 5130 4964 descs->desc[descs->ndescs] = desc; 5131 4965 5132 - chip = gpiod_to_chip(desc); 4966 + gc = gpiod_to_chip(desc); 5133 4967 /* 5134 4968 * If pin hardware number of array member 0 is also 0, select 5135 4969 * its chip as a candidate for fast bitmap processing path. ··· 5137 4971 if (descs->ndescs == 0 && gpio_chip_hwgpio(desc) == 0) { 5138 4972 struct gpio_descs *array; 5139 4973 5140 - bitmap_size = BITS_TO_LONGS(chip->ngpio > count ? 5141 - chip->ngpio : count); 4974 + bitmap_size = BITS_TO_LONGS(gc->ngpio > count ? 4975 + gc->ngpio : count); 5142 4976 5143 4977 array = kzalloc(struct_size(descs, desc, count) + 5144 4978 struct_size(array_info, invert_mask, ··· 5161 4995 5162 4996 array_info->desc = descs->desc; 5163 4997 array_info->size = count; 5164 - array_info->chip = chip; 4998 + array_info->chip = gc; 5165 4999 bitmap_set(array_info->get_mask, descs->ndescs, 5166 5000 count - descs->ndescs); 5167 5001 bitmap_set(array_info->set_mask, descs->ndescs, ··· 5169 5003 descs->info = array_info; 5170 5004 } 5171 5005 /* Unmark array members which don't belong to the 'fast' chip */ 5172 - if (array_info && array_info->chip != chip) { 5006 + if (array_info && array_info->chip != gc) { 5173 5007 __clear_bit(descs->ndescs, array_info->get_mask); 5174 5008 __clear_bit(descs->ndescs, array_info->set_mask); 5175 5009 } ··· 5194 5028 } 5195 5029 } else if (array_info) { 5196 5030 /* Exclude open drain or open source from fast output */ 5197 - if (gpiochip_line_is_open_drain(chip, descs->ndescs) || 5198 - gpiochip_line_is_open_source(chip, descs->ndescs)) 5031 + if (gpiochip_line_is_open_drain(gc, descs->ndescs) || 5032 + gpiochip_line_is_open_source(gc, descs->ndescs)) 5199 5033 __clear_bit(descs->ndescs, 5200 5034 array_info->set_mask); 5201 5035 /* Identify 'fast' pins which require invertion */ ··· 5283 5117 if (ret < 0) { 5284 5118 pr_err("gpiolib: failed to allocate char dev region\n"); 5285 5119 bus_unregister(&gpio_bus_type); 5286 - } else { 5287 - gpiolib_initialized = true; 5288 - gpiochip_setup_devs(); 5120 + return ret; 5289 5121 } 5122 + 5123 + gpiolib_initialized = true; 5124 + gpiochip_setup_devs(); 5125 + 5126 + if (IS_ENABLED(CONFIG_OF_DYNAMIC)) 5127 + WARN_ON(of_reconfig_notifier_register(&gpio_of_notifier)); 5128 + 5290 5129 return ret; 5291 5130 } 5292 5131 core_initcall(gpiolib_dev_init); ··· 5301 5130 static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev) 5302 5131 { 5303 5132 unsigned i; 5304 - struct gpio_chip *chip = gdev->chip; 5133 + struct gpio_chip *gc = gdev->chip; 5305 5134 unsigned gpio = gdev->base; 5306 5135 struct gpio_desc *gdesc = &gdev->descs[0]; 5307 5136 bool is_out; ··· 5324 5153 seq_printf(s, " gpio-%-3d (%-20.20s|%-20.20s) %s %s %s%s", 5325 5154 gpio, gdesc->name ? gdesc->name : "", gdesc->label, 5326 5155 is_out ? "out" : "in ", 5327 - chip->get ? (chip->get(chip, i) ? "hi" : "lo") : "? ", 5156 + gc->get ? (gc->get(gc, i) ? "hi" : "lo") : "? ", 5328 5157 is_irq ? "IRQ " : "", 5329 5158 active_low ? "ACTIVE LOW" : ""); 5330 5159 seq_printf(s, "\n"); ··· 5376 5205 static int gpiolib_seq_show(struct seq_file *s, void *v) 5377 5206 { 5378 5207 struct gpio_device *gdev = v; 5379 - struct gpio_chip *chip = gdev->chip; 5208 + struct gpio_chip *gc = gdev->chip; 5380 5209 struct device *parent; 5381 5210 5382 - if (!chip) { 5211 + if (!gc) { 5383 5212 seq_printf(s, "%s%s: (dangling chip)", (char *)s->private, 5384 5213 dev_name(&gdev->dev)); 5385 5214 return 0; ··· 5388 5217 seq_printf(s, "%s%s: GPIOs %d-%d", (char *)s->private, 5389 5218 dev_name(&gdev->dev), 5390 5219 gdev->base, gdev->base + gdev->ngpio - 1); 5391 - parent = chip->parent; 5220 + parent = gc->parent; 5392 5221 if (parent) 5393 5222 seq_printf(s, ", parent: %s/%s", 5394 5223 parent->bus ? parent->bus->name : "no-bus", 5395 5224 dev_name(parent)); 5396 - if (chip->label) 5397 - seq_printf(s, ", %s", chip->label); 5398 - if (chip->can_sleep) 5225 + if (gc->label) 5226 + seq_printf(s, ", %s", gc->label); 5227 + if (gc->can_sleep) 5399 5228 seq_printf(s, ", can sleep"); 5400 5229 seq_printf(s, ":\n"); 5401 5230 5402 - if (chip->dbg_show) 5403 - chip->dbg_show(s, chip); 5231 + if (gc->dbg_show) 5232 + gc->dbg_show(s, gc); 5404 5233 else 5405 5234 gpiolib_dbg_show(s, gdev); 5406 5235
+4
drivers/gpio/gpiolib.h
··· 56 56 const char *label; 57 57 void *data; 58 58 struct list_head list; 59 + struct atomic_notifier_head notifier; 59 60 60 61 #ifdef CONFIG_PINCTRL 61 62 /* ··· 120 119 const char *label; 121 120 /* Name of the GPIO */ 122 121 const char *name; 122 + #ifdef CONFIG_OF_DYNAMIC 123 + struct device_node *hog; 124 + #endif 123 125 }; 124 126 125 127 int gpiod_request(struct gpio_desc *desc, const char *label);
+1
drivers/pinctrl/devicetree.c
··· 103 103 { 104 104 return get_pinctrl_dev_from_of_node(np); 105 105 } 106 + EXPORT_SYMBOL_GPL(of_pinctrl_get); 106 107 107 108 static int dt_to_map_one_config(struct pinctrl *p, 108 109 struct pinctrl_dev *hog_pctldev,
+2 -5
drivers/pinctrl/pinctrl-ingenic.c
··· 2323 2323 jzgc->gc.direction_input = ingenic_gpio_direction_input; 2324 2324 jzgc->gc.direction_output = ingenic_gpio_direction_output; 2325 2325 jzgc->gc.get_direction = ingenic_gpio_get_direction; 2326 - 2327 - if (of_property_read_bool(node, "gpio-ranges")) { 2328 - jzgc->gc.request = gpiochip_generic_request; 2329 - jzgc->gc.free = gpiochip_generic_free; 2330 - } 2326 + jzgc->gc.request = gpiochip_generic_request; 2327 + jzgc->gc.free = gpiochip_generic_free; 2331 2328 2332 2329 jzgc->irq = irq_of_parse_and_map(node, 0); 2333 2330 if (!jzgc->irq)
+2 -2
include/asm-generic/gpio.h
··· 2 2 #ifndef _ASM_GENERIC_GPIO_H 3 3 #define _ASM_GENERIC_GPIO_H 4 4 5 - #include <linux/kernel.h> 6 5 #include <linux/types.h> 7 6 #include <linux/errno.h> 8 - #include <linux/of.h> 9 7 10 8 #ifdef CONFIG_GPIOLIB 11 9 ··· 137 139 } 138 140 139 141 #else /* !CONFIG_GPIOLIB */ 142 + 143 + #include <linux/kernel.h> 140 144 141 145 static inline bool gpio_is_valid(int number) 142 146 {
-2
include/linux/gpio.h
··· 102 102 #include <linux/kernel.h> 103 103 #include <linux/types.h> 104 104 #include <linux/bug.h> 105 - #include <linux/pinctrl/pinctrl.h> 106 105 107 106 struct device; 108 107 struct gpio_chip; 109 - struct pinctrl_dev; 110 108 111 109 static inline bool gpio_is_valid(int number) 112 110 {
+12 -1
include/linux/gpio/consumer.h
··· 2 2 #ifndef __LINUX_GPIO_CONSUMER_H 3 3 #define __LINUX_GPIO_CONSUMER_H 4 4 5 + #include <linux/bits.h> 5 6 #include <linux/bug.h> 7 + #include <linux/compiler_types.h> 6 8 #include <linux/err.h> 7 - #include <linux/kernel.h> 8 9 9 10 struct device; 10 11 ··· 157 156 struct gpio_array *array_info, 158 157 unsigned long *value_bitmap); 159 158 159 + int gpiod_set_config(struct gpio_desc *desc, unsigned long config); 160 160 int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); 161 161 int gpiod_set_transitory(struct gpio_desc *desc, bool transitory); 162 162 void gpiod_toggle_active_low(struct gpio_desc *desc); ··· 190 188 const char *label); 191 189 192 190 #else /* CONFIG_GPIOLIB */ 191 + 192 + #include <linux/kernel.h> 193 193 194 194 static inline int gpiod_count(struct device *dev, const char *con_id) 195 195 { ··· 472 468 /* GPIO can never have been requested */ 473 469 WARN_ON(desc_array); 474 470 return 0; 471 + } 472 + 473 + static inline int gpiod_set_config(struct gpio_desc *desc, unsigned long config) 474 + { 475 + /* GPIO can never have been requested */ 476 + WARN_ON(desc); 477 + return -ENOSYS; 475 478 } 476 479 477 480 static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
+70 -69
include/linux/gpio/driver.h
··· 87 87 * @need_valid_mask to make these GPIO lines unavailable for 88 88 * translation. 89 89 */ 90 - int (*child_to_parent_hwirq)(struct gpio_chip *chip, 90 + int (*child_to_parent_hwirq)(struct gpio_chip *gc, 91 91 unsigned int child_hwirq, 92 92 unsigned int child_type, 93 93 unsigned int *parent_hwirq, ··· 102 102 * variant named &gpiochip_populate_parent_fwspec_fourcell is also 103 103 * available. 104 104 */ 105 - void *(*populate_parent_alloc_arg)(struct gpio_chip *chip, 105 + void *(*populate_parent_alloc_arg)(struct gpio_chip *gc, 106 106 unsigned int parent_hwirq, 107 107 unsigned int parent_type); 108 108 ··· 114 114 * callback. If this is not specified, then a default callback will be 115 115 * provided that returns the line offset. 116 116 */ 117 - unsigned int (*child_offset_to_irq)(struct gpio_chip *chip, 117 + unsigned int (*child_offset_to_irq)(struct gpio_chip *gc, 118 118 unsigned int pin); 119 119 120 120 /** ··· 209 209 * a particular driver wants to clear IRQ related registers 210 210 * in order to avoid undesired events. 211 211 */ 212 - int (*init_hw)(struct gpio_chip *chip); 212 + int (*init_hw)(struct gpio_chip *gc); 213 213 214 214 /** 215 215 * @init_valid_mask: optional routine to initialize @valid_mask, to be ··· 220 220 * then directly set some bits to "0" if they cannot be used for 221 221 * interrupts. 222 222 */ 223 - void (*init_valid_mask)(struct gpio_chip *chip, 223 + void (*init_valid_mask)(struct gpio_chip *gc, 224 224 unsigned long *valid_mask, 225 225 unsigned int ngpios); 226 226 ··· 348 348 struct device *parent; 349 349 struct module *owner; 350 350 351 - int (*request)(struct gpio_chip *chip, 351 + int (*request)(struct gpio_chip *gc, 352 352 unsigned offset); 353 - void (*free)(struct gpio_chip *chip, 353 + void (*free)(struct gpio_chip *gc, 354 354 unsigned offset); 355 - int (*get_direction)(struct gpio_chip *chip, 355 + int (*get_direction)(struct gpio_chip *gc, 356 356 unsigned offset); 357 - int (*direction_input)(struct gpio_chip *chip, 357 + int (*direction_input)(struct gpio_chip *gc, 358 358 unsigned offset); 359 - int (*direction_output)(struct gpio_chip *chip, 359 + int (*direction_output)(struct gpio_chip *gc, 360 360 unsigned offset, int value); 361 - int (*get)(struct gpio_chip *chip, 361 + int (*get)(struct gpio_chip *gc, 362 362 unsigned offset); 363 - int (*get_multiple)(struct gpio_chip *chip, 363 + int (*get_multiple)(struct gpio_chip *gc, 364 364 unsigned long *mask, 365 365 unsigned long *bits); 366 - void (*set)(struct gpio_chip *chip, 366 + void (*set)(struct gpio_chip *gc, 367 367 unsigned offset, int value); 368 - void (*set_multiple)(struct gpio_chip *chip, 368 + void (*set_multiple)(struct gpio_chip *gc, 369 369 unsigned long *mask, 370 370 unsigned long *bits); 371 - int (*set_config)(struct gpio_chip *chip, 371 + int (*set_config)(struct gpio_chip *gc, 372 372 unsigned offset, 373 373 unsigned long config); 374 - int (*to_irq)(struct gpio_chip *chip, 374 + int (*to_irq)(struct gpio_chip *gc, 375 375 unsigned offset); 376 376 377 377 void (*dbg_show)(struct seq_file *s, 378 - struct gpio_chip *chip); 378 + struct gpio_chip *gc); 379 379 380 - int (*init_valid_mask)(struct gpio_chip *chip, 380 + int (*init_valid_mask)(struct gpio_chip *gc, 381 381 unsigned long *valid_mask, 382 382 unsigned int ngpios); 383 383 384 - int (*add_pin_ranges)(struct gpio_chip *chip); 384 + int (*add_pin_ranges)(struct gpio_chip *gc); 385 385 386 386 int base; 387 387 u16 ngpio; ··· 458 458 #endif /* CONFIG_OF_GPIO */ 459 459 }; 460 460 461 - extern const char *gpiochip_is_requested(struct gpio_chip *chip, 461 + extern const char *gpiochip_is_requested(struct gpio_chip *gc, 462 462 unsigned offset); 463 463 464 464 /* add/remove chips */ 465 - extern int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, 465 + extern int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, 466 466 struct lock_class_key *lock_key, 467 467 struct lock_class_key *request_key); 468 468 ··· 490 490 * Otherwise it returns zero as a success code. 491 491 */ 492 492 #ifdef CONFIG_LOCKDEP 493 - #define gpiochip_add_data(chip, data) ({ \ 493 + #define gpiochip_add_data(gc, data) ({ \ 494 494 static struct lock_class_key lock_key; \ 495 495 static struct lock_class_key request_key; \ 496 - gpiochip_add_data_with_key(chip, data, &lock_key, \ 496 + gpiochip_add_data_with_key(gc, data, &lock_key, \ 497 497 &request_key); \ 498 498 }) 499 499 #else 500 - #define gpiochip_add_data(chip, data) gpiochip_add_data_with_key(chip, data, NULL, NULL) 500 + #define gpiochip_add_data(gc, data) gpiochip_add_data_with_key(gc, data, NULL, NULL) 501 501 #endif /* CONFIG_LOCKDEP */ 502 502 503 - static inline int gpiochip_add(struct gpio_chip *chip) 503 + static inline int gpiochip_add(struct gpio_chip *gc) 504 504 { 505 - return gpiochip_add_data(chip, NULL); 505 + return gpiochip_add_data(gc, NULL); 506 506 } 507 - extern void gpiochip_remove(struct gpio_chip *chip); 508 - extern int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *chip, 507 + extern void gpiochip_remove(struct gpio_chip *gc); 508 + extern int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *gc, 509 509 void *data); 510 510 511 511 extern struct gpio_chip *gpiochip_find(void *data, 512 - int (*match)(struct gpio_chip *chip, void *data)); 512 + int (*match)(struct gpio_chip *gc, void *data)); 513 513 514 - bool gpiochip_line_is_irq(struct gpio_chip *chip, unsigned int offset); 515 - int gpiochip_reqres_irq(struct gpio_chip *chip, unsigned int offset); 516 - void gpiochip_relres_irq(struct gpio_chip *chip, unsigned int offset); 517 - void gpiochip_disable_irq(struct gpio_chip *chip, unsigned int offset); 518 - void gpiochip_enable_irq(struct gpio_chip *chip, unsigned int offset); 514 + bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset); 515 + int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset); 516 + void gpiochip_relres_irq(struct gpio_chip *gc, unsigned int offset); 517 + void gpiochip_disable_irq(struct gpio_chip *gc, unsigned int offset); 518 + void gpiochip_enable_irq(struct gpio_chip *gc, unsigned int offset); 519 519 520 520 /* Line status inquiry for drivers */ 521 - bool gpiochip_line_is_open_drain(struct gpio_chip *chip, unsigned int offset); 522 - bool gpiochip_line_is_open_source(struct gpio_chip *chip, unsigned int offset); 521 + bool gpiochip_line_is_open_drain(struct gpio_chip *gc, unsigned int offset); 522 + bool gpiochip_line_is_open_source(struct gpio_chip *gc, unsigned int offset); 523 523 524 524 /* Sleep persistence inquiry for drivers */ 525 - bool gpiochip_line_is_persistent(struct gpio_chip *chip, unsigned int offset); 526 - bool gpiochip_line_is_valid(const struct gpio_chip *chip, unsigned int offset); 525 + bool gpiochip_line_is_persistent(struct gpio_chip *gc, unsigned int offset); 526 + bool gpiochip_line_is_valid(const struct gpio_chip *gc, unsigned int offset); 527 527 528 528 /* get driver data */ 529 - void *gpiochip_get_data(struct gpio_chip *chip); 529 + void *gpiochip_get_data(struct gpio_chip *gc); 530 530 531 531 struct bgpio_pdata { 532 532 const char *label; ··· 536 536 537 537 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY 538 538 539 - void *gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *chip, 539 + void *gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *gc, 540 540 unsigned int parent_hwirq, 541 541 unsigned int parent_type); 542 - void *gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *chip, 542 + void *gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *gc, 543 543 unsigned int parent_hwirq, 544 544 unsigned int parent_type); 545 545 546 546 #else 547 547 548 - static inline void *gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *chip, 548 + static inline void *gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *gc, 549 549 unsigned int parent_hwirq, 550 550 unsigned int parent_type) 551 551 { 552 552 return NULL; 553 553 } 554 554 555 - static inline void *gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *chip, 555 + static inline void *gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *gc, 556 556 unsigned int parent_hwirq, 557 557 unsigned int parent_type) 558 558 { ··· 572 572 #define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3) 573 573 #define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */ 574 574 #define BGPIOF_NO_OUTPUT BIT(5) /* only input */ 575 + #define BGPIOF_NO_SET_ON_INPUT BIT(6) 575 576 576 577 int gpiochip_irq_map(struct irq_domain *d, unsigned int irq, 577 578 irq_hw_number_t hwirq); ··· 583 582 void gpiochip_irq_domain_deactivate(struct irq_domain *domain, 584 583 struct irq_data *data); 585 584 586 - void gpiochip_set_nested_irqchip(struct gpio_chip *gpiochip, 585 + void gpiochip_set_nested_irqchip(struct gpio_chip *gc, 587 586 struct irq_chip *irqchip, 588 587 unsigned int parent_irq); 589 588 590 - int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip, 589 + int gpiochip_irqchip_add_key(struct gpio_chip *gc, 591 590 struct irq_chip *irqchip, 592 591 unsigned int first_irq, 593 592 irq_flow_handler_t handler, ··· 596 595 struct lock_class_key *lock_key, 597 596 struct lock_class_key *request_key); 598 597 599 - bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gpiochip, 598 + bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gc, 600 599 unsigned int offset); 601 600 602 601 #ifdef CONFIG_LOCKDEP ··· 607 606 * boilerplate static inlines provides such a key for each 608 607 * unique instance. 609 608 */ 610 - static inline int gpiochip_irqchip_add(struct gpio_chip *gpiochip, 609 + static inline int gpiochip_irqchip_add(struct gpio_chip *gc, 611 610 struct irq_chip *irqchip, 612 611 unsigned int first_irq, 613 612 irq_flow_handler_t handler, ··· 616 615 static struct lock_class_key lock_key; 617 616 static struct lock_class_key request_key; 618 617 619 - return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq, 618 + return gpiochip_irqchip_add_key(gc, irqchip, first_irq, 620 619 handler, type, false, 621 620 &lock_key, &request_key); 622 621 } 623 622 624 - static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gpiochip, 623 + static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gc, 625 624 struct irq_chip *irqchip, 626 625 unsigned int first_irq, 627 626 irq_flow_handler_t handler, ··· 631 630 static struct lock_class_key lock_key; 632 631 static struct lock_class_key request_key; 633 632 634 - return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq, 633 + return gpiochip_irqchip_add_key(gc, irqchip, first_irq, 635 634 handler, type, true, 636 635 &lock_key, &request_key); 637 636 } 638 637 #else /* ! CONFIG_LOCKDEP */ 639 - static inline int gpiochip_irqchip_add(struct gpio_chip *gpiochip, 638 + static inline int gpiochip_irqchip_add(struct gpio_chip *gc, 640 639 struct irq_chip *irqchip, 641 640 unsigned int first_irq, 642 641 irq_flow_handler_t handler, 643 642 unsigned int type) 644 643 { 645 - return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq, 644 + return gpiochip_irqchip_add_key(gc, irqchip, first_irq, 646 645 handler, type, false, NULL, NULL); 647 646 } 648 647 649 - static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gpiochip, 648 + static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gc, 650 649 struct irq_chip *irqchip, 651 650 unsigned int first_irq, 652 651 irq_flow_handler_t handler, 653 652 unsigned int type) 654 653 { 655 - return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq, 654 + return gpiochip_irqchip_add_key(gc, irqchip, first_irq, 656 655 handler, type, true, NULL, NULL); 657 656 } 658 657 #endif /* CONFIG_LOCKDEP */ 659 658 660 - int gpiochip_generic_request(struct gpio_chip *chip, unsigned offset); 661 - void gpiochip_generic_free(struct gpio_chip *chip, unsigned offset); 662 - int gpiochip_generic_config(struct gpio_chip *chip, unsigned offset, 659 + int gpiochip_generic_request(struct gpio_chip *gc, unsigned offset); 660 + void gpiochip_generic_free(struct gpio_chip *gc, unsigned offset); 661 + int gpiochip_generic_config(struct gpio_chip *gc, unsigned offset, 663 662 unsigned long config); 664 663 665 664 /** ··· 676 675 677 676 #ifdef CONFIG_PINCTRL 678 677 679 - int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name, 678 + int gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name, 680 679 unsigned int gpio_offset, unsigned int pin_offset, 681 680 unsigned int npins); 682 - int gpiochip_add_pingroup_range(struct gpio_chip *chip, 681 + int gpiochip_add_pingroup_range(struct gpio_chip *gc, 683 682 struct pinctrl_dev *pctldev, 684 683 unsigned int gpio_offset, const char *pin_group); 685 - void gpiochip_remove_pin_ranges(struct gpio_chip *chip); 684 + void gpiochip_remove_pin_ranges(struct gpio_chip *gc); 686 685 687 686 #else /* ! CONFIG_PINCTRL */ 688 687 689 688 static inline int 690 - gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name, 689 + gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name, 691 690 unsigned int gpio_offset, unsigned int pin_offset, 692 691 unsigned int npins) 693 692 { 694 693 return 0; 695 694 } 696 695 static inline int 697 - gpiochip_add_pingroup_range(struct gpio_chip *chip, 696 + gpiochip_add_pingroup_range(struct gpio_chip *gc, 698 697 struct pinctrl_dev *pctldev, 699 698 unsigned int gpio_offset, const char *pin_group) 700 699 { ··· 702 701 } 703 702 704 703 static inline void 705 - gpiochip_remove_pin_ranges(struct gpio_chip *chip) 704 + gpiochip_remove_pin_ranges(struct gpio_chip *gc) 706 705 { 707 706 } 708 707 709 708 #endif /* CONFIG_PINCTRL */ 710 709 711 - struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, 710 + struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc, 712 711 unsigned int hwnum, 713 712 const char *label, 714 713 enum gpio_lookup_flags lflags, 715 714 enum gpiod_flags dflags); 716 715 void gpiochip_free_own_desc(struct gpio_desc *desc); 717 716 718 - void devprop_gpiochip_set_names(struct gpio_chip *chip, 717 + void devprop_gpiochip_set_names(struct gpio_chip *gc, 719 718 const struct fwnode_handle *fwnode); 720 719 721 720 #ifdef CONFIG_GPIOLIB 722 721 723 722 /* lock/unlock as IRQ */ 724 - int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset); 725 - void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset); 723 + int gpiochip_lock_as_irq(struct gpio_chip *gc, unsigned int offset); 724 + void gpiochip_unlock_as_irq(struct gpio_chip *gc, unsigned int offset); 726 725 727 726 728 727 struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); ··· 736 735 return ERR_PTR(-ENODEV); 737 736 } 738 737 739 - static inline int gpiochip_lock_as_irq(struct gpio_chip *chip, 738 + static inline int gpiochip_lock_as_irq(struct gpio_chip *gc, 740 739 unsigned int offset) 741 740 { 742 741 WARN_ON(1); 743 742 return -EINVAL; 744 743 } 745 744 746 - static inline void gpiochip_unlock_as_irq(struct gpio_chip *chip, 745 + static inline void gpiochip_unlock_as_irq(struct gpio_chip *gc, 747 746 unsigned int offset) 748 747 { 749 748 WARN_ON(1);
+73
include/linux/kfifo.h
··· 247 247 }) 248 248 249 249 /** 250 + * kfifo_is_empty_spinlocked - returns true if the fifo is empty using 251 + * a spinlock for locking 252 + * @fifo: address of the fifo to be used 253 + * @lock: spinlock to be used for locking 254 + */ 255 + #define kfifo_is_empty_spinlocked(fifo, lock) \ 256 + ({ \ 257 + unsigned long __flags; \ 258 + bool __ret; \ 259 + spin_lock_irqsave(lock, __flags); \ 260 + __ret = kfifo_is_empty(fifo); \ 261 + spin_unlock_irqrestore(lock, __flags); \ 262 + __ret; \ 263 + }) 264 + 265 + /** 266 + * kfifo_is_empty_spinlocked_noirqsave - returns true if the fifo is empty 267 + * using a spinlock for locking, doesn't disable interrupts 268 + * @fifo: address of the fifo to be used 269 + * @lock: spinlock to be used for locking 270 + */ 271 + #define kfifo_is_empty_spinlocked_noirqsave(fifo, lock) \ 272 + ({ \ 273 + bool __ret; \ 274 + spin_lock(lock); \ 275 + __ret = kfifo_is_empty(fifo); \ 276 + spin_unlock(lock); \ 277 + __ret; \ 278 + }) 279 + 280 + /** 250 281 * kfifo_is_full - returns true if the fifo is full 251 282 * @fifo: address of the fifo to be used 252 283 */ ··· 548 517 __ret; \ 549 518 }) 550 519 520 + /** 521 + * kfifo_in_spinlocked_noirqsave - put data into fifo using a spinlock for 522 + * locking, don't disable interrupts 523 + * @fifo: address of the fifo to be used 524 + * @buf: the data to be added 525 + * @n: number of elements to be added 526 + * @lock: pointer to the spinlock to use for locking 527 + * 528 + * This is a variant of kfifo_in_spinlocked() but uses spin_lock/unlock() 529 + * for locking and doesn't disable interrupts. 530 + */ 531 + #define kfifo_in_spinlocked_noirqsave(fifo, buf, n, lock) \ 532 + ({ \ 533 + unsigned int __ret; \ 534 + spin_lock(lock); \ 535 + __ret = kfifo_in(fifo, buf, n); \ 536 + spin_unlock(lock); \ 537 + __ret; \ 538 + }) 539 + 551 540 /* alias for kfifo_in_spinlocked, will be removed in a future release */ 552 541 #define kfifo_in_locked(fifo, buf, n, lock) \ 553 542 kfifo_in_spinlocked(fifo, buf, n, lock) ··· 616 565 spin_lock_irqsave(lock, __flags); \ 617 566 __ret = kfifo_out(fifo, buf, n); \ 618 567 spin_unlock_irqrestore(lock, __flags); \ 568 + __ret; \ 569 + }) \ 570 + ) 571 + 572 + /** 573 + * kfifo_out_spinlocked_noirqsave - get data from the fifo using a spinlock 574 + * for locking, don't disable interrupts 575 + * @fifo: address of the fifo to be used 576 + * @buf: pointer to the storage buffer 577 + * @n: max. number of elements to get 578 + * @lock: pointer to the spinlock to use for locking 579 + * 580 + * This is a variant of kfifo_out_spinlocked() which uses spin_lock/unlock() 581 + * for locking and doesn't disable interrupts. 582 + */ 583 + #define kfifo_out_spinlocked_noirqsave(fifo, buf, n, lock) \ 584 + __kfifo_uint_must_check_helper( \ 585 + ({ \ 586 + unsigned int __ret; \ 587 + spin_lock(lock); \ 588 + __ret = kfifo_out(fifo, buf, n); \ 589 + spin_unlock(lock); \ 619 590 __ret; \ 620 591 }) \ 621 592 )
+6 -3
include/linux/of_gpio.h
··· 11 11 #define __LINUX_OF_GPIO_H 12 12 13 13 #include <linux/compiler.h> 14 - #include <linux/kernel.h> 15 - #include <linux/errno.h> 16 - #include <linux/gpio.h> 14 + #include <linux/gpio/driver.h> 15 + #include <linux/gpio.h> /* FIXME: Shouldn't be here */ 17 16 #include <linux/of.h> 18 17 19 18 struct device_node; ··· 32 33 }; 33 34 34 35 #ifdef CONFIG_OF_GPIO 36 + 37 + #include <linux/kernel.h> 35 38 36 39 /* 37 40 * OF GPIO chip for memory mapped banks ··· 63 62 extern void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc); 64 63 65 64 #else /* CONFIG_OF_GPIO */ 65 + 66 + #include <linux/errno.h> 66 67 67 68 /* Drivers may not strictly depend on the GPIO support, so let them link. */ 68 69 static inline int of_get_named_gpio_flags(struct device_node *np,
+1 -1
include/linux/pinctrl/pinctrl.h
··· 186 186 const char *pin_group, const unsigned **pins, 187 187 unsigned *num_pins); 188 188 189 - #ifdef CONFIG_OF 189 + #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_PINCTRL) 190 190 extern struct pinctrl_dev *of_pinctrl_get(struct device_node *np); 191 191 #else 192 192 static inline
+34 -4
include/uapi/linux/gpio.h
··· 18 18 * struct gpiochip_info - Information about a certain GPIO chip 19 19 * @name: the Linux kernel name of this GPIO chip 20 20 * @label: a functional name for this GPIO chip, such as a product 21 - * number, may be NULL 21 + * number, may be empty 22 22 * @lines: number of GPIO lines on this chip 23 23 */ 24 24 struct gpiochip_info { ··· 44 44 * @flags: various flags for this line 45 45 * @name: the name of this GPIO line, such as the output pin of the line on the 46 46 * chip, a rail or a pin header name on a board, as specified by the gpio 47 - * chip, may be NULL 47 + * chip, may be empty 48 48 * @consumer: a functional name for the consumer of this GPIO line as set by 49 - * whatever is using it, will be NULL if there is no current user but may 50 - * also be NULL if the consumer doesn't set this up 49 + * whatever is using it, will be empty if there is no current user but may 50 + * also be empty if the consumer doesn't set this up 51 51 */ 52 52 struct gpioline_info { 53 53 __u32 line_offset; ··· 58 58 59 59 /* Maximum number of requested handles */ 60 60 #define GPIOHANDLES_MAX 64 61 + 62 + /* Possible line status change events */ 63 + enum { 64 + GPIOLINE_CHANGED_REQUESTED = 1, 65 + GPIOLINE_CHANGED_RELEASED, 66 + GPIOLINE_CHANGED_CONFIG, 67 + }; 68 + 69 + /** 70 + * struct gpioline_info_changed - Information about a change in status 71 + * of a GPIO line 72 + * @info: updated line information 73 + * @timestamp: estimate of time of status change occurrence, in nanoseconds 74 + * and GPIOLINE_CHANGED_CONFIG 75 + * @event_type: one of GPIOLINE_CHANGED_REQUESTED, GPIOLINE_CHANGED_RELEASED 76 + * 77 + * Note: struct gpioline_info embedded here has 32-bit alignment on its own, 78 + * but it works fine with 64-bit alignment too. With its 72 byte size, we can 79 + * guarantee there are no implicit holes between it and subsequent members. 80 + * The 20-byte padding at the end makes sure we don't add any implicit padding 81 + * at the end of the structure on 64-bit architectures. 82 + */ 83 + struct gpioline_info_changed { 84 + struct gpioline_info info; 85 + __u64 timestamp; 86 + __u32 event_type; 87 + __u32 padding[5]; /* for future use */ 88 + }; 61 89 62 90 /* Linerequest flags */ 63 91 #define GPIOHANDLE_REQUEST_INPUT (1UL << 0) ··· 204 176 205 177 #define GPIO_GET_CHIPINFO_IOCTL _IOR(0xB4, 0x01, struct gpiochip_info) 206 178 #define GPIO_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x02, struct gpioline_info) 179 + #define GPIO_GET_LINEINFO_WATCH_IOCTL _IOWR(0xB4, 0x0b, struct gpioline_info) 180 + #define GPIO_GET_LINEINFO_UNWATCH_IOCTL _IOWR(0xB4, 0x0c, __u32) 207 181 #define GPIO_GET_LINEHANDLE_IOCTL _IOWR(0xB4, 0x03, struct gpiohandle_request) 208 182 #define GPIO_GET_LINEEVENT_IOCTL _IOWR(0xB4, 0x04, struct gpioevent_request) 209 183
+1
tools/gpio/.gitignore
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 gpio-event-mon 3 3 gpio-hammer 4 + gpio-watch 4 5 lsgpio 5 6 include/linux/gpio.h
+1
tools/gpio/Build
··· 2 2 lsgpio-y += lsgpio.o gpio-utils.o 3 3 gpio-hammer-y += gpio-hammer.o gpio-utils.o 4 4 gpio-event-mon-y += gpio-event-mon.o gpio-utils.o 5 + gpio-watch-y += gpio-watch.o
+11 -2
tools/gpio/Makefile
··· 18 18 19 19 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include 20 20 21 - ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon 21 + ALL_TARGETS := lsgpio gpio-hammer gpio-event-mon gpio-watch 22 22 ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS)) 23 23 24 24 all: $(ALL_PROGRAMS) ··· 35 35 36 36 prepare: $(OUTPUT)include/linux/gpio.h 37 37 38 - GPIO_UTILS_IN := $(output)gpio-utils-in.o 38 + GPIO_UTILS_IN := $(OUTPUT)gpio-utils-in.o 39 39 $(GPIO_UTILS_IN): prepare FORCE 40 40 $(Q)$(MAKE) $(build)=gpio-utils 41 41 ··· 64 64 $(GPIO_EVENT_MON_IN): prepare FORCE $(OUTPUT)gpio-utils-in.o 65 65 $(Q)$(MAKE) $(build)=gpio-event-mon 66 66 $(OUTPUT)gpio-event-mon: $(GPIO_EVENT_MON_IN) 67 + $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ 68 + 69 + # 70 + # gpio-watch 71 + # 72 + GPIO_WATCH_IN := $(OUTPUT)gpio-watch-in.o 73 + $(GPIO_WATCH_IN): prepare FORCE 74 + $(Q)$(MAKE) $(build)=gpio-watch 75 + $(OUTPUT)gpio-watch: $(GPIO_WATCH_IN) 67 76 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ 68 77 69 78 clean:
+17 -2
tools/gpio/gpio-hammer.c
··· 77 77 78 78 fprintf(stdout, "[%c] ", swirr[j]); 79 79 j++; 80 - if (j == sizeof(swirr)-1) 80 + if (j == sizeof(swirr) - 1) 81 81 j = 0; 82 82 83 83 fprintf(stdout, "["); ··· 135 135 device_name = optarg; 136 136 break; 137 137 case 'o': 138 - lines[i] = strtoul(optarg, NULL, 10); 138 + /* 139 + * Avoid overflow. Do not immediately error, we want to 140 + * be able to accurately report on the amount of times 141 + * '-o' was given to give an accurate error message 142 + */ 143 + if (i < GPIOHANDLES_MAX) 144 + lines[i] = strtoul(optarg, NULL, 10); 145 + 139 146 i++; 140 147 break; 141 148 case '?': ··· 150 143 return -1; 151 144 } 152 145 } 146 + 147 + if (i >= GPIOHANDLES_MAX) { 148 + fprintf(stderr, 149 + "Only %d occurrences of '-o' are allowed, %d were found\n", 150 + GPIOHANDLES_MAX, i + 1); 151 + return -1; 152 + } 153 + 153 154 nlines = i; 154 155 155 156 if (!device_name || !nlines) {
+3 -3
tools/gpio/gpio-utils.c
··· 17 17 #include <linux/gpio.h> 18 18 #include "gpio-utils.h" 19 19 20 - #define COMSUMER "gpio-utils" 20 + #define CONSUMER "gpio-utils" 21 21 22 22 /** 23 23 * doc: Operation of gpio ··· 209 209 210 210 ret = gpiotools_request_linehandle(device_name, lines, nlines, 211 211 GPIOHANDLE_REQUEST_INPUT, data, 212 - COMSUMER); 212 + CONSUMER); 213 213 if (ret < 0) 214 214 return ret; 215 215 ··· 259 259 260 260 ret = gpiotools_request_linehandle(device_name, lines, nlines, 261 261 GPIOHANDLE_REQUEST_OUTPUT, data, 262 - COMSUMER); 262 + CONSUMER); 263 263 if (ret < 0) 264 264 return ret; 265 265
+99
tools/gpio/gpio-watch.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * gpio-watch - monitor unrequested lines for property changes using the 4 + * character device 5 + * 6 + * Copyright (C) 2019 BayLibre SAS 7 + * Author: Bartosz Golaszewski <bgolaszewski@baylibre.com> 8 + */ 9 + 10 + #include <ctype.h> 11 + #include <errno.h> 12 + #include <fcntl.h> 13 + #include <linux/gpio.h> 14 + #include <poll.h> 15 + #include <stdbool.h> 16 + #include <stdio.h> 17 + #include <stdlib.h> 18 + #include <string.h> 19 + #include <sys/ioctl.h> 20 + #include <unistd.h> 21 + 22 + int main(int argc, char **argv) 23 + { 24 + struct gpioline_info_changed chg; 25 + struct gpioline_info req; 26 + struct pollfd pfd; 27 + int fd, i, j, ret; 28 + char *event, *end; 29 + ssize_t rd; 30 + 31 + if (argc < 3) 32 + goto err_usage; 33 + 34 + fd = open(argv[1], O_RDWR | O_CLOEXEC); 35 + if (fd < 0) { 36 + perror("unable to open gpiochip"); 37 + return EXIT_FAILURE; 38 + } 39 + 40 + for (i = 0, j = 2; i < argc - 2; i++, j++) { 41 + memset(&req, 0, sizeof(req)); 42 + 43 + req.line_offset = strtoul(argv[j], &end, 0); 44 + if (*end != '\0') 45 + goto err_usage; 46 + 47 + ret = ioctl(fd, GPIO_GET_LINEINFO_WATCH_IOCTL, &req); 48 + if (ret) { 49 + perror("unable to set up line watch"); 50 + return EXIT_FAILURE; 51 + } 52 + } 53 + 54 + pfd.fd = fd; 55 + pfd.events = POLLIN | POLLPRI; 56 + 57 + for (;;) { 58 + ret = poll(&pfd, 1, 5000); 59 + if (ret < 0) { 60 + perror("error polling the linechanged fd"); 61 + return EXIT_FAILURE; 62 + } else if (ret > 0) { 63 + memset(&chg, 0, sizeof(chg)); 64 + rd = read(pfd.fd, &chg, sizeof(chg)); 65 + if (rd < 0 || rd != sizeof(chg)) { 66 + if (rd != sizeof(chg)) 67 + errno = EIO; 68 + 69 + perror("error reading line change event"); 70 + return EXIT_FAILURE; 71 + } 72 + 73 + switch (chg.event_type) { 74 + case GPIOLINE_CHANGED_REQUESTED: 75 + event = "requested"; 76 + break; 77 + case GPIOLINE_CHANGED_RELEASED: 78 + event = "released"; 79 + break; 80 + case GPIOLINE_CHANGED_CONFIG: 81 + event = "config changed"; 82 + break; 83 + default: 84 + fprintf(stderr, 85 + "invalid event type received from the kernel\n"); 86 + return EXIT_FAILURE; 87 + } 88 + 89 + printf("line %u: %s at %llu\n", 90 + chg.info.line_offset, event, chg.timestamp); 91 + } 92 + } 93 + 94 + return 0; 95 + 96 + err_usage: 97 + printf("%s: <gpiochip> <line0> <line1> ...\n", argv[0]); 98 + return EXIT_FAILURE; 99 + }