blob: 3878e2215c023a488855b7b216e156944b257d12 [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
David Collins18a54422012-08-09 14:41:06 -070074static struct vreg_range ln_ldo_ranges[] = {
75 VOLTAGE_RANGE( 690000, 1110000, 60000),
76 VOLTAGE_RANGE(1380000, 2220000, 120000),
77};
78
David Collins5779cea2012-01-05 15:09:21 -080079static struct vreg_range smps_ranges[] = {
80 VOLTAGE_RANGE( 375000, 737500, 12500),
81 VOLTAGE_RANGE( 750000, 1487500, 12500),
82 VOLTAGE_RANGE(1500000, 3075000, 25000),
83};
84
85static struct vreg_range ftsmps_ranges[] = {
86 VOLTAGE_RANGE( 350000, 650000, 50000),
87 VOLTAGE_RANGE( 700000, 1400000, 12500),
88 VOLTAGE_RANGE(1500000, 3300000, 50000),
89};
90
David Collins49177a72012-02-06 17:01:19 -080091static struct vreg_range corner_ranges[] = {
92 VOLTAGE_RANGE(RPM_VREG_CORNER_NONE, RPM_VREG_CORNER_HIGH, 1),
93};
94
David Collins5779cea2012-01-05 15:09:21 -080095static struct vreg_set_points pldo_set_points = SET_POINTS(pldo_ranges);
96static struct vreg_set_points nldo_set_points = SET_POINTS(nldo_ranges);
97static struct vreg_set_points nldo1200_set_points = SET_POINTS(nldo1200_ranges);
David Collins18a54422012-08-09 14:41:06 -070098static struct vreg_set_points ln_ldo_set_points = SET_POINTS(ln_ldo_ranges);
David Collins5779cea2012-01-05 15:09:21 -080099static struct vreg_set_points smps_set_points = SET_POINTS(smps_ranges);
100static struct vreg_set_points ftsmps_set_points = SET_POINTS(ftsmps_ranges);
David Collins49177a72012-02-06 17:01:19 -0800101static struct vreg_set_points corner_set_points = SET_POINTS(corner_ranges);
David Collins5779cea2012-01-05 15:09:21 -0800102
103static struct vreg_set_points *all_set_points[] = {
104 &pldo_set_points,
105 &nldo_set_points,
106 &nldo1200_set_points,
David Collins18a54422012-08-09 14:41:06 -0700107 &ln_ldo_set_points,
David Collins5779cea2012-01-05 15:09:21 -0800108 &smps_set_points,
109 &ftsmps_set_points,
David Collins49177a72012-02-06 17:01:19 -0800110 &corner_set_points,
David Collins5779cea2012-01-05 15:09:21 -0800111};
112
David Collins62ae8d92012-07-31 16:29:43 -0700113#define LDO(_id, _name, _name_pc, _ranges, _hpm_min_load, _requires_cxo) \
David Collins5779cea2012-01-05 15:09:21 -0800114 [RPM_VREG_ID_PM8038_##_id] = { \
115 .req = { \
116 [0] = { .id = MSM_RPM_ID_PM8038_##_id##_0, }, \
117 [1] = { .id = MSM_RPM_ID_PM8038_##_id##_1, }, \
118 }, \
119 .hpm_min_load = RPM_VREG_8930_##_hpm_min_load##_HPM_MIN_LOAD, \
120 .type = RPM_REGULATOR_TYPE_LDO, \
121 .set_points = &_ranges##_set_points, \
122 .part = &ldo_parts, \
123 .id = RPM_VREG_ID_PM8038_##_id, \
124 .rdesc.name = _name, \
125 .rdesc_pc.name = _name_pc, \
David Collins62ae8d92012-07-31 16:29:43 -0700126 .requires_cxo = _requires_cxo, \
David Collins5779cea2012-01-05 15:09:21 -0800127 }
128
129#define SMPS(_id, _name, _name_pc, _ranges, _hpm_min_load) \
130 [RPM_VREG_ID_PM8038_##_id] = { \
131 .req = { \
132 [0] = { .id = MSM_RPM_ID_PM8038_##_id##_0, }, \
133 [1] = { .id = MSM_RPM_ID_PM8038_##_id##_1, }, \
134 }, \
135 .hpm_min_load = RPM_VREG_8930_##_hpm_min_load##_HPM_MIN_LOAD, \
136 .type = RPM_REGULATOR_TYPE_SMPS, \
137 .set_points = &_ranges##_set_points, \
138 .part = &smps_parts, \
139 .id = RPM_VREG_ID_PM8038_##_id, \
140 .rdesc.name = _name, \
141 .rdesc_pc.name = _name_pc, \
142 }
143
144#define LVS(_id, _name, _name_pc) \
145 [RPM_VREG_ID_PM8038_##_id] = { \
146 .req = { \
147 [0] = { .id = MSM_RPM_ID_PM8038_##_id, }, \
148 [1] = { .id = -1, }, \
149 }, \
150 .type = RPM_REGULATOR_TYPE_VS, \
151 .part = &switch_parts, \
152 .id = RPM_VREG_ID_PM8038_##_id, \
153 .rdesc.name = _name, \
154 .rdesc_pc.name = _name_pc, \
155 }
156
David Collins49177a72012-02-06 17:01:19 -0800157#define CORNER(_id, _rpm_id, _name, _ranges) \
158 [RPM_VREG_ID_PM8038_##_id] = { \
159 .req = { \
160 [0] = { .id = MSM_RPM_ID_##_rpm_id, }, \
161 [1] = { .id = -1, }, \
162 }, \
163 .type = RPM_REGULATOR_TYPE_CORNER, \
164 .set_points = &_ranges##_set_points, \
165 .part = &corner_parts, \
166 .id = RPM_VREG_ID_PM8038_##_id, \
167 .rdesc.name = _name, \
168 }
169
David Collins5779cea2012-01-05 15:09:21 -0800170static struct vreg vregs[] = {
David Collins62ae8d92012-07-31 16:29:43 -0700171 LDO(L1, "8038_l1", NULL, nldo1200, LDO_1200, 1),
172 LDO(L2, "8038_l2", "8038_l2_pc", nldo, LDO_150, 1),
173 LDO(L3, "8038_l3", "8038_l3_pc", pldo, LDO_50, 0),
174 LDO(L4, "8038_l4", "8038_l4_pc", pldo, LDO_50, 0),
175 LDO(L5, "8038_l5", "8038_l5_pc", pldo, LDO_600, 0),
176 LDO(L6, "8038_l6", "8038_l6_pc", pldo, LDO_600, 0),
177 LDO(L7, "8038_l7", "8038_l7_pc", pldo, LDO_600, 0),
178 LDO(L8, "8038_l8", "8038_l8_pc", pldo, LDO_300, 0),
179 LDO(L9, "8038_l9", "8038_l9_pc", pldo, LDO_300, 0),
180 LDO(L10, "8038_l10", "8038_l10_pc", pldo, LDO_600, 0),
181 LDO(L11, "8038_l11", "8038_l11_pc", pldo, LDO_600, 0),
182 LDO(L12, "8038_l12", "8038_l12_pc", nldo, LDO_300, 1),
David Collins18a54422012-08-09 14:41:06 -0700183 LDO(L13, "8038_l13", NULL, ln_ldo, LDO_5, 0),
David Collins62ae8d92012-07-31 16:29:43 -0700184 LDO(L14, "8038_l14", "8038_l14_pc", pldo, LDO_50, 0),
185 LDO(L15, "8038_l15", "8038_l15_pc", pldo, LDO_150, 0),
186 LDO(L16, "8038_l16", NULL, nldo1200, LDO_1200, 1),
187 LDO(L17, "8038_l17", "8038_l17_pc", pldo, LDO_150, 0),
188 LDO(L18, "8038_l18", "8038_l18_pc", pldo, LDO_50, 0),
189 LDO(L19, "8038_l19", NULL, nldo1200, LDO_1200, 1),
190 LDO(L20, "8038_l20", NULL, nldo1200, LDO_1200, 1),
191 LDO(L21, "8038_l21", "8038_l21_pc", pldo, LDO_150, 0),
192 LDO(L22, "8038_l22", "8038_l22_pc", pldo, LDO_50, 0),
193 LDO(L23, "8038_l23", "8038_l23_pc", pldo, LDO_50, 0),
194 LDO(L24, "8038_l24", NULL, nldo1200, LDO_1200, 1),
David Collins18a54422012-08-09 14:41:06 -0700195 LDO(L25, "8038_l25", NULL, ln_ldo, LDO_5, 0),
David Collins62ae8d92012-07-31 16:29:43 -0700196 LDO(L26, "8038_l26", "8038_l26_pc", nldo, LDO_150, 1),
197 LDO(L27, "8038_l27", NULL, nldo1200, LDO_1200, 1),
David Collins5779cea2012-01-05 15:09:21 -0800198
199 SMPS(S1, "8038_s1", "8038_s1_pc", smps, SMPS_1500),
200 SMPS(S2, "8038_s2", "8038_s2_pc", smps, SMPS_1500),
201 SMPS(S3, "8038_s3", "8038_s3_pc", smps, SMPS_1500),
202 SMPS(S4, "8038_s4", "8038_s4_pc", smps, SMPS_1500),
203 SMPS(S5, "8038_s5", NULL, ftsmps, SMPS_2000),
204 SMPS(S6, "8038_s6", NULL, ftsmps, SMPS_2000),
205
206 LVS(LVS1, "8038_lvs1", "8038_lvs1_pc"),
207 LVS(LVS2, "8038_lvs2", "8038_lvs2_pc"),
David Collins49177a72012-02-06 17:01:19 -0800208
209 CORNER(VDD_DIG_CORNER, VOLTAGE_CORNER, "vdd_dig_corner", corner),
David Collins5779cea2012-01-05 15:09:21 -0800210};
211
212static const char *pin_func_label[] = {
213 [RPM_VREG_PIN_FN_8930_DONT_CARE] = "don't care",
214 [RPM_VREG_PIN_FN_8930_ENABLE] = "on/off",
215 [RPM_VREG_PIN_FN_8930_MODE] = "HPM/LPM",
216 [RPM_VREG_PIN_FN_8930_SLEEP_B] = "sleep_b",
217 [RPM_VREG_PIN_FN_8930_NONE] = "none",
218};
219
220static const char *force_mode_label[] = {
221 [RPM_VREG_FORCE_MODE_8930_NONE] = "none",
222 [RPM_VREG_FORCE_MODE_8930_LPM] = "LPM",
223 [RPM_VREG_FORCE_MODE_8930_AUTO] = "auto",
224 [RPM_VREG_FORCE_MODE_8930_HPM] = "HPM",
225 [RPM_VREG_FORCE_MODE_8930_BYPASS] = "BYP",
226};
227
228static const char *power_mode_label[] = {
229 [RPM_VREG_POWER_MODE_8930_HYSTERETIC] = "HYS",
230 [RPM_VREG_POWER_MODE_8930_PWM] = "PWM",
231};
232
233static const char *pin_control_label[] = {
234 " D1",
235 " A0",
236 " A1",
237 " A2",
238};
239
240static int is_real_id(int id)
241{
242 return (id >= 0) && (id <= RPM_VREG_ID_PM8038_MAX_REAL);
243}
244
245static int pc_id_to_real_id(int id)
246{
247 int real_id = 0;
248
David Collins18a54422012-08-09 14:41:06 -0700249 if (id >= RPM_VREG_ID_PM8038_L2_PC && id <= RPM_VREG_ID_PM8038_L12_PC)
David Collins5779cea2012-01-05 15:09:21 -0800250 real_id = id - RPM_VREG_ID_PM8038_L2_PC;
David Collins18a54422012-08-09 14:41:06 -0700251 else if (id >= RPM_VREG_ID_PM8038_L14_PC
252 && id <= RPM_VREG_ID_PM8038_L15_PC)
253 real_id = id - RPM_VREG_ID_PM8038_L14_PC
254 + RPM_VREG_ID_PM8038_L14;
David Collins5779cea2012-01-05 15:09:21 -0800255 else if (id >= RPM_VREG_ID_PM8038_L17_PC
256 && id <= RPM_VREG_ID_PM8038_L18_PC)
257 real_id = id - RPM_VREG_ID_PM8038_L17_PC
258 + RPM_VREG_ID_PM8038_L17;
259 else if (id >= RPM_VREG_ID_PM8038_L21_PC
260 && id <= RPM_VREG_ID_PM8038_L23_PC)
261 real_id = id - RPM_VREG_ID_PM8038_L21_PC
262 + RPM_VREG_ID_PM8038_L21;
263 else if (id == RPM_VREG_ID_PM8038_L26_PC)
264 real_id = RPM_VREG_ID_PM8038_L26;
265 else if (id >= RPM_VREG_ID_PM8038_S1_PC
266 && id <= RPM_VREG_ID_PM8038_S4_PC)
267 real_id = id - RPM_VREG_ID_PM8038_S1_PC
268 + RPM_VREG_ID_PM8038_S1;
269 else if (id >= RPM_VREG_ID_PM8038_LVS1_PC
270 && id <= RPM_VREG_ID_PM8038_LVS2_PC)
271 real_id = id - RPM_VREG_ID_PM8038_LVS1_PC
272 + RPM_VREG_ID_PM8038_LVS1;
273
274 return real_id;
275}
276
277static struct vreg_config config = {
278 .vregs = vregs,
279 .vregs_len = ARRAY_SIZE(vregs),
280
281 .vreg_id_min = RPM_VREG_ID_PM8038_L1,
282 .vreg_id_max = RPM_VREG_ID_PM8038_MAX,
283
284 .pin_func_none = RPM_VREG_PIN_FN_8930_NONE,
285 .pin_func_sleep_b = RPM_VREG_PIN_FN_8930_SLEEP_B,
286
287 .mode_lpm = REGULATOR_MODE_IDLE,
288 .mode_hpm = REGULATOR_MODE_NORMAL,
289
290 .set_points = all_set_points,
291 .set_points_len = ARRAY_SIZE(all_set_points),
292
293 .label_pin_ctrl = pin_control_label,
294 .label_pin_ctrl_len = ARRAY_SIZE(pin_control_label),
295 .label_pin_func = pin_func_label,
296 .label_pin_func_len = ARRAY_SIZE(pin_func_label),
297 .label_force_mode = force_mode_label,
298 .label_force_mode_len = ARRAY_SIZE(force_mode_label),
299 .label_power_mode = power_mode_label,
300 .label_power_mode_len = ARRAY_SIZE(power_mode_label),
301
302 .is_real_id = is_real_id,
303 .pc_id_to_real_id = pc_id_to_real_id,
304};
305
306struct vreg_config *get_config_8930(void)
307{
308 return &config;
309}