twl4030-power.c 15.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * linux/drivers/i2c/chips/twl4030-power.c
 *
 * Handle TWL4030 Power initialization
 *
 * Copyright (C) 2008 Nokia Corporation
 * Copyright (C) 2006 Texas Instruments, Inc
 *
 * Written by 	Kalle Jokiniemi
 *		Peter De Schrijver <peter.de-schrijver@nokia.com>
 * Several fixes by Amit Kucheria <amit.kucheria@verdurent.com>
 *
 * This file is subject to the terms and conditions of the GNU General
 * Public License. See the file "COPYING" in the main directory of this
 * archive for more details.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <linux/module.h>
#include <linux/pm.h>
29
#include <linux/i2c/twl.h>
30
#include <linux/platform_device.h>
31
#include <linux/of.h>
32 33 34 35 36 37

#include <asm/mach-types.h>

static u8 twl4030_start_script_address = 0x2b;

#define PWR_P1_SW_EVENTS	0x10
38 39
#define PWR_DEVOFF		(1 << 0)
#define SEQ_OFFSYNC		(1 << 0)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

#define PHY_TO_OFF_PM_MASTER(p)		(p - 0x36)
#define PHY_TO_OFF_PM_RECEIVER(p)	(p - 0x5b)

/* resource - hfclk */
#define R_HFCLKOUT_DEV_GRP 	PHY_TO_OFF_PM_RECEIVER(0xe6)

/* PM events */
#define R_P1_SW_EVENTS		PHY_TO_OFF_PM_MASTER(0x46)
#define R_P2_SW_EVENTS		PHY_TO_OFF_PM_MASTER(0x47)
#define R_P3_SW_EVENTS		PHY_TO_OFF_PM_MASTER(0x48)
#define R_CFG_P1_TRANSITION	PHY_TO_OFF_PM_MASTER(0x36)
#define R_CFG_P2_TRANSITION	PHY_TO_OFF_PM_MASTER(0x37)
#define R_CFG_P3_TRANSITION	PHY_TO_OFF_PM_MASTER(0x38)

#define LVL_WAKEUP	0x08

#define ENABLE_WARMRESET (1<<4)

#define END_OF_SCRIPT		0x3f

#define R_SEQ_ADD_A2S		PHY_TO_OFF_PM_MASTER(0x55)
#define R_SEQ_ADD_S2A12		PHY_TO_OFF_PM_MASTER(0x56)
#define	R_SEQ_ADD_S2A3		PHY_TO_OFF_PM_MASTER(0x57)
#define	R_SEQ_ADD_WARM		PHY_TO_OFF_PM_MASTER(0x58)
#define R_MEMORY_ADDRESS	PHY_TO_OFF_PM_MASTER(0x59)
#define R_MEMORY_DATA		PHY_TO_OFF_PM_MASTER(0x5a)

68 69 70 71 72 73
/* resource configuration registers
   <RESOURCE>_DEV_GRP   at address 'n+0'
   <RESOURCE>_TYPE      at address 'n+1'
   <RESOURCE>_REMAP     at address 'n+2'
   <RESOURCE>_DEDICATED at address 'n+3'
*/
74
#define DEV_GRP_OFFSET		0
75
#define TYPE_OFFSET		1
76 77
#define REMAP_OFFSET		2
#define DEDICATED_OFFSET	3
78

79
/* Bit positions in the registers */
80 81

/* <RESOURCE>_DEV_GRP */
82 83
#define DEV_GRP_SHIFT		5
#define DEV_GRP_MASK		(7 << DEV_GRP_SHIFT)
84 85

/* <RESOURCE>_TYPE */
86 87 88 89 90
#define TYPE_SHIFT		0
#define TYPE_MASK		(7 << TYPE_SHIFT)
#define TYPE2_SHIFT		3
#define TYPE2_MASK		(3 << TYPE2_SHIFT)

