Commit 45bb1674b976ef81429c1e42de05844b49d45dea
Committed by
H. Peter Anvin
1 parent
25874a299e
Exists in
master
and in
7 other branches
x86, olpc: Use device tree for platform identification
Make OLPC fully depend on device tree, and use it to identify the OLPC platform details. Some nodes are exposed as platform devices where we plan to use device tree for device probing. Signed-off-by: Daniel Drake <dsd@laptop.org> Acked-by: Grant Likely <grant.likely@secretlab.ca> LKML-Reference: <20110313151017.C255F9D401E@zog.reactivated.net> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Showing 5 changed files with 51 additions and 34 deletions Side-by-side Diff
arch/x86/Kconfig
arch/x86/include/asm/olpc_ofw.h
... | ... | @@ -26,16 +26,13 @@ |
26 | 26 | /* check if OFW was detected during boot */ |
27 | 27 | extern bool olpc_ofw_present(void); |
28 | 28 | |
29 | +extern void olpc_dt_build_devicetree(void); | |
30 | + | |
29 | 31 | #else /* !CONFIG_OLPC */ |
30 | 32 | static inline void olpc_ofw_detect(void) { } |
31 | 33 | static inline void setup_olpc_ofw_pgd(void) { } |
32 | -#endif /* !CONFIG_OLPC */ | |
33 | - | |
34 | -#ifdef CONFIG_OF_PROMTREE | |
35 | -extern void olpc_dt_build_devicetree(void); | |
36 | -#else | |
37 | 34 | static inline void olpc_dt_build_devicetree(void) { } |
38 | -#endif | |
35 | +#endif /* !CONFIG_OLPC */ | |
39 | 36 | |
40 | 37 | #endif /* _ASM_X86_OLPC_OFW_H */ |
arch/x86/platform/olpc/Makefile
arch/x86/platform/olpc/olpc.c
... | ... | @@ -18,6 +18,7 @@ |
18 | 18 | #include <linux/io.h> |
19 | 19 | #include <linux/string.h> |
20 | 20 | #include <linux/platform_device.h> |
21 | +#include <linux/of.h> | |
21 | 22 | |
22 | 23 | #include <asm/geode.h> |
23 | 24 | #include <asm/setup.h> |
24 | 25 | |
25 | 26 | |
26 | 27 | |
27 | 28 | |
28 | 29 | |
29 | 30 | |
30 | 31 | |
... | ... | @@ -187,41 +188,43 @@ |
187 | 188 | } |
188 | 189 | EXPORT_SYMBOL_GPL(olpc_ec_cmd); |
189 | 190 | |
190 | -static bool __init check_ofw_architecture(void) | |
191 | +static bool __init check_ofw_architecture(struct device_node *root) | |
191 | 192 | { |
192 | - size_t propsize; | |
193 | - char olpc_arch[5]; | |
194 | - const void *args[] = { NULL, "architecture", olpc_arch, (void *)5 }; | |
195 | - void *res[] = { &propsize }; | |
193 | + const char *olpc_arch; | |
194 | + int propsize; | |
196 | 195 | |
197 | - if (olpc_ofw("getprop", args, res)) { | |
198 | - printk(KERN_ERR "ofw: getprop call failed!\n"); | |
199 | - return false; | |
200 | - } | |
196 | + olpc_arch = of_get_property(root, "architecture", &propsize); | |
201 | 197 | return propsize == 5 && strncmp("OLPC", olpc_arch, 5) == 0; |
202 | 198 | } |
203 | 199 | |
204 | -static u32 __init get_board_revision(void) | |
200 | +static u32 __init get_board_revision(struct device_node *root) | |
205 | 201 | { |
206 | - size_t propsize; | |
207 | - __be32 rev; | |
208 | - const void *args[] = { NULL, "board-revision-int", &rev, (void *)4 }; | |
209 | - void *res[] = { &propsize }; | |
202 | + int propsize; | |
203 | + const __be32 *rev; | |
210 | 204 | |
211 | - if (olpc_ofw("getprop", args, res) || propsize != 4) { | |
212 | - printk(KERN_ERR "ofw: getprop call failed!\n"); | |
213 | - return cpu_to_be32(0); | |
214 | - } | |
215 | - return be32_to_cpu(rev); | |
205 | + rev = of_get_property(root, "board-revision-int", &propsize); | |
206 | + if (propsize != 4) | |
207 | + return 0; | |
208 | + | |
209 | + return be32_to_cpu(*rev); | |
216 | 210 | } |
217 | 211 | |
218 | 212 | static bool __init platform_detect(void) |
219 | 213 | { |
220 | - if (!check_ofw_architecture()) | |
214 | + struct device_node *root = of_find_node_by_path("/"); | |
215 | + bool success; | |
216 | + | |
217 | + if (!root) | |
221 | 218 | return false; |
222 | - olpc_platform_info.flags |= OLPC_F_PRESENT; | |
223 | - olpc_platform_info.boardrev = get_board_revision(); | |
224 | - return true; | |
219 | + | |
220 | + success = check_ofw_architecture(root); | |
221 | + if (success) { | |
222 | + olpc_platform_info.boardrev = get_board_revision(root); | |
223 | + olpc_platform_info.flags |= OLPC_F_PRESENT; | |
224 | + } | |
225 | + | |
226 | + of_node_put(root); | |
227 | + return success; | |
225 | 228 | } |
226 | 229 | |
227 | 230 | static int __init add_xo1_platform_devices(void) |
arch/x86/platform/olpc/olpc_dt.c
... | ... | @@ -19,7 +19,9 @@ |
19 | 19 | #include <linux/kernel.h> |
20 | 20 | #include <linux/bootmem.h> |
21 | 21 | #include <linux/of.h> |
22 | +#include <linux/of_platform.h> | |
22 | 23 | #include <linux/of_pdt.h> |
24 | +#include <asm/olpc.h> | |
23 | 25 | #include <asm/olpc_ofw.h> |
24 | 26 | |
25 | 27 | static phandle __init olpc_dt_getsibling(phandle node) |
... | ... | @@ -181,4 +183,21 @@ |
181 | 183 | pr_info("PROM DT: Built device tree with %u bytes of memory.\n", |
182 | 184 | prom_early_allocated); |
183 | 185 | } |
186 | + | |
187 | +/* A list of DT node/bus matches that we want to expose as platform devices */ | |
188 | +static struct of_device_id __initdata of_ids[] = { | |
189 | + { .compatible = "olpc,xo1-battery" }, | |
190 | + { .compatible = "olpc,xo1-dcon" }, | |
191 | + { .compatible = "olpc,xo1-rtc" }, | |
192 | + {}, | |
193 | +}; | |
194 | + | |
195 | +static int __init olpc_create_platform_devices(void) | |
196 | +{ | |
197 | + if (machine_is_olpc()) | |
198 | + return of_platform_bus_probe(NULL, of_ids, NULL); | |
199 | + else | |
200 | + return 0; | |
201 | +} | |
202 | +device_initcall(olpc_create_platform_devices); |