1
2
3
4
5
6
7
8
9
10
11
12
13
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_SLEEP
27static int tmio_mmc_suspend(struct device *dev)
28{
29 struct platform_device *pdev = to_platform_device(dev);
30 const struct mfd_cell *cell = mfd_get_cell(pdev);
31 int ret;
32
33 ret = pm_runtime_force_suspend(dev);
34
35
36 if (!ret && cell->disable)
37 cell->disable(pdev);
38
39 return ret;
40}
41
42static int tmio_mmc_resume(struct device *dev)
43{
44 struct platform_device *pdev = to_platform_device(dev);
45 const struct mfd_cell *cell = mfd_get_cell(pdev);
46 int ret = 0;
47
48
49 if (cell->resume)
50 ret = cell->resume(pdev);
51
52 if (!ret)
53 ret = pm_runtime_force_resume(dev);
54
55 return ret;
56}
57#endif
58
59static int tmio_mmc_probe(struct platform_device *pdev)
60{
61 const struct mfd_cell *cell = mfd_get_cell(pdev);
62 struct tmio_mmc_data *pdata;
63 struct tmio_mmc_host *host;
64 struct resource *res;
65 int ret = -EINVAL, irq;
66
67 if (pdev->num_resources != 2)
68 goto out;
69
70 pdata = pdev->dev.platform_data;
71 if (!pdata || !pdata->hclk)
72 goto out;
73
74 irq = platform_get_irq(pdev, 0);
75 if (irq < 0) {
76 ret = irq;
77 goto out;
78 }
79
80
81 if (cell->enable) {
82 ret = cell->enable(pdev);
83 if (ret)
84 goto out;
85 }
86
87 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
88 if (!res) {
89 ret = -EINVAL;
90 goto cell_disable;
91 }
92
93 pdata->flags |= TMIO_MMC_HAVE_HIGH_REG;
94
95 host = tmio_mmc_host_alloc(pdev);
96 if (!host)
97 goto cell_disable;
98
99
100 host->bus_shift = resource_size(res) >> 10;
101
102 ret = tmio_mmc_host_probe(host, pdata, NULL);
103 if (ret)
104 goto host_free;
105
106 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq,
107 IRQF_TRIGGER_FALLING,
108 dev_name(&pdev->dev), host);
109 if (ret)
110 goto host_remove;
111
112 pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
113 (unsigned long)host->ctl, irq);
114
115 return 0;
116
117host_remove:
118 tmio_mmc_host_remove(host);
119host_free:
120 tmio_mmc_host_free(host);
121cell_disable:
122 if (cell->disable)
123 cell->disable(pdev);
124out:
125 return ret;
126}
127
128static int tmio_mmc_remove(struct platform_device *pdev)
129{
130 const struct mfd_cell *cell = mfd_get_cell(pdev);
131 struct mmc_host *mmc = platform_get_drvdata(pdev);
132
133 if (mmc) {
134 struct tmio_mmc_host *host = mmc_priv(mmc);
135
136 tmio_mmc_host_remove(host);
137 if (cell->disable)
138 cell->disable(pdev);
139 }
140
141 return 0;
142}
143
144
145
146static const struct dev_pm_ops tmio_mmc_dev_pm_ops = {
147 SET_SYSTEM_SLEEP_PM_OPS(tmio_mmc_suspend, tmio_mmc_resume)
148 SET_RUNTIME_PM_OPS(tmio_mmc_host_runtime_suspend,
149 tmio_mmc_host_runtime_resume, NULL)
150};
151
152static struct platform_driver tmio_mmc_driver = {
153 .driver = {
154 .name = "tmio-mmc",
155 .pm = &tmio_mmc_dev_pm_ops,
156 },
157 .probe = tmio_mmc_probe,
158 .remove = tmio_mmc_remove,
159};
160
161module_platform_driver(tmio_mmc_driver);
162
163MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
164MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
165MODULE_LICENSE("GPL v2");
166MODULE_ALIAS("platform:tmio-mmc");
167