blob: 0de67b105581464455dc464e2e8606f3def97aea [file] [log] [blame]
David Collins5779cea2012-01-05 15:09:21 -08001/*
2 * Copyright (c) 2012, Code Aurora Forum. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#define pr_fmt(fmt) "%s: " fmt, __func__
15
16#include "rpm-regulator-private.h"
17
18/* RPM regulator request formats */
19static struct rpm_vreg_parts ldo_parts = {
20 .request_len = 2,
21 .uV = REQUEST_MEMBER(0, 0x007FFFFF, 0),
22 .pd = REQUEST_MEMBER(0, 0x00800000, 23),
23 .pc = REQUEST_MEMBER(0, 0x0F000000, 24),
24 .pf = REQUEST_MEMBER(0, 0xF0000000, 28),
25 .ip = REQUEST_MEMBER(1, 0x000003FF, 0),
26 .ia = REQUEST_MEMBER(1, 0x000FFC00, 10),
27 .fm = REQUEST_MEMBER(1, 0x00700000, 20),
28};
29
30static struct rpm_vreg_parts smps_parts = {
31 .request_len = 2,
32 .uV = REQUEST_MEMBER(0, 0x007FFFFF, 0),
33 .pd = REQUEST_MEMBER(0, 0x00800000, 23),
34 .pc = REQUEST_MEMBER(0, 0x0F000000, 24),
35 .pf = REQUEST_MEMBER(0, 0xF0000000, 28),
36 .ip = REQUEST_MEMBER(1, 0x000003FF, 0),
37 .ia = REQUEST_MEMBER(1, 0x000FFC00, 10),
38 .fm = REQUEST_MEMBER(1, 0x00700000, 20),
39 .pm = REQUEST_MEMBER(1, 0x00800000, 23),
40 .freq = REQUEST_MEMBER(1, 0x1F000000, 24),
41 .freq_clk_src = REQUEST_MEMBER(1, 0x60000000, 29),
42};
43
44static struct rpm_vreg_parts switch_parts = {
45 .request_len = 1,
46 .enable_state = REQUEST_MEMBER(0, 0x00000001, 0),
47 .pd = REQUEST_MEMBER(0, 0x00000002, 1),
48 .pc = REQUEST_MEMBER(0, 0x0000003C, 2),
49 .pf = REQUEST_MEMBER(0, 0x000003C0, 6),
50 .hpm = REQUEST_MEMBER(0, 0x00000C00, 10),
51};
52
David Collins49177a72012-02-06 17:01:19 -080053static struct rpm_vreg_parts corner_parts = {
54 .request_len = 1,
55 .uV = REQUEST_MEMBER(0, 0x00000003, 0),
56};
57
David Collins5779cea2012-01-05 15:09:21 -080058/* Physically available PMIC regulator voltage setpoint ranges */
59static struct vreg_range pldo_ranges[] = {
60 VOLTAGE_RANGE( 750000, 1487500, 12500),
61 VOLTAGE_RANGE(1500000, 3075000, 25000),
62 VOLTAGE_RANGE(3100000, 4900000, 50000),
63};
64
65static struct vreg_range nldo_ranges[] = {
66 VOLTAGE_RANGE( 750000, 1537500, 12500),
67};
68
69static struct vreg_range nldo1200_ranges[] = {
70 VOLTAGE_RANGE( 375000, 743750, 6250),
71 VOLTAGE_RANGE( 750000, 1537500, 12500),
72};
73
74static struct vreg_range smps_ranges[] = {
75 VOLTAGE_RANGE( 375000, 737500, 12500),
76 VOLTAGE_RANGE( 750000, 1487500, 12500),
77 VOLTAGE_RANGE(1500000, 3075000, 25000),
78};
79
80static struct vreg_range ftsmps_ranges[] = {
81 VOLTAGE_RANGE( 350000, 650000, 50000),
82 VOLTAGE_RANGE( 700000, 1400000, 12500),
83 VOLTAGE_RANGE(1500000, 3300000, 50000),
84};
85
David Collins49177a72012-02-06 17:01:19 -080086static struct vreg_range corner_ranges[] = {
87 VOLTAGE_RANGE(RPM_VREG_CORNER_NONE, RPM_VREG_CORNER_HIGH, 1),
88};
89
David Collins5779cea2012-01-05 15:09:21 -080090static struct vreg_set_points pldo_set_points = SET_POINTS(pldo_ranges);
91static struct vreg_set_points nldo_set_points = SET_POINTS(nldo_ranges);
92static struct vreg_set_points nldo1200_set_points = SET_POINTS(nldo1200_ranges);
93static struct vreg_set_points smps_set_points = SET_POINTS(smps_ranges);
94static struct vreg_set_points ftsmps_set_points = SET_POINTS(ftsmps_ranges);
David Collins49177a72012-02-06 17:01:19 -080095static struct vreg_set_points corner_set_points = SET_POINTS(corner_ranges);
David Collins5779cea2012-01-05 15:09:21 -080096
97static struct vreg_set_points *all_set_points[] = {
98 &pldo_set_points,
99 &nldo_set_points,
100 &nldo1200_set_points,
101 &smps_set_points,
102 &ftsmps_set_points,
David Collins49177a72012-02-06 17:01:19 -0800103 &corner_set_points,
David Collins5779cea2012-01-05 15:09:21 -0800104};
105
David Collins62ae8d92012-07-31 16:29:43 -0700106#define LDO(_id, _name, _name_pc, _ranges, _hpm_min_load, _requires_cxo) \
David Collins5779cea2012-01-05 15:09:21 -0800107 [RPM_VREG_ID_PM8038_##_id] = { \
108 .req = { \
109 [0] = { .id = MSM_RPM_ID_PM8038_##_id##_0, }, \
110 [1] = { .id = MSM_RPM_ID_PM8038_##_id##_1, }, \
111 }, \
112 .hpm_min_load = RPM_VREG_8930_##_hpm_min_load##_HPM_MIN_LOAD, \
113 .type = RPM_REGULATOR_TYPE_LDO, \
114 .set_points = &_ranges##_set_points, \
115 .part = &ldo_parts, \
116 .id = RPM_VREG_ID_PM8038_##_id, \
117 .rdesc.name = _name, \
118 .rdesc_pc.name = _name_pc, \
David Collins62ae8d92012-07-31 16:29:43 -0700119 .requires_cxo = _requires_cxo, \
David Collins5779cea2012-01-05 15:09:21 -0800120 }
121
122#define SMPS(_id, _name, _name_pc, _ranges, _hpm_min_load) \
123 [RPM_VREG_ID_PM8038_##_id] = { \
124 .req = { \
125 [0] = { .id = MSM_RPM_ID_PM8038_##_id##_0, }, \
126 [1] = { .id = MSM_RPM_ID_PM8038_##_id##_1, }, \
127 }, \
128 .hpm_min_load = RPM_VREG_8930_##_hpm_min_load##_HPM_MIN_LOAD, \
129 .type = RPM_REGULATOR_TYPE_SMPS, \
130 .set_points = &_ranges##_set_points, \
131 .part = &smps_parts, \
132 .id = RPM_VREG_ID_PM8038_##_id, \
133 .rdesc.name = _name, \
134 .rdesc_pc.name = _name_pc, \
135 }
136
137#define LVS(_id, _name, _name_pc) \
138 [RPM_VREG_ID_PM8038_##_id] = { \
139 .req = { \
140 [0] = { .id = MSM_RPM_ID_PM8038_##_id, }, \
141 [1] = { .id = -1, }, \
142 }, \
143 .type = RPM_REGULATOR_TYPE_VS, \
144 .part = &switch_parts, \
145 .id = RPM_VREG_ID_PM8038_##_id, \
146 .rdesc.name = _name, \
147 .rdesc_pc.name = _name_pc, \
148 }
149
David Collins49177a72012-02-06 17:01:19 -0800150#define CORNER(_id, _rpm_id, _name, _ranges) \
151 [RPM_VREG_ID_PM8038_##_id] = { \
152 .req = { \
153 [0] = { .id = MSM_RPM_ID_##_rpm_id, }, \
154 [1] = { .id = -1, }, \
155 }, \
156 .type = RPM_REGULATOR_TYPE_CORNER, \
157 .set_points = &_ranges##_set_points, \
158 .part = &corner_parts, \
159 .id = RPM_VREG_ID_PM8038_##_id, \
160 .rdesc.name = _name, \
161 }
162
David Collins5779cea2012-01-05 15:09:21 -0800163static struct vreg vregs[] = {
David Collins62ae8d92012-07-31 16:29:43 -0700164 LDO(L1, "8038_l1", NULL, nldo1200, LDO_1200, 1),
165 LDO(L2, "8038_l2", "8038_l2_pc", nldo, LDO_150, 1),
166 LDO(L3, "8038_l3", "8038_l3_pc", pldo, LDO_50, 0),
167 LDO(L4, "8038_l4", "8038_l4_pc", pldo, LDO_50, 0),
168 LDO(L5, "8038_l5", "8038_l5_pc", pldo, LDO_600, 0),
169 LDO(L6, "8038_l6", "8038_l6_pc", pldo, LDO_600, 0),
170 LDO(L7, "8038_l7", "8038_l7_pc", pldo, LDO_600, 0),
171 LDO(L8, "8038_l8", "8038_l8_pc", pldo, LDO_300, 0),
172 LDO(L9, "8038_l9", "8038_l9_pc", pldo, LDO_300, 0),
173 LDO(L10, "8038_l10", "8038_l10_pc", pldo, LDO_600, 0),
174 LDO(L11, "8038_l11", "8038_l11_pc", pldo, LDO_600, 0),
175 LDO(L12, "8038_l12", "8038_l12_pc", nldo, LDO_300, 1),
176 LDO(L14, "8038_l14", "8038_l14_pc", pldo, LDO_50, 0),
177 LDO(L15, "8038_l15", "8038_l15_pc", pldo, LDO_150, 0),
178 LDO(L16, "8038_l16", NULL, nldo1200, LDO_1200, 1),
179 LDO(L17, "8038_l17", "8038_l17_pc", pldo, LDO_150, 0),
180 LDO(L18, "8038_l18", "8038_l18_pc", pldo, LDO_50, 0),
181 LDO(L19, "8038_l19", NULL, nldo1200, LDO_1200, 1),
182 LDO(L20, "8038_l20", NULL, nldo1200, LDO_1200, 1),
183 LDO(L21, "8038_l21", "8038_l21_pc", pldo, LDO_150, 0),
184 LDO(L22, "8038_l22", "8038_l22_pc", pldo, LDO_50, 0),
185 LDO(L23, "8038_l23", "8038_l23_pc", pldo, LDO_50, 0),
186 LDO(L24, "8038_l24", NULL, nldo1200, LDO_1200, 1),
187 LDO(L26, "8038_l26", "8038_l26_pc", nldo, LDO_150, 1),
188 LDO(L27, "8038_l27", NULL, nldo1200, LDO_1200, 1),
David Collins5779cea2012-01-05 15:09:21 -0800189
190 SMPS(S1, "8038_s1", "8038_s1_pc", smps, SMPS_1500),
191 SMPS(S2, "8038_s2", "8038_s2_pc", smps, SMPS_1500),
192 SMPS(S3, "8038_s3", "8038_s3_pc", smps, SMPS_1500),
193 SMPS(S4, "8038_s4", "8038_s4_pc", smps, SMPS_1500),
194 SMPS(S5, "8038_s5", NULL, ftsmps, SMPS_2000),
195 SMPS(S6, "8038_s6", NULL, ftsmps, SMPS_2000),
196
197 LVS(LVS1, "8038_lvs1", "8038_lvs1_pc"),
198 LVS(LVS2, "8038_lvs2", "8038_lvs2_pc"),
David Collins49177a72012-02-06 17:01:19 -0800199
200 CORNER(VDD_DIG_CORNER, VOLTAGE_CORNER, "vdd_dig_corner", corner),
David Collins5779cea2012-01-05 15:09:21 -0800201};
202
203static const char *pin_func_label[] = {
204 [RPM_VREG_PIN_FN_8930_DONT_CARE] = "don't care",
205 [RPM_VREG_PIN_FN_8930_ENABLE] = "on/off",
206 [RPM_VREG_PIN_FN_8930_MODE] = "HPM/LPM",
207 [RPM_VREG_PIN_FN_8930_SLEEP_B] = "sleep_b",
208 [RPM_VREG_PIN_FN_8930_NONE] = "none",
209};
210
211static const char *force_mode_label[] = {
212 [RPM_VREG_FORCE_MODE_8930_NONE] = "none",
213 [RPM_VREG_FORCE_MODE_8930_LPM] = "LPM",
214 [RPM_VREG_FORCE_MODE_8930_AUTO] = "auto",
215 [RPM_VREG_FORCE_MODE_8930_HPM] = "HPM",
216 [RPM_VREG_FORCE_MODE_8930_BYPASS] = "BYP",
217};
218
219static const char *power_mode_label[] = {
220 [RPM_VREG_POWER_MODE_8930_HYSTERETIC] = "HYS",
221 [RPM_VREG_POWER_MODE_8930_PWM] = "PWM",
222};
223
224static const char *pin_control_label[] = {
225 " D1",
226 " A0",
227 " A1",
228 " A2",
229};
230
231static int is_real_id(int id)
232{
233 return (id >= 0) && (id <= RPM_VREG_ID_PM8038_MAX_REAL);
234}
235
236static int pc_id_to_real_id(int id)
237{
238 int real_id = 0;
239
240 if (id >= RPM_VREG_ID_PM8038_L2_PC && id <= RPM_VREG_ID_PM8038_L15_PC)
241 real_id = id - RPM_VREG_ID_PM8038_L2_PC;
242 else if (id >= RPM_VREG_ID_PM8038_L17_PC
243 && id <= RPM_VREG_ID_PM8038_L18_PC)
244 real_id = id - RPM_VREG_ID_PM8038_L17_PC
245 + RPM_VREG_ID_PM8038_L17;
246 else if (id >= RPM_VREG_ID_PM8038_L21_PC
247 && id <= RPM_VREG_ID_PM8038_L23_PC)
248 real_id = id - RPM_VREG_ID_PM8038_L21_PC
249 + RPM_VREG_ID_PM8038_L21;
250 else if (id == RPM_VREG_ID_PM8038_L26_PC)
251 real_id = RPM_VREG_ID_PM8038_L26;
252 else if (id >= RPM_VREG_ID_PM8038_S1_PC
253 && id <= RPM_VREG_ID_PM8038_S4_PC)
254 real_id = id - RPM_VREG_ID_PM8038_S1_PC
255 + RPM_VREG_ID_PM8038_S1;
256 else if (id >= RPM_VREG_ID_PM8038_LVS1_PC
257 && id <= RPM_VREG_ID_PM8038_LVS2_PC)
258 real_id = id - RPM_VREG_ID_PM8038_LVS1_PC
259 + RPM_VREG_ID_PM8038_LVS1;
260
261 return real_id;
262}
263
264static struct vreg_config config = {
265 .vregs = vregs,
266 .vregs_len = ARRAY_SIZE(vregs),
267
268 .vreg_id_min = RPM_VREG_ID_PM8038_L1,
269 .vreg_id_max = RPM_VREG_ID_PM8038_MAX,
270
271 .pin_func_none = RPM_VREG_PIN_FN_8930_NONE,
272 .pin_func_sleep_b = RPM_VREG_PIN_FN_8930_SLEEP_B,
273
274 .mode_lpm = REGULATOR_MODE_IDLE,
275 .mode_hpm = REGULATOR_MODE_NORMAL,
276
277 .set_points = all_set_points,
278 .set_points_len = ARRAY_SIZE(all_set_points),
279
280 .label_pin_ctrl = pin_control_label,
281 .label_pin_ctrl_len = ARRAY_SIZE(pin_control_label),
282 .label_pin_func = pin_func_label,
283 .label_pin_func_len = ARRAY_SIZE(pin_func_label),
284 .label_force_mode = force_mode_label,
285 .label_force_mode_len = ARRAY_SIZE(force_mode_label),
286 .label_power_mode = power_mode_label,
287 .label_power_mode_len = ARRAY_SIZE(power_mode_label),
288
289 .is_real_id = is_real_id,
290 .pc_id_to_real_id = pc_id_to_real_id,
291};
292
293struct vreg_config *get_config_8930(void)
294{
295 return &config;
296}