* [PATCH -next 0/2] of: introduce of_address_count() helper
@ 2022-09-30 9:08 Yang Yingliang
2022-09-30 9:08 ` [PATCH -next 1/2] of/address: " Yang Yingliang
2022-09-30 9:08 ` [PATCH -next 2/2] of/platform: use " Yang Yingliang
0 siblings, 2 replies; 5+ messages in thread
From: Yang Yingliang @ 2022-09-30 9:08 UTC (permalink / raw)
To: devicetree; +Cc: robh+dt, frowand.list, yangyingliang
Introduce of_address_count() helper to count the IO resources, so
some drivers can use it instead of open-coding.
E.g. irq-orion and tegra194-cbb.
Yang Yingliang (2):
of/address: introduce of_address_count() helper
of/platform: use of_address_count() helper
drivers/of/address.c | 11 +++++++++++
drivers/of/platform.c | 5 ++---
include/linux/of_address.h | 7 +++++++
3 files changed, 20 insertions(+), 3 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH -next 1/2] of/address: introduce of_address_count() helper
2022-09-30 9:08 [PATCH -next 0/2] of: introduce of_address_count() helper Yang Yingliang
@ 2022-09-30 9:08 ` Yang Yingliang
2022-09-30 21:56 ` Rob Herring
2022-09-30 9:08 ` [PATCH -next 2/2] of/platform: use " Yang Yingliang
1 sibling, 1 reply; 5+ messages in thread
From: Yang Yingliang @ 2022-09-30 9:08 UTC (permalink / raw)
To: devicetree; +Cc: robh+dt, frowand.list, yangyingliang
Introduce of_address_count() helper to count the IO resources
instead of open-coding it.
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/of/address.c | 11 +++++++++++
include/linux/of_address.h | 7 +++++++
2 files changed, 18 insertions(+)
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 96f0a12e507c..e32846a9a8d5 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -848,6 +848,17 @@ int of_address_to_resource(struct device_node *dev, int index,
}
EXPORT_SYMBOL_GPL(of_address_to_resource);
+int of_address_count(struct device_node *np)
+{
+ struct resource res;
+ int count = 0;
+
+ while (of_address_to_resource(np, count, &res) == 0)
+ count++;
+
+ return count;
+}
+
/**
* of_iomap - Maps the memory mapped IO for a given device_node
* @np: the device whose io range will be mapped
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
index 45598dbec269..63027e8f3397 100644
--- a/include/linux/of_address.h
+++ b/include/linux/of_address.h
@@ -43,6 +43,7 @@ extern u64 of_translate_dma_address(struct device_node *dev,
extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
extern int of_address_to_resource(struct device_node *dev, int index,
struct resource *r);
+extern int of_address_count(struct device_node *np);
extern void __iomem *of_iomap(struct device_node *device, int index);
void __iomem *of_io_request_and_map(struct device_node *device,
int index, const char *name);
@@ -127,6 +128,7 @@ static inline bool of_dma_is_coherent(struct device_node *np)
#ifdef CONFIG_OF
extern int of_address_to_resource(struct device_node *dev, int index,
struct resource *r);
+extern int of_address_count(struct device_node *np);
void __iomem *of_iomap(struct device_node *node, int index);
#else
static inline int of_address_to_resource(struct device_node *dev, int index,
@@ -139,6 +141,11 @@ static inline void __iomem *of_iomap(struct device_node *device, int index)
{
return NULL;
}
+
+static inline int of_address_count(struct device_node *np)
+{
+ return 0;
+}
#endif
#define of_range_parser_init of_pci_range_parser_init
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH -next 2/2] of/platform: use of_address_count() helper
2022-09-30 9:08 [PATCH -next 0/2] of: introduce of_address_count() helper Yang Yingliang
2022-09-30 9:08 ` [PATCH -next 1/2] of/address: " Yang Yingliang
@ 2022-09-30 9:08 ` Yang Yingliang
1 sibling, 0 replies; 5+ messages in thread
From: Yang Yingliang @ 2022-09-30 9:08 UTC (permalink / raw)
To: devicetree; +Cc: robh+dt, frowand.list, yangyingliang
Use of_address_count() to instead of open-coding it.
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/of/platform.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 3507095a69f6..81c8c227ab6b 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -115,15 +115,14 @@ struct platform_device *of_device_alloc(struct device_node *np,
{
struct platform_device *dev;
int rc, i, num_reg = 0;
- struct resource *res, temp_res;
+ struct resource *res;
dev = platform_device_alloc("", PLATFORM_DEVID_NONE);
if (!dev)
return NULL;
/* count the io resources */
- while (of_address_to_resource(np, num_reg, &temp_res) == 0)
- num_reg++;
+ num_reg = of_address_count(np);
/* Populate the resource table */
if (num_reg) {
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH -next 1/2] of/address: introduce of_address_count() helper
2022-09-30 9:08 ` [PATCH -next 1/2] of/address: " Yang Yingliang
@ 2022-09-30 21:56 ` Rob Herring
2022-10-08 7:05 ` Yang Yingliang
0 siblings, 1 reply; 5+ messages in thread
From: Rob Herring @ 2022-09-30 21:56 UTC (permalink / raw)
To: Yang Yingliang; +Cc: devicetree, frowand.list
On Fri, Sep 30, 2022 at 05:08:44PM +0800, Yang Yingliang wrote:
> Introduce of_address_count() helper to count the IO resources
> instead of open-coding it.
>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> drivers/of/address.c | 11 +++++++++++
> include/linux/of_address.h | 7 +++++++
> 2 files changed, 18 insertions(+)
>
> diff --git a/drivers/of/address.c b/drivers/of/address.c
> index 96f0a12e507c..e32846a9a8d5 100644
> --- a/drivers/of/address.c
> +++ b/drivers/of/address.c
> @@ -848,6 +848,17 @@ int of_address_to_resource(struct device_node *dev, int index,
> }
> EXPORT_SYMBOL_GPL(of_address_to_resource);
>
> +int of_address_count(struct device_node *np)
> +{
> + struct resource res;
> + int count = 0;
> +
> + while (of_address_to_resource(np, count, &res) == 0)
> + count++;
> +
> + return count;
> +}
EXPORT?
However, I'd just make this always inline instead.
> +
> /**
> * of_iomap - Maps the memory mapped IO for a given device_node
> * @np: the device whose io range will be mapped
> diff --git a/include/linux/of_address.h b/include/linux/of_address.h
> index 45598dbec269..63027e8f3397 100644
> --- a/include/linux/of_address.h
> +++ b/include/linux/of_address.h
> @@ -43,6 +43,7 @@ extern u64 of_translate_dma_address(struct device_node *dev,
> extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
> extern int of_address_to_resource(struct device_node *dev, int index,
> struct resource *r);
> +extern int of_address_count(struct device_node *np);
> extern void __iomem *of_iomap(struct device_node *device, int index);
> void __iomem *of_io_request_and_map(struct device_node *device,
> int index, const char *name);
> @@ -127,6 +128,7 @@ static inline bool of_dma_is_coherent(struct device_node *np)
> #ifdef CONFIG_OF
> extern int of_address_to_resource(struct device_node *dev, int index,
> struct resource *r);
> +extern int of_address_count(struct device_node *np);
I'm pretty sure Sparc build is going to break. Sparc has its own
implementation of of_address_to_resource().
> void __iomem *of_iomap(struct device_node *node, int index);
> #else
> static inline int of_address_to_resource(struct device_node *dev, int index,
> @@ -139,6 +141,11 @@ static inline void __iomem *of_iomap(struct device_node *device, int index)
> {
> return NULL;
> }
> +
> +static inline int of_address_count(struct device_node *np)
> +{
> + return 0;
> +}
> #endif
> #define of_range_parser_init of_pci_range_parser_init
>
> --
> 2.25.1
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next 1/2] of/address: introduce of_address_count() helper
2022-09-30 21:56 ` Rob Herring
@ 2022-10-08 7:05 ` Yang Yingliang
0 siblings, 0 replies; 5+ messages in thread
From: Yang Yingliang @ 2022-10-08 7:05 UTC (permalink / raw)
To: Rob Herring; +Cc: devicetree, frowand.list, yangyingliang
Hi,
On 2022/10/1 5:56, Rob Herring wrote:
> On Fri, Sep 30, 2022 at 05:08:44PM +0800, Yang Yingliang wrote:
>> Introduce of_address_count() helper to count the IO resources
>> instead of open-coding it.
>>
>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
>> ---
>> drivers/of/address.c | 11 +++++++++++
>> include/linux/of_address.h | 7 +++++++
>> 2 files changed, 18 insertions(+)
>>
>> diff --git a/drivers/of/address.c b/drivers/of/address.c
>> index 96f0a12e507c..e32846a9a8d5 100644
>> --- a/drivers/of/address.c
>> +++ b/drivers/of/address.c
>> @@ -848,6 +848,17 @@ int of_address_to_resource(struct device_node *dev, int index,
>> }
>> EXPORT_SYMBOL_GPL(of_address_to_resource);
>>
>> +int of_address_count(struct device_node *np)
>> +{
>> + struct resource res;
>> + int count = 0;
>> +
>> + while (of_address_to_resource(np, count, &res) == 0)
>> + count++;
>> +
>> + return count;
>> +}
> EXPORT?
>
> However, I'd just make this always inline instead.
>
>> +
>> /**
>> * of_iomap - Maps the memory mapped IO for a given device_node
>> * @np: the device whose io range will be mapped
>> diff --git a/include/linux/of_address.h b/include/linux/of_address.h
>> index 45598dbec269..63027e8f3397 100644
>> --- a/include/linux/of_address.h
>> +++ b/include/linux/of_address.h
>> @@ -43,6 +43,7 @@ extern u64 of_translate_dma_address(struct device_node *dev,
>> extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
>> extern int of_address_to_resource(struct device_node *dev, int index,
>> struct resource *r);
>> +extern int of_address_count(struct device_node *np);
>> extern void __iomem *of_iomap(struct device_node *device, int index);
>> void __iomem *of_io_request_and_map(struct device_node *device,
>> int index, const char *name);
>> @@ -127,6 +128,7 @@ static inline bool of_dma_is_coherent(struct device_node *np)
>> #ifdef CONFIG_OF
>> extern int of_address_to_resource(struct device_node *dev, int index,
>> struct resource *r);
>> +extern int of_address_count(struct device_node *np);
> I'm pretty sure Sparc build is going to break. Sparc has its own
> implementation of of_address_to_resource().
Sorry for late replying.
I will make of_address_count() inline in of_address.h in v2, so it will
compatible with
Sparc.
Thanks,
Yang
>> void __iomem *of_iomap(struct device_node *node, int index);
>> #else
>> static inline int of_address_to_resource(struct device_node *dev, int index,
>> @@ -139,6 +141,11 @@ static inline void __iomem *of_iomap(struct device_node *device, int index)
>> {
>> return NULL;
>> }
>> +
>> +static inline int of_address_count(struct device_node *np)
>> +{
>> + return 0;
>> +}
>> #endif
>> #define of_range_parser_init of_pci_range_parser_init
>>
>> --
>> 2.25.1
>>
>>
> .
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-10-08 7:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-30 9:08 [PATCH -next 0/2] of: introduce of_address_count() helper Yang Yingliang
2022-09-30 9:08 ` [PATCH -next 1/2] of/address: " Yang Yingliang
2022-09-30 21:56 ` Rob Herring
2022-10-08 7:05 ` Yang Yingliang
2022-09-30 9:08 ` [PATCH -next 2/2] of/platform: use " Yang Yingliang
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).