Commit fa9795d1 authored by Linus Walleij's avatar Linus Walleij

gpio: zynq: use container_of() to get state container

The state container of the Zynq GPIO driver is sometimes
extracted from the gpio_chip exploiting the fact that offsetof()
the struct gpio_chip inside the struct zynq_gpio is 0, so
the container_of() is in practice a noop. However if a member
is added to struct zynq_gpio in front of struct gpio_chip,
things will break. Using proper container_of() avoids this
problem.

Semantically this is a noop, the compiler will optimize it away,
but syntactically it makes me happier.

Also replace some explicit container_of() calls with the helper
function.

Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Ezra Savard <ezra.savard@xilinx.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Acked-by: default avatarHarini Katakam <harinik@xilinx.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 2f930643
...@@ -130,6 +130,12 @@ struct zynq_platform_data { ...@@ -130,6 +130,12 @@ struct zynq_platform_data {
static struct irq_chip zynq_gpio_level_irqchip; static struct irq_chip zynq_gpio_level_irqchip;
static struct irq_chip zynq_gpio_edge_irqchip; static struct irq_chip zynq_gpio_edge_irqchip;
static struct zynq_gpio *to_zynq_gpio(struct gpio_chip *gc)
{
return container_of(gc, struct zynq_gpio, chip);
}
/** /**
* zynq_gpio_get_bank_pin - Get the bank number and pin number within that bank * zynq_gpio_get_bank_pin - Get the bank number and pin number within that bank
* for a given pin in the GPIO device * for a given pin in the GPIO device
...@@ -177,7 +183,7 @@ static int zynq_gpio_get_value(struct gpio_chip *chip, unsigned int pin) ...@@ -177,7 +183,7 @@ static int zynq_gpio_get_value(struct gpio_chip *chip, unsigned int pin)
{ {
u32 data; u32 data;
unsigned int bank_num, bank_pin_num; unsigned int bank_num, bank_pin_num;
struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); struct zynq_gpio *gpio = to_zynq_gpio(chip);
zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio);
...@@ -201,7 +207,7 @@ static void zynq_gpio_set_value(struct gpio_chip *chip, unsigned int pin, ...@@ -201,7 +207,7 @@ static void zynq_gpio_set_value(struct gpio_chip *chip, unsigned int pin,
int state) int state)
{ {
unsigned int reg_offset, bank_num, bank_pin_num; unsigned int reg_offset, bank_num, bank_pin_num;
struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); struct zynq_gpio *gpio = to_zynq_gpio(chip);
zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio);
...@@ -238,7 +244,7 @@ static int zynq_gpio_dir_in(struct gpio_chip *chip, unsigned int pin) ...@@ -238,7 +244,7 @@ static int zynq_gpio_dir_in(struct gpio_chip *chip, unsigned int pin)
{ {
u32 reg; u32 reg;
unsigned int bank_num, bank_pin_num; unsigned int bank_num, bank_pin_num;
struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); struct zynq_gpio *gpio = to_zynq_gpio(chip);
zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio);
...@@ -271,7 +277,7 @@ static int zynq_gpio_dir_out(struct gpio_chip *chip, unsigned int pin, ...@@ -271,7 +277,7 @@ static int zynq_gpio_dir_out(struct gpio_chip *chip, unsigned int pin,
{ {
u32 reg; u32 reg;
unsigned int bank_num, bank_pin_num; unsigned int bank_num, bank_pin_num;
struct zynq_gpio *gpio = container_of(chip, struct zynq_gpio, chip); struct zynq_gpio *gpio = to_zynq_gpio(chip);
zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio); zynq_gpio_get_bank_pin(pin, &bank_num, &bank_pin_num, gpio);
...@@ -301,7 +307,8 @@ static int zynq_gpio_dir_out(struct gpio_chip *chip, unsigned int pin, ...@@ -301,7 +307,8 @@ static int zynq_gpio_dir_out(struct gpio_chip *chip, unsigned int pin,
static void zynq_gpio_irq_mask(struct irq_data *irq_data) static void zynq_gpio_irq_mask(struct irq_data *irq_data)
{ {
unsigned int device_pin_num, bank_num, bank_pin_num; unsigned int device_pin_num, bank_num, bank_pin_num;
struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); struct zynq_gpio *gpio =
to_zynq_gpio(irq_data_get_irq_chip_data(irq_data));
device_pin_num = irq_data->hwirq; device_pin_num = irq_data->hwirq;
zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio);
...@@ -321,7 +328,8 @@ static void zynq_gpio_irq_mask(struct irq_data *irq_data) ...@@ -321,7 +328,8 @@ static void zynq_gpio_irq_mask(struct irq_data *irq_data)
static void zynq_gpio_irq_unmask(struct irq_data *irq_data) static void zynq_gpio_irq_unmask(struct irq_data *irq_data)
{ {
unsigned int device_pin_num, bank_num, bank_pin_num; unsigned int device_pin_num, bank_num, bank_pin_num;
struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); struct zynq_gpio *gpio =
to_zynq_gpio(irq_data_get_irq_chip_data(irq_data));
device_pin_num = irq_data->hwirq; device_pin_num = irq_data->hwirq;
zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio);
...@@ -340,7 +348,8 @@ static void zynq_gpio_irq_unmask(struct irq_data *irq_data) ...@@ -340,7 +348,8 @@ static void zynq_gpio_irq_unmask(struct irq_data *irq_data)
static void zynq_gpio_irq_ack(struct irq_data *irq_data) static void zynq_gpio_irq_ack(struct irq_data *irq_data)
{ {
unsigned int device_pin_num, bank_num, bank_pin_num; unsigned int device_pin_num, bank_num, bank_pin_num;
struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); struct zynq_gpio *gpio =
to_zynq_gpio(irq_data_get_irq_chip_data(irq_data));
device_pin_num = irq_data->hwirq; device_pin_num = irq_data->hwirq;
zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio);
...@@ -390,7 +399,8 @@ static int zynq_gpio_set_irq_type(struct irq_data *irq_data, unsigned int type) ...@@ -390,7 +399,8 @@ static int zynq_gpio_set_irq_type(struct irq_data *irq_data, unsigned int type)
{ {
u32 int_type, int_pol, int_any; u32 int_type, int_pol, int_any;
unsigned int device_pin_num, bank_num, bank_pin_num; unsigned int device_pin_num, bank_num, bank_pin_num;
struct zynq_gpio *gpio = irq_data_get_irq_chip_data(irq_data); struct zynq_gpio *gpio =
to_zynq_gpio(irq_data_get_irq_chip_data(irq_data));
device_pin_num = irq_data->hwirq; device_pin_num = irq_data->hwirq;
zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio); zynq_gpio_get_bank_pin(device_pin_num, &bank_num, &bank_pin_num, gpio);
...@@ -453,7 +463,8 @@ static int zynq_gpio_set_irq_type(struct irq_data *irq_data, unsigned int type) ...@@ -453,7 +463,8 @@ static int zynq_gpio_set_irq_type(struct irq_data *irq_data, unsigned int type)
static int zynq_gpio_set_wake(struct irq_data *data, unsigned int on) static int zynq_gpio_set_wake(struct irq_data *data, unsigned int on)
{ {
struct zynq_gpio *gpio = irq_data_get_irq_chip_data(data); struct zynq_gpio *gpio =
to_zynq_gpio(irq_data_get_irq_chip_data(data));
irq_set_irq_wake(gpio->irq, on); irq_set_irq_wake(gpio->irq, on);
...@@ -518,7 +529,8 @@ static void zynq_gpio_irqhandler(struct irq_desc *desc) ...@@ -518,7 +529,8 @@ static void zynq_gpio_irqhandler(struct irq_desc *desc)
{ {
u32 int_sts, int_enb; u32 int_sts, int_enb;
unsigned int bank_num; unsigned int bank_num;
struct zynq_gpio *gpio = irq_desc_get_handler_data(desc); struct zynq_gpio *gpio =
to_zynq_gpio(irq_desc_get_handler_data(desc));
struct irq_chip *irqchip = irq_desc_get_chip(desc); struct irq_chip *irqchip = irq_desc_get_chip(desc);
chained_irq_enter(irqchip, desc); chained_irq_enter(irqchip, desc);
......
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