sdhci-omap.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. /**
  2. * SDHCI Controller driver for TI's OMAP SoCs
  3. *
  4. * Copyright (C) 2017 Texas Instruments
  5. * Author: Kishon Vijay Abraham I <kishon@ti.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 of
  9. * the License as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/delay.h>
  20. #include <linux/mmc/slot-gpio.h>
  21. #include <linux/module.h>
  22. #include <linux/of.h>
  23. #include <linux/of_device.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/pm_runtime.h>
  26. #include <linux/regulator/consumer.h>
  27. #include <linux/pinctrl/consumer.h>
  28. #include <linux/sys_soc.h>
  29. #include <linux/thermal.h>
  30. #include "sdhci-pltfm.h"
  31. #define SDHCI_OMAP_CON 0x12c
  32. #define CON_DW8 BIT(5)
  33. #define CON_DMA_MASTER BIT(20)
  34. #define CON_DDR BIT(19)
  35. #define CON_CLKEXTFREE BIT(16)
  36. #define CON_PADEN BIT(15)
  37. #define CON_CTPL BIT(11)
  38. #define CON_INIT BIT(1)
  39. #define CON_OD BIT(0)
  40. #define SDHCI_OMAP_DLL 0x0134
  41. #define DLL_SWT BIT(20)
  42. #define DLL_FORCE_SR_C_SHIFT 13
  43. #define DLL_FORCE_SR_C_MASK (0x7f << DLL_FORCE_SR_C_SHIFT)
  44. #define DLL_FORCE_VALUE BIT(12)
  45. #define DLL_CALIB BIT(1)
  46. #define SDHCI_OMAP_CMD 0x20c
  47. #define SDHCI_OMAP_PSTATE 0x0224
  48. #define PSTATE_DLEV_DAT0 BIT(20)
  49. #define PSTATE_DATI BIT(1)
  50. #define SDHCI_OMAP_HCTL 0x228
  51. #define HCTL_SDBP BIT(8)
  52. #define HCTL_SDVS_SHIFT 9
  53. #define HCTL_SDVS_MASK (0x7 << HCTL_SDVS_SHIFT)
  54. #define HCTL_SDVS_33 (0x7 << HCTL_SDVS_SHIFT)
  55. #define HCTL_SDVS_30 (0x6 << HCTL_SDVS_SHIFT)
  56. #define HCTL_SDVS_18 (0x5 << HCTL_SDVS_SHIFT)
  57. #define SDHCI_OMAP_SYSCTL 0x22c
  58. #define SYSCTL_CEN BIT(2)
  59. #define SYSCTL_CLKD_SHIFT 6
  60. #define SYSCTL_CLKD_MASK 0x3ff
  61. #define SDHCI_OMAP_STAT 0x230
  62. #define SDHCI_OMAP_IE 0x234
  63. #define INT_CC_EN BIT(0)
  64. #define SDHCI_OMAP_AC12 0x23c
  65. #define AC12_V1V8_SIGEN BIT(19)
  66. #define AC12_SCLK_SEL BIT(23)
  67. #define SDHCI_OMAP_CAPA 0x240
  68. #define CAPA_VS33 BIT(24)
  69. #define CAPA_VS30 BIT(25)
  70. #define CAPA_VS18 BIT(26)
  71. #define SDHCI_OMAP_CAPA2 0x0244
  72. #define CAPA2_TSDR50 BIT(13)
  73. #define SDHCI_OMAP_TIMEOUT 1 /* 1 msec */
  74. #define SYSCTL_CLKD_MAX 0x3FF
  75. #define IOV_1V8 1800000 /* 180000 uV */
  76. #define IOV_3V0 3000000 /* 300000 uV */
  77. #define IOV_3V3 3300000 /* 330000 uV */
  78. #define MAX_PHASE_DELAY 0x7C
  79. /* sdhci-omap controller flags */
  80. #define SDHCI_OMAP_REQUIRE_IODELAY BIT(0)
  81. struct sdhci_omap_data {
  82. u32 offset;
  83. u8 flags;
  84. };
  85. struct sdhci_omap_host {
  86. char *version;
  87. void __iomem *base;
  88. struct device *dev;
  89. struct regulator *pbias;
  90. bool pbias_enabled;
  91. struct sdhci_host *host;
  92. u8 bus_mode;
  93. u8 power_mode;
  94. u8 timing;
  95. u8 flags;
  96. struct pinctrl *pinctrl;
  97. struct pinctrl_state **pinctrl_state;
  98. bool is_tuning;
  99. };
  100. static void sdhci_omap_start_clock(struct sdhci_omap_host *omap_host);
  101. static void sdhci_omap_stop_clock(struct sdhci_omap_host *omap_host);
  102. static inline u32 sdhci_omap_readl(struct sdhci_omap_host *host,
  103. unsigned int offset)
  104. {
  105. return readl(host->base + offset);
  106. }
  107. static inline void sdhci_omap_writel(struct sdhci_omap_host *host,
  108. unsigned int offset, u32 data)
  109. {
  110. writel(data, host->base + offset);
  111. }
  112. static int sdhci_omap_set_pbias(struct sdhci_omap_host *omap_host,
  113. bool power_on, unsigned int iov)
  114. {
  115. int ret;
  116. struct device *dev = omap_host->dev;
  117. if (IS_ERR(omap_host->pbias))
  118. return 0;
  119. if (power_on) {
  120. ret = regulator_set_voltage(omap_host->pbias, iov, iov);
  121. if (ret) {
  122. dev_err(dev, "pbias set voltage failed\n");
  123. return ret;
  124. }
  125. if (omap_host->pbias_enabled)
  126. return 0;
  127. ret = regulator_enable(omap_host->pbias);
  128. if (ret) {
  129. dev_err(dev, "pbias reg enable fail\n");
  130. return ret;
  131. }
  132. omap_host->pbias_enabled = true;
  133. } else {
  134. if (!omap_host->pbias_enabled)
  135. return 0;
  136. ret = regulator_disable(omap_host->pbias);
  137. if (ret) {
  138. dev_err(dev, "pbias reg disable fail\n");
  139. return ret;
  140. }
  141. omap_host->pbias_enabled = false;
  142. }
  143. return 0;
  144. }
  145. static int sdhci_omap_enable_iov(struct sdhci_omap_host *omap_host,
  146. unsigned int iov)
  147. {
  148. int ret;
  149. struct sdhci_host *host = omap_host->host;
  150. struct mmc_host *mmc = host->mmc;
  151. ret = sdhci_omap_set_pbias(omap_host, false, 0);
  152. if (ret)
  153. return ret;
  154. if (!IS_ERR(mmc->supply.vqmmc)) {
  155. ret = regulator_set_voltage(mmc->supply.vqmmc, iov, iov);
  156. if (ret) {
  157. dev_err(mmc_dev(mmc), "vqmmc set voltage failed\n");
  158. return ret;
  159. }
  160. }
  161. ret = sdhci_omap_set_pbias(omap_host, true, iov);
  162. if (ret)
  163. return ret;
  164. return 0;
  165. }
  166. static void sdhci_omap_conf_bus_power(struct sdhci_omap_host *omap_host,
  167. unsigned char signal_voltage)
  168. {
  169. u32 reg;
  170. ktime_t timeout;
  171. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_HCTL);
  172. reg &= ~HCTL_SDVS_MASK;
  173. if (signal_voltage == MMC_SIGNAL_VOLTAGE_330)
  174. reg |= HCTL_SDVS_33;
  175. else
  176. reg |= HCTL_SDVS_18;
  177. sdhci_omap_writel(omap_host, SDHCI_OMAP_HCTL, reg);
  178. reg |= HCTL_SDBP;
  179. sdhci_omap_writel(omap_host, SDHCI_OMAP_HCTL, reg);
  180. /* wait 1ms */
  181. timeout = ktime_add_ms(ktime_get(), SDHCI_OMAP_TIMEOUT);
  182. while (1) {
  183. bool timedout = ktime_after(ktime_get(), timeout);
  184. if (sdhci_omap_readl(omap_host, SDHCI_OMAP_HCTL) & HCTL_SDBP)
  185. break;
  186. if (WARN_ON(timedout))
  187. return;
  188. usleep_range(5, 10);
  189. }
  190. }
  191. static void sdhci_omap_enable_sdio_irq(struct mmc_host *mmc, int enable)
  192. {
  193. struct sdhci_host *host = mmc_priv(mmc);
  194. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  195. struct sdhci_omap_host *omap_host = sdhci_pltfm_priv(pltfm_host);
  196. u32 reg;
  197. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_CON);
  198. if (enable)
  199. reg |= (CON_CTPL | CON_CLKEXTFREE);
  200. else
  201. reg &= ~(CON_CTPL | CON_CLKEXTFREE);
  202. sdhci_omap_writel(omap_host, SDHCI_OMAP_CON, reg);
  203. sdhci_enable_sdio_irq(mmc, enable);
  204. }
  205. static inline void sdhci_omap_set_dll(struct sdhci_omap_host *omap_host,
  206. int count)
  207. {
  208. int i;
  209. u32 reg;
  210. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_DLL);
  211. reg |= DLL_FORCE_VALUE;
  212. reg &= ~DLL_FORCE_SR_C_MASK;
  213. reg |= (count << DLL_FORCE_SR_C_SHIFT);
  214. sdhci_omap_writel(omap_host, SDHCI_OMAP_DLL, reg);
  215. reg |= DLL_CALIB;
  216. sdhci_omap_writel(omap_host, SDHCI_OMAP_DLL, reg);
  217. for (i = 0; i < 1000; i++) {
  218. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_DLL);
  219. if (reg & DLL_CALIB)
  220. break;
  221. }
  222. reg &= ~DLL_CALIB;
  223. sdhci_omap_writel(omap_host, SDHCI_OMAP_DLL, reg);
  224. }
  225. static void sdhci_omap_disable_tuning(struct sdhci_omap_host *omap_host)
  226. {
  227. u32 reg;
  228. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_AC12);
  229. reg &= ~AC12_SCLK_SEL;
  230. sdhci_omap_writel(omap_host, SDHCI_OMAP_AC12, reg);
  231. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_DLL);
  232. reg &= ~(DLL_FORCE_VALUE | DLL_SWT);
  233. sdhci_omap_writel(omap_host, SDHCI_OMAP_DLL, reg);
  234. }
  235. static int sdhci_omap_execute_tuning(struct mmc_host *mmc, u32 opcode)
  236. {
  237. struct sdhci_host *host = mmc_priv(mmc);
  238. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  239. struct sdhci_omap_host *omap_host = sdhci_pltfm_priv(pltfm_host);
  240. struct thermal_zone_device *thermal_dev;
  241. struct device *dev = omap_host->dev;
  242. struct mmc_ios *ios = &mmc->ios;
  243. u32 start_window = 0, max_window = 0;
  244. bool single_point_failure = false;
  245. bool dcrc_was_enabled = false;
  246. u8 cur_match, prev_match = 0;
  247. u32 length = 0, max_len = 0;
  248. u32 phase_delay = 0;
  249. int temperature;
  250. int ret = 0;
  251. u32 reg;
  252. int i;
  253. pltfm_host = sdhci_priv(host);
  254. omap_host = sdhci_pltfm_priv(pltfm_host);
  255. dev = omap_host->dev;
  256. /* clock tuning is not needed for upto 52MHz */
  257. if (ios->clock <= 52000000)
  258. return 0;
  259. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_CAPA2);
  260. if (ios->timing == MMC_TIMING_UHS_SDR50 && !(reg & CAPA2_TSDR50))
  261. return 0;
  262. thermal_dev = thermal_zone_get_zone_by_name("cpu_thermal");
  263. if (IS_ERR(thermal_dev)) {
  264. dev_err(dev, "Unable to get thermal zone for tuning\n");
  265. return PTR_ERR(thermal_dev);
  266. }
  267. ret = thermal_zone_get_temp(thermal_dev, &temperature);
  268. if (ret)
  269. return ret;
  270. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_DLL);
  271. reg |= DLL_SWT;
  272. sdhci_omap_writel(omap_host, SDHCI_OMAP_DLL, reg);
  273. /*
  274. * OMAP5/DRA74X/DRA72x Errata i802:
  275. * DCRC error interrupts (MMCHS_STAT[21] DCRC=0x1) can occur
  276. * during the tuning procedure. So disable it during the
  277. * tuning procedure.
  278. */
  279. if (host->ier & SDHCI_INT_DATA_CRC) {
  280. host->ier &= ~SDHCI_INT_DATA_CRC;
  281. dcrc_was_enabled = true;
  282. }
  283. omap_host->is_tuning = true;
  284. /*
  285. * Stage 1: Search for a maximum pass window ignoring any
  286. * any single point failures. If the tuning value ends up
  287. * near it, move away from it in stage 2 below
  288. */
  289. while (phase_delay <= MAX_PHASE_DELAY) {
  290. sdhci_omap_set_dll(omap_host, phase_delay);
  291. cur_match = !mmc_send_tuning(mmc, opcode, NULL);
  292. if (cur_match) {
  293. if (prev_match) {
  294. length++;
  295. } else if (single_point_failure) {
  296. /* ignore single point failure */
  297. length++;
  298. } else {
  299. start_window = phase_delay;
  300. length = 1;
  301. }
  302. } else {
  303. single_point_failure = prev_match;
  304. }
  305. if (length > max_len) {
  306. max_window = start_window;
  307. max_len = length;
  308. }
  309. prev_match = cur_match;
  310. phase_delay += 4;
  311. }
  312. if (!max_len) {
  313. dev_err(dev, "Unable to find match\n");
  314. ret = -EIO;
  315. goto tuning_error;
  316. }
  317. /*
  318. * Assign tuning value as a ratio of maximum pass window based
  319. * on temperature
  320. */
  321. if (temperature < -20000)
  322. phase_delay = min(max_window + 4 * (max_len - 1) - 24,
  323. max_window +
  324. DIV_ROUND_UP(13 * max_len, 16) * 4);
  325. else if (temperature < 20000)
  326. phase_delay = max_window + DIV_ROUND_UP(9 * max_len, 16) * 4;
  327. else if (temperature < 40000)
  328. phase_delay = max_window + DIV_ROUND_UP(8 * max_len, 16) * 4;
  329. else if (temperature < 70000)
  330. phase_delay = max_window + DIV_ROUND_UP(7 * max_len, 16) * 4;
  331. else if (temperature < 90000)
  332. phase_delay = max_window + DIV_ROUND_UP(5 * max_len, 16) * 4;
  333. else if (temperature < 120000)
  334. phase_delay = max_window + DIV_ROUND_UP(4 * max_len, 16) * 4;
  335. else
  336. phase_delay = max_window + DIV_ROUND_UP(3 * max_len, 16) * 4;
  337. /*
  338. * Stage 2: Search for a single point failure near the chosen tuning
  339. * value in two steps. First in the +3 to +10 range and then in the
  340. * +2 to -10 range. If found, move away from it in the appropriate
  341. * direction by the appropriate amount depending on the temperature.
  342. */
  343. for (i = 3; i <= 10; i++) {
  344. sdhci_omap_set_dll(omap_host, phase_delay + i);
  345. if (mmc_send_tuning(mmc, opcode, NULL)) {
  346. if (temperature < 10000)
  347. phase_delay += i + 6;
  348. else if (temperature < 20000)
  349. phase_delay += i - 12;
  350. else if (temperature < 70000)
  351. phase_delay += i - 8;
  352. else
  353. phase_delay += i - 6;
  354. goto single_failure_found;
  355. }
  356. }
  357. for (i = 2; i >= -10; i--) {
  358. sdhci_omap_set_dll(omap_host, phase_delay + i);
  359. if (mmc_send_tuning(mmc, opcode, NULL)) {
  360. if (temperature < 10000)
  361. phase_delay += i + 12;
  362. else if (temperature < 20000)
  363. phase_delay += i + 8;
  364. else if (temperature < 70000)
  365. phase_delay += i + 8;
  366. else if (temperature < 90000)
  367. phase_delay += i + 10;
  368. else
  369. phase_delay += i + 12;
  370. goto single_failure_found;
  371. }
  372. }
  373. single_failure_found:
  374. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_AC12);
  375. if (!(reg & AC12_SCLK_SEL)) {
  376. ret = -EIO;
  377. goto tuning_error;
  378. }
  379. sdhci_omap_set_dll(omap_host, phase_delay);
  380. omap_host->is_tuning = false;
  381. goto ret;
  382. tuning_error:
  383. omap_host->is_tuning = false;
  384. dev_err(dev, "Tuning failed\n");
  385. sdhci_omap_disable_tuning(omap_host);
  386. ret:
  387. sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
  388. /* Reenable forbidden interrupt */
  389. if (dcrc_was_enabled)
  390. host->ier |= SDHCI_INT_DATA_CRC;
  391. sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
  392. sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
  393. return ret;
  394. }
  395. static int sdhci_omap_card_busy(struct mmc_host *mmc)
  396. {
  397. u32 reg, ac12;
  398. int ret = false;
  399. struct sdhci_host *host = mmc_priv(mmc);
  400. struct sdhci_pltfm_host *pltfm_host;
  401. struct sdhci_omap_host *omap_host;
  402. u32 ier = host->ier;
  403. pltfm_host = sdhci_priv(host);
  404. omap_host = sdhci_pltfm_priv(pltfm_host);
  405. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_CON);
  406. ac12 = sdhci_omap_readl(omap_host, SDHCI_OMAP_AC12);
  407. reg &= ~CON_CLKEXTFREE;
  408. if (ac12 & AC12_V1V8_SIGEN)
  409. reg |= CON_CLKEXTFREE;
  410. reg |= CON_PADEN;
  411. sdhci_omap_writel(omap_host, SDHCI_OMAP_CON, reg);
  412. disable_irq(host->irq);
  413. ier |= SDHCI_INT_CARD_INT;
  414. sdhci_writel(host, ier, SDHCI_INT_ENABLE);
  415. sdhci_writel(host, ier, SDHCI_SIGNAL_ENABLE);
  416. /*
  417. * Delay is required for PSTATE to correctly reflect
  418. * DLEV/CLEV values after PADEN is set.
  419. */
  420. usleep_range(50, 100);
  421. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_PSTATE);
  422. if ((reg & PSTATE_DATI) || !(reg & PSTATE_DLEV_DAT0))
  423. ret = true;
  424. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_CON);
  425. reg &= ~(CON_CLKEXTFREE | CON_PADEN);
  426. sdhci_omap_writel(omap_host, SDHCI_OMAP_CON, reg);
  427. sdhci_writel(host, host->ier, SDHCI_INT_ENABLE);
  428. sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
  429. enable_irq(host->irq);
  430. return ret;
  431. }
  432. static int sdhci_omap_start_signal_voltage_switch(struct mmc_host *mmc,
  433. struct mmc_ios *ios)
  434. {
  435. u32 reg;
  436. int ret;
  437. unsigned int iov;
  438. struct sdhci_host *host = mmc_priv(mmc);
  439. struct sdhci_pltfm_host *pltfm_host;
  440. struct sdhci_omap_host *omap_host;
  441. struct device *dev;
  442. pltfm_host = sdhci_priv(host);
  443. omap_host = sdhci_pltfm_priv(pltfm_host);
  444. dev = omap_host->dev;
  445. if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330) {
  446. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_CAPA);
  447. if (!(reg & CAPA_VS33))
  448. return -EOPNOTSUPP;
  449. sdhci_omap_conf_bus_power(omap_host, ios->signal_voltage);
  450. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_AC12);
  451. reg &= ~AC12_V1V8_SIGEN;
  452. sdhci_omap_writel(omap_host, SDHCI_OMAP_AC12, reg);
  453. iov = IOV_3V3;
  454. } else if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180) {
  455. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_CAPA);
  456. if (!(reg & CAPA_VS18))
  457. return -EOPNOTSUPP;
  458. sdhci_omap_conf_bus_power(omap_host, ios->signal_voltage);
  459. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_AC12);
  460. reg |= AC12_V1V8_SIGEN;
  461. sdhci_omap_writel(omap_host, SDHCI_OMAP_AC12, reg);
  462. iov = IOV_1V8;
  463. } else {
  464. return -EOPNOTSUPP;
  465. }
  466. ret = sdhci_omap_enable_iov(omap_host, iov);
  467. if (ret) {
  468. dev_err(dev, "failed to switch IO voltage to %dmV\n", iov);
  469. return ret;
  470. }
  471. dev_dbg(dev, "IO voltage switched to %dmV\n", iov);
  472. return 0;
  473. }
  474. static void sdhci_omap_set_timing(struct sdhci_omap_host *omap_host, u8 timing)
  475. {
  476. int ret;
  477. struct pinctrl_state *pinctrl_state;
  478. struct device *dev = omap_host->dev;
  479. if (!(omap_host->flags & SDHCI_OMAP_REQUIRE_IODELAY))
  480. return;
  481. if (omap_host->timing == timing)
  482. return;
  483. sdhci_omap_stop_clock(omap_host);
  484. pinctrl_state = omap_host->pinctrl_state[timing];
  485. ret = pinctrl_select_state(omap_host->pinctrl, pinctrl_state);
  486. if (ret) {
  487. dev_err(dev, "failed to select pinctrl state\n");
  488. return;
  489. }
  490. sdhci_omap_start_clock(omap_host);
  491. omap_host->timing = timing;
  492. }
  493. static void sdhci_omap_set_power_mode(struct sdhci_omap_host *omap_host,
  494. u8 power_mode)
  495. {
  496. if (omap_host->bus_mode == MMC_POWER_OFF)
  497. sdhci_omap_disable_tuning(omap_host);
  498. omap_host->power_mode = power_mode;
  499. }
  500. static void sdhci_omap_set_bus_mode(struct sdhci_omap_host *omap_host,
  501. unsigned int mode)
  502. {
  503. u32 reg;
  504. if (omap_host->bus_mode == mode)
  505. return;
  506. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_CON);
  507. if (mode == MMC_BUSMODE_OPENDRAIN)
  508. reg |= CON_OD;
  509. else
  510. reg &= ~CON_OD;
  511. sdhci_omap_writel(omap_host, SDHCI_OMAP_CON, reg);
  512. omap_host->bus_mode = mode;
  513. }
  514. static void sdhci_omap_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  515. {
  516. struct sdhci_host *host = mmc_priv(mmc);
  517. struct sdhci_pltfm_host *pltfm_host;
  518. struct sdhci_omap_host *omap_host;
  519. pltfm_host = sdhci_priv(host);
  520. omap_host = sdhci_pltfm_priv(pltfm_host);
  521. sdhci_omap_set_bus_mode(omap_host, ios->bus_mode);
  522. sdhci_omap_set_timing(omap_host, ios->timing);
  523. sdhci_set_ios(mmc, ios);
  524. sdhci_omap_set_power_mode(omap_host, ios->power_mode);
  525. }
  526. static u16 sdhci_omap_calc_divisor(struct sdhci_pltfm_host *host,
  527. unsigned int clock)
  528. {
  529. u16 dsor;
  530. dsor = DIV_ROUND_UP(clk_get_rate(host->clk), clock);
  531. if (dsor > SYSCTL_CLKD_MAX)
  532. dsor = SYSCTL_CLKD_MAX;
  533. return dsor;
  534. }
  535. static void sdhci_omap_start_clock(struct sdhci_omap_host *omap_host)
  536. {
  537. u32 reg;
  538. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_SYSCTL);
  539. reg |= SYSCTL_CEN;
  540. sdhci_omap_writel(omap_host, SDHCI_OMAP_SYSCTL, reg);
  541. }
  542. static void sdhci_omap_stop_clock(struct sdhci_omap_host *omap_host)
  543. {
  544. u32 reg;
  545. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_SYSCTL);
  546. reg &= ~SYSCTL_CEN;
  547. sdhci_omap_writel(omap_host, SDHCI_OMAP_SYSCTL, reg);
  548. }
  549. static void sdhci_omap_set_clock(struct sdhci_host *host, unsigned int clock)
  550. {
  551. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  552. struct sdhci_omap_host *omap_host = sdhci_pltfm_priv(pltfm_host);
  553. unsigned long clkdiv;
  554. sdhci_omap_stop_clock(omap_host);
  555. if (!clock)
  556. return;
  557. clkdiv = sdhci_omap_calc_divisor(pltfm_host, clock);
  558. clkdiv = (clkdiv & SYSCTL_CLKD_MASK) << SYSCTL_CLKD_SHIFT;
  559. sdhci_enable_clk(host, clkdiv);
  560. sdhci_omap_start_clock(omap_host);
  561. }
  562. static void sdhci_omap_set_power(struct sdhci_host *host, unsigned char mode,
  563. unsigned short vdd)
  564. {
  565. struct mmc_host *mmc = host->mmc;
  566. mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd);
  567. }
  568. static int sdhci_omap_enable_dma(struct sdhci_host *host)
  569. {
  570. u32 reg;
  571. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  572. struct sdhci_omap_host *omap_host = sdhci_pltfm_priv(pltfm_host);
  573. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_CON);
  574. reg |= CON_DMA_MASTER;
  575. sdhci_omap_writel(omap_host, SDHCI_OMAP_CON, reg);
  576. return 0;
  577. }
  578. static unsigned int sdhci_omap_get_min_clock(struct sdhci_host *host)
  579. {
  580. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  581. return clk_get_rate(pltfm_host->clk) / SYSCTL_CLKD_MAX;
  582. }
  583. static void sdhci_omap_set_bus_width(struct sdhci_host *host, int width)
  584. {
  585. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  586. struct sdhci_omap_host *omap_host = sdhci_pltfm_priv(pltfm_host);
  587. u32 reg;
  588. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_CON);
  589. if (width == MMC_BUS_WIDTH_8)
  590. reg |= CON_DW8;
  591. else
  592. reg &= ~CON_DW8;
  593. sdhci_omap_writel(omap_host, SDHCI_OMAP_CON, reg);
  594. sdhci_set_bus_width(host, width);
  595. }
  596. static void sdhci_omap_init_74_clocks(struct sdhci_host *host, u8 power_mode)
  597. {
  598. u32 reg;
  599. ktime_t timeout;
  600. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  601. struct sdhci_omap_host *omap_host = sdhci_pltfm_priv(pltfm_host);
  602. if (omap_host->power_mode == power_mode)
  603. return;
  604. if (power_mode != MMC_POWER_ON)
  605. return;
  606. disable_irq(host->irq);
  607. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_CON);
  608. reg |= CON_INIT;
  609. sdhci_omap_writel(omap_host, SDHCI_OMAP_CON, reg);
  610. sdhci_omap_writel(omap_host, SDHCI_OMAP_CMD, 0x0);
  611. /* wait 1ms */
  612. timeout = ktime_add_ms(ktime_get(), SDHCI_OMAP_TIMEOUT);
  613. while (1) {
  614. bool timedout = ktime_after(ktime_get(), timeout);
  615. if (sdhci_omap_readl(omap_host, SDHCI_OMAP_STAT) & INT_CC_EN)
  616. break;
  617. if (WARN_ON(timedout))
  618. return;
  619. usleep_range(5, 10);
  620. }
  621. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_CON);
  622. reg &= ~CON_INIT;
  623. sdhci_omap_writel(omap_host, SDHCI_OMAP_CON, reg);
  624. sdhci_omap_writel(omap_host, SDHCI_OMAP_STAT, INT_CC_EN);
  625. enable_irq(host->irq);
  626. }
  627. static void sdhci_omap_set_uhs_signaling(struct sdhci_host *host,
  628. unsigned int timing)
  629. {
  630. u32 reg;
  631. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  632. struct sdhci_omap_host *omap_host = sdhci_pltfm_priv(pltfm_host);
  633. sdhci_omap_stop_clock(omap_host);
  634. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_CON);
  635. if (timing == MMC_TIMING_UHS_DDR50 || timing == MMC_TIMING_MMC_DDR52)
  636. reg |= CON_DDR;
  637. else
  638. reg &= ~CON_DDR;
  639. sdhci_omap_writel(omap_host, SDHCI_OMAP_CON, reg);
  640. sdhci_set_uhs_signaling(host, timing);
  641. sdhci_omap_start_clock(omap_host);
  642. }
  643. void sdhci_omap_reset(struct sdhci_host *host, u8 mask)
  644. {
  645. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  646. struct sdhci_omap_host *omap_host = sdhci_pltfm_priv(pltfm_host);
  647. /* Don't reset data lines during tuning operation */
  648. if (omap_host->is_tuning)
  649. mask &= ~SDHCI_RESET_DATA;
  650. sdhci_reset(host, mask);
  651. }
  652. #define CMD_ERR_MASK (SDHCI_INT_CRC | SDHCI_INT_END_BIT | SDHCI_INT_INDEX |\
  653. SDHCI_INT_TIMEOUT)
  654. #define CMD_MASK (CMD_ERR_MASK | SDHCI_INT_RESPONSE)
  655. static u32 sdhci_omap_irq(struct sdhci_host *host, u32 intmask)
  656. {
  657. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  658. struct sdhci_omap_host *omap_host = sdhci_pltfm_priv(pltfm_host);
  659. if (omap_host->is_tuning && host->cmd && !host->data_early &&
  660. (intmask & CMD_ERR_MASK)) {
  661. /*
  662. * Since we are not resetting data lines during tuning
  663. * operation, data error or data complete interrupts
  664. * might still arrive. Mark this request as a failure
  665. * but still wait for the data interrupt
  666. */
  667. if (intmask & SDHCI_INT_TIMEOUT)
  668. host->cmd->error = -ETIMEDOUT;
  669. else
  670. host->cmd->error = -EILSEQ;
  671. host->cmd = NULL;
  672. /*
  673. * Sometimes command error interrupts and command complete
  674. * interrupt will arrive together. Clear all command related
  675. * interrupts here.
  676. */
  677. sdhci_writel(host, intmask & CMD_MASK, SDHCI_INT_STATUS);
  678. intmask &= ~CMD_MASK;
  679. }
  680. return intmask;
  681. }
  682. static struct sdhci_ops sdhci_omap_ops = {
  683. .set_clock = sdhci_omap_set_clock,
  684. .set_power = sdhci_omap_set_power,
  685. .enable_dma = sdhci_omap_enable_dma,
  686. .get_max_clock = sdhci_pltfm_clk_get_max_clock,
  687. .get_min_clock = sdhci_omap_get_min_clock,
  688. .set_bus_width = sdhci_omap_set_bus_width,
  689. .platform_send_init_74_clocks = sdhci_omap_init_74_clocks,
  690. .reset = sdhci_omap_reset,
  691. .set_uhs_signaling = sdhci_omap_set_uhs_signaling,
  692. .irq = sdhci_omap_irq,
  693. };
  694. static int sdhci_omap_set_capabilities(struct sdhci_omap_host *omap_host)
  695. {
  696. u32 reg;
  697. int ret = 0;
  698. struct device *dev = omap_host->dev;
  699. struct regulator *vqmmc;
  700. vqmmc = regulator_get(dev, "vqmmc");
  701. if (IS_ERR(vqmmc)) {
  702. ret = PTR_ERR(vqmmc);
  703. goto reg_put;
  704. }
  705. /* voltage capabilities might be set by boot loader, clear it */
  706. reg = sdhci_omap_readl(omap_host, SDHCI_OMAP_CAPA);
  707. reg &= ~(CAPA_VS18 | CAPA_VS30 | CAPA_VS33);
  708. if (regulator_is_supported_voltage(vqmmc, IOV_3V3, IOV_3V3))
  709. reg |= CAPA_VS33;
  710. if (regulator_is_supported_voltage(vqmmc, IOV_1V8, IOV_1V8))
  711. reg |= CAPA_VS18;
  712. sdhci_omap_writel(omap_host, SDHCI_OMAP_CAPA, reg);
  713. reg_put:
  714. regulator_put(vqmmc);
  715. return ret;
  716. }
  717. static const struct sdhci_pltfm_data sdhci_omap_pdata = {
  718. .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
  719. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  720. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN |
  721. SDHCI_QUIRK_NO_HISPD_BIT |
  722. SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC,
  723. .quirks2 = SDHCI_QUIRK2_ACMD23_BROKEN |
  724. SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
  725. SDHCI_QUIRK2_RSP_136_HAS_CRC |
  726. SDHCI_QUIRK2_DISABLE_HW_TIMEOUT,
  727. .ops = &sdhci_omap_ops,
  728. };
  729. static const struct sdhci_omap_data k2g_data = {
  730. .offset = 0x200,
  731. };
  732. static const struct sdhci_omap_data dra7_data = {
  733. .offset = 0x200,
  734. .flags = SDHCI_OMAP_REQUIRE_IODELAY,
  735. };
  736. static const struct of_device_id omap_sdhci_match[] = {
  737. { .compatible = "ti,dra7-sdhci", .data = &dra7_data },
  738. { .compatible = "ti,k2g-sdhci", .data = &k2g_data },
  739. {},
  740. };
  741. MODULE_DEVICE_TABLE(of, omap_sdhci_match);
  742. static struct pinctrl_state
  743. *sdhci_omap_iodelay_pinctrl_state(struct sdhci_omap_host *omap_host, char *mode,
  744. u32 *caps, u32 capmask)
  745. {
  746. struct device *dev = omap_host->dev;
  747. char *version = omap_host->version;
  748. struct pinctrl_state *pinctrl_state = ERR_PTR(-ENODEV);
  749. char str[20];
  750. if (!(*caps & capmask))
  751. goto ret;
  752. if (version) {
  753. snprintf(str, 20, "%s-%s", mode, version);
  754. pinctrl_state = pinctrl_lookup_state(omap_host->pinctrl, str);
  755. }
  756. if (IS_ERR(pinctrl_state))
  757. pinctrl_state = pinctrl_lookup_state(omap_host->pinctrl, mode);
  758. if (IS_ERR(pinctrl_state)) {
  759. dev_err(dev, "no pinctrl state for %s mode", mode);
  760. *caps &= ~capmask;
  761. }
  762. ret:
  763. return pinctrl_state;
  764. }
  765. static int sdhci_omap_config_iodelay_pinctrl_state(struct sdhci_omap_host
  766. *omap_host)
  767. {
  768. struct device *dev = omap_host->dev;
  769. struct sdhci_host *host = omap_host->host;
  770. struct mmc_host *mmc = host->mmc;
  771. u32 *caps = &mmc->caps;
  772. u32 *caps2 = &mmc->caps2;
  773. struct pinctrl_state *state;
  774. struct pinctrl_state **pinctrl_state;
  775. if (!(omap_host->flags & SDHCI_OMAP_REQUIRE_IODELAY))
  776. return 0;
  777. pinctrl_state = devm_kcalloc(dev,
  778. MMC_TIMING_MMC_HS200 + 1,
  779. sizeof(*pinctrl_state),
  780. GFP_KERNEL);
  781. if (!pinctrl_state)
  782. return -ENOMEM;
  783. omap_host->pinctrl = devm_pinctrl_get(omap_host->dev);
  784. if (IS_ERR(omap_host->pinctrl)) {
  785. dev_err(dev, "Cannot get pinctrl\n");
  786. return PTR_ERR(omap_host->pinctrl);
  787. }
  788. state = pinctrl_lookup_state(omap_host->pinctrl, "default");
  789. if (IS_ERR(state)) {
  790. dev_err(dev, "no pinctrl state for default mode\n");
  791. return PTR_ERR(state);
  792. }
  793. pinctrl_state[MMC_TIMING_LEGACY] = state;
  794. state = sdhci_omap_iodelay_pinctrl_state(omap_host, "sdr104", caps,
  795. MMC_CAP_UHS_SDR104);
  796. if (!IS_ERR(state))
  797. pinctrl_state[MMC_TIMING_UHS_SDR104] = state;
  798. state = sdhci_omap_iodelay_pinctrl_state(omap_host, "ddr50", caps,
  799. MMC_CAP_UHS_DDR50);
  800. if (!IS_ERR(state))
  801. pinctrl_state[MMC_TIMING_UHS_DDR50] = state;
  802. state = sdhci_omap_iodelay_pinctrl_state(omap_host, "sdr50", caps,
  803. MMC_CAP_UHS_SDR50);
  804. if (!IS_ERR(state))
  805. pinctrl_state[MMC_TIMING_UHS_SDR50] = state;
  806. state = sdhci_omap_iodelay_pinctrl_state(omap_host, "sdr25", caps,
  807. MMC_CAP_UHS_SDR25);
  808. if (!IS_ERR(state))
  809. pinctrl_state[MMC_TIMING_UHS_SDR25] = state;
  810. state = sdhci_omap_iodelay_pinctrl_state(omap_host, "sdr12", caps,
  811. MMC_CAP_UHS_SDR12);
  812. if (!IS_ERR(state))
  813. pinctrl_state[MMC_TIMING_UHS_SDR12] = state;
  814. state = sdhci_omap_iodelay_pinctrl_state(omap_host, "ddr_1_8v", caps,
  815. MMC_CAP_1_8V_DDR);
  816. if (!IS_ERR(state)) {
  817. pinctrl_state[MMC_TIMING_MMC_DDR52] = state;
  818. } else {
  819. state = sdhci_omap_iodelay_pinctrl_state(omap_host, "ddr_3_3v",
  820. caps,
  821. MMC_CAP_3_3V_DDR);
  822. if (!IS_ERR(state))
  823. pinctrl_state[MMC_TIMING_MMC_DDR52] = state;
  824. }
  825. state = sdhci_omap_iodelay_pinctrl_state(omap_host, "hs", caps,
  826. MMC_CAP_SD_HIGHSPEED);
  827. if (!IS_ERR(state))
  828. pinctrl_state[MMC_TIMING_SD_HS] = state;
  829. state = sdhci_omap_iodelay_pinctrl_state(omap_host, "hs", caps,
  830. MMC_CAP_MMC_HIGHSPEED);
  831. if (!IS_ERR(state))
  832. pinctrl_state[MMC_TIMING_MMC_HS] = state;
  833. state = sdhci_omap_iodelay_pinctrl_state(omap_host, "hs200_1_8v", caps2,
  834. MMC_CAP2_HS200_1_8V_SDR);
  835. if (!IS_ERR(state))
  836. pinctrl_state[MMC_TIMING_MMC_HS200] = state;
  837. omap_host->pinctrl_state = pinctrl_state;
  838. return 0;
  839. }
  840. static const struct soc_device_attribute sdhci_omap_soc_devices[] = {
  841. {
  842. .machine = "DRA7[45]*",
  843. .revision = "ES1.[01]",
  844. },
  845. {
  846. /* sentinel */
  847. }
  848. };
  849. static int sdhci_omap_probe(struct platform_device *pdev)
  850. {
  851. int ret;
  852. u32 offset;
  853. struct device *dev = &pdev->dev;
  854. struct sdhci_host *host;
  855. struct sdhci_pltfm_host *pltfm_host;
  856. struct sdhci_omap_host *omap_host;
  857. struct mmc_host *mmc;
  858. const struct of_device_id *match;
  859. struct sdhci_omap_data *data;
  860. const struct soc_device_attribute *soc;
  861. match = of_match_device(omap_sdhci_match, dev);
  862. if (!match)
  863. return -EINVAL;
  864. data = (struct sdhci_omap_data *)match->data;
  865. if (!data) {
  866. dev_err(dev, "no sdhci omap data\n");
  867. return -EINVAL;
  868. }
  869. offset = data->offset;
  870. host = sdhci_pltfm_init(pdev, &sdhci_omap_pdata,
  871. sizeof(*omap_host));
  872. if (IS_ERR(host)) {
  873. dev_err(dev, "Failed sdhci_pltfm_init\n");
  874. return PTR_ERR(host);
  875. }
  876. pltfm_host = sdhci_priv(host);
  877. omap_host = sdhci_pltfm_priv(pltfm_host);
  878. omap_host->host = host;
  879. omap_host->base = host->ioaddr;
  880. omap_host->dev = dev;
  881. omap_host->power_mode = MMC_POWER_UNDEFINED;
  882. omap_host->timing = MMC_TIMING_LEGACY;
  883. omap_host->flags = data->flags;
  884. host->ioaddr += offset;
  885. mmc = host->mmc;
  886. sdhci_get_of_property(pdev);
  887. ret = mmc_of_parse(mmc);
  888. if (ret)
  889. goto err_pltfm_free;
  890. soc = soc_device_match(sdhci_omap_soc_devices);
  891. if (soc) {
  892. omap_host->version = "rev11";
  893. if (!strcmp(dev_name(dev), "4809c000.mmc"))
  894. mmc->f_max = 96000000;
  895. if (!strcmp(dev_name(dev), "480b4000.mmc"))
  896. mmc->f_max = 48000000;
  897. if (!strcmp(dev_name(dev), "480ad000.mmc"))
  898. mmc->f_max = 48000000;
  899. }
  900. pltfm_host->clk = devm_clk_get(dev, "fck");
  901. if (IS_ERR(pltfm_host->clk)) {
  902. ret = PTR_ERR(pltfm_host->clk);
  903. goto err_pltfm_free;
  904. }
  905. ret = clk_set_rate(pltfm_host->clk, mmc->f_max);
  906. if (ret) {
  907. dev_err(dev, "failed to set clock to %d\n", mmc->f_max);
  908. goto err_pltfm_free;
  909. }
  910. omap_host->pbias = devm_regulator_get_optional(dev, "pbias");
  911. if (IS_ERR(omap_host->pbias)) {
  912. ret = PTR_ERR(omap_host->pbias);
  913. if (ret != -ENODEV)
  914. goto err_pltfm_free;
  915. dev_dbg(dev, "unable to get pbias regulator %d\n", ret);
  916. }
  917. omap_host->pbias_enabled = false;
  918. /*
  919. * omap_device_pm_domain has callbacks to enable the main
  920. * functional clock, interface clock and also configure the
  921. * SYSCONFIG register of omap devices. The callback will be invoked
  922. * as part of pm_runtime_get_sync.
  923. */
  924. pm_runtime_enable(dev);
  925. ret = pm_runtime_get_sync(dev);
  926. if (ret < 0) {
  927. dev_err(dev, "pm_runtime_get_sync failed\n");
  928. pm_runtime_put_noidle(dev);
  929. goto err_rpm_disable;
  930. }
  931. ret = sdhci_omap_set_capabilities(omap_host);
  932. if (ret) {
  933. dev_err(dev, "failed to set system capabilities\n");
  934. goto err_put_sync;
  935. }
  936. host->mmc_host_ops.get_ro = mmc_gpio_get_ro;
  937. host->mmc_host_ops.start_signal_voltage_switch =
  938. sdhci_omap_start_signal_voltage_switch;
  939. host->mmc_host_ops.set_ios = sdhci_omap_set_ios;
  940. host->mmc_host_ops.card_busy = sdhci_omap_card_busy;
  941. host->mmc_host_ops.execute_tuning = sdhci_omap_execute_tuning;
  942. host->mmc_host_ops.enable_sdio_irq = sdhci_omap_enable_sdio_irq;
  943. /* R1B responses is required to properly manage HW busy detection. */
  944. mmc->caps |= MMC_CAP_NEED_RSP_BUSY;
  945. ret = sdhci_setup_host(host);
  946. if (ret)
  947. goto err_put_sync;
  948. ret = sdhci_omap_config_iodelay_pinctrl_state(omap_host);
  949. if (ret)
  950. goto err_cleanup_host;
  951. ret = __sdhci_add_host(host);
  952. if (ret)
  953. goto err_cleanup_host;
  954. return 0;
  955. err_cleanup_host:
  956. sdhci_cleanup_host(host);
  957. err_put_sync:
  958. pm_runtime_put_sync(dev);
  959. err_rpm_disable:
  960. pm_runtime_disable(dev);
  961. err_pltfm_free:
  962. sdhci_pltfm_free(pdev);
  963. return ret;
  964. }
  965. static int sdhci_omap_remove(struct platform_device *pdev)
  966. {
  967. struct device *dev = &pdev->dev;
  968. struct sdhci_host *host = platform_get_drvdata(pdev);
  969. sdhci_remove_host(host, true);
  970. pm_runtime_put_sync(dev);
  971. pm_runtime_disable(dev);
  972. sdhci_pltfm_free(pdev);
  973. return 0;
  974. }
  975. static struct platform_driver sdhci_omap_driver = {
  976. .probe = sdhci_omap_probe,
  977. .remove = sdhci_omap_remove,
  978. .driver = {
  979. .name = "sdhci-omap",
  980. .of_match_table = omap_sdhci_match,
  981. },
  982. };
  983. module_platform_driver(sdhci_omap_driver);
  984. MODULE_DESCRIPTION("SDHCI driver for OMAP SoCs");
  985. MODULE_AUTHOR("Texas Instruments Inc.");
  986. MODULE_LICENSE("GPL v2");
  987. MODULE_ALIAS("platform:sdhci_omap");