omap_hsmmc.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367
  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/kernel.h>
  20. #include <linux/debugfs.h>
  21. #include <linux/dmaengine.h>
  22. #include <linux/seq_file.h>
  23. #include <linux/sizes.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/delay.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/timer.h>
  29. #include <linux/clk.h>
  30. #include <linux/of.h>
  31. #include <linux/of_irq.h>
  32. #include <linux/of_gpio.h>
  33. #include <linux/of_device.h>
  34. #include <linux/mmc/host.h>
  35. #include <linux/mmc/core.h>
  36. #include <linux/mmc/mmc.h>
  37. #include <linux/mmc/slot-gpio.h>
  38. #include <linux/io.h>
  39. #include <linux/irq.h>
  40. #include <linux/gpio.h>
  41. #include <linux/regulator/consumer.h>
  42. #include <linux/pinctrl/consumer.h>
  43. #include <linux/pm_runtime.h>
  44. #include <linux/pm_wakeirq.h>
  45. #include <linux/platform_data/hsmmc-omap.h>
  46. /* OMAP HSMMC Host Controller Registers */
  47. #define OMAP_HSMMC_SYSSTATUS 0x0014
  48. #define OMAP_HSMMC_CON 0x002C
  49. #define OMAP_HSMMC_SDMASA 0x0100
  50. #define OMAP_HSMMC_BLK 0x0104
  51. #define OMAP_HSMMC_ARG 0x0108
  52. #define OMAP_HSMMC_CMD 0x010C
  53. #define OMAP_HSMMC_RSP10 0x0110
  54. #define OMAP_HSMMC_RSP32 0x0114
  55. #define OMAP_HSMMC_RSP54 0x0118
  56. #define OMAP_HSMMC_RSP76 0x011C
  57. #define OMAP_HSMMC_DATA 0x0120
  58. #define OMAP_HSMMC_PSTATE 0x0124
  59. #define OMAP_HSMMC_HCTL 0x0128
  60. #define OMAP_HSMMC_SYSCTL 0x012C
  61. #define OMAP_HSMMC_STAT 0x0130
  62. #define OMAP_HSMMC_IE 0x0134
  63. #define OMAP_HSMMC_ISE 0x0138
  64. #define OMAP_HSMMC_AC12 0x013C
  65. #define OMAP_HSMMC_CAPA 0x0140
  66. #define VS18 (1 << 26)
  67. #define VS30 (1 << 25)
  68. #define HSS (1 << 21)
  69. #define SDVS18 (0x5 << 9)
  70. #define SDVS30 (0x6 << 9)
  71. #define SDVS33 (0x7 << 9)
  72. #define SDVS_MASK 0x00000E00
  73. #define SDVSCLR 0xFFFFF1FF
  74. #define SDVSDET 0x00000400
  75. #define AUTOIDLE 0x1
  76. #define SDBP (1 << 8)
  77. #define DTO 0xe
  78. #define ICE 0x1
  79. #define ICS 0x2
  80. #define CEN (1 << 2)
  81. #define CLKD_MAX 0x3FF /* max clock divisor: 1023 */
  82. #define CLKD_MASK 0x0000FFC0
  83. #define CLKD_SHIFT 6
  84. #define DTO_MASK 0x000F0000
  85. #define DTO_SHIFT 16
  86. #define INIT_STREAM (1 << 1)
  87. #define ACEN_ACMD23 (2 << 2)
  88. #define DP_SELECT (1 << 21)
  89. #define DDIR (1 << 4)
  90. #define DMAE 0x1
  91. #define MSBS (1 << 5)
  92. #define BCE (1 << 1)
  93. #define FOUR_BIT (1 << 1)
  94. #define HSPE (1 << 2)
  95. #define IWE (1 << 24)
  96. #define DDR (1 << 19)
  97. #define CLKEXTFREE (1 << 16)
  98. #define CTPL (1 << 11)
  99. #define DW8 (1 << 5)
  100. #define OD 0x1
  101. #define STAT_CLEAR 0xFFFFFFFF
  102. #define INIT_STREAM_CMD 0x00000000
  103. #define DUAL_VOLT_OCR_BIT 7
  104. #define SRC (1 << 25)
  105. #define SRD (1 << 26)
  106. #define SOFTRESET (1 << 1)
  107. /* PSTATE */
  108. #define DLEV_DAT(x) (1 << (20 + (x)))
  109. /* Interrupt masks for IE and ISE register */
  110. #define CC_EN (1 << 0)
  111. #define TC_EN (1 << 1)
  112. #define BWR_EN (1 << 4)
  113. #define BRR_EN (1 << 5)
  114. #define CIRQ_EN (1 << 8)
  115. #define ERR_EN (1 << 15)
  116. #define CTO_EN (1 << 16)
  117. #define CCRC_EN (1 << 17)
  118. #define CEB_EN (1 << 18)
  119. #define CIE_EN (1 << 19)
  120. #define DTO_EN (1 << 20)
  121. #define DCRC_EN (1 << 21)
  122. #define DEB_EN (1 << 22)
  123. #define ACE_EN (1 << 24)
  124. #define CERR_EN (1 << 28)
  125. #define BADA_EN (1 << 29)
  126. #define INT_EN_MASK (BADA_EN | CERR_EN | ACE_EN | DEB_EN | DCRC_EN |\
  127. DTO_EN | CIE_EN | CEB_EN | CCRC_EN | CTO_EN | \
  128. BRR_EN | BWR_EN | TC_EN | CC_EN)
  129. #define CNI (1 << 7)
  130. #define ACIE (1 << 4)
  131. #define ACEB (1 << 3)
  132. #define ACCE (1 << 2)
  133. #define ACTO (1 << 1)
  134. #define ACNE (1 << 0)
  135. #define MMC_AUTOSUSPEND_DELAY 100
  136. #define MMC_TIMEOUT_MS 20 /* 20 mSec */
  137. #define MMC_TIMEOUT_US 20000 /* 20000 micro Sec */
  138. #define OMAP_MMC_MIN_CLOCK 400000
  139. #define OMAP_MMC_MAX_CLOCK 52000000
  140. #define DRIVER_NAME "omap_hsmmc"
  141. #define VDD_1V8 1800000 /* 180000 uV */
  142. #define VDD_3V0 3000000 /* 300000 uV */
  143. #define VDD_165_195 (ffs(MMC_VDD_165_195) - 1)
  144. /*
  145. * One controller can have multiple slots, like on some omap boards using
  146. * omap.c controller driver. Luckily this is not currently done on any known
  147. * omap_hsmmc.c device.
  148. */
  149. #define mmc_pdata(host) host->pdata
  150. /*
  151. * MMC Host controller read/write API's
  152. */
  153. #define OMAP_HSMMC_READ(base, reg) \
  154. __raw_readl((base) + OMAP_HSMMC_##reg)
  155. #define OMAP_HSMMC_WRITE(base, reg, val) \
  156. __raw_writel((val), (base) + OMAP_HSMMC_##reg)
  157. struct omap_hsmmc_next {
  158. unsigned int dma_len;
  159. s32 cookie;
  160. };
  161. struct omap_hsmmc_host {
  162. struct device *dev;
  163. struct mmc_host *mmc;
  164. struct mmc_request *mrq;
  165. struct mmc_command *cmd;
  166. struct mmc_data *data;
  167. struct clk *fclk;
  168. struct clk *dbclk;
  169. struct regulator *pbias;
  170. bool pbias_enabled;
  171. void __iomem *base;
  172. int vqmmc_enabled;
  173. resource_size_t mapbase;
  174. spinlock_t irq_lock; /* Prevent races with irq handler */
  175. unsigned int dma_len;
  176. unsigned int dma_sg_idx;
  177. unsigned char bus_mode;
  178. unsigned char power_mode;
  179. int suspended;
  180. u32 con;
  181. u32 hctl;
  182. u32 sysctl;
  183. u32 capa;
  184. int irq;
  185. int wake_irq;
  186. int use_dma, dma_ch;
  187. struct dma_chan *tx_chan;
  188. struct dma_chan *rx_chan;
  189. int response_busy;
  190. int context_loss;
  191. int protect_card;
  192. int reqs_blocked;
  193. int req_in_progress;
  194. unsigned long clk_rate;
  195. unsigned int flags;
  196. #define AUTO_CMD23 (1 << 0) /* Auto CMD23 support */
  197. #define HSMMC_SDIO_IRQ_ENABLED (1 << 1) /* SDIO irq enabled */
  198. struct omap_hsmmc_next next_data;
  199. struct omap_hsmmc_platform_data *pdata;
  200. /* return MMC cover switch state, can be NULL if not supported.
  201. *
  202. * possible return values:
  203. * 0 - closed
  204. * 1 - open
  205. */
  206. int (*get_cover_state)(struct device *dev);
  207. int (*card_detect)(struct device *dev);
  208. };
  209. struct omap_mmc_of_data {
  210. u32 reg_offset;
  211. u8 controller_flags;
  212. };
  213. static void omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host);
  214. static int omap_hsmmc_card_detect(struct device *dev)
  215. {
  216. struct omap_hsmmc_host *host = dev_get_drvdata(dev);
  217. return mmc_gpio_get_cd(host->mmc);
  218. }
  219. static int omap_hsmmc_get_cover_state(struct device *dev)
  220. {
  221. struct omap_hsmmc_host *host = dev_get_drvdata(dev);
  222. return mmc_gpio_get_cd(host->mmc);
  223. }
  224. static int omap_hsmmc_enable_supply(struct mmc_host *mmc)
  225. {
  226. int ret;
  227. struct omap_hsmmc_host *host = mmc_priv(mmc);
  228. struct mmc_ios *ios = &mmc->ios;
  229. if (mmc->supply.vmmc) {
  230. ret = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd);
  231. if (ret)
  232. return ret;
  233. }
  234. /* Enable interface voltage rail, if needed */
  235. if (mmc->supply.vqmmc && !host->vqmmc_enabled) {
  236. ret = regulator_enable(mmc->supply.vqmmc);
  237. if (ret) {
  238. dev_err(mmc_dev(mmc), "vmmc_aux reg enable failed\n");
  239. goto err_vqmmc;
  240. }
  241. host->vqmmc_enabled = 1;
  242. }
  243. return 0;
  244. err_vqmmc:
  245. if (mmc->supply.vmmc)
  246. mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
  247. return ret;
  248. }
  249. static int omap_hsmmc_disable_supply(struct mmc_host *mmc)
  250. {
  251. int ret;
  252. int status;
  253. struct omap_hsmmc_host *host = mmc_priv(mmc);
  254. if (mmc->supply.vqmmc && host->vqmmc_enabled) {
  255. ret = regulator_disable(mmc->supply.vqmmc);
  256. if (ret) {
  257. dev_err(mmc_dev(mmc), "vmmc_aux reg disable failed\n");
  258. return ret;
  259. }
  260. host->vqmmc_enabled = 0;
  261. }
  262. if (mmc->supply.vmmc) {
  263. ret = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
  264. if (ret)
  265. goto err_set_ocr;
  266. }
  267. return 0;
  268. err_set_ocr:
  269. if (mmc->supply.vqmmc) {
  270. status = regulator_enable(mmc->supply.vqmmc);
  271. if (status)
  272. dev_err(mmc_dev(mmc), "vmmc_aux re-enable failed\n");
  273. }
  274. return ret;
  275. }
  276. static int omap_hsmmc_set_pbias(struct omap_hsmmc_host *host, bool power_on,
  277. int vdd)
  278. {
  279. int ret;
  280. if (!host->pbias)
  281. return 0;
  282. if (power_on) {
  283. if (vdd <= VDD_165_195)
  284. ret = regulator_set_voltage(host->pbias, VDD_1V8,
  285. VDD_1V8);
  286. else
  287. ret = regulator_set_voltage(host->pbias, VDD_3V0,
  288. VDD_3V0);
  289. if (ret < 0) {
  290. dev_err(host->dev, "pbias set voltage fail\n");
  291. return ret;
  292. }
  293. if (host->pbias_enabled == 0) {
  294. ret = regulator_enable(host->pbias);
  295. if (ret) {
  296. dev_err(host->dev, "pbias reg enable fail\n");
  297. return ret;
  298. }
  299. host->pbias_enabled = 1;
  300. }
  301. } else {
  302. if (host->pbias_enabled == 1) {
  303. ret = regulator_disable(host->pbias);
  304. if (ret) {
  305. dev_err(host->dev, "pbias reg disable fail\n");
  306. return ret;
  307. }
  308. host->pbias_enabled = 0;
  309. }
  310. }
  311. return 0;
  312. }
  313. static int omap_hsmmc_set_power(struct omap_hsmmc_host *host, int power_on,
  314. int vdd)
  315. {
  316. struct mmc_host *mmc = host->mmc;
  317. int ret = 0;
  318. if (mmc_pdata(host)->set_power)
  319. return mmc_pdata(host)->set_power(host->dev, power_on, vdd);
  320. /*
  321. * If we don't see a Vcc regulator, assume it's a fixed
  322. * voltage always-on regulator.
  323. */
  324. if (!mmc->supply.vmmc)
  325. return 0;
  326. if (mmc_pdata(host)->before_set_reg)
  327. mmc_pdata(host)->before_set_reg(host->dev, power_on, vdd);
  328. ret = omap_hsmmc_set_pbias(host, false, 0);
  329. if (ret)
  330. return ret;
  331. /*
  332. * Assume Vcc regulator is used only to power the card ... OMAP
  333. * VDDS is used to power the pins, optionally with a transceiver to
  334. * support cards using voltages other than VDDS (1.8V nominal). When a
  335. * transceiver is used, DAT3..7 are muxed as transceiver control pins.
  336. *
  337. * In some cases this regulator won't support enable/disable;
  338. * e.g. it's a fixed rail for a WLAN chip.
  339. *
  340. * In other cases vcc_aux switches interface power. Example, for
  341. * eMMC cards it represents VccQ. Sometimes transceivers or SDIO
  342. * chips/cards need an interface voltage rail too.
  343. */
  344. if (power_on) {
  345. ret = omap_hsmmc_enable_supply(mmc);
  346. if (ret)
  347. return ret;
  348. ret = omap_hsmmc_set_pbias(host, true, vdd);
  349. if (ret)
  350. goto err_set_voltage;
  351. } else {
  352. ret = omap_hsmmc_disable_supply(mmc);
  353. if (ret)
  354. return ret;
  355. }
  356. if (mmc_pdata(host)->after_set_reg)
  357. mmc_pdata(host)->after_set_reg(host->dev, power_on, vdd);
  358. return 0;
  359. err_set_voltage:
  360. omap_hsmmc_disable_supply(mmc);
  361. return ret;
  362. }
  363. static int omap_hsmmc_disable_boot_regulator(struct regulator *reg)
  364. {
  365. int ret;
  366. if (!reg)
  367. return 0;
  368. if (regulator_is_enabled(reg)) {
  369. ret = regulator_enable(reg);
  370. if (ret)
  371. return ret;
  372. ret = regulator_disable(reg);
  373. if (ret)
  374. return ret;
  375. }
  376. return 0;
  377. }
  378. static int omap_hsmmc_disable_boot_regulators(struct omap_hsmmc_host *host)
  379. {
  380. struct mmc_host *mmc = host->mmc;
  381. int ret;
  382. /*
  383. * disable regulators enabled during boot and get the usecount
  384. * right so that regulators can be enabled/disabled by checking
  385. * the return value of regulator_is_enabled
  386. */
  387. ret = omap_hsmmc_disable_boot_regulator(mmc->supply.vmmc);
  388. if (ret) {
  389. dev_err(host->dev, "fail to disable boot enabled vmmc reg\n");
  390. return ret;
  391. }
  392. ret = omap_hsmmc_disable_boot_regulator(mmc->supply.vqmmc);
  393. if (ret) {
  394. dev_err(host->dev,
  395. "fail to disable boot enabled vmmc_aux reg\n");
  396. return ret;
  397. }
  398. ret = omap_hsmmc_disable_boot_regulator(host->pbias);
  399. if (ret) {
  400. dev_err(host->dev,
  401. "failed to disable boot enabled pbias reg\n");
  402. return ret;
  403. }
  404. return 0;
  405. }
  406. static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
  407. {
  408. int ocr_value = 0;
  409. int ret;
  410. struct mmc_host *mmc = host->mmc;
  411. if (mmc_pdata(host)->set_power)
  412. return 0;
  413. mmc->supply.vmmc = devm_regulator_get_optional(host->dev, "vmmc");
  414. if (IS_ERR(mmc->supply.vmmc)) {
  415. ret = PTR_ERR(mmc->supply.vmmc);
  416. if ((ret != -ENODEV) && host->dev->of_node)
  417. return ret;
  418. dev_dbg(host->dev, "unable to get vmmc regulator %ld\n",
  419. PTR_ERR(mmc->supply.vmmc));
  420. mmc->supply.vmmc = NULL;
  421. } else {
  422. ocr_value = mmc_regulator_get_ocrmask(mmc->supply.vmmc);
  423. if (ocr_value > 0)
  424. mmc_pdata(host)->ocr_mask = ocr_value;
  425. }
  426. /* Allow an aux regulator */
  427. mmc->supply.vqmmc = devm_regulator_get_optional(host->dev, "vmmc_aux");
  428. if (IS_ERR(mmc->supply.vqmmc)) {
  429. ret = PTR_ERR(mmc->supply.vqmmc);
  430. if ((ret != -ENODEV) && host->dev->of_node)
  431. return ret;
  432. dev_dbg(host->dev, "unable to get vmmc_aux regulator %ld\n",
  433. PTR_ERR(mmc->supply.vqmmc));
  434. mmc->supply.vqmmc = NULL;
  435. }
  436. host->pbias = devm_regulator_get_optional(host->dev, "pbias");
  437. if (IS_ERR(host->pbias)) {
  438. ret = PTR_ERR(host->pbias);
  439. if ((ret != -ENODEV) && host->dev->of_node) {
  440. dev_err(host->dev,
  441. "SD card detect fail? enable CONFIG_REGULATOR_PBIAS\n");
  442. return ret;
  443. }
  444. dev_dbg(host->dev, "unable to get pbias regulator %ld\n",
  445. PTR_ERR(host->pbias));
  446. host->pbias = NULL;
  447. }
  448. /* For eMMC do not power off when not in sleep state */
  449. if (mmc_pdata(host)->no_regulator_off_init)
  450. return 0;
  451. ret = omap_hsmmc_disable_boot_regulators(host);
  452. if (ret)
  453. return ret;
  454. return 0;
  455. }
  456. static irqreturn_t omap_hsmmc_cover_irq(int irq, void *dev_id);
  457. static int omap_hsmmc_gpio_init(struct mmc_host *mmc,
  458. struct omap_hsmmc_host *host,
  459. struct omap_hsmmc_platform_data *pdata)
  460. {
  461. int ret;
  462. if (gpio_is_valid(pdata->gpio_cod)) {
  463. ret = mmc_gpio_request_cd(mmc, pdata->gpio_cod, 0);
  464. if (ret)
  465. return ret;
  466. host->get_cover_state = omap_hsmmc_get_cover_state;
  467. mmc_gpio_set_cd_isr(mmc, omap_hsmmc_cover_irq);
  468. } else if (gpio_is_valid(pdata->gpio_cd)) {
  469. ret = mmc_gpio_request_cd(mmc, pdata->gpio_cd, 0);
  470. if (ret)
  471. return ret;
  472. host->card_detect = omap_hsmmc_card_detect;
  473. }
  474. if (gpio_is_valid(pdata->gpio_wp)) {
  475. ret = mmc_gpio_request_ro(mmc, pdata->gpio_wp);
  476. if (ret)
  477. return ret;
  478. }
  479. return 0;
  480. }
  481. /*
  482. * Start clock to the card
  483. */
  484. static void omap_hsmmc_start_clock(struct omap_hsmmc_host *host)
  485. {
  486. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  487. OMAP_HSMMC_READ(host->base, SYSCTL) | CEN);
  488. }
  489. /*
  490. * Stop clock to the card
  491. */
  492. static void omap_hsmmc_stop_clock(struct omap_hsmmc_host *host)
  493. {
  494. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  495. OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN);
  496. if ((OMAP_HSMMC_READ(host->base, SYSCTL) & CEN) != 0x0)
  497. dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stopped\n");
  498. }
  499. static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host,
  500. struct mmc_command *cmd)
  501. {
  502. u32 irq_mask = INT_EN_MASK;
  503. unsigned long flags;
  504. if (host->use_dma)
  505. irq_mask &= ~(BRR_EN | BWR_EN);
  506. /* Disable timeout for erases */
  507. if (cmd->opcode == MMC_ERASE)
  508. irq_mask &= ~DTO_EN;
  509. spin_lock_irqsave(&host->irq_lock, flags);
  510. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  511. OMAP_HSMMC_WRITE(host->base, ISE, irq_mask);
  512. /* latch pending CIRQ, but don't signal MMC core */
  513. if (host->flags & HSMMC_SDIO_IRQ_ENABLED)
  514. irq_mask |= CIRQ_EN;
  515. OMAP_HSMMC_WRITE(host->base, IE, irq_mask);
  516. spin_unlock_irqrestore(&host->irq_lock, flags);
  517. }
  518. static void omap_hsmmc_disable_irq(struct omap_hsmmc_host *host)
  519. {
  520. u32 irq_mask = 0;
  521. unsigned long flags;
  522. spin_lock_irqsave(&host->irq_lock, flags);
  523. /* no transfer running but need to keep cirq if enabled */
  524. if (host->flags & HSMMC_SDIO_IRQ_ENABLED)
  525. irq_mask |= CIRQ_EN;
  526. OMAP_HSMMC_WRITE(host->base, ISE, irq_mask);
  527. OMAP_HSMMC_WRITE(host->base, IE, irq_mask);
  528. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  529. spin_unlock_irqrestore(&host->irq_lock, flags);
  530. }
  531. /* Calculate divisor for the given clock frequency */
  532. static u16 calc_divisor(struct omap_hsmmc_host *host, struct mmc_ios *ios)
  533. {
  534. u16 dsor = 0;
  535. if (ios->clock) {
  536. dsor = DIV_ROUND_UP(clk_get_rate(host->fclk), ios->clock);
  537. if (dsor > CLKD_MAX)
  538. dsor = CLKD_MAX;
  539. }
  540. return dsor;
  541. }
  542. static void omap_hsmmc_set_clock(struct omap_hsmmc_host *host)
  543. {
  544. struct mmc_ios *ios = &host->mmc->ios;
  545. unsigned long regval;
  546. unsigned long timeout;
  547. unsigned long clkdiv;
  548. dev_vdbg(mmc_dev(host->mmc), "Set clock to %uHz\n", ios->clock);
  549. omap_hsmmc_stop_clock(host);
  550. regval = OMAP_HSMMC_READ(host->base, SYSCTL);
  551. regval = regval & ~(CLKD_MASK | DTO_MASK);
  552. clkdiv = calc_divisor(host, ios);
  553. regval = regval | (clkdiv << 6) | (DTO << 16);
  554. OMAP_HSMMC_WRITE(host->base, SYSCTL, regval);
  555. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  556. OMAP_HSMMC_READ(host->base, SYSCTL) | ICE);
  557. /* Wait till the ICS bit is set */
  558. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  559. while ((OMAP_HSMMC_READ(host->base, SYSCTL) & ICS) != ICS
  560. && time_before(jiffies, timeout))
  561. cpu_relax();
  562. /*
  563. * Enable High-Speed Support
  564. * Pre-Requisites
  565. * - Controller should support High-Speed-Enable Bit
  566. * - Controller should not be using DDR Mode
  567. * - Controller should advertise that it supports High Speed
  568. * in capabilities register
  569. * - MMC/SD clock coming out of controller > 25MHz
  570. */
  571. if ((mmc_pdata(host)->features & HSMMC_HAS_HSPE_SUPPORT) &&
  572. (ios->timing != MMC_TIMING_MMC_DDR52) &&
  573. (ios->timing != MMC_TIMING_UHS_DDR50) &&
  574. ((OMAP_HSMMC_READ(host->base, CAPA) & HSS) == HSS)) {
  575. regval = OMAP_HSMMC_READ(host->base, HCTL);
  576. if (clkdiv && (clk_get_rate(host->fclk)/clkdiv) > 25000000)
  577. regval |= HSPE;
  578. else
  579. regval &= ~HSPE;
  580. OMAP_HSMMC_WRITE(host->base, HCTL, regval);
  581. }
  582. omap_hsmmc_start_clock(host);
  583. }
  584. static void omap_hsmmc_set_bus_width(struct omap_hsmmc_host *host)
  585. {
  586. struct mmc_ios *ios = &host->mmc->ios;
  587. u32 con;
  588. con = OMAP_HSMMC_READ(host->base, CON);
  589. if (ios->timing == MMC_TIMING_MMC_DDR52 ||
  590. ios->timing == MMC_TIMING_UHS_DDR50)
  591. con |= DDR; /* configure in DDR mode */
  592. else
  593. con &= ~DDR;
  594. switch (ios->bus_width) {
  595. case MMC_BUS_WIDTH_8:
  596. OMAP_HSMMC_WRITE(host->base, CON, con | DW8);
  597. break;
  598. case MMC_BUS_WIDTH_4:
  599. OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
  600. OMAP_HSMMC_WRITE(host->base, HCTL,
  601. OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT);
  602. break;
  603. case MMC_BUS_WIDTH_1:
  604. OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
  605. OMAP_HSMMC_WRITE(host->base, HCTL,
  606. OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT);
  607. break;
  608. }
  609. }
  610. static void omap_hsmmc_set_bus_mode(struct omap_hsmmc_host *host)
  611. {
  612. struct mmc_ios *ios = &host->mmc->ios;
  613. u32 con;
  614. con = OMAP_HSMMC_READ(host->base, CON);
  615. if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
  616. OMAP_HSMMC_WRITE(host->base, CON, con | OD);
  617. else
  618. OMAP_HSMMC_WRITE(host->base, CON, con & ~OD);
  619. }
  620. #ifdef CONFIG_PM
  621. /*
  622. * Restore the MMC host context, if it was lost as result of a
  623. * power state change.
  624. */
  625. static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host)
  626. {
  627. struct mmc_ios *ios = &host->mmc->ios;
  628. u32 hctl, capa;
  629. unsigned long timeout;
  630. if (host->con == OMAP_HSMMC_READ(host->base, CON) &&
  631. host->hctl == OMAP_HSMMC_READ(host->base, HCTL) &&
  632. host->sysctl == OMAP_HSMMC_READ(host->base, SYSCTL) &&
  633. host->capa == OMAP_HSMMC_READ(host->base, CAPA))
  634. return 0;
  635. host->context_loss++;
  636. if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) {
  637. if (host->power_mode != MMC_POWER_OFF &&
  638. (1 << ios->vdd) <= MMC_VDD_23_24)
  639. hctl = SDVS18;
  640. else
  641. hctl = SDVS30;
  642. capa = VS30 | VS18;
  643. } else {
  644. hctl = SDVS18;
  645. capa = VS18;
  646. }
  647. if (host->mmc->caps & MMC_CAP_SDIO_IRQ)
  648. hctl |= IWE;
  649. OMAP_HSMMC_WRITE(host->base, HCTL,
  650. OMAP_HSMMC_READ(host->base, HCTL) | hctl);
  651. OMAP_HSMMC_WRITE(host->base, CAPA,
  652. OMAP_HSMMC_READ(host->base, CAPA) | capa);
  653. OMAP_HSMMC_WRITE(host->base, HCTL,
  654. OMAP_HSMMC_READ(host->base, HCTL) | SDBP);
  655. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  656. while ((OMAP_HSMMC_READ(host->base, HCTL) & SDBP) != SDBP
  657. && time_before(jiffies, timeout))
  658. ;
  659. OMAP_HSMMC_WRITE(host->base, ISE, 0);
  660. OMAP_HSMMC_WRITE(host->base, IE, 0);
  661. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  662. /* Do not initialize card-specific things if the power is off */
  663. if (host->power_mode == MMC_POWER_OFF)
  664. goto out;
  665. omap_hsmmc_set_bus_width(host);
  666. omap_hsmmc_set_clock(host);
  667. omap_hsmmc_set_bus_mode(host);
  668. out:
  669. dev_dbg(mmc_dev(host->mmc), "context is restored: restore count %d\n",
  670. host->context_loss);
  671. return 0;
  672. }
  673. /*
  674. * Save the MMC host context (store the number of power state changes so far).
  675. */
  676. static void omap_hsmmc_context_save(struct omap_hsmmc_host *host)
  677. {
  678. host->con = OMAP_HSMMC_READ(host->base, CON);
  679. host->hctl = OMAP_HSMMC_READ(host->base, HCTL);
  680. host->sysctl = OMAP_HSMMC_READ(host->base, SYSCTL);
  681. host->capa = OMAP_HSMMC_READ(host->base, CAPA);
  682. }
  683. #else
  684. static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host)
  685. {
  686. return 0;
  687. }
  688. static void omap_hsmmc_context_save(struct omap_hsmmc_host *host)
  689. {
  690. }
  691. #endif
  692. /*
  693. * Send init stream sequence to card
  694. * before sending IDLE command
  695. */
  696. static void send_init_stream(struct omap_hsmmc_host *host)
  697. {
  698. int reg = 0;
  699. unsigned long timeout;
  700. if (host->protect_card)
  701. return;
  702. disable_irq(host->irq);
  703. OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
  704. OMAP_HSMMC_WRITE(host->base, CON,
  705. OMAP_HSMMC_READ(host->base, CON) | INIT_STREAM);
  706. OMAP_HSMMC_WRITE(host->base, CMD, INIT_STREAM_CMD);
  707. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  708. while ((reg != CC_EN) && time_before(jiffies, timeout))
  709. reg = OMAP_HSMMC_READ(host->base, STAT) & CC_EN;
  710. OMAP_HSMMC_WRITE(host->base, CON,
  711. OMAP_HSMMC_READ(host->base, CON) & ~INIT_STREAM);
  712. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  713. OMAP_HSMMC_READ(host->base, STAT);
  714. enable_irq(host->irq);
  715. }
  716. static inline
  717. int omap_hsmmc_cover_is_closed(struct omap_hsmmc_host *host)
  718. {
  719. int r = 1;
  720. if (host->get_cover_state)
  721. r = host->get_cover_state(host->dev);
  722. return r;
  723. }
  724. static ssize_t
  725. omap_hsmmc_show_cover_switch(struct device *dev, struct device_attribute *attr,
  726. char *buf)
  727. {
  728. struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
  729. struct omap_hsmmc_host *host = mmc_priv(mmc);
  730. return sprintf(buf, "%s\n",
  731. omap_hsmmc_cover_is_closed(host) ? "closed" : "open");
  732. }
  733. static DEVICE_ATTR(cover_switch, S_IRUGO, omap_hsmmc_show_cover_switch, NULL);
  734. static ssize_t
  735. omap_hsmmc_show_slot_name(struct device *dev, struct device_attribute *attr,
  736. char *buf)
  737. {
  738. struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
  739. struct omap_hsmmc_host *host = mmc_priv(mmc);
  740. return sprintf(buf, "%s\n", mmc_pdata(host)->name);
  741. }
  742. static DEVICE_ATTR(slot_name, S_IRUGO, omap_hsmmc_show_slot_name, NULL);
  743. /*
  744. * Configure the response type and send the cmd.
  745. */
  746. static void
  747. omap_hsmmc_start_command(struct omap_hsmmc_host *host, struct mmc_command *cmd,
  748. struct mmc_data *data)
  749. {
  750. int cmdreg = 0, resptype = 0, cmdtype = 0;
  751. dev_vdbg(mmc_dev(host->mmc), "%s: CMD%d, argument 0x%08x\n",
  752. mmc_hostname(host->mmc), cmd->opcode, cmd->arg);
  753. host->cmd = cmd;
  754. omap_hsmmc_enable_irq(host, cmd);
  755. host->response_busy = 0;
  756. if (cmd->flags & MMC_RSP_PRESENT) {
  757. if (cmd->flags & MMC_RSP_136)
  758. resptype = 1;
  759. else if (cmd->flags & MMC_RSP_BUSY) {
  760. resptype = 3;
  761. host->response_busy = 1;
  762. } else
  763. resptype = 2;
  764. }
  765. /*
  766. * Unlike OMAP1 controller, the cmdtype does not seem to be based on
  767. * ac, bc, adtc, bcr. Only commands ending an open ended transfer need
  768. * a val of 0x3, rest 0x0.
  769. */
  770. if (cmd == host->mrq->stop)
  771. cmdtype = 0x3;
  772. cmdreg = (cmd->opcode << 24) | (resptype << 16) | (cmdtype << 22);
  773. if ((host->flags & AUTO_CMD23) && mmc_op_multi(cmd->opcode) &&
  774. host->mrq->sbc) {
  775. cmdreg |= ACEN_ACMD23;
  776. OMAP_HSMMC_WRITE(host->base, SDMASA, host->mrq->sbc->arg);
  777. }
  778. if (data) {
  779. cmdreg |= DP_SELECT | MSBS | BCE;
  780. if (data->flags & MMC_DATA_READ)
  781. cmdreg |= DDIR;
  782. else
  783. cmdreg &= ~(DDIR);
  784. }
  785. if (host->use_dma)
  786. cmdreg |= DMAE;
  787. host->req_in_progress = 1;
  788. OMAP_HSMMC_WRITE(host->base, ARG, cmd->arg);
  789. OMAP_HSMMC_WRITE(host->base, CMD, cmdreg);
  790. }
  791. static int
  792. omap_hsmmc_get_dma_dir(struct omap_hsmmc_host *host, struct mmc_data *data)
  793. {
  794. if (data->flags & MMC_DATA_WRITE)
  795. return DMA_TO_DEVICE;
  796. else
  797. return DMA_FROM_DEVICE;
  798. }
  799. static struct dma_chan *omap_hsmmc_get_dma_chan(struct omap_hsmmc_host *host,
  800. struct mmc_data *data)
  801. {
  802. return data->flags & MMC_DATA_WRITE ? host->tx_chan : host->rx_chan;
  803. }
  804. static void omap_hsmmc_request_done(struct omap_hsmmc_host *host, struct mmc_request *mrq)
  805. {
  806. int dma_ch;
  807. unsigned long flags;
  808. spin_lock_irqsave(&host->irq_lock, flags);
  809. host->req_in_progress = 0;
  810. dma_ch = host->dma_ch;
  811. spin_unlock_irqrestore(&host->irq_lock, flags);
  812. omap_hsmmc_disable_irq(host);
  813. /* Do not complete the request if DMA is still in progress */
  814. if (mrq->data && host->use_dma && dma_ch != -1)
  815. return;
  816. host->mrq = NULL;
  817. mmc_request_done(host->mmc, mrq);
  818. }
  819. /*
  820. * Notify the transfer complete to MMC core
  821. */
  822. static void
  823. omap_hsmmc_xfer_done(struct omap_hsmmc_host *host, struct mmc_data *data)
  824. {
  825. if (!data) {
  826. struct mmc_request *mrq = host->mrq;
  827. /* TC before CC from CMD6 - don't know why, but it happens */
  828. if (host->cmd && host->cmd->opcode == 6 &&
  829. host->response_busy) {
  830. host->response_busy = 0;
  831. return;
  832. }
  833. omap_hsmmc_request_done(host, mrq);
  834. return;
  835. }
  836. host->data = NULL;
  837. if (!data->error)
  838. data->bytes_xfered += data->blocks * (data->blksz);
  839. else
  840. data->bytes_xfered = 0;
  841. if (data->stop && (data->error || !host->mrq->sbc))
  842. omap_hsmmc_start_command(host, data->stop, NULL);
  843. else
  844. omap_hsmmc_request_done(host, data->mrq);
  845. }
  846. /*
  847. * Notify the core about command completion
  848. */
  849. static void
  850. omap_hsmmc_cmd_done(struct omap_hsmmc_host *host, struct mmc_command *cmd)
  851. {
  852. if (host->mrq->sbc && (host->cmd == host->mrq->sbc) &&
  853. !host->mrq->sbc->error && !(host->flags & AUTO_CMD23)) {
  854. host->cmd = NULL;
  855. omap_hsmmc_start_dma_transfer(host);
  856. omap_hsmmc_start_command(host, host->mrq->cmd,
  857. host->mrq->data);
  858. return;
  859. }
  860. host->cmd = NULL;
  861. if (cmd->flags & MMC_RSP_PRESENT) {
  862. if (cmd->flags & MMC_RSP_136) {
  863. /* response type 2 */
  864. cmd->resp[3] = OMAP_HSMMC_READ(host->base, RSP10);
  865. cmd->resp[2] = OMAP_HSMMC_READ(host->base, RSP32);
  866. cmd->resp[1] = OMAP_HSMMC_READ(host->base, RSP54);
  867. cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP76);
  868. } else {
  869. /* response types 1, 1b, 3, 4, 5, 6 */
  870. cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP10);
  871. }
  872. }
  873. if ((host->data == NULL && !host->response_busy) || cmd->error)
  874. omap_hsmmc_request_done(host, host->mrq);
  875. }
  876. /*
  877. * DMA clean up for command errors
  878. */
  879. static void omap_hsmmc_dma_cleanup(struct omap_hsmmc_host *host, int errno)
  880. {
  881. int dma_ch;
  882. unsigned long flags;
  883. host->data->error = errno;
  884. spin_lock_irqsave(&host->irq_lock, flags);
  885. dma_ch = host->dma_ch;
  886. host->dma_ch = -1;
  887. spin_unlock_irqrestore(&host->irq_lock, flags);
  888. if (host->use_dma && dma_ch != -1) {
  889. struct dma_chan *chan = omap_hsmmc_get_dma_chan(host, host->data);
  890. dmaengine_terminate_all(chan);
  891. dma_unmap_sg(chan->device->dev,
  892. host->data->sg, host->data->sg_len,
  893. omap_hsmmc_get_dma_dir(host, host->data));
  894. host->data->host_cookie = 0;
  895. }
  896. host->data = NULL;
  897. }
  898. /*
  899. * Readable error output
  900. */
  901. #ifdef CONFIG_MMC_DEBUG
  902. static void omap_hsmmc_dbg_report_irq(struct omap_hsmmc_host *host, u32 status)
  903. {
  904. /* --- means reserved bit without definition at documentation */
  905. static const char *omap_hsmmc_status_bits[] = {
  906. "CC" , "TC" , "BGE", "---", "BWR" , "BRR" , "---" , "---" ,
  907. "CIRQ", "OBI" , "---", "---", "---" , "---" , "---" , "ERRI",
  908. "CTO" , "CCRC", "CEB", "CIE", "DTO" , "DCRC", "DEB" , "---" ,
  909. "ACE" , "---" , "---", "---", "CERR", "BADA", "---" , "---"
  910. };
  911. char res[256];
  912. char *buf = res;
  913. int len, i;
  914. len = sprintf(buf, "MMC IRQ 0x%x :", status);
  915. buf += len;
  916. for (i = 0; i < ARRAY_SIZE(omap_hsmmc_status_bits); i++)
  917. if (status & (1 << i)) {
  918. len = sprintf(buf, " %s", omap_hsmmc_status_bits[i]);
  919. buf += len;
  920. }
  921. dev_vdbg(mmc_dev(host->mmc), "%s\n", res);
  922. }
  923. #else
  924. static inline void omap_hsmmc_dbg_report_irq(struct omap_hsmmc_host *host,
  925. u32 status)
  926. {
  927. }
  928. #endif /* CONFIG_MMC_DEBUG */
  929. /*
  930. * MMC controller internal state machines reset
  931. *
  932. * Used to reset command or data internal state machines, using respectively
  933. * SRC or SRD bit of SYSCTL register
  934. * Can be called from interrupt context
  935. */
  936. static inline void omap_hsmmc_reset_controller_fsm(struct omap_hsmmc_host *host,
  937. unsigned long bit)
  938. {
  939. unsigned long i = 0;
  940. unsigned long limit = MMC_TIMEOUT_US;
  941. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  942. OMAP_HSMMC_READ(host->base, SYSCTL) | bit);
  943. /*
  944. * OMAP4 ES2 and greater has an updated reset logic.
  945. * Monitor a 0->1 transition first
  946. */
  947. if (mmc_pdata(host)->features & HSMMC_HAS_UPDATED_RESET) {
  948. while ((!(OMAP_HSMMC_READ(host->base, SYSCTL) & bit))
  949. && (i++ < limit))
  950. udelay(1);
  951. }
  952. i = 0;
  953. while ((OMAP_HSMMC_READ(host->base, SYSCTL) & bit) &&
  954. (i++ < limit))
  955. udelay(1);
  956. if (OMAP_HSMMC_READ(host->base, SYSCTL) & bit)
  957. dev_err(mmc_dev(host->mmc),
  958. "Timeout waiting on controller reset in %s\n",
  959. __func__);
  960. }
  961. static void hsmmc_command_incomplete(struct omap_hsmmc_host *host,
  962. int err, int end_cmd)
  963. {
  964. if (end_cmd) {
  965. omap_hsmmc_reset_controller_fsm(host, SRC);
  966. if (host->cmd)
  967. host->cmd->error = err;
  968. }
  969. if (host->data) {
  970. omap_hsmmc_reset_controller_fsm(host, SRD);
  971. omap_hsmmc_dma_cleanup(host, err);
  972. } else if (host->mrq && host->mrq->cmd)
  973. host->mrq->cmd->error = err;
  974. }
  975. static void omap_hsmmc_do_irq(struct omap_hsmmc_host *host, int status)
  976. {
  977. struct mmc_data *data;
  978. int end_cmd = 0, end_trans = 0;
  979. int error = 0;
  980. data = host->data;
  981. dev_vdbg(mmc_dev(host->mmc), "IRQ Status is %x\n", status);
  982. if (status & ERR_EN) {
  983. omap_hsmmc_dbg_report_irq(host, status);
  984. if (status & (CTO_EN | CCRC_EN))
  985. end_cmd = 1;
  986. if (host->data || host->response_busy) {
  987. end_trans = !end_cmd;
  988. host->response_busy = 0;
  989. }
  990. if (status & (CTO_EN | DTO_EN))
  991. hsmmc_command_incomplete(host, -ETIMEDOUT, end_cmd);
  992. else if (status & (CCRC_EN | DCRC_EN | DEB_EN | CEB_EN |
  993. BADA_EN))
  994. hsmmc_command_incomplete(host, -EILSEQ, end_cmd);
  995. if (status & ACE_EN) {
  996. u32 ac12;
  997. ac12 = OMAP_HSMMC_READ(host->base, AC12);
  998. if (!(ac12 & ACNE) && host->mrq->sbc) {
  999. end_cmd = 1;
  1000. if (ac12 & ACTO)
  1001. error = -ETIMEDOUT;
  1002. else if (ac12 & (ACCE | ACEB | ACIE))
  1003. error = -EILSEQ;
  1004. host->mrq->sbc->error = error;
  1005. hsmmc_command_incomplete(host, error, end_cmd);
  1006. }
  1007. dev_dbg(mmc_dev(host->mmc), "AC12 err: 0x%x\n", ac12);
  1008. }
  1009. }
  1010. OMAP_HSMMC_WRITE(host->base, STAT, status);
  1011. if (end_cmd || ((status & CC_EN) && host->cmd))
  1012. omap_hsmmc_cmd_done(host, host->cmd);
  1013. if ((end_trans || (status & TC_EN)) && host->mrq)
  1014. omap_hsmmc_xfer_done(host, data);
  1015. }
  1016. /*
  1017. * MMC controller IRQ handler
  1018. */
  1019. static irqreturn_t omap_hsmmc_irq(int irq, void *dev_id)
  1020. {
  1021. struct omap_hsmmc_host *host = dev_id;
  1022. int status;
  1023. status = OMAP_HSMMC_READ(host->base, STAT);
  1024. while (status & (INT_EN_MASK | CIRQ_EN)) {
  1025. if (host->req_in_progress)
  1026. omap_hsmmc_do_irq(host, status);
  1027. if (status & CIRQ_EN)
  1028. mmc_signal_sdio_irq(host->mmc);
  1029. /* Flush posted write */
  1030. status = OMAP_HSMMC_READ(host->base, STAT);
  1031. }
  1032. return IRQ_HANDLED;
  1033. }
  1034. static void set_sd_bus_power(struct omap_hsmmc_host *host)
  1035. {
  1036. unsigned long i;
  1037. OMAP_HSMMC_WRITE(host->base, HCTL,
  1038. OMAP_HSMMC_READ(host->base, HCTL) | SDBP);
  1039. for (i = 0; i < loops_per_jiffy; i++) {
  1040. if (OMAP_HSMMC_READ(host->base, HCTL) & SDBP)
  1041. break;
  1042. cpu_relax();
  1043. }
  1044. }
  1045. /*
  1046. * Switch MMC interface voltage ... only relevant for MMC1.
  1047. *
  1048. * MMC2 and MMC3 use fixed 1.8V levels, and maybe a transceiver.
  1049. * The MMC2 transceiver controls are used instead of DAT4..DAT7.
  1050. * Some chips, like eMMC ones, use internal transceivers.
  1051. */
  1052. static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd)
  1053. {
  1054. u32 reg_val = 0;
  1055. int ret;
  1056. /* Disable the clocks */
  1057. if (host->dbclk)
  1058. clk_disable_unprepare(host->dbclk);
  1059. /* Turn the power off */
  1060. ret = omap_hsmmc_set_power(host, 0, 0);
  1061. /* Turn the power ON with given VDD 1.8 or 3.0v */
  1062. if (!ret)
  1063. ret = omap_hsmmc_set_power(host, 1, vdd);
  1064. if (host->dbclk)
  1065. clk_prepare_enable(host->dbclk);
  1066. if (ret != 0)
  1067. goto err;
  1068. OMAP_HSMMC_WRITE(host->base, HCTL,
  1069. OMAP_HSMMC_READ(host->base, HCTL) & SDVSCLR);
  1070. reg_val = OMAP_HSMMC_READ(host->base, HCTL);
  1071. /*
  1072. * If a MMC dual voltage card is detected, the set_ios fn calls
  1073. * this fn with VDD bit set for 1.8V. Upon card removal from the
  1074. * slot, omap_hsmmc_set_ios sets the VDD back to 3V on MMC_POWER_OFF.
  1075. *
  1076. * Cope with a bit of slop in the range ... per data sheets:
  1077. * - "1.8V" for vdds_mmc1/vdds_mmc1a can be up to 2.45V max,
  1078. * but recommended values are 1.71V to 1.89V
  1079. * - "3.0V" for vdds_mmc1/vdds_mmc1a can be up to 3.5V max,
  1080. * but recommended values are 2.7V to 3.3V
  1081. *
  1082. * Board setup code shouldn't permit anything very out-of-range.
  1083. * TWL4030-family VMMC1 and VSIM regulators are fine (avoiding the
  1084. * middle range) but VSIM can't power DAT4..DAT7 at more than 3V.
  1085. */
  1086. if ((1 << vdd) <= MMC_VDD_23_24)
  1087. reg_val |= SDVS18;
  1088. else
  1089. reg_val |= SDVS30;
  1090. OMAP_HSMMC_WRITE(host->base, HCTL, reg_val);
  1091. set_sd_bus_power(host);
  1092. return 0;
  1093. err:
  1094. dev_err(mmc_dev(host->mmc), "Unable to switch operating voltage\n");
  1095. return ret;
  1096. }
  1097. /* Protect the card while the cover is open */
  1098. static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host)
  1099. {
  1100. if (!host->get_cover_state)
  1101. return;
  1102. host->reqs_blocked = 0;
  1103. if (host->get_cover_state(host->dev)) {
  1104. if (host->protect_card) {
  1105. dev_info(host->dev, "%s: cover is closed, "
  1106. "card is now accessible\n",
  1107. mmc_hostname(host->mmc));
  1108. host->protect_card = 0;
  1109. }
  1110. } else {
  1111. if (!host->protect_card) {
  1112. dev_info(host->dev, "%s: cover is open, "
  1113. "card is now inaccessible\n",
  1114. mmc_hostname(host->mmc));
  1115. host->protect_card = 1;
  1116. }
  1117. }
  1118. }
  1119. /*
  1120. * irq handler when (cell-phone) cover is mounted/removed
  1121. */
  1122. static irqreturn_t omap_hsmmc_cover_irq(int irq, void *dev_id)
  1123. {
  1124. struct omap_hsmmc_host *host = dev_id;
  1125. sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
  1126. omap_hsmmc_protect_card(host);
  1127. mmc_detect_change(host->mmc, (HZ * 200) / 1000);
  1128. return IRQ_HANDLED;
  1129. }
  1130. static void omap_hsmmc_dma_callback(void *param)
  1131. {
  1132. struct omap_hsmmc_host *host = param;
  1133. struct dma_chan *chan;
  1134. struct mmc_data *data;
  1135. int req_in_progress;
  1136. spin_lock_irq(&host->irq_lock);
  1137. if (host->dma_ch < 0) {
  1138. spin_unlock_irq(&host->irq_lock);
  1139. return;
  1140. }
  1141. data = host->mrq->data;
  1142. chan = omap_hsmmc_get_dma_chan(host, data);
  1143. if (!data->host_cookie)
  1144. dma_unmap_sg(chan->device->dev,
  1145. data->sg, data->sg_len,
  1146. omap_hsmmc_get_dma_dir(host, data));
  1147. req_in_progress = host->req_in_progress;
  1148. host->dma_ch = -1;
  1149. spin_unlock_irq(&host->irq_lock);
  1150. /* If DMA has finished after TC, complete the request */
  1151. if (!req_in_progress) {
  1152. struct mmc_request *mrq = host->mrq;
  1153. host->mrq = NULL;
  1154. mmc_request_done(host->mmc, mrq);
  1155. }
  1156. }
  1157. static int omap_hsmmc_pre_dma_transfer(struct omap_hsmmc_host *host,
  1158. struct mmc_data *data,
  1159. struct omap_hsmmc_next *next,
  1160. struct dma_chan *chan)
  1161. {
  1162. int dma_len;
  1163. if (!next && data->host_cookie &&
  1164. data->host_cookie != host->next_data.cookie) {
  1165. dev_warn(host->dev, "[%s] invalid cookie: data->host_cookie %d"
  1166. " host->next_data.cookie %d\n",
  1167. __func__, data->host_cookie, host->next_data.cookie);
  1168. data->host_cookie = 0;
  1169. }
  1170. /* Check if next job is already prepared */
  1171. if (next || data->host_cookie != host->next_data.cookie) {
  1172. dma_len = dma_map_sg(chan->device->dev, data->sg, data->sg_len,
  1173. omap_hsmmc_get_dma_dir(host, data));
  1174. } else {
  1175. dma_len = host->next_data.dma_len;
  1176. host->next_data.dma_len = 0;
  1177. }
  1178. if (dma_len == 0)
  1179. return -EINVAL;
  1180. if (next) {
  1181. next->dma_len = dma_len;
  1182. data->host_cookie = ++next->cookie < 0 ? 1 : next->cookie;
  1183. } else
  1184. host->dma_len = dma_len;
  1185. return 0;
  1186. }
  1187. /*
  1188. * Routine to configure and start DMA for the MMC card
  1189. */
  1190. static int omap_hsmmc_setup_dma_transfer(struct omap_hsmmc_host *host,
  1191. struct mmc_request *req)
  1192. {
  1193. struct dma_async_tx_descriptor *tx;
  1194. int ret = 0, i;
  1195. struct mmc_data *data = req->data;
  1196. struct dma_chan *chan;
  1197. struct dma_slave_config cfg = {
  1198. .src_addr = host->mapbase + OMAP_HSMMC_DATA,
  1199. .dst_addr = host->mapbase + OMAP_HSMMC_DATA,
  1200. .src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
  1201. .dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
  1202. .src_maxburst = data->blksz / 4,
  1203. .dst_maxburst = data->blksz / 4,
  1204. };
  1205. /* Sanity check: all the SG entries must be aligned by block size. */
  1206. for (i = 0; i < data->sg_len; i++) {
  1207. struct scatterlist *sgl;
  1208. sgl = data->sg + i;
  1209. if (sgl->length % data->blksz)
  1210. return -EINVAL;
  1211. }
  1212. if ((data->blksz % 4) != 0)
  1213. /* REVISIT: The MMC buffer increments only when MSB is written.
  1214. * Return error for blksz which is non multiple of four.
  1215. */
  1216. return -EINVAL;
  1217. BUG_ON(host->dma_ch != -1);
  1218. chan = omap_hsmmc_get_dma_chan(host, data);
  1219. ret = dmaengine_slave_config(chan, &cfg);
  1220. if (ret)
  1221. return ret;
  1222. ret = omap_hsmmc_pre_dma_transfer(host, data, NULL, chan);
  1223. if (ret)
  1224. return ret;
  1225. tx = dmaengine_prep_slave_sg(chan, data->sg, data->sg_len,
  1226. data->flags & MMC_DATA_WRITE ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM,
  1227. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  1228. if (!tx) {
  1229. dev_err(mmc_dev(host->mmc), "prep_slave_sg() failed\n");
  1230. /* FIXME: cleanup */
  1231. return -1;
  1232. }
  1233. tx->callback = omap_hsmmc_dma_callback;
  1234. tx->callback_param = host;
  1235. /* Does not fail */
  1236. dmaengine_submit(tx);
  1237. host->dma_ch = 1;
  1238. return 0;
  1239. }
  1240. static void set_data_timeout(struct omap_hsmmc_host *host,
  1241. unsigned int timeout_ns,
  1242. unsigned int timeout_clks)
  1243. {
  1244. unsigned int timeout, cycle_ns;
  1245. uint32_t reg, clkd, dto = 0;
  1246. reg = OMAP_HSMMC_READ(host->base, SYSCTL);
  1247. clkd = (reg & CLKD_MASK) >> CLKD_SHIFT;
  1248. if (clkd == 0)
  1249. clkd = 1;
  1250. cycle_ns = 1000000000 / (host->clk_rate / clkd);
  1251. timeout = timeout_ns / cycle_ns;
  1252. timeout += timeout_clks;
  1253. if (timeout) {
  1254. while ((timeout & 0x80000000) == 0) {
  1255. dto += 1;
  1256. timeout <<= 1;
  1257. }
  1258. dto = 31 - dto;
  1259. timeout <<= 1;
  1260. if (timeout && dto)
  1261. dto += 1;
  1262. if (dto >= 13)
  1263. dto -= 13;
  1264. else
  1265. dto = 0;
  1266. if (dto > 14)
  1267. dto = 14;
  1268. }
  1269. reg &= ~DTO_MASK;
  1270. reg |= dto << DTO_SHIFT;
  1271. OMAP_HSMMC_WRITE(host->base, SYSCTL, reg);
  1272. }
  1273. static void omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host)
  1274. {
  1275. struct mmc_request *req = host->mrq;
  1276. struct dma_chan *chan;
  1277. if (!req->data)
  1278. return;
  1279. OMAP_HSMMC_WRITE(host->base, BLK, (req->data->blksz)
  1280. | (req->data->blocks << 16));
  1281. set_data_timeout(host, req->data->timeout_ns,
  1282. req->data->timeout_clks);
  1283. chan = omap_hsmmc_get_dma_chan(host, req->data);
  1284. dma_async_issue_pending(chan);
  1285. }
  1286. /*
  1287. * Configure block length for MMC/SD cards and initiate the transfer.
  1288. */
  1289. static int
  1290. omap_hsmmc_prepare_data(struct omap_hsmmc_host *host, struct mmc_request *req)
  1291. {
  1292. int ret;
  1293. host->data = req->data;
  1294. if (req->data == NULL) {
  1295. OMAP_HSMMC_WRITE(host->base, BLK, 0);
  1296. /*
  1297. * Set an arbitrary 100ms data timeout for commands with
  1298. * busy signal.
  1299. */
  1300. if (req->cmd->flags & MMC_RSP_BUSY)
  1301. set_data_timeout(host, 100000000U, 0);
  1302. return 0;
  1303. }
  1304. if (host->use_dma) {
  1305. ret = omap_hsmmc_setup_dma_transfer(host, req);
  1306. if (ret != 0) {
  1307. dev_err(mmc_dev(host->mmc), "MMC start dma failure\n");
  1308. return ret;
  1309. }
  1310. }
  1311. return 0;
  1312. }
  1313. static void omap_hsmmc_post_req(struct mmc_host *mmc, struct mmc_request *mrq,
  1314. int err)
  1315. {
  1316. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1317. struct mmc_data *data = mrq->data;
  1318. if (host->use_dma && data->host_cookie) {
  1319. struct dma_chan *c = omap_hsmmc_get_dma_chan(host, data);
  1320. dma_unmap_sg(c->device->dev, data->sg, data->sg_len,
  1321. omap_hsmmc_get_dma_dir(host, data));
  1322. data->host_cookie = 0;
  1323. }
  1324. }
  1325. static void omap_hsmmc_pre_req(struct mmc_host *mmc, struct mmc_request *mrq,
  1326. bool is_first_req)
  1327. {
  1328. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1329. if (mrq->data->host_cookie) {
  1330. mrq->data->host_cookie = 0;
  1331. return ;
  1332. }
  1333. if (host->use_dma) {
  1334. struct dma_chan *c = omap_hsmmc_get_dma_chan(host, mrq->data);
  1335. if (omap_hsmmc_pre_dma_transfer(host, mrq->data,
  1336. &host->next_data, c))
  1337. mrq->data->host_cookie = 0;
  1338. }
  1339. }
  1340. /*
  1341. * Request function. for read/write operation
  1342. */
  1343. static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req)
  1344. {
  1345. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1346. int err;
  1347. BUG_ON(host->req_in_progress);
  1348. BUG_ON(host->dma_ch != -1);
  1349. if (host->protect_card) {
  1350. if (host->reqs_blocked < 3) {
  1351. /*
  1352. * Ensure the controller is left in a consistent
  1353. * state by resetting the command and data state
  1354. * machines.
  1355. */
  1356. omap_hsmmc_reset_controller_fsm(host, SRD);
  1357. omap_hsmmc_reset_controller_fsm(host, SRC);
  1358. host->reqs_blocked += 1;
  1359. }
  1360. req->cmd->error = -EBADF;
  1361. if (req->data)
  1362. req->data->error = -EBADF;
  1363. req->cmd->retries = 0;
  1364. mmc_request_done(mmc, req);
  1365. return;
  1366. } else if (host->reqs_blocked)
  1367. host->reqs_blocked = 0;
  1368. WARN_ON(host->mrq != NULL);
  1369. host->mrq = req;
  1370. host->clk_rate = clk_get_rate(host->fclk);
  1371. err = omap_hsmmc_prepare_data(host, req);
  1372. if (err) {
  1373. req->cmd->error = err;
  1374. if (req->data)
  1375. req->data->error = err;
  1376. host->mrq = NULL;
  1377. mmc_request_done(mmc, req);
  1378. return;
  1379. }
  1380. if (req->sbc && !(host->flags & AUTO_CMD23)) {
  1381. omap_hsmmc_start_command(host, req->sbc, NULL);
  1382. return;
  1383. }
  1384. omap_hsmmc_start_dma_transfer(host);
  1385. omap_hsmmc_start_command(host, req->cmd, req->data);
  1386. }
  1387. /* Routine to configure clock values. Exposed API to core */
  1388. static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  1389. {
  1390. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1391. int do_send_init_stream = 0;
  1392. if (ios->power_mode != host->power_mode) {
  1393. switch (ios->power_mode) {
  1394. case MMC_POWER_OFF:
  1395. omap_hsmmc_set_power(host, 0, 0);
  1396. break;
  1397. case MMC_POWER_UP:
  1398. omap_hsmmc_set_power(host, 1, ios->vdd);
  1399. break;
  1400. case MMC_POWER_ON:
  1401. do_send_init_stream = 1;
  1402. break;
  1403. }
  1404. host->power_mode = ios->power_mode;
  1405. }
  1406. /* FIXME: set registers based only on changes to ios */
  1407. omap_hsmmc_set_bus_width(host);
  1408. if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) {
  1409. /* Only MMC1 can interface at 3V without some flavor
  1410. * of external transceiver; but they all handle 1.8V.
  1411. */
  1412. if ((OMAP_HSMMC_READ(host->base, HCTL) & SDVSDET) &&
  1413. (ios->vdd == DUAL_VOLT_OCR_BIT)) {
  1414. /*
  1415. * The mmc_select_voltage fn of the core does
  1416. * not seem to set the power_mode to
  1417. * MMC_POWER_UP upon recalculating the voltage.
  1418. * vdd 1.8v.
  1419. */
  1420. if (omap_hsmmc_switch_opcond(host, ios->vdd) != 0)
  1421. dev_dbg(mmc_dev(host->mmc),
  1422. "Switch operation failed\n");
  1423. }
  1424. }
  1425. omap_hsmmc_set_clock(host);
  1426. if (do_send_init_stream)
  1427. send_init_stream(host);
  1428. omap_hsmmc_set_bus_mode(host);
  1429. }
  1430. static int omap_hsmmc_get_cd(struct mmc_host *mmc)
  1431. {
  1432. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1433. if (!host->card_detect)
  1434. return -ENOSYS;
  1435. return host->card_detect(host->dev);
  1436. }
  1437. static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card)
  1438. {
  1439. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1440. if (mmc_pdata(host)->init_card)
  1441. mmc_pdata(host)->init_card(card);
  1442. }
  1443. static void omap_hsmmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
  1444. {
  1445. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1446. u32 irq_mask, con;
  1447. unsigned long flags;
  1448. spin_lock_irqsave(&host->irq_lock, flags);
  1449. con = OMAP_HSMMC_READ(host->base, CON);
  1450. irq_mask = OMAP_HSMMC_READ(host->base, ISE);
  1451. if (enable) {
  1452. host->flags |= HSMMC_SDIO_IRQ_ENABLED;
  1453. irq_mask |= CIRQ_EN;
  1454. con |= CTPL | CLKEXTFREE;
  1455. } else {
  1456. host->flags &= ~HSMMC_SDIO_IRQ_ENABLED;
  1457. irq_mask &= ~CIRQ_EN;
  1458. con &= ~(CTPL | CLKEXTFREE);
  1459. }
  1460. OMAP_HSMMC_WRITE(host->base, CON, con);
  1461. OMAP_HSMMC_WRITE(host->base, IE, irq_mask);
  1462. /*
  1463. * if enable, piggy back detection on current request
  1464. * but always disable immediately
  1465. */
  1466. if (!host->req_in_progress || !enable)
  1467. OMAP_HSMMC_WRITE(host->base, ISE, irq_mask);
  1468. /* flush posted write */
  1469. OMAP_HSMMC_READ(host->base, IE);
  1470. spin_unlock_irqrestore(&host->irq_lock, flags);
  1471. }
  1472. static int omap_hsmmc_configure_wake_irq(struct omap_hsmmc_host *host)
  1473. {
  1474. int ret;
  1475. /*
  1476. * For omaps with wake-up path, wakeirq will be irq from pinctrl and
  1477. * for other omaps, wakeirq will be from GPIO (dat line remuxed to
  1478. * gpio). wakeirq is needed to detect sdio irq in runtime suspend state
  1479. * with functional clock disabled.
  1480. */
  1481. if (!host->dev->of_node || !host->wake_irq)
  1482. return -ENODEV;
  1483. ret = dev_pm_set_dedicated_wake_irq(host->dev, host->wake_irq);
  1484. if (ret) {
  1485. dev_err(mmc_dev(host->mmc), "Unable to request wake IRQ\n");
  1486. goto err;
  1487. }
  1488. /*
  1489. * Some omaps don't have wake-up path from deeper idle states
  1490. * and need to remux SDIO DAT1 to GPIO for wake-up from idle.
  1491. */
  1492. if (host->pdata->controller_flags & OMAP_HSMMC_SWAKEUP_MISSING) {
  1493. struct pinctrl *p = devm_pinctrl_get(host->dev);
  1494. if (IS_ERR(p)) {
  1495. ret = PTR_ERR(p);
  1496. goto err_free_irq;
  1497. }
  1498. if (IS_ERR(pinctrl_lookup_state(p, PINCTRL_STATE_DEFAULT))) {
  1499. dev_info(host->dev, "missing default pinctrl state\n");
  1500. devm_pinctrl_put(p);
  1501. ret = -EINVAL;
  1502. goto err_free_irq;
  1503. }
  1504. if (IS_ERR(pinctrl_lookup_state(p, PINCTRL_STATE_IDLE))) {
  1505. dev_info(host->dev, "missing idle pinctrl state\n");
  1506. devm_pinctrl_put(p);
  1507. ret = -EINVAL;
  1508. goto err_free_irq;
  1509. }
  1510. devm_pinctrl_put(p);
  1511. }
  1512. OMAP_HSMMC_WRITE(host->base, HCTL,
  1513. OMAP_HSMMC_READ(host->base, HCTL) | IWE);
  1514. return 0;
  1515. err_free_irq:
  1516. dev_pm_clear_wake_irq(host->dev);
  1517. err:
  1518. dev_warn(host->dev, "no SDIO IRQ support, falling back to polling\n");
  1519. host->wake_irq = 0;
  1520. return ret;
  1521. }
  1522. static void omap_hsmmc_conf_bus_power(struct omap_hsmmc_host *host)
  1523. {
  1524. u32 hctl, capa, value;
  1525. /* Only MMC1 supports 3.0V */
  1526. if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) {
  1527. hctl = SDVS30;
  1528. capa = VS30 | VS18;
  1529. } else {
  1530. hctl = SDVS18;
  1531. capa = VS18;
  1532. }
  1533. value = OMAP_HSMMC_READ(host->base, HCTL) & ~SDVS_MASK;
  1534. OMAP_HSMMC_WRITE(host->base, HCTL, value | hctl);
  1535. value = OMAP_HSMMC_READ(host->base, CAPA);
  1536. OMAP_HSMMC_WRITE(host->base, CAPA, value | capa);
  1537. /* Set SD bus power bit */
  1538. set_sd_bus_power(host);
  1539. }
  1540. static int omap_hsmmc_multi_io_quirk(struct mmc_card *card,
  1541. unsigned int direction, int blk_size)
  1542. {
  1543. /* This controller can't do multiblock reads due to hw bugs */
  1544. if (direction == MMC_DATA_READ)
  1545. return 1;
  1546. return blk_size;
  1547. }
  1548. static struct mmc_host_ops omap_hsmmc_ops = {
  1549. .post_req = omap_hsmmc_post_req,
  1550. .pre_req = omap_hsmmc_pre_req,
  1551. .request = omap_hsmmc_request,
  1552. .set_ios = omap_hsmmc_set_ios,
  1553. .get_cd = omap_hsmmc_get_cd,
  1554. .get_ro = mmc_gpio_get_ro,
  1555. .init_card = omap_hsmmc_init_card,
  1556. .enable_sdio_irq = omap_hsmmc_enable_sdio_irq,
  1557. };
  1558. #ifdef CONFIG_DEBUG_FS
  1559. static int omap_hsmmc_regs_show(struct seq_file *s, void *data)
  1560. {
  1561. struct mmc_host *mmc = s->private;
  1562. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1563. seq_printf(s, "mmc%d:\n", mmc->index);
  1564. seq_printf(s, "sdio irq mode\t%s\n",
  1565. (mmc->caps & MMC_CAP_SDIO_IRQ) ? "interrupt" : "polling");
  1566. if (mmc->caps & MMC_CAP_SDIO_IRQ) {
  1567. seq_printf(s, "sdio irq \t%s\n",
  1568. (host->flags & HSMMC_SDIO_IRQ_ENABLED) ? "enabled"
  1569. : "disabled");
  1570. }
  1571. seq_printf(s, "ctx_loss:\t%d\n", host->context_loss);
  1572. pm_runtime_get_sync(host->dev);
  1573. seq_puts(s, "\nregs:\n");
  1574. seq_printf(s, "CON:\t\t0x%08x\n",
  1575. OMAP_HSMMC_READ(host->base, CON));
  1576. seq_printf(s, "PSTATE:\t\t0x%08x\n",
  1577. OMAP_HSMMC_READ(host->base, PSTATE));
  1578. seq_printf(s, "HCTL:\t\t0x%08x\n",
  1579. OMAP_HSMMC_READ(host->base, HCTL));
  1580. seq_printf(s, "SYSCTL:\t\t0x%08x\n",
  1581. OMAP_HSMMC_READ(host->base, SYSCTL));
  1582. seq_printf(s, "IE:\t\t0x%08x\n",
  1583. OMAP_HSMMC_READ(host->base, IE));
  1584. seq_printf(s, "ISE:\t\t0x%08x\n",
  1585. OMAP_HSMMC_READ(host->base, ISE));
  1586. seq_printf(s, "CAPA:\t\t0x%08x\n",
  1587. OMAP_HSMMC_READ(host->base, CAPA));
  1588. pm_runtime_mark_last_busy(host->dev);
  1589. pm_runtime_put_autosuspend(host->dev);
  1590. return 0;
  1591. }
  1592. static int omap_hsmmc_regs_open(struct inode *inode, struct file *file)
  1593. {
  1594. return single_open(file, omap_hsmmc_regs_show, inode->i_private);
  1595. }
  1596. static const struct file_operations mmc_regs_fops = {
  1597. .open = omap_hsmmc_regs_open,
  1598. .read = seq_read,
  1599. .llseek = seq_lseek,
  1600. .release = single_release,
  1601. };
  1602. static void omap_hsmmc_debugfs(struct mmc_host *mmc)
  1603. {
  1604. if (mmc->debugfs_root)
  1605. debugfs_create_file("regs", S_IRUSR, mmc->debugfs_root,
  1606. mmc, &mmc_regs_fops);
  1607. }
  1608. #else
  1609. static void omap_hsmmc_debugfs(struct mmc_host *mmc)
  1610. {
  1611. }
  1612. #endif
  1613. #ifdef CONFIG_OF
  1614. static const struct omap_mmc_of_data omap3_pre_es3_mmc_of_data = {
  1615. /* See 35xx errata 2.1.1.128 in SPRZ278F */
  1616. .controller_flags = OMAP_HSMMC_BROKEN_MULTIBLOCK_READ,
  1617. };
  1618. static const struct omap_mmc_of_data omap4_mmc_of_data = {
  1619. .reg_offset = 0x100,
  1620. };
  1621. static const struct omap_mmc_of_data am33xx_mmc_of_data = {
  1622. .reg_offset = 0x100,
  1623. .controller_flags = OMAP_HSMMC_SWAKEUP_MISSING,
  1624. };
  1625. static const struct of_device_id omap_mmc_of_match[] = {
  1626. {
  1627. .compatible = "ti,omap2-hsmmc",
  1628. },
  1629. {
  1630. .compatible = "ti,omap3-pre-es3-hsmmc",
  1631. .data = &omap3_pre_es3_mmc_of_data,
  1632. },
  1633. {
  1634. .compatible = "ti,omap3-hsmmc",
  1635. },
  1636. {
  1637. .compatible = "ti,omap4-hsmmc",
  1638. .data = &omap4_mmc_of_data,
  1639. },
  1640. {
  1641. .compatible = "ti,am33xx-hsmmc",
  1642. .data = &am33xx_mmc_of_data,
  1643. },
  1644. {},
  1645. };
  1646. MODULE_DEVICE_TABLE(of, omap_mmc_of_match);
  1647. static struct omap_hsmmc_platform_data *of_get_hsmmc_pdata(struct device *dev)
  1648. {
  1649. struct omap_hsmmc_platform_data *pdata, *legacy;
  1650. struct device_node *np = dev->of_node;
  1651. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  1652. if (!pdata)
  1653. return ERR_PTR(-ENOMEM); /* out of memory */
  1654. legacy = dev_get_platdata(dev);
  1655. if (legacy && legacy->name)
  1656. pdata->name = legacy->name;
  1657. if (of_find_property(np, "ti,dual-volt", NULL))
  1658. pdata->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT;
  1659. pdata->gpio_cd = -EINVAL;
  1660. pdata->gpio_cod = -EINVAL;
  1661. pdata->gpio_wp = -EINVAL;
  1662. if (of_find_property(np, "ti,non-removable", NULL)) {
  1663. pdata->nonremovable = true;
  1664. pdata->no_regulator_off_init = true;
  1665. }
  1666. if (of_find_property(np, "ti,needs-special-reset", NULL))
  1667. pdata->features |= HSMMC_HAS_UPDATED_RESET;
  1668. if (of_find_property(np, "ti,needs-special-hs-handling", NULL))
  1669. pdata->features |= HSMMC_HAS_HSPE_SUPPORT;
  1670. return pdata;
  1671. }
  1672. #else
  1673. static inline struct omap_hsmmc_platform_data
  1674. *of_get_hsmmc_pdata(struct device *dev)
  1675. {
  1676. return ERR_PTR(-EINVAL);
  1677. }
  1678. #endif
  1679. static int omap_hsmmc_probe(struct platform_device *pdev)
  1680. {
  1681. struct omap_hsmmc_platform_data *pdata = pdev->dev.platform_data;
  1682. struct mmc_host *mmc;
  1683. struct omap_hsmmc_host *host = NULL;
  1684. struct resource *res;
  1685. int ret, irq;
  1686. const struct of_device_id *match;
  1687. const struct omap_mmc_of_data *data;
  1688. void __iomem *base;
  1689. match = of_match_device(of_match_ptr(omap_mmc_of_match), &pdev->dev);
  1690. if (match) {
  1691. pdata = of_get_hsmmc_pdata(&pdev->dev);
  1692. if (IS_ERR(pdata))
  1693. return PTR_ERR(pdata);
  1694. if (match->data) {
  1695. data = match->data;
  1696. pdata->reg_offset = data->reg_offset;
  1697. pdata->controller_flags |= data->controller_flags;
  1698. }
  1699. }
  1700. if (pdata == NULL) {
  1701. dev_err(&pdev->dev, "Platform Data is missing\n");
  1702. return -ENXIO;
  1703. }
  1704. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1705. irq = platform_get_irq(pdev, 0);
  1706. if (res == NULL || irq < 0)
  1707. return -ENXIO;
  1708. base = devm_ioremap_resource(&pdev->dev, res);
  1709. if (IS_ERR(base))
  1710. return PTR_ERR(base);
  1711. mmc = mmc_alloc_host(sizeof(struct omap_hsmmc_host), &pdev->dev);
  1712. if (!mmc) {
  1713. ret = -ENOMEM;
  1714. goto err;
  1715. }
  1716. ret = mmc_of_parse(mmc);
  1717. if (ret)
  1718. goto err1;
  1719. host = mmc_priv(mmc);
  1720. host->mmc = mmc;
  1721. host->pdata = pdata;
  1722. host->dev = &pdev->dev;
  1723. host->use_dma = 1;
  1724. host->dma_ch = -1;
  1725. host->irq = irq;
  1726. host->mapbase = res->start + pdata->reg_offset;
  1727. host->base = base + pdata->reg_offset;
  1728. host->power_mode = MMC_POWER_OFF;
  1729. host->next_data.cookie = 1;
  1730. host->pbias_enabled = 0;
  1731. host->vqmmc_enabled = 0;
  1732. ret = omap_hsmmc_gpio_init(mmc, host, pdata);
  1733. if (ret)
  1734. goto err_gpio;
  1735. platform_set_drvdata(pdev, host);
  1736. if (pdev->dev.of_node)
  1737. host->wake_irq = irq_of_parse_and_map(pdev->dev.of_node, 1);
  1738. mmc->ops = &omap_hsmmc_ops;
  1739. mmc->f_min = OMAP_MMC_MIN_CLOCK;
  1740. if (pdata->max_freq > 0)
  1741. mmc->f_max = pdata->max_freq;
  1742. else if (mmc->f_max == 0)
  1743. mmc->f_max = OMAP_MMC_MAX_CLOCK;
  1744. spin_lock_init(&host->irq_lock);
  1745. host->fclk = devm_clk_get(&pdev->dev, "fck");
  1746. if (IS_ERR(host->fclk)) {
  1747. ret = PTR_ERR(host->fclk);
  1748. host->fclk = NULL;
  1749. goto err1;
  1750. }
  1751. if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) {
  1752. dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
  1753. omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
  1754. }
  1755. device_init_wakeup(&pdev->dev, true);
  1756. pm_runtime_enable(host->dev);
  1757. pm_runtime_get_sync(host->dev);
  1758. pm_runtime_set_autosuspend_delay(host->dev, MMC_AUTOSUSPEND_DELAY);
  1759. pm_runtime_use_autosuspend(host->dev);
  1760. omap_hsmmc_context_save(host);
  1761. host->dbclk = devm_clk_get(&pdev->dev, "mmchsdb_fck");
  1762. /*
  1763. * MMC can still work without debounce clock.
  1764. */
  1765. if (IS_ERR(host->dbclk)) {
  1766. host->dbclk = NULL;
  1767. } else if (clk_prepare_enable(host->dbclk) != 0) {
  1768. dev_warn(mmc_dev(host->mmc), "Failed to enable debounce clk\n");
  1769. host->dbclk = NULL;
  1770. }
  1771. /* Since we do only SG emulation, we can have as many segs
  1772. * as we want. */
  1773. mmc->max_segs = 1024;
  1774. mmc->max_blk_size = 512; /* Block Length at max can be 1024 */
  1775. mmc->max_blk_count = 0xFFFF; /* No. of Blocks is 16 bits */
  1776. mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
  1777. mmc->max_seg_size = mmc->max_req_size;
  1778. mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
  1779. MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE;
  1780. mmc->caps |= mmc_pdata(host)->caps;
  1781. if (mmc->caps & MMC_CAP_8_BIT_DATA)
  1782. mmc->caps |= MMC_CAP_4_BIT_DATA;
  1783. if (mmc_pdata(host)->nonremovable)
  1784. mmc->caps |= MMC_CAP_NONREMOVABLE;
  1785. mmc->pm_caps |= mmc_pdata(host)->pm_caps;
  1786. omap_hsmmc_conf_bus_power(host);
  1787. host->rx_chan = dma_request_chan(&pdev->dev, "rx");
  1788. if (IS_ERR(host->rx_chan)) {
  1789. dev_err(mmc_dev(host->mmc), "RX DMA channel request failed\n");
  1790. ret = PTR_ERR(host->rx_chan);
  1791. goto err_irq;
  1792. }
  1793. host->tx_chan = dma_request_chan(&pdev->dev, "tx");
  1794. if (IS_ERR(host->tx_chan)) {
  1795. dev_err(mmc_dev(host->mmc), "TX DMA channel request failed\n");
  1796. ret = PTR_ERR(host->tx_chan);
  1797. goto err_irq;
  1798. }
  1799. /* Request IRQ for MMC operations */
  1800. ret = devm_request_irq(&pdev->dev, host->irq, omap_hsmmc_irq, 0,
  1801. mmc_hostname(mmc), host);
  1802. if (ret) {
  1803. dev_err(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n");
  1804. goto err_irq;
  1805. }
  1806. ret = omap_hsmmc_reg_get(host);
  1807. if (ret)
  1808. goto err_irq;
  1809. mmc->ocr_avail = mmc_pdata(host)->ocr_mask;
  1810. omap_hsmmc_disable_irq(host);
  1811. /*
  1812. * For now, only support SDIO interrupt if we have a separate
  1813. * wake-up interrupt configured from device tree. This is because
  1814. * the wake-up interrupt is needed for idle state and some
  1815. * platforms need special quirks. And we don't want to add new
  1816. * legacy mux platform init code callbacks any longer as we
  1817. * are moving to DT based booting anyways.
  1818. */
  1819. ret = omap_hsmmc_configure_wake_irq(host);
  1820. if (!ret)
  1821. mmc->caps |= MMC_CAP_SDIO_IRQ;
  1822. omap_hsmmc_protect_card(host);
  1823. mmc_add_host(mmc);
  1824. if (mmc_pdata(host)->name != NULL) {
  1825. ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name);
  1826. if (ret < 0)
  1827. goto err_slot_name;
  1828. }
  1829. if (host->get_cover_state) {
  1830. ret = device_create_file(&mmc->class_dev,
  1831. &dev_attr_cover_switch);
  1832. if (ret < 0)
  1833. goto err_slot_name;
  1834. }
  1835. omap_hsmmc_debugfs(mmc);
  1836. pm_runtime_mark_last_busy(host->dev);
  1837. pm_runtime_put_autosuspend(host->dev);
  1838. return 0;
  1839. err_slot_name:
  1840. mmc_remove_host(mmc);
  1841. err_irq:
  1842. device_init_wakeup(&pdev->dev, false);
  1843. if (!IS_ERR_OR_NULL(host->tx_chan))
  1844. dma_release_channel(host->tx_chan);
  1845. if (!IS_ERR_OR_NULL(host->rx_chan))
  1846. dma_release_channel(host->rx_chan);
  1847. pm_runtime_dont_use_autosuspend(host->dev);
  1848. pm_runtime_put_sync(host->dev);
  1849. pm_runtime_disable(host->dev);
  1850. if (host->dbclk)
  1851. clk_disable_unprepare(host->dbclk);
  1852. err1:
  1853. err_gpio:
  1854. mmc_free_host(mmc);
  1855. err:
  1856. return ret;
  1857. }
  1858. static int omap_hsmmc_remove(struct platform_device *pdev)
  1859. {
  1860. struct omap_hsmmc_host *host = platform_get_drvdata(pdev);
  1861. pm_runtime_get_sync(host->dev);
  1862. mmc_remove_host(host->mmc);
  1863. dma_release_channel(host->tx_chan);
  1864. dma_release_channel(host->rx_chan);
  1865. pm_runtime_dont_use_autosuspend(host->dev);
  1866. pm_runtime_put_sync(host->dev);
  1867. pm_runtime_disable(host->dev);
  1868. device_init_wakeup(&pdev->dev, false);
  1869. if (host->dbclk)
  1870. clk_disable_unprepare(host->dbclk);
  1871. mmc_free_host(host->mmc);
  1872. return 0;
  1873. }
  1874. #ifdef CONFIG_PM_SLEEP
  1875. static int omap_hsmmc_suspend(struct device *dev)
  1876. {
  1877. struct omap_hsmmc_host *host = dev_get_drvdata(dev);
  1878. if (!host)
  1879. return 0;
  1880. pm_runtime_get_sync(host->dev);
  1881. if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) {
  1882. OMAP_HSMMC_WRITE(host->base, ISE, 0);
  1883. OMAP_HSMMC_WRITE(host->base, IE, 0);
  1884. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  1885. OMAP_HSMMC_WRITE(host->base, HCTL,
  1886. OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP);
  1887. }
  1888. if (host->dbclk)
  1889. clk_disable_unprepare(host->dbclk);
  1890. pm_runtime_put_sync(host->dev);
  1891. return 0;
  1892. }
  1893. /* Routine to resume the MMC device */
  1894. static int omap_hsmmc_resume(struct device *dev)
  1895. {
  1896. struct omap_hsmmc_host *host = dev_get_drvdata(dev);
  1897. if (!host)
  1898. return 0;
  1899. pm_runtime_get_sync(host->dev);
  1900. if (host->dbclk)
  1901. clk_prepare_enable(host->dbclk);
  1902. if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER))
  1903. omap_hsmmc_conf_bus_power(host);
  1904. omap_hsmmc_protect_card(host);
  1905. pm_runtime_mark_last_busy(host->dev);
  1906. pm_runtime_put_autosuspend(host->dev);
  1907. return 0;
  1908. }
  1909. #endif
  1910. static int omap_hsmmc_runtime_suspend(struct device *dev)
  1911. {
  1912. struct omap_hsmmc_host *host;
  1913. unsigned long flags;
  1914. int ret = 0;
  1915. host = platform_get_drvdata(to_platform_device(dev));
  1916. omap_hsmmc_context_save(host);
  1917. dev_dbg(dev, "disabled\n");
  1918. spin_lock_irqsave(&host->irq_lock, flags);
  1919. if ((host->mmc->caps & MMC_CAP_SDIO_IRQ) &&
  1920. (host->flags & HSMMC_SDIO_IRQ_ENABLED)) {
  1921. /* disable sdio irq handling to prevent race */
  1922. OMAP_HSMMC_WRITE(host->base, ISE, 0);
  1923. OMAP_HSMMC_WRITE(host->base, IE, 0);
  1924. if (!(OMAP_HSMMC_READ(host->base, PSTATE) & DLEV_DAT(1))) {
  1925. /*
  1926. * dat1 line low, pending sdio irq
  1927. * race condition: possible irq handler running on
  1928. * multi-core, abort
  1929. */
  1930. dev_dbg(dev, "pending sdio irq, abort suspend\n");
  1931. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  1932. OMAP_HSMMC_WRITE(host->base, ISE, CIRQ_EN);
  1933. OMAP_HSMMC_WRITE(host->base, IE, CIRQ_EN);
  1934. pm_runtime_mark_last_busy(dev);
  1935. ret = -EBUSY;
  1936. goto abort;
  1937. }
  1938. pinctrl_pm_select_idle_state(dev);
  1939. } else {
  1940. pinctrl_pm_select_idle_state(dev);
  1941. }
  1942. abort:
  1943. spin_unlock_irqrestore(&host->irq_lock, flags);
  1944. return ret;
  1945. }
  1946. static int omap_hsmmc_runtime_resume(struct device *dev)
  1947. {
  1948. struct omap_hsmmc_host *host;
  1949. unsigned long flags;
  1950. host = platform_get_drvdata(to_platform_device(dev));
  1951. omap_hsmmc_context_restore(host);
  1952. dev_dbg(dev, "enabled\n");
  1953. spin_lock_irqsave(&host->irq_lock, flags);
  1954. if ((host->mmc->caps & MMC_CAP_SDIO_IRQ) &&
  1955. (host->flags & HSMMC_SDIO_IRQ_ENABLED)) {
  1956. pinctrl_pm_select_default_state(host->dev);
  1957. /* irq lost, if pinmux incorrect */
  1958. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  1959. OMAP_HSMMC_WRITE(host->base, ISE, CIRQ_EN);
  1960. OMAP_HSMMC_WRITE(host->base, IE, CIRQ_EN);
  1961. } else {
  1962. pinctrl_pm_select_default_state(host->dev);
  1963. }
  1964. spin_unlock_irqrestore(&host->irq_lock, flags);
  1965. return 0;
  1966. }
  1967. static struct dev_pm_ops omap_hsmmc_dev_pm_ops = {
  1968. SET_SYSTEM_SLEEP_PM_OPS(omap_hsmmc_suspend, omap_hsmmc_resume)
  1969. .runtime_suspend = omap_hsmmc_runtime_suspend,
  1970. .runtime_resume = omap_hsmmc_runtime_resume,
  1971. };
  1972. static struct platform_driver omap_hsmmc_driver = {
  1973. .probe = omap_hsmmc_probe,
  1974. .remove = omap_hsmmc_remove,
  1975. .driver = {
  1976. .name = DRIVER_NAME,
  1977. .pm = &omap_hsmmc_dev_pm_ops,
  1978. .of_match_table = of_match_ptr(omap_mmc_of_match),
  1979. },
  1980. };
  1981. module_platform_driver(omap_hsmmc_driver);
  1982. MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver");
  1983. MODULE_LICENSE("GPL");
  1984. MODULE_ALIAS("platform:" DRIVER_NAME);
  1985. MODULE_AUTHOR("Texas Instruments Inc");