blob: 8d185de90d207ded1a256b32cdd69ae11d6ec2c6 [file] [log] [blame]
Ian Molton4a489982008-07-15 16:02:21 +01001/*
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +01002 * linux/drivers/mmc/host/tmio_mmc.c
Ian Molton4a489982008-07-15 16:02:21 +01003 *
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +01004 * Copyright (C) 2007 Ian Molton
5 * Copyright (C) 2004 Ian Molton
Ian Molton4a489982008-07-15 16:02:21 +01006 *
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 *
Philipp Zabele6f2c7a2009-06-04 20:12:37 +020013 * TC6393XB TC6391XB TC6387XB T7L66XB ASIC3
Ian Molton4a489982008-07-15 16:02:21 +010014 */
Guennadi Liakhovetskie0bc6ff2010-11-23 17:24:11 +010015
Guennadi Liakhovetskie0bc6ff2010-11-23 17:24:11 +010016#include <linux/device.h>
Ian Molton4a489982008-07-15 16:02:21 +010017#include <linux/mfd/core.h>
18#include <linux/mfd/tmio.h>
Guennadi Liakhovetskie0bc6ff2010-11-23 17:24:11 +010019#include <linux/mmc/host.h>
20#include <linux/module.h>
21#include <linux/pagemap.h>
22#include <linux/scatterlist.h>
Ian Molton4a489982008-07-15 16:02:21 +010023
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +010024#include "tmio_mmc.h"
Ian Molton4a489982008-07-15 16:02:21 +010025
26#ifdef CONFIG_PM
27static int tmio_mmc_suspend(struct platform_device *dev, pm_message_t state)
28{
Andres Salomon944dc032011-03-01 12:32:20 -080029 const struct mfd_cell *cell = mfd_get_cell(dev);
Ian Molton4a489982008-07-15 16:02:21 +010030 struct mmc_host *mmc = platform_get_drvdata(dev);
31 int ret;
32
Guennadi Liakhovetskie6ee7182011-05-05 16:13:12 +000033 ret = tmio_mmc_host_suspend(&dev->dev);
Ian Molton4a489982008-07-15 16:02:21 +010034
35 /* Tell MFD core it can disable us now.*/
36 if (!ret && cell->disable)
37 cell->disable(dev);
38
39 return ret;
40}
41
42static int tmio_mmc_resume(struct platform_device *dev)
43{
Andres Salomon944dc032011-03-01 12:32:20 -080044 const struct mfd_cell *cell = mfd_get_cell(dev);
Ian Molton4a489982008-07-15 16:02:21 +010045 struct mmc_host *mmc = platform_get_drvdata(dev);
Ian Molton4a489982008-07-15 16:02:21 +010046 int ret = 0;
47
Ian Molton4a489982008-07-15 16:02:21 +010048 /* Tell the MFD core we are ready to be enabled */
Guennadi Liakhovetskie6ee7182011-05-05 16:13:12 +000049 if (cell->resume)
Ian Molton64e88672010-01-06 13:51:48 +010050 ret = cell->resume(dev);
Ian Molton4a489982008-07-15 16:02:21 +010051
Guennadi Liakhovetskie6ee7182011-05-05 16:13:12 +000052 if (!ret)
53 ret = tmio_mmc_host_resume(&dev->dev);
Ian Molton4a489982008-07-15 16:02:21 +010054
Ian Molton4a489982008-07-15 16:02:21 +010055 return ret;
56}
57#else
58#define tmio_mmc_suspend NULL
59#define tmio_mmc_resume NULL
60#endif
61
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +010062static int __devinit tmio_mmc_probe(struct platform_device *pdev)
Ian Molton4a489982008-07-15 16:02:21 +010063{
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +010064 const struct mfd_cell *cell = mfd_get_cell(pdev);
Philipp Zabelf0e46cc2009-06-04 20:12:31 +020065 struct tmio_mmc_data *pdata;
Ian Molton4a489982008-07-15 16:02:21 +010066 struct tmio_mmc_host *host;
Magnus Damm8e7bfdb2011-05-06 11:02:33 +000067 int ret = -EINVAL, irq;
Ian Molton4a489982008-07-15 16:02:21 +010068
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +010069 if (pdev->num_resources != 2)
Ian Molton4a489982008-07-15 16:02:21 +010070 goto out;
71
Samuel Ortizec719742011-04-06 11:38:14 +020072 pdata = pdev->dev.platform_data;
Philipp Zabeld6c9b5e2009-06-04 20:12:34 +020073 if (!pdata || !pdata->hclk)
Philipp Zabelf0e46cc2009-06-04 20:12:31 +020074 goto out;
Philipp Zabeld6c9b5e2009-06-04 20:12:34 +020075
Magnus Damm8e7bfdb2011-05-06 11:02:33 +000076 irq = platform_get_irq(pdev, 0);
77 if (irq < 0) {
78 ret = irq;
79 goto out;
80 }
81
Ian Molton4a489982008-07-15 16:02:21 +010082 /* Tell the MFD core we are ready to be enabled */
83 if (cell->enable) {
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +010084 ret = cell->enable(pdev);
Ian Molton4a489982008-07-15 16:02:21 +010085 if (ret)
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +010086 goto out;
Ian Molton4a489982008-07-15 16:02:21 +010087 }
88
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +010089 ret = tmio_mmc_host_probe(&host, pdev, pdata);
Ian Molton4a489982008-07-15 16:02:21 +010090 if (ret)
Magnus Damm7ee422d2010-02-17 16:38:23 +090091 goto cell_disable;
Ian Molton4a489982008-07-15 16:02:21 +010092
Magnus Damm8e7bfdb2011-05-06 11:02:33 +000093 ret = request_irq(irq, tmio_mmc_irq, IRQF_DISABLED |
94 IRQF_TRIGGER_FALLING, dev_name(&pdev->dev), host);
95 if (ret)
96 goto host_remove;
97
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +000098 pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
Magnus Damm8e7bfdb2011-05-06 11:02:33 +000099 (unsigned long)host->ctl, irq);
Ian Molton4a489982008-07-15 16:02:21 +0100100
Ian Molton4a489982008-07-15 16:02:21 +0100101 return 0;
102
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000103host_remove:
104 tmio_mmc_host_remove(host);
Magnus Damm7ee422d2010-02-17 16:38:23 +0900105cell_disable:
106 if (cell->disable)
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100107 cell->disable(pdev);
Ian Molton4a489982008-07-15 16:02:21 +0100108out:
109 return ret;
110}
111
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100112static int __devexit tmio_mmc_remove(struct platform_device *pdev)
Ian Molton4a489982008-07-15 16:02:21 +0100113{
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100114 const struct mfd_cell *cell = mfd_get_cell(pdev);
115 struct mmc_host *mmc = platform_get_drvdata(pdev);
Ian Molton4a489982008-07-15 16:02:21 +0100116
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100117 platform_set_drvdata(pdev, NULL);
Ian Molton4a489982008-07-15 16:02:21 +0100118
119 if (mmc) {
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000120 struct tmio_mmc_host *host = mmc_priv(mmc);
121 free_irq(platform_get_irq(pdev, 0), host);
122 tmio_mmc_host_remove(host);
Magnus Damm7ee422d2010-02-17 16:38:23 +0900123 if (cell->disable)
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100124 cell->disable(pdev);
Ian Molton4a489982008-07-15 16:02:21 +0100125 }
126
127 return 0;
128}
129
130/* ------------------- device registration ----------------------- */
131
132static struct platform_driver tmio_mmc_driver = {
133 .driver = {
134 .name = "tmio-mmc",
135 .owner = THIS_MODULE,
136 },
137 .probe = tmio_mmc_probe,
138 .remove = __devexit_p(tmio_mmc_remove),
139 .suspend = tmio_mmc_suspend,
140 .resume = tmio_mmc_resume,
141};
142
143
144static int __init tmio_mmc_init(void)
145{
146 return platform_driver_register(&tmio_mmc_driver);
147}
148
149static void __exit tmio_mmc_exit(void)
150{
151 platform_driver_unregister(&tmio_mmc_driver);
152}
153
154module_init(tmio_mmc_init);
155module_exit(tmio_mmc_exit);
156
157MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
158MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
159MODULE_LICENSE("GPL v2");
160MODULE_ALIAS("platform:tmio-mmc");