2019-12-10 20:32:42

by Frank Lee

[permalink] [raw]
Subject: [PATCH] drivers: add devm_platform_ioremap_resource_byname() helper

There are currently 300+ instances of using platform_get_resource_byname()
and devm_ioremap_resource() together in the kernel tree.

This patch wraps these two calls in a single helper.

Signed-off-by: Yangtao Li <[email protected]>
---
drivers/base/platform.c | 22 +++++++++++++++++++++-
include/linux/platform_device.h | 3 +++
2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index b6c6c7d97d5b..9c4f5e229600 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -60,6 +60,7 @@ struct resource *platform_get_resource(struct platform_device *dev,
}
EXPORT_SYMBOL_GPL(platform_get_resource);

+#ifdef CONFIG_HAS_IOMEM
/**
* devm_platform_ioremap_resource - call devm_ioremap_resource() for a platform
* device
@@ -68,7 +69,7 @@ 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)
{
@@ -78,6 +79,25 @@ void __iomem *devm_platform_ioremap_resource(struct platform_device *pdev,
return devm_ioremap_resource(&pdev->dev, res);
}
EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource);
+
+/**
+ * devm_platform_ioremap_resource_byname - call devm_ioremap_resource() for
+ * a platform device
+ *
+ * @pdev: platform device to use both for memory resource lookup as well as
+ * resource managemend
+ * @name: resource name
+ */
+void __iomem *
+devm_platform_ioremap_resource_byname(struct platform_device *pdev,
+ const char *name)
+{
+ struct resource *res;
+
+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
+ return devm_ioremap_resource(&pdev->dev, res);
+}
+EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource_byname);
#endif /* CONFIG_HAS_IOMEM */

static int __platform_get_irq(struct platform_device *dev, unsigned int num)
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 1b5cec067533..24ff5da9c532 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -63,6 +63,9 @@ extern int platform_irq_count(struct platform_device *);
extern struct resource *platform_get_resource_byname(struct platform_device *,
unsigned int,
const char *);
+extern void __iomem *
+devm_platform_ioremap_resource_byname(struct platform_device *pdev,
+ const char *name);
extern int platform_get_irq_byname(struct platform_device *, const char *);
extern int platform_add_devices(struct platform_device **, int);

--
2.17.1


2019-12-10 20:32:42

by Frank Lee

[permalink] [raw]
Subject: [PATCH 1/5] nvmem: sunxi_sid: convert to devm_platform_ioremap_resource

Use devm_platform_ioremap_resource() to simplify code.

Signed-off-by: Yangtao Li <[email protected]>
---
drivers/nvmem/sunxi_sid.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/nvmem/sunxi_sid.c b/drivers/nvmem/sunxi_sid.c
index e26ef1bbf198..c54adf60b155 100644
--- a/drivers/nvmem/sunxi_sid.c
+++ b/drivers/nvmem/sunxi_sid.c
@@ -112,7 +112,6 @@ static int sun8i_sid_read_by_reg(void *context, unsigned int offset,
static int sunxi_sid_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct resource *res;
struct nvmem_config *nvmem_cfg;
struct nvmem_device *nvmem;
struct sunxi_sid *sid;
@@ -129,8 +128,7 @@ static int sunxi_sid_probe(struct platform_device *pdev)
return -EINVAL;
sid->value_offset = cfg->value_offset;

- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- sid->base = devm_ioremap_resource(dev, res);
+ sid->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(sid->base))
return PTR_ERR(sid->base);

--
2.17.1

2019-12-10 20:32:45

by Frank Lee

[permalink] [raw]
Subject: [PATCH 2/5] nvmem: lpc18xx_otp: convert to devm_platform_ioremap_resource

Use devm_platform_ioremap_resource() to simplify code.

Signed-off-by: Yangtao Li <[email protected]>
---
drivers/nvmem/lpc18xx_otp.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/nvmem/lpc18xx_otp.c b/drivers/nvmem/lpc18xx_otp.c
index 16c92ea85d49..8faed05e3cbe 100644
--- a/drivers/nvmem/lpc18xx_otp.c
+++ b/drivers/nvmem/lpc18xx_otp.c
@@ -68,14 +68,12 @@ static int lpc18xx_otp_probe(struct platform_device *pdev)
{
struct nvmem_device *nvmem;
struct lpc18xx_otp *otp;
- struct resource *res;

otp = devm_kzalloc(&pdev->dev, sizeof(*otp), GFP_KERNEL);
if (!otp)
return -ENOMEM;

- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- otp->base = devm_ioremap_resource(&pdev->dev, res);
+ otp->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(otp->base))
return PTR_ERR(otp->base);

