]>
Commit | Line | Data |
---|---|---|
cb74685e SK |
1 | /* |
2 | * s2mps11.c | |
3 | * | |
4 | * Copyright (c) 2012 Samsung Electronics Co., Ltd | |
5 | * http://www.samsung.com | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2 of the License, or (at your | |
10 | * option) any later version. | |
11 | * | |
12 | */ | |
13 | ||
14 | #include <linux/bug.h> | |
cb74685e SK |
15 | #include <linux/err.h> |
16 | #include <linux/gpio.h> | |
17 | #include <linux/slab.h> | |
18 | #include <linux/module.h> | |
19 | #include <linux/platform_device.h> | |
20 | #include <linux/regulator/driver.h> | |
21 | #include <linux/regulator/machine.h> | |
22 | #include <linux/mfd/samsung/core.h> | |
23 | #include <linux/mfd/samsung/s2mps11.h> | |
24 | ||
25 | struct s2mps11_info { | |
ad46ed14 | 26 | struct regulator_dev *rdev[S2MPS11_REGULATOR_MAX]; |
cb74685e SK |
27 | |
28 | int ramp_delay2; | |
29 | int ramp_delay34; | |
30 | int ramp_delay5; | |
31 | int ramp_delay16; | |
32 | int ramp_delay7810; | |
33 | int ramp_delay9; | |
34 | ||
35 | bool buck6_ramp; | |
36 | bool buck2_ramp; | |
37 | bool buck3_ramp; | |
38 | bool buck4_ramp; | |
39 | }; | |
40 | ||
41 | static int get_ramp_delay(int ramp_delay) | |
42 | { | |
43 | unsigned char cnt = 0; | |
44 | ||
90068348 | 45 | ramp_delay /= 6250; |
cb74685e SK |
46 | |
47 | while (true) { | |
48 | ramp_delay = ramp_delay >> 1; | |
49 | if (ramp_delay == 0) | |
50 | break; | |
51 | cnt++; | |
52 | } | |
53 | return cnt; | |
54 | } | |
55 | ||
56 | static struct regulator_ops s2mps11_ldo_ops = { | |
57 | .list_voltage = regulator_list_voltage_linear, | |
58 | .map_voltage = regulator_map_voltage_linear, | |
59 | .is_enabled = regulator_is_enabled_regmap, | |
60 | .enable = regulator_enable_regmap, | |
61 | .disable = regulator_disable_regmap, | |
62 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | |
63 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | |
64 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | |
65 | }; | |
66 | ||
67 | static struct regulator_ops s2mps11_buck_ops = { | |
68 | .list_voltage = regulator_list_voltage_linear, | |
69 | .map_voltage = regulator_map_voltage_linear, | |
70 | .is_enabled = regulator_is_enabled_regmap, | |
71 | .enable = regulator_enable_regmap, | |
72 | .disable = regulator_disable_regmap, | |
73 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | |
74 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | |
75 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | |
76 | }; | |
77 | ||
78 | #define regulator_desc_ldo1(num) { \ | |
79 | .name = "LDO"#num, \ | |
80 | .id = S2MPS11_LDO##num, \ | |
81 | .ops = &s2mps11_ldo_ops, \ | |
82 | .type = REGULATOR_VOLTAGE, \ | |
83 | .owner = THIS_MODULE, \ | |
84 | .min_uV = S2MPS11_LDO_MIN, \ | |
85 | .uV_step = S2MPS11_LDO_STEP1, \ | |
86 | .n_voltages = S2MPS11_LDO_N_VOLTAGES, \ | |
87 | .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \ | |
2693fcab | 88 | .vsel_mask = S2MPS11_LDO_VSEL_MASK, \ |
cb74685e SK |
89 | .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
90 | .enable_mask = S2MPS11_ENABLE_MASK \ | |
91 | } | |
92 | #define regulator_desc_ldo2(num) { \ | |
93 | .name = "LDO"#num, \ | |
94 | .id = S2MPS11_LDO##num, \ | |
95 | .ops = &s2mps11_ldo_ops, \ | |
96 | .type = REGULATOR_VOLTAGE, \ | |
97 | .owner = THIS_MODULE, \ | |
98 | .min_uV = S2MPS11_LDO_MIN, \ | |
99 | .uV_step = S2MPS11_LDO_STEP2, \ | |
100 | .n_voltages = S2MPS11_LDO_N_VOLTAGES, \ | |
101 | .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \ | |
2693fcab | 102 | .vsel_mask = S2MPS11_LDO_VSEL_MASK, \ |
cb74685e SK |
103 | .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \ |
104 | .enable_mask = S2MPS11_ENABLE_MASK \ | |
105 | } | |
106 | ||
107 | #define regulator_desc_buck1_4(num) { \ | |
108 | .name = "BUCK"#num, \ | |
109 | .id = S2MPS11_BUCK##num, \ | |
110 | .ops = &s2mps11_buck_ops, \ | |
111 | .type = REGULATOR_VOLTAGE, \ | |
112 | .owner = THIS_MODULE, \ | |
113 | .min_uV = S2MPS11_BUCK_MIN1, \ | |
114 | .uV_step = S2MPS11_BUCK_STEP1, \ | |
115 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ | |
90068348 | 116 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
cb74685e | 117 | .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \ |
2693fcab | 118 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
cb74685e SK |
119 | .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \ |
120 | .enable_mask = S2MPS11_ENABLE_MASK \ | |
121 | } | |
122 | ||
123 | #define regulator_desc_buck5 { \ | |
124 | .name = "BUCK5", \ | |
125 | .id = S2MPS11_BUCK5, \ | |
126 | .ops = &s2mps11_buck_ops, \ | |
127 | .type = REGULATOR_VOLTAGE, \ | |
128 | .owner = THIS_MODULE, \ | |
129 | .min_uV = S2MPS11_BUCK_MIN1, \ | |
130 | .uV_step = S2MPS11_BUCK_STEP1, \ | |
131 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ | |
90068348 | 132 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
cb74685e | 133 | .vsel_reg = S2MPS11_REG_B5CTRL2, \ |
2693fcab | 134 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
cb74685e SK |
135 | .enable_reg = S2MPS11_REG_B5CTRL1, \ |
136 | .enable_mask = S2MPS11_ENABLE_MASK \ | |
137 | } | |
138 | ||
139 | #define regulator_desc_buck6_8(num) { \ | |
140 | .name = "BUCK"#num, \ | |
141 | .id = S2MPS11_BUCK##num, \ | |
142 | .ops = &s2mps11_buck_ops, \ | |
143 | .type = REGULATOR_VOLTAGE, \ | |
144 | .owner = THIS_MODULE, \ | |
145 | .min_uV = S2MPS11_BUCK_MIN1, \ | |
146 | .uV_step = S2MPS11_BUCK_STEP1, \ | |
147 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ | |
90068348 | 148 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
cb74685e | 149 | .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \ |
2693fcab | 150 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
cb74685e SK |
151 | .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \ |
152 | .enable_mask = S2MPS11_ENABLE_MASK \ | |
153 | } | |
154 | ||
155 | #define regulator_desc_buck9 { \ | |
156 | .name = "BUCK9", \ | |
157 | .id = S2MPS11_BUCK9, \ | |
158 | .ops = &s2mps11_buck_ops, \ | |
159 | .type = REGULATOR_VOLTAGE, \ | |
160 | .owner = THIS_MODULE, \ | |
161 | .min_uV = S2MPS11_BUCK_MIN3, \ | |
162 | .uV_step = S2MPS11_BUCK_STEP3, \ | |
163 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ | |
90068348 | 164 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
cb74685e | 165 | .vsel_reg = S2MPS11_REG_B9CTRL2, \ |
2693fcab | 166 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
cb74685e SK |
167 | .enable_reg = S2MPS11_REG_B9CTRL1, \ |
168 | .enable_mask = S2MPS11_ENABLE_MASK \ | |
169 | } | |
170 | ||
171 | #define regulator_desc_buck10 { \ | |
172 | .name = "BUCK10", \ | |
173 | .id = S2MPS11_BUCK10, \ | |
174 | .ops = &s2mps11_buck_ops, \ | |
175 | .type = REGULATOR_VOLTAGE, \ | |
176 | .owner = THIS_MODULE, \ | |
177 | .min_uV = S2MPS11_BUCK_MIN2, \ | |
178 | .uV_step = S2MPS11_BUCK_STEP2, \ | |
179 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ | |
90068348 | 180 | .ramp_delay = S2MPS11_RAMP_DELAY, \ |
c76edd52 | 181 | .vsel_reg = S2MPS11_REG_B10CTRL2, \ |
2693fcab | 182 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ |
c76edd52 | 183 | .enable_reg = S2MPS11_REG_B10CTRL1, \ |
cb74685e SK |
184 | .enable_mask = S2MPS11_ENABLE_MASK \ |
185 | } | |
186 | ||
187 | static struct regulator_desc regulators[] = { | |
188 | regulator_desc_ldo2(1), | |
189 | regulator_desc_ldo1(2), | |
190 | regulator_desc_ldo1(3), | |
191 | regulator_desc_ldo1(4), | |
192 | regulator_desc_ldo1(5), | |
193 | regulator_desc_ldo2(6), | |
194 | regulator_desc_ldo1(7), | |
195 | regulator_desc_ldo1(8), | |
196 | regulator_desc_ldo1(9), | |
197 | regulator_desc_ldo1(10), | |
198 | regulator_desc_ldo2(11), | |
199 | regulator_desc_ldo1(12), | |
200 | regulator_desc_ldo1(13), | |
201 | regulator_desc_ldo1(14), | |
202 | regulator_desc_ldo1(15), | |
203 | regulator_desc_ldo1(16), | |
204 | regulator_desc_ldo1(17), | |
205 | regulator_desc_ldo1(18), | |
206 | regulator_desc_ldo1(19), | |
207 | regulator_desc_ldo1(20), | |
208 | regulator_desc_ldo1(21), | |
209 | regulator_desc_ldo2(22), | |
210 | regulator_desc_ldo2(23), | |
211 | regulator_desc_ldo1(24), | |
212 | regulator_desc_ldo1(25), | |
213 | regulator_desc_ldo1(26), | |
214 | regulator_desc_ldo2(27), | |
215 | regulator_desc_ldo1(28), | |
216 | regulator_desc_ldo1(29), | |
217 | regulator_desc_ldo1(30), | |
218 | regulator_desc_ldo1(31), | |
219 | regulator_desc_ldo1(32), | |
220 | regulator_desc_ldo1(33), | |
221 | regulator_desc_ldo1(34), | |
222 | regulator_desc_ldo1(35), | |
223 | regulator_desc_ldo1(36), | |
224 | regulator_desc_ldo1(37), | |
225 | regulator_desc_ldo1(38), | |
226 | regulator_desc_buck1_4(1), | |
227 | regulator_desc_buck1_4(2), | |
228 | regulator_desc_buck1_4(3), | |
229 | regulator_desc_buck1_4(4), | |
230 | regulator_desc_buck5, | |
231 | regulator_desc_buck6_8(6), | |
232 | regulator_desc_buck6_8(7), | |
233 | regulator_desc_buck6_8(8), | |
234 | regulator_desc_buck9, | |
235 | regulator_desc_buck10, | |
236 | }; | |
237 | ||
a5023574 | 238 | static int s2mps11_pmic_probe(struct platform_device *pdev) |
cb74685e SK |
239 | { |
240 | struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); | |
241 | struct sec_platform_data *pdata = dev_get_platdata(iodev->dev); | |
242 | struct regulator_config config = { }; | |
cb74685e | 243 | struct s2mps11_info *s2mps11; |
ad46ed14 | 244 | int i, ret; |
cb74685e SK |
245 | unsigned char ramp_enable, ramp_reg = 0; |
246 | ||
247 | if (!pdata) { | |
248 | dev_err(pdev->dev.parent, "Platform data not supplied\n"); | |
249 | return -ENODEV; | |
250 | } | |
251 | ||
252 | s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info), | |
253 | GFP_KERNEL); | |
254 | if (!s2mps11) | |
255 | return -ENOMEM; | |
256 | ||
cb74685e SK |
257 | platform_set_drvdata(pdev, s2mps11); |
258 | ||
259 | s2mps11->ramp_delay2 = pdata->buck2_ramp_delay; | |
260 | s2mps11->ramp_delay34 = pdata->buck34_ramp_delay; | |
261 | s2mps11->ramp_delay5 = pdata->buck5_ramp_delay; | |
262 | s2mps11->ramp_delay16 = pdata->buck16_ramp_delay; | |
263 | s2mps11->ramp_delay7810 = pdata->buck7810_ramp_delay; | |
264 | s2mps11->ramp_delay9 = pdata->buck9_ramp_delay; | |
265 | ||
266 | s2mps11->buck6_ramp = pdata->buck6_ramp_enable; | |
267 | s2mps11->buck2_ramp = pdata->buck2_ramp_enable; | |
268 | s2mps11->buck3_ramp = pdata->buck3_ramp_enable; | |
269 | s2mps11->buck4_ramp = pdata->buck4_ramp_enable; | |
270 | ||
271 | ramp_enable = (s2mps11->buck2_ramp << 3) | (s2mps11->buck3_ramp << 2) | | |
272 | (s2mps11->buck4_ramp << 1) | s2mps11->buck6_ramp ; | |
273 | ||
274 | if (ramp_enable) { | |
275 | if (s2mps11->buck2_ramp) | |
f7ebaaeb | 276 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay2) << 6; |
cb74685e | 277 | if (s2mps11->buck3_ramp || s2mps11->buck4_ramp) |
f7ebaaeb | 278 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay34) << 4; |
c06eed39 | 279 | sec_reg_write(iodev, S2MPS11_REG_RAMP, ramp_reg | ramp_enable); |
cb74685e SK |
280 | } |
281 | ||
282 | ramp_reg &= 0x00; | |
f7ebaaeb SK |
283 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay5) << 6; |
284 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay16) << 4; | |
285 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay7810) << 2; | |
cb74685e | 286 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay9); |
c06eed39 | 287 | sec_reg_write(iodev, S2MPS11_REG_RAMP_BUCK, ramp_reg); |
cb74685e SK |
288 | |
289 | for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) { | |
290 | ||
232b2504 | 291 | config.dev = &pdev->dev; |
cb74685e SK |
292 | config.regmap = iodev->regmap; |
293 | config.init_data = pdata->regulators[i].initdata; | |
294 | config.driver_data = s2mps11; | |
295 | ||
ad46ed14 AL |
296 | s2mps11->rdev[i] = regulator_register(®ulators[i], &config); |
297 | if (IS_ERR(s2mps11->rdev[i])) { | |
298 | ret = PTR_ERR(s2mps11->rdev[i]); | |
232b2504 AL |
299 | dev_err(&pdev->dev, "regulator init failed for %d\n", |
300 | i); | |
ad46ed14 | 301 | s2mps11->rdev[i] = NULL; |
cb74685e SK |
302 | goto err; |
303 | } | |
304 | } | |
305 | ||
306 | return 0; | |
307 | err: | |
308 | for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) | |
ad46ed14 | 309 | regulator_unregister(s2mps11->rdev[i]); |
cb74685e SK |
310 | |
311 | return ret; | |
312 | } | |
313 | ||
8dc995f5 | 314 | static int s2mps11_pmic_remove(struct platform_device *pdev) |
cb74685e SK |
315 | { |
316 | struct s2mps11_info *s2mps11 = platform_get_drvdata(pdev); | |
cb74685e SK |
317 | int i; |
318 | ||
319 | for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) | |
ad46ed14 | 320 | regulator_unregister(s2mps11->rdev[i]); |
cb74685e SK |
321 | |
322 | return 0; | |
323 | } | |
324 | ||
325 | static const struct platform_device_id s2mps11_pmic_id[] = { | |
326 | { "s2mps11-pmic", 0}, | |
327 | { }, | |
328 | }; | |
329 | MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id); | |
330 | ||
331 | static struct platform_driver s2mps11_pmic_driver = { | |
332 | .driver = { | |
333 | .name = "s2mps11-pmic", | |
334 | .owner = THIS_MODULE, | |
335 | }, | |
336 | .probe = s2mps11_pmic_probe, | |
5eb9f2b9 | 337 | .remove = s2mps11_pmic_remove, |
cb74685e SK |
338 | .id_table = s2mps11_pmic_id, |
339 | }; | |
340 | ||
341 | static int __init s2mps11_pmic_init(void) | |
342 | { | |
343 | return platform_driver_register(&s2mps11_pmic_driver); | |
344 | } | |
345 | subsys_initcall(s2mps11_pmic_init); | |
346 | ||
347 | static void __exit s2mps11_pmic_exit(void) | |
348 | { | |
349 | platform_driver_unregister(&s2mps11_pmic_driver); | |
350 | } | |
351 | module_exit(s2mps11_pmic_exit); | |
352 | ||
353 | /* Module information */ | |
354 | MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); | |
355 | MODULE_DESCRIPTION("SAMSUNG S2MPS11 Regulator Driver"); | |
356 | MODULE_LICENSE("GPL"); |