Patchwork [3/3,MTD] P4080/nand: Fix the freescale lbc issue with 36bit mode

login
register
mail settings
Submitter Zang Roy-R61911
Date Aug. 6, 2010, 2:51 a.m.
Message ID <1281063096-26598-3-git-send-email-tie-fei.zang@freescale.com>
Download mbox | patch
Permalink /patch/61055/
State Superseded
Delegated to: Kumar Gala
Headers show

Comments

Zang Roy-R61911 - Aug. 6, 2010, 2:51 a.m.
From: Lan Chunhe-B25806 <b25806@freescale.com>

When system uses 36bit physical address, res.start is 36bit
physical address. But the function of in_be32 returns 32bit
physical address. Then both of them compared each other is
wrong. So by converting the address of res.start into
the right format fixes this issue.

Signed-off-by: Lan Chunhe-B25806 <b25806@freescale.com>
Signed-off-by: Roy Zang <tie-fei.zang@freescale.com>
---
 arch/powerpc/include/asm/fsl_lbc.h |    1 +
 arch/powerpc/sysdev/fsl_lbc.c      |   33 ++++++++++++++++++++++++++++++++-
 drivers/mtd/nand/fsl_elbc_nand.c   |    2 +-
 3 files changed, 34 insertions(+), 2 deletions(-)
