DeviceTree Kernel API

Core functions

structdevice_node*of_find_all_nodes(structdevice_node*prev)

Get next node in global list

Parameters

structdevice_node*prev

Previous node or NULL to start iterationof_node_put() will be called on it

Return

A node pointer with refcount incremented, useof_node_put() on it when done.

boolof_machine_compatible_match(constchar*const*compats)

Test root of device tree against a compatible array

Parameters

constchar*const*compats

NULL terminated array of compatible strings to look for in root node’s compatible property.

Description

Returns true if the root node has any of the given compatible values in itscompatible property.

boolof_machine_device_match(conststructof_device_id*matches)

Test root of device tree against a of_device_id array

Parameters

conststructof_device_id*matches

NULL terminated array of of_device_id match structures to search in

Description

Returns true if the root node has any of the given compatible values in itscompatible property.

constvoid*of_machine_get_match_data(conststructof_device_id*matches)

Tell if root of device tree has a matching of_match structure

Parameters

conststructof_device_id*matches

NULL terminated array of of_device_id match structures to search in

Description

Returns data associated with matched entry or NULL

boolof_device_is_available(conststructdevice_node*device)

check if a device is available for use

Parameters

conststructdevice_node*device

Node to check for availability

Return

True if the status property is absent or set to “okay” or “ok”,false otherwise

boolof_device_is_big_endian(conststructdevice_node*device)

check if a device has BE registers

Parameters

conststructdevice_node*device

Node to check for endianness

Return

True if the device has a “big-endian” property, or if the kernelwas compiled for BEand the device has a “native-endian” property.Returns false otherwise.

Description

Callers would nominally use ioread32be/iowrite32be ifof_device_is_big_endian() == true, or readl/writel otherwise.

structdevice_node*of_get_parent(conststructdevice_node*node)

Get a node’s parent if any

Parameters

conststructdevice_node*node

Node to get parent

Return

A node pointer with refcount incremented, useof_node_put() on it when done.

structdevice_node*of_get_next_parent(structdevice_node*node)

Iterate to a node’s parent

Parameters

structdevice_node*node

Node to get parent of

Description

This is likeof_get_parent() except that it drops therefcount on the passed node, making it suitable for iteratingthrough a node’s parents.

Return

A node pointer with refcount incremented, useof_node_put() on it when done.

structdevice_node*of_get_next_child(conststructdevice_node*node,structdevice_node*prev)

Iterate a node childs

Parameters

conststructdevice_node*node

parent node

structdevice_node*prev

previous child of the parent node, or NULL to get first

Return

A node pointer with refcount incremented, useof_node_put() onit when done. Returns NULL when prev is the last child. Decrements therefcount of prev.

structdevice_node*of_get_next_child_with_prefix(conststructdevice_node*node,structdevice_node*prev,constchar*prefix)

Find the next child node with prefix

Parameters

conststructdevice_node*node

parent node

structdevice_node*prev

previous child of the parent node, or NULL to get first

constchar*prefix

prefix that the node name should have

Description

This function is likeof_get_next_child(), except that it automaticallyskips any nodes whose name doesn’t have the given prefix.

Return

A node pointer with refcount incremented, useof_node_put() on it when done.

structdevice_node*of_get_next_available_child(conststructdevice_node*node,structdevice_node*prev)

Find the next available child node

Parameters

conststructdevice_node*node

parent node

structdevice_node*prev

previous child of the parent node, or NULL to get first

Description

This function is likeof_get_next_child(), except that itautomatically skips any disabled nodes (i.e. status = “disabled”).

structdevice_node*of_get_next_reserved_child(conststructdevice_node*node,structdevice_node*prev)

Find the next reserved child node

Parameters

conststructdevice_node*node

parent node

structdevice_node*prev

previous child of the parent node, or NULL to get first

Description

This function is likeof_get_next_child(), except that itautomatically skips any disabled nodes (i.e. status = “disabled”).

structdevice_node*of_get_next_cpu_node(structdevice_node*prev)

Iterate on cpu nodes

Parameters

structdevice_node*prev

previous child of the /cpus node, or NULL to get first

Description

Unusable CPUs (those with the status property set to “fail” or “fail-...”)will be skipped.

Return

A cpu node pointer with refcount incremented, useof_node_put()on it when done. Returns NULL when prev is the last child. Decrementsthe refcount of prev.

structdevice_node*of_get_compatible_child(conststructdevice_node*parent,constchar*compatible)

Find compatible child node

Parameters

conststructdevice_node*parent

parent node

constchar*compatible

compatible string

Description

Lookup child node whose compatible property contains the given compatiblestring.

Return

a node pointer with refcount incremented, useof_node_put() on itwhen done; or NULL if not found.

structdevice_node*of_get_child_by_name(conststructdevice_node*node,constchar*name)

Find the child node by name for a given parent

Parameters

conststructdevice_node*node

parent node

constchar*name

child name to look for.

Description

This function looks for child node for given matching name

Return

A node pointer if found, with refcount incremented, useof_node_put() on it when done.Returns NULL if node is not found.

structdevice_node*of_get_available_child_by_name(conststructdevice_node*node,constchar*name)

Find the available child node by name for a given parent

Parameters

conststructdevice_node*node

parent node

constchar*name

child name to look for.

Description

This function looks for child node for given matching name and checks thedevice’s availability for use.

Return

A node pointer if found, with refcount incremented, useof_node_put() on it when done.Returns NULL if node is not found.

structdevice_node*of_find_node_opts_by_path(constchar*path,constchar**opts)

Find a node matching a full OF path

Parameters

constchar*path

Either the full path to match, or if the path does notstart with ‘/’, the name of a property of the /aliasesnode (an alias). In the case of an alias, the nodematching the alias’ value will be returned.

constchar**opts

Address of a pointer into which to store the start ofan options string appended to the end of the path witha ‘:’ separator.

Description

Valid paths:
  • /foo/bar Full path

  • foo Valid alias

  • foo/bar Valid alias + relative path

Return

A node pointer with refcount incremented, useof_node_put() on it when done.

structdevice_node*of_find_node_by_name(structdevice_node*from,constchar*name)

Find a node by its “name” property

Parameters

structdevice_node*from

The node to start searching from or NULL; the nodeyou pass will not be searched, only the next onewill. Typically, you pass what the previous callreturned.of_node_put() will be called onfrom.

constchar*name

The name string to match against

Return

A node pointer with refcount incremented, useof_node_put() on it when done.

structdevice_node*of_find_node_by_type(structdevice_node*from,constchar*type)

Find a node by its “device_type” property

Parameters

structdevice_node*from

The node to start searching from, or NULL to start searchingthe entire device tree. The node you pass will not besearched, only the next one will; typically, you passwhat the previous call returned.of_node_put() will becalled on from for you.

constchar*type

The type string to match against

Return

A node pointer with refcount incremented, useof_node_put() on it when done.

structdevice_node*of_find_compatible_node(structdevice_node*from,constchar*type,constchar*compatible)

Find a node based on type and one of the tokens in its “compatible” property

Parameters

structdevice_node*from

The node to start searching from or NULL, the nodeyou pass will not be searched, only the next onewill; typically, you pass what the previous callreturned.of_node_put() will be called on it

constchar*type

The type string to match “device_type” or NULL to ignore

constchar*compatible

The string to match to one of the tokens in the device“compatible” list.

Return

A node pointer with refcount incremented, useof_node_put() on it when done.

structdevice_node*of_find_node_with_property(structdevice_node*from,constchar*prop_name)

Find a node which has a property with the given name.

Parameters

structdevice_node*from

The node to start searching from or NULL, the nodeyou pass will not be searched, only the next onewill; typically, you pass what the previous callreturned.of_node_put() will be called on it

