History

Merge tag 'gpio-v5.2-updates-for-linus-part1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux into devel

gpio: updates for v5.2 (part 1) - batch of improvements for the vf610 driver which shrink the code and make use of resource managed helpers - support for a new variant of pca953x - make gpio-mockup buildable on systems without IOMEM - make gpio-74x164 more flexible by using generic device properties plus minor improvements - new driver for Mellanox BlueField - fixes for wakeup GPIOs in gpio-omap - use devm_platform_ioremap_resource() in gpio-mxc - a couple improvements of kernel docs for ACPI code - don't WARN() in gpiod_put() on optional GPIOs

Linus Walleij committed 7 years ago

Commit 4779a062 parents 12f2639 b0d256910 files · +279 −125Browse files

Unified · Split

10 files
  1. Documentation/devicetree/bindings/gpio/gpio-pca953x.txt +1 −0
  2. drivers/gpio/Kconfig +19 −14
  3. drivers/gpio/Makefile +1 −0
  4. drivers/gpio/gpio-74x164.c +9 −13
  5. drivers/gpio/gpio-mlxbf.c +152 −0
  6. drivers/gpio/gpio-omap.c +33 −28
  7. drivers/gpio/gpio-pca953x.c +1 −0
  8. drivers/gpio/gpio-vf610.c +36 −49
  9. drivers/gpio/gpiolib-acpi.c +25 −20
  10. drivers/gpio/gpiolib.c +2 −1
