1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/err.h>
14#include <linux/io.h>
15#include <linux/kernel.h>
16#include <linux/mfd/twl.h>
17
18#include "soc.h"
19#include "voltage.h"
20
21#include "pm.h"
22
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
30
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
38
39#define OMAP4_VP_CONFIG_ERROROFFSET 0x00
40#define OMAP4_VP_VSTEPMIN_VSTEPMIN 0x01
41#define OMAP4_VP_VSTEPMAX_VSTEPMAX 0x04
42#define OMAP4_VP_VLIMITTO_TIMEOUT_US 200
43
44static bool is_offset_valid;
45static u8 smps_offset;
46
47#define REG_SMPS_OFFSET 0xE0
48
49static unsigned long twl4030_vsel_to_uv(const u8 vsel)
50{
51 return (((vsel * 125) + 6000)) * 100;
52}
53
54static u8 twl4030_uv_to_vsel(unsigned long uv)
55{
56 return DIV_ROUND_UP(uv - 600000, 12500);
57}
58
59static unsigned long twl6030_vsel_to_uv(const u8 vsel)
60{
61
62
63
64
65
66
67
68
69 if (!is_offset_valid) {
70 twl_i2c_read_u8(TWL6030_MODULE_ID0, &smps_offset,
71 REG_SMPS_OFFSET);
72 is_offset_valid = true;
73 }
74
75 if (!vsel)
76 return 0;
77
78
79
80
81
82
83
84 if (vsel == 0x3A)
85 return 1350000;
86
87 if (smps_offset & 0x8)
88 return ((((vsel - 1) * 1266) + 70900)) * 10;
89 else
90 return ((((vsel - 1) * 1266) + 60770)) * 10;
91}
92
93static u8 twl6030_uv_to_vsel(unsigned long uv)
94{
95
96
97
98
99
100
101
102
103 if (!is_offset_valid) {
104 twl_i2c_read_u8(TWL6030_MODULE_ID0, &smps_offset,
105 REG_SMPS_OFFSET);
106 is_offset_valid = true;
107 }
108
109 if (!uv)
110 return 0x00;
111
112
113
114
115
116
117
118 if (uv > twl6030_vsel_to_uv(0x39)) {
119 if (uv == 1350000)
120 return 0x3A;
121 pr_err("%s:OUT OF RANGE! non mapped vsel for %ld Vs max %ld\n",
122 __func__, uv, twl6030_vsel_to_uv(0x39));
123 return 0x3A;
124 }
125
126 if (smps_offset & 0x8)
127 return DIV_ROUND_UP(uv - 709000, 12660) + 1;
128 else
129 return DIV_ROUND_UP(uv - 607700, 12660) + 1;
130}
131
132static struct omap_voltdm_pmic omap3_mpu_pmic = {
133 .slew_rate = 4000,
134 .step_size = 12500,
135 .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
136 .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
137 .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
138 .vddmin = 600000,
139 .vddmax = 1450000,
140 .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
141 .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
142 .volt_reg_addr = OMAP3_VDD_MPU_SR_CONTROL_REG,
143 .i2c_high_speed = true,
144 .vsel_to_uv = twl4030_vsel_to_uv,
145 .uv_to_vsel = twl4030_uv_to_vsel,
146};
147
148static struct omap_voltdm_pmic omap3_core_pmic = {
149 .slew_rate = 4000,
150 .step_size = 12500,
151 .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
152 .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
153 .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
154 .vddmin = 600000,
155 .vddmax = 1450000,
156 .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
157 .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
158 .volt_reg_addr = OMAP3_VDD_CORE_SR_CONTROL_REG,
159 .i2c_high_speed = true,
160 .vsel_to_uv = twl4030_vsel_to_uv,
161 .uv_to_vsel = twl4030_uv_to_vsel,
162};
163
164static struct omap_voltdm_pmic omap4_mpu_pmic = {
165 .slew_rate = 4000,
166 .step_size = 12660,
167 .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
168 .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
169 .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
170 .vddmin = 0,
171 .vddmax = 2100000,
172 .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
173 .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
174 .volt_reg_addr = OMAP4_VDD_MPU_SR_VOLT_REG,
175 .cmd_reg_addr = OMAP4_VDD_MPU_SR_CMD_REG,
176 .i2c_high_speed = true,
177 .i2c_pad_load = 3,
178 .vsel_to_uv = twl6030_vsel_to_uv,
179 .uv_to_vsel = twl6030_uv_to_vsel,
180};
181
182static struct omap_voltdm_pmic omap4_iva_pmic = {
183 .slew_rate = 4000,
184 .step_size = 12660,
185 .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
186 .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
187 .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
188 .vddmin = 0,
189 .vddmax = 2100000,
190 .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
191 .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
192 .volt_reg_addr = OMAP4_VDD_IVA_SR_VOLT_REG,
193 .cmd_reg_addr = OMAP4_VDD_IVA_SR_CMD_REG,
194 .i2c_high_speed = true,
195 .i2c_pad_load = 3,
196 .vsel_to_uv = twl6030_vsel_to_uv,
197 .uv_to_vsel = twl6030_uv_to_vsel,
198};
199
200static struct omap_voltdm_pmic omap4_core_pmic = {
201 .slew_rate = 4000,
202 .step_size = 12660,
203 .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
204 .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
205 .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
206 .vddmin = 0,
207 .vddmax = 2100000,
208 .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
209 .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
210 .volt_reg_addr = OMAP4_VDD_CORE_SR_VOLT_REG,
211 .cmd_reg_addr = OMAP4_VDD_CORE_SR_CMD_REG,
212 .i2c_high_speed = true,
213 .i2c_pad_load = 3,
214 .vsel_to_uv = twl6030_vsel_to_uv,
215 .uv_to_vsel = twl6030_uv_to_vsel,
216};
217
218int __init omap4_twl_init(void)
219{
220 struct voltagedomain *voltdm;
221
222 if (!cpu_is_omap44xx())
223 return -ENODEV;
224
225 voltdm = voltdm_lookup("mpu");
226 omap_voltage_register_pmic(voltdm, &omap4_mpu_pmic);
227
228 voltdm = voltdm_lookup("iva");
229 omap_voltage_register_pmic(voltdm, &omap4_iva_pmic);
230
231 voltdm = voltdm_lookup("core");
232 omap_voltage_register_pmic(voltdm, &omap4_core_pmic);
233
234 return 0;
235}
236
237int __init omap3_twl_init(void)
238{
239 struct voltagedomain *voltdm;
240
241 if (!cpu_is_omap34xx())
242 return -ENODEV;
243
244 voltdm = voltdm_lookup("mpu_iva");
245 omap_voltage_register_pmic(voltdm, &omap3_mpu_pmic);
246
247 voltdm = voltdm_lookup("core");
248 omap_voltage_register_pmic(voltdm, &omap3_core_pmic);
249
250 return 0;
251}
252