From 58383c78425e4ee1c077253cf297b641c861c02e Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Wed, 4 Nov 2015 09:56:26 +0100 Subject: gpio: change member .dev to .parent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Cc: Rafał Miłecki Cc: Richard Purdie Cc: Mauro Carvalho Chehab Cc: Alek Du Cc: Jaroslav Kysela Cc: Takashi Iwai Acked-by: Dmitry Torokhov Acked-by: Greg Kroah-Hartman Acked-by: Lee Jones Acked-by: Jiri Kosina Acked-by: Hans-Christian Egtvedt Acked-by: Jacek Anaszewski Signed-off-by: Linus Walleij --- drivers/gpio/gpio-intel-mid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/gpio/gpio-intel-mid.c') diff --git a/drivers/gpio/gpio-intel-mid.c b/drivers/gpio/gpio-intel-mid.c index 70097472b02c..1c46a7ef2680 100644 --- a/drivers/gpio/gpio-intel-mid.c +++ b/drivers/gpio/gpio-intel-mid.c @@ -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; -- cgit v1.2.3 From 4c628f3de69f66f429c108b27de9f6e82311636c Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Mon, 21 Dec 2015 11:00:56 +0100 Subject: gpio: intel-mid: Be sure to clamp return value As we want gpio_chip .get() calls to be able to return negative error codes and propagate to drivers, we need to go over all drivers and make sure their return values are clamped to [0,1]. We do this by using the ret = !!(val) design pattern. Acked-by: David Cohen Signed-off-by: Linus Walleij --- drivers/gpio/gpio-intel-mid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/gpio/gpio-intel-mid.c') diff --git a/drivers/gpio/gpio-intel-mid.c b/drivers/gpio/gpio-intel-mid.c index 1c46a7ef2680..26d2083a5901 100644 --- a/drivers/gpio/gpio-intel-mid.c +++ b/drivers/gpio/gpio-intel-mid.c @@ -120,7 +120,7 @@ static int intel_gpio_get(struct gpio_chip *chip, unsigned offset) { void __iomem *gplr = gpio_reg(chip, offset, GPLR); - return readl(gplr) & BIT(offset % 32); + return !!(readl(gplr) & BIT(offset % 32)); } static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value) -- cgit v1.2.3 From 5c77c0212b97693219ead6dcddf7e036421012d7 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Sun, 6 Dec 2015 10:55:28 +0100 Subject: gpio: intel-mid: 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: David Cohen Signed-off-by: Linus Walleij --- drivers/gpio/gpio-intel-mid.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'drivers/gpio/gpio-intel-mid.c') diff --git a/drivers/gpio/gpio-intel-mid.c b/drivers/gpio/gpio-intel-mid.c index 26d2083a5901..cdaba13cb8e8 100644 --- a/drivers/gpio/gpio-intel-mid.c +++ b/drivers/gpio/gpio-intel-mid.c @@ -78,15 +78,10 @@ struct intel_mid_gpio { struct pci_dev *pdev; }; -static inline struct intel_mid_gpio *to_intel_gpio_priv(struct gpio_chip *gc) -{ - return container_of(gc, struct intel_mid_gpio, chip); -} - static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset, enum GPIO_REG reg_type) { - struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); + struct intel_mid_gpio *priv = gpiochip_get_data(chip); unsigned nreg = chip->ngpio / 32; u8 reg = offset / 32; @@ -96,7 +91,7 @@ static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset, static void __iomem *gpio_reg_2bit(struct gpio_chip *chip, unsigned offset, enum GPIO_REG reg_type) { - struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); + struct intel_mid_gpio *priv = gpiochip_get_data(chip); unsigned nreg = chip->ngpio / 32; u8 reg = offset / 16; @@ -138,7 +133,7 @@ static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value) static int intel_gpio_direction_input(struct gpio_chip *chip, unsigned offset) { - struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); + struct intel_mid_gpio *priv = gpiochip_get_data(chip); void __iomem *gpdr = gpio_reg(chip, offset, GPDR); u32 value; unsigned long flags; @@ -161,7 +156,7 @@ static int intel_gpio_direction_input(struct gpio_chip *chip, unsigned offset) static int intel_gpio_direction_output(struct gpio_chip *chip, unsigned offset, int value) { - struct intel_mid_gpio *priv = to_intel_gpio_priv(chip); + struct intel_mid_gpio *priv = gpiochip_get_data(chip); void __iomem *gpdr = gpio_reg(chip, offset, GPDR); unsigned long flags; @@ -185,7 +180,7 @@ static int intel_gpio_direction_output(struct gpio_chip *chip, static int intel_mid_irq_type(struct irq_data *d, unsigned type) { struct gpio_chip *gc = irq_data_get_irq_chip_data(d); - struct intel_mid_gpio *priv = to_intel_gpio_priv(gc); + struct intel_mid_gpio *priv = gpiochip_get_data(gc); u32 gpio = irqd_to_hwirq(d); unsigned long flags; u32 value; @@ -304,7 +299,7 @@ MODULE_DEVICE_TABLE(pci, intel_gpio_ids); static void intel_mid_irq_handler(struct irq_desc *desc) { struct gpio_chip *gc = irq_desc_get_handler_data(desc); - struct intel_mid_gpio *priv = to_intel_gpio_priv(gc); + struct intel_mid_gpio *priv = gpiochip_get_data(gc); struct irq_data *data = irq_desc_get_irq_data(desc); struct irq_chip *chip = irq_data_get_irq_chip(data); u32 base, gpio, mask; @@ -406,7 +401,7 @@ static int intel_gpio_probe(struct pci_dev *pdev, spin_lock_init(&priv->lock); pci_set_drvdata(pdev, priv); - retval = gpiochip_add(&priv->chip); + retval = gpiochip_add_data(&priv->chip, priv); if (retval) { dev_err(&pdev->dev, "gpiochip_add error %d\n", retval); return retval; -- cgit v1.2.3