omap_hsmmc.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365
  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. {
  1327. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1328. if (mrq->data->host_cookie) {
  1329. mrq->data->host_cookie = 0;
  1330. return ;
  1331. }
  1332. if (host->use_dma) {
  1333. struct dma_chan *c = omap_hsmmc_get_dma_chan(host, mrq->data);
  1334. if (omap_hsmmc_pre_dma_transfer(host, mrq->data,
  1335. &host->next_data, c))
  1336. mrq->data->host_cookie = 0;
  1337. }
  1338. }
  1339. /*
  1340. * Request function. for read/write operation
  1341. */
  1342. static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req)
  1343. {
  1344. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1345. int err;
  1346. BUG_ON(host->req_in_progress);
  1347. BUG_ON(host->dma_ch != -1);
  1348. if (host->protect_card) {
  1349. if (host->reqs_blocked < 3) {
  1350. /*
  1351. * Ensure the controller is left in a consistent
  1352. * state by resetting the command and data state
  1353. * machines.
  1354. */
  1355. omap_hsmmc_reset_controller_fsm(host, SRD);
  1356. omap_hsmmc_reset_controller_fsm(host, SRC);
  1357. host->reqs_blocked += 1;
  1358. }
  1359. req->cmd->error = -EBADF;
  1360. if (req->data)
  1361. req->data->error = -EBADF;
  1362. req->cmd->retries = 0;
  1363. mmc_request_done(mmc, req);
  1364. return;
  1365. } else if (host->reqs_blocked)
  1366. host->reqs_blocked = 0;
  1367. WARN_ON(host->mrq != NULL);
  1368. host->mrq = req;
  1369. host->clk_rate = clk_get_rate(host->fclk);
  1370. err = omap_hsmmc_prepare_data(host, req);
  1371. if (err) {
  1372. req->cmd->error = err;
  1373. if (req->data)
  1374. req->data->error = err;
  1375. host->mrq = NULL;
  1376. mmc_request_done(mmc, req);
  1377. return;
  1378. }
  1379. if (req->sbc && !(host->flags & AUTO_CMD23)) {
  1380. omap_hsmmc_start_command(host, req->sbc, NULL);
  1381. return;
  1382. }
  1383. omap_hsmmc_start_dma_transfer(host);
  1384. omap_hsmmc_start_command(host, req->cmd, req->data);
  1385. }
  1386. /* Routine to configure clock values. Exposed API to core */
  1387. static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  1388. {
  1389. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1390. int do_send_init_stream = 0;
  1391. if (ios->power_mode != host->power_mode) {
  1392. switch (ios->power_mode) {
  1393. case MMC_POWER_OFF:
  1394. omap_hsmmc_set_power(host, 0, 0);
  1395. break;
  1396. case MMC_POWER_UP:
  1397. omap_hsmmc_set_power(host, 1, ios->vdd);
  1398. break;
  1399. case MMC_POWER_ON:
  1400. do_send_init_stream = 1;
  1401. break;
  1402. }
  1403. host->power_mode = ios->power_mode;
  1404. }
  1405. /* FIXME: set registers based only on changes to ios */
  1406. omap_hsmmc_set_bus_width(host);
  1407. if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) {
  1408. /* Only MMC1 can interface at 3V without some flavor
  1409. * of external transceiver; but they all handle 1.8V.
  1410. */
  1411. if ((OMAP_HSMMC_READ(host->base, HCTL) & SDVSDET) &&
  1412. (ios->vdd == DUAL_VOLT_OCR_BIT)) {
  1413. /*
  1414. * The mmc_select_voltage fn of the core does
  1415. * not seem to set the power_mode to
  1416. * MMC_POWER_UP upon recalculating the voltage.
  1417. * vdd 1.8v.
  1418. */
  1419. if (omap_hsmmc_switch_opcond(host, ios->vdd) != 0)
  1420. dev_dbg(mmc_dev(host->mmc),
  1421. "Switch operation failed\n");
  1422. }
  1423. }
  1424. omap_hsmmc_set_clock(host);
  1425. if (do_send_init_stream)
  1426. send_init_stream(host);
  1427. omap_hsmmc_set_bus_mode(host);
  1428. }
  1429. static int omap_hsmmc_get_cd(struct mmc_host *mmc)
  1430. {
  1431. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1432. if (!host->card_detect)
  1433. return -ENOSYS;
  1434. return host->card_detect(host->dev);
  1435. }
  1436. static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card)
  1437. {
  1438. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1439. if (mmc_pdata(host)->init_card)
  1440. mmc_pdata(host)->init_card(card);
  1441. }
  1442. static void omap_hsmmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
  1443. {
  1444. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1445. u32 irq_mask, con;
  1446. unsigned long flags;
  1447. spin_lock_irqsave(&host->irq_lock, flags);
  1448. con = OMAP_HSMMC_READ(host->base, CON);
  1449. irq_mask = OMAP_HSMMC_READ(host->base, ISE);
  1450. if (enable) {
  1451. host->flags |= HSMMC_SDIO_IRQ_ENABLED;
  1452. irq_mask |= CIRQ_EN;
  1453. con |= CTPL | CLKEXTFREE;
  1454. } else {
  1455. host->flags &= ~HSMMC_SDIO_IRQ_ENABLED;
  1456. irq_mask &= ~CIRQ_EN;
  1457. con &= ~(CTPL | CLKEXTFREE);
  1458. }
  1459. OMAP_HSMMC_WRITE(host->base, CON, con);
  1460. OMAP_HSMMC_WRITE(host->base, IE, irq_mask);
  1461. /*
  1462. * if enable, piggy back detection on current request
  1463. * but always disable immediately
  1464. */
  1465. if (!host->req_in_progress || !enable)
  1466. OMAP_HSMMC_WRITE(host->base, ISE, irq_mask);
  1467. /* flush posted write */
  1468. OMAP_HSMMC_READ(host->base, IE);
  1469. spin_unlock_irqrestore(&host->irq_lock, flags);
  1470. }
  1471. static int omap_hsmmc_configure_wake_irq(struct omap_hsmmc_host *host)
  1472. {
  1473. int ret;
  1474. /*
  1475. * For omaps with wake-up path, wakeirq will be irq from pinctrl and
  1476. * for other omaps, wakeirq will be from GPIO (dat line remuxed to
  1477. * gpio). wakeirq is needed to detect sdio irq in runtime suspend state
  1478. * with functional clock disabled.
  1479. */
  1480. if (!host->dev->of_node || !host->wake_irq)
  1481. return -ENODEV;
  1482. ret = dev_pm_set_dedicated_wake_irq(host->dev, host->wake_irq);
  1483. if (ret) {
  1484. dev_err(mmc_dev(host->mmc), "Unable to request wake IRQ\n");
  1485. goto err;
  1486. }
  1487. /*
  1488. * Some omaps don't have wake-up path from deeper idle states
  1489. * and need to remux SDIO DAT1 to GPIO for wake-up from idle.
  1490. */
  1491. if (host->pdata->controller_flags & OMAP_HSMMC_SWAKEUP_MISSING) {
  1492. struct pinctrl *p = devm_pinctrl_get(host->dev);
  1493. if (!p) {
  1494. ret = -ENODEV;
  1495. goto err_free_irq;
  1496. }
  1497. if (IS_ERR(pinctrl_lookup_state(p, PINCTRL_STATE_DEFAULT))) {
  1498. dev_info(host->dev, "missing default pinctrl state\n");
  1499. devm_pinctrl_put(p);
  1500. ret = -EINVAL;
  1501. goto err_free_irq;
  1502. }
  1503. if (IS_ERR(pinctrl_lookup_state(p, PINCTRL_STATE_IDLE))) {
  1504. dev_info(host->dev, "missing idle pinctrl state\n");
  1505. devm_pinctrl_put(p);
  1506. ret = -EINVAL;
  1507. goto err_free_irq;
  1508. }
  1509. devm_pinctrl_put(p);
  1510. }
  1511. OMAP_HSMMC_WRITE(host->base, HCTL,
  1512. OMAP_HSMMC_READ(host->base, HCTL) | IWE);
  1513. return 0;
  1514. err_free_irq:
  1515. dev_pm_clear_wake_irq(host->dev);
  1516. err:
  1517. dev_warn(host->dev, "no SDIO IRQ support, falling back to polling\n");
  1518. host->wake_irq = 0;
  1519. return ret;
  1520. }
  1521. static void omap_hsmmc_conf_bus_power(struct omap_hsmmc_host *host)
  1522. {
  1523. u32 hctl, capa, value;
  1524. /* Only MMC1 supports 3.0V */
  1525. if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) {
  1526. hctl = SDVS30;
  1527. capa = VS30 | VS18;
  1528. } else {
  1529. hctl = SDVS18;
  1530. capa = VS18;
  1531. }
  1532. value = OMAP_HSMMC_READ(host->base, HCTL) & ~SDVS_MASK;
  1533. OMAP_HSMMC_WRITE(host->base, HCTL, value | hctl);
  1534. value = OMAP_HSMMC_READ(host->base, CAPA);
  1535. OMAP_HSMMC_WRITE(host->base, CAPA, value | capa);
  1536. /* Set SD bus power bit */
  1537. set_sd_bus_power(host);
  1538. }
  1539. static int omap_hsmmc_multi_io_quirk(struct mmc_card *card,
  1540. unsigned int direction, int blk_size)
  1541. {
  1542. /* This controller can't do multiblock reads due to hw bugs */
  1543. if (direction == MMC_DATA_READ)
  1544. return 1;
  1545. return blk_size;
  1546. }
  1547. static struct mmc_host_ops omap_hsmmc_ops = {
  1548. .post_req = omap_hsmmc_post_req,
  1549. .pre_req = omap_hsmmc_pre_req,
  1550. .request = omap_hsmmc_request,
  1551. .set_ios = omap_hsmmc_set_ios,
  1552. .get_cd = omap_hsmmc_get_cd,
  1553. .get_ro = mmc_gpio_get_ro,
  1554. .init_card = omap_hsmmc_init_card,
  1555. .enable_sdio_irq = omap_hsmmc_enable_sdio_irq,
  1556. };
  1557. #ifdef CONFIG_DEBUG_FS
  1558. static int omap_hsmmc_regs_show(struct seq_file *s, void *data)
  1559. {
  1560. struct mmc_host *mmc = s->private;
  1561. struct omap_hsmmc_host *host = mmc_priv(mmc);
  1562. seq_printf(s, "mmc%d:\n", mmc->index);
  1563. seq_printf(s, "sdio irq mode\t%s\n",
  1564. (mmc->caps & MMC_CAP_SDIO_IRQ) ? "interrupt" : "polling");
  1565. if (mmc->caps & MMC_CAP_SDIO_IRQ) {
  1566. seq_printf(s, "sdio irq \t%s\n",
  1567. (host->flags & HSMMC_SDIO_IRQ_ENABLED) ? "enabled"
  1568. : "disabled");
  1569. }
  1570. seq_printf(s, "ctx_loss:\t%d\n", host->context_loss);
  1571. pm_runtime_get_sync(host->dev);
  1572. seq_puts(s, "\nregs:\n");
  1573. seq_printf(s, "CON:\t\t0x%08x\n",
  1574. OMAP_HSMMC_READ(host->base, CON));
  1575. seq_printf(s, "PSTATE:\t\t0x%08x\n",
  1576. OMAP_HSMMC_READ(host->base, PSTATE));
  1577. seq_printf(s, "HCTL:\t\t0x%08x\n",
  1578. OMAP_HSMMC_READ(host->base, HCTL));
  1579. seq_printf(s, "SYSCTL:\t\t0x%08x\n",
  1580. OMAP_HSMMC_READ(host->base, SYSCTL));
  1581. seq_printf(s, "IE:\t\t0x%08x\n",
  1582. OMAP_HSMMC_READ(host->base, IE));
  1583. seq_printf(s, "ISE:\t\t0x%08x\n",
  1584. OMAP_HSMMC_READ(host->base, ISE));
  1585. seq_printf(s, "CAPA:\t\t0x%08x\n",
  1586. OMAP_HSMMC_READ(host->base, CAPA));
  1587. pm_runtime_mark_last_busy(host->dev);
  1588. pm_runtime_put_autosuspend(host->dev);
  1589. return 0;
  1590. }
  1591. static int omap_hsmmc_regs_open(struct inode *inode, struct file *file)
  1592. {
  1593. return single_open(file, omap_hsmmc_regs_show, inode->i_private);
  1594. }
  1595. static const struct file_operations mmc_regs_fops = {
  1596. .open = omap_hsmmc_regs_open,
  1597. .read = seq_read,
  1598. .llseek = seq_lseek,
  1599. .release = single_release,
  1600. };
  1601. static void omap_hsmmc_debugfs(struct mmc_host *mmc)
  1602. {
  1603. if (mmc->debugfs_root)
  1604. debugfs_create_file("regs", S_IRUSR, mmc->debugfs_root,
  1605. mmc, &mmc_regs_fops);
  1606. }
  1607. #else
  1608. static void omap_hsmmc_debugfs(struct mmc_host *mmc)
  1609. {
  1610. }
  1611. #endif
  1612. #ifdef CONFIG_OF
  1613. static const struct omap_mmc_of_data omap3_pre_es3_mmc_of_data = {
  1614. /* See 35xx errata 2.1.1.128 in SPRZ278F */
  1615. .controller_flags = OMAP_HSMMC_BROKEN_MULTIBLOCK_READ,
  1616. };
  1617. static const struct omap_mmc_of_data omap4_mmc_of_data = {
  1618. .reg_offset = 0x100,
  1619. };
  1620. static const struct omap_mmc_of_data am33xx_mmc_of_data = {
  1621. .reg_offset = 0x100,
  1622. .controller_flags = OMAP_HSMMC_SWAKEUP_MISSING,
  1623. };
  1624. static const struct of_device_id omap_mmc_of_match[] = {
  1625. {
  1626. .compatible = "ti,omap2-hsmmc",
  1627. },
  1628. {
  1629. .compatible = "ti,omap3-pre-es3-hsmmc",
  1630. .data = &omap3_pre_es3_mmc_of_data,
  1631. },
  1632. {
  1633. .compatible = "ti,omap3-hsmmc",
  1634. },
  1635. {
  1636. .compatible = "ti,omap4-hsmmc",
  1637. .data = &omap4_mmc_of_data,
  1638. },
  1639. {
  1640. .compatible = "ti,am33xx-hsmmc",
  1641. .data = &am33xx_mmc_of_data,
  1642. },
  1643. {},
  1644. };
  1645. MODULE_DEVICE_TABLE(of, omap_mmc_of_match);
  1646. static struct omap_hsmmc_platform_data *of_get_hsmmc_pdata(struct device *dev)
  1647. {
  1648. struct omap_hsmmc_platform_data *pdata, *legacy;
  1649. struct device_node *np = dev->of_node;
  1650. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  1651. if (!pdata)
  1652. return ERR_PTR(-ENOMEM); /* out of memory */
  1653. legacy = dev_get_platdata(dev);
  1654. if (legacy && legacy->name)
  1655. pdata->name = legacy->name;
  1656. if (of_find_property(np, "ti,dual-volt", NULL))
  1657. pdata->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT;
  1658. pdata->gpio_cd = -EINVAL;
  1659. pdata->gpio_cod = -EINVAL;
  1660. pdata->gpio_wp = -EINVAL;
  1661. if (of_find_property(np, "ti,non-removable", NULL)) {
  1662. pdata->nonremovable = true;
  1663. pdata->no_regulator_off_init = true;
  1664. }
  1665. if (of_find_property(np, "ti,needs-special-reset", NULL))
  1666. pdata->features |= HSMMC_HAS_UPDATED_RESET;
  1667. if (of_find_property(np, "ti,needs-special-hs-handling", NULL))
  1668. pdata->features |= HSMMC_HAS_HSPE_SUPPORT;
  1669. return pdata;
  1670. }
  1671. #else
  1672. static inline struct omap_hsmmc_platform_data
  1673. *of_get_hsmmc_pdata(struct device *dev)
  1674. {
  1675. return ERR_PTR(-EINVAL);
  1676. }
  1677. #endif
  1678. static int omap_hsmmc_probe(struct platform_device *pdev)
  1679. {
  1680. struct omap_hsmmc_platform_data *pdata = pdev->dev.platform_data;
  1681. struct mmc_host *mmc;
  1682. struct omap_hsmmc_host *host = NULL;
  1683. struct resource *res;
  1684. int ret, irq;
  1685. const struct of_device_id *match;
  1686. const struct omap_mmc_of_data *data;
  1687. void __iomem *base;
  1688. match = of_match_device(of_match_ptr(omap_mmc_of_match), &pdev->dev);
  1689. if (match) {
  1690. pdata = of_get_hsmmc_pdata(&pdev->dev);
  1691. if (IS_ERR(pdata))
  1692. return PTR_ERR(pdata);
  1693. if (match->data) {
  1694. data = match->data;
  1695. pdata->reg_offset = data->reg_offset;
  1696. pdata->controller_flags |= data->controller_flags;
  1697. }
  1698. }
  1699. if (pdata == NULL) {
  1700. dev_err(&pdev->dev, "Platform Data is missing\n");
  1701. return -ENXIO;
  1702. }
  1703. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1704. irq = platform_get_irq(pdev, 0);
  1705. if (res == NULL || irq < 0)
  1706. return -ENXIO;
  1707. base = devm_ioremap_resource(&pdev->dev, res);
  1708. if (IS_ERR(base))
  1709. return PTR_ERR(base);
  1710. mmc = mmc_alloc_host(sizeof(struct omap_hsmmc_host), &pdev->dev);
  1711. if (!mmc) {
  1712. ret = -ENOMEM;
  1713. goto err;
  1714. }
  1715. ret = mmc_of_parse(mmc);
  1716. if (ret)
  1717. goto err1;
  1718. host = mmc_priv(mmc);
  1719. host->mmc = mmc;
  1720. host->pdata = pdata;
  1721. host->dev = &pdev->dev;
  1722. host->use_dma = 1;
  1723. host->dma_ch = -1;
  1724. host->irq = irq;
  1725. host->mapbase = res->start + pdata->reg_offset;
  1726. host->base = base + pdata->reg_offset;
  1727. host->power_mode = MMC_POWER_OFF;
  1728. host->next_data.cookie = 1;
  1729. host->pbias_enabled = 0;
  1730. host->vqmmc_enabled = 0;
  1731. ret = omap_hsmmc_gpio_init(mmc, host, pdata);
  1732. if (ret)
  1733. goto err_gpio;
  1734. platform_set_drvdata(pdev, host);
  1735. if (pdev->dev.of_node)
  1736. host->wake_irq = irq_of_parse_and_map(pdev->dev.of_node, 1);
  1737. mmc->ops = &omap_hsmmc_ops;
  1738. mmc->f_min = OMAP_MMC_MIN_CLOCK;
  1739. if (pdata->max_freq > 0)
  1740. mmc->f_max = pdata->max_freq;
  1741. else if (mmc->f_max == 0)
  1742. mmc->f_max = OMAP_MMC_MAX_CLOCK;
  1743. spin_lock_init(&host->irq_lock);
  1744. host->fclk = devm_clk_get(&pdev->dev, "fck");
  1745. if (IS_ERR(host->fclk)) {
  1746. ret = PTR_ERR(host->fclk);
  1747. host->fclk = NULL;
  1748. goto err1;
  1749. }
  1750. if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) {
  1751. dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
  1752. omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
  1753. }
  1754. device_init_wakeup(&pdev->dev, true);
  1755. pm_runtime_enable(host->dev);
  1756. pm_runtime_get_sync(host->dev);
  1757. pm_runtime_set_autosuspend_delay(host->dev, MMC_AUTOSUSPEND_DELAY);
  1758. pm_runtime_use_autosuspend(host->dev);
  1759. omap_hsmmc_context_save(host);
  1760. host->dbclk = devm_clk_get(&pdev->dev, "mmchsdb_fck");
  1761. /*
  1762. * MMC can still work without debounce clock.
  1763. */
  1764. if (IS_ERR(host->dbclk)) {
  1765. host->dbclk = NULL;
  1766. } else if (clk_prepare_enable(host->dbclk) != 0) {
  1767. dev_warn(mmc_dev(host->mmc), "Failed to enable debounce clk\n");
  1768. host->dbclk = NULL;
  1769. }
  1770. /* Since we do only SG emulation, we can have as many segs
  1771. * as we want. */
  1772. mmc->max_segs = 1024;
  1773. mmc->max_blk_size = 512; /* Block Length at max can be 1024 */
  1774. mmc->max_blk_count = 0xFFFF; /* No. of Blocks is 16 bits */
  1775. mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
  1776. mmc->max_seg_size = mmc->max_req_size;
  1777. mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
  1778. MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE;
  1779. mmc->caps |= mmc_pdata(host)->caps;
  1780. if (mmc->caps & MMC_CAP_8_BIT_DATA)
  1781. mmc->caps |= MMC_CAP_4_BIT_DATA;
  1782. if (mmc_pdata(host)->nonremovable)
  1783. mmc->caps |= MMC_CAP_NONREMOVABLE;
  1784. mmc->pm_caps |= mmc_pdata(host)->pm_caps;
  1785. omap_hsmmc_conf_bus_power(host);
  1786. host->rx_chan = dma_request_chan(&pdev->dev, "rx");
  1787. if (IS_ERR(host->rx_chan)) {
  1788. dev_err(mmc_dev(host->mmc), "RX DMA channel request failed\n");
  1789. ret = PTR_ERR(host->rx_chan);
  1790. goto err_irq;
  1791. }
  1792. host->tx_chan = dma_request_chan(&pdev->dev, "tx");
  1793. if (IS_ERR(host->tx_chan)) {
  1794. dev_err(mmc_dev(host->mmc), "TX DMA channel request failed\n");
  1795. ret = PTR_ERR(host->tx_chan);
  1796. goto err_irq;
  1797. }
  1798. /* Request IRQ for MMC operations */
  1799. ret = devm_request_irq(&pdev->dev, host->irq, omap_hsmmc_irq, 0,
  1800. mmc_hostname(mmc), host);
  1801. if (ret) {
  1802. dev_err(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n");
  1803. goto err_irq;
  1804. }
  1805. ret = omap_hsmmc_reg_get(host);
  1806. if (ret)
  1807. goto err_irq;
  1808. mmc->ocr_avail = mmc_pdata(host)->ocr_mask;
  1809. omap_hsmmc_disable_irq(host);
  1810. /*
  1811. * For now, only support SDIO interrupt if we have a separate
  1812. * wake-up interrupt configured from device tree. This is because
  1813. * the wake-up interrupt is needed for idle state and some
  1814. * platforms need special quirks. And we don't want to add new
  1815. * legacy mux platform init code callbacks any longer as we
  1816. * are moving to DT based booting anyways.
  1817. */
  1818. ret = omap_hsmmc_configure_wake_irq(host);
  1819. if (!ret)
  1820. mmc->caps |= MMC_CAP_SDIO_IRQ;
  1821. omap_hsmmc_protect_card(host);
  1822. mmc_add_host(mmc);
  1823. if (mmc_pdata(host)->name != NULL) {
  1824. ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name);
  1825. if (ret < 0)
  1826. goto err_slot_name;
  1827. }
  1828. if (host->get_cover_state) {
  1829. ret = device_create_file(&mmc->class_dev,
  1830. &dev_attr_cover_switch);
  1831. if (ret < 0)
  1832. goto err_slot_name;
  1833. }
  1834. omap_hsmmc_debugfs(mmc);
  1835. pm_runtime_mark_last_busy(host->dev);
  1836. pm_runtime_put_autosuspend(host->dev);
  1837. return 0;
  1838. err_slot_name:
  1839. mmc_remove_host(mmc);
  1840. err_irq:
  1841. device_init_wakeup(&pdev->dev, false);
  1842. if (!IS_ERR_OR_NULL(host->tx_chan))
  1843. dma_release_channel(host->tx_chan);
  1844. if (!IS_ERR_OR_NULL(host->rx_chan))
  1845. dma_release_channel(host->rx_chan);
  1846. pm_runtime_dont_use_autosuspend(host->dev);
  1847. pm_runtime_put_sync(host->dev);
  1848. pm_runtime_disable(host->dev);
  1849. if (host->dbclk)
  1850. clk_disable_unprepare(host->dbclk);
  1851. err1:
  1852. err_gpio:
  1853. mmc_free_host(mmc);
  1854. err:
  1855. return ret;
  1856. }
  1857. static int omap_hsmmc_remove(struct platform_device *pdev)
  1858. {
  1859. struct omap_hsmmc_host *host = platform_get_drvdata(pdev);
  1860. pm_runtime_get_sync(host->dev);
  1861. mmc_remove_host(host->mmc);
  1862. dma_release_channel(host->tx_chan);
  1863. dma_release_channel(host->rx_chan);
  1864. pm_runtime_dont_use_autosuspend(host->dev);
  1865. pm_runtime_put_sync(host->dev);
  1866. pm_runtime_disable(host->dev);
  1867. device_init_wakeup(&pdev->dev, false);
  1868. if (host->dbclk)
  1869. clk_disable_unprepare(host->dbclk);
  1870. mmc_free_host(host->mmc);
  1871. return 0;
  1872. }
  1873. #ifdef CONFIG_PM_SLEEP
  1874. static int omap_hsmmc_suspend(struct device *dev)
  1875. {
  1876. struct omap_hsmmc_host *host = dev_get_drvdata(dev);
  1877. if (!host)
  1878. return 0;
  1879. pm_runtime_get_sync(host->dev);
  1880. if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) {
  1881. OMAP_HSMMC_WRITE(host->base, ISE, 0);
  1882. OMAP_HSMMC_WRITE(host->base, IE, 0);
  1883. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  1884. OMAP_HSMMC_WRITE(host->base, HCTL,
  1885. OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP);
  1886. }
  1887. if (host->dbclk)
  1888. clk_disable_unprepare(host->dbclk);
  1889. pm_runtime_put_sync(host->dev);
  1890. return 0;
  1891. }
  1892. /* Routine to resume the MMC device */
  1893. static int omap_hsmmc_resume(struct device *dev)
  1894. {
  1895. struct omap_hsmmc_host *host = dev_get_drvdata(dev);
  1896. if (!host)
  1897. return 0;
  1898. pm_runtime_get_sync(host->dev);
  1899. if (host->dbclk)
  1900. clk_prepare_enable(host->dbclk);
  1901. if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER))
  1902. omap_hsmmc_conf_bus_power(host);
  1903. omap_hsmmc_protect_card(host);
  1904. pm_runtime_mark_last_busy(host->dev);
  1905. pm_runtime_put_autosuspend(host->dev);
  1906. return 0;
  1907. }
  1908. #endif
  1909. static int omap_hsmmc_runtime_suspend(struct device *dev)
  1910. {
  1911. struct omap_hsmmc_host *host;
  1912. unsigned long flags;
  1913. int ret = 0;
  1914. host = platform_get_drvdata(to_platform_device(dev));
  1915. omap_hsmmc_context_save(host);
  1916. dev_dbg(dev, "disabled\n");
  1917. spin_lock_irqsave(&host->irq_lock, flags);
  1918. if ((host->mmc->caps & MMC_CAP_SDIO_IRQ) &&
  1919. (host->flags & HSMMC_SDIO_IRQ_ENABLED)) {
  1920. /* disable sdio irq handling to prevent race */
  1921. OMAP_HSMMC_WRITE(host->base, ISE, 0);
  1922. OMAP_HSMMC_WRITE(host->base, IE, 0);
  1923. if (!(OMAP_HSMMC_READ(host->base, PSTATE) & DLEV_DAT(1))) {
  1924. /*
  1925. * dat1 line low, pending sdio irq
  1926. * race condition: possible irq handler running on
  1927. * multi-core, abort
  1928. */
  1929. dev_dbg(dev, "pending sdio irq, abort suspend\n");
  1930. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  1931. OMAP_HSMMC_WRITE(host->base, ISE, CIRQ_EN);
  1932. OMAP_HSMMC_WRITE(host->base, IE, CIRQ_EN);
  1933. pm_runtime_mark_last_busy(dev);
  1934. ret = -EBUSY;
  1935. goto abort;
  1936. }
  1937. pinctrl_pm_select_idle_state(dev);
  1938. } else {
  1939. pinctrl_pm_select_idle_state(dev);
  1940. }
  1941. abort:
  1942. spin_unlock_irqrestore(&host->irq_lock, flags);
  1943. return ret;
  1944. }
  1945. static int omap_hsmmc_runtime_resume(struct device *dev)
  1946. {
  1947. struct omap_hsmmc_host *host;
  1948. unsigned long flags;
  1949. host = platform_get_drvdata(to_platform_device(dev));
  1950. omap_hsmmc_context_restore(host);
  1951. dev_dbg(dev, "enabled\n");
  1952. spin_lock_irqsave(&host->irq_lock, flags);
  1953. if ((host->mmc->caps & MMC_CAP_SDIO_IRQ) &&
  1954. (host->flags & HSMMC_SDIO_IRQ_ENABLED)) {
  1955. pinctrl_pm_select_default_state(host->dev);
  1956. /* irq lost, if pinmux incorrect */
  1957. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  1958. OMAP_HSMMC_WRITE(host->base, ISE, CIRQ_EN);
  1959. OMAP_HSMMC_WRITE(host->base, IE, CIRQ_EN);
  1960. } else {
  1961. pinctrl_pm_select_default_state(host->dev);
  1962. }
  1963. spin_unlock_irqrestore(&host->irq_lock, flags);
  1964. return 0;
  1965. }
  1966. static struct dev_pm_ops omap_hsmmc_dev_pm_ops = {
  1967. SET_SYSTEM_SLEEP_PM_OPS(omap_hsmmc_suspend, omap_hsmmc_resume)
  1968. .runtime_suspend = omap_hsmmc_runtime_suspend,
  1969. .runtime_resume = omap_hsmmc_runtime_resume,
  1970. };
  1971. static struct platform_driver omap_hsmmc_driver = {
  1972. .probe = omap_hsmmc_probe,
  1973. .remove = omap_hsmmc_remove,
  1974. .driver = {
  1975. .name = DRIVER_NAME,
  1976. .pm = &omap_hsmmc_dev_pm_ops,
  1977. .of_match_table = of_match_ptr(omap_mmc_of_match),
  1978. },
  1979. };
  1980. module_platform_driver(omap_hsmmc_driver);
  1981. MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver");
  1982. MODULE_LICENSE("GPL");
  1983. MODULE_ALIAS("platform:" DRIVER_NAME);
  1984. MODULE_AUTHOR("Texas Instruments Inc");