1 /* 2 * Copyright (c) 2017 Google, Inc 3 * Written by Simon Glass <sjg@chromium.org> 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8 #include <common.h> 9 #include <dm.h> 10 #include <dm/of_access.h> 11 12 int dev_read_u32_default(struct udevice *dev, const char *propname, int def) 13 { 14 return ofnode_read_u32_default(dev_ofnode(dev), propname, def); 15 } 16 17 const char *dev_read_string(struct udevice *dev, const char *propname) 18 { 19 return ofnode_read_string(dev_ofnode(dev), propname); 20 } 21 22 bool dev_read_bool(struct udevice *dev, const char *propname) 23 { 24 return ofnode_read_bool(dev_ofnode(dev), propname); 25 } 26 27 ofnode dev_read_subnode(struct udevice *dev, const char *subnode_name) 28 { 29 return ofnode_find_subnode(dev_ofnode(dev), subnode_name); 30 } 31 32 ofnode dev_read_first_subnode(struct udevice *dev) 33 { 34 return ofnode_first_subnode(dev_ofnode(dev)); 35 } 36 37 ofnode dev_read_next_subnode(ofnode node) 38 { 39 return ofnode_next_subnode(node); 40 } 41 42 int dev_read_size(struct udevice *dev, const char *propname) 43 { 44 return ofnode_read_size(dev_ofnode(dev), propname); 45 } 46 47 fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) 48 { 49 if (ofnode_is_np(dev_ofnode(dev))) 50 return ofnode_get_addr_index(dev_ofnode(dev), index); 51 else 52 return devfdt_get_addr_index(dev, index); 53 } 54 55 fdt_addr_t dev_read_addr(struct udevice *dev) 56 { 57 return dev_read_addr_index(dev, 0); 58 } 59 60 fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *property, 61 fdt_size_t *sizep) 62 { 63 return ofnode_get_addr_size(dev_ofnode(dev), property, sizep); 64 } 65 66 const char *dev_read_name(struct udevice *dev) 67 { 68 return ofnode_get_name(dev_ofnode(dev)); 69 } 70 71 int dev_read_stringlist_search(struct udevice *dev, const char *property, 72 const char *string) 73 { 74 return ofnode_stringlist_search(dev_ofnode(dev), property, string); 75 } 76 77 int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, 78 const char *cells_name, int cell_count, 79 int index, 80 struct ofnode_phandle_args *out_args) 81 { 82 return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name, 83 cells_name, cell_count, index, 84 out_args); 85 } 86 87 int dev_read_addr_cells(struct udevice *dev) 88 { 89 return ofnode_read_addr_cells(dev_ofnode(dev)); 90 } 91 92 int dev_read_size_cells(struct udevice *dev) 93 { 94 return ofnode_read_size_cells(dev_ofnode(dev)); 95 } 96 97 int dev_read_simple_addr_cells(struct udevice *dev) 98 { 99 return ofnode_read_simple_addr_cells(dev_ofnode(dev)); 100 } 101 102 int dev_read_simple_size_cells(struct udevice *dev) 103 { 104 return ofnode_read_simple_size_cells(dev_ofnode(dev)); 105 } 106 107 int dev_read_phandle(struct udevice *dev) 108 { 109 ofnode node = dev_ofnode(dev); 110 111 if (ofnode_is_np(node)) 112 return ofnode_to_np(node)->phandle; 113 else 114 return fdt_get_phandle(gd->fdt_blob, ofnode_to_offset(node)); 115 } 116 117 const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp) 118 { 119 return ofnode_get_property(dev_ofnode(dev), propname, lenp); 120 } 121 122 int dev_read_alias_seq(struct udevice *dev, int *devnump) 123 { 124 ofnode node = dev_ofnode(dev); 125 const char *uc_name = dev->uclass->uc_drv->name; 126 int ret; 127 128 if (ofnode_is_np(node)) { 129 ret = of_alias_get_id(ofnode_to_np(node), uc_name); 130 if (ret >= 0) 131 *devnump = ret; 132 } else { 133 ret = fdtdec_get_alias_seq(gd->fdt_blob, uc_name, 134 ofnode_to_offset(node), devnump); 135 } 136 137 return ret; 138 } 139 140 int dev_read_u32_array(struct udevice *dev, const char *propname, 141 u32 *out_values, size_t sz) 142 { 143 return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); 144 } 145 146 const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname, 147 size_t sz) 148 { 149 return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz); 150 } 151 152 int dev_read_enabled(struct udevice *dev) 153 { 154 ofnode node = dev_ofnode(dev); 155 156 if (ofnode_is_np(node)) 157 return of_device_is_available(ofnode_to_np(node)); 158 else 159 return fdtdec_get_is_enabled(gd->fdt_blob, 160 ofnode_to_offset(node)); 161 } 162 163 int dev_read_resource(struct udevice *dev, uint index, struct resource *res) 164 { 165 return ofnode_read_resource(dev_ofnode(dev), index, res); 166 } 167