sdhci-msm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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. };
  55. /* Platform specific tuning */
  56. static inline int msm_dll_poll_ck_out_en(struct sdhci_host *host, u8 poll)
  57. {
  58. u32 wait_cnt = 50;
  59. u8 ck_out_en;
  60. struct mmc_host *mmc = host->mmc;
  61. /* Poll for CK_OUT_EN bit. max. poll time = 50us */
  62. ck_out_en = !!(readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) &
  63. CORE_CK_OUT_EN);
  64. while (ck_out_en != poll) {
  65. if (--wait_cnt == 0) {
  66. dev_err(mmc_dev(mmc), "%s: CK_OUT_EN bit is not %d\n",
  67. mmc_hostname(mmc), poll);
  68. return -ETIMEDOUT;
  69. }
  70. udelay(1);
  71. ck_out_en = !!(readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) &
  72. CORE_CK_OUT_EN);
  73. }
  74. return 0;
  75. }
  76. static int msm_config_cm_dll_phase(struct sdhci_host *host, u8 phase)
  77. {
  78. int rc;
  79. static const u8 grey_coded_phase_table[] = {
  80. 0x0, 0x1, 0x3, 0x2, 0x6, 0x7, 0x5, 0x4,
  81. 0xc, 0xd, 0xf, 0xe, 0xa, 0xb, 0x9, 0x8
  82. };
  83. unsigned long flags;
  84. u32 config;
  85. struct mmc_host *mmc = host->mmc;
  86. spin_lock_irqsave(&host->lock, flags);
  87. config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
  88. config &= ~(CORE_CDR_EN | CORE_CK_OUT_EN);
  89. config |= (CORE_CDR_EXT_EN | CORE_DLL_EN);
  90. writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
  91. /* Wait until CK_OUT_EN bit of DLL_CONFIG register becomes '0' */
  92. rc = msm_dll_poll_ck_out_en(host, 0);
  93. if (rc)
  94. goto err_out;
  95. /*
  96. * Write the selected DLL clock output phase (0 ... 15)
  97. * to CDR_SELEXT bit field of DLL_CONFIG register.
  98. */
  99. config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
  100. config &= ~CDR_SELEXT_MASK;
  101. config |= grey_coded_phase_table[phase] << CDR_SELEXT_SHIFT;
  102. writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
  103. /* Set CK_OUT_EN bit of DLL_CONFIG register to 1. */
  104. writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG)
  105. | CORE_CK_OUT_EN), host->ioaddr + CORE_DLL_CONFIG);
  106. /* Wait until CK_OUT_EN bit of DLL_CONFIG register becomes '1' */
  107. rc = msm_dll_poll_ck_out_en(host, 1);
  108. if (rc)
  109. goto err_out;
  110. config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
  111. config |= CORE_CDR_EN;
  112. config &= ~CORE_CDR_EXT_EN;
  113. writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
  114. goto out;
  115. err_out:
  116. dev_err(mmc_dev(mmc), "%s: Failed to set DLL phase: %d\n",
  117. mmc_hostname(mmc), phase);
  118. out:
  119. spin_unlock_irqrestore(&host->lock, flags);
  120. return rc;
  121. }
  122. /*
  123. * Find out the greatest range of consecuitive selected
  124. * DLL clock output phases that can be used as sampling
  125. * setting for SD3.0 UHS-I card read operation (in SDR104
  126. * timing mode) or for eMMC4.5 card read operation (in HS200
  127. * timing mode).
  128. * Select the 3/4 of the range and configure the DLL with the
  129. * selected DLL clock output phase.
  130. */
  131. static int msm_find_most_appropriate_phase(struct sdhci_host *host,
  132. u8 *phase_table, u8 total_phases)
  133. {
  134. int ret;
  135. u8 ranges[MAX_PHASES][MAX_PHASES] = { {0}, {0} };
  136. u8 phases_per_row[MAX_PHASES] = { 0 };
  137. int row_index = 0, col_index = 0, selected_row_index = 0, curr_max = 0;
  138. int i, cnt, phase_0_raw_index = 0, phase_15_raw_index = 0;
  139. bool phase_0_found = false, phase_15_found = false;
  140. struct mmc_host *mmc = host->mmc;
  141. if (!total_phases || (total_phases > MAX_PHASES)) {
  142. dev_err(mmc_dev(mmc), "%s: Invalid argument: total_phases=%d\n",
  143. mmc_hostname(mmc), total_phases);
  144. return -EINVAL;
  145. }
  146. for (cnt = 0; cnt < total_phases; cnt++) {
  147. ranges[row_index][col_index] = phase_table[cnt];
  148. phases_per_row[row_index] += 1;
  149. col_index++;
  150. if ((cnt + 1) == total_phases) {
  151. continue;
  152. /* check if next phase in phase_table is consecutive or not */
  153. } else if ((phase_table[cnt] + 1) != phase_table[cnt + 1]) {
  154. row_index++;
  155. col_index = 0;
  156. }
  157. }
  158. if (row_index >= MAX_PHASES)
  159. return -EINVAL;
  160. /* Check if phase-0 is present in first valid window? */
  161. if (!ranges[0][0]) {
  162. phase_0_found = true;
  163. phase_0_raw_index = 0;
  164. /* Check if cycle exist between 2 valid windows */
  165. for (cnt = 1; cnt <= row_index; cnt++) {
  166. if (phases_per_row[cnt]) {
  167. for (i = 0; i < phases_per_row[cnt]; i++) {
  168. if (ranges[cnt][i] == 15) {
  169. phase_15_found = true;
  170. phase_15_raw_index = cnt;
  171. break;
  172. }
  173. }
  174. }
  175. }
  176. }
  177. /* If 2 valid windows form cycle then merge them as single window */
  178. if (phase_0_found && phase_15_found) {
  179. /* number of phases in raw where phase 0 is present */
  180. u8 phases_0 = phases_per_row[phase_0_raw_index];
  181. /* number of phases in raw where phase 15 is present */
  182. u8 phases_15 = phases_per_row[phase_15_raw_index];
  183. if (phases_0 + phases_15 >= MAX_PHASES)
  184. /*
  185. * If there are more than 1 phase windows then total
  186. * number of phases in both the windows should not be
  187. * more than or equal to MAX_PHASES.
  188. */
  189. return -EINVAL;
  190. /* Merge 2 cyclic windows */
  191. i = phases_15;
  192. for (cnt = 0; cnt < phases_0; cnt++) {
  193. ranges[phase_15_raw_index][i] =
  194. ranges[phase_0_raw_index][cnt];
  195. if (++i >= MAX_PHASES)
  196. break;
  197. }
  198. phases_per_row[phase_0_raw_index] = 0;
  199. phases_per_row[phase_15_raw_index] = phases_15 + phases_0;
  200. }
  201. for (cnt = 0; cnt <= row_index; cnt++) {
  202. if (phases_per_row[cnt] > curr_max) {
  203. curr_max = phases_per_row[cnt];
  204. selected_row_index = cnt;
  205. }
  206. }
  207. i = (curr_max * 3) / 4;
  208. if (i)
  209. i--;
  210. ret = ranges[selected_row_index][i];
  211. if (ret >= MAX_PHASES) {
  212. ret = -EINVAL;
  213. dev_err(mmc_dev(mmc), "%s: Invalid phase selected=%d\n",
  214. mmc_hostname(mmc), ret);
  215. }
  216. return ret;
  217. }
  218. static inline void msm_cm_dll_set_freq(struct sdhci_host *host)
  219. {
  220. u32 mclk_freq = 0, config;
  221. /* Program the MCLK value to MCLK_FREQ bit field */
  222. if (host->clock <= 112000000)
  223. mclk_freq = 0;
  224. else if (host->clock <= 125000000)
  225. mclk_freq = 1;
  226. else if (host->clock <= 137000000)
  227. mclk_freq = 2;
  228. else if (host->clock <= 150000000)
  229. mclk_freq = 3;
  230. else if (host->clock <= 162000000)
  231. mclk_freq = 4;
  232. else if (host->clock <= 175000000)
  233. mclk_freq = 5;
  234. else if (host->clock <= 187000000)
  235. mclk_freq = 6;
  236. else if (host->clock <= 200000000)
  237. mclk_freq = 7;
  238. config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG);
  239. config &= ~CMUX_SHIFT_PHASE_MASK;
  240. config |= mclk_freq << CMUX_SHIFT_PHASE_SHIFT;
  241. writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG);
  242. }
  243. /* Initialize the DLL (Programmable Delay Line) */
  244. static int msm_init_cm_dll(struct sdhci_host *host)
  245. {
  246. struct mmc_host *mmc = host->mmc;
  247. int wait_cnt = 50;
  248. unsigned long flags;
  249. spin_lock_irqsave(&host->lock, flags);
  250. /*
  251. * Make sure that clock is always enabled when DLL
  252. * tuning is in progress. Keeping PWRSAVE ON may
  253. * turn off the clock.
  254. */
  255. writel_relaxed((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC)
  256. & ~CORE_CLK_PWRSAVE), host->ioaddr + CORE_VENDOR_SPEC);
  257. /* Write 1 to DLL_RST bit of DLL_CONFIG register */
  258. writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG)
  259. | CORE_DLL_RST), host->ioaddr + CORE_DLL_CONFIG);
  260. /* Write 1 to DLL_PDN bit of DLL_CONFIG register */
  261. writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG)
  262. | CORE_DLL_PDN), host->ioaddr + CORE_DLL_CONFIG);
  263. msm_cm_dll_set_freq(host);
  264. /* Write 0 to DLL_RST bit of DLL_CONFIG register */
  265. writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG)
  266. & ~CORE_DLL_RST), host->ioaddr + CORE_DLL_CONFIG);
  267. /* Write 0 to DLL_PDN bit of DLL_CONFIG register */
  268. writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG)
  269. & ~CORE_DLL_PDN), host->ioaddr + CORE_DLL_CONFIG);
  270. /* Set DLL_EN bit to 1. */
  271. writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG)
  272. | CORE_DLL_EN), host->ioaddr + CORE_DLL_CONFIG);
  273. /* Set CK_OUT_EN bit to 1. */
  274. writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG)
  275. | CORE_CK_OUT_EN), host->ioaddr + CORE_DLL_CONFIG);
  276. /* Wait until DLL_LOCK bit of DLL_STATUS register becomes '1' */
  277. while (!(readl_relaxed(host->ioaddr + CORE_DLL_STATUS) &
  278. CORE_DLL_LOCK)) {
  279. /* max. wait for 50us sec for LOCK bit to be set */
  280. if (--wait_cnt == 0) {
  281. dev_err(mmc_dev(mmc), "%s: DLL failed to LOCK\n",
  282. mmc_hostname(mmc));
  283. spin_unlock_irqrestore(&host->lock, flags);
  284. return -ETIMEDOUT;
  285. }
  286. udelay(1);
  287. }
  288. spin_unlock_irqrestore(&host->lock, flags);
  289. return 0;
  290. }
  291. static int sdhci_msm_execute_tuning(struct sdhci_host *host, u32 opcode)
  292. {
  293. int tuning_seq_cnt = 3;
  294. u8 phase, tuned_phases[16], tuned_phase_cnt = 0;
  295. int rc;
  296. struct mmc_host *mmc = host->mmc;
  297. struct mmc_ios ios = host->mmc->ios;
  298. /*
  299. * Tuning is required for SDR104, HS200 and HS400 cards and
  300. * if clock frequency is greater than 100MHz in these modes.
  301. */
  302. if (host->clock <= 100 * 1000 * 1000 ||
  303. !((ios.timing == MMC_TIMING_MMC_HS200) ||
  304. (ios.timing == MMC_TIMING_UHS_SDR104)))
  305. return 0;
  306. retry:
  307. /* First of all reset the tuning block */
  308. rc = msm_init_cm_dll(host);
  309. if (rc)
  310. return rc;
  311. phase = 0;
  312. do {
  313. /* Set the phase in delay line hw block */
  314. rc = msm_config_cm_dll_phase(host, phase);
  315. if (rc)
  316. return rc;
  317. rc = mmc_send_tuning(mmc, opcode, NULL);
  318. if (!rc) {
  319. /* Tuning is successful at this tuning point */
  320. tuned_phases[tuned_phase_cnt++] = phase;
  321. dev_dbg(mmc_dev(mmc), "%s: Found good phase = %d\n",
  322. mmc_hostname(mmc), phase);
  323. }
  324. } while (++phase < ARRAY_SIZE(tuned_phases));
  325. if (tuned_phase_cnt) {
  326. rc = msm_find_most_appropriate_phase(host, tuned_phases,
  327. tuned_phase_cnt);
  328. if (rc < 0)
  329. return rc;
  330. else
  331. phase = rc;
  332. /*
  333. * Finally set the selected phase in delay
  334. * line hw block.
  335. */
  336. rc = msm_config_cm_dll_phase(host, phase);
  337. if (rc)
  338. return rc;
  339. dev_dbg(mmc_dev(mmc), "%s: Setting the tuning phase to %d\n",
  340. mmc_hostname(mmc), phase);
  341. } else {
  342. if (--tuning_seq_cnt)
  343. goto retry;
  344. /* Tuning failed */
  345. dev_dbg(mmc_dev(mmc), "%s: No tuning point found\n",
  346. mmc_hostname(mmc));
  347. rc = -EIO;
  348. }
  349. return rc;
  350. }
  351. static const struct of_device_id sdhci_msm_dt_match[] = {
  352. { .compatible = "qcom,sdhci-msm-v4" },
  353. {},
  354. };
  355. MODULE_DEVICE_TABLE(of, sdhci_msm_dt_match);
  356. static const struct sdhci_ops sdhci_msm_ops = {
  357. .platform_execute_tuning = sdhci_msm_execute_tuning,
  358. .reset = sdhci_reset,
  359. .set_clock = sdhci_set_clock,
  360. .set_bus_width = sdhci_set_bus_width,
  361. .set_uhs_signaling = sdhci_set_uhs_signaling,
  362. };
  363. static const struct sdhci_pltfm_data sdhci_msm_pdata = {
  364. .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
  365. SDHCI_QUIRK_SINGLE_POWER_WRITE,
  366. .ops = &sdhci_msm_ops,
  367. };
  368. static int sdhci_msm_probe(struct platform_device *pdev)
  369. {
  370. struct sdhci_host *host;
  371. struct sdhci_pltfm_host *pltfm_host;
  372. struct sdhci_msm_host *msm_host;
  373. struct resource *core_memres;
  374. int ret;
  375. u16 host_version, core_minor;
  376. u32 core_version, caps;
  377. u8 core_major;
  378. host = sdhci_pltfm_init(pdev, &sdhci_msm_pdata, sizeof(*msm_host));
  379. if (IS_ERR(host))
  380. return PTR_ERR(host);
  381. pltfm_host = sdhci_priv(host);
  382. msm_host = sdhci_pltfm_priv(pltfm_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_version = readw_relaxed((host->ioaddr + SDHCI_HOST_VERSION));
  444. dev_dbg(&pdev->dev, "Host Version: 0x%x Vendor Version 0x%x\n",
  445. host_version, ((host_version & SDHCI_VENDOR_VER_MASK) >>
  446. SDHCI_VENDOR_VER_SHIFT));
  447. core_version = readl_relaxed(msm_host->core_mem + CORE_MCI_VERSION);
  448. core_major = (core_version & CORE_VERSION_MAJOR_MASK) >>
  449. CORE_VERSION_MAJOR_SHIFT;
  450. core_minor = core_version & CORE_VERSION_MINOR_MASK;
  451. dev_dbg(&pdev->dev, "MCI Version: 0x%08x, major: 0x%04x, minor: 0x%02x\n",
  452. core_version, core_major, core_minor);
  453. /*
  454. * Support for some capabilities is not advertised by newer
  455. * controller versions and must be explicitly enabled.
  456. */
  457. if (core_major >= 1 && core_minor != 0x11 && core_minor != 0x12) {
  458. caps = readl_relaxed(host->ioaddr + SDHCI_CAPABILITIES);
  459. caps |= SDHCI_CAN_VDD_300 | SDHCI_CAN_DO_8BIT;
  460. writel_relaxed(caps, host->ioaddr +
  461. CORE_VENDOR_SPEC_CAPABILITIES0);
  462. }
  463. ret = sdhci_add_host(host);
  464. if (ret)
  465. goto clk_disable;
  466. return 0;
  467. clk_disable:
  468. clk_disable_unprepare(msm_host->clk);
  469. pclk_disable:
  470. clk_disable_unprepare(msm_host->pclk);
  471. bus_clk_disable:
  472. if (!IS_ERR(msm_host->bus_clk))
  473. clk_disable_unprepare(msm_host->bus_clk);
  474. pltfm_free:
  475. sdhci_pltfm_free(pdev);
  476. return ret;
  477. }
  478. static int sdhci_msm_remove(struct platform_device *pdev)
  479. {
  480. struct sdhci_host *host = platform_get_drvdata(pdev);
  481. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  482. struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
  483. int dead = (readl_relaxed(host->ioaddr + SDHCI_INT_STATUS) ==
  484. 0xffffffff);
  485. sdhci_remove_host(host, dead);
  486. clk_disable_unprepare(msm_host->clk);
  487. clk_disable_unprepare(msm_host->pclk);
  488. if (!IS_ERR(msm_host->bus_clk))
  489. clk_disable_unprepare(msm_host->bus_clk);
  490. sdhci_pltfm_free(pdev);
  491. return 0;
  492. }
  493. static struct platform_driver sdhci_msm_driver = {
  494. .probe = sdhci_msm_probe,
  495. .remove = sdhci_msm_remove,
  496. .driver = {
  497. .name = "sdhci_msm",
  498. .of_match_table = sdhci_msm_dt_match,
  499. },
  500. };
  501. module_platform_driver(sdhci_msm_driver);
  502. MODULE_DESCRIPTION("Qualcomm Secure Digital Host Controller Interface driver");
  503. MODULE_LICENSE("GPL v2");