of_regulator.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * OF helpers for regulator framework
  4. *
  5. * Copyright (C) 2011 Texas Instruments, Inc.
  6. * Rajendra Nayak <[email protected]>
  7. */
  8. #include <linux/module.h>
  9. #include <linux/slab.h>
  10. #include <linux/of.h>
  11. #include <linux/regulator/machine.h>
  12. #include <linux/regulator/driver.h>
  13. #include <linux/regulator/of_regulator.h>
  14. #include "internal.h"
  15. static const char *const regulator_states[PM_SUSPEND_MAX + 1] = {
  16. [PM_SUSPEND_STANDBY] = "regulator-state-standby",
  17. [PM_SUSPEND_MEM] = "regulator-state-mem",
  18. [PM_SUSPEND_MAX] = "regulator-state-disk",
  19. };
  20. static void fill_limit(int *limit, int val)
  21. {
  22. if (val)
  23. if (val == 1)
  24. *limit = REGULATOR_NOTIF_LIMIT_ENABLE;
  25. else
  26. *limit = val;
  27. else
  28. *limit = REGULATOR_NOTIF_LIMIT_DISABLE;
  29. }
  30. static void of_get_regulator_prot_limits(struct device_node *np,
  31. struct regulation_constraints *constraints)
  32. {
  33. u32 pval;
  34. int i;
  35. static const char *const props[] = {
  36. "regulator-oc-%s-microamp",
  37. "regulator-ov-%s-microvolt",
  38. "regulator-temp-%s-kelvin",
  39. "regulator-uv-%s-microvolt",
  40. };
  41. struct notification_limit *limits[] = {
  42. &constraints->over_curr_limits,
  43. &constraints->over_voltage_limits,
  44. &constraints->temp_limits,
  45. &constraints->under_voltage_limits,
  46. };
  47. bool set[4] = {0};
  48. /* Protection limits: */
  49. for (i = 0; i < ARRAY_SIZE(props); i++) {
  50. char prop[255];
  51. bool found;
  52. int j;
  53. static const char *const lvl[] = {
  54. "protection", "error", "warn"
  55. };
  56. int *l[] = {
  57. &limits[i]->prot, &limits[i]->err, &limits[i]->warn,
  58. };
  59. for (j = 0; j < ARRAY_SIZE(lvl); j++) {
  60. snprintf(prop, 255, props[i], lvl[j]);
  61. found = !of_property_read_u32(np, prop, &pval);
  62. if (found)
  63. fill_limit(l[j], pval);
  64. set[i] |= found;
  65. }
  66. }
  67. constraints->over_current_detection = set[0];
  68. constraints->over_voltage_detection = set[1];
  69. constraints->over_temp_detection = set[2];
  70. constraints->under_voltage_detection = set[3];
  71. }
  72. static int of_get_regulation_constraints(struct device *dev,
  73. struct device_node *np,
  74. struct regulator_init_data **init_data,
  75. const struct regulator_desc *desc)
  76. {
  77. struct regulation_constraints *constraints = &(*init_data)->constraints;
  78. struct regulator_state *suspend_state;
  79. struct device_node *suspend_np;
  80. unsigned int mode;
  81. int ret, i, len;
  82. int n_phandles;
  83. u32 pval;
  84. n_phandles = of_count_phandle_with_args(np, "regulator-coupled-with",
  85. NULL);
  86. n_phandles = max(n_phandles, 0);
  87. constraints->name = of_get_property(np, "regulator-name", NULL);
  88. if (!of_property_read_u32(np, "regulator-min-microvolt", &pval))
  89. constraints->min_uV = pval;
  90. if (!of_property_read_u32(np, "regulator-max-microvolt", &pval))
  91. constraints->max_uV = pval;
  92. /* Voltage change possible? */
  93. if (constraints->min_uV != constraints->max_uV)
  94. constraints->valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE;
  95. /* Do we have a voltage range, if so try to apply it? */
  96. if (constraints->min_uV && constraints->max_uV)
  97. constraints->apply_uV = true;
  98. if (!of_property_read_u32(np, "regulator-microvolt-offset", &pval))
  99. constraints->uV_offset = pval;
  100. if (!of_property_read_u32(np, "regulator-min-microamp", &pval))
  101. constraints->min_uA = pval;
  102. if (!of_property_read_u32(np, "regulator-max-microamp", &pval))
  103. constraints->max_uA = pval;
  104. if (!of_property_read_u32(np, "regulator-input-current-limit-microamp",
  105. &pval))
  106. constraints->ilim_uA = pval;
  107. /* Current change possible? */
  108. if (constraints->min_uA != constraints->max_uA)
  109. constraints->valid_ops_mask |= REGULATOR_CHANGE_CURRENT;
  110. constraints->boot_on = of_property_read_bool(np, "regulator-boot-on");
  111. constraints->always_on = of_property_read_bool(np, "regulator-always-on");
  112. if (!constraints->always_on) /* status change should be possible. */
  113. constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS;
  114. constraints->pull_down = of_property_read_bool(np, "regulator-pull-down");
  115. if (of_property_read_bool(np, "regulator-allow-bypass"))
  116. constraints->valid_ops_mask |= REGULATOR_CHANGE_BYPASS;
  117. if (of_property_read_bool(np, "regulator-allow-set-load"))
  118. constraints->valid_ops_mask |= REGULATOR_CHANGE_DRMS;
  119. ret = of_property_read_u32(np, "regulator-ramp-delay", &pval);
  120. if (!ret) {
  121. if (pval)
  122. constraints->ramp_delay = pval;
  123. else
  124. constraints->ramp_disable = true;
  125. }
  126. ret = of_property_read_u32(np, "regulator-settling-time-us", &pval);
  127. if (!ret)
  128. constraints->settling_time = pval;
  129. ret = of_property_read_u32(np, "regulator-settling-time-up-us", &pval);
  130. if (!ret)
  131. constraints->settling_time_up = pval;
  132. if (constraints->settling_time_up && constraints->settling_time) {
  133. pr_warn("%pOFn: ambiguous configuration for settling time, ignoring 'regulator-settling-time-up-us'\n",
  134. np);
  135. constraints->settling_time_up = 0;
  136. }
  137. ret = of_property_read_u32(np, "regulator-settling-time-down-us",
  138. &pval);
  139. if (!ret)
  140. constraints->settling_time_down = pval;
  141. if (constraints->settling_time_down && constraints->settling_time) {
  142. pr_warn("%pOFn: ambiguous configuration for settling time, ignoring 'regulator-settling-time-down-us'\n",
  143. np);
  144. constraints->settling_time_down = 0;
  145. }
  146. ret = of_property_read_u32(np, "regulator-enable-ramp-delay", &pval);
  147. if (!ret)
  148. constraints->enable_time = pval;
  149. constraints->soft_start = of_property_read_bool(np,
  150. "regulator-soft-start");
  151. ret = of_property_read_u32(np, "regulator-active-discharge", &pval);
  152. if (!ret) {
  153. constraints->active_discharge =
  154. (pval) ? REGULATOR_ACTIVE_DISCHARGE_ENABLE :
  155. REGULATOR_ACTIVE_DISCHARGE_DISABLE;
  156. }
  157. if (!of_property_read_u32(np, "regulator-initial-mode", &pval)) {
  158. if (desc && desc->of_map_mode) {
  159. mode = desc->of_map_mode(pval);
  160. if (mode == REGULATOR_MODE_INVALID)
  161. pr_err("%pOFn: invalid mode %u\n", np, pval);
  162. else
  163. constraints->initial_mode = mode;
  164. } else {
  165. pr_warn("%pOFn: mapping for mode %d not defined\n",
  166. np, pval);
  167. }
  168. }
  169. len = of_property_count_elems_of_size(np, "regulator-allowed-modes",
  170. sizeof(u32));
  171. if (len > 0) {
  172. if (desc && desc->of_map_mode) {
  173. for (i = 0; i < len; i++) {
  174. ret = of_property_read_u32_index(np,
  175. "regulator-allowed-modes", i, &pval);
  176. if (ret) {
  177. pr_err("%pOFn: couldn't read allowed modes index %d, ret=%d\n",
  178. np, i, ret);
  179. break;
  180. }
  181. mode = desc->of_map_mode(pval);
  182. if (mode == REGULATOR_MODE_INVALID)
  183. pr_err("%pOFn: invalid regulator-allowed-modes element %u\n",
  184. np, pval);
  185. else
  186. constraints->valid_modes_mask |= mode;
  187. }
  188. if (constraints->valid_modes_mask)
  189. constraints->valid_ops_mask
  190. |= REGULATOR_CHANGE_MODE;
  191. } else {
  192. pr_warn("%pOFn: mode mapping not defined\n", np);
  193. }
  194. }
  195. if (!of_property_read_u32(np, "regulator-system-load", &pval))
  196. constraints->system_load = pval;
  197. if (n_phandles) {
  198. constraints->max_spread = devm_kzalloc(dev,
  199. sizeof(*constraints->max_spread) * n_phandles,
  200. GFP_KERNEL);
  201. if (!constraints->max_spread)
  202. return -ENOMEM;
  203. of_property_read_u32_array(np, "regulator-coupled-max-spread",
  204. constraints->max_spread, n_phandles);
  205. }
  206. if (!of_property_read_u32(np, "regulator-max-step-microvolt",
  207. &pval))
  208. constraints->max_uV_step = pval;
  209. constraints->over_current_protection = of_property_read_bool(np,
  210. "regulator-over-current-protection");
  211. of_get_regulator_prot_limits(np, constraints);
  212. for (i = 0; i < ARRAY_SIZE(regulator_states); i++) {
  213. switch (i) {
  214. case PM_SUSPEND_MEM:
  215. suspend_state = &constraints->state_mem;
  216. break;
  217. case PM_SUSPEND_MAX:
  218. suspend_state = &constraints->state_disk;
  219. break;
  220. case PM_SUSPEND_STANDBY:
  221. suspend_state = &constraints->state_standby;
  222. break;
  223. case PM_SUSPEND_ON:
  224. case PM_SUSPEND_TO_IDLE:
  225. default:
  226. continue;
  227. }
  228. suspend_np = of_get_child_by_name(np, regulator_states[i]);
  229. if (!suspend_np)
  230. continue;
  231. if (!suspend_state) {
  232. of_node_put(suspend_np);
  233. continue;
  234. }
  235. if (!of_property_read_u32(suspend_np, "regulator-mode",
  236. &pval)) {
  237. if (desc && desc->of_map_mode) {
  238. mode = desc->of_map_mode(pval);
  239. if (mode == REGULATOR_MODE_INVALID)
  240. pr_err("%pOFn: invalid mode %u\n",
  241. np, pval);
  242. else
  243. suspend_state->mode = mode;
  244. } else {
  245. pr_warn("%pOFn: mapping for mode %d not defined\n",
  246. np, pval);
  247. }
  248. }
  249. if (of_property_read_bool(suspend_np,
  250. "regulator-on-in-suspend"))
  251. suspend_state->enabled = ENABLE_IN_SUSPEND;
  252. else if (of_property_read_bool(suspend_np,
  253. "regulator-off-in-suspend"))
  254. suspend_state->enabled = DISABLE_IN_SUSPEND;
  255. if (!of_property_read_u32(suspend_np,
  256. "regulator-suspend-min-microvolt", &pval))
  257. suspend_state->min_uV = pval;
  258. if (!of_property_read_u32(suspend_np,
  259. "regulator-suspend-max-microvolt", &pval))
  260. suspend_state->max_uV = pval;
  261. if (!of_property_read_u32(suspend_np,
  262. "regulator-suspend-microvolt", &pval))
  263. suspend_state->uV = pval;
  264. else /* otherwise use min_uV as default suspend voltage */
  265. suspend_state->uV = suspend_state->min_uV;
  266. if (of_property_read_bool(suspend_np,
  267. "regulator-changeable-in-suspend"))
  268. suspend_state->changeable = true;
  269. if (i == PM_SUSPEND_MEM)
  270. constraints->initial_state = PM_SUSPEND_MEM;
  271. of_node_put(suspend_np);
  272. suspend_state = NULL;
  273. suspend_np = NULL;
  274. }
  275. return 0;
  276. }
  277. /**
  278. * of_get_regulator_init_data - extract regulator_init_data structure info
  279. * @dev: device requesting for regulator_init_data
  280. * @node: regulator device node
  281. * @desc: regulator description
  282. *
  283. * Populates regulator_init_data structure by extracting data from device
  284. * tree node, returns a pointer to the populated structure or NULL if memory
  285. * alloc fails.
  286. */
  287. struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
  288. struct device_node *node,
  289. const struct regulator_desc *desc)
  290. {
  291. struct regulator_init_data *init_data;
  292. if (!node)
  293. return NULL;
  294. init_data = devm_kzalloc(dev, sizeof(*init_data), GFP_KERNEL);
  295. if (!init_data)
  296. return NULL; /* Out of memory? */
  297. if (of_get_regulation_constraints(dev, node, &init_data, desc))
  298. return NULL;
  299. return init_data;
  300. }
  301. EXPORT_SYMBOL_GPL(of_get_regulator_init_data);
  302. struct devm_of_regulator_matches {
  303. struct of_regulator_match *matches;
  304. unsigned int num_matches;
  305. };
  306. static void devm_of_regulator_put_matches(struct device *dev, void *res)
  307. {
  308. struct devm_of_regulator_matches *devm_matches = res;
  309. int i;
  310. for (i = 0; i < devm_matches->num_matches; i++)
  311. of_node_put(devm_matches->matches[i].of_node);
  312. }
  313. /**
  314. * of_regulator_match - extract multiple regulator init data from device tree.
  315. * @dev: device requesting the data
  316. * @node: parent device node of the regulators
  317. * @matches: match table for the regulators
  318. * @num_matches: number of entries in match table
  319. *
  320. * This function uses a match table specified by the regulator driver to
  321. * parse regulator init data from the device tree. @node is expected to
  322. * contain a set of child nodes, each providing the init data for one
  323. * regulator. The data parsed from a child node will be matched to a regulator
  324. * based on either the deprecated property regulator-compatible if present,
  325. * or otherwise the child node's name. Note that the match table is modified
  326. * in place and an additional of_node reference is taken for each matched
  327. * regulator.
  328. *
  329. * Returns the number of matches found or a negative error code on failure.
  330. */
  331. int of_regulator_match(struct device *dev, struct device_node *node,
  332. struct of_regulator_match *matches,
  333. unsigned int num_matches)
  334. {
  335. unsigned int count = 0;
  336. unsigned int i;
  337. const char *name;
  338. struct device_node *child;
  339. struct devm_of_regulator_matches *devm_matches;
  340. if (!dev || !node)
  341. return -EINVAL;
  342. devm_matches = devres_alloc(devm_of_regulator_put_matches,
  343. sizeof(struct devm_of_regulator_matches),
  344. GFP_KERNEL);
  345. if (!devm_matches)
  346. return -ENOMEM;
  347. devm_matches->matches = matches;
  348. devm_matches->num_matches = num_matches;
  349. devres_add(dev, devm_matches);
  350. for (i = 0; i < num_matches; i++) {
  351. struct of_regulator_match *match = &matches[i];
  352. match->init_data = NULL;
  353. match->of_node = NULL;
  354. }
  355. for_each_child_of_node(node, child) {
  356. name = of_get_property(child,
  357. "regulator-compatible", NULL);
  358. if (!name)
  359. name = child->name;
  360. for (i = 0; i < num_matches; i++) {
  361. struct of_regulator_match *match = &matches[i];
  362. if (match->of_node)
  363. continue;
  364. if (strcmp(match->name, name))
  365. continue;
  366. match->init_data =
  367. of_get_regulator_init_data(dev, child,
  368. match->desc);
  369. if (!match->init_data) {
  370. dev_err(dev,
  371. "failed to parse DT for regulator %pOFn\n",
  372. child);
  373. of_node_put(child);
  374. return -EINVAL;
  375. }
  376. match->of_node = of_node_get(child);
  377. count++;
  378. break;
  379. }
  380. }
  381. return count;
  382. }
  383. EXPORT_SYMBOL_GPL(of_regulator_match);
  384. static struct
  385. device_node *regulator_of_get_init_node(struct device *dev,
  386. const struct regulator_desc *desc)
  387. {
  388. struct device_node *search, *child;
  389. const char *name;
  390. if (!dev->of_node || !desc->of_match)
  391. return NULL;
  392. if (desc->regulators_node) {
  393. search = of_get_child_by_name(dev->of_node,
  394. desc->regulators_node);
  395. } else {
  396. search = of_node_get(dev->of_node);
  397. if (!strcmp(desc->of_match, search->name))
  398. return search;
  399. }
  400. if (!search) {
  401. dev_dbg(dev, "Failed to find regulator container node '%s'\n",
  402. desc->regulators_node);
  403. return NULL;
  404. }
  405. for_each_available_child_of_node(search, child) {
  406. name = of_get_property(child, "regulator-compatible", NULL);
  407. if (!name) {
  408. if (!desc->of_match_full_name)
  409. name = child->name;
  410. else
  411. name = child->full_name;
  412. }
  413. if (!strcmp(desc->of_match, name)) {
  414. of_node_put(search);
  415. /*
  416. * 'of_node_get(child)' is already performed by the
  417. * for_each loop.
  418. */
  419. return child;
  420. }
  421. }
  422. of_node_put(search);
  423. return NULL;
  424. }
  425. struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
  426. const struct regulator_desc *desc,
  427. struct regulator_config *config,
  428. struct device_node **node)
  429. {
  430. struct device_node *child;
  431. struct regulator_init_data *init_data = NULL;
  432. child = regulator_of_get_init_node(config->dev, desc);
  433. if (!child)
  434. return NULL;
  435. init_data = of_get_regulator_init_data(dev, child, desc);
  436. if (!init_data) {
  437. dev_err(dev, "failed to parse DT for regulator %pOFn\n", child);
  438. goto error;
  439. }
  440. if (desc->of_parse_cb) {
  441. int ret;
  442. ret = desc->of_parse_cb(child, desc, config);
  443. if (ret) {
  444. if (ret == -EPROBE_DEFER) {
  445. of_node_put(child);
  446. return ERR_PTR(-EPROBE_DEFER);
  447. }
  448. dev_err(dev,
  449. "driver callback failed to parse DT for regulator %pOFn\n",
  450. child);
  451. goto error;
  452. }
  453. }
  454. *node = child;
  455. return init_data;
  456. error:
  457. of_node_put(child);
  458. return NULL;
  459. }
  460. struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
  461. {
  462. struct device *dev;
  463. dev = class_find_device_by_of_node(&regulator_class, np);
  464. return dev ? dev_to_rdev(dev) : NULL;
  465. }
  466. /*
  467. * Returns number of regulators coupled with rdev.
  468. */
  469. int of_get_n_coupled(struct regulator_dev *rdev)
  470. {
  471. struct device_node *node = rdev->dev.of_node;
  472. int n_phandles;
  473. n_phandles = of_count_phandle_with_args(node,
  474. "regulator-coupled-with",
  475. NULL);
  476. return (n_phandles > 0) ? n_phandles : 0;
  477. }
  478. /* Looks for "to_find" device_node in src's "regulator-coupled-with" property */
  479. static bool of_coupling_find_node(struct device_node *src,
  480. struct device_node *to_find,
  481. int *index)
  482. {
  483. int n_phandles, i;
  484. bool found = false;
  485. n_phandles = of_count_phandle_with_args(src,
  486. "regulator-coupled-with",
  487. NULL);
  488. for (i = 0; i < n_phandles; i++) {
  489. struct device_node *tmp = of_parse_phandle(src,
  490. "regulator-coupled-with", i);
  491. if (!tmp)
  492. break;
  493. /* found */
  494. if (tmp == to_find)
  495. found = true;
  496. of_node_put(tmp);
  497. if (found) {
  498. *index = i;
  499. break;
  500. }
  501. }
  502. return found;
  503. }
  504. /**
  505. * of_check_coupling_data - Parse rdev's coupling properties and check data
  506. * consistency
  507. * @rdev: pointer to regulator_dev whose data is checked
  508. *
  509. * Function checks if all the following conditions are met:
  510. * - rdev's max_spread is greater than 0
  511. * - all coupled regulators have the same max_spread
  512. * - all coupled regulators have the same number of regulator_dev phandles
  513. * - all regulators are linked to each other
  514. *
  515. * Returns true if all conditions are met.
  516. */
  517. bool of_check_coupling_data(struct regulator_dev *rdev)
  518. {
  519. struct device_node *node = rdev->dev.of_node;
  520. int n_phandles = of_get_n_coupled(rdev);
  521. struct device_node *c_node;
  522. int index;
  523. int i;
  524. bool ret = true;
  525. /* iterate over rdev's phandles */
  526. for (i = 0; i < n_phandles; i++) {
  527. int max_spread = rdev->constraints->max_spread[i];
  528. int c_max_spread, c_n_phandles;
  529. if (max_spread <= 0) {
  530. dev_err(&rdev->dev, "max_spread value invalid\n");
  531. return false;
  532. }
  533. c_node = of_parse_phandle(node,
  534. "regulator-coupled-with", i);
  535. if (!c_node)
  536. ret = false;
  537. c_n_phandles = of_count_phandle_with_args(c_node,
  538. "regulator-coupled-with",
  539. NULL);
  540. if (c_n_phandles != n_phandles) {
  541. dev_err(&rdev->dev, "number of coupled reg phandles mismatch\n");
  542. ret = false;
  543. goto clean;
  544. }
  545. if (!of_coupling_find_node(c_node, node, &index)) {
  546. dev_err(&rdev->dev, "missing 2-way linking for coupled regulators\n");
  547. ret = false;
  548. goto clean;
  549. }
  550. if (of_property_read_u32_index(c_node, "regulator-coupled-max-spread",
  551. index, &c_max_spread)) {
  552. ret = false;
  553. goto clean;
  554. }
  555. if (c_max_spread != max_spread) {
  556. dev_err(&rdev->dev,
  557. "coupled regulators max_spread mismatch\n");
  558. ret = false;
  559. goto clean;
  560. }
  561. clean:
  562. of_node_put(c_node);
  563. if (!ret)
  564. break;
  565. }
  566. return ret;
  567. }
  568. /**
  569. * of_parse_coupled_regulator() - Get regulator_dev pointer from rdev's property
  570. * @rdev: Pointer to regulator_dev, whose DTS is used as a source to parse
  571. * "regulator-coupled-with" property
  572. * @index: Index in phandles array
  573. *
  574. * Returns the regulator_dev pointer parsed from DTS. If it has not been yet
  575. * registered, returns NULL
  576. */
  577. struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev,
  578. int index)
  579. {
  580. struct device_node *node = rdev->dev.of_node;
  581. struct device_node *c_node;
  582. struct regulator_dev *c_rdev;
  583. c_node = of_parse_phandle(node, "regulator-coupled-with", index);
  584. if (!c_node)
  585. return NULL;
  586. c_rdev = of_find_regulator_by_node(c_node);
  587. of_node_put(c_node);
  588. return c_rdev;
  589. }