sdhci-s3c.c 19 KB

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