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

B
Bill Pemberton 已提交
60
static int 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
	struct resource *res;
66
	int ret = -EINVAL, irq;
I
Ian Molton 已提交
67

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

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

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

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

88 89 90 91 92 93 94
	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (!res)
		return -EINVAL;

	/* SD control register space size is 0x200, 0x400 for bus_shift=1 */
	pdata->bus_shift = resource_size(res_ctl) >> 10;

95
	ret = tmio_mmc_host_probe(&host, pdev, pdata);
I
Ian Molton 已提交
96
	if (ret)
97
		goto cell_disable;
I
Ian Molton 已提交
98

Y
Yong Zhang 已提交
99 100
	ret = request_irq(irq, tmio_mmc_irq, IRQF_TRIGGER_FALLING,
				dev_name(&pdev->dev), host);
101 102 103
	if (ret)
		goto host_remove;

104
	pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
105
		(unsigned long)host->ctl, irq);
I
Ian Molton 已提交
106 107 108

	return 0;

109 110
host_remove:
	tmio_mmc_host_remove(host);
111 112
cell_disable:
	if (cell->disable)
113
		cell->disable(pdev);
I
Ian Molton 已提交
114 115 116 117
out:
	return ret;
}

B
Bill Pemberton 已提交
118
static int tmio_mmc_remove(struct platform_device *pdev)
I
Ian Molton 已提交
119
{
120 121
	const struct mfd_cell *cell = mfd_get_cell(pdev);
	struct mmc_host *mmc = platform_get_drvdata(pdev);
I
Ian Molton 已提交
122 123

	if (mmc) {
124 125 126
		struct tmio_mmc_host *host = mmc_priv(mmc);
		free_irq(platform_get_irq(pdev, 0), host);
		tmio_mmc_host_remove(host);
127
		if (cell->disable)
128
			cell->disable(pdev);
I
Ian Molton 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141
	}

	return 0;
}

/* ------------------- device registration ----------------------- */

static struct platform_driver tmio_mmc_driver = {
	.driver = {
		.name = "tmio-mmc",
		.owner = THIS_MODULE,
	},
	.probe = tmio_mmc_probe,
B
Bill Pemberton 已提交
142
	.remove = tmio_mmc_remove,
I
Ian Molton 已提交
143 144 145 146
	.suspend = tmio_mmc_suspend,
	.resume = tmio_mmc_resume,
};

147
module_platform_driver(tmio_mmc_driver);
I
Ian Molton 已提交
148 149 150 151 152

MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:tmio-mmc");