/*
 * DANG_BEGIN_MODULE
 *
 * Description: Keyboard coordinator
 *
 * Maintainer: Eric Biederman <ebiederm@xmission.com>
 *
 * REMARK
 * This module coordinates the initialization of the keyboard.
 *
 * /REMARK
 * DANG_END_MODULE
 *
 */

#include "emu.h"
#include "init.h"
#include "iodev.h"

#include "getfd.h"
#include "keyboard.h"
#include "keyb_clients.h"
#include "keyb_server.h"

static int initialized;

void keyb_priv_init(void)
{
	/* this must be initialized before starting port-server */
	keyb_8042_init();
	open_console();
}

void keyb_init(void)
{
	if (!keyb_server_init()) {
		error("can't init keyboard server\n");
		leavedos(19);
	}
	if (!keyb_client_init()) {
		error("can't open keyboard client\n");
		leavedos(19);
	}
	initialized = 1;
}

void keyb_reset(void)
{
	keyb_8042_reset();
	keyb_server_reset();
	keyb_client_reset();
}

void keyb_close(void)
{
	if (!initialized)
		return;
#if 0
	keyb_8042_close();
#endif
	keyb_server_close();
	keyb_client_close();
	initialized = 0;
}

CONSTRUCTOR(static void init(void))
{
	iodev_register("keyb", keyb_init, keyb_reset, keyb_close);
}
