mtd: nand: sunxi: rely on nand_dt_init initialization
PATCH v2 1/1 mtd: nand: sunxi: rely on nand_dt_init initialization
nand_dt_init(), called from nand_scan_ident(), is already parsing the generic MTD/NAND DT properties, and initializing the nand_chip struct accordingly.
Rely on this initialization instead of manually parsing those properties.
---
Changes since v1:
- drop unused strength and blk_size variables
--- drivers/mtd/nand/sunxi_nand.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-)
drivers/mtd/nand/sunxi_nand.c +5 -15
@@ -1164,16 +1164,9 @@ static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc, struct device_node *np) {struct nand_chip *nand = mtd->priv; -int strength; -int blk_size;int ret; - blk_size =of_get_nand_ecc_step_size (np); - strength =of_get_nand_ecc_strength (np); -if (blk_size >0 && strength >0 ) { - ecc->size = blk_size; - ecc->strength = strength; - }else { +if (!ecc->size) { ecc->size = nand->ecc_step_ds; ecc->strength = nand->ecc_strength_ds; }
@@ -1183,10 +1176,6 @@ static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc, ecc->mode =NAND_ECC_HW ; - ret =of_get_nand_ecc_mode (np); -if (ret >=0 ) - ecc->mode = ret; -switch (ecc->mode) {case NAND_ECC_SOFT_BCH :break ;
@@ -1312,15 +1301,13 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,/* Default tR value specified in the ONFI spec (chapter 4.15.1) */ nand->chip_delay =200 ; nand->controller = &nfc->controller; + nand->dn = np; nand->select_chip = sunxi_nfc_select_chip; nand->cmd_ctrl = sunxi_nfc_cmd_ctrl; nand->read_buf = sunxi_nfc_read_buf; nand->write_buf = sunxi_nfc_write_buf; nand->read_byte = sunxi_nfc_read_byte; -if (of_get_nand_on_flash_bbt (np)) - nand->bbt_options |=NAND_BBT_USE_FLASH |NAND_BBT_NO_OOB ; - mtd = &chip->mtd; mtd->dev.parent = dev; mtd->priv = nand;
@@ -1330,6 +1317,9 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,if (ret)return ret; +if (nand->bbt_options &NAND_BBT_USE_FLASH ) + nand->bbt_options |=NAND_BBT_NO_OOB ; + ret =sunxi_nand_chip_init_timings (chip, np);if (ret) {dev_err (dev,"could not configure chip timings: %d\n" , ret);
Signature · 1 line
1.9.1
PATCH v2 1/1 mtd: nand: sunxi: rely on nand_dt_init initialization
Quoted 9 lines · Boris Brezillon
nand_dt_init(), called fromnand_scan_ident(), is already parsing the generic MTD/NAND DT properties, and initializing thenand_chipstruct accordingly.
Rely on this initialization instead of manually parsing those properties.Signed-off-by Boris Brezillon <[email protected]>---
Changes since v1:
- drop unused strength andblk_sizevariables
Good catch, I was about to comment on v1 :)
Quoted 27 lines
--- drivers/mtd/nand/sunxi_nand.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-)drivers/mtd/nand/sunxi_nand.c +1
-8@@ -1164,16 +1164,9 @@ static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc, struct device_node *np) {struct nand_chip *nand = mtd->priv; -int strength; -int blk_size;int ret; - blk_size =of_get_nand_ecc_step_size (np); - strength =of_get_nand_ecc_strength (np); -if (blk_size >0 && strength >0 ) { - ecc->size = blk_size; - ecc->strength = strength; - }else { +if (!ecc->size) { ecc->size = nand->ecc_step_ds; ecc->strength = nand->ecc_strength_ds; }
drivers/mtd/nand/sunxi_nand.c static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc, · line 1189
Quoted 7 lines
drivers/mtd/nand/sunxi_nand.c +0
-4@@ -1183,10 +1176,6 @@ static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc, ecc->mode =NAND_ECC_HW ; - ret =of_get_nand_ecc_mode (np); -if (ret >=0 ) - ecc->mode = ret; -
I think you've missed something here. You're now *only* allowing HW ECC! You now want to make this a default case.
There's also a subtle change here that affects more than just here: you don't have a good way to tell the difference between "no ECC mode provide" and NAND_ECC_NONE. Perhaps we can modify the nand_ecc_modes_t enum to include a "uninitialized" value? I'm not sure if that'd work best as 0, -1, or something else, in case there are people making assumptions elsewhere...
Quoted 21 lines
drivers/mtd/nand/sunxi_nand.c +1
-3switch (ecc->mode) {case NAND_ECC_SOFT_BCH :break ;@@ -1312,15 +1301,13 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,/* Default tR value specified in the ONFI spec (chapter 4.15.1) */ nand->chip_delay =200 ; nand->controller = &nfc->controller; + nand->dn = np; nand->select_chip = sunxi_nfc_select_chip; nand->cmd_ctrl = sunxi_nfc_cmd_ctrl; nand->read_buf = sunxi_nfc_read_buf; nand->write_buf = sunxi_nfc_write_buf; nand->read_byte = sunxi_nfc_read_byte; -if (of_get_nand_on_flash_bbt (np)) - nand->bbt_options |=NAND_BBT_USE_FLASH |NAND_BBT_NO_OOB ; - mtd = &chip->mtd; mtd->dev.parent = dev; mtd->priv = nand;
drivers/mtd/nand/sunxi_nand.c static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc, · line 1325
Quoted 9 lines
drivers/mtd/nand/sunxi_nand.c +3
-0@@ -1330,6 +1317,9 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,if (ret)return ret; +if (nand->bbt_options &NAND_BBT_USE_FLASH ) + nand->bbt_options |=NAND_BBT_NO_OOB ; + ret =sunxi_nand_chip_init_timings (chip, np);if (ret) {dev_err (dev,"could not configure chip timings: %d\n" , ret);
Brian
PATCH v2 1/1 mtd: nand: sunxi: rely on nand_dt_init initialization
Hi Brian,
Quoted 43 lines · On Tue, 1 Sep 2015 18:16:16 -0700 Brian Norris <[email protected]>…
Quoted 9 lines · Boris Brezillon
nand_dt_init(), called fromnand_scan_ident(), is already parsing the generic MTD/NAND DT properties, and initializing thenand_chipstruct accordingly.
Rely on this initialization instead of manually parsing those properties.Signed-off-by Boris Brezillon <[email protected]>---
Changes since v1:
- drop unused strength andblk_sizevariablesGood catch, I was about to comment on v1 :)
Quoted 30 lines
--- drivers/mtd/nand/sunxi_nand.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-)drivers/mtd/nand/sunxi_nand.c +1
-8@@ -1164,16 +1164,9 @@ static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc, struct device_node *np) {struct nand_chip *nand = mtd->priv; -int strength; -int blk_size;int ret; - blk_size =of_get_nand_ecc_step_size (np); - strength =of_get_nand_ecc_strength (np); -if (blk_size >0 && strength >0 ) { - ecc->size = blk_size; - ecc->strength = strength; - }else { +if (!ecc->size) { ecc->size = nand->ecc_step_ds; ecc->strength = nand->ecc_strength_ds; }@@ -1183,10 +1176,6 @@ static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc, ecc->mode =NAND_ECC_HW ;
Quoted 7 lines
drivers/mtd/nand/sunxi_nand.c static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc, · line 1189
Quoted 4 lines
drivers/mtd/nand/sunxi_nand.c +0
-4- ret =of_get_nand_ecc_mode (np); -if (ret >=0 ) - ecc->mode = ret; -I think you've missed something here. You're now *only* allowing HW ECC! You now want to make this a default case.
Indeed, I missed that point.
Quoted 7 lines
There's also a subtle change here that affects more than just here: you don't have a good way to tell the difference between "no ECC mode provide" and
NAND_ECC_NONE. Perhaps we can modify thenand_ecc_modes_tenum to include a "uninitialized" value? I'm not sure if that'd work best as 0, -1, or something else, in case there are people making assumptions elsewhere...
It really depends on what we want to do. I see at least two solutions for this problem:
1/ keep the nand_dt_init() implementation as is and ask
nand_scan_ident() callers to pre-set their default value in ecc.mode. This should work since ecc.mode is only overridden if ecc_mode is >= 0.
2/ modify the nand_dt_init function to assign the ecc_mode even if it
is negative, or create a new value in the enum (NAND_ECC_UNSPECIFIED = -1) and assign it to ecc.mode when ecc_mode is negative.
1# does not require any change, but if we choose this solution, we should make it clear that NAND controller drivers should set their default value before calling nand_scan_ident().
And if go for 2#, that's not like we'll have to patch a lot of drivers (AFAICT, the only user in 4.2 is the brcmnand driver) ;-).
Best Regards,
Boris
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH v2 1/1 mtd: nand: sunxi: rely on nand_dt_init initialization
Quoted 18 lines · Boris Brezillon
Quoted 6 lines · On Tue, 1 Sep 2015 18:16:16 -0700 Brian Norris <[email protected]>…
There's also a subtle change here that affects more than just here: you don't have a good way to tell the difference between "no ECC mode provide" and
NAND_ECC_NONE. Perhaps we can modify thenand_ecc_modes_tenum to include a "uninitialized" value? I'm not sure if that'd work best as 0, -1, or something else, in case there are people making assumptions elsewhere...It really depends on what we want to do. I see at least two solutions for this problem:
1/ keep thenand_dt_init()implementation as is and ask
nand_scan_ident()callers to pre-set their default value in ecc.mode. This should work since ecc.mode is only overridden ifecc_modeis >= 0.
2/ modify thenand_dt_initfunction to assign theecc_modeeven if it
is negative, or create a new value in the enum (NAND_ECC_UNSPECIFIED= -1) and assign it to ecc.mode whenecc_modeis negative.
Quoted 3 lines
1# does not require any change, but if we choose this solution, we should make it clear that NAND controller drivers should set their default value before calling
nand_scan_ident().
I'm OK with your choice of #1. Your v3 patch looks fine.
Quoted 2 lines
And if go for 2#, that's not like we'll have to patch a lot of drivers (AFAICT, the only user in 4.2 is the brcmnand driver) ;-).
:) Well, I thought there were others in the pipeline. I've at least reviewed another addition somewhat recently, but it wasn't quite ready.
Brian