1 1.23 thorpej /* $NetBSD: lpt_acpi.c,v 1.23 2021/01/29 15:49:55 thorpej 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.23 thorpej __KERNEL_RCSID(0, "$NetBSD: lpt_acpi.c,v 1.23 2021/01/29 15:49:55 thorpej Exp $"); 30 1.1 jmcneill 31 1.1 jmcneill #include <sys/param.h> 32 1.1 jmcneill #include <sys/device.h> 33 1.1 jmcneill #include <sys/termios.h> 34 1.19 jruoho #include <sys/systm.h> 35 1.1 jmcneill 36 1.1 jmcneill #include <dev/acpi/acpivar.h> 37 1.21 jmcneill #include <dev/acpi/acpi_intr.h> 38 1.1 jmcneill 39 1.1 jmcneill #include <dev/ic/lptvar.h> 40 1.1 jmcneill 41 1.19 jruoho #include <dev/isa/isadmavar.h> 42 1.19 jruoho 43 1.16 cube static int lpt_acpi_match(device_t, cfdata_t, void *); 44 1.16 cube static void lpt_acpi_attach(device_t, device_t, void *); 45 1.1 jmcneill 46 1.1 jmcneill struct lpt_acpi_softc { 47 1.1 jmcneill struct lpt_softc sc_lpt; 48 1.1 jmcneill }; 49 1.1 jmcneill 50 1.16 cube CFATTACH_DECL_NEW(lpt_acpi, sizeof(struct lpt_acpi_softc), lpt_acpi_match, 51 1.1 jmcneill lpt_acpi_attach, NULL, NULL); 52 1.1 jmcneill 53 1.1 jmcneill /* 54 1.1 jmcneill * Supported device IDs 55 1.1 jmcneill */ 56 1.1 jmcneill 57 1.23 thorpej static const struct device_compatible_entry compat_data[] = { 58 1.23 thorpej { .compat = "PNP04??" }, /* Standard LPT printer port */ 59 1.23 thorpej DEVICE_COMPAT_EOL 60 1.1 jmcneill }; 61 1.1 jmcneill 62 1.1 jmcneill /* 63 1.1 jmcneill * lpt_acpi_match: autoconf(9) match routine 64 1.1 jmcneill */ 65 1.10 kochi static int 66 1.16 cube lpt_acpi_match(device_t parent, cfdata_t match, void *aux) 67 1.1 jmcneill { 68 1.1 jmcneill struct acpi_attach_args *aa = aux; 69 1.1 jmcneill 70 1.23 thorpej return acpi_compatible_match(aa, compat_data); 71 1.1 jmcneill } 72 1.1 jmcneill 73 1.1 jmcneill /* 74 1.1 jmcneill * lpt_acpi_attach: autoconf(9) attach routine 75 1.1 jmcneill */ 76 1.10 kochi static void 77 1.16 cube lpt_acpi_attach(device_t parent, device_t self, void *aux) 78 1.1 jmcneill { 79 1.16 cube struct lpt_acpi_softc *asc = device_private(self); 80 1.1 jmcneill struct lpt_softc *sc = &asc->sc_lpt; 81 1.1 jmcneill struct acpi_attach_args *aa = aux; 82 1.1 jmcneill struct acpi_resources res; 83 1.1 jmcneill struct acpi_io *io; 84 1.1 jmcneill ACPI_STATUS rv; 85 1.1 jmcneill 86 1.16 cube sc->sc_dev = self; 87 1.16 cube 88 1.17 jmcneill if (!pmf_device_register(self, NULL, NULL)) 89 1.17 jmcneill aprint_error_dev(self, "couldn't establish power handler\n"); 90 1.17 jmcneill 91 1.1 jmcneill /* parse resources */ 92 1.16 cube rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS", 93 1.8 kochi &res, &acpi_resource_parse_ops_default); 94 1.6 mycroft if (ACPI_FAILURE(rv)) 95 1.1 jmcneill return; 96 1.1 jmcneill 97 1.1 jmcneill /* find our i/o registers */ 98 1.1 jmcneill io = acpi_res_io(&res, 0); 99 1.1 jmcneill if (io == NULL) { 100 1.16 cube aprint_error_dev(self, 101 1.16 cube "unable to find i/o register resource\n"); 102 1.9 kochi goto out; 103 1.1 jmcneill } 104 1.1 jmcneill 105 1.1 jmcneill sc->sc_iot = aa->aa_iot; 106 1.1 jmcneill if (bus_space_map(sc->sc_iot, io->ar_base, io->ar_length, 107 1.1 jmcneill 0, &sc->sc_ioh)) { 108 1.16 cube aprint_error_dev(self, "can't map i/o space\n"); 109 1.9 kochi goto out; 110 1.1 jmcneill } 111 1.1 jmcneill 112 1.1 jmcneill lpt_attach_subr(sc); 113 1.1 jmcneill 114 1.22 jmcneill sc->sc_ih = acpi_intr_establish(self, 115 1.22 jmcneill (uint64_t)(uintptr_t)aa->aa_node->ad_handle, 116 1.21 jmcneill IPL_TTY, false, lptintr, sc, device_xname(self)); 117 1.21 jmcneill if (sc->sc_ih == NULL) { 118 1.21 jmcneill aprint_error_dev(self, "unable to establish interrupt\n"); 119 1.21 jmcneill goto out; 120 1.21 jmcneill } 121 1.9 kochi 122 1.9 kochi out: 123 1.9 kochi acpi_resource_cleanup(&res); 124 1.1 jmcneill } 125