1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
29#include <linux/mmc/host.h>
30
31#include "sdhci-s3c-regs.h"
32#include "sdhci.h"
33
34#define MAX_BUS_CLK (4)
35
36
37#define NUM_GPIOS(x) (x + 2)
38
39
40
41
42
43
44
45
46
47
48
49struct sdhci_s3c {
50 struct sdhci_host *host;
51 struct platform_device *pdev;
52 struct resource *ioarea;
53 struct s3c_sdhci_platdata *pdata;
54 unsigned int cur_clk;
55 int ext_cd_irq;
56 int ext_cd_gpio;
57
58 struct clk *clk_io;
59 struct clk *clk_bus[MAX_BUS_CLK];
60};
61
62
63
64
65
66
67
68
69
70struct sdhci_s3c_drv_data {
71 unsigned int sdhci_quirks;
72};
73
74static inline struct sdhci_s3c *to_s3c(struct sdhci_host *host)
75{
76 return sdhci_priv(host);
77}
78
79
80
81
82
83static u32 get_curclk(u32 ctrl2)
84{
85 ctrl2 &= S3C_SDHCI_CTRL2_SELBASECLK_MASK;
86 ctrl2 >>= S3C_SDHCI_CTRL2_SELBASECLK_SHIFT;
87
88 return ctrl2;
89}
90
91static void sdhci_s3c_check_sclk(struct sdhci_host *host)
92{
93 struct sdhci_s3c *ourhost = to_s3c(host);
94 u32 tmp = readl(host->ioaddr + S3C_SDHCI_CONTROL2);
95
96 if (get_curclk(tmp) != ourhost->cur_clk) {
97 dev_dbg(&ourhost->pdev->dev, "restored ctrl2 clock setting\n");
98
99 tmp &= ~S3C_SDHCI_CTRL2_SELBASECLK_MASK;
100 tmp |= ourhost->cur_clk << S3C_SDHCI_CTRL2_SELBASECLK_SHIFT;
101 writel(tmp, host->ioaddr + S3C_SDHCI_CONTROL2);
102 }
103}
104
105
106
107
108
109
110
111static unsigned int sdhci_s3c_get_max_clk(struct sdhci_host *host)
112{
113 struct sdhci_s3c *ourhost = to_s3c(host);
114 struct clk *busclk;
115 unsigned int rate, max;
116 int clk;
117
118
119
120 sdhci_s3c_check_sclk(host);
121
122 for (max = 0, clk = 0; clk < MAX_BUS_CLK; clk++) {
123 busclk = ourhost->clk_bus[clk];
124 if (!busclk)
125 continue;
126
127 rate = clk_get_rate(busclk);
128 if (rate > max)
129 max = rate;
130 }
131
132 return max;
133}
134
135
136
137
138
139
140
141static unsigned int sdhci_s3c_consider_clock(struct sdhci_s3c *ourhost,
142 unsigned int src,
143 unsigned int wanted)
144{
145 unsigned long rate;
146 struct clk *clksrc = ourhost->clk_bus[src];
147 int div;
148
149 if (!clksrc)
150 return UINT_MAX;
151
152
153
154
155
156 if (ourhost->host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
157 rate = clk_round_rate(clksrc, wanted);
158 return wanted - rate;
159 }
160
161 rate = clk_get_rate(clksrc);
162
163 for (div = 1; div < 256; div *= 2) {
164 if ((rate / div) <= wanted)
165 break;
166 }
167
168 dev_dbg(&ourhost->pdev->dev, "clk %d: rate %ld, want %d, got %ld\n",
169 src, rate, wanted, rate / div);
170
171 return wanted - (rate / div);
172}
173
174
175
176
177
178
179
180
181
182static void sdhci_s3c_set_clock(struct sdhci_host *host, unsigned int clock)
183{
184 struct sdhci_s3c *ourhost = to_s3c(host);
185 unsigned int best = UINT_MAX;
186 unsigned int delta;
187 int best_src = 0;
188 int src;
189 u32 ctrl;
190
191
192 if (clock == 0)
193 return;
194
195 for (src = 0; src < MAX_BUS_CLK; src++) {
196 delta = sdhci_s3c_consider_clock(ourhost, src, clock);
197 if (delta < best) {
198 best = delta;
199 best_src = src;
200 }
201 }
202
203 dev_dbg(&ourhost->pdev->dev,
204 "selected source %d, clock %d, delta %d\n",
205 best_src, clock, best);
206
207
208 if (ourhost->cur_clk != best_src) {
209 struct clk *clk = ourhost->clk_bus[best_src];
210
211 clk_prepare_enable(clk);
212 clk_disable_unprepare(ourhost->clk_bus[ourhost->cur_clk]);
213
214
215 writew(0, host->ioaddr + SDHCI_CLOCK_CONTROL);
216
217 ourhost->cur_clk = best_src;
218 host->max_clk = clk_get_rate(clk);
219
220 ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2);
221 ctrl &= ~S3C_SDHCI_CTRL2_SELBASECLK_MASK;
222 ctrl |= best_src << S3C_SDHCI_CTRL2_SELBASECLK_SHIFT;
223 writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL2);
224 }
225
226
227 writel(S3C64XX_SDHCI_CONTROL4_DRIVE_9mA,
228 host->ioaddr + S3C64XX_SDHCI_CONTROL4);
229
230 ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2);
231 ctrl |= (S3C64XX_SDHCI_CTRL2_ENSTAASYNCCLR |
232 S3C64XX_SDHCI_CTRL2_ENCMDCNFMSK |
233 S3C_SDHCI_CTRL2_ENFBCLKRX |
234 S3C_SDHCI_CTRL2_DFCNT_NONE |
235 S3C_SDHCI_CTRL2_ENCLKOUTHOLD);
236 writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL2);
237
238
239 ctrl = (S3C_SDHCI_CTRL3_FCSEL1 | S3C_SDHCI_CTRL3_FCSEL0);
240 if (clock < 25 * 1000000)
241 ctrl |= (S3C_SDHCI_CTRL3_FCSEL3 | S3C_SDHCI_CTRL3_FCSEL2);
242 writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL3);
243}
244
245
246
247
248
249
250
251
252
253
254static unsigned int sdhci_s3c_get_min_clock(struct sdhci_host *host)
255{
256 struct sdhci_s3c *ourhost = to_s3c(host);
257 unsigned int delta, min = UINT_MAX;
258 int src;
259
260 for (src = 0; src < MAX_BUS_CLK; src++) {
261 delta = sdhci_s3c_consider_clock(ourhost, src, 0);
262 if (delta == UINT_MAX)
263 continue;
264
265 if (-delta < min)
266 min = -delta;
267 }
268 return min;
269}
270
271
272static unsigned int sdhci_cmu_get_max_clock(struct sdhci_host *host)
273{
274 struct sdhci_s3c *ourhost = to_s3c(host);
275
276 return clk_round_rate(ourhost->clk_bus[ourhost->cur_clk], UINT_MAX);
277}
278
279
280static unsigned int sdhci_cmu_get_min_clock(struct sdhci_host *host)
281{
282 struct sdhci_s3c *ourhost = to_s3c(host);
283
284
285
286
287
288 return clk_round_rate(ourhost->clk_bus[ourhost->cur_clk], 400000);
289}
290
291
292static void sdhci_cmu_set_clock(struct sdhci_host *host, unsigned int clock)
293{
294 struct sdhci_s3c *ourhost = to_s3c(host);
295 struct device *dev = &ourhost->pdev->dev;
296 unsigned long timeout;
297 u16 clk = 0;
298
299
300 if (clock == 0)
301 return;
302
303 sdhci_s3c_set_clock(host, clock);
304
305 clk_set_rate(ourhost->clk_bus[ourhost->cur_clk], clock);
306
307 host->clock = clock;
308
309 clk = SDHCI_CLOCK_INT_EN;
310 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
311
312
313 timeout = 20;
314 while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
315 & SDHCI_CLOCK_INT_STABLE)) {
316 if (timeout == 0) {
317 dev_err(dev, "%s: Internal clock never stabilised.\n",
318 mmc_hostname(host->mmc));
319 return;
320 }
321 timeout--;
322 mdelay(1);
323 }
324
325 clk |= SDHCI_CLOCK_CARD_EN;
326 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
327}
328
329
330
331
332
333
334
335
336
337static int sdhci_s3c_platform_bus_width(struct sdhci_host *host, int width)
338{
339 u8 ctrl;
340
341 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
342
343 switch (width) {
344 case MMC_BUS_WIDTH_8:
345 ctrl |= SDHCI_CTRL_8BITBUS;
346 ctrl &= ~SDHCI_CTRL_4BITBUS;
347 break;
348 case MMC_BUS_WIDTH_4:
349 ctrl |= SDHCI_CTRL_4BITBUS;
350 ctrl &= ~SDHCI_CTRL_8BITBUS;
351 break;
352 default:
353 ctrl &= ~SDHCI_CTRL_4BITBUS;
354 ctrl &= ~SDHCI_CTRL_8BITBUS;
355 break;
356 }
357
358 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
359
360 return 0;
361}
362
363static struct sdhci_ops sdhci_s3c_ops = {
364 .get_max_clock = sdhci_s3c_get_max_clk,
365 .set_clock = sdhci_s3c_set_clock,
366 .get_min_clock = sdhci_s3c_get_min_clock,
367 .platform_bus_width = sdhci_s3c_platform_bus_width,
368};
369
370static void sdhci_s3c_notify_change(struct platform_device *dev, int state)
371{
372 struct sdhci_host *host = platform_get_drvdata(dev);
373#ifdef CONFIG_PM_RUNTIME
374 struct sdhci_s3c *sc = sdhci_priv(host);
375#endif
376 unsigned long flags;
377
378 if (host) {
379 spin_lock_irqsave(&host->lock, flags);
380 if (state) {
381 dev_dbg(&dev->dev, "card inserted.\n");
382#ifdef CONFIG_PM_RUNTIME
383 clk_prepare_enable(sc->clk_io);
384#endif
385 host->flags &= ~SDHCI_DEVICE_DEAD;
386 host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
387 } else {
388 dev_dbg(&dev->dev, "card removed.\n");
389 host->flags |= SDHCI_DEVICE_DEAD;
390 host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
391#ifdef CONFIG_PM_RUNTIME
392 clk_disable_unprepare(sc->clk_io);
393#endif
394 }
395 tasklet_schedule(&host->card_tasklet);
396 spin_unlock_irqrestore(&host->lock, flags);
397 }
398}
399
400static irqreturn_t sdhci_s3c_gpio_card_detect_thread(int irq, void *dev_id)
401{
402 struct sdhci_s3c *sc = dev_id;
403 int status = gpio_get_value(sc->ext_cd_gpio);
404 if (sc->pdata->ext_cd_gpio_invert)
405 status = !status;
406 sdhci_s3c_notify_change(sc->pdev, status);
407 return IRQ_HANDLED;
408}
409
410static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc)
411{
412 struct s3c_sdhci_platdata *pdata = sc->pdata;
413 struct device *dev = &sc->pdev->dev;
414
415 if (devm_gpio_request(dev, pdata->ext_cd_gpio, "SDHCI EXT CD") == 0) {
416 sc->ext_cd_gpio = pdata->ext_cd_gpio;
417 sc->ext_cd_irq = gpio_to_irq(pdata->ext_cd_gpio);
418 if (sc->ext_cd_irq &&
419 request_threaded_irq(sc->ext_cd_irq, NULL,
420 sdhci_s3c_gpio_card_detect_thread,
421 IRQF_TRIGGER_RISING |
422 IRQF_TRIGGER_FALLING |
423 IRQF_ONESHOT,
424 dev_name(dev), sc) == 0) {
425 int status = gpio_get_value(sc->ext_cd_gpio);
426 if (pdata->ext_cd_gpio_invert)
427 status = !status;
428 sdhci_s3c_notify_change(sc->pdev, status);
429 } else {
430 dev_warn(dev, "cannot request irq for card detect\n");
431 sc->ext_cd_irq = 0;
432 }
433 } else {
434 dev_err(dev, "cannot request gpio for card detect\n");
435 }
436}
437
438#ifdef CONFIG_OF
439static int sdhci_s3c_parse_dt(struct device *dev,
440 struct sdhci_host *host, struct s3c_sdhci_platdata *pdata)
441{
442 struct device_node *node = dev->of_node;
443 struct sdhci_s3c *ourhost = to_s3c(host);
444 u32 max_width;
445 int gpio;
446
447
448 if (of_property_read_u32(node, "bus-width", &max_width))
449 max_width = 1;
450 pdata->max_width = max_width;
451
452
453 if (of_get_property(node, "broken-cd", NULL)) {
454 pdata->cd_type = S3C_SDHCI_CD_NONE;
455 return 0;
456 }
457
458 if (of_get_property(node, "non-removable", NULL)) {
459 pdata->cd_type = S3C_SDHCI_CD_PERMANENT;
460 return 0;
461 }
462
463 gpio = of_get_named_gpio(node, "cd-gpios", 0);
464 if (gpio_is_valid(gpio)) {
465 pdata->cd_type = S3C_SDHCI_CD_GPIO;
466 pdata->ext_cd_gpio = gpio;
467 ourhost->ext_cd_gpio = -1;
468 if (of_get_property(node, "cd-inverted", NULL))
469 pdata->ext_cd_gpio_invert = 1;
470 return 0;
471 } else if (gpio != -ENOENT) {
472 dev_err(dev, "invalid card detect gpio specified\n");
473 return -EINVAL;
474 }
475
476
477 pdata->cd_type = S3C_SDHCI_CD_INTERNAL;
478 return 0;
479}
480#else
481static int sdhci_s3c_parse_dt(struct device *dev,
482 struct sdhci_host *host, struct s3c_sdhci_platdata *pdata)
483{
484 return -EINVAL;
485}
486#endif
487
488static const struct of_device_id sdhci_s3c_dt_match[];
489
490static inline struct sdhci_s3c_drv_data *sdhci_s3c_get_driver_data(
491 struct platform_device *pdev)
492{
493#ifdef CONFIG_OF
494 if (pdev->dev.of_node) {
495 const struct of_device_id *match;
496 match = of_match_node(sdhci_s3c_dt_match, pdev->dev.of_node);
497 return (struct sdhci_s3c_drv_data *)match->data;
498 }
499#endif
500 return (struct sdhci_s3c_drv_data *)
501 platform_get_device_id(pdev)->driver_data;
502}
503
504static int sdhci_s3c_probe(struct platform_device *pdev)
505{
506 struct s3c_sdhci_platdata *pdata;
507 struct sdhci_s3c_drv_data *drv_data;
508 struct device *dev = &pdev->dev;
509 struct sdhci_host *host;
510 struct sdhci_s3c *sc;
511 struct resource *res;
512 int ret, irq, ptr, clks;
513
514 if (!pdev->dev.platform_data && !pdev->dev.of_node) {
515 dev_err(dev, "no device data specified\n");
516 return -ENOENT;
517 }
518
519 irq = platform_get_irq(pdev, 0);
520 if (irq < 0) {
521 dev_err(dev, "no irq specified\n");
522 return irq;
523 }
524
525 host = sdhci_alloc_host(dev, sizeof(struct sdhci_s3c));
526 if (IS_ERR(host)) {
527 dev_err(dev, "sdhci_alloc_host() failed\n");
528 return PTR_ERR(host);
529 }
530 sc = sdhci_priv(host);
531
532 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
533 if (!pdata) {
534 ret = -ENOMEM;
535 goto err_pdata_io_clk;
536 }
537
538 if (pdev->dev.of_node) {
539 ret = sdhci_s3c_parse_dt(&pdev->dev, host, pdata);
540 if (ret)
541 goto err_pdata_io_clk;
542 } else {
543 memcpy(pdata, pdev->dev.platform_data, sizeof(*pdata));
544 sc->ext_cd_gpio = -1;
545 }
546
547 drv_data = sdhci_s3c_get_driver_data(pdev);
548
549 sc->host = host;
550 sc->pdev = pdev;
551 sc->pdata = pdata;
552
553 platform_set_drvdata(pdev, host);
554
555 sc->clk_io = devm_clk_get(dev, "hsmmc");
556 if (IS_ERR(sc->clk_io)) {
557 dev_err(dev, "failed to get io clock\n");
558 ret = PTR_ERR(sc->clk_io);
559 goto err_pdata_io_clk;
560 }
561
562
563 clk_prepare_enable(sc->clk_io);
564
565 for (clks = 0, ptr = 0; ptr < MAX_BUS_CLK; ptr++) {
566 struct clk *clk;
567 char name[14];
568
569 snprintf(name, 14, "mmc_busclk.%d", ptr);
570 clk = devm_clk_get(dev, name);
571 if (IS_ERR(clk))
572 continue;
573
574 clks++;
575 sc->clk_bus[ptr] = clk;
576
577
578
579
580
581 sc->cur_clk = ptr;
582
583 dev_info(dev, "clock source %d: %s (%ld Hz)\n",
584 ptr, name, clk_get_rate(clk));
585 }
586
587 if (clks == 0) {
588 dev_err(dev, "failed to find any bus clocks\n");
589 ret = -ENOENT;
590 goto err_no_busclks;
591 }
592
593#ifndef CONFIG_PM_RUNTIME
594 clk_prepare_enable(sc->clk_bus[sc->cur_clk]);
595#endif
596
597 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
598 host->ioaddr = devm_ioremap_resource(&pdev->dev, res);
599 if (IS_ERR(host->ioaddr)) {
600 ret = PTR_ERR(host->ioaddr);
601 goto err_req_regs;
602 }
603
604
605 if (pdata->cfg_gpio)
606 pdata->cfg_gpio(pdev, pdata->max_width);
607
608 host->hw_name = "samsung-hsmmc";
609 host->ops = &sdhci_s3c_ops;
610 host->quirks = 0;
611 host->irq = irq;
612
613
614 host->quirks |= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC;
615 host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT;
616 if (drv_data)
617 host->quirks |= drv_data->sdhci_quirks;
618
619#ifndef CONFIG_MMC_SDHCI_S3C_DMA
620
621
622
623 host->quirks |= SDHCI_QUIRK_BROKEN_DMA;
624
625#endif
626
627
628
629
630 host->quirks |= SDHCI_QUIRK_NO_BUSY_IRQ;
631
632
633 host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12;
634
635
636 host->quirks |= SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC;
637
638 if (pdata->cd_type == S3C_SDHCI_CD_NONE ||
639 pdata->cd_type == S3C_SDHCI_CD_PERMANENT)
640 host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
641
642 if (pdata->cd_type == S3C_SDHCI_CD_PERMANENT)
643 host->mmc->caps = MMC_CAP_NONREMOVABLE;
644
645 switch (pdata->max_width) {
646 case 8:
647 host->mmc->caps |= MMC_CAP_8_BIT_DATA;
648 case 4:
649 host->mmc->caps |= MMC_CAP_4_BIT_DATA;
650 break;
651 }
652
653 if (pdata->pm_caps)
654 host->mmc->pm_caps |= pdata->pm_caps;
655
656 host->quirks |= (SDHCI_QUIRK_32BIT_DMA_ADDR |
657 SDHCI_QUIRK_32BIT_DMA_SIZE);
658
659
660 host->quirks |= SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK;
661
662
663
664
665
666 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
667 sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
668 sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
669 sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
670 }
671
672
673 if (pdata->host_caps)
674 host->mmc->caps |= pdata->host_caps;
675
676 if (pdata->host_caps2)
677 host->mmc->caps2 |= pdata->host_caps2;
678
679 pm_runtime_enable(&pdev->dev);
680 pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
681 pm_runtime_use_autosuspend(&pdev->dev);
682 pm_suspend_ignore_children(&pdev->dev, 1);
683
684 ret = sdhci_add_host(host);
685 if (ret) {
686 dev_err(dev, "sdhci_add_host() failed\n");
687 pm_runtime_forbid(&pdev->dev);
688 pm_runtime_get_noresume(&pdev->dev);
689 goto err_req_regs;
690 }
691
692
693
694
695 if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_init)
696 pdata->ext_cd_init(&sdhci_s3c_notify_change);
697 if (pdata->cd_type == S3C_SDHCI_CD_GPIO &&
698 gpio_is_valid(pdata->ext_cd_gpio))
699 sdhci_s3c_setup_card_detect_gpio(sc);
700
701#ifdef CONFIG_PM_RUNTIME
702 if (pdata->cd_type != S3C_SDHCI_CD_INTERNAL)
703 clk_disable_unprepare(sc->clk_io);
704#endif
705 return 0;
706
707 err_req_regs:
708#ifndef CONFIG_PM_RUNTIME
709 clk_disable_unprepare(sc->clk_bus[sc->cur_clk]);
710#endif
711
712 err_no_busclks:
713 clk_disable_unprepare(sc->clk_io);
714
715 err_pdata_io_clk:
716 sdhci_free_host(host);
717
718 return ret;
719}
720
721static int sdhci_s3c_remove(struct platform_device *pdev)
722{
723 struct sdhci_host *host = platform_get_drvdata(pdev);
724 struct sdhci_s3c *sc = sdhci_priv(host);
725 struct s3c_sdhci_platdata *pdata = sc->pdata;
726
727 if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_cleanup)
728 pdata->ext_cd_cleanup(&sdhci_s3c_notify_change);
729
730 if (sc->ext_cd_irq)
731 free_irq(sc->ext_cd_irq, sc);
732
733#ifdef CONFIG_PM_RUNTIME
734 if (pdata->cd_type != S3C_SDHCI_CD_INTERNAL)
735 clk_prepare_enable(sc->clk_io);
736#endif
737 sdhci_remove_host(host, 1);
738
739 pm_runtime_dont_use_autosuspend(&pdev->dev);
740 pm_runtime_disable(&pdev->dev);
741
742#ifndef CONFIG_PM_RUNTIME
743 clk_disable_unprepare(sc->clk_bus[sc->cur_clk]);
744#endif
745 clk_disable_unprepare(sc->clk_io);
746
747 sdhci_free_host(host);
748 platform_set_drvdata(pdev, NULL);
749
750 return 0;
751}
752
753#ifdef CONFIG_PM_SLEEP
754static int sdhci_s3c_suspend(struct device *dev)
755{
756 struct sdhci_host *host = dev_get_drvdata(dev);
757
758 return sdhci_suspend_host(host);
759}
760
761static int sdhci_s3c_resume(struct device *dev)
762{
763 struct sdhci_host *host = dev_get_drvdata(dev);
764
765 return sdhci_resume_host(host);
766}
767#endif
768
769#ifdef CONFIG_PM_RUNTIME
770static int sdhci_s3c_runtime_suspend(struct device *dev)
771{
772 struct sdhci_host *host = dev_get_drvdata(dev);
773 struct sdhci_s3c *ourhost = to_s3c(host);
774 struct clk *busclk = ourhost->clk_io;
775 int ret;
776
777 ret = sdhci_runtime_suspend_host(host);
778
779 clk_disable_unprepare(ourhost->clk_bus[ourhost->cur_clk]);
780 clk_disable_unprepare(busclk);
781 return ret;
782}
783
784static int sdhci_s3c_runtime_resume(struct device *dev)
785{
786 struct sdhci_host *host = dev_get_drvdata(dev);
787 struct sdhci_s3c *ourhost = to_s3c(host);
788 struct clk *busclk = ourhost->clk_io;
789 int ret;
790
791 clk_prepare_enable(busclk);
792 clk_prepare_enable(ourhost->clk_bus[ourhost->cur_clk]);
793 ret = sdhci_runtime_resume_host(host);
794 return ret;
795}
796#endif
797
798#ifdef CONFIG_PM
799static const struct dev_pm_ops sdhci_s3c_pmops = {
800 SET_SYSTEM_SLEEP_PM_OPS(sdhci_s3c_suspend, sdhci_s3c_resume)
801 SET_RUNTIME_PM_OPS(sdhci_s3c_runtime_suspend, sdhci_s3c_runtime_resume,
802 NULL)
803};
804
805#define SDHCI_S3C_PMOPS (&sdhci_s3c_pmops)
806
807#else
808#define SDHCI_S3C_PMOPS NULL
809#endif
810
811#if defined(CONFIG_CPU_EXYNOS4210) || defined(CONFIG_SOC_EXYNOS4212)
812static struct sdhci_s3c_drv_data exynos4_sdhci_drv_data = {
813 .sdhci_quirks = SDHCI_QUIRK_NONSTANDARD_CLOCK,
814};
815#define EXYNOS4_SDHCI_DRV_DATA ((kernel_ulong_t)&exynos4_sdhci_drv_data)
816#else
817#define EXYNOS4_SDHCI_DRV_DATA ((kernel_ulong_t)NULL)
818#endif
819
820static struct platform_device_id sdhci_s3c_driver_ids[] = {
821 {
822 .name = "s3c-sdhci",
823 .driver_data = (kernel_ulong_t)NULL,
824 }, {
825 .name = "exynos4-sdhci",
826 .driver_data = EXYNOS4_SDHCI_DRV_DATA,
827 },
828 { }
829};
830MODULE_DEVICE_TABLE(platform, sdhci_s3c_driver_ids);
831
832#ifdef CONFIG_OF
833static const struct of_device_id sdhci_s3c_dt_match[] = {
834 { .compatible = "samsung,s3c6410-sdhci", },
835 { .compatible = "samsung,exynos4210-sdhci",
836 .data = (void *)EXYNOS4_SDHCI_DRV_DATA },
837 {},
838};
839MODULE_DEVICE_TABLE(of, sdhci_s3c_dt_match);
840#endif
841
842static struct platform_driver sdhci_s3c_driver = {
843 .probe = sdhci_s3c_probe,
844 .remove = sdhci_s3c_remove,
845 .id_table = sdhci_s3c_driver_ids,
846 .driver = {
847 .owner = THIS_MODULE,
848 .name = "s3c-sdhci",
849 .of_match_table = of_match_ptr(sdhci_s3c_dt_match),
850 .pm = SDHCI_S3C_PMOPS,
851 },
852};
853
854module_platform_driver(sdhci_s3c_driver);
855
856MODULE_DESCRIPTION("Samsung SDHCI (HSMMC) glue");
857MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
858MODULE_LICENSE("GPL v2");
859MODULE_ALIAS("platform:s3c-sdhci");
860