blob: e897e7fc3b14cd996e3a04a8f0a98e24ef2e8ee6 [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 Hansson70a15e12014-08-25 12:28:20 +020033 ret = pm_runtime_force_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 Hansson70a15e12014-08-25 12:28:20 +020053 ret = pm_runtime_force_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);
Ian Molton25db67e2015-04-27 00:01:06 +010088 if (!res) {
89 ret = -EINVAL;
90 goto cell_disable;
91 }
Kuninori Morimoto3b159a62013-11-20 00:30:55 -080092
Kuninori Morimoto5d60e502013-11-20 00:31:06 -080093 pdata->flags |= TMIO_MMC_HAVE_HIGH_REG;
Kuninori Morimoto3b159a62013-11-20 00:30:55 -080094
Kuninori Morimoto94b110a2015-01-13 04:57:22 +000095 host = tmio_mmc_host_alloc(pdev);
96 if (!host)
Magnus Damm7ee422d2010-02-17 16:38:23 +090097 goto cell_disable;
Ian Molton4a489982008-07-15 16:02:21 +010098
Kuninori Morimoto7445bf92015-01-13 04:58:20 +000099 /* SD control register space size is 0x200, 0x400 for bus_shift=1 */
100 host->bus_shift = resource_size(res) >> 10;
101
Kuninori Morimoto94b110a2015-01-13 04:57:22 +0000102 ret = tmio_mmc_host_probe(host, pdata);
103 if (ret)
104 goto host_free;
105
Ian Moltonde501af2015-04-27 00:01:36 +0100106 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq,
107 IRQF_TRIGGER_FALLING,
Yong Zhangd9618e92011-09-22 16:59:04 +0800108 dev_name(&pdev->dev), host);
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000109 if (ret)
110 goto host_remove;
111
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000112 pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000113 (unsigned long)host->ctl, irq);
Ian Molton4a489982008-07-15 16:02:21 +0100114
Ian Molton4a489982008-07-15 16:02:21 +0100115 return 0;
116
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000117host_remove:
118 tmio_mmc_host_remove(host);
Kuninori Morimoto94b110a2015-01-13 04:57:22 +0000119host_free:
120 tmio_mmc_host_free(host);
Magnus Damm7ee422d2010-02-17 16:38:23 +0900121cell_disable:
122 if (cell->disable)
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100123 cell->disable(pdev);
Ian Molton4a489982008-07-15 16:02:21 +0100124out:
125 return ret;
126}
127
Bill Pemberton6e0ee712012-11-19 13:26:03 -0500128static int tmio_mmc_remove(struct platform_device *pdev)
Ian Molton4a489982008-07-15 16:02:21 +0100129{
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100130 const struct mfd_cell *cell = mfd_get_cell(pdev);
131 struct mmc_host *mmc = platform_get_drvdata(pdev);
Ian Molton4a489982008-07-15 16:02:21 +0100132
Ian Molton4a489982008-07-15 16:02:21 +0100133 if (mmc) {
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000134 struct tmio_mmc_host *host = mmc_priv(mmc);
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000135 tmio_mmc_host_remove(host);
Magnus Damm7ee422d2010-02-17 16:38:23 +0900136 if (cell->disable)
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100137 cell->disable(pdev);
Ian Molton4a489982008-07-15 16:02:21 +0100138 }
139
140 return 0;
141}
142
143/* ------------------- device registration ----------------------- */
144
Ulf Hanssonc8964482013-10-23 14:57:50 +0200145static const struct dev_pm_ops tmio_mmc_dev_pm_ops = {
146 SET_SYSTEM_SLEEP_PM_OPS(tmio_mmc_suspend, tmio_mmc_resume)
Rafael J. Wysocki6ed23b82014-12-04 00:34:11 +0100147 SET_RUNTIME_PM_OPS(tmio_mmc_host_runtime_suspend,
Ulf Hansson78f76df2014-08-25 12:12:02 +0200148 tmio_mmc_host_runtime_resume,
149 NULL)
Ulf Hanssonc8964482013-10-23 14:57:50 +0200150};
151
Ian Molton4a489982008-07-15 16:02:21 +0100152static struct platform_driver tmio_mmc_driver = {
153 .driver = {
154 .name = "tmio-mmc",
Ulf Hanssonc8964482013-10-23 14:57:50 +0200155 .pm = &tmio_mmc_dev_pm_ops,
Ian Molton4a489982008-07-15 16:02:21 +0100156 },
157 .probe = tmio_mmc_probe,
Bill Pemberton0433c142012-11-19 13:20:26 -0500158 .remove = tmio_mmc_remove,
Ian Molton4a489982008-07-15 16:02:21 +0100159};
160
Axel Lind1f81a62011-11-26 12:55:43 +0800161module_platform_driver(tmio_mmc_driver);
Ian Molton4a489982008-07-15 16:02:21 +0100162
163MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
164MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
165MODULE_LICENSE("GPL v2");
166MODULE_ALIAS("platform:tmio-mmc");