/* * $Id: fuart.c,v 1.1 2008/08/08 13:18:16 nbrk Exp $ */ #include #include #include #include "fuartreg.h" struct fuart_softc { bus_space_tag_t sc_iot; bus_space_handle_t sc_ioh; struct uart_attach_args sc_uaa; }; int fuart_init(void *cookie, int speed, int mode); void fuart_on(void *cookie); void fuart_off(void *cookie); void fuart_putc(void *cookie, int blocking, int c); int fuart_getc(void *cookie, int blocking); /* * Autoconf glue. */ int fuart_match(struct device *parent, void *aux); int fuart_attach(struct device *parent, struct device *self, void *aux); struct driver fuart_drv = { "fuart", /* name */ sizeof(struct fuart_softc),/* datasize */ fuart_match, /* match */ fuart_attach, /* attach */ NULL, /* detach */ -1 /* nunits XXX */ }; int fuart_match(struct device *parent, void *aux) { if (strncmp(parent->dv_xname, "footbridge", CONFIG_XNAMELEN)) return(0); /* matched */ return(1); } int fuart_attach(struct device *parent, struct device *self, void *aux) { struct fuart_softc *sc = self->dv_data; /* acquire bus space tag from parent */ sc->sc_iot = (bus_space_tag_t)aux; /* map base address */ bus_space_map(sc->sc_iot, FUART_BASE, FUART_SIZE, 0, &sc->sc_ioh); printk("DC21285 UART\n"); /* * Setup uart attach args and search for children. */ sc->sc_uaa.ua_init = fuart_init; sc->sc_uaa.ua_on = fuart_on; sc->sc_uaa.ua_off = fuart_off; sc->sc_uaa.ua_putc = fuart_putc; sc->sc_uaa.ua_getc = fuart_getc; sc->sc_uaa.ua_cookie = sc; config_search_children(self, &sc->sc_uaa); return(0); } int fuart_init(void *cookie, int speed, int mode) { struct fuart_softc *sc = cookie; /* TODO */ /* set operation mode */ bus_space_write_4(sc->sc_iot, sc->sc_ioh, H_UBRLCR, 0x60 /*8bits*/); return(0); } void fuart_on(void *cookie) { struct fuart_softc *sc = cookie; /* enable hardware */ bus_space_write_4(sc->sc_iot, sc->sc_ioh, UARTCON, 1); } void fuart_off(void *cookie) { struct fuart_softc *sc = cookie; /* disable hardware */ bus_space_write_4(sc->sc_iot, sc->sc_ioh, UARTCON, 0); } void fuart_putc(void *cookie, int blocking, int c) { /* TODO: non-blocking mode */ struct fuart_softc *sc = cookie; /* wait for transmitter to be ready */ while (bus_space_read_4(sc->sc_iot, sc->sc_ioh, UARTFLG) & 0x08 /*TXBSY*/) ; bus_space_write_4(sc->sc_iot, sc->sc_ioh, UARTDR, c); } int fuart_getc(void *cookie, int blocking) { /* TODO: non-blocking mode */ struct fuart_softc *sc = cookie; while (bus_space_read_4(sc->sc_iot, sc->sc_ioh, UARTFLG) & 0x10 /* RXFIFO */) ; bus_space_read_4(sc->sc_iot, sc->sc_ioh, UARTDR); }