Home | History | Annotate | Line # | Download | only in xscale
pxa2x0_com.c revision 1.7.24.2
      1  1.7.24.2     chris /*	$NetBSD: pxa2x0_com.c,v 1.7.24.2 2008/03/21 13:34:41 chris 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.4     lukem 
     38       1.4     lukem #include <sys/cdefs.h>
     39  1.7.24.2     chris __KERNEL_RCSID(0, "$NetBSD: pxa2x0_com.c,v 1.7.24.2 2008/03/21 13:34:41 chris Exp $");
     40       1.1       scw 
     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.7.24.1     chris #include <arm/xscale/pxa2x0cpu.h>
     59       1.1       scw #include <arm/xscale/pxa2x0reg.h>
     60       1.1       scw #include <arm/xscale/pxa2x0var.h>
     61  1.7.24.1     chris #include <arm/xscale/pxa2x0_gpio.h>
     62       1.1       scw 
     63       1.1       scw #include "locators.h"
     64       1.1       scw 
     65  1.7.24.2     chris static int	pxauart_match(device_t, cfdata_t , void *);
     66  1.7.24.2     chris static void	pxauart_attach(device_t, device_t, void *);
     67       1.1       scw 
     68  1.7.24.2     chris CFATTACH_DECL_NEW(pxauart, sizeof(struct com_softc),
     69       1.1       scw     pxauart_match, pxauart_attach, NULL, NULL);
     70       1.1       scw 
     71       1.1       scw static int
     72  1.7.24.2     chris pxauart_match(device_t parent, cfdata_t cf, void *aux)
     73       1.1       scw {
     74       1.1       scw 	struct pxaip_attach_args *pxa = aux;
     75       1.1       scw 	bus_space_tag_t bt = &pxa2x0_a4x_bs_tag;	/* XXX: This sucks */
     76       1.1       scw 	bus_space_handle_t bh;
     77  1.7.24.1     chris 	struct pxa2x0_gpioconf *gpioconf;
     78  1.7.24.1     chris 	u_int gpio;
     79  1.7.24.1     chris 	int rv, i;
     80       1.1       scw 
     81       1.1       scw 	switch (pxa->pxa_addr) {
     82       1.1       scw 	case PXA2X0_FFUART_BASE:
     83       1.1       scw 		if (pxa->pxa_intr != PXA2X0_INT_FFUART)
     84       1.1       scw 			return (0);
     85  1.7.24.1     chris 		gpioconf = CPU_IS_PXA250 ? pxa25x_com_ffuart_gpioconf :
     86  1.7.24.1     chris 			    pxa27x_com_ffuart_gpioconf;
     87       1.1       scw 		break;
     88       1.1       scw 
     89       1.1       scw 	case PXA2X0_STUART_BASE:
     90       1.1       scw 		if (pxa->pxa_intr != PXA2X0_INT_STUART)
     91       1.1       scw 			return (0);
     92  1.7.24.1     chris 		gpioconf = CPU_IS_PXA250 ? pxa25x_com_stuart_gpioconf :
     93  1.7.24.1     chris 			    pxa27x_com_stuart_gpioconf;
     94       1.1       scw 		break;
     95       1.1       scw 
     96       1.1       scw 	case PXA2X0_BTUART_BASE:	/* XXX: Config file option ... */
     97       1.1       scw 		if (pxa->pxa_intr != PXA2X0_INT_BTUART)
     98       1.1       scw 			return (0);
     99  1.7.24.1     chris 		gpioconf = CPU_IS_PXA250 ? pxa25x_com_btuart_gpioconf :
    100  1.7.24.1     chris 			    pxa27x_com_btuart_gpioconf;
    101       1.1       scw 		break;
    102       1.1       scw 
    103       1.7  kiyohara 	case PXA2X0_HWUART_BASE:
    104       1.7  kiyohara 		if (pxa->pxa_intr != PXA2X0_INT_HWUART)
    105       1.7  kiyohara 			return (0);
    106  1.7.24.1     chris 		gpioconf = CPU_IS_PXA250 ? pxa25x_com_hwuart_gpioconf :
    107  1.7.24.1     chris 			    pxa27x_com_hwuart_gpioconf;
    108       1.7  kiyohara 		break;
    109       1.7  kiyohara 
    110       1.1       scw 	default:
    111       1.1       scw 		return (0);
    112       1.1       scw 	}
    113  1.7.24.1     chris 	for (i = 0; gpioconf[i].pin != -1; i++) {
    114  1.7.24.1     chris 		gpio = pxa2x0_gpio_get_function(gpioconf[i].pin);
    115  1.7.24.1     chris 		if (GPIO_FN(gpio) != GPIO_FN(gpioconf[i].value) ||
    116  1.7.24.1     chris 		    GPIO_FN_IS_OUT(gpio) != GPIO_FN_IS_OUT(gpioconf[i].value))
    117  1.7.24.1     chris 			return (0);
    118  1.7.24.1     chris 	}
    119       1.1       scw 
    120       1.1       scw 	pxa->pxa_size = 0x20;
    121       1.1       scw 
    122       1.1       scw 	if (com_is_console(bt, pxa->pxa_addr, NULL))
    123       1.1       scw 		return (1);
    124       1.1       scw 
    125       1.1       scw 	if (bus_space_map(bt, pxa->pxa_addr, pxa->pxa_size, 0, &bh))
    126       1.1       scw 		return (0);
    127       1.1       scw 
    128       1.1       scw 	/* Make sure the UART is enabled */
    129       1.1       scw 	bus_space_write_1(bt, bh, com_ier, IER_EUART);
    130       1.1       scw 
    131       1.1       scw 	rv = comprobe1(bt, bh);
    132       1.1       scw 	bus_space_unmap(bt, bh, pxa->pxa_size);
    133       1.1       scw 
    134       1.1       scw 	return (rv);
    135       1.1       scw }
    136       1.1       scw 
    137       1.1       scw static void
    138  1.7.24.2     chris pxauart_attach(device_t parent, device_t self, void *aux)
    139       1.1       scw {
    140  1.7.24.2     chris 	struct com_softc *sc = device_private(self);
    141       1.1       scw 	struct pxaip_attach_args *pxa = aux;
    142       1.6   gdamore 	bus_space_tag_t iot;
    143       1.6   gdamore 	bus_space_handle_t ioh;
    144       1.6   gdamore 	bus_addr_t iobase;
    145       1.1       scw 
    146  1.7.24.2     chris 	sc->sc_dev = self;
    147       1.6   gdamore 	iot = &pxa2x0_a4x_bs_tag;	/* XXX: This sucks */
    148       1.6   gdamore 	iobase = pxa->pxa_addr;
    149       1.1       scw 	sc->sc_frequency = PXA2X0_COM_FREQ;
    150       1.2   thorpej 	sc->sc_type = COM_TYPE_PXA2x0;
    151       1.1       scw 
    152       1.6   gdamore 	if (com_is_console(iot, iobase, &ioh) == 0 &&
    153       1.6   gdamore 	    bus_space_map(iot, iobase, pxa->pxa_size, 0, &ioh)) {
    154  1.7.24.2     chris 		aprint_error(": can't map registers\n");
    155       1.1       scw 		return;
    156       1.1       scw 	}
    157       1.6   gdamore 	COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase);
    158       1.1       scw 
    159       1.1       scw 	com_attach_subr(sc);
    160       1.1       scw 
    161       1.1       scw 	pxa2x0_intr_establish(pxa->pxa_intr, IPL_SERIAL, comintr, sc);
    162       1.1       scw }
    163