From owner-freebsd-usb@FreeBSD.ORG Mon Dec 24 11:20:03 2007 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0211116A418 for ; Mon, 24 Dec 2007 11:20:03 +0000 (UTC) (envelope-from rpaulo@gmail.com) Received: from fk-out-0910.google.com (fk-out-0910.google.com [209.85.128.185]) by mx1.freebsd.org (Postfix) with ESMTP id 725DE13C457 for ; Mon, 24 Dec 2007 11:20:02 +0000 (UTC) (envelope-from rpaulo@gmail.com) Received: by fk-out-0910.google.com with SMTP id b27so2389182fka.11 for ; Mon, 24 Dec 2007 03:20:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:message-id:from:to:cc:subject:in-reply-to:references:user-agent:mime-version:content-type:sender; bh=KGvDHGtTzBJy8WeHVFJ+k9ZAVVkKVLDDVFn41r64xBM=; b=MxXzH8Qabtn9ZyYQ0yQXcLW3bXO4oQbxlgTP1L9ECsPOVmzrOWARZeV+6C6/GfMNupm8UR3zRpZpll0e+DXNkCSWMvCCFxRqSylpOULQc1OM7T3P6bqJ0NKNBBxYPYJb+R/pMEAdXAbl6fU8Z0X0ZX8Zxc4kWtnTYQcukAyzsOU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:message-id:from:to:cc:subject:in-reply-to:references:user-agent:mime-version:content-type:sender; b=e/T0A49/7DoJ0rXSQCGnsj6e5uTXXNOBPr3GdHKPlkA3VzkFCr0HNm39O+PPM2pmAXHxqdsTcl3ek0xbnFemmH0IyzgNCzzQa3GezjF54+5VavYVKRnOjDOS90XZ6YUXgZSETIEAV1UtbyG7gj4bry5ZNwl35l4z/kzoLHCfIJU= Received: by 10.82.105.13 with SMTP id d13mr8144648buc.30.1198493485226; Mon, 24 Dec 2007 02:51:25 -0800 (PST) Received: from epsilon.local.gmail.com ( [83.144.140.64]) by mx.google.com with ESMTPS id z37sm6420029ikz.1.2007.12.24.02.51.22 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 24 Dec 2007 02:51:24 -0800 (PST) Date: Mon, 24 Dec 2007 10:50:52 +0000 Message-ID: <86mys0mkmr.wl%rpaulo@fnop.net> From: Rui Paulo To: Ed Schouten In-Reply-To: <20071224094642.GO1169@hoeg.nl> References: <20071224094642.GO1169@hoeg.nl> User-Agent: Wanderlust/2.15.5 (Almost Unreal) Emacs/22.1 Mule/5.0 (SAKAKI) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: Rui Cc: freebsd-usb@freebsd.org Subject: Re: USB keyboard translation - Apple hardware X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Dec 2007 11:20:03 -0000 At Mon, 24 Dec 2007 10:46:42 +0100, Ed Schouten wrote: > > [1 ] > Hello everyone, > > One of the things that really made me mad when I got FreeBSD working on > my Apple MacBook, was that the Fn button on the keyboard doesn't work. > This means that I don't have the Delete, Page-{Up,Down}, Home and End > buttons. > > I took a look at kbdmap(1), but it turned out you can't add any new > modifiers, which is needed in this case, because we have a new Fn > modifier key. Maybe you could solve this in X, but I also work a lot > outside of X, so I really want to have the translation to be performed > everywhere. > > I've written the following patch for ukbd, which adds a method for > easily adding translation functions to the driver, to remap keys: > > http://g-rave.nl/unix/freebsd/freebsd-ukbd-translate.diff > > I tried to keep the code as clean as possible, so I also put some > #ifdef's around it, so that people who dislike it, can just undef it. > I've only added the quirks for the Apple MacBook keyboard, but there are > some other Apple keyboards that have some strange scancodes. I still > have to add those. > > Any comments so far? I do like this approach. The Fn key is a special key that needs special handling, but there seems to be a problem with our USB stack. The code code to detect the Fn key is: Index: ukbd.c =================================================================== RCS file: /home/ncvs/src/sys/dev/usb/ukbd.c,v retrieving revision 1.75 diff -u -p -r1.75 ukbd.c --- ukbd.c 5 Nov 2007 19:51:12 -0000 1.75 +++ ukbd.c 17 Dec 2007 21:24:35 -0000 @@ -110,6 +110,9 @@ struct ukbd_data { typedef struct ukbd_softc { device_t sc_dev; /* base device */ +#define UKBD_FN 0x01 + int sc_flags; + struct hid_location sc_loc_fn; /* location of the Fn key */ } ukbd_softc_t; #define UKBD_CHUNK 128 /* chunk size for read */ @@ -178,6 +181,10 @@ ukbd_attach(device_t self) struct usb_attach_arg *uaa = device_get_ivars(self); usbd_interface_handle iface = uaa->iface; usb_interface_descriptor_t *id; + void *desc; + int size; + usbd_status err; + uint32_t flags; keyboard_switch_t *sw; keyboard_t *kbd; @@ -191,6 +198,21 @@ ukbd_attach(device_t self) id = usbd_get_interface_descriptor(iface); + /* + * Locate the Fn key on Apple keyboards. + */ + err = usbd_read_report_desc(uaa->iface, &desc, &size, M_TEMP); + if (err) { + device_printf(self, "could not read report descriptor\n"); + return ENXIO; + } + if (hid_locate(desc, size, HID_USAGE2(HUP_CUSTOM, HUC_FNKEY), + hid_input, &sc->sc_loc_fn, &flags)) { + device_printf(self, "Fn key.\n"); + sc->sc_flags |= UKBD_FN; + } + free(desc, M_TEMP); + arg[0] = (void *)uaa; arg[1] = (void *)ukbd_intr; kbd = NULL; Index: usbhid.h =================================================================== RCS file: /home/ncvs/src/sys/dev/usb/usbhid.h,v retrieving revision 1.15 diff -u -p -r1.15 usbhid.h --- usbhid.h 6 Jan 2005 01:43:29 -0000 1.15 +++ usbhid.h 22 Dec 2007 19:18:50 -0000 @@ -94,6 +94,7 @@ typedef struct usb_hid_descriptor { #define HUP_SCALE 0x008c #define HUP_CAMERA_CONTROL 0x0090 #define HUP_ARCADE 0x0091 +#define HUP_CUSTOM 0xffff #define HUP_MICROSOFT 0xff00 /* Usages, generic desktop */ @@ -165,6 +166,9 @@ typedef struct usb_hid_descriptor { #define HUD_ERASER 0x0045 #define HUD_TABLET_PICK 0x0046 +/* Usages custom */ +#define HUC_FNKEY 0x0003 + #define HID_USAGE2(p,u) (((p) << 16) | u) #define UHID_INPUT_REPORT 0x01 But the problem relies in HUP_CUSTOM. Linux seems to be using 0x00ff instead of 0xffff, but with that value, the Fn key is not detected in FreeBSD. Another problem is reading the value of the register. When a ukbd_intr() occurs, we should be able to read the register, but somehow it's always 0. In August, I mailed the original USB stack driver, but he didn't reply. I'll try to find a solution. Regards. -- Rui Paulo