Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/vapier...
[cascardo/linux.git] / drivers / mmc / host / tmio_mmc.c
1 /*
2  * linux/drivers/mmc/host/tmio_mmc.c
3  *
4  * Copyright (C) 2007 Ian Molton
5  * Copyright (C) 2004 Ian Molton
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * Driver for the MMC / SD / SDIO cell found in:
12  *
13  * TC6393XB TC6391XB TC6387XB T7L66XB ASIC3
14  */
15
16 #include <linux/device.h>
17 #include <linux/mfd/core.h>
18 #include <linux/mfd/tmio.h>
19 #include <linux/mmc/host.h>
20 #include <linux/module.h>
21 #include <linux/pagemap.h>
22 #include <linux/scatterlist.h>
23
24 #include "tmio_mmc.h"
25
26 #ifdef CONFIG_PM
27 static int tmio_mmc_suspend(struct platform_device *dev, pm_message_t state)
28 {
29         const struct mfd_cell *cell = mfd_get_cell(dev);
30         struct mmc_host *mmc = platform_get_drvdata(dev);
31         int ret;
32
33         ret = mmc_suspend_host(mmc);
34
35         /* Tell MFD core it can disable us now.*/
36         if (!ret && cell->disable)
37                 cell->disable(dev);
38
39         return ret;
40 }
41
42 static int tmio_mmc_resume(struct platform_device *dev)
43 {
44         const struct mfd_cell *cell = mfd_get_cell(dev);
45         struct mmc_host *mmc = platform_get_drvdata(dev);
46         int ret = 0;
47
48         /* Tell the MFD core we are ready to be enabled */
49         if (cell->resume) {
50                 ret = cell->resume(dev);
51                 if (ret)
52                         goto out;
53         }
54
55         mmc_resume_host(mmc);
56
57 out:
58         return ret;
59 }
60 #else
61 #define tmio_mmc_suspend NULL
62 #define tmio_mmc_resume NULL
63 #endif
64
65 static int __devinit tmio_mmc_probe(struct platform_device *pdev)
66 {
67         const struct mfd_cell *cell = mfd_get_cell(pdev);
68         struct tmio_mmc_data *pdata;
69         struct tmio_mmc_host *host;
70         int ret = -EINVAL;
71
72         if (pdev->num_resources != 2)
73                 goto out;
74
75         pdata = mfd_get_data(pdev);
76         if (!pdata || !pdata->hclk)
77                 goto out;
78
79         /* Tell the MFD core we are ready to be enabled */
80         if (cell->enable) {
81                 ret = cell->enable(pdev);
82                 if (ret)
83                         goto out;
84         }
85
86         ret = tmio_mmc_host_probe(&host, pdev, pdata);
87         if (ret)
88                 goto cell_disable;
89
90         pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
91                 (unsigned long)host->ctl, host->irq);
92
93         return 0;
94
95 cell_disable:
96         if (cell->disable)
97                 cell->disable(pdev);
98 out:
99         return ret;
100 }
101
102 static int __devexit tmio_mmc_remove(struct platform_device *pdev)
103 {
104         const struct mfd_cell *cell = mfd_get_cell(pdev);
105         struct mmc_host *mmc = platform_get_drvdata(pdev);
106
107         platform_set_drvdata(pdev, NULL);
108
109         if (mmc) {
110                 tmio_mmc_host_remove(mmc_priv(mmc));
111                 if (cell->disable)
112                         cell->disable(pdev);
113         }
114
115         return 0;
116 }
117
118 /* ------------------- device registration ----------------------- */
119
120 static struct platform_driver tmio_mmc_driver = {
121         .driver = {
122                 .name = "tmio-mmc",
123                 .owner = THIS_MODULE,
124         },
125         .probe = tmio_mmc_probe,
126         .remove = __devexit_p(tmio_mmc_remove),
127         .suspend = tmio_mmc_suspend,
128         .resume = tmio_mmc_resume,
129 };
130
131
132 static int __init tmio_mmc_init(void)
133 {
134         return platform_driver_register(&tmio_mmc_driver);
135 }
136
137 static void __exit tmio_mmc_exit(void)
138 {
139         platform_driver_unregister(&tmio_mmc_driver);
140 }
141
142 module_init(tmio_mmc_init);
143 module_exit(tmio_mmc_exit);
144
145 MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
146 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
147 MODULE_LICENSE("GPL v2");
148 MODULE_ALIAS("platform:tmio-mmc");