omap_hsmmc.c 30 KB

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