Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 09-28-2008, 09:41 PM   #1
Registered: Apr 2008
Location: Singapore
Distribution: Slackware 14.0
Posts: 153

Rep: Reputation: 15
Exclamation Pre-requisites for hardware device programmer

For a start, how or what should i start with if i am interested in
linux programming for hardware; to produce device driver?

Old 09-28-2008, 10:54 PM   #2
Senior Member
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
First of all you need to know enough of digital electronics to be able to read the hardware documentation - you need to understand how to use the "control registers" of a device as well as how to read/write data to that device. You also need to be comfortable reading timing diagrams for the hardware and be able to spot any timing issues which may come up.

The simplest of projects would be to write a small driver for your UART (serial port hardware). Identify the exact hardware part, get the documentation, and start writing code for it. Your code can set a fixed bit rate, no hardware handshaking, no control lines - make it simple so you can test it by connecting to another serial port and running 'minicom'. The UARTs are one of the simplest devices and if you screw up the driver you don't do yourself any harm (if you tried your hand at a PS/2 serial driver and screwed up, you suddenly don't have a keyboard or mouse and may be forced to do a hard boot).

For information on device drivers, have a look at Linux Device Drivers 3rd edition (Alessandro Rubini, Jonathan Corbet, Greg Kroah-Hartman) - the electronic version is freely available.

Now anything to do with UARTS actually becomes a horrible mess in UNIX because these were traditionally used to support serial terminals. So if you have a look at the serial port code in Linux you will see that there is the base code which enables interrupts, and reads and writes data. However, data is never directly written to (or read from) the device from user space - data read from the device is passed onto the "line discipline" (a filter) for processing. When the user writes data, that data is also passed onto the line discipline for processing and the line discipline then passes the data on to the serial code which actually writes it to the UART.

Anyway, writing a UART driver will give you the simplest possible hardware driver I can think of and it will help you get familiar with the system. After that, what you study depends on what type of driver you want to make. If it is anything which goes onto the PCI bus then you need to study the parts of the Linux device driver system that relate to PCI (how they are discovered, how to request resources, etc etc). If it is a USB device then you need to look at the USB driver code structure. USB involves a protocol layer as well as the hardware driver for the USB controller chips. When you plug in ANY USB device, certain messages are sent along the line as part of the protocol. You basically have to learn how to interact with the protocol layer; your driver will have to work through that layer to discover and initialize your device and to process all incoming/outgoing messages after that. When dealing with a USB device, it is possible that you never write any code to initialize hardware. When dealing with PCI devices, you will need to set up the specific PCI controller which your device uses (the controller will be partially set up by firmware/ROM, but you need to do more setting up such as telling the controller what interrupts to use etc).
Old 09-29-2008, 07:31 PM   #3
Registered: Apr 2008
Location: Singapore
Distribution: Slackware 14.0
Posts: 153

Original Poster
Rep: Reputation: 15
Thanks pinniped. That's very informative.

At least i would know what to look for if i were to start in that area.

Thanks again :-)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
mdadm: flag device as write-mostly on pre-existing array zazoo24601 Linux - General 1 08-15-2016 12:22 PM
pre-configured vs. better hardware for new server ta0kira *BSD 6 09-27-2008 05:10 PM
programmer/hardware tech new to LQ johnwick Member Intro 1 02-03-2008 09:45 AM
MISSING REQUISITES : rsct.core.sensorrm # Base Level Fileset Liquidx AIX 2 10-14-2007 01:30 AM
Pre-purchase hardware nerves mbandrews Linux - Hardware 3 10-26-2003 03:04 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:41 AM.

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