dw_mmc-pltfm.c 3.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * Synopsys DesignWare Multimedia Card Interface driver
 *
 * Copyright (C) 2009 NXP Semiconductors
 * Copyright (C) 2009, 2010 Imagination Technologies Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

13
#include <linux/err.h>
14 15 16 17 18 19 20 21 22
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/io.h>
#include <linux/irq.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/mmc/host.h>
#include <linux/mmc/mmc.h>
#include <linux/mmc/dw_mmc.h>
23 24
#include <linux/of.h>

25
#include "dw_mmc.h"
26
#include "dw_mmc-pltfm.h"
27

28
static void dw_mci_pltfm_prepare_command(struct dw_mci *host, u32 *cmdr)
29 30 31 32 33
{
	*cmdr |= SDMMC_CMD_USE_HOLD_REG;
}

static const struct dw_mci_drv_data rockchip_drv_data = {
34 35 36 37 38
	.prepare_command	= dw_mci_pltfm_prepare_command,
};

static const struct dw_mci_drv_data socfpga_drv_data = {
	.prepare_command	= dw_mci_pltfm_prepare_command,
39 40
};

41
int dw_mci_pltfm_register(struct platform_device *pdev,
42
			  const struct dw_mci_drv_data *drv_data)
43 44 45 46
{
	struct dw_mci *host;
	struct resource	*regs;

47
	host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL);
48 49 50 51
	if (!host)
		return -ENOMEM;

	host->irq = platform_get_irq(pdev, 0);
52 53
	if (host->irq < 0)
		return host->irq;
54

55
	host->drv_data = drv_data;
56
	host->dev = &pdev->dev;
57 58
	host->irq_flags = 0;
	host->pdata = pdev->dev.platform_data;
59 60

	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
61 62 63
	host->regs = devm_ioremap_resource(&pdev->dev, regs);
	if (IS_ERR(host->regs))
		return PTR_ERR(host->regs);
64

65
	platform_set_drvdata(pdev, host);
66
	return dw_mci_probe(host);
67
}
68 69
EXPORT_SYMBOL_GPL(dw_mci_pltfm_register);

70 71 72 73 74 75 76 77
#ifdef CONFIG_PM_SLEEP
/*
 * TODO: we should probably disable the clock to the card in the suspend path.
 */
static int dw_mci_pltfm_suspend(struct device *dev)
{
	struct dw_mci *host = dev_get_drvdata(dev);

78
	return dw_mci_suspend(host);
79 80 81 82 83 84
}

static int dw_mci_pltfm_resume(struct device *dev)
{
	struct dw_mci *host = dev_get_drvdata(dev);

85
	return dw_mci_resume(host);
86 87 88 89 90 91
}
#else
#define dw_mci_pltfm_suspend	NULL
#define dw_mci_pltfm_resume	NULL
#endif /* CONFIG_PM_SLEEP */

92 93
SIMPLE_DEV_PM_OPS(dw_mci_pltfm_pmops, dw_mci_pltfm_suspend, dw_mci_pltfm_resume);
EXPORT_SYMBOL_GPL(dw_mci_pltfm_pmops);
94

95 96
static const struct of_device_id dw_mci_pltfm_match[] = {
	{ .compatible = "snps,dw-mshc", },
97 98
	{ .compatible = "rockchip,rk2928-dw-mshc",
		.data = &rockchip_drv_data },
99 100
	{ .compatible = "altr,socfpga-dw-mshc",
		.data = &socfpga_drv_data },
101 102 103 104
	{},
};
MODULE_DEVICE_TABLE(of, dw_mci_pltfm_match);

105 106
static int dw_mci_pltfm_probe(struct platform_device *pdev)
{
107 108 109 110 111 112 113 114 115
	const struct dw_mci_drv_data *drv_data = NULL;
	const struct of_device_id *match;

	if (pdev->dev.of_node) {
		match = of_match_node(dw_mci_pltfm_match, pdev->dev.of_node);
		drv_data = match->data;
	}

	return dw_mci_pltfm_register(pdev, drv_data);
116 117 118 119 120 121 122 123 124 125 126
}

int dw_mci_pltfm_remove(struct platform_device *pdev)
{
	struct dw_mci *host = platform_get_drvdata(pdev);

	dw_mci_remove(host);
	return 0;
}
EXPORT_SYMBOL_GPL(dw_mci_pltfm_remove);

127
static struct platform_driver dw_mci_pltfm_driver = {
128
	.probe		= dw_mci_pltfm_probe,
129
	.remove		= dw_mci_pltfm_remove,
130 131
	.driver		= {
		.name		= "dw_mmc",
132
		.of_match_table	= dw_mci_pltfm_match,
133 134 135 136
		.pm		= &dw_mci_pltfm_pmops,
	},
};

137
module_platform_driver(dw_mci_pltfm_driver);
138 139 140 141 142

MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
MODULE_AUTHOR("NXP Semiconductor VietNam");
MODULE_AUTHOR("Imagination Technologies Ltd");
MODULE_LICENSE("GPL v2");