[PATCH 03/12] driver: implement dev_platform_get_and_ioremap_resource
Ahmad Fatoum
a.fatoum at pengutronix.de
Wed Mar 13 03:56:22 PDT 2024
To simplify porting of Linux drivers that make use of this function, add
an implementation to barebox. This was so far not done, because AT91 has
I/O memory regions that conflict with the error pointers.
Therefore, we emit a warning if we run into such a conflict.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
drivers/base/driver.c | 19 +++++++++++++++++++
include/driver.h | 4 ++++
2 files changed, 23 insertions(+)
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index b2d428b70550..fbc5cbebe0ab 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -538,6 +538,25 @@ void __iomem *dev_request_mem_region_by_name(struct device *dev,
}
EXPORT_SYMBOL(dev_request_mem_region_by_name);
+void __iomem *dev_platform_get_and_ioremap_resource(struct device *dev,
+ int num,
+ struct resource **out_res)
+{
+ struct resource *res;
+
+ res = dev_request_mem_resource(dev, num);
+ if (IS_ERR(res))
+ return IOMEM_ERR_PTR(PTR_ERR(res));
+ else if (WARN_ON(IS_ERR_VALUE(res->start)))
+ return IOMEM_ERR_PTR(-EINVAL);
+
+ if (out_res)
+ *out_res = res;
+
+ return IOMEM(res->start);
+}
+EXPORT_SYMBOL(dev_platform_get_and_ioremap_resource);
+
struct resource *dev_request_mem_resource(struct device *dev, int num)
{
struct resource *res;
diff --git a/include/driver.h b/include/driver.h
index 7ff65d63946d..a61b9dca2285 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -289,6 +289,10 @@ struct resource *dev_request_mem_resource(struct device *dev, int num);
struct resource *dev_request_mem_resource_by_name(struct device *dev,
const char *name);
+void __iomem *dev_platform_get_and_ioremap_resource(struct device *dev,
+ int num,
+ struct resource **out_res);
+
/*
* exlusively request register base 'num' for a device
* will return NULL on error
--
2.39.2
More information about the barebox
mailing list