linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled
@ 2017-01-19 10:06 Sebastien Decourriere
  2017-01-19 23:50 ` Langer, Thomas
  0 siblings, 1 reply; 14+ messages in thread
From: Sebastien Decourriere @ 2017-01-19 10:06 UTC (permalink / raw)
  To: linux-mtd; +Cc: linux-mips, Sebastien Decourriere

The purpose of this patch is to enable the software address endianness
swapping only when the in SoC EBU endianness swapping is disabled.
To perform this check, I look at Bit 30 of the EBU_CON_0 register.
Actually, the driver expects that the in SoC swapping is disabled.
This is the case with current bootloaders shuch as U-boot.

This applies only to vr9 (xrx200) rev 1.2 and ar10 (xrx300).

I have a router which uses a proprietary bootloader which keeps
the in SoC swapping enabled. The SoC in this router is a vrx200 v1.2.
In this SoC version, I can keep the in SoC swapping without any problem.

This patch replaces my previous broken patch.

Signed-off-by: Sebastien Decourriere <sebtx452@gmail.com>
---
 drivers/mtd/maps/lantiq-flash.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/maps/lantiq-flash.c b/drivers/mtd/maps/lantiq-flash.c
index c8febb3..1cbbdcb 100644
--- a/drivers/mtd/maps/lantiq-flash.c
+++ b/drivers/mtd/maps/lantiq-flash.c
@@ -38,6 +38,8 @@ enum {
 	LTQ_NOR_NORMAL
 };
 
+#define EBU_ENDIAN_SWAP		BIT(30)
+
 struct ltq_mtd {
 	struct resource *res;
 	struct mtd_info *mtd;
@@ -113,6 +115,20 @@ ltq_mtd_probe(struct platform_device *pdev)
 	struct ltq_mtd *ltq_mtd;
 	struct cfi_private *cfi;
 	int err;
+	bool mtd_addr_swap;
+
+	/* If SoC is vr9 >= 1.2 or ar10 and EBU endian swap
+	   is enabled, we don't need to do software address swap */
+	if ( ltq_ebu_r32(LTQ_EBU_BUSCON0) & EBU_ENDIAN_SWAP ) {
+		switch (ltq_soc_type()) {
+			case SOC_TYPE_VR9_2 :
+			case SOC_TYPE_AR10 :
+				mtd_addr_swap = false;
+				break;
+			default :
+				mtd_addr_swap = true;
+		}
+	} else mtd_addr_swap = true;
 
 	if (of_machine_is_compatible("lantiq,falcon") &&
 			(ltq_boot_select() != BS_FLASH)) {
@@ -150,7 +166,10 @@ ltq_mtd_probe(struct platform_device *pdev)
 	ltq_mtd->map->copy_from = ltq_copy_from;
 	ltq_mtd->map->copy_to = ltq_copy_to;
 
-	ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
+	if (mtd_addr_swap)
+		ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
+	else
+		ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;
 	ltq_mtd->mtd = do_map_probe("cfi_probe", ltq_mtd->map);
 	ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;
 
@@ -163,8 +182,10 @@ ltq_mtd_probe(struct platform_device *pdev)
 	mtd_set_of_node(ltq_mtd->mtd, pdev->dev.of_node);
 
 	cfi = ltq_mtd->map->fldrv_priv;
-	cfi->addr_unlock1 ^= 1;
-	cfi->addr_unlock2 ^= 1;
+	if (mtd_addr_swap) {
+		cfi->addr_unlock1 ^= 1;
+		cfi->addr_unlock2 ^= 1;
+	}
 
 	err = mtd_device_register(ltq_mtd->mtd, NULL, 0);
 	if (err) {
-- 
2.1.4

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled
  2017-01-19 10:06 [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled Sebastien Decourriere
@ 2017-01-19 23:50 ` Langer, Thomas
  0 siblings, 0 replies; 14+ messages in thread
From: Langer, Thomas @ 2017-01-19 23:50 UTC (permalink / raw)
  To: Sebastien Decourriere, linux-mtd; +Cc: linux-mips

Hello Sebastien,

