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 bool ofnode_name_eq(ofnode node, const char *name)
23 const char *node_name;
26 assert(ofnode_valid(node));
28 node_name = ofnode_get_name(node);
29 len = strchrnul(node_name, '@') - node_name;
31 return (strlen(name) == len) && !strncmp(node_name, name, len);
34 int ofnode_read_u32(ofnode node, const char *propname, u32 *outp)
36 return ofnode_read_u32_index(node, propname, 0, outp);
39 u32 ofnode_read_u32_default(ofnode node, const char *propname, u32 def)
41 assert(ofnode_valid(node));
42 ofnode_read_u32_index(node, propname, 0, &def);
47 int ofnode_read_u32_index(ofnode node, const char *propname, int index,
53 assert(ofnode_valid(node));
54 debug("%s: %s: ", __func__, propname);
56 if (ofnode_is_np(node))
57 return of_read_u32_index(ofnode_to_np(node), propname, index,
60 cell = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node), propname,
63 debug("(not found)\n");
67 if (len < (sizeof(int) * (index + 1))) {
68 debug("(not large enough)\n");
72 *outp = fdt32_to_cpu(cell[index]);
73 debug("%#x (%d)\n", *outp, *outp);
78 u32 ofnode_read_u32_index_default(ofnode node, const char *propname, int index,
81 assert(ofnode_valid(node));
82 ofnode_read_u32_index(node, propname, index, &def);
87 int ofnode_read_s32_default(ofnode node, const char *propname, s32 def)
89 assert(ofnode_valid(node));
90 ofnode_read_u32(node, propname, (u32 *)&def);
95 int ofnode_read_u64(ofnode node, const char *propname, u64 *outp)
97 const unaligned_fdt64_t *cell;
100 assert(ofnode_valid(node));
101 debug("%s: %s: ", __func__, propname);
103 if (ofnode_is_np(node))
104 return of_read_u64(ofnode_to_np(node), propname, outp);
106 cell = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node), propname,
108 if (!cell || len < sizeof(*cell)) {
109 debug("(not found)\n");
112 *outp = fdt64_to_cpu(cell[0]);
113 debug("%#llx (%lld)\n", (unsigned long long)*outp,
114 (unsigned long long)*outp);
119 u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def)
121 assert(ofnode_valid(node));
122 ofnode_read_u64(node, propname, &def);
127 bool ofnode_read_bool(ofnode node, const char *propname)
131 assert(ofnode_valid(node));
132 debug("%s: %s: ", __func__, propname);
134 prop = ofnode_get_property(node, propname, NULL);
136 debug("%s\n", prop ? "true" : "false");
138 return prop ? true : false;
141 const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep)
143 const char *val = NULL;
146 assert(ofnode_valid(node));
147 debug("%s: %s: ", __func__, propname);
149 if (ofnode_is_np(node)) {
150 struct property *prop = of_find_property(
151 ofnode_to_np(node), propname, &len);
158 val = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node),
162 debug("<not found>\n");
164 *sizep = -FDT_ERR_NOTFOUND;
173 const char *ofnode_read_string(ofnode node, const char *propname)
178 str = ofnode_read_prop(node, propname, &len);
182 if (strnlen(str, len) >= len) {
183 debug("<invalid>\n");
191 int ofnode_read_size(ofnode node, const char *propname)
195 if (!ofnode_read_prop(node, propname, &len))
201 ofnode ofnode_find_subnode(ofnode node, const char *subnode_name)
205 assert(ofnode_valid(node));
206 debug("%s: %s: ", __func__, subnode_name);
208 if (ofnode_is_np(node)) {
209 const struct device_node *np = ofnode_to_np(node);
211 for (np = np->child; np; np = np->sibling) {
212 if (!strcmp(subnode_name, np->name))
215 subnode = np_to_ofnode(np);
217 int ooffset = fdt_subnode_offset(gd->fdt_blob,
218 ofnode_to_offset(node), subnode_name);
219 subnode = offset_to_ofnode(ooffset);
221 debug("%s\n", ofnode_valid(subnode) ?
222 ofnode_get_name(subnode) : "<none>");
227 int ofnode_read_u32_array(ofnode node, const char *propname,
228 u32 *out_values, size_t sz)
230 assert(ofnode_valid(node));
231 debug("%s: %s: ", __func__, propname);
233 if (ofnode_is_np(node)) {
234 return of_read_u32_array(ofnode_to_np(node), propname,
237 return fdtdec_get_int_array(gd->fdt_blob,
238 ofnode_to_offset(node), propname,
243 #if !CONFIG_IS_ENABLED(DM_INLINE_OFNODE)
244 bool ofnode_is_enabled(ofnode node)
246 if (ofnode_is_np(node)) {
247 return of_device_is_available(ofnode_to_np(node));
249 return fdtdec_get_is_enabled(gd->fdt_blob,
250 ofnode_to_offset(node));
254 ofnode ofnode_first_subnode(ofnode node)
256 assert(ofnode_valid(node));
257 if (ofnode_is_np(node))
258 return np_to_ofnode(node.np->child);
260 return offset_to_ofnode(
261 fdt_first_subnode(gd->fdt_blob, ofnode_to_offset(node)));
264 ofnode ofnode_next_subnode(ofnode node)
266 assert(ofnode_valid(node));
267 if (ofnode_is_np(node))
268 return np_to_ofnode(node.np->sibling);
270 return offset_to_ofnode(
271 fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node)));
273 #endif /* !DM_INLINE_OFNODE */
275 ofnode ofnode_get_parent(ofnode node)
279 assert(ofnode_valid(node));
280 if (ofnode_is_np(node))
281 parent = np_to_ofnode(of_get_parent(ofnode_to_np(node)));
283 parent.of_offset = fdt_parent_offset(gd->fdt_blob,
284 ofnode_to_offset(node));
289 const char *ofnode_get_name(ofnode node)
291 if (!ofnode_valid(node)) {
292 debug("%s node not valid\n", __func__);
296 if (ofnode_is_np(node))
297 return strrchr(node.np->full_name, '/') + 1;
299 return fdt_get_name(gd->fdt_blob, ofnode_to_offset(node), NULL);
302 int ofnode_get_path(ofnode node, char *buf, int buflen)
304 assert(ofnode_valid(node));
306 if (ofnode_is_np(node)) {
307 if (strlen(node.np->full_name) >= buflen)
310 strcpy(buf, node.np->full_name);
316 res = fdt_get_path(gd->fdt_blob, ofnode_to_offset(node), buf,
320 else if (res == -FDT_ERR_NOSPACE)
327 ofnode ofnode_get_by_phandle(uint phandle)
331 if (of_live_active())
332 node = np_to_ofnode(of_find_node_by_phandle(phandle));
334 node.of_offset = fdt_node_offset_by_phandle(gd->fdt_blob,
340 static fdt_addr_t __ofnode_get_addr_size_index(ofnode node, int index,
341 fdt_size_t *size, bool translate)
346 *size = FDT_SIZE_T_NONE;
348 if (ofnode_is_np(node)) {
349 const __be32 *prop_val;
353 prop_val = of_get_address(ofnode_to_np(node), index, &size64,
356 return FDT_ADDR_T_NONE;
361 ns = of_n_size_cells(ofnode_to_np(node));
363 if (translate && IS_ENABLED(CONFIG_OF_TRANSLATE) && ns > 0) {
364 return of_translate_address(ofnode_to_np(node), prop_val);
366 na = of_n_addr_cells(ofnode_to_np(node));
367 return of_read_number(prop_val, na);
370 na = ofnode_read_simple_addr_cells(ofnode_get_parent(node));
371 ns = ofnode_read_simple_size_cells(ofnode_get_parent(node));
372 return fdtdec_get_addr_size_fixed(gd->fdt_blob,
373 ofnode_to_offset(node), "reg",
379 fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size)
381 return __ofnode_get_addr_size_index(node, index, size, true);
384 fdt_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
387 return __ofnode_get_addr_size_index(node, index, size, false);
390 fdt_addr_t ofnode_get_addr_index(ofnode node, int index)
394 return ofnode_get_addr_size_index(node, index, &size);
397 fdt_addr_t ofnode_get_addr(ofnode node)
399 return ofnode_get_addr_index(node, 0);
402 fdt_size_t ofnode_get_size(ofnode node)
406 ofnode_get_addr_size_index(node, 0, &size);
411 int ofnode_stringlist_search(ofnode node, const char *property,
414 if (ofnode_is_np(node)) {
415 return of_property_match_string(ofnode_to_np(node),
420 ret = fdt_stringlist_search(gd->fdt_blob,
421 ofnode_to_offset(node), property,
423 if (ret == -FDT_ERR_NOTFOUND)
432 int ofnode_read_string_index(ofnode node, const char *property, int index,
435 if (ofnode_is_np(node)) {
436 return of_property_read_string_index(ofnode_to_np(node),
437 property, index, outp);
441 *outp = fdt_stringlist_get(gd->fdt_blob, ofnode_to_offset(node),
442 property, index, &len);
449 int ofnode_read_string_count(ofnode node, const char *property)
451 if (ofnode_is_np(node)) {
452 return of_property_count_strings(ofnode_to_np(node), property);
454 return fdt_stringlist_count(gd->fdt_blob,
455 ofnode_to_offset(node), property);
459 static void ofnode_from_fdtdec_phandle_args(struct fdtdec_phandle_args *in,
460 struct ofnode_phandle_args *out)
462 assert(OF_MAX_PHANDLE_ARGS == MAX_PHANDLE_ARGS);
463 out->node = offset_to_ofnode(in->node);
464 out->args_count = in->args_count;
465 memcpy(out->args, in->args, sizeof(out->args));
468 static void ofnode_from_of_phandle_args(struct of_phandle_args *in,
469 struct ofnode_phandle_args *out)
471 assert(OF_MAX_PHANDLE_ARGS == MAX_PHANDLE_ARGS);
472 out->node = np_to_ofnode(in->np);
473 out->args_count = in->args_count;
474 memcpy(out->args, in->args, sizeof(out->args));
477 int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
478 const char *cells_name, int cell_count,
480 struct ofnode_phandle_args *out_args)
482 if (ofnode_is_np(node)) {
483 struct of_phandle_args args;
486 ret = of_parse_phandle_with_args(ofnode_to_np(node),
487 list_name, cells_name,
492 ofnode_from_of_phandle_args(&args, out_args);
494 struct fdtdec_phandle_args args;
497 ret = fdtdec_parse_phandle_with_args(gd->fdt_blob,
498 ofnode_to_offset(node),
499 list_name, cells_name,
500 cell_count, index, &args);
503 ofnode_from_fdtdec_phandle_args(&args, out_args);
509 int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
510 const char *cells_name, int cell_count)
512 if (ofnode_is_np(node))
513 return of_count_phandle_with_args(ofnode_to_np(node),
514 list_name, cells_name, cell_count);
516 return fdtdec_parse_phandle_with_args(gd->fdt_blob,
517 ofnode_to_offset(node), list_name, cells_name,
518 cell_count, -1, NULL);
521 ofnode ofnode_path(const char *path)
523 if (of_live_active())
524 return np_to_ofnode(of_find_node_by_path(path));
526 return offset_to_ofnode(fdt_path_offset(gd->fdt_blob, path));
529 const void *ofnode_read_chosen_prop(const char *propname, int *sizep)
533 chosen_node = ofnode_path("/chosen");
535 return ofnode_read_prop(chosen_node, propname, sizep);
538 const char *ofnode_read_chosen_string(const char *propname)
540 return ofnode_read_chosen_prop(propname, NULL);
543 ofnode ofnode_get_chosen_node(const char *name)
547 prop = ofnode_read_chosen_prop(name, NULL);
549 return ofnode_null();
551 return ofnode_path(prop);
554 const void *ofnode_read_aliases_prop(const char *propname, int *sizep)
558 node = ofnode_path("/aliases");
560 return ofnode_read_prop(node, propname, sizep);
563 ofnode ofnode_get_aliases_node(const char *name)
567 prop = ofnode_read_aliases_prop(name, NULL);
569 return ofnode_null();
571 debug("%s: node_path: %s\n", __func__, prop);
573 return ofnode_path(prop);
576 int ofnode_get_child_count(ofnode parent)
581 ofnode_for_each_subnode(child, parent)
587 static int decode_timing_property(ofnode node, const char *name,
588 struct timing_entry *result)
592 length = ofnode_read_size(node, name);
594 debug("%s: could not find property %s\n",
595 ofnode_get_name(node), name);
599 if (length == sizeof(u32)) {
600 result->typ = ofnode_read_u32_default(node, name, 0);
601 result->min = result->typ;
602 result->max = result->typ;
604 ret = ofnode_read_u32_array(node, name, &result->min, 3);
610 int ofnode_decode_display_timing(ofnode parent, int index,
611 struct display_timing *dt)
614 ofnode timings, node;
618 timings = ofnode_find_subnode(parent, "display-timings");
619 if (!ofnode_valid(timings))
623 ofnode_for_each_subnode(node, timings) {
628 if (!ofnode_valid(node))
631 memset(dt, 0, sizeof(*dt));
633 ret |= decode_timing_property(node, "hback-porch", &dt->hback_porch);
634 ret |= decode_timing_property(node, "hfront-porch", &dt->hfront_porch);
635 ret |= decode_timing_property(node, "hactive", &dt->hactive);
636 ret |= decode_timing_property(node, "hsync-len", &dt->hsync_len);
637 ret |= decode_timing_property(node, "vback-porch", &dt->vback_porch);
638 ret |= decode_timing_property(node, "vfront-porch", &dt->vfront_porch);
639 ret |= decode_timing_property(node, "vactive", &dt->vactive);
640 ret |= decode_timing_property(node, "vsync-len", &dt->vsync_len);
641 ret |= decode_timing_property(node, "clock-frequency", &dt->pixelclock);
644 val = ofnode_read_u32_default(node, "vsync-active", -1);
646 dt->flags |= val ? DISPLAY_FLAGS_VSYNC_HIGH :
647 DISPLAY_FLAGS_VSYNC_LOW;
649 val = ofnode_read_u32_default(node, "hsync-active", -1);
651 dt->flags |= val ? DISPLAY_FLAGS_HSYNC_HIGH :
652 DISPLAY_FLAGS_HSYNC_LOW;
654 val = ofnode_read_u32_default(node, "de-active", -1);
656 dt->flags |= val ? DISPLAY_FLAGS_DE_HIGH :
657 DISPLAY_FLAGS_DE_LOW;
659 val = ofnode_read_u32_default(node, "pixelclk-active", -1);
661 dt->flags |= val ? DISPLAY_FLAGS_PIXDATA_POSEDGE :
662 DISPLAY_FLAGS_PIXDATA_NEGEDGE;
665 if (ofnode_read_bool(node, "interlaced"))
666 dt->flags |= DISPLAY_FLAGS_INTERLACED;
667 if (ofnode_read_bool(node, "doublescan"))
668 dt->flags |= DISPLAY_FLAGS_DOUBLESCAN;
669 if (ofnode_read_bool(node, "doubleclk"))
670 dt->flags |= DISPLAY_FLAGS_DOUBLECLK;
675 const void *ofnode_get_property(ofnode node, const char *propname, int *lenp)
677 if (ofnode_is_np(node))
678 return of_get_property(ofnode_to_np(node), propname, lenp);
680 return fdt_getprop(gd->fdt_blob, ofnode_to_offset(node),
684 int ofnode_get_first_property(ofnode node, struct ofprop *prop)
688 if (ofnode_is_np(node)) {
689 prop->prop = of_get_first_property(ofnode_to_np(prop->node));
691 return -FDT_ERR_NOTFOUND;
694 fdt_first_property_offset(gd->fdt_blob,
695 ofnode_to_offset(prop->node));
696 if (prop->offset < 0)
703 int ofnode_get_next_property(struct ofprop *prop)
705 if (ofnode_is_np(prop->node)) {
706 prop->prop = of_get_next_property(ofnode_to_np(prop->node),
709 return -FDT_ERR_NOTFOUND;
711 prop->offset = fdt_next_property_offset(gd->fdt_blob,
713 if (prop->offset < 0)
720 const void *ofnode_get_property_by_prop(const struct ofprop *prop,
721 const char **propname, int *lenp)
723 if (ofnode_is_np(prop->node))
724 return of_get_property_by_prop(ofnode_to_np(prop->node),
725 prop->prop, propname, lenp);
727 return fdt_getprop_by_offset(gd->fdt_blob,
732 bool ofnode_is_available(ofnode node)
734 if (ofnode_is_np(node))
735 return of_device_is_available(ofnode_to_np(node));
737 return fdtdec_get_is_enabled(gd->fdt_blob,
738 ofnode_to_offset(node));
741 fdt_addr_t ofnode_get_addr_size(ofnode node, const char *property,
744 if (ofnode_is_np(node)) {
747 const struct device_node *np = ofnode_to_np(node);
748 const __be32 *prop = of_get_property(np, property, &psize);
751 return FDT_ADDR_T_NONE;
752 na = of_n_addr_cells(np);
753 ns = of_n_size_cells(np);
754 *sizep = of_read_number(prop + na, ns);
756 if (CONFIG_IS_ENABLED(OF_TRANSLATE) && ns > 0)
757 return of_translate_address(np, prop);
759 return of_read_number(prop, na);
761 return fdtdec_get_addr_size(gd->fdt_blob,
762 ofnode_to_offset(node), property,
767 const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname,
770 if (ofnode_is_np(node)) {
771 const struct device_node *np = ofnode_to_np(node);
773 const __be32 *prop = of_get_property(np, propname, &psize);
775 if (!prop || sz != psize)
777 return (uint8_t *)prop;
780 return fdtdec_locate_byte_array(gd->fdt_blob,
781 ofnode_to_offset(node), propname, sz);
785 int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
786 const char *propname, struct fdt_pci_addr *addr)
792 debug("%s: %s: ", __func__, propname);
795 * If we follow the pci bus bindings strictly, we should check
796 * the value of the node's parent node's #address-cells and
797 * #size-cells. They need to be 3 and 2 accordingly. However,
798 * for simplicity we skip the check here.
800 cell = ofnode_get_property(node, propname, &len);
804 if ((len % FDT_PCI_REG_SIZE) == 0) {
805 int num = len / FDT_PCI_REG_SIZE;
808 for (i = 0; i < num; i++) {
809 debug("pci address #%d: %08lx %08lx %08lx\n", i,
810 (ulong)fdt32_to_cpu(cell[0]),
811 (ulong)fdt32_to_cpu(cell[1]),
812 (ulong)fdt32_to_cpu(cell[2]));
813 if ((fdt32_to_cpu(*cell) & type) == type) {
814 addr->phys_hi = fdt32_to_cpu(cell[0]);
815 addr->phys_mid = fdt32_to_cpu(cell[1]);
816 addr->phys_lo = fdt32_to_cpu(cell[2]);
820 cell += (FDT_PCI_ADDR_CELLS +
835 debug("(not found)\n");
839 int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device)
841 const char *list, *end;
844 list = ofnode_get_property(node, "compatible", &len);
851 if (len >= strlen("pciVVVV,DDDD")) {
852 char *s = strstr(list, "pci");
855 * check if the string is something like pciVVVV,DDDD.RR
856 * or just pciVVVV,DDDD
858 if (s && s[7] == ',' &&
859 (s[12] == '.' || s[12] == 0)) {
861 *vendor = simple_strtol(s, NULL, 16);
864 *device = simple_strtol(s, NULL, 16);
875 int ofnode_read_addr_cells(ofnode node)
877 if (ofnode_is_np(node)) {
878 return of_n_addr_cells(ofnode_to_np(node));
880 int parent = fdt_parent_offset(gd->fdt_blob,
881 ofnode_to_offset(node));
883 return fdt_address_cells(gd->fdt_blob, parent);
887 int ofnode_read_size_cells(ofnode node)
889 if (ofnode_is_np(node)) {
890 return of_n_size_cells(ofnode_to_np(node));
892 int parent = fdt_parent_offset(gd->fdt_blob,
893 ofnode_to_offset(node));
895 return fdt_size_cells(gd->fdt_blob, parent);
899 int ofnode_read_simple_addr_cells(ofnode node)
901 if (ofnode_is_np(node))
902 return of_simple_addr_cells(ofnode_to_np(node));
904 return fdt_address_cells(gd->fdt_blob, ofnode_to_offset(node));
907 int ofnode_read_simple_size_cells(ofnode node)
909 if (ofnode_is_np(node))
910 return of_simple_size_cells(ofnode_to_np(node));
912 return fdt_size_cells(gd->fdt_blob, ofnode_to_offset(node));
915 bool ofnode_pre_reloc(ofnode node)
917 #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_TPL_BUILD)
918 /* for SPL and TPL the remaining nodes after the fdtgrep 1st pass
919 * had property dm-pre-reloc or u-boot,dm-spl/tpl.
920 * They are removed in final dtb (fdtgrep 2nd pass)
924 if (ofnode_read_bool(node, "u-boot,dm-pre-reloc"))
926 if (ofnode_read_bool(node, "u-boot,dm-pre-proper"))
930 * In regular builds individual spl and tpl handling both
931 * count as handled pre-relocation for later second init.
933 if (ofnode_read_bool(node, "u-boot,dm-spl") ||
934 ofnode_read_bool(node, "u-boot,dm-tpl"))
941 int ofnode_read_resource(ofnode node, uint index, struct resource *res)
943 if (ofnode_is_np(node)) {
944 return of_address_to_resource(ofnode_to_np(node), index, res);
946 struct fdt_resource fres;
949 ret = fdt_get_resource(gd->fdt_blob, ofnode_to_offset(node),
950 "reg", index, &fres);
953 memset(res, '\0', sizeof(*res));
954 res->start = fres.start;
961 int ofnode_read_resource_byname(ofnode node, const char *name,
962 struct resource *res)
966 index = ofnode_stringlist_search(node, "reg-names", name);
970 return ofnode_read_resource(node, index, res);
973 u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr)
975 if (ofnode_is_np(node))
976 return of_translate_address(ofnode_to_np(node), in_addr);
978 return fdt_translate_address(gd->fdt_blob, ofnode_to_offset(node), in_addr);
981 u64 ofnode_translate_dma_address(ofnode node, const fdt32_t *in_addr)
983 if (ofnode_is_np(node))
984 return of_translate_dma_address(ofnode_to_np(node), in_addr);
986 return fdt_translate_dma_address(gd->fdt_blob, ofnode_to_offset(node), in_addr);
989 int ofnode_get_dma_range(ofnode node, phys_addr_t *cpu, dma_addr_t *bus, u64 *size)
991 if (ofnode_is_np(node))
992 return of_get_dma_range(ofnode_to_np(node), cpu, bus, size);
994 return fdt_get_dma_range(gd->fdt_blob, ofnode_to_offset(node),
998 int ofnode_device_is_compatible(ofnode node, const char *compat)
1000 if (ofnode_is_np(node))
1001 return of_device_is_compatible(ofnode_to_np(node), compat,
1004 return !fdt_node_check_compatible(gd->fdt_blob,
1005 ofnode_to_offset(node),
1009 ofnode ofnode_by_compatible(ofnode from, const char *compat)
1011 if (of_live_active()) {
1012 return np_to_ofnode(of_find_compatible_node(
1013 (struct device_node *)ofnode_to_np(from), NULL,
1016 return offset_to_ofnode(fdt_node_offset_by_compatible(
1017 gd->fdt_blob, ofnode_to_offset(from), compat));
1021 ofnode ofnode_by_prop_value(ofnode from, const char *propname,
1022 const void *propval, int proplen)
1024 if (of_live_active()) {
1025 return np_to_ofnode(of_find_node_by_prop_value(
1026 (struct device_node *)ofnode_to_np(from), propname,
1029 return offset_to_ofnode(fdt_node_offset_by_prop_value(
1030 gd->fdt_blob, ofnode_to_offset(from),
1031 propname, propval, proplen));
1035 int ofnode_write_prop(ofnode node, const char *propname, int len,
1038 const struct device_node *np = ofnode_to_np(node);
1039 struct property *pp;
1040 struct property *pp_last = NULL;
1041 struct property *new;
1043 if (!of_live_active())
1049 for (pp = np->properties; pp; pp = pp->next) {
1050 if (strcmp(pp->name, propname) == 0) {
1051 /* Property exists -> change value */
1052 pp->value = (void *)value;
1062 /* Property does not exist -> append new property */
1063 new = malloc(sizeof(struct property));
1067 new->name = strdup(propname);
1073 new->value = (void *)value;
1077 pp_last->next = new;
1082 int ofnode_write_string(ofnode node, const char *propname, const char *value)
1084 if (!of_live_active())
1087 assert(ofnode_valid(node));
1089 debug("%s: %s = %s", __func__, propname, value);
1091 return ofnode_write_prop(node, propname, strlen(value) + 1, value);
1094 int ofnode_set_enabled(ofnode node, bool value)
1096 if (!of_live_active())
1099 assert(ofnode_valid(node));
1102 return ofnode_write_string(node, "status", "okay");
1104 return ofnode_write_string(node, "status", "disabled");