Anton Vorontsov - Sept. 3, 2010, 11:36 a.m.
On Fri, Aug 06, 2010 at 10:51:36AM +0800, Roy Zang wrote:
[...]
>  /**
> + * convert_lbc_address - convert the base address
> + * @addr_base:	base address of the memory bank
> + *
> + * This function converts a base address of lbc into the right format for the BR
> + * registers. If the SOC has eLBC then it returns 32bit physical address else
> + * it returns 34bit physical address for local bus(Example: MPC8641).
> + */
> +unsigned int convert_lbc_address(phys_addr_t addr_base)
> +{
> +	void *dev;
> +	int compatible;
> +
> +	dev = of_find_node_by_name(NULL, "localbus");

Nope, you shouldn't do this. Never search by name.

Also, aren't there already a global dev, which was found by the
_probe() stuff?

> +	if (!dev) {
> +		printk(KERN_INFO "fsl-lbc: can't find localbus node\n");
> +		of_node_put(dev);
> +		return 0;
> +	}
> +
> +	compatible = of_device_is_compatible(dev, "fsl,elbc");
> +	of_node_put(dev);
> +	if (compatible)
> +		return addr_base & 0xffff8000;
> +	else
> +		return (addr_base & 0x0ffff8000ull) \
> +			| ((addr_base & 0x300000000ull) >> 19);
> +}
> +EXPORT_SYMBOL(convert_lbc_address);
> +
> +/**
>   * fsl_lbc_find - find Localbus bank
>   * @addr_base:	base address of the memory bank
>   *
> @@ -50,7 +80,8 @@ int fsl_lbc_find(phys_addr_t addr_base)
>  		__be32 br = in_be32(&fsl_lbc_ctrl_dev->regs->bank[i].br);
>  		__be32 or = in_be32(&fsl_lbc_ctrl_dev->regs->bank[i].or);
>  
> -		if (br & BR_V && (br & or & BR_BA) == addr_base)
> +		if (br & BR_V && (br & or & BR_BA) \

No need for "\" at the end of the line, keep == on the same line.

> +				== convert_lbc_address(addr_base))

Would be prettier if you name it fsl_lbc_addr(). Keeps prefix
the same for the rest of the file, plus makes it shorter (so
there probably won't be any need for breaking the line).

>  			return i;
>  	}
>  
> diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
> index 7bbcb3f..0e8dc40 100644
> --- a/drivers/mtd/nand/fsl_elbc_nand.c
> +++ b/drivers/mtd/nand/fsl_elbc_nand.c
> @@ -838,7 +838,7 @@ static int __devinit fsl_elbc_nand_probe(struct of_device *dev,
>  		    (in_be32(&lbc->bank[bank].br) & BR_MSEL) == BR_MS_FCM &&
>  		    (in_be32(&lbc->bank[bank].br) &
>  		     in_be32(&lbc->bank[bank].or) & BR_BA)
> -		     == res.start)
> +		     == convert_lbc_address(res.start))
>  			break;
>  
>  	if (bank >= MAX_BANKS) {
> -- 
> 1.5.6.5

Thanks,
Zang Roy-R61911 - Sept. 6, 2010, 3:56 a.m.
> -----Original Message-----
> From: Anton Vorontsov [mailto:cbouatmailru@gmail.com]
> Sent: Friday, September 03, 2010 19:36 PM
> To: Zang Roy-R61911
> Cc: linux-mtd@lists.infradead.org; Lan Chunhe-B25806; linuxppc-dev@ozlabs.org;
> akpm@linux-foundation.org; Gala Kumar-B11780
> Subject: Re: [PATCH 3/3][MTD] P4080/nand: Fix the freescale lbc issue with
> 36bit mode
> 
> On Fri, Aug 06, 2010 at 10:51:36AM +0800, Roy Zang wrote:
> [...]
> >  /**
> > + * convert_lbc_address - convert the base address
> > + * @addr_base:	base address of the memory bank
> > + *
> > + * This function converts a base address of lbc into the right format for
> the BR
> > + * registers. If the SOC has eLBC then it returns 32bit physical address
> else
> > + * it returns 34bit physical address for local bus(Example: MPC8641).
> > + */
> > +unsigned int convert_lbc_address(phys_addr_t addr_base)
> > +{
> > +	void *dev;
> > +	int compatible;
> > +
> > +	dev = of_find_node_by_name(NULL, "localbus");
> 
> Nope, you shouldn't do this. Never search by name.
OK. I will search by compatible.
> 
> Also, aren't there already a global dev, which was found by the
> _probe() stuff?
I do not see the global dev can be used in probe.

> 
> > +	if (!dev) {
> > +		printk(KERN_INFO "fsl-lbc: can't find localbus node\n");
> > +		of_node_put(dev);
> > +		return 0;
> > +	}
> > +
> > +	compatible = of_device_is_compatible(dev, "fsl,elbc");
> > +	of_node_put(dev);
> > +	if (compatible)
> > +		return addr_base & 0xffff8000;
> > +	else
> > +		return (addr_base & 0x0ffff8000ull) \
> > +			| ((addr_base & 0x300000000ull) >> 19);
> > +}
> > +EXPORT_SYMBOL(convert_lbc_address);
> > +
> > +/**
> >   * fsl_lbc_find - find Localbus bank
> >   * @addr_base:	base address of the memory bank
> >   *
> > @@ -50,7 +80,8 @@ int fsl_lbc_find(phys_addr_t addr_base)
> >  		__be32 br = in_be32(&fsl_lbc_ctrl_dev->regs->bank[i].br);
> >  		__be32 or = in_be32(&fsl_lbc_ctrl_dev->regs->bank[i].or);
> >
> > -		if (br & BR_V && (br & or & BR_BA) == addr_base)
> > +		if (br & BR_V && (br & or & BR_BA) \
> 
> No need for "\" at the end of the line, keep == on the same line.
> 
> > +				== convert_lbc_address(addr_base))
> 
> Would be prettier if you name it fsl_lbc_addr(). Keeps prefix
> the same for the rest of the file, plus makes it shorter (so
> there probably won't be any need for breaking the line).
Agree the new name.
Thanks.
Roy

Patch

diff --git a/arch/powerpc/include/asm/fsl_lbc.h b/arch/powerpc/include/asm/fsl_lbc.h
index 9b95eab..28dcf63 100644
--- a/arch/powerpc/include/asm/fsl_lbc.h
+++ b/arch/powerpc/include/asm/fsl_lbc.h
@@ -249,6 +249,7 @@  struct fsl_upm {
 	int width;
 };
 
+extern unsigned int convert_lbc_address(phys_addr_t addr_base);
 extern int fsl_lbc_find(phys_addr_t addr_base);
 extern int fsl_upm_find(phys_addr_t addr_base, struct fsl_upm *upm);
 
diff --git a/arch/powerpc/sysdev/fsl_lbc.c b/arch/powerpc/sysdev/fsl_lbc.c
index 9c9e44f..08f98d8 100644
--- a/arch/powerpc/sysdev/fsl_lbc.c
+++ b/arch/powerpc/sysdev/fsl_lbc.c
@@ -31,6 +31,36 @@  struct fsl_lbc_ctrl *fsl_lbc_ctrl_dev;
 EXPORT_SYMBOL(fsl_lbc_ctrl_dev);
 
 /**
+ * convert_lbc_address - convert the base address
+ * @addr_base:	base address of the memory bank
+ *
+ * This function converts a base address of lbc into the right format for the BR
+ * registers. If the SOC has eLBC then it returns 32bit physical address else
+ * it returns 34bit physical address for local bus(Example: MPC8641).
+ */
+unsigned int convert_lbc_address(phys_addr_t addr_base)
+{
+	void *dev;
+	int compatible;
+
+	dev = of_find_node_by_name(NULL, "localbus");
+	if (!dev) {
+		printk(KERN_INFO "fsl-lbc: can't find localbus node\n");
+		of_node_put(dev);
+		return 0;
+	}
+
+	compatible = of_device_is_compatible(dev, "fsl,elbc");
+	of_node_put(dev);
+	if (compatible)
+		return addr_base & 0xffff8000;
+	else
+		return (addr_base & 0x0ffff8000ull) \
+			| ((addr_base & 0x300000000ull) >> 19);
+}
+EXPORT_SYMBOL(convert_lbc_address);
+
+/**
  * fsl_lbc_find - find Localbus bank
  * @addr_base:	base address of the memory bank
  *
@@ -50,7 +80,8 @@  int fsl_lbc_find(phys_addr_t addr_base)
 		__be32 br = in_be32(&fsl_lbc_ctrl_dev->regs->bank[i].br);
 		__be32 or = in_be32(&fsl_lbc_ctrl_dev->regs->bank[i].or);
 
-		if (br & BR_V && (br & or & BR_BA) == addr_base)
+		if (br & BR_V && (br & or & BR_BA) \
+				== convert_lbc_address(addr_base))
 			return i;
 	}
 
diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
index 7bbcb3f..0e8dc40 100644
--- a/drivers/mtd/nand/fsl_elbc_nand.c
+++ b/drivers/mtd/nand/fsl_elbc_nand.c
@@ -838,7 +838,7 @@  static int __devinit fsl_elbc_nand_probe(struct of_device *dev,
 		    (in_be32(&lbc->bank[bank].br) & BR_MSEL) == BR_MS_FCM &&
 		    (in_be32(&lbc->bank[bank].br) &
 		     in_be32(&lbc->bank[bank].or) & BR_BA)
-		     == res.start)
+		     == convert_lbc_address(res.start))
 			break;
 
 	if (bank >= MAX_BANKS) {