sdhci-tegra.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  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_set_bus_width(struct sdhci_host *host, int bus_width)
  163. {
  164. u32 ctrl;
  165. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  166. if ((host->mmc->caps & MMC_CAP_8_BIT_DATA) &&
  167. (bus_width == MMC_BUS_WIDTH_8)) {
  168. ctrl &= ~SDHCI_CTRL_4BITBUS;
  169. ctrl |= SDHCI_CTRL_8BITBUS;
  170. } else {
  171. ctrl &= ~SDHCI_CTRL_8BITBUS;
  172. if (bus_width == MMC_BUS_WIDTH_4)
  173. ctrl |= SDHCI_CTRL_4BITBUS;
  174. else
  175. ctrl &= ~SDHCI_CTRL_4BITBUS;
  176. }
  177. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  178. }
  179. static void tegra_sdhci_pad_autocalib(struct sdhci_host *host)
  180. {
  181. u32 val;
  182. mdelay(1);
  183. val = sdhci_readl(host, SDHCI_TEGRA_AUTO_CAL_CONFIG);
  184. val |= SDHCI_AUTO_CAL_ENABLE | SDHCI_AUTO_CAL_START;
  185. sdhci_writel(host,val, SDHCI_TEGRA_AUTO_CAL_CONFIG);
  186. }
  187. static void tegra_sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
  188. {
  189. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  190. struct sdhci_tegra *tegra_host = sdhci_pltfm_priv(pltfm_host);
  191. unsigned long host_clk;
  192. if (!clock)
  193. return sdhci_set_clock(host, clock);
  194. host_clk = tegra_host->ddr_signaling ? clock * 2 : clock;
  195. clk_set_rate(pltfm_host->clk, host_clk);
  196. host->max_clk = clk_get_rate(pltfm_host->clk);
  197. sdhci_set_clock(host, clock);
  198. if (tegra_host->pad_calib_required) {
  199. tegra_sdhci_pad_autocalib(host);
  200. tegra_host->pad_calib_required = false;
  201. }
  202. }
  203. static void tegra_sdhci_set_uhs_signaling(struct sdhci_host *host,
  204. unsigned timing)
  205. {
  206. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  207. struct sdhci_tegra *tegra_host = sdhci_pltfm_priv(pltfm_host);
  208. if (timing == MMC_TIMING_UHS_DDR50)
  209. tegra_host->ddr_signaling = true;
  210. return sdhci_set_uhs_signaling(host, timing);
  211. }
  212. static unsigned int tegra_sdhci_get_max_clock(struct sdhci_host *host)
  213. {
  214. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  215. /*
  216. * DDR modes require the host to run at double the card frequency, so
  217. * the maximum rate we can support is half of the module input clock.
  218. */
  219. return clk_round_rate(pltfm_host->clk, UINT_MAX) / 2;
  220. }
  221. static void tegra_sdhci_set_tap(struct sdhci_host *host, unsigned int tap)
  222. {
  223. u32 reg;
  224. reg = sdhci_readl(host, SDHCI_TEGRA_VENDOR_CLOCK_CTRL);
  225. reg &= ~SDHCI_CLOCK_CTRL_TAP_MASK;
  226. reg |= tap << SDHCI_CLOCK_CTRL_TAP_SHIFT;
  227. sdhci_writel(host, reg, SDHCI_TEGRA_VENDOR_CLOCK_CTRL);
  228. }
  229. static int tegra_sdhci_execute_tuning(struct sdhci_host *host, u32 opcode)
  230. {
  231. unsigned int min, max;
  232. /*
  233. * Start search for minimum tap value at 10, as smaller values are
  234. * may wrongly be reported as working but fail at higher speeds,
  235. * according to the TRM.
  236. */
  237. min = 10;
  238. while (min < 255) {
  239. tegra_sdhci_set_tap(host, min);
  240. if (!mmc_send_tuning(host->mmc, opcode, NULL))
  241. break;
  242. min++;
  243. }
  244. /* Find the maximum tap value that still passes. */
  245. max = min + 1;
  246. while (max < 255) {
  247. tegra_sdhci_set_tap(host, max);
  248. if (mmc_send_tuning(host->mmc, opcode, NULL)) {
  249. max--;
  250. break;
  251. }
  252. max++;
  253. }
  254. /* The TRM states the ideal tap value is at 75% in the passing range. */
  255. tegra_sdhci_set_tap(host, min + ((max - min) * 3 / 4));
  256. return mmc_send_tuning(host->mmc, opcode, NULL);
  257. }
  258. static void tegra_sdhci_voltage_switch(struct sdhci_host *host)
  259. {
  260. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  261. struct sdhci_tegra *tegra_host = sdhci_pltfm_priv(pltfm_host);
  262. const struct sdhci_tegra_soc_data *soc_data = tegra_host->soc_data;
  263. if (soc_data->nvquirks & NVQUIRK_HAS_PADCALIB)
  264. tegra_host->pad_calib_required = true;
  265. }
  266. static const struct sdhci_ops tegra_sdhci_ops = {
  267. .get_ro = tegra_sdhci_get_ro,
  268. .read_w = tegra_sdhci_readw,
  269. .write_l = tegra_sdhci_writel,
  270. .set_clock = tegra_sdhci_set_clock,
  271. .set_bus_width = tegra_sdhci_set_bus_width,
  272. .reset = tegra_sdhci_reset,
  273. .platform_execute_tuning = tegra_sdhci_execute_tuning,
  274. .set_uhs_signaling = tegra_sdhci_set_uhs_signaling,
  275. .voltage_switch = tegra_sdhci_voltage_switch,
  276. .get_max_clock = tegra_sdhci_get_max_clock,
  277. };
  278. static const struct sdhci_pltfm_data sdhci_tegra20_pdata = {
  279. .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  280. SDHCI_QUIRK_SINGLE_POWER_WRITE |
  281. SDHCI_QUIRK_NO_HISPD_BIT |
  282. SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
  283. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
  284. .ops = &tegra_sdhci_ops,
  285. };
  286. static const struct sdhci_tegra_soc_data soc_data_tegra20 = {
  287. .pdata = &sdhci_tegra20_pdata,
  288. .nvquirks = NVQUIRK_FORCE_SDHCI_SPEC_200 |
  289. NVQUIRK_ENABLE_BLOCK_GAP_DET,
  290. };
  291. static const struct sdhci_pltfm_data sdhci_tegra30_pdata = {
  292. .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  293. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  294. SDHCI_QUIRK_SINGLE_POWER_WRITE |
  295. SDHCI_QUIRK_NO_HISPD_BIT |
  296. SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
  297. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
  298. .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
  299. .ops = &tegra_sdhci_ops,
  300. };
  301. static const struct sdhci_tegra_soc_data soc_data_tegra30 = {
  302. .pdata = &sdhci_tegra30_pdata,
  303. .nvquirks = NVQUIRK_ENABLE_SDHCI_SPEC_300 |
  304. NVQUIRK_ENABLE_SDR50 |
  305. NVQUIRK_ENABLE_SDR104 |
  306. NVQUIRK_HAS_PADCALIB,
  307. };
  308. static const struct sdhci_ops tegra114_sdhci_ops = {
  309. .get_ro = tegra_sdhci_get_ro,
  310. .read_w = tegra_sdhci_readw,
  311. .write_w = tegra_sdhci_writew,
  312. .write_l = tegra_sdhci_writel,
  313. .set_clock = tegra_sdhci_set_clock,
  314. .set_bus_width = tegra_sdhci_set_bus_width,
  315. .reset = tegra_sdhci_reset,
  316. .platform_execute_tuning = tegra_sdhci_execute_tuning,
  317. .set_uhs_signaling = tegra_sdhci_set_uhs_signaling,
  318. .voltage_switch = tegra_sdhci_voltage_switch,
  319. .get_max_clock = tegra_sdhci_get_max_clock,
  320. };
  321. static const struct sdhci_pltfm_data sdhci_tegra114_pdata = {
  322. .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  323. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  324. SDHCI_QUIRK_SINGLE_POWER_WRITE |
  325. SDHCI_QUIRK_NO_HISPD_BIT |
  326. SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
  327. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
  328. .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
  329. .ops = &tegra114_sdhci_ops,
  330. };
  331. static const struct sdhci_tegra_soc_data soc_data_tegra114 = {
  332. .pdata = &sdhci_tegra114_pdata,
  333. };
  334. static const struct sdhci_pltfm_data sdhci_tegra124_pdata = {
  335. .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  336. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  337. SDHCI_QUIRK_SINGLE_POWER_WRITE |
  338. SDHCI_QUIRK_NO_HISPD_BIT |
  339. SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
  340. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
  341. .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
  342. /*
  343. * The TRM states that the SD/MMC controller found on
  344. * Tegra124 can address 34 bits (the maximum supported by
  345. * the Tegra memory controller), but tests show that DMA
  346. * to or from above 4 GiB doesn't work. This is possibly
  347. * caused by missing programming, though it's not obvious
  348. * what sequence is required. Mark 64-bit DMA broken for
  349. * now to fix this for existing users (e.g. Nyan boards).
  350. */
  351. SDHCI_QUIRK2_BROKEN_64_BIT_DMA,
  352. .ops = &tegra114_sdhci_ops,
  353. };
  354. static const struct sdhci_tegra_soc_data soc_data_tegra124 = {
  355. .pdata = &sdhci_tegra124_pdata,
  356. };
  357. static const struct sdhci_pltfm_data sdhci_tegra210_pdata = {
  358. .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  359. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  360. SDHCI_QUIRK_SINGLE_POWER_WRITE |
  361. SDHCI_QUIRK_NO_HISPD_BIT |
  362. SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
  363. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
  364. .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
  365. .ops = &tegra114_sdhci_ops,
  366. };
  367. static const struct sdhci_tegra_soc_data soc_data_tegra210 = {
  368. .pdata = &sdhci_tegra210_pdata,
  369. };
  370. static const struct sdhci_pltfm_data sdhci_tegra186_pdata = {
  371. .quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  372. SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  373. SDHCI_QUIRK_SINGLE_POWER_WRITE |
  374. SDHCI_QUIRK_NO_HISPD_BIT |
  375. SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
  376. SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
  377. .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
  378. .ops = &tegra114_sdhci_ops,
  379. };
  380. static const struct sdhci_tegra_soc_data soc_data_tegra186 = {
  381. .pdata = &sdhci_tegra186_pdata,
  382. };
  383. static const struct of_device_id sdhci_tegra_dt_match[] = {
  384. { .compatible = "nvidia,tegra186-sdhci", .data = &soc_data_tegra186 },
  385. { .compatible = "nvidia,tegra210-sdhci", .data = &soc_data_tegra210 },
  386. { .compatible = "nvidia,tegra124-sdhci", .data = &soc_data_tegra124 },
  387. { .compatible = "nvidia,tegra114-sdhci", .data = &soc_data_tegra114 },
  388. { .compatible = "nvidia,tegra30-sdhci", .data = &soc_data_tegra30 },
  389. { .compatible = "nvidia,tegra20-sdhci", .data = &soc_data_tegra20 },
  390. {}
  391. };
  392. MODULE_DEVICE_TABLE(of, sdhci_tegra_dt_match);
  393. static int sdhci_tegra_probe(struct platform_device *pdev)
  394. {
  395. const struct of_device_id *match;
  396. const struct sdhci_tegra_soc_data *soc_data;
  397. struct sdhci_host *host;
  398. struct sdhci_pltfm_host *pltfm_host;
  399. struct sdhci_tegra *tegra_host;
  400. struct clk *clk;
  401. int rc;
  402. match = of_match_device(sdhci_tegra_dt_match, &pdev->dev);
  403. if (!match)
  404. return -EINVAL;
  405. soc_data = match->data;
  406. host = sdhci_pltfm_init(pdev, soc_data->pdata, sizeof(*tegra_host));
  407. if (IS_ERR(host))
  408. return PTR_ERR(host);
  409. pltfm_host = sdhci_priv(host);
  410. tegra_host = sdhci_pltfm_priv(pltfm_host);
  411. tegra_host->ddr_signaling = false;
  412. tegra_host->pad_calib_required = false;
  413. tegra_host->soc_data = soc_data;
  414. rc = mmc_of_parse(host->mmc);
  415. if (rc)
  416. goto err_parse_dt;
  417. if (tegra_host->soc_data->nvquirks & NVQUIRK_ENABLE_DDR50)
  418. host->mmc->caps |= MMC_CAP_1_8V_DDR;
  419. tegra_host->power_gpio = devm_gpiod_get_optional(&pdev->dev, "power",
  420. GPIOD_OUT_HIGH);
  421. if (IS_ERR(tegra_host->power_gpio)) {
  422. rc = PTR_ERR(tegra_host->power_gpio);
  423. goto err_power_req;
  424. }
  425. clk = devm_clk_get(mmc_dev(host->mmc), NULL);
  426. if (IS_ERR(clk)) {
  427. dev_err(mmc_dev(host->mmc), "clk err\n");
  428. rc = PTR_ERR(clk);
  429. goto err_clk_get;
  430. }
  431. clk_prepare_enable(clk);
  432. pltfm_host->clk = clk;
  433. tegra_host->rst = devm_reset_control_get(&pdev->dev, "sdhci");
  434. if (IS_ERR(tegra_host->rst)) {
  435. rc = PTR_ERR(tegra_host->rst);
  436. dev_err(&pdev->dev, "failed to get reset control: %d\n", rc);
  437. goto err_rst_get;
  438. }
  439. rc = reset_control_assert(tegra_host->rst);
  440. if (rc)
  441. goto err_rst_get;
  442. usleep_range(2000, 4000);
  443. rc = reset_control_deassert(tegra_host->rst);
  444. if (rc)
  445. goto err_rst_get;
  446. usleep_range(2000, 4000);
  447. rc = sdhci_add_host(host);
  448. if (rc)
  449. goto err_add_host;
  450. return 0;
  451. err_add_host:
  452. reset_control_assert(tegra_host->rst);
  453. err_rst_get:
  454. clk_disable_unprepare(pltfm_host->clk);
  455. err_clk_get:
  456. err_power_req:
  457. err_parse_dt:
  458. sdhci_pltfm_free(pdev);
  459. return rc;
  460. }
  461. static int sdhci_tegra_remove(struct platform_device *pdev)
  462. {
  463. struct sdhci_host *host = platform_get_drvdata(pdev);
  464. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  465. struct sdhci_tegra *tegra_host = sdhci_pltfm_priv(pltfm_host);
  466. sdhci_remove_host(host, 0);
  467. reset_control_assert(tegra_host->rst);
  468. usleep_range(2000, 4000);
  469. clk_disable_unprepare(pltfm_host->clk);
  470. sdhci_pltfm_free(pdev);
  471. return 0;
  472. }
  473. static struct platform_driver sdhci_tegra_driver = {
  474. .driver = {
  475. .name = "sdhci-tegra",
  476. .of_match_table = sdhci_tegra_dt_match,
  477. .pm = &sdhci_pltfm_pmops,
  478. },
  479. .probe = sdhci_tegra_probe,
  480. .remove = sdhci_tegra_remove,
  481. };
  482. module_platform_driver(sdhci_tegra_driver);
  483. MODULE_DESCRIPTION("SDHCI driver for Tegra");
  484. MODULE_AUTHOR("Google, Inc.");
  485. MODULE_LICENSE("GPL v2");