No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / acpi / spic_acpi.c
blob2405c774eaddbcab417bec59921907414480f815
1 /* $NetBSD: spic_acpi.c,v 1.21 2009/02/21 00:30:37 jmcneill Exp $ */
3 /*
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net).
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.
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: spic_acpi.c,v 1.21 2009/02/21 00:30:37 jmcneill Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 #include <sys/proc.h>
39 #include <sys/kernel.h>
40 #include <sys/callout.h>
41 #include <sys/bus.h>
43 #include <dev/ic/spicvar.h>
45 #include <dev/acpi/acpica.h>
46 #include <dev/acpi/acpivar.h>
48 struct spic_acpi_softc {
49 struct spic_softc sc_spic; /* spic device */
51 struct acpi_devnode *sc_node; /* our ACPI devnode */
53 void *sc_ih;
56 static const char * const spic_acpi_ids[] = {
57 "SNY6001",
58 NULL
61 static int spic_acpi_match(device_t, cfdata_t, void *);
62 static void spic_acpi_attach(device_t, device_t, void *);
64 CFATTACH_DECL_NEW(spic_acpi, sizeof(struct spic_acpi_softc),
65 spic_acpi_match, spic_acpi_attach, NULL, NULL);
68 static int
69 spic_acpi_match(device_t parent, cfdata_t match, void *aux)
71 struct acpi_attach_args *aa = aux;
73 if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
74 return (0);
76 return (acpi_match_hid(aa->aa_node->ad_devinfo, spic_acpi_ids));
79 static void
80 spic_acpi_attach(device_t parent, device_t self, void *aux)
82 struct spic_acpi_softc *sc = device_private(self);
83 struct acpi_attach_args *aa = aux;
84 struct acpi_io *io;
85 struct acpi_irq *irq;
86 struct acpi_resources res;
88 ACPI_STATUS rv;
90 sc->sc_spic.sc_dev = self;
91 sc->sc_node = aa->aa_node;
93 /* Parse our resources. */
94 rv = acpi_resource_parse(self, sc->sc_node->ad_handle,
95 "_CRS", &res, &acpi_resource_parse_ops_default);
96 if (ACPI_FAILURE(rv))
97 return;
99 sc->sc_spic.sc_iot = aa->aa_iot;
100 io = acpi_res_io(&res, 0);
101 if (io == NULL) {
102 aprint_error_dev(self, "unable to find io resource\n");
103 goto out;
105 if (bus_space_map(sc->sc_spic.sc_iot, io->ar_base, io->ar_length,
106 0, &sc->sc_spic.sc_ioh) != 0) {
107 aprint_error_dev(self, "unable to map data register\n");
108 goto out;
110 irq = acpi_res_irq(&res, 0);
111 if (irq == NULL) {
112 aprint_error_dev(self, "unable to find irq resource\n");
113 /* XXX unmap */
114 goto out;
116 #if 0
117 sc->sc_ih = isa_intr_establish(NULL, irq->ar_irq,
118 IST_EDGE, IPL_TTY, spic_intr, sc);
119 #endif
121 if (!pmf_device_register(self, spic_suspend, spic_resume))
122 aprint_error_dev(self, "couldn't establish power handler\n");
123 else
124 pmf_class_input_register(self);
126 spic_attach(&sc->sc_spic);
127 out:
128 acpi_resource_cleanup(&res);