blob: 85fab3729102545ddf0ac609f78f29804ae19846 [file] [log] [blame]
Ian Moltoncbdfb422008-07-15 15:12:52 +01001/*
2 * Toshiba TC6387XB support
3 * Copyright (c) 2005 Ian Molton
4 *
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.
8 *
9 * This file contains TC6387XB base support.
10 *
11 */
12
13#include <linux/module.h>
14#include <linux/platform_device.h>
Ian Molton7acb7062008-10-09 20:06:09 +020015#include <linux/clk.h>
Ian Moltoncbdfb422008-07-15 15:12:52 +010016#include <linux/err.h>
17#include <linux/mfd/core.h>
18#include <linux/mfd/tmio.h>
19#include <linux/mfd/tc6387xb.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090020#include <linux/slab.h>
Ian Moltoncbdfb422008-07-15 15:12:52 +010021
Ian Moltond2432a62008-08-04 18:58:18 +020022enum {
23 TC6387XB_CELL_MMC,
24};
25
Ian Molton64e88672010-01-06 13:51:48 +010026struct tc6387xb {
27 void __iomem *scr;
28 struct clk *clk32k;
29 struct resource rscr;
30};
31
32static struct resource tc6387xb_mmc_resources[] = {
33 {
34 .start = 0x800,
35 .end = 0x9ff,
36 .flags = IORESOURCE_MEM,
37 },
38 {
39 .start = 0,
40 .end = 0,
41 .flags = IORESOURCE_IRQ,
42 },
43};
44
45/*--------------------------------------------------------------------------*/
46
Ian Moltoncbdfb422008-07-15 15:12:52 +010047#ifdef CONFIG_PM
48static int tc6387xb_suspend(struct platform_device *dev, pm_message_t state)
49{
Ian Molton64e88672010-01-06 13:51:48 +010050 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
Jingoo Han334a41ce2013-07-30 17:10:05 +090051 struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev);
Ian Moltoncbdfb422008-07-15 15:12:52 +010052
53 if (pdata && pdata->suspend)
54 pdata->suspend(dev);
Dmitry Eremin-Solenikov7263bd32014-11-17 18:07:43 +030055 clk_disable_unprepare(tc6387xb->clk32k);
Ian Moltoncbdfb422008-07-15 15:12:52 +010056
57 return 0;
58}
59
60static int tc6387xb_resume(struct platform_device *dev)
61{
Ian Molton64e88672010-01-06 13:51:48 +010062 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
Jingoo Han334a41ce2013-07-30 17:10:05 +090063 struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev);
Ian Moltoncbdfb422008-07-15 15:12:52 +010064
Dmitry Eremin-Solenikov7263bd32014-11-17 18:07:43 +030065 clk_prepare_enable(tc6387xb->clk32k);
Ian Moltoncbdfb422008-07-15 15:12:52 +010066 if (pdata && pdata->resume)
67 pdata->resume(dev);
68
Ian Molton64e88672010-01-06 13:51:48 +010069 tmio_core_mmc_resume(tc6387xb->scr + 0x200, 0,
70 tc6387xb_mmc_resources[0].start & 0xfffe);
71
Ian Moltoncbdfb422008-07-15 15:12:52 +010072 return 0;
73}
74#else
75#define tc6387xb_suspend NULL
76#define tc6387xb_resume NULL
77#endif
78
79/*--------------------------------------------------------------------------*/
80
Ian Molton64e88672010-01-06 13:51:48 +010081static void tc6387xb_mmc_pwr(struct platform_device *mmc, int state)
82{
83 struct platform_device *dev = to_platform_device(mmc->dev.parent);
84 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
85
86 tmio_core_mmc_pwr(tc6387xb->scr + 0x200, 0, state);
87}
88
89static void tc6387xb_mmc_clk_div(struct platform_device *mmc, int state)
90{
91 struct platform_device *dev = to_platform_device(mmc->dev.parent);
92 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
93
94 tmio_core_mmc_clk_div(tc6387xb->scr + 0x200, 0, state);
95}
96
97
Ian Moltoncbdfb422008-07-15 15:12:52 +010098static int tc6387xb_mmc_enable(struct platform_device *mmc)
99{
100 struct platform_device *dev = to_platform_device(mmc->dev.parent);
Ian Molton64e88672010-01-06 13:51:48 +0100101 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100102
Dmitry Eremin-Solenikov7263bd32014-11-17 18:07:43 +0300103 clk_prepare_enable(tc6387xb->clk32k);
Ian Molton64e88672010-01-06 13:51:48 +0100104
105 tmio_core_mmc_enable(tc6387xb->scr + 0x200, 0,
106 tc6387xb_mmc_resources[0].start & 0xfffe);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100107
108 return 0;
109}
110
111static int tc6387xb_mmc_disable(struct platform_device *mmc)
112{
113 struct platform_device *dev = to_platform_device(mmc->dev.parent);
Ian Molton64e88672010-01-06 13:51:48 +0100114 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100115
Dmitry Eremin-Solenikov7263bd32014-11-17 18:07:43 +0300116 clk_disable_unprepare(tc6387xb->clk32k);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100117
118 return 0;
119}
120
Samuel Ortiz4d3792e2009-06-15 15:43:31 +0200121static struct tmio_mmc_data tc6387xb_mmc_data = {
Philipp Zabelf0e46cc2009-06-04 20:12:31 +0200122 .hclk = 24000000,
Ian Molton64e88672010-01-06 13:51:48 +0100123 .set_pwr = tc6387xb_mmc_pwr,
124 .set_clk_div = tc6387xb_mmc_clk_div,
Philipp Zabelf0e46cc2009-06-04 20:12:31 +0200125};
126
Ian Molton64e88672010-01-06 13:51:48 +0100127/*--------------------------------------------------------------------------*/
Ian Moltoncbdfb422008-07-15 15:12:52 +0100128
Geert Uytterhoevenafb580a2013-11-18 14:33:03 +0100129static const struct mfd_cell tc6387xb_cells[] = {
Ian Moltond2432a62008-08-04 18:58:18 +0200130 [TC6387XB_CELL_MMC] = {
Ian Moltoncbdfb422008-07-15 15:12:52 +0100131 .name = "tmio-mmc",
132 .enable = tc6387xb_mmc_enable,
133 .disable = tc6387xb_mmc_disable,
Samuel Ortizec719742011-04-06 11:38:14 +0200134 .platform_data = &tc6387xb_mmc_data,
135 .pdata_size = sizeof(tc6387xb_mmc_data),
Ian Moltoncbdfb422008-07-15 15:12:52 +0100136 .num_resources = ARRAY_SIZE(tc6387xb_mmc_resources),
137 .resources = tc6387xb_mmc_resources,
138 },
139};
140
Bill Pembertonf791be42012-11-19 13:23:04 -0500141static int tc6387xb_probe(struct platform_device *dev)
Ian Moltoncbdfb422008-07-15 15:12:52 +0100142{
Jingoo Han334a41ce2013-07-30 17:10:05 +0900143 struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev);
Ian Molton64e88672010-01-06 13:51:48 +0100144 struct resource *iomem, *rscr;
Ian Molton7acb7062008-10-09 20:06:09 +0200145 struct clk *clk32k;
Ian Molton64e88672010-01-06 13:51:48 +0100146 struct tc6387xb *tc6387xb;
Ian Moltoncbdfb422008-07-15 15:12:52 +0100147 int irq, ret;
148
149 iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
Lee Jonesd5ce79f2014-07-21 15:10:35 +0100150 if (!iomem)
Ian Molton7acb7062008-10-09 20:06:09 +0200151 return -EINVAL;
Ian Moltoncbdfb422008-07-15 15:12:52 +0100152
Lee Jonesd5ce79f2014-07-21 15:10:35 +0100153 tc6387xb = kzalloc(sizeof(*tc6387xb), GFP_KERNEL);
Ian Molton64e88672010-01-06 13:51:48 +0100154 if (!tc6387xb)
155 return -ENOMEM;
156
Ian Moltoncbdfb422008-07-15 15:12:52 +0100157 ret = platform_get_irq(dev, 0);
158 if (ret >= 0)
159 irq = ret;
160 else
Ian Molton64e88672010-01-06 13:51:48 +0100161 goto err_no_irq;
Ian Moltoncbdfb422008-07-15 15:12:52 +0100162
Ian Molton7acb7062008-10-09 20:06:09 +0200163 clk32k = clk_get(&dev->dev, "CLK_CK32K");
164 if (IS_ERR(clk32k)) {
165 ret = PTR_ERR(clk32k);
Ian Molton64e88672010-01-06 13:51:48 +0100166 goto err_no_clk;
Ian Molton7acb7062008-10-09 20:06:09 +0200167 }
Ian Molton64e88672010-01-06 13:51:48 +0100168
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;
174
175 ret = request_resource(iomem, rscr);
176 if (ret)
177 goto err_resource;
178
Joe Perches28f65c112011-06-09 09:13:32 -0700179 tc6387xb->scr = ioremap(rscr->start, resource_size(rscr));
Ian Molton64e88672010-01-06 13:51:48 +0100180 if (!tc6387xb->scr) {
181 ret = -ENOMEM;
182 goto err_ioremap;
183 }
184
185 tc6387xb->clk32k = clk32k;
186 platform_set_drvdata(dev, tc6387xb);
Ian Molton7acb7062008-10-09 20:06:09 +0200187
188 if (pdata && pdata->enable)
189 pdata->enable(dev);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100190
Lee Jonesd5ce79f2014-07-21 15:10:35 +0100191 dev_info(&dev->dev, "Toshiba tc6387xb initialised\n");
Ian Moltoncbdfb422008-07-15 15:12:52 +0100192
Samuel Ortiz56bf2bd2008-08-01 00:16:13 +0200193 ret = mfd_add_devices(&dev->dev, dev->id, tc6387xb_cells,
Mark Brown0848c942012-09-11 15:16:36 +0800194 ARRAY_SIZE(tc6387xb_cells), iomem, irq, NULL);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100195
196 if (!ret)
197 return 0;
198
Axel Lin08b877b2010-08-03 13:44:00 +0800199 iounmap(tc6387xb->scr);
Ian Molton64e88672010-01-06 13:51:48 +0100200err_ioremap:
201 release_resource(&tc6387xb->rscr);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100202err_resource:
Ian Molton64e88672010-01-06 13:51:48 +0100203 clk_put(clk32k);
204err_no_clk:
205err_no_irq:
206 kfree(tc6387xb);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100207 return ret;
208}
209
Bill Pemberton4740f732012-11-19 13:26:01 -0500210static int tc6387xb_remove(struct platform_device *dev)
Ian Moltoncbdfb422008-07-15 15:12:52 +0100211{
Axel Lin08b877b2010-08-03 13:44:00 +0800212 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100213
Ian Molton7acb7062008-10-09 20:06:09 +0200214 mfd_remove_devices(&dev->dev);
Axel Lin08b877b2010-08-03 13:44:00 +0800215 iounmap(tc6387xb->scr);
216 release_resource(&tc6387xb->rscr);
Dmitry Eremin-Solenikov7263bd32014-11-17 18:07:43 +0300217 clk_disable_unprepare(tc6387xb->clk32k);
Axel Lin08b877b2010-08-03 13:44:00 +0800218 clk_put(tc6387xb->clk32k);
Axel Lin08b877b2010-08-03 13:44:00 +0800219 kfree(tc6387xb);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100220
221 return 0;
222}
223
224
225static struct platform_driver tc6387xb_platform_driver = {
226 .driver = {
227 .name = "tc6387xb",
228 },
229 .probe = tc6387xb_probe,
Bill Pemberton84449212012-11-19 13:20:24 -0500230 .remove = tc6387xb_remove,
Ian Moltoncbdfb422008-07-15 15:12:52 +0100231 .suspend = tc6387xb_suspend,
232 .resume = tc6387xb_resume,
233};
234
Mark Brown65349d62011-11-23 22:58:34 +0000235module_platform_driver(tc6387xb_platform_driver);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100236
237MODULE_DESCRIPTION("Toshiba TC6387XB core driver");
238MODULE_LICENSE("GPL v2");
239MODULE_AUTHOR("Ian Molton");
240MODULE_ALIAS("platform:tc6387xb");
Ian Molton64e88672010-01-06 13:51:48 +0100241