/*
 *
 */
#include "defsfile"

extern scf_drvr_stat drvrstatic;

/* terminate - disable DIO hardware routine. */
terminate(Dev_list device_entry)				/* device list entry pointer */
{
	register Scf_lu_stat unit_stat;	/* unit static storage pointer */

	/* get unit static storage pointer */		
	unit_stat = device_entry->v_lu_stat;	

	/* disable interrupt on the pic */
#ifndef SHARED_VECTOR
	if (unit_stat->v_irq_shared == 0)
			_pic_disable(unit_stat->v_vector);
#endif
	_pic_disable(unit_stat->v_vector);

	/* disable ~P1C0 & P1C3 interrupts */
	OUT(&unit_stat->PORTADDR[DIO_ISC], 0x0);
    /* disable the IRQs on the card (in the PLX) */
    OUT(unit_stat->v_plx_base+PLX_INTCR, 0x13);	
	
	/* remove interrupt service routine */
	_os_irq(unit_stat->v_vector, 0, NULL, device_entry->v_dr_stat);

	/* set connector 1 to the following port configuration: port A = in, port B = in, port C = in */
	OUT(&unit_stat->PORTADDR[DIO_CONNCTRL], 0x1B);

	/* make sure actually last terminate call */
	if (--drvrstatic.v_attached != 0) return SUCCESS;

    /* delete events if this is the last instance */
   	_os_ev_unlink(unit_stat->lms_evh1);
    _os_ev_unlink(unit_stat->lms_evh2);
	_os_ev_delete(EV1_NAME);
	_os_ev_delete(EV2_NAME);
	
	return SUCCESS;
}
