/*
 * 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)
{
	open_console();
}

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

static void keyb_late_init(void)
{
	if (!keyb_client_init()) {
		error("can't open keyboard client\n");
		leavedos(19);
	}
}

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_client", keyb_late_init, NULL, NULL);
}
