Home | History | Annotate | Line # | Download | only in mca
      1 /*-
      2  * Copyright (c) 2007 The NetBSD Foundation, Inc.
      3  * All rights reserved.
      4  *
      5  * This code is derived from software contributed to The NetBSD Foundation
      6  * by Tim Rightnour
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27  * POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #include <sys/cdefs.h>
     31 __KERNEL_RCSID(0, "$NetBSD: ioplanar.c,v 1.6 2021/08/07 16:19:03 thorpej Exp $");
     32 
     33 #include <sys/param.h>
     34 #include <sys/device.h>
     35 #include <sys/bus.h>
     36 
     37 #include <machine/intr.h>
     38 
     39 #include <dev/mca/mcavar.h>
     40 #include <dev/mca/mcadevs.h>
     41 
     42 #include <rs6000/ioplanar/ioplanarvar.h>
     43 
     44 static int	ioplanar_match(device_t, cfdata_t, void *);
     45 static void	ioplanar_attach(device_t, device_t, void *);
     46 static int	ioplanar_print(void *, const char *);
     47 static int	ioplanar_search(device_t, cfdata_t, const int *, void *);
     48 
     49 CFATTACH_DECL_NEW(ioplanar, sizeof(struct ioplanar_softc),
     50     ioplanar_match, ioplanar_attach, NULL, NULL);
     51 
     52 struct ioplanar_softc *ioplanar_softc;
     53 extern struct cfdriver ioplanar_cd;
     54 
     55 #define RAINBOW_DEVS	7
     56 int rainbow_map[RAINBOW_DEVS] =
     57 	{ IOP_COM0, IOP_COM1, IOP_LPD, IOP_KBD_2,
     58 	  IOP_TABLET_2, IOP_MOUSE, IOP_FDC_2 };
     59 
     60 static int
     61 ioplanar_match(device_t parent, cfdata_t cf, void *aux)
     62 {
     63 	struct mca_attach_args *ma = aux;
     64 
     65 	switch (ma->ma_id) {
     66 	case MCA_PRODUCT_IBM_SIO_RAINBOW:
     67 		return 1;
     68 	}
     69 
     70 	return 0;
     71 }
     72 
     73 static void
     74 ioplanar_attach(device_t parent, device_t self, void *aux)
     75 {
     76 	struct ioplanar_softc *sc = device_private(self);
     77 	struct mca_attach_args *ma = aux;
     78 
     79 	aprint_normal("\n");
     80 
     81 	ioplanar_softc = sc;
     82 	sc->sc_dev = self;
     83 	sc->sc_ic = ma->ma_mc;
     84 	sc->sc_iot = ma->ma_iot;
     85 	sc->sc_memt = ma->ma_memt;
     86 	sc->sc_dmat = ma->ma_dmat;
     87 	sc->sc_devid = ma->ma_id;
     88 
     89 	config_search(self, aux,
     90 	    CFARGS(.search = ioplanar_search));
     91 }
     92 
     93 static int
     94 ioplanar_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
     95 {
     96 	struct ioplanar_dev_attach_args idaa;
     97 	struct mca_attach_args *ma = aux;
     98 	int i;
     99 
    100 	idaa.idaa_mc = ma->ma_mc;
    101 	idaa.idaa_iot = ma->ma_iot;
    102 	idaa.idaa_memt = ma->ma_memt;
    103 	idaa.idaa_dmat = ma->ma_dmat;
    104 	idaa.idaa_devid = ma->ma_id;
    105 
    106 	switch (ma->ma_id) {
    107 	case MCA_PRODUCT_IBM_SIO_RAINBOW:
    108 		for (i=0; i < RAINBOW_DEVS; i++) {
    109 			idaa.idaa_device = rainbow_map[i];
    110 			if (config_probe(parent, cf, &idaa))
    111 				config_attach(parent, cf, &idaa,
    112 				    ioplanar_print, CFARGS_NONE);
    113 		}
    114 		break;
    115 	default:
    116 		return 0;
    117 	}
    118 	return 0;
    119 }
    120 
    121 static int
    122 ioplanar_print(void *args, const char *name)
    123 {
    124 	/*struct ioplanar_dev_attach_args *idaa = args;*/
    125 
    126 	aprint_normal(": ");
    127 	return (UNCONF);
    128 }
    129