Home | History | Annotate | Line # | Download | only in xscale
pxa2x0_com.c revision 1.3.2.1
      1  1.3.2.1    skrll /*	$NetBSD: pxa2x0_com.c,v 1.3.2.1 2004/08/03 10:32:58 skrll Exp $	*/
      2      1.1      scw 
      3      1.1      scw /*
      4      1.1      scw  * Copyright 2003 Wasabi Systems, Inc.
      5      1.1      scw  * All rights reserved.
      6      1.1      scw  *
      7      1.1      scw  * Written by Steve C. Woodford for Wasabi Systems, Inc.
      8      1.1      scw  *
      9      1.1      scw  * Redistribution and use in source and binary forms, with or without
     10      1.1      scw  * modification, are permitted provided that the following conditions
     11      1.1      scw  * are met:
     12      1.1      scw  * 1. Redistributions of source code must retain the above copyright
     13      1.1      scw  *    notice, this list of conditions and the following disclaimer.
     14      1.1      scw  * 2. Redistributions in binary form must reproduce the above copyright
     15      1.1      scw  *    notice, this list of conditions and the following disclaimer in the
     16      1.1      scw  *    documentation and/or other materials provided with the distribution.
     17      1.1      scw  * 3. All advertising materials mentioning features or use of this software
     18      1.1      scw  *    must display the following acknowledgement:
     19      1.1      scw  *      This product includes software developed for the NetBSD Project by
     20      1.1      scw  *      Wasabi Systems, Inc.
     21      1.1      scw  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22      1.1      scw  *    or promote products derived from this software without specific prior
     23      1.1      scw  *    written permission.
     24      1.1      scw  *
     25      1.1      scw  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26      1.1      scw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27      1.1      scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28      1.1      scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29      1.1      scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30      1.1      scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31      1.1      scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32      1.1      scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33      1.1      scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34      1.1      scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35      1.1      scw  * POSSIBILITY OF SUCH DAMAGE.
     36      1.1      scw  */
     37      1.1      scw 
     38  1.3.2.1    skrll #include <sys/cdefs.h>
     39  1.3.2.1    skrll __KERNEL_RCSID(0, "$NetBSD: pxa2x0_com.c,v 1.3.2.1 2004/08/03 10:32:58 skrll Exp $");
     40  1.3.2.1    skrll 
     41      1.1      scw #include "opt_com.h"
     42      1.1      scw 
     43      1.1      scw #ifndef COM_PXA2X0
     44      1.1      scw #error "You must use options COM_PXA2X0 to get PXA2x0 serial port support"
     45      1.1      scw #endif
     46      1.1      scw 
     47      1.1      scw #include <sys/param.h>
     48      1.1      scw #include <sys/systm.h>
     49      1.1      scw #include <sys/device.h>
     50      1.1      scw #include <sys/termios.h>
     51      1.1      scw 
     52      1.1      scw #include <machine/intr.h>
     53      1.1      scw #include <machine/bus.h>
     54      1.1      scw 
     55      1.1      scw #include <dev/ic/comreg.h>
     56      1.1      scw #include <dev/ic/comvar.h>
     57      1.1      scw 
     58      1.1      scw #include <arm/xscale/pxa2x0reg.h>
     59      1.1      scw #include <arm/xscale/pxa2x0var.h>
     60      1.1      scw 
     61      1.1      scw #include "locators.h"
     62      1.1      scw 
     63      1.1      scw static int	pxauart_match(struct device *, struct cfdata *, void *);
     64      1.1      scw static void	pxauart_attach(struct device *, struct device *, void *);
     65      1.1      scw 
     66      1.1      scw CFATTACH_DECL(pxauart, sizeof(struct com_softc),
     67      1.1      scw     pxauart_match, pxauart_attach, NULL, NULL);
     68      1.1      scw 
     69      1.1      scw static int
     70      1.1      scw pxauart_match(struct device *parent, struct cfdata *cf, void *aux)
     71      1.1      scw {
     72      1.1      scw 	struct pxaip_attach_args *pxa = aux;
     73      1.1      scw 	bus_space_tag_t bt = &pxa2x0_a4x_bs_tag;	/* XXX: This sucks */
     74      1.1      scw 	bus_space_handle_t bh;
     75      1.1      scw 	int rv;
     76      1.1      scw 
     77      1.1      scw 	switch (pxa->pxa_addr) {
     78      1.1      scw 	case PXA2X0_FFUART_BASE:
     79      1.1      scw 		if (pxa->pxa_intr != PXA2X0_INT_FFUART)
     80      1.1      scw 			return (0);
     81      1.1      scw 		break;
     82      1.1      scw 
     83      1.1      scw 	case PXA2X0_STUART_BASE:
     84      1.1      scw 		if (pxa->pxa_intr != PXA2X0_INT_STUART)
     85      1.1      scw 			return (0);
     86      1.1      scw 		break;
     87      1.1      scw 
     88      1.1      scw 	case PXA2X0_BTUART_BASE:	/* XXX: Config file option ... */
     89      1.1      scw 		if (pxa->pxa_intr != PXA2X0_INT_BTUART)
     90      1.1      scw 			return (0);
     91      1.1      scw 		break;
     92      1.1      scw 
     93      1.1      scw 	default:
     94      1.1      scw 		return (0);
     95      1.1      scw 	}
     96      1.1      scw 
     97      1.1      scw 	pxa->pxa_size = 0x20;
     98      1.1      scw 
     99      1.1      scw 	if (com_is_console(bt, pxa->pxa_addr, NULL))
    100      1.1      scw 		return (1);
    101      1.1      scw 
    102      1.1      scw 	if (bus_space_map(bt, pxa->pxa_addr, pxa->pxa_size, 0, &bh))
    103      1.1      scw 		return (0);
    104      1.1      scw 
    105      1.1      scw 	/* Make sure the UART is enabled */
    106      1.1      scw 	bus_space_write_1(bt, bh, com_ier, IER_EUART);
    107      1.1      scw 
    108      1.1      scw 	rv = comprobe1(bt, bh);
    109      1.1      scw 	bus_space_unmap(bt, bh, pxa->pxa_size);
    110      1.1      scw 
    111      1.1      scw 	return (rv);
    112      1.1      scw }
    113      1.1      scw 
    114      1.1      scw static void
    115      1.1      scw pxauart_attach(struct device *parent, struct device *self, void *aux)
    116      1.1      scw {
    117      1.1      scw 	struct com_softc *sc = (struct com_softc *)self;
    118      1.1      scw 	struct pxaip_attach_args *pxa = aux;
    119      1.1      scw 
    120      1.1      scw 	sc->sc_iot = &pxa2x0_a4x_bs_tag;	/* XXX: This sucks */
    121      1.1      scw 	sc->sc_iobase = pxa->pxa_addr;
    122      1.1      scw 	sc->sc_frequency = PXA2X0_COM_FREQ;
    123      1.2  thorpej 	sc->sc_type = COM_TYPE_PXA2x0;
    124      1.1      scw 
    125      1.1      scw 	if (com_is_console(sc->sc_iot, sc->sc_iobase, &sc->sc_ioh) == 0 &&
    126      1.1      scw 	    bus_space_map(sc->sc_iot, sc->sc_iobase, pxa->pxa_size, 0,
    127      1.1      scw 			  &sc->sc_ioh)) {
    128      1.1      scw 		printf(": can't map registers\n");
    129      1.1      scw 		return;
    130      1.1      scw 	}
    131      1.1      scw 
    132      1.1      scw 	com_attach_subr(sc);
    133      1.1      scw 
    134      1.1      scw 	pxa2x0_intr_establish(pxa->pxa_intr, IPL_SERIAL, comintr, sc);
    135      1.1      scw }
    136