diff mbox

[OpenWrt-Devel] ramips: reset m25p80 when shutdown

Message ID 1446928968-12589-1-git-send-email-countrysideboy@qq.com
State Changes Requested
Headers show

Commit Message

play4fun Nov. 7, 2015, 8:42 p.m. UTC
Signed-off-by: Shonn Lu <countrysideboy@qq.com>
---
 .../0064-reset-m25p80-when-shutdown.patch          | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch

Comments

Rafał Miłecki Nov. 8, 2015, 9:25 p.m. UTC | #1
On 7 November 2015 at 21:42, Shonn Lu <countrysideboy@qq.com> wrote:
> Signed-off-by: Shonn Lu <countrysideboy@qq.com>
> ---
>  .../0064-reset-m25p80-when-shutdown.patch          | 24 ++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
>  create mode 100644 target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
>
> diff --git a/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch b/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
> new file mode 100644
> index 0000000..76f916a
> --- /dev/null
> +++ b/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
> @@ -0,0 +1,24 @@
> +--- a/drivers/mtd/devices/m25p80.c
> ++++ b/drivers/mtd/devices/m25p80.c
> +@@ -319,6 +319,12 @@
> + {
> +       struct m25p     *flash = spi_get_drvdata(spi);
> +
> ++    //        play4fun: add spi flash reset code
> ++      flash->command[0] = 0x66;
> ++      spi_write(flash->spi, flash->command, 1);
> ++      flash->command[0] = 0x99;
> ++      spi_write(flash->spi, flash->command, 1);
> ++
> +       /* Clean up MTD stuff. */
> +       return mtd_device_unregister(&flash->mtd);
> + }
> +@@ -382,6 +388,8 @@
> +       .id_table       = m25p_ids,
> +       .probe  = m25p_probe,
> +       .remove = m25p_remove,
> ++      //      play4fun add shutdown method to reset spi flash
> ++      .shutdown = m25p_remove,

What's the point with that "play4fun" something? Please describe this
patch better, explain why it is needed. Did you try to submit this
patch to mainline?
play4fun Nov. 10, 2015, 2:35 a.m. UTC | #2
Yes, I'd like to submit it to mainline.For 32MB spi flash, The mt7620a soc switch to 32bit address mode.After a soft reset, the spi flash should switch to 24bit back, otherwise the rourer would hang until you do a hard reset.



------------------ 原始邮件 ------------------
发件人: "Rafał Miłecki";<zajec5@gmail.com>;
发送时间: 2015年11月9日(星期一) 凌晨5:25
收件人: "未命名"<countrysideboy@qq.com>; 
抄送: "OpenWrt Development List"<openwrt-devel@lists.openwrt.org>; 
主题: Re: [OpenWrt-Devel] [PATCH] ramips: reset m25p80 when shutdown



On 7 November 2015 at 21:42, Shonn Lu <countrysideboy@qq.com> wrote:
> Signed-off-by: Shonn Lu <countrysideboy@qq.com>

> ---

>  .../0064-reset-m25p80-when-shutdown.patch          | 24 ++++++++++++++++++++++

>  1 file changed, 24 insertions(+)

>  create mode 100644 target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch

>

> diff --git a/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch b/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch

> new file mode 100644

> index 0000000..76f916a

> --- /dev/null

> +++ b/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch

> @@ -0,0 +1,24 @@

> +--- a/drivers/mtd/devices/m25p80.c

> ++++ b/drivers/mtd/devices/m25p80.c

> +@@ -319,6 +319,12 @@

> + {

> +       struct m25p     *flash = spi_get_drvdata(spi);

> +

> ++    //        play4fun: add spi flash reset code

> ++      flash->command[0] = 0x66;

> ++      spi_write(flash->spi, flash->command, 1);

> ++      flash->command[0] = 0x99;

> ++      spi_write(flash->spi, flash->command, 1);

> ++

> +       /* Clean up MTD stuff. */

> +       return mtd_device_unregister(&flash->mtd);

> + }

> +@@ -382,6 +388,8 @@

> +       .id_table       = m25p_ids,

> +       .probe  = m25p_probe,

> +       .remove = m25p_remove,

> ++      //      play4fun add shutdown method to reset spi flash

> ++      .shutdown = m25p_remove,


What's the point with that "play4fun" something? Please describe this
patch better, explain why it is needed. Did you try to submit this
patch to mainline?

