From owner-svn-src-stable@freebsd.org Mon Sep 7 06:14:43 2020 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1AB2D3EA34E; Mon, 7 Sep 2020 06:14:43 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BlJ0L6t93z3Rcg; Mon, 7 Sep 2020 06:14:42 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B6F0C1B21A; Mon, 7 Sep 2020 06:14:42 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0876EgMo026782; Mon, 7 Sep 2020 06:14:42 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0876EgED026781; Mon, 7 Sep 2020 06:14:42 GMT (envelope-from avg@FreeBSD.org) Message-Id: <202009070614.0876EgED026781@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Mon, 7 Sep 2020 06:14:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r365392 - stable/12/sys/dev/gpio X-SVN-Group: stable-12 X-SVN-Commit-Author: avg X-SVN-Commit-Paths: stable/12/sys/dev/gpio X-SVN-Commit-Revision: 365392 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Sep 2020 06:14:43 -0000 Author: avg Date: Mon Sep 7 06:14:42 2020 New Revision: 365392 URL: https://svnweb.freebsd.org/changeset/base/365392 Log: MFC r364145: gpiokeys: add evdev support Only linux,code is supported as it maps 1:1 to evdev key codes. No reverse mapping for freebsd,code yet. Modified: stable/12/sys/dev/gpio/gpiokeys.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/dev/gpio/gpiokeys.c ============================================================================== --- stable/12/sys/dev/gpio/gpiokeys.c Sun Sep 6 20:32:13 2020 (r365391) +++ stable/12/sys/dev/gpio/gpiokeys.c Mon Sep 7 06:14:42 2020 (r365392) @@ -29,6 +29,7 @@ __FBSDID("$FreeBSD$"); #include "opt_platform.h" #include "opt_kbd.h" +#include "opt_evdev.h" #include #include @@ -56,6 +57,11 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef EVDEV_SUPPORT +#include +#include +#endif + #define KBD_DRIVER_NAME "gpiokeys" #define GPIOKEYS_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) @@ -99,6 +105,9 @@ struct gpiokey struct resource *irq_res; void *intr_hl; struct mtx mtx; +#ifdef EVDEV_SUPPORT + uint32_t evcode; +#endif uint32_t keycode; int autorepeat; struct callout debounce_callout; @@ -115,6 +124,9 @@ struct gpiokeys_softc struct gpiokey *sc_keys; int sc_total_keys; +#ifdef EVDEV_SUPPORT + struct evdev_dev *sc_evdev; +#endif keyboard_t sc_kbd; keymap_t sc_keymap; accentmap_t sc_accmap; @@ -171,26 +183,34 @@ gpiokeys_put_key(struct gpiokeys_softc *sc, uint32_t k } static void -gpiokeys_key_event(struct gpiokeys_softc *sc, uint16_t keycode, int pressed) +gpiokeys_key_event(struct gpiokeys_softc *sc, struct gpiokey *key, int pressed) { - uint32_t key; + uint32_t code; - - key = keycode & SCAN_KEYCODE_MASK; - - if (!pressed) - key |= KEY_RELEASE; - GPIOKEYS_LOCK(sc); - if (keycode & SCAN_PREFIX_E0) - gpiokeys_put_key(sc, 0xe0); - else if (keycode & SCAN_PREFIX_E1) - gpiokeys_put_key(sc, 0xe1); +#ifdef EVDEV_SUPPORT + if (key->evcode != GPIOKEY_NONE && + (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD) != 0) { + evdev_push_key(sc->sc_evdev, key->evcode, pressed); + evdev_sync(sc->sc_evdev); + } +#endif + if (key->keycode != GPIOKEY_NONE) { + code = key->keycode & SCAN_KEYCODE_MASK; + if (!pressed) + code |= KEY_RELEASE; - gpiokeys_put_key(sc, key); + if (key->keycode & SCAN_PREFIX_E0) + gpiokeys_put_key(sc, 0xe0); + else if (key->keycode & SCAN_PREFIX_E1) + gpiokeys_put_key(sc, 0xe1); + + gpiokeys_put_key(sc, code); + } GPIOKEYS_UNLOCK(sc); - gpiokeys_event_keyinput(sc); + if (key->keycode != GPIOKEY_NONE) + gpiokeys_event_keyinput(sc); } static void @@ -200,11 +220,8 @@ gpiokey_autorepeat(void *arg) key = arg; - if (key->keycode == GPIOKEY_NONE) - return; + gpiokeys_key_event(key->parent_sc, key, 1); - gpiokeys_key_event(key->parent_sc, key->keycode, 1); - callout_reset(&key->repeat_callout, key->repeat, gpiokey_autorepeat, key); } @@ -217,12 +234,9 @@ gpiokey_debounced_intr(void *arg) key = arg; - if (key->keycode == GPIOKEY_NONE) - return; - gpio_pin_is_active(key->pin, &active); if (active) { - gpiokeys_key_event(key->parent_sc, key->keycode, 1); + gpiokeys_key_event(key->parent_sc, key, 1); if (key->autorepeat) { callout_reset(&key->repeat_callout, key->repeat_delay, gpiokey_autorepeat, key); @@ -232,7 +246,7 @@ gpiokey_debounced_intr(void *arg) if (key->autorepeat && callout_pending(&key->repeat_callout)) callout_stop(&key->repeat_callout); - gpiokeys_key_event(key->parent_sc, key->keycode, 0); + gpiokeys_key_event(key->parent_sc, key, 0); } } @@ -301,6 +315,10 @@ gpiokeys_attach_key(struct gpiokeys_softc *sc, phandle if (key->keycode == GPIOKEY_NONE) device_printf(sc->sc_dev, "<%s> failed to map linux,code value 0x%x\n", key_name, code); +#ifdef EVDEV_SUPPORT + key->evcode = code; + evdev_support_key(sc->sc_evdev, code); +#endif } else device_printf(sc->sc_dev, "<%s> no linux,code or freebsd,code property\n", @@ -365,7 +383,6 @@ gpiokeys_detach_key(struct gpiokeys_softc *sc, struct if (key->pin) gpio_pin_release(key->pin); GPIOKEY_UNLOCK(key); - GPIOKEY_LOCK_DESTROY(key); } @@ -383,11 +400,14 @@ gpiokeys_probe(device_t dev) static int gpiokeys_attach(device_t dev) { - int unit; struct gpiokeys_softc *sc; keyboard_t *kbd; +#ifdef EVDEV_SUPPORT + char *name; +#endif phandle_t keys, child; int total_keys; + int unit; if ((keys = ofw_bus_get_node(dev)) == -1) return (ENXIO); @@ -435,6 +455,19 @@ gpiokeys_attach(device_t dev) kbdd_diag(kbd, 1); } +#ifdef EVDEV_SUPPORT + sc->sc_evdev = evdev_alloc(); + evdev_set_name(sc->sc_evdev, device_get_desc(dev)); + + OF_getprop_alloc(keys, "name", (void **)&name); + evdev_set_phys(sc->sc_evdev, name != NULL ? name : "unknown"); + OF_prop_free(name); + + evdev_set_id(sc->sc_evdev, BUS_VIRTUAL, 0, 0, 0); + evdev_support_event(sc->sc_evdev, EV_SYN); + evdev_support_event(sc->sc_evdev, EV_KEY); +#endif + total_keys = 0; /* Traverse the 'gpio-keys' node and count keys */ @@ -458,6 +491,13 @@ gpiokeys_attach(device_t dev) } } +#ifdef EVDEV_SUPPORT + if (evdev_register_mtx(sc->sc_evdev, &sc->sc_mtx) != 0) { + device_printf(dev, "failed to register evdev device\n"); + goto detach; + } +#endif + return (0); detach: @@ -484,6 +524,10 @@ gpiokeys_detach(device_t dev) kbd_detach(kbd); #endif kbd_unregister(kbd); + +#ifdef EVDEV_SUPPORT + evdev_free(sc->sc_evdev); +#endif GPIOKEYS_LOCK_DESTROY(sc); if (sc->sc_keys)