Skip to content

Commit

Permalink
gpio: change member .dev to .parent
Browse files Browse the repository at this point in the history
The name .dev in a struct is normally reserved for a struct device
that is let us say a superclass to the thing described by the struct.
struct gpio_chip stands out by confusingly using a struct device *dev
to point to the parent device (such as a platform_device) that
represents the hardware. As we want to give gpio_chip:s real devices,
this is not working. We need to rename this member to parent.

This was done by two coccinelle scripts, I guess it is possible to
combine them into one, but I don't know such stuff. They look like
this:

@@
struct gpio_chip *var;
@@
-var->dev
+var->parent

and:

@@
struct gpio_chip var;
@@
-var.dev
+var.parent

and:

@@
struct bgpio_chip *var;
@@
-var->gc.dev
+var->gc.parent

Plus a few instances of bgpio that I couldn't figure out how
to teach Coccinelle to rewrite.

This patch hits all over the place, but I *strongly* prefer this
solution to any piecemal approaches that just exercise patch
mechanics all over the place. It mainly hits drivers/gpio and
drivers/pinctrl which is my own backyard anyway.

Cc: Haavard Skinnemoen <[email protected]>
Cc: Rafał Miłecki <[email protected]>
Cc: Richard Purdie <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Alek Du <[email protected]>
Cc: Jaroslav Kysela <[email protected]>
Cc: Takashi Iwai <[email protected]>
Acked-by: Dmitry Torokhov <[email protected]>
Acked-by: Greg Kroah-Hartman <[email protected]>
Acked-by: Lee Jones <[email protected]>
Acked-by: Jiri Kosina <[email protected]>
Acked-by: Hans-Christian Egtvedt <[email protected]>
Acked-by: Jacek Anaszewski <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
  • Loading branch information
linusw committed Nov 19, 2015
1 parent 8005c49 commit 58383c7
Show file tree
Hide file tree
Showing 128 changed files with 274 additions and 261 deletions.
2 changes: 1 addition & 1 deletion arch/avr32/mach-at32ap/pio.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ static int __init pio_probe(struct platform_device *pdev)
pio->chip.label = pio->name;
pio->chip.base = pdev->id * 32;
pio->chip.ngpio = 32;
pio->chip.dev = &pdev->dev;
pio->chip.parent = &pdev->dev;
pio->chip.owner = THIS_MODULE;

pio->chip.direction_input = direction_input;
Expand Down
2 changes: 1 addition & 1 deletion drivers/bcma/driver_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int bcma_gpio_init(struct bcma_drv_cc *cc)
chip->direction_input = bcma_gpio_direction_input;
chip->direction_output = bcma_gpio_direction_output;
chip->owner = THIS_MODULE;
chip->dev = bcma_bus_get_host_dev(bus);
chip->parent = bcma_bus_get_host_dev(bus);
#if IS_BUILTIN(CONFIG_OF)
if (cc->core->bus->hosttype == BCMA_HOSTTYPE_SOC)
chip->of_node = cc->core->dev.of_node;
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-104-idio-16.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static int __init idio_16_probe(struct platform_device *pdev)
}

idio16gpio->chip.label = NAME;
idio16gpio->chip.dev = dev;
idio16gpio->chip.parent = dev;
idio16gpio->chip.owner = THIS_MODULE;
idio16gpio->chip.base = -1;
idio16gpio->chip.ngpio = 32;
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpio/gpio-74x164.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static struct gen_74x164_chip *gpio_to_74x164_chip(struct gpio_chip *gc)

