1 /* $NetBSD: hpcioman.c,v 1.17 2009/05/12 12:13:49 cegger Exp $ */
4 * Copyright (c) 1999-2001 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: hpcioman.c,v 1.17 2009/05/12 12:13:49 cegger Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
39 #include <machine/config_hook.h>
40 #include <machine/platid.h>
41 #include <machine/platid_mask.h>
44 #include <dev/hpc/hpciovar.h>
45 #include <dev/hpc/hpciomanvar.h>
49 int hpcioman_match(device_t
, cfdata_t
, void *);
50 void hpcioman_attach(device_t
, device_t
, void *);
51 int hpcioman_print(void *, const char *);
52 int hpcioman_search(device_t
, cfdata_t
,
55 struct hpcioman_softc
{
59 CFATTACH_DECL(hpcioman
, sizeof(struct hpcioman_softc
),
60 hpcioman_match
, hpcioman_attach
, NULL
, NULL
);
63 hpcioman_match(device_t parent
, cfdata_t cf
, void *aux
)
65 struct hpcio_attach_args
*haa
= aux
;
68 if (strcmp(haa
->haa_busname
, HPCIO_BUSNAME
))
71 mask
= PLATID_DEREF(cf
->cf_loc
[HPCIOIFCF_PLATFORM
]);
73 return (platid_match(&platid
, &mask
));
77 hpcioman_attach(device_t parent
, device_t self
, void *aux
)
81 config_search_ia(hpcioman_search
, self
, "hpcioman", aux
);
85 hpcioman_search(device_t parent
, cfdata_t cf
,
86 const int *ldesc
, void *aux
)
88 //struct hpcioman_softc *sc = (struct hpcioman_softc *)parent;
89 struct hpcio_attach_args
*haa
= aux
;
90 struct hpcioman_attach_args hma
;
93 hma
.hma_hc
= (*haa
->haa_getchip
)(haa
->haa_sc
, cf
->cf_iochip
);
96 if (cf
->cf_level
!= HPCIOMANCF_LEVEL_DEFAULT
) {
97 switch (cf
->cf_hold
) {
99 hma
.hma_intr_mode
= HPCIO_INTR_HOLD
;
102 case HPCIOMANCF_HOLD_DEFAULT
:
104 hma
.hma_intr_mode
= HPCIO_INTR_THROUGH
;
107 hma
.hma_intr_mode
|= HPCIO_INTR_LEVEL
;
108 if (cf
->cf_level
== 0)
109 hma
.hma_intr_mode
|= HPCIO_INTR_LOW
;
111 hma
.hma_intr_mode
|= HPCIO_INTR_HIGH
;
113 switch (cf
->cf_hold
) {
115 hma
.hma_intr_mode
= HPCIO_INTR_THROUGH
;
118 case HPCIOMANCF_HOLD_DEFAULT
:
120 hma
.hma_intr_mode
= HPCIO_INTR_HOLD
;
123 hma
.hma_intr_mode
|= HPCIO_INTR_EDGE
;
124 switch (cf
->cf_edge
) {
126 hma
.hma_intr_mode
|= HPCIO_INTR_POSEDGE
;
129 hma
.hma_intr_mode
|= HPCIO_INTR_NEGEDGE
;
133 case HPCIOMANCF_EDGE_DEFAULT
:
134 hma
.hma_intr_mode
|= HPCIO_INTR_POSEDGE
;
135 hma
.hma_intr_mode
|= HPCIO_INTR_NEGEDGE
;
138 printf("%s(%d): invalid configuration, edge=%d",
139 __FILE__
, __LINE__
, cf
->cf_edge
);
144 hma
.hma_type
= cf
->cf_type
;
145 hma
.hma_id
= cf
->cf_id
;
146 hma
.hma_port
= cf
->cf_port
;
147 if (cf
->cf_active
== 0) {
154 hma
.hma_initvalue
= -1; /* none */
155 if (cf
->cf_initvalue
!= HPCIOMANCF_INITVALUE_DEFAULT
) {
156 if (cf
->cf_initvalue
== 0)
157 hma
.hma_initvalue
= hma
.hma_off
;
159 hma
.hma_initvalue
= hma
.hma_on
;
161 hma
.hma_connect
= cf
->cf_connect
;
163 config_attach(parent
, cf
, &hma
, hpcioman_print
);
169 hpcioman_print(void *aux
, const char *pnp
)
171 struct hpcioman_attach_args
*hma
= aux
;
172 int type
= hma
->hma_type
;
175 aprint_normal(" iochip %s, port %d, type %d, id %d",
176 hma
->hma_hc
? hma
->hma_hc
->hc_name
: "not found",
177 hma
->hma_port
, type
, hma
->hma_id
);
178 if (type
== CONFIG_HOOK_BUTTONEVENT
||
179 type
== CONFIG_HOOK_PMEVENT
||
180 type
== CONFIG_HOOK_EVENT
||
181 type
== CONFIG_HOOK_PCIINTR
) {
182 if (hma
->hma_intr_mode
& HPCIO_INTR_EDGE
)
183 aprint_normal (", interrupt edge [%s%s]",
184 (hma
->hma_intr_mode
&HPCIO_INTR_POSEDGE
)
186 (hma
->hma_intr_mode
&HPCIO_INTR_NEGEDGE
)
189 aprint_normal (", interrupt level %s",
190 (hma
->hma_intr_mode
&HPCIO_INTR_HIGH
) ?
193 if (hma
->hma_initvalue
!= -1)
194 aprint_normal(", initial value %d", hma
->hma_initvalue
);
195 if (hma
->hma_on
== 0)
196 aprint_normal(", active low");