David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1 | /* |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 2 | * twl-regulator.c -- support regulators in twl4030/twl6030 family chips |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2008 David Brownell |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
Stephen Rothwell | 8f52a58 | 2012-08-16 15:16:05 +1000 | [diff] [blame] | 13 | #include <linux/string.h> |
| 14 | #include <linux/slab.h> |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/platform_device.h> |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 18 | #include <linux/of.h> |
| 19 | #include <linux/of_device.h> |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 20 | #include <linux/regulator/driver.h> |
| 21 | #include <linux/regulator/machine.h> |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 22 | #include <linux/regulator/of_regulator.h> |
Santosh Shilimkar | b07682b | 2009-12-13 20:05:51 +0100 | [diff] [blame] | 23 | #include <linux/i2c/twl.h> |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 24 | |
| 25 | |
| 26 | /* |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 27 | * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 28 | * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions |
| 29 | * include an audio codec, battery charger, and more voltage regulators. |
| 30 | * These chips are often used in OMAP-based systems. |
| 31 | * |
| 32 | * This driver implements software-based resource control for various |
| 33 | * voltage regulators. This is usually augmented with state machine |
| 34 | * based control. |
| 35 | */ |
| 36 | |
| 37 | struct twlreg_info { |
| 38 | /* start of regulator's PM_RECEIVER control register bank */ |
| 39 | u8 base; |
| 40 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 41 | /* twl resource ID, for resource control state machine */ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 42 | u8 id; |
| 43 | |
| 44 | /* voltage in mV = table[VSEL]; table_len must be a power-of-two */ |
| 45 | u8 table_len; |
| 46 | const u16 *table; |
| 47 | |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame] | 48 | /* State REMAP default configuration */ |
| 49 | u8 remap; |
| 50 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 51 | /* chip constraints on regulator behavior */ |
| 52 | u16 min_mV; |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 53 | u16 max_mV; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 54 | |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 55 | u8 flags; |
| 56 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 57 | /* used by regulator core */ |
| 58 | struct regulator_desc desc; |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 59 | |
| 60 | /* chip specific features */ |
Jingoo Han | 3db3988 | 2014-01-08 10:04:48 +0900 | [diff] [blame] | 61 | unsigned long features; |
Tero Kristo | 63bfff4 | 2012-02-16 12:27:52 +0200 | [diff] [blame] | 62 | |
| 63 | /* |
| 64 | * optional override functions for voltage set/get |
| 65 | * these are currently only used for SMPS regulators |
| 66 | */ |
| 67 | int (*get_voltage)(void *data); |
| 68 | int (*set_voltage)(void *data, int target_uV); |
| 69 | |
| 70 | /* data passed from board for external get/set voltage */ |
| 71 | void *data; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | |
| 75 | /* LDO control registers ... offset is from the base of its register bank. |
| 76 | * The first three registers of all power resource banks help hardware to |
| 77 | * manage the various resource groups. |
| 78 | */ |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 79 | /* Common offset in TWL4030/6030 */ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 80 | #define VREG_GRP 0 |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 81 | /* TWL4030 register offsets */ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 82 | #define VREG_TYPE 1 |
| 83 | #define VREG_REMAP 2 |
| 84 | #define VREG_DEDICATED 3 /* LDO control */ |
Tero Kristo | ba305e3 | 2011-11-28 16:53:19 +0200 | [diff] [blame] | 85 | #define VREG_VOLTAGE_SMPS_4030 9 |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 86 | /* TWL6030 register offsets */ |
| 87 | #define VREG_TRANS 1 |
| 88 | #define VREG_STATE 2 |
| 89 | #define VREG_VOLTAGE 3 |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 90 | #define VREG_VOLTAGE_SMPS 4 |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 91 | /* TWL6030 Misc register offsets */ |
| 92 | #define VREG_BC_ALL 1 |
| 93 | #define VREG_BC_REF 2 |
| 94 | #define VREG_BC_PROC 3 |
| 95 | #define VREG_BC_CLK_RST 4 |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 96 | |
Saquib Herman | 21657ebf | 2011-04-01 10:22:42 +0530 | [diff] [blame] | 97 | /* TWL6030 LDO register values for CFG_STATE */ |
| 98 | #define TWL6030_CFG_STATE_OFF 0x00 |
| 99 | #define TWL6030_CFG_STATE_ON 0x01 |
Saquib Herman | 9a0244a | 2011-04-01 10:22:45 +0530 | [diff] [blame] | 100 | #define TWL6030_CFG_STATE_OFF2 0x02 |
| 101 | #define TWL6030_CFG_STATE_SLEEP 0x03 |
Saquib Herman | 21657ebf | 2011-04-01 10:22:42 +0530 | [diff] [blame] | 102 | #define TWL6030_CFG_STATE_GRP_SHIFT 5 |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 103 | #define TWL6030_CFG_STATE_APP_SHIFT 2 |
| 104 | #define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT) |
| 105 | #define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\ |
| 106 | TWL6030_CFG_STATE_APP_SHIFT) |
Saquib Herman | 21657ebf | 2011-04-01 10:22:42 +0530 | [diff] [blame] | 107 | |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 108 | /* Flags for SMPS Voltage reading */ |
| 109 | #define SMPS_OFFSET_EN BIT(0) |
| 110 | #define SMPS_EXTENDED_EN BIT(1) |
| 111 | |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 112 | /* twl6032 SMPS EPROM values */ |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 113 | #define TWL6030_SMPS_OFFSET 0xB0 |
| 114 | #define TWL6030_SMPS_MULT 0xB3 |
| 115 | #define SMPS_MULTOFFSET_SMPS4 BIT(0) |
| 116 | #define SMPS_MULTOFFSET_VIO BIT(1) |
| 117 | #define SMPS_MULTOFFSET_SMPS3 BIT(6) |
| 118 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 119 | static inline int |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 120 | twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 121 | { |
| 122 | u8 value; |
| 123 | int status; |
| 124 | |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 125 | status = twl_i2c_read_u8(slave_subgp, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 126 | &value, info->base + offset); |
| 127 | return (status < 0) ? status : value; |
| 128 | } |
| 129 | |
| 130 | static inline int |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 131 | twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset, |
| 132 | u8 value) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 133 | { |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 134 | return twl_i2c_write_u8(slave_subgp, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 135 | value, info->base + offset); |
| 136 | } |
| 137 | |
| 138 | /*----------------------------------------------------------------------*/ |
| 139 | |
| 140 | /* generic power resource operations, which work on all regulators */ |
| 141 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 142 | static int twlreg_grp(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 143 | { |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 144 | return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER, |
| 145 | VREG_GRP); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /* |
| 149 | * Enable/disable regulators by joining/leaving the P1 (processor) group. |
| 150 | * We assume nobody else is updating the DEV_GRP registers. |
| 151 | */ |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 152 | /* definition for 4030 family */ |
| 153 | #define P3_GRP_4030 BIT(7) /* "peripherals" */ |
| 154 | #define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */ |
| 155 | #define P1_GRP_4030 BIT(5) /* CPU/Linux */ |
| 156 | /* definition for 6030 family */ |
| 157 | #define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */ |
| 158 | #define P2_GRP_6030 BIT(1) /* "peripherals" */ |
| 159 | #define P1_GRP_6030 BIT(0) /* CPU/Linux */ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 160 | |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 161 | static int twl4030reg_is_enabled(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 162 | { |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 163 | int state = twlreg_grp(rdev); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 164 | |
| 165 | if (state < 0) |
| 166 | return state; |
| 167 | |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 168 | return state & P1_GRP_4030; |
| 169 | } |
| 170 | |
| 171 | static int twl6030reg_is_enabled(struct regulator_dev *rdev) |
| 172 | { |
| 173 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 174 | int grp = 0, val; |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 175 | |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 176 | if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS))) { |
Axel Lin | b6f476c | 2012-04-11 11:07:17 +0800 | [diff] [blame] | 177 | grp = twlreg_grp(rdev); |
| 178 | if (grp < 0) |
| 179 | return grp; |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 180 | grp &= P1_GRP_6030; |
Axel Lin | b6f476c | 2012-04-11 11:07:17 +0800 | [diff] [blame] | 181 | } else { |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 182 | grp = 1; |
Axel Lin | b6f476c | 2012-04-11 11:07:17 +0800 | [diff] [blame] | 183 | } |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 184 | |
| 185 | val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE); |
| 186 | val = TWL6030_CFG_STATE_APP(val); |
| 187 | |
| 188 | return grp && (val == TWL6030_CFG_STATE_ON); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 191 | static int twl4030reg_enable(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 192 | { |
| 193 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 194 | int grp; |
Juha Keski-Saari | 53b8a9d | 2009-12-16 14:55:26 +0200 | [diff] [blame] | 195 | int ret; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 196 | |
Axel Lin | b6f476c | 2012-04-11 11:07:17 +0800 | [diff] [blame] | 197 | grp = twlreg_grp(rdev); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 198 | if (grp < 0) |
| 199 | return grp; |
| 200 | |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 201 | grp |= P1_GRP_4030; |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 202 | |
Juha Keski-Saari | 53b8a9d | 2009-12-16 14:55:26 +0200 | [diff] [blame] | 203 | ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); |
| 204 | |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 205 | return ret; |
| 206 | } |
| 207 | |
| 208 | static int twl6030reg_enable(struct regulator_dev *rdev) |
| 209 | { |
| 210 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 211 | int grp = 0; |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 212 | int ret; |
| 213 | |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 214 | if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS))) |
Axel Lin | b6f476c | 2012-04-11 11:07:17 +0800 | [diff] [blame] | 215 | grp = twlreg_grp(rdev); |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 216 | if (grp < 0) |
| 217 | return grp; |
| 218 | |
| 219 | ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, |
| 220 | grp << TWL6030_CFG_STATE_GRP_SHIFT | |
| 221 | TWL6030_CFG_STATE_ON); |
Juha Keski-Saari | 53b8a9d | 2009-12-16 14:55:26 +0200 | [diff] [blame] | 222 | return ret; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 223 | } |
| 224 | |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 225 | static int twl4030reg_disable(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 226 | { |
| 227 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 228 | int grp; |
Saquib Herman | 21657ebf | 2011-04-01 10:22:42 +0530 | [diff] [blame] | 229 | int ret; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 230 | |
Axel Lin | b6f476c | 2012-04-11 11:07:17 +0800 | [diff] [blame] | 231 | grp = twlreg_grp(rdev); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 232 | if (grp < 0) |
| 233 | return grp; |
| 234 | |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 235 | grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030); |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 236 | |
Saquib Herman | 21657ebf | 2011-04-01 10:22:42 +0530 | [diff] [blame] | 237 | ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); |
| 238 | |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 239 | return ret; |
| 240 | } |
| 241 | |
| 242 | static int twl6030reg_disable(struct regulator_dev *rdev) |
| 243 | { |
| 244 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 245 | int grp = 0; |
| 246 | int ret; |
| 247 | |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 248 | if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS))) |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 249 | grp = P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030; |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 250 | |
| 251 | /* For 6030, set the off state for all grps enabled */ |
| 252 | ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, |
| 253 | (grp) << TWL6030_CFG_STATE_GRP_SHIFT | |
| 254 | TWL6030_CFG_STATE_OFF); |
Saquib Herman | 21657ebf | 2011-04-01 10:22:42 +0530 | [diff] [blame] | 255 | |
| 256 | return ret; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Saquib Herman | 9a0244a | 2011-04-01 10:22:45 +0530 | [diff] [blame] | 259 | static int twl4030reg_get_status(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 260 | { |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 261 | int state = twlreg_grp(rdev); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 262 | |
| 263 | if (state < 0) |
| 264 | return state; |
| 265 | state &= 0x0f; |
| 266 | |
| 267 | /* assume state != WARM_RESET; we'd not be running... */ |
| 268 | if (!state) |
| 269 | return REGULATOR_STATUS_OFF; |
| 270 | return (state & BIT(3)) |
| 271 | ? REGULATOR_STATUS_NORMAL |
| 272 | : REGULATOR_STATUS_STANDBY; |
| 273 | } |
| 274 | |
Saquib Herman | 9a0244a | 2011-04-01 10:22:45 +0530 | [diff] [blame] | 275 | static int twl6030reg_get_status(struct regulator_dev *rdev) |
| 276 | { |
| 277 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 278 | int val; |
| 279 | |
| 280 | val = twlreg_grp(rdev); |
| 281 | if (val < 0) |
| 282 | return val; |
| 283 | |
| 284 | val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE); |
| 285 | |
| 286 | switch (TWL6030_CFG_STATE_APP(val)) { |
| 287 | case TWL6030_CFG_STATE_ON: |
| 288 | return REGULATOR_STATUS_NORMAL; |
| 289 | |
| 290 | case TWL6030_CFG_STATE_SLEEP: |
| 291 | return REGULATOR_STATUS_STANDBY; |
| 292 | |
| 293 | case TWL6030_CFG_STATE_OFF: |
| 294 | case TWL6030_CFG_STATE_OFF2: |
| 295 | default: |
| 296 | break; |
| 297 | } |
| 298 | |
| 299 | return REGULATOR_STATUS_OFF; |
| 300 | } |
| 301 | |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 302 | static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 303 | { |
| 304 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 305 | unsigned message; |
| 306 | int status; |
| 307 | |
| 308 | /* We can only set the mode through state machine commands... */ |
| 309 | switch (mode) { |
| 310 | case REGULATOR_MODE_NORMAL: |
| 311 | message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE); |
| 312 | break; |
| 313 | case REGULATOR_MODE_STANDBY: |
| 314 | message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP); |
| 315 | break; |
| 316 | default: |
| 317 | return -EINVAL; |
| 318 | } |
| 319 | |
| 320 | /* Ensure the resource is associated with some group */ |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 321 | status = twlreg_grp(rdev); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 322 | if (status < 0) |
| 323 | return status; |
Rajendra Nayak | 441a450 | 2009-12-13 22:19:23 +0100 | [diff] [blame] | 324 | if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030))) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 325 | return -EACCES; |
| 326 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 327 | status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, |
Axel Lin | b9e26bc | 2010-10-22 16:38:22 +0800 | [diff] [blame] | 328 | message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB); |
| 329 | if (status < 0) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 330 | return status; |
| 331 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 332 | return twl_i2c_write_u8(TWL_MODULE_PM_MASTER, |
Axel Lin | b9e26bc | 2010-10-22 16:38:22 +0800 | [diff] [blame] | 333 | message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 334 | } |
| 335 | |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 336 | static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode) |
| 337 | { |
| 338 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 339 | int grp = 0; |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 340 | int val; |
| 341 | |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 342 | if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS))) |
Axel Lin | b6f476c | 2012-04-11 11:07:17 +0800 | [diff] [blame] | 343 | grp = twlreg_grp(rdev); |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 344 | |
| 345 | if (grp < 0) |
| 346 | return grp; |
| 347 | |
| 348 | /* Compose the state register settings */ |
| 349 | val = grp << TWL6030_CFG_STATE_GRP_SHIFT; |
| 350 | /* We can only set the mode through state machine commands... */ |
| 351 | switch (mode) { |
| 352 | case REGULATOR_MODE_NORMAL: |
| 353 | val |= TWL6030_CFG_STATE_ON; |
| 354 | break; |
| 355 | case REGULATOR_MODE_STANDBY: |
| 356 | val |= TWL6030_CFG_STATE_SLEEP; |
| 357 | break; |
| 358 | |
| 359 | default: |
| 360 | return -EINVAL; |
| 361 | } |
| 362 | |
| 363 | return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, val); |
| 364 | } |
| 365 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 366 | /*----------------------------------------------------------------------*/ |
| 367 | |
| 368 | /* |
| 369 | * Support for adjustable-voltage LDOs uses a four bit (or less) voltage |
| 370 | * select field in its control register. We use tables indexed by VSEL |
| 371 | * to record voltages in milliVolts. (Accuracy is about three percent.) |
| 372 | * |
| 373 | * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon; |
| 374 | * currently handled by listing two slightly different VAUX2 regulators, |
| 375 | * only one of which will be configured. |
| 376 | * |
| 377 | * VSEL values documented as "TI cannot support these values" are flagged |
| 378 | * in these tables as UNSUP() values; we normally won't assign them. |
Adrian Hunter | d6bb69c | 2009-03-06 14:51:30 +0200 | [diff] [blame] | 379 | * |
| 380 | * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported. |
| 381 | * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting. |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 382 | */ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 383 | #define UNSUP_MASK 0x8000 |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 384 | |
| 385 | #define UNSUP(x) (UNSUP_MASK | (x)) |
NeilBrown | 411a2df | 2012-05-09 05:44:00 +1000 | [diff] [blame] | 386 | #define IS_UNSUP(info, x) \ |
| 387 | ((UNSUP_MASK & (x)) && \ |
| 388 | !((info)->features & TWL4030_ALLOW_UNSUPPORTED)) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 389 | #define LDO_MV(x) (~UNSUP_MASK & (x)) |
| 390 | |
| 391 | |
| 392 | static const u16 VAUX1_VSEL_table[] = { |
| 393 | UNSUP(1500), UNSUP(1800), 2500, 2800, |
| 394 | 3000, 3000, 3000, 3000, |
| 395 | }; |
| 396 | static const u16 VAUX2_4030_VSEL_table[] = { |
| 397 | UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300, |
| 398 | 1500, 1800, UNSUP(1850), 2500, |
| 399 | UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000), |
| 400 | UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), |
| 401 | }; |
| 402 | static const u16 VAUX2_VSEL_table[] = { |
| 403 | 1700, 1700, 1900, 1300, |
| 404 | 1500, 1800, 2000, 2500, |
| 405 | 2100, 2800, 2200, 2300, |
| 406 | 2400, 2400, 2400, 2400, |
| 407 | }; |
| 408 | static const u16 VAUX3_VSEL_table[] = { |
| 409 | 1500, 1800, 2500, 2800, |
Adrian Hunter | d6bb69c | 2009-03-06 14:51:30 +0200 | [diff] [blame] | 410 | 3000, 3000, 3000, 3000, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 411 | }; |
| 412 | static const u16 VAUX4_VSEL_table[] = { |
| 413 | 700, 1000, 1200, UNSUP(1300), |
| 414 | 1500, 1800, UNSUP(1850), 2500, |
David Brownell | 1897e74 | 2009-03-10 11:51:15 -0800 | [diff] [blame] | 415 | UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000), |
| 416 | UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 417 | }; |
| 418 | static const u16 VMMC1_VSEL_table[] = { |
| 419 | 1850, 2850, 3000, 3150, |
| 420 | }; |
| 421 | static const u16 VMMC2_VSEL_table[] = { |
| 422 | UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300), |
| 423 | UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500), |
| 424 | 2600, 2800, 2850, 3000, |
| 425 | 3150, 3150, 3150, 3150, |
| 426 | }; |
| 427 | static const u16 VPLL1_VSEL_table[] = { |
| 428 | 1000, 1200, 1300, 1800, |
| 429 | UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000), |
| 430 | }; |
| 431 | static const u16 VPLL2_VSEL_table[] = { |
| 432 | 700, 1000, 1200, 1300, |
| 433 | UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500), |
| 434 | UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000), |
| 435 | UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), |
| 436 | }; |
| 437 | static const u16 VSIM_VSEL_table[] = { |
| 438 | UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800, |
| 439 | 2800, 3000, 3000, 3000, |
| 440 | }; |
| 441 | static const u16 VDAC_VSEL_table[] = { |
| 442 | 1200, 1300, 1800, 1800, |
| 443 | }; |
Juha Keski-Saari | 07fc493 | 2009-12-16 15:27:55 +0200 | [diff] [blame] | 444 | static const u16 VIO_VSEL_table[] = { |
| 445 | 1800, 1850, |
| 446 | }; |
| 447 | static const u16 VINTANA2_VSEL_table[] = { |
| 448 | 2500, 2750, |
| 449 | }; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 450 | |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 451 | static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index) |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 452 | { |
| 453 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 454 | int mV = info->table[index]; |
| 455 | |
NeilBrown | 411a2df | 2012-05-09 05:44:00 +1000 | [diff] [blame] | 456 | return IS_UNSUP(info, mV) ? 0 : (LDO_MV(mV) * 1000); |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 457 | } |
| 458 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 459 | static int |
Axel Lin | dd16b1f | 2012-03-26 09:30:06 +0800 | [diff] [blame] | 460 | twl4030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 461 | { |
| 462 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 463 | |
Axel Lin | dd16b1f | 2012-03-26 09:30:06 +0800 | [diff] [blame] | 464 | return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, |
| 465 | selector); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 466 | } |
| 467 | |
Axel Lin | 6949fbe | 2013-02-16 10:09:54 +0800 | [diff] [blame] | 468 | static int twl4030ldo_get_voltage_sel(struct regulator_dev *rdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 469 | { |
| 470 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
Axel Lin | 6949fbe | 2013-02-16 10:09:54 +0800 | [diff] [blame] | 471 | int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 472 | |
| 473 | if (vsel < 0) |
| 474 | return vsel; |
| 475 | |
| 476 | vsel &= info->table_len - 1; |
Axel Lin | 6949fbe | 2013-02-16 10:09:54 +0800 | [diff] [blame] | 477 | return vsel; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 478 | } |
| 479 | |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 480 | static struct regulator_ops twl4030ldo_ops = { |
| 481 | .list_voltage = twl4030ldo_list_voltage, |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 482 | |
Axel Lin | dd16b1f | 2012-03-26 09:30:06 +0800 | [diff] [blame] | 483 | .set_voltage_sel = twl4030ldo_set_voltage_sel, |
Axel Lin | 6949fbe | 2013-02-16 10:09:54 +0800 | [diff] [blame] | 484 | .get_voltage_sel = twl4030ldo_get_voltage_sel, |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 485 | |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 486 | .enable = twl4030reg_enable, |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 487 | .disable = twl4030reg_disable, |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 488 | .is_enabled = twl4030reg_is_enabled, |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 489 | |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 490 | .set_mode = twl4030reg_set_mode, |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 491 | |
Saquib Herman | 9a0244a | 2011-04-01 10:22:45 +0530 | [diff] [blame] | 492 | .get_status = twl4030reg_get_status, |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 493 | }; |
| 494 | |
Tero Kristo | ba305e3 | 2011-11-28 16:53:19 +0200 | [diff] [blame] | 495 | static int |
| 496 | twl4030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, |
| 497 | unsigned *selector) |
| 498 | { |
| 499 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 500 | int vsel = DIV_ROUND_UP(min_uV - 600000, 12500); |
| 501 | |
Tero Kristo | 63bfff4 | 2012-02-16 12:27:52 +0200 | [diff] [blame] | 502 | if (info->set_voltage) { |
| 503 | return info->set_voltage(info->data, min_uV); |
| 504 | } else { |
| 505 | twlreg_write(info, TWL_MODULE_PM_RECEIVER, |
| 506 | VREG_VOLTAGE_SMPS_4030, vsel); |
| 507 | } |
| 508 | |
Tero Kristo | ba305e3 | 2011-11-28 16:53:19 +0200 | [diff] [blame] | 509 | return 0; |
| 510 | } |
| 511 | |
| 512 | static int twl4030smps_get_voltage(struct regulator_dev *rdev) |
| 513 | { |
| 514 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
Tero Kristo | 63bfff4 | 2012-02-16 12:27:52 +0200 | [diff] [blame] | 515 | int vsel; |
| 516 | |
| 517 | if (info->get_voltage) |
| 518 | return info->get_voltage(info->data); |
| 519 | |
| 520 | vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, |
Tero Kristo | ba305e3 | 2011-11-28 16:53:19 +0200 | [diff] [blame] | 521 | VREG_VOLTAGE_SMPS_4030); |
| 522 | |
| 523 | return vsel * 12500 + 600000; |
| 524 | } |
| 525 | |
| 526 | static struct regulator_ops twl4030smps_ops = { |
| 527 | .set_voltage = twl4030smps_set_voltage, |
| 528 | .get_voltage = twl4030smps_get_voltage, |
| 529 | }; |
| 530 | |
Tero Kristo | 34a3844 | 2012-02-28 15:09:10 +0530 | [diff] [blame] | 531 | static int twl6030coresmps_set_voltage(struct regulator_dev *rdev, int min_uV, |
| 532 | int max_uV, unsigned *selector) |
| 533 | { |
| 534 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 535 | |
| 536 | if (info->set_voltage) |
| 537 | return info->set_voltage(info->data, min_uV); |
| 538 | |
| 539 | return -ENODEV; |
| 540 | } |
| 541 | |
| 542 | static int twl6030coresmps_get_voltage(struct regulator_dev *rdev) |
| 543 | { |
| 544 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 545 | |
| 546 | if (info->get_voltage) |
| 547 | return info->get_voltage(info->data); |
| 548 | |
| 549 | return -ENODEV; |
| 550 | } |
| 551 | |
| 552 | static struct regulator_ops twl6030coresmps_ops = { |
| 553 | .set_voltage = twl6030coresmps_set_voltage, |
| 554 | .get_voltage = twl6030coresmps_get_voltage, |
| 555 | }; |
| 556 | |
Axel Lin | c6a717c | 2012-07-16 18:31:10 +0800 | [diff] [blame] | 557 | static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned sel) |
| 558 | { |
| 559 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 560 | |
| 561 | switch (sel) { |
| 562 | case 0: |
| 563 | return 0; |
| 564 | case 1 ... 24: |
| 565 | /* Linear mapping from 00000001 to 00011000: |
| 566 | * Absolute voltage value = 1.0 V + 0.1 V × (sel – 00000001) |
| 567 | */ |
| 568 | return (info->min_mV + 100 * (sel - 1)) * 1000; |
| 569 | case 25 ... 30: |
| 570 | return -EINVAL; |
| 571 | case 31: |
| 572 | return 2750000; |
| 573 | default: |
| 574 | return -EINVAL; |
| 575 | } |
| 576 | } |
| 577 | |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 578 | static int |
Axel Lin | 4bcb9f4 | 2012-07-09 11:26:28 +0800 | [diff] [blame] | 579 | twl6030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector) |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 580 | { |
| 581 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 582 | |
Axel Lin | 4bcb9f4 | 2012-07-09 11:26:28 +0800 | [diff] [blame] | 583 | return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, |
| 584 | selector); |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 585 | } |
| 586 | |
Axel Lin | 4bcb9f4 | 2012-07-09 11:26:28 +0800 | [diff] [blame] | 587 | static int twl6030ldo_get_voltage_sel(struct regulator_dev *rdev) |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 588 | { |
| 589 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
Axel Lin | a3cb80f | 2012-07-09 11:22:31 +0800 | [diff] [blame] | 590 | int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE); |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 591 | |
Axel Lin | 4bcb9f4 | 2012-07-09 11:26:28 +0800 | [diff] [blame] | 592 | return vsel; |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | static struct regulator_ops twl6030ldo_ops = { |
Axel Lin | c6a717c | 2012-07-16 18:31:10 +0800 | [diff] [blame] | 596 | .list_voltage = twl6030ldo_list_voltage, |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 597 | |
Axel Lin | 4bcb9f4 | 2012-07-09 11:26:28 +0800 | [diff] [blame] | 598 | .set_voltage_sel = twl6030ldo_set_voltage_sel, |
| 599 | .get_voltage_sel = twl6030ldo_get_voltage_sel, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 600 | |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 601 | .enable = twl6030reg_enable, |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 602 | .disable = twl6030reg_disable, |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 603 | .is_enabled = twl6030reg_is_enabled, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 604 | |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 605 | .set_mode = twl6030reg_set_mode, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 606 | |
Saquib Herman | 9a0244a | 2011-04-01 10:22:45 +0530 | [diff] [blame] | 607 | .get_status = twl6030reg_get_status, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 608 | }; |
| 609 | |
| 610 | /*----------------------------------------------------------------------*/ |
| 611 | |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 612 | static struct regulator_ops twl4030fixed_ops = { |
Axel Lin | b3816d5 | 2012-12-22 13:31:19 +0800 | [diff] [blame] | 613 | .list_voltage = regulator_list_voltage_linear, |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 614 | |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 615 | .enable = twl4030reg_enable, |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 616 | .disable = twl4030reg_disable, |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 617 | .is_enabled = twl4030reg_is_enabled, |
| 618 | |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 619 | .set_mode = twl4030reg_set_mode, |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 620 | |
Saquib Herman | 9a0244a | 2011-04-01 10:22:45 +0530 | [diff] [blame] | 621 | .get_status = twl4030reg_get_status, |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 622 | }; |
| 623 | |
| 624 | static struct regulator_ops twl6030fixed_ops = { |
Axel Lin | b3816d5 | 2012-12-22 13:31:19 +0800 | [diff] [blame] | 625 | .list_voltage = regulator_list_voltage_linear, |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 626 | |
Balaji T K | f8c2940 | 2011-05-20 19:03:51 +0530 | [diff] [blame] | 627 | .enable = twl6030reg_enable, |
Balaji T K | 0ff3897 | 2011-05-20 19:03:52 +0530 | [diff] [blame] | 628 | .disable = twl6030reg_disable, |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 629 | .is_enabled = twl6030reg_is_enabled, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 630 | |
Saquib Herman | 1a39962 | 2011-04-01 10:22:46 +0530 | [diff] [blame] | 631 | .set_mode = twl6030reg_set_mode, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 632 | |
Saquib Herman | 9a0244a | 2011-04-01 10:22:45 +0530 | [diff] [blame] | 633 | .get_status = twl6030reg_get_status, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 634 | }; |
| 635 | |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 636 | /* |
| 637 | * SMPS status and control |
| 638 | */ |
| 639 | |
| 640 | static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index) |
| 641 | { |
| 642 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 643 | |
| 644 | int voltage = 0; |
| 645 | |
| 646 | switch (info->flags) { |
| 647 | case SMPS_OFFSET_EN: |
| 648 | voltage = 100000; |
| 649 | /* fall through */ |
| 650 | case 0: |
| 651 | switch (index) { |
| 652 | case 0: |
| 653 | voltage = 0; |
| 654 | break; |
| 655 | case 58: |
| 656 | voltage = 1350 * 1000; |
| 657 | break; |
| 658 | case 59: |
| 659 | voltage = 1500 * 1000; |
| 660 | break; |
| 661 | case 60: |
| 662 | voltage = 1800 * 1000; |
| 663 | break; |
| 664 | case 61: |
| 665 | voltage = 1900 * 1000; |
| 666 | break; |
| 667 | case 62: |
| 668 | voltage = 2100 * 1000; |
| 669 | break; |
| 670 | default: |
| 671 | voltage += (600000 + (12500 * (index - 1))); |
| 672 | } |
| 673 | break; |
| 674 | case SMPS_EXTENDED_EN: |
| 675 | switch (index) { |
| 676 | case 0: |
| 677 | voltage = 0; |
| 678 | break; |
| 679 | case 58: |
| 680 | voltage = 2084 * 1000; |
| 681 | break; |
| 682 | case 59: |
| 683 | voltage = 2315 * 1000; |
| 684 | break; |
| 685 | case 60: |
| 686 | voltage = 2778 * 1000; |
| 687 | break; |
| 688 | case 61: |
| 689 | voltage = 2932 * 1000; |
| 690 | break; |
| 691 | case 62: |
| 692 | voltage = 3241 * 1000; |
| 693 | break; |
| 694 | default: |
| 695 | voltage = (1852000 + (38600 * (index - 1))); |
| 696 | } |
| 697 | break; |
| 698 | case SMPS_OFFSET_EN | SMPS_EXTENDED_EN: |
| 699 | switch (index) { |
| 700 | case 0: |
| 701 | voltage = 0; |
| 702 | break; |
| 703 | case 58: |
| 704 | voltage = 4167 * 1000; |
| 705 | break; |
| 706 | case 59: |
| 707 | voltage = 2315 * 1000; |
| 708 | break; |
| 709 | case 60: |
| 710 | voltage = 2778 * 1000; |
| 711 | break; |
| 712 | case 61: |
| 713 | voltage = 2932 * 1000; |
| 714 | break; |
| 715 | case 62: |
| 716 | voltage = 3241 * 1000; |
| 717 | break; |
| 718 | default: |
| 719 | voltage = (2161000 + (38600 * (index - 1))); |
| 720 | } |
| 721 | break; |
| 722 | } |
| 723 | |
| 724 | return voltage; |
| 725 | } |
| 726 | |
Axel Lin | 38f8f43 | 2012-07-14 13:41:23 +0800 | [diff] [blame] | 727 | static int twl6030smps_map_voltage(struct regulator_dev *rdev, int min_uV, |
| 728 | int max_uV) |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 729 | { |
Axel Lin | 38f8f43 | 2012-07-14 13:41:23 +0800 | [diff] [blame] | 730 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 731 | int vsel = 0; |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 732 | |
| 733 | switch (info->flags) { |
| 734 | case 0: |
| 735 | if (min_uV == 0) |
| 736 | vsel = 0; |
Laxman Dewangan | a33b6e5 | 2012-02-03 12:54:38 +0530 | [diff] [blame] | 737 | else if ((min_uV >= 600000) && (min_uV <= 1300000)) { |
Axel Lin | 268a164 | 2012-04-09 23:35:10 +0800 | [diff] [blame] | 738 | vsel = DIV_ROUND_UP(min_uV - 600000, 12500); |
Axel Lin | 0cb2f12 | 2012-04-10 23:07:52 +0800 | [diff] [blame] | 739 | vsel++; |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 740 | } |
| 741 | /* Values 1..57 for vsel are linear and can be calculated |
| 742 | * values 58..62 are non linear. |
| 743 | */ |
Axel Lin | 78292f4 | 2012-07-14 13:37:13 +0800 | [diff] [blame] | 744 | else if ((min_uV > 1900000) && (min_uV <= 2100000)) |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 745 | vsel = 62; |
Axel Lin | 78292f4 | 2012-07-14 13:37:13 +0800 | [diff] [blame] | 746 | else if ((min_uV > 1800000) && (min_uV <= 1900000)) |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 747 | vsel = 61; |
Axel Lin | 78292f4 | 2012-07-14 13:37:13 +0800 | [diff] [blame] | 748 | else if ((min_uV > 1500000) && (min_uV <= 1800000)) |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 749 | vsel = 60; |
Axel Lin | 78292f4 | 2012-07-14 13:37:13 +0800 | [diff] [blame] | 750 | else if ((min_uV > 1350000) && (min_uV <= 1500000)) |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 751 | vsel = 59; |
Axel Lin | 78292f4 | 2012-07-14 13:37:13 +0800 | [diff] [blame] | 752 | else if ((min_uV > 1300000) && (min_uV <= 1350000)) |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 753 | vsel = 58; |
| 754 | else |
| 755 | return -EINVAL; |
| 756 | break; |
| 757 | case SMPS_OFFSET_EN: |
| 758 | if (min_uV == 0) |
| 759 | vsel = 0; |
Laxman Dewangan | a33b6e5 | 2012-02-03 12:54:38 +0530 | [diff] [blame] | 760 | else if ((min_uV >= 700000) && (min_uV <= 1420000)) { |
Axel Lin | 268a164 | 2012-04-09 23:35:10 +0800 | [diff] [blame] | 761 | vsel = DIV_ROUND_UP(min_uV - 700000, 12500); |
Axel Lin | 0cb2f12 | 2012-04-10 23:07:52 +0800 | [diff] [blame] | 762 | vsel++; |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 763 | } |
| 764 | /* Values 1..57 for vsel are linear and can be calculated |
| 765 | * values 58..62 are non linear. |
| 766 | */ |
Axel Lin | 78292f4 | 2012-07-14 13:37:13 +0800 | [diff] [blame] | 767 | else if ((min_uV > 1900000) && (min_uV <= 2100000)) |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 768 | vsel = 62; |
Axel Lin | 78292f4 | 2012-07-14 13:37:13 +0800 | [diff] [blame] | 769 | else if ((min_uV > 1800000) && (min_uV <= 1900000)) |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 770 | vsel = 61; |
Axel Lin | 78292f4 | 2012-07-14 13:37:13 +0800 | [diff] [blame] | 771 | else if ((min_uV > 1350000) && (min_uV <= 1800000)) |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 772 | vsel = 60; |
Axel Lin | 78292f4 | 2012-07-14 13:37:13 +0800 | [diff] [blame] | 773 | else if ((min_uV > 1350000) && (min_uV <= 1500000)) |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 774 | vsel = 59; |
Axel Lin | 78292f4 | 2012-07-14 13:37:13 +0800 | [diff] [blame] | 775 | else if ((min_uV > 1300000) && (min_uV <= 1350000)) |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 776 | vsel = 58; |
| 777 | else |
| 778 | return -EINVAL; |
| 779 | break; |
| 780 | case SMPS_EXTENDED_EN: |
Axel Lin | 0cb2f12 | 2012-04-10 23:07:52 +0800 | [diff] [blame] | 781 | if (min_uV == 0) { |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 782 | vsel = 0; |
Axel Lin | 0cb2f12 | 2012-04-10 23:07:52 +0800 | [diff] [blame] | 783 | } else if ((min_uV >= 1852000) && (max_uV <= 4013600)) { |
Axel Lin | 268a164 | 2012-04-09 23:35:10 +0800 | [diff] [blame] | 784 | vsel = DIV_ROUND_UP(min_uV - 1852000, 38600); |
Axel Lin | 0cb2f12 | 2012-04-10 23:07:52 +0800 | [diff] [blame] | 785 | vsel++; |
| 786 | } |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 787 | break; |
| 788 | case SMPS_OFFSET_EN|SMPS_EXTENDED_EN: |
Axel Lin | 0cb2f12 | 2012-04-10 23:07:52 +0800 | [diff] [blame] | 789 | if (min_uV == 0) { |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 790 | vsel = 0; |
Axel Lin | 78292f4 | 2012-07-14 13:37:13 +0800 | [diff] [blame] | 791 | } else if ((min_uV >= 2161000) && (min_uV <= 4321000)) { |
Axel Lin | 268a164 | 2012-04-09 23:35:10 +0800 | [diff] [blame] | 792 | vsel = DIV_ROUND_UP(min_uV - 2161000, 38600); |
Axel Lin | 0cb2f12 | 2012-04-10 23:07:52 +0800 | [diff] [blame] | 793 | vsel++; |
| 794 | } |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 795 | break; |
| 796 | } |
| 797 | |
Axel Lin | 38f8f43 | 2012-07-14 13:41:23 +0800 | [diff] [blame] | 798 | return vsel; |
| 799 | } |
Axel Lin | 78292f4 | 2012-07-14 13:37:13 +0800 | [diff] [blame] | 800 | |
Axel Lin | 38f8f43 | 2012-07-14 13:41:23 +0800 | [diff] [blame] | 801 | static int twl6030smps_set_voltage_sel(struct regulator_dev *rdev, |
| 802 | unsigned int selector) |
| 803 | { |
| 804 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 805 | |
| 806 | return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS, |
Axel Lin | 38f8f43 | 2012-07-14 13:41:23 +0800 | [diff] [blame] | 807 | selector); |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev) |
| 811 | { |
| 812 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
| 813 | |
| 814 | return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS); |
| 815 | } |
| 816 | |
| 817 | static struct regulator_ops twlsmps_ops = { |
| 818 | .list_voltage = twl6030smps_list_voltage, |
Axel Lin | 38f8f43 | 2012-07-14 13:41:23 +0800 | [diff] [blame] | 819 | .map_voltage = twl6030smps_map_voltage, |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 820 | |
Axel Lin | 38f8f43 | 2012-07-14 13:41:23 +0800 | [diff] [blame] | 821 | .set_voltage_sel = twl6030smps_set_voltage_sel, |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 822 | .get_voltage_sel = twl6030smps_get_voltage_sel, |
| 823 | |
| 824 | .enable = twl6030reg_enable, |
| 825 | .disable = twl6030reg_disable, |
| 826 | .is_enabled = twl6030reg_is_enabled, |
| 827 | |
| 828 | .set_mode = twl6030reg_set_mode, |
| 829 | |
| 830 | .get_status = twl6030reg_get_status, |
| 831 | }; |
| 832 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 833 | /*----------------------------------------------------------------------*/ |
| 834 | |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame] | 835 | #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ |
| 836 | remap_conf) \ |
| 837 | TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 838 | remap_conf, TWL4030, twl4030fixed_ops) |
Ambresh K | af8b244 | 2011-07-09 19:02:21 -0700 | [diff] [blame] | 839 | #define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \ |
| 840 | TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \ |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 841 | 0x0, TWL6030, twl6030fixed_ops) |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 842 | |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 843 | #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \ |
Arnd Bergmann | 0ffff5a | 2012-08-14 12:41:50 +0000 | [diff] [blame] | 844 | static const struct twlreg_info TWL4030_INFO_##label = { \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 845 | .base = offset, \ |
| 846 | .id = num, \ |
| 847 | .table_len = ARRAY_SIZE(label##_VSEL_table), \ |
| 848 | .table = label##_VSEL_table, \ |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame] | 849 | .remap = remap_conf, \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 850 | .desc = { \ |
| 851 | .name = #label, \ |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 852 | .id = TWL4030_REG_##label, \ |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 853 | .n_voltages = ARRAY_SIZE(label##_VSEL_table), \ |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 854 | .ops = &twl4030ldo_ops, \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 855 | .type = REGULATOR_VOLTAGE, \ |
| 856 | .owner = THIS_MODULE, \ |
Axel Lin | fca53d8 | 2012-07-04 10:46:34 +0800 | [diff] [blame] | 857 | .enable_time = turnon_delay, \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 858 | }, \ |
| 859 | } |
| 860 | |
Tero Kristo | ba305e3 | 2011-11-28 16:53:19 +0200 | [diff] [blame] | 861 | #define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \ |
Arnd Bergmann | 0ffff5a | 2012-08-14 12:41:50 +0000 | [diff] [blame] | 862 | static const struct twlreg_info TWL4030_INFO_##label = { \ |
Tero Kristo | ba305e3 | 2011-11-28 16:53:19 +0200 | [diff] [blame] | 863 | .base = offset, \ |
| 864 | .id = num, \ |
Tero Kristo | ba305e3 | 2011-11-28 16:53:19 +0200 | [diff] [blame] | 865 | .remap = remap_conf, \ |
| 866 | .desc = { \ |
| 867 | .name = #label, \ |
| 868 | .id = TWL4030_REG_##label, \ |
| 869 | .ops = &twl4030smps_ops, \ |
| 870 | .type = REGULATOR_VOLTAGE, \ |
| 871 | .owner = THIS_MODULE, \ |
Axel Lin | fca53d8 | 2012-07-04 10:46:34 +0800 | [diff] [blame] | 872 | .enable_time = turnon_delay, \ |
Tero Kristo | ba305e3 | 2011-11-28 16:53:19 +0200 | [diff] [blame] | 873 | }, \ |
| 874 | } |
| 875 | |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 876 | #define TWL6030_ADJUSTABLE_SMPS(label) \ |
Arnd Bergmann | 0ffff5a | 2012-08-14 12:41:50 +0000 | [diff] [blame] | 877 | static const struct twlreg_info TWL6030_INFO_##label = { \ |
Tero Kristo | 34a3844 | 2012-02-28 15:09:10 +0530 | [diff] [blame] | 878 | .desc = { \ |
| 879 | .name = #label, \ |
| 880 | .id = TWL6030_REG_##label, \ |
| 881 | .ops = &twl6030coresmps_ops, \ |
| 882 | .type = REGULATOR_VOLTAGE, \ |
| 883 | .owner = THIS_MODULE, \ |
| 884 | }, \ |
| 885 | } |
| 886 | |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 887 | #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ |
Arnd Bergmann | 0ffff5a | 2012-08-14 12:41:50 +0000 | [diff] [blame] | 888 | static const struct twlreg_info TWL6030_INFO_##label = { \ |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 889 | .base = offset, \ |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 890 | .min_mV = min_mVolts, \ |
| 891 | .max_mV = max_mVolts, \ |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 892 | .desc = { \ |
| 893 | .name = #label, \ |
| 894 | .id = TWL6030_REG_##label, \ |
Axel Lin | c6a717c | 2012-07-16 18:31:10 +0800 | [diff] [blame] | 895 | .n_voltages = 32, \ |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 896 | .ops = &twl6030ldo_ops, \ |
| 897 | .type = REGULATOR_VOLTAGE, \ |
| 898 | .owner = THIS_MODULE, \ |
| 899 | }, \ |
| 900 | } |
| 901 | |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 902 | #define TWL6032_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \ |
| 903 | static const struct twlreg_info TWL6032_INFO_##label = { \ |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 904 | .base = offset, \ |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 905 | .min_mV = min_mVolts, \ |
| 906 | .max_mV = max_mVolts, \ |
| 907 | .desc = { \ |
| 908 | .name = #label, \ |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 909 | .id = TWL6032_REG_##label, \ |
Axel Lin | c6a717c | 2012-07-16 18:31:10 +0800 | [diff] [blame] | 910 | .n_voltages = 32, \ |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 911 | .ops = &twl6030ldo_ops, \ |
| 912 | .type = REGULATOR_VOLTAGE, \ |
| 913 | .owner = THIS_MODULE, \ |
| 914 | }, \ |
| 915 | } |
Rajendra Nayak | 3e3d3be | 2010-04-22 14:18:32 +0530 | [diff] [blame] | 916 | |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame] | 917 | #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \ |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 918 | family, operations) \ |
Arnd Bergmann | 0ffff5a | 2012-08-14 12:41:50 +0000 | [diff] [blame] | 919 | static const struct twlreg_info TWLFIXED_INFO_##label = { \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 920 | .base = offset, \ |
| 921 | .id = num, \ |
| 922 | .min_mV = mVolts, \ |
Juha Keski-Saari | 045f972 | 2009-12-16 14:49:52 +0200 | [diff] [blame] | 923 | .remap = remap_conf, \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 924 | .desc = { \ |
| 925 | .name = #label, \ |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 926 | .id = family##_REG_##label, \ |
David Brownell | 66b659e | 2009-02-26 11:50:14 -0800 | [diff] [blame] | 927 | .n_voltages = 1, \ |
Saquib Herman | b245677 | 2011-04-01 10:22:44 +0530 | [diff] [blame] | 928 | .ops = &operations, \ |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 929 | .type = REGULATOR_VOLTAGE, \ |
| 930 | .owner = THIS_MODULE, \ |
Axel Lin | b3816d5 | 2012-12-22 13:31:19 +0800 | [diff] [blame] | 931 | .min_uV = mVolts * 1000, \ |
Axel Lin | fca53d8 | 2012-07-04 10:46:34 +0800 | [diff] [blame] | 932 | .enable_time = turnon_delay, \ |
Balaji T K | 8e6de4a | 2011-02-10 18:44:50 +0530 | [diff] [blame] | 933 | }, \ |
| 934 | } |
| 935 | |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 936 | #define TWL6032_ADJUSTABLE_SMPS(label, offset) \ |
Arnd Bergmann | 0ffff5a | 2012-08-14 12:41:50 +0000 | [diff] [blame] | 937 | static const struct twlreg_info TWLSMPS_INFO_##label = { \ |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 938 | .base = offset, \ |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 939 | .min_mV = 600, \ |
| 940 | .max_mV = 2100, \ |
| 941 | .desc = { \ |
| 942 | .name = #label, \ |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 943 | .id = TWL6032_REG_##label, \ |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 944 | .n_voltages = 63, \ |
| 945 | .ops = &twlsmps_ops, \ |
| 946 | .type = REGULATOR_VOLTAGE, \ |
| 947 | .owner = THIS_MODULE, \ |
| 948 | }, \ |
| 949 | } |
| 950 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 951 | /* |
| 952 | * We list regulators here if systems need some level of |
| 953 | * software control over them after boot. |
| 954 | */ |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 955 | TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08); |
| 956 | TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08); |
| 957 | TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08); |
| 958 | TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08); |
| 959 | TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08); |
| 960 | TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08); |
| 961 | TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08); |
| 962 | TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00); |
| 963 | TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08); |
| 964 | TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00); |
| 965 | TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08); |
| 966 | TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08); |
| 967 | TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08); |
| 968 | TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08); |
| 969 | TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08); |
| 970 | /* VUSBCP is managed *only* by the USB subchip */ |
| 971 | /* 6030 REG with base as PMC Slave Misc : 0x0030 */ |
| 972 | /* Turnon-delay and remap configuration values for 6030 are not |
| 973 | verified since the specification is not public */ |
| 974 | TWL6030_ADJUSTABLE_SMPS(VDD1); |
| 975 | TWL6030_ADJUSTABLE_SMPS(VDD2); |
| 976 | TWL6030_ADJUSTABLE_SMPS(VDD3); |
| 977 | TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300); |
| 978 | TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300); |
| 979 | TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300); |
| 980 | TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300); |
| 981 | TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300); |
| 982 | TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300); |
| 983 | /* 6025 are renamed compared to 6030 versions */ |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 984 | TWL6032_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300); |
| 985 | TWL6032_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300); |
| 986 | TWL6032_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300); |
| 987 | TWL6032_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300); |
| 988 | TWL6032_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300); |
| 989 | TWL6032_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300); |
| 990 | TWL6032_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300); |
| 991 | TWL6032_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300); |
| 992 | TWL6032_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300); |
Aaro Koskinen | 908d6d5 | 2012-08-15 01:10:04 +0300 | [diff] [blame] | 993 | TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08); |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 994 | TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08); |
| 995 | TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08); |
| 996 | TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08); |
| 997 | TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08); |
| 998 | TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0); |
| 999 | TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0); |
| 1000 | TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0); |
| 1001 | TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0); |
Peter Ujfalusi | e9d47fa | 2012-02-28 15:09:12 +0530 | [diff] [blame] | 1002 | TWL6030_FIXED_LDO(V1V8, 0x16, 1800, 0); |
| 1003 | TWL6030_FIXED_LDO(V2V1, 0x1c, 2100, 0); |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 1004 | TWL6032_ADJUSTABLE_SMPS(SMPS3, 0x34); |
| 1005 | TWL6032_ADJUSTABLE_SMPS(SMPS4, 0x10); |
| 1006 | TWL6032_ADJUSTABLE_SMPS(VIO, 0x16); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1007 | |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 1008 | static u8 twl_get_smps_offset(void) |
| 1009 | { |
| 1010 | u8 value; |
| 1011 | |
| 1012 | twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value, |
| 1013 | TWL6030_SMPS_OFFSET); |
| 1014 | return value; |
| 1015 | } |
| 1016 | |
| 1017 | static u8 twl_get_smps_mult(void) |
| 1018 | { |
| 1019 | u8 value; |
| 1020 | |
| 1021 | twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value, |
| 1022 | TWL6030_SMPS_MULT); |
| 1023 | return value; |
| 1024 | } |
| 1025 | |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1026 | #define TWL_OF_MATCH(comp, family, label) \ |
| 1027 | { \ |
| 1028 | .compatible = comp, \ |
| 1029 | .data = &family##_INFO_##label, \ |
| 1030 | } |
| 1031 | |
| 1032 | #define TWL4030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL4030, label) |
| 1033 | #define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label) |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 1034 | #define TWL6032_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6032, label) |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1035 | #define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label) |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1036 | #define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label) |
| 1037 | |
Greg Kroah-Hartman | 3d68dfe | 2012-12-21 13:26:06 -0800 | [diff] [blame] | 1038 | static const struct of_device_id twl_of_match[] = { |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1039 | TWL4030_OF_MATCH("ti,twl4030-vaux1", VAUX1), |
| 1040 | TWL4030_OF_MATCH("ti,twl4030-vaux2", VAUX2_4030), |
| 1041 | TWL4030_OF_MATCH("ti,twl5030-vaux2", VAUX2), |
| 1042 | TWL4030_OF_MATCH("ti,twl4030-vaux3", VAUX3), |
| 1043 | TWL4030_OF_MATCH("ti,twl4030-vaux4", VAUX4), |
| 1044 | TWL4030_OF_MATCH("ti,twl4030-vmmc1", VMMC1), |
| 1045 | TWL4030_OF_MATCH("ti,twl4030-vmmc2", VMMC2), |
| 1046 | TWL4030_OF_MATCH("ti,twl4030-vpll1", VPLL1), |
| 1047 | TWL4030_OF_MATCH("ti,twl4030-vpll2", VPLL2), |
| 1048 | TWL4030_OF_MATCH("ti,twl4030-vsim", VSIM), |
| 1049 | TWL4030_OF_MATCH("ti,twl4030-vdac", VDAC), |
| 1050 | TWL4030_OF_MATCH("ti,twl4030-vintana2", VINTANA2), |
| 1051 | TWL4030_OF_MATCH("ti,twl4030-vio", VIO), |
| 1052 | TWL4030_OF_MATCH("ti,twl4030-vdd1", VDD1), |
| 1053 | TWL4030_OF_MATCH("ti,twl4030-vdd2", VDD2), |
| 1054 | TWL6030_OF_MATCH("ti,twl6030-vdd1", VDD1), |
| 1055 | TWL6030_OF_MATCH("ti,twl6030-vdd2", VDD2), |
| 1056 | TWL6030_OF_MATCH("ti,twl6030-vdd3", VDD3), |
| 1057 | TWL6030_OF_MATCH("ti,twl6030-vaux1", VAUX1_6030), |
| 1058 | TWL6030_OF_MATCH("ti,twl6030-vaux2", VAUX2_6030), |
| 1059 | TWL6030_OF_MATCH("ti,twl6030-vaux3", VAUX3_6030), |
| 1060 | TWL6030_OF_MATCH("ti,twl6030-vmmc", VMMC), |
| 1061 | TWL6030_OF_MATCH("ti,twl6030-vpp", VPP), |
| 1062 | TWL6030_OF_MATCH("ti,twl6030-vusim", VUSIM), |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 1063 | TWL6032_OF_MATCH("ti,twl6032-ldo2", LDO2), |
| 1064 | TWL6032_OF_MATCH("ti,twl6032-ldo4", LDO4), |
| 1065 | TWL6032_OF_MATCH("ti,twl6032-ldo3", LDO3), |
| 1066 | TWL6032_OF_MATCH("ti,twl6032-ldo5", LDO5), |
| 1067 | TWL6032_OF_MATCH("ti,twl6032-ldo1", LDO1), |
| 1068 | TWL6032_OF_MATCH("ti,twl6032-ldo7", LDO7), |
| 1069 | TWL6032_OF_MATCH("ti,twl6032-ldo6", LDO6), |
| 1070 | TWL6032_OF_MATCH("ti,twl6032-ldoln", LDOLN), |
| 1071 | TWL6032_OF_MATCH("ti,twl6032-ldousb", LDOUSB), |
Aaro Koskinen | 908d6d5 | 2012-08-15 01:10:04 +0300 | [diff] [blame] | 1072 | TWLFIXED_OF_MATCH("ti,twl4030-vintana1", VINTANA1), |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1073 | TWLFIXED_OF_MATCH("ti,twl4030-vintdig", VINTDIG), |
| 1074 | TWLFIXED_OF_MATCH("ti,twl4030-vusb1v5", VUSB1V5), |
| 1075 | TWLFIXED_OF_MATCH("ti,twl4030-vusb1v8", VUSB1V8), |
| 1076 | TWLFIXED_OF_MATCH("ti,twl4030-vusb3v1", VUSB3V1), |
| 1077 | TWLFIXED_OF_MATCH("ti,twl6030-vana", VANA), |
| 1078 | TWLFIXED_OF_MATCH("ti,twl6030-vcxio", VCXIO), |
| 1079 | TWLFIXED_OF_MATCH("ti,twl6030-vdac", VDAC), |
| 1080 | TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB), |
Peter Ujfalusi | e9d47fa | 2012-02-28 15:09:12 +0530 | [diff] [blame] | 1081 | TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8), |
| 1082 | TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1), |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 1083 | TWLSMPS_OF_MATCH("ti,twl6032-smps3", SMPS3), |
| 1084 | TWLSMPS_OF_MATCH("ti,twl6032-smps4", SMPS4), |
| 1085 | TWLSMPS_OF_MATCH("ti,twl6032-vio", VIO), |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1086 | {}, |
| 1087 | }; |
| 1088 | MODULE_DEVICE_TABLE(of, twl_of_match); |
| 1089 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 1090 | static int twlreg_probe(struct platform_device *pdev) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1091 | { |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1092 | int i, id; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1093 | struct twlreg_info *info; |
Arnd Bergmann | 0ffff5a | 2012-08-14 12:41:50 +0000 | [diff] [blame] | 1094 | const struct twlreg_info *template; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1095 | struct regulator_init_data *initdata; |
| 1096 | struct regulation_constraints *c; |
| 1097 | struct regulator_dev *rdev; |
Tero Kristo | 63bfff4 | 2012-02-16 12:27:52 +0200 | [diff] [blame] | 1098 | struct twl_regulator_driver_data *drvdata; |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1099 | const struct of_device_id *match; |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 1100 | struct regulator_config config = { }; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1101 | |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1102 | match = of_match_device(twl_of_match, &pdev->dev); |
| 1103 | if (match) { |
Arnd Bergmann | 0ffff5a | 2012-08-14 12:41:50 +0000 | [diff] [blame] | 1104 | template = match->data; |
| 1105 | id = template->desc.id; |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1106 | initdata = of_get_regulator_init_data(&pdev->dev, |
| 1107 | pdev->dev.of_node); |
| 1108 | drvdata = NULL; |
| 1109 | } else { |
| 1110 | id = pdev->id; |
Jingoo Han | dff91d0 | 2013-07-30 17:20:47 +0900 | [diff] [blame] | 1111 | initdata = dev_get_platdata(&pdev->dev); |
Arnd Bergmann | 0ffff5a | 2012-08-14 12:41:50 +0000 | [diff] [blame] | 1112 | for (i = 0, template = NULL; i < ARRAY_SIZE(twl_of_match); i++) { |
| 1113 | template = twl_of_match[i].data; |
| 1114 | if (template && template->desc.id == id) |
Axel Lin | 5ade393 | 2012-04-09 22:32:49 +0800 | [diff] [blame] | 1115 | break; |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1116 | } |
Axel Lin | 5ade393 | 2012-04-09 22:32:49 +0800 | [diff] [blame] | 1117 | if (i == ARRAY_SIZE(twl_of_match)) |
| 1118 | return -ENODEV; |
| 1119 | |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1120 | drvdata = initdata->driver_data; |
| 1121 | if (!drvdata) |
| 1122 | return -EINVAL; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1123 | } |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1124 | |
Arnd Bergmann | 0ffff5a | 2012-08-14 12:41:50 +0000 | [diff] [blame] | 1125 | if (!template) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1126 | return -ENODEV; |
| 1127 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1128 | if (!initdata) |
| 1129 | return -EINVAL; |
| 1130 | |
Axel Lin | cd01e32 | 2014-06-16 09:44:20 +0800 | [diff] [blame] | 1131 | info = devm_kmemdup(&pdev->dev, template, sizeof(*info), GFP_KERNEL); |
Arnd Bergmann | 0ffff5a | 2012-08-14 12:41:50 +0000 | [diff] [blame] | 1132 | if (!info) |
| 1133 | return -ENOMEM; |
| 1134 | |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1135 | if (drvdata) { |
| 1136 | /* copy the driver data into regulator data */ |
| 1137 | info->features = drvdata->features; |
| 1138 | info->data = drvdata->data; |
| 1139 | info->set_voltage = drvdata->set_voltage; |
| 1140 | info->get_voltage = drvdata->get_voltage; |
| 1141 | } |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 1142 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1143 | /* Constrain board-specific capabilities according to what |
| 1144 | * this driver and the chip itself can actually do. |
| 1145 | */ |
| 1146 | c = &initdata->constraints; |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1147 | c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY; |
| 1148 | c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE |
| 1149 | | REGULATOR_CHANGE_MODE |
| 1150 | | REGULATOR_CHANGE_STATUS; |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1151 | switch (id) { |
Juha Keski-Saari | 205e5cd | 2009-12-16 15:27:56 +0200 | [diff] [blame] | 1152 | case TWL4030_REG_VIO: |
| 1153 | case TWL4030_REG_VDD1: |
| 1154 | case TWL4030_REG_VDD2: |
| 1155 | case TWL4030_REG_VPLL1: |
| 1156 | case TWL4030_REG_VINTANA1: |
| 1157 | case TWL4030_REG_VINTANA2: |
| 1158 | case TWL4030_REG_VINTDIG: |
| 1159 | c->always_on = true; |
| 1160 | break; |
| 1161 | default: |
| 1162 | break; |
| 1163 | } |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1164 | |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1165 | switch (id) { |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 1166 | case TWL6032_REG_SMPS3: |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 1167 | if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3) |
| 1168 | info->flags |= SMPS_EXTENDED_EN; |
| 1169 | if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3) |
| 1170 | info->flags |= SMPS_OFFSET_EN; |
| 1171 | break; |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 1172 | case TWL6032_REG_SMPS4: |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 1173 | if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4) |
| 1174 | info->flags |= SMPS_EXTENDED_EN; |
| 1175 | if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4) |
| 1176 | info->flags |= SMPS_OFFSET_EN; |
| 1177 | break; |
Graeme Gregory | 89ce43f | 2013-06-19 15:24:02 +0300 | [diff] [blame] | 1178 | case TWL6032_REG_VIO: |
Graeme Gregory | 4d94aee | 2011-05-22 21:21:23 +0100 | [diff] [blame] | 1179 | if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO) |
| 1180 | info->flags |= SMPS_EXTENDED_EN; |
| 1181 | if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO) |
| 1182 | info->flags |= SMPS_OFFSET_EN; |
| 1183 | break; |
| 1184 | } |
| 1185 | |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 1186 | config.dev = &pdev->dev; |
| 1187 | config.init_data = initdata; |
| 1188 | config.driver_data = info; |
| 1189 | config.of_node = pdev->dev.of_node; |
| 1190 | |
Jingoo Han | 00ce070 | 2013-09-30 09:59:04 +0900 | [diff] [blame] | 1191 | rdev = devm_regulator_register(&pdev->dev, &info->desc, &config); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1192 | if (IS_ERR(rdev)) { |
| 1193 | dev_err(&pdev->dev, "can't register %s, %ld\n", |
| 1194 | info->desc.name, PTR_ERR(rdev)); |
| 1195 | return PTR_ERR(rdev); |
| 1196 | } |
| 1197 | platform_set_drvdata(pdev, rdev); |
| 1198 | |
Saquib Herman | 776dc92 | 2011-04-01 10:22:43 +0530 | [diff] [blame] | 1199 | if (twl_class_is_4030()) |
| 1200 | twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP, |
Juha Keski-Saari | 30010fa | 2009-12-16 15:27:58 +0200 | [diff] [blame] | 1201 | info->remap); |
| 1202 | |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1203 | /* NOTE: many regulators support short-circuit IRQs (presentable |
| 1204 | * as REGULATOR_OVER_CURRENT notifications?) configured via: |
| 1205 | * - SC_CONFIG |
| 1206 | * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4) |
| 1207 | * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2) |
| 1208 | * - IT_CONFIG |
| 1209 | */ |
| 1210 | |
| 1211 | return 0; |
| 1212 | } |
| 1213 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1214 | MODULE_ALIAS("platform:twl_reg"); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1215 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1216 | static struct platform_driver twlreg_driver = { |
| 1217 | .probe = twlreg_probe, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1218 | /* NOTE: short name, to work around driver model truncation of |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1219 | * "twl_regulator.12" (and friends) to "twl_regulator.1". |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1220 | */ |
Rajendra Nayak | 2098e95 | 2012-02-28 15:09:11 +0530 | [diff] [blame] | 1221 | .driver = { |
| 1222 | .name = "twl_reg", |
| 1223 | .owner = THIS_MODULE, |
| 1224 | .of_match_table = of_match_ptr(twl_of_match), |
| 1225 | }, |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1226 | }; |
| 1227 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1228 | static int __init twlreg_init(void) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1229 | { |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1230 | return platform_driver_register(&twlreg_driver); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1231 | } |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1232 | subsys_initcall(twlreg_init); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1233 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1234 | static void __exit twlreg_exit(void) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1235 | { |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1236 | platform_driver_unregister(&twlreg_driver); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1237 | } |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1238 | module_exit(twlreg_exit) |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1239 | |
Rajendra Nayak | c4aa6f3 | 2009-12-13 21:36:49 +0100 | [diff] [blame] | 1240 | MODULE_DESCRIPTION("TWL regulator driver"); |
David Brownell | fa16a5c | 2009-02-08 10:37:06 -0800 | [diff] [blame] | 1241 | MODULE_LICENSE("GPL"); |