Commit 1ec5c186 authored by Linus Torvalds's avatar Linus Torvalds

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

Pull GPIO updates from Linus Walleij:
 "This is the bulk of GPIO changes for the v4.11 cycle

  Core changes:

   - Augment fwnode_get_named_gpiod() to configure the GPIO pin
     immediately after requesting it like all other APIs do. This is a
     treewide change also updating all users.

   - Pass a GPIO label down to gpiod_request() from
     fwnode_get_named_gpiod(). This makes debugfs and the userspace ABI
     correctly reflect the current in-kernel consumer of a pin taken
     using this abstraction. This is a treewide change also updating all
     users.

   - Rename devm_get_gpiod_from_child() to
     devm_fwnode_get_gpiod_from_child() to reflect the fact that this
     function is operating on a fwnode object. This is a treewide change
     also updating all users.

   - Make it possible to take multiple GPIOs in a single hog of device
     tree hogs.

   - The refactorings switching GPIO chips to use the .set_config()
     callback using standard pin control properties and providing a
     backend into the pin control subsystem that were also merged into
     the pin control tree naturally appear here too.

  Testing instrumentation:

   - A whole slew of cleanups and improvements to the mockup GPIO
     driver. We now have an extended userspace test exercising the
     subsystem, and we can inject interrupts etc from userspace to fully
     test the core GPIO functionality.

  New drivers:

   - New driver for the Cortina Systems Gemini GPIO controller.

   - New driver for the Exar XR17V352/354/358 chips.

   - New driver for the ACCES PCI-IDIO-16 PCI GPIO card.

  Driver changes:

   - RCAR: set the irqchip parent device, add fine-grained runtime PM
     support.

   - pca953x: support optional RESET control line on the chip.

   - DaVinci: cleanups and simplifications. Add support for multiple
     instances.

   - .set_multiple() and naming of lines on more or less all of the
     ISA/PCI GPIO controllers.

   - mcp23s08: refactored to use regmap as a first step to further
     rewrites and modernizations"

* tag 'gpio-v4.11-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (61 commits)
  gpio: reintroduce devm_get_gpiod_from_child()
  gpio: pci-idio-16: Fix PCI BAR index
  gpio: pci-idio-16: Fix PCI device ID code
  gpio: mockup: implement event injecting over debugfs
  gpio: mockup: add a dummy irqchip
  gpio: mockup: implement naming the lines
  gpio: mockup: code shrink
  gpio: mockup: readability tweaks
  gpio: Add GPIO support for the ACCES PCI-IDIO-16
  gpio: Add the devm_fwnode_get_index_gpiod_from_child() helper
  gpio: Rename devm_get_gpiod_from_child()
  gpio: mcp23s08: Select REGMAP/REGMAP_I2C to fix build error
  gpio: ws16c48: Add support for GPIO names
  gpio: gpio-mm: Add support for GPIO names
  gpio: 104-idio-16: Add support for GPIO names
  gpio: 104-idi-48: Add support for GPIO names
  gpio: 104-dio-48e: Add support for GPIO names
  gpio: ws16c48: Remove unnecessary driver_data set
  gpio: gpio-mm: Remove unnecessary driver_data set
  gpio: 104-idio-16: Remove unnecessary driver_data set
  ...
