Home | History | Annotate | Line # | Download | only in dev
auxio.c revision 1.8
      1  1.8  thorpej /*	$NetBSD: auxio.c,v 1.8 2002/10/01 18:40:06 thorpej Exp $	*/
      2  1.1      mrg 
      3  1.1      mrg /*
      4  1.2      mrg  * Copyright (c) 2000, 2001 Matthew R. Green
      5  1.1      mrg  * All rights reserved.
      6  1.1      mrg  *
      7  1.1      mrg  * Redistribution and use in source and binary forms, with or without
      8  1.1      mrg  * modification, are permitted provided that the following conditions
      9  1.1      mrg  * are met:
     10  1.1      mrg  * 1. Redistributions of source code must retain the above copyright
     11  1.1      mrg  *    notice, this list of conditions and the following disclaimer.
     12  1.1      mrg  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1      mrg  *    notice, this list of conditions and the following disclaimer in the
     14  1.1      mrg  *    documentation and/or other materials provided with the distribution.
     15  1.1      mrg  * 3. The name of the author may not be used to endorse or promote products
     16  1.1      mrg  *    derived from this software without specific prior written permission.
     17  1.1      mrg  *
     18  1.1      mrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1      mrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1      mrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1      mrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.1      mrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  1.1      mrg  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  1.1      mrg  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  1.1      mrg  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  1.1      mrg  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  1.1      mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  1.1      mrg  * SUCH DAMAGE.
     29  1.1      mrg  */
     30  1.1      mrg 
     31  1.1      mrg /*
     32  1.2      mrg  * AUXIO registers support on the sbus & ebus2, used for the floppy driver
     33  1.2      mrg  * and to control the system LED, for the BLINK option.
     34  1.1      mrg  */
     35  1.1      mrg 
     36  1.1      mrg #include <sys/param.h>
     37  1.1      mrg #include <sys/systm.h>
     38  1.2      mrg #include <sys/kernel.h>
     39  1.2      mrg #include <sys/callout.h>
     40  1.1      mrg #include <sys/errno.h>
     41  1.1      mrg #include <sys/device.h>
     42  1.1      mrg #include <sys/malloc.h>
     43  1.1      mrg 
     44  1.1      mrg #include <machine/autoconf.h>
     45  1.1      mrg #include <machine/cpu.h>
     46  1.1      mrg 
     47  1.2      mrg #include <dev/ebus/ebusreg.h>
     48  1.4      mrg #include <dev/ebus/ebusvar.h>
     49  1.1      mrg #include <sparc64/dev/sbusvar.h>
     50  1.1      mrg #include <sparc64/dev/auxioreg.h>
     51  1.2      mrg 
     52  1.2      mrg /*
     53  1.2      mrg  * on sun4u, auxio exists with one register (LED) on the sbus, and 5
     54  1.2      mrg  * registers on the ebus2 (pci) (LED, PCIMODE, FREQUENCY, SCSI
     55  1.2      mrg  * OSCILLATOR, and TEMP SENSE.
     56  1.2      mrg  */
     57  1.2      mrg 
     58  1.2      mrg struct auxio_softc {
     59  1.2      mrg 	struct device		sc_dev;
     60  1.2      mrg 
     61  1.2      mrg 	/* parent's tag */
     62  1.2      mrg 	bus_space_tag_t		sc_tag;
     63  1.2      mrg 
     64  1.2      mrg 	/* handles to the various auxio regsiter sets */
     65  1.2      mrg 	bus_space_handle_t	sc_led;
     66  1.2      mrg 	bus_space_handle_t	sc_pci;
     67  1.2      mrg 	bus_space_handle_t	sc_freq;
     68  1.2      mrg 	bus_space_handle_t	sc_scsi;
     69  1.2      mrg 	bus_space_handle_t	sc_temp;
     70  1.2      mrg 
     71  1.2      mrg 	int			sc_flags;
     72  1.2      mrg #define	AUXIO_LEDONLY		0x1
     73  1.2      mrg #define	AUXIO_EBUS		0x2
     74  1.2      mrg #define	AUXIO_SBUS		0x4
     75  1.2      mrg };
     76  1.1      mrg 
     77  1.1      mrg #define	AUXIO_ROM_NAME		"auxio"
     78  1.1      mrg 
     79  1.2      mrg void	auxio_attach_common(struct auxio_softc *);
     80  1.2      mrg int	auxio_ebus_match(struct device *, struct cfdata *, void *);
     81  1.2      mrg void	auxio_ebus_attach(struct device *, struct device *, void *);
     82  1.2      mrg int	auxio_sbus_match(struct device *, struct cfdata *, void *);
     83  1.2      mrg void	auxio_sbus_attach(struct device *, struct device *, void *);
     84  1.1      mrg 
     85  1.8  thorpej CFATTACH_DECL(auxio_ebus, sizeof(struct auxio_softc),
     86  1.8  thorpej     auxio_ebus_match, auxio_ebus_attach, NULL, NULL)
     87  1.8  thorpej 
     88  1.8  thorpej CFATTACH_DECL(auxio_sbus, sizeof(struct auxio_softc),
     89  1.8  thorpej     auxio_sbus_match, auxio_sbus_attach, NULL, NULL)
     90  1.1      mrg 
     91  1.2      mrg #ifdef BLINK
     92  1.2      mrg static struct callout blink_ch = CALLOUT_INITIALIZER;
     93  1.2      mrg 
     94  1.2      mrg static void auxio_blink(void *);
     95  1.2      mrg 
     96  1.2      mrg static void
     97  1.2      mrg auxio_blink(x)
     98  1.2      mrg 	void *x;
     99  1.2      mrg {
    100  1.2      mrg 	struct auxio_softc *sc = x;
    101  1.2      mrg 	int s;
    102  1.2      mrg 	u_int32_t led;
    103  1.2      mrg 
    104  1.2      mrg 	s = splhigh();
    105  1.2      mrg 	if (sc->sc_flags & AUXIO_EBUS)
    106  1.2      mrg 		led = le32toh(bus_space_read_4(sc->sc_tag, sc->sc_led, 0));
    107  1.2      mrg 	else
    108  1.2      mrg 		led = bus_space_read_1(sc->sc_tag, sc->sc_led, 0);
    109  1.2      mrg 	if (led & AUXIO_LED_LED)
    110  1.2      mrg 		led = 0;
    111  1.2      mrg 	else
    112  1.2      mrg 		led = AUXIO_LED_LED;
    113  1.2      mrg 	if (sc->sc_flags & AUXIO_EBUS)
    114  1.2      mrg 		bus_space_write_4(sc->sc_tag, sc->sc_led, 0, htole32(led));
    115  1.2      mrg 	else
    116  1.2      mrg 		bus_space_write_1(sc->sc_tag, sc->sc_led, 0, led);
    117  1.2      mrg 	splx(s);
    118  1.2      mrg 
    119  1.2      mrg 	/*
    120  1.2      mrg 	 * Blink rate is:
    121  1.2      mrg 	 *	full cycle every second if completely idle (loadav = 0)
    122  1.2      mrg 	 *	full cycle every 2 seconds if loadav = 1
    123  1.2      mrg 	 *	full cycle every 3 seconds if loadav = 2
    124  1.2      mrg 	 * etc.
    125  1.2      mrg 	 */
    126  1.2      mrg 	s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
    127  1.2      mrg 	callout_reset(&blink_ch, s, auxio_blink, sc);
    128  1.2      mrg }
    129  1.2      mrg #endif
    130  1.2      mrg 
    131  1.2      mrg void
    132  1.2      mrg auxio_attach_common(sc)
    133  1.2      mrg 	struct auxio_softc *sc;
    134  1.2      mrg {
    135  1.3    pooka #ifdef BLINK
    136  1.2      mrg 	static int do_once = 1;
    137  1.2      mrg 
    138  1.2      mrg 	/* only start one blinker */
    139  1.2      mrg 	if (do_once) {
    140  1.2      mrg 		auxio_blink(sc);
    141  1.2      mrg 		do_once = 0;
    142  1.2      mrg 	}
    143  1.2      mrg #endif
    144  1.2      mrg 	printf("\n");
    145  1.2      mrg }
    146  1.2      mrg 
    147  1.1      mrg int
    148  1.1      mrg auxio_ebus_match(parent, cf, aux)
    149  1.1      mrg 	struct device *parent;
    150  1.1      mrg 	struct cfdata *cf;
    151  1.1      mrg 	void *aux;
    152  1.1      mrg {
    153  1.1      mrg 	struct ebus_attach_args *ea = aux;
    154  1.1      mrg 
    155  1.1      mrg 	return (strcmp(AUXIO_ROM_NAME, ea->ea_name) == 0);
    156  1.1      mrg }
    157  1.1      mrg 
    158  1.1      mrg void
    159  1.1      mrg auxio_ebus_attach(parent, self, aux)
    160  1.1      mrg 	struct device *parent, *self;
    161  1.1      mrg 	void *aux;
    162  1.1      mrg {
    163  1.1      mrg 	struct auxio_softc *sc = (struct auxio_softc *)self;
    164  1.1      mrg 	struct ebus_attach_args *ea = aux;
    165  1.1      mrg 
    166  1.5      eeh 	sc->sc_tag = ea->ea_bustag;
    167  1.5      eeh 
    168  1.5      eeh 	if (ea->ea_nreg < 1) {
    169  1.1      mrg 		printf(": no registers??\n");
    170  1.1      mrg 		return;
    171  1.1      mrg 	}
    172  1.1      mrg 
    173  1.5      eeh 	if (ea->ea_nreg != 5) {
    174  1.1      mrg 		printf(": not 5 (%d) registers, only setting led",
    175  1.4      mrg 		    ea->ea_nreg);
    176  1.1      mrg 		sc->sc_flags = AUXIO_LEDONLY|AUXIO_EBUS;
    177  1.5      eeh 	} else if (ea->ea_nvaddr == 5) {
    178  1.5      eeh 		sc->sc_flags = AUXIO_EBUS;
    179  1.5      eeh 
    180  1.5      eeh 		sparc_promaddr_to_handle(sc->sc_tag,
    181  1.5      eeh 			ea->ea_vaddr[1], &sc->sc_pci);
    182  1.5      eeh 		sparc_promaddr_to_handle(sc->sc_tag,
    183  1.5      eeh 			ea->ea_vaddr[2], &sc->sc_freq);
    184  1.5      eeh 		sparc_promaddr_to_handle(sc->sc_tag,
    185  1.5      eeh 			ea->ea_vaddr[3], &sc->sc_scsi);
    186  1.5      eeh 		sparc_promaddr_to_handle(sc->sc_tag,
    187  1.5      eeh 			ea->ea_vaddr[4], &sc->sc_temp);
    188  1.1      mrg 	} else {
    189  1.1      mrg 		sc->sc_flags = AUXIO_EBUS;
    190  1.5      eeh 		bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[1]),
    191  1.5      eeh 			ea->ea_reg[1].size, 0, &sc->sc_pci);
    192  1.5      eeh 		bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[2]),
    193  1.5      eeh 			ea->ea_reg[2].size, 0, &sc->sc_freq);
    194  1.5      eeh 		bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[3]),
    195  1.5      eeh 			ea->ea_reg[3].size, 0, &sc->sc_scsi);
    196  1.5      eeh 		bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[4]),
    197  1.5      eeh 			ea->ea_reg[4].size, 0, &sc->sc_temp);
    198  1.1      mrg 	}
    199  1.5      eeh 
    200  1.5      eeh 	if (ea->ea_nvaddr > 0) {
    201  1.5      eeh 		sparc_promaddr_to_handle(sc->sc_tag,
    202  1.5      eeh 			ea->ea_vaddr[0], &sc->sc_led);
    203  1.5      eeh 	} else {
    204  1.5      eeh 		bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
    205  1.5      eeh 			ea->ea_reg[0].size, 0, &sc->sc_led);
    206  1.6      eeh 	}
    207  1.1      mrg 
    208  1.2      mrg 	auxio_attach_common(sc);
    209  1.1      mrg }
    210  1.1      mrg 
    211  1.1      mrg int
    212  1.1      mrg auxio_sbus_match(parent, cf, aux)
    213  1.1      mrg 	struct device *parent;
    214  1.1      mrg 	struct cfdata *cf;
    215  1.1      mrg 	void *aux;
    216  1.1      mrg {
    217  1.1      mrg 	struct sbus_attach_args *sa = aux;
    218  1.1      mrg 
    219  1.1      mrg 	return (strcmp(AUXIO_ROM_NAME, sa->sa_name) == 0);
    220  1.1      mrg }
    221  1.1      mrg 
    222  1.1      mrg void
    223  1.1      mrg auxio_sbus_attach(parent, self, aux)
    224  1.1      mrg 	struct device *parent, *self;
    225  1.1      mrg 	void *aux;
    226  1.1      mrg {
    227  1.1      mrg 	struct auxio_softc *sc = (struct auxio_softc *)self;
    228  1.1      mrg 	struct sbus_attach_args *sa = aux;
    229  1.1      mrg 
    230  1.5      eeh 	sc->sc_tag = sa->sa_bustag;
    231  1.5      eeh 
    232  1.5      eeh 	if (sa->sa_nreg < 1) {
    233  1.1      mrg 		printf(": no registers??\n");
    234  1.1      mrg 		return;
    235  1.1      mrg 	}
    236  1.1      mrg 
    237  1.5      eeh 	if (sa->sa_nreg != 1) {
    238  1.2      mrg 		printf(": not 1 (%d/%d) registers??", sa->sa_nreg,
    239  1.2      mrg 		    sa->sa_npromvaddrs);
    240  1.1      mrg 		return;
    241  1.1      mrg 	}
    242  1.1      mrg 
    243  1.1      mrg 	/* sbus auxio only has one set of registers */
    244  1.1      mrg 	sc->sc_flags = AUXIO_LEDONLY|AUXIO_SBUS;
    245  1.5      eeh 	if (sa->sa_npromvaddrs > 0) {
    246  1.5      eeh 		sbus_promaddr_to_handle(sc->sc_tag,
    247  1.5      eeh 			sa->sa_promvaddr, &sc->sc_led);
    248  1.5      eeh 	} else {
    249  1.5      eeh 		sbus_bus_map(sc->sc_tag, sa->sa_slot, sa->sa_offset,
    250  1.5      eeh 			sa->sa_size, 0, &sc->sc_led);
    251  1.5      eeh 	}
    252  1.1      mrg 
    253  1.2      mrg 	auxio_attach_common(sc);
    254  1.1      mrg }
    255