docg3.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * Handles the M-Systems DiskOnChip G3 chip
  3. *
  4. * Copyright (C) 2011 Robert Jarzmik
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #ifndef _MTD_DOCG3_H
  22. #define _MTD_DOCG3_H
  23. /*
  24. * Flash memory areas :
  25. * - 0x0000 .. 0x07ff : IPL
  26. * - 0x0800 .. 0x0fff : Data area
  27. * - 0x1000 .. 0x17ff : Registers
  28. * - 0x1800 .. 0x1fff : Unknown
  29. */
  30. #define DOC_IOSPACE_IPL 0x0000
  31. #define DOC_IOSPACE_DATA 0x0800
  32. #define DOC_IOSPACE_SIZE 0x2000
  33. /*
  34. * DOC G3 layout and adressing scheme
  35. * A page address for the block "b", plane "P" and page "p":
  36. * address = [bbbb bPpp pppp]
  37. */
  38. #define DOC_ADDR_PAGE_MASK 0x3f
  39. #define DOC_ADDR_BLOCK_SHIFT 6
  40. #define DOC_LAYOUT_NBPLANES 2
  41. #define DOC_LAYOUT_PAGES_PER_BLOCK 64
  42. #define DOC_LAYOUT_PAGE_SIZE 512
  43. #define DOC_LAYOUT_OOB_SIZE 16
  44. #define DOC_LAYOUT_WEAR_SIZE 8
  45. #define DOC_LAYOUT_PAGE_OOB_SIZE \
  46. (DOC_LAYOUT_PAGE_SIZE + DOC_LAYOUT_OOB_SIZE)
  47. #define DOC_LAYOUT_WEAR_OFFSET (DOC_LAYOUT_PAGE_OOB_SIZE * 2)
  48. #define DOC_LAYOUT_BLOCK_SIZE \
  49. (DOC_LAYOUT_PAGES_PER_BLOCK * DOC_LAYOUT_PAGE_SIZE)
  50. #define DOC_ECC_BCH_SIZE 7
  51. #define DOC_ECC_BCH_COVERED_BYTES \
  52. (DOC_LAYOUT_PAGE_SIZE + DOC_LAYOUT_OOB_PAGEINFO_SZ + \
  53. DOC_LAYOUT_OOB_HAMMING_SZ + DOC_LAYOUT_OOB_BCH_SZ)
  54. /*
  55. * Blocks distribution
  56. */
  57. #define DOC_LAYOUT_BLOCK_BBT 0
  58. #define DOC_LAYOUT_BLOCK_OTP 0
  59. #define DOC_LAYOUT_BLOCK_FIRST_DATA 6
  60. #define DOC_LAYOUT_PAGE_BBT 4
  61. /*
  62. * Extra page OOB (16 bytes wide) layout
  63. */
  64. #define DOC_LAYOUT_OOB_PAGEINFO_OFS 0
  65. #define DOC_LAYOUT_OOB_HAMMING_OFS 7
  66. #define DOC_LAYOUT_OOB_BCH_OFS 8
  67. #define DOC_LAYOUT_OOB_UNUSED_OFS 15
  68. #define DOC_LAYOUT_OOB_PAGEINFO_SZ 7
  69. #define DOC_LAYOUT_OOB_HAMMING_SZ 1
  70. #define DOC_LAYOUT_OOB_BCH_SZ 7
  71. #define DOC_LAYOUT_OOB_UNUSED_SZ 1
  72. #define DOC_CHIPID_G3 0x200
  73. #define DOC_ERASE_MARK 0xaa
  74. /*
  75. * Flash registers
  76. */
  77. #define DOC_CHIPID 0x1000
  78. #define DOC_TEST 0x1004
  79. #define DOC_BUSLOCK 0x1006
  80. #define DOC_ENDIANCONTROL 0x1008
  81. #define DOC_DEVICESELECT 0x100a
  82. #define DOC_ASICMODE 0x100c
  83. #define DOC_CONFIGURATION 0x100e
  84. #define DOC_INTERRUPTCONTROL 0x1010
  85. #define DOC_READADDRESS 0x101a
  86. #define DOC_DATAEND 0x101e
  87. #define DOC_INTERRUPTSTATUS 0x1020
  88. #define DOC_FLASHSEQUENCE 0x1032
  89. #define DOC_FLASHCOMMAND 0x1034
  90. #define DOC_FLASHADDRESS 0x1036
  91. #define DOC_FLASHCONTROL 0x1038
  92. #define DOC_NOP 0x103e
  93. #define DOC_ECCCONF0 0x1040
  94. #define DOC_ECCCONF1 0x1042
  95. #define DOC_ECCPRESET 0x1044
  96. #define DOC_HAMMINGPARITY 0x1046
  97. #define DOC_BCH_SYNDROM(idx) (0x1048 + (idx << 1))
  98. #define DOC_PROTECTION 0x1056
  99. #define DOC_DPS0_ADDRLOW 0x1060
  100. #define DOC_DPS0_ADDRHIGH 0x1062
  101. #define DOC_DPS1_ADDRLOW 0x1064
  102. #define DOC_DPS1_ADDRHIGH 0x1066
  103. #define DOC_DPS0_STATUS 0x106c
  104. #define DOC_DPS1_STATUS 0x106e
  105. #define DOC_ASICMODECONFIRM 0x1072
  106. #define DOC_CHIPID_INV 0x1074
  107. /*
  108. * Flash sequences
  109. * A sequence is preset before one or more commands are input to the chip.
  110. */
  111. #define DOC_SEQ_RESET 0x00
  112. #define DOC_SEQ_PAGE_SIZE_532 0x03
  113. #define DOC_SEQ_SET_MODE 0x09
  114. #define DOC_SEQ_READ 0x12
  115. #define DOC_SEQ_SET_PLANE1 0x0e
  116. #define DOC_SEQ_SET_PLANE2 0x10
  117. #define DOC_SEQ_PAGE_SETUP 0x1d
  118. /*
  119. * Flash commands
  120. */
  121. #define DOC_CMD_READ_PLANE1 0x00
  122. #define DOC_CMD_SET_ADDR_READ 0x05
  123. #define DOC_CMD_READ_ALL_PLANES 0x30
  124. #define DOC_CMD_READ_PLANE2 0x50
  125. #define DOC_CMD_READ_FLASH 0xe0
  126. #define DOC_CMD_PAGE_SIZE_532 0x3c
  127. #define DOC_CMD_PROG_BLOCK_ADDR 0x60
  128. #define DOC_CMD_PROG_CYCLE1 0x80
  129. #define DOC_CMD_PROG_CYCLE2 0x10
  130. #define DOC_CMD_ERASECYCLE2 0xd0
  131. #define DOC_CMD_RELIABLE_MODE 0x22
  132. #define DOC_CMD_FAST_MODE 0xa2
  133. #define DOC_CMD_RESET 0xff
  134. /*
  135. * Flash register : DOC_FLASHCONTROL
  136. */
  137. #define DOC_CTRL_VIOLATION 0x20
  138. #define DOC_CTRL_CE 0x10
  139. #define DOC_CTRL_UNKNOWN_BITS 0x08
  140. #define DOC_CTRL_PROTECTION_ERROR 0x04
  141. #define DOC_CTRL_SEQUENCE_ERROR 0x02
  142. #define DOC_CTRL_FLASHREADY 0x01
  143. /*
  144. * Flash register : DOC_ASICMODE
  145. */
  146. #define DOC_ASICMODE_RESET 0x00
  147. #define DOC_ASICMODE_NORMAL 0x01
  148. #define DOC_ASICMODE_POWERDOWN 0x02
  149. #define DOC_ASICMODE_MDWREN 0x04
  150. #define DOC_ASICMODE_BDETCT_RESET 0x08
  151. #define DOC_ASICMODE_RSTIN_RESET 0x10
  152. #define DOC_ASICMODE_RAM_WE 0x20
  153. /*
  154. * Flash register : DOC_ECCCONF0
  155. */
  156. #define DOC_ECCCONF0_READ_MODE 0x8000
  157. #define DOC_ECCCONF0_AUTO_ECC_ENABLE 0x4000
  158. #define DOC_ECCCONF0_HAMMING_ENABLE 0x1000
  159. #define DOC_ECCCONF0_BCH_ENABLE 0x0800
  160. #define DOC_ECCCONF0_DATA_BYTES_MASK 0x07ff
  161. /*
  162. * Flash register : DOC_ECCCONF1
  163. */
  164. #define DOC_ECCCONF1_BCH_SYNDROM_ERR 0x80
  165. #define DOC_ECCCONF1_UNKOWN1 0x40
  166. #define DOC_ECCCONF1_UNKOWN2 0x20
  167. #define DOC_ECCCONF1_UNKOWN3 0x10
  168. #define DOC_ECCCONF1_HAMMING_BITS_MASK 0x0f
  169. /*
  170. * Flash register : DOC_PROTECTION
  171. */
  172. #define DOC_PROTECT_FOUNDRY_OTP_LOCK 0x01
  173. #define DOC_PROTECT_CUSTOMER_OTP_LOCK 0x02
  174. #define DOC_PROTECT_LOCK_INPUT 0x04
  175. #define DOC_PROTECT_STICKY_LOCK 0x08
  176. #define DOC_PROTECT_PROTECTION_ENABLED 0x10
  177. #define DOC_PROTECT_IPL_DOWNLOAD_LOCK 0x20
  178. #define DOC_PROTECT_PROTECTION_ERROR 0x80
  179. /*
  180. * Flash register : DOC_DPS0_STATUS and DOC_DPS1_STATUS
  181. */
  182. #define DOC_DPS_OTP_PROTECTED 0x01
  183. #define DOC_DPS_READ_PROTECTED 0x02
  184. #define DOC_DPS_WRITE_PROTECTED 0x04
  185. #define DOC_DPS_HW_LOCK_ENABLED 0x08
  186. #define DOC_DPS_KEY_OK 0x80
  187. /*
  188. * Flash register : DOC_CONFIGURATION
  189. */
  190. #define DOC_CONF_IF_CFG 0x80
  191. #define DOC_CONF_MAX_ID_MASK 0x30
  192. #define DOC_CONF_VCCQ_3V 0x01
  193. /*
  194. * Flash register : DOC_READADDRESS
  195. */
  196. #define DOC_READADDR_INC 0x8000
  197. #define DOC_READADDR_ONE_BYTE 0x4000
  198. #define DOC_READADDR_ADDR_MASK 0x1fff
  199. /**
  200. * struct docg3 - DiskOnChip driver private data
  201. * @dev: the device currently under control
  202. * @base: mapped IO space
  203. * @device_id: number of the cascaded DoCG3 device (0, 1, 2 or 3)
  204. * @if_cfg: if true, reads are on 16bits, else reads are on 8bits
  205. * @bbt: bad block table cache
  206. * @debugfs_root: debugfs root node
  207. */
  208. struct docg3 {
  209. struct device *dev;
  210. void __iomem *base;
  211. unsigned int device_id:4;
  212. unsigned int if_cfg:1;
  213. int max_block;
  214. u8 *bbt;
  215. struct dentry *debugfs_root;
  216. };
  217. #define doc_err(fmt, arg...) dev_err(docg3->dev, (fmt), ## arg)
  218. #define doc_info(fmt, arg...) dev_info(docg3->dev, (fmt), ## arg)
  219. #define doc_dbg(fmt, arg...) dev_dbg(docg3->dev, (fmt), ## arg)
  220. #define doc_vdbg(fmt, arg...) dev_vdbg(docg3->dev, (fmt), ## arg)
  221. #define DEBUGFS_RO_ATTR(name, show_fct) \
  222. static int name##_open(struct inode *inode, struct file *file) \
  223. { return single_open(file, show_fct, inode->i_private); } \
  224. static const struct file_operations name##_fops = { \
  225. .owner = THIS_MODULE, \
  226. .open = name##_open, \
  227. .llseek = seq_lseek, \
  228. .read = seq_read, \
  229. .release = single_release \
  230. };
  231. #endif
  232. /*
  233. * Trace events part
  234. */
  235. #undef TRACE_SYSTEM
  236. #define TRACE_SYSTEM docg3
  237. #if !defined(_MTD_DOCG3_TRACE) || defined(TRACE_HEADER_MULTI_READ)
  238. #define _MTD_DOCG3_TRACE
  239. #include <linux/tracepoint.h>
  240. TRACE_EVENT(docg3_io,
  241. TP_PROTO(int op, int width, u16 reg, int val),
  242. TP_ARGS(op, width, reg, val),
  243. TP_STRUCT__entry(
  244. __field(int, op)
  245. __field(unsigned char, width)
  246. __field(u16, reg)
  247. __field(int, val)),
  248. TP_fast_assign(
  249. __entry->op = op;
  250. __entry->width = width;
  251. __entry->reg = reg;
  252. __entry->val = val;),
  253. TP_printk("docg3: %s%02d reg=%04x, val=%04x",
  254. __entry->op ? "write" : "read", __entry->width,
  255. __entry->reg, __entry->val)
  256. );
  257. #endif
  258. /* This part must be outside protection */
  259. #undef TRACE_INCLUDE_PATH
  260. #undef TRACE_INCLUDE_FILE
  261. #define TRACE_INCLUDE_PATH .
  262. #define TRACE_INCLUDE_FILE docg3
  263. #include <trace/define_trace.h>