91 92 93 94 95 96
/* <RESOURCE>_REMAP */
#define SLEEP_STATE_SHIFT	0
#define SLEEP_STATE_MASK	(0xf << SLEEP_STATE_SHIFT)
#define OFF_STATE_SHIFT		4
#define OFF_STATE_MASK		(0xf << OFF_STATE_SHIFT)

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
static u8 res_config_addrs[] = {
	[RES_VAUX1]	= 0x17,
	[RES_VAUX2]	= 0x1b,
	[RES_VAUX3]	= 0x1f,
	[RES_VAUX4]	= 0x23,
	[RES_VMMC1]	= 0x27,
	[RES_VMMC2]	= 0x2b,
	[RES_VPLL1]	= 0x2f,
	[RES_VPLL2]	= 0x33,
	[RES_VSIM]	= 0x37,
	[RES_VDAC]	= 0x3b,
	[RES_VINTANA1]	= 0x3f,
	[RES_VINTANA2]	= 0x43,
	[RES_VINTDIG]	= 0x47,
	[RES_VIO]	= 0x4b,
	[RES_VDD1]	= 0x55,
	[RES_VDD2]	= 0x63,
	[RES_VUSB_1V5]	= 0x71,
	[RES_VUSB_1V8]	= 0x74,
	[RES_VUSB_3V1]	= 0x77,
	[RES_VUSBCP]	= 0x7a,
	[RES_REGEN]	= 0x7f,
	[RES_NRES_PWRON] = 0x82,
	[RES_CLKEN]	= 0x85,
	[RES_SYSEN]	= 0x88,
	[RES_HFCLKOUT]	= 0x8b,
	[RES_32KCLKOUT]	= 0x8e,
	[RES_RESET]	= 0x91,
125
	[RES_MAIN_REF]	= 0x94,
126 127
};

B
Bill Pemberton 已提交
128
static int twl4030_write_script_byte(u8 address, u8 byte)
129 130 131
{
	int err;

132
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, address, R_MEMORY_ADDRESS);
133 134
	if (err)
		goto out;
135
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, byte, R_MEMORY_DATA);
136 137 138 139
out:
	return err;
}

B
Bill Pemberton 已提交
140
static int twl4030_write_script_ins(u8 address, u16 pmb_message,
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
					   u8 delay, u8 next)
{
	int err;

	address *= 4;
	err = twl4030_write_script_byte(address++, pmb_message >> 8);
	if (err)
		goto out;
	err = twl4030_write_script_byte(address++, pmb_message & 0xff);
	if (err)
		goto out;
	err = twl4030_write_script_byte(address++, delay);
	if (err)
		goto out;
	err = twl4030_write_script_byte(address++, next);
out:
	return err;
}

B
Bill Pemberton 已提交
160
static int twl4030_write_script(u8 address, struct twl4030_ins *script,
161 162
				       int len)
{
163
	int err = -EINVAL;
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184

	for (; len; len--, address++, script++) {
		if (len == 1) {
			err = twl4030_write_script_ins(address,
						script->pmb_message,
						script->delay,
						END_OF_SCRIPT);
			if (err)
				break;
		} else {
			err = twl4030_write_script_ins(address,
						script->pmb_message,
						script->delay,
						address + 1);
			if (err)
				break;
		}
	}
	return err;
}

B
Bill Pemberton 已提交
185
static int twl4030_config_wakeup3_sequence(u8 address)
186 187 188 189 190
{
	int err;
	u8 data;

	/* Set SLEEP to ACTIVE SEQ address for P3 */
191
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, address, R_SEQ_ADD_S2A3);
192 193 194 195
	if (err)
		goto out;

	/* P3 LVL_WAKEUP should be on LEVEL */
196
	err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &data, R_P3_SW_EVENTS);
197 198 199
	if (err)
		goto out;
	data |= LVL_WAKEUP;
200
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, data, R_P3_SW_EVENTS);
201 202 203 204 205 206
out:
	if (err)
		pr_err("TWL4030 wakeup sequence for P3 config error\n");
	return err;
}

B
Bill Pemberton 已提交
207
static int twl4030_config_wakeup12_sequence(u8 address)
208 209 210 211 212
{
	int err = 0;
	u8 data;

	/* Set SLEEP to ACTIVE SEQ address for P1 and P2 */
213
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, address, R_SEQ_ADD_S2A12);
214 215 216 217
	if (err)
		goto out;

	/* P1/P2 LVL_WAKEUP should be on LEVEL */
218
	err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &data, R_P1_SW_EVENTS);
219 220 221 222
	if (err)
		goto out;

	data |= LVL_WAKEUP;
223
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, data, R_P1_SW_EVENTS);
224 225 226
	if (err)
		goto out;

227
	err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &data, R_P2_SW_EVENTS);
228 229 230 231
	if (err)
		goto out;

	data |= LVL_WAKEUP;
232
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, data, R_P2_SW_EVENTS);
233 234 235 236 237
	if (err)
		goto out;

	if (machine_is_omap_3430sdp() || machine_is_omap_ldp()) {
		/* Disabling AC charger effect on sleep-active transitions */
238 239
		err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &data,
				      R_CFG_P1_TRANSITION);
240 241 242
		if (err)
			goto out;
		data &= ~(1<<1);
