2 * linux/drivers/mmc/host/glamo-mmc.c - Glamo MMC driver
4 * Copyright (C) 2007 Openmoko, Inc, Andy Green <andy@openmoko.com>
5 * Based on S3C MMC driver that was:
6 * Copyright (C) 2004-2006 maintech GmbH, Thomas Kleffel <tk@maintech.de>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/module.h>
14 #include <linux/mmc/mmc.h>
15 #include <linux/mmc/sd.h>
16 #include <linux/mmc/host.h>
17 #include <linux/platform_device.h>
18 #include <linux/irq.h>
19 #include <linux/delay.h>
20 #include <linux/interrupt.h>
21 #include <linux/spinlock.h>
22 #include <linux/workqueue.h>
23 #include <linux/crc7.h>
24 #include <linux/scatterlist.h>
26 #include <linux/regulator/consumer.h>
27 #include <linux/mfd/glamo.h>
29 #include "glamo-core.h"
30 #include "glamo-regs.h"
32 #define DRIVER_NAME "glamo-mci"
34 struct glamo_mci_host
{
35 struct platform_device
*pdev
;
36 struct glamo_mmc_platform_data
*pdata
;
38 struct resource
*mmio_mem
;
39 struct resource
*data_mem
;
40 void __iomem
*mmio_base
;
41 u16 __iomem
*data_base
;
43 struct regulator
*regulator
;
44 struct mmc_request
*mrq
;
46 unsigned int clk_rate
;
51 unsigned char request_counter
;
53 struct timer_list disable_timer
;
55 struct work_struct irq_work
;
57 unsigned clk_enabled
: 1;
60 static void glamo_mci_send_request(struct mmc_host
*mmc
, struct mmc_request
* mrq
);
61 static void glamo_mci_send_command(struct glamo_mci_host
*host
,
62 struct mmc_command
*cmd
);
67 * held at /(3 + 1) due to concerns of 100R recommended series resistor
68 * allows 16MHz @ 4-bit --> 8MBytes/sec raw
70 * you can override this on kernel commandline using
72 * glamo_mci.sd_max_clk=10000000
77 static int sd_max_clk
= 50000000;
78 module_param(sd_max_clk
, int, 0644);
83 * you can override this on kernel commandline using
85 * glamo_mci.sd_slow_ratio=8
89 * platform callback is used to decide effective clock rate, if not
90 * defined then max is used, if defined and returns nonzero, rate is
91 * divided by this factor
94 static int sd_slow_ratio
= 8;
95 module_param(sd_slow_ratio
, int, 0644);
98 * Post-power SD clock rate
100 * you can override this on kernel commandline using
102 * glamo_mci.sd_post_power_clock=1000000
106 * After changing power to card, clock is held at this rate until first bulk
110 static int sd_post_power_clock
= 1000000;
111 module_param(sd_post_power_clock
, int, 0644);
114 static inline void glamo_reg_write(struct glamo_mci_host
*glamo
,
115 u_int16_t reg
, u_int16_t val
)
117 writew(val
, glamo
->mmio_base
+ reg
);
120 static inline u_int16_t
glamo_reg_read(struct glamo_mci_host
*glamo
,
123 return readw(glamo
->mmio_base
+ reg
);
126 static void glamo_reg_set_bit_mask(struct glamo_mci_host
*glamo
,
127 u_int16_t reg
, u_int16_t mask
,
134 tmp
= glamo_reg_read(glamo
, reg
);
137 glamo_reg_write(glamo
, reg
, tmp
);
140 static void glamo_mci_clock_disable(struct glamo_mci_host
*host
) {
141 if (host
->clk_enabled
) {
142 /* glamo_engine_div_disable(host->pdata->core, GLAMO_ENGINE_MMC);*/
143 host
->clk_enabled
= 0;
144 printk("clk disabled\n");
148 static void glamo_mci_clock_enable(struct glamo_mci_host
*host
) {
149 del_timer_sync(&host
->disable_timer
);
151 if (!host
->clk_enabled
) {
152 glamo_engine_div_enable(host
->pdata
->core
, GLAMO_ENGINE_MMC
);
153 host
->clk_enabled
= 1;
154 printk("clk enabled\n");
158 static void glamo_mci_disable_timer(unsigned long data
) {
159 struct glamo_mci_host
*host
= (struct glamo_mci_host
*)data
;
160 glamo_mci_clock_disable(host
);
164 static void do_pio_read(struct glamo_mci_host
*host
, struct mmc_data
*data
)
166 struct scatterlist
*sg
;
167 u16 __iomem
*from_ptr
= host
->data_base
;
170 dev_dbg(&host
->pdev
->dev
, "pio_read():\n");
171 for (sg
= data
->sg
; sg
; sg
= sg_next(sg
)) {
172 sg_pointer
= page_address(sg_page(sg
)) + sg
->offset
;
175 memcpy(sg_pointer
, from_ptr
, sg
->length
);
176 from_ptr
+= sg
->length
>> 1;
178 data
->bytes_xfered
+= sg
->length
;
181 dev_dbg(&host
->pdev
->dev
, "pio_read(): "
182 "complete (no more data).\n");
185 static void do_pio_write(struct glamo_mci_host
*host
, struct mmc_data
*data
)
187 struct scatterlist
*sg
;
188 u16 __iomem
*to_ptr
= host
->data_base
;
191 dev_dbg(&host
->pdev
->dev
, "pio_write():\n");
192 for (sg
= data
->sg
; sg
; sg
= sg_next(sg
)) {
193 sg_pointer
= page_address(sg_page(sg
)) + sg
->offset
;
195 data
->bytes_xfered
+= sg
->length
;
197 memcpy(to_ptr
, sg_pointer
, sg
->length
);
198 to_ptr
+= sg
->length
>> 1;
201 dev_dbg(&host
->pdev
->dev
, "pio_write(): complete\n");
204 static int glamo_mci_set_card_clock(struct glamo_mci_host
*host
, int freq
)
209 glamo_mci_clock_enable(host
);
210 real_rate
= glamo_engine_reclock(host
->pdata
->core
, GLAMO_ENGINE_MMC
, freq
);
212 glamo_mci_clock_disable(host
);
218 static void glamo_mci_request_done(struct glamo_mci_host
*host
, struct
220 mod_timer(&host
->disable_timer
, jiffies
+ HZ
/ 16);
222 mmc_request_done(host
->mmc
, mrq
);
226 static void glamo_mci_irq_worker(struct work_struct
*work
)
228 struct glamo_mci_host
*host
= container_of(work
, struct glamo_mci_host
,
230 struct mmc_command
*cmd
;
233 if (!host
->mrq
|| !host
->mrq
->cmd
)
236 cmd
= host
->mrq
->cmd
;
238 status
= glamo_reg_read(host
, GLAMO_REG_MMC_RB_STAT1
);
239 dev_dbg(&host
->pdev
->dev
, "status = 0x%04x\n", status
);
241 /* we ignore a data timeout report if we are also told the data came */
242 if (status
& GLAMO_STAT1_MMC_RB_DRDY
)
243 status
&= ~GLAMO_STAT1_MMC_DTOUT
;
245 if (status
& (GLAMO_STAT1_MMC_RTOUT
|
246 GLAMO_STAT1_MMC_DTOUT
))
247 cmd
->error
= -ETIMEDOUT
;
248 if (status
& (GLAMO_STAT1_MMC_BWERR
|
249 GLAMO_STAT1_MMC_BRERR
))
250 cmd
->error
= -EILSEQ
;
252 dev_info(&host
->pdev
->dev
, "Error after cmd: 0x%x\n", status
);
256 /* issue STOP if we have been given one to use */
258 glamo_mci_send_command(host
, host
->mrq
->stop
);
260 if (cmd
->data
->flags
& MMC_DATA_READ
)
261 do_pio_read(host
, cmd
->data
);
265 glamo_mci_request_done(host
, cmd
->mrq
);
268 static irqreturn_t
glamo_mci_irq(int irq
, void *devid
)
270 struct glamo_mci_host
*host
= (struct glamo_mci_host
*)devid
;
272 schedule_work(&host
->irq_work
);
277 static void glamo_mci_send_command(struct glamo_mci_host
*host
,
278 struct mmc_command
*cmd
)
282 unsigned int timeout
= 1000000;
283 u16
* reg_resp
= (u16
*)(host
->mmio_base
+ GLAMO_REG_MMC_CMD_RSP1
);
285 int triggers_int
= 1;
287 /* if we can't do it, reject as busy */
288 if (!glamo_reg_read(host
, GLAMO_REG_MMC_RB_STAT1
) &
289 GLAMO_STAT1_MMC_IDLE
) {
294 /* create an array in wire order for CRC computation */
295 u8a
[0] = 0x40 | (cmd
->opcode
& 0x3f);
296 u8a
[1] = (u8
)(cmd
->arg
>> 24);
297 u8a
[2] = (u8
)(cmd
->arg
>> 16);
298 u8a
[3] = (u8
)(cmd
->arg
>> 8);
299 u8a
[4] = (u8
)cmd
->arg
;
300 u8a
[5] = (crc7(0, u8a
, 5) << 1) | 0x01; /* crc7 on first 5 bytes of packet */
302 /* issue the wire-order array including CRC in register order */
303 glamo_reg_write(host
, GLAMO_REG_MMC_CMD_REG1
, ((u8a
[4] << 8) | u8a
[5]));
304 glamo_reg_write(host
, GLAMO_REG_MMC_CMD_REG2
, ((u8a
[2] << 8) | u8a
[3]));
305 glamo_reg_write(host
, GLAMO_REG_MMC_CMD_REG3
, ((u8a
[0] << 8) | u8a
[1]));
307 /* command index toggle */
308 fire
|= (host
->request_counter
& 1) << 12;
310 /* set type of command */
311 switch (mmc_cmd_type(cmd
)) {
313 fire
|= GLAMO_FIRE_MMC_CMDT_BNR
;
316 fire
|= GLAMO_FIRE_MMC_CMDT_BR
;
319 fire
|= GLAMO_FIRE_MMC_CMDT_AND
;
322 fire
|= GLAMO_FIRE_MMC_CMDT_AD
;
326 * if it expects a response, set the type expected
328 * R1, Length : 48bit, Normal response
329 * R1b, Length : 48bit, same R1, but added card busy status
330 * R2, Length : 136bit (really 128 bits with CRC snipped)
331 * R3, Length : 48bit (OCR register value)
332 * R4, Length : 48bit, SDIO_OP_CONDITION, Reverse SDIO Card
333 * R5, Length : 48bit, IO_RW_DIRECTION, Reverse SDIO Card
334 * R6, Length : 48bit (RCA register)
335 * R7, Length : 48bit (interface condition, VHS(voltage supplied),
336 * check pattern, CRC7)
338 switch (mmc_resp_type(cmd
)) {
339 case MMC_RSP_R1
: /* same index as R6 and R7 */
340 fire
|= GLAMO_FIRE_MMC_RSPT_R1
;
343 fire
|= GLAMO_FIRE_MMC_RSPT_R1b
;
346 fire
|= GLAMO_FIRE_MMC_RSPT_R2
;
349 fire
|= GLAMO_FIRE_MMC_RSPT_R3
;
351 /* R4 and R5 supported by chip not defined in linux/mmc/core.h (sdio) */
354 * From the command index, set up the command class in the host ctrllr
356 * missing guys present on chip but couldn't figure out how to use yet:
358 * 0x9 "cancel running command"
360 switch (cmd
->opcode
) {
361 case MMC_READ_SINGLE_BLOCK
:
362 fire
|= GLAMO_FIRE_MMC_CC_SBR
; /* single block read */
364 case MMC_SWITCH
: /* 64 byte payload */
365 case SD_APP_SEND_SCR
:
366 case MMC_READ_MULTIPLE_BLOCK
:
367 /* we will get an interrupt off this */
369 /* multiblock no stop */
370 fire
|= GLAMO_FIRE_MMC_CC_MBRNS
;
372 /* multiblock with stop */
373 fire
|= GLAMO_FIRE_MMC_CC_MBRS
;
375 case MMC_WRITE_BLOCK
:
376 fire
|= GLAMO_FIRE_MMC_CC_SBW
; /* single block write */
378 case MMC_WRITE_MULTIPLE_BLOCK
:
380 /* multiblock with stop */
381 fire
|= GLAMO_FIRE_MMC_CC_MBWS
;
383 /* multiblock NO stop-- 'RESERVED'? */
384 fire
|= GLAMO_FIRE_MMC_CC_MBWNS
;
386 case MMC_STOP_TRANSMISSION
:
387 fire
|= GLAMO_FIRE_MMC_CC_STOP
; /* STOP */
391 fire
|= GLAMO_FIRE_MMC_CC_BASIC
; /* "basic command" */
397 host
->mrq
= cmd
->mrq
;
399 /* always largest timeout */
400 glamo_reg_write(host
, GLAMO_REG_MMC_TIMEOUT
, 0xfff);
402 /* Generate interrupt on txfer */
403 glamo_reg_set_bit_mask(host
, GLAMO_REG_MMC_BASIC
, 0xff36,
405 GLAMO_BASIC_MMC_NO_CLK_RD_WAIT
|
406 GLAMO_BASIC_MMC_EN_COMPL_INT
|
407 GLAMO_BASIC_MMC_EN_DATA_PUPS
|
408 GLAMO_BASIC_MMC_EN_CMD_PUP
);
410 /* send the command out on the wire */
411 /* dev_info(&host->pdev->dev, "Using FIRE %04X\n", fire); */
412 glamo_reg_write(host
, GLAMO_REG_MMC_CMD_FIRE
, fire
);
414 /* we are deselecting card? because it isn't going to ack then... */
415 if ((cmd
->opcode
== 7) && (cmd
->arg
== 0))
419 * we must spin until response is ready or timed out
420 * -- we don't get interrupts unless there is a bulk rx
423 status
= glamo_reg_read(host
, GLAMO_REG_MMC_RB_STAT1
);
424 while (((((status
>> 15) & 1) != (host
->request_counter
& 1)) ||
425 (!(status
& (GLAMO_STAT1_MMC_RB_RRDY
|
426 GLAMO_STAT1_MMC_RTOUT
|
427 GLAMO_STAT1_MMC_DTOUT
|
428 GLAMO_STAT1_MMC_BWERR
|
429 GLAMO_STAT1_MMC_BRERR
)))) && (timeout
--));
431 if ((status
& (GLAMO_STAT1_MMC_RTOUT
|
432 GLAMO_STAT1_MMC_DTOUT
)) ||
434 cmd
->error
= -ETIMEDOUT
;
435 } else if (status
& (GLAMO_STAT1_MMC_BWERR
|
436 GLAMO_STAT1_MMC_BRERR
)) {
437 cmd
->error
= -EILSEQ
;
440 if (cmd
->flags
& MMC_RSP_PRESENT
) {
441 if (cmd
->flags
& MMC_RSP_136
) {
442 cmd
->resp
[3] = readw(®_resp
[0]) |
443 (readw(®_resp
[1]) << 16);
444 cmd
->resp
[2] = readw(®_resp
[2]) |
445 (readw(®_resp
[3]) << 16);
446 cmd
->resp
[1] = readw(®_resp
[4]) |
447 (readw(®_resp
[5]) << 16);
448 cmd
->resp
[0] = readw(®_resp
[6]) |
449 (readw(®_resp
[7]) << 16);
451 cmd
->resp
[0] = (readw(®_resp
[0]) >> 8) |
452 (readw(®_resp
[1]) << 8) |
453 ((readw(®_resp
[2])) << 24);
458 static int glamo_mci_prepare_pio(struct glamo_mci_host
*host
,
459 struct mmc_data
*data
)
461 /* set up the block info */
462 glamo_reg_write(host
, GLAMO_REG_MMC_DATBLKLEN
, data
->blksz
);
463 glamo_reg_write(host
, GLAMO_REG_MMC_DATBLKCNT
, data
->blocks
);
465 data
->bytes_xfered
= 0;
467 /* if write, prep the write into the shared RAM before the command */
468 if (data
->flags
& MMC_DATA_WRITE
) {
469 do_pio_write(host
, data
);
472 dev_dbg(&host
->pdev
->dev
, "(blksz=%d, count=%d)\n",
473 data
->blksz
, data
->blocks
);
477 static int glamo_mci_irq_poll(struct glamo_mci_host
*host
,
478 struct mmc_command
*cmd
)
480 int timeout
= 1000000;
482 * if the glamo INT# line isn't wired (*cough* it can happen)
483 * I'm afraid we have to spin on the IRQ status bit and "be
487 * we have faith we will get an "interrupt"...
488 * but something insane like suspend problems can mean
489 * we spin here forever, so we timeout after a LONG time
491 while ((!(readw(host
->pdata
->core
->base
+
492 GLAMO_REG_IRQ_STATUS
) & GLAMO_IRQ_MMC
)) &&
496 if (cmd
->data
->error
)
497 cmd
->data
->error
= -ETIMEDOUT
;
498 dev_err(&host
->pdev
->dev
, "Payload timeout\n");
501 /* ack this interrupt source */
502 writew(GLAMO_IRQ_MMC
, host
->pdata
->core
->base
+
503 GLAMO_REG_IRQ_CLEAR
);
505 /* yay we are an interrupt controller! -- call the ISR
506 * it will stop clock to card
508 glamo_mci_irq(IRQ_GLAMO(GLAMO_IRQIDX_MMC
), host
);
513 static void glamo_mci_send_request(struct mmc_host
*mmc
, struct mmc_request
*mrq
)
515 struct glamo_mci_host
*host
= mmc_priv(mmc
);
516 struct mmc_command
*cmd
= mrq
->cmd
;
518 host
->request_counter
++;
520 if(glamo_mci_prepare_pio(host
, cmd
->data
)) {
521 cmd
->data
->error
= -EIO
;
526 dev_dbg(&host
->pdev
->dev
,"cmd 0x%x, "
527 "arg 0x%x data=%p mrq->stop=%p flags 0x%x\n",
528 cmd
->opcode
, cmd
->arg
, cmd
->data
, cmd
->mrq
->stop
,
531 glamo_mci_clock_enable(host
);
532 glamo_mci_send_command(host
, cmd
);
535 * if we don't have bulk data to take care of, we're done
537 if (!cmd
->data
|| cmd
->error
)
541 if (!host
->pdata
->core
->irq_works
) {
542 if (glamo_mci_irq_poll(host
, mrq
->cmd
))
547 * Otherwise can can use the interrupt as async completion --
548 * if there is read data coming, or we wait for write data to complete,
549 * exit without mmc_request_done() as the payload interrupt
552 dev_dbg(&host
->pdev
->dev
, "Waiting for payload data\n");
555 glamo_mci_request_done(host
, mrq
);
558 static void glamo_mci_set_power_mode(struct glamo_mci_host
*host
,
559 unsigned char power_mode
) {
562 if (power_mode
== host
->power_mode
)
567 if (host
->power_mode
== MMC_POWER_OFF
) {
568 ret
= regulator_enable(host
->regulator
);
570 dev_err(&host
->pdev
->dev
, "Failed to enable regulator: %d\n", ret
);
577 glamo_engine_disable(host
->pdata
->core
,
580 ret
= regulator_disable(host
->regulator
);
582 dev_warn(&host
->pdev
->dev
, "Failed to disable regulator: %d\n", ret
);
585 host
->power_mode
= power_mode
;
588 static void glamo_mci_set_ios(struct mmc_host
*mmc
, struct mmc_ios
*ios
)
590 struct glamo_mci_host
*host
= mmc_priv(mmc
);
597 glamo_mci_set_power_mode(host
, ios
->power_mode
);
599 if (host
->vdd
!= ios
->vdd
) {
600 ret
= mmc_regulator_set_ocr(host
->regulator
, ios
->vdd
);
602 dev_err(&host
->pdev
->dev
, "Failed to set regulator voltage: %d\n", ret
);
604 host
->vdd
= ios
->vdd
;
606 rate
= glamo_mci_set_card_clock(host
, ios
->clock
);
608 if ((ios
->power_mode
== MMC_POWER_ON
) ||
609 (ios
->power_mode
== MMC_POWER_UP
)) {
610 dev_info(&host
->pdev
->dev
,
611 "powered (vdd = %hu) clk: %dkHz div=%hu (req: %ukHz). "
612 "Bus width=%d\n", ios
->vdd
,
614 ios
->clock
/ 1000, (int)ios
->bus_width
);
616 dev_info(&host
->pdev
->dev
, "glamo_mci_set_ios: power down.\n");
620 if (ios
->bus_width
== MMC_BUS_WIDTH_4
)
621 bus_width
= GLAMO_BASIC_MMC_EN_4BIT_DATA
;
623 sd_drive
= (rate
* 4) / host
->clk_rate
;
627 glamo_reg_set_bit_mask(host
, GLAMO_REG_MMC_BASIC
,
628 GLAMO_BASIC_MMC_EN_4BIT_DATA
| 0xb0,
629 bus_width
| sd_drive
<< 6);
634 * no physical write protect supported by us
636 static int glamo_mci_get_ro(struct mmc_host
*mmc
)
641 static struct mmc_host_ops glamo_mci_ops
= {
642 .request
= glamo_mci_send_request
,
643 .set_ios
= glamo_mci_set_ios
,
644 .get_ro
= glamo_mci_get_ro
,
647 static int glamo_mci_probe(struct platform_device
*pdev
)
649 struct mmc_host
*mmc
;
650 struct glamo_mci_host
*host
;
653 dev_info(&pdev
->dev
, "glamo_mci driver (C)2007 Openmoko, Inc\n");
655 mmc
= mmc_alloc_host(sizeof(struct glamo_mci_host
), &pdev
->dev
);
661 host
= mmc_priv(mmc
);
664 host
->pdata
= pdev
->dev
.platform_data
;
665 host
->power_mode
= MMC_POWER_OFF
;
666 host
->clk_enabled
= 0;
668 INIT_WORK(&host
->irq_work
, glamo_mci_irq_worker
);
670 host
->regulator
= regulator_get(pdev
->dev
.parent
, "SD_3V3");
671 if (!host
->regulator
) {
672 dev_err(&pdev
->dev
, "Cannot proceed without regulator.\n");
674 goto probe_free_host
;
677 host
->mmio_mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
678 if (!host
->mmio_mem
) {
680 "failed to get io memory region resouce.\n");
682 goto probe_regulator_put
;
685 host
->mmio_mem
= request_mem_region(host
->mmio_mem
->start
,
686 resource_size(host
->mmio_mem
),
689 if (!host
->mmio_mem
) {
690 dev_err(&pdev
->dev
, "failed to request io memory region.\n");
692 goto probe_regulator_put
;
695 host
->mmio_base
= ioremap(host
->mmio_mem
->start
,
696 resource_size(host
->mmio_mem
));
697 if (!host
->mmio_base
) {
698 dev_err(&pdev
->dev
, "failed to ioremap() io memory region.\n");
700 goto probe_free_mem_region_mmio
;
704 /* Get ahold of our data buffer we use for data in and out on MMC */
705 host
->data_mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
706 if (!host
->data_mem
) {
708 "failed to get io memory region resource.\n");
710 goto probe_iounmap_mmio
;
713 host
->data_mem
= request_mem_region(host
->data_mem
->start
,
714 resource_size(host
->data_mem
),
717 if (!host
->data_mem
) {
718 dev_err(&pdev
->dev
, "failed to request io memory region.\n");
720 goto probe_iounmap_mmio
;
722 host
->data_base
= ioremap(host
->data_mem
->start
,
723 resource_size(host
->data_mem
));
725 if (host
->data_base
== 0) {
726 dev_err(&pdev
->dev
, "failed to ioremap() io memory region.\n");
728 goto probe_free_mem_region_data
;
731 ret
= request_irq(IRQ_GLAMO(GLAMO_IRQIDX_MMC
), glamo_mci_irq
, IRQF_SHARED
,
734 dev_err(&pdev
->dev
, "failed to register irq.\n");
735 goto probe_iounmap_data
;
740 host
->clk_rate
= glamo_pll_rate(host
->pdata
->core
, GLAMO_PLL1
);
742 /* explain our host controller capabilities */
743 mmc
->ops
= &glamo_mci_ops
;
744 mmc
->ocr_avail
= mmc_regulator_get_ocrmask(host
->regulator
);
745 mmc
->caps
= MMC_CAP_4_BIT_DATA
|
746 MMC_CAP_MMC_HIGHSPEED
|
747 MMC_CAP_SD_HIGHSPEED
;
748 mmc
->f_min
= host
->clk_rate
/ 256;
749 mmc
->f_max
= host
->clk_rate
;
751 mmc
->max_blk_count
= (1 << 16) - 1; /* GLAMO_REG_MMC_RB_BLKCNT */
752 mmc
->max_blk_size
= (1 << 12) - 1; /* GLAMO_REG_MMC_RB_BLKLEN */
753 mmc
->max_req_size
= resource_size(host
->data_mem
);
754 mmc
->max_seg_size
= mmc
->max_req_size
;
755 mmc
->max_phys_segs
= 128;
756 mmc
->max_hw_segs
= 128;
758 if (mmc
->ocr_avail
< 0) {
759 dev_warn(&pdev
->dev
, "Failed to get ocr list for regulator: %d.\n",
761 mmc
->ocr_avail
= MMC_VDD_32_33
| MMC_VDD_33_34
;
764 platform_set_drvdata(pdev
, mmc
);
766 glamo_engine_enable(host
->pdata
->core
, GLAMO_ENGINE_MMC
);
767 glamo_engine_reset(host
->pdata
->core
, GLAMO_ENGINE_MMC
);
769 glamo_reg_write(host
, GLAMO_REG_MMC_WDATADS1
,
770 (u16
)(host
->data_mem
->start
));
771 glamo_reg_write(host
, GLAMO_REG_MMC_WDATADS2
,
772 (u16
)(host
->data_mem
->start
>> 16));
774 glamo_reg_write(host
, GLAMO_REG_MMC_RDATADS1
,
775 (u16
)(host
->data_mem
->start
));
776 glamo_reg_write(host
, GLAMO_REG_MMC_RDATADS2
,
777 (u16
)(host
->data_mem
->start
>> 16));
779 setup_timer(&host
->disable_timer
, glamo_mci_disable_timer
,
780 (unsigned long)host
);
782 if ((ret
= mmc_add_host(mmc
))) {
783 dev_err(&pdev
->dev
, "failed to add mmc host.\n");
787 dev_info(&pdev
->dev
,"initialisation done.\n");
791 free_irq(IRQ_GLAMO(GLAMO_IRQIDX_MMC
), host
);
793 iounmap(host
->data_base
);
794 probe_free_mem_region_data
:
795 release_mem_region(host
->data_mem
->start
, resource_size(host
->data_mem
));
797 iounmap(host
->mmio_base
);
798 probe_free_mem_region_mmio
:
799 release_mem_region(host
->mmio_mem
->start
, resource_size(host
->mmio_mem
));
801 regulator_put(host
->regulator
);
808 static int glamo_mci_remove(struct platform_device
*pdev
)
810 struct mmc_host
*mmc
= platform_get_drvdata(pdev
);
811 struct glamo_mci_host
*host
= mmc_priv(mmc
);
813 free_irq(IRQ_GLAMO(GLAMO_IRQIDX_MMC
), host
);
815 mmc_remove_host(mmc
);
816 iounmap(host
->mmio_base
);
817 iounmap(host
->data_base
);
818 release_mem_region(host
->mmio_mem
->start
, resource_size(host
->mmio_mem
));
819 release_mem_region(host
->data_mem
->start
, resource_size(host
->data_mem
));
821 regulator_put(host
->regulator
);
825 glamo_engine_disable(host
->pdata
->core
, GLAMO_ENGINE_MMC
);
832 static int glamo_mci_suspend(struct platform_device
*dev
, pm_message_t state
)
834 struct mmc_host
*mmc
= platform_get_drvdata(dev
);
835 struct glamo_mci_host
*host
= mmc_priv(mmc
);
838 cancel_work_sync(&host
->irq_work
);
840 ret
= mmc_suspend_host(mmc
, state
);
841 glamo_mci_clock_enable(host
);
846 static int glamo_mci_resume(struct platform_device
*dev
)
848 struct mmc_host
*mmc
= platform_get_drvdata(dev
);
849 struct glamo_mci_host
*host
= mmc_priv(mmc
);
852 glamo_engine_enable(host
->pdata
->core
, GLAMO_ENGINE_MMC
);
853 glamo_engine_reset(host
->pdata
->core
, GLAMO_ENGINE_MMC
);
855 glamo_reg_write(host
, GLAMO_REG_MMC_WDATADS1
,
856 (u16
)(host
->data_mem
->start
));
857 glamo_reg_write(host
, GLAMO_REG_MMC_WDATADS2
,
858 (u16
)(host
->data_mem
->start
>> 16));
860 glamo_reg_write(host
, GLAMO_REG_MMC_RDATADS1
,
861 (u16
)(host
->data_mem
->start
));
862 glamo_reg_write(host
, GLAMO_REG_MMC_RDATADS2
,
863 (u16
)(host
->data_mem
->start
>> 16));
866 ret
= mmc_resume_host(host
->mmc
);
867 /* glamo_mci_clock_disable(host);*/
871 EXPORT_SYMBOL_GPL(glamo_mci_resume
);
873 #else /* CONFIG_PM */
874 #define glamo_mci_suspend NULL
875 #define glamo_mci_resume NULL
876 #endif /* CONFIG_PM */
879 static struct platform_driver glamo_mci_driver
=
881 .driver
.name
= "glamo-mci",
882 .probe
= glamo_mci_probe
,
883 .remove
= glamo_mci_remove
,
884 .suspend
= glamo_mci_suspend
,
885 .resume
= glamo_mci_resume
,
888 static int __init
glamo_mci_init(void)
890 platform_driver_register(&glamo_mci_driver
);
894 static void __exit
glamo_mci_exit(void)
896 platform_driver_unregister(&glamo_mci_driver
);
899 module_init(glamo_mci_init
);
900 module_exit(glamo_mci_exit
);
902 MODULE_DESCRIPTION("Glamo MMC/SD Card Interface driver");
903 MODULE_LICENSE("GPL");
904 MODULE_AUTHOR("Andy Green <andy@openmoko.com>");