tmio_mmc.c 3.1 KB
Newer Older
I
Ian Molton 已提交
1
/*
2
 * linux/drivers/mmc/host/tmio_mmc.c
I
Ian Molton 已提交
3
 *
4 5
 * Copyright (C) 2007 Ian Molton
 * Copyright (C) 2004 Ian Molton
I
Ian Molton 已提交
6 7 8 9 10 11 12
 *
 * 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:
 *
13
 * TC6393XB TC6391XB TC6387XB T7L66XB ASIC3
I
Ian Molton 已提交
14
 */
15 16

#include <linux/device.h>
I
Ian Molton 已提交
17 18
#include <linux/mfd/core.h>
#include <linux/mfd/tmio.h>
19 20 21 22
#include <linux/mmc/host.h>
#include <linux/module.h>
#include <linux/pagemap.h>
#include <linux/scatterlist.h>
23

24
#include "tmio_mmc.h"
I
Ian Molton 已提交
25 26 27 28

#ifdef CONFIG_PM
static int tmio_mmc_suspend(struct platform_device *dev, pm_message_t state)
{
29
	const struct mfd_cell *cell = mfd_get_cell(dev);
I
Ian Molton 已提交
30 31 32
	struct mmc_host *mmc = platform_get_drvdata(dev);
	int ret;

33
	ret = mmc_suspend_host(mmc);
I
Ian Molton 已提交
34 35 36 37 38 39 40 41 42 43

	/* 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)
{
44
	const struct mfd_cell *cell = mfd_get_cell(dev);
I
Ian Molton 已提交
45 46 47 48
	struct mmc_host *mmc = platform_get_drvdata(dev);
	int ret = 0;

	/* Tell the MFD core we are ready to be enabled */
49 50
	if (cell->resume) {
		ret = cell->resume(dev);
I
Ian Molton 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64
		if (ret)
			goto out;
	}

	mmc_resume_host(mmc);

out:
	return ret;
}
#else
#define tmio_mmc_suspend NULL
#define tmio_mmc_resume NULL
#endif

65
static int __devinit tmio_mmc_probe(struct platform_device *pdev)
I
Ian Molton 已提交
66
{
67
	const struct mfd_cell *cell = mfd_get_cell(pdev);
68
	struct tmio_mmc_data *pdata;
I
Ian Molton 已提交
69
	struct tmio_mmc_host *host;
70
	int ret = -EINVAL;
I
Ian Molton 已提交
71

72
	if (pdev->num_resources != 2)
I
Ian Molton 已提交
73 74
		goto out;

75
	pdata = mfd_get_data(pdev);
76
	if (!pdata || !pdata->hclk)
77
		goto out;
78

I
Ian Molton 已提交
79 80
	/* Tell the MFD core we are ready to be enabled */
	if (cell->enable) {
81
		ret = cell->enable(pdev);
I
Ian Molton 已提交
82
		if (ret)
83
			goto out;
I
Ian Molton 已提交
84 85
	}

86
	ret = tmio_mmc_host_probe(&host, pdev, pdata);
I
Ian Molton 已提交
87
	if (ret)
88
		goto cell_disable;
I
Ian Molton 已提交
89

90 91
	pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
		(unsigned long)host->ctl, host->irq);
I
Ian Molton 已提交
92 93 94

	return 0;

95 96
cell_disable:
	if (cell->disable)
97
		cell->disable(pdev);
I
Ian Molton 已提交
98 99 100 101
out:
	return ret;
}

102
static int __devexit tmio_mmc_remove(struct platform_device *pdev)
I
Ian Molton 已提交
103
{
104 105
	const struct mfd_cell *cell = mfd_get_cell(pdev);
	struct mmc_host *mmc = platform_get_drvdata(pdev);
I
Ian Molton 已提交
106

107
	platform_set_drvdata(pdev, NULL);
I
Ian Molton 已提交
108 109

	if (mmc) {
110
		tmio_mmc_host_remove(mmc_priv(mmc));
111
		if (cell->disable)
112
			cell->disable(pdev);
I
Ian Molton 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
	}

	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");