--
2.17.1

2019-12-10 20:32:53

by Frank Lee

[permalink] [raw]
Subject: [PATCH 3/5] nvmem: meson-mx-efuse: convert to devm_platform_ioremap_resource

Use devm_platform_ioremap_resource() to simplify code.

Signed-off-by: Yangtao Li <[email protected]>
---
drivers/nvmem/meson-mx-efuse.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/nvmem/meson-mx-efuse.c b/drivers/nvmem/meson-mx-efuse.c
index 07c9f38c1c60..24c6e8b15987 100644
--- a/drivers/nvmem/meson-mx-efuse.c
+++ b/drivers/nvmem/meson-mx-efuse.c
@@ -194,7 +194,6 @@ static int meson_mx_efuse_probe(struct platform_device *pdev)
{
const struct meson_mx_efuse_platform_data *drvdata;
struct meson_mx_efuse *efuse;
- struct resource *res;

drvdata = of_device_get_match_data(&pdev->dev);
if (!drvdata)
@@ -204,8 +203,7 @@ static int meson_mx_efuse_probe(struct platform_device *pdev)
if (!efuse)
return -ENOMEM;

- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- efuse->base = devm_ioremap_resource(&pdev->dev, res);
+ efuse->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(efuse->base))
return PTR_ERR(efuse->base);

--
2.17.1

2019-12-10 20:34:23

by Frank Lee

[permalink] [raw]
Subject: [PATCH 4/5] nvmem: bcm-ocotp: convert to devm_platform_ioremap_resource

Use devm_platform_ioremap_resource() to simplify code.

Signed-off-by: Yangtao Li <[email protected]>
---
drivers/nvmem/bcm-ocotp.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/nvmem/bcm-ocotp.c b/drivers/nvmem/bcm-ocotp.c
index a8097511582a..87b7198a7676 100644
--- a/drivers/nvmem/bcm-ocotp.c
+++ b/drivers/nvmem/bcm-ocotp.c
@@ -254,7 +254,6 @@ MODULE_DEVICE_TABLE(acpi, bcm_otpc_acpi_ids);
static int bcm_otpc_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct resource *res;
struct otpc_priv *priv;
struct nvmem_device *nvmem;
int err;
@@ -269,8 +268,7 @@ static int bcm_otpc_probe(struct platform_device *pdev)
return -ENODEV;

/* Get OTP base address register. */
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- priv->base = devm_ioremap_resource(dev, res);
+ priv->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(priv->base)) {
dev_err(dev, "unable to map I/O memory\n");
return PTR_ERR(priv->base);
--
2.17.1

2019-12-10 20:35:08

by Frank Lee

[permalink] [raw]
Subject: Re: [PATCH 1/5] nvmem: sunxi_sid: convert to devm_platform_ioremap_resource

There is no 5/5 in this patchset, a small mistake.

Thx,
Yangtao

2019-12-10 20:42:37

by Martin Blumenstingl

[permalink] [raw]
Subject: Re: [PATCH 3/5] nvmem: meson-mx-efuse: convert to devm_platform_ioremap_resource

On Tue, Dec 10, 2019 at 9:33 PM Yangtao Li <[email protected]> wrote:
>
> Use devm_platform_ioremap_resource() to simplify code.
>
> Signed-off-by: Yangtao Li <[email protected]>
Reviewed-by: Martin Blumenstingl <[email protected]>

thank you for taking care of this!


Martin

2019-12-28 17:43:02

by Frank Lee

[permalink] [raw]
Subject: Re: [PATCH] drivers: add devm_platform_ioremap_resource_byname() helper

ping...

On Wed, Dec 11, 2019 at 4:31 AM Yangtao Li <[email protected]> wrote:
>
> There are currently 300+ instances of using platform_get_resource_byname()
> and devm_ioremap_resource() together in the kernel tree.
>
> This patch wraps these two calls in a single helper.
>
> Signed-off-by: Yangtao Li <[email protected]>
> ---
> drivers/base/platform.c | 22 +++++++++++++++++++++-
> include/linux/platform_device.h | 3 +++
> 2 files changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index b6c6c7d97d5b..9c4f5e229600 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -60,6 +60,7 @@ struct resource *platform_get_resource(struct platform_device *dev,
> }
> EXPORT_SYMBOL_GPL(platform_get_resource);
>
> +#ifdef CONFIG_HAS_IOMEM
> /**
> * devm_platform_ioremap_resource - call devm_ioremap_resource() for a platform
> * device
> @@ -68,7 +69,7 @@ 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)
> {
> @@ -78,6 +79,25 @@ void __iomem *devm_platform_ioremap_resource(struct platform_device *pdev,
> return devm_ioremap_resource(&pdev->dev, res);
> }
> EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource);
> +
> +/**
> + * devm_platform_ioremap_resource_byname - call devm_ioremap_resource() for
> + * a platform device
> + *
> + * @pdev: platform device to use both for memory resource lookup as well as
> + * resource managemend
> + * @name: resource name
> + */
> +void __iomem *
> +devm_platform_ioremap_resource_byname(struct platform_device *pdev,
> + const char *name)
> +{
> + struct resource *res;
> +
> + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
> + return devm_ioremap_resource(&pdev->dev, res);
> +}
> +EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource_byname);
> #endif /* CONFIG_HAS_IOMEM */
>
> static int __platform_get_irq(struct platform_device *dev, unsigned int num)
> diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
> index 1b5cec067533..24ff5da9c532 100644
> --- a/include/linux/platform_device.h
> +++ b/include/linux/platform_device.h
> @@ -63,6 +63,9 @@ extern int platform_irq_count(struct platform_device *);
> extern struct resource *platform_get_resource_byname(struct platform_device *,
> unsigned int,
> const char *);
> +extern void __iomem *
> +devm_platform_ioremap_resource_byname(struct platform_device *pdev,
> + const char *name);
> extern int platform_get_irq_byname(struct platform_device *, const char *);
> extern int platform_add_devices(struct platform_device **, int);
>
> --
> 2.17.1
>

