blob: 4abdc52e52f01e9cd20932c93cf6cb8663b855a9 [file] [log] [blame]
David Collins6ef12bf2011-08-31 14:08:15 -07001/*
David Collins62ae8d92012-07-31 16:29:43 -07002 * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
David Collins6ef12bf2011-08-31 14:08:15 -07003 *
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
David Collins62ae8d92012-07-31 16:29:43 -070098#define LDO(_id, _name, _name_pc, _ranges, _hpm_min_load, _requires_cxo) \
David Collins6ef12bf2011-08-31 14:08:15 -070099 [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, \
David Collins62ae8d92012-07-31 16:29:43 -0700111 .requires_cxo = _requires_cxo, \
David Collins6ef12bf2011-08-31 14:08:15 -0700112 }
113
114#define SMPS(_id, _name, _name_pc, _ranges, _hpm_min_load) \
115 [RPM_VREG_ID_PM8018_##_id] = { \
116 .req = { \
117 [0] = { .id = MSM_RPM_ID_PM8018_##_id##_0, }, \
118 [1] = { .id = MSM_RPM_ID_PM8018_##_id##_1, }, \
119 }, \
120 .hpm_min_load = RPM_VREG_9615_##_hpm_min_load##_HPM_MIN_LOAD, \
121 .type = RPM_REGULATOR_TYPE_SMPS, \
122 .set_points = &_ranges##_set_points, \
123 .part = &smps_parts, \
124 .id = RPM_VREG_ID_PM8018_##_id, \
125 .rdesc.name = _name, \
126 .rdesc_pc.name = _name_pc, \
127 }
128
129#define LVS(_id, _name, _name_pc) \
130 [RPM_VREG_ID_PM8018_##_id] = { \
131 .req = { \
132 [0] = { .id = MSM_RPM_ID_PM8018_##_id, }, \
133 [1] = { .id = -1, }, \
134 }, \
135 .type = RPM_REGULATOR_TYPE_VS, \
136 .part = &switch_parts, \
137 .id = RPM_VREG_ID_PM8018_##_id, \
138 .rdesc.name = _name, \
139 .rdesc_pc.name = _name_pc, \
140 }
141
David Collins36c55582012-05-30 10:12:49 -0700142#define CORNER(_id, _rpm_id, _name, _ranges) \
143 [RPM_VREG_ID_PM8018_##_id] = { \
144 .req = { \
145 [0] = { .id = MSM_RPM_ID_##_rpm_id, }, \
146 [1] = { .id = -1, }, \
147 }, \
148 .type = RPM_REGULATOR_TYPE_CORNER, \
149 .set_points = &_ranges##_set_points, \
150 .part = &corner_parts, \
151 .id = RPM_VREG_ID_PM8018_##_id, \
152 .rdesc.name = _name, \
153 }
154
David Collins6ef12bf2011-08-31 14:08:15 -0700155static struct vreg vregs[] = {
David Collins62ae8d92012-07-31 16:29:43 -0700156 LDO(L2, "8018_l2", "8018_l2_pc", pldo, LDO_50, 0),
157 LDO(L3, "8018_l3", "8018_l3_pc", pldo, LDO_50, 0),
158 LDO(L4, "8018_l4", "8018_l4_pc", pldo, LDO_300, 0),
159 LDO(L5, "8018_l5", "8018_l5_pc", pldo, LDO_150, 0),
160 LDO(L6, "8018_l6", "8018_l6_pc", pldo, LDO_150, 0),
161 LDO(L7, "8018_l7", "8018_l7_pc", pldo, LDO_300, 0),
162 LDO(L8, "8018_l8", "8018_l8_pc", nldo, LDO_150, 1),
163 LDO(L9, "8018_l9", NULL, nldo1200, LDO_1200, 0),
164 LDO(L10, "8018_l10", NULL, nldo1200, LDO_1200, 0),
165 LDO(L11, "8018_l11", NULL, nldo1200, LDO_1200, 0),
166 LDO(L12, "8018_l12", NULL, nldo1200, LDO_1200, 0),
167 LDO(L13, "8018_l13", "8018_l13_pc", pldo, LDO_50, 0),
168 LDO(L14, "8018_l14", "8018_l14_pc", pldo, LDO_50, 0),
David Collins6ef12bf2011-08-31 14:08:15 -0700169
170 SMPS(S1, "8018_s1", "8018_s1_pc", smps, SMPS_1500),
171 SMPS(S2, "8018_s2", "8018_s2_pc", smps, SMPS_1500),
172 SMPS(S3, "8018_s3", "8018_s3_pc", smps, SMPS_1500),
173 SMPS(S4, "8018_s4", "8018_s4_pc", smps, SMPS_1500),
174 SMPS(S5, "8018_s5", "8018_s5_pc", smps, SMPS_1500),
175
176 LVS(LVS1, "8018_lvs1", "8018_lvs1_pc"),
David Collins36c55582012-05-30 10:12:49 -0700177
178 CORNER(VDD_DIG_CORNER, VOLTAGE_CORNER, "vdd_dig_corner", corner),
David Collins6ef12bf2011-08-31 14:08:15 -0700179};
180
181static const char *pin_control_label[] = {
182 " D1",
183 " A0",
184 " A1",
185 " A2",
186};
187
188static const char *pin_func_label[] = {
189 [RPM_VREG_PIN_FN_9615_DONT_CARE] = "don't care",
190 [RPM_VREG_PIN_FN_9615_ENABLE] = "on/off",
191 [RPM_VREG_PIN_FN_9615_MODE] = "HPM/LPM",
192 [RPM_VREG_PIN_FN_9615_SLEEP_B] = "sleep_b",
193 [RPM_VREG_PIN_FN_9615_NONE] = "none",
194};
195
196static const char *force_mode_label[] = {
197 [RPM_VREG_FORCE_MODE_9615_NONE] = "none",
198 [RPM_VREG_FORCE_MODE_9615_LPM] = "LPM",
199 [RPM_VREG_FORCE_MODE_9615_AUTO] = "auto",
200 [RPM_VREG_FORCE_MODE_9615_HPM] = "HPM",
201 [RPM_VREG_FORCE_MODE_9615_BYPASS] = "BYP",
202};
203
204static const char *power_mode_label[] = {
205 [RPM_VREG_POWER_MODE_9615_HYSTERETIC] = "HYS",
206 [RPM_VREG_POWER_MODE_9615_PWM] = "PWM",
207};
208
209static int is_real_id(int id)
210{
211 return (id >= 0) && (id <= RPM_VREG_ID_PM8018_MAX_REAL);
212}
213
214static int pc_id_to_real_id(int id)
215{
216 int real_id;
217
218 if (id >= RPM_VREG_ID_PM8018_L2_PC && id <= RPM_VREG_ID_PM8018_L8_PC)
219 real_id = id - RPM_VREG_ID_PM8018_L2_PC + RPM_VREG_ID_PM8018_L2;
220 else
221 real_id = id - RPM_VREG_ID_PM8018_L13_PC
222 + RPM_VREG_ID_PM8018_L13;
223
224 return real_id;
225}
226
227static struct vreg_config config = {
228 .vregs = vregs,
229 .vregs_len = ARRAY_SIZE(vregs),
230
231 .vreg_id_min = RPM_VREG_ID_PM8018_L2,
232 .vreg_id_max = RPM_VREG_ID_PM8018_MAX,
233
234 .pin_func_none = RPM_VREG_PIN_FN_9615_NONE,
235 .pin_func_sleep_b = RPM_VREG_PIN_FN_9615_SLEEP_B,
236
237 .mode_lpm = REGULATOR_MODE_IDLE,
238 .mode_hpm = REGULATOR_MODE_NORMAL,
239
240 .set_points = all_set_points,
241 .set_points_len = ARRAY_SIZE(all_set_points),
242
243 .label_pin_ctrl = pin_control_label,
244 .label_pin_ctrl_len = ARRAY_SIZE(pin_control_label),
245 .label_pin_func = pin_func_label,
246 .label_pin_func_len = ARRAY_SIZE(pin_func_label),
247 .label_force_mode = force_mode_label,
248 .label_force_mode_len = ARRAY_SIZE(force_mode_label),
249 .label_power_mode = power_mode_label,
250 .label_power_mode_len = ARRAY_SIZE(power_mode_label),
251
252 .is_real_id = is_real_id,
253 .pc_id_to_real_id = pc_id_to_real_id,
254};
255
256struct vreg_config *get_config_9615(void)
257{
258 return &config;
259}