2 Copyright © 2013, The AROS Development Team. All rights reserved.
7 #include <aros/debug.h>
9 #include <hardware/mmc.h>
10 #include <hardware/sdhc.h>
12 #include "sdcard_base.h"
13 #include "sdcard_unit.h"
15 ULONG
FNAME_SDCUNIT(MMCSwitch
)(UBYTE offset
, UBYTE value
, struct sdcard_Unit
*sdcUnit
)
17 struct TagItem sdcSwitchTags
[] =
19 {SDCARD_TAG_CMD
, MMC_CMD_SWITCH
},
21 {SDCARD_TAG_RSPTYPE
, MMC_RSP_R1b
},
27 D(bug("[SDCard%02ld] %s()\n", sdcUnit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
29 sdcSwitchTags
[1].ti_Data
= (MMC_SWITCH_WRITE_BYTE
<< 24) | (offset
<< 16) | (value
<< 8);
31 if ((retVal
= FNAME_SDCBUS(SendCmd
)(sdcSwitchTags
, sdcUnit
->sdcu_Bus
)) != -1)
33 /* Wait for units ready status */
34 FNAME_SDCUNIT(WaitStatus
)(1000, sdcUnit
);
39 ULONG
FNAME_SDCUNIT(MMCChangeFrequency
)(struct sdcard_Unit
*sdcUnit
)
41 UBYTE sdcRespBuf
[512];
43 struct TagItem sdcChFreqTags
[] =
45 {SDCARD_TAG_CMD
, MMC_CMD_SEND_EXT_CSD
},
47 {SDCARD_TAG_RSPTYPE
, MMC_RSP_R1
},
49 {SDCARD_TAG_DATA
, (IPTR
)sdcRespBuf
},
50 {SDCARD_TAG_DATALEN
, 512},
51 {SDCARD_TAG_DATAFLAGS
, MMC_DATA_READ
},
55 D(bug("[SDCard%02ld] %s()\n", sdcUnit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
57 if (sdcUnit
->sdcu_Bus
->sdcb_BusFlags
& AF_Bus_SPI
)
60 D(bug("[SDCard%02ld] %s: Querying Ext_CSD ... \n", sdcUnit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
61 if ((FNAME_SDCBUS(SendCmd
)(sdcChFreqTags
, sdcUnit
->sdcu_Bus
) == -1) || (FNAME_SDCBUS(WaitCmd
)(SDHCI_PS_CMD_INHIBIT
|SDHCI_PS_DATA_INHIBIT
, 1000, sdcUnit
->sdcu_Bus
) == -1))
63 D(bug("[SDCard%02ld] %s: Query Failed\n", sdcUnit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
66 D(bug("[SDCard%02ld] %s: Query Response = %08x\n", sdcUnit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
, sdcChFreqTags
[3].ti_Data
));
68 sdcCardType
= sdcRespBuf
[0xC4] & 0xF;
70 D(bug("[SDCard%02ld] %s: CardType = %d\n", sdcUnit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
, sdcCardType
));
72 if (FNAME_SDCUNIT(MMCSwitch
)(EXT_CSD_HS_TIMING
, 1, sdcUnit
) != -1)
74 D(bug("[SDCard%02ld] %s: Switch failed\n", sdcUnit
->sdcu_UnitNum
, __PRETTY_FUNCTION__
));
78 if ((FNAME_SDCBUS(SendCmd
)(sdcChFreqTags
, sdcUnit
->sdcu_Bus
) != -1) || (FNAME_SDCBUS(WaitCmd
)(SDHCI_PS_CMD_INHIBIT
|SDHCI_PS_DATA_INHIBIT
, 1000, sdcUnit
->sdcu_Bus
) != -1))
82 /* MMC supports 26MHz High-Speed mode .. */
83 sdcUnit
->sdcu_Flags
|= AF_Card_HighSpeed
;
85 /* is 52MHz mode also supported? */
86 if (sdcCardType
& MMC_HS_52MHZ
)
87 sdcUnit
->sdcu_Flags
|= AF_Card_HighSpeed52
;