blob: 273fceb83685525d85ae3cdc9ec07a210f0e6b68 [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 */
Linus Walleijcf0ce092013-05-22 16:15:13 +020019#include <linux/of_address.h>
Linus Walleij3d812772009-09-23 15:45:02 +010020#include <linux/io.h>
Linus Walleij0004b012013-05-02 16:56:15 +020021
22/* Power Management Control 16bit (R/W) */
23#define U300_SYSCON_PMCR (0x50)
24#define U300_SYSCON_PMCR_DCON_ENABLE (0x0002)
25#define U300_SYSCON_PMCR_PWR_MGNT_ENABLE (0x0001)
Linus Walleij3d812772009-09-23 15:45:02 +010026
27/*
28 * Regulators that power the board and chip and which are
29 * not copuled to specific drivers are hogged in these
30 * instances.
31 */
32static struct regulator *main_power_15;
33
34/*
35 * This function is used from pm.h to shut down the system by
36 * resetting all regulators in turn and then disable regulator
37 * LDO D (main power).
38 */
39void u300_pm_poweroff(void)
40{
41 sigset_t old, all;
42
43 sigfillset(&all);
44 if (!sigprocmask(SIG_BLOCK, &all, &old)) {
45 /* Disable LDO D to shut down the system */
46 if (main_power_15)
47 regulator_disable(main_power_15);
48 else
49 pr_err("regulator not available to shut down system\n");
50 (void) sigprocmask(SIG_SETMASK, &old, NULL);
51 }
52 return;
53}
54
55/*
56 * Hog the regulators needed to power up the board.
57 */
Linus Walleij4d3ab5e2013-04-19 10:50:42 +020058static int __init __u300_init_boardpower(struct platform_device *pdev)
Linus Walleij3d812772009-09-23 15:45:02 +010059{
Linus Walleijcf0ce092013-05-22 16:15:13 +020060 struct device_node *np = pdev->dev.of_node;
61 struct device_node *syscon_np;
62 static void __iomem *syscon_base;
Linus Walleij3d812772009-09-23 15:45:02 +010063 int err;
64 u32 val;
65
66 pr_info("U300: setting up board power\n");
Linus Walleijcf0ce092013-05-22 16:15:13 +020067
68 syscon_np = of_parse_phandle(np, "syscon", 0);
69 if (!syscon_np) {
70 pr_crit("U300: no syscon node\n");
71 return -ENODEV;
72 }
73 syscon_base = of_iomap(syscon_np, 0);
74 if (!syscon_base) {
75 pr_crit("U300: could not remap syscon\n");
76 return -ENODEV;
77 }
78
Linus Walleij75a7f3f2013-04-22 11:29:30 +020079 main_power_15 = regulator_get(&pdev->dev, "vana15");
Linus Walleij4d3ab5e2013-04-19 10:50:42 +020080
Linus Walleij3d812772009-09-23 15:45:02 +010081 if (IS_ERR(main_power_15)) {
82 pr_err("could not get vana15");
83 return PTR_ERR(main_power_15);
84 }
85 err = regulator_enable(main_power_15);
86 if (err) {
87 pr_err("could not enable vana15\n");
88 return err;
89 }
90
91 /*
92 * On U300 a special system controller register pulls up the DC
93 * until the vana15 (LDO D) regulator comes up. At this point, all
94 * regulators are set and we do not need power control via
95 * DC ON anymore. This function will likely be moved whenever
96 * the rest of the U300 power management is implemented.
97 */
98 pr_info("U300: disable system controller pull-up\n");
Linus Walleijcf0ce092013-05-22 16:15:13 +020099 val = readw(syscon_base + U300_SYSCON_PMCR);
Linus Walleij3d812772009-09-23 15:45:02 +0100100 val &= ~U300_SYSCON_PMCR_DCON_ENABLE;
Linus Walleijcf0ce092013-05-22 16:15:13 +0200101 writew(val, syscon_base + U300_SYSCON_PMCR);
Linus Walleij3d812772009-09-23 15:45:02 +0100102
103 /* Register globally exported PM poweroff hook */
104 pm_power_off = u300_pm_poweroff;
105
106 return 0;
107}
108
Linus Walleij4d3ab5e2013-04-19 10:50:42 +0200109static int __init s365_board_probe(struct platform_device *pdev)
110{
111 return __u300_init_boardpower(pdev);
112}
113
114static const struct of_device_id s365_board_match[] = {
115 { .compatible = "stericsson,s365" },
116 {},
117};
118
119static struct platform_driver s365_board_driver = {
120 .driver = {
121 .name = "s365-board",
122 .owner = THIS_MODULE,
123 .of_match_table = s365_board_match,
124 },
125};
126
Linus Walleij3d812772009-09-23 15:45:02 +0100127/*
128 * So at module init time we hog the regulator!
129 */
Linus Walleij4d3ab5e2013-04-19 10:50:42 +0200130static int __init u300_init_boardpower(void)
131{
Linus Walleij75a7f3f2013-04-22 11:29:30 +0200132 return platform_driver_probe(&s365_board_driver,
133 s365_board_probe);
Linus Walleij4d3ab5e2013-04-19 10:50:42 +0200134}
135
136device_initcall(u300_init_boardpower);