linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource()
@ 2019-08-29 14:37 Bartosz Golaszewski
  2019-08-29 14:37 ` [PATCH 1/9] Documentation: devres: add missing entry for devm_platform_ioremap_resource() Bartosz Golaszewski
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: Bartosz Golaszewski @ 2019-08-29 14:37 UTC (permalink / raw)
  To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki,
	Alban Bedel, Linus Walleij, Arnd Bergmann, Geert Uytterhoeven
  Cc: linux-doc, linux-kernel, linux-gpio, Julia Lawall, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

The new devm_platform_ioremap_resource() helper has now been widely
adopted and used in many drivers. Users of nocache and write-combined
ioremap() variants could profit from the same code shrinkage. This
series provides two new versions of devm_platform_ioremap_resource()
and uses it in a few example drivers with the assumption that - just
like was the case previously - a coccinelle script will be developed
to ease the transition for others.

Bartosz Golaszewski (9):
  Documentation: devres: add missing entry for
    devm_platform_ioremap_resource()
  lib: devres: prepare devm_ioremap_resource() for more variants
  lib: devres: provide new variants for devm_ioremap_resource()
  drivers: provide new variants of devm_platform_ioremap_resource()
  gpio: em: use devm_platform_ioremap_resource_nocache()
  gpio: ath79: use devm_platform_ioremap_resource_nocache()
  gpio: htc-egpio: use devm_platform_ioremap_resource_nocache()
  gpio: xgene: use devm_platform_ioremap_resource_nocache()
  misc: sram: use devm_platform_ioremap_resource_wc()

 .../driver-api/driver-model/devres.rst        |  5 ++
 drivers/base/platform.c                       | 70 +++++++++++++++--
 drivers/gpio/gpio-ath79.c                     | 10 +--
 drivers/gpio/gpio-em.c                        | 22 +++---
 drivers/gpio/gpio-htc-egpio.c                 | 13 ++--
 drivers/gpio/gpio-xgene.c                     | 14 +---
 drivers/misc/sram.c                           | 28 ++-----
 include/linux/device.h                        |  4 +
 include/linux/platform_device.h               |  6 ++
 lib/devres.c                                  | 76 ++++++++++++++-----
 10 files changed, 165 insertions(+), 83 deletions(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/9] Documentation: devres: add missing entry for devm_platform_ioremap_resource()
  2019-08-29 14:37 [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource() Bartosz Golaszewski
@ 2019-08-29 14:37 ` Bartosz Golaszewski
  2019-08-29 14:37 ` [PATCH 2/9] lib: devres: prepare devm_ioremap_resource() for more variants Bartosz Golaszewski
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Bartosz Golaszewski @ 2019-08-29 14:37 UTC (permalink / raw)
  To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki,
	Alban Bedel, Linus Walleij, Arnd Bergmann, Geert Uytterhoeven
  Cc: linux-doc, linux-kernel, linux-gpio, Julia Lawall, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

devm_platform_ioremap_resource() should be documented in devres.rst.
Add the missing entry.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 Documentation/driver-api/driver-model/devres.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
index a100bef54952..8e3087662daf 100644
--- a/Documentation/driver-api/driver-model/devres.rst
+++ b/Documentation/driver-api/driver-model/devres.rst
@@ -316,6 +316,7 @@ IOMAP
   devm_ioremap_nocache()
   devm_ioremap_wc()
   devm_ioremap_resource() : checks resource, requests memory region, ioremaps
+  devm_platform_ioremap_resource() : calls devm_ioremap_resource() for platform device
   devm_iounmap()
   pcim_iomap()
   pcim_iomap_regions()	: do request_region() and iomap() on multiple BARs
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/9] lib: devres: prepare devm_ioremap_resource() for more variants
  2019-08-29 14:37 [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource() Bartosz Golaszewski
  2019-08-29 14:37 ` [PATCH 1/9] Documentation: devres: add missing entry for devm_platform_ioremap_resource() Bartosz Golaszewski
@ 2019-08-29 14:37 ` Bartosz Golaszewski
  2019-08-29 14:37 ` [PATCH 3/9] lib: devres: provide new variants for devm_ioremap_resource() Bartosz Golaszewski
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Bartosz Golaszewski @ 2019-08-29 14:37 UTC (permalink / raw)
  To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki,
	Alban Bedel, Linus Walleij, Arnd Bergmann, Geert Uytterhoeven
  Cc: linux-doc, linux-kernel, linux-gpio, Julia Lawall, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

