Home | History | Annotate | Line # | Download | only in acpi
      1  1.9   thorpej /*	$NetBSD: spic_acpi.c,v 1.9 2021/01/29 15:49:55 thorpej Exp $	*/
      2  1.2  augustss 
      3  1.2  augustss /*
      4  1.2  augustss  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5  1.2  augustss  * All rights reserved.
      6  1.2  augustss  *
      7  1.2  augustss  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2  augustss  * by Lennart Augustsson (lennart (at) augustsson.net).
      9  1.2  augustss  *
     10  1.2  augustss  * Redistribution and use in source and binary forms, with or without
     11  1.2  augustss  * modification, are permitted provided that the following conditions
     12  1.2  augustss  * are met:
     13  1.2  augustss  * 1. Redistributions of source code must retain the above copyright
     14  1.2  augustss  *    notice, this list of conditions and the following disclaimer.
     15  1.2  augustss  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2  augustss  *    notice, this list of conditions and the following disclaimer in the
     17  1.2  augustss  *    documentation and/or other materials provided with the distribution.
     18  1.2  augustss  *
     19  1.2  augustss  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.2  augustss  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.2  augustss  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.2  augustss  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.2  augustss  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.2  augustss  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.2  augustss  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.2  augustss  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.2  augustss  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.2  augustss  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.2  augustss  * POSSIBILITY OF SUCH DAMAGE.
     30  1.2  augustss  */
     31  1.2  augustss 
     32  1.1  augustss #include <sys/cdefs.h>
     33  1.9   thorpej __KERNEL_RCSID(0, "$NetBSD: spic_acpi.c,v 1.9 2021/01/29 15:49:55 thorpej Exp $");
     34  1.1  augustss 
     35  1.1  augustss #include <sys/param.h>
     36  1.6    jruoho #include <sys/device.h>
     37  1.1  augustss #include <sys/systm.h>
     38  1.1  augustss 
     39  1.5    jruoho #include <dev/acpi/acpireg.h>
     40  1.1  augustss #include <dev/acpi/acpivar.h>
     41  1.7  jmcneill #include <dev/acpi/acpi_intr.h>
     42  1.1  augustss 
     43  1.6    jruoho #include <dev/ic/spicvar.h>
     44  1.6    jruoho 
     45  1.5    jruoho #define _COMPONENT		ACPI_RESOURCE_COMPONENT
     46  1.5    jruoho ACPI_MODULE_NAME		("spic_acpi")
     47  1.5    jruoho 
     48  1.1  augustss struct spic_acpi_softc {
     49  1.1  augustss 	struct spic_softc sc_spic;	/* spic device */
     50  1.1  augustss 
     51  1.1  augustss 	struct acpi_devnode *sc_node;	/* our ACPI devnode */
     52  1.1  augustss 
     53  1.4  christos 	void *sc_ih;
     54  1.4  christos };
     55  1.1  augustss 
     56  1.9   thorpej static const struct device_compatible_entry compat_data[] = {
     57  1.9   thorpej 	{ .compat = "SNY6001" },
     58  1.9   thorpej 	DEVICE_COMPAT_EOL
     59  1.1  augustss };
     60  1.1  augustss 
     61  1.4  christos static int	spic_acpi_match(device_t, cfdata_t, void *);
     62  1.4  christos static void	spic_acpi_attach(device_t, device_t, void *);
     63  1.4  christos 
     64  1.4  christos CFATTACH_DECL_NEW(spic_acpi, sizeof(struct spic_acpi_softc),
     65  1.4  christos     spic_acpi_match, spic_acpi_attach, NULL, NULL);
     66  1.1  augustss 
     67  1.1  augustss 
     68  1.4  christos static int
     69  1.4  christos spic_acpi_match(device_t parent, cfdata_t match, void *aux)
     70  1.1  augustss {
     71  1.1  augustss 	struct acpi_attach_args *aa = aux;
     72  1.1  augustss 
     73  1.9   thorpej 	return acpi_compatible_match(aa, compat_data);
     74  1.1  augustss }
     75  1.1  augustss 
     76  1.4  christos static void
     77  1.4  christos spic_acpi_attach(device_t parent, device_t self, void *aux)
     78  1.1  augustss {
     79  1.4  christos 	struct spic_acpi_softc *sc = device_private(self);
     80  1.1  augustss 	struct acpi_attach_args *aa = aux;
     81  1.1  augustss 	struct acpi_io *io;
     82  1.1  augustss 	struct acpi_irq *irq;
     83  1.4  christos 	struct acpi_resources res;
     84  1.4  christos 
     85  1.1  augustss 	ACPI_STATUS rv;
     86  1.1  augustss 
     87  1.4  christos 	sc->sc_spic.sc_dev = self;
     88  1.1  augustss 	sc->sc_node = aa->aa_node;
     89  1.1  augustss 
     90  1.1  augustss 	/* Parse our resources. */
     91  1.4  christos 	rv = acpi_resource_parse(self, sc->sc_node->ad_handle,
     92  1.4  christos 	    "_CRS", &res, &acpi_resource_parse_ops_default);
     93  1.4  christos 	if (ACPI_FAILURE(rv))
     94  1.1  augustss 		return;
     95  1.1  augustss 
     96  1.1  augustss 	sc->sc_spic.sc_iot = aa->aa_iot;
     97  1.4  christos 	io = acpi_res_io(&res, 0);
     98  1.1  augustss 	if (io == NULL) {
     99  1.4  christos 		aprint_error_dev(self, "unable to find io resource\n");
    100  1.4  christos 		goto out;
    101  1.1  augustss 	}
    102  1.1  augustss 	if (bus_space_map(sc->sc_spic.sc_iot, io->ar_base, io->ar_length,
    103  1.1  augustss 	    0, &sc->sc_spic.sc_ioh) != 0) {
    104  1.4  christos 		aprint_error_dev(self, "unable to map data register\n");
    105  1.4  christos 		goto out;
    106  1.1  augustss 	}
    107  1.4  christos 	irq = acpi_res_irq(&res, 0);
    108  1.1  augustss 	if (irq == NULL) {
    109  1.4  christos 		aprint_error_dev(self, "unable to find irq resource\n");
    110  1.1  augustss 		/* XXX unmap */
    111  1.4  christos 		goto out;
    112  1.1  augustss 	}
    113  1.1  augustss #if 0
    114  1.8  jmcneill 	sc->sc_ih = acpi_intr_establish(self,
    115  1.8  jmcneill 	    (uint64_t)(uintptr_t)aa->aa_node->ad_handle,
    116  1.7  jmcneill 	    IPL_TTY, false, spic_intr, sc, device_xname(self));
    117  1.7  jmcneill 	if (sc->sc_ih == NULL) {
    118  1.7  jmcneill 		aprint_error_dev(self, "unable to establish interrupt\n");
    119  1.7  jmcneill 		goto out;
    120  1.7  jmcneill 	}
    121  1.1  augustss #endif
    122  1.1  augustss 
    123  1.4  christos 	if (!pmf_device_register(self, spic_suspend, spic_resume))
    124  1.4  christos 		aprint_error_dev(self, "couldn't establish power handler\n");
    125  1.4  christos 	else
    126  1.4  christos 		pmf_class_input_register(self);
    127  1.4  christos 
    128  1.1  augustss 	spic_attach(&sc->sc_spic);
    129  1.4  christos  out:
    130  1.4  christos 	acpi_resource_cleanup(&res);
    131  1.1  augustss }
    132