2 * OMAP and TWL PMIC specific intializations.
4 * Copyright (C) 2010 Texas Instruments Incorporated.
6 * Copyright (C) 2009 Texas Instruments Incorporated.
8 * Copyright (C) 2009 Nokia Corporation
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/err.h>
18 #include <linux/kernel.h>
19 #include <linux/i2c/twl.h>
25 #define OMAP3_SRI2C_SLAVE_ADDR 0x12
26 #define OMAP3_VDD_MPU_SR_CONTROL_REG 0x00
27 #define OMAP3_VDD_CORE_SR_CONTROL_REG 0x01
28 #define OMAP3_VP_CONFIG_ERROROFFSET 0x00
29 #define OMAP3_VP_VSTEPMIN_VSTEPMIN 0x1
30 #define OMAP3_VP_VSTEPMAX_VSTEPMAX 0x04
31 #define OMAP3_VP_VLIMITTO_TIMEOUT_US 200
33 #define OMAP4_SRI2C_SLAVE_ADDR 0x12
34 #define OMAP4_VDD_MPU_SR_VOLT_REG 0x55
35 #define OMAP4_VDD_MPU_SR_CMD_REG 0x56
36 #define OMAP4_VDD_IVA_SR_VOLT_REG 0x5B
37 #define OMAP4_VDD_IVA_SR_CMD_REG 0x5C
38 #define OMAP4_VDD_CORE_SR_VOLT_REG 0x61
39 #define OMAP4_VDD_CORE_SR_CMD_REG 0x62
41 #define TWL6030_REG_VCORE1_CFG_GRP 0x52
42 #define TWL6030_REG_VCORE1_CFG_TRANS 0x53
43 #define TWL6030_REG_VCORE2_CFG_GRP 0x58
44 #define TWL6030_REG_VCORE2_CFG_TRANS 0x59
45 #define TWL6030_REG_VCORE3_CFG_GRP 0x5e
46 #define TWL6030_REG_VCORE3_CFG_TRANS 0x5f
47 #define TWL6030_BIT_APE_GRP BIT(0)
49 * Setup CFG_TRANS mode as follows:
50 * 0x00 (OFF) when in OFF state(bit offset 4) and in sleep (bit offset 2)
51 * 0x01 (PWM/PFM Auto) when in ACTive state (bit offset 0)
52 * Dont trust Bootloader or reset values to set them up for kernel.
54 #define TWL6030_REG_VCOREx_CFG_TRANS_MODE (0x00 << 4 | \
57 #define TWL6030_REG_VCOREx_CFG_TRANS_MODE_DESC "OFF=OFF SLEEP=OFF ACT=AUTO"
59 /* Pull down control */
60 #define TWL6030_REG_CFG_SMPS_PD 0xF6
62 static bool is_offset_valid
;
63 static u8 smps_offset
;
65 * Flag to ensure Smartreflex bit in TWL
66 * being cleared in board file is not overwritten.
68 static bool __initdata twl_sr_enable_autoinit
;
70 #define TWL4030_DCDC_GLOBAL_CFG 0x06
71 #define REG_SMPS_OFFSET 0xE0
72 #define SMARTREFLEX_ENABLE BIT(3)
75 * struct twl_reg_setup_array - NULL terminated array giving configuration
76 * @addr: reg address to write to
77 * @val: value to write with
78 * @desc: description of this reg for error printing
79 * NOTE: a NULL pointer in this indicates end of array.
81 * VCORE register configurations as per need.
83 struct twl_reg_setup_array
{
90 * _twl_set_regs() - helper to setup a config array
91 * @gendesc: generic description - used with error message
92 * @sarray: NULL terminated array of configuration values
94 * Configures TWL with a set of values terminated. If any write fails,
95 * this continues till the last and returns back with the last error
98 static int __init
_twl_set_regs(char *gendesc
,
99 struct twl_reg_setup_array
*sarray
)
105 while (sarray
->desc
) {
106 ret1
= twl_i2c_write_u8(TWL6030_MODULE_ID0
,
110 pr_err("%s: %s: failed(%d), array index=%d, desc=%s, "
111 "reg=0x%02x, val=0x%02x\n",
112 __func__
, gendesc
, ret1
, i
,
113 sarray
->desc
, sarray
->addr
, sarray
->val
);
123 static unsigned long twl4030_vsel_to_uv(const u8 vsel
)
125 return (((vsel
* 125) + 6000)) * 100;
128 static u8
twl4030_uv_to_vsel(unsigned long uv
)
130 return DIV_ROUND_UP(uv
- 600000, 12500);
133 static unsigned long twl6030_vsel_to_uv(const u8 vsel
)
136 * In TWL6030 depending on the value of SMPS_OFFSET
137 * efuse register the voltage range supported in
138 * standard mode can be either between 0.6V - 1.3V or
139 * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
140 * is programmed to all 0's where as starting from
141 * TWL6030 ES1.1 the efuse is programmed to 1
143 if (!is_offset_valid
) {
144 twl_i2c_read_u8(TWL6030_MODULE_ID0
, &smps_offset
,
146 is_offset_valid
= true;
152 * There is no specific formula for voltage to vsel
153 * conversion above 1.3V. There are special hardcoded
154 * values for voltages above 1.3V. Currently we are
155 * hardcoding only for 1.35 V which is used for 1GH OPP for
161 if (smps_offset
& 0x8)
162 return ((((vsel
- 1) * 1266) + 70900)) * 10;
164 return ((((vsel
- 1) * 1266) + 60770)) * 10;
167 static u8
twl6030_uv_to_vsel(unsigned long uv
)
170 * In TWL6030 depending on the value of SMPS_OFFSET
171 * efuse register the voltage range supported in
172 * standard mode can be either between 0.6V - 1.3V or
173 * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
174 * is programmed to all 0's where as starting from
175 * TWL6030 ES1.1 the efuse is programmed to 1
177 if (!is_offset_valid
) {
178 twl_i2c_read_u8(TWL6030_MODULE_ID0
, &smps_offset
,
180 is_offset_valid
= true;
186 * There is no specific formula for voltage to vsel
187 * conversion above 1.3V. There are special hardcoded
188 * values for voltages above 1.3V. Currently we are
189 * hardcoding only for 1.35 V which is used for 1GH OPP for
192 if (uv
> twl6030_vsel_to_uv(0x39)) {
195 pr_err("%s:OUT OF RANGE! non mapped vsel for %ld Vs max %ld\n",
196 __func__
, uv
, twl6030_vsel_to_uv(0x39));
200 if (smps_offset
& 0x8)
201 return DIV_ROUND_UP(uv
- 709000, 12660) + 1;
203 return DIV_ROUND_UP(uv
- 607700, 12660) + 1;
206 static struct omap_voltdm_pmic omap3_mpu_pmic
= {
210 .onlp_volt
= 1000000,
213 .volt_setup_time
= 0xfff,
214 .vp_erroroffset
= OMAP3_VP_CONFIG_ERROROFFSET
,
215 .vp_vstepmin
= OMAP3_VP_VSTEPMIN_VSTEPMIN
,
216 .vp_vstepmax
= OMAP3_VP_VSTEPMAX_VSTEPMAX
,
217 .vp_vddmin
= OMAP3430_VP1_VLIMITTO_VDDMIN
,
218 .vp_vddmax
= OMAP3430_VP1_VLIMITTO_VDDMAX
,
219 .vp_timeout_us
= OMAP3_VP_VLIMITTO_TIMEOUT_US
,
220 .i2c_slave_addr
= OMAP3_SRI2C_SLAVE_ADDR
,
221 .volt_reg_addr
= OMAP3_VDD_MPU_SR_CONTROL_REG
,
222 .i2c_high_speed
= true,
223 .vsel_to_uv
= twl4030_vsel_to_uv
,
224 .uv_to_vsel
= twl4030_uv_to_vsel
,
227 static struct omap_voltdm_pmic omap3_core_pmic
= {
231 .onlp_volt
= 1000000,
234 .volt_setup_time
= 0xfff,
235 .vp_erroroffset
= OMAP3_VP_CONFIG_ERROROFFSET
,
236 .vp_vstepmin
= OMAP3_VP_VSTEPMIN_VSTEPMIN
,
237 .vp_vstepmax
= OMAP3_VP_VSTEPMAX_VSTEPMAX
,
238 .vp_vddmin
= OMAP3430_VP2_VLIMITTO_VDDMIN
,
239 .vp_vddmax
= OMAP3430_VP2_VLIMITTO_VDDMAX
,
240 .vp_timeout_us
= OMAP3_VP_VLIMITTO_TIMEOUT_US
,
241 .i2c_slave_addr
= OMAP3_SRI2C_SLAVE_ADDR
,
242 .volt_reg_addr
= OMAP3_VDD_CORE_SR_CONTROL_REG
,
243 .i2c_high_speed
= true,
244 .vsel_to_uv
= twl4030_vsel_to_uv
,
245 .uv_to_vsel
= twl4030_uv_to_vsel
,
248 static struct omap_voltdm_pmic omap443x_mpu_pmic
= {
252 .onlp_volt
= 1375000,
255 .volt_setup_time
= 0,
256 .switch_on_time
= 549,
257 .vp_erroroffset
= OMAP4_VP_CONFIG_ERROROFFSET
,
258 .vp_vstepmin
= OMAP4_VP_VSTEPMIN_VSTEPMIN
,
259 .vp_vstepmax
= OMAP4_VP_VSTEPMAX_VSTEPMAX
,
260 .vp_vddmin
= OMAP4_VP_MPU_VLIMITTO_VDDMIN
,
261 .vp_vddmax
= OMAP4_VP_MPU_VLIMITTO_VDDMAX
,
262 .vp_timeout_us
= OMAP4_VP_VLIMITTO_TIMEOUT_US
,
263 .i2c_slave_addr
= OMAP4_SRI2C_SLAVE_ADDR
,
264 .volt_reg_addr
= OMAP4_VDD_MPU_SR_VOLT_REG
,
265 .cmd_reg_addr
= OMAP4_VDD_MPU_SR_CMD_REG
,
266 .i2c_high_speed
= true,
267 .i2c_scll_low
= 0x28,
268 .i2c_scll_high
= 0x2C,
269 .i2c_hscll_low
= 0x0B,
270 .i2c_hscll_high
= 0x00,
271 .vsel_to_uv
= twl6030_vsel_to_uv
,
272 .uv_to_vsel
= twl6030_uv_to_vsel
,
275 static struct omap_voltdm_pmic omap4_iva_pmic
= {
279 .onlp_volt
= 1188000,
282 .volt_setup_time
= 0,
283 .switch_on_time
= 549,
284 .vp_erroroffset
= OMAP4_VP_CONFIG_ERROROFFSET
,
285 .vp_vstepmin
= OMAP4_VP_VSTEPMIN_VSTEPMIN
,
286 .vp_vstepmax
= OMAP4_VP_VSTEPMAX_VSTEPMAX
,
287 .vp_vddmin
= OMAP4_VP_IVA_VLIMITTO_VDDMIN
,
288 .vp_vddmax
= OMAP4_VP_IVA_VLIMITTO_VDDMAX
,
289 .vp_timeout_us
= OMAP4_VP_VLIMITTO_TIMEOUT_US
,
290 .i2c_slave_addr
= OMAP4_SRI2C_SLAVE_ADDR
,
291 .volt_reg_addr
= OMAP4_VDD_IVA_SR_VOLT_REG
,
292 .cmd_reg_addr
= OMAP4_VDD_IVA_SR_CMD_REG
,
293 .i2c_high_speed
= true,
294 .i2c_scll_low
= 0x28,
295 .i2c_scll_high
= 0x2C,
296 .i2c_hscll_low
= 0x0B,
297 .i2c_hscll_high
= 0x00,
298 .vsel_to_uv
= twl6030_vsel_to_uv
,
299 .uv_to_vsel
= twl6030_uv_to_vsel
,
302 static struct omap_voltdm_pmic omap443x_core_pmic
= {
306 .onlp_volt
= 1200000,
309 .volt_setup_time
= 0,
310 .switch_on_time
= 549,
311 .vp_erroroffset
= OMAP4_VP_CONFIG_ERROROFFSET
,
312 .vp_vstepmin
= OMAP4_VP_VSTEPMIN_VSTEPMIN
,
313 .vp_vstepmax
= OMAP4_VP_VSTEPMAX_VSTEPMAX
,
314 .vp_vddmin
= OMAP4_VP_CORE_VLIMITTO_VDDMIN
,
315 .vp_vddmax
= OMAP4_VP_CORE_VLIMITTO_VDDMAX
,
316 .vp_timeout_us
= OMAP4_VP_VLIMITTO_TIMEOUT_US
,
317 .i2c_slave_addr
= OMAP4_SRI2C_SLAVE_ADDR
,
318 .i2c_high_speed
= true,
319 .i2c_scll_low
= 0x28,
320 .i2c_scll_high
= 0x2C,
321 .i2c_hscll_low
= 0x0B,
322 .i2c_hscll_high
= 0x00,
323 .volt_reg_addr
= OMAP4_VDD_CORE_SR_VOLT_REG
,
324 .cmd_reg_addr
= OMAP4_VDD_CORE_SR_CMD_REG
,
325 .vsel_to_uv
= twl6030_vsel_to_uv
,
326 .uv_to_vsel
= twl6030_uv_to_vsel
,
329 /* Core uses the MPU rail of 4430 */
330 static struct omap_voltdm_pmic omap446x_core_pmic
= {
334 .onlp_volt
= 1200000,
337 .volt_setup_time
= 0,
338 .switch_on_time
= 549,
339 .vp_erroroffset
= OMAP4_VP_CONFIG_ERROROFFSET
,
340 .vp_vstepmin
= OMAP4_VP_VSTEPMIN_VSTEPMIN
,
341 .vp_vstepmax
= OMAP4_VP_VSTEPMAX_VSTEPMAX
,
342 .vp_vddmin
= OMAP4_VP_CORE_VLIMITTO_VDDMIN
,
343 .vp_vddmax
= OMAP4_VP_CORE_VLIMITTO_VDDMAX
,
344 .vp_timeout_us
= OMAP4_VP_VLIMITTO_TIMEOUT_US
,
345 .i2c_slave_addr
= OMAP4_SRI2C_SLAVE_ADDR
,
346 .i2c_high_speed
= true,
347 .i2c_scll_low
= 0x28,
348 .i2c_scll_high
= 0x2C,
349 .i2c_hscll_low
= 0x0B,
350 .i2c_hscll_high
= 0x00,
351 .volt_reg_addr
= OMAP4_VDD_MPU_SR_VOLT_REG
,
352 .cmd_reg_addr
= OMAP4_VDD_MPU_SR_CMD_REG
,
353 .vsel_to_uv
= twl6030_vsel_to_uv
,
354 .uv_to_vsel
= twl6030_uv_to_vsel
,
357 static int __init
twl_set_sr(struct voltagedomain
*voltdm
)
362 * The smartreflex bit on twl4030 specifies if the setting of voltage
363 * is done over the I2C_SR path. Since this setting is independent of
364 * the actual usage of smartreflex AVS module, we enable TWL SR bit
365 * by default irrespective of whether smartreflex AVS module is enabled
366 * on the OMAP side or not. This is because without this bit enabled,
367 * the voltage scaling through vp forceupdate/bypass mechanism of
368 * voltage scaling will not function on TWL over I2C_SR.
370 if (!twl_sr_enable_autoinit
)
371 r
= omap3_twl_set_sr_bit(true);
376 /* OMAP4430 - All vcores: 1, 2 and 3 should go down with PREQ */
377 static __initdata
struct twl_reg_setup_array omap4430_twl6030_setup
[] = {
379 .addr
= TWL6030_REG_VCORE1_CFG_GRP
,
380 .val
= TWL6030_BIT_APE_GRP
,
381 .desc
= "Pull VCORE1 down along with App processor's PREQ1",
384 .addr
= TWL6030_REG_VCORE1_CFG_TRANS
,
385 .val
= TWL6030_REG_VCOREx_CFG_TRANS_MODE
,
386 .desc
= "VCORE1" TWL6030_REG_VCOREx_CFG_TRANS_MODE_DESC
,
389 .addr
= TWL6030_REG_VCORE2_CFG_GRP
,
390 .val
= TWL6030_BIT_APE_GRP
,
391 .desc
= "Pull VCORE2 down along with App processor's PREQ1",
394 .addr
= TWL6030_REG_VCORE2_CFG_TRANS
,
395 .val
= TWL6030_REG_VCOREx_CFG_TRANS_MODE
,
396 .desc
= "VCORE2" TWL6030_REG_VCOREx_CFG_TRANS_MODE_DESC
,
399 .addr
= TWL6030_REG_VCORE3_CFG_GRP
,
400 .val
= TWL6030_BIT_APE_GRP
,
401 .desc
= "Pull VCORE3 down along with App processor's PREQ1",
404 .addr
= TWL6030_REG_VCORE3_CFG_TRANS
,
405 .val
= TWL6030_REG_VCOREx_CFG_TRANS_MODE
,
406 .desc
= "VCORE3" TWL6030_REG_VCOREx_CFG_TRANS_MODE_DESC
,
408 { .desc
= NULL
} /* TERMINATOR */
411 static int __init
twl_set_4430vcore(struct voltagedomain
*voltdm
)
413 return _twl_set_regs("OMAP4430 ", omap4430_twl6030_setup
);
416 /* OMAP4460 - VCORE3 is unused, 1 and 2 should go down with PREQ */
417 static __initdata
struct twl_reg_setup_array omap4460_twl6030_setup
[] = {
419 .addr
= TWL6030_REG_VCORE1_CFG_GRP
,
420 .val
= TWL6030_BIT_APE_GRP
,
421 .desc
= "Pull VCORE1 down along with App processor's PREQ1",
424 .addr
= TWL6030_REG_VCORE1_CFG_TRANS
,
425 .val
= TWL6030_REG_VCOREx_CFG_TRANS_MODE
,
426 .desc
= "VCORE1" TWL6030_REG_VCOREx_CFG_TRANS_MODE_DESC
,
429 .addr
= TWL6030_REG_VCORE2_CFG_GRP
,
430 .val
= TWL6030_BIT_APE_GRP
,
431 .desc
= "Pull VCORE2 down along with App processor's PREQ1",
434 .addr
= TWL6030_REG_VCORE2_CFG_TRANS
,
435 .val
= TWL6030_REG_VCOREx_CFG_TRANS_MODE
,
436 .desc
= "VCORE2" TWL6030_REG_VCOREx_CFG_TRANS_MODE_DESC
,
439 .addr
= TWL6030_REG_CFG_SMPS_PD
,
441 .desc
= "VCORE1 disable PD on shutdown",
443 { .desc
= NULL
} /* TERMINATOR */
446 static int __init
twl_set_4460vcore(struct voltagedomain
*voltdm
)
448 return _twl_set_regs("OMAP4460 ", omap4460_twl6030_setup
);
451 #define OMAP3_TWL4030_USED (CHIP_GE_OMAP3430ES2 | \
452 CHIP_GE_OMAP3630ES1_1 | \
455 static __initdata
struct omap_pmic_map omap_twl_map
[] = {
458 .omap_chip
= OMAP_CHIP_INIT(OMAP3_TWL4030_USED
),
459 .pmic_data
= &omap3_mpu_pmic
,
460 .special_action
= twl_set_sr
,
464 .omap_chip
= OMAP_CHIP_INIT(OMAP3_TWL4030_USED
),
465 .pmic_data
= &omap3_core_pmic
,
469 .omap_chip
= OMAP_CHIP_INIT(CHIP_IS_OMAP443X
),
470 .pmic_data
= &omap443x_mpu_pmic
,
474 .omap_chip
= OMAP_CHIP_INIT(CHIP_IS_OMAP443X
),
475 .pmic_data
= &omap443x_core_pmic
,
476 .special_action
= twl_set_4430vcore
,
480 .omap_chip
= OMAP_CHIP_INIT(CHIP_IS_OMAP446X
),
481 .pmic_data
= &omap446x_core_pmic
,
482 .special_action
= twl_set_4460vcore
,
486 .omap_chip
= OMAP_CHIP_INIT(CHIP_IS_OMAP44XX
),
487 .pmic_data
= &omap4_iva_pmic
,
490 { .name
= NULL
, .pmic_data
= NULL
},
494 static __initdata
struct omap_pmic_description twl6030_pmic_desc
= {
495 .pmic_lp_tshut
= 1, /* T-OFF */
496 .pmic_lp_tstart
= 500, /* T-ON */
499 int __init
omap_twl_init(void)
501 struct omap_pmic_description
*desc
= NULL
;
503 /* Reuse OMAP3430 values */
504 if (cpu_is_omap3630()) {
505 omap3_mpu_pmic
.vp_vddmin
= OMAP3630_VP1_VLIMITTO_VDDMIN
;
506 omap3_mpu_pmic
.vp_vddmax
= OMAP3630_VP1_VLIMITTO_VDDMAX
;
507 omap3_core_pmic
.vp_vddmin
= OMAP3630_VP2_VLIMITTO_VDDMIN
;
508 omap3_core_pmic
.vp_vddmax
= OMAP3630_VP2_VLIMITTO_VDDMAX
;
510 if (cpu_is_omap44xx())
511 desc
= &twl6030_pmic_desc
;
513 return omap_pmic_register_data(omap_twl_map
, desc
);
517 * omap3_twl_set_sr_bit() - Set/Clear SR bit on TWL
518 * @enable: enable SR mode in twl or not
520 * If 'enable' is true, enables Smartreflex bit on TWL 4030 to make sure
521 * voltage scaling through OMAP SR works. Else, the smartreflex bit
522 * on twl4030 is cleared as there are platforms which use OMAP3 and T2 but
523 * use Synchronized Scaling Hardware Strategy (ENABLE_VMODE=1) and Direct
524 * Strategy Software Scaling Mode (ENABLE_VMODE=0), for setting the voltages,
525 * in those scenarios this bit is to be cleared (enable = false).
527 * Returns 0 on success, error is returned if I2C read/write fails.
529 int __init
omap3_twl_set_sr_bit(bool enable
)
533 if (twl_sr_enable_autoinit
)
534 pr_warning("%s: unexpected multiple calls\n", __func__
);
536 ret
= twl_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER
, &temp
,
537 TWL4030_DCDC_GLOBAL_CFG
);
542 temp
|= SMARTREFLEX_ENABLE
;
544 temp
&= ~SMARTREFLEX_ENABLE
;
546 ret
= twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER
, temp
,
547 TWL4030_DCDC_GLOBAL_CFG
);
549 twl_sr_enable_autoinit
= true;
553 pr_err("%s: Error access to TWL4030 (%d)\n", __func__
, ret
);
557 int __init
omap_twl_pmic_update(char *name
, u32 old_chip_id
, u32 new_chip_id
)
559 return omap_pmic_update(omap_twl_map
, name
, old_chip_id
, new_chip_id
);