From 468e67f6eb7494e3c4d4d644f281d0ba0cc265c6 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Mon, 7 Dec 2015 11:20:54 +0100 Subject: [PATCH] gpio: pca953x: use gpiochip data pointer This makes the driver use the data pointer added to the gpio_chip to store a pointer to the state container instead of relying on container_of(). Cc: Grygorii Strashko Cc: Markus Pargmann Cc: Toby Smith Signed-off-by: Linus Walleij --- drivers/gpio/gpio-pca953x.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index be3e3b903ff0..23196c5fc17c 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -107,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) { @@ -214,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; @@ -243,7 +238,7 @@ static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off) 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; @@ -293,7 +288,7 @@ static int pca953x_gpio_direction_output(struct gpio_chip *gc, 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; @@ -321,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; @@ -354,7 +349,7 @@ static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) static void pca953x_gpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits) { - struct pca953x_chip *chip = to_pca(gc); + 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); @@ -412,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)); } @@ -420,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); } @@ -428,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); } @@ -436,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; @@ -459,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); @@ -759,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;