blob: cfad844730d80195ff63172c3f69aed3e3fe1155 [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
Ulf Hanssonc8964482013-10-23 14:57:50 +020026#ifdef CONFIG_PM_SLEEP
27static int tmio_mmc_suspend(struct device *dev)
Ian Molton4a489982008-07-15 16:02:21 +010028{
Ulf Hanssonc8964482013-10-23 14:57:50 +020029 struct platform_device *pdev = to_platform_device(dev);
30 const struct mfd_cell *cell = mfd_get_cell(pdev);
Ian Molton4a489982008-07-15 16:02:21 +010031 int ret;
32
Ulf Hanssonc8964482013-10-23 14:57:50 +020033 ret = tmio_mmc_host_suspend(dev);
Ian Molton4a489982008-07-15 16:02:21 +010034
35 /* Tell MFD core it can disable us now.*/
36 if (!ret && cell->disable)
Ulf Hanssonc8964482013-10-23 14:57:50 +020037 cell->disable(pdev);
Ian Molton4a489982008-07-15 16:02:21 +010038
39 return ret;
40}
41
Ulf Hanssonc8964482013-10-23 14:57:50 +020042static int tmio_mmc_resume(struct device *dev)
Ian Molton4a489982008-07-15 16:02:21 +010043{
Ulf Hanssonc8964482013-10-23 14:57:50 +020044 struct platform_device *pdev = to_platform_device(dev);
45 const struct mfd_cell *cell = mfd_get_cell(pdev);
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)
Ulf Hanssonc8964482013-10-23 14:57:50 +020050 ret = cell->resume(pdev);
Ian Molton4a489982008-07-15 16:02:21 +010051
Guennadi Liakhovetskie6ee7182011-05-05 16:13:12 +000052 if (!ret)
Ulf Hanssonc8964482013-10-23 14:57:50 +020053 ret = tmio_mmc_host_resume(dev);
Ian Molton4a489982008-07-15 16:02:21 +010054
Ian Molton4a489982008-07-15 16:02:21 +010055 return ret;
56}
Ian Molton4a489982008-07-15 16:02:21 +010057#endif
58
Bill Pembertonc3be1ef2012-11-19 13:23:06 -050059static int tmio_mmc_probe(struct platform_device *pdev)
Ian Molton4a489982008-07-15 16:02:21 +010060{
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +010061 const struct mfd_cell *cell = mfd_get_cell(pdev);
Philipp Zabelf0e46cc2009-06-04 20:12:31 +020062 struct tmio_mmc_data *pdata;
Ian Molton4a489982008-07-15 16:02:21 +010063 struct tmio_mmc_host *host;
Kuninori Morimoto3b159a62013-11-20 00:30:55 -080064 struct resource *res;
Magnus Damm8e7bfdb2011-05-06 11:02:33 +000065 int ret = -EINVAL, irq;
Ian Molton4a489982008-07-15 16:02:21 +010066
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +010067 if (pdev->num_resources != 2)
Ian Molton4a489982008-07-15 16:02:21 +010068 goto out;
69
Samuel Ortizec719742011-04-06 11:38:14 +020070 pdata = pdev->dev.platform_data;
Philipp Zabeld6c9b5e2009-06-04 20:12:34 +020071 if (!pdata || !pdata->hclk)
Philipp Zabelf0e46cc2009-06-04 20:12:31 +020072 goto out;
Philipp Zabeld6c9b5e2009-06-04 20:12:34 +020073
Magnus Damm8e7bfdb2011-05-06 11:02:33 +000074 irq = platform_get_irq(pdev, 0);
75 if (irq < 0) {
76 ret = irq;
77 goto out;
78 }
79
Ian Molton4a489982008-07-15 16:02:21 +010080 /* Tell the MFD core we are ready to be enabled */
81 if (cell->enable) {
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +010082 ret = cell->enable(pdev);
Ian Molton4a489982008-07-15 16:02:21 +010083 if (ret)
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +010084 goto out;
Ian Molton4a489982008-07-15 16:02:21 +010085 }
86
Kuninori Morimoto3b159a62013-11-20 00:30:55 -080087 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
88 if (!res)
89 return -EINVAL;
90
91 /* SD control register space size is 0x200, 0x400 for bus_shift=1 */
Kuninori Morimoto1e0bf162014-01-07 17:33:51 -080092 pdata->bus_shift = resource_size(res) >> 10;
Kuninori Morimoto5d60e502013-11-20 00:31:06 -080093 pdata->flags |= TMIO_MMC_HAVE_HIGH_REG;
Kuninori Morimoto3b159a62013-11-20 00:30:55 -080094
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +010095 ret = tmio_mmc_host_probe(&host, pdev, pdata);
Ian Molton4a489982008-07-15 16:02:21 +010096 if (ret)
Magnus Damm7ee422d2010-02-17 16:38:23 +090097 goto cell_disable;
Ian Molton4a489982008-07-15 16:02:21 +010098
Yong Zhangd9618e92011-09-22 16:59:04 +080099 ret = request_irq(irq, tmio_mmc_irq, IRQF_TRIGGER_FALLING,
100 dev_name(&pdev->dev), host);
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000101 if (ret)
102 goto host_remove;
103
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000104 pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000105 (unsigned long)host->ctl, irq);
Ian Molton4a489982008-07-15 16:02:21 +0100106
Ian Molton4a489982008-07-15 16:02:21 +0100107 return 0;
108
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000109host_remove:
110 tmio_mmc_host_remove(host);
Magnus Damm7ee422d2010-02-17 16:38:23 +0900111cell_disable:
112 if (cell->disable)
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100113 cell->disable(pdev);
Ian Molton4a489982008-07-15 16:02:21 +0100114out:
115 return ret;
116}
117
Bill Pemberton6e0ee712012-11-19 13:26:03 -0500118static int tmio_mmc_remove(struct platform_device *pdev)
Ian Molton4a489982008-07-15 16:02:21 +0100119{
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100120 const struct mfd_cell *cell = mfd_get_cell(pdev);
121 struct mmc_host *mmc = platform_get_drvdata(pdev);
Ian Molton4a489982008-07-15 16:02:21 +0100122
Ian Molton4a489982008-07-15 16:02:21 +0100123 if (mmc) {
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000124 struct tmio_mmc_host *host = mmc_priv(mmc);
125 free_irq(platform_get_irq(pdev, 0), host);
126 tmio_mmc_host_remove(host);
Magnus Damm7ee422d2010-02-17 16:38:23 +0900127 if (cell->disable)
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100128 cell->disable(pdev);
Ian Molton4a489982008-07-15 16:02:21 +0100129 }
130
131 return 0;
132}
133
134/* ------------------- device registration ----------------------- */
135
Ulf Hanssonc8964482013-10-23 14:57:50 +0200136static const struct dev_pm_ops tmio_mmc_dev_pm_ops = {
137 SET_SYSTEM_SLEEP_PM_OPS(tmio_mmc_suspend, tmio_mmc_resume)
138};
139
Ian Molton4a489982008-07-15 16:02:21 +0100140static struct platform_driver tmio_mmc_driver = {
141 .driver = {
142 .name = "tmio-mmc",
143 .owner = THIS_MODULE,
Ulf Hanssonc8964482013-10-23 14:57:50 +0200144 .pm = &tmio_mmc_dev_pm_ops,
Ian Molton4a489982008-07-15 16:02:21 +0100145 },
146 .probe = tmio_mmc_probe,
Bill Pemberton0433c142012-11-19 13:20:26 -0500147 .remove = tmio_mmc_remove,
Ian Molton4a489982008-07-15 16:02:21 +0100148};
149
Axel Lind1f81a62011-11-26 12:55:43 +0800150module_platform_driver(tmio_mmc_driver);
Ian Molton4a489982008-07-15 16:02:21 +0100151
152MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
153MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
154MODULE_LICENSE("GPL v2");
155MODULE_ALIAS("platform:tmio-mmc");