Linux Audio

Check our new training course

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