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 the Glamo MCI driver that was -->
7 * Copyright (C) 2007 OpenMoko, Inc, Andy Green <andy@openmoko.com>
8 * Based on S3C MMC driver that was:
9 * Copyright (C) 2004-2006 maintech GmbH, Thomas Kleffel <tk@maintech.de>
13 * Based on S3C MMC driver that was (original copyright notice ---->)
15 * (C) Copyright 2006 by OpenMoko, Inc.
16 * Author: Harald Welte <laforge@openmoko.org>
18 * based on u-boot pxa MMC driver and linux/drivers/mmc/s3c2410mci.c
19 * (C) 2005-2005 Thomas Kleffel
21 * Copyright (C) 2004-2006 maintech GmbH, Thomas Kleffel <tk@maintech.de>
23 * This program is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License version 2 as
25 * published by the Free Software Foundation.
31 #include <asm/errno.h>
37 #include "glamo-regs.h"
38 #include "glamo-mmc.h"
40 #if defined(CONFIG_MMC) && defined(CONFIG_MMC_GLAMO)
42 #define MMC_BLOCK_SIZE_BITS 9
43 #define MMC_BLOCK_SIZE (1 << MMC_BLOCK_SIZE_BITS)
45 #define GLAMO_REG(x) (*(volatile u16 *)(CONFIG_GLAMO_BASE + x))
46 #define GLAMO_INTRAM_OFFSET (8 * 1024 * 1024)
47 #define GLAMO_FB_SIZE ((8 * 1024 * 1024) - 0x10000)
48 #define GLAMO_START_OF_MMC_INTMEM ((volatile u16 *)(CONFIG_GLAMO_BASE + \
49 GLAMO_INTRAM_OFFSET + GLAMO_FB_SIZE))
52 static block_dev_desc_t mmc_dev
;
53 static mmc_csd_t mmc_csd
;
54 static int mmc_ready
= 0;
56 static enum card_type card_type
= CARDTYPE_NONE
;
58 block_dev_desc_t
* mmc_get_dev(int dev
)
60 return (block_dev_desc_t
*)&mmc_dev
;
64 glamo_reg_write(u_int16_t val
, u_int16_t reg
)
70 glamo_reg_read(u_int16_t reg
)
72 return GLAMO_REG(reg
);
75 unsigned char CRC7(u8
* pu8
, int cnt
)
82 for (n
= 0; n
< 8; n
++) {
84 if ((d
& 0x80) ^ (crc
& 0x80))
89 return (crc
<< 1) | 1;
92 /* MMC_DEFAULT_RCA should probably be just 1, but this may break other code
93 that expects it to be shifted. */
94 static u_int16_t rca
= MMC_DEFAULT_RCA
>> 16;
96 static void do_pio_read(u16
*buf
, int count_words
)
98 volatile u16
*from_ptr
= GLAMO_START_OF_MMC_INTMEM
;
100 while (count_words
--)
101 *buf
++ = *from_ptr
++;
104 static void do_pio_write(u16
*buf
, int count_words
)
106 volatile u16
*to_ptr
= GLAMO_START_OF_MMC_INTMEM
;
108 while (count_words
--)
113 static int mmc_cmd(int opcode
, int arg
, int flags
,
114 int data_size
, int data_blocks
,
115 int will_stop
, u16
*resp
)
117 u16
* pu16
= (u16
*)&resp
[0];
118 u16
* reg_resp
= (u16
*)(CONFIG_GLAMO_BASE
+ GLAMO_REGOFS_MMC
+
119 GLAMO_REG_MMC_CMD_RSP1
);
128 printf("mmc_cmd(opcode=%d, arg=0x%08X, flags=0x%x, "
129 "data_size=%d, data_blocks=%d, will_stop=%d, resp=%p)\n",
130 opcode
, arg
, flags
, data_size
, data_blocks
, will_stop
, resp
);
133 case MMC_STOP_TRANSMISSION
:
142 /* this guy has data to read/write? */
143 if ((!cmd_is_stop
) && (flags
& (MMC_DATA_WRITE
| MMC_DATA_READ
))) {
145 * the S-Media-internal RAM offset for our MMC buffer
147 glamo_reg_write((u16
)GLAMO_FB_SIZE
,
148 GLAMO_REGOFS_MMC
+ GLAMO_REG_MMC_WDATADS1
);
149 glamo_reg_write((u16
)(GLAMO_FB_SIZE
>> 16),
150 GLAMO_REGOFS_MMC
+ GLAMO_REG_MMC_WDATADS2
);
151 glamo_reg_write((u16
)GLAMO_FB_SIZE
,
152 GLAMO_REGOFS_MMC
+ GLAMO_REG_MMC_RDATADS1
);
153 glamo_reg_write((u16
)(GLAMO_FB_SIZE
>> 16),
154 GLAMO_REGOFS_MMC
+ GLAMO_REG_MMC_RDATADS2
);
156 /* set up the block info */
157 glamo_reg_write(data_size
, GLAMO_REGOFS_MMC
+
158 GLAMO_REG_MMC_DATBLKLEN
);
159 glamo_reg_write(data_blocks
, GLAMO_REGOFS_MMC
+
160 GLAMO_REG_MMC_DATBLKCNT
);
163 /* if we can't do it, reject as busy */
164 if (!glamo_reg_read(GLAMO_REGOFS_MMC
+ GLAMO_REG_MMC_RB_STAT1
) &
165 GLAMO_STAT1_MMC_IDLE
)
168 /* create an array in wire order for CRC computation */
169 u8a
[0] = 0x40 | (opcode
& 0x3f);
170 u8a
[1] = (arg
>> 24);
171 u8a
[2] = (arg
>> 16);
174 u8a
[5] = CRC7(&u8a
[0], 5); /* CRC7 on first 5 bytes of packet */
176 /* issue the wire-order array including CRC in register order */
177 glamo_reg_write((u8a
[4] << 8) | u8a
[5],
178 GLAMO_REGOFS_MMC
+ GLAMO_REG_MMC_CMD_REG1
);
179 glamo_reg_write((u8a
[2] << 8) | u8a
[3],
180 GLAMO_REGOFS_MMC
+ GLAMO_REG_MMC_CMD_REG2
);
181 glamo_reg_write((u8a
[0] << 8) | u8a
[1],
182 GLAMO_REGOFS_MMC
+ GLAMO_REG_MMC_CMD_REG3
);
184 /* command index toggle */
185 fire
|= (ccnt
& 1) << 12;
187 /* set type of command */
188 switch (mmc_cmd_type(flags
)) {
190 fire
|= GLAMO_FIRE_MMC_CMDT_BNR
;
193 fire
|= GLAMO_FIRE_MMC_CMDT_BR
;
196 fire
|= GLAMO_FIRE_MMC_CMDT_AND
;
199 fire
|= GLAMO_FIRE_MMC_CMDT_AD
;
203 * if it expects a response, set the type expected
205 * R1, Length : 48bit, Normal response
206 * R1b, Length : 48bit, same R1, but added card busy status
207 * R2, Length : 136bit (really 128 bits with CRC snipped)
208 * R3, Length : 48bit (OCR register value)
209 * R4, Length : 48bit, SDIO_OP_CONDITION, Reverse SDIO Card
210 * R5, Length : 48bit, IO_RW_DIRECTION, Reverse SDIO Card
211 * R6, Length : 48bit (RCA register)
212 * R7, Length : 48bit (interface condition, VHS(voltage supplied),
213 * check pattern, CRC7)
215 switch (mmc_resp_type(flags
)) {
216 case MMC_RSP_R6
: /* same index as R7 and R1 */
217 fire
|= GLAMO_FIRE_MMC_RSPT_R1
;
220 fire
|= GLAMO_FIRE_MMC_RSPT_R1b
;
223 fire
|= GLAMO_FIRE_MMC_RSPT_R2
;
226 fire
|= GLAMO_FIRE_MMC_RSPT_R3
;
228 /* R4 and R5 supported by chip not defined in linux/mmc/core.h (sdio) */
231 * From the command index, set up the command class in the host ctrllr
233 * missing guys present on chip but couldn't figure out how to use yet:
235 * 0x9 "cancel running command"
238 case MMC_READ_SINGLE_BLOCK
:
239 fire
|= GLAMO_FIRE_MMC_CC_SBR
; /* single block read */
241 case MMC_SWITCH
: /* 64 byte payload */
242 case 0x33: /* observed issued by MCI */
243 case MMC_READ_MULTIPLE_BLOCK
:
244 /* we will get an interrupt off this */
246 /* multiblock no stop */
247 fire
|= GLAMO_FIRE_MMC_CC_MBRNS
;
249 /* multiblock with stop */
250 fire
|= GLAMO_FIRE_MMC_CC_MBRS
;
252 case MMC_WRITE_BLOCK
:
253 fire
|= GLAMO_FIRE_MMC_CC_SBW
; /* single block write */
255 case MMC_WRITE_MULTIPLE_BLOCK
:
257 /* multiblock with stop */
258 fire
|= GLAMO_FIRE_MMC_CC_MBWS
;
260 /* multiblock NO stop-- 'RESERVED'? */
261 fire
|= GLAMO_FIRE_MMC_CC_MBWNS
;
263 case MMC_STOP_TRANSMISSION
:
264 fire
|= GLAMO_FIRE_MMC_CC_STOP
; /* STOP */
267 fire
|= GLAMO_FIRE_MMC_CC_BASIC
; /* "basic command" */
270 /* enforce timeout */
271 glamo_reg_write(0xfff, GLAMO_REGOFS_MMC
+ GLAMO_REG_MMC_TIMEOUT
);
273 /* Generate interrupt on txfer; drive strength max */
274 glamo_reg_write((glamo_reg_read(GLAMO_REGOFS_MMC
+
275 GLAMO_REG_MMC_BASIC
) & 0xfe) |
276 0x0800 | GLAMO_BASIC_MMC_NO_CLK_RD_WAIT
|
277 GLAMO_BASIC_MMC_EN_COMPL_INT
|
278 GLAMO_BASIC_MMC_EN_DR_STR0
|
279 GLAMO_BASIC_MMC_EN_DR_STR1
,
280 GLAMO_REGOFS_MMC
+ GLAMO_REG_MMC_BASIC
);
282 /* send the command out on the wire */
283 /* dev_info(&host->pdev->dev, "Using FIRE %04X\n", fire); */
284 glamo_reg_write(fire
, GLAMO_REGOFS_MMC
+ GLAMO_REG_MMC_CMD_FIRE
);
287 * we must spin until response is ready or timed out
288 * -- we don't get interrupts unless there is a bulk rx
291 status
= glamo_reg_read(GLAMO_REGOFS_MMC
+
292 GLAMO_REG_MMC_RB_STAT1
);
293 while ((((status
>> 15) & 1) != (ccnt
& 1)) ||
294 (!(status
& (GLAMO_STAT1_MMC_RB_RRDY
|
295 GLAMO_STAT1_MMC_RTOUT
|
296 GLAMO_STAT1_MMC_DTOUT
|
297 GLAMO_STAT1_MMC_BWERR
|
298 GLAMO_STAT1_MMC_BRERR
))));
300 if (status
& (GLAMO_STAT1_MMC_RTOUT
| GLAMO_STAT1_MMC_DTOUT
))
302 if (status
& (GLAMO_STAT1_MMC_BWERR
| GLAMO_STAT1_MMC_BRERR
))
309 printf("cmd 0x%x, arg 0x%x flags 0x%x\n", opcode
, arg
, flags
);
310 printf("Error after cmd: 0x%x\n", error
);
314 * mangle the response registers in two different exciting
315 * undocumented ways discovered by trial and error
317 if (mmc_resp_type(flags
) == MMC_RSP_R2
)
318 /* grab the response */
319 for (n
= 0; n
< 8; n
++) /* super mangle power 1 */
320 pu16
[n
^ 6] = reg_resp
[n
];
322 for (n
= 0; n
< 3; n
++) /* super mangle power 2 */
323 pu16
[n
] = (reg_resp
[n
] >> 8) |
324 (reg_resp
[n
+ 1] << 8);
326 * if we don't have bulk data to take care of, we're done
328 if (!(flags
& (MMC_DATA_READ
| MMC_DATA_WRITE
)))
331 /* enforce timeout */
332 glamo_reg_write(0xfff, GLAMO_REGOFS_MMC
+ GLAMO_REG_MMC_TIMEOUT
);
336 while (!(glamo_reg_read(GLAMO_REG_IRQ_STATUS
) & GLAMO_IRQ_MMC
))
338 /* ack this interrupt source */
339 glamo_reg_write(GLAMO_IRQ_MMC
, GLAMO_REG_IRQ_CLEAR
);
341 if (status
& GLAMO_STAT1_MMC_DTOUT
)
343 if (status
& (GLAMO_STAT1_MMC_BWERR
| GLAMO_STAT1_MMC_BRERR
))
345 if (status
& GLAMO_STAT1_MMC_RTOUT
)
348 printf("cmd 0x%x, arg 0x%x flags 0x%x\n", opcode
, arg
, flags
);
349 printf("Error after resp: 0x%x\n", status
);
353 if (flags
& MMC_DATA_READ
) {
354 volatile u8
* pu8
= (volatile u8
*)GLAMO_START_OF_MMC_INTMEM
;
355 for (n
= 0; n
< 512; n
+= 16) {
357 for (n1
= 0; n1
< 16; n1
++) {
358 printf("%02X ", pu8
[n
+ n1
]);
370 static void glamo_mci_reset(void)
372 /* reset MMC controller */
373 glamo_reg_write(GLAMO_CLOCK_MMC_RESET
| GLAMO_CLOCK_MMC_DG_TCLK
|
374 GLAMO_CLOCK_MMC_EN_TCLK
| GLAMO_CLOCK_MMC_DG_M9CLK
|
375 GLAMO_CLOCK_MMC_EN_M9CLK
,
376 GLAMO_REG_CLOCK_MMC
);
378 /* and disable reset */
379 glamo_reg_write(GLAMO_CLOCK_MMC_DG_TCLK
|
380 GLAMO_CLOCK_MMC_EN_TCLK
| GLAMO_CLOCK_MMC_DG_M9CLK
|
381 GLAMO_CLOCK_MMC_EN_M9CLK
,
382 GLAMO_REG_CLOCK_MMC
);
386 static u_int8_t
ldo_voltage(unsigned int millivolts
)
388 if (millivolts
< 900)
390 else if (millivolts
> 3600)
394 return millivolts
/ 100;
398 int glamo_mmc_read(ulong src
, uint blksize
, uchar
*dst
, int size
)
402 int size_original
= size
;
404 if ((!size
) || (size
& (MMC_BLOCK_SIZE
- 1))) {
405 printf("Bad size %d\n", size
);
409 if (((int)dst
) & 1) {
410 printf("Bad align on dst\n");
414 resp
= mmc_cmd(MMC_SET_BLOCKLEN
, MMC_BLOCK_SIZE
,
415 MMC_CMD_AC
| MMC_RSP_R1
, 0, 0, 0,
416 (u16
*)&response
[0]);
420 case CARDTYPE_SDHC
: /* block addressing */
421 if (blksize
!= MMC_BLOCK_SIZE
) {
422 printf("Bad align on src\n");
425 resp
= mmc_cmd(MMC_READ_SINGLE_BLOCK
,
427 MMC_CMD_ADTC
| MMC_RSP_R1
|
428 MMC_DATA_READ
, MMC_BLOCK_SIZE
, 1, 0,
429 (u16
*)&response
[0]);
432 default: /* byte addressing */
433 resp
= mmc_cmd(MMC_READ_SINGLE_BLOCK
, src
* blksize
,
434 MMC_CMD_ADTC
| MMC_RSP_R1
| MMC_DATA_READ
,
435 MMC_BLOCK_SIZE
, 1, 0,
436 (u16
*)&response
[0]);
437 src
+= MMC_BLOCK_SIZE
/ blksize
;
440 do_pio_read((u16
*)dst
, MMC_BLOCK_SIZE
>> 1);
442 if (size
>= MMC_BLOCK_SIZE
)
443 size
-= MMC_BLOCK_SIZE
;
446 dst
+= MMC_BLOCK_SIZE
;
448 return size_original
;
451 ulong
mmc_bread(int dev_num
, ulong blknr
, ulong blkcnt
, void *dst
)
453 ulong size
= blkcnt
* MMC_BLOCK_SIZE
;
458 /* printf("mmc_bread(%d, %ld, %ld, %p)\n", dev_num, blknr, blkcnt, dst); */
459 glamo_mmc_read(blknr
, MMC_BLOCK_SIZE
, dst
, size
);
463 int mmc_read(ulong src
, uchar
*dst
, int size
)
465 if (src
& (MMC_BLOCK_SIZE
- 1))
466 return (glamo_mmc_read (src
, 1, dst
, size
));
468 return (glamo_mmc_read (src
>> MMC_BLOCK_SIZE_BITS
,
469 MMC_BLOCK_SIZE
, dst
, size
));
472 int mmc_write(uchar
*src
, ulong dst
, int size
)
476 int size_original
= size
;
478 if ((!size
) || (size
& (MMC_BLOCK_SIZE
- 1))) {
479 printf("Bad size %d\n", size
);
483 if (((int)dst
) & 1) {
484 printf("Bad align on dst\n");
488 resp
= mmc_cmd(MMC_SET_BLOCKLEN
, MMC_BLOCK_SIZE
,
489 MMC_CMD_AC
| MMC_RSP_R1
, 0, 0, 0,
490 (u16
*)&response
[0]);
493 do_pio_write((u16
*)src
, MMC_BLOCK_SIZE
>> 1);
495 case CARDTYPE_SDHC
: /* block addressing */
496 resp
= mmc_cmd(MMC_WRITE_BLOCK
,
497 dst
>> MMC_BLOCK_SIZE_BITS
,
498 MMC_CMD_ADTC
| MMC_RSP_R1
|
500 MMC_BLOCK_SIZE
, 1, 0,
501 (u16
*)&response
[0]);
503 default: /* byte addressing */
504 resp
= mmc_cmd(MMC_WRITE_BLOCK
, dst
,
505 MMC_CMD_ADTC
| MMC_RSP_R1
|
507 MMC_BLOCK_SIZE
, 1, 0,
508 (u16
*)&response
[0]);
511 if (size
>= MMC_BLOCK_SIZE
)
512 size
-= MMC_BLOCK_SIZE
;
515 dst
+= MMC_BLOCK_SIZE
;
516 src
+= MMC_BLOCK_SIZE
;
518 return size_original
;
521 static void print_mmc_cid(mmc_cid_t
*cid
)
523 printf("MMC found. Card desciption is:\n");
524 printf("Manufacturer ID = %02x%02x%02x\n",
525 cid
->id
[0], cid
->id
[1], cid
->id
[2]);
526 printf("HW/FW Revision = %x %x\n",cid
->hwrev
, cid
->fwrev
);
527 cid
->hwrev
= cid
->fwrev
= 0; /* null terminate string */
528 printf("Product Name = %s\n",cid
->name
);
529 printf("Serial Number = %02x%02x%02x\n",
530 cid
->sn
[0], cid
->sn
[1], cid
->sn
[2]);
531 printf("Month = %d\n",cid
->month
);
532 printf("Year = %d\n",1997 + cid
->year
);
535 static void print_sd_cid(const struct sd_cid
*cid
)
537 printf("Card Type: ");
552 printf("SD 2.0 SDHC\n");
555 printf("Manufacturer: 0x%02x, OEM \"%c%c\"\n",
556 cid
->mid
, cid
->oid_0
, cid
->oid_1
);
557 printf("Product name: \"%c%c%c%c%c\", revision %d.%d\n",
558 cid
->pnm_0
, cid
->pnm_1
, cid
->pnm_2
, cid
->pnm_3
, cid
->pnm_4
,
559 cid
->prv
>> 4, cid
->prv
& 15);
560 printf("Serial number: %u\n",
561 cid
->psn_0
<< 24 | cid
->psn_1
<< 16 | cid
->psn_2
<< 8 |
563 printf("Manufacturing date: %d/%d\n",
565 2000+((cid
->mdt_0
& 15) << 4)+((cid
->mdt_1
& 0xf0) >> 4));
566 /* printf("CRC: 0x%02x, b0 = %d\n",
567 cid->crc >> 1, cid->crc & 1); */
571 int mmc_init(int verbose
)
573 int retries
= 14, rc
= -ENODEV
;
576 mmc_cid_t
*mmc_cid
= (mmc_cid_t
*)response
;
577 struct sd_cid
*sd_cid
= (struct sd_cid
*)response
;
580 card_type
= CARDTYPE_NONE
;
584 glamo_reg_write(GLAMO_CLOCK_MMC_EN_M9CLK
|
585 GLAMO_CLOCK_MMC_EN_TCLK
|
586 GLAMO_CLOCK_MMC_DG_M9CLK
|
587 GLAMO_CLOCK_MMC_DG_TCLK
, GLAMO_REG_CLOCK_MMC
);
588 glamo_reg_write(glamo_reg_read(GLAMO_REG_HOSTBUS(2)) |
589 GLAMO_HOSTBUS2_MMIO_EN_MMC
, GLAMO_REG_HOSTBUS(2));
591 /* controller reset */
595 /* power the sdcard slot */
597 pcf50633_reg_write(PCF50633_REG_HCLDOOUT
, ldo_voltage(3300));
599 pcf50633_reg_write(PCF50633_REG_HCLDOOUT
+ 1,
600 pcf50633_reg_read(PCF50633_REG_HCLDOOUT
+ 1) | 1); /* on */
603 /* start the clock -- slowly (50MHz / 250 == 195kHz */
605 glamo_reg_write((glamo_reg_read(GLAMO_REG_CLOCK_GEN8
) & 0xff00) | 250,
606 GLAMO_REG_CLOCK_GEN8
);
608 /* enable clock to divider input */
610 glamo_reg_write(glamo_reg_read(
611 GLAMO_REG_CLOCK_GEN5_1
) | GLAMO_CLOCK_GEN51_EN_DIV_TCLK
,
612 GLAMO_REG_CLOCK_GEN5_1
);
616 /* set bus width to 1 */
618 glamo_reg_write((glamo_reg_read(GLAMO_REGOFS_MMC
+
619 GLAMO_REG_MMC_BASIC
) &
620 (~GLAMO_BASIC_MMC_EN_4BIT_DATA
)),
621 GLAMO_REGOFS_MMC
+ GLAMO_REG_MMC_BASIC
);
625 resp
= mmc_cmd(MMC_GO_IDLE_STATE
, 0, MMC_CMD_BCR
, 0, 0, 0,
626 (u16
*)&response
[0]);
634 resp
= mmc_cmd(SD_SEND_IF_COND
, 0x000001aa,
635 MMC_CMD_BCR
| MMC_RSP_R7
, 0, 0, 0,
636 (u16
*)&response
[0]);
637 if (!resp
&& (response
[0] == 0xaa)) {
638 card_type
= CARDTYPE_SD20
; /* 2.0 SD, may not be SDHC */
642 /* Well, either way let's say hello in SD card protocol */
648 resp
= mmc_cmd(MMC_APP_CMD
, 0x00000000,
649 MMC_CMD_AC
| MMC_RSP_R1
, 0, 0, 0,
650 (u16
*)&response
[0]);
653 resp
= mmc_cmd(SD_APP_OP_COND
, hcs
| 0x00300000,
654 MMC_CMD_BCR
| MMC_RSP_R3
, 0, 0, 0,
655 (u16
*)&response
[0]);
659 if (response
[3] & (1 << 6)) /* asserts block addressing */
660 card_type
= CARDTYPE_SDHC
;
662 if (response
[3] & (1 << 7)) { /* not busy */
663 if (card_type
== CARDTYPE_NONE
)
664 card_type
= CARDTYPE_SD
;
671 if (card_type
== CARDTYPE_NONE
) {
673 printf("failed to detect SD Card, trying MMC\n");
675 resp
= mmc_cmd(MMC_SEND_OP_COND
, 0x00ffc000,
676 MMC_CMD_BCR
| MMC_RSP_R3
, 0, 0, 0,
677 (u16
*)&response
[0]);
678 debug("resp %x %x\n", response
[0], response
[1]);
680 } while (retries
-- && !(response
[3] & 0x80));
682 card_type
= CARDTYPE_MMC
;
687 /* fill in device description */
688 mmc_dev
.if_type
= IF_TYPE_MMC
;
689 mmc_dev
.part_type
= PART_TYPE_DOS
;
693 mmc_dev
.removable
= 0;
694 mmc_dev
.block_read
= mmc_bread
;
696 mmc_dev
.lba
= 1 << 16; /* 64K x 512 blocks = 32MB default */
698 /* try to get card id */
699 resp
= mmc_cmd(MMC_ALL_SEND_CID
, hcs
,
700 MMC_CMD_BCR
| MMC_RSP_R2
, 0, 0, 0,
701 (u16
*)&response
[0]);
707 /* TODO configure mmc driver depending on card
711 print_mmc_cid(mmc_cid
);
712 sprintf((char *) mmc_dev
.vendor
,
713 "Man %02x%02x%02x Snr %02x%02x%02x",
714 mmc_cid
->id
[0], mmc_cid
->id
[1], mmc_cid
->id
[2],
715 mmc_cid
->sn
[0], mmc_cid
->sn
[1], mmc_cid
->sn
[2]);
716 sprintf((char *) mmc_dev
.product
, "%s", mmc_cid
->name
);
717 sprintf((char *) mmc_dev
.revision
, "%x %x",
718 mmc_cid
->hwrev
, mmc_cid
->fwrev
);
720 /* MMC exists, get CSD too */
721 resp
= mmc_cmd(MMC_SET_RELATIVE_ADDR
, MMC_DEFAULT_RCA
,
722 MMC_CMD_AC
| MMC_RSP_R1
, 0, 0, 0,
723 (u16
*)&response
[0]);
730 print_sd_cid(sd_cid
);
731 sprintf((char *) mmc_dev
.vendor
,
732 "Man %02 OEM %c%c \"%c%c%c%c%c\"",
733 sd_cid
->mid
, sd_cid
->oid_0
, sd_cid
->oid_1
,
734 sd_cid
->pnm_0
, sd_cid
->pnm_1
, sd_cid
->pnm_2
,
735 sd_cid
->pnm_3
, sd_cid
->pnm_4
);
736 sprintf((char *) mmc_dev
.product
, "%d",
737 sd_cid
->psn_0
<< 24 | sd_cid
->psn_1
<< 16 |
738 sd_cid
->psn_2
<< 8 | sd_cid
->psn_3
);
739 sprintf((char *) mmc_dev
.revision
, "%d.%d",
740 sd_cid
->prv
>> 4, sd_cid
->prv
& 15);
742 resp
= mmc_cmd(SD_SEND_RELATIVE_ADDR
, MMC_DEFAULT_RCA
,
743 MMC_CMD_BCR
| MMC_RSP_R6
, 0, 0, 0,
744 (u16
*)&response
[0]);
745 rca
= response
[2] | (response
[3] << 8);
754 resp
= mmc_cmd(MMC_SEND_CSD
, rca
<< 16,
755 MMC_CMD_AC
| MMC_RSP_R2
, 0, 0, 0,
756 (u16
*)&response
[0]);
758 mmc_csd_t
*csd
= (mmc_csd_t
*)response
;
760 memcpy(&mmc_csd
, csd
, sizeof(csd
));
763 /* FIXME add verbose printout for csd */
764 /* printf("READ_BL_LEN=%u, C_SIZE_MULT=%u, C_SIZE=%u\n",
765 csd->read_bl_len, csd->c_size_mult1,
768 mmc_dev
.lba
= (((unsigned long)1 << csd
->c_size_mult1
) *
769 (unsigned long)csd
->c_size
) >> 9;
770 printf("MMC/SD size: %dMiB\n", mmc_dev
.lba
>> 1);
773 resp
= mmc_cmd(MMC_SELECT_CARD
, rca
<<16, MMC_CMD_AC
| MMC_RSP_R1
,
774 0, 0, 0, (u16
*)&response
[0]);
778 #ifdef CONFIG_MMC_WIDE
780 if (card_type
== CARDTYPE_SD
|| card_type
== CARDTYPE_SDHC
) {
781 resp
= mmc_cmd(MMC_APP_CMD
, rca
<<16, MMC_CMD_AC
| MMC_RSP_R1
,
782 0, 0, 0, (u16
*)&response
[0]);
783 resp
= mmc_cmd(MMC_SWITCH
, 0x02, MMC_CMD_AC
| MMC_RSP_R1B
,
784 0, 0, 0, (u16
*)&response
[0]);
786 glamo_reg_write(glamo_reg_read(GLAMO_REGOFS_MMC
+
787 GLAMO_REG_MMC_BASIC
) | GLAMO_BASIC_MMC_EN_4BIT_DATA
,
788 GLAMO_REGOFS_MMC
+ GLAMO_REG_MMC_BASIC
);
792 /* crank the clock to the final speed, 16MHz */
794 glamo_reg_write((glamo_reg_read(GLAMO_REG_CLOCK_GEN8
) & 0xff00) | 2,
795 GLAMO_REG_CLOCK_GEN8
);
797 fat_register_device(&mmc_dev
, 1); /* partitions start counting with 1 */
802 void mmc_depower(void)
807 mmc_cmd(MMC_GO_IDLE_STATE
, 0, MMC_CMD_BCR
, 0, 0, 0,
808 (u16
*)&response
[0]);
810 /* hold engine reset, remove clocks */
812 glamo_reg_write(GLAMO_CLOCK_MMC_RESET
, GLAMO_REG_CLOCK_MMC
);
816 glamo_reg_write(0, GLAMO_REG_CLOCK_MMC
);
817 glamo_reg_write(glamo_reg_read(GLAMO_REG_HOSTBUS(2)) &
818 (~GLAMO_HOSTBUS2_MMIO_EN_MMC
), GLAMO_REG_HOSTBUS(2));
822 pcf50633_reg_write(PCF50633_REG_HCLDOOUT
+ 1,
823 pcf50633_reg_read(PCF50633_REG_HCLDOOUT
+ 1) & ~1); /* off */
827 mmc_ident(block_dev_desc_t
*dev
)
835 /* FIXME hard codes to 32 MB device */
836 if (addr
>= CFG_MMC_BASE
&& addr
< CFG_MMC_BASE
+ 0x02000000)
843 #endif /* defined(CONFIG_MMC) && defined(CONFIG_MMC_GLAMO) */