blob: bbda954e00fd31c2b6a8daae81c8e6b0958a51d4 [file] [log] [blame]
Linus Walleij3d812772009-09-23 15:45:02 +01001/*
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>
Linus Walleij4d3ab5e2013-04-19 10:50:42 +020013#include <linux/of.h>
14#include <linux/module.h>
15#include <linux/platform_device.h>
16#include <linux/regulator/machine.h>
Linus Walleij3d812772009-09-23 15:45:02 +010017#include <linux/regulator/consumer.h>
18/* Those are just for writing in syscon */
19#include <linux/io.h>
Linus Walleij4d3ab5e2013-04-19 10:50:42 +020020#include <asm/mach-types.h>
Linus Walleij3d812772009-09-23 15:45:02 +010021#include <mach/hardware.h>
22#include <mach/syscon.h>
23
24/*
25 * Regulators that power the board and chip and which are
26 * not copuled to specific drivers are hogged in these
27 * instances.
28 */
29static struct regulator *main_power_15;
30
31/*
32 * This function is used from pm.h to shut down the system by
33 * resetting all regulators in turn and then disable regulator
34 * LDO D (main power).
35 */
36void u300_pm_poweroff(void)
37{
38 sigset_t old, all;
39
40 sigfillset(&all);
41 if (!sigprocmask(SIG_BLOCK, &all, &old)) {
42 /* Disable LDO D to shut down the system */
43 if (main_power_15)
44 regulator_disable(main_power_15);
45 else
46 pr_err("regulator not available to shut down system\n");
47 (void) sigprocmask(SIG_SETMASK, &old, NULL);
48 }
49 return;
50}
51
52/*
53 * Hog the regulators needed to power up the board.
54 */
Linus Walleij4d3ab5e2013-04-19 10:50:42 +020055static int __init __u300_init_boardpower(struct platform_device *pdev)
Linus Walleij3d812772009-09-23 15:45:02 +010056{
57 int err;
58 u32 val;
59
60 pr_info("U300: setting up board power\n");
Linus Walleij75a7f3f2013-04-22 11:29:30 +020061 main_power_15 = regulator_get(&pdev->dev, "vana15");
Linus Walleij4d3ab5e2013-04-19 10:50:42 +020062
Linus Walleij3d812772009-09-23 15:45:02 +010063 if (IS_ERR(main_power_15)) {
64 pr_err("could not get vana15");
65 return PTR_ERR(main_power_15);
66 }
67 err = regulator_enable(main_power_15);
68 if (err) {
69 pr_err("could not enable vana15\n");
70 return err;
71 }
72
73 /*
74 * On U300 a special system controller register pulls up the DC
75 * until the vana15 (LDO D) regulator comes up. At this point, all
76 * regulators are set and we do not need power control via
77 * DC ON anymore. This function will likely be moved whenever
78 * the rest of the U300 power management is implemented.
79 */
80 pr_info("U300: disable system controller pull-up\n");
81 val = readw(U300_SYSCON_VBASE + U300_SYSCON_PMCR);
82 val &= ~U300_SYSCON_PMCR_DCON_ENABLE;
83 writew(val, U300_SYSCON_VBASE + U300_SYSCON_PMCR);
84
85 /* Register globally exported PM poweroff hook */
86 pm_power_off = u300_pm_poweroff;
87
88 return 0;
89}
90
Linus Walleij4d3ab5e2013-04-19 10:50:42 +020091static int __init s365_board_probe(struct platform_device *pdev)
92{
93 return __u300_init_boardpower(pdev);
94}
95
96static const struct of_device_id s365_board_match[] = {
97 { .compatible = "stericsson,s365" },
98 {},
99};
100
101static struct platform_driver s365_board_driver = {
102 .driver = {
103 .name = "s365-board",
104 .owner = THIS_MODULE,
105 .of_match_table = s365_board_match,
106 },
107};
108
Linus Walleij3d812772009-09-23 15:45:02 +0100109/*
110 * So at module init time we hog the regulator!
111 */
Linus Walleij4d3ab5e2013-04-19 10:50:42 +0200112static int __init u300_init_boardpower(void)
113{
Linus Walleij75a7f3f2013-04-22 11:29:30 +0200114 return platform_driver_probe(&s365_board_driver,
115 s365_board_probe);
Linus Walleij4d3ab5e2013-04-19 10:50:42 +0200116}
117
118device_initcall(u300_init_boardpower);