2 * OMAP and TWL PMIC specific initializations.
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/mfd/twl.h>
26 #define OMAP3_SRI2C_SLAVE_ADDR 0x12
27 #define OMAP3_VDD_MPU_SR_CONTROL_REG 0x00
28 #define OMAP3_VDD_CORE_SR_CONTROL_REG 0x01
29 #define OMAP3_VP_CONFIG_ERROROFFSET 0x00
30 #define OMAP3_VP_VSTEPMIN_VSTEPMIN 0x1
31 #define OMAP3_VP_VSTEPMAX_VSTEPMAX 0x04
32 #define OMAP3_VP_VLIMITTO_TIMEOUT_US 200
34 #define OMAP4_SRI2C_SLAVE_ADDR 0x12
35 #define OMAP4_VDD_MPU_SR_VOLT_REG 0x55
36 #define OMAP4_VDD_MPU_SR_CMD_REG 0x56
37 #define OMAP4_VDD_IVA_SR_VOLT_REG 0x5B
38 #define OMAP4_VDD_IVA_SR_CMD_REG 0x5C
39 #define OMAP4_VDD_CORE_SR_VOLT_REG 0x61
40 #define OMAP4_VDD_CORE_SR_CMD_REG 0x62
42 #define OMAP4_VP_CONFIG_ERROROFFSET 0x00
43 #define OMAP4_VP_VSTEPMIN_VSTEPMIN 0x01
44 #define OMAP4_VP_VSTEPMAX_VSTEPMAX 0x04
45 #define OMAP4_VP_VLIMITTO_TIMEOUT_US 200
47 static bool is_offset_valid
;
48 static u8 smps_offset
;
50 #define REG_SMPS_OFFSET 0xE0
52 static unsigned long twl4030_vsel_to_uv(const u8 vsel
)
54 return (((vsel
* 125) + 6000)) * 100;
57 static u8
twl4030_uv_to_vsel(unsigned long uv
)
59 return DIV_ROUND_UP(uv
- 600000, 12500);
62 static unsigned long twl6030_vsel_to_uv(const u8 vsel
)
65 * In TWL6030 depending on the value of SMPS_OFFSET
66 * efuse register the voltage range supported in
67 * standard mode can be either between 0.6V - 1.3V or
68 * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
69 * is programmed to all 0's where as starting from
70 * TWL6030 ES1.1 the efuse is programmed to 1
72 if (!is_offset_valid
) {
73 twl_i2c_read_u8(TWL6030_MODULE_ID0
, &smps_offset
,
75 is_offset_valid
= true;
81 * There is no specific formula for voltage to vsel
82 * conversion above 1.3V. There are special hardcoded
83 * values for voltages above 1.3V. Currently we are
84 * hardcoding only for 1.35 V which is used for 1GH OPP for
90 if (smps_offset
& 0x8)
91 return ((((vsel
- 1) * 1266) + 70900)) * 10;
93 return ((((vsel
- 1) * 1266) + 60770)) * 10;
96 static u8
twl6030_uv_to_vsel(unsigned long uv
)
99 * In TWL6030 depending on the value of SMPS_OFFSET
100 * efuse register the voltage range supported in
101 * standard mode can be either between 0.6V - 1.3V or
102 * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
103 * is programmed to all 0's where as starting from
104 * TWL6030 ES1.1 the efuse is programmed to 1
106 if (!is_offset_valid
) {
107 twl_i2c_read_u8(TWL6030_MODULE_ID0
, &smps_offset
,
109 is_offset_valid
= true;
115 * There is no specific formula for voltage to vsel
116 * conversion above 1.3V. There are special hardcoded
117 * values for voltages above 1.3V. Currently we are
118 * hardcoding only for 1.35 V which is used for 1GH OPP for
121 if (uv
> twl6030_vsel_to_uv(0x39)) {
124 pr_err("%s:OUT OF RANGE! non mapped vsel for %ld Vs max %ld\n",
125 __func__
, uv
, twl6030_vsel_to_uv(0x39));
129 if (smps_offset
& 0x8)
130 return DIV_ROUND_UP(uv
- 709000, 12660) + 1;
132 return DIV_ROUND_UP(uv
- 607700, 12660) + 1;
135 static struct omap_voltdm_pmic omap3_mpu_pmic
= {
138 .vp_erroroffset
= OMAP3_VP_CONFIG_ERROROFFSET
,
139 .vp_vstepmin
= OMAP3_VP_VSTEPMIN_VSTEPMIN
,
140 .vp_vstepmax
= OMAP3_VP_VSTEPMAX_VSTEPMAX
,
143 .vp_timeout_us
= OMAP3_VP_VLIMITTO_TIMEOUT_US
,
144 .i2c_slave_addr
= OMAP3_SRI2C_SLAVE_ADDR
,
145 .volt_reg_addr
= OMAP3_VDD_MPU_SR_CONTROL_REG
,
146 .i2c_high_speed
= true,
147 .vsel_to_uv
= twl4030_vsel_to_uv
,
148 .uv_to_vsel
= twl4030_uv_to_vsel
,
151 static struct omap_voltdm_pmic omap3_core_pmic
= {
154 .vp_erroroffset
= OMAP3_VP_CONFIG_ERROROFFSET
,
155 .vp_vstepmin
= OMAP3_VP_VSTEPMIN_VSTEPMIN
,
156 .vp_vstepmax
= OMAP3_VP_VSTEPMAX_VSTEPMAX
,
159 .vp_timeout_us
= OMAP3_VP_VLIMITTO_TIMEOUT_US
,
160 .i2c_slave_addr
= OMAP3_SRI2C_SLAVE_ADDR
,
161 .volt_reg_addr
= OMAP3_VDD_CORE_SR_CONTROL_REG
,
162 .i2c_high_speed
= true,
163 .vsel_to_uv
= twl4030_vsel_to_uv
,
164 .uv_to_vsel
= twl4030_uv_to_vsel
,
167 static struct omap_voltdm_pmic omap4_mpu_pmic
= {
170 .vp_erroroffset
= OMAP4_VP_CONFIG_ERROROFFSET
,
171 .vp_vstepmin
= OMAP4_VP_VSTEPMIN_VSTEPMIN
,
172 .vp_vstepmax
= OMAP4_VP_VSTEPMAX_VSTEPMAX
,
175 .vp_timeout_us
= OMAP4_VP_VLIMITTO_TIMEOUT_US
,
176 .i2c_slave_addr
= OMAP4_SRI2C_SLAVE_ADDR
,
177 .volt_reg_addr
= OMAP4_VDD_MPU_SR_VOLT_REG
,
178 .cmd_reg_addr
= OMAP4_VDD_MPU_SR_CMD_REG
,
179 .i2c_high_speed
= true,
181 .vsel_to_uv
= twl6030_vsel_to_uv
,
182 .uv_to_vsel
= twl6030_uv_to_vsel
,
185 static struct omap_voltdm_pmic omap4_iva_pmic
= {
188 .vp_erroroffset
= OMAP4_VP_CONFIG_ERROROFFSET
,
189 .vp_vstepmin
= OMAP4_VP_VSTEPMIN_VSTEPMIN
,
190 .vp_vstepmax
= OMAP4_VP_VSTEPMAX_VSTEPMAX
,
193 .vp_timeout_us
= OMAP4_VP_VLIMITTO_TIMEOUT_US
,
194 .i2c_slave_addr
= OMAP4_SRI2C_SLAVE_ADDR
,
195 .volt_reg_addr
= OMAP4_VDD_IVA_SR_VOLT_REG
,
196 .cmd_reg_addr
= OMAP4_VDD_IVA_SR_CMD_REG
,
197 .i2c_high_speed
= true,
199 .vsel_to_uv
= twl6030_vsel_to_uv
,
200 .uv_to_vsel
= twl6030_uv_to_vsel
,
203 static struct omap_voltdm_pmic omap4_core_pmic
= {
206 .vp_erroroffset
= OMAP4_VP_CONFIG_ERROROFFSET
,
207 .vp_vstepmin
= OMAP4_VP_VSTEPMIN_VSTEPMIN
,
208 .vp_vstepmax
= OMAP4_VP_VSTEPMAX_VSTEPMAX
,
211 .vp_timeout_us
= OMAP4_VP_VLIMITTO_TIMEOUT_US
,
212 .i2c_slave_addr
= OMAP4_SRI2C_SLAVE_ADDR
,
213 .volt_reg_addr
= OMAP4_VDD_CORE_SR_VOLT_REG
,
214 .cmd_reg_addr
= OMAP4_VDD_CORE_SR_CMD_REG
,
215 .i2c_high_speed
= true,
217 .vsel_to_uv
= twl6030_vsel_to_uv
,
218 .uv_to_vsel
= twl6030_uv_to_vsel
,
221 int __init
omap4_twl_init(void)
223 struct voltagedomain
*voltdm
;
225 if (!cpu_is_omap44xx())
228 voltdm
= voltdm_lookup("mpu");
229 omap_voltage_register_pmic(voltdm
, &omap4_mpu_pmic
);
231 voltdm
= voltdm_lookup("iva");
232 omap_voltage_register_pmic(voltdm
, &omap4_iva_pmic
);
234 voltdm
= voltdm_lookup("core");
235 omap_voltage_register_pmic(voltdm
, &omap4_core_pmic
);
240 int __init
omap3_twl_init(void)
242 struct voltagedomain
*voltdm
;
244 if (!cpu_is_omap34xx())
247 voltdm
= voltdm_lookup("mpu_iva");
248 omap_voltage_register_pmic(voltdm
, &omap3_mpu_pmic
);
250 voltdm
= voltdm_lookup("core");
251 omap_voltage_register_pmic(voltdm
, &omap3_core_pmic
);