spic_acpi.c revision 1.2 1 /* $NetBSD: spic_acpi.c,v 1.2 2002/06/13 16:48:34 augustss Exp $ */
2
3 /*
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart (at) augustsson.net).
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/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: spic_acpi.c,v 1.2 2002/06/13 16:48:34 augustss Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/proc.h>
46 #include <sys/kernel.h>
47 #include <sys/callout.h>
48
49 #include <machine/bus.h>
50
51 void *isa_intr_establish(void *ic, int irq, int type,
52 int level, int (*ih_fun)(void *), void *ih_arg);
53
54 #include <dev/ic/spicvar.h>
55
56 #include <dev/acpi/acpica.h>
57 #include <dev/acpi/acpivar.h>
58
59 struct spic_acpi_softc {
60 struct spic_softc sc_spic; /* spic device */
61
62 struct acpi_devnode *sc_node; /* our ACPI devnode */
63
64 struct acpi_resources sc_res; /* our bus resources */
65
66 void *sc_ih;
67 };
68
69 int spic_acpi_match(struct device *, struct cfdata *, void *);
70 void spic_acpi_attach(struct device *, struct device *, void *);
71
72 struct cfattach spic_acpi_ca = {
73 sizeof(struct spic_acpi_softc), spic_acpi_match, spic_acpi_attach,
74 /* spic_acpi_detach, spic_acpi_activate */
75 };
76
77 int
78 spic_acpi_match(struct device *parent, struct cfdata *match, void *aux)
79 {
80 struct acpi_attach_args *aa = aux;
81
82 if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
83 return (0);
84
85 if (strcmp(aa->aa_node->ad_devinfo.HardwareId, "SNY6001") == 0)
86 return (1);
87
88 return (0);
89 }
90
91 void
92 spic_acpi_attach(struct device *parent, struct device *self, void *aux)
93 {
94 struct spic_acpi_softc *sc = (void *) self;
95 struct acpi_attach_args *aa = aux;
96 struct acpi_io *io;
97 struct acpi_irq *irq;
98 ACPI_STATUS rv;
99
100 printf(": Sony Programmable I/O Controller\n");
101
102 sc->sc_node = aa->aa_node;
103
104 /* Parse our resources. */
105 rv = acpi_resource_parse(&sc->sc_spic.sc_dev, sc->sc_node, &sc->sc_res,
106 &acpi_resource_parse_ops_default);
107 if (rv != AE_OK) {
108 printf("%s: unable to parse resources: %d\n",
109 sc->sc_spic.sc_dev.dv_xname, rv);
110 return;
111 }
112
113 sc->sc_spic.sc_iot = aa->aa_iot;
114 io = acpi_res_io(&sc->sc_res, 0);
115 if (io == NULL) {
116 printf("%s: unable to find io resource\n",
117 sc->sc_spic.sc_dev.dv_xname);
118 return;
119 }
120 if (bus_space_map(sc->sc_spic.sc_iot, io->ar_base, io->ar_length,
121 0, &sc->sc_spic.sc_ioh) != 0) {
122 printf("%s: unable to map data register\n",
123 sc->sc_spic.sc_dev.dv_xname);
124 return;
125 }
126 irq = acpi_res_irq(&sc->sc_res, 0);
127 if (irq == NULL) {
128 printf("%s: unable to find irq resource\n",
129 sc->sc_spic.sc_dev.dv_xname);
130 /* XXX unmap */
131 return;
132 }
133 #if 0
134 sc->sc_ih = isa_intr_establish(NULL, irq->ar_irq,
135 IST_EDGE, IPL_TTY, spic_intr, sc);
136 #endif
137
138 spic_attach(&sc->sc_spic);
139 }
140
141