1 // SPDX-License-Identifier: GPL-2.0-only
3 * OMAP and TWL PMIC specific initializations.
5 * Copyright (C) 2010 Texas Instruments Incorporated.
7 * Copyright (C) 2009 Texas Instruments Incorporated.
9 * Copyright (C) 2009 Nokia Corporation
13 #include <linux/err.h>
15 #include <linux/kernel.h>
16 #include <linux/mfd/twl.h>
23 #define OMAP3_SRI2C_SLAVE_ADDR 0x12
24 #define OMAP3_VDD_MPU_SR_CONTROL_REG 0x00
25 #define OMAP3_VDD_CORE_SR_CONTROL_REG 0x01
26 #define OMAP3_VP_CONFIG_ERROROFFSET 0x00
27 #define OMAP3_VP_VSTEPMIN_VSTEPMIN 0x1
28 #define OMAP3_VP_VSTEPMAX_VSTEPMAX 0x04
29 #define OMAP3_VP_VLIMITTO_TIMEOUT_US 200
31 #define OMAP4_SRI2C_SLAVE_ADDR 0x12
32 #define OMAP4_VDD_MPU_SR_VOLT_REG 0x55
33 #define OMAP4_VDD_MPU_SR_CMD_REG 0x56
34 #define OMAP4_VDD_IVA_SR_VOLT_REG 0x5B
35 #define OMAP4_VDD_IVA_SR_CMD_REG 0x5C
36 #define OMAP4_VDD_CORE_SR_VOLT_REG 0x61
37 #define OMAP4_VDD_CORE_SR_CMD_REG 0x62
39 static bool is_offset_valid
;
40 static u8 smps_offset
;
42 #define REG_SMPS_OFFSET 0xE0
44 static unsigned long twl4030_vsel_to_uv(const u8 vsel
)
46 return (((vsel
* 125) + 6000)) * 100;
49 static u8
twl4030_uv_to_vsel(unsigned long uv
)
51 return DIV_ROUND_UP(uv
- 600000, 12500);
54 static unsigned long twl6030_vsel_to_uv(const u8 vsel
)
57 * In TWL6030 depending on the value of SMPS_OFFSET
58 * efuse register the voltage range supported in
59 * standard mode can be either between 0.6V - 1.3V or
60 * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
61 * is programmed to all 0's where as starting from
62 * TWL6030 ES1.1 the efuse is programmed to 1
64 if (!is_offset_valid
) {
65 twl_i2c_read_u8(TWL6030_MODULE_ID0
, &smps_offset
,
67 is_offset_valid
= true;
73 * There is no specific formula for voltage to vsel
74 * conversion above 1.3V. There are special hardcoded
75 * values for voltages above 1.3V. Currently we are
76 * hardcoding only for 1.35 V which is used for 1GH OPP for
82 if (smps_offset
& 0x8)
83 return ((((vsel
- 1) * 1266) + 70900)) * 10;
85 return ((((vsel
- 1) * 1266) + 60770)) * 10;
88 static u8
twl6030_uv_to_vsel(unsigned long uv
)
91 * In TWL6030 depending on the value of SMPS_OFFSET
92 * efuse register the voltage range supported in
93 * standard mode can be either between 0.6V - 1.3V or
94 * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
95 * is programmed to all 0's where as starting from
96 * TWL6030 ES1.1 the efuse is programmed to 1
98 if (!is_offset_valid
) {
99 twl_i2c_read_u8(TWL6030_MODULE_ID0
, &smps_offset
,
101 is_offset_valid
= true;
107 * There is no specific formula for voltage to vsel
108 * conversion above 1.3V. There are special hardcoded
109 * values for voltages above 1.3V. Currently we are
110 * hardcoding only for 1.35 V which is used for 1GH OPP for
113 if (uv
> twl6030_vsel_to_uv(0x39)) {
116 pr_err("%s:OUT OF RANGE! non mapped vsel for %ld Vs max %ld\n",
117 __func__
, uv
, twl6030_vsel_to_uv(0x39));
121 if (smps_offset
& 0x8)
122 return DIV_ROUND_UP(uv
- 709000, 12660) + 1;
124 return DIV_ROUND_UP(uv
- 607700, 12660) + 1;
127 static struct omap_voltdm_pmic omap3_mpu_pmic
= {
130 .vp_erroroffset
= OMAP3_VP_CONFIG_ERROROFFSET
,
131 .vp_vstepmin
= OMAP3_VP_VSTEPMIN_VSTEPMIN
,
132 .vp_vstepmax
= OMAP3_VP_VSTEPMAX_VSTEPMAX
,
135 .vp_timeout_us
= OMAP3_VP_VLIMITTO_TIMEOUT_US
,
136 .i2c_slave_addr
= OMAP3_SRI2C_SLAVE_ADDR
,
137 .volt_reg_addr
= OMAP3_VDD_MPU_SR_CONTROL_REG
,
138 .i2c_high_speed
= true,
139 .vsel_to_uv
= twl4030_vsel_to_uv
,
140 .uv_to_vsel
= twl4030_uv_to_vsel
,
143 static struct omap_voltdm_pmic omap3_core_pmic
= {
146 .vp_erroroffset
= OMAP3_VP_CONFIG_ERROROFFSET
,
147 .vp_vstepmin
= OMAP3_VP_VSTEPMIN_VSTEPMIN
,
148 .vp_vstepmax
= OMAP3_VP_VSTEPMAX_VSTEPMAX
,
151 .vp_timeout_us
= OMAP3_VP_VLIMITTO_TIMEOUT_US
,
152 .i2c_slave_addr
= OMAP3_SRI2C_SLAVE_ADDR
,
153 .volt_reg_addr
= OMAP3_VDD_CORE_SR_CONTROL_REG
,
154 .i2c_high_speed
= true,
155 .vsel_to_uv
= twl4030_vsel_to_uv
,
156 .uv_to_vsel
= twl4030_uv_to_vsel
,
159 static struct omap_voltdm_pmic omap4_mpu_pmic
= {
162 .vp_erroroffset
= OMAP4_VP_CONFIG_ERROROFFSET
,
163 .vp_vstepmin
= OMAP4_VP_VSTEPMIN_VSTEPMIN
,
164 .vp_vstepmax
= OMAP4_VP_VSTEPMAX_VSTEPMAX
,
167 .vp_timeout_us
= OMAP4_VP_VLIMITTO_TIMEOUT_US
,
168 .i2c_slave_addr
= OMAP4_SRI2C_SLAVE_ADDR
,
169 .volt_reg_addr
= OMAP4_VDD_MPU_SR_VOLT_REG
,
170 .cmd_reg_addr
= OMAP4_VDD_MPU_SR_CMD_REG
,
171 .i2c_high_speed
= true,
173 .vsel_to_uv
= twl6030_vsel_to_uv
,
174 .uv_to_vsel
= twl6030_uv_to_vsel
,
177 static struct omap_voltdm_pmic omap4_iva_pmic
= {
180 .vp_erroroffset
= OMAP4_VP_CONFIG_ERROROFFSET
,
181 .vp_vstepmin
= OMAP4_VP_VSTEPMIN_VSTEPMIN
,
182 .vp_vstepmax
= OMAP4_VP_VSTEPMAX_VSTEPMAX
,
185 .vp_timeout_us
= OMAP4_VP_VLIMITTO_TIMEOUT_US
,
186 .i2c_slave_addr
= OMAP4_SRI2C_SLAVE_ADDR
,
187 .volt_reg_addr
= OMAP4_VDD_IVA_SR_VOLT_REG
,
188 .cmd_reg_addr
= OMAP4_VDD_IVA_SR_CMD_REG
,
189 .i2c_high_speed
= true,
191 .vsel_to_uv
= twl6030_vsel_to_uv
,
192 .uv_to_vsel
= twl6030_uv_to_vsel
,
195 static struct omap_voltdm_pmic omap4_core_pmic
= {
198 .vp_erroroffset
= OMAP4_VP_CONFIG_ERROROFFSET
,
199 .vp_vstepmin
= OMAP4_VP_VSTEPMIN_VSTEPMIN
,
200 .vp_vstepmax
= OMAP4_VP_VSTEPMAX_VSTEPMAX
,
203 .vp_timeout_us
= OMAP4_VP_VLIMITTO_TIMEOUT_US
,
204 .i2c_slave_addr
= OMAP4_SRI2C_SLAVE_ADDR
,
205 .volt_reg_addr
= OMAP4_VDD_CORE_SR_VOLT_REG
,
206 .cmd_reg_addr
= OMAP4_VDD_CORE_SR_CMD_REG
,
207 .i2c_high_speed
= true,
209 .vsel_to_uv
= twl6030_vsel_to_uv
,
210 .uv_to_vsel
= twl6030_uv_to_vsel
,
213 int __init
omap4_twl_init(void)
215 struct voltagedomain
*voltdm
;
217 if (!cpu_is_omap44xx() ||
218 of_find_compatible_node(NULL
, NULL
, "motorola,cpcap"))
221 voltdm
= voltdm_lookup("mpu");
222 omap_voltage_register_pmic(voltdm
, &omap4_mpu_pmic
);
224 voltdm
= voltdm_lookup("iva");
225 omap_voltage_register_pmic(voltdm
, &omap4_iva_pmic
);
227 voltdm
= voltdm_lookup("core");
228 omap_voltage_register_pmic(voltdm
, &omap4_core_pmic
);
233 int __init
omap3_twl_init(void)
235 struct voltagedomain
*voltdm
;
237 if (!cpu_is_omap34xx())
240 voltdm
= voltdm_lookup("mpu_iva");
241 omap_voltage_register_pmic(voltdm
, &omap3_mpu_pmic
);
243 voltdm
= voltdm_lookup("core");
244 omap_voltage_register_pmic(voltdm
, &omap3_core_pmic
);