Home | History | Annotate | Line # | Download | only in acpi
lpt_acpi.c revision 1.2.2.1
      1  1.2.2.1     skrll /* $NetBSD: lpt_acpi.c,v 1.2.2.1 2004/08/03 10:45:03 skrll Exp $ */
      2      1.1  jmcneill 
      3      1.1  jmcneill /*
      4      1.1  jmcneill  * Copyright (c) 2002 Jared D. McNeill <jmcneill (at) invisible.ca>
      5      1.1  jmcneill  * All rights reserved.
      6      1.1  jmcneill  *
      7      1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      8      1.1  jmcneill  * modification, are permitted provided that the following conditions
      9      1.1  jmcneill  * are met:
     10      1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     11      1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     12      1.1  jmcneill  * 2. The name of the author may not be used to endorse or promote products
     13      1.1  jmcneill  *    derived from this software without specific prior written permission.
     14      1.1  jmcneill  *
     15      1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16      1.1  jmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17      1.1  jmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18      1.1  jmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19      1.1  jmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     20      1.1  jmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     21      1.1  jmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     22      1.1  jmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     23      1.1  jmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24      1.1  jmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25      1.1  jmcneill  * SUCH DAMAGE.
     26      1.1  jmcneill  */
     27      1.1  jmcneill 
     28      1.1  jmcneill #include <sys/cdefs.h>
     29  1.2.2.1     skrll __KERNEL_RCSID(0, "$NetBSD: lpt_acpi.c,v 1.2.2.1 2004/08/03 10:45:03 skrll Exp $");
     30      1.1  jmcneill 
     31      1.1  jmcneill #include <sys/param.h>
     32      1.1  jmcneill #include <sys/systm.h>
     33      1.1  jmcneill #include <sys/errno.h>
     34      1.1  jmcneill #include <sys/ioctl.h>
     35      1.1  jmcneill #include <sys/syslog.h>
     36      1.1  jmcneill #include <sys/device.h>
     37      1.1  jmcneill #include <sys/proc.h>
     38      1.1  jmcneill #include <sys/termios.h>
     39      1.1  jmcneill 
     40      1.1  jmcneill #include <machine/bus.h>
     41      1.1  jmcneill 
     42      1.1  jmcneill #include <dev/isa/isavar.h>
     43      1.1  jmcneill #include <dev/isa/isadmavar.h>
     44      1.1  jmcneill 
     45      1.1  jmcneill #include <dev/acpi/acpica.h>
     46      1.1  jmcneill #include <dev/acpi/acpireg.h>
     47      1.1  jmcneill #include <dev/acpi/acpivar.h>
     48      1.1  jmcneill 
     49      1.1  jmcneill #include <dev/ic/lptvar.h>
     50      1.1  jmcneill 
     51  1.2.2.1     skrll static int	lpt_acpi_match(struct device *, struct cfdata *, void *);
     52  1.2.2.1     skrll static void	lpt_acpi_attach(struct device *, struct device *, void *);
     53      1.1  jmcneill 
     54      1.1  jmcneill struct lpt_acpi_softc {
     55      1.1  jmcneill 	struct lpt_softc sc_lpt;
     56      1.1  jmcneill };
     57      1.1  jmcneill 
     58      1.1  jmcneill CFATTACH_DECL(lpt_acpi, sizeof(struct lpt_acpi_softc), lpt_acpi_match,
     59      1.1  jmcneill     lpt_acpi_attach, NULL, NULL);
     60      1.1  jmcneill 
     61      1.1  jmcneill /*
     62      1.1  jmcneill  * Supported device IDs
     63      1.1  jmcneill  */
     64      1.1  jmcneill 
     65      1.1  jmcneill static const char * const lpt_acpi_ids[] = {
     66  1.2.2.1     skrll 	"PNP04??",	/* Standard LPT printer port */
     67      1.1  jmcneill 	NULL
     68      1.1  jmcneill };
     69      1.1  jmcneill 
     70      1.1  jmcneill /*
     71      1.1  jmcneill  * lpt_acpi_match: autoconf(9) match routine
     72      1.1  jmcneill  */
     73  1.2.2.1     skrll static int
     74      1.1  jmcneill lpt_acpi_match(struct device *parent, struct cfdata *match, void *aux)
     75      1.1  jmcneill {
     76      1.1  jmcneill 	struct acpi_attach_args *aa = aux;
     77      1.1  jmcneill 
     78      1.1  jmcneill 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
     79      1.1  jmcneill 		return 0;
     80      1.1  jmcneill 
     81  1.2.2.1     skrll 	return acpi_match_hid(aa->aa_node->ad_devinfo, lpt_acpi_ids);
     82      1.1  jmcneill }
     83      1.1  jmcneill 
     84      1.1  jmcneill /*
     85      1.1  jmcneill  * lpt_acpi_attach: autoconf(9) attach routine
     86      1.1  jmcneill  */
     87  1.2.2.1     skrll static void
     88      1.1  jmcneill lpt_acpi_attach(struct device *parent, struct device *self, void *aux)
     89      1.1  jmcneill {
     90      1.1  jmcneill 	struct lpt_acpi_softc *asc = (struct lpt_acpi_softc *)self;
     91      1.1  jmcneill 	struct lpt_softc *sc = &asc->sc_lpt;
     92      1.1  jmcneill 	struct acpi_attach_args *aa = aux;
     93      1.1  jmcneill 	struct acpi_resources res;
     94      1.1  jmcneill 	struct acpi_io *io;
     95      1.1  jmcneill 	struct acpi_irq *irq;
     96      1.1  jmcneill 	ACPI_STATUS rv;
     97      1.1  jmcneill 
     98      1.1  jmcneill 	printf("\n");
     99      1.1  jmcneill 
    100      1.1  jmcneill 	/* parse resources */
    101  1.2.2.1     skrll 	rv = acpi_resource_parse(&sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
    102  1.2.2.1     skrll 	    &res, &acpi_resource_parse_ops_default);
    103  1.2.2.1     skrll 	if (ACPI_FAILURE(rv))
    104      1.1  jmcneill 		return;
    105      1.1  jmcneill 
    106      1.1  jmcneill 	/* find our i/o registers */
    107      1.1  jmcneill 	io = acpi_res_io(&res, 0);
    108      1.1  jmcneill 	if (io == NULL) {
    109      1.1  jmcneill 		printf("%s: unable to find i/o register resource\n",
    110      1.1  jmcneill 		    sc->sc_dev.dv_xname);
    111  1.2.2.1     skrll 		goto out;
    112      1.1  jmcneill 	}
    113      1.1  jmcneill 
    114      1.1  jmcneill 	/* find our IRQ */
    115      1.1  jmcneill 	irq = acpi_res_irq(&res, 0);
    116      1.1  jmcneill 	if (irq == NULL) {
    117      1.1  jmcneill 		printf("%s: unable to find irq resource\n",
    118      1.1  jmcneill 		    sc->sc_dev.dv_xname);
    119  1.2.2.1     skrll 		goto out;
    120      1.1  jmcneill 	}
    121      1.1  jmcneill 
    122      1.1  jmcneill 	sc->sc_iot = aa->aa_iot;
    123      1.1  jmcneill 	if (bus_space_map(sc->sc_iot, io->ar_base, io->ar_length,
    124      1.1  jmcneill 		    0, &sc->sc_ioh)) {
    125      1.1  jmcneill 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    126  1.2.2.1     skrll 		goto out;
    127      1.1  jmcneill 	}
    128      1.1  jmcneill 
    129      1.1  jmcneill 	lpt_attach_subr(sc);
    130      1.1  jmcneill 
    131      1.2  jdolecek 	sc->sc_ih = isa_intr_establish(aa->aa_ic, irq->ar_irq,
    132      1.2  jdolecek 	    (irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL,
    133      1.2  jdolecek 	    IPL_TTY, lptintr, sc);
    134  1.2.2.1     skrll 
    135  1.2.2.1     skrll  out:
    136  1.2.2.1     skrll 	acpi_resource_cleanup(&res);
    137      1.1  jmcneill }
    138