1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2017 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
10 #include <fdt_support.h>
13 #include <linux/libfdt.h>
14 #include <dm/of_access.h>
15 #include <dm/of_addr.h>
16 #include <dm/ofnode.h>
17 #include <linux/err.h>
18 #include <linux/ioport.h>
19 #include <asm/global_data.h>
21 int ofnode_read_u32(ofnode node, const char *propname, u32 *outp)
23 return ofnode_read_u32_index(node, propname, 0, outp);
26 u32 ofnode_read_u32_default(ofnode node, const char *propname, u32 def)
28 assert(ofnode_valid(node));
29 ofnode_read_u32_index(node, propname, 0, &def);
34 int ofnode_read_u32_index(ofnode node, const char *propname, int index,
40 assert(ofnode_valid(node));
41 debug("%s: %s: ", __func__, propname);
43 if (ofnode_is_np(node))
44 return of_read_u32_index(ofnode_to_np(node), propname, index,
47 cell = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node), propname,
50 debug("(not found)\n");
54 if (len < (sizeof(int) * (index + 1))) {
55 debug("(not large enough)\n");
59 *outp = fdt32_to_cpu(cell[index]);
60 debug("%#x (%d)\n", *outp, *outp);
65 u32 ofnode_read_u32_index_default(ofnode node, const char *propname, int index,
68 assert(ofnode_valid(node));
69 ofnode_read_u32_index(node, propname, index, &def);
74 int ofnode_read_s32_default(ofnode node, const char *propname, s32 def)
76 assert(ofnode_valid(node));
77 ofnode_read_u32(node, propname, (u32 *)&def);
82 int ofnode_read_u64(ofnode node, const char *propname, u64 *outp)
84 const unaligned_fdt64_t *cell;
87 assert(ofnode_valid(node));
88 debug("%s: %s: ", __func__, propname);
90 if (ofnode_is_np(node))
91 return of_read_u64(ofnode_to_np(node), propname, outp);
93 cell = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node), propname,
95 if (!cell || len < sizeof(*cell)) {
96 debug("(not found)\n");
99 *outp = fdt64_to_cpu(cell[0]);
100 debug("%#llx (%lld)\n", (unsigned long long)*outp,
101 (unsigned long long)*outp);
106 u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def)
108 assert(ofnode_valid(node));
109 ofnode_read_u64(node, propname, &def);
114 bool ofnode_read_bool(ofnode node, const char *propname)
118 assert(ofnode_valid(node));
119 debug("%s: %s: ", __func__, propname);
121 prop = ofnode_get_property(node, propname, NULL);
123 debug("%s\n", prop ? "true" : "false");
125 return prop ? true : false;
128 const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep)
130 const char *val = NULL;
133 assert(ofnode_valid(node));
134 debug("%s: %s: ", __func__, propname);
136 if (ofnode_is_np(node)) {
137 struct property *prop = of_find_property(
138 ofnode_to_np(node), propname, &len);
145 val = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node),
149 debug("<not found>\n");
151 *sizep = -FDT_ERR_NOTFOUND;
160 const char *ofnode_read_string(ofnode node, const char *propname)
165 str = ofnode_read_prop(node, propname, &len);
169 if (strnlen(str, len) >= len) {
170 debug("<invalid>\n");
178 int ofnode_read_size(ofnode node, const char *propname)
182 if (!ofnode_read_prop(node, propname, &len))
188 ofnode ofnode_find_subnode(ofnode node, const char *subnode_name)
192 assert(ofnode_valid(node));
193 debug("%s: %s: ", __func__, subnode_name);
195 if (ofnode_is_np(node)) {
196 const struct device_node *np = ofnode_to_np(node);
198 for (np = np->child; np; np = np->sibling) {
199 if (!strcmp(subnode_name, np->name))
202 subnode = np_to_ofnode(np);
204 int ooffset = fdt_subnode_offset(gd->fdt_blob,
205 ofnode_to_offset(node), subnode_name);
206 subnode = offset_to_ofnode(ooffset);
208 debug("%s\n", ofnode_valid(subnode) ?
209 ofnode_get_name(subnode) : "<none>");
214 int ofnode_read_u32_array(ofnode node, const char *propname,
215 u32 *out_values, size_t sz)
217 assert(ofnode_valid(node));
218 debug("%s: %s: ", __func__, propname);
220 if (ofnode_is_np(node)) {
221 return of_read_u32_array(ofnode_to_np(node), propname,
224 return fdtdec_get_int_array(gd->fdt_blob,
225 ofnode_to_offset(node), propname,
230 #if !CONFIG_IS_ENABLED(DM_INLINE_OFNODE)
231 bool ofnode_is_enabled(ofnode node)
233 if (ofnode_is_np(node)) {
234 return of_device_is_available(ofnode_to_np(node));
236 return fdtdec_get_is_enabled(gd->fdt_blob,
237 ofnode_to_offset(node));
241 ofnode ofnode_first_subnode(ofnode node)
243 assert(ofnode_valid(node));
244 if (ofnode_is_np(node))
245 return np_to_ofnode(node.np->child);
247 return offset_to_ofnode(
248 fdt_first_subnode(gd->fdt_blob, ofnode_to_offset(node)));
251 ofnode ofnode_next_subnode(ofnode node)
253 assert(ofnode_valid(node));
254 if (ofnode_is_np(node))
255 return np_to_ofnode(node.np->sibling);
257 return offset_to_ofnode(
258 fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node)));
260 #endif /* !DM_INLINE_OFNODE */
262 ofnode ofnode_get_parent(ofnode node)
266 assert(ofnode_valid(node));
267 if (ofnode_is_np(node))
268 parent = np_to_ofnode(of_get_parent(ofnode_to_np(node)));
270 parent.of_offset = fdt_parent_offset(gd->fdt_blob,
271 ofnode_to_offset(node));
276 const char *ofnode_get_name(ofnode node)
278 if (!ofnode_valid(node)) {
279 debug("%s node not valid\n", __func__);
283 if (ofnode_is_np(node))
284 return strrchr(node.np->full_name, '/') + 1;
286 return fdt_get_name(gd->fdt_blob, ofnode_to_offset(node), NULL);
289 int ofnode_get_path(ofnode node, char *buf, int buflen)
291 assert(ofnode_valid(node));
293 if (ofnode_is_np(node)) {
294 if (strlen(node.np->full_name) >= buflen)
297 strcpy(buf, node.np->full_name);
303 res = fdt_get_path(gd->fdt_blob, ofnode_to_offset(node), buf,
307 else if (res == -FDT_ERR_NOSPACE)
314 ofnode ofnode_get_by_phandle(uint phandle)
318 if (of_live_active())
319 node = np_to_ofnode(of_find_node_by_phandle(phandle));
321 node.of_offset = fdt_node_offset_by_phandle(gd->fdt_blob,
327 static fdt_addr_t __ofnode_get_addr_size_index(ofnode node, int index,
328 fdt_size_t *size, bool translate)
332 *size = FDT_SIZE_T_NONE;
334 if (ofnode_is_np(node)) {
335 const __be32 *prop_val;
339 prop_val = of_get_address(ofnode_to_np(node), index, &size64,
342 return FDT_ADDR_T_NONE;
346 ns = of_n_size_cells(ofnode_to_np(node));
348 if (translate && IS_ENABLED(CONFIG_OF_TRANSLATE) && ns > 0) {
349 return of_translate_address(ofnode_to_np(node), prop_val);
351 na = of_n_addr_cells(ofnode_to_np(node));
352 return of_read_number(prop_val, na);
355 na = ofnode_read_simple_addr_cells(ofnode_get_parent(node));
356 ns = ofnode_read_simple_size_cells(ofnode_get_parent(node));
357 return fdtdec_get_addr_size_fixed(gd->fdt_blob,
358 ofnode_to_offset(node), "reg",
363 return FDT_ADDR_T_NONE;
366 fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size)
368 return __ofnode_get_addr_size_index(node, index, size, true);
371 fdt_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
374 return __ofnode_get_addr_size_index(node, index, size, false);
377 fdt_addr_t ofnode_get_addr_index(ofnode node, int index)
381 return ofnode_get_addr_size_index(node, index, &size);
384 fdt_addr_t ofnode_get_addr(ofnode node)
386 return ofnode_get_addr_index(node, 0);
389 fdt_size_t ofnode_get_size(ofnode node)
393 ofnode_get_addr_size_index(node, 0, &size);
398 int ofnode_stringlist_search(ofnode node, const char *property,
401 if (ofnode_is_np(node)) {
402 return of_property_match_string(ofnode_to_np(node),
407 ret = fdt_stringlist_search(gd->fdt_blob,
408 ofnode_to_offset(node), property,
410 if (ret == -FDT_ERR_NOTFOUND)
419 int ofnode_read_string_index(ofnode node, const char *property, int index,
422 if (ofnode_is_np(node)) {
423 return of_property_read_string_index(ofnode_to_np(node),
424 property, index, outp);
428 *outp = fdt_stringlist_get(gd->fdt_blob, ofnode_to_offset(node),
429 property, index, &len);
436 int ofnode_read_string_count(ofnode node, const char *property)
438 if (ofnode_is_np(node)) {
439 return of_property_count_strings(ofnode_to_np(node), property);
441 return fdt_stringlist_count(gd->fdt_blob,
442 ofnode_to_offset(node), property);
446 static void ofnode_from_fdtdec_phandle_args(struct fdtdec_phandle_args *in,
447 struct ofnode_phandle_args *out)
449 assert(OF_MAX_PHANDLE_ARGS == MAX_PHANDLE_ARGS);
450 out->node = offset_to_ofnode(in->node);
451 out->args_count = in->args_count;
452 memcpy(out->args, in->args, sizeof(out->args));
455 static void ofnode_from_of_phandle_args(struct of_phandle_args *in,
456 struct ofnode_phandle_args *out)
458 assert(OF_MAX_PHANDLE_ARGS == MAX_PHANDLE_ARGS);
459 out->node = np_to_ofnode(in->np);
460 out->args_count = in->args_count;
461 memcpy(out->args, in->args, sizeof(out->args));
464 int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
465 const char *cells_name, int cell_count,
467 struct ofnode_phandle_args *out_args)
469 if (ofnode_is_np(node)) {
470 struct of_phandle_args args;
473 ret = of_parse_phandle_with_args(ofnode_to_np(node),
474 list_name, cells_name,
479 ofnode_from_of_phandle_args(&args, out_args);
481 struct fdtdec_phandle_args args;
484 ret = fdtdec_parse_phandle_with_args(gd->fdt_blob,
485 ofnode_to_offset(node),
486 list_name, cells_name,
487 cell_count, index, &args);
490 ofnode_from_fdtdec_phandle_args(&args, out_args);
496 int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
497 const char *cells_name, int cell_count)
499 if (ofnode_is_np(node))
500 return of_count_phandle_with_args(ofnode_to_np(node),
501 list_name, cells_name, cell_count);
503 return fdtdec_parse_phandle_with_args(gd->fdt_blob,
504 ofnode_to_offset(node), list_name, cells_name,
505 cell_count, -1, NULL);
508 ofnode ofnode_path(const char *path)
510 if (of_live_active())
511 return np_to_ofnode(of_find_node_by_path(path));
513 return offset_to_ofnode(fdt_path_offset(gd->fdt_blob, path));
516 const void *ofnode_read_chosen_prop(const char *propname, int *sizep)
520 chosen_node = ofnode_path("/chosen");
522 return ofnode_read_prop(chosen_node, propname, sizep);
525 const char *ofnode_read_chosen_string(const char *propname)
527 return ofnode_read_chosen_prop(propname, NULL);
530 ofnode ofnode_get_chosen_node(const char *name)
534 prop = ofnode_read_chosen_prop(name, NULL);
536 return ofnode_null();
538 return ofnode_path(prop);
541 const void *ofnode_read_aliases_prop(const char *propname, int *sizep)
545 node = ofnode_path("/aliases");
547 return ofnode_read_prop(node, propname, sizep);
550 ofnode ofnode_get_aliases_node(const char *name)
554 prop = ofnode_read_aliases_prop(name, NULL);
556 return ofnode_null();
558 debug("%s: node_path: %s\n", __func__, prop);
560 return ofnode_path(prop);
563 int ofnode_get_child_count(ofnode parent)
568 ofnode_for_each_subnode(child, parent)
574 static int decode_timing_property(ofnode node, const char *name,
575 struct timing_entry *result)
579 length = ofnode_read_size(node, name);
581 debug("%s: could not find property %s\n",
582 ofnode_get_name(node), name);
586 if (length == sizeof(u32)) {
587 result->typ = ofnode_read_u32_default(node, name, 0);
588 result->min = result->typ;
589 result->max = result->typ;
591 ret = ofnode_read_u32_array(node, name, &result->min, 3);
597 int ofnode_decode_display_timing(ofnode parent, int index,
598 struct display_timing *dt)
601 ofnode timings, node;
605 timings = ofnode_find_subnode(parent, "display-timings");
606 if (!ofnode_valid(timings))
610 ofnode_for_each_subnode(node, timings) {
615 if (!ofnode_valid(node))
618 memset(dt, 0, sizeof(*dt));
620 ret |= decode_timing_property(node, "hback-porch", &dt->hback_porch);
621 ret |= decode_timing_property(node, "hfront-porch", &dt->hfront_porch);
622 ret |= decode_timing_property(node, "hactive", &dt->hactive);
623 ret |= decode_timing_property(node, "hsync-len", &dt->hsync_len);
624 ret |= decode_timing_property(node, "vback-porch", &dt->vback_porch);
625 ret |= decode_timing_property(node, "vfront-porch", &dt->vfront_porch);
626 ret |= decode_timing_property(node, "vactive", &dt->vactive);
627 ret |= decode_timing_property(node, "vsync-len", &dt->vsync_len);
628 ret |= decode_timing_property(node, "clock-frequency", &dt->pixelclock);
631 val = ofnode_read_u32_default(node, "vsync-active", -1);
633 dt->flags |= val ? DISPLAY_FLAGS_VSYNC_HIGH :
634 DISPLAY_FLAGS_VSYNC_LOW;
636 val = ofnode_read_u32_default(node, "hsync-active", -1);
638 dt->flags |= val ? DISPLAY_FLAGS_HSYNC_HIGH :
639 DISPLAY_FLAGS_HSYNC_LOW;
641 val = ofnode_read_u32_default(node, "de-active", -1);
643 dt->flags |= val ? DISPLAY_FLAGS_DE_HIGH :
644 DISPLAY_FLAGS_DE_LOW;
646 val = ofnode_read_u32_default(node, "pixelclk-active", -1);
648 dt->flags |= val ? DISPLAY_FLAGS_PIXDATA_POSEDGE :
649 DISPLAY_FLAGS_PIXDATA_NEGEDGE;
652 if (ofnode_read_bool(node, "interlaced"))
653 dt->flags |= DISPLAY_FLAGS_INTERLACED;
654 if (ofnode_read_bool(node, "doublescan"))
655 dt->flags |= DISPLAY_FLAGS_DOUBLESCAN;
656 if (ofnode_read_bool(node, "doubleclk"))
657 dt->flags |= DISPLAY_FLAGS_DOUBLECLK;
662 const void *ofnode_get_property(ofnode node, const char *propname, int *lenp)
664 if (ofnode_is_np(node))
665 return of_get_property(ofnode_to_np(node), propname, lenp);
667 return fdt_getprop(gd->fdt_blob, ofnode_to_offset(node),
671 int ofnode_get_first_property(ofnode node, struct ofprop *prop)
675 if (ofnode_is_np(node)) {
676 prop->prop = of_get_first_property(ofnode_to_np(prop->node));
678 return -FDT_ERR_NOTFOUND;
681 fdt_first_property_offset(gd->fdt_blob,
682 ofnode_to_offset(prop->node));
683 if (prop->offset < 0)
690 int ofnode_get_next_property(struct ofprop *prop)
692 if (ofnode_is_np(prop->node)) {
693 prop->prop = of_get_next_property(ofnode_to_np(prop->node),
696 return -FDT_ERR_NOTFOUND;
698 prop->offset = fdt_next_property_offset(gd->fdt_blob,
700 if (prop->offset < 0)
707 const void *ofnode_get_property_by_prop(const struct ofprop *prop,
708 const char **propname, int *lenp)
710 if (ofnode_is_np(prop->node))
711 return of_get_property_by_prop(ofnode_to_np(prop->node),
712 prop->prop, propname, lenp);
714 return fdt_getprop_by_offset(gd->fdt_blob,
719 bool ofnode_is_available(ofnode node)
721 if (ofnode_is_np(node))
722 return of_device_is_available(ofnode_to_np(node));
724 return fdtdec_get_is_enabled(gd->fdt_blob,
725 ofnode_to_offset(node));
728 fdt_addr_t ofnode_get_addr_size(ofnode node, const char *property,
731 if (ofnode_is_np(node)) {
734 const struct device_node *np = ofnode_to_np(node);
735 const __be32 *prop = of_get_property(np, property, &psize);
738 return FDT_ADDR_T_NONE;
739 na = of_n_addr_cells(np);
740 ns = of_n_size_cells(np);
741 *sizep = of_read_number(prop + na, ns);
743 if (CONFIG_IS_ENABLED(OF_TRANSLATE) && ns > 0)
744 return of_translate_address(np, prop);
746 return of_read_number(prop, na);
748 return fdtdec_get_addr_size(gd->fdt_blob,
749 ofnode_to_offset(node), property,
754 const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname,
757 if (ofnode_is_np(node)) {
758 const struct device_node *np = ofnode_to_np(node);
760 const __be32 *prop = of_get_property(np, propname, &psize);
762 if (!prop || sz != psize)
764 return (uint8_t *)prop;
767 return fdtdec_locate_byte_array(gd->fdt_blob,
768 ofnode_to_offset(node), propname, sz);
772 int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
773 const char *propname, struct fdt_pci_addr *addr)
779 debug("%s: %s: ", __func__, propname);
782 * If we follow the pci bus bindings strictly, we should check
783 * the value of the node's parent node's #address-cells and
784 * #size-cells. They need to be 3 and 2 accordingly. However,
785 * for simplicity we skip the check here.
787 cell = ofnode_get_property(node, propname, &len);
791 if ((len % FDT_PCI_REG_SIZE) == 0) {
792 int num = len / FDT_PCI_REG_SIZE;
795 for (i = 0; i < num; i++) {
796 debug("pci address #%d: %08lx %08lx %08lx\n", i,
797 (ulong)fdt32_to_cpu(cell[0]),
798 (ulong)fdt32_to_cpu(cell[1]),
799 (ulong)fdt32_to_cpu(cell[2]));
800 if ((fdt32_to_cpu(*cell) & type) == type) {
801 addr->phys_hi = fdt32_to_cpu(cell[0]);
802 addr->phys_mid = fdt32_to_cpu(cell[1]);
803 addr->phys_lo = fdt32_to_cpu(cell[2]);
807 cell += (FDT_PCI_ADDR_CELLS +
822 debug("(not found)\n");
826 int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device)
828 const char *list, *end;
831 list = ofnode_get_property(node, "compatible", &len);
838 if (len >= strlen("pciVVVV,DDDD")) {
839 char *s = strstr(list, "pci");
842 * check if the string is something like pciVVVV,DDDD.RR
843 * or just pciVVVV,DDDD
845 if (s && s[7] == ',' &&
846 (s[12] == '.' || s[12] == 0)) {
848 *vendor = simple_strtol(s, NULL, 16);
851 *device = simple_strtol(s, NULL, 16);
862 int ofnode_read_addr_cells(ofnode node)
864 if (ofnode_is_np(node)) {
865 return of_n_addr_cells(ofnode_to_np(node));
867 int parent = fdt_parent_offset(gd->fdt_blob,
868 ofnode_to_offset(node));
870 return fdt_address_cells(gd->fdt_blob, parent);
874 int ofnode_read_size_cells(ofnode node)
876 if (ofnode_is_np(node)) {
877 return of_n_size_cells(ofnode_to_np(node));
879 int parent = fdt_parent_offset(gd->fdt_blob,
880 ofnode_to_offset(node));
882 return fdt_size_cells(gd->fdt_blob, parent);
886 int ofnode_read_simple_addr_cells(ofnode node)
888 if (ofnode_is_np(node))
889 return of_simple_addr_cells(ofnode_to_np(node));
891 return fdt_address_cells(gd->fdt_blob, ofnode_to_offset(node));
894 int ofnode_read_simple_size_cells(ofnode node)
896 if (ofnode_is_np(node))
897 return of_simple_size_cells(ofnode_to_np(node));
899 return fdt_size_cells(gd->fdt_blob, ofnode_to_offset(node));
902 bool ofnode_pre_reloc(ofnode node)
904 #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_TPL_BUILD)
905 /* for SPL and TPL the remaining nodes after the fdtgrep 1st pass
906 * had property dm-pre-reloc or u-boot,dm-spl/tpl.
907 * They are removed in final dtb (fdtgrep 2nd pass)
911 if (ofnode_read_bool(node, "u-boot,dm-pre-reloc"))
913 if (ofnode_read_bool(node, "u-boot,dm-pre-proper"))
917 * In regular builds individual spl and tpl handling both
918 * count as handled pre-relocation for later second init.
920 if (ofnode_read_bool(node, "u-boot,dm-spl") ||
921 ofnode_read_bool(node, "u-boot,dm-tpl"))
928 int ofnode_read_resource(ofnode node, uint index, struct resource *res)
930 if (ofnode_is_np(node)) {
931 return of_address_to_resource(ofnode_to_np(node), index, res);
933 struct fdt_resource fres;
936 ret = fdt_get_resource(gd->fdt_blob, ofnode_to_offset(node),
937 "reg", index, &fres);
940 memset(res, '\0', sizeof(*res));
941 res->start = fres.start;
948 int ofnode_read_resource_byname(ofnode node, const char *name,
949 struct resource *res)
953 index = ofnode_stringlist_search(node, "reg-names", name);
957 return ofnode_read_resource(node, index, res);
960 u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr)
962 if (ofnode_is_np(node))
963 return of_translate_address(ofnode_to_np(node), in_addr);
965 return fdt_translate_address(gd->fdt_blob, ofnode_to_offset(node), in_addr);
968 u64 ofnode_translate_dma_address(ofnode node, const fdt32_t *in_addr)
970 if (ofnode_is_np(node))
971 return of_translate_dma_address(ofnode_to_np(node), in_addr);
973 return fdt_translate_dma_address(gd->fdt_blob, ofnode_to_offset(node), in_addr);
976 int ofnode_get_dma_range(ofnode node, phys_addr_t *cpu, dma_addr_t *bus, u64 *size)
978 if (ofnode_is_np(node))
979 return of_get_dma_range(ofnode_to_np(node), cpu, bus, size);
981 return fdt_get_dma_range(gd->fdt_blob, ofnode_to_offset(node),
985 int ofnode_device_is_compatible(ofnode node, const char *compat)
987 if (ofnode_is_np(node))
988 return of_device_is_compatible(ofnode_to_np(node), compat,
991 return !fdt_node_check_compatible(gd->fdt_blob,
992 ofnode_to_offset(node),
996 ofnode ofnode_by_compatible(ofnode from, const char *compat)
998 if (of_live_active()) {
999 return np_to_ofnode(of_find_compatible_node(
1000 (struct device_node *)ofnode_to_np(from), NULL,
1003 return offset_to_ofnode(fdt_node_offset_by_compatible(
1004 gd->fdt_blob, ofnode_to_offset(from), compat));
1008 ofnode ofnode_by_prop_value(ofnode from, const char *propname,
1009 const void *propval, int proplen)
1011 if (of_live_active()) {
1012 return np_to_ofnode(of_find_node_by_prop_value(
1013 (struct device_node *)ofnode_to_np(from), propname,
1016 return offset_to_ofnode(fdt_node_offset_by_prop_value(
1017 gd->fdt_blob, ofnode_to_offset(from),
1018 propname, propval, proplen));
1022 int ofnode_write_prop(ofnode node, const char *propname, int len,
1025 const struct device_node *np = ofnode_to_np(node);
1026 struct property *pp;
1027 struct property *pp_last = NULL;
1028 struct property *new;
1030 if (!of_live_active())
1036 for (pp = np->properties; pp; pp = pp->next) {
1037 if (strcmp(pp->name, propname) == 0) {
1038 /* Property exists -> change value */
1039 pp->value = (void *)value;
1049 /* Property does not exist -> append new property */
1050 new = malloc(sizeof(struct property));
1054 new->name = strdup(propname);
1060 new->value = (void *)value;
1064 pp_last->next = new;
1069 int ofnode_write_string(ofnode node, const char *propname, const char *value)
1071 if (!of_live_active())
1074 assert(ofnode_valid(node));
1076 debug("%s: %s = %s", __func__, propname, value);
1078 return ofnode_write_prop(node, propname, strlen(value) + 1, value);
1081 int ofnode_set_enabled(ofnode node, bool value)
1083 if (!of_live_active())
1086 assert(ofnode_valid(node));
1089 return ofnode_write_string(node, "status", "okay");
1091 return ofnode_write_string(node, "status", "disabled");