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