2019-12-29 12:15:51

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH] drivers: add devm_platform_ioremap_resource_byname() helper

sob., 28 gru 2019 o 18:39 Frank Lee <[email protected]> napisaƂ(a):
>
> ping...
>
> On Wed, Dec 11, 2019 at 4:31 AM Yangtao Li <[email protected]> wrote:
> >
> > There are currently 300+ instances of using platform_get_resource_byname()
> > and devm_ioremap_resource() together in the kernel tree.
> >
> > This patch wraps these two calls in a single helper.
> >
> > Signed-off-by: Yangtao Li <[email protected]>
> > ---
> > drivers/base/platform.c | 22 +++++++++++++++++++++-
> > include/linux/platform_device.h | 3 +++
> > 2 files changed, 24 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> > index b6c6c7d97d5b..9c4f5e229600 100644
> > --- a/drivers/base/platform.c
> > +++ b/drivers/base/platform.c
> > @@ -60,6 +60,7 @@ struct resource *platform_get_resource(struct platform_device *dev,
> > }
> > EXPORT_SYMBOL_GPL(platform_get_resource);
> >
> > +#ifdef CONFIG_HAS_IOMEM
> > /**
> > * devm_platform_ioremap_resource - call devm_ioremap_resource() for a platform
> > * device
> > @@ -68,7 +69,7 @@ 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)
> > {
> > @@ -78,6 +79,25 @@ void __iomem *devm_platform_ioremap_resource(struct platform_device *pdev,
> > return devm_ioremap_resource(&pdev->dev, res);
> > }
> > EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource);
> > +
> > +/**
> > + * devm_platform_ioremap_resource_byname - call devm_ioremap_resource() for
> > + * a platform device
> > + *
> > + * @pdev: platform device to use both for memory resource lookup as well as
> > + * resource managemend
> > + * @name: resource name
> > + */
> > +void __iomem *
> > +devm_platform_ioremap_resource_byname(struct platform_device *pdev,
> > + const char *name)
> > +{
> > + struct resource *res;
> > +
> > + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
> > + return devm_ioremap_resource(&pdev->dev, res);
> > +}
> > +EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource_byname);
> > #endif /* CONFIG_HAS_IOMEM */
> >
> > static int __platform_get_irq(struct platform_device *dev, unsigned int num)
> > diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
> > index 1b5cec067533..24ff5da9c532 100644
> > --- a/include/linux/platform_device.h
> > +++ b/include/linux/platform_device.h
> > @@ -63,6 +63,9 @@ extern int platform_irq_count(struct platform_device *);
> > extern struct resource *platform_get_resource_byname(struct platform_device *,
> > unsigned int,
> > const char *);
> > +extern void __iomem *
> > +devm_platform_ioremap_resource_byname(struct platform_device *pdev,
> > + const char *name);
> > extern int platform_get_irq_byname(struct platform_device *, const char *);
> > extern int platform_add_devices(struct platform_device **, int);
> >
> > --
> > 2.17.1
> >

This exact routine has existed upstream since commit c9c8641d3ebd
("drivers: provide devm_platform_ioremap_resource_byname()"). What
version are you working on?

Bart