epgpio.c revision 1.5 1 /* $NetBSD: epgpio.c,v 1.5 2012/10/27 17:17:37 chs Exp $ */
2
3 /*
4 * Copyright (c) 2005 HAMAJIMA Katsuomi. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: epgpio.c,v 1.5 2012/10/27 17:17:37 chs Exp $");
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/device.h>
35 #include <sys/bus.h>
36 #include <machine/intr.h>
37 #include <sys/gpio.h>
38 #include <dev/gpio/gpiovar.h>
39 #include <arm/ep93xx/ep93xxvar.h>
40 #include <arm/ep93xx/epsocvar.h>
41 #include <arm/ep93xx/epgpioreg.h>
42 #include <arm/ep93xx/epgpiovar.h>
43 #include "opt_ep93xx_gpio_mask.h"
44 #include "gpio.h"
45 #include "locators.h"
46
47 #ifdef EPGPIO_DEBUG
48 int epgpio_debug = EPGPIO_DEBUG;
49 #define DPRINTFN(n,x) if (epgpio_debug>(n)) printf x;
50 #else
51 #define DPRINTFN(n,x)
52 #endif
53
54 #define EPGPIO_NPORTS 8
55 #define EPGPIO_NPINS 8
56
57 struct port_info {
58 struct epgpio_softc *sc;
59 int unit;
60 #if NGPIO > 0
61 struct gpio_chipset_tag gpio_chipset;
62 gpio_pin_t pins[EPGPIO_NPINS];
63 int gpio_mask;
64 int gpio_npins;
65 #endif
66 bus_size_t pxdr;
67 bus_size_t pxddr;
68 bus_size_t xinten;
69 bus_size_t xinttype1;
70 bus_size_t xinttype2;
71 bus_size_t xeoi;
72 bus_size_t xdb;
73 };
74
75 struct intr_req {
76 int irq;
77 int (*ih_func)(void *);
78 int (*ireq_func)(void *);
79 void *ireq_arg;
80 void *cookie;
81 };
82
83 struct epgpio_softc {
84 bus_space_tag_t sc_iot;
85 bus_space_handle_t sc_ioh;
86 struct port_info sc_port[EPGPIO_NPORTS];
87 struct intr_req sc_ireq_combine;
88 struct intr_req sc_ireq_f[EPGPIO_NPINS];
89 };
90
91 static int epgpio_match(device_t, cfdata_t, void *);
92 static void epgpio_attach(device_t, device_t, void *);
93
94 #if NGPIO > 0
95 static int epgpiobus_print(void *, const char *);
96 static int epgpio_pin_read(void *, int);
97 static void epgpio_pin_write(void *, int, int);
98 static void epgpio_pin_ctl(void *, int, int);
99 #endif
100
101 static int epgpio_search(device_t, cfdata_t, const int *, void *);
102 static int epgpio_print(void *, const char *);
103
104 static int epgpio_intr_combine(void* arg);
105 static int epgpio_intr_f(void* arg, int);
106 static int epgpio_intr_0(void* arg);
107 static int epgpio_intr_1(void* arg);
108 static int epgpio_intr_2(void* arg);
109 static int epgpio_intr_3(void* arg);
110 static int epgpio_intr_4(void* arg);
111 static int epgpio_intr_5(void* arg);
112 static int epgpio_intr_6(void* arg);
113 static int epgpio_intr_7(void* arg);
114
115 static void epgpio_bit_set(struct epgpio_softc *, bus_size_t, int);
116 static void epgpio_bit_clear(struct epgpio_softc *, bus_size_t, int);
117
118 CFATTACH_DECL_NEW(epgpio, sizeof(struct epgpio_softc),
119 epgpio_match, epgpio_attach, NULL, NULL);
120
121 static int
122 epgpio_match(device_t parent, cfdata_t match, void *aux)
123 {
124 return 2;
125 }
126
127 static void
128 epgpio_attach(device_t parent, device_t self, void *aux)
129 {
130 struct epgpio_softc *sc = device_private(self);
131 struct epsoc_attach_args *sa = aux;
132 struct port_info *pi;
133 #if NGPIO > 0
134 struct gpiobus_attach_args gba;
135 int dir, val;
136 int i, j, pin;
137 #endif
138
139 printf("\n");
140 sc->sc_iot = sa->sa_iot;
141
142 if (bus_space_map(sa->sa_iot, sa->sa_addr,
143 sa->sa_size, 0, &sc->sc_ioh)){
144 printf("%s: Cannot map registers", device_xname(self));
145 return;
146 }
147
148 /* PORT A */
149 pi = &sc->sc_port[0];
150 pi->unit = 0;
151 pi->sc = sc;
152 pi->pxdr = EP93XX_GPIO_PADR;
153 pi->pxddr = EP93XX_GPIO_PADDR;
154 pi->xinten = EP93XX_GPIO_AIntEn;
155 pi->xinttype1 = EP93XX_GPIO_AIntType1;
156 pi->xinttype2 = EP93XX_GPIO_AIntType2;
157 pi->xeoi = EP93XX_GPIO_AEOI;
158 pi->xdb = EP93XX_GPIO_ADB;
159 #if NGPIO > 0
160 pi->gpio_mask = EPGPIO_PORT_A_MASK;
161 #endif
162 bus_space_write_4(sc->sc_iot, sc->sc_ioh, pi->xinten, 0);
163 /* PORT B */
164 pi = &sc->sc_port[1];
165 pi->unit = 1;
166 pi->sc = sc;
167 pi->pxdr = EP93XX_GPIO_PBDR;
168 pi->pxddr = EP93XX_GPIO_PBDDR;
169 pi->xinten = EP93XX_GPIO_BIntEn;
170 pi->xinttype1 = EP93XX_GPIO_BIntType1;
171 pi->xinttype2 = EP93XX_GPIO_BIntType2;
172 pi->xeoi = EP93XX_GPIO_BEOI;
173 pi->xdb = EP93XX_GPIO_BDB;
174 #if NGPIO > 0
175 pi->gpio_mask = EPGPIO_PORT_B_MASK;
176 #endif
177 bus_space_write_4(sc->sc_iot, sc->sc_ioh, pi->xinten, 0);
178 /* PORT C */
179 pi = &sc->sc_port[2];
180 pi->unit = 2;
181 pi->sc = sc;
182 pi->pxdr = EP93XX_GPIO_PCDR;
183 pi->pxddr = EP93XX_GPIO_PCDDR;
184 pi->xinten = pi->xinttype1 = pi->xinttype2 = pi->xeoi = pi->xdb = -1;
185 #if NGPIO > 0
186 pi->gpio_mask = EPGPIO_PORT_C_MASK;
187 #endif
188 /* PORT D */
189 pi = &sc->sc_port[3];
190 pi->unit = 3;
191 pi->sc = sc;
192 pi->pxdr = EP93XX_GPIO_PDDR;
193 pi->pxddr = EP93XX_GPIO_PDDDR;
194 pi->xinten = pi->xinttype1 = pi->xinttype2 = pi->xeoi = pi->xdb = -1;
195 #if NGPIO > 0
196 pi->gpio_mask = EPGPIO_PORT_D_MASK;
197 #endif
198 /* PORT E */
199 pi = &sc->sc_port[4];
200 pi->unit = 4;
201 pi->sc = sc;
202 pi->pxdr = EP93XX_GPIO_PEDR;
203 pi->pxddr = EP93XX_GPIO_PEDDR;
204 pi->xinten = pi->xinttype1 = pi->xinttype2 = pi->xeoi = pi->xdb = -1;
205 #if NGPIO > 0
206 pi->gpio_mask = EPGPIO_PORT_E_MASK;
207 #endif
208 /* PORT F */
209 pi = &sc->sc_port[5];
210 pi->unit = 5;
211 pi->sc = sc;
212 pi->pxdr = EP93XX_GPIO_PFDR;
213 pi->pxddr = EP93XX_GPIO_PFDDR;
214 pi->xinten = EP93XX_GPIO_FIntEn;
215 pi->xinttype1 = EP93XX_GPIO_FIntType1;
216 pi->xinttype2 = EP93XX_GPIO_FIntType2;
217 pi->xeoi = EP93XX_GPIO_FEOI;
218 pi->xdb = EP93XX_GPIO_FDB;
219 #if NGPIO > 0
220 pi->gpio_mask = EPGPIO_PORT_F_MASK;
221 #endif
222 bus_space_write_4(sc->sc_iot, sc->sc_ioh, pi->xinten, 0);
223 /* PORT G */
224 pi = &sc->sc_port[6];
225 pi->unit = 6;
226 pi->sc = sc;
227 pi->pxdr = EP93XX_GPIO_PGDR;
228 pi->pxddr = EP93XX_GPIO_PGDDR;
229 pi->xinten = pi->xinttype1 = pi->xinttype2 = pi->xeoi = pi->xdb = -1;
230 #if NGPIO > 0
231 pi->gpio_mask = EPGPIO_PORT_G_MASK;
232 #endif
233 /* PORT H */
234 pi = &sc->sc_port[7];
235 pi->unit = 7;
236 pi->sc = sc;
237 pi->pxdr = EP93XX_GPIO_PHDR;
238 pi->pxddr = EP93XX_GPIO_PHDDR;
239 pi->xinten = pi->xinttype1 = pi->xinttype2 = pi->xeoi = pi->xdb = -1;
240 #if NGPIO > 0
241 pi->gpio_mask = EPGPIO_PORT_H_MASK;
242 #endif
243
244 /* PORT A & B */
245 sc->sc_ireq_combine.irq = EP93XX_GPIO_INTR;
246 sc->sc_ireq_combine.ih_func = epgpio_intr_combine;
247 /* PORT F */
248 sc->sc_ireq_f[0].irq = EP93XX_GPIO0_INTR;
249 sc->sc_ireq_f[0].ih_func = epgpio_intr_0;
250 sc->sc_ireq_f[1].irq = EP93XX_GPIO1_INTR;
251 sc->sc_ireq_f[1].ih_func = epgpio_intr_1;
252 sc->sc_ireq_f[2].irq = EP93XX_GPIO2_INTR;
253 sc->sc_ireq_f[2].ih_func = epgpio_intr_2;
254 sc->sc_ireq_f[3].irq = EP93XX_GPIO3_INTR;
255 sc->sc_ireq_f[3].ih_func = epgpio_intr_3;
256 sc->sc_ireq_f[4].irq = EP93XX_GPIO4_INTR;
257 sc->sc_ireq_f[4].ih_func = epgpio_intr_4;
258 sc->sc_ireq_f[5].irq = EP93XX_GPIO5_INTR;
259 sc->sc_ireq_f[5].ih_func = epgpio_intr_5;
260 sc->sc_ireq_f[6].irq = EP93XX_GPIO6_INTR;
261 sc->sc_ireq_f[6].ih_func = epgpio_intr_6;
262 sc->sc_ireq_f[7].irq = EP93XX_GPIO7_INTR;
263 sc->sc_ireq_f[7].ih_func = epgpio_intr_7;
264
265 #if NGPIO > 0
266 /* initialize and attach gpio(4) */
267 for (i = 0; i < EPGPIO_NPORTS; i++) {
268 pi = &sc->sc_port[i];
269 /*
270 * If this port is completely disabled for gpio attachment,
271 * then skip it.
272 */
273 if (pi->gpio_mask == 0x00)
274 continue;
275
276 dir = bus_space_read_4(sc->sc_iot, sc->sc_ioh, pi->pxddr) & 0xff;
277 val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, pi->pxdr) & 0xff;
278
279 /*
280 * pin_num doesn't seem to be used for anything in the GPIO
281 * code. So we're going to use it to refer to the REAL pin
282 * on the port. Just to keep things straight below:
283 *
284 * pin - The pin number as seen by the GPIO code
285 * j - The ACTUAL pin on the port
286 */
287
288 for (j = 0, pin = 0; j < EPGPIO_NPINS; j++) {
289 if (pi->gpio_mask & (1 << j)) {
290 pi->pins[pin].pin_num = j;
291 pi->pins[pin].pin_caps = (GPIO_PIN_INPUT
292 | GPIO_PIN_OUTPUT);
293 if((dir >> j) & 0x01)
294 pi->pins[pin].pin_flags =
295 GPIO_PIN_OUTPUT;
296 else
297 pi->pins[pin].pin_flags =
298 GPIO_PIN_INPUT;
299 if((val >> j) & 0x01)
300 pi->pins[pin].pin_state = GPIO_PIN_HIGH;
301 else
302 pi->pins[pin].pin_state = GPIO_PIN_LOW;
303 pin++;
304 }
305 }
306 pi->gpio_chipset.gp_cookie = pi;
307 pi->gpio_chipset.gp_pin_read = epgpio_pin_read;
308 pi->gpio_chipset.gp_pin_write = epgpio_pin_write;
309 pi->gpio_chipset.gp_pin_ctl = epgpio_pin_ctl;
310 gba.gba_gc = &pi->gpio_chipset;
311 gba.gba_pins = pi->pins;
312 gba.gba_npins = pin;
313 config_found_ia(self, "gpiobus", &gba, epgpiobus_print);
314 }
315 #endif
316
317 config_search_ia(epgpio_search, self, "epgpio", epgpio_print);
318 }
319
320 #if NGPIO > 0
321 static int
322 epgpiobus_print(void *aux, const char *name)
323 {
324 struct gpiobus_attach_args *gba = aux;
325 struct port_info *pi = (struct port_info *)gba->gba_gc->gp_cookie;
326
327 gpiobus_print(aux, name);
328 aprint_normal(": port %c", pi->unit+'A');
329
330 return (UNCONF);
331 }
332 #endif
333
334
335 static int
336 epgpio_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
337 {
338 struct epgpio_softc *sc = device_private(parent);
339 struct epgpio_attach_args ga;
340
341 ga.ga_gc = sc;
342 ga.ga_iot = sc->sc_iot;
343 ga.ga_port = cf->cf_loc[EPGPIOCF_PORT];
344 ga.ga_bit1 = cf->cf_loc[EPGPIOCF_BIT1];
345 ga.ga_bit2 = cf->cf_loc[EPGPIOCF_BIT2];
346
347 if (config_match(parent, cf, &ga) > 0)
348 config_attach(parent, cf, &ga, epgpio_print);
349
350 return 0;
351 }
352
353 static int
354 epgpio_print(void *aux, const char *name)
355 {
356 struct epgpio_attach_args *ga = aux;
357 struct epgpio_softc *sc = ga->ga_gc;
358
359 aprint_normal(":");
360 if (ga->ga_port > -1)
361 aprint_normal(" port %c", sc->sc_port[ga->ga_port].unit+'A');
362 if (ga->ga_bit1 > -1)
363 aprint_normal(" bit1 %d", ga->ga_bit1);
364 if (ga->ga_bit2 > -1)
365 aprint_normal(" bit2 %d", ga->ga_bit2);
366
367 return (UNCONF);
368 }
369
370 int
371 epgpio_read(struct epgpio_softc *sc, epgpio_port port, int bit)
372 {
373 struct port_info *pi = &sc->sc_port[port];
374
375 #if NGPIO > 0
376 pi->pins[bit].pin_caps = 0;
377 #endif
378 return (bus_space_read_4(sc->sc_iot, sc->sc_ioh, pi->pxdr) >> bit) & 1;
379 }
380
381 void
382 epgpio_set(struct epgpio_softc *sc, epgpio_port port, int bit)
383 {
384 struct port_info *pi = &sc->sc_port[port];
385
386 #if NGPIO > 0
387 pi->pins[bit].pin_caps = 0;
388 #endif
389 epgpio_bit_set(sc, pi->pxdr, bit);
390 }
391
392 void
393 epgpio_clear(struct epgpio_softc *sc, epgpio_port port, int bit)
394 {
395 struct port_info *pi = &sc->sc_port[port];
396
397 #if NGPIO > 0
398 pi->pins[bit].pin_caps = 0;
399 #endif
400 epgpio_bit_clear(sc, pi->pxdr, bit);
401 }
402
403 void
404 epgpio_in(struct epgpio_softc *sc, epgpio_port port, int bit)
405 {
406 struct port_info *pi = &sc->sc_port[port];
407
408 #if NGPIO > 0
409 pi->pins[bit].pin_caps = 0;
410 #endif
411 epgpio_bit_clear(sc, pi->pxddr, bit);
412 }
413
414 void
415 epgpio_out(struct epgpio_softc *sc, epgpio_port port, int bit)
416 {
417 struct port_info *pi = &sc->sc_port[port];
418
419 #if NGPIO > 0
420 pi->pins[bit].pin_caps = 0;
421 #endif
422 epgpio_bit_set(sc, pi->pxddr, bit);
423 }
424
425 void *
426 epgpio_intr_establish(struct epgpio_softc *sc, epgpio_port port, int bit,
427 int flag, int ipl, int (*ireq_func)(void *), void *arg) {
428 struct port_info *pi;
429 struct intr_req *intq;
430
431 DPRINTFN(1, ("epgpio_intr_establish: port=%d, bit=%d, flag=%#x\n",port,bit,flag));
432
433 if (bit < 0 || bit >= EPGPIO_NPINS)
434 return 0;
435
436 switch (port) {
437 case PORT_A:
438 case PORT_B:
439 intq = &sc->sc_ireq_combine;
440 break;
441 case PORT_F:
442 intq = &sc->sc_ireq_f[bit];
443 break;
444 default:
445 return 0;
446 };
447
448 if (intq->ireq_func)
449 return 0; /* already used */
450
451 intq->ireq_func = ireq_func;
452 intq->ireq_arg = arg;
453
454 pi = &sc->sc_port[port];
455 epgpio_bit_clear(sc, pi->xinten, bit);
456 epgpio_in(sc, port, bit);
457 #if NGPIO > 0
458 pi->pins[bit].pin_caps = 0;
459 #endif
460
461 if (flag & EDGE_TRIGGER)
462 epgpio_bit_set(sc, pi->xinttype1, bit);
463 else /* LEVEL_SENSE */
464 epgpio_bit_clear(sc, pi->xinttype1, bit);
465 if (flag & RISING_EDGE) /* or HIGH_LEVEL */
466 epgpio_bit_set(sc, pi->xinttype2, bit);
467 else /* FALLING_EDGE or LOW_LEVEL */
468 epgpio_bit_clear(sc, pi->xinttype2, bit);
469 if (flag & DEBOUNCE)
470 epgpio_bit_set(sc, pi->xdb, bit);
471 else
472 epgpio_bit_clear(sc, pi->xdb, bit);
473
474 if (!intq->cookie)
475 intq->cookie = ep93xx_intr_establish(intq->irq, ipl,
476 intq->ih_func, pi);
477 bus_space_write_4(sc->sc_iot, sc->sc_ioh, pi->xeoi, 1 << bit);
478 epgpio_bit_set(sc, pi->xinten, bit);
479 return intq->cookie;
480 }
481
482 void
483 epgpio_intr_disestablish(struct epgpio_softc *sc, epgpio_port port, int bit)
484 {
485 struct port_info *pi;
486 struct intr_req *intq;
487
488 DPRINTFN(1, ("epgpio_intr_disestablish: port=%d, bit=%d\n",port,bit));
489
490 if (bit < 0 || bit >= EPGPIO_NPINS)
491 return;
492
493 switch (port) {
494 case PORT_A:
495 case PORT_B:
496 intq = &sc->sc_ireq_combine;
497 break;
498 case PORT_F:
499 intq = &sc->sc_ireq_f[bit];
500 break;
501 default:
502 return;
503 };
504
505 if (!intq->ireq_func)
506 return;
507
508 pi = &sc->sc_port[port];
509 epgpio_bit_clear(sc, pi->xinten, bit);
510 intq->ireq_func = 0;
511 intq->ireq_arg = 0;
512 ep93xx_intr_disestablish(intq->cookie);
513 intq->cookie = 0;
514 }
515
516 static int
517 epgpio_intr_combine(void *arg)
518 {
519 struct port_info *pi = arg;
520 struct epgpio_softc *sc = pi->sc;
521 struct intr_req *intq = &sc->sc_ireq_combine;
522 int err = 0;
523
524 DPRINTFN(1, ("epgpio_intr_combine\n"));
525
526 if (intq->ireq_func)
527 err = (*intq->ireq_func)(intq->ireq_arg);
528 epgpio_bit_set(sc, pi->xeoi, 0xff);
529 return err;
530 }
531
532 static int
533 epgpio_intr_f(void *arg, int bit)
534 {
535 struct port_info *pi = arg;
536 struct epgpio_softc *sc = pi->sc;
537 struct intr_req *intq = &sc->sc_ireq_f[bit];
538 int err = 0;
539
540 DPRINTFN(1, ("epgpio_intr_%d\n", bit));
541
542 if (intq->ireq_func)
543 err = (*intq->ireq_func)(intq->ireq_arg);
544 epgpio_bit_set(sc, pi->xeoi, bit);
545 return err;
546 }
547
548 static int
549 epgpio_intr_0(void *arg)
550 {
551 return epgpio_intr_f(arg, 0);
552 }
553
554 static int
555 epgpio_intr_1(void *arg)
556 {
557 return epgpio_intr_f(arg, 1);
558 }
559
560 static int
561 epgpio_intr_2(void *arg)
562 {
563 return epgpio_intr_f(arg, 2);
564 }
565
566 static int
567 epgpio_intr_3(void *arg)
568 {
569 return epgpio_intr_f(arg, 3);
570 }
571
572 static int
573 epgpio_intr_4(void *arg)
574 {
575 return epgpio_intr_f(arg, 4);
576 }
577
578 static int
579 epgpio_intr_5(void *arg)
580 {
581 return epgpio_intr_f(arg, 5);
582 }
583
584 static int
585 epgpio_intr_6(void *arg)
586 {
587 return epgpio_intr_f(arg, 6);
588 }
589
590 static int
591 epgpio_intr_7(void *arg)
592 {
593 return epgpio_intr_f(arg, 7);
594 }
595
596 #if NGPIO > 0
597 static int
598 epgpio_pin_read(void *arg, int pin)
599 {
600 struct port_info *pi = arg;
601 struct epgpio_softc *sc = pi->sc;
602
603 pin %= pi->gpio_npins;
604 if (!pi->pins[pin].pin_caps)
605 return 0; /* EBUSY? */
606
607 return (bus_space_read_4(sc->sc_iot, sc->sc_ioh,
608 pi->pxdr) >> pi->pins[pin].pin_num) & 1;
609 }
610
611 static void
612 epgpio_pin_write(void *arg, int pin, int val)
613 {
614 struct port_info *pi = arg;
615 struct epgpio_softc *sc = pi->sc;
616
617 pin %= pi->gpio_npins;
618 if (!pi->pins[pin].pin_caps)
619 return;
620
621 if (val)
622 epgpio_bit_set(sc, pi->pxdr, pi->pins[pin].pin_num);
623 else
624 epgpio_bit_clear(sc, pi->pxdr, pi->pins[pin].pin_num);
625 }
626
627 static void
628 epgpio_pin_ctl(void *arg, int pin, int flags)
629 {
630 struct port_info *pi = arg;
631 struct epgpio_softc *sc = pi->sc;
632
633 pin %= pi->gpio_npins;
634 if (!pi->pins[pin].pin_caps)
635 return;
636
637 if (flags & GPIO_PIN_INPUT)
638 epgpio_bit_clear(sc, pi->pxddr, pi->pins[pin].pin_num);
639 else if (flags & GPIO_PIN_OUTPUT)
640 epgpio_bit_set(sc, pi->pxddr, pi->pins[pin].pin_num);
641 }
642 #endif
643
644 static void
645 epgpio_bit_set(struct epgpio_softc *sc, bus_size_t reg, int bit)
646 {
647 int t = bus_space_read_4(sc->sc_iot, sc->sc_ioh, reg) & 0xff;
648 bus_space_write_4(sc->sc_iot, sc->sc_ioh, reg, t | (1 << bit));
649 }
650
651 static void
652 epgpio_bit_clear(struct epgpio_softc *sc, bus_size_t reg, int bit)
653 {
654 int t = bus_space_read_4(sc->sc_iot, sc->sc_ioh, reg) & 0xff;
655 bus_space_write_4(sc->sc_iot, sc->sc_ioh, reg, t & ~(1 << bit));
656 }
657