mtd: nand: raw: atmel: Using dm driver for older sam9 SoCs
Subsystems (6)
cover mtd: nand: raw: atmel: Using dm driver for older sam9 SoCs
Hello raw NAND fans,
today I thought it would be interesting to have all that automatic NAND flash timings setting usable with an old board featuring a at91sam9g20 SoC, which would pave the way to get rid of the old atmel raw nand driver eventually. My "let's try this quickly" ended up in "damn this took hours and now I'm stuck".
Those older SoCs have no hardware ecc engine like the sama5d2 or sam9x60 have, which the Linux driver can work with. (The U-Boot driver was ported from Linux back then.)
The problem is NAND flash detection fails because the atmel nand controller drivers fails on probing. In fact atmel_nand_controller_init() tries to set the pointer nc->pmecc by calling devm_atmel_pmecc_get(). That one probably gets a -EPROBE_DEFER returned by atmel_pmecc_get_by_node() and then atmel_nand_controller_init() returns -EPROBE_DEFER too and probing the driver fails. I suspect it should work fine if nc->pmecc would be NULL, but I have no idea what would be the right place to implement this. I also suspect that -EPROBE_DEFER contradicts the U-Boot driver model somehow? The raw/atmel/nand-controller driver was adapted (quite a bit) to work with U-Boot, but maybe some aspects of U-Boot driver model where not considered correctly?
The attached patches are what I have so far, marked them as RFC because my actual goal of using the new dm based driver for the old SoC was not completed.
Greets
Alex
P.S.: Patch stack based on next.
Alexander Dahl (3):
ARM: dts: at91sam9260: Add modern NAND controller nodes
memory: atmel-ebi: Add compatible for older 9260 cores
mtd: nand: raw: atmel: Remove redundant PMECC probe
arch/arm/dts/at91sam9260.dtsi | 47 ++++++++++++++++++++ drivers/memory/atmel_ebi.c | 1 + drivers/mtd/nand/raw/atmel/nand-controller.c | 7 --- drivers/mtd/nand/raw/atmel/pmecc.c | 1 + 4 files changed, 49 insertions(+), 7 deletions(-)
base-commit: beedf675b36841ce1e077779157a87a6505317e6
Signature · 1 line
2.39.2
RFC PATCH 1/3 ARM: dts: at91sam9260: Add modern NAND controller nodes
Required for using the new dm enabled nand-controller driver on sam9260 family based boards. Ported from Linux v6.8. Node for old NAND driver binding kept in place for now, so we can change nan controller driver board by board.
--- arch/arm/dts/at91sam9260.dtsi | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
arch/arm/dts/at91sam9260.dtsi +47 -0
@@ -99,6 +99,16 @@ reg = <0xffffea00 0x200>; }; + smc: smc@ffffec00 { + compatible = "atmel,at91sam9260-smc", "syscon"; + reg = <0xffffec00 0x200>; + }; + + matrix: matrix@ffffee00 { + compatible = "atmel,at91sam9260-matrix", "syscon"; + reg = <0xffffee00 0x200>; + }; + pmc: pmc@fffffc00 { compatible = "atmel,at91sam9260-pmc", "syscon"; reg = <0xfffffc00 0x100>;
@@ -575,6 +585,16 @@ <AT91_PIOC 13 AT91_PERIPH_GPIO AT91_PINCTRL_PULL_UP /* PC13 gpio RDY pin pull_up */ AT91_PIOC 14 AT91_PERIPH_GPIO AT91_PINCTRL_PULL_UP>; /* PC14 gpio enable pin pull_up */ }; + + pinctrl_nand_rb: nand-rb-0 { + atmel,pins = + <AT91_PIOC 13 AT91_PERIPH_GPIO AT91_PINCTRL_PULL_UP>; + }; + + pinctrl_nand_cs: nand-cs-0 { + atmel,pins = + <AT91_PIOC 14 AT91_PERIPH_GPIO AT91_PINCTRL_PULL_UP>; + }; }; macb {
@@ -1030,6 +1050,33 @@ clock-names = "ohci_clk", "hclk", "uhpck"; status = "disabled"; }; + + ebi: ebi@10000000 { + compatible = "atmel,at91sam9260-ebi"; + #address-cells = <2>; + #size-cells = <1>; + atmel,smc = <&smc>; + atmel,matrix = <&matrix>; + reg = <0x10000000 0x80000000>; + ranges = <0x0 0x0 0x10000000 0x10000000 + 0x1 0x0 0x20000000 0x10000000 + 0x2 0x0 0x30000000 0x10000000 + 0x3 0x0 0x40000000 0x10000000 + 0x4 0x0 0x50000000 0x10000000 + 0x5 0x0 0x60000000 0x10000000 + 0x6 0x0 0x70000000 0x10000000 + 0x7 0x0 0x80000000 0x10000000>; + clocks = <&mck>; + status = "disabled"; + + nand_controller: nand-controller { + compatible = "atmel,at91sam9260-nand-controller"; + #address-cells = <2>; + #size-cells = <1>; + ranges; + status = "disabled"; + }; + }; }; i2c@0 {
Signature · 1 line
2.39.2
RFC PATCH 2/3 memory: atmel-ebi: Add compatible for older 9260 cores
In reply to Alexander DahlRequired for using the new dm enabled nand controller driver on old boards like the at91sam9g20-ek.
--- drivers/memory/atmel_ebi.c | 1 + 1 file changed, 1 insertion(+)
drivers/memory/atmel_ebi.c +1 -0
@@ -23,6 +23,7 @@ static int atmel_ebi_probe(struct udevice *dev) }static const struct udevice_id atmel_ebi_match[] = { + {.compatible ="atmel,at91sam9260-ebi" }, {.compatible ="microchip,sam9x60-ebi" }, {.compatible ="atmel,sama5d3-ebi" }, {/* Sentinel */ }
Signature · 1 line
2.39.2
RFC PATCH 3/3 mtd: nand: raw: atmel: Remove redundant PMECC probe
In reply to Alexander DahlAlways probing pmecc in the generic nand controller probe function and bailing out if pmecc is missing, prevents the driver to be usable for SoCs which do not have a pmecc hardware ecc engine like older sam9 SoCs, for example at91sam9g20. Tested on sam9x60 that the call, which the comment was moved to, is sufficient to probe the pmecc.
--- drivers/mtd/nand/raw/atmel/nand-controller.c | 7 ------- drivers/mtd/nand/raw/atmel/pmecc.c | 1 + 2 files changed, 1 insertion(+), 7 deletions(-)
drivers/mtd/nand/raw/atmel/nand-controller.c +0 -7
@@ -2203,7 +2203,6 @@ static const struct udevice_id atmel_nand_controller_of_ids[] = {static int atmel_nand_controller_probe (struct udevice *dev) {const struct atmel_nand_controller_caps *caps; -struct udevice *pmecc_dev; caps = (struct atmel_nand_controller_caps *)dev_get_driver_data (dev);if (!caps) {
@@ -2211,12 +2210,6 @@ static int atmel_nand_controller_probe(struct udevice *dev)return -EINVAL ; } -/* Probe pmecc driver */ -if (uclass_get_device (UCLASS_MTD ,1 , &pmecc_dev)) { -printf ("%s: get device fail\n" , __func__); -return -EINVAL ; - } -return caps->ops->probe (dev, caps); }
drivers/mtd/nand/raw/atmel/pmecc.c +1 -0
@@ -913,6 +913,7 @@ struct atmel_pmecc *devm_atmel_pmecc_get(struct udevice *userdev) ret =ofnode_parse_phandle_with_args (userdev->node_,"ecc-engine" ,NULL ,0 ,0 , &args); +/* Probe pmecc driver */ ret =uclass_get_device_by_ofnode (UCLASS_MTD , args.node, &pdev);if (ret)return NULL ;
Signature · 1 line
2.39.2
Quoted 2 lines · Alexander Dahl
Hello raw NAND fans,
Hello Alexander,
Thank you for your efforts
Quoted 10 lines
today I thought it would be interesting to have all that automatic NAND flash timings setting usable with an old board featuring a at91sam9g20 SoC, which would pave the way to get rid of the old atmel raw nand driver eventually. My "let's try this quickly" ended up in "damn this took hours and now I'm stuck".
Those older SoCs have no hardware ecc engine like the sama5d2 or sam9x60 have, which the Linux driver can work with. (The U-Boot driver was ported from Linux back then.)
Quoted 12 lines
The problem is NAND flash detection fails because the atmel nand controller drivers fails on probing. In fact
atmel_nand_controller_init()tries to set the pointernc->pmeccby callingdevm_atmel_pmecc_get(). That one probably gets a -EPROBE_DEFER returned byatmel_pmecc_get_by_node()and thenatmel_nand_controller_init()returns -EPROBE_DEFER too and probing the driver fails. I suspect it should work fine ifnc->pmeccwould be NULL, but I have no idea what would be the right place to implement this. I also suspect that -EPROBE_DEFER contradicts the U-Boot driver model somehow? The raw/atmel/nand-controller driver was adapted (quite a bit) to work with U-Boot, but maybe some aspects of U-Boot driver model where not considered correctly?
I added Simon, to give us a hint on how to approach this.
How I see it, is that the probing of the NAND should pause, and then the DM should look for the dependency, and probe it. if that dependency fails, then NAND probe fails. But returning DEFER would not be good since I do not believe there is another probe attempt unless manually done so (and it would be weird to get some error on first probe and success on the next, at least in u-boot state of mind) Maybe Simon can give us some ideas
Quoted 4 lines
The attached patches are what I have so far, marked them as RFC because my actual goal of using the new dm based driver for the old SoC was not completed.
Patches look good, but I am not sure whether they bring any additional value as you claim it's not working. Maybe they could be picked up and worked more to get it into the state you want ?
From my knowledge, investing effort into these old SoCs is not a priority for the at91 people.
Eugen
Quoted 19 lines
Greets
Alex
P.S.: Patch stack based on next.Alexander Dahl (3):
ARM: dts: at91sam9260: Add modern NAND controller nodes
memory: atmel-ebi: Add compatible for older 9260 cores
mtd: nand: raw: atmel: Remove redundant PMECC probearch/arm/dts/at91sam9260.dtsi | 47 ++++++++++++++++++++ drivers/memory/atmel_ebi.c | 1 + drivers/mtd/nand/raw/atmel/nand-controller.c | 7 --- drivers/mtd/nand/raw/atmel/pmecc.c | 1 + 4 files changed, 49 insertions(+), 7 deletions(-)base-commit:
beedf675b36841ce1e077779157a87a6505317e6