243 244
		err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, data,
				       R_CFG_P1_TRANSITION);
245 246 247 248 249 250 251 252 253 254 255
		if (err)
			goto out;
	}

out:
	if (err)
		pr_err("TWL4030 wakeup sequence for P1 and P2" \
			"config error\n");
	return err;
}

B
Bill Pemberton 已提交
256
static int twl4030_config_sleep_sequence(u8 address)
257 258 259 260
{
	int err;

	/* Set ACTIVE to SLEEP SEQ address in T2 memory*/
261
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, address, R_SEQ_ADD_A2S);
262 263 264 265 266 267 268

	if (err)
		pr_err("TWL4030 sleep sequence config error\n");

	return err;
}

B
Bill Pemberton 已提交
269
static int twl4030_config_warmreset_sequence(u8 address)
270 271 272 273 274
{
	int err;
	u8 rd_data;

	/* Set WARM RESET SEQ address for P1 */
275
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, address, R_SEQ_ADD_WARM);
276 277 278 279
	if (err)
		goto out;

	/* P1/P2/P3 enable WARMRESET */
280
	err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &rd_data, R_P1_SW_EVENTS);
281 282 283 284
	if (err)
		goto out;

	rd_data |= ENABLE_WARMRESET;
285
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, rd_data, R_P1_SW_EVENTS);
286 287 288
	if (err)
		goto out;

289
	err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &rd_data, R_P2_SW_EVENTS);
290 291 292 293
	if (err)
		goto out;

	rd_data |= ENABLE_WARMRESET;
294
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, rd_data, R_P2_SW_EVENTS);
295 296 297
	if (err)
		goto out;

298
	err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &rd_data, R_P3_SW_EVENTS);
299 300 301 302
	if (err)
		goto out;

	rd_data |= ENABLE_WARMRESET;
303
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, rd_data, R_P3_SW_EVENTS);
304 305 306 307 308 309
out:
	if (err)
		pr_err("TWL4030 warmreset seq config error\n");
	return err;
}

B
Bill Pemberton 已提交
310
static int twl4030_configure_resource(struct twl4030_resconfig *rconfig)
311 312 313 314 315
{
	int rconfig_addr;
	int err;
	u8 type;
	u8 grp;
316
	u8 remap;
317 318 319 320 321 322 323 324 325 326

	if (rconfig->resource > TOTAL_RESOURCES) {
		pr_err("TWL4030 Resource %d does not exist\n",
			rconfig->resource);
		return -EINVAL;
	}

	rconfig_addr = res_config_addrs[rconfig->resource];

	/* Set resource group */
327
	err = twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &grp,
B
Balaji T K 已提交
328
			      rconfig_addr + DEV_GRP_OFFSET);
329 330 331 332 333 334
	if (err) {
		pr_err("TWL4030 Resource %d group could not be read\n",
			rconfig->resource);
		return err;
	}

335
	if (rconfig->devgroup != TWL4030_RESCONFIG_UNDEF) {
336 337
		grp &= ~DEV_GRP_MASK;
		grp |= rconfig->devgroup << DEV_GRP_SHIFT;
338
		err = twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER,
B
Balaji T K 已提交
339
				       grp, rconfig_addr + DEV_GRP_OFFSET);
340 341 342 343 344 345 346
		if (err < 0) {
			pr_err("TWL4030 failed to program devgroup\n");
			return err;
		}
	}

	/* Set resource types */
347
	err = twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &type,
348 349 350 351 352 353 354
				rconfig_addr + TYPE_OFFSET);
	if (err < 0) {
		pr_err("TWL4030 Resource %d type could not be read\n",
			rconfig->resource);
		return err;
	}

355
	if (rconfig->type != TWL4030_RESCONFIG_UNDEF) {
356 357 358 359
		type &= ~TYPE_MASK;
		type |= rconfig->type << TYPE_SHIFT;
	}

360
	if (rconfig->type2 != TWL4030_RESCONFIG_UNDEF) {
361 362 363 364
		type &= ~TYPE2_MASK;
		type |= rconfig->type2 << TYPE2_SHIFT;
	}

365
	err = twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER,
366 367 368 369 370 371
				type, rconfig_addr + TYPE_OFFSET);
	if (err < 0) {
		pr_err("TWL4030 failed to program resource type\n");
		return err;
	}

372
	/* Set remap states */
373
	err = twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &remap,
B
Balaji T K 已提交
374
			      rconfig_addr + REMAP_OFFSET);
