blob: f746df493892c160a9623b9687c17c81dadcd66e [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);
88 if (!res)
89 return -EINVAL;
90
Kuninori Morimoto5d60e502013-11-20 00:31:06 -080091 pdata->flags |= TMIO_MMC_HAVE_HIGH_REG;
Kuninori Morimoto3b159a62013-11-20 00:30:55 -080092
Kuninori Morimoto94b110a2015-01-13 04:57:22 +000093 host = tmio_mmc_host_alloc(pdev);
94 if (!host)
Magnus Damm7ee422d2010-02-17 16:38:23 +090095 goto cell_disable;
Ian Molton4a489982008-07-15 16:02:21 +010096
Kuninori Morimoto7445bf92015-01-13 04:58:20 +000097 /* SD control register space size is 0x200, 0x400 for bus_shift=1 */
98 host->bus_shift = resource_size(res) >> 10;
99
Kuninori Morimoto94b110a2015-01-13 04:57:22 +0000100 ret = tmio_mmc_host_probe(host, pdata);
101 if (ret)
102 goto host_free;
103
Yong Zhangd9618e92011-09-22 16:59:04 +0800104 ret = request_irq(irq, tmio_mmc_irq, IRQF_TRIGGER_FALLING,
105 dev_name(&pdev->dev), host);
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000106 if (ret)
107 goto host_remove;
108
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000109 pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000110 (unsigned long)host->ctl, irq);
Ian Molton4a489982008-07-15 16:02:21 +0100111
Ian Molton4a489982008-07-15 16:02:21 +0100112 return 0;
113
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000114host_remove:
115 tmio_mmc_host_remove(host);
Kuninori Morimoto94b110a2015-01-13 04:57:22 +0000116host_free:
117 tmio_mmc_host_free(host);
Magnus Damm7ee422d2010-02-17 16:38:23 +0900118cell_disable:
119 if (cell->disable)
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100120 cell->disable(pdev);
Ian Molton4a489982008-07-15 16:02:21 +0100121out:
122 return ret;
123}
124
Bill Pemberton6e0ee712012-11-19 13:26:03 -0500125static int tmio_mmc_remove(struct platform_device *pdev)
Ian Molton4a489982008-07-15 16:02:21 +0100126{
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100127 const struct mfd_cell *cell = mfd_get_cell(pdev);
128 struct mmc_host *mmc = platform_get_drvdata(pdev);
Ian Molton4a489982008-07-15 16:02:21 +0100129
Ian Molton4a489982008-07-15 16:02:21 +0100130 if (mmc) {
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000131 struct tmio_mmc_host *host = mmc_priv(mmc);
132 free_irq(platform_get_irq(pdev, 0), host);
133 tmio_mmc_host_remove(host);
Magnus Damm7ee422d2010-02-17 16:38:23 +0900134 if (cell->disable)
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100135 cell->disable(pdev);
Ian Molton4a489982008-07-15 16:02:21 +0100136 }
137
138 return 0;
139}
140
141/* ------------------- device registration ----------------------- */
142
Ulf Hanssonc8964482013-10-23 14:57:50 +0200143static const struct dev_pm_ops tmio_mmc_dev_pm_ops = {
144 SET_SYSTEM_SLEEP_PM_OPS(tmio_mmc_suspend, tmio_mmc_resume)
Rafael J. Wysocki6ed23b82014-12-04 00:34:11 +0100145 SET_RUNTIME_PM_OPS(tmio_mmc_host_runtime_suspend,
Ulf Hansson78f76df2014-08-25 12:12:02 +0200146 tmio_mmc_host_runtime_resume,
147 NULL)
Ulf Hanssonc8964482013-10-23 14:57:50 +0200148};
149
Ian Molton4a489982008-07-15 16:02:21 +0100150static struct platform_driver tmio_mmc_driver = {
151 .driver = {
152 .name = "tmio-mmc",
Ulf Hanssonc8964482013-10-23 14:57:50 +0200153 .pm = &tmio_mmc_dev_pm_ops,
Ian Molton4a489982008-07-15 16:02:21 +0100154 },
155 .probe = tmio_mmc_probe,
Bill Pemberton0433c142012-11-19 13:20:26 -0500156 .remove = tmio_mmc_remove,
Ian Molton4a489982008-07-15 16:02:21 +0100157};
158
Axel Lind1f81a62011-11-26 12:55:43 +0800159module_platform_driver(tmio_mmc_driver);
Ian Molton4a489982008-07-15 16:02:21 +0100160
161MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
162MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
163MODULE_LICENSE("GPL v2");
164MODULE_ALIAS("platform:tmio-mmc");