[BACK]Return to fuart.c CVS log [TXT][DIR] Up to [local] / prex-old / dev / arm / cats

Annotation of prex-old/dev/arm/cats/fuart.c, Revision 1.1

1.1     ! nbrk        1: /*
        !             2:  * $Id$
        !             3:  */
        !             4: #include <driver.h>
        !             5: #include <bus.h>
        !             6: #include <dev/ic/comvar.h>
        !             7:
        !             8: #include "fuartreg.h"
        !             9:
        !            10: struct fuart_softc {
        !            11:        bus_space_tag_t sc_iot;
        !            12:        bus_space_handle_t      sc_ioh;
        !            13:
        !            14:        struct uart_attach_args sc_uaa;
        !            15: };
        !            16:
        !            17: int            fuart_init(void *cookie, int speed, int mode);
        !            18: void   fuart_on(void *cookie);
        !            19: void   fuart_off(void *cookie);
        !            20: void   fuart_putc(void *cookie, int blocking, int c);
        !            21: int            fuart_getc(void *cookie, int blocking);
        !            22:
        !            23: /*
        !            24:  * Autoconf glue.
        !            25:  */
        !            26: int    fuart_match(struct device *parent, void *aux);
        !            27: int    fuart_attach(struct device *parent, struct device *self, void *aux);
        !            28:
        !            29: struct driver fuart_drv = {
        !            30:        "fuart",                                        /* name */
        !            31:        sizeof(struct fuart_softc),/* datasize */
        !            32:        fuart_match,                            /* match */
        !            33:        fuart_attach,                           /* attach */
        !            34:        NULL,                                           /* detach */
        !            35:        -1                                                      /* nunits XXX */
        !            36: };
        !            37:
        !            38:
        !            39:
        !            40: int
        !            41: fuart_match(struct device *parent, void *aux)
        !            42: {
        !            43:        if (strncmp(parent->dv_xname, "footbridge", CONFIG_XNAMELEN))
        !            44:                return(0);
        !            45:
        !            46:        /* matched */
        !            47:        return(1);
        !            48: }
        !            49:
        !            50:
        !            51: int
        !            52: fuart_attach(struct device *parent, struct device *self, void *aux)
        !            53: {
        !            54:        struct fuart_softc      *sc = self->dv_data;
        !            55:
        !            56:        /* acquire bus space tag from parent */
        !            57:        sc->sc_iot = (bus_space_tag_t)aux;
        !            58:
        !            59:        /* map base address */
        !            60:        bus_space_map(sc->sc_iot, FUART_BASE, FUART_SIZE, 0, &sc->sc_ioh);
        !            61:
        !            62:        printk("DC21285 UART\n");
        !            63:
        !            64:        /*
        !            65:         * Setup uart attach args and search for children.
        !            66:         */
        !            67:        sc->sc_uaa.ua_init = fuart_init;
        !            68:        sc->sc_uaa.ua_on = fuart_on;
        !            69:        sc->sc_uaa.ua_off = fuart_off;
        !            70:        sc->sc_uaa.ua_putc = fuart_putc;
        !            71:        sc->sc_uaa.ua_getc = fuart_getc;
        !            72:        sc->sc_uaa.ua_cookie = sc;
        !            73:
        !            74:        config_search_children(self, &sc->sc_uaa);
        !            75:
        !            76:        return(0);
        !            77: }
        !            78:
        !            79:
        !            80: int
        !            81: fuart_init(void *cookie, int speed, int mode)
        !            82: {
        !            83:        struct fuart_softc *sc = cookie;
        !            84:
        !            85:        /* TODO */
        !            86:
        !            87:        /* set operation mode */
        !            88:        bus_space_write_4(sc->sc_iot, sc->sc_ioh, H_UBRLCR, 0x60 /*8bits*/);
        !            89:
        !            90:        return(0);
        !            91: }
        !            92:
        !            93:
        !            94: void
        !            95: fuart_on(void *cookie)
        !            96: {
        !            97:        struct fuart_softc *sc = cookie;
        !            98:
        !            99:        /* enable hardware */
        !           100:        bus_space_write_4(sc->sc_iot, sc->sc_ioh, UARTCON, 1);
        !           101:
        !           102:
        !           103: }
        !           104:
        !           105:
        !           106: void
        !           107: fuart_off(void *cookie)
        !           108: {
        !           109:        struct fuart_softc *sc = cookie;
        !           110:
        !           111:        /* disable hardware */
        !           112:        bus_space_write_4(sc->sc_iot, sc->sc_ioh, UARTCON, 0);
        !           113: }
        !           114:
        !           115:
        !           116: void
        !           117: fuart_putc(void *cookie, int blocking, int c)
        !           118: {
        !           119:        /* TODO: non-blocking mode */
        !           120:        struct fuart_softc *sc = cookie;
        !           121:
        !           122:        /* wait for transmitter to be ready */
        !           123:        while (bus_space_read_4(sc->sc_iot, sc->sc_ioh, UARTFLG) & 0x08 /*TXBSY*/)
        !           124:                ;
        !           125:
        !           126:        bus_space_write_4(sc->sc_iot, sc->sc_ioh, UARTDR, c);
        !           127: }
        !           128:
        !           129:
        !           130: int
        !           131: fuart_getc(void *cookie, int blocking)
        !           132: {
        !           133:        /* TODO: non-blocking mode */
        !           134:        struct fuart_softc *sc = cookie;
        !           135:
        !           136:        while (bus_space_read_4(sc->sc_iot, sc->sc_ioh, UARTFLG) & 0x10 /* RXFIFO */)
        !           137:                ;
        !           138:
        !           139:        bus_space_read_4(sc->sc_iot, sc->sc_ioh, UARTDR);
        !           140: }
        !           141:

CVSweb