Commit 3a57123e598ea46fc88a8e29e6932eba02d4ac5f

Authored by Simon Glass
1 parent 6fb2f57916

dm: gpio: Refactor to prepare for live tree support

Move the main part of the GPIO request function into a separate function
so that it can be used by the live tree function when added. Update the
xlate method to use a node reference.

Update all GPIO drivers to handle the modified xlate() method.

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 8 changed files with 41 additions and 29 deletions Side-by-side Diff

drivers/gpio/74x164_gpio.c
... ... @@ -106,7 +106,7 @@
106 106 }
107 107  
108 108 static int gen_74x164_xlate(struct udevice *dev, struct gpio_desc *desc,
109   - struct fdtdec_phandle_args *args)
  109 + struct ofnode_phandle_args *args)
110 110 {
111 111 desc->offset = args->args[0];
112 112 desc->flags = args->args[1] & GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0;
drivers/gpio/gpio-uclass.c
... ... @@ -114,9 +114,8 @@
114 114 return 0;
115 115 }
116 116  
117   -int gpio_xlate_offs_flags(struct udevice *dev,
118   - struct gpio_desc *desc,
119   - struct fdtdec_phandle_args *args)
  117 +int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
  118 + struct ofnode_phandle_args *args)
120 119 {
121 120 if (args->args_count < 1)
122 121 return -EINVAL;
... ... @@ -133,7 +132,7 @@
133 132 }
134 133  
135 134 static int gpio_find_and_xlate(struct gpio_desc *desc,
136   - struct fdtdec_phandle_args *args)
  135 + struct ofnode_phandle_args *args)
137 136 {
138 137 struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
139 138  
140 139  
141 140  
142 141  
143 142  
144 143  
145 144  
... ... @@ -642,37 +641,30 @@
642 641 return vector;
643 642 }
644 643  
645   -static int _gpio_request_by_name_nodev(const void *blob, int node,
646   - const char *list_name, int index,
647   - struct gpio_desc *desc, int flags,
648   - bool add_index)
  644 +static int gpio_request_tail(int ret, ofnode node,
  645 + struct ofnode_phandle_args *args,
  646 + const char *list_name, int index,
  647 + struct gpio_desc *desc, int flags, bool add_index)
649 648 {
650   - struct fdtdec_phandle_args args;
651   - int ret;
652   -
653 649 desc->dev = NULL;
654 650 desc->offset = 0;
655 651 desc->flags = 0;
656   - ret = fdtdec_parse_phandle_with_args(blob, node, list_name,
657   - "#gpio-cells", 0, index, &args);
658   - if (ret) {
659   - debug("%s: fdtdec_parse_phandle_with_args failed\n", __func__);
  652 + if (ret)
660 653 goto err;
661   - }
662 654  
663   - ret = uclass_get_device_by_of_offset(UCLASS_GPIO, args.node,
664   - &desc->dev);
  655 + ret = uclass_get_device_by_ofnode(UCLASS_GPIO, args->node,
  656 + &desc->dev);
665 657 if (ret) {
666 658 debug("%s: uclass_get_device_by_of_offset failed\n", __func__);
667 659 goto err;
668 660 }
669   - ret = gpio_find_and_xlate(desc, &args);
  661 + ret = gpio_find_and_xlate(desc, args);
670 662 if (ret) {
671 663 debug("%s: gpio_find_and_xlate failed\n", __func__);
672 664 goto err;
673 665 }
674 666 ret = dm_gpio_requestf(desc, add_index ? "%s.%s%d" : "%s.%s",
675   - fdt_get_name(blob, node, NULL),
  667 + ofnode_get_name(node),
676 668 list_name, index);
677 669 if (ret) {
678 670 debug("%s: dm_gpio_requestf failed\n", __func__);
679 671  
... ... @@ -687,8 +679,25 @@
687 679 return 0;
688 680 err:
689 681 debug("%s: Node '%s', property '%s', failed to request GPIO index %d: %d\n",
690   - __func__, fdt_get_name(blob, node, NULL), list_name, index, ret);
  682 + __func__, ofnode_get_name(node), list_name, index, ret);
691 683 return ret;
  684 +}
  685 +
  686 +static int _gpio_request_by_name_nodev(const void *blob, int node,
  687 + const char *list_name, int index,
  688 + struct gpio_desc *desc, int flags,
  689 + bool add_index)
  690 +{
  691 + struct ofnode_phandle_args args;
  692 + int ret;
  693 +
  694 + ret = ofnode_parse_phandle_with_args(offset_to_ofnode(node), list_name,
  695 + "#gpio-cells", 0, index, &args);
  696 + if (ret)
  697 + debug("%s: fdtdec_parse_phandle_with_args failed\n", __func__);
  698 +
  699 + return gpio_request_tail(ret, offset_to_ofnode(node), &args, list_name,
  700 + index, desc, flags, add_index);
692 701 }
693 702  
694 703 int gpio_request_by_name_nodev(const void *blob, int node,
drivers/gpio/pca953x_gpio.c
... ... @@ -228,7 +228,7 @@
228 228 }
229 229  
230 230 static int pca953x_xlate(struct udevice *dev, struct gpio_desc *desc,
231   - struct fdtdec_phandle_args *args)
  231 + struct ofnode_phandle_args *args)
