2000-03-30 07:29:47 +04:00
|
|
|
/* $NetBSD: btnmgr.c,v 1.6 2000/03/30 03:29:47 sato Exp $ */
|
1999-12-23 09:26:08 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999
|
|
|
|
* Shin Takemura and PocketBSD Project. 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the PocketBSD project
|
|
|
|
* and its contributors.
|
|
|
|
* 4. Neither the name of the project nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
|
|
|
*
|
|
|
|
*/
|
2000-02-27 19:34:13 +03:00
|
|
|
#define BTNMGRDEBUG
|
1999-12-23 09:26:08 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
|
2000-03-12 15:08:16 +03:00
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
|
|
#include <dev/wscons/wskbdvar.h>
|
|
|
|
#include <dev/wscons/wsksymdef.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/autoconf.h>
|
1999-12-23 09:26:08 +03:00
|
|
|
#include <machine/config_hook.h>
|
|
|
|
|
2000-02-27 19:34:13 +03:00
|
|
|
#ifdef BTNMGRDEBUG
|
2000-03-14 11:37:31 +03:00
|
|
|
#ifndef BTNMGRDEBUG_CONF
|
|
|
|
#define BTNMGRDEBUG_CONF 0
|
|
|
|
#endif
|
|
|
|
int btnmgr_debug = BTNMGRDEBUG_CONF;
|
2000-02-27 19:34:13 +03:00
|
|
|
#define DPRINTF(arg) if (btnmgr_debug) printf arg;
|
|
|
|
#define DPRINTFN(n, arg) if (btnmgr_debug > (n)) printf arg;
|
|
|
|
#else
|
|
|
|
#define DPRINTF(arg)
|
|
|
|
#define DPRINTFN(n, arg)
|
|
|
|
#endif
|
|
|
|
|
1999-12-23 09:26:08 +03:00
|
|
|
cdev_decl(btnmgr);
|
|
|
|
|
|
|
|
struct btnmgr_softc {
|
2000-03-12 15:08:16 +03:00
|
|
|
struct device sc_dev;
|
1999-12-23 09:26:08 +03:00
|
|
|
config_hook_tag sc_hook_tag;
|
2000-03-12 15:08:16 +03:00
|
|
|
int sc_enabled;
|
|
|
|
struct device *sc_wskbddev;
|
1999-12-23 09:26:08 +03:00
|
|
|
};
|
|
|
|
|
2000-03-12 15:08:16 +03:00
|
|
|
/*
|
1999-12-23 09:26:08 +03:00
|
|
|
static struct btnmgr_softc *the_btnmgr_sc;
|
2000-03-12 15:08:16 +03:00
|
|
|
*/
|
1999-12-23 09:26:08 +03:00
|
|
|
|
2000-03-12 15:08:16 +03:00
|
|
|
/*
|
2000-02-27 19:34:13 +03:00
|
|
|
void btnmgrattach __P((int));
|
2000-03-12 15:08:16 +03:00
|
|
|
*/
|
|
|
|
int btnmgrmatch __P((struct device *, struct cfdata *, void *));
|
|
|
|
void btnmgrattach __P((struct device *, struct device *, void *));
|
2000-02-27 19:34:13 +03:00
|
|
|
char* btnmgr_name __P((long));
|
|
|
|
static int btnmgr_hook __P((void *, int, long, void *));
|
1999-12-23 09:26:08 +03:00
|
|
|
|
2000-03-12 15:08:16 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* global/static data
|
|
|
|
*/
|
|
|
|
struct cfattach btnmgr_ca = {
|
|
|
|
sizeof(struct btnmgr_softc), btnmgrmatch, btnmgrattach
|
|
|
|
};
|
|
|
|
|
|
|
|
/* wskbd accessopts */
|
|
|
|
int btnmgr_wskbd_enable __P((void *, int));
|
|
|
|
void btnmgr_wskbd_set_leds __P((void *, int));
|
|
|
|
int btnmgr_wskbd_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
|
|
|
|
|
|
|
|
const struct wskbd_accessops btnmgr_wskbd_accessops = {
|
|
|
|
btnmgr_wskbd_enable,
|
|
|
|
btnmgr_wskbd_set_leds,
|
|
|
|
btnmgr_wskbd_ioctl,
|
|
|
|
};
|
|
|
|
|
2000-03-14 11:37:31 +03:00
|
|
|
/* button config: index by buttun event id */
|
|
|
|
static const struct {
|
|
|
|
int kevent;
|
|
|
|
int keycode;
|
|
|
|
char *name;
|
|
|
|
} button_config[] = {
|
|
|
|
/* kevent keycode name id */
|
|
|
|
{ 0, 1, "Power" }, /* CONFIG_HOOK_BUTTONEVENT_POWER */
|
|
|
|
{ 1, 2, "OK" }, /* CONFIG_HOOK_BUTTONEVENT_OK */
|
|
|
|
{ 1, 3, "Cancel" }, /* CONFIG_HOOK_BUTTONEVENT_CANCEL */
|
|
|
|
{ 1, 4, "Up" }, /* CONFIG_HOOK_BUTTONEVENT_UP */
|
|
|
|
{ 1, 5, "Down" }, /* CONFIG_HOOK_BUTTONEVENT_DOWN */
|
|
|
|
{ 0, 6, "Rec" }, /* CONFIG_HOOK_BUTTONEVENT_REC */
|
|
|
|
{ 0, 7, "Cover" }, /* CONFIG_HOOK_BUTTONEVENT_COVER */
|
|
|
|
{ 0, 8, "Light" }, /* CONFIG_HOOK_BUTTONEVENT_LIGHT */
|
|
|
|
{ 0, 9, "Contrast" }, /* CONFIG_HOOK_BUTTONEVENT_CONTRAST */
|
|
|
|
{ 1, 10, "Application 0" },/* CONFIG_HOOK_BUTTONEVENT_APP0 */
|
|
|
|
{ 1, 11, "Application 1" },/* CONFIG_HOOK_BUTTONEVENT_APP1 */
|
|
|
|
{ 1, 12, "Application 2" },/* CONFIG_HOOK_BUTTONEVENT_APP2 */
|
|
|
|
{ 1, 13, "Application 3" },/* CONFIG_HOOK_BUTTONEVENT_APP3 */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int n_button_config =
|
|
|
|
sizeof(button_config) / sizeof(*button_config);
|
|
|
|
|
2000-02-27 19:34:13 +03:00
|
|
|
static const struct {
|
1999-12-23 09:26:08 +03:00
|
|
|
long id;
|
|
|
|
char *name;
|
|
|
|
} button_names[] = {
|
2000-03-12 15:08:16 +03:00
|
|
|
/* button id name key code */
|
|
|
|
{ CONFIG_HOOK_BUTTONEVENT_POWER, "Power" }, /* 1 */
|
|
|
|
{ CONFIG_HOOK_BUTTONEVENT_OK, "OK" }, /* 2 */
|
|
|
|
{ CONFIG_HOOK_BUTTONEVENT_CANCEL, "Cancel" }, /* 3 */
|
|
|
|
{ CONFIG_HOOK_BUTTONEVENT_UP, "Up" }, /* 4 */
|
|
|
|
{ CONFIG_HOOK_BUTTONEVENT_DOWN, "Down" }, /* 5 */
|
|
|
|
{ CONFIG_HOOK_BUTTONEVENT_REC, "Rec" }, /* 6 */
|
|
|
|
{ CONFIG_HOOK_BUTTONEVENT_COVER, "Cover" }, /* 7 */
|
|
|
|
{ CONFIG_HOOK_BUTTONEVENT_LIGHT, "Light" }, /* 8 */
|
|
|
|
{ CONFIG_HOOK_BUTTONEVENT_CONTRAST, "Contrast" }, /* 9 */
|
|
|
|
{ CONFIG_HOOK_BUTTONEVENT_APP0, "Application 0" }, /* 10 */
|
|
|
|
{ CONFIG_HOOK_BUTTONEVENT_APP1, "Application 1" }, /* 11 */
|
|
|
|
{ CONFIG_HOOK_BUTTONEVENT_APP2, "Application 2" }, /* 12 */
|
|
|
|
{ CONFIG_HOOK_BUTTONEVENT_APP3, "Application 3" }, /* 13 */
|
1999-12-23 09:26:08 +03:00
|
|
|
};
|
2000-02-27 19:34:13 +03:00
|
|
|
static const int n_button_names =
|
|
|
|
sizeof(button_names) / sizeof(*button_names);
|
1999-12-23 09:26:08 +03:00
|
|
|
|
2000-03-12 15:08:16 +03:00
|
|
|
#define KC(n) KS_KEYCODE(n)
|
|
|
|
static const keysym_t btnmgr_keydesc_default[] = {
|
|
|
|
/* pos normal shifted altgr shift-altgr */
|
2000-03-30 07:29:47 +04:00
|
|
|
KC(2), KS_Return,
|
|
|
|
KC(3), KS_Escape,
|
|
|
|
KC(4), KS_KP_Up,
|
|
|
|
KC(5), KS_KP_Down,
|
2000-03-14 11:37:31 +03:00
|
|
|
KC(10), KS_f9,
|
|
|
|
KC(11), KS_f10,
|
|
|
|
KC(12), KS_f11,
|
|
|
|
KC(13), KS_f12,
|
2000-03-12 15:08:16 +03:00
|
|
|
};
|
|
|
|
#undef KC
|
|
|
|
#define KBD_MAP(name, base, map) \
|
|
|
|
{ name, base, sizeof(map)/sizeof(keysym_t), map }
|
|
|
|
const struct wscons_keydesc btnmgr_keydesctab[] = {
|
2000-03-14 11:37:31 +03:00
|
|
|
KBD_MAP(KB_US, 0, btnmgr_keydesc_default),
|
2000-03-12 15:08:16 +03:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
#undef KBD_MAP
|
|
|
|
|
|
|
|
struct wskbd_mapdata btnmgr_keymapdata = {
|
|
|
|
btnmgr_keydesctab,
|
|
|
|
KB_US, /* XXX, This is bad idea... */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* function bodies
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
btnmgrmatch(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct mainbus_attach_args *ma = aux;
|
|
|
|
|
|
|
|
if (strcmp(ma->ma_name, match->cf_driver->cd_name))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
1999-12-23 09:26:08 +03:00
|
|
|
void
|
2000-03-12 15:08:16 +03:00
|
|
|
btnmgrattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1999-12-23 09:26:08 +03:00
|
|
|
{
|
|
|
|
int id;
|
2000-03-12 15:08:16 +03:00
|
|
|
struct btnmgr_softc *sc = (struct btnmgr_softc *)self;
|
|
|
|
struct wskbddev_attach_args wa;
|
1999-12-23 09:26:08 +03:00
|
|
|
|
2000-03-12 15:08:16 +03:00
|
|
|
printf("\n");
|
1999-12-23 09:26:08 +03:00
|
|
|
|
2000-03-12 15:08:16 +03:00
|
|
|
/*
|
|
|
|
* install button event listener
|
|
|
|
*/
|
1999-12-23 09:26:08 +03:00
|
|
|
for (id = 0; id < 16; id++)
|
2000-03-12 15:08:16 +03:00
|
|
|
sc->sc_hook_tag = config_hook(CONFIG_HOOK_BUTTONEVENT,
|
|
|
|
id, CONFIG_HOOK_SHARE,
|
|
|
|
btnmgr_hook, sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* attach wskbd
|
|
|
|
*/
|
|
|
|
wa.console = 0;
|
|
|
|
wa.keymap = &btnmgr_keymapdata;
|
|
|
|
wa.accessops = &btnmgr_wskbd_accessops;
|
|
|
|
wa.accesscookie = sc;
|
|
|
|
|
|
|
|
sc->sc_wskbddev = config_found(self, &wa, wskbddevprint);
|
1999-12-23 09:26:08 +03:00
|
|
|
}
|
|
|
|
|
2000-02-27 19:34:13 +03:00
|
|
|
static int
|
1999-12-23 09:26:08 +03:00
|
|
|
btnmgr_hook(ctx, type, id, msg)
|
|
|
|
void *ctx;
|
|
|
|
int type;
|
|
|
|
long id;
|
|
|
|
void *msg;
|
|
|
|
{
|
|
|
|
struct btnmgr_softc *sc = ctx;
|
|
|
|
|
2000-02-27 19:34:13 +03:00
|
|
|
DPRINTF(("%s button: %s\n", btnmgr_name(id), msg ? "ON" : "OFF"));
|
1999-12-23 09:26:08 +03:00
|
|
|
|
2000-03-14 11:37:31 +03:00
|
|
|
if (button_config[id].kevent)
|
|
|
|
wskbd_input(sc->sc_wskbddev,
|
|
|
|
msg ? WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP,
|
|
|
|
button_config[id].keycode);
|
2000-03-12 15:08:16 +03:00
|
|
|
|
1999-12-23 09:26:08 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
btnmgr_name(id)
|
|
|
|
long id;
|
|
|
|
{
|
2000-03-14 11:37:31 +03:00
|
|
|
if (id < n_button_config)
|
|
|
|
return button_config[id].name;
|
1999-12-23 09:26:08 +03:00
|
|
|
return ("unknown");
|
|
|
|
}
|
|
|
|
|
2000-03-12 15:08:16 +03:00
|
|
|
int
|
|
|
|
btnmgr_wskbd_enable(scx, on)
|
|
|
|
void *scx;
|
|
|
|
int on;
|
|
|
|
{
|
|
|
|
struct btnmgr_softc *sc = scx;
|
|
|
|
|
|
|
|
if (on) {
|
|
|
|
if (sc->sc_enabled)
|
|
|
|
return (EBUSY);
|
|
|
|
sc->sc_enabled = 1;
|
|
|
|
} else {
|
|
|
|
sc->sc_enabled = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
btnmgr_wskbd_set_leds(scx, leds)
|
|
|
|
void *scx;
|
|
|
|
int leds;
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We have nothing to do.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
btnmgr_wskbd_ioctl(scx, cmd, data, flag, p)
|
|
|
|
void *scx;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case WSKBDIO_GTYPE:
|
2000-03-13 04:46:44 +03:00
|
|
|
*(int *)data = WSKBD_TYPE_HPC_BTN;
|
2000-03-12 15:08:16 +03:00
|
|
|
return 0;
|
|
|
|
case WSKBDIO_SETLEDS:
|
|
|
|
DPRINTF(("%s(%d): no LED\n", __FILE__, __LINE__));
|
|
|
|
return 0;
|
|
|
|
case WSKBDIO_GETLEDS:
|
|
|
|
DPRINTF(("%s(%d): no LED\n", __FILE__, __LINE__));
|
|
|
|
*(int *)data = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1999-12-23 09:26:08 +03:00
|
|
|
#ifdef notyet
|
|
|
|
int
|
|
|
|
btnmgropen(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
btnmgrclose(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
btnmgrread(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flag;
|
|
|
|
{
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
btnmgrwrite(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flag;
|
|
|
|
{
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
btnmgrioctl(dev, cmd, data, flag, p)
|
|
|
|
dev_t dev;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
#endif /* notyet */
|