blob: f396fed9764ada7670adb64505a5743f6148145f [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
106#define LDO(_id, _name, _name_pc, _ranges, _hpm_min_load) \
107 [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, \
119 }
120
121#define SMPS(_id, _name, _name_pc, _ranges, _hpm_min_load) \
122 [RPM_VREG_ID_PM8038_##_id] = { \
123 .req = { \
124 [0] = { .id = MSM_RPM_ID_PM8038_##_id##_0, }, \
125 [1] = { .id = MSM_RPM_ID_PM8038_##_id##_1, }, \
126 }, \
127 .hpm_min_load = RPM_VREG_8930_##_hpm_min_load##_HPM_MIN_LOAD, \
128 .type = RPM_REGULATOR_TYPE_SMPS, \
129 .set_points = &_ranges##_set_points, \
130 .part = &smps_parts, \
131 .id = RPM_VREG_ID_PM8038_##_id, \
132 .rdesc.name = _name, \
133 .rdesc_pc.name = _name_pc, \
134 }
135
136#define LVS(_id, _name, _name_pc) \
137 [RPM_VREG_ID_PM8038_##_id] = { \
138 .req = { \
139 [0] = { .id = MSM_RPM_ID_PM8038_##_id, }, \
140 [1] = { .id = -1, }, \
141 }, \
142 .type = RPM_REGULATOR_TYPE_VS, \
143 .part = &switch_parts, \
144 .id = RPM_VREG_ID_PM8038_##_id, \
145 .rdesc.name = _name, \
146 .rdesc_pc.name = _name_pc, \
147 }
148
David Collins49177a72012-02-06 17:01:19 -0800149#define CORNER(_id, _rpm_id, _name, _ranges) \
150 [RPM_VREG_ID_PM8038_##_id] = { \
151 .req = { \
152 [0] = { .id = MSM_RPM_ID_##_rpm_id, }, \
153 [1] = { .id = -1, }, \
154 }, \
155 .type = RPM_REGULATOR_TYPE_CORNER, \
156 .set_points = &_ranges##_set_points, \
157 .part = &corner_parts, \
158 .id = RPM_VREG_ID_PM8038_##_id, \
159 .rdesc.name = _name, \
160 }
161
David Collins5779cea2012-01-05 15:09:21 -0800162static struct vreg vregs[] = {
163 LDO(L1, "8038_l1", NULL, nldo1200, LDO_1200),
164 LDO(L2, "8038_l2", "8038_l2_pc", nldo, LDO_150),
165 LDO(L3, "8038_l3", "8038_l3_pc", pldo, LDO_50),
166 LDO(L4, "8038_l4", "8038_l4_pc", pldo, LDO_50),
167 LDO(L5, "8038_l5", "8038_l5_pc", pldo, LDO_600),
168 LDO(L6, "8038_l6", "8038_l6_pc", pldo, LDO_600),
169 LDO(L7, "8038_l7", "8038_l7_pc", pldo, LDO_600),
170 LDO(L8, "8038_l8", "8038_l8_pc", pldo, LDO_300),
171 LDO(L9, "8038_l9", "8038_l9_pc", pldo, LDO_300),
172 LDO(L10, "8038_l10", "8038_l10_pc", pldo, LDO_600),
173 LDO(L11, "8038_l11", "8038_l11_pc", pldo, LDO_600),
174 LDO(L12, "8038_l12", "8038_l12_pc", nldo, LDO_300),
175 LDO(L14, "8038_l14", "8038_l14_pc", pldo, LDO_50),
176 LDO(L15, "8038_l15", "8038_l15_pc", pldo, LDO_150),
177 LDO(L16, "8038_l16", NULL, nldo1200, LDO_1200),
178 LDO(L17, "8038_l17", "8038_l17_pc", pldo, LDO_150),
179 LDO(L18, "8038_l18", "8038_l18_pc", pldo, LDO_50),
180 LDO(L19, "8038_l19", NULL, nldo1200, LDO_1200),
181 LDO(L20, "8038_l20", NULL, nldo1200, LDO_1200),
182 LDO(L21, "8038_l21", "8038_l21_pc", pldo, LDO_150),
183 LDO(L22, "8038_l22", "8038_l22_pc", pldo, LDO_50),
184 LDO(L23, "8038_l23", "8038_l23_pc", pldo, LDO_50),
185 LDO(L24, "8038_l24", NULL, nldo1200, LDO_1200),
186 LDO(L26, "8038_l26", "8038_l26_pc", nldo, LDO_150),
187 LDO(L27, "8038_l27", NULL, nldo1200, LDO_1200),
188
189 SMPS(S1, "8038_s1", "8038_s1_pc", smps, SMPS_1500),
190 SMPS(S2, "8038_s2", "8038_s2_pc", smps, SMPS_1500),
191 SMPS(S3, "8038_s3", "8038_s3_pc", smps, SMPS_1500),
192 SMPS(S4, "8038_s4", "8038_s4_pc", smps, SMPS_1500),
193 SMPS(S5, "8038_s5", NULL, ftsmps, SMPS_2000),
194 SMPS(S6, "8038_s6", NULL, ftsmps, SMPS_2000),
195
196 LVS(LVS1, "8038_lvs1", "8038_lvs1_pc"),
197 LVS(LVS2, "8038_lvs2", "8038_lvs2_pc"),
David Collins49177a72012-02-06 17:01:19 -0800198
199 CORNER(VDD_DIG_CORNER, VOLTAGE_CORNER, "vdd_dig_corner", corner),
David Collins5779cea2012-01-05 15:09:21 -0800200};
201
202static const char *pin_func_label[] = {
203 [RPM_VREG_PIN_FN_8930_DONT_CARE] = "don't care",
204 [RPM_VREG_PIN_FN_8930_ENABLE] = "on/off",
205 [RPM_VREG_PIN_FN_8930_MODE] = "HPM/LPM",
206 [RPM_VREG_PIN_FN_8930_SLEEP_B] = "sleep_b",
207 [RPM_VREG_PIN_FN_8930_NONE] = "none",
208};
209
210static const char *force_mode_label[] = {
211 [RPM_VREG_FORCE_MODE_8930_NONE] = "none",
212 [RPM_VREG_FORCE_MODE_8930_LPM] = "LPM",
213 [RPM_VREG_FORCE_MODE_8930_AUTO] = "auto",
214 [RPM_VREG_FORCE_MODE_8930_HPM] = "HPM",
215 [RPM_VREG_FORCE_MODE_8930_BYPASS] = "BYP",
216};
217
218static const char *power_mode_label[] = {
219 [RPM_VREG_POWER_MODE_8930_HYSTERETIC] = "HYS",
220 [RPM_VREG_POWER_MODE_8930_PWM] = "PWM",
221};
222
223static const char *pin_control_label[] = {
224 " D1",
225 " A0",
226 " A1",
227 " A2",
228};
229
230static int is_real_id(int id)
231{
232 return (id >= 0) && (id <= RPM_VREG_ID_PM8038_MAX_REAL);
233}
234
235static int pc_id_to_real_id(int id)
236{
237 int real_id = 0;
238
239 if (id >= RPM_VREG_ID_PM8038_L2_PC && id <= RPM_VREG_ID_PM8038_L15_PC)
240 real_id = id - RPM_VREG_ID_PM8038_L2_PC;
241 else if (id >= RPM_VREG_ID_PM8038_L17_PC
242 && id <= RPM_VREG_ID_PM8038_L18_PC)
243 real_id = id - RPM_VREG_ID_PM8038_L17_PC
244 + RPM_VREG_ID_PM8038_L17;
245 else if (id >= RPM_VREG_ID_PM8038_L21_PC
246 && id <= RPM_VREG_ID_PM8038_L23_PC)
247 real_id = id - RPM_VREG_ID_PM8038_L21_PC
248 + RPM_VREG_ID_PM8038_L21;
249 else if (id == RPM_VREG_ID_PM8038_L26_PC)
250 real_id = RPM_VREG_ID_PM8038_L26;
251 else if (id >= RPM_VREG_ID_PM8038_S1_PC
252 && id <= RPM_VREG_ID_PM8038_S4_PC)
253 real_id = id - RPM_VREG_ID_PM8038_S1_PC
254 + RPM_VREG_ID_PM8038_S1;
255 else if (id >= RPM_VREG_ID_PM8038_LVS1_PC
256 && id <= RPM_VREG_ID_PM8038_LVS2_PC)
257 real_id = id - RPM_VREG_ID_PM8038_LVS1_PC
258 + RPM_VREG_ID_PM8038_LVS1;
259
260 return real_id;
261}
262
263static struct vreg_config config = {
264 .vregs = vregs,
265 .vregs_len = ARRAY_SIZE(vregs),
266
267 .vreg_id_min = RPM_VREG_ID_PM8038_L1,
268 .vreg_id_max = RPM_VREG_ID_PM8038_MAX,
269
270 .pin_func_none = RPM_VREG_PIN_FN_8930_NONE,
271 .pin_func_sleep_b = RPM_VREG_PIN_FN_8930_SLEEP_B,
272
273 .mode_lpm = REGULATOR_MODE_IDLE,
274 .mode_hpm = REGULATOR_MODE_NORMAL,
275
276 .set_points = all_set_points,
277 .set_points_len = ARRAY_SIZE(all_set_points),
278
279 .label_pin_ctrl = pin_control_label,
280 .label_pin_ctrl_len = ARRAY_SIZE(pin_control_label),
281 .label_pin_func = pin_func_label,
282 .label_pin_func_len = ARRAY_SIZE(pin_func_label),
283 .label_force_mode = force_mode_label,
284 .label_force_mode_len = ARRAY_SIZE(force_mode_label),
285 .label_power_mode = power_mode_label,
286 .label_power_mode_len = ARRAY_SIZE(power_mode_label),
287
288 .is_real_id = is_real_id,
289 .pc_id_to_real_id = pc_id_to_real_id,
290};
291
292struct vreg_config *get_config_8930(void)
293{
294 return &config;
295}