blob: 465996da93eae02ab45e47f912b961e840ace401 [file] [log] [blame]
Yann Gautierbb836ee2018-07-16 17:55:07 +02001/*
Yann Gautiera45433b2019-01-16 18:31:00 +01002 * Copyright (c) 2016-2019, STMicroelectronics - All Rights Reserved
Yann Gautierbb836ee2018-07-16 17:55:07 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Yann Gautierbb836ee2018-07-16 17:55:07 +02007#include <string.h>
8
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <common/debug.h>
Yann Gautiera45433b2019-01-16 18:31:00 +010010#include <drivers/st/stpmic1.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011#include <plat/common/platform.h>
12
Yann Gautierbb836ee2018-07-16 17:55:07 +020013struct regul_struct {
14 const char *dt_node_name;
15 const uint16_t *voltage_table;
16 uint8_t voltage_table_size;
17 uint8_t control_reg;
18 uint8_t low_power_reg;
Yann Gautieref85e532019-01-17 14:27:50 +010019 uint8_t pull_down_reg;
20 uint8_t pull_down;
21 uint8_t mask_reset_reg;
22 uint8_t mask_reset;
Yann Gautierbb836ee2018-07-16 17:55:07 +020023};
24
Yann Gautiera45433b2019-01-16 18:31:00 +010025static struct i2c_handle_s *pmic_i2c_handle;
26static uint16_t pmic_i2c_addr;
Yann Gautierbb836ee2018-07-16 17:55:07 +020027
28/* Voltage tables in mV */
29static const uint16_t buck1_voltage_table[] = {
Yann Gautieref85e532019-01-17 14:27:50 +010030 725,
31 725,
32 725,
33 725,
34 725,
Yann Gautierbb836ee2018-07-16 17:55:07 +020035 725,
36 750,
37 775,
38 800,
39 825,
40 850,
41 875,
42 900,
43 925,
44 950,
45 975,
46 1000,
47 1025,
48 1050,
49 1075,
50 1100,
51 1125,
52 1150,
53 1175,
54 1200,
55 1225,
56 1250,
57 1275,
58 1300,
59 1325,
60 1350,
Yann Gautieref85e532019-01-17 14:27:50 +010061 1375,
62 1400,
63 1425,
64 1450,
65 1475,
66 1500,
67 1500,
68 1500,
69 1500,
70 1500,
71 1500,
72 1500,
73 1500,
74 1500,
75 1500,
76 1500,
77 1500,
78 1500,
79 1500,
80 1500,
81 1500,
82 1500,
83 1500,
84 1500,
85 1500,
86 1500,
87 1500,
88 1500,
89 1500,
90 1500,
91 1500,
92 1500,
93 1500,
Yann Gautierbb836ee2018-07-16 17:55:07 +020094};
95
96static const uint16_t buck2_voltage_table[] = {
97 1000,
98 1000,
99 1000,
100 1000,
101 1000,
102 1000,
103 1000,
104 1000,
105 1000,
106 1000,
107 1000,
108 1000,
109 1000,
110 1000,
111 1000,
112 1000,
113 1000,
114 1000,
115 1050,
116 1050,
117 1100,
118 1100,
119 1150,
120 1150,
121 1200,
122 1200,
123 1250,
124 1250,
125 1300,
126 1300,
127 1350,
128 1350,
129 1400,
130 1400,
131 1450,
132 1450,
133 1500,
134};
135
136static const uint16_t buck3_voltage_table[] = {
137 1000,
138 1000,
139 1000,
140 1000,
141 1000,
142 1000,
143 1000,
144 1000,
145 1000,
146 1000,
147 1000,
148 1000,
149 1000,
150 1000,
151 1000,
152 1000,
153 1000,
154 1000,
155 1000,
156 1000,
157 1100,
158 1100,
159 1100,
160 1100,
161 1200,
162 1200,
163 1200,
164 1200,
165 1300,
166 1300,
167 1300,
168 1300,
169 1400,
170 1400,
171 1400,
172 1400,
173 1500,
174 1600,
175 1700,
176 1800,
177 1900,
178 2000,
179 2100,
180 2200,
181 2300,
182 2400,
183 2500,
184 2600,
185 2700,
186 2800,
187 2900,
188 3000,
189 3100,
190 3200,
191 3300,
192 3400,
193};
194
195static const uint16_t buck4_voltage_table[] = {
196 600,
197 625,
198 650,
199 675,
200 700,
201 725,
202 750,
203 775,
204 800,
205 825,
206 850,
207 875,
208 900,
209 925,
210 950,
211 975,
212 1000,
213 1025,
214 1050,
215 1075,
216 1100,
217 1125,
218 1150,
219 1175,
220 1200,
221 1225,
222 1250,
223 1275,
224 1300,
225 1300,
226 1350,
227 1350,
228 1400,
229 1400,
230 1450,
231 1450,
232 1500,
233 1600,
234 1700,
235 1800,
236 1900,
237 2000,
238 2100,
239 2200,
240 2300,
241 2400,
242 2500,
243 2600,
244 2700,
245 2800,
246 2900,
247 3000,
248 3100,
249 3200,
250 3300,
251 3400,
252 3500,
253 3600,
254 3700,
255 3800,
256 3900,
257};
258
259static const uint16_t ldo1_voltage_table[] = {
260 1700,
261 1700,
262 1700,
263 1700,
264 1700,
265 1700,
266 1700,
267 1700,
268 1700,
269 1800,
270 1900,
271 2000,
272 2100,
273 2200,
274 2300,
275 2400,
276 2500,
277 2600,
278 2700,
279 2800,
280 2900,
281 3000,
282 3100,
283 3200,
284 3300,
285};
286
287static const uint16_t ldo2_voltage_table[] = {
288 1700,
289 1700,
290 1700,
291 1700,
292 1700,
293 1700,
294 1700,
295 1700,
296 1700,
297 1800,
298 1900,
299 2000,
300 2100,
301 2200,
302 2300,
303 2400,
304 2500,
305 2600,
306 2700,
307 2800,
308 2900,
309 3000,
310 3100,
311 3200,
312 3300,
313};
314
315static const uint16_t ldo3_voltage_table[] = {
316 1700,
317 1700,
318 1700,
319 1700,
320 1700,
321 1700,
322 1700,
323 1700,
324 1700,
325 1800,
326 1900,
327 2000,
328 2100,
329 2200,
330 2300,
331 2400,
332 2500,
333 2600,
334 2700,
335 2800,
336 2900,
337 3000,
338 3100,
339 3200,
340 3300,
341 3300,
342 3300,
343 3300,
344 3300,
345 3300,
346 3300,
Yann Gautieref85e532019-01-17 14:27:50 +0100347 500,
Yann Gautierbb836ee2018-07-16 17:55:07 +0200348 0xFFFF, /* VREFDDR */
349};
350
351static const uint16_t ldo5_voltage_table[] = {
352 1700,
353 1700,
354 1700,
355 1700,
356 1700,
357 1700,
358 1700,
359 1700,
360 1700,
361 1800,
362 1900,
363 2000,
364 2100,
365 2200,
366 2300,
367 2400,
368 2500,
369 2600,
370 2700,
371 2800,
372 2900,
373 3000,
374 3100,
375 3200,
376 3300,
377 3400,
378 3500,
379 3600,
380 3700,
381 3800,
382 3900,
383};
384
385static const uint16_t ldo6_voltage_table[] = {
386 900,
387 1000,
388 1100,
389 1200,
390 1300,
391 1400,
392 1500,
393 1600,
394 1700,
395 1800,
396 1900,
397 2000,
398 2100,
399 2200,
400 2300,
401 2400,
402 2500,
403 2600,
404 2700,
405 2800,
406 2900,
407 3000,
408 3100,
409 3200,
410 3300,
411};
412
413static const uint16_t ldo4_voltage_table[] = {
414 3300,
415};
416
417static const uint16_t vref_ddr_voltage_table[] = {
418 3300,
419};
420
421/* Table of Regulators in PMIC SoC */
422static const struct regul_struct regulators_table[] = {
423 {
424 .dt_node_name = "buck1",
425 .voltage_table = buck1_voltage_table,
426 .voltage_table_size = ARRAY_SIZE(buck1_voltage_table),
427 .control_reg = BUCK1_CONTROL_REG,
428 .low_power_reg = BUCK1_PWRCTRL_REG,
Yann Gautieref85e532019-01-17 14:27:50 +0100429 .pull_down_reg = BUCK_PULL_DOWN_REG,
430 .pull_down = BUCK1_PULL_DOWN_SHIFT,
431 .mask_reset_reg = MASK_RESET_BUCK_REG,
432 .mask_reset = BUCK1_MASK_RESET,
Yann Gautierbb836ee2018-07-16 17:55:07 +0200433 },
434 {
435 .dt_node_name = "buck2",
436 .voltage_table = buck2_voltage_table,
437 .voltage_table_size = ARRAY_SIZE(buck2_voltage_table),
438 .control_reg = BUCK2_CONTROL_REG,
439 .low_power_reg = BUCK2_PWRCTRL_REG,
Yann Gautieref85e532019-01-17 14:27:50 +0100440 .pull_down_reg = BUCK_PULL_DOWN_REG,
441 .pull_down = BUCK2_PULL_DOWN_SHIFT,
442 .mask_reset_reg = MASK_RESET_BUCK_REG,
443 .mask_reset = BUCK2_MASK_RESET,
Yann Gautierbb836ee2018-07-16 17:55:07 +0200444 },
445 {
446 .dt_node_name = "buck3",
447 .voltage_table = buck3_voltage_table,
448 .voltage_table_size = ARRAY_SIZE(buck3_voltage_table),
449 .control_reg = BUCK3_CONTROL_REG,
450 .low_power_reg = BUCK3_PWRCTRL_REG,
Yann Gautieref85e532019-01-17 14:27:50 +0100451 .pull_down_reg = BUCK_PULL_DOWN_REG,
452 .pull_down = BUCK3_PULL_DOWN_SHIFT,
453 .mask_reset_reg = MASK_RESET_BUCK_REG,
454 .mask_reset = BUCK3_MASK_RESET,
Yann Gautierbb836ee2018-07-16 17:55:07 +0200455 },
456 {
457 .dt_node_name = "buck4",
458 .voltage_table = buck4_voltage_table,
459 .voltage_table_size = ARRAY_SIZE(buck4_voltage_table),
460 .control_reg = BUCK4_CONTROL_REG,
461 .low_power_reg = BUCK4_PWRCTRL_REG,
Yann Gautieref85e532019-01-17 14:27:50 +0100462 .pull_down_reg = BUCK_PULL_DOWN_REG,
463 .pull_down = BUCK4_PULL_DOWN_SHIFT,
464 .mask_reset_reg = MASK_RESET_BUCK_REG,
465 .mask_reset = BUCK4_MASK_RESET,
Yann Gautierbb836ee2018-07-16 17:55:07 +0200466 },
467 {
468 .dt_node_name = "ldo1",
469 .voltage_table = ldo1_voltage_table,
470 .voltage_table_size = ARRAY_SIZE(ldo1_voltage_table),
471 .control_reg = LDO1_CONTROL_REG,
472 .low_power_reg = LDO1_PWRCTRL_REG,
Yann Gautieref85e532019-01-17 14:27:50 +0100473 .mask_reset_reg = MASK_RESET_LDO_REG,
474 .mask_reset = LDO1_MASK_RESET,
Yann Gautierbb836ee2018-07-16 17:55:07 +0200475 },
476 {
477 .dt_node_name = "ldo2",
478 .voltage_table = ldo2_voltage_table,
479 .voltage_table_size = ARRAY_SIZE(ldo2_voltage_table),
480 .control_reg = LDO2_CONTROL_REG,
481 .low_power_reg = LDO2_PWRCTRL_REG,
Yann Gautieref85e532019-01-17 14:27:50 +0100482 .mask_reset_reg = MASK_RESET_LDO_REG,
483 .mask_reset = LDO2_MASK_RESET,
Yann Gautierbb836ee2018-07-16 17:55:07 +0200484 },
485 {
486 .dt_node_name = "ldo3",
487 .voltage_table = ldo3_voltage_table,
488 .voltage_table_size = ARRAY_SIZE(ldo3_voltage_table),
489 .control_reg = LDO3_CONTROL_REG,
490 .low_power_reg = LDO3_PWRCTRL_REG,
Yann Gautieref85e532019-01-17 14:27:50 +0100491 .mask_reset_reg = MASK_RESET_LDO_REG,
492 .mask_reset = LDO3_MASK_RESET,
Yann Gautierbb836ee2018-07-16 17:55:07 +0200493 },
494 {
495 .dt_node_name = "ldo4",
496 .voltage_table = ldo4_voltage_table,
497 .voltage_table_size = ARRAY_SIZE(ldo4_voltage_table),
498 .control_reg = LDO4_CONTROL_REG,
499 .low_power_reg = LDO4_PWRCTRL_REG,
Yann Gautieref85e532019-01-17 14:27:50 +0100500 .mask_reset_reg = MASK_RESET_LDO_REG,
501 .mask_reset = LDO4_MASK_RESET,
Yann Gautierbb836ee2018-07-16 17:55:07 +0200502 },
503 {
504 .dt_node_name = "ldo5",
505 .voltage_table = ldo5_voltage_table,
506 .voltage_table_size = ARRAY_SIZE(ldo5_voltage_table),
507 .control_reg = LDO5_CONTROL_REG,
508 .low_power_reg = LDO5_PWRCTRL_REG,
Yann Gautieref85e532019-01-17 14:27:50 +0100509 .mask_reset_reg = MASK_RESET_LDO_REG,
510 .mask_reset = LDO5_MASK_RESET,
Yann Gautierbb836ee2018-07-16 17:55:07 +0200511 },
512 {
513 .dt_node_name = "ldo6",
514 .voltage_table = ldo6_voltage_table,
515 .voltage_table_size = ARRAY_SIZE(ldo6_voltage_table),
516 .control_reg = LDO6_CONTROL_REG,
517 .low_power_reg = LDO6_PWRCTRL_REG,
Yann Gautieref85e532019-01-17 14:27:50 +0100518 .mask_reset_reg = MASK_RESET_LDO_REG,
519 .mask_reset = LDO6_MASK_RESET,
Yann Gautierbb836ee2018-07-16 17:55:07 +0200520 },
521 {
522 .dt_node_name = "vref_ddr",
523 .voltage_table = vref_ddr_voltage_table,
524 .voltage_table_size = ARRAY_SIZE(vref_ddr_voltage_table),
525 .control_reg = VREF_DDR_CONTROL_REG,
526 .low_power_reg = VREF_DDR_PWRCTRL_REG,
Yann Gautieref85e532019-01-17 14:27:50 +0100527 .mask_reset_reg = MASK_RESET_LDO_REG,
528 .mask_reset = VREF_DDR_MASK_RESET,
Yann Gautierbb836ee2018-07-16 17:55:07 +0200529 },
530};
531
Yann Gautiera45433b2019-01-16 18:31:00 +0100532#define MAX_REGUL ARRAY_SIZE(regulators_table)
Yann Gautierbb836ee2018-07-16 17:55:07 +0200533
Yann Gautiera45433b2019-01-16 18:31:00 +0100534static const struct regul_struct *get_regulator_data(const char *name)
Yann Gautierbb836ee2018-07-16 17:55:07 +0200535{
536 uint8_t i;
537
538 for (i = 0 ; i < MAX_REGUL ; i++) {
539 if (strncmp(name, regulators_table[i].dt_node_name,
540 strlen(regulators_table[i].dt_node_name)) == 0) {
541 return &regulators_table[i];
542 }
543 }
544
545 /* Regulator not found */
546 panic();
547 return NULL;
548}
549
Yann Gautiera45433b2019-01-16 18:31:00 +0100550static uint8_t voltage_to_index(const char *name, uint16_t millivolts)
Yann Gautierbb836ee2018-07-16 17:55:07 +0200551{
Yann Gautiera45433b2019-01-16 18:31:00 +0100552 const struct regul_struct *regul = get_regulator_data(name);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200553 uint8_t i;
554
555 for (i = 0 ; i < regul->voltage_table_size ; i++) {
556 if (regul->voltage_table[i] == millivolts) {
557 return i;
558 }
559 }
560
561 /* Voltage not found */
562 panic();
563
564 return 0;
565}
566
Yann Gautieref85e532019-01-17 14:27:50 +0100567int stpmic1_powerctrl_on(void)
568{
569 return stpmic1_register_update(MAIN_CONTROL_REG, PWRCTRL_PIN_VALID,
570 PWRCTRL_PIN_VALID);
571}
572
Yann Gautiera45433b2019-01-16 18:31:00 +0100573int stpmic1_switch_off(void)
Yann Gautierbb836ee2018-07-16 17:55:07 +0200574{
Yann Gautiera45433b2019-01-16 18:31:00 +0100575 return stpmic1_register_update(MAIN_CONTROL_REG, 1,
576 SOFTWARE_SWITCH_OFF_ENABLED);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200577}
578
Yann Gautiera45433b2019-01-16 18:31:00 +0100579int stpmic1_regulator_enable(const char *name)
Yann Gautierbb836ee2018-07-16 17:55:07 +0200580{
Yann Gautiera45433b2019-01-16 18:31:00 +0100581 const struct regul_struct *regul = get_regulator_data(name);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200582
Yann Gautiera45433b2019-01-16 18:31:00 +0100583 return stpmic1_register_update(regul->control_reg, BIT(0), BIT(0));
Yann Gautierbb836ee2018-07-16 17:55:07 +0200584}
585
Yann Gautiera45433b2019-01-16 18:31:00 +0100586int stpmic1_regulator_disable(const char *name)
Yann Gautierbb836ee2018-07-16 17:55:07 +0200587{
Yann Gautiera45433b2019-01-16 18:31:00 +0100588 const struct regul_struct *regul = get_regulator_data(name);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200589
Yann Gautiera45433b2019-01-16 18:31:00 +0100590 return stpmic1_register_update(regul->control_reg, 0, BIT(0));
Yann Gautierbb836ee2018-07-16 17:55:07 +0200591}
592
Yann Gautiera45433b2019-01-16 18:31:00 +0100593uint8_t stpmic1_is_regulator_enabled(const char *name)
Yann Gautierbb836ee2018-07-16 17:55:07 +0200594{
595 uint8_t val;
Yann Gautiera45433b2019-01-16 18:31:00 +0100596 const struct regul_struct *regul = get_regulator_data(name);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200597
Yann Gautiera45433b2019-01-16 18:31:00 +0100598 if (stpmic1_register_read(regul->control_reg, &val) != 0) {
Yann Gautierbb836ee2018-07-16 17:55:07 +0200599 panic();
600 }
601
602 return (val & 0x1U);
603}
604
Yann Gautiera45433b2019-01-16 18:31:00 +0100605int stpmic1_regulator_voltage_set(const char *name, uint16_t millivolts)
Yann Gautierbb836ee2018-07-16 17:55:07 +0200606{
Yann Gautiera45433b2019-01-16 18:31:00 +0100607 uint8_t voltage_index = voltage_to_index(name, millivolts);
608 const struct regul_struct *regul = get_regulator_data(name);
Yann Gautieref85e532019-01-17 14:27:50 +0100609 uint8_t mask;
610
611 /* Voltage can be set for buck<N> or ldo<N> (except ldo4) regulators */
612 if (strncmp(name, "buck", 4) == 0) {
613 mask = BUCK_VOLTAGE_MASK;
614 } else if ((strncmp(name, "ldo", 3) == 0) &&
615 (strncmp(name, "ldo4", 4) != 0)) {
616 mask = LDO_VOLTAGE_MASK;
617 } else {
618 return 0;
619 }
620
621 return stpmic1_register_update(regul->control_reg,
622 voltage_index << LDO_BUCK_VOLTAGE_SHIFT,
623 mask);
624}
625
626int stpmic1_regulator_pull_down_set(const char *name)
627{
628 const struct regul_struct *regul = get_regulator_data(name);
629
630 if (regul->pull_down_reg != 0) {
631 return stpmic1_register_update(regul->pull_down_reg,
632 BIT(regul->pull_down),
633 LDO_BUCK_PULL_DOWN_MASK <<
634 regul->pull_down);
635 }
636
637 return 0;
638}
639
640int stpmic1_regulator_mask_reset_set(const char *name)
641{
642 const struct regul_struct *regul = get_regulator_data(name);
643
644 return stpmic1_register_update(regul->mask_reset_reg,
645 BIT(regul->mask_reset),
646 LDO_BUCK_RESET_MASK <<
647 regul->mask_reset);
648}
649
650int stpmic1_regulator_voltage_get(const char *name)
651{
652 const struct regul_struct *regul = get_regulator_data(name);
653 uint8_t value;
654 uint8_t mask;
Yann Gautierbb836ee2018-07-16 17:55:07 +0200655
Yann Gautieref85e532019-01-17 14:27:50 +0100656 /* Voltage can be set for buck<N> or ldo<N> (except ldo4) regulators */
657 if (strncmp(name, "buck", 4) == 0) {
658 mask = BUCK_VOLTAGE_MASK;
659 } else if ((strncmp(name, "ldo", 3) == 0) &&
660 (strncmp(name, "ldo4", 4) != 0)) {
661 mask = LDO_VOLTAGE_MASK;
662 } else {
663 return 0;
664 }
665
666 if (stpmic1_register_read(regul->control_reg, &value))
667 return -1;
668
669 value = (value & mask) >> LDO_BUCK_VOLTAGE_SHIFT;
670
671 if (value > regul->voltage_table_size)
672 return -1;
673
674 return (int)regul->voltage_table[value];
Yann Gautierbb836ee2018-07-16 17:55:07 +0200675}
676
Yann Gautiera45433b2019-01-16 18:31:00 +0100677int stpmic1_register_read(uint8_t register_id, uint8_t *value)
Yann Gautierbb836ee2018-07-16 17:55:07 +0200678{
Yann Gautiera45433b2019-01-16 18:31:00 +0100679 return stm32_i2c_mem_read(pmic_i2c_handle, pmic_i2c_addr,
680 (uint16_t)register_id, I2C_MEMADD_SIZE_8BIT,
681 value, 1, 100000);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200682}
683
Yann Gautiera45433b2019-01-16 18:31:00 +0100684int stpmic1_register_write(uint8_t register_id, uint8_t value)
Yann Gautierbb836ee2018-07-16 17:55:07 +0200685{
686 int status;
687
Yann Gautiera45433b2019-01-16 18:31:00 +0100688 status = stm32_i2c_mem_write(pmic_i2c_handle, pmic_i2c_addr,
Yann Gautierbb836ee2018-07-16 17:55:07 +0200689 (uint16_t)register_id,
690 I2C_MEMADD_SIZE_8BIT, &value, 1, 100000);
691
Yann Gautieref85e532019-01-17 14:27:50 +0100692#if ENABLE_ASSERTIONS
Yann Gautierbb836ee2018-07-16 17:55:07 +0200693 if (status != 0) {
694 return status;
695 }
696
697 if ((register_id != WATCHDOG_CONTROL_REG) && (register_id <= 0x40U)) {
698 uint8_t readval;
699
Yann Gautiera45433b2019-01-16 18:31:00 +0100700 status = stpmic1_register_read(register_id, &readval);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200701 if (status != 0) {
702 return status;
703 }
704
705 if (readval != value) {
706 return -1;
707 }
708 }
Yann Gautieref85e532019-01-17 14:27:50 +0100709#endif
Yann Gautierbb836ee2018-07-16 17:55:07 +0200710
Yann Gautieref85e532019-01-17 14:27:50 +0100711 return status;
Yann Gautierbb836ee2018-07-16 17:55:07 +0200712}
713
Yann Gautiera45433b2019-01-16 18:31:00 +0100714int stpmic1_register_update(uint8_t register_id, uint8_t value, uint8_t mask)
Yann Gautierbb836ee2018-07-16 17:55:07 +0200715{
716 int status;
717 uint8_t val;
718
Yann Gautiera45433b2019-01-16 18:31:00 +0100719 status = stpmic1_register_read(register_id, &val);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200720 if (status != 0) {
721 return status;
722 }
723
Yann Gautieref85e532019-01-17 14:27:50 +0100724 val = (val & ~mask) | (value & mask);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200725
Yann Gautiera45433b2019-01-16 18:31:00 +0100726 return stpmic1_register_write(register_id, val);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200727}
728
Yann Gautiera45433b2019-01-16 18:31:00 +0100729void stpmic1_bind_i2c(struct i2c_handle_s *i2c_handle, uint16_t i2c_addr)
Yann Gautierbb836ee2018-07-16 17:55:07 +0200730{
Yann Gautiera45433b2019-01-16 18:31:00 +0100731 pmic_i2c_handle = i2c_handle;
732 pmic_i2c_addr = i2c_addr;
Yann Gautierbb836ee2018-07-16 17:55:07 +0200733}
Yann Gautieref85e532019-01-17 14:27:50 +0100734
735void stpmic1_dump_regulators(void)
736{
737 uint32_t i;
738
739 for (i = 0U; i < MAX_REGUL; i++) {
740 const char *name __unused = regulators_table[i].dt_node_name;
741
742 VERBOSE("PMIC regul %s: %sable, %dmV",
743 name,
744 stpmic1_is_regulator_enabled(name) ? "en" : "dis",
745 stpmic1_regulator_voltage_get(name));
746 }
747}
748
749int stpmic1_get_version(unsigned long *version)
750{
751 int rc;
752 uint8_t read_val;
753
754 rc = stpmic1_register_read(VERSION_STATUS_REG, &read_val);
755 if (rc) {
756 return -1;
757 }
758
759 *version = (unsigned long)read_val;
760
761 return 0;
762}