Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 May 2014 17:06:56 +0000 (UTC)
From:      Jakub Wojciech Klama <jceel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r266706 - in user/jceel/soc2014_evdev/head/sys: conf dev/evdev dev/usb/input
Message-ID:  <201405261706.s4QH6ueE055626@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jceel
Date: Mon May 26 17:06:56 2014
New Revision: 266706
URL: http://svnweb.freebsd.org/changeset/base/266706

Log:
  Add evdev support for ukbd(4) and USB HID to evdev scancode map.

Added:
  user/jceel/soc2014_evdev/head/sys/dev/evdev/evdev_utils.c   (contents, props changed)
Modified:
  user/jceel/soc2014_evdev/head/sys/conf/files
  user/jceel/soc2014_evdev/head/sys/dev/evdev/evdev.h
  user/jceel/soc2014_evdev/head/sys/dev/usb/input/ukbd.c

Modified: user/jceel/soc2014_evdev/head/sys/conf/files
==============================================================================
--- user/jceel/soc2014_evdev/head/sys/conf/files	Mon May 26 17:06:27 2014	(r266705)
+++ user/jceel/soc2014_evdev/head/sys/conf/files	Mon May 26 17:06:56 2014	(r266706)
@@ -1363,6 +1363,7 @@ dev/etherswitch/rtl8366/rtl8366rb.c	opti
 dev/etherswitch/ukswitch/ukswitch.c	optional ukswitch
 dev/evdev/evdev.c			optional evdev
 dev/evdev/cdev.c			optional evdev
+dev/evdev/evdev_utils.c			optional evdev
 dev/ex/if_ex.c			optional ex
 dev/ex/if_ex_isa.c		optional ex isa
 dev/ex/if_ex_pccard.c		optional ex pccard

