blob: 05495930b0d9c00702bbe77254a11cf122b06a07 [file] [log] [blame]
David Collinsd1ac2f12012-02-14 13:34:18 -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 <linux/module.h>
17#include <linux/delay.h>
18#include <linux/err.h>
19#include <linux/string.h>
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/bitops.h>
23#include <linux/slab.h>
24#include <linux/spmi.h>
25#include <linux/of.h>
26#include <linux/of_device.h>
27#include <linux/platform_device.h>
28#include <linux/regulator/driver.h>
29#include <linux/regulator/of_regulator.h>
30#include <linux/regulator/qpnp-regulator.h>
31
David Collinsd1ac2f12012-02-14 13:34:18 -080032/* Debug Flag Definitions */
33enum {
34 QPNP_VREG_DEBUG_REQUEST = BIT(0), /* Show requests */
35 QPNP_VREG_DEBUG_DUPLICATE = BIT(1), /* Show duplicate requests */
36 QPNP_VREG_DEBUG_INIT = BIT(2), /* Show state after probe */
37 QPNP_VREG_DEBUG_WRITES = BIT(3), /* Show SPMI writes */
38 QPNP_VREG_DEBUG_READS = BIT(4), /* Show SPMI reads */
39};
40
41static int qpnp_vreg_debug_mask;
42module_param_named(
43 debug_mask, qpnp_vreg_debug_mask, int, S_IRUSR | S_IWUSR
44);
45
46#define vreg_err(vreg, fmt, ...) \
47 pr_err("%s: " fmt, vreg->rdesc.name, ##__VA_ARGS__)
48
49/* These types correspond to unique register layouts. */
50enum qpnp_regulator_logical_type {
51 QPNP_REGULATOR_LOGICAL_TYPE_SMPS,
52 QPNP_REGULATOR_LOGICAL_TYPE_LDO,
53 QPNP_REGULATOR_LOGICAL_TYPE_VS,
54 QPNP_REGULATOR_LOGICAL_TYPE_BOOST,
55 QPNP_REGULATOR_LOGICAL_TYPE_FTSMPS,
56};
57
58enum qpnp_regulator_type {
David Collinsbad606a2012-08-21 10:57:36 -070059 QPNP_REGULATOR_TYPE_BUCK = 0x03,
David Collinsd1ac2f12012-02-14 13:34:18 -080060 QPNP_REGULATOR_TYPE_LDO = 0x04,
61 QPNP_REGULATOR_TYPE_VS = 0x05,
62 QPNP_REGULATOR_TYPE_BOOST = 0x1B,
63 QPNP_REGULATOR_TYPE_FTS = 0x1C,
64};
65
66enum qpnp_regulator_subtype {
67 QPNP_REGULATOR_SUBTYPE_GP_CTL = 0x08,
68 QPNP_REGULATOR_SUBTYPE_RF_CTL = 0x09,
69 QPNP_REGULATOR_SUBTYPE_N50 = 0x01,
70 QPNP_REGULATOR_SUBTYPE_N150 = 0x02,
71 QPNP_REGULATOR_SUBTYPE_N300 = 0x03,
72 QPNP_REGULATOR_SUBTYPE_N600 = 0x04,
73 QPNP_REGULATOR_SUBTYPE_N1200 = 0x05,
David Collins75ebd572012-08-29 14:08:10 -070074 QPNP_REGULATOR_SUBTYPE_N600_ST = 0x06,
75 QPNP_REGULATOR_SUBTYPE_N1200_ST = 0x07,
David Collinsd1ac2f12012-02-14 13:34:18 -080076 QPNP_REGULATOR_SUBTYPE_P50 = 0x08,
77 QPNP_REGULATOR_SUBTYPE_P150 = 0x09,
78 QPNP_REGULATOR_SUBTYPE_P300 = 0x0A,
79 QPNP_REGULATOR_SUBTYPE_P600 = 0x0B,
80 QPNP_REGULATOR_SUBTYPE_P1200 = 0x0C,
David Collins75ebd572012-08-29 14:08:10 -070081 QPNP_REGULATOR_SUBTYPE_LV_P50 = 0x28,
82 QPNP_REGULATOR_SUBTYPE_LV_P150 = 0x29,
83 QPNP_REGULATOR_SUBTYPE_LV_P300 = 0x2A,
84 QPNP_REGULATOR_SUBTYPE_LV_P600 = 0x2B,
85 QPNP_REGULATOR_SUBTYPE_LV_P1200 = 0x2C,
David Collinsd1ac2f12012-02-14 13:34:18 -080086 QPNP_REGULATOR_SUBTYPE_LV100 = 0x01,
87 QPNP_REGULATOR_SUBTYPE_LV300 = 0x02,
88 QPNP_REGULATOR_SUBTYPE_MV300 = 0x08,
89 QPNP_REGULATOR_SUBTYPE_MV500 = 0x09,
90 QPNP_REGULATOR_SUBTYPE_HDMI = 0x10,
91 QPNP_REGULATOR_SUBTYPE_OTG = 0x11,
92 QPNP_REGULATOR_SUBTYPE_5V_BOOST = 0x01,
93 QPNP_REGULATOR_SUBTYPE_FTS_CTL = 0x08,
94};
95
96enum qpnp_common_regulator_registers {
David Collinsbad606a2012-08-21 10:57:36 -070097 QPNP_COMMON_REG_DIG_MAJOR_REV = 0x01,
David Collinsd1ac2f12012-02-14 13:34:18 -080098 QPNP_COMMON_REG_TYPE = 0x04,
99 QPNP_COMMON_REG_SUBTYPE = 0x05,
100 QPNP_COMMON_REG_VOLTAGE_RANGE = 0x40,
101 QPNP_COMMON_REG_VOLTAGE_SET = 0x41,
102 QPNP_COMMON_REG_MODE = 0x45,
103 QPNP_COMMON_REG_ENABLE = 0x46,
104 QPNP_COMMON_REG_PULL_DOWN = 0x48,
105};
106
107enum qpnp_ldo_registers {
108 QPNP_LDO_REG_SOFT_START = 0x4C,
109};
110
111enum qpnp_vs_registers {
112 QPNP_VS_REG_OCP = 0x4A,
113 QPNP_VS_REG_SOFT_START = 0x4C,
114};
115
116enum qpnp_boost_registers {
David Collins6f846752012-08-17 17:59:28 -0700117 QPNP_BOOST_REG_CURRENT_LIMIT = 0x4A,
David Collinsd1ac2f12012-02-14 13:34:18 -0800118};
119
120/* Used for indexing into ctrl_reg. These are offets from 0x40 */
121enum qpnp_common_control_register_index {
122 QPNP_COMMON_IDX_VOLTAGE_RANGE = 0,
123 QPNP_COMMON_IDX_VOLTAGE_SET = 1,
124 QPNP_COMMON_IDX_MODE = 5,
125 QPNP_COMMON_IDX_ENABLE = 6,
126};
127
David Collinsd1ac2f12012-02-14 13:34:18 -0800128/* Common regulator control register layout */
129#define QPNP_COMMON_ENABLE_MASK 0x80
130#define QPNP_COMMON_ENABLE 0x80
131#define QPNP_COMMON_DISABLE 0x00
132#define QPNP_COMMON_ENABLE_FOLLOW_HW_EN3_MASK 0x08
133#define QPNP_COMMON_ENABLE_FOLLOW_HW_EN2_MASK 0x04
134#define QPNP_COMMON_ENABLE_FOLLOW_HW_EN1_MASK 0x02
135#define QPNP_COMMON_ENABLE_FOLLOW_HW_EN0_MASK 0x01
136#define QPNP_COMMON_ENABLE_FOLLOW_ALL_MASK 0x0F
137
138/* Common regulator mode register layout */
139#define QPNP_COMMON_MODE_HPM_MASK 0x80
140#define QPNP_COMMON_MODE_AUTO_MASK 0x40
141#define QPNP_COMMON_MODE_BYPASS_MASK 0x20
142#define QPNP_COMMON_MODE_FOLLOW_AWAKE_MASK 0x10
143#define QPNP_COMMON_MODE_FOLLOW_HW_EN3_MASK 0x08
144#define QPNP_COMMON_MODE_FOLLOW_HW_EN2_MASK 0x04
145#define QPNP_COMMON_MODE_FOLLOW_HW_EN1_MASK 0x02
146#define QPNP_COMMON_MODE_FOLLOW_HW_EN0_MASK 0x01
147#define QPNP_COMMON_MODE_FOLLOW_ALL_MASK 0x1F
148
149/* Common regulator pull down control register layout */
150#define QPNP_COMMON_PULL_DOWN_ENABLE_MASK 0x80
151
152/* LDO regulator current limit control register layout */
153#define QPNP_LDO_CURRENT_LIMIT_ENABLE_MASK 0x80
154
155/* LDO regulator soft start control register layout */
156#define QPNP_LDO_SOFT_START_ENABLE_MASK 0x80
157
158/* VS regulator over current protection control register layout */
159#define QPNP_VS_OCP_ENABLE_MASK 0x80
160#define QPNP_VS_OCP_OVERRIDE_MASK 0x01
161#define QPNP_VS_OCP_DISABLE 0x00
162
163/* VS regulator soft start control register layout */
164#define QPNP_VS_SOFT_START_ENABLE_MASK 0x80
165#define QPNP_VS_SOFT_START_SEL_MASK 0x03
166
167/* Boost regulator current limit control register layout */
168#define QPNP_BOOST_CURRENT_LIMIT_ENABLE_MASK 0x80
169#define QPNP_BOOST_CURRENT_LIMIT_MASK 0x07
170
David Collinsbdd32812012-05-10 13:22:56 -0700171/*
172 * This voltage in uV is returned by get_voltage functions when there is no way
173 * to determine the current voltage level. It is needed because the regulator
174 * framework treats a 0 uV voltage as an error.
175 */
176#define VOLTAGE_UNKNOWN 1
177
David Collinsd1ac2f12012-02-14 13:34:18 -0800178struct qpnp_voltage_range {
179 int min_uV;
180 int max_uV;
181 int step_uV;
182 int set_point_min_uV;
183 unsigned n_voltages;
184 u8 range_sel;
185};
186
187struct qpnp_voltage_set_points {
188 struct qpnp_voltage_range *range;
189 int count;
190 unsigned n_voltages;
191};
192
193struct qpnp_regulator_mapping {
194 enum qpnp_regulator_type type;
195 enum qpnp_regulator_subtype subtype;
196 enum qpnp_regulator_logical_type logical_type;
David Collinsbad606a2012-08-21 10:57:36 -0700197 u32 revision_min;
198 u32 revision_max;
David Collinsd1ac2f12012-02-14 13:34:18 -0800199 struct regulator_ops *ops;
200 struct qpnp_voltage_set_points *set_points;
201 int hpm_min_load;
202};
203
204struct qpnp_regulator {
205 struct regulator_desc rdesc;
206 struct spmi_device *spmi_dev;
207 struct regulator_dev *rdev;
208 struct qpnp_voltage_set_points *set_points;
209 enum qpnp_regulator_logical_type logical_type;
210 int enable_time;
211 int ocp_enable_time;
212 int ocp_enable;
213 int system_load;
214 int hpm_min_load;
215 u32 write_count;
216 u32 prev_write_count;
217 u16 base_addr;
218 /* ctrl_reg provides a shadow copy of register values 0x40 to 0x47. */
219 u8 ctrl_reg[8];
220};
221
David Collinsbad606a2012-08-21 10:57:36 -0700222#define QPNP_VREG_MAP(_type, _subtype, _dig_major_min, _dig_major_max, \
223 _logical_type, _ops_val, _set_points_val, _hpm_min_load) \
David Collinsd1ac2f12012-02-14 13:34:18 -0800224 { \
225 .type = QPNP_REGULATOR_TYPE_##_type, \
226 .subtype = QPNP_REGULATOR_SUBTYPE_##_subtype, \
David Collinsbad606a2012-08-21 10:57:36 -0700227 .revision_min = _dig_major_min, \
228 .revision_max = _dig_major_max, \
David Collinsd1ac2f12012-02-14 13:34:18 -0800229 .logical_type = QPNP_REGULATOR_LOGICAL_TYPE_##_logical_type, \
230 .ops = &qpnp_##_ops_val##_ops, \
231 .set_points = &_set_points_val##_set_points, \
232 .hpm_min_load = _hpm_min_load, \
233 }
234
235#define VOLTAGE_RANGE(_range_sel, _min_uV, _set_point_min_uV, _max_uV, \
236 _step_uV) \
237 { \
238 .min_uV = _min_uV, \
239 .set_point_min_uV = _set_point_min_uV, \
240 .max_uV = _max_uV, \
241 .step_uV = _step_uV, \
242 .range_sel = _range_sel, \
243 }
244
245#define SET_POINTS(_ranges) \
246{ \
247 .range = _ranges, \
248 .count = ARRAY_SIZE(_ranges), \
249};
250
251/*
252 * These tables contain the physically available PMIC regulator voltage setpoint
253 * ranges. Where two ranges overlap in hardware, one of the ranges is trimmed
254 * to ensure that the setpoints available to software are monotonically
255 * increasing and unique. The set_voltage callback functions expect these
256 * properties to hold.
257 */
258static struct qpnp_voltage_range pldo_ranges[] = {
David Collinsbdd32812012-05-10 13:22:56 -0700259 VOLTAGE_RANGE(2, 750000, 750000, 1537500, 12500),
David Collinsd1ac2f12012-02-14 13:34:18 -0800260 VOLTAGE_RANGE(3, 1500000, 1550000, 3075000, 25000),
261 VOLTAGE_RANGE(4, 1750000, 3100000, 4900000, 50000),
262};
263
David Collinsbdd32812012-05-10 13:22:56 -0700264static struct qpnp_voltage_range nldo1_ranges[] = {
265 VOLTAGE_RANGE(2, 750000, 750000, 1537500, 12500),
266};
267
268static struct qpnp_voltage_range nldo2_ranges[] = {
269 VOLTAGE_RANGE(1, 375000, 375000, 768750, 6250),
270 VOLTAGE_RANGE(2, 750000, 775000, 1537500, 12500),
David Collinsd1ac2f12012-02-14 13:34:18 -0800271};
272
David Collinsbad606a2012-08-21 10:57:36 -0700273static struct qpnp_voltage_range nldo3_ranges[] = {
274 VOLTAGE_RANGE(0, 375000, 375000, 1537500, 12500),
275};
276
David Collinsd1ac2f12012-02-14 13:34:18 -0800277static struct qpnp_voltage_range smps_ranges[] = {
278 VOLTAGE_RANGE(0, 375000, 375000, 1562500, 12500),
279 VOLTAGE_RANGE(1, 1550000, 1575000, 3125000, 25000),
280};
281
282static struct qpnp_voltage_range ftsmps_ranges[] = {
David Collins45b86ac2012-08-09 09:44:15 -0700283 VOLTAGE_RANGE(0, 0, 350000, 1275000, 5000),
284 VOLTAGE_RANGE(1, 0, 1280000, 2040000, 10000),
David Collinsd1ac2f12012-02-14 13:34:18 -0800285};
286
287static struct qpnp_voltage_range boost_ranges[] = {
288 VOLTAGE_RANGE(0, 4000000, 4000000, 5550000, 50000),
289};
290
291static struct qpnp_voltage_set_points pldo_set_points = SET_POINTS(pldo_ranges);
David Collinsbdd32812012-05-10 13:22:56 -0700292static struct qpnp_voltage_set_points nldo1_set_points
293 = SET_POINTS(nldo1_ranges);
294static struct qpnp_voltage_set_points nldo2_set_points
295 = SET_POINTS(nldo2_ranges);
David Collinsbad606a2012-08-21 10:57:36 -0700296static struct qpnp_voltage_set_points nldo3_set_points
297 = SET_POINTS(nldo3_ranges);
David Collinsd1ac2f12012-02-14 13:34:18 -0800298static struct qpnp_voltage_set_points smps_set_points = SET_POINTS(smps_ranges);
299static struct qpnp_voltage_set_points ftsmps_set_points
300 = SET_POINTS(ftsmps_ranges);
301static struct qpnp_voltage_set_points boost_set_points
302 = SET_POINTS(boost_ranges);
303static struct qpnp_voltage_set_points none_set_points;
304
305static struct qpnp_voltage_set_points *all_set_points[] = {
306 &pldo_set_points,
David Collinsbdd32812012-05-10 13:22:56 -0700307 &nldo1_set_points,
308 &nldo2_set_points,
David Collinsbad606a2012-08-21 10:57:36 -0700309 &nldo3_set_points,
David Collinsd1ac2f12012-02-14 13:34:18 -0800310 &smps_set_points,
311 &ftsmps_set_points,
312 &boost_set_points,
313};
314
315/* Determines which label to add to a debug print statement. */
316enum qpnp_regulator_action {
317 QPNP_REGULATOR_ACTION_INIT,
318 QPNP_REGULATOR_ACTION_ENABLE,
319 QPNP_REGULATOR_ACTION_DISABLE,
320 QPNP_REGULATOR_ACTION_VOLTAGE,
321 QPNP_REGULATOR_ACTION_MODE,
322};
323
324static void qpnp_vreg_show_state(struct regulator_dev *rdev,
325 enum qpnp_regulator_action action);
326
327#define DEBUG_PRINT_BUFFER_SIZE 64
328static void fill_string(char *str, size_t str_len, u8 *buf, int buf_len)
329{
330 int pos = 0;
331 int i;
332
333 for (i = 0; i < buf_len; i++) {
334 pos += scnprintf(str + pos, str_len - pos, "0x%02X", buf[i]);
335 if (i < buf_len - 1)
336 pos += scnprintf(str + pos, str_len - pos, ", ");
337 }
338}
339
340static inline int qpnp_vreg_read(struct qpnp_regulator *vreg, u16 addr, u8 *buf,
341 int len)
342{
343 char str[DEBUG_PRINT_BUFFER_SIZE];
344 int rc = 0;
345
346 rc = spmi_ext_register_readl(vreg->spmi_dev->ctrl, vreg->spmi_dev->sid,
347 vreg->base_addr + addr, buf, len);
348
349 if (!rc && (qpnp_vreg_debug_mask & QPNP_VREG_DEBUG_READS)) {
350 str[0] = '\0';
351 fill_string(str, DEBUG_PRINT_BUFFER_SIZE, buf, len);
352 pr_info(" %-11s: read(0x%04X), sid=%d, len=%d; %s\n",
353 vreg->rdesc.name, vreg->base_addr + addr,
354 vreg->spmi_dev->sid, len, str);
355 }
356
357 return rc;
358}
359
360static inline int qpnp_vreg_write(struct qpnp_regulator *vreg, u16 addr,
361 u8 *buf, int len)
362{
363 char str[DEBUG_PRINT_BUFFER_SIZE];
364 int rc = 0;
365
366 if (qpnp_vreg_debug_mask & QPNP_VREG_DEBUG_WRITES) {
367 str[0] = '\0';
368 fill_string(str, DEBUG_PRINT_BUFFER_SIZE, buf, len);
369 pr_info("%-11s: write(0x%04X), sid=%d, len=%d; %s\n",
370 vreg->rdesc.name, vreg->base_addr + addr,
371 vreg->spmi_dev->sid, len, str);
372 }
373
374 rc = spmi_ext_register_writel(vreg->spmi_dev->ctrl,
375 vreg->spmi_dev->sid, vreg->base_addr + addr, buf, len);
376 if (!rc)
377 vreg->write_count += len;
378
379 return rc;
380}
381
382/*
383 * qpnp_vreg_write_optimized - write the minimum sized contiguous subset of buf
384 * @vreg: qpnp_regulator pointer for this regulator
385 * @addr: local SPMI address offset from this peripheral's base address
386 * @buf: new data to write into the SPMI registers
387 * @buf_save: old data in the registers
388 * @len: number of bytes to write
389 *
390 * This function checks for unchanged register values between buf and buf_save
391 * starting at both ends of buf. Only the contiguous subset in the middle of
392 * buf starting and ending with new values is sent.
393 *
394 * Consider the following example:
395 * buf offset: 0 1 2 3 4 5 6 7
396 * reg state: U U C C U C U U
397 * (U = unchanged, C = changed)
398 * In this example registers 2 through 5 will be written with a single
399 * transaction.
400 */
401static inline int qpnp_vreg_write_optimized(struct qpnp_regulator *vreg,
402 u16 addr, u8 *buf, u8 *buf_save, int len)
403{
404 int i, rc, start, end;
405
406 for (i = 0; i < len; i++)
407 if (buf[i] != buf_save[i])
408 break;
409 start = i;
410
411 for (i = len - 1; i >= 0; i--)
412 if (buf[i] != buf_save[i])
413 break;
414 end = i;
415
416 if (start > end) {
417 /* No modified register values present. */
418 return 0;
419 }
420
421 rc = qpnp_vreg_write(vreg, addr + start, &buf[start], end - start + 1);
422 if (!rc)
423 for (i = start; i <= end; i++)
424 buf_save[i] = buf[i];
425
426 return rc;
427}
428
429/*
430 * Perform a masked write to a PMIC register only if the new value differs
431 * from the last value written to the register. This removes redundant
432 * register writing.
433 */
434static int qpnp_vreg_masked_write(struct qpnp_regulator *vreg, u16 addr, u8 val,
435 u8 mask, u8 *reg_save)
436{
437 int rc = 0;
438 u8 reg;
439
440 reg = (*reg_save & ~mask) | (val & mask);
441 if (reg != *reg_save) {
442 rc = qpnp_vreg_write(vreg, addr, &reg, 1);
443
444 if (rc) {
445 vreg_err(vreg, "write failed; addr=0x%03X, rc=%d\n",
446 addr, rc);
447 } else {
448 *reg_save = reg;
449 }
450 }
451
452 return rc;
453}
454
455/*
456 * Perform a masked read-modify-write to a PMIC register only if the new value
457 * differs from the value currently in the register. This removes redundant
458 * register writing.
459 */
460static int qpnp_vreg_masked_read_write(struct qpnp_regulator *vreg, u16 addr,
461 u8 val, u8 mask)
462{
463 int rc;
464 u8 reg;
465
466 rc = qpnp_vreg_read(vreg, addr, &reg, 1);
467 if (rc) {
468 vreg_err(vreg, "read failed; addr=0x%03X, rc=%d\n", addr, rc);
469 return rc;
470 }
471
472 return qpnp_vreg_masked_write(vreg, addr, val, mask, &reg);
473}
474
475static int qpnp_regulator_common_is_enabled(struct regulator_dev *rdev)
476{
477 struct qpnp_regulator *vreg = rdev_get_drvdata(rdev);
478
479 return (vreg->ctrl_reg[QPNP_COMMON_IDX_ENABLE]
480 & QPNP_COMMON_ENABLE_MASK)
481 == QPNP_COMMON_ENABLE;
482}
483
484static int qpnp_regulator_common_enable(struct regulator_dev *rdev)
485{
486 struct qpnp_regulator *vreg = rdev_get_drvdata(rdev);
487 int rc;
488
489 rc = qpnp_vreg_masked_write(vreg, QPNP_COMMON_REG_ENABLE,
490 QPNP_COMMON_ENABLE, QPNP_COMMON_ENABLE_MASK,
491 &vreg->ctrl_reg[QPNP_COMMON_IDX_ENABLE]);
492
493 if (rc)
494 vreg_err(vreg, "qpnp_vreg_masked_write failed, rc=%d\n", rc);
495 else
496 qpnp_vreg_show_state(rdev, QPNP_REGULATOR_ACTION_ENABLE);
497
498 return rc;
499}
500
501static int qpnp_regulator_vs_enable(struct regulator_dev *rdev)
502{
503 struct qpnp_regulator *vreg = rdev_get_drvdata(rdev);
504 int rc;
505 u8 reg;
506
507 if (vreg->ocp_enable == QPNP_REGULATOR_ENABLE) {
508 /* Disable OCP */
509 reg = QPNP_VS_OCP_DISABLE;
510 rc = qpnp_vreg_write(vreg, QPNP_VS_REG_OCP, &reg, 1);
511 if (rc)
512 goto fail;
513 }
514
515 rc = qpnp_regulator_common_enable(rdev);
516 if (rc)
517 goto fail;
518
519 if (vreg->ocp_enable == QPNP_REGULATOR_ENABLE) {
520 /* Wait for inrush current to subsided, then enable OCP. */
521 udelay(vreg->ocp_enable_time);
522 reg = QPNP_VS_OCP_ENABLE_MASK;
523 rc = qpnp_vreg_write(vreg, QPNP_VS_REG_OCP, &reg, 1);
524 if (rc)
525 goto fail;
526 }
527
528 return rc;
529fail:
530 vreg_err(vreg, "qpnp_vreg_write failed, rc=%d\n", rc);
531
532 return rc;
533}
534
535static int qpnp_regulator_common_disable(struct regulator_dev *rdev)
536{
537 struct qpnp_regulator *vreg = rdev_get_drvdata(rdev);
538 int rc;
539
540 rc = qpnp_vreg_masked_write(vreg, QPNP_COMMON_REG_ENABLE,
541 QPNP_COMMON_DISABLE, QPNP_COMMON_ENABLE_MASK,
542 &vreg->ctrl_reg[QPNP_COMMON_IDX_ENABLE]);
543
544 if (rc)
545 vreg_err(vreg, "qpnp_vreg_masked_write failed, rc=%d\n", rc);
546 else
547 qpnp_vreg_show_state(rdev, QPNP_REGULATOR_ACTION_DISABLE);
548
549 return rc;
550}
551
552static int qpnp_regulator_select_voltage(struct qpnp_regulator *vreg,
553 int min_uV, int max_uV, int *range_sel, int *voltage_sel)
554{
555 struct qpnp_voltage_range *range;
556 int uV = min_uV;
557 int lim_min_uV, lim_max_uV, i;
558
559 /* Check if request voltage is outside of physically settable range. */
560 lim_min_uV = vreg->set_points->range[0].set_point_min_uV;
561 lim_max_uV =
562 vreg->set_points->range[vreg->set_points->count - 1].max_uV;
563
564 if (uV < lim_min_uV && max_uV >= lim_min_uV)
565 uV = lim_min_uV;
566
567 if (uV < lim_min_uV || uV > lim_max_uV) {
568 vreg_err(vreg,
569 "request v=[%d, %d] is outside possible v=[%d, %d]\n",
570 min_uV, max_uV, lim_min_uV, lim_max_uV);
571 return -EINVAL;
572 }
573
574 /* Find the range which uV is inside of. */
575 for (i = vreg->set_points->count - 1; i > 0; i--)
576 if (uV > vreg->set_points->range[i - 1].max_uV)
577 break;
578 range = &vreg->set_points->range[i];
579 *range_sel = range->range_sel;
580
581 /*
582 * Force uV to be an allowed set point by applying a ceiling function to
583 * the uV value.
584 */
585 *voltage_sel = (uV - range->min_uV + range->step_uV - 1)
586 / range->step_uV;
587 uV = *voltage_sel * range->step_uV + range->min_uV;
588
589 if (uV > max_uV) {
590 vreg_err(vreg,
591 "request v=[%d, %d] cannot be met by any set point; "
592 "next set point: %d\n",
593 min_uV, max_uV, uV);
594 return -EINVAL;
595 }
596
597 return 0;
598}
599
600static int qpnp_regulator_common_set_voltage(struct regulator_dev *rdev,
601 int min_uV, int max_uV, unsigned *selector)
602{
603 struct qpnp_regulator *vreg = rdev_get_drvdata(rdev);
604 int rc, range_sel, voltage_sel;
605 u8 buf[2];
606
607 rc = qpnp_regulator_select_voltage(vreg, min_uV, max_uV, &range_sel,
608 &voltage_sel);
609 if (rc) {
610 vreg_err(vreg, "could not set voltage, rc=%d\n", rc);
611 return rc;
612 }
613
614 buf[0] = range_sel;
615 buf[1] = voltage_sel;
616 if ((vreg->ctrl_reg[QPNP_COMMON_IDX_VOLTAGE_RANGE] != range_sel)
617 && (vreg->ctrl_reg[QPNP_COMMON_IDX_VOLTAGE_SET] == voltage_sel)) {
618 /* Handle latched range change. */
619 rc = qpnp_vreg_write(vreg, QPNP_COMMON_REG_VOLTAGE_RANGE,
620 buf, 2);
621 if (!rc) {
622 vreg->ctrl_reg[QPNP_COMMON_IDX_VOLTAGE_RANGE] = buf[0];
623 vreg->ctrl_reg[QPNP_COMMON_IDX_VOLTAGE_SET] = buf[1];
624 }
625 } else {
626 /* Either write can be optimized away safely. */
627 rc = qpnp_vreg_write_optimized(vreg,
628 QPNP_COMMON_REG_VOLTAGE_RANGE, buf,
629 &vreg->ctrl_reg[QPNP_COMMON_IDX_VOLTAGE_RANGE], 2);
630 }
631
632 if (rc)
633 vreg_err(vreg, "SPMI write failed, rc=%d\n", rc);
634 else
635 qpnp_vreg_show_state(rdev, QPNP_REGULATOR_ACTION_VOLTAGE);
636
637 return rc;
638}
639
640static int qpnp_regulator_common_get_voltage(struct regulator_dev *rdev)
641{
642 struct qpnp_regulator *vreg = rdev_get_drvdata(rdev);
643 struct qpnp_voltage_range *range = NULL;
644 int range_sel, voltage_sel, i;
645
646 range_sel = vreg->ctrl_reg[QPNP_COMMON_IDX_VOLTAGE_RANGE];
647 voltage_sel = vreg->ctrl_reg[QPNP_COMMON_IDX_VOLTAGE_SET];
648
649 for (i = 0; i < vreg->set_points->count; i++) {
650 if (vreg->set_points->range[i].range_sel == range_sel) {
651 range = &vreg->set_points->range[i];
652 break;
653 }
654 }
655
656 if (!range) {
657 vreg_err(vreg, "voltage unknown, range %d is invalid\n",
658 range_sel);
David Collinsbdd32812012-05-10 13:22:56 -0700659 return VOLTAGE_UNKNOWN;
David Collinsd1ac2f12012-02-14 13:34:18 -0800660 }
661
662 return range->step_uV * voltage_sel + range->min_uV;
663}
664
665static int qpnp_regulator_boost_set_voltage(struct regulator_dev *rdev,
666 int min_uV, int max_uV, unsigned *selector)
667{
668 struct qpnp_regulator *vreg = rdev_get_drvdata(rdev);
669 int rc, range_sel, voltage_sel;
670
671 rc = qpnp_regulator_select_voltage(vreg, min_uV, max_uV, &range_sel,
672 &voltage_sel);
673 if (rc) {
674 vreg_err(vreg, "could not set voltage, rc=%d\n", rc);
675 return rc;
676 }
677
678 /*
679 * Boost type regulators do not have range select register so only
680 * voltage set register needs to be written.
681 */
682 rc = qpnp_vreg_masked_write(vreg, QPNP_COMMON_REG_VOLTAGE_SET,
683 voltage_sel, 0xFF, &vreg->ctrl_reg[QPNP_COMMON_IDX_VOLTAGE_SET]);
684
685 if (rc)
686 vreg_err(vreg, "SPMI write failed, rc=%d\n", rc);
687 else
688 qpnp_vreg_show_state(rdev, QPNP_REGULATOR_ACTION_VOLTAGE);
689
690 return rc;
691}
692
693static int qpnp_regulator_boost_get_voltage(struct regulator_dev *rdev)
694{
695 struct qpnp_regulator *vreg = rdev_get_drvdata(rdev);
696 int voltage_sel = vreg->ctrl_reg[QPNP_COMMON_IDX_VOLTAGE_SET];
697
698 return boost_ranges[0].step_uV * voltage_sel + boost_ranges[0].min_uV;
699}
700
701static int qpnp_regulator_common_list_voltage(struct regulator_dev *rdev,
702 unsigned selector)
703{
704 struct qpnp_regulator *vreg = rdev_get_drvdata(rdev);
705 int uV = 0;
706 int i;
707
708 if (selector >= vreg->set_points->n_voltages)
709 return 0;
710
711 for (i = 0; i < vreg->set_points->count; i++) {
712 if (selector < vreg->set_points->range[i].n_voltages) {
713 uV = selector * vreg->set_points->range[i].step_uV
714 + vreg->set_points->range[i].set_point_min_uV;
715 break;
716 } else {
717 selector -= vreg->set_points->range[i].n_voltages;
718 }
719 }
720
721 return uV;
722}
723
724static unsigned int qpnp_regulator_common_get_mode(struct regulator_dev *rdev)
725{
726 struct qpnp_regulator *vreg = rdev_get_drvdata(rdev);
727
728 return (vreg->ctrl_reg[QPNP_COMMON_IDX_MODE]
729 & QPNP_COMMON_MODE_HPM_MASK)
730 ? REGULATOR_MODE_NORMAL : REGULATOR_MODE_IDLE;
731}
732
733static int qpnp_regulator_common_set_mode(struct regulator_dev *rdev,
734 unsigned int mode)
735{
736 struct qpnp_regulator *vreg = rdev_get_drvdata(rdev);
737 int rc = 0;
738 u8 val;
739
740 if (mode != REGULATOR_MODE_NORMAL && mode != REGULATOR_MODE_IDLE) {
741 vreg_err(vreg, "invalid mode: %u\n", mode);
742 return -EINVAL;
743 }
744
745 val = (mode == REGULATOR_MODE_NORMAL ? QPNP_COMMON_MODE_HPM_MASK : 0);
746
747 rc = qpnp_vreg_masked_write(vreg, QPNP_COMMON_REG_MODE, val,
748 QPNP_COMMON_MODE_HPM_MASK,
749 &vreg->ctrl_reg[QPNP_COMMON_IDX_MODE]);
750
751 if (rc)
752 vreg_err(vreg, "SPMI write failed, rc=%d\n", rc);
753 else
754 qpnp_vreg_show_state(rdev, QPNP_REGULATOR_ACTION_MODE);
755
756 return rc;
757}
758
759static unsigned int qpnp_regulator_common_get_optimum_mode(
760 struct regulator_dev *rdev, int input_uV, int output_uV,
761 int load_uA)
762{
763 struct qpnp_regulator *vreg = rdev_get_drvdata(rdev);
764 unsigned int mode;
765
766 if (load_uA + vreg->system_load >= vreg->hpm_min_load)
767 mode = REGULATOR_MODE_NORMAL;
768 else
769 mode = REGULATOR_MODE_IDLE;
770
771 return mode;
772}
773
774static int qpnp_regulator_common_enable_time(struct regulator_dev *rdev)
775{
776 struct qpnp_regulator *vreg = rdev_get_drvdata(rdev);
777
778 return vreg->enable_time;
779}
780
781static const char const *qpnp_print_actions[] = {
782 [QPNP_REGULATOR_ACTION_INIT] = "initial ",
783 [QPNP_REGULATOR_ACTION_ENABLE] = "enable ",
784 [QPNP_REGULATOR_ACTION_DISABLE] = "disable ",
785 [QPNP_REGULATOR_ACTION_VOLTAGE] = "set voltage",
786 [QPNP_REGULATOR_ACTION_MODE] = "set mode ",
787};
788
789static void qpnp_vreg_show_state(struct regulator_dev *rdev,
790 enum qpnp_regulator_action action)
791{
792 struct qpnp_regulator *vreg = rdev_get_drvdata(rdev);
793 const char *action_label = qpnp_print_actions[action];
794 unsigned int mode = 0;
795 int uV = 0;
796 const char *mode_label = "";
797 enum qpnp_regulator_logical_type type;
798 const char *enable_label;
799 char pc_enable_label[5] = {'\0'};
800 char pc_mode_label[8] = {'\0'};
801 bool show_req, show_dupe, show_init, has_changed;
802 u8 en_reg, mode_reg;
803
804 /* Do not print unless appropriate flags are set. */
805 show_req = qpnp_vreg_debug_mask & QPNP_VREG_DEBUG_REQUEST;
806 show_dupe = qpnp_vreg_debug_mask & QPNP_VREG_DEBUG_DUPLICATE;
807 show_init = qpnp_vreg_debug_mask & QPNP_VREG_DEBUG_INIT;
808 has_changed = vreg->write_count != vreg->prev_write_count;
809 if (!((show_init && action == QPNP_REGULATOR_ACTION_INIT)
810 || (show_req && (has_changed || show_dupe)))) {
811 return;
812 }
813
814 vreg->prev_write_count = vreg->write_count;
815
816 type = vreg->logical_type;
817
818 enable_label = qpnp_regulator_common_is_enabled(rdev) ? "on " : "off";
819
820 if (type == QPNP_REGULATOR_LOGICAL_TYPE_SMPS
821 || type == QPNP_REGULATOR_LOGICAL_TYPE_LDO
822 || type == QPNP_REGULATOR_LOGICAL_TYPE_FTSMPS)
823 uV = qpnp_regulator_common_get_voltage(rdev);
824
825 if (type == QPNP_REGULATOR_LOGICAL_TYPE_BOOST)
826 uV = qpnp_regulator_boost_get_voltage(rdev);
827
828 if (type == QPNP_REGULATOR_LOGICAL_TYPE_SMPS
829 || type == QPNP_REGULATOR_LOGICAL_TYPE_LDO
830 || type == QPNP_REGULATOR_LOGICAL_TYPE_FTSMPS) {
831 mode = qpnp_regulator_common_get_mode(rdev);
832 mode_label = mode == REGULATOR_MODE_NORMAL ? "HPM" : "LPM";
833 }
834
835 if (type == QPNP_REGULATOR_LOGICAL_TYPE_SMPS
836 || type == QPNP_REGULATOR_LOGICAL_TYPE_LDO
837 || type == QPNP_REGULATOR_LOGICAL_TYPE_VS) {
838 en_reg = vreg->ctrl_reg[QPNP_COMMON_IDX_ENABLE];
839 pc_enable_label[0] =
840 en_reg & QPNP_COMMON_ENABLE_FOLLOW_HW_EN3_MASK ? '3' : '_';
841 pc_enable_label[1] =
842 en_reg & QPNP_COMMON_ENABLE_FOLLOW_HW_EN2_MASK ? '2' : '_';
843 pc_enable_label[2] =
844 en_reg & QPNP_COMMON_ENABLE_FOLLOW_HW_EN1_MASK ? '1' : '_';
845 pc_enable_label[3] =
846 en_reg & QPNP_COMMON_ENABLE_FOLLOW_HW_EN0_MASK ? '0' : '_';
847 }
848
849 switch (type) {
850 case QPNP_REGULATOR_LOGICAL_TYPE_SMPS:
851 mode_reg = vreg->ctrl_reg[QPNP_COMMON_IDX_MODE];
852 pc_mode_label[0] =
853 mode_reg & QPNP_COMMON_MODE_AUTO_MASK ? 'A' : '_';
854 pc_mode_label[1] =
855 mode_reg & QPNP_COMMON_MODE_FOLLOW_AWAKE_MASK ? 'W' : '_';
856 pc_mode_label[2] =
857 mode_reg & QPNP_COMMON_MODE_FOLLOW_HW_EN3_MASK ? '3' : '_';
858 pc_mode_label[3] =
859 mode_reg & QPNP_COMMON_MODE_FOLLOW_HW_EN2_MASK ? '2' : '_';
860 pc_mode_label[4] =
861 mode_reg & QPNP_COMMON_MODE_FOLLOW_HW_EN1_MASK ? '1' : '_';
862 pc_mode_label[5] =
863 mode_reg & QPNP_COMMON_MODE_FOLLOW_HW_EN0_MASK ? '0' : '_';
864
865 pr_info("%s %-11s: %s, v=%7d uV, mode=%s, pc_en=%s, "
866 "alt_mode=%s\n",
867 action_label, vreg->rdesc.name, enable_label, uV,
868 mode_label, pc_enable_label, pc_mode_label);
869 break;
870 case QPNP_REGULATOR_LOGICAL_TYPE_LDO:
871 mode_reg = vreg->ctrl_reg[QPNP_COMMON_IDX_MODE];
872 pc_mode_label[0] =
873 mode_reg & QPNP_COMMON_MODE_AUTO_MASK ? 'A' : '_';
874 pc_mode_label[1] =
875 mode_reg & QPNP_COMMON_MODE_BYPASS_MASK ? 'B' : '_';
876 pc_mode_label[2] =
877 mode_reg & QPNP_COMMON_MODE_FOLLOW_AWAKE_MASK ? 'W' : '_';
878 pc_mode_label[3] =
879 mode_reg & QPNP_COMMON_MODE_FOLLOW_HW_EN3_MASK ? '3' : '_';
880 pc_mode_label[4] =
881 mode_reg & QPNP_COMMON_MODE_FOLLOW_HW_EN2_MASK ? '2' : '_';
882 pc_mode_label[5] =
883 mode_reg & QPNP_COMMON_MODE_FOLLOW_HW_EN1_MASK ? '1' : '_';
884 pc_mode_label[6] =
885 mode_reg & QPNP_COMMON_MODE_FOLLOW_HW_EN0_MASK ? '0' : '_';
886
887 pr_info("%s %-11s: %s, v=%7d uV, mode=%s, pc_en=%s, "
888 "alt_mode=%s\n",
889 action_label, vreg->rdesc.name, enable_label, uV,
890 mode_label, pc_enable_label, pc_mode_label);
891 break;
892 case QPNP_REGULATOR_LOGICAL_TYPE_VS:
893 mode_reg = vreg->ctrl_reg[QPNP_COMMON_IDX_MODE];
894 pc_mode_label[0] =
895 mode_reg & QPNP_COMMON_MODE_AUTO_MASK ? 'A' : '_';
896 pc_mode_label[1] =
897 mode_reg & QPNP_COMMON_MODE_FOLLOW_AWAKE_MASK ? 'W' : '_';
898
899 pr_info("%s %-11s: %s, pc_en=%s, alt_mode=%s\n",
900 action_label, vreg->rdesc.name, enable_label,
901 pc_enable_label, pc_mode_label);
902 break;
903 case QPNP_REGULATOR_LOGICAL_TYPE_BOOST:
904 pr_info("%s %-11s: %s, v=%7d uV\n",
905 action_label, vreg->rdesc.name, enable_label, uV);
906 break;
907 case QPNP_REGULATOR_LOGICAL_TYPE_FTSMPS:
908 mode_reg = vreg->ctrl_reg[QPNP_COMMON_IDX_MODE];
909 pc_mode_label[0] =
910 mode_reg & QPNP_COMMON_MODE_AUTO_MASK ? 'A' : '_';
911
912 pr_info("%s %-11s: %s, v=%7d uV, mode=%s, alt_mode=%s\n",
913 action_label, vreg->rdesc.name, enable_label, uV,
914 mode_label, pc_mode_label);
915 break;
916 default:
917 break;
918 }
919}
920
921static struct regulator_ops qpnp_smps_ops = {
922 .enable = qpnp_regulator_common_enable,
923 .disable = qpnp_regulator_common_disable,
924 .is_enabled = qpnp_regulator_common_is_enabled,
925 .set_voltage = qpnp_regulator_common_set_voltage,
926 .get_voltage = qpnp_regulator_common_get_voltage,
927 .list_voltage = qpnp_regulator_common_list_voltage,
928 .set_mode = qpnp_regulator_common_set_mode,
929 .get_mode = qpnp_regulator_common_get_mode,
930 .get_optimum_mode = qpnp_regulator_common_get_optimum_mode,
931 .enable_time = qpnp_regulator_common_enable_time,
932};
933
934static struct regulator_ops qpnp_ldo_ops = {
935 .enable = qpnp_regulator_common_enable,
936 .disable = qpnp_regulator_common_disable,
937 .is_enabled = qpnp_regulator_common_is_enabled,
938 .set_voltage = qpnp_regulator_common_set_voltage,
939 .get_voltage = qpnp_regulator_common_get_voltage,
940 .list_voltage = qpnp_regulator_common_list_voltage,
941 .set_mode = qpnp_regulator_common_set_mode,
942 .get_mode = qpnp_regulator_common_get_mode,
943 .get_optimum_mode = qpnp_regulator_common_get_optimum_mode,
944 .enable_time = qpnp_regulator_common_enable_time,
945};
946
947static struct regulator_ops qpnp_vs_ops = {
948 .enable = qpnp_regulator_vs_enable,
949 .disable = qpnp_regulator_common_disable,
950 .is_enabled = qpnp_regulator_common_is_enabled,
951 .enable_time = qpnp_regulator_common_enable_time,
952};
953
954static struct regulator_ops qpnp_boost_ops = {
955 .enable = qpnp_regulator_common_enable,
956 .disable = qpnp_regulator_common_disable,
957 .is_enabled = qpnp_regulator_common_is_enabled,
958 .set_voltage = qpnp_regulator_boost_set_voltage,
959 .get_voltage = qpnp_regulator_boost_get_voltage,
960 .list_voltage = qpnp_regulator_common_list_voltage,
961 .enable_time = qpnp_regulator_common_enable_time,
962};
963
964static struct regulator_ops qpnp_ftsmps_ops = {
965 .enable = qpnp_regulator_common_enable,
966 .disable = qpnp_regulator_common_disable,
967 .is_enabled = qpnp_regulator_common_is_enabled,
968 .set_voltage = qpnp_regulator_common_set_voltage,
969 .get_voltage = qpnp_regulator_common_get_voltage,
970 .list_voltage = qpnp_regulator_common_list_voltage,
971 .set_mode = qpnp_regulator_common_set_mode,
972 .get_mode = qpnp_regulator_common_get_mode,
973 .get_optimum_mode = qpnp_regulator_common_get_optimum_mode,
974 .enable_time = qpnp_regulator_common_enable_time,
975};
976
David Collinsbad606a2012-08-21 10:57:36 -0700977/* Maximum possible digital major revision value */
978#define INF 0xFF
979
David Collinsd1ac2f12012-02-14 13:34:18 -0800980static const struct qpnp_regulator_mapping supported_regulators[] = {
David Collinsbad606a2012-08-21 10:57:36 -0700981 /* type subtype dig_min dig_max ltype ops setpoints hpm_min */
982 QPNP_VREG_MAP(BUCK, GP_CTL, 0, INF, SMPS, smps, smps, 100000),
983 QPNP_VREG_MAP(LDO, N300, 0, INF, LDO, ldo, nldo1, 10000),
984 QPNP_VREG_MAP(LDO, N600, 0, 0, LDO, ldo, nldo2, 10000),
985 QPNP_VREG_MAP(LDO, N1200, 0, 0, LDO, ldo, nldo2, 10000),
986 QPNP_VREG_MAP(LDO, N600, 1, INF, LDO, ldo, nldo3, 10000),
987 QPNP_VREG_MAP(LDO, N1200, 1, INF, LDO, ldo, nldo3, 10000),
David Collins75ebd572012-08-29 14:08:10 -0700988 QPNP_VREG_MAP(LDO, N600_ST, 0, 0, LDO, ldo, nldo2, 10000),
989 QPNP_VREG_MAP(LDO, N1200_ST, 0, 0, LDO, ldo, nldo2, 10000),
990 QPNP_VREG_MAP(LDO, N600_ST, 1, INF, LDO, ldo, nldo3, 10000),
991 QPNP_VREG_MAP(LDO, N1200_ST, 1, INF, LDO, ldo, nldo3, 10000),
David Collinsbad606a2012-08-21 10:57:36 -0700992 QPNP_VREG_MAP(LDO, P50, 0, INF, LDO, ldo, pldo, 5000),
993 QPNP_VREG_MAP(LDO, P150, 0, INF, LDO, ldo, pldo, 10000),
994 QPNP_VREG_MAP(LDO, P300, 0, INF, LDO, ldo, pldo, 10000),
995 QPNP_VREG_MAP(LDO, P600, 0, INF, LDO, ldo, pldo, 10000),
996 QPNP_VREG_MAP(LDO, P1200, 0, INF, LDO, ldo, pldo, 10000),
David Collins75ebd572012-08-29 14:08:10 -0700997 QPNP_VREG_MAP(LDO, LV_P50, 0, INF, LDO, ldo, pldo, 5000),
998 QPNP_VREG_MAP(LDO, LV_P150, 0, INF, LDO, ldo, pldo, 10000),
999 QPNP_VREG_MAP(LDO, LV_P300, 0, INF, LDO, ldo, pldo, 10000),
1000 QPNP_VREG_MAP(LDO, LV_P600, 0, INF, LDO, ldo, pldo, 10000),
1001 QPNP_VREG_MAP(LDO, LV_P1200, 0, INF, LDO, ldo, pldo, 10000),
David Collinsbad606a2012-08-21 10:57:36 -07001002 QPNP_VREG_MAP(VS, LV100, 0, INF, VS, vs, none, 0),
1003 QPNP_VREG_MAP(VS, LV300, 0, INF, VS, vs, none, 0),
1004 QPNP_VREG_MAP(VS, MV300, 0, INF, VS, vs, none, 0),
1005 QPNP_VREG_MAP(VS, MV500, 0, INF, VS, vs, none, 0),
1006 QPNP_VREG_MAP(VS, HDMI, 0, INF, VS, vs, none, 0),
1007 QPNP_VREG_MAP(VS, OTG, 0, INF, VS, vs, none, 0),
1008 QPNP_VREG_MAP(BOOST, 5V_BOOST, 0, INF, BOOST, boost, boost, 0),
1009 QPNP_VREG_MAP(FTS, FTS_CTL, 0, INF, FTSMPS, ftsmps, ftsmps, 100000),
David Collinsd1ac2f12012-02-14 13:34:18 -08001010};
1011
1012static int qpnp_regulator_match(struct qpnp_regulator *vreg)
1013{
1014 const struct qpnp_regulator_mapping *mapping;
Michael Bohan9328e492012-08-09 11:37:36 -07001015 struct device_node *node = vreg->spmi_dev->dev.of_node;
David Collinsd1ac2f12012-02-14 13:34:18 -08001016 int rc, i;
David Collinsbad606a2012-08-21 10:57:36 -07001017 u32 type_reg[2], dig_major_rev;
1018 u8 version[QPNP_COMMON_REG_SUBTYPE - QPNP_COMMON_REG_DIG_MAJOR_REV + 1];
1019 u8 type, subtype;
David Collinsd1ac2f12012-02-14 13:34:18 -08001020
David Collinsbad606a2012-08-21 10:57:36 -07001021 rc = qpnp_vreg_read(vreg, QPNP_COMMON_REG_DIG_MAJOR_REV, version,
1022 ARRAY_SIZE(version));
1023 if (rc) {
1024 vreg_err(vreg, "could not read version registers, rc=%d\n", rc);
1025 return rc;
1026 }
1027 dig_major_rev = version[QPNP_COMMON_REG_DIG_MAJOR_REV
1028 - QPNP_COMMON_REG_DIG_MAJOR_REV];
1029 type = version[QPNP_COMMON_REG_TYPE
1030 - QPNP_COMMON_REG_DIG_MAJOR_REV];
1031 subtype = version[QPNP_COMMON_REG_SUBTYPE
1032 - QPNP_COMMON_REG_DIG_MAJOR_REV];
1033
1034 /*
1035 * Override type and subtype register values if qcom,force-type is
1036 * present in the device tree node.
1037 */
1038 rc = of_property_read_u32_array(node, "qcom,force-type", type_reg, 2);
Michael Bohan9328e492012-08-09 11:37:36 -07001039 if (!rc) {
1040 type = type_reg[0];
1041 subtype = type_reg[1];
David Collinsd1ac2f12012-02-14 13:34:18 -08001042 }
David Collinsd1ac2f12012-02-14 13:34:18 -08001043
1044 rc = -ENODEV;
1045 for (i = 0; i < ARRAY_SIZE(supported_regulators); i++) {
1046 mapping = &supported_regulators[i];
David Collinsbad606a2012-08-21 10:57:36 -07001047 if (mapping->type == type && mapping->subtype == subtype
1048 && mapping->revision_min <= dig_major_rev
1049 && mapping->revision_max >= dig_major_rev) {
David Collinsd1ac2f12012-02-14 13:34:18 -08001050 vreg->logical_type = mapping->logical_type;
1051 vreg->set_points = mapping->set_points;
1052 vreg->hpm_min_load = mapping->hpm_min_load;
1053 vreg->rdesc.ops = mapping->ops;
1054 vreg->rdesc.n_voltages
1055 = mapping->set_points->n_voltages;
1056 rc = 0;
1057 break;
1058 }
1059 }
1060
1061 return rc;
1062}
1063
1064static int qpnp_regulator_init_registers(struct qpnp_regulator *vreg,
1065 struct qpnp_regulator_platform_data *pdata)
1066{
1067 int rc, i;
1068 enum qpnp_regulator_logical_type type;
1069 u8 ctrl_reg[8], reg, mask;
1070
1071 type = vreg->logical_type;
1072
1073 rc = qpnp_vreg_read(vreg, QPNP_COMMON_REG_VOLTAGE_RANGE,
1074 vreg->ctrl_reg, 8);
1075 if (rc) {
1076 vreg_err(vreg, "spmi read failed, rc=%d\n", rc);
1077 return rc;
1078 }
1079
1080 for (i = 0; i < ARRAY_SIZE(ctrl_reg); i++)
1081 ctrl_reg[i] = vreg->ctrl_reg[i];
1082
1083 /* Set up enable pin control. */
1084 if ((type == QPNP_REGULATOR_LOGICAL_TYPE_SMPS
1085 || type == QPNP_REGULATOR_LOGICAL_TYPE_LDO
1086 || type == QPNP_REGULATOR_LOGICAL_TYPE_VS)
1087 && !(pdata->pin_ctrl_enable
1088 & QPNP_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT)) {
1089 ctrl_reg[QPNP_COMMON_IDX_ENABLE] &=
1090 ~QPNP_COMMON_ENABLE_FOLLOW_ALL_MASK;
1091 ctrl_reg[QPNP_COMMON_IDX_ENABLE] |=
1092 pdata->pin_ctrl_enable & QPNP_COMMON_ENABLE_FOLLOW_ALL_MASK;
1093 }
1094
1095 /* Set up auto mode control. */
1096 if ((type == QPNP_REGULATOR_LOGICAL_TYPE_SMPS
1097 || type == QPNP_REGULATOR_LOGICAL_TYPE_LDO
1098 || type == QPNP_REGULATOR_LOGICAL_TYPE_VS
1099 || type == QPNP_REGULATOR_LOGICAL_TYPE_FTSMPS)
1100 && (pdata->auto_mode_enable != QPNP_REGULATOR_USE_HW_DEFAULT)) {
1101 ctrl_reg[QPNP_COMMON_IDX_MODE] &=
1102 ~QPNP_COMMON_MODE_AUTO_MASK;
1103 ctrl_reg[QPNP_COMMON_IDX_MODE] |=
1104 (pdata->auto_mode_enable ? QPNP_COMMON_MODE_AUTO_MASK : 0);
1105 }
1106
1107 /* Set up mode pin control. */
1108 if ((type == QPNP_REGULATOR_LOGICAL_TYPE_SMPS
1109 || type == QPNP_REGULATOR_LOGICAL_TYPE_LDO)
1110 && !(pdata->pin_ctrl_hpm
1111 & QPNP_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) {
1112 ctrl_reg[QPNP_COMMON_IDX_MODE] &=
1113 ~QPNP_COMMON_MODE_FOLLOW_ALL_MASK;
1114 ctrl_reg[QPNP_COMMON_IDX_MODE] |=
1115 pdata->pin_ctrl_hpm & QPNP_COMMON_MODE_FOLLOW_ALL_MASK;
1116 }
1117
1118 if (type == QPNP_REGULATOR_LOGICAL_TYPE_VS
1119 && !(pdata->pin_ctrl_hpm & QPNP_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) {
1120 ctrl_reg[QPNP_COMMON_IDX_MODE] &=
1121 ~QPNP_COMMON_MODE_FOLLOW_AWAKE_MASK;
1122 ctrl_reg[QPNP_COMMON_IDX_MODE] |=
1123 pdata->pin_ctrl_hpm & QPNP_COMMON_MODE_FOLLOW_AWAKE_MASK;
1124 }
1125
1126 if (type == QPNP_REGULATOR_LOGICAL_TYPE_LDO
1127 && pdata->bypass_mode_enable != QPNP_REGULATOR_USE_HW_DEFAULT) {
1128 ctrl_reg[QPNP_COMMON_IDX_MODE] &=
1129 ~QPNP_COMMON_MODE_BYPASS_MASK;
1130 ctrl_reg[QPNP_COMMON_IDX_MODE] |=
1131 (pdata->bypass_mode_enable
1132 ? QPNP_COMMON_MODE_BYPASS_MASK : 0);
1133 }
1134
1135 /* Set boost current limit. */
1136 if (type == QPNP_REGULATOR_LOGICAL_TYPE_BOOST
1137 && pdata->boost_current_limit
1138 != QPNP_BOOST_CURRENT_LIMIT_HW_DEFAULT) {
David Collins6f846752012-08-17 17:59:28 -07001139 reg = pdata->boost_current_limit;
1140 mask = QPNP_BOOST_CURRENT_LIMIT_MASK;
1141 rc = qpnp_vreg_masked_read_write(vreg,
1142 QPNP_BOOST_REG_CURRENT_LIMIT, reg, mask);
1143 if (rc) {
1144 vreg_err(vreg, "spmi write failed, rc=%d\n", rc);
1145 return rc;
1146 }
David Collinsd1ac2f12012-02-14 13:34:18 -08001147 }
1148
1149 /* Write back any control register values that were modified. */
1150 rc = qpnp_vreg_write_optimized(vreg, QPNP_COMMON_REG_VOLTAGE_RANGE,
1151 ctrl_reg, vreg->ctrl_reg, 8);
1152 if (rc) {
1153 vreg_err(vreg, "spmi write failed, rc=%d\n", rc);
1154 return rc;
1155 }
1156
1157 /* Set pull down. */
1158 if ((type == QPNP_REGULATOR_LOGICAL_TYPE_SMPS
1159 || type == QPNP_REGULATOR_LOGICAL_TYPE_LDO
1160 || type == QPNP_REGULATOR_LOGICAL_TYPE_VS)
1161 && pdata->pull_down_enable != QPNP_REGULATOR_USE_HW_DEFAULT) {
1162 reg = pdata->pull_down_enable
1163 ? QPNP_COMMON_PULL_DOWN_ENABLE_MASK : 0;
1164 rc = qpnp_vreg_write(vreg, QPNP_COMMON_REG_PULL_DOWN, &reg, 1);
1165 if (rc) {
1166 vreg_err(vreg, "spmi write failed, rc=%d\n", rc);
1167 return rc;
1168 }
1169 }
1170
1171 if (type == QPNP_REGULATOR_LOGICAL_TYPE_FTSMPS
1172 && pdata->pull_down_enable != QPNP_REGULATOR_USE_HW_DEFAULT) {
1173 /* FTSMPS has other bits in the pull down control register. */
1174 reg = pdata->pull_down_enable
1175 ? QPNP_COMMON_PULL_DOWN_ENABLE_MASK : 0;
1176 rc = qpnp_vreg_masked_read_write(vreg,
1177 QPNP_COMMON_REG_PULL_DOWN, reg,
1178 QPNP_COMMON_PULL_DOWN_ENABLE_MASK);
1179 if (rc) {
1180 vreg_err(vreg, "spmi write failed, rc=%d\n", rc);
1181 return rc;
1182 }
1183 }
1184
1185 /* Set soft start for LDO. */
1186 if (type == QPNP_REGULATOR_LOGICAL_TYPE_LDO
1187 && pdata->soft_start_enable != QPNP_REGULATOR_USE_HW_DEFAULT) {
1188 reg = pdata->soft_start_enable
1189 ? QPNP_LDO_SOFT_START_ENABLE_MASK : 0;
1190 rc = qpnp_vreg_write(vreg, QPNP_LDO_REG_SOFT_START, &reg, 1);
1191 if (rc) {
1192 vreg_err(vreg, "spmi write failed, rc=%d\n", rc);
1193 return rc;
1194 }
1195 }
1196
1197 /* Set soft start strength and over current protection for VS. */
1198 if (type == QPNP_REGULATOR_LOGICAL_TYPE_VS) {
1199 reg = 0;
1200 mask = 0;
1201 if (pdata->soft_start_enable != QPNP_REGULATOR_USE_HW_DEFAULT) {
1202 reg |= pdata->soft_start_enable
1203 ? QPNP_VS_SOFT_START_ENABLE_MASK : 0;
1204 mask |= QPNP_VS_SOFT_START_ENABLE_MASK;
1205 }
1206 if (pdata->vs_soft_start_strength
1207 != QPNP_VS_SOFT_START_STR_HW_DEFAULT) {
1208 reg |= pdata->vs_soft_start_strength
1209 & QPNP_VS_SOFT_START_SEL_MASK;
1210 mask |= QPNP_VS_SOFT_START_SEL_MASK;
1211 }
1212 rc = qpnp_vreg_masked_read_write(vreg, QPNP_VS_REG_SOFT_START,
1213 reg, mask);
1214 if (rc) {
1215 vreg_err(vreg, "spmi write failed, rc=%d\n", rc);
1216 return rc;
1217 }
1218
1219 if (pdata->ocp_enable != QPNP_REGULATOR_USE_HW_DEFAULT) {
1220 reg = pdata->ocp_enable ? QPNP_VS_OCP_ENABLE_MASK : 0;
1221 rc = qpnp_vreg_write(vreg, QPNP_VS_REG_OCP, &reg, 1);
1222 if (rc) {
1223 vreg_err(vreg, "spmi write failed, rc=%d\n",
1224 rc);
1225 return rc;
1226 }
1227 }
1228 }
1229
1230 return rc;
1231}
1232
1233/* Fill in pdata elements based on values found in device tree. */
1234static int qpnp_regulator_get_dt_config(struct spmi_device *spmi,
1235 struct qpnp_regulator_platform_data *pdata)
1236{
1237 struct resource *res;
1238 struct device_node *node = spmi->dev.of_node;
1239 int rc = 0;
1240
1241 pdata->init_data.constraints.input_uV
1242 = pdata->init_data.constraints.max_uV;
1243
Michael Bohan0e5534d2012-05-22 17:33:45 -07001244 res = spmi_get_resource(spmi, NULL, IORESOURCE_MEM, 0);
David Collinsd1ac2f12012-02-14 13:34:18 -08001245 if (!res) {
1246 dev_err(&spmi->dev, "%s: node is missing base address\n",
1247 __func__);
1248 return -EINVAL;
1249 }
1250 pdata->base_addr = res->start;
1251
1252 /*
1253 * Initialize configuration parameters to use hardware default in case
1254 * no value is specified via device tree.
1255 */
1256 pdata->auto_mode_enable = QPNP_REGULATOR_USE_HW_DEFAULT;
1257 pdata->bypass_mode_enable = QPNP_REGULATOR_USE_HW_DEFAULT;
1258 pdata->ocp_enable = QPNP_REGULATOR_USE_HW_DEFAULT;
1259 pdata->pull_down_enable = QPNP_REGULATOR_USE_HW_DEFAULT;
1260 pdata->soft_start_enable = QPNP_REGULATOR_USE_HW_DEFAULT;
1261 pdata->boost_current_limit = QPNP_BOOST_CURRENT_LIMIT_HW_DEFAULT;
1262 pdata->pin_ctrl_enable = QPNP_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT;
1263 pdata->pin_ctrl_hpm = QPNP_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT;
1264 pdata->vs_soft_start_strength = QPNP_VS_SOFT_START_STR_HW_DEFAULT;
1265
1266 /* These bindings are optional, so it is okay if they are not found. */
1267 of_property_read_u32(node, "qcom,auto-mode-enable",
1268 &pdata->auto_mode_enable);
1269 of_property_read_u32(node, "qcom,bypass-mode-enable",
1270 &pdata->bypass_mode_enable);
1271 of_property_read_u32(node, "qcom,ocp-enable", &pdata->ocp_enable);
1272 of_property_read_u32(node, "qcom,pull-down-enable",
1273 &pdata->pull_down_enable);
1274 of_property_read_u32(node, "qcom,soft-start-enable",
1275 &pdata->soft_start_enable);
1276 of_property_read_u32(node, "qcom,boost-current-limit",
1277 &pdata->boost_current_limit);
1278 of_property_read_u32(node, "qcom,pin-ctrl-enable",
1279 &pdata->pin_ctrl_enable);
1280 of_property_read_u32(node, "qcom,pin-ctrl-hpm", &pdata->pin_ctrl_hpm);
1281 of_property_read_u32(node, "qcom,vs-soft-start-strength",
1282 &pdata->vs_soft_start_strength);
1283 of_property_read_u32(node, "qcom,system-load", &pdata->system_load);
1284 of_property_read_u32(node, "qcom,enable-time", &pdata->enable_time);
1285 of_property_read_u32(node, "qcom,ocp-enable-time",
1286 &pdata->ocp_enable_time);
1287
1288 return rc;
1289}
1290
1291static struct of_device_id spmi_match_table[];
1292
1293#define MAX_NAME_LEN 127
1294
1295static int __devinit qpnp_regulator_probe(struct spmi_device *spmi)
1296{
1297 struct qpnp_regulator_platform_data *pdata;
1298 struct qpnp_regulator *vreg;
1299 struct regulator_desc *rdesc;
1300 struct qpnp_regulator_platform_data of_pdata;
1301 struct regulator_init_data *init_data;
1302 char *reg_name;
1303 int rc;
1304 bool is_dt;
1305
1306 vreg = kzalloc(sizeof(struct qpnp_regulator), GFP_KERNEL);
1307 if (!vreg) {
1308 dev_err(&spmi->dev, "%s: Can't allocate qpnp_regulator\n",
1309 __func__);
1310 return -ENOMEM;
1311 }
1312
1313 is_dt = of_match_device(spmi_match_table, &spmi->dev);
1314
1315 /* Check if device tree is in use. */
1316 if (is_dt) {
Steve Mucklef132c6c2012-06-06 18:30:57 -07001317 init_data = of_get_regulator_init_data(&spmi->dev,
1318 spmi->dev.of_node);
David Collinsd1ac2f12012-02-14 13:34:18 -08001319 if (!init_data) {
1320 dev_err(&spmi->dev, "%s: unable to allocate memory\n",
1321 __func__);
1322 kfree(vreg);
1323 return -ENOMEM;
1324 }
1325 memset(&of_pdata, 0,
1326 sizeof(struct qpnp_regulator_platform_data));
1327 memcpy(&of_pdata.init_data, init_data,
1328 sizeof(struct regulator_init_data));
1329
1330 if (of_get_property(spmi->dev.of_node, "parent-supply", NULL))
1331 of_pdata.init_data.supply_regulator = "parent";
1332
1333 rc = qpnp_regulator_get_dt_config(spmi, &of_pdata);
1334 if (rc) {
1335 dev_err(&spmi->dev, "%s: DT parsing failed, rc=%d\n",
1336 __func__, rc);
1337 kfree(vreg);
1338 return -ENOMEM;
1339 }
1340
1341 pdata = &of_pdata;
1342 } else {
1343 pdata = spmi->dev.platform_data;
1344 }
1345
1346 if (pdata == NULL) {
1347 dev_err(&spmi->dev, "%s: no platform data specified\n",
1348 __func__);
1349 kfree(vreg);
1350 return -EINVAL;
1351 }
1352
1353 vreg->spmi_dev = spmi;
1354 vreg->prev_write_count = -1;
1355 vreg->write_count = 0;
1356 vreg->base_addr = pdata->base_addr;
1357 vreg->enable_time = pdata->enable_time;
1358 vreg->system_load = pdata->system_load;
1359 vreg->ocp_enable = pdata->ocp_enable;
1360 vreg->ocp_enable_time = pdata->ocp_enable_time;
1361
1362 rdesc = &vreg->rdesc;
1363 rdesc->id = spmi->ctrl->nr;
1364 rdesc->owner = THIS_MODULE;
1365 rdesc->type = REGULATOR_VOLTAGE;
1366
1367 reg_name = kzalloc(strnlen(pdata->init_data.constraints.name,
1368 MAX_NAME_LEN) + 1, GFP_KERNEL);
1369 if (!reg_name) {
1370 dev_err(&spmi->dev, "%s: Can't allocate regulator name\n",
1371 __func__);
1372 kfree(vreg);
1373 return -ENOMEM;
1374 }
1375 strlcpy(reg_name, pdata->init_data.constraints.name,
1376 strnlen(pdata->init_data.constraints.name, MAX_NAME_LEN) + 1);
1377 rdesc->name = reg_name;
1378
1379 dev_set_drvdata(&spmi->dev, vreg);
1380
1381 rc = qpnp_regulator_match(vreg);
1382 if (rc) {
1383 vreg_err(vreg, "regulator type unknown, rc=%d\n", rc);
1384 goto bail;
1385 }
1386
1387 if (is_dt && rdesc->ops) {
1388 /* Fill in ops and mode masks when using device tree. */
1389 if (rdesc->ops->enable)
1390 pdata->init_data.constraints.valid_ops_mask
1391 |= REGULATOR_CHANGE_STATUS;
1392 if (rdesc->ops->get_voltage)
1393 pdata->init_data.constraints.valid_ops_mask
1394 |= REGULATOR_CHANGE_VOLTAGE;
1395 if (rdesc->ops->get_mode) {
1396 pdata->init_data.constraints.valid_ops_mask
1397 |= REGULATOR_CHANGE_MODE
1398 | REGULATOR_CHANGE_DRMS;
1399 pdata->init_data.constraints.valid_modes_mask
1400 = REGULATOR_MODE_NORMAL | REGULATOR_MODE_IDLE;
1401 }
1402 }
1403
1404 rc = qpnp_regulator_init_registers(vreg, pdata);
1405 if (rc) {
1406 vreg_err(vreg, "common initialization failed, rc=%d\n", rc);
1407 goto bail;
1408 }
1409
1410 vreg->rdev = regulator_register(rdesc, &spmi->dev,
1411 &(pdata->init_data), vreg, spmi->dev.of_node);
1412 if (IS_ERR(vreg->rdev)) {
1413 rc = PTR_ERR(vreg->rdev);
1414 vreg_err(vreg, "regulator_register failed, rc=%d\n", rc);
1415 goto bail;
1416 }
1417
1418 qpnp_vreg_show_state(vreg->rdev, QPNP_REGULATOR_ACTION_INIT);
1419
1420 return 0;
1421
1422bail:
1423 if (rc)
1424 vreg_err(vreg, "probe failed, rc=%d\n", rc);
1425
1426 kfree(vreg->rdesc.name);
1427 kfree(vreg);
1428
1429 return rc;
1430}
1431
1432static int __devexit qpnp_regulator_remove(struct spmi_device *spmi)
1433{
1434 struct qpnp_regulator *vreg;
1435
1436 vreg = dev_get_drvdata(&spmi->dev);
1437 dev_set_drvdata(&spmi->dev, NULL);
1438
1439 if (vreg) {
1440 regulator_unregister(vreg->rdev);
1441 kfree(vreg->rdesc.name);
1442 kfree(vreg);
1443 }
1444
1445 return 0;
1446}
1447
1448static struct of_device_id spmi_match_table[] = {
1449 { .compatible = QPNP_REGULATOR_DRIVER_NAME, },
1450 {}
1451};
1452
1453static const struct spmi_device_id qpnp_regulator_id[] = {
1454 { QPNP_REGULATOR_DRIVER_NAME, 0 },
1455 { }
1456};
1457MODULE_DEVICE_TABLE(spmi, qpnp_regulator_id);
1458
1459static struct spmi_driver qpnp_regulator_driver = {
1460 .driver = {
1461 .name = QPNP_REGULATOR_DRIVER_NAME,
1462 .of_match_table = spmi_match_table,
1463 .owner = THIS_MODULE,
1464 },
1465 .probe = qpnp_regulator_probe,
1466 .remove = __devexit_p(qpnp_regulator_remove),
1467 .id_table = qpnp_regulator_id,
1468};
1469
1470/*
1471 * Pre-compute the number of set points available for each regulator type to
1472 * avoid unnecessary calculations later in runtime.
1473 */
1474static void qpnp_regulator_set_point_init(void)
1475{
1476 struct qpnp_voltage_set_points **set_points;
1477 int i, j, temp;
1478
1479 set_points = all_set_points;
1480
1481 for (i = 0; i < ARRAY_SIZE(all_set_points); i++) {
1482 temp = 0;
1483 for (j = 0; j < all_set_points[i]->count; j++) {
1484 all_set_points[i]->range[j].n_voltages
1485 = (all_set_points[i]->range[j].max_uV
1486 - all_set_points[i]->range[j].set_point_min_uV)
1487 / all_set_points[i]->range[j].step_uV + 1;
1488 temp += all_set_points[i]->range[j].n_voltages;
1489 }
1490 all_set_points[i]->n_voltages = temp;
1491 }
1492}
1493
1494/**
1495 * qpnp_regulator_init() - register spmi driver for qpnp-regulator
1496 *
1497 * This initialization function should be called in systems in which driver
1498 * registration ordering must be controlled precisely.
1499 */
1500int __init qpnp_regulator_init(void)
1501{
1502 static bool has_registered;
1503
1504 if (has_registered)
1505 return 0;
1506 else
1507 has_registered = true;
1508
1509 qpnp_regulator_set_point_init();
1510
1511 return spmi_driver_register(&qpnp_regulator_driver);
1512}
1513EXPORT_SYMBOL(qpnp_regulator_init);
1514
1515static void __exit qpnp_regulator_exit(void)
1516{
1517 spmi_driver_unregister(&qpnp_regulator_driver);
1518}
1519
1520MODULE_DESCRIPTION("QPNP PMIC regulator driver");
1521MODULE_LICENSE("GPL v2");
1522
1523arch_initcall(qpnp_regulator_init);
1524module_exit(qpnp_regulator_exit);