-- 
Rafał
Weijie Gao Nov. 11, 2015, 10:53 a.m. UTC | #3
2015-11-08 4:42 GMT+08:00 Shonn Lu <countrysideboy@qq.com>:

> Signed-off-by: Shonn Lu <countrysideboy@qq.com>
> ---
>  .../0064-reset-m25p80-when-shutdown.patch          | 24
> ++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
>  create mode 100644
> target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
>
> diff --git
> a/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
> b/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
> new file mode 100644
> index 0000000..76f916a
> --- /dev/null
> +++
> b/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
> @@ -0,0 +1,24 @@
> +--- a/drivers/mtd/devices/m25p80.c
> ++++ b/drivers/mtd/devices/m25p80.c
> +@@ -319,6 +319,12 @@
> + {
> +       struct m25p     *flash = spi_get_drvdata(spi);
> +
> ++    //        play4fun: add spi flash reset code
> ++      flash->command[0] = 0x66;
> ++      spi_write(flash->spi, flash->command, 1);
> ++      flash->command[0] = 0x99;
> ++      spi_write(flash->spi, flash->command, 1);
> ++
> +       /* Clean up MTD stuff. */
> +       return mtd_device_unregister(&flash->mtd);
> + }
> +@@ -382,6 +388,8 @@
> +       .id_table       = m25p_ids,
> +       .probe  = m25p_probe,
> +       .remove = m25p_remove,
> ++      //      play4fun add shutdown method to reset spi flash
> ++      .shutdown = m25p_remove,
> +
> +       /* REVISIT: many of these chips have deep power-down modes, which
> +        * should clearly be entered on suspend() to minimize power use.
> --
> 1.9.1
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


This is not enough for w25q256.
The Extended Address Register (EAR) must be cleared, or the higher half
16MB may be accessed in 3-byte addressing mode, and this will cause a boot
failure.
Arjen de Korte Nov. 11, 2015, 11:07 a.m. UTC | #4
Citeren Weijie Gao <hackpascal@gmail.com>:

> 2015-11-08 4:42 GMT+08:00 Shonn Lu <countrysideboy@qq.com>:
>
>> Signed-off-by: Shonn Lu <countrysideboy@qq.com>
>> ---
>>  .../0064-reset-m25p80-when-shutdown.patch          | 24
>> ++++++++++++++++++++++
>>  1 file changed, 24 insertions(+)
>>  create mode 100644
>> target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
>>
>> diff --git
>> a/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
>> b/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
>> new file mode 100644
>> index 0000000..76f916a
>> --- /dev/null
>> +++
>> b/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
>> @@ -0,0 +1,24 @@
>> +--- a/drivers/mtd/devices/m25p80.c
>> ++++ b/drivers/mtd/devices/m25p80.c
>> +@@ -319,6 +319,12 @@
>> + {
>> +       struct m25p     *flash = spi_get_drvdata(spi);
>> +
>> ++    //        play4fun: add spi flash reset code
>> ++      flash->command[0] = 0x66;
>> ++      spi_write(flash->spi, flash->command, 1);
>> ++      flash->command[0] = 0x99;
>> ++      spi_write(flash->spi, flash->command, 1);
>> ++
>> +       /* Clean up MTD stuff. */
>> +       return mtd_device_unregister(&flash->mtd);
>> + }
>> +@@ -382,6 +388,8 @@
>> +       .id_table       = m25p_ids,
>> +       .probe  = m25p_probe,
>> +       .remove = m25p_remove,
>> ++      //      play4fun add shutdown method to reset spi flash
>> ++      .shutdown = m25p_remove,
>> +
>> +       /* REVISIT: many of these chips have deep power-down modes, which
>> +        * should clearly be entered on suspend() to minimize power use.
>> --
>> 1.9.1
>> _______________________________________________
>> openwrt-devel mailing list
>> openwrt-devel@lists.openwrt.org
>> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
>
>
> This is not enough for w25q256.

It is.

> The Extended Address Register (EAR) must be cleared, or the higher half
> 16MB may be accessed in 3-byte addressing mode, and this will cause a boot
> failure.

 From the W25Q256FV datasheet (page 23):

"Upon  power  up  or  after  the  execution  of  a  Software/Hardware   
Reset,  the  Extended  Address  Register
values will be cleared to 0."

So sending the device a software reset, should be sufficient as the  
EAR will be cleared.
Daniel Golle Nov. 11, 2015, 11:26 a.m. UTC | #5
Hi!

On Wed, Nov 11, 2015 at 06:53:33PM +0800, Weijie Gao wrote:
> 2015-11-08 4:42 GMT+08:00 Shonn Lu <countrysideboy@qq.com>:
> 
> > Signed-off-by: Shonn Lu <countrysideboy@qq.com>
> > ---
> >  .../0064-reset-m25p80-when-shutdown.patch          | 24
> > ++++++++++++++++++++++
> >  1 file changed, 24 insertions(+)
> >  create mode 100644
> > target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
> >
> > diff --git
> > a/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
> > b/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
> > new file mode 100644
> > index 0000000..76f916a
> > --- /dev/null
> > +++
> > b/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
> > @@ -0,0 +1,24 @@
> > +--- a/drivers/mtd/devices/m25p80.c
> > ++++ b/drivers/mtd/devices/m25p80.c
> > +@@ -319,6 +319,12 @@
> > + {
> > +       struct m25p     *flash = spi_get_drvdata(spi);
> > +
> > ++    //        play4fun: add spi flash reset code
> > ++      flash->command[0] = 0x66;
> > ++      spi_write(flash->spi, flash->command, 1);
> > ++      flash->command[0] = 0x99;
> > ++      spi_write(flash->spi, flash->command, 1);
> > ++
> > +       /* Clean up MTD stuff. */
> > +       return mtd_device_unregister(&flash->mtd);
> > + }
> > +@@ -382,6 +388,8 @@
> > +       .id_table       = m25p_ids,
> > +       .probe  = m25p_probe,
> > +       .remove = m25p_remove,
> > ++      //      play4fun add shutdown method to reset spi flash
> > ++      .shutdown = m25p_remove,
> > +
> > +       /* REVISIT: many of these chips have deep power-down modes, which
> > +        * should clearly be entered on suspend() to minimize power use.
> > --
> > 1.9.1
> > _______________________________________________
> > openwrt-devel mailing list
> > openwrt-devel@lists.openwrt.org
> > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
> 
> 
> This is not enough for w25q256.
> The Extended Address Register (EAR) must be cleared, or the higher half
> 16MB may be accessed in 3-byte addressing mode, and this will cause a boot
> failure.

At least on Macronix SPI chips, using 0x66, 0x99 to reset the chip is
not nough as that will not clear the adressing-mode bits.
Using 0xE9 (EX4B; exit 4-byte mode) instead fixes the issue eg. on
MX25L256.

Also note, that while it's helpful to find out the details by directly
writing values to the SPI bus, this is probably not acceptable
upstream.

I reckon we'll need a generic shutdown function in spi-nor.c calling
set_4byte(nor, info, 0)
We can then use that in m25p_remove.



Cheers


Daniel
Dorian Schneltzer Nov. 11, 2015, 11:59 a.m. UTC | #6
Hi!
On 11/11/2015 12:26 PM, Daniel Golle wrote:
> Hi!
>
> On Wed, Nov 11, 2015 at 06:53:33PM +0800, Weijie Gao wrote:
>> 2015-11-08 4:42 GMT+08:00 Shonn Lu <countrysideboy@qq.com>:
>>
>>> Signed-off-by: Shonn Lu <countrysideboy@qq.com>
>>> ---
>>>  .../0064-reset-m25p80-when-shutdown.patch          | 24
>>> ++++++++++++++++++++++
>>>  1 file changed, 24 insertions(+)
>>>  create mode 100644
>>> target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
>>>
>>> diff --git
>>> a/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
>>> b/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
>>> new file mode 100644
>>> index 0000000..76f916a
>>> --- /dev/null
>>> +++
>>> b/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
>>> @@ -0,0 +1,24 @@
>>> +--- a/drivers/mtd/devices/m25p80.c
>>> ++++ b/drivers/mtd/devices/m25p80.c
>>> +@@ -319,6 +319,12 @@
>>> + {
>>> +       struct m25p     *flash = spi_get_drvdata(spi);
>>> +
>>> ++    //        play4fun: add spi flash reset code
>>> ++      flash->command[0] = 0x66;
>>> ++      spi_write(flash->spi, flash->command, 1);
>>> ++      flash->command[0] = 0x99;
>>> ++      spi_write(flash->spi, flash->command, 1);
>>> ++
>>> +       /* Clean up MTD stuff. */
>>> +       return mtd_device_unregister(&flash->mtd);
>>> + }
>>> +@@ -382,6 +388,8 @@
>>> +       .id_table       = m25p_ids,
>>> +       .probe  = m25p_probe,
>>> +       .remove = m25p_remove,
>>> ++      //      play4fun add shutdown method to reset spi flash
>>> ++      .shutdown = m25p_remove,
>>> +
>>> +       /* REVISIT: many of these chips have deep power-down modes,
which
>>> +        * should clearly be entered on suspend() to minimize power use.
>>> --
>>> 1.9.1
>>> _______________________________________________
>>> openwrt-devel mailing list
>>> openwrt-devel@lists.openwrt.org
>>> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
>>
>>
>> This is not enough for w25q256.
>> The Extended Address Register (EAR) must be cleared, or the higher half
>> 16MB may be accessed in 3-byte addressing mode, and this will cause a
boot
>> failure.
>
> At least on Macronix SPI chips, using 0x66, 0x99 to reset the chip is
> not nough as that will not clear the adressing-mode bits.
> Using 0xE9 (EX4B; exit 4-byte mode) instead fixes the issue eg. on
> MX25L256.
>
> Also note, that while it's helpful to find out the details by directly
> writing values to the SPI bus, this is probably not acceptable
> upstream.
>
> I reckon we'll need a generic shutdown function in spi-nor.c calling
> set_4byte(nor, info, 0)
> We can then use that in m25p_remove.
>
>
>
> Cheers
>
>
> Daniel
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Daniel is right. I had the reboot problem on the ALL5003 Module, RT5350
based and with Macronix MX25L25635E. Since Ralink U-Boot can only boot
in 24bit mode, the SPI Flash needs to be re-setted to 24bit mode from
32bit mode in order to be able to boot. Macronix has released an
application note called "MX25L25635E 256Mb Serial Flash Application in
System Reset" on their homepage, regarding exact this problem. There, in
the introduction, they wrote: "MX25L25635E provides 24-bit and 32-bit
address modes by command definition. Once the device enters 32-bit
address mode by B7 command, command E9 or power-off cycle is required to
exit the 32-bit address mode. After the flash switches to 32-bit address
mode and the system executes a warm boot (power is not off during the
system reset), the flash memory will remain in 32-bit address mode and
will not be able to boot by 24-bit addressing. "

In order to fix the problem, I used the patch from Shonn Lu, but
modified. Instead of writing 0x66 and 0x99, I just wrote 0xE9. After
this, the reboot worked like a charm. I don't know if writing just 0xE9
is enough in order to reset Winbond SPI flash. But I can confirm that
just writing an 0xE9 solves the reboot problem on Macronix 32MB SPI Flash.

I have some Winbond 25Q256FV chips here, but I need to find the time to
replace the macronix on my all5003 by a winbond in order to test the
patch. Maybe next week.


Cheers,
Dorian
play4fun Nov. 11, 2015, 12:25 p.m. UTC | #7
I do not test this patch on all the 32MB spi flash except my Youku YK1 router.I am looking forward to a generic shutdown function which adapt to Macronix or Winbond.

Cheers
Shonn
diff mbox

Patch

diff --git a/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch b/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
new file mode 100644
index 0000000..76f916a
--- /dev/null
+++ b/target/linux/ramips/patches-3.18/0064-reset-m25p80-when-shutdown.patch
@@ -0,0 +1,24 @@ 
+--- a/drivers/mtd/devices/m25p80.c
++++ b/drivers/mtd/devices/m25p80.c
+@@ -319,6 +319,12 @@
+ {
+ 	struct m25p	*flash = spi_get_drvdata(spi);
+ 
++    //	play4fun: add spi flash reset code  
++	flash->command[0] = 0x66;  
++	spi_write(flash->spi, flash->command, 1);  
++	flash->command[0] = 0x99;  
++	spi_write(flash->spi, flash->command, 1);
++ 
+ 	/* Clean up MTD stuff. */
+ 	return mtd_device_unregister(&flash->mtd);
+ }
+@@ -382,6 +388,8 @@
+ 	.id_table	= m25p_ids,
+ 	.probe	= m25p_probe,
+ 	.remove	= m25p_remove,
++	//	play4fun add shutdown method to reset spi flash
++	.shutdown = m25p_remove,
+ 
+ 	/* REVISIT: many of these chips have deep power-down modes, which
+ 	 * should clearly be entered on suspend() to minimize power use.