Commit | Line | Data |
---|---|---|
4a48998f | 1 | /* |
b6147490 | 2 | * linux/drivers/mmc/host/tmio_mmc.c |
4a48998f | 3 | * |
b6147490 GL |
4 | * Copyright (C) 2007 Ian Molton |
5 | * Copyright (C) 2004 Ian Molton | |
4a48998f IM |
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 | * | |
e6f2c7ad | 13 | * TC6393XB TC6391XB TC6387XB T7L66XB ASIC3 |
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 IM |
25 | |
26 | #ifdef CONFIG_PM | |
27 | static int tmio_mmc_suspend(struct platform_device *dev, pm_message_t state) | |
28 | { | |
944dc035 | 29 | const struct mfd_cell *cell = mfd_get_cell(dev); |
4a48998f IM |
30 | int ret; |
31 | ||
e6ee7182 | 32 | ret = tmio_mmc_host_suspend(&dev->dev); |
4a48998f IM |
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 | { | |
944dc035 | 43 | const struct mfd_cell *cell = mfd_get_cell(dev); |
4a48998f IM |
44 | int ret = 0; |
45 | ||
4a48998f | 46 | /* Tell the MFD core we are ready to be enabled */ |
e6ee7182 | 47 | if (cell->resume) |
64e8867b | 48 | ret = cell->resume(dev); |
4a48998f | 49 | |
e6ee7182 GL |
50 | if (!ret) |
51 | ret = tmio_mmc_host_resume(&dev->dev); | |
4a48998f | 52 | |
4a48998f IM |
53 | return ret; |
54 | } | |
55 | #else | |
56 | #define tmio_mmc_suspend NULL | |
57 | #define tmio_mmc_resume NULL | |
58 | #endif | |
59 | ||
c3be1efd | 60 | static int tmio_mmc_probe(struct platform_device *pdev) |
4a48998f | 61 | { |
b6147490 | 62 | const struct mfd_cell *cell = mfd_get_cell(pdev); |
f0e46cc4 | 63 | struct tmio_mmc_data *pdata; |
4a48998f | 64 | struct tmio_mmc_host *host; |
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 | ||
b6147490 | 87 | ret = tmio_mmc_host_probe(&host, pdev, pdata); |
4a48998f | 88 | if (ret) |
7ee422dc | 89 | goto cell_disable; |
4a48998f | 90 | |
d9618e9f YZ |
91 | ret = request_irq(irq, tmio_mmc_irq, IRQF_TRIGGER_FALLING, |
92 | dev_name(&pdev->dev), host); | |
8e7bfdb3 MD |
93 | if (ret) |
94 | goto host_remove; | |
95 | ||
311f3ac7 | 96 | pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc), |
8e7bfdb3 | 97 | (unsigned long)host->ctl, irq); |
4a48998f | 98 | |
4a48998f IM |
99 | return 0; |
100 | ||
8e7bfdb3 MD |
101 | host_remove: |
102 | tmio_mmc_host_remove(host); | |
7ee422dc MD |
103 | cell_disable: |
104 | if (cell->disable) | |
b6147490 | 105 | cell->disable(pdev); |
4a48998f IM |
106 | out: |
107 | return ret; | |
108 | } | |
109 | ||
6e0ee714 | 110 | static int tmio_mmc_remove(struct platform_device *pdev) |
4a48998f | 111 | { |
b6147490 GL |
112 | const struct mfd_cell *cell = mfd_get_cell(pdev); |
113 | struct mmc_host *mmc = platform_get_drvdata(pdev); | |
4a48998f | 114 | |
b6147490 | 115 | platform_set_drvdata(pdev, NULL); |
4a48998f IM |
116 | |
117 | if (mmc) { | |
8e7bfdb3 MD |
118 | struct tmio_mmc_host *host = mmc_priv(mmc); |
119 | free_irq(platform_get_irq(pdev, 0), host); | |
120 | tmio_mmc_host_remove(host); | |
7ee422dc | 121 | if (cell->disable) |
b6147490 | 122 | cell->disable(pdev); |
4a48998f IM |
123 | } |
124 | ||
125 | return 0; | |
126 | } | |
127 | ||
128 | /* ------------------- device registration ----------------------- */ | |
129 | ||
130 | static struct platform_driver tmio_mmc_driver = { | |
131 | .driver = { | |
132 | .name = "tmio-mmc", | |
133 | .owner = THIS_MODULE, | |
134 | }, | |
135 | .probe = tmio_mmc_probe, | |
0433c143 | 136 | .remove = tmio_mmc_remove, |
4a48998f IM |
137 | .suspend = tmio_mmc_suspend, |
138 | .resume = tmio_mmc_resume, | |
139 | }; | |
140 | ||
d1f81a64 | 141 | module_platform_driver(tmio_mmc_driver); |
4a48998f IM |
142 | |
143 | MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver"); | |
144 | MODULE_AUTHOR("Ian Molton <spyro@f2s.com>"); | |
145 | MODULE_LICENSE("GPL v2"); | |
146 | MODULE_ALIAS("platform:tmio-mmc"); |