mmc.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /*
  2. * MMC definitions
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 as
  5. * published by the Free Software Foundation.
  6. */
  7. #ifndef __AML_MMC_H__
  8. #define __AML_MMC_H__
  9. #include <linux/types.h>
  10. #include <linux/device.h>
  11. #include <linux/mmc/host.h>
  12. enum aml_mmc_waitfor {
  13. COMPLETION_NONE,
  14. COMPLETION_FINALIZE,
  15. COMPLETION_CMDSENT,
  16. COMPLETION_RSPFIN,
  17. COMPLETION_XFERFINISH,
  18. COMPLETION_XFERFINISH_RSPFIN,
  19. };
  20. struct aml_sd_host;
  21. struct aml_mmc_platform_data {
  22. unsigned int no_wprotect : 1;
  23. unsigned int no_detect : 1;
  24. unsigned int wprotect_invert : 1;
  25. unsigned int detect_invert : 1; /* set => detect active high. */
  26. unsigned int use_dma : 1;
  27. unsigned int gpio_detect;
  28. unsigned int gpio_wprotect;
  29. unsigned long ocr_avail;
  30. int sdio_port;
  31. unsigned int max_width;
  32. unsigned int host_caps;
  33. unsigned int f_min;
  34. unsigned int f_max;
  35. unsigned int clock;
  36. unsigned int max_blk_count;
  37. unsigned int max_blk_size;
  38. unsigned int max_req_size;
  39. unsigned int max_seg_size;
  40. int (*sdio_init)(struct aml_sd_host * host);
  41. int (*sdio_detect)(struct aml_sd_host * host);
  42. void (*sdio_pwr_prepare)(unsigned port);
  43. void (*sdio_pwr_on)(unsigned port);
  44. void (*sdio_pwr_off)(unsigned port);
  45. };
  46. struct aml_sd_host {
  47. /* back-link to device */
  48. struct device *dev;
  49. struct aml_mmc_platform_data * pdata;
  50. struct mmc_host *mmc;
  51. struct resource *mem;
  52. struct clk *clk;
  53. void __iomem *base;
  54. int irq;
  55. int irq_cd;
  56. int dma;
  57. unsigned long clk_rate;
  58. int dodma;
  59. int dmatogo;
  60. bool irq_disabled;
  61. bool irq_enabled;
  62. bool irq_state;
  63. int sdio_irqen;
  64. struct mmc_request *mrq;
  65. int cmd_is_stop;
  66. spinlock_t complete_lock;
  67. enum aml_mmc_waitfor complete_what;
  68. int dma_complete;
  69. u32 pio_sgptr;
  70. u32 pio_bytes;
  71. u32 pio_count;
  72. u32 *pio_ptr;
  73. #define XFER_NONE 0
  74. #define XFER_READ 1
  75. #define XFER_WRITE 2
  76. u32 pio_active;
  77. int bus_width;
  78. int sdio_port;
  79. int locked;
  80. char dbgmsg_cmd[301];
  81. char dbgmsg_dat[301];
  82. char *status;
  83. unsigned int ccnt, dcnt;
  84. struct tasklet_struct pio_tasklet;
  85. #ifdef CONFIG_DEBUG_FS
  86. struct dentry *debug_root;
  87. struct dentry *debug_state;
  88. struct dentry *debug_regs;
  89. #endif
  90. #ifdef CONFIG_CPU_FREQ
  91. struct notifier_block freq_transition;
  92. #endif
  93. };
  94. #ifdef CONFIG_MMC_AML
  95. typedef struct SDHW_CMD_Argument_Reg
  96. {
  97. unsigned int arg;
  98. } SDHW_CMD_Argument_Reg_t;
  99. typedef struct SDHW_CMD_Send_Reg
  100. {
  101. unsigned cmd_data: 8; // Bit 7:0
  102. unsigned cmd_res_bits: 8; // Bit 15:8
  103. unsigned res_without_crc7: 1; // Bit 16
  104. unsigned res_with_data: 1; // Bit 17
  105. unsigned res_crc7_from_8: 1; // Bit 18
  106. unsigned check_dat0_busy: 1; // Bit 19
  107. unsigned cmd_send_data: 1; // Bit 20
  108. unsigned use_int_window: 1; // Bit 21
  109. unsigned reserved: 2; // Bit 22:23
  110. unsigned repeat_package_times: 8; // Bit 31:24
  111. } SDHW_CMD_Send_Reg_t;
  112. typedef struct SDIO_Config_Reg
  113. {
  114. unsigned cmd_clk_divide: 10; // Bit 9:0
  115. unsigned cmd_disable_crc: 1; // Bit 10
  116. unsigned cmd_out_at_posedge: 1; // Bit 11
  117. unsigned cmd_argument_bits: 6; // Bit 17:12
  118. unsigned res_latch_at_negedge: 1; // Bit 18
  119. unsigned data_latch_at_negedge: 1; // Bit 19
  120. unsigned bus_width: 1; // Bit 20
  121. unsigned m_endian: 2; // Bit 22:21
  122. unsigned write_Nwr: 6; // Bit 28:23
  123. unsigned write_crc_ok_status: 3; // Bit 31:29
  124. } SDIO_Config_Reg_t;
  125. typedef struct SDIO_Status_IRQ_Reg
  126. {
  127. unsigned status: 4; // Bit 3:0
  128. unsigned cmd_busy: 1; // Bit 4
  129. unsigned res_crc7_ok: 1; // Bit 5
  130. unsigned data_read_crc16_ok: 1; // Bit 6
  131. unsigned data_write_crc16_ok: 1; // Bit 7
  132. unsigned if_int: 1; // Bit 8
  133. unsigned cmd_int: 1; // Bit 9
  134. unsigned soft_int: 1; // Bit 10
  135. unsigned set_soft_int: 1; // Bit 11
  136. unsigned status_info: 4; // Bit 15:12
  137. unsigned timing_out_int: 1; // Bit 16
  138. unsigned amrisc_timing_out_int_en:1; // Bit 17
  139. unsigned arc_timing_out_int_en: 1; // Bit 18
  140. unsigned timing_out_count: 13; // Bit 31:19
  141. } SDIO_Status_IRQ_Reg_t;
  142. typedef struct SDHW_IRQ_Config_Reg
  143. {
  144. unsigned amrisc_if_int_en: 1; // Bit 0
  145. unsigned amrisc_cmd_int_en: 1; // Bit 1
  146. unsigned amrisc_soft_int_en: 1; // Bit 2
  147. unsigned arc_if_int_en: 1; // Bit 3
  148. unsigned arc_cmd_int_en: 1; // Bit 4
  149. unsigned arc_soft_int_en: 1; // Bit 5
  150. unsigned if_int_config: 2; // Bit 7:6
  151. unsigned data: 6; // Bit 13:8
  152. unsigned force_enable: 1; // Bit 14
  153. unsigned soft_reset: 1; // Bit 15
  154. unsigned force_output_en: 6; // Bit 21:16
  155. unsigned diable_mem_halt: 2; // Bit 23:22
  156. unsigned force_data_read: 6; // Bit 29:24
  157. unsigned force_halt: 1; // Bit 30
  158. unsigned halt_hole:1; // Bit 31
  159. } SDHW_IRQ_Config_Reg_t;
  160. typedef struct MSHW_IRQ_Config_Reg
  161. {
  162. unsigned amrisc_if_int_en: 1; // Bit 0
  163. unsigned amrisc_cmd_int_en: 1; // Bit 1
  164. unsigned amrisc_soft_int_en: 1; // Bit 2
  165. unsigned arc_if_int_en: 1; // Bit 3
  166. unsigned arc_cmd_int_en: 1; // Bit 4
  167. unsigned arc_soft_int_en: 1; // Bit 5
  168. unsigned if_int_config: 2; // Bit 7:6
  169. unsigned data0: 1; // Bit 8
  170. unsigned data1: 1; // Bit 9
  171. unsigned data2: 1; // Bit 10
  172. unsigned data3: 1; // Bit 11
  173. unsigned bs: 1; // Bit 12
  174. unsigned sclk: 1; // Bit 13
  175. unsigned force_enable: 1; // Bit 14
  176. unsigned soft_reset: 1; // Bit 15
  177. unsigned force_output_en: 6; // Bit 21:16
  178. unsigned diable_mem_halt: 2; // Bit 23:22
  179. unsigned force_data_read: 6; // Bit 29:24
  180. unsigned force_halt: 1; // Bit 30
  181. unsigned halt_hole:1; // Bit 31
  182. } MSHW_IRQ_Config_Reg_t;
  183. typedef struct SDIO_Multi_Config_Reg
  184. {
  185. unsigned port_sel: 2; // Bit 1:0
  186. unsigned ms_enable: 1; // Bit 2
  187. unsigned ms_sclk_always: 1; // Bit 3
  188. unsigned stream_enable: 1; // Bit 4
  189. unsigned stream_8_bits_mode: 1; // Bit 5
  190. unsigned data_catch_level: 2; // Bit 7:6
  191. unsigned write_read_out_index: 1; // Bit 8
  192. unsigned data_catch_out_en: 1; // Bit 9
  193. unsigned reserved: 2; // Bit 11:10
  194. unsigned res_read_index: 4; // Bit 15:12
  195. unsigned data_catch_finish_point: 12; // Bit 27:16
  196. unsigned reserved1: 4; // Bit 31:28
  197. } SDIO_Multi_Config_Reg_t;
  198. typedef struct SDIO_M_Addr_Reg
  199. {
  200. unsigned int m_addr;
  201. } SDIO_M_Addr_Reg_t;
  202. typedef struct SDHW_Extension_Reg
  203. {
  204. unsigned cmd_arg_ext: 16; // Bit 15:0
  205. unsigned data_rw_number: 14; // Bit 29:16
  206. unsigned data_rw_without_crc16: 1; // Bit 30
  207. unsigned crc_status_4line: 1; // Bit 31
  208. } SDHW_Extension_Reg_t;
  209. //LSB -> MSB, structrue for SD Card Status
  210. typedef struct _SD_Card_Status
  211. {
  212. unsigned Reserved3: 2;
  213. unsigned Reserved4: 1;
  214. unsigned AKE_SEQ_ERROR: 1; //Error in the sequence of authentication process.
  215. unsigned Reserved5: 1;
  216. unsigned APP_CMD: 1; //The card will expect ACMD, or indication that the command has been interpreted as ACMD.
  217. unsigned NotUsed: 2;
  218. unsigned READY_FOR_DATA: 1; //Corresponds to buffer empty signalling on the bus.
  219. unsigned CURRENT_STATE: 4; //The state of the card when receiving the command.
  220. unsigned ERASE_RESET: 1; //An erase sequence was cleared beforem executing because an out of erase sequence command was received.
  221. unsigned CARD_ECC_DISABLED: 1; //The command has been executed without using the internal ECC.
  222. unsigned WP_ERASE_SKIP: 1; //Only partial address space was erased due to existing write protected blocks.
  223. unsigned CID_CSD_OVERWRITE: 1; //Can be either one of the following errors:
  224. unsigned Reserved1: 1;
  225. unsigned Reserved2: 1;
  226. unsigned ERROR: 1; //A general or an unknown error occurred during the operation.
  227. unsigned CC_ERROR: 1; //Internal card controller error
  228. unsigned CARD_ECC_FAILED: 1; //Card internal ECC was applied but failed to correct the data.
  229. unsigned ILLEGAL_COMMAND: 1; //Command not legal for the card state
  230. unsigned COM_CRC_ERROR: 1; //The CRC check of the previous command failed.
  231. unsigned LOCK_UNLOCK_FAILED: 1; //Set when a sequence or password error has been detected in lock/ unlock card command or if there was an attempt to access a locked card
  232. unsigned CARD_IS_LOCKED: 1; //When set, signals that the card is locked by the host
  233. unsigned WP_VIOLATION: 1; //Attempt to program a write-protected block.
  234. unsigned ERASE_PARAM: 1; //An invalid selection of write-blocks for erase occurred.
  235. unsigned ERASE_SEQ_ERROR: 1; //An error in the sequence of erase commands occurred.
  236. unsigned BLOCK_LEN_ERROR: 1; //The transferred block length is not allowed for this card, or the number of transferred bytes does not match the block length.
  237. unsigned ADDRESS_ERROR: 1; //A misaligned address that did not match the block length was used in the command.
  238. unsigned OUT_OF_RANGE: 1; //The command??s argument was out of the allowed range for this card.
  239. } SD_Card_Status_t;
  240. //structure for response
  241. typedef struct _SD_Response_R1
  242. {
  243. SD_Card_Status_t card_status; //card status
  244. } SD_Response_R1_t;
  245. typedef enum _SD_Error_Status_t {
  246. SD_NO_ERROR = 0,
  247. SD_ERROR_OUT_OF_RANGE, //Bit 31
  248. SD_ERROR_ADDRESS, //Bit 30
  249. SD_ERROR_BLOCK_LEN, //Bit 29
  250. SD_ERROR_ERASE_SEQ, //Bit 28
  251. SD_ERROR_ERASE_PARAM, //Bit 27
  252. SD_ERROR_WP_VIOLATION, //Bit 26
  253. SD_ERROR_CARD_IS_LOCKED, //Bit 25
  254. SD_ERROR_LOCK_UNLOCK_FAILED, //Bit 24
  255. SD_ERROR_COM_CRC, //Bit 23
  256. SD_ERROR_ILLEGAL_COMMAND, //Bit 22
  257. SD_ERROR_CARD_ECC_FAILED, //Bit 21
  258. SD_ERROR_CC, //Bit 20
  259. SD_ERROR_GENERAL, //Bit 19
  260. SD_ERROR_Reserved1, //Bit 18
  261. SD_ERROR_Reserved2, //Bit 17
  262. SD_ERROR_CID_CSD_OVERWRITE, //Bit 16
  263. SD_ERROR_AKE_SEQ, //Bit 03
  264. SD_ERROR_STATE_MISMATCH,
  265. SD_ERROR_HEADER_MISMATCH,
  266. SD_ERROR_DATA_CRC,
  267. SD_ERROR_TIMEOUT,
  268. SD_ERROR_DRIVER_FAILURE,
  269. SD_ERROR_WRITE_PROTECTED,
  270. SD_ERROR_NO_MEMORY,
  271. SD_ERROR_SWITCH_FUNCTION_COMUNICATION,
  272. SD_ERROR_NO_FUNCTION_SWITCH,
  273. SD_ERROR_NO_CARD_INS
  274. } SD_Error_Status_t;
  275. typedef enum _SD_Bus_Width
  276. {
  277. SD_BUS_SINGLE = 1, //only DAT0
  278. SD_BUS_WIDE = 4 //use DAT0-4
  279. } SD_Bus_Width_t;
  280. // for CMD_SEND
  281. #define repeat_package_times_bit 24
  282. #define use_int_window_bit 21
  283. #define use_int_window_bit 21
  284. #define cmd_send_data_bit 20
  285. #define check_busy_on_dat0_bit 19
  286. #define response_crc7_from_8_bit 18
  287. #define response_have_data_bit 17
  288. #define response_do_not_have_crc7_bit 16
  289. #define cmd_response_bits_bit 8
  290. #define cmd_command_bit 0
  291. // for SDIO_CONFIG
  292. #define sdio_write_CRC_ok_status_bit 29
  293. #define sdio_write_Nwr_bit 23
  294. #define m_endian_bit 21
  295. #define bus_width_bit 20 // 0 1-bit, 1-4bits
  296. #define data_latch_at_negedge_bit 19
  297. #define response_latch_at_negedge_bit 18
  298. #define cmd_argument_bits_bit 12
  299. #define cmd_out_at_posedge_bit 11
  300. #define cmd_disable_CRC_bit 10
  301. #define cmd_clk_divide_bit 0
  302. // SDIO_STATUS_IRQ
  303. #define sdio_timing_out_count_bit 19
  304. #define arc_timing_out_int_en_bit 18
  305. #define amrisc_timing_out_int_en_bit 17
  306. #define sdio_timing_out_int_bit 16
  307. #define sdio_status_info_bit 12
  308. #define sdio_set_soft_int_bit 11
  309. #define sdio_soft_int_bit 10
  310. #define sdio_cmd_int_bit 9
  311. #define sdio_if_int_bit 8
  312. #define sdio_data_write_crc16_ok_bit 7
  313. #define sdio_data_read_crc16_ok_bit 6
  314. #define sdio_cmd_crc7_ok_bit 5
  315. #define sdio_cmd_busy_bit 4
  316. #define sdio_status_bit 0
  317. // SDIO_IRQ_CONFIG
  318. #define force_halt_bit 30
  319. #define sdio_force_read_back_bit 24
  320. #define disable_mem_halt_bit 22
  321. #define sdio_force_output_en_bit 16
  322. #define soft_reset_bit 15
  323. #define sdio_force_enable_bit 14
  324. #define sdio_force_read_data_bit 8
  325. #define sdio_if_int_config_bit 6
  326. #define arc_soft_int_en_bit 5
  327. #define arc_cmd_int_en_bit 4
  328. #define arc_if_int_en_bit 3
  329. #define amrisc_soft_int_en_bit 2
  330. #define amrisc_cmd_int_en_bit 1
  331. #define amrisc_if_int_en_bit 0
  332. // for SDIO_MULT_CONFIG
  333. #define data_catch_finish_point_bit 16
  334. #define response_read_index_bit 12
  335. #define data_catch_readout_en_bit 9
  336. #define write_read_out_index_bit 8
  337. #define data_catch_level_bit 6
  338. #define stream_8_bits_mode_bit 5
  339. #define stream_enable_bit 4
  340. #define ms_sclk_always_bit 3
  341. #define ms_enable_bit_bit 2
  342. #define SDIO_port_sel_bit 0
  343. #define ERROR_NONE 0
  344. #define ERROR_GO_IDLE1 1
  345. #define ERROR_GO_IDLE2 2
  346. #define ERROR_APP55_1 3
  347. #define ERROR_ACMD41 4
  348. #define ERROR_APP55_2 5
  349. #define ERROR_VOLTAGE_VALIDATION 6
  350. #define ERROR_SEND_CID1 7
  351. #define ERROR_SEND_RELATIVE_ADDR 8
  352. #define ERROR_SEND_CID2 9
  353. #define ERROR_SELECT_CARD 10
  354. #define ERROR_APP55_RETRY3 11
  355. #define ERROR_SEND_SCR 12
  356. #define ERROR_READ_BLOCK 13
  357. #define ERROR_STOP_TRANSMISSION 14
  358. #define ERROR_MAGIC_WORDS 15
  359. #define ERROR_CMD1 16
  360. #define ERROR_MMC_SWITCH_BUS 17
  361. #define ERROR_COM_CRC 18
  362. #define ERROR_DATA_CRC 19
  363. #define CARD_TYPE_SD 0
  364. #define CARD_TYPE_SDHC 1
  365. #define CARD_TYPE_MMC 2
  366. #define CARD_TYPE_EMMC 3
  367. /* 250ms of timeout */
  368. #define CLK_DIV 250 /* (200/((31+1)*2)=0.390625MHz),this define is for SD_CLK in Card Identification Stage */
  369. #define VOLTAGE_VALIDATION_RETRY 0x8000
  370. #define TIMEOUT_SHORT (250*1000) /* 250ms */
  371. #define TIMEOUT_DATA (300*1000) /* 300ms (TIMEOUT_SHORT+ (READ_SIZE*8)/10000000) */
  372. #ifndef CONFIG_SDIO_BUFFER_SIZE
  373. #define CONFIG_SDIO_BUFFER_SIZE 64*1024
  374. #endif
  375. #define NO_DELAY_DATA 0
  376. //Misc definitions
  377. #define MAX_RESPONSE_BYTES 18
  378. #define RESPONSE_R1_R3_R6_R7_LENGTH 6
  379. #define RESPONSE_R2_CID_CSD_LENGTH 17
  380. #define RESPONSE_R4_R5_NONE_LENGTH 0
  381. #define OCR_HCS 0x40000000
  382. #define M3_SDIO_PORT_A 0
  383. #define M3_SDIO_PORT_B 1
  384. #define M3_SDIO_PORT_C 2
  385. #define M3_SDIO_PORT_XC_A 3
  386. #define M3_SDIO_PORT_XC_B 4
  387. #define M3_SDIO_PORT_XC_C 5
  388. #endif
  389. #endif