omap_hsmmc.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272
  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/interrupt.h>
  20. #include <linux/delay.h>
  21. #include <linux/dma-mapping.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/workqueue.h>
  24. #include <linux/timer.h>
  25. #include <linux/clk.h>
  26. #include <linux/mmc/host.h>
  27. #include <linux/io.h>
  28. #include <linux/semaphore.h>
  29. #include <mach/dma.h>
  30. #include <mach/hardware.h>
  31. #include <mach/board.h>
  32. #include <mach/mmc.h>
  33. #include <mach/cpu.h>
  34. /* OMAP HSMMC Host Controller Registers */
  35. #define OMAP_HSMMC_SYSCONFIG 0x0010
  36. #define OMAP_HSMMC_CON 0x002C
  37. #define OMAP_HSMMC_BLK 0x0104
  38. #define OMAP_HSMMC_ARG 0x0108
  39. #define OMAP_HSMMC_CMD 0x010C
  40. #define OMAP_HSMMC_RSP10 0x0110
  41. #define OMAP_HSMMC_RSP32 0x0114
  42. #define OMAP_HSMMC_RSP54 0x0118
  43. #define OMAP_HSMMC_RSP76 0x011C
  44. #define OMAP_HSMMC_DATA 0x0120
  45. #define OMAP_HSMMC_HCTL 0x0128
  46. #define OMAP_HSMMC_SYSCTL 0x012C
  47. #define OMAP_HSMMC_STAT 0x0130
  48. #define OMAP_HSMMC_IE 0x0134
  49. #define OMAP_HSMMC_ISE 0x0138
  50. #define OMAP_HSMMC_CAPA 0x0140
  51. #define VS18 (1 << 26)
  52. #define VS30 (1 << 25)
  53. #define SDVS18 (0x5 << 9)
  54. #define SDVS30 (0x6 << 9)
  55. #define SDVS33 (0x7 << 9)
  56. #define SDVS_MASK 0x00000E00
  57. #define SDVSCLR 0xFFFFF1FF
  58. #define SDVSDET 0x00000400
  59. #define AUTOIDLE 0x1
  60. #define SDBP (1 << 8)
  61. #define DTO 0xe
  62. #define ICE 0x1
  63. #define ICS 0x2
  64. #define CEN (1 << 2)
  65. #define CLKD_MASK 0x0000FFC0
  66. #define CLKD_SHIFT 6
  67. #define DTO_MASK 0x000F0000
  68. #define DTO_SHIFT 16
  69. #define INT_EN_MASK 0x307F0033
  70. #define INIT_STREAM (1 << 1)
  71. #define DP_SELECT (1 << 21)
  72. #define DDIR (1 << 4)
  73. #define DMA_EN 0x1
  74. #define MSBS (1 << 5)
  75. #define BCE (1 << 1)
  76. #define FOUR_BIT (1 << 1)
  77. #define CC 0x1
  78. #define TC 0x02
  79. #define OD 0x1
  80. #define ERR (1 << 15)
  81. #define CMD_TIMEOUT (1 << 16)
  82. #define DATA_TIMEOUT (1 << 20)
  83. #define CMD_CRC (1 << 17)
  84. #define DATA_CRC (1 << 21)
  85. #define CARD_ERR (1 << 28)
  86. #define STAT_CLEAR 0xFFFFFFFF
  87. #define INIT_STREAM_CMD 0x00000000
  88. #define DUAL_VOLT_OCR_BIT 7
  89. #define SRC (1 << 25)
  90. #define SRD (1 << 26)
  91. /*
  92. * FIXME: Most likely all the data using these _DEVID defines should come
  93. * from the platform_data, or implemented in controller and slot specific
  94. * functions.
  95. */
  96. #define OMAP_MMC1_DEVID 0
  97. #define OMAP_MMC2_DEVID 1
  98. #define OMAP_MMC_DATADIR_NONE 0
  99. #define OMAP_MMC_DATADIR_READ 1
  100. #define OMAP_MMC_DATADIR_WRITE 2
  101. #define MMC_TIMEOUT_MS 20
  102. #define OMAP_MMC_MASTER_CLOCK 96000000
  103. #define DRIVER_NAME "mmci-omap-hs"
  104. /*
  105. * One controller can have multiple slots, like on some omap boards using
  106. * omap.c controller driver. Luckily this is not currently done on any known
  107. * omap_hsmmc.c device.
  108. */
  109. #define mmc_slot(host) (host->pdata->slots[host->slot_id])
  110. /*
  111. * MMC Host controller read/write API's
  112. */
  113. #define OMAP_HSMMC_READ(base, reg) \
  114. __raw_readl((base) + OMAP_HSMMC_##reg)
  115. #define OMAP_HSMMC_WRITE(base, reg, val) \
  116. __raw_writel((val), (base) + OMAP_HSMMC_##reg)
  117. struct mmc_omap_host {
  118. struct device *dev;
  119. struct mmc_host *mmc;
  120. struct mmc_request *mrq;
  121. struct mmc_command *cmd;
  122. struct mmc_data *data;
  123. struct clk *fclk;
  124. struct clk *iclk;
  125. struct clk *dbclk;
  126. struct semaphore sem;
  127. struct work_struct mmc_carddetect_work;
  128. void __iomem *base;
  129. resource_size_t mapbase;
  130. unsigned int id;
  131. unsigned int dma_len;
  132. unsigned int dma_dir;
  133. unsigned char bus_mode;
  134. unsigned char datadir;
  135. u32 *buffer;
  136. u32 bytesleft;
  137. int suspended;
  138. int irq;
  139. int carddetect;
  140. int use_dma, dma_ch;
  141. int initstr;
  142. int slot_id;
  143. int dbclk_enabled;
  144. struct omap_mmc_platform_data *pdata;
  145. };
  146. /*
  147. * Stop clock to the card
  148. */
  149. static void omap_mmc_stop_clock(struct mmc_omap_host *host)
  150. {
  151. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  152. OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN);
  153. if ((OMAP_HSMMC_READ(host->base, SYSCTL) & CEN) != 0x0)
  154. dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stoped\n");
  155. }
  156. /*
  157. * Send init stream sequence to card
  158. * before sending IDLE command
  159. */
  160. static void send_init_stream(struct mmc_omap_host *host)
  161. {
  162. int reg = 0;
  163. unsigned long timeout;
  164. disable_irq(host->irq);
  165. OMAP_HSMMC_WRITE(host->base, CON,
  166. OMAP_HSMMC_READ(host->base, CON) | INIT_STREAM);
  167. OMAP_HSMMC_WRITE(host->base, CMD, INIT_STREAM_CMD);
  168. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  169. while ((reg != CC) && time_before(jiffies, timeout))
  170. reg = OMAP_HSMMC_READ(host->base, STAT) & CC;
  171. OMAP_HSMMC_WRITE(host->base, CON,
  172. OMAP_HSMMC_READ(host->base, CON) & ~INIT_STREAM);
  173. enable_irq(host->irq);
  174. }
  175. static inline
  176. int mmc_omap_cover_is_closed(struct mmc_omap_host *host)
  177. {
  178. int r = 1;
  179. if (host->pdata->slots[host->slot_id].get_cover_state)
  180. r = host->pdata->slots[host->slot_id].get_cover_state(host->dev,
  181. host->slot_id);
  182. return r;
  183. }
  184. static ssize_t
  185. mmc_omap_show_cover_switch(struct device *dev, struct device_attribute *attr,
  186. char *buf)
  187. {
  188. struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
  189. struct mmc_omap_host *host = mmc_priv(mmc);
  190. return sprintf(buf, "%s\n", mmc_omap_cover_is_closed(host) ? "closed" :
  191. "open");
  192. }
  193. static DEVICE_ATTR(cover_switch, S_IRUGO, mmc_omap_show_cover_switch, NULL);
  194. static ssize_t
  195. mmc_omap_show_slot_name(struct device *dev, struct device_attribute *attr,
  196. char *buf)
  197. {
  198. struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
  199. struct mmc_omap_host *host = mmc_priv(mmc);
  200. struct omap_mmc_slot_data slot = host->pdata->slots[host->slot_id];
  201. return sprintf(buf, "slot:%s\n", slot.name);
  202. }
  203. static DEVICE_ATTR(slot_name, S_IRUGO, mmc_omap_show_slot_name, NULL);
  204. /*
  205. * Configure the response type and send the cmd.
  206. */
  207. static void
  208. mmc_omap_start_command(struct mmc_omap_host *host, struct mmc_command *cmd,
  209. struct mmc_data *data)
  210. {
  211. int cmdreg = 0, resptype = 0, cmdtype = 0;
  212. dev_dbg(mmc_dev(host->mmc), "%s: CMD%d, argument 0x%08x\n",
  213. mmc_hostname(host->mmc), cmd->opcode, cmd->arg);
  214. host->cmd = cmd;
  215. /*
  216. * Clear status bits and enable interrupts
  217. */
  218. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  219. OMAP_HSMMC_WRITE(host->base, ISE, INT_EN_MASK);
  220. OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
  221. if (cmd->flags & MMC_RSP_PRESENT) {
  222. if (cmd->flags & MMC_RSP_136)
  223. resptype = 1;
  224. else
  225. resptype = 2;
  226. }
  227. /*
  228. * Unlike OMAP1 controller, the cmdtype does not seem to be based on
  229. * ac, bc, adtc, bcr. Only commands ending an open ended transfer need
  230. * a val of 0x3, rest 0x0.
  231. */
  232. if (cmd == host->mrq->stop)
  233. cmdtype = 0x3;
  234. cmdreg = (cmd->opcode << 24) | (resptype << 16) | (cmdtype << 22);
  235. if (data) {
  236. cmdreg |= DP_SELECT | MSBS | BCE;
  237. if (data->flags & MMC_DATA_READ)
  238. cmdreg |= DDIR;
  239. else
  240. cmdreg &= ~(DDIR);
  241. }
  242. if (host->use_dma)
  243. cmdreg |= DMA_EN;
  244. OMAP_HSMMC_WRITE(host->base, ARG, cmd->arg);
  245. OMAP_HSMMC_WRITE(host->base, CMD, cmdreg);
  246. }
  247. /*
  248. * Notify the transfer complete to MMC core
  249. */
  250. static void
  251. mmc_omap_xfer_done(struct mmc_omap_host *host, struct mmc_data *data)
  252. {
  253. host->data = NULL;
  254. if (host->use_dma && host->dma_ch != -1)
  255. dma_unmap_sg(mmc_dev(host->mmc), data->sg, host->dma_len,
  256. host->dma_dir);
  257. host->datadir = OMAP_MMC_DATADIR_NONE;
  258. if (!data->error)
  259. data->bytes_xfered += data->blocks * (data->blksz);
  260. else
  261. data->bytes_xfered = 0;
  262. if (!data->stop) {
  263. host->mrq = NULL;
  264. mmc_request_done(host->mmc, data->mrq);
  265. return;
  266. }
  267. mmc_omap_start_command(host, data->stop, NULL);
  268. }
  269. /*
  270. * Notify the core about command completion
  271. */
  272. static void
  273. mmc_omap_cmd_done(struct mmc_omap_host *host, struct mmc_command *cmd)
  274. {
  275. host->cmd = NULL;
  276. if (cmd->flags & MMC_RSP_PRESENT) {
  277. if (cmd->flags & MMC_RSP_136) {
  278. /* response type 2 */
  279. cmd->resp[3] = OMAP_HSMMC_READ(host->base, RSP10);
  280. cmd->resp[2] = OMAP_HSMMC_READ(host->base, RSP32);
  281. cmd->resp[1] = OMAP_HSMMC_READ(host->base, RSP54);
  282. cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP76);
  283. } else {
  284. /* response types 1, 1b, 3, 4, 5, 6 */
  285. cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP10);
  286. }
  287. }
  288. if (host->data == NULL || cmd->error) {
  289. host->mrq = NULL;
  290. mmc_request_done(host->mmc, cmd->mrq);
  291. }
  292. }
  293. /*
  294. * DMA clean up for command errors
  295. */
  296. static void mmc_dma_cleanup(struct mmc_omap_host *host)
  297. {
  298. host->data->error = -ETIMEDOUT;
  299. if (host->use_dma && host->dma_ch != -1) {
  300. dma_unmap_sg(mmc_dev(host->mmc), host->data->sg, host->dma_len,
  301. host->dma_dir);
  302. omap_free_dma(host->dma_ch);
  303. host->dma_ch = -1;
  304. up(&host->sem);
  305. }
  306. host->data = NULL;
  307. host->datadir = OMAP_MMC_DATADIR_NONE;
  308. }
  309. /*
  310. * Readable error output
  311. */
  312. #ifdef CONFIG_MMC_DEBUG
  313. static void mmc_omap_report_irq(struct mmc_omap_host *host, u32 status)
  314. {
  315. /* --- means reserved bit without definition at documentation */
  316. static const char *mmc_omap_status_bits[] = {
  317. "CC", "TC", "BGE", "---", "BWR", "BRR", "---", "---", "CIRQ",
  318. "OBI", "---", "---", "---", "---", "---", "ERRI", "CTO", "CCRC",
  319. "CEB", "CIE", "DTO", "DCRC", "DEB", "---", "ACE", "---",
  320. "---", "---", "---", "CERR", "CERR", "BADA", "---", "---", "---"
  321. };
  322. char res[256];
  323. char *buf = res;
  324. int len, i;
  325. len = sprintf(buf, "MMC IRQ 0x%x :", status);
  326. buf += len;
  327. for (i = 0; i < ARRAY_SIZE(mmc_omap_status_bits); i++)
  328. if (status & (1 << i)) {
  329. len = sprintf(buf, " %s", mmc_omap_status_bits[i]);
  330. buf += len;
  331. }
  332. dev_dbg(mmc_dev(host->mmc), "%s\n", res);
  333. }
  334. #endif /* CONFIG_MMC_DEBUG */
  335. /*
  336. * MMC controller internal state machines reset
  337. *
  338. * Used to reset command or data internal state machines, using respectively
  339. * SRC or SRD bit of SYSCTL register
  340. * Can be called from interrupt context
  341. */
  342. static inline void mmc_omap_reset_controller_fsm(struct mmc_omap_host *host,
  343. unsigned long bit)
  344. {
  345. unsigned long i = 0;
  346. unsigned long limit = (loops_per_jiffy *
  347. msecs_to_jiffies(MMC_TIMEOUT_MS));
  348. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  349. OMAP_HSMMC_READ(host->base, SYSCTL) | bit);
  350. while ((OMAP_HSMMC_READ(host->base, SYSCTL) & bit) &&
  351. (i++ < limit))
  352. cpu_relax();
  353. if (OMAP_HSMMC_READ(host->base, SYSCTL) & bit)
  354. dev_err(mmc_dev(host->mmc),
  355. "Timeout waiting on controller reset in %s\n",
  356. __func__);
  357. }
  358. /*
  359. * MMC controller IRQ handler
  360. */
  361. static irqreturn_t mmc_omap_irq(int irq, void *dev_id)
  362. {
  363. struct mmc_omap_host *host = dev_id;
  364. struct mmc_data *data;
  365. int end_cmd = 0, end_trans = 0, status;
  366. if (host->cmd == NULL && host->data == NULL) {
  367. OMAP_HSMMC_WRITE(host->base, STAT,
  368. OMAP_HSMMC_READ(host->base, STAT));
  369. return IRQ_HANDLED;
  370. }
  371. data = host->data;
  372. status = OMAP_HSMMC_READ(host->base, STAT);
  373. dev_dbg(mmc_dev(host->mmc), "IRQ Status is %x\n", status);
  374. if (status & ERR) {
  375. #ifdef CONFIG_MMC_DEBUG
  376. mmc_omap_report_irq(host, status);
  377. #endif
  378. if ((status & CMD_TIMEOUT) ||
  379. (status & CMD_CRC)) {
  380. if (host->cmd) {
  381. if (status & CMD_TIMEOUT) {
  382. mmc_omap_reset_controller_fsm(host, SRC);
  383. host->cmd->error = -ETIMEDOUT;
  384. } else {
  385. host->cmd->error = -EILSEQ;
  386. }
  387. end_cmd = 1;
  388. }
  389. if (host->data) {
  390. mmc_dma_cleanup(host);
  391. mmc_omap_reset_controller_fsm(host, SRD);
  392. }
  393. }
  394. if ((status & DATA_TIMEOUT) ||
  395. (status & DATA_CRC)) {
  396. if (host->data) {
  397. if (status & DATA_TIMEOUT)
  398. mmc_dma_cleanup(host);
  399. else
  400. host->data->error = -EILSEQ;
  401. mmc_omap_reset_controller_fsm(host, SRD);
  402. end_trans = 1;
  403. }
  404. }
  405. if (status & CARD_ERR) {
  406. dev_dbg(mmc_dev(host->mmc),
  407. "Ignoring card err CMD%d\n", host->cmd->opcode);
  408. if (host->cmd)
  409. end_cmd = 1;
  410. if (host->data)
  411. end_trans = 1;
  412. }
  413. }
  414. OMAP_HSMMC_WRITE(host->base, STAT, status);
  415. if (end_cmd || (status & CC))
  416. mmc_omap_cmd_done(host, host->cmd);
  417. if (end_trans || (status & TC))
  418. mmc_omap_xfer_done(host, data);
  419. return IRQ_HANDLED;
  420. }
  421. /*
  422. * Switch MMC interface voltage ... only relevant for MMC1.
  423. *
  424. * MMC2 and MMC3 use fixed 1.8V levels, and maybe a transceiver.
  425. * The MMC2 transceiver controls are used instead of DAT4..DAT7.
  426. * Some chips, like eMMC ones, use internal transceivers.
  427. */
  428. static int omap_mmc_switch_opcond(struct mmc_omap_host *host, int vdd)
  429. {
  430. u32 reg_val = 0;
  431. int ret;
  432. /* Disable the clocks */
  433. clk_disable(host->fclk);
  434. clk_disable(host->iclk);
  435. clk_disable(host->dbclk);
  436. /* Turn the power off */
  437. ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0);
  438. if (ret != 0)
  439. goto err;
  440. /* Turn the power ON with given VDD 1.8 or 3.0v */
  441. ret = mmc_slot(host).set_power(host->dev, host->slot_id, 1, vdd);
  442. if (ret != 0)
  443. goto err;
  444. clk_enable(host->fclk);
  445. clk_enable(host->iclk);
  446. clk_enable(host->dbclk);
  447. OMAP_HSMMC_WRITE(host->base, HCTL,
  448. OMAP_HSMMC_READ(host->base, HCTL) & SDVSCLR);
  449. reg_val = OMAP_HSMMC_READ(host->base, HCTL);
  450. /*
  451. * If a MMC dual voltage card is detected, the set_ios fn calls
  452. * this fn with VDD bit set for 1.8V. Upon card removal from the
  453. * slot, omap_mmc_set_ios sets the VDD back to 3V on MMC_POWER_OFF.
  454. *
  455. * Cope with a bit of slop in the range ... per data sheets:
  456. * - "1.8V" for vdds_mmc1/vdds_mmc1a can be up to 2.45V max,
  457. * but recommended values are 1.71V to 1.89V
  458. * - "3.0V" for vdds_mmc1/vdds_mmc1a can be up to 3.5V max,
  459. * but recommended values are 2.7V to 3.3V
  460. *
  461. * Board setup code shouldn't permit anything very out-of-range.
  462. * TWL4030-family VMMC1 and VSIM regulators are fine (avoiding the
  463. * middle range) but VSIM can't power DAT4..DAT7 at more than 3V.
  464. */
  465. if ((1 << vdd) <= MMC_VDD_23_24)
  466. reg_val |= SDVS18;
  467. else
  468. reg_val |= SDVS30;
  469. OMAP_HSMMC_WRITE(host->base, HCTL, reg_val);
  470. OMAP_HSMMC_WRITE(host->base, HCTL,
  471. OMAP_HSMMC_READ(host->base, HCTL) | SDBP);
  472. return 0;
  473. err:
  474. dev_dbg(mmc_dev(host->mmc), "Unable to switch operating voltage\n");
  475. return ret;
  476. }
  477. /*
  478. * Work Item to notify the core about card insertion/removal
  479. */
  480. static void mmc_omap_detect(struct work_struct *work)
  481. {
  482. struct mmc_omap_host *host = container_of(work, struct mmc_omap_host,
  483. mmc_carddetect_work);
  484. struct omap_mmc_slot_data *slot = &mmc_slot(host);
  485. host->carddetect = slot->card_detect(slot->card_detect_irq);
  486. sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
  487. if (host->carddetect) {
  488. mmc_detect_change(host->mmc, (HZ * 200) / 1000);
  489. } else {
  490. mmc_omap_reset_controller_fsm(host, SRD);
  491. mmc_detect_change(host->mmc, (HZ * 50) / 1000);
  492. }
  493. }
  494. /*
  495. * ISR for handling card insertion and removal
  496. */
  497. static irqreturn_t omap_mmc_cd_handler(int irq, void *dev_id)
  498. {
  499. struct mmc_omap_host *host = (struct mmc_omap_host *)dev_id;
  500. schedule_work(&host->mmc_carddetect_work);
  501. return IRQ_HANDLED;
  502. }
  503. /*
  504. * DMA call back function
  505. */
  506. static void mmc_omap_dma_cb(int lch, u16 ch_status, void *data)
  507. {
  508. struct mmc_omap_host *host = data;
  509. if (ch_status & OMAP2_DMA_MISALIGNED_ERR_IRQ)
  510. dev_dbg(mmc_dev(host->mmc), "MISALIGNED_ADRS_ERR\n");
  511. if (host->dma_ch < 0)
  512. return;
  513. omap_free_dma(host->dma_ch);
  514. host->dma_ch = -1;
  515. /*
  516. * DMA Callback: run in interrupt context.
  517. * mutex_unlock will through a kernel warning if used.
  518. */
  519. up(&host->sem);
  520. }
  521. /*
  522. * Configure dma src and destination parameters
  523. */
  524. static int mmc_omap_config_dma_param(int sync_dir, struct mmc_omap_host *host,
  525. struct mmc_data *data)
  526. {
  527. if (sync_dir == 0) {
  528. omap_set_dma_dest_params(host->dma_ch, 0,
  529. OMAP_DMA_AMODE_CONSTANT,
  530. (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
  531. omap_set_dma_src_params(host->dma_ch, 0,
  532. OMAP_DMA_AMODE_POST_INC,
  533. sg_dma_address(&data->sg[0]), 0, 0);
  534. } else {
  535. omap_set_dma_src_params(host->dma_ch, 0,
  536. OMAP_DMA_AMODE_CONSTANT,
  537. (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
  538. omap_set_dma_dest_params(host->dma_ch, 0,
  539. OMAP_DMA_AMODE_POST_INC,
  540. sg_dma_address(&data->sg[0]), 0, 0);
  541. }
  542. return 0;
  543. }
  544. /*
  545. * Routine to configure and start DMA for the MMC card
  546. */
  547. static int
  548. mmc_omap_start_dma_transfer(struct mmc_omap_host *host, struct mmc_request *req)
  549. {
  550. int sync_dev, sync_dir = 0;
  551. int dma_ch = 0, ret = 0, err = 1;
  552. struct mmc_data *data = req->data;
  553. /*
  554. * If for some reason the DMA transfer is still active,
  555. * we wait for timeout period and free the dma
  556. */
  557. if (host->dma_ch != -1) {
  558. set_current_state(TASK_UNINTERRUPTIBLE);
  559. schedule_timeout(100);
  560. if (down_trylock(&host->sem)) {
  561. omap_free_dma(host->dma_ch);
  562. host->dma_ch = -1;
  563. up(&host->sem);
  564. return err;
  565. }
  566. } else {
  567. if (down_trylock(&host->sem))
  568. return err;
  569. }
  570. if (!(data->flags & MMC_DATA_WRITE)) {
  571. host->dma_dir = DMA_FROM_DEVICE;
  572. if (host->id == OMAP_MMC1_DEVID)
  573. sync_dev = OMAP24XX_DMA_MMC1_RX;
  574. else
  575. sync_dev = OMAP24XX_DMA_MMC2_RX;
  576. } else {
  577. host->dma_dir = DMA_TO_DEVICE;
  578. if (host->id == OMAP_MMC1_DEVID)
  579. sync_dev = OMAP24XX_DMA_MMC1_TX;
  580. else
  581. sync_dev = OMAP24XX_DMA_MMC2_TX;
  582. }
  583. ret = omap_request_dma(sync_dev, "MMC/SD", mmc_omap_dma_cb,
  584. host, &dma_ch);
  585. if (ret != 0) {
  586. dev_dbg(mmc_dev(host->mmc),
  587. "%s: omap_request_dma() failed with %d\n",
  588. mmc_hostname(host->mmc), ret);
  589. return ret;
  590. }
  591. host->dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg,
  592. data->sg_len, host->dma_dir);
  593. host->dma_ch = dma_ch;
  594. if (!(data->flags & MMC_DATA_WRITE))
  595. mmc_omap_config_dma_param(1, host, data);
  596. else
  597. mmc_omap_config_dma_param(0, host, data);
  598. if ((data->blksz % 4) == 0)
  599. omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S32,
  600. (data->blksz / 4), data->blocks, OMAP_DMA_SYNC_FRAME,
  601. sync_dev, sync_dir);
  602. else
  603. /* REVISIT: The MMC buffer increments only when MSB is written.
  604. * Return error for blksz which is non multiple of four.
  605. */
  606. return -EINVAL;
  607. omap_start_dma(dma_ch);
  608. return 0;
  609. }
  610. static void set_data_timeout(struct mmc_omap_host *host,
  611. struct mmc_request *req)
  612. {
  613. unsigned int timeout, cycle_ns;
  614. uint32_t reg, clkd, dto = 0;
  615. reg = OMAP_HSMMC_READ(host->base, SYSCTL);
  616. clkd = (reg & CLKD_MASK) >> CLKD_SHIFT;
  617. if (clkd == 0)
  618. clkd = 1;
  619. cycle_ns = 1000000000 / (clk_get_rate(host->fclk) / clkd);
  620. timeout = req->data->timeout_ns / cycle_ns;
  621. timeout += req->data->timeout_clks;
  622. if (timeout) {
  623. while ((timeout & 0x80000000) == 0) {
  624. dto += 1;
  625. timeout <<= 1;
  626. }
  627. dto = 31 - dto;
  628. timeout <<= 1;
  629. if (timeout && dto)
  630. dto += 1;
  631. if (dto >= 13)
  632. dto -= 13;
  633. else
  634. dto = 0;
  635. if (dto > 14)
  636. dto = 14;
  637. }
  638. reg &= ~DTO_MASK;
  639. reg |= dto << DTO_SHIFT;
  640. OMAP_HSMMC_WRITE(host->base, SYSCTL, reg);
  641. }
  642. /*
  643. * Configure block length for MMC/SD cards and initiate the transfer.
  644. */
  645. static int
  646. mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req)
  647. {
  648. int ret;
  649. host->data = req->data;
  650. if (req->data == NULL) {
  651. host->datadir = OMAP_MMC_DATADIR_NONE;
  652. OMAP_HSMMC_WRITE(host->base, BLK, 0);
  653. return 0;
  654. }
  655. OMAP_HSMMC_WRITE(host->base, BLK, (req->data->blksz)
  656. | (req->data->blocks << 16));
  657. set_data_timeout(host, req);
  658. host->datadir = (req->data->flags & MMC_DATA_WRITE) ?
  659. OMAP_MMC_DATADIR_WRITE : OMAP_MMC_DATADIR_READ;
  660. if (host->use_dma) {
  661. ret = mmc_omap_start_dma_transfer(host, req);
  662. if (ret != 0) {
  663. dev_dbg(mmc_dev(host->mmc), "MMC start dma failure\n");
  664. return ret;
  665. }
  666. }
  667. return 0;
  668. }
  669. /*
  670. * Request function. for read/write operation
  671. */
  672. static void omap_mmc_request(struct mmc_host *mmc, struct mmc_request *req)
  673. {
  674. struct mmc_omap_host *host = mmc_priv(mmc);
  675. WARN_ON(host->mrq != NULL);
  676. host->mrq = req;
  677. mmc_omap_prepare_data(host, req);
  678. mmc_omap_start_command(host, req->cmd, req->data);
  679. }
  680. /* Routine to configure clock values. Exposed API to core */
  681. static void omap_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  682. {
  683. struct mmc_omap_host *host = mmc_priv(mmc);
  684. u16 dsor = 0;
  685. unsigned long regval;
  686. unsigned long timeout;
  687. switch (ios->power_mode) {
  688. case MMC_POWER_OFF:
  689. mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0);
  690. break;
  691. case MMC_POWER_UP:
  692. mmc_slot(host).set_power(host->dev, host->slot_id, 1, ios->vdd);
  693. break;
  694. }
  695. switch (mmc->ios.bus_width) {
  696. case MMC_BUS_WIDTH_4:
  697. OMAP_HSMMC_WRITE(host->base, HCTL,
  698. OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT);
  699. break;
  700. case MMC_BUS_WIDTH_1:
  701. OMAP_HSMMC_WRITE(host->base, HCTL,
  702. OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT);
  703. break;
  704. }
  705. if (host->id == OMAP_MMC1_DEVID) {
  706. /* Only MMC1 can interface at 3V without some flavor
  707. * of external transceiver; but they all handle 1.8V.
  708. */
  709. if ((OMAP_HSMMC_READ(host->base, HCTL) & SDVSDET) &&
  710. (ios->vdd == DUAL_VOLT_OCR_BIT)) {
  711. /*
  712. * The mmc_select_voltage fn of the core does
  713. * not seem to set the power_mode to
  714. * MMC_POWER_UP upon recalculating the voltage.
  715. * vdd 1.8v.
  716. */
  717. if (omap_mmc_switch_opcond(host, ios->vdd) != 0)
  718. dev_dbg(mmc_dev(host->mmc),
  719. "Switch operation failed\n");
  720. }
  721. }
  722. if (ios->clock) {
  723. dsor = OMAP_MMC_MASTER_CLOCK / ios->clock;
  724. if (dsor < 1)
  725. dsor = 1;
  726. if (OMAP_MMC_MASTER_CLOCK / dsor > ios->clock)
  727. dsor++;
  728. if (dsor > 250)
  729. dsor = 250;
  730. }
  731. omap_mmc_stop_clock(host);
  732. regval = OMAP_HSMMC_READ(host->base, SYSCTL);
  733. regval = regval & ~(CLKD_MASK);
  734. regval = regval | (dsor << 6) | (DTO << 16);
  735. OMAP_HSMMC_WRITE(host->base, SYSCTL, regval);
  736. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  737. OMAP_HSMMC_READ(host->base, SYSCTL) | ICE);
  738. /* Wait till the ICS bit is set */
  739. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  740. while ((OMAP_HSMMC_READ(host->base, SYSCTL) & ICS) != 0x2
  741. && time_before(jiffies, timeout))
  742. msleep(1);
  743. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  744. OMAP_HSMMC_READ(host->base, SYSCTL) | CEN);
  745. if (ios->power_mode == MMC_POWER_ON)
  746. send_init_stream(host);
  747. if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
  748. OMAP_HSMMC_WRITE(host->base, CON,
  749. OMAP_HSMMC_READ(host->base, CON) | OD);
  750. }
  751. static int omap_hsmmc_get_cd(struct mmc_host *mmc)
  752. {
  753. struct mmc_omap_host *host = mmc_priv(mmc);
  754. struct omap_mmc_platform_data *pdata = host->pdata;
  755. if (!pdata->slots[0].card_detect)
  756. return -ENOSYS;
  757. return pdata->slots[0].card_detect(pdata->slots[0].card_detect_irq);
  758. }
  759. static int omap_hsmmc_get_ro(struct mmc_host *mmc)
  760. {
  761. struct mmc_omap_host *host = mmc_priv(mmc);
  762. struct omap_mmc_platform_data *pdata = host->pdata;
  763. if (!pdata->slots[0].get_ro)
  764. return -ENOSYS;
  765. return pdata->slots[0].get_ro(host->dev, 0);
  766. }
  767. static void omap_hsmmc_init(struct mmc_omap_host *host)
  768. {
  769. u32 hctl, capa, value;
  770. /* Only MMC1 supports 3.0V */
  771. if (host->id == OMAP_MMC1_DEVID) {
  772. hctl = SDVS30;
  773. capa = VS30 | VS18;
  774. } else {
  775. hctl = SDVS18;
  776. capa = VS18;
  777. }
  778. value = OMAP_HSMMC_READ(host->base, HCTL) & ~SDVS_MASK;
  779. OMAP_HSMMC_WRITE(host->base, HCTL, value | hctl);
  780. value = OMAP_HSMMC_READ(host->base, CAPA);
  781. OMAP_HSMMC_WRITE(host->base, CAPA, value | capa);
  782. /* Set the controller to AUTO IDLE mode */
  783. value = OMAP_HSMMC_READ(host->base, SYSCONFIG);
  784. OMAP_HSMMC_WRITE(host->base, SYSCONFIG, value | AUTOIDLE);
  785. /* Set SD bus power bit */
  786. value = OMAP_HSMMC_READ(host->base, HCTL);
  787. OMAP_HSMMC_WRITE(host->base, HCTL, value | SDBP);
  788. }
  789. static struct mmc_host_ops mmc_omap_ops = {
  790. .request = omap_mmc_request,
  791. .set_ios = omap_mmc_set_ios,
  792. .get_cd = omap_hsmmc_get_cd,
  793. .get_ro = omap_hsmmc_get_ro,
  794. /* NYET -- enable_sdio_irq */
  795. };
  796. static int __init omap_mmc_probe(struct platform_device *pdev)
  797. {
  798. struct omap_mmc_platform_data *pdata = pdev->dev.platform_data;
  799. struct mmc_host *mmc;
  800. struct mmc_omap_host *host = NULL;
  801. struct resource *res;
  802. int ret = 0, irq;
  803. if (pdata == NULL) {
  804. dev_err(&pdev->dev, "Platform Data is missing\n");
  805. return -ENXIO;
  806. }
  807. if (pdata->nr_slots == 0) {
  808. dev_err(&pdev->dev, "No Slots\n");
  809. return -ENXIO;
  810. }
  811. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  812. irq = platform_get_irq(pdev, 0);
  813. if (res == NULL || irq < 0)
  814. return -ENXIO;
  815. res = request_mem_region(res->start, res->end - res->start + 1,
  816. pdev->name);
  817. if (res == NULL)
  818. return -EBUSY;
  819. mmc = mmc_alloc_host(sizeof(struct mmc_omap_host), &pdev->dev);
  820. if (!mmc) {
  821. ret = -ENOMEM;
  822. goto err;
  823. }
  824. host = mmc_priv(mmc);
  825. host->mmc = mmc;
  826. host->pdata = pdata;
  827. host->dev = &pdev->dev;
  828. host->use_dma = 1;
  829. host->dev->dma_mask = &pdata->dma_mask;
  830. host->dma_ch = -1;
  831. host->irq = irq;
  832. host->id = pdev->id;
  833. host->slot_id = 0;
  834. host->mapbase = res->start;
  835. host->base = ioremap(host->mapbase, SZ_4K);
  836. platform_set_drvdata(pdev, host);
  837. INIT_WORK(&host->mmc_carddetect_work, mmc_omap_detect);
  838. mmc->ops = &mmc_omap_ops;
  839. mmc->f_min = 400000;
  840. mmc->f_max = 52000000;
  841. sema_init(&host->sem, 1);
  842. host->iclk = clk_get(&pdev->dev, "mmchs_ick");
  843. if (IS_ERR(host->iclk)) {
  844. ret = PTR_ERR(host->iclk);
  845. host->iclk = NULL;
  846. goto err1;
  847. }
  848. host->fclk = clk_get(&pdev->dev, "mmchs_fck");
  849. if (IS_ERR(host->fclk)) {
  850. ret = PTR_ERR(host->fclk);
  851. host->fclk = NULL;
  852. clk_put(host->iclk);
  853. goto err1;
  854. }
  855. if (clk_enable(host->fclk) != 0) {
  856. clk_put(host->iclk);
  857. clk_put(host->fclk);
  858. goto err1;
  859. }
  860. if (clk_enable(host->iclk) != 0) {
  861. clk_disable(host->fclk);
  862. clk_put(host->iclk);
  863. clk_put(host->fclk);
  864. goto err1;
  865. }
  866. host->dbclk = clk_get(&pdev->dev, "mmchsdb_fck");
  867. /*
  868. * MMC can still work without debounce clock.
  869. */
  870. if (IS_ERR(host->dbclk))
  871. dev_warn(mmc_dev(host->mmc), "Failed to get debounce clock\n");
  872. else
  873. if (clk_enable(host->dbclk) != 0)
  874. dev_dbg(mmc_dev(host->mmc), "Enabling debounce"
  875. " clk failed\n");
  876. else
  877. host->dbclk_enabled = 1;
  878. #ifdef CONFIG_MMC_BLOCK_BOUNCE
  879. mmc->max_phys_segs = 1;
  880. mmc->max_hw_segs = 1;
  881. #endif
  882. mmc->max_blk_size = 512; /* Block Length at max can be 1024 */
  883. mmc->max_blk_count = 0xFFFF; /* No. of Blocks is 16 bits */
  884. mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
  885. mmc->max_seg_size = mmc->max_req_size;
  886. mmc->ocr_avail = mmc_slot(host).ocr_mask;
  887. mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED;
  888. if (pdata->slots[host->slot_id].wires >= 4)
  889. mmc->caps |= MMC_CAP_4_BIT_DATA;
  890. omap_hsmmc_init(host);
  891. /* Request IRQ for MMC operations */
  892. ret = request_irq(host->irq, mmc_omap_irq, IRQF_DISABLED,
  893. mmc_hostname(mmc), host);
  894. if (ret) {
  895. dev_dbg(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n");
  896. goto err_irq;
  897. }
  898. if (pdata->init != NULL) {
  899. if (pdata->init(&pdev->dev) != 0) {
  900. dev_dbg(mmc_dev(host->mmc),
  901. "Unable to configure MMC IRQs\n");
  902. goto err_irq_cd_init;
  903. }
  904. }
  905. /* Request IRQ for card detect */
  906. if ((mmc_slot(host).card_detect_irq) && (mmc_slot(host).card_detect)) {
  907. ret = request_irq(mmc_slot(host).card_detect_irq,
  908. omap_mmc_cd_handler,
  909. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
  910. | IRQF_DISABLED,
  911. mmc_hostname(mmc), host);
  912. if (ret) {
  913. dev_dbg(mmc_dev(host->mmc),
  914. "Unable to grab MMC CD IRQ\n");
  915. goto err_irq_cd;
  916. }
  917. }
  918. OMAP_HSMMC_WRITE(host->base, ISE, INT_EN_MASK);
  919. OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
  920. mmc_add_host(mmc);
  921. if (host->pdata->slots[host->slot_id].name != NULL) {
  922. ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name);
  923. if (ret < 0)
  924. goto err_slot_name;
  925. }
  926. if (mmc_slot(host).card_detect_irq && mmc_slot(host).card_detect &&
  927. host->pdata->slots[host->slot_id].get_cover_state) {
  928. ret = device_create_file(&mmc->class_dev,
  929. &dev_attr_cover_switch);
  930. if (ret < 0)
  931. goto err_cover_switch;
  932. }
  933. return 0;
  934. err_cover_switch:
  935. device_remove_file(&mmc->class_dev, &dev_attr_cover_switch);
  936. err_slot_name:
  937. mmc_remove_host(mmc);
  938. err_irq_cd:
  939. free_irq(mmc_slot(host).card_detect_irq, host);
  940. err_irq_cd_init:
  941. free_irq(host->irq, host);
  942. err_irq:
  943. clk_disable(host->fclk);
  944. clk_disable(host->iclk);
  945. clk_put(host->fclk);
  946. clk_put(host->iclk);
  947. if (host->dbclk_enabled) {
  948. clk_disable(host->dbclk);
  949. clk_put(host->dbclk);
  950. }
  951. err1:
  952. iounmap(host->base);
  953. err:
  954. dev_dbg(mmc_dev(host->mmc), "Probe Failed\n");
  955. release_mem_region(res->start, res->end - res->start + 1);
  956. if (host)
  957. mmc_free_host(mmc);
  958. return ret;
  959. }
  960. static int omap_mmc_remove(struct platform_device *pdev)
  961. {
  962. struct mmc_omap_host *host = platform_get_drvdata(pdev);
  963. struct resource *res;
  964. if (host) {
  965. mmc_remove_host(host->mmc);
  966. if (host->pdata->cleanup)
  967. host->pdata->cleanup(&pdev->dev);
  968. free_irq(host->irq, host);
  969. if (mmc_slot(host).card_detect_irq)
  970. free_irq(mmc_slot(host).card_detect_irq, host);
  971. flush_scheduled_work();
  972. clk_disable(host->fclk);
  973. clk_disable(host->iclk);
  974. clk_put(host->fclk);
  975. clk_put(host->iclk);
  976. if (host->dbclk_enabled) {
  977. clk_disable(host->dbclk);
  978. clk_put(host->dbclk);
  979. }
  980. mmc_free_host(host->mmc);
  981. iounmap(host->base);
  982. }
  983. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  984. if (res)
  985. release_mem_region(res->start, res->end - res->start + 1);
  986. platform_set_drvdata(pdev, NULL);
  987. return 0;
  988. }
  989. #ifdef CONFIG_PM
  990. static int omap_mmc_suspend(struct platform_device *pdev, pm_message_t state)
  991. {
  992. int ret = 0;
  993. struct mmc_omap_host *host = platform_get_drvdata(pdev);
  994. if (host && host->suspended)
  995. return 0;
  996. if (host) {
  997. ret = mmc_suspend_host(host->mmc, state);
  998. if (ret == 0) {
  999. host->suspended = 1;
  1000. OMAP_HSMMC_WRITE(host->base, ISE, 0);
  1001. OMAP_HSMMC_WRITE(host->base, IE, 0);
  1002. if (host->pdata->suspend) {
  1003. ret = host->pdata->suspend(&pdev->dev,
  1004. host->slot_id);
  1005. if (ret)
  1006. dev_dbg(mmc_dev(host->mmc),
  1007. "Unable to handle MMC board"
  1008. " level suspend\n");
  1009. }
  1010. if (host->id == OMAP_MMC1_DEVID
  1011. && !(OMAP_HSMMC_READ(host->base, HCTL)
  1012. & SDVSDET)) {
  1013. OMAP_HSMMC_WRITE(host->base, HCTL,
  1014. OMAP_HSMMC_READ(host->base, HCTL)
  1015. & SDVSCLR);
  1016. OMAP_HSMMC_WRITE(host->base, HCTL,
  1017. OMAP_HSMMC_READ(host->base, HCTL)
  1018. | SDVS30);
  1019. OMAP_HSMMC_WRITE(host->base, HCTL,
  1020. OMAP_HSMMC_READ(host->base, HCTL)
  1021. | SDBP);
  1022. }
  1023. clk_disable(host->fclk);
  1024. clk_disable(host->iclk);
  1025. clk_disable(host->dbclk);
  1026. }
  1027. }
  1028. return ret;
  1029. }
  1030. /* Routine to resume the MMC device */
  1031. static int omap_mmc_resume(struct platform_device *pdev)
  1032. {
  1033. int ret = 0;
  1034. struct mmc_omap_host *host = platform_get_drvdata(pdev);
  1035. if (host && !host->suspended)
  1036. return 0;
  1037. if (host) {
  1038. ret = clk_enable(host->fclk);
  1039. if (ret)
  1040. goto clk_en_err;
  1041. ret = clk_enable(host->iclk);
  1042. if (ret) {
  1043. clk_disable(host->fclk);
  1044. clk_put(host->fclk);
  1045. goto clk_en_err;
  1046. }
  1047. if (clk_enable(host->dbclk) != 0)
  1048. dev_dbg(mmc_dev(host->mmc),
  1049. "Enabling debounce clk failed\n");
  1050. omap_hsmmc_init(host);
  1051. if (host->pdata->resume) {
  1052. ret = host->pdata->resume(&pdev->dev, host->slot_id);
  1053. if (ret)
  1054. dev_dbg(mmc_dev(host->mmc),
  1055. "Unmask interrupt failed\n");
  1056. }
  1057. /* Notify the core to resume the host */
  1058. ret = mmc_resume_host(host->mmc);
  1059. if (ret == 0)
  1060. host->suspended = 0;
  1061. }
  1062. return ret;
  1063. clk_en_err:
  1064. dev_dbg(mmc_dev(host->mmc),
  1065. "Failed to enable MMC clocks during resume\n");
  1066. return ret;
  1067. }
  1068. #else
  1069. #define omap_mmc_suspend NULL
  1070. #define omap_mmc_resume NULL
  1071. #endif
  1072. static struct platform_driver omap_mmc_driver = {
  1073. .probe = omap_mmc_probe,
  1074. .remove = omap_mmc_remove,
  1075. .suspend = omap_mmc_suspend,
  1076. .resume = omap_mmc_resume,
  1077. .driver = {
  1078. .name = DRIVER_NAME,
  1079. .owner = THIS_MODULE,
  1080. },
  1081. };
  1082. static int __init omap_mmc_init(void)
  1083. {
  1084. /* Register the MMC driver */
  1085. return platform_driver_register(&omap_mmc_driver);
  1086. }
  1087. static void __exit omap_mmc_cleanup(void)
  1088. {
  1089. /* Unregister MMC driver */
  1090. platform_driver_unregister(&omap_mmc_driver);
  1091. }
  1092. module_init(omap_mmc_init);
  1093. module_exit(omap_mmc_cleanup);
  1094. MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver");
  1095. MODULE_LICENSE("GPL");
  1096. MODULE_ALIAS("platform:" DRIVER_NAME);
  1097. MODULE_AUTHOR("Texas Instruments Inc");