From 174538845b1490d05a8c97c49088c54f4365551c Mon Sep 17 00:00:00 2001 From: Christoph Muellner Date: Tue, 12 Feb 2019 18:28:53 +0100 Subject: dm: pinctrl: Remove obsolete function pinctrl_decode_pin_config_dm(). This reverts commit 5ff776889212c080e3d1a33634ac904405ed6845. As noted in the comment, the function pinctrl_decode_pin_config_dm() only served as a temporary solution. Since the function has no users anymore, we can remove it again. Signed-off-by: Christoph Muellner Reviewed-by: Simon Glass --- include/dm/pinctrl.h | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'include') diff --git a/include/dm/pinctrl.h b/include/dm/pinctrl.h index ff2b82e7c2..63a7d55b88 100644 --- a/include/dm/pinctrl.h +++ b/include/dm/pinctrl.h @@ -354,18 +354,6 @@ int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph); */ int pinctrl_decode_pin_config(const void *blob, int node); -/** - * pinctrl_decode_pin_config_dm() - decode pin configuration flags - * - * This decodes some of the PIN_CONFIG values into flags, with each value - * being (1 << pin_cfg). This does not support things with values like the - * slew rate. - * - * @pinconfig: Pinconfig udevice - * @return decoded flag value, or -ve on error - */ -int pinctrl_decode_pin_config_dm(struct udevice *dev); - /** * pinctrl_get_gpio_mux() - get the mux value for a particular GPIO * -- cgit From c7fbee540e006b4cf6cda9272d0d5c9847b3db11 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 20 Mar 2019 18:21:26 +0100 Subject: dm: remove unused function dm_fdt_pre_reloc The function dm_ofnode_pre_reloc should be used instead of the function dm_fdt_pre_reloc and avoid duplicated code. Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- include/dm/util.h | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'include') diff --git a/include/dm/util.h b/include/dm/util.h index 9ff6531d1b..60d3b93dec 100644 --- a/include/dm/util.h +++ b/include/dm/util.h @@ -39,32 +39,6 @@ static inline void dm_dump_devres(void) } #endif -/** - * Check if a dt node should be or was bound before relocation. - * - * Devicetree nodes can be marked as needed to be bound - * in the loader stages via special devicetree properties. - * - * Before relocation this function can be used to check if nodes - * are required in either SPL or TPL stages. - * - * After relocation and jumping into the real U-Boot binary - * it is possible to determine if a node was bound in one of - * SPL/TPL stages. - * - * There are 3 settings currently in use - * - - * - u-boot,dm-pre-reloc: legacy and indicates any of TPL or SPL - * Existing platforms only use it to indicate nodes needed in - * SPL. Should probably be replaced by u-boot,dm-spl for - * existing platforms. - * @blob: devicetree - * @offset: node offset - * - * Returns true if node is needed in SPL/TL, false otherwise. - */ -bool dm_fdt_pre_reloc(const void *blob, int offset); - /** * Check if an of node should be or was bound before relocation. * -- cgit From 155d0a08fb9bf0ab39c3db8961bd618f49897630 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Thu, 21 Mar 2019 19:09:59 +0100 Subject: fdtdec: Add cpu_to_fdt_{addr, size}() macros These macros are useful for converting the endianness of variables of type fdt_addr_t and fdt_size_t. Reviewed-by: Simon Glass Signed-off-by: Thierry Reding --- include/fdtdec.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/fdtdec.h b/include/fdtdec.h index ad00f79f20..be34dca756 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -27,11 +27,15 @@ typedef phys_size_t fdt_size_t; #define FDT_ADDR_T_NONE (-1U) #define fdt_addr_to_cpu(reg) be64_to_cpu(reg) #define fdt_size_to_cpu(reg) be64_to_cpu(reg) +#define cpu_to_fdt_addr(reg) cpu_to_be64(reg) +#define cpu_to_fdt_size(reg) cpu_to_be64(reg) typedef fdt64_t fdt_val_t; #else #define FDT_ADDR_T_NONE (-1U) #define fdt_addr_to_cpu(reg) be32_to_cpu(reg) #define fdt_size_to_cpu(reg) be32_to_cpu(reg) +#define cpu_to_fdt_addr(reg) cpu_to_be32(reg) +#define cpu_to_fdt_size(reg) cpu_to_be32(reg) typedef fdt32_t fdt_val_t; #endif -- cgit From 4f253ad064689bc55eaba1c3e7d42f0f358a72c3 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Thu, 21 Mar 2019 19:10:00 +0100 Subject: fdtdec: Add fdt_{addr, size}_unpack() helpers These helpers can be used to unpack variables of type fdt_addr_t and fdt_size_t into a pair of 32-bit variables. This is useful in cases where such variables need to be written to properties (such as "reg") of a device tree node where they need to be split into cells. Signed-off-by: Thierry Reding --- include/fdtdec.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'include') diff --git a/include/fdtdec.h b/include/fdtdec.h index be34dca756..3f7538734a 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -23,6 +23,31 @@ */ typedef phys_addr_t fdt_addr_t; typedef phys_size_t fdt_size_t; + +static inline fdt32_t fdt_addr_unpack(fdt_addr_t addr, fdt32_t *upper) +{ + if (upper) +#ifdef CONFIG_PHYS_64BIT + *upper = addr >> 32; +#else + *upper = 0; +#endif + + return addr; +} + +static inline fdt32_t fdt_size_unpack(fdt_size_t size, fdt32_t *upper) +{ + if (upper) +#ifdef CONFIG_PHYS_64BIT + *upper = size >> 32; +#else + *upper = 0; +#endif + + return size; +} + #ifdef CONFIG_PHYS_64BIT #define FDT_ADDR_T_NONE (-1U) #define fdt_addr_to_cpu(reg) be64_to_cpu(reg) -- cgit From 8153d53b9340e652f78efbf99979d951ba853458 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Thu, 21 Mar 2019 19:10:01 +0100 Subject: fdtdec: Implement fdtdec_set_phandle() This function can be used to set a phandle for a given node. Signed-off-by: Thierry Reding --- include/fdtdec.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include') diff --git a/include/fdtdec.h b/include/fdtdec.h index 3f7538734a..ba7f873b89 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -1020,6 +1020,17 @@ int fdtdec_setup_memory_banksize_fdt(const void *blob); */ int fdtdec_setup_memory_banksize(void); +/** + * fdtdec_set_phandle() - sets the phandle of a given node + * + * @param blob FDT blob + * @param node offset in the FDT blob of the node whose phandle is to + * be set + * @param phandle phandle to set for the given node + * @return 0 on success or a negative error code on failure + */ +int fdtdec_set_phandle(void *blob, int node, uint32_t phandle); + /** * Set up the device tree ready for use */ -- cgit From c9222a08b3f7d1b0f7a72301db99dc54e09a3d10 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Thu, 21 Mar 2019 19:10:02 +0100 Subject: fdtdec: Implement fdtdec_add_reserved_memory() This function can be used to add subnodes in the /reserved-memory node. Reviewed-by: Simon Glass Signed-off-by: Thierry Reding --- include/fdtdec.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'include') diff --git a/include/fdtdec.h b/include/fdtdec.h index ba7f873b89..9bd6a70587 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -1031,6 +1031,54 @@ int fdtdec_setup_memory_banksize(void); */ int fdtdec_set_phandle(void *blob, int node, uint32_t phandle); +/** + * fdtdec_add_reserved_memory() - add or find a reserved-memory node + * + * If a reserved-memory node already exists for the given carveout, a phandle + * for that node will be returned. Otherwise a new node will be created and a + * phandle corresponding to it will be returned. + * + * See Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt + * for details on how to use reserved memory regions. + * + * As an example, consider the following code snippet: + * + * struct fdt_memory fb = { + * .start = 0x92cb3000, + * .end = 0x934b2fff, + * }; + * uint32_t phandle; + * + * fdtdec_add_reserved_memory(fdt, "framebuffer", &fb, &phandle); + * + * This results in the following subnode being added to the top-level + * /reserved-memory node: + * + * reserved-memory { + * #address-cells = <0x00000002>; + * #size-cells = <0x00000002>; + * ranges; + * + * framebuffer@92cb3000 { + * reg = <0x00000000 0x92cb3000 0x00000000 0x00800000>; + * phandle = <0x0000004d>; + * }; + * }; + * + * If the top-level /reserved-memory node does not exist, it will be created. + * The phandle returned from the function call can be used to reference this + * reserved memory region from other nodes. + * + * @param blob FDT blob + * @param basename base name of the node to create + * @param carveout information about the carveout region + * @param phandlep return location for the phandle of the carveout region + * @return 0 on success or a negative error code on failure + */ +int fdtdec_add_reserved_memory(void *blob, const char *basename, + const struct fdt_memory *carveout, + uint32_t *phandlep); + /** * Set up the device tree ready for use */ -- cgit From 16523ac79081b31741b7f72221a41e1197f051e7 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Thu, 21 Mar 2019 19:10:03 +0100 Subject: fdtdec: Implement carveout support functions The fdtdec_get_carveout() and fdtdec_set_carveout() function can be used to read a carveout from a given node or add a carveout to a given node using the standard device tree bindings (involving reserved-memory nodes and the memory-region property). Reviewed-by: Simon Glass Signed-off-by: Thierry Reding --- include/fdtdec.h | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'include') diff --git a/include/fdtdec.h b/include/fdtdec.h index 9bd6a70587..266c58271f 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -1069,6 +1069,8 @@ int fdtdec_set_phandle(void *blob, int node, uint32_t phandle); * The phandle returned from the function call can be used to reference this * reserved memory region from other nodes. * + * See fdtdec_set_carveout() for a more elaborate example. + * * @param blob FDT blob * @param basename base name of the node to create * @param carveout information about the carveout region @@ -1079,6 +1081,85 @@ int fdtdec_add_reserved_memory(void *blob, const char *basename, const struct fdt_memory *carveout, uint32_t *phandlep); +/** + * fdtdec_get_carveout() - reads a carveout from an FDT + * + * Reads information about a carveout region from an FDT. The carveout is a + * referenced by its phandle that is read from a given property in a given + * node. + * + * @param blob FDT blob + * @param node name of a node + * @param name name of the property in the given node that contains + * the phandle for the carveout + * @param index index of the phandle for which to read the carveout + * @param carveout return location for the carveout information + * @return 0 on success or a negative error code on failure + */ +int fdtdec_get_carveout(const void *blob, const char *node, const char *name, + unsigned int index, struct fdt_memory *carveout); + +/** + * fdtdec_set_carveout() - sets a carveout region for a given node + * + * Sets a carveout region for a given node. If a reserved-memory node already + * exists for the carveout, the phandle for that node will be reused. If no + * such node exists, a new one will be created and a phandle to it stored in + * a specified property of the given node. + * + * As an example, consider the following code snippet: + * + * const char *node = "/host1x@50000000/dc@54240000"; + * struct fdt_memory fb = { + * .start = 0x92cb3000, + * .end = 0x934b2fff, + * }; + * + * fdtdec_set_carveout(fdt, node, "memory-region", 0, "framebuffer", &fb); + * + * dc@54200000 is a display controller and was set up by the bootloader to + * scan out the framebuffer specified by "fb". This would cause the following + * reserved memory region to be added: + * + * reserved-memory { + * #address-cells = <0x00000002>; + * #size-cells = <0x00000002>; + * ranges; + * + * framebuffer@92cb3000 { + * reg = <0x00000000 0x92cb3000 0x00000000 0x00800000>; + * phandle = <0x0000004d>; + * }; + * }; + * + * A "memory-region" property will also be added to the node referenced by the + * offset parameter. + * + * host1x@50000000 { + * ... + * + * dc@54240000 { + * ... + * memory-region = <0x0000004d>; + * ... + * }; + * + * ... + * }; + * + * @param blob FDT blob + * @param node name of the node to add the carveout to + * @param prop_name name of the property in which to store the phandle of + * the carveout + * @param index index of the phandle to store + * @param name base name of the reserved-memory node to create + * @param carveout information about the carveout to add + * @return 0 on success or a negative error code on failure + */ +int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name, + unsigned int index, const char *name, + const struct fdt_memory *carveout); + /** * Set up the device tree ready for use */ -- cgit