Device Drivers for System on Chip (SOC) - linux

I want to read the GPS data from my android phone inside the kernel space. I want to write a device driver for my GPS and request data through it. But unlike external devices I could not find the Vendor Id and device Id of the GPS hardware or the SOC on which it is installed. Can someone help me with how to collect the details required for writing the driver?
Thanks.

You already have found one of many problems with SOC and device drivers. Therefore another approach is used in the linux kernel: Platform driver and Platform devices. You wont need any Vendor IDs and such stuff.
I recommend you to read some tutorials and get started with it:
Readme: https://www.kernel.org/doc/Documentation/driver-model/platform.txt
Code example for CAN: https://github.com/torvalds/linux/tree/master/drivers/net/can/ifi_canfd
Disscussion about difference: What is the difference between a Linux platform driver and normal device driver?
Sadly I am not able to answer your questions on how to get those id's.

Related

CDC class vid:pid to use for my STM32F3 based equipment

I am plannig to use usb connection to let PC communicate with my equipment based on STM32F373VC.
I tried the CDC class using the example in STM32CubeF3 V1.9.0 by removing the uart peripheral management.
PC detects a usb device with vid:pid 0483:5740. Linux automatically recognizes CDC class (STMicroelectronics STM32F407), loads the cdc_acm module, and the ttyACM0 VCP is created. I don't know about Windows, but reading the readme of the example it seems that a driver should be installed.
I have some questions:
Can I use VID:PID 0483:5740 for my product?
Does the various versions of Windows automatically recognize the device (and associate it with the CDC driver) or is it really necessary to install a driver?
If I can't use these VID:PID, can I ask ST for a PID assigned to me for small productions (as other silicon vendors do)?
Could ST assign me a PID that the various versions of Windows, Linux and Mac automatically recognize as CDCs without needing to install drivers or configure anything?
If not, do VID:PID pairs exist that are automatically recognized by the various versions of Windows, Linux and Mac as CDC class without needing to install drivers or configure and that I can legally use for my small production?
About drivers recognizing your device:
If your device is of class CDC, driver should be able to be loaded no matter what VID:PID is used (as long as selected VID:PID is not assigned to other device that has device specific driver). For Windows please refer to this document.
You should be able to test Linux CDC class driver by altering device descriptor in your device library code (which should be possible, if I correctly understand available ST documentation).
About having your own VID:PID:
There is some thread on github about this here. It should cover all possible options including the ones you asked about.

WebUSB with FT230x serial chip

I'm hoping to use the newly released WebUSB API to communicate with a device i developed. This devices uses a FT230X USB to serial chip. The drivers of this chip are installed on most devices and communicating with it using minicom works smoothly. Now i want to try communicate with it through the browser. I started by downloading this example for arduino: webusb arduino. I set the filter to { 'vendorId': 0x0403, 'productId': 0x6015 } which shows the device. I'm able to find the device but when i try to connect i get the error: NotFoundError: Device unavailable.
Is there a way to find more specific errors? Should i set up a different interface or do i need to change some other configurations? I'm new to USB drivers so any help getting me on my way would be nice. I did read the (short) getting started documentation here. I use Ubuntu 16.04
The FT230X USB to serial chip does not provide an USB interface that Chrome can take control of. This is because, as you mention, the drivers for this chip are available with your operating system. With the serial driver attached Chrome cannot make the device available to your page through the WebUSB API.
The Arduino example programs the Atmel 32u4 chip on many Arduino and Arduino-compatible boards to add an additional USB interface which is not claimed by any system driver and is therefore available to Chrome.
Some developers have also had success either changing the vendor and product ID of their device so that the OS drivers do not claim it or by manually unbinding the driver.

Linux Virtual USB device driver

My goal is to create a virtual USB char device (not block device) for Linux 2.6.32 and above (I use debian squeeze) that would be recognize by the system.
I would like that this device be listed with lsusb as a normal USB device, and that every application could use libusb in order to open the device, and send control message, and make bulk write/read. But behind this virtual device, it's behavior would be set by my application. I want to set it's product ID, it's vendor ID, answer to USB status, and bulk read.
I've read some posts about how to use USB/IP in order to create a virtual USB device, and that's exactly what I want to do
Installation and emulation of virtual USB Device
http://breaking-the-system.blogspot.fr/2014/08/emulating-usb-devices-in-python-with-no.html
But unfortunately, when I tried with 2.6.32 kernel and above, I didn't succeed making it work. So I looked at how to create a kernel module that would create the virtual device :
http://pete.akeo.ie/2011/08/writing-linux-device-driver-for-kernels.html
This one looks great also, but the sample provided doest not indicate how to make it an USB device.
I've seen some post talking about it with windows but none that could help me with Linux.
I would like to avoid buying some USB programmable cards when it can be done with software.
Have anyone any leads on how to make the first methods works under newer kernel, or convert the sample code of the second method for making an USB device ?
I have fixed the code of http://breaking-the-system.blogspot.fr/2014/08/emulating-usb-devices-in-python-with-no.html (first method using USB/IP) to work with linux 4.3.
In the original code are missing USB requests like set configuration and get status. Without the implementation of all USB requests used for the OS driver the code will not work.
The fixed code can be downloaded in https://github.com/lcgamboa/USB-Emulation .
I guess raw-gadget kernel module is the thing that you want?
you can check the dummy_hcd and tests directory inside the repo, it will guide you how to create a virtual USB device

Detect the presence of a device when it's hot plugged in Linux

I am running the SPI code on the panda board and I want to know which function in the code is responsible for detecting the device when it's hot plugged.
Can somebody with the background of embedded systems, Linux device drivers and/or spi please answer my question?
This is the line in your code that does the magic:
1286 MODULE_DEVICE_TABLE(of, omap_mcspi_of_match);
Process:
1. Driver for each device exposes its information using the API MODULE_DEVICE_TABLE. Each device has a unique vendor Id and device Id.
2. At compilation time, the build process extracts this information out of the driver and builds a table.
3. When the device is plugged in, the kernel checks this device table to see if any driver is
available for the particular Vendor/Device Id. If yes then it loads that driver and initializes the device.
Read following articles for more info:
http://www.linux-mag.com/id/2617/
http://www.linuxjournal.com/node/5604/print

Linux user space PCI driver

I'm trying to write a PCI device driver that runs in user space. Not my idea, what the client wants. Target is an embedded Linux board that will never have more than a single user. I'm an experienced C programmer and know Linux, just not familiar with Linux driver development.
Is this really a device driver or just a library? Do I need to use the typical calls pci_register_driver, etc. or can I just access the device using fopen, and using mmap and ioperm to get to it?
Interrupts will be done using the MSI model. Also need to handle DMA transfers. The device will be streaming lots of data to the user.
There's not much info out there on this subject, LDD3 only devotes a couple of pages to it, and there's nothing else that I could find here on SO.
Thanks in advance!
If there is no driver handling the PCI card it would be possible to access it using ioperm (or iopl - depending on the address) if only port accesses are required.
Using DMA and interrupts is definitely impossible without a kernel-mode driver.
By googleing I found some text about something like a "generic kernel-mode driver" that allows writing user-mode drivers (including DMA and interrupts).
You should ask your customer which kind of kernel-mode drivers for accessing PCI cards is installed on the Linux board.
There is now a proper way to do high performance userspace PCI drivers, called vfio. There is not much documentation, but see the kernel docs http://lxr.free-electrons.com/source/Documentation/vfio.txt and the header file /usr/include/linux.vfio.h. It is available since Linux 3.6.

Resources