constchar*prop_name

The name of the property to look for.

Return

A node pointer with refcount incremented, useof_node_put() on it when done.

conststructof_device_id*of_match_node(conststructof_device_id*matches,conststructdevice_node*node)

Tell if a device_node has a matching of_match structure

Parameters

conststructof_device_id*matches

array of of device match structures to search in

conststructdevice_node*node

the of device structure to match against

Description

Low level utility function used by device matching.

structdevice_node*of_find_matching_node_and_match(structdevice_node*from,conststructof_device_id*matches,conststructof_device_id**match)

Find a node based on an of_device_id match table.

Parameters

structdevice_node*from

The node to start searching from or NULL, the nodeyou pass will not be searched, only the next onewill; typically, you pass what the previous callreturned.of_node_put() will be called on it

conststructof_device_id*matches

array of of device match structures to search in

conststructof_device_id**match

Updated to point at the matches entry which matched

Return

A node pointer with refcount incremented, useof_node_put() on it when done.

intof_alias_from_compatible(conststructdevice_node*node,char*alias,intlen)

Lookup appropriate alias for a device node depending on compatible

Parameters

conststructdevice_node*node

pointer to a device tree node

char*alias

Pointer to buffer that alias value will be copied into

intlen

Length of alias value

Description

Based on the value of the compatible property, this routine will attemptto choose an appropriate alias value for a particular device tree node.It does this by stripping the manufacturer prefix (as delimited by a ‘,’)from the first entry in the compatible list property.

Note

The matching on just the “product” side of the compatible is a relicfrom I2C and SPI. Please do not add any new user.

Return

This routine returns 0 on success, <0 on failure.

structdevice_node*of_find_node_by_phandle(phandlehandle)

Find a node given a phandle

Parameters

phandlehandle

phandle of the node to find

Return

A node pointer with refcount incremented, useof_node_put() on it when done.

intof_parse_phandle_with_args_map(conststructdevice_node*np,constchar*list_name,constchar*stem_name,intindex,structof_phandle_args*out_args)

Find a node pointed by phandle in a list and remap it

Parameters

conststructdevice_node*np

pointer to a device tree node containing a list

constchar*list_name

property name that contains a list

constchar*stem_name

stem of property names that specify phandles’ arguments count

intindex

index of a phandle to parse out

structof_phandle_args*out_args

optional pointer to output arguments structure (will be filled)

Description

This function is useful to parse lists of phandles and their arguments.Returns 0 on success and fills out_args, on error returns appropriate errnovalue. The difference between this function andof_parse_phandle_with_args()is that this API remaps a phandle if the node the phandle points to hasa <stem_name>-map property.

Caller is responsible to callof_node_put() on the returned out_args->nppointer.

Example:

