]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - lib/fdtdec.c
Merge branch 'master' of git://git.denx.de/u-boot-arm
[karo-tx-uboot.git] / lib / fdtdec.c
index da12df209c964a7202b8ddadbc22b5e4a1c843e1..6dba4389f23c231c9b9b34a330b7afeb753689b1 100644 (file)
@@ -43,6 +43,8 @@ static const char * const compat_names[COMPAT_COUNT] = {
        COMPAT(NVIDIA_TEGRA20_EMC_TABLE, "nvidia,tegra20-emc-table"),
        COMPAT(NVIDIA_TEGRA20_KBC, "nvidia,tegra20-kbc"),
        COMPAT(NVIDIA_TEGRA20_NAND, "nvidia,tegra20-nand"),
+       COMPAT(NVIDIA_TEGRA20_PWM, "nvidia,tegra20-pwm"),
+       COMPAT(NVIDIA_TEGRA20_DC, "nvidia,tegra20-dc"),
 };
 
 const char *fdtdec_get_compatible(enum fdt_compat_id id)
@@ -52,28 +54,6 @@ const char *fdtdec_get_compatible(enum fdt_compat_id id)
        return compat_names[id];
 }
 
-/**
- * Look in the FDT for an alias with the given name and return its node.
- *
- * @param blob FDT blob
- * @param name alias name to look up
- * @return node offset if found, or an error code < 0 otherwise
- */
-static int find_alias_node(const void *blob, const char *name)
-{
-       const char *path;
-       int alias_node;
-
-       debug("find_alias_node: %s\n", name);
-       alias_node = fdt_path_offset(blob, "/aliases");
-       if (alias_node < 0)
-               return alias_node;
-       path = fdt_getprop(blob, alias_node, name, NULL);
-       if (!path)
-               return -FDT_ERR_NOTFOUND;
-       return fdt_path_offset(blob, path);
-}
-
 fdt_addr_t fdtdec_get_addr(const void *blob, int node,
                const char *prop_name)
 {
@@ -111,6 +91,19 @@ s32 fdtdec_get_int(const void *blob, int node, const char *prop_name,
        return default_val;
 }
 
+uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name,
+               uint64_t default_val)
+{
+       const uint64_t *cell64;
+       int length;
+
+       cell64 = fdt_getprop(blob, node, prop_name, &length);
+       if (!cell64 || length < sizeof(*cell64))
+               return default_val;
+
+       return fdt64_to_cpu(*cell64);
+}
+
 int fdtdec_get_is_enabled(const void *blob, int node)
 {
        const char *cell;
@@ -171,7 +164,7 @@ int fdtdec_next_alias(const void *blob, const char *name,
        /* snprintf() is not available */
        assert(strlen(name) < MAX_STR_LEN);
        sprintf(str, "%.*s%d", MAX_STR_LEN, name, *upto);
-       node = find_alias_node(blob, str);
+       node = fdt_path_offset(blob, str);
        if (node < 0)
                return node;
        err = fdt_node_check_compatible(blob, node, compat_names[id]);
@@ -474,6 +467,26 @@ int fdtdec_decode_gpio(const void *blob, int node, const char *prop_name,
        return err == 1 ? 0 : err;
 }
 
+int fdtdec_get_gpio(struct fdt_gpio_state *gpio)
+{
+       int val;
+
+       if (!fdt_gpio_isvalid(gpio))
+               return -1;
+
+       val = gpio_get_value(gpio->gpio);
+       return gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val;
+}
+
+int fdtdec_set_gpio(struct fdt_gpio_state *gpio, int val)
+{
+       if (!fdt_gpio_isvalid(gpio))
+               return -1;
+
+       val = gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val;
+       return gpio_set_value(gpio->gpio, val);
+}
+
 int fdtdec_setup_gpio(struct fdt_gpio_state *gpio)
 {
        /*