Home | History | Annotate | Line # | Download | only in acpi
spic_acpi.c revision 1.6
      1  1.6    jruoho /*	$NetBSD: spic_acpi.c,v 1.6 2010/03/05 14:00:17 jruoho 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.6    jruoho __KERNEL_RCSID(0, "$NetBSD: spic_acpi.c,v 1.6 2010/03/05 14:00:17 jruoho 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.1  augustss 
     42  1.6    jruoho #include <dev/ic/spicvar.h>
     43  1.6    jruoho 
     44  1.5    jruoho #define _COMPONENT		ACPI_RESOURCE_COMPONENT
     45  1.5    jruoho ACPI_MODULE_NAME		("spic_acpi")
     46  1.5    jruoho 
     47  1.1  augustss struct spic_acpi_softc {
     48  1.1  augustss 	struct spic_softc sc_spic;	/* spic device */
     49  1.1  augustss 
     50  1.1  augustss 	struct acpi_devnode *sc_node;	/* our ACPI devnode */
     51  1.1  augustss 
     52  1.4  christos 	void *sc_ih;
     53  1.4  christos };
     54  1.1  augustss 
     55  1.4  christos static const char * const spic_acpi_ids[] = {
     56  1.4  christos 	"SNY6001",
     57  1.4  christos 	NULL
     58  1.1  augustss };
     59  1.1  augustss 
     60  1.4  christos static int	spic_acpi_match(device_t, cfdata_t, void *);
     61  1.4  christos static void	spic_acpi_attach(device_t, device_t, void *);
     62  1.4  christos 
     63  1.4  christos CFATTACH_DECL_NEW(spic_acpi, sizeof(struct spic_acpi_softc),
     64  1.4  christos     spic_acpi_match, spic_acpi_attach, NULL, NULL);
     65  1.1  augustss 
     66  1.1  augustss 
     67  1.4  christos static int
     68  1.4  christos spic_acpi_match(device_t parent, cfdata_t match, void *aux)
     69  1.1  augustss {
     70  1.1  augustss 	struct acpi_attach_args *aa = aux;
     71  1.1  augustss 
     72  1.1  augustss 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
     73  1.1  augustss 		return (0);
     74  1.1  augustss 
     75  1.4  christos 	return (acpi_match_hid(aa->aa_node->ad_devinfo, spic_acpi_ids));
     76  1.1  augustss }
     77  1.1  augustss 
     78  1.4  christos static void
     79  1.4  christos spic_acpi_attach(device_t parent, device_t self, void *aux)
     80  1.1  augustss {
     81  1.4  christos 	struct spic_acpi_softc *sc = device_private(self);
     82  1.1  augustss 	struct acpi_attach_args *aa = aux;
     83  1.1  augustss 	struct acpi_io *io;
     84  1.1  augustss 	struct acpi_irq *irq;
     85  1.4  christos 	struct acpi_resources res;
     86  1.4  christos 
     87  1.1  augustss 	ACPI_STATUS rv;
     88  1.1  augustss 
     89  1.4  christos 	sc->sc_spic.sc_dev = self;
     90  1.1  augustss 	sc->sc_node = aa->aa_node;
     91  1.1  augustss 
     92  1.1  augustss 	/* Parse our resources. */
     93  1.4  christos 	rv = acpi_resource_parse(self, sc->sc_node->ad_handle,
     94  1.4  christos 	    "_CRS", &res, &acpi_resource_parse_ops_default);
     95  1.4  christos 	if (ACPI_FAILURE(rv))
     96  1.1  augustss 		return;
     97  1.1  augustss 
     98  1.1  augustss 	sc->sc_spic.sc_iot = aa->aa_iot;
     99  1.4  christos 	io = acpi_res_io(&res, 0);
    100  1.1  augustss 	if (io == NULL) {
    101  1.4  christos 		aprint_error_dev(self, "unable to find io resource\n");
    102  1.4  christos 		goto out;
    103  1.1  augustss 	}
    104  1.1  augustss 	if (bus_space_map(sc->sc_spic.sc_iot, io->ar_base, io->ar_length,
    105  1.1  augustss 	    0, &sc->sc_spic.sc_ioh) != 0) {
    106  1.4  christos 		aprint_error_dev(self, "unable to map data register\n");
    107  1.4  christos 		goto out;
    108  1.1  augustss 	}
    109  1.4  christos 	irq = acpi_res_irq(&res, 0);
    110  1.1  augustss 	if (irq == NULL) {
    111  1.4  christos 		aprint_error_dev(self, "unable to find irq resource\n");
    112  1.1  augustss 		/* XXX unmap */
    113  1.4  christos 		goto out;
    114  1.1  augustss 	}
    115  1.1  augustss #if 0
    116  1.1  augustss 	sc->sc_ih = isa_intr_establish(NULL, irq->ar_irq,
    117  1.1  augustss 	    IST_EDGE, IPL_TTY, spic_intr, sc);
    118  1.1  augustss #endif
    119  1.1  augustss 
    120  1.4  christos 	if (!pmf_device_register(self, spic_suspend, spic_resume))
    121  1.4  christos 		aprint_error_dev(self, "couldn't establish power handler\n");
    122  1.4  christos 	else
    123  1.4  christos 		pmf_class_input_register(self);
    124  1.4  christos 
    125  1.1  augustss 	spic_attach(&sc->sc_spic);
    126  1.4  christos  out:
    127  1.4  christos 	acpi_resource_cleanup(&res);
    128  1.1  augustss }
    129