omap_hsmmc.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392
  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/omap-dmaengine.h>
  35. #include <linux/mmc/host.h>
  36. #include <linux/mmc/core.h>
  37. #include <linux/mmc/mmc.h>
  38. #include <linux/mmc/slot-gpio.h>
  39. #include <linux/io.h>
  40. #include <linux/irq.h>
  41. #include <linux/gpio.h>
  42. #include <linux/regulator/consumer.h>
  43. #include <linux/pinctrl/consumer.h>
  44. #include <linux/pm_runtime.h>
  45. #include <linux/pm_wakeirq.h>
  46. #include <linux/platform_data/hsmmc-omap.h>
  47. /* OMAP HSMMC Host Controller Registers */
  48. #define OMAP_HSMMC_SYSSTATUS 0x0014
  49. #define OMAP_HSMMC_CON 0x002C
  50. #define OMAP_HSMMC_SDMASA 0x0100
  51. #define OMAP_HSMMC_BLK 0x0104
  52. #define OMAP_HSMMC_ARG 0x0108
  53. #define OMAP_HSMMC_CMD 0x010C
  54. #define OMAP_HSMMC_RSP10 0x0110
  55. #define OMAP_HSMMC_RSP32 0x0114
  56. #define OMAP_HSMMC_RSP54 0x0118
  57. #define OMAP_HSMMC_RSP76 0x011C
  58. #define OMAP_HSMMC_DATA 0x0120
  59. #define OMAP_HSMMC_PSTATE 0x0124
  60. #define OMAP_HSMMC_HCTL 0x0128
  61. #define OMAP_HSMMC_SYSCTL 0x012C
  62. #define OMAP_HSMMC_STAT 0x0130
  63. #define OMAP_HSMMC_IE 0x0134
  64. #define OMAP_HSMMC_ISE 0x0138
  65. #define OMAP_HSMMC_AC12 0x013C
  66. #define OMAP_HSMMC_CAPA 0x0140
  67. #define VS18 (1 << 26)
  68. #define VS30 (1 << 25)
  69. #define HSS (1 << 21)
  70. #define SDVS18 (0x5 << 9)
  71. #define SDVS30 (0x6 << 9)
  72. #define SDVS33 (0x7 << 9)
  73. #define SDVS_MASK 0x00000E00
  74. #define SDVSCLR 0xFFFFF1FF
  75. #define SDVSDET 0x00000400
  76. #define AUTOIDLE 0x1
  77. #define SDBP (1 << 8)
  78. #define DTO 0xe
  79. #define ICE 0x1
  80. #define ICS 0x2
  81. #define CEN (1 << 2)
  82. #define CLKD_MAX 0x3FF /* max clock divisor: 1023 */
  83. #define CLKD_MASK 0x0000FFC0
  84. #define CLKD_SHIFT 6
  85. #define DTO_MASK 0x000F0000
  86. #define DTO_SHIFT 16
  87. #define INIT_STREAM (1 << 1)
  88. #define ACEN_ACMD23 (2 << 2)
  89. #define DP_SELECT (1 << 21)
  90. #define DDIR (1 << 4)
  91. #define DMAE 0x1
  92. #define MSBS (1 << 5)
  93. #define BCE (1 << 1)
  94. #define FOUR_BIT (1 << 1)
  95. #define HSPE (1 << 2)
  96. #define IWE (1 << 24)
  97. #define DDR (1 << 19)
  98. #define CLKEXTFREE (1 << 16)
  99. #define CTPL (1 << 11)
  100. #define DW8 (1 << 5)
  101. #define OD 0x1
  102. #define STAT_CLEAR 0xFFFFFFFF
  103. #define INIT_STREAM_CMD 0x00000000
  104. #define DUAL_VOLT_OCR_BIT 7
  105. #define SRC (1 << 25)
  106. #define SRD (1 << 26)
  107. #define SOFTRESET (1 << 1)
  108. /* PSTATE */
  109. #define DLEV_DAT(x) (1 << (20 + (x)))
  110. /* Interrupt masks for IE and ISE register */
  111. #define CC_EN (1 << 0)
  112. #define TC_EN (1 << 1)
  113. #define BWR_EN (1 << 4)
  114. #define BRR_EN (1 << 5)
  115. #define CIRQ_EN (1 << 8)
  116. #define ERR_EN (1 << 15)
  117. #define CTO_EN (1 << 16)
  118. #define CCRC_EN (1 << 17)
  119. #define CEB_EN (1 << 18)
  120. #define CIE_EN (1 << 19)
  121. #define DTO_EN (1 << 20)
  122. #define DCRC_EN (1 << 21)
  123. #define DEB_EN (1 << 22)
  124. #define ACE_EN (1 << 24)
  125. #define CERR_EN (1 << 28)
  126. #define BADA_EN (1 << 29)
  127. #define INT_EN_MASK (BADA_EN | CERR_EN | ACE_EN | DEB_EN | DCRC_EN |\
  128. DTO_EN | CIE_EN | CEB_EN | CCRC_EN | CTO_EN | \
  129. BRR_EN | BWR_EN | TC_EN | CC_EN)
  130. #define CNI (1 << 7)
  131. #define ACIE (1 << 4)
  132. #define ACEB (1 << 3)
  133. #define ACCE (1 << 2)
  134. #define ACTO (1 << 1)
  135. #define ACNE (1 << 0)
  136. #define MMC_AUTOSUSPEND_DELAY 100
  137. #define MMC_TIMEOUT_MS 20 /* 20 mSec */
  138. #define MMC_TIMEOUT_US 20000 /* 20000 micro Sec */
  139. #define OMAP_MMC_MIN_CLOCK 400000
  140. #define OMAP_MMC_MAX_CLOCK 52000000
  141. #define DRIVER_NAME "omap_hsmmc"
  142. #define VDD_1V8 1800000 /* 180000 uV */
  143. #define VDD_3V0 3000000 /* 300000 uV */
  144. #define VDD_165_195 (ffs(MMC_VDD_165_195) - 1)
  145. /*
  146. * One controller can have multiple slots, like on some omap boards using
  147. * omap.c controller driver. Luckily this is not currently done on any known
  148. * omap_hsmmc.c device.
  149. */
  150. #define mmc_pdata(host) host->pdata
  151. /*
  152. * MMC Host controller read/write API's
  153. */
  154. #define OMAP_HSMMC_READ(base, reg) \
  155. __raw_readl((base) + OMAP_HSMMC_##reg)
  156. #define OMAP_HSMMC_WRITE(base, reg, val) \
  157. __raw_writel((val), (base) + OMAP_HSMMC_##reg)
  158. struct omap_hsmmc_next {
  159. unsigned int dma_len;
  160. s32 cookie;
  161. };
  162. struct omap_hsmmc_host {
  163. struct device *dev;
  164. struct mmc_host *mmc;
  165. struct mmc_request *mrq;
  166. struct mmc_command *cmd;
  167. struct mmc_data *data;
  168. struct clk *fclk;
  169. struct clk *dbclk;
  170. struct regulator *pbias;
  171. bool pbias_enabled;
  172. void __iomem *base;
  173. int vqmmc_enabled;
  174. resource_size_t mapbase;
  175. spinlock_t irq_lock; /* Prevent races with irq handler */
  176. unsigned int dma_len;
  177. unsigned int dma_sg_idx;
  178. unsigned char bus_mode;
  179. unsigned char power_mode;
  180. int suspended;
  181. u32 con;
  182. u32 hctl;
  183. u32 sysctl;
  184. u32 capa;
  185. int irq;
  186. int wake_irq;
  187. int use_dma, dma_ch;
  188. struct dma_chan *tx_chan;
  189. struct dma_chan *rx_chan;
  190. int response_busy;
  191. int context_loss;
  192. int protect_card;
  193. int reqs_blocked;
  194. int req_in_progress;
  195. unsigned long clk_rate;
  196. unsigned int flags;
  197. #define AUTO_CMD23 (1 << 0) /* Auto CMD23 support */
  198. #define HSMMC_SDIO_IRQ_ENABLED (1 << 1) /* SDIO irq enabled */
  199. struct omap_hsmmc_next next_data;
  200. struct omap_hsmmc_platform_data *pdata;
  201. /* return MMC cover switch state, can be NULL if not supported.
  202. *
  203. * possible return values:
  204. * 0 - closed
  205. * 1 - open
  206. */
  207. int (*get_cover_state)(struct device *dev);
  208. int (*card_detect)(struct device *dev);
  209. };
  210. struct omap_mmc_of_data {
  211. u32 reg_offset;
  212. u8 controller_flags;
  213. };
  214. static void omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host);
  215. static int omap_hsmmc_card_detect(struct device *dev)
  216. {
  217. struct omap_hsmmc_host *host = dev_get_drvdata(dev);
  218. return mmc_gpio_get_cd(host->mmc);
  219. }
  220. static int omap_hsmmc_get_cover_state(struct device *dev)
  221. {
  222. struct omap_hsmmc_host *host = dev_get_drvdata(dev);
  223. return mmc_gpio_get_cd(host->mmc);
  224. }
  225. static int omap_hsmmc_enable_supply(struct mmc_host *mmc)
  226. {
  227. int ret;
  228. struct omap_hsmmc_host *host = mmc_priv(mmc);
  229. struct mmc_ios *ios = &mmc->ios;
  230. if (mmc->supply.vmmc) {
  231. ret = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd);
  232. if (ret)
  233. return ret;
  234. }
  235. /* Enable interface voltage rail, if needed */
  236. if (mmc->supply.vqmmc && !host->vqmmc_enabled) {
  237. ret = regulator_enable(mmc->supply.vqmmc);
  238. if (ret) {
  239. dev_err(mmc_dev(mmc), "vmmc_aux reg enable failed\n");
  240. goto err_vqmmc;
  241. }
  242. host->vqmmc_enabled = 1;
  243. }
  244. return 0;
  245. err_vqmmc:
  246. if (mmc->supply.vmmc)
  247. mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
  248. return ret;
  249. }
  250. static int omap_hsmmc_disable_supply(struct mmc_host *mmc)
  251. {
  252. int ret;
  253. int status;
  254. struct omap_hsmmc_host *host = mmc_priv(mmc);
  255. if (mmc->supply.vqmmc && host->vqmmc_enabled) {
  256. ret = regulator_disable(mmc->supply.vqmmc);
  257. if (ret) {
  258. dev_err(mmc_dev(mmc), "vmmc_aux reg disable failed\n");
  259. return ret;
  260. }
  261. host->vqmmc_enabled = 0;
  262. }
  263. if (mmc->supply.vmmc) {
  264. ret = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
  265. if (ret)
  266. goto err_set_ocr;
  267. }
  268. return 0;
  269. err_set_ocr:
  270. if (mmc->supply.vqmmc) {
  271. status = regulator_enable(mmc->supply.vqmmc);
  272. if (status)
  273. dev_err(mmc_dev(mmc), "vmmc_aux re-enable failed\n");
  274. }
  275. return ret;
  276. }
  277. static int omap_hsmmc_set_pbias(struct omap_hsmmc_host *host, bool power_on,
  278. int vdd)
  279. {
  280. int ret;
  281. if (!host->pbias)
  282. return 0;
  283. if (power_on) {
  284. if (vdd <= VDD_165_195)
  285. ret = regulator_set_voltage(host->pbias, VDD_1V8,
  286. VDD_1V8);
  287. else
  288. ret = regulator_set_voltage(host->pbias, VDD_3V0,
  289. VDD_3V0);
  290. if (ret < 0) {
  291. dev_err(host->dev, "pbias set voltage fail\n");
  292. return ret;
  293. }
  294. if (host->pbias_enabled == 0) {
  295. ret = regulator_enable(host->pbias);
  296. if (ret) {
  297. dev_err(host->dev, "pbias reg enable fail\n");
  298. return ret;
  299. }
  300. host->pbias_enabled = 1;
  301. }
  302. } else {
  303. if (host->pbias_enabled == 1) {
  304. ret = regulator_disable(host->pbias);
  305. if (ret) {
  306. dev_err(host->dev, "pbias reg disable fail\n");
  307. return ret;
  308. }
  309. host->pbias_enabled = 0;
  310. }
  311. }
  312. return 0;
  313. }
  314. static int omap_hsmmc_set_power(struct omap_hsmmc_host *host, int power_on,
  315. int vdd)
  316. {
  317. struct mmc_host *mmc = host->mmc;
  318. int ret = 0;
  319. if (mmc_pdata(host)->set_power)
  320. return mmc_pdata(host)->set_power(host->dev, power_on, vdd);
  321. /*
  322. * If we don't see a Vcc regulator, assume it's a fixed
  323. * voltage always-on regulator.
  324. */
  325. if (!mmc->supply.vmmc)
  326. return 0;
  327. if (mmc_pdata(host)->before_set_reg)
  328. mmc_pdata(host)->before_set_reg(host->dev, power_on, vdd);
  329. ret = omap_hsmmc_set_pbias(host, false, 0);
  330. if (ret)
  331. return ret;
  332. /*
  333. * Assume Vcc regulator is used only to power the card ... OMAP
  334. * VDDS is used to power the pins, optionally with a transceiver to
  335. * support cards using voltages other than VDDS (1.8V nominal). When a
  336. * transceiver is used, DAT3..7 are muxed as transceiver control pins.
  337. *
  338. * In some cases this regulator won't support enable/disable;
  339. * e.g. it's a fixed rail for a WLAN chip.
  340. *
  341. * In other cases vcc_aux switches interface power. Example, for
  342. * eMMC cards it represents VccQ. Sometimes transceivers or SDIO
  343. * chips/cards need an interface voltage rail too.
  344. */
  345. if (power_on) {
  346. ret = omap_hsmmc_enable_supply(mmc);
  347. if (ret)
  348. return ret;
  349. ret = omap_hsmmc_set_pbias(host, true, vdd);
  350. if (ret)
  351. goto err_set_voltage;
  352. } else {
  353. ret = omap_hsmmc_disable_supply(mmc);
  354. if (ret)
  355. return ret;
  356. }
  357. if (mmc_pdata(host)->after_set_reg)
  358. mmc_pdata(host)->after_set_reg(host->dev, power_on, vdd);
  359. return 0;
  360. err_set_voltage:
  361. omap_hsmmc_disable_supply(mmc);
  362. return ret;
  363. }
  364. static int omap_hsmmc_disable_boot_regulator(struct regulator *reg)
  365. {
  366. int ret;
  367. if (!reg)
  368. return 0;
  369. if (regulator_is_enabled(reg)) {
  370. ret = regulator_enable(reg);
  371. if (ret)
  372. return ret;
  373. ret = regulator_disable(reg);
  374. if (ret)
  375. return ret;
  376. }
  377. return 0;
  378. }
  379. static int omap_hsmmc_disable_boot_regulators(struct omap_hsmmc_host *host)
  380. {
  381. struct mmc_host *mmc = host->mmc;
  382. int ret;
  383. /*
  384. * disable regulators enabled during boot and get the usecount
  385. * right so that regulators can be enabled/disabled by checking
  386. * the return value of regulator_is_enabled
  387. */
  388. ret = omap_hsmmc_disable_boot_regulator(mmc->supply.vmmc);
  389. if (ret) {
  390. dev_err(host->dev, "fail to disable boot enabled vmmc reg\n");
  391. return ret;
  392. }
  393. ret = omap_hsmmc_disable_boot_regulator(mmc->supply.vqmmc);
  394. if (ret) {
  395. dev_err(host->dev,
  396. "fail to disable boot enabled vmmc_aux reg\n");
  397. return ret;
  398. }
  399. ret = omap_hsmmc_disable_boot_regulator(host->pbias);
  400. if (ret) {
  401. dev_err(host->dev,
  402. "failed to disable boot enabled pbias reg\n");
  403. return ret;
  404. }
  405. return 0;
  406. }
  407. static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
  408. {
  409. int ocr_value = 0;
  410. int ret;
  411. struct mmc_host *mmc = host->mmc;
  412. if (mmc_pdata(host)->set_power)
  413. return 0;
  414. mmc->supply.vmmc = devm_regulator_get_optional(host->dev, "vmmc");
  415. if (IS_ERR(mmc->supply.vmmc)) {
  416. ret = PTR_ERR(mmc->supply.vmmc);
  417. if ((ret != -ENODEV) && host->dev->of_node)
  418. return ret;
  419. dev_dbg(host->dev, "unable to get vmmc regulator %ld\n",
  420. PTR_ERR(mmc->supply.vmmc));
  421. mmc->supply.vmmc = NULL;
  422. } else {
  423. ocr_value = mmc_regulator_get_ocrmask(mmc->supply.vmmc);
  424. if (ocr_value > 0)
  425. mmc_pdata(host)->ocr_mask = ocr_value;
  426. }
  427. /* Allow an aux regulator */
  428. mmc->supply.vqmmc = devm_regulator_get_optional(host->dev, "vmmc_aux");
  429. if (IS_ERR(mmc->supply.vqmmc)) {
  430. ret = PTR_ERR(mmc->supply.vqmmc);
  431. if ((ret != -ENODEV) && host->dev->of_node)
  432. return ret;
  433. dev_dbg(host->dev, "unable to get vmmc_aux regulator %ld\n",
  434. PTR_ERR(mmc->supply.vqmmc));
  435. mmc->supply.vqmmc = NULL;
  436. }
  437. host->pbias = devm_regulator_get_optional(host->dev, "pbias");
  438. if (IS_ERR(host->pbias)) {
  439. ret = PTR_ERR(host->pbias);
  440. if ((ret != -ENODEV) && host->dev->of_node) {
  441. dev_err(host->dev,
  442. "SD card detect fail? enable CONFIG_REGULATOR_PBIAS\n");
  443. return ret;
  444. }
  445. dev_dbg(host->dev, "unable to get pbias regulator %ld\n",
  446. PTR_ERR(host->pbias));
  447. host->pbias = NULL;
  448. }
  449. /* For eMMC do not power off when not in sleep state */
  450. if (mmc_pdata(host)->no_regulator_off_init)
  451. return 0;
  452. ret = omap_hsmmc_disable_boot_regulators(host);
  453. if (ret)
  454. return ret;
  455. return 0;
  456. }
  457. static irqreturn_t omap_hsmmc_cover_irq(int irq, void *dev_id);
  458. static int omap_hsmmc_gpio_init(struct mmc_host *mmc,
  459. struct omap_hsmmc_host *host,
  460. struct omap_hsmmc_platform_data *pdata)
  461. {
  462. int ret;
  463. if (gpio_is_valid(pdata->gpio_cod)) {
  464. ret = mmc_gpio_request_cd(mmc, pdata->gpio_cod, 0);
  465. if (ret)
  466. return ret;
  467. host->get_cover_state = omap_hsmmc_get_cover_state;
  468. mmc_gpio_set_cd_isr(mmc, omap_hsmmc_cover_irq);
  469. } else if (gpio_is_valid(pdata->gpio_cd)) {
  470. ret = mmc_gpio_request_cd(mmc, pdata->gpio_cd, 0);
  471. if (ret)
  472. return ret;
  473. host->card_detect = omap_hsmmc_card_detect;
  474. }
  475. if (gpio_is_valid(pdata->gpio_wp)) {
  476. ret = mmc_gpio_request_ro(mmc, pdata->gpio_wp);
  477. if (ret)
  478. return ret;
  479. }
  480. return 0;
  481. }
  482. /*
  483. * Start clock to the card
  484. */
  485. static void omap_hsmmc_start_clock(struct omap_hsmmc_host *host)
  486. {
  487. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  488. OMAP_HSMMC_READ(host->base, SYSCTL) | CEN);
  489. }
  490. /*
  491. * Stop clock to the card
  492. */
  493. static void omap_hsmmc_stop_clock(struct omap_hsmmc_host *host)
  494. {
  495. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  496. OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN);
  497. if ((OMAP_HSMMC_READ(host->base, SYSCTL) & CEN) != 0x0)
  498. dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stopped\n");
  499. }
  500. static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host,
  501. struct mmc_command *cmd)
  502. {
  503. u32 irq_mask = INT_EN_MASK;
  504. unsigned long flags;
  505. if (host->use_dma)
  506. irq_mask &= ~(BRR_EN | BWR_EN);
  507. /* Disable timeout for erases */
  508. if (cmd->opcode == MMC_ERASE)
  509. irq_mask &= ~DTO_EN;
  510. spin_lock_irqsave(&host->irq_lock, flags);
  511. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  512. OMAP_HSMMC_WRITE(host->base, ISE, irq_mask);
  513. /* latch pending CIRQ, but don't signal MMC core */
  514. if (host->flags & HSMMC_SDIO_IRQ_ENABLED)
  515. irq_mask |= CIRQ_EN;
  516. OMAP_HSMMC_WRITE(host->base, IE, irq_mask);
  517. spin_unlock_irqrestore(&host->irq_lock, flags);
  518. }
  519. static void omap_hsmmc_disable_irq(struct omap_hsmmc_host *host)
  520. {
  521. u32 irq_mask = 0;
  522. unsigned long flags;
  523. spin_lock_irqsave(&host->irq_lock, flags);
  524. /* no transfer running but need to keep cirq if enabled */
  525. if (host->flags & HSMMC_SDIO_IRQ_ENABLED)
  526. irq_mask |= CIRQ_EN;
  527. OMAP_HSMMC_WRITE(host->base, ISE, irq_mask);
  528. OMAP_HSMMC_WRITE(host->base, IE, irq_mask);
  529. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  530. spin_unlock_irqrestore(&host->irq_lock, flags);
  531. }
  532. /* Calculate divisor for the given clock frequency */
  533. static u16 calc_divisor(struct omap_hsmmc_host *host, struct mmc_ios *ios)
  534. {
  535. u16 dsor = 0;
  536. if (ios->clock) {
  537. dsor = DIV_ROUND_UP(clk_get_rate(host->fclk), ios->clock);
  538. if (dsor > CLKD_MAX)
  539. dsor = CLKD_MAX;
  540. }
  541. return dsor;
  542. }
  543. static void omap_hsmmc_set_clock(struct omap_hsmmc_host *host)
  544. {
  545. struct mmc_ios *ios = &host->mmc->ios;
  546. unsigned long regval;
  547. unsigned long timeout;
  548. unsigned long clkdiv;
  549. dev_vdbg(mmc_dev(host->mmc), "Set clock to %uHz\n", ios->clock);
  550. omap_hsmmc_stop_clock(host);
  551. regval = OMAP_HSMMC_READ(host->base, SYSCTL);
  552. regval = regval & ~(CLKD_MASK | DTO_MASK);
  553. clkdiv = calc_divisor(host, ios);
  554. regval = regval | (clkdiv << 6) | (DTO << 16);
  555. OMAP_HSMMC_WRITE(host->base, SYSCTL, regval);
  556. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  557. OMAP_HSMMC_READ(host->base, SYSCTL) | ICE);
  558. /* Wait till the ICS bit is set */
  559. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  560. while ((OMAP_HSMMC_READ(host->base, SYSCTL) & ICS) != ICS
  561. && time_before(jiffies, timeout))
  562. cpu_relax();
  563. /*
  564. * Enable High-Speed Support
  565. * Pre-Requisites
  566. * - Controller should support High-Speed-Enable Bit
  567. * - Controller should not be using DDR Mode
  568. * - Controller should advertise that it supports High Speed
  569. * in capabilities register
  570. * - MMC/SD clock coming out of controller > 25MHz
  571. */
  572. if ((mmc_pdata(host)->features & HSMMC_HAS_HSPE_SUPPORT) &&
  573. (ios->timing != MMC_TIMING_MMC_DDR52) &&
  574. (ios->timing != MMC_TIMING_UHS_DDR50) &&
  575. ((OMAP_HSMMC_READ(host->base, CAPA) & HSS) == HSS)) {
  576. regval = OMAP_HSMMC_READ(host->base, HCTL);
  577. if (clkdiv && (clk_get_rate(host->fclk)/clkdiv) > 25000000)
  578. regval |= HSPE;
  579. else
  580. regval &= ~HSPE;
  581. OMAP_HSMMC_WRITE(host->base, HCTL, regval);
  582. }
  583. omap_hsmmc_start_clock(host);
  584. }
  585. static void omap_hsmmc_set_bus_width(struct omap_hsmmc_host *host)
  586. {
  587. struct mmc_ios *ios = &host->mmc->ios;
  588. u32 con;
  589. con = OMAP_HSMMC_READ(host->base, CON);
  590. if (ios->timing == MMC_TIMING_MMC_DDR52 ||
  591. ios->timing == MMC_TIMING_UHS_DDR50)
  592. con |= DDR; /* configure in DDR mode */
  593. else
  594. con &= ~DDR;
  595. switch (ios->bus_width) {
  596. case MMC_BUS_WIDTH_8:
  597. OMAP_HSMMC_WRITE(host->base, CON, con | DW8);
  598. break;
  599. case MMC_BUS_WIDTH_4:
  600. OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
  601. OMAP_HSMMC_WRITE(host->base, HCTL,
  602. OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT);
  603. break;
  604. case MMC_BUS_WIDTH_1:
  605. OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8);
  606. OMAP_HSMMC_WRITE(host->base, HCTL,
  607. OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT);
  608. break;
  609. }
  610. }
  611. static void omap_hsmmc_set_bus_mode(struct omap_hsmmc_host *host)
  612. {
  613. struct mmc_ios *ios = &host->mmc->ios;
  614. u32 con;
  615. con = OMAP_HSMMC_READ(host->base, CON);
  616. if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
  617. OMAP_HSMMC_WRITE(host->base, CON, con | OD);
  618. else
  619. OMAP_HSMMC_WRITE(host->base, CON, con & ~OD);
  620. }
  621. #ifdef CONFIG_PM
  622. /*
  623. * Restore the MMC host context, if it was lost as result of a
  624. * power state change.
  625. */
  626. static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host)
  627. {
  628. struct mmc_ios *ios = &host->mmc->ios;
  629. u32 hctl, capa;
  630. unsigned long timeout;
  631. if (host->con == OMAP_HSMMC_READ(host->base, CON) &&
  632. host->hctl == OMAP_HSMMC_READ(host->base, HCTL) &&
  633. host->sysctl == OMAP_HSMMC_READ(host->base, SYSCTL) &&
  634. host->capa == OMAP_HSMMC_READ(host->base, CAPA))
  635. return 0;
  636. host->context_loss++;
  637. if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) {
  638. if (host->power_mode != MMC_POWER_OFF &&
  639. (1 << ios->vdd) <= MMC_VDD_23_24)
  640. hctl = SDVS18;
  641. else
  642. hctl = SDVS30;
  643. capa = VS30 | VS18;
  644. } else {
  645. hctl = SDVS18;
  646. capa = VS18;
  647. }
  648. if (host->mmc->caps & MMC_CAP_SDIO_IRQ)
  649. hctl |= IWE;
  650. OMAP_HSMMC_WRITE(host->base, HCTL,
  651. OMAP_HSMMC_READ(host->base, HCTL) | hctl);
  652. OMAP_HSMMC_WRITE(host->base, CAPA,
  653. OMAP_HSMMC_READ(host->base, CAPA) | capa);
  654. OMAP_HSMMC_WRITE(host->base, HCTL,
  655. OMAP_HSMMC_READ(host->base, HCTL) | SDBP);
  656. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  657. while ((OMAP_HSMMC_READ(host->base, HCTL) & SDBP) != SDBP
  658. && time_before(jiffies, timeout))
  659. ;
  660. OMAP_HSMMC_WRITE(host->base, ISE, 0);
  661. OMAP_HSMMC_WRITE(host->base, IE, 0);
  662. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  663. /* Do not initialize card-specific things if the power is off */
  664. if (host->power_mode == MMC_POWER_OFF)
  665. goto out;
  666. omap_hsmmc_set_bus_width(host);
  667. omap_hsmmc_set_clock(host);
  668. omap_hsmmc_set_bus_mode(host);
  669. out:
  670. dev_dbg(mmc_dev(host->mmc), "context is restored: restore count %d\n",
  671. host->context_loss);
  672. return 0;
  673. }
  674. /*
  675. * Save the MMC host context (store the number of power state changes so far).
  676. */
  677. static void omap_hsmmc_context_save(struct omap_hsmmc_host *host)
  678. {
  679. host->con = OMAP_HSMMC_READ(host->base, CON);
  680. host->hctl = OMAP_HSMMC_READ(host->base, HCTL);
  681. host->sysctl = OMAP_HSMMC_READ(host->base, SYSCTL);
  682. host->capa = OMAP_HSMMC_READ(host->base, CAPA);
  683. }
  684. #else
  685. static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host)
  686. {
  687. return 0;
  688. }
  689. static void omap_hsmmc_context_save(struct omap_hsmmc_host *host)
  690. {
  691. }
  692. #endif
  693. /*
  694. * Send init stream sequence to card
  695. * before sending IDLE command
  696. */
  697. static void send_init_stream(struct omap_hsmmc_host *host)
  698. {
  699. int reg = 0;
  700. unsigned long timeout;
  701. if (host->protect_card)
  702. return;
  703. disable_irq(host->irq);
  704. OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
  705. OMAP_HSMMC_WRITE(host->base, CON,
  706. OMAP_HSMMC_READ(host->base, CON) | INIT_STREAM);
  707. OMAP_HSMMC_WRITE(host->base, CMD, INIT_STREAM_CMD);
  708. timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS);
  709. while ((reg != CC_EN) && time_before(jiffies, timeout))
  710. reg = OMAP_HSMMC_READ(host->base, STAT) & CC_EN;
  711. OMAP_HSMMC_WRITE(host->base, CON,
  712. OMAP_HSMMC_READ(host->base, CON) & ~INIT_STREAM);
  713. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  714. OMAP_HSMMC_READ(host->base, STAT);
  715. enable_irq(host->irq);
  716. }
  717. static inline
  718. int omap_hsmmc_cover_is_closed(struct omap_hsmmc_host *host)
  719. {
  720. int r = 1;
  721. if (host->get_cover_state)
  722. r = host->get_cover_state(host->dev);
  723. return r;
  724. }
  725. static ssize_t
  726. omap_hsmmc_show_cover_switch(struct device *dev, struct device_attribute *attr,
  727. char *buf)
  728. {
  729. struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
  730. struct omap_hsmmc_host *host = mmc_priv(mmc);
  731. return sprintf(buf, "%s\n",
  732. omap_hsmmc_cover_is_closed(host) ? "closed" : "open");
  733. }
  734. static DEVICE_ATTR(cover_switch, S_IRUGO, omap_hsmmc_show_cover_switch, NULL);
  735. static ssize_t
  736. omap_hsmmc_show_slot_name(struct device *dev, struct device_attribute *attr,
  737. char *buf)
  738. {
  739. struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
  740. struct omap_hsmmc_host *host = mmc_priv(mmc);
  741. return sprintf(buf, "%s\n", mmc_pdata(host)->name);
  742. }
  743. static DEVICE_ATTR(slot_name, S_IRUGO, omap_hsmmc_show_slot_name, NULL);
  744. /*
  745. * Configure the response type and send the cmd.
  746. */
  747. static void
  748. omap_hsmmc_start_command(struct omap_hsmmc_host *host, struct mmc_command *cmd,
  749. struct mmc_data *data)
  750. {
  751. int cmdreg = 0, resptype = 0, cmdtype = 0;
  752. dev_vdbg(mmc_dev(host->mmc), "%s: CMD%d, argument 0x%08x\n",
  753. mmc_hostname(host->mmc), cmd->opcode, cmd->arg);
  754. host->cmd = cmd;
  755. omap_hsmmc_enable_irq(host, cmd);
  756. host->response_busy = 0;
  757. if (cmd->flags & MMC_RSP_PRESENT) {
  758. if (cmd->flags & MMC_RSP_136)
  759. resptype = 1;
  760. else if (cmd->flags & MMC_RSP_BUSY) {
  761. resptype = 3;
  762. host->response_busy = 1;
  763. } else
  764. resptype = 2;
  765. }
  766. /*
  767. * Unlike OMAP1 controller, the cmdtype does not seem to be based on
  768. * ac, bc, adtc, bcr. Only commands ending an open ended transfer need
  769. * a val of 0x3, rest 0x0.
  770. */
  771. if (cmd == host->mrq->stop)
  772. cmdtype = 0x3;
  773. cmdreg = (cmd->opcode << 24) | (resptype << 16) | (cmdtype << 22);
  774. if ((host->flags & AUTO_CMD23) && mmc_op_multi(cmd->opcode) &&
  775. host->mrq->sbc) {
  776. cmdreg |= ACEN_ACMD23;
  777. OMAP_HSMMC_WRITE(host->base, SDMASA, host->mrq->sbc->arg);
  778. }
  779. if (data) {
  780. cmdreg |= DP_SELECT | MSBS | BCE;
  781. if (data->flags & MMC_DATA_READ)
  782. cmdreg |= DDIR;
  783. else
  784. cmdreg &= ~(DDIR);
  785. }
  786. if (host->use_dma)
  787. cmdreg |= DMAE;
  788. host->req_in_progress = 1;
  789. OMAP_HSMMC_WRITE(host->base, ARG, cmd->arg);
  790. OMAP_HSMMC_WRITE(host->base, CMD, cmdreg);
  791. }
  792. static int
  793. omap_hsmmc_get_dma_dir(struct omap_hsmmc_host *host, struct mmc_data *data)
  794. {
  795. if (data->flags & MMC_DATA_WRITE)
  796. return DMA_TO_DEVICE;
  797. else
  798. return DMA_FROM_DEVICE;
  799. }
  800. static struct dma_chan *omap_hsmmc_get_dma_chan(struct omap_hsmmc_host *host,
  801. struct mmc_data *data)
  802. {
  803. return data->flags & MMC_DATA_WRITE ? host->tx_chan : host->rx_chan;
  804. }
  805. static void omap_hsmmc_request_done(struct omap_hsmmc_host *host, struct mmc_request *mrq)
  806. {
  807. int dma_ch;
  808. unsigned long flags;
  809. spin_lock_irqsave(&host->irq_lock, flags);
  810. host->req_in_progress = 0;
  811. dma_ch = host->dma_ch;
  812. spin_unlock_irqrestore(&host->irq_lock, flags);
  813. omap_hsmmc_disable_irq(host);
  814. /* Do not complete the request if DMA is still in progress */
  815. if (mrq->data && host->use_dma && dma_ch != -1)
  816. return;
  817. host->mrq = NULL;
  818. mmc_request_done(host->mmc, mrq);
  819. }
  820. /*
  821. * Notify the transfer complete to MMC core
  822. */
  823. static void
  824. omap_hsmmc_xfer_done(struct omap_hsmmc_host *host, struct mmc_data *data)
  825. {
  826. if (!data) {
  827. struct mmc_request *mrq = host->mrq;
  828. /* TC before CC from CMD6 - don't know why, but it happens */
  829. if (host->cmd && host->cmd->opcode == 6 &&
  830. host->response_busy) {
  831. host->response_busy = 0;
  832. return;
  833. }
  834. omap_hsmmc_request_done(host, mrq);
  835. return;
  836. }
  837. host->data = NULL;
  838. if (!data->error)
  839. data->bytes_xfered += data->blocks * (data->blksz);
  840. else
  841. data->bytes_xfered = 0;
  842. if (data->stop && (data->error || !host->mrq->sbc))
  843. omap_hsmmc_start_command(host, data->stop, NULL);
  844. else
  845. omap_hsmmc_request_done(host, data->mrq);
  846. }
  847. /*
  848. * Notify the core about command completion
  849. */
  850. static void
  851. omap_hsmmc_cmd_done(struct omap_hsmmc_host *host, struct mmc_command *cmd)
  852. {
  853. if (host->mrq->sbc && (host->cmd == host->mrq->sbc) &&
  854. !host->mrq->sbc->error && !(host->flags & AUTO_CMD23)) {
  855. host->cmd = NULL;
  856. omap_hsmmc_start_dma_transfer(host);
  857. omap_hsmmc_start_command(host, host->mrq->cmd,
  858. host->mrq->data);
  859. return;
  860. }
  861. host->cmd = NULL;
  862. if (cmd->flags & MMC_RSP_PRESENT) {
  863. if (cmd->flags & MMC_RSP_136) {
  864. /* response type 2 */
  865. cmd->resp[3] = OMAP_HSMMC_READ(host->base, RSP10);
  866. cmd->resp[2] = OMAP_HSMMC_READ(host->base, RSP32);
  867. cmd->resp[1] = OMAP_HSMMC_READ(host->base, RSP54);
  868. cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP76);
  869. } else {
  870. /* response types 1, 1b, 3, 4, 5, 6 */
  871. cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP10);
  872. }
  873. }
  874. if ((host->data == NULL && !host->response_busy) || cmd->error)
  875. omap_hsmmc_request_done(host, host->mrq);
  876. }
  877. /*
  878. * DMA clean up for command errors
  879. */
  880. static void omap_hsmmc_dma_cleanup(struct omap_hsmmc_host *host, int errno)
  881. {
  882. int dma_ch;
  883. unsigned long flags;
  884. host->data->error = errno;
  885. spin_lock_irqsave(&host->irq_lock, flags);
  886. dma_ch = host->dma_ch;
  887. host->dma_ch = -1;
  888. spin_unlock_irqrestore(&host->irq_lock, flags);
  889. if (host->use_dma && dma_ch != -1) {
  890. struct dma_chan *chan = omap_hsmmc_get_dma_chan(host, host->data);
  891. dmaengine_terminate_all(chan);
  892. dma_unmap_sg(chan->device->dev,
  893. host->data->sg, host->data->sg_len,
  894. omap_hsmmc_get_dma_dir(host, host->data));
  895. host->data->host_cookie = 0;
  896. }
  897. host->data = NULL;
  898. }
  899. /*
  900. * Readable error output
  901. */
  902. #ifdef CONFIG_MMC_DEBUG
  903. static void omap_hsmmc_dbg_report_irq(struct omap_hsmmc_host *host, u32 status)
  904. {
  905. /* --- means reserved bit without definition at documentation */
  906. static const char *omap_hsmmc_status_bits[] = {
  907. "CC" , "TC" , "BGE", "---", "BWR" , "BRR" , "---" , "---" ,
  908. "CIRQ", "OBI" , "---", "---", "---" , "---" , "---" , "ERRI",
  909. "CTO" , "CCRC", "CEB", "CIE", "DTO" , "DCRC", "DEB" , "---" ,
  910. "ACE" , "---" , "---", "---", "CERR", "BADA", "---" , "---"
  911. };
  912. char res[256];
  913. char *buf = res;
  914. int len, i;
  915. len = sprintf(buf, "MMC IRQ 0x%x :", status);
  916. buf += len;
  917. for (i = 0; i < ARRAY_SIZE(omap_hsmmc_status_bits); i++)
  918. if (status & (1 << i)) {
  919. len = sprintf(buf, " %s", omap_hsmmc_status_bits[i]);
  920. buf += len;
  921. }
  922. dev_vdbg(mmc_dev(host->mmc), "%s\n", res);
  923. }
  924. #else
  925. static inline void omap_hsmmc_dbg_report_irq(struct omap_hsmmc_host *host,
  926. u32 status)
  927. {
  928. }
  929. #endif /* CONFIG_MMC_DEBUG */
  930. /*
  931. * MMC controller internal state machines reset
  932. *
  933. * Used to reset command or data internal state machines, using respectively
  934. * SRC or SRD bit of SYSCTL register
  935. * Can be called from interrupt context
  936. */
  937. static inline void omap_hsmmc_reset_controller_fsm(struct omap_hsmmc_host *host,
  938. unsigned long bit)
  939. {
  940. unsigned long i = 0;
  941. unsigned long limit = MMC_TIMEOUT_US;
  942. OMAP_HSMMC_WRITE(host->base, SYSCTL,
  943. OMAP_HSMMC_READ(host->base, SYSCTL) | bit);
  944. /*
  945. * OMAP4 ES2 and greater has an updated reset logic.
  946. * Monitor a 0->1 transition first
  947. */
  948. if (mmc_pdata(host)->features & HSMMC_HAS_UPDATED_RESET) {
  949. while ((!(OMAP_HSMMC_READ(host->base, SYSCTL) & bit))
  950. && (i++ < limit))
  951. udelay(1);
  952. }
  953. i = 0;
  954. while ((OMAP_HSMMC_READ(host->base, SYSCTL) & bit) &&
  955. (i++ < limit))
  956. udelay(1);
  957. if (OMAP_HSMMC_READ(host->base, SYSCTL) & bit)
  958. dev_err(mmc_dev(host->mmc),
  959. "Timeout waiting on controller reset in %s\n",
  960. __func__);
  961. }
  962. static void hsmmc_command_incomplete(struct omap_hsmmc_host *host,
  963. int err, int end_cmd)
  964. {
  965. if (end_cmd) {
  966. omap_hsmmc_reset_controller_fsm(host, SRC);
  967. if (host->cmd)
  968. host->cmd->error = err;
  969. }
  970. if (host->data) {
  971. omap_hsmmc_reset_controller_fsm(host, SRD);
  972. omap_hsmmc_dma_cleanup(host, err);
  973. } else if (host->mrq && host->mrq->cmd)
  974. host->mrq->cmd->error = err;
  975. }
  976. static void omap_hsmmc_do_irq(struct omap_hsmmc_host *host, int status)
  977. {
  978. struct mmc_data *data;
  979. int end_cmd = 0, end_trans = 0;
  980. int error = 0;
  981. data = host->data;
  982. dev_vdbg(mmc_dev(host->mmc), "IRQ Status is %x\n", status);
  983. if (status & ERR_EN) {
  984. omap_hsmmc_dbg_report_irq(host, status);
  985. if (status & (CTO_EN | CCRC_EN))
  986. end_cmd = 1;
  987. if (host->data || host->response_busy) {
  988. end_trans = !end_cmd;
  989. host->response_busy = 0;
  990. }
  991. if (status & (CTO_EN | DTO_EN))
  992. hsmmc_command_incomplete(host, -ETIMEDOUT, end_cmd);
  993. else if (status & (CCRC_EN | DCRC_EN | DEB_EN | CEB_EN |
  994. BADA_EN))
  995. hsmmc_command_incomplete(host, -EILSEQ, end_cmd);
  996. if (status & ACE_EN) {
  997. u32 ac12;
  998. ac12 = OMAP_HSMMC_READ(host->base, AC12);
  999. if (!(ac12 & ACNE) && host->mrq->sbc) {
  1000. end_cmd = 1;
  1001. if (ac12 & ACTO)
  1002. error = -ETIMEDOUT;
  1003. else if (ac12 & (ACCE | ACEB | ACIE))
  1004. error = -EILSEQ;
  1005. host->mrq->sbc->error = error;
  1006. hsmmc_command_incomplete(host, error, end_cmd);
  1007. }
  1008. dev_dbg(mmc_dev(host->mmc), "AC12 err: 0x%x\n", ac12);
  1009. }
  1010. }
  1011. OMAP_HSMMC_WRITE(host->base, STAT, status);
  1012. if (end_cmd || ((status & CC_EN) && host->cmd))
  1013. omap_hsmmc_cmd_done(host, host->cmd);
  1014. if ((end_trans || (status & TC_EN)) && host->mrq)
  1015. omap_hsmmc_xfer_done(host, data);
  1016. }
  1017. /*
  1018. * MMC controller IRQ handler
  1019. */
  1020. static irqreturn_t omap_hsmmc_irq(int irq, void *dev_id)
  1021. {
  1022. struct omap_hsmmc_host *host = dev_id;
  1023. int status;
  1024. status = OMAP_HSMMC_READ(host->base, STAT);
  1025. while (status & (INT_EN_MASK | CIRQ_EN)) {
  1026. if (host->req_in_progress)
  1027. omap_hsmmc_do_irq(host, status);
  1028. if (status & CIRQ_EN)
  1029. mmc_signal_sdio_irq(host->mmc);
  1030. /* Flush posted write */
  1031. status = OMAP_HSMMC_READ(host->base, STAT);
  1032. }
  1033. return IRQ_HANDLED;
  1034. }
  1035. static void set_sd_bus_power(struct omap_hsmmc_host *host)
  1036. {
  1037. unsigned long i;
  1038. OMAP_HSMMC_WRITE(host->base, HCTL,
  1039. OMAP_HSMMC_READ(host->base, HCTL) | SDBP);
  1040. for (i = 0; i < loops_per_jiffy; i++) {
  1041. if (OMAP_HSMMC_READ(host->base, HCTL) & SDBP)
  1042. break;
  1043. cpu_relax();
  1044. }
  1045. }
  1046. /*
  1047. * Switch MMC interface voltage ... only relevant for MMC1.
  1048. *
  1049. * MMC2 and MMC3 use fixed 1.8V levels, and maybe a transceiver.
  1050. * The MMC2 transceiver controls are used instead of DAT4..DAT7.
  1051. * Some chips, like eMMC ones, use internal transceivers.
  1052. */
  1053. static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd)
  1054. {
  1055. u32 reg_val = 0;
  1056. int ret;
  1057. /* Disable the clocks */
  1058. if (host->dbclk)
  1059. clk_disable_unprepare(host->dbclk);
  1060. /* Turn the power off */
  1061. ret = omap_hsmmc_set_power(host, 0, 0);
  1062. /* Turn the power ON with given VDD 1.8 or 3.0v */
  1063. if (!ret)
  1064. ret = omap_hsmmc_set_power(host, 1, vdd);
  1065. if (host->dbclk)
  1066. clk_prepare_enable(host->dbclk);
  1067. if (ret != 0)
  1068. goto err;
  1069. OMAP_HSMMC_WRITE(host->base, HCTL,
  1070. OMAP_HSMMC_READ(host->base, HCTL) & SDVSCLR);
  1071. reg_val = OMAP_HSMMC_READ(host->base, HCTL);
  1072. /*
  1073. * If a MMC dual voltage card is detected, the set_ios fn calls
  1074. * this fn with VDD bit set for 1.8V. Upon card removal from the
  1075. * slot, omap_hsmmc_set_ios sets the VDD back to 3V on MMC_POWER_OFF.
  1076. *
  1077. * Cope with a bit of slop in the range ... per data sheets:
  1078. * - "1.8V" for vdds_mmc1/vdds_mmc1a can be up to 2.45V max,
  1079. * but recommended values are 1.71V to 1.89V
  1080. * - "3.0V" for vdds_mmc1/vdds_mmc1a can be up to 3.5V max,
  1081. * but recommended values are 2.7V to 3.3V
  1082. *
  1083. * Board setup code shouldn't permit anything very out-of-range.
  1084. * TWL4030-family VMMC1 and VSIM regulators are fine (avoiding the
  1085. * middle range) but VSIM can't power DAT4..DAT7 at more than 3V.
  1086. */
  1087. if ((1 << vdd) <= MMC_VDD_23_24)
  1088. reg_val |= SDVS18;
  1089. else
  1090. reg_val |= SDVS30;
  1091. OMAP_HSMMC_WRITE(host->base, HCTL, reg_val);
  1092. set_sd_bus_power(host);
  1093. return 0;
  1094. err:
  1095. dev_err(mmc_dev(host->mmc), "Unable to switch operating voltage\n");
  1096. return ret;
  1097. }
  1098. /* Protect the card while the cover is open */
  1099. static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host)
  1100. {
  1101. if (!host->get_cover_state)
  1102. return;
  1103. host->reqs_blocked = 0;
  1104. if (host->get_cover_state(host->dev)) {
  1105. if (host->protect_card) {
  1106. dev_info(host->dev, "%s: cover is closed, "
  1107. "card is now accessible\n",
  1108. mmc_hostname(host->mmc));
  1109. host->protect_card = 0;
  1110. }
  1111. } else {
  1112. if (!host->protect_card) {
  1113. dev_info(host->dev, "%s: cover is open, "
  1114. "card is now inaccessible\n",
  1115. mmc_hostname(host->mmc));
  1116. host->protect_card = 1;
  1117. }
  1118. }
  1119. }
  1120. /*
  1121. * irq handler when (cell-phone) cover is mounted/removed
  1122. */
  1123. static irqreturn_t omap_hsmmc_cover_irq(int irq, void *dev_id)
  1124. {
  1125. struct omap_hsmmc_host *host = dev_id;
  1126. sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
  1127. omap_hsmmc_protect_card(host);
  1128. mmc_detect_change(host->mmc, (HZ * 200) / 1000);
  1129. return IRQ_HANDLED;
  1130. }
  1131. static void omap_hsmmc_dma_callback(void *param)
  1132. {
  1133. struct omap_hsmmc_host *host = param;
  1134. struct dma_chan *chan;
  1135. struct mmc_data *data;
  1136. int req_in_progress;
  1137. spin_lock_irq(&host->irq_lock);
  1138. if (host->dma_ch < 0) {
  1139. spin_unlock_irq(&host->irq_lock);
  1140. return;
  1141. }
  1142. data = host->mrq->data;
  1143. chan = omap_hsmmc_get_dma_chan(host, data);
  1144. if (!data->host_cookie)
  1145. dma_unmap_sg(chan->device->dev,
  1146. data->sg, data->sg_len,
  1147. omap_hsmmc_get_dma_dir(host, data));
  1148. req_in_progress = host->req_in_progress;
  1149. host->dma_ch = -1;
  1150. spin_unlock_irq(&host->irq_lock);
  1151. /* If DMA has finished after TC, complete the request */
  1152. if (!req_in_progress) {
  1153. struct mmc_request *mrq = host->mrq;
  1154. host->mrq = NULL;
  1155. mmc_request_done(host->mmc, mrq);
  1156. }
  1157. }
  1158. static int omap_hsmmc_pre_dma_transfer(struct omap_hsmmc_host *host,
  1159. struct mmc_data *data,
  1160. struct omap_hsmmc_next *next,
  1161. struct dma_chan *chan)
  1162. {
  1163. int dma_len;
  1164. if (!next && data->host_cookie &&
  1165. data->host_cookie != host->next_data.cookie) {
  1166. dev_warn(host->dev, "[%s] invalid cookie: data->host_cookie %d"
  1167. " host->next_data.cookie %d\n",
  1168. __func__, data->host_cookie, host->next_data.cookie);
  1169. data->host_cookie = 0;
  1170. }
  1171. /* Check if next job is already prepared */
  1172. if (next || data->host_cookie != host->next_data.cookie) {
  1173. dma_len = dma_map_sg(chan->device->dev, data->sg, data->sg_len,
  1174. omap_hsmmc_get_dma_dir(host, data));
  1175. } else {
  1176. dma_len = host->next_data.dma_len;
  1177. host->next_data.dma_len = 0;
  1178. }
  1179. if (dma_len == 0)
  1180. return -EINVAL;
  1181. if (next) {
  1182. next->dma_len = dma_len;
  1183. data->host_cookie = ++next->cookie < 0 ? 1 : next->cookie;
  1184. } else
  1185. host->dma_len = dma_len;
  1186. return 0;
  1187. }
  1188. /*
  1189. * Routine to configure and start DMA for the MMC card
  1190. */
  1191. static int omap_hsmmc_setup_dma_transfer(struct omap_hsmmc_host *host,
  1192. struct mmc_request *req)
  1193. {
  1194. struct dma_slave_config cfg;
  1195. struct dma_async_tx_descriptor *tx;
  1196. int ret = 0, i;
  1197. struct mmc_data *data = req->data;
  1198. struct dma_chan *chan;
  1199. /* Sanity check: all the SG entries must be aligned by block size. */
  1200. for (i = 0; i < data->sg_len; i++) {
  1201. struct scatterlist *sgl;
  1202. sgl = data->sg + i;
  1203. if (sgl->length % data->blksz)
  1204. return -EINVAL;
  1205. }
  1206. if ((data->blksz % 4) != 0)
  1207. /* REVISIT: The MMC buffer increments only when MSB is written.
  1208. * Return error for blksz which is non multiple of four.
  1209. */
  1210. return -EINVAL;
  1211. BUG_ON(host->dma_ch != -1);
  1212. chan = omap_hsmmc_get_dma_chan(host, data);
  1213. cfg.src_addr = host->mapbase + OMAP_HSMMC_DATA;
  1214. cfg.dst_addr = host->mapbase + OMAP_HSMMC_DATA;
  1215. cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  1216. cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  1217. cfg.src_maxburst = data->blksz / 4;
  1218. cfg.dst_maxburst = data->blksz / 4;
  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 (!p) {
  1495. ret = -ENODEV;
  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;
  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. if (of_find_property(np, "ti,dual-volt", NULL))
  1655. pdata->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT;
  1656. pdata->gpio_cd = -EINVAL;
  1657. pdata->gpio_cod = -EINVAL;
  1658. pdata->gpio_wp = -EINVAL;
  1659. if (of_find_property(np, "ti,non-removable", NULL)) {
  1660. pdata->nonremovable = true;
  1661. pdata->no_regulator_off_init = true;
  1662. }
  1663. if (of_find_property(np, "ti,needs-special-reset", NULL))
  1664. pdata->features |= HSMMC_HAS_UPDATED_RESET;
  1665. if (of_find_property(np, "ti,needs-special-hs-handling", NULL))
  1666. pdata->features |= HSMMC_HAS_HSPE_SUPPORT;
  1667. return pdata;
  1668. }
  1669. #else
  1670. static inline struct omap_hsmmc_platform_data
  1671. *of_get_hsmmc_pdata(struct device *dev)
  1672. {
  1673. return ERR_PTR(-EINVAL);
  1674. }
  1675. #endif
  1676. static int omap_hsmmc_probe(struct platform_device *pdev)
  1677. {
  1678. struct omap_hsmmc_platform_data *pdata = pdev->dev.platform_data;
  1679. struct mmc_host *mmc;
  1680. struct omap_hsmmc_host *host = NULL;
  1681. struct resource *res;
  1682. int ret, irq;
  1683. const struct of_device_id *match;
  1684. dma_cap_mask_t mask;
  1685. unsigned tx_req, rx_req;
  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. if (!pdev->dev.of_node) {
  1787. res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx");
  1788. if (!res) {
  1789. dev_err(mmc_dev(host->mmc), "cannot get DMA TX channel\n");
  1790. ret = -ENXIO;
  1791. goto err_irq;
  1792. }
  1793. tx_req = res->start;
  1794. res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
  1795. if (!res) {
  1796. dev_err(mmc_dev(host->mmc), "cannot get DMA RX channel\n");
  1797. ret = -ENXIO;
  1798. goto err_irq;
  1799. }
  1800. rx_req = res->start;
  1801. }
  1802. dma_cap_zero(mask);
  1803. dma_cap_set(DMA_SLAVE, mask);
  1804. host->rx_chan =
  1805. dma_request_slave_channel_compat(mask, omap_dma_filter_fn,
  1806. &rx_req, &pdev->dev, "rx");
  1807. if (!host->rx_chan) {
  1808. dev_err(mmc_dev(host->mmc), "unable to obtain RX DMA engine channel\n");
  1809. ret = -ENXIO;
  1810. goto err_irq;
  1811. }
  1812. host->tx_chan =
  1813. dma_request_slave_channel_compat(mask, omap_dma_filter_fn,
  1814. &tx_req, &pdev->dev, "tx");
  1815. if (!host->tx_chan) {
  1816. dev_err(mmc_dev(host->mmc), "unable to obtain TX DMA engine channel\n");
  1817. ret = -ENXIO;
  1818. goto err_irq;
  1819. }
  1820. /* Request IRQ for MMC operations */
  1821. ret = devm_request_irq(&pdev->dev, host->irq, omap_hsmmc_irq, 0,
  1822. mmc_hostname(mmc), host);
  1823. if (ret) {
  1824. dev_err(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n");
  1825. goto err_irq;
  1826. }
  1827. ret = omap_hsmmc_reg_get(host);
  1828. if (ret)
  1829. goto err_irq;
  1830. mmc->ocr_avail = mmc_pdata(host)->ocr_mask;
  1831. omap_hsmmc_disable_irq(host);
  1832. /*
  1833. * For now, only support SDIO interrupt if we have a separate
  1834. * wake-up interrupt configured from device tree. This is because
  1835. * the wake-up interrupt is needed for idle state and some
  1836. * platforms need special quirks. And we don't want to add new
  1837. * legacy mux platform init code callbacks any longer as we
  1838. * are moving to DT based booting anyways.
  1839. */
  1840. ret = omap_hsmmc_configure_wake_irq(host);
  1841. if (!ret)
  1842. mmc->caps |= MMC_CAP_SDIO_IRQ;
  1843. omap_hsmmc_protect_card(host);
  1844. mmc_add_host(mmc);
  1845. if (mmc_pdata(host)->name != NULL) {
  1846. ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name);
  1847. if (ret < 0)
  1848. goto err_slot_name;
  1849. }
  1850. if (host->get_cover_state) {
  1851. ret = device_create_file(&mmc->class_dev,
  1852. &dev_attr_cover_switch);
  1853. if (ret < 0)
  1854. goto err_slot_name;
  1855. }
  1856. omap_hsmmc_debugfs(mmc);
  1857. pm_runtime_mark_last_busy(host->dev);
  1858. pm_runtime_put_autosuspend(host->dev);
  1859. return 0;
  1860. err_slot_name:
  1861. mmc_remove_host(mmc);
  1862. err_irq:
  1863. device_init_wakeup(&pdev->dev, false);
  1864. if (host->tx_chan)
  1865. dma_release_channel(host->tx_chan);
  1866. if (host->rx_chan)
  1867. dma_release_channel(host->rx_chan);
  1868. pm_runtime_dont_use_autosuspend(host->dev);
  1869. pm_runtime_put_sync(host->dev);
  1870. pm_runtime_disable(host->dev);
  1871. if (host->dbclk)
  1872. clk_disable_unprepare(host->dbclk);
  1873. err1:
  1874. err_gpio:
  1875. mmc_free_host(mmc);
  1876. err:
  1877. return ret;
  1878. }
  1879. static int omap_hsmmc_remove(struct platform_device *pdev)
  1880. {
  1881. struct omap_hsmmc_host *host = platform_get_drvdata(pdev);
  1882. pm_runtime_get_sync(host->dev);
  1883. mmc_remove_host(host->mmc);
  1884. dma_release_channel(host->tx_chan);
  1885. dma_release_channel(host->rx_chan);
  1886. pm_runtime_dont_use_autosuspend(host->dev);
  1887. pm_runtime_put_sync(host->dev);
  1888. pm_runtime_disable(host->dev);
  1889. device_init_wakeup(&pdev->dev, false);
  1890. if (host->dbclk)
  1891. clk_disable_unprepare(host->dbclk);
  1892. mmc_free_host(host->mmc);
  1893. return 0;
  1894. }
  1895. #ifdef CONFIG_PM_SLEEP
  1896. static int omap_hsmmc_suspend(struct device *dev)
  1897. {
  1898. struct omap_hsmmc_host *host = dev_get_drvdata(dev);
  1899. if (!host)
  1900. return 0;
  1901. pm_runtime_get_sync(host->dev);
  1902. if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) {
  1903. OMAP_HSMMC_WRITE(host->base, ISE, 0);
  1904. OMAP_HSMMC_WRITE(host->base, IE, 0);
  1905. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  1906. OMAP_HSMMC_WRITE(host->base, HCTL,
  1907. OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP);
  1908. }
  1909. if (host->dbclk)
  1910. clk_disable_unprepare(host->dbclk);
  1911. pm_runtime_put_sync(host->dev);
  1912. return 0;
  1913. }
  1914. /* Routine to resume the MMC device */
  1915. static int omap_hsmmc_resume(struct device *dev)
  1916. {
  1917. struct omap_hsmmc_host *host = dev_get_drvdata(dev);
  1918. if (!host)
  1919. return 0;
  1920. pm_runtime_get_sync(host->dev);
  1921. if (host->dbclk)
  1922. clk_prepare_enable(host->dbclk);
  1923. if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER))
  1924. omap_hsmmc_conf_bus_power(host);
  1925. omap_hsmmc_protect_card(host);
  1926. pm_runtime_mark_last_busy(host->dev);
  1927. pm_runtime_put_autosuspend(host->dev);
  1928. return 0;
  1929. }
  1930. #endif
  1931. static int omap_hsmmc_runtime_suspend(struct device *dev)
  1932. {
  1933. struct omap_hsmmc_host *host;
  1934. unsigned long flags;
  1935. int ret = 0;
  1936. host = platform_get_drvdata(to_platform_device(dev));
  1937. omap_hsmmc_context_save(host);
  1938. dev_dbg(dev, "disabled\n");
  1939. spin_lock_irqsave(&host->irq_lock, flags);
  1940. if ((host->mmc->caps & MMC_CAP_SDIO_IRQ) &&
  1941. (host->flags & HSMMC_SDIO_IRQ_ENABLED)) {
  1942. /* disable sdio irq handling to prevent race */
  1943. OMAP_HSMMC_WRITE(host->base, ISE, 0);
  1944. OMAP_HSMMC_WRITE(host->base, IE, 0);
  1945. if (!(OMAP_HSMMC_READ(host->base, PSTATE) & DLEV_DAT(1))) {
  1946. /*
  1947. * dat1 line low, pending sdio irq
  1948. * race condition: possible irq handler running on
  1949. * multi-core, abort
  1950. */
  1951. dev_dbg(dev, "pending sdio irq, abort suspend\n");
  1952. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  1953. OMAP_HSMMC_WRITE(host->base, ISE, CIRQ_EN);
  1954. OMAP_HSMMC_WRITE(host->base, IE, CIRQ_EN);
  1955. pm_runtime_mark_last_busy(dev);
  1956. ret = -EBUSY;
  1957. goto abort;
  1958. }
  1959. pinctrl_pm_select_idle_state(dev);
  1960. } else {
  1961. pinctrl_pm_select_idle_state(dev);
  1962. }
  1963. abort:
  1964. spin_unlock_irqrestore(&host->irq_lock, flags);
  1965. return ret;
  1966. }
  1967. static int omap_hsmmc_runtime_resume(struct device *dev)
  1968. {
  1969. struct omap_hsmmc_host *host;
  1970. unsigned long flags;
  1971. host = platform_get_drvdata(to_platform_device(dev));
  1972. omap_hsmmc_context_restore(host);
  1973. dev_dbg(dev, "enabled\n");
  1974. spin_lock_irqsave(&host->irq_lock, flags);
  1975. if ((host->mmc->caps & MMC_CAP_SDIO_IRQ) &&
  1976. (host->flags & HSMMC_SDIO_IRQ_ENABLED)) {
  1977. pinctrl_pm_select_default_state(host->dev);
  1978. /* irq lost, if pinmux incorrect */
  1979. OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
  1980. OMAP_HSMMC_WRITE(host->base, ISE, CIRQ_EN);
  1981. OMAP_HSMMC_WRITE(host->base, IE, CIRQ_EN);
  1982. } else {
  1983. pinctrl_pm_select_default_state(host->dev);
  1984. }
  1985. spin_unlock_irqrestore(&host->irq_lock, flags);
  1986. return 0;
  1987. }
  1988. static struct dev_pm_ops omap_hsmmc_dev_pm_ops = {
  1989. SET_SYSTEM_SLEEP_PM_OPS(omap_hsmmc_suspend, omap_hsmmc_resume)
  1990. .runtime_suspend = omap_hsmmc_runtime_suspend,
  1991. .runtime_resume = omap_hsmmc_runtime_resume,
  1992. };
  1993. static struct platform_driver omap_hsmmc_driver = {
  1994. .probe = omap_hsmmc_probe,
  1995. .remove = omap_hsmmc_remove,
  1996. .driver = {
  1997. .name = DRIVER_NAME,
  1998. .pm = &omap_hsmmc_dev_pm_ops,
  1999. .of_match_table = of_match_ptr(omap_mmc_of_match),
  2000. },
  2001. };
  2002. module_platform_driver(omap_hsmmc_driver);
  2003. MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver");
  2004. MODULE_LICENSE("GPL");
  2005. MODULE_ALIAS("platform:" DRIVER_NAME);
  2006. MODULE_AUTHOR("Texas Instruments Inc");