Linus Walleij | 3d81277 | 2009-09-23 15:45:02 +0100 | [diff] [blame] | 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> |
Linus Walleij | 4d3ab5e | 2013-04-19 10:50:42 +0200 | [diff] [blame] | 13 | #include <linux/of.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/regulator/machine.h> |
Linus Walleij | 3d81277 | 2009-09-23 15:45:02 +0100 | [diff] [blame] | 17 | #include <linux/regulator/consumer.h> |
| 18 | /* Those are just for writing in syscon */ |
| 19 | #include <linux/io.h> |
Linus Walleij | 0004b01 | 2013-05-02 16:56:15 +0200 | [diff] [blame^] | 20 | #include <mach/u300-regs.h> |
| 21 | |
| 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 Walleij | 3d81277 | 2009-09-23 15:45:02 +0100 | [diff] [blame] | 26 | |
| 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 | */ |
| 32 | static 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 | */ |
| 39 | void 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 Walleij | 4d3ab5e | 2013-04-19 10:50:42 +0200 | [diff] [blame] | 58 | static int __init __u300_init_boardpower(struct platform_device *pdev) |
Linus Walleij | 3d81277 | 2009-09-23 15:45:02 +0100 | [diff] [blame] | 59 | { |
| 60 | int err; |
| 61 | u32 val; |
| 62 | |
| 63 | pr_info("U300: setting up board power\n"); |
Linus Walleij | 75a7f3f | 2013-04-22 11:29:30 +0200 | [diff] [blame] | 64 | main_power_15 = regulator_get(&pdev->dev, "vana15"); |
Linus Walleij | 4d3ab5e | 2013-04-19 10:50:42 +0200 | [diff] [blame] | 65 | |
Linus Walleij | 3d81277 | 2009-09-23 15:45:02 +0100 | [diff] [blame] | 66 | if (IS_ERR(main_power_15)) { |
| 67 | pr_err("could not get vana15"); |
| 68 | return PTR_ERR(main_power_15); |
| 69 | } |
| 70 | err = regulator_enable(main_power_15); |
| 71 | if (err) { |
| 72 | pr_err("could not enable vana15\n"); |
| 73 | return err; |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * On U300 a special system controller register pulls up the DC |
| 78 | * until the vana15 (LDO D) regulator comes up. At this point, all |
| 79 | * regulators are set and we do not need power control via |
| 80 | * DC ON anymore. This function will likely be moved whenever |
| 81 | * the rest of the U300 power management is implemented. |
| 82 | */ |
| 83 | pr_info("U300: disable system controller pull-up\n"); |
| 84 | val = readw(U300_SYSCON_VBASE + U300_SYSCON_PMCR); |
| 85 | val &= ~U300_SYSCON_PMCR_DCON_ENABLE; |
| 86 | writew(val, U300_SYSCON_VBASE + U300_SYSCON_PMCR); |
| 87 | |
| 88 | /* Register globally exported PM poweroff hook */ |
| 89 | pm_power_off = u300_pm_poweroff; |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Linus Walleij | 4d3ab5e | 2013-04-19 10:50:42 +0200 | [diff] [blame] | 94 | static int __init s365_board_probe(struct platform_device *pdev) |
| 95 | { |
| 96 | return __u300_init_boardpower(pdev); |
| 97 | } |
| 98 | |
| 99 | static const struct of_device_id s365_board_match[] = { |
| 100 | { .compatible = "stericsson,s365" }, |
| 101 | {}, |
| 102 | }; |
| 103 | |
| 104 | static struct platform_driver s365_board_driver = { |
| 105 | .driver = { |
| 106 | .name = "s365-board", |
| 107 | .owner = THIS_MODULE, |
| 108 | .of_match_table = s365_board_match, |
| 109 | }, |
| 110 | }; |
| 111 | |
Linus Walleij | 3d81277 | 2009-09-23 15:45:02 +0100 | [diff] [blame] | 112 | /* |
| 113 | * So at module init time we hog the regulator! |
| 114 | */ |
Linus Walleij | 4d3ab5e | 2013-04-19 10:50:42 +0200 | [diff] [blame] | 115 | static int __init u300_init_boardpower(void) |
| 116 | { |
Linus Walleij | 75a7f3f | 2013-04-22 11:29:30 +0200 | [diff] [blame] | 117 | return platform_driver_probe(&s365_board_driver, |
| 118 | s365_board_probe); |
Linus Walleij | 4d3ab5e | 2013-04-19 10:50:42 +0200 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | device_initcall(u300_init_boardpower); |