aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Ban <james.ban.opensource@diasemi.com>2014-07-14 00:48:45 -0400
committerMark Brown <broonie@linaro.org>2014-07-14 14:15:56 -0400
commit1028a37daa148cc6cf85aa2aecb4390ddf1e1e56 (patch)
treedad06ff63e36beb40ee54e7a46f7671a823913cc
parent7171511eaec5bf23fb06078f59784a3a0626b38f (diff)
regulator: da9211: new regulator driver
This is the driver for the Dialog DA9211 Multi-phase 12A DC-DC Buck Converter regulator. It communicates via an I2C bus to the device. Signed-off-by: James Ban <james.ban.opensource@diasemi.com> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--drivers/regulator/Kconfig10
-rw-r--r--drivers/regulator/Makefile1
-rw-r--r--drivers/regulator/da9211-regulator.c388
-rw-r--r--drivers/regulator/da9211-regulator.h271
-rw-r--r--include/linux/regulator/da9211.h32
5 files changed, 702 insertions, 0 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 789eb46090e3..f5040fc49a3a 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -198,6 +198,16 @@ config REGULATOR_DA9210
198 converter 12A DC-DC Buck controlled through an I2C 198 converter 12A DC-DC Buck controlled through an I2C
199 interface. 199 interface.
200 200
201config REGULATOR_DA9211
202 tristate "Dialog Semiconductor DA9211/DA9212 regulator"
203 depends on I2C
204 select REGMAP_I2C
205 help
206 Say y here to support for the Dialog Semiconductor DA9211/DA9212.
207 The DA9211/DA9212 is a multi-phase synchronous step down
208 converter 12A DC-DC Buck controlled through an I2C
209 interface.
210
201config REGULATOR_DBX500_PRCMU 211config REGULATOR_DBX500_PRCMU
202 bool 212 bool
203 213
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index d461110f4463..aa4a6aa7b558 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o
27obj-$(CONFIG_REGULATOR_DA9055) += da9055-regulator.o 27obj-$(CONFIG_REGULATOR_DA9055) += da9055-regulator.o
28obj-$(CONFIG_REGULATOR_DA9063) += da9063-regulator.o 28obj-$(CONFIG_REGULATOR_DA9063) += da9063-regulator.o
29obj-$(CONFIG_REGULATOR_DA9210) += da9210-regulator.o 29obj-$(CONFIG_REGULATOR_DA9210) += da9210-regulator.o
30obj-$(CONFIG_REGULATOR_DA9211) += da9211-regulator.o
30obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o 31obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o
31obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o 32obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o
32obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o 33obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o
diff --git a/drivers/regulator/da9211-regulator.c b/drivers/regulator/da9211-regulator.c
new file mode 100644
index 000000000000..bd1850658a3f
--- /dev/null
+++ b/drivers/regulator/da9211-regulator.c
@@ -0,0 +1,388 @@
1/*
2 * da9211-regulator.c - Regulator device driver for DA9211
3 * Copyright (C) 2014 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
16#include <linux/err.h>
17#include <linux/gpio.h>
18#include <linux/i2c.h>
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/slab.h>
22#include <linux/regulator/driver.h>
23#include <linux/regulator/machine.h>
24#include <linux/regmap.h>
25#include <linux/irq.h>
26#include <linux/interrupt.h>
27#include <linux/regulator/da9211.h>
28#include "da9211-regulator.h"
29
30#define DA9211_BUCK_MODE_SLEEP 1
31#define DA9211_BUCK_MODE_SYNC 2
32#define DA9211_BUCK_MODE_AUTO 3
33
34/* DA9211 REGULATOR IDs */
35#define DA9211_ID_BUCKA 0
36#define DA9211_ID_BUCKB 1
37
38struct da9211 {
39 struct device *dev;
40 struct regmap *regmap;
41 struct da9211_pdata *pdata;
42 struct regulator_dev *rdev[DA9211_MAX_REGULATORS];
43 int num_regulator;
44 int chip_irq;
45};
46
47static const struct regmap_range_cfg da9211_regmap_range[] = {
48 {
49 .selector_reg = DA9211_REG_PAGE_CON,
50 .selector_mask = DA9211_REG_PAGE_MASK,
51 .selector_shift = DA9211_REG_PAGE_SHIFT,
52 .window_start = 0,
53 .window_len = 256,
54 .range_min = 0,
55 .range_max = 2*256,
56 },
57};
58
59static const struct regmap_config da9211_regmap_config = {
60 .reg_bits = 8,
61 .val_bits = 8,
62 .max_register = 2 * 256,
63 .ranges = da9211_regmap_range,
64 .num_ranges = ARRAY_SIZE(da9211_regmap_range),
65};
66
67/* Default limits measured in millivolts and milliamps */
68#define DA9211_MIN_MV 300
69#define DA9211_MAX_MV 1570
70#define DA9211_STEP_MV 10
71
72/* Current limits for buck (uA) indices corresponds with register values */
73static const int da9211_current_limits[] = {
74 2000000, 2200000, 2400000, 2600000, 2800000, 3000000, 3200000, 3400000,
75 3600000, 3800000, 4000000, 4200000, 4400000, 4600000, 4800000, 5000000
76};
77
78static unsigned int da9211_buck_get_mode(struct regulator_dev *rdev)
79{
80 int id = rdev_get_id(rdev);
81 struct da9211 *chip = rdev_get_drvdata(rdev);
82 unsigned int data;
83 int ret, mode = 0;
84
85 ret = regmap_read(chip->regmap, DA9211_REG_BUCKA_CONF+id, &data);
86 if (ret < 0)
87 return ret;
88
89 switch (data & 0x03) {
90 case DA9211_BUCK_MODE_SYNC:
91 mode = REGULATOR_MODE_FAST;
92 break;
93 case DA9211_BUCK_MODE_AUTO:
94 mode = REGULATOR_MODE_NORMAL;
95 break;
96 case DA9211_BUCK_MODE_SLEEP:
97 mode = REGULATOR_MODE_STANDBY;
98 break;
99 }
100
101 return mode;
102}
103
104static int da9211_buck_set_mode(struct regulator_dev *rdev,
105 unsigned int mode)
106{
107 int id = rdev_get_id(rdev);
108 struct da9211 *chip = rdev_get_drvdata(rdev);
109 int val = 0;
110
111 switch (mode) {
112 case REGULATOR_MODE_FAST:
113 val = DA9211_BUCK_MODE_SYNC;
114 break;
115 case REGULATOR_MODE_NORMAL:
116 val = DA9211_BUCK_MODE_AUTO;
117 break;
118 case REGULATOR_MODE_STANDBY:
119 val = DA9211_BUCK_MODE_SLEEP;
120 break;
121 }
122
123 return regmap_update_bits(chip->regmap, DA9211_REG_BUCKA_CONF+id,
124 0x03, val);
125}
126
127static int da9211_set_current_limit(struct regulator_dev *rdev, int min,
128 int max)
129{
130 int id = rdev_get_id(rdev);
131 struct da9211 *chip = rdev_get_drvdata(rdev);
132 int i;
133
134 /* search for closest to maximum */
135 for (i = ARRAY_SIZE(da9211_current_limits)-1; i >= 0; i--) {
136 if (min <= da9211_current_limits[i] &&
137 max >= da9211_current_limits[i]) {
138 return regmap_update_bits(chip->regmap,
139 DA9211_REG_BUCK_ILIM,
140 (0x0F << id*4), (i << id*4));
141 }
142 }
143
144 return -EINVAL;
145}
146
147static int da9211_get_current_limit(struct regulator_dev *rdev)
148{
149 int id = rdev_get_id(rdev);
150 struct da9211 *chip = rdev_get_drvdata(rdev);
151 unsigned int data;
152 int ret;
153
154 ret = regmap_read(chip->regmap, DA9211_REG_BUCK_ILIM, &data);
155 if (ret < 0)
156 return ret;
157
158 /* select one of 16 values: 0000 (2000mA) to 1111 (5000mA) */
159 data = (data >> id*4) & 0x0F;
160 return da9211_current_limits[data];
161}
162
163static struct regulator_ops da9211_buck_ops = {
164 .get_mode = da9211_buck_get_mode,
165 .set_mode = da9211_buck_set_mode,
166 .enable = regulator_enable_regmap,
167 .disable = regulator_disable_regmap,
168 .is_enabled = regulator_is_enabled_regmap,
169 .set_voltage_sel = regulator_set_voltage_sel_regmap,
170 .get_voltage_sel = regulator_get_voltage_sel_regmap,
171 .list_voltage = regulator_list_voltage_linear,
172 .set_current_limit = da9211_set_current_limit,
173 .get_current_limit = da9211_get_current_limit,
174};
175
176#define DA9211_BUCK(_id) \
177{\
178 .name = #_id,\
179 .ops = &da9211_buck_ops,\
180 .type = REGULATOR_VOLTAGE,\
181 .id = DA9211_ID_##_id,\
182 .n_voltages = (DA9211_MAX_MV - DA9211_MIN_MV) / DA9211_STEP_MV + 1,\
183 .min_uV = (DA9211_MIN_MV * 1000),\
184 .uV_step = (DA9211_STEP_MV * 1000),\
185 .enable_reg = DA9211_REG_BUCKA_CONT + DA9211_ID_##_id,\
186 .enable_mask = DA9211_BUCKA_EN,\
187 .vsel_reg = DA9211_REG_VBUCKA_A + DA9211_ID_##_id * 2,\
188 .vsel_mask = DA9211_VBUCK_MASK,\
189 .owner = THIS_MODULE,\
190}
191
192static struct regulator_desc da9211_regulators[] = {
193 DA9211_BUCK(BUCKA),
194 DA9211_BUCK(BUCKB),
195};
196
197static irqreturn_t da9211_irq_handler(int irq, void *data)
198{
199 struct da9211 *chip = data;
200 int reg_val, err, ret = IRQ_NONE;
201
202 err = regmap_read(chip->regmap, DA9211_REG_EVENT_B, &reg_val);
203 if (err < 0)
204 goto error_i2c;
205
206 if (reg_val & DA9211_E_OV_CURR_A) {
207 regulator_notifier_call_chain(chip->rdev[0],
208 REGULATOR_EVENT_OVER_CURRENT,
209 rdev_get_drvdata(chip->rdev[0]));
210
211 err = regmap_write(chip->regmap, DA9211_REG_EVENT_B,
212 DA9211_E_OV_CURR_A);
213 if (err < 0)
214 goto error_i2c;
215
216 ret = IRQ_HANDLED;
217 }
218
219 if (reg_val & DA9211_E_OV_CURR_B) {
220 regulator_notifier_call_chain(chip->rdev[1],
221 REGULATOR_EVENT_OVER_CURRENT,
222 rdev_get_drvdata(chip->rdev[1]));
223
224 err = regmap_write(chip->regmap, DA9211_REG_EVENT_B,
225 DA9211_E_OV_CURR_B);
226 if (err < 0)
227 goto error_i2c;
228
229 ret = IRQ_HANDLED;
230 }
231
232 return ret;
233
234error_i2c:
235 dev_err(chip->dev, "I2C error : %d\n", err);
236 return IRQ_NONE;
237}
238
239static int da9211_regulator_init(struct da9211 *chip)
240{
241 struct regulator_config config = { };
242 int i, ret;
243 unsigned int data;
244
245 ret = regmap_read(chip->regmap, DA9211_REG_CONFIG_E, &data);
246 if (ret < 0) {
247 dev_err(chip->dev, "Failed to read CONTROL_E reg: %d\n", ret);
248 goto err;
249 }
250
251 data &= DA9211_SLAVE_SEL;
252 /* If configuration for 1/2 bucks is different between platform data
253 * and the register, driver should exit.
254 */
255 if ((chip->pdata->num_buck == 2 && data == 0x40)
256 || (chip->pdata->num_buck == 1 && data == 0x00)) {
257 if (data == 0)
258 chip->num_regulator = 1;
259 else
260 chip->num_regulator = 2;
261 } else {
262 ret = -EINVAL;
263 dev_err(chip->dev, "Configuration is mismatched\n");
264 goto err;
265 }
266
267 for (i = 0; i < chip->num_regulator; i++) {
268 if (chip->pdata)
269 config.init_data =
270 &(chip->pdata->init_data[i]);
271
272 config.dev = chip->dev;
273 config.driver_data = chip;
274 config.regmap = chip->regmap;
275
276 chip->rdev[i] = devm_regulator_register(chip->dev,
277 &da9211_regulators[i], &config);
278 if (IS_ERR(chip->rdev[i])) {
279 dev_err(chip->dev,
280 "Failed to register DA9211 regulator\n");
281 ret = PTR_ERR(chip->rdev[i]);
282 goto err_regulator;
283 }
284
285 if (chip->chip_irq != 0) {
286 ret = regmap_update_bits(chip->regmap,
287 DA9211_REG_MASK_B, DA9211_M_OV_CURR_A << i, 1);
288 if (ret < 0) {
289 dev_err(chip->dev,
290 "Failed to update mask reg: %d\n", ret);
291 goto err_regulator;
292 }
293 }
294 }
295
296 return 0;
297
298err_regulator:
299 while (--i >= 0)
300 devm_regulator_unregister(chip->dev, chip->rdev[i]);
301err:
302 return ret;
303}
304/*
305 * I2C driver interface functions
306 */
307static int da9211_i2c_probe(struct i2c_client *i2c,
308 const struct i2c_device_id *id)
309{
310 struct da9211 *chip;
311 int error, ret;
312
313 chip = devm_kzalloc(&i2c->dev, sizeof(struct da9211), GFP_KERNEL);
314
315 chip->dev = &i2c->dev;
316 chip->regmap = devm_regmap_init_i2c(i2c, &da9211_regmap_config);
317 if (IS_ERR(chip->regmap)) {
318 error = PTR_ERR(chip->regmap);
319 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
320 error);
321 return error;
322 }
323
324 i2c_set_clientdata(i2c, chip);
325
326 chip->pdata = i2c->dev.platform_data;
327 if (!chip->pdata) {
328 dev_err(&i2c->dev, "No platform init data supplied\n");
329 return -ENODEV;
330 }
331
332 chip->chip_irq = i2c->irq;
333
334 if (chip->chip_irq != 0) {
335 ret = devm_request_threaded_irq(chip->dev, chip->chip_irq, NULL,
336 da9211_irq_handler,
337 IRQF_TRIGGER_LOW|IRQF_ONESHOT,
338 "da9211", chip);
339 if (ret != 0) {
340 dev_err(chip->dev, "Failed to request IRQ: %d\n",
341 chip->chip_irq);
342 return ret;
343 }
344 } else {
345 dev_warn(chip->dev, "No IRQ configured\n");
346 }
347
348 ret = da9211_regulator_init(chip);
349
350 if (ret < 0)
351 dev_err(&i2c->dev, "Failed to initialize regulator: %d\n", ret);
352
353 return ret;
354}
355
356static int da9211_i2c_remove(struct i2c_client *i2c)
357{
358 struct da9211 *chip = i2c_get_clientdata(i2c);
359 int i;
360
361 for (i = 0; i < chip->num_regulator; i++)
362 devm_regulator_unregister(chip->dev, chip->rdev[i]);
363
364 return 0;
365}
366
367static const struct i2c_device_id da9211_i2c_id[] = {
368 {"da9211", 0},
369 {},
370};
371
372MODULE_DEVICE_TABLE(i2c, da9211_i2c_id);
373
374static struct i2c_driver da9211_regulator_driver = {
375 .driver = {
376 .name = "da9211",
377 .owner = THIS_MODULE,
378 },
379 .probe = da9211_i2c_probe,
380 .remove = da9211_i2c_remove,
381 .id_table = da9211_i2c_id,
382};
383
384module_i2c_driver(da9211_regulator_driver);
385
386MODULE_AUTHOR("James Ban <James.Ban.opensource@diasemi.com>");
387MODULE_DESCRIPTION("Regulator device driver for Dialog DA9211");
388MODULE_LICENSE("GPL v2");
diff --git a/drivers/regulator/da9211-regulator.h b/drivers/regulator/da9211-regulator.h
new file mode 100644
index 000000000000..88b1769e8058
--- /dev/null
+++ b/drivers/regulator/da9211-regulator.h
@@ -0,0 +1,271 @@
1/*
2 * da9211-regulator.h - Regulator definitions for DA9211
3 * Copyright (C) 2014 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
16#ifndef __DA9211_REGISTERS_H__
17#define __DA9211_REGISTERS_H__
18
19/* Page selection */
20#define DA9211_REG_PAGE_CON 0x00
21
22/* System Control and Event Registers */
23#define DA9211_REG_STATUS_A 0x50
24#define DA9211_REG_STATUS_B 0x51
25#define DA9211_REG_EVENT_A 0x52
26#define DA9211_REG_EVENT_B 0x53
27#define DA9211_REG_MASK_A 0x54
28#define DA9211_REG_MASK_B 0x55
29#define DA9211_REG_CONTROL_A 0x56
30
31/* GPIO Control Registers */
32#define DA9211_REG_GPIO_0_1 0x58
33#define DA9211_REG_GPIO_2_3 0x59
34#define DA9211_REG_GPIO_4 0x5A
35
36/* Regulator Registers */
37#define DA9211_REG_BUCKA_CONT 0x5D
38#define DA9211_REG_BUCKB_CONT 0x5E
39#define DA9211_REG_BUCK_ILIM 0xD0
40#define DA9211_REG_BUCKA_CONF 0xD1
41#define DA9211_REG_BUCKB_CONF 0xD2
42#define DA9211_REG_BUCK_CONF 0xD3
43#define DA9211_REG_VBACKA_MAX 0xD5
44#define DA9211_REG_VBACKB_MAX 0xD6
45#define DA9211_REG_VBUCKA_A 0xD7
46#define DA9211_REG_VBUCKA_B 0xD8
47#define DA9211_REG_VBUCKB_A 0xD9
48#define DA9211_REG_VBUCKB_B 0xDA
49
50/* I2C Interface Settings */
51#define DA9211_REG_INTERFACE 0x105
52
53/* BUCK Phase Selection*/
54#define DA9211_REG_CONFIG_E 0x147
55
56/*
57 * Registers bits
58 */
59/* DA9211_REG_PAGE_CON (addr=0x00) */
60#define DA9211_REG_PAGE_SHIFT 1
61#define DA9211_REG_PAGE_MASK 0x02
62/* On I2C registers 0x00 - 0xFF */
63#define DA9211_REG_PAGE0 0
64/* On I2C registers 0x100 - 0x1FF */
65#define DA9211_REG_PAGE2 2
66#define DA9211_PAGE_WRITE_MODE 0x00
67#define DA9211_REPEAT_WRITE_MODE 0x40
68#define DA9211_PAGE_REVERT 0x80
69
70/* DA9211_REG_STATUS_A (addr=0x50) */
71#define DA9211_GPI0 0x01
72#define DA9211_GPI1 0x02
73#define DA9211_GPI2 0x04
74#define DA9211_GPI3 0x08
75#define DA9211_GPI4 0x10
76
77/* DA9211_REG_EVENT_A (addr=0x52) */
78#define DA9211_E_GPI0 0x01
79#define DA9211_E_GPI1 0x02
80#define DA9211_E_GPI2 0x04
81#define DA9211_E_GPI3 0x08
82#define DA9211_E_GPI4 0x10
83#define DA9211_E_UVLO_IO 0x40
84
85/* DA9211_REG_EVENT_B (addr=0x53) */
86#define DA9211_E_PWRGOOD_A 0x01
87#define DA9211_E_PWRGOOD_B 0x02
88#define DA9211_E_TEMP_WARN 0x04
89#define DA9211_E_TEMP_CRIT 0x08
90#define DA9211_E_OV_CURR_A 0x10
91#define DA9211_E_OV_CURR_B 0x20
92
93/* DA9211_REG_MASK_A (addr=0x54) */
94#define DA9211_M_GPI0 0x01
95#define DA9211_M_GPI1 0x02
96#define DA9211_M_GPI2 0x04
97#define DA9211_M_GPI3 0x08
98#define DA9211_M_GPI4 0x10
99#define DA9211_M_UVLO_IO 0x40
100
101/* DA9211_REG_MASK_B (addr=0x55) */
102#define DA9211_M_PWRGOOD_A 0x01
103#define DA9211_M_PWRGOOD_B 0x02
104#define DA9211_M_TEMP_WARN 0x04
105#define DA9211_M_TEMP_CRIT 0x08
106#define DA9211_M_OV_CURR_A 0x10
107#define DA9211_M_OV_CURR_B 0x20
108
109/* DA9211_REG_CONTROL_A (addr=0x56) */
110#define DA9211_DEBOUNCING_SHIFT 0
111#define DA9211_DEBOUNCING_MASK 0x07
112#define DA9211_SLEW_RATE_SHIFT 3
113#define DA9211_SLEW_RATE_A_MASK 0x18
114#define DA9211_SLEW_RATE_B_SHIFT 5
115#define DA9211_SLEW_RATE_B_MASK 0x60
116#define DA9211_V_LOCK 0x80
117
118/* DA9211_REG_GPIO_0_1 (addr=0x58) */
119#define DA9211_GPIO0_PIN_SHIFT 0
120#define DA9211_GPIO0_PIN_MASK 0x03
121#define DA9211_GPIO0_PIN_GPI 0x00
122#define DA9211_GPIO0_PIN_GPO_OD 0x02
123#define DA9211_GPIO0_PIN_GPO 0x03
124#define DA9211_GPIO0_TYPE 0x04
125#define DA9211_GPIO0_TYPE_GPI 0x00
126#define DA9211_GPIO0_TYPE_GPO 0x04
127#define DA9211_GPIO0_MODE 0x08
128#define DA9211_GPIO1_PIN_SHIFT 4
129#define DA9211_GPIO1_PIN_MASK 0x30
130#define DA9211_GPIO1_PIN_GPI 0x00
131#define DA9211_GPIO1_PIN_VERROR 0x10
132#define DA9211_GPIO1_PIN_GPO_OD 0x20
133#define DA9211_GPIO1_PIN_GPO 0x30
134#define DA9211_GPIO1_TYPE_SHIFT 0x40
135#define DA9211_GPIO1_TYPE_GPI 0x00
136#define DA9211_GPIO1_TYPE_GPO 0x40
137#define DA9211_GPIO1_MODE 0x80
138
139/* DA9211_REG_GPIO_2_3 (addr=0x59) */
140#define DA9211_GPIO2_PIN_SHIFT 0
141#define DA9211_GPIO2_PIN_MASK 0x03
142#define DA9211_GPIO2_PIN_GPI 0x00
143#define DA9211_GPIO5_PIN_BUCK_CLK 0x10
144#define DA9211_GPIO2_PIN_GPO_OD 0x02
145#define DA9211_GPIO2_PIN_GPO 0x03
146#define DA9211_GPIO2_TYPE 0x04
147#define DA9211_GPIO2_TYPE_GPI 0x00
148#define DA9211_GPIO2_TYPE_GPO 0x04
149#define DA9211_GPIO2_MODE 0x08
150#define DA9211_GPIO3_PIN_SHIFT 4
151#define DA9211_GPIO3_PIN_MASK 0x30
152#define DA9211_GPIO3_PIN_GPI 0x00
153#define DA9211_GPIO3_PIN_IERROR 0x10
154#define DA9211_GPIO3_PIN_GPO_OD 0x20
155#define DA9211_GPIO3_PIN_GPO 0x30
156#define DA9211_GPIO3_TYPE_SHIFT 0x40
157#define DA9211_GPIO3_TYPE_GPI 0x00
158#define DA9211_GPIO3_TYPE_GPO 0x40
159#define DA9211_GPIO3_MODE 0x80
160
161/* DA9211_REG_GPIO_4 (addr=0x5A) */
162#define DA9211_GPIO4_PIN_SHIFT 0
163#define DA9211_GPIO4_PIN_MASK 0x03
164#define DA9211_GPIO4_PIN_GPI 0x00
165#define DA9211_GPIO4_PIN_GPO_OD 0x02
166#define DA9211_GPIO4_PIN_GPO 0x03
167#define DA9211_GPIO4_TYPE 0x04
168#define DA9211_GPIO4_TYPE_GPI 0x00
169#define DA9211_GPIO4_TYPE_GPO 0x04
170#define DA9211_GPIO4_MODE 0x08
171
172/* DA9211_REG_BUCKA_CONT (addr=0x5D) */
173#define DA9211_BUCKA_EN 0x01
174#define DA9211_BUCKA_GPI_SHIFT 1
175#define DA9211_BUCKA_GPI_MASK 0x06
176#define DA9211_BUCKA_GPI_OFF 0x00
177#define DA9211_BUCKA_GPI_GPIO0 0x02
178#define DA9211_BUCKA_GPI_GPIO1 0x04
179#define DA9211_BUCKA_GPI_GPIO3 0x06
180#define DA9211_BUCKA_PD_DIS 0x08
181#define DA9211_VBUCKA_SEL 0x10
182#define DA9211_VBUCKA_SEL_A 0x00
183#define DA9211_VBUCKA_SEL_B 0x10
184#define DA9211_VBUCKA_GPI_SHIFT 5
185#define DA9211_VBUCKA_GPI_MASK 0x60
186#define DA9211_VBUCKA_GPI_OFF 0x00
187#define DA9211_VBUCKA_GPI_GPIO1 0x20
188#define DA9211_VBUCKA_GPI_GPIO2 0x40
189#define DA9211_VBUCKA_GPI_GPIO4 0x60
190
191/* DA9211_REG_BUCKB_CONT (addr=0x5E) */
192#define DA9211_BUCKB_EN 0x01
193#define DA9211_BUCKB_GPI_SHIFT 1
194#define DA9211_BUCKB_GPI_MASK 0x06
195#define DA9211_BUCKB_GPI_OFF 0x00
196#define DA9211_BUCKB_GPI_GPIO0 0x02
197#define DA9211_BUCKB_GPI_GPIO1 0x04
198#define DA9211_BUCKB_GPI_GPIO3 0x06
199#define DA9211_BUCKB_PD_DIS 0x08
200#define DA9211_VBUCKB_SEL 0x10
201#define DA9211_VBUCKB_SEL_A 0x00
202#define DA9211_VBUCKB_SEL_B 0x10
203#define DA9211_VBUCKB_GPI_SHIFT 5
204#define DA9211_VBUCKB_GPI_MASK 0x60
205#define DA9211_VBUCKB_GPI_OFF 0x00
206#define DA9211_VBUCKB_GPI_GPIO1 0x20
207#define DA9211_VBUCKB_GPI_GPIO2 0x40
208#define DA9211_VBUCKB_GPI_GPIO4 0x60
209
210/* DA9211_REG_BUCK_ILIM (addr=0xD0) */
211#define DA9211_BUCKA_ILIM_SHIFT 0
212#define DA9211_BUCKA_ILIM_MASK 0x0F
213#define DA9211_BUCKB_ILIM_SHIFT 4
214#define DA9211_BUCKB_ILIM_MASK 0xF0
215
216/* DA9211_REG_BUCKA_CONF (addr=0xD1) */
217#define DA9211_BUCKA_MODE_SHIFT 0
218#define DA9211_BUCKA_MODE_MASK 0x03
219#define DA9211_BUCKA_MODE_MANUAL 0x00
220#define DA9211_BUCKA_MODE_SLEEP 0x01
221#define DA9211_BUCKA_MODE_SYNC 0x02
222#define DA9211_BUCKA_MODE_AUTO 0x03
223#define DA9211_BUCKA_UP_CTRL_SHIFT 2
224#define DA9211_BUCKA_UP_CTRL_MASK 0x1C
225#define DA9211_BUCKA_DOWN_CTRL_SHIFT 5
226#define DA9211_BUCKA_DOWN_CTRL_MASK 0xE0
227
228/* DA9211_REG_BUCKB_CONF (addr=0xD2) */
229#define DA9211_BUCKB_MODE_SHIFT 0
230#define DA9211_BUCKB_MODE_MASK 0x03
231#define DA9211_BUCKB_MODE_MANUAL 0x00
232#define DA9211_BUCKB_MODE_SLEEP 0x01
233#define DA9211_BUCKB_MODE_SYNC 0x02
234#define DA9211_BUCKB_MODE_AUTO 0x03
235#define DA9211_BUCKB_UP_CTRL_SHIFT 2
236#define DA9211_BUCKB_UP_CTRL_MASK 0x1C
237#define DA9211_BUCKB_DOWN_CTRL_SHIFT 5
238#define DA9211_BUCKB_DOWN_CTRL_MASK 0xE0
239
240/* DA9211_REG_BUCK_CONF (addr=0xD3) */
241#define DA9211_PHASE_SEL_A_SHIFT 0
242#define DA9211_PHASE_SEL_A_MASK 0x03
243#define DA9211_PHASE_SEL_B_SHIFT 2
244#define DA9211_PHASE_SEL_B_MASK 0x04
245#define DA9211_PH_SH_EN_A_SHIFT 3
246#define DA9211_PH_SH_EN_A_MASK 0x08
247#define DA9211_PH_SH_EN_B_SHIFT 4
248#define DA9211_PH_SH_EN_B_MASK 0x10
249
250/* DA9211_REG_VBUCKA_MAX (addr=0xD5) */
251#define DA9211_VBUCKA_BASE_SHIFT 0
252#define DA9211_VBUCKA_BASE_MASK 0x7F
253
254/* DA9211_REG_VBUCKB_MAX (addr=0xD6) */
255#define DA9211_VBUCKB_BASE_SHIFT 0
256#define DA9211_VBUCKB_BASE_MASK 0x7F
257
258/* DA9211_REG_VBUCKA/B_A/B (addr=0xD7/0xD8/0xD9/0xDA) */
259#define DA9211_VBUCK_SHIFT 0
260#define DA9211_VBUCK_MASK 0x7F
261#define DA9211_VBUCK_BIAS 0
262#define DA9211_BUCK_SL 0x80
263
264/* DA9211_REG_INTERFACE (addr=0x105) */
265#define DA9211_IF_BASE_ADDR_SHIFT 4
266#define DA9211_IF_BASE_ADDR_MASK 0xF0
267
268/* DA9211_REG_CONFIG_E (addr=0x147) */
269#define DA9211_SLAVE_SEL 0x40
270
271#endif /* __DA9211_REGISTERS_H__ */
diff --git a/include/linux/regulator/da9211.h b/include/linux/regulator/da9211.h
new file mode 100644
index 000000000000..0981ce0e72cc
--- /dev/null
+++ b/include/linux/regulator/da9211.h
@@ -0,0 +1,32 @@
1/*
2 * da9211.h - Regulator device driver for DA9211
3 * Copyright (C) 2014 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
16#ifndef __LINUX_REGULATOR_DA9211_H
17#define __LINUX_REGULATOR_DA9211_H
18
19#include <linux/regulator/machine.h>
20
21#define DA9211_MAX_REGULATORS 2
22
23struct da9211_pdata {
24 /*
25 * Number of buck
26 * 1 : 4 phase 1 buck
27 * 2 : 2 phase 2 buck
28 */
29 int num_buck;
30 struct regulator_init_data *init_data;
31};
32#endif