gpio: vf610: use container_of() to get state container
The state container of the vf610 GPIO driver is sometimes extracted from the gpio_chip exploiting the fact that offsetof() the struct gpio_chip inside the struct vf610_gpio_port is 0, so the container_of() is in practice a noop. However if a member is added to struct vf610_gpio_port 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. Acked-by: Stefan Agner <stefan@agner.ch> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
This commit is contained in:
parent
218f1f8b50
commit
2f930643c5
1 changed files with 19 additions and 10 deletions
|
@ -62,6 +62,11 @@ struct vf610_gpio_port {
|
||||||
|
|
||||||
static struct irq_chip vf610_gpio_irq_chip;
|
static struct irq_chip vf610_gpio_irq_chip;
|
||||||
|
|
||||||
|
static struct vf610_gpio_port *to_vf610_gp(struct gpio_chip *gc)
|
||||||
|
{
|
||||||
|
return container_of(gc, struct vf610_gpio_port, gc);
|
||||||
|
}
|
||||||
|
|
||||||
static const struct of_device_id vf610_gpio_dt_ids[] = {
|
static const struct of_device_id vf610_gpio_dt_ids[] = {
|
||||||
{ .compatible = "fsl,vf610-gpio" },
|
{ .compatible = "fsl,vf610-gpio" },
|
||||||
{ /* sentinel */ }
|
{ /* sentinel */ }
|
||||||
|
@ -89,16 +94,14 @@ static void vf610_gpio_free(struct gpio_chip *chip, unsigned offset)
|
||||||
|
|
||||||
static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio)
|
static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio)
|
||||||
{
|
{
|
||||||
struct vf610_gpio_port *port =
|
struct vf610_gpio_port *port = to_vf610_gp(gc);
|
||||||
container_of(gc, struct vf610_gpio_port, gc);
|
|
||||||
|
|
||||||
return !!(vf610_gpio_readl(port->gpio_base + GPIO_PDIR) & BIT(gpio));
|
return !!(vf610_gpio_readl(port->gpio_base + GPIO_PDIR) & BIT(gpio));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
|
static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
|
||||||
{
|
{
|
||||||
struct vf610_gpio_port *port =
|
struct vf610_gpio_port *port = to_vf610_gp(gc);
|
||||||
container_of(gc, struct vf610_gpio_port, gc);
|
|
||||||
unsigned long mask = BIT(gpio);
|
unsigned long mask = BIT(gpio);
|
||||||
|
|
||||||
if (val)
|
if (val)
|
||||||
|
@ -122,7 +125,8 @@ static int vf610_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
|
||||||
|
|
||||||
static void vf610_gpio_irq_handler(struct irq_desc *desc)
|
static void vf610_gpio_irq_handler(struct irq_desc *desc)
|
||||||
{
|
{
|
||||||
struct vf610_gpio_port *port = irq_desc_get_handler_data(desc);
|
struct vf610_gpio_port *port =
|
||||||
|
to_vf610_gp(irq_desc_get_handler_data(desc));
|
||||||
struct irq_chip *chip = irq_desc_get_chip(desc);
|
struct irq_chip *chip = irq_desc_get_chip(desc);
|
||||||
int pin;
|
int pin;
|
||||||
unsigned long irq_isfr;
|
unsigned long irq_isfr;
|
||||||
|
@ -142,7 +146,8 @@ static void vf610_gpio_irq_handler(struct irq_desc *desc)
|
||||||
|
|
||||||
static void vf610_gpio_irq_ack(struct irq_data *d)
|
static void vf610_gpio_irq_ack(struct irq_data *d)
|
||||||
{
|
{
|
||||||
struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d);
|
struct vf610_gpio_port *port =
|
||||||
|
to_vf610_gp(irq_data_get_irq_chip_data(d));
|
||||||
int gpio = d->hwirq;
|
int gpio = d->hwirq;
|
||||||
|
|
||||||
vf610_gpio_writel(BIT(gpio), port->base + PORT_ISFR);
|
vf610_gpio_writel(BIT(gpio), port->base + PORT_ISFR);
|
||||||
|
@ -150,7 +155,8 @@ static void vf610_gpio_irq_ack(struct irq_data *d)
|
||||||
|
|
||||||
static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type)
|
static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type)
|
||||||
{
|
{
|
||||||
struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d);
|
struct vf610_gpio_port *port =
|
||||||
|
to_vf610_gp(irq_data_get_irq_chip_data(d));
|
||||||
u8 irqc;
|
u8 irqc;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -185,7 +191,8 @@ static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type)
|
||||||
|
|
||||||
static void vf610_gpio_irq_mask(struct irq_data *d)
|
static void vf610_gpio_irq_mask(struct irq_data *d)
|
||||||
{
|
{
|
||||||
struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d);
|
struct vf610_gpio_port *port =
|
||||||
|
to_vf610_gp(irq_data_get_irq_chip_data(d));
|
||||||
void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq);
|
void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq);
|
||||||
|
|
||||||
vf610_gpio_writel(0, pcr_base);
|
vf610_gpio_writel(0, pcr_base);
|
||||||
|
@ -193,7 +200,8 @@ static void vf610_gpio_irq_mask(struct irq_data *d)
|
||||||
|
|
||||||
static void vf610_gpio_irq_unmask(struct irq_data *d)
|
static void vf610_gpio_irq_unmask(struct irq_data *d)
|
||||||
{
|
{
|
||||||
struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d);
|
struct vf610_gpio_port *port =
|
||||||
|
to_vf610_gp(irq_data_get_irq_chip_data(d));
|
||||||
void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq);
|
void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq);
|
||||||
|
|
||||||
vf610_gpio_writel(port->irqc[d->hwirq] << PORT_PCR_IRQC_OFFSET,
|
vf610_gpio_writel(port->irqc[d->hwirq] << PORT_PCR_IRQC_OFFSET,
|
||||||
|
@ -202,7 +210,8 @@ static void vf610_gpio_irq_unmask(struct irq_data *d)
|
||||||
|
|
||||||
static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable)
|
static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable)
|
||||||
{
|
{
|
||||||
struct vf610_gpio_port *port = irq_data_get_irq_chip_data(d);
|
struct vf610_gpio_port *port =
|
||||||
|
to_vf610_gp(irq_data_get_irq_chip_data(d));
|
||||||
|
|
||||||
if (enable)
|
if (enable)
|
||||||
enable_irq_wake(port->irq);
|
enable_irq_wake(port->irq);
|
||||||
|
|
Loading…
Add table
Reference in a new issue