phandle1: node1 {    #list-cells = <2>;};phandle2: node2 {    #list-cells = <1>;};phandle3: node3 {    #list-cells = <1>;    list-map = <0 &phandle2 3>,               <1 &phandle2 2>,               <2 &phandle1 5 1>;    list-map-mask = <0x3>;};node4 {    list = <&phandle1 1 2 &phandle3 0>;};

To get a device_node of thenode2 node you may call this:of_parse_phandle_with_args(node4, “list”, “list”, 1,args);

intof_count_phandle_with_args(conststructdevice_node*np,constchar*list_name,constchar*cells_name)

Find the number of phandles references in a property

Parameters

conststructdevice_node*np

pointer to a device tree node containing a list

constchar*list_name

property name that contains a list

constchar*cells_name

property name that specifies phandles’ arguments count

Return

The number of phandle + argument tuples within a property. Itis a typical pattern to encode a list of phandle and variablearguments into a single property. The number of arguments is encodedby a property in the phandle-target node. For example, a gpiosproperty would contain a list of GPIO specifies consisting of aphandle and 1 or more arguments. The number of arguments aredetermined by the #gpio-cells property in the node pointed to by thephandle.

intof_add_property(structdevice_node*np,structproperty*prop)

Add a property to a node

Parameters

structdevice_node*np

Caller’s Device Node

structproperty*prop

Property to add

intof_remove_property(structdevice_node*np,structproperty*prop)

Remove a property from a node.

Parameters

structdevice_node*np

Caller’s Device Node

structproperty*prop

Property to remove

Description

Note that we don’t actually remove it, since we have given outwho-knows-how-many pointers to the data using get-property.Instead we just move the property to the “dead properties”list, so it won’t be found any more.

intof_alias_get_id(conststructdevice_node*np,constchar*stem)

Get alias id for the given device_node

Parameters

conststructdevice_node*np

Pointer to the given device_node

constchar*stem

Alias stem of the given device_node

Description

The function travels the lookup table to get the alias id for the givendevice_node and alias stem.

Return

The alias id if found.

intof_alias_get_highest_id(constchar*stem)

Get highest alias id for the given stem

Parameters

constchar*stem

Alias stem to be examined

Description

The function travels the lookup table to get the highest alias id for thegiven alias stem. It returns the alias id if found.

boolof_console_check(conststructdevice_node*dn,char*name,intindex)

Test and setup console for DT setup

Parameters

conststructdevice_node*dn

Pointer to device node

char*name

Name to use for preferred console without index. ex. “ttyS”

intindex

Index to use for preferred console.

Description

Check if the given device node matches the stdout-path property in the/chosen node. If it does then register it as the preferred console.

Return

TRUE if console successfully setup. Otherwise return FALSE.

intof_map_id(conststructdevice_node*np,u32id,constchar*map_name,constchar*map_mask_name,structdevice_node**target,u32*id_out)

Translate an ID through a downstream mapping.

Parameters

conststructdevice_node*np

root complex device node.

u32id

device ID to map.

constchar*map_name

property name of the map to use.

constchar*map_mask_name

optional property name of the mask to use.

structdevice_node**target

optional pointer to a target device node.

u32*id_out

optional pointer to receive the translated ID.

Description

Given a device ID, look up the appropriate implementation-definedplatform ID and/or the target device which receives transactions on thatID, as per the “iommu-map” and “msi-map” bindings. Either oftarget orid_out may be NULL if only the other is required. Iftarget points toa non-NULL device node pointer, only entries targeting that node will bematched; if it points to a NULL value, it will receive the device node ofthe first matching target phandle, with a reference held.

Return

0 on success or a standard error code on failure.

voidof_node_init(structdevice_node*node)

initialize a devicetree node

Parameters

structdevice_node*node

Pointer to device node that has been created bykzalloc()

Description

On return the device_node refcount is set to one. Useof_node_put()onnode when done to free the memory allocated for it. If the nodeis NOT a dynamic node the memory will not be freed. The decision ofwhether to free the memory will be done by node->release(), which isof_node_release().

boolof_machine_is_compatible(constchar*compat)

Test root of device tree for a given compatible value

Parameters

constchar*compat

compatible string to look for in root node’s compatible property.

Return

true if the root node has the given value in its compatible property.

structdevice_node*of_parse_phandle(conststructdevice_node*np,constchar*phandle_name,intindex)

Resolve a phandle property to a device_node pointer

Parameters

conststructdevice_node*np

Pointer to device node holding phandle property

constchar*phandle_name

Name of property holding a phandle value

intindex

For properties holding a table of phandles, this is the index intothe table

Return

The device_node pointer with refcount incremented. Useof_node_put() on it when done.

intof_parse_phandle_with_args(conststructdevice_node*np,constchar*list_name,constchar*cells_name,intindex,structof_phandle_args*out_args)

Find a node pointed by phandle in a list

Parameters

conststructdevice_node*np

pointer to a device tree node containing a list

constchar*list_name

property name that contains a list

constchar*cells_name

property name that specifies phandles’ arguments count

intindex

index of a phandle to parse out

structof_phandle_args*out_args

optional pointer to output arguments structure (will be filled)

Description

This function is useful to parse lists of phandles and their arguments.Returns 0 on success and fills out_args, on error returns appropriateerrno value.

Caller is responsible to callof_node_put() on the returned out_args->nppointer.

Example:

phandle1: node1 {    #list-cells = <2>;};phandle2: node2 {    #list-cells = <1>;};node3 {    list = <&phandle1 1 2 &phandle2 3>;};

To get a device_node of thenode2 node you may call this:of_parse_phandle_with_args(node3, “list”, “#list-cells”, 1,args);

intof_parse_phandle_with_fixed_args(conststructdevice_node*np,constchar*list_name,intcell_count,intindex,structof_phandle_args*out_args)

Find a node pointed by phandle in a list

Parameters

conststructdevice_node*np

pointer to a device tree node containing a list

constchar*list_name

property name that contains a list

intcell_count

number of argument cells following the phandle

intindex

index of a phandle to parse out

structof_phandle_args*out_args

optional pointer to output arguments structure (will be filled)

Description

This function is useful to parse lists of phandles and their arguments.Returns 0 on success and fills out_args, on error returns appropriateerrno value.

Caller is responsible to callof_node_put() on the returned out_args->nppointer.

Example:

phandle1: node1 {};phandle2: node2 {};node3 {    list = <&phandle1 0 2 &phandle2 2 3>;};

To get a device_node of thenode2 node you may call this:of_parse_phandle_with_fixed_args(node3, “list”, 2, 1,args);

intof_parse_phandle_with_optional_args(conststructdevice_node*np,constchar*list_name,constchar*cells_name,intindex,structof_phandle_args*out_args)

Find a node pointed by phandle in a list

Parameters

conststructdevice_node*np

pointer to a device tree node containing a list

constchar*list_name

property name that contains a list

constchar*cells_name

property name that specifies phandles’ arguments count

intindex

index of a phandle to parse out

structof_phandle_args*out_args

optional pointer to output arguments structure (will be filled)

Description

Same asof_parse_phandle_with_args() except that if the cells_name propertyis not found, cell_count of 0 is assumed.

This is used to useful, if you have a phandle which didn’t have argumentsbefore and thus doesn’t have a ‘#*-cells’ property but is now migrated tohaving arguments while retaining backwards compatibility.

boolof_phandle_args_equal(conststructof_phandle_args*a1,conststructof_phandle_args*a2)

Compare two of_phandle_args

Parameters

conststructof_phandle_args*a1

First of_phandle_args to compare

conststructof_phandle_args*a2

Second of_phandle_args to compare

Return

True if a1 and a2 are the same (same node pointer, same phandleargs), false otherwise.

intof_property_count_u8_elems(conststructdevice_node*np,constchar*propname)

Count the number of u8 elements in a property

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

Description

Search for a property in a device node and count the number of u8 elementsin it.

Return

The number of elements on success, -EINVAL if the property doesnot exist or its length does not match a multiple of u8 and -ENODATA if theproperty does not have a value.

intof_property_count_u16_elems(conststructdevice_node*np,constchar*propname)

Count the number of u16 elements in a property

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

Description

Search for a property in a device node and count the number of u16 elementsin it.

Return

The number of elements on success, -EINVAL if the property doesnot exist or its length does not match a multiple of u16 and -ENODATA if theproperty does not have a value.

intof_property_count_u32_elems(conststructdevice_node*np,constchar*propname)

Count the number of u32 elements in a property

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

Description

Search for a property in a device node and count the number of u32 elementsin it.

Return

The number of elements on success, -EINVAL if the property doesnot exist or its length does not match a multiple of u32 and -ENODATA if theproperty does not have a value.

intof_property_count_u64_elems(conststructdevice_node*np,constchar*propname)

Count the number of u64 elements in a property

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

Description

Search for a property in a device node and count the number of u64 elementsin it.

Return

The number of elements on success, -EINVAL if the property doesnot exist or its length does not match a multiple of u64 and -ENODATA if theproperty does not have a value.

intof_property_read_string_array(conststructdevice_node*np,constchar*propname,constchar**out_strs,size_tsz)

Read an array of strings from a multiple strings property.

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

constchar**out_strs

output array of string pointers.

size_tsz

number of array elements to read.

Description

Search for a property in a device tree node and retrieve a list ofterminated string values (pointer to data, not a copy) in that property.

Return

Ifout_strs is NULL, the number of strings in the property is returned.

intof_property_count_strings(conststructdevice_node*np,constchar*propname)

Find and return the number of strings from a multiple strings property.

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

Description

Search for a property in a device tree node and retrieve the number of nullterminated string contain in it.

Return

The number of strings on success, -EINVAL if the property does notexist, -ENODATA if property does not have a value, and -EILSEQ if the stringis not null-terminated within the length of the property data.

intof_property_read_string_index(conststructdevice_node*np,constchar*propname,intindex,constchar**output)

Find and read a string from a multiple strings property.

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

intindex

index of the string in the list of strings

constchar**output

pointer to null terminated return string, modified only ifreturn value is 0.

Description

Search for a property in a device tree node and retrieve a nullterminated string value (pointer to data, not a copy) in the list of stringscontained in that property.

The out_string pointer is modified only if a valid string can be decoded.

Return

0 on success, -EINVAL if the property does not exist, -ENODATA ifproperty does not have a value, and -EILSEQ if the string is notnull-terminated within the length of the property data.

boolof_property_present(conststructdevice_node*np,constchar*propname)

Test if a property is present in a node

Parameters

conststructdevice_node*np

device node to search for the property.

constchar*propname

name of the property to be searched.

Description

Test for a property present in a device node.

Return

true if the property exists false otherwise.

intof_property_read_u8_array(conststructdevice_node*np,constchar*propname,u8*out_values,size_tsz)

Find and read an array of u8 from a property.

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

u8*out_values

pointer to return value, modified only if return value is 0.

size_tsz

number of array elements to read

Description

Search for a property in a device node and read 8-bit value(s) fromit.

dts entry of array should be like:

property=/bits/8<0x500x600x70>;

The out_values is modified only if a valid u8 value can be decoded.

Return

0 on success, -EINVAL if the property does not exist,-ENODATA if property does not have a value, and -EOVERFLOW if theproperty data isn’t large enough.

intof_property_read_u16_array(conststructdevice_node*np,constchar*propname,u16*out_values,size_tsz)

Find and read an array of u16 from a property.

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

u16*out_values

pointer to return value, modified only if return value is 0.

size_tsz

number of array elements to read

Description

Search for a property in a device node and read 16-bit value(s) fromit.

dts entry of array should be like:

property=/bits/16<0x50000x60000x7000>;

The out_values is modified only if a valid u16 value can be decoded.

Return

0 on success, -EINVAL if the property does not exist,-ENODATA if property does not have a value, and -EOVERFLOW if theproperty data isn’t large enough.

intof_property_read_u32_array(conststructdevice_node*np,constchar*propname,u32*out_values,size_tsz)

Find and read an array of 32 bit integers from a property.

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

u32*out_values

pointer to return value, modified only if return value is 0.

size_tsz

number of array elements to read

Description

Search for a property in a device node and read 32-bit value(s) fromit.

The out_values is modified only if a valid u32 value can be decoded.

Return

0 on success, -EINVAL if the property does not exist,-ENODATA if property does not have a value, and -EOVERFLOW if theproperty data isn’t large enough.

intof_property_read_u64_array(conststructdevice_node*np,constchar*propname,u64*out_values,size_tsz)

Find and read an array of 64 bit integers from a property.

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

u64*out_values

pointer to return value, modified only if return value is 0.

size_tsz

number of array elements to read

Description

Search for a property in a device node and read 64-bit value(s) fromit.

The out_values is modified only if a valid u64 value can be decoded.

Return

0 on success, -EINVAL if the property does not exist,-ENODATA if property does not have a value, and -EOVERFLOW if theproperty data isn’t large enough.

structof_changeset_entry

Holds a changeset entry

Definition:

struct of_changeset_entry {    struct list_head node;    unsigned long action;    struct device_node *np;    struct property *prop;    struct property *old_prop;};

Members

node

list_head for the log list

action

notifier action

np

pointer to the device node affected

prop

pointer to the property affected

old_prop

hold a pointer to the original property

Description

Every modification of the device tree during a changesetis held in a list of of_changeset_entry structures.That way we can recover from a partial application, or we canrevert the changeset

structof_changeset

changeset tracker structure

Definition:

struct of_changeset {    struct list_head entries;};

Members

entries

list_head for the changeset entries

Description

changesets are a convenient way to apply bulk changes to thelive tree. In case of an error, changes are rolled-back.changesets live on after initial application, and if notdestroyed after use, they can be reverted in one single call.

boolof_device_is_system_power_controller(conststructdevice_node*np)

Tells if system-power-controller is found for device_node

Parameters

conststructdevice_node*np

Pointer to the given device_node

Return

true if present false otherwise

boolof_have_populated_dt(void)

Has DT been populated by bootloader

Parameters

void

no arguments

Return

True if a DTB has been populated by the bootloader and it isn’t theempty builtin one. False otherwise.

boolof_property_read_bool(conststructdevice_node*np,constchar*propname)

Find a property

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

Description

Search for a boolean property in a device node. Usage on non-booleanproperty types is deprecated.

Return

true if the property exists false otherwise.

boolof_graph_is_present(conststructdevice_node*node)

check graph’s presence

Parameters

conststructdevice_node*node

pointer to device_node containing graph port

Return

True ifnode has a port or ports (with a port) sub-node,false otherwise.

intof_property_count_elems_of_size(conststructdevice_node*np,constchar*propname,intelem_size)

Count the number of elements in a property

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

intelem_size

size of the individual element

Description

Search for a property in a device node and count the number of elements ofsize elem_size in it.

Return

The number of elements on sucess, -EINVAL if the property does notexist or its length does not match a multiple of elem_size and -ENODATA ifthe property does not have a value.

intof_property_read_u8_index(conststructdevice_node*np,constchar*propname,u32index,u8*out_value)

Find and read a u8 from a multi-value property.

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

u32index

index of the u8 in the list of values

u8*out_value

pointer to return value, modified only if no error.

Description

Search for a property in a device node and read nth 8-bit value fromit.

The out_value is modified only if a valid u8 value can be decoded.

Return

0 on success, -EINVAL if the property does not exist,-ENODATA if property does not have a value, and -EOVERFLOW if theproperty data isn’t large enough.

intof_property_read_u16_index(conststructdevice_node*np,constchar*propname,u32index,u16*out_value)

Find and read a u16 from a multi-value property.

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

u32index

index of the u16 in the list of values

u16*out_value

pointer to return value, modified only if no error.

Description

Search for a property in a device node and read nth 16-bit value fromit.

The out_value is modified only if a valid u16 value can be decoded.

Return

0 on success, -EINVAL if the property does not exist,-ENODATA if property does not have a value, and -EOVERFLOW if theproperty data isn’t large enough.

intof_property_read_u32_index(conststructdevice_node*np,constchar*propname,u32index,u32*out_value)

Find and read a u32 from a multi-value property.

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

u32index

index of the u32 in the list of values

u32*out_value

pointer to return value, modified only if no error.

Description

Search for a property in a device node and read nth 32-bit value fromit.

The out_value is modified only if a valid u32 value can be decoded.

Return

0 on success, -EINVAL if the property does not exist,-ENODATA if property does not have a value, and -EOVERFLOW if theproperty data isn’t large enough.

intof_property_read_u64_index(conststructdevice_node*np,constchar*propname,u32index,u64*out_value)

Find and read a u64 from a multi-value property.

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

u32index

index of the u64 in the list of values

u64*out_value

pointer to return value, modified only if no error.

Description

Search for a property in a device node and read nth 64-bit value fromit.

The out_value is modified only if a valid u64 value can be decoded.

Return

0 on success, -EINVAL if the property does not exist,-ENODATA if property does not have a value, and -EOVERFLOW if theproperty data isn’t large enough.

intof_property_read_variable_u8_array(conststructdevice_node*np,constchar*propname,u8*out_values,size_tsz_min,size_tsz_max)

Find and read an array of u8 from a property, with bounds on the minimum and maximum array size.

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

u8*out_values

pointer to found values.

size_tsz_min

minimum number of array elements to read

size_tsz_max

maximum number of array elements to read, if zero there is noupper limit on the number of elements in the dts entry but onlysz_min will be read.

Description

Search for a property in a device node and read 8-bit value(s) fromit.

dts entry of array should be like:

property=/bits/8<0x500x600x70>;

The out_values is modified only if a valid u8 value can be decoded.

Return

The number of elements read on success, -EINVAL if the propertydoes not exist, -ENODATA if property does not have a value, and -EOVERFLOWif the property data is smaller than sz_min or longer than sz_max.

intof_property_read_variable_u16_array(conststructdevice_node*np,constchar*propname,u16*out_values,size_tsz_min,size_tsz_max)

Find and read an array of u16 from a property, with bounds on the minimum and maximum array size.

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

u16*out_values

pointer to found values.

size_tsz_min

minimum number of array elements to read

size_tsz_max

maximum number of array elements to read, if zero there is noupper limit on the number of elements in the dts entry but onlysz_min will be read.

Description

Search for a property in a device node and read 16-bit value(s) fromit.

dts entry of array should be like:

property=/bits/16<0x50000x60000x7000>;

The out_values is modified only if a valid u16 value can be decoded.

Return

The number of elements read on success, -EINVAL if the propertydoes not exist, -ENODATA if property does not have a value, and -EOVERFLOWif the property data is smaller than sz_min or longer than sz_max.

intof_property_read_variable_u32_array(conststructdevice_node*np,constchar*propname,u32*out_values,size_tsz_min,size_tsz_max)

Find and read an array of 32 bit integers from a property, with bounds on the minimum and maximum array size.

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

u32*out_values

pointer to return found values.

size_tsz_min

minimum number of array elements to read

size_tsz_max

maximum number of array elements to read, if zero there is noupper limit on the number of elements in the dts entry but onlysz_min will be read.

Description

Search for a property in a device node and read 32-bit value(s) fromit.

The out_values is modified only if a valid u32 value can be decoded.

Return

The number of elements read on success, -EINVAL if the propertydoes not exist, -ENODATA if property does not have a value, and -EOVERFLOWif the property data is smaller than sz_min or longer than sz_max.

intof_property_read_u64(conststructdevice_node*np,constchar*propname,u64*out_value)

Find and read a 64 bit integer from a property

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

u64*out_value

pointer to return value, modified only if return value is 0.

Description

Search for a property in a device node and read a 64-bit value fromit.

The out_value is modified only if a valid u64 value can be decoded.

Return

0 on success, -EINVAL if the property does not exist,-ENODATA if property does not have a value, and -EOVERFLOW if theproperty data isn’t large enough.

intof_property_read_variable_u64_array(conststructdevice_node*np,constchar*propname,u64*out_values,size_tsz_min,size_tsz_max)

Find and read an array of 64 bit integers from a property, with bounds on the minimum and maximum array size.

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

u64*out_values

pointer to found values.

size_tsz_min

minimum number of array elements to read

size_tsz_max

maximum number of array elements to read, if zero there is noupper limit on the number of elements in the dts entry but onlysz_min will be read.

Description

Search for a property in a device node and read 64-bit value(s) fromit.

The out_values is modified only if a valid u64 value can be decoded.

Return

The number of elements read on success, -EINVAL if the propertydoes not exist, -ENODATA if property does not have a value, and -EOVERFLOWif the property data is smaller than sz_min or longer than sz_max.

intof_property_read_string(conststructdevice_node*np,constchar*propname,constchar**out_string)

Find and read a string from a property

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

constchar**out_string

pointer to null terminated return string, modified only ifreturn value is 0.

Description

Search for a property in a device tree node and retrieve a nullterminated string value (pointer to data, not a copy).

Note that the empty string “” has length of 1, thus -ENODATA cannotbe interpreted as an empty string.

The out_string pointer is modified only if a valid string can be decoded.

Return

0 on success, -EINVAL if the property does not exist, -ENODATA ifproperty does not have a value, and -EILSEQ if the string is notnull-terminated within the length of the property data.

intof_property_match_string(conststructdevice_node*np,constchar*propname,constchar*string)

Find string in a list and return index

Parameters

conststructdevice_node*np

pointer to the node containing the string list property

constchar*propname

string list property name

constchar*string

pointer to the string to search for in the string list

Description

Search for an exact match of string in a device node property which is astring of lists.

Return

the index of the first occurrence of the string on success, -EINVALif the property does not exist, -ENODATA if the property does not have avalue, and -EILSEQ if the string is not null-terminated within the length ofthe property data.

intof_property_read_string_helper(conststructdevice_node*np,constchar*propname,constchar**out_strs,size_tsz,intskip)

Utility helper for parsing string properties

Parameters

conststructdevice_node*np

device node from which the property value is to be read.

constchar*propname

name of the property to be searched.

constchar**out_strs

output array of string pointers.

size_tsz

number of array elements to read.

intskip

Number of strings to skip over at beginning of list.

Description

Don’t call this function directly. It is a utility helper for theof_property_read_string*() family of functions.

intof_graph_parse_endpoint(conststructdevice_node*node,structof_endpoint*endpoint)

parse common endpoint node properties

Parameters

conststructdevice_node*node

pointer to endpoint device_node

structof_endpoint*endpoint

pointer to the OF endpoint data structure

Description

The caller should hold a reference tonode.

structdevice_node*of_graph_get_port_by_id(structdevice_node*parent,u32id)

get the port matching a given id

Parameters

structdevice_node*parent

pointer to the parent device node

u32id

id of the port

Return

A ‘port’ node pointer with refcount incremented. The callerhas to useof_node_put() on it when done.

structdevice_node*of_graph_get_next_port(conststructdevice_node*parent,structdevice_node*prev)

get next port node.

Parameters

conststructdevice_node*parent

pointer to the parent device node, or parent ports node

structdevice_node*prev

previous port node, or NULL to get first

Description

Parent device node can be used asparent whether device node has ports nodeor not. It will work same as ports**0** node.

Return

A ‘port’ node pointer with refcount incremented. Refcountof the passedprev node is decremented.

structdevice_node*of_graph_get_next_port_endpoint(conststructdevice_node*port,structdevice_node*prev)

get next endpoint node in port. If it reached to end of the port, it will return NULL.

Parameters

conststructdevice_node*port

pointer to the target port node

structdevice_node*prev

previous endpoint node, or NULL to get first

Return

An ‘endpoint’ node pointer with refcount incremented. Refcountof the passedprev node is decremented.

structdevice_node*of_graph_get_next_endpoint(conststructdevice_node*parent,structdevice_node*prev)

get next endpoint node

Parameters

conststructdevice_node*parent

pointer to the parent device node

structdevice_node*prev

previous endpoint node, or NULL to get first

Return

An ‘endpoint’ node pointer with refcount incremented. Refcountof the passedprev node is decremented.

structdevice_node*of_graph_get_endpoint_by_regs(conststructdevice_node*parent,intport_reg,intreg)

get endpoint node of specific identifiers

Parameters

conststructdevice_node*parent

pointer to the parent device node

intport_reg

identifier (value of reg property) of the parent port node

intreg

identifier (value of reg property) of the endpoint node

Return

An ‘endpoint’ node pointer which is identified by reg and at the sameis the child of a port node identified by port_reg. reg and port_reg areignored when they are -1. Useof_node_put() on the pointer when done.

structdevice_node*of_graph_get_remote_endpoint(conststructdevice_node*node)

get remote endpoint node

Parameters

conststructdevice_node*node

pointer to a local endpoint device_node

Return

Remote endpoint node associated with remote endpoint node linkedtonode. Useof_node_put() on it when done.

structdevice_node*of_graph_get_port_parent(structdevice_node*node)

get port’s parent node

Parameters

structdevice_node*node

pointer to a local endpoint device_node

Return

device node associated with endpoint node linkedtonode. Useof_node_put() on it when done.

structdevice_node*of_graph_get_remote_port_parent(conststructdevice_node*node)

get remote port’s parent node

Parameters

conststructdevice_node*node

pointer to a local endpoint device_node

Return

Remote device node associated with remote endpoint node linkedtonode. Useof_node_put() on it when done.

structdevice_node*of_graph_get_remote_port(conststructdevice_node*node)

get remote port node

Parameters

conststructdevice_node*node

pointer to a local endpoint device_node

Return

Remote port node associated with remote endpoint node linkedtonode. Useof_node_put() on it when done.

unsignedintof_graph_get_endpoint_count(conststructdevice_node*np)

get the number of endpoints in a device node

Parameters

conststructdevice_node*np

parent device node containing ports and endpoints

Return

count of endpoint of this device node

unsignedintof_graph_get_port_count(structdevice_node*np)

get the number of port in a device or ports node

Parameters

structdevice_node*np

pointer to the device or ports node

Return

count of port of this device or ports node

structdevice_node*of_graph_get_remote_node(conststructdevice_node*node,u32port,u32endpoint)

get remote parent device_node for given port/endpoint

Parameters

conststructdevice_node*node

pointer to parent device_node containing graph port/endpoint

u32port

identifier (value of reg property) of the parent port node

u32endpoint

identifier (value of reg property) of the endpoint node

Return

Remote device node associated with remote endpoint node linkedtonode. Useof_node_put() on it when done.

structof_endpoint

the OF graph endpoint data structure

Definition:

struct of_endpoint {    unsigned int port;    unsigned int id;    const struct device_node *local_node;};

Members

port

identifier (value of reg property) of a port this endpoint belongs to

id

identifier (value of reg property) of this endpoint

local_node

pointer to device_node of this endpoint

for_each_endpoint_of_node

for_each_endpoint_of_node(parent,child)

iterate over every endpoint in a device node

Parameters

parent

parent device node containing ports and endpoints

child

loop variable pointing to the current endpoint node

Description

When breaking out of the loop, of_node_put(child) has to be called manually.

for_each_of_graph_port

for_each_of_graph_port(parent,child)

iterate over every port in a device or ports node

Parameters

parent

parent device or ports node containing port

child

loop variable pointing to the current port node

Description

When breaking out of the loop, and continue to use thechild, you need touse return_ptr(child) or no_free_ptr(child) not to call__free() for it.

for_each_of_graph_port_endpoint

for_each_of_graph_port_endpoint(parent,child)

iterate over every endpoint in a port node

Parameters

parent

parent port node

child

loop variable pointing to the current endpoint node

Description

When breaking out of the loop, and continue to use thechild, you need touse return_ptr(child) or no_free_ptr(child) not to call__free() for it.

const__be32*of_translate_dma_region(structdevice_node*dev,const__be32*prop,phys_addr_t*start,size_t*length)

Translate device tree address and size tuple

Parameters

structdevice_node*dev

device tree node for which to translate

const__be32*prop

pointer into array of cells

phys_addr_t*start

return value for the start of the DMA range

size_t*length

return value for the length of the DMA range

Description

Returns a pointer to the cell immediately following the translated DMA region.

intof_property_read_reg(structdevice_node*np,intidx,u64*addr,u64*size)

Retrieve the specified “reg” entry index without translating

Parameters

structdevice_node*np

device tree node for which to retrieve “reg” from

intidx

“reg” entry index to read

u64*addr

return value for the untranslated address

u64*size

return value for the entry size

Description

Returns -EINVAL if “reg” is not found. Returns 0 on success with addr andsize values filled in.

boolof_dma_is_coherent(structdevice_node*np)

Check if device is coherent

Parameters

structdevice_node*np

device node

Description

It returns true if “dma-coherent” property was foundfor this device in the DT, or if DMA is coherent bydefault for OF devices on the current platform and no“dma-noncoherent” property was found for this device.

intof_address_to_resource(structdevice_node*dev,intindex,structresource*r)

Translate device tree address and return as resource

Parameters

structdevice_node*dev

Caller’s Device Node

intindex

Index into the array

structresource*r

Pointer to resource array

Description

Returns -EINVAL if the range cannot be converted to resource.

Note that if your address is a PIO address, the conversion will fail ifthe physical address can’t be internally converted to an IO token withpci_address_to_pio(), that is because it’s either called too early or itcan’t be matched to any host bridge IO space

void__iomem*of_iomap(structdevice_node*np,intindex)

Maps the memory mapped IO for a given device_node

Parameters

structdevice_node*np

the device whose io range will be mapped

intindex

index of the io range

Description

Returns a pointer to the mapped memory

unsignedintirq_of_parse_and_map(structdevice_node*dev,intindex)

Parse and map an interrupt into linux virq space

Parameters

structdevice_node*dev

Device node of the device whose interrupt is to be mapped

intindex

Index of the interrupt to map

Description

This function is a wrapper that chainsof_irq_parse_one() andirq_create_of_mapping() to make things easier to callers

structdevice_node*of_irq_find_parent(structdevice_node*child)

Given a device node, find its interrupt parent node

Parameters

structdevice_node*child

pointer to device node

Return

A pointer to the interrupt parent node with refcount increasedor NULL if the interrupt parent could not be determined.

intof_irq_parse_raw(const__be32*addr,structof_phandle_args*out_irq)

Low level interrupt tree parsing

Parameters

const__be32*addr

address specifier (start of “reg” property of the device) in be32 format

structof_phandle_args*out_irq

structure of_phandle_args updated by this function

Description

This function is a low-level interrupt tree walking function. Itcan be used to do a partial walk with synthesized reg and interruptsproperties, for example when resolving PCI interrupts when no devicenode exist for the parent. It takes an interrupt specifier structure asinput, walks the tree looking for any interrupt-map properties, translatesthe specifier for each map, and then returns the translated map.

Return

0 on success and a negative number on error

Note

refcount of nodeout_irq->np is increased by 1 on success.

intof_irq_parse_one(structdevice_node*device,intindex,structof_phandle_args*out_irq)

Resolve an interrupt for a device

Parameters

structdevice_node*device

the device whose interrupt is to be resolved

intindex

index of the interrupt to resolve

structof_phandle_args*out_irq

structure of_phandle_args filled by this function

Description

This function resolves an interrupt for a node by walking the interrupt tree,finding which interrupt controller node it is attached to, and returning theinterrupt specifier that can be used to retrieve a Linux IRQ number.

Note

refcount of nodeout_irq->np is increased by 1 on success.

intof_irq_to_resource(structdevice_node*dev,intindex,structresource*r)

Decode a node’s IRQ and return it as a resource

Parameters

structdevice_node*dev

pointer to device tree node

intindex

zero-based index of the irq

structresource*r

pointer to resource structure to return result into.

intof_irq_get(structdevice_node*dev,intindex)

Decode a node’s IRQ and return it as a Linux IRQ number

Parameters

structdevice_node*dev

pointer to device tree node

intindex

zero-based index of the IRQ

Return

Linux IRQ number on success, or 0 on the IRQ mapping failure, or-EPROBE_DEFER if the IRQ domain is not yet created, or error code in caseof any other failure.

intof_irq_get_byname(structdevice_node*dev,constchar*name)

Decode a node’s IRQ and return it as a Linux IRQ number

Parameters

structdevice_node*dev

pointer to device tree node

constchar*name

IRQ name

Return

Linux IRQ number on success, or 0 on the IRQ mapping failure, or-EPROBE_DEFER if the IRQ domain is not yet created, or error code in caseof any other failure.

intof_irq_count(structdevice_node*dev)

Count the number of IRQs a node uses

Parameters

structdevice_node*dev

pointer to device tree node

intof_irq_to_resource_table(structdevice_node*dev,structresource*res,intnr_irqs)

Fill in resource table with node’s IRQ info

Parameters

structdevice_node*dev

pointer to device tree node

structresource*res

array of resources to fill in

intnr_irqs

the number of IRQs (and upper bound for num ofres elements)

Return

The size of the filled in table (up tonr_irqs).

u32of_msi_xlate(structdevice*dev,structdevice_node**msi_np,u32id_in)

map a MSI ID and find relevant MSI controller node

Parameters

structdevice*dev

device for which the mapping is to be done.

structdevice_node**msi_np

Pointer to target MSI controller node

u32id_in

Device ID.

Description

Walk up the device hierarchy looking for devices with a “msi-map”or “msi-parent” property. If found, apply the mapping toid_in.Ifmsi_np points to a non-NULL device node pointer, only entries targetingthat node will be matched; if it points to a NULL value, it will receive thedevice node of the first matching target phandle, with a reference held.

Return

The mapped MSI id.

structirq_domain*of_msi_get_domain(structdevice*dev,conststructdevice_node*np,enumirq_domain_bus_tokentoken)

Use msi-parent to find the relevant MSI domain

Parameters

structdevice*dev

device for which the domain is requested

conststructdevice_node*np

device node fordev

enumirq_domain_bus_tokentoken

bus type for this domain

Description

Parse the msi-parent property and returns the corresponding MSI domain.

Return

the MSI domain for this device (or NULL on failure).

voidof_msi_configure(structdevice*dev,conststructdevice_node*np)

Set the msi_domain field of a device

Parameters

structdevice*dev

device structure to associate with an MSI irq domain

conststructdevice_node*np

device node for that device

void*of_fdt_unflatten_tree(constunsignedlong*blob,structdevice_node*dad,structdevice_node**mynodes)

create tree of device_nodes from flat blob

Parameters

constunsignedlong*blob

Flat device tree blob

structdevice_node*dad

Parent device node

structdevice_node**mynodes

The device tree created by the call

Description

unflattens the device-tree passed by the firmware, creating thetree ofstructdevice_node. It also fills the “name” and “type”pointers of the nodes so the normal device-tree walking functionscan be used.

Return

NULL on failure or the memory chunk containing the unflatteneddevice tree on success.

Driver model functions

intof_driver_match_device(structdevice*dev,conststructdevice_driver*drv)

Tell if a driver’s of_match_table matches a device.

Parameters

structdevice*dev

the device structure to match against

conststructdevice_driver*drv

the device_driver structure to test

conststructof_device_id*of_match_device(conststructof_device_id*matches,conststructdevice*dev)

Tell if astructdevice matches an of_device_id list

Parameters

conststructof_device_id*matches

array of of_device_id match structures to search in

conststructdevice*dev

the OF device structure to match against

Description

Used by a driver to check whether an platform_device present in thesystem is in its list of supported devices.

intof_dma_configure_id(structdevice*dev,structdevice_node*np,boolforce_dma,constu32*id)

Setup DMA configuration

Parameters

structdevice*dev

Device to apply DMA configuration

structdevice_node*np

Pointer to OF node having DMA configuration

boolforce_dma

Whether device is to be set up byof_dma_configure() even ifDMA capability is not explicitly described by firmware.

constu32*id

Optional const pointer value input id

Description

Try to get devices’s DMA configuration from DT and update itaccordingly.

If platform code needs to use its own special DMA configuration, itcan use a platform bus notifier and handle BUS_NOTIFY_ADD_DEVICE eventsto fix up DMA configuration.

ssize_tof_device_modalias(structdevice*dev,char*str,ssize_tlen)

Fill buffer with newline terminated modalias string

Parameters

structdevice*dev

Calling device

char*str

Modalias string

ssize_tlen

Size ofstr

voidof_device_uevent(conststructdevice*dev,structkobj_uevent_env*env)

Display OF related uevent information

Parameters

conststructdevice*dev

Device to display the uevent information for

structkobj_uevent_env*env

Kernel object’s userspace event reference to fill up

voidof_device_make_bus_id(structdevice*dev)

Use the device node data to assign a unique name

Parameters

structdevice*dev

pointer to device structure that is linked to a device tree node

Description

This routine will first try using the translated bus address toderive a unique name. If it cannot, then it will prepend names fromparent nodes until a unique name can be derived.

structof_dev_auxdata

lookup table entry for device names & platform_data

Definition:

struct of_dev_auxdata {    char *compatible;    resource_size_t phys_addr;    char *name;    void *platform_data;};

Members

compatible

compatible value of node to match against node

phys_addr

Start address of registers to match against node

name

Name to assign for matching nodes

platform_data

platform_data to assign for matching nodes

Description

This lookup table allows the caller ofof_platform_populate() to overridethe names of devices when creating devices from the device tree. The tableshould be terminated with an empty entry. It also allows the platform_datapointer to be set.

The reason for this functionality is that some Linux infrastructure usesthe device name to look up a specific device, but the Linux-specific namesare not encoded into the device tree, so the kernel needs to provide specificvalues.

Note

Using an auxdata lookup table should be considered a last resort whenconverting a platform to use the DT. Normally the automatically generateddevice name will not matter, and drivers should obtain data from the devicenode instead of from an anonymous platform_data pointer.

structplatform_device*of_find_device_by_node(structdevice_node*np)

Find the platform_device associated with a node

Parameters

structdevice_node*np

Pointer to device tree node

Description

Takes a reference to the embeddedstructdevice which needs to be droppedafter use.

Return

platform_device pointer, or NULL if not found

structplatform_device*of_device_alloc(structdevice_node*np,constchar*bus_id,structdevice*parent)

Allocate and initialize an of_device

Parameters

structdevice_node*np

device node to assign to device

constchar*bus_id

Name to assign to the device. May be null to use default name.

structdevice*parent

Parent device.

structplatform_device*of_platform_device_create(structdevice_node*np,constchar*bus_id,structdevice*parent)

Alloc, initialize and register an of_device

Parameters

structdevice_node*np

pointer to node to create device for

constchar*bus_id

name to assign device

structdevice*parent

Linux device model parent device.

Return

Pointer to created platform device, or NULL if a device was notregistered. Unavailable devices will not get registered.

intof_platform_bus_probe(structdevice_node*root,conststructof_device_id*matches,structdevice*parent)

Probe the device-tree for platform buses

Parameters

structdevice_node*root

parent of the first level to probe or NULL for the root of the tree

conststructof_device_id*matches

match table for bus nodes

structdevice*parent

parent to hook devices from, NULL for toplevel

Description

Note that children of the provided root are not instantiated as devicesunless the specified root itself matches the bus list and is not NULL.

intof_platform_populate(structdevice_node*root,conststructof_device_id*matches,conststructof_dev_auxdata*lookup,structdevice*parent)

Populate platform_devices from device tree data

Parameters

structdevice_node*root

parent of the first level to probe or NULL for the root of the tree

conststructof_device_id*matches

match table, NULL to use the default

conststructof_dev_auxdata*lookup

auxdata table for matching id and platform_data with device nodes

structdevice*parent

parent to hook devices from, NULL for toplevel

Description

Similar toof_platform_bus_probe(), this function walks the device treeand creates devices from nodes. It differs in that it follows the modernconvention of requiring all device nodes to have a ‘compatible’ property,and it is suitable for creating devices which are children of the rootnode (of_platform_bus_probe will only create children of the root whichare selected by thematches argument).

New board support should be using this function instead ofof_platform_bus_probe().

Return

0 on success, < 0 on failure.

voidof_platform_depopulate(structdevice*parent)

Remove devices populated from device tree

Parameters

structdevice*parent

device which children will be removed

Description

Complementary toof_platform_populate(), this function removes childrenof the given device (and, recursively, their children) that have beencreated from their respective device tree nodes (and only those,leaving others - eg. manually created - unharmed).

intdevm_of_platform_populate(structdevice*dev)

Populate platform_devices from device tree data

Parameters

structdevice*dev

device that requested to populate from device tree data

Description

Similar toof_platform_populate(), but will automatically callof_platform_depopulate() when the device is unbound from the bus.

Return

0 on success, < 0 on failure.

voiddevm_of_platform_depopulate(structdevice*dev)

Remove devices populated from device tree

Parameters

structdevice*dev

device that requested to depopulate from device tree data

Description

Complementary todevm_of_platform_populate(), this function removes childrenof the given device (and, recursively, their children) that have beencreated from their respective device tree nodes (and only those,leaving others - eg. manually created - unharmed).

Overlay and Dynamic DT functions

intof_resolve_phandles(structdevice_node*overlay)

Relocate and resolve overlay against live tree

Parameters

structdevice_node*overlay

Pointer to devicetree overlay to relocate and resolve

Description

Modify (relocate) values of local phandles inoverlay to a range thatdoes not conflict with the live expanded devicetree. Update referencesto the local phandles inoverlay. Update (resolve) phandle referencesinoverlay that refer to the live expanded devicetree.

Phandle values in the live tree are in the range of1 ..live_tree_max_phandle(). The range of phandle values in the overlayalso begin with at 1. Adjust the phandle values in the overlay to beginatlive_tree_max_phandle() + 1. Update references to the phandles tothe adjusted phandle values.

The name of each property in the “__fixups__” node in the overlay matchesthe name of a symbol (a label) in the live tree. The values of eachproperty in the “__fixups__” node is a list of the property values in theoverlay that need to be updated to contain the phandle referencecorresponding to that symbol in the live tree. Update the references inthe overlay with the phandle values in the live tree.

overlay must be detached.

Resolving and applyingoverlay to the live expanded devicetree must beprotected by a mechanism to ensure that multiple overlays are processedin a single threaded manner so that multiple overlays will not relocatephandles to overlapping ranges. The mechanism to enforce this is notyet implemented.

Return

0 on success or a negative error value on error.

structdevice_node*of_node_get(structdevice_node*node)

Increment refcount of a node

Parameters

structdevice_node*node

Node to inc refcount, NULL is supported to simplify writing ofcallers

Return

The node with refcount incremented.

voidof_node_put(structdevice_node*node)

Decrement refcount of a node

Parameters

structdevice_node*node

Node to dec refcount, NULL is supported to simplify writing ofcallers

intof_detach_node(structdevice_node*np)

“Unplug” a node from the device tree.

Parameters

structdevice_node*np

Pointer to the caller’s Device Node

structdevice_node*of_changeset_create_node(structof_changeset*ocs,structdevice_node*parent,constchar*full_name)

Dynamically create a device node and attach to a given changeset.

Parameters

structof_changeset*ocs

Pointer to changeset

structdevice_node*parent

Pointer to parent device node

constchar*full_name

Node full name

Return

Pointer to the created device node or NULL in case of an error.

voidof_changeset_init(structof_changeset*ocs)

Initialize a changeset for use

Parameters

structof_changeset*ocs

changeset pointer

Description

Initialize a changeset structure

voidof_changeset_destroy(structof_changeset*ocs)

Destroy a changeset

Parameters

structof_changeset*ocs

changeset pointer

Description

Destroys a changeset. Note that if a changeset is applied,its changes to the tree cannot be reverted.

intof_changeset_apply(structof_changeset*ocs)

Applies a changeset

Parameters

structof_changeset*ocs

changeset pointer

Description

Applies a changeset to the live tree.Any side-effects of live tree state changes are applied here onsuccess, like creation/destruction of devices and side-effectslike creation of sysfs properties and directories.

Return

0 on success, a negative error value in case of an error.On error the partially applied effects are reverted.

intof_changeset_revert(structof_changeset*ocs)

Reverts an applied changeset

Parameters

structof_changeset*ocs

changeset pointer

Description

Reverts a changeset returning the state of the tree to what itwas before the application.Any side-effects like creation/destruction of devices andremoval of sysfs properties and directories are applied.

Return

0 on success, a negative error value in case of an error.

intof_changeset_action(structof_changeset*ocs,unsignedlongaction,structdevice_node*np,structproperty*prop)

Add an action to the tail of the changeset list

Parameters

structof_changeset*ocs

changeset pointer

unsignedlongaction

action to perform

structdevice_node*np

Pointer to device node

structproperty*prop

Pointer to property

Description

On action being one of:+ OF_RECONFIG_ATTACH_NODE+ OF_RECONFIG_DETACH_NODE,+ OF_RECONFIG_ADD_PROPERTY+ OF_RECONFIG_REMOVE_PROPERTY,+ OF_RECONFIG_UPDATE_PROPERTY

Return

0 on success, a negative error value in case of an error.

intof_changeset_add_prop_string(structof_changeset*ocs,structdevice_node*np,constchar*prop_name,constchar*str)

Add a string property to a changeset

Parameters

structof_changeset*ocs

changeset pointer

structdevice_node*np

device node pointer

constchar*prop_name

name of the property to be added

constchar*str

pointer to null terminated string

Description

Create a string property and add it to a changeset.

Return

0 on success, a negative error value in case of an error.

intof_changeset_add_prop_string_array(structof_changeset*ocs,structdevice_node*np,constchar*prop_name,constchar*const*str_array,size_tsz)

Add a string list property to a changeset

Parameters

structof_changeset*ocs

changeset pointer

structdevice_node*np

device node pointer

constchar*prop_name

name of the property to be added

constchar*const*str_array

pointer to an array of null terminated strings

size_tsz

number of string array elements

Description

Create a string list property and add it to a changeset.

Return

0 on success, a negative error value in case of an error.

intof_changeset_add_prop_u32_array(structof_changeset*ocs,structdevice_node*np,constchar*prop_name,constu32*array,size_tsz)

Add a property of 32 bit integers property to a changeset

Parameters

structof_changeset*ocs

changeset pointer

structdevice_node*np

device node pointer

constchar*prop_name

name of the property to be added

constu32*array

pointer to an array of 32 bit integers

size_tsz

number of array elements

Description

Create a property of 32 bit integers and add it to a changeset.

Return

0 on success, a negative error value in case of an error.

intof_changeset_add_prop_bool(structof_changeset*ocs,structdevice_node*np,constchar*prop_name)

Add a boolean property (i.e. a property without any values) to a changeset.

Parameters

structof_changeset*ocs

changeset pointer

structdevice_node*np

device node pointer

constchar*prop_name

name of the property to be added

Description

Create a boolean property and add it to a changeset.

Return

0 on success, a negative error value in case of an error.

intof_changeset_update_prop_string(structof_changeset*ocs,structdevice_node*np,constchar*prop_name,constchar*str)

Add a string property update to a changeset

Parameters

structof_changeset*ocs

changeset pointer

structdevice_node*np

device node pointer

constchar*prop_name

name of the property to be updated

constchar*str

pointer to null terminated string

Description

Create a string property to be updated and add it to a changeset.

Return

0 on success, a negative error value in case of an error.

intof_overlay_notifier_register(structnotifier_block*nb)

Register notifier for overlay operations

Parameters

structnotifier_block*nb

Notifier block to register

Description

Register for notification on overlay operations on device tree nodes. Thereported actions defined byof_reconfig_change. The notifier callbackfurthermore receives a pointer to the affected device tree node.

Note that a notifier callback is not supposed to store pointers to a devicetree node or its content beyondOF_OVERLAY_POST_REMOVE corresponding to therespective node it received.

intof_overlay_notifier_unregister(structnotifier_block*nb)

Unregister notifier for overlay operations

Parameters

structnotifier_block*nb

Notifier block to unregister

intof_overlay_fdt_apply(constvoid*overlay_fdt,u32overlay_fdt_size,int*ret_ovcs_id,conststructdevice_node*base)

Create and apply an overlay changeset

Parameters

constvoid*overlay_fdt

pointer to overlay FDT

u32overlay_fdt_size

number of bytes inoverlay_fdt

int*ret_ovcs_id

pointer for returning created changeset id

conststructdevice_node*base

pointer for the target node to apply overlay

Description

Creates and applies an overlay changeset.

Seeof_overlay_apply() for important behavior information.

On error return, the changeset may be partially applied. This is especiallylikely if an OF_OVERLAY_POST_APPLY notifier returns an error. In this casethe caller should callof_overlay_remove() with the value in*ret_ovcs_id.

Return

0 on success, or a negative error number.*ret_ovcs_id is set tothe value of overlay changeset id, which can be passed toof_overlay_remove()to remove the overlay.

intof_overlay_remove(int*ovcs_id)

Revert and free an overlay changeset

Parameters

int*ovcs_id

Pointer to overlay changeset id

Description

Removes an overlay if it is permissible.ovcs_id was previously returnedbyof_overlay_fdt_apply().

If an error occurred while attempting to revert the overlay changeset,then an attempt is made to re-apply any changeset entry that wasreverted. If an error occurs on re-apply then the state of the devicetree can not be determined, and any following attempt to apply or removean overlay changeset will be refused.

A non-zero return value will not revert the changeset if error is from:
  • parameter checks

  • overlay changeset pre-remove notifier

  • overlay changeset entry revert

If an error is returned by an overlay changeset pre-remove notifierthen no further overlay changeset pre-remove notifier will be called.

If more than one notifier returns an error, then the last notifiererror to occur is returned.

A non-zero return value will revert the changeset if error is from:
  • overlay changeset entry notifier

  • overlay changeset post-remove notifier

If an error is returned by an overlay changeset post-remove notifierthen no further overlay changeset post-remove notifier will be called.

Return

0 on success, or a negative error number.*ovcs_id is set tozero after reverting the changeset, even if a subsequent error occurs.

intof_overlay_remove_all(void)

Reverts and frees all overlay changesets

Parameters

void

no arguments

Description

Removes all overlays from the system in the correct order.

Return

0 on success, or a negative error number