[992] | 1 | /** |
---|
| 2 | * \File : reset_ioc_sdc.h |
---|
| 3 | * \Date : 31/O4/2015 |
---|
| 4 | * \Author : alain greiner |
---|
| 5 | * \Copyright (c) UPMC-LIP6 |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 9 | // This driver supports the SocLib VciAhciSdc component, that is a single channel, |
---|
| 10 | // block oriented, SD card contrÃŽler, respecting the AHCI standard. |
---|
| 11 | // This driver supports only SD Cards V2 and higher, and the block |
---|
| 12 | // size must be 512 bytes. |
---|
| 13 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 14 | |
---|
| 15 | #ifndef _RESET_SDC_IOC_H_ |
---|
| 16 | #define _RESET_SDC_IOC_H_ |
---|
| 17 | |
---|
| 18 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 19 | // SDC Addressable Registers (up to 64 registers) |
---|
| 20 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 21 | |
---|
| 22 | enum SoclibSdcRegisters |
---|
| 23 | { |
---|
| 24 | SDC_PERIOD = 32, // system cycles / Write-Only |
---|
| 25 | SDC_CMD_ID = 33, // command index / Write-Only |
---|
| 26 | SDC_CMD_ARG = 34, // command argument / Write-Only |
---|
| 27 | SDC_RSP_STS = 35, // response status / Read-Only |
---|
| 28 | }; |
---|
| 29 | |
---|
| 30 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 31 | // Software supported SDC commands |
---|
| 32 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 33 | |
---|
| 34 | enum SoclibSdcCommands |
---|
| 35 | { |
---|
| 36 | SDC_CMD0 = 0, // Soft reset |
---|
| 37 | SDC_CMD3 = 3, // Relative Card Address |
---|
| 38 | SDC_CMD7 = 7, // Toggle mode |
---|
| 39 | SDC_CMD8 = 8, // Voltage info |
---|
| 40 | SDC_CMD41 = 41, // Operation Condition |
---|
| 41 | }; |
---|
| 42 | |
---|
| 43 | enum SoclibSdcErrorCodes |
---|
| 44 | { |
---|
| 45 | SDC_ERROR_LBA = 0x40000000, // LBA larger tnan SD card capacity |
---|
| 46 | SDC_ERROR_CRC = 0x00800000, // CRC error reported by SD card |
---|
| 47 | SDC_ERROR_CMD = 0x00400000, // command notsupported by SD card |
---|
| 48 | }; |
---|
| 49 | |
---|
| 50 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 51 | // Various SD Card constants |
---|
| 52 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 53 | |
---|
| 54 | #define SDC_CMD8_ARGUMENT 0x00000155 // VHS = 2.7-3.6 V / check = 0x55 |
---|
| 55 | #define SDC_CMD41_ARGUMENT 0x40000000 // High Capacity Host Support |
---|
| 56 | #define SDC_CMD41_RSP_BUSY 0x80000000 // Card Busy when 0 |
---|
| 57 | #define SDC_CMD41_RSP_CCS 0x40000000 // High Capacity when 1 |
---|
| 58 | |
---|
| 59 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 60 | // AHCI Addressable Registers |
---|
| 61 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 62 | |
---|
| 63 | enum SoclibAhciRegisters |
---|
| 64 | { |
---|
| 65 | AHCI_PXCLB = 0, // command list base address 32 LSB bits |
---|
| 66 | AHCI_PXCLBU = 1, // command list base address 32 MSB bits |
---|
| 67 | AHCI_PXIS = 4, // interrupt status |
---|
| 68 | AHCI_PXIE = 5, // interrupt enable |
---|
| 69 | AHCI_PXCMD = 6, // run |
---|
| 70 | AHCI_PXCI = 14, // command bit-vector |
---|
| 71 | }; |
---|
| 72 | |
---|
| 73 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 74 | // AHCI structures for Command List |
---|
| 75 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 76 | |
---|
| 77 | /////// command descriptor /////////////////////// |
---|
| 78 | typedef struct ahci_cmd_desc_s // size = 16 bytes |
---|
| 79 | { |
---|
| 80 | unsigned char flag[2]; // W in bit 6 of flag[0] |
---|
| 81 | unsigned char prdtl[2]; // Number of buffers |
---|
| 82 | unsigned int prdbc; // Number of bytes actually transfered |
---|
| 83 | unsigned int ctba; // Command Table base address 32 LSB bits |
---|
| 84 | unsigned int ctbau; // Command Table base address 32 MSB bits |
---|
| 85 | } ahci_cmd_desc_t; |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 89 | // AHCI structures for Command Table |
---|
| 90 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 91 | |
---|
| 92 | /////// command header /////////////////////////////// |
---|
| 93 | typedef struct ahci_cmd_header_s // size = 16 bytes |
---|
| 94 | { |
---|
| 95 | unsigned int res0; // reserved |
---|
| 96 | unsigned char lba0; // LBA 7:0 |
---|
| 97 | unsigned char lba1; // LBA 15:8 |
---|
| 98 | unsigned char lba2; // LBA 23:16 |
---|
| 99 | unsigned char res1; // reserved |
---|
| 100 | unsigned char lba3; // LBA 31:24 |
---|
| 101 | unsigned char lba4; // LBA 39:32 |
---|
| 102 | unsigned char lba5; // LBA 47:40 |
---|
| 103 | unsigned char res2; // reserved |
---|
| 104 | unsigned int res3; // reserved |
---|
| 105 | } ahci_cmd_header_t; |
---|
| 106 | |
---|
| 107 | /////// Buffer Descriptor ////////////////////////// |
---|
| 108 | typedef struct ahci_cmd_buffer_s // size = 16 bytes |
---|
| 109 | { |
---|
| 110 | unsigned int dba; // Buffer base address 32 LSB bits |
---|
| 111 | unsigned int dbau; // Buffer base address 32 MSB bits |
---|
| 112 | unsigned int res0; // reserved |
---|
| 113 | unsigned int dbc; // Buffer bytes count |
---|
| 114 | } ahci_cmd_buffer_t; |
---|
| 115 | |
---|
| 116 | /////// command table ///////////////////////////////// |
---|
| 117 | typedef struct ahci_cmd_table_s // size = 32 bytes |
---|
| 118 | { |
---|
| 119 | ahci_cmd_header_t header; // contains LBA value |
---|
| 120 | ahci_cmd_buffer_t buffer; // contains buffer descriptor |
---|
| 121 | } ahci_cmd_table_t; |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 125 | // This function initializes the AHCI_SDC controller and the SD Card. |
---|
| 126 | // Returns 0 if success, > 0 if failure |
---|
| 127 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 128 | |
---|
| 129 | unsigned int reset_sdc_init(); |
---|
| 130 | |
---|
| 131 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 132 | // Transfer data between the block device and a memory buffer. |
---|
| 133 | // - lba : first block index on the block device |
---|
| 134 | // - buffer : base address of the memory buffer |
---|
| 135 | // - count : number of blocks to be transfered. |
---|
| 136 | // Returns 0 if success, > 0 if error. |
---|
| 137 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 138 | |
---|
| 139 | unsigned int reset_sdc_read( unsigned int lba, |
---|
| 140 | void* buffer, |
---|
| 141 | unsigned int count); |
---|
| 142 | |
---|
| 143 | #endif |
---|
| 144 | |
---|
| 145 | // Local Variables: |
---|
| 146 | // tab-width: 4 |
---|
| 147 | // c-basic-offset: 4 |
---|
| 148 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 149 | // indent-tabs-mode: nil |
---|
| 150 | // End: |
---|
| 151 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|