1 /* $NetBSD: attimer_acpi.c,v 1.13 2009/04/07 17:59:18 dyoung Exp $ */ 2 3 /* 4 * Copyright (c) 2005 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Quentin Garnier. 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 * 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. 30 */ 31 32 /* 33 * Copyright (c) 2002 Jared D. McNeill <jmcneill@invisible.ca> 34 * All rights reserved. 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions 38 * are met: 39 * 1. Redistributions of source code must retain the above copyright 40 * notice, this list of conditions and the following disclaimer. 41 * 2. The name of the author may not be used to endorse or promote products 42 * derived from this software without specific prior written permission. 43 * 44 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 45 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 46 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 47 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 48 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 49 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 50 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 51 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 52 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 54 * SUCH DAMAGE. 55 */ 56 57 /* 58 * ACPI attimer(4) attachment based on lpt_acpi.c by Jared D. McNeill. 59 */ 60 61 #include <sys/cdefs.h> 62 __KERNEL_RCSID(0, "$NetBSD: attimer_acpi.c,v 1.13 2009/04/07 17:59:18 dyoung Exp $"); 63 64 #include <sys/param.h> 65 #include <sys/systm.h> 66 #include <sys/errno.h> 67 #include <sys/ioctl.h> 68 #include <sys/device.h> 69 #include <sys/proc.h> 70 71 #include <sys/bus.h> 72 73 #include <dev/acpi/acpica.h> 74 #include <dev/acpi/acpireg.h> 75 #include <dev/acpi/acpivar.h> 76 77 #include <dev/ic/attimervar.h> 78 79 static int attimer_acpi_match(device_t, cfdata_t, void *); 80 static void attimer_acpi_attach(device_t, device_t, void *); 81 82 CFATTACH_DECL3_NEW(attimer_acpi, sizeof(struct attimer_softc), 83 attimer_acpi_match, attimer_acpi_attach, attimer_detach, NULL, NULL, NULL, 84 DVF_DETACH_SHUTDOWN); 85 86 /* 87 * Supported device IDs 88 */ 89 90 static const char * const attimer_acpi_ids[] = { 91 "PNP0100", /* AT Timer */ 92 NULL 93 }; 94 95 /* 96 * attimer_acpi_match: autoconf(9) match routine 97 */ 98 static int 99 attimer_acpi_match(device_t parent, cfdata_t match, void *aux) 100 { 101 struct acpi_attach_args *aa = aux; 102 103 if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) 104 return 0; 105 106 return acpi_match_hid(aa->aa_node->ad_devinfo, attimer_acpi_ids); 107 } 108 109 /* 110 * attimer_acpi_attach: autoconf(9) attach routine 111 */ 112 static void 113 attimer_acpi_attach(device_t parent, device_t self, void *aux) 114 { 115 struct attimer_softc *sc = device_private(self); 116 struct acpi_attach_args *aa = aux; 117 struct acpi_resources res; 118 struct acpi_io *io; 119 ACPI_STATUS rv; 120 121 sc->sc_dev = self; 122 123 /* parse resources */ 124 rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS", 125 &res, &acpi_resource_parse_ops_default); 126 if (ACPI_FAILURE(rv)) 127 return; 128 129 /* find our i/o registers */ 130 io = acpi_res_io(&res, 0); 131 if (io == NULL) { 132 aprint_error_dev(self, 133 "unable to find i/o register resource\n"); 134 goto out; 135 } 136 137 sc->sc_iot = aa->aa_iot; 138 sc->sc_size = io->ar_length; 139 if (bus_space_map(sc->sc_iot, io->ar_base, sc->sc_size, 140 0, &sc->sc_ioh) != 0) { 141 aprint_error_dev(self, "can't map i/o space\n"); 142 goto out; 143 } 144 145 attimer_attach(sc); 146 147 out: 148 acpi_resource_cleanup(&res); 149 } 150