blob: 6c4a9adf966a2b5ea76b8d6b9e7b0df98368c003 [file] [log] [blame]
David Collins6f032ba2011-08-31 14:08:15 -07001/*
2 * Copyright (c) 2011, 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 .mV = REQUEST_MEMBER(0, 0x00000FFF, 0),
22 .ip = REQUEST_MEMBER(0, 0x00FFF000, 12),
23 .fm = REQUEST_MEMBER(0, 0x03000000, 24),
24 .pc = REQUEST_MEMBER(0, 0x3C000000, 26),
25 .pf = REQUEST_MEMBER(0, 0xC0000000, 30),
26 .pd = REQUEST_MEMBER(1, 0x00000001, 0),
27 .ia = REQUEST_MEMBER(1, 0x00001FFE, 1),
28};
29
30static struct rpm_vreg_parts smps_parts = {
31 .request_len = 2,
32 .mV = REQUEST_MEMBER(0, 0x00000FFF, 0),
33 .ip = REQUEST_MEMBER(0, 0x00FFF000, 12),
34 .fm = REQUEST_MEMBER(0, 0x03000000, 24),
35 .pc = REQUEST_MEMBER(0, 0x3C000000, 26),
36 .pf = REQUEST_MEMBER(0, 0xC0000000, 30),
37 .pd = REQUEST_MEMBER(1, 0x00000001, 0),
38 .ia = REQUEST_MEMBER(1, 0x00001FFE, 1),
39 .freq = REQUEST_MEMBER(1, 0x001FE000, 13),
40 .freq_clk_src = REQUEST_MEMBER(1, 0x00600000, 21),
41};
42
43static struct rpm_vreg_parts switch_parts = {
44 .request_len = 1,
45 .enable_state = REQUEST_MEMBER(0, 0x00000001, 0),
46 .pd = REQUEST_MEMBER(0, 0x00000002, 1),
47 .pc = REQUEST_MEMBER(0, 0x0000003C, 2),
48 .pf = REQUEST_MEMBER(0, 0x000000C0, 6),
49 .hpm = REQUEST_MEMBER(0, 0x00000300, 8),
50};
51
52static struct rpm_vreg_parts ncp_parts = {
53 .request_len = 1,
54 .mV = REQUEST_MEMBER(0, 0x00000FFF, 0),
55 .enable_state = REQUEST_MEMBER(0, 0x00001000, 12),
56 .comp_mode = REQUEST_MEMBER(0, 0x00002000, 13),
57 .freq = REQUEST_MEMBER(0, 0x003FC000, 14),
58};
59
60/* Physically available PMIC regulator voltage setpoint ranges */
61static struct vreg_range pldo_ranges[] = {
62 VOLTAGE_RANGE( 750000, 1487500, 12500),
63 VOLTAGE_RANGE(1500000, 3075000, 25000),
64 VOLTAGE_RANGE(3100000, 4900000, 50000),
65};
66
67static struct vreg_range nldo_ranges[] = {
68 VOLTAGE_RANGE( 750000, 1537500, 12500),
69};
70
71static struct vreg_range smps_ranges[] = {
72 VOLTAGE_RANGE( 375000, 737500, 12500),
73 VOLTAGE_RANGE( 750000, 1487500, 12500),
74 VOLTAGE_RANGE(1500000, 3075000, 25000),
75};
76
77static struct vreg_range ftsmps_ranges[] = {
78 VOLTAGE_RANGE( 350000, 650000, 50000),
79 VOLTAGE_RANGE( 700000, 1400000, 12500),
80 VOLTAGE_RANGE(1500000, 3300000, 50000),
81};
82
83static struct vreg_range ncp_ranges[] = {
84 VOLTAGE_RANGE(1500000, 3050000, 50000),
85};
86
87static struct vreg_set_points pldo_set_points = SET_POINTS(pldo_ranges);
88static struct vreg_set_points nldo_set_points = SET_POINTS(nldo_ranges);
89static struct vreg_set_points smps_set_points = SET_POINTS(smps_ranges);
90static struct vreg_set_points ftsmps_set_points = SET_POINTS(ftsmps_ranges);
91static struct vreg_set_points ncp_set_points = SET_POINTS(ncp_ranges);
92
93static struct vreg_set_points *all_set_points[] = {
94 &pldo_set_points,
95 &nldo_set_points,
96 &smps_set_points,
97 &ftsmps_set_points,
98 &ncp_set_points,
99};
100
101#define LDO(_vreg_id, _rpm_id, _name, _name_pc, _ranges, _hpm_min_load) \
102 [RPM_VREG_ID_##_vreg_id] = { \
103 .req = { \
104 [0] = { .id = MSM_RPM_ID_##_rpm_id##_0, }, \
105 [1] = { .id = MSM_RPM_ID_##_rpm_id##_1, }, \
106 }, \
107 .hpm_min_load = RPM_VREG_8660_##_hpm_min_load##_HPM_MIN_LOAD, \
108 .type = RPM_REGULATOR_TYPE_LDO, \
109 .set_points = &_ranges##_set_points, \
110 .part = &ldo_parts, \
111 .id = RPM_VREG_ID_##_vreg_id, \
112 .rdesc.name = _name, \
113 .rdesc_pc.name = _name_pc, \
114 }
115
116#define SMPS(_vreg_id, _rpm_id, _name, _name_pc, _ranges, _hpm_min_load) \
117 [RPM_VREG_ID_##_vreg_id] = { \
118 .req = { \
119 [0] = { .id = MSM_RPM_ID_##_rpm_id##_0, }, \
120 [1] = { .id = MSM_RPM_ID_##_rpm_id##_1, }, \
121 }, \
122 .hpm_min_load = RPM_VREG_8660_##_hpm_min_load##_HPM_MIN_LOAD, \
123 .type = RPM_REGULATOR_TYPE_SMPS, \
124 .set_points = &_ranges##_set_points, \
125 .part = &smps_parts, \
126 .id = RPM_VREG_ID_##_vreg_id, \
127 .rdesc.name = _name, \
128 .rdesc_pc.name = _name_pc, \
129 }
130
131#define LVS(_vreg_id, _rpm_id, _name, _name_pc) \
132 [RPM_VREG_ID_##_vreg_id] = { \
133 .req = { \
134 [0] = { .id = MSM_RPM_ID_##_rpm_id, }, \
135 [1] = { .id = -1, }, \
136 }, \
137 .type = RPM_REGULATOR_TYPE_VS, \
138 .part = &switch_parts, \
139 .id = RPM_VREG_ID_##_vreg_id, \
140 .rdesc.name = _name, \
141 .rdesc_pc.name = _name_pc, \
142 }
143
144#define MVS(_vreg_id, _rpm_id, _name, _name_pc) \
145 LVS(_vreg_id, _rpm_id, _name, _name_pc)
146
147#define NCP(_vreg_id, _rpm_id, _name, _name_pc) \
148 [RPM_VREG_ID_##_vreg_id] = { \
149 .req = { \
150 [0] = { .id = MSM_RPM_ID_##_rpm_id##_0, }, \
151 [1] = { .id = MSM_RPM_ID_##_rpm_id##_1, }, \
152 }, \
153 .type = RPM_REGULATOR_TYPE_NCP, \
154 .set_points = &ncp_set_points, \
155 .part = &ncp_parts, \
156 .id = RPM_VREG_ID_##_vreg_id, \
157 .rdesc.name = _name, \
158 .rdesc_pc.name = _name_pc, \
159 }
160
161static struct vreg vregs[] = {
162 LDO(PM8058_L0, LDO0, "8058_l0", "8058_l0_pc", nldo, LDO_150),
163 LDO(PM8058_L1, LDO1, "8058_l1", "8058_l1_pc", nldo, LDO_300),
164 LDO(PM8058_L2, LDO2, "8058_l2", "8058_l2_pc", pldo, LDO_300),
165 LDO(PM8058_L3, LDO3, "8058_l3", "8058_l3_pc", pldo, LDO_150),
166 LDO(PM8058_L4, LDO4, "8058_l4", "8058_l4_pc", pldo, LDO_50),
167 LDO(PM8058_L5, LDO5, "8058_l5", "8058_l5_pc", pldo, LDO_300),
168 LDO(PM8058_L6, LDO6, "8058_l6", "8058_l6_pc", pldo, LDO_50),
169 LDO(PM8058_L7, LDO7, "8058_l7", "8058_l7_pc", pldo, LDO_50),
170 LDO(PM8058_L8, LDO8, "8058_l8", "8058_l8_pc", pldo, LDO_300),
171 LDO(PM8058_L9, LDO9, "8058_l9", "8058_l9_pc", pldo, LDO_300),
172 LDO(PM8058_L10, LDO10, "8058_l10", "8058_l10_pc", pldo, LDO_300),
173 LDO(PM8058_L11, LDO11, "8058_l11", "8058_l11_pc", pldo, LDO_150),
174 LDO(PM8058_L12, LDO12, "8058_l12", "8058_l12_pc", pldo, LDO_150),
175 LDO(PM8058_L13, LDO13, "8058_l13", "8058_l13_pc", pldo, LDO_300),
176 LDO(PM8058_L14, LDO14, "8058_l14", "8058_l14_pc", pldo, LDO_300),
177 LDO(PM8058_L15, LDO15, "8058_l15", "8058_l15_pc", pldo, LDO_300),
178 LDO(PM8058_L16, LDO16, "8058_l16", "8058_l16_pc", pldo, LDO_300),
179 LDO(PM8058_L17, LDO17, "8058_l17", "8058_l17_pc", pldo, LDO_150),
180 LDO(PM8058_L18, LDO18, "8058_l18", "8058_l18_pc", pldo, LDO_150),
181 LDO(PM8058_L19, LDO19, "8058_l19", "8058_l19_pc", pldo, LDO_150),
182 LDO(PM8058_L20, LDO20, "8058_l20", "8058_l20_pc", pldo, LDO_150),
183 LDO(PM8058_L21, LDO21, "8058_l21", "8058_l21_pc", nldo, LDO_150),
184 LDO(PM8058_L22, LDO22, "8058_l22", "8058_l22_pc", nldo, LDO_300),
185 LDO(PM8058_L23, LDO23, "8058_l23", "8058_l23_pc", nldo, LDO_300),
186 LDO(PM8058_L24, LDO24, "8058_l24", "8058_l24_pc", nldo, LDO_150),
187 LDO(PM8058_L25, LDO25, "8058_l25", "8058_l25_pc", nldo, LDO_150),
188
189 SMPS(PM8058_S0, SMPS0, "8058_s0", "8058_s0_pc", smps, SMPS),
190 SMPS(PM8058_S1, SMPS1, "8058_s1", "8058_s1_pc", smps, SMPS),
191 SMPS(PM8058_S2, SMPS2, "8058_s2", "8058_s2_pc", smps, SMPS),
192 SMPS(PM8058_S3, SMPS3, "8058_s3", "8058_s3_pc", smps, SMPS),
193 SMPS(PM8058_S4, SMPS4, "8058_s4", "8058_s4_pc", smps, SMPS),
194
195 LVS(PM8058_LVS0, LVS0, "8058_lvs0", "8058_lvs0_pc"),
196 LVS(PM8058_LVS1, LVS1, "8058_lvs1", "8058_lvs1_pc"),
197
198 NCP(PM8058_NCP, NCP, "8058_ncp", NULL),
199
200 LDO(PM8901_L0, LDO0B, "8901_l0", "8901_l0_pc", nldo, LDO_300),
201 LDO(PM8901_L1, LDO1B, "8901_l1", "8901_l1_pc", pldo, LDO_300),
202 LDO(PM8901_L2, LDO2B, "8901_l2", "8901_l2_pc", pldo, LDO_300),
203 LDO(PM8901_L3, LDO3B, "8901_l3", "8901_l3_pc", pldo, LDO_300),
204 LDO(PM8901_L4, LDO4B, "8901_l4", "8901_l4_pc", pldo, LDO_300),
205 LDO(PM8901_L5, LDO5B, "8901_l5", "8901_l5_pc", pldo, LDO_300),
206 LDO(PM8901_L6, LDO6B, "8901_l6", "8901_l6_pc", pldo, LDO_300),
207
208 SMPS(PM8901_S0, SMPS0B, "8901_s0", "8901_s0_pc", ftsmps, FTSMPS),
209 SMPS(PM8901_S1, SMPS1B, "8901_s1", "8901_s1_pc", ftsmps, FTSMPS),
210 SMPS(PM8901_S2, SMPS2B, "8901_s2", "8901_s2_pc", ftsmps, FTSMPS),
211 SMPS(PM8901_S3, SMPS3B, "8901_s3", "8901_s3_pc", ftsmps, FTSMPS),
212 SMPS(PM8901_S4, SMPS4B, "8901_s4", "8901_s4_pc", ftsmps, FTSMPS),
213
214 LVS(PM8901_LVS0, LVS0B, "8901_lvs0", "8901_lvs0_pc"),
215 LVS(PM8901_LVS1, LVS1B, "8901_lvs1", "8901_lvs1_pc"),
216 LVS(PM8901_LVS2, LVS2B, "8901_lvs2", "8901_lvs2_pc"),
217 LVS(PM8901_LVS3, LVS3B, "8901_lvs3", "8901_lvs3_pc"),
218
219 MVS(PM8901_MVS0, MVS, "8901_mvs0", "8901_mvs0_pc"),
220};
221
222static const char *pin_func_label[] = {
223 [RPM_VREG_PIN_FN_8660_ENABLE] = "on/off",
224 [RPM_VREG_PIN_FN_8660_MODE] = "HPM/LPM",
225 [RPM_VREG_PIN_FN_8660_SLEEP_B] = "sleep_b",
226 [RPM_VREG_PIN_FN_8660_NONE] = "none",
227};
228
229static const char *force_mode_label[] = {
230 [RPM_VREG_FORCE_MODE_8660_NONE] = "none",
231 [RPM_VREG_FORCE_MODE_8660_LPM] = "LPM",
232 [RPM_VREG_FORCE_MODE_8660_HPM] = "HPM",
233};
234
235static const char *pin_control_label[] = {
236 " A0",
237 " A1",
238 " D0",
239 " D1",
240};
241
242static int is_real_id(int id)
243{
244 return (id >= 0) && (id <= RPM_VREG_ID_8660_MAX_REAL);
245}
246
247static int pc_id_to_real_id(int id)
248{
249 int real_id;
250
251 if (id >= RPM_VREG_ID_PM8058_L0_PC && id <= RPM_VREG_ID_PM8058_LVS1_PC)
252 real_id = id - RPM_VREG_ID_PM8058_L0_PC + RPM_VREG_ID_PM8058_L0;
253 else
254 real_id = id - RPM_VREG_ID_PM8901_L0_PC + RPM_VREG_ID_PM8901_L0;
255
256 return real_id;
257}
258
259static struct vreg_config config = {
260 .vregs = vregs,
261 .vregs_len = ARRAY_SIZE(vregs),
262
263 .vreg_id_min = RPM_VREG_ID_PM8058_L0,
264 .vreg_id_max = RPM_VREG_ID_8660_MAX,
265
266 .pin_func_none = RPM_VREG_PIN_FN_8660_NONE,
267 .pin_func_sleep_b = RPM_VREG_PIN_FN_8660_SLEEP_B,
268
269 .mode_lpm = REGULATOR_MODE_IDLE,
270 .mode_hpm = REGULATOR_MODE_NORMAL,
271
272 .set_points = all_set_points,
273 .set_points_len = ARRAY_SIZE(all_set_points),
274
275 .label_pin_ctrl = pin_control_label,
276 .label_pin_ctrl_len = ARRAY_SIZE(pin_control_label),
277 .label_pin_func = pin_func_label,
278 .label_pin_func_len = ARRAY_SIZE(pin_func_label),
279 .label_force_mode = force_mode_label,
280 .label_force_mode_len = ARRAY_SIZE(force_mode_label),
281
282 .is_real_id = is_real_id,
283 .pc_id_to_real_id = pc_id_to_real_id,
284
285 .use_legacy_optimum_mode = 1,
286 .ia_follows_ip = 1,
287};
288
289struct vreg_config *get_config_8660(void)
290{
291 return &config;
292}