sdhci-tegra.c 15 KB

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