2008-04-29 00:22:51 +04:00
|
|
|
/* $NetBSD: atppc_acpi.c,v 1.14 2008/04/28 20:23:47 martin Exp $ */
|
2004-01-25 14:46:49 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2004 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jaromir Dolecek.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2008-04-29 00:22:51 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: atppc_acpi.c,v 1.14 2008/04/28 20:23:47 martin Exp $");
|
2004-01-25 14:46:49 +03:00
|
|
|
|
|
|
|
#include "opt_atppc.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/termios.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
2004-01-25 14:46:49 +03:00
|
|
|
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
#include <dev/isa/isadmavar.h>
|
|
|
|
|
|
|
|
#include <dev/acpi/acpica.h>
|
|
|
|
#include <dev/acpi/acpireg.h>
|
|
|
|
#include <dev/acpi/acpivar.h>
|
|
|
|
|
|
|
|
#include <dev/ic/atppcvar.h>
|
|
|
|
#include <dev/isa/atppc_isadma.h>
|
|
|
|
|
2008-04-16 13:39:01 +04:00
|
|
|
static int atppc_acpi_match(device_t, cfdata_t, void *);
|
|
|
|
static void atppc_acpi_attach(device_t, device_t, void *);
|
2004-01-25 14:46:49 +03:00
|
|
|
|
|
|
|
struct atppc_acpi_softc {
|
|
|
|
struct atppc_softc sc_atppc;
|
|
|
|
|
|
|
|
isa_chipset_tag_t sc_ic;
|
|
|
|
int sc_drq;
|
|
|
|
};
|
|
|
|
|
2008-04-15 19:02:28 +04:00
|
|
|
CFATTACH_DECL_NEW(atppc_acpi, sizeof(struct atppc_acpi_softc), atppc_acpi_match,
|
2004-01-25 14:46:49 +03:00
|
|
|
atppc_acpi_attach, NULL, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Supported device IDs
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const char * const atppc_acpi_ids[] = {
|
|
|
|
"PNP04??", /* Standard AT printer port */
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2004-04-10 15:48:10 +04:00
|
|
|
static int atppc_acpi_dma_start(struct atppc_softc *, void *, u_int,
|
2004-01-25 14:46:49 +03:00
|
|
|
u_int8_t);
|
|
|
|
static int atppc_acpi_dma_finish(struct atppc_softc *);
|
|
|
|
static int atppc_acpi_dma_abort(struct atppc_softc *);
|
2008-04-16 13:39:01 +04:00
|
|
|
static int atppc_acpi_dma_malloc(device_t, void **, bus_addr_t *,
|
2004-01-25 14:46:49 +03:00
|
|
|
bus_size_t);
|
2008-04-16 13:39:01 +04:00
|
|
|
static void atppc_acpi_dma_free(device_t, void **, bus_addr_t *,
|
2004-01-25 14:46:49 +03:00
|
|
|
bus_size_t);
|
|
|
|
/*
|
|
|
|
* atppc_acpi_match: autoconf(9) match routine
|
|
|
|
*/
|
|
|
|
static int
|
2008-04-16 13:39:01 +04:00
|
|
|
atppc_acpi_match(device_t parent, cfdata_t match, void *aux)
|
2004-01-25 14:46:49 +03:00
|
|
|
{
|
|
|
|
struct acpi_attach_args *aa = aux;
|
|
|
|
|
|
|
|
if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return acpi_match_hid(aa->aa_node->ad_devinfo, atppc_acpi_ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-04-16 13:39:01 +04:00
|
|
|
atppc_acpi_attach(device_t parent, device_t self, void *aux)
|
2004-01-25 14:46:49 +03:00
|
|
|
{
|
2008-04-16 13:39:01 +04:00
|
|
|
struct atppc_softc *sc = device_private(self);
|
|
|
|
struct atppc_acpi_softc *asc = device_private(self);
|
2004-01-25 14:46:49 +03:00
|
|
|
struct acpi_attach_args *aa = aux;
|
|
|
|
struct acpi_resources res;
|
|
|
|
struct acpi_io *io;
|
|
|
|
struct acpi_irq *irq;
|
|
|
|
struct acpi_drq *drq;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
int nirq;
|
|
|
|
|
|
|
|
sc->sc_dev_ok = ATPPC_NOATTACH;
|
|
|
|
|
2006-02-20 15:17:49 +03:00
|
|
|
aprint_naive(": AT Parallel Port\n");
|
|
|
|
aprint_normal(": AT Parallel Port\n");
|
2004-01-25 14:46:49 +03:00
|
|
|
|
|
|
|
/* parse resources */
|
2008-04-15 19:02:28 +04:00
|
|
|
rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
|
2004-04-11 13:38:19 +04:00
|
|
|
&res, &acpi_resource_parse_ops_default);
|
2004-01-25 14:46:49 +03:00
|
|
|
if (ACPI_FAILURE(rv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* find our i/o registers */
|
|
|
|
io = acpi_res_io(&res, 0);
|
|
|
|
if (io == NULL) {
|
2008-04-15 19:02:28 +04:00
|
|
|
aprint_error_dev(sc->sc_dev, "unable to find i/o register resource\n");
|
2004-04-11 14:36:35 +04:00
|
|
|
goto out;
|
2004-01-25 14:46:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find our IRQ */
|
|
|
|
irq = acpi_res_irq(&res, 0);
|
|
|
|
if (irq == NULL) {
|
2008-04-15 19:02:28 +04:00
|
|
|
aprint_error_dev(sc->sc_dev, "unable to find irq resource\n");
|
2004-04-11 14:36:35 +04:00
|
|
|
goto out;
|
2004-01-25 14:46:49 +03:00
|
|
|
}
|
|
|
|
nirq = irq->ar_irq;
|
|
|
|
|
|
|
|
/* find our DRQ */
|
|
|
|
drq = acpi_res_drq(&res, 0);
|
|
|
|
if (drq == NULL) {
|
2008-04-15 19:02:28 +04:00
|
|
|
aprint_error_dev(sc->sc_dev, "unable to find drq resource\n");
|
2004-04-11 14:36:35 +04:00
|
|
|
goto out;
|
2004-01-25 14:46:49 +03:00
|
|
|
}
|
|
|
|
asc->sc_drq = drq->ar_drq;
|
|
|
|
|
|
|
|
/* Attach */
|
2008-04-16 13:39:01 +04:00
|
|
|
sc->sc_dev = self;
|
2004-01-25 14:46:49 +03:00
|
|
|
sc->sc_iot = aa->aa_iot;
|
|
|
|
sc->sc_has = 0;
|
|
|
|
asc->sc_ic = aa->aa_ic;
|
|
|
|
|
|
|
|
sc->sc_dev_ok = ATPPC_ATTACHED;
|
|
|
|
|
|
|
|
if (bus_space_map(sc->sc_iot, io->ar_base, io->ar_length, 0,
|
|
|
|
&sc->sc_ioh) != 0) {
|
2008-04-06 01:44:50 +04:00
|
|
|
aprint_error_dev(self, "attempt to map bus space failed, device not "
|
|
|
|
"properly attached.\n");
|
2004-04-11 14:36:35 +04:00
|
|
|
goto out;
|
2004-01-25 14:46:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_ieh = isa_intr_establish(aa->aa_ic, nirq,
|
|
|
|
(irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL,
|
|
|
|
IPL_TTY, atppcintr, sc);
|
|
|
|
|
|
|
|
/* setup DMA hooks */
|
|
|
|
if (atppc_isadma_setup(sc, asc->sc_ic, asc->sc_drq) == 0) {
|
|
|
|
sc->sc_has |= ATPPC_HAS_DMA;
|
|
|
|
sc->sc_dma_start = atppc_acpi_dma_start;
|
|
|
|
sc->sc_dma_finish = atppc_acpi_dma_finish;
|
|
|
|
sc->sc_dma_abort = atppc_acpi_dma_abort;
|
|
|
|
sc->sc_dma_malloc = atppc_acpi_dma_malloc;
|
|
|
|
sc->sc_dma_free = atppc_acpi_dma_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_has |= ATPPC_HAS_INTR;
|
|
|
|
|
|
|
|
/* Run soft configuration attach */
|
|
|
|
atppc_sc_attach(sc);
|
2004-04-11 14:36:35 +04:00
|
|
|
out:
|
|
|
|
acpi_resource_cleanup(&res);
|
2004-01-25 14:46:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Start DMA operation over ISA bus */
|
2004-04-10 15:48:10 +04:00
|
|
|
static int
|
2004-01-25 14:46:49 +03:00
|
|
|
atppc_acpi_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes,
|
|
|
|
u_int8_t mode)
|
|
|
|
{
|
|
|
|
struct atppc_acpi_softc * sc = (struct atppc_acpi_softc *) lsc;
|
2004-04-10 15:48:10 +04:00
|
|
|
|
2004-01-25 14:46:49 +03:00
|
|
|
return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop DMA operation over ISA bus */
|
2004-04-10 15:48:10 +04:00
|
|
|
static int
|
2004-01-25 14:46:49 +03:00
|
|
|
atppc_acpi_dma_finish(struct atppc_softc * lsc)
|
|
|
|
{
|
|
|
|
struct atppc_acpi_softc * sc = (struct atppc_acpi_softc *) lsc;
|
2004-04-10 15:48:10 +04:00
|
|
|
|
2004-01-25 14:46:49 +03:00
|
|
|
return atppc_isadma_finish(sc->sc_ic, sc->sc_drq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Abort DMA operation over ISA bus */
|
2004-04-10 15:48:10 +04:00
|
|
|
int
|
2004-01-25 14:46:49 +03:00
|
|
|
atppc_acpi_dma_abort(struct atppc_softc * lsc)
|
|
|
|
{
|
|
|
|
struct atppc_acpi_softc * sc = (struct atppc_acpi_softc *) lsc;
|
2004-04-10 15:48:10 +04:00
|
|
|
|
2004-01-25 14:46:49 +03:00
|
|
|
return atppc_isadma_abort(sc->sc_ic, sc->sc_drq);
|
|
|
|
}
|
|
|
|
|
2004-04-10 15:48:10 +04:00
|
|
|
/* Allocate memory for DMA over ISA bus */
|
2004-05-01 16:03:27 +04:00
|
|
|
static int
|
2008-04-16 13:39:01 +04:00
|
|
|
atppc_acpi_dma_malloc(device_t dev, void ** buf, bus_addr_t * bus_addr,
|
2004-01-25 14:46:49 +03:00
|
|
|
bus_size_t size)
|
|
|
|
{
|
2008-04-16 13:39:01 +04:00
|
|
|
struct atppc_acpi_softc * sc = device_private(dev);
|
2004-01-25 14:46:49 +03:00
|
|
|
|
|
|
|
return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
|
|
|
|
}
|
|
|
|
|
2004-04-10 15:48:10 +04:00
|
|
|
/* Free memory allocated by atppc_isa_dma_malloc() */
|
2004-05-01 16:03:27 +04:00
|
|
|
static void
|
2008-04-16 13:39:01 +04:00
|
|
|
atppc_acpi_dma_free(device_t dev, void ** buf, bus_addr_t * bus_addr,
|
2004-01-25 14:46:49 +03:00
|
|
|
bus_size_t size)
|
|
|
|
{
|
2008-04-16 13:39:01 +04:00
|
|
|
struct atppc_acpi_softc * sc = device_private(dev);
|
2004-01-25 14:46:49 +03:00
|
|
|
|
|
|
|
return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
|
|
|
|
}
|