Added a test for MUIA_Listview_SelectChange.
[AROS.git] / rom / devs / sdcard / sdcard_mmcunit.c
blobe49d0657a7050ae545770ec56d986e2e3b97a5b9
1 /*
2 Copyright © 2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
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},
20 {SDCARD_TAG_ARG, 0},
21 {SDCARD_TAG_RSPTYPE, MMC_RSP_R1b},
22 {SDCARD_TAG_RSP, 0},
23 {TAG_DONE, 0}
25 ULONG retVal;
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);
36 return retVal;
39 ULONG FNAME_SDCUNIT(MMCChangeFrequency)(struct sdcard_Unit *sdcUnit)
41 UBYTE sdcRespBuf[512];
42 UBYTE sdcCardType;
43 struct TagItem sdcChFreqTags[] =
45 {SDCARD_TAG_CMD, MMC_CMD_SEND_EXT_CSD},
46 {SDCARD_TAG_ARG, 0},
47 {SDCARD_TAG_RSPTYPE, MMC_RSP_R1},
48 {SDCARD_TAG_RSP, 0},
49 {SDCARD_TAG_DATA, (IPTR)sdcRespBuf},
50 {SDCARD_TAG_DATALEN, 512},
51 {SDCARD_TAG_DATAFLAGS, MMC_DATA_READ},
52 {TAG_DONE, 0}
55 D(bug("[SDCard%02ld] %s()\n", sdcUnit->sdcu_UnitNum, __PRETTY_FUNCTION__));
57 if (sdcUnit->sdcu_Bus->sdcb_BusFlags & AF_Bus_SPI)
58 return 0;
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__));
64 return 0;
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__));
75 return -1;
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))
80 if (sdcRespBuf[0xB9])
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;
90 return 0;