1*1dc652efSthorpej /* $NetBSD: auxio_ebus.c,v 1.7 2023/12/20 05:33:58 thorpej Exp $ */
27e689e2dSmartin
37e689e2dSmartin /*
47e689e2dSmartin * Copyright (c) 2000, 2001, 2015 Matthew R. Green
57e689e2dSmartin * All rights reserved.
67e689e2dSmartin *
77e689e2dSmartin * Redistribution and use in source and binary forms, with or without
87e689e2dSmartin * modification, are permitted provided that the following conditions
97e689e2dSmartin * are met:
107e689e2dSmartin * 1. Redistributions of source code must retain the above copyright
117e689e2dSmartin * notice, this list of conditions and the following disclaimer.
127e689e2dSmartin * 2. Redistributions in binary form must reproduce the above copyright
137e689e2dSmartin * notice, this list of conditions and the following disclaimer in the
147e689e2dSmartin * documentation and/or other materials provided with the distribution.
157e689e2dSmartin *
167e689e2dSmartin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
177e689e2dSmartin * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
187e689e2dSmartin * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
197e689e2dSmartin * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
207e689e2dSmartin * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
217e689e2dSmartin * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
227e689e2dSmartin * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
237e689e2dSmartin * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
247e689e2dSmartin * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
257e689e2dSmartin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
267e689e2dSmartin * SUCH DAMAGE.
277e689e2dSmartin */
287e689e2dSmartin
297e689e2dSmartin /*
307e689e2dSmartin * AUXIO registers support on the sbus & ebus2, used for the floppy driver
317e689e2dSmartin * and to control the system LED, for the BLINK option.
327e689e2dSmartin */
337e689e2dSmartin
347e689e2dSmartin #include <sys/cdefs.h>
35*1dc652efSthorpej __KERNEL_RCSID(0, "$NetBSD: auxio_ebus.c,v 1.7 2023/12/20 05:33:58 thorpej Exp $");
367e689e2dSmartin
377e689e2dSmartin #include "opt_auxio.h"
387e689e2dSmartin
397e689e2dSmartin #include <sys/param.h>
407e689e2dSmartin #include <sys/systm.h>
417e689e2dSmartin #include <sys/kernel.h>
427e689e2dSmartin #include <sys/callout.h>
437e689e2dSmartin #include <sys/errno.h>
447e689e2dSmartin #include <sys/device.h>
457e689e2dSmartin
467e689e2dSmartin #include <machine/autoconf.h>
477e689e2dSmartin #include <machine/cpu.h>
487e689e2dSmartin
497e689e2dSmartin #include <dev/ebus/ebusreg.h>
507e689e2dSmartin #include <dev/ebus/ebusvar.h>
517e689e2dSmartin #include <dev/sbus/sbusvar.h>
527e689e2dSmartin #include <sparc64/dev/auxioreg.h>
537e689e2dSmartin #include <sparc64/dev/auxiovar.h>
547e689e2dSmartin
557e689e2dSmartin static int auxio_ebus_match(device_t, cfdata_t, void *);
567e689e2dSmartin static void auxio_ebus_attach(device_t, device_t, void *);
577e689e2dSmartin
587e689e2dSmartin CFATTACH_DECL_NEW(auxio_ebus, sizeof(struct auxio_softc),
597e689e2dSmartin auxio_ebus_match, auxio_ebus_attach, NULL, NULL);
607e689e2dSmartin
617e689e2dSmartin static int
auxio_ebus_match(device_t parent,cfdata_t cf,void * aux)627e689e2dSmartin auxio_ebus_match(device_t parent, cfdata_t cf, void *aux)
637e689e2dSmartin {
647e689e2dSmartin struct ebus_attach_args *ea = aux;
657e689e2dSmartin
667e689e2dSmartin return (strcmp(AUXIO_ROM_NAME, ea->ea_name) == 0);
677e689e2dSmartin }
687e689e2dSmartin
697e689e2dSmartin static void
auxio_ebus_attach(device_t parent,device_t self,void * aux)707e689e2dSmartin auxio_ebus_attach(device_t parent, device_t self, void *aux)
717e689e2dSmartin {
727e689e2dSmartin struct auxio_softc *sc = device_private(self);
737e689e2dSmartin struct ebus_attach_args *ea = aux;
747e689e2dSmartin
757e689e2dSmartin sc->sc_dev = self;
767e689e2dSmartin sc->sc_tag = ea->ea_bustag;
777e689e2dSmartin
787e689e2dSmartin if (ea->ea_nreg < 1) {
797e689e2dSmartin printf(": no registers??\n");
807e689e2dSmartin return;
817e689e2dSmartin }
827e689e2dSmartin
837e689e2dSmartin sc->sc_flags = AUXIO_EBUS;
847e689e2dSmartin if (ea->ea_nreg != 5) {
857e689e2dSmartin printf(": not 5 (%d) registers, only setting led",
867e689e2dSmartin ea->ea_nreg);
877e689e2dSmartin sc->sc_flags |= AUXIO_LEDONLY;
887e689e2dSmartin } else if (ea->ea_nvaddr == 5) {
897e689e2dSmartin sparc_promaddr_to_handle(sc->sc_tag,
907e689e2dSmartin ea->ea_vaddr[1], &sc->sc_pci);
917e689e2dSmartin sparc_promaddr_to_handle(sc->sc_tag,
927e689e2dSmartin ea->ea_vaddr[2], &sc->sc_freq);
937e689e2dSmartin sparc_promaddr_to_handle(sc->sc_tag,
947e689e2dSmartin ea->ea_vaddr[3], &sc->sc_scsi);
957e689e2dSmartin sparc_promaddr_to_handle(sc->sc_tag,
967e689e2dSmartin ea->ea_vaddr[4], &sc->sc_temp);
977e689e2dSmartin } else {
987e689e2dSmartin bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[1]),
997e689e2dSmartin ea->ea_reg[1].size, 0, &sc->sc_pci);
1007e689e2dSmartin bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[2]),
1017e689e2dSmartin ea->ea_reg[2].size, 0, &sc->sc_freq);
1027e689e2dSmartin bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[3]),
1037e689e2dSmartin ea->ea_reg[3].size, 0, &sc->sc_scsi);
1047e689e2dSmartin bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[4]),
1057e689e2dSmartin ea->ea_reg[4].size, 0, &sc->sc_temp);
1067e689e2dSmartin }
1077e689e2dSmartin
1087e689e2dSmartin if (ea->ea_nvaddr > 0) {
1097e689e2dSmartin sparc_promaddr_to_handle(sc->sc_tag,
1107e689e2dSmartin ea->ea_vaddr[0], &sc->sc_led);
1117e689e2dSmartin } else {
1127e689e2dSmartin bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
1137e689e2dSmartin ea->ea_reg[0].size, 0, &sc->sc_led);
1147e689e2dSmartin }
1157e689e2dSmartin
1167e689e2dSmartin auxio_attach_common(sc);
1177e689e2dSmartin }
118