1 /* 2 * Copyright (c) 2018 Fuzhou Rockchip Electronics Co., Ltd 3 * 4 * SPDX-License-Identifier: GPL-2.0 5 */ 6 7 #ifndef __FLASH_H 8 #define __FLASH_H 9 10 #ifndef BIT 11 #define BIT(nr) (1 << (nr)) 12 #endif 13 14 #define MAX_FLASH_NUM 2 15 #define MAX_IDB_RESERVED_BLOCK 12 16 17 #define NAND_CACHE_READ_EN BIT(0) 18 #define NAND_CACHE_RANDOM_READ_EN BIT(1) 19 #define NAND_CACHE_PROG_EN BIT(2) 20 #define NAND_MULTI_READ_EN BIT(3) 21 22 #define NAND_MULTI_PROG_EN BIT(4) 23 #define NAND_INTERLEAVE_EN BIT(5) 24 #define NAND_READ_RETRY_EN BIT(6) 25 #define NAND_RANDOMIZER_EN BIT(7) 26 27 #define NAND_INTER_MODE_OFFSET (0x8) 28 #define NAND_INTER_MODE_MARK (0x07) 29 #define NAND_INTER_SDR_EN BIT(0) 30 #define NAND_INTER_ONFI_EN BIT(1) 31 #define NAND_INTER_TOGGLE_EN BIT(2) 32 33 #define NAND_SDR_EN BIT(8) 34 #define NAND_ONFI_EN BIT(9) 35 #define NAND_TOGGLE_EN BIT(10) 36 #define NAND_UNIQUE_ID_EN BIT(11) 37 38 #define RESET_CMD 0xff 39 #define READ_ID_CMD 0x90 40 #define READ_STATUS_CMD 0x70 41 #define PAGE_PROG_CMD 0x8010 42 #define BLOCK_ERASE_CMD 0x60d0 43 #define READ_CMD 0x0030 44 #define READ_DP_OUT_CMD 0x05E0 45 #define READ_ECC_STATUS_CMD 0x7A 46 47 #define SAMSUNG 0x00 /* SAMSUNG */ 48 #define TOSHIBA 0x01 /* TOSHIBA */ 49 #define HYNIX 0x02 /* HYNIX */ 50 #define INFINEON 0x03 /* INFINEON */ 51 #define MICRON 0x04 /* MICRON */ 52 #define RENESAS 0x05 /* RENESAS */ 53 #define ST 0x06 /* ST */ 54 #define INTEL 0x07 /* intel */ 55 #define Sandisk 0x08 /* Sandisk */ 56 57 #define RR_NONE 0x00 58 #define RR_HY_1 0x01 /* hynix H27UCG8T2M */ 59 #define RR_HY_2 0x02 /* hynix H27UBG08U0B */ 60 #define RR_HY_3 0x03 /* hynix H27UCG08U0B H27UBG08U0C */ 61 #define RR_HY_4 0x04 /* hynix H27UCG8T2A */ 62 #define RR_HY_5 0x05 /* hynix H27UCG8T2E */ 63 #define RR_HY_6 0x06 /* hynix H27QCG8T2F5R-BCG */ 64 #define RR_MT_1 0x11 /* micron */ 65 #define RR_MT_2 0x12 /* micron L94C L95B */ 66 #define RR_TH_1 0x21 /* toshiba */ 67 #define RR_TH_2 0x22 /* toshiba */ 68 #define RR_TH_3 0x23 /* toshiba */ 69 #define RR_SS_1 0x31 /* samsung */ 70 #define RR_SD_1 0x41 /* Sandisk */ 71 #define RR_SD_2 0x42 /* Sandisk */ 72 #define RR_SD_3 0x43 /* Sandisk */ 73 #define RR_SD_4 0x44 /* Sandisk */ 74 75 /* 0 1 2 3 4 5 6 7 8 9 slc */ 76 #define LSB_0 0 77 /* 0 1 2 3 6 7 A B E F hynix, micron 74A */ 78 #define LSB_1 1 79 /* 0 1 3 5 7 9 B D toshiba samsung sandisk */ 80 #define LSB_2 2 81 /* 0 1 2 3 4 5 8 9 C D 10 11 micron 84A */ 82 #define LSB_3 3 83 /* 0 1 2 3 4 5 7 8 A B E F micron L95B */ 84 #define LSB_4 4 85 /* 0 1 2 3 4 5 8 9 14 15 20 21 26 27 micron B74A TLC */ 86 #define LSB_6 6 87 /* 0 3 6 9 C F 12 15 18 15 1B 1E 21 24 K9ABGD8U0C TLC */ 88 #define LSB_7 7 89 90 /* BadBlockFlagMode */ 91 /* first spare @ first page of each blocks */ 92 #define BBF_1 1 93 /* first spare @ last page of each blocks */ 94 #define BBF_2 2 95 /* first spare @ first and last page of each blocks */ 96 #define BBF_11 3 97 /* sandisk 15nm flash prog first page without data and check status */ 98 #define BBF_3 4 99 100 #define MPM_0 0 /* block 0 ~ 1 */ 101 #define MPM_1 1 /* block 0 ~ 2048... */ 102 103 struct NAND_PARA_INFO_T { 104 u8 id_bytes; 105 u8 nand_id[6]; 106 u8 vendor; 107 u8 die_per_chip; 108 u8 sec_per_page; 109 u16 page_per_blk; 110 u8 cell; /* 1 slc , 2 mlc , 3 tlc */ 111 u8 plane_per_die; 112 u16 blk_per_plane; 113 u16 operation_opt; 114 u8 lsb_mode; 115 u8 read_retry_mode; 116 u8 ecc_bits; 117 u8 access_freq; 118 u8 opt_mode; 119 u8 die_gap; 120 u8 bad_block_mode; 121 u8 multi_plane_mode; 122 u8 reversd2[6]; /* 32 bytes */ 123 }; 124 125 extern struct nand_phy_info g_nand_phy_info; 126 extern struct nand_ops g_nand_ops; 127 extern void __iomem *nandc_base; 128 129 void nandc_flash_get_id(u8 cs, void *buf); 130 void nandc_flash_reset(u8 chip_sel); 131 u32 nandc_flash_init(void __iomem *nandc_addr); 132 u32 nandc_flash_deinit(void); 133 134 #endif 135