Commit 8148c17b authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'gpio-v5.2-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 the GPIO changes for the v5.2 kernel cycle. A bit
  later than usual because I was ironing out my own mistakes. I'm
  holding some stuff back for the next kernel as a result, and this
  should be a healthy and well tested batch.

  Core changes:

   - The gpiolib MMIO driver has been enhanced to handle two direction
     registers, i.e. one register to set lines as input and one register
     to set lines as output. It turns out some silicon engineer thinks
     the ability to configure a line as input and output at the same
     time makes sense, this can be debated but includes a lot of analog
     electronics reasoning, and the registers are there and need to be
     handled consistently. Unsurprisingly, we enforce the lines to be
     either inputs or outputs in such schemes.

   - Send in the proper argument value to .set_config() dispatched to
     the pin control subsystem. Nobody used it before, now someone does,
     so fix it to work as expected.

   - The ACPI gpiolib portions can now handle pin bias setting (pull up
     or pull down). This has been in the ACPI spec for years and we
     finally have it properly integrated with Linux GPIOs. It was based
     on an observation from Andy Schevchenko that Thomas Petazzoni's
     changes to the core for biasing the PCA950x GPIO expander actually
     happen to fit hand-in-glove with what the ACPI core needed. Such
     nice synergies happen sometimes.

  New drivers:

   - A new driver for the Mellanox BlueField GPIO controller. This is
     using 64bit MMIO registers and can configure lines as inputs and
     outputs at the same time and after improving the MMIO library we
     handle it just fine. Interesting.

   - A new IXP4xx proper gpiochip driver with hierarchical interrupts
     should be coming in from the ARM SoC tree as well.

  Driver enhancements:

   - The PCA053x driver handles the CAT9554 GPIO expander.

   - The PCA053x driver handles the NXP PCAL6416 GPIO expander.

   - Wake-up support on PCA053x GPIO lines.

   - OMAP now does a nice asynchronous IRQ handling on wake-ups by
     letting everything wake up on edges, and this makes runtime PM work
     as expected too.

  Misc:

   - Several cleanups such as devres fixes.

   - Get rid of some languager comstructs that cause problems when
     compiling with LLVMs clang.

   - Documentation review and update"

* tag 'gpio-v5.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (85 commits)
  gpio: Update documentation
  docs: gpio: convert docs to ReST and rename to *.rst
  gpio: sch: Remove write-only core_base
  gpio: pxa: Make two symbols static
  gpiolib: acpi: Respect pin bias setting
  gpiolib: acpi: Add acpi_gpio_update_gpiod_lookup_flags() helper
  gpiolib: acpi: Set pin value, based on bias, more accurately
  gpiolib: acpi: Change type of dflags
  gpiolib: Introduce GPIO_LOOKUP_FLAGS_DEFAULT
  gpiolib: Make use of enum gpio_lookup_flags consistent
  gpiolib: Indent entry values of enum gpio_lookup_flags
  gpio: pca953x: add support for pca6416
  dt-bindings: gpio: pca953x: document the nxp,pca6416
  gpio: pca953x: add pcal6416 to the of_device_id table
  gpio: gpio-omap: Remove conditional pm_runtime handling for GPIO interrupts
  gpio: gpio-omap: configure edge detection for level IRQs for idle wakeup
  tracing: stop making gpio tracing configurable
  gpio: pca953x: Configure wake-up path when wake-up is enabled
  gpio: of: Optimize quirk checks
  gpio: mmio: Drop bgpio_dir_inverted
  ...
