Home | History | Annotate | Line # | Download | only in dev
j720ssp.c revision 1.28.4.1
      1  1.28.4.1  rpaulo /*	$NetBSD: j720ssp.c,v 1.28.4.1 2006/09/09 02:39:38 rpaulo Exp $	*/
      2       1.1  toshii 
      3       1.1  toshii /*-
      4  1.28.4.1  rpaulo  * Copyright (c) 2001, 2006 The NetBSD Foundation, Inc.
      5       1.1  toshii  * All rights reserved.
      6       1.1  toshii  *
      7       1.1  toshii  * This code is derived from software contributed to The NetBSD Foundation
      8  1.28.4.1  rpaulo  * by IWAMOTO Toshihiro.
      9       1.1  toshii  *
     10       1.1  toshii  * Redistribution and use in source and binary forms, with or without
     11       1.1  toshii  * modification, are permitted provided that the following conditions
     12       1.1  toshii  * are met:
     13       1.1  toshii  * 1. Redistributions of source code must retain the above copyright
     14       1.1  toshii  *    notice, this list of conditions and the following disclaimer.
     15       1.1  toshii  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1  toshii  *    notice, this list of conditions and the following disclaimer in the
     17       1.1  toshii  *    documentation and/or other materials provided with the distribution.
     18       1.1  toshii  * 3. All advertising materials mentioning features or use of this software
     19       1.1  toshii  *    must display the following acknowledgement:
     20       1.1  toshii  *        This product includes software developed by the NetBSD
     21       1.1  toshii  *        Foundation, Inc. and its contributors.
     22       1.1  toshii  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1  toshii  *    contributors may be used to endorse or promote products derived
     24       1.1  toshii  *    from this software without specific prior written permission.
     25       1.1  toshii  *
     26       1.1  toshii  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1  toshii  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1  toshii  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1  toshii  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1  toshii  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1  toshii  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1  toshii  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1  toshii  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1  toshii  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1  toshii  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1  toshii  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1  toshii  */
     38       1.1  toshii 
     39  1.28.4.1  rpaulo /* Jornada 720 SSP port. */
     40      1.18   lukem 
     41      1.18   lukem #include <sys/cdefs.h>
     42  1.28.4.1  rpaulo __KERNEL_RCSID(0, "$NetBSD: j720ssp.c,v 1.28.4.1 2006/09/09 02:39:38 rpaulo Exp $");
     43      1.10    manu 
     44       1.1  toshii #include <sys/param.h>
     45       1.1  toshii #include <sys/systm.h>
     46       1.1  toshii #include <sys/device.h>
     47       1.7  ichiro 
     48       1.7  ichiro #include <arm/sa11x0/sa11x0_var.h>
     49       1.7  ichiro #include <arm/sa11x0/sa11x0_gpioreg.h>
     50       1.7  ichiro #include <arm/sa11x0/sa11x0_ppcreg.h>
     51       1.7  ichiro #include <arm/sa11x0/sa11x0_sspreg.h>
     52       1.1  toshii 
     53  1.28.4.1  rpaulo #include <hpcarm/dev/j720sspvar.h>
     54       1.1  toshii 
     55  1.28.4.1  rpaulo #ifdef DEBUG
     56  1.28.4.1  rpaulo #define DPRINTF(arg)	printf arg
     57       1.1  toshii #else
     58  1.28.4.1  rpaulo #define DPRINTF(arg)	/* nothing */
     59       1.1  toshii #endif
     60       1.1  toshii 
     61  1.28.4.1  rpaulo #define BIT_INVERT(x)							\
     62  1.28.4.1  rpaulo 	do {								\
     63  1.28.4.1  rpaulo 		(x) = ((((x) & 0xf0) >> 4) | (((x) & 0x0f) << 4));	\
     64  1.28.4.1  rpaulo 		(x) = ((((x) & 0xcc) >> 2) | (((x) & 0x33) << 2));	\
     65  1.28.4.1  rpaulo 		(x) = ((((x) & 0xaa) >> 1) | (((x) & 0x55) << 1));	\
     66  1.28.4.1  rpaulo 	} while (0)
     67  1.28.4.1  rpaulo 
     68  1.28.4.1  rpaulo static int	j720ssp_match(struct device *, struct cfdata *, void *);
     69  1.28.4.1  rpaulo static void	j720ssp_attach(struct device *, struct device *, void *);
     70  1.28.4.1  rpaulo static int	j720ssp_search(struct device *, struct cfdata *,
     71  1.28.4.1  rpaulo 		    const int *, void *);
     72  1.28.4.1  rpaulo static int	j720ssp_print(void *, const char *);
     73       1.6  toshii 
     74  1.28.4.1  rpaulo CFATTACH_DECL(j720ssp, sizeof(struct j720ssp_softc),
     75  1.28.4.1  rpaulo     j720ssp_match, j720ssp_attach, NULL, NULL);
     76       1.1  toshii 
     77       1.1  toshii 
     78  1.28.4.1  rpaulo static int
     79  1.28.4.1  rpaulo j720ssp_match(struct device *parent, struct cfdata *cf, void *aux)
     80  1.28.4.1  rpaulo {
     81       1.1  toshii 
     82  1.28.4.1  rpaulo 	if (strcmp(cf->cf_name, "j720ssp") != 0)
     83  1.28.4.1  rpaulo 		return 0;
     84      1.10    manu 
     85  1.28.4.1  rpaulo 	return 1;
     86       1.1  toshii }
     87       1.1  toshii 
     88  1.28.4.1  rpaulo static void
     89  1.28.4.1  rpaulo j720ssp_attach(struct device *parent, struct device *self, void *aux)
     90       1.1  toshii {
     91       1.1  toshii 	struct j720ssp_softc *sc = (void *)self;
     92       1.1  toshii 	struct sa11x0_softc *psc = (void *)parent;
     93       1.1  toshii 	struct sa11x0_attach_args *sa = aux;
     94       1.1  toshii 
     95       1.1  toshii 	sc->sc_iot = psc->sc_iot;
     96       1.1  toshii 	sc->sc_gpioh = psc->sc_gpioh;
     97  1.28.4.1  rpaulo 	sc->sc_parent = psc;
     98  1.28.4.1  rpaulo 
     99       1.1  toshii 	if (bus_space_map(sc->sc_iot, sa->sa_addr, sa->sa_size, 0,
    100  1.28.4.1  rpaulo 	    &sc->sc_ssph)) {
    101  1.28.4.1  rpaulo 		printf(": unable to map SSP registers\n");
    102       1.1  toshii 		return;
    103       1.1  toshii 	}
    104       1.1  toshii 
    105  1.28.4.1  rpaulo 	printf("\n");
    106       1.6  toshii 
    107  1.28.4.1  rpaulo 	config_search_ia(j720ssp_search, self, "j720ssp", NULL);
    108       1.6  toshii }
    109       1.6  toshii 
    110       1.6  toshii static int
    111  1.28.4.1  rpaulo j720ssp_search(struct device *parent, struct cfdata *cf,
    112  1.28.4.1  rpaulo     const int *ldesc, void *aux)
    113      1.10    manu {
    114       1.6  toshii 
    115  1.28.4.1  rpaulo 	if (config_match(parent, cf, NULL) > 0)
    116  1.28.4.1  rpaulo 		config_attach(parent, cf, NULL, j720ssp_print);
    117       1.6  toshii 
    118  1.28.4.1  rpaulo 	return 0;
    119       1.6  toshii }
    120       1.6  toshii 
    121       1.6  toshii static int
    122  1.28.4.1  rpaulo j720ssp_print(void *aux, const char *pnp)
    123      1.10    manu {
    124       1.6  toshii 
    125  1.28.4.1  rpaulo 	return pnp ? QUIET : UNCONF;
    126       1.1  toshii }
    127       1.1  toshii 
    128       1.1  toshii int
    129  1.28.4.1  rpaulo j720ssp_readwrite(struct j720ssp_softc *sc, int drainfifo, int in,
    130  1.28.4.1  rpaulo     int *out, int wait)
    131       1.1  toshii {
    132  1.28.4.1  rpaulo 	int timeout;
    133       1.1  toshii 
    134  1.28.4.1  rpaulo 	while (!(bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) & SR_TNF))
    135  1.28.4.1  rpaulo 		continue;
    136       1.1  toshii 
    137  1.28.4.1  rpaulo 	timeout = 400000;
    138  1.28.4.1  rpaulo 	while (bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PLR) & 0x400)
    139  1.28.4.1  rpaulo 		if (--timeout == 0) {
    140  1.28.4.1  rpaulo 			DPRINTF(("j720ssp_readwrite: timeout 0\n"));
    141       1.1  toshii 			return -1;
    142       1.1  toshii 		}
    143       1.1  toshii 	if (drainfifo) {
    144  1.28.4.1  rpaulo 		while (bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) &
    145       1.1  toshii 		      SR_RNE)
    146       1.1  toshii 			bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
    147       1.9    manu 		delay(wait);
    148       1.1  toshii 	}
    149       1.1  toshii 
    150  1.28.4.1  rpaulo 	BIT_INVERT(in);
    151  1.28.4.1  rpaulo 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_DR, in << 8);
    152       1.1  toshii 
    153       1.9    manu 	delay(wait);
    154  1.28.4.1  rpaulo 	timeout = 100000;
    155  1.28.4.1  rpaulo 	while (!(bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) & SR_RNE))
    156  1.28.4.1  rpaulo 		if (--timeout == 0) {
    157  1.28.4.1  rpaulo 			DPRINTF(("j720ssp_readwrite: timeout 1\n"));
    158       1.1  toshii 			return -1;
    159       1.1  toshii 		}
    160       1.1  toshii 
    161       1.1  toshii 	*out = bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
    162  1.28.4.1  rpaulo 	BIT_INVERT(*out);
    163       1.1  toshii 
    164       1.1  toshii 	return 0;
    165       1.1  toshii }
    166