Commit | Line | Data |
---|---|---|
2cd64ae3 CZ |
1 | /* |
2 | * Regulator driver for Rockchip RK808 | |
3 | * | |
4 | * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd | |
5 | * | |
6 | * Author: Chris Zhong <zyw@rock-chips.com> | |
7 | * Author: Zhang Qing <zhangqing@rock-chips.com> | |
8 | * | |
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. | |
12 | * | |
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 | |
16 | * more details. | |
2cd64ae3 CZ |
17 | */ |
18 | ||
19 | #include <linux/module.h> | |
2cd64ae3 | 20 | #include <linux/i2c.h> |
2cd64ae3 | 21 | #include <linux/mfd/rk808.h> |
2cd64ae3 CZ |
22 | #include <linux/of_device.h> |
23 | #include <linux/regulator/driver.h> | |
24 | #include <linux/regulator/of_regulator.h> | |
571a4010 CZ |
25 | |
26 | /* Field Definitions */ | |
2cd64ae3 CZ |
27 | #define RK808_BUCK_VSEL_MASK 0x3f |
28 | #define RK808_BUCK4_VSEL_MASK 0xf | |
29 | #define RK808_LDO_VSEL_MASK 0x1f | |
30 | ||
31 | static const int buck_set_vol_base_addr[] = { | |
32 | RK808_BUCK1_ON_VSEL_REG, | |
33 | RK808_BUCK2_ON_VSEL_REG, | |
34 | RK808_BUCK3_CONFIG_REG, | |
35 | RK808_BUCK4_ON_VSEL_REG, | |
36 | }; | |
37 | ||
38 | static const int buck_contr_base_addr[] = { | |
39 | RK808_BUCK1_CONFIG_REG, | |
40 | RK808_BUCK2_CONFIG_REG, | |
41 | RK808_BUCK3_CONFIG_REG, | |
42 | RK808_BUCK4_CONFIG_REG, | |
43 | }; | |
44 | ||
2cd64ae3 CZ |
45 | static const int ldo_set_vol_base_addr[] = { |
46 | RK808_LDO1_ON_VSEL_REG, | |
47 | RK808_LDO2_ON_VSEL_REG, | |
48 | RK808_LDO3_ON_VSEL_REG, | |
49 | RK808_LDO4_ON_VSEL_REG, | |
50 | RK808_LDO5_ON_VSEL_REG, | |
51 | RK808_LDO6_ON_VSEL_REG, | |
52 | RK808_LDO7_ON_VSEL_REG, | |
53 | RK808_LDO8_ON_VSEL_REG, | |
54 | }; | |
55 | ||
571a4010 | 56 | /* rk808 voltage number */ |
2cd64ae3 CZ |
57 | static const struct regulator_linear_range rk808_buck_voltage_ranges[] = { |
58 | REGULATOR_LINEAR_RANGE(700000, 0, 63, 12500), | |
59 | }; | |
60 | ||
61 | static const struct regulator_linear_range rk808_buck4_voltage_ranges[] = { | |
62 | REGULATOR_LINEAR_RANGE(1800000, 0, 15, 100000), | |
63 | }; | |
64 | ||
65 | static const struct regulator_linear_range rk808_ldo_voltage_ranges[] = { | |
66 | REGULATOR_LINEAR_RANGE(1800000, 0, 16, 100000), | |
67 | }; | |
68 | ||
69 | static const struct regulator_linear_range rk808_ldo3_voltage_ranges[] = { | |
70 | REGULATOR_LINEAR_RANGE(800000, 0, 13, 100000), | |
71 | REGULATOR_LINEAR_RANGE(2500000, 15, 15, 0), | |
72 | }; | |
73 | ||
74 | static const struct regulator_linear_range rk808_ldo6_voltage_ranges[] = { | |
75 | REGULATOR_LINEAR_RANGE(800000, 0, 17, 100000), | |
76 | }; | |
77 | ||
78 | static struct regulator_ops rk808_reg_ops = { | |
79 | .list_voltage = regulator_list_voltage_linear_range, | |
80 | .map_voltage = regulator_map_voltage_linear_range, | |
81 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | |
82 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | |
83 | .enable = regulator_enable_regmap, | |
84 | .disable = regulator_disable_regmap, | |
85 | .is_enabled = regulator_is_enabled_regmap, | |
86 | }; | |
87 | ||
88 | static struct regulator_ops rk808_switch_ops = { | |
89 | .enable = regulator_enable_regmap, | |
90 | .disable = regulator_disable_regmap, | |
91 | .is_enabled = regulator_is_enabled_regmap, | |
92 | }; | |
93 | ||
94 | static const struct regulator_desc rk808_reg[] = { | |
95 | { | |
96 | .name = "DCDC_REG1", | |
b8074eba | 97 | .supply_name = "vcc1", |
2cd64ae3 CZ |
98 | .id = RK808_ID_DCDC1, |
99 | .ops = &rk808_reg_ops, | |
100 | .type = REGULATOR_VOLTAGE, | |
101 | .n_voltages = 64, | |
102 | .linear_ranges = rk808_buck_voltage_ranges, | |
103 | .n_linear_ranges = ARRAY_SIZE(rk808_buck_voltage_ranges), | |
104 | .vsel_reg = RK808_BUCK1_ON_VSEL_REG, | |
105 | .vsel_mask = RK808_BUCK_VSEL_MASK, | |
106 | .enable_reg = RK808_DCDC_EN_REG, | |
107 | .enable_mask = BIT(0), | |
108 | .owner = THIS_MODULE, | |
109 | }, { | |
110 | .name = "DCDC_REG2", | |
b8074eba | 111 | .supply_name = "vcc2", |
2cd64ae3 CZ |
112 | .id = RK808_ID_DCDC2, |
113 | .ops = &rk808_reg_ops, | |
114 | .type = REGULATOR_VOLTAGE, | |
115 | .n_voltages = 64, | |
116 | .linear_ranges = rk808_buck_voltage_ranges, | |
117 | .n_linear_ranges = ARRAY_SIZE(rk808_buck_voltage_ranges), | |
118 | .vsel_reg = RK808_BUCK2_ON_VSEL_REG, | |
119 | .vsel_mask = RK808_BUCK_VSEL_MASK, | |
120 | .enable_reg = RK808_DCDC_EN_REG, | |
121 | .enable_mask = BIT(1), | |
122 | .owner = THIS_MODULE, | |
123 | }, { | |
124 | .name = "DCDC_REG3", | |
b8074eba | 125 | .supply_name = "vcc3", |
2cd64ae3 CZ |
126 | .id = RK808_ID_DCDC3, |
127 | .ops = &rk808_switch_ops, | |
128 | .type = REGULATOR_VOLTAGE, | |
129 | .n_voltages = 1, | |
130 | .enable_reg = RK808_DCDC_EN_REG, | |
131 | .enable_mask = BIT(2), | |
132 | .owner = THIS_MODULE, | |
133 | }, { | |
134 | .name = "DCDC_REG4", | |
b8074eba | 135 | .supply_name = "vcc4", |
2cd64ae3 CZ |
136 | .id = RK808_ID_DCDC4, |
137 | .ops = &rk808_reg_ops, | |
138 | .type = REGULATOR_VOLTAGE, | |
5a82067f | 139 | .n_voltages = 16, |
2cd64ae3 CZ |
140 | .linear_ranges = rk808_buck4_voltage_ranges, |
141 | .n_linear_ranges = ARRAY_SIZE(rk808_buck4_voltage_ranges), | |
142 | .vsel_reg = RK808_BUCK4_ON_VSEL_REG, | |
143 | .vsel_mask = RK808_BUCK4_VSEL_MASK, | |
144 | .enable_reg = RK808_DCDC_EN_REG, | |
145 | .enable_mask = BIT(3), | |
146 | .owner = THIS_MODULE, | |
147 | }, { | |
148 | .name = "LDO_REG1", | |
b8074eba | 149 | .supply_name = "vcc6", |
2cd64ae3 CZ |
150 | .id = RK808_ID_LDO1, |
151 | .ops = &rk808_reg_ops, | |
152 | .type = REGULATOR_VOLTAGE, | |
153 | .n_voltages = 17, | |
154 | .linear_ranges = rk808_ldo_voltage_ranges, | |
155 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo_voltage_ranges), | |
156 | .vsel_reg = RK808_LDO1_ON_VSEL_REG, | |
157 | .vsel_mask = RK808_LDO_VSEL_MASK, | |
158 | .enable_reg = RK808_LDO_EN_REG, | |
159 | .enable_mask = BIT(0), | |
160 | .owner = THIS_MODULE, | |
161 | }, { | |
162 | .name = "LDO_REG2", | |
b8074eba | 163 | .supply_name = "vcc6", |
2cd64ae3 CZ |
164 | .id = RK808_ID_LDO2, |
165 | .ops = &rk808_reg_ops, | |
166 | .type = REGULATOR_VOLTAGE, | |
167 | .n_voltages = 17, | |
168 | .linear_ranges = rk808_ldo_voltage_ranges, | |
169 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo_voltage_ranges), | |
170 | .vsel_reg = RK808_LDO2_ON_VSEL_REG, | |
171 | .vsel_mask = RK808_LDO_VSEL_MASK, | |
172 | .enable_reg = RK808_LDO_EN_REG, | |
173 | .enable_mask = BIT(1), | |
174 | .owner = THIS_MODULE, | |
175 | }, { | |
176 | .name = "LDO_REG3", | |
b8074eba | 177 | .supply_name = "vcc7", |
2cd64ae3 CZ |
178 | .id = RK808_ID_LDO3, |
179 | .ops = &rk808_reg_ops, | |
180 | .type = REGULATOR_VOLTAGE, | |
181 | .n_voltages = 16, | |
182 | .linear_ranges = rk808_ldo3_voltage_ranges, | |
183 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo3_voltage_ranges), | |
184 | .vsel_reg = RK808_LDO3_ON_VSEL_REG, | |
185 | .vsel_mask = RK808_BUCK4_VSEL_MASK, | |
186 | .enable_reg = RK808_LDO_EN_REG, | |
187 | .enable_mask = BIT(2), | |
188 | .owner = THIS_MODULE, | |
189 | }, { | |
190 | .name = "LDO_REG4", | |
b8074eba | 191 | .supply_name = "vcc9", |
2cd64ae3 CZ |
192 | .id = RK808_ID_LDO4, |
193 | .ops = &rk808_reg_ops, | |
194 | .type = REGULATOR_VOLTAGE, | |
195 | .n_voltages = 17, | |
196 | .linear_ranges = rk808_ldo_voltage_ranges, | |
197 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo_voltage_ranges), | |
198 | .vsel_reg = RK808_LDO4_ON_VSEL_REG, | |
199 | .vsel_mask = RK808_LDO_VSEL_MASK, | |
200 | .enable_reg = RK808_LDO_EN_REG, | |
201 | .enable_mask = BIT(3), | |
202 | .owner = THIS_MODULE, | |
203 | }, { | |
204 | .name = "LDO_REG5", | |
b8074eba | 205 | .supply_name = "vcc9", |
2cd64ae3 CZ |
206 | .id = RK808_ID_LDO5, |
207 | .ops = &rk808_reg_ops, | |
208 | .type = REGULATOR_VOLTAGE, | |
209 | .n_voltages = 17, | |
210 | .linear_ranges = rk808_ldo_voltage_ranges, | |
211 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo_voltage_ranges), | |
212 | .vsel_reg = RK808_LDO5_ON_VSEL_REG, | |
213 | .vsel_mask = RK808_LDO_VSEL_MASK, | |
214 | .enable_reg = RK808_LDO_EN_REG, | |
215 | .enable_mask = BIT(4), | |
216 | .owner = THIS_MODULE, | |
217 | }, { | |
218 | .name = "LDO_REG6", | |
b8074eba | 219 | .supply_name = "vcc10", |
2cd64ae3 CZ |
220 | .id = RK808_ID_LDO6, |
221 | .ops = &rk808_reg_ops, | |
222 | .type = REGULATOR_VOLTAGE, | |
223 | .n_voltages = 18, | |
224 | .linear_ranges = rk808_ldo6_voltage_ranges, | |
225 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo6_voltage_ranges), | |
226 | .vsel_reg = RK808_LDO6_ON_VSEL_REG, | |
227 | .vsel_mask = RK808_LDO_VSEL_MASK, | |
228 | .enable_reg = RK808_LDO_EN_REG, | |
229 | .enable_mask = BIT(5), | |
230 | .owner = THIS_MODULE, | |
231 | }, { | |
232 | .name = "LDO_REG7", | |
b8074eba | 233 | .supply_name = "vcc7", |
2cd64ae3 CZ |
234 | .id = RK808_ID_LDO7, |
235 | .ops = &rk808_reg_ops, | |
236 | .type = REGULATOR_VOLTAGE, | |
237 | .n_voltages = 18, | |
238 | .linear_ranges = rk808_ldo6_voltage_ranges, | |
239 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo6_voltage_ranges), | |
240 | .vsel_reg = RK808_LDO7_ON_VSEL_REG, | |
241 | .vsel_mask = RK808_LDO_VSEL_MASK, | |
242 | .enable_reg = RK808_LDO_EN_REG, | |
243 | .enable_mask = BIT(6), | |
244 | .owner = THIS_MODULE, | |
245 | }, { | |
246 | .name = "LDO_REG8", | |
b8074eba | 247 | .supply_name = "vcc11", |
2cd64ae3 CZ |
248 | .id = RK808_ID_LDO8, |
249 | .ops = &rk808_reg_ops, | |
250 | .type = REGULATOR_VOLTAGE, | |
251 | .n_voltages = 17, | |
252 | .linear_ranges = rk808_ldo_voltage_ranges, | |
253 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo_voltage_ranges), | |
254 | .vsel_reg = RK808_LDO8_ON_VSEL_REG, | |
255 | .vsel_mask = RK808_LDO_VSEL_MASK, | |
256 | .enable_reg = RK808_LDO_EN_REG, | |
257 | .enable_mask = BIT(7), | |
258 | .owner = THIS_MODULE, | |
259 | }, { | |
260 | .name = "SWITCH_REG1", | |
b8074eba | 261 | .supply_name = "vcc8", |
2cd64ae3 CZ |
262 | .id = RK808_ID_SWITCH1, |
263 | .ops = &rk808_switch_ops, | |
264 | .type = REGULATOR_VOLTAGE, | |
265 | .enable_reg = RK808_DCDC_EN_REG, | |
266 | .enable_mask = BIT(5), | |
267 | .owner = THIS_MODULE, | |
268 | }, { | |
269 | .name = "SWITCH_REG2", | |
b8074eba | 270 | .supply_name = "vcc12", |
2cd64ae3 CZ |
271 | .id = RK808_ID_SWITCH2, |
272 | .ops = &rk808_switch_ops, | |
273 | .type = REGULATOR_VOLTAGE, | |
274 | .enable_reg = RK808_DCDC_EN_REG, | |
275 | .enable_mask = BIT(6), | |
276 | .owner = THIS_MODULE, | |
277 | }, | |
278 | }; | |
279 | ||
280 | static struct of_regulator_match rk808_reg_matches[] = { | |
281 | [RK808_ID_DCDC1] = { .name = "DCDC_REG1" }, | |
282 | [RK808_ID_DCDC2] = { .name = "DCDC_REG2" }, | |
283 | [RK808_ID_DCDC3] = { .name = "DCDC_REG3" }, | |
284 | [RK808_ID_DCDC4] = { .name = "DCDC_REG4" }, | |
285 | [RK808_ID_LDO1] = { .name = "LDO_REG1" }, | |
286 | [RK808_ID_LDO2] = { .name = "LDO_REG2" }, | |
287 | [RK808_ID_LDO3] = { .name = "LDO_REG3" }, | |
288 | [RK808_ID_LDO4] = { .name = "LDO_REG4" }, | |
289 | [RK808_ID_LDO5] = { .name = "LDO_REG5" }, | |
290 | [RK808_ID_LDO6] = { .name = "LDO_REG6" }, | |
291 | [RK808_ID_LDO7] = { .name = "LDO_REG7" }, | |
292 | [RK808_ID_LDO8] = { .name = "LDO_REG8" }, | |
293 | [RK808_ID_SWITCH1] = { .name = "SWITCH_REG1" }, | |
294 | [RK808_ID_SWITCH2] = { .name = "SWITCH_REG2" }, | |
295 | }; | |
296 | ||
2cd64ae3 CZ |
297 | static int rk808_regulator_probe(struct platform_device *pdev) |
298 | { | |
299 | struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent); | |
d76c333e | 300 | struct i2c_client *client = rk808->i2c; |
571a4010 | 301 | struct device_node *reg_np; |
462004f1 | 302 | struct regulator_config config = {}; |
2cd64ae3 | 303 | struct regulator_dev *rk808_rdev; |
571a4010 | 304 | int ret, i; |
2cd64ae3 | 305 | |
571a4010 CZ |
306 | reg_np = of_get_child_by_name(client->dev.of_node, "regulators"); |
307 | if (!reg_np) | |
308 | return -ENXIO; | |
2cd64ae3 | 309 | |
571a4010 CZ |
310 | ret = of_regulator_match(&client->dev, reg_np, rk808_reg_matches, |
311 | RK808_NUM_REGULATORS); | |
312 | if (ret < 0) | |
2cd64ae3 CZ |
313 | return ret; |
314 | ||
2cd64ae3 CZ |
315 | /* Instantiate the regulators */ |
316 | for (i = 0; i < RK808_NUM_REGULATORS; i++) { | |
571a4010 CZ |
317 | if (!rk808_reg_matches[i].init_data || |
318 | !rk808_reg_matches[i].of_node) | |
2cd64ae3 CZ |
319 | continue; |
320 | ||
d76c333e | 321 | config.dev = &client->dev; |
2cd64ae3 CZ |
322 | config.driver_data = rk808; |
323 | config.regmap = rk808->regmap; | |
571a4010 CZ |
324 | config.of_node = rk808_reg_matches[i].of_node; |
325 | config.init_data = rk808_reg_matches[i].init_data; | |
2cd64ae3 CZ |
326 | |
327 | rk808_rdev = devm_regulator_register(&pdev->dev, | |
328 | &rk808_reg[i], &config); | |
329 | if (IS_ERR(rk808_rdev)) { | |
d76c333e | 330 | dev_err(&client->dev, |
2cd64ae3 CZ |
331 | "failed to register %d regulator\n", i); |
332 | return PTR_ERR(rk808_rdev); | |
333 | } | |
2cd64ae3 | 334 | } |
571a4010 | 335 | |
2cd64ae3 CZ |
336 | return 0; |
337 | } | |
338 | ||
339 | static struct platform_driver rk808_regulator_driver = { | |
340 | .probe = rk808_regulator_probe, | |
341 | .driver = { | |
342 | .name = "rk808-regulator", | |
343 | .owner = THIS_MODULE, | |
344 | }, | |
345 | }; | |
346 | ||
347 | module_platform_driver(rk808_regulator_driver); | |
348 | ||
349 | MODULE_DESCRIPTION("regulator driver for the rk808 series PMICs"); | |
350 | MODULE_AUTHOR("Chris Zhong<zyw@rock-chips.com>"); | |
571a4010 | 351 | MODULE_AUTHOR("Zhang Qing<zhangqing@rock-chips.com>"); |
2cd64ae3 CZ |
352 | MODULE_LICENSE("GPL"); |
353 | MODULE_ALIAS("platform:rk808-regulator"); |