Home | History | Annotate | Line # | Download | only in ic
am79c930.c revision 1.13
      1  1.13     perry /* $NetBSD: am79c930.c,v 1.13 2005/02/27 00:27:00 perry Exp $ */
      2   1.2  sommerfe 
      3   1.1  sommerfe /*-
      4   1.1  sommerfe  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5   1.1  sommerfe  * All rights reserved.
      6   1.1  sommerfe  *
      7   1.1  sommerfe  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1  sommerfe  * by Bill Sommerfeld
      9   1.1  sommerfe  *
     10   1.1  sommerfe  * Redistribution and use in source and binary forms, with or without
     11   1.1  sommerfe  * modification, are permitted provided that the following conditions
     12   1.1  sommerfe  * are met:
     13   1.1  sommerfe  * 1. Redistributions of source code must retain the above copyright
     14   1.1  sommerfe  *    notice, this list of conditions and the following disclaimer.
     15   1.1  sommerfe  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1  sommerfe  *    notice, this list of conditions and the following disclaimer in the
     17   1.1  sommerfe  *    documentation and/or other materials provided with the distribution.
     18   1.1  sommerfe  * 3. All advertising materials mentioning features or use of this software
     19   1.1  sommerfe  *    must display the following acknowledgement:
     20   1.1  sommerfe  *        This product includes software developed by the NetBSD
     21   1.1  sommerfe  *        Foundation, Inc. and its contributors.
     22   1.1  sommerfe  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1  sommerfe  *    contributors may be used to endorse or promote products derived
     24   1.1  sommerfe  *    from this software without specific prior written permission.
     25   1.1  sommerfe  *
     26   1.1  sommerfe  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1  sommerfe  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1  sommerfe  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1  sommerfe  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1  sommerfe  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1  sommerfe  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1  sommerfe  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1  sommerfe  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1  sommerfe  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1  sommerfe  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1  sommerfe  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1  sommerfe  */
     38   1.1  sommerfe 
     39   1.1  sommerfe /*
     40   1.1  sommerfe  * Am79c930 chip driver.
     41   1.1  sommerfe  *
     42   1.1  sommerfe  * This is used by the awi driver to use the shared
     43   1.1  sommerfe  * memory attached to the 79c930 to communicate with the firmware running
     44   1.1  sommerfe  * in the 930's on-board 80188 core.
     45   1.1  sommerfe  *
     46   1.1  sommerfe  * The 79c930 can be mapped into just I/O space, or also have a
     47   1.1  sommerfe  * memory mapping; the mapping must be set up by the bus front-end
     48   1.1  sommerfe  * before am79c930_init is called.
     49   1.1  sommerfe  */
     50   1.1  sommerfe 
     51   1.1  sommerfe /*
     52   1.1  sommerfe  * operations:
     53   1.1  sommerfe  *
     54   1.1  sommerfe  * read_8, read_16, read_32, read_64, read_bytes
     55   1.1  sommerfe  * write_8, write_16, write_32, write_64, write_bytes
     56   1.1  sommerfe  * (two versions, depending on whether memory-space or i/o space is in use).
     57   1.1  sommerfe  *
     58   1.1  sommerfe  * interrupt E.C.
     59   1.1  sommerfe  * start isr
     60   1.1  sommerfe  * end isr
     61   1.1  sommerfe  */
     62   1.7     lukem 
     63   1.7     lukem #include <sys/cdefs.h>
     64   1.9      onoe #ifdef __NetBSD__
     65  1.13     perry __KERNEL_RCSID(0, "$NetBSD: am79c930.c,v 1.13 2005/02/27 00:27:00 perry Exp $");
     66   1.9      onoe #endif
     67   1.9      onoe #ifdef __FreeBSD__
     68   1.9      onoe __FBSDID("$FreeBSD$");
     69   1.9      onoe #endif
     70   1.1  sommerfe 
     71   1.1  sommerfe #include <sys/param.h>
     72   1.1  sommerfe #include <sys/systm.h>
     73   1.9      onoe #include <sys/endian.h>
     74   1.4      onoe #ifndef __FreeBSD__
     75   1.1  sommerfe #include <sys/device.h>
     76   1.4      onoe #endif
     77   1.1  sommerfe 
     78   1.1  sommerfe #include <machine/cpu.h>
     79   1.4      onoe #ifdef __FreeBSD__
     80   1.4      onoe #include <machine/bus_pio.h>
     81   1.4      onoe #include <machine/bus_memio.h>
     82   1.4      onoe #endif
     83   1.1  sommerfe #include <machine/bus.h>
     84   1.4      onoe #ifdef __NetBSD__
     85   1.1  sommerfe #include <machine/intr.h>
     86   1.4      onoe #endif
     87   1.1  sommerfe 
     88   1.4      onoe #ifdef __NetBSD__
     89   1.1  sommerfe #include <dev/ic/am79c930reg.h>
     90   1.1  sommerfe #include <dev/ic/am79c930var.h>
     91   1.4      onoe #endif
     92   1.4      onoe #ifdef __FreeBSD__
     93   1.4      onoe #include <dev/awi/am79c930reg.h>
     94   1.4      onoe #include <dev/awi/am79c930var.h>
     95   1.4      onoe #endif
     96   1.1  sommerfe 
     97   1.4      onoe #define AM930_DELAY(x) /*nothing*/
     98   1.1  sommerfe 
     99  1.12       jmc #ifndef __BUS_SPACE_HAS_STREAM_METHODS
    100  1.12       jmc #define bus_space_read_stream_2		bus_space_read_2
    101  1.12       jmc #define bus_space_read_stream_4		bus_space_read_4
    102  1.12       jmc #define bus_space_write_stream_2	bus_space_write_2
    103  1.12       jmc #define bus_space_write_stream_4 	bus_space_write_4
    104  1.12       jmc #endif /* __BUS_SPACE_HAS_STREAM_METHODS */
    105  1.12       jmc 
    106   1.9      onoe void am79c930_regdump(struct am79c930_softc *sc);
    107   1.1  sommerfe 
    108   1.9      onoe static void io_write_1(struct am79c930_softc *, u_int32_t, u_int8_t);
    109   1.9      onoe static void io_write_2(struct am79c930_softc *, u_int32_t, u_int16_t);
    110   1.9      onoe static void io_write_4(struct am79c930_softc *, u_int32_t, u_int32_t);
    111   1.9      onoe static void io_write_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
    112   1.9      onoe 
    113   1.9      onoe static u_int8_t io_read_1(struct am79c930_softc *, u_int32_t);
    114   1.9      onoe static u_int16_t io_read_2(struct am79c930_softc *, u_int32_t);
    115   1.9      onoe static u_int32_t io_read_4(struct am79c930_softc *, u_int32_t);
    116   1.9      onoe static void io_read_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
    117   1.9      onoe 
    118   1.9      onoe static void mem_write_1(struct am79c930_softc *, u_int32_t, u_int8_t);
    119   1.9      onoe static void mem_write_2(struct am79c930_softc *, u_int32_t, u_int16_t);
    120   1.9      onoe static void mem_write_4(struct am79c930_softc *, u_int32_t, u_int32_t);
    121   1.9      onoe static void mem_write_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
    122   1.9      onoe 
    123   1.9      onoe static u_int8_t mem_read_1(struct am79c930_softc *, u_int32_t);
    124   1.9      onoe static u_int16_t mem_read_2(struct am79c930_softc *, u_int32_t);
    125   1.9      onoe static u_int32_t mem_read_4(struct am79c930_softc *, u_int32_t);
    126   1.9      onoe static void mem_read_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
    127   1.1  sommerfe 
    128   1.1  sommerfe static struct am79c930_ops iospace_ops = {
    129   1.1  sommerfe 	io_write_1,
    130   1.1  sommerfe 	io_write_2,
    131   1.1  sommerfe 	io_write_4,
    132   1.1  sommerfe 	io_write_bytes,
    133   1.1  sommerfe 	io_read_1,
    134   1.1  sommerfe 	io_read_2,
    135   1.1  sommerfe 	io_read_4,
    136   1.1  sommerfe 	io_read_bytes
    137   1.1  sommerfe };
    138   1.1  sommerfe 
    139   1.1  sommerfe struct am79c930_ops memspace_ops = {
    140   1.1  sommerfe 	mem_write_1,
    141   1.1  sommerfe 	mem_write_2,
    142   1.1  sommerfe 	mem_write_4,
    143   1.1  sommerfe 	mem_write_bytes,
    144   1.1  sommerfe 	mem_read_1,
    145   1.1  sommerfe 	mem_read_2,
    146   1.1  sommerfe 	mem_read_4,
    147   1.1  sommerfe 	mem_read_bytes
    148   1.1  sommerfe };
    149   1.1  sommerfe 
    150   1.9      onoe static void
    151   1.9      onoe io_write_1( struct am79c930_softc *sc, u_int32_t off, u_int8_t val)
    152   1.1  sommerfe {
    153   1.1  sommerfe 	AM930_DELAY(1);
    154   1.1  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
    155   1.1  sommerfe 	    ((off>>8)& 0x7f));
    156   1.1  sommerfe 	AM930_DELAY(1);
    157   1.1  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
    158   1.1  sommerfe 	AM930_DELAY(1);
    159   1.1  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA, val);
    160   1.1  sommerfe 	AM930_DELAY(1);
    161   1.1  sommerfe }
    162   1.1  sommerfe 
    163   1.9      onoe static void
    164   1.9      onoe io_write_2(struct am79c930_softc *sc, u_int32_t off, u_int16_t val)
    165   1.1  sommerfe {
    166   1.3  sommerfe 	AM930_DELAY(1);
    167   1.3  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
    168   1.3  sommerfe 	    ((off>>8)& 0x7f));
    169   1.3  sommerfe 	AM930_DELAY(1);
    170   1.3  sommerfe 	bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
    171   1.3  sommerfe 	AM930_DELAY(1);
    172   1.3  sommerfe 	bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, val & 0xff);
    173   1.3  sommerfe 	AM930_DELAY(1);
    174   1.3  sommerfe 	bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, (val>>8)&0xff);
    175   1.3  sommerfe 	AM930_DELAY(1);
    176   1.1  sommerfe }
    177   1.1  sommerfe 
    178   1.9      onoe static void
    179   1.9      onoe io_write_4(struct am79c930_softc *sc, u_int32_t off, u_int32_t val)
    180   1.1  sommerfe {
    181   1.3  sommerfe 	AM930_DELAY(1);
    182   1.3  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
    183   1.3  sommerfe 	    ((off>>8)& 0x7f));
    184   1.3  sommerfe 	AM930_DELAY(1);
    185   1.3  sommerfe 	bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
    186   1.3  sommerfe 	AM930_DELAY(1);
    187   1.3  sommerfe 	bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,val & 0xff);
    188   1.3  sommerfe 	AM930_DELAY(1);
    189   1.3  sommerfe 	bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>8)&0xff);
    190   1.3  sommerfe 	AM930_DELAY(1);
    191   1.3  sommerfe 	bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>16)&0xff);
    192   1.3  sommerfe 	AM930_DELAY(1);
    193   1.3  sommerfe 	bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>24)&0xff);
    194   1.3  sommerfe 	AM930_DELAY(1);
    195   1.1  sommerfe }
    196   1.1  sommerfe 
    197   1.9      onoe static void
    198   1.9      onoe io_write_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
    199   1.9      onoe     size_t len)
    200   1.1  sommerfe {
    201   1.1  sommerfe 	int i;
    202   1.3  sommerfe 
    203   1.3  sommerfe 	AM930_DELAY(1);
    204   1.3  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
    205   1.3  sommerfe 	    ((off>>8)& 0x7f));
    206   1.3  sommerfe 	AM930_DELAY(1);
    207   1.3  sommerfe 	bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
    208   1.3  sommerfe 	AM930_DELAY(1);
    209   1.1  sommerfe 	for (i=0; i<len; i++)
    210   1.3  sommerfe 		bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,ptr[i]);
    211   1.1  sommerfe }
    212   1.1  sommerfe 
    213   1.9      onoe static u_int8_t
    214   1.9      onoe io_read_1(struct am79c930_softc *sc, u_int32_t off)
    215   1.1  sommerfe {
    216   1.1  sommerfe 	u_int8_t val;
    217   1.9      onoe 
    218   1.1  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
    219   1.1  sommerfe 	    ((off>>8)& 0x7f));
    220   1.1  sommerfe 	AM930_DELAY(1);
    221   1.1  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
    222   1.1  sommerfe 	AM930_DELAY(1);
    223   1.1  sommerfe 	val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
    224   1.1  sommerfe 	AM930_DELAY(1);
    225   1.1  sommerfe 	return val;
    226   1.1  sommerfe }
    227   1.1  sommerfe 
    228   1.9      onoe static u_int16_t
    229   1.9      onoe io_read_2(struct am79c930_softc *sc, u_int32_t off)
    230   1.1  sommerfe {
    231   1.3  sommerfe 	u_int16_t val;
    232   1.3  sommerfe 
    233   1.3  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
    234   1.3  sommerfe 	    ((off>>8)& 0x7f));
    235   1.3  sommerfe 	AM930_DELAY(1);
    236   1.3  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
    237   1.3  sommerfe 	AM930_DELAY(1);
    238   1.3  sommerfe 	val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
    239   1.3  sommerfe 	AM930_DELAY(1);
    240   1.3  sommerfe 	val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
    241  1.13     perry 	AM930_DELAY(1);
    242   1.3  sommerfe 	return val;
    243   1.1  sommerfe }
    244   1.1  sommerfe 
    245   1.9      onoe static u_int32_t
    246   1.9      onoe io_read_4(struct am79c930_softc *sc, u_int32_t off)
    247   1.1  sommerfe {
    248   1.3  sommerfe 	u_int32_t val;
    249   1.3  sommerfe 
    250   1.3  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
    251   1.3  sommerfe 	    ((off>>8)& 0x7f));
    252   1.3  sommerfe 	AM930_DELAY(1);
    253   1.3  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
    254   1.3  sommerfe 	AM930_DELAY(1);
    255   1.3  sommerfe 	val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
    256   1.3  sommerfe 	AM930_DELAY(1);
    257   1.3  sommerfe 	val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
    258  1.13     perry 	AM930_DELAY(1);
    259   1.3  sommerfe 	val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 16;
    260  1.13     perry 	AM930_DELAY(1);
    261   1.3  sommerfe 	val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 24;
    262  1.13     perry 	AM930_DELAY(1);
    263   1.3  sommerfe 	return val;
    264   1.1  sommerfe }
    265   1.1  sommerfe 
    266   1.9      onoe static void
    267   1.9      onoe io_read_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
    268   1.9      onoe     size_t len)
    269   1.1  sommerfe {
    270   1.1  sommerfe 	int i;
    271  1.13     perry 
    272   1.3  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
    273   1.3  sommerfe 	    ((off>>8)& 0x7f));
    274   1.3  sommerfe 	AM930_DELAY(1);
    275   1.3  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
    276   1.3  sommerfe 	AM930_DELAY(1);
    277  1.13     perry 	for (i=0; i<len; i++)
    278   1.3  sommerfe 		ptr[i] = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
    279   1.3  sommerfe 		    AM79C930_IODPA);
    280   1.1  sommerfe }
    281   1.1  sommerfe 
    282   1.9      onoe static void
    283   1.9      onoe mem_write_1(struct am79c930_softc *sc, u_int32_t off, u_int8_t val)
    284   1.1  sommerfe {
    285   1.1  sommerfe 	bus_space_write_1(sc->sc_memt, sc->sc_memh, off, val);
    286   1.1  sommerfe }
    287   1.1  sommerfe 
    288  1.10    dyoung static void
    289  1.10    dyoung mem_write_2(struct am79c930_softc *sc, u_int32_t off, u_int16_t val)
    290   1.1  sommerfe {
    291   1.5      onoe 	bus_space_tag_t t = sc->sc_memt;
    292   1.5      onoe 	bus_space_handle_t h = sc->sc_memh;
    293   1.5      onoe 
    294   1.5      onoe 	/* could be unaligned */
    295   1.5      onoe 	if ((off & 0x1) == 0)
    296  1.11    dyoung 		bus_space_write_stream_2(t, h, off,    htole16(val));
    297   1.5      onoe 	else {
    298   1.5      onoe 		bus_space_write_1(t, h, off,    val        & 0xff);
    299   1.5      onoe 		bus_space_write_1(t, h, off+1, (val >>  8) & 0xff);
    300   1.5      onoe 	}
    301   1.1  sommerfe }
    302   1.1  sommerfe 
    303   1.9      onoe static void
    304   1.9      onoe mem_write_4(struct am79c930_softc *sc, u_int32_t off, u_int32_t val)
    305   1.1  sommerfe {
    306   1.5      onoe 	bus_space_tag_t t = sc->sc_memt;
    307   1.5      onoe 	bus_space_handle_t h = sc->sc_memh;
    308   1.5      onoe 
    309   1.5      onoe 	/* could be unaligned */
    310   1.5      onoe 	if ((off & 0x3) == 0)
    311  1.11    dyoung 		bus_space_write_stream_4(t, h, off,    htole32(val));
    312   1.5      onoe 	else {
    313   1.5      onoe 		bus_space_write_1(t, h, off,    val        & 0xff);
    314   1.5      onoe 		bus_space_write_1(t, h, off+1, (val >>  8) & 0xff);
    315   1.5      onoe 		bus_space_write_1(t, h, off+2, (val >> 16) & 0xff);
    316   1.5      onoe 		bus_space_write_1(t, h, off+3, (val >> 24) & 0xff);
    317   1.5      onoe 	}
    318   1.1  sommerfe }
    319   1.1  sommerfe 
    320   1.9      onoe static void
    321   1.9      onoe mem_write_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
    322   1.9      onoe     size_t len)
    323   1.1  sommerfe {
    324   1.3  sommerfe 	bus_space_write_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
    325   1.1  sommerfe }
    326   1.1  sommerfe 
    327   1.9      onoe static u_int8_t
    328   1.9      onoe mem_read_1(struct am79c930_softc *sc, u_int32_t off)
    329   1.1  sommerfe {
    330   1.1  sommerfe 	return bus_space_read_1(sc->sc_memt, sc->sc_memh, off);
    331   1.1  sommerfe }
    332   1.1  sommerfe 
    333   1.9      onoe static u_int16_t
    334   1.9      onoe mem_read_2(struct am79c930_softc *sc, u_int32_t off)
    335   1.1  sommerfe {
    336   1.5      onoe 	/* could be unaligned */
    337   1.5      onoe 	if ((off & 0x1) == 0)
    338  1.11    dyoung 		return le16toh(bus_space_read_stream_2(sc->sc_memt,
    339  1.11    dyoung 		    sc->sc_memh, off));
    340   1.5      onoe 	else
    341   1.5      onoe 		return
    342   1.5      onoe 		     bus_space_read_1(sc->sc_memt, sc->sc_memh, off  )       |
    343   1.5      onoe 		    (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8);
    344   1.1  sommerfe }
    345   1.1  sommerfe 
    346   1.9      onoe static u_int32_t
    347   1.9      onoe mem_read_4(struct am79c930_softc *sc, u_int32_t off)
    348   1.1  sommerfe {
    349   1.5      onoe 	/* could be unaligned */
    350   1.5      onoe 	if ((off & 0x3) == 0)
    351  1.11    dyoung 		return le32toh(bus_space_read_stream_4(sc->sc_memt, sc->sc_memh,
    352  1.11    dyoung 		    off));
    353   1.5      onoe 	else
    354   1.5      onoe 		return
    355   1.5      onoe 		     bus_space_read_1(sc->sc_memt, sc->sc_memh, off  )       |
    356   1.5      onoe 		    (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8) |
    357   1.5      onoe 		    (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+2) <<16) |
    358   1.5      onoe 		    (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+3) <<24);
    359   1.1  sommerfe }
    360   1.1  sommerfe 
    361   1.9      onoe static void
    362   1.9      onoe mem_read_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
    363   1.9      onoe     size_t len)
    364   1.1  sommerfe {
    365   1.3  sommerfe 	bus_space_read_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
    366   1.1  sommerfe }
    367   1.1  sommerfe 
    368   1.1  sommerfe 
    369   1.1  sommerfe /*
    370   1.1  sommerfe  * Set bits in GCR.
    371   1.1  sommerfe  */
    372   1.1  sommerfe 
    373   1.9      onoe void
    374   1.9      onoe am79c930_gcr_setbits(struct am79c930_softc *sc, u_int8_t bits)
    375   1.1  sommerfe {
    376   1.1  sommerfe 	u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
    377   1.1  sommerfe 
    378   1.1  sommerfe 	gcr |= bits;
    379  1.13     perry 
    380   1.1  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
    381   1.1  sommerfe }
    382   1.1  sommerfe 
    383   1.1  sommerfe /*
    384   1.1  sommerfe  * Clear bits in GCR.
    385   1.1  sommerfe  */
    386   1.1  sommerfe 
    387   1.9      onoe void
    388   1.9      onoe am79c930_gcr_clearbits(struct am79c930_softc *sc, u_int8_t bits)
    389   1.1  sommerfe {
    390   1.1  sommerfe 	u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
    391   1.1  sommerfe 
    392   1.1  sommerfe 	gcr &= ~bits;
    393  1.13     perry 
    394   1.1  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
    395   1.1  sommerfe }
    396   1.1  sommerfe 
    397   1.9      onoe u_int8_t
    398   1.9      onoe am79c930_gcr_read(struct am79c930_softc *sc)
    399   1.1  sommerfe {
    400   1.1  sommerfe 	return bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
    401   1.1  sommerfe }
    402   1.1  sommerfe 
    403  1.13     perry #if 0
    404   1.9      onoe void
    405   1.9      onoe am79c930_regdump(struct am79c930_softc *sc)
    406   1.1  sommerfe {
    407   1.1  sommerfe 	u_int8_t buf[8];
    408   1.1  sommerfe 	int i;
    409   1.1  sommerfe 
    410   1.1  sommerfe 	AM930_DELAY(5);
    411   1.1  sommerfe 	for (i=0; i<8; i++) {
    412   1.1  sommerfe 		buf[i] = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, i);
    413   1.1  sommerfe 		AM930_DELAY(5);
    414   1.1  sommerfe 	}
    415   1.1  sommerfe 	printf("am79c930: regdump:");
    416   1.1  sommerfe 	for (i=0; i<8; i++) {
    417   1.1  sommerfe 		printf(" %02x", buf[i]);
    418   1.1  sommerfe 	}
    419   1.1  sommerfe 	printf("\n");
    420   1.1  sommerfe }
    421   1.1  sommerfe #endif
    422   1.1  sommerfe 
    423   1.9      onoe void
    424   1.9      onoe am79c930_chip_init(struct am79c930_softc *sc, int how)
    425   1.1  sommerfe {
    426   1.1  sommerfe 	/* zero the bank select register, and leave it that way.. */
    427   1.1  sommerfe 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_BSS, 0);
    428   1.1  sommerfe 	if (how)
    429   1.1  sommerfe 	  	sc->sc_ops = &memspace_ops;
    430   1.1  sommerfe 	else
    431   1.1  sommerfe 	  	sc->sc_ops = &iospace_ops;
    432   1.1  sommerfe }
    433