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.
|
|
|
|
*
|
1998-09-13 20:44:55 +00:00
|
|
|
* $Id: ppb_1284.c,v 1.5 1998/09/13 18:26:26 nsouch Exp $
|
1997-08-16 14:05:38 +00:00
|
|
|
*
|
|
|
|
*/
|
1998-01-31 07:23:16 +00:00
|
|
|
|
|
|
|
#include "opt_debug_1284.h"
|
|
|
|
|
1997-08-16 14:05:38 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
|
|
|
|
#include <machine/clock.h>
|
|
|
|
|
|
|
|
#include <dev/ppbus/ppbconf.h>
|
|
|
|
#include <dev/ppbus/ppb_1284.h>
|
|
|
|
|
|
|
|
/*
|
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
|
|
|
|
*/
|
|
|
|
int
|
1998-08-03 19:14:33 +00:00
|
|
|
do_1284_wait(struct ppb_device *dev, char mask, char status)
|
1997-08-16 14:05:38 +00:00
|
|
|
{
|
|
|
|
int i;
|
1998-08-03 19:14:33 +00:00
|
|
|
char r;
|
|
|
|
|
|
|
|
/* try up to 5ms */
|
|
|
|
for (i = 0; i < 20; i++) {
|
|
|
|
r = ppb_rstr(dev);
|
|
|
|
DELAY(25);
|
|
|
|
if ((r & mask) == status)
|
|
|
|
return (0);
|
|
|
|
}
|
1997-08-16 14:05:38 +00:00
|
|
|
|
|
|
|
return (ppb_poll_device(dev, 4, mask, status, PPB_NOINTR));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define nibble2char(s) (((s & ~nACK) >> 3) | (~s & nBUSY) >> 4)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
nibble_1284_inbyte(struct ppb_device *dev, char *buffer)
|
|
|
|
{
|
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++) {
|
|
|
|
/* ready to take data (nAUTO low) */
|
1998-09-13 18:26:26 +00:00
|
|
|
ppb_wctr(dev, AUTOFEED & ~(STROBE | SELECTIN));
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1998-08-03 19:14:33 +00:00
|
|
|
if ((error = do_1284_wait(dev, nACK, 0)))
|
1997-08-16 14:05:38 +00:00
|
|
|
return (error);
|
|
|
|
|
|
|
|
/* read nibble */
|
|
|
|
nibble[i] = ppb_rstr(dev);
|
|
|
|
|
|
|
|
/* ack, not ready for another nibble */
|
1998-09-13 18:26:26 +00:00
|
|
|
ppb_wctr(dev, 0 & ~(AUTOFEED | STROBE | SELECTIN));
|
1997-08-16 14:05:38 +00:00
|
|
|
|
|
|
|
/* wait ack from peripherial */
|
1998-08-03 19:14:33 +00:00
|
|
|
if ((error = do_1284_wait(dev, nACK, nACK)))
|
1997-08-16 14:05:38 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
*buffer = ((nibble2char(nibble[1]) << 4) & 0xf0) |
|
|
|
|
(nibble2char(nibble[0]) & 0x0f);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nibble_1284_sync()
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nibble_1284_sync(struct ppb_device *dev)
|
|
|
|
{
|
|
|
|
char ctr;
|
|
|
|
|
|
|
|
ctr = ppb_rctr(dev);
|
|
|
|
|
|
|
|
ppb_wctr(dev, (ctr & ~AUTOFEED) | SELECTIN);
|
1998-08-03 19:14:33 +00:00
|
|
|
if (do_1284_wait(dev, nACK, 0))
|
1997-08-16 14:05:38 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
ppb_wctr(dev, ctr | AUTOFEED);
|
1998-08-03 19:14:33 +00:00
|
|
|
do_1284_wait(dev, nACK, nACK);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
|
|
|
ppb_wctr(dev, (ctr & ~AUTOFEED) | SELECTIN);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-09-13 18:26:26 +00:00
|
|
|
* ppb_1284_negociate()
|
1997-08-16 14:05:38 +00:00
|
|
|
*
|
|
|
|
* Normal nibble mode or request device id mode (see ppb_1284.h)
|
|
|
|
*/
|
|
|
|
int
|
1998-09-13 18:26:26 +00:00
|
|
|
ppb_1284_negociate(struct ppb_device *dev, int mode)
|
1997-08-16 14:05:38 +00:00
|
|
|
{
|
|
|
|
int error;
|
1998-09-13 18:26:26 +00:00
|
|
|
int phase = 0;
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1998-09-13 18:26:26 +00:00
|
|
|
ppb_wctr(dev, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED));
|
|
|
|
DELAY(1);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
|
|
|
ppb_wdtr(dev, mode);
|
1998-09-13 18:26:26 +00:00
|
|
|
DELAY(1);
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1998-09-13 18:26:26 +00:00
|
|
|
ppb_wctr(dev, (nINIT | AUTOFEED) & ~(STROBE | SELECTIN));
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1998-09-13 18:26:26 +00:00
|
|
|
if ((error = do_1284_wait(dev, nACK | PERROR | SELECT | nFAULT,
|
|
|
|
PERROR | SELECT | nFAULT)))
|
|
|
|
goto error;
|
1997-08-16 14:05:38 +00:00
|
|
|
|
1998-09-13 18:26:26 +00:00
|
|
|
phase = 1;
|
|
|
|
|
|
|
|
ppb_wctr(dev, (nINIT | STROBE | AUTOFEED) & ~SELECTIN);
|
1997-08-16 14:05:38 +00:00
|
|
|
DELAY(5);
|
|
|
|
|
1998-09-13 18:26:26 +00:00
|
|
|
ppb_wctr(dev, nINIT & ~(SELECTIN | AUTOFEED | STROBE));
|
|
|
|
|
|
|
|
#if 0 /* not respected by most devices */
|
|
|
|
if ((error = do_1284_wait(dev, nACK, nACK)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (mode == 0)
|
|
|
|
if ((error = do_1284_wait(dev, SELECT, 0)))
|
|
|
|
goto error;
|
|
|
|
else
|
|
|
|
if ((error = do_1284_wait(dev, SELECT, SELECT)))
|
|
|
|
goto error;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (bootverbose)
|
|
|
|
printf("%s: status=0x%x %d\n", __FUNCTION__, ppb_rstr(dev), phase);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ppb_1284_terminate(struct ppb_device *dev, int how)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
switch (how) {
|
|
|
|
case VALID_STATE:
|
|
|
|
|
|
|
|
ppb_wctr(dev, SELECTIN & ~(STROBE | AUTOFEED));
|
|
|
|
|
|
|
|
if ((error = do_1284_wait(dev, nACK | nBUSY | nFAULT, nFAULT)))
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
ppb_wctr(dev, (SELECTIN | AUTOFEED) & ~STROBE);
|
|
|
|
|
|
|
|
if ((error = do_1284_wait(dev, nACK, nACK)))
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
ppb_wctr(dev, SELECTIN & ~(STROBE | AUTOFEED));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
1997-08-16 14:05:38 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|