Home | History | Annotate | Line # | Download | only in dev
      1 /*	$NetBSD: auxio_ebus.c,v 1.7 2023/12/20 05:33:58 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2000, 2001, 2015 Matthew R. Green
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 /*
     30  * AUXIO registers support on the sbus & ebus2, used for the floppy driver
     31  * and to control the system LED, for the BLINK option.
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 __KERNEL_RCSID(0, "$NetBSD: auxio_ebus.c,v 1.7 2023/12/20 05:33:58 thorpej Exp $");
     36 
     37 #include "opt_auxio.h"
     38 
     39 #include <sys/param.h>
     40 #include <sys/systm.h>
     41 #include <sys/kernel.h>
     42 #include <sys/callout.h>
     43 #include <sys/errno.h>
     44 #include <sys/device.h>
     45 
     46 #include <machine/autoconf.h>
     47 #include <machine/cpu.h>
     48 
     49 #include <dev/ebus/ebusreg.h>
     50 #include <dev/ebus/ebusvar.h>
     51 #include <dev/sbus/sbusvar.h>
     52 #include <sparc64/dev/auxioreg.h>
     53 #include <sparc64/dev/auxiovar.h>
     54 
     55 static int	auxio_ebus_match(device_t, cfdata_t, void *);
     56 static void	auxio_ebus_attach(device_t, device_t, void *);
     57 
     58 CFATTACH_DECL_NEW(auxio_ebus, sizeof(struct auxio_softc),
     59     auxio_ebus_match, auxio_ebus_attach, NULL, NULL);
     60 
     61 static int
     62 auxio_ebus_match(device_t parent, cfdata_t cf, void *aux)
     63 {
     64 	struct ebus_attach_args *ea = aux;
     65 
     66 	return (strcmp(AUXIO_ROM_NAME, ea->ea_name) == 0);
     67 }
     68 
     69 static void
     70 auxio_ebus_attach(device_t parent, device_t self, void *aux)
     71 {
     72 	struct auxio_softc *sc = device_private(self);
     73 	struct ebus_attach_args *ea = aux;
     74 
     75 	sc->sc_dev = self;
     76 	sc->sc_tag = ea->ea_bustag;
     77 
     78 	if (ea->ea_nreg < 1) {
     79 		printf(": no registers??\n");
     80 		return;
     81 	}
     82 
     83 	sc->sc_flags = AUXIO_EBUS;
     84 	if (ea->ea_nreg != 5) {
     85 		printf(": not 5 (%d) registers, only setting led",
     86 		    ea->ea_nreg);
     87 		sc->sc_flags |= AUXIO_LEDONLY;
     88 	} else if (ea->ea_nvaddr == 5) {
     89 		sparc_promaddr_to_handle(sc->sc_tag,
     90 			ea->ea_vaddr[1], &sc->sc_pci);
     91 		sparc_promaddr_to_handle(sc->sc_tag,
     92 			ea->ea_vaddr[2], &sc->sc_freq);
     93 		sparc_promaddr_to_handle(sc->sc_tag,
     94 			ea->ea_vaddr[3], &sc->sc_scsi);
     95 		sparc_promaddr_to_handle(sc->sc_tag,
     96 			ea->ea_vaddr[4], &sc->sc_temp);
     97 	} else {
     98 		bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[1]),
     99 			ea->ea_reg[1].size, 0, &sc->sc_pci);
    100 		bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[2]),
    101 			ea->ea_reg[2].size, 0, &sc->sc_freq);
    102 		bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[3]),
    103 			ea->ea_reg[3].size, 0, &sc->sc_scsi);
    104 		bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[4]),
    105 			ea->ea_reg[4].size, 0, &sc->sc_temp);
    106 	}
    107 
    108 	if (ea->ea_nvaddr > 0) {
    109 		sparc_promaddr_to_handle(sc->sc_tag,
    110 			ea->ea_vaddr[0], &sc->sc_led);
    111 	} else {
    112 		bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
    113 			ea->ea_reg[0].size, 0, &sc->sc_led);
    114 	}
    115 
    116 	auxio_attach_common(sc);
    117 }
    118