Skip to contentSkip to conversation

gpio: replace nocache ioremap functions with devm_platform_ioremap_resource()

PATCH In review Bartosz Golaszewski 3 participants 9 messages Oct 2, 2019 – Oct 4, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover gpio: replace nocache ioremap functions with devm_platform_ioremap_resource()

From: Bartosz Golaszewski <[email protected]>

According to Arnd Bergmann:

"The only architecture that actually has a difference between ioremap() and ioremap_nocache() seems to be ia64. I would generally assume that any driver using ioremap_nocache() that is not ia64 specific should just use ioremap()."

This series converts all users of nocache ioremap variants that aren't ia64-specific to using devm_platform_ioremap_resource().

Most of these don't call request_mem_region() currently, which devm_platform_ioremap_resource() does implicitly, so testing would be appreciated.

Included are two minor fixes for xgene and htc-egpio.

Bartosz Golaszewski (6):
gpio: xgene: remove redundant error message
gpio: xgene: use devm_platform_ioremap_resource()
gpio: em: use devm_platform_ioremap_resource()
gpio: ath79: use devm_platform_ioremap_resource()
gpio: htc-egpio: use devm_platform_ioremap_resource()
gpio: htc-egpio: remove redundant error message

 drivers/gpio/gpio-ath79.c     | 10 +++-------
 drivers/gpio/gpio-em.c        | 20 ++++++++-----------
 drivers/gpio/gpio-htc-egpio.c | 37 ++++++++++++-----------------------
 drivers/gpio/gpio-xgene.c     | 27 ++++++-------------------
 4 files changed, 30 insertions(+), 64 deletions(-)
Signature · 1 line
2.23.0
#1 lore raw

PATCH 1/6 gpio: xgene: remove redundant error message

From: Bartosz Golaszewski <[email protected]>

There's no need to emit an error message on probe failure unless we're printing some meaningful info. Otherwise the core driver code will inform us about a probe error.

---
 drivers/gpio/gpio-xgene.c | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)
drivers/gpio/gpio-xgene.c +7 -16
index 2918363884de..900b38a7dba8 100644
@@ -160,23 +160,17 @@ static int xgene_gpio_probe(struct platform_device *pdev)
 	int err = 0;
 
 	gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
-	if (!gpio) {
-		err = -ENOMEM;
-		goto err;
-	}
+	if (!gpio)
+		return -ENOMEM;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
-		err = -EINVAL;
-		goto err;
-	}
+	if (!res)
+		return -EINVAL;
 
 	gpio->base = devm_ioremap_nocache(&pdev->dev, res->start,
 							resource_size(res));
-	if (!gpio->base) {
-		err = -ENOMEM;
-		goto err;
-	}
+	if (!gpio->base)
+		return -ENOMEM;
 
 	gpio->chip.ngpio = XGENE_MAX_GPIOS;
 
@@ -196,14 +190,11 @@ static int xgene_gpio_probe(struct platform_device *pdev)
 	if (err) {
 		dev_err(&pdev->dev,
 			"failed to register gpiochip.\n");
-		goto err;
+		return err;
 	}
 
 	dev_info(&pdev->dev, "X-Gene GPIO driver registered.\n");
 	return 0;
-err:
-	dev_err(&pdev->dev, "X-Gene GPIO driver registration failed.\n");
-	return err;
 }
 
 static const struct of_device_id xgene_gpio_of_match[] = {
Signature · 1 line
2.23.0
#2 lore raw

PATCH 2/6 gpio: xgene: use devm_platform_ioremap_resource()

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

There's no need to use the nocache variant of ioremap(). Switch to using devm_platform_ioremap_resource().

---
 drivers/gpio/gpio-xgene.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpio/gpio-xgene.c +3 -9
index 900b38a7dba8..a6e66ac18e1f 100644
@@ -155,7 +155,6 @@ static SIMPLE_DEV_PM_OPS(xgene_gpio_pm, xgene_gpio_suspend, xgene_gpio_resume);
 
 static int xgene_gpio_probe(struct platform_device *pdev)
 {
-	struct resource *res;
 	struct xgene_gpio *gpio;
 	int err = 0;
 
@@ -163,14 +162,9 @@ static int xgene_gpio_probe(struct platform_device *pdev)
 	if (!gpio)
 		return -ENOMEM;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -EINVAL;
-
-	gpio->base = devm_ioremap_nocache(&pdev->dev, res->start,
-							resource_size(res));
-	if (!gpio->base)
-		return -ENOMEM;
+	gpio->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(gpio->base))
+		return PTR_ERR(gpio->base);
 
 	gpio->chip.ngpio = XGENE_MAX_GPIOS;
 
Signature · 1 line
2.23.0
#6 lore raw

PATCH 5/6 gpio: htc-egpio: use devm_platform_ioremap_resource()

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

There's no need to use the nocache variant of ioremap(). Switch to using devm_platform_ioremap_resource().

---
 drivers/gpio/gpio-htc-egpio.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/gpio/gpio-htc-egpio.c +2 -7
index 6eb56f7ab9c9..2d4b0b888f66 100644
@@ -281,14 +281,9 @@ static int __init egpio_probe(struct platform_device *pdev)
 		ei->chained_irq = res->start;
 
 	/* Map egpio chip into virtual address space. */
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
+	ei->base_addr = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(ei->base_addr))
 		goto fail;
