tmio_mmc.c 3.5 KB
Newer Older
I
Ian Molton 已提交
1
/*
2 3 4
 * Driver for the MMC / SD / SDIO cell found in:
 *
 * TC6393XB TC6391XB TC6387XB T7L66XB ASIC3
I
Ian Molton 已提交
5
 *
6 7
 * Copyright (C) 2007 Ian Molton
 * Copyright (C) 2004 Ian Molton
I
Ian Molton 已提交
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.
 */
13 14

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

22
#include "tmio_mmc.h"
I
Ian Molton 已提交
23

24 25
#ifdef CONFIG_PM_SLEEP
static int tmio_mmc_suspend(struct device *dev)
I
Ian Molton 已提交
26
{
27 28
	struct platform_device *pdev = to_platform_device(dev);
	const struct mfd_cell *cell = mfd_get_cell(pdev);
I
Ian Molton 已提交
29 30
	int ret;

31
	ret = pm_runtime_force_suspend(dev);
I
Ian Molton 已提交
32 33 34

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

	return ret;
}

40
static int tmio_mmc_resume(struct device *dev)
I
Ian Molton 已提交
41
{
42 43
	struct platform_device *pdev = to_platform_device(dev);
	const struct mfd_cell *cell = mfd_get_cell(pdev);
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(pdev);
I
Ian Molton 已提交
49

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

	return ret;
}
#endif

B
Bill Pemberton 已提交
57
static int tmio_mmc_probe(struct platform_device *pdev)
I
Ian Molton 已提交
58
{
59
	const struct mfd_cell *cell = mfd_get_cell(pdev);
60
	struct tmio_mmc_data *pdata;
I
Ian Molton 已提交
61
	struct tmio_mmc_host *host;
62
	struct resource *res;
63
	int ret = -EINVAL, irq;
I
Ian Molton 已提交
64

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

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

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

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

85
	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
86 87 88 89
	if (!res) {
		ret = -EINVAL;
		goto cell_disable;
	}
90

91
	pdata->flags |= TMIO_MMC_HAVE_HIGH_REG;
92

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

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

100 101 102 103
	ret = tmio_mmc_host_probe(host, pdata);
	if (ret)
		goto host_free;

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

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

	return 0;

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

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

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

	return 0;
}

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

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

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

159
module_platform_driver(tmio_mmc_driver);
I
Ian Molton 已提交
160 161 162 163 164

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