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

File: [local] / prex-old / dev / arm / cats / fuart.c (download)

Revision 1.1, Fri Aug 8 13:18:16 2008 UTC (15 years, 9 months ago) by nbrk
Branch: MAIN
CVS Tags: HEAD

Start implementing basic hardware support for CATS, based on new autoconfiguration
mechanism. This effectively uses bus_space to abstract children of parents.
Some info about these drivers:
hostio is a host memory-mapped i/o - one and only child of 'root';
footbridge is just a proxy for now;
fuart is a DC21285 UART driver which fills uart_attach_args and attaches
com, which is machine independent driver;

This all is not finished yet (just quick hacks), but commit it so i could work at home.

/*
 * $Id: fuart.c,v 1.1 2008/08/08 13:18:16 nbrk Exp $
 */
#include <driver.h>
#include <bus.h>
#include <dev/ic/comvar.h>

#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);
}