Writing HID driver
John Baldwin
jhb at freebsd.org
Fri Oct 21 13:06:42 UTC 2011
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
More information about the freebsd-drivers
mailing list