]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/mips/mediatek/mtk_gpio_v1.c
Import to 0.6.1
[FreeBSD/FreeBSD.git] / sys / mips / mediatek / mtk_gpio_v1.c
1 /*-
2  * Copyright 2016 Stanislav Galabov
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29         
30 #include "opt_platform.h"
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/conf.h>
35 #include <sys/bus.h>
36 #include <sys/kernel.h>
37 #include <sys/module.h>
38 #include <sys/lock.h>
39 #include <sys/mutex.h>
40 #include <sys/proc.h>
41 #include <sys/resource.h>
42 #include <sys/gpio.h>
43                 
44 #include <machine/bus.h>
45 #include <machine/intr.h>
46
47 #include <mips/mediatek/mtk_soc.h>
48                 
49 #include <dev/gpio/gpiobusvar.h>
50                 
51 #include <dev/fdt/fdt_common.h>
52 #include <dev/ofw/ofw_bus.h>
53 #include <dev/ofw/ofw_bus_subr.h>
54
55 #include <gnu/dts/include/dt-bindings/interrupt-controller/irq.h>
56
57 #include "gpio_if.h"
58 #include "pic_if.h"
59
60 #define MTK_GPIO_PINS 32
61
62 struct mtk_gpio_pin_irqsrc {
63         struct intr_irqsrc      isrc;
64         u_int                   irq;
65 };
66
67 struct mtk_gpio_pin {
68         uint32_t                        pin_caps;
69         uint32_t                        pin_flags;
70         enum intr_trigger               intr_trigger;
71         enum intr_polarity              intr_polarity;
72         char                            pin_name[GPIOMAXNAME];
73         struct mtk_gpio_pin_irqsrc      pin_irqsrc;
74 };
75
76 struct mtk_gpio_softc {
77         device_t                dev;
78         device_t                busdev;
79         struct resource         *res[2];
80         struct mtx              mtx;
81         struct mtk_gpio_pin     pins[MTK_GPIO_PINS];
82         void                    *intrhand;
83
84         uint32_t                num_pins;
85         uint8_t                 do_remap;
86 };
87
88 #define PIC_INTR_ISRC(sc, irq)  (&(sc)->pins[(irq)].pin_irqsrc.isrc)
89
90 static struct resource_spec mtk_gpio_spec[] = {
91         { SYS_RES_MEMORY, 0, RF_ACTIVE },
92         { SYS_RES_IRQ,    0, RF_ACTIVE | RF_SHAREABLE },
93         { -1, 0 }
94 };
95
96 static int mtk_gpio_probe(device_t dev);
97 static int mtk_gpio_attach(device_t dev);
98 static int mtk_gpio_detach(device_t dev);
99 static int mtk_gpio_intr(void *arg);
100
101 #define MTK_GPIO_LOCK(sc)               mtx_lock_spin(&(sc)->mtx)
102 #define MTK_GPIO_UNLOCK(sc)             mtx_unlock_spin(&(sc)->mtx)
103 #define MTK_GPIO_LOCK_INIT(sc)          \
104     mtx_init(&(sc)->mtx, device_get_nameunit((sc)->dev),        \
105     "mtk_gpio", MTX_SPIN)
106 #define MTK_GPIO_LOCK_DESTROY(sc)       mtx_destroy(&(sc)->mtx)
107
108 #define MTK_WRITE_4(sc, reg, val)       bus_write_4((sc)->res[0], (reg), (val))
109 #define MTK_READ_4(sc, reg)             bus_read_4((sc)->res[0], (reg))
110
111 /* Register definitions */
112 #define GPIO_PIOINT(_sc)                0x0000
113 #define GPIO_PIOEDGE(_sc)               0x0004
114 #define GPIO_PIORENA(_sc)               0x0008
115 #define GPIO_PIOFENA(_sc)               0x000C
116 #define GPIO_PIODATA(_sc)               ((_sc)->do_remap ? 0x0020 : 0x0010)
117 #define GPIO_PIODIR(_sc)                ((_sc)->do_remap ? 0x0024 : 0x0014)
118 #define GPIO_PIOPOL(_sc)                ((_sc)->do_remap ? 0x0028 : 0x0018)
119 #define GPIO_PIOSET(_sc)                ((_sc)->do_remap ? 0x002C : 0x001C)
120 #define GPIO_PIORESET(_sc)              ((_sc)->do_remap ? 0x0030 : 0x0020)
121 #define GPIO_PIOTOG(_sc)                ((_sc)->do_remap ? 0x0034 : 0x0024)
122
123 static struct ofw_compat_data compat_data[] = {
124         { "ralink,rt2880-gpio",         1 },
125         { "ralink,rt3050-gpio",         1 },
126         { "ralink,rt3352-gpio",         1 },
127         { "ralink,rt3883-gpio",         1 },
128         { "ralink,rt5350-gpio",         1 },
129         { "ralink,mt7620a-gpio",        1 },
130         { NULL,                         0 }
131 };
132
133 static int
134 mtk_gpio_probe(device_t dev)
135 {
136         phandle_t node;
137
138         if (!ofw_bus_status_okay(dev))
139                 return (ENXIO);
140
141         if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
142                 return (ENXIO);
143
144         node = ofw_bus_get_node(dev);
145         if (!OF_hasprop(node, "gpio-controller"))
146                 return (ENXIO);
147
148         device_set_desc(dev, "MTK GPIO Controller (v1)");
149
150         return (BUS_PROBE_DEFAULT);
151 }
152
153 static int
154 mtk_pic_register_isrcs(struct mtk_gpio_softc *sc)
155 {
156         int error;
157         uint32_t irq;
158         struct intr_irqsrc *isrc;
159         const char *name;
160
161         name = device_get_nameunit(sc->dev);
162         for (irq = 0; irq < sc->num_pins; irq++) {
163                 sc->pins[irq].pin_irqsrc.irq = irq;
164                 isrc = PIC_INTR_ISRC(sc, irq);
165                 error = intr_isrc_register(isrc, sc->dev, 0, "%s", name);
166                 if (error != 0) {
167                         /* XXX call intr_isrc_deregister */
168                         device_printf(sc->dev, "%s failed", __func__);
169                         return (error);
170                 }
171         }
172
173         return (0);
174 }
175
176 static int
177 mtk_gpio_pin_set_direction(struct mtk_gpio_softc *sc, uint32_t pin,
178     uint32_t dir)
179 {
180         uint32_t regval, mask = (1u << pin);
181
182         if (!(sc->pins[pin].pin_caps & dir))
183                 return (EINVAL);
184
185         regval = MTK_READ_4(sc, GPIO_PIODIR(sc));
186         if (dir == GPIO_PIN_INPUT)
187                 regval &= ~mask;
188         else
189                 regval |= mask;
190         MTK_WRITE_4(sc, GPIO_PIODIR(sc), regval);
191
192         sc->pins[pin].pin_flags &= ~(GPIO_PIN_INPUT | GPIO_PIN_OUTPUT);
193         sc->pins[pin].pin_flags |= dir;
194
195         return (0);
196 }
197
198 static int
199 mtk_gpio_pin_set_invert(struct mtk_gpio_softc *sc, uint32_t pin, uint32_t val)
200 {
201         uint32_t regval, mask = (1u << pin);
202
203         regval = MTK_READ_4(sc, GPIO_PIOPOL(sc));
204         if (val)
205                 regval |= mask;
206         else
207                 regval &= ~mask;
208         MTK_WRITE_4(sc, GPIO_PIOPOL(sc), regval);
209         sc->pins[pin].pin_flags &= ~(GPIO_PIN_INVIN | GPIO_PIN_INVOUT);
210         sc->pins[pin].pin_flags |= val;
211
212         return (0);
213 }
214
215 static void
216 mtk_gpio_pin_probe(struct mtk_gpio_softc *sc, uint32_t pin)
217 {
218         uint32_t mask = (1u << pin);
219         uint32_t val;
220
221         /* Clear cached gpio config */
222         sc->pins[pin].pin_flags = 0;
223
224         val = MTK_READ_4(sc, GPIO_PIORENA(sc)) |
225             MTK_READ_4(sc, GPIO_PIOFENA(sc));
226         if (val & mask) {
227                 /* Pin is in interrupt mode */
228                 sc->pins[pin].intr_trigger = INTR_TRIGGER_EDGE;
229                 val = MTK_READ_4(sc, GPIO_PIORENA(sc));
230                 if (val & mask)
231                         sc->pins[pin].intr_polarity = INTR_POLARITY_HIGH;
232                 else
233                         sc->pins[pin].intr_polarity = INTR_POLARITY_LOW;
234         }
235
236         val = MTK_READ_4(sc, GPIO_PIODIR(sc));
237         if (val & mask)
238                 sc->pins[pin].pin_flags |= GPIO_PIN_OUTPUT;
239         else
240                 sc->pins[pin].pin_flags |= GPIO_PIN_INPUT;
241
242         val = MTK_READ_4(sc, GPIO_PIOPOL(sc));
243         if (val & mask) {
244                 if (sc->pins[pin].pin_flags & GPIO_PIN_INPUT) {
245                         sc->pins[pin].pin_flags |= GPIO_PIN_INVIN;
246                 } else {
247                         sc->pins[pin].pin_flags |= GPIO_PIN_INVOUT;
248                 }
249         }
250 }
251
252 static int
253 mtk_gpio_attach(device_t dev)
254 {
255         struct mtk_gpio_softc *sc;
256         phandle_t node;
257         uint32_t i, num_pins;
258
259         sc = device_get_softc(dev);
260         sc->dev = dev;
261
262         if (bus_alloc_resources(dev, mtk_gpio_spec, sc->res)) {
263                 device_printf(dev, "could not allocate resources for device\n");
264                 return (ENXIO);
265         }
266
267         MTK_GPIO_LOCK_INIT(sc);
268
269         node = ofw_bus_get_node(dev);
270
271         if (OF_hasprop(node, "clocks"))
272                 mtk_soc_start_clock(dev);
273         if (OF_hasprop(node, "resets"))
274                 mtk_soc_reset_device(dev);
275
276         if (OF_hasprop(node, "mtk,register-gap")) {
277                 device_printf(dev, "<register gap>\n");
278                 sc->do_remap = 1;
279         } else {
280                 device_printf(dev, "<no register gap>\n");
281                 sc->do_remap = 0;
282         }
283
284         if (OF_hasprop(node, "ralink,num-gpios") && (OF_getencprop(node,
285             "ralink,num-gpios", &num_pins, sizeof(num_pins)) >= 0))
286                 sc->num_pins = num_pins;
287         else
288                 sc->num_pins = MTK_GPIO_PINS;
289
290         for (i = 0; i < num_pins; i++) {
291                 sc->pins[i].pin_caps |= GPIO_PIN_INPUT | GPIO_PIN_OUTPUT |
292                     GPIO_PIN_INVIN | GPIO_PIN_INVOUT;
293                 sc->pins[i].intr_polarity = INTR_POLARITY_HIGH;
294                 sc->pins[i].intr_trigger = INTR_TRIGGER_EDGE;
295
296                 snprintf(sc->pins[i].pin_name, GPIOMAXNAME - 1, "gpio%c%d",
297                     device_get_unit(dev) + 'a', i);
298                 sc->pins[i].pin_name[GPIOMAXNAME - 1] = '\0';
299
300                 mtk_gpio_pin_probe(sc, i);
301         }
302
303         if (mtk_pic_register_isrcs(sc) != 0) {
304                 device_printf(dev, "could not register PIC ISRCs\n");
305                 goto fail;
306         }
307
308         if (intr_pic_register(dev, OF_xref_from_node(node)) != 0) {
309                 device_printf(dev, "could not register PIC\n");
310                 goto fail;
311         }
312
313         if (bus_setup_intr(dev, sc->res[1], INTR_TYPE_MISC | INTR_MPSAFE,
314             mtk_gpio_intr, NULL, sc, &sc->intrhand) != 0)
315                 goto fail_pic;
316
317         sc->busdev = gpiobus_attach_bus(dev);
318         if (sc->busdev == NULL)
319                 goto fail_pic;
320
321         return (0);
322 fail_pic:
323         intr_pic_deregister(dev, OF_xref_from_node(node));
324 fail:
325         if(sc->intrhand != NULL)
326                 bus_teardown_intr(dev, sc->res[1], sc->intrhand);
327         bus_release_resources(dev, mtk_gpio_spec, sc->res);
328         MTK_GPIO_LOCK_DESTROY(sc);
329         return (ENXIO);
330 }
331
332 static int
333 mtk_gpio_detach(device_t dev)
334 {
335         struct mtk_gpio_softc *sc = device_get_softc(dev);
336         phandle_t node;
337
338         node = ofw_bus_get_node(dev);
339         intr_pic_deregister(dev, OF_xref_from_node(node));
340         if (sc->intrhand != NULL)
341                 bus_teardown_intr(dev, sc->res[1], sc->intrhand);
342         bus_release_resources(dev, mtk_gpio_spec, sc->res);
343         MTK_GPIO_LOCK_DESTROY(sc);
344         return (0);
345 }
346
347 static device_t
348 mtk_gpio_get_bus(device_t dev)
349 {
350         struct mtk_gpio_softc *sc = device_get_softc(dev);
351
352         return (sc->busdev);
353 }
354
355 static int
356 mtk_gpio_pin_max(device_t dev, int *maxpin)
357 {
358         struct mtk_gpio_softc *sc = device_get_softc(dev);
359
360         *maxpin = sc->num_pins - 1;
361
362         return (0);
363 }
364
365 static int
366 mtk_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps)
367 {
368         struct mtk_gpio_softc *sc = device_get_softc(dev);
369
370         if (pin >= sc->num_pins)
371                 return (EINVAL);
372
373         MTK_GPIO_LOCK(sc);
374         *caps = sc->pins[pin].pin_caps;
375         MTK_GPIO_UNLOCK(sc);
376
377         return (0);
378 }
379
380 static int
381 mtk_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags)
382 {
383         struct mtk_gpio_softc *sc = device_get_softc(dev);
384
385         if (pin >= sc->num_pins)
386                 return (EINVAL);
387
388         MTK_GPIO_LOCK(sc);
389         *flags = sc->pins[pin].pin_flags;
390         MTK_GPIO_UNLOCK(sc);
391
392         return (0);
393 }
394
395 static int
396 mtk_gpio_pin_getname(device_t dev, uint32_t pin, char *name)
397 {
398         struct mtk_gpio_softc *sc = device_get_softc(dev);
399
400         if (pin >= sc->num_pins)
401                 return (EINVAL);
402
403         strncpy(name, sc->pins[pin].pin_name, GPIOMAXNAME - 1);
404         name[GPIOMAXNAME - 1] = '\0';
405
406         return (0);
407 }
408
409 static int
410 mtk_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags)
411 {
412         struct mtk_gpio_softc *sc;
413         int retval;
414
415         sc = device_get_softc(dev);
416
417         if (pin >= sc->num_pins)
418                 return (EINVAL);
419
420         MTK_GPIO_LOCK(sc);
421         retval = mtk_gpio_pin_set_direction(sc, pin,
422             flags & (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT));
423         if (retval == 0)
424                 retval = mtk_gpio_pin_set_invert(sc, pin,
425                     flags & (GPIO_PIN_INVIN | GPIO_PIN_INVOUT));
426         MTK_GPIO_UNLOCK(sc);
427
428         return (retval);
429 }
430
431 static int
432 mtk_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value)
433 {
434         struct mtk_gpio_softc *sc;
435         int ret;
436
437         sc = device_get_softc(dev);
438         ret = 0;
439
440         if (pin >= sc->num_pins)
441                 return (EINVAL);
442
443         MTK_GPIO_LOCK(sc);
444         if(!(sc->pins[pin].pin_flags & GPIO_PIN_OUTPUT)) {
445                 ret = EINVAL;
446                 goto out;
447         }
448
449         if (value)
450                 MTK_WRITE_4(sc, GPIO_PIOSET(sc), (1u << pin));
451         else
452                 MTK_WRITE_4(sc, GPIO_PIORESET(sc), (1u << pin));
453
454 out:
455         MTK_GPIO_UNLOCK(sc);
456         return (ret);
457 }
458
459 static int
460 mtk_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val)
461 {
462         struct mtk_gpio_softc *sc;
463         uint32_t data;
464         int ret;
465
466         sc = device_get_softc(dev);
467         ret = 0;
468
469         if (pin >= sc->num_pins)
470                 return (EINVAL);
471
472         MTK_GPIO_LOCK(sc);
473         if(!(sc->pins[pin].pin_flags & GPIO_PIN_INPUT)) {
474                 ret = EINVAL;
475                 goto out;
476         }
477         data = MTK_READ_4(sc, GPIO_PIODATA(sc));
478         *val = (data & (1u << pin)) ? 1 : 0;
479
480 out:
481         MTK_GPIO_UNLOCK(sc);
482         return (ret);
483 }
484
485 static int
486 mtk_gpio_pin_toggle(device_t dev, uint32_t pin)
487 {
488         struct mtk_gpio_softc *sc;
489         int ret;
490
491         if (pin >= sc->num_pins)
492                 return (EINVAL);
493
494         sc = device_get_softc(dev);
495         ret = 0;
496
497         MTK_GPIO_LOCK(sc);
498         if (!(sc->pins[pin].pin_flags & GPIO_PIN_OUTPUT)) {
499                 ret = EINVAL;
500                 goto out;
501         }
502         MTK_WRITE_4(sc, GPIO_PIOTOG(sc), (1u << pin));
503
504 out:
505         MTK_GPIO_UNLOCK(sc);
506
507         return (ret);
508 }
509
510 static int
511 mtk_gpio_pic_map_intr(device_t dev, struct intr_map_data *data,
512     struct intr_irqsrc **isrcp)
513 {
514         struct mtk_gpio_softc *sc;
515
516         sc = device_get_softc(dev);
517
518         if (data == NULL || data->type != INTR_MAP_DATA_FDT ||
519             data->fdt.ncells != 1 || data->fdt.cells[0] >= sc->num_pins)
520                 return (EINVAL);
521
522         *isrcp = PIC_INTR_ISRC(sc, data->fdt.cells[0]);
523         return (0);
524 }
525
526 static void
527 mtk_gpio_pic_enable_intr(device_t dev, struct intr_irqsrc *isrc)
528 {
529         struct mtk_gpio_softc *sc;
530         struct mtk_gpio_pin_irqsrc *pisrc;
531         uint32_t pin, mask, val;
532
533         sc = device_get_softc(dev);
534
535         pisrc = (struct mtk_gpio_pin_irqsrc *)isrc;
536         pin = pisrc->irq;
537         mask = 1u << pin;
538
539         MTK_GPIO_LOCK(sc);
540
541         if (sc->pins[pin].intr_polarity == INTR_POLARITY_LOW) {
542                 val = MTK_READ_4(sc, GPIO_PIORENA(sc)) & ~mask;
543                 MTK_WRITE_4(sc, GPIO_PIORENA(sc), val);
544                 val = MTK_READ_4(sc, GPIO_PIOFENA(sc)) | mask;
545                 MTK_WRITE_4(sc, GPIO_PIOFENA(sc), val);
546         } else {
547                 val = MTK_READ_4(sc, GPIO_PIOFENA(sc)) & ~mask;
548                 MTK_WRITE_4(sc, GPIO_PIOFENA(sc), val);
549                 val = MTK_READ_4(sc, GPIO_PIORENA(sc)) | mask;
550                 MTK_WRITE_4(sc, GPIO_PIORENA(sc), val);
551         }
552
553         MTK_GPIO_UNLOCK(sc);
554 }
555
556 static void
557 mtk_gpio_pic_disable_intr(device_t dev, struct intr_irqsrc *isrc)
558 {
559         struct mtk_gpio_softc *sc;
560         struct mtk_gpio_pin_irqsrc *pisrc;
561         uint32_t pin, mask, val;
562
563         sc = device_get_softc(dev);
564
565         pisrc = (struct mtk_gpio_pin_irqsrc *)isrc;
566         pin = pisrc->irq;
567         mask = 1u << pin;
568
569         MTK_GPIO_LOCK(sc);
570
571         val = MTK_READ_4(sc, GPIO_PIORENA(sc)) & ~mask;
572         MTK_WRITE_4(sc, GPIO_PIORENA(sc), val);
573         val = MTK_READ_4(sc, GPIO_PIOFENA(sc)) & ~mask;
574         MTK_WRITE_4(sc, GPIO_PIOFENA(sc), val);
575
576         MTK_GPIO_UNLOCK(sc);
577 }
578
579 static void
580 mtk_gpio_pic_pre_ithread(device_t dev, struct intr_irqsrc *isrc)
581 {
582
583         mtk_gpio_pic_disable_intr(dev, isrc);
584 }
585
586 static void
587 mtk_gpio_pic_post_ithread(device_t dev, struct intr_irqsrc *isrc)
588 {
589
590         mtk_gpio_pic_enable_intr(dev, isrc);
591 }
592
593 static void
594 mtk_gpio_pic_post_filter(device_t dev, struct intr_irqsrc *isrc)
595 {
596         struct mtk_gpio_softc *sc;
597         struct mtk_gpio_pin_irqsrc *pisrc;
598
599         pisrc = (struct mtk_gpio_pin_irqsrc *)isrc;
600         sc = device_get_softc(dev);
601         MTK_GPIO_LOCK(sc);
602         MTK_WRITE_4(sc, GPIO_PIOINT(sc), 1u << pisrc->irq);
603         MTK_GPIO_UNLOCK(sc);
604 }
605
606 static int
607 mtk_gpio_intr(void *arg)
608 {
609         struct mtk_gpio_softc *sc;
610         uint32_t i, interrupts;
611
612         sc = arg;
613         interrupts = MTK_READ_4(sc, GPIO_PIOINT(sc));
614
615         for (i = 0; interrupts != 0; i++, interrupts >>= 1) {
616                 if ((interrupts & 0x1) == 0)
617                         continue;
618                 if (intr_isrc_dispatch(PIC_INTR_ISRC(sc, i),
619                     curthread->td_intr_frame) != 0) {
620                         device_printf(sc->dev, "spurious interrupt %d\n", i);
621                 }
622         }       
623
624         return (FILTER_HANDLED);
625 }
626
627 static phandle_t
628 mtk_gpio_get_node(device_t bus, device_t dev)
629 {
630
631         /* We only have one child, the GPIO bus, which needs our own node. */
632         return (ofw_bus_get_node(bus));
633 }
634
635 static device_method_t mtk_gpio_methods[] = {
636         /* Device interface */
637         DEVMETHOD(device_probe,         mtk_gpio_probe),
638         DEVMETHOD(device_attach,        mtk_gpio_attach),
639         DEVMETHOD(device_detach,        mtk_gpio_detach),
640         
641         /* GPIO protocol */
642         DEVMETHOD(gpio_get_bus,         mtk_gpio_get_bus),
643         DEVMETHOD(gpio_pin_max,         mtk_gpio_pin_max),
644         DEVMETHOD(gpio_pin_getname,     mtk_gpio_pin_getname),
645         DEVMETHOD(gpio_pin_getflags,    mtk_gpio_pin_getflags),
646         DEVMETHOD(gpio_pin_getcaps,     mtk_gpio_pin_getcaps),
647         DEVMETHOD(gpio_pin_setflags,    mtk_gpio_pin_setflags),
648         DEVMETHOD(gpio_pin_get,         mtk_gpio_pin_get),
649         DEVMETHOD(gpio_pin_set,         mtk_gpio_pin_set),
650         DEVMETHOD(gpio_pin_toggle,      mtk_gpio_pin_toggle),
651
652         /* Interrupt controller interface */
653         DEVMETHOD(pic_disable_intr,     mtk_gpio_pic_disable_intr),
654         DEVMETHOD(pic_enable_intr,      mtk_gpio_pic_enable_intr),
655         DEVMETHOD(pic_map_intr,         mtk_gpio_pic_map_intr),
656         DEVMETHOD(pic_post_filter,      mtk_gpio_pic_post_filter),
657         DEVMETHOD(pic_post_ithread,     mtk_gpio_pic_post_ithread),
658         DEVMETHOD(pic_pre_ithread,      mtk_gpio_pic_pre_ithread),
659
660         /* ofw_bus interface */
661         DEVMETHOD(ofw_bus_get_node,     mtk_gpio_get_node),
662
663         DEVMETHOD_END
664 };
665
666 static driver_t mtk_gpio_driver = {
667         "gpio",
668         mtk_gpio_methods,
669         sizeof(struct mtk_gpio_softc),
670 };
671
672 static devclass_t mtk_gpio_devclass;
673
674 EARLY_DRIVER_MODULE(mtk_gpio_v1, simplebus, mtk_gpio_driver,
675     mtk_gpio_devclass, 0, 0, BUS_PASS_INTERRUPT + BUS_PASS_ORDER_LATE);