mtd: brcmnand: factor out CFG and CFG_EXT bitfields
authorBrian Norris <computersforpeace@gmail.com>
Fri, 30 Oct 2015 06:59:19 +0000 (12:29 +0530)
committerBrian Norris <computersforpeace@gmail.com>
Fri, 30 Oct 2015 18:50:34 +0000 (11:50 -0700)
Use enum instead of magic numbers for CFG and CFG_EXT bitfields.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Tested-by: Anup Patel <anup.patel@broadcom.com>
drivers/mtd/nand/brcmnand/brcmnand.c

index 7c1c306650a4c07eed6c74b12af2e8b2bc98feb7..3bd31a6055b642e9529577a66b25242fb6729432 100644 (file)
@@ -344,6 +344,28 @@ static const u8 brcmnand_cs_offsets_cs0[] = {
        [BRCMNAND_CS_TIMING2]           = 0x14,
 };
 
+/*
+ * Bitfields for the CFG and CFG_EXT registers. Pre-v7.1 controllers only had
+ * one config register, but once the bitfields overflowed, newer controllers
+ * (v7.1 and newer) added a CFG_EXT register and shuffled a few fields around.
+ */
+enum {
+       CFG_BLK_ADR_BYTES_SHIFT         = 8,
+       CFG_COL_ADR_BYTES_SHIFT         = 12,
+       CFG_FUL_ADR_BYTES_SHIFT         = 16,
+       CFG_BUS_WIDTH_SHIFT             = 23,
+       CFG_BUS_WIDTH                   = BIT(CFG_BUS_WIDTH_SHIFT),
+       CFG_DEVICE_SIZE_SHIFT           = 24,
+
+       /* Only for pre-v7.1 (with no CFG_EXT register) */
+       CFG_PAGE_SIZE_SHIFT             = 20,
+       CFG_BLK_SIZE_SHIFT              = 28,
+
+       /* Only for v7.1+ (with CFG_EXT register) */
+       CFG_EXT_PAGE_SIZE_SHIFT         = 0,
+       CFG_EXT_BLK_SIZE_SHIFT          = 4,
+};
+
 /* BRCMNAND_INTFC_STATUS */
 enum {
        INTFC_FLASH_STATUS              = GENMASK(7, 0),
@@ -1720,17 +1742,19 @@ static int brcmnand_set_cfg(struct brcmnand_host *host,
        }
        device_size = fls64(cfg->device_size) - fls64(BRCMNAND_MIN_DEVSIZE);
 
-       tmp = (cfg->blk_adr_bytes << 8) |
-               (cfg->col_adr_bytes << 12) |
-               (cfg->ful_adr_bytes << 16) |
-               (!!(cfg->device_width == 16) << 23) |
-               (device_size << 24);
+       tmp = (cfg->blk_adr_bytes << CFG_BLK_ADR_BYTES_SHIFT) |
+               (cfg->col_adr_bytes << CFG_COL_ADR_BYTES_SHIFT) |
+               (cfg->ful_adr_bytes << CFG_FUL_ADR_BYTES_SHIFT) |
+               (!!(cfg->device_width == 16) << CFG_BUS_WIDTH_SHIFT) |
+               (device_size << CFG_DEVICE_SIZE_SHIFT);
        if (cfg_offs == cfg_ext_offs) {
-               tmp |= (page_size << 20) | (block_size << 28);
+               tmp |= (page_size << CFG_PAGE_SIZE_SHIFT) |
+                      (block_size << CFG_BLK_SIZE_SHIFT);
                nand_writereg(ctrl, cfg_offs, tmp);
        } else {
                nand_writereg(ctrl, cfg_offs, tmp);
-               tmp = page_size | (block_size << 4);
+               tmp = (page_size << CFG_EXT_PAGE_SIZE_SHIFT) |
+                     (block_size << CFG_EXT_BLK_SIZE_SHIFT);
                nand_writereg(ctrl, cfg_ext_offs, tmp);
        }