Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Masahiro Yamada and committed by
Boris Brezillon
14157f86 882fd157

+14 -15
+1 -2
drivers/mtd/nand/atmel/nand-controller.c
··· 718 718 nc->op.addrs[nc->op.naddrs++] = page; 719 719 nc->op.addrs[nc->op.naddrs++] = page >> 8; 720 720 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) 723 722 nc->op.addrs[nc->op.naddrs++] = page >> 16; 724 723 } 725 724 }
+1 -2
drivers/mtd/nand/au1550nd.c
··· 331 331 332 332 ctx->write_byte(mtd, (u8)(page_addr >> 8)); 333 333 334 - /* One more address cycle for devices > 32MiB */ 335 - if (this->chipsize > (32 << 20)) 334 + if (this->options & NAND_ROW_ADDR_3) 336 335 ctx->write_byte(mtd, 337 336 ((page_addr >> 16) & 0x0f)); 338 337 }
+1 -2
drivers/mtd/nand/diskonchip.c
··· 705 705 if (page_addr != -1) { 706 706 WriteDOC((unsigned char)(page_addr & 0xff), docptr, Mplus_FlashAddress); 707 707 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) { 710 709 WriteDOC((unsigned char)((page_addr >> 16) & 0x0f), docptr, Mplus_FlashAddress); 711 710 printk("high density\n"); 712 711 }
+1 -2
drivers/mtd/nand/hisi504_nand.c
··· 432 432 host->addr_value[0] |= (page_addr & 0xffff) 433 433 << (host->addr_cycle * 8); 434 434 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) { 437 436 host->addr_cycle += 1; 438 437 if (host->command == NAND_CMD_ERASE1) 439 438 host->addr_value[0] |= ((page_addr >> 16) & 0xff) << 16;
+1 -2
drivers/mtd/nand/mxc_nand.c
··· 859 859 host->devtype_data->send_addr(host, 860 860 (page_addr >> 8) & 0xff, true); 861 861 } else { 862 - /* One more address cycle for higher density devices */ 863 - if (mtd->size >= 0x4000000) { 862 + if (nand_chip->options & NAND_ROW_ADDR_3) { 864 863 /* paddr_8 - paddr_15 */ 865 864 host->devtype_data->send_addr(host, 866 865 (page_addr >> 8) & 0xff,
+5 -4
drivers/mtd/nand/nand_base.c
··· 727 727 chip->cmd_ctrl(mtd, page_addr, ctrl); 728 728 ctrl &= ~NAND_CTRL_CHANGE; 729 729 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) 732 731 chip->cmd_ctrl(mtd, page_addr >> 16, ctrl); 733 732 } 734 733 chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); ··· 853 854 chip->cmd_ctrl(mtd, page_addr, ctrl); 854 855 chip->cmd_ctrl(mtd, page_addr >> 8, 855 856 NAND_NCE | NAND_ALE); 856 - /* One more address cycle for devices > 128MiB */ 857 - if (chip->chipsize > (128 << 20)) 857 + if (chip->options & NAND_ROW_ADDR_3) 858 858 chip->cmd_ctrl(mtd, page_addr >> 16, 859 859 NAND_NCE | NAND_ALE); 860 860 } ··· 3997 3999 chip->chip_shift = ffs((unsigned)(chip->chipsize >> 32)); 3998 4000 chip->chip_shift += 32 - 1; 3999 4001 } 4002 + 4003 + if (chip->chip_shift - chip->page_shift > 16) 4004 + chip->options |= NAND_ROW_ADDR_3; 4000 4005 4001 4006 chip->badblockbits = 8; 4002 4007 chip->erase = single_erase;
+1 -1
drivers/mtd/nand/nuc900_nand.c
··· 154 154 if (page_addr != -1) { 155 155 write_addr_reg(nand, page_addr); 156 156 157 - if (chip->chipsize > (128 << 20)) { 157 + if (chip->options & NAND_ROW_ADDR_3) { 158 158 write_addr_reg(nand, page_addr >> 8); 159 159 write_addr_reg(nand, page_addr >> 16 | ENDADDR); 160 160 } else {
+3
include/linux/mtd/rawnand.h
··· 177 177 */ 178 178 #define NAND_NEED_SCRAMBLING 0x00002000 179 179 180 + /* Device needs 3rd row address cycle */ 181 + #define NAND_ROW_ADDR_3 0x00004000 182 + 180 183 /* Options valid for Samsung large page devices */ 181 184 #define NAND_SAMSUNG_LP_OPTIONS NAND_CACHEPRG 182 185