diff options
author | Jeremy Kerr <jeremy.kerr@canonical.com> | 2010-01-30 03:45:26 -0500 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2010-02-09 10:34:10 -0500 |
commit | 337148812f97368a8ec4a69f1691e4c5ce3af494 (patch) | |
tree | 3fa2e5477c657cb2ebc40db9182d0989a5d60e13 /drivers/of/gpio.c | |
parent | 2e89e685a8fd0e8334de967739d11e2e28c1a4dd (diff) |
of: assume big-endian properties, adding conversions where necessary
Properties in the device tree are specified as big-endian. At present,
the only platforms to support device trees are also big-endian, so we've
been acessing the properties as raw values.
We'd like to add device tree support to little-endian platforms too, so
add endian conversion to the sites where we access property values in
the common of code.
Compiled on powerpc (ppc44x_defconfig & ppc64_defconfig) and arm (fdt
support only for now).
Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/of/gpio.c')
-rw-r--r-- | drivers/of/gpio.c | 13 |
1 files changed, 7 insertions, 6 deletions
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 | ||