11.7Sthorpej/* $NetBSD: ug_acpi.c,v 1.7 2021/01/29 15:49:55 thorpej Exp $ */ 21.1Sxtraeme 31.1Sxtraeme/* 41.1Sxtraeme * Copyright (c) 2007 Mihai Chelaru <kefren@netbsd.ro> 51.1Sxtraeme * All rights reserved. 61.1Sxtraeme * 71.1Sxtraeme * Redistribution and use in source and binary forms, with or without 81.1Sxtraeme * modification, are permitted provided that the following conditions 91.1Sxtraeme * are met: 101.1Sxtraeme * 1. Redistributions of source code must retain the above copyright 111.1Sxtraeme * notice, this list of conditions and the following disclaimer. 121.1Sxtraeme * 2. The name of the author may not be used to endorse or promote products 131.1Sxtraeme * derived from this software without specific prior written permission. 141.1Sxtraeme * 151.1Sxtraeme * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 161.1Sxtraeme * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 171.1Sxtraeme * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 181.1Sxtraeme * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 191.1Sxtraeme * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 201.1Sxtraeme * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 211.1Sxtraeme * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 221.1Sxtraeme * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 231.1Sxtraeme * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 241.1Sxtraeme * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 251.1Sxtraeme * SUCH DAMAGE. 261.1Sxtraeme */ 271.1Sxtraeme 281.2Sxtraeme#include <sys/cdefs.h> 291.7Sthorpej__KERNEL_RCSID(0, "$NetBSD: ug_acpi.c,v 1.7 2021/01/29 15:49:55 thorpej Exp $"); 301.2Sxtraeme 311.1Sxtraeme#include <sys/param.h> 321.6Sjruoho#include <sys/device.h> 331.1Sxtraeme#include <sys/systm.h> 341.1Sxtraeme 351.1Sxtraeme#include <dev/acpi/acpivar.h> 361.1Sxtraeme 371.1Sxtraeme#include <dev/ic/ugreg.h> 381.1Sxtraeme#include <dev/ic/ugvar.h> 391.1Sxtraeme 401.1Sxtraeme/* autoconf(9) functions */ 411.4Sxtraemestatic int ug_acpi_match(device_t, cfdata_t, void *); 421.4Sxtraemestatic void ug_acpi_attach(device_t, device_t, void *); 431.1Sxtraeme 441.4SxtraemeCFATTACH_DECL_NEW(ug_acpi, sizeof(struct ug_softc), ug_acpi_match, 451.1Sxtraeme ug_acpi_attach, NULL, NULL); 461.1Sxtraeme 471.1Sxtraeme/* 481.1Sxtraeme * Supported devices 491.1Sxtraeme * XXX: only uGuru 2005 for now 501.1Sxtraeme */ 511.1Sxtraeme 521.7Sthorpejstatic const struct device_compatible_entry compat_data[] = { 531.7Sthorpej { .compat = "ABT2005" }, /* uGuru 2005 */ 541.7Sthorpej DEVICE_COMPAT_EOL 551.1Sxtraeme}; 561.1Sxtraeme 571.1Sxtraemestatic int 581.4Sxtraemeug_acpi_match(device_t parent, cfdata_t match, void *aux) 591.1Sxtraeme{ 601.1Sxtraeme struct acpi_attach_args *aa = aux; 611.1Sxtraeme 621.7Sthorpej return acpi_compatible_match(aa, compat_data); 631.1Sxtraeme} 641.1Sxtraeme 651.1Sxtraemestatic void 661.4Sxtraemeug_acpi_attach(device_t parent, device_t self, void *aux) 671.1Sxtraeme{ 681.4Sxtraeme struct ug_softc *sc = device_private(self); 691.1Sxtraeme struct acpi_attach_args *aa = aux; 701.1Sxtraeme struct acpi_resources res; 711.1Sxtraeme struct acpi_io *io; 721.1Sxtraeme bus_space_handle_t ioh; 731.1Sxtraeme ACPI_STATUS rv; 741.1Sxtraeme 751.1Sxtraeme /* parse resources */ 761.4Sxtraeme rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS", 771.1Sxtraeme &res, &acpi_resource_parse_ops_default); 781.1Sxtraeme if (ACPI_FAILURE(rv)) 791.1Sxtraeme return; 801.1Sxtraeme 811.1Sxtraeme /* find our i/o registers */ 821.1Sxtraeme io = acpi_res_io(&res, 0); 831.1Sxtraeme if (io == NULL) { 841.4Sxtraeme aprint_error_dev(self, 851.4Sxtraeme "unable to find i/o register resource\n"); 861.1Sxtraeme acpi_resource_cleanup(&res); 871.1Sxtraeme return; 881.1Sxtraeme } 891.1Sxtraeme 901.1Sxtraeme if (bus_space_map(aa->aa_iot, io->ar_base, io->ar_length, 911.1Sxtraeme 0, &ioh)) { 921.4Sxtraeme aprint_error_dev(self, "can't map i/o space\n"); 931.1Sxtraeme acpi_resource_cleanup(&res); 941.1Sxtraeme return; 951.1Sxtraeme } 961.1Sxtraeme 971.4Sxtraeme aprint_normal("%s", device_xname(self)); 981.1Sxtraeme 991.1Sxtraeme sc->version = 2; /* uGuru 2005 */ 1001.1Sxtraeme sc->sc_ioh = ioh; 1011.1Sxtraeme sc->sc_iot = aa->aa_iot; 1021.4Sxtraeme ug2_attach(self); 1031.1Sxtraeme 1041.1Sxtraeme acpi_resource_cleanup(&res); 1051.1Sxtraeme} 106