Blame view

drivers/mfd/tc6387xb.c 5.49 KB
cbdfb4263   Ian Molton   mfd: driver for t...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  /*
   * Toshiba TC6387XB support
   * Copyright (c) 2005 Ian Molton
   *
   * 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.
   *
   * This file contains TC6387XB base support.
   *
   */
  
  #include <linux/module.h>
  #include <linux/platform_device.h>
7acb706ca   Ian Molton   mfd: update TMIO ...
15
  #include <linux/clk.h>
cbdfb4263   Ian Molton   mfd: driver for t...
16
17
18
19
  #include <linux/err.h>
  #include <linux/mfd/core.h>
  #include <linux/mfd/tmio.h>
  #include <linux/mfd/tc6387xb.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
20
  #include <linux/slab.h>
cbdfb4263   Ian Molton   mfd: driver for t...
21

d2432a632   Ian Molton   mfd: tc6387 MMC p...
22
23
24
  enum {
  	TC6387XB_CELL_MMC,
  };
64e8867ba   Ian Molton   mfd: tmio_mmc har...
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  struct tc6387xb {
  	void __iomem *scr;
  	struct clk *clk32k;
  	struct resource rscr;
  };
  
  static struct resource tc6387xb_mmc_resources[] = {
  	{
  		.start = 0x800,
  		.end   = 0x9ff,
  		.flags = IORESOURCE_MEM,
  	},
  	{
  		.start = 0,
  		.end   = 0,
  		.flags = IORESOURCE_IRQ,
  	},
  };
  
  /*--------------------------------------------------------------------------*/
cbdfb4263   Ian Molton   mfd: driver for t...
45
46
47
  #ifdef CONFIG_PM
  static int tc6387xb_suspend(struct platform_device *dev, pm_message_t state)
  {
64e8867ba   Ian Molton   mfd: tmio_mmc har...
48
  	struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
334a41ce9   Jingoo Han   mfd: Use dev_get_...
49
  	struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev);
cbdfb4263   Ian Molton   mfd: driver for t...
50
51
52
  
  	if (pdata && pdata->suspend)
  		pdata->suspend(dev);
7263bd392   Dmitry Eremin-Solenikov   mfd: tc6387xb: pr...
53
  	clk_disable_unprepare(tc6387xb->clk32k);
cbdfb4263   Ian Molton   mfd: driver for t...
54
55
56
57
58
59
  
  	return 0;
  }
  
  static int tc6387xb_resume(struct platform_device *dev)
  {
64e8867ba   Ian Molton   mfd: tmio_mmc har...
60
  	struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
334a41ce9   Jingoo Han   mfd: Use dev_get_...
61
  	struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev);
cbdfb4263   Ian Molton   mfd: driver for t...
62

7263bd392   Dmitry Eremin-Solenikov   mfd: tc6387xb: pr...
63
  	clk_prepare_enable(tc6387xb->clk32k);
cbdfb4263   Ian Molton   mfd: driver for t...
64
65
  	if (pdata && pdata->resume)
  		pdata->resume(dev);
64e8867ba   Ian Molton   mfd: tmio_mmc har...
66
67
  	tmio_core_mmc_resume(tc6387xb->scr + 0x200, 0,
  		tc6387xb_mmc_resources[0].start & 0xfffe);
cbdfb4263   Ian Molton   mfd: driver for t...
68
69
70
71
72
73
74
75
  	return 0;
  }
  #else
  #define tc6387xb_suspend  NULL
  #define tc6387xb_resume   NULL
  #endif
  
  /*--------------------------------------------------------------------------*/
64e8867ba   Ian Molton   mfd: tmio_mmc har...
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  static void tc6387xb_mmc_pwr(struct platform_device *mmc, int state)
  {
  	struct platform_device *dev = to_platform_device(mmc->dev.parent);
  	struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
  
  	tmio_core_mmc_pwr(tc6387xb->scr + 0x200, 0, state);
  }
  
  static void tc6387xb_mmc_clk_div(struct platform_device *mmc, int state)
  {
  	struct platform_device *dev = to_platform_device(mmc->dev.parent);
  	struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
  
  	tmio_core_mmc_clk_div(tc6387xb->scr + 0x200, 0, state);
  }