We want to add the nocache and write-combined variants of
devm_ioremap_resource(). Let's first implement __devm_ioremap_resource()
which takes an additional argument type. The types are the same as
for __devm_ioremap(). The existing devm_ioremap_resource() now simply
calls __devm_ioremap_resource() with regular DEVM_IOREMAP type.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 lib/devres.c | 47 +++++++++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 20 deletions(-)

diff --git a/lib/devres.c b/lib/devres.c
index 6a0e9bd6524a..a14c727128c1 100644
--- a/lib/devres.c
+++ b/lib/devres.c
@@ -114,25 +114,9 @@ void devm_iounmap(struct device *dev, void __iomem *addr)
 }
 EXPORT_SYMBOL(devm_iounmap);
 
-/**
- * devm_ioremap_resource() - check, request region, and ioremap resource
- * @dev: generic device to handle the resource for
- * @res: resource to be handled
- *
- * Checks that a resource is a valid memory region, requests the memory
- * region and ioremaps it. All operations are managed and will be undone
- * on driver detach.
- *
- * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code
- * on failure. Usage example:
- *
- *	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- *	base = devm_ioremap_resource(&pdev->dev, res);
- *	if (IS_ERR(base))
- *		return PTR_ERR(base);
- */
-void __iomem *devm_ioremap_resource(struct device *dev,
-				    const struct resource *res)
+static void __iomem *
+__devm_ioremap_resource(struct device *dev, const struct resource *res,
+			enum devm_ioremap_type type)
 {
 	resource_size_t size;
 	void __iomem *dest_ptr;
@@ -151,7 +135,7 @@ void __iomem *devm_ioremap_resource(struct device *dev,
 		return IOMEM_ERR_PTR(-EBUSY);
 	}
 
-	dest_ptr = devm_ioremap(dev, res->start, size);
+	dest_ptr = __devm_ioremap(dev, res->start, size, type);
 	if (!dest_ptr) {
 		dev_err(dev, "ioremap failed for resource %pR\n", res);
 		devm_release_mem_region(dev, res->start, size);
@@ -160,6 +144,29 @@ void __iomem *devm_ioremap_resource(struct device *dev,
 
 	return dest_ptr;
 }
+
+/**
+ * devm_ioremap_resource() - check, request region, and ioremap resource
+ * @dev: generic device to handle the resource for
+ * @res: resource to be handled
+ *
+ * Checks that a resource is a valid memory region, requests the memory
+ * region and ioremaps it. All operations are managed and will be undone
+ * on driver detach.
+ *
+ * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code
+ * on failure. Usage example:
+ *
+ *	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ *	base = devm_ioremap_resource(&pdev->dev, res);
+ *	if (IS_ERR(base))
+ *		return PTR_ERR(base);
+ */
+void __iomem *devm_ioremap_resource(struct device *dev,
+				    const struct resource *res)
+{
+	return __devm_ioremap_resource(dev, res, DEVM_IOREMAP);
+}
 EXPORT_SYMBOL(devm_ioremap_resource);
 
 /*
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/9] lib: devres: provide new variants for devm_ioremap_resource()
  2019-08-29 14:37 [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource() Bartosz Golaszewski
  2019-08-29 14:37 ` [PATCH 1/9] Documentation: devres: add missing entry for devm_platform_ioremap_resource() Bartosz Golaszewski
  2019-08-29 14:37 ` [PATCH 2/9] lib: devres: prepare devm_ioremap_resource() for more variants Bartosz Golaszewski
@ 2019-08-29 14:37 ` Bartosz Golaszewski
  2019-08-29 15:09   ` Arnd Bergmann
  2019-08-29 14:37 ` [PATCH 4/9] drivers: provide new variants of devm_platform_ioremap_resource() Bartosz Golaszewski
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 13+ messages in thread
From: Bartosz Golaszewski @ 2019-08-29 14:37 UTC (permalink / raw)
  To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki,
	Alban Bedel, Linus Walleij, Arnd Bergmann, Geert Uytterhoeven
  Cc: linux-doc, linux-kernel, linux-gpio, Julia Lawall, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Provide two new variants of devm_ioremap_resource() - one for nocache
and one for write-combined ioremap.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 .../driver-api/driver-model/devres.rst        |  2 ++
 include/linux/device.h                        |  4 +++
 lib/devres.c                                  | 29 +++++++++++++++++++
 3 files changed, 35 insertions(+)

diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
index 8e3087662daf..20c4be0389ab 100644
--- a/Documentation/driver-api/driver-model/devres.rst
+++ b/Documentation/driver-api/driver-model/devres.rst
@@ -316,6 +316,8 @@ IOMAP
   devm_ioremap_nocache()
   devm_ioremap_wc()
   devm_ioremap_resource() : checks resource, requests memory region, ioremaps
+  devm_ioremap_resource_nocache()
+  devm_ioremap_resource_wc()
   devm_platform_ioremap_resource() : calls devm_ioremap_resource() for platform device
   devm_iounmap()
   pcim_iomap()
diff --git a/include/linux/device.h b/include/linux/device.h
index 6717adee33f0..e8aa916e8eb2 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -710,6 +710,10 @@ extern void devm_free_pages(struct device *dev, unsigned long addr);
 
 void __iomem *devm_ioremap_resource(struct device *dev,
 				    const struct resource *res);
+void __iomem *devm_ioremap_resource_nocache(struct device *dev,
+					    const struct resource *res);
+void __iomem *devm_ioremap_resource_wc(struct device *dev,
+				       const struct resource *res);
 
 void __iomem *devm_of_iomap(struct device *dev,
 			    struct device_node *node, int index,
diff --git a/lib/devres.c b/lib/devres.c
index a14c727128c1..f1297bcc8891 100644
--- a/lib/devres.c
+++ b/lib/devres.c
@@ -169,6 +169,35 @@ void __iomem *devm_ioremap_resource(struct device *dev,
 }
 EXPORT_SYMBOL(devm_ioremap_resource);
 
+/**
+ * devm_ioremap_resource_nocache() - nocache variant of devm_ioremap_resource()
+ * @dev: generic device to handle the resource for
+ * @res: resource to be handled
+ *
+ * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code
+ * on failure. Usage example:
+ */
+void __iomem *devm_ioremap_resource_nocache(struct device *dev,
+					    const struct resource *res)
+{
+	return __devm_ioremap_resource(dev, res, DEVM_IOREMAP_NC);
+}
+
+/**
+ * devm_ioremap_resource_wc() - write-combined variant of
+ *				devm_ioremap_resource()
+ * @dev: generic device to handle the resource for
+ * @res: resource to be handled
+ *
+ * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code
+ * on failure. Usage example:
+ */
+void __iomem *devm_ioremap_resource_wc(struct device *dev,
+				       const struct resource *res)
+{
+	return __devm_ioremap_resource(dev, res, DEVM_IOREMAP_WC);
+}
+
 /*
  * devm_of_iomap - Requests a resource and maps the memory mapped IO
  *		   for a given device_node managed by a given device
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 4/9] drivers: provide new variants of devm_platform_ioremap_resource()
  2019-08-29 14:37 [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource() Bartosz Golaszewski
                   ` (2 preceding siblings ...)
  2019-08-29 14:37 ` [PATCH 3/9] lib: devres: provide new variants for devm_ioremap_resource() Bartosz Golaszewski
@ 2019-08-29 14:37 ` Bartosz Golaszewski
  2019-08-29 14:37 ` [PATCH 5/9] gpio: em: use devm_platform_ioremap_resource_nocache() Bartosz Golaszewski
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Bartosz Golaszewski @ 2019-08-29 14:37 UTC (permalink / raw)
  To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki,
	Alban Bedel, Linus Walleij, Arnd Bergmann, Geert Uytterhoeven
  Cc: linux-doc, linux-kernel, linux-gpio, Julia Lawall, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Provide two new variants of devm_platform_ioremap_resource() - one for
nocache and one for write-combined ioremap.

Move the core functionality into a separate static function -
__devm_platform_ioremap_resource() - that takes an additional type
argument.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 .../driver-api/driver-model/devres.rst        |  2 +
 drivers/base/platform.c                       | 70 +++++++++++++++++--
 include/linux/platform_device.h               |  6 ++
 3 files changed, 73 insertions(+), 5 deletions(-)

diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
index 20c4be0389ab..37d10e5cc44c 100644
--- a/Documentation/driver-api/driver-model/devres.rst
+++ b/Documentation/driver-api/driver-model/devres.rst
@@ -319,6 +319,8 @@ IOMAP
   devm_ioremap_resource_nocache()
   devm_ioremap_resource_wc()
   devm_platform_ioremap_resource() : calls devm_ioremap_resource() for platform device
+  devm_platform_ioremap_resource_nocache()
+  devm_platform_ioremap_resource_wc()
   devm_iounmap()
   pcim_iomap()
   pcim_iomap_regions()	: do request_region() and iomap() on multiple BARs
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index ec974ba9c0c4..4191e776ebae 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -79,6 +79,37 @@ struct resource *platform_get_resource(struct platform_device *dev,
 }
 EXPORT_SYMBOL_GPL(platform_get_resource);
 
+#ifdef CONFIG_HAS_IOMEM
+enum {
+	IOREMAP_TYPE_NONE,
+	IOREMAP_TYPE_NOCACHE,
+	IOREMAP_TYPE_WC,
+};
+
+static void __iomem *
+__devm_platform_ioremap_resource(struct platform_device *pdev,
+				 unsigned int index, int type)
+{
+	struct resource *res = platform_get_resource(pdev,
+						     IORESOURCE_MEM, index);
+	struct device *dev = &pdev->dev;
+	void __iomem *addr = NULL;
+
+	switch (type) {
+	case IOREMAP_TYPE_NONE:
+		addr = devm_ioremap_resource(dev, res);
+		break;
+	case IOREMAP_TYPE_NOCACHE:
+		addr = devm_ioremap_resource_nocache(dev, res);
+		break;
+	case IOREMAP_TYPE_WC:
+		addr = devm_ioremap_resource_wc(dev, res);
+		break;
+	}
+
+	return addr;
+}
+
 /**
  * devm_platform_ioremap_resource - call devm_ioremap_resource() for a platform
  *				    device
@@ -87,16 +118,45 @@ EXPORT_SYMBOL_GPL(platform_get_resource);
  *        resource management
  * @index: resource index
  */
-#ifdef CONFIG_HAS_IOMEM
 void __iomem *devm_platform_ioremap_resource(struct platform_device *pdev,
 					     unsigned int index)
 {
-	struct resource *res;
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, index);
-	return devm_ioremap_resource(&pdev->dev, res);
+	return __devm_platform_ioremap_resource(pdev, index, IOREMAP_TYPE_NONE);
 }
 EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource);
