From owner-freebsd-drivers@FreeBSD.ORG Fri Oct 21 13:06:42 2011 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 60A481065670; Fri, 21 Oct 2011 13:06:42 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 381748FC18; Fri, 21 Oct 2011 13:06:42 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id B5BE846B45; Fri, 21 Oct 2011 09:06:41 -0400 (EDT) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id C2C5D8A06A; Fri, 21 Oct 2011 08:30:42 -0400 (EDT) From: John Baldwin To: freebsd-drivers@freebsd.org Date: Fri, 21 Oct 2011 08:30:42 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110617; KDE/4.5.5; amd64; ; ) References: <4E9EBAEE.2070500@timon.net.nz> In-Reply-To: <4E9EBAEE.2070500@timon.net.nz> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201110210830.42285.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Fri, 21 Oct 2011 08:30:42 -0400 (EDT) Cc: Warner Losh Subject: Re: Writing HID driver X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Oct 2011 13:06:42 -0000 On Wednesday, October 19, 2011 7:56:30 am Alexandr Matveev wrote: > Hi, > > I'm writing the driver for the USB keyboard, which has two interfaces: > first is generic keyboard and second is HID device. If I load driver and > then attach the keyboard - everything is OK. But if I attach keyboard > and then kldload driver, it won't attach to the device because the default > uhid driver already attached to it first. To prevent this, driver > searches for > uhid devices after being loaded and compares a pnpinfo string to search > for suitable devices and detach them. > > Everything works fine, but I have two questions: > 1) Is there any simpler way to do the same thing? Not currently, no. > 2) Is there a way to get device vendor & product without using device > bus-specific functions? No, but you can probably implement lkbd_detach_uhid() a bit simpler by doing something like: devclass_t dc; device_t devices; int devcount, error, i; dc = devclass_find("uhid"); if (dc == NULL) return; error = devclass_get_devices(dc, &devices, &devcount); if (error) { printf("Unable to fetch uhid device list: %d\n", error); return; } for (i = 0; i < devcount; i++) { /* * Do the same checks you do in your probe routine and * detach the devices that match. */ } free(devlist, M_TEMP); -- John Baldwin