Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Handles the M-Systems DiskOnChip G3 chip
0004  *
0005  * Copyright (C) 2011 Robert Jarzmik
0006  */
0007 
0008 #ifndef _MTD_DOCG3_H
0009 #define _MTD_DOCG3_H
0010 
0011 #include <linux/mtd/mtd.h>
0012 
0013 /*
0014  * Flash memory areas :
0015  *   - 0x0000 .. 0x07ff : IPL
0016  *   - 0x0800 .. 0x0fff : Data area
0017  *   - 0x1000 .. 0x17ff : Registers
0018  *   - 0x1800 .. 0x1fff : Unknown
0019  */
0020 #define DOC_IOSPACE_IPL         0x0000
0021 #define DOC_IOSPACE_DATA        0x0800
0022 #define DOC_IOSPACE_SIZE        0x2000
0023 
0024 /*
0025  * DOC G3 layout and adressing scheme
0026  *   A page address for the block "b", plane "P" and page "p":
0027  *   address = [bbbb bPpp pppp]
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  * ECC related constants
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  * Blocks distribution
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  * Extra page OOB (16 bytes wide) layout
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  * Flash registers
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  * Flash sequences
0124  * A sequence is preset before one or more commands are input to the chip.
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  * Flash commands
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  * Flash register : DOC_FLASHCONTROL
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  * Flash register : DOC_ASICMODE
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  * Flash register : DOC_ECCCONF0
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  * Flash register : DOC_ECCCONF1
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  * Flash register : DOC_PROTECTION
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  * Flash register : DOC_DPS0_STATUS and DOC_DPS1_STATUS
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  * Flash register : DOC_CONFIGURATION
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  * Flash register : DOC_READADDRESS
0229  */
0230 #define DOC_READADDR_INC        0x8000
0231 #define DOC_READADDR_ONE_BYTE       0x4000
0232 #define DOC_READADDR_ADDR_MASK      0x1fff
0233 
0234 /*
0235  * Flash register : DOC_POWERMODE
0236  */
0237 #define DOC_POWERDOWN_READY     0x80
0238 
0239 /*
0240  * Status of erase and write operation
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  * DPS key management
0248  *
0249  * Each floor of docg3 has 2 protection areas: DPS0 and DPS1. These areas span
0250  * across block boundaries, and define whether these blocks can be read or
0251  * written.
0252  * The definition is dynamically stored in page 0 of blocks (2,3) for DPS0, and
0253  * page 0 of blocks (4,5) for DPS1.
0254  */
0255 #define DOC_LAYOUT_DPS_KEY_LENGTH   8
0256 
0257 /**
0258  * struct docg3_cascade - Cascade of 1 to 4 docg3 chips
0259  * @floors: floors (ie. one physical docg3 chip is one floor)
0260  * @base: IO space to access all chips in the cascade
0261  * @bch: the BCH correcting control structure
0262  * @lock: lock to protect docg3 IO space from concurrent accesses
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  * struct docg3 - DiskOnChip driver private data
0273  * @dev: the device currently under control
0274  * @cascade: the cascade this device belongs to
0275  * @device_id: number of the cascaded DoCG3 device (0, 1, 2 or 3)
0276  * @if_cfg: if true, reads are on 16bits, else reads are on 8bits
0277 
0278  * @reliable: if 0, docg3 in normal mode, if 1 docg3 in fast mode, if 2 in
0279  *            reliable mode
0280  *            Fast mode implies more errors than normal mode.
0281  *            Reliable mode implies that page 2*n and 2*n+1 are clones.
0282  * @bbt: bad block table cache
0283  * @oob_write_ofs: offset of the MTD where this OOB should belong (ie. in next
0284  *                 page_write)
0285  * @oob_autoecc: if 1, use only bytes 0-7, 15, and fill the others with HW ECC
0286  *               if 0, use all the 16 bytes.
0287  * @oob_write_buf: prepared OOB for next page_write
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  * Trace events part
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 /* This part must be outside protection */
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>