1997-08-16 14:05:38 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997 Nicolas Souchu
|
|
|
|
* 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.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1997-08-16 14:05:38 +00:00
|
|
|
*
|
|
|
|
*/
|
1998-01-31 07:23:16 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/*
|
|
|
|
* General purpose routines for the IEEE1284-1994 Standard
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opt_ppb_1284.h"
|
1998-01-31 07:23:16 +00:00
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-01-14 00:18:06 +00:00
|
|
|
#include <sys/bus.h>
|
1997-08-16 14:05:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <dev/ppbus/ppbconf.h>
|
|
|
|
#include <dev/ppbus/ppb_1284.h>
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
#include "ppbus_if.h"
|
|
|
|
|
|
|
|
#include <dev/ppbus/ppbio.h>
|
|
|
|
|
|
|
|
#define DEVTOSOFTC(dev) ((struct ppb_data *)device_get_softc(dev))
|
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
/*
|
1998-08-03 19:14:33 +00:00
|
|
|
* do_1284_wait()
|
1997-08-16 14:05:38 +00:00
|
|
|
*
|
|
|
|
* Wait for the peripherial up to 40ms
|
|
|
|
*/
|
1999-01-10 12:04:56 +00:00
|
|
|
static int
|
2000-01-14 00:18:06 +00:00
|
|
|
do_1284_wait(device_t bus, char mask, char status)
|
1997-08-16 14:05:38 +00:00
|
|
|
{
|
2000-01-14 00:18:06 +00:00
|
|
|
return (ppb_poll_bus(bus, 4, mask, status, PPB_NOINTR | PPB_POLL));
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-01-14 00:18:06 +00:00
|
|
|
do_peripheral_wait(device_t bus, char mask, char status)
|
1999-01-10 12:04:56 +00:00
|
|
|
{
|
2000-01-14 00:18:06 +00:00
|
|
|
return (ppb_poll_bus(bus, 100, mask, status, PPB_NOINTR | PPB_POLL));
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define nibble2char(s) (((s & ~nACK) >> 3) | (~s & nBUSY) >> 4)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ppb_1284_reset_error()
|
|
|
|
*
|
|
|
|
* Unconditionaly reset the error field
|
|
|
|
*/
|
|
|
|
static int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_reset_error(device_t bus, int state)
|
1999-01-10 12:04:56 +00:00
|
|
|
{
|
2000-01-14 00:18:06 +00:00
|
|
|
struct ppb_data *ppb = DEVTOSOFTC(bus);
|
|
|
|
|
|
|
|
ppb->error = PPB_NO_ERROR;
|
|
|
|
ppb->state = state;
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ppb_1284_get_state()
|
|
|
|
*
|
|
|
|
* Get IEEE1284 state
|
|
|
|
*/
|
2000-01-14 08:03:15 +00:00
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_get_state(device_t bus)
|
1999-01-10 12:04:56 +00:00
|
|
|
{
|
2000-01-14 00:18:06 +00:00
|
|
|
return (DEVTOSOFTC(bus)->state);
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ppb_1284_set_state()
|
|
|
|
*
|
|
|
|
* Change IEEE1284 state if no error occured
|
|
|
|
*/
|
2000-01-14 08:03:15 +00:00
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_state(device_t bus, int state)
|
1999-01-10 12:04:56 +00:00
|
|
|
{
|
2000-01-14 00:18:06 +00:00
|
|
|
struct ppb_data *ppb = DEVTOSOFTC(bus);
|
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* call ppb_1284_reset_error() if you absolutly want to change
|
|
|
|
* the state from PPB_ERROR to another */
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((ppb->state != PPB_ERROR) &&
|
|
|
|
(ppb->error == PPB_NO_ERROR)) {
|
|
|
|
ppb->state = state;
|
|
|
|
ppb->error = PPB_NO_ERROR;
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_error(device_t bus, int error, int event)
|
1999-01-10 12:04:56 +00:00
|
|
|
{
|
2000-01-14 00:18:06 +00:00
|
|
|
struct ppb_data *ppb = DEVTOSOFTC(bus);
|
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* do not accumulate errors */
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((ppb->error == PPB_NO_ERROR) &&
|
|
|
|
(ppb->state != PPB_ERROR)) {
|
|
|
|
ppb->error = error;
|
|
|
|
ppb->state = PPB_ERROR;
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_1284
|
|
|
|
printf("ppb1284: error=%d status=0x%x event=%d\n", error,
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_rstr(bus) & 0xff, event);
|
1999-01-10 12:04:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ppb_request_mode()
|
|
|
|
*
|
|
|
|
* Converts mode+options into ext. value
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ppb_request_mode(int mode, int options)
|
|
|
|
{
|
|
|
|
int request_mode = 0;
|
|
|
|
|
|
|
|
if (options & PPB_EXTENSIBILITY_LINK) {
|
|
|
|
request_mode = EXT_LINK_1284_NORMAL;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
switch (mode) {
|
|
|
|
case PPB_NIBBLE:
|
|
|
|
request_mode = (options & PPB_REQUEST_ID) ?
|
|
|
|
NIBBLE_1284_REQUEST_ID :
|
|
|
|
NIBBLE_1284_NORMAL;
|
|
|
|
break;
|
|
|
|
case PPB_PS2:
|
|
|
|
request_mode = (options & PPB_REQUEST_ID) ?
|
|
|
|
BYTE_1284_REQUEST_ID :
|
|
|
|
BYTE_1284_NORMAL;
|
|
|
|
break;
|
|
|
|
case PPB_ECP:
|
|
|
|
if (options & PPB_USE_RLE)
|
|
|
|
request_mode = (options & PPB_REQUEST_ID) ?
|
|
|
|
ECP_1284_RLE_REQUEST_ID :
|
|
|
|
ECP_1284_RLE;
|
|
|
|
else
|
|
|
|
request_mode = (options & PPB_REQUEST_ID) ?
|
|
|
|
ECP_1284_REQUEST_ID :
|
|
|
|
ECP_1284_NORMAL;
|
|
|
|
break;
|
|
|
|
case PPB_EPP:
|
|
|
|
request_mode = EPP_1284_NORMAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("%s: unsupported mode %d\n", __FUNCTION__, mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (request_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ppb_peripheral_negociate()
|
|
|
|
*
|
|
|
|
* Negociate the peripheral side
|
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_peripheral_negociate(device_t bus, int mode, int options)
|
1999-01-10 12:04:56 +00:00
|
|
|
{
|
|
|
|
int spin, request_mode, error = 0;
|
1998-08-03 19:14:33 +00:00
|
|
|
char r;
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_set_mode(bus, PPB_COMPATIBLE);
|
|
|
|
ppb_1284_set_state(bus, PPB_PERIPHERAL_NEGOCIATION);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* compute ext. value */
|
|
|
|
request_mode = ppb_request_mode(mode, options);
|
|
|
|
|
|
|
|
/* wait host */
|
|
|
|
spin = 10;
|
2000-01-14 00:18:06 +00:00
|
|
|
while (spin-- && (ppb_rstr(bus) & nBUSY))
|
1999-01-10 12:04:56 +00:00
|
|
|
DELAY(1);
|
|
|
|
|
|
|
|
/* check termination */
|
2000-01-14 00:18:06 +00:00
|
|
|
if (!(ppb_rstr(bus) & SELECT) || !spin) {
|
1999-01-10 12:04:56 +00:00
|
|
|
error = ENODEV;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Event 4 - read ext. value */
|
2000-01-14 00:18:06 +00:00
|
|
|
r = ppb_rdtr(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* nibble mode is not supported */
|
|
|
|
if ((r == (char)request_mode) ||
|
|
|
|
(r == NIBBLE_1284_NORMAL)) {
|
|
|
|
|
|
|
|
/* Event 5 - restore direction bit, no data avail */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (STROBE | nINIT) & ~(SELECTIN));
|
1999-01-10 12:04:56 +00:00
|
|
|
DELAY(1);
|
|
|
|
|
|
|
|
/* Event 6 */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT) & ~(SELECTIN | STROBE));
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
if (r == NIBBLE_1284_NORMAL) {
|
|
|
|
#ifdef DEBUG_1284
|
|
|
|
printf("R");
|
|
|
|
#endif
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 4);
|
1999-01-10 12:04:56 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto error;
|
|
|
|
} else {
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_state(bus, PPB_PERIPHERAL_IDLE);
|
1999-01-10 12:04:56 +00:00
|
|
|
switch (r) {
|
|
|
|
case BYTE_1284_NORMAL:
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_set_mode(bus, PPB_BYTE);
|
1999-01-10 12:04:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_1284
|
|
|
|
printf("A");
|
|
|
|
#endif
|
|
|
|
/* negociation succeeds */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Event 5 - mode not supported */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, SELECTIN);
|
1999-01-10 12:04:56 +00:00
|
|
|
DELAY(1);
|
|
|
|
|
|
|
|
/* Event 6 */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (SELECTIN) & ~(STROBE | nINIT));
|
|
|
|
ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 4);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_1284
|
|
|
|
printf("r");
|
|
|
|
#endif
|
|
|
|
error = EINVAL;
|
|
|
|
goto error;
|
1998-08-03 19:14:33 +00:00
|
|
|
}
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
error:
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_peripheral_terminate(bus, PPB_WAIT);
|
1999-01-10 12:04:56 +00:00
|
|
|
return (error);
|
1997-08-16 14:05:38 +00:00
|
|
|
}
|
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/*
|
|
|
|
* ppb_peripheral_terminate()
|
|
|
|
*
|
|
|
|
* Terminate peripheral transfer side
|
|
|
|
*
|
|
|
|
* Always return 0 in compatible mode
|
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_peripheral_terminate(device_t bus, int how)
|
1999-01-10 12:04:56 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
#ifdef DEBUG_1284
|
|
|
|
printf("t");
|
|
|
|
#endif
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_state(bus, PPB_PERIPHERAL_TERMINATION);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* Event 22 - wait up to host response time (1s) */
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = do_peripheral_wait(bus, SELECT | nBUSY, 0))) {
|
|
|
|
ppb_1284_set_error(bus, PPB_TIMEOUT, 22);
|
1999-01-10 12:04:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Event 24 */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN));
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* Event 25 - wait up to host response time (1s) */
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = do_peripheral_wait(bus, nBUSY, nBUSY))) {
|
|
|
|
ppb_1284_set_error(bus, PPB_TIMEOUT, 25);
|
1999-01-10 12:04:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Event 26 */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (SELECTIN | nINIT | STROBE) & ~(AUTOFEED));
|
1999-01-10 12:04:56 +00:00
|
|
|
DELAY(1);
|
|
|
|
/* Event 27 */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (SELECTIN | nINIT) & ~(STROBE | AUTOFEED));
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* Event 28 - wait up to host response time (1s) */
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = do_peripheral_wait(bus, nBUSY, 0))) {
|
|
|
|
ppb_1284_set_error(bus, PPB_TIMEOUT, 28);
|
1999-01-10 12:04:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_set_mode(bus, PPB_COMPATIBLE);
|
|
|
|
ppb_1284_set_state(bus, PPB_FORWARD_IDLE);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* byte_peripheral_outbyte()
|
|
|
|
*
|
|
|
|
* Write 1 byte in BYTE mode
|
|
|
|
*/
|
|
|
|
static int
|
2000-01-14 00:18:06 +00:00
|
|
|
byte_peripheral_outbyte(device_t bus, char *buffer, int last)
|
1999-01-10 12:04:56 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
/* Event 7 */
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = do_1284_wait(bus, nBUSY, nBUSY))) {
|
|
|
|
ppb_1284_set_error(bus, PPB_TIMEOUT, 7);
|
1999-01-10 12:04:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check termination */
|
2000-01-14 00:18:06 +00:00
|
|
|
if (!(ppb_rstr(bus) & SELECT)) {
|
|
|
|
ppb_peripheral_terminate(bus, PPB_WAIT);
|
1999-01-10 12:04:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Event 15 - put byte on data lines */
|
|
|
|
#ifdef DEBUG_1284
|
|
|
|
printf("B");
|
|
|
|
#endif
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wdtr(bus, *buffer);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* Event 9 */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (AUTOFEED | STROBE) & ~(nINIT | SELECTIN));
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* Event 10 - wait data read */
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = do_peripheral_wait(bus, nBUSY, 0))) {
|
|
|
|
ppb_1284_set_error(bus, PPB_TIMEOUT, 16);
|
1999-01-10 12:04:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Event 11 */
|
|
|
|
if (!last) {
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (AUTOFEED) & ~(nINIT | STROBE | SELECTIN));
|
1999-01-10 12:04:56 +00:00
|
|
|
} else {
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT) & ~(STROBE | SELECTIN | AUTOFEED));
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Event 16 - wait strobe */
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = do_peripheral_wait(bus, nACK | nBUSY, 0))) {
|
|
|
|
ppb_1284_set_error(bus, PPB_TIMEOUT, 16);
|
1999-01-10 12:04:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* check termination */
|
2000-01-14 00:18:06 +00:00
|
|
|
if (!(ppb_rstr(bus) & SELECT)) {
|
|
|
|
ppb_peripheral_terminate(bus, PPB_WAIT);
|
1999-01-10 12:04:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* byte_peripheral_write()
|
|
|
|
*
|
|
|
|
* Write n bytes in BYTE mode
|
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
byte_peripheral_write(device_t bus, char *buffer, int len, int *sent)
|
1999-01-10 12:04:56 +00:00
|
|
|
{
|
|
|
|
int error = 0, i;
|
|
|
|
char r;
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_state(bus, PPB_PERIPHERAL_TRANSFER);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* wait forever, the remote host is master and should initiate
|
|
|
|
* termination
|
|
|
|
*/
|
|
|
|
for (i=0; i<len; i++) {
|
|
|
|
/* force remote nFAULT low to release the remote waiting
|
|
|
|
* process, if any
|
|
|
|
*/
|
2000-01-14 00:18:06 +00:00
|
|
|
r = ppb_rctr(bus);
|
|
|
|
ppb_wctr(bus, r & ~nINIT);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_1284
|
|
|
|
printf("y");
|
|
|
|
#endif
|
|
|
|
/* Event 7 */
|
2000-01-14 00:18:06 +00:00
|
|
|
error = ppb_poll_bus(bus, PPB_FOREVER, nBUSY, nBUSY,
|
1999-01-10 12:04:56 +00:00
|
|
|
PPB_INTR);
|
|
|
|
|
|
|
|
if (error && error != EWOULDBLOCK)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
#ifdef DEBUG_1284
|
|
|
|
printf("b");
|
|
|
|
#endif
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = byte_peripheral_outbyte(bus, buffer+i, (i == len-1))))
|
1999-01-10 12:04:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
error:
|
|
|
|
if (!error)
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_state(bus, PPB_PERIPHERAL_IDLE);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
*sent = i;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* byte_1284_inbyte()
|
|
|
|
*
|
|
|
|
* Read 1 byte in BYTE mode
|
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
byte_1284_inbyte(device_t bus, char *buffer)
|
1999-01-10 12:04:56 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
/* Event 7 - ready to take data (nAUTO low) */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (PCD | nINIT | AUTOFEED) & ~(STROBE | SELECTIN));
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* Event 9 - peripheral set nAck low */
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = do_1284_wait(bus, nACK, 0))) {
|
|
|
|
ppb_1284_set_error(bus, PPB_TIMEOUT, 9);
|
1999-01-10 12:04:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the byte */
|
2000-01-14 00:18:06 +00:00
|
|
|
*buffer = ppb_rdtr(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* Event 10 - data received, can't accept more */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT) & ~(AUTOFEED | STROBE | SELECTIN));
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* Event 11 - peripheral ack */
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = do_1284_wait(bus, nACK, nACK))) {
|
|
|
|
ppb_1284_set_error(bus, PPB_TIMEOUT, 11);
|
1999-01-10 12:04:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Event 16 - strobe */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN));
|
1999-01-10 12:04:56 +00:00
|
|
|
DELAY(3);
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT) & ~(AUTOFEED | STROBE | SELECTIN));
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
return (error);
|
|
|
|
}
|
1997-08-16 14:05:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nibble_1284_inbyte()
|
|
|
|
*
|
1998-08-03 19:14:33 +00:00
|
|
|
* Read 1 byte in NIBBLE mode
|
1997-08-16 14:05:38 +00:00
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
nibble_1284_inbyte(device_t bus, char *buffer)
|
1997-08-16 14:05:38 +00:00
|
|
|
{
|
1998-08-03 19:14:33 +00:00
|
|
|
char nibble[2];
|
1997-08-16 14:05:38 +00:00
|
|
|
int i, error;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* Event 7 - ready to take data (nAUTO low) */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT | AUTOFEED) & ~(STROBE | SELECTIN));
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* Event 8 - peripheral writes the first nibble */
|
|
|
|
|
|
|
|
/* Event 9 - peripheral set nAck low */
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = do_1284_wait(bus, nACK, 0))) {
|
|
|
|
ppb_1284_set_error(bus, PPB_TIMEOUT, 9);
|
1999-01-10 12:04:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
1997-08-16 14:05:38 +00:00
|
|
|
|
|
|
|
/* read nibble */
|
2000-01-14 00:18:06 +00:00
|
|
|
nibble[i] = ppb_rstr(bus);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* Event 10 - ack, nibble received */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, nINIT & ~(AUTOFEED | STROBE | SELECTIN));
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* Event 11 - wait ack from peripherial */
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = do_1284_wait(bus, nACK, nACK))) {
|
|
|
|
ppb_1284_set_error(bus, PPB_TIMEOUT, 11);
|
1999-01-10 12:04:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
1997-08-16 14:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*buffer = ((nibble2char(nibble[1]) << 4) & 0xf0) |
|
|
|
|
(nibble2char(nibble[0]) & 0x0f);
|
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
error:
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* spp_1284_read()
|
|
|
|
*
|
|
|
|
* Read in IEEE1284 NIBBLE/BYTE mode
|
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
spp_1284_read(device_t bus, int mode, char *buffer, int max, int *read)
|
1999-01-10 12:04:56 +00:00
|
|
|
{
|
|
|
|
int error = 0, len = 0;
|
|
|
|
int terminate_after_transfer = 1;
|
|
|
|
int state;
|
|
|
|
|
|
|
|
*read = len = 0;
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
state = ppb_1284_get_state(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case PPB_FORWARD_IDLE:
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = ppb_1284_negociate(bus, mode, 0)))
|
1999-01-10 12:04:56 +00:00
|
|
|
return (error);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPB_REVERSE_IDLE:
|
|
|
|
terminate_after_transfer = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
|
|
|
if ((error = ppb_1284_negociate(bus, mode, 0)))
|
1999-01-10 12:04:56 +00:00
|
|
|
return (error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
while ((len < max) && !(ppb_rstr(bus) & (nFAULT))) {
|
1999-01-10 12:04:56 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_state(bus, PPB_REVERSE_TRANSFER);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_1284
|
|
|
|
printf("B");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case PPB_NIBBLE:
|
|
|
|
/* read a byte, error means no more data */
|
2000-01-14 00:18:06 +00:00
|
|
|
if (nibble_1284_inbyte(bus, buffer+len))
|
1999-01-10 12:04:56 +00:00
|
|
|
goto end_while;
|
|
|
|
break;
|
|
|
|
case PPB_BYTE:
|
2000-01-14 00:18:06 +00:00
|
|
|
if (byte_1284_inbyte(bus, buffer+len))
|
1999-01-10 12:04:56 +00:00
|
|
|
goto end_while;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
goto end_while;
|
|
|
|
}
|
|
|
|
len ++;
|
|
|
|
}
|
|
|
|
end_while:
|
|
|
|
|
|
|
|
if (!error)
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_state(bus, PPB_REVERSE_IDLE);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
*read = len;
|
|
|
|
|
|
|
|
if (terminate_after_transfer || error)
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
return (error);
|
1997-08-16 14:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-01-10 12:04:56 +00:00
|
|
|
* ppb_1284_read_id()
|
|
|
|
*
|
1997-08-16 14:05:38 +00:00
|
|
|
*/
|
1999-01-10 12:04:56 +00:00
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_read_id(device_t bus, int mode, char *buffer,
|
1999-01-10 12:04:56 +00:00
|
|
|
int max, int *read)
|
1997-08-16 14:05:38 +00:00
|
|
|
{
|
1999-01-10 12:04:56 +00:00
|
|
|
int error = 0;
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* fill the buffer with 0s */
|
|
|
|
bzero(buffer, max);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
switch (mode) {
|
|
|
|
case PPB_NIBBLE:
|
|
|
|
case PPB_ECP:
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = ppb_1284_negociate(bus, PPB_NIBBLE, PPB_REQUEST_ID)))
|
1999-01-10 12:04:56 +00:00
|
|
|
return (error);
|
2000-01-14 00:18:06 +00:00
|
|
|
error = spp_1284_read(bus, PPB_NIBBLE, buffer, max, read);
|
1999-01-10 12:04:56 +00:00
|
|
|
break;
|
|
|
|
case PPB_BYTE:
|
2000-01-14 00:18:06 +00:00
|
|
|
if ((error = ppb_1284_negociate(bus, PPB_BYTE, PPB_REQUEST_ID)))
|
1999-01-10 12:04:56 +00:00
|
|
|
return (error);
|
2000-01-14 00:18:06 +00:00
|
|
|
error = spp_1284_read(bus, PPB_BYTE, buffer, max, read);
|
1999-01-10 12:04:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("%s: unsupported mode %d\n", __FUNCTION__, mode);
|
|
|
|
}
|
1997-08-16 14:05:38 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
return (error);
|
|
|
|
}
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/*
|
|
|
|
* ppb_1284_read()
|
|
|
|
*
|
|
|
|
* IEEE1284 read
|
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_read(device_t bus, int mode, char *buffer,
|
1999-01-10 12:04:56 +00:00
|
|
|
int max, int *read)
|
|
|
|
{
|
|
|
|
int error = 0;
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
switch (mode) {
|
|
|
|
case PPB_NIBBLE:
|
|
|
|
case PPB_BYTE:
|
2000-01-14 00:18:06 +00:00
|
|
|
error = spp_1284_read(bus, mode, buffer, max, read);
|
1999-01-10 12:04:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
1997-08-16 14:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-09-13 18:26:26 +00:00
|
|
|
* ppb_1284_negociate()
|
1997-08-16 14:05:38 +00:00
|
|
|
*
|
1999-01-10 12:04:56 +00:00
|
|
|
* IEEE1284 negociation phase
|
|
|
|
*
|
1997-08-16 14:05:38 +00:00
|
|
|
* Normal nibble mode or request device id mode (see ppb_1284.h)
|
1999-01-10 12:04:56 +00:00
|
|
|
*
|
|
|
|
* After negociation, nFAULT is low if data is available
|
1997-08-16 14:05:38 +00:00
|
|
|
*/
|
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_negociate(device_t bus, int mode, int options)
|
1997-08-16 14:05:38 +00:00
|
|
|
{
|
|
|
|
int error;
|
1999-01-10 12:04:56 +00:00
|
|
|
int request_mode;
|
|
|
|
|
|
|
|
#ifdef DEBUG_1284
|
|
|
|
printf("n");
|
|
|
|
#endif
|
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
if (ppb_1284_get_state(bus) >= PPB_PERIPHERAL_NEGOCIATION)
|
|
|
|
ppb_peripheral_terminate(bus, PPB_WAIT);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
2000-01-14 00:18:06 +00:00
|
|
|
if (ppb_1284_get_state(bus) != PPB_FORWARD_IDLE)
|
|
|
|
ppb_1284_terminate(bus);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_1284
|
|
|
|
printf("%d", mode);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ensure the host is in compatible mode */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_set_mode(bus, PPB_COMPATIBLE);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* reset error to catch the actual negociation error */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_reset_error(bus, PPB_FORWARD_IDLE);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* calculate ext. value */
|
|
|
|
request_mode = ppb_request_mode(mode, options);
|
|
|
|
|
|
|
|
/* default state */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED));
|
1998-09-13 18:26:26 +00:00
|
|
|
DELAY(1);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* enter negociation phase */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_state(bus, PPB_NEGOCIATION);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
/* Event 0 - put the exten. value on the data lines */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wdtr(bus, request_mode);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
#ifdef PERIPH_1284
|
|
|
|
/* request remote host attention */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN));
|
1999-01-10 12:04:56 +00:00
|
|
|
DELAY(1);
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT) & ~(STROBE | AUTOFEED | SELECTIN));
|
1999-01-10 12:04:56 +00:00
|
|
|
#else
|
1998-09-13 18:26:26 +00:00
|
|
|
DELAY(1);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
#endif /* !PERIPH_1284 */
|
|
|
|
|
|
|
|
/* Event 1 - enter IEEE1284 mode */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT | AUTOFEED) & ~(STROBE | SELECTIN));
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
#ifdef PERIPH_1284
|
|
|
|
/* ignore the PError line, wait a bit more, remote host's
|
|
|
|
* interrupts don't respond fast enough */
|
2000-01-14 00:18:06 +00:00
|
|
|
if (ppb_poll_bus(bus, 40, nACK | SELECT | nFAULT,
|
1999-01-10 12:04:56 +00:00
|
|
|
SELECT | nFAULT, PPB_NOINTR | PPB_POLL)) {
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_error(bus, PPB_NOT_IEEE1284, 2);
|
1999-01-10 12:04:56 +00:00
|
|
|
error = ENODEV;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* Event 2 - trying IEEE1284 dialog */
|
2000-01-14 00:18:06 +00:00
|
|
|
if (do_1284_wait(bus, nACK | PERROR | SELECT | nFAULT,
|
1999-01-10 12:04:56 +00:00
|
|
|
PERROR | SELECT | nFAULT)) {
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_error(bus, PPB_NOT_IEEE1284, 2);
|
1999-01-10 12:04:56 +00:00
|
|
|
error = ENODEV;
|
1998-09-13 18:26:26 +00:00
|
|
|
goto error;
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
|
|
|
#endif /* !PERIPH_1284 */
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* Event 3 - latch the ext. value to the peripheral */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT | STROBE | AUTOFEED) & ~SELECTIN);
|
1999-01-10 12:04:56 +00:00
|
|
|
DELAY(1);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* Event 4 - IEEE1284 device recognized */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, nINIT & ~(SELECTIN | AUTOFEED | STROBE));
|
1998-09-13 18:26:26 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* Event 6 - waiting for status lines */
|
2000-01-14 00:18:06 +00:00
|
|
|
if (do_1284_wait(bus, nACK, nACK)) {
|
|
|
|
ppb_1284_set_error(bus, PPB_TIMEOUT, 6);
|
1999-01-10 12:04:56 +00:00
|
|
|
error = EBUSY;
|
1998-09-13 18:26:26 +00:00
|
|
|
goto error;
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
1998-09-13 18:26:26 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* Event 7 - quering result consider nACK not to misunderstand
|
|
|
|
* a remote computer terminate sequence */
|
1999-01-14 21:38:16 +00:00
|
|
|
if (options & PPB_EXTENSIBILITY_LINK) {
|
|
|
|
|
|
|
|
/* XXX not fully supported yet */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
1999-01-14 21:38:16 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
}
|
1999-01-10 12:04:56 +00:00
|
|
|
if (request_mode == NIBBLE_1284_NORMAL) {
|
2000-01-14 00:18:06 +00:00
|
|
|
if (do_1284_wait(bus, nACK | SELECT, nACK)) {
|
|
|
|
ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 7);
|
1999-01-10 12:04:56 +00:00
|
|
|
error = ENODEV;
|
1998-09-13 18:26:26 +00:00
|
|
|
goto error;
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
2000-01-14 00:18:06 +00:00
|
|
|
if (do_1284_wait(bus, nACK | SELECT, SELECT | nACK)) {
|
|
|
|
ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 7);
|
1999-01-10 12:04:56 +00:00
|
|
|
error = ENODEV;
|
1998-09-13 18:26:26 +00:00
|
|
|
goto error;
|
1999-01-10 12:04:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case PPB_NIBBLE:
|
|
|
|
case PPB_PS2:
|
|
|
|
/* enter reverse idle phase */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_state(bus, PPB_REVERSE_IDLE);
|
1999-01-10 12:04:56 +00:00
|
|
|
break;
|
|
|
|
case PPB_ECP:
|
|
|
|
/* negociation ok, now setup the communication */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_state(bus, PPB_SETUP);
|
|
|
|
ppb_wctr(bus, (nINIT | AUTOFEED) & ~(SELECTIN | STROBE));
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
#ifdef PERIPH_1284
|
|
|
|
/* ignore PError line */
|
2000-01-14 00:18:06 +00:00
|
|
|
if (do_1284_wait(bus, nACK | SELECT | nBUSY,
|
1999-01-10 12:04:56 +00:00
|
|
|
nACK | SELECT | nBUSY)) {
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_error(bus, PPB_TIMEOUT, 30);
|
1999-01-10 12:04:56 +00:00
|
|
|
error = ENODEV;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
#else
|
2000-01-14 00:18:06 +00:00
|
|
|
if (do_1284_wait(bus, nACK | SELECT | PERROR | nBUSY,
|
1999-01-10 12:04:56 +00:00
|
|
|
nACK | SELECT | PERROR | nBUSY)) {
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_error(bus, PPB_TIMEOUT, 30);
|
1999-01-10 12:04:56 +00:00
|
|
|
error = ENODEV;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
#endif /* !PERIPH_1284 */
|
|
|
|
|
|
|
|
/* ok, the host enters the ForwardIdle state */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_state(bus, PPB_ECP_FORWARD_IDLE);
|
1999-01-10 12:04:56 +00:00
|
|
|
break;
|
|
|
|
case PPB_EPP:
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_state(bus, PPB_EPP_IDLE);
|
1999-01-10 12:04:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic("%s: unknown mode (%d)!", __FUNCTION__, mode);
|
|
|
|
}
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_set_mode(bus, mode);
|
1998-09-13 18:26:26 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
error:
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(bus);
|
1998-09-13 18:26:26 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/*
|
|
|
|
* ppb_1284_terminate()
|
|
|
|
*
|
|
|
|
* IEEE1284 termination phase, return code should ignored since the host
|
|
|
|
* is _always_ in compatible mode after ppb_1284_terminate()
|
|
|
|
*/
|
1998-09-13 18:26:26 +00:00
|
|
|
int
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_terminate(device_t bus)
|
1998-09-13 18:26:26 +00:00
|
|
|
{
|
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
#ifdef DEBUG_1284
|
|
|
|
printf("T");
|
|
|
|
#endif
|
1998-09-13 18:26:26 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* do not reset error here to keep the error that
|
|
|
|
* may occured before the ppb_1284_terminate() call */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_1284_set_state(bus, PPB_TERMINATION);
|
1998-09-13 18:26:26 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
#ifdef PERIPH_1284
|
|
|
|
/* request remote host attention */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT | STROBE | SELECTIN) & ~(AUTOFEED));
|
1999-01-10 12:04:56 +00:00
|
|
|
DELAY(1);
|
|
|
|
#endif /* PERIPH_1284 */
|
1998-09-13 18:26:26 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* Event 22 - set nSelectin low and nAutoFeed high */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED));
|
1998-09-13 18:26:26 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* Event 24 - waiting for peripheral, Xflag ignored */
|
2000-01-14 00:18:06 +00:00
|
|
|
if (do_1284_wait(bus, nACK | nBUSY | nFAULT, nFAULT)) {
|
|
|
|
ppb_1284_set_error(bus, PPB_TIMEOUT, 24);
|
1999-01-10 12:04:56 +00:00
|
|
|
goto error;
|
|
|
|
}
|
1998-09-13 18:26:26 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* Event 25 - set nAutoFd low */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT | SELECTIN | AUTOFEED) & ~STROBE);
|
1998-09-13 18:26:26 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* Event 26 - compatible mode status is set */
|
|
|
|
|
|
|
|
/* Event 27 - peripheral set nAck high */
|
2000-01-14 00:18:06 +00:00
|
|
|
if (do_1284_wait(bus, nACK, nACK)) {
|
|
|
|
ppb_1284_set_error(bus, PPB_TIMEOUT, 27);
|
1998-09-13 18:26:26 +00:00
|
|
|
}
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1999-01-10 12:04:56 +00:00
|
|
|
/* Event 28 - end termination, return to idle phase */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_wctr(bus, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED));
|
1999-01-10 12:04:56 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
/* return to compatible mode */
|
2000-01-14 00:18:06 +00:00
|
|
|
ppb_set_mode(bus, PPB_COMPATIBLE);
|
|
|
|
ppb_1284_set_state(bus, PPB_FORWARD_IDLE);
|
1999-01-10 12:04:56 +00:00
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
return (0);
|
|
|
|
}
|