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