diff options
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/Kconfig | 8 | ||||
-rw-r--r-- | drivers/of/Makefile | 1 | ||||
-rw-r--r-- | drivers/of/base.c | 318 | ||||
-rw-r--r-- | drivers/of/fdt.c | 590 | ||||
-rw-r--r-- | drivers/of/gpio.c | 13 | ||||
-rw-r--r-- | drivers/of/of_i2c.c | 4 | ||||
-rw-r--r-- | drivers/of/of_mdio.c | 8 | ||||
-rw-r--r-- | drivers/of/of_spi.c | 6 |
8 files changed, 927 insertions, 21 deletions
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index d2fa27c5c1b2..7cecc8fea9bd 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig | |||
@@ -1,3 +1,11 @@ | |||
1 | config OF_FLATTREE | ||
2 | bool | ||
3 | depends on OF | ||
4 | |||
5 | config OF_DYNAMIC | ||
6 | def_bool y | ||
7 | depends on OF && PPC_OF | ||
8 | |||
1 | config OF_DEVICE | 9 | config OF_DEVICE |
2 | def_bool y | 10 | def_bool y |
3 | depends on OF && (SPARC || PPC_OF || MICROBLAZE) | 11 | depends on OF && (SPARC || PPC_OF || MICROBLAZE) |
diff --git a/drivers/of/Makefile b/drivers/of/Makefile index bdfb5f5d4b06..f232cc98ce00 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile | |||
@@ -1,4 +1,5 @@ | |||
1 | obj-y = base.o | 1 | obj-y = base.o |
2 | obj-$(CONFIG_OF_FLATTREE) += fdt.o | ||
2 | obj-$(CONFIG_OF_DEVICE) += device.o platform.o | 3 | obj-$(CONFIG_OF_DEVICE) += device.o platform.o |
3 | obj-$(CONFIG_OF_GPIO) += gpio.o | 4 | obj-$(CONFIG_OF_GPIO) += gpio.o |
4 | obj-$(CONFIG_OF_I2C) += of_i2c.o | 5 | obj-$(CONFIG_OF_I2C) += of_i2c.o |
diff --git a/drivers/of/base.c b/drivers/of/base.c index e6627b2320f1..cb96888d1427 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -20,8 +20,10 @@ | |||
20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | #include <linux/of.h> | 21 | #include <linux/of.h> |
22 | #include <linux/spinlock.h> | 22 | #include <linux/spinlock.h> |
23 | #include <linux/proc_fs.h> | ||
23 | 24 | ||
24 | struct device_node *allnodes; | 25 | struct device_node *allnodes; |
26 | struct device_node *of_chosen; | ||
25 | 27 | ||
26 | /* use when traversing tree through the allnext, child, sibling, | 28 | /* use when traversing tree through the allnext, child, sibling, |
27 | * or parent members of struct device_node. | 29 | * or parent members of struct device_node. |
@@ -37,7 +39,7 @@ int of_n_addr_cells(struct device_node *np) | |||
37 | np = np->parent; | 39 | np = np->parent; |
38 | ip = of_get_property(np, "#address-cells", NULL); | 40 | ip = of_get_property(np, "#address-cells", NULL); |
39 | if (ip) | 41 | if (ip) |
40 | return *ip; | 42 | return be32_to_cpup(ip); |
41 | } while (np->parent); | 43 | } while (np->parent); |
42 | /* No #address-cells property for the root node */ | 44 | /* No #address-cells property for the root node */ |
43 | return OF_ROOT_NODE_ADDR_CELLS_DEFAULT; | 45 | return OF_ROOT_NODE_ADDR_CELLS_DEFAULT; |
@@ -53,13 +55,88 @@ int of_n_size_cells(struct device_node *np) | |||
53 | np = np->parent; | 55 | np = np->parent; |
54 | ip = of_get_property(np, "#size-cells", NULL); | 56 | ip = of_get_property(np, "#size-cells", NULL); |
55 | if (ip) | 57 | if (ip) |
56 | return *ip; | 58 | return be32_to_cpup(ip); |
57 | } while (np->parent); | 59 | } while (np->parent); |
58 | /* No #size-cells property for the root node */ | 60 | /* No #size-cells property for the root node */ |
59 | return OF_ROOT_NODE_SIZE_CELLS_DEFAULT; | 61 | return OF_ROOT_NODE_SIZE_CELLS_DEFAULT; |
60 | } | 62 | } |
61 | EXPORT_SYMBOL(of_n_size_cells); | 63 | EXPORT_SYMBOL(of_n_size_cells); |
62 | 64 | ||
65 | #if !defined(CONFIG_SPARC) /* SPARC doesn't do ref counting (yet) */ | ||
66 | /** | ||
67 | * of_node_get - Increment refcount of a node | ||
68 | * @node: Node to inc refcount, NULL is supported to | ||
69 | * simplify writing of callers | ||
70 | * | ||
71 | * Returns node. | ||
72 | */ | ||
73 | struct device_node *of_node_get(struct device_node *node) | ||
74 | { | ||
75 | if (node) | ||
76 | kref_get(&node->kref); | ||
77 | return node; | ||
78 | } | ||
79 | EXPORT_SYMBOL(of_node_get); | ||
80 | |||
81 | static inline struct device_node *kref_to_device_node(struct kref *kref) | ||
82 | { | ||
83 | return container_of(kref, struct device_node, kref); | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | * of_node_release - release a dynamically allocated node | ||
88 | * @kref: kref element of the node to be released | ||
89 | * | ||
90 | * In of_node_put() this function is passed to kref_put() | ||
91 | * as the destructor. | ||
92 | */ | ||
93 | static void of_node_release(struct kref *kref) | ||
94 | { | ||
95 | struct device_node *node = kref_to_device_node(kref); | ||
96 | struct property *prop = node->properties; | ||
97 | |||
98 | /* We should never be releasing nodes that haven't been detached. */ | ||
99 | if (!of_node_check_flag(node, OF_DETACHED)) { | ||
100 | pr_err("ERROR: Bad of_node_put() on %s\n", node->full_name); | ||
101 | dump_stack(); | ||
102 | kref_init(&node->kref); | ||
103 | return; | ||
104 | } | ||
105 | |||
106 | if (!of_node_check_flag(node, OF_DYNAMIC)) | ||
107 | return; | ||
108 | |||
109 | while (prop) { | ||
110 | struct property *next = prop->next; | ||
111 | kfree(prop->name); | ||
112 | kfree(prop->value); | ||
113 | kfree(prop); | ||
114 | prop = next; | ||
115 | |||
116 | if (!prop) { | ||
117 | prop = node->deadprops; | ||
118 | node->deadprops = NULL; | ||
119 | } | ||
120 | } | ||
121 | kfree(node->full_name); | ||
122 | kfree(node->data); | ||
123 | kfree(node); | ||
124 | } | ||
125 | |||
126 | /** | ||
127 | * of_node_put - Decrement refcount of a node | ||
128 | * @node: Node to dec refcount, NULL is supported to | ||
129 | * simplify writing of callers | ||
130 | * | ||
131 | */ | ||
132 | void of_node_put(struct device_node *node) | ||
133 | { | ||
134 | if (node) | ||
135 | kref_put(&node->kref, of_node_release); | ||
136 | } | ||
137 | EXPORT_SYMBOL(of_node_put); | ||
138 | #endif /* !CONFIG_SPARC */ | ||
139 | |||
63 | struct property *of_find_property(const struct device_node *np, | 140 | struct property *of_find_property(const struct device_node *np, |
64 | const char *name, | 141 | const char *name, |
65 | int *lenp) | 142 | int *lenp) |
@@ -144,6 +221,27 @@ int of_device_is_compatible(const struct device_node *device, | |||
144 | EXPORT_SYMBOL(of_device_is_compatible); | 221 | EXPORT_SYMBOL(of_device_is_compatible); |
145 | 222 | ||
146 | /** | 223 | /** |
224 | * of_machine_is_compatible - Test root of device tree for a given compatible value | ||
225 | * @compat: compatible string to look for in root node's compatible property. | ||
226 | * | ||
227 | * Returns true if the root node has the given value in its | ||
228 | * compatible property. | ||
229 | */ | ||
230 | int of_machine_is_compatible(const char *compat) | ||
231 | { | ||
232 | struct device_node *root; | ||
233 | int rc = 0; | ||
234 | |||
235 | root = of_find_node_by_path("/"); | ||
236 | if (root) { | ||
237 | rc = of_device_is_compatible(root, compat); | ||
238 | of_node_put(root); | ||
239 | } | ||
240 | return rc; | ||
241 | } | ||
242 | EXPORT_SYMBOL(of_machine_is_compatible); | ||
243 | |||
244 | /** | ||
147 | * of_device_is_available - check if a device is available for use | 245 | * of_device_is_available - check if a device is available for use |
148 | * | 246 | * |
149 | * @device: Node to check for availability | 247 | * @device: Node to check for availability |
@@ -519,6 +617,27 @@ int of_modalias_node(struct device_node *node, char *modalias, int len) | |||
519 | EXPORT_SYMBOL_GPL(of_modalias_node); | 617 | EXPORT_SYMBOL_GPL(of_modalias_node); |
520 | 618 | ||
521 | /** | 619 | /** |
620 | * of_find_node_by_phandle - Find a node given a phandle | ||
621 | * @handle: phandle of the node to find | ||
622 | * | ||
623 | * Returns a node pointer with refcount incremented, use | ||
624 | * of_node_put() on it when done. | ||
625 | */ | ||
626 | struct device_node *of_find_node_by_phandle(phandle handle) | ||
627 | { | ||
628 | struct device_node *np; | ||
629 | |||
630 | read_lock(&devtree_lock); | ||
631 | for (np = allnodes; np; np = np->allnext) | ||
632 | if (np->phandle == handle) | ||
633 | break; | ||
634 | of_node_get(np); | ||
635 | read_unlock(&devtree_lock); | ||
636 | return np; | ||
637 | } | ||
638 | EXPORT_SYMBOL(of_find_node_by_phandle); | ||
639 | |||
640 | /** | ||
522 | * of_parse_phandle - Resolve a phandle property to a device_node pointer | 641 | * of_parse_phandle - Resolve a phandle property to a device_node pointer |
523 | * @np: Pointer to device node holding phandle property | 642 | * @np: Pointer to device node holding phandle property |
524 | * @phandle_name: Name of property holding a phandle value | 643 | * @phandle_name: Name of property holding a phandle value |
@@ -578,8 +697,8 @@ int of_parse_phandles_with_args(struct device_node *np, const char *list_name, | |||
578 | const void **out_args) | 697 | const void **out_args) |
579 | { | 698 | { |
580 | int ret = -EINVAL; | 699 | int ret = -EINVAL; |
581 | const u32 *list; | 700 | const __be32 *list; |
582 | const u32 *list_end; | 701 | const __be32 *list_end; |
583 | int size; | 702 | int size; |
584 | int cur_index = 0; | 703 | int cur_index = 0; |
585 | struct device_node *node = NULL; | 704 | struct device_node *node = NULL; |
@@ -593,7 +712,7 @@ int of_parse_phandles_with_args(struct device_node *np, const char *list_name, | |||
593 | list_end = list + size / sizeof(*list); | 712 | list_end = list + size / sizeof(*list); |
594 | 713 | ||
595 | while (list < list_end) { | 714 | while (list < list_end) { |
596 | const u32 *cells; | 715 | const __be32 *cells; |
597 | const phandle *phandle; | 716 | const phandle *phandle; |
598 | 717 | ||
599 | phandle = list++; | 718 | phandle = list++; |
@@ -617,7 +736,7 @@ int of_parse_phandles_with_args(struct device_node *np, const char *list_name, | |||
617 | goto err1; | 736 | goto err1; |
618 | } | 737 | } |
619 | 738 | ||
620 | list += *cells; | 739 | list += be32_to_cpup(cells); |
621 | if (list > list_end) { | 740 | if (list > list_end) { |
622 | pr_debug("%s: insufficient arguments length\n", | 741 | pr_debug("%s: insufficient arguments length\n", |
623 | np->full_name); | 742 | np->full_name); |
@@ -658,3 +777,190 @@ err0: | |||
658 | return ret; | 777 | return ret; |
659 | } | 778 | } |
660 | EXPORT_SYMBOL(of_parse_phandles_with_args); | 779 | EXPORT_SYMBOL(of_parse_phandles_with_args); |
780 | |||
781 | /** | ||
782 | * prom_add_property - Add a property to a node | ||
783 | */ | ||
784 | int prom_add_property(struct device_node *np, struct property *prop) | ||
785 | { | ||
786 | struct property **next; | ||
787 | unsigned long flags; | ||
788 | |||
789 | prop->next = NULL; | ||
790 | write_lock_irqsave(&devtree_lock, flags); | ||
791 | next = &np->properties; | ||
792 | while (*next) { | ||
793 | if (strcmp(prop->name, (*next)->name) == 0) { | ||
794 | /* duplicate ! don't insert it */ | ||
795 | write_unlock_irqrestore(&devtree_lock, flags); | ||
796 | return -1; | ||
797 | } | ||
798 | next = &(*next)->next; | ||
799 | } | ||
800 | *next = prop; | ||
801 | write_unlock_irqrestore(&devtree_lock, flags); | ||
802 | |||
803 | #ifdef CONFIG_PROC_DEVICETREE | ||
804 | /* try to add to proc as well if it was initialized */ | ||
805 | if (np->pde) | ||
806 | proc_device_tree_add_prop(np->pde, prop); | ||
807 | #endif /* CONFIG_PROC_DEVICETREE */ | ||
808 | |||
809 | return 0; | ||
810 | } | ||
811 | |||
812 | /** | ||
813 | * prom_remove_property - Remove a property from a node. | ||
814 | * | ||
815 | * Note that we don't actually remove it, since we have given out | ||
816 | * who-knows-how-many pointers to the data using get-property. | ||
817 | * Instead we just move the property to the "dead properties" | ||
818 | * list, so it won't be found any more. | ||
819 | */ | ||
820 | int prom_remove_property(struct device_node *np, struct property *prop) | ||
821 | { | ||
822 | struct property **next; | ||
823 | unsigned long flags; | ||
824 | int found = 0; | ||
825 | |||
826 | write_lock_irqsave(&devtree_lock, flags); | ||
827 | next = &np->properties; | ||
828 | while (*next) { | ||
829 | if (*next == prop) { | ||
830 | /* found the node */ | ||
831 | *next = prop->next; | ||
832 | prop->next = np->deadprops; | ||
833 | np->deadprops = prop; | ||
834 | found = 1; | ||
835 | break; | ||
836 | } | ||
837 | next = &(*next)->next; | ||
838 | } | ||
839 | write_unlock_irqrestore(&devtree_lock, flags); | ||
840 | |||
841 | if (!found) | ||
842 | return -ENODEV; | ||
843 | |||
844 | #ifdef CONFIG_PROC_DEVICETREE | ||
845 | /* try to remove the proc node as well */ | ||
846 | if (np->pde) | ||
847 | proc_device_tree_remove_prop(np->pde, prop); | ||
848 | #endif /* CONFIG_PROC_DEVICETREE */ | ||
849 | |||
850 | return 0; | ||
851 | } | ||
852 | |||
853 | /* | ||
854 | * prom_update_property - Update a property in a node. | ||
855 | * | ||
856 | * Note that we don't actually remove it, since we have given out | ||
857 | * who-knows-how-many pointers to the data using get-property. | ||
858 | * Instead we just move the property to the "dead properties" list, | ||
859 | * and add the new property to the property list | ||
860 | */ | ||
861 | int prom_update_property(struct device_node *np, | ||
862 | struct property *newprop, | ||
863 | struct property *oldprop) | ||
864 | { | ||
865 | struct property **next; | ||
866 | unsigned long flags; | ||
867 | int found = 0; | ||
868 | |||
869 | write_lock_irqsave(&devtree_lock, flags); | ||
870 | next = &np->properties; | ||
871 | while (*next) { | ||
872 | if (*next == oldprop) { | ||
873 | /* found the node */ | ||
874 | newprop->next = oldprop->next; | ||
875 | *next = newprop; | ||
876 | oldprop->next = np->deadprops; | ||
877 | np->deadprops = oldprop; | ||
878 | found = 1; | ||
879 | break; | ||
880 | } | ||
881 | next = &(*next)->next; | ||
882 | } | ||
883 | write_unlock_irqrestore(&devtree_lock, flags); | ||
884 | |||
885 | if (!found) | ||
886 | return -ENODEV; | ||
887 | |||
888 | #ifdef CONFIG_PROC_DEVICETREE | ||
889 | /* try to add to proc as well if it was initialized */ | ||
890 | if (np->pde) | ||
891 | proc_device_tree_update_prop(np->pde, newprop, oldprop); | ||
892 | #endif /* CONFIG_PROC_DEVICETREE */ | ||
893 | |||
894 | return 0; | ||
895 | } | ||
896 | |||
897 | #if defined(CONFIG_OF_DYNAMIC) | ||
898 | /* | ||
899 | * Support for dynamic device trees. | ||
900 | * | ||
901 | * On some platforms, the device tree can be manipulated at runtime. | ||
902 | * The routines in this section support adding, removing and changing | ||
903 | * device tree nodes. | ||
904 | */ | ||
905 | |||
906 | /** | ||
907 | * of_attach_node - Plug a device node into the tree and global list. | ||
908 | */ | ||
909 | void of_attach_node(struct device_node *np) | ||
910 | { | ||
911 | unsigned long flags; | ||
912 | |||
913 | write_lock_irqsave(&devtree_lock, flags); | ||
914 | np->sibling = np->parent->child; | ||
915 | np->allnext = allnodes; | ||
916 | np->parent->child = np; | ||
917 | allnodes = np; | ||
918 | write_unlock_irqrestore(&devtree_lock, flags); | ||
919 | } | ||
920 | |||
921 | /** | ||
922 | * of_detach_node - "Unplug" a node from the device tree. | ||
923 | * | ||
924 | * The caller must hold a reference to the node. The memory associated with | ||
925 | * the node is not freed until its refcount goes to zero. | ||
926 | */ | ||
927 | void of_detach_node(struct device_node *np) | ||
928 | { | ||
929 | struct device_node *parent; | ||
930 | unsigned long flags; | ||
931 | |||
932 | write_lock_irqsave(&devtree_lock, flags); | ||
933 | |||
934 | parent = np->parent; | ||
935 | if (!parent) | ||
936 | goto out_unlock; | ||
937 | |||
938 | if (allnodes == np) | ||
939 | allnodes = np->allnext; | ||
940 | else { | ||
941 | struct device_node *prev; | ||
942 | for (prev = allnodes; | ||
943 | prev->allnext != np; | ||
944 | prev = prev->allnext) | ||
945 | ; | ||
946 | prev->allnext = np->allnext; | ||
947 | } | ||
948 | |||
949 | if (parent->child == np) | ||
950 | parent->child = np->sibling; | ||
951 | else { | ||
952 | struct device_node *prevsib; | ||
953 | for (prevsib = np->parent->child; | ||
954 | prevsib->sibling != np; | ||
955 | prevsib = prevsib->sibling) | ||
956 | ; | ||
957 | prevsib->sibling = np->sibling; | ||
958 | } | ||
959 | |||
960 | of_node_set_flag(np, OF_DETACHED); | ||
961 | |||
962 | out_unlock: | ||
963 | write_unlock_irqrestore(&devtree_lock, flags); | ||
964 | } | ||
965 | #endif /* defined(CONFIG_OF_DYNAMIC) */ | ||
966 | |||
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c new file mode 100644 index 000000000000..406757a9d7ea --- /dev/null +++ b/drivers/of/fdt.c | |||
@@ -0,0 +1,590 @@ | |||
1 | /* | ||
2 | * Functions for working with the Flattened Device Tree data format | ||
3 | * | ||
4 | * Copyright 2009 Benjamin Herrenschmidt, IBM Corp | ||
5 | * benh@kernel.crashing.org | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 as published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/initrd.h> | ||
14 | #include <linux/of.h> | ||
15 | #include <linux/of_fdt.h> | ||
16 | #include <linux/string.h> | ||
17 | #include <linux/errno.h> | ||
18 | |||
19 | #ifdef CONFIG_PPC | ||
20 | #include <asm/machdep.h> | ||
21 | #endif /* CONFIG_PPC */ | ||
22 | |||
23 | #include <asm/page.h> | ||
24 | |||
25 | int __initdata dt_root_addr_cells; | ||
26 | int __initdata dt_root_size_cells; | ||
27 | |||
28 | struct boot_param_header *initial_boot_params; | ||
29 | |||
30 | char *find_flat_dt_string(u32 offset) | ||
31 | { | ||
32 | return ((char *)initial_boot_params) + | ||
33 | be32_to_cpu(initial_boot_params->off_dt_strings) + offset; | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * of_scan_flat_dt - scan flattened tree blob and call callback on each. | ||
38 | * @it: callback function | ||
39 | * @data: context data pointer | ||
40 | * | ||
41 | * This function is used to scan the flattened device-tree, it is | ||
42 | * used to extract the memory information at boot before we can | ||
43 | * unflatten the tree | ||
44 | */ | ||
45 | int __init of_scan_flat_dt(int (*it)(unsigned long node, | ||
46 | const char *uname, int depth, | ||
47 | void *data), | ||
48 | void *data) | ||
49 | { | ||
50 | unsigned long p = ((unsigned long)initial_boot_params) + | ||
51 | be32_to_cpu(initial_boot_params->off_dt_struct); | ||
52 | int rc = 0; | ||
53 | int depth = -1; | ||
54 | |||
55 | do { | ||
56 | u32 tag = be32_to_cpup((__be32 *)p); | ||
57 | char *pathp; | ||
58 | |||
59 | p += 4; | ||
60 | if (tag == OF_DT_END_NODE) { | ||
61 | depth--; | ||
62 | continue; | ||
63 | } | ||
64 | if (tag == OF_DT_NOP) | ||
65 | continue; | ||
66 | if (tag == OF_DT_END) | ||
67 | break; | ||
68 | if (tag == OF_DT_PROP) { | ||
69 | u32 sz = be32_to_cpup((__be32 *)p); | ||
70 | p += 8; | ||
71 | if (be32_to_cpu(initial_boot_params->version) < 0x10) | ||
72 | p = _ALIGN(p, sz >= 8 ? 8 : 4); | ||
73 | p += sz; | ||
74 | p = _ALIGN(p, 4); | ||
75 | continue; | ||
76 | } | ||
77 | if (tag != OF_DT_BEGIN_NODE) { | ||
78 | pr_err("Invalid tag %x in flat device tree!\n", tag); | ||
79 | return -EINVAL; | ||
80 | } | ||
81 | depth++; | ||
82 | pathp = (char *)p; | ||
83 | p = _ALIGN(p + strlen(pathp) + 1, 4); | ||
84 | if ((*pathp) == '/') { | ||
85 | char *lp, *np; | ||
86 | for (lp = NULL, np = pathp; *np; np++) | ||
87 | if ((*np) == '/') | ||
88 | lp = np+1; | ||
89 | if (lp != NULL) | ||
90 | pathp = lp; | ||
91 | } | ||
92 | rc = it(p, pathp, depth, data); | ||
93 | if (rc != 0) | ||
94 | break; | ||
95 | } while (1); | ||
96 | |||
97 | return rc; | ||
98 | } | ||
99 | |||
100 | /** | ||
101 | * of_get_flat_dt_root - find the root node in the flat blob | ||
102 | */ | ||
103 | unsigned long __init of_get_flat_dt_root(void) | ||
104 | { | ||
105 | unsigned long p = ((unsigned long)initial_boot_params) + | ||
106 | be32_to_cpu(initial_boot_params->off_dt_struct); | ||
107 | |||
108 | while (be32_to_cpup((__be32 *)p) == OF_DT_NOP) | ||
109 | p += 4; | ||
110 | BUG_ON(be32_to_cpup((__be32 *)p) != OF_DT_BEGIN_NODE); | ||
111 | p += 4; | ||
112 | return _ALIGN(p + strlen((char *)p) + 1, 4); | ||
113 | } | ||
114 | |||
115 | /** | ||
116 | * of_get_flat_dt_prop - Given a node in the flat blob, return the property ptr | ||
117 | * | ||
118 | * This function can be used within scan_flattened_dt callback to get | ||
119 | * access to properties | ||
120 | */ | ||
121 | void *__init of_get_flat_dt_prop(unsigned long node, const char *name, | ||
122 | unsigned long *size) | ||
123 | { | ||
124 | unsigned long p = node; | ||
125 | |||
126 | do { | ||
127 | u32 tag = be32_to_cpup((__be32 *)p); | ||
128 | u32 sz, noff; | ||
129 | const char *nstr; | ||
130 | |||
131 | p += 4; | ||
132 | if (tag == OF_DT_NOP) | ||
133 | continue; | ||
134 | if (tag != OF_DT_PROP) | ||
135 | return NULL; | ||
136 | |||
137 | sz = be32_to_cpup((__be32 *)p); | ||
138 | noff = be32_to_cpup((__be32 *)(p + 4)); | ||
139 | p += 8; | ||
140 | if (be32_to_cpu(initial_boot_params->version) < 0x10) | ||
141 | p = _ALIGN(p, sz >= 8 ? 8 : 4); | ||
142 | |||
143 | nstr = find_flat_dt_string(noff); | ||
144 | if (nstr == NULL) { | ||
145 | pr_warning("Can't find property index name !\n"); | ||
146 | return NULL; | ||
147 | } | ||
148 | if (strcmp(name, nstr) == 0) { | ||
149 | if (size) | ||
150 | *size = sz; | ||
151 | return (void *)p; | ||
152 | } | ||
153 | p += sz; | ||
154 | p = _ALIGN(p, 4); | ||
155 | } while (1); | ||
156 | } | ||
157 | |||
158 | /** | ||
159 | * of_flat_dt_is_compatible - Return true if given node has compat in compatible list | ||
160 | * @node: node to test | ||
161 | * @compat: compatible string to compare with compatible list. | ||
162 | */ | ||
163 | int __init of_flat_dt_is_compatible(unsigned long node, const char *compat) | ||
164 | { | ||
165 | const char *cp; | ||
166 | unsigned long cplen, l; | ||
167 | |||
168 | cp = of_get_flat_dt_prop(node, "compatible", &cplen); | ||
169 | if (cp == NULL) | ||
170 | return 0; | ||
171 | while (cplen > 0) { | ||
172 | if (strncasecmp(cp, compat, strlen(compat)) == 0) | ||
173 | return 1; | ||
174 | l = strlen(cp) + 1; | ||
175 | cp += l; | ||
176 | cplen -= l; | ||
177 | } | ||
178 | |||
179 | return 0; | ||
180 | } | ||
181 | |||
182 | static void *__init unflatten_dt_alloc(unsigned long *mem, unsigned long size, | ||
183 | unsigned long align) | ||
184 | { | ||
185 | void *res; | ||
186 | |||
187 | *mem = _ALIGN(*mem, align); | ||
188 | res = (void *)*mem; | ||
189 | *mem += size; | ||
190 | |||
191 | return res; | ||
192 | } | ||
193 | |||
194 | /** | ||
195 | * unflatten_dt_node - Alloc and populate a device_node from the flat tree | ||
196 | * @p: pointer to node in flat tree | ||
197 | * @dad: Parent struct device_node | ||
198 | * @allnextpp: pointer to ->allnext from last allocated device_node | ||
199 | * @fpsize: Size of the node path up at the current depth. | ||
200 | */ | ||
201 | unsigned long __init unflatten_dt_node(unsigned long mem, | ||
202 | unsigned long *p, | ||
203 | struct device_node *dad, | ||
204 | struct device_node ***allnextpp, | ||
205 | unsigned long fpsize) | ||
206 | { | ||
207 | struct device_node *np; | ||
208 | struct property *pp, **prev_pp = NULL; | ||
209 | char *pathp; | ||
210 | u32 tag; | ||
211 | unsigned int l, allocl; | ||
212 | int has_name = 0; | ||
213 | int new_format = 0; | ||
214 | |||
215 | tag = be32_to_cpup((__be32 *)(*p)); | ||
216 | if (tag != OF_DT_BEGIN_NODE) { | ||
217 | pr_err("Weird tag at start of node: %x\n", tag); | ||
218 | return mem; | ||
219 | } | ||
220 | *p += 4; | ||
221 | pathp = (char *)*p; | ||
222 | l = allocl = strlen(pathp) + 1; | ||
223 | *p = _ALIGN(*p + l, 4); | ||
224 | |||
225 | /* version 0x10 has a more compact unit name here instead of the full | ||
226 | * path. we accumulate the full path size using "fpsize", we'll rebuild | ||
227 | * it later. We detect this because the first character of the name is | ||
228 | * not '/'. | ||
229 | */ | ||
230 | if ((*pathp) != '/') { | ||
231 | new_format = 1; | ||
232 | if (fpsize == 0) { | ||
233 | /* root node: special case. fpsize accounts for path | ||
234 | * plus terminating zero. root node only has '/', so | ||
235 | * fpsize should be 2, but we want to avoid the first | ||
236 | * level nodes to have two '/' so we use fpsize 1 here | ||
237 | */ | ||
238 | fpsize = 1; | ||
239 | allocl = 2; | ||
240 | } else { | ||
241 | /* account for '/' and path size minus terminal 0 | ||
242 | * already in 'l' | ||
243 | */ | ||
244 | fpsize += l; | ||
245 | allocl = fpsize; | ||
246 | } | ||
247 | } | ||
248 | |||
249 | np = unflatten_dt_alloc(&mem, sizeof(struct device_node) + allocl, | ||
250 | __alignof__(struct device_node)); | ||
251 | if (allnextpp) { | ||
252 | memset(np, 0, sizeof(*np)); | ||
253 | np->full_name = ((char *)np) + sizeof(struct device_node); | ||
254 | if (new_format) { | ||
255 | char *fn = np->full_name; | ||
256 | /* rebuild full path for new format */ | ||
257 | if (dad && dad->parent) { | ||
258 | strcpy(fn, dad->full_name); | ||
259 | #ifdef DEBUG | ||
260 | if ((strlen(fn) + l + 1) != allocl) { | ||
261 | pr_debug("%s: p: %d, l: %d, a: %d\n", | ||
262 | pathp, (int)strlen(fn), | ||
263 | l, allocl); | ||
264 | } | ||
265 | #endif | ||
266 | fn += strlen(fn); | ||
267 | } | ||
268 | *(fn++) = '/'; | ||
269 | memcpy(fn, pathp, l); | ||
270 | } else | ||
271 | memcpy(np->full_name, pathp, l); | ||
272 | prev_pp = &np->properties; | ||
273 | **allnextpp = np; | ||
274 | *allnextpp = &np->allnext; | ||
275 | if (dad != NULL) { | ||
276 | np->parent = dad; | ||
277 | /* we temporarily use the next field as `last_child'*/ | ||
278 | if (dad->next == NULL) | ||
279 | dad->child = np; | ||
280 | else | ||
281 | dad->next->sibling = np; | ||
282 | dad->next = np; | ||
283 | } | ||
284 | kref_init(&np->kref); | ||
285 | } | ||
286 | while (1) { | ||
287 | u32 sz, noff; | ||
288 | char *pname; | ||
289 | |||
290 | tag = be32_to_cpup((__be32 *)(*p)); | ||
291 | if (tag == OF_DT_NOP) { | ||
292 | *p += 4; | ||
293 | continue; | ||
294 | } | ||
295 | if (tag != OF_DT_PROP) | ||
296 | break; | ||
297 | *p += 4; | ||
298 | sz = be32_to_cpup((__be32 *)(*p)); | ||
299 | noff = be32_to_cpup((__be32 *)((*p) + 4)); | ||
300 | *p += 8; | ||
301 | if (be32_to_cpu(initial_boot_params->version) < 0x10) | ||
302 | *p = _ALIGN(*p, sz >= 8 ? 8 : 4); | ||
303 | |||
304 | pname = find_flat_dt_string(noff); | ||
305 | if (pname == NULL) { | ||
306 | pr_info("Can't find property name in list !\n"); | ||
307 | break; | ||
308 | } | ||
309 | if (strcmp(pname, "name") == 0) | ||
310 | has_name = 1; | ||
311 | l = strlen(pname) + 1; | ||
312 | pp = unflatten_dt_alloc(&mem, sizeof(struct property), | ||
313 | __alignof__(struct property)); | ||
314 | if (allnextpp) { | ||
315 | /* We accept flattened tree phandles either in | ||
316 | * ePAPR-style "phandle" properties, or the | ||
317 | * legacy "linux,phandle" properties. If both | ||
318 | * appear and have different values, things | ||
319 | * will get weird. Don't do that. */ | ||
320 | if ((strcmp(pname, "phandle") == 0) || | ||
321 | (strcmp(pname, "linux,phandle") == 0)) { | ||
322 | if (np->phandle == 0) | ||
323 | np->phandle = *((u32 *)*p); | ||
324 | } | ||
325 | /* And we process the "ibm,phandle" property | ||
326 | * used in pSeries dynamic device tree | ||
327 | * stuff */ | ||
328 | if (strcmp(pname, "ibm,phandle") == 0) | ||
329 | np->phandle = *((u32 *)*p); | ||
330 | pp->name = pname; | ||
331 | pp->length = sz; | ||
332 | pp->value = (void *)*p; | ||
333 | *prev_pp = pp; | ||
334 | prev_pp = &pp->next; | ||
335 | } | ||
336 | *p = _ALIGN((*p) + sz, 4); | ||
337 | } | ||
338 | /* with version 0x10 we may not have the name property, recreate | ||
339 | * it here from the unit name if absent | ||
340 | */ | ||
341 | if (!has_name) { | ||
342 | char *p1 = pathp, *ps = pathp, *pa = NULL; | ||
343 | int sz; | ||
344 | |||
345 | while (*p1) { | ||
346 | if ((*p1) == '@') | ||
347 | pa = p1; | ||
348 | if ((*p1) == '/') | ||
349 | ps = p1 + 1; | ||
350 | p1++; | ||
351 | } | ||
352 | if (pa < ps) | ||
353 | pa = p1; | ||
354 | sz = (pa - ps) + 1; | ||
355 | pp = unflatten_dt_alloc(&mem, sizeof(struct property) + sz, | ||
356 | __alignof__(struct property)); | ||
357 | if (allnextpp) { | ||
358 | pp->name = "name"; | ||
359 | pp->length = sz; | ||
360 | pp->value = pp + 1; | ||
361 | *prev_pp = pp; | ||
362 | prev_pp = &pp->next; | ||
363 | memcpy(pp->value, ps, sz - 1); | ||
364 | ((char *)pp->value)[sz - 1] = 0; | ||
365 | pr_debug("fixed up name for %s -> %s\n", pathp, | ||
366 | (char *)pp->value); | ||
367 | } | ||
368 | } | ||
369 | if (allnextpp) { | ||
370 | *prev_pp = NULL; | ||
371 | np->name = of_get_property(np, "name", NULL); | ||
372 | np->type = of_get_property(np, "device_type", NULL); | ||
373 | |||
374 | if (!np->name) | ||
375 | np->name = "<NULL>"; | ||
376 | if (!np->type) | ||
377 | np->type = "<NULL>"; | ||
378 | } | ||
379 | while (tag == OF_DT_BEGIN_NODE) { | ||
380 | mem = unflatten_dt_node(mem, p, np, allnextpp, fpsize); | ||
381 | tag = be32_to_cpup((__be32 *)(*p)); | ||
382 | } | ||
383 | if (tag != OF_DT_END_NODE) { | ||
384 | pr_err("Weird tag at end of node: %x\n", tag); | ||
385 | return mem; | ||
386 | } | ||
387 | *p += 4; | ||
388 | return mem; | ||
389 | } | ||
390 | |||
391 | #ifdef CONFIG_BLK_DEV_INITRD | ||
392 | /** | ||
393 | * early_init_dt_check_for_initrd - Decode initrd location from flat tree | ||
394 | * @node: reference to node containing initrd location ('chosen') | ||
395 | */ | ||
396 | void __init early_init_dt_check_for_initrd(unsigned long node) | ||
397 | { | ||
398 | unsigned long start, end, len; | ||
399 | __be32 *prop; | ||
400 | |||
401 | pr_debug("Looking for initrd properties... "); | ||
402 | |||
403 | prop = of_get_flat_dt_prop(node, "linux,initrd-start", &len); | ||
404 | if (!prop) | ||
405 | return; | ||
406 | start = of_read_ulong(prop, len/4); | ||
407 | |||
408 | prop = of_get_flat_dt_prop(node, "linux,initrd-end", &len); | ||
409 | if (!prop) | ||
410 | return; | ||
411 | end = of_read_ulong(prop, len/4); | ||
412 | |||
413 | early_init_dt_setup_initrd_arch(start, end); | ||
414 | pr_debug("initrd_start=0x%lx initrd_end=0x%lx\n", start, end); | ||
415 | } | ||
416 | #else | ||
417 | inline void early_init_dt_check_for_initrd(unsigned long node) | ||
418 | { | ||
419 | } | ||
420 | #endif /* CONFIG_BLK_DEV_INITRD */ | ||
421 | |||
422 | /** | ||
423 | * early_init_dt_scan_root - fetch the top level address and size cells | ||
424 | */ | ||
425 | int __init early_init_dt_scan_root(unsigned long node, const char *uname, | ||
426 | int depth, void *data) | ||
427 | { | ||
428 | __be32 *prop; | ||
429 | |||
430 | if (depth != 0) | ||
431 | return 0; | ||
432 | |||
433 | dt_root_size_cells = OF_ROOT_NODE_SIZE_CELLS_DEFAULT; | ||
434 | dt_root_addr_cells = OF_ROOT_NODE_ADDR_CELLS_DEFAULT; | ||
435 | |||
436 | prop = of_get_flat_dt_prop(node, "#size-cells", NULL); | ||
437 | if (prop) | ||
438 | dt_root_size_cells = be32_to_cpup(prop); | ||
439 | pr_debug("dt_root_size_cells = %x\n", dt_root_size_cells); | ||
440 | |||
441 | prop = of_get_flat_dt_prop(node, "#address-cells", NULL); | ||
442 | if (prop) | ||
443 | dt_root_addr_cells = be32_to_cpup(prop); | ||
444 | pr_debug("dt_root_addr_cells = %x\n", dt_root_addr_cells); | ||
445 | |||
446 | /* break now */ | ||
447 | return 1; | ||
448 | } | ||
449 | |||
450 | u64 __init dt_mem_next_cell(int s, __be32 **cellp) | ||
451 | { | ||
452 | __be32 *p = *cellp; | ||
453 | |||
454 | *cellp = p + s; | ||
455 | return of_read_number(p, s); | ||
456 | } | ||
457 | |||
458 | /** | ||
459 | * early_init_dt_scan_memory - Look for an parse memory nodes | ||
460 | */ | ||
461 | int __init early_init_dt_scan_memory(unsigned long node, const char *uname, | ||
462 | int depth, void *data) | ||
463 | { | ||
464 | char *type = of_get_flat_dt_prop(node, "device_type", NULL); | ||
465 | __be32 *reg, *endp; | ||
466 | unsigned long l; | ||
467 | |||
468 | /* We are scanning "memory" nodes only */ | ||
469 | if (type == NULL) { | ||
470 | /* | ||
471 | * The longtrail doesn't have a device_type on the | ||
472 | * /memory node, so look for the node called /memory@0. | ||
473 | */ | ||
474 | if (depth != 1 || strcmp(uname, "memory@0") != 0) | ||
475 | return 0; | ||
476 | } else if (strcmp(type, "memory") != 0) | ||
477 | return 0; | ||
478 | |||
479 | reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l); | ||
480 | if (reg == NULL) | ||
481 | reg = of_get_flat_dt_prop(node, "reg", &l); | ||
482 | if (reg == NULL) | ||
483 | return 0; | ||
484 | |||
485 | endp = reg + (l / sizeof(__be32)); | ||
486 | |||
487 | pr_debug("memory scan node %s, reg size %ld, data: %x %x %x %x,\n", | ||
488 | uname, l, reg[0], reg[1], reg[2], reg[3]); | ||
489 | |||
490 | while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { | ||
491 | u64 base, size; | ||
492 | |||
493 | base = dt_mem_next_cell(dt_root_addr_cells, ®); | ||
494 | size = dt_mem_next_cell(dt_root_size_cells, ®); | ||
495 | |||
496 | if (size == 0) | ||
497 | continue; | ||
498 | pr_debug(" - %llx , %llx\n", (unsigned long long)base, | ||
499 | (unsigned long long)size); | ||
500 | |||
501 | early_init_dt_add_memory_arch(base, size); | ||
502 | } | ||
503 | |||
504 | return 0; | ||
505 | } | ||
506 | |||
507 | int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, | ||
508 | int depth, void *data) | ||
509 | { | ||
510 | unsigned long l; | ||
511 | char *p; | ||
512 | |||
513 | pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname); | ||
514 | |||
515 | if (depth != 1 || | ||
516 | (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0)) | ||
517 | return 0; | ||
518 | |||
519 | early_init_dt_check_for_initrd(node); | ||
520 | |||
521 | /* Retreive command line */ | ||
522 | p = of_get_flat_dt_prop(node, "bootargs", &l); | ||
523 | if (p != NULL && l > 0) | ||
524 | strlcpy(cmd_line, p, min((int)l, COMMAND_LINE_SIZE)); | ||
525 | |||
526 | #ifdef CONFIG_CMDLINE | ||
527 | #ifndef CONFIG_CMDLINE_FORCE | ||
528 | if (p == NULL || l == 0 || (l == 1 && (*p) == 0)) | ||
529 | #endif | ||
530 | strlcpy(cmd_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); | ||
531 | #endif /* CONFIG_CMDLINE */ | ||
532 | |||
533 | early_init_dt_scan_chosen_arch(node); | ||
534 | |||
535 | pr_debug("Command line is: %s\n", cmd_line); | ||
536 | |||
537 | /* break now */ | ||
538 | return 1; | ||
539 | } | ||
540 | |||
541 | /** | ||
542 | * unflatten_device_tree - create tree of device_nodes from flat blob | ||
543 | * | ||
544 | * unflattens the device-tree passed by the firmware, creating the | ||
545 | * tree of struct device_node. It also fills the "name" and "type" | ||
546 | * pointers of the nodes so the normal device-tree walking functions | ||
547 | * can be used. | ||
548 | */ | ||
549 | void __init unflatten_device_tree(void) | ||
550 | { | ||
551 | unsigned long start, mem, size; | ||
552 | struct device_node **allnextp = &allnodes; | ||
553 | |||
554 | pr_debug(" -> unflatten_device_tree()\n"); | ||
555 | |||
556 | /* First pass, scan for size */ | ||
557 | start = ((unsigned long)initial_boot_params) + | ||
558 | be32_to_cpu(initial_boot_params->off_dt_struct); | ||
559 | size = unflatten_dt_node(0, &start, NULL, NULL, 0); | ||
560 | size = (size | 3) + 1; | ||
561 | |||
562 | pr_debug(" size is %lx, allocating...\n", size); | ||
563 | |||
564 | /* Allocate memory for the expanded device tree */ | ||
565 | mem = early_init_dt_alloc_memory_arch(size + 4, | ||
566 | __alignof__(struct device_node)); | ||
567 | mem = (unsigned long) __va(mem); | ||
568 | |||
569 | ((__be32 *)mem)[size / 4] = cpu_to_be32(0xdeadbeef); | ||
570 | |||
571 | pr_debug(" unflattening %lx...\n", mem); | ||
572 | |||
573 | /* Second pass, do actual unflattening */ | ||
574 | start = ((unsigned long)initial_boot_params) + | ||
575 | be32_to_cpu(initial_boot_params->off_dt_struct); | ||
576 | unflatten_dt_node(mem, &start, NULL, &allnextp, 0); | ||
577 | if (be32_to_cpup((__be32 *)start) != OF_DT_END) | ||
578 | pr_warning("Weird tag at end of tree: %08x\n", *((u32 *)start)); | ||
579 | if (be32_to_cpu(((__be32 *)mem)[size / 4]) != 0xdeadbeef) | ||
580 | pr_warning("End of tree marker overwritten: %08x\n", | ||
581 | be32_to_cpu(((__be32 *)mem)[size / 4])); | ||
582 | *allnextp = NULL; | ||
583 | |||
584 | /* Get pointer to OF "/chosen" node for use everywhere */ | ||
585 | of_chosen = of_find_node_by_path("/chosen"); | ||
586 | if (of_chosen == NULL) | ||
587 | of_chosen = of_find_node_by_path("/chosen@0"); | ||
588 | |||
589 | pr_debug(" <- unflatten_device_tree()\n"); | ||
590 | } | ||
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c index 6eea601a9204..24c3606217f8 100644 --- a/drivers/of/gpio.c +++ b/drivers/of/gpio.c | |||
@@ -36,7 +36,7 @@ int of_get_gpio_flags(struct device_node *np, int index, | |||
36 | struct of_gpio_chip *of_gc = NULL; | 36 | struct of_gpio_chip *of_gc = NULL; |
37 | int size; | 37 | int size; |
38 | const void *gpio_spec; | 38 | const void *gpio_spec; |
39 | const u32 *gpio_cells; | 39 | const __be32 *gpio_cells; |
40 | 40 | ||
41 | ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index, | 41 | ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index, |
42 | &gc, &gpio_spec); | 42 | &gc, &gpio_spec); |
@@ -55,7 +55,7 @@ int of_get_gpio_flags(struct device_node *np, int index, | |||
55 | 55 | ||
56 | gpio_cells = of_get_property(gc, "#gpio-cells", &size); | 56 | gpio_cells = of_get_property(gc, "#gpio-cells", &size); |
57 | if (!gpio_cells || size != sizeof(*gpio_cells) || | 57 | if (!gpio_cells || size != sizeof(*gpio_cells) || |
58 | *gpio_cells != of_gc->gpio_cells) { | 58 | be32_to_cpup(gpio_cells) != of_gc->gpio_cells) { |
59 | pr_debug("%s: wrong #gpio-cells for %s\n", | 59 | pr_debug("%s: wrong #gpio-cells for %s\n", |
60 | np->full_name, gc->full_name); | 60 | np->full_name, gc->full_name); |
61 | ret = -EINVAL; | 61 | ret = -EINVAL; |
@@ -127,7 +127,8 @@ EXPORT_SYMBOL(of_gpio_count); | |||
127 | int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np, | 127 | int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np, |
128 | const void *gpio_spec, enum of_gpio_flags *flags) | 128 | const void *gpio_spec, enum of_gpio_flags *flags) |
129 | { | 129 | { |
130 | const u32 *gpio = gpio_spec; | 130 | const __be32 *gpio = gpio_spec; |
131 | const u32 n = be32_to_cpup(gpio); | ||
131 | 132 | ||
132 | /* | 133 | /* |
133 | * We're discouraging gpio_cells < 2, since that way you'll have to | 134 | * We're discouraging gpio_cells < 2, since that way you'll have to |
@@ -140,13 +141,13 @@ int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np, | |||
140 | return -EINVAL; | 141 | return -EINVAL; |
141 | } | 142 | } |
142 | 143 | ||
143 | if (*gpio > of_gc->gc.ngpio) | 144 | if (n > of_gc->gc.ngpio) |
144 | return -EINVAL; | 145 | return -EINVAL; |
145 | 146 | ||
146 | if (flags) | 147 | if (flags) |
147 | *flags = gpio[1]; | 148 | *flags = be32_to_cpu(gpio[1]); |
148 | 149 | ||
149 | return *gpio; | 150 | return n; |
150 | } | 151 | } |
151 | EXPORT_SYMBOL(of_gpio_simple_xlate); | 152 | EXPORT_SYMBOL(of_gpio_simple_xlate); |
152 | 153 | ||
diff --git a/drivers/of/of_i2c.c b/drivers/of/of_i2c.c index fa65a2b2ae2e..a3a708e590d0 100644 --- a/drivers/of/of_i2c.c +++ b/drivers/of/of_i2c.c | |||
@@ -25,7 +25,7 @@ void of_register_i2c_devices(struct i2c_adapter *adap, | |||
25 | for_each_child_of_node(adap_node, node) { | 25 | for_each_child_of_node(adap_node, node) { |
26 | struct i2c_board_info info = {}; | 26 | struct i2c_board_info info = {}; |
27 | struct dev_archdata dev_ad = {}; | 27 | struct dev_archdata dev_ad = {}; |
28 | const u32 *addr; | 28 | const __be32 *addr; |
29 | int len; | 29 | int len; |
30 | 30 | ||
31 | if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) | 31 | if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) |
@@ -40,7 +40,7 @@ void of_register_i2c_devices(struct i2c_adapter *adap, | |||
40 | 40 | ||
41 | info.irq = irq_of_parse_and_map(node, 0); | 41 | info.irq = irq_of_parse_and_map(node, 0); |
42 | 42 | ||
43 | info.addr = *addr; | 43 | info.addr = be32_to_cpup(addr); |
44 | 44 | ||
45 | dev_archdata_set_node(&dev_ad, node); | 45 | dev_archdata_set_node(&dev_ad, node); |
46 | info.archdata = &dev_ad; | 46 | info.archdata = &dev_ad; |
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index 4b22ba568b19..18ecae4a4375 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c | |||
@@ -51,7 +51,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) | |||
51 | 51 | ||
52 | /* Loop over the child nodes and register a phy_device for each one */ | 52 | /* Loop over the child nodes and register a phy_device for each one */ |
53 | for_each_child_of_node(np, child) { | 53 | for_each_child_of_node(np, child) { |
54 | const u32 *addr; | 54 | const __be32 *addr; |
55 | int len; | 55 | int len; |
56 | 56 | ||
57 | /* A PHY must have a reg property in the range [0-31] */ | 57 | /* A PHY must have a reg property in the range [0-31] */ |
@@ -68,7 +68,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) | |||
68 | mdio->irq[*addr] = PHY_POLL; | 68 | mdio->irq[*addr] = PHY_POLL; |
69 | } | 69 | } |
70 | 70 | ||
71 | phy = get_phy_device(mdio, *addr); | 71 | phy = get_phy_device(mdio, be32_to_cpup(addr)); |
72 | if (!phy) { | 72 | if (!phy) { |
73 | dev_err(&mdio->dev, "error probing PHY at address %i\n", | 73 | dev_err(&mdio->dev, "error probing PHY at address %i\n", |
74 | *addr); | 74 | *addr); |
@@ -160,7 +160,7 @@ struct phy_device *of_phy_connect_fixed_link(struct net_device *dev, | |||
160 | struct device_node *net_np; | 160 | struct device_node *net_np; |
161 | char bus_id[MII_BUS_ID_SIZE + 3]; | 161 | char bus_id[MII_BUS_ID_SIZE + 3]; |
162 | struct phy_device *phy; | 162 | struct phy_device *phy; |
163 | const u32 *phy_id; | 163 | const __be32 *phy_id; |
164 | int sz; | 164 | int sz; |
165 | 165 | ||
166 | if (!dev->dev.parent) | 166 | if (!dev->dev.parent) |
@@ -174,7 +174,7 @@ struct phy_device *of_phy_connect_fixed_link(struct net_device *dev, | |||
174 | if (!phy_id || sz < sizeof(*phy_id)) | 174 | if (!phy_id || sz < sizeof(*phy_id)) |
175 | return NULL; | 175 | return NULL; |
176 | 176 | ||
177 | sprintf(bus_id, PHY_ID_FMT, "0", phy_id[0]); | 177 | sprintf(bus_id, PHY_ID_FMT, "0", be32_to_cpu(phy_id[0])); |
178 | 178 | ||
179 | phy = phy_connect(dev, bus_id, hndlr, 0, iface); | 179 | phy = phy_connect(dev, bus_id, hndlr, 0, iface); |
180 | return IS_ERR(phy) ? NULL : phy; | 180 | return IS_ERR(phy) ? NULL : phy; |
diff --git a/drivers/of/of_spi.c b/drivers/of/of_spi.c index bed0ed6dcdc1..f65f48b98448 100644 --- a/drivers/of/of_spi.c +++ b/drivers/of/of_spi.c | |||
@@ -23,7 +23,7 @@ void of_register_spi_devices(struct spi_master *master, struct device_node *np) | |||
23 | { | 23 | { |
24 | struct spi_device *spi; | 24 | struct spi_device *spi; |
25 | struct device_node *nc; | 25 | struct device_node *nc; |
26 | const u32 *prop; | 26 | const __be32 *prop; |
27 | int rc; | 27 | int rc; |
28 | int len; | 28 | int len; |
29 | 29 | ||
@@ -54,7 +54,7 @@ void of_register_spi_devices(struct spi_master *master, struct device_node *np) | |||
54 | spi_dev_put(spi); | 54 | spi_dev_put(spi); |
55 | continue; | 55 | continue; |
56 | } | 56 | } |
57 | spi->chip_select = *prop; | 57 | spi->chip_select = be32_to_cpup(prop); |
58 | 58 | ||
59 | /* Mode (clock phase/polarity/etc.) */ | 59 | /* Mode (clock phase/polarity/etc.) */ |
60 | if (of_find_property(nc, "spi-cpha", NULL)) | 60 | if (of_find_property(nc, "spi-cpha", NULL)) |
@@ -72,7 +72,7 @@ void of_register_spi_devices(struct spi_master *master, struct device_node *np) | |||
72 | spi_dev_put(spi); | 72 | spi_dev_put(spi); |
73 | continue; | 73 | continue; |
74 | } | 74 | } |
75 | spi->max_speed_hz = *prop; | 75 | spi->max_speed_hz = be32_to_cpup(prop); |
76 | 76 | ||
77 | /* IRQ */ | 77 | /* IRQ */ |
78 | spi->irq = irq_of_parse_and_map(nc, 0); | 78 | spi->irq = irq_of_parse_and_map(nc, 0); |