sdhci-msm.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. /*
  2. * drivers/mmc/host/sdhci-msm.c - Qualcomm SDHCI Platform driver
  3. *
  4. * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <linux/module.h>
  17. #include <linux/of_device.h>
  18. #include <linux/delay.h>
  19. #include <linux/mmc/mmc.h>
  20. #include <linux/slab.h>
  21. #include "sdhci-pltfm.h"
  22. #define CORE_MCI_VERSION 0x50
  23. #define CORE_VERSION_MAJOR_SHIFT 28
  24. #define CORE_VERSION_MAJOR_MASK (0xf << CORE_VERSION_MAJOR_SHIFT)
  25. #define CORE_VERSION_MINOR_MASK 0xff
  26. #define CORE_HC_MODE 0x78
  27. #define HC_MODE_EN 0x1
  28. #define CORE_POWER 0x0
  29. #define CORE_SW_RST BIT(7)
  30. #define MAX_PHASES 16
  31. #define CORE_DLL_LOCK BIT(7)
  32. #define CORE_DLL_EN BIT(16)
  33. #define CORE_CDR_EN BIT(17)
  34. #define CORE_CK_OUT_EN BIT(18)
  35. #define CORE_CDR_EXT_EN BIT(19)
  36. #define CORE_DLL_PDN BIT(29)
  37. #define CORE_DLL_RST BIT(30)
  38. #define CORE_DLL_CONFIG 0x100
  39. #define CORE_DLL_STATUS 0x108
  40. #define CORE_VENDOR_SPEC 0x10c
  41. #define CORE_CLK_PWRSAVE BIT(1)
  42. #define CORE_VENDOR_SPEC_CAPABILITIES0 0x11c
  43. #define CDR_SELEXT_SHIFT 20
  44. #define CDR_SELEXT_MASK (0xf << CDR_SELEXT_SHIFT)
  45. #define CMUX_SHIFT_PHASE_SHIFT 24
  46. #define CMUX_SHIFT_PHASE_MASK (7 << CMUX_SHIFT_PHASE_SHIFT)
  47. struct sdhci_msm_host {
  48. struct platform_device *pdev;
  49. void __iomem *core_mem; /* MSM SDCC mapped address */
  50. struct clk *clk; /* main SD/MMC bus clock */
  51. struct clk *pclk; /* SDHC peripheral bus clock */
  52. struct clk *bus_clk; /* SDHC bus voter clock */
  53. struct mmc_host *mmc;
  54. struct sdhci_pltfm_data sdhci_msm_pdata;
  55. };
  56. /* Platform specific tuning */
  57. static inline int msm_dll_poll_ck_out_en(struct sdhci_host *host, u8 poll)
  58. {
  59. u32 wait_cnt = 50;
  60. u8 ck_out_en;
  61. struct mmc_host *mmc = host->mmc;
  62. /* Poll for CK_OUT_EN bit. max. poll time = 50us */
  63. ck_out_en = !!(readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) &
  64. CORE_CK_OUT_EN);
  65. while (ck_out_en != poll) {
  66. if (--wait_cnt == 0) {
  67. dev_err(mmc_dev(mmc), "%s: CK_OUT_EN bit is not %d\n",
  68. mmc_hostname(mmc), poll);
  69. return -ETIMEDOUT;
  70. }
  71. udelay(1);
  72. ck_out_en = !!(readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) &
  73. CORE_CK_OUT_EN);
  74. }
  75. return 0;
  76. }
  77. static int msm_config_cm_dll_phase(struct sdhci_host *host, u8 phase)
  78. {
  79. int rc;
  80. static const u8 grey_coded_phase_table[] = {
  81. 0x0, 0x1, 0x3, 0x2, 0x6, 0x7, 0x5, 0x4,
  82. 0xc, 0xd, 0xf, 0xe, 0xa, 0xb, 0x9, 0x8
  83. };
  84. unsigned long flags;
  85. u32 config;
  86. struct mmc_host *mmc = host->mmc;
  87. spin_lock_irqsave(&host->lock, flags);
  88. config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
  89. config &= ~(CORE_CDR_EN | CORE_CK_OUT_EN);
  90. config |= (CORE_CDR_EXT_EN | CORE_DLL_EN);
  91. writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
  92. /* Wait until CK_OUT_EN bit of DLL_CONFIG register becomes '0' */
  93. rc = msm_dll_poll_ck_out_en(host, 0);
  94. if (rc)
  95. goto err_out;
  96. /*
  97. * Write the selected DLL clock output phase (0 ... 15)
  98. * to CDR_SELEXT bit field of DLL_CONFIG register.
  99. */
  100. config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
  101. config &= ~CDR_SELEXT_MASK;
  102. config |= grey_coded_phase_table[phase] << CDR_SELEXT_SHIFT;
  103. writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
  104. /* Set CK_OUT_EN bit of DLL_CONFIG register to 1. */
  105. writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG)
  106. | CORE_CK_OUT_EN), host->ioaddr + CORE_DLL_CONFIG);
  107. /* Wait until CK_OUT_EN bit of DLL_CONFIG register becomes '1' */
  108. rc = msm_dll_poll_ck_out_en(host, 1);
  109. if (rc)
  110. goto err_out;
  111. config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
  112. config |= CORE_CDR_EN;
  113. config &= ~CORE_CDR_EXT_EN;
  114. writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
  115. goto out;
  116. err_out:
  117. dev_err(mmc_dev(mmc), "%s: Failed to set DLL phase: %d\n",
  118. mmc_hostname(mmc), phase);
  119. out:
  120. spin_unlock_irqrestore(&host->lock, flags);
  121. return rc;
  122. }
  123. /*
  124. * Find out the greatest range of consecuitive selected
  125. * DLL clock output phases that can be used as sampling
  126. * setting for SD3.0 UHS-I card read operation (in SDR104
  127. * timing mode) or for eMMC4.5 card read operation (in HS200
  128. * timing mode).
  129. * Select the 3/4 of the range and configure the DLL with the
  130. * selected DLL clock output phase.
  131. */
  132. static int msm_find_most_appropriate_phase(struct sdhci_host *host,
  133. u8 *phase_table, u8 total_phases)
  134. {
  135. int ret;
  136. u8 ranges[MAX_PHASES][MAX_PHASES] = { {0}, {0} };
  137. u8 phases_per_row[MAX_PHASES] = { 0 };
  138. int row_index = 0, col_index = 0, selected_row_index = 0, curr_max = 0;
  139. int i, cnt, phase_0_raw_index = 0, phase_15_raw_index = 0;
  140. bool phase_0_found = false, phase_15_found = false;
  141. struct mmc_host *mmc = host->mmc;
  142. if (!total_phases || (total_phases > MAX_PHASES)) {
  143. dev_err(mmc_dev(mmc), "%s: Invalid argument: total_phases=%d\n",
  144. mmc_hostname(mmc), total_phases);
  145. return -EINVAL;
  146. }
  147. for (cnt = 0; cnt < total_phases; cnt++) {
  148. ranges[row_index][col_index] = phase_table[cnt];
  149. phases_per_row[row_index] += 1;
  150. col_index++;
  151. if ((cnt + 1) == total_phases) {
  152. continue;
  153. /* check if next phase in phase_table is consecutive or not */
  154. } else if ((phase_table[cnt] + 1) != phase_table[cnt + 1]) {
  155. row_index++;
  156. col_index = 0;
  157. }
  158. }
  159. if (row_index >= MAX_PHASES)
  160. return -EINVAL;
  161. /* Check if phase-0 is present in first valid window? */
  162. if (!ranges[0][0]) {
  163. phase_0_found = true;
  164. phase_0_raw_index = 0;
  165. /* Check if cycle exist between 2 valid windows */
  166. for (cnt = 1; cnt <= row_index; cnt++) {
  167. if (phases_per_row[cnt]) {
  168. for (i = 0; i < phases_per_row[cnt]; i++) {
  169. if (ranges[cnt][i] == 15) {
  170. phase_15_found = true;
  171. phase_15_raw_index = cnt;
  172. break;
  173. }
  174. }
  175. }
  176. }
  177. }
  178. /* If 2 valid windows form cycle then merge them as single window */
  179. if (phase_0_found && phase_15_found) {
  180. /* number of phases in raw where phase 0 is present */
  181. u8 phases_0 = phases_per_row[phase_0_raw_index];
  182. /* number of phases in raw where phase 15 is present */
  183. u8 phases_15 = phases_per_row[phase_15_raw_index];
  184. if (phases_0 + phases_15 >= MAX_PHASES)
  185. /*
  186. * If there are more than 1 phase windows then total
  187. * number of phases in both the windows should not be
  188. * more than or equal to MAX_PHASES.
  189. */
  190. return -EINVAL;
  191. /* Merge 2 cyclic windows */
  192. i = phases_15;
  193. for (cnt = 0; cnt < phases_0; cnt++) {
  194. ranges[phase_15_raw_index][i] =
  195. ranges[phase_0_raw_index][cnt];
  196. if (++i >= MAX_PHASES)
  197. break;
  198. }
  199. phases_per_row[phase_0_raw_index] = 0;
  200. phases_per_row[phase_15_raw_index] = phases_15 + phases_0;
  201. }
  202. for (cnt = 0; cnt <= row_index; cnt++) {
  203. if (phases_per_row[cnt] > curr_max) {
  204. curr_max = phases_per_row[cnt];
  205. selected_row_index = cnt;
  206. }
  207. }
  208. i = (curr_max * 3) / 4;
  209. if (i)
  210. i--;
  211. ret = ranges[selected_row_index][i];
  212. if (ret >= MAX_PHASES) {
  213. ret = -EINVAL;
  214. dev_err(mmc_dev(mmc), "%s: Invalid phase selected=%d\n",
  215. mmc_hostname(mmc), ret);
  216. }
  217. return ret;
  218. }
  219. static inline void msm_cm_dll_set_freq(struct sdhci_host *host)
  220. {
  221. u32 mclk_freq = 0, config;
  222. /* Program the MCLK value to MCLK_FREQ bit field */
  223. if (host->clock <= 112000000)
  224. mclk_freq = 0;
  225. else if (host->clock <= 125000000)
  226. mclk_freq = 1;
  227. else if (host->clock <= 137000000)
  228. mclk_freq = 2;
  229. else if (host->clock <= 150000000)
  230. mclk_freq = 3;
  231. else if (host->clock <= 162000000)
  232. mclk_freq = 4;
  233. else if (host->clock <= 175000000)
  234. mclk_freq = 5;
  235. else if (host->clock <= 187000000)
  236. mclk_freq = 6;
  237. else if (host->clock <= 200000000)
  238. mclk_freq = 7;
  239. config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
  240. config &= ~CMUX_SHIFT_PHASE_MASK;
  241. config |= mclk_freq << CMUX_SHIFT_PHASE_SHIFT;
  242. writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
  243. }
  244. /* Initialize the DLL (Programmable Delay Line) */
  245. static int msm_init_cm_dll(struct sdhci_host *host)
  246. {
  247. struct mmc_host *mmc = host->mmc;
  248. int wait_cnt = 50;
  249. unsigned long flags;
  250. spin_lock_irqsave(&host->lock, flags);
  251. /*
  252. * Make sure that clock is always enabled when DLL
  253. * tuning is in progress. Keeping PWRSAVE ON may
  254. * turn off the clock.
  255. */
  256. writel_relaxed((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC)
  257. & ~CORE_CLK_PWRSAVE), host->ioaddr + CORE_VENDOR_SPEC);
  258. /* Write 1 to DLL_RST bit of DLL_CONFIG register */
  259. writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG)
  260. | CORE_DLL_RST), host->ioaddr + CORE_DLL_CONFIG);
  261. /* Write 1 to DLL_PDN bit of DLL_CONFIG register */
  262. writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG)
  263. | CORE_DLL_PDN), host->ioaddr + CORE_DLL_CONFIG);
  264. msm_cm_dll_set_freq(host);
  265. /* Write 0 to DLL_RST bit of DLL_CONFIG register */
  266. writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG)
  267. & ~CORE_DLL_RST), host->ioaddr + CORE_DLL_CONFIG);
  268. /* Write 0 to DLL_PDN bit of DLL_CONFIG register */
  269. writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG)
  270. & ~CORE_DLL_PDN), host->ioaddr + CORE_DLL_CONFIG);
  271. /* Set DLL_EN bit to 1. */
  272. writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG)
  273. | CORE_DLL_EN), host->ioaddr + CORE_DLL_CONFIG);
  274. /* Set CK_OUT_EN bit to 1. */
  275. writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG)
  276. | CORE_CK_OUT_EN), host->ioaddr + CORE_DLL_CONFIG);
  277. /* Wait until DLL_LOCK bit of DLL_STATUS register becomes '1' */
  278. while (!(readl_relaxed(host->ioaddr + CORE_DLL_STATUS) &
  279. CORE_DLL_LOCK)) {
  280. /* max. wait for 50us sec for LOCK bit to be set */
  281. if (--wait_cnt == 0) {
  282. dev_err(mmc_dev(mmc), "%s: DLL failed to LOCK\n",
  283. mmc_hostname(mmc));
  284. spin_unlock_irqrestore(&host->lock, flags);
  285. return -ETIMEDOUT;
  286. }
  287. udelay(1);
  288. }
  289. spin_unlock_irqrestore(&host->lock, flags);
  290. return 0;
  291. }
  292. static int sdhci_msm_execute_tuning(struct sdhci_host *host, u32 opcode)
  293. {
  294. int tuning_seq_cnt = 3;
  295. u8 phase, tuned_phases[16], tuned_phase_cnt = 0;
  296. int rc;
  297. struct mmc_host *mmc = host->mmc;
  298. struct mmc_ios ios = host->mmc->ios;
  299. /*
  300. * Tuning is required for SDR104, HS200 and HS400 cards and
  301. * if clock frequency is greater than 100MHz in these modes.
  302. */
  303. if (host->clock <= 100 * 1000 * 1000 ||
  304. !((ios.timing == MMC_TIMING_MMC_HS200) ||
  305. (ios.timing == MMC_TIMING_UHS_SDR104)))
  306. return 0;
  307. retry:
  308. /* First of all reset the tuning block */
  309. rc = msm_init_cm_dll(host);
  310. if (rc)
  311. return rc;
  312. phase = 0;
  313. do {
  314. /* Set the phase in delay line hw block */
  315. rc = msm_config_cm_dll_phase(host, phase);
  316. if (rc)
  317. return rc;
  318. rc = mmc_send_tuning(mmc);
  319. if (!rc) {
  320. /* Tuning is successful at this tuning point */
  321. tuned_phases[tuned_phase_cnt++] = phase;
  322. dev_dbg(mmc_dev(mmc), "%s: Found good phase = %d\n",
  323. mmc_hostname(mmc), phase);
  324. }
  325. } while (++phase < ARRAY_SIZE(tuned_phases));
  326. if (tuned_phase_cnt) {
  327. rc = msm_find_most_appropriate_phase(host, tuned_phases,
  328. tuned_phase_cnt);
  329. if (rc < 0)
  330. return rc;
  331. else
  332. phase = rc;
  333. /*
  334. * Finally set the selected phase in delay
  335. * line hw block.
  336. */
  337. rc = msm_config_cm_dll_phase(host, phase);
  338. if (rc)
  339. return rc;
  340. dev_dbg(mmc_dev(mmc), "%s: Setting the tuning phase to %d\n",
  341. mmc_hostname(mmc), phase);
  342. } else {
  343. if (--tuning_seq_cnt)
  344. goto retry;
  345. /* Tuning failed */
  346. dev_dbg(mmc_dev(mmc), "%s: No tuning point found\n",
  347. mmc_hostname(mmc));
  348. rc = -EIO;
  349. }
  350. return rc;
  351. }
  352. static const struct of_device_id sdhci_msm_dt_match[] = {
  353. { .compatible = "qcom,sdhci-msm-v4" },
  354. {},
  355. };
  356. MODULE_DEVICE_TABLE(of, sdhci_msm_dt_match);
  357. static struct sdhci_ops sdhci_msm_ops = {
  358. .platform_execute_tuning = sdhci_msm_execute_tuning,
  359. .reset = sdhci_reset,
  360. .set_clock = sdhci_set_clock,
  361. .set_bus_width = sdhci_set_bus_width,
  362. .set_uhs_signaling = sdhci_set_uhs_signaling,
  363. };
  364. static int sdhci_msm_probe(struct platform_device *pdev)
  365. {
  366. struct sdhci_host *host;
  367. struct sdhci_pltfm_host *pltfm_host;
  368. struct sdhci_msm_host *msm_host;
  369. struct resource *core_memres;
  370. int ret;
  371. u16 host_version, core_minor;
  372. u32 core_version, caps;
  373. u8 core_major;
  374. msm_host = devm_kzalloc(&pdev->dev, sizeof(*msm_host), GFP_KERNEL);
  375. if (!msm_host)
  376. return -ENOMEM;
  377. msm_host->sdhci_msm_pdata.ops = &sdhci_msm_ops;
  378. host = sdhci_pltfm_init(pdev, &msm_host->sdhci_msm_pdata, 0);
  379. if (IS_ERR(host))
  380. return PTR_ERR(host);
  381. pltfm_host = sdhci_priv(host);
  382. pltfm_host->priv = msm_host;
  383. msm_host->mmc = host->mmc;
  384. msm_host->pdev = pdev;
  385. ret = mmc_of_parse(host->mmc);
  386. if (ret)
  387. goto pltfm_free;
  388. sdhci_get_of_property(pdev);
  389. /* Setup SDCC bus voter clock. */
  390. msm_host->bus_clk = devm_clk_get(&pdev->dev, "bus");
  391. if (!IS_ERR(msm_host->bus_clk)) {
  392. /* Vote for max. clk rate for max. performance */
  393. ret = clk_set_rate(msm_host->bus_clk, INT_MAX);
  394. if (ret)
  395. goto pltfm_free;
  396. ret = clk_prepare_enable(msm_host->bus_clk);
  397. if (ret)
  398. goto pltfm_free;
  399. }
  400. /* Setup main peripheral bus clock */
  401. msm_host->pclk = devm_clk_get(&pdev->dev, "iface");
  402. if (IS_ERR(msm_host->pclk)) {
  403. ret = PTR_ERR(msm_host->pclk);
  404. dev_err(&pdev->dev, "Perpheral clk setup failed (%d)\n", ret);
  405. goto bus_clk_disable;
  406. }
  407. ret = clk_prepare_enable(msm_host->pclk);
  408. if (ret)
  409. goto bus_clk_disable;
  410. /* Setup SDC MMC clock */
  411. msm_host->clk = devm_clk_get(&pdev->dev, "core");
  412. if (IS_ERR(msm_host->clk)) {
  413. ret = PTR_ERR(msm_host->clk);
  414. dev_err(&pdev->dev, "SDC MMC clk setup failed (%d)\n", ret);
  415. goto pclk_disable;
  416. }
  417. /* Vote for maximum clock rate for maximum performance */
  418. ret = clk_set_rate(msm_host->clk, INT_MAX);
  419. if (ret)
  420. dev_warn(&pdev->dev, "core clock boost failed\n");
  421. ret = clk_prepare_enable(msm_host->clk);
  422. if (ret)
  423. goto pclk_disable;
  424. core_memres = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  425. msm_host->core_mem = devm_ioremap_resource(&pdev->dev, core_memres);
  426. if (IS_ERR(msm_host->core_mem)) {
  427. dev_err(&pdev->dev, "Failed to remap registers\n");
  428. ret = PTR_ERR(msm_host->core_mem);
  429. goto clk_disable;
  430. }
  431. /* Reset the core and Enable SDHC mode */
  432. writel_relaxed(readl_relaxed(msm_host->core_mem + CORE_POWER) |
  433. CORE_SW_RST, msm_host->core_mem + CORE_POWER);
  434. /* SW reset can take upto 10HCLK + 15MCLK cycles. (min 40us) */
  435. usleep_range(1000, 5000);
  436. if (readl(msm_host->core_mem + CORE_POWER) & CORE_SW_RST) {
  437. dev_err(&pdev->dev, "Stuck in reset\n");
  438. ret = -ETIMEDOUT;
  439. goto clk_disable;
  440. }
  441. /* Set HC_MODE_EN bit in HC_MODE register */
  442. writel_relaxed(HC_MODE_EN, (msm_host->core_mem + CORE_HC_MODE));
  443. host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
  444. host->quirks |= SDHCI_QUIRK_SINGLE_POWER_WRITE;
  445. host_version = readw_relaxed((host->ioaddr + SDHCI_HOST_VERSION));
  446. dev_dbg(&pdev->dev, "Host Version: 0x%x Vendor Version 0x%x\n",
  447. host_version, ((host_version & SDHCI_VENDOR_VER_MASK) >>
  448. SDHCI_VENDOR_VER_SHIFT));
  449. core_version = readl_relaxed(msm_host->core_mem + CORE_MCI_VERSION);
  450. core_major = (core_version & CORE_VERSION_MAJOR_MASK) >>
  451. CORE_VERSION_MAJOR_SHIFT;
  452. core_minor = core_version & CORE_VERSION_MINOR_MASK;
  453. dev_dbg(&pdev->dev, "MCI Version: 0x%08x, major: 0x%04x, minor: 0x%02x\n",
  454. core_version, core_major, core_minor);
  455. /*
  456. * Support for some capabilities is not advertised by newer
  457. * controller versions and must be explicitly enabled.
  458. */
  459. if (core_major >= 1 && core_minor != 0x11 && core_minor != 0x12) {
  460. caps = readl_relaxed(host->ioaddr + SDHCI_CAPABILITIES);
  461. caps |= SDHCI_CAN_VDD_300 | SDHCI_CAN_DO_8BIT;
  462. writel_relaxed(caps, host->ioaddr +
  463. CORE_VENDOR_SPEC_CAPABILITIES0);
  464. }
  465. ret = sdhci_add_host(host);
  466. if (ret)
  467. goto clk_disable;
  468. return 0;
  469. clk_disable:
  470. clk_disable_unprepare(msm_host->clk);
  471. pclk_disable:
  472. clk_disable_unprepare(msm_host->pclk);
  473. bus_clk_disable:
  474. if (!IS_ERR(msm_host->bus_clk))
  475. clk_disable_unprepare(msm_host->bus_clk);
  476. pltfm_free:
  477. sdhci_pltfm_free(pdev);
  478. return ret;
  479. }
  480. static int sdhci_msm_remove(struct platform_device *pdev)
  481. {
  482. struct sdhci_host *host = platform_get_drvdata(pdev);
  483. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  484. struct sdhci_msm_host *msm_host = pltfm_host->priv;
  485. int dead = (readl_relaxed(host->ioaddr + SDHCI_INT_STATUS) ==
  486. 0xffffffff);
  487. sdhci_remove_host(host, dead);
  488. sdhci_pltfm_free(pdev);
  489. clk_disable_unprepare(msm_host->clk);
  490. clk_disable_unprepare(msm_host->pclk);
  491. if (!IS_ERR(msm_host->bus_clk))
  492. clk_disable_unprepare(msm_host->bus_clk);
  493. return 0;
  494. }
  495. static struct platform_driver sdhci_msm_driver = {
  496. .probe = sdhci_msm_probe,
  497. .remove = sdhci_msm_remove,
  498. .driver = {
  499. .name = "sdhci_msm",
  500. .of_match_table = sdhci_msm_dt_match,
  501. },
  502. };
  503. module_platform_driver(sdhci_msm_driver);
  504. MODULE_DESCRIPTION("Qualcomm Secure Digital Host Controller Interface driver");
  505. MODULE_LICENSE("GPL v2");