From 09258f1e8b12acc4a2a02b60d942660798038fba Mon Sep 17 00:00:00 2001 From: Abhilash Kesavan Date: Thu, 25 Oct 2012 16:30:58 +0000 Subject: fdt: Add function to get config int from device tree Add a function to look up a configuration item such as machine id and return its value. Note: The code has been taken as is from the Chromium u-boot development tree and needs Simon Glass' sign-off. Signed-off-by: Abhilash Kesavan Signed-off-by: Simon Glass --- include/fdtdec.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'include/fdtdec.h') diff --git a/include/fdtdec.h b/include/fdtdec.h index 0b14075..d880fe8 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -354,6 +354,19 @@ int fdtdec_decode_gpio(const void *blob, int node, const char *prop_name, */ int fdtdec_setup_gpio(struct fdt_gpio_state *gpio); +/** + * Look in the FDT for a config item with the given name and return its value + * as a 32-bit integer. The property must have at least 4 bytes of data. The + * value of the first cell is returned. + * + * @param blob FDT blob to use + * @param prop_name Node property name + * @param default_val default value to return if the property is not found + * @return integer value, if found, or default_val if not + */ +int fdtdec_get_config_int(const void *blob, const char *prop_name, + int default_val); + /* * Look up a property in a node and return its contents in a byte * array of given length. The property must have at least enough data for -- cgit v1.1 From 332ab0d54aaa5b8b27096996d10c8c6183c6972c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 25 Oct 2012 16:30:59 +0000 Subject: fdt: Add function to get a config string from device tree Add a function to look up a configuration string such as board name and returns its value. We look in the "/config" node for this. Signed-off-by: Simon Glass --- include/fdtdec.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include/fdtdec.h') diff --git a/include/fdtdec.h b/include/fdtdec.h index d880fe8..e828662 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -367,6 +367,16 @@ int fdtdec_setup_gpio(struct fdt_gpio_state *gpio); int fdtdec_get_config_int(const void *blob, const char *prop_name, int default_val); +/** + * Look in the FDT for a config item with the given name and return its value + * as a string. + * + * @param blob FDT blob + * @param prop_name property name to look up + * @returns property string, NULL on error. + */ +char *fdtdec_get_config_string(const void *blob, const char *prop_name); + /* * Look up a property in a node and return its contents in a byte * array of given length. The property must have at least enough data for -- cgit v1.1 From f20c461984c3d986fde037d4c5bf600aa0497676 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 25 Oct 2012 16:31:00 +0000 Subject: fdt: Add fdtdec_decode_region() to decode memory region A memory region has a start and a size and is often specified in a node by a 'reg' property. Add a function to decode this information from the fdt. Signed-off-by: Simon Glass --- include/fdtdec.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include/fdtdec.h') diff --git a/include/fdtdec.h b/include/fdtdec.h index e828662..341e6a1 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -40,10 +40,12 @@ typedef u64 fdt_addr_t; #define FDT_ADDR_T_NONE (-1ULL) #define fdt_addr_to_cpu(reg) be64_to_cpu(reg) +#define fdt_size_to_cpu(reg) be64_to_cpu(reg) #else typedef u32 fdt_addr_t; #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) #endif /* Information obtained about memory from the FDT */ @@ -408,4 +410,21 @@ int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name, */ const u8 *fdtdec_locate_byte_array(const void *blob, int node, const char *prop_name, int count); + +/** + * Look up a property in a node which contains a memory region address and + * size. Then return a pointer to this address. + * + * The property must hold one address with a length. This is only tested on + * 32-bit machines. + * + * @param blob FDT blob + * @param node node to examine + * @param prop_name name of property to find + * @param ptrp returns pointer to region, or NULL if no address + * @param size returns size of region + * @return 0 if ok, -1 on error (propery not found) + */ +int fdtdec_decode_region(const void *blob, int node, + const char *prop_name, void **ptrp, size_t *size); #endif -- cgit v1.1 From 5921f6a2924827548caf55b28a6827b9d856e37f Mon Sep 17 00:00:00 2001 From: Abhilash Kesavan Date: Thu, 25 Oct 2012 16:31:01 +0000 Subject: fdt: Add function for decoding multiple gpios globally available Samsung's SDHCI bindings require multiple gpios to be parsed and configured at a time. Export the already available fdtdec_decode_gpios for this purpose. Signed-off-by: Abhilash Kesavan Commit-Ready: Che-Liang Chiou Signed-off-by: Simon Glass --- include/fdtdec.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'include/fdtdec.h') diff --git a/include/fdtdec.h b/include/fdtdec.h index 341e6a1..e70714b 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -345,6 +345,22 @@ int fdtdec_decode_gpio(const void *blob, int node, const char *prop_name, struct fdt_gpio_state *gpio); /** + * Decode a list of GPIOs from an FDT. This creates a list of GPIOs with no + * terminating item. + * + * @param blob FDT blob to use + * @param node Node to look at + * @param prop_name Node property name + * @param gpio Array of gpio elements to fill from FDT. This will be + * untouched if either 0 or an error is returned + * @param max_count Maximum number of elements allowed + * @return number of GPIOs read if ok, -FDT_ERR_BADLAYOUT if max_count would + * be exceeded, or -FDT_ERR_NOTFOUND if the property is missing. + */ +int fdtdec_decode_gpios(const void *blob, int node, const char *prop_name, + struct fdt_gpio_state *gpio, int max_count); + +/** * Set up a GPIO pin according to the provided gpio information. At present this * just requests the GPIO. * -- cgit v1.1 From 7cde397b21a347134a39c40e24355a0e438adae3 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Mon, 12 Nov 2012 23:13:54 -0500 Subject: fdt: Export fdtdec_lookup() and fix the name The name of this function is not consistent, so fix it, and export the function for external use. Signed-off-by: Simon Glass --- include/fdtdec.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'include/fdtdec.h') diff --git a/include/fdtdec.h b/include/fdtdec.h index e70714b..f8a4e94 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -110,6 +110,19 @@ int fdtdec_next_alias(const void *blob, const char *name, enum fdt_compat_id id, int *upto); /** + * Find the compatible ID for a given node. + * + * Generally each node has at least one compatible string attached to it. + * This function looks through our list of known compatible strings and + * returns the corresponding ID which matches the compatible string. + * + * @param blob FDT blob to use + * @param node Node containing compatible string to find + * @return compatible ID, or COMPAT_UNKNOWN if we cannot find a match + */ +enum fdt_compat_id fdtdec_lookup(const void *blob, int node); + +/** * Find the next compatible node for a peripheral. * * Do the first call with node = 0. This function will return a pointer to -- cgit v1.1 From 79289c0b5ff4a8c7869d7ca629cddc660dd06095 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 25 Oct 2012 16:31:04 +0000 Subject: fdt: Add function to read boolean property Signed-off-by: Vincent Palatin Commit-Ready: Vincent Palatin Commit-Ready: Gabe Black Signed-off-by: Simon Glass --- include/fdtdec.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include/fdtdec.h') diff --git a/include/fdtdec.h b/include/fdtdec.h index f8a4e94..a37cf54 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -399,6 +399,16 @@ int fdtdec_get_config_int(const void *blob, const char *prop_name, int default_val); /** + * Look in the FDT for a config item with the given name + * and return whether it exists. + * + * @param blob FDT blob + * @param prop_name property name to look up + * @return 1, if it exists, or 0 if not + */ +int fdtdec_get_config_bool(const void *blob, const char *prop_name); + +/** * Look in the FDT for a config item with the given name and return its value * as a string. * -- cgit v1.1 From aadef0a1bc3db81708471c9d18eb6c756659196f Mon Sep 17 00:00:00 2001 From: Che-Liang Chiou Date: Thu, 25 Oct 2012 16:31:05 +0000 Subject: fdt: Add fdtdec_get_uint64 to decode a 64-bit value from a property It decodes a 64-bit value from a property that is at least 8 bytes long. Signed-off-by: Che-Liang Chiou Signed-off-by: Simon Glass --- include/fdtdec.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include/fdtdec.h') diff --git a/include/fdtdec.h b/include/fdtdec.h index a37cf54..b5d7d2f 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -182,6 +182,21 @@ s32 fdtdec_get_int(const void *blob, int node, const char *prop_name, s32 default_val); /** + * Look up a 64-bit integer property in a node and return it. The property + * must have at least 8 bytes of data (2 cells). The first two cells are + * concatenated to form a 8 bytes value, where the first cell is top half and + * the second cell is bottom half. + * + * @param blob FDT blob + * @param node node to examine + * @param prop_name name of property to find + * @param default_val default value to return if the property is not found + * @return integer value, if found, or default_val if not + */ +uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name, + uint64_t default_val); + +/** * Checks whether a node is enabled. * This looks for a 'status' property. If this exists, then returns 1 if * the status is 'ok' and 0 otherwise. If there is no status property, -- cgit v1.1 From 202ff7537558edfd759b400cfe9e56c56fc7868c Mon Sep 17 00:00:00 2001 From: Sean Paul Date: Thu, 25 Oct 2012 16:31:06 +0000 Subject: fdt: Add polarity-aware gpio functions to fdtdec Add get and set gpio functions to fdtdec that take into account the polarity field in fdtdec_gpio_state.flags. Signed-off-by: Sean Paul Signed-off-by: Simon Glass --- include/fdtdec.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'include/fdtdec.h') diff --git a/include/fdtdec.h b/include/fdtdec.h index b5d7d2f..5164ce2 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -90,6 +90,22 @@ struct fdt_gpio_state { #define fdt_gpio_isvalid(x) ((x)->gpio != FDT_GPIO_NONE) /** + * Read the GPIO taking into account the polarity of the pin. + * + * @param gpio pointer to the decoded gpio + * @return value of the gpio if successful, < 0 if unsuccessful + */ +int fdtdec_get_gpio(struct fdt_gpio_state *gpio); + +/** + * Write the GPIO taking into account the polarity of the pin. + * + * @param gpio pointer to the decoded gpio + * @return 0 if successful + */ +int fdtdec_set_gpio(struct fdt_gpio_state *gpio, int val); + +/** * Find the next numbered alias for a peripheral. This is used to enumerate * all the peripherals of a certain type. * -- cgit v1.1