1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * arch/arm/mach-u300/regulator.c
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2009 ST-Ericsson AB
6*4882a593Smuzhiyun * Handle board-bound regulators and board power not related
7*4882a593Smuzhiyun * to any devices.
8*4882a593Smuzhiyun * Author: Linus Walleij <linus.walleij@stericsson.com>
9*4882a593Smuzhiyun */
10*4882a593Smuzhiyun #include <linux/device.h>
11*4882a593Smuzhiyun #include <linux/signal.h>
12*4882a593Smuzhiyun #include <linux/err.h>
13*4882a593Smuzhiyun #include <linux/of.h>
14*4882a593Smuzhiyun #include <linux/module.h>
15*4882a593Smuzhiyun #include <linux/platform_device.h>
16*4882a593Smuzhiyun #include <linux/regulator/machine.h>
17*4882a593Smuzhiyun #include <linux/regulator/consumer.h>
18*4882a593Smuzhiyun #include <linux/mfd/syscon.h>
19*4882a593Smuzhiyun #include <linux/regmap.h>
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun /* Power Management Control 16bit (R/W) */
22*4882a593Smuzhiyun #define U300_SYSCON_PMCR (0x50)
23*4882a593Smuzhiyun #define U300_SYSCON_PMCR_DCON_ENABLE (0x0002)
24*4882a593Smuzhiyun #define U300_SYSCON_PMCR_PWR_MGNT_ENABLE (0x0001)
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun /*
27*4882a593Smuzhiyun * Regulators that power the board and chip and which are
28*4882a593Smuzhiyun * not copuled to specific drivers are hogged in these
29*4882a593Smuzhiyun * instances.
30*4882a593Smuzhiyun */
31*4882a593Smuzhiyun static struct regulator *main_power_15;
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun /*
34*4882a593Smuzhiyun * This function is used from pm.h to shut down the system by
35*4882a593Smuzhiyun * resetting all regulators in turn and then disable regulator
36*4882a593Smuzhiyun * LDO D (main power).
37*4882a593Smuzhiyun */
u300_pm_poweroff(void)38*4882a593Smuzhiyun void u300_pm_poweroff(void)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun sigset_t old, all;
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun sigfillset(&all);
43*4882a593Smuzhiyun if (!sigprocmask(SIG_BLOCK, &all, &old)) {
44*4882a593Smuzhiyun /* Disable LDO D to shut down the system */
45*4882a593Smuzhiyun if (main_power_15)
46*4882a593Smuzhiyun regulator_disable(main_power_15);
47*4882a593Smuzhiyun else
48*4882a593Smuzhiyun pr_err("regulator not available to shut down system\n");
49*4882a593Smuzhiyun (void) sigprocmask(SIG_SETMASK, &old, NULL);
50*4882a593Smuzhiyun }
51*4882a593Smuzhiyun return;
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun /*
55*4882a593Smuzhiyun * Hog the regulators needed to power up the board.
56*4882a593Smuzhiyun */
__u300_init_boardpower(struct platform_device * pdev)57*4882a593Smuzhiyun static int __init __u300_init_boardpower(struct platform_device *pdev)
58*4882a593Smuzhiyun {
59*4882a593Smuzhiyun struct device_node *np = pdev->dev.of_node;
60*4882a593Smuzhiyun struct device_node *syscon_np;
61*4882a593Smuzhiyun struct regmap *regmap;
62*4882a593Smuzhiyun int err;
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun pr_info("U300: setting up board power\n");
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun syscon_np = of_parse_phandle(np, "syscon", 0);
67*4882a593Smuzhiyun if (!syscon_np) {
68*4882a593Smuzhiyun pr_crit("U300: no syscon node\n");
69*4882a593Smuzhiyun return -ENODEV;
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun regmap = syscon_node_to_regmap(syscon_np);
72*4882a593Smuzhiyun if (IS_ERR(regmap)) {
73*4882a593Smuzhiyun pr_crit("U300: could not locate syscon regmap\n");
74*4882a593Smuzhiyun return PTR_ERR(regmap);
75*4882a593Smuzhiyun }
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun main_power_15 = regulator_get(&pdev->dev, "vana15");
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun if (IS_ERR(main_power_15)) {
80*4882a593Smuzhiyun pr_err("could not get vana15");
81*4882a593Smuzhiyun return PTR_ERR(main_power_15);
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun err = regulator_enable(main_power_15);
84*4882a593Smuzhiyun if (err) {
85*4882a593Smuzhiyun pr_err("could not enable vana15\n");
86*4882a593Smuzhiyun return err;
87*4882a593Smuzhiyun }
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun /*
90*4882a593Smuzhiyun * On U300 a special system controller register pulls up the DC
91*4882a593Smuzhiyun * until the vana15 (LDO D) regulator comes up. At this point, all
92*4882a593Smuzhiyun * regulators are set and we do not need power control via
93*4882a593Smuzhiyun * DC ON anymore. This function will likely be moved whenever
94*4882a593Smuzhiyun * the rest of the U300 power management is implemented.
95*4882a593Smuzhiyun */
96*4882a593Smuzhiyun pr_info("U300: disable system controller pull-up\n");
97*4882a593Smuzhiyun regmap_update_bits(regmap, U300_SYSCON_PMCR,
98*4882a593Smuzhiyun U300_SYSCON_PMCR_DCON_ENABLE, 0);
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun /* Register globally exported PM poweroff hook */
101*4882a593Smuzhiyun pm_power_off = u300_pm_poweroff;
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun return 0;
104*4882a593Smuzhiyun }
105*4882a593Smuzhiyun
s365_board_probe(struct platform_device * pdev)106*4882a593Smuzhiyun static int __init s365_board_probe(struct platform_device *pdev)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun return __u300_init_boardpower(pdev);
109*4882a593Smuzhiyun }
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun static const struct of_device_id s365_board_match[] = {
112*4882a593Smuzhiyun { .compatible = "stericsson,s365" },
113*4882a593Smuzhiyun {},
114*4882a593Smuzhiyun };
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun static struct platform_driver s365_board_driver = {
117*4882a593Smuzhiyun .driver = {
118*4882a593Smuzhiyun .name = "s365-board",
119*4882a593Smuzhiyun .of_match_table = s365_board_match,
120*4882a593Smuzhiyun },
121*4882a593Smuzhiyun };
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun /*
124*4882a593Smuzhiyun * So at module init time we hog the regulator!
125*4882a593Smuzhiyun */
u300_init_boardpower(void)126*4882a593Smuzhiyun static int __init u300_init_boardpower(void)
127*4882a593Smuzhiyun {
128*4882a593Smuzhiyun return platform_driver_probe(&s365_board_driver,
129*4882a593Smuzhiyun s365_board_probe);
130*4882a593Smuzhiyun }
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun device_initcall(u300_init_boardpower);
133*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
134*4882a593Smuzhiyun MODULE_AUTHOR("Linus Walleij");
135