Commit | Line | Data |
---|---|---|
3d81277b LW |
1 | /* |
2 | * arch/arm/mach-u300/regulator.c | |
3 | * | |
4 | * Copyright (C) 2009 ST-Ericsson AB | |
5 | * License terms: GNU General Public License (GPL) version 2 | |
6 | * Handle board-bound regulators and board power not related | |
7 | * to any devices. | |
8 | * Author: Linus Walleij <linus.walleij@stericsson.com> | |
9 | */ | |
10 | #include <linux/device.h> | |
11 | #include <linux/signal.h> | |
12 | #include <linux/err.h> | |
13 | #include <linux/regulator/consumer.h> | |
14 | /* Those are just for writing in syscon */ | |
15 | #include <linux/io.h> | |
16 | #include <mach/hardware.h> | |
17 | #include <mach/syscon.h> | |
18 | ||
19 | /* | |
20 | * Regulators that power the board and chip and which are | |
21 | * not copuled to specific drivers are hogged in these | |
22 | * instances. | |
23 | */ | |
24 | static struct regulator *main_power_15; | |
25 | ||
26 | /* | |
27 | * This function is used from pm.h to shut down the system by | |
28 | * resetting all regulators in turn and then disable regulator | |
29 | * LDO D (main power). | |
30 | */ | |
31 | void u300_pm_poweroff(void) | |
32 | { | |
33 | sigset_t old, all; | |
34 | ||
35 | sigfillset(&all); | |
36 | if (!sigprocmask(SIG_BLOCK, &all, &old)) { | |
37 | /* Disable LDO D to shut down the system */ | |
38 | if (main_power_15) | |
39 | regulator_disable(main_power_15); | |
40 | else | |
41 | pr_err("regulator not available to shut down system\n"); | |
42 | (void) sigprocmask(SIG_SETMASK, &old, NULL); | |
43 | } | |
44 | return; | |
45 | } | |
46 | ||
47 | /* | |
48 | * Hog the regulators needed to power up the board. | |
49 | */ | |
50 | static int __init u300_init_boardpower(void) | |
51 | { | |
52 | int err; | |
53 | u32 val; | |
54 | ||
55 | pr_info("U300: setting up board power\n"); | |
56 | main_power_15 = regulator_get(NULL, "vana15"); | |
57 | if (IS_ERR(main_power_15)) { | |
58 | pr_err("could not get vana15"); | |
59 | return PTR_ERR(main_power_15); | |
60 | } | |
61 | err = regulator_enable(main_power_15); | |
62 | if (err) { | |
63 | pr_err("could not enable vana15\n"); | |
64 | return err; | |
65 | } | |
66 | ||
67 | /* | |
68 | * On U300 a special system controller register pulls up the DC | |
69 | * until the vana15 (LDO D) regulator comes up. At this point, all | |
70 | * regulators are set and we do not need power control via | |
71 | * DC ON anymore. This function will likely be moved whenever | |
72 | * the rest of the U300 power management is implemented. | |
73 | */ | |
74 | pr_info("U300: disable system controller pull-up\n"); | |
75 | val = readw(U300_SYSCON_VBASE + U300_SYSCON_PMCR); | |
76 | val &= ~U300_SYSCON_PMCR_DCON_ENABLE; | |
77 | writew(val, U300_SYSCON_VBASE + U300_SYSCON_PMCR); | |
78 | ||
79 | /* Register globally exported PM poweroff hook */ | |
80 | pm_power_off = u300_pm_poweroff; | |
81 | ||
82 | return 0; | |
83 | } | |
84 | ||
85 | /* | |
86 | * So at module init time we hog the regulator! | |
87 | */ | |
88 | module_init(u300_init_boardpower); |