]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/rockchip/rk30xx_gpio.c
Merge latest (commit c8c1b3a77934768c7f7a4a9c10140c8bec529059) files
[FreeBSD/FreeBSD.git] / sys / arm / rockchip / rk30xx_gpio.c
1 /*-
2  * Copyright (c) 2013 Ganbold Tsagaankhuu <ganbold@freebsd.org>
3  * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
4  * Copyright (c) 2012 Luiz Otavio O Souza.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  */
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/bus.h>
35
36 #include <sys/kernel.h>
37 #include <sys/module.h>
38 #include <sys/rman.h>
39 #include <sys/lock.h>
40 #include <sys/mutex.h>
41 #include <sys/gpio.h>
42
43 #include <machine/bus.h>
44 #include <machine/cpu.h>
45 #include <machine/cpufunc.h>
46 #include <machine/resource.h>
47 #include <machine/fdt.h>
48 #include <machine/intr.h>
49
50 #include <dev/fdt/fdt_common.h>
51 #include <dev/gpio/gpiobusvar.h>
52 #include <dev/ofw/ofw_bus.h>
53 #include <dev/ofw/ofw_bus_subr.h>
54
55 #include "gpio_if.h"
56
57 #include "rk30xx_grf.h"
58 #include "rk30xx_pmu.h"
59
60 /*
61  * RK3188 has 4 banks of gpio.
62  * 32 pins per bank
63  * PA0 - PA7 | PB0 - PB7
64  * PC0 - PC7 | PD0 - PD7
65  */
66
67 #define RK30_GPIO_PINS          32
68 #define RK30_GPIO_DEFAULT_CAPS  (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT | \
69     GPIO_PIN_PULLUP | GPIO_PIN_PULLDOWN)
70
71 #define RK30_GPIO_NONE                  0
72 #define RK30_GPIO_PULLUP                1
73 #define RK30_GPIO_PULLDOWN              2
74
75 struct rk30_gpio_softc {
76         device_t                sc_dev;
77         device_t                sc_busdev;
78         struct mtx              sc_mtx;
79         struct resource *       sc_mem_res;
80         struct resource *       sc_irq_res;
81         bus_space_tag_t         sc_bst;
82         bus_space_handle_t      sc_bsh;
83         void *                  sc_intrhand;
84         int                     sc_bank;
85         int                     sc_gpio_npins;
86         struct gpio_pin         sc_gpio_pins[RK30_GPIO_PINS];
87 };
88
89 /* We use our base address to find out our bank number. */
90 static unsigned long rk30_gpio_base_addr[4] =
91         { 0x2000a000, 0x2003c000, 0x2003e000, 0x20080000 };
92 static struct rk30_gpio_softc *rk30_gpio_sc = NULL;
93
94 typedef int (*gpios_phandler_t)(phandle_t, pcell_t *, int);
95
96 struct gpio_ctrl_entry {
97         const char              *compat;
98         gpios_phandler_t        handler;
99 };
100
101 int rk30_gpios_prop_handle(phandle_t ctrl, pcell_t *gpios, int len);
102 static int rk30_gpio_init(void);
103
104 struct gpio_ctrl_entry gpio_controllers[] = {
105         { "rockchip,rk30xx-gpio", &rk30_gpios_prop_handle },
106         { "rockchip,rk30xx-gpio", &rk30_gpios_prop_handle },
107         { "rockchip,rk30xx-gpio", &rk30_gpios_prop_handle },
108         { "rockchip,rk30xx-gpio", &rk30_gpios_prop_handle },
109         { NULL, NULL }
110 };
111
112 #define RK30_GPIO_LOCK(_sc)             mtx_lock(&_sc->sc_mtx)
113 #define RK30_GPIO_UNLOCK(_sc)           mtx_unlock(&_sc->sc_mtx)
114 #define RK30_GPIO_LOCK_ASSERT(_sc)      mtx_assert(&_sc->sc_mtx, MA_OWNED)
115
116 #define RK30_GPIO_SWPORT_DR             0x00
117 #define RK30_GPIO_SWPORT_DDR            0x04
118 #define RK30_GPIO_INTEN                 0x30
119 #define RK30_GPIO_INTMASK               0x34
120 #define RK30_GPIO_INTTYPE_LEVEL         0x38
121 #define RK30_GPIO_INT_POLARITY          0x3c
122 #define RK30_GPIO_INT_STATUS            0x40
123 #define RK30_GPIO_INT_RAWSTATUS         0x44
124 #define RK30_GPIO_DEBOUNCE              0x48
125 #define RK30_GPIO_PORT_EOI              0x4c
126 #define RK30_GPIO_EXT_PORT              0x50
127 #define RK30_GPIO_LS_SYNC               0x60
128
129 #define RK30_GPIO_WRITE(_sc, _off, _val)                \
130     bus_space_write_4(_sc->sc_bst, _sc->sc_bsh, _off, _val)
131 #define RK30_GPIO_READ(_sc, _off)                       \
132     bus_space_read_4(_sc->sc_bst, _sc->sc_bsh, _off)
133
134 static uint32_t
135 rk30_gpio_get_function(struct rk30_gpio_softc *sc, uint32_t pin)
136 {
137
138         if (RK30_GPIO_READ(sc, RK30_GPIO_SWPORT_DDR) & (1U << pin))
139                 return (GPIO_PIN_OUTPUT);
140         else
141                 return (GPIO_PIN_INPUT);
142 }
143
144 static void
145 rk30_gpio_set_function(struct rk30_gpio_softc *sc, uint32_t pin, uint32_t func)
146 {
147         uint32_t data;
148
149         /* Must be called with lock held. */
150         RK30_GPIO_LOCK_ASSERT(sc);
151         data = RK30_GPIO_READ(sc, RK30_GPIO_SWPORT_DDR);
152         if (func == GPIO_PIN_OUTPUT)
153                 data |= (1U << pin);
154         else
155                 data &= ~(1U << pin);
156         RK30_GPIO_WRITE(sc, RK30_GPIO_SWPORT_DDR, data);
157 }
158
159 static void
160 rk30_gpio_set_pud(struct rk30_gpio_softc *sc, uint32_t pin, uint32_t state)
161 {
162         uint32_t pud;
163
164         /* Must be called with lock held. */
165         RK30_GPIO_LOCK_ASSERT(sc);
166         switch (state) {
167         case GPIO_PIN_PULLUP:
168                 pud = RK30_GPIO_PULLUP;
169                 break;
170         case GPIO_PIN_PULLDOWN:
171                 pud = RK30_GPIO_PULLDOWN;
172                 break;
173         default:
174                 pud = RK30_GPIO_NONE;
175         }
176         /*
177          * The pull up/down registers for GPIO0A and half of GPIO0B
178          * (the first 12 pins on bank 0) are at a different location.
179          */
180         if (sc->sc_bank == 0 && pin < 12)
181                 rk30_pmu_gpio_pud(pin, pud);
182         else
183                 rk30_grf_gpio_pud(sc->sc_bank, pin, pud);
184 }
185
186 static void
187 rk30_gpio_pin_configure(struct rk30_gpio_softc *sc, struct gpio_pin *pin,
188     unsigned int flags)
189 {
190
191         RK30_GPIO_LOCK(sc);
192         /*
193          * Manage input/output.
194          */
195         if (flags & (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT)) {
196                 pin->gp_flags &= ~(GPIO_PIN_INPUT | GPIO_PIN_OUTPUT);
197                 if (flags & GPIO_PIN_OUTPUT)
198                         pin->gp_flags |= GPIO_PIN_OUTPUT;
199                 else
200                         pin->gp_flags |= GPIO_PIN_INPUT;
201                 rk30_gpio_set_function(sc, pin->gp_pin, pin->gp_flags);
202         }
203         /* Manage Pull-up/pull-down. */
204         pin->gp_flags &= ~(GPIO_PIN_PULLUP | GPIO_PIN_PULLDOWN);
205         if (flags & (GPIO_PIN_PULLUP | GPIO_PIN_PULLDOWN)) {
206                 if (flags & GPIO_PIN_PULLUP)
207                         pin->gp_flags |= GPIO_PIN_PULLUP;
208                 else
209                         pin->gp_flags |= GPIO_PIN_PULLDOWN;
210         }
211         rk30_gpio_set_pud(sc, pin->gp_pin, pin->gp_flags);
212         RK30_GPIO_UNLOCK(sc);
213 }
214
215 static device_t
216 rk30_gpio_get_bus(device_t dev)
217 {
218         struct rk30_gpio_softc *sc;
219
220         sc = device_get_softc(dev);
221
222         return (sc->sc_busdev);
223 }
224
225 static int
226 rk30_gpio_pin_max(device_t dev, int *maxpin)
227 {
228
229         *maxpin = RK30_GPIO_PINS - 1;
230         return (0);
231 }
232
233 static int
234 rk30_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps)
235 {
236         struct rk30_gpio_softc *sc = device_get_softc(dev);
237         int i;
238
239         for (i = 0; i < sc->sc_gpio_npins; i++) {
240                 if (sc->sc_gpio_pins[i].gp_pin == pin)
241                         break;
242         }
243
244         if (i >= sc->sc_gpio_npins)
245                 return (EINVAL);
246
247         RK30_GPIO_LOCK(sc);
248         *caps = sc->sc_gpio_pins[i].gp_caps;
249         RK30_GPIO_UNLOCK(sc);
250
251         return (0);
252 }
253
254 static int
255 rk30_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags)
256 {
257         struct rk30_gpio_softc *sc = device_get_softc(dev);
258         int i;
259
260         for (i = 0; i < sc->sc_gpio_npins; i++) {
261                 if (sc->sc_gpio_pins[i].gp_pin == pin)
262                         break;
263         }
264
265         if (i >= sc->sc_gpio_npins)
266                 return (EINVAL);
267
268         RK30_GPIO_LOCK(sc);
269         *flags = sc->sc_gpio_pins[i].gp_flags;
270         RK30_GPIO_UNLOCK(sc);
271
272         return (0);
273 }
274
275 static int
276 rk30_gpio_pin_getname(device_t dev, uint32_t pin, char *name)
277 {
278         struct rk30_gpio_softc *sc = device_get_softc(dev);
279         int i;
280
281         for (i = 0; i < sc->sc_gpio_npins; i++) {
282                 if (sc->sc_gpio_pins[i].gp_pin == pin)
283                         break;
284         }
285
286         if (i >= sc->sc_gpio_npins)
287                 return (EINVAL);
288
289         RK30_GPIO_LOCK(sc);
290         memcpy(name, sc->sc_gpio_pins[i].gp_name, GPIOMAXNAME);
291         RK30_GPIO_UNLOCK(sc);
292
293         return (0);
294 }
295
296 static int
297 rk30_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags)
298 {
299         struct rk30_gpio_softc *sc = device_get_softc(dev);
300         int i;
301
302         for (i = 0; i < sc->sc_gpio_npins; i++) {
303                 if (sc->sc_gpio_pins[i].gp_pin == pin)
304                         break;
305         }
306
307         if (i >= sc->sc_gpio_npins)
308                 return (EINVAL);
309
310         rk30_gpio_pin_configure(sc, &sc->sc_gpio_pins[i], flags);
311
312         return (0);
313 }
314
315 static int
316 rk30_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value)
317 {
318         int i;
319         struct rk30_gpio_softc *sc;
320         uint32_t data;
321
322         sc = device_get_softc(dev);
323         for (i = 0; i < sc->sc_gpio_npins; i++) {
324                 if (sc->sc_gpio_pins[i].gp_pin == pin)
325                         break;
326         }
327         if (i >= sc->sc_gpio_npins)
328                 return (EINVAL);
329         RK30_GPIO_LOCK(sc);
330         data = RK30_GPIO_READ(sc, RK30_GPIO_SWPORT_DR);
331         if (value)
332                 data |= (1U << pin);
333         else
334                 data &= ~(1U << pin);
335         RK30_GPIO_WRITE(sc, RK30_GPIO_SWPORT_DR, data);
336         RK30_GPIO_UNLOCK(sc);
337
338         return (0);
339 }
340
341 static int
342 rk30_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val)
343 {
344         int i;
345         struct rk30_gpio_softc *sc;
346         uint32_t data;
347
348         sc = device_get_softc(dev);
349         for (i = 0; i < sc->sc_gpio_npins; i++) {
350                 if (sc->sc_gpio_pins[i].gp_pin == pin)
351                         break;
352         }
353         if (i >= sc->sc_gpio_npins)
354                 return (EINVAL);
355         RK30_GPIO_LOCK(sc);
356         data = RK30_GPIO_READ(sc, RK30_GPIO_EXT_PORT);
357         RK30_GPIO_UNLOCK(sc);
358         *val = (data & (1U << pin)) ? 1 : 0;
359
360         return (0);
361 }
362
363 static int
364 rk30_gpio_pin_toggle(device_t dev, uint32_t pin)
365 {
366         int i;
367         struct rk30_gpio_softc *sc;
368         uint32_t data;
369
370         sc = device_get_softc(dev);
371         for (i = 0; i < sc->sc_gpio_npins; i++) {
372                 if (sc->sc_gpio_pins[i].gp_pin == pin)
373                         break;
374         }
375         if (i >= sc->sc_gpio_npins)
376                 return (EINVAL);
377         RK30_GPIO_LOCK(sc);
378         data = RK30_GPIO_READ(sc, RK30_GPIO_SWPORT_DR);
379         if (data & (1U << pin))
380                 data &= ~(1U << pin);
381         else
382                 data |= (1U << pin);
383         RK30_GPIO_WRITE(sc, RK30_GPIO_SWPORT_DR, data);
384         RK30_GPIO_UNLOCK(sc);
385
386         return (0);
387 }
388
389 static int
390 rk30_gpio_probe(device_t dev)
391 {
392
393         if (!ofw_bus_status_okay(dev))
394                 return (ENXIO);
395
396         if (!ofw_bus_is_compatible(dev, "rockchip,rk30xx-gpio"))
397                 return (ENXIO);
398
399         device_set_desc(dev, "Rockchip RK30XX GPIO controller");
400         return (BUS_PROBE_DEFAULT);
401 }
402
403 static int
404 rk30_gpio_attach(device_t dev)
405 {
406         struct rk30_gpio_softc *sc = device_get_softc(dev);
407         int i, rid;
408         phandle_t gpio;
409         unsigned long start;
410
411         if (rk30_gpio_sc)
412                 return (ENXIO);
413         sc->sc_dev = dev;
414         mtx_init(&sc->sc_mtx, "rk30 gpio", "gpio", MTX_DEF);
415
416         rid = 0;
417         sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
418             RF_ACTIVE);
419         if (!sc->sc_mem_res) {
420                 device_printf(dev, "cannot allocate memory window\n");
421                 goto fail;
422         }
423         sc->sc_bst = rman_get_bustag(sc->sc_mem_res);
424         sc->sc_bsh = rman_get_bushandle(sc->sc_mem_res);
425         /* Check the unit we are attaching by our base address. */
426         sc->sc_bank = -1;
427         start = rman_get_start(sc->sc_mem_res);
428         for (i = 0; i < nitems(rk30_gpio_base_addr); i++) {
429                 if (rk30_gpio_base_addr[i] == start) {
430                         sc->sc_bank = i;
431                         break;
432                 }
433         }
434         if (sc->sc_bank == -1) {
435                 device_printf(dev,
436                     "unsupported device unit (only GPIO0..3 are supported)\n");
437                 goto fail;
438         }
439
440         rid = 0;
441         sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
442             RF_ACTIVE);
443         if (!sc->sc_irq_res) {
444                 device_printf(dev, "cannot allocate interrupt\n");
445                 goto fail;
446         }
447
448         /* Find our node. */
449         gpio = ofw_bus_get_node(sc->sc_dev);
450
451         if (!OF_hasprop(gpio, "gpio-controller"))
452                 /* Node is not a GPIO controller. */
453                 goto fail;
454
455         /* Initialize the software controlled pins. */
456         for (i = 0; i < RK30_GPIO_PINS; i++) {
457                 snprintf(sc->sc_gpio_pins[i].gp_name, GPIOMAXNAME,
458                     "pin %d", i);
459                 sc->sc_gpio_pins[i].gp_pin = i;
460                 sc->sc_gpio_pins[i].gp_caps = RK30_GPIO_DEFAULT_CAPS;
461                 sc->sc_gpio_pins[i].gp_flags = rk30_gpio_get_function(sc, i);
462         }
463         sc->sc_gpio_npins = i;
464         rk30_gpio_sc = sc;
465         rk30_gpio_init();
466         sc->sc_busdev = gpiobus_attach_bus(dev);
467         if (sc->sc_busdev == NULL)
468                 goto fail;
469
470         return (0);
471
472 fail:
473         if (sc->sc_irq_res)
474                 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res);
475         if (sc->sc_mem_res)
476                 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res);
477         mtx_destroy(&sc->sc_mtx);
478
479         return (ENXIO);
480 }
481
482 static int
483 rk30_gpio_detach(device_t dev)
484 {
485
486         return (EBUSY);
487 }
488
489 static device_method_t rk30_gpio_methods[] = {
490         /* Device interface */
491         DEVMETHOD(device_probe,         rk30_gpio_probe),
492         DEVMETHOD(device_attach,        rk30_gpio_attach),
493         DEVMETHOD(device_detach,        rk30_gpio_detach),
494
495         /* GPIO protocol */
496         DEVMETHOD(gpio_get_bus,         rk30_gpio_get_bus),
497         DEVMETHOD(gpio_pin_max,         rk30_gpio_pin_max),
498         DEVMETHOD(gpio_pin_getname,     rk30_gpio_pin_getname),
499         DEVMETHOD(gpio_pin_getflags,    rk30_gpio_pin_getflags),
500         DEVMETHOD(gpio_pin_getcaps,     rk30_gpio_pin_getcaps),
501         DEVMETHOD(gpio_pin_setflags,    rk30_gpio_pin_setflags),
502         DEVMETHOD(gpio_pin_get,         rk30_gpio_pin_get),
503         DEVMETHOD(gpio_pin_set,         rk30_gpio_pin_set),
504         DEVMETHOD(gpio_pin_toggle,      rk30_gpio_pin_toggle),
505
506         DEVMETHOD_END
507 };
508
509 static devclass_t rk30_gpio_devclass;
510
511 static driver_t rk30_gpio_driver = {
512         "gpio",
513         rk30_gpio_methods,
514         sizeof(struct rk30_gpio_softc),
515 };
516
517 DRIVER_MODULE(rk30_gpio, simplebus, rk30_gpio_driver, rk30_gpio_devclass, 0, 0);
518
519 int
520 rk30_gpios_prop_handle(phandle_t ctrl, pcell_t *gpios, int len)
521 {
522         struct rk30_gpio_softc *sc;
523         pcell_t gpio_cells;
524         int inc, t, tuples, tuple_size;
525         int dir, flags, pin, i;
526         u_long gpio_ctrl, size;
527
528         sc = rk30_gpio_sc;
529         if (sc == NULL)
530                 return ENXIO;
531
532         if (OF_getprop(ctrl, "#gpio-cells", &gpio_cells, sizeof(pcell_t)) < 0)
533                 return (ENXIO);
534
535         gpio_cells = fdt32_to_cpu(gpio_cells);
536         if (gpio_cells != 2)
537                 return (ENXIO);
538
539         tuple_size = gpio_cells * sizeof(pcell_t) + sizeof(phandle_t);
540         tuples = len / tuple_size;
541
542         if (fdt_regsize(ctrl, &gpio_ctrl, &size))
543                 return (ENXIO);
544
545         /*
546          * Skip controller reference, since controller's phandle is given
547          * explicitly (in a function argument).
548          */
549         inc = sizeof(ihandle_t) / sizeof(pcell_t);
550         gpios += inc;
551         for (t = 0; t < tuples; t++) {
552                 pin = fdt32_to_cpu(gpios[0]);
553                 dir = fdt32_to_cpu(gpios[1]);
554                 flags = fdt32_to_cpu(gpios[2]);
555
556                 for (i = 0; i < sc->sc_gpio_npins; i++) {
557                         if (sc->sc_gpio_pins[i].gp_pin == pin)
558                                 break;
559                 }
560                 if (i >= sc->sc_gpio_npins)
561                         return (EINVAL);
562
563                 rk30_gpio_pin_configure(sc, &sc->sc_gpio_pins[i], flags);
564
565                 if (dir == 1) {
566                         /* Input. */
567                         rk30_gpio_pin_set(sc->sc_dev, pin, GPIO_PIN_INPUT);
568                 } else {
569                         /* Output. */
570                         rk30_gpio_pin_set(sc->sc_dev, pin, GPIO_PIN_OUTPUT);
571                 }
572                 gpios += gpio_cells + inc;
573         }
574
575         return (0);
576 }
577
578 #define MAX_PINS_PER_NODE       5
579 #define GPIOS_PROP_CELLS        4
580
581 static int
582 rk30_gpio_init(void)
583 {
584         phandle_t child, parent, root, ctrl;
585         pcell_t gpios[MAX_PINS_PER_NODE * GPIOS_PROP_CELLS];
586         struct gpio_ctrl_entry *e;
587         int len, rv;
588
589         root = OF_finddevice("/");
590         len = 0;
591         parent = root;
592
593         /* Traverse through entire tree to find nodes with 'gpios' prop */
594         for (child = OF_child(parent); child != 0; child = OF_peer(child)) {
595
596                 /* Find a 'leaf'. Start the search from this node. */
597                 while (OF_child(child)) {
598                         parent = child;
599                         child = OF_child(child);
600                 }
601                 if ((len = OF_getproplen(child, "gpios")) > 0) {
602
603                         if (len > sizeof(gpios))
604                                 return (ENXIO);
605
606                         /* Get 'gpios' property. */
607                         OF_getprop(child, "gpios", &gpios, len);
608
609                         e = (struct gpio_ctrl_entry *)&gpio_controllers;
610
611                         /* Find and call a handler. */
612                         for (; e->compat; e++) {
613                                 /*
614                                  * First cell of 'gpios' property should
615                                  * contain a ref. to a node defining GPIO
616                                  * controller.
617                                  */
618                                 ctrl = OF_node_from_xref(fdt32_to_cpu(gpios[0]));
619
620                                 if (fdt_is_compatible(ctrl, e->compat))
621                                         /* Call a handler. */
622                                         if ((rv = e->handler(ctrl,
623                                             (pcell_t *)&gpios, len)))
624                                                 return (rv);
625                         }
626                 }
627
628                 if (OF_peer(child) == 0) {
629                         /* No more siblings. */
630                         child = parent;
631                         parent = OF_parent(child);
632                 }
633         }
634         return (0);
635 }