375 376 377 378 379 380
	if (err < 0) {
		pr_err("TWL4030 Resource %d remap could not be read\n",
			rconfig->resource);
		return err;
	}

381
	if (rconfig->remap_off != TWL4030_RESCONFIG_UNDEF) {
382 383 384 385
		remap &= ~OFF_STATE_MASK;
		remap |= rconfig->remap_off << OFF_STATE_SHIFT;
	}

386
	if (rconfig->remap_sleep != TWL4030_RESCONFIG_UNDEF) {
387
		remap &= ~SLEEP_STATE_MASK;
388
		remap |= rconfig->remap_sleep << SLEEP_STATE_SHIFT;
389 390
	}

391
	err = twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER,
B
Balaji T K 已提交
392 393
			       remap,
			       rconfig_addr + REMAP_OFFSET);
394 395 396 397 398
	if (err < 0) {
		pr_err("TWL4030 failed to program remap\n");
		return err;
	}

399 400 401
	return 0;
}

B
Bill Pemberton 已提交
402
static int load_twl4030_script(struct twl4030_script *tscript,
403 404 405
	       u8 address)
{
	int err;
406
	static int order;
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426

	/* Make sure the script isn't going beyond last valid address (0x3f) */
	if ((address + tscript->size) > END_OF_SCRIPT) {
		pr_err("TWL4030 scripts too big error\n");
		return -EINVAL;
	}

	err = twl4030_write_script(address, tscript->script, tscript->size);
	if (err)
		goto out;

	if (tscript->flags & TWL4030_WRST_SCRIPT) {
		err = twl4030_config_warmreset_sequence(address);
		if (err)
			goto out;
	}
	if (tscript->flags & TWL4030_WAKEUP12_SCRIPT) {
		err = twl4030_config_wakeup12_sequence(address);
		if (err)
			goto out;
427
		order = 1;
428 429 430 431 432 433
	}
	if (tscript->flags & TWL4030_WAKEUP3_SCRIPT) {
		err = twl4030_config_wakeup3_sequence(address);
		if (err)
			goto out;
	}
434
	if (tscript->flags & TWL4030_SLEEP_SCRIPT) {
435
		if (!order)
436 437 438
			pr_warning("TWL4030: Bad order of scripts (sleep "\
					"script before wakeup) Leads to boot"\
					"failure on some boards\n");
439
		err = twl4030_config_sleep_sequence(address);
440
	}
441 442 443 444
out:
	return err;
}

445 446 447 448
int twl4030_remove_script(u8 flags)
{
	int err = 0;

449 450
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG1,
			       TWL4030_PM_MASTER_PROTECT_KEY);
451 452 453 454 455
	if (err) {
		pr_err("twl4030: unable to unlock PROTECT_KEY\n");
		return err;
	}

456 457
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG2,
			       TWL4030_PM_MASTER_PROTECT_KEY);
458 459 460 461 462 463
	if (err) {
		pr_err("twl4030: unable to unlock PROTECT_KEY\n");
		return err;
	}

	if (flags & TWL4030_WRST_SCRIPT) {
464 465
		err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, END_OF_SCRIPT,
				       R_SEQ_ADD_WARM);
466 467 468 469
		if (err)
			return err;
	}
	if (flags & TWL4030_WAKEUP12_SCRIPT) {
470 471
		err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, END_OF_SCRIPT,
				       R_SEQ_ADD_S2A12);
472
		if (err)
473 474 475
			return err;
	}
	if (flags & TWL4030_WAKEUP3_SCRIPT) {
476 477
		err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, END_OF_SCRIPT,
				       R_SEQ_ADD_S2A3);
478 479 480 481
		if (err)
			return err;
	}
	if (flags & TWL4030_SLEEP_SCRIPT) {
482 483
		err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, END_OF_SCRIPT,
				       R_SEQ_ADD_A2S);
484 485 486 487
		if (err)
			return err;
	}

488 489
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 0,
			       TWL4030_PM_MASTER_PROTECT_KEY);
490 491 492 493 494 495
	if (err)
		pr_err("TWL4030 Unable to relock registers\n");

	return err;
}

496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
int twl4030_power_configure_scripts(struct twl4030_power_data *pdata)
{
	int err;
	int i;
	u8 address = twl4030_start_script_address;

	for (i = 0; i < pdata->num; i++) {
		err = load_twl4030_script(pdata->scripts[i], address);
		if (err)
			return err;
		address += pdata->scripts[i]->size;
	}

	return 0;
}

