xref: /netbsd-src/sys/arch/sparc64/dev/auxio_sbus.c (revision 1dc652ef5a0bffbd0917f95e0797bad8c6fc8efd)
1*1dc652efSthorpej /*	$NetBSD: auxio_sbus.c,v 1.2 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_sbus.c,v 1.2 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_sbus_match(device_t, cfdata_t, void *);
567e689e2dSmartin static void	auxio_sbus_attach(device_t, device_t, void *);
577e689e2dSmartin 
587e689e2dSmartin CFATTACH_DECL_NEW(auxio_sbus, sizeof(struct auxio_softc),
597e689e2dSmartin     auxio_sbus_match, auxio_sbus_attach, NULL, NULL);
607e689e2dSmartin 
617e689e2dSmartin static int
auxio_sbus_match(device_t parent,cfdata_t cf,void * aux)627e689e2dSmartin auxio_sbus_match(device_t parent, cfdata_t cf, void *aux)
637e689e2dSmartin {
647e689e2dSmartin 	struct sbus_attach_args *sa = aux;
657e689e2dSmartin 
667e689e2dSmartin 	return strcmp(AUXIO_ROM_NAME, sa->sa_name) == 0;
677e689e2dSmartin }
687e689e2dSmartin 
697e689e2dSmartin static void
auxio_sbus_attach(device_t parent,device_t self,void * aux)707e689e2dSmartin auxio_sbus_attach(device_t parent, device_t self, void *aux)
717e689e2dSmartin {
727e689e2dSmartin 	struct auxio_softc *sc = device_private(self);
737e689e2dSmartin 	struct sbus_attach_args *sa = aux;
747e689e2dSmartin 
757e689e2dSmartin 	sc->sc_dev = self;
767e689e2dSmartin 	sc->sc_tag = sa->sa_bustag;
777e689e2dSmartin 
787e689e2dSmartin 	if (sa->sa_nreg < 1) {
797e689e2dSmartin 		printf(": no registers??\n");
807e689e2dSmartin 		return;
817e689e2dSmartin 	}
827e689e2dSmartin 
837e689e2dSmartin 	if (sa->sa_nreg != 1) {
847e689e2dSmartin 		printf(": not 1 (%d/%d) registers??", sa->sa_nreg,
857e689e2dSmartin 		    sa->sa_npromvaddrs);
867e689e2dSmartin 		return;
877e689e2dSmartin 	}
887e689e2dSmartin 
897e689e2dSmartin 	/* sbus auxio only has one set of registers */
907e689e2dSmartin 	sc->sc_flags = AUXIO_LEDONLY;
917e689e2dSmartin 	if (sa->sa_npromvaddrs > 0) {
927e689e2dSmartin 		sbus_promaddr_to_handle(sc->sc_tag,
937e689e2dSmartin 			sa->sa_promvaddr, &sc->sc_led);
947e689e2dSmartin 	} else {
957e689e2dSmartin 		sbus_bus_map(sc->sc_tag, sa->sa_slot, sa->sa_offset,
967e689e2dSmartin 			sa->sa_size, 0, &sc->sc_led);
977e689e2dSmartin 	}
987e689e2dSmartin 
997e689e2dSmartin 	auxio_attach_common(sc);
1007e689e2dSmartin }
101