232 232 {
233 233 desc->offset = args->args[0];
234 234 desc->flags = args->args[1] & GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0;
drivers/gpio/sandbox.c
... ... @@ -8,6 +8,7 @@
8 8 #include <fdtdec.h>
9 9 #include <malloc.h>
10 10 #include <asm/gpio.h>
  11 +#include <dm/of.h>
11 12 #include <dt-bindings/gpio/gpio.h>
12 13  
13 14 DECLARE_GLOBAL_DATA_PTR;
... ... @@ -165,7 +166,7 @@
165 166 }
166 167  
167 168 static int sb_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
168   - struct fdtdec_phandle_args *args)
  169 + struct ofnode_phandle_args *args)
169 170 {
170 171 desc->offset = args->args[0];
171 172 if (args->args_count < 2)
drivers/gpio/sunxi_gpio.c
... ... @@ -217,7 +217,7 @@
217 217 }
218 218  
219 219 static int sunxi_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
220   - struct fdtdec_phandle_args *args)
  220 + struct ofnode_phandle_args *args)
221 221 {
222 222 int ret;
223 223  
drivers/gpio/tegra186_gpio.c
... ... @@ -139,7 +139,7 @@
139 139 }
140 140  
141 141 static int tegra186_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
142   - struct fdtdec_phandle_args *args)
  142 + struct ofnode_phandle_args *args)
143 143 {
144 144 int gpio, port, ret;
145 145  
drivers/gpio/tegra_gpio.c
... ... @@ -236,7 +236,7 @@
236 236 }
237 237  
238 238 static int tegra_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
239   - struct fdtdec_phandle_args *args)
  239 + struct ofnode_phandle_args *args)
240 240 {
241 241 int gpio, port, ret;
242 242  
include/asm-generic/gpio.h
... ... @@ -7,6 +7,8 @@
7 7 #ifndef _ASM_GENERIC_GPIO_H_
8 8 #define _ASM_GENERIC_GPIO_H_
9 9  
  10 +struct ofnode_phandle_args;
  11 +
10 12 /*
11 13 * Generic GPIO API for U-Boot
12 14 *
... ... @@ -214,7 +216,7 @@
214 216 *
215 217 */
216 218 int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
217   - struct fdtdec_phandle_args *args);
  219 + struct ofnode_phandle_args *args);
218 220  
219 221 /**
220 222 * struct struct dm_gpio_ops - Driver model GPIO operations
... ... @@ -286,7 +288,7 @@
286 288 * @return 0 if OK, -ve on error
287 289 */
288 290 int (*xlate)(struct udevice *dev, struct gpio_desc *desc,
289   - struct fdtdec_phandle_args *args);
  291 + struct ofnode_phandle_args *args);
290 292 };
291 293  
292 294 /**