blob: 6bf6267005571b5fadc03d4bab9d8e60489d2d0c [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
Tony Lindgrene4c060d2012-10-05 13:25:59 -070021#include "soc.h"
Paul Walmsleye1d6f472011-02-25 15:54:33 -070022#include "voltage.h"
Thara Gopinathfbc319f2010-12-10 22:51:05 +053023
Nishanth Menondda0aea2011-01-03 12:58:30 -060024#include "pm.h"
25
Thara Gopinathfbc319f2010-12-10 22:51:05 +053026#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
33
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053034#define OMAP4_SRI2C_SLAVE_ADDR 0x12
35#define OMAP4_VDD_MPU_SR_VOLT_REG 0x55
Nishanth Menonee7fbba2011-05-18 00:17:34 -050036#define OMAP4_VDD_MPU_SR_CMD_REG 0x56
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053037#define OMAP4_VDD_IVA_SR_VOLT_REG 0x5B
Nishanth Menonee7fbba2011-05-18 00:17:34 -050038#define OMAP4_VDD_IVA_SR_CMD_REG 0x5C
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053039#define OMAP4_VDD_CORE_SR_VOLT_REG 0x61
Nishanth Menonee7fbba2011-05-18 00:17:34 -050040#define OMAP4_VDD_CORE_SR_CMD_REG 0x62
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053041
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
46
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053047static bool is_offset_valid;
48static u8 smps_offset;
49
50#define REG_SMPS_OFFSET 0xE0
51
Nishanth Menonc84ff1c2011-01-03 12:58:29 -060052static unsigned long twl4030_vsel_to_uv(const u8 vsel)
Thara Gopinathfbc319f2010-12-10 22:51:05 +053053{
54 return (((vsel * 125) + 6000)) * 100;
55}
56
Nishanth Menonc84ff1c2011-01-03 12:58:29 -060057static u8 twl4030_uv_to_vsel(unsigned long uv)
Thara Gopinathfbc319f2010-12-10 22:51:05 +053058{
59 return DIV_ROUND_UP(uv - 600000, 12500);
60}
61
Nishanth Menonc84ff1c2011-01-03 12:58:29 -060062static unsigned long twl6030_vsel_to_uv(const u8 vsel)
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053063{
64 /*
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
71 */
72 if (!is_offset_valid) {
73 twl_i2c_read_u8(TWL6030_MODULE_ID0, &smps_offset,
74 REG_SMPS_OFFSET);
75 is_offset_valid = true;
76 }
77
Nishanth Menon2aed5b92011-05-18 00:17:32 -050078 if (!vsel)
79 return 0;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053080 /*
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
85 * OMAP4430.
86 */
87 if (vsel == 0x3A)
88 return 1350000;
89
90 if (smps_offset & 0x8)
Patrick Titiano58e241f2011-05-18 00:17:30 -050091 return ((((vsel - 1) * 1266) + 70900)) * 10;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053092 else
Patrick Titiano58e241f2011-05-18 00:17:30 -050093 return ((((vsel - 1) * 1266) + 60770)) * 10;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053094}
95
Nishanth Menonc84ff1c2011-01-03 12:58:29 -060096static u8 twl6030_uv_to_vsel(unsigned long uv)
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053097{
98 /*
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
105 */
106 if (!is_offset_valid) {
107 twl_i2c_read_u8(TWL6030_MODULE_ID0, &smps_offset,
108 REG_SMPS_OFFSET);
109 is_offset_valid = true;
110 }
111
Nishanth Menon2aed5b92011-05-18 00:17:32 -0500112 if (!uv)
113 return 0x00;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530114 /*
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
119 * OMAP4430.
120 */
Nishanth Menon36649422011-05-18 00:17:31 -0500121 if (uv > twl6030_vsel_to_uv(0x39)) {
122 if (uv == 1350000)
123 return 0x3A;
124 pr_err("%s:OUT OF RANGE! non mapped vsel for %ld Vs max %ld\n",
125 __func__, uv, twl6030_vsel_to_uv(0x39));
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530126 return 0x3A;
Nishanth Menon36649422011-05-18 00:17:31 -0500127 }
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530128
129 if (smps_offset & 0x8)
Patrick Titiano58e241f2011-05-18 00:17:30 -0500130 return DIV_ROUND_UP(uv - 709000, 12660) + 1;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530131 else
Patrick Titiano58e241f2011-05-18 00:17:30 -0500132 return DIV_ROUND_UP(uv - 607700, 12660) + 1;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530133}
134
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700135static struct omap_voltdm_pmic omap3_mpu_pmic = {
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530136 .slew_rate = 4000,
137 .step_size = 12500,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530138 .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
139 .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
140 .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
Tero Kristo5a84dc52012-09-25 19:33:42 +0300141 .vddmin = 600000,
142 .vddmax = 1450000,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530143 .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
144 .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700145 .volt_reg_addr = OMAP3_VDD_MPU_SR_CONTROL_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700146 .i2c_high_speed = true,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530147 .vsel_to_uv = twl4030_vsel_to_uv,
148 .uv_to_vsel = twl4030_uv_to_vsel,
149};
150
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700151static struct omap_voltdm_pmic omap3_core_pmic = {
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530152 .slew_rate = 4000,
153 .step_size = 12500,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530154 .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
155 .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
156 .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
Tero Kristo5a84dc52012-09-25 19:33:42 +0300157 .vddmin = 600000,
158 .vddmax = 1450000,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530159 .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
160 .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700161 .volt_reg_addr = OMAP3_VDD_CORE_SR_CONTROL_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700162 .i2c_high_speed = true,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530163 .vsel_to_uv = twl4030_vsel_to_uv,
164 .uv_to_vsel = twl4030_uv_to_vsel,
165};
166
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700167static struct omap_voltdm_pmic omap4_mpu_pmic = {
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530168 .slew_rate = 4000,
Patrick Titiano58e241f2011-05-18 00:17:30 -0500169 .step_size = 12660,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530170 .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
171 .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
172 .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
Tero Kristo5a84dc52012-09-25 19:33:42 +0300173 .vddmin = 0,
174 .vddmax = 2100000,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530175 .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
176 .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700177 .volt_reg_addr = OMAP4_VDD_MPU_SR_VOLT_REG,
Nishanth Menonee7fbba2011-05-18 00:17:34 -0500178 .cmd_reg_addr = OMAP4_VDD_MPU_SR_CMD_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700179 .i2c_high_speed = true,
Tero Kristo00bd2282012-09-25 19:33:48 +0300180 .i2c_pad_load = 3,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530181 .vsel_to_uv = twl6030_vsel_to_uv,
182 .uv_to_vsel = twl6030_uv_to_vsel,
183};
184
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700185static struct omap_voltdm_pmic omap4_iva_pmic = {
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530186 .slew_rate = 4000,
Patrick Titiano58e241f2011-05-18 00:17:30 -0500187 .step_size = 12660,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530188 .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
189 .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
190 .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
Tero Kristo5a84dc52012-09-25 19:33:42 +0300191 .vddmin = 0,
192 .vddmax = 2100000,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530193 .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
194 .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700195 .volt_reg_addr = OMAP4_VDD_IVA_SR_VOLT_REG,
Nishanth Menonee7fbba2011-05-18 00:17:34 -0500196 .cmd_reg_addr = OMAP4_VDD_IVA_SR_CMD_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700197 .i2c_high_speed = true,
Tero Kristo00bd2282012-09-25 19:33:48 +0300198 .i2c_pad_load = 3,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530199 .vsel_to_uv = twl6030_vsel_to_uv,
200 .uv_to_vsel = twl6030_uv_to_vsel,
201};
202
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700203static struct omap_voltdm_pmic omap4_core_pmic = {
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530204 .slew_rate = 4000,
Patrick Titiano58e241f2011-05-18 00:17:30 -0500205 .step_size = 12660,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530206 .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
207 .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
208 .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
Tero Kristo5a84dc52012-09-25 19:33:42 +0300209 .vddmin = 0,
210 .vddmax = 2100000,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530211 .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
212 .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700213 .volt_reg_addr = OMAP4_VDD_CORE_SR_VOLT_REG,
Nishanth Menonee7fbba2011-05-18 00:17:34 -0500214 .cmd_reg_addr = OMAP4_VDD_CORE_SR_CMD_REG,
Tero Kristo83b5b552012-09-25 19:33:49 +0300215 .i2c_high_speed = true,
Tero Kristo00bd2282012-09-25 19:33:48 +0300216 .i2c_pad_load = 3,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530217 .vsel_to_uv = twl6030_vsel_to_uv,
218 .uv_to_vsel = twl6030_uv_to_vsel,
219};
220
221int __init omap4_twl_init(void)
222{
223 struct voltagedomain *voltdm;
224
225 if (!cpu_is_omap44xx())
226 return -ENODEV;
227
Kevin Hilman81a60482011-03-16 14:25:45 -0700228 voltdm = voltdm_lookup("mpu");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700229 omap_voltage_register_pmic(voltdm, &omap4_mpu_pmic);
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530230
Kevin Hilman81a60482011-03-16 14:25:45 -0700231 voltdm = voltdm_lookup("iva");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700232 omap_voltage_register_pmic(voltdm, &omap4_iva_pmic);
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530233
Kevin Hilman81a60482011-03-16 14:25:45 -0700234 voltdm = voltdm_lookup("core");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700235 omap_voltage_register_pmic(voltdm, &omap4_core_pmic);
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530236
237 return 0;
238}
239
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530240int __init omap3_twl_init(void)
241{
242 struct voltagedomain *voltdm;
243
244 if (!cpu_is_omap34xx())
245 return -ENODEV;
246
Kevin Hilman280a7272011-03-23 11:18:08 -0700247 voltdm = voltdm_lookup("mpu_iva");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700248 omap_voltage_register_pmic(voltdm, &omap3_mpu_pmic);
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530249
Kevin Hilman81a60482011-03-16 14:25:45 -0700250 voltdm = voltdm_lookup("core");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700251 omap_voltage_register_pmic(voltdm, &omap3_core_pmic);
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530252
253 return 0;
254}