aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of/base.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r--drivers/of/base.c451
1 files changed, 123 insertions, 328 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index b9864806e9b8..d8574adf0d62 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -17,6 +17,7 @@
17 * as published by the Free Software Foundation; either version 17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version. 18 * 2 of the License, or (at your option) any later version.
19 */ 19 */
20#include <linux/console.h>
20#include <linux/ctype.h> 21#include <linux/ctype.h>
21#include <linux/cpu.h> 22#include <linux/cpu.h>
22#include <linux/module.h> 23#include <linux/module.h>
@@ -35,15 +36,17 @@ struct device_node *of_allnodes;
35EXPORT_SYMBOL(of_allnodes); 36EXPORT_SYMBOL(of_allnodes);
36struct device_node *of_chosen; 37struct device_node *of_chosen;
37struct device_node *of_aliases; 38struct device_node *of_aliases;
38static struct device_node *of_stdout; 39struct device_node *of_stdout;
39 40
40static struct kset *of_kset; 41struct kset *of_kset;
41 42
42/* 43/*
43 * Used to protect the of_aliases; but also overloaded to hold off addition of 44 * Used to protect the of_aliases, to hold off addition of nodes to sysfs.
44 * nodes to sysfs 45 * This mutex must be held whenever modifications are being made to the
46 * device tree. The of_{attach,detach}_node() and
47 * of_{add,remove,update}_property() helpers make sure this happens.
45 */ 48 */
46DEFINE_MUTEX(of_aliases_mutex); 49DEFINE_MUTEX(of_mutex);
47 50
48/* use when traversing tree through the allnext, child, sibling, 51/* use when traversing tree through the allnext, child, sibling,
49 * or parent members of struct device_node. 52 * or parent members of struct device_node.
@@ -89,79 +92,7 @@ int __weak of_node_to_nid(struct device_node *np)
89} 92}
90#endif 93#endif
91 94
92#if defined(CONFIG_OF_DYNAMIC) 95#ifndef CONFIG_OF_DYNAMIC
93/**
94 * of_node_get - Increment refcount of a node
95 * @node: Node to inc refcount, NULL is supported to
96 * simplify writing of callers
97 *
98 * Returns node.
99 */
100struct device_node *of_node_get(struct device_node *node)
101{
102 if (node)
103 kobject_get(&node->kobj);
104 return node;
105}
106EXPORT_SYMBOL(of_node_get);
107
108static inline struct device_node *kobj_to_device_node(struct kobject *kobj)
109{
110 return container_of(kobj, struct device_node, kobj);
111}
112
113/**
114 * of_node_release - release a dynamically allocated node
115 * @kref: kref element of the node to be released
116 *
117 * In of_node_put() this function is passed to kref_put()
118 * as the destructor.
119 */
120static void of_node_release(struct kobject *kobj)
121{
122 struct device_node *node = kobj_to_device_node(kobj);
123 struct property *prop = node->properties;
124
125 /* We should never be releasing nodes that haven't been detached. */
126 if (!of_node_check_flag(node, OF_DETACHED)) {
127 pr_err("ERROR: Bad of_node_put() on %s\n", node->full_name);
128 dump_stack();
129 return;
130 }
131
132 if (!of_node_check_flag(node, OF_DYNAMIC))
133 return;
134
135 while (prop) {
136 struct property *next = prop->next;
137 kfree(prop->name);
138 kfree(prop->value);
139 kfree(prop);
140 prop = next;
141
142 if (!prop) {
143 prop = node->deadprops;
144 node->deadprops = NULL;
145 }
146 }
147 kfree(node->full_name);
148 kfree(node->data);
149 kfree(node);
150}
151
152/**
153 * of_node_put - Decrement refcount of a node
154 * @node: Node to dec refcount, NULL is supported to
155 * simplify writing of callers
156 *
157 */
158void of_node_put(struct device_node *node)
159{
160 if (node)
161 kobject_put(&node->kobj);
162}
163EXPORT_SYMBOL(of_node_put);
164#else
165static void of_node_release(struct kobject *kobj) 96static void of_node_release(struct kobject *kobj)
166{ 97{
167 /* Without CONFIG_OF_DYNAMIC, no nodes gets freed */ 98 /* Without CONFIG_OF_DYNAMIC, no nodes gets freed */
@@ -200,13 +131,16 @@ static const char *safe_name(struct kobject *kobj, const char *orig_name)
200 return name; 131 return name;
201} 132}
202 133
203static int __of_add_property_sysfs(struct device_node *np, struct property *pp) 134int __of_add_property_sysfs(struct device_node *np, struct property *pp)
204{ 135{
205 int rc; 136 int rc;
206 137
207 /* Important: Don't leak passwords */ 138 /* Important: Don't leak passwords */
208 bool secure = strncmp(pp->name, "security-", 9) == 0; 139 bool secure = strncmp(pp->name, "security-", 9) == 0;
209 140
141 if (!of_kset || !of_node_is_attached(np))
142 return 0;
143
210 sysfs_bin_attr_init(&pp->attr); 144 sysfs_bin_attr_init(&pp->attr);
211 pp->attr.attr.name = safe_name(&np->kobj, pp->name); 145 pp->attr.attr.name = safe_name(&np->kobj, pp->name);
212 pp->attr.attr.mode = secure ? S_IRUSR : S_IRUGO; 146 pp->attr.attr.mode = secure ? S_IRUSR : S_IRUGO;
@@ -218,12 +152,15 @@ static int __of_add_property_sysfs(struct device_node *np, struct property *pp)
218 return rc; 152 return rc;
219} 153}
220 154
221static int __of_node_add(struct device_node *np) 155int __of_attach_node_sysfs(struct device_node *np)
222{ 156{
223 const char *name; 157 const char *name;
224 struct property *pp; 158 struct property *pp;
225 int rc; 159 int rc;
226 160
161 if (!of_kset)
162 return 0;
163
227 np->kobj.kset = of_kset; 164 np->kobj.kset = of_kset;
228 if (!np->parent) { 165 if (!np->parent) {
229 /* Nodes without parents are new top level trees */ 166 /* Nodes without parents are new top level trees */
@@ -245,59 +182,20 @@ static int __of_node_add(struct device_node *np)
245 return 0; 182 return 0;
246} 183}
247 184
248int of_node_add(struct device_node *np)
249{
250 int rc = 0;
251
252 BUG_ON(!of_node_is_initialized(np));
253
254 /*
255 * Grab the mutex here so that in a race condition between of_init() and
256 * of_node_add(), node addition will still be consistent.
257 */
258 mutex_lock(&of_aliases_mutex);
259 if (of_kset)
260 rc = __of_node_add(np);
261 else
262 /* This scenario may be perfectly valid, but report it anyway */
263 pr_info("of_node_add(%s) before of_init()\n", np->full_name);
264 mutex_unlock(&of_aliases_mutex);
265 return rc;
266}
267
268#if defined(CONFIG_OF_DYNAMIC)
269static void of_node_remove(struct device_node *np)
270{
271 struct property *pp;
272
273 BUG_ON(!of_node_is_initialized(np));
274
275 /* only remove properties if on sysfs */
276 if (of_node_is_attached(np)) {
277 for_each_property_of_node(np, pp)
278 sysfs_remove_bin_file(&np->kobj, &pp->attr);
279 kobject_del(&np->kobj);
280 }
281
282 /* finally remove the kobj_init ref */
283 of_node_put(np);
284}
285#endif
286
287static int __init of_init(void) 185static int __init of_init(void)
288{ 186{
289 struct device_node *np; 187 struct device_node *np;
290 188
291 /* Create the kset, and register existing nodes */ 189 /* Create the kset, and register existing nodes */
292 mutex_lock(&of_aliases_mutex); 190 mutex_lock(&of_mutex);
293 of_kset = kset_create_and_add("devicetree", NULL, firmware_kobj); 191 of_kset = kset_create_and_add("devicetree", NULL, firmware_kobj);
294 if (!of_kset) { 192 if (!of_kset) {
295 mutex_unlock(&of_aliases_mutex); 193 mutex_unlock(&of_mutex);
296 return -ENOMEM; 194 return -ENOMEM;
297 } 195 }
298 for_each_of_allnodes(np) 196 for_each_of_allnodes(np)
299 __of_node_add(np); 197 __of_attach_node_sysfs(np);
300 mutex_unlock(&of_aliases_mutex); 198 mutex_unlock(&of_mutex);
301 199
302 /* Symlink in /proc as required by userspace ABI */ 200 /* Symlink in /proc as required by userspace ABI */
303 if (of_allnodes) 201 if (of_allnodes)
@@ -369,8 +267,8 @@ EXPORT_SYMBOL(of_find_all_nodes);
369 * Find a property with a given name for a given node 267 * Find a property with a given name for a given node
370 * and return the value. 268 * and return the value.
371 */ 269 */
372static const void *__of_get_property(const struct device_node *np, 270const void *__of_get_property(const struct device_node *np,
373 const char *name, int *lenp) 271 const char *name, int *lenp)
374{ 272{
375 struct property *pp = __of_find_property(np, name, lenp); 273 struct property *pp = __of_find_property(np, name, lenp);
376 274
@@ -1748,32 +1646,10 @@ int of_count_phandle_with_args(const struct device_node *np, const char *list_na
1748} 1646}
1749EXPORT_SYMBOL(of_count_phandle_with_args); 1647EXPORT_SYMBOL(of_count_phandle_with_args);
1750 1648
1751#if defined(CONFIG_OF_DYNAMIC)
1752static int of_property_notify(int action, struct device_node *np,
1753 struct property *prop)
1754{
1755 struct of_prop_reconfig pr;
1756
1757 /* only call notifiers if the node is attached */
1758 if (!of_node_is_attached(np))
1759 return 0;
1760
1761 pr.dn = np;
1762 pr.prop = prop;
1763 return of_reconfig_notify(action, &pr);
1764}
1765#else
1766static int of_property_notify(int action, struct device_node *np,
1767 struct property *prop)
1768{
1769 return 0;
1770}
1771#endif
1772
1773/** 1649/**
1774 * __of_add_property - Add a property to a node without lock operations 1650 * __of_add_property - Add a property to a node without lock operations
1775 */ 1651 */
1776static int __of_add_property(struct device_node *np, struct property *prop) 1652int __of_add_property(struct device_node *np, struct property *prop)
1777{ 1653{
1778 struct property **next; 1654 struct property **next;
1779 1655
@@ -1799,22 +1675,49 @@ int of_add_property(struct device_node *np, struct property *prop)
1799 unsigned long flags; 1675 unsigned long flags;
1800 int rc; 1676 int rc;
1801 1677
1802 rc = of_property_notify(OF_RECONFIG_ADD_PROPERTY, np, prop); 1678 mutex_lock(&of_mutex);
1803 if (rc)
1804 return rc;
1805 1679
1806 raw_spin_lock_irqsave(&devtree_lock, flags); 1680 raw_spin_lock_irqsave(&devtree_lock, flags);
1807 rc = __of_add_property(np, prop); 1681 rc = __of_add_property(np, prop);
1808 raw_spin_unlock_irqrestore(&devtree_lock, flags); 1682 raw_spin_unlock_irqrestore(&devtree_lock, flags);
1809 if (rc)
1810 return rc;
1811 1683
1812 if (of_node_is_attached(np)) 1684 if (!rc)
1813 __of_add_property_sysfs(np, prop); 1685 __of_add_property_sysfs(np, prop);
1814 1686
1687 mutex_unlock(&of_mutex);
1688
1689 if (!rc)
1690 of_property_notify(OF_RECONFIG_ADD_PROPERTY, np, prop, NULL);
1691
1815 return rc; 1692 return rc;
1816} 1693}
1817 1694
1695int __of_remove_property(struct device_node *np, struct property *prop)
1696{
1697 struct property **next;
1698
1699 for (next = &np->properties; *next; next = &(*next)->next) {
1700 if (*next == prop)
1701 break;
1702 }
1703 if (*next == NULL)
1704 return -ENODEV;
1705
1706 /* found the node */
1707 *next = prop->next;
1708 prop->next = np->deadprops;
1709 np->deadprops = prop;
1710
1711 return 0;
1712}
1713
1714void __of_remove_property_sysfs(struct device_node *np, struct property *prop)
1715{
1716 /* at early boot, bail here and defer setup to of_init() */
1717 if (of_kset && of_node_is_attached(np))
1718 sysfs_remove_bin_file(&np->kobj, &prop->attr);
1719}
1720
1818/** 1721/**
1819 * of_remove_property - Remove a property from a node. 1722 * of_remove_property - Remove a property from a node.
1820 * 1723 *
@@ -1825,211 +1728,98 @@ int of_add_property(struct device_node *np, struct property *prop)
1825 */ 1728 */
1826int of_remove_property(struct device_node *np, struct property *prop) 1729int of_remove_property(struct device_node *np, struct property *prop)
1827{ 1730{
1828 struct property **next;
1829 unsigned long flags; 1731 unsigned long flags;
1830 int found = 0;
1831 int rc; 1732 int rc;
1832 1733
1833 rc = of_property_notify(OF_RECONFIG_REMOVE_PROPERTY, np, prop); 1734 mutex_lock(&of_mutex);
1834 if (rc)
1835 return rc;
1836 1735
1837 raw_spin_lock_irqsave(&devtree_lock, flags); 1736 raw_spin_lock_irqsave(&devtree_lock, flags);
1838 next = &np->properties; 1737 rc = __of_remove_property(np, prop);
1839 while (*next) {
1840 if (*next == prop) {
1841 /* found the node */
1842 *next = prop->next;
1843 prop->next = np->deadprops;
1844 np->deadprops = prop;
1845 found = 1;
1846 break;
1847 }
1848 next = &(*next)->next;
1849 }
1850 raw_spin_unlock_irqrestore(&devtree_lock, flags); 1738 raw_spin_unlock_irqrestore(&devtree_lock, flags);
1851 1739
1852 if (!found) 1740 if (!rc)
1853 return -ENODEV; 1741 __of_remove_property_sysfs(np, prop);
1854 1742
1855 /* at early boot, bail hear and defer setup to of_init() */ 1743 mutex_unlock(&of_mutex);
1856 if (!of_kset)
1857 return 0;
1858 1744
1859 sysfs_remove_bin_file(&np->kobj, &prop->attr); 1745 if (!rc)
1746 of_property_notify(OF_RECONFIG_REMOVE_PROPERTY, np, prop, NULL);
1860 1747
1861 return 0; 1748 return rc;
1862} 1749}
1863 1750
1864/* 1751int __of_update_property(struct device_node *np, struct property *newprop,
1865 * of_update_property - Update a property in a node, if the property does 1752 struct property **oldpropp)
1866 * not exist, add it.
1867 *
1868 * Note that we don't actually remove it, since we have given out
1869 * who-knows-how-many pointers to the data using get-property.
1870 * Instead we just move the property to the "dead properties" list,
1871 * and add the new property to the property list
1872 */
1873int of_update_property(struct device_node *np, struct property *newprop)
1874{ 1753{
1875 struct property **next, *oldprop; 1754 struct property **next, *oldprop;
1876 unsigned long flags;
1877 int rc;
1878
1879 rc = of_property_notify(OF_RECONFIG_UPDATE_PROPERTY, np, newprop);
1880 if (rc)
1881 return rc;
1882 1755
1883 if (!newprop->name) 1756 for (next = &np->properties; *next; next = &(*next)->next) {
1884 return -EINVAL; 1757 if (of_prop_cmp((*next)->name, newprop->name) == 0)
1758 break;
1759 }
1760 *oldpropp = oldprop = *next;
1885 1761
1886 raw_spin_lock_irqsave(&devtree_lock, flags); 1762 if (oldprop) {
1887 next = &np->properties;
1888 oldprop = __of_find_property(np, newprop->name, NULL);
1889 if (!oldprop) {
1890 /* add the new node */
1891 rc = __of_add_property(np, newprop);
1892 } else while (*next) {
1893 /* replace the node */ 1763 /* replace the node */
1894 if (*next == oldprop) { 1764 newprop->next = oldprop->next;
1895 newprop->next = oldprop->next; 1765 *next = newprop;
1896 *next = newprop; 1766 oldprop->next = np->deadprops;
1897 oldprop->next = np->deadprops; 1767 np->deadprops = oldprop;
1898 np->deadprops = oldprop; 1768 } else {
1899 break; 1769 /* new node */
1900 } 1770 newprop->next = NULL;
1901 next = &(*next)->next; 1771 *next = newprop;
1902 } 1772 }
1903 raw_spin_unlock_irqrestore(&devtree_lock, flags);
1904 if (rc)
1905 return rc;
1906 1773
1774 return 0;
1775}
1776
1777void __of_update_property_sysfs(struct device_node *np, struct property *newprop,
1778 struct property *oldprop)
1779{
1907 /* At early boot, bail out and defer setup to of_init() */ 1780 /* At early boot, bail out and defer setup to of_init() */
1908 if (!of_kset) 1781 if (!of_kset)
1909 return 0; 1782 return;
1910 1783
1911 /* Update the sysfs attribute */
1912 if (oldprop) 1784 if (oldprop)
1913 sysfs_remove_bin_file(&np->kobj, &oldprop->attr); 1785 sysfs_remove_bin_file(&np->kobj, &oldprop->attr);
1914 __of_add_property_sysfs(np, newprop); 1786 __of_add_property_sysfs(np, newprop);
1915
1916 return 0;
1917} 1787}
1918 1788
1919#if defined(CONFIG_OF_DYNAMIC)
1920/* 1789/*
1921 * Support for dynamic device trees. 1790 * of_update_property - Update a property in a node, if the property does
1791 * not exist, add it.
1922 * 1792 *
1923 * On some platforms, the device tree can be manipulated at runtime. 1793 * Note that we don't actually remove it, since we have given out
1924 * The routines in this section support adding, removing and changing 1794 * who-knows-how-many pointers to the data using get-property.
1925 * device tree nodes. 1795 * Instead we just move the property to the "dead properties" list,
1926 */ 1796 * and add the new property to the property list
1927
1928static BLOCKING_NOTIFIER_HEAD(of_reconfig_chain);
1929
1930int of_reconfig_notifier_register(struct notifier_block *nb)
1931{
1932 return blocking_notifier_chain_register(&of_reconfig_chain, nb);
1933}
1934EXPORT_SYMBOL_GPL(of_reconfig_notifier_register);
1935
1936int of_reconfig_notifier_unregister(struct notifier_block *nb)
1937{
1938 return blocking_notifier_chain_unregister(&of_reconfig_chain, nb);
1939}
1940EXPORT_SYMBOL_GPL(of_reconfig_notifier_unregister);
1941
1942int of_reconfig_notify(unsigned long action, void *p)
1943{
1944 int rc;
1945
1946 rc = blocking_notifier_call_chain(&of_reconfig_chain, action, p);
1947 return notifier_to_errno(rc);
1948}
1949
1950/**
1951 * of_attach_node - Plug a device node into the tree and global list.
1952 */ 1797 */
1953int of_attach_node(struct device_node *np) 1798int of_update_property(struct device_node *np, struct property *newprop)
1954{ 1799{
1800 struct property *oldprop;
1955 unsigned long flags; 1801 unsigned long flags;
1956 int rc; 1802 int rc;
1957 1803
1958 rc = of_reconfig_notify(OF_RECONFIG_ATTACH_NODE, np); 1804 if (!newprop->name)
1959 if (rc) 1805 return -EINVAL;
1960 return rc;
1961
1962 raw_spin_lock_irqsave(&devtree_lock, flags);
1963 np->sibling = np->parent->child;
1964 np->allnext = np->parent->allnext;
1965 np->parent->allnext = np;
1966 np->parent->child = np;
1967 of_node_clear_flag(np, OF_DETACHED);
1968 raw_spin_unlock_irqrestore(&devtree_lock, flags);
1969
1970 of_node_add(np);
1971 return 0;
1972}
1973
1974/**
1975 * of_detach_node - "Unplug" a node from the device tree.
1976 *
1977 * The caller must hold a reference to the node. The memory associated with
1978 * the node is not freed until its refcount goes to zero.
1979 */
1980int of_detach_node(struct device_node *np)
1981{
1982 struct device_node *parent;
1983 unsigned long flags;
1984 int rc = 0;
1985 1806
1986 rc = of_reconfig_notify(OF_RECONFIG_DETACH_NODE, np); 1807 mutex_lock(&of_mutex);
1987 if (rc)
1988 return rc;
1989 1808
1990 raw_spin_lock_irqsave(&devtree_lock, flags); 1809 raw_spin_lock_irqsave(&devtree_lock, flags);
1810 rc = __of_update_property(np, newprop, &oldprop);
1811 raw_spin_unlock_irqrestore(&devtree_lock, flags);
1991 1812
1992 if (of_node_check_flag(np, OF_DETACHED)) { 1813 if (!rc)
1993 /* someone already detached it */ 1814 __of_update_property_sysfs(np, newprop, oldprop);
1994 raw_spin_unlock_irqrestore(&devtree_lock, flags);
1995 return rc;
1996 }
1997
1998 parent = np->parent;
1999 if (!parent) {
2000 raw_spin_unlock_irqrestore(&devtree_lock, flags);
2001 return rc;
2002 }
2003 1815
2004 if (of_allnodes == np) 1816 mutex_unlock(&of_mutex);
2005 of_allnodes = np->allnext;
2006 else {
2007 struct device_node *prev;
2008 for (prev = of_allnodes;
2009 prev->allnext != np;
2010 prev = prev->allnext)
2011 ;
2012 prev->allnext = np->allnext;
2013 }
2014 1817
2015 if (parent->child == np) 1818 if (!rc)
2016 parent->child = np->sibling; 1819 of_property_notify(OF_RECONFIG_UPDATE_PROPERTY, np, newprop, oldprop);
2017 else {
2018 struct device_node *prevsib;
2019 for (prevsib = np->parent->child;
2020 prevsib->sibling != np;
2021 prevsib = prevsib->sibling)
2022 ;
2023 prevsib->sibling = np->sibling;
2024 }
2025
2026 of_node_set_flag(np, OF_DETACHED);
2027 raw_spin_unlock_irqrestore(&devtree_lock, flags);
2028 1820
2029 of_node_remove(np);
2030 return rc; 1821 return rc;
2031} 1822}
2032#endif /* defined(CONFIG_OF_DYNAMIC) */
2033 1823
2034static void of_alias_add(struct alias_prop *ap, struct device_node *np, 1824static void of_alias_add(struct alias_prop *ap, struct device_node *np,
2035 int id, const char *stem, int stem_len) 1825 int id, const char *stem, int stem_len)
@@ -2062,9 +1852,12 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
2062 of_chosen = of_find_node_by_path("/chosen@0"); 1852 of_chosen = of_find_node_by_path("/chosen@0");
2063 1853
2064 if (of_chosen) { 1854 if (of_chosen) {
1855 /* linux,stdout-path and /aliases/stdout are for legacy compatibility */
2065 const char *name = of_get_property(of_chosen, "stdout-path", NULL); 1856 const char *name = of_get_property(of_chosen, "stdout-path", NULL);
2066 if (!name) 1857 if (!name)
2067 name = of_get_property(of_chosen, "linux,stdout-path", NULL); 1858 name = of_get_property(of_chosen, "linux,stdout-path", NULL);
1859 if (IS_ENABLED(CONFIG_PPC) && !name)
1860 name = of_get_property(of_aliases, "stdout", NULL);
2068 if (name) 1861 if (name)
2069 of_stdout = of_find_node_by_path(name); 1862 of_stdout = of_find_node_by_path(name);
2070 } 1863 }
@@ -2122,7 +1915,7 @@ int of_alias_get_id(struct device_node *np, const char *stem)
2122 struct alias_prop *app; 1915 struct alias_prop *app;
2123 int id = -ENODEV; 1916 int id = -ENODEV;
2124 1917
2125 mutex_lock(&of_aliases_mutex); 1918 mutex_lock(&of_mutex);
2126 list_for_each_entry(app, &aliases_lookup, link) { 1919 list_for_each_entry(app, &aliases_lookup, link) {
2127 if (strcmp(app->stem, stem) != 0) 1920 if (strcmp(app->stem, stem) != 0)
2128 continue; 1921 continue;
@@ -2132,7 +1925,7 @@ int of_alias_get_id(struct device_node *np, const char *stem)
2132 break; 1925 break;
2133 } 1926 }
2134 } 1927 }
2135 mutex_unlock(&of_aliases_mutex); 1928 mutex_unlock(&of_mutex);
2136 1929
2137 return id; 1930 return id;
2138} 1931}
@@ -2180,20 +1973,22 @@ const char *of_prop_next_string(struct property *prop, const char *cur)
2180EXPORT_SYMBOL_GPL(of_prop_next_string); 1973EXPORT_SYMBOL_GPL(of_prop_next_string);
2181 1974
2182/** 1975/**
2183 * of_device_is_stdout_path - check if a device node matches the 1976 * of_console_check() - Test and setup console for DT setup
2184 * linux,stdout-path property 1977 * @dn - Pointer to device node
2185 * 1978 * @name - Name to use for preferred console without index. ex. "ttyS"
2186 * Check if this device node matches the linux,stdout-path property 1979 * @index - Index to use for preferred console.
2187 * in the chosen node. return true if yes, false otherwise. 1980 *
1981 * Check if the given device node matches the stdout-path property in the
1982 * /chosen node. If it does then register it as the preferred console and return
1983 * TRUE. Otherwise return FALSE.
2188 */ 1984 */
2189int of_device_is_stdout_path(struct device_node *dn) 1985bool of_console_check(struct device_node *dn, char *name, int index)
2190{ 1986{
2191 if (!of_stdout) 1987 if (!dn || dn != of_stdout || console_set_on_cmdline)
2192 return false; 1988 return false;
2193 1989 return add_preferred_console(name, index, NULL);
2194 return of_stdout == dn;
2195} 1990}
2196EXPORT_SYMBOL_GPL(of_device_is_stdout_path); 1991EXPORT_SYMBOL_GPL(of_console_check);
2197 1992
2198/** 1993/**
2199 * of_find_next_cache_node - Find a node's subsidiary cache 1994 * of_find_next_cache_node - Find a node's subsidiary cache