tmio_mmc.c 3.6 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
#ifdef CONFIG_PM_SLEEP
static int tmio_mmc_suspend(struct device *dev)
I
Ian Molton 已提交
28
{
29 30
	struct platform_device *pdev = to_platform_device(dev);
	const struct mfd_cell *cell = mfd_get_cell(pdev);
I
Ian Molton 已提交
31 32
	int ret;

33
	ret = pm_runtime_force_suspend(dev);
I
Ian Molton 已提交
34 35 36

	/* Tell MFD core it can disable us now.*/
	if (!ret && cell->disable)
37
		cell->disable(pdev);
I
Ian Molton 已提交
38 39 40 41

	return ret;
}

42
static int tmio_mmc_resume(struct device *dev)
I
Ian Molton 已提交
43
{
44 45
	struct platform_device *pdev = to_platform_device(dev);
	const struct mfd_cell *cell = mfd_get_cell(pdev);
I
Ian Molton 已提交
46 47 48
	int ret = 0;

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

52
	if (!ret)
53
		ret = pm_runtime_force_resume(dev);
I
Ian Molton 已提交
54 55 56 57 58

	return ret;
}
#endif

B
Bill Pemberton 已提交
59
static int tmio_mmc_probe(struct platform_device *pdev)
I
Ian Molton 已提交
60
{
61
	const struct mfd_cell *cell = mfd_get_cell(pdev);
62
	struct tmio_mmc_data *pdata;
I
Ian Molton 已提交
63
	struct tmio_mmc_host *host;
64
	struct resource *res;
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
	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
88 89 90 91
	if (!res) {
		ret = -EINVAL;
		goto cell_disable;
	}
92

93
	pdata->flags |= TMIO_MMC_HAVE_HIGH_REG;
94

95 96
	host = tmio_mmc_host_alloc(pdev);
	if (!host)
97
		goto cell_disable;
I
Ian Molton 已提交
98

99 100 101
	/* SD control register space size is 0x200, 0x400 for bus_shift=1 */
	host->bus_shift = resource_size(res) >> 10;

102 103 104 105
	ret = tmio_mmc_host_probe(host, pdata);
	if (ret)
		goto host_free;

I
Ian Molton 已提交
106 107
	ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq,
				IRQF_TRIGGER_FALLING,
Y
Yong Zhang 已提交
108
				dev_name(&pdev->dev), host);
109 110 111
	if (ret)
		goto host_remove;

112
	pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
113
		(unsigned long)host->ctl, irq);
I
Ian Molton 已提交
114 115 116

	return 0;

117 118
host_remove:
	tmio_mmc_host_remove(host);
119 120
host_free:
	tmio_mmc_host_free(host);
121 122
cell_disable:
	if (cell->disable)
123
		cell->disable(pdev);
I
Ian Molton 已提交
124 125 126 127
out:
	return ret;
}

B
Bill Pemberton 已提交
128
static int tmio_mmc_remove(struct platform_device *pdev)
I
Ian Molton 已提交
129
{
130 131
	const struct mfd_cell *cell = mfd_get_cell(pdev);
	struct mmc_host *mmc = platform_get_drvdata(pdev);
I
Ian Molton 已提交
132 133

	if (mmc) {
134 135
		struct tmio_mmc_host *host = mmc_priv(mmc);
		tmio_mmc_host_remove(host);
136
		if (cell->disable)
137
			cell->disable(pdev);
I
Ian Molton 已提交
138 139 140 141 142 143 144
	}

	return 0;
}

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

145 146
static const struct dev_pm_ops tmio_mmc_dev_pm_ops = {
	SET_SYSTEM_SLEEP_PM_OPS(tmio_mmc_suspend, tmio_mmc_resume)
147
	SET_RUNTIME_PM_OPS(tmio_mmc_host_runtime_suspend,
148 149
			tmio_mmc_host_runtime_resume,
			NULL)
150 151
};

I
Ian Molton 已提交
152 153 154
static struct platform_driver tmio_mmc_driver = {
	.driver = {
		.name = "tmio-mmc",
155
		.pm = &tmio_mmc_dev_pm_ops,
I
Ian Molton 已提交
156 157
	},
	.probe = tmio_mmc_probe,
B
Bill Pemberton 已提交
158
	.remove = tmio_mmc_remove,
I
Ian Molton 已提交
159 160
};

161
module_platform_driver(tmio_mmc_driver);
I
Ian Molton 已提交
162 163 164 165 166

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