parents 6fe567df 0fbee1df
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
Required properties: Required properties:
- compatible: Has to contain one of the following: - compatible: Has to contain one of the following:
nxp,pca6416
nxp,pca9505 nxp,pca9505
nxp,pca9534 nxp,pca9534
nxp,pca9535 nxp,pca9535
...@@ -30,6 +31,7 @@ Required properties: ...@@ -30,6 +31,7 @@ Required properties:
ti,tca6424 ti,tca6424
ti,tca9539 ti,tca9539
ti,tca9554 ti,tca9554
onnn,cat9554
onnn,pca9654 onnn,pca9654
exar,xra1202 exar,xra1202
- gpio-controller: if used as gpio expander. - gpio-controller: if used as gpio expander.
......
This diff is collapsed.
:orphan:
====
gpio
====
.. toctree::
:maxdepth: 1
sysfs
.. only:: subproject and html
Indices
=======
* :ref:`genindex`
GPIO Sysfs Interface for Userspace GPIO Sysfs Interface for Userspace
================================== ==================================
THIS ABI IS DEPRECATED, THE ABI DOCUMENTATION HAS BEEN MOVED TO .. warning::
Documentation/ABI/obsolete/sysfs-gpio AND NEW USERSPACE CONSUMERS
ARE SUPPOSED TO USE THE CHARACTER DEVICE ABI. THIS OLD SYSFS ABI WILL THIS ABI IS DEPRECATED, THE ABI DOCUMENTATION HAS BEEN MOVED TO
NOT BE DEVELOPED (NO NEW FEATURES), IT WILL JUST BE MAINTAINED. Documentation/ABI/obsolete/sysfs-gpio AND NEW USERSPACE CONSUMERS
ARE SUPPOSED TO USE THE CHARACTER DEVICE ABI. THIS OLD SYSFS ABI WILL
NOT BE DEVELOPED (NO NEW FEATURES), IT WILL JUST BE MAINTAINED.
Refer to the examples in tools/gpio/* for an introduction to the new Refer to the examples in tools/gpio/* for an introduction to the new
character device ABI. Also see the userspace header in character device ABI. Also see the userspace header in
...@@ -51,13 +53,15 @@ The control interfaces are write-only: ...@@ -51,13 +53,15 @@ The control interfaces are write-only:
/sys/class/gpio/ /sys/class/gpio/
"export" ... Userspace may ask the kernel to export control of "export" ...
Userspace may ask the kernel to export control of
a GPIO to userspace by writing its number to this file. a GPIO to userspace by writing its number to this file.
Example: "echo 19 > export" will create a "gpio19" node Example: "echo 19 > export" will create a "gpio19" node
for GPIO #19, if that's not requested by kernel code. for GPIO #19, if that's not requested by kernel code.
"unexport" ... Reverses the effect of exporting to userspace. "unexport" ...
Reverses the effect of exporting to userspace.
Example: "echo 19 > unexport" will remove a "gpio19" Example: "echo 19 > unexport" will remove a "gpio19"
node exported using the "export" file. node exported using the "export" file.
...@@ -67,7 +71,8 @@ and have the following read/write attributes: ...@@ -67,7 +71,8 @@ and have the following read/write attributes:
/sys/class/gpio/gpioN/ /sys/class/gpio/gpioN/
"direction" ... reads as either "in" or "out". This value may "direction" ...
reads as either "in" or "out". This value may
normally be written. Writing as "out" defaults to normally be written. Writing as "out" defaults to
initializing the value as low. To ensure glitch free initializing the value as low. To ensure glitch free
operation, values "low" and "high" may be written to operation, values "low" and "high" may be written to
...@@ -78,7 +83,8 @@ and have the following read/write attributes: ...@@ -78,7 +83,8 @@ and have the following read/write attributes:
it was exported by kernel code that didn't explicitly it was exported by kernel code that didn't explicitly
allow userspace to reconfigure this GPIO's direction. allow userspace to reconfigure this GPIO's direction.
"value" ... reads as either 0 (low) or 1 (high). If the GPIO "value" ...
reads as either 0 (low) or 1 (high). If the GPIO
is configured as an output, this value may be written; is configured as an output, this value may be written;
any nonzero value is treated as high. any nonzero value is treated as high.
...@@ -92,14 +98,16 @@ and have the following read/write attributes: ...@@ -92,14 +98,16 @@ and have the following read/write attributes:
file and read the new value or close the file and re-open it file and read the new value or close the file and re-open it
to read the value. to read the value.
"edge" ... reads as either "none", "rising", "falling", or "edge" ...
reads as either "none", "rising", "falling", or
"both". Write these strings to select the signal edge(s) "both". Write these strings to select the signal edge(s)
that will make poll(2) on the "value" file return. that will make poll(2) on the "value" file return.
This file exists only if the pin can be configured as an This file exists only if the pin can be configured as an
interrupt generating input pin. interrupt generating input pin.
"active_low" ... reads as either 0 (false) or 1 (true). Write "active_low" ...
reads as either 0 (false) or 1 (true). Write
any nonzero value to invert the value attribute both any nonzero value to invert the value attribute both
for reading and writing. Existing and subsequent for reading and writing. Existing and subsequent
poll(2) support configuration via the edge attribute poll(2) support configuration via the edge attribute
...@@ -112,11 +120,14 @@ read-only attributes: ...@@ -112,11 +120,14 @@ read-only attributes:
/sys/class/gpio/gpiochipN/ /sys/class/gpio/gpiochipN/
"base" ... same as N, the first GPIO managed by this chip "base" ...
same as N, the first GPIO managed by this chip
"label" ... provided for diagnostics (not always unique) "label" ...
provided for diagnostics (not always unique)
"ngpio" ... how many GPIOs this manages (N to N + ngpio - 1) "ngpio" ...
how many GPIOs this manages (N to N + ngpio - 1)
Board documentation should in most cases cover what GPIOs are used for Board documentation should in most cases cover what GPIOs are used for
what purposes. However, those numbers are not always stable; GPIOs on what purposes. However, those numbers are not always stable; GPIOs on
...@@ -129,7 +140,7 @@ the correct GPIO number to use for a given signal. ...@@ -129,7 +140,7 @@ the correct GPIO number to use for a given signal.
Exporting from Kernel code Exporting from Kernel code
-------------------------- --------------------------
Kernel code can explicitly manage exports of GPIOs which have already been Kernel code can explicitly manage exports of GPIOs which have already been
requested using gpio_request(): requested using gpio_request()::
/* export the GPIO to userspace */ /* export the GPIO to userspace */
int gpiod_export(struct gpio_desc *desc, bool direction_may_change); int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
......
...@@ -247,7 +247,6 @@ CONFIG_PANIC_TIMEOUT=-1 ...@@ -247,7 +247,6 @@ CONFIG_PANIC_TIMEOUT=-1
# CONFIG_SCHED_DEBUG is not set # CONFIG_SCHED_DEBUG is not set
CONFIG_SCHED_STACK_END_CHECK=y CONFIG_SCHED_STACK_END_CHECK=y
CONFIG_FUNCTION_TRACER=y CONFIG_FUNCTION_TRACER=y
# CONFIG_TRACING_EVENTS_GPIO is not set
# CONFIG_RUNTIME_TESTING_MENU is not set # CONFIG_RUNTIME_TESTING_MENU is not set
CONFIG_DEBUG_WX=y CONFIG_DEBUG_WX=y
CONFIG_DEBUG_USER=y CONFIG_DEBUG_USER=y
......
...@@ -247,7 +247,6 @@ CONFIG_PANIC_TIMEOUT=-1 ...@@ -247,7 +247,6 @@ CONFIG_PANIC_TIMEOUT=-1
# CONFIG_SCHED_DEBUG is not set # CONFIG_SCHED_DEBUG is not set
CONFIG_SCHED_STACK_END_CHECK=y CONFIG_SCHED_STACK_END_CHECK=y
CONFIG_FUNCTION_TRACER=y CONFIG_FUNCTION_TRACER=y
# CONFIG_TRACING_EVENTS_GPIO is not set
# CONFIG_RUNTIME_TESTING_MENU is not set # CONFIG_RUNTIME_TESTING_MENU is not set
CONFIG_DEBUG_WX=y CONFIG_DEBUG_WX=y
CONFIG_DEBUG_USER=y CONFIG_DEBUG_USER=y
......
...@@ -329,20 +329,6 @@ config GPIO_MM_LANTIQ ...@@ -329,20 +329,6 @@ config GPIO_MM_LANTIQ
(EBU) found on Lantiq SoCs. The gpios are output only as they are (EBU) found on Lantiq SoCs. The gpios are output only as they are
created by attaching a 16bit latch to the bus. created by attaching a 16bit latch to the bus.
config GPIO_MOCKUP
tristate "GPIO Testing Driver"
depends on GPIOLIB && SYSFS
select GPIO_SYSFS
select GPIOLIB_IRQCHIP
select IRQ_SIM
help
This enables GPIO Testing driver, which provides a way to test GPIO
subsystem through sysfs(or char device) and debugfs. GPIO_SYSFS
must be selected for this test.
User could use it through the script in
tools/testing/selftests/gpio/gpio-mockup.sh. Reference the usage in
it.
config GPIO_MPC5200 config GPIO_MPC5200
def_bool y def_bool y
depends on PPC_MPC52xx depends on PPC_MPC52xx
...@@ -1315,6 +1301,13 @@ config GPIO_MERRIFIELD ...@@ -1315,6 +1301,13 @@ config GPIO_MERRIFIELD
help help
Say Y here to support Intel Merrifield GPIO. Say Y here to support Intel Merrifield GPIO.
config GPIO_MLXBF
tristate "Mellanox BlueField SoC GPIO"
depends on (MELLANOX_PLATFORM && ARM64 && ACPI) || (64BIT && COMPILE_TEST)
select GPIO_GENERIC
help
Say Y here if you want GPIO support on Mellanox BlueField SoC.
config GPIO_ML_IOH config GPIO_ML_IOH
tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support" tristate "OKI SEMICONDUCTOR ML7213 IOH GPIO support"
depends on X86 || COMPILE_TEST depends on X86 || COMPILE_TEST
...@@ -1441,4 +1434,16 @@ config GPIO_VIPERBOARD ...@@ -1441,4 +1434,16 @@ config GPIO_VIPERBOARD
endmenu endmenu
config GPIO_MOCKUP
tristate "GPIO Testing Driver"
depends on GPIOLIB
select IRQ_SIM
help
This enables GPIO Testing driver, which provides a way to test GPIO
subsystem through sysfs(or char device) and debugfs. GPIO_SYSFS
must be selected for this test.
User could use it through the script in
tools/testing/selftests/gpio/gpio-mockup.sh. Reference the usage in
it.
endif endif
...@@ -85,6 +85,7 @@ obj-$(CONFIG_GPIO_MENZ127) += gpio-menz127.o ...@@ -85,6 +85,7 @@ obj-$(CONFIG_GPIO_MENZ127) += gpio-menz127.o
obj-$(CONFIG_GPIO_MERRIFIELD) += gpio-merrifield.o obj-$(CONFIG_GPIO_MERRIFIELD) += gpio-merrifield.o
obj-$(CONFIG_GPIO_MC33880) += gpio-mc33880.o obj-$(CONFIG_GPIO_MC33880) += gpio-mc33880.o
obj-$(CONFIG_GPIO_MC9S08DZ60) += gpio-mc9s08dz60.o obj-$(CONFIG_GPIO_MC9S08DZ60) += gpio-mc9s08dz60.o
obj-$(CONFIG_GPIO_MLXBF) += gpio-mlxbf.o
obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o
obj-$(CONFIG_GPIO_MM_LANTIQ) += gpio-mm-lantiq.o obj-$(CONFIG_GPIO_MM_LANTIQ) += gpio-mm-lantiq.o
obj-$(CONFIG_GPIO_MOCKUP) += gpio-mockup.o obj-$(CONFIG_GPIO_MOCKUP) += gpio-mockup.o
......
// SPDX-License-Identifier: GPL-2.0-only
/* /*
* 74Hx164 - Generic serial-in/parallel-out 8-bits shift register GPIO driver * 74Hx164 - Generic serial-in/parallel-out 8-bits shift register GPIO driver
* *
* Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org> * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
* Copyright (C) 2010 Miguel Gaio <miguel.gaio@efixo.com> * Copyright (C) 2010 Miguel Gaio <miguel.gaio@efixo.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/ */
#include <linux/init.h>
#include <linux/mutex.h>
#include <linux/spi/spi.h>
#include <linux/gpio/driver.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
#include <linux/slab.h> #include <linux/gpio/driver.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mutex.h>
#include <linux/property.h>
#include <linux/slab.h>
#include <linux/spi/spi.h>
#define GEN_74X164_NUMBER_GPIOS 8 #define GEN_74X164_NUMBER_GPIOS 8
...@@ -116,10 +113,9 @@ static int gen_74x164_probe(struct spi_device *spi) ...@@ -116,10 +113,9 @@ static int gen_74x164_probe(struct spi_device *spi)
if (ret < 0) if (ret < 0)
return ret; return ret;
if (of_property_read_u32(spi->dev.of_node, "registers-number", ret = device_property_read_u32(&spi->dev, "registers-number", &nregs);
&nregs)) { if (ret) {
dev_err(&spi->dev, dev_err(&spi->dev, "Missing 'registers-number' property.\n");
"Missing registers-number property in the DT.\n");
return -EINVAL; return -EINVAL;
} }
......
...@@ -106,7 +106,6 @@ static int mmio_74xx_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) ...@@ -106,7 +106,6 @@ static int mmio_74xx_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
static int mmio_74xx_gpio_probe(struct platform_device *pdev) static int mmio_74xx_gpio_probe(struct platform_device *pdev)
{ {
struct mmio_74xx_gpio_priv *priv; struct mmio_74xx_gpio_priv *priv;
struct resource *res;
void __iomem *dat; void __iomem *dat;
int err; int err;
...@@ -116,8 +115,7 @@ static int mmio_74xx_gpio_probe(struct platform_device *pdev) ...@@ -116,8 +115,7 @@ static int mmio_74xx_gpio_probe(struct platform_device *pdev)
priv->flags = (uintptr_t)of_device_get_match_data(&pdev->dev); priv->flags = (uintptr_t)of_device_get_match_data(&pdev->dev);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); dat = devm_platform_ioremap_resource(pdev, 0);
dat = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(dat)) if (IS_ERR(dat))
return PTR_ERR(dat); return PTR_ERR(dat);
......
...@@ -78,7 +78,6 @@ static int pt_gpio_probe(struct platform_device *pdev) ...@@ -78,7 +78,6 @@ static int pt_gpio_probe(struct platform_device *pdev)
struct acpi_device *acpi_dev; struct acpi_device *acpi_dev;
acpi_handle handle = ACPI_HANDLE(dev); acpi_handle handle = ACPI_HANDLE(dev);
struct pt_gpio_chip *pt_gpio; struct pt_gpio_chip *pt_gpio;
struct resource *res_mem;
int ret = 0; int ret = 0;
if (acpi_bus_get_device(handle, &acpi_dev)) { if (acpi_bus_get_device(handle, &acpi_dev)) {
...@@ -90,12 +89,7 @@ static int pt_gpio_probe(struct platform_device *pdev) ...@@ -90,12 +89,7 @@ static int pt_gpio_probe(struct platform_device *pdev)
if (!pt_gpio) if (!pt_gpio)
return -ENOMEM; return -ENOMEM;
res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); pt_gpio->reg_base = devm_platform_ioremap_resource(pdev, 0);
if (!res_mem) {
dev_err(&pdev->dev, "Failed to get MMIO resource for PT GPIO.\n");
return -EINVAL;
}
pt_gpio->reg_base = devm_ioremap_resource(dev, res_mem);
if (IS_ERR(pt_gpio->reg_base)) { if (IS_ERR(pt_gpio->reg_base)) {
dev_err(&pdev->dev, "Failed to map MMIO resource for PT GPIO.\n"); dev_err(&pdev->dev, "Failed to map MMIO resource for PT GPIO.\n");
return PTR_ERR(pt_gpio->reg_base); return PTR_ERR(pt_gpio->reg_base);
......
...@@ -1156,15 +1156,13 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev) ...@@ -1156,15 +1156,13 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev)
{ {
const struct of_device_id *gpio_id; const struct of_device_id *gpio_id;
struct aspeed_gpio *gpio; struct aspeed_gpio *gpio;
struct resource *res;
int rc, i, banks; int rc, i, banks;
gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
if (!gpio) if (!gpio)
return -ENOMEM; return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); gpio->base = devm_platform_ioremap_resource(pdev, 0);
gpio->base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(gpio->base)) if (IS_ERR(gpio->base))
return PTR_ERR(gpio->base); return PTR_ERR(gpio->base);
......
...@@ -568,7 +568,6 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev) ...@@ -568,7 +568,6 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
const struct of_device_id *match; const struct of_device_id *match;
struct resource *res;
struct bcm_kona_gpio_bank *bank; struct bcm_kona_gpio_bank *bank;
struct bcm_kona_gpio *kona_gpio; struct bcm_kona_gpio *kona_gpio;
struct gpio_chip *chip; struct gpio_chip *chip;
...@@ -618,8 +617,7 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev) ...@@ -618,8 +617,7 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev)
return -ENXIO; return -ENXIO;
} }
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); kona_gpio->reg_base = devm_platform_ioremap_resource(pdev, 0);
kona_gpio->reg_base = devm_ioremap_resource(dev, res);
if (IS_ERR(kona_gpio->reg_base)) { if (IS_ERR(kona_gpio->reg_base)) {
ret = -ENXIO; ret = -ENXIO;
goto err_irq_domain; goto err_irq_domain;
......
...@@ -148,7 +148,6 @@ static struct irq_chip cdns_gpio_irqchip = { ...@@ -148,7 +148,6 @@ static struct irq_chip cdns_gpio_irqchip = {
static int cdns_gpio_probe(struct platform_device *pdev) static int cdns_gpio_probe(struct platform_device *pdev)
{ {
struct cdns_gpio_chip *cgpio; struct cdns_gpio_chip *cgpio;
struct resource *res;
int ret, irq; int ret, irq;
u32 dir_prev; u32 dir_prev;
u32 num_gpios = 32; u32 num_gpios = 32;
...@@ -157,8 +156,7 @@ static int cdns_gpio_probe(struct platform_device *pdev) ...@@ -157,8 +156,7 @@ static int cdns_gpio_probe(struct platform_device *pdev)
if (!cgpio) if (!cgpio)
return -ENOMEM; return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); cgpio->regs = devm_platform_ioremap_resource(pdev, 0);
cgpio->regs = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(cgpio->regs)) if (IS_ERR(cgpio->regs))
return PTR_ERR(cgpio->regs); return PTR_ERR(cgpio->regs);
......
...@@ -19,7 +19,6 @@ static int clps711x_gpio_probe(struct platform_device *pdev) ...@@ -19,7 +19,6 @@ static int clps711x_gpio_probe(struct platform_device *pdev)
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
void __iomem *dat, *dir; void __iomem *dat, *dir;
struct gpio_chip *gc; struct gpio_chip *gc;
struct resource *res;
int err, id; int err, id;
if (!np) if (!np)
...@@ -33,13 +32,11 @@ static int clps711x_gpio_probe(struct platform_device *pdev) ...@@ -33,13 +32,11 @@ static int clps711x_gpio_probe(struct platform_device *pdev)
if (!gc) if (!gc)
return -ENOMEM; return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); dat = devm_platform_ioremap_resource(pdev, 0);
dat = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(dat)) if (IS_ERR(dat))
return PTR_ERR(dat); return PTR_ERR(dat);
res = platform_get_resource(pdev, IORESOURCE_MEM, 1); dir = devm_platform_ioremap_resource(pdev, 1);
dir = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(dir)) if (IS_ERR(dir))
return PTR_ERR(dir); return PTR_ERR(dir);
......
...@@ -655,7 +655,6 @@ MODULE_DEVICE_TABLE(acpi, dwapb_acpi_match); ...@@ -655,7 +655,6 @@ MODULE_DEVICE_TABLE(acpi, dwapb_acpi_match);
static int dwapb_gpio_probe(struct platform_device *pdev) static int dwapb_gpio_probe(struct platform_device *pdev)
{ {
unsigned int i; unsigned int i;
struct resource *res;
struct dwapb_gpio *gpio; struct dwapb_gpio *gpio;
int err; int err;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
...@@ -688,8 +687,7 @@ static int dwapb_gpio_probe(struct platform_device *pdev) ...@@ -688,8 +687,7 @@ static int dwapb_gpio_probe(struct platform_device *pdev)
if (!gpio->ports) if (!gpio->ports)
return -ENOMEM; return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); gpio->regs = devm_platform_ioremap_resource(pdev, 0);
gpio->regs = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(gpio->regs)) if (IS_ERR(gpio->regs))
return PTR_ERR(gpio->regs); return PTR_ERR(gpio->regs);
......
...@@ -225,7 +225,6 @@ static int ftgpio_gpio_set_config(struct gpio_chip *gc, unsigned int offset, ...@@ -225,7 +225,6 @@ static int ftgpio_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
static int ftgpio_gpio_probe(struct platform_device *pdev) static int ftgpio_gpio_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct resource *res;
struct ftgpio_gpio *g; struct ftgpio_gpio *g;
int irq; int irq;
int ret; int ret;
...@@ -236,8 +235,7 @@ static int ftgpio_gpio_probe(struct platform_device *pdev) ...@@ -236,8 +235,7 @@ static int ftgpio_gpio_probe(struct platform_device *pdev)
g->dev = dev; g->dev = dev;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); g->base = devm_platform_ioremap_resource(pdev, 0);
g->base = devm_ioremap_resource(dev, res);
if (IS_ERR(g->base)) if (IS_ERR(g->base))
return PTR_ERR(g->base); return PTR_ERR(g->base);
......
...@@ -208,7 +208,6 @@ static int hlwd_gpio_irq_set_type(struct irq_data *data, unsigned int flow_type) ...@@ -208,7 +208,6 @@ static int hlwd_gpio_irq_set_type(struct irq_data *data, unsigned int flow_type)
static int hlwd_gpio_probe(struct platform_device *pdev) static int hlwd_gpio_probe(struct platform_device *pdev)
{ {
struct hlwd_gpio *hlwd; struct hlwd_gpio *hlwd;
struct resource *regs_resource;
u32 ngpios; u32 ngpios;
int res; int res;
...@@ -216,8 +215,7 @@ static int hlwd_gpio_probe(struct platform_device *pdev) ...@@ -216,8 +215,7 @@ static int hlwd_gpio_probe(struct platform_device *pdev)
if (!hlwd) if (!hlwd)
return -ENOMEM; return -ENOMEM;
regs_resource = platform_get_resource(pdev, IORESOURCE_MEM, 0); hlwd->regs = devm_platform_ioremap_resource(pdev, 0);
hlwd->regs = devm_ioremap_resource(&pdev->dev, regs_resource);
if (IS_ERR(hlwd->regs)) if (IS_ERR(hlwd->regs))
return PTR_ERR(hlwd->regs); return PTR_ERR(hlwd->regs);
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
static int iop3xx_gpio_probe(struct platform_device *pdev) static int iop3xx_gpio_probe(struct platform_device *pdev)
{ {
struct resource *res;
struct gpio_chip *gc; struct gpio_chip *gc;
void __iomem *base; void __iomem *base;
int err; int err;
...@@ -30,8 +29,7 @@ static int iop3xx_gpio_probe(struct platform_device *pdev) ...@@ -30,8 +29,7 @@ static int iop3xx_gpio_probe(struct platform_device *pdev)
if (!gc) if (!gc)
return -ENOMEM; return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); base = devm_platform_ioremap_resource(pdev, 0);
base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(base)) if (IS_ERR(base))
return PTR_ERR(base); return PTR_ERR(base);
......
...@@ -147,7 +147,6 @@ static int ttl_probe(struct platform_device *pdev) ...@@ -147,7 +147,6 @@ static int ttl_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct ttl_module *mod; struct ttl_module *mod;
struct gpio_chip *gpio; struct gpio_chip *gpio;
struct resource *res;
int ret; int ret;
pdata = dev_get_platdata(&pdev->dev); pdata = dev_get_platdata(&pdev->dev);
...@@ -164,8 +163,7 @@ static int ttl_probe(struct platform_device *pdev) ...@@ -164,8 +163,7 @@ static int ttl_probe(struct platform_device *pdev)
spin_lock_init(&mod->lock); spin_lock_init(&mod->lock);
/* get access to the MODULbus registers for this module */ /* get access to the MODULbus registers for this module */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); mod->regs = devm_platform_ioremap_resource(pdev, 0);
mod->regs = devm_ioremap_resource(dev, res);
if (IS_ERR(mod->regs)) if (IS_ERR(mod->regs))
return PTR_ERR(mod->regs); return PTR_ERR(mod->regs);
......
...@@ -47,15 +47,13 @@ static int ls1x_gpio_probe(struct platform_device *pdev) ...@@ -47,15 +47,13 @@ static int ls1x_gpio_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct gpio_chip *gc; struct gpio_chip *gc;
struct resource *res;
int ret; int ret;
gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL);
if (!gc) if (!gc)
return -ENOMEM; return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); gpio_reg_base = devm_platform_ioremap_resource(pdev, 0);
gpio_reg_base = devm_ioremap_resource(dev, res);
if (IS_ERR(gpio_reg_base)) if (IS_ERR(gpio_reg_base))
return PTR_ERR(gpio_reg_base); return PTR_ERR(gpio_reg_base);
......
...@@ -340,10 +340,7 @@ static int lpc18xx_gpio_probe(struct platform_device *pdev) ...@@ -340,10 +340,7 @@ static int lpc18xx_gpio_probe(struct platform_device *pdev)
index = of_property_match_string(dev->of_node, "reg-names", "gpio"); index = of_property_match_string(dev->of_node, "reg-names", "gpio");
if (index < 0) { if (index < 0) {
/* To support backward compatibility take the first resource */ /* To support backward compatibility take the first resource */
struct resource *res; gc->base = devm_platform_ioremap_resource(pdev, 0);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
gc->base = devm_ioremap_resource(dev, res);
} else { } else {
struct resource res; struct resource res;
......
...@@ -146,7 +146,6 @@ static void mb86s70_gpio_set(struct gpio_chip *gc, unsigned gpio, int value) ...@@ -146,7 +146,6 @@ static void mb86s70_gpio_set(struct gpio_chip *gc, unsigned gpio, int value)
static int mb86s70_gpio_probe(struct platform_device *pdev) static int mb86s70_gpio_probe(struct platform_device *pdev)
{ {
struct mb86s70_gpio_chip *gchip; struct mb86s70_gpio_chip *gchip;
struct resource *res;
int ret; int ret;
gchip = devm_kzalloc(&pdev->dev, sizeof(*gchip), GFP_KERNEL); gchip = devm_kzalloc(&pdev->dev, sizeof(*gchip), GFP_KERNEL);
...@@ -155,8 +154,7 @@ static int mb86s70_gpio_probe(struct platform_device *pdev) ...@@ -155,8 +154,7 @@ static int mb86s70_gpio_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, gchip); platform_set_drvdata(pdev, gchip);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); gchip->base = devm_platform_ioremap_resource(pdev, 0);
gchip->base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(gchip->base)) if (IS_ERR(gchip->base))
return PTR_ERR(gchip->base); return PTR_ERR(gchip->base);
......
// SPDX-License-Identifier: GPL-2.0
#include <linux/acpi.h>
#include <linux/bitops.h>
#include <linux/device.h>
#include <linux/gpio/driver.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/resource.h>
#include <linux/types.h>
/* Number of pins on BlueField */
#define MLXBF_GPIO_NR 54
/* Pad Electrical Controls. */
#define MLXBF_GPIO_PAD_CONTROL_FIRST_WORD 0x0700
#define MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD 0x0708
#define MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD 0x0710
#define MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD 0x0718
#define MLXBF_GPIO_PIN_DIR_I 0x1040
#define MLXBF_GPIO_PIN_DIR_O 0x1048
#define MLXBF_GPIO_PIN_STATE 0x1000
#define MLXBF_GPIO_SCRATCHPAD 0x20
#ifdef CONFIG_PM
struct mlxbf_gpio_context_save_regs {
u64 scratchpad;
u64 pad_control[MLXBF_GPIO_NR];
u64 pin_dir_i;
u64 pin_dir_o;
};
#endif
/* Device state structure. */
struct mlxbf_gpio_state {
struct gpio_chip gc;
/* Memory Address */
void __iomem *base;
#ifdef CONFIG_PM
struct mlxbf_gpio_context_save_regs csave_regs;
#endif
};
static int mlxbf_gpio_probe(struct platform_device *pdev)
{
struct mlxbf_gpio_state *gs;
struct device *dev = &pdev->dev;
struct gpio_chip *gc;
int ret;
gs = devm_kzalloc(&pdev->dev, sizeof(*gs), GFP_KERNEL);
if (!gs)
return -ENOMEM;
gs->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(gs->base))
return PTR_ERR(gs->base);
gc = &gs->gc;
ret = bgpio_init(gc, dev, 8,
gs->base + MLXBF_GPIO_PIN_STATE,
NULL,
NULL,
gs->base + MLXBF_GPIO_PIN_DIR_O,
gs->base + MLXBF_GPIO_PIN_DIR_I,
0);
if (ret)
return -ENODEV;
gc->owner = THIS_MODULE;
gc->ngpio = MLXBF_GPIO_NR;
ret = devm_gpiochip_add_data(dev, &gs->gc, gs);
if (ret) {
dev_err(&pdev->dev, "Failed adding memory mapped gpiochip\n");
return ret;
}
platform_set_drvdata(pdev, gs);
dev_info(&pdev->dev, "registered Mellanox BlueField GPIO");
return 0;
}
#ifdef CONFIG_PM
static int mlxbf_gpio_suspend(struct platform_device *pdev, pm_message_t state)
{
struct mlxbf_gpio_state *gs = platform_get_drvdata(pdev);
gs->csave_regs.scratchpad = readq(gs->base + MLXBF_GPIO_SCRATCHPAD);
gs->csave_regs.pad_control[0] =
readq(gs->base + MLXBF_GPIO_PAD_CONTROL_FIRST_WORD);
gs->csave_regs.pad_control[1] =
readq(gs->base + MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD);
gs->csave_regs.pad_control[2] =
readq(gs->base + MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD);
gs->csave_regs.pad_control[3] =
readq(gs->base + MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD);
gs->csave_regs.pin_dir_i = readq(gs->base + MLXBF_GPIO_PIN_DIR_I);
gs->csave_regs.pin_dir_o = readq(gs->base + MLXBF_GPIO_PIN_DIR_O);
return 0;
}
static int mlxbf_gpio_resume(struct platform_device *pdev)
{
struct mlxbf_gpio_state *gs = platform_get_drvdata(pdev);
writeq(gs->csave_regs.scratchpad, gs->base + MLXBF_GPIO_SCRATCHPAD);
writeq(gs->csave_regs.pad_control[0],
gs->base + MLXBF_GPIO_PAD_CONTROL_FIRST_WORD);
writeq(gs->csave_regs.pad_control[1],
gs->base + MLXBF_GPIO_PAD_CONTROL_1_FIRST_WORD);
writeq(gs->csave_regs.pad_control[2],
gs->base + MLXBF_GPIO_PAD_CONTROL_2_FIRST_WORD);
writeq(gs->csave_regs.pad_control[3],
gs->base + MLXBF_GPIO_PAD_CONTROL_3_FIRST_WORD);
writeq(gs->csave_regs.pin_dir_i, gs->base + MLXBF_GPIO_PIN_DIR_I);
writeq(gs->csave_regs.pin_dir_o, gs->base + MLXBF_GPIO_PIN_DIR_O);
return 0;
}
#endif
static const struct acpi_device_id mlxbf_gpio_acpi_match[] = {
{ "MLNXBF02", 0 },
{}
};
MODULE_DEVICE_TABLE(acpi, mlxbf_gpio_acpi_match);
static struct platform_driver mlxbf_gpio_driver = {
.driver = {
.name = "mlxbf_gpio",
.acpi_match_table = ACPI_PTR(mlxbf_gpio_acpi_match),
},
.probe = mlxbf_gpio_probe,
#ifdef CONFIG_PM
.suspend = mlxbf_gpio_suspend,
.resume = mlxbf_gpio_resume,
#endif
};
module_platform_driver(mlxbf_gpio_driver);
MODULE_DESCRIPTION("Mellanox BlueField GPIO Driver");
MODULE_AUTHOR("Mellanox Technologies");
MODULE_LICENSE("GPL");
...@@ -134,17 +134,6 @@ static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio) ...@@ -134,17 +134,6 @@ static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio)
unsigned long pinmask = bgpio_line2mask(gc, gpio); unsigned long pinmask = bgpio_line2mask(gc, gpio);
bool dir = !!(gc->bgpio_dir & pinmask); bool dir = !!(gc->bgpio_dir & pinmask);
/*
* If the direction is OUT we read the value from the SET
* register, and if the direction is IN we read the value
* from the DAT register.
*
* If the direction bits are inverted, naturally this gets
* inverted too.
*/
if (gc->bgpio_dir_inverted)
dir = !dir;
if (dir) if (dir)
return !!(gc->read_reg(gc->reg_set) & pinmask); return !!(gc->read_reg(gc->reg_set) & pinmask);
else else
...@@ -164,14 +153,8 @@ static int bgpio_get_set_multiple(struct gpio_chip *gc, unsigned long *mask, ...@@ -164,14 +153,8 @@ static int bgpio_get_set_multiple(struct gpio_chip *gc, unsigned long *mask,
/* Make sure we first clear any bits that are zero when we read the register */ /* Make sure we first clear any bits that are zero when we read the register */
*bits &= ~*mask; *bits &= ~*mask;
/* Exploit the fact that we know which directions are set */
if (gc->bgpio_dir_inverted) {
set_mask = *mask & ~gc->bgpio_dir;
get_mask = *mask & gc->bgpio_dir;
} else {
set_mask = *mask & gc->bgpio_dir; set_mask = *mask & gc->bgpio_dir;
get_mask = *mask & ~gc->bgpio_dir; get_mask = *mask & ~gc->bgpio_dir;
}
if (set_mask) if (set_mask)
*bits |= gc->read_reg(gc->reg_set) & set_mask; *bits |= gc->read_reg(gc->reg_set) & set_mask;
...@@ -372,11 +355,12 @@ static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) ...@@ -372,11 +355,12 @@ static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
spin_lock_irqsave(&gc->bgpio_lock, flags); spin_lock_irqsave(&gc->bgpio_lock, flags);
if (gc->bgpio_dir_inverted)
gc->bgpio_dir |= bgpio_line2mask(gc, gpio);
else
gc->bgpio_dir &= ~bgpio_line2mask(gc, gpio); gc->bgpio_dir &= ~bgpio_line2mask(gc, gpio);
gc->write_reg(gc->reg_dir, gc->bgpio_dir);
if (gc->reg_dir_in)
gc->write_reg(gc->reg_dir_in, ~gc->bgpio_dir);
if (gc->reg_dir_out)
gc->write_reg(gc->reg_dir_out, gc->bgpio_dir);
spin_unlock_irqrestore(&gc->bgpio_lock, flags); spin_unlock_irqrestore(&gc->bgpio_lock, flags);
...@@ -385,11 +369,16 @@ static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) ...@@ -385,11 +369,16 @@ static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio) static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio)
{ {
/* Return 0 if output, 1 of input */ /* Return 0 if output, 1 if input */
if (gc->bgpio_dir_inverted) if (gc->bgpio_dir_unreadable)
return !!(gc->read_reg(gc->reg_dir) & bgpio_line2mask(gc, gpio)); return !(gc->bgpio_dir & bgpio_line2mask(gc, gpio));
else if (gc->reg_dir_out)
return !(gc->read_reg(gc->reg_dir) & bgpio_line2mask(gc, gpio)); return !(gc->read_reg(gc->reg_dir_out) & bgpio_line2mask(gc, gpio));
if (gc->reg_dir_in)
return !!(gc->read_reg(gc->reg_dir_in) & bgpio_line2mask(gc, gpio));
/* This should not happen */
return 1;
} }
static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
...@@ -400,11 +389,12 @@ static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) ...@@ -400,11 +389,12 @@ static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
spin_lock_irqsave(&gc->bgpio_lock, flags); spin_lock_irqsave(&gc->bgpio_lock, flags);
if (gc->bgpio_dir_inverted)
gc->bgpio_dir &= ~bgpio_line2mask(gc, gpio);
else
gc->bgpio_dir |= bgpio_line2mask(gc, gpio); gc->bgpio_dir |= bgpio_line2mask(gc, gpio);
gc->write_reg(gc->reg_dir, gc->bgpio_dir);
if (gc->reg_dir_in)
gc->write_reg(gc->reg_dir_in, ~gc->bgpio_dir);
if (gc->reg_dir_out)
gc->write_reg(gc->reg_dir_out, gc->bgpio_dir);
spin_unlock_irqrestore(&gc->bgpio_lock, flags); spin_unlock_irqrestore(&gc->bgpio_lock, flags);
...@@ -537,19 +527,12 @@ static int bgpio_setup_direction(struct gpio_chip *gc, ...@@ -537,19 +527,12 @@ static int bgpio_setup_direction(struct gpio_chip *gc,
void __iomem *dirin, void __iomem *dirin,
unsigned long flags) unsigned long flags)
{ {
if (dirout && dirin) { if (dirout || dirin) {
return -EINVAL; gc->reg_dir_out = dirout;
} else if (dirout) { gc->reg_dir_in = dirin;
gc->reg_dir = dirout;
gc->direction_output = bgpio_dir_out;
gc->direction_input = bgpio_dir_in;
gc->get_direction = bgpio_get_dir;
} else if (dirin) {
gc->reg_dir = dirin;
gc->direction_output = bgpio_dir_out; gc->direction_output = bgpio_dir_out;
gc->direction_input = bgpio_dir_in; gc->direction_input = bgpio_dir_in;
gc->get_direction = bgpio_get_dir; gc->get_direction = bgpio_get_dir;
gc->bgpio_dir_inverted = true;
} else { } else {
if (flags & BGPIOF_NO_OUTPUT) if (flags & BGPIOF_NO_OUTPUT)
gc->direction_output = bgpio_dir_out_err; gc->direction_output = bgpio_dir_out_err;
...@@ -588,11 +571,11 @@ static int bgpio_request(struct gpio_chip *chip, unsigned gpio_pin) ...@@ -588,11 +571,11 @@ static int bgpio_request(struct gpio_chip *chip, unsigned gpio_pin)
* @dirout: MMIO address for the register to set the line as OUTPUT. It is assumed * @dirout: MMIO address for the register to set the line as OUTPUT. It is assumed
* that setting a line to 1 in this register will turn that line into an * that setting a line to 1 in this register will turn that line into an
* output line. Conversely, setting the line to 0 will turn that line into * output line. Conversely, setting the line to 0 will turn that line into
* an input. Either this or @dirin can be defined, but never both. * an input.
* @dirin: MMIO address for the register to set this line as INPUT. It is assumed * @dirin: MMIO address for the register to set this line as INPUT. It is assumed
* that setting a line to 1 in this register will turn that line into an * that setting a line to 1 in this register will turn that line into an
* input line. Conversely, setting the line to 0 will turn that line into * input line. Conversely, setting the line to 0 will turn that line into
* an output. Either this or @dirout can be defined, but never both. * an output.
* @flags: Different flags that will affect the behaviour of the device, such as * @flags: Different flags that will affect the behaviour of the device, such as
* endianness etc. * endianness etc.
*/ */
...@@ -634,8 +617,28 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev, ...@@ -634,8 +617,28 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
if (gc->set == bgpio_set_set && if (gc->set == bgpio_set_set &&
!(flags & BGPIOF_UNREADABLE_REG_SET)) !(flags & BGPIOF_UNREADABLE_REG_SET))
gc->bgpio_data = gc->read_reg(gc->reg_set); gc->bgpio_data = gc->read_reg(gc->reg_set);
if (gc->reg_dir && !(flags & BGPIOF_UNREADABLE_REG_DIR))
gc->bgpio_dir = gc->read_reg(gc->reg_dir); if (flags & BGPIOF_UNREADABLE_REG_DIR)
gc->bgpio_dir_unreadable = true;
/*
* Inspect hardware to find initial direction setting.
*/
if ((gc->reg_dir_out || gc->reg_dir_in) &&
!(flags & BGPIOF_UNREADABLE_REG_DIR)) {
if (gc->reg_dir_out)
gc->bgpio_dir = gc->read_reg(gc->reg_dir_out);
else if (gc->reg_dir_in)
gc->bgpio_dir = ~gc->read_reg(gc->reg_dir_in);
/*
* If we have two direction registers, synchronise
* input setting to output setting, the library
* can not handle a line being input and output at
* the same time.
*/
if (gc->reg_dir_out && gc->reg_dir_in)
gc->write_reg(gc->reg_dir_in, ~gc->bgpio_dir);
}
return ret; return ret;
} }
......
...@@ -293,7 +293,6 @@ mediatek_gpio_bank_probe(struct device *dev, ...@@ -293,7 +293,6 @@ mediatek_gpio_bank_probe(struct device *dev,
static int static int
mediatek_gpio_probe(struct platform_device *pdev) mediatek_gpio_probe(struct platform_device *pdev)
{ {
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
struct mtk *mtk; struct mtk *mtk;
...@@ -304,7 +303,7 @@ mediatek_gpio_probe(struct platform_device *pdev) ...@@ -304,7 +303,7 @@ mediatek_gpio_probe(struct platform_device *pdev)
if (!mtk) if (!mtk)
return -ENOMEM; return -ENOMEM;
mtk->base = devm_ioremap_resource(dev, res); mtk->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(mtk->base)) if (IS_ERR(mtk->base))
return PTR_ERR(mtk->base); return PTR_ERR(mtk->base);
......
...@@ -1038,11 +1038,9 @@ static const struct regmap_config mvebu_gpio_regmap_config = { ...@@ -1038,11 +1038,9 @@ static const struct regmap_config mvebu_gpio_regmap_config = {
static int mvebu_gpio_probe_raw(struct platform_device *pdev, static int mvebu_gpio_probe_raw(struct platform_device *pdev,
struct mvebu_gpio_chip *mvchip) struct mvebu_gpio_chip *mvchip)
{ {
struct resource *res;
void __iomem *base; void __iomem *base;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); base = devm_platform_ioremap_resource(pdev, 0);
base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(base)) if (IS_ERR(base))
return PTR_ERR(base); return PTR_ERR(base);
...@@ -1062,8 +1060,7 @@ static int mvebu_gpio_probe_raw(struct platform_device *pdev, ...@@ -1062,8 +1060,7 @@ static int mvebu_gpio_probe_raw(struct platform_device *pdev,
* per-CPU registers * per-CPU registers
*/ */
if (mvchip->soc_variant == MVEBU_GPIO_SOC_VARIANT_ARMADAXP) { if (mvchip->soc_variant == MVEBU_GPIO_SOC_VARIANT_ARMADAXP) {
res = platform_get_resource(pdev, IORESOURCE_MEM, 1); base = devm_platform_ioremap_resource(pdev, 1);
base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(base)) if (IS_ERR(base))
return PTR_ERR(base); return PTR_ERR(base);
......
...@@ -411,7 +411,6 @@ static int mxc_gpio_probe(struct platform_device *pdev) ...@@ -411,7 +411,6 @@ static int mxc_gpio_probe(struct platform_device *pdev)
{ {
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
struct mxc_gpio_port *port; struct mxc_gpio_port *port;
struct resource *iores;
int irq_base; int irq_base;
int err; int err;
...@@ -423,8 +422,7 @@ static int mxc_gpio_probe(struct platform_device *pdev) ...@@ -423,8 +422,7 @@ static int mxc_gpio_probe(struct platform_device *pdev)
port->dev = &pdev->dev; port->dev = &pdev->dev;
iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); port->base = devm_platform_ioremap_resource(pdev, 0);
port->base = devm_ioremap_resource(&pdev->dev, iores);
if (IS_ERR(port->base)) if (IS_ERR(port->base))
return PTR_ERR(port->base); return PTR_ERR(port->base);
......
...@@ -82,7 +82,6 @@ static int octeon_gpio_probe(struct platform_device *pdev) ...@@ -82,7 +82,6 @@ static int octeon_gpio_probe(struct platform_device *pdev)
{ {
struct octeon_gpio *gpio; struct octeon_gpio *gpio;
struct gpio_chip *chip; struct gpio_chip *chip;
struct resource *res_mem;
void __iomem *reg_base; void __iomem *reg_base;
int err = 0; int err = 0;
...@@ -91,8 +90,7 @@ static int octeon_gpio_probe(struct platform_device *pdev) ...@@ -91,8 +90,7 @@ static int octeon_gpio_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
chip = &gpio->chip; chip = &gpio->chip;
res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); reg_base = devm_platform_ioremap_resource(pdev, 0);
reg_base = devm_ioremap_resource(&pdev->dev, res_mem);
if (IS_ERR(reg_base)) if (IS_ERR(reg_base))
return PTR_ERR(reg_base); return PTR_ERR(reg_base);
......
This diff is collapsed.
...@@ -73,6 +73,7 @@ ...@@ -73,6 +73,7 @@
#define PCA_CHIP_TYPE(x) ((x) & PCA_TYPE_MASK) #define PCA_CHIP_TYPE(x) ((x) & PCA_TYPE_MASK)
static const struct i2c_device_id pca953x_id[] = { static const struct i2c_device_id pca953x_id[] = {
{ "pca6416", 16 | PCA953X_TYPE | PCA_INT, },
{ "pca9505", 40 | PCA953X_TYPE | PCA_INT, }, { "pca9505", 40 | PCA953X_TYPE | PCA_INT, },
{ "pca9534", 8 | PCA953X_TYPE | PCA_INT, }, { "pca9534", 8 | PCA953X_TYPE | PCA_INT, },
{ "pca9535", 16 | PCA953X_TYPE | PCA_INT, }, { "pca9535", 16 | PCA953X_TYPE | PCA_INT, },
...@@ -153,6 +154,7 @@ struct pca953x_chip { ...@@ -153,6 +154,7 @@ struct pca953x_chip {
u8 irq_trig_fall[MAX_BANK]; u8 irq_trig_fall[MAX_BANK];
struct irq_chip irq_chip; struct irq_chip irq_chip;
#endif #endif
atomic_t wakeup_path;
struct i2c_client *client; struct i2c_client *client;
struct gpio_chip gpio_chip; struct gpio_chip gpio_chip;
...@@ -581,6 +583,11 @@ static int pca953x_irq_set_wake(struct irq_data *d, unsigned int on) ...@@ -581,6 +583,11 @@ static int pca953x_irq_set_wake(struct irq_data *d, unsigned int on)
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct pca953x_chip *chip = gpiochip_get_data(gc); struct pca953x_chip *chip = gpiochip_get_data(gc);
if (on)
atomic_inc(&chip->wakeup_path);
else
atomic_dec(&chip->wakeup_path);
return irq_set_irq_wake(chip->client->irq, on); return irq_set_irq_wake(chip->client->irq, on);
} }
...@@ -1100,6 +1107,9 @@ static int pca953x_suspend(struct device *dev) ...@@ -1100,6 +1107,9 @@ static int pca953x_suspend(struct device *dev)
regcache_cache_only(chip->regmap, true); regcache_cache_only(chip->regmap, true);
if (atomic_read(&chip->wakeup_path))
device_set_wakeup_path(dev);
else
regulator_disable(chip->regulator); regulator_disable(chip->regulator);
return 0; return 0;
...@@ -1110,11 +1120,13 @@ static int pca953x_resume(struct device *dev) ...@@ -1110,11 +1120,13 @@ static int pca953x_resume(struct device *dev)
struct pca953x_chip *chip = dev_get_drvdata(dev); struct pca953x_chip *chip = dev_get_drvdata(dev);
int ret; int ret;
if (!atomic_read(&chip->wakeup_path)) {
ret = regulator_enable(chip->regulator); ret = regulator_enable(chip->regulator);
if (ret != 0) { if (ret != 0) {
dev_err(dev, "Failed to enable regulator: %d\n", ret); dev_err(dev, "Failed to enable regulator: %d\n", ret);
return 0; return 0;
} }
}
regcache_cache_only(chip->regmap, false); regcache_cache_only(chip->regmap, false);
regcache_mark_dirty(chip->regmap); regcache_mark_dirty(chip->regmap);
...@@ -1137,6 +1149,7 @@ static int pca953x_resume(struct device *dev) ...@@ -1137,6 +1149,7 @@ static int pca953x_resume(struct device *dev)
#define OF_957X(__nrgpio, __int) (void *)(__nrgpio | PCA957X_TYPE | __int) #define OF_957X(__nrgpio, __int) (void *)(__nrgpio | PCA957X_TYPE | __int)
static const struct of_device_id pca953x_dt_ids[] = { static const struct of_device_id pca953x_dt_ids[] = {
{ .compatible = "nxp,pca6416", .data = OF_953X(16, PCA_INT), },
{ .compatible = "nxp,pca9505", .data = OF_953X(40, PCA_INT), }, { .compatible = "nxp,pca9505", .data = OF_953X(40, PCA_INT), },
{ .compatible = "nxp,pca9534", .data = OF_953X( 8, PCA_INT), }, { .compatible = "nxp,pca9534", .data = OF_953X( 8, PCA_INT), },
{ .compatible = "nxp,pca9535", .data = OF_953X(16, PCA_INT), }, { .compatible = "nxp,pca9535", .data = OF_953X(16, PCA_INT), },
...@@ -1152,6 +1165,7 @@ static const struct of_device_id pca953x_dt_ids[] = { ...@@ -1152,6 +1165,7 @@ static const struct of_device_id pca953x_dt_ids[] = {
{ .compatible = "nxp,pca9575", .data = OF_957X(16, PCA_INT), }, { .compatible = "nxp,pca9575", .data = OF_957X(16, PCA_INT), },
{ .compatible = "nxp,pca9698", .data = OF_953X(40, 0), }, { .compatible = "nxp,pca9698", .data = OF_953X(40, 0), },
{ .compatible = "nxp,pcal6416", .data = OF_953X(16, PCA_LATCH_INT), },
{ .compatible = "nxp,pcal6524", .data = OF_953X(24, PCA_LATCH_INT), }, { .compatible = "nxp,pcal6524", .data = OF_953X(24, PCA_LATCH_INT), },
{ .compatible = "nxp,pcal9555a", .data = OF_953X(16, PCA_LATCH_INT), }, { .compatible = "nxp,pcal9555a", .data = OF_953X(16, PCA_LATCH_INT), },
...@@ -1167,6 +1181,7 @@ static const struct of_device_id pca953x_dt_ids[] = { ...@@ -1167,6 +1181,7 @@ static const struct of_device_id pca953x_dt_ids[] = {
{ .compatible = "ti,tca6416", .data = OF_953X(16, PCA_INT), }, { .compatible = "ti,tca6416", .data = OF_953X(16, PCA_INT), },
{ .compatible = "ti,tca6424", .data = OF_953X(24, PCA_INT), }, { .compatible = "ti,tca6424", .data = OF_953X(24, PCA_INT), },
{ .compatible = "onnn,cat9554", .data = OF_953X( 8, PCA_INT), },
{ .compatible = "onnn,pca9654", .data = OF_953X( 8, PCA_INT), }, { .compatible = "onnn,pca9654", .data = OF_953X( 8, PCA_INT), },
{ .compatible = "exar,xra1202", .data = OF_953X( 8, 0), }, { .compatible = "exar,xra1202", .data = OF_953X( 8, 0), },
......
...@@ -577,7 +577,7 @@ static int pxa_irq_domain_map(struct irq_domain *d, unsigned int irq, ...@@ -577,7 +577,7 @@ static int pxa_irq_domain_map(struct irq_domain *d, unsigned int irq,
return 0; return 0;
} }
const struct irq_domain_ops pxa_irq_domain_ops = { static const struct irq_domain_ops pxa_irq_domain_ops = {
.map = pxa_irq_domain_map, .map = pxa_irq_domain_map,
.xlate = irq_domain_xlate_twocell, .xlate = irq_domain_xlate_twocell,
}; };
...@@ -622,7 +622,6 @@ static int pxa_gpio_probe(struct platform_device *pdev) ...@@ -622,7 +622,6 @@ static int pxa_gpio_probe(struct platform_device *pdev)
{ {
struct pxa_gpio_chip *pchip; struct pxa_gpio_chip *pchip;
struct pxa_gpio_bank *c; struct pxa_gpio_bank *c;
struct resource *res;
struct clk *clk; struct clk *clk;
struct pxa_gpio_platform_data *info; struct pxa_gpio_platform_data *info;
void __iomem *gpio_reg_base; void __iomem *gpio_reg_base;
...@@ -665,11 +664,8 @@ static int pxa_gpio_probe(struct platform_device *pdev) ...@@ -665,11 +664,8 @@ static int pxa_gpio_probe(struct platform_device *pdev)
pchip->irq0 = irq0; pchip->irq0 = irq0;
pchip->irq1 = irq1; pchip->irq1 = irq1;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) gpio_reg_base = devm_platform_ioremap_resource(pdev, 0);
return -EINVAL;
gpio_reg_base = devm_ioremap(&pdev->dev, res->start,
resource_size(res));
if (!gpio_reg_base) if (!gpio_reg_base)
return -EINVAL; return -EINVAL;
...@@ -816,7 +812,7 @@ static void pxa_gpio_resume(void) ...@@ -816,7 +812,7 @@ static void pxa_gpio_resume(void)
#define pxa_gpio_resume NULL #define pxa_gpio_resume NULL
#endif #endif
struct syscore_ops pxa_gpio_syscore_ops = { static struct syscore_ops pxa_gpio_syscore_ops = {
.suspend = pxa_gpio_suspend, .suspend = pxa_gpio_suspend,
.resume = pxa_gpio_resume, .resume = pxa_gpio_resume,
}; };
......
...@@ -430,7 +430,7 @@ static int gpio_rcar_parse_dt(struct gpio_rcar_priv *p, unsigned int *npins) ...@@ -430,7 +430,7 @@ static int gpio_rcar_parse_dt(struct gpio_rcar_priv *p, unsigned int *npins)
static int gpio_rcar_probe(struct platform_device *pdev) static int gpio_rcar_probe(struct platform_device *pdev)
{ {
struct gpio_rcar_priv *p; struct gpio_rcar_priv *p;
struct resource *io, *irq; struct resource *irq;
struct gpio_chip *gpio_chip; struct gpio_chip *gpio_chip;
struct irq_chip *irq_chip; struct irq_chip *irq_chip;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
...@@ -461,8 +461,7 @@ static int gpio_rcar_probe(struct platform_device *pdev) ...@@ -461,8 +461,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
goto err0; goto err0;
} }
io = platform_get_resource(pdev, IORESOURCE_MEM, 0); p->base = devm_platform_ioremap_resource(pdev, 0);
p->base = devm_ioremap_resource(dev, io);
if (IS_ERR(p->base)) { if (IS_ERR(p->base)) {
ret = PTR_ERR(p->base); ret = PTR_ERR(p->base);
goto err0; goto err0;
......
...@@ -23,7 +23,6 @@ struct sch_gpio { ...@@ -23,7 +23,6 @@ struct sch_gpio {
struct gpio_chip chip; struct gpio_chip chip;
spinlock_t lock; spinlock_t lock;
unsigned short iobase; unsigned short iobase;
unsigned short core_base;
unsigned short resume_base; unsigned short resume_base;
}; };
...@@ -166,7 +165,6 @@ static int sch_gpio_probe(struct platform_device *pdev) ...@@ -166,7 +165,6 @@ static int sch_gpio_probe(struct platform_device *pdev)
switch (pdev->id) { switch (pdev->id) {
case PCI_DEVICE_ID_INTEL_SCH_LPC: case PCI_DEVICE_ID_INTEL_SCH_LPC:
sch->core_base = 0;
sch->resume_base = 10; sch->resume_base = 10;
sch->chip.ngpio = 14; sch->chip.ngpio = 14;
...@@ -185,19 +183,16 @@ static int sch_gpio_probe(struct platform_device *pdev) ...@@ -185,19 +183,16 @@ static int sch_gpio_probe(struct platform_device *pdev)
break; break;
case PCI_DEVICE_ID_INTEL_ITC_LPC: case PCI_DEVICE_ID_INTEL_ITC_LPC:
sch->core_base = 0;
sch->resume_base = 5; sch->resume_base = 5;
sch->chip.ngpio = 14; sch->chip.ngpio = 14;
break; break;
case PCI_DEVICE_ID_INTEL_CENTERTON_ILB: case PCI_DEVICE_ID_INTEL_CENTERTON_ILB:
sch->core_base = 0;
sch->resume_base = 21; sch->resume_base = 21;
sch->chip.ngpio = 30; sch->chip.ngpio = 30;
break; break;
case PCI_DEVICE_ID_INTEL_QUARK_X1000_ILB: case PCI_DEVICE_ID_INTEL_QUARK_X1000_ILB:
sch->core_base = 0;
sch->resume_base = 2; sch->resume_base = 2;
sch->chip.ngpio = 8; sch->chip.ngpio = 8;
break; break;
......
...@@ -122,15 +122,13 @@ static int spics_gpio_probe(struct platform_device *pdev) ...@@ -122,15 +122,13 @@ static int spics_gpio_probe(struct platform_device *pdev)
{ {
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
struct spear_spics *spics; struct spear_spics *spics;
struct resource *res;
int ret; int ret;
spics = devm_kzalloc(&pdev->dev, sizeof(*spics), GFP_KERNEL); spics = devm_kzalloc(&pdev->dev, sizeof(*spics), GFP_KERNEL);
if (!spics) if (!spics)
return -ENOMEM; return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); spics->base = devm_platform_ioremap_resource(pdev, 0);
spics->base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(spics->base)) if (IS_ERR(spics->base))
return PTR_ERR(spics->base); return PTR_ERR(spics->base);
......
...@@ -219,7 +219,6 @@ static int sprd_gpio_probe(struct platform_device *pdev) ...@@ -219,7 +219,6 @@ static int sprd_gpio_probe(struct platform_device *pdev)
{ {
struct gpio_irq_chip *irq; struct gpio_irq_chip *irq;
struct sprd_gpio *sprd_gpio; struct sprd_gpio *sprd_gpio;
struct resource *res;
int ret; int ret;
sprd_gpio = devm_kzalloc(&pdev->dev, sizeof(*sprd_gpio), GFP_KERNEL); sprd_gpio = devm_kzalloc(&pdev->dev, sizeof(*sprd_gpio), GFP_KERNEL);
...@@ -232,8 +231,7 @@ static int sprd_gpio_probe(struct platform_device *pdev) ...@@ -232,8 +231,7 @@ static int sprd_gpio_probe(struct platform_device *pdev)
return sprd_gpio->irq; return sprd_gpio->irq;
} }
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); sprd_gpio->base = devm_platform_ioremap_resource(pdev, 0);
sprd_gpio->base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(sprd_gpio->base)) if (IS_ERR(sprd_gpio->base))
return PTR_ERR(sprd_gpio->base); return PTR_ERR(sprd_gpio->base);
......
...@@ -360,7 +360,6 @@ static int gsta_probe(struct platform_device *dev) ...@@ -360,7 +360,6 @@ static int gsta_probe(struct platform_device *dev)
struct pci_dev *pdev; struct pci_dev *pdev;
struct sta2x11_gpio_pdata *gpio_pdata; struct sta2x11_gpio_pdata *gpio_pdata;
struct gsta_gpio *chip; struct gsta_gpio *chip;
struct resource *res;
pdev = *(struct pci_dev **)dev_get_platdata(&dev->dev); pdev = *(struct pci_dev **)dev_get_platdata(&dev->dev);
gpio_pdata = dev_get_platdata(&pdev->dev); gpio_pdata = dev_get_platdata(&pdev->dev);
...@@ -369,13 +368,11 @@ static int gsta_probe(struct platform_device *dev) ...@@ -369,13 +368,11 @@ static int gsta_probe(struct platform_device *dev)
dev_err(&dev->dev, "no gpio config\n"); dev_err(&dev->dev, "no gpio config\n");
pr_debug("gpio config: %p\n", gpio_pdata); pr_debug("gpio config: %p\n", gpio_pdata);
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
chip = devm_kzalloc(&dev->dev, sizeof(*chip), GFP_KERNEL); chip = devm_kzalloc(&dev->dev, sizeof(*chip), GFP_KERNEL);
if (!chip) if (!chip)
return -ENOMEM; return -ENOMEM;
chip->dev = &dev->dev; chip->dev = &dev->dev;
chip->reg_base = devm_ioremap_resource(&dev->dev, res); chip->reg_base = devm_platform_ioremap_resource(dev, 0);
if (IS_ERR(chip->reg_base)) if (IS_ERR(chip->reg_base))
return PTR_ERR(chip->reg_base); return PTR_ERR(chip->reg_base);
......
...@@ -210,7 +210,6 @@ static int xway_stp_hw_init(struct xway_stp *chip) ...@@ -210,7 +210,6 @@ static int xway_stp_hw_init(struct xway_stp *chip)
static int xway_stp_probe(struct platform_device *pdev) static int xway_stp_probe(struct platform_device *pdev)
{ {
struct resource *res;
u32 shadow, groups, dsl, phy; u32 shadow, groups, dsl, phy;
struct xway_stp *chip; struct xway_stp *chip;
struct clk *clk; struct clk *clk;
...@@ -220,8 +219,7 @@ static int xway_stp_probe(struct platform_device *pdev) ...@@ -220,8 +219,7 @@ static int xway_stp_probe(struct platform_device *pdev)
if (!chip) if (!chip)
return -ENOMEM; return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); chip->virt = devm_platform_ioremap_resource(pdev, 0);
chip->virt = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(chip->virt)) if (IS_ERR(chip->virt))
return PTR_ERR(chip->virt); return PTR_ERR(chip->virt);
......
...@@ -120,7 +120,6 @@ static irqreturn_t tb10x_gpio_irq_cascade(int irq, void *data) ...@@ -120,7 +120,6 @@ static irqreturn_t tb10x_gpio_irq_cascade(int irq, void *data)
static int tb10x_gpio_probe(struct platform_device *pdev) static int tb10x_gpio_probe(struct platform_device *pdev)
{ {
struct tb10x_gpio *tb10x_gpio; struct tb10x_gpio *tb10x_gpio;
struct resource *mem;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
int ret = -EBUSY; int ret = -EBUSY;
...@@ -136,8 +135,7 @@ static int tb10x_gpio_probe(struct platform_device *pdev) ...@@ -136,8 +135,7 @@ static int tb10x_gpio_probe(struct platform_device *pdev)
if (tb10x_gpio == NULL) if (tb10x_gpio == NULL)
return -ENOMEM; return -ENOMEM;
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); tb10x_gpio->base = devm_platform_ioremap_resource(pdev, 0);
tb10x_gpio->base = devm_ioremap_resource(dev, mem);
if (IS_ERR(tb10x_gpio->base)) if (IS_ERR(tb10x_gpio->base))
return PTR_ERR(tb10x_gpio->base); return PTR_ERR(tb10x_gpio->base);
......
...@@ -569,7 +569,6 @@ static const struct dev_pm_ops tegra_gpio_pm_ops = { ...@@ -569,7 +569,6 @@ static const struct dev_pm_ops tegra_gpio_pm_ops = {
static int tegra_gpio_probe(struct platform_device *pdev) static int tegra_gpio_probe(struct platform_device *pdev)
{ {
struct tegra_gpio_info *tgi; struct tegra_gpio_info *tgi;
struct resource *res;
struct tegra_gpio_bank *bank; struct tegra_gpio_bank *bank;
unsigned int gpio, i, j; unsigned int gpio, i, j;
int ret; int ret;
...@@ -645,8 +644,7 @@ static int tegra_gpio_probe(struct platform_device *pdev) ...@@ -645,8 +644,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)
bank->tgi = tgi; bank->tgi = tgi;
} }
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); tgi->regs = devm_platform_ioremap_resource(pdev, 0);
tgi->regs = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(tgi->regs)) if (IS_ERR(tgi->regs))
return PTR_ERR(tgi->regs); return PTR_ERR(tgi->regs);
......
...@@ -229,7 +229,6 @@ static int timbgpio_probe(struct platform_device *pdev) ...@@ -229,7 +229,6 @@ static int timbgpio_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct gpio_chip *gc; struct gpio_chip *gc;
struct timbgpio *tgpio; struct timbgpio *tgpio;
struct resource *iomem;
struct timbgpio_platform_data *pdata = dev_get_platdata(&pdev->dev); struct timbgpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
int irq = platform_get_irq(pdev, 0); int irq = platform_get_irq(pdev, 0);
...@@ -246,8 +245,7 @@ static int timbgpio_probe(struct platform_device *pdev) ...@@ -246,8 +245,7 @@ static int timbgpio_probe(struct platform_device *pdev)
spin_lock_init(&tgpio->lock); spin_lock_init(&tgpio->lock);
iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); tgpio->membase = devm_platform_ioremap_resource(pdev, 0);
tgpio->membase = devm_ioremap_resource(dev, iomem);
if (IS_ERR(tgpio->membase)) if (IS_ERR(tgpio->membase))
return PTR_ERR(tgpio->membase); return PTR_ERR(tgpio->membase);
......
...@@ -23,7 +23,6 @@ static int ts4800_gpio_probe(struct platform_device *pdev) ...@@ -23,7 +23,6 @@ static int ts4800_gpio_probe(struct platform_device *pdev)
{ {
struct device_node *node; struct device_node *node;
struct gpio_chip *chip; struct gpio_chip *chip;
struct resource *res;
void __iomem *base_addr; void __iomem *base_addr;
int retval; int retval;
u32 ngpios; u32 ngpios;
...@@ -32,8 +31,7 @@ static int ts4800_gpio_probe(struct platform_device *pdev) ...@@ -32,8 +31,7 @@ static int ts4800_gpio_probe(struct platform_device *pdev)
if (!chip) if (!chip)
return -ENOMEM; return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); base_addr = devm_platform_ioremap_resource(pdev, 0);
base_addr = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(base_addr)) if (IS_ERR(base_addr))
return PTR_ERR(base_addr); return PTR_ERR(base_addr);
......
...@@ -346,7 +346,6 @@ static int uniphier_gpio_probe(struct platform_device *pdev) ...@@ -346,7 +346,6 @@ static int uniphier_gpio_probe(struct platform_device *pdev)
struct uniphier_gpio_priv *priv; struct uniphier_gpio_priv *priv;
struct gpio_chip *chip; struct gpio_chip *chip;
struct irq_chip *irq_chip; struct irq_chip *irq_chip;
struct resource *regs;
unsigned int nregs; unsigned int nregs;
u32 ngpios; u32 ngpios;
int ret; int ret;
...@@ -370,8 +369,7 @@ static int uniphier_gpio_probe(struct platform_device *pdev) ...@@ -370,8 +369,7 @@ static int uniphier_gpio_probe(struct platform_device *pdev)
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); priv->regs = devm_platform_ioremap_resource(pdev, 0);
priv->regs = devm_ioremap_resource(dev, regs);
if (IS_ERR(priv->regs)) if (IS_ERR(priv->regs))
return PTR_ERR(priv->regs); return PTR_ERR(priv->regs);
......
...@@ -29,6 +29,7 @@ struct fsl_gpio_soc_data { ...@@ -29,6 +29,7 @@ struct fsl_gpio_soc_data {
struct vf610_gpio_port { struct vf610_gpio_port {
struct gpio_chip gc; struct gpio_chip gc;
struct irq_chip ic;
void __iomem *base; void __iomem *base;
void __iomem *gpio_base; void __iomem *gpio_base;
const struct fsl_gpio_soc_data *sdata; const struct fsl_gpio_soc_data *sdata;
...@@ -60,8 +61,6 @@ struct vf610_gpio_port { ...@@ -60,8 +61,6 @@ struct vf610_gpio_port {
#define PORT_INT_EITHER_EDGE 0xb #define PORT_INT_EITHER_EDGE 0xb
#define PORT_INT_LOGIC_ONE 0xc #define PORT_INT_LOGIC_ONE 0xc
static struct irq_chip vf610_gpio_irq_chip;
static const struct fsl_gpio_soc_data imx_data = { static const struct fsl_gpio_soc_data imx_data = {
.have_paddr = true, .have_paddr = true,
}; };
...@@ -86,28 +85,24 @@ static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio) ...@@ -86,28 +85,24 @@ static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio)
{ {
struct vf610_gpio_port *port = gpiochip_get_data(gc); struct vf610_gpio_port *port = gpiochip_get_data(gc);
unsigned long mask = BIT(gpio); unsigned long mask = BIT(gpio);
void __iomem *addr; unsigned long offset = GPIO_PDIR;
if (port->sdata && port->sdata->have_paddr) { if (port->sdata && port->sdata->have_paddr) {
mask &= vf610_gpio_readl(port->gpio_base + GPIO_PDDR); mask &= vf610_gpio_readl(port->gpio_base + GPIO_PDDR);
addr = mask ? port->gpio_base + GPIO_PDOR : if (mask)
port->gpio_base + GPIO_PDIR; offset = GPIO_PDOR;
return !!(vf610_gpio_readl(addr) & BIT(gpio));
} else {
return !!(vf610_gpio_readl(port->gpio_base + GPIO_PDIR)
& BIT(gpio));
} }
return !!(vf610_gpio_readl(port->gpio_base + offset) & BIT(gpio));
} }
static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
{ {
struct vf610_gpio_port *port = gpiochip_get_data(gc); struct vf610_gpio_port *port = gpiochip_get_data(gc);
unsigned long mask = BIT(gpio); unsigned long mask = BIT(gpio);
unsigned long offset = val ? GPIO_PSOR : GPIO_PCOR;
if (val) vf610_gpio_writel(mask, port->gpio_base + offset);
vf610_gpio_writel(mask, port->gpio_base + GPIO_PSOR);
else
vf610_gpio_writel(mask, port->gpio_base + GPIO_PCOR);
} }
static int vf610_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) static int vf610_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
...@@ -237,37 +232,31 @@ static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable) ...@@ -237,37 +232,31 @@ static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable)
return 0; return 0;
} }
static struct irq_chip vf610_gpio_irq_chip = { static void vf610_gpio_disable_clk(void *data)
.name = "gpio-vf610", {
.irq_ack = vf610_gpio_irq_ack, clk_disable_unprepare(data);
.irq_mask = vf610_gpio_irq_mask, }
.irq_unmask = vf610_gpio_irq_unmask,
.irq_set_type = vf610_gpio_irq_set_type,
.irq_set_wake = vf610_gpio_irq_set_wake,
};
static int vf610_gpio_probe(struct platform_device *pdev) static int vf610_gpio_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
struct vf610_gpio_port *port; struct vf610_gpio_port *port;
struct resource *iores;
struct gpio_chip *gc; struct gpio_chip *gc;
struct irq_chip *ic;
int i; int i;
int ret; int ret;
port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL); port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
if (!port) if (!port)
return -ENOMEM; return -ENOMEM;
port->sdata = of_device_get_match_data(dev); port->sdata = of_device_get_match_data(dev);
iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); port->base = devm_platform_ioremap_resource(pdev, 0);
port->base = devm_ioremap_resource(dev, iores);
if (IS_ERR(port->base)) if (IS_ERR(port->base))
return PTR_ERR(port->base); return PTR_ERR(port->base);
iores = platform_get_resource(pdev, IORESOURCE_MEM, 1); port->gpio_base = devm_platform_ioremap_resource(pdev, 1);
port->gpio_base = devm_ioremap_resource(dev, iores);
if (IS_ERR(port->gpio_base)) if (IS_ERR(port->gpio_base))
return PTR_ERR(port->gpio_base); return PTR_ERR(port->gpio_base);
...@@ -275,11 +264,15 @@ static int vf610_gpio_probe(struct platform_device *pdev) ...@@ -275,11 +264,15 @@ static int vf610_gpio_probe(struct platform_device *pdev)
if (port->irq < 0) if (port->irq < 0)
return port->irq; return port->irq;
port->clk_port = devm_clk_get(&pdev->dev, "port"); port->clk_port = devm_clk_get(dev, "port");
if (!IS_ERR(port->clk_port)) { if (!IS_ERR(port->clk_port)) {
ret = clk_prepare_enable(port->clk_port); ret = clk_prepare_enable(port->clk_port);
if (ret) if (ret)
return ret; return ret;
ret = devm_add_action_or_reset(dev, vf610_gpio_disable_clk,
port->clk_port);
if (ret)
return ret;
} else if (port->clk_port == ERR_PTR(-EPROBE_DEFER)) { } else if (port->clk_port == ERR_PTR(-EPROBE_DEFER)) {
/* /*
* Percolate deferrals, for anything else, * Percolate deferrals, for anything else,
...@@ -288,20 +281,19 @@ static int vf610_gpio_probe(struct platform_device *pdev) ...@@ -288,20 +281,19 @@ static int vf610_gpio_probe(struct platform_device *pdev)
return PTR_ERR(port->clk_port); return PTR_ERR(port->clk_port);
} }
port->clk_gpio = devm_clk_get(&pdev->dev, "gpio"); port->clk_gpio = devm_clk_get(dev, "gpio");
if (!IS_ERR(port->clk_gpio)) { if (!IS_ERR(port->clk_gpio)) {
ret = clk_prepare_enable(port->clk_gpio); ret = clk_prepare_enable(port->clk_gpio);
if (ret) { if (ret)
clk_disable_unprepare(port->clk_port); return ret;
ret = devm_add_action_or_reset(dev, vf610_gpio_disable_clk,
port->clk_gpio);
if (ret)
return ret; return ret;
}
} else if (port->clk_gpio == ERR_PTR(-EPROBE_DEFER)) { } else if (port->clk_gpio == ERR_PTR(-EPROBE_DEFER)) {
clk_disable_unprepare(port->clk_port);
return PTR_ERR(port->clk_gpio); return PTR_ERR(port->clk_gpio);
} }
platform_set_drvdata(pdev, port);
gc = &port->gc; gc = &port->gc;
gc->of_node = np; gc->of_node = np;
gc->parent = dev; gc->parent = dev;
...@@ -316,7 +308,15 @@ static int vf610_gpio_probe(struct platform_device *pdev) ...@@ -316,7 +308,15 @@ static int vf610_gpio_probe(struct platform_device *pdev)
gc->direction_output = vf610_gpio_direction_output; gc->direction_output = vf610_gpio_direction_output;
gc->set = vf610_gpio_set; gc->set = vf610_gpio_set;
ret = gpiochip_add_data(gc, port); ic = &port->ic;
ic->name = "gpio-vf610";
ic->irq_ack = vf610_gpio_irq_ack;
ic->irq_mask = vf610_gpio_irq_mask;
ic->irq_unmask = vf610_gpio_irq_unmask;
ic->irq_set_type = vf610_gpio_irq_set_type;
ic->irq_set_wake = vf610_gpio_irq_set_wake;
ret = devm_gpiochip_add_data(dev, gc, port);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -327,39 +327,23 @@ static int vf610_gpio_probe(struct platform_device *pdev) ...@@ -327,39 +327,23 @@ static int vf610_gpio_probe(struct platform_device *pdev)
/* Clear the interrupt status register for all GPIO's */ /* Clear the interrupt status register for all GPIO's */
vf610_gpio_writel(~0, port->base + PORT_ISFR); vf610_gpio_writel(~0, port->base + PORT_ISFR);
ret = gpiochip_irqchip_add(gc, &vf610_gpio_irq_chip, 0, ret = gpiochip_irqchip_add(gc, ic, 0, handle_edge_irq, IRQ_TYPE_NONE);
handle_edge_irq, IRQ_TYPE_NONE);
if (ret) { if (ret) {
dev_err(dev, "failed to add irqchip\n"); dev_err(dev, "failed to add irqchip\n");
gpiochip_remove(gc);
return ret; return ret;
} }
gpiochip_set_chained_irqchip(gc, &vf610_gpio_irq_chip, port->irq, gpiochip_set_chained_irqchip(gc, ic, port->irq,
vf610_gpio_irq_handler); vf610_gpio_irq_handler);
return 0; return 0;
} }
static int vf610_gpio_remove(struct platform_device *pdev)
{
struct vf610_gpio_port *port = platform_get_drvdata(pdev);
gpiochip_remove(&port->gc);
if (!IS_ERR(port->clk_port))
clk_disable_unprepare(port->clk_port);
if (!IS_ERR(port->clk_gpio))
clk_disable_unprepare(port->clk_gpio);
return 0;
}
static struct platform_driver vf610_gpio_driver = { static struct platform_driver vf610_gpio_driver = {
.driver = { .driver = {
.name = "gpio-vf610", .name = "gpio-vf610",
.of_match_table = vf610_gpio_dt_ids, .of_match_table = vf610_gpio_dt_ids,
}, },
.probe = vf610_gpio_probe, .probe = vf610_gpio_probe,
.remove = vf610_gpio_remove,
}; };
builtin_platform_driver(vf610_gpio_driver); builtin_platform_driver(vf610_gpio_driver);
...@@ -229,7 +229,6 @@ static int xgene_gpio_sb_probe(struct platform_device *pdev) ...@@ -229,7 +229,6 @@ static int xgene_gpio_sb_probe(struct platform_device *pdev)
{ {
struct xgene_gpio_sb *priv; struct xgene_gpio_sb *priv;
int ret; int ret;
struct resource *res;
void __iomem *regs; void __iomem *regs;
struct irq_domain *parent_domain = NULL; struct irq_domain *parent_domain = NULL;
u32 val32; u32 val32;
...@@ -238,8 +237,7 @@ static int xgene_gpio_sb_probe(struct platform_device *pdev) ...@@ -238,8 +237,7 @@ static int xgene_gpio_sb_probe(struct platform_device *pdev)
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); regs = devm_platform_ioremap_resource(pdev, 0);
regs = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(regs)) if (IS_ERR(regs))
return PTR_ERR(regs); return PTR_ERR(regs);
......
...@@ -290,22 +290,17 @@ MODULE_DEVICE_TABLE(of, xlp_gpio_of_ids); ...@@ -290,22 +290,17 @@ MODULE_DEVICE_TABLE(of, xlp_gpio_of_ids);
static int xlp_gpio_probe(struct platform_device *pdev) static int xlp_gpio_probe(struct platform_device *pdev)
{ {
struct gpio_chip *gc; struct gpio_chip *gc;
struct resource *iores;
struct xlp_gpio_priv *priv; struct xlp_gpio_priv *priv;
void __iomem *gpio_base; void __iomem *gpio_base;
int irq_base, irq, err; int irq_base, irq, err;
int ngpio; int ngpio;
u32 soc_type; u32 soc_type;
iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!iores)
return -ENODEV;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
gpio_base = devm_ioremap_resource(&pdev->dev, iores); gpio_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(gpio_base)) if (IS_ERR(gpio_base))
return PTR_ERR(gpio_base); return PTR_ERR(gpio_base);
......
...@@ -218,15 +218,13 @@ static int zx_gpio_probe(struct platform_device *pdev) ...@@ -218,15 +218,13 @@ static int zx_gpio_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct zx_gpio *chip; struct zx_gpio *chip;
struct resource *res;
int irq, id, ret; int irq, id, ret;
chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
if (!chip) if (!chip)
return -ENOMEM; return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); chip->base = devm_platform_ioremap_resource(pdev, 0);
chip->base = devm_ioremap_resource(dev, res);
if (IS_ERR(chip->base)) if (IS_ERR(chip->base))
return PTR_ERR(chip->base); return PTR_ERR(chip->base);
......
...@@ -834,7 +834,6 @@ static int zynq_gpio_probe(struct platform_device *pdev) ...@@ -834,7 +834,6 @@ static int zynq_gpio_probe(struct platform_device *pdev)
int ret, bank_num; int ret, bank_num;
struct zynq_gpio *gpio; struct zynq_gpio *gpio;
struct gpio_chip *chip; struct gpio_chip *chip;
struct resource *res;
const struct of_device_id *match; const struct of_device_id *match;
gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
...@@ -849,8 +848,7 @@ static int zynq_gpio_probe(struct platform_device *pdev) ...@@ -849,8 +848,7 @@ static int zynq_gpio_probe(struct platform_device *pdev)
gpio->p_data = match->data; gpio->p_data = match->data;
platform_set_drvdata(pdev, gpio); platform_set_drvdata(pdev, gpio);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); gpio->base_addr = devm_platform_ioremap_resource(pdev, 0);
gpio->base_addr = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(gpio->base_addr)) if (IS_ERR(gpio->base_addr))
return PTR_ERR(gpio->base_addr); return PTR_ERR(gpio->base_addr);
......
...@@ -24,13 +24,13 @@ ...@@ -24,13 +24,13 @@
* *
* @node: list-entry of the events list of the struct acpi_gpio_chip * @node: list-entry of the events list of the struct acpi_gpio_chip
* @handle: handle of ACPI method to execute when the IRQ triggers * @handle: handle of ACPI method to execute when the IRQ triggers
* @handler: irq_handler to pass to request_irq when requesting the IRQ * @handler: handler function to pass to request_irq() when requesting the IRQ
* @pin: GPIO pin number on the gpio_chip * @pin: GPIO pin number on the struct gpio_chip
* @irq: Linux IRQ number for the event, for request_ / free_irq * @irq: Linux IRQ number for the event, for request_irq() / free_irq()
* @irqflags: flags to pass to request_irq when requesting the IRQ * @irqflags: flags to pass to request_irq() when requesting the IRQ
* @irq_is_wake: If the ACPI flags indicate the IRQ is a wakeup source * @irq_is_wake: If the ACPI flags indicate the IRQ is a wakeup source
* @irq_requested:True if request_irq has been done * @irq_requested:True if request_irq() has been done
* @desc: gpio_desc for the GPIO pin for this event * @desc: struct gpio_desc for the GPIO pin for this event
*/ */
struct acpi_gpio_event { struct acpi_gpio_event {
struct list_head node; struct list_head node;
...@@ -65,10 +65,10 @@ struct acpi_gpio_chip { ...@@ -65,10 +65,10 @@ struct acpi_gpio_chip {
}; };
/* /*
* For gpiochips which call acpi_gpiochip_request_interrupts() before late_init * For GPIO chips which call acpi_gpiochip_request_interrupts() before late_init
* (so builtin drivers) we register the ACPI GpioInt IRQ handlers from a * (so builtin drivers) we register the ACPI GpioInt IRQ handlers from a
* late_initcall_sync handler, so that other builtin drivers can register their * late_initcall_sync() handler, so that other builtin drivers can register their
* OpRegions before the event handlers can run. This list contains gpiochips * OpRegions before the event handlers can run. This list contains GPIO chips
* for which the acpi_gpiochip_request_irqs() call has been deferred. * for which the acpi_gpiochip_request_irqs() call has been deferred.
*/ */
static DEFINE_MUTEX(acpi_gpio_deferred_req_irqs_lock); static DEFINE_MUTEX(acpi_gpio_deferred_req_irqs_lock);
...@@ -90,7 +90,7 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data) ...@@ -90,7 +90,7 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
* *
* Return: GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR * Return: GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR
* error value. Specifically returns %-EPROBE_DEFER if the referenced GPIO * error value. Specifically returns %-EPROBE_DEFER if the referenced GPIO
* controller does not have gpiochip registered at the moment. This is to * controller does not have GPIO chip registered at the moment. This is to
* support probe deferral. * support probe deferral.
*/ */
static struct gpio_desc *acpi_get_gpiod(char *path, int pin) static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
...@@ -287,9 +287,9 @@ static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares, ...@@ -287,9 +287,9 @@ static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares,
* *
* ACPI5 platforms can use GPIO signaled ACPI events. These GPIO interrupts are * ACPI5 platforms can use GPIO signaled ACPI events. These GPIO interrupts are
* handled by ACPI event methods which need to be called from the GPIO * handled by ACPI event methods which need to be called from the GPIO
* chip's interrupt handler. acpi_gpiochip_request_interrupts finds out which * chip's interrupt handler. acpi_gpiochip_request_interrupts() finds out which
* gpio pins have acpi event methods and assigns interrupt handlers that calls * GPIO pins have ACPI event methods and assigns interrupt handlers that calls
* the acpi event methods for those pins. * the ACPI event methods for those pins.
*/ */
void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
{ {
...@@ -444,8 +444,6 @@ static bool acpi_get_driver_gpio_data(struct acpi_device *adev, ...@@ -444,8 +444,6 @@ static bool acpi_get_driver_gpio_data(struct acpi_device *adev,
static enum gpiod_flags static enum gpiod_flags
acpi_gpio_to_gpiod_flags(const struct acpi_resource_gpio *agpio) acpi_gpio_to_gpiod_flags(const struct acpi_resource_gpio *agpio)
{ {
bool pull_up = agpio->pin_config == ACPI_PIN_CONFIG_PULLUP;
switch (agpio->io_restriction) { switch (agpio->io_restriction) {
case ACPI_IO_RESTRICT_INPUT: case ACPI_IO_RESTRICT_INPUT:
return GPIOD_IN; return GPIOD_IN;
...@@ -454,16 +452,26 @@ acpi_gpio_to_gpiod_flags(const struct acpi_resource_gpio *agpio) ...@@ -454,16 +452,26 @@ acpi_gpio_to_gpiod_flags(const struct acpi_resource_gpio *agpio)
* ACPI GPIO resources don't contain an initial value for the * ACPI GPIO resources don't contain an initial value for the
* GPIO. Therefore we deduce that value from the pull field * GPIO. Therefore we deduce that value from the pull field
* instead. If the pin is pulled up we assume default to be * instead. If the pin is pulled up we assume default to be
* high, otherwise low. * high, if it is pulled down we assume default to be low,
* otherwise we leave pin untouched.
*/ */
return pull_up ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; switch (agpio->pin_config) {
case ACPI_PIN_CONFIG_PULLUP:
return GPIOD_OUT_HIGH;
case ACPI_PIN_CONFIG_PULLDOWN:
return GPIOD_OUT_LOW;
default:
break;
}
default: default:
break;
}
/* /*
* Assume that the BIOS has configured the direction and pull * Assume that the BIOS has configured the direction and pull
* accordingly. * accordingly.
*/ */
return GPIOD_ASIS; return GPIOD_ASIS;
}
} }
static int static int
...@@ -517,6 +525,26 @@ acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, struct acpi_gpio_info *inf ...@@ -517,6 +525,26 @@ acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, struct acpi_gpio_info *inf
return ret; return ret;
} }
int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
struct acpi_gpio_info *info)
{
switch (info->pin_config) {
case ACPI_PIN_CONFIG_PULLUP:
*lookupflags |= GPIO_PULL_UP;
break;
case ACPI_PIN_CONFIG_PULLDOWN:
*lookupflags |= GPIO_PULL_DOWN;
break;
default:
break;
}
if (info->polarity == GPIO_ACTIVE_LOW)
*lookupflags |= GPIO_ACTIVE_LOW;
return 0;
}
struct acpi_gpio_lookup { struct acpi_gpio_lookup {
struct acpi_gpio_info info; struct acpi_gpio_info info;
int index; int index;
...@@ -550,6 +578,7 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data) ...@@ -550,6 +578,7 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
lookup->desc = acpi_get_gpiod(agpio->resource_source.string_ptr, lookup->desc = acpi_get_gpiod(agpio->resource_source.string_ptr,
agpio->pin_table[pin_index]); agpio->pin_table[pin_index]);
lookup->info.pin_config = agpio->pin_config;
lookup->info.gpioint = gpioint; lookup->info.gpioint = gpioint;
/* /*
...@@ -653,7 +682,7 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode, ...@@ -653,7 +682,7 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode,
* that case @index is used to select the GPIO entry in the property value * that case @index is used to select the GPIO entry in the property value
* (in case of multiple). * (in case of multiple).
* *
* If the GPIO cannot be translated or there is an error an ERR_PTR is * If the GPIO cannot be translated or there is an error, an ERR_PTR is
* returned. * returned.
* *
* Note: if the GPIO resource has multiple entries in the pin list, this * Note: if the GPIO resource has multiple entries in the pin list, this
...@@ -696,7 +725,7 @@ struct gpio_desc *acpi_find_gpio(struct device *dev, ...@@ -696,7 +725,7 @@ struct gpio_desc *acpi_find_gpio(struct device *dev,
const char *con_id, const char *con_id,
unsigned int idx, unsigned int idx,
enum gpiod_flags *dflags, enum gpiod_flags *dflags,
enum gpio_lookup_flags *lookupflags) unsigned long *lookupflags)
{ {
struct acpi_device *adev = ACPI_COMPANION(dev); struct acpi_device *adev = ACPI_COMPANION(dev);
struct acpi_gpio_info info; struct acpi_gpio_info info;
...@@ -737,10 +766,8 @@ struct gpio_desc *acpi_find_gpio(struct device *dev, ...@@ -737,10 +766,8 @@ struct gpio_desc *acpi_find_gpio(struct device *dev,
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
if (info.polarity == GPIO_ACTIVE_LOW)
*lookupflags |= GPIO_ACTIVE_LOW;
acpi_gpio_update_gpiod_flags(dflags, &info); acpi_gpio_update_gpiod_flags(dflags, &info);
acpi_gpio_update_gpiod_lookup_flags(lookupflags, &info);
return desc; return desc;
} }
...@@ -751,10 +778,13 @@ struct gpio_desc *acpi_find_gpio(struct device *dev, ...@@ -751,10 +778,13 @@ struct gpio_desc *acpi_find_gpio(struct device *dev,
* @index: index of GpioIo/GpioInt resource (starting from %0) * @index: index of GpioIo/GpioInt resource (starting from %0)
* @info: info pointer to fill in (optional) * @info: info pointer to fill in (optional)
* *
* If @fwnode is an ACPI device object, call %acpi_get_gpiod_by_index() for it. * If @fwnode is an ACPI device object, call acpi_get_gpiod_by_index() for it.
* Otherwise (ie. it is a data-only non-device object), use the property-based * Otherwise (i.e. it is a data-only non-device object), use the property-based
* GPIO lookup to get to the GPIO resource with the relevant information and use * GPIO lookup to get to the GPIO resource with the relevant information and use
* that to obtain the GPIO descriptor to return. * that to obtain the GPIO descriptor to return.
*
* If the GPIO cannot be translated or there is an error an ERR_PTR is
* returned.
*/ */
struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode, struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
const char *propname, int index, const char *propname, int index,
...@@ -816,6 +846,7 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index) ...@@ -816,6 +846,7 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
return PTR_ERR(desc); return PTR_ERR(desc);
if (info.gpioint && idx++ == index) { if (info.gpioint && idx++ == index) {
unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
char label[32]; char label[32];
int irq; int irq;
...@@ -827,7 +858,7 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index) ...@@ -827,7 +858,7 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
return irq; return irq;
snprintf(label, sizeof(label), "GpioInt() %d", index); snprintf(label, sizeof(label), "GpioInt() %d", index);
ret = gpiod_configure_flags(desc, label, 0, info.flags); ret = gpiod_configure_flags(desc, label, lflags, info.flags);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -992,16 +1023,19 @@ static void acpi_gpiochip_free_regions(struct acpi_gpio_chip *achip) ...@@ -992,16 +1023,19 @@ static void acpi_gpiochip_free_regions(struct acpi_gpio_chip *achip)
} }
} }
static struct gpio_desc *acpi_gpiochip_parse_own_gpio( static struct gpio_desc *
struct acpi_gpio_chip *achip, struct fwnode_handle *fwnode, acpi_gpiochip_parse_own_gpio(struct acpi_gpio_chip *achip,
const char **name, unsigned int *lflags, unsigned int *dflags) struct fwnode_handle *fwnode,
const char **name,
unsigned long *lflags,
enum gpiod_flags *dflags)
{ {
struct gpio_chip *chip = achip->chip; struct gpio_chip *chip = achip->chip;
struct gpio_desc *desc; struct gpio_desc *desc;
u32 gpios[2]; u32 gpios[2];
int ret; int ret;
*lflags = 0; *lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
*dflags = 0; *dflags = 0;
*name = NULL; *name = NULL;
...@@ -1037,7 +1071,8 @@ static void acpi_gpiochip_scan_gpios(struct acpi_gpio_chip *achip) ...@@ -1037,7 +1071,8 @@ static void acpi_gpiochip_scan_gpios(struct acpi_gpio_chip *achip)
struct fwnode_handle *fwnode; struct fwnode_handle *fwnode;
device_for_each_child_node(chip->parent, fwnode) { device_for_each_child_node(chip->parent, fwnode) {
unsigned int lflags, dflags; unsigned long lflags;
enum gpiod_flags dflags;
struct gpio_desc *desc; struct gpio_desc *desc;
const char *name; const char *name;
int ret; int ret;
...@@ -1158,11 +1193,13 @@ static int acpi_find_gpio_count(struct acpi_resource *ares, void *data) ...@@ -1158,11 +1193,13 @@ static int acpi_find_gpio_count(struct acpi_resource *ares, void *data)
} }
/** /**
* acpi_gpio_count - return the number of GPIOs associated with a * acpi_gpio_count - count the GPIOs associated with a device / function
* device / function or -ENOENT if no GPIO has been * @dev: GPIO consumer, can be %NULL for system-global GPIOs
* assigned to the requested function.
* @dev: GPIO consumer, can be NULL for system-global GPIOs
* @con_id: function within the GPIO consumer * @con_id: function within the GPIO consumer
*
* Return:
* The number of GPIOs associated with a device / function or %-ENOENT,
* if no GPIO has been assigned to the requested function.
*/ */
int acpi_gpio_count(struct device *dev, const char *con_id) int acpi_gpio_count(struct device *dev, const char *con_id)
{ {
......
...@@ -86,9 +86,9 @@ static void of_gpio_flags_quirks(struct device_node *np, ...@@ -86,9 +86,9 @@ static void of_gpio_flags_quirks(struct device_node *np,
if (IS_ENABLED(CONFIG_REGULATOR) && if (IS_ENABLED(CONFIG_REGULATOR) &&
(of_device_is_compatible(np, "regulator-fixed") || (of_device_is_compatible(np, "regulator-fixed") ||
of_device_is_compatible(np, "reg-fixed-voltage") || of_device_is_compatible(np, "reg-fixed-voltage") ||
(of_device_is_compatible(np, "regulator-gpio") && (!(strcmp(propname, "enable-gpio") &&
!(strcmp(propname, "enable-gpio") && strcmp(propname, "enable-gpios")) &&
strcmp(propname, "enable-gpios"))))) { of_device_is_compatible(np, "regulator-gpio")))) {
/* /*
* The regulator GPIO handles are specified such that the * The regulator GPIO handles are specified such that the
* presence or absence of "enable-active-high" solely controls * presence or absence of "enable-active-high" solely controls
...@@ -119,9 +119,8 @@ static void of_gpio_flags_quirks(struct device_node *np, ...@@ -119,9 +119,8 @@ static void of_gpio_flags_quirks(struct device_node *np,
* property named "cs-gpios" we need to inspect the child node * property named "cs-gpios" we need to inspect the child node
* to determine if the flags should have inverted semantics. * to determine if the flags should have inverted semantics.
*/ */
if (IS_ENABLED(CONFIG_SPI_MASTER) && if (IS_ENABLED(CONFIG_SPI_MASTER) && !strcmp(propname, "cs-gpios") &&
of_property_read_bool(np, "cs-gpios") && of_property_read_bool(np, "cs-gpios")) {
!strcmp(propname, "cs-gpios")) {
struct device_node *child; struct device_node *child;
u32 cs; u32 cs;
int ret; int ret;
...@@ -288,8 +287,7 @@ static struct gpio_desc *of_find_regulator_gpio(struct device *dev, const char * ...@@ -288,8 +287,7 @@ static struct gpio_desc *of_find_regulator_gpio(struct device *dev, const char *
} }
struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
unsigned int idx, unsigned int idx, unsigned long *flags)
enum gpio_lookup_flags *flags)
{ {
char prop_name[32]; /* 32 is max size of property name */ char prop_name[32]; /* 32 is max size of property name */
enum of_gpio_flags of_flags; enum of_gpio_flags of_flags;
...@@ -362,8 +360,8 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, ...@@ -362,8 +360,8 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
* @chip: GPIO chip whose hog is parsed * @chip: GPIO chip whose hog is parsed
* @idx: Index of the GPIO to parse * @idx: Index of the GPIO to parse
* @name: GPIO line name * @name: GPIO line name
* @lflags: gpio_lookup_flags - returned from of_find_gpio() or * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from
* of_parse_own_gpio() * of_find_gpio() or of_parse_own_gpio()
* @dflags: gpiod_flags - optional GPIO initialization flags * @dflags: gpiod_flags - optional GPIO initialization flags
* *
* Returns GPIO descriptor to use with Linux GPIO API, or one of the errno * Returns GPIO descriptor to use with Linux GPIO API, or one of the errno
...@@ -372,7 +370,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, ...@@ -372,7 +370,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
static struct gpio_desc *of_parse_own_gpio(struct device_node *np, static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
struct gpio_chip *chip, struct gpio_chip *chip,
unsigned int idx, const char **name, unsigned int idx, const char **name,
enum gpio_lookup_flags *lflags, unsigned long *lflags,
enum gpiod_flags *dflags) enum gpiod_flags *dflags)
{ {
struct device_node *chip_np; struct device_node *chip_np;
...@@ -388,7 +386,7 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, ...@@ -388,7 +386,7 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
xlate_flags = 0; xlate_flags = 0;
*lflags = 0; *lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
*dflags = 0; *dflags = 0;
ret = of_property_read_u32(chip_np, "#gpio-cells", &tmp); ret = of_property_read_u32(chip_np, "#gpio-cells", &tmp);
...@@ -445,7 +443,7 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip) ...@@ -445,7 +443,7 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
struct gpio_desc *desc = NULL; struct gpio_desc *desc = NULL;
struct device_node *np; struct device_node *np;
const char *name; const char *name;
enum gpio_lookup_flags lflags; unsigned long lflags;
enum gpiod_flags dflags; enum gpiod_flags dflags;
unsigned int i; unsigned int i;
int ret; int ret;
......
...@@ -2519,6 +2519,7 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, ...@@ -2519,6 +2519,7 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
const char *label, const char *label,
enum gpiod_flags flags) enum gpiod_flags flags)
{ {
unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum); struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum);
int err; int err;
...@@ -2531,7 +2532,7 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, ...@@ -2531,7 +2532,7 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
if (err < 0) if (err < 0)
return ERR_PTR(err); return ERR_PTR(err);
err = gpiod_configure_flags(desc, label, 0, flags); err = gpiod_configure_flags(desc, label, lflags, flags);
if (err) { if (err) {
chip_err(chip, "setup of own GPIO %s failed\n", label); chip_err(chip, "setup of own GPIO %s failed\n", label);
gpiod_free_commit(desc); gpiod_free_commit(desc);
...@@ -2569,8 +2570,20 @@ EXPORT_SYMBOL_GPL(gpiochip_free_own_desc); ...@@ -2569,8 +2570,20 @@ EXPORT_SYMBOL_GPL(gpiochip_free_own_desc);
static int gpio_set_config(struct gpio_chip *gc, unsigned offset, static int gpio_set_config(struct gpio_chip *gc, unsigned offset,
enum pin_config_param mode) enum pin_config_param mode)
{ {
unsigned long config = { PIN_CONF_PACKED(mode, 0) }; unsigned long config;
unsigned arg;
switch (mode) {
case PIN_CONFIG_BIAS_PULL_DOWN:
case PIN_CONFIG_BIAS_PULL_UP:
arg = 1;
break;
default:
arg = 0;
}
config = PIN_CONF_PACKED(mode, arg);
return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP; return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP;
} }
...@@ -3915,8 +3928,7 @@ static struct gpiod_lookup_table *gpiod_find_lookup_table(struct device *dev) ...@@ -3915,8 +3928,7 @@ static struct gpiod_lookup_table *gpiod_find_lookup_table(struct device *dev)
} }
static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
unsigned int idx, unsigned int idx, unsigned long *flags)
enum gpio_lookup_flags *flags)
{ {
struct gpio_desc *desc = ERR_PTR(-ENOENT); struct gpio_desc *desc = ERR_PTR(-ENOENT);
struct gpiod_lookup_table *table; struct gpiod_lookup_table *table;
...@@ -4072,8 +4084,8 @@ EXPORT_SYMBOL_GPL(gpiod_get_optional); ...@@ -4072,8 +4084,8 @@ EXPORT_SYMBOL_GPL(gpiod_get_optional);
* gpiod_configure_flags - helper function to configure a given GPIO * gpiod_configure_flags - helper function to configure a given GPIO
* @desc: gpio whose value will be assigned * @desc: gpio whose value will be assigned
* @con_id: function within the GPIO consumer * @con_id: function within the GPIO consumer
* @lflags: gpio_lookup_flags - returned from of_find_gpio() or * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from
* of_get_gpio_hog() * of_find_gpio() or of_get_gpio_hog()
* @dflags: gpiod_flags - optional GPIO initialization flags * @dflags: gpiod_flags - optional GPIO initialization flags
* *
* Return 0 on success, -ENOENT if no GPIO has been assigned to the * Return 0 on success, -ENOENT if no GPIO has been assigned to the
...@@ -4155,9 +4167,9 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev, ...@@ -4155,9 +4167,9 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
unsigned int idx, unsigned int idx,
enum gpiod_flags flags) enum gpiod_flags flags)
{ {
unsigned long lookupflags = GPIO_LOOKUP_FLAGS_DEFAULT;
struct gpio_desc *desc = NULL; struct gpio_desc *desc = NULL;
int status; int status;
enum gpio_lookup_flags lookupflags = 0;
/* Maybe we have a device name, maybe not */ /* Maybe we have a device name, maybe not */
const char *devname = dev ? dev_name(dev) : "?"; const char *devname = dev ? dev_name(dev) : "?";
...@@ -4242,8 +4254,8 @@ struct gpio_desc *gpiod_get_from_of_node(struct device_node *node, ...@@ -4242,8 +4254,8 @@ struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
enum gpiod_flags dflags, enum gpiod_flags dflags,
const char *label) const char *label)
{ {
unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
struct gpio_desc *desc; struct gpio_desc *desc;
unsigned long lflags = 0;
enum of_gpio_flags flags; enum of_gpio_flags flags;
bool active_low = false; bool active_low = false;
bool single_ended = false; bool single_ended = false;
...@@ -4321,8 +4333,8 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, ...@@ -4321,8 +4333,8 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
enum gpiod_flags dflags, enum gpiod_flags dflags,
const char *label) const char *label)
{ {
unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
struct gpio_desc *desc = ERR_PTR(-ENODEV); struct gpio_desc *desc = ERR_PTR(-ENODEV);
unsigned long lflags = 0;
int ret; int ret;
if (!fwnode) if (!fwnode)
...@@ -4342,9 +4354,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, ...@@ -4342,9 +4354,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
return desc; return desc;
acpi_gpio_update_gpiod_flags(&dflags, &info); acpi_gpio_update_gpiod_flags(&dflags, &info);
acpi_gpio_update_gpiod_lookup_flags(&lflags, &info);
if (info.polarity == GPIO_ACTIVE_LOW)
lflags |= GPIO_ACTIVE_LOW;
} }
/* Currently only ACPI takes this path */ /* Currently only ACPI takes this path */
...@@ -4395,8 +4405,8 @@ EXPORT_SYMBOL_GPL(gpiod_get_index_optional); ...@@ -4395,8 +4405,8 @@ EXPORT_SYMBOL_GPL(gpiod_get_index_optional);
* gpiod_hog - Hog the specified GPIO desc given the provided flags * gpiod_hog - Hog the specified GPIO desc given the provided flags
* @desc: gpio whose value will be assigned * @desc: gpio whose value will be assigned
* @name: gpio line name * @name: gpio line name
* @lflags: gpio_lookup_flags - returned from of_find_gpio() or * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from
* of_get_gpio_hog() * of_find_gpio() or of_get_gpio_hog()
* @dflags: gpiod_flags - optional GPIO initialization flags * @dflags: gpiod_flags - optional GPIO initialization flags
*/ */
int gpiod_hog(struct gpio_desc *desc, const char *name, int gpiod_hog(struct gpio_desc *desc, const char *name,
...@@ -4449,8 +4459,6 @@ int gpiod_hog(struct gpio_desc *desc, const char *name, ...@@ -4449,8 +4459,6 @@ int gpiod_hog(struct gpio_desc *desc, const char *name,
/** /**
* gpiochip_free_hogs - Scan gpio-controller chip and release GPIO hog * gpiochip_free_hogs - Scan gpio-controller chip and release GPIO hog
* @chip: gpio chip to act on * @chip: gpio chip to act on
*
* This is only used by of_gpiochip_remove to free hogged gpios
*/ */
static void gpiochip_free_hogs(struct gpio_chip *chip) static void gpiochip_free_hogs(struct gpio_chip *chip)
{ {
...@@ -4620,6 +4628,7 @@ EXPORT_SYMBOL_GPL(gpiod_get_array_optional); ...@@ -4620,6 +4628,7 @@ EXPORT_SYMBOL_GPL(gpiod_get_array_optional);
*/ */
void gpiod_put(struct gpio_desc *desc) void gpiod_put(struct gpio_desc *desc)
{ {
if (desc)
gpiod_free(desc); gpiod_free(desc);
} }
EXPORT_SYMBOL_GPL(gpiod_put); EXPORT_SYMBOL_GPL(gpiod_put);
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <linux/cdev.h> #include <linux/cdev.h>
enum of_gpio_flags; enum of_gpio_flags;
enum gpio_lookup_flags;
struct acpi_device; struct acpi_device;
/** /**
...@@ -75,6 +74,7 @@ struct gpio_device { ...@@ -75,6 +74,7 @@ struct gpio_device {
* @adev: reference to ACPI device which consumes GPIO resource * @adev: reference to ACPI device which consumes GPIO resource
* @flags: GPIO initialization flags * @flags: GPIO initialization flags
* @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
* @pin_config: pin bias as provided by ACPI
* @polarity: interrupt polarity as provided by ACPI * @polarity: interrupt polarity as provided by ACPI
* @triggering: triggering type as provided by ACPI * @triggering: triggering type as provided by ACPI
* @quirks: Linux specific quirks as provided by struct acpi_gpio_mapping * @quirks: Linux specific quirks as provided by struct acpi_gpio_mapping
...@@ -83,6 +83,7 @@ struct acpi_gpio_info { ...@@ -83,6 +83,7 @@ struct acpi_gpio_info {
struct acpi_device *adev; struct acpi_device *adev;
enum gpiod_flags flags; enum gpiod_flags flags;
bool gpioint; bool gpioint;
int pin_config;
int polarity; int polarity;
int triggering; int triggering;
unsigned int quirks; unsigned int quirks;
...@@ -95,7 +96,7 @@ static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" }; ...@@ -95,7 +96,7 @@ static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" };
struct gpio_desc *of_find_gpio(struct device *dev, struct gpio_desc *of_find_gpio(struct device *dev,
const char *con_id, const char *con_id,
unsigned int idx, unsigned int idx,
enum gpio_lookup_flags *flags); unsigned long *lookupflags);
struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
const char *list_name, int index, enum of_gpio_flags *flags); const char *list_name, int index, enum of_gpio_flags *flags);
int of_gpiochip_add(struct gpio_chip *gc); int of_gpiochip_add(struct gpio_chip *gc);
...@@ -104,7 +105,7 @@ void of_gpiochip_remove(struct gpio_chip *gc); ...@@ -104,7 +105,7 @@ void of_gpiochip_remove(struct gpio_chip *gc);
static inline struct gpio_desc *of_find_gpio(struct device *dev, static inline struct gpio_desc *of_find_gpio(struct device *dev,
const char *con_id, const char *con_id,
unsigned int idx, unsigned int idx,
enum gpio_lookup_flags *flags) unsigned long *lookupflags)
{ {
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
...@@ -126,12 +127,14 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip); ...@@ -126,12 +127,14 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip);
int acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, int acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags,
struct acpi_gpio_info *info); struct acpi_gpio_info *info);
int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
struct acpi_gpio_info *info);
struct gpio_desc *acpi_find_gpio(struct device *dev, struct gpio_desc *acpi_find_gpio(struct device *dev,
const char *con_id, const char *con_id,
unsigned int idx, unsigned int idx,
enum gpiod_flags *dflags, enum gpiod_flags *dflags,
enum gpio_lookup_flags *lookupflags); unsigned long *lookupflags);
struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode, struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
const char *propname, int index, const char *propname, int index,
struct acpi_gpio_info *info); struct acpi_gpio_info *info);
...@@ -154,11 +157,17 @@ acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, struct acpi_gpio_info *inf ...@@ -154,11 +157,17 @@ acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, struct acpi_gpio_info *inf
{ {
return 0; return 0;
} }
static inline int
acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
struct acpi_gpio_info *info)
{
return 0;
}
static inline struct gpio_desc * static inline struct gpio_desc *
acpi_find_gpio(struct device *dev, const char *con_id, acpi_find_gpio(struct device *dev, const char *con_id,
unsigned int idx, enum gpiod_flags *dflags, unsigned int idx, enum gpiod_flags *dflags,
enum gpio_lookup_flags *lookupflags) unsigned long *lookupflags)
{ {
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
......
...@@ -655,115 +655,6 @@ static int mcp23s08_irqchip_setup(struct mcp23s08 *mcp) ...@@ -655,115 +655,6 @@ static int mcp23s08_irqchip_setup(struct mcp23s08 *mcp)
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
#ifdef CONFIG_DEBUG_FS
#include <linux/seq_file.h>
/*
* This compares the chip's registers with the register
* cache and corrects any incorrectly set register. This
* can be used to fix state for MCP23xxx, that temporary
* lost its power supply.
*/
#define MCP23S08_CONFIG_REGS 7
static int __check_mcp23s08_reg_cache(struct mcp23s08 *mcp)
{
int cached[MCP23S08_CONFIG_REGS];
int err = 0, i;
/* read cached config registers */
for (i = 0; i < MCP23S08_CONFIG_REGS; i++) {
err = mcp_read(mcp, i, &cached[i]);
if (err)
goto out;
}
regcache_cache_bypass(mcp->regmap, true);
for (i = 0; i < MCP23S08_CONFIG_REGS; i++) {
int uncached;
err = mcp_read(mcp, i, &uncached);
if (err)
goto out;
if (uncached != cached[i]) {
dev_err(mcp->dev, "restoring reg 0x%02x from 0x%04x to 0x%04x (power-loss?)\n",
i, uncached, cached[i]);
mcp_write(mcp, i, cached[i]);
}
}
out:
if (err)
dev_err(mcp->dev, "read error: reg=%02x, err=%d", i, err);
regcache_cache_bypass(mcp->regmap, false);
return err;
}
/*
* This shows more info than the generic gpio dump code:
* pullups, deglitching, open drain drive.
*/
static void mcp23s08_dbg_show(struct seq_file *s, struct gpio_chip *chip)
{
struct mcp23s08 *mcp;
char bank;
int t;
unsigned mask;
int iodir, gpio, gppu;
mcp = gpiochip_get_data(chip);
/* NOTE: we only handle one bank for now ... */
bank = '0' + ((mcp->addr >> 1) & 0x7);
mutex_lock(&mcp->lock);
t = __check_mcp23s08_reg_cache(mcp);
if (t) {
seq_printf(s, " I/O Error\n");
goto done;
}
t = mcp_read(mcp, MCP_IODIR, &iodir);
if (t) {
seq_printf(s, " I/O Error\n");
goto done;
}
t = mcp_read(mcp, MCP_GPIO, &gpio);
if (t) {
seq_printf(s, " I/O Error\n");
goto done;
}
t = mcp_read(mcp, MCP_GPPU, &gppu);
if (t) {
seq_printf(s, " I/O Error\n");
goto done;
}
for (t = 0, mask = BIT(0); t < chip->ngpio; t++, mask <<= 1) {
const char *label;
label = gpiochip_is_requested(chip, t);
if (!label)
continue;
seq_printf(s, " gpio-%-3d P%c.%d (%-12s) %s %s %s\n",
chip->base + t, bank, t, label,
(iodir & mask) ? "in " : "out",
(gpio & mask) ? "hi" : "lo",
(gppu & mask) ? "up" : " ");
/* NOTE: ignoring the irq-related registers */
}
done:
mutex_unlock(&mcp->lock);
}
#else
#define mcp23s08_dbg_show NULL
#endif
/*----------------------------------------------------------------------*/
static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
void *data, unsigned addr, unsigned type, void *data, unsigned addr, unsigned type,
unsigned int base, int cs) unsigned int base, int cs)
...@@ -784,7 +675,6 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, ...@@ -784,7 +675,6 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
mcp->chip.get = mcp23s08_get; mcp->chip.get = mcp23s08_get;
mcp->chip.direction_output = mcp23s08_direction_output; mcp->chip.direction_output = mcp23s08_direction_output;
mcp->chip.set = mcp23s08_set; mcp->chip.set = mcp23s08_set;
mcp->chip.dbg_show = mcp23s08_dbg_show;
#ifdef CONFIG_OF_GPIO #ifdef CONFIG_OF_GPIO
mcp->chip.of_gpio_n_cells = 2; mcp->chip.of_gpio_n_cells = 2;
mcp->chip.of_node = dev->of_node; mcp->chip.of_node = dev->of_node;
......
...@@ -227,9 +227,10 @@ struct gpio_irq_chip { ...@@ -227,9 +227,10 @@ struct gpio_irq_chip {
* @reg_dat: data (in) register for generic GPIO * @reg_dat: data (in) register for generic GPIO
* @reg_set: output set register (out=high) for generic GPIO * @reg_set: output set register (out=high) for generic GPIO
* @reg_clr: output clear register (out=low) for generic GPIO * @reg_clr: output clear register (out=low) for generic GPIO
* @reg_dir: direction setting register for generic GPIO * @reg_dir_out: direction out setting register for generic GPIO
* @bgpio_dir_inverted: indicates that the direction register is inverted * @reg_dir_in: direction in setting register for generic GPIO
* (gpiolib private state variable) * @bgpio_dir_unreadable: indicates that the direction register(s) cannot
* be read and we need to rely on out internal state tracking.
* @bgpio_bits: number of register bits used for a generic GPIO i.e. * @bgpio_bits: number of register bits used for a generic GPIO i.e.
* <register width> * 8 * <register width> * 8
* @bgpio_lock: used to lock chip->bgpio_data. Also, this is needed to keep * @bgpio_lock: used to lock chip->bgpio_data. Also, this is needed to keep
...@@ -237,7 +238,8 @@ struct gpio_irq_chip { ...@@ -237,7 +238,8 @@ struct gpio_irq_chip {
* @bgpio_data: shadowed data register for generic GPIO to clear/set bits * @bgpio_data: shadowed data register for generic GPIO to clear/set bits
* safely. * safely.
* @bgpio_dir: shadowed direction register for generic GPIO to clear/set * @bgpio_dir: shadowed direction register for generic GPIO to clear/set
* direction safely. * direction safely. A "1" in this word means the line is set as
* output.
* *
* A gpio_chip can help platforms abstract various sources of GPIOs so * A gpio_chip can help platforms abstract various sources of GPIOs so
* they can all be accessed through a common programing interface. * they can all be accessed through a common programing interface.
...@@ -298,8 +300,9 @@ struct gpio_chip { ...@@ -298,8 +300,9 @@ struct gpio_chip {
void __iomem *reg_dat; void __iomem *reg_dat;
void __iomem *reg_set; void __iomem *reg_set;
void __iomem *reg_clr; void __iomem *reg_clr;
void __iomem *reg_dir; void __iomem *reg_dir_out;
bool bgpio_dir_inverted; void __iomem *reg_dir_in;
bool bgpio_dir_unreadable;
int bgpio_bits; int bgpio_bits;
spinlock_t bgpio_lock; spinlock_t bgpio_lock;
unsigned long bgpio_data; unsigned long bgpio_data;
......
...@@ -14,6 +14,8 @@ enum gpio_lookup_flags { ...@@ -14,6 +14,8 @@ enum gpio_lookup_flags {
GPIO_TRANSITORY = (1 << 3), GPIO_TRANSITORY = (1 << 3),
GPIO_PULL_UP = (1 << 4), GPIO_PULL_UP = (1 << 4),
GPIO_PULL_DOWN = (1 << 5), GPIO_PULL_DOWN = (1 << 5),
GPIO_LOOKUP_FLAGS_DEFAULT = GPIO_ACTIVE_HIGH | GPIO_PERSISTENT,
}; };
/** /**
...@@ -22,7 +24,7 @@ enum gpio_lookup_flags { ...@@ -22,7 +24,7 @@ enum gpio_lookup_flags {
* @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO
* @con_id: name of the GPIO from the device's point of view * @con_id: name of the GPIO from the device's point of view
* @idx: index of the GPIO in case several GPIOs share the same name * @idx: index of the GPIO in case several GPIOs share the same name
* @flags: mask of GPIO_* values * @flags: bitmask of gpio_lookup_flags GPIO_* values
* *
* gpiod_lookup is a lookup table for associating GPIOs to specific devices and * gpiod_lookup is a lookup table for associating GPIOs to specific devices and
* functions using platform data. * functions using platform data.
...@@ -32,7 +34,7 @@ struct gpiod_lookup { ...@@ -32,7 +34,7 @@ struct gpiod_lookup {
u16 chip_hwnum; u16 chip_hwnum;
const char *con_id; const char *con_id;
unsigned int idx; unsigned int idx;
enum gpio_lookup_flags flags; unsigned long flags;
}; };
struct gpiod_lookup_table { struct gpiod_lookup_table {
...@@ -46,7 +48,7 @@ struct gpiod_lookup_table { ...@@ -46,7 +48,7 @@ struct gpiod_lookup_table {
* @chip_label: name of the chip the GPIO belongs to * @chip_label: name of the chip the GPIO belongs to
* @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO
* @line_name: consumer name for the hogged line * @line_name: consumer name for the hogged line
* @lflags: mask of GPIO lookup flags * @lflags: bitmask of gpio_lookup_flags GPIO_* values
* @dflags: GPIO flags used to specify the direction and value * @dflags: GPIO flags used to specify the direction and value
*/ */
struct gpiod_hog { struct gpiod_hog {
...@@ -54,7 +56,7 @@ struct gpiod_hog { ...@@ -54,7 +56,7 @@ struct gpiod_hog {
const char *chip_label; const char *chip_label;
u16 chip_hwnum; u16 chip_hwnum;
const char *line_name; const char *line_name;
enum gpio_lookup_flags lflags; unsigned long lflags;
int dflags; int dflags;
}; };
......
...@@ -200,8 +200,6 @@ struct omap_gpio_platform_data { ...@@ -200,8 +200,6 @@ struct omap_gpio_platform_data {
bool is_mpuio; /* whether the bank is of type MPUIO */ bool is_mpuio; /* whether the bank is of type MPUIO */
u32 non_wakeup_gpios; u32 non_wakeup_gpios;
u32 quirks; /* Version specific quirks mask */
struct omap_gpio_reg_offs *regs; struct omap_gpio_reg_offs *regs;
/* Return context loss count due to PM states changing */ /* Return context loss count due to PM states changing */
......
...@@ -2,10 +2,6 @@ ...@@ -2,10 +2,6 @@
#undef TRACE_SYSTEM #undef TRACE_SYSTEM
#define TRACE_SYSTEM gpio #define TRACE_SYSTEM gpio
#ifndef CONFIG_TRACING_EVENTS_GPIO
#define NOTRACE
#endif
#if !defined(_TRACE_GPIO_H) || defined(TRACE_HEADER_MULTI_READ) #if !defined(_TRACE_GPIO_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_GPIO_H #define _TRACE_GPIO_H
......
...@@ -774,13 +774,6 @@ config TRACE_EVAL_MAP_FILE ...@@ -774,13 +774,6 @@ config TRACE_EVAL_MAP_FILE
If unsure, say N If unsure, say N
config TRACING_EVENTS_GPIO
bool "Trace gpio events"
depends on GPIOLIB
default y
help
Enable tracing events for gpio subsystem
config GCOV_PROFILE_FTRACE config GCOV_PROFILE_FTRACE
bool "Enable GCOV profiling on ftrace subsystem" bool "Enable GCOV profiling on ftrace subsystem"
depends on GCOV_KERNEL depends on GCOV_KERNEL
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment