4 * Copyright (C) 2009 Magnus Damm
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Based on "Compaq ASIC3 support":
12 * Copyright 2001 Compaq Computer Corporation.
13 * Copyright 2004-2005 Phil Blundell
14 * Copyright 2007-2008 OpenedHand Ltd.
16 * Authors: Phil Blundell <pb@handhelds.org>,
17 * Samuel Ortiz <sameo@openedhand.com>
21 #include <linux/kernel.h>
22 #include <linux/clk.h>
23 #include <linux/slab.h>
24 #include <linux/platform_device.h>
25 #include <linux/mmc/host.h>
26 #include <linux/mfd/core.h>
27 #include <linux/mfd/tmio.h>
28 #include <linux/mfd/sh_mobile_sdhi.h>
30 struct sh_mobile_sdhi {
32 struct tmio_mmc_data mmc_data;
33 struct mfd_cell cell_mmc;
36 static struct resource sh_mobile_sdhi_resources[] = {
40 .flags = IORESOURCE_MEM,
45 .flags = IORESOURCE_IRQ,
49 static struct mfd_cell sh_mobile_sdhi_cell = {
51 .num_resources = ARRAY_SIZE(sh_mobile_sdhi_resources),
52 .resources = sh_mobile_sdhi_resources,
55 static void sh_mobile_sdhi_set_pwr(struct platform_device *tmio, int state)
57 struct platform_device *pdev = to_platform_device(tmio->dev.parent);
58 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
61 p->set_pwr(pdev, state);
64 static int __init sh_mobile_sdhi_probe(struct platform_device *pdev)
66 struct sh_mobile_sdhi *priv;
71 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
73 dev_err(&pdev->dev, "missing MEM resource\n");
75 irq = platform_get_irq(pdev, 0);
77 dev_err(&pdev->dev, "missing IRQ resource\n");
79 if (!mem || (irq < 0))
82 priv = kzalloc(sizeof(struct sh_mobile_sdhi), GFP_KERNEL);
84 dev_err(&pdev->dev, "kzalloc failed\n");
88 snprintf(clk_name, sizeof(clk_name), "sdhi%d", pdev->id);
89 priv->clk = clk_get(&pdev->dev, clk_name);
90 if (IS_ERR(priv->clk)) {
91 dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name);
92 ret = PTR_ERR(priv->clk);
97 clk_enable(priv->clk);
99 priv->mmc_data.hclk = clk_get_rate(priv->clk);
100 priv->mmc_data.set_pwr = sh_mobile_sdhi_set_pwr;
101 priv->mmc_data.capabilities = MMC_CAP_MMC_HIGHSPEED;
103 memcpy(&priv->cell_mmc, &sh_mobile_sdhi_cell, sizeof(priv->cell_mmc));
104 priv->cell_mmc.driver_data = &priv->mmc_data;
105 priv->cell_mmc.platform_data = &priv->cell_mmc;
106 priv->cell_mmc.data_size = sizeof(priv->cell_mmc);
108 platform_set_drvdata(pdev, priv);
110 ret = mfd_add_devices(&pdev->dev, pdev->id,
111 &priv->cell_mmc, 1, mem, irq);
113 clk_disable(priv->clk);
121 static int sh_mobile_sdhi_remove(struct platform_device *pdev)
123 struct sh_mobile_sdhi *priv = platform_get_drvdata(pdev);
125 mfd_remove_devices(&pdev->dev);
126 clk_disable(priv->clk);
133 static struct platform_driver sh_mobile_sdhi_driver = {
135 .name = "sh_mobile_sdhi",
136 .owner = THIS_MODULE,
138 .probe = sh_mobile_sdhi_probe,
139 .remove = __devexit_p(sh_mobile_sdhi_remove),
142 static int __init sh_mobile_sdhi_init(void)
144 return platform_driver_register(&sh_mobile_sdhi_driver);
147 static void __exit sh_mobile_sdhi_exit(void)
149 platform_driver_unregister(&sh_mobile_sdhi_driver);
152 module_init(sh_mobile_sdhi_init);
153 module_exit(sh_mobile_sdhi_exit);
155 MODULE_DESCRIPTION("SuperH Mobile SDHI driver");
156 MODULE_AUTHOR("Magnus Damm");
157 MODULE_LICENSE("GPL v2");