cbdfb4263   Ian Molton   mfd: driver for t...
91
92
93
  static int tc6387xb_mmc_enable(struct platform_device *mmc)
  {
  	struct platform_device *dev      = to_platform_device(mmc->dev.parent);
64e8867ba   Ian Molton   mfd: tmio_mmc har...
94
  	struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
cbdfb4263   Ian Molton   mfd: driver for t...
95

7263bd392   Dmitry Eremin-Solenikov   mfd: tc6387xb: pr...
96
  	clk_prepare_enable(tc6387xb->clk32k);
64e8867ba   Ian Molton   mfd: tmio_mmc har...
97
98
99
  
  	tmio_core_mmc_enable(tc6387xb->scr + 0x200, 0,
  		tc6387xb_mmc_resources[0].start & 0xfffe);
cbdfb4263   Ian Molton   mfd: driver for t...
100
101
102
103
104
105
106
  
  	return 0;
  }
  
  static int tc6387xb_mmc_disable(struct platform_device *mmc)
  {
  	struct platform_device *dev      = to_platform_device(mmc->dev.parent);
64e8867ba   Ian Molton   mfd: tmio_mmc har...
107
  	struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
cbdfb4263   Ian Molton   mfd: driver for t...
108

7263bd392   Dmitry Eremin-Solenikov   mfd: tc6387xb: pr...
109
  	clk_disable_unprepare(tc6387xb->clk32k);
cbdfb4263   Ian Molton   mfd: driver for t...
110
111
112
  
  	return 0;
  }
4d3792e05   Samuel Ortiz   mfd: fix tmio rel...
113
  static struct tmio_mmc_data tc6387xb_mmc_data = {
f0e46cc49   Philipp Zabel   MFD,mmc: tmio_mmc...
114
  	.hclk = 24000000,
64e8867ba   Ian Molton   mfd: tmio_mmc har...
115
116
  	.set_pwr = tc6387xb_mmc_pwr,
  	.set_clk_div = tc6387xb_mmc_clk_div,
f0e46cc49   Philipp Zabel   MFD,mmc: tmio_mmc...
117
  };
64e8867ba   Ian Molton   mfd: tmio_mmc har...
118
  /*--------------------------------------------------------------------------*/
cbdfb4263   Ian Molton   mfd: driver for t...
119

afb580a94   Geert Uytterhoeven   mfd: toshiba: Con...
120
  static const struct mfd_cell tc6387xb_cells[] = {
d2432a632   Ian Molton   mfd: tc6387 MMC p...
121
  	[TC6387XB_CELL_MMC] = {
cbdfb4263   Ian Molton   mfd: driver for t...
122
123
124
  		.name = "tmio-mmc",
  		.enable = tc6387xb_mmc_enable,
  		.disable = tc6387xb_mmc_disable,
ec71974f2   Samuel Ortiz   mmc: Use device p...
125
126
  		.platform_data = &tc6387xb_mmc_data,
  		.pdata_size    = sizeof(tc6387xb_mmc_data),
cbdfb4263   Ian Molton   mfd: driver for t...
127
128
129
130
  		.num_resources = ARRAY_SIZE(tc6387xb_mmc_resources),
  		.resources = tc6387xb_mmc_resources,
  	},
  };
f791be492   Bill Pemberton   mfd: remove use o...
131
  static int tc6387xb_probe(struct platform_device *dev)
cbdfb4263   Ian Molton   mfd: driver for t...
132
  {
334a41ce9   Jingoo Han   mfd: Use dev_get_...
133
  	struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev);
64e8867ba   Ian Molton   mfd: tmio_mmc har...
134
  	struct resource *iomem, *rscr;
7acb706ca   Ian Molton   mfd: update TMIO ...
135
  	struct clk *clk32k;
64e8867ba   Ian Molton   mfd: tmio_mmc har...
136
  	struct tc6387xb *tc6387xb;
cbdfb4263   Ian Molton   mfd: driver for t...
137
138
139
  	int irq, ret;
  
  	iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
d5ce79ff2   Lee Jones   mfd: tc6387xb: Re...
140
  	if (!iomem)
7acb706ca   Ian Molton   mfd: update TMIO ...
141
  		return -EINVAL;
cbdfb4263   Ian Molton   mfd: driver for t...
142

d5ce79ff2   Lee Jones   mfd: tc6387xb: Re...
143
  	tc6387xb = kzalloc(sizeof(*tc6387xb), GFP_KERNEL);
64e8867ba   Ian Molton   mfd: tmio_mmc har...
144
145
  	if (!tc6387xb)
  		return -ENOMEM;
cbdfb4263   Ian Molton   mfd: driver for t...
146
147
148
149
  	ret  = platform_get_irq(dev, 0);
  	if (ret >= 0)
  		irq = ret;
  	else
64e8867ba   Ian Molton   mfd: tmio_mmc har...
150
  		goto err_no_irq;
cbdfb4263   Ian Molton   mfd: driver for t...
151

7acb706ca   Ian Molton   mfd: update TMIO ...
152
153
154
  	clk32k = clk_get(&dev->dev, "CLK_CK32K");
  	if (IS_ERR(clk32k)) {
  		ret = PTR_ERR(clk32k);
64e8867ba   Ian Molton   mfd: tmio_mmc har...
155
156
157
158
159
160
161
162
163
164
165
  		goto err_no_clk;
  	}
  
  	rscr = &tc6387xb->rscr;
  	rscr->name = "tc6387xb-core";
  	rscr->start = iomem->start;
  	rscr->end = iomem->start + 0xff;
  	rscr->flags = IORESOURCE_MEM;
  
  	ret = request_resource(iomem, rscr);
  	if (ret)
