kernel: fix sanity check
[minix.git] / drivers / mmc / mmchost.h
blob37e44c4fa1a7c0989154da468a1493f7bd60fae1
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 */
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.
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.
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.
22 * The following diagram shows the structure that will be used to modulate the
23 * hardware written in umlwiki syntax.
25 * [/host/
26 * +instance:int] 1 --- 0..4 [ /slot/
27 * +card_detect:func ] 1 --- 0..1 [ /card/ ]
28 * `
31 #define MAX_SD_SLOTS 4
33 struct mmc_host;
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
40 struct sd_card_regs
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 */
52 /* struct representing an mmc command */
53 struct mmc_command
55 uint32_t cmd;
56 uint32_t args;
57 uint32_t resp_type;
59 #define RESP_LEN_48_CHK_BUSY (3<<0)
60 #define RESP_LEN_48 (2<<0)
61 #define RESP_LEN_136 (1<<0)
62 #define NO_RESPONSE (0<<0)
64 uint32_t resp[4];
65 unsigned char *data;
66 uint32_t data_len;
69 /* structure representing an SD card */
70 struct sd_card
72 /* pointer back to the SD slot for convenience */
73 struct sd_slot *slot;
75 struct sd_card_regs regs;
77 /* some helpers (data comming from the csd) */
78 uint32_t blk_size;
79 uint32_t blk_count;
81 /* drive state: deaf, initialized, dead */
82 unsigned state;
84 /* MINIX/block driver related things */
85 int open_ct; /* in-use count */
87 /* 1 disks + 4 partitions and 16 possible sub partitions */
88 struct device part[MINOR_PER_DISK + PARTITONS_PER_DISK];
89 struct device subpart[PARTITONS_PER_DISK * SUBPARTITION_PER_PARTITION];
92 /* structure representing an SD slot */
93 struct sd_slot
95 /* pointer back to the host for convenience */
96 struct mmc_host *host;
98 unsigned state;
99 struct sd_card card;
102 /* structure for the host controller */
103 struct mmc_host
105 /* MMC host configuration */
106 int (*host_set_instance) (struct mmc_host * host, int instance);
107 /* MMC host configuration */
108 int (*host_init) (struct mmc_host * host);
109 /* Set log level */
110 void (*set_log_level) (int level);
111 /* Host controller reset */
112 int (*host_reset) (struct mmc_host * host);
113 /* Card detection (binary yes/no) */
114 int (*card_detect) (struct sd_slot * slot);
115 /* Perform card detection e.g. card type */
116 struct sd_card *(*card_initialize) (struct sd_slot * slot);
117 /* Release the card */
118 int (*card_release) (struct sd_card * card);
120 /* read count blocks into existing buf */
121 int (*read) (struct sd_card * card,
122 uint32_t blknr, uint32_t count, unsigned char *buf);
124 /* write count blocks */
125 int (*write) (struct sd_card * card,
126 uint32_t blknr, uint32_t count, unsigned char *buf);
128 /* up to 4 slots with 4 SD cards */
129 struct sd_slot slot[MAX_SD_SLOTS];
132 #if 0
133 /* Command execution */
134 int (*send_cmd) (struct sd_card * card, struct mmc_command *);
136 /* struct representing an mmc command */
137 struct mmc_command
139 uint32_t cmd;
140 uint32_t args;
141 uint32_t resp[4];
142 unsigned char *data;
143 uint32_t data_len;
145 #endif
147 /* Hack done for driver registration */
148 void host_initialize_host_structure_mmchs(struct mmc_host *host);
149 void host_initialize_host_structure_dummy(struct mmc_host *host);