1 1.8 thorpej /* $Id: at91pio.c,v 1.8 2021/08/07 16:18:43 thorpej Exp $ */ 2 1.8 thorpej /* $NetBSD: at91pio.c,v 1.8 2021/08/07 16:18:43 thorpej 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.8 thorpej __KERNEL_RCSID(0, "$NetBSD: at91pio.c,v 1.8 2021/08/07 16:18:43 thorpej 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.7 thorpej config_found(self, &gba, at91piobus_print, 187 1.8 thorpej CFARGS(.iattr = "gpiobus")); 188 1.2 matt #endif 189 1.2 matt 190 1.2 matt /* attach device */ 191 1.7 thorpej config_search(self, NULL, 192 1.8 thorpej CFARGS(.search = at91pio_search, 193 1.8 thorpej .iattr = "at91pio")); 194 1.2 matt } 195 1.2 matt 196 1.2 matt #if NGPIO > 0 197 1.2 matt static int 198 1.2 matt at91piobus_print(void *aux, const char *name) 199 1.2 matt { 200 1.2 matt struct gpiobus_attach_args *gba = aux; 201 1.2 matt struct at91pio_softc *sc = (struct at91pio_softc *)gba->gba_gc->gp_cookie; 202 1.2 matt 203 1.2 matt gpiobus_print(aux, name); 204 1.2 matt aprint_normal(": port %s (mask %08"PRIX32")", 205 1.2 matt at91_peripheral_name(sc->sc_pid), 206 1.2 matt at91_gpio_mask(sc->sc_pid)); 207 1.2 matt 208 1.2 matt return (UNCONF); 209 1.2 matt } 210 1.2 matt #endif 211 1.2 matt 212 1.2 matt 213 1.2 matt static int 214 1.5 chs at91pio_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux) 215 1.2 matt { 216 1.5 chs struct at91pio_softc *sc = device_private(parent); 217 1.2 matt struct at91pio_attach_args paa; 218 1.2 matt 219 1.2 matt paa.paa_sc = sc; 220 1.2 matt paa.paa_iot = sc->sc_iot; 221 1.2 matt paa.paa_pid = cf->cf_loc[AT91PIOCF_PID]; 222 1.2 matt paa.paa_bit = cf->cf_loc[AT91PIOCF_BIT]; 223 1.2 matt 224 1.7 thorpej if (config_probe(parent, cf, &paa)) 225 1.8 thorpej config_attach(parent, cf, &paa, at91pio_print, CFARGS_NONE); 226 1.2 matt 227 1.2 matt return 0; 228 1.2 matt } 229 1.2 matt 230 1.2 matt static int 231 1.2 matt at91pio_print(void *aux, const char *name) 232 1.2 matt { 233 1.5 chs struct at91pio_attach_args *paa = aux; 234 1.2 matt 235 1.2 matt aprint_normal(":"); 236 1.2 matt if (paa->paa_pid > -1) 237 1.2 matt aprint_normal(" port %s", at91_peripheral_name(paa->paa_pid)); 238 1.2 matt if (paa->paa_bit > -1) 239 1.2 matt aprint_normal(" bit %d", paa->paa_bit); 240 1.2 matt 241 1.2 matt return (UNCONF); 242 1.2 matt } 243 1.2 matt 244 1.2 matt int 245 1.2 matt at91pio_read(struct at91pio_softc *sc, int bit) 246 1.2 matt { 247 1.2 matt #if NGPIO > 0 248 1.2 matt sc->pins[bit].pin_caps = 0; 249 1.2 matt #endif 250 1.2 matt return (PIO_READ(sc, PIO_PDSR) >> bit) & 1; 251 1.2 matt } 252 1.2 matt 253 1.2 matt void 254 1.2 matt at91pio_set(struct at91pio_softc *sc, int bit) 255 1.2 matt { 256 1.2 matt #if NGPIO > 0 257 1.2 matt sc->pins[bit].pin_caps = 0; 258 1.2 matt #endif 259 1.2 matt PIO_WRITE(sc, PIO_SODR, (1U << bit)); 260 1.2 matt } 261 1.2 matt 262 1.2 matt void 263 1.2 matt at91pio_clear(struct at91pio_softc *sc, int bit) 264 1.2 matt { 265 1.2 matt #if NGPIO > 0 266 1.2 matt sc->pins[bit].pin_caps = 0; 267 1.2 matt #endif 268 1.2 matt PIO_WRITE(sc, PIO_CODR, (1U << bit)); 269 1.2 matt } 270 1.2 matt 271 1.2 matt void 272 1.2 matt at91pio_in(struct at91pio_softc *sc, int bit) 273 1.2 matt { 274 1.2 matt #if NGPIO > 0 275 1.2 matt sc->pins[bit].pin_caps = 0; 276 1.2 matt #endif 277 1.2 matt PIO_WRITE(sc, PIO_ODR, (1U << bit)); 278 1.2 matt } 279 1.2 matt 280 1.2 matt void 281 1.2 matt at91pio_out(struct at91pio_softc *sc, int bit) 282 1.2 matt { 283 1.2 matt #if NGPIO > 0 284 1.2 matt sc->pins[bit].pin_caps = 0; 285 1.2 matt #endif 286 1.2 matt PIO_WRITE(sc, PIO_OER, (1U << bit)); 287 1.2 matt } 288 1.2 matt 289 1.2 matt void at91pio_per(struct at91pio_softc *sc, int bit, int perab) 290 1.2 matt { 291 1.2 matt #if NGPIO > 0 292 1.2 matt sc->pins[bit].pin_caps = 0; 293 1.2 matt #endif 294 1.2 matt switch (perab) { 295 1.2 matt case -1: 296 1.2 matt PIO_WRITE(sc, PIO_PER, (1U << bit)); 297 1.2 matt break; 298 1.2 matt case 0: 299 1.2 matt PIO_WRITE(sc, PIO_ASR, (1U << bit)); 300 1.2 matt PIO_WRITE(sc, PIO_PDR, (1U << bit)); 301 1.2 matt break; 302 1.2 matt case 1: 303 1.2 matt PIO_WRITE(sc, PIO_BSR, (1U << bit)); 304 1.2 matt PIO_WRITE(sc, PIO_PDR, (1U << bit)); 305 1.2 matt break; 306 1.2 matt default: 307 1.2 matt panic("%s: perab is invalid: %i", __FUNCTION__, perab); 308 1.2 matt break; 309 1.2 matt } 310 1.2 matt } 311 1.2 matt 312 1.2 matt void * 313 1.2 matt at91pio_intr_establish(struct at91pio_softc *sc, int bit, 314 1.2 matt int ipl, int (*ireq_func)(void *), void *arg) 315 1.2 matt { 316 1.2 matt struct intr_req *ireq; 317 1.2 matt 318 1.2 matt DPRINTFN(1, ("at91pio_intr_establish: port=%s, bit=%d\n", at91_peripheral_name(sc->sc_pid), bit)); 319 1.2 matt 320 1.2 matt if (bit < 0 || bit >= AT91PIO_NPINS) 321 1.2 matt return 0; 322 1.2 matt 323 1.2 matt ireq = &sc->ireq[bit]; 324 1.2 matt 325 1.2 matt if (ireq->ireq_func) /* already used */ 326 1.2 matt return 0; 327 1.2 matt 328 1.2 matt ireq->ireq_func = ireq_func; 329 1.2 matt ireq->ireq_arg = arg; 330 1.2 matt ireq->ireq_ipl = ipl; 331 1.2 matt 332 1.2 matt PIO_WRITE(sc, PIO_IDR, (1U << bit)); /* disable interrupt for now */ 333 1.2 matt at91pio_in(sc, bit); /* make sure pin is input */ 334 1.2 matt #if NGPIO > 0 335 1.2 matt sc->pins[bit].pin_caps = 0; 336 1.2 matt #endif 337 1.2 matt #if 0 338 1.2 matt if (flag & EDGE_TRIGGER) 339 1.2 matt at91pio_bit_set(sc, sc->xinttype1, bit); 340 1.2 matt else /* LEVEL_SENSE */ 341 1.2 matt at91pio_bit_clear(sc, sc->xinttype1, bit); 342 1.2 matt if (flag & RISING_EDGE) /* or HIGH_LEVEL */ 343 1.2 matt at91pio_bit_set(sc, sc->xinttype2, bit); 344 1.2 matt else /* FALLING_EDGE or LOW_LEVEL */ 345 1.2 matt at91pio_bit_clear(sc, sc->xinttype2, bit); 346 1.2 matt if (flag & DEBOUNCE) 347 1.2 matt PIO_WRITE(sc, PIO_IFER, (1U << bit)); 348 1.2 matt else 349 1.2 matt PIO_WRITE(sc, PIO_IFDR, (1U << bit)); 350 1.2 matt #endif 351 1.2 matt 352 1.2 matt if (!sc->ih) { 353 1.2 matt // use IPL_BIO because we want lowest possible priority as 354 1.2 matt // we really don't know what priority is going to be used by 355 1.2 matt // the caller.. this is not really optimal but tell me a 356 1.2 matt // better way 357 1.2 matt sc->ih = at91_intr_establish(sc->sc_pid, IPL_BIO, INTR_HIGH_LEVEL, 358 1.2 matt at91pio_intr, sc); 359 1.2 matt } 360 1.2 matt 361 1.2 matt //(void)PIO_READ(sc, PIO_ISR); // clear interrupts 362 1.2 matt PIO_WRITE(sc, PIO_IER, (1U << bit)); // enable interrupt 363 1.2 matt 364 1.2 matt return sc->ih; 365 1.2 matt } 366 1.2 matt 367 1.2 matt void 368 1.2 matt at91pio_intr_disestablish(struct at91pio_softc *sc, int bit, void *cookie) 369 1.2 matt { 370 1.2 matt struct intr_req *ireq; 371 1.2 matt int i; 372 1.2 matt 373 1.2 matt DPRINTFN(1, ("at91pio_intr_disestablish: port=%s, bit=%d\n", at91_peripheral_name(sc->sc_pid), bit)); 374 1.2 matt 375 1.2 matt if (bit < 0 || bit >= AT91PIO_NPINS) 376 1.2 matt return; 377 1.2 matt 378 1.2 matt if (cookie != sc->ih) 379 1.2 matt return; 380 1.2 matt 381 1.2 matt ireq = &sc->ireq[bit]; 382 1.2 matt 383 1.2 matt if (!ireq->ireq_func) 384 1.2 matt return; 385 1.2 matt 386 1.2 matt PIO_WRITE(sc, PIO_IDR, (1U << bit)); 387 1.2 matt ireq->ireq_func = 0; 388 1.2 matt ireq->ireq_arg = 0; 389 1.2 matt 390 1.2 matt for (i = 0; i < AT91PIO_NPINS; i++) { 391 1.2 matt if (sc->ireq[i].ireq_func) 392 1.2 matt break; 393 1.2 matt } 394 1.2 matt 395 1.2 matt if (i >= AT91PIO_NPINS) { 396 1.2 matt at91_intr_disestablish(sc->ih); 397 1.2 matt sc->ih = 0; 398 1.2 matt } 399 1.2 matt } 400 1.2 matt 401 1.2 matt static int 402 1.2 matt at91pio_intr(void *arg) 403 1.2 matt { 404 1.2 matt struct at91pio_softc *sc = arg; 405 1.2 matt int bit; 406 1.6 skrll uint32_t isr; 407 1.2 matt 408 1.2 matt isr = (PIO_READ(sc, PIO_ISR) & PIO_READ(sc, PIO_IMR)); 409 1.2 matt if (!isr) 410 1.2 matt return 0; 411 1.2 matt 412 1.2 matt do { 413 1.2 matt bit = ffs(isr) - 1; 414 1.2 matt isr &= ~(1U << bit); 415 1.2 matt #ifdef DIAGNOSTIC 416 1.2 matt if (bit < 0) 417 1.2 matt panic("%s: isr is zero (0x%X)", __FUNCTION__, isr); 418 1.2 matt #endif 419 1.2 matt if (sc->ireq[bit].ireq_func) { 420 1.2 matt int s = _splraise(sc->ireq[bit].ireq_ipl); 421 1.2 matt (*sc->ireq[bit].ireq_func)(sc->ireq[bit].ireq_arg); 422 1.2 matt splx(s); 423 1.2 matt } 424 1.2 matt } while (isr); 425 1.2 matt 426 1.2 matt return 1; 427 1.2 matt } 428 1.2 matt 429 1.2 matt 430 1.2 matt #if NGPIO > 0 431 1.2 matt static int 432 1.2 matt at91pio_pin_read(void *arg, int pin) 433 1.2 matt { 434 1.2 matt struct at91pio_softc *sc = arg; 435 1.2 matt 436 1.2 matt pin %= AT91PIO_NPINS; 437 1.2 matt if (!sc->pins[pin].pin_caps) 438 1.2 matt return 0; /* EBUSY? */ 439 1.2 matt 440 1.2 matt return (PIO_READ(sc, PIO_PDSR) >> pin) & 1; 441 1.2 matt } 442 1.2 matt 443 1.2 matt static void 444 1.2 matt at91pio_pin_write(void *arg, int pin, int val) 445 1.2 matt { 446 1.2 matt struct at91pio_softc *sc = arg; 447 1.2 matt 448 1.2 matt pin %= AT91PIO_NPINS; 449 1.2 matt if (!sc->pins[pin].pin_caps) 450 1.2 matt return; 451 1.2 matt 452 1.2 matt if (val) 453 1.2 matt PIO_WRITE(sc, PIO_SODR, (1U << pin)); 454 1.2 matt else 455 1.2 matt PIO_WRITE(sc, PIO_CODR, (1U << pin)); 456 1.2 matt } 457 1.2 matt 458 1.2 matt static void 459 1.2 matt at91pio_pin_ctl(void *arg, int pin, int flags) 460 1.2 matt { 461 1.2 matt struct at91pio_softc *sc = arg; 462 1.2 matt 463 1.2 matt pin %= AT91PIO_NPINS; 464 1.2 matt if (!sc->pins[pin].pin_caps) 465 1.2 matt return; 466 1.2 matt 467 1.2 matt if (flags & GPIO_PIN_INPUT) 468 1.2 matt PIO_WRITE(sc, PIO_ODR, (1U << pin)); 469 1.2 matt else if (flags & GPIO_PIN_OUTPUT) 470 1.2 matt PIO_WRITE(sc, PIO_OER, (1U << pin)); 471 1.2 matt 472 1.2 matt if (flags & GPIO_PIN_OPENDRAIN) 473 1.2 matt PIO_WRITE(sc, PIO_MDER, (1U << pin)); 474 1.2 matt else if (flags & GPIO_PIN_PUSHPULL) 475 1.2 matt PIO_WRITE(sc, PIO_MDDR, (1U << pin)); 476 1.2 matt 477 1.2 matt if (flags & GPIO_PIN_PULLUP) 478 1.2 matt PIO_WRITE(sc, PIO_PUER, (1U << pin)); 479 1.2 matt else 480 1.2 matt PIO_WRITE(sc, PIO_PUDR, (1U << pin)); 481 1.2 matt } 482 1.2 matt #endif 483 1.2 matt 484