at91pio.c revision 1.2 1 1.2 matt /* $Id: at91pio.c,v 1.2 2008/07/03 01:15:38 matt Exp $ */
2 1.2 matt /* $NetBSD: at91pio.c,v 1.2 2008/07/03 01:15:38 matt 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.2 matt __KERNEL_RCSID(0, "$NetBSD: at91pio.c,v 1.2 2008/07/03 01:15:38 matt 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.2 matt #include <machine/bus.h>
40 1.2 matt #include <machine/intr.h>
41 1.2 matt #include <dev/gpio/gpiovar.h>
42 1.2 matt #include <arm/at91/at91var.h>
43 1.2 matt #include <arm/at91/at91reg.h>
44 1.2 matt #include <arm/at91/at91pioreg.h>
45 1.2 matt #include <arm/at91/at91piovar.h>
46 1.2 matt #include "gpio.h"
47 1.2 matt #if NGPIO > 0
48 1.2 matt #include <sys/gpio.h>
49 1.2 matt #endif
50 1.2 matt #include "locators.h"
51 1.2 matt
52 1.2 matt #ifdef AT91PIO_DEBUG
53 1.2 matt int at91pio_debug = AT91PIO_DEBUG;
54 1.2 matt #define DPRINTFN(n,x) if (at91pio_debug>(n)) printf x;
55 1.2 matt #else
56 1.2 matt #define DPRINTFN(n,x)
57 1.2 matt #endif
58 1.2 matt
59 1.2 matt #define AT91PIO_NMAXPORTS 4
60 1.2 matt #define AT91PIO_NPINS 32
61 1.2 matt
62 1.2 matt struct intr_req {
63 1.2 matt int (*ireq_func)(void *);
64 1.2 matt void *ireq_arg;
65 1.2 matt int ireq_ipl;
66 1.2 matt };
67 1.2 matt
68 1.2 matt #define PIO_READ(_sc, _reg) bus_space_read_4((_sc)->sc_iot, (_sc)->sc_ioh, (_reg))
69 1.2 matt #define PIO_WRITE(_sc, _reg, _val) bus_space_write_4((_sc)->sc_iot, (_sc)->sc_ioh, (_reg), (_val))
70 1.2 matt
71 1.2 matt struct at91pio_softc {
72 1.2 matt struct device sc_dev;
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.2 matt CFATTACH_DECL(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.2 matt struct at91pio_softc *sc = (struct at91pio_softc*)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.2 matt printf("%s: Cannot map registers", self->dv_xname);
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.2 matt at91pio_search(device_t parent, cfdata_t cf,
212 1.2 matt const int *ldesc, void *aux)
213 1.2 matt {
214 1.2 matt struct at91pio_softc *sc = (struct at91pio_softc*)parent;
215 1.2 matt struct at91pio_attach_args paa;
216 1.2 matt
217 1.2 matt paa.paa_sc = sc;
218 1.2 matt paa.paa_iot = sc->sc_iot;
219 1.2 matt paa.paa_pid = cf->cf_loc[AT91PIOCF_PID];
220 1.2 matt paa.paa_bit = cf->cf_loc[AT91PIOCF_BIT];
221 1.2 matt
222 1.2 matt if (config_match(parent, cf, &paa) > 0)
223 1.2 matt config_attach(parent, cf, &paa, at91pio_print);
224 1.2 matt
225 1.2 matt return 0;
226 1.2 matt }
227 1.2 matt
228 1.2 matt static int
229 1.2 matt at91pio_print(void *aux, const char *name)
230 1.2 matt {
231 1.2 matt struct at91pio_attach_args *paa = (struct at91pio_attach_args*)aux;
232 1.2 matt // struct at91pio_softc *sc = (struct at91pio_softc*)paa->paa_sc;
233 1.2 matt
234 1.2 matt aprint_normal(":");
235 1.2 matt if (paa->paa_pid > -1)
236 1.2 matt aprint_normal(" port %s", at91_peripheral_name(paa->paa_pid));
237 1.2 matt if (paa->paa_bit > -1)
238 1.2 matt aprint_normal(" bit %d", paa->paa_bit);
239 1.2 matt
240 1.2 matt return (UNCONF);
241 1.2 matt }
242 1.2 matt
243 1.2 matt int
244 1.2 matt at91pio_read(struct at91pio_softc *sc, int bit)
245 1.2 matt {
246 1.2 matt #if NGPIO > 0
247 1.2 matt sc->pins[bit].pin_caps = 0;
248 1.2 matt #endif
249 1.2 matt return (PIO_READ(sc, PIO_PDSR) >> bit) & 1;
250 1.2 matt }
251 1.2 matt
252 1.2 matt void
253 1.2 matt at91pio_set(struct at91pio_softc *sc, int bit)
254 1.2 matt {
255 1.2 matt #if NGPIO > 0
256 1.2 matt sc->pins[bit].pin_caps = 0;
257 1.2 matt #endif
258 1.2 matt PIO_WRITE(sc, PIO_SODR, (1U << bit));
259 1.2 matt }
260 1.2 matt
261 1.2 matt void
262 1.2 matt at91pio_clear(struct at91pio_softc *sc, int bit)
263 1.2 matt {
264 1.2 matt #if NGPIO > 0
265 1.2 matt sc->pins[bit].pin_caps = 0;
266 1.2 matt #endif
267 1.2 matt PIO_WRITE(sc, PIO_CODR, (1U << bit));
268 1.2 matt }
269 1.2 matt
270 1.2 matt void
271 1.2 matt at91pio_in(struct at91pio_softc *sc, int bit)
272 1.2 matt {
273 1.2 matt #if NGPIO > 0
274 1.2 matt sc->pins[bit].pin_caps = 0;
275 1.2 matt #endif
276 1.2 matt PIO_WRITE(sc, PIO_ODR, (1U << bit));
277 1.2 matt }
278 1.2 matt
279 1.2 matt void
280 1.2 matt at91pio_out(struct at91pio_softc *sc, int bit)
281 1.2 matt {
282 1.2 matt #if NGPIO > 0
283 1.2 matt sc->pins[bit].pin_caps = 0;
284 1.2 matt #endif
285 1.2 matt PIO_WRITE(sc, PIO_OER, (1U << bit));
286 1.2 matt }
287 1.2 matt
288 1.2 matt void at91pio_per(struct at91pio_softc *sc, int bit, int perab)
289 1.2 matt {
290 1.2 matt #if NGPIO > 0
291 1.2 matt sc->pins[bit].pin_caps = 0;
292 1.2 matt #endif
293 1.2 matt switch (perab) {
294 1.2 matt case -1:
295 1.2 matt PIO_WRITE(sc, PIO_PER, (1U << bit));
296 1.2 matt break;
297 1.2 matt case 0:
298 1.2 matt PIO_WRITE(sc, PIO_ASR, (1U << bit));
299 1.2 matt PIO_WRITE(sc, PIO_PDR, (1U << bit));
300 1.2 matt break;
301 1.2 matt case 1:
302 1.2 matt PIO_WRITE(sc, PIO_BSR, (1U << bit));
303 1.2 matt PIO_WRITE(sc, PIO_PDR, (1U << bit));
304 1.2 matt break;
305 1.2 matt default:
306 1.2 matt panic("%s: perab is invalid: %i", __FUNCTION__, perab);
307 1.2 matt break;
308 1.2 matt }
309 1.2 matt }
310 1.2 matt
311 1.2 matt void *
312 1.2 matt at91pio_intr_establish(struct at91pio_softc *sc, int bit,
313 1.2 matt int ipl, int (*ireq_func)(void *), void *arg)
314 1.2 matt {
315 1.2 matt struct intr_req *ireq;
316 1.2 matt
317 1.2 matt DPRINTFN(1, ("at91pio_intr_establish: port=%s, bit=%d\n", at91_peripheral_name(sc->sc_pid), bit));
318 1.2 matt
319 1.2 matt if (bit < 0 || bit >= AT91PIO_NPINS)
320 1.2 matt return 0;
321 1.2 matt
322 1.2 matt ireq = &sc->ireq[bit];
323 1.2 matt
324 1.2 matt if (ireq->ireq_func) /* already used */
325 1.2 matt return 0;
326 1.2 matt
327 1.2 matt ireq->ireq_func = ireq_func;
328 1.2 matt ireq->ireq_arg = arg;
329 1.2 matt ireq->ireq_ipl = ipl;
330 1.2 matt
331 1.2 matt PIO_WRITE(sc, PIO_IDR, (1U << bit)); /* disable interrupt for now */
332 1.2 matt at91pio_in(sc, bit); /* make sure pin is input */
333 1.2 matt #if NGPIO > 0
334 1.2 matt sc->pins[bit].pin_caps = 0;
335 1.2 matt #endif
336 1.2 matt #if 0
337 1.2 matt if (flag & EDGE_TRIGGER)
338 1.2 matt at91pio_bit_set(sc, sc->xinttype1, bit);
339 1.2 matt else /* LEVEL_SENSE */
340 1.2 matt at91pio_bit_clear(sc, sc->xinttype1, bit);
341 1.2 matt if (flag & RISING_EDGE) /* or HIGH_LEVEL */
342 1.2 matt at91pio_bit_set(sc, sc->xinttype2, bit);
343 1.2 matt else /* FALLING_EDGE or LOW_LEVEL */
344 1.2 matt at91pio_bit_clear(sc, sc->xinttype2, bit);
345 1.2 matt if (flag & DEBOUNCE)
346 1.2 matt PIO_WRITE(sc, PIO_IFER, (1U << bit));
347 1.2 matt else
348 1.2 matt PIO_WRITE(sc, PIO_IFDR, (1U << bit));
349 1.2 matt #endif
350 1.2 matt
351 1.2 matt if (!sc->ih) {
352 1.2 matt // use IPL_BIO because we want lowest possible priority as
353 1.2 matt // we really don't know what priority is going to be used by
354 1.2 matt // the caller.. this is not really optimal but tell me a
355 1.2 matt // better way
356 1.2 matt sc->ih = at91_intr_establish(sc->sc_pid, IPL_BIO, INTR_HIGH_LEVEL,
357 1.2 matt at91pio_intr, sc);
358 1.2 matt }
359 1.2 matt
360 1.2 matt //(void)PIO_READ(sc, PIO_ISR); // clear interrupts
361 1.2 matt PIO_WRITE(sc, PIO_IER, (1U << bit)); // enable interrupt
362 1.2 matt
363 1.2 matt return sc->ih;
364 1.2 matt }
365 1.2 matt
366 1.2 matt void
367 1.2 matt at91pio_intr_disestablish(struct at91pio_softc *sc, int bit, void *cookie)
368 1.2 matt {
369 1.2 matt struct intr_req *ireq;
370 1.2 matt int i;
371 1.2 matt
372 1.2 matt DPRINTFN(1, ("at91pio_intr_disestablish: port=%s, bit=%d\n", at91_peripheral_name(sc->sc_pid), bit));
373 1.2 matt
374 1.2 matt if (bit < 0 || bit >= AT91PIO_NPINS)
375 1.2 matt return;
376 1.2 matt
377 1.2 matt if (cookie != sc->ih)
378 1.2 matt return;
379 1.2 matt
380 1.2 matt ireq = &sc->ireq[bit];
381 1.2 matt
382 1.2 matt if (!ireq->ireq_func)
383 1.2 matt return;
384 1.2 matt
385 1.2 matt PIO_WRITE(sc, PIO_IDR, (1U << bit));
386 1.2 matt ireq->ireq_func = 0;
387 1.2 matt ireq->ireq_arg = 0;
388 1.2 matt
389 1.2 matt for (i = 0; i < AT91PIO_NPINS; i++) {
390 1.2 matt if (sc->ireq[i].ireq_func)
391 1.2 matt break;
392 1.2 matt }
393 1.2 matt
394 1.2 matt if (i >= AT91PIO_NPINS) {
395 1.2 matt at91_intr_disestablish(sc->ih);
396 1.2 matt sc->ih = 0;
397 1.2 matt }
398 1.2 matt }
399 1.2 matt
400 1.2 matt static int
401 1.2 matt at91pio_intr(void *arg)
402 1.2 matt {
403 1.2 matt struct at91pio_softc *sc = arg;
404 1.2 matt int bit;
405 1.2 matt u_int32_t isr;
406 1.2 matt
407 1.2 matt isr = (PIO_READ(sc, PIO_ISR) & PIO_READ(sc, PIO_IMR));
408 1.2 matt if (!isr)
409 1.2 matt return 0;
410 1.2 matt
411 1.2 matt do {
412 1.2 matt bit = ffs(isr) - 1;
413 1.2 matt isr &= ~(1U << bit);
414 1.2 matt #ifdef DIAGNOSTIC
415 1.2 matt if (bit < 0)
416 1.2 matt panic("%s: isr is zero (0x%X)", __FUNCTION__, isr);
417 1.2 matt #endif
418 1.2 matt if (sc->ireq[bit].ireq_func) {
419 1.2 matt int s = _splraise(sc->ireq[bit].ireq_ipl);
420 1.2 matt (*sc->ireq[bit].ireq_func)(sc->ireq[bit].ireq_arg);
421 1.2 matt splx(s);
422 1.2 matt }
423 1.2 matt } while (isr);
424 1.2 matt
425 1.2 matt return 1;
426 1.2 matt }
427 1.2 matt
428 1.2 matt
429 1.2 matt #if NGPIO > 0
430 1.2 matt static int
431 1.2 matt at91pio_pin_read(void *arg, int pin)
432 1.2 matt {
433 1.2 matt struct at91pio_softc *sc = arg;
434 1.2 matt
435 1.2 matt pin %= AT91PIO_NPINS;
436 1.2 matt if (!sc->pins[pin].pin_caps)
437 1.2 matt return 0; /* EBUSY? */
438 1.2 matt
439 1.2 matt return (PIO_READ(sc, PIO_PDSR) >> pin) & 1;
440 1.2 matt }
441 1.2 matt
442 1.2 matt static void
443 1.2 matt at91pio_pin_write(void *arg, int pin, int val)
444 1.2 matt {
445 1.2 matt struct at91pio_softc *sc = arg;
446 1.2 matt
447 1.2 matt pin %= AT91PIO_NPINS;
448 1.2 matt if (!sc->pins[pin].pin_caps)
449 1.2 matt return;
450 1.2 matt
451 1.2 matt if (val)
452 1.2 matt PIO_WRITE(sc, PIO_SODR, (1U << pin));
453 1.2 matt else
454 1.2 matt PIO_WRITE(sc, PIO_CODR, (1U << pin));
455 1.2 matt }
456 1.2 matt
457 1.2 matt static void
458 1.2 matt at91pio_pin_ctl(void *arg, int pin, int flags)
459 1.2 matt {
460 1.2 matt struct at91pio_softc *sc = arg;
461 1.2 matt
462 1.2 matt pin %= AT91PIO_NPINS;
463 1.2 matt if (!sc->pins[pin].pin_caps)
464 1.2 matt return;
465 1.2 matt
466 1.2 matt if (flags & GPIO_PIN_INPUT)
467 1.2 matt PIO_WRITE(sc, PIO_ODR, (1U << pin));
468 1.2 matt else if (flags & GPIO_PIN_OUTPUT)
469 1.2 matt PIO_WRITE(sc, PIO_OER, (1U << pin));
470 1.2 matt
471 1.2 matt if (flags & GPIO_PIN_OPENDRAIN)
472 1.2 matt PIO_WRITE(sc, PIO_MDER, (1U << pin));
473 1.2 matt else if (flags & GPIO_PIN_PUSHPULL)
474 1.2 matt PIO_WRITE(sc, PIO_MDDR, (1U << pin));
475 1.2 matt
476 1.2 matt if (flags & GPIO_PIN_PULLUP)
477 1.2 matt PIO_WRITE(sc, PIO_PUER, (1U << pin));
478 1.2 matt else
479 1.2 matt PIO_WRITE(sc, PIO_PUDR, (1U << pin));
480 1.2 matt }
481 1.2 matt #endif
482 1.2 matt
483