blob: 82ac3d8438c55b109c8469c73420a9e1f94dba7d [file] [log] [blame]
David Collins6ef12bf2011-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 .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 Collins36c55582012-05-30 10:12:49 -070053static struct rpm_vreg_parts corner_parts = {
54 .request_len = 1,
55 .uV = REQUEST_MEMBER(0, 0x00000003, 0),
56};
57
David Collins6ef12bf2011-08-31 14:08:15 -070058/* 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
David Collins36c55582012-05-30 10:12:49 -070080static struct vreg_range corner_ranges[] = {
81 VOLTAGE_RANGE(RPM_VREG_CORNER_NONE, RPM_VREG_CORNER_HIGH, 1),
82};
83
David Collins6ef12bf2011-08-31 14:08:15 -070084static struct vreg_set_points pldo_set_points = SET_POINTS(pldo_ranges);
85static struct vreg_set_points nldo_set_points = SET_POINTS(nldo_ranges);
86static struct vreg_set_points nldo1200_set_points = SET_POINTS(nldo1200_ranges);
87static struct vreg_set_points smps_set_points = SET_POINTS(smps_ranges);
David Collins36c55582012-05-30 10:12:49 -070088static struct vreg_set_points corner_set_points = SET_POINTS(corner_ranges);
David Collins6ef12bf2011-08-31 14:08:15 -070089
90static struct vreg_set_points *all_set_points[] = {
91 &pldo_set_points,
92 &nldo_set_points,
93 &nldo1200_set_points,
94 &smps_set_points,
David Collins36c55582012-05-30 10:12:49 -070095 &corner_set_points,
David Collins6ef12bf2011-08-31 14:08:15 -070096};
97
98#define LDO(_id, _name, _name_pc, _ranges, _hpm_min_load) \
99 [RPM_VREG_ID_PM8018_##_id] = { \
100 .req = { \
101 [0] = { .id = MSM_RPM_ID_PM8018_##_id##_0, }, \
102 [1] = { .id = MSM_RPM_ID_PM8018_##_id##_1, }, \
103 }, \
104 .hpm_min_load = RPM_VREG_9615_##_hpm_min_load##_HPM_MIN_LOAD, \
105 .type = RPM_REGULATOR_TYPE_LDO, \
106 .set_points = &_ranges##_set_points, \
107 .part = &ldo_parts, \
108 .id = RPM_VREG_ID_PM8018_##_id, \
109 .rdesc.name = _name, \
110 .rdesc_pc.name = _name_pc, \
111 }
112
113#define SMPS(_id, _name, _name_pc, _ranges, _hpm_min_load) \
114 [RPM_VREG_ID_PM8018_##_id] = { \
115 .req = { \
116 [0] = { .id = MSM_RPM_ID_PM8018_##_id##_0, }, \
117 [1] = { .id = MSM_RPM_ID_PM8018_##_id##_1, }, \
118 }, \
119 .hpm_min_load = RPM_VREG_9615_##_hpm_min_load##_HPM_MIN_LOAD, \
120 .type = RPM_REGULATOR_TYPE_SMPS, \
121 .set_points = &_ranges##_set_points, \
122 .part = &smps_parts, \
123 .id = RPM_VREG_ID_PM8018_##_id, \
124 .rdesc.name = _name, \
125 .rdesc_pc.name = _name_pc, \
126 }
127
128#define LVS(_id, _name, _name_pc) \
129 [RPM_VREG_ID_PM8018_##_id] = { \
130 .req = { \
131 [0] = { .id = MSM_RPM_ID_PM8018_##_id, }, \
132 [1] = { .id = -1, }, \
133 }, \
134 .type = RPM_REGULATOR_TYPE_VS, \
135 .part = &switch_parts, \
136 .id = RPM_VREG_ID_PM8018_##_id, \
137 .rdesc.name = _name, \
138 .rdesc_pc.name = _name_pc, \
139 }
140
David Collins36c55582012-05-30 10:12:49 -0700141#define CORNER(_id, _rpm_id, _name, _ranges) \
142 [RPM_VREG_ID_PM8018_##_id] = { \
143 .req = { \
144 [0] = { .id = MSM_RPM_ID_##_rpm_id, }, \
145 [1] = { .id = -1, }, \
146 }, \
147 .type = RPM_REGULATOR_TYPE_CORNER, \
148 .set_points = &_ranges##_set_points, \
149 .part = &corner_parts, \
150 .id = RPM_VREG_ID_PM8018_##_id, \
151 .rdesc.name = _name, \
152 }
153
David Collins6ef12bf2011-08-31 14:08:15 -0700154static struct vreg vregs[] = {
155 LDO(L2, "8018_l2", "8018_l2_pc", pldo, LDO_50),
156 LDO(L3, "8018_l3", "8018_l3_pc", pldo, LDO_50),
157 LDO(L4, "8018_l4", "8018_l4_pc", pldo, LDO_300),
158 LDO(L5, "8018_l5", "8018_l5_pc", pldo, LDO_150),
159 LDO(L6, "8018_l6", "8018_l6_pc", pldo, LDO_150),
160 LDO(L7, "8018_l7", "8018_l7_pc", pldo, LDO_300),
161 LDO(L8, "8018_l8", "8018_l8_pc", nldo, LDO_150),
162 LDO(L9, "8018_l9", NULL, nldo1200, LDO_1200),
163 LDO(L10, "8018_l10", NULL, nldo1200, LDO_1200),
164 LDO(L11, "8018_l11", NULL, nldo1200, LDO_1200),
165 LDO(L12, "8018_l12", NULL, nldo1200, LDO_1200),
166 LDO(L13, "8018_l13", "8018_l13_pc", pldo, LDO_50),
167 LDO(L14, "8018_l14", "8018_l14_pc", pldo, LDO_50),
168
169 SMPS(S1, "8018_s1", "8018_s1_pc", smps, SMPS_1500),
170 SMPS(S2, "8018_s2", "8018_s2_pc", smps, SMPS_1500),
171 SMPS(S3, "8018_s3", "8018_s3_pc", smps, SMPS_1500),
172 SMPS(S4, "8018_s4", "8018_s4_pc", smps, SMPS_1500),
173 SMPS(S5, "8018_s5", "8018_s5_pc", smps, SMPS_1500),
174
175 LVS(LVS1, "8018_lvs1", "8018_lvs1_pc"),
David Collins36c55582012-05-30 10:12:49 -0700176
177 CORNER(VDD_DIG_CORNER, VOLTAGE_CORNER, "vdd_dig_corner", corner),
David Collins6ef12bf2011-08-31 14:08:15 -0700178};
179
180static const char *pin_control_label[] = {
181 " D1",
182 " A0",
183 " A1",
184 " A2",
185};
186
187static const char *pin_func_label[] = {
188 [RPM_VREG_PIN_FN_9615_DONT_CARE] = "don't care",
189 [RPM_VREG_PIN_FN_9615_ENABLE] = "on/off",
190 [RPM_VREG_PIN_FN_9615_MODE] = "HPM/LPM",
191 [RPM_VREG_PIN_FN_9615_SLEEP_B] = "sleep_b",
192 [RPM_VREG_PIN_FN_9615_NONE] = "none",
193};
194
195static const char *force_mode_label[] = {
196 [RPM_VREG_FORCE_MODE_9615_NONE] = "none",
197 [RPM_VREG_FORCE_MODE_9615_LPM] = "LPM",
198 [RPM_VREG_FORCE_MODE_9615_AUTO] = "auto",
199 [RPM_VREG_FORCE_MODE_9615_HPM] = "HPM",
200 [RPM_VREG_FORCE_MODE_9615_BYPASS] = "BYP",
201};
202
203static const char *power_mode_label[] = {
204 [RPM_VREG_POWER_MODE_9615_HYSTERETIC] = "HYS",
205 [RPM_VREG_POWER_MODE_9615_PWM] = "PWM",
206};
207
208static int is_real_id(int id)
209{
210 return (id >= 0) && (id <= RPM_VREG_ID_PM8018_MAX_REAL);
211}
212
213static int pc_id_to_real_id(int id)
214{
215 int real_id;
216
217 if (id >= RPM_VREG_ID_PM8018_L2_PC && id <= RPM_VREG_ID_PM8018_L8_PC)
218 real_id = id - RPM_VREG_ID_PM8018_L2_PC + RPM_VREG_ID_PM8018_L2;
219 else
220 real_id = id - RPM_VREG_ID_PM8018_L13_PC
221 + RPM_VREG_ID_PM8018_L13;
222
223 return real_id;
224}
225
226static struct vreg_config config = {
227 .vregs = vregs,
228 .vregs_len = ARRAY_SIZE(vregs),
229
230 .vreg_id_min = RPM_VREG_ID_PM8018_L2,
231 .vreg_id_max = RPM_VREG_ID_PM8018_MAX,
232
233 .pin_func_none = RPM_VREG_PIN_FN_9615_NONE,
234 .pin_func_sleep_b = RPM_VREG_PIN_FN_9615_SLEEP_B,
235
236 .mode_lpm = REGULATOR_MODE_IDLE,
237 .mode_hpm = REGULATOR_MODE_NORMAL,
238
239 .set_points = all_set_points,
240 .set_points_len = ARRAY_SIZE(all_set_points),
241
242 .label_pin_ctrl = pin_control_label,
243 .label_pin_ctrl_len = ARRAY_SIZE(pin_control_label),
244 .label_pin_func = pin_func_label,
245 .label_pin_func_len = ARRAY_SIZE(pin_func_label),
246 .label_force_mode = force_mode_label,
247 .label_force_mode_len = ARRAY_SIZE(force_mode_label),
248 .label_power_mode = power_mode_label,
249 .label_power_mode_len = ARRAY_SIZE(power_mode_label),
250
251 .is_real_id = is_real_id,
252 .pc_id_to_real_id = pc_id_to_real_id,
253};
254
255struct vreg_config *get_config_9615(void)
256{
257 return &config;
258}