sdhci-s3c.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. /* linux/drivers/mmc/host/sdhci-s3c.c
  2. *
  3. * Copyright 2008 Openmoko Inc.
  4. * Copyright 2008 Simtec Electronics
  5. * Ben Dooks <ben@simtec.co.uk>
  6. * http://armlinux.simtec.co.uk/
  7. *
  8. * SDHCI (HSMMC) support for Samsung SoC
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/spinlock.h>
  15. #include <linux/delay.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/platform_data/mmc-sdhci-s3c.h>
  19. #include <linux/slab.h>
  20. #include <linux/clk.h>
  21. #include <linux/io.h>
  22. #include <linux/gpio.h>
  23. #include <linux/module.h>
  24. #include <linux/of.h>
  25. #include <linux/of_gpio.h>
  26. #include <linux/pm.h>
  27. #include <linux/pm_runtime.h>
  28. #include <linux/mmc/host.h>
  29. #include "sdhci-s3c-regs.h"
  30. #include "sdhci.h"
  31. #define MAX_BUS_CLK (4)
  32. /**
  33. * struct sdhci_s3c - S3C SDHCI instance
  34. * @host: The SDHCI host created
  35. * @pdev: The platform device we where created from.
  36. * @ioarea: The resource created when we claimed the IO area.
  37. * @pdata: The platform data for this controller.
  38. * @cur_clk: The index of the current bus clock.
  39. * @clk_io: The clock for the internal bus interface.
  40. * @clk_bus: The clocks that are available for the SD/MMC bus clock.
  41. */
  42. struct sdhci_s3c {
  43. struct sdhci_host *host;
  44. struct platform_device *pdev;
  45. struct resource *ioarea;
  46. struct s3c_sdhci_platdata *pdata;
  47. int cur_clk;
  48. int ext_cd_irq;
  49. int ext_cd_gpio;
  50. struct clk *clk_io;
  51. struct clk *clk_bus[MAX_BUS_CLK];
  52. unsigned long clk_rates[MAX_BUS_CLK];
  53. bool no_divider;
  54. };
  55. /**
  56. * struct sdhci_s3c_driver_data - S3C SDHCI platform specific driver data
  57. * @sdhci_quirks: sdhci host specific quirks.
  58. *
  59. * Specifies platform specific configuration of sdhci controller.
  60. * Note: A structure for driver specific platform data is used for future
  61. * expansion of its usage.
  62. */
  63. struct sdhci_s3c_drv_data {
  64. unsigned int sdhci_quirks;
  65. bool no_divider;
  66. };
  67. static inline struct sdhci_s3c *to_s3c(struct sdhci_host *host)
  68. {
  69. return sdhci_priv(host);
  70. }
  71. /**
  72. * sdhci_s3c_get_max_clk - callback to get maximum clock frequency.
  73. * @host: The SDHCI host instance.
  74. *
  75. * Callback to return the maximum clock rate acheivable by the controller.
  76. */
  77. static unsigned int sdhci_s3c_get_max_clk(struct sdhci_host *host)
  78. {
  79. struct sdhci_s3c *ourhost = to_s3c(host);
  80. unsigned long rate, max = 0;
  81. int src;
  82. for (src = 0; src < MAX_BUS_CLK; src++) {
  83. rate = ourhost->clk_rates[src];
  84. if (rate > max)
  85. max = rate;
  86. }
  87. return max;
  88. }
  89. /**
  90. * sdhci_s3c_consider_clock - consider one the bus clocks for current setting
  91. * @ourhost: Our SDHCI instance.
  92. * @src: The source clock index.
  93. * @wanted: The clock frequency wanted.
  94. */
  95. static unsigned int sdhci_s3c_consider_clock(struct sdhci_s3c *ourhost,
  96. unsigned int src,
  97. unsigned int wanted)
  98. {
  99. unsigned long rate;
  100. struct clk *clksrc = ourhost->clk_bus[src];
  101. int shift;
  102. if (IS_ERR(clksrc))
  103. return UINT_MAX;
  104. /*
  105. * If controller uses a non-standard clock division, find the best clock
  106. * speed possible with selected clock source and skip the division.
  107. */
  108. if (ourhost->no_divider) {
  109. rate = clk_round_rate(clksrc, wanted);
  110. return wanted - rate;
  111. }
  112. rate = ourhost->clk_rates[src];
  113. for (shift = 0; shift <= 8; ++shift) {
  114. if ((rate >> shift) <= wanted)
  115. break;
  116. }
  117. if (shift > 8) {
  118. dev_dbg(&ourhost->pdev->dev,
  119. "clk %d: rate %ld, min rate %lu > wanted %u\n",
  120. src, rate, rate / 256, wanted);
  121. return UINT_MAX;
  122. }
  123. dev_dbg(&ourhost->pdev->dev, "clk %d: rate %ld, want %d, got %ld\n",
  124. src, rate, wanted, rate >> shift);
  125. return wanted - (rate >> shift);
  126. }
  127. /**
  128. * sdhci_s3c_set_clock - callback on clock change
  129. * @host: The SDHCI host being changed
  130. * @clock: The clock rate being requested.
  131. *
  132. * When the card's clock is going to be changed, look at the new frequency
  133. * and find the best clock source to go with it.
  134. */
  135. static void sdhci_s3c_set_clock(struct sdhci_host *host, unsigned int clock)
  136. {
  137. struct sdhci_s3c *ourhost = to_s3c(host);
  138. unsigned int best = UINT_MAX;
  139. unsigned int delta;
  140. int best_src = 0;
  141. int src;
  142. u32 ctrl;
  143. host->mmc->actual_clock = 0;
  144. /* don't bother if the clock is going off. */
  145. if (clock == 0) {
  146. sdhci_set_clock(host, clock);
  147. return;
  148. }
  149. for (src = 0; src < MAX_BUS_CLK; src++) {
  150. delta = sdhci_s3c_consider_clock(ourhost, src, clock);
  151. if (delta < best) {
  152. best = delta;
  153. best_src = src;
  154. }
  155. }
  156. dev_dbg(&ourhost->pdev->dev,
  157. "selected source %d, clock %d, delta %d\n",
  158. best_src, clock, best);
  159. /* select the new clock source */
  160. if (ourhost->cur_clk != best_src) {
  161. struct clk *clk = ourhost->clk_bus[best_src];
  162. clk_prepare_enable(clk);
  163. if (ourhost->cur_clk >= 0)
  164. clk_disable_unprepare(
  165. ourhost->clk_bus[ourhost->cur_clk]);
  166. ourhost->cur_clk = best_src;
  167. host->max_clk = ourhost->clk_rates[best_src];
  168. }
  169. /* turn clock off to card before changing clock source */
  170. writew(0, host->ioaddr + SDHCI_CLOCK_CONTROL);
  171. ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2);
  172. ctrl &= ~S3C_SDHCI_CTRL2_SELBASECLK_MASK;
  173. ctrl |= best_src << S3C_SDHCI_CTRL2_SELBASECLK_SHIFT;
  174. writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL2);
  175. /* reprogram default hardware configuration */
  176. writel(S3C64XX_SDHCI_CONTROL4_DRIVE_9mA,
  177. host->ioaddr + S3C64XX_SDHCI_CONTROL4);
  178. ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2);
  179. ctrl |= (S3C64XX_SDHCI_CTRL2_ENSTAASYNCCLR |
  180. S3C64XX_SDHCI_CTRL2_ENCMDCNFMSK |
  181. S3C_SDHCI_CTRL2_ENFBCLKRX |
  182. S3C_SDHCI_CTRL2_DFCNT_NONE |
  183. S3C_SDHCI_CTRL2_ENCLKOUTHOLD);
  184. writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL2);
  185. /* reconfigure the controller for new clock rate */
  186. ctrl = (S3C_SDHCI_CTRL3_FCSEL1 | S3C_SDHCI_CTRL3_FCSEL0);
  187. if (clock < 25 * 1000000)
  188. ctrl |= (S3C_SDHCI_CTRL3_FCSEL3 | S3C_SDHCI_CTRL3_FCSEL2);
  189. writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL3);
  190. sdhci_set_clock(host, clock);
  191. }
  192. /**
  193. * sdhci_s3c_get_min_clock - callback to get minimal supported clock value
  194. * @host: The SDHCI host being queried
  195. *
  196. * To init mmc host properly a minimal clock value is needed. For high system
  197. * bus clock's values the standard formula gives values out of allowed range.
  198. * The clock still can be set to lower values, if clock source other then
  199. * system bus is selected.
  200. */
  201. static unsigned int sdhci_s3c_get_min_clock(struct sdhci_host *host)
  202. {
  203. struct sdhci_s3c *ourhost = to_s3c(host);
  204. unsigned long rate, min = ULONG_MAX;
  205. int src;
  206. for (src = 0; src < MAX_BUS_CLK; src++) {
  207. rate = ourhost->clk_rates[src] / 256;
  208. if (!rate)
  209. continue;
  210. if (rate < min)
  211. min = rate;
  212. }
  213. return min;
  214. }
  215. /* sdhci_cmu_get_max_clk - callback to get maximum clock frequency.*/
  216. static unsigned int sdhci_cmu_get_max_clock(struct sdhci_host *host)
  217. {
  218. struct sdhci_s3c *ourhost = to_s3c(host);
  219. unsigned long rate, max = 0;
  220. int src;
  221. for (src = 0; src < MAX_BUS_CLK; src++) {
  222. struct clk *clk;
  223. clk = ourhost->clk_bus[src];
  224. if (IS_ERR(clk))
  225. continue;
  226. rate = clk_round_rate(clk, ULONG_MAX);
  227. if (rate > max)
  228. max = rate;
  229. }
  230. return max;
  231. }
  232. /* sdhci_cmu_get_min_clock - callback to get minimal supported clock value. */
  233. static unsigned int sdhci_cmu_get_min_clock(struct sdhci_host *host)
  234. {
  235. struct sdhci_s3c *ourhost = to_s3c(host);
  236. unsigned long rate, min = ULONG_MAX;
  237. int src;
  238. for (src = 0; src < MAX_BUS_CLK; src++) {
  239. struct clk *clk;
  240. clk = ourhost->clk_bus[src];
  241. if (IS_ERR(clk))
  242. continue;
  243. rate = clk_round_rate(clk, 0);
  244. if (rate < min)
  245. min = rate;
  246. }
  247. return min;
  248. }
  249. /* sdhci_cmu_set_clock - callback on clock change.*/
  250. static void sdhci_cmu_set_clock(struct sdhci_host *host, unsigned int clock)
  251. {
  252. struct sdhci_s3c *ourhost = to_s3c(host);
  253. struct device *dev = &ourhost->pdev->dev;
  254. unsigned long timeout;
  255. u16 clk = 0;
  256. int ret;
  257. host->mmc->actual_clock = 0;
  258. /* If the clock is going off, set to 0 at clock control register */
  259. if (clock == 0) {
  260. sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
  261. return;
  262. }
  263. sdhci_s3c_set_clock(host, clock);
  264. /* Reset SD Clock Enable */
  265. clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
  266. clk &= ~SDHCI_CLOCK_CARD_EN;
  267. sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
  268. spin_unlock_irq(&host->lock);
  269. ret = clk_set_rate(ourhost->clk_bus[ourhost->cur_clk], clock);
  270. spin_lock_irq(&host->lock);
  271. if (ret != 0) {
  272. dev_err(dev, "%s: failed to set clock rate %uHz\n",
  273. mmc_hostname(host->mmc), clock);
  274. return;
  275. }
  276. clk = SDHCI_CLOCK_INT_EN;
  277. sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
  278. /* Wait max 20 ms */
  279. timeout = 20;
  280. while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
  281. & SDHCI_CLOCK_INT_STABLE)) {
  282. if (timeout == 0) {
  283. dev_err(dev, "%s: Internal clock never stabilised.\n",
  284. mmc_hostname(host->mmc));
  285. return;
  286. }
  287. timeout--;
  288. mdelay(1);
  289. }
  290. clk |= SDHCI_CLOCK_CARD_EN;
  291. sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
  292. }
  293. /**
  294. * sdhci_s3c_set_bus_width - support 8bit buswidth
  295. * @host: The SDHCI host being queried
  296. * @width: MMC_BUS_WIDTH_ macro for the bus width being requested
  297. *
  298. * We have 8-bit width support but is not a v3 controller.
  299. * So we add platform_bus_width() and support 8bit width.
  300. */
  301. static void sdhci_s3c_set_bus_width(struct sdhci_host *host, int width)
  302. {
  303. u8 ctrl;
  304. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  305. switch (width) {
  306. case MMC_BUS_WIDTH_8:
  307. ctrl |= SDHCI_CTRL_8BITBUS;
  308. ctrl &= ~SDHCI_CTRL_4BITBUS;
  309. break;
  310. case MMC_BUS_WIDTH_4:
  311. ctrl |= SDHCI_CTRL_4BITBUS;
  312. ctrl &= ~SDHCI_CTRL_8BITBUS;
  313. break;
  314. default:
  315. ctrl &= ~SDHCI_CTRL_4BITBUS;
  316. ctrl &= ~SDHCI_CTRL_8BITBUS;
  317. break;
  318. }
  319. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  320. }
  321. static struct sdhci_ops sdhci_s3c_ops = {
  322. .get_max_clock = sdhci_s3c_get_max_clk,
  323. .set_clock = sdhci_s3c_set_clock,
  324. .get_min_clock = sdhci_s3c_get_min_clock,
  325. .set_bus_width = sdhci_s3c_set_bus_width,
  326. .reset = sdhci_reset,
  327. .set_uhs_signaling = sdhci_set_uhs_signaling,
  328. };
  329. #ifdef CONFIG_OF
  330. static int sdhci_s3c_parse_dt(struct device *dev,
  331. struct sdhci_host *host, struct s3c_sdhci_platdata *pdata)
  332. {
  333. struct device_node *node = dev->of_node;
  334. u32 max_width;
  335. /* if the bus-width property is not specified, assume width as 1 */
  336. if (of_property_read_u32(node, "bus-width", &max_width))
  337. max_width = 1;
  338. pdata->max_width = max_width;
  339. /* get the card detection method */
  340. if (of_get_property(node, "broken-cd", NULL)) {
  341. pdata->cd_type = S3C_SDHCI_CD_NONE;
  342. return 0;
  343. }
  344. if (of_get_property(node, "non-removable", NULL)) {
  345. pdata->cd_type = S3C_SDHCI_CD_PERMANENT;
  346. return 0;
  347. }
  348. if (of_get_named_gpio(node, "cd-gpios", 0))
  349. return 0;
  350. /* assuming internal card detect that will be configured by pinctrl */
  351. pdata->cd_type = S3C_SDHCI_CD_INTERNAL;
  352. return 0;
  353. }
  354. #else
  355. static int sdhci_s3c_parse_dt(struct device *dev,
  356. struct sdhci_host *host, struct s3c_sdhci_platdata *pdata)
  357. {
  358. return -EINVAL;
  359. }
  360. #endif
  361. static const struct of_device_id sdhci_s3c_dt_match[];
  362. static inline struct sdhci_s3c_drv_data *sdhci_s3c_get_driver_data(
  363. struct platform_device *pdev)
  364. {
  365. #ifdef CONFIG_OF
  366. if (pdev->dev.of_node) {
  367. const struct of_device_id *match;
  368. match = of_match_node(sdhci_s3c_dt_match, pdev->dev.of_node);
  369. return (struct sdhci_s3c_drv_data *)match->data;
  370. }
  371. #endif
  372. return (struct sdhci_s3c_drv_data *)
  373. platform_get_device_id(pdev)->driver_data;
  374. }
  375. static int sdhci_s3c_probe(struct platform_device *pdev)
  376. {
  377. struct s3c_sdhci_platdata *pdata;
  378. struct sdhci_s3c_drv_data *drv_data;
  379. struct device *dev = &pdev->dev;
  380. struct sdhci_host *host;
  381. struct sdhci_s3c *sc;
  382. struct resource *res;
  383. int ret, irq, ptr, clks;
  384. if (!pdev->dev.platform_data && !pdev->dev.of_node) {
  385. dev_err(dev, "no device data specified\n");
  386. return -ENOENT;
  387. }
  388. irq = platform_get_irq(pdev, 0);
  389. if (irq < 0) {
  390. dev_err(dev, "no irq specified\n");
  391. return irq;
  392. }
  393. host = sdhci_alloc_host(dev, sizeof(struct sdhci_s3c));
  394. if (IS_ERR(host)) {
  395. dev_err(dev, "sdhci_alloc_host() failed\n");
  396. return PTR_ERR(host);
  397. }
  398. sc = sdhci_priv(host);
  399. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  400. if (!pdata) {
  401. ret = -ENOMEM;
  402. goto err_pdata_io_clk;
  403. }
  404. if (pdev->dev.of_node) {
  405. ret = sdhci_s3c_parse_dt(&pdev->dev, host, pdata);
  406. if (ret)
  407. goto err_pdata_io_clk;
  408. } else {
  409. memcpy(pdata, pdev->dev.platform_data, sizeof(*pdata));
  410. sc->ext_cd_gpio = -1; /* invalid gpio number */
  411. }
  412. drv_data = sdhci_s3c_get_driver_data(pdev);
  413. sc->host = host;
  414. sc->pdev = pdev;
  415. sc->pdata = pdata;
  416. sc->cur_clk = -1;
  417. platform_set_drvdata(pdev, host);
  418. sc->clk_io = devm_clk_get(dev, "hsmmc");
  419. if (IS_ERR(sc->clk_io)) {
  420. dev_err(dev, "failed to get io clock\n");
  421. ret = PTR_ERR(sc->clk_io);
  422. goto err_pdata_io_clk;
  423. }
  424. /* enable the local io clock and keep it running for the moment. */
  425. clk_prepare_enable(sc->clk_io);
  426. for (clks = 0, ptr = 0; ptr < MAX_BUS_CLK; ptr++) {
  427. char name[14];
  428. snprintf(name, 14, "mmc_busclk.%d", ptr);
  429. sc->clk_bus[ptr] = devm_clk_get(dev, name);
  430. if (IS_ERR(sc->clk_bus[ptr]))
  431. continue;
  432. clks++;
  433. sc->clk_rates[ptr] = clk_get_rate(sc->clk_bus[ptr]);
  434. dev_info(dev, "clock source %d: %s (%ld Hz)\n",
  435. ptr, name, sc->clk_rates[ptr]);
  436. }
  437. if (clks == 0) {
  438. dev_err(dev, "failed to find any bus clocks\n");
  439. ret = -ENOENT;
  440. goto err_no_busclks;
  441. }
  442. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  443. host->ioaddr = devm_ioremap_resource(&pdev->dev, res);
  444. if (IS_ERR(host->ioaddr)) {
  445. ret = PTR_ERR(host->ioaddr);
  446. goto err_req_regs;
  447. }
  448. /* Ensure we have minimal gpio selected CMD/CLK/Detect */
  449. if (pdata->cfg_gpio)
  450. pdata->cfg_gpio(pdev, pdata->max_width);
  451. host->hw_name = "samsung-hsmmc";
  452. host->ops = &sdhci_s3c_ops;
  453. host->quirks = 0;
  454. host->quirks2 = 0;
  455. host->irq = irq;
  456. /* Setup quirks for the controller */
  457. host->quirks |= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC;
  458. host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT;
  459. if (drv_data) {
  460. host->quirks |= drv_data->sdhci_quirks;
  461. sc->no_divider = drv_data->no_divider;
  462. }
  463. #ifndef CONFIG_MMC_SDHCI_S3C_DMA
  464. /* we currently see overruns on errors, so disable the SDMA
  465. * support as well. */
  466. host->quirks |= SDHCI_QUIRK_BROKEN_DMA;
  467. #endif /* CONFIG_MMC_SDHCI_S3C_DMA */
  468. /* It seems we do not get an DATA transfer complete on non-busy
  469. * transfers, not sure if this is a problem with this specific
  470. * SDHCI block, or a missing configuration that needs to be set. */
  471. host->quirks |= SDHCI_QUIRK_NO_BUSY_IRQ;
  472. /* This host supports the Auto CMD12 */
  473. host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12;
  474. /* Samsung SoCs need BROKEN_ADMA_ZEROLEN_DESC */
  475. host->quirks |= SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC;
  476. if (pdata->cd_type == S3C_SDHCI_CD_NONE ||
  477. pdata->cd_type == S3C_SDHCI_CD_PERMANENT)
  478. host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
  479. if (pdata->cd_type == S3C_SDHCI_CD_PERMANENT)
  480. host->mmc->caps = MMC_CAP_NONREMOVABLE;
  481. switch (pdata->max_width) {
  482. case 8:
  483. host->mmc->caps |= MMC_CAP_8_BIT_DATA;
  484. case 4:
  485. host->mmc->caps |= MMC_CAP_4_BIT_DATA;
  486. break;
  487. }
  488. if (pdata->pm_caps)
  489. host->mmc->pm_caps |= pdata->pm_caps;
  490. host->quirks |= (SDHCI_QUIRK_32BIT_DMA_ADDR |
  491. SDHCI_QUIRK_32BIT_DMA_SIZE);
  492. /* HSMMC on Samsung SoCs uses SDCLK as timeout clock */
  493. host->quirks |= SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK;
  494. /*
  495. * If controller does not have internal clock divider,
  496. * we can use overriding functions instead of default.
  497. */
  498. if (sc->no_divider) {
  499. sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
  500. sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
  501. sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
  502. }
  503. /* It supports additional host capabilities if needed */
  504. if (pdata->host_caps)
  505. host->mmc->caps |= pdata->host_caps;
  506. if (pdata->host_caps2)
  507. host->mmc->caps2 |= pdata->host_caps2;
  508. pm_runtime_enable(&pdev->dev);
  509. pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
  510. pm_runtime_use_autosuspend(&pdev->dev);
  511. pm_suspend_ignore_children(&pdev->dev, 1);
  512. ret = mmc_of_parse(host->mmc);
  513. if (ret)
  514. goto err_req_regs;
  515. ret = sdhci_add_host(host);
  516. if (ret) {
  517. dev_err(dev, "sdhci_add_host() failed\n");
  518. goto err_req_regs;
  519. }
  520. #ifdef CONFIG_PM
  521. if (pdata->cd_type != S3C_SDHCI_CD_INTERNAL)
  522. clk_disable_unprepare(sc->clk_io);
  523. #endif
  524. return 0;
  525. err_req_regs:
  526. pm_runtime_disable(&pdev->dev);
  527. err_no_busclks:
  528. clk_disable_unprepare(sc->clk_io);
  529. err_pdata_io_clk:
  530. sdhci_free_host(host);
  531. return ret;
  532. }
  533. static int sdhci_s3c_remove(struct platform_device *pdev)
  534. {
  535. struct sdhci_host *host = platform_get_drvdata(pdev);
  536. struct sdhci_s3c *sc = sdhci_priv(host);
  537. if (sc->ext_cd_irq)
  538. free_irq(sc->ext_cd_irq, sc);
  539. #ifdef CONFIG_PM
  540. if (sc->pdata->cd_type != S3C_SDHCI_CD_INTERNAL)
  541. clk_prepare_enable(sc->clk_io);
  542. #endif
  543. sdhci_remove_host(host, 1);
  544. pm_runtime_dont_use_autosuspend(&pdev->dev);
  545. pm_runtime_disable(&pdev->dev);
  546. clk_disable_unprepare(sc->clk_io);
  547. sdhci_free_host(host);
  548. return 0;
  549. }
  550. #ifdef CONFIG_PM_SLEEP
  551. static int sdhci_s3c_suspend(struct device *dev)
  552. {
  553. struct sdhci_host *host = dev_get_drvdata(dev);
  554. return sdhci_suspend_host(host);
  555. }
  556. static int sdhci_s3c_resume(struct device *dev)
  557. {
  558. struct sdhci_host *host = dev_get_drvdata(dev);
  559. return sdhci_resume_host(host);
  560. }
  561. #endif
  562. #ifdef CONFIG_PM
  563. static int sdhci_s3c_runtime_suspend(struct device *dev)
  564. {
  565. struct sdhci_host *host = dev_get_drvdata(dev);
  566. struct sdhci_s3c *ourhost = to_s3c(host);
  567. struct clk *busclk = ourhost->clk_io;
  568. int ret;
  569. ret = sdhci_runtime_suspend_host(host);
  570. if (ourhost->cur_clk >= 0)
  571. clk_disable_unprepare(ourhost->clk_bus[ourhost->cur_clk]);
  572. clk_disable_unprepare(busclk);
  573. return ret;
  574. }
  575. static int sdhci_s3c_runtime_resume(struct device *dev)
  576. {
  577. struct sdhci_host *host = dev_get_drvdata(dev);
  578. struct sdhci_s3c *ourhost = to_s3c(host);
  579. struct clk *busclk = ourhost->clk_io;
  580. int ret;
  581. clk_prepare_enable(busclk);
  582. if (ourhost->cur_clk >= 0)
  583. clk_prepare_enable(ourhost->clk_bus[ourhost->cur_clk]);
  584. ret = sdhci_runtime_resume_host(host);
  585. return ret;
  586. }
  587. #endif
  588. static const struct dev_pm_ops sdhci_s3c_pmops = {
  589. SET_SYSTEM_SLEEP_PM_OPS(sdhci_s3c_suspend, sdhci_s3c_resume)
  590. SET_RUNTIME_PM_OPS(sdhci_s3c_runtime_suspend, sdhci_s3c_runtime_resume,
  591. NULL)
  592. };
  593. #if defined(CONFIG_CPU_EXYNOS4210) || defined(CONFIG_SOC_EXYNOS4212)
  594. static struct sdhci_s3c_drv_data exynos4_sdhci_drv_data = {
  595. .no_divider = true,
  596. };
  597. #define EXYNOS4_SDHCI_DRV_DATA ((kernel_ulong_t)&exynos4_sdhci_drv_data)
  598. #else
  599. #define EXYNOS4_SDHCI_DRV_DATA ((kernel_ulong_t)NULL)
  600. #endif
  601. static const struct platform_device_id sdhci_s3c_driver_ids[] = {
  602. {
  603. .name = "s3c-sdhci",
  604. .driver_data = (kernel_ulong_t)NULL,
  605. }, {
  606. .name = "exynos4-sdhci",
  607. .driver_data = EXYNOS4_SDHCI_DRV_DATA,
  608. },
  609. { }
  610. };
  611. MODULE_DEVICE_TABLE(platform, sdhci_s3c_driver_ids);
  612. #ifdef CONFIG_OF
  613. static const struct of_device_id sdhci_s3c_dt_match[] = {
  614. { .compatible = "samsung,s3c6410-sdhci", },
  615. { .compatible = "samsung,exynos4210-sdhci",
  616. .data = (void *)EXYNOS4_SDHCI_DRV_DATA },
  617. {},
  618. };
  619. MODULE_DEVICE_TABLE(of, sdhci_s3c_dt_match);
  620. #endif
  621. static struct platform_driver sdhci_s3c_driver = {
  622. .probe = sdhci_s3c_probe,
  623. .remove = sdhci_s3c_remove,
  624. .id_table = sdhci_s3c_driver_ids,
  625. .driver = {
  626. .name = "s3c-sdhci",
  627. .of_match_table = of_match_ptr(sdhci_s3c_dt_match),
  628. .pm = &sdhci_s3c_pmops,
  629. },
  630. };
  631. module_platform_driver(sdhci_s3c_driver);
  632. MODULE_DESCRIPTION("Samsung SDHCI (HSMMC) glue");
  633. MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
  634. MODULE_LICENSE("GPL v2");
  635. MODULE_ALIAS("platform:s3c-sdhci");