int twl4030_power_configure_resources(struct twl4030_power_data *pdata)
{
	struct twl4030_resconfig *resconfig = pdata->resource_config;
	int err;

	if (resconfig) {
		while (resconfig->resource) {
			err = twl4030_configure_resource(resconfig);
			if (err)
				return err;
			resconfig++;
		}
	}

	return 0;
}

529 530 531 532 533 534 535 536 537
/*
 * In master mode, start the power off sequence.
 * After a successful execution, TWL shuts down the power to the SoC
 * and all peripherals connected to it.
 */
void twl4030_power_off(void)
{
	int err;

538
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, PWR_DEVOFF,
539 540 541 542 543
			       TWL4030_PM_MASTER_P1_SW_EVENTS);
	if (err)
		pr_err("TWL4030 Unable to power off\n");
}

544 545 546 547 548 549 550 551 552 553 554 555
static bool twl4030_power_use_poweroff(struct twl4030_power_data *pdata,
					struct device_node *node)
{
	if (pdata && pdata->use_poweroff)
		return true;

	if (of_property_read_bool(node, "ti,use_poweroff"))
		return true;

	return false;
}

556
int twl4030_power_probe(struct platform_device *pdev)
557
{
J
Jingoo Han 已提交
558
	struct twl4030_power_data *pdata = dev_get_platdata(&pdev->dev);
559
	struct device_node *node = pdev->dev.of_node;
560
	int err = 0;
561
	int err2 = 0;
562
	u8 val;
563

564 565 566 567 568
	if (!pdata && !node) {
		dev_err(&pdev->dev, "Platform data is missing\n");
		return -EINVAL;
	}

569 570
	err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG1,
			       TWL4030_PM_MASTER_PROTECT_KEY);
571 572
	err |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
			       TWL4030_PM_MASTER_KEY_CFG2,
573
			       TWL4030_PM_MASTER_PROTECT_KEY);
574 575 576 577 578

	if (err) {
		pr_err("TWL4030 Unable to unlock registers\n");
		return err;
	}
579

580 581 582
	if (pdata) {
		/* TODO: convert to device tree */
		err = twl4030_power_configure_scripts(pdata);
583 584
		if (err) {
			pr_err("TWL4030 failed to load scripts\n");
585
			goto relock;
586
		}
587
		err = twl4030_power_configure_resources(pdata);
588 589
		if (err) {
			pr_err("TWL4030 failed to configure resource\n");
590
			goto relock;
591
		}
592
	}
593

594
	/* Board has to be wired properly to use this feature */
595
	if (twl4030_power_use_poweroff(pdata, node) && !pm_power_off) {
596
		/* Default for SEQ_OFFSYNC is set, lets ensure this */
597
		err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val,
598 599 600 601 602 603
				      TWL4030_PM_MASTER_CFG_P123_TRANSITION);
		if (err) {
			pr_warning("TWL4030 Unable to read registers\n");

		} else if (!(val & SEQ_OFFSYNC)) {
			val |= SEQ_OFFSYNC;
604
			err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, val,
605 606 607 608 609 610 611 612 613 614 615
					TWL4030_PM_MASTER_CFG_P123_TRANSITION);
			if (err) {
				pr_err("TWL4030 Unable to setup SEQ_OFFSYNC\n");
				goto relock;
			}
		}

		pm_power_off = twl4030_power_off;
	}

relock:
616
	err2 = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 0,
617
			       TWL4030_PM_MASTER_PROTECT_KEY);
618
	if (err2) {
619
		pr_err("TWL4030 Unable to relock registers\n");
620 621 622
		return err2;
	}

623 624 625 626 627 628
	return err;
}

static int twl4030_power_remove(struct platform_device *pdev)
{
	return 0;
629
}
630

631 632 633 634 635 636 637 638
#ifdef CONFIG_OF
static const struct of_device_id twl4030_power_of_match[] = {
	{.compatible = "ti,twl4030-power", },
	{ },
};
MODULE_DEVICE_TABLE(of, twl4030_power_of_match);
#endif

639 640 641 642
static struct platform_driver twl4030_power_driver = {
	.driver = {
		.name	= "twl4030_power",
		.owner	= THIS_MODULE,
643
		.of_match_table = of_match_ptr(twl4030_power_of_match),
644 645 646 647 648 649 650 651 652 653 654 655
	},
	.probe		= twl4030_power_probe,
	.remove		= twl4030_power_remove,
};

module_platform_driver(twl4030_power_driver);

MODULE_AUTHOR("Nokia Corporation");
MODULE_AUTHOR("Texas Instruments, Inc.");
MODULE_DESCRIPTION("Power management for TWL4030");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:twl4030_power");