sdhci-tegra.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. /*
  2. * Copyright (C) 2010 Google, Inc.
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/err.h>
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/clk.h>
  20. #include <linux/io.h>
  21. #include <linux/of.h>
  22. #include <linux/of_device.h>
  23. #include <linux/reset.h>
  24. #include <linux/mmc/card.h>
  25. #include <linux/mmc/host.h>
  26. #include <linux/mmc/mmc.h>
  27. #include <linux/mmc/slot-gpio.h>
  28. #include <linux/gpio/consumer.h>
  29. #include "sdhci-pltfm.h"
  30. /* Tegra SDHOST controller vendor register definitions */
  31. #define SDHCI_TEGRA_VENDOR_CLOCK_CTRL 0x100
  32. #define SDHCI_CLOCK_CTRL_TAP_MASK 0x00ff0000
  33. #define SDHCI_CLOCK_CTRL_TAP_SHIFT 16
  34. #define SDHCI_CLOCK_CTRL_SDR50_TUNING_OVERRIDE BIT(5)
  35. #define SDHCI_CLOCK_CTRL_PADPIPE_CLKEN_OVERRIDE BIT(3)
  36. #define SDHCI_CLOCK_CTRL_SPI_MODE_CLKEN_OVERRIDE BIT(2)
  37. #define SDHCI_TEGRA_VENDOR_MISC_CTRL 0x120
  38. #define SDHCI_MISC_CTRL_ENABLE_SDR104 0x8
  39. #define SDHCI_MISC_CTRL_ENABLE_SDR50 0x10
  40. #define SDHCI_MISC_CTRL_ENABLE_SDHCI_SPEC_300 0x20
  41. #define SDHCI_MISC_CTRL_ENABLE_DDR50 0x200
  42. #define SDHCI_TEGRA_AUTO_CAL_CONFIG 0x1e4
  43. #define SDHCI_AUTO_CAL_START BIT(31)
  44. #define SDHCI_AUTO_CAL_ENABLE BIT(29)
  45. #define NVQUIRK_FORCE_SDHCI_SPEC_200 BIT(0)
  46. #define NVQUIRK_ENABLE_BLOCK_GAP_DET BIT(1)
  47. #define NVQUIRK_ENABLE_SDHCI_SPEC_300 BIT(2)
  48. #define NVQUIRK_ENABLE_SDR50 BIT(3)
  49. #define NVQUIRK_ENABLE_SDR104 BIT(4)
  50. #define NVQUIRK_ENABLE_DDR50 BIT(5)
  51. #define NVQUIRK_HAS_PADCALIB BIT(6)
  52. struct sdhci_tegra_soc_data {
  53. const struct sdhci_pltfm_data *pdata;
  54. u32 nvquirks;
  55. };
  56. struct sdhci_tegra {
  57. const struct sdhci_tegra_soc_data *soc_data;
  58. struct gpio_desc *power_gpio;
  59. bool ddr_signaling;
  60. bool pad_calib_required;
  61. struct reset_control *rst;
  62. };
  63. static u16 tegra_sdhci_readw(struct sdhci_host *host, int reg)
  64. {
  65. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  66. struct sdhci_tegra *tegra_host = sdhci_pltfm_priv(pltfm_host);
  67. const struct sdhci_tegra_soc_data *soc_data = tegra_host->soc_data;
  68. if (unlikely((soc_data->nvquirks & NVQUIRK_FORCE_SDHCI_SPEC_200) &&
  69. (reg == SDHCI_HOST_VERSION))) {
  70. /* Erratum: Version register is invalid in HW. */
  71. return SDHCI_SPEC_200;
  72. }
  73. return readw(host->ioaddr + reg);
  74. }
  75. static void tegra_sdhci_writew(struct sdhci_host *host, u16 val, int reg)
  76. {
  77. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  78. switch (reg) {
  79. case SDHCI_TRANSFER_MODE:
  80. /*
  81. * Postpone this write, we must do it together with a
  82. * command write that is down below.
  83. */
  84. pltfm_host->xfer_mode_shadow = val;
  85. return;
  86. case SDHCI_COMMAND:
  87. writel((val << 16) | pltfm_host->xfer_mode_shadow,
  88. host->ioaddr + SDHCI_TRANSFER_MODE);
  89. return;
  90. }
  91. writew(val, host->ioaddr + reg);
  92. }
  93. static void tegra_sdhci_writel(struct sdhci_host *host, u32 val, int reg)
  94. {
  95. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  96. struct sdhci_tegra *tegra_host = sdhci_pltfm_priv(pltfm_host);
  97. const struct sdhci_tegra_soc_data *soc_data = tegra_host->soc_data;
  98. /* Seems like we're getting spurious timeout and crc errors, so
  99. * disable signalling of them. In case of real errors software
  100. * timers should take care of eventually detecting them.
  101. */
  102. if (unlikely(reg == SDHCI_SIGNAL_ENABLE))
  103. val &= ~(SDHCI_INT_TIMEOUT|SDHCI_INT_CRC);
  104. writel(val, host->ioaddr + reg);
  105. if (unlikely((soc_data->nvquirks & NVQUIRK_ENABLE_BLOCK_GAP_DET) &&
  106. (reg == SDHCI_INT_ENABLE))) {
  107. /* Erratum: Must enable block gap interrupt detection */
  108. u8 gap_ctrl = readb(host->ioaddr + SDHCI_BLOCK_GAP_CONTROL);
  109. if (val & SDHCI_INT_CARD_INT)
  110. gap_ctrl |= 0x8;
  111. else
  112. gap_ctrl &= ~0x8;
  113. writeb(gap_ctrl, host->ioaddr + SDHCI_BLOCK_GAP_CONTROL);
  114. }
  115. }
  116. static unsigned int tegra_sdhci_get_ro(struct sdhci_host *host)
  117. {
  118. return mmc_gpio_get_ro(host->mmc);
  119. }
  120. static void tegra_sdhci_reset(struct sdhci_host *host, u8 mask)
  121. {
  122. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  123. struct sdhci_tegra *tegra_host = sdhci_pltfm_priv(pltfm_host);
  124. const struct sdhci_tegra_soc_data *soc_data = tegra_host->soc_data;
  125. u32 misc_ctrl, clk_ctrl;
  126. sdhci_reset(host, mask);
  127. if (!(mask & SDHCI_RESET_ALL))
  128. return;
  129. misc_ctrl = sdhci_readl(host, SDHCI_TEGRA_VENDOR_MISC_CTRL);
  130. clk_ctrl = sdhci_readl(host, SDHCI_TEGRA_VENDOR_CLOCK_CTRL);
  131. misc_ctrl &= ~(SDHCI_MISC_CTRL_ENABLE_SDHCI_SPEC_300 |
  132. SDHCI_MISC_CTRL_ENABLE_SDR50 |
  133. SDHCI_MISC_CTRL_ENABLE_DDR50 |
  134. SDHCI_MISC_CTRL_ENABLE_SDR104);
  135. clk_ctrl &= ~SDHCI_CLOCK_CTRL_SPI_MODE_CLKEN_OVERRIDE;
  136. /*
  137. * If the board does not define a regulator for the SDHCI
  138. * IO voltage, then don't advertise support for UHS modes
  139. * even if the device supports it because the IO voltage
  140. * cannot be configured.
  141. */
  142. if (!IS_ERR(host->mmc->supply.vqmmc)) {
  143. /* Erratum: Enable SDHCI spec v3.00 support */
  144. if (soc_data->nvquirks & NVQUIRK_ENABLE_SDHCI_SPEC_300)
  145. misc_ctrl |= SDHCI_MISC_CTRL_ENABLE_SDHCI_SPEC_300;
  146. /* Advertise UHS modes as supported by host */
  147. if (soc_data->nvquirks & NVQUIRK_ENABLE_SDR50)
  148. misc_ctrl |= SDHCI_MISC_CTRL_ENABLE_SDR50;
  149. if (soc_data->nvquirks & NVQUIRK_ENABLE_DDR50)
  150. misc_ctrl |= SDHCI_MISC_CTRL_ENABLE_DDR50;
  151. if (soc_data->nvquirks & NVQUIRK_ENABLE_SDR104)
  152. misc_ctrl |= SDHCI_MISC_CTRL_ENABLE_SDR104;
  153. if (soc_data->nvquirks & SDHCI_MISC_CTRL_ENABLE_SDR50)
  154. clk_ctrl |= SDHCI_CLOCK_CTRL_SDR50_TUNING_OVERRIDE;
  155. }
  156. sdhci_writel(host, misc_ctrl, SDHCI_TEGRA_VENDOR_MISC_CTRL);
  157. sdhci_writel(host, clk_ctrl, SDHCI_TEGRA_VENDOR_CLOCK_CTRL);
  158. if (soc_data->nvquirks & NVQUIRK_HAS_PADCALIB)
  159. tegra_host->pad_calib_required = true;
  160. tegra_host->ddr_signaling = false;
  161. }
  162. static void tegra_sdhci_pad_autocalib(struct sdhci_host *host)
  163. {
  164. u32 val;
  165. mdelay(1);
  166. val = sdhci_readl(host, SDHCI_TEGRA_AUTO_CAL_CONFIG);
  167. val |= SDHCI_AUTO_CAL_ENABLE | SDHCI_AUTO_CAL_START;
  168. sdhci_writel(host,val, SDHCI_TEGRA_AUTO_CAL_CONFIG);
  169. }
  170. static void tegra_sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
  171. {
  172. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  173. struct sdhci_tegra *tegra_host = sdhci_pltfm_priv(pltfm_host);
  174. unsigned long host_clk;
  175. if (!clock)
  176. return sdhci_set_clock(host, clock);
  177. host_clk = tegra_host->ddr_signaling ? clock * 2 : clock;
  178. clk_set_rate(pltfm_host->clk, host_clk);
  179. host->max_clk = clk_get_rate(pltfm_host->clk);
  180. sdhci_set_clock(host, clock);
  181. if (tegra_host->pad_calib_required) {
  182. tegra_sdhci_pad_autocalib(host);
  183. tegra_host->pad_calib_required = false;
  184. }
  185. }
  186. static void tegra_sdhci_set_uhs_signaling(struct sdhci_host *host,
  187. unsigned timing)
  188. {
  189. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  190. struct sdhci_tegra *tegra_host = sdhci_pltfm_priv(pltfm_host);
  191. if (timing == MMC_TIMING_UHS_DDR50)
  192. tegra_host->ddr_signaling = true;
  193. return sdhci_set_uhs_signaling(host, timing);
  194. }
  195. static unsigned int tegra_sdhci_get_max_clock(struct sdhci_host *host)
  196. {
  197. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  198. /*
  199. * DDR modes require the host to run at double the card frequency, so
  200. * the maximum rate we can support is half of the module input clock.
  201. */
  202. return clk_round_rate(pltfm_host->clk, UINT_MAX) / 2;
  203. }
  204. static void tegra_sdhci_set_tap(struct sdhci_host *host, unsigned int tap)
  205. {
  206. u32 reg;
  207. reg = sdhci_readl(host, SDHCI_TEGRA_VENDOR_CLOCK_CTRL);
  208. reg &= ~SDHCI_CLOCK_CTRL_TAP_MASK;
  209. reg |= tap << SDHCI_CLOCK_CTRL_TAP_SHIFT;
  210. sdhci_writel(host, reg, SDHCI_TEGRA_VENDOR_CLOCK_CTRL);
  211. }
  212. static int tegra_sdhci_execute_tuning(struct sdhci_host *host, u32 opcode)
  213. {
  214. unsigned int min, max;
  215. /*
  216. * Start search for minimum tap value at 10, as smaller values are
  217. * may wrongly be reported as working but fail at higher speeds,
  218. * according to the TRM.
  219. */
  220. min = 10;
  221. while (min < 255) {
  222. tegra_sdhci_set_tap(host, min);
  223. if (!mmc_send_tuning(host->mmc, opcode, NULL))
  224. break;
  225. min++;
  226. }
  227. /* Find the maximum tap value that still passes. */
  228. max = min + 1;
  229. while (max < 255) {
  230. tegra_sdhci_set_tap(host, max);
  231. if (mmc_send_tuning(host->mmc, opcode, NULL)) {
  232. max--;
  233. break;
  234. }
  235. max++;
  236. }
  237. /* The TRM states the ideal tap value is at 75% in the passing range. */
  238. tegra_sdhci_set_tap(host, min + ((max - min) * 3 / 4));
  239. return mmc_send_tuning(host->mmc, opcode, NULL);
  240. }
  241. static void tegra_sdhci_voltage_switch(struct sdhci_host *host)
  242. {
  243. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  244. struct sdhci_tegra *tegra_host = sdhci_pltfm_priv(pltfm_host);
  245. const struct sdhci_tegra_soc_data *soc_data = tegra_host->soc_data;
  246. if (soc_data->nvquirks & NVQUIRK_HAS_PADCALIB)
  247. tegra_host->pad_calib_required = true;
  248. }
  249. static const struct sdhci_ops tegra_sdhci_ops = {
  250. .get_ro = tegra_sdhci_get_ro,
  251. .read_w = tegra_sdhci_readw,
  252. .write_l = tegra_sdhci_writel,
  253. .set_clock = tegra_sdhci_set_clock,
  254. .set_bus_width = sdhci_set_bus_width,
  255. .reset = tegra_sdhci_reset,
  256. .platform_execute_tuning = tegra_sdhci_execute_tuning,
  257. .set_uhs_signaling = tegra_sdhci_set_uhs_signaling,
  258. .voltage_switch = tegra_sdhci_voltage_switch,
  259. .get_max_clock = tegra_sdhci_get_max_clock,
  260. };
  261. static const struct sdhci_pltfm_data sdhci_tegra20_pdata = {
  262. .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  263. SDHCI_QUIRK_SINGLE_POWER_WRITE |
  264. SDHCI_QUIRK_NO_HISPD_BIT |
  265. SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
  266. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
  267. .ops = &tegra_sdhci_ops,
  268. };
  269. static const struct sdhci_tegra_soc_data soc_data_tegra20 = {
  270. .pdata = &sdhci_tegra20_pdata,
  271. .nvquirks = NVQUIRK_FORCE_SDHCI_SPEC_200 |
  272. NVQUIRK_ENABLE_BLOCK_GAP_DET,
  273. };
  274. static const struct sdhci_pltfm_data sdhci_tegra30_pdata = {
  275. .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  276. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  277. SDHCI_QUIRK_SINGLE_POWER_WRITE |
  278. SDHCI_QUIRK_NO_HISPD_BIT |
  279. SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
  280. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
  281. .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
  282. .ops = &tegra_sdhci_ops,
  283. };
  284. static const struct sdhci_tegra_soc_data soc_data_tegra30 = {
  285. .pdata = &sdhci_tegra30_pdata,
  286. .nvquirks = NVQUIRK_ENABLE_SDHCI_SPEC_300 |
  287. NVQUIRK_ENABLE_SDR50 |
  288. NVQUIRK_ENABLE_SDR104 |
  289. NVQUIRK_HAS_PADCALIB,
  290. };
  291. static const struct sdhci_ops tegra114_sdhci_ops = {
  292. .get_ro = tegra_sdhci_get_ro,
  293. .read_w = tegra_sdhci_readw,
  294. .write_w = tegra_sdhci_writew,
  295. .write_l = tegra_sdhci_writel,
  296. .set_clock = tegra_sdhci_set_clock,
  297. .set_bus_width = sdhci_set_bus_width,
  298. .reset = tegra_sdhci_reset,
  299. .platform_execute_tuning = tegra_sdhci_execute_tuning,
  300. .set_uhs_signaling = tegra_sdhci_set_uhs_signaling,
  301. .voltage_switch = tegra_sdhci_voltage_switch,
  302. .get_max_clock = tegra_sdhci_get_max_clock,
  303. };
  304. static const struct sdhci_pltfm_data sdhci_tegra114_pdata = {
  305. .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  306. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  307. SDHCI_QUIRK_SINGLE_POWER_WRITE |
  308. SDHCI_QUIRK_NO_HISPD_BIT |
  309. SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
  310. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
  311. .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
  312. .ops = &tegra114_sdhci_ops,
  313. };
  314. static const struct sdhci_tegra_soc_data soc_data_tegra114 = {
  315. .pdata = &sdhci_tegra114_pdata,
  316. };
  317. static const struct sdhci_pltfm_data sdhci_tegra124_pdata = {
  318. .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  319. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  320. SDHCI_QUIRK_SINGLE_POWER_WRITE |
  321. SDHCI_QUIRK_NO_HISPD_BIT |
  322. SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
  323. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
  324. .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
  325. /*
  326. * The TRM states that the SD/MMC controller found on
  327. * Tegra124 can address 34 bits (the maximum supported by
  328. * the Tegra memory controller), but tests show that DMA
  329. * to or from above 4 GiB doesn't work. This is possibly
  330. * caused by missing programming, though it's not obvious
  331. * what sequence is required. Mark 64-bit DMA broken for
  332. * now to fix this for existing users (e.g. Nyan boards).
  333. */
  334. SDHCI_QUIRK2_BROKEN_64_BIT_DMA,
  335. .ops = &tegra114_sdhci_ops,
  336. };
  337. static const struct sdhci_tegra_soc_data soc_data_tegra124 = {
  338. .pdata = &sdhci_tegra124_pdata,
  339. };
  340. static const struct sdhci_pltfm_data sdhci_tegra210_pdata = {
  341. .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  342. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  343. SDHCI_QUIRK_SINGLE_POWER_WRITE |
  344. SDHCI_QUIRK_NO_HISPD_BIT |
  345. SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
  346. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
  347. .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
  348. .ops = &tegra114_sdhci_ops,
  349. };
  350. static const struct sdhci_tegra_soc_data soc_data_tegra210 = {
  351. .pdata = &sdhci_tegra210_pdata,
  352. };
  353. static const struct sdhci_pltfm_data sdhci_tegra186_pdata = {
  354. .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  355. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  356. SDHCI_QUIRK_SINGLE_POWER_WRITE |
  357. SDHCI_QUIRK_NO_HISPD_BIT |
  358. SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
  359. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
  360. .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
  361. .ops = &tegra114_sdhci_ops,
  362. };
  363. static const struct sdhci_tegra_soc_data soc_data_tegra186 = {
  364. .pdata = &sdhci_tegra186_pdata,
  365. };
  366. static const struct of_device_id sdhci_tegra_dt_match[] = {
  367. { .compatible = "nvidia,tegra186-sdhci", .data = &soc_data_tegra186 },
  368. { .compatible = "nvidia,tegra210-sdhci", .data = &soc_data_tegra210 },
  369. { .compatible = "nvidia,tegra124-sdhci", .data = &soc_data_tegra124 },
  370. { .compatible = "nvidia,tegra114-sdhci", .data = &soc_data_tegra114 },
  371. { .compatible = "nvidia,tegra30-sdhci", .data = &soc_data_tegra30 },
  372. { .compatible = "nvidia,tegra20-sdhci", .data = &soc_data_tegra20 },
  373. {}
  374. };
  375. MODULE_DEVICE_TABLE(of, sdhci_tegra_dt_match);
  376. static int sdhci_tegra_probe(struct platform_device *pdev)
  377. {
  378. const struct of_device_id *match;
  379. const struct sdhci_tegra_soc_data *soc_data;
  380. struct sdhci_host *host;
  381. struct sdhci_pltfm_host *pltfm_host;
  382. struct sdhci_tegra *tegra_host;
  383. struct clk *clk;
  384. int rc;
  385. match = of_match_device(sdhci_tegra_dt_match, &pdev->dev);
  386. if (!match)
  387. return -EINVAL;
  388. soc_data = match->data;
  389. host = sdhci_pltfm_init(pdev, soc_data->pdata, sizeof(*tegra_host));
  390. if (IS_ERR(host))
  391. return PTR_ERR(host);
  392. pltfm_host = sdhci_priv(host);
  393. tegra_host = sdhci_pltfm_priv(pltfm_host);
  394. tegra_host->ddr_signaling = false;
  395. tegra_host->pad_calib_required = false;
  396. tegra_host->soc_data = soc_data;
  397. rc = mmc_of_parse(host->mmc);
  398. if (rc)
  399. goto err_parse_dt;
  400. if (tegra_host->soc_data->nvquirks & NVQUIRK_ENABLE_DDR50)
  401. host->mmc->caps |= MMC_CAP_1_8V_DDR;
  402. tegra_host->power_gpio = devm_gpiod_get_optional(&pdev->dev, "power",
  403. GPIOD_OUT_HIGH);
  404. if (IS_ERR(tegra_host->power_gpio)) {
  405. rc = PTR_ERR(tegra_host->power_gpio);
  406. goto err_power_req;
  407. }
  408. clk = devm_clk_get(mmc_dev(host->mmc), NULL);
  409. if (IS_ERR(clk)) {
  410. dev_err(mmc_dev(host->mmc), "clk err\n");
  411. rc = PTR_ERR(clk);
  412. goto err_clk_get;
  413. }
  414. clk_prepare_enable(clk);
  415. pltfm_host->clk = clk;
  416. tegra_host->rst = devm_reset_control_get_exclusive(&pdev->dev,
  417. "sdhci");
  418. if (IS_ERR(tegra_host->rst)) {
  419. rc = PTR_ERR(tegra_host->rst);
  420. dev_err(&pdev->dev, "failed to get reset control: %d\n", rc);
  421. goto err_rst_get;
  422. }
  423. rc = reset_control_assert(tegra_host->rst);
  424. if (rc)
  425. goto err_rst_get;
  426. usleep_range(2000, 4000);
  427. rc = reset_control_deassert(tegra_host->rst);
  428. if (rc)
  429. goto err_rst_get;
  430. usleep_range(2000, 4000);
  431. rc = sdhci_add_host(host);
  432. if (rc)
  433. goto err_add_host;
  434. return 0;
  435. err_add_host:
  436. reset_control_assert(tegra_host->rst);
  437. err_rst_get:
  438. clk_disable_unprepare(pltfm_host->clk);
  439. err_clk_get:
  440. err_power_req:
  441. err_parse_dt:
  442. sdhci_pltfm_free(pdev);
  443. return rc;
  444. }
  445. static int sdhci_tegra_remove(struct platform_device *pdev)
  446. {
  447. struct sdhci_host *host = platform_get_drvdata(pdev);
  448. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  449. struct sdhci_tegra *tegra_host = sdhci_pltfm_priv(pltfm_host);
  450. sdhci_remove_host(host, 0);
  451. reset_control_assert(tegra_host->rst);
  452. usleep_range(2000, 4000);
  453. clk_disable_unprepare(pltfm_host->clk);
  454. sdhci_pltfm_free(pdev);
  455. return 0;
  456. }
  457. static struct platform_driver sdhci_tegra_driver = {
  458. .driver = {
  459. .name = "sdhci-tegra",
  460. .of_match_table = sdhci_tegra_dt_match,
  461. .pm = &sdhci_pltfm_pmops,
  462. },
  463. .probe = sdhci_tegra_probe,
  464. .remove = sdhci_tegra_remove,
  465. };
  466. module_platform_driver(sdhci_tegra_driver);
  467. MODULE_DESCRIPTION("SDHCI driver for Tegra");
  468. MODULE_AUTHOR("Google, Inc.");
  469. MODULE_LICENSE("GPL v2");