2 * Regulator driver for Rockchip RK808
4 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
6 * Author: Chris Zhong <zyw@rock-chips.com>
7 * Author: Zhang Qing <zhangqing@rock-chips.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms and conditions of the GNU General Public License,
11 * version 2, as published by the Free Software Foundation.
13 * This program is distributed in the hope it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 #include <linux/module.h>
20 #include <linux/i2c.h>
21 #include <linux/mfd/rk808.h>
22 #include <linux/of_device.h>
23 #include <linux/regulator/driver.h>
24 #include <linux/regulator/of_regulator.h>
26 /* Field Definitions */
27 #define RK808_BUCK_VSEL_MASK 0x3f
28 #define RK808_BUCK4_VSEL_MASK 0xf
29 #define RK808_LDO_VSEL_MASK 0x1f
31 /* Ramp rate definitions for buck1 / buck2 only */
32 #define RK808_RAMP_RATE_OFFSET 3
33 #define RK808_RAMP_RATE_MASK (3 << RK808_RAMP_RATE_OFFSET)
34 #define RK808_RAMP_RATE_2MV_PER_US (0 << RK808_RAMP_RATE_OFFSET)
35 #define RK808_RAMP_RATE_4MV_PER_US (1 << RK808_RAMP_RATE_OFFSET)
36 #define RK808_RAMP_RATE_6MV_PER_US (2 << RK808_RAMP_RATE_OFFSET)
37 #define RK808_RAMP_RATE_10MV_PER_US (3 << RK808_RAMP_RATE_OFFSET)
39 static const int rk808_buck_config_regs
[] = {
40 RK808_BUCK1_CONFIG_REG
,
41 RK808_BUCK2_CONFIG_REG
,
42 RK808_BUCK3_CONFIG_REG
,
43 RK808_BUCK4_CONFIG_REG
,
46 static const struct regulator_linear_range rk808_buck_voltage_ranges
[] = {
47 REGULATOR_LINEAR_RANGE(700000, 0, 63, 12500),
50 static const struct regulator_linear_range rk808_buck4_voltage_ranges
[] = {
51 REGULATOR_LINEAR_RANGE(1800000, 0, 15, 100000),
54 static const struct regulator_linear_range rk808_ldo_voltage_ranges
[] = {
55 REGULATOR_LINEAR_RANGE(1800000, 0, 16, 100000),
58 static const struct regulator_linear_range rk808_ldo3_voltage_ranges
[] = {
59 REGULATOR_LINEAR_RANGE(800000, 0, 13, 100000),
60 REGULATOR_LINEAR_RANGE(2500000, 15, 15, 0),
63 static const struct regulator_linear_range rk808_ldo6_voltage_ranges
[] = {
64 REGULATOR_LINEAR_RANGE(800000, 0, 17, 100000),
67 static int rk808_set_ramp_delay(struct regulator_dev
*rdev
, int ramp_delay
)
69 unsigned int ramp_value
= RK808_RAMP_RATE_10MV_PER_US
;
70 unsigned int reg
= rk808_buck_config_regs
[rdev
->desc
->id
-
75 ramp_value
= RK808_RAMP_RATE_2MV_PER_US
;
78 ramp_value
= RK808_RAMP_RATE_4MV_PER_US
;
81 ramp_value
= RK808_RAMP_RATE_6MV_PER_US
;
86 pr_warn("%s ramp_delay: %d not supported, setting 10000\n",
87 rdev
->desc
->name
, ramp_delay
);
90 return regmap_update_bits(rdev
->regmap
, reg
,
91 RK808_RAMP_RATE_MASK
, ramp_value
);
94 static struct regulator_ops rk808_buck1_2_ops
= {
95 .list_voltage
= regulator_list_voltage_linear_range
,
96 .map_voltage
= regulator_map_voltage_linear_range
,
97 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
98 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
99 .enable
= regulator_enable_regmap
,
100 .disable
= regulator_disable_regmap
,
101 .is_enabled
= regulator_is_enabled_regmap
,
102 .set_ramp_delay
= rk808_set_ramp_delay
,
105 static struct regulator_ops rk808_reg_ops
= {
106 .list_voltage
= regulator_list_voltage_linear_range
,
107 .map_voltage
= regulator_map_voltage_linear_range
,
108 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
109 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
110 .enable
= regulator_enable_regmap
,
111 .disable
= regulator_disable_regmap
,
112 .is_enabled
= regulator_is_enabled_regmap
,
115 static struct regulator_ops rk808_switch_ops
= {
116 .enable
= regulator_enable_regmap
,
117 .disable
= regulator_disable_regmap
,
118 .is_enabled
= regulator_is_enabled_regmap
,
121 static const struct regulator_desc rk808_reg
[] = {
124 .supply_name
= "vcc1",
125 .id
= RK808_ID_DCDC1
,
126 .ops
= &rk808_buck1_2_ops
,
127 .type
= REGULATOR_VOLTAGE
,
129 .linear_ranges
= rk808_buck_voltage_ranges
,
130 .n_linear_ranges
= ARRAY_SIZE(rk808_buck_voltage_ranges
),
131 .vsel_reg
= RK808_BUCK1_ON_VSEL_REG
,
132 .vsel_mask
= RK808_BUCK_VSEL_MASK
,
133 .enable_reg
= RK808_DCDC_EN_REG
,
134 .enable_mask
= BIT(0),
135 .owner
= THIS_MODULE
,
138 .supply_name
= "vcc2",
139 .id
= RK808_ID_DCDC2
,
140 .ops
= &rk808_buck1_2_ops
,
141 .type
= REGULATOR_VOLTAGE
,
143 .linear_ranges
= rk808_buck_voltage_ranges
,
144 .n_linear_ranges
= ARRAY_SIZE(rk808_buck_voltage_ranges
),
145 .vsel_reg
= RK808_BUCK2_ON_VSEL_REG
,
146 .vsel_mask
= RK808_BUCK_VSEL_MASK
,
147 .enable_reg
= RK808_DCDC_EN_REG
,
148 .enable_mask
= BIT(1),
149 .owner
= THIS_MODULE
,
152 .supply_name
= "vcc3",
153 .id
= RK808_ID_DCDC3
,
154 .ops
= &rk808_switch_ops
,
155 .type
= REGULATOR_VOLTAGE
,
157 .enable_reg
= RK808_DCDC_EN_REG
,
158 .enable_mask
= BIT(2),
159 .owner
= THIS_MODULE
,
162 .supply_name
= "vcc4",
163 .id
= RK808_ID_DCDC4
,
164 .ops
= &rk808_reg_ops
,
165 .type
= REGULATOR_VOLTAGE
,
167 .linear_ranges
= rk808_buck4_voltage_ranges
,
168 .n_linear_ranges
= ARRAY_SIZE(rk808_buck4_voltage_ranges
),
169 .vsel_reg
= RK808_BUCK4_ON_VSEL_REG
,
170 .vsel_mask
= RK808_BUCK4_VSEL_MASK
,
171 .enable_reg
= RK808_DCDC_EN_REG
,
172 .enable_mask
= BIT(3),
173 .owner
= THIS_MODULE
,
176 .supply_name
= "vcc6",
178 .ops
= &rk808_reg_ops
,
179 .type
= REGULATOR_VOLTAGE
,
181 .linear_ranges
= rk808_ldo_voltage_ranges
,
182 .n_linear_ranges
= ARRAY_SIZE(rk808_ldo_voltage_ranges
),
183 .vsel_reg
= RK808_LDO1_ON_VSEL_REG
,
184 .vsel_mask
= RK808_LDO_VSEL_MASK
,
185 .enable_reg
= RK808_LDO_EN_REG
,
186 .enable_mask
= BIT(0),
187 .owner
= THIS_MODULE
,
190 .supply_name
= "vcc6",
192 .ops
= &rk808_reg_ops
,
193 .type
= REGULATOR_VOLTAGE
,
195 .linear_ranges
= rk808_ldo_voltage_ranges
,
196 .n_linear_ranges
= ARRAY_SIZE(rk808_ldo_voltage_ranges
),
197 .vsel_reg
= RK808_LDO2_ON_VSEL_REG
,
198 .vsel_mask
= RK808_LDO_VSEL_MASK
,
199 .enable_reg
= RK808_LDO_EN_REG
,
200 .enable_mask
= BIT(1),
201 .owner
= THIS_MODULE
,
204 .supply_name
= "vcc7",
206 .ops
= &rk808_reg_ops
,
207 .type
= REGULATOR_VOLTAGE
,
209 .linear_ranges
= rk808_ldo3_voltage_ranges
,
210 .n_linear_ranges
= ARRAY_SIZE(rk808_ldo3_voltage_ranges
),
211 .vsel_reg
= RK808_LDO3_ON_VSEL_REG
,
212 .vsel_mask
= RK808_BUCK4_VSEL_MASK
,
213 .enable_reg
= RK808_LDO_EN_REG
,
214 .enable_mask
= BIT(2),
215 .owner
= THIS_MODULE
,
218 .supply_name
= "vcc9",
220 .ops
= &rk808_reg_ops
,
221 .type
= REGULATOR_VOLTAGE
,
223 .linear_ranges
= rk808_ldo_voltage_ranges
,
224 .n_linear_ranges
= ARRAY_SIZE(rk808_ldo_voltage_ranges
),
225 .vsel_reg
= RK808_LDO4_ON_VSEL_REG
,
226 .vsel_mask
= RK808_LDO_VSEL_MASK
,
227 .enable_reg
= RK808_LDO_EN_REG
,
228 .enable_mask
= BIT(3),
229 .owner
= THIS_MODULE
,
232 .supply_name
= "vcc9",
234 .ops
= &rk808_reg_ops
,
235 .type
= REGULATOR_VOLTAGE
,
237 .linear_ranges
= rk808_ldo_voltage_ranges
,
238 .n_linear_ranges
= ARRAY_SIZE(rk808_ldo_voltage_ranges
),
239 .vsel_reg
= RK808_LDO5_ON_VSEL_REG
,
240 .vsel_mask
= RK808_LDO_VSEL_MASK
,
241 .enable_reg
= RK808_LDO_EN_REG
,
242 .enable_mask
= BIT(4),
243 .owner
= THIS_MODULE
,
246 .supply_name
= "vcc10",
248 .ops
= &rk808_reg_ops
,
249 .type
= REGULATOR_VOLTAGE
,
251 .linear_ranges
= rk808_ldo6_voltage_ranges
,
252 .n_linear_ranges
= ARRAY_SIZE(rk808_ldo6_voltage_ranges
),
253 .vsel_reg
= RK808_LDO6_ON_VSEL_REG
,
254 .vsel_mask
= RK808_LDO_VSEL_MASK
,
255 .enable_reg
= RK808_LDO_EN_REG
,
256 .enable_mask
= BIT(5),
257 .owner
= THIS_MODULE
,
260 .supply_name
= "vcc7",
262 .ops
= &rk808_reg_ops
,
263 .type
= REGULATOR_VOLTAGE
,
265 .linear_ranges
= rk808_ldo6_voltage_ranges
,
266 .n_linear_ranges
= ARRAY_SIZE(rk808_ldo6_voltage_ranges
),
267 .vsel_reg
= RK808_LDO7_ON_VSEL_REG
,
268 .vsel_mask
= RK808_LDO_VSEL_MASK
,
269 .enable_reg
= RK808_LDO_EN_REG
,
270 .enable_mask
= BIT(6),
271 .owner
= THIS_MODULE
,
274 .supply_name
= "vcc11",
276 .ops
= &rk808_reg_ops
,
277 .type
= REGULATOR_VOLTAGE
,
279 .linear_ranges
= rk808_ldo_voltage_ranges
,
280 .n_linear_ranges
= ARRAY_SIZE(rk808_ldo_voltage_ranges
),
281 .vsel_reg
= RK808_LDO8_ON_VSEL_REG
,
282 .vsel_mask
= RK808_LDO_VSEL_MASK
,
283 .enable_reg
= RK808_LDO_EN_REG
,
284 .enable_mask
= BIT(7),
285 .owner
= THIS_MODULE
,
287 .name
= "SWITCH_REG1",
288 .supply_name
= "vcc8",
289 .id
= RK808_ID_SWITCH1
,
290 .ops
= &rk808_switch_ops
,
291 .type
= REGULATOR_VOLTAGE
,
292 .enable_reg
= RK808_DCDC_EN_REG
,
293 .enable_mask
= BIT(5),
294 .owner
= THIS_MODULE
,
296 .name
= "SWITCH_REG2",
297 .supply_name
= "vcc12",
298 .id
= RK808_ID_SWITCH2
,
299 .ops
= &rk808_switch_ops
,
300 .type
= REGULATOR_VOLTAGE
,
301 .enable_reg
= RK808_DCDC_EN_REG
,
302 .enable_mask
= BIT(6),
303 .owner
= THIS_MODULE
,
307 static struct of_regulator_match rk808_reg_matches
[] = {
308 [RK808_ID_DCDC1
] = { .name
= "DCDC_REG1" },
309 [RK808_ID_DCDC2
] = { .name
= "DCDC_REG2" },
310 [RK808_ID_DCDC3
] = { .name
= "DCDC_REG3" },
311 [RK808_ID_DCDC4
] = { .name
= "DCDC_REG4" },
312 [RK808_ID_LDO1
] = { .name
= "LDO_REG1" },
313 [RK808_ID_LDO2
] = { .name
= "LDO_REG2" },
314 [RK808_ID_LDO3
] = { .name
= "LDO_REG3" },
315 [RK808_ID_LDO4
] = { .name
= "LDO_REG4" },
316 [RK808_ID_LDO5
] = { .name
= "LDO_REG5" },
317 [RK808_ID_LDO6
] = { .name
= "LDO_REG6" },
318 [RK808_ID_LDO7
] = { .name
= "LDO_REG7" },
319 [RK808_ID_LDO8
] = { .name
= "LDO_REG8" },
320 [RK808_ID_SWITCH1
] = { .name
= "SWITCH_REG1" },
321 [RK808_ID_SWITCH2
] = { .name
= "SWITCH_REG2" },
324 static int rk808_regulator_probe(struct platform_device
*pdev
)
326 struct rk808
*rk808
= dev_get_drvdata(pdev
->dev
.parent
);
327 struct i2c_client
*client
= rk808
->i2c
;
328 struct device_node
*reg_np
;
329 struct regulator_config config
= {};
330 struct regulator_dev
*rk808_rdev
;
333 reg_np
= of_get_child_by_name(client
->dev
.of_node
, "regulators");
337 ret
= of_regulator_match(&pdev
->dev
, reg_np
, rk808_reg_matches
,
338 RK808_NUM_REGULATORS
);
343 /* Instantiate the regulators */
344 for (i
= 0; i
< RK808_NUM_REGULATORS
; i
++) {
345 if (!rk808_reg_matches
[i
].init_data
||
346 !rk808_reg_matches
[i
].of_node
)
349 config
.dev
= &client
->dev
;
350 config
.driver_data
= rk808
;
351 config
.regmap
= rk808
->regmap
;
352 config
.of_node
= rk808_reg_matches
[i
].of_node
;
353 config
.init_data
= rk808_reg_matches
[i
].init_data
;
355 rk808_rdev
= devm_regulator_register(&pdev
->dev
,
356 &rk808_reg
[i
], &config
);
357 if (IS_ERR(rk808_rdev
)) {
358 dev_err(&client
->dev
,
359 "failed to register %d regulator\n", i
);
360 return PTR_ERR(rk808_rdev
);
367 static struct platform_driver rk808_regulator_driver
= {
368 .probe
= rk808_regulator_probe
,
370 .name
= "rk808-regulator",
371 .owner
= THIS_MODULE
,
375 module_platform_driver(rk808_regulator_driver
);
377 MODULE_DESCRIPTION("regulator driver for the rk808 series PMICs");
378 MODULE_AUTHOR("Chris Zhong<zyw@rock-chips.com>");
379 MODULE_AUTHOR("Zhang Qing<zhangqing@rock-chips.com>");
380 MODULE_LICENSE("GPL");
381 MODULE_ALIAS("platform:rk808-regulator");