parents d5dee39b 3498d869
Cortina Systems Gemini GPIO Controller
Required properties:
- compatible : Must be "cortina,gemini-gpio"
- reg : Should contain registers location and length
- interrupts : Should contain the interrupt line for the GPIO block
- gpio-controller : marks this as a GPIO controller
- #gpio-cells : Should be 2, see gpio/gpio.txt
- interrupt-controller : marks this as an interrupt controller
- #interrupt-cells : a standard two-cell interrupt flag, see
interrupt-controller/interrupts.txt
Example:
gpio@4d000000 {
compatible = "cortina,gemini-gpio";
reg = <0x4d000000 0x100>;
interrupts = <22 IRQ_TYPE_LEVEL_HIGH>;
gpio-controller;
#gpio-cells = <2>;
interrupt-controller;
#interrupt-cells = <2>;
};
...@@ -29,6 +29,10 @@ Required properties: ...@@ -29,6 +29,10 @@ Required properties:
onsemi,pca9654 onsemi,pca9654
exar,xra1202 exar,xra1202
Optional properties:
- reset-gpios: GPIO specification for the RESET input. This is an
active low signal to the PCA953x.
Example: Example:
......
...@@ -187,10 +187,10 @@ gpio-controller's driver probe function. ...@@ -187,10 +187,10 @@ gpio-controller's driver probe function.
Each GPIO hog definition is represented as a child node of the GPIO controller. Each GPIO hog definition is represented as a child node of the GPIO controller.
Required properties: Required properties:
- gpio-hog: A property specifying that this child node represent a GPIO hog. - gpio-hog: A property specifying that this child node represents a GPIO hog.
- gpios: Store the GPIO information (id, flags, ...). Shall contain the - gpios: Store the GPIO information (id, flags, ...) for each GPIO to
number of cells specified in its parent node (GPIO controller affect. Shall contain an integer multiple of the number of cells
node). specified in its parent node (GPIO controller node).
Only one of the following properties scanned in the order shown below. Only one of the following properties scanned in the order shown below.
This means that when multiple properties are present they will be searched This means that when multiple properties are present they will be searched
in the order presented below and the first match is taken as the intended in the order presented below and the first match is taken as the intended
......
...@@ -41,34 +41,71 @@ In the gpiolib framework each GPIO controller is packaged as a "struct ...@@ -41,34 +41,71 @@ In the gpiolib framework each GPIO controller is packaged as a "struct
gpio_chip" (see linux/gpio/driver.h for its complete definition) with members gpio_chip" (see linux/gpio/driver.h for its complete definition) with members
common to each controller of that type: common to each controller of that type:
- methods to establish GPIO direction - methods to establish GPIO line direction
- methods used to access GPIO values - methods used to access GPIO line values
- method to return the IRQ number associated to a given GPIO - method to set electrical configuration to a a given GPIO line
- method to return the IRQ number associated to a given GPIO line
- flag saying whether calls to its methods may sleep - flag saying whether calls to its methods may sleep
- optional line names array to identify lines
- optional debugfs dump method (showing extra state like pullup config) - optional debugfs dump method (showing extra state like pullup config)
- optional base number (will be automatically assigned if omitted) - optional base number (will be automatically assigned if omitted)
- label for diagnostics and GPIOs mapping using platform data - optional label for diagnostics and GPIO chip mapping using platform data
The code implementing a gpio_chip should support multiple instances of the The code implementing a gpio_chip should support multiple instances of the
controller, possibly using the driver model. That code will configure each controller, possibly using the driver model. That code will configure each
gpio_chip and issue gpiochip_add(). Removing a GPIO controller should be rare; gpio_chip and issue gpiochip_add[_data]() or devm_gpiochip_add_data().
use gpiochip_remove() when it is unavoidable. Removing a GPIO controller should be rare; use [devm_]gpiochip_remove() when
it is unavoidable.
Most often a gpio_chip is part of an instance-specific structure with state not Often a gpio_chip is part of an instance-specific structure with states not
exposed by the GPIO interfaces, such as addressing, power management, and more. exposed by the GPIO interfaces, such as addressing, power management, and more.
Chips such as codecs will have complex non-GPIO state. Chips such as audio codecs will have complex non-GPIO states.
Any debugfs dump method should normally ignore signals which haven't been Any debugfs dump method should normally ignore signals which haven't been
requested as GPIOs. They can use gpiochip_is_requested(), which returns either requested as GPIOs. They can use gpiochip_is_requested(), which returns either
NULL or the label associated with that GPIO when it was requested. NULL or the label associated with that GPIO when it was requested.
RT_FULL: GPIO driver should not use spinlock_t or any sleepable APIs RT_FULL: the GPIO driver should not use spinlock_t or any sleepable APIs
(like PM runtime) in its gpio_chip implementation (.get/.set and direction (like PM runtime) in its gpio_chip implementation (.get/.set and direction
control callbacks) if it is expected to call GPIO APIs from atomic context control callbacks) if it is expected to call GPIO APIs from atomic context
on -RT (inside hard IRQ handlers and similar contexts). Normally this should on -RT (inside hard IRQ handlers and similar contexts). Normally this should
not be required. not be required.
GPIO electrical configuration
-----------------------------
GPIOs can be configured for several electrical modes of operation by using the
.set_config() callback. Currently this API supports setting debouncing and
single-ended modes (open drain/open source). These settings are described
below.
The .set_config() callback uses the same enumerators and configuration
semantics as the generic pin control drivers. This is not a coincidence: it is
possible to assign the .set_config() to the function gpiochip_generic_config()
which will result in pinctrl_gpio_set_config() being called and eventually
ending up in the pin control back-end "behind" the GPIO controller, usually
closer to the actual pins. This way the pin controller can manage the below
listed GPIO configurations.
GPIOs with debounce support
---------------------------
Debouncing is a configuration set to a pin indicating that it is connected to
a mechanical switch or button, or similar that may bounce. Bouncing means the
line is pulled high/low quickly at very short intervals for mechanical
reasons. This can result in the value being unstable or irqs fireing repeatedly
unless the line is debounced.
Debouncing in practice involves setting up a timer when something happens on
the line, wait a little while and then sample the line again, so see if it
still has the same value (low or high). This could also be repeated by a clever
state machine, waiting for a line to become stable. In either case, it sets
a certain number of milliseconds for debouncing, or just "on/off" if that time
is not configurable.
GPIOs with open drain/source support GPIOs with open drain/source support
------------------------------------ ------------------------------------
......
...@@ -265,6 +265,12 @@ L: linux-iio@vger.kernel.org ...@@ -265,6 +265,12 @@ L: linux-iio@vger.kernel.org
S: Maintained S: Maintained
F: drivers/iio/counter/104-quad-8.c F: drivers/iio/counter/104-quad-8.c
ACCES PCI-IDIO-16 GPIO DRIVER
M: William Breathitt Gray <vilhelm.gray@gmail.com>
L: linux-gpio@vger.kernel.org
S: Maintained
F: drivers/gpio/gpio-pci-idio-16.c
ACENIC DRIVER ACENIC DRIVER
M: Jes Sorensen <jes@trained-monkey.org> M: Jes Sorensen <jes@trained-monkey.org>
L: linux-acenic@sunsite.dk L: linux-acenic@sunsite.dk
......
...@@ -185,6 +185,13 @@ config GPIO_ETRAXFS ...@@ -185,6 +185,13 @@ config GPIO_ETRAXFS
help help
Say yes here to support the GPIO controller on Axis ETRAX FS SoCs. Say yes here to support the GPIO controller on Axis ETRAX FS SoCs.
config GPIO_EXAR
tristate "Support for GPIO pins on XR17V352/354/358"
depends on SERIAL_8250_EXAR
help
Selecting this option will enable handling of GPIO pins present
on Exar XR17V352/354/358 chips.
config GPIO_GE_FPGA config GPIO_GE_FPGA
bool "GE FPGA based GPIO" bool "GE FPGA based GPIO"
depends on GE_FPGA depends on GE_FPGA
...@@ -197,6 +204,15 @@ config GPIO_GE_FPGA ...@@ -197,6 +204,15 @@ config GPIO_GE_FPGA
and write pin state) for GPIO implemented in a number of GE single and write pin state) for GPIO implemented in a number of GE single
board computers. board computers.
config GPIO_GEMINI
bool "Gemini GPIO"
depends on ARCH_GEMINI
depends on OF_GPIO
select GPIO_GENERIC
select GPIOLIB_IRQCHIP
help
Support for common GPIOs found in Cortina systems Gemini platforms.
config GPIO_GENERIC_PLATFORM config GPIO_GENERIC_PLATFORM
tristate "Generic memory-mapped GPIO controller support (MMIO platform device)" tristate "Generic memory-mapped GPIO controller support (MMIO platform device)"
select GPIO_GENERIC select GPIO_GENERIC
...@@ -282,6 +298,8 @@ config GPIO_MOCKUP ...@@ -282,6 +298,8 @@ config GPIO_MOCKUP
tristate "GPIO Testing Driver" tristate "GPIO Testing Driver"
depends on GPIOLIB && SYSFS depends on GPIOLIB && SYSFS
select GPIO_SYSFS select GPIO_SYSFS
select GPIOLIB_IRQCHIP
select IRQ_WORK
help help
This enables GPIO Testing driver, which provides a way to test GPIO This enables GPIO Testing driver, which provides a way to test GPIO
subsystem through sysfs(or char device) and debugfs. GPIO_SYSFS subsystem through sysfs(or char device) and debugfs. GPIO_SYSFS
...@@ -1141,6 +1159,15 @@ config GPIO_PCH ...@@ -1141,6 +1159,15 @@ config GPIO_PCH
ML7223/ML7831 is companion chip for Intel Atom E6xx series. ML7223/ML7831 is companion chip for Intel Atom E6xx series.
ML7223/ML7831 is completely compatible for Intel EG20T PCH. ML7223/ML7831 is completely compatible for Intel EG20T PCH.
config GPIO_PCI_IDIO_16
tristate "ACCES PCI-IDIO-16 GPIO support"
select GPIOLIB_IRQCHIP
help
Enables GPIO support for the ACCES PCI-IDIO-16. An interrupt is
generated when any of the inputs change state (low to high or high to
low). Input filter control is not supported by this driver, and the
input filters are deactivated by this driver.
config GPIO_RDC321X config GPIO_RDC321X
tristate "RDC R-321x GPIO support" tristate "RDC R-321x GPIO support"
select MFD_CORE select MFD_CORE
...@@ -1197,6 +1224,8 @@ config GPIO_MCP23S08 ...@@ -1197,6 +1224,8 @@ config GPIO_MCP23S08
tristate "Microchip MCP23xxx I/O expander" tristate "Microchip MCP23xxx I/O expander"
depends on OF_GPIO depends on OF_GPIO
select GPIOLIB_IRQCHIP select GPIOLIB_IRQCHIP
select REGMAP_I2C if I2C
select REGMAP if SPI_MASTER
help help
SPI/I2C driver for Microchip MCP23S08/MCP23S17/MCP23008/MCP23017 SPI/I2C driver for Microchip MCP23S08/MCP23S17/MCP23008/MCP23017
I/O expanders. I/O expanders.
......
...@@ -46,8 +46,10 @@ obj-$(CONFIG_GPIO_DWAPB) += gpio-dwapb.o ...@@ -46,8 +46,10 @@ obj-$(CONFIG_GPIO_DWAPB) += gpio-dwapb.o
obj-$(CONFIG_GPIO_EM) += gpio-em.o obj-$(CONFIG_GPIO_EM) += gpio-em.o
obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o
obj-$(CONFIG_GPIO_ETRAXFS) += gpio-etraxfs.o obj-$(CONFIG_GPIO_ETRAXFS) += gpio-etraxfs.o
obj-$(CONFIG_GPIO_EXAR) += gpio-exar.o
obj-$(CONFIG_GPIO_F7188X) += gpio-f7188x.o obj-$(CONFIG_GPIO_F7188X) += gpio-f7188x.o
obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o
obj-$(CONFIG_GPIO_GEMINI) += gpio-gemini.o
obj-$(CONFIG_GPIO_GPIO_MM) += gpio-gpio-mm.o obj-$(CONFIG_GPIO_GPIO_MM) += gpio-gpio-mm.o
obj-$(CONFIG_GPIO_GRGPIO) += gpio-grgpio.o obj-$(CONFIG_GPIO_GRGPIO) += gpio-grgpio.o
obj-$(CONFIG_HTC_EGPIO) += gpio-htc-egpio.o obj-$(CONFIG_HTC_EGPIO) += gpio-htc-egpio.o
...@@ -90,6 +92,7 @@ obj-$(CONFIG_GPIO_OMAP) += gpio-omap.o ...@@ -90,6 +92,7 @@ obj-$(CONFIG_GPIO_OMAP) += gpio-omap.o
obj-$(CONFIG_GPIO_PCA953X) += gpio-pca953x.o obj-$(CONFIG_GPIO_PCA953X) += gpio-pca953x.o
obj-$(CONFIG_GPIO_PCF857X) += gpio-pcf857x.o obj-$(CONFIG_GPIO_PCF857X) += gpio-pcf857x.o
obj-$(CONFIG_GPIO_PCH) += gpio-pch.o obj-$(CONFIG_GPIO_PCH) += gpio-pch.o
obj-$(CONFIG_GPIO_PCI_IDIO_16) += gpio-pci-idio-16.o
obj-$(CONFIG_GPIO_PISOSR) += gpio-pisosr.o obj-$(CONFIG_GPIO_PISOSR) += gpio-pisosr.o
obj-$(CONFIG_GPIO_PL061) += gpio-pl061.o obj-$(CONFIG_GPIO_PL061) += gpio-pl061.o
obj-$(CONFIG_GPIO_PXA) += gpio-pxa.o obj-$(CONFIG_GPIO_PXA) += gpio-pxa.o
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* This file is based on kernel/irq/devres.c * This file is based on kernel/irq/devres.c
* *
* Copyright (c) 2011 John Crispin <blogic@openwrt.org> * Copyright (c) 2011 John Crispin <john@phrozen.org>
*/ */
#include <linux/module.h> #include <linux/module.h>
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/gfp.h> #include <linux/gfp.h>
#include "gpiolib.h"
static void devm_gpiod_release(struct device *dev, void *res) static void devm_gpiod_release(struct device *dev, void *res)
{ {
struct gpio_desc **desc = res; struct gpio_desc **desc = res;
...@@ -123,19 +125,26 @@ struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, ...@@ -123,19 +125,26 @@ struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
EXPORT_SYMBOL(devm_gpiod_get_index); EXPORT_SYMBOL(devm_gpiod_get_index);
/** /**
* devm_get_gpiod_from_child - get a GPIO descriptor from a device's child node * devm_fwnode_get_index_gpiod_from_child - get a GPIO descriptor from a
* device's child node
* @dev: GPIO consumer * @dev: GPIO consumer
* @con_id: function within the GPIO consumer * @con_id: function within the GPIO consumer
* @index: index of the GPIO to obtain in the consumer
* @child: firmware node (child of @dev) * @child: firmware node (child of @dev)
* @flags: GPIO initialization flags
* *
* GPIO descriptors returned from this function are automatically disposed on * GPIO descriptors returned from this function are automatically disposed on
* driver detach. * driver detach.
*
* On successfull request the GPIO pin is configured in accordance with
* provided @flags.
*/ */
struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
const char *con_id, const char *con_id, int index,
struct fwnode_handle *child) struct fwnode_handle *child,
enum gpiod_flags flags,
const char *label)
{ {
static const char * const suffixes[] = { "gpios", "gpio" };
char prop_name[32]; /* 32 is max size of property name */ char prop_name[32]; /* 32 is max size of property name */
struct gpio_desc **dr; struct gpio_desc **dr;
struct gpio_desc *desc; struct gpio_desc *desc;
...@@ -146,15 +155,16 @@ struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, ...@@ -146,15 +155,16 @@ struct gpio_desc *devm_get_gpiod_from_child(struct device *dev,
if (!dr) if (!dr)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
for (i = 0; i < ARRAY_SIZE(suffixes); i++) { for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
if (con_id) if (con_id)
snprintf(prop_name, sizeof(prop_name), "%s-%s", snprintf(prop_name, sizeof(prop_name), "%s-%s",
con_id, suffixes[i]); con_id, gpio_suffixes[i]);
else else
snprintf(prop_name, sizeof(prop_name), "%s", snprintf(prop_name, sizeof(prop_name), "%s",
suffixes[i]); gpio_suffixes[i]);
desc = fwnode_get_named_gpiod(child, prop_name); desc = fwnode_get_named_gpiod(child, prop_name, index, flags,
label);
if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT)) if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT))
break; break;
} }
...@@ -168,7 +178,7 @@ struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, ...@@ -168,7 +178,7 @@ struct gpio_desc *devm_get_gpiod_from_child(struct device *dev,
return desc; return desc;
} }
EXPORT_SYMBOL(devm_get_gpiod_from_child); EXPORT_SYMBOL(devm_fwnode_get_index_gpiod_from_child);
/** /**
* devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional() * devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional()
......
...@@ -48,7 +48,6 @@ MODULE_PARM_DESC(irq, "ACCES 104-DIO-48E interrupt line numbers"); ...@@ -48,7 +48,6 @@ MODULE_PARM_DESC(irq, "ACCES 104-DIO-48E interrupt line numbers");
* @control: Control registers state * @control: Control registers state
* @lock: synchronization lock to prevent I/O race conditions * @lock: synchronization lock to prevent I/O race conditions
* @base: base port address of the GPIO device * @base: base port address of the GPIO device
* @irq: Interrupt line number
* @irq_mask: I/O bits affected by interrupts * @irq_mask: I/O bits affected by interrupts
*/ */
struct dio48e_gpio { struct dio48e_gpio {
...@@ -58,7 +57,6 @@ struct dio48e_gpio { ...@@ -58,7 +57,6 @@ struct dio48e_gpio {
unsigned char control[2]; unsigned char control[2];
spinlock_t lock; spinlock_t lock;
unsigned base; unsigned base;
unsigned irq;
unsigned char irq_mask; unsigned char irq_mask;
}; };
...@@ -204,6 +202,44 @@ static void dio48e_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ...@@ -204,6 +202,44 @@ static void dio48e_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
spin_unlock_irqrestore(&dio48egpio->lock, flags); spin_unlock_irqrestore(&dio48egpio->lock, flags);
} }
static void dio48e_gpio_set_multiple(struct gpio_chip *chip,
unsigned long *mask, unsigned long *bits)
{
struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
unsigned int i;
const unsigned int gpio_reg_size = 8;
unsigned int port;
unsigned int out_port;
unsigned int bitmask;
unsigned long flags;
/* set bits are evaluated a gpio register size at a time */
for (i = 0; i < chip->ngpio; i += gpio_reg_size) {
/* no more set bits in this mask word; skip to the next word */
if (!mask[BIT_WORD(i)]) {
i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size;
continue;
}
port = i / gpio_reg_size;
out_port = (port > 2) ? port + 1 : port;
bitmask = mask[BIT_WORD(i)] & bits[BIT_WORD(i)];
spin_lock_irqsave(&dio48egpio->lock, flags);
/* update output state data and set device gpio register */
dio48egpio->out_state[port] &= ~mask[BIT_WORD(i)];
dio48egpio->out_state[port] |= bitmask;
outb(dio48egpio->out_state[port], dio48egpio->base + out_port);
spin_unlock_irqrestore(&dio48egpio->lock, flags);
/* prepare for next gpio register set */
mask[BIT_WORD(i)] >>= gpio_reg_size;
bits[BIT_WORD(i)] >>= gpio_reg_size;
}
}
static void dio48e_irq_ack(struct irq_data *data) static void dio48e_irq_ack(struct irq_data *data)
{ {
} }
...@@ -302,6 +338,26 @@ static irqreturn_t dio48e_irq_handler(int irq, void *dev_id) ...@@ -302,6 +338,26 @@ static irqreturn_t dio48e_irq_handler(int irq, void *dev_id)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
#define DIO48E_NGPIO 48
static const char *dio48e_names[DIO48E_NGPIO] = {
"PPI Group 0 Port A 0", "PPI Group 0 Port A 1", "PPI Group 0 Port A 2",
"PPI Group 0 Port A 3", "PPI Group 0 Port A 4", "PPI Group 0 Port A 5",
"PPI Group 0 Port A 6", "PPI Group 0 Port A 7", "PPI Group 0 Port B 0",
"PPI Group 0 Port B 1", "PPI Group 0 Port B 2", "PPI Group 0 Port B 3",
"PPI Group 0 Port B 4", "PPI Group 0 Port B 5", "PPI Group 0 Port B 6",
"PPI Group 0 Port B 7", "PPI Group 0 Port C 0", "PPI Group 0 Port C 1",
"PPI Group 0 Port C 2", "PPI Group 0 Port C 3", "PPI Group 0 Port C 4",
"PPI Group 0 Port C 5", "PPI Group 0 Port C 6", "PPI Group 0 Port C 7",
"PPI Group 1 Port A 0", "PPI Group 1 Port A 1", "PPI Group 1 Port A 2",
"PPI Group 1 Port A 3", "PPI Group 1 Port A 4", "PPI Group 1 Port A 5",
"PPI Group 1 Port A 6", "PPI Group 1 Port A 7", "PPI Group 1 Port B 0",
"PPI Group 1 Port B 1", "PPI Group 1 Port B 2", "PPI Group 1 Port B 3",
"PPI Group 1 Port B 4", "PPI Group 1 Port B 5", "PPI Group 1 Port B 6",
"PPI Group 1 Port B 7", "PPI Group 1 Port C 0", "PPI Group 1 Port C 1",
"PPI Group 1 Port C 2", "PPI Group 1 Port C 3", "PPI Group 1 Port C 4",
"PPI Group 1 Port C 5", "PPI Group 1 Port C 6", "PPI Group 1 Port C 7"
};
static int dio48e_probe(struct device *dev, unsigned int id) static int dio48e_probe(struct device *dev, unsigned int id)
{ {
struct dio48e_gpio *dio48egpio; struct dio48e_gpio *dio48egpio;
...@@ -322,20 +378,19 @@ static int dio48e_probe(struct device *dev, unsigned int id) ...@@ -322,20 +378,19 @@ static int dio48e_probe(struct device *dev, unsigned int id)
dio48egpio->chip.parent = dev; dio48egpio->chip.parent = dev;
dio48egpio->chip.owner = THIS_MODULE; dio48egpio->chip.owner = THIS_MODULE;
dio48egpio->chip.base = -1; dio48egpio->chip.base = -1;
dio48egpio->chip.ngpio = 48; dio48egpio->chip.ngpio = DIO48E_NGPIO;
dio48egpio->chip.names = dio48e_names;
dio48egpio->chip.get_direction = dio48e_gpio_get_direction; dio48egpio->chip.get_direction = dio48e_gpio_get_direction;
dio48egpio->chip.direction_input = dio48e_gpio_direction_input; dio48egpio->chip.direction_input = dio48e_gpio_direction_input;
dio48egpio->chip.direction_output = dio48e_gpio_direction_output; dio48egpio->chip.direction_output = dio48e_gpio_direction_output;
dio48egpio->chip.get = dio48e_gpio_get; dio48egpio->chip.get = dio48e_gpio_get;
dio48egpio->chip.set = dio48e_gpio_set; dio48egpio->chip.set = dio48e_gpio_set;
dio48egpio->chip.set_multiple = dio48e_gpio_set_multiple;
dio48egpio->base = base[id]; dio48egpio->base = base[id];
dio48egpio->irq = irq[id];
spin_lock_init(&dio48egpio->lock); spin_lock_init(&dio48egpio->lock);
dev_set_drvdata(dev, dio48egpio); err = devm_gpiochip_add_data(dev, &dio48egpio->chip, dio48egpio);
err = gpiochip_add_data(&dio48egpio->chip, dio48egpio);
if (err) { if (err) {
dev_err(dev, "GPIO registering failed (%d)\n", err); dev_err(dev, "GPIO registering failed (%d)\n", err);
return err; return err;
...@@ -360,28 +415,15 @@ static int dio48e_probe(struct device *dev, unsigned int id) ...@@ -360,28 +415,15 @@ static int dio48e_probe(struct device *dev, unsigned int id)
handle_edge_irq, IRQ_TYPE_NONE); handle_edge_irq, IRQ_TYPE_NONE);
if (err) { if (err) {
dev_err(dev, "Could not add irqchip (%d)\n", err); dev_err(dev, "Could not add irqchip (%d)\n", err);
goto err_gpiochip_remove; return err;
} }
err = request_irq(irq[id], dio48e_irq_handler, 0, name, dio48egpio); err = devm_request_irq(dev, irq[id], dio48e_irq_handler, 0, name,
dio48egpio);
if (err) { if (err) {
dev_err(dev, "IRQ handler registering failed (%d)\n", err); dev_err(dev, "IRQ handler registering failed (%d)\n", err);
goto err_gpiochip_remove;
}
return 0;
err_gpiochip_remove:
gpiochip_remove(&dio48egpio->chip);
return err; return err;
} }
static int dio48e_remove(struct device *dev, unsigned int id)
{
struct dio48e_gpio *const dio48egpio = dev_get_drvdata(dev);
free_irq(dio48egpio->irq, dio48egpio);
gpiochip_remove(&dio48egpio->chip);
return 0; return 0;
} }
...@@ -391,7 +433,6 @@ static struct isa_driver dio48e_driver = { ...@@ -391,7 +433,6 @@ static struct isa_driver dio48e_driver = {
.driver = { .driver = {
.name = "104-dio-48e" .name = "104-dio-48e"
}, },
.remove = dio48e_remove
}; };
module_isa_driver(dio48e_driver, num_dio48e); module_isa_driver(dio48e_driver, num_dio48e);
......
...@@ -47,7 +47,6 @@ MODULE_PARM_DESC(irq, "ACCES 104-IDI-48 interrupt line numbers"); ...@@ -47,7 +47,6 @@ MODULE_PARM_DESC(irq, "ACCES 104-IDI-48 interrupt line numbers");
* @ack_lock: synchronization lock to prevent IRQ handler race conditions * @ack_lock: synchronization lock to prevent IRQ handler race conditions
* @irq_mask: input bits affected by interrupts * @irq_mask: input bits affected by interrupts
* @base: base port address of the GPIO device * @base: base port address of the GPIO device
* @irq: Interrupt line number
* @cos_enb: Change-Of-State IRQ enable boundaries mask * @cos_enb: Change-Of-State IRQ enable boundaries mask
*/ */
struct idi_48_gpio { struct idi_48_gpio {
...@@ -56,7 +55,6 @@ struct idi_48_gpio { ...@@ -56,7 +55,6 @@ struct idi_48_gpio {
spinlock_t ack_lock; spinlock_t ack_lock;
unsigned char irq_mask[6]; unsigned char irq_mask[6];
unsigned base; unsigned base;
unsigned irq;
unsigned char cos_enb; unsigned char cos_enb;
}; };
...@@ -219,6 +217,18 @@ static irqreturn_t idi_48_irq_handler(int irq, void *dev_id) ...@@ -219,6 +217,18 @@ static irqreturn_t idi_48_irq_handler(int irq, void *dev_id)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
#define IDI48_NGPIO 48
static const char *idi48_names[IDI48_NGPIO] = {
"Bit 0 A", "Bit 1 A", "Bit 2 A", "Bit 3 A", "Bit 4 A", "Bit 5 A",
"Bit 6 A", "Bit 7 A", "Bit 8 A", "Bit 9 A", "Bit 10 A", "Bit 11 A",
"Bit 12 A", "Bit 13 A", "Bit 14 A", "Bit 15 A", "Bit 16 A", "Bit 17 A",
"Bit 18 A", "Bit 19 A", "Bit 20 A", "Bit 21 A", "Bit 22 A", "Bit 23 A",
"Bit 0 B", "Bit 1 B", "Bit 2 B", "Bit 3 B", "Bit 4 B", "Bit 5 B",
"Bit 6 B", "Bit 7 B", "Bit 8 B", "Bit 9 B", "Bit 10 B", "Bit 11 B",
"Bit 12 B", "Bit 13 B", "Bit 14 B", "Bit 15 B", "Bit 16 B", "Bit 17 B",
"Bit 18 B", "Bit 19 B", "Bit 20 B", "Bit 21 B", "Bit 22 B", "Bit 23 B"
};
static int idi_48_probe(struct device *dev, unsigned int id) static int idi_48_probe(struct device *dev, unsigned int id)
{ {
struct idi_48_gpio *idi48gpio; struct idi_48_gpio *idi48gpio;
...@@ -239,19 +249,17 @@ static int idi_48_probe(struct device *dev, unsigned int id) ...@@ -239,19 +249,17 @@ static int idi_48_probe(struct device *dev, unsigned int id)
idi48gpio->chip.parent = dev; idi48gpio->chip.parent = dev;
idi48gpio->chip.owner = THIS_MODULE; idi48gpio->chip.owner = THIS_MODULE;
idi48gpio->chip.base = -1; idi48gpio->chip.base = -1;
idi48gpio->chip.ngpio = 48; idi48gpio->chip.ngpio = IDI48_NGPIO;
idi48gpio->chip.names = idi48_names;
idi48gpio->chip.get_direction = idi_48_gpio_get_direction; idi48gpio->chip.get_direction = idi_48_gpio_get_direction;
idi48gpio->chip.direction_input = idi_48_gpio_direction_input; idi48gpio->chip.direction_input = idi_48_gpio_direction_input;
idi48gpio->chip.get = idi_48_gpio_get; idi48gpio->chip.get = idi_48_gpio_get;
idi48gpio->base = base[id]; idi48gpio->base = base[id];
idi48gpio->irq = irq[id];
spin_lock_init(&idi48gpio->lock); spin_lock_init(&idi48gpio->lock);
spin_lock_init(&idi48gpio->ack_lock); spin_lock_init(&idi48gpio->ack_lock);
dev_set_drvdata(dev, idi48gpio); err = devm_gpiochip_add_data(dev, &idi48gpio->chip, idi48gpio);
err = gpiochip_add_data(&idi48gpio->chip, idi48gpio);
if (err) { if (err) {
dev_err(dev, "GPIO registering failed (%d)\n", err); dev_err(dev, "GPIO registering failed (%d)\n", err);
return err; return err;
...@@ -265,29 +273,15 @@ static int idi_48_probe(struct device *dev, unsigned int id) ...@@ -265,29 +273,15 @@ static int idi_48_probe(struct device *dev, unsigned int id)
handle_edge_irq, IRQ_TYPE_NONE); handle_edge_irq, IRQ_TYPE_NONE);
if (err) { if (err) {
dev_err(dev, "Could not add irqchip (%d)\n", err); dev_err(dev, "Could not add irqchip (%d)\n", err);
goto err_gpiochip_remove; return err;
} }
err = request_irq(irq[id], idi_48_irq_handler, IRQF_SHARED, name, err = devm_request_irq(dev, irq[id], idi_48_irq_handler, IRQF_SHARED,
idi48gpio); name, idi48gpio);
if (err) { if (err) {
dev_err(dev, "IRQ handler registering failed (%d)\n", err); dev_err(dev, "IRQ handler registering failed (%d)\n", err);
goto err_gpiochip_remove;
}
return 0;
err_gpiochip_remove:
gpiochip_remove(&idi48gpio->chip);
return err; return err;
} }
static int idi_48_remove(struct device *dev, unsigned int id)
{
struct idi_48_gpio *const idi48gpio = dev_get_drvdata(dev);
free_irq(idi48gpio->irq, idi48gpio);
gpiochip_remove(&idi48gpio->chip);
return 0; return 0;
} }
...@@ -297,7 +291,6 @@ static struct isa_driver idi_48_driver = { ...@@ -297,7 +291,6 @@ static struct isa_driver idi_48_driver = {
.driver = { .driver = {
.name = "104-idi-48" .name = "104-idi-48"
}, },
.remove = idi_48_remove
}; };
module_isa_driver(idi_48_driver, num_idi_48); module_isa_driver(idi_48_driver, num_idi_48);
......
...@@ -46,7 +46,6 @@ MODULE_PARM_DESC(irq, "ACCES 104-IDIO-16 interrupt line numbers"); ...@@ -46,7 +46,6 @@ MODULE_PARM_DESC(irq, "ACCES 104-IDIO-16 interrupt line numbers");
* @lock: synchronization lock to prevent I/O race conditions * @lock: synchronization lock to prevent I/O race conditions
* @irq_mask: I/O bits affected by interrupts * @irq_mask: I/O bits affected by interrupts
* @base: base port address of the GPIO device * @base: base port address of the GPIO device
* @irq: Interrupt line number
* @out_state: output bits state * @out_state: output bits state
*/ */
struct idio_16_gpio { struct idio_16_gpio {
...@@ -54,7 +53,6 @@ struct idio_16_gpio { ...@@ -54,7 +53,6 @@ struct idio_16_gpio {
spinlock_t lock; spinlock_t lock;
unsigned long irq_mask; unsigned long irq_mask;
unsigned base; unsigned base;
unsigned irq;
unsigned out_state; unsigned out_state;
}; };
...@@ -116,6 +114,25 @@ static void idio_16_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ...@@ -116,6 +114,25 @@ static void idio_16_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
spin_unlock_irqrestore(&idio16gpio->lock, flags); spin_unlock_irqrestore(&idio16gpio->lock, flags);
} }
static void idio_16_gpio_set_multiple(struct gpio_chip *chip,
unsigned long *mask, unsigned long *bits)
{
struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
unsigned long flags;
spin_lock_irqsave(&idio16gpio->lock, flags);
idio16gpio->out_state &= ~*mask;
idio16gpio->out_state |= *mask & *bits;
if (*mask & 0xFF)
outb(idio16gpio->out_state, idio16gpio->base);
if ((*mask >> 8) & 0xFF)
outb(idio16gpio->out_state >> 8, idio16gpio->base + 4);
spin_unlock_irqrestore(&idio16gpio->lock, flags);
}
static void idio_16_irq_ack(struct irq_data *data) static void idio_16_irq_ack(struct irq_data *data)
{ {
} }
...@@ -193,6 +210,14 @@ static irqreturn_t idio_16_irq_handler(int irq, void *dev_id) ...@@ -193,6 +210,14 @@ static irqreturn_t idio_16_irq_handler(int irq, void *dev_id)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
#define IDIO_16_NGPIO 32
static const char *idio_16_names[IDIO_16_NGPIO] = {
"OUT0", "OUT1", "OUT2", "OUT3", "OUT4", "OUT5", "OUT6", "OUT7",
"OUT8", "OUT9", "OUT10", "OUT11", "OUT12", "OUT13", "OUT14", "OUT15",
"IIN0", "IIN1", "IIN2", "IIN3", "IIN4", "IIN5", "IIN6", "IIN7",
"IIN8", "IIN9", "IIN10", "IIN11", "IIN12", "IIN13", "IIN14", "IIN15"
};
static int idio_16_probe(struct device *dev, unsigned int id) static int idio_16_probe(struct device *dev, unsigned int id)
{ {
struct idio_16_gpio *idio16gpio; struct idio_16_gpio *idio16gpio;
...@@ -213,21 +238,20 @@ static int idio_16_probe(struct device *dev, unsigned int id) ...@@ -213,21 +238,20 @@ static int idio_16_probe(struct device *dev, unsigned int id)
idio16gpio->chip.parent = dev; idio16gpio->chip.parent = dev;
idio16gpio->chip.owner = THIS_MODULE; idio16gpio->chip.owner = THIS_MODULE;
idio16gpio->chip.base = -1; idio16gpio->chip.base = -1;
idio16gpio->chip.ngpio = 32; idio16gpio->chip.ngpio = IDIO_16_NGPIO;
idio16gpio->chip.names = idio_16_names;
idio16gpio->chip.get_direction = idio_16_gpio_get_direction; idio16gpio->chip.get_direction = idio_16_gpio_get_direction;
idio16gpio->chip.direction_input = idio_16_gpio_direction_input; idio16gpio->chip.direction_input = idio_16_gpio_direction_input;
idio16gpio->chip.direction_output = idio_16_gpio_direction_output; idio16gpio->chip.direction_output = idio_16_gpio_direction_output;
idio16gpio->chip.get = idio_16_gpio_get; idio16gpio->chip.get = idio_16_gpio_get;
idio16gpio->chip.set = idio_16_gpio_set; idio16gpio->chip.set = idio_16_gpio_set;
idio16gpio->chip.set_multiple = idio_16_gpio_set_multiple;
idio16gpio->base = base[id]; idio16gpio->base = base[id];
idio16gpio->irq = irq[id];
idio16gpio->out_state = 0xFFFF; idio16gpio->out_state = 0xFFFF;
spin_lock_init(&idio16gpio->lock); spin_lock_init(&idio16gpio->lock);
dev_set_drvdata(dev, idio16gpio); err = devm_gpiochip_add_data(dev, &idio16gpio->chip, idio16gpio);
err = gpiochip_add_data(&idio16gpio->chip, idio16gpio);
if (err) { if (err) {
dev_err(dev, "GPIO registering failed (%d)\n", err); dev_err(dev, "GPIO registering failed (%d)\n", err);
return err; return err;
...@@ -241,28 +265,15 @@ static int idio_16_probe(struct device *dev, unsigned int id) ...@@ -241,28 +265,15 @@ static int idio_16_probe(struct device *dev, unsigned int id)
handle_edge_irq, IRQ_TYPE_NONE); handle_edge_irq, IRQ_TYPE_NONE);
if (err) { if (err) {
dev_err(dev, "Could not add irqchip (%d)\n", err); dev_err(dev, "Could not add irqchip (%d)\n", err);
goto err_gpiochip_remove; return err;
} }
err = request_irq(irq[id], idio_16_irq_handler, 0, name, idio16gpio); err = devm_request_irq(dev, irq[id], idio_16_irq_handler, 0, name,
idio16gpio);
if (err) { if (err) {
dev_err(dev, "IRQ handler registering failed (%d)\n", err); dev_err(dev, "IRQ handler registering failed (%d)\n", err);
goto err_gpiochip_remove;
}
return 0;
err_gpiochip_remove:
gpiochip_remove(&idio16gpio->chip);
return err; return err;
} }
static int idio_16_remove(struct device *dev, unsigned int id)
{
struct idio_16_gpio *const idio16gpio = dev_get_drvdata(dev);
free_irq(idio16gpio->irq, idio16gpio);
gpiochip_remove(&idio16gpio->chip);
return 0; return 0;
} }
...@@ -272,7 +283,6 @@ static struct isa_driver idio_16_driver = { ...@@ -272,7 +283,6 @@ static struct isa_driver idio_16_driver = {
.driver = { .driver = {
.name = "104-idio-16" .name = "104-idio-16"
}, },
.remove = idio_16_remove
}; };
module_isa_driver(idio_16_driver, num_idio_16); module_isa_driver(idio_16_driver, num_idio_16);
......
This diff is collapsed.
/*
* GPIO driver for Exar XR17V35X chip
*
* Copyright (C) 2015 Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
*
* 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/bitops.h>
#include <linux/device.h>
#include <linux/gpio/driver.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/platform_device.h>
#define EXAR_OFFSET_MPIOLVL_LO 0x90
#define EXAR_OFFSET_MPIOSEL_LO 0x93
#define EXAR_OFFSET_MPIOLVL_HI 0x96
#define EXAR_OFFSET_MPIOSEL_HI 0x99
#define DRIVER_NAME "gpio_exar"
static DEFINE_IDA(ida_index);
struct exar_gpio_chip {
struct gpio_chip gpio_chip;
struct mutex lock;
int index;
void __iomem *regs;
char name[20];
};
static void exar_update(struct gpio_chip *chip, unsigned int reg, int val,
unsigned int offset)
{
struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip);
int temp;
mutex_lock(&exar_gpio->lock);
temp = readb(exar_gpio->regs + reg);
temp &= ~BIT(offset);
if (val)
temp |= BIT(offset);
writeb(temp, exar_gpio->regs + reg);
mutex_unlock(&exar_gpio->lock);
}
static int exar_set_direction(struct gpio_chip *chip, int direction,
unsigned int offset)
{
unsigned int bank = offset / 8;
unsigned int addr;
addr = bank ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO;
exar_update(chip, addr, direction, offset % 8);
return 0;
}
static int exar_direction_output(struct gpio_chip *chip, unsigned int offset,
int value)
{
return exar_set_direction(chip, 0, offset);
}
static int exar_direction_input(struct gpio_chip *chip, unsigned int offset)
{
return exar_set_direction(chip, 1, offset);
}
static int exar_get(struct gpio_chip *chip, unsigned int reg)
{
struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip);
int value;
mutex_lock(&exar_gpio->lock);
value = readb(exar_gpio->regs + reg);
mutex_unlock(&exar_gpio->lock);
return !!value;
}
static int exar_get_direction(struct gpio_chip *chip, unsigned int offset)
{
unsigned int bank = offset / 8;
unsigned int addr;
int val;
addr = bank ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO;
val = exar_get(chip, addr) >> (offset % 8);
return !!val;
}
static int exar_get_value(struct gpio_chip *chip, unsigned int offset)
{
unsigned int bank = offset / 8;
unsigned int addr;
int val;
addr = bank ? EXAR_OFFSET_MPIOLVL_LO : EXAR_OFFSET_MPIOLVL_HI;
val = exar_get(chip, addr) >> (offset % 8);
return !!val;
}
static void exar_set_value(struct gpio_chip *chip, unsigned int offset,
int value)
{
unsigned int bank = offset / 8;
unsigned int addr;
addr = bank ? EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO;
exar_update(chip, addr, value, offset % 8);
}
static int gpio_exar_probe(struct platform_device *pdev)
{
struct pci_dev *pcidev = platform_get_drvdata(pdev);
struct exar_gpio_chip *exar_gpio;
void __iomem *p;
int index, ret;
if (pcidev->vendor != PCI_VENDOR_ID_EXAR)
return -ENODEV;
/*
* Map the pci device to get the register addresses.
* We will need to read and write those registers to control
* the GPIO pins.
* Using managed functions will save us from unmaping on exit.
* As the device is enabled using managed functions by the
* UART driver we can also use managed functions here.
*/
p = pcim_iomap(pcidev, 0, 0);
if (!p)
return -ENOMEM;
exar_gpio = devm_kzalloc(&pcidev->dev, sizeof(*exar_gpio), GFP_KERNEL);
if (!exar_gpio)
return -ENOMEM;
mutex_init(&exar_gpio->lock);
index = ida_simple_get(&ida_index, 0, 0, GFP_KERNEL);
sprintf(exar_gpio->name, "exar_gpio%d", index);
exar_gpio->gpio_chip.label = exar_gpio->name;
exar_gpio->gpio_chip.parent = &pcidev->dev;
exar_gpio->gpio_chip.direction_output = exar_direction_output;
exar_gpio->gpio_chip.direction_input = exar_direction_input;
exar_gpio->gpio_chip.get_direction = exar_get_direction;
exar_gpio->gpio_chip.get = exar_get_value;
exar_gpio->gpio_chip.set = exar_set_value;
exar_gpio->gpio_chip.base = -1;
exar_gpio->gpio_chip.ngpio = 16;
exar_gpio->regs = p;
exar_gpio->index = index;
ret = devm_gpiochip_add_data(&pcidev->dev,
&exar_gpio->gpio_chip, exar_gpio);
if (ret)
goto err_destroy;
platform_set_drvdata(pdev, exar_gpio);
return 0;
err_destroy:
ida_simple_remove(&ida_index, index);
mutex_destroy(&exar_gpio->lock);
return ret;
}
static int gpio_exar_remove(struct platform_device *pdev)
{
struct exar_gpio_chip *exar_gpio = platform_get_drvdata(pdev);
ida_simple_remove(&ida_index, exar_gpio->index);
mutex_destroy(&exar_gpio->lock);
return 0;
}
static struct platform_driver gpio_exar_driver = {
.probe = gpio_exar_probe,
.remove = gpio_exar_remove,
.driver = {
.name = DRIVER_NAME,
},
};
module_platform_driver(gpio_exar_driver);
MODULE_ALIAS("platform:" DRIVER_NAME);
MODULE_DESCRIPTION("Exar GPIO driver");
MODULE_AUTHOR("Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>");
MODULE_LICENSE("GPL");
/*
* Gemini gpiochip and interrupt routines
* Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
*
* Based on arch/arm/mach-gemini/gpio.c:
* Copyright (C) 2008-2009 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
*
* Based on plat-mxc/gpio.c:
* MXC GPIO support. (c) 2008 Daniel Mack <daniel@caiaq.de>
* Copyright 2008 Juergen Beisert, kernel@pengutronix.de
*/
#include <linux/gpio/driver.h>
#include <linux/io.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/of_gpio.h>
#include <linux/bitops.h>
/* GPIO registers definition */
#define GPIO_DATA_OUT 0x00
#define GPIO_DATA_IN 0x04
#define GPIO_DIR 0x08
#define GPIO_DATA_SET 0x10
#define GPIO_DATA_CLR 0x14
#define GPIO_PULL_EN 0x18
#define GPIO_PULL_TYPE 0x1C
#define GPIO_INT_EN 0x20
#define GPIO_INT_STAT 0x24
#define GPIO_INT_MASK 0x2C
#define GPIO_INT_CLR 0x30
#define GPIO_INT_TYPE 0x34
#define GPIO_INT_BOTH_EDGE 0x38
#define GPIO_INT_LEVEL 0x3C
#define GPIO_DEBOUNCE_EN 0x40
#define GPIO_DEBOUNCE_PRESCALE 0x44
/**
* struct gemini_gpio - Gemini GPIO state container
* @dev: containing device for this instance
* @gc: gpiochip for this instance
*/
struct gemini_gpio {
struct device *dev;
struct gpio_chip gc;
void __iomem *base;
};
static void gemini_gpio_ack_irq(struct irq_data *d)
{
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct gemini_gpio *g = gpiochip_get_data(gc);
writel(BIT(irqd_to_hwirq(d)), g->base + GPIO_INT_CLR);
}
static void gemini_gpio_mask_irq(struct irq_data *d)
{
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct gemini_gpio *g = gpiochip_get_data(gc);
u32 val;
val = readl(g->base + GPIO_INT_EN);
val &= ~BIT(irqd_to_hwirq(d));
writel(val, g->base + GPIO_INT_EN);
}
static void gemini_gpio_unmask_irq(struct irq_data *d)
{
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct gemini_gpio *g = gpiochip_get_data(gc);
u32 val;
val = readl(g->base + GPIO_INT_EN);
val |= BIT(irqd_to_hwirq(d));
writel(val, g->base + GPIO_INT_EN);
}
static int gemini_gpio_set_irq_type(struct irq_data *d, unsigned int type)
{
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct gemini_gpio *g = gpiochip_get_data(gc);
u32 mask = BIT(irqd_to_hwirq(d));
u32 reg_both, reg_level, reg_type;
reg_type = readl(g->base + GPIO_INT_TYPE);
reg_level = readl(g->base + GPIO_INT_LEVEL);
reg_both = readl(g->base + GPIO_INT_BOTH_EDGE);
switch (type) {
case IRQ_TYPE_EDGE_BOTH:
irq_set_handler_locked(d, handle_edge_irq);
reg_type &= ~mask;
reg_both |= mask;
break;
case IRQ_TYPE_EDGE_RISING:
irq_set_handler_locked(d, handle_edge_irq);
reg_type &= ~mask;
reg_both &= ~mask;
reg_level &= ~mask;
break;
case IRQ_TYPE_EDGE_FALLING:
irq_set_handler_locked(d, handle_edge_irq);
reg_type &= ~mask;
reg_both &= ~mask;
reg_level |= mask;
break;
case IRQ_TYPE_LEVEL_HIGH:
irq_set_handler_locked(d, handle_level_irq);
reg_type |= mask;
reg_level &= ~mask;
break;
case IRQ_TYPE_LEVEL_LOW:
irq_set_handler_locked(d, handle_level_irq);
reg_type |= mask;
reg_level |= mask;
break;
default:
irq_set_handler_locked(d, handle_bad_irq);
return -EINVAL;
}
writel(reg_type, g->base + GPIO_INT_TYPE);
writel(reg_level, g->base + GPIO_INT_LEVEL);
writel(reg_both, g->base + GPIO_INT_BOTH_EDGE);
gemini_gpio_ack_irq(d);
return 0;
}
static struct irq_chip gemini_gpio_irqchip = {
.name = "GPIO",
.irq_ack = gemini_gpio_ack_irq,
.irq_mask = gemini_gpio_mask_irq,
.irq_unmask = gemini_gpio_unmask_irq,
.irq_set_type = gemini_gpio_set_irq_type,
};
static void gemini_gpio_irq_handler(struct irq_desc *desc)
{
struct gpio_chip *gc = irq_desc_get_handler_data(desc);
struct gemini_gpio *g = gpiochip_get_data(gc);
struct irq_chip *irqchip = irq_desc_get_chip(desc);
int offset;
unsigned long stat;
chained_irq_enter(irqchip, desc);
stat = readl(g->base + GPIO_INT_STAT);
if (stat)
for_each_set_bit(offset, &stat, gc->ngpio)
generic_handle_irq(irq_find_mapping(gc->irqdomain,
offset));
chained_irq_exit(irqchip, desc);
}
static int gemini_gpio_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct resource *res;
struct gemini_gpio *g;
int irq;
int ret;
g = devm_kzalloc(dev, sizeof(*g), GFP_KERNEL);
if (!g)
return -ENOMEM;
g->dev = dev;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
g->base = devm_ioremap_resource(dev, res);
if (IS_ERR(g->base))
return PTR_ERR(g->base);
irq = platform_get_irq(pdev, 0);
if (!irq)
return -EINVAL;
ret = bgpio_init(&g->gc, dev, 4,
g->base + GPIO_DATA_IN,
g->base + GPIO_DATA_SET,
g->base + GPIO_DATA_CLR,
g->base + GPIO_DIR,
NULL,
0);
if (ret) {
dev_err(dev, "unable to init generic GPIO\n");
return ret;
}
g->gc.label = "Gemini";
g->gc.base = -1;
g->gc.parent = dev;
g->gc.owner = THIS_MODULE;
/* ngpio is set by bgpio_init() */
ret = devm_gpiochip_add_data(dev, &g->gc, g);
if (ret)
return ret;
/* Disable, unmask and clear all interrupts */
writel(0x0, g->base + GPIO_INT_EN);
writel(0x0, g->base + GPIO_INT_MASK);
writel(~0x0, g->base + GPIO_INT_CLR);
ret = gpiochip_irqchip_add(&g->gc, &gemini_gpio_irqchip,
0, handle_bad_irq,
IRQ_TYPE_NONE);
if (ret) {
dev_info(dev, "could not add irqchip\n");
return ret;
}
gpiochip_set_chained_irqchip(&g->gc, &gemini_gpio_irqchip,
irq, gemini_gpio_irq_handler);
dev_info(dev, "Gemini GPIO @%p registered\n", g->base);
return 0;
}
static const struct of_device_id gemini_gpio_of_match[] = {
{
.compatible = "cortina,gemini-gpio",
},
{},
};
static struct platform_driver gemini_gpio_driver = {
.driver = {
.name = "gemini-gpio",
.of_match_table = of_match_ptr(gemini_gpio_of_match),
},
.probe = gemini_gpio_probe,
};
builtin_platform_driver(gemini_gpio_driver);
...@@ -192,6 +192,56 @@ static void gpiomm_gpio_set(struct gpio_chip *chip, unsigned int offset, ...@@ -192,6 +192,56 @@ static void gpiomm_gpio_set(struct gpio_chip *chip, unsigned int offset,
spin_unlock_irqrestore(&gpiommgpio->lock, flags); spin_unlock_irqrestore(&gpiommgpio->lock, flags);
} }
static void gpiomm_gpio_set_multiple(struct gpio_chip *chip,
unsigned long *mask, unsigned long *bits)
{
struct gpiomm_gpio *const gpiommgpio = gpiochip_get_data(chip);
unsigned int i;
const unsigned int gpio_reg_size = 8;
unsigned int port;
unsigned int out_port;
unsigned int bitmask;
unsigned long flags;
/* set bits are evaluated a gpio register size at a time */
for (i = 0; i < chip->ngpio; i += gpio_reg_size) {
/* no more set bits in this mask word; skip to the next word */
if (!mask[BIT_WORD(i)]) {
i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size;
continue;
}
port = i / gpio_reg_size;
out_port = (port > 2) ? port + 1 : port;
bitmask = mask[BIT_WORD(i)] & bits[BIT_WORD(i)];
spin_lock_irqsave(&gpiommgpio->lock, flags);
/* update output state data and set device gpio register */
gpiommgpio->out_state[port] &= ~mask[BIT_WORD(i)];
gpiommgpio->out_state[port] |= bitmask;
outb(gpiommgpio->out_state[port], gpiommgpio->base + out_port);
spin_unlock_irqrestore(&gpiommgpio->lock, flags);
/* prepare for next gpio register set */
mask[BIT_WORD(i)] >>= gpio_reg_size;
bits[BIT_WORD(i)] >>= gpio_reg_size;
}
}
#define GPIOMM_NGPIO 48
static const char *gpiomm_names[GPIOMM_NGPIO] = {
"Port 1A0", "Port 1A1", "Port 1A2", "Port 1A3", "Port 1A4", "Port 1A5",
"Port 1A6", "Port 1A7", "Port 1B0", "Port 1B1", "Port 1B2", "Port 1B3",
"Port 1B4", "Port 1B5", "Port 1B6", "Port 1B7", "Port 1C0", "Port 1C1",
"Port 1C2", "Port 1C3", "Port 1C4", "Port 1C5", "Port 1C6", "Port 1C7",
"Port 2A0", "Port 2A1", "Port 2A2", "Port 2A3", "Port 2A4", "Port 2A5",
"Port 2A6", "Port 2A7", "Port 2B0", "Port 2B1", "Port 2B2", "Port 2B3",
"Port 2B4", "Port 2B5", "Port 2B6", "Port 2B7", "Port 2C0", "Port 2C1",
"Port 2C2", "Port 2C3", "Port 2C4", "Port 2C5", "Port 2C6", "Port 2C7",
};
static int gpiomm_probe(struct device *dev, unsigned int id) static int gpiomm_probe(struct device *dev, unsigned int id)
{ {
struct gpiomm_gpio *gpiommgpio; struct gpiomm_gpio *gpiommgpio;
...@@ -212,19 +262,19 @@ static int gpiomm_probe(struct device *dev, unsigned int id) ...@@ -212,19 +262,19 @@ static int gpiomm_probe(struct device *dev, unsigned int id)
gpiommgpio->chip.parent = dev; gpiommgpio->chip.parent = dev;
gpiommgpio->chip.owner = THIS_MODULE; gpiommgpio->chip.owner = THIS_MODULE;
gpiommgpio->chip.base = -1; gpiommgpio->chip.base = -1;
gpiommgpio->chip.ngpio = 48; gpiommgpio->chip.ngpio = GPIOMM_NGPIO;
gpiommgpio->chip.names = gpiomm_names;
gpiommgpio->chip.get_direction = gpiomm_gpio_get_direction; gpiommgpio->chip.get_direction = gpiomm_gpio_get_direction;
gpiommgpio->chip.direction_input = gpiomm_gpio_direction_input; gpiommgpio->chip.direction_input = gpiomm_gpio_direction_input;
gpiommgpio->chip.direction_output = gpiomm_gpio_direction_output; gpiommgpio->chip.direction_output = gpiomm_gpio_direction_output;
gpiommgpio->chip.get = gpiomm_gpio_get; gpiommgpio->chip.get = gpiomm_gpio_get;
gpiommgpio->chip.set = gpiomm_gpio_set; gpiommgpio->chip.set = gpiomm_gpio_set;
gpiommgpio->chip.set_multiple = gpiomm_gpio_set_multiple;
gpiommgpio->base = base[id]; gpiommgpio->base = base[id];
spin_lock_init(&gpiommgpio->lock); spin_lock_init(&gpiommgpio->lock);
dev_set_drvdata(dev, gpiommgpio); err = devm_gpiochip_add_data(dev, &gpiommgpio->chip, gpiommgpio);
err = gpiochip_add_data(&gpiommgpio->chip, gpiommgpio);
if (err) { if (err) {
dev_err(dev, "GPIO registering failed (%d)\n", err); dev_err(dev, "GPIO registering failed (%d)\n", err);
return err; return err;
...@@ -243,21 +293,11 @@ static int gpiomm_probe(struct device *dev, unsigned int id) ...@@ -243,21 +293,11 @@ static int gpiomm_probe(struct device *dev, unsigned int id)
return 0; return 0;
} }
static int gpiomm_remove(struct device *dev, unsigned int id)
{
struct gpiomm_gpio *const gpiommgpio = dev_get_drvdata(dev);
gpiochip_remove(&gpiommgpio->chip);
return 0;
}
static struct isa_driver gpiomm_driver = { static struct isa_driver gpiomm_driver = {
.probe = gpiomm_probe, .probe = gpiomm_probe,
.driver = { .driver = {
.name = "gpio-mm" .name = "gpio-mm"
}, },
.remove = gpiomm_remove
}; };
module_isa_driver(gpiomm_driver, num_gpiomm); module_isa_driver(gpiomm_driver, num_gpiomm);
......
...@@ -321,7 +321,7 @@ static void intel_mid_irq_init_hw(struct intel_mid_gpio *priv) ...@@ -321,7 +321,7 @@ static void intel_mid_irq_init_hw(struct intel_mid_gpio *priv)
} }
} }
static int intel_gpio_runtime_idle(struct device *dev) static int __maybe_unused intel_gpio_runtime_idle(struct device *dev)
{ {
int err = pm_schedule_suspend(dev, 500); int err = pm_schedule_suspend(dev, 500);
return err ?: -EBUSY; return err ?: -EBUSY;
......
This diff is collapsed.
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* under the terms of the GNU General Public License version 2 as published * under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation. * by the Free Software Foundation.
* *
* Copyright (C) 2012 John Crispin <blogic@openwrt.org> * Copyright (C) 2012 John Crispin <john@phrozen.org>
*/ */
#include <linux/init.h> #include <linux/init.h>
......
This diff is collapsed.
...@@ -659,7 +659,7 @@ static int mvebu_gpio_probe(struct platform_device *pdev) ...@@ -659,7 +659,7 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
match = of_match_device(mvebu_gpio_of_match, &pdev->dev); match = of_match_device(mvebu_gpio_of_match, &pdev->dev);
if (match) if (match)
soc_variant = (int) match->data; soc_variant = (unsigned long) match->data;
else else
soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION; soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/platform_data/pca953x.h> #include <linux/platform_data/pca953x.h>
...@@ -754,8 +755,16 @@ static int pca953x_probe(struct i2c_client *client, ...@@ -754,8 +755,16 @@ static int pca953x_probe(struct i2c_client *client,
invert = pdata->invert; invert = pdata->invert;
chip->names = pdata->names; chip->names = pdata->names;
} else { } else {
struct gpio_desc *reset_gpio;
chip->gpio_start = -1; chip->gpio_start = -1;
irq_base = 0; irq_base = 0;
/* See if we need to de-assert a reset pin */
reset_gpio = devm_gpiod_get_optional(&client->dev, "reset",
GPIOD_OUT_LOW);
if (IS_ERR(reset_gpio))
return PTR_ERR(reset_gpio);
} }
chip->client = client; chip->client = client;
......
/*
* GPIO driver for the ACCES PCI-IDIO-16
* Copyright (C) 2017 William Breathitt Gray
*
* 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.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
#include <linux/bitops.h>
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/gpio/driver.h>
#include <linux/interrupt.h>
#include <linux/irqdesc.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/spinlock.h>
#include <linux/types.h>
/**
* struct idio_16_gpio_reg - GPIO device registers structure
* @out0_7: Read: FET Drive Outputs 0-7
* Write: FET Drive Outputs 0-7
* @in0_7: Read: Isolated Inputs 0-7
* Write: Clear Interrupt
* @irq_ctl: Read: Enable IRQ
* Write: Disable IRQ
* @filter_ctl: Read: Activate Input Filters 0-15
* Write: Deactivate Input Filters 0-15
* @out8_15: Read: FET Drive Outputs 8-15
* Write: FET Drive Outputs 8-15
* @in8_15: Read: Isolated Inputs 8-15
* Write: Unused
* @irq_status: Read: Interrupt status
* Write: Unused
*/
struct idio_16_gpio_reg {
u8 out0_7;
u8 in0_7;
u8 irq_ctl;
u8 filter_ctl;
u8 out8_15;
u8 in8_15;
u8 irq_status;
};
/**
* struct idio_16_gpio - GPIO device private data structure
* @chip: instance of the gpio_chip
* @lock: synchronization lock to prevent I/O race conditions
* @reg: I/O address offset for the GPIO device registers
* @irq_mask: I/O bits affected by interrupts
*/
struct idio_16_gpio {
struct gpio_chip chip;
spinlock_t lock;
struct idio_16_gpio_reg __iomem *reg;
unsigned long irq_mask;
};
static int idio_16_gpio_get_direction(struct gpio_chip *chip,
unsigned int offset)
{
if (offset > 15)
return 1;
return 0;
}
static int idio_16_gpio_direction_input(struct gpio_chip *chip,
unsigned int offset)
{
return 0;
}
static int idio_16_gpio_direction_output(struct gpio_chip *chip,
unsigned int offset, int value)
{
chip->set(chip, offset, value);
return 0;
}
static int idio_16_gpio_get(struct gpio_chip *chip, unsigned int offset)
{
struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
unsigned long mask = BIT(offset);
if (offset < 8)
return !!(ioread8(&idio16gpio->reg->out0_7) & mask);
if (offset < 16)
return !!(ioread8(&idio16gpio->reg->out8_15) & (mask >> 8));
if (offset < 24)
return !!(ioread8(&idio16gpio->reg->in0_7) & (mask >> 16));
return !!(ioread8(&idio16gpio->reg->in8_15) & (mask >> 24));
}
static void idio_16_gpio_set(struct gpio_chip *chip, unsigned int offset,
int value)
{
struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
unsigned int mask = BIT(offset);
void __iomem *base;
unsigned long flags;
unsigned int out_state;
if (offset > 15)
return;
if (offset > 7) {
mask >>= 8;
base = &idio16gpio->reg->out8_15;
} else
base = &idio16gpio->reg->out0_7;
spin_lock_irqsave(&idio16gpio->lock, flags);
if (value)
out_state = ioread8(base) | mask;
else
out_state = ioread8(base) & ~mask;
iowrite8(out_state, base);
spin_unlock_irqrestore(&idio16gpio->lock, flags);
}
static void idio_16_gpio_set_multiple(struct gpio_chip *chip,
unsigned long *mask, unsigned long *bits)
{
struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
unsigned long flags;
unsigned int out_state;
spin_lock_irqsave(&idio16gpio->lock, flags);
/* process output lines 0-7 */
if (*mask & 0xFF) {
out_state = ioread8(&idio16gpio->reg->out0_7) & ~*mask;
out_state |= *mask & *bits;
iowrite8(out_state, &idio16gpio->reg->out0_7);
}
/* shift to next output line word */
*mask >>= 8;
/* process output lines 8-15 */
if (*mask & 0xFF) {
*bits >>= 8;
out_state = ioread8(&idio16gpio->reg->out8_15) & ~*mask;
out_state |= *mask & *bits;
iowrite8(out_state, &idio16gpio->reg->out8_15);
}
spin_unlock_irqrestore(&idio16gpio->lock, flags);
}
static void idio_16_irq_ack(struct irq_data *data)
{
}
static void idio_16_irq_mask(struct irq_data *data)
{
struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
const unsigned long mask = BIT(irqd_to_hwirq(data));
unsigned long flags;
idio16gpio->irq_mask &= ~mask;
if (!idio16gpio->irq_mask) {
spin_lock_irqsave(&idio16gpio->lock, flags);
iowrite8(0, &idio16gpio->reg->irq_ctl);
spin_unlock_irqrestore(&idio16gpio->lock, flags);
}
}
static void idio_16_irq_unmask(struct irq_data *data)
{
struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
struct idio_16_gpio *const idio16gpio = gpiochip_get_data(chip);
const unsigned long mask = BIT(irqd_to_hwirq(data));
const unsigned long prev_irq_mask = idio16gpio->irq_mask;
unsigned long flags;
idio16gpio->irq_mask |= mask;
if (!prev_irq_mask) {
spin_lock_irqsave(&idio16gpio->lock, flags);
ioread8(&idio16gpio->reg->irq_ctl);
spin_unlock_irqrestore(&idio16gpio->lock, flags);
}
}
static int idio_16_irq_set_type(struct irq_data *data, unsigned int flow_type)
{
/* The only valid irq types are none and both-edges */
if (flow_type != IRQ_TYPE_NONE &&
(flow_type & IRQ_TYPE_EDGE_BOTH) != IRQ_TYPE_EDGE_BOTH)
return -EINVAL;
return 0;
}
static struct irq_chip idio_16_irqchip = {
.name = "pci-idio-16",
.irq_ack = idio_16_irq_ack,
.irq_mask = idio_16_irq_mask,
.irq_unmask = idio_16_irq_unmask,
.irq_set_type = idio_16_irq_set_type
};
static irqreturn_t idio_16_irq_handler(int irq, void *dev_id)
{
struct idio_16_gpio *const idio16gpio = dev_id;
unsigned int irq_status;
struct gpio_chip *const chip = &idio16gpio->chip;
int gpio;
spin_lock(&idio16gpio->lock);
irq_status = ioread8(&idio16gpio->reg->irq_status);
spin_unlock(&idio16gpio->lock);
/* Make sure our device generated IRQ */
if (!(irq_status & 0x3) || !(irq_status & 0x4))
return IRQ_NONE;
for_each_set_bit(gpio, &idio16gpio->irq_mask, chip->ngpio)
generic_handle_irq(irq_find_mapping(chip->irqdomain, gpio));
spin_lock(&idio16gpio->lock);
/* Clear interrupt */
iowrite8(0, &idio16gpio->reg->in0_7);
spin_unlock(&idio16gpio->lock);
return IRQ_HANDLED;
}
#define IDIO_16_NGPIO 32
static const char *idio_16_names[IDIO_16_NGPIO] = {
"OUT0", "OUT1", "OUT2", "OUT3", "OUT4", "OUT5", "OUT6", "OUT7",
"OUT8", "OUT9", "OUT10", "OUT11", "OUT12", "OUT13", "OUT14", "OUT15",
"IIN0", "IIN1", "IIN2", "IIN3", "IIN4", "IIN5", "IIN6", "IIN7",
"IIN8", "IIN9", "IIN10", "IIN11", "IIN12", "IIN13", "IIN14", "IIN15"
};
static int idio_16_probe(struct pci_dev *pdev, const struct pci_device_id *id)
{
struct device *const dev = &pdev->dev;
struct idio_16_gpio *idio16gpio;
int err;
const size_t pci_bar_index = 2;
const char *const name = pci_name(pdev);
idio16gpio = devm_kzalloc(dev, sizeof(*idio16gpio), GFP_KERNEL);
if (!idio16gpio)
return -ENOMEM;
err = pcim_enable_device(pdev);
if (err) {
dev_err(dev, "Failed to enable PCI device (%d)\n", err);
return err;
}
err = pcim_iomap_regions(pdev, BIT(pci_bar_index), name);
if (err) {
dev_err(dev, "Unable to map PCI I/O addresses (%d)\n", err);
return err;
}
idio16gpio->reg = pcim_iomap_table(pdev)[pci_bar_index];
/* Deactivate input filters */
iowrite8(0, &idio16gpio->reg->filter_ctl);
idio16gpio->chip.label = name;
idio16gpio->chip.parent = dev;
idio16gpio->chip.owner = THIS_MODULE;
idio16gpio->chip.base = -1;
idio16gpio->chip.ngpio = IDIO_16_NGPIO;
idio16gpio->chip.names = idio_16_names;
idio16gpio->chip.get_direction = idio_16_gpio_get_direction;
idio16gpio->chip.direction_input = idio_16_gpio_direction_input;
idio16gpio->chip.direction_output = idio_16_gpio_direction_output;
idio16gpio->chip.get = idio_16_gpio_get;
idio16gpio->chip.set = idio_16_gpio_set;
idio16gpio->chip.set_multiple = idio_16_gpio_set_multiple;
spin_lock_init(&idio16gpio->lock);
err = devm_gpiochip_add_data(dev, &idio16gpio->chip, idio16gpio);
if (err) {
dev_err(dev, "GPIO registering failed (%d)\n", err);
return err;
}
/* Disable IRQ by default and clear any pending interrupt */
iowrite8(0, &idio16gpio->reg->irq_ctl);
iowrite8(0, &idio16gpio->reg->in0_7);
err = gpiochip_irqchip_add(&idio16gpio->chip, &idio_16_irqchip, 0,
handle_edge_irq, IRQ_TYPE_NONE);
if (err) {
dev_err(dev, "Could not add irqchip (%d)\n", err);
return err;
}
err = devm_request_irq(dev, pdev->irq, idio_16_irq_handler, IRQF_SHARED,
name, idio16gpio);
if (err) {
dev_err(dev, "IRQ handler registering failed (%d)\n", err);
return err;
}
return 0;
}
static const struct pci_device_id idio_16_pci_dev_id[] = {
{ PCI_DEVICE(0x494F, 0x0DC8) }, { 0 }
};
MODULE_DEVICE_TABLE(pci, idio_16_pci_dev_id);
static struct pci_driver idio_16_driver = {
.name = "pci-idio-16",
.id_table = idio_16_pci_dev_id,
.probe = idio_16_probe
};
module_pci_driver(idio_16_driver);
MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>");
MODULE_DESCRIPTION("ACCES PCI-IDIO-16 GPIO driver");
MODULE_LICENSE("GPL v2");
...@@ -242,11 +242,24 @@ static void gpio_rcar_config_general_input_output_mode(struct gpio_chip *chip, ...@@ -242,11 +242,24 @@ static void gpio_rcar_config_general_input_output_mode(struct gpio_chip *chip,
static int gpio_rcar_request(struct gpio_chip *chip, unsigned offset) static int gpio_rcar_request(struct gpio_chip *chip, unsigned offset)
{ {
return pinctrl_request_gpio(chip->base + offset); struct gpio_rcar_priv *p = gpiochip_get_data(chip);
int error;
error = pm_runtime_get_sync(&p->pdev->dev);
if (error < 0)
return error;
error = pinctrl_request_gpio(chip->base + offset);
if (error)
pm_runtime_put(&p->pdev->dev);
return error;
} }
static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset) static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset)
{ {
struct gpio_rcar_priv *p = gpiochip_get_data(chip);
pinctrl_free_gpio(chip->base + offset); pinctrl_free_gpio(chip->base + offset);
/* /*
...@@ -254,6 +267,8 @@ static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset) ...@@ -254,6 +267,8 @@ static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset)
* drive the GPIO pin as an output. * drive the GPIO pin as an output.
*/ */
gpio_rcar_config_general_input_output_mode(chip, offset, false); gpio_rcar_config_general_input_output_mode(chip, offset, false);
pm_runtime_put(&p->pdev->dev);
} }
static int gpio_rcar_direction_input(struct gpio_chip *chip, unsigned offset) static int gpio_rcar_direction_input(struct gpio_chip *chip, unsigned offset)
...@@ -426,7 +441,6 @@ static int gpio_rcar_probe(struct platform_device *pdev) ...@@ -426,7 +441,6 @@ static int gpio_rcar_probe(struct platform_device *pdev)
} }
pm_runtime_enable(dev); pm_runtime_enable(dev);
pm_runtime_get_sync(dev);
io = platform_get_resource(pdev, IORESOURCE_MEM, 0); io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
...@@ -460,6 +474,7 @@ static int gpio_rcar_probe(struct platform_device *pdev) ...@@ -460,6 +474,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
irq_chip = &p->irq_chip; irq_chip = &p->irq_chip;
irq_chip->name = name; irq_chip->name = name;
irq_chip->parent_device = dev;
irq_chip->irq_mask = gpio_rcar_irq_disable; irq_chip->irq_mask = gpio_rcar_irq_disable;
irq_chip->irq_unmask = gpio_rcar_irq_enable; irq_chip->irq_unmask = gpio_rcar_irq_enable;
irq_chip->irq_set_type = gpio_rcar_irq_set_type; irq_chip->irq_set_type = gpio_rcar_irq_set_type;
...@@ -494,7 +509,6 @@ static int gpio_rcar_probe(struct platform_device *pdev) ...@@ -494,7 +509,6 @@ static int gpio_rcar_probe(struct platform_device *pdev)
err1: err1:
gpiochip_remove(gpio_chip); gpiochip_remove(gpio_chip);
err0: err0:
pm_runtime_put(dev);
pm_runtime_disable(dev); pm_runtime_disable(dev);
return ret; return ret;
} }
...@@ -505,7 +519,6 @@ static int gpio_rcar_remove(struct platform_device *pdev) ...@@ -505,7 +519,6 @@ static int gpio_rcar_remove(struct platform_device *pdev)
gpiochip_remove(&p->gpio_chip); gpiochip_remove(&p->gpio_chip);
pm_runtime_put(&pdev->dev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
return 0; return 0;
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* under the terms of the GNU General Public License version 2 as published * under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation. * by the Free Software Foundation.
* *
* Copyright (C) 2012 John Crispin <blogic@openwrt.org> * Copyright (C) 2012 John Crispin <john@phrozen.org>
* *
*/ */
......
...@@ -46,7 +46,6 @@ MODULE_PARM_DESC(irq, "WinSystems WS16C48 interrupt line numbers"); ...@@ -46,7 +46,6 @@ MODULE_PARM_DESC(irq, "WinSystems WS16C48 interrupt line numbers");
* @irq_mask: I/O bits affected by interrupts * @irq_mask: I/O bits affected by interrupts
* @flow_mask: IRQ flow type mask for the respective I/O bits * @flow_mask: IRQ flow type mask for the respective I/O bits
* @base: base port address of the GPIO device * @base: base port address of the GPIO device
* @irq: Interrupt line number
*/ */
struct ws16c48_gpio { struct ws16c48_gpio {
struct gpio_chip chip; struct gpio_chip chip;
...@@ -56,7 +55,6 @@ struct ws16c48_gpio { ...@@ -56,7 +55,6 @@ struct ws16c48_gpio {
unsigned long irq_mask; unsigned long irq_mask;
unsigned long flow_mask; unsigned long flow_mask;
unsigned base; unsigned base;
unsigned irq;
}; };
static int ws16c48_gpio_get_direction(struct gpio_chip *chip, unsigned offset) static int ws16c48_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
...@@ -155,6 +153,46 @@ static void ws16c48_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ...@@ -155,6 +153,46 @@ static void ws16c48_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
spin_unlock_irqrestore(&ws16c48gpio->lock, flags); spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
} }
static void ws16c48_gpio_set_multiple(struct gpio_chip *chip,
unsigned long *mask, unsigned long *bits)
{
struct ws16c48_gpio *const ws16c48gpio = gpiochip_get_data(chip);
unsigned int i;
const unsigned int gpio_reg_size = 8;
unsigned int port;
unsigned int iomask;
unsigned int bitmask;
unsigned long flags;
/* set bits are evaluated a gpio register size at a time */
for (i = 0; i < chip->ngpio; i += gpio_reg_size) {
/* no more set bits in this mask word; skip to the next word */
if (!mask[BIT_WORD(i)]) {
i = (BIT_WORD(i) + 1) * BITS_PER_LONG - gpio_reg_size;
continue;
}
port = i / gpio_reg_size;
/* mask out GPIO configured for input */
iomask = mask[BIT_WORD(i)] & ~ws16c48gpio->io_state[port];
bitmask = iomask & bits[BIT_WORD(i)];
spin_lock_irqsave(&ws16c48gpio->lock, flags);
/* update output state data and set device gpio register */
ws16c48gpio->out_state[port] &= ~iomask;
ws16c48gpio->out_state[port] |= bitmask;
outb(ws16c48gpio->out_state[port], ws16c48gpio->base + port);
spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
/* prepare for next gpio register set */
mask[BIT_WORD(i)] >>= gpio_reg_size;
bits[BIT_WORD(i)] >>= gpio_reg_size;
}
}
static void ws16c48_irq_ack(struct irq_data *data) static void ws16c48_irq_ack(struct irq_data *data)
{ {
struct gpio_chip *chip = irq_data_get_irq_chip_data(data); struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
...@@ -303,6 +341,22 @@ static irqreturn_t ws16c48_irq_handler(int irq, void *dev_id) ...@@ -303,6 +341,22 @@ static irqreturn_t ws16c48_irq_handler(int irq, void *dev_id)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
#define WS16C48_NGPIO 48
static const char *ws16c48_names[WS16C48_NGPIO] = {
"Port 0 Bit 0", "Port 0 Bit 1", "Port 0 Bit 2", "Port 0 Bit 3",
"Port 0 Bit 4", "Port 0 Bit 5", "Port 0 Bit 6", "Port 0 Bit 7",
"Port 1 Bit 0", "Port 1 Bit 1", "Port 1 Bit 2", "Port 1 Bit 3",
"Port 1 Bit 4", "Port 1 Bit 5", "Port 1 Bit 6", "Port 1 Bit 7",
"Port 2 Bit 0", "Port 2 Bit 1", "Port 2 Bit 2", "Port 2 Bit 3",
"Port 2 Bit 4", "Port 2 Bit 5", "Port 2 Bit 6", "Port 2 Bit 7",
"Port 3 Bit 0", "Port 3 Bit 1", "Port 3 Bit 2", "Port 3 Bit 3",
"Port 3 Bit 4", "Port 3 Bit 5", "Port 3 Bit 6", "Port 3 Bit 7",
"Port 4 Bit 0", "Port 4 Bit 1", "Port 4 Bit 2", "Port 4 Bit 3",
"Port 4 Bit 4", "Port 4 Bit 5", "Port 4 Bit 6", "Port 4 Bit 7",
"Port 5 Bit 0", "Port 5 Bit 1", "Port 5 Bit 2", "Port 5 Bit 3",
"Port 5 Bit 4", "Port 5 Bit 5", "Port 5 Bit 6", "Port 5 Bit 7"
};
static int ws16c48_probe(struct device *dev, unsigned int id) static int ws16c48_probe(struct device *dev, unsigned int id)
{ {
struct ws16c48_gpio *ws16c48gpio; struct ws16c48_gpio *ws16c48gpio;
...@@ -323,20 +377,19 @@ static int ws16c48_probe(struct device *dev, unsigned int id) ...@@ -323,20 +377,19 @@ static int ws16c48_probe(struct device *dev, unsigned int id)
ws16c48gpio->chip.parent = dev; ws16c48gpio->chip.parent = dev;
ws16c48gpio->chip.owner = THIS_MODULE; ws16c48gpio->chip.owner = THIS_MODULE;
ws16c48gpio->chip.base = -1; ws16c48gpio->chip.base = -1;
ws16c48gpio->chip.ngpio = 48; ws16c48gpio->chip.ngpio = WS16C48_NGPIO;
ws16c48gpio->chip.names = ws16c48_names;
ws16c48gpio->chip.get_direction = ws16c48_gpio_get_direction; ws16c48gpio->chip.get_direction = ws16c48_gpio_get_direction;
ws16c48gpio->chip.direction_input = ws16c48_gpio_direction_input; ws16c48gpio->chip.direction_input = ws16c48_gpio_direction_input;
ws16c48gpio->chip.direction_output = ws16c48_gpio_direction_output; ws16c48gpio->chip.direction_output = ws16c48_gpio_direction_output;
ws16c48gpio->chip.get = ws16c48_gpio_get; ws16c48gpio->chip.get = ws16c48_gpio_get;
ws16c48gpio->chip.set = ws16c48_gpio_set; ws16c48gpio->chip.set = ws16c48_gpio_set;
ws16c48gpio->chip.set_multiple = ws16c48_gpio_set_multiple;
ws16c48gpio->base = base[id]; ws16c48gpio->base = base[id];
ws16c48gpio->irq = irq[id];
spin_lock_init(&ws16c48gpio->lock); spin_lock_init(&ws16c48gpio->lock);
dev_set_drvdata(dev, ws16c48gpio); err = devm_gpiochip_add_data(dev, &ws16c48gpio->chip, ws16c48gpio);
err = gpiochip_add_data(&ws16c48gpio->chip, ws16c48gpio);
if (err) { if (err) {
dev_err(dev, "GPIO registering failed (%d)\n", err); dev_err(dev, "GPIO registering failed (%d)\n", err);
return err; return err;
...@@ -353,29 +406,15 @@ static int ws16c48_probe(struct device *dev, unsigned int id) ...@@ -353,29 +406,15 @@ static int ws16c48_probe(struct device *dev, unsigned int id)
handle_edge_irq, IRQ_TYPE_NONE); handle_edge_irq, IRQ_TYPE_NONE);
if (err) { if (err) {
dev_err(dev, "Could not add irqchip (%d)\n", err); dev_err(dev, "Could not add irqchip (%d)\n", err);
goto err_gpiochip_remove; return err;
} }
err = request_irq(irq[id], ws16c48_irq_handler, IRQF_SHARED, name, err = devm_request_irq(dev, irq[id], ws16c48_irq_handler, IRQF_SHARED,
ws16c48gpio); name, ws16c48gpio);
if (err) { if (err) {
dev_err(dev, "IRQ handler registering failed (%d)\n", err); dev_err(dev, "IRQ handler registering failed (%d)\n", err);
goto err_gpiochip_remove;
}
return 0;
err_gpiochip_remove:
gpiochip_remove(&ws16c48gpio->chip);
return err; return err;
} }
static int ws16c48_remove(struct device *dev, unsigned int id)
{
struct ws16c48_gpio *const ws16c48gpio = dev_get_drvdata(dev);
free_irq(ws16c48gpio->irq, ws16c48gpio);
gpiochip_remove(&ws16c48gpio->chip);
return 0; return 0;
} }
...@@ -385,7 +424,6 @@ static struct isa_driver ws16c48_driver = { ...@@ -385,7 +424,6 @@ static struct isa_driver ws16c48_driver = {
.driver = { .driver = {
.name = "ws16c48" .name = "ws16c48"
}, },
.remove = ws16c48_remove
}; };
module_isa_driver(ws16c48_driver, num_ws16c48); module_isa_driver(ws16c48_driver, num_ws16c48);
......
...@@ -416,9 +416,8 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data) ...@@ -416,9 +416,8 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT; agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT;
/* /*
* ActiveLow is only specified for GpioInt resource. If * Polarity and triggering are only specified for GpioInt
* GpioIo is used then the only way to set the flag is * resource.
* to use _DSD "gpios" property.
* Note: we expect here: * Note: we expect here:
* - ACPI_ACTIVE_LOW == GPIO_ACTIVE_LOW * - ACPI_ACTIVE_LOW == GPIO_ACTIVE_LOW
* - ACPI_ACTIVE_HIGH == GPIO_ACTIVE_HIGH * - ACPI_ACTIVE_HIGH == GPIO_ACTIVE_HIGH
......
...@@ -160,6 +160,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, ...@@ -160,6 +160,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
* of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API
* @np: device node to get GPIO from * @np: device node to get GPIO from
* @chip: GPIO chip whose hog is parsed * @chip: GPIO chip whose hog is parsed
* @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: gpio_lookup_flags - returned from of_find_gpio() or
* of_parse_own_gpio() * of_parse_own_gpio()
...@@ -170,7 +171,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, ...@@ -170,7 +171,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,
const char **name, unsigned int idx, const char **name,
enum gpio_lookup_flags *lflags, enum gpio_lookup_flags *lflags,
enum gpiod_flags *dflags) enum gpiod_flags *dflags)
{ {
...@@ -178,6 +179,7 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, ...@@ -178,6 +179,7 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
enum of_gpio_flags xlate_flags; enum of_gpio_flags xlate_flags;
struct of_phandle_args gpiospec; struct of_phandle_args gpiospec;
struct gpio_desc *desc; struct gpio_desc *desc;
unsigned int i;
u32 tmp; u32 tmp;
int ret; int ret;
...@@ -196,9 +198,12 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, ...@@ -196,9 +198,12 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
gpiospec.np = chip_np; gpiospec.np = chip_np;
gpiospec.args_count = tmp; gpiospec.args_count = tmp;
ret = of_property_read_u32_array(np, "gpios", gpiospec.args, tmp); for (i = 0; i < tmp; i++) {
ret = of_property_read_u32_index(np, "gpios", idx * tmp + i,
&gpiospec.args[i]);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
}
desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, &xlate_flags); desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, &xlate_flags);
if (IS_ERR(desc)) if (IS_ERR(desc))
...@@ -240,15 +245,18 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip) ...@@ -240,15 +245,18 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
const char *name; const char *name;
enum gpio_lookup_flags lflags; enum gpio_lookup_flags lflags;
enum gpiod_flags dflags; enum gpiod_flags dflags;
unsigned int i;
int ret; int ret;
for_each_available_child_of_node(chip->of_node, np) { for_each_available_child_of_node(chip->of_node, np) {
if (!of_property_read_bool(np, "gpio-hog")) if (!of_property_read_bool(np, "gpio-hog"))
continue; continue;
desc = of_parse_own_gpio(np, chip, &name, &lflags, &dflags); for (i = 0;; i++) {
desc = of_parse_own_gpio(np, chip, i, &name, &lflags,
&dflags);
if (IS_ERR(desc)) if (IS_ERR(desc))
continue; break;
ret = gpiod_hog(desc, name, lflags, dflags); ret = gpiod_hog(desc, name, lflags, dflags);
if (ret < 0) { if (ret < 0) {
...@@ -256,6 +264,7 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip) ...@@ -256,6 +264,7 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
return ret; return ret;
} }
} }
}
return 0; return 0;
} }
......
#include <linux/bitops.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
...@@ -982,7 +983,7 @@ static int gpio_chrdev_open(struct inode *inode, struct file *filp) ...@@ -982,7 +983,7 @@ static int gpio_chrdev_open(struct inode *inode, struct file *filp)
struct gpio_device, chrdev); struct gpio_device, chrdev);
/* Fail on open if the backing gpiochip is gone */ /* Fail on open if the backing gpiochip is gone */
if (!gdev || !gdev->chip) if (!gdev->chip)
return -ENODEV; return -ENODEV;
get_device(&gdev->dev); get_device(&gdev->dev);
filp->private_data = gdev; filp->private_data = gdev;
...@@ -1001,8 +1002,6 @@ static int gpio_chrdev_release(struct inode *inode, struct file *filp) ...@@ -1001,8 +1002,6 @@ static int gpio_chrdev_release(struct inode *inode, struct file *filp)
struct gpio_device *gdev = container_of(inode->i_cdev, struct gpio_device *gdev = container_of(inode->i_cdev,
struct gpio_device, chrdev); struct gpio_device, chrdev);
if (!gdev)
return -ENODEV;
put_device(&gdev->dev); put_device(&gdev->dev);
return 0; return 0;
} }
...@@ -1423,7 +1422,6 @@ void devm_gpiochip_remove(struct device *dev, struct gpio_chip *chip) ...@@ -1423,7 +1422,6 @@ void devm_gpiochip_remove(struct device *dev, struct gpio_chip *chip)
ret = devres_release(dev, devm_gpio_chip_release, ret = devres_release(dev, devm_gpio_chip_release,
devm_gpio_chip_match, chip); devm_gpio_chip_match, chip);
if (!ret)
WARN_ON(ret); WARN_ON(ret);
} }
EXPORT_SYMBOL_GPL(devm_gpiochip_remove); EXPORT_SYMBOL_GPL(devm_gpiochip_remove);
...@@ -2586,19 +2584,12 @@ static void gpio_chip_set_multiple(struct gpio_chip *chip, ...@@ -2586,19 +2584,12 @@ static void gpio_chip_set_multiple(struct gpio_chip *chip,
if (chip->set_multiple) { if (chip->set_multiple) {
chip->set_multiple(chip, mask, bits); chip->set_multiple(chip, mask, bits);
} else { } else {
int i; unsigned int i;
for (i = 0; i < chip->ngpio; i++) {
if (mask[BIT_WORD(i)] == 0) {
/* no more set bits in this mask word;
* skip ahead to the next word */
i = (BIT_WORD(i) + 1) * BITS_PER_LONG - 1;
continue;
}
/* set outputs if the corresponding mask bit is set */ /* set outputs if the corresponding mask bit is set */
if (__test_and_clear_bit(i, mask)) for_each_set_bit(i, mask, chip->ngpio)
chip->set(chip, i, test_bit(i, bits)); chip->set(chip, i, test_bit(i, bits));
} }
}
} }
void gpiod_set_array_value_complex(bool raw, bool can_sleep, void gpiod_set_array_value_complex(bool raw, bool can_sleep,
...@@ -3325,6 +3316,8 @@ EXPORT_SYMBOL_GPL(gpiod_get_index); ...@@ -3325,6 +3316,8 @@ EXPORT_SYMBOL_GPL(gpiod_get_index);
* fwnode_get_named_gpiod - obtain a GPIO from firmware node * fwnode_get_named_gpiod - obtain a GPIO from firmware node
* @fwnode: handle of the firmware node * @fwnode: handle of the firmware node
* @propname: name of the firmware property representing the GPIO * @propname: name of the firmware property representing the GPIO
* @index: index of the GPIO to obtain in the consumer
* @dflags: GPIO initialization flags
* *
* This function can be used for drivers that get their configuration * This function can be used for drivers that get their configuration
* from firmware. * from firmware.
...@@ -3333,12 +3326,18 @@ EXPORT_SYMBOL_GPL(gpiod_get_index); ...@@ -3333,12 +3326,18 @@ EXPORT_SYMBOL_GPL(gpiod_get_index);
* underlying firmware interface and then makes sure that the GPIO * underlying firmware interface and then makes sure that the GPIO
* descriptor is requested before it is returned to the caller. * descriptor is requested before it is returned to the caller.
* *
* On successfull request the GPIO pin is configured in accordance with
* provided @dflags.
*
* In case of error an ERR_PTR() is returned. * In case of error an ERR_PTR() is returned.
*/ */
struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
const char *propname) const char *propname, int index,
enum gpiod_flags dflags,
const char *label)
{ {
struct gpio_desc *desc = ERR_PTR(-ENODEV); struct gpio_desc *desc = ERR_PTR(-ENODEV);
unsigned long lflags = 0;
bool active_low = false; bool active_low = false;
bool single_ended = false; bool single_ended = false;
int ret; int ret;
...@@ -3349,8 +3348,8 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, ...@@ -3349,8 +3348,8 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
if (is_of_node(fwnode)) { if (is_of_node(fwnode)) {
enum of_gpio_flags flags; enum of_gpio_flags flags;
desc = of_get_named_gpiod_flags(to_of_node(fwnode), propname, 0, desc = of_get_named_gpiod_flags(to_of_node(fwnode), propname,
&flags); index, &flags);
if (!IS_ERR(desc)) { if (!IS_ERR(desc)) {
active_low = flags & OF_GPIO_ACTIVE_LOW; active_low = flags & OF_GPIO_ACTIVE_LOW;
single_ended = flags & OF_GPIO_SINGLE_ENDED; single_ended = flags & OF_GPIO_SINGLE_ENDED;
...@@ -3358,7 +3357,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, ...@@ -3358,7 +3357,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
} else if (is_acpi_node(fwnode)) { } else if (is_acpi_node(fwnode)) {
struct acpi_gpio_info info; struct acpi_gpio_info info;
desc = acpi_node_get_gpiod(fwnode, propname, 0, &info); desc = acpi_node_get_gpiod(fwnode, propname, index, &info);
if (!IS_ERR(desc)) if (!IS_ERR(desc))
active_low = info.polarity == GPIO_ACTIVE_LOW; active_low = info.polarity == GPIO_ACTIVE_LOW;
} }
...@@ -3366,18 +3365,24 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, ...@@ -3366,18 +3365,24 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
if (IS_ERR(desc)) if (IS_ERR(desc))
return desc; return desc;
ret = gpiod_request(desc, NULL); ret = gpiod_request(desc, label);
if (ret) if (ret)
return ERR_PTR(ret); return ERR_PTR(ret);
if (active_low) if (active_low)
set_bit(FLAG_ACTIVE_LOW, &desc->flags); lflags |= GPIO_ACTIVE_LOW;
if (single_ended) { if (single_ended) {
if (active_low) if (active_low)
set_bit(FLAG_OPEN_DRAIN, &desc->flags); lflags |= GPIO_OPEN_DRAIN;
else else
set_bit(FLAG_OPEN_SOURCE, &desc->flags); lflags |= GPIO_OPEN_SOURCE;
}
ret = gpiod_configure_flags(desc, propname, lflags, dflags);
if (ret < 0) {
gpiod_put(desc);
return ERR_PTR(ret);
} }
return desc; return desc;
......
...@@ -76,7 +76,8 @@ struct gpio_device { ...@@ -76,7 +76,8 @@ struct gpio_device {
/** /**
* struct acpi_gpio_info - ACPI GPIO specific information * struct acpi_gpio_info - ACPI GPIO specific information
* @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
* @active_low: in case of @gpioint, the pin is active low * @polarity: interrupt polarity as provided by ACPI
* @triggering: triggering type as provided by ACPI
*/ */
struct acpi_gpio_info { struct acpi_gpio_info {
bool gpioint; bool gpioint;
......
...@@ -485,7 +485,10 @@ static int gpio_keys_setup_key(struct platform_device *pdev, ...@@ -485,7 +485,10 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
spin_lock_init(&bdata->lock); spin_lock_init(&bdata->lock);
if (child) { if (child) {
bdata->gpiod = devm_get_gpiod_from_child(dev, NULL, child); bdata->gpiod = devm_fwnode_get_gpiod_from_child(dev, NULL,
child,
GPIOD_IN,
desc);
if (IS_ERR(bdata->gpiod)) { if (IS_ERR(bdata->gpiod)) {
error = PTR_ERR(bdata->gpiod); error = PTR_ERR(bdata->gpiod);
if (error == -ENOENT) { if (error == -ENOENT) {
...@@ -500,13 +503,6 @@ static int gpio_keys_setup_key(struct platform_device *pdev, ...@@ -500,13 +503,6 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
error); error);
return error; return error;
} }
} else {
error = gpiod_direction_input(bdata->gpiod);
if (error) {
dev_err(dev, "Failed to configure GPIO %d as input: %d\n",
desc_to_gpio(bdata->gpiod), error);
return error;
}
} }
} else if (gpio_is_valid(button->gpio)) { } else if (gpio_is_valid(button->gpio)) {
/* /*
......
...@@ -303,8 +303,10 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) ...@@ -303,8 +303,10 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
bdata->gpiod = devm_get_gpiod_from_child(dev, NULL, bdata->gpiod = devm_fwnode_get_gpiod_from_child(dev,
child); NULL, child,
GPIOD_IN,
button->desc);
if (IS_ERR(bdata->gpiod)) { if (IS_ERR(bdata->gpiod)) {
error = PTR_ERR(bdata->gpiod); error = PTR_ERR(bdata->gpiod);
if (error != -EPROBE_DEFER) if (error != -EPROBE_DEFER)
...@@ -314,14 +316,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) ...@@ -314,14 +316,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
fwnode_handle_put(child); fwnode_handle_put(child);
return error; return error;
} }
error = gpiod_direction_input(bdata->gpiod);
if (error) {
dev_err(dev, "Failed to configure GPIO %d as input: %d\n",
desc_to_gpio(bdata->gpiod), error);
fwnode_handle_put(child);
return error;
}
} else if (gpio_is_valid(button->gpio)) { } else if (gpio_is_valid(button->gpio)) {
/* /*
* Legacy GPIO number so request the GPIO here and * Legacy GPIO number so request the GPIO here and
......
...@@ -174,12 +174,6 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev) ...@@ -174,12 +174,6 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
const char *state = NULL; const char *state = NULL;
struct device_node *np = to_of_node(child); struct device_node *np = to_of_node(child);
led.gpiod = devm_get_gpiod_from_child(dev, NULL, child);
if (IS_ERR(led.gpiod)) {
fwnode_handle_put(child);
return ERR_CAST(led.gpiod);
}
ret = fwnode_property_read_string(child, "label", &led.name); ret = fwnode_property_read_string(child, "label", &led.name);
if (ret && IS_ENABLED(CONFIG_OF) && np) if (ret && IS_ENABLED(CONFIG_OF) && np)
led.name = np->name; led.name = np->name;
...@@ -188,6 +182,14 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev) ...@@ -188,6 +182,14 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
led.gpiod = devm_fwnode_get_gpiod_from_child(dev, NULL, child,
GPIOD_ASIS,
led.name);
if (IS_ERR(led.gpiod)) {
fwnode_handle_put(child);
return ERR_CAST(led.gpiod);
}
fwnode_property_read_string(child, "linux,default-trigger", fwnode_property_read_string(child, "linux,default-trigger",
&led.default_trigger); &led.default_trigger);
......
...@@ -184,32 +184,31 @@ static void tpg110_init(struct device *dev, struct device_node *np, ...@@ -184,32 +184,31 @@ static void tpg110_init(struct device *dev, struct device_node *np,
{ {
dev_info(dev, "TPG110 display init\n"); dev_info(dev, "TPG110 display init\n");
grestb = devm_get_gpiod_from_child(dev, "grestb", &np->fwnode); /* This asserts the GRESTB signal, putting the display into reset */
grestb = devm_fwnode_get_gpiod_from_child(dev, "grestb", &np->fwnode,
GPIOD_OUT_HIGH, "grestb");
if (IS_ERR(grestb)) { if (IS_ERR(grestb)) {
dev_err(dev, "no GRESTB GPIO\n"); dev_err(dev, "no GRESTB GPIO\n");
return; return;
} }
/* This asserts the GRESTB signal, putting the display into reset */ scen = devm_fwnode_get_gpiod_from_child(dev, "scen", &np->fwnode,
gpiod_direction_output(grestb, 1); GPIOD_OUT_LOW, "scen");
scen = devm_get_gpiod_from_child(dev, "scen", &np->fwnode);
if (IS_ERR(scen)) { if (IS_ERR(scen)) {
dev_err(dev, "no SCEN GPIO\n"); dev_err(dev, "no SCEN GPIO\n");
return; return;
} }
gpiod_direction_output(scen, 0); scl = devm_fwnode_get_gpiod_from_child(dev, "scl", &np->fwnode,
scl = devm_get_gpiod_from_child(dev, "scl", &np->fwnode); GPIOD_OUT_LOW, "scl");
if (IS_ERR(scl)) { if (IS_ERR(scl)) {
dev_err(dev, "no SCL GPIO\n"); dev_err(dev, "no SCL GPIO\n");
return; return;
} }
gpiod_direction_output(scl, 0); sda = devm_fwnode_get_gpiod_from_child(dev, "sda", &np->fwnode,
sda = devm_get_gpiod_from_child(dev, "sda", &np->fwnode); GPIOD_OUT_LOW, "sda");
if (IS_ERR(sda)) { if (IS_ERR(sda)) {
dev_err(dev, "no SDA GPIO\n"); dev_err(dev, "no SDA GPIO\n");
return; return;
} }
gpiod_direction_output(sda, 0);
board->enable = tpg110_enable; board->enable = tpg110_enable;
board->disable = tpg110_disable; board->disable = tpg110_disable;
} }
......
...@@ -135,10 +135,24 @@ int desc_to_gpio(const struct gpio_desc *desc); ...@@ -135,10 +135,24 @@ int desc_to_gpio(const struct gpio_desc *desc);
struct fwnode_handle; struct fwnode_handle;
struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
const char *propname); const char *propname, int index,
struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, enum gpiod_flags dflags,
const char *con_id, const char *label);
struct fwnode_handle *child); struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
const char *con_id, int index,
struct fwnode_handle *child,
enum gpiod_flags flags,
const char *label);
/* FIXME: delete this helper when users are switched over */
static inline struct gpio_desc *devm_get_gpiod_from_child(struct device *dev,
const char *con_id, struct fwnode_handle *child)
{
return devm_fwnode_get_index_gpiod_from_child(dev, con_id,
0, child,
GPIOD_ASIS,
"?");
}
#else /* CONFIG_GPIOLIB */ #else /* CONFIG_GPIOLIB */
static inline int gpiod_count(struct device *dev, const char *con_id) static inline int gpiod_count(struct device *dev, const char *con_id)
...@@ -411,20 +425,45 @@ static inline int desc_to_gpio(const struct gpio_desc *desc) ...@@ -411,20 +425,45 @@ static inline int desc_to_gpio(const struct gpio_desc *desc)
/* Child properties interface */ /* Child properties interface */
struct fwnode_handle; struct fwnode_handle;
static inline struct gpio_desc *fwnode_get_named_gpiod( static inline
struct fwnode_handle *fwnode, const char *propname) struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
const char *propname, int index,
enum gpiod_flags dflags,
const char *label)
{ {
return ERR_PTR(-ENOSYS); return ERR_PTR(-ENOSYS);
} }
static inline struct gpio_desc *devm_get_gpiod_from_child( static inline
struct device *dev, const char *con_id, struct fwnode_handle *child) struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
const char *con_id, int index,
struct fwnode_handle *child,
enum gpiod_flags flags,
const char *label)
{
return ERR_PTR(-ENOSYS);
}
/* FIXME: delete this when all users are switched over */
static inline struct gpio_desc *devm_get_gpiod_from_child(struct device *dev,
const char *con_id, struct fwnode_handle *child)
{ {
return ERR_PTR(-ENOSYS); return ERR_PTR(-ENOSYS);
} }
#endif /* CONFIG_GPIOLIB */ #endif /* CONFIG_GPIOLIB */
static inline
struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
const char *con_id,
struct fwnode_handle *child,
enum gpiod_flags flags,
const char *label)
{
return devm_fwnode_get_index_gpiod_from_child(dev, con_id, 0, child,
flags, label);
}
#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
int gpiod_export(struct gpio_desc *desc, bool direction_may_change); int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
......
...@@ -21,23 +21,28 @@ ...@@ -21,23 +21,28 @@
#include <asm-generic/gpio.h> #include <asm-generic/gpio.h>
#define MAX_REGS_BANKS 5
struct davinci_gpio_platform_data { struct davinci_gpio_platform_data {
u32 ngpio; u32 ngpio;
u32 gpio_unbanked; u32 gpio_unbanked;
}; };
struct davinci_gpio_irq_data {
void __iomem *regs;
struct davinci_gpio_controller *chip;
int bank_num;
};
struct davinci_gpio_controller { struct davinci_gpio_controller {
struct gpio_chip chip; struct gpio_chip chip;
struct irq_domain *irq_domain; struct irq_domain *irq_domain;
/* Serialize access to GPIO registers */ /* Serialize access to GPIO registers */
spinlock_t lock; spinlock_t lock;
void __iomem *regs; void __iomem *regs[MAX_REGS_BANKS];
void __iomem *set_data;
void __iomem *clr_data;
void __iomem *in_data;
int gpio_unbanked; int gpio_unbanked;
unsigned gpio_irq; unsigned int base_irq;
unsigned int base;
}; };
/* /*
......
gpio-event-mon
gpio-hammer
lsgpio
...@@ -38,7 +38,7 @@ int hammer_device(const char *device_name, unsigned int *lines, int nlines, ...@@ -38,7 +38,7 @@ int hammer_device(const char *device_name, unsigned int *lines, int nlines,
memset(&data.values, 0, sizeof(data.values)); memset(&data.values, 0, sizeof(data.values));
ret = gpiotools_request_linehandle(device_name, lines, nlines, ret = gpiotools_request_linehandle(device_name, lines, nlines,
GPIOHANDLE_REQUEST_OUTPUT, &data, GPIOHANDLE_REQUEST_OUTPUT, &data,
"gpio-hammler"); "gpio-hammer");
if (ret < 0) if (ret < 0)
goto exit_error; goto exit_error;
else else
......
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