blob: ecae9890f0f2d8910c9c4e61d8e827bef18ca57b [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
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053033#define OMAP4_SRI2C_SLAVE_ADDR 0x12
34#define OMAP4_VDD_MPU_SR_VOLT_REG 0x55
Nishanth Menonee7fbba2011-05-18 00:17:34 -050035#define OMAP4_VDD_MPU_SR_CMD_REG 0x56
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053036#define OMAP4_VDD_IVA_SR_VOLT_REG 0x5B
Nishanth Menonee7fbba2011-05-18 00:17:34 -050037#define OMAP4_VDD_IVA_SR_CMD_REG 0x5C
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053038#define OMAP4_VDD_CORE_SR_VOLT_REG 0x61
Nishanth Menonee7fbba2011-05-18 00:17:34 -050039#define OMAP4_VDD_CORE_SR_CMD_REG 0x62
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053040
41#define OMAP4_VP_CONFIG_ERROROFFSET 0x00
42#define OMAP4_VP_VSTEPMIN_VSTEPMIN 0x01
43#define OMAP4_VP_VSTEPMAX_VSTEPMAX 0x04
44#define OMAP4_VP_VLIMITTO_TIMEOUT_US 200
45
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053046static bool is_offset_valid;
47static u8 smps_offset;
Thara Gopinath40713182011-02-15 13:28:58 +053048/*
49 * Flag to ensure Smartreflex bit in TWL
50 * being cleared in board file is not overwritten.
51 */
52static bool __initdata twl_sr_enable_autoinit;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053053
Thara Gopinath40713182011-02-15 13:28:58 +053054#define TWL4030_DCDC_GLOBAL_CFG 0x06
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053055#define REG_SMPS_OFFSET 0xE0
Thara Gopinath40713182011-02-15 13:28:58 +053056#define SMARTREFLEX_ENABLE BIT(3)
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053057
Nishanth Menonc84ff1c2011-01-03 12:58:29 -060058static unsigned long twl4030_vsel_to_uv(const u8 vsel)
Thara Gopinathfbc319f2010-12-10 22:51:05 +053059{
60 return (((vsel * 125) + 6000)) * 100;
61}
62
Nishanth Menonc84ff1c2011-01-03 12:58:29 -060063static u8 twl4030_uv_to_vsel(unsigned long uv)
Thara Gopinathfbc319f2010-12-10 22:51:05 +053064{
65 return DIV_ROUND_UP(uv - 600000, 12500);
66}
67
Nishanth Menonc84ff1c2011-01-03 12:58:29 -060068static unsigned long twl6030_vsel_to_uv(const u8 vsel)
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053069{
70 /*
71 * In TWL6030 depending on the value of SMPS_OFFSET
72 * efuse register the voltage range supported in
73 * standard mode can be either between 0.6V - 1.3V or
74 * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
75 * is programmed to all 0's where as starting from
76 * TWL6030 ES1.1 the efuse is programmed to 1
77 */
78 if (!is_offset_valid) {
79 twl_i2c_read_u8(TWL6030_MODULE_ID0, &smps_offset,
80 REG_SMPS_OFFSET);
81 is_offset_valid = true;
82 }
83
Nishanth Menon2aed5b92011-05-18 00:17:32 -050084 if (!vsel)
85 return 0;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053086 /*
87 * There is no specific formula for voltage to vsel
88 * conversion above 1.3V. There are special hardcoded
89 * values for voltages above 1.3V. Currently we are
90 * hardcoding only for 1.35 V which is used for 1GH OPP for
91 * OMAP4430.
92 */
93 if (vsel == 0x3A)
94 return 1350000;
95
96 if (smps_offset & 0x8)
Patrick Titiano58e241f2011-05-18 00:17:30 -050097 return ((((vsel - 1) * 1266) + 70900)) * 10;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053098 else
Patrick Titiano58e241f2011-05-18 00:17:30 -050099 return ((((vsel - 1) * 1266) + 60770)) * 10;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530100}
101
Nishanth Menonc84ff1c2011-01-03 12:58:29 -0600102static u8 twl6030_uv_to_vsel(unsigned long uv)
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530103{
104 /*
105 * In TWL6030 depending on the value of SMPS_OFFSET
106 * efuse register the voltage range supported in
107 * standard mode can be either between 0.6V - 1.3V or
108 * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
109 * is programmed to all 0's where as starting from
110 * TWL6030 ES1.1 the efuse is programmed to 1
111 */
112 if (!is_offset_valid) {
113 twl_i2c_read_u8(TWL6030_MODULE_ID0, &smps_offset,
114 REG_SMPS_OFFSET);
115 is_offset_valid = true;
116 }
117
Nishanth Menon2aed5b92011-05-18 00:17:32 -0500118 if (!uv)
119 return 0x00;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530120 /*
121 * There is no specific formula for voltage to vsel
122 * conversion above 1.3V. There are special hardcoded
123 * values for voltages above 1.3V. Currently we are
124 * hardcoding only for 1.35 V which is used for 1GH OPP for
125 * OMAP4430.
126 */
Nishanth Menon36649422011-05-18 00:17:31 -0500127 if (uv > twl6030_vsel_to_uv(0x39)) {
128 if (uv == 1350000)
129 return 0x3A;
130 pr_err("%s:OUT OF RANGE! non mapped vsel for %ld Vs max %ld\n",
131 __func__, uv, twl6030_vsel_to_uv(0x39));
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530132 return 0x3A;
Nishanth Menon36649422011-05-18 00:17:31 -0500133 }
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530134
135 if (smps_offset & 0x8)
Patrick Titiano58e241f2011-05-18 00:17:30 -0500136 return DIV_ROUND_UP(uv - 709000, 12660) + 1;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530137 else
Patrick Titiano58e241f2011-05-18 00:17:30 -0500138 return DIV_ROUND_UP(uv - 607700, 12660) + 1;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530139}
140
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700141static struct omap_voltdm_pmic omap3_mpu_pmic = {
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530142 .slew_rate = 4000,
143 .step_size = 12500,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530144 .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
145 .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
146 .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
Tero Kristo5a84dc52012-09-25 19:33:42 +0300147 .vddmin = 600000,
148 .vddmax = 1450000,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530149 .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
150 .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700151 .volt_reg_addr = OMAP3_VDD_MPU_SR_CONTROL_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700152 .i2c_high_speed = true,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530153 .vsel_to_uv = twl4030_vsel_to_uv,
154 .uv_to_vsel = twl4030_uv_to_vsel,
155};
156
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700157static struct omap_voltdm_pmic omap3_core_pmic = {
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530158 .slew_rate = 4000,
159 .step_size = 12500,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530160 .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
161 .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
162 .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
Tero Kristo5a84dc52012-09-25 19:33:42 +0300163 .vddmin = 600000,
164 .vddmax = 1450000,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530165 .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
166 .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700167 .volt_reg_addr = OMAP3_VDD_CORE_SR_CONTROL_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700168 .i2c_high_speed = true,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530169 .vsel_to_uv = twl4030_vsel_to_uv,
170 .uv_to_vsel = twl4030_uv_to_vsel,
171};
172
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700173static struct omap_voltdm_pmic omap4_mpu_pmic = {
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530174 .slew_rate = 4000,
Patrick Titiano58e241f2011-05-18 00:17:30 -0500175 .step_size = 12660,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530176 .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
177 .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
178 .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
Tero Kristo5a84dc52012-09-25 19:33:42 +0300179 .vddmin = 0,
180 .vddmax = 2100000,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530181 .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
182 .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700183 .volt_reg_addr = OMAP4_VDD_MPU_SR_VOLT_REG,
Nishanth Menonee7fbba2011-05-18 00:17:34 -0500184 .cmd_reg_addr = OMAP4_VDD_MPU_SR_CMD_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700185 .i2c_high_speed = true,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530186 .vsel_to_uv = twl6030_vsel_to_uv,
187 .uv_to_vsel = twl6030_uv_to_vsel,
188};
189
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700190static struct omap_voltdm_pmic omap4_iva_pmic = {
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530191 .slew_rate = 4000,
Patrick Titiano58e241f2011-05-18 00:17:30 -0500192 .step_size = 12660,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530193 .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
194 .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
195 .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
Tero Kristo5a84dc52012-09-25 19:33:42 +0300196 .vddmin = 0,
197 .vddmax = 2100000,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530198 .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
199 .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700200 .volt_reg_addr = OMAP4_VDD_IVA_SR_VOLT_REG,
Nishanth Menonee7fbba2011-05-18 00:17:34 -0500201 .cmd_reg_addr = OMAP4_VDD_IVA_SR_CMD_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700202 .i2c_high_speed = true,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530203 .vsel_to_uv = twl6030_vsel_to_uv,
204 .uv_to_vsel = twl6030_uv_to_vsel,
205};
206
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700207static struct omap_voltdm_pmic omap4_core_pmic = {
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530208 .slew_rate = 4000,
Patrick Titiano58e241f2011-05-18 00:17:30 -0500209 .step_size = 12660,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530210 .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
211 .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
212 .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
Tero Kristo5a84dc52012-09-25 19:33:42 +0300213 .vddmin = 0,
214 .vddmax = 2100000,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530215 .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
216 .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700217 .volt_reg_addr = OMAP4_VDD_CORE_SR_VOLT_REG,
Nishanth Menonee7fbba2011-05-18 00:17:34 -0500218 .cmd_reg_addr = OMAP4_VDD_CORE_SR_CMD_REG,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530219 .vsel_to_uv = twl6030_vsel_to_uv,
220 .uv_to_vsel = twl6030_uv_to_vsel,
221};
222
223int __init omap4_twl_init(void)
224{
225 struct voltagedomain *voltdm;
226
227 if (!cpu_is_omap44xx())
228 return -ENODEV;
229
Kevin Hilman81a60482011-03-16 14:25:45 -0700230 voltdm = voltdm_lookup("mpu");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700231 omap_voltage_register_pmic(voltdm, &omap4_mpu_pmic);
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530232
Kevin Hilman81a60482011-03-16 14:25:45 -0700233 voltdm = voltdm_lookup("iva");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700234 omap_voltage_register_pmic(voltdm, &omap4_iva_pmic);
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530235
Kevin Hilman81a60482011-03-16 14:25:45 -0700236 voltdm = voltdm_lookup("core");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700237 omap_voltage_register_pmic(voltdm, &omap4_core_pmic);
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530238
239 return 0;
240}
241
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530242int __init omap3_twl_init(void)
243{
244 struct voltagedomain *voltdm;
245
246 if (!cpu_is_omap34xx())
247 return -ENODEV;
248
Thara Gopinath40713182011-02-15 13:28:58 +0530249 /*
250 * The smartreflex bit on twl4030 specifies if the setting of voltage
251 * is done over the I2C_SR path. Since this setting is independent of
252 * the actual usage of smartreflex AVS module, we enable TWL SR bit
253 * by default irrespective of whether smartreflex AVS module is enabled
254 * on the OMAP side or not. This is because without this bit enabled,
255 * the voltage scaling through vp forceupdate/bypass mechanism of
256 * voltage scaling will not function on TWL over I2C_SR.
257 */
258 if (!twl_sr_enable_autoinit)
259 omap3_twl_set_sr_bit(true);
260
Kevin Hilman280a7272011-03-23 11:18:08 -0700261 voltdm = voltdm_lookup("mpu_iva");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700262 omap_voltage_register_pmic(voltdm, &omap3_mpu_pmic);
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530263
Kevin Hilman81a60482011-03-16 14:25:45 -0700264 voltdm = voltdm_lookup("core");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700265 omap_voltage_register_pmic(voltdm, &omap3_core_pmic);
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530266
267 return 0;
268}
Thara Gopinath40713182011-02-15 13:28:58 +0530269
270/**
271 * omap3_twl_set_sr_bit() - Set/Clear SR bit on TWL
272 * @enable: enable SR mode in twl or not
273 *
274 * If 'enable' is true, enables Smartreflex bit on TWL 4030 to make sure
275 * voltage scaling through OMAP SR works. Else, the smartreflex bit
276 * on twl4030 is cleared as there are platforms which use OMAP3 and T2 but
277 * use Synchronized Scaling Hardware Strategy (ENABLE_VMODE=1) and Direct
278 * Strategy Software Scaling Mode (ENABLE_VMODE=0), for setting the voltages,
279 * in those scenarios this bit is to be cleared (enable = false).
280 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300281 * Returns 0 on success, error is returned if I2C read/write fails.
Thara Gopinath40713182011-02-15 13:28:58 +0530282 */
283int __init omap3_twl_set_sr_bit(bool enable)
284{
285 u8 temp;
286 int ret;
287 if (twl_sr_enable_autoinit)
288 pr_warning("%s: unexpected multiple calls\n", __func__);
289
290 ret = twl_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &temp,
291 TWL4030_DCDC_GLOBAL_CFG);
292 if (ret)
293 goto err;
294
295 if (enable)
296 temp |= SMARTREFLEX_ENABLE;
297 else
298 temp &= ~SMARTREFLEX_ENABLE;
299
300 ret = twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, temp,
301 TWL4030_DCDC_GLOBAL_CFG);
302 if (!ret) {
303 twl_sr_enable_autoinit = true;
304 return 0;
305 }
306err:
307 pr_err("%s: Error access to TWL4030 (%d)\n", __func__, ret);
308 return ret;
309}