omap_hsmmc.c 31 KB

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