Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/i2c/chips/twl4030-power.c |
| 3 | * |
| 4 | * Handle TWL4030 Power initialization |
| 5 | * |
| 6 | * Copyright (C) 2008 Nokia Corporation |
| 7 | * Copyright (C) 2006 Texas Instruments, Inc |
| 8 | * |
| 9 | * Written by Kalle Jokiniemi |
| 10 | * Peter De Schrijver <peter.de-schrijver@nokia.com> |
| 11 | * Several fixes by Amit Kucheria <amit.kucheria@verdurent.com> |
| 12 | * |
| 13 | * This file is subject to the terms and conditions of the GNU General |
| 14 | * Public License. See the file "COPYING" in the main directory of this |
| 15 | * archive for more details. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/pm.h> |
Santosh Shilimkar | b07682b | 2009-12-13 20:05:51 +0100 | [diff] [blame] | 29 | #include <linux/i2c/twl.h> |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 30 | #include <linux/platform_device.h> |
Florian Vaussard | b0fc1da | 2013-06-18 15:17:58 +0200 | [diff] [blame] | 31 | #include <linux/of.h> |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 32 | #include <linux/of_device.h> |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 33 | |
| 34 | #include <asm/mach-types.h> |
| 35 | |
| 36 | static u8 twl4030_start_script_address = 0x2b; |
| 37 | |
Tony Lindgren | 3205728 | 2014-05-20 11:17:53 -0700 | [diff] [blame] | 38 | /* Register bits for P1, P2 and P3_SW_EVENTS */ |
| 39 | #define PWR_STOPON_PRWON BIT(6) |
| 40 | #define PWR_STOPON_SYSEN BIT(5) |
| 41 | #define PWR_ENABLE_WARMRESET BIT(4) |
| 42 | #define PWR_LVL_WAKEUP BIT(3) |
| 43 | #define PWR_DEVACT BIT(2) |
| 44 | #define PWR_DEVSLP BIT(1) |
| 45 | #define PWR_DEVOFF BIT(0) |
| 46 | |
Tony Lindgren | 481c7f8 | 2014-11-02 10:07:56 -0800 | [diff] [blame] | 47 | /* Register bits for CFG_P1_TRANSITION (also for P2 and P3) */ |
| 48 | #define STARTON_SWBUG BIT(7) /* Start on watchdog */ |
| 49 | #define STARTON_VBUS BIT(5) /* Start on VBUS */ |
| 50 | #define STARTON_VBAT BIT(4) /* Start on battery insert */ |
| 51 | #define STARTON_RTC BIT(3) /* Start on RTC */ |
| 52 | #define STARTON_USB BIT(2) /* Start on USB host */ |
| 53 | #define STARTON_CHG BIT(1) /* Start on charger */ |
| 54 | #define STARTON_PWON BIT(0) /* Start on PWRON button */ |
| 55 | |
Igor Grinberg | 26cc3ab | 2011-11-13 11:49:50 +0200 | [diff] [blame] | 56 | #define SEQ_OFFSYNC (1 << 0) |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 57 | |
| 58 | #define PHY_TO_OFF_PM_MASTER(p) (p - 0x36) |
| 59 | #define PHY_TO_OFF_PM_RECEIVER(p) (p - 0x5b) |
| 60 | |
| 61 | /* resource - hfclk */ |
| 62 | #define R_HFCLKOUT_DEV_GRP PHY_TO_OFF_PM_RECEIVER(0xe6) |
| 63 | |
| 64 | /* PM events */ |
| 65 | #define R_P1_SW_EVENTS PHY_TO_OFF_PM_MASTER(0x46) |
| 66 | #define R_P2_SW_EVENTS PHY_TO_OFF_PM_MASTER(0x47) |
| 67 | #define R_P3_SW_EVENTS PHY_TO_OFF_PM_MASTER(0x48) |
| 68 | #define R_CFG_P1_TRANSITION PHY_TO_OFF_PM_MASTER(0x36) |
| 69 | #define R_CFG_P2_TRANSITION PHY_TO_OFF_PM_MASTER(0x37) |
| 70 | #define R_CFG_P3_TRANSITION PHY_TO_OFF_PM_MASTER(0x38) |
| 71 | |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 72 | #define END_OF_SCRIPT 0x3f |
| 73 | |
| 74 | #define R_SEQ_ADD_A2S PHY_TO_OFF_PM_MASTER(0x55) |
| 75 | #define R_SEQ_ADD_S2A12 PHY_TO_OFF_PM_MASTER(0x56) |
| 76 | #define R_SEQ_ADD_S2A3 PHY_TO_OFF_PM_MASTER(0x57) |
| 77 | #define R_SEQ_ADD_WARM PHY_TO_OFF_PM_MASTER(0x58) |
| 78 | #define R_MEMORY_ADDRESS PHY_TO_OFF_PM_MASTER(0x59) |
| 79 | #define R_MEMORY_DATA PHY_TO_OFF_PM_MASTER(0x5a) |
| 80 | |
Amit Kucheria | 890463f | 2009-10-19 15:10:48 +0300 | [diff] [blame] | 81 | /* resource configuration registers |
| 82 | <RESOURCE>_DEV_GRP at address 'n+0' |
| 83 | <RESOURCE>_TYPE at address 'n+1' |
| 84 | <RESOURCE>_REMAP at address 'n+2' |
| 85 | <RESOURCE>_DEDICATED at address 'n+3' |
| 86 | */ |
Amit Kucheria | e97d154 | 2009-10-19 15:10:44 +0300 | [diff] [blame] | 87 | #define DEV_GRP_OFFSET 0 |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 88 | #define TYPE_OFFSET 1 |
Amit Kucheria | b4ead61 | 2009-10-19 15:11:00 +0300 | [diff] [blame] | 89 | #define REMAP_OFFSET 2 |
| 90 | #define DEDICATED_OFFSET 3 |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 91 | |
Amit Kucheria | e97d154 | 2009-10-19 15:10:44 +0300 | [diff] [blame] | 92 | /* Bit positions in the registers */ |
Amit Kucheria | 890463f | 2009-10-19 15:10:48 +0300 | [diff] [blame] | 93 | |
| 94 | /* <RESOURCE>_DEV_GRP */ |
Amit Kucheria | e97d154 | 2009-10-19 15:10:44 +0300 | [diff] [blame] | 95 | #define DEV_GRP_SHIFT 5 |
| 96 | #define DEV_GRP_MASK (7 << DEV_GRP_SHIFT) |
Amit Kucheria | 890463f | 2009-10-19 15:10:48 +0300 | [diff] [blame] | 97 | |
| 98 | /* <RESOURCE>_TYPE */ |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 99 | #define TYPE_SHIFT 0 |
| 100 | #define TYPE_MASK (7 << TYPE_SHIFT) |
| 101 | #define TYPE2_SHIFT 3 |
| 102 | #define TYPE2_MASK (3 << TYPE2_SHIFT) |
| 103 | |
Amit Kucheria | b4ead61 | 2009-10-19 15:11:00 +0300 | [diff] [blame] | 104 | /* <RESOURCE>_REMAP */ |
| 105 | #define SLEEP_STATE_SHIFT 0 |
| 106 | #define SLEEP_STATE_MASK (0xf << SLEEP_STATE_SHIFT) |
| 107 | #define OFF_STATE_SHIFT 4 |
| 108 | #define OFF_STATE_MASK (0xf << OFF_STATE_SHIFT) |
| 109 | |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 110 | static u8 res_config_addrs[] = { |
| 111 | [RES_VAUX1] = 0x17, |
| 112 | [RES_VAUX2] = 0x1b, |
| 113 | [RES_VAUX3] = 0x1f, |
| 114 | [RES_VAUX4] = 0x23, |
| 115 | [RES_VMMC1] = 0x27, |
| 116 | [RES_VMMC2] = 0x2b, |
| 117 | [RES_VPLL1] = 0x2f, |
| 118 | [RES_VPLL2] = 0x33, |
| 119 | [RES_VSIM] = 0x37, |
| 120 | [RES_VDAC] = 0x3b, |
| 121 | [RES_VINTANA1] = 0x3f, |
| 122 | [RES_VINTANA2] = 0x43, |
| 123 | [RES_VINTDIG] = 0x47, |
| 124 | [RES_VIO] = 0x4b, |
| 125 | [RES_VDD1] = 0x55, |
| 126 | [RES_VDD2] = 0x63, |
| 127 | [RES_VUSB_1V5] = 0x71, |
| 128 | [RES_VUSB_1V8] = 0x74, |
| 129 | [RES_VUSB_3V1] = 0x77, |
| 130 | [RES_VUSBCP] = 0x7a, |
| 131 | [RES_REGEN] = 0x7f, |
| 132 | [RES_NRES_PWRON] = 0x82, |
| 133 | [RES_CLKEN] = 0x85, |
| 134 | [RES_SYSEN] = 0x88, |
| 135 | [RES_HFCLKOUT] = 0x8b, |
| 136 | [RES_32KCLKOUT] = 0x8e, |
| 137 | [RES_RESET] = 0x91, |
Lesly A M | d7ac829 | 2011-04-14 17:57:51 +0530 | [diff] [blame] | 138 | [RES_MAIN_REF] = 0x94, |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 139 | }; |
| 140 | |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 141 | /* |
| 142 | * Usable values for .remap_sleep and .remap_off |
| 143 | * Based on table "5.3.3 Resource Operating modes" |
| 144 | */ |
| 145 | enum { |
| 146 | TWL_REMAP_OFF = 0, |
| 147 | TWL_REMAP_SLEEP = 8, |
| 148 | TWL_REMAP_ACTIVE = 9, |
| 149 | }; |
| 150 | |
| 151 | /* |
| 152 | * Macros to configure the PM register states for various resources. |
| 153 | * Note that we can make MSG_SINGULAR etc private to this driver once |
| 154 | * omap3 has been made DT only. |
| 155 | */ |
| 156 | #define TWL_DFLT_DELAY 2 /* typically 2 32 KiHz cycles */ |
Tony Lindgren | 76714d2 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 157 | #define TWL_DEV_GRP_P123 (DEV_GRP_P1 | DEV_GRP_P2 | DEV_GRP_P3) |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 158 | #define TWL_RESOURCE_SET(res, state) \ |
| 159 | { MSG_SINGULAR(DEV_GRP_NULL, (res), (state)), TWL_DFLT_DELAY } |
| 160 | #define TWL_RESOURCE_ON(res) TWL_RESOURCE_SET(res, RES_STATE_ACTIVE) |
| 161 | #define TWL_RESOURCE_OFF(res) TWL_RESOURCE_SET(res, RES_STATE_OFF) |
| 162 | #define TWL_RESOURCE_RESET(res) TWL_RESOURCE_SET(res, RES_STATE_WRST) |
| 163 | /* |
| 164 | * It seems that type1 and type2 is just the resource init order |
| 165 | * number for the type1 and type2 group. |
| 166 | */ |
Tony Lindgren | 76714d2 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 167 | #define TWL_RESOURCE_SET_ACTIVE(res, state) \ |
| 168 | { MSG_SINGULAR(DEV_GRP_NULL, (res), RES_STATE_ACTIVE), (state) } |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 169 | #define TWL_RESOURCE_GROUP_RESET(group, type1, type2) \ |
| 170 | { MSG_BROADCAST(DEV_GRP_NULL, (group), (type1), (type2), \ |
| 171 | RES_STATE_WRST), TWL_DFLT_DELAY } |
Tony Lindgren | 76714d2 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 172 | #define TWL_RESOURCE_GROUP_SLEEP(group, type, type2) \ |
| 173 | { MSG_BROADCAST(DEV_GRP_NULL, (group), (type), (type2), \ |
| 174 | RES_STATE_SLEEP), TWL_DFLT_DELAY } |
| 175 | #define TWL_RESOURCE_GROUP_ACTIVE(group, type, type2) \ |
| 176 | { MSG_BROADCAST(DEV_GRP_NULL, (group), (type), (type2), \ |
| 177 | RES_STATE_ACTIVE), TWL_DFLT_DELAY } |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 178 | #define TWL_REMAP_SLEEP(res, devgrp, typ, typ2) \ |
| 179 | { .resource = (res), .devgroup = (devgrp), \ |
| 180 | .type = (typ), .type2 = (typ2), \ |
| 181 | .remap_off = TWL_REMAP_OFF, \ |
| 182 | .remap_sleep = TWL_REMAP_SLEEP, } |
Tony Lindgren | 76714d2 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 183 | #define TWL_REMAP_OFF(res, devgrp, typ, typ2) \ |
| 184 | { .resource = (res), .devgroup = (devgrp), \ |
| 185 | .type = (typ), .type2 = (typ2), \ |
| 186 | .remap_off = TWL_REMAP_OFF, .remap_sleep = TWL_REMAP_OFF, } |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 187 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 188 | static int twl4030_write_script_byte(u8 address, u8 byte) |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 189 | { |
| 190 | int err; |
| 191 | |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 192 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, address, R_MEMORY_ADDRESS); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 193 | if (err) |
| 194 | goto out; |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 195 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, byte, R_MEMORY_DATA); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 196 | out: |
| 197 | return err; |
| 198 | } |
| 199 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 200 | static int twl4030_write_script_ins(u8 address, u16 pmb_message, |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 201 | u8 delay, u8 next) |
| 202 | { |
| 203 | int err; |
| 204 | |
| 205 | address *= 4; |
| 206 | err = twl4030_write_script_byte(address++, pmb_message >> 8); |
| 207 | if (err) |
| 208 | goto out; |
| 209 | err = twl4030_write_script_byte(address++, pmb_message & 0xff); |
| 210 | if (err) |
| 211 | goto out; |
| 212 | err = twl4030_write_script_byte(address++, delay); |
| 213 | if (err) |
| 214 | goto out; |
| 215 | err = twl4030_write_script_byte(address++, next); |
| 216 | out: |
| 217 | return err; |
| 218 | } |
| 219 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 220 | static int twl4030_write_script(u8 address, struct twl4030_ins *script, |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 221 | int len) |
| 222 | { |
Arnd Bergmann | f65e9ea | 2013-01-25 14:14:26 +0000 | [diff] [blame] | 223 | int err = -EINVAL; |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 224 | |
| 225 | for (; len; len--, address++, script++) { |
| 226 | if (len == 1) { |
| 227 | err = twl4030_write_script_ins(address, |
| 228 | script->pmb_message, |
| 229 | script->delay, |
| 230 | END_OF_SCRIPT); |
| 231 | if (err) |
| 232 | break; |
| 233 | } else { |
| 234 | err = twl4030_write_script_ins(address, |
| 235 | script->pmb_message, |
| 236 | script->delay, |
| 237 | address + 1); |
| 238 | if (err) |
| 239 | break; |
| 240 | } |
| 241 | } |
| 242 | return err; |
| 243 | } |
| 244 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 245 | static int twl4030_config_wakeup3_sequence(u8 address) |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 246 | { |
| 247 | int err; |
| 248 | u8 data; |
| 249 | |
| 250 | /* Set SLEEP to ACTIVE SEQ address for P3 */ |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 251 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, address, R_SEQ_ADD_S2A3); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 252 | if (err) |
| 253 | goto out; |
| 254 | |
| 255 | /* P3 LVL_WAKEUP should be on LEVEL */ |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 256 | err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &data, R_P3_SW_EVENTS); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 257 | if (err) |
| 258 | goto out; |
Tony Lindgren | 3205728 | 2014-05-20 11:17:53 -0700 | [diff] [blame] | 259 | data |= PWR_LVL_WAKEUP; |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 260 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, data, R_P3_SW_EVENTS); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 261 | out: |
| 262 | if (err) |
| 263 | pr_err("TWL4030 wakeup sequence for P3 config error\n"); |
| 264 | return err; |
| 265 | } |
| 266 | |
Tony Lindgren | 5c188d7 | 2015-04-27 10:18:14 -0700 | [diff] [blame] | 267 | static int |
| 268 | twl4030_config_wakeup12_sequence(const struct twl4030_power_data *pdata, |
| 269 | u8 address) |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 270 | { |
| 271 | int err = 0; |
| 272 | u8 data; |
| 273 | |
| 274 | /* Set SLEEP to ACTIVE SEQ address for P1 and P2 */ |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 275 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, address, R_SEQ_ADD_S2A12); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 276 | if (err) |
| 277 | goto out; |
| 278 | |
| 279 | /* P1/P2 LVL_WAKEUP should be on LEVEL */ |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 280 | err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &data, R_P1_SW_EVENTS); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 281 | if (err) |
| 282 | goto out; |
| 283 | |
Tony Lindgren | 3205728 | 2014-05-20 11:17:53 -0700 | [diff] [blame] | 284 | data |= PWR_LVL_WAKEUP; |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 285 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, data, R_P1_SW_EVENTS); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 286 | if (err) |
| 287 | goto out; |
| 288 | |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 289 | err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &data, R_P2_SW_EVENTS); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 290 | if (err) |
| 291 | goto out; |
| 292 | |
Tony Lindgren | 3205728 | 2014-05-20 11:17:53 -0700 | [diff] [blame] | 293 | data |= PWR_LVL_WAKEUP; |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 294 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, data, R_P2_SW_EVENTS); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 295 | if (err) |
| 296 | goto out; |
| 297 | |
Tony Lindgren | 5c188d7 | 2015-04-27 10:18:14 -0700 | [diff] [blame] | 298 | if (pdata->ac_charger_quirk || machine_is_omap_3430sdp() || |
| 299 | machine_is_omap_ldp()) { |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 300 | /* Disabling AC charger effect on sleep-active transitions */ |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 301 | err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &data, |
| 302 | R_CFG_P1_TRANSITION); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 303 | if (err) |
| 304 | goto out; |
Tony Lindgren | 5c188d7 | 2015-04-27 10:18:14 -0700 | [diff] [blame] | 305 | data &= ~STARTON_CHG; |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 306 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, data, |
| 307 | R_CFG_P1_TRANSITION); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 308 | if (err) |
| 309 | goto out; |
| 310 | } |
| 311 | |
| 312 | out: |
| 313 | if (err) |
| 314 | pr_err("TWL4030 wakeup sequence for P1 and P2" \ |
| 315 | "config error\n"); |
| 316 | return err; |
| 317 | } |
| 318 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 319 | static int twl4030_config_sleep_sequence(u8 address) |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 320 | { |
| 321 | int err; |
| 322 | |
| 323 | /* Set ACTIVE to SLEEP SEQ address in T2 memory*/ |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 324 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, address, R_SEQ_ADD_A2S); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 325 | |
| 326 | if (err) |
| 327 | pr_err("TWL4030 sleep sequence config error\n"); |
| 328 | |
| 329 | return err; |
| 330 | } |
| 331 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 332 | static int twl4030_config_warmreset_sequence(u8 address) |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 333 | { |
| 334 | int err; |
| 335 | u8 rd_data; |
| 336 | |
| 337 | /* Set WARM RESET SEQ address for P1 */ |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 338 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, address, R_SEQ_ADD_WARM); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 339 | if (err) |
| 340 | goto out; |
| 341 | |
| 342 | /* P1/P2/P3 enable WARMRESET */ |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 343 | err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &rd_data, R_P1_SW_EVENTS); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 344 | if (err) |
| 345 | goto out; |
| 346 | |
Tony Lindgren | 3205728 | 2014-05-20 11:17:53 -0700 | [diff] [blame] | 347 | rd_data |= PWR_ENABLE_WARMRESET; |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 348 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, rd_data, R_P1_SW_EVENTS); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 349 | if (err) |
| 350 | goto out; |
| 351 | |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 352 | err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &rd_data, R_P2_SW_EVENTS); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 353 | if (err) |
| 354 | goto out; |
| 355 | |
Tony Lindgren | 3205728 | 2014-05-20 11:17:53 -0700 | [diff] [blame] | 356 | rd_data |= PWR_ENABLE_WARMRESET; |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 357 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, rd_data, R_P2_SW_EVENTS); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 358 | if (err) |
| 359 | goto out; |
| 360 | |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 361 | err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &rd_data, R_P3_SW_EVENTS); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 362 | if (err) |
| 363 | goto out; |
| 364 | |
Tony Lindgren | 3205728 | 2014-05-20 11:17:53 -0700 | [diff] [blame] | 365 | rd_data |= PWR_ENABLE_WARMRESET; |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 366 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, rd_data, R_P3_SW_EVENTS); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 367 | out: |
| 368 | if (err) |
| 369 | pr_err("TWL4030 warmreset seq config error\n"); |
| 370 | return err; |
| 371 | } |
| 372 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 373 | static int twl4030_configure_resource(struct twl4030_resconfig *rconfig) |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 374 | { |
| 375 | int rconfig_addr; |
| 376 | int err; |
| 377 | u8 type; |
| 378 | u8 grp; |
Amit Kucheria | b4ead61 | 2009-10-19 15:11:00 +0300 | [diff] [blame] | 379 | u8 remap; |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 380 | |
| 381 | if (rconfig->resource > TOTAL_RESOURCES) { |
| 382 | pr_err("TWL4030 Resource %d does not exist\n", |
| 383 | rconfig->resource); |
| 384 | return -EINVAL; |
| 385 | } |
| 386 | |
| 387 | rconfig_addr = res_config_addrs[rconfig->resource]; |
| 388 | |
| 389 | /* Set resource group */ |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 390 | err = twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &grp, |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 391 | rconfig_addr + DEV_GRP_OFFSET); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 392 | if (err) { |
| 393 | pr_err("TWL4030 Resource %d group could not be read\n", |
| 394 | rconfig->resource); |
| 395 | return err; |
| 396 | } |
| 397 | |
Aaro Koskinen | 56baa66 | 2009-10-19 21:24:02 +0200 | [diff] [blame] | 398 | if (rconfig->devgroup != TWL4030_RESCONFIG_UNDEF) { |
Amit Kucheria | e97d154 | 2009-10-19 15:10:44 +0300 | [diff] [blame] | 399 | grp &= ~DEV_GRP_MASK; |
| 400 | grp |= rconfig->devgroup << DEV_GRP_SHIFT; |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 401 | err = twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 402 | grp, rconfig_addr + DEV_GRP_OFFSET); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 403 | if (err < 0) { |
| 404 | pr_err("TWL4030 failed to program devgroup\n"); |
| 405 | return err; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /* Set resource types */ |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 410 | err = twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &type, |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 411 | rconfig_addr + TYPE_OFFSET); |
| 412 | if (err < 0) { |
| 413 | pr_err("TWL4030 Resource %d type could not be read\n", |
| 414 | rconfig->resource); |
| 415 | return err; |
| 416 | } |
| 417 | |
Aaro Koskinen | 56baa66 | 2009-10-19 21:24:02 +0200 | [diff] [blame] | 418 | if (rconfig->type != TWL4030_RESCONFIG_UNDEF) { |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 419 | type &= ~TYPE_MASK; |
| 420 | type |= rconfig->type << TYPE_SHIFT; |
| 421 | } |
| 422 | |
Aaro Koskinen | 56baa66 | 2009-10-19 21:24:02 +0200 | [diff] [blame] | 423 | if (rconfig->type2 != TWL4030_RESCONFIG_UNDEF) { |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 424 | type &= ~TYPE2_MASK; |
| 425 | type |= rconfig->type2 << TYPE2_SHIFT; |
| 426 | } |
| 427 | |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 428 | err = twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 429 | type, rconfig_addr + TYPE_OFFSET); |
| 430 | if (err < 0) { |
| 431 | pr_err("TWL4030 failed to program resource type\n"); |
| 432 | return err; |
| 433 | } |
| 434 | |
Amit Kucheria | b4ead61 | 2009-10-19 15:11:00 +0300 | [diff] [blame] | 435 | /* Set remap states */ |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 436 | err = twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &remap, |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 437 | rconfig_addr + REMAP_OFFSET); |
Amit Kucheria | b4ead61 | 2009-10-19 15:11:00 +0300 | [diff] [blame] | 438 | if (err < 0) { |
| 439 | pr_err("TWL4030 Resource %d remap could not be read\n", |
| 440 | rconfig->resource); |
| 441 | return err; |
| 442 | } |
| 443 | |
Amit Kucheria | 53cf9a6 | 2009-10-21 14:49:22 +0300 | [diff] [blame] | 444 | if (rconfig->remap_off != TWL4030_RESCONFIG_UNDEF) { |
Amit Kucheria | b4ead61 | 2009-10-19 15:11:00 +0300 | [diff] [blame] | 445 | remap &= ~OFF_STATE_MASK; |
| 446 | remap |= rconfig->remap_off << OFF_STATE_SHIFT; |
| 447 | } |
| 448 | |
Amit Kucheria | 53cf9a6 | 2009-10-21 14:49:22 +0300 | [diff] [blame] | 449 | if (rconfig->remap_sleep != TWL4030_RESCONFIG_UNDEF) { |
Amit Kucheria | b4ead61 | 2009-10-19 15:11:00 +0300 | [diff] [blame] | 450 | remap &= ~SLEEP_STATE_MASK; |
Mike Turquette | 1ea933f | 2010-02-05 09:51:37 +0100 | [diff] [blame] | 451 | remap |= rconfig->remap_sleep << SLEEP_STATE_SHIFT; |
Amit Kucheria | b4ead61 | 2009-10-19 15:11:00 +0300 | [diff] [blame] | 452 | } |
| 453 | |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 454 | err = twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 455 | remap, |
| 456 | rconfig_addr + REMAP_OFFSET); |
Amit Kucheria | b4ead61 | 2009-10-19 15:11:00 +0300 | [diff] [blame] | 457 | if (err < 0) { |
| 458 | pr_err("TWL4030 failed to program remap\n"); |
| 459 | return err; |
| 460 | } |
| 461 | |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 462 | return 0; |
| 463 | } |
| 464 | |
Tony Lindgren | 5c188d7 | 2015-04-27 10:18:14 -0700 | [diff] [blame] | 465 | static int load_twl4030_script(const struct twl4030_power_data *pdata, |
| 466 | struct twl4030_script *tscript, |
| 467 | u8 address) |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 468 | { |
| 469 | int err; |
Amit Kucheria | 75a7456 | 2009-08-17 17:01:56 +0300 | [diff] [blame] | 470 | static int order; |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 471 | |
| 472 | /* Make sure the script isn't going beyond last valid address (0x3f) */ |
| 473 | if ((address + tscript->size) > END_OF_SCRIPT) { |
| 474 | pr_err("TWL4030 scripts too big error\n"); |
| 475 | return -EINVAL; |
| 476 | } |
| 477 | |
| 478 | err = twl4030_write_script(address, tscript->script, tscript->size); |
| 479 | if (err) |
| 480 | goto out; |
| 481 | |
| 482 | if (tscript->flags & TWL4030_WRST_SCRIPT) { |
| 483 | err = twl4030_config_warmreset_sequence(address); |
| 484 | if (err) |
| 485 | goto out; |
| 486 | } |
| 487 | if (tscript->flags & TWL4030_WAKEUP12_SCRIPT) { |
Tony Lindgren | fc7d76e | 2014-05-13 18:34:04 -0700 | [diff] [blame] | 488 | /* Reset any existing sleep script to avoid hangs on reboot */ |
| 489 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, END_OF_SCRIPT, |
| 490 | R_SEQ_ADD_A2S); |
| 491 | if (err) |
| 492 | goto out; |
| 493 | |
Tony Lindgren | 5c188d7 | 2015-04-27 10:18:14 -0700 | [diff] [blame] | 494 | err = twl4030_config_wakeup12_sequence(pdata, address); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 495 | if (err) |
| 496 | goto out; |
Amit Kucheria | 75a7456 | 2009-08-17 17:01:56 +0300 | [diff] [blame] | 497 | order = 1; |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 498 | } |
| 499 | if (tscript->flags & TWL4030_WAKEUP3_SCRIPT) { |
| 500 | err = twl4030_config_wakeup3_sequence(address); |
| 501 | if (err) |
| 502 | goto out; |
| 503 | } |
Lesly A M | c62dd36 | 2011-04-14 17:57:49 +0530 | [diff] [blame] | 504 | if (tscript->flags & TWL4030_SLEEP_SCRIPT) { |
Lesly A M | 1f968ff | 2011-04-14 17:57:50 +0530 | [diff] [blame] | 505 | if (!order) |
Amit Kucheria | 75a7456 | 2009-08-17 17:01:56 +0300 | [diff] [blame] | 506 | pr_warning("TWL4030: Bad order of scripts (sleep "\ |
| 507 | "script before wakeup) Leads to boot"\ |
| 508 | "failure on some boards\n"); |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 509 | err = twl4030_config_sleep_sequence(address); |
Lesly A M | c62dd36 | 2011-04-14 17:57:49 +0530 | [diff] [blame] | 510 | } |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 511 | out: |
| 512 | return err; |
| 513 | } |
| 514 | |
Mike Turquette | 11a441c | 2010-02-22 11:16:30 -0600 | [diff] [blame] | 515 | int twl4030_remove_script(u8 flags) |
| 516 | { |
| 517 | int err = 0; |
| 518 | |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 519 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG1, |
| 520 | TWL4030_PM_MASTER_PROTECT_KEY); |
Mike Turquette | 11a441c | 2010-02-22 11:16:30 -0600 | [diff] [blame] | 521 | if (err) { |
| 522 | pr_err("twl4030: unable to unlock PROTECT_KEY\n"); |
| 523 | return err; |
| 524 | } |
| 525 | |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 526 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG2, |
| 527 | TWL4030_PM_MASTER_PROTECT_KEY); |
Mike Turquette | 11a441c | 2010-02-22 11:16:30 -0600 | [diff] [blame] | 528 | if (err) { |
| 529 | pr_err("twl4030: unable to unlock PROTECT_KEY\n"); |
| 530 | return err; |
| 531 | } |
| 532 | |
| 533 | if (flags & TWL4030_WRST_SCRIPT) { |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 534 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, END_OF_SCRIPT, |
| 535 | R_SEQ_ADD_WARM); |
Mike Turquette | 11a441c | 2010-02-22 11:16:30 -0600 | [diff] [blame] | 536 | if (err) |
| 537 | return err; |
| 538 | } |
| 539 | if (flags & TWL4030_WAKEUP12_SCRIPT) { |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 540 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, END_OF_SCRIPT, |
| 541 | R_SEQ_ADD_S2A12); |
Lesly A M | eac78a2 | 2011-05-04 17:38:53 +0530 | [diff] [blame] | 542 | if (err) |
Mike Turquette | 11a441c | 2010-02-22 11:16:30 -0600 | [diff] [blame] | 543 | return err; |
| 544 | } |
| 545 | if (flags & TWL4030_WAKEUP3_SCRIPT) { |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 546 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, END_OF_SCRIPT, |
| 547 | R_SEQ_ADD_S2A3); |
Mike Turquette | 11a441c | 2010-02-22 11:16:30 -0600 | [diff] [blame] | 548 | if (err) |
| 549 | return err; |
| 550 | } |
| 551 | if (flags & TWL4030_SLEEP_SCRIPT) { |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 552 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, END_OF_SCRIPT, |
| 553 | R_SEQ_ADD_A2S); |
Mike Turquette | 11a441c | 2010-02-22 11:16:30 -0600 | [diff] [blame] | 554 | if (err) |
| 555 | return err; |
| 556 | } |
| 557 | |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 558 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 0, |
| 559 | TWL4030_PM_MASTER_PROTECT_KEY); |
Mike Turquette | 11a441c | 2010-02-22 11:16:30 -0600 | [diff] [blame] | 560 | if (err) |
| 561 | pr_err("TWL4030 Unable to relock registers\n"); |
| 562 | |
| 563 | return err; |
| 564 | } |
| 565 | |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 566 | static int |
| 567 | twl4030_power_configure_scripts(const struct twl4030_power_data *pdata) |
Florian Vaussard | f58cb40 | 2013-06-18 15:17:57 +0200 | [diff] [blame] | 568 | { |
| 569 | int err; |
| 570 | int i; |
| 571 | u8 address = twl4030_start_script_address; |
| 572 | |
| 573 | for (i = 0; i < pdata->num; i++) { |
Tony Lindgren | 5c188d7 | 2015-04-27 10:18:14 -0700 | [diff] [blame] | 574 | err = load_twl4030_script(pdata, pdata->scripts[i], address); |
Florian Vaussard | f58cb40 | 2013-06-18 15:17:57 +0200 | [diff] [blame] | 575 | if (err) |
| 576 | return err; |
| 577 | address += pdata->scripts[i]->size; |
| 578 | } |
| 579 | |
| 580 | return 0; |
| 581 | } |
| 582 | |
Tony Lindgren | 482e7db | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 583 | static void twl4030_patch_rconfig(struct twl4030_resconfig *common, |
| 584 | struct twl4030_resconfig *board) |
| 585 | { |
| 586 | while (common->resource) { |
| 587 | struct twl4030_resconfig *b = board; |
| 588 | |
| 589 | while (b->resource) { |
| 590 | if (b->resource == common->resource) { |
| 591 | *common = *b; |
| 592 | break; |
| 593 | } |
| 594 | b++; |
| 595 | } |
| 596 | common++; |
| 597 | } |
| 598 | } |
| 599 | |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 600 | static int |
| 601 | twl4030_power_configure_resources(const struct twl4030_power_data *pdata) |
Florian Vaussard | f58cb40 | 2013-06-18 15:17:57 +0200 | [diff] [blame] | 602 | { |
| 603 | struct twl4030_resconfig *resconfig = pdata->resource_config; |
Tony Lindgren | 482e7db | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 604 | struct twl4030_resconfig *boardconf = pdata->board_config; |
Florian Vaussard | f58cb40 | 2013-06-18 15:17:57 +0200 | [diff] [blame] | 605 | int err; |
| 606 | |
| 607 | if (resconfig) { |
Tony Lindgren | 482e7db | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 608 | if (boardconf) |
| 609 | twl4030_patch_rconfig(resconfig, boardconf); |
| 610 | |
Florian Vaussard | f58cb40 | 2013-06-18 15:17:57 +0200 | [diff] [blame] | 611 | while (resconfig->resource) { |
| 612 | err = twl4030_configure_resource(resconfig); |
| 613 | if (err) |
| 614 | return err; |
| 615 | resconfig++; |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | return 0; |
| 620 | } |
| 621 | |
Tony Lindgren | 481c7f8 | 2014-11-02 10:07:56 -0800 | [diff] [blame] | 622 | static int twl4030_starton_mask_and_set(u8 bitmask, u8 bitvalues) |
| 623 | { |
| 624 | u8 regs[3] = { TWL4030_PM_MASTER_CFG_P1_TRANSITION, |
| 625 | TWL4030_PM_MASTER_CFG_P2_TRANSITION, |
| 626 | TWL4030_PM_MASTER_CFG_P3_TRANSITION, }; |
| 627 | u8 val; |
| 628 | int i, err; |
| 629 | |
| 630 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG1, |
| 631 | TWL4030_PM_MASTER_PROTECT_KEY); |
| 632 | if (err) |
| 633 | goto relock; |
| 634 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, |
| 635 | TWL4030_PM_MASTER_KEY_CFG2, |
| 636 | TWL4030_PM_MASTER_PROTECT_KEY); |
| 637 | if (err) |
| 638 | goto relock; |
| 639 | |
| 640 | for (i = 0; i < sizeof(regs); i++) { |
| 641 | err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, |
| 642 | &val, regs[i]); |
| 643 | if (err) |
| 644 | break; |
| 645 | val = (~bitmask & val) | (bitmask & bitvalues); |
| 646 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, |
| 647 | val, regs[i]); |
| 648 | if (err) |
| 649 | break; |
| 650 | } |
| 651 | |
| 652 | if (err) |
| 653 | pr_err("TWL4030 Register access failed: %i\n", err); |
| 654 | |
| 655 | relock: |
| 656 | return twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 0, |
| 657 | TWL4030_PM_MASTER_PROTECT_KEY); |
| 658 | } |
| 659 | |
Igor Grinberg | 26cc3ab | 2011-11-13 11:49:50 +0200 | [diff] [blame] | 660 | /* |
| 661 | * In master mode, start the power off sequence. |
| 662 | * After a successful execution, TWL shuts down the power to the SoC |
| 663 | * and all peripherals connected to it. |
| 664 | */ |
| 665 | void twl4030_power_off(void) |
| 666 | { |
| 667 | int err; |
| 668 | |
Tony Lindgren | 481c7f8 | 2014-11-02 10:07:56 -0800 | [diff] [blame] | 669 | /* Disable start on charger or VBUS as it can break poweroff */ |
| 670 | err = twl4030_starton_mask_and_set(STARTON_VBUS | STARTON_CHG, 0); |
| 671 | if (err) |
| 672 | pr_err("TWL4030 Unable to configure start-up\n"); |
| 673 | |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 674 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, PWR_DEVOFF, |
Igor Grinberg | 26cc3ab | 2011-11-13 11:49:50 +0200 | [diff] [blame] | 675 | TWL4030_PM_MASTER_P1_SW_EVENTS); |
| 676 | if (err) |
| 677 | pr_err("TWL4030 Unable to power off\n"); |
| 678 | } |
| 679 | |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 680 | static bool twl4030_power_use_poweroff(const struct twl4030_power_data *pdata, |
Florian Vaussard | b0fc1da | 2013-06-18 15:17:58 +0200 | [diff] [blame] | 681 | struct device_node *node) |
| 682 | { |
| 683 | if (pdata && pdata->use_poweroff) |
| 684 | return true; |
| 685 | |
Nishanth Menon | fecc445 | 2014-09-17 07:34:12 -0500 | [diff] [blame] | 686 | if (of_property_read_bool(node, "ti,system-power-controller")) |
| 687 | return true; |
| 688 | |
Florian Vaussard | b0fc1da | 2013-06-18 15:17:58 +0200 | [diff] [blame] | 689 | if (of_property_read_bool(node, "ti,use_poweroff")) |
| 690 | return true; |
| 691 | |
| 692 | return false; |
| 693 | } |
| 694 | |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 695 | #ifdef CONFIG_OF |
| 696 | |
| 697 | /* Generic warm reset configuration for omap3 */ |
| 698 | |
| 699 | static struct twl4030_ins omap3_wrst_seq[] = { |
| 700 | TWL_RESOURCE_OFF(RES_NRES_PWRON), |
| 701 | TWL_RESOURCE_OFF(RES_RESET), |
| 702 | TWL_RESOURCE_RESET(RES_MAIN_REF), |
| 703 | TWL_RESOURCE_GROUP_RESET(RES_GRP_ALL, RES_TYPE_R0, RES_TYPE2_R2), |
| 704 | TWL_RESOURCE_RESET(RES_VUSB_3V1), |
| 705 | TWL_RESOURCE_GROUP_RESET(RES_GRP_ALL, RES_TYPE_R0, RES_TYPE2_R1), |
| 706 | TWL_RESOURCE_GROUP_RESET(RES_GRP_RC, RES_TYPE_ALL, RES_TYPE2_R0), |
| 707 | TWL_RESOURCE_ON(RES_RESET), |
| 708 | TWL_RESOURCE_ON(RES_NRES_PWRON), |
| 709 | }; |
| 710 | |
| 711 | static struct twl4030_script omap3_wrst_script = { |
| 712 | .script = omap3_wrst_seq, |
| 713 | .size = ARRAY_SIZE(omap3_wrst_seq), |
| 714 | .flags = TWL4030_WRST_SCRIPT, |
| 715 | }; |
| 716 | |
| 717 | static struct twl4030_script *omap3_reset_scripts[] = { |
| 718 | &omap3_wrst_script, |
| 719 | }; |
| 720 | |
| 721 | static struct twl4030_resconfig omap3_rconfig[] = { |
| 722 | TWL_REMAP_SLEEP(RES_HFCLKOUT, DEV_GRP_P3, -1, -1), |
| 723 | TWL_REMAP_SLEEP(RES_VDD1, DEV_GRP_P1, -1, -1), |
| 724 | TWL_REMAP_SLEEP(RES_VDD2, DEV_GRP_P1, -1, -1), |
| 725 | { 0, 0 }, |
| 726 | }; |
| 727 | |
| 728 | static struct twl4030_power_data omap3_reset = { |
| 729 | .scripts = omap3_reset_scripts, |
| 730 | .num = ARRAY_SIZE(omap3_reset_scripts), |
| 731 | .resource_config = omap3_rconfig, |
| 732 | }; |
| 733 | |
Tony Lindgren | 76714d2 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 734 | /* Recommended generic default idle configuration for off-idle */ |
| 735 | |
| 736 | /* Broadcast message to put res to sleep */ |
| 737 | static struct twl4030_ins omap3_idle_sleep_on_seq[] = { |
| 738 | TWL_RESOURCE_GROUP_SLEEP(RES_GRP_ALL, RES_TYPE_ALL, 0), |
| 739 | }; |
| 740 | |
| 741 | static struct twl4030_script omap3_idle_sleep_on_script = { |
| 742 | .script = omap3_idle_sleep_on_seq, |
| 743 | .size = ARRAY_SIZE(omap3_idle_sleep_on_seq), |
| 744 | .flags = TWL4030_SLEEP_SCRIPT, |
| 745 | }; |
| 746 | |
| 747 | /* Broadcast message to put res to active */ |
| 748 | static struct twl4030_ins omap3_idle_wakeup_p12_seq[] = { |
| 749 | TWL_RESOURCE_GROUP_ACTIVE(RES_GRP_ALL, RES_TYPE_ALL, 0), |
| 750 | }; |
| 751 | |
| 752 | static struct twl4030_script omap3_idle_wakeup_p12_script = { |
| 753 | .script = omap3_idle_wakeup_p12_seq, |
| 754 | .size = ARRAY_SIZE(omap3_idle_wakeup_p12_seq), |
| 755 | .flags = TWL4030_WAKEUP12_SCRIPT, |
| 756 | }; |
| 757 | |
| 758 | /* Broadcast message to put res to active */ |
| 759 | static struct twl4030_ins omap3_idle_wakeup_p3_seq[] = { |
| 760 | TWL_RESOURCE_SET_ACTIVE(RES_CLKEN, 0x37), |
| 761 | TWL_RESOURCE_GROUP_ACTIVE(RES_GRP_ALL, RES_TYPE_ALL, 0), |
| 762 | }; |
| 763 | |
| 764 | static struct twl4030_script omap3_idle_wakeup_p3_script = { |
| 765 | .script = omap3_idle_wakeup_p3_seq, |
| 766 | .size = ARRAY_SIZE(omap3_idle_wakeup_p3_seq), |
| 767 | .flags = TWL4030_WAKEUP3_SCRIPT, |
| 768 | }; |
| 769 | |
| 770 | static struct twl4030_script *omap3_idle_scripts[] = { |
| 771 | &omap3_idle_wakeup_p12_script, |
| 772 | &omap3_idle_wakeup_p3_script, |
| 773 | &omap3_wrst_script, |
| 774 | &omap3_idle_sleep_on_script, |
| 775 | }; |
| 776 | |
| 777 | /* |
| 778 | * Recommended configuration based on "Recommended Sleep |
| 779 | * Sequences for the Zoom Platform": |
| 780 | * http://omappedia.com/wiki/File:Recommended_Sleep_Sequences_Zoom.pdf |
| 781 | * Note that the type1 and type2 seem to be just the init order number |
| 782 | * for type1 and type2 groups as specified in the document mentioned |
| 783 | * above. |
| 784 | */ |
| 785 | static struct twl4030_resconfig omap3_idle_rconfig[] = { |
Tony Lindgren | daebabd | 2014-08-19 08:24:05 -0700 | [diff] [blame] | 786 | TWL_REMAP_SLEEP(RES_VAUX1, TWL4030_RESCONFIG_UNDEF, 0, 0), |
| 787 | TWL_REMAP_SLEEP(RES_VAUX2, TWL4030_RESCONFIG_UNDEF, 0, 0), |
| 788 | TWL_REMAP_SLEEP(RES_VAUX3, TWL4030_RESCONFIG_UNDEF, 0, 0), |
| 789 | TWL_REMAP_SLEEP(RES_VAUX4, TWL4030_RESCONFIG_UNDEF, 0, 0), |
| 790 | TWL_REMAP_SLEEP(RES_VMMC1, TWL4030_RESCONFIG_UNDEF, 0, 0), |
| 791 | TWL_REMAP_SLEEP(RES_VMMC2, TWL4030_RESCONFIG_UNDEF, 0, 0), |
Tony Lindgren | 76714d2 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 792 | TWL_REMAP_OFF(RES_VPLL1, DEV_GRP_P1, 3, 1), |
| 793 | TWL_REMAP_SLEEP(RES_VPLL2, DEV_GRP_P1, 0, 0), |
Tony Lindgren | daebabd | 2014-08-19 08:24:05 -0700 | [diff] [blame] | 794 | TWL_REMAP_SLEEP(RES_VSIM, TWL4030_RESCONFIG_UNDEF, 0, 0), |
| 795 | TWL_REMAP_SLEEP(RES_VDAC, TWL4030_RESCONFIG_UNDEF, 0, 0), |
Tony Lindgren | 76714d2 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 796 | TWL_REMAP_SLEEP(RES_VINTANA1, TWL_DEV_GRP_P123, 1, 2), |
| 797 | TWL_REMAP_SLEEP(RES_VINTANA2, TWL_DEV_GRP_P123, 0, 2), |
| 798 | TWL_REMAP_SLEEP(RES_VINTDIG, TWL_DEV_GRP_P123, 1, 2), |
| 799 | TWL_REMAP_SLEEP(RES_VIO, TWL_DEV_GRP_P123, 2, 2), |
| 800 | TWL_REMAP_OFF(RES_VDD1, DEV_GRP_P1, 4, 1), |
| 801 | TWL_REMAP_OFF(RES_VDD2, DEV_GRP_P1, 3, 1), |
Tony Lindgren | daebabd | 2014-08-19 08:24:05 -0700 | [diff] [blame] | 802 | TWL_REMAP_SLEEP(RES_VUSB_1V5, TWL4030_RESCONFIG_UNDEF, 0, 0), |
| 803 | TWL_REMAP_SLEEP(RES_VUSB_1V8, TWL4030_RESCONFIG_UNDEF, 0, 0), |
Tony Lindgren | 76714d2 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 804 | TWL_REMAP_SLEEP(RES_VUSB_3V1, TWL_DEV_GRP_P123, 0, 0), |
| 805 | /* Resource #20 USB charge pump skipped */ |
| 806 | TWL_REMAP_SLEEP(RES_REGEN, TWL_DEV_GRP_P123, 2, 1), |
| 807 | TWL_REMAP_SLEEP(RES_NRES_PWRON, TWL_DEV_GRP_P123, 0, 1), |
| 808 | TWL_REMAP_SLEEP(RES_CLKEN, TWL_DEV_GRP_P123, 3, 2), |
| 809 | TWL_REMAP_SLEEP(RES_SYSEN, TWL_DEV_GRP_P123, 6, 1), |
| 810 | TWL_REMAP_SLEEP(RES_HFCLKOUT, DEV_GRP_P3, 0, 2), |
| 811 | TWL_REMAP_SLEEP(RES_32KCLKOUT, TWL_DEV_GRP_P123, 0, 0), |
| 812 | TWL_REMAP_SLEEP(RES_RESET, TWL_DEV_GRP_P123, 6, 0), |
| 813 | TWL_REMAP_SLEEP(RES_MAIN_REF, TWL_DEV_GRP_P123, 0, 0), |
| 814 | { /* Terminator */ }, |
| 815 | }; |
| 816 | |
| 817 | static struct twl4030_power_data omap3_idle = { |
| 818 | .scripts = omap3_idle_scripts, |
| 819 | .num = ARRAY_SIZE(omap3_idle_scripts), |
| 820 | .resource_config = omap3_idle_rconfig, |
| 821 | }; |
| 822 | |
Tony Lindgren | 43fef47 | 2014-05-13 18:34:09 -0700 | [diff] [blame] | 823 | /* Disable 32 KiHz oscillator during idle */ |
| 824 | static struct twl4030_resconfig osc_off_rconfig[] = { |
| 825 | TWL_REMAP_OFF(RES_CLKEN, DEV_GRP_P1 | DEV_GRP_P3, 3, 2), |
| 826 | { /* Terminator */ }, |
| 827 | }; |
| 828 | |
| 829 | static struct twl4030_power_data osc_off_idle = { |
| 830 | .scripts = omap3_idle_scripts, |
| 831 | .num = ARRAY_SIZE(omap3_idle_scripts), |
| 832 | .resource_config = omap3_idle_rconfig, |
| 833 | .board_config = osc_off_rconfig, |
| 834 | }; |
| 835 | |
Tony Lindgren | 5c188d7 | 2015-04-27 10:18:14 -0700 | [diff] [blame] | 836 | static struct twl4030_power_data omap3_idle_ac_quirk = { |
| 837 | .scripts = omap3_idle_scripts, |
| 838 | .num = ARRAY_SIZE(omap3_idle_scripts), |
| 839 | .resource_config = omap3_idle_rconfig, |
| 840 | .ac_charger_quirk = true, |
| 841 | }; |
| 842 | |
| 843 | static struct twl4030_power_data omap3_idle_ac_quirk_osc_off = { |
| 844 | .scripts = omap3_idle_scripts, |
| 845 | .num = ARRAY_SIZE(omap3_idle_scripts), |
| 846 | .resource_config = omap3_idle_rconfig, |
| 847 | .board_config = osc_off_rconfig, |
| 848 | .ac_charger_quirk = true, |
| 849 | }; |
| 850 | |
Fabian Frederick | 908725d | 2015-03-16 20:21:36 +0100 | [diff] [blame] | 851 | static const struct of_device_id twl4030_power_of_match[] = { |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 852 | { |
Tony Lindgren | 1b9b46d | 2014-11-02 10:09:38 -0800 | [diff] [blame] | 853 | .compatible = "ti,twl4030-power", |
| 854 | }, |
| 855 | { |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 856 | .compatible = "ti,twl4030-power-reset", |
| 857 | .data = &omap3_reset, |
| 858 | }, |
Tony Lindgren | 76714d2 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 859 | { |
| 860 | .compatible = "ti,twl4030-power-idle", |
| 861 | .data = &omap3_idle, |
| 862 | }, |
Tony Lindgren | 43fef47 | 2014-05-13 18:34:09 -0700 | [diff] [blame] | 863 | { |
| 864 | .compatible = "ti,twl4030-power-idle-osc-off", |
| 865 | .data = &osc_off_idle, |
| 866 | }, |
Tony Lindgren | 5c188d7 | 2015-04-27 10:18:14 -0700 | [diff] [blame] | 867 | { |
| 868 | .compatible = "ti,twl4030-power-omap3-sdp", |
| 869 | .data = &omap3_idle_ac_quirk, |
| 870 | }, |
| 871 | { |
| 872 | .compatible = "ti,twl4030-power-omap3-ldp", |
| 873 | .data = &omap3_idle_ac_quirk_osc_off, |
| 874 | }, |
| 875 | { |
| 876 | .compatible = "ti,twl4030-power-omap3-evm", |
| 877 | .data = &omap3_idle_ac_quirk, |
| 878 | }, |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 879 | { }, |
| 880 | }; |
| 881 | MODULE_DEVICE_TABLE(of, twl4030_power_of_match); |
| 882 | #endif /* CONFIG_OF */ |
| 883 | |
Jingoo Han | fae0158 | 2013-08-01 10:52:55 +0900 | [diff] [blame] | 884 | static int twl4030_power_probe(struct platform_device *pdev) |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 885 | { |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 886 | const struct twl4030_power_data *pdata = dev_get_platdata(&pdev->dev); |
Florian Vaussard | b0fc1da | 2013-06-18 15:17:58 +0200 | [diff] [blame] | 887 | struct device_node *node = pdev->dev.of_node; |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 888 | const struct of_device_id *match; |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 889 | int err = 0; |
Florian Vaussard | cb3cabd | 2013-06-18 15:18:00 +0200 | [diff] [blame] | 890 | int err2 = 0; |
Florian Vaussard | f58cb40 | 2013-06-18 15:17:57 +0200 | [diff] [blame] | 891 | u8 val; |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 892 | |
Florian Vaussard | b0fc1da | 2013-06-18 15:17:58 +0200 | [diff] [blame] | 893 | if (!pdata && !node) { |
| 894 | dev_err(&pdev->dev, "Platform data is missing\n"); |
| 895 | return -EINVAL; |
| 896 | } |
| 897 | |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 898 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG1, |
| 899 | TWL4030_PM_MASTER_PROTECT_KEY); |
Florian Vaussard | e77a4c2 | 2013-06-18 15:17:59 +0200 | [diff] [blame] | 900 | err |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, |
| 901 | TWL4030_PM_MASTER_KEY_CFG2, |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 902 | TWL4030_PM_MASTER_PROTECT_KEY); |
Florian Vaussard | e77a4c2 | 2013-06-18 15:17:59 +0200 | [diff] [blame] | 903 | |
| 904 | if (err) { |
| 905 | pr_err("TWL4030 Unable to unlock registers\n"); |
| 906 | return err; |
| 907 | } |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 908 | |
Tony Lindgren | e7cd1d1 | 2014-05-20 11:17:54 -0700 | [diff] [blame] | 909 | match = of_match_device(of_match_ptr(twl4030_power_of_match), |
| 910 | &pdev->dev); |
| 911 | if (match && match->data) |
| 912 | pdata = match->data; |
| 913 | |
Florian Vaussard | b0fc1da | 2013-06-18 15:17:58 +0200 | [diff] [blame] | 914 | if (pdata) { |
Florian Vaussard | b0fc1da | 2013-06-18 15:17:58 +0200 | [diff] [blame] | 915 | err = twl4030_power_configure_scripts(pdata); |
Florian Vaussard | e77a4c2 | 2013-06-18 15:17:59 +0200 | [diff] [blame] | 916 | if (err) { |
| 917 | pr_err("TWL4030 failed to load scripts\n"); |
Florian Vaussard | cb3cabd | 2013-06-18 15:18:00 +0200 | [diff] [blame] | 918 | goto relock; |
Florian Vaussard | e77a4c2 | 2013-06-18 15:17:59 +0200 | [diff] [blame] | 919 | } |
Florian Vaussard | b0fc1da | 2013-06-18 15:17:58 +0200 | [diff] [blame] | 920 | err = twl4030_power_configure_resources(pdata); |
Florian Vaussard | e77a4c2 | 2013-06-18 15:17:59 +0200 | [diff] [blame] | 921 | if (err) { |
| 922 | pr_err("TWL4030 failed to configure resource\n"); |
Florian Vaussard | cb3cabd | 2013-06-18 15:18:00 +0200 | [diff] [blame] | 923 | goto relock; |
Florian Vaussard | e77a4c2 | 2013-06-18 15:17:59 +0200 | [diff] [blame] | 924 | } |
Florian Vaussard | b0fc1da | 2013-06-18 15:17:58 +0200 | [diff] [blame] | 925 | } |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 926 | |
Igor Grinberg | 26cc3ab | 2011-11-13 11:49:50 +0200 | [diff] [blame] | 927 | /* Board has to be wired properly to use this feature */ |
Florian Vaussard | b0fc1da | 2013-06-18 15:17:58 +0200 | [diff] [blame] | 928 | if (twl4030_power_use_poweroff(pdata, node) && !pm_power_off) { |
Igor Grinberg | 26cc3ab | 2011-11-13 11:49:50 +0200 | [diff] [blame] | 929 | /* Default for SEQ_OFFSYNC is set, lets ensure this */ |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 930 | err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val, |
Igor Grinberg | 26cc3ab | 2011-11-13 11:49:50 +0200 | [diff] [blame] | 931 | TWL4030_PM_MASTER_CFG_P123_TRANSITION); |
| 932 | if (err) { |
| 933 | pr_warning("TWL4030 Unable to read registers\n"); |
| 934 | |
| 935 | } else if (!(val & SEQ_OFFSYNC)) { |
| 936 | val |= SEQ_OFFSYNC; |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 937 | err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, val, |
Igor Grinberg | 26cc3ab | 2011-11-13 11:49:50 +0200 | [diff] [blame] | 938 | TWL4030_PM_MASTER_CFG_P123_TRANSITION); |
| 939 | if (err) { |
| 940 | pr_err("TWL4030 Unable to setup SEQ_OFFSYNC\n"); |
| 941 | goto relock; |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | pm_power_off = twl4030_power_off; |
| 946 | } |
| 947 | |
| 948 | relock: |
Florian Vaussard | cb3cabd | 2013-06-18 15:18:00 +0200 | [diff] [blame] | 949 | err2 = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 0, |
Peter Ujfalusi | 4850f12 | 2012-11-13 09:28:52 +0100 | [diff] [blame] | 950 | TWL4030_PM_MASTER_PROTECT_KEY); |
Florian Vaussard | cb3cabd | 2013-06-18 15:18:00 +0200 | [diff] [blame] | 951 | if (err2) { |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 952 | pr_err("TWL4030 Unable to relock registers\n"); |
Florian Vaussard | cb3cabd | 2013-06-18 15:18:00 +0200 | [diff] [blame] | 953 | return err2; |
| 954 | } |
| 955 | |
Florian Vaussard | 637d689 | 2013-06-18 15:17:56 +0200 | [diff] [blame] | 956 | return err; |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 957 | } |
Florian Vaussard | 637d689 | 2013-06-18 15:17:56 +0200 | [diff] [blame] | 958 | |
| 959 | static int twl4030_power_remove(struct platform_device *pdev) |
| 960 | { |
| 961 | return 0; |
| 962 | } |
| 963 | |
| 964 | static struct platform_driver twl4030_power_driver = { |
| 965 | .driver = { |
| 966 | .name = "twl4030_power", |
Florian Vaussard | b0fc1da | 2013-06-18 15:17:58 +0200 | [diff] [blame] | 967 | .of_match_table = of_match_ptr(twl4030_power_of_match), |
Florian Vaussard | 637d689 | 2013-06-18 15:17:56 +0200 | [diff] [blame] | 968 | }, |
| 969 | .probe = twl4030_power_probe, |
| 970 | .remove = twl4030_power_remove, |
| 971 | }; |
| 972 | |
| 973 | module_platform_driver(twl4030_power_driver); |
| 974 | |
| 975 | MODULE_AUTHOR("Nokia Corporation"); |
| 976 | MODULE_AUTHOR("Texas Instruments, Inc."); |
| 977 | MODULE_DESCRIPTION("Power management for TWL4030"); |
| 978 | MODULE_LICENSE("GPL"); |
| 979 | MODULE_ALIAS("platform:twl4030_power"); |