diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-01-17 21:32:01 +0100 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-01-17 21:32:01 +0100 |
commit | 58cf279acac3080ce03eeea5ca268210b3165fe1 (patch) | |
tree | 54997706fbfea2cd9fd4c4044edbd8ecdc154dfb /drivers/gpio/gpio-pca953x.c | |
parent | Merge git://www.linux-watchdog.org/linux-watchdog (diff) | |
parent | gpio: generic: make bgpio_pdata always visible (diff) | |
download | linux-58cf279acac3080ce03eeea5ca268210b3165fe1.tar.xz linux-58cf279acac3080ce03eeea5ca268210b3165fe1.zip |
Merge tag 'gpio-v4.5-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO updates from Linus Walleij:
"Here is the bulk of GPIO changes for v4.5.
Notably there are big refactorings mostly by myself, aimed at getting
the gpio_chip into a shape that makes me believe I can proceed to
preserve state for a proper userspace ABI (character device) that has
already been proposed once, but resulted in the feedback that I need
to go back and restructure stuff. So I've been restructuring stuff.
On the way I ran into brokenness (return code from the get_value()
callback) and had to fix it. Also, refactored generic GPIO to be
simpler.
Some of that is still waiting to trickle down from the subsystems all
over the kernel that provide random gpio_chips, I've touched every
single GPIO driver in the kernel now, oh man I didn't know I was
responsible for so much...
Apart from that we're churning along as usual.
I took some effort to test and retest so it should merge nicely and we
shook out a couple of bugs in -next.
Infrastructural changes:
- In struct gpio_chip, rename the .dev node to .parent to better
reflect the fact that this is not the GPIO struct device
abstraction. We will add that soon so this would be totallt
confusing.
- It was noted that the driver .get_value() callbacks was sometimes
reporting negative -ERR values to the gpiolib core, expecting them
to be propagated to consumer gpiod_get_value() and gpio_get_value()
calls. This was not happening, so as there was a mess of drivers
returning negative errors and some returning "anything else than
zero" to indicate that a line was active. As some would have bit
31 set to indicate "line active" it clashed with negative error
codes. This is fixed by the largeish series clamping values in all
drivers with !!value to [0,1] and then augmenting the code to
propagate error codes to consumers. (Includes some ACKed patches
in other subsystems.)
- Add a void *data pointer to struct gpio_chip. The container_of()
design pattern is indeed very nice, but we want to reform the
struct gpio_chip to be a non-volative, stateless business, and keep
states internal to the gpiolib to be able to hold on to the state
when adding a proper userspace ABI (character device) further down
the road. To achieve this, drivers need a handle at the internal
state that is not dependent on their struct gpio_chip() so we add
gpiochip_add_data() and gpiochip_get_data() following the pattern
of many other subsystems. All the "use gpiochip data pointer"
patches transforms drivers to this scheme.
- The Generic GPIO chip header has been merged into the general
<linux/gpio/driver.h> header, and the custom header for that
removed. Instead of having a separate mm_gpio_chip struct for
these generic drivers, merge that into struct gpio_chip,
simplifying the code and removing the need for separate and
confusing includes.
Misc improvements:
- Stabilize the way GPIOs are looked up from the ACPI legacy
specification.
- Incremental driver features for PXA, PCA953X, Lantiq (patches from
the OpenWRT community), RCAR, Zynq, PL061, 104-idi-48
New drivers:
- Add a GPIO chip to the ALSA SoC AC97 driver.
- Add a new Broadcom NSP SoC driver (this lands in the pinctrl dir,
but the branch is merged here too to account for infrastructural
changes).
- The sx150x driver now supports the sx1502"
* tag 'gpio-v4.5-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (220 commits)
gpio: generic: make bgpio_pdata always visible
gpiolib: fix chip order in gpio list
gpio: mpc8xxx: Do not use gpiochip_get_data() in mpc8xxx_gpio_save_regs()
gpio: mm-lantiq: Do not use gpiochip_get_data() in ltq_mm_save_regs()
gpio: brcmstb: Allow building driver for BMIPS_GENERIC
gpio: brcmstb: Set endian flags for big-endian MIPS
gpio: moxart: fix build regression
gpio: xilinx: Do not use gpiochip_get_data() in xgpio_save_regs()
leds: pca9532: use gpiochip data pointer
leds: tca6507: use gpiochip data pointer
hid: cp2112: use gpiochip data pointer
bcma: gpio: use gpiochip data pointer
avr32: gpio: use gpiochip data pointer
video: fbdev: via: use gpiochip data pointer
gpio: pch: Optimize pch_gpio_get()
Revert "pinctrl: lantiq: Implement gpio_chip.to_irq"
pinctrl: nsp-gpio: use gpiochip data pointer
pinctrl: vt8500-wmt: use gpiochip data pointer
pinctrl: exynos5440: use gpiochip data pointer
pinctrl: at91-pio4: use gpiochip data pointer
...
Diffstat (limited to 'drivers/gpio/gpio-pca953x.c')
-rw-r--r-- | drivers/gpio/gpio-pca953x.c | 141 |
1 files changed, 93 insertions, 48 deletions
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 2d4892cc70fb..23196c5fc17c 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -18,9 +18,7 @@ #include <linux/i2c.h> #include <linux/platform_data/pca953x.h> #include <linux/slab.h> -#ifdef CONFIG_OF_GPIO #include <linux/of_platform.h> -#endif #include <linux/acpi.h> #define PCA953X_INPUT 0 @@ -109,11 +107,6 @@ struct pca953x_chip { unsigned long driver_data; }; -static inline struct pca953x_chip *to_pca(struct gpio_chip *gc) -{ - return container_of(gc, struct pca953x_chip, gpio_chip); -} - static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val, int off) { @@ -216,7 +209,7 @@ static int pca953x_read_regs(struct pca953x_chip *chip, int reg, u8 *val) static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off) { - struct pca953x_chip *chip = to_pca(gc); + struct pca953x_chip *chip = gpiochip_get_data(gc); u8 reg_val; int ret, offset = 0; @@ -245,7 +238,7 @@ exit: static int pca953x_gpio_direction_output(struct gpio_chip *gc, unsigned off, int val) { - struct pca953x_chip *chip = to_pca(gc); + struct pca953x_chip *chip = gpiochip_get_data(gc); u8 reg_val; int ret, offset = 0; @@ -295,7 +288,7 @@ exit: static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) { - struct pca953x_chip *chip = to_pca(gc); + struct pca953x_chip *chip = gpiochip_get_data(gc); u32 reg_val; int ret, offset = 0; @@ -323,7 +316,7 @@ static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) { - struct pca953x_chip *chip = to_pca(gc); + struct pca953x_chip *chip = gpiochip_get_data(gc); u8 reg_val; int ret, offset = 0; @@ -352,6 +345,43 @@ exit: mutex_unlock(&chip->i2c_lock); } + +static void pca953x_gpio_set_multiple(struct gpio_chip *gc, + unsigned long *mask, unsigned long *bits) +{ + struct pca953x_chip *chip = gpiochip_get_data(gc); + u8 reg_val[MAX_BANK]; + int ret, offset = 0; + int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); + int bank; + + switch (chip->chip_type) { + case PCA953X_TYPE: + offset = PCA953X_OUTPUT; + break; + case PCA957X_TYPE: + offset = PCA957X_OUT; + break; + } + + memcpy(reg_val, chip->reg_output, NBANK(chip)); + mutex_lock(&chip->i2c_lock); + for(bank=0; bank<NBANK(chip); bank++) { + unsigned bankmask = mask[bank/4] >> ((bank % 4) * 8); + if(bankmask) { + unsigned bankval = bits[bank/4] >> ((bank % 4) * 8); + reg_val[bank] = (reg_val[bank] & ~bankmask) | bankval; + } + } + ret = i2c_smbus_write_i2c_block_data(chip->client, offset << bank_shift, NBANK(chip), reg_val); + if (ret) + goto exit; + + memcpy(chip->reg_output, reg_val, NBANK(chip)); +exit: + mutex_unlock(&chip->i2c_lock); +} + static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios) { struct gpio_chip *gc; @@ -362,12 +392,13 @@ static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios) gc->direction_output = pca953x_gpio_direction_output; gc->get = pca953x_gpio_get_value; gc->set = pca953x_gpio_set_value; + gc->set_multiple = pca953x_gpio_set_multiple; gc->can_sleep = true; gc->base = chip->gpio_start; gc->ngpio = gpios; gc->label = chip->client->name; - gc->dev = &chip->client->dev; + gc->parent = &chip->client->dev; gc->owner = THIS_MODULE; gc->names = chip->names; } @@ -376,7 +407,7 @@ static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios) static void pca953x_irq_mask(struct irq_data *d) { struct gpio_chip *gc = irq_data_get_irq_chip_data(d); - struct pca953x_chip *chip = to_pca(gc); + struct pca953x_chip *chip = gpiochip_get_data(gc); chip->irq_mask[d->hwirq / BANK_SZ] &= ~(1 << (d->hwirq % BANK_SZ)); } @@ -384,7 +415,7 @@ static void pca953x_irq_mask(struct irq_data *d) static void pca953x_irq_unmask(struct irq_data *d) { struct gpio_chip *gc = irq_data_get_irq_chip_data(d); - struct pca953x_chip *chip = to_pca(gc); + struct pca953x_chip *chip = gpiochip_get_data(gc); chip->irq_mask[d->hwirq / BANK_SZ] |= 1 << (d->hwirq % BANK_SZ); } @@ -392,7 +423,7 @@ static void pca953x_irq_unmask(struct irq_data *d) static void pca953x_irq_bus_lock(struct irq_data *d) { struct gpio_chip *gc = irq_data_get_irq_chip_data(d); - struct pca953x_chip *chip = to_pca(gc); + struct pca953x_chip *chip = gpiochip_get_data(gc); mutex_lock(&chip->irq_lock); } @@ -400,7 +431,7 @@ static void pca953x_irq_bus_lock(struct irq_data *d) static void pca953x_irq_bus_sync_unlock(struct irq_data *d) { struct gpio_chip *gc = irq_data_get_irq_chip_data(d); - struct pca953x_chip *chip = to_pca(gc); + struct pca953x_chip *chip = gpiochip_get_data(gc); u8 new_irqs; int level, i; @@ -423,7 +454,7 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d) static int pca953x_irq_set_type(struct irq_data *d, unsigned int type) { struct gpio_chip *gc = irq_data_get_irq_chip_data(d); - struct pca953x_chip *chip = to_pca(gc); + struct pca953x_chip *chip = gpiochip_get_data(gc); int bank_nb = d->hwirq / BANK_SZ; u8 mask = 1 << (d->hwirq % BANK_SZ); @@ -660,6 +691,8 @@ out: return ret; } +static const struct of_device_id pca953x_dt_ids[]; + static int pca953x_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -691,12 +724,18 @@ static int pca953x_probe(struct i2c_client *client, chip->driver_data = id->driver_data; } else { const struct acpi_device_id *id; + const struct of_device_id *match; - id = acpi_match_device(pca953x_acpi_ids, &client->dev); - if (!id) - return -ENODEV; + match = of_match_device(pca953x_dt_ids, &client->dev); + if (match) { + chip->driver_data = (int)(uintptr_t)match->data; + } else { + id = acpi_match_device(pca953x_acpi_ids, &client->dev); + if (!id) + return -ENODEV; - chip->driver_data = id->driver_data; + chip->driver_data = id->driver_data; + } } chip->chip_type = PCA_CHIP_TYPE(chip->driver_data); @@ -715,7 +754,7 @@ static int pca953x_probe(struct i2c_client *client, if (ret) return ret; - ret = gpiochip_add(&chip->gpio_chip); + ret = gpiochip_add_data(&chip->gpio_chip, chip); if (ret) return ret; @@ -755,33 +794,39 @@ static int pca953x_remove(struct i2c_client *client) return 0; } +/* convenience to stop overlong match-table lines */ +#define OF_953X(__nrgpio, __int) (void *)(__nrgpio | PCA953X_TYPE | __int) +#define OF_957X(__nrgpio, __int) (void *)(__nrgpio | PCA957X_TYPE | __int) + static const struct of_device_id pca953x_dt_ids[] = { - { .compatible = "nxp,pca9505", }, - { .compatible = "nxp,pca9534", }, - { .compatible = "nxp,pca9535", }, - { .compatible = "nxp,pca9536", }, - { .compatible = "nxp,pca9537", }, - { .compatible = "nxp,pca9538", }, - { .compatible = "nxp,pca9539", }, - { .compatible = "nxp,pca9554", }, - { .compatible = "nxp,pca9555", }, - { .compatible = "nxp,pca9556", }, - { .compatible = "nxp,pca9557", }, - { .compatible = "nxp,pca9574", }, - { .compatible = "nxp,pca9575", }, - { .compatible = "nxp,pca9698", }, - - { .compatible = "maxim,max7310", }, - { .compatible = "maxim,max7312", }, - { .compatible = "maxim,max7313", }, - { .compatible = "maxim,max7315", }, - - { .compatible = "ti,pca6107", }, - { .compatible = "ti,tca6408", }, - { .compatible = "ti,tca6416", }, - { .compatible = "ti,tca6424", }, - - { .compatible = "exar,xra1202", }, + { .compatible = "nxp,pca9505", .data = OF_953X(40, PCA_INT), }, + { .compatible = "nxp,pca9534", .data = OF_953X( 8, PCA_INT), }, + { .compatible = "nxp,pca9535", .data = OF_953X(16, PCA_INT), }, + { .compatible = "nxp,pca9536", .data = OF_953X( 4, 0), }, + { .compatible = "nxp,pca9537", .data = OF_953X( 4, PCA_INT), }, + { .compatible = "nxp,pca9538", .data = OF_953X( 8, PCA_INT), }, + { .compatible = "nxp,pca9539", .data = OF_953X(16, PCA_INT), }, + { .compatible = "nxp,pca9554", .data = OF_953X( 8, PCA_INT), }, + { .compatible = "nxp,pca9555", .data = OF_953X(16, PCA_INT), }, + { .compatible = "nxp,pca9556", .data = OF_953X( 8, 0), }, + { .compatible = "nxp,pca9557", .data = OF_953X( 8, 0), }, + { .compatible = "nxp,pca9574", .data = OF_957X( 8, PCA_INT), }, + { .compatible = "nxp,pca9575", .data = OF_957X(16, PCA_INT), }, + { .compatible = "nxp,pca9698", .data = OF_953X(40, 0), }, + + { .compatible = "maxim,max7310", .data = OF_953X( 8, 0), }, + { .compatible = "maxim,max7312", .data = OF_953X(16, PCA_INT), }, + { .compatible = "maxim,max7313", .data = OF_953X(16, PCA_INT), }, + { .compatible = "maxim,max7315", .data = OF_953X( 8, PCA_INT), }, + + { .compatible = "ti,pca6107", .data = OF_953X( 8, PCA_INT), }, + { .compatible = "ti,tca6408", .data = OF_953X( 8, PCA_INT), }, + { .compatible = "ti,tca6416", .data = OF_953X(16, PCA_INT), }, + { .compatible = "ti,tca6424", .data = OF_953X(24, PCA_INT), }, + + { .compatible = "onsemi,pca9654", .data = OF_953X( 8, PCA_INT), }, + + { .compatible = "exar,xra1202", .data = OF_953X( 8, 0), }, { } }; |