0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _MTD_DOCG3_H
0009 #define _MTD_DOCG3_H
0010
0011 #include <linux/mtd/mtd.h>
0012
0013
0014
0015
0016
0017
0018
0019
0020 #define DOC_IOSPACE_IPL 0x0000
0021 #define DOC_IOSPACE_DATA 0x0800
0022 #define DOC_IOSPACE_SIZE 0x2000
0023
0024
0025
0026
0027
0028
0029
0030 #define DOC_ADDR_PAGE_MASK 0x3f
0031 #define DOC_ADDR_BLOCK_SHIFT 6
0032 #define DOC_LAYOUT_NBPLANES 2
0033 #define DOC_LAYOUT_PAGES_PER_BLOCK 64
0034 #define DOC_LAYOUT_PAGE_SIZE 512
0035 #define DOC_LAYOUT_OOB_SIZE 16
0036 #define DOC_LAYOUT_WEAR_SIZE 8
0037 #define DOC_LAYOUT_PAGE_OOB_SIZE \
0038 (DOC_LAYOUT_PAGE_SIZE + DOC_LAYOUT_OOB_SIZE)
0039 #define DOC_LAYOUT_WEAR_OFFSET (DOC_LAYOUT_PAGE_OOB_SIZE * 2)
0040 #define DOC_LAYOUT_BLOCK_SIZE \
0041 (DOC_LAYOUT_PAGES_PER_BLOCK * DOC_LAYOUT_PAGE_SIZE)
0042
0043
0044
0045
0046 #define DOC_ECC_BCH_M 14
0047 #define DOC_ECC_BCH_T 4
0048 #define DOC_ECC_BCH_PRIMPOLY 0x4443
0049 #define DOC_ECC_BCH_SIZE 7
0050 #define DOC_ECC_BCH_COVERED_BYTES \
0051 (DOC_LAYOUT_PAGE_SIZE + DOC_LAYOUT_OOB_PAGEINFO_SZ + \
0052 DOC_LAYOUT_OOB_HAMMING_SZ)
0053 #define DOC_ECC_BCH_TOTAL_BYTES \
0054 (DOC_ECC_BCH_COVERED_BYTES + DOC_LAYOUT_OOB_BCH_SZ)
0055
0056
0057
0058
0059 #define DOC_LAYOUT_BLOCK_BBT 0
0060 #define DOC_LAYOUT_BLOCK_OTP 0
0061 #define DOC_LAYOUT_BLOCK_FIRST_DATA 6
0062
0063 #define DOC_LAYOUT_PAGE_BBT 4
0064
0065
0066
0067
0068 #define DOC_LAYOUT_OOB_PAGEINFO_OFS 0
0069 #define DOC_LAYOUT_OOB_HAMMING_OFS 7
0070 #define DOC_LAYOUT_OOB_BCH_OFS 8
0071 #define DOC_LAYOUT_OOB_UNUSED_OFS 15
0072 #define DOC_LAYOUT_OOB_PAGEINFO_SZ 7
0073 #define DOC_LAYOUT_OOB_HAMMING_SZ 1
0074 #define DOC_LAYOUT_OOB_BCH_SZ 7
0075 #define DOC_LAYOUT_OOB_UNUSED_SZ 1
0076
0077
0078 #define DOC_CHIPID_G3 0x200
0079 #define DOC_ERASE_MARK 0xaa
0080 #define DOC_MAX_NBFLOORS 4
0081
0082
0083
0084 #define DOC_CHIPID 0x1000
0085 #define DOC_TEST 0x1004
0086 #define DOC_BUSLOCK 0x1006
0087 #define DOC_ENDIANCONTROL 0x1008
0088 #define DOC_DEVICESELECT 0x100a
0089 #define DOC_ASICMODE 0x100c
0090 #define DOC_CONFIGURATION 0x100e
0091 #define DOC_INTERRUPTCONTROL 0x1010
0092 #define DOC_READADDRESS 0x101a
0093 #define DOC_DATAEND 0x101e
0094 #define DOC_INTERRUPTSTATUS 0x1020
0095
0096 #define DOC_FLASHSEQUENCE 0x1032
0097 #define DOC_FLASHCOMMAND 0x1034
0098 #define DOC_FLASHADDRESS 0x1036
0099 #define DOC_FLASHCONTROL 0x1038
0100 #define DOC_NOP 0x103e
0101
0102 #define DOC_ECCCONF0 0x1040
0103 #define DOC_ECCCONF1 0x1042
0104 #define DOC_ECCPRESET 0x1044
0105 #define DOC_HAMMINGPARITY 0x1046
0106 #define DOC_BCH_HW_ECC(idx) (0x1048 + idx)
0107
0108 #define DOC_PROTECTION 0x1056
0109 #define DOC_DPS0_KEY 0x105c
0110 #define DOC_DPS1_KEY 0x105e
0111 #define DOC_DPS0_ADDRLOW 0x1060
0112 #define DOC_DPS0_ADDRHIGH 0x1062
0113 #define DOC_DPS1_ADDRLOW 0x1064
0114 #define DOC_DPS1_ADDRHIGH 0x1066
0115 #define DOC_DPS0_STATUS 0x106c
0116 #define DOC_DPS1_STATUS 0x106e
0117
0118 #define DOC_ASICMODECONFIRM 0x1072
0119 #define DOC_CHIPID_INV 0x1074
0120 #define DOC_POWERMODE 0x107c
0121
0122
0123
0124
0125
0126 #define DOC_SEQ_RESET 0x00
0127 #define DOC_SEQ_PAGE_SIZE_532 0x03
0128 #define DOC_SEQ_SET_FASTMODE 0x05
0129 #define DOC_SEQ_SET_RELIABLEMODE 0x09
0130 #define DOC_SEQ_READ 0x12
0131 #define DOC_SEQ_SET_PLANE1 0x0e
0132 #define DOC_SEQ_SET_PLANE2 0x10
0133 #define DOC_SEQ_PAGE_SETUP 0x1d
0134 #define DOC_SEQ_ERASE 0x27
0135 #define DOC_SEQ_PLANES_STATUS 0x31
0136
0137
0138
0139
0140 #define DOC_CMD_READ_PLANE1 0x00
0141 #define DOC_CMD_SET_ADDR_READ 0x05
0142 #define DOC_CMD_READ_ALL_PLANES 0x30
0143 #define DOC_CMD_READ_PLANE2 0x50
0144 #define DOC_CMD_READ_FLASH 0xe0
0145 #define DOC_CMD_PAGE_SIZE_532 0x3c
0146
0147 #define DOC_CMD_PROG_BLOCK_ADDR 0x60
0148 #define DOC_CMD_PROG_CYCLE1 0x80
0149 #define DOC_CMD_PROG_CYCLE2 0x10
0150 #define DOC_CMD_PROG_CYCLE3 0x11
0151 #define DOC_CMD_ERASECYCLE2 0xd0
0152 #define DOC_CMD_READ_STATUS 0x70
0153 #define DOC_CMD_PLANES_STATUS 0x71
0154
0155 #define DOC_CMD_RELIABLE_MODE 0x22
0156 #define DOC_CMD_FAST_MODE 0xa2
0157
0158 #define DOC_CMD_RESET 0xff
0159
0160
0161
0162
0163 #define DOC_CTRL_VIOLATION 0x20
0164 #define DOC_CTRL_CE 0x10
0165 #define DOC_CTRL_UNKNOWN_BITS 0x08
0166 #define DOC_CTRL_PROTECTION_ERROR 0x04
0167 #define DOC_CTRL_SEQUENCE_ERROR 0x02
0168 #define DOC_CTRL_FLASHREADY 0x01
0169
0170
0171
0172
0173 #define DOC_ASICMODE_RESET 0x00
0174 #define DOC_ASICMODE_NORMAL 0x01
0175 #define DOC_ASICMODE_POWERDOWN 0x02
0176 #define DOC_ASICMODE_MDWREN 0x04
0177 #define DOC_ASICMODE_BDETCT_RESET 0x08
0178 #define DOC_ASICMODE_RSTIN_RESET 0x10
0179 #define DOC_ASICMODE_RAM_WE 0x20
0180
0181
0182
0183
0184 #define DOC_ECCCONF0_WRITE_MODE 0x0000
0185 #define DOC_ECCCONF0_READ_MODE 0x8000
0186 #define DOC_ECCCONF0_AUTO_ECC_ENABLE 0x4000
0187 #define DOC_ECCCONF0_HAMMING_ENABLE 0x1000
0188 #define DOC_ECCCONF0_BCH_ENABLE 0x0800
0189 #define DOC_ECCCONF0_DATA_BYTES_MASK 0x07ff
0190
0191
0192
0193
0194 #define DOC_ECCCONF1_BCH_SYNDROM_ERR 0x80
0195 #define DOC_ECCCONF1_UNKOWN1 0x40
0196 #define DOC_ECCCONF1_PAGE_IS_WRITTEN 0x20
0197 #define DOC_ECCCONF1_UNKOWN3 0x10
0198 #define DOC_ECCCONF1_HAMMING_BITS_MASK 0x0f
0199
0200
0201
0202
0203 #define DOC_PROTECT_FOUNDRY_OTP_LOCK 0x01
0204 #define DOC_PROTECT_CUSTOMER_OTP_LOCK 0x02
0205 #define DOC_PROTECT_LOCK_INPUT 0x04
0206 #define DOC_PROTECT_STICKY_LOCK 0x08
0207 #define DOC_PROTECT_PROTECTION_ENABLED 0x10
0208 #define DOC_PROTECT_IPL_DOWNLOAD_LOCK 0x20
0209 #define DOC_PROTECT_PROTECTION_ERROR 0x80
0210
0211
0212
0213
0214 #define DOC_DPS_OTP_PROTECTED 0x01
0215 #define DOC_DPS_READ_PROTECTED 0x02
0216 #define DOC_DPS_WRITE_PROTECTED 0x04
0217 #define DOC_DPS_HW_LOCK_ENABLED 0x08
0218 #define DOC_DPS_KEY_OK 0x80
0219
0220
0221
0222
0223 #define DOC_CONF_IF_CFG 0x80
0224 #define DOC_CONF_MAX_ID_MASK 0x30
0225 #define DOC_CONF_VCCQ_3V 0x01
0226
0227
0228
0229
0230 #define DOC_READADDR_INC 0x8000
0231 #define DOC_READADDR_ONE_BYTE 0x4000
0232 #define DOC_READADDR_ADDR_MASK 0x1fff
0233
0234
0235
0236
0237 #define DOC_POWERDOWN_READY 0x80
0238
0239
0240
0241
0242 #define DOC_PLANES_STATUS_FAIL 0x01
0243 #define DOC_PLANES_STATUS_PLANE0_KO 0x02
0244 #define DOC_PLANES_STATUS_PLANE1_KO 0x04
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255 #define DOC_LAYOUT_DPS_KEY_LENGTH 8
0256
0257
0258
0259
0260
0261
0262
0263
0264 struct docg3_cascade {
0265 struct mtd_info *floors[DOC_MAX_NBFLOORS];
0266 void __iomem *base;
0267 struct bch_control *bch;
0268 struct mutex lock;
0269 };
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289 struct docg3 {
0290 struct device *dev;
0291 struct docg3_cascade *cascade;
0292 unsigned int device_id:4;
0293 unsigned int if_cfg:1;
0294 unsigned int reliable:2;
0295 int max_block;
0296 u8 *bbt;
0297 loff_t oob_write_ofs;
0298 int oob_autoecc;
0299 u8 oob_write_buf[DOC_LAYOUT_OOB_SIZE];
0300 };
0301
0302 #define doc_err(fmt, arg...) dev_err(docg3->dev, (fmt), ## arg)
0303 #define doc_info(fmt, arg...) dev_info(docg3->dev, (fmt), ## arg)
0304 #define doc_dbg(fmt, arg...) dev_dbg(docg3->dev, (fmt), ## arg)
0305 #define doc_vdbg(fmt, arg...) dev_vdbg(docg3->dev, (fmt), ## arg)
0306 #endif
0307
0308
0309
0310
0311 #undef TRACE_SYSTEM
0312 #define TRACE_SYSTEM docg3
0313
0314 #if !defined(_MTD_DOCG3_TRACE) || defined(TRACE_HEADER_MULTI_READ)
0315 #define _MTD_DOCG3_TRACE
0316
0317 #include <linux/tracepoint.h>
0318
0319 TRACE_EVENT(docg3_io,
0320 TP_PROTO(int op, int width, u16 reg, int val),
0321 TP_ARGS(op, width, reg, val),
0322 TP_STRUCT__entry(
0323 __field(int, op)
0324 __field(unsigned char, width)
0325 __field(u16, reg)
0326 __field(int, val)),
0327 TP_fast_assign(
0328 __entry->op = op;
0329 __entry->width = width;
0330 __entry->reg = reg;
0331 __entry->val = val;),
0332 TP_printk("docg3: %s%02d reg=%04x, val=%04x",
0333 __entry->op ? "write" : "read", __entry->width,
0334 __entry->reg, __entry->val)
0335 );
0336 #endif
0337
0338
0339 #undef TRACE_INCLUDE_PATH
0340 #undef TRACE_INCLUDE_FILE
0341 #define TRACE_INCLUDE_PATH .
0342 #define TRACE_INCLUDE_FILE docg3
0343 #include <trace/define_trace.h>