omap_hsmmc.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399
  1. /*
  2. * drivers/mmc/host/omap_hsmmc.c
  3. *
  4. * Driver for OMAP2430/3430 MMC controller.
  5. *
  6. * Copyright (C) 2007 Texas Instruments.
  7. *
  8. * Authors:
  9. * Syed Mohammed Khasim <x0khasim@ti.com>
  10. * Madhusudhan <madhu.cr@ti.com>
  11. * Mohit Jalori <mjalori@ti.com>
  12. *
  13. * This file is licensed under the terms of the GNU General Public License
  14. * version 2. This program is licensed "as is" without any warranty of any
  15. * kind, whether express or implied.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/debugfs.h>
  20. #include <linux/seq_file.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/delay.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/workqueue.h>
  26. #include <linux/timer.h>
  27. #include <linux/clk.h>
  28. #include <linux/mmc/host.h>
  29. #include <linux/mmc/core.h>
  30. #include <linux/io.h>
  31. #include <linux/semaphore.h>
  32. #include <linux/gpio.h>
  33. #include <linux/regulator/consumer.h>
  34. #include <plat/dma.h>
  35. #include <mach/hardware.h>
  36. #include <plat/board.h>
  37. #include <plat/mmc.h>
  38. #include <plat/cpu.h>
  39. /* OMAP HSMMC Host Controller Registers */
  40. #define OMAP_HSMMC_SYSCONFIG 0x0010
  41. #define OMAP_HSMMC_SYSSTATUS 0x0014
  42. #define OMAP_HSMMC_CON 0x002C
  43. #define OMAP_HSMMC_BLK 0x0104
  44. #define OMAP_HSMMC_ARG 0x0108
  45. #define OMAP_HSMMC_CMD 0x010C
  46. #define OMAP_HSMMC_RSP10 0x0110
  47. #define OMAP_HSMMC_RSP32 0x0114
  48. #define OMAP_HSMMC_RSP54 0x0118
  49. #define OMAP_HSMMC_RSP76 0x011C
  50. #define OMAP_HSMMC_DATA 0x0120
  51. #define OMAP_HSMMC_HCTL 0x0128
  52. #define OMAP_HSMMC_SYSCTL 0x012C
  53. #define OMAP_HSMMC_STAT 0x0130
  54. #define OMAP_HSMMC_IE 0x0134
  55. #define OMAP_HSMMC_ISE 0x0138
  56. #define OMAP_HSMMC_CAPA 0x0140
  57. #define VS18 (1 << 26)
  58. #define VS30 (1 << 25)
  59. #define SDVS18 (0x5 << 9)
  60. #define SDVS30 (0x6 << 9)
  61. #define SDVS33 (0x7 << 9)
  62. #define SDVS_MASK 0x00000E00
  63. #define SDVSCLR 0xFFFFF1FF
  64. #define SDVSDET 0x00000400
  65. #define AUTOIDLE 0x1
  66. #define SDBP (1 << 8)
  67. #define DTO 0xe
  68. #define ICE 0x1
  69. #define ICS 0x2
  70. #define CEN (1 << 2)
  71. #define CLKD_MASK 0x0000FFC0
  72. #define CLKD_SHIFT 6
  73. #define DTO_MASK 0x000F0000
  74. #define DTO_SHIFT 16
  75. #define INT_EN_MASK 0x307F0033
  76. #define BWR_ENABLE (1 << 4)
  77. #define BRR_ENABLE (1 << 5)
  78. #define INIT_STREAM (1 << 1)
  79. #define DP_SELECT (1 << 21)
  80. #define DDIR (1 << 4)
  81. #define DMA_EN 0x1
  82. #define MSBS (1 << 5)
  83. #define BCE (1 << 1)
  84. #define FOUR_BIT (1 << 1)
  85. #define DW8 (1 << 5)
  86. #define CC 0x1
  87. #define TC 0x02
  88. #define OD 0x1
  89. #define ERR (1 << 15)
  90. #define CMD_TIMEOUT (1 << 16)
  91. #define DATA_TIMEOUT (1 << 20)
  92. #define CMD_CRC (1 << 17)
  93. #define DATA_CRC (1 << 21)
  94. #define CARD_ERR (1 << 28)
  95. #define STAT_CLEAR 0xFFFFFFFF
  96. #define INIT_STREAM_CMD 0x00000000
  97. #define DUAL_VOLT_OCR_BIT 7
  98. #define SRC (1 << 25)
  99. #define SRD (1 << 26)
  100. #define SOFTRESET (1 << 1)
  101. #define RESETDONE (1 << 0)
  102. /*
  103. * FIXME: Most likely all the data using these _DEVID defines should come
  104. * from the platform_data, or implemented in controller and slot specific
  105. * functions.
  106. */
  107. #define OMAP_MMC1_DEVID 0
  108. #define OMAP_MMC2_DEVID 1
  109. #define OMAP_MMC3_DEVID 2
  110. #define OMAP_MMC4_DEVID 3
  111. #define OMAP_MMC5_DEVID 4
  112. #define MMC_TIMEOUT_MS 20
  113. #define OMAP_MMC_MASTER_CLOCK 96000000
  114. #define DRIVER_NAME "mmci-omap-hs"
  115. /* Timeouts for entering power saving states on inactivity, msec */
  116. #define OMAP_MMC_DISABLED_TIMEOUT 100
  117. #define OMAP_MMC_SLEEP_TIMEOUT 1000
  118. #define OMAP_MMC_OFF_TIMEOUT 8000
  119. /*
  120. * One controller can have multiple slots, like on some omap boards using
  121. * omap.c controller driver. Luckily this is not currently done on any known
  122. * omap_hsmmc.c device.
  123. */
  124. #define mmc_slot(host) (host->pdata->slots[host->slot_id])
  125. /*
  126. * MMC Host controller read/write API's
  127. */
  128. #define OMAP_HSMMC_READ(base, reg) \
  129. __raw_readl((base) + OMAP_HSMMC_##reg)
  130. #define OMAP_HSMMC_WRITE(base, reg, val) \
  131. __raw_writel((val), (base) + OMAP_HSMMC_##reg)
  132. struct omap_hsmmc_host {
  133. struct device *dev;
  134. struct mmc_host *mmc;
  135. struct mmc_request *mrq;
  136. struct mmc_command *cmd;
  137. struct mmc_data *data;
  138. struct clk *fclk;
  139. struct clk *iclk;
  140. struct clk *dbclk;
  141. /*
  142. * vcc == configured supply
  143. * vcc_aux == optional
  144. * - MMC1, supply for DAT4..DAT7
  145. * - MMC2/MMC2, external level shifter voltage supply, for
  146. * chip (SDIO, eMMC, etc) or transceiver (MMC2 only)
  147. */
  148. struct regulator *vcc;
  149. struct regulator *vcc_aux;
  150. struct semaphore sem;
  151. struct work_struct mmc_carddetect_work;
  152. void __iomem *base;
  153. resource_size_t mapbase;
  154. spinlock_t irq_lock; /* Prevent races with irq handler */
  155. unsigned long flags;
  156. unsigned int id;
  157. unsigned int dma_len;
  158. unsigned int dma_sg_idx;
  159. unsigned char bus_mode;
  160. unsigned char power_mode;
  161. u32 *buffer;
  162. u32 bytesleft;
  163. int suspended;
  164. int irq;
  165. int use_dma, dma_ch;
  166. int dma_line_tx, dma_line_rx;
  167. int slot_id;
  168. int got_dbclk;
  169. int response_busy;
  170. int context_loss;
  171. int dpm_state;
  172. int vdd;
  173. int protect_card;
  174. int reqs_blocked;
  175. int use_reg;
  176. struct omap_mmc_platform_data *pdata;
  177. };
  178. static int omap_hsmmc_card_detect(struct device *dev, int slot)
  179. {
  180. struct omap_mmc_platform_data *mmc = dev->platform_data;
  181. /* NOTE: assumes card detect signal is active-low */
  182. return !gpio_get_value_cansleep(mmc->slots[0].switch_pin);
  183. }
  184. static int omap_hsmmc_get_wp(struct device *dev, int slot)
  185. {
  186. struct omap_mmc_platform_data *mmc = dev->platform_data;
  187. /* NOTE: assumes write protect signal is active-high */
  188. return gpio_get_value_cansleep(mmc->slots[0].gpio_wp);
  189. }
  190. static int omap_hsmmc_get_cover_state(struct device *dev, int slot)
  191. {
  192. struct omap_mmc_platform_data *mmc = dev->platform_data;
  193. /* NOTE: assumes card detect signal is active-low */
  194. return !gpio_get_value_cansleep(mmc->slots[0].switch_pin);
  195. }
  196. #ifdef CONFIG_PM
  197. static int omap_hsmmc_suspend_cdirq(struct device *dev, int slot)
  198. {
  199. struct omap_mmc_platform_data *mmc = dev->platform_data;
  200. disable_irq(mmc->slots[0].card_detect_irq);
  201. return 0;
  202. }
  203. static int omap_hsmmc_resume_cdirq(struct device *dev, int slot)
  204. {
  205. struct omap_mmc_platform_data *mmc = dev->platform_data;
  206. enable_irq(mmc->slots[0].card_detect_irq);
  207. return 0;
  208. }
  209. #else
  210. #define omap_hsmmc_suspend_cdirq NULL
  211. #define omap_hsmmc_resume_cdirq NULL
  212. #endif
  213. #ifdef CONFIG_REGULATOR
  214. static int omap_hsmmc_1_set_power(struct device *dev, int slot, int power_on,
  215. int vdd)
  216. {
  217. struct omap_hsmmc_host *host =
  218. platform_get_drvdata(to_platform_device(dev));
  219. int ret;
  220. if (mmc_slot(host).before_set_reg)
  221. mmc_slot(host).before_set_reg(dev, slot, power_on, vdd);
  222. if (power_on)
  223. ret = mmc_regulator_set_ocr(host->vcc, vdd);
  224. else
  225. ret = mmc_regulator_set_ocr(host->vcc, 0);
  226. if (mmc_slot(host).after_set_reg)
  227. mmc_slot(host).after_set_reg(dev, slot, power_on, vdd);
  228. return ret;
  229. }
  230. static int omap_hsmmc_23_set_power(struct device *dev, int slot, int power_on,
  231. int vdd)
  232. {
  233. struct omap_hsmmc_host *host =
  234. platform_get_drvdata(to_platform_device(dev));
  235. int ret = 0;
  236. /*
  237. * If we don't see a Vcc regulator, assume it's a fixed
  238. * voltage always-on regulator.
  239. */
  240. if (!host->vcc)
  241. return 0;
  242. if (mmc_slot(host).before_set_reg)
  243. mmc_slot(host).before_set_reg(dev, slot, power_on, vdd);
  244. /*
  245. * Assume Vcc regulator is used only to power the card ... OMAP
  246. * VDDS is used to power the pins, optionally with a transceiver to
  247. * support cards using voltages other than VDDS (1.8V nominal). When a
  248. * transceiver is used, DAT3..7 are muxed as transceiver control pins.
  249. *
  250. * In some cases this regulator won't support enable/disable;
  251. * e.g. it's a fixed rail for a WLAN chip.
  252. *
  253. * In other cases vcc_aux switches interface power. Example, for
  254. * eMMC cards it represents VccQ. Sometimes transceivers or SDIO
  255. * chips/cards need an interface voltage rail too.
  256. */
  257. if (power_on) {
  258. ret = mmc_regulator_set_ocr(host->vcc, vdd);
  259. /* Enable interface voltage rail, if needed */
  260. if (ret == 0 && host->vcc_aux) {
  261. ret = regulator_enable(host->vcc_aux);
  262. if (ret < 0)
  263. ret = mmc_regulator_set_ocr(host->vcc, 0);
  264. }
  265. } else {
  266. if (host->vcc_aux)
  267. ret = regulator_disable(host->vcc_aux);
  268. if (ret == 0)
  269. ret = mmc_regulator_set_ocr(host->vcc, 0);
  270. }
  271. if (mmc_slot(host).after_set_reg)
  272. mmc_slot(host).after_set_reg(dev, slot, power_on, vdd);
  273. return ret;
  274. }
  275. static int omap_hsmmc_1_set_sleep(struct device *dev, int slot, int sleep,
  276. int vdd, int cardsleep)
  277. {
  278. struct omap_hsmmc_host *host =
  279. platform_get_drvdata(to_platform_device(dev));
  280. int mode = sleep ? REGULATOR_MODE_STANDBY : REGULATOR_MODE_NORMAL;
  281. return regulator_set_mode(host->vcc, mode);
  282. }
  283. static int omap_hsmmc_23_set_sleep(struct device *dev, int slot, int sleep,
  284. int vdd, int cardsleep)
  285. {
  286. struct omap_hsmmc_host *host =
  287. platform_get_drvdata(to_platform_device(dev));
  288. int err, mode;
  289. /*
  290. * If we don't see a Vcc regulator, assume it's a fixed
  291. * voltage always-on regulator.
  292. */
  293. if (!host->vcc)
  294. return 0;
  295. mode = sleep ? REGULATOR_MODE_STANDBY : REGULATOR_MODE_NORMAL;
  296. if (!host->vcc_aux)
  297. return regulator_set_mode(host->vcc, mode);
  298. if (cardsleep) {
  299. /* VCC can be turned off if card is asleep */
  300. if (sleep)
  301. err = mmc_regulator_set_ocr(host->vcc, 0);
  302. else
  303. err = mmc_regulator_set_ocr(host->vcc, vdd);
  304. } else
  305. err = regulator_set_mode(host->vcc, mode);
  306. if (err)
  307. return err;
  308. if (!mmc_slot(host).vcc_aux_disable_is_sleep)
  309. return regulator_set_mode(host->vcc_aux, mode);
  310. if (sleep)
  311. return regulator_disable(host->vcc_aux);
  312. else
  313. return regulator_enable(host->vcc_aux);
  314. }
  315. static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
  316. {
  317. struct regulator *reg;
  318. int ret = 0;
  319. switch (host->id) {
  320. case OMAP_MMC1_DEVID:
  321. /* On-chip level shifting via PBIAS0/PBIAS1 */
  322. mmc_slot(host).set_power = omap_hsmmc_1_set_power;
  323. mmc_slot(host).set_sleep = omap_hsmmc_1_set_sleep;
  324. break;
  325. case OMAP_MMC2_DEVID:
  326. case OMAP_MMC3_DEVID:
  327. /* Off-chip level shifting, or none */
  328. mmc_slot(host).set_power = omap_hsmmc_23_set_power;
  329. mmc_slot(host).set_sleep = omap_hsmmc_23_set_sleep;
  330. break;
  331. default:
  332. pr_err("MMC%d configuration not supported!\n", host->id);
  333. return -EINVAL;
  334. }
  335. reg = regulator_get(host->dev, "vmmc");
  336. if (IS_ERR(reg)) {
  337. dev_dbg(host->dev, "vmmc regulator missing\n");
  338. /*
  339. * HACK: until fixed.c regulator is usable,
  340. * we don't require a main regulator
  341. * for MMC2 or MMC3
  342. */
  343. if (host->id == OMAP_MMC1_DEVID) {
  344. ret = PTR_ERR(reg);
  345. goto err;
  346. }
  347. } else {
  348. host->vcc = reg;
  349. mmc_slot(host).ocr_mask = mmc_regulator_get_ocrmask(reg);
  350. /* Allow an aux regulator */
  351. reg = regulator_get(host->dev, "vmmc_aux");
  352. host->vcc_aux = IS_ERR(reg) ? NULL : reg;
  353. /*
  354. * UGLY HACK: workaround regulator framework bugs.
  355. * When the bootloader leaves a supply active, it's
  356. * initialized with zero usecount ... and we can't
  357. * disable it without first enabling it. Until the
  358. * framework is fixed, we need a workaround like this
  359. * (which is safe for MMC, but not in general).
  360. */
  361. if (regulator_is_enabled(host->vcc) > 0) {
  362. regulator_enable(host->vcc);
  363. regulator_disable(host->vcc);
  364. }
  365. if (host->vcc_aux) {
  366. if (regulator_is_enabled(reg) > 0) {
  367. regulator_enable(reg);
  368. regulator_disable(reg);
  369. }
  370. }
  371. }
  372. return 0;
  373. err:
  374. mmc_slot(host).set_power = NULL;
  375. mmc_slot(host).set_sleep = NULL;
  376. return ret;
  377. }
  378. static void omap_hsmmc_reg_put(struct omap_hsmmc_host *host)
  379. {
  380. regulator_put(host->vcc);
  381. regulator_put(host->vcc_aux);
  382. mmc_slot(host).set_power = NULL;
  383. mmc_slot(host).set_sleep = NULL;
  384. }
  385. static inline int omap_hsmmc_have_reg(void)
  386. {
  387. return 1;
  388. }
  389. #else
  390. static inline int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
  391. {
  392. return -EINVAL;
  393. }
  394. static inline void omap_hsmmc_reg_put(struct omap_hsmmc_host *host)
  395. {
  396. }
  397. static inline int omap_hsmmc_have_reg(void)
  398. {
  399. return 0;
  400. }
  401. #endif
  402. static int omap_hsmmc_gpio_init(struct omap_mmc_platform_data *pdata)
  403. {
  404. int ret;
  405. if (gpio_is_valid(pdata->slots[0].switch_pin)) {
  406. pdata->suspend = omap_hsmmc_suspend_cdirq;
  407. pdata->resume = omap_hsmmc_resume_cdirq;
  408. if (pdata->slots[0].cover)
  409. pdata->slots[0].get_cover_state =
  410. omap_hsmmc_get_cover_state;
  411. else
  412. pdata->slots[0].card_detect = omap_hsmmc_card_detect;
  413. pdata->slots[0].card_detect_irq =
  414. gpio_to_irq(pdata->slots[0].switch_pin);
  415. ret = gpio_request(pdata->slots[0].switch_pin, "mmc_cd");
  416. if (ret)
  417. return ret;
  418. ret = gpio_direction_input(pdata->slots[0].switch_pin);
  419. if (ret)
  420. goto err_free_sp;
  421. } else
  422. pdata->slots[0].switch_pin = -EINVAL;
  423. if (gpio_is_valid(pdata->slots[0].gpio_wp)) {
  424. pdata->slots[0].get_ro = omap_hsmmc_get_wp;
  425. ret = gpio_request(pdata->slots[0].gpio_wp, "mmc_wp");
  426. if (ret)
  427. goto err_free_cd;
  428. ret = gpio_direction_input(pdata->slots[0].gpio_wp);
  429. if (ret)
  430. goto err_free_wp;
  431. } else
  432. pdata->slots[0].gpio_wp = -EINVAL;
  433. return 0;
  434. err_free_wp:
  435. gpio_free(pdata->slots[0].gpio_wp);
  436. err_free_cd:
  437. if (gpio_is_valid(pdata->slots[0].switch_pin))
  438. err_free_sp:
  439. gpio_free(pdata->slots[0].switch_pin);
  440. return ret;
  441. }
  442. static void omap_hsmmc_gpio_free(struct omap_mmc_platform_data *pdata)
  443. {
  444. if (gpio_is_valid(pdata->slots[0].gpio_wp))
  445. gpio_free(pdata->slots[0].gpio_wp);
  446. if (gpio_is_valid(pdata->slots[0].switch_pin))
  447. gpio_free(pdata->slots[0].switch_pin);
  448. }
  449. /*
  450. * Stop clock to the card
  451. */
  452. static void omap_hsmmc_stop_clock(struct omap_hsmmc_host *host)
  453. {
  454. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  455. OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN);
  456. if ((OMAP_HSMMC_READ(host->base, SYSCTL) & CEN) != 0x0)
  457. dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stoped\n");
  458. }
  459. #ifdef CONFIG_PM
  460. /*
  461. * Restore the MMC host context, if it was lost as result of a
  462. * power state change.
  463. */
  464. static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host)
  465. {
  466. struct mmc_ios *ios = &host->mmc->ios;
  467. struct omap_mmc_platform_data *pdata = host->pdata;
  468. int context_loss = 0;
  469. u32 hctl, capa, con;
  470. u16 dsor = 0;
  471. unsigned long timeout;
  472. if (pdata->get_context_loss_count) {
  473. context_loss = pdata->get_context_loss_count(host->dev);
  474. if (context_loss < 0)
  475. return 1;
  476. }
  477. dev_dbg(mmc_dev(host->mmc), "context was %slost\n",
  478. context_loss == host->context_loss ? "not " : "");
  479. if (host->context_loss == context_loss)
  480. return 1;
  481. /* Wait for hardware reset */
  482. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  483. while ((OMAP_HSMMC_READ(host->base, SYSSTATUS) & RESETDONE) != RESETDONE
  484. && time_before(jiffies, timeout))
  485. ;
  486. /* Do software reset */
  487. OMAP_HSMMC_WRITE(host->base, SYSCONFIG, SOFTRESET);
  488. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  489. while ((OMAP_HSMMC_READ(host->base, SYSSTATUS) & RESETDONE) != RESETDONE
  490. && time_before(jiffies, timeout))
  491. ;
  492. OMAP_HSMMC_WRITE(host->base, SYSCONFIG,
  493. OMAP_HSMMC_READ(host->base, SYSCONFIG) | AUTOIDLE);
  494. if (host->id == OMAP_MMC1_DEVID) {
  495. if (host->power_mode != MMC_POWER_OFF &&
  496. (1 << ios->vdd) <= MMC_VDD_23_24)
  497. hctl = SDVS18;
  498. else
  499. hctl = SDVS30;
  500. capa = VS30 | VS18;
  501. } else {
  502. hctl = SDVS18;
  503. capa = VS18;
  504. }
  505. OMAP_HSMMC_WRITE(host->base, HCTL,
  506. OMAP_HSMMC_READ(host->base, HCTL) | hctl);
  507. OMAP_HSMMC_WRITE(host->base, CAPA,
  508. OMAP_HSMMC_READ(host->base, CAPA) | capa);
  509. OMAP_HSMMC_WRITE(host->base, HCTL,
  510. OMAP_HSMMC_READ(host->base, HCTL) | SDBP);
  511. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  512. while ((OMAP_HSMMC_READ(host->base, HCTL) & SDBP) != SDBP
  513. && time_before(jiffies, timeout))
  514. ;
  515. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  516. OMAP_HSMMC_WRITE(host->base, ISE, INT_EN_MASK);
  517. OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
  518. /* Do not initialize card-specific things if the power is off */
  519. if (host->power_mode == MMC_POWER_OFF)
  520. goto out;
  521. con = OMAP_HSMMC_READ(host->base, CON);
  522. switch (ios->bus_width) {
  523. case MMC_BUS_WIDTH_8:
  524. OMAP_HSMMC_WRITE(host->base, CON, con | DW8);
  525. break;
  526. case MMC_BUS_WIDTH_4:
  527. OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
  528. OMAP_HSMMC_WRITE(host->base, HCTL,
  529. OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT);
  530. break;
  531. case MMC_BUS_WIDTH_1:
  532. OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
  533. OMAP_HSMMC_WRITE(host->base, HCTL,
  534. OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT);
  535. break;
  536. }
  537. if (ios->clock) {
  538. dsor = OMAP_MMC_MASTER_CLOCK / ios->clock;
  539. if (dsor < 1)
  540. dsor = 1;
  541. if (OMAP_MMC_MASTER_CLOCK / dsor > ios->clock)
  542. dsor++;
  543. if (dsor > 250)
  544. dsor = 250;
  545. }
  546. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  547. OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN);
  548. OMAP_HSMMC_WRITE(host->base, SYSCTL, (dsor << 6) | (DTO << 16));
  549. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  550. OMAP_HSMMC_READ(host->base, SYSCTL) | ICE);
  551. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  552. while ((OMAP_HSMMC_READ(host->base, SYSCTL) & ICS) != ICS
  553. && time_before(jiffies, timeout))
  554. ;
  555. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  556. OMAP_HSMMC_READ(host->base, SYSCTL) | CEN);
  557. con = OMAP_HSMMC_READ(host->base, CON);
  558. if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
  559. OMAP_HSMMC_WRITE(host->base, CON, con | OD);
  560. else
  561. OMAP_HSMMC_WRITE(host->base, CON, con & ~OD);
  562. out:
  563. host->context_loss = context_loss;
  564. dev_dbg(mmc_dev(host->mmc), "context is restored\n");
  565. return 0;
  566. }
  567. /*
  568. * Save the MMC host context (store the number of power state changes so far).
  569. */
  570. static void omap_hsmmc_context_save(struct omap_hsmmc_host *host)
  571. {
  572. struct omap_mmc_platform_data *pdata = host->pdata;
  573. int context_loss;
  574. if (pdata->get_context_loss_count) {
  575. context_loss = pdata->get_context_loss_count(host->dev);
  576. if (context_loss < 0)
  577. return;
  578. host->context_loss = context_loss;
  579. }
  580. }
  581. #else
  582. static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host)
  583. {
  584. return 0;
  585. }
  586. static void omap_hsmmc_context_save(struct omap_hsmmc_host *host)
  587. {
  588. }
  589. #endif
  590. /*
  591. * Send init stream sequence to card
  592. * before sending IDLE command
  593. */
  594. static void send_init_stream(struct omap_hsmmc_host *host)
  595. {
  596. int reg = 0;
  597. unsigned long timeout;
  598. if (host->protect_card)
  599. return;
  600. disable_irq(host->irq);
  601. OMAP_HSMMC_WRITE(host->base, CON,
  602. OMAP_HSMMC_READ(host->base, CON) | INIT_STREAM);
  603. OMAP_HSMMC_WRITE(host->base, CMD, INIT_STREAM_CMD);
  604. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  605. while ((reg != CC) && time_before(jiffies, timeout))
  606. reg = OMAP_HSMMC_READ(host->base, STAT) & CC;
  607. OMAP_HSMMC_WRITE(host->base, CON,
  608. OMAP_HSMMC_READ(host->base, CON) & ~INIT_STREAM);
  609. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  610. OMAP_HSMMC_READ(host->base, STAT);
  611. enable_irq(host->irq);
  612. }
  613. static inline
  614. int omap_hsmmc_cover_is_closed(struct omap_hsmmc_host *host)
  615. {
  616. int r = 1;
  617. if (mmc_slot(host).get_cover_state)
  618. r = mmc_slot(host).get_cover_state(host->dev, host->slot_id);
  619. return r;
  620. }
  621. static ssize_t
  622. omap_hsmmc_show_cover_switch(struct device *dev, struct device_attribute *attr,
  623. char *buf)
  624. {
  625. struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
  626. struct omap_hsmmc_host *host = mmc_priv(mmc);
  627. return sprintf(buf, "%s\n",
  628. omap_hsmmc_cover_is_closed(host) ? "closed" : "open");
  629. }
  630. static DEVICE_ATTR(cover_switch, S_IRUGO, omap_hsmmc_show_cover_switch, NULL);
  631. static ssize_t
  632. omap_hsmmc_show_slot_name(struct device *dev, struct device_attribute *attr,
  633. char *buf)
  634. {
  635. struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
  636. struct omap_hsmmc_host *host = mmc_priv(mmc);
  637. return sprintf(buf, "%s\n", mmc_slot(host).name);
  638. }
  639. static DEVICE_ATTR(slot_name, S_IRUGO, omap_hsmmc_show_slot_name, NULL);
  640. /*
  641. * Configure the response type and send the cmd.
  642. */
  643. static void
  644. omap_hsmmc_start_command(struct omap_hsmmc_host *host, struct mmc_command *cmd,
  645. struct mmc_data *data)
  646. {
  647. int cmdreg = 0, resptype = 0, cmdtype = 0;
  648. dev_dbg(mmc_dev(host->mmc), "%s: CMD%d, argument 0x%08x\n",
  649. mmc_hostname(host->mmc), cmd->opcode, cmd->arg);
  650. host->cmd = cmd;
  651. /*
  652. * Clear status bits and enable interrupts
  653. */
  654. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  655. OMAP_HSMMC_WRITE(host->base, ISE, INT_EN_MASK);
  656. if (host->use_dma)
  657. OMAP_HSMMC_WRITE(host->base, IE,
  658. INT_EN_MASK & ~(BRR_ENABLE | BWR_ENABLE));
  659. else
  660. OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
  661. host->response_busy = 0;
  662. if (cmd->flags & MMC_RSP_PRESENT) {
  663. if (cmd->flags & MMC_RSP_136)
  664. resptype = 1;
  665. else if (cmd->flags & MMC_RSP_BUSY) {
  666. resptype = 3;
  667. host->response_busy = 1;
  668. } else
  669. resptype = 2;
  670. }
  671. /*
  672. * Unlike OMAP1 controller, the cmdtype does not seem to be based on
  673. * ac, bc, adtc, bcr. Only commands ending an open ended transfer need
  674. * a val of 0x3, rest 0x0.
  675. */
  676. if (cmd == host->mrq->stop)
  677. cmdtype = 0x3;
  678. cmdreg = (cmd->opcode << 24) | (resptype << 16) | (cmdtype << 22);
  679. if (data) {
  680. cmdreg |= DP_SELECT | MSBS | BCE;
  681. if (data->flags & MMC_DATA_READ)
  682. cmdreg |= DDIR;
  683. else
  684. cmdreg &= ~(DDIR);
  685. }
  686. if (host->use_dma)
  687. cmdreg |= DMA_EN;
  688. /*
  689. * In an interrupt context (i.e. STOP command), the spinlock is unlocked
  690. * by the interrupt handler, otherwise (i.e. for a new request) it is
  691. * unlocked here.
  692. */
  693. if (!in_interrupt())
  694. spin_unlock_irqrestore(&host->irq_lock, host->flags);
  695. OMAP_HSMMC_WRITE(host->base, ARG, cmd->arg);
  696. OMAP_HSMMC_WRITE(host->base, CMD, cmdreg);
  697. }
  698. static int
  699. omap_hsmmc_get_dma_dir(struct omap_hsmmc_host *host, struct mmc_data *data)
  700. {
  701. if (data->flags & MMC_DATA_WRITE)
  702. return DMA_TO_DEVICE;
  703. else
  704. return DMA_FROM_DEVICE;
  705. }
  706. /*
  707. * Notify the transfer complete to MMC core
  708. */
  709. static void
  710. omap_hsmmc_xfer_done(struct omap_hsmmc_host *host, struct mmc_data *data)
  711. {
  712. if (!data) {
  713. struct mmc_request *mrq = host->mrq;
  714. /* TC before CC from CMD6 - don't know why, but it happens */
  715. if (host->cmd && host->cmd->opcode == 6 &&
  716. host->response_busy) {
  717. host->response_busy = 0;
  718. return;
  719. }
  720. host->mrq = NULL;
  721. mmc_request_done(host->mmc, mrq);
  722. return;
  723. }
  724. host->data = NULL;
  725. if (host->use_dma && host->dma_ch != -1)
  726. dma_unmap_sg(mmc_dev(host->mmc), data->sg, host->dma_len,
  727. omap_hsmmc_get_dma_dir(host, data));
  728. if (!data->error)
  729. data->bytes_xfered += data->blocks * (data->blksz);
  730. else
  731. data->bytes_xfered = 0;
  732. if (!data->stop) {
  733. host->mrq = NULL;
  734. mmc_request_done(host->mmc, data->mrq);
  735. return;
  736. }
  737. omap_hsmmc_start_command(host, data->stop, NULL);
  738. }
  739. /*
  740. * Notify the core about command completion
  741. */
  742. static void
  743. omap_hsmmc_cmd_done(struct omap_hsmmc_host *host, struct mmc_command *cmd)
  744. {
  745. host->cmd = NULL;
  746. if (cmd->flags & MMC_RSP_PRESENT) {
  747. if (cmd->flags & MMC_RSP_136) {
  748. /* response type 2 */
  749. cmd->resp[3] = OMAP_HSMMC_READ(host->base, RSP10);
  750. cmd->resp[2] = OMAP_HSMMC_READ(host->base, RSP32);
  751. cmd->resp[1] = OMAP_HSMMC_READ(host->base, RSP54);
  752. cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP76);
  753. } else {
  754. /* response types 1, 1b, 3, 4, 5, 6 */
  755. cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP10);
  756. }
  757. }
  758. if ((host->data == NULL && !host->response_busy) || cmd->error) {
  759. host->mrq = NULL;
  760. mmc_request_done(host->mmc, cmd->mrq);
  761. }
  762. }
  763. /*
  764. * DMA clean up for command errors
  765. */
  766. static void omap_hsmmc_dma_cleanup(struct omap_hsmmc_host *host, int errno)
  767. {
  768. host->data->error = errno;
  769. if (host->use_dma && host->dma_ch != -1) {
  770. dma_unmap_sg(mmc_dev(host->mmc), host->data->sg, host->dma_len,
  771. omap_hsmmc_get_dma_dir(host, host->data));
  772. omap_free_dma(host->dma_ch);
  773. host->dma_ch = -1;
  774. up(&host->sem);
  775. }
  776. host->data = NULL;
  777. }
  778. /*
  779. * Readable error output
  780. */
  781. #ifdef CONFIG_MMC_DEBUG
  782. static void omap_hsmmc_report_irq(struct omap_hsmmc_host *host, u32 status)
  783. {
  784. /* --- means reserved bit without definition at documentation */
  785. static const char *omap_hsmmc_status_bits[] = {
  786. "CC", "TC", "BGE", "---", "BWR", "BRR", "---", "---", "CIRQ",
  787. "OBI", "---", "---", "---", "---", "---", "ERRI", "CTO", "CCRC",
  788. "CEB", "CIE", "DTO", "DCRC", "DEB", "---", "ACE", "---",
  789. "---", "---", "---", "CERR", "CERR", "BADA", "---", "---", "---"
  790. };
  791. char res[256];
  792. char *buf = res;
  793. int len, i;
  794. len = sprintf(buf, "MMC IRQ 0x%x :", status);
  795. buf += len;
  796. for (i = 0; i < ARRAY_SIZE(omap_hsmmc_status_bits); i++)
  797. if (status & (1 << i)) {
  798. len = sprintf(buf, " %s", omap_hsmmc_status_bits[i]);
  799. buf += len;
  800. }
  801. dev_dbg(mmc_dev(host->mmc), "%s\n", res);
  802. }
  803. #endif /* CONFIG_MMC_DEBUG */
  804. /*
  805. * MMC controller internal state machines reset
  806. *
  807. * Used to reset command or data internal state machines, using respectively
  808. * SRC or SRD bit of SYSCTL register
  809. * Can be called from interrupt context
  810. */
  811. static inline void omap_hsmmc_reset_controller_fsm(struct omap_hsmmc_host *host,
  812. unsigned long bit)
  813. {
  814. unsigned long i = 0;
  815. unsigned long limit = (loops_per_jiffy *
  816. msecs_to_jiffies(MMC_TIMEOUT_MS));
  817. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  818. OMAP_HSMMC_READ(host->base, SYSCTL) | bit);
  819. while ((OMAP_HSMMC_READ(host->base, SYSCTL) & bit) &&
  820. (i++ < limit))
  821. cpu_relax();
  822. if (OMAP_HSMMC_READ(host->base, SYSCTL) & bit)
  823. dev_err(mmc_dev(host->mmc),
  824. "Timeout waiting on controller reset in %s\n",
  825. __func__);
  826. }
  827. /*
  828. * MMC controller IRQ handler
  829. */
  830. static irqreturn_t omap_hsmmc_irq(int irq, void *dev_id)
  831. {
  832. struct omap_hsmmc_host *host = dev_id;
  833. struct mmc_data *data;
  834. int end_cmd = 0, end_trans = 0, status;
  835. spin_lock(&host->irq_lock);
  836. if (host->mrq == NULL) {
  837. OMAP_HSMMC_WRITE(host->base, STAT,
  838. OMAP_HSMMC_READ(host->base, STAT));
  839. /* Flush posted write */
  840. OMAP_HSMMC_READ(host->base, STAT);
  841. spin_unlock(&host->irq_lock);
  842. return IRQ_HANDLED;
  843. }
  844. data = host->data;
  845. status = OMAP_HSMMC_READ(host->base, STAT);
  846. dev_dbg(mmc_dev(host->mmc), "IRQ Status is %x\n", status);
  847. if (status & ERR) {
  848. #ifdef CONFIG_MMC_DEBUG
  849. omap_hsmmc_report_irq(host, status);
  850. #endif
  851. if ((status & CMD_TIMEOUT) ||
  852. (status & CMD_CRC)) {
  853. if (host->cmd) {
  854. if (status & CMD_TIMEOUT) {
  855. omap_hsmmc_reset_controller_fsm(host,
  856. SRC);
  857. host->cmd->error = -ETIMEDOUT;
  858. } else {
  859. host->cmd->error = -EILSEQ;
  860. }
  861. end_cmd = 1;
  862. }
  863. if (host->data || host->response_busy) {
  864. if (host->data)
  865. omap_hsmmc_dma_cleanup(host,
  866. -ETIMEDOUT);
  867. host->response_busy = 0;
  868. omap_hsmmc_reset_controller_fsm(host, SRD);
  869. }
  870. }
  871. if ((status & DATA_TIMEOUT) ||
  872. (status & DATA_CRC)) {
  873. if (host->data || host->response_busy) {
  874. int err = (status & DATA_TIMEOUT) ?
  875. -ETIMEDOUT : -EILSEQ;
  876. if (host->data)
  877. omap_hsmmc_dma_cleanup(host, err);
  878. else
  879. host->mrq->cmd->error = err;
  880. host->response_busy = 0;
  881. omap_hsmmc_reset_controller_fsm(host, SRD);
  882. end_trans = 1;
  883. }
  884. }
  885. if (status & CARD_ERR) {
  886. dev_dbg(mmc_dev(host->mmc),
  887. "Ignoring card err CMD%d\n", host->cmd->opcode);
  888. if (host->cmd)
  889. end_cmd = 1;
  890. if (host->data)
  891. end_trans = 1;
  892. }
  893. }
  894. OMAP_HSMMC_WRITE(host->base, STAT, status);
  895. /* Flush posted write */
  896. OMAP_HSMMC_READ(host->base, STAT);
  897. if (end_cmd || ((status & CC) && host->cmd))
  898. omap_hsmmc_cmd_done(host, host->cmd);
  899. if ((end_trans || (status & TC)) && host->mrq)
  900. omap_hsmmc_xfer_done(host, data);
  901. spin_unlock(&host->irq_lock);
  902. return IRQ_HANDLED;
  903. }
  904. static void set_sd_bus_power(struct omap_hsmmc_host *host)
  905. {
  906. unsigned long i;
  907. OMAP_HSMMC_WRITE(host->base, HCTL,
  908. OMAP_HSMMC_READ(host->base, HCTL) | SDBP);
  909. for (i = 0; i < loops_per_jiffy; i++) {
  910. if (OMAP_HSMMC_READ(host->base, HCTL) & SDBP)
  911. break;
  912. cpu_relax();
  913. }
  914. }
  915. /*
  916. * Switch MMC interface voltage ... only relevant for MMC1.
  917. *
  918. * MMC2 and MMC3 use fixed 1.8V levels, and maybe a transceiver.
  919. * The MMC2 transceiver controls are used instead of DAT4..DAT7.
  920. * Some chips, like eMMC ones, use internal transceivers.
  921. */
  922. static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd)
  923. {
  924. u32 reg_val = 0;
  925. int ret;
  926. /* Disable the clocks */
  927. clk_disable(host->fclk);
  928. clk_disable(host->iclk);
  929. if (host->got_dbclk)
  930. clk_disable(host->dbclk);
  931. /* Turn the power off */
  932. ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0);
  933. /* Turn the power ON with given VDD 1.8 or 3.0v */
  934. if (!ret)
  935. ret = mmc_slot(host).set_power(host->dev, host->slot_id, 1,
  936. vdd);
  937. clk_enable(host->iclk);
  938. clk_enable(host->fclk);
  939. if (host->got_dbclk)
  940. clk_enable(host->dbclk);
  941. if (ret != 0)
  942. goto err;
  943. OMAP_HSMMC_WRITE(host->base, HCTL,
  944. OMAP_HSMMC_READ(host->base, HCTL) & SDVSCLR);
  945. reg_val = OMAP_HSMMC_READ(host->base, HCTL);
  946. /*
  947. * If a MMC dual voltage card is detected, the set_ios fn calls
  948. * this fn with VDD bit set for 1.8V. Upon card removal from the
  949. * slot, omap_hsmmc_set_ios sets the VDD back to 3V on MMC_POWER_OFF.
  950. *
  951. * Cope with a bit of slop in the range ... per data sheets:
  952. * - "1.8V" for vdds_mmc1/vdds_mmc1a can be up to 2.45V max,
  953. * but recommended values are 1.71V to 1.89V
  954. * - "3.0V" for vdds_mmc1/vdds_mmc1a can be up to 3.5V max,
  955. * but recommended values are 2.7V to 3.3V
  956. *
  957. * Board setup code shouldn't permit anything very out-of-range.
  958. * TWL4030-family VMMC1 and VSIM regulators are fine (avoiding the
  959. * middle range) but VSIM can't power DAT4..DAT7 at more than 3V.
  960. */
  961. if ((1 << vdd) <= MMC_VDD_23_24)
  962. reg_val |= SDVS18;
  963. else
  964. reg_val |= SDVS30;
  965. OMAP_HSMMC_WRITE(host->base, HCTL, reg_val);
  966. set_sd_bus_power(host);
  967. return 0;
  968. err:
  969. dev_dbg(mmc_dev(host->mmc), "Unable to switch operating voltage\n");
  970. return ret;
  971. }
  972. /* Protect the card while the cover is open */
  973. static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host)
  974. {
  975. if (!mmc_slot(host).get_cover_state)
  976. return;
  977. host->reqs_blocked = 0;
  978. if (mmc_slot(host).get_cover_state(host->dev, host->slot_id)) {
  979. if (host->protect_card) {
  980. printk(KERN_INFO "%s: cover is closed, "
  981. "card is now accessible\n",
  982. mmc_hostname(host->mmc));
  983. host->protect_card = 0;
  984. }
  985. } else {
  986. if (!host->protect_card) {
  987. printk(KERN_INFO "%s: cover is open, "
  988. "card is now inaccessible\n",
  989. mmc_hostname(host->mmc));
  990. host->protect_card = 1;
  991. }
  992. }
  993. }
  994. /*
  995. * Work Item to notify the core about card insertion/removal
  996. */
  997. static void omap_hsmmc_detect(struct work_struct *work)
  998. {
  999. struct omap_hsmmc_host *host =
  1000. container_of(work, struct omap_hsmmc_host, mmc_carddetect_work);
  1001. struct omap_mmc_slot_data *slot = &mmc_slot(host);
  1002. int carddetect;
  1003. if (host->suspended)
  1004. return;
  1005. sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
  1006. if (slot->card_detect)
  1007. carddetect = slot->card_detect(host->dev, host->slot_id);
  1008. else {
  1009. omap_hsmmc_protect_card(host);
  1010. carddetect = -ENOSYS;
  1011. }
  1012. if (carddetect) {
  1013. mmc_detect_change(host->mmc, (HZ * 200) / 1000);
  1014. } else {
  1015. mmc_host_enable(host->mmc);
  1016. omap_hsmmc_reset_controller_fsm(host, SRD);
  1017. mmc_host_lazy_disable(host->mmc);
  1018. mmc_detect_change(host->mmc, (HZ * 50) / 1000);
  1019. }
  1020. }
  1021. /*
  1022. * ISR for handling card insertion and removal
  1023. */
  1024. static irqreturn_t omap_hsmmc_cd_handler(int irq, void *dev_id)
  1025. {
  1026. struct omap_hsmmc_host *host = (struct omap_hsmmc_host *)dev_id;
  1027. if (host->suspended)
  1028. return IRQ_HANDLED;
  1029. schedule_work(&host->mmc_carddetect_work);
  1030. return IRQ_HANDLED;
  1031. }
  1032. static int omap_hsmmc_get_dma_sync_dev(struct omap_hsmmc_host *host,
  1033. struct mmc_data *data)
  1034. {
  1035. int sync_dev;
  1036. if (data->flags & MMC_DATA_WRITE)
  1037. sync_dev = host->dma_line_tx;
  1038. else
  1039. sync_dev = host->dma_line_rx;
  1040. return sync_dev;
  1041. }
  1042. static void omap_hsmmc_config_dma_params(struct omap_hsmmc_host *host,
  1043. struct mmc_data *data,
  1044. struct scatterlist *sgl)
  1045. {
  1046. int blksz, nblk, dma_ch;
  1047. dma_ch = host->dma_ch;
  1048. if (data->flags & MMC_DATA_WRITE) {
  1049. omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
  1050. (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
  1051. omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
  1052. sg_dma_address(sgl), 0, 0);
  1053. } else {
  1054. omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
  1055. (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
  1056. omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
  1057. sg_dma_address(sgl), 0, 0);
  1058. }
  1059. blksz = host->data->blksz;
  1060. nblk = sg_dma_len(sgl) / blksz;
  1061. omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S32,
  1062. blksz / 4, nblk, OMAP_DMA_SYNC_FRAME,
  1063. omap_hsmmc_get_dma_sync_dev(host, data),
  1064. !(data->flags & MMC_DATA_WRITE));
  1065. omap_start_dma(dma_ch);
  1066. }
  1067. /*
  1068. * DMA call back function
  1069. */
  1070. static void omap_hsmmc_dma_cb(int lch, u16 ch_status, void *data)
  1071. {
  1072. struct omap_hsmmc_host *host = data;
  1073. if (ch_status & OMAP2_DMA_MISALIGNED_ERR_IRQ)
  1074. dev_dbg(mmc_dev(host->mmc), "MISALIGNED_ADRS_ERR\n");
  1075. if (host->dma_ch < 0)
  1076. return;
  1077. host->dma_sg_idx++;
  1078. if (host->dma_sg_idx < host->dma_len) {
  1079. /* Fire up the next transfer. */
  1080. omap_hsmmc_config_dma_params(host, host->data,
  1081. host->data->sg + host->dma_sg_idx);
  1082. return;
  1083. }
  1084. omap_free_dma(host->dma_ch);
  1085. host->dma_ch = -1;
  1086. /*
  1087. * DMA Callback: run in interrupt context.
  1088. * mutex_unlock will throw a kernel warning if used.
  1089. */
  1090. up(&host->sem);
  1091. }
  1092. /*
  1093. * Routine to configure and start DMA for the MMC card
  1094. */
  1095. static int omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host,
  1096. struct mmc_request *req)
  1097. {
  1098. int dma_ch = 0, ret = 0, err = 1, i;
  1099. struct mmc_data *data = req->data;
  1100. /* Sanity check: all the SG entries must be aligned by block size. */
  1101. for (i = 0; i < data->sg_len; i++) {
  1102. struct scatterlist *sgl;
  1103. sgl = data->sg + i;
  1104. if (sgl->length % data->blksz)
  1105. return -EINVAL;
  1106. }
  1107. if ((data->blksz % 4) != 0)
  1108. /* REVISIT: The MMC buffer increments only when MSB is written.
  1109. * Return error for blksz which is non multiple of four.
  1110. */
  1111. return -EINVAL;
  1112. /*
  1113. * If for some reason the DMA transfer is still active,
  1114. * we wait for timeout period and free the dma
  1115. */
  1116. if (host->dma_ch != -1) {
  1117. set_current_state(TASK_UNINTERRUPTIBLE);
  1118. schedule_timeout(100);
  1119. if (down_trylock(&host->sem)) {
  1120. omap_free_dma(host->dma_ch);
  1121. host->dma_ch = -1;
  1122. up(&host->sem);
  1123. return err;
  1124. }
  1125. } else {
  1126. if (down_trylock(&host->sem))
  1127. return err;
  1128. }
  1129. ret = omap_request_dma(omap_hsmmc_get_dma_sync_dev(host, data),
  1130. "MMC/SD", omap_hsmmc_dma_cb, host, &dma_ch);
  1131. if (ret != 0) {
  1132. dev_err(mmc_dev(host->mmc),
  1133. "%s: omap_request_dma() failed with %d\n",
  1134. mmc_hostname(host->mmc), ret);
  1135. return ret;
  1136. }
  1137. host->dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg,
  1138. data->sg_len, omap_hsmmc_get_dma_dir(host, data));
  1139. host->dma_ch = dma_ch;
  1140. host->dma_sg_idx = 0;
  1141. omap_hsmmc_config_dma_params(host, data, data->sg);
  1142. return 0;
  1143. }
  1144. static void set_data_timeout(struct omap_hsmmc_host *host,
  1145. unsigned int timeout_ns,
  1146. unsigned int timeout_clks)
  1147. {
  1148. unsigned int timeout, cycle_ns;
  1149. uint32_t reg, clkd, dto = 0;
  1150. reg = OMAP_HSMMC_READ(host->base, SYSCTL);
  1151. clkd = (reg & CLKD_MASK) >> CLKD_SHIFT;
  1152. if (clkd == 0)
  1153. clkd = 1;
  1154. cycle_ns = 1000000000 / (clk_get_rate(host->fclk) / clkd);
  1155. timeout = timeout_ns / cycle_ns;
  1156. timeout += timeout_clks;
  1157. if (timeout) {
  1158. while ((timeout & 0x80000000) == 0) {
  1159. dto += 1;
  1160. timeout <<= 1;
  1161. }
  1162. dto = 31 - dto;
  1163. timeout <<= 1;
  1164. if (timeout && dto)
  1165. dto += 1;
  1166. if (dto >= 13)
  1167. dto -= 13;
  1168. else
  1169. dto = 0;
  1170. if (dto > 14)
  1171. dto = 14;
  1172. }
  1173. reg &= ~DTO_MASK;
  1174. reg |= dto << DTO_SHIFT;
  1175. OMAP_HSMMC_WRITE(host->base, SYSCTL, reg);
  1176. }
  1177. /*
  1178. * Configure block length for MMC/SD cards and initiate the transfer.
  1179. */
  1180. static int
  1181. omap_hsmmc_prepare_data(struct omap_hsmmc_host *host, struct mmc_request *req)
  1182. {
  1183. int ret;
  1184. host->data = req->data;
  1185. if (req->data == NULL) {
  1186. OMAP_HSMMC_WRITE(host->base, BLK, 0);
  1187. /*
  1188. * Set an arbitrary 100ms data timeout for commands with
  1189. * busy signal.
  1190. */
  1191. if (req->cmd->flags & MMC_RSP_BUSY)
  1192. set_data_timeout(host, 100000000U, 0);
  1193. return 0;
  1194. }
  1195. OMAP_HSMMC_WRITE(host->base, BLK, (req->data->blksz)
  1196. | (req->data->blocks << 16));
  1197. set_data_timeout(host, req->data->timeout_ns, req->data->timeout_clks);
  1198. if (host->use_dma) {
  1199. ret = omap_hsmmc_start_dma_transfer(host, req);
  1200. if (ret != 0) {
  1201. dev_dbg(mmc_dev(host->mmc), "MMC start dma failure\n");
  1202. return ret;
  1203. }
  1204. }
  1205. return 0;
  1206. }
  1207. /*
  1208. * Request function. for read/write operation
  1209. */
  1210. static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req)
  1211. {
  1212. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1213. int err;
  1214. /*
  1215. * Prevent races with the interrupt handler because of unexpected
  1216. * interrupts, but not if we are already in interrupt context i.e.
  1217. * retries.
  1218. */
  1219. if (!in_interrupt()) {
  1220. spin_lock_irqsave(&host->irq_lock, host->flags);
  1221. /*
  1222. * Protect the card from I/O if there is a possibility
  1223. * it can be removed.
  1224. */
  1225. if (host->protect_card) {
  1226. if (host->reqs_blocked < 3) {
  1227. /*
  1228. * Ensure the controller is left in a consistent
  1229. * state by resetting the command and data state
  1230. * machines.
  1231. */
  1232. omap_hsmmc_reset_controller_fsm(host, SRD);
  1233. omap_hsmmc_reset_controller_fsm(host, SRC);
  1234. host->reqs_blocked += 1;
  1235. }
  1236. req->cmd->error = -EBADF;
  1237. if (req->data)
  1238. req->data->error = -EBADF;
  1239. spin_unlock_irqrestore(&host->irq_lock, host->flags);
  1240. mmc_request_done(mmc, req);
  1241. return;
  1242. } else if (host->reqs_blocked)
  1243. host->reqs_blocked = 0;
  1244. }
  1245. WARN_ON(host->mrq != NULL);
  1246. host->mrq = req;
  1247. err = omap_hsmmc_prepare_data(host, req);
  1248. if (err) {
  1249. req->cmd->error = err;
  1250. if (req->data)
  1251. req->data->error = err;
  1252. host->mrq = NULL;
  1253. if (!in_interrupt())
  1254. spin_unlock_irqrestore(&host->irq_lock, host->flags);
  1255. mmc_request_done(mmc, req);
  1256. return;
  1257. }
  1258. omap_hsmmc_start_command(host, req->cmd, req->data);
  1259. }
  1260. /* Routine to configure clock values. Exposed API to core */
  1261. static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  1262. {
  1263. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1264. u16 dsor = 0;
  1265. unsigned long regval;
  1266. unsigned long timeout;
  1267. u32 con;
  1268. int do_send_init_stream = 0;
  1269. mmc_host_enable(host->mmc);
  1270. if (ios->power_mode != host->power_mode) {
  1271. switch (ios->power_mode) {
  1272. case MMC_POWER_OFF:
  1273. mmc_slot(host).set_power(host->dev, host->slot_id,
  1274. 0, 0);
  1275. host->vdd = 0;
  1276. break;
  1277. case MMC_POWER_UP:
  1278. mmc_slot(host).set_power(host->dev, host->slot_id,
  1279. 1, ios->vdd);
  1280. host->vdd = ios->vdd;
  1281. break;
  1282. case MMC_POWER_ON:
  1283. do_send_init_stream = 1;
  1284. break;
  1285. }
  1286. host->power_mode = ios->power_mode;
  1287. }
  1288. /* FIXME: set registers based only on changes to ios */
  1289. con = OMAP_HSMMC_READ(host->base, CON);
  1290. switch (mmc->ios.bus_width) {
  1291. case MMC_BUS_WIDTH_8:
  1292. OMAP_HSMMC_WRITE(host->base, CON, con | DW8);
  1293. break;
  1294. case MMC_BUS_WIDTH_4:
  1295. OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
  1296. OMAP_HSMMC_WRITE(host->base, HCTL,
  1297. OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT);
  1298. break;
  1299. case MMC_BUS_WIDTH_1:
  1300. OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
  1301. OMAP_HSMMC_WRITE(host->base, HCTL,
  1302. OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT);
  1303. break;
  1304. }
  1305. if (host->id == OMAP_MMC1_DEVID) {
  1306. /* Only MMC1 can interface at 3V without some flavor
  1307. * of external transceiver; but they all handle 1.8V.
  1308. */
  1309. if ((OMAP_HSMMC_READ(host->base, HCTL) & SDVSDET) &&
  1310. (ios->vdd == DUAL_VOLT_OCR_BIT)) {
  1311. /*
  1312. * The mmc_select_voltage fn of the core does
  1313. * not seem to set the power_mode to
  1314. * MMC_POWER_UP upon recalculating the voltage.
  1315. * vdd 1.8v.
  1316. */
  1317. if (omap_hsmmc_switch_opcond(host, ios->vdd) != 0)
  1318. dev_dbg(mmc_dev(host->mmc),
  1319. "Switch operation failed\n");
  1320. }
  1321. }
  1322. if (ios->clock) {
  1323. dsor = OMAP_MMC_MASTER_CLOCK / ios->clock;
  1324. if (dsor < 1)
  1325. dsor = 1;
  1326. if (OMAP_MMC_MASTER_CLOCK / dsor > ios->clock)
  1327. dsor++;
  1328. if (dsor > 250)
  1329. dsor = 250;
  1330. }
  1331. omap_hsmmc_stop_clock(host);
  1332. regval = OMAP_HSMMC_READ(host->base, SYSCTL);
  1333. regval = regval & ~(CLKD_MASK);
  1334. regval = regval | (dsor << 6) | (DTO << 16);
  1335. OMAP_HSMMC_WRITE(host->base, SYSCTL, regval);
  1336. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  1337. OMAP_HSMMC_READ(host->base, SYSCTL) | ICE);
  1338. /* Wait till the ICS bit is set */
  1339. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  1340. while ((OMAP_HSMMC_READ(host->base, SYSCTL) & ICS) != ICS
  1341. && time_before(jiffies, timeout))
  1342. msleep(1);
  1343. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  1344. OMAP_HSMMC_READ(host->base, SYSCTL) | CEN);
  1345. if (do_send_init_stream)
  1346. send_init_stream(host);
  1347. con = OMAP_HSMMC_READ(host->base, CON);
  1348. if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
  1349. OMAP_HSMMC_WRITE(host->base, CON, con | OD);
  1350. else
  1351. OMAP_HSMMC_WRITE(host->base, CON, con & ~OD);
  1352. if (host->power_mode == MMC_POWER_OFF)
  1353. mmc_host_disable(host->mmc);
  1354. else
  1355. mmc_host_lazy_disable(host->mmc);
  1356. }
  1357. static int omap_hsmmc_get_cd(struct mmc_host *mmc)
  1358. {
  1359. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1360. if (!mmc_slot(host).card_detect)
  1361. return -ENOSYS;
  1362. return mmc_slot(host).card_detect(host->dev, host->slot_id);
  1363. }
  1364. static int omap_hsmmc_get_ro(struct mmc_host *mmc)
  1365. {
  1366. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1367. if (!mmc_slot(host).get_ro)
  1368. return -ENOSYS;
  1369. return mmc_slot(host).get_ro(host->dev, 0);
  1370. }
  1371. static void omap_hsmmc_conf_bus_power(struct omap_hsmmc_host *host)
  1372. {
  1373. u32 hctl, capa, value;
  1374. /* Only MMC1 supports 3.0V */
  1375. if (host->id == OMAP_MMC1_DEVID) {
  1376. hctl = SDVS30;
  1377. capa = VS30 | VS18;
  1378. } else {
  1379. hctl = SDVS18;
  1380. capa = VS18;
  1381. }
  1382. value = OMAP_HSMMC_READ(host->base, HCTL) & ~SDVS_MASK;
  1383. OMAP_HSMMC_WRITE(host->base, HCTL, value | hctl);
  1384. value = OMAP_HSMMC_READ(host->base, CAPA);
  1385. OMAP_HSMMC_WRITE(host->base, CAPA, value | capa);
  1386. /* Set the controller to AUTO IDLE mode */
  1387. value = OMAP_HSMMC_READ(host->base, SYSCONFIG);
  1388. OMAP_HSMMC_WRITE(host->base, SYSCONFIG, value | AUTOIDLE);
  1389. /* Set SD bus power bit */
  1390. set_sd_bus_power(host);
  1391. }
  1392. /*
  1393. * Dynamic power saving handling, FSM:
  1394. * ENABLED -> DISABLED -> CARDSLEEP / REGSLEEP -> OFF
  1395. * ^___________| | |
  1396. * |______________________|______________________|
  1397. *
  1398. * ENABLED: mmc host is fully functional
  1399. * DISABLED: fclk is off
  1400. * CARDSLEEP: fclk is off, card is asleep, voltage regulator is asleep
  1401. * REGSLEEP: fclk is off, voltage regulator is asleep
  1402. * OFF: fclk is off, voltage regulator is off
  1403. *
  1404. * Transition handlers return the timeout for the next state transition
  1405. * or negative error.
  1406. */
  1407. enum {ENABLED = 0, DISABLED, CARDSLEEP, REGSLEEP, OFF};
  1408. /* Handler for [ENABLED -> DISABLED] transition */
  1409. static int omap_hsmmc_enabled_to_disabled(struct omap_hsmmc_host *host)
  1410. {
  1411. omap_hsmmc_context_save(host);
  1412. clk_disable(host->fclk);
  1413. host->dpm_state = DISABLED;
  1414. dev_dbg(mmc_dev(host->mmc), "ENABLED -> DISABLED\n");
  1415. if (host->power_mode == MMC_POWER_OFF)
  1416. return 0;
  1417. return OMAP_MMC_SLEEP_TIMEOUT;
  1418. }
  1419. /* Handler for [DISABLED -> REGSLEEP / CARDSLEEP] transition */
  1420. static int omap_hsmmc_disabled_to_sleep(struct omap_hsmmc_host *host)
  1421. {
  1422. int err, new_state;
  1423. if (!mmc_try_claim_host(host->mmc))
  1424. return 0;
  1425. clk_enable(host->fclk);
  1426. omap_hsmmc_context_restore(host);
  1427. if (mmc_card_can_sleep(host->mmc)) {
  1428. err = mmc_card_sleep(host->mmc);
  1429. if (err < 0) {
  1430. clk_disable(host->fclk);
  1431. mmc_release_host(host->mmc);
  1432. return err;
  1433. }
  1434. new_state = CARDSLEEP;
  1435. } else {
  1436. new_state = REGSLEEP;
  1437. }
  1438. if (mmc_slot(host).set_sleep)
  1439. mmc_slot(host).set_sleep(host->dev, host->slot_id, 1, 0,
  1440. new_state == CARDSLEEP);
  1441. /* FIXME: turn off bus power and perhaps interrupts too */
  1442. clk_disable(host->fclk);
  1443. host->dpm_state = new_state;
  1444. mmc_release_host(host->mmc);
  1445. dev_dbg(mmc_dev(host->mmc), "DISABLED -> %s\n",
  1446. host->dpm_state == CARDSLEEP ? "CARDSLEEP" : "REGSLEEP");
  1447. if (mmc_slot(host).no_off)
  1448. return 0;
  1449. if ((host->mmc->caps & MMC_CAP_NONREMOVABLE) ||
  1450. mmc_slot(host).card_detect ||
  1451. (mmc_slot(host).get_cover_state &&
  1452. mmc_slot(host).get_cover_state(host->dev, host->slot_id)))
  1453. return OMAP_MMC_OFF_TIMEOUT;
  1454. return 0;
  1455. }
  1456. /* Handler for [REGSLEEP / CARDSLEEP -> OFF] transition */
  1457. static int omap_hsmmc_sleep_to_off(struct omap_hsmmc_host *host)
  1458. {
  1459. if (!mmc_try_claim_host(host->mmc))
  1460. return 0;
  1461. if (mmc_slot(host).no_off)
  1462. return 0;
  1463. if (!((host->mmc->caps & MMC_CAP_NONREMOVABLE) ||
  1464. mmc_slot(host).card_detect ||
  1465. (mmc_slot(host).get_cover_state &&
  1466. mmc_slot(host).get_cover_state(host->dev, host->slot_id)))) {
  1467. mmc_release_host(host->mmc);
  1468. return 0;
  1469. }
  1470. mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0);
  1471. host->vdd = 0;
  1472. host->power_mode = MMC_POWER_OFF;
  1473. dev_dbg(mmc_dev(host->mmc), "%s -> OFF\n",
  1474. host->dpm_state == CARDSLEEP ? "CARDSLEEP" : "REGSLEEP");
  1475. host->dpm_state = OFF;
  1476. mmc_release_host(host->mmc);
  1477. return 0;
  1478. }
  1479. /* Handler for [DISABLED -> ENABLED] transition */
  1480. static int omap_hsmmc_disabled_to_enabled(struct omap_hsmmc_host *host)
  1481. {
  1482. int err;
  1483. err = clk_enable(host->fclk);
  1484. if (err < 0)
  1485. return err;
  1486. omap_hsmmc_context_restore(host);
  1487. host->dpm_state = ENABLED;
  1488. dev_dbg(mmc_dev(host->mmc), "DISABLED -> ENABLED\n");
  1489. return 0;
  1490. }
  1491. /* Handler for [SLEEP -> ENABLED] transition */
  1492. static int omap_hsmmc_sleep_to_enabled(struct omap_hsmmc_host *host)
  1493. {
  1494. if (!mmc_try_claim_host(host->mmc))
  1495. return 0;
  1496. clk_enable(host->fclk);
  1497. omap_hsmmc_context_restore(host);
  1498. if (mmc_slot(host).set_sleep)
  1499. mmc_slot(host).set_sleep(host->dev, host->slot_id, 0,
  1500. host->vdd, host->dpm_state == CARDSLEEP);
  1501. if (mmc_card_can_sleep(host->mmc))
  1502. mmc_card_awake(host->mmc);
  1503. dev_dbg(mmc_dev(host->mmc), "%s -> ENABLED\n",
  1504. host->dpm_state == CARDSLEEP ? "CARDSLEEP" : "REGSLEEP");
  1505. host->dpm_state = ENABLED;
  1506. mmc_release_host(host->mmc);
  1507. return 0;
  1508. }
  1509. /* Handler for [OFF -> ENABLED] transition */
  1510. static int omap_hsmmc_off_to_enabled(struct omap_hsmmc_host *host)
  1511. {
  1512. clk_enable(host->fclk);
  1513. omap_hsmmc_context_restore(host);
  1514. omap_hsmmc_conf_bus_power(host);
  1515. mmc_power_restore_host(host->mmc);
  1516. host->dpm_state = ENABLED;
  1517. dev_dbg(mmc_dev(host->mmc), "OFF -> ENABLED\n");
  1518. return 0;
  1519. }
  1520. /*
  1521. * Bring MMC host to ENABLED from any other PM state.
  1522. */
  1523. static int omap_hsmmc_enable(struct mmc_host *mmc)
  1524. {
  1525. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1526. switch (host->dpm_state) {
  1527. case DISABLED:
  1528. return omap_hsmmc_disabled_to_enabled(host);
  1529. case CARDSLEEP:
  1530. case REGSLEEP:
  1531. return omap_hsmmc_sleep_to_enabled(host);
  1532. case OFF:
  1533. return omap_hsmmc_off_to_enabled(host);
  1534. default:
  1535. dev_dbg(mmc_dev(host->mmc), "UNKNOWN state\n");
  1536. return -EINVAL;
  1537. }
  1538. }
  1539. /*
  1540. * Bring MMC host in PM state (one level deeper).
  1541. */
  1542. static int omap_hsmmc_disable(struct mmc_host *mmc, int lazy)
  1543. {
  1544. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1545. switch (host->dpm_state) {
  1546. case ENABLED: {
  1547. int delay;
  1548. delay = omap_hsmmc_enabled_to_disabled(host);
  1549. if (lazy || delay < 0)
  1550. return delay;
  1551. return 0;
  1552. }
  1553. case DISABLED:
  1554. return omap_hsmmc_disabled_to_sleep(host);
  1555. case CARDSLEEP:
  1556. case REGSLEEP:
  1557. return omap_hsmmc_sleep_to_off(host);
  1558. default:
  1559. dev_dbg(mmc_dev(host->mmc), "UNKNOWN state\n");
  1560. return -EINVAL;
  1561. }
  1562. }
  1563. static int omap_hsmmc_enable_fclk(struct mmc_host *mmc)
  1564. {
  1565. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1566. int err;
  1567. err = clk_enable(host->fclk);
  1568. if (err)
  1569. return err;
  1570. dev_dbg(mmc_dev(host->mmc), "mmc_fclk: enabled\n");
  1571. omap_hsmmc_context_restore(host);
  1572. return 0;
  1573. }
  1574. static int omap_hsmmc_disable_fclk(struct mmc_host *mmc, int lazy)
  1575. {
  1576. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1577. omap_hsmmc_context_save(host);
  1578. clk_disable(host->fclk);
  1579. dev_dbg(mmc_dev(host->mmc), "mmc_fclk: disabled\n");
  1580. return 0;
  1581. }
  1582. static const struct mmc_host_ops omap_hsmmc_ops = {
  1583. .enable = omap_hsmmc_enable_fclk,
  1584. .disable = omap_hsmmc_disable_fclk,
  1585. .request = omap_hsmmc_request,
  1586. .set_ios = omap_hsmmc_set_ios,
  1587. .get_cd = omap_hsmmc_get_cd,
  1588. .get_ro = omap_hsmmc_get_ro,
  1589. /* NYET -- enable_sdio_irq */
  1590. };
  1591. static const struct mmc_host_ops omap_hsmmc_ps_ops = {
  1592. .enable = omap_hsmmc_enable,
  1593. .disable = omap_hsmmc_disable,
  1594. .request = omap_hsmmc_request,
  1595. .set_ios = omap_hsmmc_set_ios,
  1596. .get_cd = omap_hsmmc_get_cd,
  1597. .get_ro = omap_hsmmc_get_ro,
  1598. /* NYET -- enable_sdio_irq */
  1599. };
  1600. #ifdef CONFIG_DEBUG_FS
  1601. static int omap_hsmmc_regs_show(struct seq_file *s, void *data)
  1602. {
  1603. struct mmc_host *mmc = s->private;
  1604. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1605. int context_loss = 0;
  1606. if (host->pdata->get_context_loss_count)
  1607. context_loss = host->pdata->get_context_loss_count(host->dev);
  1608. seq_printf(s, "mmc%d:\n"
  1609. " enabled:\t%d\n"
  1610. " dpm_state:\t%d\n"
  1611. " nesting_cnt:\t%d\n"
  1612. " ctx_loss:\t%d:%d\n"
  1613. "\nregs:\n",
  1614. mmc->index, mmc->enabled ? 1 : 0,
  1615. host->dpm_state, mmc->nesting_cnt,
  1616. host->context_loss, context_loss);
  1617. if (host->suspended || host->dpm_state == OFF) {
  1618. seq_printf(s, "host suspended, can't read registers\n");
  1619. return 0;
  1620. }
  1621. if (clk_enable(host->fclk) != 0) {
  1622. seq_printf(s, "can't read the regs\n");
  1623. return 0;
  1624. }
  1625. seq_printf(s, "SYSCONFIG:\t0x%08x\n",
  1626. OMAP_HSMMC_READ(host->base, SYSCONFIG));
  1627. seq_printf(s, "CON:\t\t0x%08x\n",
  1628. OMAP_HSMMC_READ(host->base, CON));
  1629. seq_printf(s, "HCTL:\t\t0x%08x\n",
  1630. OMAP_HSMMC_READ(host->base, HCTL));
  1631. seq_printf(s, "SYSCTL:\t\t0x%08x\n",
  1632. OMAP_HSMMC_READ(host->base, SYSCTL));
  1633. seq_printf(s, "IE:\t\t0x%08x\n",
  1634. OMAP_HSMMC_READ(host->base, IE));
  1635. seq_printf(s, "ISE:\t\t0x%08x\n",
  1636. OMAP_HSMMC_READ(host->base, ISE));
  1637. seq_printf(s, "CAPA:\t\t0x%08x\n",
  1638. OMAP_HSMMC_READ(host->base, CAPA));
  1639. clk_disable(host->fclk);
  1640. return 0;
  1641. }
  1642. static int omap_hsmmc_regs_open(struct inode *inode, struct file *file)
  1643. {
  1644. return single_open(file, omap_hsmmc_regs_show, inode->i_private);
  1645. }
  1646. static const struct file_operations mmc_regs_fops = {
  1647. .open = omap_hsmmc_regs_open,
  1648. .read = seq_read,
  1649. .llseek = seq_lseek,
  1650. .release = single_release,
  1651. };
  1652. static void omap_hsmmc_debugfs(struct mmc_host *mmc)
  1653. {
  1654. if (mmc->debugfs_root)
  1655. debugfs_create_file("regs", S_IRUSR, mmc->debugfs_root,
  1656. mmc, &mmc_regs_fops);
  1657. }
  1658. #else
  1659. static void omap_hsmmc_debugfs(struct mmc_host *mmc)
  1660. {
  1661. }
  1662. #endif
  1663. static int __init omap_hsmmc_probe(struct platform_device *pdev)
  1664. {
  1665. struct omap_mmc_platform_data *pdata = pdev->dev.platform_data;
  1666. struct mmc_host *mmc;
  1667. struct omap_hsmmc_host *host = NULL;
  1668. struct resource *res;
  1669. int ret, irq;
  1670. if (pdata == NULL) {
  1671. dev_err(&pdev->dev, "Platform Data is missing\n");
  1672. return -ENXIO;
  1673. }
  1674. if (pdata->nr_slots == 0) {
  1675. dev_err(&pdev->dev, "No Slots\n");
  1676. return -ENXIO;
  1677. }
  1678. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1679. irq = platform_get_irq(pdev, 0);
  1680. if (res == NULL || irq < 0)
  1681. return -ENXIO;
  1682. res = request_mem_region(res->start, res->end - res->start + 1,
  1683. pdev->name);
  1684. if (res == NULL)
  1685. return -EBUSY;
  1686. ret = omap_hsmmc_gpio_init(pdata);
  1687. if (ret)
  1688. goto err;
  1689. mmc = mmc_alloc_host(sizeof(struct omap_hsmmc_host), &pdev->dev);
  1690. if (!mmc) {
  1691. ret = -ENOMEM;
  1692. goto err_alloc;
  1693. }
  1694. host = mmc_priv(mmc);
  1695. host->mmc = mmc;
  1696. host->pdata = pdata;
  1697. host->dev = &pdev->dev;
  1698. host->use_dma = 1;
  1699. host->dev->dma_mask = &pdata->dma_mask;
  1700. host->dma_ch = -1;
  1701. host->irq = irq;
  1702. host->id = pdev->id;
  1703. host->slot_id = 0;
  1704. host->mapbase = res->start;
  1705. host->base = ioremap(host->mapbase, SZ_4K);
  1706. host->power_mode = MMC_POWER_OFF;
  1707. platform_set_drvdata(pdev, host);
  1708. INIT_WORK(&host->mmc_carddetect_work, omap_hsmmc_detect);
  1709. if (mmc_slot(host).power_saving)
  1710. mmc->ops = &omap_hsmmc_ps_ops;
  1711. else
  1712. mmc->ops = &omap_hsmmc_ops;
  1713. /*
  1714. * If regulator_disable can only put vcc_aux to sleep then there is
  1715. * no off state.
  1716. */
  1717. if (mmc_slot(host).vcc_aux_disable_is_sleep)
  1718. mmc_slot(host).no_off = 1;
  1719. mmc->f_min = 400000;
  1720. mmc->f_max = 52000000;
  1721. sema_init(&host->sem, 1);
  1722. spin_lock_init(&host->irq_lock);
  1723. host->iclk = clk_get(&pdev->dev, "ick");
  1724. if (IS_ERR(host->iclk)) {
  1725. ret = PTR_ERR(host->iclk);
  1726. host->iclk = NULL;
  1727. goto err1;
  1728. }
  1729. host->fclk = clk_get(&pdev->dev, "fck");
  1730. if (IS_ERR(host->fclk)) {
  1731. ret = PTR_ERR(host->fclk);
  1732. host->fclk = NULL;
  1733. clk_put(host->iclk);
  1734. goto err1;
  1735. }
  1736. omap_hsmmc_context_save(host);
  1737. mmc->caps |= MMC_CAP_DISABLE;
  1738. mmc_set_disable_delay(mmc, OMAP_MMC_DISABLED_TIMEOUT);
  1739. /* we start off in DISABLED state */
  1740. host->dpm_state = DISABLED;
  1741. if (mmc_host_enable(host->mmc) != 0) {
  1742. clk_put(host->iclk);
  1743. clk_put(host->fclk);
  1744. goto err1;
  1745. }
  1746. if (clk_enable(host->iclk) != 0) {
  1747. mmc_host_disable(host->mmc);
  1748. clk_put(host->iclk);
  1749. clk_put(host->fclk);
  1750. goto err1;
  1751. }
  1752. if (cpu_is_omap2430()) {
  1753. host->dbclk = clk_get(&pdev->dev, "mmchsdb_fck");
  1754. /*
  1755. * MMC can still work without debounce clock.
  1756. */
  1757. if (IS_ERR(host->dbclk))
  1758. dev_warn(mmc_dev(host->mmc),
  1759. "Failed to get debounce clock\n");
  1760. else
  1761. host->got_dbclk = 1;
  1762. if (host->got_dbclk)
  1763. if (clk_enable(host->dbclk) != 0)
  1764. dev_dbg(mmc_dev(host->mmc), "Enabling debounce"
  1765. " clk failed\n");
  1766. }
  1767. /* Since we do only SG emulation, we can have as many segs
  1768. * as we want. */
  1769. mmc->max_phys_segs = 1024;
  1770. mmc->max_hw_segs = 1024;
  1771. mmc->max_blk_size = 512; /* Block Length at max can be 1024 */
  1772. mmc->max_blk_count = 0xFFFF; /* No. of Blocks is 16 bits */
  1773. mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
  1774. mmc->max_seg_size = mmc->max_req_size;
  1775. mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
  1776. MMC_CAP_WAIT_WHILE_BUSY;
  1777. if (mmc_slot(host).wires >= 8)
  1778. mmc->caps |= MMC_CAP_8_BIT_DATA;
  1779. else if (mmc_slot(host).wires >= 4)
  1780. mmc->caps |= MMC_CAP_4_BIT_DATA;
  1781. if (mmc_slot(host).nonremovable)
  1782. mmc->caps |= MMC_CAP_NONREMOVABLE;
  1783. omap_hsmmc_conf_bus_power(host);
  1784. /* Select DMA lines */
  1785. switch (host->id) {
  1786. case OMAP_MMC1_DEVID:
  1787. host->dma_line_tx = OMAP24XX_DMA_MMC1_TX;
  1788. host->dma_line_rx = OMAP24XX_DMA_MMC1_RX;
  1789. break;
  1790. case OMAP_MMC2_DEVID:
  1791. host->dma_line_tx = OMAP24XX_DMA_MMC2_TX;
  1792. host->dma_line_rx = OMAP24XX_DMA_MMC2_RX;
  1793. break;
  1794. case OMAP_MMC3_DEVID:
  1795. host->dma_line_tx = OMAP34XX_DMA_MMC3_TX;
  1796. host->dma_line_rx = OMAP34XX_DMA_MMC3_RX;
  1797. break;
  1798. case OMAP_MMC4_DEVID:
  1799. host->dma_line_tx = OMAP44XX_DMA_MMC4_TX;
  1800. host->dma_line_rx = OMAP44XX_DMA_MMC4_RX;
  1801. break;
  1802. case OMAP_MMC5_DEVID:
  1803. host->dma_line_tx = OMAP44XX_DMA_MMC5_TX;
  1804. host->dma_line_rx = OMAP44XX_DMA_MMC5_RX;
  1805. break;
  1806. default:
  1807. dev_err(mmc_dev(host->mmc), "Invalid MMC id\n");
  1808. goto err_irq;
  1809. }
  1810. /* Request IRQ for MMC operations */
  1811. ret = request_irq(host->irq, omap_hsmmc_irq, IRQF_DISABLED,
  1812. mmc_hostname(mmc), host);
  1813. if (ret) {
  1814. dev_dbg(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n");
  1815. goto err_irq;
  1816. }
  1817. if (pdata->init != NULL) {
  1818. if (pdata->init(&pdev->dev) != 0) {
  1819. dev_dbg(mmc_dev(host->mmc),
  1820. "Unable to configure MMC IRQs\n");
  1821. goto err_irq_cd_init;
  1822. }
  1823. }
  1824. if (omap_hsmmc_have_reg() && !mmc_slot(host).set_power) {
  1825. ret = omap_hsmmc_reg_get(host);
  1826. if (ret)
  1827. goto err_reg;
  1828. host->use_reg = 1;
  1829. }
  1830. mmc->ocr_avail = mmc_slot(host).ocr_mask;
  1831. /* Request IRQ for card detect */
  1832. if ((mmc_slot(host).card_detect_irq)) {
  1833. ret = request_irq(mmc_slot(host).card_detect_irq,
  1834. omap_hsmmc_cd_handler,
  1835. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
  1836. | IRQF_DISABLED,
  1837. mmc_hostname(mmc), host);
  1838. if (ret) {
  1839. dev_dbg(mmc_dev(host->mmc),
  1840. "Unable to grab MMC CD IRQ\n");
  1841. goto err_irq_cd;
  1842. }
  1843. }
  1844. OMAP_HSMMC_WRITE(host->base, ISE, INT_EN_MASK);
  1845. OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
  1846. mmc_host_lazy_disable(host->mmc);
  1847. omap_hsmmc_protect_card(host);
  1848. mmc_add_host(mmc);
  1849. if (mmc_slot(host).name != NULL) {
  1850. ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name);
  1851. if (ret < 0)
  1852. goto err_slot_name;
  1853. }
  1854. if (mmc_slot(host).card_detect_irq && mmc_slot(host).get_cover_state) {
  1855. ret = device_create_file(&mmc->class_dev,
  1856. &dev_attr_cover_switch);
  1857. if (ret < 0)
  1858. goto err_slot_name;
  1859. }
  1860. omap_hsmmc_debugfs(mmc);
  1861. return 0;
  1862. err_slot_name:
  1863. mmc_remove_host(mmc);
  1864. free_irq(mmc_slot(host).card_detect_irq, host);
  1865. err_irq_cd:
  1866. if (host->use_reg)
  1867. omap_hsmmc_reg_put(host);
  1868. err_reg:
  1869. if (host->pdata->cleanup)
  1870. host->pdata->cleanup(&pdev->dev);
  1871. err_irq_cd_init:
  1872. free_irq(host->irq, host);
  1873. err_irq:
  1874. mmc_host_disable(host->mmc);
  1875. clk_disable(host->iclk);
  1876. clk_put(host->fclk);
  1877. clk_put(host->iclk);
  1878. if (host->got_dbclk) {
  1879. clk_disable(host->dbclk);
  1880. clk_put(host->dbclk);
  1881. }
  1882. err1:
  1883. iounmap(host->base);
  1884. platform_set_drvdata(pdev, NULL);
  1885. mmc_free_host(mmc);
  1886. err_alloc:
  1887. omap_hsmmc_gpio_free(pdata);
  1888. err:
  1889. release_mem_region(res->start, res->end - res->start + 1);
  1890. return ret;
  1891. }
  1892. static int omap_hsmmc_remove(struct platform_device *pdev)
  1893. {
  1894. struct omap_hsmmc_host *host = platform_get_drvdata(pdev);
  1895. struct resource *res;
  1896. if (host) {
  1897. mmc_host_enable(host->mmc);
  1898. mmc_remove_host(host->mmc);
  1899. if (host->use_reg)
  1900. omap_hsmmc_reg_put(host);
  1901. if (host->pdata->cleanup)
  1902. host->pdata->cleanup(&pdev->dev);
  1903. free_irq(host->irq, host);
  1904. if (mmc_slot(host).card_detect_irq)
  1905. free_irq(mmc_slot(host).card_detect_irq, host);
  1906. flush_scheduled_work();
  1907. mmc_host_disable(host->mmc);
  1908. clk_disable(host->iclk);
  1909. clk_put(host->fclk);
  1910. clk_put(host->iclk);
  1911. if (host->got_dbclk) {
  1912. clk_disable(host->dbclk);
  1913. clk_put(host->dbclk);
  1914. }
  1915. mmc_free_host(host->mmc);
  1916. iounmap(host->base);
  1917. omap_hsmmc_gpio_free(pdev->dev.platform_data);
  1918. }
  1919. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1920. if (res)
  1921. release_mem_region(res->start, res->end - res->start + 1);
  1922. platform_set_drvdata(pdev, NULL);
  1923. return 0;
  1924. }
  1925. #ifdef CONFIG_PM
  1926. static int omap_hsmmc_suspend(struct platform_device *pdev, pm_message_t state)
  1927. {
  1928. int ret = 0;
  1929. struct omap_hsmmc_host *host = platform_get_drvdata(pdev);
  1930. if (host && host->suspended)
  1931. return 0;
  1932. if (host) {
  1933. host->suspended = 1;
  1934. if (host->pdata->suspend) {
  1935. ret = host->pdata->suspend(&pdev->dev,
  1936. host->slot_id);
  1937. if (ret) {
  1938. dev_dbg(mmc_dev(host->mmc),
  1939. "Unable to handle MMC board"
  1940. " level suspend\n");
  1941. host->suspended = 0;
  1942. return ret;
  1943. }
  1944. }
  1945. cancel_work_sync(&host->mmc_carddetect_work);
  1946. mmc_host_enable(host->mmc);
  1947. ret = mmc_suspend_host(host->mmc, state);
  1948. if (ret == 0) {
  1949. OMAP_HSMMC_WRITE(host->base, ISE, 0);
  1950. OMAP_HSMMC_WRITE(host->base, IE, 0);
  1951. OMAP_HSMMC_WRITE(host->base, HCTL,
  1952. OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP);
  1953. mmc_host_disable(host->mmc);
  1954. clk_disable(host->iclk);
  1955. if (host->got_dbclk)
  1956. clk_disable(host->dbclk);
  1957. } else {
  1958. host->suspended = 0;
  1959. if (host->pdata->resume) {
  1960. ret = host->pdata->resume(&pdev->dev,
  1961. host->slot_id);
  1962. if (ret)
  1963. dev_dbg(mmc_dev(host->mmc),
  1964. "Unmask interrupt failed\n");
  1965. }
  1966. mmc_host_disable(host->mmc);
  1967. }
  1968. }
  1969. return ret;
  1970. }
  1971. /* Routine to resume the MMC device */
  1972. static int omap_hsmmc_resume(struct platform_device *pdev)
  1973. {
  1974. int ret = 0;
  1975. struct omap_hsmmc_host *host = platform_get_drvdata(pdev);
  1976. if (host && !host->suspended)
  1977. return 0;
  1978. if (host) {
  1979. ret = clk_enable(host->iclk);
  1980. if (ret)
  1981. goto clk_en_err;
  1982. if (mmc_host_enable(host->mmc) != 0) {
  1983. clk_disable(host->iclk);
  1984. goto clk_en_err;
  1985. }
  1986. if (host->got_dbclk)
  1987. clk_enable(host->dbclk);
  1988. omap_hsmmc_conf_bus_power(host);
  1989. if (host->pdata->resume) {
  1990. ret = host->pdata->resume(&pdev->dev, host->slot_id);
  1991. if (ret)
  1992. dev_dbg(mmc_dev(host->mmc),
  1993. "Unmask interrupt failed\n");
  1994. }
  1995. omap_hsmmc_protect_card(host);
  1996. /* Notify the core to resume the host */
  1997. ret = mmc_resume_host(host->mmc);
  1998. if (ret == 0)
  1999. host->suspended = 0;
  2000. mmc_host_lazy_disable(host->mmc);
  2001. }
  2002. return ret;
  2003. clk_en_err:
  2004. dev_dbg(mmc_dev(host->mmc),
  2005. "Failed to enable MMC clocks during resume\n");
  2006. return ret;
  2007. }
  2008. #else
  2009. #define omap_hsmmc_suspend NULL
  2010. #define omap_hsmmc_resume NULL
  2011. #endif
  2012. static struct platform_driver omap_hsmmc_driver = {
  2013. .remove = omap_hsmmc_remove,
  2014. .suspend = omap_hsmmc_suspend,
  2015. .resume = omap_hsmmc_resume,
  2016. .driver = {
  2017. .name = DRIVER_NAME,
  2018. .owner = THIS_MODULE,
  2019. },
  2020. };
  2021. static int __init omap_hsmmc_init(void)
  2022. {
  2023. /* Register the MMC driver */
  2024. return platform_driver_probe(&omap_hsmmc_driver, omap_hsmmc_probe);
  2025. }
  2026. static void __exit omap_hsmmc_cleanup(void)
  2027. {
  2028. /* Unregister MMC driver */
  2029. platform_driver_unregister(&omap_hsmmc_driver);
  2030. }
  2031. module_init(omap_hsmmc_init);
  2032. module_exit(omap_hsmmc_cleanup);
  2033. MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver");
  2034. MODULE_LICENSE("GPL");
  2035. MODULE_ALIAS("platform:" DRIVER_NAME);
  2036. MODULE_AUTHOR("Texas Instruments Inc");