Home | History | Annotate | Line # | Download | only in acpi
spic_acpi.c revision 1.2
      1  1.2  augustss /*	$NetBSD: spic_acpi.c,v 1.2 2002/06/13 16:48:34 augustss 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  * 3. All advertising materials mentioning features or use of this software
     19  1.2  augustss  *    must display the following acknowledgement:
     20  1.2  augustss  *        This product includes software developed by the NetBSD
     21  1.2  augustss  *        Foundation, Inc. and its contributors.
     22  1.2  augustss  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2  augustss  *    contributors may be used to endorse or promote products derived
     24  1.2  augustss  *    from this software without specific prior written permission.
     25  1.2  augustss  *
     26  1.2  augustss  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2  augustss  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2  augustss  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2  augustss  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2  augustss  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2  augustss  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2  augustss  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2  augustss  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2  augustss  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2  augustss  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2  augustss  * POSSIBILITY OF SUCH DAMAGE.
     37  1.2  augustss  */
     38  1.2  augustss 
     39  1.1  augustss #include <sys/cdefs.h>
     40  1.2  augustss __KERNEL_RCSID(0, "$NetBSD: spic_acpi.c,v 1.2 2002/06/13 16:48:34 augustss Exp $");
     41  1.1  augustss 
     42  1.1  augustss #include <sys/param.h>
     43  1.1  augustss #include <sys/systm.h>
     44  1.1  augustss #include <sys/device.h>
     45  1.1  augustss #include <sys/proc.h>
     46  1.1  augustss #include <sys/kernel.h>
     47  1.1  augustss #include <sys/callout.h>
     48  1.1  augustss 
     49  1.1  augustss #include <machine/bus.h>
     50  1.1  augustss 
     51  1.1  augustss void	*isa_intr_establish(void *ic, int irq, int type,
     52  1.1  augustss 	    int level, int (*ih_fun)(void *), void *ih_arg);
     53  1.1  augustss 
     54  1.1  augustss #include <dev/ic/spicvar.h>
     55  1.1  augustss 
     56  1.1  augustss #include <dev/acpi/acpica.h>
     57  1.1  augustss #include <dev/acpi/acpivar.h>
     58  1.1  augustss 
     59  1.1  augustss struct spic_acpi_softc {
     60  1.1  augustss 	struct spic_softc sc_spic;	/* spic device */
     61  1.1  augustss 
     62  1.1  augustss 	struct acpi_devnode *sc_node;	/* our ACPI devnode */
     63  1.1  augustss 
     64  1.1  augustss 	struct acpi_resources sc_res;	/* our bus resources */
     65  1.1  augustss 
     66  1.1  augustss 	void *sc_ih;
     67  1.1  augustss };
     68  1.1  augustss 
     69  1.1  augustss int	spic_acpi_match(struct device *, struct cfdata *, void *);
     70  1.1  augustss void	spic_acpi_attach(struct device *, struct device *, void *);
     71  1.1  augustss 
     72  1.1  augustss struct cfattach spic_acpi_ca = {
     73  1.1  augustss 	sizeof(struct spic_acpi_softc), spic_acpi_match, spic_acpi_attach,
     74  1.1  augustss 	/* spic_acpi_detach, spic_acpi_activate */
     75  1.1  augustss };
     76  1.1  augustss 
     77  1.1  augustss int
     78  1.1  augustss spic_acpi_match(struct device *parent, struct cfdata *match, void *aux)
     79  1.1  augustss {
     80  1.1  augustss 	struct acpi_attach_args *aa = aux;
     81  1.1  augustss 
     82  1.1  augustss 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
     83  1.1  augustss 		return (0);
     84  1.1  augustss 
     85  1.1  augustss 	if (strcmp(aa->aa_node->ad_devinfo.HardwareId, "SNY6001") == 0)
     86  1.1  augustss 		return (1);
     87  1.1  augustss 
     88  1.1  augustss 	return (0);
     89  1.1  augustss }
     90  1.1  augustss 
     91  1.1  augustss void
     92  1.1  augustss spic_acpi_attach(struct device *parent, struct device *self, void *aux)
     93  1.1  augustss {
     94  1.1  augustss 	struct spic_acpi_softc *sc = (void *) self;
     95  1.1  augustss 	struct acpi_attach_args *aa = aux;
     96  1.1  augustss 	struct acpi_io *io;
     97  1.1  augustss 	struct acpi_irq *irq;
     98  1.1  augustss 	ACPI_STATUS rv;
     99  1.1  augustss 
    100  1.1  augustss 	printf(": Sony Programmable I/O Controller\n");
    101  1.1  augustss 
    102  1.1  augustss 	sc->sc_node = aa->aa_node;
    103  1.1  augustss 
    104  1.1  augustss 	/* Parse our resources. */
    105  1.1  augustss 	rv = acpi_resource_parse(&sc->sc_spic.sc_dev, sc->sc_node, &sc->sc_res,
    106  1.1  augustss 	    &acpi_resource_parse_ops_default);
    107  1.1  augustss 	if (rv != AE_OK) {
    108  1.1  augustss 		printf("%s: unable to parse resources: %d\n",
    109  1.1  augustss 		    sc->sc_spic.sc_dev.dv_xname, rv);
    110  1.1  augustss 		return;
    111  1.1  augustss 	}
    112  1.1  augustss 
    113  1.1  augustss 	sc->sc_spic.sc_iot = aa->aa_iot;
    114  1.1  augustss 	io = acpi_res_io(&sc->sc_res, 0);
    115  1.1  augustss 	if (io == NULL) {
    116  1.1  augustss 		printf("%s: unable to find io resource\n",
    117  1.1  augustss 		    sc->sc_spic.sc_dev.dv_xname);
    118  1.1  augustss 		return;
    119  1.1  augustss 	}
    120  1.1  augustss 	if (bus_space_map(sc->sc_spic.sc_iot, io->ar_base, io->ar_length,
    121  1.1  augustss 	    0, &sc->sc_spic.sc_ioh) != 0) {
    122  1.1  augustss 		printf("%s: unable to map data register\n",
    123  1.1  augustss 		    sc->sc_spic.sc_dev.dv_xname);
    124  1.1  augustss 		return;
    125  1.1  augustss 	}
    126  1.1  augustss 	irq = acpi_res_irq(&sc->sc_res, 0);
    127  1.1  augustss 	if (irq == NULL) {
    128  1.1  augustss 		printf("%s: unable to find irq resource\n",
    129  1.1  augustss 		    sc->sc_spic.sc_dev.dv_xname);
    130  1.1  augustss 		/* XXX unmap */
    131  1.1  augustss 		return;
    132  1.1  augustss 	}
    133  1.1  augustss #if 0
    134  1.1  augustss 	sc->sc_ih = isa_intr_establish(NULL, irq->ar_irq,
    135  1.1  augustss 	    IST_EDGE, IPL_TTY, spic_intr, sc);
    136  1.1  augustss #endif
    137  1.1  augustss 
    138  1.1  augustss 	spic_attach(&sc->sc_spic);
    139  1.1  augustss }
    140  1.1  augustss 
    141