Home | History | Annotate | Line # | Download | only in dev
auxio_ebus.c revision 1.4
      1 /*	$NetBSD: auxio_ebus.c,v 1.4 2000/04/13 09:53:49 mrg Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2000 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  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  */
     30 
     31 /*
     32  * AUXIO registers support on the Ebus2.
     33  */
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/errno.h>
     38 #include <sys/device.h>
     39 #include <sys/malloc.h>
     40 
     41 #include <machine/autoconf.h>
     42 #include <machine/cpu.h>
     43 
     44 #include <sparc64/dev/ebusreg.h>
     45 #include <sparc64/dev/ebusvar.h>
     46 #include <sparc64/dev/auxioreg.h>
     47 #include <sparc64/dev/auxiovar.h>
     48 
     49 #define	AUXIO_ROM_NAME		"auxio"
     50 
     51 int	auxio_ebus_match __P((struct device *, struct cfdata *, void *));
     52 void	auxio_ebus_attach __P((struct device *, struct device *, void *));
     53 
     54 struct cfattach auxio_ebus_ca = {
     55 	sizeof(struct device), auxio_ebus_match, auxio_ebus_attach
     56 };
     57 
     58 /*
     59  * We export this structure so that anyone who wishes to fiddle the
     60  * AUXIO registers can.
     61  *
     62  * XXX we need to better design the access here for when there are
     63  * multiple Ebus2's in one system..
     64  */
     65 struct auxio_registers auxio_registers;
     66 
     67 int
     68 auxio_ebus_match(parent, cf, aux)
     69 	struct device *parent;
     70 	struct cfdata *cf;
     71 	void *aux;
     72 {
     73 	struct ebus_attach_args *ea = aux;
     74 
     75 	return (strcmp(AUXIO_ROM_NAME, ea->ea_name) == 0);
     76 }
     77 
     78 void
     79 auxio_ebus_attach(parent, self, aux)
     80 	struct device *parent, *self;
     81 	void *aux;
     82 {
     83 	struct ebus_attach_args *ea = aux;
     84 	int i, first = 1;
     85 
     86 	/*
     87 	 * for each of the registers found, if we know the matching
     88 	 * AUXIO register, set it up.
     89 	 */
     90 	for (i = 0; i < ea->ea_nregs; i++) {
     91 
     92 #define	SHOWIT(s) do { \
     93 	if (first) { \
     94 		first = 0; \
     95 		printf(": found"); \
     96 	} \
     97 	printf(" %s", s); \
     98 } while (0)
     99 
    100 		if (ea->ea_regs[i].lo == AUXIO_FD) {
    101 			SHOWIT("fd");
    102 			auxio_registers.auxio_fd.lo = ea->ea_regs[i].lo;
    103 			auxio_registers.auxio_fd.hi = ea->ea_regs[i].hi;
    104 		} else if (ea->ea_regs[i].lo == AUXIO_AUDIO) {
    105 			SHOWIT("audio");
    106 			auxio_registers.auxio_audio.lo = ea->ea_regs[i].lo;
    107 			auxio_registers.auxio_audio.hi = ea->ea_regs[i].hi;
    108 		} else if (ea->ea_regs[i].lo == AUXIO_POWER) {
    109 			SHOWIT("power");
    110 			auxio_registers.auxio_power.lo = ea->ea_regs[i].lo;
    111 			auxio_registers.auxio_power.hi = ea->ea_regs[i].hi;
    112 		} else if (ea->ea_regs[i].lo == AUXIO_LED) {
    113 			SHOWIT("led");
    114 			auxio_registers.auxio_led.lo = ea->ea_regs[i].lo;
    115 			auxio_registers.auxio_led.hi = ea->ea_regs[i].hi;
    116 		} else if (ea->ea_regs[i].lo == AUXIO_PCI) {
    117 			SHOWIT("pci");
    118 			auxio_registers.auxio_pci.lo = ea->ea_regs[i].lo;
    119 			auxio_registers.auxio_pci.hi = ea->ea_regs[i].hi;
    120 		} else if (ea->ea_regs[i].lo == AUXIO_FREQ) {
    121 			SHOWIT("freq");
    122 			auxio_registers.auxio_freq.lo = ea->ea_regs[i].lo;
    123 			auxio_registers.auxio_freq.hi = ea->ea_regs[i].hi;
    124 		} else if (ea->ea_regs[i].lo == AUXIO_SCSI) {
    125 			SHOWIT("scsi");
    126 			auxio_registers.auxio_scsi.lo = ea->ea_regs[i].lo;
    127 			auxio_registers.auxio_scsi.hi = ea->ea_regs[i].hi;
    128 		} else if (ea->ea_regs[i].lo == AUXIO_TEMP) {
    129 			SHOWIT("temp");
    130 			auxio_registers.auxio_temp.lo = ea->ea_regs[i].lo;
    131 			auxio_registers.auxio_temp.hi = ea->ea_regs[i].hi;
    132 		} else {
    133 			printf(": unknown auxio register %x.%x",
    134 			    ea->ea_regs[i].hi, ea->ea_regs[i].lo);
    135 		}
    136 	}
    137 	printf("\n");
    138 }
    139