at91pio.c revision 1.5 1 1.5 chs /* $Id: at91pio.c,v 1.5 2012/10/27 17:17:36 chs Exp $ */
2 1.5 chs /* $NetBSD: at91pio.c,v 1.5 2012/10/27 17:17:36 chs Exp $ */
3 1.2 matt
4 1.2 matt /*
5 1.2 matt * Copyright (c) 2007 Embedtronics Oy. All rights reserved.
6 1.2 matt *
7 1.2 matt * Based on arch/arm/ep93xx/epgpio.c,
8 1.2 matt * Copyright (c) 2005 HAMAJIMA Katsuomi. All rights reserved.
9 1.2 matt *
10 1.2 matt * Redistribution and use in source and binary forms, with or without
11 1.2 matt * modification, are permitted provided that the following conditions
12 1.2 matt * are met:
13 1.2 matt * 1. Redistributions of source code must retain the above copyright
14 1.2 matt * notice, this list of conditions and the following disclaimer.
15 1.2 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 matt * notice, this list of conditions and the following disclaimer in the
17 1.2 matt * documentation and/or other materials provided with the distribution.
18 1.2 matt *
19 1.2 matt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 1.2 matt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.2 matt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.2 matt * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 1.2 matt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.2 matt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.2 matt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.2 matt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.2 matt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.2 matt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.2 matt * SUCH DAMAGE.
30 1.2 matt */
31 1.2 matt
32 1.2 matt #include <sys/cdefs.h>
33 1.5 chs __KERNEL_RCSID(0, "$NetBSD: at91pio.c,v 1.5 2012/10/27 17:17:36 chs Exp $");
34 1.2 matt
35 1.2 matt #include <sys/param.h>
36 1.2 matt #include <sys/systm.h>
37 1.2 matt #include <sys/kernel.h>
38 1.2 matt #include <sys/device.h>
39 1.3 matt #include <sys/gpio.h>
40 1.4 dyoung #include <sys/bus.h>
41 1.2 matt #include <machine/intr.h>
42 1.2 matt #include <dev/gpio/gpiovar.h>
43 1.2 matt #include <arm/at91/at91var.h>
44 1.2 matt #include <arm/at91/at91reg.h>
45 1.2 matt #include <arm/at91/at91pioreg.h>
46 1.2 matt #include <arm/at91/at91piovar.h>
47 1.2 matt #include "gpio.h"
48 1.2 matt #if NGPIO > 0
49 1.2 matt #include <sys/gpio.h>
50 1.2 matt #endif
51 1.2 matt #include "locators.h"
52 1.2 matt
53 1.2 matt #ifdef AT91PIO_DEBUG
54 1.2 matt int at91pio_debug = AT91PIO_DEBUG;
55 1.2 matt #define DPRINTFN(n,x) if (at91pio_debug>(n)) printf x;
56 1.2 matt #else
57 1.2 matt #define DPRINTFN(n,x)
58 1.2 matt #endif
59 1.2 matt
60 1.2 matt #define AT91PIO_NMAXPORTS 4
61 1.2 matt #define AT91PIO_NPINS 32
62 1.2 matt
63 1.2 matt struct intr_req {
64 1.2 matt int (*ireq_func)(void *);
65 1.2 matt void *ireq_arg;
66 1.2 matt int ireq_ipl;
67 1.2 matt };
68 1.2 matt
69 1.2 matt #define PIO_READ(_sc, _reg) bus_space_read_4((_sc)->sc_iot, (_sc)->sc_ioh, (_reg))
70 1.2 matt #define PIO_WRITE(_sc, _reg, _val) bus_space_write_4((_sc)->sc_iot, (_sc)->sc_ioh, (_reg), (_val))
71 1.2 matt
72 1.2 matt struct at91pio_softc {
73 1.2 matt bus_space_tag_t sc_iot;
74 1.2 matt bus_space_handle_t sc_ioh;
75 1.2 matt int sc_pid;
76 1.2 matt #if NGPIO > 0
77 1.2 matt struct gpio_chipset_tag gpio_chipset;
78 1.2 matt gpio_pin_t pins[AT91PIO_NPINS];
79 1.2 matt #endif
80 1.2 matt int irq;
81 1.2 matt void *ih;
82 1.2 matt struct intr_req ireq[AT91PIO_NPINS];
83 1.2 matt };
84 1.2 matt
85 1.2 matt static int at91pio_match(device_t, cfdata_t, void *);
86 1.2 matt static void at91pio_attach(device_t, device_t, void *);
87 1.2 matt
88 1.2 matt #if NGPIO > 0
89 1.2 matt static int at91piobus_print(void *, const char *);
90 1.2 matt static int at91pio_pin_read(void *, int);
91 1.2 matt static void at91pio_pin_write(void *, int, int);
92 1.2 matt static void at91pio_pin_ctl(void *, int, int);
93 1.2 matt #endif
94 1.2 matt
95 1.2 matt static int at91pio_search(device_t, cfdata_t, const int *, void *);
96 1.2 matt static int at91pio_print(void *, const char *);
97 1.2 matt
98 1.2 matt static int at91pio_intr(void* arg);
99 1.2 matt
100 1.5 chs CFATTACH_DECL_NEW(at91pio, sizeof(struct at91pio_softc),
101 1.2 matt at91pio_match, at91pio_attach, NULL, NULL);
102 1.2 matt
103 1.2 matt static struct at91pio_softc *at91pio_softc[AT91_PIO_COUNT];
104 1.2 matt
105 1.2 matt struct at91pio_softc *at91pio_sc(at91pio_port port)
106 1.2 matt {
107 1.2 matt if (port < AT91_PIO_COUNT)
108 1.2 matt return at91pio_softc[port];
109 1.2 matt return NULL;
110 1.2 matt }
111 1.2 matt
112 1.2 matt
113 1.2 matt static int
114 1.2 matt at91pio_match(device_t parent, cfdata_t match, void *aux)
115 1.2 matt {
116 1.2 matt if (strcmp(match->cf_name, "at91pio") == 0)
117 1.2 matt return 2;
118 1.2 matt return 0;
119 1.2 matt }
120 1.2 matt
121 1.2 matt static void
122 1.2 matt at91pio_attach(device_t parent, device_t self, void *aux)
123 1.2 matt {
124 1.5 chs struct at91pio_softc *sc = device_private(self);
125 1.2 matt struct at91bus_attach_args *sa = aux;
126 1.2 matt #if NGPIO > 0
127 1.2 matt struct gpiobus_attach_args gba;
128 1.2 matt uint32_t psr, osr, pin;
129 1.2 matt int j, n;
130 1.2 matt #endif
131 1.2 matt printf("\n");
132 1.2 matt sc->sc_iot = sa->sa_iot;
133 1.2 matt sc->sc_pid = sa->sa_pid;
134 1.2 matt
135 1.2 matt if (bus_space_map(sa->sa_iot, sa->sa_addr,
136 1.2 matt sa->sa_size, 0, &sc->sc_ioh)){
137 1.5 chs printf("%s: Cannot map registers", device_xname(self));
138 1.2 matt return;
139 1.2 matt }
140 1.2 matt
141 1.2 matt /* save descriptor: */
142 1.2 matt at91pio_port p = at91_pio_port(sa->sa_pid);
143 1.2 matt if (p < AT91_PIO_COUNT && !at91pio_softc[p])
144 1.2 matt at91pio_softc[p] = sc;
145 1.2 matt
146 1.2 matt /* make sure peripheral is enabled: */
147 1.2 matt at91_peripheral_clock(sc->sc_pid, 1);
148 1.2 matt
149 1.2 matt /* initialize ports (disable interrupts) */
150 1.2 matt PIO_WRITE(sc, PIO_IDR, -1);
151 1.2 matt
152 1.2 matt #if NGPIO > 0
153 1.2 matt /* initialize and attach gpio(4) */
154 1.2 matt psr = PIO_READ(sc, PIO_PSR); // only ports
155 1.2 matt osr = PIO_READ(sc, PIO_OSR);
156 1.2 matt pin = PIO_READ(sc, PIO_PDSR);
157 1.2 matt psr &= ~at91_gpio_mask(sc->sc_pid);
158 1.2 matt for (j = n = 0; j < AT91PIO_NPINS; j++) {
159 1.2 matt sc->pins[n].pin_num = j;
160 1.2 matt if (psr & (1 << j))
161 1.2 matt sc->pins[n].pin_caps = (GPIO_PIN_INPUT
162 1.2 matt | GPIO_PIN_OUTPUT
163 1.2 matt | GPIO_PIN_OPENDRAIN // @@@ not all pins
164 1.2 matt | GPIO_PIN_PUSHPULL
165 1.2 matt | GPIO_PIN_PULLUP);
166 1.2 matt else
167 1.2 matt sc->pins[n].pin_caps = 0;
168 1.2 matt
169 1.2 matt if (osr & (1 << j))
170 1.2 matt sc->pins[n].pin_flags = GPIO_PIN_OUTPUT;
171 1.2 matt else
172 1.2 matt sc->pins[n].pin_flags = GPIO_PIN_INPUT;
173 1.2 matt if (pin & (1 << j))
174 1.2 matt sc->pins[n].pin_state = GPIO_PIN_HIGH;
175 1.2 matt else
176 1.2 matt sc->pins[n].pin_state = GPIO_PIN_LOW;
177 1.2 matt n++;
178 1.2 matt }
179 1.2 matt sc->gpio_chipset.gp_cookie = sc;
180 1.2 matt sc->gpio_chipset.gp_pin_read = at91pio_pin_read;
181 1.2 matt sc->gpio_chipset.gp_pin_write = at91pio_pin_write;
182 1.2 matt sc->gpio_chipset.gp_pin_ctl = at91pio_pin_ctl;
183 1.2 matt gba.gba_gc = &sc->gpio_chipset;
184 1.2 matt gba.gba_pins = sc->pins;
185 1.2 matt gba.gba_npins = n;
186 1.2 matt config_found_ia(self, "gpiobus", &gba, at91piobus_print);
187 1.2 matt #endif
188 1.2 matt
189 1.2 matt /* attach device */
190 1.2 matt config_search_ia(at91pio_search, self, "at91pio", at91pio_print);
191 1.2 matt }
192 1.2 matt
193 1.2 matt #if NGPIO > 0
194 1.2 matt static int
195 1.2 matt at91piobus_print(void *aux, const char *name)
196 1.2 matt {
197 1.2 matt struct gpiobus_attach_args *gba = aux;
198 1.2 matt struct at91pio_softc *sc = (struct at91pio_softc *)gba->gba_gc->gp_cookie;
199 1.2 matt
200 1.2 matt gpiobus_print(aux, name);
201 1.2 matt aprint_normal(": port %s (mask %08"PRIX32")",
202 1.2 matt at91_peripheral_name(sc->sc_pid),
203 1.2 matt at91_gpio_mask(sc->sc_pid));
204 1.2 matt
205 1.2 matt return (UNCONF);
206 1.2 matt }
207 1.2 matt #endif
208 1.2 matt
209 1.2 matt
210 1.2 matt static int
211 1.5 chs at91pio_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
212 1.2 matt {
213 1.5 chs struct at91pio_softc *sc = device_private(parent);
214 1.2 matt struct at91pio_attach_args paa;
215 1.2 matt
216 1.2 matt paa.paa_sc = sc;
217 1.2 matt paa.paa_iot = sc->sc_iot;
218 1.2 matt paa.paa_pid = cf->cf_loc[AT91PIOCF_PID];
219 1.2 matt paa.paa_bit = cf->cf_loc[AT91PIOCF_BIT];
220 1.2 matt
221 1.2 matt if (config_match(parent, cf, &paa) > 0)
222 1.2 matt config_attach(parent, cf, &paa, at91pio_print);
223 1.2 matt
224 1.2 matt return 0;
225 1.2 matt }
226 1.2 matt
227 1.2 matt static int
228 1.2 matt at91pio_print(void *aux, const char *name)
229 1.2 matt {
230 1.5 chs struct at91pio_attach_args *paa = aux;
231 1.2 matt
232 1.2 matt aprint_normal(":");
233 1.2 matt if (paa->paa_pid > -1)
234 1.2 matt aprint_normal(" port %s", at91_peripheral_name(paa->paa_pid));
235 1.2 matt if (paa->paa_bit > -1)
236 1.2 matt aprint_normal(" bit %d", paa->paa_bit);
237 1.2 matt
238 1.2 matt return (UNCONF);
239 1.2 matt }
240 1.2 matt
241 1.2 matt int
242 1.2 matt at91pio_read(struct at91pio_softc *sc, int bit)
243 1.2 matt {
244 1.2 matt #if NGPIO > 0
245 1.2 matt sc->pins[bit].pin_caps = 0;
246 1.2 matt #endif
247 1.2 matt return (PIO_READ(sc, PIO_PDSR) >> bit) & 1;
248 1.2 matt }
249 1.2 matt
250 1.2 matt void
251 1.2 matt at91pio_set(struct at91pio_softc *sc, int bit)
252 1.2 matt {
253 1.2 matt #if NGPIO > 0
254 1.2 matt sc->pins[bit].pin_caps = 0;
255 1.2 matt #endif
256 1.2 matt PIO_WRITE(sc, PIO_SODR, (1U << bit));
257 1.2 matt }
258 1.2 matt
259 1.2 matt void
260 1.2 matt at91pio_clear(struct at91pio_softc *sc, int bit)
261 1.2 matt {
262 1.2 matt #if NGPIO > 0
263 1.2 matt sc->pins[bit].pin_caps = 0;
264 1.2 matt #endif
265 1.2 matt PIO_WRITE(sc, PIO_CODR, (1U << bit));
266 1.2 matt }
267 1.2 matt
268 1.2 matt void
269 1.2 matt at91pio_in(struct at91pio_softc *sc, int bit)
270 1.2 matt {
271 1.2 matt #if NGPIO > 0
272 1.2 matt sc->pins[bit].pin_caps = 0;
273 1.2 matt #endif
274 1.2 matt PIO_WRITE(sc, PIO_ODR, (1U << bit));
275 1.2 matt }
276 1.2 matt
277 1.2 matt void
278 1.2 matt at91pio_out(struct at91pio_softc *sc, int bit)
279 1.2 matt {
280 1.2 matt #if NGPIO > 0
281 1.2 matt sc->pins[bit].pin_caps = 0;
282 1.2 matt #endif
283 1.2 matt PIO_WRITE(sc, PIO_OER, (1U << bit));
284 1.2 matt }
285 1.2 matt
286 1.2 matt void at91pio_per(struct at91pio_softc *sc, int bit, int perab)
287 1.2 matt {
288 1.2 matt #if NGPIO > 0
289 1.2 matt sc->pins[bit].pin_caps = 0;
290 1.2 matt #endif
291 1.2 matt switch (perab) {
292 1.2 matt case -1:
293 1.2 matt PIO_WRITE(sc, PIO_PER, (1U << bit));
294 1.2 matt break;
295 1.2 matt case 0:
296 1.2 matt PIO_WRITE(sc, PIO_ASR, (1U << bit));
297 1.2 matt PIO_WRITE(sc, PIO_PDR, (1U << bit));
298 1.2 matt break;
299 1.2 matt case 1:
300 1.2 matt PIO_WRITE(sc, PIO_BSR, (1U << bit));
301 1.2 matt PIO_WRITE(sc, PIO_PDR, (1U << bit));
302 1.2 matt break;
303 1.2 matt default:
304 1.2 matt panic("%s: perab is invalid: %i", __FUNCTION__, perab);
305 1.2 matt break;
306 1.2 matt }
307 1.2 matt }
308 1.2 matt
309 1.2 matt void *
310 1.2 matt at91pio_intr_establish(struct at91pio_softc *sc, int bit,
311 1.2 matt int ipl, int (*ireq_func)(void *), void *arg)
312 1.2 matt {
313 1.2 matt struct intr_req *ireq;
314 1.2 matt
315 1.2 matt DPRINTFN(1, ("at91pio_intr_establish: port=%s, bit=%d\n", at91_peripheral_name(sc->sc_pid), bit));
316 1.2 matt
317 1.2 matt if (bit < 0 || bit >= AT91PIO_NPINS)
318 1.2 matt return 0;
319 1.2 matt
320 1.2 matt ireq = &sc->ireq[bit];
321 1.2 matt
322 1.2 matt if (ireq->ireq_func) /* already used */
323 1.2 matt return 0;
324 1.2 matt
325 1.2 matt ireq->ireq_func = ireq_func;
326 1.2 matt ireq->ireq_arg = arg;
327 1.2 matt ireq->ireq_ipl = ipl;
328 1.2 matt
329 1.2 matt PIO_WRITE(sc, PIO_IDR, (1U << bit)); /* disable interrupt for now */
330 1.2 matt at91pio_in(sc, bit); /* make sure pin is input */
331 1.2 matt #if NGPIO > 0
332 1.2 matt sc->pins[bit].pin_caps = 0;
333 1.2 matt #endif
334 1.2 matt #if 0
335 1.2 matt if (flag & EDGE_TRIGGER)
336 1.2 matt at91pio_bit_set(sc, sc->xinttype1, bit);
337 1.2 matt else /* LEVEL_SENSE */
338 1.2 matt at91pio_bit_clear(sc, sc->xinttype1, bit);
339 1.2 matt if (flag & RISING_EDGE) /* or HIGH_LEVEL */
340 1.2 matt at91pio_bit_set(sc, sc->xinttype2, bit);
341 1.2 matt else /* FALLING_EDGE or LOW_LEVEL */
342 1.2 matt at91pio_bit_clear(sc, sc->xinttype2, bit);
343 1.2 matt if (flag & DEBOUNCE)
344 1.2 matt PIO_WRITE(sc, PIO_IFER, (1U << bit));
345 1.2 matt else
346 1.2 matt PIO_WRITE(sc, PIO_IFDR, (1U << bit));
347 1.2 matt #endif
348 1.2 matt
349 1.2 matt if (!sc->ih) {
350 1.2 matt // use IPL_BIO because we want lowest possible priority as
351 1.2 matt // we really don't know what priority is going to be used by
352 1.2 matt // the caller.. this is not really optimal but tell me a
353 1.2 matt // better way
354 1.2 matt sc->ih = at91_intr_establish(sc->sc_pid, IPL_BIO, INTR_HIGH_LEVEL,
355 1.2 matt at91pio_intr, sc);
356 1.2 matt }
357 1.2 matt
358 1.2 matt //(void)PIO_READ(sc, PIO_ISR); // clear interrupts
359 1.2 matt PIO_WRITE(sc, PIO_IER, (1U << bit)); // enable interrupt
360 1.2 matt
361 1.2 matt return sc->ih;
362 1.2 matt }
363 1.2 matt
364 1.2 matt void
365 1.2 matt at91pio_intr_disestablish(struct at91pio_softc *sc, int bit, void *cookie)
366 1.2 matt {
367 1.2 matt struct intr_req *ireq;
368 1.2 matt int i;
369 1.2 matt
370 1.2 matt DPRINTFN(1, ("at91pio_intr_disestablish: port=%s, bit=%d\n", at91_peripheral_name(sc->sc_pid), bit));
371 1.2 matt
372 1.2 matt if (bit < 0 || bit >= AT91PIO_NPINS)
373 1.2 matt return;
374 1.2 matt
375 1.2 matt if (cookie != sc->ih)
376 1.2 matt return;
377 1.2 matt
378 1.2 matt ireq = &sc->ireq[bit];
379 1.2 matt
380 1.2 matt if (!ireq->ireq_func)
381 1.2 matt return;
382 1.2 matt
383 1.2 matt PIO_WRITE(sc, PIO_IDR, (1U << bit));
384 1.2 matt ireq->ireq_func = 0;
385 1.2 matt ireq->ireq_arg = 0;
386 1.2 matt
387 1.2 matt for (i = 0; i < AT91PIO_NPINS; i++) {
388 1.2 matt if (sc->ireq[i].ireq_func)
389 1.2 matt break;
390 1.2 matt }
391 1.2 matt
392 1.2 matt if (i >= AT91PIO_NPINS) {
393 1.2 matt at91_intr_disestablish(sc->ih);
394 1.2 matt sc->ih = 0;
395 1.2 matt }
396 1.2 matt }
397 1.2 matt
398 1.2 matt static int
399 1.2 matt at91pio_intr(void *arg)
400 1.2 matt {
401 1.2 matt struct at91pio_softc *sc = arg;
402 1.2 matt int bit;
403 1.2 matt u_int32_t isr;
404 1.2 matt
405 1.2 matt isr = (PIO_READ(sc, PIO_ISR) & PIO_READ(sc, PIO_IMR));
406 1.2 matt if (!isr)
407 1.2 matt return 0;
408 1.2 matt
409 1.2 matt do {
410 1.2 matt bit = ffs(isr) - 1;
411 1.2 matt isr &= ~(1U << bit);
412 1.2 matt #ifdef DIAGNOSTIC
413 1.2 matt if (bit < 0)
414 1.2 matt panic("%s: isr is zero (0x%X)", __FUNCTION__, isr);
415 1.2 matt #endif
416 1.2 matt if (sc->ireq[bit].ireq_func) {
417 1.2 matt int s = _splraise(sc->ireq[bit].ireq_ipl);
418 1.2 matt (*sc->ireq[bit].ireq_func)(sc->ireq[bit].ireq_arg);
419 1.2 matt splx(s);
420 1.2 matt }
421 1.2 matt } while (isr);
422 1.2 matt
423 1.2 matt return 1;
424 1.2 matt }
425 1.2 matt
426 1.2 matt
427 1.2 matt #if NGPIO > 0
428 1.2 matt static int
429 1.2 matt at91pio_pin_read(void *arg, int pin)
430 1.2 matt {
431 1.2 matt struct at91pio_softc *sc = arg;
432 1.2 matt
433 1.2 matt pin %= AT91PIO_NPINS;
434 1.2 matt if (!sc->pins[pin].pin_caps)
435 1.2 matt return 0; /* EBUSY? */
436 1.2 matt
437 1.2 matt return (PIO_READ(sc, PIO_PDSR) >> pin) & 1;
438 1.2 matt }
439 1.2 matt
440 1.2 matt static void
441 1.2 matt at91pio_pin_write(void *arg, int pin, int val)
442 1.2 matt {
443 1.2 matt struct at91pio_softc *sc = arg;
444 1.2 matt
445 1.2 matt pin %= AT91PIO_NPINS;
446 1.2 matt if (!sc->pins[pin].pin_caps)
447 1.2 matt return;
448 1.2 matt
449 1.2 matt if (val)
450 1.2 matt PIO_WRITE(sc, PIO_SODR, (1U << pin));
451 1.2 matt else
452 1.2 matt PIO_WRITE(sc, PIO_CODR, (1U << pin));
453 1.2 matt }
454 1.2 matt
455 1.2 matt static void
456 1.2 matt at91pio_pin_ctl(void *arg, int pin, int flags)
457 1.2 matt {
458 1.2 matt struct at91pio_softc *sc = arg;
459 1.2 matt
460 1.2 matt pin %= AT91PIO_NPINS;
461 1.2 matt if (!sc->pins[pin].pin_caps)
462 1.2 matt return;
463 1.2 matt
464 1.2 matt if (flags & GPIO_PIN_INPUT)
465 1.2 matt PIO_WRITE(sc, PIO_ODR, (1U << pin));
466 1.2 matt else if (flags & GPIO_PIN_OUTPUT)
467 1.2 matt PIO_WRITE(sc, PIO_OER, (1U << pin));
468 1.2 matt
469 1.2 matt if (flags & GPIO_PIN_OPENDRAIN)
470 1.2 matt PIO_WRITE(sc, PIO_MDER, (1U << pin));
471 1.2 matt else if (flags & GPIO_PIN_PUSHPULL)
472 1.2 matt PIO_WRITE(sc, PIO_MDDR, (1U << pin));
473 1.2 matt
474 1.2 matt if (flags & GPIO_PIN_PULLUP)
475 1.2 matt PIO_WRITE(sc, PIO_PUER, (1U << pin));
476 1.2 matt else
477 1.2 matt PIO_WRITE(sc, PIO_PUDR, (1U << pin));
478 1.2 matt }
479 1.2 matt #endif
480 1.2 matt
481