X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=drivers%2Fof%2Fbase.c;h=99764db0875aa0e1b34ca348ca1606c2a8990258;hb=d56a669ca59c37ed0a7282a251b2f2f22533343a;hp=adb8764861c02893d1e965bf077c0c9706abdadb;hpb=6b7acae74fc2ffe6cfd7592e95ca933cadb31219;p=firefly-linux-kernel-4.4.55.git diff --git a/drivers/of/base.c b/drivers/of/base.c index adb8764861c0..99764db0875a 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -567,6 +567,29 @@ bool of_device_is_available(const struct device_node *device) } EXPORT_SYMBOL(of_device_is_available); +/** + * of_device_is_big_endian - check if a device has BE registers + * + * @device: Node to check for endianness + * + * Returns true if the device has a "big-endian" property, or if the kernel + * was compiled for BE *and* the device has a "native-endian" property. + * Returns false otherwise. + * + * Callers would nominally use ioread32be/iowrite32be if + * of_device_is_big_endian() == true, or readl/writel otherwise. + */ +bool of_device_is_big_endian(const struct device_node *device) +{ + if (of_property_read_bool(device, "big-endian")) + return true; + if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) && + of_property_read_bool(device, "native-endian")) + return true; + return false; +} +EXPORT_SYMBOL(of_device_is_big_endian); + /** * of_get_parent - Get a node's parent if any * @node: Node to get parent @@ -640,8 +663,9 @@ static struct device_node *__of_get_next_child(const struct device_node *node, * @node: parent node * @prev: previous child of the parent node, or NULL to get first * - * Returns a node pointer with refcount incremented, use - * of_node_put() on it when done. + * Returns a node pointer with refcount incremented, use of_node_put() on + * it when done. Returns NULL when prev is the last child. Decrements the + * refcount of prev. */ struct device_node *of_get_next_child(const struct device_node *node, struct device_node *prev) @@ -715,13 +739,8 @@ static struct device_node *__of_find_node_by_path(struct device_node *parent, { struct device_node *child; int len; - const char *end; - - end = strchr(path, ':'); - if (!end) - end = strchrnul(path, '/'); - len = end - path; + len = strcspn(path, "/:"); if (!len) return NULL; @@ -1893,10 +1912,8 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)) name = of_get_property(of_chosen, "linux,stdout-path", NULL); if (IS_ENABLED(CONFIG_PPC) && !name) name = of_get_property(of_aliases, "stdout", NULL); - if (name) { + if (name) of_stdout = of_find_node_opts_by_path(name, &of_stdout_options); - add_preferred_console("stdout-path", 0, NULL); - } } if (!of_aliases) @@ -1967,6 +1984,32 @@ int of_alias_get_id(struct device_node *np, const char *stem) } EXPORT_SYMBOL_GPL(of_alias_get_id); +/** + * of_alias_get_highest_id - Get highest alias id for the given stem + * @stem: Alias stem to be examined + * + * The function travels the lookup table to get the highest alias id for the + * given alias stem. It returns the alias id if found. + */ +int of_alias_get_highest_id(const char *stem) +{ + struct alias_prop *app; + int id = -ENODEV; + + mutex_lock(&of_mutex); + list_for_each_entry(app, &aliases_lookup, link) { + if (strcmp(app->stem, stem) != 0) + continue; + + if (app->id > id) + id = app->id; + } + mutex_unlock(&of_mutex); + + return id; +} +EXPORT_SYMBOL_GPL(of_alias_get_highest_id); + const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur, u32 *pu) { @@ -2089,14 +2132,45 @@ int of_graph_parse_endpoint(const struct device_node *node, } EXPORT_SYMBOL(of_graph_parse_endpoint); +/** + * of_graph_get_port_by_id() - get the port matching a given id + * @parent: pointer to the parent device node + * @id: id of the port + * + * Return: A 'port' node pointer with refcount incremented. The caller + * has to use of_node_put() on it when done. + */ +struct device_node *of_graph_get_port_by_id(struct device_node *parent, u32 id) +{ + struct device_node *node, *port; + + node = of_get_child_by_name(parent, "ports"); + if (node) + parent = node; + + for_each_child_of_node(parent, port) { + u32 port_id = 0; + + if (of_node_cmp(port->name, "port") != 0) + continue; + of_property_read_u32(port, "reg", &port_id); + if (id == port_id) + break; + } + + of_node_put(node); + + return port; +} +EXPORT_SYMBOL(of_graph_get_port_by_id); + /** * of_graph_get_next_endpoint() - get next endpoint node * @parent: pointer to the parent device node * @prev: previous endpoint node, or NULL to get first * * Return: An 'endpoint' node pointer with refcount incremented. Refcount - * of the passed @prev node is not decremented, the caller have to use - * of_node_put() on it when done. + * of the passed @prev node is decremented. */ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent, struct device_node *prev) @@ -2132,12 +2206,6 @@ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent, if (WARN_ONCE(!port, "%s(): endpoint %s has no parent node\n", __func__, prev->full_name)) return NULL; - - /* - * Avoid dropping prev node refcount to 0 when getting the next - * child below. - */ - of_node_get(prev); } while (1) {