Home | History | Annotate | Line # | Download | only in hpc
hpcioman.c revision 1.2
      1 /*	$NetBSD: hpcioman.c,v 1.2 2001/05/01 00:25:17 takemura Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1999-2001 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by UCHIYAMA Yasushi.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/param.h>
     40 #include <sys/systm.h>
     41 #include <sys/device.h>
     42 
     43 #include <machine/config_hook.h>
     44 #include <machine/platid.h>
     45 #include <machine/platid_mask.h>
     46 
     47 #include <dev/hpc/hpciovar.h>
     48 #include <dev/hpc/hpciomanvar.h>
     49 
     50 #include "locators.h"
     51 
     52 int	hpcioman_match(struct device *, struct cfdata *, void *);
     53 void	hpcioman_attach(struct device *, struct device *, void *);
     54 int	hpcioman_print(void *, const char *);
     55 int	hpcioman_search(struct device *, struct cfdata *, void *);
     56 
     57 struct hpcioman_softc {
     58 	struct device sc_dev;
     59 };
     60 
     61 struct cfattach hpcioman_ca = {
     62 	sizeof(struct hpcioman_softc), hpcioman_match, hpcioman_attach
     63 };
     64 
     65 int
     66 hpcioman_match(struct device *parent, struct cfdata *cf, void *aux)
     67 {
     68 	struct hpcio_attach_args *haa = aux;
     69 	platid_mask_t mask;
     70 
     71 	if (strcmp(haa->haa_busname, HPCIO_BUSNAME))
     72 		return 0;
     73 	/* select platform */
     74 	mask = PLATID_DEREF(cf->cf_loc[HPCIOIFCF_PLATFORM]);
     75 
     76 	return platid_match(&platid, &mask);
     77 }
     78 
     79 void
     80 hpcioman_attach(struct device *parent, struct device *self, void *aux)
     81 {
     82 	printf("\n");
     83 
     84 	config_search(hpcioman_search, self, aux);
     85 }
     86 
     87 int
     88 hpcioman_search(struct device *parent, struct cfdata *cf, void *aux)
     89 {
     90 	//struct hpcioman_softc *sc = (struct hpcioman_softc *)parent;
     91 	struct hpcio_attach_args *haa = aux;
     92 	struct hpcioman_attach_args hma;
     93 
     94 	/* get io chip */
     95 	hma.hma_hc = (*haa->haa_getchip)(haa->haa_sc, cf->cf_iochip);
     96 
     97 	/* interrupt mode */
     98 	hma.hma_intr_mode = HPCIO_INTR_HOLD;
     99 	if (cf->cf_level != HPCIOMANCF_LEVEL_DEFAULT) {
    100 		hma.hma_intr_mode |= HPCIO_INTR_LEVEL;
    101 		if (cf->cf_level == 0)
    102 			hma.hma_intr_mode |= HPCIO_INTR_LOW;
    103 		else
    104 			hma.hma_intr_mode |= HPCIO_INTR_HIGH;
    105 	} else {
    106 		hma.hma_intr_mode |= HPCIO_INTR_EDGE;
    107 		switch (cf->cf_edge) {
    108 		case 1:
    109 			hma.hma_intr_mode |= HPCIO_INTR_POSEDGE;
    110 			break;
    111 		case 2:
    112 			hma.hma_intr_mode |= HPCIO_INTR_NEGEDGE;
    113 			break;
    114 		case 0:
    115 		case 3:
    116 		case HPCIOMANCF_EDGE_DEFAULT:
    117 			hma.hma_intr_mode |= HPCIO_INTR_POSEDGE;
    118 			hma.hma_intr_mode |= HPCIO_INTR_NEGEDGE;
    119 			break;
    120 		default:
    121 			printf("%s(%d): invalid configuration, edge=%d",
    122 			    __FILE__, __LINE__, cf->cf_edge);
    123 			break;
    124 		}
    125 	}
    126 
    127 	hma.hma_type = cf->cf_type;
    128 	hma.hma_id = cf->cf_id;
    129 	hma.hma_port = cf->cf_port;
    130 	if (cf->cf_active == 0) {
    131 		hma.hma_on = 0;
    132 		hma.hma_off = 1;
    133 	} else {
    134 		hma.hma_on = 1;
    135 		hma.hma_off = 0;
    136 	}
    137 	hma.hma_initvalue = -1; /* none */
    138 	if (cf->cf_initvalue != HPCIOMANCF_INITVALUE_DEFAULT) {
    139 		if (cf->cf_initvalue == 0)
    140 			hma.hma_initvalue = hma.hma_off;
    141 		else
    142 			hma.hma_initvalue = hma.hma_on;
    143 	}
    144 
    145 	config_attach(parent, cf, &hma, hpcioman_print);
    146 
    147 	return (0);
    148 }
    149 
    150 int
    151 hpcioman_print(void *aux, const char *pnp)
    152 {
    153 	struct hpcioman_attach_args *hma = aux;
    154 	int type = hma->hma_type;
    155 
    156 	if (!pnp)  {
    157 		printf(" iochip %s, port %d, type %d, id %d",
    158 		       hma->hma_hc ? hma->hma_hc->hc_name : "not found",
    159 		       hma->hma_port, type, hma->hma_id);
    160 		if (type == CONFIG_HOOK_BUTTONEVENT ||
    161 		    type == CONFIG_HOOK_PMEVENT ||
    162 		    type == CONFIG_HOOK_EVENT) {
    163 			if (hma->hma_intr_mode & HPCIO_INTR_EDGE)
    164 				printf (", interrupt edge [%s%s]",
    165 				    (hma->hma_intr_mode&HPCIO_INTR_POSEDGE) ? "p" : "",
    166 				    (hma->hma_intr_mode&HPCIO_INTR_NEGEDGE) ? "n" : "");
    167 			else
    168 				printf (", interrupt level %s",
    169 				    (hma->hma_intr_mode&HPCIO_INTR_HIGH) ? "high" : "low");
    170 		}
    171 		if (hma->hma_initvalue != -1)
    172 			printf(", initial value %d", hma->hma_initvalue);
    173 		if (hma->hma_on == 0)
    174 			printf(", active low");
    175 	}
    176 
    177 	return QUIET;
    178 }
    179