> -----Original Message-----
> From: linux-mips-bounce@linux-mips.org [mailto:linux-mips-bounce@linux-
> mips.org] On Behalf Of Sebastien Decourriere
> Sent: Thursday, January 19, 2017 11:07 AM
> To: linux-mtd@lists.infradead.org
> Cc: linux-mips@linux-mips.org; Sebastien Decourriere <sebtx452@gmail.com>
> Subject: [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap
> is enabled
> 
> The purpose of this patch is to enable the software address endianness
> swapping only when the in SoC EBU endianness swapping is disabled.
> To perform this check, I look at Bit 30 of the EBU_CON_0 register.
> Actually, the driver expects that the in SoC swapping is disabled.
> This is the case with current bootloaders shuch as U-boot.
> 
> This applies only to vr9 (xrx200) rev 1.2 and ar10 (xrx300).
> 
> I have a router which uses a proprietary bootloader which keeps
> the in SoC swapping enabled. The SoC in this router is a vrx200 v1.2.
> In this SoC version, I can keep the in SoC swapping without any problem.
> 
> This patch replaces my previous broken patch.
> 
> Signed-off-by: Sebastien Decourriere <sebtx452@gmail.com>
> ---
>  drivers/mtd/maps/lantiq-flash.c | 27 ++++++++++++++++++++++++---
>  1 file changed, 24 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mtd/maps/lantiq-flash.c b/drivers/mtd/maps/lantiq-
> flash.c
> index c8febb3..1cbbdcb 100644
> --- a/drivers/mtd/maps/lantiq-flash.c
> +++ b/drivers/mtd/maps/lantiq-flash.c
> @@ -38,6 +38,8 @@ enum {
>  	LTQ_NOR_NORMAL
>  };
> 
> +#define EBU_ENDIAN_SWAP		BIT(30)
> +
>  struct ltq_mtd {
>  	struct resource *res;
>  	struct mtd_info *mtd;
> @@ -113,6 +115,20 @@ ltq_mtd_probe(struct platform_device *pdev)
>  	struct ltq_mtd *ltq_mtd;
>  	struct cfi_private *cfi;
>  	int err;
> +	bool mtd_addr_swap;
> +
> +	/* If SoC is vr9 >= 1.2 or ar10 and EBU endian swap
> +	   is enabled, we don't need to do software address swap */
> +	if ( ltq_ebu_r32(LTQ_EBU_BUSCON0) & EBU_ENDIAN_SWAP ) {

This register does not exist for all Lantiq SoCs, even the definition
is only in "arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h", but
not in "arch/mips/include/asm/mach-lantiq/falcon/lantiq_soc.h"

Please add at least a compile check for the define.

> +		switch (ltq_soc_type()) {
> +			case SOC_TYPE_VR9_2 :
> +			case SOC_TYPE_AR10 :
> +				mtd_addr_swap = false;
> +				break;
> +			default :
> +				mtd_addr_swap = true;
Missing break

> +		}
> +	} else mtd_addr_swap = true;

Has this been checked with checkpatch.pl?
This line results in message "ERROR: trailing statements should be on next line",
some other warning about spaces are also in this patch.

> 
>  	if (of_machine_is_compatible("lantiq,falcon") &&
>  			(ltq_boot_select() != BS_FLASH)) {
> @@ -150,7 +166,10 @@ ltq_mtd_probe(struct platform_device *pdev)
>  	ltq_mtd->map->copy_from = ltq_copy_from;
>  	ltq_mtd->map->copy_to = ltq_copy_to;
> 
> -	ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
> +	if (mtd_addr_swap)
> +		ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
> +	else
> +		ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;
>  	ltq_mtd->mtd = do_map_probe("cfi_probe", ltq_mtd->map);
>  	ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;
> 
> @@ -163,8 +182,10 @@ ltq_mtd_probe(struct platform_device *pdev)
>  	mtd_set_of_node(ltq_mtd->mtd, pdev->dev.of_node);
> 
>  	cfi = ltq_mtd->map->fldrv_priv;
> -	cfi->addr_unlock1 ^= 1;
> -	cfi->addr_unlock2 ^= 1;
> +	if (mtd_addr_swap) {
> +		cfi->addr_unlock1 ^= 1;
> +		cfi->addr_unlock2 ^= 1;
> +	}
> 
>  	err = mtd_device_register(ltq_mtd->mtd, NULL, 0);
>  	if (err) {
> --
> 2.1.4
> 

Regards,
Thomas

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled
  2017-01-26 11:02       ` Seb
@ 2017-01-26 16:01         ` Langer, Thomas
  0 siblings, 0 replies; 14+ messages in thread
From: Langer, Thomas @ 2017-01-26 16:01 UTC (permalink / raw)
  To: Seb; +Cc: Hauke Mehrtens, linux-mtd, linux-mips

Hi Sebastian,

> 
> > We should introduce specific compatible strings for this driver, which
> trigger this,
> > e.g. "lantiq,nor-vr9" or "lantiq,nor-ar10" (or better using family names
> "xrx200" and "xrx300")
> 
> You mean we can use the same way as other drivers, for example in the
> physmap_of_versatile.c file :
> 
> static const struct of_device_id syscon_match[] = {
>         {
>                 .compatible = "arm,integrator-ap-syscon",
>                 .data = (void *)INTEGRATOR_AP_FLASHPROT,
>         },
>         {
>                 .compatible = "arm,integrator-cp-syscon",
>                 .data = (void *)INTEGRATOR_CP_FLASHPROT,
>         },
> 
> etc...
> 
> 
> We can't filter on xrx200 or vr9, but we have to know the VR9 version
> (as the VR9 < 1.2 is not compatible with this patch).

Then extend the compatible strings with versions (where necessary).
This requires to know the SoC version for each board, but it should be 
okay and is done for other system already this way.

> 
> Regards,
> 
> Sebastien

Regards,
Thomas

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled
  2017-01-25 16:58     ` Langer, Thomas
@ 2017-01-26 11:02       ` Seb
  2017-01-26 16:01         ` Langer, Thomas
  0 siblings, 1 reply; 14+ messages in thread
From: Seb @ 2017-01-26 11:02 UTC (permalink / raw)
  To: Langer, Thomas; +Cc: Hauke Mehrtens, linux-mtd, linux-mips

Hi Thomas


> No, please avoid "of_machine_is_compatible" in drivers.

OK


> We should introduce specific compatible strings for this driver, which trigger this,
> e.g. "lantiq,nor-vr9" or "lantiq,nor-ar10" (or better using family names "xrx200" and "xrx300")

You mean we can use the same way as other drivers, for example in the
physmap_of_versatile.c file :

static const struct of_device_id syscon_match[] = {
        {
                .compatible = "arm,integrator-ap-syscon",
                .data = (void *)INTEGRATOR_AP_FLASHPROT,
        },
        {
                .compatible = "arm,integrator-cp-syscon",
                .data = (void *)INTEGRATOR_CP_FLASHPROT,
        },

etc...


We can't filter on xrx200 or vr9, but we have to know the VR9 version
(as the VR9 < 1.2 is not compatible with this patch).

Regards,

Sebastien

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled
  2017-01-25  9:04   ` Seb
@ 2017-01-25 16:58     ` Langer, Thomas
  2017-01-26 11:02       ` Seb
  0 siblings, 1 reply; 14+ messages in thread
From: Langer, Thomas @ 2017-01-25 16:58 UTC (permalink / raw)
  To: Seb, Hauke Mehrtens; +Cc: linux-mtd, linux-mips

> Hello,

Hi Sebastian

> 
> 
> > I would prefer to use a device tree option to activate this check and
> > only access LTQ_EBU_BUSCON0 when this property is set.
> 
> If I understand correctly, I have to make something like this :
> 
> ---
> 
> bool mtd_addr_swap=true;
> 
>         if (!of_machine_is_compatible("lantiq,falcon") &&
>                 of_find_property(pdev->dev.of_node,
> "lantiq,ebu_swap_check", NULL))
>                 if (ltq_ebu_r32(LTQ_EBU_BUSCON0) & EBU_FLASH_ENDIAN_SWAP)
>                         mtd_addr_swap = false;
> 

No, please avoid "of_machine_is_compatible" in drivers.

> ---
> 
> And then set this property directly on my device-specific dts file ?

We should introduce specific compatible strings for this driver, which trigger this,
e.g. "lantiq,nor-vr9" or "lantiq,nor-ar10" (or better using family names "xrx200" and "xrx300")

Regards,
Thomas

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled
  2017-01-24 21:32 ` Hauke Mehrtens
@ 2017-01-25  9:04   ` Seb
  2017-01-25 16:58     ` Langer, Thomas
  0 siblings, 1 reply; 14+ messages in thread
From: Seb @ 2017-01-25  9:04 UTC (permalink / raw)
  To: Hauke Mehrtens; +Cc: linux-mtd, linux-mips

Hello,


> I would prefer to use a device tree option to activate this check and
> only access LTQ_EBU_BUSCON0 when this property is set.

If I understand correctly, I have to make something like this :

---

bool mtd_addr_swap=true;

        if (!of_machine_is_compatible("lantiq,falcon") &&
                of_find_property(pdev->dev.of_node,
"lantiq,ebu_swap_check", NULL))
                if (ltq_ebu_r32(LTQ_EBU_BUSCON0) & EBU_FLASH_ENDIAN_SWAP)
                        mtd_addr_swap = false;

---

And then set this property directly on my device-specific dts file ?

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled
  2017-01-20  9:33 Sebastien Decourriere
  2017-01-24 17:03 ` Ralf Baechle
@ 2017-01-24 21:32 ` Hauke Mehrtens
  2017-01-25  9:04   ` Seb
  1 sibling, 1 reply; 14+ messages in thread
From: Hauke Mehrtens @ 2017-01-24 21:32 UTC (permalink / raw)
  To: Sebastien Decourriere, linux-mtd; +Cc: linux-mips

On 01/20/2017 10:33 AM, Sebastien Decourriere wrote:
> The purpose of this patch is to enable the software address endianness
> swapping only when the in SoC EBU endianness swapping is disabled.
> To perform this check, I look at Bit 30 of the EBU_CON_0 register.
> Actually, the driver expects that the in SoC swapping is disabled.
> This is the case with current bootloaders shuch as U-boot.
> 
> This applies only to vr9 (xrx200) rev 1.2 and ar10 (xrx300).
> 
> I have a router which uses a proprietary bootloader which keeps
> the in SoC swapping enabled. The SoC in this router is a vrx200 v1.2.
> In this SoC version, I can keep the in SoC swapping without any problem.
> 
> This patch replaces my previous broken patch.
> 
> Signed-off-by: Sebastien Decourriere <sebtx452@gmail.com>
> ---
>  .../mips/include/asm/mach-lantiq/xway/lantiq_soc.h |  1 +
>  drivers/mtd/maps/lantiq-flash.c                    | 29 +++++++++++++++++++---
>  2 files changed, 27 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h b/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
> index 17b41bb..0ed0896 100644
> --- a/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
> +++ b/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
> @@ -87,6 +87,7 @@ extern __iomem void *ltq_cgu_membase;
>  #define LTQ_EBU_PCC_ISTAT	0x00A0
>  #define LTQ_EBU_BUSCON1		0x0064
>  #define LTQ_EBU_ADDRSEL1	0x0024
> +#define EBU_FLASH_ENDIAN_SWAP	0x40000000
>  #define EBU_WRDIS		0x80000000
>  
>  /* WDT */
> diff --git a/drivers/mtd/maps/lantiq-flash.c b/drivers/mtd/maps/lantiq-flash.c
> index c8febb3..8d628d2 100644
> --- a/drivers/mtd/maps/lantiq-flash.c
> +++ b/drivers/mtd/maps/lantiq-flash.c
> @@ -113,6 +113,24 @@ ltq_mtd_probe(struct platform_device *pdev)
>  	struct ltq_mtd *ltq_mtd;
>  	struct cfi_private *cfi;
>  	int err;
> +	bool mtd_addr_swap = true;
> +
> +#ifdef CONFIG_SOC_TYPE_XWAY
> +	/* If SoC is vr9 rev 1.2 or ar10 and EBU endian swap
> +	 *  is enabled, we don't need to do software address swap
> +	 */
> +	if (ltq_ebu_r32(LTQ_EBU_BUSCON0) & EBU_FLASH_ENDIAN_SWAP) {
> +		switch (ltq_soc_type()) {

I would like to get rid of the calls to ltq_soc_type(). This list also
has to get extended for more recent SoCs which are not yet supported by
mainline kernel like xrx500 (GRX350/550), grx300/330.

This EBU register also does not exits on falcon, this SoC uses a
different EBU.

I would prefer to use a device tree option to activate this check and
only access LTQ_EBU_BUSCON0 when this property is set.

> +		case SOC_TYPE_VR9_2:
> +		case SOC_TYPE_AR10:
> +			mtd_addr_swap = false;
> +			break;
> +		default:
> +			mtd_addr_swap = true;
> +			break;
> +		}
> +	}
> +#endif
>  
>  	if (of_machine_is_compatible("lantiq,falcon") &&
>  			(ltq_boot_select() != BS_FLASH)) {
> @@ -150,7 +168,10 @@ ltq_mtd_probe(struct platform_device *pdev)
>  	ltq_mtd->map->copy_from = ltq_copy_from;
>  	ltq_mtd->map->copy_to = ltq_copy_to;
>  
> -	ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
> +	if (mtd_addr_swap)
> +		ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
> +	else
> +		ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;
>  	ltq_mtd->mtd = do_map_probe("cfi_probe", ltq_mtd->map);
>  	ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;
>  
> @@ -163,8 +184,10 @@ ltq_mtd_probe(struct platform_device *pdev)
>  	mtd_set_of_node(ltq_mtd->mtd, pdev->dev.of_node);
>  
>  	cfi = ltq_mtd->map->fldrv_priv;
> -	cfi->addr_unlock1 ^= 1;
> -	cfi->addr_unlock2 ^= 1;
> +	if (mtd_addr_swap) {
> +		cfi->addr_unlock1 ^= 1;
> +		cfi->addr_unlock2 ^= 1;
> +	}
>  
>  	err = mtd_device_register(ltq_mtd->mtd, NULL, 0);
>  	if (err) {
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled
  2017-01-20  9:33 Sebastien Decourriere
@ 2017-01-24 17:03 ` Ralf Baechle
  2017-01-24 21:32 ` Hauke Mehrtens
  1 sibling, 0 replies; 14+ messages in thread
From: Ralf Baechle @ 2017-01-24 17:03 UTC (permalink / raw)
  To: Sebastien Decourriere; +Cc: linux-mtd, linux-mips

On Fri, Jan 20, 2017 at 10:33:54AM +0100, Sebastien Decourriere wrote:

> The purpose of this patch is to enable the software address endianness
> swapping only when the in SoC EBU endianness swapping is disabled.
> To perform this check, I look at Bit 30 of the EBU_CON_0 register.
> Actually, the driver expects that the in SoC swapping is disabled.
> This is the case with current bootloaders shuch as U-boot.
> 
> This applies only to vr9 (xrx200) rev 1.2 and ar10 (xrx300).
> 
> I have a router which uses a proprietary bootloader which keeps
> the in SoC swapping enabled. The SoC in this router is a vrx200 v1.2.
> In this SoC version, I can keep the in SoC swapping without any problem.
> 
> This patch replaces my previous broken patch.
> 
> Signed-off-by: Sebastien Decourriere <sebtx452@gmail.com>
>  .../mips/include/asm/mach-lantiq/xway/lantiq_soc.h |  1 +
>  drivers/mtd/maps/lantiq-flash.c                    | 29 +++++++++++++++++++---

Acked-by: Ralf Baechle <ralf@linux-mips.org>

for the trivial MIPS bit.

  Ralf

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled
@ 2017-01-20  9:33 Sebastien Decourriere
  2017-01-24 17:03 ` Ralf Baechle
  2017-01-24 21:32 ` Hauke Mehrtens
  0 siblings, 2 replies; 14+ messages in thread
From: Sebastien Decourriere @ 2017-01-20  9:33 UTC (permalink / raw)
  To: linux-mtd; +Cc: linux-mips, Sebastien Decourriere

The purpose of this patch is to enable the software address endianness
swapping only when the in SoC EBU endianness swapping is disabled.
To perform this check, I look at Bit 30 of the EBU_CON_0 register.
Actually, the driver expects that the in SoC swapping is disabled.
This is the case with current bootloaders shuch as U-boot.

This applies only to vr9 (xrx200) rev 1.2 and ar10 (xrx300).

I have a router which uses a proprietary bootloader which keeps
the in SoC swapping enabled. The SoC in this router is a vrx200 v1.2.
In this SoC version, I can keep the in SoC swapping without any problem.

This patch replaces my previous broken patch.

Signed-off-by: Sebastien Decourriere <sebtx452@gmail.com>
---
 .../mips/include/asm/mach-lantiq/xway/lantiq_soc.h |  1 +
 drivers/mtd/maps/lantiq-flash.c                    | 29 +++++++++++++++++++---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h b/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
index 17b41bb..0ed0896 100644
--- a/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
+++ b/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
@@ -87,6 +87,7 @@ extern __iomem void *ltq_cgu_membase;
 #define LTQ_EBU_PCC_ISTAT	0x00A0
 #define LTQ_EBU_BUSCON1		0x0064
 #define LTQ_EBU_ADDRSEL1	0x0024
+#define EBU_FLASH_ENDIAN_SWAP	0x40000000
 #define EBU_WRDIS		0x80000000
 
 /* WDT */
diff --git a/drivers/mtd/maps/lantiq-flash.c b/drivers/mtd/maps/lantiq-flash.c
index c8febb3..8d628d2 100644
--- a/drivers/mtd/maps/lantiq-flash.c
+++ b/drivers/mtd/maps/lantiq-flash.c
@@ -113,6 +113,24 @@ ltq_mtd_probe(struct platform_device *pdev)
 	struct ltq_mtd *ltq_mtd;
 	struct cfi_private *cfi;
 	int err;
+	bool mtd_addr_swap = true;
+
+#ifdef CONFIG_SOC_TYPE_XWAY
+	/* If SoC is vr9 rev 1.2 or ar10 and EBU endian swap
+	 *  is enabled, we don't need to do software address swap
+	 */
+	if (ltq_ebu_r32(LTQ_EBU_BUSCON0) & EBU_FLASH_ENDIAN_SWAP) {
+		switch (ltq_soc_type()) {
+		case SOC_TYPE_VR9_2:
+		case SOC_TYPE_AR10:
+			mtd_addr_swap = false;
+			break;
+		default:
+			mtd_addr_swap = true;
+			break;
+		}
+	}
+#endif
 
 	if (of_machine_is_compatible("lantiq,falcon") &&
 			(ltq_boot_select() != BS_FLASH)) {
@@ -150,7 +168,10 @@ ltq_mtd_probe(struct platform_device *pdev)
 	ltq_mtd->map->copy_from = ltq_copy_from;
 	ltq_mtd->map->copy_to = ltq_copy_to;
 
-	ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
+	if (mtd_addr_swap)
+		ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
+	else
+		ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;
 	ltq_mtd->mtd = do_map_probe("cfi_probe", ltq_mtd->map);
 	ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;
 
@@ -163,8 +184,10 @@ ltq_mtd_probe(struct platform_device *pdev)
 	mtd_set_of_node(ltq_mtd->mtd, pdev->dev.of_node);
 
 	cfi = ltq_mtd->map->fldrv_priv;
-	cfi->addr_unlock1 ^= 1;
-	cfi->addr_unlock2 ^= 1;
+	if (mtd_addr_swap) {
+		cfi->addr_unlock1 ^= 1;
+		cfi->addr_unlock2 ^= 1;
+	}
 
 	err = mtd_device_register(ltq_mtd->mtd, NULL, 0);
 	if (err) {
-- 
2.1.4

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled
  2017-01-18 13:51     ` John Crispin
@ 2017-01-18 17:12       ` Seb
  0 siblings, 0 replies; 14+ messages in thread
From: Seb @ 2017-01-18 17:12 UTC (permalink / raw)
  To: John Crispin; +Cc: linux-mtd, linux-mips

> the bug is also fixed on the 300 and 500 series chips, so we would want
> to check for that aswell.
>

I added this to the begin of "ltq_mtd_probe" function:

bool mtd_addr_swap;

        if ( ltq_ebu_r32(LTQ_EBU_BUSCON0) & EBU_ENDIAN_SWAP ) {
                switch (ltq_soc_type()) {
                        case SOC_TYPE_VR9_2 :
                        case SOC_TYPE_AR10 :
                                mtd_addr_swap = false;
                                break;
                        default :
                                mtd_addr_swap = true;
                }
        } else mtd_addr_swap = true;


It's easier to add other architectures as needed. I tried it on my
OpenWrt release, and got it working fine. Is it correct in this way ?

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled
  2017-01-18 13:48   ` Seb
@ 2017-01-18 13:51     ` John Crispin
  2017-01-18 17:12       ` Seb
  0 siblings, 1 reply; 14+ messages in thread
From: John Crispin @ 2017-01-18 13:51 UTC (permalink / raw)
  To: Seb; +Cc: linux-mtd, linux-mips



On 18/01/2017 14:48, Seb wrote:
> Hi John,
> 
> 
>>>
>>>       ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
>>
>> this line should be dropped
> 
> Yes, I noticed this mistake. I fixed it but forgotten to add thix fix
> to my commit -_-
> 
>>> +     /* We swap the addresses only if the EBU endianness swap is disabled */
>>> +     if (ltq_ebu_r32(LTQ_EBU_BUSCON0) & BIT(30))
>>
>> add a define for BIT(30) please and we should really check if this a
>> v1.2 or newer. if my memory is correct this was a silicon bug inside
>> v1.0 and v1.1
> 
> In my kernel (OpenWrt) boot log I have :
> 
> [    0.000000] Linux version 4.4.14 (qa@serveurQA) (gcc version 5.3.0
> (OpenWrt GCC 5.3.0 50020) ) #150 SMP Tue Jan 17 09:18:24 UTC 2017
> [    0.000000] SoC: xRX200 rev 1.2
> [    0.000000] bootconsole [early0] enabled
> [    0.000000] CPU0 revision is: 00019556 (MIPS 34Kc)
> 
> It would be better to ensure that the SoC version is >= 1.2 (as this
> bug was fixed in this version).

the bug is also fixed on the 300 and 500 series chips, so we would want
to check for that aswell.

	John




> You can get more informations in my OpenWrt pull request :
> 
> https://github.com/openwrt/openwrt/pull/321
> 
> 
> Regards,
> 
> Sebastien.
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled
  2017-01-18 12:38 ` John Crispin
@ 2017-01-18 13:48   ` Seb
  2017-01-18 13:51     ` John Crispin
  0 siblings, 1 reply; 14+ messages in thread
From: Seb @ 2017-01-18 13:48 UTC (permalink / raw)
  To: John Crispin; +Cc: linux-mtd, linux-mips

Hi John,


>>
>>       ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
>
> this line should be dropped

Yes, I noticed this mistake. I fixed it but forgotten to add thix fix
to my commit -_-

>> +     /* We swap the addresses only if the EBU endianness swap is disabled */
>> +     if (ltq_ebu_r32(LTQ_EBU_BUSCON0) & BIT(30))
>
> add a define for BIT(30) please and we should really check if this a
> v1.2 or newer. if my memory is correct this was a silicon bug inside
> v1.0 and v1.1

In my kernel (OpenWrt) boot log I have :

[    0.000000] Linux version 4.4.14 (qa@serveurQA) (gcc version 5.3.0
(OpenWrt GCC 5.3.0 50020) ) #150 SMP Tue Jan 17 09:18:24 UTC 2017
[    0.000000] SoC: xRX200 rev 1.2
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 00019556 (MIPS 34Kc)

It would be better to ensure that the SoC version is >= 1.2 (as this
bug was fixed in this version).

You can get more informations in my OpenWrt pull request :

https://github.com/openwrt/openwrt/pull/321


Regards,

Sebastien.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled
  2017-01-18 12:10 Sebastien Decourriere
@ 2017-01-18 12:38 ` John Crispin
  2017-01-18 13:48   ` Seb
  0 siblings, 1 reply; 14+ messages in thread
From: John Crispin @ 2017-01-18 12:38 UTC (permalink / raw)
  To: Sebastien Decourriere, linux-mtd; +Cc: linux-mips

Hi Sebastien,

thanks, comments inline

On 18/01/2017 13:10, Sebastien Decourriere wrote:
> The purpose of this patch is to enable the software address endianness
> swapping only when the in SoC EBU endianness swapping is disabled.
> To perform this check, I look at Bit 30 of the EBU_CON_0 register.
> Actually, the driver expects that the in SoC swapping is disabled.
> This is the case with current bootloaders shuch as U-boot. But,
> 
> I have a router which uses a proprietary bootloader which keeps
> the in SoC swapping enabled. The SoC in this router is a vrx200 v1.2.
> In this SoC version, I can keep the in SoC swapping without any problem.
> 
> Signed-off-by: Sebastien Decourriere <sebtx452@gmail.com>
> ---
>  drivers/mtd/maps/lantiq-flash.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/maps/lantiq-flash.c b/drivers/mtd/maps/lantiq-flash.c
> index c8febb3..a091efa 100644
> --- a/drivers/mtd/maps/lantiq-flash.c
> +++ b/drivers/mtd/maps/lantiq-flash.c
> @@ -151,6 +151,11 @@ ltq_mtd_probe(struct platform_device *pdev)
>  	ltq_mtd->map->copy_to = ltq_copy_to;
>  
>  	ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;

this line should be dropped

> +	/* We swap the addresses only if the EBU endianness swap is disabled */
> +	if (ltq_ebu_r32(LTQ_EBU_BUSCON0) & BIT(30))

add a define for BIT(30) please and we should really check if this a
v1.2 or newer. if my memory is correct this was a silicon bug inside
v1.0 and v1.1

	John

> +		ltq_mtd->map[i].map_priv_1 = LTQ_NOR_NORMAL;
> +	else
> +		ltq_mtd->map[i].map_priv_1 = LTQ_NOR_PROBING;
>  	ltq_mtd->mtd = do_map_probe("cfi_probe", ltq_mtd->map);
>  	ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;
>  
> @@ -163,8 +168,11 @@ ltq_mtd_probe(struct platform_device *pdev)
>  	mtd_set_of_node(ltq_mtd->mtd, pdev->dev.of_node);
>  
>  	cfi = ltq_mtd->map->fldrv_priv;
> -	cfi->addr_unlock1 ^= 1;
> -	cfi->addr_unlock2 ^= 1;
> +	/* We swap the addresses only if the EBU endianness swap is disabled */
> +	if (!(ltq_ebu_r32(LTQ_EBU_BUSCON0) & BIT(30))) {
> +		cfi->addr_unlock1 ^= 1;
> +		cfi->addr_unlock2 ^= 1;
> +	}
>  
>  	err = mtd_device_register(ltq_mtd->mtd, NULL, 0);
>  	if (err) {
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled
@ 2017-01-18 12:10 Sebastien Decourriere
  2017-01-18 12:38 ` John Crispin
  0 siblings, 1 reply; 14+ messages in thread
From: Sebastien Decourriere @ 2017-01-18 12:10 UTC (permalink / raw)
  To: linux-mtd; +Cc: linux-mips, Sebastien Decourriere

The purpose of this patch is to enable the software address endianness
swapping only when the in SoC EBU endianness swapping is disabled.
To perform this check, I look at Bit 30 of the EBU_CON_0 register.
Actually, the driver expects that the in SoC swapping is disabled.
This is the case with current bootloaders shuch as U-boot. But,

I have a router which uses a proprietary bootloader which keeps
the in SoC swapping enabled. The SoC in this router is a vrx200 v1.2.
In this SoC version, I can keep the in SoC swapping without any problem.

Signed-off-by: Sebastien Decourriere <sebtx452@gmail.com>
---
 drivers/mtd/maps/lantiq-flash.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/maps/lantiq-flash.c b/drivers/mtd/maps/lantiq-flash.c
index c8febb3..a091efa 100644
--- a/drivers/mtd/maps/lantiq-flash.c
+++ b/drivers/mtd/maps/lantiq-flash.c
@@ -151,6 +151,11 @@ ltq_mtd_probe(struct platform_device *pdev)
 	ltq_mtd->map->copy_to = ltq_copy_to;
 
 	ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
+	/* We swap the addresses only if the EBU endianness swap is disabled */
+	if (ltq_ebu_r32(LTQ_EBU_BUSCON0) & BIT(30))
+		ltq_mtd->map[i].map_priv_1 = LTQ_NOR_NORMAL;
+	else
+		ltq_mtd->map[i].map_priv_1 = LTQ_NOR_PROBING;
 	ltq_mtd->mtd = do_map_probe("cfi_probe", ltq_mtd->map);
 	ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;
 
@@ -163,8 +168,11 @@ ltq_mtd_probe(struct platform_device *pdev)
 	mtd_set_of_node(ltq_mtd->mtd, pdev->dev.of_node);
 
 	cfi = ltq_mtd->map->fldrv_priv;
-	cfi->addr_unlock1 ^= 1;
-	cfi->addr_unlock2 ^= 1;
+	/* We swap the addresses only if the EBU endianness swap is disabled */
+	if (!(ltq_ebu_r32(LTQ_EBU_BUSCON0) & BIT(30))) {
+		cfi->addr_unlock1 ^= 1;
+		cfi->addr_unlock2 ^= 1;
+	}
 
 	err = mtd_device_register(ltq_mtd->mtd, NULL, 0);
 	if (err) {
-- 
2.1.4

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2017-01-26 16:01 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-19 10:06 [PATCH] mtd: maps: lantiq-flash: Check if the EBU endianness swap is enabled Sebastien Decourriere
2017-01-19 23:50 ` Langer, Thomas
  -- strict thread matches above, loose matches on Subject: below --
2017-01-20  9:33 Sebastien Decourriere
2017-01-24 17:03 ` Ralf Baechle
2017-01-24 21:32 ` Hauke Mehrtens
2017-01-25  9:04   ` Seb
2017-01-25 16:58     ` Langer, Thomas
2017-01-26 11:02       ` Seb
2017-01-26 16:01         ` Langer, Thomas
2017-01-18 12:10 Sebastien Decourriere
2017-01-18 12:38 ` John Crispin
2017-01-18 13:48   ` Seb
2017-01-18 13:51     ` John Crispin
2017-01-18 17:12       ` Seb

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).