2007-03-04 08:59:00 +03:00
|
|
|
/* $NetBSD: atppc.c,v 1.23 2007/03/04 06:01:50 christos Exp $ */
|
2004-01-21 03:33:37 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2001 Alcove - Nicolas Souchu
|
2004-02-11 00:55:38 +03:00
|
|
|
* Copyright (c) 2003, 2004 Gary Thorpe <gathorpe@users.sourceforge.net>
|
2004-01-20 02:22:23 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 AUTHOR 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 AUTHOR 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.
|
|
|
|
*
|
2004-01-25 03:28:01 +03:00
|
|
|
* FreeBSD: src/sys/isa/ppc.c,v 1.26.2.5 2001/10/02 05:21:45 nsouch Exp
|
2004-01-20 02:22:23 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-01-25 03:28:01 +03:00
|
|
|
#include <sys/cdefs.h>
|
2007-03-04 08:59:00 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: atppc.c,v 1.23 2007/03/04 06:01:50 christos Exp $");
|
2004-01-25 03:28:01 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
#include "opt_atppc.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
2004-02-24 20:41:09 +03:00
|
|
|
/*#include <machine/intr.h>*/
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
#include <dev/isa/isareg.h>
|
|
|
|
|
|
|
|
#include <dev/ic/atppcreg.h>
|
|
|
|
#include <dev/ic/atppcvar.h>
|
|
|
|
|
|
|
|
#include <dev/ppbus/ppbus_conf.h>
|
|
|
|
#include <dev/ppbus/ppbus_msq.h>
|
|
|
|
#include <dev/ppbus/ppbus_io.h>
|
|
|
|
#include <dev/ppbus/ppbus_var.h>
|
|
|
|
|
|
|
|
#ifdef ATPPC_DEBUG
|
|
|
|
int atppc_debug = 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ATPPC_VERBOSE
|
|
|
|
int atppc_verbose = 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* List of supported chipsets detection routines */
|
|
|
|
static int (*chipset_detect[])(struct atppc_softc *) = {
|
2006-12-25 21:39:47 +03:00
|
|
|
/* XXX Add these LATER: maybe as separate devices?
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_pc873xx_detect,
|
|
|
|
atppc_smc37c66xgt_detect,
|
|
|
|
atppc_w83877f_detect,
|
|
|
|
atppc_smc37c935_detect,
|
|
|
|
*/
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Prototypes for functions. */
|
|
|
|
|
2004-09-13 16:55:47 +04:00
|
|
|
/* Print function for config_found() */
|
2004-01-28 17:26:24 +03:00
|
|
|
static int atppc_print(void *, const char *);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Detection routines */
|
|
|
|
static int atppc_detect_fifo(struct atppc_softc *);
|
|
|
|
static int atppc_detect_chipset(struct atppc_softc *);
|
|
|
|
static int atppc_detect_generic(struct atppc_softc *);
|
|
|
|
|
|
|
|
/* Routines for ppbus interface (bus + device) */
|
|
|
|
static int atppc_read(struct device *, char *, int, int, size_t *);
|
|
|
|
static int atppc_write(struct device *, char *, int, int, size_t *);
|
|
|
|
static int atppc_setmode(struct device *, int);
|
|
|
|
static int atppc_getmode(struct device *);
|
|
|
|
static int atppc_check_epp_timeout(struct device *);
|
|
|
|
static void atppc_reset_epp_timeout(struct device *);
|
|
|
|
static void atppc_ecp_sync(struct device *);
|
|
|
|
static int atppc_exec_microseq(struct device *, struct ppbus_microseq * *);
|
|
|
|
static u_int8_t atppc_io(struct device *, int, u_char *, int, u_char);
|
|
|
|
static int atppc_read_ivar(struct device *, int, unsigned int *);
|
|
|
|
static int atppc_write_ivar(struct device *, int, unsigned int *);
|
|
|
|
static int atppc_add_handler(struct device *, void (*)(void *), void *);
|
2004-01-28 17:26:24 +03:00
|
|
|
static int atppc_remove_handler(struct device *, void (*)(void *));
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
/* Utility functions */
|
|
|
|
|
|
|
|
/* Functions to read bytes into device's input buffer */
|
|
|
|
static void atppc_nibble_read(struct atppc_softc * const);
|
|
|
|
static void atppc_byte_read(struct atppc_softc * const);
|
|
|
|
static void atppc_epp_read(struct atppc_softc * const);
|
|
|
|
static void atppc_ecp_read(struct atppc_softc * const);
|
2004-01-28 17:26:24 +03:00
|
|
|
static void atppc_ecp_read_dma(struct atppc_softc *, unsigned int *,
|
2004-01-20 02:22:23 +03:00
|
|
|
unsigned char);
|
2004-01-28 17:26:24 +03:00
|
|
|
static void atppc_ecp_read_pio(struct atppc_softc *, unsigned int *,
|
2004-01-20 02:22:23 +03:00
|
|
|
unsigned char);
|
2006-05-29 19:17:29 +04:00
|
|
|
static void atppc_ecp_read_error(struct atppc_softc *);
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* Functions to write bytes to device's output buffer */
|
|
|
|
static void atppc_std_write(struct atppc_softc * const);
|
|
|
|
static void atppc_epp_write(struct atppc_softc * const);
|
|
|
|
static void atppc_fifo_write(struct atppc_softc * const);
|
2004-01-28 17:26:24 +03:00
|
|
|
static void atppc_fifo_write_dma(struct atppc_softc * const, unsigned char,
|
2004-01-20 02:22:23 +03:00
|
|
|
unsigned char);
|
|
|
|
static void atppc_fifo_write_pio(struct atppc_softc * const, unsigned char,
|
|
|
|
unsigned char);
|
2004-01-28 17:26:24 +03:00
|
|
|
static void atppc_fifo_write_error(struct atppc_softc * const,
|
2004-01-20 02:22:23 +03:00
|
|
|
const unsigned int);
|
|
|
|
|
|
|
|
/* Miscellaneous */
|
2004-01-28 17:26:24 +03:00
|
|
|
static int atppc_poll_str(const struct atppc_softc * const, const u_int8_t,
|
2004-01-20 02:22:23 +03:00
|
|
|
const u_int8_t);
|
2007-03-04 08:59:00 +03:00
|
|
|
static int atppc_wait_interrupt(struct atppc_softc * const, const void *,
|
2004-01-20 02:22:23 +03:00
|
|
|
const u_int8_t);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2004-01-28 17:26:24 +03:00
|
|
|
* Generic attach and detach functions for atppc device. If sc_dev_ok in soft
|
2004-01-20 02:22:23 +03:00
|
|
|
* configuration data is not ATPPC_ATTACHED, these should be skipped altogether.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Soft configuration attach for atppc */
|
|
|
|
void
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_sc_attach(struct atppc_softc *lsc)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
|
|
|
/* Adapter used to configure ppbus device */
|
|
|
|
struct parport_adapter sc_parport_adapter;
|
|
|
|
char buf[64];
|
|
|
|
|
2004-04-21 21:38:48 +04:00
|
|
|
ATPPC_LOCK_INIT(lsc);
|
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Probe and set up chipset */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc_detect_chipset(lsc) != 0) {
|
|
|
|
if (atppc_detect_generic(lsc) != 0) {
|
|
|
|
ATPPC_DPRINTF(("%s: Error detecting chipset\n",
|
|
|
|
lsc->sc_dev.dv_xname));
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Probe and setup FIFO queue */
|
2004-01-25 14:41:17 +03:00
|
|
|
if (atppc_detect_fifo(lsc) == 0) {
|
2004-01-28 17:26:24 +03:00
|
|
|
printf("%s: FIFO <depth,wthr,rthr>=<%d,%d,%d>\n",
|
|
|
|
lsc->sc_dev.dv_xname, lsc->sc_fifo, lsc->sc_wthr,
|
2004-01-25 14:41:17 +03:00
|
|
|
lsc->sc_rthr);
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Print out chipset capabilities */
|
|
|
|
bitmask_snprintf(lsc->sc_has, "\20\1INTR\2DMA\3FIFO\4PS2\5ECP\6EPP",
|
2004-01-28 17:26:24 +03:00
|
|
|
buf, sizeof(buf));
|
|
|
|
printf("%s: capabilities=%s\n", lsc->sc_dev.dv_xname, buf);
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
/* Initialize device's buffer pointers */
|
2004-01-28 17:26:24 +03:00
|
|
|
lsc->sc_outb = lsc->sc_outbstart = lsc->sc_inb = lsc->sc_inbstart
|
2004-01-20 02:22:23 +03:00
|
|
|
= NULL;
|
|
|
|
lsc->sc_inb_nbytes = lsc->sc_outb_nbytes = 0;
|
|
|
|
|
|
|
|
/* Last configuration step: set mode to standard mode */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc_setmode(&(lsc->sc_dev), PPBUS_COMPATIBLE) != 0) {
|
|
|
|
ATPPC_DPRINTF(("%s: unable to initialize mode.\n",
|
2004-01-25 14:41:17 +03:00
|
|
|
lsc->sc_dev.dv_xname));
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined (MULTIPROCESSOR) || defined (LOCKDEBUG)
|
|
|
|
/* Initialize lock structure */
|
|
|
|
simple_lock_init(&(lsc->sc_lock));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Set up parport_adapter structure */
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Set capabilites */
|
|
|
|
sc_parport_adapter.capabilities = 0;
|
2004-01-28 17:26:24 +03:00
|
|
|
if (lsc->sc_has & ATPPC_HAS_INTR) {
|
2004-01-20 02:22:23 +03:00
|
|
|
sc_parport_adapter.capabilities |= PPBUS_HAS_INTR;
|
|
|
|
}
|
2004-01-28 17:26:24 +03:00
|
|
|
if (lsc->sc_has & ATPPC_HAS_DMA) {
|
2004-01-20 02:22:23 +03:00
|
|
|
sc_parport_adapter.capabilities |= PPBUS_HAS_DMA;
|
|
|
|
}
|
2004-01-28 17:26:24 +03:00
|
|
|
if (lsc->sc_has & ATPPC_HAS_FIFO) {
|
2004-01-20 02:22:23 +03:00
|
|
|
sc_parport_adapter.capabilities |= PPBUS_HAS_FIFO;
|
|
|
|
}
|
2004-01-28 17:26:24 +03:00
|
|
|
if (lsc->sc_has & ATPPC_HAS_PS2) {
|
2004-01-20 02:22:23 +03:00
|
|
|
sc_parport_adapter.capabilities |= PPBUS_HAS_PS2;
|
|
|
|
}
|
2004-01-28 17:26:24 +03:00
|
|
|
if (lsc->sc_has & ATPPC_HAS_EPP) {
|
2004-01-20 02:22:23 +03:00
|
|
|
sc_parport_adapter.capabilities |= PPBUS_HAS_EPP;
|
|
|
|
}
|
2004-01-28 17:26:24 +03:00
|
|
|
if (lsc->sc_has & ATPPC_HAS_ECP) {
|
2004-01-20 02:22:23 +03:00
|
|
|
sc_parport_adapter.capabilities |= PPBUS_HAS_ECP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set function pointers */
|
|
|
|
sc_parport_adapter.parport_io = atppc_io;
|
|
|
|
sc_parport_adapter.parport_exec_microseq = atppc_exec_microseq;
|
2004-01-28 17:26:24 +03:00
|
|
|
sc_parport_adapter.parport_reset_epp_timeout =
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_reset_epp_timeout;
|
|
|
|
sc_parport_adapter.parport_setmode = atppc_setmode;
|
|
|
|
sc_parport_adapter.parport_getmode = atppc_getmode;
|
|
|
|
sc_parport_adapter.parport_ecp_sync = atppc_ecp_sync;
|
|
|
|
sc_parport_adapter.parport_read = atppc_read;
|
|
|
|
sc_parport_adapter.parport_write = atppc_write;
|
|
|
|
sc_parport_adapter.parport_read_ivar = atppc_read_ivar;
|
|
|
|
sc_parport_adapter.parport_write_ivar = atppc_write_ivar;
|
|
|
|
sc_parport_adapter.parport_dma_malloc = lsc->sc_dma_malloc;
|
|
|
|
sc_parport_adapter.parport_dma_free = lsc->sc_dma_free;
|
|
|
|
sc_parport_adapter.parport_add_handler = atppc_add_handler;
|
|
|
|
sc_parport_adapter.parport_remove_handler = atppc_remove_handler;
|
|
|
|
|
|
|
|
/* Initialize handler list, may be added to by grandchildren */
|
|
|
|
SLIST_INIT(&(lsc->sc_handler_listhead));
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Initialize interrupt state */
|
|
|
|
lsc->sc_irqstat = ATPPC_IRQ_NONE;
|
|
|
|
lsc->sc_ecr_intr = lsc->sc_ctr_intr = lsc->sc_str_intr = 0;
|
|
|
|
|
|
|
|
/* Disable DMA/interrupts (each ppbus driver selects usage itself) */
|
|
|
|
lsc->sc_use = 0;
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
/* Configure child of the device. */
|
2004-09-13 16:55:47 +04:00
|
|
|
lsc->child = config_found(&(lsc->sc_dev), &(sc_parport_adapter),
|
|
|
|
atppc_print);
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Soft configuration detach */
|
2004-08-24 04:53:28 +04:00
|
|
|
int
|
|
|
|
atppc_sc_detach(struct atppc_softc *lsc, int flag)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
struct device *dev = (struct device *)lsc;
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
/* Detach children devices */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (config_detach(lsc->child, flag) && !(flag & DETACH_QUIET)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
printf("%s not able to detach child device, ", dev->dv_xname);
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
if (!(flag & DETACH_FORCE)) {
|
2004-01-20 22:58:00 +03:00
|
|
|
printf("cannot detach\n");
|
2004-01-20 02:22:23 +03:00
|
|
|
return 1;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 22:58:00 +03:00
|
|
|
printf("continuing (DETACH_FORCE)\n");
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
if (!(flag & DETACH_QUIET))
|
2004-01-20 02:22:23 +03:00
|
|
|
printf("%s detached", dev->dv_xname);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-09-13 16:55:47 +04:00
|
|
|
/* Used by config_found() to print out device information */
|
2004-01-28 17:26:24 +03:00
|
|
|
static int
|
|
|
|
atppc_print(void *aux, const char *name)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
|
|
|
/* Print out something on failure. */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (name != NULL) {
|
2004-01-20 02:22:23 +03:00
|
|
|
printf("%s: child devices", name);
|
|
|
|
return UNCONF;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QUIET;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Machine independent detection routines for atppc driver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Detect parallel port I/O port: taken from FreeBSD code directly. */
|
|
|
|
int
|
|
|
|
atppc_detect_port(bus_space_tag_t iot, bus_space_handle_t ioh)
|
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
/*
|
|
|
|
* Much shorter than scheme used by lpt_isa_probe() and lpt_port_test()
|
|
|
|
* in original lpt driver.
|
|
|
|
* Write to data register common to all controllers and read back the
|
2004-01-20 02:22:23 +03:00
|
|
|
* values. Also tests control and status registers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2004-01-28 17:26:24 +03:00
|
|
|
* Cannot use convenient macros because the device's config structure
|
2004-01-20 02:22:23 +03:00
|
|
|
* may not have been created yet: major change from FreeBSD code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int rval;
|
|
|
|
u_int8_t ctr_sav, dtr_sav, str_sav;
|
|
|
|
|
|
|
|
/* Store writtable registers' values and test if they can be read */
|
|
|
|
str_sav = bus_space_read_1(iot, ioh, ATPPC_SPP_STR);
|
|
|
|
ctr_sav = bus_space_read_1(iot, ioh, ATPPC_SPP_CTR);
|
|
|
|
dtr_sav = bus_space_read_1(iot, ioh, ATPPC_SPP_DTR);
|
2004-01-28 17:26:24 +03:00
|
|
|
bus_space_barrier(iot, ioh, 0, IO_LPTSIZE,
|
|
|
|
BUS_SPACE_BARRIER_READ);
|
2004-01-20 02:22:23 +03:00
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
/*
|
|
|
|
* Ensure PS2 ports in output mode, also read back value of control
|
|
|
|
* register.
|
2004-01-20 02:22:23 +03:00
|
|
|
*/
|
|
|
|
bus_space_write_1(iot, ioh, ATPPC_SPP_CTR, 0x0c);
|
2004-01-28 17:26:24 +03:00
|
|
|
bus_space_barrier(iot, ioh, 0, IO_LPTSIZE,
|
|
|
|
BUS_SPACE_BARRIER_WRITE);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
if (bus_space_read_1(iot, ioh, ATPPC_SPP_CTR) != 0x0c) {
|
2004-01-20 02:22:23 +03:00
|
|
|
rval = 0;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Test if two values can be written and read from the data
|
|
|
|
* register.
|
2004-01-20 02:22:23 +03:00
|
|
|
*/
|
2004-01-28 17:26:24 +03:00
|
|
|
bus_space_barrier(iot, ioh, 0, IO_LPTSIZE,
|
|
|
|
BUS_SPACE_BARRIER_READ);
|
2004-01-20 02:22:23 +03:00
|
|
|
bus_space_write_1(iot, ioh, ATPPC_SPP_DTR, 0xaa);
|
2004-01-28 17:26:24 +03:00
|
|
|
bus_space_barrier(iot, ioh, 0, IO_LPTSIZE,
|
|
|
|
BUS_SPACE_BARRIER_WRITE);
|
2004-01-20 02:22:23 +03:00
|
|
|
if (bus_space_read_1(iot, ioh, ATPPC_SPP_DTR) != 0xaa) {
|
|
|
|
rval = 1;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Second value to test */
|
2004-01-28 17:26:24 +03:00
|
|
|
bus_space_barrier(iot, ioh, 0, IO_LPTSIZE,
|
|
|
|
BUS_SPACE_BARRIER_READ);
|
2004-01-20 02:22:23 +03:00
|
|
|
bus_space_write_1(iot, ioh, ATPPC_SPP_DTR, 0x55);
|
2004-01-28 17:26:24 +03:00
|
|
|
bus_space_barrier(iot, ioh, 0, IO_LPTSIZE,
|
|
|
|
BUS_SPACE_BARRIER_WRITE);
|
|
|
|
if (bus_space_read_1(iot, ioh, ATPPC_SPP_DTR) != 0x55) {
|
2004-01-20 02:22:23 +03:00
|
|
|
rval = 1;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
rval = 0;
|
|
|
|
}
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Restore registers */
|
2004-01-28 17:26:24 +03:00
|
|
|
bus_space_barrier(iot, ioh, 0, IO_LPTSIZE,
|
|
|
|
BUS_SPACE_BARRIER_READ);
|
2004-01-20 02:22:23 +03:00
|
|
|
bus_space_write_1(iot, ioh, ATPPC_SPP_CTR, ctr_sav);
|
|
|
|
bus_space_write_1(iot, ioh, ATPPC_SPP_DTR, dtr_sav);
|
|
|
|
bus_space_write_1(iot, ioh, ATPPC_SPP_STR, str_sav);
|
2004-01-28 17:26:24 +03:00
|
|
|
bus_space_barrier(iot, ioh, 0, IO_LPTSIZE,
|
|
|
|
BUS_SPACE_BARRIER_WRITE);
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detect parallel port chipset. */
|
|
|
|
static int
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_detect_chipset(struct atppc_softc *atppc)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
|
|
|
/* Try each detection routine. */
|
|
|
|
int i, mode;
|
|
|
|
for (i = 0; chipset_detect[i] != NULL; i++) {
|
|
|
|
if ((mode = chipset_detect[i](atppc)) != -1) {
|
|
|
|
atppc->sc_mode = mode;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detect generic capabilities. */
|
2004-01-28 17:26:24 +03:00
|
|
|
static int
|
|
|
|
atppc_detect_generic(struct atppc_softc *atppc)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
|
|
|
u_int8_t ecr_sav = atppc_r_ecr(atppc);
|
|
|
|
u_int8_t ctr_sav = atppc_r_ctr(atppc);
|
|
|
|
u_int8_t str_sav = atppc_r_str(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
u_int8_t tmp;
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
|
|
|
|
/* Default to generic */
|
|
|
|
atppc->sc_type = ATPPC_TYPE_GENERIC;
|
|
|
|
atppc->sc_model = GENERIC;
|
|
|
|
|
|
|
|
/* Check for ECP */
|
|
|
|
tmp = atppc_r_ecr(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
if ((tmp & ATPPC_FIFO_EMPTY) && !(tmp & ATPPC_FIFO_FULL)) {
|
|
|
|
atppc_w_ecr(atppc, 0x34);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
tmp = atppc_r_ecr(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (tmp == 0x35) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_has |= ATPPC_HAS_ECP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allow search for SMC style ECP+EPP mode */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_has & ATPPC_HAS_ECP) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_w_ecr(atppc, ATPPC_ECR_EPP);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
}
|
|
|
|
/* Check for EPP by checking for timeout bit */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc_check_epp_timeout(&(atppc->sc_dev)) != 0) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_has |= ATPPC_HAS_EPP;
|
|
|
|
atppc->sc_epp = ATPPC_EPP_1_9;
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_has & ATPPC_HAS_ECP) {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* SMC like chipset found */
|
|
|
|
atppc->sc_model = SMC_LIKE;
|
|
|
|
atppc->sc_type = ATPPC_TYPE_SMCLIKE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detect PS2 mode */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_has & ATPPC_HAS_ECP) {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Put ECP port into PS2 mode */
|
|
|
|
atppc_w_ecr(atppc, ATPPC_ECR_PS2);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
}
|
|
|
|
/* Put PS2 port in input mode: writes should not be readable */
|
|
|
|
atppc_w_ctr(atppc, 0x20);
|
|
|
|
atppc_barrier_w(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
/*
|
|
|
|
* Write two values to data port: if neither are read back,
|
2004-01-20 02:22:23 +03:00
|
|
|
* bidirectional mode is functional.
|
|
|
|
*/
|
|
|
|
atppc_w_dtr(atppc, 0xaa);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
tmp = atppc_r_dtr(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-02-24 20:41:09 +03:00
|
|
|
if (tmp != 0xaa) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_w_dtr(atppc, 0x55);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
tmp = atppc_r_dtr(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (tmp != 0x55) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_has |= ATPPC_HAS_PS2;
|
|
|
|
}
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Restore to previous state */
|
|
|
|
atppc_w_ecr(atppc, ecr_sav);
|
|
|
|
atppc_w_ctr(atppc, ctr_sav);
|
|
|
|
atppc_w_str(atppc, str_sav);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
/*
|
|
|
|
* Detect parallel port FIFO: taken from FreeBSD code directly.
|
2004-01-20 02:22:23 +03:00
|
|
|
*/
|
|
|
|
static int
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_detect_fifo(struct atppc_softc *atppc)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
|
|
|
#ifdef ATPPC_DEBUG
|
2004-01-28 17:26:24 +03:00
|
|
|
struct device *dev = (struct device *)atppc;
|
2004-01-20 02:22:23 +03:00
|
|
|
#endif
|
|
|
|
u_int8_t ecr_sav;
|
|
|
|
u_int8_t ctr_sav;
|
|
|
|
u_int8_t str_sav;
|
|
|
|
u_int8_t cc;
|
|
|
|
short i;
|
|
|
|
|
|
|
|
/* If there is no ECP mode, we cannot config a FIFO */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (!(atppc->sc_has & ATPPC_HAS_ECP)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save registers */
|
|
|
|
ecr_sav = atppc_r_ecr(atppc);
|
|
|
|
ctr_sav = atppc_r_ctr(atppc);
|
|
|
|
str_sav = atppc_r_str(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Enter ECP configuration mode, no interrupt, no DMA */
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_w_ecr(atppc, (ATPPC_ECR_CFG | ATPPC_SERVICE_INTR) &
|
2004-01-20 02:22:23 +03:00
|
|
|
~ATPPC_ENABLE_DMA);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
/* read PWord size - transfers in FIFO mode must be PWord aligned */
|
|
|
|
atppc->sc_pword = (atppc_r_cnfgA(atppc) & ATPPC_PWORD_MASK);
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
|
|
|
|
/* XXX 16 and 32 bits implementations not supported */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_pword != ATPPC_PWORD_8) {
|
|
|
|
ATPPC_DPRINTF(("%s(%s): FIFO PWord(%d) not supported.\n",
|
2004-01-20 02:22:23 +03:00
|
|
|
__func__, dev->dv_xname, atppc->sc_pword));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Byte mode, reverse direction, no interrupt, no DMA */
|
|
|
|
atppc_w_ecr(atppc, ATPPC_ECR_PS2 | ATPPC_SERVICE_INTR);
|
|
|
|
atppc_w_ctr(atppc, (ctr_sav & ~IRQENABLE) | PCD);
|
|
|
|
/* enter ECP test mode, no interrupt, no DMA */
|
|
|
|
atppc_w_ecr(atppc, ATPPC_ECR_TST | ATPPC_SERVICE_INTR);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
/* flush the FIFO */
|
|
|
|
for (i = 0; i < 1024; i++) {
|
|
|
|
atppc_r_fifo(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
cc = atppc_r_ecr(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (cc & ATPPC_FIFO_EMPTY)
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= 1024) {
|
2004-01-28 17:26:24 +03:00
|
|
|
ATPPC_DPRINTF(("%s(%s): cannot flush FIFO.\n", __func__,
|
2004-01-20 02:22:23 +03:00
|
|
|
dev->dv_xname));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test mode, enable interrupts, no DMA */
|
|
|
|
atppc_w_ecr(atppc, ATPPC_ECR_TST);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
/* Determine readIntrThreshold - fill FIFO until serviceIntr is set */
|
|
|
|
for (i = atppc->sc_rthr = atppc->sc_fifo = 0; i < 1024; i++) {
|
|
|
|
atppc_w_fifo(atppc, (char)i);
|
|
|
|
atppc_barrier_w(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
cc = atppc_r_ecr(atppc);
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
if ((atppc->sc_rthr == 0) && (cc & ATPPC_SERVICE_INTR)) {
|
|
|
|
/* readThreshold reached */
|
|
|
|
atppc->sc_rthr = i + 1;
|
|
|
|
}
|
|
|
|
if (cc & ATPPC_FIFO_FULL) {
|
|
|
|
atppc->sc_fifo = i + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i >= 1024) {
|
2004-01-28 17:26:24 +03:00
|
|
|
ATPPC_DPRINTF(("%s(%s): cannot fill FIFO.\n", __func__,
|
2004-01-20 02:22:23 +03:00
|
|
|
dev->dv_xname));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Change direction */
|
|
|
|
atppc_w_ctr(atppc, (ctr_sav & ~IRQENABLE) & ~PCD);
|
|
|
|
atppc_barrier_w(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
|
2004-01-22 17:22:20 +03:00
|
|
|
/* Clear the serviceIntr bit we've already set in the above loop */
|
|
|
|
atppc_w_ecr(atppc, ATPPC_ECR_TST);
|
|
|
|
atppc_barrier_w(atppc);
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
/* Determine writeIntrThreshold - empty FIFO until serviceIntr is set */
|
2004-01-28 17:26:24 +03:00
|
|
|
for (atppc->sc_wthr = 0; i > -1; i--) {
|
|
|
|
cc = atppc_r_fifo(atppc);
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (cc != (char)(atppc->sc_fifo - i - 1)) {
|
|
|
|
ATPPC_DPRINTF(("%s(%s): invalid data in FIFO.\n",
|
2004-01-20 02:22:23 +03:00
|
|
|
__func__, dev->dv_xname));
|
|
|
|
goto error;
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
cc = atppc_r_ecr(atppc);
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if ((atppc->sc_wthr == 0) && (cc & ATPPC_SERVICE_INTR)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* writeIntrThreshold reached */
|
|
|
|
atppc->sc_wthr = atppc->sc_fifo - i;
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
if (i > 0 && (cc & ATPPC_FIFO_EMPTY)) {
|
|
|
|
/* If FIFO empty before the last byte, error */
|
|
|
|
ATPPC_DPRINTF(("%s(%s): data lost in FIFO.\n", __func__,
|
|
|
|
dev->dv_xname));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIFO must be empty after the last byte */
|
2004-01-28 17:26:24 +03:00
|
|
|
cc = atppc_r_ecr(atppc);
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
if (!(cc & ATPPC_FIFO_EMPTY)) {
|
2004-01-28 17:26:24 +03:00
|
|
|
ATPPC_DPRINTF(("%s(%s): cannot empty the FIFO.\n", __func__,
|
2004-01-20 02:22:23 +03:00
|
|
|
dev->dv_xname));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore original registers */
|
|
|
|
atppc_w_ctr(atppc, ctr_sav);
|
|
|
|
atppc_w_str(atppc, str_sav);
|
|
|
|
atppc_w_ecr(atppc, ecr_sav);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
/* Update capabilities */
|
|
|
|
atppc->sc_has |= ATPPC_HAS_FIFO;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* Restore original registers */
|
|
|
|
atppc_w_ctr(atppc, ctr_sav);
|
|
|
|
atppc_w_str(atppc, str_sav);
|
|
|
|
atppc_w_ecr(atppc, ecr_sav);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Interrupt handler for atppc device: wakes up read/write functions */
|
2004-01-28 17:26:24 +03:00
|
|
|
int
|
|
|
|
atppcintr(void *arg)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
struct atppc_softc *atppc = (struct atppc_softc *)arg;
|
|
|
|
struct device *dev = &atppc->sc_dev;
|
2004-02-10 21:42:48 +03:00
|
|
|
int claim = 1;
|
2004-01-20 02:22:23 +03:00
|
|
|
enum { NONE, READER, WRITER } wake_up = NONE;
|
|
|
|
|
|
|
|
/* Record registers' status */
|
|
|
|
atppc->sc_str_intr = atppc_r_str(atppc);
|
|
|
|
atppc->sc_ctr_intr = atppc_r_ctr(atppc);
|
|
|
|
atppc->sc_ecr_intr = atppc_r_ecr(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
/* Determine cause of interrupt and wake up top half */
|
|
|
|
switch (atppc->sc_mode) {
|
2004-01-20 02:22:23 +03:00
|
|
|
case ATPPC_MODE_STD:
|
|
|
|
/* nAck pulsed for 5 usec, too fast to check reliably, assume */
|
|
|
|
atppc->sc_irqstat = ATPPC_IRQ_nACK;
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_outb)
|
2004-01-20 02:22:23 +03:00
|
|
|
wake_up = WRITER;
|
|
|
|
else
|
2004-02-10 21:42:48 +03:00
|
|
|
claim = 0;
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
case ATPPC_MODE_NIBBLE:
|
|
|
|
case ATPPC_MODE_PS2:
|
|
|
|
/* nAck is set low by device and then high on ack */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (!(atppc->sc_str_intr & nACK)) {
|
2004-02-10 21:42:48 +03:00
|
|
|
claim = 0;
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
atppc->sc_irqstat = ATPPC_IRQ_nACK;
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_inb)
|
2004-01-20 02:22:23 +03:00
|
|
|
wake_up = READER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATPPC_MODE_ECP:
|
|
|
|
case ATPPC_MODE_FAST:
|
|
|
|
/* Confirm interrupt cause: these are not pulsed as in nAck. */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_ecr_intr & ATPPC_SERVICE_INTR) {
|
|
|
|
if (atppc->sc_ecr_intr & ATPPC_ENABLE_DMA)
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_irqstat |= ATPPC_IRQ_DMA;
|
2004-01-28 17:26:24 +03:00
|
|
|
else
|
|
|
|
atppc->sc_irqstat |= ATPPC_IRQ_FIFO;
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Decide where top half will be waiting */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_mode & ATPPC_MODE_ECP) {
|
|
|
|
if (atppc->sc_ctr_intr & PCD) {
|
|
|
|
if (atppc->sc_inb)
|
2004-01-20 02:22:23 +03:00
|
|
|
wake_up = READER;
|
|
|
|
else
|
2004-02-10 21:42:48 +03:00
|
|
|
claim = 0;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
|
|
|
if (atppc->sc_outb)
|
2004-01-20 02:22:23 +03:00
|
|
|
wake_up = WRITER;
|
|
|
|
else
|
2004-02-10 21:42:48 +03:00
|
|
|
claim = 0;
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
|
|
|
if (atppc->sc_outb)
|
2004-01-20 02:22:23 +03:00
|
|
|
wake_up = WRITER;
|
|
|
|
else
|
2004-02-10 21:42:48 +03:00
|
|
|
claim = 0;
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
|
|
|
}
|
2004-02-24 18:12:51 +03:00
|
|
|
/* Determine if nFault has occurred */
|
2004-01-28 17:26:24 +03:00
|
|
|
if ((atppc->sc_mode & ATPPC_MODE_ECP) &&
|
|
|
|
(atppc->sc_ecr_intr & ATPPC_nFAULT_INTR) &&
|
2004-01-20 02:22:23 +03:00
|
|
|
!(atppc->sc_str_intr & nFAULT)) {
|
|
|
|
|
|
|
|
/* Device is requesting the channel */
|
|
|
|
atppc->sc_irqstat |= ATPPC_IRQ_nFAULT;
|
2004-02-10 21:42:48 +03:00
|
|
|
claim = 1;
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATPPC_MODE_EPP:
|
|
|
|
/* nAck pulsed for 5 usec, too fast to check reliably */
|
|
|
|
atppc->sc_irqstat = ATPPC_IRQ_nACK;
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_inb)
|
2004-01-20 02:22:23 +03:00
|
|
|
wake_up = WRITER;
|
2004-01-28 17:26:24 +03:00
|
|
|
else if (atppc->sc_outb)
|
2004-01-20 02:22:23 +03:00
|
|
|
wake_up = READER;
|
2004-01-28 17:26:24 +03:00
|
|
|
else
|
2004-02-10 21:42:48 +03:00
|
|
|
claim = 0;
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic("%s: chipset is in invalid mode.", dev->dv_xname);
|
|
|
|
}
|
|
|
|
|
2004-02-10 21:42:48 +03:00
|
|
|
if (claim) {
|
|
|
|
switch (wake_up) {
|
|
|
|
case NONE:
|
|
|
|
break;
|
2004-01-20 02:22:23 +03:00
|
|
|
|
2004-02-10 21:42:48 +03:00
|
|
|
case READER:
|
|
|
|
wakeup(atppc->sc_inb);
|
|
|
|
break;
|
2004-01-20 02:22:23 +03:00
|
|
|
|
2004-02-10 21:42:48 +03:00
|
|
|
case WRITER:
|
|
|
|
wakeup(atppc->sc_outb);
|
|
|
|
break;
|
|
|
|
}
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
2004-02-10 21:42:48 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Call all of the installed handlers */
|
2004-02-10 21:42:48 +03:00
|
|
|
if (claim) {
|
2004-01-20 02:22:23 +03:00
|
|
|
struct atppc_handler_node * callback;
|
2004-01-28 17:26:24 +03:00
|
|
|
SLIST_FOREACH(callback, &(atppc->sc_handler_listhead),
|
2004-01-20 02:22:23 +03:00
|
|
|
entries) {
|
|
|
|
(*callback->func)(callback->arg);
|
|
|
|
}
|
|
|
|
}
|
2004-02-10 21:42:48 +03:00
|
|
|
|
|
|
|
return claim;
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Functions which support ppbus interface */
|
|
|
|
|
|
|
|
|
|
|
|
/* Check EPP mode timeout */
|
|
|
|
static int
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_check_epp_timeout(struct device *dev)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
struct atppc_softc *atppc = (struct atppc_softc *)dev;
|
2004-01-20 02:22:23 +03:00
|
|
|
int s;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
s = splatppc();
|
|
|
|
ATPPC_LOCK(atppc);
|
|
|
|
|
|
|
|
atppc_reset_epp_timeout(dev);
|
|
|
|
error = !(atppc_r_str(atppc) & TIMEOUT);
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
|
|
|
|
ATPPC_UNLOCK(atppc);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* EPP timeout, according to the PC87332 manual
|
|
|
|
* Semantics of clearing EPP timeout bit.
|
|
|
|
* PC87332 - reading SPP_STR does it...
|
|
|
|
* SMC - write 1 to EPP timeout bit XXX
|
|
|
|
* Others - (?) write 0 to EPP timeout bit
|
|
|
|
*/
|
|
|
|
static void
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_reset_epp_timeout(struct device *dev)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
struct atppc_softc *atppc = (struct atppc_softc *)dev;
|
2004-01-20 02:22:23 +03:00
|
|
|
register unsigned char r;
|
|
|
|
|
|
|
|
r = atppc_r_str(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
atppc_w_str(atppc, r | 0x1);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
atppc_w_str(atppc, r & 0xfe);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Read from atppc device: returns 0 on success. */
|
|
|
|
static int
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_read(struct device *dev, char *buf, int len, int ioflag,
|
|
|
|
size_t *cnt)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
struct atppc_softc *atppc = (struct atppc_softc *)dev;
|
2004-01-20 02:22:23 +03:00
|
|
|
int error = 0;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splatppc();
|
|
|
|
ATPPC_LOCK(atppc);
|
|
|
|
|
|
|
|
*cnt = 0;
|
|
|
|
|
|
|
|
/* Initialize buffer */
|
|
|
|
atppc->sc_inb = atppc->sc_inbstart = buf;
|
|
|
|
atppc->sc_inb_nbytes = len;
|
|
|
|
|
|
|
|
/* Initialize device input error state for new operation */
|
|
|
|
atppc->sc_inerr = 0;
|
|
|
|
|
|
|
|
/* Call appropriate function to read bytes */
|
|
|
|
switch(atppc->sc_mode) {
|
|
|
|
case ATPPC_MODE_STD:
|
|
|
|
case ATPPC_MODE_FAST:
|
|
|
|
error = ENODEV;
|
|
|
|
break;
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
case ATPPC_MODE_NIBBLE:
|
|
|
|
atppc_nibble_read(atppc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATPPC_MODE_PS2:
|
|
|
|
atppc_byte_read(atppc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATPPC_MODE_ECP:
|
|
|
|
atppc_ecp_read(atppc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATPPC_MODE_EPP:
|
|
|
|
atppc_epp_read(atppc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-01-28 17:26:24 +03:00
|
|
|
panic("%s(%s): chipset in invalid mode.\n", __func__,
|
|
|
|
dev->dv_xname);
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update counter*/
|
|
|
|
*cnt = (atppc->sc_inbstart - atppc->sc_inb);
|
|
|
|
|
|
|
|
/* Reset buffer */
|
|
|
|
atppc->sc_inb = atppc->sc_inbstart = NULL;
|
|
|
|
atppc->sc_inb_nbytes = 0;
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
if (!(error))
|
2004-01-20 02:22:23 +03:00
|
|
|
error = atppc->sc_inerr;
|
|
|
|
|
|
|
|
ATPPC_UNLOCK(atppc);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write to atppc device: returns 0 on success. */
|
|
|
|
static int
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_write(struct device *dev, char *buf, int len, int ioflag, size_t *cnt)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
struct atppc_softc * const atppc = (struct atppc_softc *)dev;
|
2004-01-20 02:22:23 +03:00
|
|
|
int error = 0;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
*cnt = 0;
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
s = splatppc();
|
|
|
|
ATPPC_LOCK(atppc);
|
|
|
|
|
|
|
|
/* Set up line buffer */
|
|
|
|
atppc->sc_outb = atppc->sc_outbstart = buf;
|
|
|
|
atppc->sc_outb_nbytes = len;
|
|
|
|
|
|
|
|
/* Initialize device output error state for new operation */
|
|
|
|
atppc->sc_outerr = 0;
|
|
|
|
|
|
|
|
/* Call appropriate function to write bytes */
|
2004-01-28 17:26:24 +03:00
|
|
|
switch (atppc->sc_mode) {
|
2004-01-20 02:22:23 +03:00
|
|
|
case ATPPC_MODE_STD:
|
|
|
|
atppc_std_write(atppc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATPPC_MODE_NIBBLE:
|
|
|
|
case ATPPC_MODE_PS2:
|
|
|
|
error = ENODEV;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATPPC_MODE_FAST:
|
|
|
|
case ATPPC_MODE_ECP:
|
|
|
|
atppc_fifo_write(atppc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATPPC_MODE_EPP:
|
|
|
|
atppc_epp_write(atppc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-01-28 17:26:24 +03:00
|
|
|
panic("%s(%s): chipset in invalid mode.\n", __func__,
|
2004-01-20 02:22:23 +03:00
|
|
|
dev->dv_xname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update counter*/
|
|
|
|
*cnt = (atppc->sc_outbstart - atppc->sc_outb);
|
|
|
|
|
|
|
|
/* Reset output buffer */
|
|
|
|
atppc->sc_outb = atppc->sc_outbstart = NULL;
|
|
|
|
atppc->sc_outb_nbytes = 0;
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
if (!(error))
|
2004-01-20 02:22:23 +03:00
|
|
|
error = atppc->sc_outerr;
|
|
|
|
|
|
|
|
ATPPC_UNLOCK(atppc);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
/*
|
|
|
|
* Set mode of chipset to mode argument. Modes not supported are ignored. If
|
|
|
|
* multiple modes are flagged, the mode is not changed. Mode's are those
|
|
|
|
* defined for ppbus_softc.sc_mode in ppbus_conf.h. Only ECP-capable chipsets
|
|
|
|
* can change their mode of operation. However, ALL operation modes support
|
|
|
|
* centronics mode and nibble mode. Modes determine both hardware AND software
|
2004-01-20 02:22:23 +03:00
|
|
|
* behaviour.
|
2004-01-28 17:26:24 +03:00
|
|
|
* NOTE: the mode for ECP should only be changed when the channel is in
|
|
|
|
* forward idle mode. This function does not make sure FIFO's have flushed or
|
2004-01-20 02:22:23 +03:00
|
|
|
* any consistency checks.
|
|
|
|
*/
|
2004-01-28 17:26:24 +03:00
|
|
|
static int
|
|
|
|
atppc_setmode(struct device *dev, int mode)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
struct atppc_softc *atppc = (struct atppc_softc *)dev;
|
|
|
|
u_int8_t ecr;
|
2004-01-20 02:22:23 +03:00
|
|
|
u_int8_t chipset_mode;
|
|
|
|
int s;
|
|
|
|
int rval = 0;
|
|
|
|
|
|
|
|
s = splatppc();
|
|
|
|
ATPPC_LOCK(atppc);
|
|
|
|
|
|
|
|
/* If ECP capable, configure ecr register */
|
|
|
|
if (atppc->sc_has & ATPPC_HAS_ECP) {
|
|
|
|
/* Read ECR with mode masked out */
|
2004-02-03 21:54:59 +03:00
|
|
|
ecr = (atppc_r_ecr(atppc) & 0x1f);
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
switch (mode) {
|
2004-01-20 02:22:23 +03:00
|
|
|
case PPBUS_ECP:
|
|
|
|
/* Set ECP mode */
|
|
|
|
ecr |= ATPPC_ECR_ECP;
|
|
|
|
chipset_mode = ATPPC_MODE_ECP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPBUS_EPP:
|
|
|
|
/* Set EPP mode */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_has & ATPPC_HAS_EPP) {
|
2004-01-20 02:22:23 +03:00
|
|
|
ecr |= ATPPC_ECR_EPP;
|
|
|
|
chipset_mode = ATPPC_MODE_EPP;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
rval = ENODEV;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPBUS_FAST:
|
|
|
|
/* Set fast centronics mode */
|
|
|
|
ecr |= ATPPC_ECR_FIFO;
|
|
|
|
chipset_mode = ATPPC_MODE_FAST;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPBUS_PS2:
|
|
|
|
/* Set PS2 mode */
|
|
|
|
ecr |= ATPPC_ECR_PS2;
|
|
|
|
chipset_mode = ATPPC_MODE_PS2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPBUS_COMPATIBLE:
|
|
|
|
/* Set standard mode */
|
|
|
|
ecr |= ATPPC_ECR_STD;
|
2004-02-24 20:41:09 +03:00
|
|
|
chipset_mode = ATPPC_MODE_STD;
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PPBUS_NIBBLE:
|
|
|
|
/* Set nibble mode: uses chipset standard mode */
|
|
|
|
ecr |= ATPPC_ECR_STD;
|
|
|
|
chipset_mode = ATPPC_MODE_NIBBLE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Invalid mode specified for ECP chip */
|
|
|
|
ATPPC_DPRINTF(("%s(%s): invalid mode passed as "
|
|
|
|
"argument.\n", __func__, dev->dv_xname));
|
|
|
|
rval = ENODEV;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Switch to byte mode to be able to change modes. */
|
|
|
|
atppc_w_ecr(atppc, ATPPC_ECR_PS2);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
/* Update mode */
|
|
|
|
atppc_w_ecr(atppc, ecr);
|
|
|
|
atppc_barrier_w(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
|
|
|
switch (mode) {
|
2004-01-20 02:22:23 +03:00
|
|
|
case PPBUS_EPP:
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_has & ATPPC_HAS_EPP) {
|
2004-01-20 02:22:23 +03:00
|
|
|
chipset_mode = ATPPC_MODE_EPP;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
rval = ENODEV;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPBUS_PS2:
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_has & ATPPC_HAS_PS2) {
|
2004-01-20 02:22:23 +03:00
|
|
|
chipset_mode = ATPPC_MODE_PS2;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
rval = ENODEV;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPBUS_NIBBLE:
|
|
|
|
/* Set nibble mode (virtual) */
|
|
|
|
chipset_mode = ATPPC_MODE_NIBBLE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPBUS_COMPATIBLE:
|
|
|
|
chipset_mode = ATPPC_MODE_STD;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPBUS_ECP:
|
|
|
|
rval = ENODEV;
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ATPPC_DPRINTF(("%s(%s): invalid mode passed as "
|
|
|
|
"argument.\n", __func__, dev->dv_xname));
|
|
|
|
rval = ENODEV;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
atppc->sc_mode = chipset_mode;
|
2004-01-28 17:26:24 +03:00
|
|
|
if (chipset_mode == ATPPC_MODE_PS2) {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Set direction bit to reverse */
|
|
|
|
ecr = atppc_r_ctr(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
ecr |= PCD;
|
|
|
|
atppc_w_ctr(atppc, ecr);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
ATPPC_UNLOCK(atppc);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the current mode of chipset */
|
|
|
|
static int
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_getmode(struct device *dev)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
struct atppc_softc *atppc = (struct atppc_softc *)dev;
|
2004-01-20 02:22:23 +03:00
|
|
|
int mode;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splatppc();
|
|
|
|
ATPPC_LOCK(atppc);
|
|
|
|
|
|
|
|
/* The chipset can only be in one mode at a time logically */
|
2004-01-28 17:26:24 +03:00
|
|
|
switch (atppc->sc_mode) {
|
2004-01-20 02:22:23 +03:00
|
|
|
case ATPPC_MODE_ECP:
|
|
|
|
mode = PPBUS_ECP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATPPC_MODE_EPP:
|
|
|
|
mode = PPBUS_EPP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATPPC_MODE_PS2:
|
|
|
|
mode = PPBUS_PS2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATPPC_MODE_STD:
|
|
|
|
mode = PPBUS_COMPATIBLE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATPPC_MODE_NIBBLE:
|
|
|
|
mode = PPBUS_NIBBLE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATPPC_MODE_FAST:
|
|
|
|
mode = PPBUS_FAST;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-01-28 17:26:24 +03:00
|
|
|
panic("%s(%s): device is in invalid mode!", __func__,
|
2004-01-20 02:22:23 +03:00
|
|
|
dev->dv_xname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ATPPC_UNLOCK(atppc);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
/* Wait for FIFO buffer to empty for ECP-capable chipset */
|
2004-01-20 02:22:23 +03:00
|
|
|
static void
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_ecp_sync(struct device *dev)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
struct atppc_softc *atppc = (struct atppc_softc *)dev;
|
2004-01-20 02:22:23 +03:00
|
|
|
int i;
|
|
|
|
int s;
|
|
|
|
u_int8_t r;
|
|
|
|
|
|
|
|
s = splatppc();
|
|
|
|
ATPPC_LOCK(atppc);
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
/*
|
|
|
|
* Only wait for FIFO to empty if mode is chipset is ECP-capable AND
|
2004-01-20 02:22:23 +03:00
|
|
|
* the mode is either ECP or Fast Centronics.
|
|
|
|
*/
|
|
|
|
r = atppc_r_ecr(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
r &= 0xe0;
|
2004-01-28 17:26:24 +03:00
|
|
|
if (!(atppc->sc_has & ATPPC_HAS_ECP) || ((r != ATPPC_ECR_ECP)
|
2004-01-20 02:22:23 +03:00
|
|
|
&& (r != ATPPC_ECR_FIFO))) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for FIFO to empty */
|
|
|
|
for (i = 0; i < ((MAXBUSYWAIT/hz) * 1000000); i += 100) {
|
|
|
|
r = atppc_r_ecr(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
if (r & ATPPC_FIFO_EMPTY) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
delay(100); /* Supposed to be a 100 usec delay */
|
|
|
|
}
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
ATPPC_DPRINTF(("%s: ECP sync failed, data still in FIFO.\n",
|
2004-01-20 02:22:23 +03:00
|
|
|
dev->dv_xname));
|
|
|
|
|
|
|
|
end:
|
|
|
|
ATPPC_UNLOCK(atppc);
|
|
|
|
splx(s);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Execute a microsequence to handle fast I/O operations. */
|
|
|
|
static int
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_exec_microseq(struct device *dev, struct ppbus_microseq **p_msq)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
struct atppc_softc *atppc = (struct atppc_softc *)dev;
|
|
|
|
struct ppbus_microseq *mi = *p_msq;
|
|
|
|
char cc, *p;
|
2004-01-20 02:22:23 +03:00
|
|
|
int i, iter, len;
|
|
|
|
int error;
|
|
|
|
int s;
|
|
|
|
register int reg;
|
|
|
|
register unsigned char mask;
|
|
|
|
register int accum = 0;
|
2004-01-28 17:26:24 +03:00
|
|
|
register char *ptr = NULL;
|
|
|
|
struct ppbus_microseq *stack = NULL;
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
s = splatppc();
|
|
|
|
ATPPC_LOCK(atppc);
|
|
|
|
|
|
|
|
/* microsequence registers are equivalent to PC-like port registers */
|
|
|
|
|
|
|
|
#define r_reg(register,atppc) bus_space_read_1((atppc)->sc_iot, \
|
|
|
|
(atppc)->sc_ioh, (register))
|
|
|
|
#define w_reg(register, atppc, byte) bus_space_write_1((atppc)->sc_iot, \
|
|
|
|
(atppc)->sc_ioh, (register), (byte))
|
|
|
|
|
|
|
|
/* Loop until microsequence execution finishes (ending op code) */
|
|
|
|
for (;;) {
|
2004-01-28 17:26:24 +03:00
|
|
|
switch (mi->opcode) {
|
2004-01-20 02:22:23 +03:00
|
|
|
case MS_OP_RSET:
|
|
|
|
cc = r_reg(mi->arg[0].i, atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
cc &= (char)mi->arg[2].i; /* clear mask */
|
|
|
|
cc |= (char)mi->arg[1].i; /* assert mask */
|
|
|
|
w_reg(mi->arg[0].i, atppc, cc);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
mi++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MS_OP_RASSERT_P:
|
|
|
|
reg = mi->arg[1].i;
|
|
|
|
ptr = atppc->sc_ptr;
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
if ((len = mi->arg[0].i) == MS_ACCUM) {
|
2004-01-20 02:22:23 +03:00
|
|
|
accum = atppc->sc_accum;
|
|
|
|
for (; accum; accum--) {
|
|
|
|
w_reg(reg, atppc, *ptr++);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
}
|
|
|
|
atppc->sc_accum = accum;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < len; i++) {
|
2004-01-20 02:22:23 +03:00
|
|
|
w_reg(reg, atppc, *ptr++);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
atppc->sc_ptr = ptr;
|
|
|
|
mi++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MS_OP_RFETCH_P:
|
|
|
|
reg = mi->arg[1].i;
|
|
|
|
mask = (char)mi->arg[2].i;
|
|
|
|
ptr = atppc->sc_ptr;
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
if ((len = mi->arg[0].i) == MS_ACCUM) {
|
2004-01-20 02:22:23 +03:00
|
|
|
accum = atppc->sc_accum;
|
|
|
|
for (; accum; accum--) {
|
|
|
|
*ptr++ = r_reg(reg, atppc) & mask;
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
}
|
|
|
|
atppc->sc_accum = accum;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < len; i++) {
|
2004-01-20 02:22:23 +03:00
|
|
|
*ptr++ = r_reg(reg, atppc) & mask;
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
atppc->sc_ptr = ptr;
|
|
|
|
mi++;
|
2004-01-28 17:26:24 +03:00
|
|
|
break;
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
case MS_OP_RFETCH:
|
2004-01-28 17:26:24 +03:00
|
|
|
*((char *)mi->arg[2].p) = r_reg(mi->arg[0].i, atppc) &
|
2004-01-20 02:22:23 +03:00
|
|
|
(char)mi->arg[1].i;
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
mi++;
|
2004-01-28 17:26:24 +03:00
|
|
|
break;
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
case MS_OP_RASSERT:
|
|
|
|
case MS_OP_DELAY:
|
|
|
|
/* let's suppose the next instr. is the same */
|
|
|
|
do {
|
2004-01-28 17:26:24 +03:00
|
|
|
for (;mi->opcode == MS_OP_RASSERT; mi++) {
|
|
|
|
w_reg(mi->arg[0].i, atppc,
|
2004-01-20 02:22:23 +03:00
|
|
|
(char)mi->arg[1].i);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
}
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
for (;mi->opcode == MS_OP_DELAY; mi++) {
|
2004-01-20 02:22:23 +03:00
|
|
|
delay(mi->arg[0].i);
|
|
|
|
}
|
2004-01-28 17:26:24 +03:00
|
|
|
} while (mi->opcode == MS_OP_RASSERT);
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MS_OP_ADELAY:
|
2004-01-28 17:26:24 +03:00
|
|
|
if (mi->arg[0].i) {
|
2004-01-20 02:22:23 +03:00
|
|
|
tsleep(atppc, PPBUSPRI, "atppcdelay",
|
|
|
|
mi->arg[0].i * (hz/1000));
|
|
|
|
}
|
|
|
|
mi++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MS_OP_TRIG:
|
|
|
|
reg = mi->arg[0].i;
|
|
|
|
iter = mi->arg[1].i;
|
|
|
|
p = (char *)mi->arg[2].p;
|
|
|
|
|
|
|
|
/* XXX delay limited to 255 us */
|
2004-01-28 17:26:24 +03:00
|
|
|
for (i = 0; i < iter; i++) {
|
2004-01-20 02:22:23 +03:00
|
|
|
w_reg(reg, atppc, *p++);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
delay((unsigned char)*p++);
|
|
|
|
}
|
|
|
|
|
|
|
|
mi++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MS_OP_SET:
|
|
|
|
atppc->sc_accum = mi->arg[0].i;
|
|
|
|
mi++;
|
2004-01-28 17:26:24 +03:00
|
|
|
break;
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
case MS_OP_DBRA:
|
2004-01-28 17:26:24 +03:00
|
|
|
if (--atppc->sc_accum > 0) {
|
2004-01-20 02:22:23 +03:00
|
|
|
mi += mi->arg[0].i;
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
mi++;
|
2004-01-28 17:26:24 +03:00
|
|
|
break;
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
case MS_OP_BRSET:
|
|
|
|
cc = atppc_r_str(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if ((cc & (char)mi->arg[0].i) == (char)mi->arg[0].i) {
|
2004-01-20 02:22:23 +03:00
|
|
|
mi += mi->arg[1].i;
|
|
|
|
}
|
|
|
|
mi++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MS_OP_BRCLEAR:
|
|
|
|
cc = atppc_r_str(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if ((cc & (char)mi->arg[0].i) == 0) {
|
|
|
|
mi += mi->arg[1].i;
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
|
|
|
mi++;
|
2004-01-28 17:26:24 +03:00
|
|
|
break;
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
case MS_OP_BRSTAT:
|
|
|
|
cc = atppc_r_str(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if ((cc & ((char)mi->arg[0].i | (char)mi->arg[1].i)) ==
|
2004-01-20 02:22:23 +03:00
|
|
|
(char)mi->arg[0].i) {
|
|
|
|
mi += mi->arg[2].i;
|
|
|
|
}
|
|
|
|
mi++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MS_OP_C_CALL:
|
|
|
|
/*
|
|
|
|
* If the C call returns !0 then end the microseq.
|
|
|
|
* The current state of ptr is passed to the C function
|
|
|
|
*/
|
2004-01-28 17:26:24 +03:00
|
|
|
if ((error = mi->arg[0].f(mi->arg[1].p,
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_ptr))) {
|
|
|
|
ATPPC_UNLOCK(atppc);
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
mi++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MS_OP_PTR:
|
|
|
|
atppc->sc_ptr = (char *)mi->arg[0].p;
|
|
|
|
mi++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MS_OP_CALL:
|
|
|
|
if (stack) {
|
2004-01-28 17:26:24 +03:00
|
|
|
panic("%s - %s: too much calls", dev->dv_xname,
|
2004-01-20 02:22:23 +03:00
|
|
|
__func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mi->arg[0].p) {
|
|
|
|
/* store state of the actual microsequence */
|
|
|
|
stack = mi;
|
|
|
|
|
|
|
|
/* jump to the new microsequence */
|
|
|
|
mi = (struct ppbus_microseq *)mi->arg[0].p;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
mi++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MS_OP_SUBRET:
|
|
|
|
/* retrieve microseq and pc state before the call */
|
|
|
|
mi = stack;
|
|
|
|
|
|
|
|
/* reset the stack */
|
|
|
|
stack = 0;
|
|
|
|
|
|
|
|
/* XXX return code */
|
|
|
|
|
|
|
|
mi++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MS_OP_PUT:
|
|
|
|
case MS_OP_GET:
|
|
|
|
case MS_OP_RET:
|
2004-01-28 17:26:24 +03:00
|
|
|
/*
|
2004-01-20 02:22:23 +03:00
|
|
|
* Can't return to atppc level during the execution
|
|
|
|
* of a submicrosequence.
|
|
|
|
*/
|
|
|
|
if (stack) {
|
2004-01-28 17:26:24 +03:00
|
|
|
panic("%s: cannot return to atppc level",
|
2004-01-20 02:22:23 +03:00
|
|
|
__func__);
|
|
|
|
}
|
|
|
|
/* update pc for atppc level of execution */
|
|
|
|
*p_msq = mi;
|
|
|
|
|
|
|
|
ATPPC_UNLOCK(atppc);
|
|
|
|
splx(s);
|
|
|
|
return (0);
|
|
|
|
break;
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
default:
|
2004-01-20 02:22:23 +03:00
|
|
|
panic("%s: unknown microsequence "
|
2004-01-28 17:26:24 +03:00
|
|
|
"opcode 0x%x", __func__, mi->opcode);
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Should not be reached! */
|
|
|
|
#ifdef ATPPC_DEBUG
|
|
|
|
panic("%s: unexpected code reached!\n", __func__);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* General I/O routine */
|
|
|
|
static u_int8_t
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_io(struct device *dev, int iop, u_char *addr, int cnt, u_char byte)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
struct atppc_softc *atppc = (struct atppc_softc *)dev;
|
2004-01-20 02:22:23 +03:00
|
|
|
u_int8_t val = 0;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splatppc();
|
|
|
|
ATPPC_LOCK(atppc);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
switch (iop) {
|
|
|
|
case PPBUS_OUTSB_EPP:
|
2004-01-28 17:26:24 +03:00
|
|
|
bus_space_write_multi_1(atppc->sc_iot, atppc->sc_ioh,
|
2004-01-20 02:22:23 +03:00
|
|
|
ATPPC_EPP_DATA, addr, cnt);
|
|
|
|
break;
|
|
|
|
case PPBUS_OUTSW_EPP:
|
2004-01-28 17:26:24 +03:00
|
|
|
bus_space_write_multi_2(atppc->sc_iot, atppc->sc_ioh,
|
2004-01-20 02:22:23 +03:00
|
|
|
ATPPC_EPP_DATA, (u_int16_t *)addr, cnt);
|
|
|
|
break;
|
|
|
|
case PPBUS_OUTSL_EPP:
|
2004-01-28 17:26:24 +03:00
|
|
|
bus_space_write_multi_4(atppc->sc_iot, atppc->sc_ioh,
|
2004-01-20 02:22:23 +03:00
|
|
|
ATPPC_EPP_DATA, (u_int32_t *)addr, cnt);
|
|
|
|
break;
|
|
|
|
case PPBUS_INSB_EPP:
|
2004-01-28 17:26:24 +03:00
|
|
|
bus_space_read_multi_1(atppc->sc_iot, atppc->sc_ioh,
|
2004-01-20 02:22:23 +03:00
|
|
|
ATPPC_EPP_DATA, addr, cnt);
|
|
|
|
break;
|
|
|
|
case PPBUS_INSW_EPP:
|
2004-01-28 17:26:24 +03:00
|
|
|
bus_space_read_multi_2(atppc->sc_iot, atppc->sc_ioh,
|
2004-01-20 02:22:23 +03:00
|
|
|
ATPPC_EPP_DATA, (u_int16_t *)addr, cnt);
|
|
|
|
break;
|
|
|
|
case PPBUS_INSL_EPP:
|
2004-01-28 17:26:24 +03:00
|
|
|
bus_space_read_multi_4(atppc->sc_iot, atppc->sc_ioh,
|
2004-01-20 02:22:23 +03:00
|
|
|
ATPPC_EPP_DATA, (u_int32_t *)addr, cnt);
|
|
|
|
break;
|
|
|
|
case PPBUS_RDTR:
|
|
|
|
val = (atppc_r_dtr(atppc));
|
|
|
|
break;
|
|
|
|
case PPBUS_RSTR:
|
|
|
|
val = (atppc_r_str(atppc));
|
|
|
|
break;
|
|
|
|
case PPBUS_RCTR:
|
|
|
|
val = (atppc_r_ctr(atppc));
|
|
|
|
break;
|
|
|
|
case PPBUS_REPP_A:
|
|
|
|
val = (atppc_r_eppA(atppc));
|
|
|
|
break;
|
|
|
|
case PPBUS_REPP_D:
|
|
|
|
val = (atppc_r_eppD(atppc));
|
|
|
|
break;
|
|
|
|
case PPBUS_RECR:
|
|
|
|
val = (atppc_r_ecr(atppc));
|
|
|
|
break;
|
|
|
|
case PPBUS_RFIFO:
|
|
|
|
val = (atppc_r_fifo(atppc));
|
|
|
|
break;
|
|
|
|
case PPBUS_WDTR:
|
|
|
|
atppc_w_dtr(atppc, byte);
|
|
|
|
break;
|
|
|
|
case PPBUS_WSTR:
|
|
|
|
atppc_w_str(atppc, byte);
|
|
|
|
break;
|
|
|
|
case PPBUS_WCTR:
|
|
|
|
atppc_w_ctr(atppc, byte);
|
|
|
|
break;
|
|
|
|
case PPBUS_WEPP_A:
|
|
|
|
atppc_w_eppA(atppc, byte);
|
|
|
|
break;
|
|
|
|
case PPBUS_WEPP_D:
|
|
|
|
atppc_w_eppD(atppc, byte);
|
|
|
|
break;
|
|
|
|
case PPBUS_WECR:
|
|
|
|
atppc_w_ecr(atppc, byte);
|
|
|
|
break;
|
|
|
|
case PPBUS_WFIFO:
|
|
|
|
atppc_w_fifo(atppc, byte);
|
|
|
|
break;
|
|
|
|
default:
|
2004-01-28 17:26:24 +03:00
|
|
|
panic("%s(%s): unknown I/O operation", dev->dv_xname,
|
2004-01-20 02:22:23 +03:00
|
|
|
__func__);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
atppc_barrier(atppc);
|
|
|
|
|
|
|
|
ATPPC_UNLOCK(atppc);
|
|
|
|
splx(s);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read "instance variables" of atppc device */
|
|
|
|
static int
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_read_ivar(struct device *dev, int index, unsigned int *val)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
struct atppc_softc *atppc = (struct atppc_softc *)dev;
|
2004-01-20 02:22:23 +03:00
|
|
|
int rval = 0;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splatppc();
|
|
|
|
ATPPC_LOCK(atppc);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
switch(index) {
|
|
|
|
case PPBUS_IVAR_EPP_PROTO:
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_epp == ATPPC_EPP_1_9)
|
2004-01-20 02:22:23 +03:00
|
|
|
*val = PPBUS_EPP_1_9;
|
2004-01-28 17:26:24 +03:00
|
|
|
else if (atppc->sc_epp == ATPPC_EPP_1_7)
|
2004-01-20 02:22:23 +03:00
|
|
|
*val = PPBUS_EPP_1_7;
|
2004-02-03 21:54:59 +03:00
|
|
|
/* XXX what if not using EPP ? */
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PPBUS_IVAR_INTR:
|
2004-02-03 21:54:59 +03:00
|
|
|
*val = ((atppc->sc_use & ATPPC_USE_INTR) != 0);
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PPBUS_IVAR_DMA:
|
2004-02-03 21:54:59 +03:00
|
|
|
*val = ((atppc->sc_use & ATPPC_USE_DMA) != 0);
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rval = ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
ATPPC_UNLOCK(atppc);
|
|
|
|
splx(s);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write "instance varaibles" of atppc device */
|
|
|
|
static int
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_write_ivar(struct device *dev, int index, unsigned int *val)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
struct atppc_softc *atppc = (struct atppc_softc *)dev;
|
2004-01-20 02:22:23 +03:00
|
|
|
int rval = 0;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splatppc();
|
|
|
|
ATPPC_LOCK(atppc);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
switch(index) {
|
|
|
|
case PPBUS_IVAR_EPP_PROTO:
|
2004-01-28 17:26:24 +03:00
|
|
|
if (*val == PPBUS_EPP_1_9 || *val == PPBUS_EPP_1_7)
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_epp = *val;
|
|
|
|
else
|
|
|
|
rval = EINVAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPBUS_IVAR_INTR:
|
2004-01-28 17:26:24 +03:00
|
|
|
if (*val == 0)
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_use &= ~ATPPC_USE_INTR;
|
2004-01-28 17:26:24 +03:00
|
|
|
else if (atppc->sc_has & ATPPC_HAS_INTR)
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_use |= ATPPC_USE_INTR;
|
|
|
|
else
|
2004-01-28 17:26:24 +03:00
|
|
|
rval = ENODEV;
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PPBUS_IVAR_DMA:
|
2004-01-28 17:26:24 +03:00
|
|
|
if (*val == 0)
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_use &= ~ATPPC_USE_DMA;
|
2004-01-28 17:26:24 +03:00
|
|
|
else if (atppc->sc_has & ATPPC_HAS_DMA)
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_use |= ATPPC_USE_DMA;
|
|
|
|
else
|
2004-01-28 17:26:24 +03:00
|
|
|
rval = ENODEV;
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rval = ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
ATPPC_UNLOCK(atppc);
|
|
|
|
splx(s);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a handler routine to be called by the interrupt handler */
|
2004-01-28 17:26:24 +03:00
|
|
|
static int
|
|
|
|
atppc_add_handler(struct device *dev, void (*handler)(void *), void *arg)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
struct atppc_softc *atppc = (struct atppc_softc *)dev;
|
|
|
|
struct atppc_handler_node *callback;
|
2004-01-20 02:22:23 +03:00
|
|
|
int rval = 0;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splatppc();
|
|
|
|
ATPPC_LOCK(atppc);
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
if (handler == NULL) {
|
|
|
|
ATPPC_DPRINTF(("%s(%s): attempt to register NULL handler.\n",
|
2004-01-20 02:22:23 +03:00
|
|
|
__func__, dev->dv_xname));
|
|
|
|
rval = EINVAL;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
|
|
|
callback = malloc(sizeof(struct atppc_handler_node), M_DEVBUF,
|
2004-01-20 02:22:23 +03:00
|
|
|
M_NOWAIT);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (callback) {
|
2004-01-20 02:22:23 +03:00
|
|
|
callback->func = handler;
|
|
|
|
callback->arg = arg;
|
2004-01-28 17:26:24 +03:00
|
|
|
SLIST_INSERT_HEAD(&(atppc->sc_handler_listhead),
|
2004-01-20 02:22:23 +03:00
|
|
|
callback, entries);
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
rval = ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ATPPC_UNLOCK(atppc);
|
|
|
|
splx(s);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove a handler added by atppc_add_handler() */
|
2004-01-28 17:26:24 +03:00
|
|
|
static int
|
|
|
|
atppc_remove_handler(struct device *dev, void (*handler)(void *))
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
struct atppc_softc *atppc = (struct atppc_softc *)dev;
|
|
|
|
struct atppc_handler_node *callback;
|
2004-01-20 02:22:23 +03:00
|
|
|
int rval = EINVAL;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splatppc();
|
|
|
|
ATPPC_LOCK(atppc);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
if (SLIST_EMPTY(&(atppc->sc_handler_listhead)))
|
2004-01-20 02:22:23 +03:00
|
|
|
panic("%s(%s): attempt to remove handler from empty list.\n",
|
|
|
|
__func__, dev->dv_xname);
|
|
|
|
|
|
|
|
/* Search list for handler */
|
|
|
|
SLIST_FOREACH(callback, &(atppc->sc_handler_listhead), entries) {
|
2004-01-28 17:26:24 +03:00
|
|
|
if (callback->func == handler) {
|
|
|
|
SLIST_REMOVE(&(atppc->sc_handler_listhead), callback,
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_handler_node, entries);
|
|
|
|
free(callback, M_DEVBUF);
|
|
|
|
rval = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ATPPC_UNLOCK(atppc);
|
|
|
|
splx(s);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Utility functions */
|
|
|
|
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
/*
|
|
|
|
* Functions that read bytes from port into buffer: called from interrupt
|
|
|
|
* handler depending on current chipset mode and cause of interrupt. Return
|
2004-01-20 02:22:23 +03:00
|
|
|
* value: number of bytes moved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Only the lower 4 bits of the final value are valid */
|
|
|
|
#define nibble2char(s) ((((s) & ~nACK) >> 3) | (~(s) & nBUSY) >> 4)
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
/* Read bytes in nibble mode */
|
|
|
|
static void
|
|
|
|
atppc_nibble_read(struct atppc_softc *atppc)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u_int8_t nibble[2];
|
|
|
|
u_int8_t ctr;
|
|
|
|
u_int8_t str;
|
|
|
|
|
|
|
|
/* Enable interrupts if needed */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_use & ATPPC_USE_INTR) {
|
2004-01-20 02:22:23 +03:00
|
|
|
ctr = atppc_r_ctr(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (!(ctr & IRQENABLE)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
ctr |= IRQENABLE;
|
|
|
|
atppc_w_ctr(atppc, ctr);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
}
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
while (atppc->sc_inbstart < (atppc->sc_inb + atppc->sc_inb_nbytes)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Check if device has data to send in idle phase */
|
|
|
|
str = atppc_r_str(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (str & nDATAVAIL) {
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Nibble-mode handshake transfer */
|
2004-01-28 17:26:24 +03:00
|
|
|
for (i = 0; i < 2; i++) {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Event 7 - ready to take data (HOSTBUSY low) */
|
|
|
|
ctr = atppc_r_ctr(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
ctr |= HOSTBUSY;
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_w_ctr(atppc, ctr);
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
/* Event 8 - peripheral writes the first nibble */
|
|
|
|
|
|
|
|
/* Event 9 - peripheral set nAck low */
|
|
|
|
atppc->sc_inerr = atppc_poll_str(atppc, 0, PTRCLK);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_inerr)
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* read nibble */
|
|
|
|
nibble[i] = atppc_r_str(atppc);
|
|
|
|
|
|
|
|
/* Event 10 - ack, nibble received */
|
|
|
|
ctr &= ~HOSTBUSY;
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_w_ctr(atppc, ctr);
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
/* Event 11 - wait ack from peripherial */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_use & ATPPC_USE_INTR)
|
|
|
|
atppc->sc_inerr = atppc_wait_interrupt(atppc,
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_inb, ATPPC_IRQ_nACK);
|
|
|
|
else
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc->sc_inerr = atppc_poll_str(atppc, PTRCLK,
|
2004-01-20 02:22:23 +03:00
|
|
|
PTRCLK);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_inerr)
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store byte transfered */
|
|
|
|
*(atppc->sc_inbstart) = ((nibble2char(nibble[1]) << 4) & 0xf0) |
|
|
|
|
(nibble2char(nibble[0]) & 0x0f);
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc->sc_inbstart++;
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read bytes in bidirectional mode */
|
2004-01-28 17:26:24 +03:00
|
|
|
static void
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_byte_read(struct atppc_softc * const atppc)
|
|
|
|
{
|
|
|
|
u_int8_t ctr;
|
|
|
|
u_int8_t str;
|
|
|
|
|
|
|
|
/* Check direction bit */
|
2004-01-28 17:26:24 +03:00
|
|
|
ctr = atppc_r_ctr(atppc);
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (!(ctr & PCD)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
ATPPC_DPRINTF(("%s: byte-mode read attempted without direction "
|
|
|
|
"bit set.", atppc->sc_dev.dv_xname));
|
|
|
|
atppc->sc_inerr = ENODEV;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Enable interrupts if needed */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_use & ATPPC_USE_INTR) {
|
|
|
|
if (!(ctr & IRQENABLE)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
ctr |= IRQENABLE;
|
|
|
|
atppc_w_ctr(atppc, ctr);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
}
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Byte-mode handshake transfer */
|
2004-01-28 17:26:24 +03:00
|
|
|
while (atppc->sc_inbstart < (atppc->sc_inb + atppc->sc_inb_nbytes)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Check if device has data to send */
|
|
|
|
str = atppc_r_str(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (str & nDATAVAIL) {
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Event 7 - ready to take data (nAUTO low) */
|
|
|
|
ctr |= HOSTBUSY;
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_w_ctr(atppc, ctr);
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
/* Event 9 - peripheral set nAck low */
|
|
|
|
atppc->sc_inerr = atppc_poll_str(atppc, 0, PTRCLK);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_inerr)
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Store byte transfered */
|
|
|
|
*(atppc->sc_inbstart) = atppc_r_dtr(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
|
|
|
|
/* Event 10 - data received, can't accept more */
|
|
|
|
ctr &= ~HOSTBUSY;
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_w_ctr(atppc, ctr);
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
/* Event 11 - peripheral ack */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_use & ATPPC_USE_INTR)
|
|
|
|
atppc->sc_inerr = atppc_wait_interrupt(atppc,
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_inb, ATPPC_IRQ_nACK);
|
|
|
|
else
|
|
|
|
atppc->sc_inerr = atppc_poll_str(atppc, PTRCLK, PTRCLK);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_inerr)
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Event 16 - strobe */
|
|
|
|
str |= HOSTCLK;
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_w_str(atppc, str);
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
DELAY(1);
|
|
|
|
str &= ~HOSTCLK;
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_w_str(atppc, str);
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
/* Update counter */
|
|
|
|
atppc->sc_inbstart++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read bytes in EPP mode */
|
2004-01-28 17:26:24 +03:00
|
|
|
static void
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_epp_read(struct atppc_softc * atppc)
|
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_epp == ATPPC_EPP_1_9) {
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
|
|
|
uint8_t str;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
atppc_reset_epp_timeout((struct device *)atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
for (i = 0; i < atppc->sc_inb_nbytes; i++) {
|
2004-01-20 02:22:23 +03:00
|
|
|
*(atppc->sc_inbstart) = atppc_r_eppD(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
str = atppc_r_str(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (str & TIMEOUT) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_inerr = EIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
atppc->sc_inbstart++;
|
|
|
|
}
|
|
|
|
}
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Read data block from EPP data register */
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_r_eppD_multi(atppc, atppc->sc_inbstart,
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_inb_nbytes);
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
/* Update buffer position, byte count and counter */
|
|
|
|
atppc->sc_inbstart += atppc->sc_inb_nbytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
/* Read bytes in ECP mode */
|
|
|
|
static void
|
|
|
|
atppc_ecp_read(struct atppc_softc *atppc)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
|
|
|
u_int8_t ecr;
|
|
|
|
u_int8_t ctr;
|
|
|
|
u_int8_t str;
|
|
|
|
const unsigned char ctr_sav = atppc_r_ctr(atppc);
|
|
|
|
const unsigned char ecr_sav = atppc_r_ecr(atppc);
|
|
|
|
unsigned int worklen;
|
|
|
|
|
|
|
|
/* Check direction bit */
|
2004-01-28 17:26:24 +03:00
|
|
|
ctr = ctr_sav;
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (!(ctr & PCD)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
ATPPC_DPRINTF(("%s: ecp-mode read attempted without direction "
|
|
|
|
"bit set.", atppc->sc_dev.dv_xname));
|
|
|
|
atppc->sc_inerr = ENODEV;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear device request if any */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_use & ATPPC_USE_INTR)
|
|
|
|
atppc->sc_irqstat &= ~ATPPC_IRQ_nFAULT;
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
while (atppc->sc_inbstart < (atppc->sc_inb + atppc->sc_inb_nbytes)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
ecr = atppc_r_ecr(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (ecr & ATPPC_FIFO_EMPTY) {
|
|
|
|
/* Check for invalid state */
|
|
|
|
if (ecr & ATPPC_FIFO_FULL) {
|
2006-05-29 19:17:29 +04:00
|
|
|
atppc_ecp_read_error(atppc);
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Check if device has data to send */
|
|
|
|
str = atppc_r_str(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (str & nDATAVAIL) {
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_use & ATPPC_USE_INTR) {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Enable interrupts */
|
|
|
|
ecr &= ~ATPPC_SERVICE_INTR;
|
|
|
|
atppc_w_ecr(atppc, ecr);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
/* Wait for FIFO to fill */
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc->sc_inerr = atppc_wait_interrupt(atppc,
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_inb, ATPPC_IRQ_FIFO);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_inerr)
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
DELAY(1);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2004-01-28 17:26:24 +03:00
|
|
|
else if (ecr & ATPPC_FIFO_FULL) {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Transfer sc_fifo bytes */
|
|
|
|
worklen = atppc->sc_fifo;
|
|
|
|
}
|
2004-01-28 17:26:24 +03:00
|
|
|
else if (ecr & ATPPC_SERVICE_INTR) {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Transfer sc_rthr bytes */
|
|
|
|
worklen = atppc->sc_rthr;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* At least one byte is in the FIFO */
|
|
|
|
worklen = 1;
|
|
|
|
}
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
if ((atppc->sc_use & ATPPC_USE_INTR) &&
|
2004-01-20 02:22:23 +03:00
|
|
|
(atppc->sc_use & ATPPC_USE_DMA)) {
|
|
|
|
|
|
|
|
atppc_ecp_read_dma(atppc, &worklen, ecr);
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_ecp_read_pio(atppc, &worklen, ecr);
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_inerr) {
|
2006-05-29 19:17:29 +04:00
|
|
|
atppc_ecp_read_error(atppc);
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update counter */
|
|
|
|
atppc->sc_inbstart += worklen;
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
atppc_w_ctr(atppc, ctr_sav);
|
|
|
|
atppc_w_ecr(atppc, ecr_sav);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
}
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
/* Read bytes in ECP mode using DMA transfers */
|
|
|
|
static void
|
|
|
|
atppc_ecp_read_dma(struct atppc_softc *atppc, unsigned int *length,
|
2004-01-20 02:22:23 +03:00
|
|
|
unsigned char ecr)
|
|
|
|
{
|
|
|
|
/* Limit transfer to maximum DMA size and start it */
|
|
|
|
*length = min(*length, atppc->sc_dma_maxsize);
|
|
|
|
atppc->sc_dmastat = ATPPC_DMA_INIT;
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc->sc_dma_start(atppc, atppc->sc_inbstart, *length,
|
2004-01-20 02:22:23 +03:00
|
|
|
ATPPC_DMA_MODE_READ);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_dmastat = ATPPC_DMA_STARTED;
|
|
|
|
|
|
|
|
/* Enable interrupts, DMA */
|
|
|
|
ecr &= ~ATPPC_SERVICE_INTR;
|
|
|
|
ecr |= ATPPC_ENABLE_DMA;
|
|
|
|
atppc_w_ecr(atppc, ecr);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
/* Wait for DMA completion */
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc->sc_inerr = atppc_wait_interrupt(atppc, atppc->sc_inb,
|
2004-01-20 02:22:23 +03:00
|
|
|
ATPPC_IRQ_DMA);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_inerr)
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Get register value recorded by interrupt handler */
|
2004-01-28 17:26:24 +03:00
|
|
|
ecr = atppc->sc_ecr_intr;
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Clear DMA programming */
|
|
|
|
atppc->sc_dma_finish(atppc);
|
|
|
|
atppc->sc_dmastat = ATPPC_DMA_COMPLETE;
|
|
|
|
/* Disable DMA */
|
|
|
|
ecr &= ~ATPPC_ENABLE_DMA;
|
|
|
|
atppc_w_ecr(atppc, ecr);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
}
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
/* Read bytes in ECP mode using PIO transfers */
|
|
|
|
static void
|
|
|
|
atppc_ecp_read_pio(struct atppc_softc *atppc, unsigned int *length,
|
2004-01-20 02:22:23 +03:00
|
|
|
unsigned char ecr)
|
|
|
|
{
|
|
|
|
/* Disable DMA */
|
|
|
|
ecr &= ~ATPPC_ENABLE_DMA;
|
|
|
|
atppc_w_ecr(atppc, ecr);
|
|
|
|
atppc_barrier_w(atppc);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Read from FIFO */
|
|
|
|
atppc_r_fifo_multi(atppc, atppc->sc_inbstart, *length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle errors for ECP reads */
|
2004-01-28 17:26:24 +03:00
|
|
|
static void
|
2006-05-29 19:17:29 +04:00
|
|
|
atppc_ecp_read_error(struct atppc_softc *atppc)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
|
|
|
unsigned char ecr = atppc_r_ecr(atppc);
|
|
|
|
|
|
|
|
/* Abort DMA if not finished */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_dmastat == ATPPC_DMA_STARTED) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_dma_abort(atppc);
|
|
|
|
ATPPC_DPRINTF(("%s: DMA interrupted.\n", __func__));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for invalid states */
|
2004-01-28 17:26:24 +03:00
|
|
|
if ((ecr & ATPPC_FIFO_EMPTY) && (ecr & ATPPC_FIFO_FULL)) {
|
|
|
|
ATPPC_DPRINTF(("%s: FIFO full+empty bits set.\n", __func__));
|
2004-01-20 02:22:23 +03:00
|
|
|
ATPPC_DPRINTF(("%s: reseting FIFO.\n", __func__));
|
|
|
|
atppc_w_ecr(atppc, ATPPC_ECR_PS2);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
/*
|
|
|
|
* Functions that write bytes to port from buffer: called from atppc_write()
|
2004-01-20 02:22:23 +03:00
|
|
|
* function depending on current chipset mode. Returns number of bytes moved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Write bytes in std/bidirectional mode */
|
2004-01-28 17:26:24 +03:00
|
|
|
static void
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_std_write(struct atppc_softc * const atppc)
|
|
|
|
{
|
|
|
|
unsigned int timecount;
|
|
|
|
unsigned char ctr;
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
ctr = atppc_r_ctr(atppc);
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
/* Enable interrupts if needed */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_use & ATPPC_USE_INTR) {
|
|
|
|
if (!(ctr & IRQENABLE)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
ctr |= IRQENABLE;
|
|
|
|
atppc_w_ctr(atppc, ctr);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
while (atppc->sc_outbstart < (atppc->sc_outb + atppc->sc_outb_nbytes)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Wait for peripheral to become ready for MAXBUSYWAIT */
|
|
|
|
atppc->sc_outerr = atppc_poll_str(atppc, SPP_READY, SPP_MASK);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_outerr)
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Put data in data register */
|
|
|
|
atppc_w_dtr(atppc, *(atppc->sc_outbstart));
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
DELAY(1);
|
|
|
|
|
|
|
|
/* Pulse strobe to indicate valid data on lines */
|
|
|
|
ctr |= STROBE;
|
|
|
|
atppc_w_ctr(atppc, ctr);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
DELAY(1);
|
|
|
|
ctr &= ~STROBE;
|
|
|
|
atppc_w_ctr(atppc, ctr);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
/* Wait for nACK for MAXBUSYWAIT */
|
|
|
|
timecount = 0;
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_use & ATPPC_USE_INTR) {
|
|
|
|
atppc->sc_outerr = atppc_wait_interrupt(atppc,
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_outb, ATPPC_IRQ_nACK);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_outerr)
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Try to catch the pulsed acknowledgement */
|
|
|
|
atppc->sc_outerr = atppc_poll_str(atppc, 0, nACK);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_outerr)
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
|
|
|
atppc->sc_outerr = atppc_poll_str(atppc, nACK, nACK);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_outerr)
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update buffer position, byte count and counter */
|
|
|
|
atppc->sc_outbstart++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Write bytes in EPP mode */
|
2004-01-28 17:26:24 +03:00
|
|
|
static void
|
|
|
|
atppc_epp_write(struct atppc_softc *atppc)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_epp == ATPPC_EPP_1_9) {
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
|
|
|
uint8_t str;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
atppc_reset_epp_timeout((struct device *)atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
for (i = 0; i < atppc->sc_outb_nbytes; i++) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_w_eppD(atppc, *(atppc->sc_outbstart));
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
str = atppc_r_str(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (str & TIMEOUT) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_outerr = EIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
atppc->sc_outbstart++;
|
|
|
|
}
|
|
|
|
}
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Write data block to EPP data register */
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_w_eppD_multi(atppc, atppc->sc_outbstart,
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_outb_nbytes);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
/* Update buffer position, byte count and counter */
|
|
|
|
atppc->sc_outbstart += atppc->sc_outb_nbytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Write bytes in ECP/Fast Centronics mode */
|
2004-01-28 17:26:24 +03:00
|
|
|
static void
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_fifo_write(struct atppc_softc * const atppc)
|
|
|
|
{
|
|
|
|
unsigned char ctr;
|
|
|
|
unsigned char ecr;
|
|
|
|
const unsigned char ctr_sav = atppc_r_ctr(atppc);
|
|
|
|
const unsigned char ecr_sav = atppc_r_ecr(atppc);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
ctr = ctr_sav;
|
|
|
|
ecr = ecr_sav;
|
|
|
|
atppc_barrier_r(atppc);
|
|
|
|
|
|
|
|
/* Reset and flush FIFO */
|
|
|
|
atppc_w_ecr(atppc, ATPPC_ECR_PS2);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
/* Disable nAck interrupts and initialize port bits */
|
|
|
|
ctr &= ~(IRQENABLE | STROBE | AUTOFEED);
|
|
|
|
atppc_w_ctr(atppc, ctr);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
/* Restore mode */
|
|
|
|
atppc_w_ecr(atppc, ecr);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
/* DMA or Programmed IO */
|
2004-01-28 17:26:24 +03:00
|
|
|
if ((atppc->sc_use & ATPPC_USE_DMA) &&
|
|
|
|
(atppc->sc_use & ATPPC_USE_INTR)) {
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_fifo_write_dma(atppc, ecr, ctr);
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_fifo_write_pio(atppc, ecr, ctr);
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Restore original register values */
|
|
|
|
atppc_w_ctr(atppc, ctr_sav);
|
|
|
|
atppc_w_ecr(atppc, ecr_sav);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
}
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
static void
|
|
|
|
atppc_fifo_write_dma(struct atppc_softc * const atppc, unsigned char ecr,
|
2004-01-20 02:22:23 +03:00
|
|
|
unsigned char ctr)
|
|
|
|
{
|
|
|
|
unsigned int len;
|
|
|
|
unsigned int worklen;
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
for (len = (atppc->sc_outb + atppc->sc_outb_nbytes) -
|
|
|
|
atppc->sc_outbstart; len > 0; len = (atppc->sc_outb +
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_outb_nbytes) - atppc->sc_outbstart) {
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Wait for device to become ready */
|
|
|
|
atppc->sc_outerr = atppc_poll_str(atppc, SPP_READY, SPP_MASK);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_outerr)
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Reset chipset for next DMA transfer */
|
|
|
|
atppc_w_ecr(atppc, ATPPC_ECR_PS2);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
atppc_w_ecr(atppc, ecr);
|
|
|
|
atppc_barrier_w(atppc);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Limit transfer to maximum DMA size and start it */
|
2004-01-28 23:08:35 +03:00
|
|
|
worklen = min(len, atppc->sc_dma_maxsize);
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_dmastat = ATPPC_DMA_INIT;
|
|
|
|
atppc->sc_dma_start(atppc, atppc->sc_outbstart,
|
|
|
|
worklen, ATPPC_DMA_MODE_WRITE);
|
|
|
|
atppc->sc_dmastat = ATPPC_DMA_STARTED;
|
|
|
|
|
|
|
|
/* Enable interrupts, DMA */
|
|
|
|
ecr &= ~ATPPC_SERVICE_INTR;
|
|
|
|
ecr |= ATPPC_ENABLE_DMA;
|
|
|
|
atppc_w_ecr(atppc, ecr);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
/* Wait for DMA completion */
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc->sc_outerr = atppc_wait_interrupt(atppc, atppc->sc_outb,
|
2004-01-20 02:22:23 +03:00
|
|
|
ATPPC_IRQ_DMA);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_outerr) {
|
|
|
|
atppc_fifo_write_error(atppc, worklen);
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Get register value recorded by interrupt handler */
|
2004-01-28 17:26:24 +03:00
|
|
|
ecr = atppc->sc_ecr_intr;
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Clear DMA programming */
|
|
|
|
atppc->sc_dma_finish(atppc);
|
|
|
|
atppc->sc_dmastat = ATPPC_DMA_COMPLETE;
|
|
|
|
/* Disable DMA */
|
|
|
|
ecr &= ~ATPPC_ENABLE_DMA;
|
|
|
|
atppc_w_ecr(atppc, ecr);
|
|
|
|
atppc_barrier_w(atppc);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Wait for FIFO to empty */
|
2004-01-28 17:26:24 +03:00
|
|
|
for (;;) {
|
|
|
|
if (ecr & ATPPC_FIFO_EMPTY) {
|
|
|
|
if (ecr & ATPPC_FIFO_FULL) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_outerr = EIO;
|
|
|
|
atppc_fifo_write_error(atppc, worklen);
|
|
|
|
return;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Enable service interrupt */
|
|
|
|
ecr &= ~ATPPC_SERVICE_INTR;
|
|
|
|
atppc_w_ecr(atppc, ecr);
|
|
|
|
atppc_barrier_w(atppc);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc->sc_outerr = atppc_wait_interrupt(atppc,
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_outb, ATPPC_IRQ_FIFO);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_outerr) {
|
|
|
|
atppc_fifo_write_error(atppc, worklen);
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Get register value recorded by interrupt handler */
|
2004-01-28 17:26:24 +03:00
|
|
|
ecr = atppc->sc_ecr_intr;
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update pointer */
|
|
|
|
atppc->sc_outbstart += worklen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
static void
|
|
|
|
atppc_fifo_write_pio(struct atppc_softc * const atppc, unsigned char ecr,
|
2004-01-20 02:22:23 +03:00
|
|
|
unsigned char ctr)
|
|
|
|
{
|
|
|
|
unsigned int len;
|
|
|
|
unsigned int worklen;
|
|
|
|
unsigned int timecount;
|
|
|
|
|
|
|
|
/* Disable DMA */
|
|
|
|
ecr &= ~ATPPC_ENABLE_DMA;
|
|
|
|
atppc_w_ecr(atppc, ecr);
|
|
|
|
atppc_barrier_w(atppc);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
for (len = (atppc->sc_outb + atppc->sc_outb_nbytes) -
|
|
|
|
atppc->sc_outbstart; len > 0; len = (atppc->sc_outb +
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_outb_nbytes) - atppc->sc_outbstart) {
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Wait for device to become ready */
|
|
|
|
atppc->sc_outerr = atppc_poll_str(atppc, SPP_READY, SPP_MASK);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_outerr)
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Limit transfer to minimum of space in FIFO and buffer */
|
|
|
|
worklen = min(len, atppc->sc_fifo);
|
|
|
|
|
|
|
|
/* Write to FIFO */
|
|
|
|
atppc_w_fifo_multi(atppc, atppc->sc_outbstart, worklen);
|
|
|
|
|
|
|
|
timecount = 0;
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_use & ATPPC_USE_INTR) {
|
2004-01-20 02:22:23 +03:00
|
|
|
ecr = atppc_r_ecr(atppc);
|
|
|
|
atppc_barrier_w(atppc);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Wait for interrupt */
|
2004-01-28 17:26:24 +03:00
|
|
|
for (;;) {
|
|
|
|
if (ecr & ATPPC_FIFO_EMPTY) {
|
|
|
|
if (ecr & ATPPC_FIFO_FULL) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_outerr = EIO;
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_fifo_write_error(atppc,
|
2004-01-20 02:22:23 +03:00
|
|
|
worklen);
|
|
|
|
return;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable service interrupt */
|
|
|
|
ecr &= ~ATPPC_SERVICE_INTR;
|
|
|
|
atppc_w_ecr(atppc, ecr);
|
|
|
|
atppc_barrier_w(atppc);
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc->sc_outerr = atppc_wait_interrupt(atppc,
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_outb, ATPPC_IRQ_FIFO);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_outerr) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_fifo_write_error(atppc, worklen);
|
|
|
|
return;
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Get ECR value saved by interrupt handler */
|
2004-01-28 17:26:24 +03:00
|
|
|
ecr = atppc->sc_ecr_intr;
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
|
|
|
for (; timecount < ((MAXBUSYWAIT/hz)*1000000);
|
|
|
|
timecount++) {
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
ecr = atppc_r_ecr(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (ecr & ATPPC_FIFO_EMPTY) {
|
|
|
|
if (ecr & ATPPC_FIFO_FULL) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_outerr = EIO;
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_fifo_write_error(atppc,
|
2004-01-20 02:22:23 +03:00
|
|
|
worklen);
|
|
|
|
return;
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DELAY(1);
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
if (((timecount*hz)/1000000) >= MAXBUSYWAIT) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_outerr = EIO;
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_fifo_write_error(atppc, worklen);
|
2004-01-20 02:22:23 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Update pointer */
|
|
|
|
atppc->sc_outbstart += worklen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
static void
|
|
|
|
atppc_fifo_write_error(struct atppc_softc * const atppc,
|
2004-01-20 02:22:23 +03:00
|
|
|
const unsigned int worklen)
|
|
|
|
{
|
|
|
|
unsigned char ecr = atppc_r_ecr(atppc);
|
|
|
|
|
|
|
|
/* Abort DMA if not finished */
|
2004-01-28 17:26:24 +03:00
|
|
|
if (atppc->sc_dmastat == ATPPC_DMA_STARTED) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_dma_abort(atppc);
|
|
|
|
ATPPC_DPRINTF(("%s: DMA interrupted.\n", __func__));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for invalid states */
|
2004-01-28 17:26:24 +03:00
|
|
|
if ((ecr & ATPPC_FIFO_EMPTY) && (ecr & ATPPC_FIFO_FULL)) {
|
|
|
|
ATPPC_DPRINTF(("%s: FIFO full+empty bits set.\n", __func__));
|
|
|
|
} else if (!(ecr & ATPPC_FIFO_EMPTY)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
unsigned char ctr = atppc_r_ctr(atppc);
|
|
|
|
int bytes_left;
|
|
|
|
int i;
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
ATPPC_DPRINTF(("%s(%s): FIFO not empty.\n", __func__,
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_dev.dv_xname));
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Drive strobe low to stop data transfer */
|
|
|
|
ctr &= ~STROBE;
|
|
|
|
atppc_w_ctr(atppc, ctr);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
|
|
|
|
/* Determine how many bytes remain in FIFO */
|
2004-01-28 17:26:24 +03:00
|
|
|
for (i = 0; i < atppc->sc_fifo; i++) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc_w_fifo(atppc, (unsigned char)i);
|
|
|
|
ecr = atppc_r_ecr(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if (ecr & ATPPC_FIFO_FULL)
|
2004-01-20 02:22:23 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
bytes_left = (atppc->sc_fifo) - (i + 1);
|
2004-01-28 17:26:24 +03:00
|
|
|
ATPPC_DPRINTF(("%s: %d bytes left in FIFO.\n", __func__,
|
2004-01-20 02:22:23 +03:00
|
|
|
bytes_left));
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Update counter */
|
|
|
|
atppc->sc_outbstart += (worklen - bytes_left);
|
2004-01-28 17:26:24 +03:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Update counter */
|
|
|
|
atppc->sc_outbstart += worklen;
|
|
|
|
}
|
|
|
|
|
|
|
|
ATPPC_DPRINTF(("%s: reseting FIFO.\n", __func__));
|
|
|
|
atppc_w_ecr(atppc, ATPPC_ECR_PS2);
|
|
|
|
atppc_barrier_w(atppc);
|
|
|
|
}
|
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
/*
|
|
|
|
* Poll status register using mask and status for MAXBUSYWAIT.
|
2004-01-20 02:22:23 +03:00
|
|
|
* Returns 0 if device ready, error value otherwise.
|
|
|
|
*/
|
|
|
|
static int
|
2004-01-28 17:26:24 +03:00
|
|
|
atppc_poll_str(const struct atppc_softc * const atppc, const u_int8_t status,
|
2004-01-20 02:22:23 +03:00
|
|
|
const u_int8_t mask)
|
|
|
|
{
|
|
|
|
unsigned int timecount;
|
|
|
|
u_int8_t str;
|
|
|
|
int error = EIO;
|
|
|
|
|
|
|
|
/* Wait for str to have status for MAXBUSYWAIT */
|
2004-01-28 17:26:24 +03:00
|
|
|
for (timecount = 0; timecount < ((MAXBUSYWAIT/hz)*1000000);
|
2004-01-20 02:22:23 +03:00
|
|
|
timecount++) {
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
str = atppc_r_str(atppc);
|
|
|
|
atppc_barrier_r(atppc);
|
2004-01-28 17:26:24 +03:00
|
|
|
if ((str & mask) == status) {
|
2004-01-20 02:22:23 +03:00
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DELAY(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for interrupt for MAXBUSYWAIT: returns 0 if acknowledge received. */
|
|
|
|
static int
|
2007-03-04 08:59:00 +03:00
|
|
|
atppc_wait_interrupt(struct atppc_softc * const atppc, const void *where,
|
2004-01-20 02:22:23 +03:00
|
|
|
const u_int8_t irqstat)
|
|
|
|
{
|
|
|
|
int error = EIO;
|
|
|
|
|
|
|
|
atppc->sc_irqstat &= ~irqstat;
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Wait for interrupt for MAXBUSYWAIT */
|
2004-01-28 17:26:24 +03:00
|
|
|
error = ltsleep(where, PPBUSPRI | PCATCH, __func__, MAXBUSYWAIT,
|
|
|
|
ATPPC_SC_LOCK(atppc));
|
2004-02-24 20:41:09 +03:00
|
|
|
|
2004-01-28 17:26:24 +03:00
|
|
|
if (!(error) && (atppc->sc_irqstat & irqstat)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
atppc->sc_irqstat &= ~irqstat;
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|