7acb706ca   Ian Molton   mfd: update TMIO ...
166
  		goto err_resource;
64e8867ba   Ian Molton   mfd: tmio_mmc har...
167

28f65c11f   Joe Perches   treewide: Convert...
168
  	tc6387xb->scr = ioremap(rscr->start, resource_size(rscr));
64e8867ba   Ian Molton   mfd: tmio_mmc har...
169
170
171
  	if (!tc6387xb->scr) {
  		ret = -ENOMEM;
  		goto err_ioremap;
7acb706ca   Ian Molton   mfd: update TMIO ...
172
  	}
64e8867ba   Ian Molton   mfd: tmio_mmc har...
173
174
175
  
  	tc6387xb->clk32k = clk32k;
  	platform_set_drvdata(dev, tc6387xb);
7acb706ca   Ian Molton   mfd: update TMIO ...
176
177
178
  
  	if (pdata && pdata->enable)
  		pdata->enable(dev);
cbdfb4263   Ian Molton   mfd: driver for t...
179

d5ce79ff2   Lee Jones   mfd: tc6387xb: Re...
180
181
  	dev_info(&dev->dev, "Toshiba tc6387xb initialised
  ");
cbdfb4263   Ian Molton   mfd: driver for t...
182

56bf2bda0   Samuel Ortiz   mfd: Fix 7l66 and...
183
  	ret = mfd_add_devices(&dev->dev, dev->id, tc6387xb_cells,
0848c94fb   Mark Brown   mfd: core: Push i...
184
  			      ARRAY_SIZE(tc6387xb_cells), iomem, irq, NULL);
cbdfb4263   Ian Molton   mfd: driver for t...
185
186
187
  
  	if (!ret)
  		return 0;
08b877b80   Axel Lin   mfd: Fix tc6387xb...
188
  	iounmap(tc6387xb->scr);
64e8867ba   Ian Molton   mfd: tmio_mmc har...
189
190
  err_ioremap:
  	release_resource(&tc6387xb->rscr);
cbdfb4263   Ian Molton   mfd: driver for t...
191
  err_resource:
64e8867ba   Ian Molton   mfd: tmio_mmc har...
192
193
194
195
  	clk_put(clk32k);
  err_no_clk:
  err_no_irq:
  	kfree(tc6387xb);
cbdfb4263   Ian Molton   mfd: driver for t...
196
197
  	return ret;
  }
4740f73fe   Bill Pemberton   mfd: remove use o...
198
  static int tc6387xb_remove(struct platform_device *dev)
cbdfb4263   Ian Molton   mfd: driver for t...
199
  {
08b877b80   Axel Lin   mfd: Fix tc6387xb...
200
  	struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
cbdfb4263   Ian Molton   mfd: driver for t...
201

7acb706ca   Ian Molton   mfd: update TMIO ...
202
  	mfd_remove_devices(&dev->dev);
08b877b80   Axel Lin   mfd: Fix tc6387xb...
203
204
  	iounmap(tc6387xb->scr);
  	release_resource(&tc6387xb->rscr);
7263bd392   Dmitry Eremin-Solenikov   mfd: tc6387xb: pr...
205
  	clk_disable_unprepare(tc6387xb->clk32k);
08b877b80   Axel Lin   mfd: Fix tc6387xb...
206
  	clk_put(tc6387xb->clk32k);
08b877b80   Axel Lin   mfd: Fix tc6387xb...
207
  	kfree(tc6387xb);
cbdfb4263   Ian Molton   mfd: driver for t...
208
209
210
211
212
213
214
215
216
217
  
  	return 0;
  }
  
  
  static struct platform_driver tc6387xb_platform_driver = {
  	.driver = {
  		.name		= "tc6387xb",
  	},
  	.probe		= tc6387xb_probe,
84449216b   Bill Pemberton   mfd: remove use o...
218
  	.remove		= tc6387xb_remove,
cbdfb4263   Ian Molton   mfd: driver for t...
219
220
221
  	.suspend        = tc6387xb_suspend,
  	.resume         = tc6387xb_resume,
  };
65349d60d   Mark Brown   mfd: Convert MFD ...
222
  module_platform_driver(tc6387xb_platform_driver);
cbdfb4263   Ian Molton   mfd: driver for t...
223
224
225
226
227
  
  MODULE_DESCRIPTION("Toshiba TC6387XB core driver");
  MODULE_LICENSE("GPL v2");
  MODULE_AUTHOR("Ian Molton");
  MODULE_ALIAS("platform:tc6387xb");
64e8867ba   Ian Molton   mfd: tmio_mmc har...
228