Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00049 #include <cfg/clock.h>
00050 #include <cfg/mmci.h>
00051
00052 #include <dev/npl.h>
00053 #include <dev/mmcard.h>
00054 #include <dev/spibus.h>
00055
00056 #if !defined(NPL_MMC_CLOCK) || (NPL_MMC_CLOCK < 1000)
00057 #undef NPL_MMC_CLOCK
00058 #define NPL_MMC_CLOCK 12500000
00059 #endif
00060
00061 #if 0
00062
00063 #define NUTDEBUG
00064 #include <stdio.h>
00065 #endif
00066
00071
00072 static int NplMmc0Reset(NUTDEVICE * dev);
00073 static void NplMmc0Led(int mode);
00074 static int NplMmc0Power(int mode);
00075
00079 static MEMCARDSUPP mcsSpiMmc0Npl = {
00080 0,
00081 0,
00082 NplMmc0Reset,
00083 NplMmc0Led,
00084 NplMmc0Power,
00085 };
00086
00092 static void NplMmc0Insertion(void *arg)
00093 {
00094 MEMCARDSUPP *mcs = (MEMCARDSUPP *) arg;
00095
00096
00097 mcs->mcs_cf = 1;
00098
00099 mcs->mcs_sf = NUTMC_SF_CD;
00100
00101 if (inw(NPL_SLR) & NPL_LANWAKEUP) {
00102 mcs->mcs_sf |= NUTMC_SF_WP;
00103 }
00104
00105
00106 NplIrqDisable(&sig_MMCD);
00107 NplIrqEnable(&sig_NMMCD);
00108 }
00109
00115 static void NplMmcRemoval(void *arg)
00116 {
00117 MEMCARDSUPP *mcs = (MEMCARDSUPP *) arg;
00118
00119
00120 mcs->mcs_cf = 1;
00121
00122 mcs->mcs_sf = 0;
00123
00124
00125 NplIrqDisable(&sig_NMMCD);
00126 NplIrqEnable(&sig_MMCD);
00127 }
00128
00134 static void NplMmc0Led(int mode)
00135 {
00136 #ifdef NPL_MMC0_ULED
00137 if (mode == NUTMC_IND_OFF) {
00138 outb(NPL_XER, inb(NPL_XER) | NPL_USRLED);
00139 } else {
00140 outb(NPL_XER, inb(NPL_XER) & ~NPL_USRLED);
00141 }
00142 #endif
00143 }
00144
00155 static int NplMmc0Power(int mode)
00156 {
00157 return -1;
00158 }
00159
00165 static int NplMmc0Reset(NUTDEVICE * dev)
00166 {
00167 uint_fast8_t i;
00168
00169
00170 outb(NPL_XER, inb(NPL_XER) | NPL_MMCS);
00171
00172 for (i = 0; i < 10; i++) {
00173 outb(NPL_MMCDR, 0xFF);
00174 while ((inb(NPL_SLR) & NPL_MMCREADY) == 0);
00175 inb(NPL_MMCDR);
00176 }
00177
00178 NplMmc0Led(NUTMC_IND_OFF);
00179
00180 return 0;
00181 }
00182
00191 static int SpiMmc0NplInit(NUTDEVICE * dev)
00192 {
00193 int rc;
00194
00195 NplMmc0Reset(dev);
00196
00197
00198 rc = NplRegisterIrqHandler(&sig_MMCD, NplMmc0Insertion, dev->dev_dcb);
00199 if (rc == 0) {
00200 rc = NplRegisterIrqHandler(&sig_NMMCD, NplMmcRemoval, dev->dev_dcb);
00201 if (rc == 0) {
00202 NplIrqEnable(&sig_MMCD);
00203
00204 rc = SpiMmcInit(dev);
00205 }
00206 }
00207 return rc;
00208 }
00209
00213 NUTSPINODE nodeSpiMmc0Npl = {
00214 NULL,
00215 NULL,
00216 NPL_MMC_CLOCK,
00217 SPI_MODE_0,
00218 8,
00219 0
00220 };
00221
00234 NUTDEVICE devNplSpiMmc0 = {
00235 0,
00236 {'M', 'M', 'C', '0', 0, 0, 0, 0, 0}
00237 ,
00238 0,
00239 0,
00240 0,
00241 &nodeSpiMmc0Npl,
00242 &mcsSpiMmc0Npl,
00243 SpiMmc0NplInit,
00244 SpiMmcIOCtl,
00245 SpiMmcBlockRead,
00246 SpiMmcBlockWrite,
00247 #ifdef __HARVARD_ARCH__
00248 SpiMmcBlockWrite_P,
00249 #endif
00250 SpiMmcMount,
00251 SpiMmcUnmount,
00252 0
00253 };
00254