Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Factor out bus-independant HID code so that it can be sh...



details:   https://anonhg.NetBSD.org/src/rev/bdc87bbbf97a
branches:  trunk
changeset: 828381:bdc87bbbf97a
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Sun Dec 10 17:03:07 2017 +0000

description:
Factor out bus-independant HID code so that it can be shared by USB, bluetooth
and i2c.
dev/usb/ukbdmap.c is renamed to dev/hid/hidkbdmap.c
dev/usb/hid.[ch] moved to dev/hid/
usage pages moved from dev/usb/usbhid.h moved to dev/hid/hid.h,
and updated with OpenBSD entries.
bus-independant code moved from dev/usb/ums.c to dev/hid/hidms.c
(the same should be done for keyboard and touchpad drivers)

Needed for the upcoming HID over I2C support, proposed on tech-kern@
on Dec, 1.

diffstat:

 sys/conf/files              |    9 +-
 sys/dev/bluetooth/bthidev.c |    6 +-
 sys/dev/bluetooth/btkbd.c   |   10 +-
 sys/dev/bluetooth/btmagic.c |    6 +-
 sys/dev/bluetooth/btms.c    |    6 +-
 sys/dev/fdt/gpiokeys.c      |    8 +-
 sys/dev/hid/files.hid       |   13 +
 sys/dev/hid/hid.c           |  533 +++++++++++++++++++++++++++++++++++
 sys/dev/hid/hid.h           |  422 ++++++++++++++++++++++++++++
 sys/dev/hid/hidkbdmap.c     |  658 ++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/hid/hidms.c         |  290 +++++++++++++++++++
 sys/dev/hid/hidms.h         |   63 ++++
 sys/dev/i2c/tcakp.c         |    8 +-
 sys/dev/usb/files.usb       |    5 +-
 sys/dev/usb/hid.c           |  533 -----------------------------------
 sys/dev/usb/hid.h           |   89 -----
 sys/dev/usb/uatp.c          |    6 +-
 sys/dev/usb/ucycom.c        |    6 +-
 sys/dev/usb/uhid.c          |    6 +-
 sys/dev/usb/uhidev.c        |    6 +-
 sys/dev/usb/ukbd.c          |   10 +-
 sys/dev/usb/ukbdmap.c       |  658 --------------------------------------------
 sys/dev/usb/ums.c           |  288 +-----------------
 sys/dev/usb/usbhid.h        |  130 +--------
 sys/dev/usb/uthum.c         |    6 +-
 sys/dev/usb/uts.c           |    6 +-
 sys/dev/usb/uyurex.c        |    6 +-
 27 files changed, 2063 insertions(+), 1724 deletions(-)

diffs (truncated from 4300 to 300 lines):

diff -r 6d9b6eb65b24 -r bdc87bbbf97a sys/conf/files
--- a/sys/conf/files    Sun Dec 10 16:53:32 2017 +0000
+++ b/sys/conf/files    Sun Dec 10 17:03:07 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.1185 2017/11/25 16:31:03 jmcneill Exp $
+#      $NetBSD: files,v 1.1186 2017/12/10 17:03:07 bouyer Exp $
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
 version        20171118
@@ -379,6 +379,9 @@
 device spdmem
 file   dev/ic/spdmem.c                 spdmem
 
+# Generic HID support (used by USB, bluetooth and i2c)
+include "dev/hid/files.hid"
+
 # I2C device support
 include "dev/i2c/files.i2c"
 
@@ -1291,10 +1294,6 @@
 #
 include "external/bsd/dwc2/conf/files.dwc2"
 
-# USB HID processing (as used by bluetooth and usb code)
-define hid
-file   dev/usb/hid.c                   hid
-
 # SD Host controller
 device sdhc: sdmmcbus
 file   dev/sdmmc/sdhc.c                sdhc                    needs-flag
