Author: gonzo
Date: Thu May 12 20:15:23 2016
New Revision: 299566
URL: https://svnweb.freebsd.org/changeset/base/299566

Log:
  Fix detach routine for gpiokeys
  
  - Release pin only when all per=key callouts are stopped
  - Unregister keyboard when detaching device node

Modified:
  head/sys/dev/gpio/gpiokeys.c

Modified: head/sys/dev/gpio/gpiokeys.c
==============================================================================
--- head/sys/dev/gpio/gpiokeys.c        Thu May 12 20:14:44 2016        
(r299565)
+++ head/sys/dev/gpio/gpiokeys.c        Thu May 12 20:15:23 2016        
(r299566)
@@ -57,6 +57,8 @@ __FBSDID("$FreeBSD$");
 #include <dev/gpio/gpiobusvar.h>
 #include <dev/gpio/gpiokeys.h>
 
+#define        KBD_DRIVER_NAME "gpiokeys"
+
 #define        GPIOKEYS_LOCK(_sc)              mtx_lock(&(_sc)->sc_mtx)
 #define        GPIOKEYS_UNLOCK(_sc)            mtx_unlock(&(_sc)->sc_mtx)
 #define        GPIOKEYS_LOCK_INIT(_sc) \
@@ -357,12 +359,12 @@ gpiokeys_detach_key(struct gpiokeys_soft
        if (key->irq_res)
                bus_release_resource(sc->sc_dev, SYS_RES_IRQ,
                    key->irq_rid, key->irq_res);
-       if (key->pin)
-               gpio_pin_release(key->pin);
        if (callout_pending(&key->repeat_callout))
                callout_drain(&key->repeat_callout);
        if (callout_pending(&key->debounce_callout))
                callout_drain(&key->debounce_callout);
+       if (key->pin)
+               gpio_pin_release(key->pin);
        GPIOKEY_UNLOCK(key);
 
        GPIOKEY_LOCK_DESTROY(key);
@@ -397,7 +399,7 @@ gpiokeys_attach(device_t dev)
 
        GPIOKEYS_LOCK_INIT(sc);
        unit = device_get_unit(dev);
-       kbd_init_struct(kbd, "gpiokeys", KB_OTHER, unit, 0, 0, 0);
+       kbd_init_struct(kbd, KBD_DRIVER_NAME, KB_OTHER, unit, 0, 0, 0);
 
        kbd->kb_data = (void *)sc;
        sc->sc_mode = K_XLATE;
@@ -468,6 +470,7 @@ static int
 gpiokeys_detach(device_t dev)
 {
        struct gpiokeys_softc *sc;
+       keyboard_t *kbd;
        int i;
 
        sc = device_get_softc(dev);
@@ -475,6 +478,14 @@ gpiokeys_detach(device_t dev)
        for (i = 0; i < sc->sc_total_keys; i++)
                gpiokeys_detach_key(sc, &sc->sc_keys[i]);
 
+       kbd = kbd_get_keyboard(kbd_find_keyboard(KBD_DRIVER_NAME,
+           device_get_unit(dev)));
+
+#ifdef KBD_INSTALL_CDEV
+       kbd_detach(kbd);
+#endif
+       kbd_unregister(kbd);
+
        GPIOKEYS_LOCK_DESTROY(sc);
        if (sc->sc_keys)
                free(sc->sc_keys, M_DEVBUF);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to