blob: 5b4376041bd1971f8a12b56f62c563db863afed4 [file] [log] [blame]
Yann Gautierbb836ee2018-07-16 17:55:07 +02001/*
Yann Gautierf0a74762022-01-06 09:35:35 +01002 * Copyright (c) 2017-2022, STMicroelectronics - All Rights Reserved
Yann Gautierbb836ee2018-07-16 17:55:07 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Yann Gautiere6f10322021-09-27 14:31:40 +02007#include <assert.h>
Yann Gautierbb836ee2018-07-16 17:55:07 +02008#include <errno.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <common/debug.h>
11#include <drivers/delay_timer.h>
Yann Gautiere6f10322021-09-27 14:31:40 +020012#include <drivers/st/regulator.h>
Yann Gautierf3928f62019-02-14 11:15:03 +010013#include <drivers/st/stm32_i2c.h>
Yann Gautiera45433b2019-01-16 18:31:00 +010014#include <drivers/st/stm32mp_pmic.h>
Yann Gautiera45433b2019-01-16 18:31:00 +010015#include <drivers/st/stpmic1.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016#include <lib/mmio.h>
17#include <lib/utils_def.h>
Nicolas Le Bayonf5188ee2019-09-19 11:24:50 +020018#include <libfdt.h>
19
20#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000021
Nicolas Le Bayon342865a2019-11-15 15:56:06 +010022#define PMIC_NODE_NOT_FOUND 1
Yann Gautierbb836ee2018-07-16 17:55:07 +020023
24static struct i2c_handle_s i2c_handle;
25static uint32_t pmic_i2c_addr;
26
Yann Gautiere6f10322021-09-27 14:31:40 +020027static int register_pmic(void);
28
Yann Gautierbb836ee2018-07-16 17:55:07 +020029static int dt_get_pmic_node(void *fdt)
30{
Nicolas Le Bayon342865a2019-11-15 15:56:06 +010031 static int node = -FDT_ERR_BADOFFSET;
32
33 if (node == -FDT_ERR_BADOFFSET) {
34 node = fdt_node_offset_by_compatible(fdt, -1, "st,stpmic1");
35 }
36
37 return node;
Yann Gautierbb836ee2018-07-16 17:55:07 +020038}
39
Yann Gautierf3928f62019-02-14 11:15:03 +010040int dt_pmic_status(void)
Yann Gautierbb836ee2018-07-16 17:55:07 +020041{
Nicolas Le Bayon342865a2019-11-15 15:56:06 +010042 static int status = -FDT_ERR_BADVALUE;
Yann Gautierbb836ee2018-07-16 17:55:07 +020043 int node;
44 void *fdt;
45
Nicolas Le Bayon342865a2019-11-15 15:56:06 +010046 if (status != -FDT_ERR_BADVALUE) {
47 return status;
48 }
49
Yann Gautierbb836ee2018-07-16 17:55:07 +020050 if (fdt_get_address(&fdt) == 0) {
Yann Gautierf3928f62019-02-14 11:15:03 +010051 return -ENOENT;
Yann Gautierbb836ee2018-07-16 17:55:07 +020052 }
53
54 node = dt_get_pmic_node(fdt);
Yann Gautierf3928f62019-02-14 11:15:03 +010055 if (node <= 0) {
Nicolas Le Bayon342865a2019-11-15 15:56:06 +010056 status = -FDT_ERR_NOTFOUND;
57
58 return status;
Yann Gautierbb836ee2018-07-16 17:55:07 +020059 }
60
Nicolas Le Bayon342865a2019-11-15 15:56:06 +010061 status = (int)fdt_get_status(node);
62
63 return status;
Yann Gautierbb836ee2018-07-16 17:55:07 +020064}
65
Etienne Carriere67b106a2019-12-02 10:10:08 +010066static bool dt_pmic_is_secure(void)
67{
68 int status = dt_pmic_status();
69
70 return (status >= 0) &&
71 (status == DT_SECURE) &&
72 (i2c_handle.dt_status == DT_SECURE);
73}
74
Yann Gautierf3928f62019-02-14 11:15:03 +010075/*
76 * Get PMIC and its I2C bus configuration from the device tree.
Nicolas Le Bayon342865a2019-11-15 15:56:06 +010077 * Return 0 on success, negative on error, 1 if no PMIC node is defined.
Yann Gautierf3928f62019-02-14 11:15:03 +010078 */
79static int dt_pmic_i2c_config(struct dt_node_info *i2c_info,
80 struct stm32_i2c_init_s *init)
Yann Gautierbb836ee2018-07-16 17:55:07 +020081{
Nicolas Le Bayon342865a2019-11-15 15:56:06 +010082 static int i2c_node = -FDT_ERR_NOTFOUND;
Yann Gautierbb836ee2018-07-16 17:55:07 +020083 void *fdt;
Yann Gautierbb836ee2018-07-16 17:55:07 +020084
85 if (fdt_get_address(&fdt) == 0) {
Nicolas Le Bayon342865a2019-11-15 15:56:06 +010086 return -FDT_ERR_NOTFOUND;
Yann Gautierbb836ee2018-07-16 17:55:07 +020087 }
88
Nicolas Le Bayon342865a2019-11-15 15:56:06 +010089 if (i2c_node == -FDT_ERR_NOTFOUND) {
90 int pmic_node;
91 const fdt32_t *cuint;
Yann Gautierbb836ee2018-07-16 17:55:07 +020092
Nicolas Le Bayon342865a2019-11-15 15:56:06 +010093 pmic_node = dt_get_pmic_node(fdt);
94 if (pmic_node < 0) {
95 return PMIC_NODE_NOT_FOUND;
96 }
Yann Gautierbb836ee2018-07-16 17:55:07 +020097
Nicolas Le Bayon342865a2019-11-15 15:56:06 +010098 cuint = fdt_getprop(fdt, pmic_node, "reg", NULL);
99 if (cuint == NULL) {
100 return -FDT_ERR_NOTFOUND;
101 }
Yann Gautierbb836ee2018-07-16 17:55:07 +0200102
Nicolas Le Bayon342865a2019-11-15 15:56:06 +0100103 pmic_i2c_addr = fdt32_to_cpu(*cuint) << 1;
104 if (pmic_i2c_addr > UINT16_MAX) {
105 return -FDT_ERR_BADVALUE;
106 }
107
108 i2c_node = fdt_parent_offset(fdt, pmic_node);
109 if (i2c_node < 0) {
110 return -FDT_ERR_NOTFOUND;
111 }
Yann Gautierbb836ee2018-07-16 17:55:07 +0200112 }
113
114 dt_fill_device_info(i2c_info, i2c_node);
115 if (i2c_info->base == 0U) {
116 return -FDT_ERR_NOTFOUND;
117 }
118
Yann Gautierf3928f62019-02-14 11:15:03 +0100119 return stm32_i2c_get_setup_from_fdt(fdt, i2c_node, init);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200120}
121
Yann Gautierf3928f62019-02-14 11:15:03 +0100122bool initialize_pmic_i2c(void)
Yann Gautierbb836ee2018-07-16 17:55:07 +0200123{
124 int ret;
125 struct dt_node_info i2c_info;
Yann Gautierf3928f62019-02-14 11:15:03 +0100126 struct i2c_handle_s *i2c = &i2c_handle;
127 struct stm32_i2c_init_s i2c_init;
Yann Gautierbb836ee2018-07-16 17:55:07 +0200128
Yann Gautierf3928f62019-02-14 11:15:03 +0100129 ret = dt_pmic_i2c_config(&i2c_info, &i2c_init);
130 if (ret < 0) {
131 ERROR("I2C configuration failed %d\n", ret);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200132 panic();
133 }
134
Yann Gautierf3928f62019-02-14 11:15:03 +0100135 if (ret != 0) {
136 return false;
Yann Gautierbb836ee2018-07-16 17:55:07 +0200137 }
138
139 /* Initialize PMIC I2C */
Yann Gautierf3928f62019-02-14 11:15:03 +0100140 i2c->i2c_base_addr = i2c_info.base;
141 i2c->dt_status = i2c_info.status;
142 i2c->clock = i2c_info.clock;
Benjamin Gaignard53ee7d32020-02-24 13:57:40 +0100143 i2c->i2c_state = I2C_STATE_RESET;
Yann Gautierf3928f62019-02-14 11:15:03 +0100144 i2c_init.own_address1 = pmic_i2c_addr;
145 i2c_init.addressing_mode = I2C_ADDRESSINGMODE_7BIT;
146 i2c_init.dual_address_mode = I2C_DUALADDRESS_DISABLE;
147 i2c_init.own_address2 = 0;
148 i2c_init.own_address2_masks = I2C_OAR2_OA2NOMASK;
149 i2c_init.general_call_mode = I2C_GENERALCALL_DISABLE;
150 i2c_init.no_stretch_mode = I2C_NOSTRETCH_DISABLE;
151 i2c_init.analog_filter = 1;
152 i2c_init.digital_filter_coef = 0;
Yann Gautierbb836ee2018-07-16 17:55:07 +0200153
Yann Gautierf3928f62019-02-14 11:15:03 +0100154 ret = stm32_i2c_init(i2c, &i2c_init);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200155 if (ret != 0) {
156 ERROR("Cannot initialize I2C %x (%d)\n",
Yann Gautierf3928f62019-02-14 11:15:03 +0100157 i2c->i2c_base_addr, ret);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200158 panic();
159 }
160
Yann Gautierf3928f62019-02-14 11:15:03 +0100161 if (!stm32_i2c_is_device_ready(i2c, pmic_i2c_addr, 1,
162 I2C_TIMEOUT_BUSY_MS)) {
163 ERROR("I2C device not ready\n");
Yann Gautierbb836ee2018-07-16 17:55:07 +0200164 panic();
165 }
166
Yann Gautierf3928f62019-02-14 11:15:03 +0100167 stpmic1_bind_i2c(i2c, (uint16_t)pmic_i2c_addr);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200168
Yann Gautierf3928f62019-02-14 11:15:03 +0100169 return true;
Yann Gautierbb836ee2018-07-16 17:55:07 +0200170}
171
Etienne Carriere67b106a2019-12-02 10:10:08 +0100172static void register_pmic_shared_peripherals(void)
173{
174 uintptr_t i2c_base = i2c_handle.i2c_base_addr;
175
176 if (dt_pmic_is_secure()) {
177 stm32mp_register_secure_periph_iomem(i2c_base);
178 } else {
179 if (i2c_base != 0U) {
180 stm32mp_register_non_secure_periph_iomem(i2c_base);
181 }
182 }
183}
184
Yann Gautierbb836ee2018-07-16 17:55:07 +0200185void initialize_pmic(void)
186{
Yann Gautierf3928f62019-02-14 11:15:03 +0100187 if (!initialize_pmic_i2c()) {
188 VERBOSE("No PMIC\n");
189 return;
190 }
Yann Gautierbb836ee2018-07-16 17:55:07 +0200191
Etienne Carriere67b106a2019-12-02 10:10:08 +0100192 register_pmic_shared_peripherals();
193
Yann Gautiere6f10322021-09-27 14:31:40 +0200194 if (register_pmic() < 0) {
Nicolas Le Bayon0b10b652019-11-18 13:13:36 +0100195 panic();
Yann Gautiere6f10322021-09-27 14:31:40 +0200196 }
197
198 if (stpmic1_powerctrl_on() < 0) {
199 panic();
200 }
201
Nicolas Le Bayon0b10b652019-11-18 13:13:36 +0100202}
203
204#if DEBUG
205void print_pmic_info_and_debug(void)
206{
207 unsigned long pmic_version;
208
Yann Gautierf3928f62019-02-14 11:15:03 +0100209 if (stpmic1_get_version(&pmic_version) != 0) {
210 ERROR("Failed to access PMIC\n");
Yann Gautierbb836ee2018-07-16 17:55:07 +0200211 panic();
212 }
213
Yann Gautierf3928f62019-02-14 11:15:03 +0100214 INFO("PMIC version = 0x%02lx\n", pmic_version);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200215}
Nicolas Le Bayon0b10b652019-11-18 13:13:36 +0100216#endif
Yann Gautierbb836ee2018-07-16 17:55:07 +0200217
218int pmic_ddr_power_init(enum ddr_type ddr_type)
219{
Yann Gautierbb836ee2018-07-16 17:55:07 +0200220 int status;
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100221 uint16_t buck3_min_mv;
Yann Gautiercc5f89a2020-02-12 09:36:23 +0100222 struct rdev *buck2, *buck3, *vref;
223 struct rdev *ldo3 __unused;
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100224
225 buck2 = regulator_get_by_name("buck2");
226 if (buck2 == NULL) {
227 return -ENOENT;
228 }
229
Yann Gautiercc5f89a2020-02-12 09:36:23 +0100230#if STM32MP15
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100231 ldo3 = regulator_get_by_name("ldo3");
232 if (ldo3 == NULL) {
233 return -ENOENT;
234 }
Yann Gautiercc5f89a2020-02-12 09:36:23 +0100235#endif
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100236
237 vref = regulator_get_by_name("vref_ddr");
238 if (vref == NULL) {
239 return -ENOENT;
240 }
Yann Gautierbb836ee2018-07-16 17:55:07 +0200241
242 switch (ddr_type) {
243 case STM32MP_DDR3:
Yann Gautiercc5f89a2020-02-12 09:36:23 +0100244#if STM32MP15
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100245 status = regulator_set_flag(ldo3, REGUL_SINK_SOURCE);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200246 if (status != 0) {
247 return status;
248 }
Yann Gautiercc5f89a2020-02-12 09:36:23 +0100249#endif
Yann Gautierbb836ee2018-07-16 17:55:07 +0200250
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100251 status = regulator_set_min_voltage(buck2);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200252 if (status != 0) {
253 return status;
254 }
255
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100256 status = regulator_enable(buck2);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200257 if (status != 0) {
258 return status;
259 }
260
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100261 status = regulator_enable(vref);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200262 if (status != 0) {
263 return status;
264 }
265
Yann Gautiercc5f89a2020-02-12 09:36:23 +0100266#if STM32MP15
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100267 status = regulator_enable(ldo3);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200268 if (status != 0) {
269 return status;
270 }
Yann Gautiercc5f89a2020-02-12 09:36:23 +0100271#endif
Yann Gautierbb836ee2018-07-16 17:55:07 +0200272 break;
273
274 case STM32MP_LPDDR2:
Yann Gautier917a00c2019-04-16 16:20:58 +0200275 case STM32MP_LPDDR3:
Yann Gautierbb836ee2018-07-16 17:55:07 +0200276 /*
277 * Set LDO3 to 1.8V
278 * Set LDO3 to bypass mode if BUCK3 = 1.8V
279 * Set LDO3 to normal mode if BUCK3 != 1.8V
280 */
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100281 buck3 = regulator_get_by_name("buck3");
282 if (buck3 == NULL) {
283 return -ENOENT;
Yann Gautierbb836ee2018-07-16 17:55:07 +0200284 }
285
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100286 regulator_get_range(buck3, &buck3_min_mv, NULL);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200287
Yann Gautiercc5f89a2020-02-12 09:36:23 +0100288#if STM32MP15
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100289 if (buck3_min_mv != 1800) {
290 status = regulator_set_min_voltage(ldo3);
291 if (status != 0) {
292 return status;
293 }
294 } else {
295 status = regulator_set_flag(ldo3, REGUL_ENABLE_BYPASS);
296 if (status != 0) {
297 return status;
298 }
Yann Gautierbb836ee2018-07-16 17:55:07 +0200299 }
Yann Gautiercc5f89a2020-02-12 09:36:23 +0100300#endif
Yann Gautierbb836ee2018-07-16 17:55:07 +0200301
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100302 status = regulator_set_min_voltage(buck2);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200303 if (status != 0) {
304 return status;
305 }
306
Yann Gautiercc5f89a2020-02-12 09:36:23 +0100307#if STM32MP15
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100308 status = regulator_enable(ldo3);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200309 if (status != 0) {
310 return status;
311 }
Yann Gautiercc5f89a2020-02-12 09:36:23 +0100312#endif
Yann Gautierbb836ee2018-07-16 17:55:07 +0200313
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100314 status = regulator_enable(buck2);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200315 if (status != 0) {
316 return status;
317 }
318
Pascal Paillet5e36dbb2020-12-15 19:05:09 +0100319 status = regulator_enable(vref);
Yann Gautierbb836ee2018-07-16 17:55:07 +0200320 if (status != 0) {
321 return status;
322 }
Yann Gautierbb836ee2018-07-16 17:55:07 +0200323 break;
324
325 default:
326 break;
327 };
328
329 return 0;
330}
Yann Gautiere6f10322021-09-27 14:31:40 +0200331
Yann Gautiere05e8cf2022-01-18 15:49:42 +0100332int pmic_voltages_init(void)
333{
334#if STM32MP13
335 struct rdev *buck1, *buck4;
336 int status;
337
338 buck1 = regulator_get_by_name("buck1");
339 if (buck1 == NULL) {
340 return -ENOENT;
341 }
342
343 buck4 = regulator_get_by_name("buck4");
344 if (buck4 == NULL) {
345 return -ENOENT;
346 }
347
348 status = regulator_set_min_voltage(buck1);
349 if (status != 0) {
350 return status;
351 }
352
353 status = regulator_set_min_voltage(buck4);
354 if (status != 0) {
355 return status;
356 }
357#endif
358
359 return 0;
360}
361
Yann Gautiere6f10322021-09-27 14:31:40 +0200362enum {
363 STPMIC1_BUCK1 = 0,
364 STPMIC1_BUCK2,
365 STPMIC1_BUCK3,
366 STPMIC1_BUCK4,
367 STPMIC1_LDO1,
368 STPMIC1_LDO2,
369 STPMIC1_LDO3,
370 STPMIC1_LDO4,
371 STPMIC1_LDO5,
372 STPMIC1_LDO6,
373 STPMIC1_VREF_DDR,
374 STPMIC1_BOOST,
375 STPMIC1_VBUS_OTG,
376 STPMIC1_SW_OUT,
377};
378
379static int pmic_set_state(const struct regul_description *desc, bool enable)
380{
Yann Gautierf0a74762022-01-06 09:35:35 +0100381 VERBOSE("%s: set state to %d\n", desc->node_name, enable);
Yann Gautiere6f10322021-09-27 14:31:40 +0200382
383 if (enable == STATE_ENABLE) {
384 return stpmic1_regulator_enable(desc->node_name);
385 } else {
386 return stpmic1_regulator_disable(desc->node_name);
387 }
388}
389
390static int pmic_get_state(const struct regul_description *desc)
391{
392 VERBOSE("%s: get state\n", desc->node_name);
393
394 return stpmic1_is_regulator_enabled(desc->node_name);
395}
396
397static int pmic_get_voltage(const struct regul_description *desc)
398{
399 VERBOSE("%s: get volt\n", desc->node_name);
400
401 return stpmic1_regulator_voltage_get(desc->node_name);
402}
403
404static int pmic_set_voltage(const struct regul_description *desc, uint16_t mv)
405{
406 VERBOSE("%s: get volt\n", desc->node_name);
407
408 return stpmic1_regulator_voltage_set(desc->node_name, mv);
409}
410
411static int pmic_list_voltages(const struct regul_description *desc,
412 const uint16_t **levels, size_t *count)
413{
414 VERBOSE("%s: list volt\n", desc->node_name);
415
416 return stpmic1_regulator_levels_mv(desc->node_name, levels, count);
417}
418
419static int pmic_set_flag(const struct regul_description *desc, uint16_t flag)
420{
421 VERBOSE("%s: set_flag 0x%x\n", desc->node_name, flag);
422
423 switch (flag) {
424 case REGUL_OCP:
425 return stpmic1_regulator_icc_set(desc->node_name);
426
427 case REGUL_ACTIVE_DISCHARGE:
428 return stpmic1_active_discharge_mode_set(desc->node_name);
429
430 case REGUL_PULL_DOWN:
431 return stpmic1_regulator_pull_down_set(desc->node_name);
432
433 case REGUL_MASK_RESET:
434 return stpmic1_regulator_mask_reset_set(desc->node_name);
435
436 case REGUL_SINK_SOURCE:
437 return stpmic1_regulator_sink_mode_set(desc->node_name);
438
439 case REGUL_ENABLE_BYPASS:
440 return stpmic1_regulator_bypass_mode_set(desc->node_name);
441
442 default:
443 return -EINVAL;
444 }
445}
446
Yann Gautierb62e1172022-02-09 17:35:45 +0100447static const struct regul_ops pmic_ops = {
Yann Gautiere6f10322021-09-27 14:31:40 +0200448 .set_state = pmic_set_state,
449 .get_state = pmic_get_state,
450 .set_voltage = pmic_set_voltage,
451 .get_voltage = pmic_get_voltage,
452 .list_voltages = pmic_list_voltages,
453 .set_flag = pmic_set_flag,
454};
455
456#define DEFINE_REGU(name) { \
457 .node_name = name, \
458 .ops = &pmic_ops, \
459 .driver_data = NULL, \
460 .enable_ramp_delay = 1000, \
461}
462
463static const struct regul_description pmic_regs[] = {
464 [STPMIC1_BUCK1] = DEFINE_REGU("buck1"),
465 [STPMIC1_BUCK2] = DEFINE_REGU("buck2"),
466 [STPMIC1_BUCK3] = DEFINE_REGU("buck3"),
467 [STPMIC1_BUCK4] = DEFINE_REGU("buck4"),
468 [STPMIC1_LDO1] = DEFINE_REGU("ldo1"),
469 [STPMIC1_LDO2] = DEFINE_REGU("ldo2"),
470 [STPMIC1_LDO3] = DEFINE_REGU("ldo3"),
471 [STPMIC1_LDO4] = DEFINE_REGU("ldo4"),
472 [STPMIC1_LDO5] = DEFINE_REGU("ldo5"),
473 [STPMIC1_LDO6] = DEFINE_REGU("ldo6"),
474 [STPMIC1_VREF_DDR] = DEFINE_REGU("vref_ddr"),
475 [STPMIC1_BOOST] = DEFINE_REGU("boost"),
476 [STPMIC1_VBUS_OTG] = DEFINE_REGU("pwr_sw1"),
477 [STPMIC1_SW_OUT] = DEFINE_REGU("pwr_sw2"),
478};
479
480#define NB_REG ARRAY_SIZE(pmic_regs)
481
482static int register_pmic(void)
483{
484 void *fdt;
485 int pmic_node, regulators_node, subnode;
486
487 VERBOSE("Register pmic\n");
488
489 if (fdt_get_address(&fdt) == 0) {
490 return -FDT_ERR_NOTFOUND;
491 }
492
493 pmic_node = dt_get_pmic_node(fdt);
494 if (pmic_node < 0) {
495 return pmic_node;
496 }
497
498 regulators_node = fdt_subnode_offset(fdt, pmic_node, "regulators");
499 if (regulators_node < 0) {
500 return -ENOENT;
501 }
502
503 fdt_for_each_subnode(subnode, fdt, regulators_node) {
504 const char *reg_name = fdt_get_name(fdt, subnode, NULL);
505 const struct regul_description *desc;
506 unsigned int i;
507 int ret;
508
509 for (i = 0; i < NB_REG; i++) {
510 desc = &pmic_regs[i];
511 if (strcmp(desc->node_name, reg_name) == 0) {
512 break;
513 }
514 }
515 assert(i < NB_REG);
516
517 ret = regulator_register(desc, subnode);
518 if (ret != 0) {
519 WARN("%s:%d failed to register %s\n", __func__,
520 __LINE__, reg_name);
521 return ret;
522 }
523 }
524
525 return 0;
526}