omap_hsmmc.c 58 KB

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