blob: 22595ec6dc857c590b54f41006c6227827a3a8f6 [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
53/* Physically available PMIC regulator voltage setpoint ranges */
54static struct vreg_range pldo_ranges[] = {
55 VOLTAGE_RANGE( 750000, 1487500, 12500),
56 VOLTAGE_RANGE(1500000, 3075000, 25000),
57 VOLTAGE_RANGE(3100000, 4900000, 50000),
58};
59
60static struct vreg_range nldo_ranges[] = {
61 VOLTAGE_RANGE( 750000, 1537500, 12500),
62};
63
64static struct vreg_range nldo1200_ranges[] = {
65 VOLTAGE_RANGE( 375000, 743750, 6250),
66 VOLTAGE_RANGE( 750000, 1537500, 12500),
67};
68
69static struct vreg_range smps_ranges[] = {
70 VOLTAGE_RANGE( 375000, 737500, 12500),
71 VOLTAGE_RANGE( 750000, 1487500, 12500),
72 VOLTAGE_RANGE(1500000, 3075000, 25000),
73};
74
75static struct vreg_range ftsmps_ranges[] = {
76 VOLTAGE_RANGE( 350000, 650000, 50000),
77 VOLTAGE_RANGE( 700000, 1400000, 12500),
78 VOLTAGE_RANGE(1500000, 3300000, 50000),
79};
80
81static struct vreg_set_points pldo_set_points = SET_POINTS(pldo_ranges);
82static struct vreg_set_points nldo_set_points = SET_POINTS(nldo_ranges);
83static struct vreg_set_points nldo1200_set_points = SET_POINTS(nldo1200_ranges);
84static struct vreg_set_points smps_set_points = SET_POINTS(smps_ranges);
85static struct vreg_set_points ftsmps_set_points = SET_POINTS(ftsmps_ranges);
86
87static struct vreg_set_points *all_set_points[] = {
88 &pldo_set_points,
89 &nldo_set_points,
90 &nldo1200_set_points,
91 &smps_set_points,
92 &ftsmps_set_points,
93};
94
95#define LDO(_id, _name, _name_pc, _ranges, _hpm_min_load) \
96 [RPM_VREG_ID_PM8038_##_id] = { \
97 .req = { \
98 [0] = { .id = MSM_RPM_ID_PM8038_##_id##_0, }, \
99 [1] = { .id = MSM_RPM_ID_PM8038_##_id##_1, }, \
100 }, \
101 .hpm_min_load = RPM_VREG_8930_##_hpm_min_load##_HPM_MIN_LOAD, \
102 .type = RPM_REGULATOR_TYPE_LDO, \
103 .set_points = &_ranges##_set_points, \
104 .part = &ldo_parts, \
105 .id = RPM_VREG_ID_PM8038_##_id, \
106 .rdesc.name = _name, \
107 .rdesc_pc.name = _name_pc, \
108 }
109
110#define SMPS(_id, _name, _name_pc, _ranges, _hpm_min_load) \
111 [RPM_VREG_ID_PM8038_##_id] = { \
112 .req = { \
113 [0] = { .id = MSM_RPM_ID_PM8038_##_id##_0, }, \
114 [1] = { .id = MSM_RPM_ID_PM8038_##_id##_1, }, \
115 }, \
116 .hpm_min_load = RPM_VREG_8930_##_hpm_min_load##_HPM_MIN_LOAD, \
117 .type = RPM_REGULATOR_TYPE_SMPS, \
118 .set_points = &_ranges##_set_points, \
119 .part = &smps_parts, \
120 .id = RPM_VREG_ID_PM8038_##_id, \
121 .rdesc.name = _name, \
122 .rdesc_pc.name = _name_pc, \
123 }
124
125#define LVS(_id, _name, _name_pc) \
126 [RPM_VREG_ID_PM8038_##_id] = { \
127 .req = { \
128 [0] = { .id = MSM_RPM_ID_PM8038_##_id, }, \
129 [1] = { .id = -1, }, \
130 }, \
131 .type = RPM_REGULATOR_TYPE_VS, \
132 .part = &switch_parts, \
133 .id = RPM_VREG_ID_PM8038_##_id, \
134 .rdesc.name = _name, \
135 .rdesc_pc.name = _name_pc, \
136 }
137
138static struct vreg vregs[] = {
139 LDO(L1, "8038_l1", NULL, nldo1200, LDO_1200),
140 LDO(L2, "8038_l2", "8038_l2_pc", nldo, LDO_150),
141 LDO(L3, "8038_l3", "8038_l3_pc", pldo, LDO_50),
142 LDO(L4, "8038_l4", "8038_l4_pc", pldo, LDO_50),
143 LDO(L5, "8038_l5", "8038_l5_pc", pldo, LDO_600),
144 LDO(L6, "8038_l6", "8038_l6_pc", pldo, LDO_600),
145 LDO(L7, "8038_l7", "8038_l7_pc", pldo, LDO_600),
146 LDO(L8, "8038_l8", "8038_l8_pc", pldo, LDO_300),
147 LDO(L9, "8038_l9", "8038_l9_pc", pldo, LDO_300),
148 LDO(L10, "8038_l10", "8038_l10_pc", pldo, LDO_600),
149 LDO(L11, "8038_l11", "8038_l11_pc", pldo, LDO_600),
150 LDO(L12, "8038_l12", "8038_l12_pc", nldo, LDO_300),
151 LDO(L14, "8038_l14", "8038_l14_pc", pldo, LDO_50),
152 LDO(L15, "8038_l15", "8038_l15_pc", pldo, LDO_150),
153 LDO(L16, "8038_l16", NULL, nldo1200, LDO_1200),
154 LDO(L17, "8038_l17", "8038_l17_pc", pldo, LDO_150),
155 LDO(L18, "8038_l18", "8038_l18_pc", pldo, LDO_50),
156 LDO(L19, "8038_l19", NULL, nldo1200, LDO_1200),
157 LDO(L20, "8038_l20", NULL, nldo1200, LDO_1200),
158 LDO(L21, "8038_l21", "8038_l21_pc", pldo, LDO_150),
159 LDO(L22, "8038_l22", "8038_l22_pc", pldo, LDO_50),
160 LDO(L23, "8038_l23", "8038_l23_pc", pldo, LDO_50),
161 LDO(L24, "8038_l24", NULL, nldo1200, LDO_1200),
162 LDO(L26, "8038_l26", "8038_l26_pc", nldo, LDO_150),
163 LDO(L27, "8038_l27", NULL, nldo1200, LDO_1200),
164
165 SMPS(S1, "8038_s1", "8038_s1_pc", smps, SMPS_1500),
166 SMPS(S2, "8038_s2", "8038_s2_pc", smps, SMPS_1500),
167 SMPS(S3, "8038_s3", "8038_s3_pc", smps, SMPS_1500),
168 SMPS(S4, "8038_s4", "8038_s4_pc", smps, SMPS_1500),
169 SMPS(S5, "8038_s5", NULL, ftsmps, SMPS_2000),
170 SMPS(S6, "8038_s6", NULL, ftsmps, SMPS_2000),
171
172 LVS(LVS1, "8038_lvs1", "8038_lvs1_pc"),
173 LVS(LVS2, "8038_lvs2", "8038_lvs2_pc"),
174};
175
176static const char *pin_func_label[] = {
177 [RPM_VREG_PIN_FN_8930_DONT_CARE] = "don't care",
178 [RPM_VREG_PIN_FN_8930_ENABLE] = "on/off",
179 [RPM_VREG_PIN_FN_8930_MODE] = "HPM/LPM",
180 [RPM_VREG_PIN_FN_8930_SLEEP_B] = "sleep_b",
181 [RPM_VREG_PIN_FN_8930_NONE] = "none",
182};
183
184static const char *force_mode_label[] = {
185 [RPM_VREG_FORCE_MODE_8930_NONE] = "none",
186 [RPM_VREG_FORCE_MODE_8930_LPM] = "LPM",
187 [RPM_VREG_FORCE_MODE_8930_AUTO] = "auto",
188 [RPM_VREG_FORCE_MODE_8930_HPM] = "HPM",
189 [RPM_VREG_FORCE_MODE_8930_BYPASS] = "BYP",
190};
191
192static const char *power_mode_label[] = {
193 [RPM_VREG_POWER_MODE_8930_HYSTERETIC] = "HYS",
194 [RPM_VREG_POWER_MODE_8930_PWM] = "PWM",
195};
196
197static const char *pin_control_label[] = {
198 " D1",
199 " A0",
200 " A1",
201 " A2",
202};
203
204static int is_real_id(int id)
205{
206 return (id >= 0) && (id <= RPM_VREG_ID_PM8038_MAX_REAL);
207}
208
209static int pc_id_to_real_id(int id)
210{
211 int real_id = 0;
212
213 if (id >= RPM_VREG_ID_PM8038_L2_PC && id <= RPM_VREG_ID_PM8038_L15_PC)
214 real_id = id - RPM_VREG_ID_PM8038_L2_PC;
215 else if (id >= RPM_VREG_ID_PM8038_L17_PC
216 && id <= RPM_VREG_ID_PM8038_L18_PC)
217 real_id = id - RPM_VREG_ID_PM8038_L17_PC
218 + RPM_VREG_ID_PM8038_L17;
219 else if (id >= RPM_VREG_ID_PM8038_L21_PC
220 && id <= RPM_VREG_ID_PM8038_L23_PC)
221 real_id = id - RPM_VREG_ID_PM8038_L21_PC
222 + RPM_VREG_ID_PM8038_L21;
223 else if (id == RPM_VREG_ID_PM8038_L26_PC)
224 real_id = RPM_VREG_ID_PM8038_L26;
225 else if (id >= RPM_VREG_ID_PM8038_S1_PC
226 && id <= RPM_VREG_ID_PM8038_S4_PC)
227 real_id = id - RPM_VREG_ID_PM8038_S1_PC
228 + RPM_VREG_ID_PM8038_S1;
229 else if (id >= RPM_VREG_ID_PM8038_LVS1_PC
230 && id <= RPM_VREG_ID_PM8038_LVS2_PC)
231 real_id = id - RPM_VREG_ID_PM8038_LVS1_PC
232 + RPM_VREG_ID_PM8038_LVS1;
233
234 return real_id;
235}
236
237static struct vreg_config config = {
238 .vregs = vregs,
239 .vregs_len = ARRAY_SIZE(vregs),
240
241 .vreg_id_min = RPM_VREG_ID_PM8038_L1,
242 .vreg_id_max = RPM_VREG_ID_PM8038_MAX,
243
244 .pin_func_none = RPM_VREG_PIN_FN_8930_NONE,
245 .pin_func_sleep_b = RPM_VREG_PIN_FN_8930_SLEEP_B,
246
247 .mode_lpm = REGULATOR_MODE_IDLE,
248 .mode_hpm = REGULATOR_MODE_NORMAL,
249
250 .set_points = all_set_points,
251 .set_points_len = ARRAY_SIZE(all_set_points),
252
253 .label_pin_ctrl = pin_control_label,
254 .label_pin_ctrl_len = ARRAY_SIZE(pin_control_label),
255 .label_pin_func = pin_func_label,
256 .label_pin_func_len = ARRAY_SIZE(pin_func_label),
257 .label_force_mode = force_mode_label,
258 .label_force_mode_len = ARRAY_SIZE(force_mode_label),
259 .label_power_mode = power_mode_label,
260 .label_power_mode_len = ARRAY_SIZE(power_mode_label),
261
262 .is_real_id = is_real_id,
263 .pc_id_to_real_id = pc_id_to_real_id,
264};
265
266struct vreg_config *get_config_8930(void)
267{
268 return &config;
269}