1 2 #define SUBPARTITION_PER_PARTITION 4 /* 4 sub partitions per partition */ 3 #define PARTITONS_PER_DISK 4 /* 4 partitions per disk */ 4 #define MINOR_PER_DISK 1 /* one additional minor to point to */ 5 6 /** 7 * We can have multiple MMC host controller present on the hardware. The MINIX 8 * approach to handle this is to run a driver for each instance. Every driver 9 * will therefore be stated with an "instance" id and the rest of the code here 10 * will assume a single host controller to be present. 11 * 12 * The SD specification allows multiple cards to be attached to a single host 13 * controller using the same lines. I recommend reading SD Specifications Part 1 14 * Physical layer Simplified Specification chapter 3 about SD Memory Card system 15 * concepts if you want to get a better understanding of this. 16 * 17 * In practice an MMC host will usually have a single slot attached to it and that 18 * Slot may or may not contain a card. On sudden card removal we might want to 19 * keep track of the last inserted card and we might therefore at later stage 20 * add an additional "last_card" attribute to the card. 21 * 22 * The following diagram shows the structure that will be used to modulate the 23 * hardware written in umlwiki syntax. 24 * 25 * [/host/ 26 * +instance:int] 1 --- 0..4 [ /slot/ 27 * +card_detect:func ] 1 --- 0..1 [ /card/ ] 28 * ` 29 */ 30 31 #define MAX_SD_SLOTS 4 32 33 struct mmc_host; 34 35 //TODO Add more modes like INACTIVE STATE and such 36 #define SD_MODE_UNINITIALIZED 0 37 #define SD_MODE_CARD_IDENTIFICATION 1 38 #define SD_MODE_DATA_TRANSFER_MODE 2 39 40 struct sd_card_regs 41 { 42 uint32_t cid[4]; /* Card Identification */ 43 uint32_t rca; /* Relative card address */ 44 uint32_t dsr; /* Driver stage register */ 45 uint32_t csd[4]; /* Card specific data */ 46 uint32_t scr[2]; /* SD configuration */ 47 uint32_t ocr; /* Operation conditions */ 48 uint32_t ssr[5]; /* SD Status */ 49 uint32_t csr; /* Card status */ 50 }; 51 52 #define RESP_LEN_48_CHK_BUSY (3<<0) 53 #define RESP_LEN_48 (2<<0) 54 #define RESP_LEN_136 (1<<0) 55 #define RESP_NO_RESPONSE (0<<0) 56 57 #define DATA_NONE (0) 58 #define DATA_READ (1) 59 #define DATA_WRITE (2) 60 61 /* struct representing an mmc command */ 62 struct mmc_command 63 { 64 uint32_t cmd; 65 uint32_t args; 66 uint32_t resp_type; 67 uint32_t data_type; 68 uint32_t resp[4]; 69 unsigned char *data; 70 uint32_t data_len; 71 }; 72 73 /* structure representing an SD card */ 74 struct sd_card 75 { 76 /* pointer back to the SD slot for convenience */ 77 struct sd_slot *slot; 78 79 struct sd_card_regs regs; 80 81 /* some helpers (data comming from the csd) */ 82 uint32_t blk_size; 83 uint32_t blk_count; 84 85 /* drive state: deaf, initialized, dead */ 86 unsigned state; 87 88 /* MINIX/block driver related things */ 89 int open_ct; /* in-use count */ 90 91 /* 1 disks + 4 partitions and 16 possible sub partitions */ 92 struct device part[MINOR_PER_DISK + PARTITONS_PER_DISK]; 93 struct device subpart[PARTITONS_PER_DISK * SUBPARTITION_PER_PARTITION]; 94 }; 95 96 /* structure representing an SD slot */ 97 struct sd_slot 98 { 99 /* pointer back to the host for convenience */ 100 struct mmc_host *host; 101 102 unsigned state; 103 struct sd_card card; 104 }; 105 106 /* structure for the host controller */ 107 struct mmc_host 108 { 109 /* MMC host configuration */ 110 int (*host_set_instance) (struct mmc_host * host, int instance); 111 /* MMC host configuration */ 112 int (*host_init) (struct mmc_host * host); 113 /* Set log level */ 114 void (*set_log_level) (int level); 115 /* Host controller reset */ 116 int (*host_reset) (struct mmc_host * host); 117 /* Card detection (binary yes/no) */ 118 int (*card_detect) (struct sd_slot * slot); 119 /* Perform card detection e.g. card type */ 120 struct sd_card *(*card_initialize) (struct sd_slot * slot); 121 /* Release the card */ 122 int (*card_release) (struct sd_card * card); 123 124 /* Additional hardware interrupts */ 125 void (*hw_intr) (unsigned int irqs); 126 127 /* read count blocks into existing buf */ 128 int (*read) (struct sd_card * card, 129 uint32_t blknr, uint32_t count, unsigned char *buf); 130 131 /* write count blocks */ 132 int (*write) (struct sd_card * card, 133 uint32_t blknr, uint32_t count, unsigned char *buf); 134 135 /* up to 4 slots with 4 SD cards */ 136 struct sd_slot slot[MAX_SD_SLOTS]; 137 }; 138 139 #if 0 140 /* Command execution */ 141 int (*send_cmd) (struct sd_card * card, struct mmc_command *); 142 143 /* struct representing an mmc command */ 144 struct mmc_command 145 { 146 uint32_t cmd; 147 uint32_t args; 148 uint32_t resp[4]; 149 unsigned char *data; 150 uint32_t data_len; 151 }; 152 #endif 153 154 /* Hack done for driver registration */ 155 void host_initialize_host_structure_mmchs(struct mmc_host *host); 156 void host_initialize_host_structure_dummy(struct mmc_host *host); 157