aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-03-18 00:05:32 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-03-18 00:05:32 -0400
commit1a46712aa99594eabe1e9aeedf115dfff0db1dfd (patch)
tree61240865e6b55e2f2b2c174b333c2a097bd4f31e /drivers/regulator
parent82b666eee71618b7ca812ee529af116582617dec (diff)
parentccbd805aa934dd1b863ef115a9c55f119b2388cf (diff)
Merge tag 'gpio-v4.6-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO updates from Linus Walleij: "This is the bulk of GPIO changes for kernel v4.6. There is quite a lot of interesting stuff going on. The patches to other subsystems and arch-wide are ACKed as far as possible, though I consider things like per-arch <asm/gpio.h> as essentially a part of the GPIO subsystem so it should not be needed. Core changes: - The gpio_chip is now a *real device*. Until now the gpio chips were just piggybacking the parent device or (gasp) floating in space outside of the device model. We now finally make GPIO chips devices. The gpio_chip will create a gpio_device which contains a struct device, and this gpio_device struct is kept private. Anything that needs to be kept private from the rest of the kernel will gradually be moved over to the gpio_device. - As a result of making the gpio_device a real device, we have added resource management, so devm_gpiochip_add_data() will cut down on overhead and reduce code lines. A huge slew of patches convert almost all drivers in the subsystem to use this. - Building on making the GPIO a real device, we add the first step of a new userspace ABI: the GPIO character device. We take small steps here, so we first add a pure *information* ABI and the tool "lsgpio" that will list all GPIO devices on the system and all lines on these devices. We can now discover GPIOs properly from userspace. We still have not come up with a way to actually *use* GPIOs from userspace. - To encourage people to use the character device for the future, we have it always-enabled when using GPIO. The old sysfs ABI is still opt-in (and can be used in parallel), but is marked as deprecated. We will keep it around for the foreseeable future, but it will not be extended to cover ever more use cases. Cleanup: - Bjorn Helgaas removed a whole slew of per-architecture <asm/gpio.h> includes. This dates back to when GPIO was an opt-in feature and no shared library even existed: just a header file with proper prototypes was provided and all semantics were up to the arch to implement. These patches make the GPIO chip even more a proper device and cleans out leftovers of the old in-kernel API here and there. Still some cruft is left but it's very little now. - There is still some clamping of return values for .get() going on, but we now return sane values in the vast majority of drivers and the errorpath is sanitized. Some patches for powerpc, blackfin and unicore still drop in. - We continue to switch the ARM, MIPS, blackfin, m68k local GPIO implementations to use gpiochip_add_data() and cut down on code lines. - MPC8xxx is converted to use the generic GPIO helpers. - ATH79 is converted to use the generic GPIO helpers. New drivers: - WinSystems WS16C48 - Acces 104-DIO-48E - F81866 (a F7188x variant) - Qoric (a MPC8xxx variant) - TS-4800 - SPI serializers (pisosr): simple 74xx shift registers connected to SPI to obtain a dirt-cheap output-only GPIO expander. - Texas Instruments TPIC2810 - Texas Instruments TPS65218 - Texas Instruments TPS65912 - X-Gene (ARM64) standby GPIO controller" * tag 'gpio-v4.6-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (194 commits) Revert "Share upstreaming patches" gpio: mcp23s08: Fix clearing of interrupt. gpiolib: Fix comment referring to gpio_*() in gpiod_*() gpio: pca953x: Fix pca953x_gpio_set_multiple() on 64-bit gpio: xgene: Fix kconfig for standby GIPO contoller gpio: Add generic serializer DT binding gpio: uapi: use 0xB4 as ioctl() major gpio: tps65912: fix bad merge Revert "gpio: lp3943: Drop pin_used and lp3943_gpio_request/lp3943_gpio_free" gpio: omap: drop dev field from gpio_bank structure gpio: mpc8xxx: Slightly update the code for better readability gpio: mpc8xxx: Remove *read_reg and *write_reg from struct mpc8xxx_gpio_chip gpio: mpc8xxx: Fixup setting gpio direction output gpio: mcp23s08: Add support for mcp23s18 dt-bindings: gpio: altera: Fix altr,interrupt-type property gpio: add driver for MEN 16Z127 GPIO controller gpio: lp3943: Drop pin_used and lp3943_gpio_request/lp3943_gpio_free gpio: timberdale: Switch to devm_ioremap_resource() gpio: ts4800: Add IMX51 dependency gpiolib: rewrite gpiodev_add_to_list ...
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/Kconfig2
-rw-r--r--drivers/regulator/tps65912-regulator.c613
2 files changed, 121 insertions, 494 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 91040ec8e242..c77dc08b1202 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -788,7 +788,7 @@ config REGULATOR_TPS65910
788 788
789config REGULATOR_TPS65912 789config REGULATOR_TPS65912
790 tristate "TI TPS65912 Power regulator" 790 tristate "TI TPS65912 Power regulator"
791 depends on (MFD_TPS65912_I2C || MFD_TPS65912_SPI) 791 depends on MFD_TPS65912
792 help 792 help
793 This driver supports TPS65912 voltage regulator chip. 793 This driver supports TPS65912 voltage regulator chip.
794 794
diff --git a/drivers/regulator/tps65912-regulator.c b/drivers/regulator/tps65912-regulator.c
index 9503d5481a52..a4921a70da55 100644
--- a/drivers/regulator/tps65912-regulator.c
+++ b/drivers/regulator/tps65912-regulator.c
@@ -1,541 +1,168 @@
1/* 1/*
2 * tps65912.c -- TI tps65912 2 * Regulator driver for TI TPS65912x PMICs
3 * 3 *
4 * Copyright 2011 Texas Instruments Inc. 4 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
5 * Andrew F. Davis <afd@ti.com>
5 * 6 *
6 * Author: Margarita Olaya Cabrera <magi@slimlogic.co.uk> 7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
7 * 10 *
8 * This program is free software; you can redistribute it and/or modify it 11 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
9 * under the terms of the GNU General Public License as published by the 12 * kind, whether expressed or implied; without even the implied warranty
10 * Free Software Foundation; either version 2 of the License, or (at your 13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * option) any later version. 14 * GNU General Public License version 2 for more details.
12 * 15 *
13 * This driver is based on wm8350 implementation. 16 * Based on the TPS65218 driver and the previous TPS65912 driver by
17 * Margarita Olaya Cabrera <magi@slimlogic.co.uk>
14 */ 18 */
15 19
16#include <linux/kernel.h>
17#include <linux/module.h> 20#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/err.h>
20#include <linux/platform_device.h> 21#include <linux/platform_device.h>
21#include <linux/regulator/driver.h> 22#include <linux/regulator/driver.h>
22#include <linux/regulator/machine.h>
23#include <linux/slab.h>
24#include <linux/gpio.h>
25#include <linux/mfd/tps65912.h>
26
27/* DCDC's */
28#define TPS65912_REG_DCDC1 0
29#define TPS65912_REG_DCDC2 1
30#define TPS65912_REG_DCDC3 2
31#define TPS65912_REG_DCDC4 3
32
33/* LDOs */
34#define TPS65912_REG_LDO1 4
35#define TPS65912_REG_LDO2 5
36#define TPS65912_REG_LDO3 6
37#define TPS65912_REG_LDO4 7
38#define TPS65912_REG_LDO5 8
39#define TPS65912_REG_LDO6 9
40#define TPS65912_REG_LDO7 10
41#define TPS65912_REG_LDO8 11
42#define TPS65912_REG_LDO9 12
43#define TPS65912_REG_LDO10 13
44
45/* Number of step-down converters available */
46#define TPS65912_NUM_DCDC 4
47
48/* Number of LDO voltage regulators available */
49#define TPS65912_NUM_LDO 10
50 23
51/* Number of total regulators available */ 24#include <linux/mfd/tps65912.h>
52#define TPS65912_NUM_REGULATOR (TPS65912_NUM_DCDC + TPS65912_NUM_LDO)
53
54#define TPS65912_REG_ENABLED 0x80
55#define OP_SELREG_MASK 0x40
56#define OP_SELREG_SHIFT 6
57
58struct tps_info {
59 const char *name;
60};
61 25
62static struct tps_info tps65912_regs[] = { 26enum tps65912_regulators { DCDC1, DCDC2, DCDC3, DCDC4, LDO1, LDO2, LDO3,
63 { 27 LDO4, LDO5, LDO6, LDO7, LDO8, LDO9, LDO10 };
64 .name = "DCDC1", 28
65 }, 29#define TPS65912_REGULATOR(_name, _id, _of_match, _ops, _vr, _er, _lr) \
66 { 30 [_id] = { \
67 .name = "DCDC2", 31 .name = _name, \
68 }, 32 .of_match = _of_match, \
69 { 33 .regulators_node = "regulators", \
70 .name = "DCDC3", 34 .id = _id, \
71 }, 35 .ops = &_ops, \
72 { 36 .n_voltages = 64, \
73 .name = "DCDC4", 37 .type = REGULATOR_VOLTAGE, \
74 }, 38 .owner = THIS_MODULE, \
75 { 39 .vsel_reg = _vr, \
76 .name = "LDO1", 40 .vsel_mask = 0x3f, \
77 }, 41 .enable_reg = _er, \
78 { 42 .enable_mask = BIT(7), \
79 .name = "LDO2", 43 .volt_table = NULL, \
80 }, 44 .linear_ranges = _lr, \
81 { 45 .n_linear_ranges = ARRAY_SIZE(_lr), \
82 .name = "LDO3", 46 }
83 },
84 {
85 .name = "LDO4",
86 },
87 {
88 .name = "LDO5",
89 },
90 {
91 .name = "LDO6",
92 },
93 {
94 .name = "LDO7",
95 },
96 {
97 .name = "LDO8",
98 },
99 {
100 .name = "LDO9",
101 },
102 {
103 .name = "LDO10",
104 },
105};
106 47
107struct tps65912_reg { 48static const struct regulator_linear_range tps65912_dcdc_ranges[] = {
108 struct regulator_desc desc[TPS65912_NUM_REGULATOR]; 49 REGULATOR_LINEAR_RANGE(500000, 0x0, 0x3f, 50000),
109 struct tps65912 *mfd;
110 struct regulator_dev *rdev[TPS65912_NUM_REGULATOR];
111 struct tps_info *info[TPS65912_NUM_REGULATOR];
112 /* for read/write access */
113 struct mutex io_lock;
114 int mode;
115 int (*get_ctrl_reg)(int);
116 int dcdc_range[TPS65912_NUM_DCDC];
117 int pwm_mode_reg;
118 int eco_reg;
119}; 50};
120 51
121static const struct regulator_linear_range tps65912_ldo_ranges[] = { 52static const struct regulator_linear_range tps65912_ldo_ranges[] = {
122 REGULATOR_LINEAR_RANGE(800000, 0, 32, 25000), 53 REGULATOR_LINEAR_RANGE(800000, 0x0, 0x20, 25000),
123 REGULATOR_LINEAR_RANGE(1650000, 33, 60, 50000), 54 REGULATOR_LINEAR_RANGE(1650000, 0x21, 0x3c, 50000),
124 REGULATOR_LINEAR_RANGE(3100000, 61, 63, 100000), 55 REGULATOR_LINEAR_RANGE(3100000, 0x3d, 0x3f, 100000),
125}; 56};
126 57
127static int tps65912_get_range(struct tps65912_reg *pmic, int id)
128{
129 struct tps65912 *mfd = pmic->mfd;
130 int range;
131
132 switch (id) {
133 case TPS65912_REG_DCDC1:
134 range = tps65912_reg_read(mfd, TPS65912_DCDC1_LIMIT);
135 break;
136 case TPS65912_REG_DCDC2:
137 range = tps65912_reg_read(mfd, TPS65912_DCDC2_LIMIT);
138 break;
139 case TPS65912_REG_DCDC3:
140 range = tps65912_reg_read(mfd, TPS65912_DCDC3_LIMIT);
141 break;
142 case TPS65912_REG_DCDC4:
143 range = tps65912_reg_read(mfd, TPS65912_DCDC4_LIMIT);
144 break;
145 default:
146 return 0;
147 }
148
149 if (range >= 0)
150 range = (range & DCDC_LIMIT_RANGE_MASK)
151 >> DCDC_LIMIT_RANGE_SHIFT;
152
153 pmic->dcdc_range[id] = range;
154 return range;
155}
156
157static unsigned long tps65912_vsel_to_uv_range0(u8 vsel)
158{
159 unsigned long uv;
160
161 uv = ((vsel * 12500) + 500000);
162 return uv;
163}
164
165static unsigned long tps65912_vsel_to_uv_range1(u8 vsel)
166{
167 unsigned long uv;
168
169 uv = ((vsel * 12500) + 700000);
170 return uv;
171}
172
173static unsigned long tps65912_vsel_to_uv_range2(u8 vsel)
174{
175 unsigned long uv;
176
177 uv = ((vsel * 25000) + 500000);
178 return uv;
179}
180
181static unsigned long tps65912_vsel_to_uv_range3(u8 vsel)
182{
183 unsigned long uv;
184
185 if (vsel == 0x3f)
186 uv = 3800000;
187 else
188 uv = ((vsel * 50000) + 500000);
189
190 return uv;
191}
192
193static int tps65912_get_ctrl_register(int id)
194{
195 if (id >= TPS65912_REG_DCDC1 && id <= TPS65912_REG_LDO4)
196 return id * 3 + TPS65912_DCDC1_AVS;
197 else if (id >= TPS65912_REG_LDO5 && id <= TPS65912_REG_LDO10)
198 return id - TPS65912_REG_LDO5 + TPS65912_LDO5;
199 else
200 return -EINVAL;
201}
202
203static int tps65912_get_sel_register(struct tps65912_reg *pmic, int id)
204{
205 struct tps65912 *mfd = pmic->mfd;
206 int opvsel;
207 u8 reg = 0;
208
209 if (id >= TPS65912_REG_DCDC1 && id <= TPS65912_REG_LDO4) {
210 opvsel = tps65912_reg_read(mfd, id * 3 + TPS65912_DCDC1_OP);
211 if (opvsel & OP_SELREG_MASK)
212 reg = id * 3 + TPS65912_DCDC1_AVS;
213 else
214 reg = id * 3 + TPS65912_DCDC1_OP;
215 } else if (id >= TPS65912_REG_LDO5 && id <= TPS65912_REG_LDO10) {
216 reg = id - TPS65912_REG_LDO5 + TPS65912_LDO5;
217 } else {
218 return -EINVAL;
219 }
220
221 return reg;
222}
223
224static int tps65912_get_mode_regiters(struct tps65912_reg *pmic, int id)
225{
226 switch (id) {
227 case TPS65912_REG_DCDC1:
228 pmic->pwm_mode_reg = TPS65912_DCDC1_CTRL;
229 pmic->eco_reg = TPS65912_DCDC1_AVS;
230 break;
231 case TPS65912_REG_DCDC2:
232 pmic->pwm_mode_reg = TPS65912_DCDC2_CTRL;
233 pmic->eco_reg = TPS65912_DCDC2_AVS;
234 break;
235 case TPS65912_REG_DCDC3:
236 pmic->pwm_mode_reg = TPS65912_DCDC3_CTRL;
237 pmic->eco_reg = TPS65912_DCDC3_AVS;
238 break;
239 case TPS65912_REG_DCDC4:
240 pmic->pwm_mode_reg = TPS65912_DCDC4_CTRL;
241 pmic->eco_reg = TPS65912_DCDC4_AVS;
242 break;
243 default:
244 return -EINVAL;
245 }
246
247 return 0;
248}
249
250static int tps65912_reg_is_enabled(struct regulator_dev *dev)
251{
252 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
253 struct tps65912 *mfd = pmic->mfd;
254 int reg, value, id = rdev_get_id(dev);
255
256 if (id < TPS65912_REG_DCDC1 || id > TPS65912_REG_LDO10)
257 return -EINVAL;
258
259 reg = pmic->get_ctrl_reg(id);
260 if (reg < 0)
261 return reg;
262
263 value = tps65912_reg_read(mfd, reg);
264 if (value < 0)
265 return value;
266
267 return value & TPS65912_REG_ENABLED;
268}
269
270static int tps65912_reg_enable(struct regulator_dev *dev)
271{
272 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
273 struct tps65912 *mfd = pmic->mfd;
274 int id = rdev_get_id(dev);
275 int reg;
276
277 if (id < TPS65912_REG_DCDC1 || id > TPS65912_REG_LDO10)
278 return -EINVAL;
279
280 reg = pmic->get_ctrl_reg(id);
281 if (reg < 0)
282 return reg;
283
284 return tps65912_set_bits(mfd, reg, TPS65912_REG_ENABLED);
285}
286
287static int tps65912_reg_disable(struct regulator_dev *dev)
288{
289 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
290 struct tps65912 *mfd = pmic->mfd;
291 int id = rdev_get_id(dev), reg;
292
293 reg = pmic->get_ctrl_reg(id);
294 if (reg < 0)
295 return reg;
296
297 return tps65912_clear_bits(mfd, reg, TPS65912_REG_ENABLED);
298}
299
300static int tps65912_set_mode(struct regulator_dev *dev, unsigned int mode)
301{
302 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
303 struct tps65912 *mfd = pmic->mfd;
304 int pwm_mode, eco, id = rdev_get_id(dev);
305
306 tps65912_get_mode_regiters(pmic, id);
307
308 pwm_mode = tps65912_reg_read(mfd, pmic->pwm_mode_reg);
309 eco = tps65912_reg_read(mfd, pmic->eco_reg);
310
311 pwm_mode &= DCDCCTRL_DCDC_MODE_MASK;
312 eco &= DCDC_AVS_ECO_MASK;
313
314 switch (mode) {
315 case REGULATOR_MODE_FAST:
316 /* Verify if mode alredy set */
317 if (pwm_mode && !eco)
318 break;
319 tps65912_set_bits(mfd, pmic->pwm_mode_reg, DCDCCTRL_DCDC_MODE_MASK);
320 tps65912_clear_bits(mfd, pmic->eco_reg, DCDC_AVS_ECO_MASK);
321 break;
322 case REGULATOR_MODE_NORMAL:
323 case REGULATOR_MODE_IDLE:
324 if (!pwm_mode && !eco)
325 break;
326 tps65912_clear_bits(mfd, pmic->pwm_mode_reg, DCDCCTRL_DCDC_MODE_MASK);
327 tps65912_clear_bits(mfd, pmic->eco_reg, DCDC_AVS_ECO_MASK);
328 break;
329 case REGULATOR_MODE_STANDBY:
330 if (!pwm_mode && eco)
331 break;
332 tps65912_clear_bits(mfd, pmic->pwm_mode_reg, DCDCCTRL_DCDC_MODE_MASK);
333 tps65912_set_bits(mfd, pmic->eco_reg, DCDC_AVS_ECO_MASK);
334 break;
335 default:
336 return -EINVAL;
337 }
338
339 return 0;
340}
341
342static unsigned int tps65912_get_mode(struct regulator_dev *dev)
343{
344 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
345 struct tps65912 *mfd = pmic->mfd;
346 int pwm_mode, eco, mode = 0, id = rdev_get_id(dev);
347
348 tps65912_get_mode_regiters(pmic, id);
349
350 pwm_mode = tps65912_reg_read(mfd, pmic->pwm_mode_reg);
351 eco = tps65912_reg_read(mfd, pmic->eco_reg);
352
353 pwm_mode &= DCDCCTRL_DCDC_MODE_MASK;
354 eco &= DCDC_AVS_ECO_MASK;
355
356 if (pwm_mode && !eco)
357 mode = REGULATOR_MODE_FAST;
358 else if (!pwm_mode && !eco)
359 mode = REGULATOR_MODE_NORMAL;
360 else if (!pwm_mode && eco)
361 mode = REGULATOR_MODE_STANDBY;
362
363 return mode;
364}
365
366static int tps65912_list_voltage(struct regulator_dev *dev, unsigned selector)
367{
368 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
369 int range, voltage = 0, id = rdev_get_id(dev);
370
371 if (id > TPS65912_REG_DCDC4)
372 return -EINVAL;
373
374 range = pmic->dcdc_range[id];
375
376 switch (range) {
377 case 0:
378 /* 0.5 - 1.2875V in 12.5mV steps */
379 voltage = tps65912_vsel_to_uv_range0(selector);
380 break;
381 case 1:
382 /* 0.7 - 1.4875V in 12.5mV steps */
383 voltage = tps65912_vsel_to_uv_range1(selector);
384 break;
385 case 2:
386 /* 0.5 - 2.075V in 25mV steps */
387 voltage = tps65912_vsel_to_uv_range2(selector);
388 break;
389 case 3:
390 /* 0.5 - 3.8V in 50mV steps */
391 voltage = tps65912_vsel_to_uv_range3(selector);
392 break;
393 }
394 return voltage;
395}
396
397static int tps65912_get_voltage_sel(struct regulator_dev *dev)
398{
399 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
400 struct tps65912 *mfd = pmic->mfd;
401 int id = rdev_get_id(dev);
402 int reg, vsel;
403
404 reg = tps65912_get_sel_register(pmic, id);
405 if (reg < 0)
406 return reg;
407
408 vsel = tps65912_reg_read(mfd, reg);
409 vsel &= 0x3F;
410
411 return vsel;
412}
413
414static int tps65912_set_voltage_sel(struct regulator_dev *dev,
415 unsigned selector)
416{
417 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
418 struct tps65912 *mfd = pmic->mfd;
419 int id = rdev_get_id(dev);
420 int value;
421 u8 reg;
422
423 reg = tps65912_get_sel_register(pmic, id);
424 value = tps65912_reg_read(mfd, reg);
425 value &= 0xC0;
426 return tps65912_reg_write(mfd, reg, selector | value);
427}
428
429/* Operations permitted on DCDCx */ 58/* Operations permitted on DCDCx */
430static struct regulator_ops tps65912_ops_dcdc = { 59static struct regulator_ops tps65912_ops_dcdc = {
431 .is_enabled = tps65912_reg_is_enabled, 60 .is_enabled = regulator_is_enabled_regmap,
432 .enable = tps65912_reg_enable, 61 .enable = regulator_enable_regmap,
433 .disable = tps65912_reg_disable, 62 .disable = regulator_disable_regmap,
434 .set_mode = tps65912_set_mode, 63 .get_voltage_sel = regulator_get_voltage_sel_regmap,
435 .get_mode = tps65912_get_mode, 64 .set_voltage_sel = regulator_set_voltage_sel_regmap,
436 .get_voltage_sel = tps65912_get_voltage_sel, 65 .list_voltage = regulator_list_voltage_linear_range,
437 .set_voltage_sel = tps65912_set_voltage_sel,
438 .list_voltage = tps65912_list_voltage,
439}; 66};
440 67
441/* Operations permitted on LDOx */ 68/* Operations permitted on LDOx */
442static struct regulator_ops tps65912_ops_ldo = { 69static struct regulator_ops tps65912_ops_ldo = {
443 .is_enabled = tps65912_reg_is_enabled, 70 .is_enabled = regulator_is_enabled_regmap,
444 .enable = tps65912_reg_enable, 71 .enable = regulator_enable_regmap,
445 .disable = tps65912_reg_disable, 72 .disable = regulator_disable_regmap,
446 .get_voltage_sel = tps65912_get_voltage_sel, 73 .get_voltage_sel = regulator_get_voltage_sel_regmap,
447 .set_voltage_sel = tps65912_set_voltage_sel, 74 .set_voltage_sel = regulator_set_voltage_sel_regmap,
448 .list_voltage = regulator_list_voltage_linear_range, 75 .list_voltage = regulator_list_voltage_linear_range,
449 .map_voltage = regulator_map_voltage_linear_range, 76 .map_voltage = regulator_map_voltage_linear_range,
77};
78
79static const struct regulator_desc regulators[] = {
80 TPS65912_REGULATOR("DCDC1", DCDC1, "dcdc1", tps65912_ops_dcdc,
81 TPS65912_DCDC1_OP, TPS65912_DCDC1_CTRL,
82 tps65912_dcdc_ranges),
83 TPS65912_REGULATOR("DCDC2", DCDC2, "dcdc2", tps65912_ops_dcdc,
84 TPS65912_DCDC2_OP, TPS65912_DCDC2_CTRL,
85 tps65912_dcdc_ranges),
86 TPS65912_REGULATOR("DCDC3", DCDC3, "dcdc3", tps65912_ops_dcdc,
87 TPS65912_DCDC3_OP, TPS65912_DCDC3_CTRL,
88 tps65912_dcdc_ranges),
89 TPS65912_REGULATOR("DCDC4", DCDC4, "dcdc4", tps65912_ops_dcdc,
90 TPS65912_DCDC4_OP, TPS65912_DCDC4_CTRL,
91 tps65912_dcdc_ranges),
92 TPS65912_REGULATOR("LDO1", LDO1, "ldo1", tps65912_ops_ldo,
93 TPS65912_LDO1_OP, TPS65912_LDO1_AVS,
94 tps65912_ldo_ranges),
95 TPS65912_REGULATOR("LDO2", LDO2, "ldo2", tps65912_ops_ldo,
96 TPS65912_LDO2_OP, TPS65912_LDO2_AVS,
97 tps65912_ldo_ranges),
98 TPS65912_REGULATOR("LDO3", LDO3, "ldo3", tps65912_ops_ldo,
99 TPS65912_LDO3_OP, TPS65912_LDO3_AVS,
100 tps65912_ldo_ranges),
101 TPS65912_REGULATOR("LDO4", LDO4, "ldo4", tps65912_ops_ldo,
102 TPS65912_LDO4_OP, TPS65912_LDO4_AVS,
103 tps65912_ldo_ranges),
104 TPS65912_REGULATOR("LDO5", LDO5, "ldo5", tps65912_ops_ldo,
105 TPS65912_LDO5, TPS65912_LDO5,
106 tps65912_ldo_ranges),
107 TPS65912_REGULATOR("LDO6", LDO6, "ldo6", tps65912_ops_ldo,
108 TPS65912_LDO6, TPS65912_LDO6,
109 tps65912_ldo_ranges),
110 TPS65912_REGULATOR("LDO7", LDO7, "ldo7", tps65912_ops_ldo,
111 TPS65912_LDO7, TPS65912_LDO7,
112 tps65912_ldo_ranges),
113 TPS65912_REGULATOR("LDO8", LDO8, "ldo8", tps65912_ops_ldo,
114 TPS65912_LDO8, TPS65912_LDO8,
115 tps65912_ldo_ranges),
116 TPS65912_REGULATOR("LDO9", LDO9, "ldo9", tps65912_ops_ldo,
117 TPS65912_LDO9, TPS65912_LDO9,
118 tps65912_ldo_ranges),
119 TPS65912_REGULATOR("LDO10", LDO10, "ldo10", tps65912_ops_ldo,
120 TPS65912_LDO10, TPS65912_LDO10,
121 tps65912_ldo_ranges),
450}; 122};
451 123
452static int tps65912_probe(struct platform_device *pdev) 124static int tps65912_regulator_probe(struct platform_device *pdev)
453{ 125{
454 struct tps65912 *tps65912 = dev_get_drvdata(pdev->dev.parent); 126 struct tps65912 *tps = dev_get_drvdata(pdev->dev.parent);
455 struct regulator_config config = { }; 127 struct regulator_config config = { };
456 struct tps_info *info;
457 struct regulator_init_data *reg_data;
458 struct regulator_dev *rdev; 128 struct regulator_dev *rdev;
459 struct tps65912_reg *pmic;
460 struct tps65912_board *pmic_plat_data;
461 int i; 129 int i;
462 130
463 pmic_plat_data = dev_get_platdata(tps65912->dev); 131 platform_set_drvdata(pdev, tps);
464 if (!pmic_plat_data)
465 return -EINVAL;
466 132
467 reg_data = pmic_plat_data->tps65912_pmic_init_data; 133 config.dev = &pdev->dev;
134 config.driver_data = tps;
135 config.dev->of_node = tps->dev->of_node;
136 config.regmap = tps->regmap;
468 137
469 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); 138 for (i = 0; i < ARRAY_SIZE(regulators); i++) {
470 if (!pmic) 139 rdev = devm_regulator_register(&pdev->dev, &regulators[i],
471 return -ENOMEM;
472
473 mutex_init(&pmic->io_lock);
474 pmic->mfd = tps65912;
475 platform_set_drvdata(pdev, pmic);
476
477 pmic->get_ctrl_reg = &tps65912_get_ctrl_register;
478 info = tps65912_regs;
479
480 for (i = 0; i < TPS65912_NUM_REGULATOR; i++, info++, reg_data++) {
481 int range = 0;
482 /* Register the regulators */
483 pmic->info[i] = info;
484
485 pmic->desc[i].name = info->name;
486 pmic->desc[i].id = i;
487 pmic->desc[i].n_voltages = 64;
488 if (i > TPS65912_REG_DCDC4) {
489 pmic->desc[i].ops = &tps65912_ops_ldo;
490 pmic->desc[i].linear_ranges = tps65912_ldo_ranges;
491 pmic->desc[i].n_linear_ranges =
492 ARRAY_SIZE(tps65912_ldo_ranges);
493 } else {
494 pmic->desc[i].ops = &tps65912_ops_dcdc;
495 }
496 pmic->desc[i].type = REGULATOR_VOLTAGE;
497 pmic->desc[i].owner = THIS_MODULE;
498 range = tps65912_get_range(pmic, i);
499
500 config.dev = tps65912->dev;
501 config.init_data = reg_data;
502 config.driver_data = pmic;
503
504 rdev = devm_regulator_register(&pdev->dev, &pmic->desc[i],
505 &config); 140 &config);
506 if (IS_ERR(rdev)) { 141 if (IS_ERR(rdev)) {
507 dev_err(tps65912->dev, 142 dev_err(tps->dev, "failed to register %s regulator\n",
508 "failed to register %s regulator\n",
509 pdev->name); 143 pdev->name);
510 return PTR_ERR(rdev); 144 return PTR_ERR(rdev);
511 } 145 }
512
513 /* Save regulator for cleanup */
514 pmic->rdev[i] = rdev;
515 } 146 }
147
516 return 0; 148 return 0;
517} 149}
518 150
519static struct platform_driver tps65912_driver = { 151static const struct platform_device_id tps65912_regulator_id_table[] = {
152 { "tps65912-regulator", },
153 { /* sentinel */ }
154};
155MODULE_DEVICE_TABLE(platform, tps65912_regulator_id_table);
156
157static struct platform_driver tps65912_regulator_driver = {
520 .driver = { 158 .driver = {
521 .name = "tps65912-pmic", 159 .name = "tps65912-regulator",
522 }, 160 },
523 .probe = tps65912_probe, 161 .probe = tps65912_regulator_probe,
162 .id_table = tps65912_regulator_id_table,
524}; 163};
164module_platform_driver(tps65912_regulator_driver);
525 165
526static int __init tps65912_init(void) 166MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
527{
528 return platform_driver_register(&tps65912_driver);
529}
530subsys_initcall(tps65912_init);
531
532static void __exit tps65912_cleanup(void)
533{
534 platform_driver_unregister(&tps65912_driver);
535}
536module_exit(tps65912_cleanup);
537
538MODULE_AUTHOR("Margarita Olaya Cabrera <magi@slimlogic.co.uk>");
539MODULE_DESCRIPTION("TPS65912 voltage regulator driver"); 167MODULE_DESCRIPTION("TPS65912 voltage regulator driver");
540MODULE_LICENSE("GPL v2"); 168MODULE_LICENSE("GPL v2");
541MODULE_ALIAS("platform:tps65912-pmic");