omap_hsmmc.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394
  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_detect_change(host->mmc, (HZ * 50) / 1000);
  1016. }
  1017. /*
  1018. * ISR for handling card insertion and removal
  1019. */
  1020. static irqreturn_t omap_hsmmc_cd_handler(int irq, void *dev_id)
  1021. {
  1022. struct omap_hsmmc_host *host = (struct omap_hsmmc_host *)dev_id;
  1023. if (host->suspended)
  1024. return IRQ_HANDLED;
  1025. schedule_work(&host->mmc_carddetect_work);
  1026. return IRQ_HANDLED;
  1027. }
  1028. static int omap_hsmmc_get_dma_sync_dev(struct omap_hsmmc_host *host,
  1029. struct mmc_data *data)
  1030. {
  1031. int sync_dev;
  1032. if (data->flags & MMC_DATA_WRITE)
  1033. sync_dev = host->dma_line_tx;
  1034. else
  1035. sync_dev = host->dma_line_rx;
  1036. return sync_dev;
  1037. }
  1038. static void omap_hsmmc_config_dma_params(struct omap_hsmmc_host *host,
  1039. struct mmc_data *data,
  1040. struct scatterlist *sgl)
  1041. {
  1042. int blksz, nblk, dma_ch;
  1043. dma_ch = host->dma_ch;
  1044. if (data->flags & MMC_DATA_WRITE) {
  1045. omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
  1046. (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
  1047. omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
  1048. sg_dma_address(sgl), 0, 0);
  1049. } else {
  1050. omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
  1051. (host->mapbase + OMAP_HSMMC_DATA), 0, 0);
  1052. omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
  1053. sg_dma_address(sgl), 0, 0);
  1054. }
  1055. blksz = host->data->blksz;
  1056. nblk = sg_dma_len(sgl) / blksz;
  1057. omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S32,
  1058. blksz / 4, nblk, OMAP_DMA_SYNC_FRAME,
  1059. omap_hsmmc_get_dma_sync_dev(host, data),
  1060. !(data->flags & MMC_DATA_WRITE));
  1061. omap_start_dma(dma_ch);
  1062. }
  1063. /*
  1064. * DMA call back function
  1065. */
  1066. static void omap_hsmmc_dma_cb(int lch, u16 ch_status, void *data)
  1067. {
  1068. struct omap_hsmmc_host *host = data;
  1069. if (ch_status & OMAP2_DMA_MISALIGNED_ERR_IRQ)
  1070. dev_dbg(mmc_dev(host->mmc), "MISALIGNED_ADRS_ERR\n");
  1071. if (host->dma_ch < 0)
  1072. return;
  1073. host->dma_sg_idx++;
  1074. if (host->dma_sg_idx < host->dma_len) {
  1075. /* Fire up the next transfer. */
  1076. omap_hsmmc_config_dma_params(host, host->data,
  1077. host->data->sg + host->dma_sg_idx);
  1078. return;
  1079. }
  1080. omap_free_dma(host->dma_ch);
  1081. host->dma_ch = -1;
  1082. /*
  1083. * DMA Callback: run in interrupt context.
  1084. * mutex_unlock will throw a kernel warning if used.
  1085. */
  1086. up(&host->sem);
  1087. }
  1088. /*
  1089. * Routine to configure and start DMA for the MMC card
  1090. */
  1091. static int omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host,
  1092. struct mmc_request *req)
  1093. {
  1094. int dma_ch = 0, ret = 0, err = 1, i;
  1095. struct mmc_data *data = req->data;
  1096. /* Sanity check: all the SG entries must be aligned by block size. */
  1097. for (i = 0; i < data->sg_len; i++) {
  1098. struct scatterlist *sgl;
  1099. sgl = data->sg + i;
  1100. if (sgl->length % data->blksz)
  1101. return -EINVAL;
  1102. }
  1103. if ((data->blksz % 4) != 0)
  1104. /* REVISIT: The MMC buffer increments only when MSB is written.
  1105. * Return error for blksz which is non multiple of four.
  1106. */
  1107. return -EINVAL;
  1108. /*
  1109. * If for some reason the DMA transfer is still active,
  1110. * we wait for timeout period and free the dma
  1111. */
  1112. if (host->dma_ch != -1) {
  1113. set_current_state(TASK_UNINTERRUPTIBLE);
  1114. schedule_timeout(100);
  1115. if (down_trylock(&host->sem)) {
  1116. omap_free_dma(host->dma_ch);
  1117. host->dma_ch = -1;
  1118. up(&host->sem);
  1119. return err;
  1120. }
  1121. } else {
  1122. if (down_trylock(&host->sem))
  1123. return err;
  1124. }
  1125. ret = omap_request_dma(omap_hsmmc_get_dma_sync_dev(host, data),
  1126. "MMC/SD", omap_hsmmc_dma_cb, host, &dma_ch);
  1127. if (ret != 0) {
  1128. dev_err(mmc_dev(host->mmc),
  1129. "%s: omap_request_dma() failed with %d\n",
  1130. mmc_hostname(host->mmc), ret);
  1131. return ret;
  1132. }
  1133. host->dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg,
  1134. data->sg_len, omap_hsmmc_get_dma_dir(host, data));
  1135. host->dma_ch = dma_ch;
  1136. host->dma_sg_idx = 0;
  1137. omap_hsmmc_config_dma_params(host, data, data->sg);
  1138. return 0;
  1139. }
  1140. static void set_data_timeout(struct omap_hsmmc_host *host,
  1141. unsigned int timeout_ns,
  1142. unsigned int timeout_clks)
  1143. {
  1144. unsigned int timeout, cycle_ns;
  1145. uint32_t reg, clkd, dto = 0;
  1146. reg = OMAP_HSMMC_READ(host->base, SYSCTL);
  1147. clkd = (reg & CLKD_MASK) >> CLKD_SHIFT;
  1148. if (clkd == 0)
  1149. clkd = 1;
  1150. cycle_ns = 1000000000 / (clk_get_rate(host->fclk) / clkd);
  1151. timeout = timeout_ns / cycle_ns;
  1152. timeout += timeout_clks;
  1153. if (timeout) {
  1154. while ((timeout & 0x80000000) == 0) {
  1155. dto += 1;
  1156. timeout <<= 1;
  1157. }
  1158. dto = 31 - dto;
  1159. timeout <<= 1;
  1160. if (timeout && dto)
  1161. dto += 1;
  1162. if (dto >= 13)
  1163. dto -= 13;
  1164. else
  1165. dto = 0;
  1166. if (dto > 14)
  1167. dto = 14;
  1168. }
  1169. reg &= ~DTO_MASK;
  1170. reg |= dto << DTO_SHIFT;
  1171. OMAP_HSMMC_WRITE(host->base, SYSCTL, reg);
  1172. }
  1173. /*
  1174. * Configure block length for MMC/SD cards and initiate the transfer.
  1175. */
  1176. static int
  1177. omap_hsmmc_prepare_data(struct omap_hsmmc_host *host, struct mmc_request *req)
  1178. {
  1179. int ret;
  1180. host->data = req->data;
  1181. if (req->data == NULL) {
  1182. OMAP_HSMMC_WRITE(host->base, BLK, 0);
  1183. /*
  1184. * Set an arbitrary 100ms data timeout for commands with
  1185. * busy signal.
  1186. */
  1187. if (req->cmd->flags & MMC_RSP_BUSY)
  1188. set_data_timeout(host, 100000000U, 0);
  1189. return 0;
  1190. }
  1191. OMAP_HSMMC_WRITE(host->base, BLK, (req->data->blksz)
  1192. | (req->data->blocks << 16));
  1193. set_data_timeout(host, req->data->timeout_ns, req->data->timeout_clks);
  1194. if (host->use_dma) {
  1195. ret = omap_hsmmc_start_dma_transfer(host, req);
  1196. if (ret != 0) {
  1197. dev_dbg(mmc_dev(host->mmc), "MMC start dma failure\n");
  1198. return ret;
  1199. }
  1200. }
  1201. return 0;
  1202. }
  1203. /*
  1204. * Request function. for read/write operation
  1205. */
  1206. static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req)
  1207. {
  1208. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1209. int err;
  1210. /*
  1211. * Prevent races with the interrupt handler because of unexpected
  1212. * interrupts, but not if we are already in interrupt context i.e.
  1213. * retries.
  1214. */
  1215. if (!in_interrupt()) {
  1216. spin_lock_irqsave(&host->irq_lock, host->flags);
  1217. /*
  1218. * Protect the card from I/O if there is a possibility
  1219. * it can be removed.
  1220. */
  1221. if (host->protect_card) {
  1222. if (host->reqs_blocked < 3) {
  1223. /*
  1224. * Ensure the controller is left in a consistent
  1225. * state by resetting the command and data state
  1226. * machines.
  1227. */
  1228. omap_hsmmc_reset_controller_fsm(host, SRD);
  1229. omap_hsmmc_reset_controller_fsm(host, SRC);
  1230. host->reqs_blocked += 1;
  1231. }
  1232. req->cmd->error = -EBADF;
  1233. if (req->data)
  1234. req->data->error = -EBADF;
  1235. spin_unlock_irqrestore(&host->irq_lock, host->flags);
  1236. mmc_request_done(mmc, req);
  1237. return;
  1238. } else if (host->reqs_blocked)
  1239. host->reqs_blocked = 0;
  1240. }
  1241. WARN_ON(host->mrq != NULL);
  1242. host->mrq = req;
  1243. err = omap_hsmmc_prepare_data(host, req);
  1244. if (err) {
  1245. req->cmd->error = err;
  1246. if (req->data)
  1247. req->data->error = err;
  1248. host->mrq = NULL;
  1249. if (!in_interrupt())
  1250. spin_unlock_irqrestore(&host->irq_lock, host->flags);
  1251. mmc_request_done(mmc, req);
  1252. return;
  1253. }
  1254. omap_hsmmc_start_command(host, req->cmd, req->data);
  1255. }
  1256. /* Routine to configure clock values. Exposed API to core */
  1257. static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  1258. {
  1259. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1260. u16 dsor = 0;
  1261. unsigned long regval;
  1262. unsigned long timeout;
  1263. u32 con;
  1264. int do_send_init_stream = 0;
  1265. mmc_host_enable(host->mmc);
  1266. if (ios->power_mode != host->power_mode) {
  1267. switch (ios->power_mode) {
  1268. case MMC_POWER_OFF:
  1269. mmc_slot(host).set_power(host->dev, host->slot_id,
  1270. 0, 0);
  1271. host->vdd = 0;
  1272. break;
  1273. case MMC_POWER_UP:
  1274. mmc_slot(host).set_power(host->dev, host->slot_id,
  1275. 1, ios->vdd);
  1276. host->vdd = ios->vdd;
  1277. break;
  1278. case MMC_POWER_ON:
  1279. do_send_init_stream = 1;
  1280. break;
  1281. }
  1282. host->power_mode = ios->power_mode;
  1283. }
  1284. /* FIXME: set registers based only on changes to ios */
  1285. con = OMAP_HSMMC_READ(host->base, CON);
  1286. switch (mmc->ios.bus_width) {
  1287. case MMC_BUS_WIDTH_8:
  1288. OMAP_HSMMC_WRITE(host->base, CON, con | DW8);
  1289. break;
  1290. case MMC_BUS_WIDTH_4:
  1291. OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
  1292. OMAP_HSMMC_WRITE(host->base, HCTL,
  1293. OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT);
  1294. break;
  1295. case MMC_BUS_WIDTH_1:
  1296. OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
  1297. OMAP_HSMMC_WRITE(host->base, HCTL,
  1298. OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT);
  1299. break;
  1300. }
  1301. if (host->id == OMAP_MMC1_DEVID) {
  1302. /* Only MMC1 can interface at 3V without some flavor
  1303. * of external transceiver; but they all handle 1.8V.
  1304. */
  1305. if ((OMAP_HSMMC_READ(host->base, HCTL) & SDVSDET) &&
  1306. (ios->vdd == DUAL_VOLT_OCR_BIT)) {
  1307. /*
  1308. * The mmc_select_voltage fn of the core does
  1309. * not seem to set the power_mode to
  1310. * MMC_POWER_UP upon recalculating the voltage.
  1311. * vdd 1.8v.
  1312. */
  1313. if (omap_hsmmc_switch_opcond(host, ios->vdd) != 0)
  1314. dev_dbg(mmc_dev(host->mmc),
  1315. "Switch operation failed\n");
  1316. }
  1317. }
  1318. if (ios->clock) {
  1319. dsor = OMAP_MMC_MASTER_CLOCK / ios->clock;
  1320. if (dsor < 1)
  1321. dsor = 1;
  1322. if (OMAP_MMC_MASTER_CLOCK / dsor > ios->clock)
  1323. dsor++;
  1324. if (dsor > 250)
  1325. dsor = 250;
  1326. }
  1327. omap_hsmmc_stop_clock(host);
  1328. regval = OMAP_HSMMC_READ(host->base, SYSCTL);
  1329. regval = regval & ~(CLKD_MASK);
  1330. regval = regval | (dsor << 6) | (DTO << 16);
  1331. OMAP_HSMMC_WRITE(host->base, SYSCTL, regval);
  1332. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  1333. OMAP_HSMMC_READ(host->base, SYSCTL) | ICE);
  1334. /* Wait till the ICS bit is set */
  1335. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  1336. while ((OMAP_HSMMC_READ(host->base, SYSCTL) & ICS) != ICS
  1337. && time_before(jiffies, timeout))
  1338. msleep(1);
  1339. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  1340. OMAP_HSMMC_READ(host->base, SYSCTL) | CEN);
  1341. if (do_send_init_stream)
  1342. send_init_stream(host);
  1343. con = OMAP_HSMMC_READ(host->base, CON);
  1344. if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
  1345. OMAP_HSMMC_WRITE(host->base, CON, con | OD);
  1346. else
  1347. OMAP_HSMMC_WRITE(host->base, CON, con & ~OD);
  1348. if (host->power_mode == MMC_POWER_OFF)
  1349. mmc_host_disable(host->mmc);
  1350. else
  1351. mmc_host_lazy_disable(host->mmc);
  1352. }
  1353. static int omap_hsmmc_get_cd(struct mmc_host *mmc)
  1354. {
  1355. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1356. if (!mmc_slot(host).card_detect)
  1357. return -ENOSYS;
  1358. return mmc_slot(host).card_detect(host->dev, host->slot_id);
  1359. }
  1360. static int omap_hsmmc_get_ro(struct mmc_host *mmc)
  1361. {
  1362. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1363. if (!mmc_slot(host).get_ro)
  1364. return -ENOSYS;
  1365. return mmc_slot(host).get_ro(host->dev, 0);
  1366. }
  1367. static void omap_hsmmc_conf_bus_power(struct omap_hsmmc_host *host)
  1368. {
  1369. u32 hctl, capa, value;
  1370. /* Only MMC1 supports 3.0V */
  1371. if (host->id == OMAP_MMC1_DEVID) {
  1372. hctl = SDVS30;
  1373. capa = VS30 | VS18;
  1374. } else {
  1375. hctl = SDVS18;
  1376. capa = VS18;
  1377. }
  1378. value = OMAP_HSMMC_READ(host->base, HCTL) & ~SDVS_MASK;
  1379. OMAP_HSMMC_WRITE(host->base, HCTL, value | hctl);
  1380. value = OMAP_HSMMC_READ(host->base, CAPA);
  1381. OMAP_HSMMC_WRITE(host->base, CAPA, value | capa);
  1382. /* Set the controller to AUTO IDLE mode */
  1383. value = OMAP_HSMMC_READ(host->base, SYSCONFIG);
  1384. OMAP_HSMMC_WRITE(host->base, SYSCONFIG, value | AUTOIDLE);
  1385. /* Set SD bus power bit */
  1386. set_sd_bus_power(host);
  1387. }
  1388. /*
  1389. * Dynamic power saving handling, FSM:
  1390. * ENABLED -> DISABLED -> CARDSLEEP / REGSLEEP -> OFF
  1391. * ^___________| | |
  1392. * |______________________|______________________|
  1393. *
  1394. * ENABLED: mmc host is fully functional
  1395. * DISABLED: fclk is off
  1396. * CARDSLEEP: fclk is off, card is asleep, voltage regulator is asleep
  1397. * REGSLEEP: fclk is off, voltage regulator is asleep
  1398. * OFF: fclk is off, voltage regulator is off
  1399. *
  1400. * Transition handlers return the timeout for the next state transition
  1401. * or negative error.
  1402. */
  1403. enum {ENABLED = 0, DISABLED, CARDSLEEP, REGSLEEP, OFF};
  1404. /* Handler for [ENABLED -> DISABLED] transition */
  1405. static int omap_hsmmc_enabled_to_disabled(struct omap_hsmmc_host *host)
  1406. {
  1407. omap_hsmmc_context_save(host);
  1408. clk_disable(host->fclk);
  1409. host->dpm_state = DISABLED;
  1410. dev_dbg(mmc_dev(host->mmc), "ENABLED -> DISABLED\n");
  1411. if (host->power_mode == MMC_POWER_OFF)
  1412. return 0;
  1413. return OMAP_MMC_SLEEP_TIMEOUT;
  1414. }
  1415. /* Handler for [DISABLED -> REGSLEEP / CARDSLEEP] transition */
  1416. static int omap_hsmmc_disabled_to_sleep(struct omap_hsmmc_host *host)
  1417. {
  1418. int err, new_state;
  1419. if (!mmc_try_claim_host(host->mmc))
  1420. return 0;
  1421. clk_enable(host->fclk);
  1422. omap_hsmmc_context_restore(host);
  1423. if (mmc_card_can_sleep(host->mmc)) {
  1424. err = mmc_card_sleep(host->mmc);
  1425. if (err < 0) {
  1426. clk_disable(host->fclk);
  1427. mmc_release_host(host->mmc);
  1428. return err;
  1429. }
  1430. new_state = CARDSLEEP;
  1431. } else {
  1432. new_state = REGSLEEP;
  1433. }
  1434. if (mmc_slot(host).set_sleep)
  1435. mmc_slot(host).set_sleep(host->dev, host->slot_id, 1, 0,
  1436. new_state == CARDSLEEP);
  1437. /* FIXME: turn off bus power and perhaps interrupts too */
  1438. clk_disable(host->fclk);
  1439. host->dpm_state = new_state;
  1440. mmc_release_host(host->mmc);
  1441. dev_dbg(mmc_dev(host->mmc), "DISABLED -> %s\n",
  1442. host->dpm_state == CARDSLEEP ? "CARDSLEEP" : "REGSLEEP");
  1443. if (mmc_slot(host).no_off)
  1444. return 0;
  1445. if ((host->mmc->caps & MMC_CAP_NONREMOVABLE) ||
  1446. mmc_slot(host).card_detect ||
  1447. (mmc_slot(host).get_cover_state &&
  1448. mmc_slot(host).get_cover_state(host->dev, host->slot_id)))
  1449. return OMAP_MMC_OFF_TIMEOUT;
  1450. return 0;
  1451. }
  1452. /* Handler for [REGSLEEP / CARDSLEEP -> OFF] transition */
  1453. static int omap_hsmmc_sleep_to_off(struct omap_hsmmc_host *host)
  1454. {
  1455. if (!mmc_try_claim_host(host->mmc))
  1456. return 0;
  1457. if (mmc_slot(host).no_off)
  1458. return 0;
  1459. if (!((host->mmc->caps & MMC_CAP_NONREMOVABLE) ||
  1460. mmc_slot(host).card_detect ||
  1461. (mmc_slot(host).get_cover_state &&
  1462. mmc_slot(host).get_cover_state(host->dev, host->slot_id)))) {
  1463. mmc_release_host(host->mmc);
  1464. return 0;
  1465. }
  1466. mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0);
  1467. host->vdd = 0;
  1468. host->power_mode = MMC_POWER_OFF;
  1469. dev_dbg(mmc_dev(host->mmc), "%s -> OFF\n",
  1470. host->dpm_state == CARDSLEEP ? "CARDSLEEP" : "REGSLEEP");
  1471. host->dpm_state = OFF;
  1472. mmc_release_host(host->mmc);
  1473. return 0;
  1474. }
  1475. /* Handler for [DISABLED -> ENABLED] transition */
  1476. static int omap_hsmmc_disabled_to_enabled(struct omap_hsmmc_host *host)
  1477. {
  1478. int err;
  1479. err = clk_enable(host->fclk);
  1480. if (err < 0)
  1481. return err;
  1482. omap_hsmmc_context_restore(host);
  1483. host->dpm_state = ENABLED;
  1484. dev_dbg(mmc_dev(host->mmc), "DISABLED -> ENABLED\n");
  1485. return 0;
  1486. }
  1487. /* Handler for [SLEEP -> ENABLED] transition */
  1488. static int omap_hsmmc_sleep_to_enabled(struct omap_hsmmc_host *host)
  1489. {
  1490. if (!mmc_try_claim_host(host->mmc))
  1491. return 0;
  1492. clk_enable(host->fclk);
  1493. omap_hsmmc_context_restore(host);
  1494. if (mmc_slot(host).set_sleep)
  1495. mmc_slot(host).set_sleep(host->dev, host->slot_id, 0,
  1496. host->vdd, host->dpm_state == CARDSLEEP);
  1497. if (mmc_card_can_sleep(host->mmc))
  1498. mmc_card_awake(host->mmc);
  1499. dev_dbg(mmc_dev(host->mmc), "%s -> ENABLED\n",
  1500. host->dpm_state == CARDSLEEP ? "CARDSLEEP" : "REGSLEEP");
  1501. host->dpm_state = ENABLED;
  1502. mmc_release_host(host->mmc);
  1503. return 0;
  1504. }
  1505. /* Handler for [OFF -> ENABLED] transition */
  1506. static int omap_hsmmc_off_to_enabled(struct omap_hsmmc_host *host)
  1507. {
  1508. clk_enable(host->fclk);
  1509. omap_hsmmc_context_restore(host);
  1510. omap_hsmmc_conf_bus_power(host);
  1511. mmc_power_restore_host(host->mmc);
  1512. host->dpm_state = ENABLED;
  1513. dev_dbg(mmc_dev(host->mmc), "OFF -> ENABLED\n");
  1514. return 0;
  1515. }
  1516. /*
  1517. * Bring MMC host to ENABLED from any other PM state.
  1518. */
  1519. static int omap_hsmmc_enable(struct mmc_host *mmc)
  1520. {
  1521. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1522. switch (host->dpm_state) {
  1523. case DISABLED:
  1524. return omap_hsmmc_disabled_to_enabled(host);
  1525. case CARDSLEEP:
  1526. case REGSLEEP:
  1527. return omap_hsmmc_sleep_to_enabled(host);
  1528. case OFF:
  1529. return omap_hsmmc_off_to_enabled(host);
  1530. default:
  1531. dev_dbg(mmc_dev(host->mmc), "UNKNOWN state\n");
  1532. return -EINVAL;
  1533. }
  1534. }
  1535. /*
  1536. * Bring MMC host in PM state (one level deeper).
  1537. */
  1538. static int omap_hsmmc_disable(struct mmc_host *mmc, int lazy)
  1539. {
  1540. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1541. switch (host->dpm_state) {
  1542. case ENABLED: {
  1543. int delay;
  1544. delay = omap_hsmmc_enabled_to_disabled(host);
  1545. if (lazy || delay < 0)
  1546. return delay;
  1547. return 0;
  1548. }
  1549. case DISABLED:
  1550. return omap_hsmmc_disabled_to_sleep(host);
  1551. case CARDSLEEP:
  1552. case REGSLEEP:
  1553. return omap_hsmmc_sleep_to_off(host);
  1554. default:
  1555. dev_dbg(mmc_dev(host->mmc), "UNKNOWN state\n");
  1556. return -EINVAL;
  1557. }
  1558. }
  1559. static int omap_hsmmc_enable_fclk(struct mmc_host *mmc)
  1560. {
  1561. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1562. int err;
  1563. err = clk_enable(host->fclk);
  1564. if (err)
  1565. return err;
  1566. dev_dbg(mmc_dev(host->mmc), "mmc_fclk: enabled\n");
  1567. omap_hsmmc_context_restore(host);
  1568. return 0;
  1569. }
  1570. static int omap_hsmmc_disable_fclk(struct mmc_host *mmc, int lazy)
  1571. {
  1572. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1573. omap_hsmmc_context_save(host);
  1574. clk_disable(host->fclk);
  1575. dev_dbg(mmc_dev(host->mmc), "mmc_fclk: disabled\n");
  1576. return 0;
  1577. }
  1578. static const struct mmc_host_ops omap_hsmmc_ops = {
  1579. .enable = omap_hsmmc_enable_fclk,
  1580. .disable = omap_hsmmc_disable_fclk,
  1581. .request = omap_hsmmc_request,
  1582. .set_ios = omap_hsmmc_set_ios,
  1583. .get_cd = omap_hsmmc_get_cd,
  1584. .get_ro = omap_hsmmc_get_ro,
  1585. /* NYET -- enable_sdio_irq */
  1586. };
  1587. static const struct mmc_host_ops omap_hsmmc_ps_ops = {
  1588. .enable = omap_hsmmc_enable,
  1589. .disable = omap_hsmmc_disable,
  1590. .request = omap_hsmmc_request,
  1591. .set_ios = omap_hsmmc_set_ios,
  1592. .get_cd = omap_hsmmc_get_cd,
  1593. .get_ro = omap_hsmmc_get_ro,
  1594. /* NYET -- enable_sdio_irq */
  1595. };
  1596. #ifdef CONFIG_DEBUG_FS
  1597. static int omap_hsmmc_regs_show(struct seq_file *s, void *data)
  1598. {
  1599. struct mmc_host *mmc = s->private;
  1600. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1601. int context_loss = 0;
  1602. if (host->pdata->get_context_loss_count)
  1603. context_loss = host->pdata->get_context_loss_count(host->dev);
  1604. seq_printf(s, "mmc%d:\n"
  1605. " enabled:\t%d\n"
  1606. " dpm_state:\t%d\n"
  1607. " nesting_cnt:\t%d\n"
  1608. " ctx_loss:\t%d:%d\n"
  1609. "\nregs:\n",
  1610. mmc->index, mmc->enabled ? 1 : 0,
  1611. host->dpm_state, mmc->nesting_cnt,
  1612. host->context_loss, context_loss);
  1613. if (host->suspended || host->dpm_state == OFF) {
  1614. seq_printf(s, "host suspended, can't read registers\n");
  1615. return 0;
  1616. }
  1617. if (clk_enable(host->fclk) != 0) {
  1618. seq_printf(s, "can't read the regs\n");
  1619. return 0;
  1620. }
  1621. seq_printf(s, "SYSCONFIG:\t0x%08x\n",
  1622. OMAP_HSMMC_READ(host->base, SYSCONFIG));
  1623. seq_printf(s, "CON:\t\t0x%08x\n",
  1624. OMAP_HSMMC_READ(host->base, CON));
  1625. seq_printf(s, "HCTL:\t\t0x%08x\n",
  1626. OMAP_HSMMC_READ(host->base, HCTL));
  1627. seq_printf(s, "SYSCTL:\t\t0x%08x\n",
  1628. OMAP_HSMMC_READ(host->base, SYSCTL));
  1629. seq_printf(s, "IE:\t\t0x%08x\n",
  1630. OMAP_HSMMC_READ(host->base, IE));
  1631. seq_printf(s, "ISE:\t\t0x%08x\n",
  1632. OMAP_HSMMC_READ(host->base, ISE));
  1633. seq_printf(s, "CAPA:\t\t0x%08x\n",
  1634. OMAP_HSMMC_READ(host->base, CAPA));
  1635. clk_disable(host->fclk);
  1636. return 0;
  1637. }
  1638. static int omap_hsmmc_regs_open(struct inode *inode, struct file *file)
  1639. {
  1640. return single_open(file, omap_hsmmc_regs_show, inode->i_private);
  1641. }
  1642. static const struct file_operations mmc_regs_fops = {
  1643. .open = omap_hsmmc_regs_open,
  1644. .read = seq_read,
  1645. .llseek = seq_lseek,
  1646. .release = single_release,
  1647. };
  1648. static void omap_hsmmc_debugfs(struct mmc_host *mmc)
  1649. {
  1650. if (mmc->debugfs_root)
  1651. debugfs_create_file("regs", S_IRUSR, mmc->debugfs_root,
  1652. mmc, &mmc_regs_fops);
  1653. }
  1654. #else
  1655. static void omap_hsmmc_debugfs(struct mmc_host *mmc)
  1656. {
  1657. }
  1658. #endif
  1659. static int __init omap_hsmmc_probe(struct platform_device *pdev)
  1660. {
  1661. struct omap_mmc_platform_data *pdata = pdev->dev.platform_data;
  1662. struct mmc_host *mmc;
  1663. struct omap_hsmmc_host *host = NULL;
  1664. struct resource *res;
  1665. int ret, irq;
  1666. if (pdata == NULL) {
  1667. dev_err(&pdev->dev, "Platform Data is missing\n");
  1668. return -ENXIO;
  1669. }
  1670. if (pdata->nr_slots == 0) {
  1671. dev_err(&pdev->dev, "No Slots\n");
  1672. return -ENXIO;
  1673. }
  1674. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1675. irq = platform_get_irq(pdev, 0);
  1676. if (res == NULL || irq < 0)
  1677. return -ENXIO;
  1678. res = request_mem_region(res->start, res->end - res->start + 1,
  1679. pdev->name);
  1680. if (res == NULL)
  1681. return -EBUSY;
  1682. ret = omap_hsmmc_gpio_init(pdata);
  1683. if (ret)
  1684. goto err;
  1685. mmc = mmc_alloc_host(sizeof(struct omap_hsmmc_host), &pdev->dev);
  1686. if (!mmc) {
  1687. ret = -ENOMEM;
  1688. goto err_alloc;
  1689. }
  1690. host = mmc_priv(mmc);
  1691. host->mmc = mmc;
  1692. host->pdata = pdata;
  1693. host->dev = &pdev->dev;
  1694. host->use_dma = 1;
  1695. host->dev->dma_mask = &pdata->dma_mask;
  1696. host->dma_ch = -1;
  1697. host->irq = irq;
  1698. host->id = pdev->id;
  1699. host->slot_id = 0;
  1700. host->mapbase = res->start;
  1701. host->base = ioremap(host->mapbase, SZ_4K);
  1702. host->power_mode = MMC_POWER_OFF;
  1703. platform_set_drvdata(pdev, host);
  1704. INIT_WORK(&host->mmc_carddetect_work, omap_hsmmc_detect);
  1705. if (mmc_slot(host).power_saving)
  1706. mmc->ops = &omap_hsmmc_ps_ops;
  1707. else
  1708. mmc->ops = &omap_hsmmc_ops;
  1709. /*
  1710. * If regulator_disable can only put vcc_aux to sleep then there is
  1711. * no off state.
  1712. */
  1713. if (mmc_slot(host).vcc_aux_disable_is_sleep)
  1714. mmc_slot(host).no_off = 1;
  1715. mmc->f_min = 400000;
  1716. mmc->f_max = 52000000;
  1717. sema_init(&host->sem, 1);
  1718. spin_lock_init(&host->irq_lock);
  1719. host->iclk = clk_get(&pdev->dev, "ick");
  1720. if (IS_ERR(host->iclk)) {
  1721. ret = PTR_ERR(host->iclk);
  1722. host->iclk = NULL;
  1723. goto err1;
  1724. }
  1725. host->fclk = clk_get(&pdev->dev, "fck");
  1726. if (IS_ERR(host->fclk)) {
  1727. ret = PTR_ERR(host->fclk);
  1728. host->fclk = NULL;
  1729. clk_put(host->iclk);
  1730. goto err1;
  1731. }
  1732. omap_hsmmc_context_save(host);
  1733. mmc->caps |= MMC_CAP_DISABLE;
  1734. mmc_set_disable_delay(mmc, OMAP_MMC_DISABLED_TIMEOUT);
  1735. /* we start off in DISABLED state */
  1736. host->dpm_state = DISABLED;
  1737. if (mmc_host_enable(host->mmc) != 0) {
  1738. clk_put(host->iclk);
  1739. clk_put(host->fclk);
  1740. goto err1;
  1741. }
  1742. if (clk_enable(host->iclk) != 0) {
  1743. mmc_host_disable(host->mmc);
  1744. clk_put(host->iclk);
  1745. clk_put(host->fclk);
  1746. goto err1;
  1747. }
  1748. if (cpu_is_omap2430()) {
  1749. host->dbclk = clk_get(&pdev->dev, "mmchsdb_fck");
  1750. /*
  1751. * MMC can still work without debounce clock.
  1752. */
  1753. if (IS_ERR(host->dbclk))
  1754. dev_warn(mmc_dev(host->mmc),
  1755. "Failed to get debounce clock\n");
  1756. else
  1757. host->got_dbclk = 1;
  1758. if (host->got_dbclk)
  1759. if (clk_enable(host->dbclk) != 0)
  1760. dev_dbg(mmc_dev(host->mmc), "Enabling debounce"
  1761. " clk failed\n");
  1762. }
  1763. /* Since we do only SG emulation, we can have as many segs
  1764. * as we want. */
  1765. mmc->max_phys_segs = 1024;
  1766. mmc->max_hw_segs = 1024;
  1767. mmc->max_blk_size = 512; /* Block Length at max can be 1024 */
  1768. mmc->max_blk_count = 0xFFFF; /* No. of Blocks is 16 bits */
  1769. mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
  1770. mmc->max_seg_size = mmc->max_req_size;
  1771. mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
  1772. MMC_CAP_WAIT_WHILE_BUSY;
  1773. if (mmc_slot(host).wires >= 8)
  1774. mmc->caps |= MMC_CAP_8_BIT_DATA;
  1775. else if (mmc_slot(host).wires >= 4)
  1776. mmc->caps |= MMC_CAP_4_BIT_DATA;
  1777. if (mmc_slot(host).nonremovable)
  1778. mmc->caps |= MMC_CAP_NONREMOVABLE;
  1779. omap_hsmmc_conf_bus_power(host);
  1780. /* Select DMA lines */
  1781. switch (host->id) {
  1782. case OMAP_MMC1_DEVID:
  1783. host->dma_line_tx = OMAP24XX_DMA_MMC1_TX;
  1784. host->dma_line_rx = OMAP24XX_DMA_MMC1_RX;
  1785. break;
  1786. case OMAP_MMC2_DEVID:
  1787. host->dma_line_tx = OMAP24XX_DMA_MMC2_TX;
  1788. host->dma_line_rx = OMAP24XX_DMA_MMC2_RX;
  1789. break;
  1790. case OMAP_MMC3_DEVID:
  1791. host->dma_line_tx = OMAP34XX_DMA_MMC3_TX;
  1792. host->dma_line_rx = OMAP34XX_DMA_MMC3_RX;
  1793. break;
  1794. case OMAP_MMC4_DEVID:
  1795. host->dma_line_tx = OMAP44XX_DMA_MMC4_TX;
  1796. host->dma_line_rx = OMAP44XX_DMA_MMC4_RX;
  1797. break;
  1798. case OMAP_MMC5_DEVID:
  1799. host->dma_line_tx = OMAP44XX_DMA_MMC5_TX;
  1800. host->dma_line_rx = OMAP44XX_DMA_MMC5_RX;
  1801. break;
  1802. default:
  1803. dev_err(mmc_dev(host->mmc), "Invalid MMC id\n");
  1804. goto err_irq;
  1805. }
  1806. /* Request IRQ for MMC operations */
  1807. ret = request_irq(host->irq, omap_hsmmc_irq, IRQF_DISABLED,
  1808. mmc_hostname(mmc), host);
  1809. if (ret) {
  1810. dev_dbg(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n");
  1811. goto err_irq;
  1812. }
  1813. if (pdata->init != NULL) {
  1814. if (pdata->init(&pdev->dev) != 0) {
  1815. dev_dbg(mmc_dev(host->mmc),
  1816. "Unable to configure MMC IRQs\n");
  1817. goto err_irq_cd_init;
  1818. }
  1819. }
  1820. if (omap_hsmmc_have_reg() && !mmc_slot(host).set_power) {
  1821. ret = omap_hsmmc_reg_get(host);
  1822. if (ret)
  1823. goto err_reg;
  1824. host->use_reg = 1;
  1825. }
  1826. mmc->ocr_avail = mmc_slot(host).ocr_mask;
  1827. /* Request IRQ for card detect */
  1828. if ((mmc_slot(host).card_detect_irq)) {
  1829. ret = request_irq(mmc_slot(host).card_detect_irq,
  1830. omap_hsmmc_cd_handler,
  1831. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
  1832. | IRQF_DISABLED,
  1833. mmc_hostname(mmc), host);
  1834. if (ret) {
  1835. dev_dbg(mmc_dev(host->mmc),
  1836. "Unable to grab MMC CD IRQ\n");
  1837. goto err_irq_cd;
  1838. }
  1839. }
  1840. OMAP_HSMMC_WRITE(host->base, ISE, INT_EN_MASK);
  1841. OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
  1842. mmc_host_lazy_disable(host->mmc);
  1843. omap_hsmmc_protect_card(host);
  1844. mmc_add_host(mmc);
  1845. if (mmc_slot(host).name != NULL) {
  1846. ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name);
  1847. if (ret < 0)
  1848. goto err_slot_name;
  1849. }
  1850. if (mmc_slot(host).card_detect_irq && mmc_slot(host).get_cover_state) {
  1851. ret = device_create_file(&mmc->class_dev,
  1852. &dev_attr_cover_switch);
  1853. if (ret < 0)
  1854. goto err_slot_name;
  1855. }
  1856. omap_hsmmc_debugfs(mmc);
  1857. return 0;
  1858. err_slot_name:
  1859. mmc_remove_host(mmc);
  1860. free_irq(mmc_slot(host).card_detect_irq, host);
  1861. err_irq_cd:
  1862. if (host->use_reg)
  1863. omap_hsmmc_reg_put(host);
  1864. err_reg:
  1865. if (host->pdata->cleanup)
  1866. host->pdata->cleanup(&pdev->dev);
  1867. err_irq_cd_init:
  1868. free_irq(host->irq, host);
  1869. err_irq:
  1870. mmc_host_disable(host->mmc);
  1871. clk_disable(host->iclk);
  1872. clk_put(host->fclk);
  1873. clk_put(host->iclk);
  1874. if (host->got_dbclk) {
  1875. clk_disable(host->dbclk);
  1876. clk_put(host->dbclk);
  1877. }
  1878. err1:
  1879. iounmap(host->base);
  1880. platform_set_drvdata(pdev, NULL);
  1881. mmc_free_host(mmc);
  1882. err_alloc:
  1883. omap_hsmmc_gpio_free(pdata);
  1884. err:
  1885. release_mem_region(res->start, res->end - res->start + 1);
  1886. return ret;
  1887. }
  1888. static int omap_hsmmc_remove(struct platform_device *pdev)
  1889. {
  1890. struct omap_hsmmc_host *host = platform_get_drvdata(pdev);
  1891. struct resource *res;
  1892. if (host) {
  1893. mmc_host_enable(host->mmc);
  1894. mmc_remove_host(host->mmc);
  1895. if (host->use_reg)
  1896. omap_hsmmc_reg_put(host);
  1897. if (host->pdata->cleanup)
  1898. host->pdata->cleanup(&pdev->dev);
  1899. free_irq(host->irq, host);
  1900. if (mmc_slot(host).card_detect_irq)
  1901. free_irq(mmc_slot(host).card_detect_irq, host);
  1902. flush_scheduled_work();
  1903. mmc_host_disable(host->mmc);
  1904. clk_disable(host->iclk);
  1905. clk_put(host->fclk);
  1906. clk_put(host->iclk);
  1907. if (host->got_dbclk) {
  1908. clk_disable(host->dbclk);
  1909. clk_put(host->dbclk);
  1910. }
  1911. mmc_free_host(host->mmc);
  1912. iounmap(host->base);
  1913. omap_hsmmc_gpio_free(pdev->dev.platform_data);
  1914. }
  1915. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1916. if (res)
  1917. release_mem_region(res->start, res->end - res->start + 1);
  1918. platform_set_drvdata(pdev, NULL);
  1919. return 0;
  1920. }
  1921. #ifdef CONFIG_PM
  1922. static int omap_hsmmc_suspend(struct platform_device *pdev, pm_message_t state)
  1923. {
  1924. int ret = 0;
  1925. struct omap_hsmmc_host *host = platform_get_drvdata(pdev);
  1926. if (host && host->suspended)
  1927. return 0;
  1928. if (host) {
  1929. host->suspended = 1;
  1930. if (host->pdata->suspend) {
  1931. ret = host->pdata->suspend(&pdev->dev,
  1932. host->slot_id);
  1933. if (ret) {
  1934. dev_dbg(mmc_dev(host->mmc),
  1935. "Unable to handle MMC board"
  1936. " level suspend\n");
  1937. host->suspended = 0;
  1938. return ret;
  1939. }
  1940. }
  1941. cancel_work_sync(&host->mmc_carddetect_work);
  1942. mmc_host_enable(host->mmc);
  1943. ret = mmc_suspend_host(host->mmc, state);
  1944. if (ret == 0) {
  1945. OMAP_HSMMC_WRITE(host->base, ISE, 0);
  1946. OMAP_HSMMC_WRITE(host->base, IE, 0);
  1947. OMAP_HSMMC_WRITE(host->base, HCTL,
  1948. OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP);
  1949. mmc_host_disable(host->mmc);
  1950. clk_disable(host->iclk);
  1951. if (host->got_dbclk)
  1952. clk_disable(host->dbclk);
  1953. } else {
  1954. host->suspended = 0;
  1955. if (host->pdata->resume) {
  1956. ret = host->pdata->resume(&pdev->dev,
  1957. host->slot_id);
  1958. if (ret)
  1959. dev_dbg(mmc_dev(host->mmc),
  1960. "Unmask interrupt failed\n");
  1961. }
  1962. mmc_host_disable(host->mmc);
  1963. }
  1964. }
  1965. return ret;
  1966. }
  1967. /* Routine to resume the MMC device */
  1968. static int omap_hsmmc_resume(struct platform_device *pdev)
  1969. {
  1970. int ret = 0;
  1971. struct omap_hsmmc_host *host = platform_get_drvdata(pdev);
  1972. if (host && !host->suspended)
  1973. return 0;
  1974. if (host) {
  1975. ret = clk_enable(host->iclk);
  1976. if (ret)
  1977. goto clk_en_err;
  1978. if (mmc_host_enable(host->mmc) != 0) {
  1979. clk_disable(host->iclk);
  1980. goto clk_en_err;
  1981. }
  1982. if (host->got_dbclk)
  1983. clk_enable(host->dbclk);
  1984. omap_hsmmc_conf_bus_power(host);
  1985. if (host->pdata->resume) {
  1986. ret = host->pdata->resume(&pdev->dev, host->slot_id);
  1987. if (ret)
  1988. dev_dbg(mmc_dev(host->mmc),
  1989. "Unmask interrupt failed\n");
  1990. }
  1991. omap_hsmmc_protect_card(host);
  1992. /* Notify the core to resume the host */
  1993. ret = mmc_resume_host(host->mmc);
  1994. if (ret == 0)
  1995. host->suspended = 0;
  1996. mmc_host_lazy_disable(host->mmc);
  1997. }
  1998. return ret;
  1999. clk_en_err:
  2000. dev_dbg(mmc_dev(host->mmc),
  2001. "Failed to enable MMC clocks during resume\n");
  2002. return ret;
  2003. }
  2004. #else
  2005. #define omap_hsmmc_suspend NULL
  2006. #define omap_hsmmc_resume NULL
  2007. #endif
  2008. static struct platform_driver omap_hsmmc_driver = {
  2009. .remove = omap_hsmmc_remove,
  2010. .suspend = omap_hsmmc_suspend,
  2011. .resume = omap_hsmmc_resume,
  2012. .driver = {
  2013. .name = DRIVER_NAME,
  2014. .owner = THIS_MODULE,
  2015. },
  2016. };
  2017. static int __init omap_hsmmc_init(void)
  2018. {
  2019. /* Register the MMC driver */
  2020. return platform_driver_probe(&omap_hsmmc_driver, omap_hsmmc_probe);
  2021. }
  2022. static void __exit omap_hsmmc_cleanup(void)
  2023. {
  2024. /* Unregister MMC driver */
  2025. platform_driver_unregister(&omap_hsmmc_driver);
  2026. }
  2027. module_init(omap_hsmmc_init);
  2028. module_exit(omap_hsmmc_cleanup);
  2029. MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver");
  2030. MODULE_LICENSE("GPL");
  2031. MODULE_ALIAS("platform:" DRIVER_NAME);
  2032. MODULE_AUTHOR("Texas Instruments Inc");