omap_hsmmc.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852
  1. /*
  2. * drivers/mmc/host/omap_hsmmc.c
  3. *
  4. * Driver for OMAP2430/3430 MMC controller.
  5. *
  6. * Copyright (C) 2007 Texas Instruments.
  7. *
  8. * Authors:
  9. * Syed Mohammed Khasim <x0khasim@ti.com>
  10. * Madhusudhan <madhu.cr@ti.com>
  11. * Mohit Jalori <mjalori@ti.com>
  12. *
  13. * This file is licensed under the terms of the GNU General Public License
  14. * version 2. This program is licensed "as is" without any warranty of any
  15. * kind, whether express or implied.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/debugfs.h>
  20. #include <linux/seq_file.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/delay.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/workqueue.h>
  26. #include <linux/timer.h>
  27. #include <linux/clk.h>
  28. #include <linux/mmc/host.h>
  29. #include <linux/io.h>
  30. #include <linux/semaphore.h>
  31. #include <mach/dma.h>
  32. #include <mach/hardware.h>
  33. #include <mach/board.h>
  34. #include <mach/mmc.h>
  35. #include <mach/cpu.h>
  36. /* OMAP HSMMC Host Controller Registers */
  37. #define OMAP_HSMMC_SYSCONFIG 0x0010
  38. #define OMAP_HSMMC_SYSSTATUS 0x0014
  39. #define OMAP_HSMMC_CON 0x002C
  40. #define OMAP_HSMMC_BLK 0x0104
  41. #define OMAP_HSMMC_ARG 0x0108
  42. #define OMAP_HSMMC_CMD 0x010C
  43. #define OMAP_HSMMC_RSP10 0x0110
  44. #define OMAP_HSMMC_RSP32 0x0114
  45. #define OMAP_HSMMC_RSP54 0x0118
  46. #define OMAP_HSMMC_RSP76 0x011C
  47. #define OMAP_HSMMC_DATA 0x0120
  48. #define OMAP_HSMMC_HCTL 0x0128
  49. #define OMAP_HSMMC_SYSCTL 0x012C
  50. #define OMAP_HSMMC_STAT 0x0130
  51. #define OMAP_HSMMC_IE 0x0134
  52. #define OMAP_HSMMC_ISE 0x0138
  53. #define OMAP_HSMMC_CAPA 0x0140
  54. #define VS18 (1 << 26)
  55. #define VS30 (1 << 25)
  56. #define SDVS18 (0x5 << 9)
  57. #define SDVS30 (0x6 << 9)
  58. #define SDVS33 (0x7 << 9)
  59. #define SDVS_MASK 0x00000E00
  60. #define SDVSCLR 0xFFFFF1FF
  61. #define SDVSDET 0x00000400
  62. #define AUTOIDLE 0x1
  63. #define SDBP (1 << 8)
  64. #define DTO 0xe
  65. #define ICE 0x1
  66. #define ICS 0x2
  67. #define CEN (1 << 2)
  68. #define CLKD_MASK 0x0000FFC0
  69. #define CLKD_SHIFT 6
  70. #define DTO_MASK 0x000F0000
  71. #define DTO_SHIFT 16
  72. #define INT_EN_MASK 0x307F0033
  73. #define BWR_ENABLE (1 << 4)
  74. #define BRR_ENABLE (1 << 5)
  75. #define INIT_STREAM (1 << 1)
  76. #define DP_SELECT (1 << 21)
  77. #define DDIR (1 << 4)
  78. #define DMA_EN 0x1
  79. #define MSBS (1 << 5)
  80. #define BCE (1 << 1)
  81. #define FOUR_BIT (1 << 1)
  82. #define DW8 (1 << 5)
  83. #define CC 0x1
  84. #define TC 0x02
  85. #define OD 0x1
  86. #define ERR (1 << 15)
  87. #define CMD_TIMEOUT (1 << 16)
  88. #define DATA_TIMEOUT (1 << 20)
  89. #define CMD_CRC (1 << 17)
  90. #define DATA_CRC (1 << 21)
  91. #define CARD_ERR (1 << 28)
  92. #define STAT_CLEAR 0xFFFFFFFF
  93. #define INIT_STREAM_CMD 0x00000000
  94. #define DUAL_VOLT_OCR_BIT 7
  95. #define SRC (1 << 25)
  96. #define SRD (1 << 26)
  97. #define SOFTRESET (1 << 1)
  98. #define RESETDONE (1 << 0)
  99. /*
  100. * FIXME: Most likely all the data using these _DEVID defines should come
  101. * from the platform_data, or implemented in controller and slot specific
  102. * functions.
  103. */
  104. #define OMAP_MMC1_DEVID 0
  105. #define OMAP_MMC2_DEVID 1
  106. #define OMAP_MMC3_DEVID 2
  107. #define MMC_TIMEOUT_MS 20
  108. #define OMAP_MMC_MASTER_CLOCK 96000000
  109. #define DRIVER_NAME "mmci-omap-hs"
  110. /* Timeouts for entering power saving states on inactivity, msec */
  111. #define OMAP_MMC_DISABLED_TIMEOUT 100
  112. #define OMAP_MMC_OFF_TIMEOUT 1000
  113. /*
  114. * One controller can have multiple slots, like on some omap boards using
  115. * omap.c controller driver. Luckily this is not currently done on any known
  116. * omap_hsmmc.c device.
  117. */
  118. #define mmc_slot(host) (host->pdata->slots[host->slot_id])
  119. /*
  120. * MMC Host controller read/write API's
  121. */
  122. #define OMAP_HSMMC_READ(base, reg) \
  123. __raw_readl((base) + OMAP_HSMMC_##reg)
  124. #define OMAP_HSMMC_WRITE(base, reg, val) \
  125. __raw_writel((val), (base) + OMAP_HSMMC_##reg)
  126. struct mmc_omap_host {
  127. struct device *dev;
  128. struct mmc_host *mmc;
  129. struct mmc_request *mrq;
  130. struct mmc_command *cmd;
  131. struct mmc_data *data;
  132. struct clk *fclk;
  133. struct clk *iclk;
  134. struct clk *dbclk;
  135. struct semaphore sem;
  136. struct work_struct mmc_carddetect_work;
  137. void __iomem *base;
  138. resource_size_t mapbase;
  139. unsigned int id;
  140. unsigned int dma_len;
  141. unsigned int dma_sg_idx;
  142. unsigned char bus_mode;
  143. unsigned char power_mode;
  144. u32 *buffer;
  145. u32 bytesleft;
  146. int suspended;
  147. int irq;
  148. int use_dma, dma_ch;
  149. int dma_line_tx, dma_line_rx;
  150. int slot_id;
  151. int dbclk_enabled;
  152. int response_busy;
  153. int context_loss;
  154. int dpm_state;
  155. struct omap_mmc_platform_data *pdata;
  156. };
  157. /*
  158. * Stop clock to the card
  159. */
  160. static void omap_mmc_stop_clock(struct mmc_omap_host *host)
  161. {
  162. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  163. OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN);
  164. if ((OMAP_HSMMC_READ(host->base, SYSCTL) & CEN) != 0x0)
  165. dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stoped\n");
  166. }
  167. #ifdef CONFIG_PM
  168. /*
  169. * Restore the MMC host context, if it was lost as result of a
  170. * power state change.
  171. */
  172. static int omap_mmc_restore_ctx(struct mmc_omap_host *host)
  173. {
  174. struct mmc_ios *ios = &host->mmc->ios;
  175. struct omap_mmc_platform_data *pdata = host->pdata;
  176. int context_loss = 0;
  177. u32 hctl, capa, con;
  178. u16 dsor = 0;
  179. unsigned long timeout;
  180. if (pdata->get_context_loss_count) {
  181. context_loss = pdata->get_context_loss_count(host->dev);
  182. if (context_loss < 0)
  183. return 1;
  184. }
  185. dev_dbg(mmc_dev(host->mmc), "context was %slost\n",
  186. context_loss == host->context_loss ? "not " : "");
  187. if (host->context_loss == context_loss)
  188. return 1;
  189. /* Wait for hardware reset */
  190. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  191. while ((OMAP_HSMMC_READ(host->base, SYSSTATUS) & RESETDONE) != RESETDONE
  192. && time_before(jiffies, timeout))
  193. ;
  194. /* Do software reset */
  195. OMAP_HSMMC_WRITE(host->base, SYSCONFIG, SOFTRESET);
  196. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  197. while ((OMAP_HSMMC_READ(host->base, SYSSTATUS) & RESETDONE) != RESETDONE
  198. && time_before(jiffies, timeout))
  199. ;
  200. OMAP_HSMMC_WRITE(host->base, SYSCONFIG,
  201. OMAP_HSMMC_READ(host->base, SYSCONFIG) | AUTOIDLE);
  202. if (host->id == OMAP_MMC1_DEVID) {
  203. if (host->power_mode != MMC_POWER_OFF &&
  204. (1 << ios->vdd) <= MMC_VDD_23_24)
  205. hctl = SDVS18;
  206. else
  207. hctl = SDVS30;
  208. capa = VS30 | VS18;
  209. } else {
  210. hctl = SDVS18;
  211. capa = VS18;
  212. }
  213. OMAP_HSMMC_WRITE(host->base, HCTL,
  214. OMAP_HSMMC_READ(host->base, HCTL) | hctl);
  215. OMAP_HSMMC_WRITE(host->base, CAPA,
  216. OMAP_HSMMC_READ(host->base, CAPA) | capa);
  217. OMAP_HSMMC_WRITE(host->base, HCTL,
  218. OMAP_HSMMC_READ(host->base, HCTL) | SDBP);
  219. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  220. while ((OMAP_HSMMC_READ(host->base, HCTL) & SDBP) != SDBP
  221. && time_before(jiffies, timeout))
  222. ;
  223. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  224. OMAP_HSMMC_WRITE(host->base, ISE, INT_EN_MASK);
  225. OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
  226. /* Do not initialize card-specific things if the power is off */
  227. if (host->power_mode == MMC_POWER_OFF)
  228. goto out;
  229. con = OMAP_HSMMC_READ(host->base, CON);
  230. switch (ios->bus_width) {
  231. case MMC_BUS_WIDTH_8:
  232. OMAP_HSMMC_WRITE(host->base, CON, con | DW8);
  233. break;
  234. case MMC_BUS_WIDTH_4:
  235. OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
  236. OMAP_HSMMC_WRITE(host->base, HCTL,
  237. OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT);
  238. break;
  239. case MMC_BUS_WIDTH_1:
  240. OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
  241. OMAP_HSMMC_WRITE(host->base, HCTL,
  242. OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT);
  243. break;
  244. }
  245. if (ios->clock) {
  246. dsor = OMAP_MMC_MASTER_CLOCK / ios->clock;
  247. if (dsor < 1)
  248. dsor = 1;
  249. if (OMAP_MMC_MASTER_CLOCK / dsor > ios->clock)
  250. dsor++;
  251. if (dsor > 250)
  252. dsor = 250;
  253. }
  254. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  255. OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN);
  256. OMAP_HSMMC_WRITE(host->base, SYSCTL, (dsor << 6) | (DTO << 16));
  257. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  258. OMAP_HSMMC_READ(host->base, SYSCTL) | ICE);
  259. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  260. while ((OMAP_HSMMC_READ(host->base, SYSCTL) & ICS) != ICS
  261. && time_before(jiffies, timeout))
  262. ;
  263. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  264. OMAP_HSMMC_READ(host->base, SYSCTL) | CEN);
  265. con = OMAP_HSMMC_READ(host->base, CON);
  266. if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
  267. OMAP_HSMMC_WRITE(host->base, CON, con | OD);
  268. else
  269. OMAP_HSMMC_WRITE(host->base, CON, con & ~OD);
  270. out:
  271. host->context_loss = context_loss;
  272. dev_dbg(mmc_dev(host->mmc), "context is restored\n");
  273. return 0;
  274. }
  275. /*
  276. * Save the MMC host context (store the number of power state changes so far).
  277. */
  278. static void omap_mmc_save_ctx(struct mmc_omap_host *host)
  279. {
  280. struct omap_mmc_platform_data *pdata = host->pdata;
  281. int context_loss;
  282. if (pdata->get_context_loss_count) {
  283. context_loss = pdata->get_context_loss_count(host->dev);
  284. if (context_loss < 0)
  285. return;
  286. host->context_loss = context_loss;
  287. }
  288. }
  289. #else
  290. static int omap_mmc_restore_ctx(struct mmc_omap_host *host)
  291. {
  292. return 0;
  293. }
  294. static void omap_mmc_save_ctx(struct mmc_omap_host *host)
  295. {
  296. }
  297. #endif
  298. /*
  299. * Send init stream sequence to card
  300. * before sending IDLE command
  301. */
  302. static void send_init_stream(struct mmc_omap_host *host)
  303. {
  304. int reg = 0;
  305. unsigned long timeout;
  306. disable_irq(host->irq);
  307. OMAP_HSMMC_WRITE(host->base, CON,
  308. OMAP_HSMMC_READ(host->base, CON) | INIT_STREAM);
  309. OMAP_HSMMC_WRITE(host->base, CMD, INIT_STREAM_CMD);
  310. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  311. while ((reg != CC) && time_before(jiffies, timeout))
  312. reg = OMAP_HSMMC_READ(host->base, STAT) & CC;
  313. OMAP_HSMMC_WRITE(host->base, CON,
  314. OMAP_HSMMC_READ(host->base, CON) & ~INIT_STREAM);
  315. enable_irq(host->irq);
  316. }
  317. static inline
  318. int mmc_omap_cover_is_closed(struct mmc_omap_host *host)
  319. {
  320. int r = 1;
  321. if (host->pdata->slots[host->slot_id].get_cover_state)
  322. r = host->pdata->slots[host->slot_id].get_cover_state(host->dev,
  323. host->slot_id);
  324. return r;
  325. }
  326. static ssize_t
  327. mmc_omap_show_cover_switch(struct device *dev, struct device_attribute *attr,
  328. char *buf)
  329. {
  330. struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
  331. struct mmc_omap_host *host = mmc_priv(mmc);
  332. return sprintf(buf, "%s\n", mmc_omap_cover_is_closed(host) ? "closed" :
  333. "open");
  334. }
  335. static DEVICE_ATTR(cover_switch, S_IRUGO, mmc_omap_show_cover_switch, NULL);
  336. static ssize_t
  337. mmc_omap_show_slot_name(struct device *dev, struct device_attribute *attr,
  338. char *buf)
  339. {
  340. struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
  341. struct mmc_omap_host *host = mmc_priv(mmc);
  342. struct omap_mmc_slot_data slot = host->pdata->slots[host->slot_id];
  343. return sprintf(buf, "%s\n", slot.name);
  344. }
  345. static DEVICE_ATTR(slot_name, S_IRUGO, mmc_omap_show_slot_name, NULL);
  346. /*
  347. * Configure the response type and send the cmd.
  348. */
  349. static void
  350. mmc_omap_start_command(struct mmc_omap_host *host, struct mmc_command *cmd,
  351. struct mmc_data *data)
  352. {
  353. int cmdreg = 0, resptype = 0, cmdtype = 0;
  354. dev_dbg(mmc_dev(host->mmc), "%s: CMD%d, argument 0x%08x\n",
  355. mmc_hostname(host->mmc), cmd->opcode, cmd->arg);
  356. host->cmd = cmd;
  357. /*
  358. * Clear status bits and enable interrupts
  359. */
  360. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  361. OMAP_HSMMC_WRITE(host->base, ISE, INT_EN_MASK);
  362. if (host->use_dma)
  363. OMAP_HSMMC_WRITE(host->base, IE,
  364. INT_EN_MASK & ~(BRR_ENABLE | BWR_ENABLE));
  365. else
  366. OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
  367. host->response_busy = 0;
  368. if (cmd->flags & MMC_RSP_PRESENT) {
  369. if (cmd->flags & MMC_RSP_136)
  370. resptype = 1;
  371. else if (cmd->flags & MMC_RSP_BUSY) {
  372. resptype = 3;
  373. host->response_busy = 1;
  374. } else
  375. resptype = 2;
  376. }
  377. /*
  378. * Unlike OMAP1 controller, the cmdtype does not seem to be based on
  379. * ac, bc, adtc, bcr. Only commands ending an open ended transfer need
  380. * a val of 0x3, rest 0x0.
  381. */
  382. if (cmd == host->mrq->stop)
  383. cmdtype = 0x3;
  384. cmdreg = (cmd->opcode << 24) | (resptype << 16) | (cmdtype << 22);
  385. if (data) {
  386. cmdreg |= DP_SELECT | MSBS | BCE;
  387. if (data->flags & MMC_DATA_READ)
  388. cmdreg |= DDIR;
  389. else
  390. cmdreg &= ~(DDIR);
  391. }
  392. if (host->use_dma)
  393. cmdreg |= DMA_EN;
  394. OMAP_HSMMC_WRITE(host->base, ARG, cmd->arg);
  395. OMAP_HSMMC_WRITE(host->base, CMD, cmdreg);
  396. }
  397. static int
  398. mmc_omap_get_dma_dir(struct mmc_omap_host *host, struct mmc_data *data)
  399. {
  400. if (data->flags & MMC_DATA_WRITE)
  401. return DMA_TO_DEVICE;
  402. else
  403. return DMA_FROM_DEVICE;
  404. }
  405. /*
  406. * Notify the transfer complete to MMC core
  407. */
  408. static void
  409. mmc_omap_xfer_done(struct mmc_omap_host *host, struct mmc_data *data)
  410. {
  411. if (!data) {
  412. struct mmc_request *mrq = host->mrq;
  413. host->mrq = NULL;
  414. mmc_request_done(host->mmc, mrq);
  415. return;
  416. }
  417. host->data = NULL;
  418. if (host->use_dma && host->dma_ch != -1)
  419. dma_unmap_sg(mmc_dev(host->mmc), data->sg, host->dma_len,
  420. mmc_omap_get_dma_dir(host, data));
  421. if (!data->error)
  422. data->bytes_xfered += data->blocks * (data->blksz);
  423. else
  424. data->bytes_xfered = 0;
  425. if (!data->stop) {
  426. host->mrq = NULL;
  427. mmc_request_done(host->mmc, data->mrq);
  428. return;
  429. }
  430. mmc_omap_start_command(host, data->stop, NULL);
  431. }
  432. /*
  433. * Notify the core about command completion
  434. */
  435. static void
  436. mmc_omap_cmd_done(struct mmc_omap_host *host, struct mmc_command *cmd)
  437. {
  438. host->cmd = NULL;
  439. if (cmd->flags & MMC_RSP_PRESENT) {
  440. if (cmd->flags & MMC_RSP_136) {
  441. /* response type 2 */
  442. cmd->resp[3] = OMAP_HSMMC_READ(host->base, RSP10);
  443. cmd->resp[2] = OMAP_HSMMC_READ(host->base, RSP32);
  444. cmd->resp[1] = OMAP_HSMMC_READ(host->base, RSP54);
  445. cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP76);
  446. } else {
  447. /* response types 1, 1b, 3, 4, 5, 6 */
  448. cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP10);
  449. }
  450. }
  451. if ((host->data == NULL && !host->response_busy) || cmd->error) {
  452. host->mrq = NULL;
  453. mmc_request_done(host->mmc, cmd->mrq);
  454. }
  455. }
  456. /*
  457. * DMA clean up for command errors
  458. */
  459. static void mmc_dma_cleanup(struct mmc_omap_host *host, int errno)
  460. {
  461. host->data->error = errno;
  462. if (host->use_dma && host->dma_ch != -1) {
  463. dma_unmap_sg(mmc_dev(host->mmc), host->data->sg, host->dma_len,
  464. mmc_omap_get_dma_dir(host, host->data));
  465. omap_free_dma(host->dma_ch);
  466. host->dma_ch = -1;
  467. up(&host->sem);
  468. }
  469. host->data = NULL;
  470. }
  471. /*
  472. * Readable error output
  473. */
  474. #ifdef CONFIG_MMC_DEBUG
  475. static void mmc_omap_report_irq(struct mmc_omap_host *host, u32 status)
  476. {
  477. /* --- means reserved bit without definition at documentation */
  478. static const char *mmc_omap_status_bits[] = {
  479. "CC", "TC", "BGE", "---", "BWR", "BRR", "---", "---", "CIRQ",
  480. "OBI", "---", "---", "---", "---", "---", "ERRI", "CTO", "CCRC",
  481. "CEB", "CIE", "DTO", "DCRC", "DEB", "---", "ACE", "---",
  482. "---", "---", "---", "CERR", "CERR", "BADA", "---", "---", "---"
  483. };
  484. char res[256];
  485. char *buf = res;
  486. int len, i;
  487. len = sprintf(buf, "MMC IRQ 0x%x :", status);
  488. buf += len;
  489. for (i = 0; i < ARRAY_SIZE(mmc_omap_status_bits); i++)
  490. if (status & (1 << i)) {
  491. len = sprintf(buf, " %s", mmc_omap_status_bits[i]);
  492. buf += len;
  493. }
  494. dev_dbg(mmc_dev(host->mmc), "%s\n", res);
  495. }
  496. #endif /* CONFIG_MMC_DEBUG */
  497. /*
  498. * MMC controller internal state machines reset
  499. *
  500. * Used to reset command or data internal state machines, using respectively
  501. * SRC or SRD bit of SYSCTL register
  502. * Can be called from interrupt context
  503. */
  504. static inline void mmc_omap_reset_controller_fsm(struct mmc_omap_host *host,
  505. unsigned long bit)
  506. {
  507. unsigned long i = 0;
  508. unsigned long limit = (loops_per_jiffy *
  509. msecs_to_jiffies(MMC_TIMEOUT_MS));
  510. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  511. OMAP_HSMMC_READ(host->base, SYSCTL) | bit);
  512. while ((OMAP_HSMMC_READ(host->base, SYSCTL) & bit) &&
  513. (i++ < limit))
  514. cpu_relax();
  515. if (OMAP_HSMMC_READ(host->base, SYSCTL) & bit)
  516. dev_err(mmc_dev(host->mmc),
  517. "Timeout waiting on controller reset in %s\n",
  518. __func__);
  519. }
  520. /*
  521. * MMC controller IRQ handler
  522. */
  523. static irqreturn_t mmc_omap_irq(int irq, void *dev_id)
  524. {
  525. struct mmc_omap_host *host = dev_id;
  526. struct mmc_data *data;
  527. int end_cmd = 0, end_trans = 0, status;
  528. if (host->mrq == NULL) {
  529. OMAP_HSMMC_WRITE(host->base, STAT,
  530. OMAP_HSMMC_READ(host->base, STAT));
  531. /* Flush posted write */
  532. OMAP_HSMMC_READ(host->base, STAT);
  533. return IRQ_HANDLED;
  534. }
  535. data = host->data;
  536. status = OMAP_HSMMC_READ(host->base, STAT);
  537. dev_dbg(mmc_dev(host->mmc), "IRQ Status is %x\n", status);
  538. if (status & ERR) {
  539. #ifdef CONFIG_MMC_DEBUG
  540. mmc_omap_report_irq(host, status);
  541. #endif
  542. if ((status & CMD_TIMEOUT) ||
  543. (status & CMD_CRC)) {
  544. if (host->cmd) {
  545. if (status & CMD_TIMEOUT) {
  546. mmc_omap_reset_controller_fsm(host, SRC);
  547. host->cmd->error = -ETIMEDOUT;
  548. } else {
  549. host->cmd->error = -EILSEQ;
  550. }
  551. end_cmd = 1;
  552. }
  553. if (host->data || host->response_busy) {
  554. if (host->data)
  555. mmc_dma_cleanup(host, -ETIMEDOUT);
  556. host->response_busy = 0;
  557. mmc_omap_reset_controller_fsm(host, SRD);
  558. }
  559. }
  560. if ((status & DATA_TIMEOUT) ||
  561. (status & DATA_CRC)) {
  562. if (host->data || host->response_busy) {
  563. int err = (status & DATA_TIMEOUT) ?
  564. -ETIMEDOUT : -EILSEQ;
  565. if (host->data)
  566. mmc_dma_cleanup(host, err);
  567. else
  568. host->mrq->cmd->error = err;
  569. host->response_busy = 0;
  570. mmc_omap_reset_controller_fsm(host, SRD);
  571. end_trans = 1;
  572. }
  573. }
  574. if (status & CARD_ERR) {
  575. dev_dbg(mmc_dev(host->mmc),
  576. "Ignoring card err CMD%d\n", host->cmd->opcode);
  577. if (host->cmd)
  578. end_cmd = 1;
  579. if (host->data)
  580. end_trans = 1;
  581. }
  582. }
  583. OMAP_HSMMC_WRITE(host->base, STAT, status);
  584. /* Flush posted write */
  585. OMAP_HSMMC_READ(host->base, STAT);
  586. if (end_cmd || ((status & CC) && host->cmd))
  587. mmc_omap_cmd_done(host, host->cmd);
  588. if (end_trans || (status & TC))
  589. mmc_omap_xfer_done(host, data);
  590. return IRQ_HANDLED;
  591. }
  592. static void set_sd_bus_power(struct mmc_omap_host *host)
  593. {
  594. unsigned long i;
  595. OMAP_HSMMC_WRITE(host->base, HCTL,
  596. OMAP_HSMMC_READ(host->base, HCTL) | SDBP);
  597. for (i = 0; i < loops_per_jiffy; i++) {
  598. if (OMAP_HSMMC_READ(host->base, HCTL) & SDBP)
  599. break;
  600. cpu_relax();
  601. }
  602. }
  603. /*
  604. * Switch MMC interface voltage ... only relevant for MMC1.
  605. *
  606. * MMC2 and MMC3 use fixed 1.8V levels, and maybe a transceiver.
  607. * The MMC2 transceiver controls are used instead of DAT4..DAT7.
  608. * Some chips, like eMMC ones, use internal transceivers.
  609. */
  610. static int omap_mmc_switch_opcond(struct mmc_omap_host *host, int vdd)
  611. {
  612. u32 reg_val = 0;
  613. int ret;
  614. /* Disable the clocks */
  615. clk_disable(host->fclk);
  616. clk_disable(host->iclk);
  617. clk_disable(host->dbclk);
  618. /* Turn the power off */
  619. ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0);
  620. if (ret != 0)
  621. goto err;
  622. /* Turn the power ON with given VDD 1.8 or 3.0v */
  623. ret = mmc_slot(host).set_power(host->dev, host->slot_id, 1, vdd);
  624. if (ret != 0)
  625. goto err;
  626. clk_enable(host->fclk);
  627. clk_enable(host->iclk);
  628. clk_enable(host->dbclk);
  629. OMAP_HSMMC_WRITE(host->base, HCTL,
  630. OMAP_HSMMC_READ(host->base, HCTL) & SDVSCLR);
  631. reg_val = OMAP_HSMMC_READ(host->base, HCTL);
  632. /*
  633. * If a MMC dual voltage card is detected, the set_ios fn calls
  634. * this fn with VDD bit set for 1.8V. Upon card removal from the
  635. * slot, omap_mmc_set_ios sets the VDD back to 3V on MMC_POWER_OFF.
  636. *
  637. * Cope with a bit of slop in the range ... per data sheets:
  638. * - "1.8V" for vdds_mmc1/vdds_mmc1a can be up to 2.45V max,
  639. * but recommended values are 1.71V to 1.89V
  640. * - "3.0V" for vdds_mmc1/vdds_mmc1a can be up to 3.5V max,
  641. * but recommended values are 2.7V to 3.3V
  642. *
  643. * Board setup code shouldn't permit anything very out-of-range.
  644. * TWL4030-family VMMC1 and VSIM regulators are fine (avoiding the
  645. * middle range) but VSIM can't power DAT4..DAT7 at more than 3V.
  646. */
  647. if ((1 << vdd) <= MMC_VDD_23_24)
  648. reg_val |= SDVS18;
  649. else
  650. reg_val |= SDVS30;
  651. OMAP_HSMMC_WRITE(host->base, HCTL, reg_val);
  652. set_sd_bus_power(host);
  653. return 0;
  654. err:
  655. dev_dbg(mmc_dev(host->mmc), "Unable to switch operating voltage\n");
  656. return ret;
  657. }
  658. /*
  659. * Work Item to notify the core about card insertion/removal
  660. */
  661. static void mmc_omap_detect(struct work_struct *work)
  662. {
  663. struct mmc_omap_host *host = container_of(work, struct mmc_omap_host,
  664. mmc_carddetect_work);
  665. struct omap_mmc_slot_data *slot = &mmc_slot(host);
  666. int carddetect;
  667. if (host->suspended)
  668. return;
  669. sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
  670. if (mmc_slot(host).card_detect)
  671. carddetect = slot->card_detect(slot->card_detect_irq);
  672. else
  673. carddetect = -ENOSYS;
  674. if (carddetect) {
  675. mmc_detect_change(host->mmc, (HZ * 200) / 1000);
  676. } else {
  677. mmc_host_enable(host->mmc);
  678. mmc_omap_reset_controller_fsm(host, SRD);
  679. mmc_host_lazy_disable(host->mmc);
  680. mmc_detect_change(host->mmc, (HZ * 50) / 1000);
  681. }
  682. }
  683. /*
  684. * ISR for handling card insertion and removal
  685. */
  686. static irqreturn_t omap_mmc_cd_handler(int irq, void *dev_id)
  687. {
  688. struct mmc_omap_host *host = (struct mmc_omap_host *)dev_id;
  689. if (host->suspended)
  690. return IRQ_HANDLED;
  691. schedule_work(&host->mmc_carddetect_work);
  692. return IRQ_HANDLED;
  693. }
  694. static int mmc_omap_get_dma_sync_dev(struct mmc_omap_host *host,
  695. struct mmc_data *data)
  696. {
  697. int sync_dev;
  698. if (data->flags & MMC_DATA_WRITE)
  699. sync_dev = host->dma_line_tx;
  700. else
  701. sync_dev = host->dma_line_rx;
  702. return sync_dev;
  703. }
  704. static void mmc_omap_config_dma_params(struct mmc_omap_host *host,
  705. struct mmc_data *data,
  706. struct scatterlist *sgl)
  707. {
  708. int blksz, nblk, dma_ch;
  709. dma_ch = host->dma_ch;
  710. if (data->flags & MMC_DATA_WRITE) {
  711. omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
  712. (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
  713. omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
  714. sg_dma_address(sgl), 0, 0);
  715. } else {
  716. omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
  717. (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
  718. omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
  719. sg_dma_address(sgl), 0, 0);
  720. }
  721. blksz = host->data->blksz;
  722. nblk = sg_dma_len(sgl) / blksz;
  723. omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S32,
  724. blksz / 4, nblk, OMAP_DMA_SYNC_FRAME,
  725. mmc_omap_get_dma_sync_dev(host, data),
  726. !(data->flags & MMC_DATA_WRITE));
  727. omap_start_dma(dma_ch);
  728. }
  729. /*
  730. * DMA call back function
  731. */
  732. static void mmc_omap_dma_cb(int lch, u16 ch_status, void *data)
  733. {
  734. struct mmc_omap_host *host = data;
  735. if (ch_status & OMAP2_DMA_MISALIGNED_ERR_IRQ)
  736. dev_dbg(mmc_dev(host->mmc), "MISALIGNED_ADRS_ERR\n");
  737. if (host->dma_ch < 0)
  738. return;
  739. host->dma_sg_idx++;
  740. if (host->dma_sg_idx < host->dma_len) {
  741. /* Fire up the next transfer. */
  742. mmc_omap_config_dma_params(host, host->data,
  743. host->data->sg + host->dma_sg_idx);
  744. return;
  745. }
  746. omap_free_dma(host->dma_ch);
  747. host->dma_ch = -1;
  748. /*
  749. * DMA Callback: run in interrupt context.
  750. * mutex_unlock will throw a kernel warning if used.
  751. */
  752. up(&host->sem);
  753. }
  754. /*
  755. * Routine to configure and start DMA for the MMC card
  756. */
  757. static int
  758. mmc_omap_start_dma_transfer(struct mmc_omap_host *host, struct mmc_request *req)
  759. {
  760. int dma_ch = 0, ret = 0, err = 1, i;
  761. struct mmc_data *data = req->data;
  762. /* Sanity check: all the SG entries must be aligned by block size. */
  763. for (i = 0; i < data->sg_len; i++) {
  764. struct scatterlist *sgl;
  765. sgl = data->sg + i;
  766. if (sgl->length % data->blksz)
  767. return -EINVAL;
  768. }
  769. if ((data->blksz % 4) != 0)
  770. /* REVISIT: The MMC buffer increments only when MSB is written.
  771. * Return error for blksz which is non multiple of four.
  772. */
  773. return -EINVAL;
  774. /*
  775. * If for some reason the DMA transfer is still active,
  776. * we wait for timeout period and free the dma
  777. */
  778. if (host->dma_ch != -1) {
  779. set_current_state(TASK_UNINTERRUPTIBLE);
  780. schedule_timeout(100);
  781. if (down_trylock(&host->sem)) {
  782. omap_free_dma(host->dma_ch);
  783. host->dma_ch = -1;
  784. up(&host->sem);
  785. return err;
  786. }
  787. } else {
  788. if (down_trylock(&host->sem))
  789. return err;
  790. }
  791. ret = omap_request_dma(mmc_omap_get_dma_sync_dev(host, data), "MMC/SD",
  792. mmc_omap_dma_cb,host, &dma_ch);
  793. if (ret != 0) {
  794. dev_err(mmc_dev(host->mmc),
  795. "%s: omap_request_dma() failed with %d\n",
  796. mmc_hostname(host->mmc), ret);
  797. return ret;
  798. }
  799. host->dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg,
  800. data->sg_len, mmc_omap_get_dma_dir(host, data));
  801. host->dma_ch = dma_ch;
  802. host->dma_sg_idx = 0;
  803. mmc_omap_config_dma_params(host, data, data->sg);
  804. return 0;
  805. }
  806. static void set_data_timeout(struct mmc_omap_host *host,
  807. struct mmc_request *req)
  808. {
  809. unsigned int timeout, cycle_ns;
  810. uint32_t reg, clkd, dto = 0;
  811. reg = OMAP_HSMMC_READ(host->base, SYSCTL);
  812. clkd = (reg & CLKD_MASK) >> CLKD_SHIFT;
  813. if (clkd == 0)
  814. clkd = 1;
  815. cycle_ns = 1000000000 / (clk_get_rate(host->fclk) / clkd);
  816. timeout = req->data->timeout_ns / cycle_ns;
  817. timeout += req->data->timeout_clks;
  818. if (timeout) {
  819. while ((timeout & 0x80000000) == 0) {
  820. dto += 1;
  821. timeout <<= 1;
  822. }
  823. dto = 31 - dto;
  824. timeout <<= 1;
  825. if (timeout && dto)
  826. dto += 1;
  827. if (dto >= 13)
  828. dto -= 13;
  829. else
  830. dto = 0;
  831. if (dto > 14)
  832. dto = 14;
  833. }
  834. reg &= ~DTO_MASK;
  835. reg |= dto << DTO_SHIFT;
  836. OMAP_HSMMC_WRITE(host->base, SYSCTL, reg);
  837. }
  838. /*
  839. * Configure block length for MMC/SD cards and initiate the transfer.
  840. */
  841. static int
  842. mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req)
  843. {
  844. int ret;
  845. host->data = req->data;
  846. if (req->data == NULL) {
  847. OMAP_HSMMC_WRITE(host->base, BLK, 0);
  848. return 0;
  849. }
  850. OMAP_HSMMC_WRITE(host->base, BLK, (req->data->blksz)
  851. | (req->data->blocks << 16));
  852. set_data_timeout(host, req);
  853. if (host->use_dma) {
  854. ret = mmc_omap_start_dma_transfer(host, req);
  855. if (ret != 0) {
  856. dev_dbg(mmc_dev(host->mmc), "MMC start dma failure\n");
  857. return ret;
  858. }
  859. }
  860. return 0;
  861. }
  862. /*
  863. * Request function. for read/write operation
  864. */
  865. static void omap_mmc_request(struct mmc_host *mmc, struct mmc_request *req)
  866. {
  867. struct mmc_omap_host *host = mmc_priv(mmc);
  868. int err;
  869. WARN_ON(host->mrq != NULL);
  870. host->mrq = req;
  871. err = mmc_omap_prepare_data(host, req);
  872. if (err) {
  873. req->cmd->error = err;
  874. if (req->data)
  875. req->data->error = err;
  876. host->mrq = NULL;
  877. mmc_request_done(mmc, req);
  878. return;
  879. }
  880. mmc_omap_start_command(host, req->cmd, req->data);
  881. }
  882. /* Routine to configure clock values. Exposed API to core */
  883. static void omap_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  884. {
  885. struct mmc_omap_host *host = mmc_priv(mmc);
  886. u16 dsor = 0;
  887. unsigned long regval;
  888. unsigned long timeout;
  889. u32 con;
  890. int do_send_init_stream = 0;
  891. mmc_host_enable(host->mmc);
  892. if (ios->power_mode != host->power_mode) {
  893. switch (ios->power_mode) {
  894. case MMC_POWER_OFF:
  895. mmc_slot(host).set_power(host->dev, host->slot_id,
  896. 0, 0);
  897. break;
  898. case MMC_POWER_UP:
  899. mmc_slot(host).set_power(host->dev, host->slot_id,
  900. 1, ios->vdd);
  901. break;
  902. case MMC_POWER_ON:
  903. do_send_init_stream = 1;
  904. break;
  905. }
  906. host->power_mode = ios->power_mode;
  907. }
  908. /* FIXME: set registers based only on changes to ios */
  909. con = OMAP_HSMMC_READ(host->base, CON);
  910. switch (mmc->ios.bus_width) {
  911. case MMC_BUS_WIDTH_8:
  912. OMAP_HSMMC_WRITE(host->base, CON, con | DW8);
  913. break;
  914. case MMC_BUS_WIDTH_4:
  915. OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
  916. OMAP_HSMMC_WRITE(host->base, HCTL,
  917. OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT);
  918. break;
  919. case MMC_BUS_WIDTH_1:
  920. OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
  921. OMAP_HSMMC_WRITE(host->base, HCTL,
  922. OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT);
  923. break;
  924. }
  925. if (host->id == OMAP_MMC1_DEVID) {
  926. /* Only MMC1 can interface at 3V without some flavor
  927. * of external transceiver; but they all handle 1.8V.
  928. */
  929. if ((OMAP_HSMMC_READ(host->base, HCTL) & SDVSDET) &&
  930. (ios->vdd == DUAL_VOLT_OCR_BIT)) {
  931. /*
  932. * The mmc_select_voltage fn of the core does
  933. * not seem to set the power_mode to
  934. * MMC_POWER_UP upon recalculating the voltage.
  935. * vdd 1.8v.
  936. */
  937. if (omap_mmc_switch_opcond(host, ios->vdd) != 0)
  938. dev_dbg(mmc_dev(host->mmc),
  939. "Switch operation failed\n");
  940. }
  941. }
  942. if (ios->clock) {
  943. dsor = OMAP_MMC_MASTER_CLOCK / ios->clock;
  944. if (dsor < 1)
  945. dsor = 1;
  946. if (OMAP_MMC_MASTER_CLOCK / dsor > ios->clock)
  947. dsor++;
  948. if (dsor > 250)
  949. dsor = 250;
  950. }
  951. omap_mmc_stop_clock(host);
  952. regval = OMAP_HSMMC_READ(host->base, SYSCTL);
  953. regval = regval & ~(CLKD_MASK);
  954. regval = regval | (dsor << 6) | (DTO << 16);
  955. OMAP_HSMMC_WRITE(host->base, SYSCTL, regval);
  956. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  957. OMAP_HSMMC_READ(host->base, SYSCTL) | ICE);
  958. /* Wait till the ICS bit is set */
  959. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  960. while ((OMAP_HSMMC_READ(host->base, SYSCTL) & ICS) != ICS
  961. && time_before(jiffies, timeout))
  962. msleep(1);
  963. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  964. OMAP_HSMMC_READ(host->base, SYSCTL) | CEN);
  965. if (do_send_init_stream)
  966. send_init_stream(host);
  967. con = OMAP_HSMMC_READ(host->base, CON);
  968. if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
  969. OMAP_HSMMC_WRITE(host->base, CON, con | OD);
  970. else
  971. OMAP_HSMMC_WRITE(host->base, CON, con & ~OD);
  972. if (host->power_mode == MMC_POWER_OFF)
  973. mmc_host_disable(host->mmc);
  974. else
  975. mmc_host_lazy_disable(host->mmc);
  976. }
  977. static int omap_hsmmc_get_cd(struct mmc_host *mmc)
  978. {
  979. struct mmc_omap_host *host = mmc_priv(mmc);
  980. struct omap_mmc_platform_data *pdata = host->pdata;
  981. if (!pdata->slots[0].card_detect)
  982. return -ENOSYS;
  983. return pdata->slots[0].card_detect(pdata->slots[0].card_detect_irq);
  984. }
  985. static int omap_hsmmc_get_ro(struct mmc_host *mmc)
  986. {
  987. struct mmc_omap_host *host = mmc_priv(mmc);
  988. struct omap_mmc_platform_data *pdata = host->pdata;
  989. if (!pdata->slots[0].get_ro)
  990. return -ENOSYS;
  991. return pdata->slots[0].get_ro(host->dev, 0);
  992. }
  993. static void omap_hsmmc_init(struct mmc_omap_host *host)
  994. {
  995. u32 hctl, capa, value;
  996. /* Only MMC1 supports 3.0V */
  997. if (host->id == OMAP_MMC1_DEVID) {
  998. hctl = SDVS30;
  999. capa = VS30 | VS18;
  1000. } else {
  1001. hctl = SDVS18;
  1002. capa = VS18;
  1003. }
  1004. value = OMAP_HSMMC_READ(host->base, HCTL) & ~SDVS_MASK;
  1005. OMAP_HSMMC_WRITE(host->base, HCTL, value | hctl);
  1006. value = OMAP_HSMMC_READ(host->base, CAPA);
  1007. OMAP_HSMMC_WRITE(host->base, CAPA, value | capa);
  1008. /* Set the controller to AUTO IDLE mode */
  1009. value = OMAP_HSMMC_READ(host->base, SYSCONFIG);
  1010. OMAP_HSMMC_WRITE(host->base, SYSCONFIG, value | AUTOIDLE);
  1011. /* Set SD bus power bit */
  1012. set_sd_bus_power(host);
  1013. }
  1014. /*
  1015. * Dynamic power saving handling, FSM:
  1016. * ENABLED -> DISABLED -> OFF
  1017. * ^___________| |
  1018. * |______________________|
  1019. *
  1020. * ENABLED: mmc host is fully functional
  1021. * DISABLED: fclk is off
  1022. * OFF: fclk is off,voltage regulator is off
  1023. *
  1024. * Transition handlers return the timeout for the next state transition
  1025. * or negative error.
  1026. */
  1027. enum {ENABLED = 0, DISABLED, OFF};
  1028. /* Handler for [ENABLED -> DISABLED] transition */
  1029. static int omap_mmc_enabled_to_disabled(struct mmc_omap_host *host)
  1030. {
  1031. omap_mmc_save_ctx(host);
  1032. clk_disable(host->fclk);
  1033. host->dpm_state = DISABLED;
  1034. dev_dbg(mmc_dev(host->mmc), "ENABLED -> DISABLED\n");
  1035. if (host->power_mode == MMC_POWER_OFF)
  1036. return 0;
  1037. return msecs_to_jiffies(OMAP_MMC_OFF_TIMEOUT);
  1038. }
  1039. /* Handler for [DISABLED -> OFF] transition */
  1040. static int omap_mmc_disabled_to_off(struct mmc_omap_host *host)
  1041. {
  1042. int new_state;
  1043. dev_dbg(mmc_dev(host->mmc), "DISABLED -> OFF\n");
  1044. if (!mmc_try_claim_host(host->mmc))
  1045. return 0;
  1046. clk_enable(host->fclk);
  1047. omap_mmc_restore_ctx(host);
  1048. if ((host->mmc->caps & MMC_CAP_NONREMOVABLE) ||
  1049. mmc_slot(host).card_detect ||
  1050. (mmc_slot(host).get_cover_state &&
  1051. mmc_slot(host).get_cover_state(host->dev, host->slot_id))) {
  1052. mmc_power_save_host(host->mmc);
  1053. new_state = OFF;
  1054. } else
  1055. new_state = DISABLED;
  1056. OMAP_HSMMC_WRITE(host->base, ISE, 0);
  1057. OMAP_HSMMC_WRITE(host->base, IE, 0);
  1058. OMAP_HSMMC_WRITE(host->base, HCTL,
  1059. OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP);
  1060. clk_disable(host->fclk);
  1061. clk_disable(host->iclk);
  1062. clk_disable(host->dbclk);
  1063. host->dpm_state = new_state;
  1064. mmc_release_host(host->mmc);
  1065. return 0;
  1066. }
  1067. /* Handler for [DISABLED -> ENABLED] transition */
  1068. static int omap_mmc_disabled_to_enabled(struct mmc_omap_host *host)
  1069. {
  1070. int err;
  1071. err = clk_enable(host->fclk);
  1072. if (err < 0)
  1073. return err;
  1074. omap_mmc_restore_ctx(host);
  1075. host->dpm_state = ENABLED;
  1076. dev_dbg(mmc_dev(host->mmc), "DISABLED -> ENABLED\n");
  1077. return 0;
  1078. }
  1079. /* Handler for [OFF -> ENABLED] transition */
  1080. static int omap_mmc_off_to_enabled(struct mmc_omap_host *host)
  1081. {
  1082. clk_enable(host->fclk);
  1083. clk_enable(host->iclk);
  1084. if (clk_enable(host->dbclk))
  1085. dev_dbg(mmc_dev(host->mmc),
  1086. "Enabling debounce clk failed\n");
  1087. omap_mmc_restore_ctx(host);
  1088. omap_hsmmc_init(host);
  1089. mmc_power_restore_host(host->mmc);
  1090. host->dpm_state = ENABLED;
  1091. dev_dbg(mmc_dev(host->mmc), "OFF -> ENABLED\n");
  1092. return 0;
  1093. }
  1094. /*
  1095. * Bring MMC host to ENABLED from any other PM state.
  1096. */
  1097. static int omap_mmc_enable(struct mmc_host *mmc)
  1098. {
  1099. struct mmc_omap_host *host = mmc_priv(mmc);
  1100. switch (host->dpm_state) {
  1101. case DISABLED:
  1102. return omap_mmc_disabled_to_enabled(host);
  1103. case OFF:
  1104. return omap_mmc_off_to_enabled(host);
  1105. default:
  1106. dev_dbg(mmc_dev(host->mmc), "UNKNOWN state\n");
  1107. return -EINVAL;
  1108. }
  1109. }
  1110. /*
  1111. * Bring MMC host in PM state (one level deeper).
  1112. */
  1113. static int omap_mmc_disable(struct mmc_host *mmc, int lazy)
  1114. {
  1115. struct mmc_omap_host *host = mmc_priv(mmc);
  1116. switch (host->dpm_state) {
  1117. case ENABLED: {
  1118. int delay;
  1119. delay = omap_mmc_enabled_to_disabled(host);
  1120. if (lazy || delay < 0)
  1121. return delay;
  1122. return 0;
  1123. }
  1124. case DISABLED:
  1125. return omap_mmc_disabled_to_off(host);
  1126. default:
  1127. dev_dbg(mmc_dev(host->mmc), "UNKNOWN state\n");
  1128. return -EINVAL;
  1129. }
  1130. }
  1131. static int omap_mmc_enable_fclk(struct mmc_host *mmc)
  1132. {
  1133. struct mmc_omap_host *host = mmc_priv(mmc);
  1134. int err;
  1135. err = clk_enable(host->fclk);
  1136. if (err)
  1137. return err;
  1138. dev_dbg(mmc_dev(host->mmc), "mmc_fclk: enabled\n");
  1139. omap_mmc_restore_ctx(host);
  1140. return 0;
  1141. }
  1142. static int omap_mmc_disable_fclk(struct mmc_host *mmc, int lazy)
  1143. {
  1144. struct mmc_omap_host *host = mmc_priv(mmc);
  1145. omap_mmc_save_ctx(host);
  1146. clk_disable(host->fclk);
  1147. dev_dbg(mmc_dev(host->mmc), "mmc_fclk: disabled\n");
  1148. return 0;
  1149. }
  1150. static const struct mmc_host_ops mmc_omap_ops = {
  1151. .enable = omap_mmc_enable_fclk,
  1152. .disable = omap_mmc_disable_fclk,
  1153. .request = omap_mmc_request,
  1154. .set_ios = omap_mmc_set_ios,
  1155. .get_cd = omap_hsmmc_get_cd,
  1156. .get_ro = omap_hsmmc_get_ro,
  1157. /* NYET -- enable_sdio_irq */
  1158. };
  1159. static const struct mmc_host_ops mmc_omap_ps_ops = {
  1160. .enable = omap_mmc_enable,
  1161. .disable = omap_mmc_disable,
  1162. .request = omap_mmc_request,
  1163. .set_ios = omap_mmc_set_ios,
  1164. .get_cd = omap_hsmmc_get_cd,
  1165. .get_ro = omap_hsmmc_get_ro,
  1166. /* NYET -- enable_sdio_irq */
  1167. };
  1168. #ifdef CONFIG_DEBUG_FS
  1169. static int mmc_regs_show(struct seq_file *s, void *data)
  1170. {
  1171. struct mmc_host *mmc = s->private;
  1172. struct mmc_omap_host *host = mmc_priv(mmc);
  1173. struct omap_mmc_platform_data *pdata = host->pdata;
  1174. int context_loss = 0;
  1175. if (pdata->get_context_loss_count)
  1176. context_loss = pdata->get_context_loss_count(host->dev);
  1177. seq_printf(s, "mmc%d:\n"
  1178. " enabled:\t%d\n"
  1179. " dpm_state:\t%d\n"
  1180. " nesting_cnt:\t%d\n"
  1181. " ctx_loss:\t%d:%d\n"
  1182. "\nregs:\n",
  1183. mmc->index, mmc->enabled ? 1 : 0,
  1184. host->dpm_state, mmc->nesting_cnt,
  1185. host->context_loss, context_loss);
  1186. if (host->suspended || host->dpm_state == OFF) {
  1187. seq_printf(s, "host suspended, can't read registers\n");
  1188. return 0;
  1189. }
  1190. if (clk_enable(host->fclk) != 0) {
  1191. seq_printf(s, "can't read the regs\n");
  1192. return 0;
  1193. }
  1194. seq_printf(s, "SYSCONFIG:\t0x%08x\n",
  1195. OMAP_HSMMC_READ(host->base, SYSCONFIG));
  1196. seq_printf(s, "CON:\t\t0x%08x\n",
  1197. OMAP_HSMMC_READ(host->base, CON));
  1198. seq_printf(s, "HCTL:\t\t0x%08x\n",
  1199. OMAP_HSMMC_READ(host->base, HCTL));
  1200. seq_printf(s, "SYSCTL:\t\t0x%08x\n",
  1201. OMAP_HSMMC_READ(host->base, SYSCTL));
  1202. seq_printf(s, "IE:\t\t0x%08x\n",
  1203. OMAP_HSMMC_READ(host->base, IE));
  1204. seq_printf(s, "ISE:\t\t0x%08x\n",
  1205. OMAP_HSMMC_READ(host->base, ISE));
  1206. seq_printf(s, "CAPA:\t\t0x%08x\n",
  1207. OMAP_HSMMC_READ(host->base, CAPA));
  1208. clk_disable(host->fclk);
  1209. return 0;
  1210. }
  1211. static int mmc_regs_open(struct inode *inode, struct file *file)
  1212. {
  1213. return single_open(file, mmc_regs_show, inode->i_private);
  1214. }
  1215. static const struct file_operations mmc_regs_fops = {
  1216. .open = mmc_regs_open,
  1217. .read = seq_read,
  1218. .llseek = seq_lseek,
  1219. .release = single_release,
  1220. };
  1221. static void omap_mmc_debugfs(struct mmc_host *mmc)
  1222. {
  1223. if (mmc->debugfs_root)
  1224. debugfs_create_file("regs", S_IRUSR, mmc->debugfs_root,
  1225. mmc, &mmc_regs_fops);
  1226. }
  1227. #else
  1228. static void omap_mmc_debugfs(struct mmc_host *mmc)
  1229. {
  1230. }
  1231. #endif
  1232. static int __init omap_mmc_probe(struct platform_device *pdev)
  1233. {
  1234. struct omap_mmc_platform_data *pdata = pdev->dev.platform_data;
  1235. struct mmc_host *mmc;
  1236. struct mmc_omap_host *host = NULL;
  1237. struct resource *res;
  1238. int ret = 0, irq;
  1239. if (pdata == NULL) {
  1240. dev_err(&pdev->dev, "Platform Data is missing\n");
  1241. return -ENXIO;
  1242. }
  1243. if (pdata->nr_slots == 0) {
  1244. dev_err(&pdev->dev, "No Slots\n");
  1245. return -ENXIO;
  1246. }
  1247. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1248. irq = platform_get_irq(pdev, 0);
  1249. if (res == NULL || irq < 0)
  1250. return -ENXIO;
  1251. res = request_mem_region(res->start, res->end - res->start + 1,
  1252. pdev->name);
  1253. if (res == NULL)
  1254. return -EBUSY;
  1255. mmc = mmc_alloc_host(sizeof(struct mmc_omap_host), &pdev->dev);
  1256. if (!mmc) {
  1257. ret = -ENOMEM;
  1258. goto err;
  1259. }
  1260. host = mmc_priv(mmc);
  1261. host->mmc = mmc;
  1262. host->pdata = pdata;
  1263. host->dev = &pdev->dev;
  1264. host->use_dma = 1;
  1265. host->dev->dma_mask = &pdata->dma_mask;
  1266. host->dma_ch = -1;
  1267. host->irq = irq;
  1268. host->id = pdev->id;
  1269. host->slot_id = 0;
  1270. host->mapbase = res->start;
  1271. host->base = ioremap(host->mapbase, SZ_4K);
  1272. host->power_mode = -1;
  1273. platform_set_drvdata(pdev, host);
  1274. INIT_WORK(&host->mmc_carddetect_work, mmc_omap_detect);
  1275. if (pdata->slots[host->slot_id].power_saving)
  1276. mmc->ops = &mmc_omap_ps_ops;
  1277. else
  1278. mmc->ops = &mmc_omap_ops;
  1279. mmc->f_min = 400000;
  1280. mmc->f_max = 52000000;
  1281. sema_init(&host->sem, 1);
  1282. host->iclk = clk_get(&pdev->dev, "ick");
  1283. if (IS_ERR(host->iclk)) {
  1284. ret = PTR_ERR(host->iclk);
  1285. host->iclk = NULL;
  1286. goto err1;
  1287. }
  1288. host->fclk = clk_get(&pdev->dev, "fck");
  1289. if (IS_ERR(host->fclk)) {
  1290. ret = PTR_ERR(host->fclk);
  1291. host->fclk = NULL;
  1292. clk_put(host->iclk);
  1293. goto err1;
  1294. }
  1295. omap_mmc_save_ctx(host);
  1296. mmc->caps |= MMC_CAP_DISABLE;
  1297. mmc_set_disable_delay(mmc, OMAP_MMC_DISABLED_TIMEOUT);
  1298. /* we start off in DISABLED state */
  1299. host->dpm_state = DISABLED;
  1300. if (mmc_host_enable(host->mmc) != 0) {
  1301. clk_put(host->iclk);
  1302. clk_put(host->fclk);
  1303. goto err1;
  1304. }
  1305. if (clk_enable(host->iclk) != 0) {
  1306. mmc_host_disable(host->mmc);
  1307. clk_put(host->iclk);
  1308. clk_put(host->fclk);
  1309. goto err1;
  1310. }
  1311. host->dbclk = clk_get(&pdev->dev, "mmchsdb_fck");
  1312. /*
  1313. * MMC can still work without debounce clock.
  1314. */
  1315. if (IS_ERR(host->dbclk))
  1316. dev_warn(mmc_dev(host->mmc), "Failed to get debounce clock\n");
  1317. else
  1318. if (clk_enable(host->dbclk) != 0)
  1319. dev_dbg(mmc_dev(host->mmc), "Enabling debounce"
  1320. " clk failed\n");
  1321. else
  1322. host->dbclk_enabled = 1;
  1323. /* Since we do only SG emulation, we can have as many segs
  1324. * as we want. */
  1325. mmc->max_phys_segs = 1024;
  1326. mmc->max_hw_segs = 1024;
  1327. mmc->max_blk_size = 512; /* Block Length at max can be 1024 */
  1328. mmc->max_blk_count = 0xFFFF; /* No. of Blocks is 16 bits */
  1329. mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
  1330. mmc->max_seg_size = mmc->max_req_size;
  1331. mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED;
  1332. if (pdata->slots[host->slot_id].wires >= 8)
  1333. mmc->caps |= MMC_CAP_8_BIT_DATA;
  1334. else if (pdata->slots[host->slot_id].wires >= 4)
  1335. mmc->caps |= MMC_CAP_4_BIT_DATA;
  1336. if (pdata->slots[host->slot_id].nonremovable)
  1337. mmc->caps |= MMC_CAP_NONREMOVABLE;
  1338. omap_hsmmc_init(host);
  1339. /* Select DMA lines */
  1340. switch (host->id) {
  1341. case OMAP_MMC1_DEVID:
  1342. host->dma_line_tx = OMAP24XX_DMA_MMC1_TX;
  1343. host->dma_line_rx = OMAP24XX_DMA_MMC1_RX;
  1344. break;
  1345. case OMAP_MMC2_DEVID:
  1346. host->dma_line_tx = OMAP24XX_DMA_MMC2_TX;
  1347. host->dma_line_rx = OMAP24XX_DMA_MMC2_RX;
  1348. break;
  1349. case OMAP_MMC3_DEVID:
  1350. host->dma_line_tx = OMAP34XX_DMA_MMC3_TX;
  1351. host->dma_line_rx = OMAP34XX_DMA_MMC3_RX;
  1352. break;
  1353. default:
  1354. dev_err(mmc_dev(host->mmc), "Invalid MMC id\n");
  1355. goto err_irq;
  1356. }
  1357. /* Request IRQ for MMC operations */
  1358. ret = request_irq(host->irq, mmc_omap_irq, IRQF_DISABLED,
  1359. mmc_hostname(mmc), host);
  1360. if (ret) {
  1361. dev_dbg(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n");
  1362. goto err_irq;
  1363. }
  1364. /* initialize power supplies, gpios, etc */
  1365. if (pdata->init != NULL) {
  1366. if (pdata->init(&pdev->dev) != 0) {
  1367. dev_dbg(mmc_dev(host->mmc), "late init error\n");
  1368. goto err_irq_cd_init;
  1369. }
  1370. }
  1371. mmc->ocr_avail = mmc_slot(host).ocr_mask;
  1372. /* Request IRQ for card detect */
  1373. if ((mmc_slot(host).card_detect_irq)) {
  1374. ret = request_irq(mmc_slot(host).card_detect_irq,
  1375. omap_mmc_cd_handler,
  1376. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
  1377. | IRQF_DISABLED,
  1378. mmc_hostname(mmc), host);
  1379. if (ret) {
  1380. dev_dbg(mmc_dev(host->mmc),
  1381. "Unable to grab MMC CD IRQ\n");
  1382. goto err_irq_cd;
  1383. }
  1384. }
  1385. OMAP_HSMMC_WRITE(host->base, ISE, INT_EN_MASK);
  1386. OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
  1387. mmc_host_lazy_disable(host->mmc);
  1388. mmc_add_host(mmc);
  1389. if (host->pdata->slots[host->slot_id].name != NULL) {
  1390. ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name);
  1391. if (ret < 0)
  1392. goto err_slot_name;
  1393. }
  1394. if (mmc_slot(host).card_detect_irq &&
  1395. host->pdata->slots[host->slot_id].get_cover_state) {
  1396. ret = device_create_file(&mmc->class_dev,
  1397. &dev_attr_cover_switch);
  1398. if (ret < 0)
  1399. goto err_cover_switch;
  1400. }
  1401. omap_mmc_debugfs(mmc);
  1402. return 0;
  1403. err_cover_switch:
  1404. device_remove_file(&mmc->class_dev, &dev_attr_cover_switch);
  1405. err_slot_name:
  1406. mmc_remove_host(mmc);
  1407. err_irq_cd:
  1408. free_irq(mmc_slot(host).card_detect_irq, host);
  1409. err_irq_cd_init:
  1410. free_irq(host->irq, host);
  1411. err_irq:
  1412. mmc_host_disable(host->mmc);
  1413. clk_disable(host->iclk);
  1414. clk_put(host->fclk);
  1415. clk_put(host->iclk);
  1416. if (host->dbclk_enabled) {
  1417. clk_disable(host->dbclk);
  1418. clk_put(host->dbclk);
  1419. }
  1420. err1:
  1421. iounmap(host->base);
  1422. err:
  1423. dev_dbg(mmc_dev(host->mmc), "Probe Failed\n");
  1424. release_mem_region(res->start, res->end - res->start + 1);
  1425. if (host)
  1426. mmc_free_host(mmc);
  1427. return ret;
  1428. }
  1429. static int omap_mmc_remove(struct platform_device *pdev)
  1430. {
  1431. struct mmc_omap_host *host = platform_get_drvdata(pdev);
  1432. struct resource *res;
  1433. if (host) {
  1434. mmc_host_enable(host->mmc);
  1435. mmc_remove_host(host->mmc);
  1436. if (host->pdata->cleanup)
  1437. host->pdata->cleanup(&pdev->dev);
  1438. free_irq(host->irq, host);
  1439. if (mmc_slot(host).card_detect_irq)
  1440. free_irq(mmc_slot(host).card_detect_irq, host);
  1441. flush_scheduled_work();
  1442. mmc_host_disable(host->mmc);
  1443. clk_disable(host->iclk);
  1444. clk_put(host->fclk);
  1445. clk_put(host->iclk);
  1446. if (host->dbclk_enabled) {
  1447. clk_disable(host->dbclk);
  1448. clk_put(host->dbclk);
  1449. }
  1450. mmc_free_host(host->mmc);
  1451. iounmap(host->base);
  1452. }
  1453. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1454. if (res)
  1455. release_mem_region(res->start, res->end - res->start + 1);
  1456. platform_set_drvdata(pdev, NULL);
  1457. return 0;
  1458. }
  1459. #ifdef CONFIG_PM
  1460. static int omap_mmc_suspend(struct platform_device *pdev, pm_message_t state)
  1461. {
  1462. int ret = 0;
  1463. struct mmc_omap_host *host = platform_get_drvdata(pdev);
  1464. if (host && host->suspended)
  1465. return 0;
  1466. if (host) {
  1467. host->suspended = 1;
  1468. if (host->pdata->suspend) {
  1469. ret = host->pdata->suspend(&pdev->dev,
  1470. host->slot_id);
  1471. if (ret) {
  1472. dev_dbg(mmc_dev(host->mmc),
  1473. "Unable to handle MMC board"
  1474. " level suspend\n");
  1475. host->suspended = 0;
  1476. return ret;
  1477. }
  1478. }
  1479. cancel_work_sync(&host->mmc_carddetect_work);
  1480. mmc_host_enable(host->mmc);
  1481. ret = mmc_suspend_host(host->mmc, state);
  1482. if (ret == 0) {
  1483. OMAP_HSMMC_WRITE(host->base, ISE, 0);
  1484. OMAP_HSMMC_WRITE(host->base, IE, 0);
  1485. OMAP_HSMMC_WRITE(host->base, HCTL,
  1486. OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP);
  1487. mmc_host_disable(host->mmc);
  1488. clk_disable(host->iclk);
  1489. clk_disable(host->dbclk);
  1490. } else {
  1491. host->suspended = 0;
  1492. if (host->pdata->resume) {
  1493. ret = host->pdata->resume(&pdev->dev,
  1494. host->slot_id);
  1495. if (ret)
  1496. dev_dbg(mmc_dev(host->mmc),
  1497. "Unmask interrupt failed\n");
  1498. }
  1499. mmc_host_disable(host->mmc);
  1500. }
  1501. }
  1502. return ret;
  1503. }
  1504. /* Routine to resume the MMC device */
  1505. static int omap_mmc_resume(struct platform_device *pdev)
  1506. {
  1507. int ret = 0;
  1508. struct mmc_omap_host *host = platform_get_drvdata(pdev);
  1509. if (host && !host->suspended)
  1510. return 0;
  1511. if (host) {
  1512. ret = clk_enable(host->iclk);
  1513. if (ret)
  1514. goto clk_en_err;
  1515. if (clk_enable(host->dbclk) != 0)
  1516. dev_dbg(mmc_dev(host->mmc),
  1517. "Enabling debounce clk failed\n");
  1518. if (mmc_host_enable(host->mmc) != 0) {
  1519. clk_disable(host->iclk);
  1520. goto clk_en_err;
  1521. }
  1522. omap_hsmmc_init(host);
  1523. if (host->pdata->resume) {
  1524. ret = host->pdata->resume(&pdev->dev, host->slot_id);
  1525. if (ret)
  1526. dev_dbg(mmc_dev(host->mmc),
  1527. "Unmask interrupt failed\n");
  1528. }
  1529. /* Notify the core to resume the host */
  1530. ret = mmc_resume_host(host->mmc);
  1531. if (ret == 0)
  1532. host->suspended = 0;
  1533. mmc_host_lazy_disable(host->mmc);
  1534. }
  1535. return ret;
  1536. clk_en_err:
  1537. dev_dbg(mmc_dev(host->mmc),
  1538. "Failed to enable MMC clocks during resume\n");
  1539. return ret;
  1540. }
  1541. #else
  1542. #define omap_mmc_suspend NULL
  1543. #define omap_mmc_resume NULL
  1544. #endif
  1545. static struct platform_driver omap_mmc_driver = {
  1546. .remove = omap_mmc_remove,
  1547. .suspend = omap_mmc_suspend,
  1548. .resume = omap_mmc_resume,
  1549. .driver = {
  1550. .name = DRIVER_NAME,
  1551. .owner = THIS_MODULE,
  1552. },
  1553. };
  1554. static int __init omap_mmc_init(void)
  1555. {
  1556. /* Register the MMC driver */
  1557. return platform_driver_probe(&omap_mmc_driver, omap_mmc_probe);
  1558. }
  1559. static void __exit omap_mmc_cleanup(void)
  1560. {
  1561. /* Unregister MMC driver */
  1562. platform_driver_unregister(&omap_mmc_driver);
  1563. }
  1564. module_init(omap_mmc_init);
  1565. module_exit(omap_mmc_cleanup);
  1566. MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver");
  1567. MODULE_LICENSE("GPL");
  1568. MODULE_ALIAS("platform:" DRIVER_NAME);
  1569. MODULE_AUTHOR("Texas Instruments Inc");