-	ei->base_addr = devm_ioremap_nocache(&pdev->dev, res->start,
-					     resource_size(res));
-	if (!ei->base_addr)
-		goto fail;
-	pr_debug("EGPIO phys=%08x virt=%p\n", (u32)res->start, ei->base_addr);
 
 	if ((pdata->bus_width != 16) && (pdata->bus_width != 32))
 		goto fail;
Signature · 1 line
2.23.0
#5 lore raw

PATCH 4/6 gpio: ath79: use devm_platform_ioremap_resource()

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

There's no need to use the nocache variant of ioremap(). Switch to using devm_platform_ioremap_resource().

---
 drivers/gpio/gpio-ath79.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/gpio/gpio-ath79.c +3 -7
index f1a5ea9b3de2..53fae02c40ad 100644
@@ -226,7 +226,6 @@ static int ath79_gpio_probe(struct platform_device *pdev)
 	struct device_node *np = dev->of_node;
 	struct ath79_gpio_ctrl *ctrl;
 	struct gpio_irq_chip *girq;
-	struct resource *res;
 	u32 ath79_gpio_count;
 	bool oe_inverted;
 	int err;
@@ -256,12 +255,9 @@ static int ath79_gpio_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -EINVAL;
-	ctrl->base = devm_ioremap_nocache(dev, res->start, resource_size(res));
-	if (!ctrl->base)
-		return -ENOMEM;
+	ctrl->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(ctrl->base))
+		return PTR_ERR(ctrl->base);
 
 	raw_spin_lock_init(&ctrl->lock);
 	err = bgpio_init(&ctrl->gc, dev, 4,
Signature · 1 line
2.23.0
#7 lore raw

PATCH 6/6 gpio: htc-egpio: remove redundant error message

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

There's no need to emit an error message on probe failure unless we're printing some meaningful info. Otherwise the core driver code will inform us about a probe error. Also: the driver currently drops info about errors propagated from called functions by default to returning -EINVAL. This fixes it as well.

---
 drivers/gpio/gpio-htc-egpio.c | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)
drivers/gpio/gpio-htc-egpio.c +11 -17
index 2d4b0b888f66..8aa23d70b1e6 100644
@@ -265,7 +265,6 @@ static int __init egpio_probe(struct platform_device *pdev)
 	struct gpio_chip  *chip;
 	unsigned int      irq, irq_end;
 	int               i;
-	int               ret;
 
 	/* Initialize ei data structure. */
 	ei = devm_kzalloc(&pdev->dev, sizeof(*ei), GFP_KERNEL);
@@ -275,7 +274,6 @@ static int __init egpio_probe(struct platform_device *pdev)
 	spin_lock_init(&ei->lock);
 
 	/* Find chained irq */
-	ret = -EINVAL;
 	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	if (res)
 		ei->chained_irq = res->start;
@@ -283,15 +281,17 @@ static int __init egpio_probe(struct platform_device *pdev)
 	/* Map egpio chip into virtual address space. */
 	ei->base_addr = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(ei->base_addr))
-		goto fail;
+		return PTR_ERR(ei->base_addr);
 
 	if ((pdata->bus_width != 16) && (pdata->bus_width != 32))
-		goto fail;
+		return -EINVAL;
+
 	ei->bus_shift = fls(pdata->bus_width - 1) - 3;
 	pr_debug("bus_shift = %d\n", ei->bus_shift);
 
 	if ((pdata->reg_width != 8) && (pdata->reg_width != 16))
-		goto fail;
+		return -EINVAL;
+
 	ei->reg_shift = fls(pdata->reg_width - 1);
 	pr_debug("reg_shift = %d\n", ei->reg_shift);
 
@@ -303,10 +303,9 @@ static int __init egpio_probe(struct platform_device *pdev)
 	ei->chip = devm_kcalloc(&pdev->dev,
 				ei->nchips, sizeof(struct egpio_chip),
 				GFP_KERNEL);
-	if (!ei->chip) {
-		ret = -ENOMEM;
-		goto fail;
-	}
+	if (!ei->chip)
+		return -ENOMEM;
+
 	for (i = 0; i < ei->nchips; i++) {
 		ei->chip[i].reg_start = pdata->chip[i].reg_start;
 		ei->chip[i].cached_values = pdata->chip[i].initial_values;
@@ -316,10 +315,9 @@ static int __init egpio_probe(struct platform_device *pdev)
 		chip->label = devm_kasprintf(&pdev->dev, GFP_KERNEL,
 					     "htc-egpio-%d",
 					     i);
-		if (!chip->label) {
-			ret = -ENOMEM;
-			goto fail;
-		}
+		if (!chip->label)
+			return -ENOMEM;
+
 		chip->parent          = &pdev->dev;
 		chip->owner           = THIS_MODULE;
 		chip->get             = egpio_get;
@@ -361,10 +359,6 @@ static int __init egpio_probe(struct platform_device *pdev)
 	}
 
 	return 0;
