Home | History | Annotate | Line # | Download | only in acpi
com_acpi.c revision 1.27.4.2
      1  1.27.4.2      yamt /* $NetBSD: com_acpi.c,v 1.27.4.2 2009/07/18 14:52:59 yamt 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.27.4.2      yamt __KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v 1.27.4.2 2009/07/18 14:52:59 yamt 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.24        ad #include <sys/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/comvar.h>
     50       1.1  jmcneill 
     51      1.27      cube static int	com_acpi_match(device_t, cfdata_t , void *);
     52      1.27      cube static void	com_acpi_attach(device_t, device_t, void *);
     53       1.1  jmcneill 
     54       1.1  jmcneill struct com_acpi_softc {
     55       1.1  jmcneill 	struct com_softc sc_com;
     56       1.1  jmcneill 	void *sc_ih;
     57       1.1  jmcneill };
     58       1.1  jmcneill 
     59      1.27      cube CFATTACH_DECL_NEW(com_acpi, sizeof(struct com_acpi_softc), com_acpi_match,
     60      1.26    dyoung     com_acpi_attach, NULL, com_activate);
     61       1.1  jmcneill 
     62       1.1  jmcneill /*
     63       1.1  jmcneill  * Supported device IDs
     64       1.1  jmcneill  */
     65       1.1  jmcneill 
     66       1.2      matt static const char * const com_acpi_ids[] = {
     67       1.1  jmcneill 	"PNP0500",	/* Standard PC COM port */
     68       1.1  jmcneill 	"PNP0501",	/* 16550A-compatible COM port */
     69       1.1  jmcneill 	"PNP0510",	/* Generic IRDA-compatible device */
     70       1.1  jmcneill 	"PNP0511",	/* Generic IRDA-compatible device */
     71       1.6  jmcneill 	"IBM0071",	/* IBM ThinkPad IRDA device */
     72      1.12   mycroft 	"SMCF010",	/* SMC SuperIO IRDA device */
     73      1.17    rpaulo 	"NSC6001",	/* NSC IRDA device */
     74      1.23  christos 	"FUJ02E6",	/* Fujitsu Serial Pen Tablet */
     75       1.1  jmcneill 	NULL
     76       1.1  jmcneill };
     77       1.1  jmcneill 
     78       1.1  jmcneill /*
     79       1.1  jmcneill  * com_acpi_match: autoconf(9) match routine
     80       1.1  jmcneill  */
     81      1.15     kochi static int
     82      1.27      cube com_acpi_match(device_t parent, cfdata_t match, void *aux)
     83       1.1  jmcneill {
     84       1.1  jmcneill 	struct acpi_attach_args *aa = aux;
     85       1.1  jmcneill 
     86       1.1  jmcneill 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
     87       1.1  jmcneill 		return 0;
     88       1.1  jmcneill 
     89       1.9     kochi 	return acpi_match_hid(aa->aa_node->ad_devinfo,com_acpi_ids);
     90       1.1  jmcneill }
     91       1.1  jmcneill 
     92       1.1  jmcneill /*
     93       1.1  jmcneill  * com_acpi_attach: autoconf(9) attach routine
     94       1.1  jmcneill  */
     95      1.15     kochi static void
     96      1.27      cube com_acpi_attach(device_t parent, device_t self, void *aux)
     97       1.1  jmcneill {
     98      1.27      cube 	struct com_acpi_softc *asc = device_private(self);
     99       1.1  jmcneill 	struct com_softc *sc = &asc->sc_com;
    100       1.1  jmcneill 	struct acpi_attach_args *aa = aux;
    101       1.1  jmcneill 	struct acpi_resources res;
    102       1.1  jmcneill 	struct acpi_io *io;
    103  1.27.4.2      yamt 	struct acpi_mem *mem;
    104       1.1  jmcneill 	struct acpi_irq *irq;
    105  1.27.4.2      yamt 	bus_space_tag_t iot;
    106      1.19   gdamore 	bus_space_handle_t ioh;
    107  1.27.4.2      yamt 	bus_addr_t base;
    108  1.27.4.2      yamt 	bus_size_t size;
    109       1.1  jmcneill 	ACPI_STATUS rv;
    110       1.1  jmcneill 
    111      1.27      cube 	sc->sc_dev = self;
    112      1.27      cube 
    113       1.1  jmcneill 	/* parse resources */
    114      1.27      cube 	rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
    115      1.13     kochi 	    &res, &acpi_resource_parse_ops_default);
    116      1.11   mycroft 	if (ACPI_FAILURE(rv))
    117       1.1  jmcneill 		return;
    118       1.1  jmcneill 
    119       1.1  jmcneill 	/* find our i/o registers */
    120       1.1  jmcneill 	io = acpi_res_io(&res, 0);
    121  1.27.4.2      yamt 	if (io != NULL) {
    122  1.27.4.2      yamt 		iot = aa->aa_iot;
    123  1.27.4.2      yamt 		base = io->ar_base;
    124  1.27.4.2      yamt 		size = io->ar_length;
    125  1.27.4.2      yamt 	} else {
    126  1.27.4.2      yamt 		mem = acpi_res_mem(&res, 0);
    127  1.27.4.2      yamt 		if (mem != NULL) {
    128  1.27.4.2      yamt 			iot = aa->aa_memt;
    129  1.27.4.2      yamt 			base = mem->ar_base;
    130  1.27.4.2      yamt 			size = mem->ar_length;
    131  1.27.4.2      yamt 		} else {
    132  1.27.4.2      yamt 			aprint_error_dev(self,
    133  1.27.4.2      yamt 			    "unable to find i/o register and memory resource\n");
    134  1.27.4.2      yamt 			goto out;
    135  1.27.4.2      yamt 		}
    136       1.1  jmcneill 	}
    137       1.1  jmcneill 
    138       1.1  jmcneill 	/* find our IRQ */
    139       1.1  jmcneill 	irq = acpi_res_irq(&res, 0);
    140       1.1  jmcneill 	if (irq == NULL) {
    141      1.27      cube 		aprint_error_dev(self, "unable to find irq resource\n");
    142      1.14     kochi 		goto out;
    143       1.1  jmcneill 	}
    144       1.1  jmcneill 
    145  1.27.4.2      yamt 	if (!com_is_console(iot, base, &ioh))
    146  1.27.4.2      yamt 		if (bus_space_map(iot, base, size, 0, &ioh)) {
    147      1.27      cube 			aprint_error_dev(self, "can't map i/o space\n");
    148      1.14     kochi 			goto out;
    149       1.5  jmcneill 		}
    150  1.27.4.2      yamt 	COM_INIT_REGS(sc->sc_regs, iot, ioh, base);
    151       1.1  jmcneill 
    152      1.27      cube 	aprint_normal("%s", device_xname(self));
    153       1.1  jmcneill 
    154      1.19   gdamore 	if (com_probe_subr(&sc->sc_regs) == 0) {
    155      1.18     kochi 		aprint_error(": com probe failed\n");
    156      1.14     kochi 		goto out;
    157       1.1  jmcneill 	}
    158       1.1  jmcneill 
    159       1.1  jmcneill 	sc->sc_frequency = 115200 * 16;
    160       1.1  jmcneill 
    161       1.1  jmcneill 	com_attach_subr(sc);
    162       1.1  jmcneill 
    163       1.7  jdolecek 	asc->sc_ih = isa_intr_establish(aa->aa_ic, irq->ar_irq,
    164       1.7  jdolecek 	    (irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL,
    165       1.7  jdolecek 	    IPL_SERIAL, comintr, sc);
    166      1.25   xtraeme 
    167      1.25   xtraeme 	if (!pmf_device_register(self, NULL, com_resume))
    168      1.25   xtraeme 		aprint_error_dev(self, "couldn't establish a power handler\n");
    169      1.25   xtraeme 
    170      1.14     kochi  out:
    171      1.14     kochi 	acpi_resource_cleanup(&res);
    172       1.1  jmcneill }
    173