LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 08-17-2022, 11:06 PM   #1
zua5248
LQ Newbie
 
Registered: Aug 2022
Posts: 5

Rep: Reputation: 0
What is the scenario if I have to install a device that does not have drivers in Kernel?


I am working with device tree but I need some bigger picture understanding first in order to go into details.

Let's assume there is a video encoding device that is attached with embedded hardware like raspberry pi using I2C may be or SPI (interface does not matter for now). In my understanding there is a big chance that you will get the drivers of most hardware in the Linux Kernel but if you do not find the driver for that particular device.

What will be our option here? Do I have to write the drivers on my own? Then I have to put those drivers in Linux Kernel and then enable them in the device tree?

How to write those drivers (I am not asking for a tutorial but in general) is it exactly like how we write drivers in embedded systems like STM32 where we have to set data on registers and then get data from registers, managing bits of data etc?

I just need some big picture information so that I can then go into the detail and use it as a rough guide in the world of linux drivers.
 
Old 08-18-2022, 08:07 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,288

Rep: Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322
There's linux kernel documents online explaining that driver wrtiting process.

My uninitiated understanding of it is that devices have a pci or usb ID. From that the kernel module & firmware are loaded. If it's not pci or usb, it's the port that's driven.

Writing code for the kernel is a serious business and a high coding standard is required. If your code is sub-par, you can write a driver which combines it's own source files with kernel files. This is common with realtek drivers. Many companies hire kernel devs; but realtek's don't. So guys write drivers on github which do this. I recently built drivers for the RTL8821CU and the RTL88x2BU and RinCat & morrownr both have drivers that compile on 5.x kernels and install. They are good examples. Why not study them?

If you don't have experience, i2c is easy but exposes hardware. The GPIO stuff is a pain in the gooseberries. Enjoy yourself.
 
Old 08-18-2022, 08:35 PM   #3
blue_z
Member
 
Registered: Jul 2015
Location: USA
Distribution: Ubuntu, Lubuntu, Mint, custom embedded
Posts: 104

Rep: Reputation: Disabled
Quote:
Originally Posted by zua5248 View Post
What will be our option here?
What are your chip selection criteria?
Are you choosing a chip using just board/hardware-oriented criteria such as chip size, number of pins, power consumption, availability, vendor relationships?
Or is there a system perspective that includes software features and compatibility, and availability of driver(s) for your kernel?


Quote:
Originally Posted by zua5248 View Post
Do I have to write the drivers on my own?
Since that can be riskiest and/or most expensive path, you need to check all resources. Make inquires to the chip manufacturer. Besides the Linux kernel github, check the appropriate mailing lists (e.g. linux-media) for any developments pertaining to the chip in question.
Alternatively you could hire someone (or an outfit) to do the development for you.
Beware of licensing issues. I'm not a lawyer, but if you base your new driver on an existing Linux kernel driver (which is under GPL), then your work is also GPL. It you want/need to develop proprietary code (think Nvidia), then you would need to use a "clean room" method.


Quote:
Originally Posted by zua5248 View Post
Then I have to put those drivers in Linux Kernel and then enable them in the device tree?
Broadly speaking, yes.


Quote:
Originally Posted by zua5248 View Post
How to write those drivers (I am not asking for a tutorial but in general) is it exactly like how we write drivers in embedded systems like STM32 where we have to set data on registers and then get data from registers, managing bits of data etc?
That sounds like an unstructured microcontroller perspective.
A kernel device driver has two salient interfaces: the device or hardware interface, and the kernel or subsystem interface.

So far you have only (crudely) described the device or hardware interface. The Linux kernel has many software layers, and uses hardware abstraction or encapsulation for HW portability and/or HW substitution. So accesses to device registers will utilize macros or (primitive) functions rather than explicit assignment statements. The control bits and fields of device registers will be referenced by macros/mnemonics rather than numeric values in the source code.

The other salient interface of a Linux device driver is its flip side, for the the kernel or subsystem interface. The structure or capabilities of the driver will depend on where the driver fits in the kernel framework. The layered implementation of the kernel divides it into subsystems, and each subsystem can have its own framework. The capabilities a driver exposes (to its higher layer) is (typically) through ops vectors, rather than exporting its function names.

A video encoder would be part of the Video4Linux subsystem. Refer to this (old) presentation for basic concepts and resources: https://events.static.linuxfound.org...012_debski.pdf

Note that code submitted for inclusion in the mainline kernel source must adhere to the kernel coding style. Suggest that you use kernel coding style from the start, rather than make a mess and try to clean up later.

Regards

Last edited by blue_z; 08-18-2022 at 09:00 PM.
 
Old 08-19-2022, 05:16 AM   #4
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,288

Rep: Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322
Good points.

The funny thing here is that he won't want to say what he has on his mind, because it's 'top secret.' But if his 'top secret' ideas work, he'll still have to ram it down somebody's throat to sell it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Does a powered device have to have power over ethernet (PoE) device technology built in to be powered mredc Linux - Networking 4 12-26-2021 09:38 AM
arpspoof scenario does not work Barade Linux - Security 1 10-15-2016 02:26 AM
How to solve this scenario in Linux device drivers haribabu1836 Linux - Software 2 12-09-2011 01:22 AM
Best install scenario mobo Linux - General 4 11-13-2004 07:57 AM
install scenario Jeebizz Slackware 8 10-14-2004 04:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 04:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration