Home | History | Annotate | Line # | Download | only in dev
j720ssp.c revision 1.32.78.1
      1  1.32.78.1  thorpej /*	$NetBSD: j720ssp.c,v 1.32.78.1 2021/03/20 19:33:35 thorpej Exp $	*/
      2        1.1   toshii 
      3        1.1   toshii /*-
      4       1.29    peter  * 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.29    peter  * 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  *
     19        1.1   toshii  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1   toshii  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1   toshii  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1   toshii  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1   toshii  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1   toshii  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1   toshii  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1   toshii  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1   toshii  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1   toshii  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1   toshii  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1   toshii  */
     31        1.1   toshii 
     32       1.29    peter /* Jornada 720 SSP port. */
     33       1.18    lukem 
     34       1.18    lukem #include <sys/cdefs.h>
     35  1.32.78.1  thorpej __KERNEL_RCSID(0, "$NetBSD: j720ssp.c,v 1.32.78.1 2021/03/20 19:33:35 thorpej Exp $");
     36       1.10     manu 
     37        1.1   toshii #include <sys/param.h>
     38        1.1   toshii #include <sys/systm.h>
     39        1.1   toshii #include <sys/device.h>
     40        1.7   ichiro 
     41        1.7   ichiro #include <arm/sa11x0/sa11x0_var.h>
     42        1.7   ichiro #include <arm/sa11x0/sa11x0_gpioreg.h>
     43        1.7   ichiro #include <arm/sa11x0/sa11x0_ppcreg.h>
     44        1.7   ichiro #include <arm/sa11x0/sa11x0_sspreg.h>
     45        1.1   toshii 
     46       1.29    peter #include <hpcarm/dev/j720sspvar.h>
     47       1.10     manu 
     48       1.29    peter #ifdef DEBUG
     49       1.32      rjs #define DPRINTF(arg)	aprint_normal arg
     50        1.1   toshii #else
     51       1.29    peter #define DPRINTF(arg)	/* nothing */
     52        1.1   toshii #endif
     53        1.1   toshii 
     54       1.30    peter #define BIT_INVERT(x)							\
     55       1.30    peter 	do {								\
     56       1.30    peter 		(x) = ((((x) & 0xf0) >> 4) | (((x) & 0x0f) << 4));	\
     57       1.30    peter 		(x) = ((((x) & 0xcc) >> 2) | (((x) & 0x33) << 2));	\
     58       1.30    peter 		(x) = ((((x) & 0xaa) >> 1) | (((x) & 0x55) << 1));	\
     59       1.30    peter 	} while (0)
     60       1.30    peter 
     61       1.32      rjs static int	j720ssp_match(device_t, cfdata_t, void *);
     62       1.32      rjs static void	j720ssp_attach(device_t, device_t, void *);
     63       1.32      rjs static int	j720ssp_search(device_t, cfdata_t, const int *, void *);
     64       1.29    peter static int	j720ssp_print(void *, const char *);
     65        1.6   toshii 
     66       1.32      rjs CFATTACH_DECL_NEW(j720ssp, sizeof(struct j720ssp_softc),
     67       1.29    peter     j720ssp_match, j720ssp_attach, NULL, NULL);
     68        1.1   toshii 
     69        1.1   toshii 
     70       1.29    peter static int
     71       1.32      rjs j720ssp_match(device_t parent, cfdata_t cf, void *aux)
     72       1.29    peter {
     73        1.1   toshii 
     74       1.29    peter 	if (strcmp(cf->cf_name, "j720ssp") != 0)
     75       1.29    peter 		return 0;
     76        1.1   toshii 
     77       1.29    peter 	return 1;
     78        1.1   toshii }
     79        1.1   toshii 
     80       1.29    peter static void
     81       1.32      rjs j720ssp_attach(device_t parent, device_t self, void *aux)
     82        1.1   toshii {
     83       1.32      rjs 	struct j720ssp_softc *sc = device_private(self);
     84       1.32      rjs 	struct sa11x0_softc *psc = device_private(parent);
     85        1.1   toshii 	struct sa11x0_attach_args *sa = aux;
     86        1.1   toshii 
     87       1.32      rjs 	sc->sc_dev = self;
     88        1.1   toshii 	sc->sc_iot = psc->sc_iot;
     89        1.1   toshii 	sc->sc_gpioh = psc->sc_gpioh;
     90       1.29    peter 	sc->sc_parent = psc;
     91       1.29    peter 
     92        1.1   toshii 	if (bus_space_map(sc->sc_iot, sa->sa_addr, sa->sa_size, 0,
     93       1.29    peter 	    &sc->sc_ssph)) {
     94       1.32      rjs 		aprint_normal(": unable to map SSP registers\n");
     95        1.1   toshii 		return;
     96        1.1   toshii 	}
     97        1.1   toshii 
     98       1.32      rjs 	aprint_normal("\n");
     99        1.3   toshii 
    100  1.32.78.1  thorpej 	config_search(self, NULL,
    101  1.32.78.1  thorpej 	    CFARG_SUBMATCH, j720ssp_search,
    102  1.32.78.1  thorpej 	    CFARG_IATTR, "j720ssp",
    103  1.32.78.1  thorpej 	    CFARG_EOL);
    104        1.1   toshii }
    105        1.1   toshii 
    106       1.29    peter static int
    107       1.32      rjs j720ssp_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    108        1.6   toshii {
    109        1.6   toshii 
    110       1.29    peter 	if (config_match(parent, cf, NULL) > 0)
    111       1.29    peter 		config_attach(parent, cf, NULL, j720ssp_print);
    112        1.6   toshii 
    113        1.9     manu 	return 0;
    114        1.6   toshii }
    115        1.6   toshii 
    116        1.6   toshii static int
    117       1.29    peter j720ssp_print(void *aux, const char *pnp)
    118       1.10     manu {
    119        1.6   toshii 
    120       1.29    peter 	return pnp ? QUIET : UNCONF;
    121        1.1   toshii }
    122        1.1   toshii 
    123        1.1   toshii int
    124       1.29    peter j720ssp_readwrite(struct j720ssp_softc *sc, int drainfifo, int in,
    125       1.29    peter     int *out, int wait)
    126        1.1   toshii {
    127       1.29    peter 	int timeout;
    128        1.1   toshii 
    129       1.29    peter 	while (!(bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) & SR_TNF))
    130       1.29    peter 		continue;
    131        1.1   toshii 
    132       1.29    peter 	timeout = 400000;
    133       1.29    peter 	while (bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PLR) & 0x400)
    134       1.29    peter 		if (--timeout == 0) {
    135       1.29    peter 			DPRINTF(("j720ssp_readwrite: timeout 0\n"));
    136        1.1   toshii 			return -1;
    137        1.1   toshii 		}
    138        1.1   toshii 	if (drainfifo) {
    139       1.29    peter 		while (bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) &
    140        1.1   toshii 		      SR_RNE)
    141        1.1   toshii 			bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
    142        1.9     manu 		delay(wait);
    143        1.1   toshii 	}
    144        1.1   toshii 
    145       1.30    peter 	BIT_INVERT(in);
    146       1.30    peter 	bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_DR, in << 8);
    147        1.1   toshii 
    148        1.9     manu 	delay(wait);
    149       1.29    peter 	timeout = 100000;
    150       1.29    peter 	while (!(bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) & SR_RNE))
    151       1.29    peter 		if (--timeout == 0) {
    152       1.29    peter 			DPRINTF(("j720ssp_readwrite: timeout 1\n"));
    153        1.1   toshii 			return -1;
    154        1.1   toshii 		}
    155        1.1   toshii 
    156        1.1   toshii 	*out = bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
    157       1.30    peter 	BIT_INVERT(*out);
    158        1.1   toshii 
    159        1.1   toshii 	return 0;
    160        1.1   toshii }
    161