diff mbox

ARM: at91: pm: fix SRAM allocation

Message ID 1425292978-28135-1-git-send-email-alexandre.belloni@free-electrons.com (mailing list archive)
State New, archived
Headers show

Commit Message

Alexandre Belloni March 2, 2015, 10:42 a.m. UTC
On some platforms, there are multiple SRAM nodes defined in the device tree but
some of them are disabled, leading to allocation failure. Try to find the first
enabled SRAM node and allocate from it.

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
 arch/arm/mach-at91/pm.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

Comments

Jean-Christophe PLAGNIOL-VILLARD March 2, 2015, 10:50 a.m. UTC | #1
> On Mar 2, 2015, at 6:42 PM, Alexandre Belloni <alexandre.belloni@free-electrons.com> wrote:
> 
> On some platforms, there are multiple SRAM nodes defined in the device tree but
> some of them are disabled, leading to allocation failure. Try to find the first
> enabled SRAM node and allocate from it.
> 
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> ---
> arch/arm/mach-at91/pm.c | 20 +++++++++-----------
> 1 file changed, 9 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
> index 5e34fb143309..97cc529b6fa0 100644
> --- a/arch/arm/mach-at91/pm.c
> +++ b/arch/arm/mach-at91/pm.c
> @@ -272,35 +272,33 @@ static void __init at91_pm_sram_init(void)
> 	struct device_node *node;
> 	struct platform_device *pdev;

pdev not initialised at NULL
> 
> -	node = of_find_compatible_node(NULL, NULL, "mmio-sram");
> -	if (!node) {
> -		pr_warn("%s: failed to find sram node!\n", __func__);
> -		return;
> +	for_each_compatible_node(node, NULL, "mmio-sram") {
> +		pdev = of_find_device_by_node(node);
> +		if (pdev) {
> +			of_node_put(node);
> +			break;
> +		}
> 	}
> 
> -	pdev = of_find_device_by_node(node);
> 	if (!pdev) {
> 		pr_warn("%s: failed to find sram device!\n", __func__);
> -		goto put_node;
> +		return;
> 	}
> 
> 	sram_pool = dev_get_gen_pool(&pdev->dev);
> 	if (!sram_pool) {
> 		pr_warn("%s: sram pool unavailable!\n", __func__);
> -		goto put_node;
> +		return;
> 	}
> 
> 	sram_base = gen_pool_alloc(sram_pool, at91_slow_clock_sz);
> 	if (!sram_base) {
> 		pr_warn("%s: unable to alloc ocram!\n", __func__);
> -		goto put_node;
> +		return;
> 	}
> 
> 	sram_pbase = gen_pool_virt_to_phys(sram_pool, sram_base);
> 	slow_clock = __arm_ioremap_exec(sram_pbase, at91_slow_clock_sz, false);
> -
> -put_node:
> -	of_node_put(node);
> }
> #endif
> 
> -- 
> 2.1.0
>
Alexandre Belloni March 2, 2015, 10:57 a.m. UTC | #2
On 02/03/2015 at 18:50:27 +0800, Jean-Christophe PLAGNIOL-VILLARD wrote :
> 
> > On Mar 2, 2015, at 6:42 PM, Alexandre Belloni <alexandre.belloni@free-electrons.com> wrote:
> > 
> > On some platforms, there are multiple SRAM nodes defined in the device tree but
> > some of them are disabled, leading to allocation failure. Try to find the first
> > enabled SRAM node and allocate from it.
> > 
> > Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> > ---
> > arch/arm/mach-at91/pm.c | 20 +++++++++-----------
> > 1 file changed, 9 insertions(+), 11 deletions(-)
> > 
> > diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
> > index 5e34fb143309..97cc529b6fa0 100644
> > --- a/arch/arm/mach-at91/pm.c
> > +++ b/arch/arm/mach-at91/pm.c
> > @@ -272,35 +272,33 @@ static void __init at91_pm_sram_init(void)
> > 	struct device_node *node;
> > 	struct platform_device *pdev;
> 
> pdev not initialised at NULL

Indeed, I'll fix that. It doesn't really matter for now as all the
at91 DT have at least one sram node.

Wenyou, can you test it? If it works, I'll send v2.
Jean-Christophe PLAGNIOL-VILLARD March 2, 2015, 4:14 p.m. UTC | #3
> On Mar 2, 2015, at 6:57 PM, Alexandre Belloni <alexandre.belloni@free-electrons.com> wrote:
> 
> On 02/03/2015 at 18:50:27 +0800, Jean-Christophe PLAGNIOL-VILLARD wrote :
>> 
>>> On Mar 2, 2015, at 6:42 PM, Alexandre Belloni <alexandre.belloni@free-electrons.com> wrote:
>>> 
>>> On some platforms, there are multiple SRAM nodes defined in the device tree but
>>> some of them are disabled, leading to allocation failure. Try to find the first
>>> enabled SRAM node and allocate from it.
>>> 
>>> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
>>> ---
>>> arch/arm/mach-at91/pm.c | 20 +++++++++-----------
>>> 1 file changed, 9 insertions(+), 11 deletions(-)
>>> 
>>> diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
>>> index 5e34fb143309..97cc529b6fa0 100644
>>> --- a/arch/arm/mach-at91/pm.c
>>> +++ b/arch/arm/mach-at91/pm.c
>>> @@ -272,35 +272,33 @@ static void __init at91_pm_sram_init(void)
>>> 	struct device_node *node;
>>> 	struct platform_device *pdev;
>> 
>> pdev not initialised at NULL
> 
> Indeed, I'll fix that. It doesn't really matter for now as all the
> at91 DT have at least one sram node.
except if we drop it or when we add a new SoC and forget it