Modified: user/jceel/soc2014_evdev/head/sys/dev/evdev/evdev.h
==============================================================================
--- user/jceel/soc2014_evdev/head/sys/dev/evdev/evdev.h	Mon May 26 17:06:27 2014	(r266705)
+++ user/jceel/soc2014_evdev/head/sys/dev/evdev/evdev.h	Mon May 26 17:06:56 2014	(r266706)
@@ -136,4 +136,8 @@ void evdev_support_sw(struct evdev_dev *
 int evdev_register_client(struct evdev_dev *, struct evdev_client **);
 int evdev_dispose_client(struct evdev_client *);
 
+/* Utility functions: */
+uint16_t evdev_hid2key(int);
+uint16_t evdev_at2key(int);
+
 #endif	/* _DEV_EVDEV_EVDEV_H */

Added: user/jceel/soc2014_evdev/head/sys/dev/evdev/evdev_utils.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/jceel/soc2014_evdev/head/sys/dev/evdev/evdev_utils.c	Mon May 26 17:06:56 2014	(r266706)
@@ -0,0 +1,128 @@
+/*-
+ * Copyright (c) 2014 Jakub Wojciech Klama <jceel@FreeBSD.org>
+ * 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 AUTHOR 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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/conf.h>
+#include <sys/malloc.h>
+
+#include <dev/evdev/input.h>
+#include <dev/evdev/evdev.h>
+
+#define	NONE	KEY_RESERVED
+
+static uint16_t evdev_usb_scancodes[256] = {
+	/* 0x00 - 0x27 */
+	NONE,	NONE,	NONE,	NONE,	KEY_A,	KEY_B,	KEY_C,	KEY_D,
+	KEY_E,	KEY_F,	KEY_G,	KEY_H,	KEY_I,	KEY_J,	KEY_K,	KEY_L,
+	KEY_M,	KEY_N,	KEY_O,	KEY_P,	KEY_Q,	KEY_R,	KEY_S,	KEY_T,
+	KEY_U,	KEY_V,	KEY_W,	KEY_X,	KEY_Y,	KEY_Z,	KEY_1,	KEY_2,
+	KEY_3,	KEY_4,	KEY_5,	KEY_6,	KEY_7,	KEY_8,	KEY_9,	KEY_0,
+	/* 0x28 - 0x3f */
+	KEY_ENTER,	KEY_ESC,	KEY_BACKSPACE,	KEY_TAB, 
+	KEY_SPACE,	KEY_MINUS,	KEY_EQUAL,	KEY_LEFTBRACE, 
+	KEY_RIGHTBRACE,	KEY_BACKSLASH,	NONE,		KEY_SEMICOLON,
+	KEY_APOSTROPHE,	KEY_GRAVE,	KEY_COMMA,	KEY_DOT, 
+	KEY_SLASH,	KEY_CAPSLOCK,	KEY_F1,		KEY_F2,
+	KEY_F3,		KEY_F4,		KEY_F5,		KEY_F6,
+	/* 0x40 - 0x5f */
+	KEY_F7, 	KEY_F8,		KEY_F9,		KEY_F10, 
+	KEY_F11, 	KEY_F12,	KEY_SYSRQ,	KEY_SCROLLLOCK,
+	KEY_PAUSE,	KEY_INSERT,	KEY_HOME,	KEY_PAGEUP,
+	KEY_DELETE,	KEY_END,	KEY_PAGEDOWN,	KEY_RIGHT,
+	KEY_LEFT,	KEY_DOWN,	KEY_UP,		KEY_NUMLOCK,
+	KEY_SLASH,	KEY_KPASTERISK,	KEY_KPMINUS,	KEY_KPPLUS,
+	KEY_KPENTER,	KEY_KP1,	KEY_KP2,	KEY_KP3,
+	KEY_KP4,	NONE,		KEY_KP6,	KEY_KP7,
+	/* 0x60 - 0x7f */
+	KEY_KP8,	KEY_KP9,	KEY_KP0,	KEY_KPDOT,
+	NONE,		NONE, /* XXX */	KEY_F13,	KEY_F14,
+	KEY_F15,	KEY_F16,	KEY_F17,	KEY_F18,
+	KEY_F19,	KEY_F20,	KEY_F21,	KEY_F22,
+	KEY_F23,	KEY_F24,	KEY_HELP,	KEY_UNDO,
+	KEY_CUT,	KEY_COPY,	KEY_PASTE,	KEY_MUTE,
+	KEY_VOLUMEUP,	KEY_VOLUMEDOWN,	NONE,		KEY_KATAKANA,
+	NONE,		NONE,		KEY_HIRAGANA,	NONE,
+	/* 0x80 - 0x9f */
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		KEY_KP5,	NONE,
+	NONE,		KEY_SYSRQ,	NONE,		KEY_CLEAR,
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,	
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	/* 0xa0 - 0xbf */
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	NONE, 		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	/* 0xc0 - 0xdf */
+	NONE,		NONE,		NONE,		NONE,
+	NONE, 		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	/* 0xe0 - 0xff */
+	KEY_LEFTCTRL,	KEY_LEFTSHIFT,	KEY_LEFTALT,	KEY_LEFTMETA,
+	KEY_RIGHTCTRL,	KEY_RIGHTSHIFT,	KEY_RIGHTALT,	KEY_RIGHTMETA,	
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	NONE, 		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+	NONE,		NONE,		NONE,		NONE,
+
+};
+
+static uint16_t evdev_at_set1_scancodes[256] = {
+	NONE,
+};
+	
+
+inline uint16_t
+evdev_hid2key(int scancode)
+{
+	return evdev_usb_scancodes[scancode];
+}
+
+inline uint16_t
+evdev_at2key(int scancode)
+{
+	return evdev_at_set1_scancodes[scancode];
+}

Modified: user/jceel/soc2014_evdev/head/sys/dev/usb/input/ukbd.c
==============================================================================
--- user/jceel/soc2014_evdev/head/sys/dev/usb/input/ukbd.c	Mon May 26 17:06:27 2014	(r266705)
+++ user/jceel/soc2014_evdev/head/sys/dev/usb/input/ukbd.c	Mon May 26 17:06:56 2014	(r266706)
@@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
 #include "opt_compat.h"
 #include "opt_kbd.h"
 #include "opt_ukbd.h"
