1 Index: linux-2.6.18/drivers/mmc/atmel-mci.c
2 ===================================================================
3 --- linux-2.6.18.orig/drivers/mmc/atmel-mci.c 2007-01-15 16:36:59.000000000 +0100
4 +++ linux-2.6.18/drivers/mmc/atmel-mci.c 2007-01-16 13:18:40.000000000 +0100
12 struct atmel_mci_dma {
14 * Data might complete before command for very short transfers
17 - if (test_bit(EVENT_CMD_COMPLETE, &host->completed_events)
19 - || test_bit(EVENT_STOP_COMPLETE, &host->completed_events)))
20 + if (mci_cmd_is_complete(host)
21 + && (!data->stop || mci_stop_is_complete(host)))
22 atmci_request_end(host->mmc, data->mrq);
26 host->pending_events, host->completed_events,
27 mci_readl(host, IMR));
29 - if (test_and_clear_bit(EVENT_CMD_ERROR, &host->pending_events)) {
30 + if (mci_clear_cmd_error_is_pending(host)) {
31 struct mmc_command *cmd;
33 - set_bit(EVENT_CMD_ERROR, &host->completed_events);
34 - clear_bit(EVENT_CMD_COMPLETE, &host->pending_events);
35 + mci_set_cmd_error_complete(host);
36 + mci_clear_cmd_pending(host);
41 atmci_command_error(mmc, cmd, host->error_status);
42 atmci_request_end(mmc, cmd->mrq);
44 - if (test_and_clear_bit(EVENT_STOP_ERROR, &host->pending_events)) {
45 - set_bit(EVENT_STOP_ERROR, &host->completed_events);
46 - clear_bit(EVENT_STOP_COMPLETE, &host->pending_events);
47 + if (mci_clear_stop_error_is_pending(host)) {
48 + mci_set_stop_error_complete(host);
49 + mci_clear_stop_pending(host);
50 atmci_command_error(mmc, host->mrq->stop,
53 atmci_request_end(mmc, host->mrq);
55 - if (test_and_clear_bit(EVENT_CMD_COMPLETE, &host->pending_events)) {
56 - set_bit(EVENT_CMD_COMPLETE, &host->completed_events);
58 - || test_bit(EVENT_DATA_COMPLETE, &host->completed_events))
59 + if (mci_clear_cmd_is_pending(host)) {
60 + mci_set_cmd_complete(host);
61 + if (!mrq->data || mci_data_is_complete(host))
62 atmci_request_end(mmc, mrq);
64 - if (test_and_clear_bit(EVENT_STOP_COMPLETE, &host->pending_events)) {
65 - set_bit(EVENT_STOP_COMPLETE, &host->completed_events);
66 - if (test_bit(EVENT_DATA_COMPLETE, &host->completed_events))
67 + if (mci_clear_stop_is_pending(host)) {
68 + mci_set_stop_complete(host);
69 + if (mci_data_is_complete(host))
70 atmci_request_end(mmc, mrq);
72 - if (test_and_clear_bit(EVENT_DMA_ERROR, &host->pending_events)) {
73 - set_bit(EVENT_DMA_ERROR, &host->completed_events);
74 - clear_bit(EVENT_DATA_COMPLETE, &host->pending_events);
75 + if (mci_clear_dma_error_is_pending(host)) {
76 + mci_set_dma_error_complete(host);
77 + mci_clear_data_pending(host);
79 /* DMA controller got bus error => invalid address */
80 data->error = MMC_ERR_INVALID;
82 mmc_hostname(mmc), host->data->bytes_xfered);
85 - && !test_and_set_bit(EVENT_STOP_SENT,
86 - &host->completed_events))
87 + && !mci_set_stop_sent_is_completed(host))
88 /* TODO: Check if card is still present */
89 send_stop_cmd(host->mmc, data, 0);
91 atmci_data_complete(host, data);
93 - if (test_and_clear_bit(EVENT_DATA_ERROR, &host->pending_events)) {
94 + if (mci_clear_data_error_is_pending(host)) {
95 u32 status = host->error_status;
97 - set_bit(EVENT_DATA_ERROR, &host->completed_events);
98 - clear_bit(EVENT_DATA_COMPLETE, &host->pending_events);
99 + mci_set_data_error_complete(host);
100 + mci_clear_data_pending(host);
102 dma_stop_request(host->dma.req.req.dmac,
103 host->dma.req.req.channel);
104 @@ -686,14 +700,14 @@
105 mmc_hostname(host->mmc), data->bytes_xfered);
108 - && !test_and_set_bit(EVENT_STOP_SENT, &host->completed_events))
109 + && !mci_set_stop_sent_is_completed(host))
110 /* TODO: Check if card is still present */
111 send_stop_cmd(host->mmc, data, 0);
113 atmci_data_complete(host, data);
115 - if (test_and_clear_bit(EVENT_DATA_COMPLETE, &host->pending_events)) {
116 - set_bit(EVENT_DATA_COMPLETE, &host->completed_events);
117 + if (mci_clear_data_is_pending(host)) {
118 + mci_set_data_complete(host);
119 data->bytes_xfered = data->blocks * data->blksz;
120 atmci_data_complete(host, data);
122 @@ -716,10 +761,10 @@
123 mci_writel(host, IDR, MCI_BIT(CMDRDY) | MCI_CMD_ERROR_FLAGS);
126 - if (test_bit(EVENT_STOP_SENT, &host->completed_events))
127 - set_bit(EVENT_STOP_COMPLETE, &host->pending_events);
128 + if (mci_stop_sent_is_complete(host))
129 + mci_set_stop_pending(host);
131 - set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
132 + mci_set_cmd_pending(host);
134 tasklet_schedule(&host->tasklet);
136 @@ -735,13 +780,12 @@
137 host = container_of(dma, struct atmel_mci, dma);
140 - if (data->stop && !test_and_set_bit(EVENT_STOP_SENT,
141 - &host->completed_events))
142 + if (data->stop && !mci_set_stop_sent_is_completed(host))
143 send_stop_cmd(host->mmc, data, 0);
145 if (data->flags & MMC_DATA_READ) {
146 mci_writel(host, IDR, MCI_DATA_ERROR_FLAGS);
147 - set_bit(EVENT_DATA_COMPLETE, &host->pending_events);
148 + mci_set_data_pending(host);
149 tasklet_schedule(&host->tasklet);
153 mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
154 | MCI_DATA_ERROR_FLAGS));
156 - set_bit(EVENT_DMA_ERROR, &host->pending_events);
157 + mci_set_dma_error_pending(host);
158 tasklet_schedule(&host->tasklet);
161 @@ -790,10 +834,10 @@
162 | MCI_DATA_ERROR_FLAGS));
163 host->error_status = status;
165 - if (test_bit(EVENT_STOP_SENT, &host->completed_events))
166 - set_bit(EVENT_STOP_ERROR, &host->pending_events);
167 + if (mci_stop_sent_is_complete(host))
168 + mci_set_stop_error_pending(host);
170 - set_bit(EVENT_CMD_ERROR, &host->pending_events);
171 + mci_set_cmd_error_pending(host);
172 tasklet_schedule(&host->tasklet);
176 mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
177 | MCI_DATA_ERROR_FLAGS));
178 host->error_status = status;
179 - set_bit(EVENT_DATA_ERROR, &host->pending_events);
180 + mci_set_data_error_pending(host);
181 tasklet_schedule(&host->tasklet);
185 if (pending & MCI_BIT(NOTBUSY)) {
186 mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
187 | MCI_DATA_ERROR_FLAGS));
188 - set_bit(EVENT_DATA_COMPLETE, &host->pending_events);
189 + mci_set_data_pending(host);
190 tasklet_schedule(&host->tasklet);
193 Index: linux-2.6.18/drivers/mmc/atmel-mci.h
194 ===================================================================
195 --- linux-2.6.18.orig/drivers/mmc/atmel-mci.h 2007-01-16 13:22:59.000000000 +0100
196 +++ linux-2.6.18/drivers/mmc/atmel-mci.h 2007-01-16 13:24:33.000000000 +0100
197 @@ -189,4 +189,124 @@
198 #define mci_writel(port,reg,value) \
199 __raw_writel((value), (port)->regs + MCI_##reg)
201 +/* Test bit macros for completed events */
202 +#define mci_cmd_is_complete(host) \
203 + test_bit(EVENT_CMD_COMPLETE, &host->completed_events)
204 +#define mci_cmd_error_is_complete(host) \
205 + test_bit(EVENT_CMD_ERROR, &host->completed_events)
206 +#define mci_data_is_complete(host) \
207 + test_bit(EVENT_DATA_COMPLETE, &host->completed_events)
208 +#define mci_data_error_is_complete(host) \
209 + test_bit(EVENT_DATA_ERROR, &host->completed_events)
210 +#define mci_stop_sent_is_complete(host) \
211 + test_bit(EVENT_STOP_SENT, &host->completed_events)
212 +#define mci_stop_is_complete(host) \
213 + test_bit(EVENT_STOP_COMPLETE, &host->completed_events)
214 +#define mci_stop_error_is_complete(host) \
215 + test_bit(EVENT_STOP_ERROR, &host->completed_events)
216 +#define mci_dma_error_is_complete(host) \
217 + test_bit(EVENT_DMA_ERROR, &host->completed_events)
218 +#define mci_card_detect_is_complete(host) \
219 + test_bit(EVENT_CARD_DETECT, &host->completed_events)
221 +/* Test and clear bit macros for pending events */
222 +#define mci_clear_cmd_is_pending(host) \
223 + test_and_clear_bit(EVENT_CMD_COMPLETE, &host->pending_events)
224 +#define mci_clear_cmd_error_is_pending(host) \
225 + test_and_clear_bit(EVENT_CMD_ERROR, &host->pending_events)
226 +#define mci_clear_data_is_pending(host) \
227 + test_and_clear_bit(EVENT_DATA_COMPLETE, &host->pending_events)
228 +#define mci_clear_data_error_is_pending(host) \
229 + test_and_clear_bit(EVENT_DATA_ERROR, &host->pending_events)
230 +#define mci_clear_stop_sent_is_pending(host) \
231 + test_and_clear_bit(EVENT_STOP_SENT, &host->pending_events)
232 +#define mci_clear_stop_is_pending(host) \
233 + test_and_clear_bit(EVENT_STOP_COMPLETE, &host->pending_events)
234 +#define mci_clear_stop_error_is_pending(host) \
235 + test_and_clear_bit(EVENT_STOP_ERROR, &host->pending_events)
236 +#define mci_clear_dma_error_is_pending(host) \
237 + test_and_clear_bit(EVENT_DMA_ERROR, &host->pending_events)
238 +#define mci_clear_card_detect_is_pending(host) \
239 + test_and_clear_bit(EVENT_CARD_DETECT, &host->pending_events)
241 +/* Test and set bit macros for completed events */
242 +#define mci_set_cmd_is_completed(host) \
243 + test_and_set_bit(EVENT_CMD_COMPLETE, &host->completed_events)
244 +#define mci_set_cmd_error_is_completed(host) \
245 + test_and_set_bit(EVENT_CMD_ERROR, &host->completed_events)
246 +#define mci_set_data_is_completed(host) \
247 + test_and_set_bit(EVENT_DATA_COMPLETE, &host->completed_events)
248 +#define mci_set_data_error_is_completed(host) \
249 + test_and_set_bit(EVENT_DATA_ERROR, &host->completed_events)
250 +#define mci_set_stop_sent_is_completed(host) \
251 + test_and_set_bit(EVENT_STOP_SENT, &host->completed_events)
252 +#define mci_set_stop_is_completed(host) \
253 + test_and_set_bit(EVENT_STOP_COMPLETE, &host->completed_events)
254 +#define mci_set_stop_error_is_completed(host) \
255 + test_and_set_bit(EVENT_STOP_ERROR, &host->completed_events)
256 +#define mci_set_dma_error_is_completed(host) \
257 + test_and_set_bit(EVENT_DMA_ERROR, &host->completed_events)
258 +#define mci_set_card_detect_is_completed(host) \
259 + test_and_set_bit(EVENT_CARD_DETECT, &host->completed_events)
261 +/* Set bit macros for completed events */
262 +#define mci_set_cmd_complete(host) \
263 + set_bit(EVENT_CMD_COMPLETE, &host->completed_events)
264 +#define mci_set_cmd_error_complete(host) \
265 + set_bit(EVENT_CMD_ERROR, &host->completed_events)
266 +#define mci_set_data_complete(host) \
267 + set_bit(EVENT_DATA_COMPLETE, &host->completed_events)
268 +#define mci_set_data_error_complete(host) \
269 + set_bit(EVENT_DATA_ERROR, &host->completed_events)
270 +#define mci_set_stop_sent_complete(host) \
271 + set_bit(EVENT_STOP_SENT, &host->completed_events)
272 +#define mci_set_stop_complete(host) \
273 + set_bit(EVENT_STOP_COMPLETE, &host->completed_events)
274 +#define mci_set_stop_error_complete(host) \
275 + set_bit(EVENT_STOP_ERROR, &host->completed_events)
276 +#define mci_set_dma_error_complete(host) \
277 + set_bit(EVENT_DMA_ERROR, &host->completed_events)
278 +#define mci_set_card_detect_complete(host) \
279 + set_bit(EVENT_CARD_DETECT, &host->completed_events)
281 +/* Set bit macros for pending events */
282 +#define mci_set_cmd_pending(host) \
283 + set_bit(EVENT_CMD_COMPLETE, &host->pending_events)
284 +#define mci_set_cmd_error_pending(host) \
285 + set_bit(EVENT_CMD_ERROR, &host->pending_events)
286 +#define mci_set_data_pending(host) \
287 + set_bit(EVENT_DATA_COMPLETE, &host->pending_events)
288 +#define mci_set_data_error_pending(host) \
289 + set_bit(EVENT_DATA_ERROR, &host->pending_events)
290 +#define mci_set_stop_sent_pending(host) \
291 + set_bit(EVENT_STOP_SENT, &host->pending_events)
292 +#define mci_set_stop_pending(host) \
293 + set_bit(EVENT_STOP_COMPLETE, &host->pending_events)
294 +#define mci_set_stop_error_pending(host) \
295 + set_bit(EVENT_STOP_ERROR, &host->pending_events)
296 +#define mci_set_dma_error_pending(host) \
297 + set_bit(EVENT_DMA_ERROR, &host->pending_events)
298 +#define mci_set_card_detect_pending(host) \
299 + set_bit(EVENT_CARD_DETECT, &host->pending_events)
301 +/* Clear bit macros for pending events */
302 +#define mci_clear_cmd_pending(host) \
303 + clear_bit(EVENT_CMD_COMPLETE, &host->pending_events)
304 +#define mci_clear_cmd_error_pending(host) \
305 + clear_bit(EVENT_CMD_ERROR, &host->pending_events)
306 +#define mci_clear_data_pending(host) \
307 + clear_bit(EVENT_DATA_COMPLETE, &host->pending_events)
308 +#define mci_clear_data_error_pending(host) \
309 + clear_bit(EVENT_DATA_ERROR, &host->pending_events)
310 +#define mci_clear_stop_sent_pending(host) \
311 + clear_bit(EVENT_STOP_SENT, &host->pending_events)
312 +#define mci_clear_stop_pending(host) \
313 + clear_bit(EVENT_STOP_COMPLETE, &host->pending_events)
314 +#define mci_clear_stop_error_pending(host) \
315 + clear_bit(EVENT_STOP_ERROR, &host->pending_events)
316 +#define mci_clear_dma_error_pending(host) \
317 + clear_bit(EVENT_DMA_ERROR, &host->pending_events)
318 +#define mci_clear_card_detect_pending(host) \
319 + clear_bit(EVENT_CARD_DETECT, &host->pending_events)
321 #endif /* __DRIVERS_MMC_ATMEL_MCI_H__ */