mmc: tmio: move {tmio_}mmc_of_parse() to tmio_mmc_host_alloc()
[linux-2.6-block.git] / drivers / mmc / host / tmio_mmc.c
CommitLineData
4a48998f 1/*
b21f13d8
SH
2 * Driver for the MMC / SD / SDIO cell found in:
3 *
4 * TC6393XB TC6391XB TC6387XB T7L66XB ASIC3
4a48998f 5 *
87317c4d
SH
6 * Copyright (C) 2017 Renesas Electronics Corporation
7 * Copyright (C) 2017 Horms Solutions, Simon Horman
b6147490
GL
8 * Copyright (C) 2007 Ian Molton
9 * Copyright (C) 2004 Ian Molton
4a48998f
IM
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
4a48998f 14 */
e0bc6ff8 15
e0bc6ff8 16#include <linux/device.h>
4a48998f
IM
17#include <linux/mfd/core.h>
18#include <linux/mfd/tmio.h>
e0bc6ff8
GL
19#include <linux/mmc/host.h>
20#include <linux/module.h>
21#include <linux/pagemap.h>
22#include <linux/scatterlist.h>
6ff56e0d 23
b6147490 24#include "tmio_mmc.h"
4a48998f 25
c8964481
UH
26#ifdef CONFIG_PM_SLEEP
27static int tmio_mmc_suspend(struct device *dev)
4a48998f 28{
c8964481
UH
29 struct platform_device *pdev = to_platform_device(dev);
30 const struct mfd_cell *cell = mfd_get_cell(pdev);
4a48998f
IM
31 int ret;
32
70a15e1a 33 ret = pm_runtime_force_suspend(dev);
4a48998f
IM
34
35 /* Tell MFD core it can disable us now.*/
36 if (!ret && cell->disable)
c8964481 37 cell->disable(pdev);
4a48998f
IM
38
39 return ret;
40}
41
c8964481 42static int tmio_mmc_resume(struct device *dev)
4a48998f 43{
c8964481
UH
44 struct platform_device *pdev = to_platform_device(dev);
45 const struct mfd_cell *cell = mfd_get_cell(pdev);
4a48998f
IM
46 int ret = 0;
47
4a48998f 48 /* Tell the MFD core we are ready to be enabled */
e6ee7182 49 if (cell->resume)
c8964481 50 ret = cell->resume(pdev);
4a48998f 51
e6ee7182 52 if (!ret)
70a15e1a 53 ret = pm_runtime_force_resume(dev);
4a48998f 54
4a48998f
IM
55 return ret;
56}
4a48998f
IM
57#endif
58
c3be1efd 59static int tmio_mmc_probe(struct platform_device *pdev)
4a48998f 60{
b6147490 61 const struct mfd_cell *cell = mfd_get_cell(pdev);
f0e46cc4 62 struct tmio_mmc_data *pdata;
4a48998f 63 struct tmio_mmc_host *host;
3b159a6e 64 struct resource *res;
8e7bfdb3 65 int ret = -EINVAL, irq;
4a48998f 66
b6147490 67 if (pdev->num_resources != 2)
4a48998f
IM
68 goto out;
69
ec71974f 70 pdata = pdev->dev.platform_data;
d6c9b5ed 71 if (!pdata || !pdata->hclk)
f0e46cc4 72 goto out;
d6c9b5ed 73
8e7bfdb3
MD
74 irq = platform_get_irq(pdev, 0);
75 if (irq < 0) {
76 ret = irq;
77 goto out;
78 }
79
4a48998f
IM
80 /* Tell the MFD core we are ready to be enabled */
81 if (cell->enable) {
b6147490 82 ret = cell->enable(pdev);
4a48998f 83 if (ret)
b6147490 84 goto out;
4a48998f
IM
85 }
86
3b159a6e 87 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
25db67e2
IM
88 if (!res) {
89 ret = -EINVAL;
90 goto cell_disable;
91 }
3b159a6e 92
5d60e500 93 pdata->flags |= TMIO_MMC_HAVE_HIGH_REG;
3b159a6e 94
b21fc294 95 host = tmio_mmc_host_alloc(pdev, pdata);
8d09a133
MY
96 if (IS_ERR(host)) {
97 ret = PTR_ERR(host);
7ee422dc 98 goto cell_disable;
8d09a133 99 }
4a48998f 100
7445bf9e
KM
101 /* SD control register space size is 0x200, 0x400 for bus_shift=1 */
102 host->bus_shift = resource_size(res) >> 10;
103
b21fc294
MY
104 host->mmc->f_max = pdata->hclk;
105 host->mmc->f_min = pdata->hclk / 512;
106
107 ret = tmio_mmc_host_probe(host, NULL);
94b110af
KM
108 if (ret)
109 goto host_free;
110
de501af9 111 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq,
f2218db8
SH
112 IRQF_TRIGGER_FALLING,
113 dev_name(&pdev->dev), host);
8e7bfdb3
MD
114 if (ret)
115 goto host_remove;
116
311f3ac7 117 pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
8e7bfdb3 118 (unsigned long)host->ctl, irq);
4a48998f 119
4a48998f
IM
120 return 0;
121
8e7bfdb3
MD
122host_remove:
123 tmio_mmc_host_remove(host);
94b110af
KM
124host_free:
125 tmio_mmc_host_free(host);
7ee422dc
MD
126cell_disable:
127 if (cell->disable)
b6147490 128 cell->disable(pdev);
4a48998f
IM
129out:
130 return ret;
131}
132
6e0ee714 133static int tmio_mmc_remove(struct platform_device *pdev)
4a48998f 134{
b6147490 135 const struct mfd_cell *cell = mfd_get_cell(pdev);
a3b05373 136 struct tmio_mmc_host *host = platform_get_drvdata(pdev);
4a48998f 137
a3b05373
MY
138 tmio_mmc_host_remove(host);
139 if (cell->disable)
140 cell->disable(pdev);
4a48998f
IM
141
142 return 0;
143}
144
145/* ------------------- device registration ----------------------- */
146
c8964481
UH
147static const struct dev_pm_ops tmio_mmc_dev_pm_ops = {
148 SET_SYSTEM_SLEEP_PM_OPS(tmio_mmc_suspend, tmio_mmc_resume)
6ed23b80 149 SET_RUNTIME_PM_OPS(tmio_mmc_host_runtime_suspend,
f2218db8 150 tmio_mmc_host_runtime_resume, NULL)
c8964481
UH
151};
152
4a48998f
IM
153static struct platform_driver tmio_mmc_driver = {
154 .driver = {
155 .name = "tmio-mmc",
c8964481 156 .pm = &tmio_mmc_dev_pm_ops,
4a48998f
IM
157 },
158 .probe = tmio_mmc_probe,
0433c143 159 .remove = tmio_mmc_remove,
4a48998f
IM
160};
161
d1f81a64 162module_platform_driver(tmio_mmc_driver);
4a48998f
IM
163
164MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
165MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
166MODULE_LICENSE("GPL v2");
167MODULE_ALIAS("platform:tmio-mmc");