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