+#include "opt_evdev.h"
 
 #include <sys/stdint.h>
 #include <sys/stddef.h>
@@ -73,6 +74,11 @@ __FBSDID("$FreeBSD$");
 
 #include <dev/usb/quirk/usb_quirk.h>
 
+#ifdef EVDEV
+#include <dev/evdev/input.h>
+#include <dev/evdev/evdev.h>
+#endif
+
 #include <sys/ioccom.h>
 #include <sys/filio.h>
 #include <sys/tty.h>
@@ -164,6 +170,9 @@ struct ukbd_softc {
 	struct usb_device *sc_udev;
 	struct usb_interface *sc_iface;
 	struct usb_xfer *sc_xfer[UKBD_N_TRANSFER];
+#ifdef EVDEV
+	struct evdev_dev *sc_evdev;
+#endif /* EVDEV */
 
 	uint32_t sc_ntime[UKBD_NKEYCODE];
 	uint32_t sc_otime[UKBD_NKEYCODE];
@@ -374,6 +383,13 @@ static device_attach_t ukbd_attach;
 static device_detach_t ukbd_detach;
 static device_resume_t ukbd_resume;
 
+#ifdef EVDEV
+static struct evdev_methods ukbd_evdev_methods = {
+	.ev_open = NULL,
+	.ev_close = NULL,
+};
+#endif
+
 static uint8_t
 ukbd_any_key_pressed(struct ukbd_softc *sc)
 {
@@ -402,6 +418,11 @@ ukbd_put_key(struct ukbd_softc *sc, uint
 	DPRINTF("0x%02x (%d) %s\n", key, key,
 	    (key & KEY_RELEASE) ? "released" : "pressed");
 
+#ifdef EVDEV
+	evdev_push_event(sc->sc_evdev, EV_KEY, evdev_hid2key(KEY_INDEX(key)), !(key & KEY_RELEASE));
+	evdev_sync(sc->sc_evdev);
+#endif
+
 	if (sc->sc_inputs < UKBD_IN_BUF_SIZE) {
 		sc->sc_input[sc->sc_inputtail] = key;
 		++(sc->sc_inputs);
@@ -1180,6 +1201,9 @@ ukbd_attach(device_t dev)
 	usb_error_t err;
 	uint16_t n;
 	uint16_t hid_len;
+#ifdef EVDEV
+	int i;
+#endif
 #ifdef USB_DEBUG
 	int rate;
 #endif
@@ -1277,6 +1301,21 @@ ukbd_attach(device_t dev)
 		goto detach;
 	}
 #endif
+
+#ifdef EVDEV
+	sc->sc_evdev = evdev_alloc();
+	evdev_set_name(sc->sc_evdev, device_get_desc(dev));
+	evdev_set_serial(sc->sc_evdev, "0");
+	evdev_set_methods(sc->sc_evdev, &ukbd_evdev_methods);
+	evdev_support_event(sc->sc_evdev, EV_SYN);
+	evdev_support_event(sc->sc_evdev, EV_KEY);
+
+	for (i = 0x01; i < 0x59; i++)
+		evdev_support_key(sc->sc_evdev, i);
+
+	evdev_register(dev, sc->sc_evdev);
+#endif
+
 	sc->sc_flags |= UKBD_FLAG_ATTACHED;
 
 	if (bootverbose) {
@@ -1344,6 +1383,12 @@ ukbd_detach(device_t dev)
 		}
 	}
 #endif
+
+#ifdef EVDEV
+	if (sc->sc_flags & UKBD_FLAG_ATTACHED)
+		evdev_unregister(dev, sc->sc_evdev);
+#endif
+
 	if (KBD_IS_CONFIGURED(&sc->sc_kbd)) {
 		error = kbd_unregister(&sc->sc_kbd);
 		if (error) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405261706.s4QH6ueE055626>