Best Regards,
J.
> 
> Wenyou, can you test it? If it works, I'll send v2.
> 
> -- 
> Alexandre Belloni, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com
Alexandre Belloni March 2, 2015, 6:15 p.m. UTC | #4
On 03/03/2015 at 00:14:57 +0800, Jean-Christophe PLAGNIOL-VILLARD wrote :
> >> pdev not initialised at NULL
> > 
> > Indeed, I'll fix that. It doesn't really matter for now as all the
> > at91 DT have at least one sram node.
> except if we drop it or when we add a new SoC and forget it
> 

Sure, I was just saying that it doesn't matter for test purposes. It
will be fixed in v2. I just want to make sure it is also working on g20
before sending it.
Wenyou Yang March 3, 2015, 3:25 a.m. UTC | #5
Hi Alexandre,

> -----Original Message-----

> From: Alexandre Belloni [mailto:alexandre.belloni@free-electrons.com]

> Sent: 2015?3?2? 18:58

> To: Jean-Christophe PLAGNIOL-VILLARD

> Cc: Ferre, Nicolas; Yang, Wenyou; linux-arm-kernel@lists.infradead.org; linux-

> kernel@vger.kernel.org

> Subject: Re: [PATCH] ARM: at91: pm: fix SRAM allocation

> 

> On 02/03/2015 at 18:50:27 +0800, Jean-Christophe PLAGNIOL-VILLARD wrote :

> >

> > > On Mar 2, 2015, at 6:42 PM, Alexandre Belloni <alexandre.belloni@free-

> electrons.com> wrote:

> > >

> > > On some platforms, there are multiple SRAM nodes defined in the

> > > device tree but some of them are disabled, leading to allocation

> > > failure. Try to find the first enabled SRAM node and allocate from it.

> > >

> > > Signed-off-by: Alexandre Belloni

> > > <alexandre.belloni@free-electrons.com>

> > > ---

> > > arch/arm/mach-at91/pm.c | 20 +++++++++-----------

> > > 1 file changed, 9 insertions(+), 11 deletions(-)

> > >

> > > diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c index

> > > 5e34fb143309..97cc529b6fa0 100644

> > > --- a/arch/arm/mach-at91/pm.c

> > > +++ b/arch/arm/mach-at91/pm.c

> > > @@ -272,35 +272,33 @@ static void __init at91_pm_sram_init(void)

> > > 	struct device_node *node;

> > > 	struct platform_device *pdev;

> >

> > pdev not initialised at NULL

> 

> Indeed, I'll fix that. It doesn't really matter for now as all the

> at91 DT have at least one sram node.

> 

> Wenyou, can you test it? If it works, I'll send v2.

It works. Thanks.

Tested it on the AT91SAM9G20EK, AT91SAM9G35EK and SAMA5D36EK board.

Tested-by: Wenyou Yang <wenyou.yang@atmel.com>


> 

> --

> Alexandre Belloni, Free Electrons

> Embedded Linux, Kernel and Android engineering http://free-electrons.com



Best Regards,
Wenyou Yang
diff mbox

Patch

diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
index 5e34fb143309..97cc529b6fa0 100644
--- a/arch/arm/mach-at91/pm.c
+++ b/arch/arm/mach-at91/pm.c
@@ -272,35 +272,33 @@  static void __init at91_pm_sram_init(void)
 	struct device_node *node;
 	struct platform_device *pdev;
 
-	node = of_find_compatible_node(NULL, NULL, "mmio-sram");
-	if (!node) {
-		pr_warn("%s: failed to find sram node!\n", __func__);
-		return;
+	for_each_compatible_node(node, NULL, "mmio-sram") {
+		pdev = of_find_device_by_node(node);
+		if (pdev) {
+			of_node_put(node);
+			break;
+		}
 	}
 
-	pdev = of_find_device_by_node(node);
 	if (!pdev) {
 		pr_warn("%s: failed to find sram device!\n", __func__);
-		goto put_node;
+		return;
 	}
 
 	sram_pool = dev_get_gen_pool(&pdev->dev);
 	if (!sram_pool) {
 		pr_warn("%s: sram pool unavailable!\n", __func__);
-		goto put_node;
+		return;
 	}
 
 	sram_base = gen_pool_alloc(sram_pool, at91_slow_clock_sz);
 	if (!sram_base) {
 		pr_warn("%s: unable to alloc ocram!\n", __func__);
-		goto put_node;
+		return;
 	}
 
 	sram_pbase = gen_pool_virt_to_phys(sram_pool, sram_base);
 	slow_clock = __arm_ioremap_exec(sram_pbase, at91_slow_clock_sz, false);
-
-put_node:
-	of_node_put(node);
 }
 #endif