sd.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*****************************************************************************
  2. *
  3. * Copyright Andes Technology Corporation 2007-2008
  4. * All Rights Reserved.
  5. *
  6. * Revision History:
  7. *
  8. * Aug.21.2007 Created.
  9. ****************************************************************************/
  10. /*****************************************************************************
  11. *
  12. * FILE NAME VERSION
  13. *
  14. * sd.h
  15. *
  16. * DESCRIPTION
  17. *
  18. * SD controller driver interfaces for client applications.
  19. * (Nucleus I/O Driver Architecture)
  20. *
  21. * DATA STRUCTURES
  22. *
  23. * None
  24. *
  25. * DEPENDENCIES
  26. *
  27. * ag101regs.h
  28. * ag101defs.h
  29. *
  30. ****************************************************************************/
  31. #ifndef __SD_H__
  32. #define __SD_H__
  33. #include <inttypes.h>
  34. /*
  35. * SDD I/O control code, used for clients not using driver wrapper routines,
  36. * i.e., when not using middle-ware interfaces. Driver implementation target
  37. * is that almost every IOCTL should exist a corresponding wrapper routine.
  38. */
  39. typedef enum SDD_IOCTL {
  40. SDD_IOCTL_READ_SECTORS, /* Parameter: pointer to SDD_IOCTL_READ_SECTORS_PARAM struct */
  41. SDD_IOCTL_WRITE_SECTORS, /* Parameter: pointer to SDD_IOCTL_WRITE_SECTORS_PARAM struct */
  42. } SDD_IOCTL;
  43. /* Parameter struct for SDD_IOCTL_ */
  44. typedef struct _SDD_IOCTL_READ_SECTORS_PARAM {
  45. uint32_t lba_sector; /* start sector number */
  46. uint32_t sector_count; /* number of sectors included in this operation */
  47. uint32_t sector_size; /* sector size in bytes */
  48. void *io_buff; /* buffer pointer */
  49. } SDD_IOCTL_READ_SECTORS_PARAM;
  50. typedef struct _SDD_IOCTL_WRITE_SECTORS_PARAM {
  51. uint32_t lba_sector; /* start sector number */
  52. uint32_t sector_count; /* number of sectors included in this operation */
  53. uint32_t sector_size; /* sector size in bytes */
  54. void *io_buff; /* buffer pointer */
  55. } SDD_IOCTL_WRITE_SECTORS_PARAM;
  56. typedef enum SDD_EVENTS {
  57. SDD_EVENT_CD = 0x00000001, /* Card-detection event. Event parameter: SDD_CD_EVENT */
  58. } SDD_EVENTS;
  59. typedef enum SDD_CD_EVENT_PARAM {
  60. SDD_CD_CARD_INSERTED = 1,
  61. SDD_CD_CARD_REMOVED = 0,
  62. } SDD_CD_EVENT_PARAM;
  63. typedef enum SDD_DMA_MODE {
  64. SDD_DMA_NONE = 0, /* no dma, deivce i/o is through pio */
  65. SDD_DMA_DCH = 1, /* dma channel is dynamically allocated on i/o request and get free after dma. */
  66. SDD_DMA_SCH = 2, /* dma channel is allocated and occupied during device initialization. */
  67. } SDD_DMA_MODE;
  68. /* Define data structures for management of CF device. */
  69. typedef struct SDD_DEVICE_STRUCT {
  70. void *bdev_id; /* (reserved) The block device context. This field is reserved by the driver. */
  71. uint8_t dma; /* (in) one of the enum value in SDD_DMA_MODE. */
  72. uint8_t func; /* (in) (Reserved currently) Preferred SD card function mode (SD Memory, SD/IO, SPI) */
  73. uint8_t padding[2]; /* stuff bytes */
  74. } SDD_DEVICE;
  75. /*****************************************************************************
  76. * Note: Everything below is designed as an interface wrapper to access
  77. * SD driver.
  78. *
  79. * [Structures]
  80. *
  81. * [Functions]
  82. *
  83. *
  84. ****************************************************************************/
  85. /* driver generic error code for SDC */
  86. #define SDD_SUCCESS 0x00
  87. #define SDD_INVALID_INIT 0x01
  88. #define SDD_INVALID_REQUEST 0x02
  89. #define SDD_NOT_SUPPORTED 0x03
  90. #define SDD_INVALID_FUNCTION 0x11
  91. #define SDD_INVALID_PARAMETER 0x12
  92. #define SDD_CARD_REMOVED 0x13
  93. #define SDD_INVALID_MEDIA 0x14
  94. #define SDD_INVALID_IOCTL 0x15
  95. #define SDD_WRITE_DATA_ERROR 0x16
  96. #define SDD_READ_DATA_ERROR 0x17
  97. #define SDD_INVLAID_ADDRESS 0x18
  98. #define SDD_INVLAID_ADDR_RANGE 0x19
  99. #define SDD_CMD_TIMEOUT 0x21
  100. #define SDD_CMD_ERROR 0x22
  101. #define SDD_RSP_TIMEOUT 0x23
  102. #define SDD_RSP_CRC_ERROR 0x24
  103. #define SDD_NOT_SUPPORT_ACMD 0x25
  104. #define SDD_CSR_ERROR 0x26
  105. #define SDD_INVALID_STATE 0x27
  106. #define SDD_WAIT_TIMEOUT 0x28
  107. #define SDD_WRITE_PROTECTED 0x29
  108. #define SDD_CARD_LOCKED 0x30
  109. extern void _sdd_lisr(int vector);
  110. extern void _sdd_hisr(void *param);
  111. extern uint32_t NDS_SD_Init(SDD_DEVICE * sdd_dev);
  112. extern void NDS_SD_Unload(void);
  113. extern uint32_t NDS_SD_ReadSectors(SDD_DEVICE * sdd_dev, uint32_t sector,
  114. uint32_t sector_count, uint32_t sector_size,
  115. void *buffer);
  116. extern uint32_t NDS_SD_WriteSectors(SDD_DEVICE * sdd_dev, uint32_t sector,
  117. uint32_t sector_count, uint32_t sector_size,
  118. void *buffer);
  119. #endif /* __SD_H__ */