2

I have a USB device that I am using with Ubuntu 20.04.3. The manufacturer provided a library and a driver.

I can install the driver and get the device to work, but every time the kernel updates I must reinstall the driver to the new tree. I understand that this is the job of dkms and I started working on getting that up as it doesn't look too difficult, but taking a step back I am wondering if there might be a simpler/better way to get the device to work as I think that most of their userbase is windows, so there is not much dev time given to the linux side of things. And anyway I want to understand more about how linux does things.

The driver they supply is a slightly modified Exar driver. Looking at the diffs between their version and the vanilla Exar driver, basically all they did was add their vendor number and product id number to the code so their device would be recognized as compatible to the driver and run the appropriate blocks of code (same as the specific Exar chip they use) when the device matches their device descriptor.

Based on this very helpful page and other sources around the internet, my understanding is that each driver has a modules.alias file that essentially has rules on what types of devices it accepts. Then when the device is plugged in, the system pulls info from the device to make a modalias file for that device. Then the first, most specific driver to match the device modalias to a rule in the modules.alias file is the driver that gets assigned to the device.

So I imagine my device has an Exar chip and could use the Exar driver to make it work if the driver accepted it and recognized it as essentially an Exar chip. But since the manufacturer put their own custom device descriptor, modprobe doesn't recognize the device as being compatible with the vanilla Exar driver.

Rather than copying the driver and modifying it so slightly to make the system honor it as they did, is there a way to tell the system that this device really is compatible with the vanilla Exar driver or has an Exar device hidden within as some kind of sub-device? Like an alias for device descriptors as far as modprobe is concerned?

Or perhaps there's a way to write a different driver for this device that utilizes the underlying exar driver and passes everything through to it rather than copying the code? Then I could get the benefit of updates from the chip manufacturer.

Or should I continue with dkms because the way the manufacturer did it the best way to do it?

I have seen examples on how to bind and unbind drivers to devices with udev rules, but I think that if the driver doen't match, it won't be bound anyway? And even if it did, would that be the "best" way?

1

1 Answer 1

0

As @ReedGhost so helpfully suggested in the comments (thanks!), this is exactly what I wanted to do. I found the built in xr_serial module and echoed my device vendor and product id to the newid file. The built-in driver recognizes my device as compatible and is loaded when I plug it in.

However, this did not solve my specific use case because the built in exar driver is written for multiple devices with different product ids. There is an if-then-else chain that specifies a certain chunk of code to be run for each specific product id. So some functionality still does not work because my device's id causes it to go to the else section of the code when it should run one of the other sections.

I realize now that I would really need to spoof or substitute the id of my device to the ids of the specific chip used instead of just adding a new one to be recognized by the driver.

EDIT: Actually, I will probably try to write a different driver for the device that utilizes the manufacturer-supplied driver under the hood as that seems like the more correct way to do it and get the benefits of updates. This question and this question seem like good starting points for anyone who finds this and has this same problem. In the meantime, I used dkms to just update the driver.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .