Skip to content

Commit 7aa921e

Browse files
masahir0yambarus
authored andcommitted
mtd: nand: introduce NAND_ROW_ADDR_3 flag
Several drivers check ->chipsize to see if the third row address cycle is needed. Instead of embedding magic sizes such as 32MB, 128MB in drivers, introduce a new flag NAND_ROW_ADDR_3 for clean-up. Since nand_scan_ident() knows well about the device, it can handle this properly. The flag is set if the row address bit width is greater than 16. Delete comments such as "One more address cycle for ..." because intention is now clear enough from the code. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Acked-by: Wenyou Yang <wenyou.yang@microchip.com> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> (cherry picked from commit 14157f8)
1 parent a16134b commit 7aa921e

8 files changed

Lines changed: 14 additions & 15 deletions

File tree

drivers/mtd/nand/atmel/nand-controller.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,7 @@ static void atmel_nfc_set_op_addr(struct nand_chip *chip, int page, int column)
718718
nc->op.addrs[nc->op.naddrs++] = page;
719719
nc->op.addrs[nc->op.naddrs++] = page >> 8;
720720

721-
if ((mtd->writesize > 512 && chip->chipsize > SZ_128M) ||
722-
(mtd->writesize <= 512 && chip->chipsize > SZ_32M))
721+
if (chip->options & NAND_ROW_ADDR_3)
723722
nc->op.addrs[nc->op.naddrs++] = page >> 16;
724723
}
725724
}

drivers/mtd/nand/au1550nd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,7 @@ static void au1550_command(struct mtd_info *mtd, unsigned command, int column, i
331331

332332
ctx->write_byte(mtd, (u8)(page_addr >> 8));
333333

334-
/* One more address cycle for devices > 32MiB */
335-
if (this->chipsize > (32 << 20))
334+
if (this->options & NAND_ROW_ADDR_3)
336335
ctx->write_byte(mtd,
337336
((page_addr >> 16) & 0x0f));
338337
}

drivers/mtd/nand/diskonchip.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,7 @@ static void doc2001plus_command(struct mtd_info *mtd, unsigned command, int colu
705705
if (page_addr != -1) {
706706
WriteDOC((unsigned char)(page_addr & 0xff), docptr, Mplus_FlashAddress);
707707
WriteDOC((unsigned char)((page_addr >> 8) & 0xff), docptr, Mplus_FlashAddress);
708-
/* One more address cycle for higher density devices */
709-
if (this->chipsize & 0x0c000000) {
708+
if (this->options & NAND_ROW_ADDR_3) {
710709
WriteDOC((unsigned char)((page_addr >> 16) & 0x0f), docptr, Mplus_FlashAddress);
711710
printk("high density\n");
712711
}

drivers/mtd/nand/hisi504_nand.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,7 @@ static void set_addr(struct mtd_info *mtd, int column, int page_addr)
432432
host->addr_value[0] |= (page_addr & 0xffff)
433433
<< (host->addr_cycle * 8);
434434
host->addr_cycle += 2;
435-
/* One more address cycle for devices > 128MiB */
436-
if (chip->chipsize > (128 << 20)) {
435+
if (chip->options & NAND_ROW_ADDR_3) {
437436
host->addr_cycle += 1;
438437
if (host->command == NAND_CMD_ERASE1)
439438
host->addr_value[0] |= ((page_addr >> 16) & 0xff) << 16;

drivers/mtd/nand/mxc_nand.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,8 +859,7 @@ static void mxc_do_addr_cycle(struct mtd_info *mtd, int column, int page_addr)
859859
host->devtype_data->send_addr(host,
860860
(page_addr >> 8) & 0xff, true);
861861
} else {
862-
/* One more address cycle for higher density devices */
863-
if (mtd->size >= 0x4000000) {
862+
if (nand_chip->options & NAND_ROW_ADDR_3) {
864863
/* paddr_8 - paddr_15 */
865864
host->devtype_data->send_addr(host,
866865
(page_addr >> 8) & 0xff,

drivers/mtd/nand/nand_base.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,7 @@ static void nand_command(struct mtd_info *mtd, unsigned int command,
727727
chip->cmd_ctrl(mtd, page_addr, ctrl);
728728
ctrl &= ~NAND_CTRL_CHANGE;
729729
chip->cmd_ctrl(mtd, page_addr >> 8, ctrl);
730-
/* One more address cycle for devices > 32MiB */
731-
if (chip->chipsize > (32 << 20))
730+
if (chip->options & NAND_ROW_ADDR_3)
732731
chip->cmd_ctrl(mtd, page_addr >> 16, ctrl);
733732
}
734733
chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE);
@@ -854,8 +853,7 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
854853
chip->cmd_ctrl(mtd, page_addr, ctrl);
855854
chip->cmd_ctrl(mtd, page_addr >> 8,
856855
NAND_NCE | NAND_ALE);
857-
/* One more address cycle for devices > 128MiB */
858-
if (chip->chipsize > (128 << 20))
856+
if (chip->options & NAND_ROW_ADDR_3)
859857
chip->cmd_ctrl(mtd, page_addr >> 16,
860858
NAND_NCE | NAND_ALE);
861859
}
@@ -4003,6 +4001,9 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
40034001
chip->chip_shift += 32 - 1;
40044002
}
40054003

4004+
if (chip->chip_shift - chip->page_shift > 16)
4005+
chip->options |= NAND_ROW_ADDR_3;
4006+
40064007
chip->badblockbits = 8;
40074008
chip->erase = single_erase;
40084009

drivers/mtd/nand/nuc900_nand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static void nuc900_nand_command_lp(struct mtd_info *mtd, unsigned int command,
154154
if (page_addr != -1) {
155155
write_addr_reg(nand, page_addr);
156156

157-
if (chip->chipsize > (128 << 20)) {
157+
if (chip->options & NAND_ROW_ADDR_3) {
158158
write_addr_reg(nand, page_addr >> 8);
159159
write_addr_reg(nand, page_addr >> 16 | ENDADDR);
160160
} else {

include/linux/mtd/rawnand.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ enum nand_ecc_algo {
177177
*/
178178
#define NAND_NEED_SCRAMBLING 0x00002000
179179

180+
/* Device needs 3rd row address cycle */
181+
#define NAND_ROW_ADDR_3 0x00004000
182+
180183
/* Options valid for Samsung large page devices */
181184
#define NAND_SAMSUNG_LP_OPTIONS NAND_CACHEPRG
182185

0 commit comments

Comments
 (0)