/*-
* Copyright (c) 1998 NetBSD Foundation, Inc.
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
/*
* MC68901 MFP (multi function periferal) driver for NetBSD/x68k
*/
/*
* MFP is used as keyboard controller, which may be used before
* ordinary initialization.
*/
/* stop all interrupts */
mfp_set_iera(0);
mfp_set_ierb(0);
/* make MSCTRL 'High', XXX where should I do it? */
mfp_send_usart(0x41);
/* Timer A settings */
mfp_set_tacr(MFP_TIMERA_RESET | MFP_TIMERA_STOP);
/* Timer B settings: used for USART clock */
mfp_set_tbcr(MFP_TIMERB_RESET | MFP_TIMERB_STOP);
/* Timer C/D settings */
mfp_set_tcdcr(0);
}
extern int delay_divisor;
static void
mfp_calibrate_delay(void)
{
/*
* Stolen from mvme68k.
*/
/*
* X68k provides 4MHz clock (= 0.25usec) for MFP timer C.
* 10000usec = 0.25usec * 200 * 200
* Our slowest clock is 20MHz (?). Its delay_divisor value
* should be about 102. Start from 140 here.
*/
for (delay_divisor = 140; delay_divisor > 0; delay_divisor--) {
mfp_set_tcdr(255-0);
mfp_set_tcdcr(0x70); /* 1/200 delay mode */
_delay(10000);
mfp_set_tcdcr(0); /* stop timer */
if ((255 - mfp_get_tcdr()) > 200)
break; /* got it! */
/* retry! */
}
}
/*
* MFP utility functions
*/
/*
* wait for built-in display hsync.
* should be called before writing to frame buffer.
* might be called before realconfig.
*/
void
mfp_wait_for_hsync(void)
{
/* wait for CRT HSYNC */
while (mfp_get_gpip() & MFP_GPIP_HSYNC)
__asm("nop");
while (!(mfp_get_gpip() & MFP_GPIP_HSYNC))
__asm("nop");
}
/*
* send COMMAND to the MFP USART.
* USART is attached to the keyboard.
* might be called before realconfig.
*/
int
mfp_send_usart(int command)
{
while (!(mfp_get_tsr() & MFP_TSR_BE));
mfp_set_udr(command);
return 0;
}
int
mfp_receive_usart(void)
{
while (!(mfp_get_rsr() & MFP_RSR_BF))
__asm("nop");
return mfp_get_udr();
}