2 * Toshiba TC6387XB support
3 * Copyright (c) 2005 Ian Molton
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This file contains TC6387XB base support.
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/clk.h>
16 #include <linux/err.h>
17 #include <linux/mfd/core.h>
18 #include <linux/mfd/tmio.h>
19 #include <linux/mfd/tc6387xb.h>
20 #include <linux/slab.h>
32 static struct resource tc6387xb_mmc_resources[] = {
36 .flags = IORESOURCE_MEM,
41 .flags = IORESOURCE_IRQ,
45 /*--------------------------------------------------------------------------*/
48 static int tc6387xb_suspend(struct platform_device *dev, pm_message_t state)
50 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
51 struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev);
53 if (pdata && pdata->suspend)
55 clk_disable_unprepare(tc6387xb->clk32k);
60 static int tc6387xb_resume(struct platform_device *dev)
62 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
63 struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev);
65 clk_prepare_enable(tc6387xb->clk32k);
66 if (pdata && pdata->resume)
69 tmio_core_mmc_resume(tc6387xb->scr + 0x200, 0,
70 tc6387xb_mmc_resources[0].start & 0xfffe);
75 #define tc6387xb_suspend NULL
76 #define tc6387xb_resume NULL
79 /*--------------------------------------------------------------------------*/
81 static void tc6387xb_mmc_pwr(struct platform_device *mmc, int state)
83 struct platform_device *dev = to_platform_device(mmc->dev.parent);
84 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
86 tmio_core_mmc_pwr(tc6387xb->scr + 0x200, 0, state);
89 static void tc6387xb_mmc_clk_div(struct platform_device *mmc, int state)
91 struct platform_device *dev = to_platform_device(mmc->dev.parent);
92 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
94 tmio_core_mmc_clk_div(tc6387xb->scr + 0x200, 0, state);
98 static int tc6387xb_mmc_enable(struct platform_device *mmc)
100 struct platform_device *dev = to_platform_device(mmc->dev.parent);
101 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
103 clk_prepare_enable(tc6387xb->clk32k);
105 tmio_core_mmc_enable(tc6387xb->scr + 0x200, 0,
106 tc6387xb_mmc_resources[0].start & 0xfffe);
111 static int tc6387xb_mmc_disable(struct platform_device *mmc)
113 struct platform_device *dev = to_platform_device(mmc->dev.parent);
114 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
116 clk_disable_unprepare(tc6387xb->clk32k);
121 static struct tmio_mmc_data tc6387xb_mmc_data = {
123 .set_pwr = tc6387xb_mmc_pwr,
124 .set_clk_div = tc6387xb_mmc_clk_div,
127 /*--------------------------------------------------------------------------*/
129 static const struct mfd_cell tc6387xb_cells[] = {
130 [TC6387XB_CELL_MMC] = {
132 .enable = tc6387xb_mmc_enable,
133 .disable = tc6387xb_mmc_disable,
134 .platform_data = &tc6387xb_mmc_data,
135 .pdata_size = sizeof(tc6387xb_mmc_data),
136 .num_resources = ARRAY_SIZE(tc6387xb_mmc_resources),
137 .resources = tc6387xb_mmc_resources,
141 static int tc6387xb_probe(struct platform_device *dev)
143 struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev);
144 struct resource *iomem, *rscr;
146 struct tc6387xb *tc6387xb;
149 iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
153 tc6387xb = kzalloc(sizeof(*tc6387xb), GFP_KERNEL);
157 ret = platform_get_irq(dev, 0);
163 clk32k = clk_get(&dev->dev, "CLK_CK32K");
164 if (IS_ERR(clk32k)) {
165 ret = PTR_ERR(clk32k);
169 rscr = &tc6387xb->rscr;
170 rscr->name = "tc6387xb-core";
171 rscr->start = iomem->start;
172 rscr->end = iomem->start + 0xff;
173 rscr->flags = IORESOURCE_MEM;
175 ret = request_resource(iomem, rscr);
179 tc6387xb->scr = ioremap(rscr->start, resource_size(rscr));
180 if (!tc6387xb->scr) {
185 tc6387xb->clk32k = clk32k;
186 platform_set_drvdata(dev, tc6387xb);
188 if (pdata && pdata->enable)
191 dev_info(&dev->dev, "Toshiba tc6387xb initialised\n");
193 ret = mfd_add_devices(&dev->dev, dev->id, tc6387xb_cells,
194 ARRAY_SIZE(tc6387xb_cells), iomem, irq, NULL);
199 iounmap(tc6387xb->scr);
201 release_resource(&tc6387xb->rscr);
210 static int tc6387xb_remove(struct platform_device *dev)
212 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
214 mfd_remove_devices(&dev->dev);
215 iounmap(tc6387xb->scr);
216 release_resource(&tc6387xb->rscr);
217 clk_disable_unprepare(tc6387xb->clk32k);
218 clk_put(tc6387xb->clk32k);
225 static struct platform_driver tc6387xb_platform_driver = {
229 .probe = tc6387xb_probe,
230 .remove = tc6387xb_remove,
231 .suspend = tc6387xb_suspend,
232 .resume = tc6387xb_resume,
235 module_platform_driver(tc6387xb_platform_driver);
237 MODULE_DESCRIPTION("Toshiba TC6387XB core driver");
238 MODULE_LICENSE("GPL v2");
239 MODULE_AUTHOR("Ian Molton");
240 MODULE_ALIAS("platform:tc6387xb");