txioman.c revision 1.2
1/*	$NetBSD: txioman.c,v 1.2 2000/10/22 10:42:33 uch Exp $ */
2
3/*-
4 * Copyright (c) 1999, 2000 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#include "opt_tx39_debug.h"
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/device.h>
43
44#include <machine/bus.h>
45#include <machine/intr.h>
46
47#include <machine/config_hook.h>
48#include <machine/platid.h>
49#include <machine/platid_mask.h>
50
51#include <hpcmips/tx/tx39var.h>
52#include <hpcmips/tx/txiomanvar.h>
53
54#include "locators.h"
55
56int	txioman_match(struct device *, struct cfdata *, void *);
57void	txioman_attach(struct device *, struct device *, void *);
58int	txioman_print(void *, const char *);
59int	txioman_search(struct device *, struct cfdata *, void *);
60
61struct txioman_softc {
62	struct device sc_dev;
63};
64
65struct cfattach txioman_ca = {
66	sizeof(struct txioman_softc), txioman_match, txioman_attach
67};
68
69int
70txioman_match(struct device *parent, struct cfdata *cf, void *aux)
71{
72	platid_mask_t mask;
73
74	/* select platform */
75	mask = PLATID_DEREF(cf->cf_loc[TXSIMCF_PLATFORM]);
76	if (platid_match(&platid, &mask)) {
77		return ATTACH_NORMAL;
78	}
79
80	return 0;
81}
82
83void
84txioman_attach(struct device *parent, struct device *self, void *aux)
85{
86	struct txsim_attach_args *ta = aux;
87	struct txio_attach_args taa;
88
89	taa.taa_tc = ta->ta_tc;
90	printf("\n");
91
92	config_search(txioman_search, self, &taa);
93}
94
95int
96txioman_search(struct device *parent, struct cfdata *cf, void *aux)
97{
98	struct txio_attach_args *taa = aux;
99
100	taa->taa_group	= cf->cf_group;
101	taa->taa_port	= cf->cf_port;
102	taa->taa_type	= cf->cf_type;
103	taa->taa_id	= cf->cf_id;
104	taa->taa_edge	= cf->cf_edge;
105	taa->taa_initial = cf->cf_initial;
106
107	config_attach(parent, cf, taa, txioman_print);
108
109	return 0;
110}
111
112int
113txioman_print(void *aux, const char *pnp)
114{
115	struct txio_attach_args *taa = aux;
116	int edge = taa->taa_edge;
117	int type = taa->taa_type;
118
119	if (!pnp)  {
120		printf(" group %d port %d type %d id %d", taa->taa_group,
121		       taa->taa_port, type, taa->taa_id);
122		if (type == CONFIG_HOOK_BUTTONEVENT ||
123		    type == CONFIG_HOOK_PMEVENT ||
124		    type == CONFIG_HOOK_EVENT) {
125			printf (" interrupt edge [%s%s]",
126				edge & 0x1 ? "p" : "", edge & 0x2 ? "n" : "");
127		}
128		if (taa->taa_initial != -1)
129			printf(" initial %d", taa->taa_initial);
130	}
131
132	return QUIET;
133}
134