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 46 #define SAMSUNG 0x00 /* SAMSUNG */ 47 #define TOSHIBA 0x01 /* TOSHIBA */ 48 #define HYNIX 0x02 /* HYNIX */ 49 #define INFINEON 0x03 /* INFINEON */ 50 #define MICRON 0x04 /* MICRON */ 51 #define RENESAS 0x05 /* RENESAS */ 52 #define ST 0x06 /* ST */ 53 #define INTEL 0x07 /* intel */ 54 #define Sandisk 0x08 /* Sandisk */ 55 56 #define RR_NONE 0x00 57 #define RR_HY_1 0x01 /* hynix H27UCG8T2M */ 58 #define RR_HY_2 0x02 /* hynix H27UBG08U0B */ 59 #define RR_HY_3 0x03 /* hynix H27UCG08U0B H27UBG08U0C */ 60 #define RR_HY_4 0x04 /* hynix H27UCG8T2A */ 61 #define RR_HY_5 0x05 /* hynix H27UCG8T2E */ 62 #define RR_HY_6 0x06 /* hynix H27QCG8T2F5R-BCG */ 63 #define RR_MT_1 0x11 /* micron */ 64 #define RR_MT_2 0x12 /* micron L94C L95B */ 65 #define RR_TH_1 0x21 /* toshiba */ 66 #define RR_TH_2 0x22 /* toshiba */ 67 #define RR_TH_3 0x23 /* toshiba */ 68 #define RR_SS_1 0x31 /* samsung */ 69 #define RR_SD_1 0x41 /* Sandisk */ 70 #define RR_SD_2 0x42 /* Sandisk */ 71 #define RR_SD_3 0x43 /* Sandisk */ 72 #define RR_SD_4 0x44 /* Sandisk */ 73 74 /* 0 1 2 3 4 5 6 7 8 9 slc */ 75 #define LSB_0 0 76 /* 0 1 2 3 6 7 A B E F hynix, micron 74A */ 77 #define LSB_1 1 78 /* 0 1 3 5 7 9 B D toshiba samsung sandisk */ 79 #define LSB_2 2 80 /* 0 1 2 3 4 5 8 9 C D 10 11 micron 84A */ 81 #define LSB_3 3 82 /* 0 1 2 3 4 5 7 8 A B E F micron L95B */ 83 #define LSB_4 4 84 /* 0 1 2 3 4 5 8 9 14 15 20 21 26 27 micron B74A TLC */ 85 #define LSB_6 6 86 /* 0 3 6 9 C F 12 15 18 15 1B 1E 21 24 K9ABGD8U0C TLC */ 87 #define LSB_7 7 88 89 /* BadBlockFlagMode */ 90 /* first spare @ first page of each blocks */ 91 #define BBF_1 1 92 /* first spare @ last page of each blocks */ 93 #define BBF_2 2 94 /* first spare @ first and last page of each blocks */ 95 #define BBF_11 3 96 /* sandisk 15nm flash prog first page without data and check status */ 97 #define BBF_3 4 98 99 #define MPM_0 0 /* block 0 ~ 1 */ 100 #define MPM_1 1 /* block 0 ~ 2048... */ 101 102 struct NAND_PARA_INFO_T { 103 u8 id_bytes; 104 u8 nand_id[6]; 105 u8 vendor; 106 u8 die_per_chip; 107 u8 sec_per_page; 108 u16 page_per_blk; 109 u8 cell; /* 1 slc , 2 mlc , 3 tlc */ 110 u8 plane_per_die; 111 u16 blk_per_plane; 112 u16 operation_opt; 113 u8 lsb_mode; 114 u8 read_retry_mode; 115 u8 ecc_bits; 116 u8 access_freq; 117 u8 opt_mode; 118 u8 die_gap; 119 u8 bad_block_mode; 120 u8 multi_plane_mode; 121 u8 reversd2[6]; /* 32 bytes */ 122 }; 123 124 struct FLASH_INFO_T { 125 u16 block_size; 126 u8 ecc_bits; 127 u32 flash_size; 128 u16 page_size; 129 u8 access_time; 130 u8 manufacturer_name; 131 u8 flash_mask; 132 }; 133 134 extern struct nand_phy_info g_nand_phy_info; 135 extern struct nand_ops g_nand_ops; 136 extern void __iomem *nandc_base; 137 138 void nandc_flash_get_id(u8 cs, void *buf); 139 void nandc_flash_reset(u8 chip_sel); 140 u32 nandc_flash_init(void __iomem *nandc_addr); 141 u32 nandc_flash_deinit(void); 142 143 #endif 144