ms_mspro.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #ifndef _H_MS_MSPRO
  2. #define _H_MS_MSPRO
  3. #include <linux/slab.h>
  4. #include <linux/types.h>
  5. #include <linux/cardreader/card_block.h>
  6. #include <linux/cardreader/cardreader.h>
  7. #include <linux/cardreader/sdio_hw.h>
  8. #include <mach/card_io.h>
  9. #include "ms_protocol.h"
  10. #pragma pack(1)
  11. typedef struct _MS_MSPRO_INT_Register {
  12. unsigned CMDNK:1; //D0: Command Nack
  13. unsigned Reserved1:1; //D1
  14. unsigned Reserved2:1; //D2
  15. unsigned Reserved3:1; //D3
  16. unsigned Reserved4:1; //D4
  17. unsigned BREQ:1; //D5: Buffer Request
  18. unsigned ERR:1; //D6: Error
  19. unsigned CED:1; //D7: Command End
  20. } MS_MSPRO_INT_Register_t;
  21. typedef struct _MS_MSPRO_TPC_Packet {
  22. union {
  23. unsigned long value;
  24. struct {
  25. unsigned check_code:4;
  26. unsigned code:4;
  27. } format;
  28. struct {
  29. unsigned noname1:3;
  30. unsigned bRead:1;
  31. unsigned noname2:3;
  32. unsigned bWrite:1;
  33. } trans_dir;
  34. } TPC_cmd;
  35. union {
  36. struct {
  37. unsigned long count;
  38. unsigned char *buffer;
  39. } in;
  40. struct {
  41. unsigned long count;
  42. unsigned char *buffer;
  43. } out;
  44. } param;
  45. unsigned char int_reg;
  46. } MS_MSPRO_TPC_Packet_t;
  47. typedef struct _MS_MSPRO_Reg_Set {
  48. unsigned char read_addr;
  49. unsigned char read_size;
  50. unsigned char write_addr;
  51. unsigned char write_size;
  52. } MS_MSPRO_Reg_Set_t;
  53. #pragma pack()
  54. typedef enum _MS_MSPRO_Card_Type
  55. {
  56. CARD_NONE_TYPE = 0,
  57. CARD_TYPE_MS,
  58. CARD_TYPE_MSPRO
  59. } MS_MSPRO_Card_Type_t;
  60. typedef enum _MS_MSPRO_Interface_Mode
  61. {
  62. INTERFACE_SERIAL = 1,
  63. INTERFACE_PARALLEL = 4
  64. } MS_MSPRO_Interface_Mode_t;
  65. typedef enum _MS_MSPRO_Error_Status
  66. {
  67. MS_MSPRO_NO_ERROR =0,
  68. MS_MSPRO_ERROR_TPC_FORMAT,
  69. MS_MSPRO_ERROR_RDY_TIMEOUT,
  70. MS_MSPRO_ERROR_INT_TIMEOUT,
  71. MS_MSPRO_ERROR_DATA_CRC,
  72. MS_MSPRO_ERROR_MEDIA_TYPE,
  73. MS_MSPRO_ERROR_CMDNK,
  74. MS_MSPRO_ERROR_CED,
  75. MS_MSPRO_ERROR_FLASH_READ,
  76. MS_MSPRO_ERROR_FLASH_WRITE,
  77. MS_MSPRO_ERROR_FLASH_ERASE,
  78. MS_MSPRO_ERROR_PARAMETER,
  79. MS_MSPRO_ERROR_WRITE_PROTECTED,
  80. MS_MSPRO_ERROR_READ_ONLY,
  81. MS_ERROR_BOOT_SEARCH,
  82. MS_ERROR_MEMORY_STICK_TYPE,
  83. MS_ERROR_FORMAT_TYPE,
  84. MS_ERROR_BLOCK_NUMBER_SIZE,
  85. MS_ERROR_DISABLED_BLOCK,
  86. MS_ERROR_NO_FREE_BLOCK,
  87. MS_ERROR_LOGICAL_PHYSICAL_TABLE,
  88. MS_ERROR_BOOT_IDI,
  89. MSPRO_ERROR_MEDIA_BREAKDOWN,
  90. MSPRO_ERROR_STARTUP_TIMEOUT,
  91. MSPRO_ERROR_WRITE_DISABLED,
  92. MS_MSPRO_ERROR_TIMEOUT,
  93. MS_MSPRO_ERROR_UNSUPPORTED,
  94. MS_MSPRO_ERROR_NO_MEMORY,
  95. MS_MSPRO_ERROR_NO_READ
  96. } MS_MSPRO_Error_Status_t;
  97. typedef enum _MS_MSPRO_Media_Type
  98. {
  99. MEMORY_STICK_ERROR,
  100. MEMORY_STICK,
  101. MEMORY_STICK_WITH_SP,
  102. MEMORY_STICK_ROM,
  103. MEMORY_STICK_R,
  104. MEMORY_STICK_ROM_WITH_SP,
  105. MEMORY_STICK_R_WITH_SP,
  106. MEMORY_STICK_PRO,
  107. MEMORY_STICK_PRO_ROM,
  108. MEMORY_STICK_PRO_R,
  109. MEMORY_STICK_IO,
  110. MEMORY_STICK_PRO_IO
  111. } MS_MSPRO_Media_Type_t;
  112. typedef enum _Endian_Type
  113. {
  114. ENDIAN_TYPE_WORD = 2,
  115. ENDIAN_TYPE_DWORD = 4,
  116. ENDIAN_TYPE_QWORD = 8
  117. } Endian_Type_t;
  118. typedef union _MS_MSPRO_Card_Buffer {
  119. struct {
  120. MS_Registers_t regs;
  121. MS_MSPRO_Reg_Set_t reg_set;
  122. unsigned char boot_area_protection_process_flag;
  123. unsigned char boot_block_nums;
  124. unsigned char boot_block_no[2];
  125. MS_Boot_Header_t boot_header;
  126. MS_Boot_System_Entry_t boot_system_entry;
  127. MS_Boot_Attribute_Information_t boot_attribute_information;
  128. MS_Disabled_Block_Data_t disabled_block_data;
  129. //MS_Boot_IDI_t boot_idi;
  130. unsigned short logical_physical_table[MS_MAX_SEGMENT_NUMBERS *
  131. MS_BLOCKS_PER_SEGMENT];
  132. unsigned short free_block_table[MS_MAX_SEGMENT_NUMBERS *
  133. MS_MAX_FREE_BLOCKS_PER_SEGMENT];
  134. } ms;
  135. struct {
  136. MSPRO_Registers_t regs;
  137. MS_MSPRO_Reg_Set_t reg_set;
  138. MSPRO_Attribute_Information_Area_t attribute_information_area;
  139. MSPRO_Device_Information_Entry_t
  140. device_information_entry
  141. [MSRPO_MAX_DEVICE_INFORMATION_ENTRY];
  142. unsigned char system_entry_index;
  143. MSPRO_System_Information_t system_information;
  144. } mspro;
  145. } MS_MSPRO_Card_Buffer_t;
  146. typedef struct _MS_MSPRO_Card_Info {
  147. MS_MSPRO_Card_Type_t card_type;
  148. MS_MSPRO_Media_Type_t media_type;
  149. MS_MSPRO_Interface_Mode_t interface_mode;
  150. unsigned long blk_len;
  151. unsigned long blk_nums;
  152. unsigned char write_protected_flag;
  153. unsigned char read_only_flag;
  154. int inited_flag;
  155. int removed_flag;
  156. int init_retry;
  157. u32 raw_cid;
  158. unsigned ms_clk_unit;
  159. void (*ms_mspro_power) (int power_on);
  160. int (*ms_mspro_get_ins) (void);
  161. void (*ms_mspro_io_release) (void);
  162. SDIO_Pad_Type_t io_pad_type; /* hw io pin pad */
  163. unsigned char *dma_buf;
  164. unsigned char *dma_phy_buf;
  165. unsigned char *ms_mspro_buf;
  166. unsigned char *ms_mspro_phy_buf;
  167. unsigned char* data_buf;
  168. unsigned char* data_phy_buf;
  169. } MS_MSPRO_Card_Info_t;
  170. //Transfer Protocol Command (TPC)
  171. #define TPC_MS_READ_PAGE_DATA 0x2D
  172. #define TPC_MS_MSPRO_READ_REG 0x4B
  173. #define TPC_MS_MSPRO_GET_INT 0x78
  174. #define TPC_MS_WRITE_PAGE_DATA 0xD2
  175. #define TPC_MS_MSPRO_WRITE_REG 0xB4
  176. #define TPC_MS_MSPRO_SET_RW_REG_ADRS 0x87
  177. #define TPC_MS_MSPRO_SET_CMD 0xE1
  178. #define TPC_MSPRO_READ_LONG_DATA 0x2D
  179. #define TPC_MSPRO_READ_SHORT_DATA 0x3C
  180. #define TPC_MSPRO_WRITE_LONG_DATA 0xD2
  181. #define TPC_MSPRO_WRITE_SHORT_DATA 0xC3
  182. #define TPC_MSPRO_EX_SET_CMD 0x96
  183. #define MS_MSPRO_RDY_TIMEOUT (50*TIMER_1MS) //10ms, sleep mode
  184. #define MS_MSPRO_INT_TIMEOUT (1500*TIMER_1MS) //1500ms, sleep mode
  185. #define MS_MSPRO_INIT_RETRY 3
  186. #define MS_MSPRO_TRANSFER_SLOWER_CLK 12 //M HZ
  187. #define MS_MSPRO_TRANSFER_CLK 18 //M HZ
  188. #define MS_MSPRO_TRANSFER_HIGHSPEED_CLK 25 //M HZ
  189. #define MS_WRITE_ESPECIAL_CAPACITY_BLOCKS 130000
  190. #endif //_H_MS_MSPRO