sdhci-msm.c 16 KB

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