mtd: nand: raw: atmel: R/B gpio on sam9x60
Subsystems (4)
cover mtd: nand: raw: atmel: R/B gpio on sam9x60
Hello everyone,
this is a patch series wtih some real fixes _and_ a question or some kind of support request in the cover letter. I would be happy if anyone could read the cover letter carefully and answer to that one what might be the problem I see. O:-)
I'm currently working on the sam9x60-curiosity board and especially trying to get it booting from onboard raw NAND flash. As reported in my last series I got the flash recognized already. However interacting with it was terribly slow, because nand_wait_ready() calling atmel_nand_dev_ready() ran into a 400ms timeout in several occasions, especially when reading from the device. Reading a single block triggered that timeout two times per page, which summed up to over 50 seconds for 64 × 4096 = 256k Bytes!
(You can have U-Boot print that warning from nand_wait_ready() by increasing the console log level to at least "warn".)
Note: the dts from atmel/next seems correct to me, I double checked that again. My own debug log messages showed the GPIO is accessed, and if you add enough debug messages sometimes the timeout is not reached, so I'm sure the NAND chip eventually switches that R/B line and the code correctly sees that, that line level change however takes ages, something between 400ms and 500ms most of the times.
I vaguely remembered on SAMA5D2 the old atmel raw nand driver is used which does not support reading the R/B signal, but nevertheless works. I'm not familiar in detail with those raw NAND flash chips, but as far as I can understand, there are other ways to determine if the chip is ready or busy. So after I removed that rb-gpio parameter from 'at91-sam9x60_curiosity.dts' I ran into the bug fixed by patch 2.
With that patch applied _and_ rb-gpio still removed from dts, raw NAND access is reasonably fast on sam9x60-curiosity board. (You might want to rebase to atmel/next for testing this.) Not sure if I should send a patch for that dts change, because I suppose it's a workaround only and not addressing the actual cause?
I think the fix is correct in itself, I tested different combinations and compared with the driver in Linux, however …
Can anyone explain to me, why flash access is sooo slow if the R/B gpio is used? Especially in comparision to Linux, where I don't need to remove that thing from dts and it works reasonably fast?
The actual flash chip is a Macronix MX30LF4G28AD, 512 MiB, SLC, erase
size: 256 KiB, page size: 4096, OOB size: 256.
Greets
Alex
P.S.: although not returned by get_maintainer.pl I added Eugen to Cc because he is maintainer of the at91 and might have some insight if it is a general problem of the nand controller in at91 socs?
Alexander Dahl (2):
mtd: nand: raw: atmel: Remove duplicate line
mtd: nand: raw: atmel: Add error handling when rb-gpios missing
drivers/mtd/nand/raw/atmel/nand-controller.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
base-commit: a169438411f9277cc689c14078151aa1d1caae3c
Signature · 1 line
2.30.2
PATCH 1/2 mtd: nand: raw: atmel: Remove duplicate line
--- drivers/mtd/nand/raw/atmel/nand-controller.c | 1 - 1 file changed, 1 deletion(-)
drivers/mtd/nand/raw/atmel/nand-controller.c +0 -1
@@ -1474,7 +1474,6 @@ static void atmel_nand_init(struct atmel_nand_controller *nc, mtd->dev->parent = nc->dev; nand->controller = &nc->base; - nand->controller = &nc->base; chip->cmd_ctrl = atmel_nand_cmd_ctrl; chip->read_byte = atmel_nand_read_byte;
Signature · 1 line
2.30.2
Re: [PATCH 1/2] mtd: nand: raw: atmel: Remove duplicate line
Hi
Quoted 19 lines · Alexander Dahl
Signed-off-by Alexander Dahl <[email protected]>--- drivers/mtd/nand/raw/atmel/nand-controller.c | 1 - 1 file changed, 1 deletion(-)drivers/mtd/nand/raw/atmel/nand-controller.c +0
-2@@ -1474,7 +1474,6 @@ static void atmel_nand_init(struct atmel_nand_controller *nc, mtd->dev->parent = nc->dev; nand->controller = &nc->base; - nand->controller = &nc->base; chip->cmd_ctrl = atmel_nand_cmd_ctrl; chip->read_byte = atmel_nand_read_byte; --
Quoted 2 lines
2.30.2
Signature · 11 lines
Michael Nazzareno Trimarchi Co-Founder & Chief Executive Officer M. +39 347 913 2170 [email protected] __________________________________ Amarula Solutions BV Joop Geesinkweg 125, 1114 AB, Amsterdam, NL T. +31 (0)85 111 9172 [email protected] www.amarulasolutions.com
Re: [PATCH 1/2] mtd: nand: raw: atmel: Remove duplicate line
Quoted 8 lines · Michael Nazzareno Trimarchi
Hi
Quoted 2 lines · Alexander Dahl
Signed-off-by Alexander Dahl <[email protected]>Reviewed-by Michael Trimarchi <[email protected]>
Applied this one patch to u-boot-at91/next , thanks !
PATCH 2/2 mtd: nand: raw: atmel: Add error handling when rb-gpios missing
In reply to Alexander DahlAdapt behaviour to Linux kernel driver.
The return value of gpio_request_by_name_nodev() was not checked before, and thus in case 'rb-gpios' was missing in DT, rb.type was set to ATMEL_NAND_GPIO_RB nevertheless, leading to output like this for example (on sam9x60-curiosity with the line removed from dts):
NAND: Could not find valid ONFI parameter page; aborting device found, Manufacturer ID: 0xc2, Chip ID: 0xdc Macronix NAND 512MiB 3,3V 8-bit
512 MiB, SLC, erase size: 256 KiB, page size: 4096, OOB size: 64 atmel-nand-controller nand-controller: NAND scan failed: -22 Failed to probe nand driver (err = -22)
Failed to initialize NAND controller. (error -22)
0 MiB
Note: not having that gpio assigned in dts is fine, the driver does not override nand_chip->dev_ready() then and a generic solution is used.
--- drivers/mtd/nand/raw/atmel/nand-controller.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/mtd/nand/raw/atmel/nand-controller.c +7 -4
@@ -1600,10 +1600,13 @@ static struct atmel_nand *atmel_nand_create(struct atmel_nand_controller *nc, nand->cs[i].rb.type =ATMEL_NAND_NATIVE_RB ; nand->cs[i].rb.id = val; }else { -gpio_request_by_name_nodev (np,"rb-gpios" ,0 , - &nand->cs[i].rb.gpio, -GPIOD_IS_IN ); - nand->cs[i].rb.type =ATMEL_NAND_GPIO_RB ; + ret =gpio_request_by_name_nodev (np,"rb-gpios" ,0 , + &nand->cs[i].rb.gpio, +GPIOD_IS_IN ); +if (ret) +dev_err (nc->dev,"Failed to get R/B gpio (err = %d)\n" , ret); +else + nand->cs[i].rb.type =ATMEL_NAND_GPIO_RB ; } gpio_request_by_name_nodev(np, "cs-gpios", 0,
Signature · 1 line
2.30.2
Re: [PATCH 2/2] mtd: nand: raw: atmel: Add error handling when rb-gpios missing
Hi
Quoted 33 lines · Alexander Dahl
Adapt behaviour to Linux kernel driver.
The return value of
gpio_request_by_name_nodev()was not checked before, and thus in case 'rb-gpios' was missing in DT, rb.type was set toATMEL_NAND_GPIO_RBnevertheless, leading to output like this for example (on sam9x60-curiosity with the line removed from dts):NAND: Could not find valid ONFI parameter page; aborting device found, Manufacturer ID:
0xc2, Chip ID:0xdcMacronix NAND 512MiB 3,3V 8-bit
512 MiB, SLC, erase size: 256 KiB, page size: 4096, OOB size: 64 atmel-nand-controller nand-controller: NAND scan failed: -22 Failed to probe nand driver (err = -22)
Failed to initialize NAND controller. (error -22)
0 MiBNote: not having that gpio assigned in dts is fine, the driver does not override
nand_chip->dev_ready()then and a generic solution is used.Fixes 6a8dfd57220d ("nand: atmel: Add DM based NAND driver")Signed-off-by Alexander Dahl <[email protected]>--- drivers/mtd/nand/raw/atmel/nand-controller.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)drivers/mtd/nand/raw/atmel/nand-controller.c +0
-0@@ -1600,10 +1600,13 @@ static struct atmel_nand *atmel_nand_create(struct atmel_nand_controller *nc, nand->cs[i].rb.type =ATMEL_NAND_NATIVE_RB ; nand->cs[i].rb.id = val;
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand *atmel_nand_create(struct atmel_nand_controller *nc, · line 1607
Quoted 10 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +5
-4}else { -gpio_request_by_name_nodev (np,"rb-gpios" ,0 , - &nand->cs[i].rb.gpio, -GPIOD_IS_IN ); - nand->cs[i].rb.type =ATMEL_NAND_GPIO_RB ; + ret =gpio_request_by_name_nodev (np,"rb-gpios" ,0 , + &nand->cs[i].rb.gpio, +GPIOD_IS_IN ); +if (ret) +dev_err (nc->dev,"Failed to get R/B gpio (err = %d)\n" , ret);
Should not then an error here
Michael
Quoted 8 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +2
-1+else + nand->cs[i].rb.type =ATMEL_NAND_GPIO_RB ; } gpio_request_by_name_nodev(np, "cs-gpios", 0, --2.30.2
Signature · 11 lines
Michael Nazzareno Trimarchi Co-Founder & Chief Executive Officer M. +39 347 913 2170 [email protected] __________________________________ Amarula Solutions BV Joop Geesinkweg 125, 1114 AB, Amsterdam, NL T. +31 (0)85 111 9172 [email protected] www.amarulasolutions.com
Re: [PATCH 2/2] mtd: nand: raw: atmel: Add error handling when rb-gpios missing
Hello Michael,
Am Tue, Aug 08, 2023 at 03:49:45PM +0200 schrieb Michael Nazzareno Trimarchi:
Quoted 40 lines
Hi
Quoted 37 lines · Alexander Dahl
Adapt behaviour to Linux kernel driver.
The return value of
gpio_request_by_name_nodev()was not checked before, and thus in case 'rb-gpios' was missing in DT, rb.type was set toATMEL_NAND_GPIO_RBnevertheless, leading to output like this for example (on sam9x60-curiosity with the line removed from dts):NAND: Could not find valid ONFI parameter page; aborting device found, Manufacturer ID:
0xc2, Chip ID:0xdcMacronix NAND 512MiB 3,3V 8-bit
512 MiB, SLC, erase size: 256 KiB, page size: 4096, OOB size: 64 atmel-nand-controller nand-controller: NAND scan failed: -22 Failed to probe nand driver (err = -22)
Failed to initialize NAND controller. (error -22)
0 MiBNote: not having that gpio assigned in dts is fine, the driver does not override
nand_chip->dev_ready()then and a generic solution is used.Fixes 6a8dfd57220d ("nand: atmel: Add DM based NAND driver")Signed-off-by Alexander Dahl <[email protected]>--- drivers/mtd/nand/raw/atmel/nand-controller.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)drivers/mtd/nand/raw/atmel/nand-controller.c +0
-3@@ -1600,10 +1600,13 @@ static struct atmel_nand *atmel_nand_create(struct atmel_nand_controller *nc, nand->cs[i].rb.type =ATMEL_NAND_NATIVE_RB ; nand->cs[i].rb.id = val; }else { -gpio_request_by_name_nodev (np,"rb-gpios" ,0 , - &nand->cs[i].rb.gpio, -GPIOD_IS_IN );
Quoted 8 lines
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand *atmel_nand_create(struct atmel_nand_controller *nc, · line 1607
Quoted 6 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +5
-1- nand->cs[i].rb.type =ATMEL_NAND_GPIO_RB ; + ret =gpio_request_by_name_nodev (np,"rb-gpios" ,0 , + &nand->cs[i].rb.gpio, +GPIOD_IS_IN ); +if (ret) +dev_err (nc->dev,"Failed to get R/B gpio (err = %d)\n" , ret);Should not then an error here
Different log level or no message at all?
Note: Linux prints the same message with error level in that case.
Greets
Alex
Quoted 25 lines
Michael
Quoted 8 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +2
-1+else + nand->cs[i].rb.type =ATMEL_NAND_GPIO_RB ; } gpio_request_by_name_nodev(np, "cs-gpios", 0, --2.30.2
Signature · 11 lines
Michael Nazzareno Trimarchi Co-Founder & Chief Executive Officer M. +39 347 913 2170 [email protected] __________________________________ Amarula Solutions BV Joop Geesinkweg 125, 1114 AB, Amsterdam, NL T. +31 (0)85 111 9172 [email protected] www.amarulasolutions.com
Re: [PATCH 2/2] mtd: nand: raw: atmel: Add error handling when rb-gpios missing
Hi,
Quoted 52 lines · Alexander Dahl
Hello Michael,
Am Tue, Aug 08, 2023 at 03:49:45PM +0200 schrieb Michael Nazzareno Trimarchi:
Quoted 40 lines
Hi
Quoted 37 lines · Alexander Dahl
Adapt behaviour to Linux kernel driver.
The return value of
gpio_request_by_name_nodev()was not checked before, and thus in case 'rb-gpios' was missing in DT, rb.type was set toATMEL_NAND_GPIO_RBnevertheless, leading to output like this for example (on sam9x60-curiosity with the line removed from dts):NAND: Could not find valid ONFI parameter page; aborting device found, Manufacturer ID:
0xc2, Chip ID:0xdcMacronix NAND 512MiB 3,3V 8-bit
512 MiB, SLC, erase size: 256 KiB, page size: 4096, OOB size: 64 atmel-nand-controller nand-controller: NAND scan failed: -22 Failed to probe nand driver (err = -22)
Failed to initialize NAND controller. (error -22)
0 MiBNote: not having that gpio assigned in dts is fine, the driver does not override
nand_chip->dev_ready()then and a generic solution is used.Fixes 6a8dfd57220d ("nand: atmel: Add DM based NAND driver")Signed-off-by Alexander Dahl <[email protected]>--- drivers/mtd/nand/raw/atmel/nand-controller.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)drivers/mtd/nand/raw/atmel/nand-controller.c +0
-3@@ -1600,10 +1600,13 @@ static struct atmel_nand *atmel_nand_create(struct atmel_nand_controller *nc, nand->cs[i].rb.type =ATMEL_NAND_NATIVE_RB ; nand->cs[i].rb.id = val; }else { -gpio_request_by_name_nodev (np,"rb-gpios" ,0 , - &nand->cs[i].rb.gpio, -GPIOD_IS_IN );Quoted 8 lines
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand *atmel_nand_create(struct atmel_nand_controller *nc, · line 1607
Quoted 6 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +5
-1- nand->cs[i].rb.type =ATMEL_NAND_GPIO_RB ; + ret =gpio_request_by_name_nodev (np,"rb-gpios" ,0 , + &nand->cs[i].rb.gpio, +GPIOD_IS_IN ); +if (ret) +dev_err (nc->dev,"Failed to get R/B gpio (err = %d)\n" , ret);Should not then an error here
Quoted 7 lines
Different log level or no message at all?
Note: Linux prints the same message with error level in that case.
Greets
Alex
Since the rb-gpios is optional, we can continue probing without it. Throwing an error message is optional and pure informative. So I am fine with it
What I wanted to ask is what happens with nand->cs[i].rb.type , is it 0 by default ?
Other than that, I can apply this patch, Michael, do you have any more comments on it ?
Thanks,
Eugen
Quoted 25 lines
Quoted 25 lines
Michael
Quoted 8 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +2
-1+else + nand->cs[i].rb.type =ATMEL_NAND_GPIO_RB ; } gpio_request_by_name_nodev(np, "cs-gpios", 0, --2.30.2
Signature · 11 lines
Michael Nazzareno Trimarchi Co-Founder & Chief Executive Officer M. +39 347 913 2170 [email protected] __________________________________ Amarula Solutions BV Joop Geesinkweg 125, 1114 AB, Amsterdam, NL T. +31 (0)85 111 9172 [email protected] www.amarulasolutions.com
Re: [PATCH 2/2] mtd: nand: raw: atmel: Add error handling when rb-gpios missing
Hi
Quoted 60 lines · Eugen Hristev
Hi,
Quoted 56 lines · Alexander Dahl
Hello Michael,
Am Tue, Aug 08, 2023 at 03:49:45PM +0200 schrieb Michael Nazzareno Trimarchi:
Quoted 40 lines
Hi
Quoted 37 lines · Alexander Dahl
Adapt behaviour to Linux kernel driver.
The return value of
gpio_request_by_name_nodev()was not checked before, and thus in case 'rb-gpios' was missing in DT, rb.type was set toATMEL_NAND_GPIO_RBnevertheless, leading to output like this for example (on sam9x60-curiosity with the line removed from dts):NAND: Could not find valid ONFI parameter page; aborting device found, Manufacturer ID:
0xc2, Chip ID:0xdcMacronix NAND 512MiB 3,3V 8-bit
512 MiB, SLC, erase size: 256 KiB, page size: 4096, OOB size: 64 atmel-nand-controller nand-controller: NAND scan failed: -22 Failed to probe nand driver (err = -22)
Failed to initialize NAND controller. (error -22)
0 MiBNote: not having that gpio assigned in dts is fine, the driver does not override
nand_chip->dev_ready()then and a generic solution is used.Fixes 6a8dfd57220d ("nand: atmel: Add DM based NAND driver")Signed-off-by Alexander Dahl <[email protected]>--- drivers/mtd/nand/raw/atmel/nand-controller.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)drivers/mtd/nand/raw/atmel/nand-controller.c +0
-3@@ -1600,10 +1600,13 @@ static struct atmel_nand *atmel_nand_create(struct atmel_nand_controller *nc, nand->cs[i].rb.type =ATMEL_NAND_NATIVE_RB ; nand->cs[i].rb.id = val; }else { -gpio_request_by_name_nodev (np,"rb-gpios" ,0 , - &nand->cs[i].rb.gpio, -GPIOD_IS_IN );Quoted 8 lines
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand *atmel_nand_create(struct atmel_nand_controller *nc, · line 1607
Quoted 6 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +5
-1- nand->cs[i].rb.type =ATMEL_NAND_GPIO_RB ; + ret =gpio_request_by_name_nodev (np,"rb-gpios" ,0 , + &nand->cs[i].rb.gpio, +GPIOD_IS_IN ); +if (ret) +dev_err (nc->dev,"Failed to get R/B gpio (err = %d)\n" , ret);Should not then an error here
Different log level or no message at all?
Note: Linux prints the same message with error level in that case.
Quoted 8 lines
Quoted 3 lines
Greets
AlexSince the rb-gpios is optional, we can continue probing without it. Throwing an error message is optional and pure informative. So I am fine with it
Yes ok, but I'm not sure linux give an error if the gpio is get as optional and condition
is IS_ERR. Am I right?
For the rest is fine
Michael
Quoted 34 lines
What I wanted to ask is what happens with nand->cs[i].rb.type , is it 0 by default ?
Other than that, I can apply this patch, Michael, do you have any more comments on it ?
Thanks,
EugenQuoted 25 lines
Quoted 25 lines
Michael
Quoted 8 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +2
-1+else + nand->cs[i].rb.type =ATMEL_NAND_GPIO_RB ; } gpio_request_by_name_nodev(np, "cs-gpios", 0, --2.30.2
--
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
Signature · 11 lines
Michael Nazzareno Trimarchi Co-Founder & Chief Executive Officer M. +39 347 913 2170 [email protected] __________________________________ Amarula Solutions BV Joop Geesinkweg 125, 1114 AB, Amsterdam, NL T. +31 (0)85 111 9172 [email protected] www.amarulasolutions.com
Re: [PATCH 2/2] mtd: nand: raw: atmel: Add error handling when rb-gpios missing
Quoted 68 lines · Michael Nazzareno Trimarchi
Hi
Quoted 64 lines · Eugen Hristev
Hi,
Quoted 59 lines · Alexander Dahl
Hello Michael,
Am Tue, Aug 08, 2023 at 03:49:45PM +0200 schrieb Michael Nazzareno Trimarchi:
Quoted 40 lines
Hi
Quoted 37 lines · Alexander Dahl
Adapt behaviour to Linux kernel driver.
The return value of
gpio_request_by_name_nodev()was not checked before, and thus in case 'rb-gpios' was missing in DT, rb.type was set toATMEL_NAND_GPIO_RBnevertheless, leading to output like this for example (on sam9x60-curiosity with the line removed from dts):NAND: Could not find valid ONFI parameter page; aborting device found, Manufacturer ID:
0xc2, Chip ID:0xdcMacronix NAND 512MiB 3,3V 8-bit
512 MiB, SLC, erase size: 256 KiB, page size: 4096, OOB size: 64 atmel-nand-controller nand-controller: NAND scan failed: -22 Failed to probe nand driver (err = -22)
Failed to initialize NAND controller. (error -22)
0 MiBNote: not having that gpio assigned in dts is fine, the driver does not override
nand_chip->dev_ready()then and a generic solution is used.Fixes 6a8dfd57220d ("nand: atmel: Add DM based NAND driver")Signed-off-by Alexander Dahl <[email protected]>--- drivers/mtd/nand/raw/atmel/nand-controller.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)drivers/mtd/nand/raw/atmel/nand-controller.c +0
-3@@ -1600,10 +1600,13 @@ static struct atmel_nand *atmel_nand_create(struct atmel_nand_controller *nc, nand->cs[i].rb.type =ATMEL_NAND_NATIVE_RB ; nand->cs[i].rb.id = val; }else { -gpio_request_by_name_nodev (np,"rb-gpios" ,0 , - &nand->cs[i].rb.gpio, -GPIOD_IS_IN );Quoted 8 lines
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand *atmel_nand_create(struct atmel_nand_controller *nc, · line 1607
Quoted 6 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +5
-1- nand->cs[i].rb.type =ATMEL_NAND_GPIO_RB ; + ret =gpio_request_by_name_nodev (np,"rb-gpios" ,0 , + &nand->cs[i].rb.gpio, +GPIOD_IS_IN ); +if (ret) +dev_err (nc->dev,"Failed to get R/B gpio (err = %d)\n" , ret);Should not then an error here
Different log level or no message at all?
Note: Linux prints the same message with error level in that case.
Greets
Alex
Quoted 8 lines
Quoted 4 lines
Since the rb-gpios is optional, we can continue probing without it. Throwing an error message is optional and pure informative. So I am fine with it
Yes ok, but I'm not sure linux give an error if the gpio is get as optional and condition
isIS_ERR. Am I right?
if (IS_ERR(gpio) && PTR_ERR(gpio) != -ENOENT) {
dev_err(nc->dev,
"Failed to get R/B gpio (err = %ld)\n",
PTR_ERR(gpio));
return ERR_CAST(gpio);
}So Linux throws the message if IS_ERR . If the property is missing (ENOENT) it moves on.
Can we replicate the same behavior or this behavior does not suit us in U-boot ?
Basically I think it should be :
if (ret && ret != -ENOENT) dev_err(...) if (!ret) rb.type = ATMEL_NAND_GPIO_RB;
Is this what you had in mind Michael ?
Eugen
Quoted 41 lines
For the rest is fine
Michael
Quoted 34 lines
What I wanted to ask is what happens with nand->cs[i].rb.type , is it 0 by default ?
Other than that, I can apply this patch, Michael, do you have any more comments on it ?
Thanks,
EugenQuoted 25 lines
Quoted 25 lines
Michael
Quoted 8 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +2
-1+else + nand->cs[i].rb.type =ATMEL_NAND_GPIO_RB ; } gpio_request_by_name_nodev(np, "cs-gpios", 0, --2.30.2
--
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
Re: [PATCH 2/2] mtd: nand: raw: atmel: Add error handling when rb-gpios missing
Hello Eugen, hello Michael,
Am Wed, Aug 23, 2023 at 01:59:58PM +0300 schrieb Eugen Hristev:
Quoted 92 lines · Michael Nazzareno Trimarchi
Quoted 68 lines
Hi
Quoted 64 lines · Eugen Hristev
Hi,
Quoted 59 lines · Alexander Dahl
Hello Michael,
Am Tue, Aug 08, 2023 at 03:49:45PM +0200 schrieb Michael Nazzareno Trimarchi:
Quoted 40 lines
Hi
Quoted 37 lines · Alexander Dahl
Adapt behaviour to Linux kernel driver.
The return value of
gpio_request_by_name_nodev()was not checked before, and thus in case 'rb-gpios' was missing in DT, rb.type was set toATMEL_NAND_GPIO_RBnevertheless, leading to output like this for example (on sam9x60-curiosity with the line removed from dts):NAND: Could not find valid ONFI parameter page; aborting device found, Manufacturer ID:
0xc2, Chip ID:0xdcMacronix NAND 512MiB 3,3V 8-bit
512 MiB, SLC, erase size: 256 KiB, page size: 4096, OOB size: 64 atmel-nand-controller nand-controller: NAND scan failed: -22 Failed to probe nand driver (err = -22)
Failed to initialize NAND controller. (error -22)
0 MiBNote: not having that gpio assigned in dts is fine, the driver does not override
nand_chip->dev_ready()then and a generic solution is used.Fixes 6a8dfd57220d ("nand: atmel: Add DM based NAND driver")Signed-off-by Alexander Dahl <[email protected]>--- drivers/mtd/nand/raw/atmel/nand-controller.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)drivers/mtd/nand/raw/atmel/nand-controller.c +0
-3@@ -1600,10 +1600,13 @@ static struct atmel_nand *atmel_nand_create(struct atmel_nand_controller *nc, nand->cs[i].rb.type =ATMEL_NAND_NATIVE_RB ; nand->cs[i].rb.id = val; }else { -gpio_request_by_name_nodev (np,"rb-gpios" ,0 , - &nand->cs[i].rb.gpio, -GPIOD_IS_IN );Quoted 8 lines
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand *atmel_nand_create(struct atmel_nand_controller *nc, · line 1607
Quoted 6 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +5
-1- nand->cs[i].rb.type =ATMEL_NAND_GPIO_RB ; + ret =gpio_request_by_name_nodev (np,"rb-gpios" ,0 , + &nand->cs[i].rb.gpio, +GPIOD_IS_IN ); +if (ret) +dev_err (nc->dev,"Failed to get R/B gpio (err = %d)\n" , ret);Should not then an error here
Different log level or no message at all?
Note: Linux prints the same message with error level in that case.
Greets
AlexQuoted 8 lines
Quoted 4 lines
Since the rb-gpios is optional, we can continue probing without it. Throwing an error message is optional and pure informative. So I am fine with it
Yes ok, but I'm not sure linux give an error if the gpio is get as optional and condition
isIS_ERR. Am I right?if (IS_ERR(gpio) && PTR_ERR(gpio) != -ENOENT) { dev_err(nc->dev, "Failed to get R/B gpio (err = %ld)\n", PTR_ERR(gpio)); return ERR_CAST(gpio); }So Linux throws the message if
IS_ERR. If the property is missing (ENOENT) it moves on.Can we replicate the same behavior or this behavior does not suit us in U-boot ?
Quoted 8 lines
Basically I think it should be :
if (ret && ret != -ENOENT) dev_err(...) if (!ret) rb.type = ATMEL_NAND_GPIO_RB;Is this what you had in mind Michael ?
The discussion between you guys somehow got stuck. I still have this patch on my TODO list, but I'm not sure how to proceed. Please advice in which direction to go forward, there's still an error condition (described in the initial commit message) here, which needs to be handled, otherwise the NAND flash might not be usable.
Greets
Alex
Quoted 45 lines
Eugen
Quoted 41 lines
For the rest is fine
Michael
Quoted 34 lines
What I wanted to ask is what happens with nand->cs[i].rb.type , is it 0 by default ?
Other than that, I can apply this patch, Michael, do you have any more comments on it ?
Thanks,
EugenQuoted 25 lines
Quoted 25 lines
Michael
Quoted 8 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +2
-1+else + nand->cs[i].rb.type =ATMEL_NAND_GPIO_RB ; } gpio_request_by_name_nodev(np, "cs-gpios", 0, --2.30.2
--
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
Re: [PATCH 2/2] mtd: nand: raw: atmel: Add error handling when rb-gpios missing
Hi
Il mer 20 set 2023, 08:13 Alexander Dahl <[email protected]> ha scritto:
Quoted 126 lines
Hello Eugen, hello Michael,
Am Wed, Aug 23, 2023 at 01:59:58PM +0300 schrieb Eugen Hristev:
Quoted 6 lines · Michael Nazzareno Trimarchi
Quoted 5 lines
Hi
Quoted 1 line · Eugen Hristev
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Hi,
Quoted 3 lines · Alexander Dahl
Hello Michael,
Am Tue, Aug 08, 2023 at 03:49:45PM +0200 schrieb Michael Nazzareno
Trimarchi:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Hi
On Tue, Aug 8, 2023 at 3:03 PM Alexander Dahl <[email protected]>
Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Adapt behaviour to Linux kernel driver.
The return value of
gpio_request_by_name_nodev()was notchecked before,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
and thus in case 'rb-gpios' was missing in DT, rb.type was set
to
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
ATMEL_NAND_GPIO_RBnevertheless, leading to output like thisfor
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
example (on sam9x60-curiosity with the line removed from dts):
NAND: Could not find valid ONFI parameter page; aborting device found, Manufacturer ID: 0xc2, Chip ID: 0xdc Macronix NAND 512MiB 3,3V 8-bit 512 MiB, SLC, erase size: 256 KiB, page size: 4096, OOBsize: 64
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
atmel-nand-controller nand-controller: NAND scan failed:
-22
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Failed to probe nand driver (err = -22) Failed to initialize NAND controller. (error -22) 0 MiB
Note: not having that gpio assigned in dts is fine, the driver
does not
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
override
nand_chip->dev_ready()then and a generic solution isused.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Fixes 6a8dfd57220d ("nand: atmel: Add DM based NAND driver")Signed-off-by Alexander Dahl <[email protected]>--- drivers/mtd/nand/raw/atmel/nand-controller.c | 11+++++++----
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Review
Quoted 3 lines
1 file changed, 7 insertions(+), 4 deletions(-)(quoted diff) +0
-0
b/drivers/mtd/nand/raw/atmel/nand-controller.cQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand
Quoted 4 lines
index
2b29c8def6..8e745a5111100644drivers/mtd/nand/raw/atmel/nand-controller.c +0
-0@@ -1600,10 +1600,13 @@ static struct atmel_nand*atmel_nand_create(struct
atmel_nand_controller*nc,Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand · line 1600
Quoted 1 line
drivers/mtd/nand/raw/atmel/nand-controller.c +0
-0nand->cs[i].rb.type =
ATMEL_NAND_NATIVE_RB;Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand · line 1603
Quoted 3 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +0
-1nand->cs[i].rb.id = val; }else { - gpio_request_by_name_nodev(np,"rb-gpios", 0,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand · line 1604
Quoted 1 line
drivers/mtd/nand/raw/atmel/nand-controller.c +0
-1-&nand->cs[i].rb.gpio,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand · line 1605
Quoted 1 line
drivers/mtd/nand/raw/atmel/nand-controller.c +0
-1-
GPIOD_IS_IN);Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand · line 1606
Quoted 1 line
drivers/mtd/nand/raw/atmel/nand-controller.c +0
-1- nand->cs[i].rb.type =
ATMEL_NAND_GPIO_RB;Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand · line 1603
Quoted 1 line
drivers/mtd/nand/raw/atmel/nand-controller.c +1
-0+ ret = gpio_request_by_name_nodev(np,"rb-gpios", 0,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand · line 1604
Quoted 1 line
drivers/mtd/nand/raw/atmel/nand-controller.c +1
-0+&nand->cs[i].rb.gpio,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand · line 1605
Quoted 1 line
drivers/mtd/nand/raw/atmel/nand-controller.c +1
-0+
GPIOD_IS_IN);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/mtd/nand/raw/atmel/nand-controller.c static struct atmel_nand · line 1607
Quoted 2 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +2
-0+if (ret) + dev_err(nc->dev, "Failed toget R/B gpio (err = %d)\n", ret);
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Should not then an error here
Different log level or no message at all?
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Note: Linux prints the same message with error level in that case.
Greets
AlexSince the rb-gpios is optional, we can continue probing without it. Throwing an error message is optional and pure informative. So I am
fine
Quoted 11 lines
Quoted 6 lines
Quoted 2 lines
with it
Yes ok, but I'm not sure linux give an error if the gpio is get as optional and condition
isIS_ERR. Am I right?if (IS_ERR(gpio) && PTR_ERR(gpio) != -ENOENT) { dev_err(nc->dev, "Failed to get R/B gpio (err =%ld)\n",
Quoted 5 lines
PTR_ERR(gpio)); return ERR_CAST(gpio); }So Linux throws the message if
IS_ERR. If the property is missing(ENOENT)
Quoted 12 lines
it moves on.
Can we replicate the same behavior or this behavior does not suit us in U-boot ?
Basically I think it should be :
if (ret && ret != -ENOENT) dev_err(...) if (!ret) rb.type = ATMEL_NAND_GPIO_RB;
Quoted 7 lines
Quoted 1 line
Is this what you had in mind Michael ?
The discussion between you guys somehow got stuck. I still have this patch on my TODO list, but I'm not sure how to proceed. Please advice in which direction to go forward, there's still an error condition (described in the initial commit message) here, which needs to be handled, otherwise the NAND flash might not be usable.
Yes the suggestion above is what is the right path to follow.
Michael
Quoted 53 lines
Greets
AlexQuoted 9 lines
Eugen
Quoted 6 lines
For the rest is fine
Michael
Quoted 1 line
What I wanted to ask is what happens with nand->cs[i].rb.type , is
it 0
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
by default ?
Other than that, I can apply this patch, Michael, do you have any
more
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
comments on it ?
Thanks,
EugenQuoted 5 lines
Quoted 5 lines
Michael
Quoted 2 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +2
-0+else + nand->cs[i].rb.type =
ATMEL_NAND_GPIO_RB;Quoted 24 lines
Quoted 23 lines
Quoted 21 lines
Quoted 20 lines
Quoted 20 lines
Quoted 6 lines
drivers/mtd/nand/raw/atmel/nand-controller.c +0
-1} gpio_request_by_name_nodev(np, "cs-gpios", 0, --2.30.2
--
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
Added Mihai who tested this a lot at some point in time
Eugen
Quoted 65 lines · Alexander Dahl
Hello everyone,
this is a patch series wtih some real fixes _and_ a question or some kind of support request in the cover letter. I would be happy if anyone could read the cover letter carefully and answer to that one what might be the problem I see. O:-)
I'm currently working on the sam9x60-curiosity board and especially trying to get it booting from onboard raw NAND flash. As reported in my last series I got the flash recognized already. However interacting with it was terribly slow, because
nand_wait_ready()callingatmel_nand_dev_ready()ran into a 400ms timeout in several occasions, especially when reading from the device. Reading a single block triggered that timeout two times per page, which summed up to over 50 seconds for 64 × 4096 = 256k Bytes!(You can have U-Boot print that warning from
nand_wait_ready()by increasing the console log level to at least "warn".)Note: the dts from atmel/next seems correct to me, I double checked that again. My own debug log messages showed the GPIO is accessed, and if you add enough debug messages sometimes the timeout is not reached, so I'm sure the NAND chip eventually switches that R/B line and the code correctly sees that, that line level change however takes ages, something between 400ms and 500ms most of the times.
I vaguely remembered on SAMA5D2 the old atmel raw nand driver is used which does not support reading the R/B signal, but nevertheless works. I'm not familiar in detail with those raw NAND flash chips, but as far as I can understand, there are other ways to determine if the chip is ready or busy. So after I removed that rb-gpio parameter from '
at91-sam9x60_curiosity.dts' I ran into the bug fixed by patch 2.With that patch applied _and_ rb-gpio still removed from dts, raw NAND access is reasonably fast on sam9x60-curiosity board. (You might want to rebase to atmel/next for testing this.) Not sure if I should send a patch for that dts change, because I suppose it's a workaround only and not addressing the actual cause?
I think the fix is correct in itself, I tested different combinations and compared with the driver in Linux, however …
Can anyone explain to me, why flash access is sooo slow if the R/B gpio is used? Especially in comparision to Linux, where I don't need to remove that thing from dts and it works reasonably fast?
The actual flash chip is a Macronix MX30LF4G28AD, 512 MiB, SLC, erase
size: 256 KiB, page size: 4096, OOB size: 256.Greets
Alex
P.S.: although not returned by get_maintainer.pl I added Eugen to Cc because he is maintainer of the at91 and might have some insight if it is a general problem of the nand controller in at91 socs?Alexander Dahl (2):
mtd: nand: raw: atmel: Remove duplicate line
mtd: nand: raw: atmel: Add error handling when rb-gpios missingdrivers/mtd/nand/raw/atmel/nand-controller.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)base-commit:
a169438411f9277cc689c14078151aa1d1caae3c
Hi Alex,
Please find bellow my answer:
------------------------------
Added Mihai who tested this a lot at some point in time
Eugen
Quoted 40 lines · Alexander Dahl
Hello everyone,
this is a patch series wtih some real fixes _and_ a question or some kind of support request in the cover letter. I would be happy if anyone could read the cover letter carefully and answer to that one what might be the problem I see. O:-)
I'm currently working on the sam9x60-curiosity board and especially trying to get it booting from onboard raw NAND flash. As reported in my last series I got the flash recognized already. However interacting with it was terribly slow, because
nand_wait_ready()callingatmel_nand_dev_ready()ran into a 400ms timeout in several occasions, especially when reading from the device. Reading a single block triggered that timeout two times per page, which summed up to over 50 seconds for 64 × 4096 = 256k Bytes!(You can have U-Boot print that warning from
nand_wait_ready()by increasing the console log level to at least "warn".)Note: the dts from atmel/next seems correct to me, I double checked that again. My own debug log messages showed the GPIO is accessed, and if you add enough debug messages sometimes the timeout is not reached, so I'm sure the NAND chip eventually switches that R/B line and the code correctly sees that, that line level change however takes ages, something between 400ms and 500ms most of the times.
I vaguely remembered on SAMA5D2 the old atmel raw nand driver is used which does not support reading the R/B signal, but nevertheless works. I'm not familiar in detail with those raw NAND flash chips, but as far as I can understand, there are other ways to determine if the chip is ready or busy. So after I removed that rb-gpio parameter from '
at91-sam9x60_curiosity.dts' I ran into the bug fixed by patch 2.With that patch applied _and_ rb-gpio still removed from dts, raw NAND access is reasonably fast on sam9x60-curiosity board. (You might want to rebase to atmel/next for testing this.) Not sure if I should send a patch for that dts change, because I suppose it's a workaround only and not addressing the actual cause?
Quoted 6 lines
I think the fix is correct in itself, I tested different combinations and compared with the driver in Linux, however …
Can anyone explain to me, why flash access is sooo slow if the R/B gpio is used? Especially in comparision to Linux, where I don't need to remove that thing from dts and it works reasonably fast?
// I'm sorry for quoting (email is sent from Outlook) # Please add in your board dts: atmel,rb = <0> # nand@3 {
# reg = <0x3 0x0 0x800000>;
# atmel,rb = <0>;
# cs-gpios = <&pioD 4 GPIO_ACTIVE_HIGH>;
# rb-gpios = <&pioD 5 GPIO_ACTIVE_HIGH>;
# nand-bus-width = <8>;
# nand-ecc-mode = "hw";
# nand-ecc-strength = <8>;
# nand-ecc-step-size = <512>;
# nand-on-flash-bbt;>
Quoted 19 lines
The actual flash chip is a Macronix MX30LF4G28AD, 512 MiB, SLC, erase
size: 256 KiB, page size: 4096, OOB size: 256.Greets
Alex
P.S.: although not returned by get_maintainer.pl I added Eugen to Cc because he is maintainer of the at91 and might have some insight if it is a general problem of the nand controller in at91 socs?Alexander Dahl (2):
mtd: nand: raw: atmel: Remove duplicate line
mtd: nand: raw: atmel: Add error handling when rb-gpios missingdrivers/mtd/nand/raw/atmel/nand-controller.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)base-commit:
a169438411f9277cc689c14078151aa1d1caae3c
Hello Mihai,
Am Tue, Aug 08, 2023 at 01:40:26PM +0000 schrieb [email protected]:
Quoted 4 lines
Hi Alex,
Please find bellow my answer:
Quoted 40 lines
------------------------------
Added Mihai who tested this a lot at some point in time
Eugen
Quoted 33 lines · Alexander Dahl
Hello everyone,
this is a patch series wtih some real fixes _and_ a question or some kind of support request in the cover letter. I would be happy if anyone could read the cover letter carefully and answer to that one what might be the problem I see. O:-)
I'm currently working on the sam9x60-curiosity board and especially trying to get it booting from onboard raw NAND flash. As reported in my last series I got the flash recognized already. However interacting with it was terribly slow, because
nand_wait_ready()callingatmel_nand_dev_ready()ran into a 400ms timeout in several occasions, especially when reading from the device. Reading a single block triggered that timeout two times per page, which summed up to over 50 seconds for 64 × 4096 = 256k Bytes!(You can have U-Boot print that warning from
nand_wait_ready()by increasing the console log level to at least "warn".)Note: the dts from atmel/next seems correct to me, I double checked that again. My own debug log messages showed the GPIO is accessed, and if you add enough debug messages sometimes the timeout is not reached, so I'm sure the NAND chip eventually switches that R/B line and the code correctly sees that, that line level change however takes ages, something between 400ms and 500ms most of the times.
I vaguely remembered on SAMA5D2 the old atmel raw nand driver is used which does not support reading the R/B signal, but nevertheless works. I'm not familiar in detail with those raw NAND flash chips, but as far as I can understand, there are other ways to determine if the chip is ready or busy. So after I removed that rb-gpio parameter from '
at91-sam9x60_curiosity.dts' I ran into the bug fixed by patch 2.
Maybe I should add: currently there are two different drivers for atmel raw nand controllers in U-Boot, the old non-DM driver used by sam9g20 or sama5 based boards for example and a new driver used by sam9x60 based boards. We are talking about sam9x60 and the new driver in 'drivers/mtd/nand/raw/atmel/nand-controller.c' here.
Quoted 10 lines
Quoted 10 lines
With that patch applied _and_ rb-gpio still removed from dts, raw NAND access is reasonably fast on sam9x60-curiosity board. (You might want to rebase to atmel/next for testing this.) Not sure if I should send a patch for that dts change, because I suppose it's a workaround only and not addressing the actual cause?
I think the fix is correct in itself, I tested different combinations and compared with the driver in Linux, however …
Quoted 6 lines
Quoted 3 lines
Can anyone explain to me, why flash access is sooo slow if the R/B gpio is used? Especially in comparision to Linux, where I don't need to remove that thing from dts and it works reasonably fast?
// I'm sorry for quoting (email is sent from Outlook) # Please add in your board dts: atmel,rb = <0>
Although the new U-Boot driver tests for that, it is not documented in U-Boot devicetree bindings. According to Linux kernel (v6.4) device tree binding documentation it is only meaningful for sama5. Those binding documentation was added to Linux back in 2019 by Boris Brezillon. And that line is not present in the dts file for sam9x60-curiosity in Linux, so access is fast on Linux without that line (this is the part I don't understand yet).
From what I saw in datasheets sam9x60 and sama5d2 have different controllers (named 'SMC' and 'HSMC') and the U-Boot driver reflects that. That's why I did not add 'atmel,rb' to dts before, I though SMC is the older one which does not support native R/B line handling? (And because I took it from U-Boot sam9x60ek.dts which also does not have it.)
Nevertheless, I tried to add it now in U-Boot as you suggested (although without adapting pinctrl), and to my suprise it works … o.O
Trying the same in Linux leads to not finding a NAND device and thus failing of the atmel-nand-controller driver probe.
(Note: all this while booting from SD card, so at91bootstrap should not interfere, because it does not touch nand.)
What I did not test yet:
- How it behaves in U-Boot when also adapting pinctrl
- How other combinations of adaptions to dts behave in Linux
Sending this mail now anyway, it's too long already and office time is up for today. Will do more systematic tests tomorrow. Any more insights welcome.
Greets
Alex
Quoted 31 lines
# nand@3 {
# reg = <0x30x00x800000>;
# atmel,rb = <0>;
# cs-gpios = <&pioD 4GPIO_ACTIVE_HIGH>;
# rb-gpios = <&pioD 5GPIO_ACTIVE_HIGH>;
# nand-bus-width = <8>;
# nand-ecc-mode = "hw";
# nand-ecc-strength = <8>;
# nand-ecc-step-size = <512>;
# nand-on-flash-bbt;>Quoted 19 lines
The actual flash chip is a Macronix MX30LF4G28AD, 512 MiB, SLC, erase
size: 256 KiB, page size: 4096, OOB size: 256.Greets
Alex
P.S.: although not returned by get_maintainer.pl I added Eugen to Cc because he is maintainer of the at91 and might have some insight if it is a general problem of the nand controller in at91 socs?Alexander Dahl (2):
mtd: nand: raw: atmel: Remove duplicate line
mtd: nand: raw: atmel: Add error handling when rb-gpios missingdrivers/mtd/nand/raw/atmel/nand-controller.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)base-commit:
a169438411f9277cc689c14078151aa1d1caae3c
Hello everyone,
I had a closer look into the SAMA5D2 Series Datasheet and the SAM9X60 Data Sheet again. See below.
Am Tue, Aug 08, 2023 at 05:00:48PM +0200 schrieb Alexander Dahl:
Quoted 48 lines
Hello Mihai,
Am Tue, Aug 08, 2023 at 01:40:26PM +0000 schrieb [email protected]:
Quoted 4 lines
Hi Alex,
Please find bellow my answer:
Quoted 40 lines
------------------------------
Added Mihai who tested this a lot at some point in time
Eugen
Quoted 33 lines · Alexander Dahl
Hello everyone,
this is a patch series wtih some real fixes _and_ a question or some kind of support request in the cover letter. I would be happy if anyone could read the cover letter carefully and answer to that one what might be the problem I see. O:-)
I'm currently working on the sam9x60-curiosity board and especially trying to get it booting from onboard raw NAND flash. As reported in my last series I got the flash recognized already. However interacting with it was terribly slow, because
nand_wait_ready()callingatmel_nand_dev_ready()ran into a 400ms timeout in several occasions, especially when reading from the device. Reading a single block triggered that timeout two times per page, which summed up to over 50 seconds for 64 × 4096 = 256k Bytes!(You can have U-Boot print that warning from
nand_wait_ready()by increasing the console log level to at least "warn".)Note: the dts from atmel/next seems correct to me, I double checked that again. My own debug log messages showed the GPIO is accessed, and if you add enough debug messages sometimes the timeout is not reached, so I'm sure the NAND chip eventually switches that R/B line and the code correctly sees that, that line level change however takes ages, something between 400ms and 500ms most of the times.
I vaguely remembered on SAMA5D2 the old atmel raw nand driver is used which does not support reading the R/B signal, but nevertheless works. I'm not familiar in detail with those raw NAND flash chips, but as far as I can understand, there are other ways to determine if the chip is ready or busy. So after I removed that rb-gpio parameter from '
at91-sam9x60_curiosity.dts' I ran into the bug fixed by patch 2.
Quoted 5 lines
Maybe I should add: currently there are two different drivers for atmel raw nand controllers in U-Boot, the old non-DM driver used by sam9g20 or sama5 based boards for example and a new driver used by sam9x60 based boards. We are talking about sam9x60 and the new driver in '
drivers/mtd/nand/raw/atmel/nand-controller.c' here.
The old one is enabled by CONFIG_NAND_ATMEL, the new one by CONFIG_DM_NAND_ATMEL instead.
Quoted 31 lines
Quoted 9 lines
Quoted 9 lines
With that patch applied _and_ rb-gpio still removed from dts, raw NAND access is reasonably fast on sam9x60-curiosity board. (You might want to rebase to atmel/next for testing this.) Not sure if I should send a patch for that dts change, because I suppose it's a workaround only and not addressing the actual cause?
I think the fix is correct in itself, I tested different combinations and compared with the driver in Linux, however …
Quoted 6 lines
Quoted 3 lines
Can anyone explain to me, why flash access is sooo slow if the R/B gpio is used? Especially in comparision to Linux, where I don't need to remove that thing from dts and it works reasonably fast?
// I'm sorry for quoting (email is sent from Outlook) # Please add in your board dts: atmel,rb = <0>
Although the new U-Boot driver tests for that, it is not documented in U-Boot devicetree bindings. According to Linux kernel (v6.4) device tree binding documentation it is only meaningful for sama5. Those binding documentation was added to Linux back in 2019 by Boris Brezillon. And that line is not present in the dts file for sam9x60-curiosity in Linux, so access is fast on Linux without that line (this is the part I don't understand yet).
From what I saw in datasheets sam9x60 and sama5d2 have different controllers (named 'SMC' and 'HSMC') and the U-Boot driver reflects that. That's why I did not add 'atmel,rb' to dts before, I though SMC is the older one which does not support native R/B line handling? (And because I took it from U-Boot
sam9x60ek.dtswhich also does not have it.)
Quoted 5 lines
Nevertheless, I tried to add it now in U-Boot as you suggested (although without adapting pinctrl), and to my suprise it works … o.O
Trying the same in Linux leads to not finding a NAND device and thus failing of the atmel-nand-controller driver probe.
From datasheet POV this all makes sense. The HSMC on SAMA5D2 has a native NANDRDY signal/peripheral function to handle the R/B pin of the flash and can do the low level communication by itself with an embedded Nand Flash Controller (NFC). The SMC on SAM9X60 has no such thing and the datasheet explicitly recommends to connect the R/B pin to _any_ GPIO.
The new dm-based nand-controller driver in U-Boot only checks if dts has the 'rb-gpios' property and only then overrides the chip->dev_ready function. So for U-Boot this explains why adding that line yields the same result: it's effectivly the same handling as with ATMEL_NAND_NO_RB.
And because Linux can also not use a SoC feature which simply is not there, the question remains:
If both Linux and U-Boot have the GPIO handling for R/B setup, why can Linux access the chip fast and U-Boot can not?
I suspect because they have different drivers doing different things? One would have to look in deep detail what is done differently?
Whatever it is, from my POV it makes no sense to add the 'atmel,rb' property to the sam9x60 dts. The only two possible paths I see:
1. Short workaround: Remove the 'rb-gpios' property from U-Boot dts. The status can also be fetched through a NAND command from status register bit 6 of the flash (NAND_STATUS_READY) and that is done in drivers/mtd/nand/raw/nand_base.c all over the place. (This is probably why it works in this case and also why it works for SAMA5D2 in U-Boot with other boards, where we explicitly had to undef SYS_NAND_READY_PIN.)
2. Long term solution: Find the real cause and fix the U-Boot driver(s) …
Quoted 7 lines
(Note: all this while booting from SD card, so at91bootstrap should not interfere, because it does not touch nand.)
What I did not test yet:
- How it behaves in U-Boot when also adapting pinctrl
- How other combinations of adaptions to dts behave in Linux
Won't pursue these tests. Makes no sense in my opinion, because of the reasons stated above.
Greets
Alex
Quoted 38 lines
Sending this mail now anyway, it's too long already and office time is up for today. Will do more systematic tests tomorrow. Any more insights welcome.
Greets
AlexQuoted 31 lines
# nand@3 {
# reg = <0x30x00x800000>;
# atmel,rb = <0>;
# cs-gpios = <&pioD 4GPIO_ACTIVE_HIGH>;
# rb-gpios = <&pioD 5GPIO_ACTIVE_HIGH>;
# nand-bus-width = <8>;
# nand-ecc-mode = "hw";
# nand-ecc-strength = <8>;
# nand-ecc-step-size = <512>;
# nand-on-flash-bbt;>Quoted 19 lines
The actual flash chip is a Macronix MX30LF4G28AD, 512 MiB, SLC, erase
size: 256 KiB, page size: 4096, OOB size: 256.Greets
Alex
P.S.: although not returned by get_maintainer.pl I added Eugen to Cc because he is maintainer of the at91 and might have some insight if it is a general problem of the nand controller in at91 socs?Alexander Dahl (2):
mtd: nand: raw: atmel: Remove duplicate line
mtd: nand: raw: atmel: Add error handling when rb-gpios missingdrivers/mtd/nand/raw/atmel/nand-controller.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)base-commit:
a169438411f9277cc689c14078151aa1d1caae3c
Hello,
just a short supplement …
Am Wed, Aug 09, 2023 at 09:40:15AM +0200 schrieb Alexander Dahl:
Quoted 113 lines
Hello everyone,
I had a closer look into the SAMA5D2 Series Datasheet and the SAM9X60 Data Sheet again. See below.
Am Tue, Aug 08, 2023 at 05:00:48PM +0200 schrieb Alexander Dahl:
Quoted 48 lines
Hello Mihai,
Am Tue, Aug 08, 2023 at 01:40:26PM +0000 schrieb [email protected]:
Quoted 4 lines
Hi Alex,
Please find bellow my answer:
Quoted 40 lines
------------------------------
Added Mihai who tested this a lot at some point in time
Eugen
Quoted 33 lines · Alexander Dahl
Hello everyone,
this is a patch series wtih some real fixes _and_ a question or some kind of support request in the cover letter. I would be happy if anyone could read the cover letter carefully and answer to that one what might be the problem I see. O:-)
I'm currently working on the sam9x60-curiosity board and especially trying to get it booting from onboard raw NAND flash. As reported in my last series I got the flash recognized already. However interacting with it was terribly slow, because
nand_wait_ready()callingatmel_nand_dev_ready()ran into a 400ms timeout in several occasions, especially when reading from the device. Reading a single block triggered that timeout two times per page, which summed up to over 50 seconds for 64 × 4096 = 256k Bytes!(You can have U-Boot print that warning from
nand_wait_ready()by increasing the console log level to at least "warn".)Note: the dts from atmel/next seems correct to me, I double checked that again. My own debug log messages showed the GPIO is accessed, and if you add enough debug messages sometimes the timeout is not reached, so I'm sure the NAND chip eventually switches that R/B line and the code correctly sees that, that line level change however takes ages, something between 400ms and 500ms most of the times.
I vaguely remembered on SAMA5D2 the old atmel raw nand driver is used which does not support reading the R/B signal, but nevertheless works. I'm not familiar in detail with those raw NAND flash chips, but as far as I can understand, there are other ways to determine if the chip is ready or busy. So after I removed that rb-gpio parameter from '
at91-sam9x60_curiosity.dts' I ran into the bug fixed by patch 2.Quoted 5 lines
Maybe I should add: currently there are two different drivers for atmel raw nand controllers in U-Boot, the old non-DM driver used by sam9g20 or sama5 based boards for example and a new driver used by sam9x60 based boards. We are talking about sam9x60 and the new driver in '
drivers/mtd/nand/raw/atmel/nand-controller.c' here.The old one is enabled by
CONFIG_NAND_ATMEL, the new one byCONFIG_DM_NAND_ATMELinstead.Quoted 31 lines
Quoted 9 lines
Quoted 9 lines
With that patch applied _and_ rb-gpio still removed from dts, raw NAND access is reasonably fast on sam9x60-curiosity board. (You might want to rebase to atmel/next for testing this.) Not sure if I should send a patch for that dts change, because I suppose it's a workaround only and not addressing the actual cause?
I think the fix is correct in itself, I tested different combinations and compared with the driver in Linux, however …
Quoted 6 lines
Quoted 3 lines
Can anyone explain to me, why flash access is sooo slow if the R/B gpio is used? Especially in comparision to Linux, where I don't need to remove that thing from dts and it works reasonably fast?
// I'm sorry for quoting (email is sent from Outlook) # Please add in your board dts: atmel,rb = <0>
Although the new U-Boot driver tests for that, it is not documented in U-Boot devicetree bindings. According to Linux kernel (v6.4) device tree binding documentation it is only meaningful for sama5. Those binding documentation was added to Linux back in 2019 by Boris Brezillon. And that line is not present in the dts file for sam9x60-curiosity in Linux, so access is fast on Linux without that line (this is the part I don't understand yet).
From what I saw in datasheets sam9x60 and sama5d2 have different controllers (named 'SMC' and 'HSMC') and the U-Boot driver reflects that. That's why I did not add 'atmel,rb' to dts before, I though SMC is the older one which does not support native R/B line handling? (And because I took it from U-Boot
sam9x60ek.dtswhich also does not have it.)Quoted 5 lines
Nevertheless, I tried to add it now in U-Boot as you suggested (although without adapting pinctrl), and to my suprise it works … o.O
Trying the same in Linux leads to not finding a NAND device and thus failing of the atmel-nand-controller driver probe.
From datasheet POV this all makes sense. The HSMC on SAMA5D2 has a native NANDRDY signal/peripheral function to handle the R/B pin of the flash and can do the low level communication by itself with an embedded Nand Flash Controller (NFC). The SMC on SAM9X60 has no such thing and the datasheet explicitly recommends to connect the R/B pin to _any_ GPIO.
The new dm-based nand-controller driver in U-Boot only checks if dts has the 'rb-gpios' property and only then overrides the
chip->dev_readyfunction. So for U-Boot this explains why adding that line yields the same result: it's effectivly the same handling as withATMEL_NAND_NO_RB.
Quoted 8 lines
And because Linux can also not use a SoC feature which simply is not there, the question remains:
If both Linux and U-Boot have the GPIO handling for R/B setup, why can Linux access the chip fast and U-Boot can not?
I suspect because they have different drivers doing different things? One would have to look in deep detail what is done differently?
The answer is maybe simpler than I thought? No driver at all in Linux (v6.4) evaluates the 'rb-gpios' devicetree property. The Linux atmel nand controller driver only considers an old binding, which is not used in recent dts for sam9x60. So I guess Linux also does "soft wait" only and does not read the R/B pin. I suggest to discuss this topic separately on linux-mtd …
Greets
Alex
P.S.: according to the schematic/layout files of the sam9x60-curiosity board it's not easily possible to probe the R/B signal with an oscilloscope or logic analyzer, because it's a direct wire between a ball of the flash chip and a ball of the SoC, which is not exposed. No pads to probe, one would have to scratch away the covering solder mask …
Quoted 66 lines
Whatever it is, from my POV it makes no sense to add the 'atmel,rb' property to the sam9x60 dts. The only two possible paths I see:
1. Short workaround: Remove the 'rb-gpios' property from U-Boot dts. The status can also be fetched through a NAND command from status register bit 6 of the flash (
NAND_STATUS_READY) and that is done indrivers/mtd/nand/raw/nand_base.call over the place. (This is probably why it works in this case and also why it works for SAMA5D2 in U-Boot with other boards, where we explicitly had to undefSYS_NAND_READY_PIN.)2. Long term solution: Find the real cause and fix the U-Boot driver(s) …
Quoted 7 lines
(Note: all this while booting from SD card, so at91bootstrap should not interfere, because it does not touch nand.)
What I did not test yet:
- How it behaves in U-Boot when also adapting pinctrl
- How other combinations of adaptions to dts behave in LinuxWon't pursue these tests. Makes no sense in my opinion, because of the reasons stated above.
Greets
AlexQuoted 38 lines
Sending this mail now anyway, it's too long already and office time is up for today. Will do more systematic tests tomorrow. Any more insights welcome.
Greets
AlexQuoted 31 lines
# nand@3 {
# reg = <0x30x00x800000>;
# atmel,rb = <0>;
# cs-gpios = <&pioD 4GPIO_ACTIVE_HIGH>;
# rb-gpios = <&pioD 5GPIO_ACTIVE_HIGH>;
# nand-bus-width = <8>;
# nand-ecc-mode = "hw";
# nand-ecc-strength = <8>;
# nand-ecc-step-size = <512>;
# nand-on-flash-bbt;>Quoted 19 lines
The actual flash chip is a Macronix MX30LF4G28AD, 512 MiB, SLC, erase
size: 256 KiB, page size: 4096, OOB size: 256.Greets
Alex
P.S.: although not returned by get_maintainer.pl I added Eugen to Cc because he is maintainer of the at91 and might have some insight if it is a general problem of the nand controller in at91 socs?Alexander Dahl (2):
mtd: nand: raw: atmel: Remove duplicate line
mtd: nand: raw: atmel: Add error handling when rb-gpios missingdrivers/mtd/nand/raw/atmel/nand-controller.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)base-commit:
a169438411f9277cc689c14078151aa1d1caae3c