Home | History | Annotate | Line # | Download | only in acpi
spic_acpi.c revision 1.1
      1 #include <sys/cdefs.h>
      2 __KERNEL_RCSID(0, "$NetBSD: spic_acpi.c,v 1.1 2002/04/22 12:42:56 augustss Exp $");
      3 
      4 #include <sys/param.h>
      5 #include <sys/systm.h>
      6 #include <sys/device.h>
      7 #include <sys/proc.h>
      8 #include <sys/kernel.h>
      9 #include <sys/callout.h>
     10 
     11 #include <machine/bus.h>
     12 
     13 void	*isa_intr_establish(void *ic, int irq, int type,
     14 	    int level, int (*ih_fun)(void *), void *ih_arg);
     15 
     16 #include <dev/ic/spicvar.h>
     17 
     18 #include <dev/acpi/acpica.h>
     19 #include <dev/acpi/acpivar.h>
     20 
     21 struct spic_acpi_softc {
     22 	struct spic_softc sc_spic;	/* spic device */
     23 
     24 	struct acpi_devnode *sc_node;	/* our ACPI devnode */
     25 
     26 	struct acpi_resources sc_res;	/* our bus resources */
     27 
     28 	void *sc_ih;
     29 };
     30 
     31 int	spic_acpi_match(struct device *, struct cfdata *, void *);
     32 void	spic_acpi_attach(struct device *, struct device *, void *);
     33 
     34 struct cfattach spic_acpi_ca = {
     35 	sizeof(struct spic_acpi_softc), spic_acpi_match, spic_acpi_attach,
     36 	/* spic_acpi_detach, spic_acpi_activate */
     37 };
     38 
     39 int
     40 spic_acpi_match(struct device *parent, struct cfdata *match, void *aux)
     41 {
     42 	struct acpi_attach_args *aa = aux;
     43 
     44 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
     45 		return (0);
     46 
     47 	if (strcmp(aa->aa_node->ad_devinfo.HardwareId, "SNY6001") == 0)
     48 		return (1);
     49 
     50 	return (0);
     51 }
     52 
     53 void
     54 spic_acpi_attach(struct device *parent, struct device *self, void *aux)
     55 {
     56 	struct spic_acpi_softc *sc = (void *) self;
     57 	struct acpi_attach_args *aa = aux;
     58 	struct acpi_io *io;
     59 	struct acpi_irq *irq;
     60 	ACPI_STATUS rv;
     61 
     62 	printf(": Sony Programmable I/O Controller\n");
     63 
     64 	sc->sc_node = aa->aa_node;
     65 
     66 	/* Parse our resources. */
     67 	rv = acpi_resource_parse(&sc->sc_spic.sc_dev, sc->sc_node, &sc->sc_res,
     68 	    &acpi_resource_parse_ops_default);
     69 	if (rv != AE_OK) {
     70 		printf("%s: unable to parse resources: %d\n",
     71 		    sc->sc_spic.sc_dev.dv_xname, rv);
     72 		return;
     73 	}
     74 
     75 	sc->sc_spic.sc_iot = aa->aa_iot;
     76 	io = acpi_res_io(&sc->sc_res, 0);
     77 	if (io == NULL) {
     78 		printf("%s: unable to find io resource\n",
     79 		    sc->sc_spic.sc_dev.dv_xname);
     80 		return;
     81 	}
     82 	if (bus_space_map(sc->sc_spic.sc_iot, io->ar_base, io->ar_length,
     83 	    0, &sc->sc_spic.sc_ioh) != 0) {
     84 		printf("%s: unable to map data register\n",
     85 		    sc->sc_spic.sc_dev.dv_xname);
     86 		return;
     87 	}
     88 	irq = acpi_res_irq(&sc->sc_res, 0);
     89 	if (irq == NULL) {
     90 		printf("%s: unable to find irq resource\n",
     91 		    sc->sc_spic.sc_dev.dv_xname);
     92 		/* XXX unmap */
     93 		return;
     94 	}
     95 #if 0
     96 	sc->sc_ih = isa_intr_establish(NULL, irq->ar_irq,
     97 	    IST_EDGE, IPL_TTY, spic_intr, sc);
     98 #endif
     99 
    100 	spic_attach(&sc->sc_spic);
    101 }
    102 
    103