diff -r 6d9b6eb65b24 -r bdc87bbbf97a sys/dev/bluetooth/bthidev.c
--- a/sys/dev/bluetooth/bthidev.c       Sun Dec 10 16:53:32 2017 +0000
+++ b/sys/dev/bluetooth/bthidev.c       Sun Dec 10 17:03:07 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bthidev.c,v 1.29 2014/08/05 07:55:31 rtr Exp $ */
+/*     $NetBSD: bthidev.c,v 1.30 2017/12/10 17:03:07 bouyer Exp $      */
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bthidev.c,v 1.29 2014/08/05 07:55:31 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bthidev.c,v 1.30 2017/12/10 17:03:07 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/condvar.h>
@@ -54,7 +54,7 @@
 #include <netbt/bluetooth.h>
 #include <netbt/l2cap.h>
 
-#include <dev/usb/hid.h>
+#include <dev/hid/hid.h>
 #include <dev/bluetooth/btdev.h>
 #include <dev/bluetooth/bthid.h>
 #include <dev/bluetooth/bthidev.h>
diff -r 6d9b6eb65b24 -r bdc87bbbf97a sys/dev/bluetooth/btkbd.c
--- a/sys/dev/bluetooth/btkbd.c Sun Dec 10 16:53:32 2017 +0000
+++ b/sys/dev/bluetooth/btkbd.c Sun Dec 10 17:03:07 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: btkbd.c,v 1.17 2014/11/16 16:20:00 ozaki-r Exp $       */
+/*     $NetBSD: btkbd.c,v 1.18 2017/12/10 17:03:07 bouyer Exp $        */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: btkbd.c,v 1.17 2014/11/16 16:20:00 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: btkbd.c,v 1.18 2017/12/10 17:03:07 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/callout.h>
@@ -81,7 +81,7 @@
 #include <dev/bluetooth/bthid.h>
 #include <dev/bluetooth/bthidev.h>
 
-#include <dev/usb/hid.h>
+#include <dev/hid/hid.h>
 #include <dev/usb/usb.h>
 #include <dev/usb/usbhid.h>
 
@@ -163,10 +163,10 @@
 };
 
 /* wskbd(4) keymap data */