+
+/**
+ * devm_platform_ioremap_resource_nocache - nocache variant of
+ *                                          devm_platform_ioremap_resource()
+ *
+ * @pdev: platform device to use both for memory resource lookup as well as
+ *        resource management
+ * @index: resource index
+ */
+void __iomem *
+devm_platform_ioremap_resource_nocache(struct platform_device *pdev,
+				       unsigned int index)
+{
+	return __devm_platform_ioremap_resource(pdev, index,
+						IOREMAP_TYPE_NOCACHE);
+}
+EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource_nocache);
+
+/**
+ * devm_platform_ioremap_resource_wc - write-combined variant of
+ *                                     devm_platform_ioremap_resource()
+ *
+ * @pdev: platform device to use both for memory resource lookup as well as
+ *        resource management
+ * @index: resource index
+ */
+void __iomem *devm_platform_ioremap_resource_wc(struct platform_device *pdev,
+						unsigned int index)
+{
+	return __devm_platform_ioremap_resource(pdev, index, IOREMAP_TYPE_WC);
+}
+EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource_wc);
+
 #endif /* CONFIG_HAS_IOMEM */
 
 /**
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 9bc36b589827..00ae0679396e 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -54,6 +54,12 @@ extern struct resource *platform_get_resource(struct platform_device *,
 extern void __iomem *
 devm_platform_ioremap_resource(struct platform_device *pdev,
 			       unsigned int index);
+extern void __iomem *
+devm_platform_ioremap_resource_nocache(struct platform_device *pdev,
+				       unsigned int index);
+extern void __iomem *
+devm_platform_ioremap_resource_wc(struct platform_device *pdev,
+				  unsigned int index);
 extern int platform_get_irq(struct platform_device *, unsigned int);
 extern int platform_irq_count(struct platform_device *);
 extern struct resource *platform_get_resource_byname(struct platform_device *,
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 5/9] gpio: em: use devm_platform_ioremap_resource_nocache()
  2019-08-29 14:37 [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource() Bartosz Golaszewski
                   ` (3 preceding siblings ...)
  2019-08-29 14:37 ` [PATCH 4/9] drivers: provide new variants of devm_platform_ioremap_resource() Bartosz Golaszewski
@ 2019-08-29 14:37 ` Bartosz Golaszewski
  2019-08-29 14:37 ` [PATCH 6/9] gpio: ath79: " Bartosz Golaszewski
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Bartosz Golaszewski @ 2019-08-29 14:37 UTC (permalink / raw)
  To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki,
	Alban Bedel, Linus Walleij, Arnd Bergmann, Geert Uytterhoeven
  Cc: linux-doc, linux-kernel, linux-gpio, Julia Lawall, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Use the new devm_platform_ioremap_resource_nocache() helper for memory
range mapping instead of devm_ioremap_nocache() combined with a call to
platform_get_resource().

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/gpio/gpio-em.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
index a87951293aaa..0f4f5e11278a 100644
--- a/drivers/gpio/gpio-em.c
+++ b/drivers/gpio/gpio-em.c
@@ -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;
 	const char *name = dev_name(&pdev->dev);
@@ -284,25 +284,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]) {
-		dev_err(&pdev->dev, "missing IRQ or IOMEM\n");
+	if (!irq[0] || !irq[1]) {
+		dev_err(&pdev->dev, "missing IRQ resources\n");
 		return -EINVAL;
 	}
 
-	p->base0 = devm_ioremap_nocache(&pdev->dev, io[0]->start,
-					resource_size(io[0]));
-	if (!p->base0)
-		return -ENOMEM;
+	p->base0 = devm_platform_ioremap_resource_nocache(pdev, 0);
+	if (IS_ERR(p->base0))
+		return PTR_ERR(p->base0);
 
-	p->base1 = devm_ioremap_nocache(&pdev->dev, io[1]->start,
-				   resource_size(io[1]));
-	if (!p->base1)
-		return -ENOMEM;
+	p->base1 = devm_platform_ioremap_resource_nocache(pdev, 1);
+	if (IS_ERR(p->base1))
+		return PTR_ERR(p->base1);
 
 	if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) {
 		dev_err(&pdev->dev, "Missing ngpios OF property\n");
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 6/9] gpio: ath79: use devm_platform_ioremap_resource_nocache()
  2019-08-29 14:37 [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource() Bartosz Golaszewski
                   ` (4 preceding siblings ...)
  2019-08-29 14:37 ` [PATCH 5/9] gpio: em: use devm_platform_ioremap_resource_nocache() Bartosz Golaszewski
@ 2019-08-29 14:37 ` Bartosz Golaszewski
  2019-08-29 14:37 ` [PATCH 7/9] gpio: htc-egpio: " Bartosz Golaszewski
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Bartosz Golaszewski @ 2019-08-29 14:37 UTC (permalink / raw)
  To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki,
	Alban Bedel, Linus Walleij, Arnd Bergmann, Geert Uytterhoeven
  Cc: linux-doc, linux-kernel, linux-gpio, Julia Lawall, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Use the new devm_platform_ioremap_resource_nocache() helper for memory
range mapping instead of devm_ioremap_nocache() combined with a call to
platform_get_resource().

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/gpio/gpio-ath79.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpio-ath79.c b/drivers/gpio/gpio-ath79.c
index f1a5ea9b3de2..c2c5d7dd2575 100644
--- a/drivers/gpio/gpio-ath79.c
+++ b/drivers/gpio/gpio-ath79.c
@@ -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_nocache(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,
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 7/9] gpio: htc-egpio: use devm_platform_ioremap_resource_nocache()
  2019-08-29 14:37 [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource() Bartosz Golaszewski
                   ` (5 preceding siblings ...)
  2019-08-29 14:37 ` [PATCH 6/9] gpio: ath79: " Bartosz Golaszewski
@ 2019-08-29 14:37 ` Bartosz Golaszewski
  2019-08-29 14:37 ` [PATCH 8/9] gpio: xgene: " Bartosz Golaszewski
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Bartosz Golaszewski @ 2019-08-29 14:37 UTC (permalink / raw)
  To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki,
	Alban Bedel, Linus Walleij, Arnd Bergmann, Geert Uytterhoeven
  Cc: linux-doc, linux-kernel, linux-gpio, Julia Lawall, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Use the new devm_platform_ioremap_resource_nocache() helper for memory
range mapping instead of devm_ioremap_nocache() combined with a call to
platform_get_resource().

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/gpio/gpio-htc-egpio.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpio-htc-egpio.c b/drivers/gpio/gpio-htc-egpio.c
index 9d3ac51a765c..7d8548e03226 100644
--- a/drivers/gpio/gpio-htc-egpio.c
+++ b/drivers/gpio/gpio-htc-egpio.c
@@ -295,14 +295,13 @@ 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_nocache(pdev, 0);
+	if (IS_ERR(ei->base_addr)) {
+		ret = PTR_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);
+	}
+	pr_debug("EGPIO phys=%08x virt=%p\n",
+		 virt_to_phys(ei->base_addr), ei->base_addr);
 
 	if ((pdata->bus_width != 16) && (pdata->bus_width != 32))
 		goto fail;
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 8/9] gpio: xgene: use devm_platform_ioremap_resource_nocache()
  2019-08-29 14:37 [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource() Bartosz Golaszewski
                   ` (6 preceding siblings ...)
  2019-08-29 14:37 ` [PATCH 7/9] gpio: htc-egpio: " Bartosz Golaszewski
@ 2019-08-29 14:37 ` Bartosz Golaszewski
  2019-08-29 14:37 ` [PATCH 9/9] misc: sram: use devm_platform_ioremap_resource_wc() Bartosz Golaszewski
  2019-08-29 14:48 ` [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource() Geert Uytterhoeven
  9 siblings, 0 replies; 13+ messages in thread
From: Bartosz Golaszewski @ 2019-08-29 14:37 UTC (permalink / raw)
  To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki,
	Alban Bedel, Linus Walleij, Arnd Bergmann, Geert Uytterhoeven
  Cc: linux-doc, linux-kernel, linux-gpio, Julia Lawall, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Use the new devm_platform_ioremap_resource_nocache() helper for memory
range mapping instead of devm_ioremap_nocache() combined with a call to
platform_get_resource().

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/gpio/gpio-xgene.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/gpio/gpio-xgene.c b/drivers/gpio/gpio-xgene.c
index 2918363884de..559b8e53c2e0 100644
--- a/drivers/gpio/gpio-xgene.c
+++ b/drivers/gpio/gpio-xgene.c
@@ -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;
 
@@ -165,16 +164,9 @@ static int xgene_gpio_probe(struct platform_device *pdev)
 		goto err;
 	}
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
-		err = -EINVAL;
-		goto err;
-	}
-
-	gpio->base = devm_ioremap_nocache(&pdev->dev, res->start,
-							resource_size(res));
-	if (!gpio->base) {
-		err = -ENOMEM;
+	gpio->base = devm_platform_ioremap_resource_nocache(pdev, 0);
+	if (IS_ERR(gpio->base)) {
+		err = PTR_ERR(gpio->base);
 		goto err;
 	}
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 9/9] misc: sram: use devm_platform_ioremap_resource_wc()
  2019-08-29 14:37 [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource() Bartosz Golaszewski
                   ` (7 preceding siblings ...)
  2019-08-29 14:37 ` [PATCH 8/9] gpio: xgene: " Bartosz Golaszewski
@ 2019-08-29 14:37 ` Bartosz Golaszewski
  2019-08-29 14:48 ` [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource() Geert Uytterhoeven
  9 siblings, 0 replies; 13+ messages in thread
From: Bartosz Golaszewski @ 2019-08-29 14:37 UTC (permalink / raw)
  To: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki,
	Alban Bedel, Linus Walleij, Arnd Bergmann, Geert Uytterhoeven
  Cc: linux-doc, linux-kernel, linux-gpio, Julia Lawall, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Use the new devm_platform_ioremap_resource_wc() helper instead of
devm_ioremap_wc() combinded with a call to platform_get_resource().
Also use devm_platform_ioremap_resource() where applicable.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/misc/sram.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
index f30448bf3a63..6c1a23cb3e8c 100644
--- a/drivers/misc/sram.c
+++ b/drivers/misc/sram.c
@@ -340,8 +340,6 @@ static const struct of_device_id sram_dt_ids[] = {
 static int sram_probe(struct platform_device *pdev)
 {
 	struct sram_dev *sram;
-	struct resource *res;
-	size_t size;
 	int ret;
 	int (*init_func)(void);
 
@@ -351,25 +349,14 @@ static int sram_probe(struct platform_device *pdev)
 
 	sram->dev = &pdev->dev;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
-		dev_err(sram->dev, "found no memory resource\n");
-		return -EINVAL;
-	}
-
-	size = resource_size(res);
-
-	if (!devm_request_mem_region(sram->dev, res->start, size, pdev->name)) {
-		dev_err(sram->dev, "could not request region for resource\n");
-		return -EBUSY;
-	}
-
 	if (of_property_read_bool(pdev->dev.of_node, "no-memory-wc"))
-		sram->virt_base = devm_ioremap(sram->dev, res->start, size);
+		sram->virt_base = devm_platform_ioremap_resource(pdev, 0);
 	else
-		sram->virt_base = devm_ioremap_wc(sram->dev, res->start, size);
-	if (!sram->virt_base)
-		return -ENOMEM;
+		sram->virt_base = devm_platform_ioremap_resource_wc(pdev, 0);
+	if (IS_ERR(sram->virt_base)) {
+		dev_err(&pdev->dev, "could not map SRAM registers\n");
+		return PTR_ERR(sram->virt_base);
+	}
 
 	sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY),
 					  NUMA_NO_NODE, NULL);
@@ -382,7 +369,8 @@ static int sram_probe(struct platform_device *pdev)
 	else
 		clk_prepare_enable(sram->clk);
 
-	ret = sram_reserve_regions(sram, res);
+	ret = sram_reserve_regions(sram,
+			platform_get_resource(pdev, IORESOURCE_MEM, 0));
 	if (ret)
 		goto err_disable_clk;
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource()
  2019-08-29 14:37 [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource() Bartosz Golaszewski
                   ` (8 preceding siblings ...)
  2019-08-29 14:37 ` [PATCH 9/9] misc: sram: use devm_platform_ioremap_resource_wc() Bartosz Golaszewski
@ 2019-08-29 14:48 ` Geert Uytterhoeven
  2019-08-30 15:59   ` Christoph Hellwig
  9 siblings, 1 reply; 13+ messages in thread
From: Geert Uytterhoeven @ 2019-08-29 14:48 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki,
	Alban Bedel, Linus Walleij, Arnd Bergmann, Geert Uytterhoeven,
	open list:DOCUMENTATION, Linux Kernel Mailing List,
	open list:GPIO SUBSYSTEM, Julia Lawall, Bartosz Golaszewski,
	Christoph Hellwig

Hi Bartosz,

On Thu, Aug 29, 2019 at 4:38 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> The new devm_platform_ioremap_resource() helper has now been widely
> adopted and used in many drivers. Users of nocache and write-combined
> ioremap() variants could profit from the same code shrinkage. This
> series provides two new versions of devm_platform_ioremap_resource()
> and uses it in a few example drivers with the assumption that - just
> like was the case previously - a coccinelle script will be developed
> to ease the transition for others.

Please be aware that the number of ioremap() variants is being
reduced, as some of them are redundant (e.g. ioremap() already creates
an uncached mapping, so ioremap_nocache() is not needed).
So less is better than more ;-)

https://lore.kernel.org/lkml/20190817073253.27819-1-hch@lst.de/

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/9] lib: devres: provide new variants for devm_ioremap_resource()
  2019-08-29 14:37 ` [PATCH 3/9] lib: devres: provide new variants for devm_ioremap_resource() Bartosz Golaszewski
@ 2019-08-29 15:09   ` Arnd Bergmann
  0 siblings, 0 replies; 13+ messages in thread
From: Arnd Bergmann @ 2019-08-29 15:09 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Jonathan Corbet, Greg Kroah-Hartman, Rafael J . Wysocki,
	Alban Bedel, Linus Walleij, Geert Uytterhoeven,
	open list:DOCUMENTATION, Linux Kernel Mailing List,
	open list:GPIO SUBSYSTEM, Julia Lawall, Bartosz Golaszewski

On Thu, Aug 29, 2019 at 4:38 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> @@ -710,6 +710,10 @@ extern void devm_free_pages(struct device *dev, unsigned long addr);
>
>  void __iomem *devm_ioremap_resource(struct device *dev,
>                                     const struct resource *res);
> +void __iomem *devm_ioremap_resource_nocache(struct device *dev,
> +                                           const struct resource *res);
> +void __iomem *devm_ioremap_resource_wc(struct device *dev,
> +                                      const struct resource *res);
>
>  void __iomem *devm_of_iomap(struct device *dev,
>                             struct device_node *node, int index,
> diff --git a/lib/devres.c b/lib/devres.c

I think adding devm_ioremap_resource_wc() and
devm_platform_ioremap_resource_wc() makes sense, but I think we're
better off without devm_ioremap_resource_nocache() and
devm_ioremap_resource_cache().

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().

The ia64 version of ioremap() tries to guess whether it needs
a cached or uncached mapping, everyone else always
gets uncached these days.

       Arnd

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource()
  2019-08-29 14:48 ` [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource() Geert Uytterhoeven
@ 2019-08-30 15:59   ` Christoph Hellwig
  0 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2019-08-30 15:59 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Bartosz Golaszewski, Jonathan Corbet, Greg Kroah-Hartman,
	Rafael J . Wysocki, Alban Bedel, Linus Walleij, Arnd Bergmann,
	Geert Uytterhoeven, open list:DOCUMENTATION,
	Linux Kernel Mailing List, open list:GPIO SUBSYSTEM,
	Julia Lawall, Bartosz Golaszewski, Christoph Hellwig

On Thu, Aug 29, 2019 at 04:48:36PM +0200, Geert Uytterhoeven wrote:
> Hi Bartosz,
> 
> On Thu, Aug 29, 2019 at 4:38 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> > From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> >
> > The new devm_platform_ioremap_resource() helper has now been widely
> > adopted and used in many drivers. Users of nocache and write-combined
> > ioremap() variants could profit from the same code shrinkage. This
> > series provides two new versions of devm_platform_ioremap_resource()
> > and uses it in a few example drivers with the assumption that - just
> > like was the case previously - a coccinelle script will be developed
> > to ease the transition for others.
> 
> Please be aware that the number of ioremap() variants is being
> reduced, as some of them are redundant (e.g. ioremap() already creates
> an uncached mapping, so ioremap_nocache() is not needed).
> So less is better than more ;-)

Yes.  If I can get the ia64 and openrisc patch in I plan to send Linus
a scripted removal of ioremap_nocache after -rc1.  I already have a
local patch for current mainline as of about two weeks ago.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2019-08-30 15:59 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-29 14:37 [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource() Bartosz Golaszewski
2019-08-29 14:37 ` [PATCH 1/9] Documentation: devres: add missing entry for devm_platform_ioremap_resource() Bartosz Golaszewski
2019-08-29 14:37 ` [PATCH 2/9] lib: devres: prepare devm_ioremap_resource() for more variants Bartosz Golaszewski
2019-08-29 14:37 ` [PATCH 3/9] lib: devres: provide new variants for devm_ioremap_resource() Bartosz Golaszewski
2019-08-29 15:09   ` Arnd Bergmann
2019-08-29 14:37 ` [PATCH 4/9] drivers: provide new variants of devm_platform_ioremap_resource() Bartosz Golaszewski
2019-08-29 14:37 ` [PATCH 5/9] gpio: em: use devm_platform_ioremap_resource_nocache() Bartosz Golaszewski
2019-08-29 14:37 ` [PATCH 6/9] gpio: ath79: " Bartosz Golaszewski
2019-08-29 14:37 ` [PATCH 7/9] gpio: htc-egpio: " Bartosz Golaszewski
2019-08-29 14:37 ` [PATCH 8/9] gpio: xgene: " Bartosz Golaszewski
2019-08-29 14:37 ` [PATCH 9/9] misc: sram: use devm_platform_ioremap_resource_wc() Bartosz Golaszewski
2019-08-29 14:48 ` [PATCH 0/9] drivers: add new variants of devm_platform_ioremap_resource() Geert Uytterhoeven
2019-08-30 15:59   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).