Home | History | Annotate | Line # | Download | only in acpi
      1 /*	$NetBSD: spic_acpi.c,v 1.9 2021/01/29 15:49:55 thorpej 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  *
     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 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: spic_acpi.c,v 1.9 2021/01/29 15:49:55 thorpej Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/device.h>
     37 #include <sys/systm.h>
     38 
     39 #include <dev/acpi/acpireg.h>
     40 #include <dev/acpi/acpivar.h>
     41 #include <dev/acpi/acpi_intr.h>
     42 
     43 #include <dev/ic/spicvar.h>
     44 
     45 #define _COMPONENT		ACPI_RESOURCE_COMPONENT
     46 ACPI_MODULE_NAME		("spic_acpi")
     47 
     48 struct spic_acpi_softc {
     49 	struct spic_softc sc_spic;	/* spic device */
     50 
     51 	struct acpi_devnode *sc_node;	/* our ACPI devnode */
     52 
     53 	void *sc_ih;
     54 };
     55 
     56 static const struct device_compatible_entry compat_data[] = {
     57 	{ .compat = "SNY6001" },
     58 	DEVICE_COMPAT_EOL
     59 };
     60 
     61 static int	spic_acpi_match(device_t, cfdata_t, void *);
     62 static void	spic_acpi_attach(device_t, device_t, void *);
     63 
     64 CFATTACH_DECL_NEW(spic_acpi, sizeof(struct spic_acpi_softc),
     65     spic_acpi_match, spic_acpi_attach, NULL, NULL);
     66 
     67 
     68 static int
     69 spic_acpi_match(device_t parent, cfdata_t match, void *aux)
     70 {
     71 	struct acpi_attach_args *aa = aux;
     72 
     73 	return acpi_compatible_match(aa, compat_data);
     74 }
     75 
     76 static void
     77 spic_acpi_attach(device_t parent, device_t self, void *aux)
     78 {
     79 	struct spic_acpi_softc *sc = device_private(self);
     80 	struct acpi_attach_args *aa = aux;
     81 	struct acpi_io *io;
     82 	struct acpi_irq *irq;
     83 	struct acpi_resources res;
     84 
     85 	ACPI_STATUS rv;
     86 
     87 	sc->sc_spic.sc_dev = self;
     88 	sc->sc_node = aa->aa_node;
     89 
     90 	/* Parse our resources. */
     91 	rv = acpi_resource_parse(self, sc->sc_node->ad_handle,
     92 	    "_CRS", &res, &acpi_resource_parse_ops_default);
     93 	if (ACPI_FAILURE(rv))
     94 		return;
     95 
     96 	sc->sc_spic.sc_iot = aa->aa_iot;
     97 	io = acpi_res_io(&res, 0);
     98 	if (io == NULL) {
     99 		aprint_error_dev(self, "unable to find io resource\n");
    100 		goto out;
    101 	}
    102 	if (bus_space_map(sc->sc_spic.sc_iot, io->ar_base, io->ar_length,
    103 	    0, &sc->sc_spic.sc_ioh) != 0) {
    104 		aprint_error_dev(self, "unable to map data register\n");
    105 		goto out;
    106 	}
    107 	irq = acpi_res_irq(&res, 0);
    108 	if (irq == NULL) {
    109 		aprint_error_dev(self, "unable to find irq resource\n");
    110 		/* XXX unmap */
    111 		goto out;
    112 	}
    113 #if 0
    114 	sc->sc_ih = acpi_intr_establish(self,
    115 	    (uint64_t)(uintptr_t)aa->aa_node->ad_handle,
    116 	    IPL_TTY, false, spic_intr, sc, device_xname(self));
    117 	if (sc->sc_ih == NULL) {
    118 		aprint_error_dev(self, "unable to establish interrupt\n");
    119 		goto out;
    120 	}
    121 #endif
    122 
    123 	if (!pmf_device_register(self, spic_suspend, spic_resume))
    124 		aprint_error_dev(self, "couldn't establish power handler\n");
    125 	else
    126 		pmf_class_input_register(self);
    127 
    128 	spic_attach(&sc->sc_spic);
    129  out:
    130 	acpi_resource_cleanup(&res);
    131 }
    132