Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 25 Mar 2007 11:57:17 +1000
From:      Timothy Bourke <timbob@bigpond.com>
To:        hackers@freebsd.org
Subject:   enable/disable in kbd drivers
Message-ID:  <20070325015717.GA797@triptrop>

next in thread | raw e-mail | index | archive | help

--5I6of5zJg18YgZEa
Content-Type: multipart/mixed; boundary="DocE+STaALJfprDB"
Content-Disposition: inline


--DocE+STaALJfprDB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

I have almost finished a ppbus-based driver for Super Nintendo
controllers. It presents itself as a keyboard to the operating system. I
wanted to start and stop the polling thread via, respectively, the
kbd_enable_t and kbd_disable_t hooks, but these do not seem to be called
properly. Hence this post.

The enable and disable functions are identical across the keyboard
drivers (atkbd, ukbd, vkbd, kbdmux). Enable calls the KBD_ACTIVATE macro
which increments the kb_active count. Disable calls the KBD_DEACTIVATE
macro which decrements the kb_active count. It seems reasonable to
assume that the two functions should be called in pairs.

However, enable is called too many times and disable is never called.

In the kbdmux_ioctl routine:
    KBADDKBD: enable is called via the KBDMUX_ENABLE macro.
    KBRELKBD: does NOT call disable

Taking dev/usb/ukbd.c as an example, the effect can be seen by adding
this line to the ukbd_enable function (after the call to KBD_ACTIVATE):
    printf("ukbd_enable: %d\n", KBD_IS_ACTIVE(kbd));
And similarly for ukbd_disable and then running dmesg or kbdcontrol.

Additionally, each kbd driver calls its own enable function when
attached. For example, in USB_ATTACH(ukbd):
    (*sw->enable)(kbd);
This would appear to be unnecessary for keyboards connected via kbdmux.
I am less certain about those connected directly, but the syscons
sccngetch routine does seems to call enable and disable. Perhaps it
should also call enable when it first starts?

Does the attached patch seem reasonable? It would fix my immediate
problem.

I could write a patch to remove the calls to enable in the driver init
routines but tI don't really understand how syscons works.

Tim.


--DocE+STaALJfprDB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="kbdmux.patch"
Content-Transfer-Encoding: quoted-printable

--- sys/dev/kbdmux/kbdmux.c.orig	Sun Mar 25 11:33:57 2007
+++ sys/dev/kbdmux/kbdmux.c	Sun Mar 25 11:36:46 2007
@@ -132,6 +132,9 @@
 #define	KBDMUX_ENABLE(kbd) \
 	(*kbdsw[(kbd)->kb_index]->enable)((kbd))
=20
+#define	KBDMUX_DISABLE(kbd) \
+	(*kbdsw[(kbd)->kb_index]->disable)((kbd))
+
 #define	KBDMUX_POLL(kbd, on) \
 	(*kbdsw[(kbd)->kb_index]->poll)((kbd), (on))
=20
@@ -1029,6 +1032,7 @@
 				break;
=20
 		if (k !=3D NULL) {
+			KBDMUX_DISABLE(k->kbd);
 			error =3D kbd_release(k->kbd, &k->kbd);
 			if (error =3D=3D 0) {
 				SLIST_REMOVE(&state->ks_kbds, k, kbdmux_kbd, next);

--DocE+STaALJfprDB--

--5I6of5zJg18YgZEa
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.4 (FreeBSD)

iD8DBQFGBdb9tKVK1sFb0ecRAoAfAJ4jPcRes/YX2/vRszKrTrcF0qCgPwCfaCUr
VL6Gbe+4v06Rhjr+LRFZLtQ=
=MJce
-----END PGP SIGNATURE-----

--5I6of5zJg18YgZEa--



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