/* $Header$
 * driver for parallax board set.
 */

#define USERMODE_PIO

#include	"plxmd.h"
/*#include	"plxioctl.h" */
#include	"plxreg.h"

extern plx_softc plx_sc[];
extern struct buf plx_buf[];


#define PLXCSR 	0x2000f0c0


char *plx_errorstring[] = {
	"Non-Existent Memory",					/*  0 */
	"Illegal Opcode",					/*  1 */
	"Polygon Vertex Overflow",				/*  2 */
	"Fill Stack Overflow",					/*  3 */
	"Parameter",						/*  4 */
	"Mode",							/*  5 */
	"Get (non dma) (1280 multi-context version)",		/*  6 */
	"Put (non dma) (1280 multi-context version)",		/*  7 */
	"Ram Allocation",					/*  8 */
	"Microcode Store Load",					/*  9 */
	"Video",						/* 10 */
	"Restore Stream Without Previous Save",			/* 11 */
};
int plx_errormax = sizeof(plx_errorstring) / sizeof(plx_errorstring[0]) - 1;

plx_init()
{
    register struct plx_device *plxaddr;
    extern int cpu, sid_ext;

    if (cpu != 8 || sid_ext != 1)
      return(0);

    plxaddr = (struct plx_device *) PLXCSR;
    if (badaddr(plxaddr, sizeof(short)))
      return(0);

    if (!plx_ioclear(plxaddr))
      return(0);


    v_getc = plxgetc;
    v_putc = plxputc;
    v_getct = plxgetct;

    return(1);
}


plx_ioclear(plxaddr)
register struct plx_device *plxaddr;
{
	register int tries = 10000;
	register u_short saved_csr;

	dprintf("plx_ioclear()\n");

	DELAY(plx_registerdelay);
	OUTWORD(plxaddr->csr, CSR_RESET);

	while (tries-- > 0) {
		DELAY(IOCLEAR_DELAY);
		saved_csr = INWORD(plxaddr->csr);
		DELAY(plx_registerdelay);
		if ((saved_csr == (CSR_READY|CSR_WC)) || (saved_csr == CSR_WC))
			return (1);
		dprintf("plx_ioclear: csr=0x%x\n", saved_csr);
	}
	printf("plx_ioclear: failed, csr=0x%x\n", saved_csr);
	DELAY(plx_registerdelay);
	return (0);
}
