omap_hsmmc.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  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. if (host->id != OMAP_MMC1_DEVID)
  432. return 0;
  433. /* Disable the clocks */
  434. clk_disable(host->fclk);
  435. clk_disable(host->iclk);
  436. clk_disable(host->dbclk);
  437. /* Turn the power off */
  438. ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0);
  439. if (ret != 0)
  440. goto err;
  441. /* Turn the power ON with given VDD 1.8 or 3.0v */
  442. ret = mmc_slot(host).set_power(host->dev, host->slot_id, 1, vdd);
  443. if (ret != 0)
  444. goto err;
  445. clk_enable(host->fclk);
  446. clk_enable(host->iclk);
  447. clk_enable(host->dbclk);
  448. OMAP_HSMMC_WRITE(host->base, HCTL,
  449. OMAP_HSMMC_READ(host->base, HCTL) & SDVSCLR);
  450. reg_val = OMAP_HSMMC_READ(host->base, HCTL);
  451. /*
  452. * If a MMC dual voltage card is detected, the set_ios fn calls
  453. * this fn with VDD bit set for 1.8V. Upon card removal from the
  454. * slot, omap_mmc_set_ios sets the VDD back to 3V on MMC_POWER_OFF.
  455. *
  456. * Cope with a bit of slop in the range ... per data sheets:
  457. * - "1.8V" for vdds_mmc1/vdds_mmc1a can be up to 2.45V max,
  458. * but recommended values are 1.71V to 1.89V
  459. * - "3.0V" for vdds_mmc1/vdds_mmc1a can be up to 3.5V max,
  460. * but recommended values are 2.7V to 3.3V
  461. *
  462. * Board setup code shouldn't permit anything very out-of-range.
  463. * TWL4030-family VMMC1 and VSIM regulators are fine (avoiding the
  464. * middle range) but VSIM can't power DAT4..DAT7 at more than 3V.
  465. */
  466. if ((1 << vdd) <= MMC_VDD_23_24)
  467. reg_val |= SDVS18;
  468. else
  469. reg_val |= SDVS30;
  470. OMAP_HSMMC_WRITE(host->base, HCTL, reg_val);
  471. OMAP_HSMMC_WRITE(host->base, HCTL,
  472. OMAP_HSMMC_READ(host->base, HCTL) | SDBP);
  473. return 0;
  474. err:
  475. dev_dbg(mmc_dev(host->mmc), "Unable to switch operating voltage\n");
  476. return ret;
  477. }
  478. /*
  479. * Work Item to notify the core about card insertion/removal
  480. */
  481. static void mmc_omap_detect(struct work_struct *work)
  482. {
  483. struct mmc_omap_host *host = container_of(work, struct mmc_omap_host,
  484. mmc_carddetect_work);
  485. struct omap_mmc_slot_data *slot = &mmc_slot(host);
  486. host->carddetect = slot->card_detect(slot->card_detect_irq);
  487. sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
  488. if (host->carddetect) {
  489. mmc_detect_change(host->mmc, (HZ * 200) / 1000);
  490. } else {
  491. mmc_omap_reset_controller_fsm(host, SRD);
  492. mmc_detect_change(host->mmc, (HZ * 50) / 1000);
  493. }
  494. }
  495. /*
  496. * ISR for handling card insertion and removal
  497. */
  498. static irqreturn_t omap_mmc_cd_handler(int irq, void *dev_id)
  499. {
  500. struct mmc_omap_host *host = (struct mmc_omap_host *)dev_id;
  501. schedule_work(&host->mmc_carddetect_work);
  502. return IRQ_HANDLED;
  503. }
  504. /*
  505. * DMA call back function
  506. */
  507. static void mmc_omap_dma_cb(int lch, u16 ch_status, void *data)
  508. {
  509. struct mmc_omap_host *host = data;
  510. if (ch_status & OMAP2_DMA_MISALIGNED_ERR_IRQ)
  511. dev_dbg(mmc_dev(host->mmc), "MISALIGNED_ADRS_ERR\n");
  512. if (host->dma_ch < 0)
  513. return;
  514. omap_free_dma(host->dma_ch);
  515. host->dma_ch = -1;
  516. /*
  517. * DMA Callback: run in interrupt context.
  518. * mutex_unlock will through a kernel warning if used.
  519. */
  520. up(&host->sem);
  521. }
  522. /*
  523. * Configure dma src and destination parameters
  524. */
  525. static int mmc_omap_config_dma_param(int sync_dir, struct mmc_omap_host *host,
  526. struct mmc_data *data)
  527. {
  528. if (sync_dir == 0) {
  529. omap_set_dma_dest_params(host->dma_ch, 0,
  530. OMAP_DMA_AMODE_CONSTANT,
  531. (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
  532. omap_set_dma_src_params(host->dma_ch, 0,
  533. OMAP_DMA_AMODE_POST_INC,
  534. sg_dma_address(&data->sg[0]), 0, 0);
  535. } else {
  536. omap_set_dma_src_params(host->dma_ch, 0,
  537. OMAP_DMA_AMODE_CONSTANT,
  538. (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
  539. omap_set_dma_dest_params(host->dma_ch, 0,
  540. OMAP_DMA_AMODE_POST_INC,
  541. sg_dma_address(&data->sg[0]), 0, 0);
  542. }
  543. return 0;
  544. }
  545. /*
  546. * Routine to configure and start DMA for the MMC card
  547. */
  548. static int
  549. mmc_omap_start_dma_transfer(struct mmc_omap_host *host, struct mmc_request *req)
  550. {
  551. int sync_dev, sync_dir = 0;
  552. int dma_ch = 0, ret = 0, err = 1;
  553. struct mmc_data *data = req->data;
  554. /*
  555. * If for some reason the DMA transfer is still active,
  556. * we wait for timeout period and free the dma
  557. */
  558. if (host->dma_ch != -1) {
  559. set_current_state(TASK_UNINTERRUPTIBLE);
  560. schedule_timeout(100);
  561. if (down_trylock(&host->sem)) {
  562. omap_free_dma(host->dma_ch);
  563. host->dma_ch = -1;
  564. up(&host->sem);
  565. return err;
  566. }
  567. } else {
  568. if (down_trylock(&host->sem))
  569. return err;
  570. }
  571. if (!(data->flags & MMC_DATA_WRITE)) {
  572. host->dma_dir = DMA_FROM_DEVICE;
  573. if (host->id == OMAP_MMC1_DEVID)
  574. sync_dev = OMAP24XX_DMA_MMC1_RX;
  575. else
  576. sync_dev = OMAP24XX_DMA_MMC2_RX;
  577. } else {
  578. host->dma_dir = DMA_TO_DEVICE;
  579. if (host->id == OMAP_MMC1_DEVID)
  580. sync_dev = OMAP24XX_DMA_MMC1_TX;
  581. else
  582. sync_dev = OMAP24XX_DMA_MMC2_TX;
  583. }
  584. ret = omap_request_dma(sync_dev, "MMC/SD", mmc_omap_dma_cb,
  585. host, &dma_ch);
  586. if (ret != 0) {
  587. dev_dbg(mmc_dev(host->mmc),
  588. "%s: omap_request_dma() failed with %d\n",
  589. mmc_hostname(host->mmc), ret);
  590. return ret;
  591. }
  592. host->dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg,
  593. data->sg_len, host->dma_dir);
  594. host->dma_ch = dma_ch;
  595. if (!(data->flags & MMC_DATA_WRITE))
  596. mmc_omap_config_dma_param(1, host, data);
  597. else
  598. mmc_omap_config_dma_param(0, host, data);
  599. if ((data->blksz % 4) == 0)
  600. omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S32,
  601. (data->blksz / 4), data->blocks, OMAP_DMA_SYNC_FRAME,
  602. sync_dev, sync_dir);
  603. else
  604. /* REVISIT: The MMC buffer increments only when MSB is written.
  605. * Return error for blksz which is non multiple of four.
  606. */
  607. return -EINVAL;
  608. omap_start_dma(dma_ch);
  609. return 0;
  610. }
  611. static void set_data_timeout(struct mmc_omap_host *host,
  612. struct mmc_request *req)
  613. {
  614. unsigned int timeout, cycle_ns;
  615. uint32_t reg, clkd, dto = 0;
  616. reg = OMAP_HSMMC_READ(host->base, SYSCTL);
  617. clkd = (reg & CLKD_MASK) >> CLKD_SHIFT;
  618. if (clkd == 0)
  619. clkd = 1;
  620. cycle_ns = 1000000000 / (clk_get_rate(host->fclk) / clkd);
  621. timeout = req->data->timeout_ns / cycle_ns;
  622. timeout += req->data->timeout_clks;
  623. if (timeout) {
  624. while ((timeout & 0x80000000) == 0) {
  625. dto += 1;
  626. timeout <<= 1;
  627. }
  628. dto = 31 - dto;
  629. timeout <<= 1;
  630. if (timeout && dto)
  631. dto += 1;
  632. if (dto >= 13)
  633. dto -= 13;
  634. else
  635. dto = 0;
  636. if (dto > 14)
  637. dto = 14;
  638. }
  639. reg &= ~DTO_MASK;
  640. reg |= dto << DTO_SHIFT;
  641. OMAP_HSMMC_WRITE(host->base, SYSCTL, reg);
  642. }
  643. /*
  644. * Configure block length for MMC/SD cards and initiate the transfer.
  645. */
  646. static int
  647. mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req)
  648. {
  649. int ret;
  650. host->data = req->data;
  651. if (req->data == NULL) {
  652. host->datadir = OMAP_MMC_DATADIR_NONE;
  653. OMAP_HSMMC_WRITE(host->base, BLK, 0);
  654. return 0;
  655. }
  656. OMAP_HSMMC_WRITE(host->base, BLK, (req->data->blksz)
  657. | (req->data->blocks << 16));
  658. set_data_timeout(host, req);
  659. host->datadir = (req->data->flags & MMC_DATA_WRITE) ?
  660. OMAP_MMC_DATADIR_WRITE : OMAP_MMC_DATADIR_READ;
  661. if (host->use_dma) {
  662. ret = mmc_omap_start_dma_transfer(host, req);
  663. if (ret != 0) {
  664. dev_dbg(mmc_dev(host->mmc), "MMC start dma failure\n");
  665. return ret;
  666. }
  667. }
  668. return 0;
  669. }
  670. /*
  671. * Request function. for read/write operation
  672. */
  673. static void omap_mmc_request(struct mmc_host *mmc, struct mmc_request *req)
  674. {
  675. struct mmc_omap_host *host = mmc_priv(mmc);
  676. WARN_ON(host->mrq != NULL);
  677. host->mrq = req;
  678. mmc_omap_prepare_data(host, req);
  679. mmc_omap_start_command(host, req->cmd, req->data);
  680. }
  681. /* Routine to configure clock values. Exposed API to core */
  682. static void omap_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  683. {
  684. struct mmc_omap_host *host = mmc_priv(mmc);
  685. u16 dsor = 0;
  686. unsigned long regval;
  687. unsigned long timeout;
  688. switch (ios->power_mode) {
  689. case MMC_POWER_OFF:
  690. mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0);
  691. /*
  692. * Reset interface voltage to 3V if it's 1.8V now;
  693. * only relevant on MMC-1, the others always use 1.8V.
  694. *
  695. * REVISIT: If we are able to detect cards after unplugging
  696. * a 1.8V card, this code should not be needed.
  697. */
  698. if (host->id != OMAP_MMC1_DEVID)
  699. break;
  700. if (!(OMAP_HSMMC_READ(host->base, HCTL) & SDVSDET)) {
  701. int vdd = fls(host->mmc->ocr_avail) - 1;
  702. if (omap_mmc_switch_opcond(host, vdd) != 0)
  703. host->mmc->ios.vdd = vdd;
  704. }
  705. break;
  706. case MMC_POWER_UP:
  707. mmc_slot(host).set_power(host->dev, host->slot_id, 1, ios->vdd);
  708. break;
  709. }
  710. switch (mmc->ios.bus_width) {
  711. case MMC_BUS_WIDTH_4:
  712. OMAP_HSMMC_WRITE(host->base, HCTL,
  713. OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT);
  714. break;
  715. case MMC_BUS_WIDTH_1:
  716. OMAP_HSMMC_WRITE(host->base, HCTL,
  717. OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT);
  718. break;
  719. }
  720. if (host->id == OMAP_MMC1_DEVID) {
  721. /* Only MMC1 can interface at 3V without some flavor
  722. * of external transceiver; but they all handle 1.8V.
  723. */
  724. if ((OMAP_HSMMC_READ(host->base, HCTL) & SDVSDET) &&
  725. (ios->vdd == DUAL_VOLT_OCR_BIT)) {
  726. /*
  727. * The mmc_select_voltage fn of the core does
  728. * not seem to set the power_mode to
  729. * MMC_POWER_UP upon recalculating the voltage.
  730. * vdd 1.8v.
  731. */
  732. if (omap_mmc_switch_opcond(host, ios->vdd) != 0)
  733. dev_dbg(mmc_dev(host->mmc),
  734. "Switch operation failed\n");
  735. }
  736. }
  737. if (ios->clock) {
  738. dsor = OMAP_MMC_MASTER_CLOCK / ios->clock;
  739. if (dsor < 1)
  740. dsor = 1;
  741. if (OMAP_MMC_MASTER_CLOCK / dsor > ios->clock)
  742. dsor++;
  743. if (dsor > 250)
  744. dsor = 250;
  745. }
  746. omap_mmc_stop_clock(host);
  747. regval = OMAP_HSMMC_READ(host->base, SYSCTL);
  748. regval = regval & ~(CLKD_MASK);
  749. regval = regval | (dsor << 6) | (DTO << 16);
  750. OMAP_HSMMC_WRITE(host->base, SYSCTL, regval);
  751. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  752. OMAP_HSMMC_READ(host->base, SYSCTL) | ICE);
  753. /* Wait till the ICS bit is set */
  754. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  755. while ((OMAP_HSMMC_READ(host->base, SYSCTL) & ICS) != 0x2
  756. && time_before(jiffies, timeout))
  757. msleep(1);
  758. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  759. OMAP_HSMMC_READ(host->base, SYSCTL) | CEN);
  760. if (ios->power_mode == MMC_POWER_ON)
  761. send_init_stream(host);
  762. if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
  763. OMAP_HSMMC_WRITE(host->base, CON,
  764. OMAP_HSMMC_READ(host->base, CON) | OD);
  765. }
  766. static int omap_hsmmc_get_cd(struct mmc_host *mmc)
  767. {
  768. struct mmc_omap_host *host = mmc_priv(mmc);
  769. struct omap_mmc_platform_data *pdata = host->pdata;
  770. if (!pdata->slots[0].card_detect)
  771. return -ENOSYS;
  772. return pdata->slots[0].card_detect(pdata->slots[0].card_detect_irq);
  773. }
  774. static int omap_hsmmc_get_ro(struct mmc_host *mmc)
  775. {
  776. struct mmc_omap_host *host = mmc_priv(mmc);
  777. struct omap_mmc_platform_data *pdata = host->pdata;
  778. if (!pdata->slots[0].get_ro)
  779. return -ENOSYS;
  780. return pdata->slots[0].get_ro(host->dev, 0);
  781. }
  782. static struct mmc_host_ops mmc_omap_ops = {
  783. .request = omap_mmc_request,
  784. .set_ios = omap_mmc_set_ios,
  785. .get_cd = omap_hsmmc_get_cd,
  786. .get_ro = omap_hsmmc_get_ro,
  787. /* NYET -- enable_sdio_irq */
  788. };
  789. static int __init omap_mmc_probe(struct platform_device *pdev)
  790. {
  791. struct omap_mmc_platform_data *pdata = pdev->dev.platform_data;
  792. struct mmc_host *mmc;
  793. struct mmc_omap_host *host = NULL;
  794. struct resource *res;
  795. int ret = 0, irq;
  796. u32 hctl, capa;
  797. if (pdata == NULL) {
  798. dev_err(&pdev->dev, "Platform Data is missing\n");
  799. return -ENXIO;
  800. }
  801. if (pdata->nr_slots == 0) {
  802. dev_err(&pdev->dev, "No Slots\n");
  803. return -ENXIO;
  804. }
  805. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  806. irq = platform_get_irq(pdev, 0);
  807. if (res == NULL || irq < 0)
  808. return -ENXIO;
  809. res = request_mem_region(res->start, res->end - res->start + 1,
  810. pdev->name);
  811. if (res == NULL)
  812. return -EBUSY;
  813. mmc = mmc_alloc_host(sizeof(struct mmc_omap_host), &pdev->dev);
  814. if (!mmc) {
  815. ret = -ENOMEM;
  816. goto err;
  817. }
  818. host = mmc_priv(mmc);
  819. host->mmc = mmc;
  820. host->pdata = pdata;
  821. host->dev = &pdev->dev;
  822. host->use_dma = 1;
  823. host->dev->dma_mask = &pdata->dma_mask;
  824. host->dma_ch = -1;
  825. host->irq = irq;
  826. host->id = pdev->id;
  827. host->slot_id = 0;
  828. host->mapbase = res->start;
  829. host->base = ioremap(host->mapbase, SZ_4K);
  830. platform_set_drvdata(pdev, host);
  831. INIT_WORK(&host->mmc_carddetect_work, mmc_omap_detect);
  832. mmc->ops = &mmc_omap_ops;
  833. mmc->f_min = 400000;
  834. mmc->f_max = 52000000;
  835. sema_init(&host->sem, 1);
  836. host->iclk = clk_get(&pdev->dev, "mmchs_ick");
  837. if (IS_ERR(host->iclk)) {
  838. ret = PTR_ERR(host->iclk);
  839. host->iclk = NULL;
  840. goto err1;
  841. }
  842. host->fclk = clk_get(&pdev->dev, "mmchs_fck");
  843. if (IS_ERR(host->fclk)) {
  844. ret = PTR_ERR(host->fclk);
  845. host->fclk = NULL;
  846. clk_put(host->iclk);
  847. goto err1;
  848. }
  849. if (clk_enable(host->fclk) != 0) {
  850. clk_put(host->iclk);
  851. clk_put(host->fclk);
  852. goto err1;
  853. }
  854. if (clk_enable(host->iclk) != 0) {
  855. clk_disable(host->fclk);
  856. clk_put(host->iclk);
  857. clk_put(host->fclk);
  858. goto err1;
  859. }
  860. host->dbclk = clk_get(&pdev->dev, "mmchsdb_fck");
  861. /*
  862. * MMC can still work without debounce clock.
  863. */
  864. if (IS_ERR(host->dbclk))
  865. dev_warn(mmc_dev(host->mmc), "Failed to get debounce clock\n");
  866. else
  867. if (clk_enable(host->dbclk) != 0)
  868. dev_dbg(mmc_dev(host->mmc), "Enabling debounce"
  869. " clk failed\n");
  870. else
  871. host->dbclk_enabled = 1;
  872. #ifdef CONFIG_MMC_BLOCK_BOUNCE
  873. mmc->max_phys_segs = 1;
  874. mmc->max_hw_segs = 1;
  875. #endif
  876. mmc->max_blk_size = 512; /* Block Length at max can be 1024 */
  877. mmc->max_blk_count = 0xFFFF; /* No. of Blocks is 16 bits */
  878. mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
  879. mmc->max_seg_size = mmc->max_req_size;
  880. mmc->ocr_avail = mmc_slot(host).ocr_mask;
  881. mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED;
  882. if (pdata->slots[host->slot_id].wires >= 4)
  883. mmc->caps |= MMC_CAP_4_BIT_DATA;
  884. /* Only MMC1 supports 3.0V */
  885. if (host->id == OMAP_MMC1_DEVID) {
  886. hctl = SDVS30;
  887. capa = VS30 | VS18;
  888. } else {
  889. hctl = SDVS18;
  890. capa = VS18;
  891. }
  892. OMAP_HSMMC_WRITE(host->base, HCTL,
  893. OMAP_HSMMC_READ(host->base, HCTL) | hctl);
  894. OMAP_HSMMC_WRITE(host->base, CAPA,
  895. OMAP_HSMMC_READ(host->base, CAPA) | capa);
  896. /* Set the controller to AUTO IDLE mode */
  897. OMAP_HSMMC_WRITE(host->base, SYSCONFIG,
  898. OMAP_HSMMC_READ(host->base, SYSCONFIG) | AUTOIDLE);
  899. /* Set SD bus power bit */
  900. OMAP_HSMMC_WRITE(host->base, HCTL,
  901. OMAP_HSMMC_READ(host->base, HCTL) | SDBP);
  902. /* Request IRQ for MMC operations */
  903. ret = request_irq(host->irq, mmc_omap_irq, IRQF_DISABLED,
  904. mmc_hostname(mmc), host);
  905. if (ret) {
  906. dev_dbg(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n");
  907. goto err_irq;
  908. }
  909. if (pdata->init != NULL) {
  910. if (pdata->init(&pdev->dev) != 0) {
  911. dev_dbg(mmc_dev(host->mmc),
  912. "Unable to configure MMC IRQs\n");
  913. goto err_irq_cd_init;
  914. }
  915. }
  916. /* Request IRQ for card detect */
  917. if ((mmc_slot(host).card_detect_irq) && (mmc_slot(host).card_detect)) {
  918. ret = request_irq(mmc_slot(host).card_detect_irq,
  919. omap_mmc_cd_handler,
  920. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
  921. | IRQF_DISABLED,
  922. mmc_hostname(mmc), host);
  923. if (ret) {
  924. dev_dbg(mmc_dev(host->mmc),
  925. "Unable to grab MMC CD IRQ\n");
  926. goto err_irq_cd;
  927. }
  928. }
  929. OMAP_HSMMC_WRITE(host->base, ISE, INT_EN_MASK);
  930. OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
  931. mmc_add_host(mmc);
  932. if (host->pdata->slots[host->slot_id].name != NULL) {
  933. ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name);
  934. if (ret < 0)
  935. goto err_slot_name;
  936. }
  937. if (mmc_slot(host).card_detect_irq && mmc_slot(host).card_detect &&
  938. host->pdata->slots[host->slot_id].get_cover_state) {
  939. ret = device_create_file(&mmc->class_dev,
  940. &dev_attr_cover_switch);
  941. if (ret < 0)
  942. goto err_cover_switch;
  943. }
  944. return 0;
  945. err_cover_switch:
  946. device_remove_file(&mmc->class_dev, &dev_attr_cover_switch);
  947. err_slot_name:
  948. mmc_remove_host(mmc);
  949. err_irq_cd:
  950. free_irq(mmc_slot(host).card_detect_irq, host);
  951. err_irq_cd_init:
  952. free_irq(host->irq, host);
  953. err_irq:
  954. clk_disable(host->fclk);
  955. clk_disable(host->iclk);
  956. clk_put(host->fclk);
  957. clk_put(host->iclk);
  958. if (host->dbclk_enabled) {
  959. clk_disable(host->dbclk);
  960. clk_put(host->dbclk);
  961. }
  962. err1:
  963. iounmap(host->base);
  964. err:
  965. dev_dbg(mmc_dev(host->mmc), "Probe Failed\n");
  966. release_mem_region(res->start, res->end - res->start + 1);
  967. if (host)
  968. mmc_free_host(mmc);
  969. return ret;
  970. }
  971. static int omap_mmc_remove(struct platform_device *pdev)
  972. {
  973. struct mmc_omap_host *host = platform_get_drvdata(pdev);
  974. struct resource *res;
  975. if (host) {
  976. mmc_remove_host(host->mmc);
  977. if (host->pdata->cleanup)
  978. host->pdata->cleanup(&pdev->dev);
  979. free_irq(host->irq, host);
  980. if (mmc_slot(host).card_detect_irq)
  981. free_irq(mmc_slot(host).card_detect_irq, host);
  982. flush_scheduled_work();
  983. clk_disable(host->fclk);
  984. clk_disable(host->iclk);
  985. clk_put(host->fclk);
  986. clk_put(host->iclk);
  987. if (host->dbclk_enabled) {
  988. clk_disable(host->dbclk);
  989. clk_put(host->dbclk);
  990. }
  991. mmc_free_host(host->mmc);
  992. iounmap(host->base);
  993. }
  994. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  995. if (res)
  996. release_mem_region(res->start, res->end - res->start + 1);
  997. platform_set_drvdata(pdev, NULL);
  998. return 0;
  999. }
  1000. #ifdef CONFIG_PM
  1001. static int omap_mmc_suspend(struct platform_device *pdev, pm_message_t state)
  1002. {
  1003. int ret = 0;
  1004. struct mmc_omap_host *host = platform_get_drvdata(pdev);
  1005. if (host && host->suspended)
  1006. return 0;
  1007. if (host) {
  1008. ret = mmc_suspend_host(host->mmc, state);
  1009. if (ret == 0) {
  1010. host->suspended = 1;
  1011. OMAP_HSMMC_WRITE(host->base, ISE, 0);
  1012. OMAP_HSMMC_WRITE(host->base, IE, 0);
  1013. if (host->pdata->suspend) {
  1014. ret = host->pdata->suspend(&pdev->dev,
  1015. host->slot_id);
  1016. if (ret)
  1017. dev_dbg(mmc_dev(host->mmc),
  1018. "Unable to handle MMC board"
  1019. " level suspend\n");
  1020. }
  1021. if (host->id == OMAP_MMC1_DEVID
  1022. && !(OMAP_HSMMC_READ(host->base, HCTL)
  1023. & SDVSDET)) {
  1024. OMAP_HSMMC_WRITE(host->base, HCTL,
  1025. OMAP_HSMMC_READ(host->base, HCTL)
  1026. & SDVSCLR);
  1027. OMAP_HSMMC_WRITE(host->base, HCTL,
  1028. OMAP_HSMMC_READ(host->base, HCTL)
  1029. | SDVS30);
  1030. OMAP_HSMMC_WRITE(host->base, HCTL,
  1031. OMAP_HSMMC_READ(host->base, HCTL)
  1032. | SDBP);
  1033. }
  1034. clk_disable(host->fclk);
  1035. clk_disable(host->iclk);
  1036. clk_disable(host->dbclk);
  1037. }
  1038. }
  1039. return ret;
  1040. }
  1041. /* Routine to resume the MMC device */
  1042. static int omap_mmc_resume(struct platform_device *pdev)
  1043. {
  1044. int ret = 0;
  1045. struct mmc_omap_host *host = platform_get_drvdata(pdev);
  1046. if (host && !host->suspended)
  1047. return 0;
  1048. if (host) {
  1049. ret = clk_enable(host->fclk);
  1050. if (ret)
  1051. goto clk_en_err;
  1052. ret = clk_enable(host->iclk);
  1053. if (ret) {
  1054. clk_disable(host->fclk);
  1055. clk_put(host->fclk);
  1056. goto clk_en_err;
  1057. }
  1058. if (clk_enable(host->dbclk) != 0)
  1059. dev_dbg(mmc_dev(host->mmc),
  1060. "Enabling debounce clk failed\n");
  1061. if (host->pdata->resume) {
  1062. ret = host->pdata->resume(&pdev->dev, host->slot_id);
  1063. if (ret)
  1064. dev_dbg(mmc_dev(host->mmc),
  1065. "Unmask interrupt failed\n");
  1066. }
  1067. /* Notify the core to resume the host */
  1068. ret = mmc_resume_host(host->mmc);
  1069. if (ret == 0)
  1070. host->suspended = 0;
  1071. }
  1072. return ret;
  1073. clk_en_err:
  1074. dev_dbg(mmc_dev(host->mmc),
  1075. "Failed to enable MMC clocks during resume\n");
  1076. return ret;
  1077. }
  1078. #else
  1079. #define omap_mmc_suspend NULL
  1080. #define omap_mmc_resume NULL
  1081. #endif
  1082. static struct platform_driver omap_mmc_driver = {
  1083. .probe = omap_mmc_probe,
  1084. .remove = omap_mmc_remove,
  1085. .suspend = omap_mmc_suspend,
  1086. .resume = omap_mmc_resume,
  1087. .driver = {
  1088. .name = DRIVER_NAME,
  1089. .owner = THIS_MODULE,
  1090. },
  1091. };
  1092. static int __init omap_mmc_init(void)
  1093. {
  1094. /* Register the MMC driver */
  1095. return platform_driver_register(&omap_mmc_driver);
  1096. }
  1097. static void __exit omap_mmc_cleanup(void)
  1098. {
  1099. /* Unregister MMC driver */
  1100. platform_driver_unregister(&omap_mmc_driver);
  1101. }
  1102. module_init(omap_mmc_init);
  1103. module_exit(omap_mmc_cleanup);
  1104. MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver");
  1105. MODULE_LICENSE("GPL");
  1106. MODULE_ALIAS("platform:" DRIVER_NAME);
  1107. MODULE_AUTHOR("Texas Instruments Inc");