tmio_mmc.c 3.3 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
	int ret;

32
	ret = tmio_mmc_host_suspend(&dev->dev);
I
Ian Molton 已提交
33 34 35 36 37 38 39 40 41 42

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

	/* Tell the MFD core we are ready to be enabled */
47
	if (cell->resume)
48
		ret = cell->resume(dev);
I
Ian Molton 已提交
49

50 51
	if (!ret)
		ret = tmio_mmc_host_resume(&dev->dev);
I
Ian Molton 已提交
52 53 54 55 56 57 58 59

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

60
static int __devinit tmio_mmc_probe(struct platform_device *pdev)
I
Ian Molton 已提交
61
{
62
	const struct mfd_cell *cell = mfd_get_cell(pdev);
63
	struct tmio_mmc_data *pdata;
I
Ian Molton 已提交
64
	struct tmio_mmc_host *host;
65
	int ret = -EINVAL, irq;
I
Ian Molton 已提交
66

67
	if (pdev->num_resources != 2)
I
Ian Molton 已提交
68 69
		goto out;

70
	pdata = pdev->dev.platform_data;
71
	if (!pdata || !pdata->hclk)
72
		goto out;
73

74 75 76 77 78 79
	irq = platform_get_irq(pdev, 0);
	if (irq < 0) {
		ret = irq;
		goto out;
	}

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

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

91 92 93 94 95
	ret = request_irq(irq, tmio_mmc_irq, IRQF_DISABLED |
			  IRQF_TRIGGER_FALLING, dev_name(&pdev->dev), host);
	if (ret)
		goto host_remove;

96
	pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
97
		(unsigned long)host->ctl, irq);
I
Ian Molton 已提交
98 99 100

	return 0;

101 102
host_remove:
	tmio_mmc_host_remove(host);
103 104
cell_disable:
	if (cell->disable)
105
		cell->disable(pdev);
I
Ian Molton 已提交
106 107 108 109
out:
	return ret;
}

110
static int __devexit tmio_mmc_remove(struct platform_device *pdev)
I
Ian Molton 已提交
111
{
112 113
	const struct mfd_cell *cell = mfd_get_cell(pdev);
	struct mmc_host *mmc = platform_get_drvdata(pdev);
I
Ian Molton 已提交
114

115
	platform_set_drvdata(pdev, NULL);
I
Ian Molton 已提交
116 117

	if (mmc) {
118 119 120
		struct tmio_mmc_host *host = mmc_priv(mmc);
		free_irq(platform_get_irq(pdev, 0), host);
		tmio_mmc_host_remove(host);
121
		if (cell->disable)
122
			cell->disable(pdev);
I
Ian Molton 已提交
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 149 150 151 152 153 154 155 156 157 158
	}

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