blob: a8e2449a09785a21b74b1f4d5ef5b1684816188d [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/kernel.h>
14#include <linux/io.h>
15#include <linux/delay.h>
16#include <linux/platform_device.h>
17#include <linux/err.h>
18#include <linux/regulator/driver.h>
19#include <linux/regulator/machine.h>
20#include <linux/clk.h>
21#include <mach/msm_iomap.h>
22#include <mach/msm_bus_board.h>
23#include <mach/msm_bus.h>
24#include <mach/scm-io.h>
25#include "clock.h"
26#include "footswitch.h"
27
28#ifdef CONFIG_MSM_SECURE_IO
29#undef readl_relaxed
30#undef writel_relaxed
31#define readl_relaxed secure_readl
32#define writel_relaxed secure_writel
33#endif
34
35#define REG(off) (MSM_MMSS_CLK_CTL_BASE + (off))
36#define GEMINI_GFS_CTL_REG REG(0x01A0)
37#define GFX2D0_GFS_CTL_REG REG(0x0180)
38#define GFX2D1_GFS_CTL_REG REG(0x0184)
39#define GFX3D_GFS_CTL_REG REG(0x0188)
40#define MDP_GFS_CTL_REG REG(0x0190)
41#define ROT_GFS_CTL_REG REG(0x018C)
42#define VED_GFS_CTL_REG REG(0x0194)
43#define VFE_GFS_CTL_REG REG(0x0198)
44#define VPE_GFS_CTL_REG REG(0x019C)
Matt Wagantall37f34b32011-08-23 18:14:47 -070045#define VCAP_GFS_CTL_REG REG(0x0254)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070046
47#define CLAMP_BIT BIT(5)
48#define ENABLE_BIT BIT(8)
49#define RETENTION_BIT BIT(9)
50
51#define RESET_DELAY_US 1
52/* Core clock rate to use if one has not previously been set. */
53#define DEFAULT_CLK_RATE 27000000
54
55/*
56 * Lock is only needed to protect against the first footswitch_enable()
57 * call occuring concurrently with late_footswitch_init().
58 */
59static DEFINE_MUTEX(claim_lock);
60
61struct clock_state {
62 int ahb_clk_en;
63 int axi_clk_en;
64 int core_clk_rate;
65};
66
67struct footswitch {
68 struct regulator_dev *rdev;
69 struct regulator_desc desc;
70 void *gfs_ctl_reg;
71 int bus_port1, bus_port2;
72 bool is_enabled;
73 bool is_claimed;
Matt Wagantall49722712011-08-17 18:50:53 -070074 const bool has_axi_clk;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070075 struct clk *core_clk;
76 struct clk *ahb_clk;
77 struct clk *axi_clk;
78 unsigned int reset_rate;
79 struct clock_state clk_state;
80 unsigned int gfs_delay_cnt:5;
81};
82
83static int setup_clocks(struct footswitch *fs)
84{
85 int rc = 0;
86
87 /*
88 * Enable all clocks in the power domain. If a core requires a
89 * specific clock rate when being reset, apply it.
90 */
91 fs->clk_state.core_clk_rate = clk_get_rate(fs->core_clk);
92 if (!fs->clk_state.core_clk_rate || fs->reset_rate) {
93 int rate = fs->reset_rate ? fs->reset_rate : DEFAULT_CLK_RATE;
94 rc = clk_set_rate(fs->core_clk, rate);
95 if (rc) {
Matt Wagantall49722712011-08-17 18:50:53 -070096 pr_err("%s: Failed to set core_clk rate to %d Hz.\n",
97 __func__, fs->reset_rate);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070098 return rc;
99 }
100 }
101 clk_enable(fs->core_clk);
102
103 /*
104 * Some AHB and AXI clocks are for reset purposes only. These clocks
105 * will fail to enable. Keep track of them so we don't try to disable
106 * them later and crash.
107 */
108 fs->clk_state.ahb_clk_en = !clk_enable(fs->ahb_clk);
109 if (fs->axi_clk)
110 fs->clk_state.axi_clk_en = !clk_enable(fs->axi_clk);
111
112 return rc;
113}
114
115static void restore_clocks(struct footswitch *fs)
116{
117 /* Restore clocks to their orignal states before setup_clocks(). */
118 if (fs->axi_clk && fs->clk_state.axi_clk_en)
119 clk_disable(fs->axi_clk);
120 if (fs->clk_state.ahb_clk_en)
121 clk_disable(fs->ahb_clk);
122 clk_disable(fs->core_clk);
123 if (fs->clk_state.core_clk_rate) {
124 if (clk_set_rate(fs->core_clk, fs->clk_state.core_clk_rate))
Matt Wagantall49722712011-08-17 18:50:53 -0700125 pr_err("%s: Failed to restore core_clk rate.\n",
126 __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700127 }
128}
129
130static int footswitch_is_enabled(struct regulator_dev *rdev)
131{
132 struct footswitch *fs = rdev_get_drvdata(rdev);
133
134 return fs->is_enabled;
135}
136
137static int footswitch_enable(struct regulator_dev *rdev)
138{
139 struct footswitch *fs = rdev_get_drvdata(rdev);
140 uint32_t regval, rc = 0;
141
142 mutex_lock(&claim_lock);
143 fs->is_claimed = true;
144 mutex_unlock(&claim_lock);
145
Matt Wagantall88edea92011-07-21 10:29:56 -0700146 /* Return early if already enabled. */
147 regval = readl_relaxed(fs->gfs_ctl_reg);
148 if ((regval & (ENABLE_BIT | CLAMP_BIT)) == ENABLE_BIT)
149 return 0;
150
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700151 /* Make sure required clocks are on at the correct rates. */
152 rc = setup_clocks(fs);
153 if (rc)
154 goto out;
155
156 /* Un-halt all bus ports in the power domain. */
157 if (fs->bus_port1) {
158 rc = msm_bus_axi_portunhalt(fs->bus_port1);
159 if (rc) {
160 pr_err("%s: Port 1 unhalt failed.\n", __func__);
161 goto out;
162 }
163 }
164 if (fs->bus_port2) {
165 rc = msm_bus_axi_portunhalt(fs->bus_port2);
166 if (rc) {
167 pr_err("%s: Port 2 unhalt failed.\n", __func__);
168 goto out;
169 }
170 }
171
172 /*
173 * (Re-)Assert resets for all clocks in the clock domain, since
174 * footswitch_enable() is first called before footswitch_disable()
175 * and resets should be asserted before power is restored.
176 */
177 if (fs->axi_clk)
178 clk_reset(fs->axi_clk, CLK_RESET_ASSERT);
179 clk_reset(fs->ahb_clk, CLK_RESET_ASSERT);
180 clk_reset(fs->core_clk, CLK_RESET_ASSERT);
181 /* Wait for synchronous resets to propagate. */
182 udelay(RESET_DELAY_US);
183
184 /* Enable the power rail at the footswitch. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185 regval |= ENABLE_BIT;
186 writel_relaxed(regval, fs->gfs_ctl_reg);
187 /* Wait for the rail to fully charge. */
188 mb();
189 udelay(1);
190
191 /* Un-clamp the I/O ports. */
192 regval &= ~CLAMP_BIT;
193 writel_relaxed(regval, fs->gfs_ctl_reg);
194
195 /* Deassert resets for all clocks in the power domain. */
196 clk_reset(fs->core_clk, CLK_RESET_DEASSERT);
197 clk_reset(fs->ahb_clk, CLK_RESET_DEASSERT);
198 if (fs->axi_clk)
199 clk_reset(fs->axi_clk, CLK_RESET_DEASSERT);
200 /* Toggle core reset again after first power-on (required for GFX3D). */
201 if (fs->desc.id == FS_GFX3D) {
202 clk_reset(fs->core_clk, CLK_RESET_ASSERT);
203 udelay(RESET_DELAY_US);
204 clk_reset(fs->core_clk, CLK_RESET_DEASSERT);
205 udelay(RESET_DELAY_US);
206 }
207
208 /* Return clocks to their state before this function. */
209 restore_clocks(fs);
210
211 fs->is_enabled = true;
212out:
213 return rc;
214}
215
216static int footswitch_disable(struct regulator_dev *rdev)
217{
218 struct footswitch *fs = rdev_get_drvdata(rdev);
219 uint32_t regval, rc = 0;
220
Matt Wagantall88edea92011-07-21 10:29:56 -0700221 /* Return early if already disabled. */
222 regval = readl_relaxed(fs->gfs_ctl_reg);
223 if ((regval & ENABLE_BIT) == 0)
224 return 0;
225
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700226 /* Make sure required clocks are on at the correct rates. */
227 rc = setup_clocks(fs);
228 if (rc)
229 goto out;
230
231 /* Halt all bus ports in the power domain. */
232 if (fs->bus_port1) {
233 rc = msm_bus_axi_porthalt(fs->bus_port1);
234 if (rc) {
235 pr_err("%s: Port 1 halt failed.\n", __func__);
236 goto out;
237 }
238 }
239 if (fs->bus_port2) {
240 rc = msm_bus_axi_porthalt(fs->bus_port2);
241 if (rc) {
242 pr_err("%s: Port 1 halt failed.\n", __func__);
243 goto err_port2_halt;
244 }
245 }
246
247 /*
248 * Assert resets for all clocks in the clock domain so that
249 * outputs settle prior to clamping.
250 */
251 if (fs->axi_clk)
252 clk_reset(fs->axi_clk, CLK_RESET_ASSERT);
253 clk_reset(fs->ahb_clk, CLK_RESET_ASSERT);
254 clk_reset(fs->core_clk, CLK_RESET_ASSERT);
255 /* Wait for synchronous resets to propagate. */
256 udelay(RESET_DELAY_US);
257
258 /*
Matt Wagantall1ab7d942011-12-02 17:59:57 -0800259 * Return clocks to their state before this function. For robustness
260 * if memory-retention across collapses is required, clocks should
261 * be disabled before asserting the clamps. Assuming clocks were off
262 * before entering footswitch_disable(), this will be true.
263 */
264 restore_clocks(fs);
265
266 /*
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700267 * Clamp the I/O ports of the core to ensure the values
268 * remain fixed while the core is collapsed.
269 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700270 regval |= CLAMP_BIT;
271 writel_relaxed(regval, fs->gfs_ctl_reg);
272
273 /* Collapse the power rail at the footswitch. */
274 regval &= ~ENABLE_BIT;
275 writel_relaxed(regval, fs->gfs_ctl_reg);
276
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700277 fs->is_enabled = false;
278
279 return rc;
280
281err_port2_halt:
282 msm_bus_axi_portunhalt(fs->bus_port1);
283out:
284 return rc;
285}
286
287static int gfx2d_footswitch_enable(struct regulator_dev *rdev)
288{
289 struct footswitch *fs = rdev_get_drvdata(rdev);
290 uint32_t regval, rc = 0;
291
292 mutex_lock(&claim_lock);
293 fs->is_claimed = true;
294 mutex_unlock(&claim_lock);
295
Matt Wagantall88edea92011-07-21 10:29:56 -0700296 /* Return early if already enabled. */
297 regval = readl_relaxed(fs->gfs_ctl_reg);
298 if ((regval & (ENABLE_BIT | CLAMP_BIT)) == ENABLE_BIT)
299 return 0;
300
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700301 /* Make sure required clocks are on at the correct rates. */
302 rc = setup_clocks(fs);
303 if (rc)
304 goto out;
305
306 /* Un-halt all bus ports in the power domain. */
307 if (fs->bus_port1) {
308 rc = msm_bus_axi_portunhalt(fs->bus_port1);
309 if (rc) {
310 pr_err("%s: Port 1 unhalt failed.\n", __func__);
311 goto out;
312 }
313 }
314
315 /* Disable core clock. */
316 clk_disable(fs->core_clk);
317
318 /*
319 * (Re-)Assert resets for all clocks in the clock domain, since
320 * footswitch_enable() is first called before footswitch_disable()
321 * and resets should be asserted before power is restored.
322 */
323 if (fs->axi_clk)
324 clk_reset(fs->axi_clk, CLK_RESET_ASSERT);
325 clk_reset(fs->ahb_clk, CLK_RESET_ASSERT);
326 clk_reset(fs->core_clk, CLK_RESET_ASSERT);
327 /* Wait for synchronous resets to propagate. */
328 udelay(20);
329
330 /* Enable the power rail at the footswitch. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700331 regval |= ENABLE_BIT;
332 writel_relaxed(regval, fs->gfs_ctl_reg);
333 mb();
334 udelay(1);
335
336 /* Un-clamp the I/O ports. */
337 regval &= ~CLAMP_BIT;
338 writel_relaxed(regval, fs->gfs_ctl_reg);
339
340 /* Deassert resets for all clocks in the power domain. */
341 if (fs->axi_clk)
342 clk_reset(fs->axi_clk, CLK_RESET_DEASSERT);
343 clk_reset(fs->ahb_clk, CLK_RESET_DEASSERT);
344 clk_reset(fs->core_clk, CLK_RESET_DEASSERT);
345 udelay(20);
346
347 /* Re-enable core clock. */
348 clk_enable(fs->core_clk);
349
350 /* Return clocks to their state before this function. */
351 restore_clocks(fs);
352
353 fs->is_enabled = true;
354out:
355 return rc;
356}
357
358static int gfx2d_footswitch_disable(struct regulator_dev *rdev)
359{
360 struct footswitch *fs = rdev_get_drvdata(rdev);
361 uint32_t regval, rc = 0;
362
Matt Wagantall88edea92011-07-21 10:29:56 -0700363 /* Return early if already disabled. */
364 regval = readl_relaxed(fs->gfs_ctl_reg);
365 if ((regval & ENABLE_BIT) == 0)
366 return 0;
367
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700368 /* Make sure required clocks are on at the correct rates. */
369 rc = setup_clocks(fs);
370 if (rc)
371 goto out;
372
373 /* Halt all bus ports in the power domain. */
374 if (fs->bus_port1) {
375 rc = msm_bus_axi_porthalt(fs->bus_port1);
376 if (rc) {
377 pr_err("%s: Port 1 halt failed.\n", __func__);
378 goto out;
379 }
380 }
381
382 /* Disable core clock. */
383 clk_disable(fs->core_clk);
384
385 /*
386 * Assert resets for all clocks in the clock domain so that
387 * outputs settle prior to clamping.
388 */
389 if (fs->axi_clk)
390 clk_reset(fs->axi_clk, CLK_RESET_ASSERT);
391 clk_reset(fs->ahb_clk, CLK_RESET_ASSERT);
392 clk_reset(fs->core_clk, CLK_RESET_ASSERT);
393 /* Wait for synchronous resets to propagate. */
394 udelay(20);
395
396 /*
397 * Clamp the I/O ports of the core to ensure the values
398 * remain fixed while the core is collapsed.
399 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700400 regval |= CLAMP_BIT;
401 writel_relaxed(regval, fs->gfs_ctl_reg);
402
403 /* Collapse the power rail at the footswitch. */
404 regval &= ~ENABLE_BIT;
405 writel_relaxed(regval, fs->gfs_ctl_reg);
406
407 /* Re-enable core clock. */
408 clk_enable(fs->core_clk);
409
410 /* Return clocks to their state before this function. */
411 restore_clocks(fs);
412
413 fs->is_enabled = false;
414
415out:
416 return rc;
417}
418
419static struct regulator_ops standard_fs_ops = {
420 .is_enabled = footswitch_is_enabled,
421 .enable = footswitch_enable,
422 .disable = footswitch_disable,
423};
424
425static struct regulator_ops gfx2d_fs_ops = {
426 .is_enabled = footswitch_is_enabled,
427 .enable = gfx2d_footswitch_enable,
428 .disable = gfx2d_footswitch_disable,
429};
430
Matt Wagantall49722712011-08-17 18:50:53 -0700431#define FOOTSWITCH(_id, _name, _ops, _gfs_ctl_reg, _dc, _axi_clk, \
432 _reset_rate, _bp1, _bp2) \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700433 [(_id)] = { \
434 .desc = { \
435 .id = (_id), \
436 .name = (_name), \
437 .ops = (_ops), \
438 .type = REGULATOR_VOLTAGE, \
439 .owner = THIS_MODULE, \
440 }, \
441 .gfs_ctl_reg = (_gfs_ctl_reg), \
442 .gfs_delay_cnt = (_dc), \
443 .bus_port1 = (_bp1), \
444 .bus_port2 = (_bp2), \
Matt Wagantall49722712011-08-17 18:50:53 -0700445 .has_axi_clk = (_axi_clk), \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700446 .reset_rate = (_reset_rate), \
447 }
448static struct footswitch footswitches[] = {
449 FOOTSWITCH(FS_GFX2D0, "fs_gfx2d0", &gfx2d_fs_ops,
Matt Wagantall49722712011-08-17 18:50:53 -0700450 GFX2D0_GFS_CTL_REG, 31, false, 0,
451 MSM_BUS_MASTER_GRAPHICS_2D_CORE0, 0),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700452 FOOTSWITCH(FS_GFX2D1, "fs_gfx2d1", &gfx2d_fs_ops,
Matt Wagantall49722712011-08-17 18:50:53 -0700453 GFX2D1_GFS_CTL_REG, 31, false, 0,
454 MSM_BUS_MASTER_GRAPHICS_2D_CORE1, 0),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700455 FOOTSWITCH(FS_GFX3D, "fs_gfx3d", &standard_fs_ops,
Matt Wagantall49722712011-08-17 18:50:53 -0700456 GFX3D_GFS_CTL_REG, 31, false, 27000000,
457 MSM_BUS_MASTER_GRAPHICS_3D, 0),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700458 FOOTSWITCH(FS_IJPEG, "fs_ijpeg", &standard_fs_ops,
Matt Wagantall49722712011-08-17 18:50:53 -0700459 GEMINI_GFS_CTL_REG, 31, true, 0,
460 MSM_BUS_MASTER_JPEG_ENC, 0),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700461 FOOTSWITCH(FS_MDP, "fs_mdp", &standard_fs_ops,
Matt Wagantall49722712011-08-17 18:50:53 -0700462 MDP_GFS_CTL_REG, 31, true, 0,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700463 MSM_BUS_MASTER_MDP_PORT0,
Matt Wagantall49722712011-08-17 18:50:53 -0700464 MSM_BUS_MASTER_MDP_PORT1),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700465 FOOTSWITCH(FS_ROT, "fs_rot", &standard_fs_ops,
Matt Wagantall49722712011-08-17 18:50:53 -0700466 ROT_GFS_CTL_REG, 31, true, 0,
467 MSM_BUS_MASTER_ROTATOR, 0),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700468 FOOTSWITCH(FS_VED, "fs_ved", &standard_fs_ops,
Matt Wagantall49722712011-08-17 18:50:53 -0700469 VED_GFS_CTL_REG, 31, true, 0,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700470 MSM_BUS_MASTER_HD_CODEC_PORT0,
Matt Wagantall49722712011-08-17 18:50:53 -0700471 MSM_BUS_MASTER_HD_CODEC_PORT1),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700472 FOOTSWITCH(FS_VFE, "fs_vfe", &standard_fs_ops,
Matt Wagantall49722712011-08-17 18:50:53 -0700473 VFE_GFS_CTL_REG, 31, true, 0,
474 MSM_BUS_MASTER_VFE, 0),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700475 FOOTSWITCH(FS_VPE, "fs_vpe", &standard_fs_ops,
Matt Wagantall49722712011-08-17 18:50:53 -0700476 VPE_GFS_CTL_REG, 31, true, 0,
477 MSM_BUS_MASTER_VPE, 0),
Matt Wagantall37f34b32011-08-23 18:14:47 -0700478 FOOTSWITCH(FS_VCAP, "fs_vcap", &standard_fs_ops,
479 VCAP_GFS_CTL_REG, 31, true, 0,
480 MSM_BUS_MASTER_VIDEO_CAP, 0),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700481};
482
483static int footswitch_probe(struct platform_device *pdev)
484{
485 struct footswitch *fs;
486 struct regulator_init_data *init_data;
487 uint32_t regval, rc = 0;
488
489 if (pdev == NULL)
490 return -EINVAL;
491
492 if (pdev->id >= MAX_FS)
493 return -ENODEV;
494
495 fs = &footswitches[pdev->id];
496 init_data = pdev->dev.platform_data;
497
498 /* Setup core clock. */
Matt Wagantall49722712011-08-17 18:50:53 -0700499 fs->core_clk = clk_get(&pdev->dev, "core_clk");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700500 if (IS_ERR(fs->core_clk)) {
Matt Wagantall49722712011-08-17 18:50:53 -0700501 pr_err("%s: clk_get(core_clk) failed\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700502 rc = PTR_ERR(fs->core_clk);
503 goto err_core_clk;
504 }
505
506 /* Setup AHB clock. */
Matt Wagantall49722712011-08-17 18:50:53 -0700507 fs->ahb_clk = clk_get(&pdev->dev, "iface_clk");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700508 if (IS_ERR(fs->ahb_clk)) {
Matt Wagantall49722712011-08-17 18:50:53 -0700509 pr_err("%s: clk_get(iface_clk) failed\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700510 rc = PTR_ERR(fs->ahb_clk);
511 goto err_ahb_clk;
512 }
513
514 /* Setup AXI clock. */
Matt Wagantall49722712011-08-17 18:50:53 -0700515 if (fs->has_axi_clk) {
516 fs->axi_clk = clk_get(&pdev->dev, "bus_clk");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700517 if (IS_ERR(fs->axi_clk)) {
Matt Wagantall49722712011-08-17 18:50:53 -0700518 pr_err("%s: clk_get(bus_clk) failed\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700519 rc = PTR_ERR(fs->axi_clk);
520 goto err_axi_clk;
521 }
522 }
523
524 /*
525 * Set number of AHB_CLK cycles to delay the assertion of gfs_en_all
526 * after enabling the footswitch. Also ensure the retention bit is
527 * clear so disabling the footswitch will power-collapse the core.
528 */
529 regval = readl_relaxed(fs->gfs_ctl_reg);
530 regval |= fs->gfs_delay_cnt;
531 regval &= ~RETENTION_BIT;
532 writel_relaxed(regval, fs->gfs_ctl_reg);
533
534 fs->rdev = regulator_register(&fs->desc, &pdev->dev, init_data, fs);
535 if (IS_ERR(footswitches[pdev->id].rdev)) {
536 pr_err("%s: regulator_register(\"%s\") failed\n",
537 __func__, fs->desc.name);
538 rc = PTR_ERR(footswitches[pdev->id].rdev);
539 goto err_register;
540 }
541
542 return 0;
543
544err_register:
Matt Wagantall49722712011-08-17 18:50:53 -0700545 if (fs->has_axi_clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700546 clk_put(fs->axi_clk);
547err_axi_clk:
548 clk_put(fs->ahb_clk);
549err_ahb_clk:
550 clk_put(fs->core_clk);
551err_core_clk:
552 return rc;
553}
554
555static int __devexit footswitch_remove(struct platform_device *pdev)
556{
557 struct footswitch *fs = &footswitches[pdev->id];
558
559 clk_put(fs->core_clk);
560 clk_put(fs->ahb_clk);
561 if (fs->axi_clk)
562 clk_put(fs->axi_clk);
563
564 regulator_unregister(fs->rdev);
565
566 return 0;
567}
568
569static struct platform_driver footswitch_driver = {
570 .probe = footswitch_probe,
571 .remove = __devexit_p(footswitch_remove),
572 .driver = {
Matt Wagantall49722712011-08-17 18:50:53 -0700573 .name = "footswitch-8x60",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700574 .owner = THIS_MODULE,
575 },
576};
577
578static int __init late_footswitch_init(void)
579{
580 int i;
581
582 mutex_lock(&claim_lock);
583 /* Turn off all registered but unused footswitches. */
584 for (i = 0; i < ARRAY_SIZE(footswitches); i++)
585 if (footswitches[i].rdev && !footswitches[i].is_claimed)
Matt Wagantall7a261362011-07-14 19:07:10 -0700586 footswitches[i].rdev->desc->ops->
587 disable(footswitches[i].rdev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700588 mutex_unlock(&claim_lock);
589
590 return 0;
591}
592late_initcall(late_footswitch_init);
593
594static int __init footswitch_init(void)
595{
596 return platform_driver_register(&footswitch_driver);
597}
598subsys_initcall(footswitch_init);
599
600static void __exit footswitch_exit(void)
601{
602 platform_driver_unregister(&footswitch_driver);
603}
604module_exit(footswitch_exit);
605
606MODULE_LICENSE("GPL v2");
607MODULE_DESCRIPTION("MSM8x60 rail footswitch");
608MODULE_ALIAS("platform:footswitch-msm8x60");