summaryrefslogtreecommitdiff
path: root/include/dm/ofnode.h
Commit message (Collapse)AuthorAgeFilesLines
* dm: core: Inline a few ofnode functions in SPLSimon Glass2020-12-221-11/+45
| | | | | | | | | | | | | | | | A recent change to unify the flattree/livetree code introduced a small size increase in SPL on some boards. For example SPL code size for px30-core-ctouch2-px30 increased by 40 bytes. To address this we can take advantage of the fact that some of the ofnode functions are only called a few times in SPL, so it is worth inlining them. Add new Kconfig options to control this. These functions are not inlined for U-Boot proper, since this increases code size. Fixes: 2ebea5eaebf ("dm: core: Combine the flattree and livetree binding code") Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: core: Add an ofnode function to get the devicetree rootSimon Glass2020-12-131-0/+12
| | | | | | | This is needed in at least one place. Avoid the conditional code in root.c by adding this inline function. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: core: Add a livetree function to check node statusSimon Glass2020-12-131-0/+11
| | | | | | | Add a way to find out if a node is enabled or not, based on its 'status' property. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: core: Add support for getting node from aliasesMichal Simek2020-10-271-0/+22
| | | | | | | | | Add support for getting a node/property from aliases. The similar functionality is provided for chosen node and this implemenatation is copy of it. Signed-off-by: Michal Simek <michal.simek@xilinx.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* dm: add cells_count parameter in *_count_phandle_with_argsPatrick Delaunay2020-10-061-1/+2
| | | | | | | | | | | | | | | | | | | The cell_count argument is required when cells_name is NULL. This patch adds this parameter in live tree API - of_count_phandle_with_args - ofnode_count_phandle_with_args - dev_count_phandle_with_args This parameter solves issue when these API is used to count the number of element of a cell without cell name. This parameter allow to force the size cell. For example: count = dev_count_phandle_with_args(dev, "array", NULL, 3); Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* dm: update test on of_offset in ofnode_validPatrick Delaunay2020-10-061-1/+1
| | | | | | | | | | | | | | | | Update the test for node.of_offset because an invalid offset is not always set to -1 because the return value of the libfdt functions are: + an error with a value < 0 + a valid offset with value >=0 For example, in ofnode_get_by_phandle() function, we have: node.of_offset = fdt_node_offset_by_phandle(gd->fdt_blob, phandle); and this function can return -FDT_ERR_BADPHANDLE (-6). Without this patch, the added test dm_test_ofnode_get_by_phandle failed. Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* dm: ofnode: Fix compile breakage with OF_CHECKS enabledStefan Roese2020-10-061-3/+4
| | | | | | | | | Include missing log.h and change _ofnode_to_np() to ofnode_to_np() so that compiling with OF_CHECKS enabled does not break. Signed-off-by: Stefan Roese <sr@denx.de> Cc: Simon Glass <sjg@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
* dm: remove superfluous comment for union ofnode_unionHeinrich Schuchardt2020-07-281-1/+1
| | | | | | "future live tree" does not make sense anymore as we have CONFIG_OF_LIVE. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* dm: core: Add function to get child count of ofnode or deviceChunfeng Yun2020-05-021-0/+8
| | | | | | | | | | This patch add function used to get the child count of a ofnode or a device Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com> Signed-off-by: Frank Wunderlich <frank-w@public-files.de> Reviewed-by: Weijie Gao <weijie.gao@mediatek.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* dm: core: add ofnode and dev function to iterate on node propertyPatrick Delaunay2020-04-161-1/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add functions to iterate on all property with livetree - dev_read_first_prop - dev_read_next_prop - dev_read_prop_by_prop and - ofnode_get_first_property - ofnode_get_next_property - ofnode_get_property_by_prop And helper: dev_for_each_property For example: struct ofprop property; dev_for_each_property(property, config) { value = dev_read_prop_by_prop(&property, &propname, &len); or: for (res = ofnode_get_first_property(node, &property); !res; res = ofnode_get_next_property(&property)) { value = ofnode_get_property_by_prop(&property, &propname, &len); .... } Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* dm: core: support reading a single indexed u32 valueDario Binacchi2020-04-161-0/+25
| | | | | | | | | The patch adds helper functions to allow reading a single indexed u32 value from a device-tree property containing multiple u32 values, that is an array of integers. Signed-off-by: Dario Binacchi <dariobin@libero.it> Reviewed-by: Simon Glass <sjg@chromium.org>
* dm: core: Add ofnode_get_chosen_prop()Simon Glass2020-02-051-0/+12
| | | | | | | Add a function to read a property from the chosen node, providing access to its length. Update ofnode_get_chosen_string() to make use of it. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: core: Add ofnode_read_prop()Simon Glass2020-02-051-1/+12
| | | | | | | | | Add a new function to read a property that supports reading the length as well. Reimplement ofnode_read_string() using it and fix its comment. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: core: Rename ofnode_get_chosen_prop()Simon Glass2020-02-051-4/+5
| | | | | | | | | | | | | This function is actually intended to read a string rather than a property. All of its current callers use it that way. Also there is no way to return the length of the property from this function. Rename it to better indicate its purpose, using ofnode_read as the prefix since this matches most other functions. Also add some tests which are missing for these functions. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: core: Update comment for ofnode_get_chosen_node()Simon Glass2020-02-051-3/+6
| | | | | | | The current comment is a big vague and misleading. Rewrite it to state precisely what the function does. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: core: Fix offset_to_ofnode() with invalid offsetSimon Glass2019-12-151-1/+1
| | | | | | | | | | | | | | | | If the offset is -1 this function correctly sets up a null ofnode. But if the offset is any other negative number (e.g. -FDT_ERR_BADPATH) then it does the wrong thing. An offset of -1 in ofnode indicates that the ofnode is not valid. Any other negative value is not handled by ofnode_valid(). We could of course change that function, but it seems much better to always use the same value for an invalid node. Fix it by setting the offset to -1 if it is invalid for any reason. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
* dm: core: Add functions to read 64-bit dt propertiesT Karthik Reddy2019-09-061-1/+1
| | | | | | | | | This patch adds functions dev_read_u64_default & dev_read_u64 to read unsigned 64-bit values from devicetree. Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com> Signed-off-by: Michal Simek <michal.simek@xilinx.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
* dm: core: Introduce xxx_translate_dma_address()Fabien Dessenne2019-07-221-1/+15
| | | | | | | | | | | | | | | | | | | Add the following functions to translate DMA address to CPU address: - dev_translate_dma_address() - ofnode_translate_dma_address() - of_translate_dma_address() - fdt_translate_dma_address() These functions work the same way as xxx_translate_address(), with the difference that the translation relies on the "dma-ranges" property instead of the "ranges" property. Add related test. Test report: => ut dm fdt_translation Test: dm_test_fdt_translation: test-fdt.c Test: dm_test_fdt_translation: test-fdt.c (flat tree) Failures: 0 Signed-off-by: Fabien Dessenne <fabien.dessenne@st.com>
* dm: doc: add documentation for pre-reloc properties in SPL and TPLPatrick Delaunay2019-07-101-2/+4
| | | | | | | | | | | Add documentation for the pre-reloc property in SPL and TPL device-tree: - u-boot,dm-pre-proper - u-boot,dm-pre-reloc - u-boot,dm-spl - u-boot,dm-tpl Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* core: ofnode: Have ofnode_read_u32_default return a u32Trent Piepho2019-05-211-1/+1
| | | | | | | | | | | | | It was returning an int, which doesn't work if the u32 it is reading, or the default value, will overflow a signed int. While it could be made to work, when using a C standard/compiler where casting negative signed values to unsigned has a defined behavior, combined with careful casting, it seems obvious one is meant to use ofnode_read_s32_default() with signed values. Cc: Simon Glass <sjg@chromium.org> Signed-off-by: Trent Piepho <tpiepho@impinj.com>
* core: ofnode: Add ofnode_get_addr_size_indexKeerthy2019-05-211-0/+14
| | | | | | | | Add ofnode_get_addr_size_index function to fetch the address and size of the reg space based on index. Signed-off-by: Keerthy <j-keerthy@ti.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* ofnode: fix comment typoBaruch Siach2018-11-291-1/+1
| | | | Signed-off-by: Baruch Siach <baruch@tkos.co.il>
* dm: core: add missing prototype for ofnode_read_u64Lukas Auer2018-11-261-0/+10
| | | | | | Signed-off-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* core: Add functions to set properties in live-treeMario Six2018-09-291-0/+46
| | | | | | | | | | | | Implement a set of functions to manipulate properties in a live device tree: * ofnode_write_prop() to set generic properties of a node * ofnode_write_string() to set string properties of a node * ofnode_set_enabled() to either enable or disable a node Signed-off-by: Mario Six <mario.six@gdsys.cc> Reviewed-by: Simon Glass <sjg@chromium.org>
* ofnode: add ofnode_by_prop_value()Jens Wiklander2018-09-181-0/+14
| | | | | | | | Adds ofnode_by_prop_value() to search for nodes with a given property and value, an ofnode version of fdt_node_offset_by_prop_value(). Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Simon Glass <sjg@chromium.org>
* dm: core: Add ofnode function to read PCI vendor and device idBin Meng2018-08-081-0/+13
| | | | | | | | We don't have the live-tree version of fdtdec_get_pci_vendev(). This adds the API. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* dm: core: Add a way to find an ofnode by compatible stringSimon Glass2018-07-091-0/+11
| | | | | | | Add an ofnode_by_compatible() to allow iterating through ofnodes with a given compatible string. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: core: Add comments to ofnode_read_resource() functoinsSimon Glass2018-07-091-0/+23
| | | | | | These functions are missing comments. Add some. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: core: Fix a few ofnode function commentsSimon Glass2018-07-091-1/+3
| | | | | | Tidy up three return-value errors. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: core: Add ofnode function to read a 64-bit intSimon Glass2018-07-091-0/+10
| | | | | | | We have a 32-bit version of this function. Add a 64-bit version as well so we can easily read 64-bit ints from the device tree. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: ofnode: add ofnode_device_is_compatible() helperMasahiro Yamada2018-05-071-0/+11
| | | | | | | | device_is_compatible() takes udevice, but there is no such a helper that takes ofnode. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* SPDX: Convert all of our single license tags to Linux Kernel styleTom Rini2018-05-071-2/+1
| | | | | | | | | | | | | | | | | | | | When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <trini@konsulko.com>
* core: add ofnode_get_by_phandle() apiKever Yang2018-02-231-0/+8
| | | | | | | | | | | We need to get ofnode from a phandle, add interface to support both live dt and fdt. Signed-off-by: Kever Yang <kever.yang@rock-chips.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com> Tested-by: Klaus Goger <klaus.goger@theobroma-systems.com> Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
* core: ofnode: add ofnode_get_parent functionPhilipp Tomsich2018-02-231-0/+8
| | | | | | | | | | The Rockchip video drivers need to walk the ofnode-parrents to find an enclosing device that has a UCLASS_DISPLAY driver bound. This adds a ofnode_get_parent()-function that returns the parent-node. Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com> Tested-by: Klaus Goger <klaus.goger@theobroma-systems.com> Reviewed-by: Anatolij Gustschin <agust@denx.de>
* core: Add {ofnode, dev}_translate_address functionsMario Six2018-01-211-0/+13
| | | | | Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Mario Six <mario.six@gdsys.cc>
* dm: core: fix member name in ofnode_union documentationBaruch Siach2017-11-171-1/+1
| | | | | | | Fixes: 4984de2baaa ("dm: core: Add ofnode to represent device tree nodes") Cc: Simon Glass <sjg@chromium.org> Signed-off-by: Baruch Siach <baruch@tkos.co.il> Reviewed-by: Simon Glass <sjg@chromium.org>
* dm: core: Add ofnode_for_each_subnode()Simon Glass2017-09-111-0/+24
| | | | | | | Add a convenience macro to iterate over subnodes of a node. Make use of this where appropriate in the code. Signed-off-by: Simon Glass <sjg@chromium.org>
* ofnode: add {ofnode, dev}_read_resource_byname()Masahiro Yamada2017-08-291-0/+2
| | | | | | | | | | | Linux supports platform_get_resource_byname() to look up a resource by name. We want a similar helper. It is useful when a device node has named register regions. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* Merge git://git.denx.de/u-boot-usbTom Rini2017-07-291-0/+17
|\
| * dm: core: add ofnode_count_phandle_with_args()Patrice Chotard2017-07-281-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. To implement it, either of_count_phandle_with_args() or fdtdec_parse_phandle_with_args() are used respectively for live tree and flat tree. By passing index = -1, these 2 functions returns the number of phandle contained into the property list. Add also the dev_count_phandle_with_args() based on ofnode_count_phandle_with_args() Signed-off-by: Patrice Chotard <patrice.chotard@st.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* | dm: core: Add ofnode_read_resource()Simon Glass2017-07-281-0/+4
|/ | | | | | | | | | | We sometimes need to read a resource from an arbitrary node. In any case for consistency we should not put the live-tree switching code in a dev_read_...() function. Update this to suit. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Marcel Ziswiler <marcel.ziswiler@toradex.com> Tested-on: Beaver, Jetson-TK1 Tested-by: Stephen Warren <swarren@nvidia.com>
* dm: ofnode: rename ofnode_read_prop() to ofnode_get_property()Masahiro Yamada2017-07-111-2/+2
| | | | | | | | | | | | | This function returns the pointer to the value of a node property. The current name ofnode_read_prop() is confusing. Follow the naming of_get_property() from Linux. The return type (const u32 *) is wrong. DT property values can be strings as well as integers. This is why of_get_property/fdt_getprop returns an opaque pointer. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Acked-by: Simon Glass <sjg@chromium.org>
* dm: core: Add functions to obtain node's address/size cellsSimon Glass2017-07-111-0/+20
| | | | | | | | | | | | | | | | The of_n_addr_cells() and of_n_size_cells() functions are useful for getting the size of addresses in a node, but in a few places U-Boot needs to obtain the actual property value for a node without walking up the stack. Add functions for this and just the existing code to use it. Add a comment to the existing ofnode functions which do not do the right thing with a flat tree. This fixes a problem reading PCI addresses. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Marcel Ziswiler <marcel.ziswiler@toradex.com> Tested-on: Beaver, Jetson-TK1
* dm: core: Add ofnode_read_string_count()Simon Glass2017-07-111-1/+11
| | | | | | | | | This provides a way to find the number of strings in a string list. Add it and also fix up the comment for ofnode_read_string_index(). Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Marcel Ziswiler <marcel.ziswiler@toradex.com> Tested-on: Beaver, Jetson-TK1
* dm: core: Add address operations on device tree referencesSimon Glass2017-06-011-1/+22
| | | | | | Add functions to add addresses in the device tree using ofnode references. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: core: Add operations on device tree referencesSimon Glass2017-06-011-3/+464
| | | | | | | | | | | | | | | | | | | | | | | Since U-Boot supports both a live tree and a flat tree, we need an easy way to access the tree without worrying about which is currently active. To support this, U-Boot has the concept of an ofnode, which can refer either to a live tree node or a flat tree node. For the live tree, the reference contains a pointer to the node (struct device_node *) or NULL if the node is invalid. For the flat tree, the reference contains the node offset or -1 if the node is invalid. Add a basic set of operations using ofnodes. These are implemented by using either libfdt functions (in the case of a flat DT reference) or the live-tree of_...() functions. Note that it is not possible to have both live and flat references active at the same time. As soon as the live tree is available, everything in U-Boot should switch to using that. This avoids confusion and allows us to assume that the type of a reference is simply based on whether we have a live tree yet, or not. Signed-off-by: Simon Glass <sjg@chromium.org>
* dm: core: Add ofnode to represent device tree nodesSimon Glass2017-06-011-0/+96
With live tree we need a struct device_node * to reference a node. With the existing flat tree, we need an int offset. We need to unify these into a single value which can represent both. Add an ofnode union for this and adjust existing code to move to this. Signed-off-by: Simon Glass <sjg@chromium.org>