blob: b30adf349b73f100e4a9404d1edd9bbf9881fca8 [file] [log] [blame]
Thara Gopinathfbc319f2010-12-10 22:51:05 +05301/**
2 * OMAP and TWL PMIC specific intializations.
3 *
4 * Copyright (C) 2010 Texas Instruments Incorporated.
5 * Thara Gopinath
6 * Copyright (C) 2009 Texas Instruments Incorporated.
7 * Nishanth Menon
8 * Copyright (C) 2009 Nokia Corporation
9 * Paul Walmsley
10 *
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.
14 */
15
16#include <linux/err.h>
17#include <linux/io.h>
18#include <linux/kernel.h>
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053019#include <linux/i2c/twl.h>
Thara Gopinathfbc319f2010-12-10 22:51:05 +053020
Paul Walmsleye1d6f472011-02-25 15:54:33 -070021#include "voltage.h"
Thara Gopinathfbc319f2010-12-10 22:51:05 +053022
Nishanth Menondda0aea2011-01-03 12:58:30 -060023#include "pm.h"
24
Thara Gopinathfbc319f2010-12-10 22:51:05 +053025#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
32
33#define OMAP3430_VP1_VLIMITTO_VDDMIN 0x14
34#define OMAP3430_VP1_VLIMITTO_VDDMAX 0x42
35#define OMAP3430_VP2_VLIMITTO_VDDMIN 0x18
36#define OMAP3430_VP2_VLIMITTO_VDDMAX 0x2c
37
38#define OMAP3630_VP1_VLIMITTO_VDDMIN 0x18
39#define OMAP3630_VP1_VLIMITTO_VDDMAX 0x3c
40#define OMAP3630_VP2_VLIMITTO_VDDMIN 0x18
41#define OMAP3630_VP2_VLIMITTO_VDDMAX 0x30
42
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053043#define OMAP4_SRI2C_SLAVE_ADDR 0x12
44#define OMAP4_VDD_MPU_SR_VOLT_REG 0x55
45#define OMAP4_VDD_IVA_SR_VOLT_REG 0x5B
46#define OMAP4_VDD_CORE_SR_VOLT_REG 0x61
47
48#define OMAP4_VP_CONFIG_ERROROFFSET 0x00
49#define OMAP4_VP_VSTEPMIN_VSTEPMIN 0x01
50#define OMAP4_VP_VSTEPMAX_VSTEPMAX 0x04
51#define OMAP4_VP_VLIMITTO_TIMEOUT_US 200
52
53#define OMAP4_VP_MPU_VLIMITTO_VDDMIN 0xA
54#define OMAP4_VP_MPU_VLIMITTO_VDDMAX 0x39
55#define OMAP4_VP_IVA_VLIMITTO_VDDMIN 0xA
56#define OMAP4_VP_IVA_VLIMITTO_VDDMAX 0x2D
57#define OMAP4_VP_CORE_VLIMITTO_VDDMIN 0xA
58#define OMAP4_VP_CORE_VLIMITTO_VDDMAX 0x28
59
60static bool is_offset_valid;
61static u8 smps_offset;
Thara Gopinath40713182011-02-15 13:28:58 +053062/*
63 * Flag to ensure Smartreflex bit in TWL
64 * being cleared in board file is not overwritten.
65 */
66static bool __initdata twl_sr_enable_autoinit;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053067
Thara Gopinath40713182011-02-15 13:28:58 +053068#define TWL4030_DCDC_GLOBAL_CFG 0x06
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053069#define REG_SMPS_OFFSET 0xE0
Thara Gopinath40713182011-02-15 13:28:58 +053070#define SMARTREFLEX_ENABLE BIT(3)
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053071
Nishanth Menonc84ff1c2011-01-03 12:58:29 -060072static unsigned long twl4030_vsel_to_uv(const u8 vsel)
Thara Gopinathfbc319f2010-12-10 22:51:05 +053073{
74 return (((vsel * 125) + 6000)) * 100;
75}
76
Nishanth Menonc84ff1c2011-01-03 12:58:29 -060077static u8 twl4030_uv_to_vsel(unsigned long uv)
Thara Gopinathfbc319f2010-12-10 22:51:05 +053078{
79 return DIV_ROUND_UP(uv - 600000, 12500);
80}
81
Nishanth Menonc84ff1c2011-01-03 12:58:29 -060082static unsigned long twl6030_vsel_to_uv(const u8 vsel)
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053083{
84 /*
85 * In TWL6030 depending on the value of SMPS_OFFSET
86 * efuse register the voltage range supported in
87 * standard mode can be either between 0.6V - 1.3V or
88 * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
89 * is programmed to all 0's where as starting from
90 * TWL6030 ES1.1 the efuse is programmed to 1
91 */
92 if (!is_offset_valid) {
93 twl_i2c_read_u8(TWL6030_MODULE_ID0, &smps_offset,
94 REG_SMPS_OFFSET);
95 is_offset_valid = true;
96 }
97
Nishanth Menon2aed5b92011-05-18 00:17:32 -050098 if (!vsel)
99 return 0;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530100 /*
101 * There is no specific formula for voltage to vsel
102 * conversion above 1.3V. There are special hardcoded
103 * values for voltages above 1.3V. Currently we are
104 * hardcoding only for 1.35 V which is used for 1GH OPP for
105 * OMAP4430.
106 */
107 if (vsel == 0x3A)
108 return 1350000;
109
110 if (smps_offset & 0x8)
Patrick Titiano58e241f2011-05-18 00:17:30 -0500111 return ((((vsel - 1) * 1266) + 70900)) * 10;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530112 else
Patrick Titiano58e241f2011-05-18 00:17:30 -0500113 return ((((vsel - 1) * 1266) + 60770)) * 10;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530114}
115
Nishanth Menonc84ff1c2011-01-03 12:58:29 -0600116static u8 twl6030_uv_to_vsel(unsigned long uv)
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530117{
118 /*
119 * In TWL6030 depending on the value of SMPS_OFFSET
120 * efuse register the voltage range supported in
121 * standard mode can be either between 0.6V - 1.3V or
122 * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
123 * is programmed to all 0's where as starting from
124 * TWL6030 ES1.1 the efuse is programmed to 1
125 */
126 if (!is_offset_valid) {
127 twl_i2c_read_u8(TWL6030_MODULE_ID0, &smps_offset,
128 REG_SMPS_OFFSET);
129 is_offset_valid = true;
130 }
131
Nishanth Menon2aed5b92011-05-18 00:17:32 -0500132 if (!uv)
133 return 0x00;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530134 /*
135 * There is no specific formula for voltage to vsel
136 * conversion above 1.3V. There are special hardcoded
137 * values for voltages above 1.3V. Currently we are
138 * hardcoding only for 1.35 V which is used for 1GH OPP for
139 * OMAP4430.
140 */
Nishanth Menon36649422011-05-18 00:17:31 -0500141 if (uv > twl6030_vsel_to_uv(0x39)) {
142 if (uv == 1350000)
143 return 0x3A;
144 pr_err("%s:OUT OF RANGE! non mapped vsel for %ld Vs max %ld\n",
145 __func__, uv, twl6030_vsel_to_uv(0x39));
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530146 return 0x3A;
Nishanth Menon36649422011-05-18 00:17:31 -0500147 }
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530148
149 if (smps_offset & 0x8)
Patrick Titiano58e241f2011-05-18 00:17:30 -0500150 return DIV_ROUND_UP(uv - 709000, 12660) + 1;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530151 else
Patrick Titiano58e241f2011-05-18 00:17:30 -0500152 return DIV_ROUND_UP(uv - 607700, 12660) + 1;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530153}
154
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700155static struct omap_voltdm_pmic omap3_mpu_pmic = {
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530156 .slew_rate = 4000,
157 .step_size = 12500,
158 .on_volt = 1200000,
159 .onlp_volt = 1000000,
160 .ret_volt = 975000,
161 .off_volt = 600000,
162 .volt_setup_time = 0xfff,
163 .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
164 .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
165 .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
166 .vp_vddmin = OMAP3430_VP1_VLIMITTO_VDDMIN,
167 .vp_vddmax = OMAP3430_VP1_VLIMITTO_VDDMAX,
168 .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
169 .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700170 .volt_reg_addr = OMAP3_VDD_MPU_SR_CONTROL_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700171 .i2c_high_speed = true,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530172 .vsel_to_uv = twl4030_vsel_to_uv,
173 .uv_to_vsel = twl4030_uv_to_vsel,
174};
175
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700176static struct omap_voltdm_pmic omap3_core_pmic = {
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530177 .slew_rate = 4000,
178 .step_size = 12500,
179 .on_volt = 1200000,
180 .onlp_volt = 1000000,
181 .ret_volt = 975000,
182 .off_volt = 600000,
183 .volt_setup_time = 0xfff,
184 .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
185 .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
186 .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
187 .vp_vddmin = OMAP3430_VP2_VLIMITTO_VDDMIN,
188 .vp_vddmax = OMAP3430_VP2_VLIMITTO_VDDMAX,
189 .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
190 .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700191 .volt_reg_addr = OMAP3_VDD_CORE_SR_CONTROL_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700192 .i2c_high_speed = true,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530193 .vsel_to_uv = twl4030_vsel_to_uv,
194 .uv_to_vsel = twl4030_uv_to_vsel,
195};
196
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700197static struct omap_voltdm_pmic omap4_mpu_pmic = {
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530198 .slew_rate = 4000,
Patrick Titiano58e241f2011-05-18 00:17:30 -0500199 .step_size = 12660,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530200 .on_volt = 1350000,
201 .onlp_volt = 1350000,
202 .ret_volt = 837500,
203 .off_volt = 600000,
204 .volt_setup_time = 0,
205 .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
206 .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
207 .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
208 .vp_vddmin = OMAP4_VP_MPU_VLIMITTO_VDDMIN,
209 .vp_vddmax = OMAP4_VP_MPU_VLIMITTO_VDDMAX,
210 .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
211 .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700212 .volt_reg_addr = OMAP4_VDD_MPU_SR_VOLT_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700213 .i2c_high_speed = true,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530214 .vsel_to_uv = twl6030_vsel_to_uv,
215 .uv_to_vsel = twl6030_uv_to_vsel,
216};
217
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700218static struct omap_voltdm_pmic omap4_iva_pmic = {
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530219 .slew_rate = 4000,
Patrick Titiano58e241f2011-05-18 00:17:30 -0500220 .step_size = 12660,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530221 .on_volt = 1100000,
222 .onlp_volt = 1100000,
223 .ret_volt = 837500,
224 .off_volt = 600000,
225 .volt_setup_time = 0,
226 .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
227 .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
228 .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
229 .vp_vddmin = OMAP4_VP_IVA_VLIMITTO_VDDMIN,
230 .vp_vddmax = OMAP4_VP_IVA_VLIMITTO_VDDMAX,
231 .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
232 .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700233 .volt_reg_addr = OMAP4_VDD_IVA_SR_VOLT_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700234 .i2c_high_speed = true,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530235 .vsel_to_uv = twl6030_vsel_to_uv,
236 .uv_to_vsel = twl6030_uv_to_vsel,
237};
238
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700239static struct omap_voltdm_pmic omap4_core_pmic = {
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530240 .slew_rate = 4000,
Patrick Titiano58e241f2011-05-18 00:17:30 -0500241 .step_size = 12660,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530242 .on_volt = 1100000,
243 .onlp_volt = 1100000,
244 .ret_volt = 837500,
245 .off_volt = 600000,
246 .volt_setup_time = 0,
247 .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
248 .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
249 .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
250 .vp_vddmin = OMAP4_VP_CORE_VLIMITTO_VDDMIN,
251 .vp_vddmax = OMAP4_VP_CORE_VLIMITTO_VDDMAX,
252 .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
253 .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700254 .volt_reg_addr = OMAP4_VDD_CORE_SR_VOLT_REG,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530255 .vsel_to_uv = twl6030_vsel_to_uv,
256 .uv_to_vsel = twl6030_uv_to_vsel,
257};
258
259int __init omap4_twl_init(void)
260{
261 struct voltagedomain *voltdm;
262
263 if (!cpu_is_omap44xx())
264 return -ENODEV;
265
Kevin Hilman81a60482011-03-16 14:25:45 -0700266 voltdm = voltdm_lookup("mpu");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700267 omap_voltage_register_pmic(voltdm, &omap4_mpu_pmic);
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530268
Kevin Hilman81a60482011-03-16 14:25:45 -0700269 voltdm = voltdm_lookup("iva");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700270 omap_voltage_register_pmic(voltdm, &omap4_iva_pmic);
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530271
Kevin Hilman81a60482011-03-16 14:25:45 -0700272 voltdm = voltdm_lookup("core");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700273 omap_voltage_register_pmic(voltdm, &omap4_core_pmic);
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530274
275 return 0;
276}
277
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530278int __init omap3_twl_init(void)
279{
280 struct voltagedomain *voltdm;
281
282 if (!cpu_is_omap34xx())
283 return -ENODEV;
284
285 if (cpu_is_omap3630()) {
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700286 omap3_mpu_pmic.vp_vddmin = OMAP3630_VP1_VLIMITTO_VDDMIN;
287 omap3_mpu_pmic.vp_vddmax = OMAP3630_VP1_VLIMITTO_VDDMAX;
288 omap3_core_pmic.vp_vddmin = OMAP3630_VP2_VLIMITTO_VDDMIN;
289 omap3_core_pmic.vp_vddmax = OMAP3630_VP2_VLIMITTO_VDDMAX;
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530290 }
291
Thara Gopinath40713182011-02-15 13:28:58 +0530292 /*
293 * The smartreflex bit on twl4030 specifies if the setting of voltage
294 * is done over the I2C_SR path. Since this setting is independent of
295 * the actual usage of smartreflex AVS module, we enable TWL SR bit
296 * by default irrespective of whether smartreflex AVS module is enabled
297 * on the OMAP side or not. This is because without this bit enabled,
298 * the voltage scaling through vp forceupdate/bypass mechanism of
299 * voltage scaling will not function on TWL over I2C_SR.
300 */
301 if (!twl_sr_enable_autoinit)
302 omap3_twl_set_sr_bit(true);
303
Kevin Hilman280a7272011-03-23 11:18:08 -0700304 voltdm = voltdm_lookup("mpu_iva");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700305 omap_voltage_register_pmic(voltdm, &omap3_mpu_pmic);
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530306
Kevin Hilman81a60482011-03-16 14:25:45 -0700307 voltdm = voltdm_lookup("core");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700308 omap_voltage_register_pmic(voltdm, &omap3_core_pmic);
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530309
310 return 0;
311}
Thara Gopinath40713182011-02-15 13:28:58 +0530312
313/**
314 * omap3_twl_set_sr_bit() - Set/Clear SR bit on TWL
315 * @enable: enable SR mode in twl or not
316 *
317 * If 'enable' is true, enables Smartreflex bit on TWL 4030 to make sure
318 * voltage scaling through OMAP SR works. Else, the smartreflex bit
319 * on twl4030 is cleared as there are platforms which use OMAP3 and T2 but
320 * use Synchronized Scaling Hardware Strategy (ENABLE_VMODE=1) and Direct
321 * Strategy Software Scaling Mode (ENABLE_VMODE=0), for setting the voltages,
322 * in those scenarios this bit is to be cleared (enable = false).
323 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300324 * Returns 0 on success, error is returned if I2C read/write fails.
Thara Gopinath40713182011-02-15 13:28:58 +0530325 */
326int __init omap3_twl_set_sr_bit(bool enable)
327{
328 u8 temp;
329 int ret;
330 if (twl_sr_enable_autoinit)
331 pr_warning("%s: unexpected multiple calls\n", __func__);
332
333 ret = twl_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &temp,
334 TWL4030_DCDC_GLOBAL_CFG);
335 if (ret)
336 goto err;
337
338 if (enable)
339 temp |= SMARTREFLEX_ENABLE;
340 else
341 temp &= ~SMARTREFLEX_ENABLE;
342
343 ret = twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, temp,
344 TWL4030_DCDC_GLOBAL_CFG);
345 if (!ret) {
346 twl_sr_enable_autoinit = true;
347 return 0;
348 }
349err:
350 pr_err("%s: Error access to TWL4030 (%d)\n", __func__, ret);
351 return ret;
352}