blob: 8860d4d2bc22329cc7d8b5335e537695bfadf213 [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 int ret;
31
Guennadi Liakhovetskie6ee7182011-05-05 16:13:12 +000032 ret = tmio_mmc_host_suspend(&dev->dev);
Ian Molton4a489982008-07-15 16:02:21 +010033
34 /* Tell MFD core it can disable us now.*/
35 if (!ret && cell->disable)
36 cell->disable(dev);
37
38 return ret;
39}
40
41static int tmio_mmc_resume(struct platform_device *dev)
42{
Andres Salomon944dc032011-03-01 12:32:20 -080043 const struct mfd_cell *cell = mfd_get_cell(dev);
Ian Molton4a489982008-07-15 16:02:21 +010044 int ret = 0;
45
Ian Molton4a489982008-07-15 16:02:21 +010046 /* Tell the MFD core we are ready to be enabled */
Guennadi Liakhovetskie6ee7182011-05-05 16:13:12 +000047 if (cell->resume)
Ian Molton64e88672010-01-06 13:51:48 +010048 ret = cell->resume(dev);
Ian Molton4a489982008-07-15 16:02:21 +010049
Guennadi Liakhovetskie6ee7182011-05-05 16:13:12 +000050 if (!ret)
51 ret = tmio_mmc_host_resume(&dev->dev);
Ian Molton4a489982008-07-15 16:02:21 +010052
Ian Molton4a489982008-07-15 16:02:21 +010053 return ret;
54}
55#else
56#define tmio_mmc_suspend NULL
57#define tmio_mmc_resume NULL
58#endif
59
Bill Pembertonc3be1ef2012-11-19 13:23:06 -050060static int tmio_mmc_probe(struct platform_device *pdev)
Ian Molton4a489982008-07-15 16:02:21 +010061{
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +010062 const struct mfd_cell *cell = mfd_get_cell(pdev);
Philipp Zabelf0e46cc2009-06-04 20:12:31 +020063 struct tmio_mmc_data *pdata;
Ian Molton4a489982008-07-15 16:02:21 +010064 struct tmio_mmc_host *host;
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
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +010087 ret = tmio_mmc_host_probe(&host, pdev, pdata);
Ian Molton4a489982008-07-15 16:02:21 +010088 if (ret)
Magnus Damm7ee422d2010-02-17 16:38:23 +090089 goto cell_disable;
Ian Molton4a489982008-07-15 16:02:21 +010090
Yong Zhangd9618e92011-09-22 16:59:04 +080091 ret = request_irq(irq, tmio_mmc_irq, IRQF_TRIGGER_FALLING,
92 dev_name(&pdev->dev), host);
Magnus Damm8e7bfdb2011-05-06 11:02:33 +000093 if (ret)
94 goto host_remove;
95
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +000096 pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
Magnus Damm8e7bfdb2011-05-06 11:02:33 +000097 (unsigned long)host->ctl, irq);
Ian Molton4a489982008-07-15 16:02:21 +010098
Ian Molton4a489982008-07-15 16:02:21 +010099 return 0;
100
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000101host_remove:
102 tmio_mmc_host_remove(host);
Magnus Damm7ee422d2010-02-17 16:38:23 +0900103cell_disable:
104 if (cell->disable)
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100105 cell->disable(pdev);
Ian Molton4a489982008-07-15 16:02:21 +0100106out:
107 return ret;
108}
109
Bill Pemberton6e0ee712012-11-19 13:26:03 -0500110static int tmio_mmc_remove(struct platform_device *pdev)
Ian Molton4a489982008-07-15 16:02:21 +0100111{
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100112 const struct mfd_cell *cell = mfd_get_cell(pdev);
113 struct mmc_host *mmc = platform_get_drvdata(pdev);
Ian Molton4a489982008-07-15 16:02:21 +0100114
Ian Molton4a489982008-07-15 16:02:21 +0100115 if (mmc) {
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000116 struct tmio_mmc_host *host = mmc_priv(mmc);
117 free_irq(platform_get_irq(pdev, 0), host);
118 tmio_mmc_host_remove(host);
Magnus Damm7ee422d2010-02-17 16:38:23 +0900119 if (cell->disable)
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100120 cell->disable(pdev);
Ian Molton4a489982008-07-15 16:02:21 +0100121 }
122
123 return 0;
124}
125
126/* ------------------- device registration ----------------------- */
127
128static struct platform_driver tmio_mmc_driver = {
129 .driver = {
130 .name = "tmio-mmc",
131 .owner = THIS_MODULE,
132 },
133 .probe = tmio_mmc_probe,
Bill Pemberton0433c142012-11-19 13:20:26 -0500134 .remove = tmio_mmc_remove,
Ian Molton4a489982008-07-15 16:02:21 +0100135 .suspend = tmio_mmc_suspend,
136 .resume = tmio_mmc_resume,
137};
138
Axel Lind1f81a62011-11-26 12:55:43 +0800139module_platform_driver(tmio_mmc_driver);
Ian Molton4a489982008-07-15 16:02:21 +0100140
141MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
142MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
143MODULE_LICENSE("GPL v2");
144MODULE_ALIAS("platform:tmio-mmc");