Documentation/devicetree/bindings/gpio/gpio-pca953x.txt+1−0
@@ -30,6 +30,7 @@ Required properties: · 29 unmodified lines
30 ti,tca642430 ti,tca6424
31 ti,tca953931 ti,tca9539
32 ti,tca955432 ti,tca9554
33 onnn,cat9554
33 onnn,pca965434 onnn,pca9654
34 exar,xra120235 exar,xra1202
35 - gpio-controller: if used as gpio expander.36 - gpio-controller: if used as gpio expander.
drivers/gpio/Kconfig+19−14
@@ -330,20 +330,6 @@ config GPIO_MM_LANTIQ · 329 unmodified lines
330 (EBU) found on Lantiq SoCs. The gpios are output only as they are330 (EBU) found on Lantiq SoCs. The gpios are output only as they are
331 created by attaching a 16bit latch to the bus.331 created by attaching a 16bit latch to the bus.
332 332
333config GPIO_MOCKUP
334 tristate "GPIO Testing Driver"
335 depends on GPIOLIB && SYSFS
336 select GPIO_SYSFS
337 select GPIOLIB_IRQCHIP
338 select IRQ_SIM
339 help
340 This enables GPIO Testing driver, which provides a way to test GPIO
341 subsystem through sysfs(or char device) and debugfs. GPIO_SYSFS
342 must be selected for this test.
343 User could use it through the script in
344 tools/testing/selftests/gpio/gpio-mockup.sh. Reference the usage in
345 it.
346
347config GPIO_MPC5200333config GPIO_MPC5200
348 def_bool y334 def_bool y
349 depends on PPC_MPC52xx335 depends on PPC_MPC52xx
@@ -1316,6 +1302,13 @@ config GPIO_MERRIFIELD · 966 unmodified lines
1316 help1302 help
1317 Say Y here to support Intel Merrifield GPIO.1303 Say Y here to support Intel Merrifield GPIO.
1318 1304
1305config GPIO_MLXBF
1306 tristate "Mellanox BlueField SoC GPIO"
1307 depends on (MELLANOX_PLATFORM && ARM64 && ACPI) || (64BIT && COMPILE_TEST)
1308 select GPIO_GENERIC
1309 help
1310 Say Y here if you want GPIO support on Mellanox BlueField SoC.
1311
1319config GPIO_ML_IOH1312config GPIO_ML_IOH
1320 tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support"1313 tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support"
1321 depends on X86 || COMPILE_TEST1314 depends on X86 || COMPILE_TEST
@@ -1442,4 +1435,16 @@ config GPIO_VIPERBOARD · 120 unmodified lines
1442 1435
1443endmenu1436endmenu
1444 1437
1438config GPIO_MOCKUP
1439 tristate "GPIO Testing Driver"
1440 depends on GPIOLIB
1441 select IRQ_SIM
1442 help
1443 This enables GPIO Testing driver, which provides a way to test GPIO
1444 subsystem through sysfs(or char device) and debugfs. GPIO_SYSFS
1445 must be selected for this test.
1446 User could use it through the script in
1447 tools/testing/selftests/gpio/gpio-mockup.sh. Reference the usage in
1448 it.
1449
1445endif1450endif
drivers/gpio/Makefile+1−0
@@ -85,6 +85,7 @@ obj-$(CONFIG_GPIO_MENZ127) += gpio-menz127.o · 84 unmodified lines
85obj-$(CONFIG_GPIO_MERRIFIELD) += gpio-merrifield.o85obj-$(CONFIG_GPIO_MERRIFIELD) += gpio-merrifield.o
86obj-$(CONFIG_GPIO_MC33880) += gpio-mc33880.o86obj-$(CONFIG_GPIO_MC33880) += gpio-mc33880.o
87obj-$(CONFIG_GPIO_MC9S08DZ60) += gpio-mc9s08dz60.o87obj-$(CONFIG_GPIO_MC9S08DZ60) += gpio-mc9s08dz60.o
88obj-$(CONFIG_GPIO_MLXBF) += gpio-mlxbf.o
88obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o89obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o
89obj-$(CONFIG_GPIO_MM_LANTIQ) += gpio-mm-lantiq.o90obj-$(CONFIG_GPIO_MM_LANTIQ) += gpio-mm-lantiq.o
90obj-$(CONFIG_GPIO_MOCKUP) += gpio-mockup.o91obj-$(CONFIG_GPIO_MOCKUP) += gpio-mockup.o
drivers/gpio/gpio-74x164.c+9−13
@@ -1,21 +1,18 @@
1// SPDX-License-Identifier: GPL-2.0-only
1/*2/*
2 * 74Hx164 - Generic serial-in/parallel-out 8-bits shift register GPIO driver3 * 74Hx164 - Generic serial-in/parallel-out 8-bits shift register GPIO driver
3 *4 *
4 * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>5 * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2010 Miguel Gaio <miguel.gaio@efixo.com>6 * Copyright (C) 2010 Miguel Gaio <miguel.gaio@efixo.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */7 */
11 8
12#include <linux/init.h>
13#include <linux/mutex.h>
14#include <linux/spi/spi.h>
15#include <linux/gpio/driver.h>
16#include <linux/gpio/consumer.h>9#include <linux/gpio/consumer.h>
17#include <linux/slab.h>10#include <linux/gpio/driver.h>
18#include <linux/module.h>11#include <linux/module.h>
12#include <linux/mutex.h>
13#include <linux/property.h>
14#include <linux/slab.h>
15#include <linux/spi/spi.h>
19 16
20#define GEN_74X164_NUMBER_GPIOS 817#define GEN_74X164_NUMBER_GPIOS 8
21 18
@@ -116,10 +113,9 @@ static int gen_74x164_probe(struct spi_device *spi) · 94 unmodified lines
116 if (ret < 0)113 if (ret < 0)
117 return ret;114 return ret;
118 115
119 if (of_property_read_u32(spi->dev.of_node, "registers-number",116 ret = device_property_read_u32(&spi->dev, "registers-number", &nregs);
120 &nregs)) {117 if (ret) {
121 dev_err(&spi->dev,118 dev_err(&spi->dev, "Missing 'registers-number' property.\n");
122 "Missing registers-number property in the DT.\n");
123 return -EINVAL;119 return -EINVAL;
124 }120 }
125 121
drivers/gpio/gpio-mlxbf.c+152−0
@@ -0,0 +1,152 @@
1// SPDX-License-Identifier: GPL-2.0
2
3#include <linux/acpi.h>
4#include <linux/bitops.h>
5#include <linux/device.h>
6#include <linux/gpio/driver.h>
7#include <linux/io.h>
8#include <linux/kernel.h>
9#include <linux/module.h>
10#include <linux/platform_device.h>
11#include <linux/pm.h>
12#include <linux/resource.h>
13#include <linux/types.h>
14
15/* Number of pins on BlueField */
16#define MLXBF_GPIO_NR 54
17
18/* Pad Electrical Controls. */
19#define MLXBF_GPIO_PAD_CONTROL_FIRST_WORD 0x0700
20#define MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD 0x0708
21#define MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD 0x0710
22#define MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD 0x0718
23
24#define MLXBF_GPIO_PIN_DIR_I 0x1040
25#define MLXBF_GPIO_PIN_DIR_O 0x1048
26#define MLXBF_GPIO_PIN_STATE 0x1000
27#define MLXBF_GPIO_SCRATCHPAD 0x20
28
29#ifdef CONFIG_PM
30struct mlxbf_gpio_context_save_regs {
31 u64 scratchpad;
32 u64 pad_control[MLXBF_GPIO_NR];
33 u64 pin_dir_i;
34 u64 pin_dir_o;
35};
36#endif
37
38/* Device state structure. */
39struct mlxbf_gpio_state {
40 struct gpio_chip gc;
41
42 /* Memory Address */
43 void __iomem *base;
44
45#ifdef CONFIG_PM
46 struct mlxbf_gpio_context_save_regs csave_regs;
47#endif
48};
49
50static int mlxbf_gpio_probe(struct platform_device *pdev)
51{
52 struct mlxbf_gpio_state *gs;
53 struct device *dev = &pdev->dev;
54 struct gpio_chip *gc;
55 int ret;
56
57 gs = devm_kzalloc(&pdev->dev, sizeof(*gs), GFP_KERNEL);
58 if (!gs)
59 return -ENOMEM;
60
61 gs->base = devm_platform_ioremap_resource(pdev, 0);
62 if (IS_ERR(gs->base))
63 return PTR_ERR(gs->base);
64
65 gc = &gs->gc;
66 ret = bgpio_init(gc, dev, 8,
67 gs->base + MLXBF_GPIO_PIN_STATE,
68 NULL,
69 NULL,
70 gs->base + MLXBF_GPIO_PIN_DIR_O,
71 gs->base + MLXBF_GPIO_PIN_DIR_I,
72 0);
73 if (ret)
74 return -ENODEV;
75
76 gc->owner = THIS_MODULE;
77 gc->ngpio = MLXBF_GPIO_NR;
78
79 ret = devm_gpiochip_add_data(dev, &gs->gc, gs);
80 if (ret) {
81 dev_err(&pdev->dev, "Failed adding memory mapped gpiochip\n");
82 return ret;
83 }
84
85 platform_set_drvdata(pdev, gs);
86 dev_info(&pdev->dev, "registered Mellanox BlueField GPIO");
87 return 0;
88}
89
90#ifdef CONFIG_PM
91static int mlxbf_gpio_suspend(struct platform_device *pdev, pm_message_t state)
92{
93 struct mlxbf_gpio_state *gs = platform_get_drvdata(pdev);
94
95 gs->csave_regs.scratchpad = readq(gs->base + MLXBF_GPIO_SCRATCHPAD);
96 gs->csave_regs.pad_control[0] =
97 readq(gs->base + MLXBF_GPIO_PAD_CONTROL_FIRST_WORD);
98 gs->csave_regs.pad_control[1] =
99 readq(gs->base + MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD);
100 gs->csave_regs.pad_control[2] =
101 readq(gs->base + MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD);
102 gs->csave_regs.pad_control[3] =
103 readq(gs->base + MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD);
104 gs->csave_regs.pin_dir_i = readq(gs->base + MLXBF_GPIO_PIN_DIR_I);
105 gs->csave_regs.pin_dir_o = readq(gs->base + MLXBF_GPIO_PIN_DIR_O);
106
107 return 0;
108}
109
110static int mlxbf_gpio_resume(struct platform_device *pdev)
111{
112 struct mlxbf_gpio_state *gs = platform_get_drvdata(pdev);
113
114 writeq(gs->csave_regs.scratchpad, gs->base + MLXBF_GPIO_SCRATCHPAD);
115 writeq(gs->csave_regs.pad_control[0],
116 gs->base + MLXBF_GPIO_PAD_CONTROL_FIRST_WORD);
117 writeq(gs->csave_regs.pad_control[1],
118 gs->base + MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD);
119 writeq(gs->csave_regs.pad_control[2],
120 gs->base + MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD);
121 writeq(gs->csave_regs.pad_control[3],
122 gs->base + MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD);
123 writeq(gs->csave_regs.pin_dir_i, gs->base + MLXBF_GPIO_PIN_DIR_I);
124 writeq(gs->csave_regs.pin_dir_o, gs->base + MLXBF_GPIO_PIN_DIR_O);
125
126 return 0;
127}
128#endif
129
130static const struct acpi_device_id mlxbf_gpio_acpi_match[] = {
131 { "MLNXBF02", 0 },
132 {}
133};
134MODULE_DEVICE_TABLE(acpi, mlxbf_gpio_acpi_match);
135
136static struct platform_driver mlxbf_gpio_driver = {
137 .driver = {
138 .name = "mlxbf_gpio",
139 .acpi_match_table = ACPI_PTR(mlxbf_gpio_acpi_match),
140 },
141 .probe = mlxbf_gpio_probe,
142#ifdef CONFIG_PM
143 .suspend = mlxbf_gpio_suspend,
144 .resume = mlxbf_gpio_resume,
145#endif
146};
147
148module_platform_driver(mlxbf_gpio_driver);
149
150MODULE_DESCRIPTION("Mellanox BlueField GPIO Driver");
151MODULE_AUTHOR("Mellanox Technologies");
152MODULE_LICENSE("GPL");
drivers/gpio/gpio-omap.c+33−28
@@ -83,7 +83,6 @@ struct gpio_bank { · 82 unmodified lines
83 int stride;83 int stride;
84 u32 width;84 u32 width;
85 int context_loss_count;85 int context_loss_count;
86 bool workaround_enabled;
87 u32 quirks;86 u32 quirks;
88 87
89 void (*set_dataout)(struct gpio_bank *bank, unsigned gpio, int enable);88 void (*set_dataout)(struct gpio_bank *bank, unsigned gpio, int enable);
@@ -353,6 +352,22 @@ static void omap_clear_gpio_debounce(struct gpio_bank *bank, unsigned offset) · 263 unmodified lines
353 }352 }
354}353}
355 354
355/*
356 * Off mode wake-up capable GPIOs in bank(s) that are in the wakeup domain.
357 * See TRM section for GPIO for "Wake-Up Generation" for the list of GPIOs
358 * in wakeup domain. If bank->non_wakeup_gpios is not configured, assume none
359 * are capable waking up the system from off mode.
360 */
361static bool omap_gpio_is_off_wakeup_capable(struct gpio_bank *bank, u32 gpio_mask)
362{
363 u32 no_wake = bank->non_wakeup_gpios;
364
365 if (no_wake)
366 return !!(~no_wake & gpio_mask);
367
368 return false;
369}
370
356static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio,371static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio,
357 unsigned trigger)372 unsigned trigger)
358{373{
@@ -384,13 +399,7 @@ static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio, · 25 unmodified lines
384 }399 }
385 400
386 /* This part needs to be executed always for OMAP{34xx, 44xx} */401 /* This part needs to be executed always for OMAP{34xx, 44xx} */
387 if (!bank->regs->irqctrl) {402 if (!bank->regs->irqctrl && !omap_gpio_is_off_wakeup_capable(bank, gpio)) {
388 /* On omap24xx proceed only when valid GPIO bit is set */
389 if (bank->non_wakeup_gpios) {
390 if (!(bank->non_wakeup_gpios & gpio_bit))
391 goto exit;
392 }
393
394 /*403 /*
395 * Log the edge gpio and manually trigger the IRQ404 * Log the edge gpio and manually trigger the IRQ
396 * after resume if the input level changes405 * after resume if the input level changes
@@ -403,7 +412,6 @@ static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio, · 6 unmodified lines
403 bank->enabled_non_wakeup_gpios &= ~gpio_bit;412 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
404 }413 }
405 414
406exit:
407 bank->level_mask =415 bank->level_mask =
408 readl_relaxed(bank->base + bank->regs->leveldetect0) |416 readl_relaxed(bank->base + bank->regs->leveldetect0) |
409 readl_relaxed(bank->base + bank->regs->leveldetect1);417 readl_relaxed(bank->base + bank->regs->leveldetect1);
@@ -1311,7 +1319,10 @@ static void omap_gpio_restore_context(struct gpio_bank *bank) · 901 unmodified lines
1311static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context)1319static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context)
1312{1320{
1313 struct device *dev = bank->chip.parent;1321 struct device *dev = bank->chip.parent;
1314 u32 l1 = 0, l2 = 0;1322 void __iomem *base = bank->base;
1323 u32 nowake;
1324
1325 bank->saved_datain = readl_relaxed(base + bank->regs->datain);
1315 1326
1316 if (bank->funcs.idle_enable_level_quirk)1327 if (bank->funcs.idle_enable_level_quirk)
1317 bank->funcs.idle_enable_level_quirk(bank);1328 bank->funcs.idle_enable_level_quirk(bank);
@@ -1323,22 +1334,15 @@ static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context) · 5 unmodified lines
1323 goto update_gpio_context_count;1334 goto update_gpio_context_count;
1324 1335
1325 /*1336 /*
1326 * If going to OFF, remove triggering for all1337 * If going to OFF, remove triggering for all wkup domain
1327 * non-wakeup GPIOs. Otherwise spurious IRQs will be1338 * non-wakeup GPIOs. Otherwise spurious IRQs will be
1328 * generated. See OMAP2420 Errata item 1.101.1339 * generated. See OMAP2420 Errata item 1.101.
1329 */1340 */
1330 bank->saved_datain = readl_relaxed(bank->base +1341 if (!bank->loses_context && bank->enabled_non_wakeup_gpios) {
1331 bank->regs->datain);1342 nowake = bank->enabled_non_wakeup_gpios;
1332 l1 = bank->context.fallingdetect;1343 omap_gpio_rmw(base, bank->regs->fallingdetect, nowake, ~nowake);
1333 l2 = bank->context.risingdetect;1344 omap_gpio_rmw(base, bank->regs->risingdetect, nowake, ~nowake);
1334 1345 }
1335 l1 &= ~bank->enabled_non_wakeup_gpios;
1336 l2 &= ~bank->enabled_non_wakeup_gpios;
1337
1338 writel_relaxed(l1, bank->base + bank->regs->fallingdetect);
1339 writel_relaxed(l2, bank->base + bank->regs->risingdetect);
1340
1341 bank->workaround_enabled = true;
1342 1346
1343update_gpio_context_count:1347update_gpio_context_count:
1344 if (bank->get_context_loss_count)1348 if (bank->get_context_loss_count)
@@ -1383,11 +1387,14 @@ static void omap_gpio_unidle(struct gpio_bank *bank) · 38 unmodified lines
1383 return;1387 return;
1384 }1388 }
1385 }1389 }
1390 } else {
1391 /* Restore changes done for OMAP2420 errata 1.101 */
1392 writel_relaxed(bank->context.fallingdetect,
1393 bank->base + bank->regs->fallingdetect);
1394 writel_relaxed(bank->context.risingdetect,
1395 bank->base + bank->regs->risingdetect);
1386 }1396 }
1387 1397
1388 if (!bank->workaround_enabled)
1389 return;
1390
1391 l = readl_relaxed(bank->base + bank->regs->datain);1398 l = readl_relaxed(bank->base + bank->regs->datain);
1392 1399
1393 /*1400 /*
@@ -1437,8 +1444,6 @@ static void omap_gpio_unidle(struct gpio_bank *bank) · 43 unmodified lines
1437 writel_relaxed(old0, bank->base + bank->regs->leveldetect0);1444 writel_relaxed(old0, bank->base + bank->regs->leveldetect0);
1438 writel_relaxed(old1, bank->base + bank->regs->leveldetect1);1445 writel_relaxed(old1, bank->base + bank->regs->leveldetect1);
1439 }1446 }
1440
1441 bank->workaround_enabled = false;
1442}1447}
1443 1448
1444static int gpio_omap_cpu_notifier(struct notifier_block *nb,1449static int gpio_omap_cpu_notifier(struct notifier_block *nb,
drivers/gpio/gpio-pca953x.c+1−0
@@ -1178,6 +1178,7 @@ static const struct of_device_id pca953x_dt_ids[] = { · 1177 unmodified lines
1178 { .compatible = "ti,tca6416", .data = OF_953X(16, PCA_INT), },1178 { .compatible = "ti,tca6416", .data = OF_953X(16, PCA_INT), },
1179 { .compatible = "ti,tca6424", .data = OF_953X(24, PCA_INT), },1179 { .compatible = "ti,tca6424", .data = OF_953X(24, PCA_INT), },
1180 1180
1181 { .compatible = "onnn,cat9554", .data = OF_953X( 8, PCA_INT), },
1181 { .compatible = "onnn,pca9654", .data = OF_953X( 8, PCA_INT), },1182 { .compatible = "onnn,pca9654", .data = OF_953X( 8, PCA_INT), },
1182 1183
1183 { .compatible = "exar,xra1202", .data = OF_953X( 8, 0), },1184 { .compatible = "exar,xra1202", .data = OF_953X( 8, 0), },
drivers/gpio/gpio-vf610.c+36−49
@@ -29,6 +29,7 @@ struct fsl_gpio_soc_data { · 28 unmodified lines
29 29
30struct vf610_gpio_port {30struct vf610_gpio_port {
31 struct gpio_chip gc;31 struct gpio_chip gc;
32 struct irq_chip ic;
32 void __iomem *base;33 void __iomem *base;
33 void __iomem *gpio_base;34 void __iomem *gpio_base;
34 const struct fsl_gpio_soc_data *sdata;35 const struct fsl_gpio_soc_data *sdata;
@@ -60,8 +61,6 @@ struct vf610_gpio_port { · 25 unmodified lines
60#define PORT_INT_EITHER_EDGE 0xb61#define PORT_INT_EITHER_EDGE 0xb
61#define PORT_INT_LOGIC_ONE 0xc62#define PORT_INT_LOGIC_ONE 0xc
62 63
63static struct irq_chip vf610_gpio_irq_chip;
64
65static const struct fsl_gpio_soc_data imx_data = {64static const struct fsl_gpio_soc_data imx_data = {
66 .have_paddr = true,65 .have_paddr = true,
67};66};
@@ -86,28 +85,24 @@ static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio) · 18 unmodified lines
86{85{
87 struct vf610_gpio_port *port = gpiochip_get_data(gc);86 struct vf610_gpio_port *port = gpiochip_get_data(gc);
88 unsigned long mask = BIT(gpio);87 unsigned long mask = BIT(gpio);
89 void __iomem *addr;88 unsigned long offset = GPIO_PDIR;
90 89
91 if (port->sdata && port->sdata->have_paddr) {90 if (port->sdata && port->sdata->have_paddr) {
92 mask &= vf610_gpio_readl(port->gpio_base + GPIO_PDDR);91 mask &= vf610_gpio_readl(port->gpio_base + GPIO_PDDR);
93 addr = mask ? port->gpio_base + GPIO_PDOR :92 if (mask)
94 port->gpio_base + GPIO_PDIR;93 offset = GPIO_PDOR;
95 return !!(vf610_gpio_readl(addr) & BIT(gpio));
96 } else {
97 return !!(vf610_gpio_readl(port->gpio_base + GPIO_PDIR)
98 & BIT(gpio));
99 }94 }
95
96 return !!(vf610_gpio_readl(port->gpio_base + offset) & BIT(gpio));
100}97}
101 98
102static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)99static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
103{100{
104 struct vf610_gpio_port *port = gpiochip_get_data(gc);101 struct vf610_gpio_port *port = gpiochip_get_data(gc);
105 unsigned long mask = BIT(gpio);102 unsigned long mask = BIT(gpio);
103 unsigned long offset = val ? GPIO_PSOR : GPIO_PCOR;
106 104
107 if (val)105 vf610_gpio_writel(mask, port->gpio_base + offset);
108 vf610_gpio_writel(mask, port->gpio_base + GPIO_PSOR);
109 else
110 vf610_gpio_writel(mask, port->gpio_base + GPIO_PCOR);
111}106}
112 107
113static int vf610_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)108static int vf610_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
@@ -237,14 +232,10 @@ static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable) · 123 unmodified lines
237 return 0;232 return 0;
238}233}
239 234
240static struct irq_chip vf610_gpio_irq_chip = {235static void vf610_gpio_disable_clk(void *data)
241 .name = "gpio-vf610",236{
242 .irq_ack = vf610_gpio_irq_ack,237 clk_disable_unprepare(data);
243 .irq_mask = vf610_gpio_irq_mask,238}
244 .irq_unmask = vf610_gpio_irq_unmask,
245 .irq_set_type = vf610_gpio_irq_set_type,
246 .irq_set_wake = vf610_gpio_irq_set_wake,
247};
248 239
249static int vf610_gpio_probe(struct platform_device *pdev)240static int vf610_gpio_probe(struct platform_device *pdev)
250{241{
@@ -252,10 +243,11 @@ static int vf610_gpio_probe(struct platform_device *pdev) · 1 unmodified line
252 struct device_node *np = dev->of_node;243 struct device_node *np = dev->of_node;
253 struct vf610_gpio_port *port;244 struct vf610_gpio_port *port;
254 struct gpio_chip *gc;245 struct gpio_chip *gc;
246 struct irq_chip *ic;
255 int i;247 int i;
256 int ret;248 int ret;
257 249
258 port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL);250 port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
259 if (!port)251 if (!port)
260 return -ENOMEM;252 return -ENOMEM;
261 253
@@ -272,11 +264,15 @@ static int vf610_gpio_probe(struct platform_device *pdev) · 10 unmodified lines
272 if (port->irq < 0)264 if (port->irq < 0)
273 return port->irq;265 return port->irq;
274 266
275 port->clk_port = devm_clk_get(&pdev->dev, "port");267 port->clk_port = devm_clk_get(dev, "port");
276 if (!IS_ERR(port->clk_port)) {268 if (!IS_ERR(port->clk_port)) {
277 ret = clk_prepare_enable(port->clk_port);269 ret = clk_prepare_enable(port->clk_port);
278 if (ret)270 if (ret)
279 return ret;271 return ret;
272 ret = devm_add_action_or_reset(dev, vf610_gpio_disable_clk,
273 port->clk_port);
274 if (ret)
275 return ret;
280 } else if (port->clk_port == ERR_PTR(-EPROBE_DEFER)) {276 } else if (port->clk_port == ERR_PTR(-EPROBE_DEFER)) {
281 /*277 /*
282 * Percolate deferrals, for anything else,278 * Percolate deferrals, for anything else,
@@ -285,20 +281,19 @@ static int vf610_gpio_probe(struct platform_device *pdev) · 2 unmodified lines
285 return PTR_ERR(port->clk_port);281 return PTR_ERR(port->clk_port);
286 }282 }
287 283
288 port->clk_gpio = devm_clk_get(&pdev->dev, "gpio");284 port->clk_gpio = devm_clk_get(dev, "gpio");
289 if (!IS_ERR(port->clk_gpio)) {285 if (!IS_ERR(port->clk_gpio)) {
290 ret = clk_prepare_enable(port->clk_gpio);286 ret = clk_prepare_enable(port->clk_gpio);
291 if (ret) {287 if (ret)
292 clk_disable_unprepare(port->clk_port);288 return ret;
289 ret = devm_add_action_or_reset(dev, vf610_gpio_disable_clk,
290 port->clk_gpio);
291 if (ret)
293 return ret;292 return ret;
294 }
295 } else if (port->clk_gpio == ERR_PTR(-EPROBE_DEFER)) {293 } else if (port->clk_gpio == ERR_PTR(-EPROBE_DEFER)) {
296 clk_disable_unprepare(port->clk_port);
297 return PTR_ERR(port->clk_gpio);294 return PTR_ERR(port->clk_gpio);
298 }295 }
299 296
300 platform_set_drvdata(pdev, port);
301
302 gc = &port->gc;297 gc = &port->gc;
303 gc->of_node = np;298 gc->of_node = np;
304 gc->parent = dev;299 gc->parent = dev;
@@ -313,7 +308,15 @@ static int vf610_gpio_probe(struct platform_device *pdev) · 8 unmodified lines
313 gc->direction_output = vf610_gpio_direction_output;308 gc->direction_output = vf610_gpio_direction_output;
314 gc->set = vf610_gpio_set;309 gc->set = vf610_gpio_set;
315 310
316 ret = gpiochip_add_data(gc, port);311 ic = &port->ic;
312 ic->name = "gpio-vf610";
313 ic->irq_ack = vf610_gpio_irq_ack;
314 ic->irq_mask = vf610_gpio_irq_mask;
315 ic->irq_unmask = vf610_gpio_irq_unmask;
316 ic->irq_set_type = vf610_gpio_irq_set_type;
317 ic->irq_set_wake = vf610_gpio_irq_set_wake;
318
319 ret = devm_gpiochip_add_data(dev, gc, port);
317 if (ret < 0)320 if (ret < 0)
318 return ret;321 return ret;
319 322
@@ -324,39 +327,23 @@ static int vf610_gpio_probe(struct platform_device *pdev) · 4 unmodified lines
324 /* Clear the interrupt status register for all GPIO's */327 /* Clear the interrupt status register for all GPIO's */
325 vf610_gpio_writel(~0, port->base + PORT_ISFR);328 vf610_gpio_writel(~0, port->base + PORT_ISFR);
326 329
327 ret = gpiochip_irqchip_add(gc, &vf610_gpio_irq_chip, 0,330 ret = gpiochip_irqchip_add(gc, ic, 0, handle_edge_irq, IRQ_TYPE_NONE);
328 handle_edge_irq, IRQ_TYPE_NONE);
329 if (ret) {331 if (ret) {
330 dev_err(dev, "failed to add irqchip\n");332 dev_err(dev, "failed to add irqchip\n");
331 gpiochip_remove(gc);
332 return ret;333 return ret;
333 }334 }
334 gpiochip_set_chained_irqchip(gc, &vf610_gpio_irq_chip, port->irq,335 gpiochip_set_chained_irqchip(gc, ic, port->irq,
335 vf610_gpio_irq_handler);336 vf610_gpio_irq_handler);
336 337
337 return 0;338 return 0;
338}339}
339 340
340static int vf610_gpio_remove(struct platform_device *pdev)
341{
342 struct vf610_gpio_port *port = platform_get_drvdata(pdev);
343
344 gpiochip_remove(&port->gc);
345 if (!IS_ERR(port->clk_port))
346 clk_disable_unprepare(port->clk_port);
347 if (!IS_ERR(port->clk_gpio))
348 clk_disable_unprepare(port->clk_gpio);
349
350 return 0;
351}
352
353static struct platform_driver vf610_gpio_driver = {341static struct platform_driver vf610_gpio_driver = {
354 .driver = {342 .driver = {
355 .name = "gpio-vf610",343 .name = "gpio-vf610",
356 .of_match_table = vf610_gpio_dt_ids,344 .of_match_table = vf610_gpio_dt_ids,
357 },345 },
358 .probe = vf610_gpio_probe,346 .probe = vf610_gpio_probe,
359 .remove = vf610_gpio_remove,
360};347};
361 348
362builtin_platform_driver(vf610_gpio_driver);349builtin_platform_driver(vf610_gpio_driver);
drivers/gpio/gpiolib-acpi.c+25−20
@@ -24,13 +24,13 @@ · 23 unmodified lines
24 *24 *
25 * @node: list-entry of the events list of the struct acpi_gpio_chip25 * @node: list-entry of the events list of the struct acpi_gpio_chip
26 * @handle: handle of ACPI method to execute when the IRQ triggers26 * @handle: handle of ACPI method to execute when the IRQ triggers
27 * @handler: irq_handler to pass to request_irq when requesting the IRQ27 * @handler: handler function to pass to request_irq() when requesting the IRQ
28 * @pin: GPIO pin number on the gpio_chip28 * @pin: GPIO pin number on the struct gpio_chip
29 * @irq: Linux IRQ number for the event, for request_ / free_irq29 * @irq: Linux IRQ number for the event, for request_irq() / free_irq()
30 * @irqflags: flags to pass to request_irq when requesting the IRQ30 * @irqflags: flags to pass to request_irq() when requesting the IRQ
31 * @irq_is_wake: If the ACPI flags indicate the IRQ is a wakeup source31 * @irq_is_wake: If the ACPI flags indicate the IRQ is a wakeup source
32 * @irq_requested:True if request_irq has been done32 * @irq_requested:True if request_irq() has been done
33 * @desc: gpio_desc for the GPIO pin for this event33 * @desc: struct gpio_desc for the GPIO pin for this event
34 */34 */
35struct acpi_gpio_event {35struct acpi_gpio_event {
36 struct list_head node;36 struct list_head node;
@@ -65,10 +65,10 @@ struct acpi_gpio_chip { · 28 unmodified lines
65};65};
66 66
67/*67/*
68 * For gpiochips which call acpi_gpiochip_request_interrupts() before late_init68 * For GPIO chips which call acpi_gpiochip_request_interrupts() before late_init
69 * (so builtin drivers) we register the ACPI GpioInt IRQ handlers from a69 * (so builtin drivers) we register the ACPI GpioInt IRQ handlers from a
70 * late_initcall_sync handler, so that other builtin drivers can register their70 * late_initcall_sync() handler, so that other builtin drivers can register their
71 * OpRegions before the event handlers can run. This list contains gpiochips71 * OpRegions before the event handlers can run. This list contains GPIO chips
72 * for which the acpi_gpiochip_request_irqs() call has been deferred.72 * for which the acpi_gpiochip_request_irqs() call has been deferred.
73 */73 */
74static DEFINE_MUTEX(acpi_gpio_deferred_req_irqs_lock);74static DEFINE_MUTEX(acpi_gpio_deferred_req_irqs_lock);
@@ -90,7 +90,7 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data) · 15 unmodified lines
90 *90 *
91 * Return: GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR91 * Return: GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR
92 * error value. Specifically returns %-EPROBE_DEFER if the referenced GPIO92 * error value. Specifically returns %-EPROBE_DEFER if the referenced GPIO
93 * controller does not have gpiochip registered at the moment. This is to93 * controller does not have GPIO chip registered at the moment. This is to
94 * support probe deferral.94 * support probe deferral.
95 */95 */
96static struct gpio_desc *acpi_get_gpiod(char *path, int pin)96static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
@@ -287,9 +287,9 @@ fail_free_desc: · 190 unmodified lines
287 *287 *
288 * ACPI5 platforms can use GPIO signaled ACPI events. These GPIO interrupts are288 * ACPI5 platforms can use GPIO signaled ACPI events. These GPIO interrupts are
289 * handled by ACPI event methods which need to be called from the GPIO289 * handled by ACPI event methods which need to be called from the GPIO
290 * chip's interrupt handler. acpi_gpiochip_request_interrupts finds out which290 * chip's interrupt handler. acpi_gpiochip_request_interrupts() finds out which
291 * gpio pins have acpi event methods and assigns interrupt handlers that calls291 * GPIO pins have ACPI event methods and assigns interrupt handlers that calls
292 * the acpi event methods for those pins.292 * the ACPI event methods for those pins.
293 */293 */
294void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)294void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
295{295{
@@ -653,7 +653,7 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode, · 357 unmodified lines
653 * that case @index is used to select the GPIO entry in the property value653 * that case @index is used to select the GPIO entry in the property value
654 * (in case of multiple).654 * (in case of multiple).
655 *655 *
656 * If the GPIO cannot be translated or there is an error an ERR_PTR is656 * If the GPIO cannot be translated or there is an error, an ERR_PTR is
657 * returned.657 * returned.
658 *658 *
659 * Note: if the GPIO resource has multiple entries in the pin list, this659 * Note: if the GPIO resource has multiple entries in the pin list, this
@@ -751,10 +751,13 @@ struct gpio_desc *acpi_find_gpio(struct device *dev, · 91 unmodified lines
751 * @index: index of GpioIo/GpioInt resource (starting from %0)751 * @index: index of GpioIo/GpioInt resource (starting from %0)
752 * @info: info pointer to fill in (optional)752 * @info: info pointer to fill in (optional)
753 *753 *
754 * If @fwnode is an ACPI device object, call %acpi_get_gpiod_by_index() for it.754 * If @fwnode is an ACPI device object, call acpi_get_gpiod_by_index() for it.
755 * Otherwise (ie. it is a data-only non-device object), use the property-based755 * Otherwise (i.e. it is a data-only non-device object), use the property-based
756 * GPIO lookup to get to the GPIO resource with the relevant information and use756 * GPIO lookup to get to the GPIO resource with the relevant information and use
757 * that to obtain the GPIO descriptor to return.757 * that to obtain the GPIO descriptor to return.
758 *
759 * If the GPIO cannot be translated or there is an error an ERR_PTR is
760 * returned.
758 */761 */
759struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,762struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
760 const char *propname, int index,763 const char *propname, int index,
@@ -1158,11 +1161,13 @@ static int acpi_find_gpio_count(struct acpi_resource *ares, void *data) · 397 unmodified lines
1158}1161}
1159 1162
1160/**1163/**
1161 * acpi_gpio_count - return the number of GPIOs associated with a1164 * acpi_gpio_count - count the GPIOs associated with a device / function
1162 * device / function or -ENOENT if no GPIO has been1165 * @dev: GPIO consumer, can be %NULL for system-global GPIOs
1163 * assigned to the requested function.
1164 * @dev: GPIO consumer, can be NULL for system-global GPIOs
1165 * @con_id: function within the GPIO consumer1166 * @con_id: function within the GPIO consumer
1167 *
1168 * Return:
1169 * The number of GPIOs associated with a device / function or %-ENOENT,
1170 * if no GPIO has been assigned to the requested function.
1166 */1171 */
1167int acpi_gpio_count(struct device *dev, const char *con_id)1172int acpi_gpio_count(struct device *dev, const char *con_id)
1168{1173{
drivers/gpio/gpiolib.c+2−1
@@ -4626,7 +4626,8 @@ EXPORT_SYMBOL_GPL(gpiod_get_array_optional); · 4625 unmodified lines
4626 */4626 */
4627void gpiod_put(struct gpio_desc *desc)4627void gpiod_put(struct gpio_desc *desc)
4628{4628{
4629 gpiod_free(desc);4629 if (desc)
4630 gpiod_free(desc);
4630}4631}
4631EXPORT_SYMBOL_GPL(gpiod_put);4632EXPORT_SYMBOL_GPL(gpiod_put);
4632 4633

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t