omap_hsmmc.c 58 KB

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