sdhci-s3c.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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/delay.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/slab.h>
  18. #include <linux/clk.h>
  19. #include <linux/io.h>
  20. #include <linux/gpio.h>
  21. #include <linux/module.h>
  22. #include <linux/mmc/host.h>
  23. #include <plat/sdhci.h>
  24. #include <plat/regs-sdhci.h>
  25. #include "sdhci.h"
  26. #define MAX_BUS_CLK (4)
  27. /**
  28. * struct sdhci_s3c - S3C SDHCI instance
  29. * @host: The SDHCI host created
  30. * @pdev: The platform device we where created from.
  31. * @ioarea: The resource created when we claimed the IO area.
  32. * @pdata: The platform data for this controller.
  33. * @cur_clk: The index of the current bus clock.
  34. * @clk_io: The clock for the internal bus interface.
  35. * @clk_bus: The clocks that are available for the SD/MMC bus clock.
  36. */
  37. struct sdhci_s3c {
  38. struct sdhci_host *host;
  39. struct platform_device *pdev;
  40. struct resource *ioarea;
  41. struct s3c_sdhci_platdata *pdata;
  42. unsigned int cur_clk;
  43. int ext_cd_irq;
  44. int ext_cd_gpio;
  45. struct clk *clk_io;
  46. struct clk *clk_bus[MAX_BUS_CLK];
  47. };
  48. static inline struct sdhci_s3c *to_s3c(struct sdhci_host *host)
  49. {
  50. return sdhci_priv(host);
  51. }
  52. /**
  53. * get_curclk - convert ctrl2 register to clock source number
  54. * @ctrl2: Control2 register value.
  55. */
  56. static u32 get_curclk(u32 ctrl2)
  57. {
  58. ctrl2 &= S3C_SDHCI_CTRL2_SELBASECLK_MASK;
  59. ctrl2 >>= S3C_SDHCI_CTRL2_SELBASECLK_SHIFT;
  60. return ctrl2;
  61. }
  62. static void sdhci_s3c_check_sclk(struct sdhci_host *host)
  63. {
  64. struct sdhci_s3c *ourhost = to_s3c(host);
  65. u32 tmp = readl(host->ioaddr + S3C_SDHCI_CONTROL2);
  66. if (get_curclk(tmp) != ourhost->cur_clk) {
  67. dev_dbg(&ourhost->pdev->dev, "restored ctrl2 clock setting\n");
  68. tmp &= ~S3C_SDHCI_CTRL2_SELBASECLK_MASK;
  69. tmp |= ourhost->cur_clk << S3C_SDHCI_CTRL2_SELBASECLK_SHIFT;
  70. writel(tmp, host->ioaddr + 0x80);
  71. }
  72. }
  73. /**
  74. * sdhci_s3c_get_max_clk - callback to get maximum clock frequency.
  75. * @host: The SDHCI host instance.
  76. *
  77. * Callback to return the maximum clock rate acheivable by the controller.
  78. */
  79. static unsigned int sdhci_s3c_get_max_clk(struct sdhci_host *host)
  80. {
  81. struct sdhci_s3c *ourhost = to_s3c(host);
  82. struct clk *busclk;
  83. unsigned int rate, max;
  84. int clk;
  85. /* note, a reset will reset the clock source */
  86. sdhci_s3c_check_sclk(host);
  87. for (max = 0, clk = 0; clk < MAX_BUS_CLK; clk++) {
  88. busclk = ourhost->clk_bus[clk];
  89. if (!busclk)
  90. continue;
  91. rate = clk_get_rate(busclk);
  92. if (rate > max)
  93. max = rate;
  94. }
  95. return max;
  96. }
  97. /**
  98. * sdhci_s3c_consider_clock - consider one the bus clocks for current setting
  99. * @ourhost: Our SDHCI instance.
  100. * @src: The source clock index.
  101. * @wanted: The clock frequency wanted.
  102. */
  103. static unsigned int sdhci_s3c_consider_clock(struct sdhci_s3c *ourhost,
  104. unsigned int src,
  105. unsigned int wanted)
  106. {
  107. unsigned long rate;
  108. struct clk *clksrc = ourhost->clk_bus[src];
  109. int div;
  110. if (!clksrc)
  111. return UINT_MAX;
  112. /*
  113. * Clock divider's step is different as 1 from that of host controller
  114. * when 'clk_type' is S3C_SDHCI_CLK_DIV_EXTERNAL.
  115. */
  116. if (ourhost->pdata->clk_type) {
  117. rate = clk_round_rate(clksrc, wanted);
  118. return wanted - rate;
  119. }
  120. rate = clk_get_rate(clksrc);
  121. for (div = 1; div < 256; div *= 2) {
  122. if ((rate / div) <= wanted)
  123. break;
  124. }
  125. dev_dbg(&ourhost->pdev->dev, "clk %d: rate %ld, want %d, got %ld\n",
  126. src, rate, wanted, rate / div);
  127. return (wanted - (rate / div));
  128. }
  129. /**
  130. * sdhci_s3c_set_clock - callback on clock change
  131. * @host: The SDHCI host being changed
  132. * @clock: The clock rate being requested.
  133. *
  134. * When the card's clock is going to be changed, look at the new frequency
  135. * and find the best clock source to go with it.
  136. */
  137. static void sdhci_s3c_set_clock(struct sdhci_host *host, unsigned int clock)
  138. {
  139. struct sdhci_s3c *ourhost = to_s3c(host);
  140. unsigned int best = UINT_MAX;
  141. unsigned int delta;
  142. int best_src = 0;
  143. int src;
  144. u32 ctrl;
  145. /* don't bother if the clock is going off. */
  146. if (clock == 0)
  147. return;
  148. for (src = 0; src < MAX_BUS_CLK; src++) {
  149. delta = sdhci_s3c_consider_clock(ourhost, src, clock);
  150. if (delta < best) {
  151. best = delta;
  152. best_src = src;
  153. }
  154. }
  155. dev_dbg(&ourhost->pdev->dev,
  156. "selected source %d, clock %d, delta %d\n",
  157. best_src, clock, best);
  158. /* select the new clock source */
  159. if (ourhost->cur_clk != best_src) {
  160. struct clk *clk = ourhost->clk_bus[best_src];
  161. /* turn clock off to card before changing clock source */
  162. writew(0, host->ioaddr + SDHCI_CLOCK_CONTROL);
  163. ourhost->cur_clk = best_src;
  164. host->max_clk = clk_get_rate(clk);
  165. ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2);
  166. ctrl &= ~S3C_SDHCI_CTRL2_SELBASECLK_MASK;
  167. ctrl |= best_src << S3C_SDHCI_CTRL2_SELBASECLK_SHIFT;
  168. writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL2);
  169. }
  170. /* reprogram default hardware configuration */
  171. writel(S3C64XX_SDHCI_CONTROL4_DRIVE_9mA,
  172. host->ioaddr + S3C64XX_SDHCI_CONTROL4);
  173. ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2);
  174. ctrl |= (S3C64XX_SDHCI_CTRL2_ENSTAASYNCCLR |
  175. S3C64XX_SDHCI_CTRL2_ENCMDCNFMSK |
  176. S3C_SDHCI_CTRL2_ENFBCLKRX |
  177. S3C_SDHCI_CTRL2_DFCNT_NONE |
  178. S3C_SDHCI_CTRL2_ENCLKOUTHOLD);
  179. writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL2);
  180. /* reconfigure the controller for new clock rate */
  181. ctrl = (S3C_SDHCI_CTRL3_FCSEL1 | S3C_SDHCI_CTRL3_FCSEL0);
  182. if (clock < 25 * 1000000)
  183. ctrl |= (S3C_SDHCI_CTRL3_FCSEL3 | S3C_SDHCI_CTRL3_FCSEL2);
  184. writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL3);
  185. }
  186. /**
  187. * sdhci_s3c_get_min_clock - callback to get minimal supported clock value
  188. * @host: The SDHCI host being queried
  189. *
  190. * To init mmc host properly a minimal clock value is needed. For high system
  191. * bus clock's values the standard formula gives values out of allowed range.
  192. * The clock still can be set to lower values, if clock source other then
  193. * system bus is selected.
  194. */
  195. static unsigned int sdhci_s3c_get_min_clock(struct sdhci_host *host)
  196. {
  197. struct sdhci_s3c *ourhost = to_s3c(host);
  198. unsigned int delta, min = UINT_MAX;
  199. int src;
  200. for (src = 0; src < MAX_BUS_CLK; src++) {
  201. delta = sdhci_s3c_consider_clock(ourhost, src, 0);
  202. if (delta == UINT_MAX)
  203. continue;
  204. /* delta is a negative value in this case */
  205. if (-delta < min)
  206. min = -delta;
  207. }
  208. return min;
  209. }
  210. /* sdhci_cmu_get_max_clk - callback to get maximum clock frequency.*/
  211. static unsigned int sdhci_cmu_get_max_clock(struct sdhci_host *host)
  212. {
  213. struct sdhci_s3c *ourhost = to_s3c(host);
  214. return clk_round_rate(ourhost->clk_bus[ourhost->cur_clk], UINT_MAX);
  215. }
  216. /* sdhci_cmu_get_min_clock - callback to get minimal supported clock value. */
  217. static unsigned int sdhci_cmu_get_min_clock(struct sdhci_host *host)
  218. {
  219. struct sdhci_s3c *ourhost = to_s3c(host);
  220. /*
  221. * initial clock can be in the frequency range of
  222. * 100KHz-400KHz, so we set it as max value.
  223. */
  224. return clk_round_rate(ourhost->clk_bus[ourhost->cur_clk], 400000);
  225. }
  226. /* sdhci_cmu_set_clock - callback on clock change.*/
  227. static void sdhci_cmu_set_clock(struct sdhci_host *host, unsigned int clock)
  228. {
  229. struct sdhci_s3c *ourhost = to_s3c(host);
  230. /* don't bother if the clock is going off */
  231. if (clock == 0)
  232. return;
  233. sdhci_s3c_set_clock(host, clock);
  234. clk_set_rate(ourhost->clk_bus[ourhost->cur_clk], clock);
  235. host->clock = clock;
  236. }
  237. /**
  238. * sdhci_s3c_platform_8bit_width - support 8bit buswidth
  239. * @host: The SDHCI host being queried
  240. * @width: MMC_BUS_WIDTH_ macro for the bus width being requested
  241. *
  242. * We have 8-bit width support but is not a v3 controller.
  243. * So we add platform_8bit_width() and support 8bit width.
  244. */
  245. static int sdhci_s3c_platform_8bit_width(struct sdhci_host *host, int width)
  246. {
  247. u8 ctrl;
  248. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  249. switch (width) {
  250. case MMC_BUS_WIDTH_8:
  251. ctrl |= SDHCI_CTRL_8BITBUS;
  252. ctrl &= ~SDHCI_CTRL_4BITBUS;
  253. break;
  254. case MMC_BUS_WIDTH_4:
  255. ctrl |= SDHCI_CTRL_4BITBUS;
  256. ctrl &= ~SDHCI_CTRL_8BITBUS;
  257. break;
  258. default:
  259. ctrl &= ~SDHCI_CTRL_4BITBUS;
  260. ctrl &= ~SDHCI_CTRL_8BITBUS;
  261. break;
  262. }
  263. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  264. return 0;
  265. }
  266. static struct sdhci_ops sdhci_s3c_ops = {
  267. .get_max_clock = sdhci_s3c_get_max_clk,
  268. .set_clock = sdhci_s3c_set_clock,
  269. .get_min_clock = sdhci_s3c_get_min_clock,
  270. .platform_8bit_width = sdhci_s3c_platform_8bit_width,
  271. };
  272. static void sdhci_s3c_notify_change(struct platform_device *dev, int state)
  273. {
  274. struct sdhci_host *host = platform_get_drvdata(dev);
  275. unsigned long flags;
  276. if (host) {
  277. spin_lock_irqsave(&host->lock, flags);
  278. if (state) {
  279. dev_dbg(&dev->dev, "card inserted.\n");
  280. host->flags &= ~SDHCI_DEVICE_DEAD;
  281. host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
  282. } else {
  283. dev_dbg(&dev->dev, "card removed.\n");
  284. host->flags |= SDHCI_DEVICE_DEAD;
  285. host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
  286. }
  287. tasklet_schedule(&host->card_tasklet);
  288. spin_unlock_irqrestore(&host->lock, flags);
  289. }
  290. }
  291. static irqreturn_t sdhci_s3c_gpio_card_detect_thread(int irq, void *dev_id)
  292. {
  293. struct sdhci_s3c *sc = dev_id;
  294. int status = gpio_get_value(sc->ext_cd_gpio);
  295. if (sc->pdata->ext_cd_gpio_invert)
  296. status = !status;
  297. sdhci_s3c_notify_change(sc->pdev, status);
  298. return IRQ_HANDLED;
  299. }
  300. static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc)
  301. {
  302. struct s3c_sdhci_platdata *pdata = sc->pdata;
  303. struct device *dev = &sc->pdev->dev;
  304. if (gpio_request(pdata->ext_cd_gpio, "SDHCI EXT CD") == 0) {
  305. sc->ext_cd_gpio = pdata->ext_cd_gpio;
  306. sc->ext_cd_irq = gpio_to_irq(pdata->ext_cd_gpio);
  307. if (sc->ext_cd_irq &&
  308. request_threaded_irq(sc->ext_cd_irq, NULL,
  309. sdhci_s3c_gpio_card_detect_thread,
  310. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  311. dev_name(dev), sc) == 0) {
  312. int status = gpio_get_value(sc->ext_cd_gpio);
  313. if (pdata->ext_cd_gpio_invert)
  314. status = !status;
  315. sdhci_s3c_notify_change(sc->pdev, status);
  316. } else {
  317. dev_warn(dev, "cannot request irq for card detect\n");
  318. sc->ext_cd_irq = 0;
  319. }
  320. } else {
  321. dev_err(dev, "cannot request gpio for card detect\n");
  322. }
  323. }
  324. static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
  325. {
  326. struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data;
  327. struct device *dev = &pdev->dev;
  328. struct sdhci_host *host;
  329. struct sdhci_s3c *sc;
  330. struct resource *res;
  331. int ret, irq, ptr, clks;
  332. if (!pdata) {
  333. dev_err(dev, "no device data specified\n");
  334. return -ENOENT;
  335. }
  336. irq = platform_get_irq(pdev, 0);
  337. if (irq < 0) {
  338. dev_err(dev, "no irq specified\n");
  339. return irq;
  340. }
  341. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  342. if (!res) {
  343. dev_err(dev, "no memory specified\n");
  344. return -ENOENT;
  345. }
  346. host = sdhci_alloc_host(dev, sizeof(struct sdhci_s3c));
  347. if (IS_ERR(host)) {
  348. dev_err(dev, "sdhci_alloc_host() failed\n");
  349. return PTR_ERR(host);
  350. }
  351. sc = sdhci_priv(host);
  352. sc->host = host;
  353. sc->pdev = pdev;
  354. sc->pdata = pdata;
  355. sc->ext_cd_gpio = -1; /* invalid gpio number */
  356. platform_set_drvdata(pdev, host);
  357. sc->clk_io = clk_get(dev, "hsmmc");
  358. if (IS_ERR(sc->clk_io)) {
  359. dev_err(dev, "failed to get io clock\n");
  360. ret = PTR_ERR(sc->clk_io);
  361. goto err_io_clk;
  362. }
  363. /* enable the local io clock and keep it running for the moment. */
  364. clk_enable(sc->clk_io);
  365. for (clks = 0, ptr = 0; ptr < MAX_BUS_CLK; ptr++) {
  366. struct clk *clk;
  367. char *name = pdata->clocks[ptr];
  368. if (name == NULL)
  369. continue;
  370. clk = clk_get(dev, name);
  371. if (IS_ERR(clk)) {
  372. dev_err(dev, "failed to get clock %s\n", name);
  373. continue;
  374. }
  375. clks++;
  376. sc->clk_bus[ptr] = clk;
  377. /*
  378. * save current clock index to know which clock bus
  379. * is used later in overriding functions.
  380. */
  381. sc->cur_clk = ptr;
  382. clk_enable(clk);
  383. dev_info(dev, "clock source %d: %s (%ld Hz)\n",
  384. ptr, name, clk_get_rate(clk));
  385. }
  386. if (clks == 0) {
  387. dev_err(dev, "failed to find any bus clocks\n");
  388. ret = -ENOENT;
  389. goto err_no_busclks;
  390. }
  391. sc->ioarea = request_mem_region(res->start, resource_size(res),
  392. mmc_hostname(host->mmc));
  393. if (!sc->ioarea) {
  394. dev_err(dev, "failed to reserve register area\n");
  395. ret = -ENXIO;
  396. goto err_req_regs;
  397. }
  398. host->ioaddr = ioremap_nocache(res->start, resource_size(res));
  399. if (!host->ioaddr) {
  400. dev_err(dev, "failed to map registers\n");
  401. ret = -ENXIO;
  402. goto err_req_regs;
  403. }
  404. /* Ensure we have minimal gpio selected CMD/CLK/Detect */
  405. if (pdata->cfg_gpio)
  406. pdata->cfg_gpio(pdev, pdata->max_width);
  407. host->hw_name = "samsung-hsmmc";
  408. host->ops = &sdhci_s3c_ops;
  409. host->quirks = 0;
  410. host->irq = irq;
  411. /* Setup quirks for the controller */
  412. host->quirks |= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC;
  413. host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT;
  414. #ifndef CONFIG_MMC_SDHCI_S3C_DMA
  415. /* we currently see overruns on errors, so disable the SDMA
  416. * support as well. */
  417. host->quirks |= SDHCI_QUIRK_BROKEN_DMA;
  418. #endif /* CONFIG_MMC_SDHCI_S3C_DMA */
  419. /* It seems we do not get an DATA transfer complete on non-busy
  420. * transfers, not sure if this is a problem with this specific
  421. * SDHCI block, or a missing configuration that needs to be set. */
  422. host->quirks |= SDHCI_QUIRK_NO_BUSY_IRQ;
  423. /* This host supports the Auto CMD12 */
  424. host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12;
  425. /* Samsung SoCs need BROKEN_ADMA_ZEROLEN_DESC */
  426. host->quirks |= SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC;
  427. if (pdata->cd_type == S3C_SDHCI_CD_NONE ||
  428. pdata->cd_type == S3C_SDHCI_CD_PERMANENT)
  429. host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
  430. if (pdata->cd_type == S3C_SDHCI_CD_PERMANENT)
  431. host->mmc->caps = MMC_CAP_NONREMOVABLE;
  432. if (pdata->host_caps)
  433. host->mmc->caps |= pdata->host_caps;
  434. host->quirks |= (SDHCI_QUIRK_32BIT_DMA_ADDR |
  435. SDHCI_QUIRK_32BIT_DMA_SIZE);
  436. /* HSMMC on Samsung SoCs uses SDCLK as timeout clock */
  437. host->quirks |= SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK;
  438. /*
  439. * If controller does not have internal clock divider,
  440. * we can use overriding functions instead of default.
  441. */
  442. if (pdata->clk_type) {
  443. sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
  444. sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
  445. sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
  446. }
  447. /* It supports additional host capabilities if needed */
  448. if (pdata->host_caps)
  449. host->mmc->caps |= pdata->host_caps;
  450. ret = sdhci_add_host(host);
  451. if (ret) {
  452. dev_err(dev, "sdhci_add_host() failed\n");
  453. goto err_add_host;
  454. }
  455. /* The following two methods of card detection might call
  456. sdhci_s3c_notify_change() immediately, so they can be called
  457. only after sdhci_add_host(). Setup errors are ignored. */
  458. if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_init)
  459. pdata->ext_cd_init(&sdhci_s3c_notify_change);
  460. if (pdata->cd_type == S3C_SDHCI_CD_GPIO &&
  461. gpio_is_valid(pdata->ext_cd_gpio))
  462. sdhci_s3c_setup_card_detect_gpio(sc);
  463. return 0;
  464. err_add_host:
  465. release_resource(sc->ioarea);
  466. kfree(sc->ioarea);
  467. err_req_regs:
  468. for (ptr = 0; ptr < MAX_BUS_CLK; ptr++) {
  469. if (sc->clk_bus[ptr]) {
  470. clk_disable(sc->clk_bus[ptr]);
  471. clk_put(sc->clk_bus[ptr]);
  472. }
  473. }
  474. err_no_busclks:
  475. clk_disable(sc->clk_io);
  476. clk_put(sc->clk_io);
  477. err_io_clk:
  478. sdhci_free_host(host);
  479. return ret;
  480. }
  481. static int __devexit sdhci_s3c_remove(struct platform_device *pdev)
  482. {
  483. struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data;
  484. struct sdhci_host *host = platform_get_drvdata(pdev);
  485. struct sdhci_s3c *sc = sdhci_priv(host);
  486. int ptr;
  487. if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_cleanup)
  488. pdata->ext_cd_cleanup(&sdhci_s3c_notify_change);
  489. if (sc->ext_cd_irq)
  490. free_irq(sc->ext_cd_irq, sc);
  491. if (gpio_is_valid(sc->ext_cd_gpio))
  492. gpio_free(sc->ext_cd_gpio);
  493. sdhci_remove_host(host, 1);
  494. for (ptr = 0; ptr < 3; ptr++) {
  495. if (sc->clk_bus[ptr]) {
  496. clk_disable(sc->clk_bus[ptr]);
  497. clk_put(sc->clk_bus[ptr]);
  498. }
  499. }
  500. clk_disable(sc->clk_io);
  501. clk_put(sc->clk_io);
  502. iounmap(host->ioaddr);
  503. release_resource(sc->ioarea);
  504. kfree(sc->ioarea);
  505. sdhci_free_host(host);
  506. platform_set_drvdata(pdev, NULL);
  507. return 0;
  508. }
  509. #ifdef CONFIG_PM
  510. static int sdhci_s3c_suspend(struct platform_device *dev, pm_message_t pm)
  511. {
  512. struct sdhci_host *host = platform_get_drvdata(dev);
  513. return sdhci_suspend_host(host, pm);
  514. }
  515. static int sdhci_s3c_resume(struct platform_device *dev)
  516. {
  517. struct sdhci_host *host = platform_get_drvdata(dev);
  518. return sdhci_resume_host(host);
  519. }
  520. #else
  521. #define sdhci_s3c_suspend NULL
  522. #define sdhci_s3c_resume NULL
  523. #endif
  524. static struct platform_driver sdhci_s3c_driver = {
  525. .probe = sdhci_s3c_probe,
  526. .remove = __devexit_p(sdhci_s3c_remove),
  527. .suspend = sdhci_s3c_suspend,
  528. .resume = sdhci_s3c_resume,
  529. .driver = {
  530. .owner = THIS_MODULE,
  531. .name = "s3c-sdhci",
  532. },
  533. };
  534. static int __init sdhci_s3c_init(void)
  535. {
  536. return platform_driver_register(&sdhci_s3c_driver);
  537. }
  538. static void __exit sdhci_s3c_exit(void)
  539. {
  540. platform_driver_unregister(&sdhci_s3c_driver);
  541. }
  542. module_init(sdhci_s3c_init);
  543. module_exit(sdhci_s3c_exit);
  544. MODULE_DESCRIPTION("Samsung SDHCI (HSMMC) glue");
  545. MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
  546. MODULE_LICENSE("GPL v2");
  547. MODULE_ALIAS("platform:s3c-sdhci");