Merge branch 'tunnels'
[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         int ret;
31
32         ret = tmio_mmc_host_suspend(&dev->dev);
33
34         /* Tell MFD core it can disable us now.*/
35         if (!ret && cell->disable)
36                 cell->disable(dev);
37
38         return ret;
39 }
40
41 static int tmio_mmc_resume(struct platform_device *dev)
42 {
43         const struct mfd_cell *cell = mfd_get_cell(dev);
44         int ret = 0;
45
46         /* Tell the MFD core we are ready to be enabled */
47         if (cell->resume)
48                 ret = cell->resume(dev);
49
50         if (!ret)
51                 ret = tmio_mmc_host_resume(&dev->dev);
52
53         return ret;
54 }
55 #else
56 #define tmio_mmc_suspend NULL
57 #define tmio_mmc_resume NULL
58 #endif
59
60 static int tmio_mmc_probe(struct platform_device *pdev)
61 {
62         const struct mfd_cell *cell = mfd_get_cell(pdev);
63         struct tmio_mmc_data *pdata;
64         struct tmio_mmc_host *host;
65         struct resource *res;
66         int ret = -EINVAL, irq;
67
68         if (pdev->num_resources != 2)
69                 goto out;
70
71         pdata = pdev->dev.platform_data;
72         if (!pdata || !pdata->hclk)
73                 goto out;
74
75         irq = platform_get_irq(pdev, 0);
76         if (irq < 0) {
77                 ret = irq;
78                 goto out;
79         }
80
81         /* Tell the MFD core we are ready to be enabled */
82         if (cell->enable) {
83                 ret = cell->enable(pdev);
84                 if (ret)
85                         goto out;
86         }
87
88         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
89         if (!res)
90                 return -EINVAL;
91
92         /* SD control register space size is 0x200, 0x400 for bus_shift=1 */
93         pdata->bus_shift = resource_size(res) >> 10;
94         pdata->flags |= TMIO_MMC_HAVE_HIGH_REG;
95
96         ret = tmio_mmc_host_probe(&host, pdev, pdata);
97         if (ret)
98                 goto cell_disable;
99
100         ret = request_irq(irq, tmio_mmc_irq, IRQF_TRIGGER_FALLING,
101                                 dev_name(&pdev->dev), host);
102         if (ret)
103                 goto host_remove;
104
105         pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
106                 (unsigned long)host->ctl, irq);
107
108         return 0;
109
110 host_remove:
111         tmio_mmc_host_remove(host);
112 cell_disable:
113         if (cell->disable)
114                 cell->disable(pdev);
115 out:
116         return ret;
117 }
118
119 static int tmio_mmc_remove(struct platform_device *pdev)
120 {
121         const struct mfd_cell *cell = mfd_get_cell(pdev);
122         struct mmc_host *mmc = platform_get_drvdata(pdev);
123
124         if (mmc) {
125                 struct tmio_mmc_host *host = mmc_priv(mmc);
126                 free_irq(platform_get_irq(pdev, 0), host);
127                 tmio_mmc_host_remove(host);
128                 if (cell->disable)
129                         cell->disable(pdev);
130         }
131
132         return 0;
133 }
134
135 /* ------------------- device registration ----------------------- */
136
137 static struct platform_driver tmio_mmc_driver = {
138         .driver = {
139                 .name = "tmio-mmc",
140                 .owner = THIS_MODULE,
141         },
142         .probe = tmio_mmc_probe,
143         .remove = tmio_mmc_remove,
144         .suspend = tmio_mmc_suspend,
145         .resume = tmio_mmc_resume,
146 };
147
148 module_platform_driver(tmio_mmc_driver);
149
150 MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
151 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
152 MODULE_LICENSE("GPL v2");
153 MODULE_ALIAS("platform:tmio-mmc");