static int __gen_74x164_write_config(struct gen_74x164_chip *chip)
{
struct spi_device *spi = to_spi_device(chip->gpio_chip.dev);
struct spi_device *spi = to_spi_device(chip->gpio_chip.parent);
struct spi_message message;
struct spi_transfer *msg_buf;
int i, ret = 0;
Expand Down Expand Up @@ -143,7 +143,7 @@ static int gen_74x164_probe(struct spi_device *spi)
return -ENOMEM;

chip->gpio_chip.can_sleep = true;
chip->gpio_chip.dev = &spi->dev;
chip->gpio_chip.parent = &spi->dev;
chip->gpio_chip.owner = THIS_MODULE;

mutex_init(&chip->lock);
Expand Down
19 changes: 10 additions & 9 deletions drivers/gpio/gpio-adnp.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static int adnp_read(struct adnp *adnp, unsigned offset, uint8_t *value)

err = i2c_smbus_read_byte_data(adnp->client, offset);
if (err < 0) {
dev_err(adnp->gpio.dev, "%s failed: %d\n",
dev_err(adnp->gpio.parent, "%s failed: %d\n",
"i2c_smbus_read_byte_data()", err);
return err;
}
Expand All @@ -62,7 +62,7 @@ static int adnp_write(struct adnp *adnp, unsigned offset, uint8_t value)

err = i2c_smbus_write_byte_data(adnp->client, offset, value);
if (err < 0) {
dev_err(adnp->gpio.dev, "%s failed: %d\n",
dev_err(adnp->gpio.parent, "%s failed: %d\n",
"i2c_smbus_write_byte_data()", err);
return err;
}
Expand Down Expand Up @@ -266,8 +266,8 @@ static int adnp_gpio_setup(struct adnp *adnp, unsigned int num_gpios)
chip->base = -1;
chip->ngpio = num_gpios;
chip->label = adnp->client->name;
chip->dev = &adnp->client->dev;
chip->of_node = chip->dev->of_node;
chip->parent = &adnp->client->dev;
chip->of_node = chip->parent->of_node;
chip->owner = THIS_MODULE;

err = gpiochip_add(chip);
Expand Down Expand Up @@ -435,7 +435,8 @@ static int adnp_irq_setup(struct adnp *adnp)
* is chosen to match the register layout of the hardware in that
* each segment contains the corresponding bits for all interrupts.
*/
adnp->irq_enable = devm_kzalloc(chip->dev, num_regs * 6, GFP_KERNEL);
adnp->irq_enable = devm_kzalloc(chip->parent, num_regs * 6,
GFP_KERNEL);
if (!adnp->irq_enable)
return -ENOMEM;

Expand All @@ -462,12 +463,12 @@ static int adnp_irq_setup(struct adnp *adnp)
adnp->irq_enable[i] = 0x00;
}

err = devm_request_threaded_irq(chip->dev, adnp->client->irq,
err = devm_request_threaded_irq(chip->parent, adnp->client->irq,
NULL, adnp_irq,
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
dev_name(chip->dev), adnp);
dev_name(chip->parent), adnp);
if (err != 0) {
dev_err(chip->dev, "can't request IRQ#%d: %d\n",
dev_err(chip->parent, "can't request IRQ#%d: %d\n",
adnp->client->irq, err);
return err;
}
Expand All @@ -478,7 +479,7 @@ static int adnp_irq_setup(struct adnp *adnp)
handle_simple_irq,
IRQ_TYPE_NONE);
if (err) {
dev_err(chip->dev,
dev_err(chip->parent,
"could not connect irqchip to gpiochip\n");
return err;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-altera.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ static int altera_gpio_probe(struct platform_device *pdev)
altera_gc->mmchip.gc.get = altera_gpio_get;
altera_gc->mmchip.gc.set = altera_gpio_set;
altera_gc->mmchip.gc.owner = THIS_MODULE;
altera_gc->mmchip.gc.dev = &pdev->dev;
altera_gc->mmchip.gc.parent = &pdev->dev;

ret = of_mm_gpiochip_add(node, &altera_gc->mmchip);
if (ret) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-amd8111.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static int __init amd_gpio_init(void)
goto out;
}
gp.pdev = pdev;
gp.chip.dev = &pdev->dev;
gp.chip.parent = &pdev->dev;

spin_lock_init(&gp.lock);

Expand Down
18 changes: 9 additions & 9 deletions drivers/gpio/gpio-amdpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ static int pt_gpio_request(struct gpio_chip *gc, unsigned offset)
unsigned long flags;
u32 using_pins;

dev_dbg(gc->dev, "pt_gpio_request offset=%x\n", offset);
dev_dbg(gc->parent, "pt_gpio_request offset=%x\n", offset);

spin_lock_irqsave(&pt_gpio->lock, flags);

using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG);
if (using_pins & BIT(offset)) {
dev_warn(gc->dev, "PT GPIO pin %x reconfigured\n",
offset);
dev_warn(gc->parent, "PT GPIO pin %x reconfigured\n",
offset);
spin_unlock_irqrestore(&pt_gpio->lock, flags);
return -EINVAL;
}
Expand All @@ -72,7 +72,7 @@ static void pt_gpio_free(struct gpio_chip *gc, unsigned offset)

spin_unlock_irqrestore(&pt_gpio->lock, flags);

dev_dbg(gc->dev, "pt_gpio_free offset=%x\n", offset);
dev_dbg(gc->parent, "pt_gpio_free offset=%x\n", offset);
}

static void pt_gpio_set_value(struct gpio_chip *gc, unsigned offset, int value)
Expand All @@ -81,7 +81,7 @@ static void pt_gpio_set_value(struct gpio_chip *gc, unsigned offset, int value)
unsigned long flags;
u32 data;

dev_dbg(gc->dev, "pt_gpio_set_value offset=%x, value=%x\n",
dev_dbg(gc->parent, "pt_gpio_set_value offset=%x, value=%x\n",
offset, value);

spin_lock_irqsave(&pt_gpio->lock, flags);
Expand Down Expand Up @@ -116,7 +116,7 @@ static int pt_gpio_get_value(struct gpio_chip *gc, unsigned offset)
data >>= offset;
data &= 1;

dev_dbg(gc->dev, "pt_gpio_get_value offset=%x, value=%x\n",
dev_dbg(gc->parent, "pt_gpio_get_value offset=%x, value=%x\n",
offset, data);

return data;
Expand All @@ -128,7 +128,7 @@ static int pt_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
unsigned long flags;
u32 data;

dev_dbg(gc->dev, "pt_gpio_dirction_input offset=%x\n", offset);
dev_dbg(gc->parent, "pt_gpio_dirction_input offset=%x\n", offset);

spin_lock_irqsave(&pt_gpio->lock, flags);

Expand All @@ -148,7 +148,7 @@ static int pt_gpio_direction_output(struct gpio_chip *gc,
unsigned long flags;
u32 data;

dev_dbg(gc->dev, "pt_gpio_direction_output offset=%x, value=%x\n",
dev_dbg(gc->parent, "pt_gpio_direction_output offset=%x, value=%x\n",
offset, value);

spin_lock_irqsave(&pt_gpio->lock, flags);
Expand Down Expand Up @@ -202,7 +202,7 @@ static int pt_gpio_probe(struct platform_device *pdev)

pt_gpio->gc.label = pdev->name;
pt_gpio->gc.owner = THIS_MODULE;
pt_gpio->gc.dev = dev;
pt_gpio->gc.parent = dev;
pt_gpio->gc.request = pt_gpio_request;
pt_gpio->gc.free = pt_gpio_free;
pt_gpio->gc.direction_input = pt_gpio_direction_input;
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-arizona.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static int arizona_gpio_probe(struct platform_device *pdev)

arizona_gpio->arizona = arizona;
arizona_gpio->gpio_chip = template_chip;
arizona_gpio->gpio_chip.dev = &pdev->dev;
arizona_gpio->gpio_chip.parent = &pdev->dev;
#ifdef CONFIG_OF_GPIO
arizona_gpio->gpio_chip.of_node = arizona->dev->of_node;
#endif
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-ath79.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static int ath79_gpio_probe(struct platform_device *pdev)

spin_lock_init(&ctrl->lock);
memcpy(&ctrl->chip, &ath79_gpio_chip, sizeof(ctrl->chip));
ctrl->chip.dev = &pdev->dev;
ctrl->chip.parent = &pdev->dev;
ctrl->chip.ngpio = ath79_gpio_count;
if (oe_inverted) {
ctrl->chip.direction_input = ar934x_gpio_direction_input;
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpio/gpio-bcm-kona.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ static int bcm_kona_gpio_set_debounce(struct gpio_chip *chip, unsigned gpio,
reg_base = kona_gpio->reg_base;
/* debounce must be 1-128ms (or 0) */
if ((debounce > 0 && debounce < 1000) || debounce > 128000) {
dev_err(chip->dev, "Debounce value %u not in range\n",
dev_err(chip->parent, "Debounce value %u not in range\n",
debounce);
return -EINVAL;
}
Expand Down Expand Up @@ -416,7 +416,7 @@ static int bcm_kona_gpio_irq_set_type(struct irq_data *d, unsigned int type)
case IRQ_TYPE_LEVEL_LOW:
/* BCM GPIO doesn't support level triggering */
default:
dev_err(kona_gpio->gpio_chip.dev,
dev_err(kona_gpio->gpio_chip.parent,
"Invalid BCM GPIO irq type 0x%x\n", type);
return -EINVAL;
}
Expand Down Expand Up @@ -477,7 +477,7 @@ static int bcm_kona_gpio_irq_reqres(struct irq_data *d)
struct bcm_kona_gpio *kona_gpio = irq_data_get_irq_chip_data(d);

if (gpiochip_lock_as_irq(&kona_gpio->gpio_chip, d->hwirq)) {
dev_err(kona_gpio->gpio_chip.dev,
dev_err(kona_gpio->gpio_chip.parent,
"unable to lock HW IRQ %lu for IRQ\n",
d->hwirq);
return -EINVAL;
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-crystalcove.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ static int crystalcove_gpio_probe(struct platform_device *pdev)
cg->chip.base = -1;
cg->chip.ngpio = CRYSTALCOVE_VGPIO_NUM;
cg->chip.can_sleep = true;
cg->chip.dev = dev;
cg->chip.parent = dev;
cg->chip.dbg_show = crystalcove_gpio_dbg_show;
cg->regmap = pmic->regmap;

Expand Down
4 changes: 2 additions & 2 deletions drivers/gpio/gpio-davinci.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ static int davinci_gpio_of_xlate(struct gpio_chip *gc,
const struct of_phandle_args *gpiospec,
u32 *flags)
{
struct davinci_gpio_controller *chips = dev_get_drvdata(gc->dev);
struct davinci_gpio_platform_data *pdata = dev_get_platdata(gc->dev);
struct davinci_gpio_controller *chips = dev_get_drvdata(gc->parent);
struct davinci_gpio_platform_data *pdata = dev_get_platdata(gc->parent);

if (gpiospec->args[0] > pdata->ngpio)
return -EINVAL;
Expand Down
10 changes: 5 additions & 5 deletions drivers/gpio/gpio-dln2.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ static void dln2_irq_bus_unlock(struct irq_data *irqd)

ret = dln2_gpio_set_event_cfg(dln2, pin, type, 0);
if (ret)
dev_err(dln2->gpio.dev, "failed to set event\n");
dev_err(dln2->gpio.parent, "failed to set event\n");
}

mutex_unlock(&dln2->irq_lock);
Expand Down Expand Up @@ -406,19 +406,19 @@ static void dln2_gpio_event(struct platform_device *pdev, u16 echo,
struct dln2_gpio *dln2 = platform_get_drvdata(pdev);

if (len < sizeof(*event)) {
dev_err(dln2->gpio.dev, "short event message\n");
dev_err(dln2->gpio.parent, "short event message\n");
return;
}

pin = le16_to_cpu(event->pin);
if (pin >= dln2->gpio.ngpio) {
dev_err(dln2->gpio.dev, "out of bounds pin %d\n", pin);
dev_err(dln2->gpio.parent, "out of bounds pin %d\n", pin);
return;
}

irq = irq_find_mapping(dln2->gpio.irqdomain, pin);
if (!irq) {
dev_err(dln2->gpio.dev, "pin %d not mapped to IRQ\n", pin);
dev_err(dln2->gpio.parent, "pin %d not mapped to IRQ\n", pin);
return;
}

Expand Down Expand Up @@ -462,7 +462,7 @@ static int dln2_gpio_probe(struct platform_device *pdev)
dln2->pdev = pdev;

dln2->gpio.label = "dln2";
dln2->gpio.dev = dev;
dln2->gpio.parent = dev;
dln2->gpio.owner = THIS_MODULE;
dln2->gpio.base = -1;
dln2->gpio.ngpio = pins;
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpio/gpio-em.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static int em_gio_irq_reqres(struct irq_data *d)
struct em_gio_priv *p = irq_data_get_irq_chip_data(d);

if (gpiochip_lock_as_irq(&p->gpio_chip, irqd_to_hwirq(d))) {
dev_err(p->gpio_chip.dev,
dev_err(p->gpio_chip.parent,
"unable to lock HW IRQ %lu for IRQ\n",
irqd_to_hwirq(d));
return -EINVAL;
Expand Down Expand Up @@ -332,7 +332,7 @@ static int em_gio_probe(struct platform_device *pdev)
gpio_chip->request = em_gio_request;
gpio_chip->free = em_gio_free;
gpio_chip->label = name;
gpio_chip->dev = &pdev->dev;
gpio_chip->parent = &pdev->dev;
gpio_chip->owner = THIS_MODULE;
gpio_chip->base = -1;
gpio_chip->ngpio = ngpios;
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-f7188x.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ static int f7188x_gpio_probe(struct platform_device *pdev)
for (i = 0; i < data->nr_bank; i++) {
struct f7188x_gpio_bank *bank = &data->bank[i];

bank->chip.dev = &pdev->dev;
bank->chip.parent = &pdev->dev;
bank->data = data;

err = gpiochip_add(&bank->chip);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ int bgpio_init(struct bgpio_chip *bgc, struct device *dev,
return -EINVAL;

spin_lock_init(&bgc->lock);
bgc->gc.dev = dev;
bgc->gc.parent = dev;
bgc->gc.label = dev_name(dev);
bgc->gc.base = -1;
bgc->gc.ngpio = bgc->bits;
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-ich.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static void ichx_gpiolib_setup(struct gpio_chip *chip)
{
chip->owner = THIS_MODULE;
chip->label = DRV_NAME;
chip->dev = &ichx_priv.dev->dev;
chip->parent = &ichx_priv.dev->dev;

/* Allow chip-specific overrides of request()/get() */
chip->request = ichx_priv.desc->request ?
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-intel-mid.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ static int intel_gpio_probe(struct pci_dev *pdev,

priv->reg_base = pcim_iomap_table(pdev)[0];
priv->chip.label = dev_name(&pdev->dev);
priv->chip.dev = &pdev->dev;
priv->chip.parent = &pdev->dev;
priv->chip.request = intel_gpio_request;
priv->chip.direction_input = intel_gpio_direction_input;
priv->chip.direction_output = intel_gpio_direction_output;
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpio/gpio-janz-ttl.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct ttl_module {

static int ttl_get_value(struct gpio_chip *gpio, unsigned offset)
{
struct ttl_module *mod = dev_get_drvdata(gpio->dev);
struct ttl_module *mod = dev_get_drvdata(gpio->parent);
u8 *shadow;
int ret;

Expand All @@ -81,7 +81,7 @@ static int ttl_get_value(struct gpio_chip *gpio, unsigned offset)

static void ttl_set_value(struct gpio_chip *gpio, unsigned offset, int value)
{
struct ttl_module *mod = dev_get_drvdata(gpio->dev);
struct ttl_module *mod = dev_get_drvdata(gpio->parent);
void __iomem *port;
u8 *shadow;

Expand Down Expand Up @@ -172,7 +172,7 @@ static int ttl_probe(struct platform_device *pdev)

/* Initialize the GPIO data structures */
gpio = &mod->gpio;
gpio->dev = &pdev->dev;
gpio->parent = &pdev->dev;
gpio->label = pdev->name;
gpio->get = ttl_get_value;
gpio->set = ttl_set_value;
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-kempld.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ static int kempld_gpio_probe(struct platform_device *pdev)
chip = &gpio->chip;
chip->label = "gpio-kempld";
chip->owner = THIS_MODULE;
chip->dev = dev;
chip->parent = dev;
chip->can_sleep = true;
if (pdata && pdata->gpio_base)
chip->base = pdata->gpio_base;
Expand Down
Loading

0 comments on commit 58383c7

Please sign in to comment.