sdhci-s3c.c 18 KB

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