-
-fail:
-	printk(KERN_ERR "EGPIO failed to setup\n");
-	return ret;
 }
 
 #ifdef CONFIG_PM
Signature · 1 line
2.23.0
#3 lore raw

PATCH 3/6 gpio: em: use devm_platform_ioremap_resource()

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

There's no need to use the nocache variant of ioremap(). Switch to using devm_platform_ioremap_resource().

---
 drivers/gpio/gpio-em.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/gpio/gpio-em.c +8 -12
index 620f25b7efb4..674ebebaf90b 100644
@@ -269,7 +269,7 @@ static void em_gio_irq_domain_remove(void *data)
 static int em_gio_probe(struct platform_device *pdev)
 {
 	struct em_gio_priv *p;
-	struct resource *io[2], *irq[2];
+	struct resource *irq[2];
 	struct gpio_chip *gpio_chip;
 	struct irq_chip *irq_chip;
 	struct device *dev = &pdev->dev;
@@ -285,25 +285,21 @@ static int em_gio_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, p);
 	spin_lock_init(&p->sense_lock);
 
-	io[0] = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	io[1] = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	irq[0] = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	irq[1] = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
 
-	if (!io[0] || !io[1] || !irq[0] || !irq[1]) {
+	if (!irq[0] || !irq[1]) {
 		dev_err(dev, "missing IRQ or IOMEM\n");
 		return -EINVAL;
 	}
 
-	p->base0 = devm_ioremap_nocache(dev, io[0]->start,
-					resource_size(io[0]));
-	if (!p->base0)
-		return -ENOMEM;
+	p->base0 = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(p->base0))
+		return PTR_ERR(p->base0);
 
-	p->base1 = devm_ioremap_nocache(dev, io[1]->start,
-				   resource_size(io[1]));
-	if (!p->base1)
-		return -ENOMEM;
+	p->base1 = devm_platform_ioremap_resource(pdev, 1);
+	if (IS_ERR(p->base1))
+		return PTR_ERR(p->base1);
 
 	if (of_property_read_u32(dev->of_node, "ngpios", &ngpios)) {
 		dev_err(dev, "Missing ngpios OF property\n");
Signature · 1 line
2.23.0
Reviewed-by on v1 3/6
#4 lore raw

Re: [PATCH 3/6] gpio: em: use devm_platform_ioremap_resource()

CC linux-renesas-soc

Quoted 6 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

There's no need to use the nocache variant of ioremap(). Switch to using devm_platform_ioremap_resource().

Quoted 34 lines
drivers/gpio/gpio-em.c +5 -8
@@ -269,7 +269,7 @@ static void em_gio_irq_domain_remove(void *data)
 static int em_gio_probe(struct platform_device *pdev)
 {
        struct em_gio_priv *p;
-       struct resource *io[2], *irq[2];
+       struct resource *irq[2];
        struct gpio_chip *gpio_chip;
        struct irq_chip *irq_chip;
        struct device *dev = &pdev->dev;
@@ -285,25 +285,21 @@ static int em_gio_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, p);
        spin_lock_init(&p->sense_lock);
 
-       io[0] = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       io[1] = platform_get_resource(pdev, IORESOURCE_MEM, 1);
        irq[0] = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
        irq[1] = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
 
-       if (!io[0] || !io[1] || !irq[0] || !irq[1]) {
+       if (!irq[0] || !irq[1]) {
                dev_err(dev, "missing IRQ or IOMEM\n");
                return -EINVAL;
        }
 
-       p->base0 = devm_ioremap_nocache(dev, io[0]->start,
-                                       resource_size(io[0]));
-       if (!p->base0)
-               return -ENOMEM;
+       p->base0 = devm_platform_ioremap_resource(pdev, 0);
+       if (IS_ERR(p->base0))
+               return PTR_ERR(p->base0);
 

drivers/gpio/gpio-em.c static int em_gio_probe(struct platform_device *pdev) · line 305

Quoted 10 lines
drivers/gpio/gpio-em.c +3 -4
-       p->base1 = devm_ioremap_nocache(dev, io[1]->start,
-                                  resource_size(io[1]));
-       if (!p->base1)
-               return -ENOMEM;
+       p->base1 = devm_platform_ioremap_resource(pdev, 1);
+       if (IS_ERR(p->base1))
+               return PTR_ERR(p->base1);
 
        if (of_property_read_u32(dev->of_node, "ngpios", &ngpios)) {
                dev_err(dev, "Missing ngpios OF property\n");

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Reviewed-by on the v1 series
#8 lore raw
In reply to Bartosz Golaszewski
Quoted 2 lines · Bartosz Golaszewski

This series converts all users of nocache ioremap variants that aren't ia64-specific to using devm_platform_ioremap_resource().

Do we have an ia64 gpio driver even?

Quoted 5 lines

Most of these don't call request_mem_region() currently, which devm_platform_ioremap_resource() does implicitly, so testing would be appreciated.

Included are two minor fixes for xgene and htc-egpio.

All the patches:

Send me a pull request at your earliest convenience!

Thanks,
Linus Walleij