aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/regulator/Kconfig20
-rw-r--r--drivers/regulator/Makefile2
-rw-r--r--drivers/regulator/da9063-regulator.c934
-rw-r--r--drivers/regulator/da9210-regulator.c196
-rw-r--r--drivers/regulator/da9210-regulator.h288
5 files changed, 1440 insertions, 0 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index b05fa9009e82..4a5367e3b6c3 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -157,6 +157,26 @@ config REGULATOR_DA9055
157 This driver can also be built as a module. If so, the module 157 This driver can also be built as a module. If so, the module
158 will be called da9055-regulator. 158 will be called da9055-regulator.
159 159
160config REGULATOR_DA9063
161 tristate "Dialog Semiconductor DA9063 regulators"
162 depends on MFD_DA9063
163 help
164 Say y here to support the BUCKs and LDOs regulators found on
165 DA9063 PMICs.
166
167 This driver can also be built as a module. If so, the module
168 will be called da9063-regulator.
169
170config REGULATOR_DA9210
171 tristate "Dialog Semiconductor DA9210 regulator"
172 depends on I2C
173 select REGMAP_I2C
174 help
175 Say y here to support for the Dialog Semiconductor DA9210.
176 The DA9210 is a multi-phase synchronous step down
177 converter 12A DC-DC Buck controlled through an I2C
178 interface.
179
160config REGULATOR_DBX500_PRCMU 180config REGULATOR_DBX500_PRCMU
161 bool 181 bool
162 182
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index e292f26a1fbd..40cbb1b35c1d 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -21,6 +21,8 @@ obj-$(CONFIG_REGULATOR_AS3711) += as3711-regulator.o
21obj-$(CONFIG_REGULATOR_DA903X) += da903x.o 21obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
22obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o 22obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o
23obj-$(CONFIG_REGULATOR_DA9055) += da9055-regulator.o 23obj-$(CONFIG_REGULATOR_DA9055) += da9055-regulator.o
24obj-$(CONFIG_REGULATOR_DA9063) += da9063-regulator.o
25obj-$(CONFIG_REGULATOR_DA9210) += da9210-regulator.o
24obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o 26obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o
25obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o 27obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o
26obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o 28obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o
diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c
new file mode 100644
index 000000000000..1a7816390773
--- /dev/null
+++ b/drivers/regulator/da9063-regulator.c
@@ -0,0 +1,934 @@
1/*
2 * Regulator driver for DA9063 PMIC series
3 *
4 * Copyright 2012 Dialog Semiconductors Ltd.
5 * Copyright 2013 Philipp Zabel, Pengutronix
6 *
7 * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 */
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/err.h>
19#include <linux/slab.h>
20#include <linux/of.h>
21#include <linux/platform_device.h>
22#include <linux/regmap.h>
23#include <linux/regulator/driver.h>
24#include <linux/regulator/machine.h>
25#include <linux/regulator/of_regulator.h>
26#include <linux/mfd/da9063/core.h>
27#include <linux/mfd/da9063/pdata.h>
28#include <linux/mfd/da9063/registers.h>
29
30
31/* Definition for registering regmap bit fields using a mask */
32#define BFIELD(_reg, _mask) \
33 REG_FIELD(_reg, __builtin_ffs((int)_mask) - 1, \
34 sizeof(unsigned int) * 8 - __builtin_clz((_mask)) - 1)
35
36/* Regulator capabilities and registers description */
37struct da9063_regulator_info {
38 struct regulator_desc desc;
39
40 /* Current limiting */
41 unsigned n_current_limits;
42 const int *current_limits;
43
44 /* DA9063 main register fields */
45 struct reg_field mode; /* buck mode of operation */
46 struct reg_field suspend;
47 struct reg_field sleep;
48 struct reg_field suspend_sleep;
49 unsigned int suspend_vsel_reg;
50 struct reg_field ilimit;
51
52 /* DA9063 event detection bit */
53 struct reg_field oc_event;
54};
55
56/* Macros for LDO */
57#define DA9063_LDO(chip, regl_name, min_mV, step_mV, max_mV) \
58 .desc.id = chip##_ID_##regl_name, \
59 .desc.name = __stringify(chip##_##regl_name), \
60 .desc.ops = &da9063_ldo_ops, \
61 .desc.min_uV = (min_mV) * 1000, \
62 .desc.uV_step = (step_mV) * 1000, \
63 .desc.n_voltages = (((max_mV) - (min_mV))/(step_mV) + 1), \
64 .desc.enable_reg = DA9063_REG_##regl_name##_CONT, \
65 .desc.enable_mask = DA9063_LDO_EN, \
66 .desc.vsel_reg = DA9063_REG_V##regl_name##_A, \
67 .desc.vsel_mask = DA9063_V##regl_name##_MASK, \
68 .desc.linear_min_sel = DA9063_V##regl_name##_BIAS, \
69 .sleep = BFIELD(DA9063_REG_V##regl_name##_A, DA9063_LDO_SL), \
70 .suspend_sleep = BFIELD(DA9063_REG_V##regl_name##_B, DA9063_LDO_SL), \
71 .suspend_vsel_reg = DA9063_REG_V##regl_name##_B
72
73/* Macros for voltage DC/DC converters (BUCKs) */
74#define DA9063_BUCK(chip, regl_name, min_mV, step_mV, max_mV, limits_array) \
75 .desc.id = chip##_ID_##regl_name, \
76 .desc.name = __stringify(chip##_##regl_name), \
77 .desc.ops = &da9063_buck_ops, \
78 .desc.min_uV = (min_mV) * 1000, \
79 .desc.uV_step = (step_mV) * 1000, \
80 .desc.n_voltages = ((max_mV) - (min_mV))/(step_mV) + 1, \
81 .current_limits = limits_array, \
82 .n_current_limits = ARRAY_SIZE(limits_array)
83
84#define DA9063_BUCK_COMMON_FIELDS(regl_name) \
85 .desc.enable_reg = DA9063_REG_##regl_name##_CONT, \
86 .desc.enable_mask = DA9063_BUCK_EN, \
87 .desc.vsel_reg = DA9063_REG_V##regl_name##_A, \
88 .desc.vsel_mask = DA9063_VBUCK_MASK, \
89 .desc.linear_min_sel = DA9063_VBUCK_BIAS, \
90 .sleep = BFIELD(DA9063_REG_V##regl_name##_A, DA9063_BUCK_SL), \
91 .suspend_sleep = BFIELD(DA9063_REG_V##regl_name##_B, DA9063_BUCK_SL), \
92 .suspend_vsel_reg = DA9063_REG_V##regl_name##_B, \
93 .mode = BFIELD(DA9063_REG_##regl_name##_CFG, DA9063_BUCK_MODE_MASK)
94
95/* Defines asignment of regulators info table to chip model */
96struct da9063_dev_model {
97 const struct da9063_regulator_info *regulator_info;
98 unsigned n_regulators;
99 unsigned dev_model;
100};
101
102/* Single regulator settings */
103struct da9063_regulator {
104 struct regulator_desc desc;
105 struct regulator_dev *rdev;
106 struct da9063 *hw;
107 const struct da9063_regulator_info *info;
108
109 struct regmap_field *mode;
110 struct regmap_field *suspend;
111 struct regmap_field *sleep;
112 struct regmap_field *suspend_sleep;
113 struct regmap_field *ilimit;
114};
115
116/* Encapsulates all information for the regulators driver */
117struct da9063_regulators {
118 int irq_ldo_lim;
119 int irq_uvov;
120
121 unsigned n_regulators;
122 /* Array size to be defined during init. Keep at end. */
123 struct da9063_regulator regulator[0];
124};
125
126/* BUCK modes for DA9063 */
127enum {
128 BUCK_MODE_MANUAL, /* 0 */
129 BUCK_MODE_SLEEP, /* 1 */
130 BUCK_MODE_SYNC, /* 2 */
131 BUCK_MODE_AUTO /* 3 */
132};
133
134/* Regulator operations */
135
136/* Current limits array (in uA) for BCORE1, BCORE2, BPRO.
137 Entry indexes corresponds to register values. */
138static const int da9063_buck_a_limits[] = {
139 500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000,
140 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000
141};
142
143/* Current limits array (in uA) for BMEM, BIO, BPERI.
144 Entry indexes corresponds to register values. */
145static const int da9063_buck_b_limits[] = {
146 1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,
147 2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000
148};
149
150/* Current limits array (in uA) for merged BCORE1 and BCORE2.
151 Entry indexes corresponds to register values. */
152static const int da9063_bcores_merged_limits[] = {
153 1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000,
154 2600000, 2800000, 3000000, 3200000, 3400000, 3600000, 3800000, 4000000
155};
156
157/* Current limits array (in uA) for merged BMEM and BIO.
158 Entry indexes corresponds to register values. */
159static const int da9063_bmem_bio_merged_limits[] = {
160 3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000,
161 4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000
162};
163
164static int da9063_set_current_limit(struct regulator_dev *rdev,
165 int min_uA, int max_uA)
166{
167 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
168 const struct da9063_regulator_info *rinfo = regl->info;
169 int n, tval;
170
171 for (n = 0; n < rinfo->n_current_limits; n++) {
172 tval = rinfo->current_limits[n];
173 if (tval >= min_uA && tval <= max_uA)
174 return regmap_field_write(regl->ilimit, n);
175 }
176
177 return -EINVAL;
178}
179
180static int da9063_get_current_limit(struct regulator_dev *rdev)
181{
182 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
183 const struct da9063_regulator_info *rinfo = regl->info;
184 unsigned int sel;
185 int ret;
186
187 ret = regmap_field_read(regl->ilimit, &sel);
188 if (ret < 0)
189 return ret;
190
191 if (sel >= rinfo->n_current_limits)
192 sel = rinfo->n_current_limits - 1;
193
194 return rinfo->current_limits[sel];
195}
196
197static int da9063_buck_set_mode(struct regulator_dev *rdev, unsigned mode)
198{
199 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
200 unsigned val;
201
202 switch (mode) {
203 case REGULATOR_MODE_FAST:
204 val = BUCK_MODE_SYNC;
205 break;
206 case REGULATOR_MODE_NORMAL:
207 val = BUCK_MODE_AUTO;
208 break;
209 case REGULATOR_MODE_STANDBY:
210 val = BUCK_MODE_SLEEP;
211 break;
212 default:
213 return -EINVAL;
214 }
215
216 return regmap_field_write(regl->mode, val);
217}
218
219/*
220 * Bucks use single mode register field for normal operation
221 * and suspend state.
222 * There are 3 modes to map to: FAST, NORMAL, and STANDBY.
223 */
224
225static unsigned da9063_buck_get_mode(struct regulator_dev *rdev)
226{
227 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
228 struct regmap_field *field;
229 unsigned int val, mode = 0;
230 int ret;
231
232 ret = regmap_field_read(regl->mode, &val);
233 if (ret < 0)
234 return ret;
235
236 switch (val) {
237 default:
238 case BUCK_MODE_MANUAL:
239 mode = REGULATOR_MODE_FAST | REGULATOR_MODE_STANDBY;
240 /* Sleep flag bit decides the mode */
241 break;
242 case BUCK_MODE_SLEEP:
243 return REGULATOR_MODE_STANDBY;
244 case BUCK_MODE_SYNC:
245 return REGULATOR_MODE_FAST;
246 case BUCK_MODE_AUTO:
247 return REGULATOR_MODE_NORMAL;
248 }
249
250 /* Detect current regulator state */
251 ret = regmap_field_read(regl->suspend, &val);
252 if (ret < 0)
253 return 0;
254
255 /* Read regulator mode from proper register, depending on state */
256 if (val)
257 field = regl->suspend_sleep;
258 else
259 field = regl->sleep;
260
261 ret = regmap_field_read(field, &val);
262 if (ret < 0)
263 return 0;
264
265 if (val)
266 mode &= REGULATOR_MODE_STANDBY;
267 else
268 mode &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST;
269
270 return mode;
271}
272
273/*
274 * LDOs use sleep flags - one for normal and one for suspend state.
275 * There are 2 modes to map to: NORMAL and STANDBY (sleep) for each state.
276 */
277
278static int da9063_ldo_set_mode(struct regulator_dev *rdev, unsigned mode)
279{
280 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
281 unsigned val;
282
283 switch (mode) {
284 case REGULATOR_MODE_NORMAL:
285 val = 0;
286 break;
287 case REGULATOR_MODE_STANDBY:
288 val = 1;
289 break;
290 default:
291 return -EINVAL;
292 }
293
294 return regmap_field_write(regl->sleep, val);
295}
296
297static unsigned da9063_ldo_get_mode(struct regulator_dev *rdev)
298{
299 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
300 struct regmap_field *field;
301 int ret, val;
302
303 /* Detect current regulator state */
304 ret = regmap_field_read(regl->suspend, &val);
305 if (ret < 0)
306 return 0;
307
308 /* Read regulator mode from proper register, depending on state */
309 if (val)
310 field = regl->suspend_sleep;
311 else
312 field = regl->sleep;
313
314 ret = regmap_field_read(field, &val);
315 if (ret < 0)
316 return 0;
317
318 if (val)
319 return REGULATOR_MODE_STANDBY;
320 else
321 return REGULATOR_MODE_NORMAL;
322}
323
324static int da9063_buck_get_status(struct regulator_dev *rdev)
325{
326 int ret = regulator_is_enabled_regmap(rdev);
327
328 if (ret == 0) {
329 ret = REGULATOR_STATUS_OFF;
330 } else if (ret > 0) {
331 ret = da9063_buck_get_mode(rdev);
332 if (ret > 0)
333 ret = regulator_mode_to_status(ret);
334 else if (ret == 0)
335 ret = -EIO;
336 }
337
338 return ret;
339}
340
341static int da9063_ldo_get_status(struct regulator_dev *rdev)
342{
343 int ret = regulator_is_enabled_regmap(rdev);
344
345 if (ret == 0) {
346 ret = REGULATOR_STATUS_OFF;
347 } else if (ret > 0) {
348 ret = da9063_ldo_get_mode(rdev);
349 if (ret > 0)
350 ret = regulator_mode_to_status(ret);
351 else if (ret == 0)
352 ret = -EIO;
353 }
354
355 return ret;
356}
357
358static int da9063_set_suspend_voltage(struct regulator_dev *rdev, int uV)
359{
360 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
361 const struct da9063_regulator_info *rinfo = regl->info;
362 int ret, sel;
363
364 sel = regulator_map_voltage_linear(rdev, uV, uV);
365 if (sel < 0)
366 return -EINVAL;
367
368 sel <<= ffs(rdev->desc->vsel_mask) - 1;
369
370 ret = regmap_update_bits(regl->hw->regmap, rinfo->suspend_vsel_reg,
371 rdev->desc->vsel_mask, sel);
372
373 return ret;
374}
375
376static int da9063_suspend_enable(struct regulator_dev *rdev)
377{
378 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
379
380 return regmap_field_write(regl->suspend, 1);
381}
382
383static int da9063_suspend_disable(struct regulator_dev *rdev)
384{
385 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
386
387 return regmap_field_write(regl->suspend, 0);
388}
389
390static int da9063_buck_set_suspend_mode(struct regulator_dev *rdev, unsigned mode)
391{
392 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
393 int val;
394
395 switch (mode) {
396 case REGULATOR_MODE_FAST:
397 val = BUCK_MODE_SYNC;
398 break;
399 case REGULATOR_MODE_NORMAL:
400 val = BUCK_MODE_AUTO;
401 break;
402 case REGULATOR_MODE_STANDBY:
403 val = BUCK_MODE_SLEEP;
404 break;
405 default:
406 return -EINVAL;
407 }
408
409 return regmap_field_write(regl->mode, val);
410}
411
412static int da9063_ldo_set_suspend_mode(struct regulator_dev *rdev, unsigned mode)
413{
414 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
415 unsigned val;
416
417 switch (mode) {
418 case REGULATOR_MODE_NORMAL:
419 val = 0;
420 break;
421 case REGULATOR_MODE_STANDBY:
422 val = 1;
423 break;
424 default:
425 return -EINVAL;
426 }
427
428 return regmap_field_write(regl->suspend_sleep, val);
429}
430
431static struct regulator_ops da9063_buck_ops = {
432 .enable = regulator_enable_regmap,
433 .disable = regulator_disable_regmap,
434 .is_enabled = regulator_is_enabled_regmap,
435 .get_voltage_sel = regulator_get_voltage_sel_regmap,
436 .set_voltage_sel = regulator_set_voltage_sel_regmap,
437 .list_voltage = regulator_list_voltage_linear,
438 .set_current_limit = da9063_set_current_limit,
439 .get_current_limit = da9063_get_current_limit,
440 .set_mode = da9063_buck_set_mode,
441 .get_mode = da9063_buck_get_mode,
442 .get_status = da9063_buck_get_status,
443 .set_suspend_voltage = da9063_set_suspend_voltage,
444 .set_suspend_enable = da9063_suspend_enable,
445 .set_suspend_disable = da9063_suspend_disable,
446 .set_suspend_mode = da9063_buck_set_suspend_mode,
447};
448
449static struct regulator_ops da9063_ldo_ops = {
450 .enable = regulator_enable_regmap,
451 .disable = regulator_disable_regmap,
452 .is_enabled = regulator_is_enabled_regmap,
453 .get_voltage_sel = regulator_get_voltage_sel_regmap,
454 .set_voltage_sel = regulator_set_voltage_sel_regmap,
455 .list_voltage = regulator_list_voltage_linear,
456 .set_mode = da9063_ldo_set_mode,
457 .get_mode = da9063_ldo_get_mode,
458 .get_status = da9063_ldo_get_status,
459 .set_suspend_voltage = da9063_set_suspend_voltage,
460 .set_suspend_enable = da9063_suspend_enable,
461 .set_suspend_disable = da9063_suspend_disable,
462 .set_suspend_mode = da9063_ldo_set_suspend_mode,
463};
464
465/* Info of regulators for DA9063 */
466static const struct da9063_regulator_info da9063_regulator_info[] = {
467 {
468 DA9063_BUCK(DA9063, BCORE1, 300, 10, 1570,
469 da9063_buck_a_limits),
470 DA9063_BUCK_COMMON_FIELDS(BCORE1),
471 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE1_SEL),
472 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_C,
473 DA9063_BCORE1_ILIM_MASK),
474 },
475 {
476 DA9063_BUCK(DA9063, BCORE2, 300, 10, 1570,
477 da9063_buck_a_limits),
478 DA9063_BUCK_COMMON_FIELDS(BCORE2),
479 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE2_SEL),
480 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_C,
481 DA9063_BCORE2_ILIM_MASK),
482 },
483 {
484 DA9063_BUCK(DA9063, BPRO, 530, 10, 1800,
485 da9063_buck_a_limits),
486 DA9063_BUCK_COMMON_FIELDS(BPRO),
487 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBPRO_SEL),
488 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_B,
489 DA9063_BPRO_ILIM_MASK),
490 },
491 {
492 DA9063_BUCK(DA9063, BMEM, 800, 20, 3340,
493 da9063_buck_b_limits),
494 DA9063_BUCK_COMMON_FIELDS(BMEM),
495 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBMEM_SEL),
496 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_A,
497 DA9063_BMEM_ILIM_MASK),
498 },
499 {
500 DA9063_BUCK(DA9063, BIO, 800, 20, 3340,
501 da9063_buck_b_limits),
502 DA9063_BUCK_COMMON_FIELDS(BIO),
503 .suspend = BFIELD(DA9063_REG_DVC_2, DA9063_VBIO_SEL),
504 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_A,
505 DA9063_BIO_ILIM_MASK),
506 },
507 {
508 DA9063_BUCK(DA9063, BPERI, 800, 20, 3340,
509 da9063_buck_b_limits),
510 DA9063_BUCK_COMMON_FIELDS(BPERI),
511 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBPERI_SEL),
512 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_B,
513 DA9063_BPERI_ILIM_MASK),
514 },
515 {
516 DA9063_BUCK(DA9063, BCORES_MERGED, 300, 10, 1570,
517 da9063_bcores_merged_limits),
518 /* BCORES_MERGED uses the same register fields as BCORE1 */
519 DA9063_BUCK_COMMON_FIELDS(BCORE1),
520 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE1_SEL),
521 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_C,
522 DA9063_BCORE1_ILIM_MASK),
523 },
524 {
525 DA9063_BUCK(DA9063, BMEM_BIO_MERGED, 800, 20, 3340,
526 da9063_bmem_bio_merged_limits),
527 /* BMEM_BIO_MERGED uses the same register fields as BMEM */
528 DA9063_BUCK_COMMON_FIELDS(BMEM),
529 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBMEM_SEL),
530 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_A,
531 DA9063_BMEM_ILIM_MASK),
532 },
533 {
534 DA9063_LDO(DA9063, LDO1, 600, 20, 1860),
535 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VLDO1_SEL),
536 },
537 {
538 DA9063_LDO(DA9063, LDO2, 600, 20, 1860),
539 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VLDO2_SEL),
540 },
541 {
542 DA9063_LDO(DA9063, LDO3, 900, 20, 3440),
543 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VLDO3_SEL),
544 .oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO3_LIM),
545 },
546 {
547 DA9063_LDO(DA9063, LDO4, 900, 20, 3440),
548 .suspend = BFIELD(DA9063_REG_DVC_2, DA9063_VLDO4_SEL),
549 .oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO4_LIM),
550 },
551 {
552 DA9063_LDO(DA9063, LDO5, 900, 50, 3600),
553 .suspend = BFIELD(DA9063_REG_LDO5_CONT, DA9063_VLDO5_SEL),
554 },
555 {
556 DA9063_LDO(DA9063, LDO6, 900, 50, 3600),
557 .suspend = BFIELD(DA9063_REG_LDO6_CONT, DA9063_VLDO6_SEL),
558 },
559 {
560 DA9063_LDO(DA9063, LDO7, 900, 50, 3600),
561 .suspend = BFIELD(DA9063_REG_LDO7_CONT, DA9063_VLDO7_SEL),
562 .oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO7_LIM),
563 },
564 {
565 DA9063_LDO(DA9063, LDO8, 900, 50, 3600),
566 .suspend = BFIELD(DA9063_REG_LDO8_CONT, DA9063_VLDO8_SEL),
567 .oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO8_LIM),
568 },
569 {
570 DA9063_LDO(DA9063, LDO9, 950, 50, 3600),
571 .suspend = BFIELD(DA9063_REG_LDO9_CONT, DA9063_VLDO9_SEL),
572 },
573 {
574 DA9063_LDO(DA9063, LDO10, 900, 50, 3600),
575 .suspend = BFIELD(DA9063_REG_LDO10_CONT, DA9063_VLDO10_SEL),
576 },
577 {
578 DA9063_LDO(DA9063, LDO11, 900, 50, 3600),
579 .suspend = BFIELD(DA9063_REG_LDO11_CONT, DA9063_VLDO11_SEL),
580 .oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO11_LIM),
581 },
582};
583
584/* Link chip model with regulators info table */
585static struct da9063_dev_model regulators_models[] = {
586 {
587 .regulator_info = da9063_regulator_info,
588 .n_regulators = ARRAY_SIZE(da9063_regulator_info),
589 .dev_model = PMIC_DA9063,
590 },
591 { }
592};
593
594/* Regulator interrupt handlers */
595static irqreturn_t da9063_ldo_lim_event(int irq, void *data)
596{
597 struct da9063_regulators *regulators = data;
598 struct da9063 *hw = regulators->regulator[0].hw;
599 struct da9063_regulator *regl;
600 int bits, i , ret;
601
602 ret = regmap_read(hw->regmap, DA9063_REG_STATUS_D, &bits);
603 if (ret < 0)
604 return IRQ_NONE;
605
606 for (i = regulators->n_regulators - 1; i >= 0; i--) {
607 regl = &regulators->regulator[i];
608 if (regl->info->oc_event.reg != DA9063_REG_STATUS_D)
609 continue;
610
611 if (BIT(regl->info->oc_event.lsb) & bits)
612 regulator_notifier_call_chain(regl->rdev,
613 REGULATOR_EVENT_OVER_CURRENT, NULL);
614 }
615
616 return IRQ_HANDLED;
617}
618
619/*
620 * Probing and Initialisation functions
621 */
622static const struct regulator_init_data *da9063_get_regulator_initdata(
623 const struct da9063_regulators_pdata *regl_pdata, int id)
624{
625 int i;
626
627 for (i = 0; i < regl_pdata->n_regulators; i++) {
628 if (id == regl_pdata->regulator_data[i].id)
629 return regl_pdata->regulator_data[i].initdata;
630 }
631
632 return NULL;
633}
634
635#ifdef CONFIG_OF
636static struct of_regulator_match da9063_matches[] = {
637 [DA9063_ID_BCORE1] = { .name = "bcore1" },
638 [DA9063_ID_BCORE2] = { .name = "bcore2" },
639 [DA9063_ID_BPRO] = { .name = "bpro", },
640 [DA9063_ID_BMEM] = { .name = "bmem", },
641 [DA9063_ID_BIO] = { .name = "bio", },
642 [DA9063_ID_BPERI] = { .name = "bperi", },
643 [DA9063_ID_BCORES_MERGED] = { .name = "bcores-merged" },
644 [DA9063_ID_BMEM_BIO_MERGED] = { .name = "bmem-bio-merged", },
645 [DA9063_ID_LDO1] = { .name = "ldo1", },
646 [DA9063_ID_LDO2] = { .name = "ldo2", },
647 [DA9063_ID_LDO3] = { .name = "ldo3", },
648 [DA9063_ID_LDO4] = { .name = "ldo4", },
649 [DA9063_ID_LDO5] = { .name = "ldo5", },
650 [DA9063_ID_LDO6] = { .name = "ldo6", },
651 [DA9063_ID_LDO7] = { .name = "ldo7", },
652 [DA9063_ID_LDO8] = { .name = "ldo8", },
653 [DA9063_ID_LDO9] = { .name = "ldo9", },
654 [DA9063_ID_LDO10] = { .name = "ldo10", },
655 [DA9063_ID_LDO11] = { .name = "ldo11", },
656};
657
658static struct da9063_regulators_pdata *da9063_parse_regulators_dt(
659 struct platform_device *pdev,
660 struct of_regulator_match **da9063_reg_matches)
661{
662 struct da9063_regulators_pdata *pdata;
663 struct da9063_regulator_data *rdata;
664 struct device_node *node;
665 int i, n, num;
666
667 node = of_find_node_by_name(pdev->dev.parent->of_node, "regulators");
668 if (!node) {
669 dev_err(&pdev->dev, "Regulators device node not found\n");
670 return ERR_PTR(-ENODEV);
671 }
672
673 num = of_regulator_match(&pdev->dev, node, da9063_matches,
674 ARRAY_SIZE(da9063_matches));
675 if (num < 0) {
676 dev_err(&pdev->dev, "Failed to match regulators\n");
677 return ERR_PTR(-EINVAL);
678 }
679
680 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
681 if (!pdata)
682 return ERR_PTR(-ENOMEM);
683
684 pdata->regulator_data = devm_kzalloc(&pdev->dev,
685 num * sizeof(*pdata->regulator_data),
686 GFP_KERNEL);
687 if (!pdata->regulator_data)
688 return ERR_PTR(-ENOMEM);
689 pdata->n_regulators = num;
690
691 n = 0;
692 for (i = 0; i < ARRAY_SIZE(da9063_matches); i++) {
693 if (!da9063_matches[i].init_data)
694 continue;
695
696 rdata = &pdata->regulator_data[n];
697 rdata->id = i;
698 rdata->initdata = da9063_matches[i].init_data;
699
700 n++;
701 };
702
703 *da9063_reg_matches = da9063_matches;
704 return pdata;
705}
706#else
707static struct da9063_regulators_pdata *da9063_parse_regulators_dt(
708 struct platform_device *pdev,
709 struct of_regulator_match **da9063_reg_matches)
710{
711 da9063_reg_matches = NULL;
712 return PTR_ERR(-ENODEV);
713}
714#endif
715
716static int da9063_regulator_probe(struct platform_device *pdev)
717{
718 struct da9063 *da9063 = dev_get_drvdata(pdev->dev.parent);
719 struct da9063_pdata *da9063_pdata = dev_get_platdata(da9063->dev);
720 struct of_regulator_match *da9063_reg_matches;
721 struct da9063_regulators_pdata *regl_pdata;
722 const struct da9063_dev_model *model;
723 struct da9063_regulators *regulators;
724 struct da9063_regulator *regl;
725 struct regulator_config config;
726 bool bcores_merged, bmem_bio_merged;
727 int id, irq, n, n_regulators, ret, val;
728 size_t size;
729
730 regl_pdata = da9063_pdata ? da9063_pdata->regulators_pdata : NULL;
731
732 if (!regl_pdata)
733 regl_pdata = da9063_parse_regulators_dt(pdev,
734 &da9063_reg_matches);
735
736 if (IS_ERR(regl_pdata) || regl_pdata->n_regulators == 0) {
737 dev_err(&pdev->dev,
738 "No regulators defined for the platform\n");
739 return PTR_ERR(regl_pdata);
740 }
741
742 /* Find regulators set for particular device model */
743 for (model = regulators_models; model->regulator_info; model++) {
744 if (model->dev_model == da9063->model)
745 break;
746 }
747 if (!model->regulator_info) {
748 dev_err(&pdev->dev, "Chip model not recognised (%u)\n",
749 da9063->model);
750 return -ENODEV;
751 }
752
753 ret = regmap_read(da9063->regmap, DA9063_REG_CONFIG_H, &val);
754 if (ret < 0) {
755 dev_err(&pdev->dev,
756 "Error while reading BUCKs configuration\n");
757 return -EIO;
758 }
759 bcores_merged = val & DA9063_BCORE_MERGE;
760 bmem_bio_merged = val & DA9063_BUCK_MERGE;
761
762 n_regulators = model->n_regulators;
763 if (bcores_merged)
764 n_regulators -= 2; /* remove BCORE1, BCORE2 */
765 else
766 n_regulators--; /* remove BCORES_MERGED */
767 if (bmem_bio_merged)
768 n_regulators -= 2; /* remove BMEM, BIO */
769 else
770 n_regulators--; /* remove BMEM_BIO_MERGED */
771
772 /* Allocate memory required by usable regulators */
773 size = sizeof(struct da9063_regulators) +
774 n_regulators * sizeof(struct da9063_regulator);
775 regulators = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
776 if (!regulators) {
777 dev_err(&pdev->dev, "No memory for regulators\n");
778 return -ENOMEM;
779 }
780
781 regulators->n_regulators = n_regulators;
782 platform_set_drvdata(pdev, regulators);
783
784 /* Register all regulators declared in platform information */
785 n = 0;
786 id = 0;
787 while (n < regulators->n_regulators) {
788 /* Skip regulator IDs depending on merge mode configuration */
789 switch (id) {
790 case DA9063_ID_BCORE1:
791 case DA9063_ID_BCORE2:
792 if (bcores_merged) {
793 id++;
794 continue;
795 }
796 break;
797 case DA9063_ID_BMEM:
798 case DA9063_ID_BIO:
799 if (bmem_bio_merged) {
800 id++;
801 continue;
802 }
803 break;
804 case DA9063_ID_BCORES_MERGED:
805 if (!bcores_merged) {
806 id++;
807 continue;
808 }
809 break;
810 case DA9063_ID_BMEM_BIO_MERGED:
811 if (!bmem_bio_merged) {
812 id++;
813 continue;
814 }
815 break;
816 }
817
818 /* Initialise regulator structure */
819 regl = &regulators->regulator[n];
820 regl->hw = da9063;
821 regl->info = &model->regulator_info[id];
822 regl->desc = regl->info->desc;
823 regl->desc.type = REGULATOR_VOLTAGE;
824 regl->desc.owner = THIS_MODULE;
825
826 if (regl->info->mode.reg)
827 regl->mode = devm_regmap_field_alloc(&pdev->dev,
828 da9063->regmap, regl->info->mode);
829 if (regl->info->suspend.reg)
830 regl->suspend = devm_regmap_field_alloc(&pdev->dev,
831 da9063->regmap, regl->info->suspend);
832 if (regl->info->sleep.reg)
833 regl->sleep = devm_regmap_field_alloc(&pdev->dev,
834 da9063->regmap, regl->info->sleep);
835 if (regl->info->suspend_sleep.reg)
836 regl->suspend_sleep = devm_regmap_field_alloc(&pdev->dev,
837 da9063->regmap, regl->info->suspend_sleep);
838 if (regl->info->ilimit.reg)
839 regl->ilimit = devm_regmap_field_alloc(&pdev->dev,
840 da9063->regmap, regl->info->ilimit);
841
842 /* Register regulator */
843 memset(&config, 0, sizeof(config));
844 config.dev = &pdev->dev;
845 config.init_data = da9063_get_regulator_initdata(regl_pdata, id);
846 config.driver_data = regl;
847 if (da9063_reg_matches)
848 config.of_node = da9063_reg_matches[id].of_node;
849 config.regmap = da9063->regmap;
850 regl->rdev = regulator_register(&regl->desc, &config);
851 if (IS_ERR(regl->rdev)) {
852 dev_err(&pdev->dev,
853 "Failed to register %s regulator\n",
854 regl->desc.name);
855 ret = PTR_ERR(regl->rdev);
856 goto err;
857 }
858 id++;
859 n++;
860 }
861
862 /* LDOs overcurrent event support */
863 irq = platform_get_irq_byname(pdev, "LDO_LIM");
864 if (irq < 0) {
865 ret = irq;
866 dev_err(&pdev->dev, "Failed to get IRQ.\n");
867 goto err;
868 }
869
870 regulators->irq_ldo_lim = regmap_irq_get_virq(da9063->regmap_irq, irq);
871 if (regulators->irq_ldo_lim >= 0) {
872 ret = request_threaded_irq(regulators->irq_ldo_lim,
873 NULL, da9063_ldo_lim_event,
874 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
875 "LDO_LIM", regulators);
876 if (ret) {
877 dev_err(&pdev->dev,
878 "Failed to request LDO_LIM IRQ.\n");
879 regulators->irq_ldo_lim = -ENXIO;
880 }
881 }
882
883 return 0;
884
885err:
886 /* Wind back regulators registeration */
887 while (--n >= 0)
888 regulator_unregister(regulators->regulator[n].rdev);
889
890 return ret;
891}
892
893static int da9063_regulator_remove(struct platform_device *pdev)
894{
895 struct da9063_regulators *regulators = platform_get_drvdata(pdev);
896 struct da9063_regulator *regl;
897
898 free_irq(regulators->irq_ldo_lim, regulators);
899 free_irq(regulators->irq_uvov, regulators);
900
901 for (regl = &regulators->regulator[regulators->n_regulators - 1];
902 regl >= &regulators->regulator[0]; regl--)
903 regulator_unregister(regl->rdev);
904
905 return 0;
906}
907
908static struct platform_driver da9063_regulator_driver = {
909 .driver = {
910 .name = DA9063_DRVNAME_REGULATORS,
911 .owner = THIS_MODULE,
912 },
913 .probe = da9063_regulator_probe,
914 .remove = da9063_regulator_remove,
915};
916
917static int __init da9063_regulator_init(void)
918{
919 return platform_driver_register(&da9063_regulator_driver);
920}
921subsys_initcall(da9063_regulator_init);
922
923static void __exit da9063_regulator_cleanup(void)
924{
925 platform_driver_unregister(&da9063_regulator_driver);
926}
927module_exit(da9063_regulator_cleanup);
928
929
930/* Module information */
931MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>");
932MODULE_DESCRIPTION("DA9063 regulators driver");
933MODULE_LICENSE("GPL");
934MODULE_ALIAS("paltform:" DA9063_DRVNAME_REGULATORS);
diff --git a/drivers/regulator/da9210-regulator.c b/drivers/regulator/da9210-regulator.c
new file mode 100644
index 000000000000..f0fe54b38977
--- /dev/null
+++ b/drivers/regulator/da9210-regulator.c
@@ -0,0 +1,196 @@
1/*
2 * da9210-regulator.c - Regulator device driver for DA9210
3 * Copyright (C) 2013 Dialog Semiconductor Ltd.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#include <linux/err.h>
22#include <linux/i2c.h>
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/slab.h>
26#include <linux/regulator/driver.h>
27#include <linux/regulator/machine.h>
28#include <linux/regmap.h>
29
30#include "da9210-regulator.h"
31
32struct da9210 {
33 struct regulator_dev *rdev;
34 struct regmap *regmap;
35};
36
37static const struct regmap_config da9210_regmap_config = {
38 .reg_bits = 8,
39 .val_bits = 8,
40};
41
42static int da9210_set_current_limit(struct regulator_dev *rdev, int min_uA,
43 int max_uA);
44static int da9210_get_current_limit(struct regulator_dev *rdev);
45
46static struct regulator_ops da9210_buck_ops = {
47 .enable = regulator_enable_regmap,
48 .disable = regulator_disable_regmap,
49 .is_enabled = regulator_is_enabled_regmap,
50 .set_voltage_sel = regulator_set_voltage_sel_regmap,
51 .get_voltage_sel = regulator_get_voltage_sel_regmap,
52 .list_voltage = regulator_list_voltage_linear,
53 .set_current_limit = da9210_set_current_limit,
54 .get_current_limit = da9210_get_current_limit,
55};
56
57/* Default limits measured in millivolts and milliamps */
58#define DA9210_MIN_MV 300
59#define DA9210_MAX_MV 1570
60#define DA9210_STEP_MV 10
61
62/* Current limits for buck (uA) indices corresponds with register values */
63static const int da9210_buck_limits[] = {
64 1600000, 1800000, 2000000, 2200000, 2400000, 2600000, 2800000, 3000000,
65 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000, 4600000
66};
67
68static const struct regulator_desc da9210_reg = {
69 .name = "DA9210",
70 .id = 0,
71 .ops = &da9210_buck_ops,
72 .type = REGULATOR_VOLTAGE,
73 .n_voltages = ((DA9210_MAX_MV - DA9210_MIN_MV) / DA9210_STEP_MV) + 1,
74 .min_uV = (DA9210_MIN_MV * 1000),
75 .uV_step = (DA9210_STEP_MV * 1000),
76 .vsel_reg = DA9210_REG_VBUCK_A,
77 .vsel_mask = DA9210_VBUCK_MASK,
78 .enable_reg = DA9210_REG_BUCK_CONT,
79 .enable_mask = DA9210_BUCK_EN,
80 .owner = THIS_MODULE,
81};
82
83static int da9210_set_current_limit(struct regulator_dev *rdev, int min_uA,
84 int max_uA)
85{
86 struct da9210 *chip = rdev_get_drvdata(rdev);
87 unsigned int sel;
88 int i;
89
90 /* search for closest to maximum */
91 for (i = ARRAY_SIZE(da9210_buck_limits)-1; i >= 0; i--) {
92 if (min_uA <= da9210_buck_limits[i] &&
93 max_uA >= da9210_buck_limits[i]) {
94 sel = i;
95 sel = sel << DA9210_BUCK_ILIM_SHIFT;
96 return regmap_update_bits(chip->regmap,
97 DA9210_REG_BUCK_ILIM,
98 DA9210_BUCK_ILIM_MASK, sel);
99 }
100 }
101
102 return -EINVAL;
103}
104
105static int da9210_get_current_limit(struct regulator_dev *rdev)
106{
107 struct da9210 *chip = rdev_get_drvdata(rdev);
108 unsigned int data;
109 unsigned int sel;
110 int ret;
111
112 ret = regmap_read(chip->regmap, DA9210_REG_BUCK_ILIM, &data);
113 if (ret < 0)
114 return ret;
115
116 /* select one of 16 values: 0000 (1600mA) to 1111 (4600mA) */
117 sel = (data & DA9210_BUCK_ILIM_MASK) >> DA9210_BUCK_ILIM_SHIFT;
118
119 return da9210_buck_limits[sel];
120}
121
122/*
123 * I2C driver interface functions
124 */
125static int da9210_i2c_probe(struct i2c_client *i2c,
126 const struct i2c_device_id *id)
127{
128 struct da9210 *chip;
129 struct da9210_pdata *pdata = i2c->dev.platform_data;
130 struct regulator_dev *rdev = NULL;
131 struct regulator_config config = { };
132 int error;
133
134 chip = devm_kzalloc(&i2c->dev, sizeof(struct da9210), GFP_KERNEL);
135 if (NULL == chip) {
136 dev_err(&i2c->dev,
137 "Cannot kzalloc memory for regulator structure\n");
138 return -ENOMEM;
139 }
140
141 chip->regmap = devm_regmap_init_i2c(i2c, &da9210_regmap_config);
142 if (IS_ERR(chip->regmap)) {
143 error = PTR_ERR(chip->regmap);
144 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
145 error);
146 return error;
147 }
148
149 config.dev = &i2c->dev;
150 if (pdata)
151 config.init_data = &pdata->da9210_constraints;
152 config.driver_data = chip;
153 config.regmap = chip->regmap;
154
155 rdev = regulator_register(&da9210_reg, &config);
156 if (IS_ERR(rdev)) {
157 dev_err(&i2c->dev, "Failed to register DA9210 regulator\n");
158 return PTR_ERR(rdev);
159 }
160
161 chip->rdev = rdev;
162
163 i2c_set_clientdata(i2c, chip);
164
165 return 0;
166}
167
168static int da9210_i2c_remove(struct i2c_client *i2c)
169{
170 struct da9210 *chip = i2c_get_clientdata(i2c);
171 regulator_unregister(chip->rdev);
172 return 0;
173}
174
175static const struct i2c_device_id da9210_i2c_id[] = {
176 {"da9210", 0},
177 {},
178};
179
180MODULE_DEVICE_TABLE(i2c, da9210_i2c_id);
181
182static struct i2c_driver da9210_regulator_driver = {
183 .driver = {
184 .name = "da9210",
185 .owner = THIS_MODULE,
186 },
187 .probe = da9210_i2c_probe,
188 .remove = da9210_i2c_remove,
189 .id_table = da9210_i2c_id,
190};
191
192module_i2c_driver(da9210_regulator_driver);
193
194MODULE_AUTHOR("S Twiss <stwiss.opensource@diasemi.com>");
195MODULE_DESCRIPTION("Regulator device driver for Dialog DA9210");
196MODULE_LICENSE("GPL v2");
diff --git a/drivers/regulator/da9210-regulator.h b/drivers/regulator/da9210-regulator.h
new file mode 100644
index 000000000000..749c550808b6
--- /dev/null
+++ b/drivers/regulator/da9210-regulator.h
@@ -0,0 +1,288 @@
1
2/*
3 * da9210-regulator.h - Regulator definitions for DA9210
4 * Copyright (C) 2013 Dialog Semiconductor Ltd.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#ifndef __DA9210_REGISTERS_H__
23#define __DA9210_REGISTERS_H__
24
25struct da9210_pdata {
26 struct regulator_init_data da9210_constraints;
27};
28
29/* Page selection */
30#define DA9210_REG_PAGE_CON 0x00
31
32/* System Control and Event Registers */
33#define DA9210_REG_STATUS_A 0x50
34#define DA9210_REG_STATUS_B 0x51
35#define DA9210_REG_EVENT_A 0x52
36#define DA9210_REG_EVENT_B 0x53
37#define DA9210_REG_MASK_A 0x54
38#define DA9210_REG_MASK_B 0x55
39#define DA9210_REG_CONTROL_A 0x56
40
41/* GPIO Control Registers */
42#define DA9210_REG_GPIO_0_1 0x58
43#define DA9210_REG_GPIO_2_3 0x59
44#define DA9210_REG_GPIO_4_5 0x5A
45#define DA9210_REG_GPIO_6 0x5B
46
47/* Regulator Registers */
48#define DA9210_REG_BUCK_CONT 0x5D
49#define DA9210_REG_BUCK_ILIM 0xD0
50#define DA9210_REG_BUCK_CONF1 0xD1
51#define DA9210_REG_BUCK_CONF2 0xD2
52#define DA9210_REG_VBACK_AUTO 0xD4
53#define DA9210_REG_VBACK_BASE 0xD5
54#define DA9210_REG_VBACK_MAX_DVC_IF 0xD6
55#define DA9210_REG_VBACK_DVC 0xD7
56#define DA9210_REG_VBUCK_A 0xD8
57#define DA9210_REG_VBUCK_B 0xD9
58
59/* I2C Interface Settings */
60#define DA9210_REG_INTERFACE 0x105
61
62/* OTP */
63#define DA9210_REG_OPT_COUNT 0x140
64#define DA9210_REG_OPT_ADDR 0x141
65#define DA9210_REG_OPT_DATA 0x142
66
67/* Customer Trim and Configuration */
68#define DA9210_REG_CONFIG_A 0x143
69#define DA9210_REG_CONFIG_B 0x144
70#define DA9210_REG_CONFIG_C 0x145
71#define DA9210_REG_CONFIG_D 0x146
72#define DA9210_REG_CONFIG_E 0x147
73
74
75/*
76 * Registers bits
77 */
78/* DA9210_REG_PAGE_CON (addr=0x00) */
79#define DA9210_PEG_PAGE_SHIFT 0
80#define DA9210_REG_PAGE_MASK 0x0F
81/* On I2C registers 0x00 - 0xFF */
82#define DA9210_REG_PAGE0 0
83/* On I2C registers 0x100 - 0x1FF */
84#define DA9210_REG_PAGE2 2
85#define DA9210_PAGE_WRITE_MODE 0x00
86#define DA9210_REPEAT_WRITE_MODE 0x40
87#define DA9210_PAGE_REVERT 0x80
88
89/* DA9210_REG_STATUS_A (addr=0x50) */
90#define DA9210_GPI0 0x01
91#define DA9210_GPI1 0x02
92#define DA9210_GPI2 0x04
93#define DA9210_GPI3 0x08
94#define DA9210_GPI4 0x10
95#define DA9210_GPI5 0x20
96#define DA9210_GPI6 0x40
97
98/* DA9210_REG_EVENT_A (addr=0x52) */
99#define DA9210_E_GPI0 0x01
100#define DA9210_E_GPI1 0x02
101#define DA9210_E_GPI2 0x04
102#define DA9210_E_GPI3 0x08
103#define DA9210_E_GPI4 0x10
104#define DA9210_E_GPI5 0x20
105#define DA9210_E_GPI6 0x40
106
107/* DA9210_REG_EVENT_B (addr=0x53) */
108#define DA9210_E_OVCURR 0x01
109#define DA9210_E_NPWRGOOD 0x02
110#define DA9210_E_TEMP_WARN 0x04
111#define DA9210_E_TEMP_CRIT 0x08
112#define DA9210_E_VMAX 0x10
113
114/* DA9210_REG_MASK_A (addr=0x54) */
115#define DA9210_M_GPI0 0x01
116#define DA9210_M_GPI1 0x02
117#define DA9210_M_GPI2 0x04
118#define DA9210_M_GPI3 0x08
119#define DA9210_M_GPI4 0x10
120#define DA9210_M_GPI5 0x20
121#define DA9210_M_GPI6 0x40
122
123/* DA9210_REG_MASK_B (addr=0x55) */
124#define DA9210_M_OVCURR 0x01
125#define DA9210_M_NPWRGOOD 0x02
126#define DA9210_M_TEMP_WARN 0x04
127#define DA9210_M_TEMP_CRIT 0x08
128#define DA9210_M_VMAX 0x10
129
130/* DA9210_REG_CONTROL_A (addr=0x56) */
131#define DA9210_DEBOUNCING_SHIFT 0
132#define DA9210_DEBOUNCING_MASK 0x07
133#define DA9210_SLEW_RATE_SHIFT 3
134#define DA9210_SLEW_RATE_MASK 0x18
135#define DA9210_V_LOCK 0x20
136
137/* DA9210_REG_GPIO_0_1 (addr=0x58) */
138#define DA9210_GPIO0_PIN_SHIFT 0
139#define DA9210_GPIO0_PIN_MASK 0x03
140#define DA9210_GPIO0_PIN_GPI 0x00
141#define DA9210_GPIO0_PIN_GPO_OD 0x02
142#define DA9210_GPIO0_PIN_GPO 0x03
143#define DA9210_GPIO0_TYPE 0x04
144#define DA9210_GPIO0_TYPE_GPI 0x00
145#define DA9210_GPIO0_TYPE_GPO 0x04
146#define DA9210_GPIO0_MODE 0x08
147#define DA9210_GPIO1_PIN_SHIFT 4
148#define DA9210_GPIO1_PIN_MASK 0x30
149#define DA9210_GPIO1_PIN_GPI 0x00
150#define DA9210_GPIO1_PIN_VERROR 0x10
151#define DA9210_GPIO1_PIN_GPO_OD 0x20
152#define DA9210_GPIO1_PIN_GPO 0x30
153#define DA9210_GPIO1_TYPE_SHIFT 0x40
154#define DA9210_GPIO1_TYPE_GPI 0x00
155#define DA9210_GPIO1_TYPE_GPO 0x40
156#define DA9210_GPIO1_MODE 0x80
157
158/* DA9210_REG_GPIO_2_3 (addr=0x59) */
159#define DA9210_GPIO2_PIN_SHIFT 0
160#define DA9210_GPIO2_PIN_MASK 0x03
161#define DA9210_GPIO2_PIN_GPI 0x00
162#define DA9210_GPIO5_PIN_BUCK_CLK 0x10
163#define DA9210_GPIO2_PIN_GPO_OD 0x02
164#define DA9210_GPIO2_PIN_GPO 0x03
165#define DA9210_GPIO2_TYPE 0x04
166#define DA9210_GPIO2_TYPE_GPI 0x00
167#define DA9210_GPIO2_TYPE_GPO 0x04
168#define DA9210_GPIO2_MODE 0x08
169#define DA9210_GPIO3_PIN_SHIFT 4
170#define DA9210_GPIO3_PIN_MASK 0x30
171#define DA9210_GPIO3_PIN_GPI 0x00
172#define DA9210_GPIO3_PIN_IERROR 0x10
173#define DA9210_GPIO3_PIN_GPO_OD 0x20
174#define DA9210_GPIO3_PIN_GPO 0x30
175#define DA9210_GPIO3_TYPE_SHIFT 0x40
176#define DA9210_GPIO3_TYPE_GPI 0x00
177#define DA9210_GPIO3_TYPE_GPO 0x40
178#define DA9210_GPIO3_MODE 0x80
179
180/* DA9210_REG_GPIO_4_5 (addr=0x5A) */
181#define DA9210_GPIO4_PIN_SHIFT 0
182#define DA9210_GPIO4_PIN_MASK 0x03
183#define DA9210_GPIO4_PIN_GPI 0x00
184#define DA9210_GPIO4_PIN_GPO_OD 0x02
185#define DA9210_GPIO4_PIN_GPO 0x03
186#define DA9210_GPIO4_TYPE 0x04
187#define DA9210_GPIO4_TYPE_GPI 0x00
188#define DA9210_GPIO4_TYPE_GPO 0x04
189#define DA9210_GPIO4_MODE 0x08
190#define DA9210_GPIO5_PIN_SHIFT 4
191#define DA9210_GPIO5_PIN_MASK 0x30
192#define DA9210_GPIO5_PIN_GPI 0x00
193#define DA9210_GPIO5_PIN_INTERFACE 0x01
194#define DA9210_GPIO5_PIN_GPO_OD 0x20
195#define DA9210_GPIO5_PIN_GPO 0x30
196#define DA9210_GPIO5_TYPE_SHIFT 0x40
197#define DA9210_GPIO5_TYPE_GPI 0x00
198#define DA9210_GPIO5_TYPE_GPO 0x40
199#define DA9210_GPIO5_MODE 0x80
200
201/* DA9210_REG_GPIO_6 (addr=0x5B) */
202#define DA9210_GPIO6_PIN_SHIFT 0
203#define DA9210_GPIO6_PIN_MASK 0x03
204#define DA9210_GPIO6_PIN_GPI 0x00
205#define DA9210_GPIO6_PIN_INTERFACE 0x01
206#define DA9210_GPIO6_PIN_GPO_OD 0x02
207#define DA9210_GPIO6_PIN_GPO 0x03
208#define DA9210_GPIO6_TYPE 0x04
209#define DA9210_GPIO6_TYPE_GPI 0x00
210#define DA9210_GPIO6_TYPE_GPO 0x04
211#define DA9210_GPIO6_MODE 0x08
212
213/* DA9210_REG_BUCK_CONT (addr=0x5D) */
214#define DA9210_BUCK_EN 0x01
215#define DA9210_BUCK_GPI_SHIFT 1
216#define DA9210_BUCK_GPI_MASK 0x06
217#define DA9210_BUCK_GPI_OFF 0x00
218#define DA9210_BUCK_GPI_GPIO0 0x02
219#define DA9210_BUCK_GPI_GPIO3 0x04
220#define DA9210_BUCK_GPI_GPIO4 0x06
221#define DA9210_BUCK_PD_DIS 0x08
222#define DA9210_VBUCK_SEL 0x10
223#define DA9210_VBUCK_SEL_A 0x00
224#define DA9210_VBUCK_SEL_B 0x10
225#define DA9210_VBUCK_GPI_SHIFT 5
226#define DA9210_VBUCK_GPI_MASK 0x60
227#define DA9210_VBUCK_GPI_OFF 0x00
228#define DA9210_VBUCK_GPI_GPIO0 0x20
229#define DA9210_VBUCK_GPI_GPIO3 0x40
230#define DA9210_VBUCK_GPI_GPIO4 0x60
231#define DA9210_DVC_CTRL_EN 0x80
232
233/* DA9210_REG_BUCK_ILIM (addr=0xD0) */
234#define DA9210_BUCK_ILIM_SHIFT 0
235#define DA9210_BUCK_ILIM_MASK 0x0F
236#define DA9210_BUCK_IALARM 0x10
237
238/* DA9210_REG_BUCK_CONF1 (addr=0xD1) */
239#define DA9210_BUCK_MODE_SHIFT 0
240#define DA9210_BUCK_MODE_MASK 0x03
241#define DA9210_BUCK_MODE_MANUAL 0x00
242#define DA9210_BUCK_MODE_SLEEP 0x01
243#define DA9210_BUCK_MODE_SYNC 0x02
244#define DA9210_BUCK_MODE_AUTO 0x03
245#define DA9210_STARTUP_CTRL_SHIFT 2
246#define DA9210_STARTUP_CTRL_MASK 0x1C
247#define DA9210_PWR_DOWN_CTRL_SHIFT 5
248#define DA9210_PWR_DOWN_CTRL_MASK 0xE0
249
250/* DA9210_REG_BUCK_CONF2 (addr=0xD2) */
251#define DA9210_PHASE_SEL_SHIFT 0
252#define DA9210_PHASE_SEL_MASK 0x03
253#define DA9210_FREQ_SEL 0x40
254
255/* DA9210_REG_BUCK_AUTO (addr=0xD4) */
256#define DA9210_VBUCK_AUTO_SHIFT 0
257#define DA9210_VBUCK_AUTO_MASK 0x7F
258
259/* DA9210_REG_BUCK_BASE (addr=0xD5) */
260#define DA9210_VBUCK_BASE_SHIFT 0
261#define DA9210_VBUCK_BASE_MASK 0x7F
262
263/* DA9210_REG_VBUCK_MAX_DVC_IF (addr=0xD6) */
264#define DA9210_VBUCK_MAX_SHIFT 0
265#define DA9210_VBUCK_MAX_MASK 0x7F
266#define DA9210_DVC_STEP_SIZE 0x80
267#define DA9210_DVC_STEP_SIZE_10MV 0x00
268#define DA9210_DVC_STEP_SIZE_20MV 0x80
269
270/* DA9210_REG_VBUCK_DVC (addr=0xD7) */
271#define DA9210_VBUCK_DVC_SHIFT 0
272#define DA9210_VBUCK_DVC_MASK 0x7F
273
274/* DA9210_REG_VBUCK_A/B (addr=0xD8/0xD9) */
275#define DA9210_VBUCK_SHIFT 0
276#define DA9210_VBUCK_MASK 0x7F
277#define DA9210_VBUCK_BIAS 0
278#define DA9210_BUCK_SL 0x80
279
280/* DA9210_REG_INTERFACE (addr=0x105) */
281#define DA9210_IF_BASE_ADDR_SHIFT 4
282#define DA9210_IF_BASE_ADDR_MASK 0xF0
283
284/* DA9210_REG_CONFIG_E (addr=0x147) */
285#define DA9210_STAND_ALONE 0x01
286
287#endif /* __DA9210_REGISTERS_H__ */
288