Home | History | Annotate | Line # | Download | only in dev
ipaq_atmelgpio.c revision 1.1
      1  1.1  ichiro /*	$NetBSD: ipaq_atmelgpio.c,v 1.1 2001/08/01 07:59:43 ichiro Exp $	*/
      2  1.1  ichiro 
      3  1.1  ichiro /*-
      4  1.1  ichiro  * Copyright (c) 2001 The NetBSD Foundation, Inc.  All rights reserved.
      5  1.1  ichiro  *
      6  1.1  ichiro  * This code is derived from software contributed to The NetBSD Foundation
      7  1.1  ichiro  * by Ichiro FUKUHARA (ichiro (at) ichiro.org).
      8  1.1  ichiro  *
      9  1.1  ichiro  * Redistribution and use in source and binary forms, with or without
     10  1.1  ichiro  * modification, are permitted provided that the following conditions
     11  1.1  ichiro  * are met:
     12  1.1  ichiro  * 1. Redistributions of source code must retain the above copyright
     13  1.1  ichiro  *    notice, this list of conditions and the following disclaimer.
     14  1.1  ichiro  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  ichiro  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  ichiro  *    documentation and/or other materials provided with the distribution.
     17  1.1  ichiro  * 3. All advertising materials mentioning features or use of this software
     18  1.1  ichiro  *    must display the following acknowledgement:
     19  1.1  ichiro  *	This product includes software developed by the NetBSD
     20  1.1  ichiro  *	Foundation, Inc. and its contributors.
     21  1.1  ichiro  * 4. Neither the name of The NetBSD Foundation nor the names of its
     22  1.1  ichiro  *    contributors may be used to endorse or promote products derived
     23  1.1  ichiro  *    from this software without specific prior written permission.
     24  1.1  ichiro  *
     25  1.1  ichiro  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     26  1.1  ichiro  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1  ichiro  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1  ichiro  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     29  1.1  ichiro  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1  ichiro  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1  ichiro  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1  ichiro  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1  ichiro  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1  ichiro  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1  ichiro  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1  ichiro  */
     37  1.1  ichiro /*
     38  1.1  ichiro  * iPAQ uses Atmel microcontroller to service a few of peripheral devices.
     39  1.1  ichiro  * This controller connect to UART1 of SA11x0.
     40  1.1  ichiro  */
     41  1.1  ichiro 
     42  1.1  ichiro #include <sys/param.h>
     43  1.1  ichiro #include <sys/systm.h>
     44  1.1  ichiro #include <sys/types.h>
     45  1.1  ichiro #include <sys/conf.h>
     46  1.1  ichiro #include <sys/file.h>
     47  1.1  ichiro #include <sys/device.h>
     48  1.1  ichiro #include <sys/kernel.h>
     49  1.1  ichiro #include <sys/kthread.h>
     50  1.1  ichiro #include <sys/malloc.h>
     51  1.1  ichiro 
     52  1.1  ichiro #include <machine/bus.h>
     53  1.1  ichiro 
     54  1.1  ichiro #include <hpcarm/dev/ipaq_saipvar.h>
     55  1.1  ichiro #include <hpcarm/dev/ipaq_gpioreg.h>
     56  1.1  ichiro #include <hpcarm/dev/ipaq_atmel.h>
     57  1.1  ichiro #include <hpcarm/sa11x0/sa11x0_comreg.h>
     58  1.1  ichiro #include <hpcarm/sa11x0/sa11x0_reg.h>
     59  1.1  ichiro 
     60  1.1  ichiro struct atmelgpio_softc {
     61  1.1  ichiro 	struct device		sc_dev;
     62  1.1  ichiro 	bus_space_tag_t		sc_iot;
     63  1.1  ichiro 	bus_space_handle_t	sc_ioh;
     64  1.1  ichiro 	struct ipaq_softc	*sc_parent;
     65  1.1  ichiro };
     66  1.1  ichiro 
     67  1.1  ichiro static	int	atmelgpio_match(struct device *, struct cfdata *, void *);
     68  1.1  ichiro static	void	atmelgpio_attach(struct device *, struct device *, void *);
     69  1.1  ichiro static	int	atmelgpio_print(void *, const char *);
     70  1.1  ichiro static	int	atmelgpio_search(struct device *, struct cfdata *, void *);
     71  1.1  ichiro static	void	atmelgpio_init(struct atmelgpio_softc *);
     72  1.1  ichiro 
     73  1.1  ichiro struct cfattach atmelgpio_ca = {
     74  1.1  ichiro 	sizeof(struct atmelgpio_softc), atmelgpio_match, atmelgpio_attach
     75  1.1  ichiro };
     76  1.1  ichiro 
     77  1.1  ichiro static int
     78  1.1  ichiro atmelgpio_match(parent, cf, aux)
     79  1.1  ichiro 	struct device *parent;
     80  1.1  ichiro 	struct cfdata *cf;
     81  1.1  ichiro 	void *aux;
     82  1.1  ichiro {
     83  1.1  ichiro 	return (1);
     84  1.1  ichiro }
     85  1.1  ichiro 
     86  1.1  ichiro static void
     87  1.1  ichiro atmelgpio_attach(parent, self, aux)
     88  1.1  ichiro 	struct device *parent;
     89  1.1  ichiro 	struct device *self;
     90  1.1  ichiro 	void *aux;
     91  1.1  ichiro {
     92  1.1  ichiro 	struct atmelgpio_softc *sc = (struct atmelgpio_softc *)self;
     93  1.1  ichiro 	struct ipaq_softc *psc = (struct ipaq_softc *)parent;
     94  1.1  ichiro 
     95  1.1  ichiro 	printf("\n");
     96  1.1  ichiro 	printf("%s: Atmel microcontroller GPIO\n",  sc->sc_dev.dv_xname);
     97  1.1  ichiro 
     98  1.1  ichiro 	sc->sc_iot = psc->sc_iot;
     99  1.1  ichiro 	sc->sc_ioh = psc->sc_ioh;
    100  1.1  ichiro 	sc->sc_parent = (struct ipaq_softc *)parent;
    101  1.1  ichiro 
    102  1.1  ichiro 	if (bus_space_map(sc->sc_iot, SACOM1_BASE, SACOM_NPORTS, 0,
    103  1.1  ichiro                         &sc->sc_ioh)) {
    104  1.1  ichiro                 printf("%s: unable to map of UART1 registers\n", sc->sc_dev.dv_xname);
    105  1.1  ichiro                 return;
    106  1.1  ichiro         }
    107  1.1  ichiro 
    108  1.1  ichiro 	atmelgpio_init(sc);
    109  1.1  ichiro 
    110  1.1  ichiro 	/*
    111  1.1  ichiro 	 *  Attach each devices
    112  1.1  ichiro 	 */
    113  1.1  ichiro 
    114  1.1  ichiro 	config_search(atmelgpio_search, self, NULL);
    115  1.1  ichiro }
    116  1.1  ichiro 
    117  1.1  ichiro static int
    118  1.1  ichiro atmelgpio_search(parent, cf, aux)
    119  1.1  ichiro 	struct device *parent;
    120  1.1  ichiro 	struct cfdata *cf;
    121  1.1  ichiro 	void *aux;
    122  1.1  ichiro {
    123  1.1  ichiro 	if ((*cf->cf_attach->ca_match)(parent, cf, NULL) > 0)
    124  1.1  ichiro 		config_attach(parent, cf, NULL, atmelgpio_print);
    125  1.1  ichiro 	return 0;
    126  1.1  ichiro }
    127  1.1  ichiro 
    128  1.1  ichiro 
    129  1.1  ichiro static int
    130  1.1  ichiro atmelgpio_print(aux, name)
    131  1.1  ichiro 	void *aux;
    132  1.1  ichiro 	const char *name;
    133  1.1  ichiro {
    134  1.1  ichiro 	return (UNCONF);
    135  1.1  ichiro }
    136  1.1  ichiro 
    137  1.1  ichiro static void
    138  1.1  ichiro atmelgpio_init(sc)
    139  1.1  ichiro 	struct atmelgpio_softc *sc;
    140  1.1  ichiro {
    141  1.1  ichiro 	/* 8 bits no parity 1 stop bit */
    142  1.1  ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACOM_CR0, CR0_DSS);
    143  1.1  ichiro 
    144  1.1  ichiro 	/* Set baud rate 115k */
    145  1.1  ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACOM_CR1, 0);
    146  1.1  ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACOM_CR2, SACOMSPEED(115200));
    147  1.1  ichiro }
    148