mmcard.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. #ifndef _DEV_MMCARD_H_
  2. #define _DEV_MMCARD_H_
  3. /*
  4. * Copyright (C) 2005 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  23. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*!
  35. * \file dev/mmcard.h
  36. * \brief Header file for basic multimedia card driver.
  37. *
  38. * \verbatim
  39. *
  40. * $Log: mmcard.h,v $
  41. * Revision 1.3 2006/10/08 16:48:09 haraldkipp
  42. * Documentation fixed
  43. *
  44. * Revision 1.2 2006/09/05 12:34:55 haraldkipp
  45. * Added commands for native MMC interface.
  46. *
  47. * Revision 1.1 2006/01/05 16:32:10 haraldkipp
  48. * First check-in.
  49. *
  50. *
  51. * \endverbatim
  52. */
  53. #include <sys/device.h>
  54. #include <sys/file.h>
  55. /*!
  56. * \addtogroup xgMmCard
  57. */
  58. /*@{*/
  59. /*!
  60. * \brief Low level access information structure.
  61. */
  62. typedef struct _MMCIFC {
  63. /*! Initialize the card. */
  64. int (*mmcifc_in) (void);
  65. /*! Read received byte and transmit a new one. */
  66. u_char(*mmcifc_io) (u_char);
  67. /*! Select or deselect the card. */
  68. int (*mmcifc_cs) (int);
  69. /*! Query card detect. */
  70. int (*mmcifc_cd) (void);
  71. /*! Query write protect. */
  72. int (*mmcifc_wp) (void);
  73. } MMCIFC;
  74. #define MMCMD_HOST 0x40
  75. #define MMCMD_RESET_CRC 0x95
  76. /*! \brief Reset card to idle state.
  77. *
  78. * In idle state the card will not accept any other commands than
  79. * MMCMD_SEND_OP_COND or MMCMD_READ_OCR.
  80. */
  81. #define MMCMD_GO_IDLE_STATE 0
  82. /*! \brief Activate card's initialization process. */
  83. #define MMCMD_SEND_OP_COND 1
  84. /*! \brief Send operation condition register.
  85. *
  86. * Queries the operation condition register content from all cards, which
  87. * are in idle state.
  88. */
  89. #define MMCMD_ALL_SEND_CID 2
  90. /*! \brief Assign relative card address. */
  91. #define MMCMD_SEND_RELATIVE_ADDR 3
  92. /*! \brief Assign relative card address. */
  93. #define MMCMD_SELECT_CARD 7
  94. /*! \brief Query card's CSD. */
  95. #define MMCMD_SEND_CSD 9
  96. /*! \brief Query card's CID. */
  97. #define MMCMD_SEND_CID 10
  98. /*! \brief Stop multiple block transmission. */
  99. #define MMCMD_STOP_TRANSMISSION 12
  100. /*! \brief Query card's status register. */
  101. #define MMCMD_SEND_STATUS 13
  102. /*! \brief Select block length for following read/write commands. */
  103. #define MMCMD_SET_BLOCKLEN 16
  104. /*! \brief Initiate single block read. */
  105. #define MMCMD_READ_SINGLE_BLOCK 17
  106. /*! \brief Initiate continuous block read. */
  107. #define MMCMD_READ_MULTIPLE_BLOCK 18
  108. /*! \brief Initiate single block write. */
  109. #define MMCMD_WRITE_BLOCK 24
  110. /*! \brief Initiate continuous block write. */
  111. #define MMCMD_WRITE_MULTIPLE_BLOCK 25
  112. /*! \brief Initiate programming of programmable CSD bits. */
  113. #define MMCMD_PROGRAM_CSD 27
  114. /*! \brief Enable card's optional write protection. */
  115. #define MMCMD_SET_WRITE_PROTECT 28
  116. /*! \brief Disable card's write protection. */
  117. #define MMCMD_CLR_WRITE_PROTECT 29
  118. /*! \brief Query card's write protect status. */
  119. #define MMCMD_SEND_WRITE_PROTECT 30
  120. /*! \brief Set address of the first erase group. */
  121. #define MMCMD_TAG_ERASE_GROUP_START 35
  122. /*! \brief Set address of the last erase group. */
  123. #define MMCMD_TAG_ERASE_GROUP_END 36
  124. /*! \brief Erase previously selected sectors. */
  125. #define MMCMD_ERASE 38
  126. /*! \brief Set/clear password or lock/unlock the card. */
  127. #define MMCMD_LOCK_UNLOCK 42
  128. /*! \brief Query card's operating condition register. */
  129. #define MMCMD_READ_OCR 58
  130. /*! \brief Enable or disable CRC mode.
  131. *
  132. * In SPI mode CRC is disabled by default.
  133. */
  134. #define MMCMD_CRC_ON_OFF 59
  135. /*! \brief Card is idle. */
  136. #define MMR1_IDLE_STATE 0x00
  137. /*! \brief Card is busy. */
  138. #define MMR1_NOT_IDLE 0x01
  139. /*! \brief Erase sequence was cleared before execution. */
  140. #define MMR1_ERASE_RESET 0x02
  141. /*! \brief Illegal command code detected. */
  142. #define MMR1_ILLEGAL_COMMAND 0x04
  143. /*! \brief Bad command CRC detected. */
  144. #define MMR1_COM_CRC_ERROR 0x08
  145. /*! \brief Bad erase sequence. */
  146. #define MMR1_ERASE_SEQ_ERROR 0x10
  147. /*! \brief Misaligned address did not match block length. */
  148. #define MMR1_ADDRESS_ERROR 0x20
  149. /*! \brief Command parameter is out of range. */
  150. #define MMR1_PARAMETER_ERROR 0x40
  151. /*! \brief Card is locked. */
  152. #define MMR2_CARD_LOCKED 0x01
  153. /*! \brief Erasing write protected sector or password error. */
  154. #define MMR2_WP_ERASE_SKIP 0x02
  155. /*! \brief General or unknown error occured. */
  156. #define MMR2_ERROR 0x04
  157. /*! \brief Internal card controller error. */
  158. #define MMR2_CC_ERROR 0x08
  159. /*! \brief Bad internal ECC. */
  160. #define MMR2_ECC_FAILED 0x10
  161. /*! \brief Failed to write to protected block. */
  162. #define MMR2_WP_VIOLATION 0x20
  163. /*! \brief Invalid erase parameter. */
  164. #define MMR2_ERASE_PARAMETER 0x40
  165. /*! \brief Command parameter is out of range. */
  166. #define MMR2_OUT_OF_RANGE 0x80
  167. #define MMCSR_OUT_OF_RANGE 0x80000000
  168. #define MMCSR_ADDRESS_ERROR 0x40000000
  169. #define MMCSR_BLOCK_LEN_ERROR 0x20000000
  170. #define MMCSR_ERASE_SEQ_ERROR 0x10000000
  171. #define MMCSR_ERASE_PARAM 0x08000000
  172. #define MMCSR_WP_VIOLATION 0x04000000
  173. #define MMCSR_COM_CRC_ERROR 0x00800000
  174. #define MMCSR_ILLEGAL_COMMAND 0x00400000
  175. #define MMCSR_ERROR 0x00080000
  176. #define MMCSR_CIDCSD_OVERWRITE 0x00010000
  177. #define MMCSR_WP_ERASE_SKIP 0x00008000
  178. #define MMCSR_CARD_ECC_DISABLED 0x00004000
  179. #define MMCSR_ERASE_RESET 0x00002000
  180. #define MMCSR_STATE_MASK 0x00001E00
  181. #define MMCSR_READY_FOR_DATA 0x00000100
  182. #define MMCSR_IS_IDLE 0x00000000
  183. #define MMCSR_IS_READY 0x00000200
  184. #define MMCSR_IS_IDENT 0x00000400
  185. #define MMCSR_IS_STBY 0x00000600
  186. #define MMCSR_IS_TRAN 0x00000800
  187. #define MMCSR_IS_DATA 0x00000A00
  188. #define MMCSR_IS_RCV 0x00000C00
  189. #define MMCSR_IS_PRG 0x00000E00
  190. #define MMCSR_IS_DIS 0x00001000
  191. #define MMDR_ACCEPTED
  192. #define MMDR_CRC_ERROR
  193. #define MMDR_WRITE_ERROR
  194. #define MMCERR_TIMEOUT 0x00000001
  195. #define MMCOP_NBUSY 0x80000000
  196. /*! \brief Number of bytes in the CID register. */
  197. #define MMCARD_CIDR_SIZE 16
  198. /*! \brief Number of bytes in the CSD register. */
  199. #define MMCARD_CSDR_SIZE 16
  200. /*! \brief Number of bytes in the operating condition register. */
  201. #define MMCARD_OCR_SIZE 32
  202. /*!
  203. * \name Control Codes
  204. */
  205. /*@{*/
  206. /*! \brief Retrieve card status. */
  207. #define MMCARD_GETSTATUS 0x2001
  208. /*! \brief Retrieve operation condition register. */
  209. #define MMCARD_GETOCR 0x2002
  210. /*! \brief Retrieve card identification. */
  211. #define MMCARD_GETCID 0x2003
  212. /*! \brief Retrieve card specific data. */
  213. #define MMCARD_GETCSD 0x2004
  214. /*@}*/
  215. /*!
  216. * \brief Multimedia card identification register.
  217. */
  218. typedef struct __attribute__ ((packed)) _MMC_CID {
  219. /*! \brief Manufacturer identifier. */
  220. u_char mmcid_mid;
  221. /*! \brief OEM/Application identifier. */
  222. u_short mmcid_oid;
  223. /*! \brief Product name. */
  224. u_char mmcid_pnm[6];
  225. /*! \brief Product revision. */
  226. u_char mmcid_rev;
  227. /*! \brief Serial number. */
  228. u_long mmcid_psn;
  229. /*! \brief Manufacturing date code. */
  230. u_char mmcid_mdt;
  231. /*! \brief CRC7 checksum. */
  232. u_char mmcid_crc;
  233. } MMC_CID;
  234. /*!
  235. * \brief Multimedia card identification register.
  236. */
  237. typedef struct __attribute__ ((packed)) _MMC_CSD {
  238. /*! \brief Card specification. */
  239. u_char mmcsd_spec;
  240. /*! \brief Data read access time. */
  241. u_char mmcsd_taac;
  242. /*! \brief Data read access time 2. */
  243. u_char mmcsd_nsac;
  244. /*! \brief Maximum data transfer rate. */
  245. u_char mmcsd_speed;
  246. /*! \brief Card command classes and max. read block length. */
  247. u_char mmcsd_ccc_bl[2];
  248. /*! \brief Read-only fields.
  249. *
  250. * - [0] 0..1 Device size bits 10..11.
  251. * - [0] 2..3 Reserved.
  252. * - [0] 4 DSR implemented.
  253. * - [0] 5 Read block misalignment.
  254. * - [0] 6 Write block misalignment.
  255. * - [0] 7 Partial blocks for read allowed.
  256. * - [1] 0..7 Device size bits 2..9.
  257. * - [2] 0..2 Max. read current at VDD max.
  258. * - [2] 3..5 Max. read current at VDD min.
  259. * - [2] 6..7 Device size bits 0..1.
  260. * - [3] 0..1 Device size multiplier bits 1..2.
  261. * - [3] 2..4 Max. write current at VDD max.
  262. * - [3] 5..7 Max. write current at VDD min.
  263. * - [4] 0..1 Erase group size multiplier bits 3..4.
  264. * - [4] 2..6 Erase group size.
  265. * - [4] 7 Device size multiplier bit 0.
  266. * - [5] 0..4 Write protect group size.
  267. * - [5] 5..7 Erase group size multiplier bits 0..2.
  268. * - [6] 0..1 Max. write data block length bits 2..3.
  269. * - [6] 2..4 Read to write speed factor.
  270. * - [6] 5..6 Reserved.
  271. * - [6] 7 Write protect group enable.
  272. * - [7] 0 Content protection application.
  273. * - [7] 1..4 Reserved.
  274. * - [7] 5 Partial blocks for write allowed.
  275. * - [7] 6..7 Max. write data block length bits 0..1.
  276. */
  277. u_char mmcsd_rfld[8];
  278. /*! \brief Programmable field. */
  279. u_char mmcsd_pfld;
  280. /*! \brief Checksum. */
  281. u_char mmcsd_crc;
  282. } MMC_CSD;
  283. /*@}*/
  284. __BEGIN_DECLS
  285. /* Prototypes */
  286. extern int MmCardDevInit(NUTDEVICE * dev);
  287. extern int MmCardIOCtl(NUTDEVICE * dev, int req, void *conf);
  288. extern int MmCardBlockRead(NUTFILE * nfp, void *buffer, int len);
  289. extern int MmCardBlockWrite(NUTFILE * nfp, CONST void *buffer, int len);
  290. #ifdef __HARVARD_ARCH__
  291. extern int MmCardBlockWrite_P(NUTFILE * nfp, PGM_P buffer, int len);
  292. #endif
  293. extern NUTFILE *MmCardMount(NUTDEVICE * dev, CONST char *name, int mode, int acc);
  294. extern int MmCardUnmount(NUTFILE * nfp);
  295. __END_DECLS
  296. /* End of prototypes */
  297. #endif