2008-07-15 09:02:21 -06:00
|
|
|
/*
|
2011-03-23 05:42:44 -06:00
|
|
|
* linux/drivers/mmc/host/tmio_mmc.c
|
2008-07-15 09:02:21 -06:00
|
|
|
*
|
2011-03-23 05:42:44 -06:00
|
|
|
* Copyright (C) 2007 Ian Molton
|
|
|
|
* Copyright (C) 2004 Ian Molton
|
2008-07-15 09:02:21 -06:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Driver for the MMC / SD / SDIO cell found in:
|
|
|
|
*
|
2009-06-04 12:12:37 -06:00
|
|
|
* TC6393XB TC6391XB TC6387XB T7L66XB ASIC3
|
2008-07-15 09:02:21 -06:00
|
|
|
*/
|
2010-11-23 09:24:11 -07:00
|
|
|
|
|
|
|
#include <linux/device.h>
|
2008-07-15 09:02:21 -06:00
|
|
|
#include <linux/mfd/core.h>
|
|
|
|
#include <linux/mfd/tmio.h>
|
2010-11-23 09:24:11 -07:00
|
|
|
#include <linux/mmc/host.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/scatterlist.h>
|
2011-01-05 15:36:14 -07:00
|
|
|
|
2011-03-23 05:42:44 -06:00
|
|
|
#include "tmio_mmc.h"
|
2008-07-15 09:02:21 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int tmio_mmc_suspend(struct platform_device *dev, pm_message_t state)
|
|
|
|
{
|
2011-03-01 13:32:20 -07:00
|
|
|
const struct mfd_cell *cell = mfd_get_cell(dev);
|
2008-07-15 09:02:21 -06:00
|
|
|
struct mmc_host *mmc = platform_get_drvdata(dev);
|
|
|
|
int ret;
|
|
|
|
|
2011-05-05 10:13:12 -06:00
|
|
|
ret = tmio_mmc_host_suspend(&dev->dev);
|
2008-07-15 09:02:21 -06:00
|
|
|
|
|
|
|
/* Tell MFD core it can disable us now.*/
|
|
|
|
if (!ret && cell->disable)
|
|
|
|
cell->disable(dev);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tmio_mmc_resume(struct platform_device *dev)
|
|
|
|
{
|
2011-03-01 13:32:20 -07:00
|
|
|
const struct mfd_cell *cell = mfd_get_cell(dev);
|
2008-07-15 09:02:21 -06:00
|
|
|
struct mmc_host *mmc = platform_get_drvdata(dev);
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* Tell the MFD core we are ready to be enabled */
|
2011-05-05 10:13:12 -06:00
|
|
|
if (cell->resume)
|
2010-01-06 05:51:48 -07:00
|
|
|
ret = cell->resume(dev);
|
2008-07-15 09:02:21 -06:00
|
|
|
|
2011-05-05 10:13:12 -06:00
|
|
|
if (!ret)
|
|
|
|
ret = tmio_mmc_host_resume(&dev->dev);
|
2008-07-15 09:02:21 -06:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define tmio_mmc_suspend NULL
|
|
|
|
#define tmio_mmc_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2011-03-23 05:42:44 -06:00
|
|
|
static int __devinit tmio_mmc_probe(struct platform_device *pdev)
|
2008-07-15 09:02:21 -06:00
|
|
|
{
|
2011-03-23 05:42:44 -06:00
|
|
|
const struct mfd_cell *cell = mfd_get_cell(pdev);
|
2009-06-04 12:12:31 -06:00
|
|
|
struct tmio_mmc_data *pdata;
|
2008-07-15 09:02:21 -06:00
|
|
|
struct tmio_mmc_host *host;
|
2011-05-06 05:02:33 -06:00
|
|
|
int ret = -EINVAL, irq;
|
2008-07-15 09:02:21 -06:00
|
|
|
|
2011-03-23 05:42:44 -06:00
|
|
|
if (pdev->num_resources != 2)
|
2008-07-15 09:02:21 -06:00
|
|
|
goto out;
|
|
|
|
|
2011-03-23 05:42:44 -06:00
|
|
|
pdata = mfd_get_data(pdev);
|
2009-06-04 12:12:34 -06:00
|
|
|
if (!pdata || !pdata->hclk)
|
2009-06-04 12:12:31 -06:00
|
|
|
goto out;
|
2009-06-04 12:12:34 -06:00
|
|
|
|
2011-05-06 05:02:33 -06:00
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
|
|
if (irq < 0) {
|
|
|
|
ret = irq;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2008-07-15 09:02:21 -06:00
|
|
|
/* Tell the MFD core we are ready to be enabled */
|
|
|
|
if (cell->enable) {
|
2011-03-23 05:42:44 -06:00
|
|
|
ret = cell->enable(pdev);
|
2008-07-15 09:02:21 -06:00
|
|
|
if (ret)
|
2011-03-23 05:42:44 -06:00
|
|
|
goto out;
|
2008-07-15 09:02:21 -06:00
|
|
|
}
|
|
|
|
|
2011-03-23 05:42:44 -06:00
|
|
|
ret = tmio_mmc_host_probe(&host, pdev, pdata);
|
2008-07-15 09:02:21 -06:00
|
|
|
if (ret)
|
2010-02-17 00:38:23 -07:00
|
|
|
goto cell_disable;
|
2008-07-15 09:02:21 -06:00
|
|
|
|
2011-05-06 05:02:33 -06:00
|
|
|
ret = request_irq(irq, tmio_mmc_irq, IRQF_DISABLED |
|
|
|
|
IRQF_TRIGGER_FALLING, dev_name(&pdev->dev), host);
|
|
|
|
if (ret)
|
|
|
|
goto host_remove;
|
|
|
|
|
2010-05-19 12:34:22 -06:00
|
|
|
pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
|
2011-05-06 05:02:33 -06:00
|
|
|
(unsigned long)host->ctl, irq);
|
2008-07-15 09:02:21 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2011-05-06 05:02:33 -06:00
|
|
|
host_remove:
|
|
|
|
tmio_mmc_host_remove(host);
|
2010-02-17 00:38:23 -07:00
|
|
|
cell_disable:
|
|
|
|
if (cell->disable)
|
2011-03-23 05:42:44 -06:00
|
|
|
cell->disable(pdev);
|
2008-07-15 09:02:21 -06:00
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-23 05:42:44 -06:00
|
|
|
static int __devexit tmio_mmc_remove(struct platform_device *pdev)
|
2008-07-15 09:02:21 -06:00
|
|
|
{
|
2011-03-23 05:42:44 -06:00
|
|
|
const struct mfd_cell *cell = mfd_get_cell(pdev);
|
|
|
|
struct mmc_host *mmc = platform_get_drvdata(pdev);
|
2008-07-15 09:02:21 -06:00
|
|
|
|
2011-03-23 05:42:44 -06:00
|
|
|
platform_set_drvdata(pdev, NULL);
|
2008-07-15 09:02:21 -06:00
|
|
|
|
|
|
|
if (mmc) {
|
2011-05-06 05:02:33 -06:00
|
|
|
struct tmio_mmc_host *host = mmc_priv(mmc);
|
|
|
|
free_irq(platform_get_irq(pdev, 0), host);
|
|
|
|
tmio_mmc_host_remove(host);
|
2010-02-17 00:38:23 -07:00
|
|
|
if (cell->disable)
|
2011-03-23 05:42:44 -06:00
|
|
|
cell->disable(pdev);
|
2008-07-15 09:02:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------- device registration ----------------------- */
|
|
|
|
|
|
|
|
static struct platform_driver tmio_mmc_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "tmio-mmc",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.probe = tmio_mmc_probe,
|
|
|
|
.remove = __devexit_p(tmio_mmc_remove),
|
|
|
|
.suspend = tmio_mmc_suspend,
|
|
|
|
.resume = tmio_mmc_resume,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int __init tmio_mmc_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&tmio_mmc_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit tmio_mmc_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&tmio_mmc_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(tmio_mmc_init);
|
|
|
|
module_exit(tmio_mmc_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
|
|
|
|
MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_ALIAS("platform:tmio-mmc");
|