aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/Kconfig9
-rw-r--r--drivers/of/Makefile1
-rw-r--r--drivers/of/base.c40
-rw-r--r--drivers/of/device.c30
-rw-r--r--drivers/of/of_mtd.c85
-rw-r--r--drivers/of/platform.c6
-rw-r--r--drivers/of/selftest.c29
7 files changed, 179 insertions, 21 deletions
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 268163dd71c7..8e84ce9765a9 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -35,9 +35,10 @@ config OF_EARLY_FLATTREE
35config OF_PROMTREE 35config OF_PROMTREE
36 bool 36 bool
37 37
38# Hardly any platforms need this. It is safe to select, but only do so if you
39# need it.
38config OF_DYNAMIC 40config OF_DYNAMIC
39 def_bool y 41 bool
40 depends on PPC_OF
41 42
42config OF_ADDRESS 43config OF_ADDRESS
43 def_bool y 44 def_bool y
@@ -90,4 +91,8 @@ config OF_PCI_IRQ
90 help 91 help
91 OpenFirmware PCI IRQ routing helpers 92 OpenFirmware PCI IRQ routing helpers
92 93
94config OF_MTD
95 depends on MTD
96 def_bool y
97
93endmenu # OF 98endmenu # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index a73f5a51ff4c..aa90e602c8a7 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -12,3 +12,4 @@ obj-$(CONFIG_OF_SELFTEST) += selftest.o
12obj-$(CONFIG_OF_MDIO) += of_mdio.o 12obj-$(CONFIG_OF_MDIO) += of_mdio.o
13obj-$(CONFIG_OF_PCI) += of_pci.o 13obj-$(CONFIG_OF_PCI) += of_pci.o
14obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o 14obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o
15obj-$(CONFIG_OF_MTD) += of_mtd.o
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 133908a6fd8d..580644986945 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -88,7 +88,7 @@ int of_n_size_cells(struct device_node *np)
88} 88}
89EXPORT_SYMBOL(of_n_size_cells); 89EXPORT_SYMBOL(of_n_size_cells);
90 90
91#if !defined(CONFIG_SPARC) /* SPARC doesn't do ref counting (yet) */ 91#if defined(CONFIG_OF_DYNAMIC)
92/** 92/**
93 * of_node_get - Increment refcount of a node 93 * of_node_get - Increment refcount of a node
94 * @node: Node to inc refcount, NULL is supported to 94 * @node: Node to inc refcount, NULL is supported to
@@ -161,7 +161,7 @@ void of_node_put(struct device_node *node)
161 kref_put(&node->kref, of_node_release); 161 kref_put(&node->kref, of_node_release);
162} 162}
163EXPORT_SYMBOL(of_node_put); 163EXPORT_SYMBOL(of_node_put);
164#endif /* !CONFIG_SPARC */ 164#endif /* CONFIG_OF_DYNAMIC */
165 165
166struct property *of_find_property(const struct device_node *np, 166struct property *of_find_property(const struct device_node *np,
167 const char *name, 167 const char *name,
@@ -761,6 +761,42 @@ int of_property_read_string_index(struct device_node *np, const char *propname,
761} 761}
762EXPORT_SYMBOL_GPL(of_property_read_string_index); 762EXPORT_SYMBOL_GPL(of_property_read_string_index);
763 763
764/**
765 * of_property_match_string() - Find string in a list and return index
766 * @np: pointer to node containing string list property
767 * @propname: string list property name
768 * @string: pointer to string to search for in string list
769 *
770 * This function searches a string list property and returns the index
771 * of a specific string value.
772 */
773int of_property_match_string(struct device_node *np, const char *propname,
774 const char *string)
775{
776 struct property *prop = of_find_property(np, propname, NULL);
777 size_t l;
778 int i;
779 const char *p, *end;
780
781 if (!prop)
782 return -EINVAL;
783 if (!prop->value)
784 return -ENODATA;
785
786 p = prop->value;
787 end = p + prop->length;
788
789 for (i = 0; p < end; i++, p += l) {
790 l = strlen(p) + 1;
791 if (p + l > end)
792 return -EILSEQ;
793 pr_debug("comparing %s with %s\n", string, p);
794 if (strcmp(string, p) == 0)
795 return i; /* Found it; return index */
796 }
797 return -ENODATA;
798}
799EXPORT_SYMBOL_GPL(of_property_match_string);
764 800
765/** 801/**
766 * of_property_count_strings - Find and return the number of strings from a 802 * of_property_count_strings - Find and return the number of strings from a
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 62b4b32ac887..4c74e4fc5a51 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -128,39 +128,41 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
128/** 128/**
129 * of_device_uevent - Display OF related uevent information 129 * of_device_uevent - Display OF related uevent information
130 */ 130 */
131int of_device_uevent(struct device *dev, struct kobj_uevent_env *env) 131void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
132{ 132{
133 const char *compat; 133 const char *compat;
134 int seen = 0, cplen, sl; 134 int seen = 0, cplen, sl;
135 135
136 if ((!dev) || (!dev->of_node)) 136 if ((!dev) || (!dev->of_node))
137 return -ENODEV; 137 return;
138
139 if (add_uevent_var(env, "OF_NAME=%s", dev->of_node->name))
140 return -ENOMEM;
141 138
142 if (add_uevent_var(env, "OF_TYPE=%s", dev->of_node->type)) 139 add_uevent_var(env, "OF_NAME=%s", dev->of_node->name);
143 return -ENOMEM; 140 add_uevent_var(env, "OF_FULLNAME=%s", dev->of_node->full_name);
141 if (dev->of_node->type && strcmp("<NULL>", dev->of_node->type) != 0)
142 add_uevent_var(env, "OF_TYPE=%s", dev->of_node->type);
144 143
145 /* Since the compatible field can contain pretty much anything 144 /* Since the compatible field can contain pretty much anything
146 * it's not really legal to split it out with commas. We split it 145 * it's not really legal to split it out with commas. We split it
147 * up using a number of environment variables instead. */ 146 * up using a number of environment variables instead. */
148
149 compat = of_get_property(dev->of_node, "compatible", &cplen); 147 compat = of_get_property(dev->of_node, "compatible", &cplen);
150 while (compat && *compat && cplen > 0) { 148 while (compat && *compat && cplen > 0) {
151 if (add_uevent_var(env, "OF_COMPATIBLE_%d=%s", seen, compat)) 149 add_uevent_var(env, "OF_COMPATIBLE_%d=%s", seen, compat);
152 return -ENOMEM;
153
154 sl = strlen(compat) + 1; 150 sl = strlen(compat) + 1;
155 compat += sl; 151 compat += sl;
156 cplen -= sl; 152 cplen -= sl;
157 seen++; 153 seen++;
158 } 154 }
155 add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen);
156}
159 157
160 if (add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen)) 158int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
161 return -ENOMEM; 159{
160 int sl;
161
162 if ((!dev) || (!dev->of_node))
163 return -ENODEV;
162 164
163 /* modalias is trickier, we add it in 2 steps */ 165 /* Devicetree modalias is tricky, we add it in 2 steps */
164 if (add_uevent_var(env, "MODALIAS=")) 166 if (add_uevent_var(env, "MODALIAS="))
165 return -ENOMEM; 167 return -ENOMEM;
166 168
diff --git a/drivers/of/of_mtd.c b/drivers/of/of_mtd.c
new file mode 100644
index 000000000000..e7cad627a5d1
--- /dev/null
+++ b/drivers/of/of_mtd.c
@@ -0,0 +1,85 @@
1/*
2 * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
3 *
4 * OF helpers for mtd.
5 *
6 * This file is released under the GPLv2
7 *
8 */
9#include <linux/kernel.h>
10#include <linux/of_mtd.h>
11#include <linux/mtd/nand.h>
12#include <linux/export.h>
13
14/**
15 * It maps 'enum nand_ecc_modes_t' found in include/linux/mtd/nand.h
16 * into the device tree binding of 'nand-ecc', so that MTD
17 * device driver can get nand ecc from device tree.
18 */
19static const char *nand_ecc_modes[] = {
20 [NAND_ECC_NONE] = "none",
21 [NAND_ECC_SOFT] = "soft",
22 [NAND_ECC_HW] = "hw",
23 [NAND_ECC_HW_SYNDROME] = "hw_syndrome",
24 [NAND_ECC_HW_OOB_FIRST] = "hw_oob_first",
25 [NAND_ECC_SOFT_BCH] = "soft_bch",
26};
27
28/**
29 * of_get_nand_ecc_mode - Get nand ecc mode for given device_node
30 * @np: Pointer to the given device_node
31 *
32 * The function gets ecc mode string from property 'nand-ecc-mode',
33 * and return its index in nand_ecc_modes table, or errno in error case.
34 */
35const int of_get_nand_ecc_mode(struct device_node *np)
36{
37 const char *pm;
38 int err, i;
39
40 err = of_property_read_string(np, "nand-ecc-mode", &pm);
41 if (err < 0)
42 return err;
43
44 for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++)
45 if (!strcasecmp(pm, nand_ecc_modes[i]))
46 return i;
47
48 return -ENODEV;
49}
50EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);
51
52/**
53 * of_get_nand_bus_width - Get nand bus witdh for given device_node
54 * @np: Pointer to the given device_node
55 *
56 * return bus width option, or errno in error case.
57 */
58int of_get_nand_bus_width(struct device_node *np)
59{
60 u32 val;
61
62 if (of_property_read_u32(np, "nand-bus-width", &val))
63 return 8;
64
65 switch(val) {
66 case 8:
67 case 16:
68 return val;
69 default:
70 return -EIO;
71 }
72}
73EXPORT_SYMBOL_GPL(of_get_nand_bus_width);
74
75/**
76 * of_get_nand_on_flash_bbt - Get nand on flash bbt for given device_node
77 * @np: Pointer to the given device_node
78 *
79 * return true if present false other wise
80 */
81bool of_get_nand_on_flash_bbt(struct device_node *np)
82{
83 return of_property_read_bool(np, "nand-on-flash-bbt");
84}
85EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt);
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 20fbebd49db3..343ad29e211c 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -253,7 +253,7 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
253 if (!of_device_is_available(node)) 253 if (!of_device_is_available(node))
254 return NULL; 254 return NULL;
255 255
256 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 256 dev = amba_device_alloc(NULL, 0, 0);
257 if (!dev) 257 if (!dev)
258 return NULL; 258 return NULL;
259 259
@@ -283,14 +283,14 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
283 if (ret) 283 if (ret)
284 goto err_free; 284 goto err_free;
285 285
286 ret = amba_device_register(dev, &iomem_resource); 286 ret = amba_device_add(dev, &iomem_resource);
287 if (ret) 287 if (ret)
288 goto err_free; 288 goto err_free;
289 289
290 return dev; 290 return dev;
291 291
292err_free: 292err_free:
293 kfree(dev); 293 amba_device_put(dev);
294 return NULL; 294 return NULL;
295} 295}
296#else /* CONFIG_ARM_AMBA */ 296#else /* CONFIG_ARM_AMBA */
diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c
index 9d2b4803a9d6..f24ffd7088d2 100644
--- a/drivers/of/selftest.c
+++ b/drivers/of/selftest.c
@@ -120,6 +120,34 @@ static void __init of_selftest_parse_phandle_with_args(void)
120 pr_info("end - %s\n", passed_all ? "PASS" : "FAIL"); 120 pr_info("end - %s\n", passed_all ? "PASS" : "FAIL");
121} 121}
122 122
123static void __init of_selftest_property_match_string(void)
124{
125 struct device_node *np;
126 int rc;
127
128 pr_info("start\n");
129 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
130 if (!np) {
131 pr_err("No testcase data in device tree\n");
132 return;
133 }
134
135 rc = of_property_match_string(np, "phandle-list-names", "first");
136 selftest(rc == 0, "first expected:0 got:%i\n", rc);
137 rc = of_property_match_string(np, "phandle-list-names", "second");
138 selftest(rc == 1, "second expected:0 got:%i\n", rc);
139 rc = of_property_match_string(np, "phandle-list-names", "third");
140 selftest(rc == 2, "third expected:0 got:%i\n", rc);
141 rc = of_property_match_string(np, "phandle-list-names", "fourth");
142 selftest(rc == -ENODATA, "unmatched string; rc=%i", rc);
143 rc = of_property_match_string(np, "missing-property", "blah");
144 selftest(rc == -EINVAL, "missing property; rc=%i", rc);
145 rc = of_property_match_string(np, "empty-property", "blah");
146 selftest(rc == -ENODATA, "empty property; rc=%i", rc);
147 rc = of_property_match_string(np, "unterminated-string", "blah");
148 selftest(rc == -EILSEQ, "unterminated string; rc=%i", rc);
149}
150
123static int __init of_selftest(void) 151static int __init of_selftest(void)
124{ 152{
125 struct device_node *np; 153 struct device_node *np;
@@ -133,6 +161,7 @@ static int __init of_selftest(void)
133 161
134 pr_info("start of selftest - you will see error messages\n"); 162 pr_info("start of selftest - you will see error messages\n");
135 of_selftest_parse_phandle_with_args(); 163 of_selftest_parse_phandle_with_args();
164 of_selftest_property_match_string();
136 pr_info("end of selftest - %s\n", selftest_passed ? "PASS" : "FAIL"); 165 pr_info("end of selftest - %s\n", selftest_passed ? "PASS" : "FAIL");
137 return 0; 166 return 0;
138} 167}