12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049 |
- /* SPDX-License-Identifier: GPL-2.0+ */
- /*
- * Function to read values from the device tree node attached to a udevice.
- *
- * Copyright (c) 2017 Google, Inc
- * Written by Simon Glass <sjg@chromium.org>
- */
- #ifndef _DM_READ_H
- #define _DM_READ_H
- #include <linux/errno.h>
- #include <dm/device.h>
- #include <dm/fdtaddr.h>
- #include <dm/ofnode.h>
- #include <dm/uclass.h>
- struct resource;
- #if CONFIG_IS_ENABLED(OF_LIVE)
- static inline const struct device_node *dev_np(const struct udevice *dev)
- {
- return ofnode_to_np(dev->node);
- }
- #else
- static inline const struct device_node *dev_np(const struct udevice *dev)
- {
- return NULL;
- }
- #endif
- /**
- * dev_ofnode() - get the DT node reference associated with a udevice
- *
- * @dev: device to check
- * @return reference of the the device's DT node
- */
- static inline ofnode dev_ofnode(const struct udevice *dev)
- {
- return dev->node;
- }
- static inline bool dev_of_valid(const struct udevice *dev)
- {
- return ofnode_valid(dev_ofnode(dev));
- }
- #ifndef CONFIG_DM_DEV_READ_INLINE
- /**
- * dev_read_u32() - read a 32-bit integer from a device's DT property
- *
- * @dev: device to read DT property from
- * @propname: name of the property to read from
- * @outp: place to put value (if found)
- * @return 0 if OK, -ve on error
- */
- int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp);
- /**
- * dev_read_u32_default() - read a 32-bit integer from a device's DT property
- *
- * @dev: device to read DT property from
- * @propname: name of the property to read from
- * @def: default value to return if the property has no value
- * @return property value, or @def if not found
- */
- int dev_read_u32_default(const struct udevice *dev, const char *propname,
- int def);
- /**
- * dev_read_u32_index() - read an indexed 32-bit integer from a device's DT
- * property
- *
- * @dev: device to read DT property from
- * @propname: name of the property to read from
- * @index: index of the integer to return
- * @outp: place to put value (if found)
- * @return 0 if OK, -ve on error
- */
- int dev_read_u32_index(struct udevice *dev, const char *propname, int index,
- u32 *outp);
- /**
- * dev_read_u32_index_default() - read an indexed 32-bit integer from a device's
- * DT property
- *
- * @dev: device to read DT property from
- * @propname: name of the property to read from
- * @index: index of the integer to return
- * @def: default value to return if the property has no value
- * @return property value, or @def if not found
- */
- u32 dev_read_u32_index_default(struct udevice *dev, const char *propname,
- int index, u32 def);
- /**
- * dev_read_s32() - read a signed 32-bit integer from a device's DT property
- *
- * @dev: device to read DT property from
- * @propname: name of the property to read from
- * @outp: place to put value (if found)
- * @return 0 if OK, -ve on error
- */
- int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp);
- /**
- * dev_read_s32_default() - read a signed 32-bit int from a device's DT property
- *
- * @dev: device to read DT property from
- * @propname: name of the property to read from
- * @def: default value to return if the property has no value
- * @return property value, or @def if not found
- */
- int dev_read_s32_default(const struct udevice *dev, const char *propname,
- int def);
- /**
- * dev_read_u32u() - read a 32-bit integer from a device's DT property
- *
- * This version uses a standard uint type.
- *
- * @dev: device to read DT property from
- * @propname: name of the property to read from
- * @outp: place to put value (if found)
- * @return 0 if OK, -ve on error
- */
- int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp);
- /**
- * dev_read_u64() - read a 64-bit integer from a device's DT property
- *
- * @dev: device to read DT property from
- * @propname: name of the property to read from
- * @outp: place to put value (if found)
- * @return 0 if OK, -ve on error
- */
- int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp);
- /**
- * dev_read_u64_default() - read a 64-bit integer from a device's DT property
- *
- * @dev: device to read DT property from
- * @propname: name of the property to read from
- * @def: default value to return if the property has no value
- * @return property value, or @def if not found
- */
- u64 dev_read_u64_default(const struct udevice *dev, const char *propname,
- u64 def);
- /**
- * dev_read_string() - Read a string from a device's DT property
- *
- * @dev: device to read DT property from
- * @propname: name of the property to read
- * @return string from property value, or NULL if there is no such property
- */
- const char *dev_read_string(const struct udevice *dev, const char *propname);
- /**
- * dev_read_bool() - read a boolean value from a device's DT property
- *
- * @dev: device to read DT property from
- * @propname: name of property to read
- * @return true if property is present (meaning true), false if not present
- */
- bool dev_read_bool(const struct udevice *dev, const char *propname);
- /**
- * dev_read_subnode() - find a named subnode of a device
- *
- * @dev: device whose DT node contains the subnode
- * @subnode_name: name of subnode to find
- * @return reference to subnode (which can be invalid if there is no such
- * subnode)
- */
- ofnode dev_read_subnode(const struct udevice *dev, const char *subbnode_name);
- /**
- * dev_read_size() - read the size of a property
- *
- * @dev: device to check
- * @propname: property to check
- * @return size of property if present, or -EINVAL if not
- */
- int dev_read_size(const struct udevice *dev, const char *propname);
- /**
- * dev_read_addr_index() - Get the indexed reg property of a device
- *
- * @dev: Device to read from
- * @index: the 'reg' property can hold a list of <addr, size> pairs
- * and @index is used to select which one is required
- *
- * @return address or FDT_ADDR_T_NONE if not found
- */
- fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index);
- /**
- * dev_read_addr_size_index() - Get the indexed reg property of a device
- *
- * @dev: Device to read from
- * @index: the 'reg' property can hold a list of <addr, size> pairs
- * and @index is used to select which one is required
- * @size: place to put size value (on success)
- *
- * @return address or FDT_ADDR_T_NONE if not found
- */
- fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index,
- fdt_size_t *size);
- /**
- * dev_remap_addr_index() - Get the indexed reg property of a device
- * as a memory-mapped I/O pointer
- *
- * @dev: Device to read from
- * @index: the 'reg' property can hold a list of <addr, size> pairs
- * and @index is used to select which one is required
- *
- * @return pointer or NULL if not found
- */
- void *dev_remap_addr_index(const struct udevice *dev, int index);
- /**
- * dev_read_addr_name() - Get the reg property of a device, indexed by name
- *
- * @dev: Device to read from
- * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
- * 'reg-names' property providing named-based identification. @index
- * indicates the value to search for in 'reg-names'.
- *
- * @return address or FDT_ADDR_T_NONE if not found
- */
- fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name);
- /**
- * dev_read_addr_size_name() - Get the reg property of a device, indexed by name
- *
- * @dev: Device to read from
- * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
- * 'reg-names' property providing named-based identification. @index
- * indicates the value to search for in 'reg-names'.
- * @size: place to put size value (on success)
- *
- * @return address or FDT_ADDR_T_NONE if not found
- */
- fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name,
- fdt_size_t *size);
- /**
- * dev_remap_addr_name() - Get the reg property of a device, indexed by name,
- * as a memory-mapped I/O pointer
- *
- * @dev: Device to read from
- * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
- * 'reg-names' property providing named-based identification. @index
- * indicates the value to search for in 'reg-names'.
- *
- * @return pointer or NULL if not found
- */
- void *dev_remap_addr_name(const struct udevice *dev, const char *name);
- /**
- * dev_read_addr() - Get the reg property of a device
- *
- * @dev: Device to read from
- *
- * @return address or FDT_ADDR_T_NONE if not found
- */
- fdt_addr_t dev_read_addr(const struct udevice *dev);
- /**
- * dev_read_addr_ptr() - Get the reg property of a device
- * as a pointer
- *
- * @dev: Device to read from
- *
- * @return pointer or NULL if not found
- */
- void *dev_read_addr_ptr(const struct udevice *dev);
- /**
- * dev_read_addr_pci() - Read an address and handle PCI address translation
- *
- * At present U-Boot does not have address translation logic for PCI in the
- * livetree implementation (of_addr.c). This special function supports this for
- * the flat tree implementation.
- *
- * This function should be removed (and code should use dev_read() instead)
- * once:
- *
- * 1. PCI address translation is added; and either
- * 2. everything uses livetree where PCI translation is used (which is feasible
- * in SPL and U-Boot proper) or PCI address translation is added to
- * fdtdec_get_addr() and friends.
- *
- * @dev: Device to read from
- * @return address or FDT_ADDR_T_NONE if not found
- */
- fdt_addr_t dev_read_addr_pci(const struct udevice *dev);
- /**
- * dev_remap_addr() - Get the reg property of a device as a
- * memory-mapped I/O pointer
- *
- * @dev: Device to read from
- *
- * @return pointer or NULL if not found
- */
- void *dev_remap_addr(const struct udevice *dev);
- /**
- * dev_read_addr_size() - get address and size from a device property
- *
- * This does no address translation. It simply reads an property that contains
- * an address and a size value, one after the other.
- *
- * @dev: Device to read from
- * @propname: property to read
- * @sizep: place to put size value (on success)
- * @return address value, or FDT_ADDR_T_NONE on error
- */
- fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *propname,
- fdt_size_t *sizep);
- /**
- * dev_read_name() - get the name of a device's node
- *
- * @dev: Device to read from
- * @return name of node
- */
- const char *dev_read_name(const struct udevice *dev);
- /**
- * dev_read_stringlist_search() - find string in a string list and return index
- *
- * Note that it is possible for this function to succeed on property values
- * that are not NUL-terminated. That's because the function will stop after
- * finding the first occurrence of @string. This can for example happen with
- * small-valued cell properties, such as #address-cells, when searching for
- * the empty string.
- *
- * @dev: device to check
- * @propname: name of the property containing the string list
- * @string: string to look up in the string list
- *
- * @return:
- * the index of the string in the list of strings
- * -ENODATA if the property is not found
- * -EINVAL on some other error
- */
- int dev_read_stringlist_search(const struct udevice *dev, const char *property,
- const char *string);
- /**
- * dev_read_string_index() - obtain an indexed string from a string list
- *
- * @dev: device to examine
- * @propname: name of the property containing the string list
- * @index: index of the string to return
- * @out: return location for the string
- *
- * @return:
- * length of string, if found or -ve error value if not found
- */
- int dev_read_string_index(const struct udevice *dev, const char *propname,
- int index, const char **outp);
- /**
- * dev_read_string_count() - find the number of strings in a string list
- *
- * @dev: device to examine
- * @propname: name of the property containing the string list
- * @return:
- * number of strings in the list, or -ve error value if not found
- */
- int dev_read_string_count(const struct udevice *dev, const char *propname);
- /**
- * dev_read_phandle_with_args() - Find a node pointed by phandle in a list
- *
- * This function is useful to parse lists of phandles and their arguments.
- * Returns 0 on success and fills out_args, on error returns appropriate
- * errno value.
- *
- * Caller is responsible to call of_node_put() on the returned out_args->np
- * pointer.
- *
- * Example:
- *
- * phandle1: node1 {
- * #list-cells = <2>;
- * }
- *
- * phandle2: node2 {
- * #list-cells = <1>;
- * }
- *
- * node3 {
- * list = <&phandle1 1 2 &phandle2 3>;
- * }
- *
- * To get a device_node of the `node2' node you may call this:
- * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args);
- *
- * @dev: device whose node containing a list
- * @list_name: property name that contains a list
- * @cells_name: property name that specifies phandles' arguments count
- * @cells_count: Cell count to use if @cells_name is NULL
- * @index: index of a phandle to parse out
- * @out_args: optional pointer to output arguments structure (will be filled)
- * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
- * @list_name does not exist, -EINVAL if a phandle was not found,
- * @cells_name could not be found, the arguments were truncated or there
- * were too many arguments.
- */
- int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name,
- const char *cells_name, int cell_count,
- int index, struct ofnode_phandle_args *out_args);
- /**
- * dev_count_phandle_with_args() - Return phandle number in a list
- *
- * This function is usefull to get phandle number contained in a property list.
- * For example, this allows to allocate the right amount of memory to keep
- * clock's reference contained into the "clocks" property.
- *
- *
- * @dev: device whose node containing a list
- * @list_name: property name that contains a list
- * @cells_name: property name that specifies phandles' arguments count
- * @cells_count: Cell count to use if @cells_name is NULL
- * @Returns number of phandle found on success, on error returns appropriate
- * errno value.
- */
- int dev_count_phandle_with_args(const struct udevice *dev,
- const char *list_name, const char *cells_name,
- int cell_count);
- /**
- * dev_read_addr_cells() - Get the number of address cells for a device's node
- *
- * This walks back up the tree to find the closest #address-cells property
- * which controls the given node.
- *
- * @dev: device to check
- * @return number of address cells this node uses
- */
- int dev_read_addr_cells(const struct udevice *dev);
- /**
- * dev_read_size_cells() - Get the number of size cells for a device's node
- *
- * This walks back up the tree to find the closest #size-cells property
- * which controls the given node.
- *
- * @dev: device to check
- * @return number of size cells this node uses
- */
- int dev_read_size_cells(const struct udevice *dev);
- /**
- * dev_read_addr_cells() - Get the address cells property in a node
- *
- * This function matches fdt_address_cells().
- *
- * @dev: device to check
- * @return number of address cells this node uses
- */
- int dev_read_simple_addr_cells(const struct udevice *dev);
- /**
- * dev_read_size_cells() - Get the size cells property in a node
- *
- * This function matches fdt_size_cells().
- *
- * @dev: device to check
- * @return number of size cells this node uses
- */
- int dev_read_simple_size_cells(const struct udevice *dev);
- /**
- * dev_read_phandle() - Get the phandle from a device
- *
- * @dev: device to check
- * @return phandle (1 or greater), or 0 if no phandle or other error
- */
- int dev_read_phandle(const struct udevice *dev);
- /**
- * dev_read_prop()- - read a property from a device's node
- *
- * @dev: device to check
- * @propname: property to read
- * @lenp: place to put length on success
- * @return pointer to property, or NULL if not found
- */
- const void *dev_read_prop(const struct udevice *dev, const char *propname,
- int *lenp);
- /**
- * dev_read_first_prop()- get the reference of the first property
- *
- * Get reference to the first property of the node, it is used to iterate
- * and read all the property with dev_read_prop_by_prop().
- *
- * @dev: device to check
- * @prop: place to put argument reference
- * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
- */
- int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop);
- /**
- * ofnode_get_next_property() - get the reference of the next property
- *
- * Get reference to the next property of the node, it is used to iterate
- * and read all the property with dev_read_prop_by_prop().
- *
- * @prop: reference of current argument and place to put reference of next one
- * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
- */
- int dev_read_next_prop(struct ofprop *prop);
- /**
- * dev_read_prop_by_prop() - get a pointer to the value of a property
- *
- * Get value for the property identified by the provided reference.
- *
- * @prop: reference on property
- * @propname: If non-NULL, place to property name on success,
- * @lenp: If non-NULL, place to put length on success
- * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
- */
- const void *dev_read_prop_by_prop(struct ofprop *prop,
- const char **propname, int *lenp);
- /**
- * dev_read_alias_seq() - Get the alias sequence number of a node
- *
- * This works out whether a node is pointed to by an alias, and if so, the
- * sequence number of that alias. Aliases are of the form <base><num> where
- * <num> is the sequence number. For example spi2 would be sequence number 2.
- *
- * @dev: device to look up
- * @devnump: set to the sequence number if one is found
- * @return 0 if a sequence was found, -ve if not
- */
- int dev_read_alias_seq(const struct udevice *dev, int *devnump);
- /**
- * dev_read_u32_array() - Find and read an array of 32 bit integers
- *
- * Search for a property in a device node and read 32-bit value(s) from
- * it.
- *
- * The out_values is modified only if a valid u32 value can be decoded.
- *
- * @dev: device to look up
- * @propname: name of the property to read
- * @out_values: pointer to return value, modified only if return value is 0
- * @sz: number of array elements to read
- * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if
- * property does not have a value, and -EOVERFLOW if the property data isn't
- * large enough.
- */
- int dev_read_u32_array(const struct udevice *dev, const char *propname,
- u32 *out_values, size_t sz);
- /**
- * dev_read_first_subnode() - find the first subnode of a device's node
- *
- * @dev: device to look up
- * @return reference to the first subnode (which can be invalid if the device's
- * node has no subnodes)
- */
- ofnode dev_read_first_subnode(const struct udevice *dev);
- /**
- * ofnode_next_subnode() - find the next sibling of a subnode
- *
- * @node: valid reference to previous node (sibling)
- * @return reference to the next subnode (which can be invalid if the node
- * has no more siblings)
- */
- ofnode dev_read_next_subnode(ofnode node);
- /**
- * dev_read_u8_array_ptr() - find an 8-bit array
- *
- * Look up a device's node property and return a pointer to its contents as a
- * byte array of given length. The property must have at least enough data
- * for the array (count bytes). It may have more, but this will be ignored.
- * The data is not copied.
- *
- * @dev: device to look up
- * @propname: name of property to find
- * @sz: number of array elements
- * @return pointer to byte array if found, or NULL if the property is not
- * found or there is not enough data
- */
- const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
- const char *propname, size_t sz);
- /**
- * dev_read_enabled() - check whether a node is enabled
- *
- * This looks for a 'status' property. If this exists, then returns 1 if
- * the status is 'ok' and 0 otherwise. If there is no status property,
- * it returns 1 on the assumption that anything mentioned should be enabled
- * by default.
- *
- * @dev: device to examine
- * @return integer value 0 (not enabled) or 1 (enabled)
- */
- int dev_read_enabled(const struct udevice *dev);
- /**
- * dev_read_resource() - obtain an indexed resource from a device.
- *
- * @dev: device to examine
- * @index index of the resource to retrieve (0 = first)
- * @res returns the resource
- * @return 0 if ok, negative on error
- */
- int dev_read_resource(const struct udevice *dev, uint index,
- struct resource *res);
- /**
- * dev_read_resource_byname() - obtain a named resource from a device.
- *
- * @dev: device to examine
- * @name: name of the resource to retrieve
- * @res: returns the resource
- * @return 0 if ok, negative on error
- */
- int dev_read_resource_byname(const struct udevice *dev, const char *name,
- struct resource *res);
- /**
- * dev_translate_address() - Translate a device-tree address
- *
- * Translate an address from the device-tree into a CPU physical address. This
- * function walks up the tree and applies the various bus mappings along the
- * way.
- *
- * @dev: device giving the context in which to translate the address
- * @in_addr: pointer to the address to translate
- * @return the translated address; OF_BAD_ADDR on error
- */
- u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr);
- /**
- * dev_translate_dma_address() - Translate a device-tree DMA address
- *
- * Translate a DMA address from the device-tree into a CPU physical address.
- * This function walks up the tree and applies the various bus mappings along
- * the way.
- *
- * @dev: device giving the context in which to translate the DMA address
- * @in_addr: pointer to the DMA address to translate
- * @return the translated DMA address; OF_BAD_ADDR on error
- */
- u64 dev_translate_dma_address(const struct udevice *dev,
- const fdt32_t *in_addr);
- /**
- * dev_read_alias_highest_id - Get highest alias id for the given stem
- * @stem: Alias stem to be examined
- *
- * The function travels the lookup table to get the highest alias id for the
- * given alias stem.
- * @return alias ID, if found, else -1
- */
- int dev_read_alias_highest_id(const char *stem);
- /**
- * dev_get_child_count() - get the child count of a device
- *
- * @dev: device to use for interation (struct udevice *)
- * @return the count of child subnode
- */
- int dev_get_child_count(const struct udevice *dev);
- /**
- * dev_read_pci_bus_range - Read PCI bus-range resource
- *
- * Look at the bus range property of a device node and return the pci bus
- * range for this node.
- *
- * @dev: device to examine
- * @res returns the resource
- * @return 0 if ok, negative on error
- */
- int dev_read_pci_bus_range(const struct udevice *dev, struct resource *res);
- #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
- static inline int dev_read_u32(const struct udevice *dev,
- const char *propname, u32 *outp)
- {
- return ofnode_read_u32(dev_ofnode(dev), propname, outp);
- }
- static inline int dev_read_u32_default(const struct udevice *dev,
- const char *propname, int def)
- {
- return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
- }
- static inline int dev_read_u32_index(struct udevice *dev,
- const char *propname, int index, u32 *outp)
- {
- return ofnode_read_u32_index(dev_ofnode(dev), propname, index, outp);
- }
- static inline u32 dev_read_u32_index_default(struct udevice *dev,
- const char *propname, int index,
- u32 def)
- {
- return ofnode_read_u32_index_default(dev_ofnode(dev), propname, index,
- def);
- }
- static inline int dev_read_s32(const struct udevice *dev,
- const char *propname, s32 *outp)
- {
- return ofnode_read_s32(dev_ofnode(dev), propname, outp);
- }
- static inline int dev_read_s32_default(const struct udevice *dev,
- const char *propname, int def)
- {
- return ofnode_read_s32_default(dev_ofnode(dev), propname, def);
- }
- static inline int dev_read_u32u(const struct udevice *dev,
- const char *propname, uint *outp)
- {
- u32 val;
- int ret;
- ret = ofnode_read_u32(dev_ofnode(dev), propname, &val);
- if (ret)
- return ret;
- *outp = val;
- return 0;
- }
- static inline int dev_read_u64(const struct udevice *dev,
- const char *propname, u64 *outp)
- {
- return ofnode_read_u64(dev_ofnode(dev), propname, outp);
- }
- static inline u64 dev_read_u64_default(const struct udevice *dev,
- const char *propname, u64 def)
- {
- return ofnode_read_u64_default(dev_ofnode(dev), propname, def);
- }
- static inline const char *dev_read_string(const struct udevice *dev,
- const char *propname)
- {
- return ofnode_read_string(dev_ofnode(dev), propname);
- }
- static inline bool dev_read_bool(const struct udevice *dev,
- const char *propname)
- {
- return ofnode_read_bool(dev_ofnode(dev), propname);
- }
- static inline ofnode dev_read_subnode(const struct udevice *dev,
- const char *subbnode_name)
- {
- return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
- }
- static inline int dev_read_size(const struct udevice *dev, const char *propname)
- {
- return ofnode_read_size(dev_ofnode(dev), propname);
- }
- static inline fdt_addr_t dev_read_addr_index(const struct udevice *dev,
- int index)
- {
- return devfdt_get_addr_index(dev, index);
- }
- static inline fdt_addr_t dev_read_addr_size_index(const struct udevice *dev,
- int index,
- fdt_size_t *size)
- {
- return devfdt_get_addr_size_index(dev, index, size);
- }
- static inline fdt_addr_t dev_read_addr_name(const struct udevice *dev,
- const char *name)
- {
- return devfdt_get_addr_name(dev, name);
- }
- static inline fdt_addr_t dev_read_addr_size_name(const struct udevice *dev,
- const char *name,
- fdt_size_t *size)
- {
- return devfdt_get_addr_size_name(dev, name, size);
- }
- static inline fdt_addr_t dev_read_addr(const struct udevice *dev)
- {
- return devfdt_get_addr(dev);
- }
- static inline void *dev_read_addr_ptr(const struct udevice *dev)
- {
- return devfdt_get_addr_ptr(dev);
- }
- static inline fdt_addr_t dev_read_addr_pci(const struct udevice *dev)
- {
- return devfdt_get_addr_pci(dev);
- }
- static inline void *dev_remap_addr(const struct udevice *dev)
- {
- return devfdt_remap_addr(dev);
- }
- static inline void *dev_remap_addr_index(const struct udevice *dev, int index)
- {
- return devfdt_remap_addr_index(dev, index);
- }
- static inline void *dev_remap_addr_name(const struct udevice *dev,
- const char *name)
- {
- return devfdt_remap_addr_name(dev, name);
- }
- static inline fdt_addr_t dev_read_addr_size(const struct udevice *dev,
- const char *propname,
- fdt_size_t *sizep)
- {
- return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep);
- }
- static inline const char *dev_read_name(const struct udevice *dev)
- {
- return ofnode_get_name(dev_ofnode(dev));
- }
- static inline int dev_read_stringlist_search(const struct udevice *dev,
- const char *propname,
- const char *string)
- {
- return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
- }
- static inline int dev_read_string_index(const struct udevice *dev,
- const char *propname, int index,
- const char **outp)
- {
- return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
- }
- static inline int dev_read_string_count(const struct udevice *dev,
- const char *propname)
- {
- return ofnode_read_string_count(dev_ofnode(dev), propname);
- }
- static inline int dev_read_phandle_with_args(const struct udevice *dev,
- const char *list_name, const char *cells_name, int cell_count,
- int index, struct ofnode_phandle_args *out_args)
- {
- return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
- cells_name, cell_count, index,
- out_args);
- }
- static inline int dev_count_phandle_with_args(const struct udevice *dev,
- const char *list_name, const char *cells_name, int cell_count)
- {
- return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
- cells_name, cell_count);
- }
- static inline int dev_read_addr_cells(const struct udevice *dev)
- {
- int parent = fdt_parent_offset(gd->fdt_blob, dev_of_offset(dev));
- return fdt_address_cells(gd->fdt_blob, parent);
- }
- static inline int dev_read_size_cells(const struct udevice *dev)
- {
- int parent = fdt_parent_offset(gd->fdt_blob, dev_of_offset(dev));
- return fdt_size_cells(gd->fdt_blob, parent);
- }
- static inline int dev_read_simple_addr_cells(const struct udevice *dev)
- {
- return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
- }
- static inline int dev_read_simple_size_cells(const struct udevice *dev)
- {
- return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
- }
- static inline int dev_read_phandle(const struct udevice *dev)
- {
- return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
- }
- static inline const void *dev_read_prop(const struct udevice *dev,
- const char *propname, int *lenp)
- {
- return ofnode_get_property(dev_ofnode(dev), propname, lenp);
- }
- static inline int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop)
- {
- return ofnode_get_first_property(dev_ofnode(dev), prop);
- }
- static inline int dev_read_next_prop(struct ofprop *prop)
- {
- return ofnode_get_next_property(prop);
- }
- static inline const void *dev_read_prop_by_prop(struct ofprop *prop,
- const char **propname,
- int *lenp)
- {
- return ofnode_get_property_by_prop(prop, propname, lenp);
- }
- static inline int dev_read_alias_seq(const struct udevice *dev, int *devnump)
- {
- #if CONFIG_IS_ENABLED(OF_CONTROL)
- return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
- dev_of_offset(dev), devnump);
- #else
- return -ENOTSUPP;
- #endif
- }
- static inline int dev_read_u32_array(const struct udevice *dev,
- const char *propname, u32 *out_values,
- size_t sz)
- {
- return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
- }
- static inline ofnode dev_read_first_subnode(const struct udevice *dev)
- {
- return ofnode_first_subnode(dev_ofnode(dev));
- }
- static inline ofnode dev_read_next_subnode(ofnode node)
- {
- return ofnode_next_subnode(node);
- }
- static inline const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
- const char *propname,
- size_t sz)
- {
- return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
- }
- static inline int dev_read_enabled(const struct udevice *dev)
- {
- return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
- }
- static inline int dev_read_resource(const struct udevice *dev, uint index,
- struct resource *res)
- {
- return ofnode_read_resource(dev_ofnode(dev), index, res);
- }
- static inline int dev_read_resource_byname(const struct udevice *dev,
- const char *name,
- struct resource *res)
- {
- return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
- }
- static inline u64 dev_translate_address(const struct udevice *dev,
- const fdt32_t *in_addr)
- {
- return ofnode_translate_address(dev_ofnode(dev), in_addr);
- }
- static inline u64 dev_translate_dma_address(const struct udevice *dev,
- const fdt32_t *in_addr)
- {
- return ofnode_translate_dma_address(dev_ofnode(dev), in_addr);
- }
- static inline int dev_read_alias_highest_id(const char *stem)
- {
- if (!CONFIG_IS_ENABLED(OF_LIBFDT))
- return -1;
- return fdtdec_get_alias_highest_id(gd->fdt_blob, stem);
- }
- static inline int dev_get_child_count(const struct udevice *dev)
- {
- return ofnode_get_child_count(dev_ofnode(dev));
- }
- #endif /* CONFIG_DM_DEV_READ_INLINE */
- /**
- * dev_for_each_subnode() - Helper function to iterate through subnodes
- *
- * This creates a for() loop which works through the subnodes in a device's
- * device-tree node.
- *
- * @subnode: ofnode holding the current subnode
- * @dev: device to use for interation (struct udevice *)
- */
- #define dev_for_each_subnode(subnode, dev) \
- for (subnode = dev_read_first_subnode(dev); \
- ofnode_valid(subnode); \
- subnode = ofnode_next_subnode(subnode))
- /**
- * dev_for_each_property() - Helper function to iterate through property
- *
- * This creates a for() loop which works through the property in a device's
- * device-tree node.
- *
- * @prop: struct ofprop holding the current property
- * @dev: device to use for interation (struct udevice *)
- */
- #define dev_for_each_property(prop, dev) \
- for (int ret_prop = dev_read_first_prop(dev, &prop); \
- !ret_prop; \
- ret_prop = dev_read_next_prop(&prop))
- #endif
|