blob: 8cd999f4af58044f00958df94652b79aff7cb513 [file] [log] [blame]
Ben Dooks0d1bb412009-06-14 13:52:37 +01001/* 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
15#include <linux/delay.h>
16#include <linux/dma-mapping.h>
17#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Ben Dooks0d1bb412009-06-14 13:52:37 +010019#include <linux/clk.h>
20#include <linux/io.h>
Marek Szyprowski17866e12010-08-10 18:01:58 -070021#include <linux/gpio.h>
Ben Dooks0d1bb412009-06-14 13:52:37 +010022
23#include <linux/mmc/host.h>
24
25#include <plat/sdhci.h>
26#include <plat/regs-sdhci.h>
27
28#include "sdhci.h"
29
30#define MAX_BUS_CLK (4)
31
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 */
42struct sdhci_s3c {
43 struct sdhci_host *host;
44 struct platform_device *pdev;
45 struct resource *ioarea;
46 struct s3c_sdhci_platdata *pdata;
47 unsigned int cur_clk;
Marek Szyprowski17866e12010-08-10 18:01:58 -070048 int ext_cd_irq;
49 int ext_cd_gpio;
Ben Dooks0d1bb412009-06-14 13:52:37 +010050
51 struct clk *clk_io;
52 struct clk *clk_bus[MAX_BUS_CLK];
53};
54
55static inline struct sdhci_s3c *to_s3c(struct sdhci_host *host)
56{
57 return sdhci_priv(host);
58}
59
60/**
61 * get_curclk - convert ctrl2 register to clock source number
62 * @ctrl2: Control2 register value.
63 */
64static u32 get_curclk(u32 ctrl2)
65{
66 ctrl2 &= S3C_SDHCI_CTRL2_SELBASECLK_MASK;
67 ctrl2 >>= S3C_SDHCI_CTRL2_SELBASECLK_SHIFT;
68
69 return ctrl2;
70}
71
72static void sdhci_s3c_check_sclk(struct sdhci_host *host)
73{
74 struct sdhci_s3c *ourhost = to_s3c(host);
75 u32 tmp = readl(host->ioaddr + S3C_SDHCI_CONTROL2);
76
77 if (get_curclk(tmp) != ourhost->cur_clk) {
78 dev_dbg(&ourhost->pdev->dev, "restored ctrl2 clock setting\n");
79
80 tmp &= ~S3C_SDHCI_CTRL2_SELBASECLK_MASK;
81 tmp |= ourhost->cur_clk << S3C_SDHCI_CTRL2_SELBASECLK_SHIFT;
82 writel(tmp, host->ioaddr + 0x80);
83 }
84}
85
86/**
87 * sdhci_s3c_get_max_clk - callback to get maximum clock frequency.
88 * @host: The SDHCI host instance.
89 *
90 * Callback to return the maximum clock rate acheivable by the controller.
91*/
92static unsigned int sdhci_s3c_get_max_clk(struct sdhci_host *host)
93{
94 struct sdhci_s3c *ourhost = to_s3c(host);
95 struct clk *busclk;
96 unsigned int rate, max;
97 int clk;
98
99 /* note, a reset will reset the clock source */
100
101 sdhci_s3c_check_sclk(host);
102
103 for (max = 0, clk = 0; clk < MAX_BUS_CLK; clk++) {
104 busclk = ourhost->clk_bus[clk];
105 if (!busclk)
106 continue;
107
108 rate = clk_get_rate(busclk);
109 if (rate > max)
110 max = rate;
111 }
112
113 return max;
114}
115
Ben Dooks0d1bb412009-06-14 13:52:37 +0100116/**
117 * sdhci_s3c_consider_clock - consider one the bus clocks for current setting
118 * @ourhost: Our SDHCI instance.
119 * @src: The source clock index.
120 * @wanted: The clock frequency wanted.
121 */
122static unsigned int sdhci_s3c_consider_clock(struct sdhci_s3c *ourhost,
123 unsigned int src,
124 unsigned int wanted)
125{
126 unsigned long rate;
127 struct clk *clksrc = ourhost->clk_bus[src];
128 int div;
129
130 if (!clksrc)
131 return UINT_MAX;
132
Jeongbae Seo253e0a72010-10-08 17:46:21 +0900133 /*
134 * Clock divider's step is different as 1 from that of host controller
135 * when 'clk_type' is S3C_SDHCI_CLK_DIV_EXTERNAL.
136 */
137 if (ourhost->pdata->clk_type) {
138 rate = clk_round_rate(clksrc, wanted);
139 return wanted - rate;
140 }
141
Ben Dooks0d1bb412009-06-14 13:52:37 +0100142 rate = clk_get_rate(clksrc);
143
144 for (div = 1; div < 256; div *= 2) {
145 if ((rate / div) <= wanted)
146 break;
147 }
148
149 dev_dbg(&ourhost->pdev->dev, "clk %d: rate %ld, want %d, got %ld\n",
150 src, rate, wanted, rate / div);
151
152 return (wanted - (rate / div));
153}
154
155/**
156 * sdhci_s3c_set_clock - callback on clock change
157 * @host: The SDHCI host being changed
158 * @clock: The clock rate being requested.
159 *
160 * When the card's clock is going to be changed, look at the new frequency
161 * and find the best clock source to go with it.
162*/
163static void sdhci_s3c_set_clock(struct sdhci_host *host, unsigned int clock)
164{
165 struct sdhci_s3c *ourhost = to_s3c(host);
166 unsigned int best = UINT_MAX;
167 unsigned int delta;
168 int best_src = 0;
169 int src;
170 u32 ctrl;
171
172 /* don't bother if the clock is going off. */
173 if (clock == 0)
174 return;
175
176 for (src = 0; src < MAX_BUS_CLK; src++) {
177 delta = sdhci_s3c_consider_clock(ourhost, src, clock);
178 if (delta < best) {
179 best = delta;
180 best_src = src;
181 }
182 }
183
184 dev_dbg(&ourhost->pdev->dev,
185 "selected source %d, clock %d, delta %d\n",
186 best_src, clock, best);
187
188 /* select the new clock source */
189
190 if (ourhost->cur_clk != best_src) {
191 struct clk *clk = ourhost->clk_bus[best_src];
192
193 /* turn clock off to card before changing clock source */
194 writew(0, host->ioaddr + SDHCI_CLOCK_CONTROL);
195
196 ourhost->cur_clk = best_src;
197 host->max_clk = clk_get_rate(clk);
Ben Dooks0d1bb412009-06-14 13:52:37 +0100198
199 ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2);
200 ctrl &= ~S3C_SDHCI_CTRL2_SELBASECLK_MASK;
201 ctrl |= best_src << S3C_SDHCI_CTRL2_SELBASECLK_SHIFT;
202 writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL2);
203 }
204
205 /* reconfigure the hardware for new clock rate */
206
207 {
208 struct mmc_ios ios;
209
210 ios.clock = clock;
211
212 if (ourhost->pdata->cfg_card)
213 (ourhost->pdata->cfg_card)(ourhost->pdev, host->ioaddr,
214 &ios, NULL);
215 }
216}
217
Marek Szyprowskice5f0362010-08-10 18:01:56 -0700218/**
219 * sdhci_s3c_get_min_clock - callback to get minimal supported clock value
220 * @host: The SDHCI host being queried
221 *
222 * To init mmc host properly a minimal clock value is needed. For high system
223 * bus clock's values the standard formula gives values out of allowed range.
224 * The clock still can be set to lower values, if clock source other then
225 * system bus is selected.
226*/
227static unsigned int sdhci_s3c_get_min_clock(struct sdhci_host *host)
228{
229 struct sdhci_s3c *ourhost = to_s3c(host);
230 unsigned int delta, min = UINT_MAX;
231 int src;
232
233 for (src = 0; src < MAX_BUS_CLK; src++) {
234 delta = sdhci_s3c_consider_clock(ourhost, src, 0);
235 if (delta == UINT_MAX)
236 continue;
237 /* delta is a negative value in this case */
238 if (-delta < min)
239 min = -delta;
240 }
241 return min;
242}
243
Jeongbae Seo253e0a72010-10-08 17:46:21 +0900244/* sdhci_cmu_get_max_clk - callback to get maximum clock frequency.*/
245static unsigned int sdhci_cmu_get_max_clock(struct sdhci_host *host)
246{
247 struct sdhci_s3c *ourhost = to_s3c(host);
248
249 return clk_round_rate(ourhost->clk_bus[ourhost->cur_clk], UINT_MAX);
250}
251
252/* sdhci_cmu_get_min_clock - callback to get minimal supported clock value. */
253static unsigned int sdhci_cmu_get_min_clock(struct sdhci_host *host)
254{
255 struct sdhci_s3c *ourhost = to_s3c(host);
256
257 /*
258 * initial clock can be in the frequency range of
259 * 100KHz-400KHz, so we set it as max value.
260 */
261 return clk_round_rate(ourhost->clk_bus[ourhost->cur_clk], 400000);
262}
263
264/* sdhci_cmu_set_clock - callback on clock change.*/
265static void sdhci_cmu_set_clock(struct sdhci_host *host, unsigned int clock)
266{
267 struct sdhci_s3c *ourhost = to_s3c(host);
268
269 /* don't bother if the clock is going off */
270 if (clock == 0)
271 return;
272
273 sdhci_s3c_set_clock(host, clock);
274
275 clk_set_rate(ourhost->clk_bus[ourhost->cur_clk], clock);
276
277 host->clock = clock;
278}
279
Jaehoon Chung548f07d2011-01-12 11:59:12 +0900280/**
281 * sdhci_s3c_platform_8bit_width - support 8bit buswidth
282 * @host: The SDHCI host being queried
283 * @width: MMC_BUS_WIDTH_ macro for the bus width being requested
284 *
285 * We have 8-bit width support but is not a v3 controller.
286 * So we add platform_8bit_width() and support 8bit width.
287 */
288static int sdhci_s3c_platform_8bit_width(struct sdhci_host *host, int width)
289{
290 u8 ctrl;
291
292 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
293
294 switch (width) {
295 case MMC_BUS_WIDTH_8:
296 ctrl |= SDHCI_CTRL_8BITBUS;
297 ctrl &= ~SDHCI_CTRL_4BITBUS;
298 break;
299 case MMC_BUS_WIDTH_4:
300 ctrl |= SDHCI_CTRL_4BITBUS;
301 ctrl &= ~SDHCI_CTRL_8BITBUS;
302 break;
303 default:
Girish K S1c72a512011-08-26 14:58:18 +0530304 ctrl &= ~SDHCI_CTRL_4BITBUS;
305 ctrl &= ~SDHCI_CTRL_8BITBUS;
Jaehoon Chung548f07d2011-01-12 11:59:12 +0900306 break;
307 }
308
309 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
310
311 return 0;
312}
313
Ben Dooks0d1bb412009-06-14 13:52:37 +0100314static struct sdhci_ops sdhci_s3c_ops = {
315 .get_max_clock = sdhci_s3c_get_max_clk,
Ben Dooks0d1bb412009-06-14 13:52:37 +0100316 .set_clock = sdhci_s3c_set_clock,
Marek Szyprowskice5f0362010-08-10 18:01:56 -0700317 .get_min_clock = sdhci_s3c_get_min_clock,
Jaehoon Chung548f07d2011-01-12 11:59:12 +0900318 .platform_8bit_width = sdhci_s3c_platform_8bit_width,
Ben Dooks0d1bb412009-06-14 13:52:37 +0100319};
320
Marek Szyprowski17866e12010-08-10 18:01:58 -0700321static void sdhci_s3c_notify_change(struct platform_device *dev, int state)
322{
323 struct sdhci_host *host = platform_get_drvdata(dev);
Marek Szyprowski06fe5772010-09-20 15:03:42 +0200324 unsigned long flags;
325
Marek Szyprowski17866e12010-08-10 18:01:58 -0700326 if (host) {
Marek Szyprowski06fe5772010-09-20 15:03:42 +0200327 spin_lock_irqsave(&host->lock, flags);
Marek Szyprowski17866e12010-08-10 18:01:58 -0700328 if (state) {
329 dev_dbg(&dev->dev, "card inserted.\n");
330 host->flags &= ~SDHCI_DEVICE_DEAD;
331 host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
332 } else {
333 dev_dbg(&dev->dev, "card removed.\n");
334 host->flags |= SDHCI_DEVICE_DEAD;
335 host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
336 }
Kyungmin Parkf5228862010-08-19 14:13:37 -0700337 tasklet_schedule(&host->card_tasklet);
Marek Szyprowski06fe5772010-09-20 15:03:42 +0200338 spin_unlock_irqrestore(&host->lock, flags);
Marek Szyprowski17866e12010-08-10 18:01:58 -0700339 }
340}
341
342static irqreturn_t sdhci_s3c_gpio_card_detect_thread(int irq, void *dev_id)
343{
344 struct sdhci_s3c *sc = dev_id;
345 int status = gpio_get_value(sc->ext_cd_gpio);
346 if (sc->pdata->ext_cd_gpio_invert)
347 status = !status;
348 sdhci_s3c_notify_change(sc->pdev, status);
349 return IRQ_HANDLED;
350}
351
352static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc)
353{
354 struct s3c_sdhci_platdata *pdata = sc->pdata;
355 struct device *dev = &sc->pdev->dev;
356
357 if (gpio_request(pdata->ext_cd_gpio, "SDHCI EXT CD") == 0) {
358 sc->ext_cd_gpio = pdata->ext_cd_gpio;
359 sc->ext_cd_irq = gpio_to_irq(pdata->ext_cd_gpio);
360 if (sc->ext_cd_irq &&
361 request_threaded_irq(sc->ext_cd_irq, NULL,
362 sdhci_s3c_gpio_card_detect_thread,
363 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
364 dev_name(dev), sc) == 0) {
365 int status = gpio_get_value(sc->ext_cd_gpio);
366 if (pdata->ext_cd_gpio_invert)
367 status = !status;
368 sdhci_s3c_notify_change(sc->pdev, status);
369 } else {
370 dev_warn(dev, "cannot request irq for card detect\n");
371 sc->ext_cd_irq = 0;
372 }
373 } else {
374 dev_err(dev, "cannot request gpio for card detect\n");
375 }
376}
377
Ben Dooks0d1bb412009-06-14 13:52:37 +0100378static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
379{
380 struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data;
381 struct device *dev = &pdev->dev;
382 struct sdhci_host *host;
383 struct sdhci_s3c *sc;
384 struct resource *res;
385 int ret, irq, ptr, clks;
386
387 if (!pdata) {
388 dev_err(dev, "no device data specified\n");
389 return -ENOENT;
390 }
391
392 irq = platform_get_irq(pdev, 0);
393 if (irq < 0) {
394 dev_err(dev, "no irq specified\n");
395 return irq;
396 }
397
398 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
399 if (!res) {
400 dev_err(dev, "no memory specified\n");
401 return -ENOENT;
402 }
403
404 host = sdhci_alloc_host(dev, sizeof(struct sdhci_s3c));
405 if (IS_ERR(host)) {
406 dev_err(dev, "sdhci_alloc_host() failed\n");
407 return PTR_ERR(host);
408 }
409
410 sc = sdhci_priv(host);
411
412 sc->host = host;
413 sc->pdev = pdev;
414 sc->pdata = pdata;
Marek Szyprowski17866e12010-08-10 18:01:58 -0700415 sc->ext_cd_gpio = -1; /* invalid gpio number */
Ben Dooks0d1bb412009-06-14 13:52:37 +0100416
417 platform_set_drvdata(pdev, host);
418
419 sc->clk_io = clk_get(dev, "hsmmc");
420 if (IS_ERR(sc->clk_io)) {
421 dev_err(dev, "failed to get io clock\n");
422 ret = PTR_ERR(sc->clk_io);
423 goto err_io_clk;
424 }
425
426 /* enable the local io clock and keep it running for the moment. */
427 clk_enable(sc->clk_io);
428
429 for (clks = 0, ptr = 0; ptr < MAX_BUS_CLK; ptr++) {
430 struct clk *clk;
431 char *name = pdata->clocks[ptr];
432
433 if (name == NULL)
434 continue;
435
436 clk = clk_get(dev, name);
437 if (IS_ERR(clk)) {
438 dev_err(dev, "failed to get clock %s\n", name);
439 continue;
440 }
441
442 clks++;
443 sc->clk_bus[ptr] = clk;
Jeongbae Seo253e0a72010-10-08 17:46:21 +0900444
445 /*
446 * save current clock index to know which clock bus
447 * is used later in overriding functions.
448 */
449 sc->cur_clk = ptr;
450
Ben Dooks0d1bb412009-06-14 13:52:37 +0100451 clk_enable(clk);
452
453 dev_info(dev, "clock source %d: %s (%ld Hz)\n",
454 ptr, name, clk_get_rate(clk));
455 }
456
457 if (clks == 0) {
458 dev_err(dev, "failed to find any bus clocks\n");
459 ret = -ENOENT;
460 goto err_no_busclks;
461 }
462
463 sc->ioarea = request_mem_region(res->start, resource_size(res),
464 mmc_hostname(host->mmc));
465 if (!sc->ioarea) {
466 dev_err(dev, "failed to reserve register area\n");
467 ret = -ENXIO;
468 goto err_req_regs;
469 }
470
471 host->ioaddr = ioremap_nocache(res->start, resource_size(res));
472 if (!host->ioaddr) {
473 dev_err(dev, "failed to map registers\n");
474 ret = -ENXIO;
475 goto err_req_regs;
476 }
477
478 /* Ensure we have minimal gpio selected CMD/CLK/Detect */
479 if (pdata->cfg_gpio)
480 pdata->cfg_gpio(pdev, pdata->max_width);
481
482 host->hw_name = "samsung-hsmmc";
483 host->ops = &sdhci_s3c_ops;
484 host->quirks = 0;
485 host->irq = irq;
486
487 /* Setup quirks for the controller */
Thomas Abrahamb2e75ef2010-05-26 14:42:05 -0700488 host->quirks |= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC;
Marek Szyprowskia1d56462010-08-10 18:01:57 -0700489 host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT;
Ben Dooks0d1bb412009-06-14 13:52:37 +0100490
491#ifndef CONFIG_MMC_SDHCI_S3C_DMA
492
493 /* we currently see overruns on errors, so disable the SDMA
494 * support as well. */
495 host->quirks |= SDHCI_QUIRK_BROKEN_DMA;
496
Ben Dooks0d1bb412009-06-14 13:52:37 +0100497#endif /* CONFIG_MMC_SDHCI_S3C_DMA */
498
499 /* It seems we do not get an DATA transfer complete on non-busy
500 * transfers, not sure if this is a problem with this specific
501 * SDHCI block, or a missing configuration that needs to be set. */
502 host->quirks |= SDHCI_QUIRK_NO_BUSY_IRQ;
503
Kyungmin Park732f0e32010-10-30 12:58:56 +0900504 /* This host supports the Auto CMD12 */
505 host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12;
506
Marek Szyprowski17866e12010-08-10 18:01:58 -0700507 if (pdata->cd_type == S3C_SDHCI_CD_NONE ||
508 pdata->cd_type == S3C_SDHCI_CD_PERMANENT)
509 host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
510
511 if (pdata->cd_type == S3C_SDHCI_CD_PERMANENT)
512 host->mmc->caps = MMC_CAP_NONREMOVABLE;
513
Jaehoon Chung548f07d2011-01-12 11:59:12 +0900514 if (pdata->host_caps)
515 host->mmc->caps |= pdata->host_caps;
516
Ben Dooks0d1bb412009-06-14 13:52:37 +0100517 host->quirks |= (SDHCI_QUIRK_32BIT_DMA_ADDR |
518 SDHCI_QUIRK_32BIT_DMA_SIZE);
519
Hyuk Lee3fe42e02010-08-10 18:01:55 -0700520 /* HSMMC on Samsung SoCs uses SDCLK as timeout clock */
521 host->quirks |= SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK;
522
Jeongbae Seo253e0a72010-10-08 17:46:21 +0900523 /*
524 * If controller does not have internal clock divider,
525 * we can use overriding functions instead of default.
526 */
527 if (pdata->clk_type) {
528 sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
529 sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
530 sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
531 }
532
Jeongbae Seob3824f22010-10-08 17:46:20 +0900533 /* It supports additional host capabilities if needed */
534 if (pdata->host_caps)
535 host->mmc->caps |= pdata->host_caps;
536
Ben Dooks0d1bb412009-06-14 13:52:37 +0100537 ret = sdhci_add_host(host);
538 if (ret) {
539 dev_err(dev, "sdhci_add_host() failed\n");
540 goto err_add_host;
541 }
542
Marek Szyprowski17866e12010-08-10 18:01:58 -0700543 /* The following two methods of card detection might call
544 sdhci_s3c_notify_change() immediately, so they can be called
545 only after sdhci_add_host(). Setup errors are ignored. */
546 if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_init)
547 pdata->ext_cd_init(&sdhci_s3c_notify_change);
548 if (pdata->cd_type == S3C_SDHCI_CD_GPIO &&
549 gpio_is_valid(pdata->ext_cd_gpio))
550 sdhci_s3c_setup_card_detect_gpio(sc);
551
Ben Dooks0d1bb412009-06-14 13:52:37 +0100552 return 0;
553
554 err_add_host:
555 release_resource(sc->ioarea);
556 kfree(sc->ioarea);
557
558 err_req_regs:
559 for (ptr = 0; ptr < MAX_BUS_CLK; ptr++) {
560 clk_disable(sc->clk_bus[ptr]);
561 clk_put(sc->clk_bus[ptr]);
562 }
563
564 err_no_busclks:
565 clk_disable(sc->clk_io);
566 clk_put(sc->clk_io);
567
568 err_io_clk:
569 sdhci_free_host(host);
570
571 return ret;
572}
573
574static int __devexit sdhci_s3c_remove(struct platform_device *pdev)
575{
Marek Szyprowski17866e12010-08-10 18:01:58 -0700576 struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data;
Marek Szyprowski9d51a6b2010-07-20 13:24:33 -0700577 struct sdhci_host *host = platform_get_drvdata(pdev);
578 struct sdhci_s3c *sc = sdhci_priv(host);
579 int ptr;
580
Marek Szyprowski17866e12010-08-10 18:01:58 -0700581 if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_cleanup)
582 pdata->ext_cd_cleanup(&sdhci_s3c_notify_change);
583
584 if (sc->ext_cd_irq)
585 free_irq(sc->ext_cd_irq, sc);
586
587 if (gpio_is_valid(sc->ext_cd_gpio))
588 gpio_free(sc->ext_cd_gpio);
589
Marek Szyprowski9d51a6b2010-07-20 13:24:33 -0700590 sdhci_remove_host(host, 1);
591
592 for (ptr = 0; ptr < 3; ptr++) {
Marek Szyprowski9320f7c2010-09-23 16:22:05 +0200593 if (sc->clk_bus[ptr]) {
594 clk_disable(sc->clk_bus[ptr]);
595 clk_put(sc->clk_bus[ptr]);
596 }
Marek Szyprowski9d51a6b2010-07-20 13:24:33 -0700597 }
598 clk_disable(sc->clk_io);
599 clk_put(sc->clk_io);
600
601 iounmap(host->ioaddr);
602 release_resource(sc->ioarea);
603 kfree(sc->ioarea);
604
605 sdhci_free_host(host);
606 platform_set_drvdata(pdev, NULL);
607
Ben Dooks0d1bb412009-06-14 13:52:37 +0100608 return 0;
609}
610
611#ifdef CONFIG_PM
612
613static int sdhci_s3c_suspend(struct platform_device *dev, pm_message_t pm)
614{
615 struct sdhci_host *host = platform_get_drvdata(dev);
616
617 sdhci_suspend_host(host, pm);
618 return 0;
619}
620
621static int sdhci_s3c_resume(struct platform_device *dev)
622{
623 struct sdhci_host *host = platform_get_drvdata(dev);
624
625 sdhci_resume_host(host);
626 return 0;
627}
628
629#else
630#define sdhci_s3c_suspend NULL
631#define sdhci_s3c_resume NULL
632#endif
633
634static struct platform_driver sdhci_s3c_driver = {
635 .probe = sdhci_s3c_probe,
636 .remove = __devexit_p(sdhci_s3c_remove),
637 .suspend = sdhci_s3c_suspend,
638 .resume = sdhci_s3c_resume,
639 .driver = {
640 .owner = THIS_MODULE,
641 .name = "s3c-sdhci",
642 },
643};
644
645static int __init sdhci_s3c_init(void)
646{
647 return platform_driver_register(&sdhci_s3c_driver);
648}
649
650static void __exit sdhci_s3c_exit(void)
651{
652 platform_driver_unregister(&sdhci_s3c_driver);
653}
654
655module_init(sdhci_s3c_init);
656module_exit(sdhci_s3c_exit);
657
658MODULE_DESCRIPTION("Samsung SDHCI (HSMMC) glue");
659MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
660MODULE_LICENSE("GPL v2");
661MODULE_ALIAS("platform:s3c-sdhci");