Home | History | Annotate | Line # | Download | only in acpi
atppc_acpi.c revision 1.2
      1 /* $NetBSD: atppc_acpi.c,v 1.2 2004/04/10 11:48:11 kochi Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2004 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jaromir Dolecek.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: atppc_acpi.c,v 1.2 2004/04/10 11:48:11 kochi Exp $");
     41 
     42 #include "opt_atppc.h"
     43 
     44 #include <sys/param.h>
     45 #include <sys/systm.h>
     46 #include <sys/errno.h>
     47 #include <sys/ioctl.h>
     48 #include <sys/syslog.h>
     49 #include <sys/device.h>
     50 #include <sys/proc.h>
     51 #include <sys/termios.h>
     52 
     53 #include <machine/bus.h>
     54 
     55 #include <dev/isa/isavar.h>
     56 #include <dev/isa/isadmavar.h>
     57 
     58 #include <dev/acpi/acpica.h>
     59 #include <dev/acpi/acpireg.h>
     60 #include <dev/acpi/acpivar.h>
     61 
     62 #include <dev/ic/atppcvar.h>
     63 #include <dev/isa/atppc_isadma.h>
     64 
     65 static int	atppc_acpi_match(struct device *, struct cfdata *, void *);
     66 static void	atppc_acpi_attach(struct device *, struct device *, void *);
     67 
     68 struct atppc_acpi_softc {
     69 	struct atppc_softc sc_atppc;
     70 
     71 	isa_chipset_tag_t sc_ic;
     72 	int sc_drq;
     73 };
     74 
     75 CFATTACH_DECL(atppc_acpi, sizeof(struct atppc_acpi_softc), atppc_acpi_match,
     76     atppc_acpi_attach, NULL, NULL);
     77 
     78 /*
     79  * Supported device IDs
     80  */
     81 
     82 static const char * const atppc_acpi_ids[] = {
     83 	"PNP04??",	/* Standard AT printer port */
     84 	NULL
     85 };
     86 
     87 static int atppc_acpi_dma_start(struct atppc_softc *, void *, u_int,
     88 	u_int8_t);
     89 static int atppc_acpi_dma_finish(struct atppc_softc *);
     90 static int atppc_acpi_dma_abort(struct atppc_softc *);
     91 static int atppc_acpi_dma_malloc(struct device *, caddr_t *, bus_addr_t *,
     92 	bus_size_t);
     93 static void atppc_acpi_dma_free(struct device *, caddr_t *, bus_addr_t *,
     94 	bus_size_t);
     95 /*
     96  * atppc_acpi_match: autoconf(9) match routine
     97  */
     98 static int
     99 atppc_acpi_match(struct device *parent, struct cfdata *match, void *aux)
    100 {
    101 	struct acpi_attach_args *aa = aux;
    102 
    103 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
    104 		return 0;
    105 
    106 	return acpi_match_hid(aa->aa_node->ad_devinfo, atppc_acpi_ids);
    107 }
    108 
    109 static void
    110 atppc_acpi_attach(struct device *parent, struct device *self, void *aux)
    111 {
    112 	struct atppc_softc *sc = (struct atppc_softc *) self;
    113 	struct atppc_acpi_softc *asc = (struct atppc_acpi_softc *)self;
    114 	struct acpi_attach_args *aa = aux;
    115 	struct acpi_resources res;
    116 	struct acpi_io *io;
    117 	struct acpi_irq *irq;
    118 	struct acpi_drq *drq;
    119 	ACPI_STATUS rv;
    120 	int nirq;
    121 
    122 	sc->sc_dev_ok = ATPPC_NOATTACH;
    123 
    124 	printf(": AT Parallel Port\n");
    125 
    126 	/* parse resources */
    127 	rv = acpi_resource_parse(&sc->sc_dev, aa->aa_node, &res,
    128 	    &acpi_resource_parse_ops_default);
    129 	if (ACPI_FAILURE(rv))
    130 		return;
    131 
    132 	/* find our i/o registers */
    133 	io = acpi_res_io(&res, 0);
    134 	if (io == NULL) {
    135 		printf("%s: unable to find i/o register resource\n",
    136 		    sc->sc_dev.dv_xname);
    137 		return;
    138 	}
    139 
    140 	/* find our IRQ */
    141 	irq = acpi_res_irq(&res, 0);
    142 	if (irq == NULL) {
    143 		printf("%s: unable to find irq resource\n",
    144 		    sc->sc_dev.dv_xname);
    145 		return;
    146 	}
    147 	nirq = irq->ar_irq;
    148 
    149 	/* find our DRQ */
    150 	drq = acpi_res_drq(&res, 0);
    151 	if (drq == NULL) {
    152 		printf("%s: unable to find drq resource\n",
    153 		    sc->sc_dev.dv_xname);
    154 		return;
    155 	}
    156 	asc->sc_drq = drq->ar_drq;
    157 
    158 	/* Attach */
    159 	sc->sc_iot = aa->aa_iot;
    160 	sc->sc_has = 0;
    161 	asc->sc_ic = aa->aa_ic;
    162 
    163 	sc->sc_dev_ok = ATPPC_ATTACHED;
    164 
    165 	if (bus_space_map(sc->sc_iot, io->ar_base, io->ar_length, 0,
    166 		&sc->sc_ioh) != 0) {
    167 		printf("%s: attempt to map bus space failed, device not "
    168 			"properly attached.\n", self->dv_xname);
    169 		return;
    170 	}
    171 
    172 	sc->sc_ieh = isa_intr_establish(aa->aa_ic, nirq,
    173 	    (irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL,
    174 	    IPL_TTY, atppcintr, sc);
    175 
    176 	/* setup DMA hooks */
    177 	if (atppc_isadma_setup(sc, asc->sc_ic, asc->sc_drq) == 0) {
    178 		sc->sc_has |= ATPPC_HAS_DMA;
    179 		sc->sc_dma_start = atppc_acpi_dma_start;
    180 		sc->sc_dma_finish = atppc_acpi_dma_finish;
    181 		sc->sc_dma_abort = atppc_acpi_dma_abort;
    182 		sc->sc_dma_malloc = atppc_acpi_dma_malloc;
    183 		sc->sc_dma_free = atppc_acpi_dma_free;
    184 	}
    185 
    186 	sc->sc_has |= ATPPC_HAS_INTR;
    187 
    188 	/* Run soft configuration attach */
    189 	atppc_sc_attach(sc);
    190 }
    191 
    192 /* Start DMA operation over ISA bus */
    193 static int
    194 atppc_acpi_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes,
    195 	u_int8_t mode)
    196 {
    197 	struct atppc_acpi_softc * sc = (struct atppc_acpi_softc *) lsc;
    198 
    199 	return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode);
    200 }
    201 
    202 /* Stop DMA operation over ISA bus */
    203 static int
    204 atppc_acpi_dma_finish(struct atppc_softc * lsc)
    205 {
    206 	struct atppc_acpi_softc * sc = (struct atppc_acpi_softc *) lsc;
    207 
    208 	return atppc_isadma_finish(sc->sc_ic, sc->sc_drq);
    209 }
    210 
    211 /* Abort DMA operation over ISA bus */
    212 int
    213 atppc_acpi_dma_abort(struct atppc_softc * lsc)
    214 {
    215 	struct atppc_acpi_softc * sc = (struct atppc_acpi_softc *) lsc;
    216 
    217 	return atppc_isadma_abort(sc->sc_ic, sc->sc_drq);
    218 }
    219 
    220 /* Allocate memory for DMA over ISA bus */
    221 int
    222 atppc_acpi_dma_malloc(struct device * dev, caddr_t * buf, bus_addr_t * bus_addr,
    223 	bus_size_t size)
    224 {
    225 	struct atppc_acpi_softc * sc = (struct atppc_acpi_softc *) dev;
    226 
    227 	return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
    228 }
    229 
    230 /* Free memory allocated by atppc_isa_dma_malloc() */
    231 void
    232 atppc_acpi_dma_free(struct device * dev, caddr_t * buf, bus_addr_t * bus_addr,
    233 	bus_size_t size)
    234 {
    235 	struct atppc_acpi_softc * sc = (struct atppc_acpi_softc *) dev;
    236 
    237 	return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
    238 }
    239