-extern const struct wscons_keydesc ukbd_keydesctab[];
+extern const struct wscons_keydesc hidkbd_keydesctab[];
 
 const struct wskbd_mapdata btkbd_keymapdata = {
-       ukbd_keydesctab,
+       hidkbd_keydesctab,
 #if defined(BTKBD_LAYOUT)
        BTKBD_LAYOUT,
 #elif defined(PCKBD_LAYOUT)
diff -r 6d9b6eb65b24 -r bdc87bbbf97a sys/dev/bluetooth/btmagic.c
--- a/sys/dev/bluetooth/btmagic.c       Sun Dec 10 16:53:32 2017 +0000
+++ b/sys/dev/bluetooth/btmagic.c       Sun Dec 10 17:03:07 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: btmagic.c,v 1.16 2016/07/07 06:55:41 msaitoh Exp $     */
+/*     $NetBSD: btmagic.c,v 1.17 2017/12/10 17:03:07 bouyer Exp $      */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -85,7 +85,7 @@
  *****************************************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: btmagic.c,v 1.16 2016/07/07 06:55:41 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: btmagic.c,v 1.17 2017/12/10 17:03:07 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -108,7 +108,7 @@
 #include <dev/bluetooth/bthid.h>
 #include <dev/bluetooth/bthidev.h>
 
-#include <dev/usb/hid.h>
+#include <dev/hid/hid.h>
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdevs.h>
 
diff -r 6d9b6eb65b24 -r bdc87bbbf97a sys/dev/bluetooth/btms.c
--- a/sys/dev/bluetooth/btms.c  Sun Dec 10 16:53:32 2017 +0000
+++ b/sys/dev/bluetooth/btms.c  Sun Dec 10 17:03:07 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: btms.c,v 1.12 2014/12/13 19:28:55 nonaka Exp $ */
+/*     $NetBSD: btms.c,v 1.13 2017/12/10 17:03:07 bouyer Exp $ */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: btms.c,v 1.12 2014/12/13 19:28:55 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: btms.c,v 1.13 2017/12/10 17:03:07 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -79,7 +79,7 @@
 #include <dev/bluetooth/bthid.h>
 #include <dev/bluetooth/bthidev.h>
 
-#include <dev/usb/hid.h>
+#include <dev/hid/hid.h>
 #include <dev/usb/usb.h>
 #include <dev/usb/usbhid.h>
 
diff -r 6d9b6eb65b24 -r bdc87bbbf97a sys/dev/fdt/gpiokeys.c
--- a/sys/dev/fdt/gpiokeys.c    Sun Dec 10 16:53:32 2017 +0000
+++ b/sys/dev/fdt/gpiokeys.c    Sun Dec 10 17:03:07 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gpiokeys.c,v 1.5 2017/09/23 23:54:30 jmcneill Exp $ */
+/* $NetBSD: gpiokeys.c,v 1.6 2017/12/10 17:03:07 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gpiokeys.c,v 1.5 2017/09/23 23:54:30 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gpiokeys.c,v 1.6 2017/12/10 17:03:07 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -59,9 +59,9 @@
 static void    gpiokeys_tick(void *);
 static void    gpiokeys_task(void *);
 
-extern const struct wscons_keydesc ukbd_keydesctab[];
+extern const struct wscons_keydesc hidkbd_keydesctab[];
 static const struct wskbd_mapdata gpiokeys_keymapdata = {
-       ukbd_keydesctab,
+       hidkbd_keydesctab,
        KB_US,
 };
 
diff -r 6d9b6eb65b24 -r bdc87bbbf97a sys/dev/hid/files.hid
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/hid/files.hid     Sun Dec 10 17:03:07 2017 +0000
@@ -0,0 +1,13 @@
+#       $NetBSD: files.hid,v 1.1 2017/12/10 17:03:07 bouyer Exp $
+
+# Human Interface Devices
+# Used by USB, bluetooth and i2c
+
+# HID processing
+define  hid
+file    dev/hid/hid.c                  hid
+
+define hidms
+file    dev/hid/hidms.c                        hidms
+
+file   dev/hid/hidkbdmap.c             ukbd | btkbd | linux_keymap
diff -r 6d9b6eb65b24 -r bdc87bbbf97a sys/dev/hid/hid.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/hid/hid.c Sun Dec 10 17:03:07 2017 +0000
@@ -0,0 +1,533 @@
+/*     $NetBSD: hid.c,v 1.1 2017/12/10 17:03:07 bouyer Exp $   */
+/*     $FreeBSD: src/sys/dev/usb/hid.c,v 1.11 1999/11/17 22:33:39 n_hibma Exp $ */
+
+/*
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Lennart Augustsson (lennart%augustsson.net@localhost) at
+ * Carlstedt Research & Technology.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: hid.c,v 1.1 2017/12/10 17:03:07 bouyer Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_usb.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/kmem.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbhid.h>
+
+#include <dev/hid/hid.h>
+
+#ifdef UHIDEV_DEBUG
+#define DPRINTF(x)     if (uhidevdebug) printf x
+#define DPRINTFN(n,x)  if (uhidevdebug>(n)) printf x
+extern int uhidevdebug;
+#else
+#define DPRINTF(x)
+#define DPRINTFN(n,x)
+#endif
+
+Static void hid_clear_local(struct hid_item *);
+
+#define MAXUSAGE 256
+struct hid_data {
+       const u_char *start;
+       const u_char *end;
+       const u_char *p;
+       struct hid_item cur;
+       int32_t usages[MAXUSAGE];
+       int nu;
+       int minset;
+       int multi;
+       int multimax;
+       enum hid_kind kind;
+};
+
+Static void
+hid_clear_local(struct hid_item *c)
+{
+
+       DPRINTFN(5,("hid_clear_local\n"));
+       c->usage = 0;
+       c->usage_minimum = 0;
+       c->usage_maximum = 0;
+       c->designator_index = 0;
+       c->designator_minimum = 0;
+       c->designator_maximum = 0;
+       c->string_index = 0;
+       c->string_minimum = 0;
+       c->string_maximum = 0;
+       c->set_delimiter = 0;
+}
+
+struct hid_data *
+hid_start_parse(const void *d, int len, enum hid_kind kind)
+{
+       struct hid_data *s;
+
+       s = kmem_zalloc(sizeof(*s), KM_SLEEP);



Home | Main Index | Thread Index | Old Index