Skip to contentSkip to conversation

gpio: mmio: use devm_platform_ioremap_resource_byname()

PATCH In review [email protected] 2 participants 2 messages Feb 17, 2020 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gpio: mmio: use devm_platform_ioremap_resource_byname()

From: chenqiwu <[email protected]>

Use devm_platform_ioremap_resource_byname() instead of calling platform_get_resource_byname() and devm_ioremap_resource() separately to simplify code.

---
changes in v2:
- remove bgpio_map() entirely.

---
 drivers/gpio/gpio-mmio.c | 28 +++++-----------------------
 1 file changed, 5 insertions(+), 23 deletions(-)
drivers/gpio/gpio-mmio.c +5 -23
index f729e3e..b7170d6 100644
@@ -654,24 +654,6 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
 
 #if IS_ENABLED(CONFIG_GPIO_GENERIC_PLATFORM)
 
-static void __iomem *bgpio_map(struct platform_device *pdev,
-			       const char *name,
-			       resource_size_t sane_sz)
-{
-	struct resource *r;
-	resource_size_t sz;
-
-	r = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
-	if (!r)
-		return NULL;
-
-	sz = resource_size(r);
-	if (sz != sane_sz)
-		return IOMEM_ERR_PTR(-EINVAL);
-
-	return devm_ioremap_resource(&pdev->dev, r);
-}
-
 #ifdef CONFIG_OF
 static const struct of_device_id bgpio_of_match[] = {
 	{ .compatible = "brcm,bcm6345-gpio" },
@@ -742,23 +724,23 @@ static int bgpio_pdev_probe(struct platform_device *pdev)
 
 	sz = resource_size(r);
 
-	dat = bgpio_map(pdev, "dat", sz);
+	dat = devm_platform_ioremap_resource_byname(pdev, "dat");
 	if (IS_ERR(dat))
 		return PTR_ERR(dat);
 
-	set = bgpio_map(pdev, "set", sz);
+	set = devm_platform_ioremap_resource_byname(pdev, "set");
 	if (IS_ERR(set))
 		return PTR_ERR(set);
 
-	clr = bgpio_map(pdev, "clr", sz);
+	clr = devm_platform_ioremap_resource_byname(pdev, "clr");
 	if (IS_ERR(clr))
 		return PTR_ERR(clr);
 
-	dirout = bgpio_map(pdev, "dirout", sz);
+	dirout = devm_platform_ioremap_resource_byname(pdev, "dirout");
 	if (IS_ERR(dirout))
 		return PTR_ERR(dirout);
 
-	dirin = bgpio_map(pdev, "dirin", sz);
+	dirin = devm_platform_ioremap_resource_byname(pdev, "dirin");
 	if (IS_ERR(dirin))
 		return PTR_ERR(dirin);
 
Signature · 1 line
1.9.1
#1 lore raw

pon., 17 lut 2020 o 11:48 <[email protected]> napisał(a):

Quoted 27 lines

From: chenqiwu <[email protected]>

Use devm_platform_ioremap_resource_byname() instead of calling platform_get_resource_byname() and devm_ioremap_resource() separately to simplify code.

---
changes in v2:
- remove bgpio_map() entirely.

---
 drivers/gpio/gpio-mmio.c | 28 +++++-----------------------
 1 file changed, 5 insertions(+), 23 deletions(-)
drivers/gpio/gpio-mmio.c +0 -4
index f729e3e..b7170d6 100644
@@ -654,24 +654,6 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
 
 #if IS_ENABLED(CONFIG_GPIO_GENERIC_PLATFORM)
 
-static void __iomem *bgpio_map(struct platform_device *pdev,
-                              const char *name,
-                              resource_size_t sane_sz)
-{

drivers/gpio/gpio-mmio.c int bgpio_init(struct gpio_chip *gc, struct device *dev, · line 670

Quoted 10 lines
drivers/gpio/gpio-mmio.c +0 -10
-       struct resource *r;
-       resource_size_t sz;
-
-       r = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
-       if (!r)
-               return NULL;
-
-       sz = resource_size(r);
-       if (sz != sane_sz)
-               return IOMEM_ERR_PTR(-EINVAL);

I missed this in v1: are you sure that this check is not needed? I'd say it's up to users to correctly define the size of mapped regions but I'd also assume the original author added this if for a reason.

Bart