Thread: How to get started with writing driver in Linux?

  1. #1
    Registered User Maz's Avatar
    Join Date
    Nov 2005

    How to get started with writing driver in Linux?

    Hi deee Ho peeps!

    It has been quite a while since I did my first attempt to dig into kernel level programming. Back then I managed to write my nice "Hello World" module with printk().

    After that, I've done some small attempts to get more familiar with the mysterious world of drivers, but usually I've ran out of time & skills & googling enthusiasm, before managing to accidentally overwrite non volatile memory from my network card

    However a few days ago I had the pleasure of participating in a one day quick course to world of device drivers... As "one day quick course" tells, it was not really anything more but an introduction of some things. However that reminded me about my present goals

    So when I get back home, I digged through my old cabins, and managed to find MSP3880SP-W modem (with microphone socket), and
    Aztec 50-0038AZ-2S-2 ISA Sound Card

    So I took a new goal. I want to write my own driver, which will read voltages inputted via mic socket. I guess theres DACs there already, so if only I knew how, it should be possible

    I've written some small things for turning on/off leds etc - but I've always had some HW guy whom to ask about memory addresses to write etc. Now I am facing a different problem. How to use ISA bridge? Is there some interface in kernel for handling ISA devices? If yes, how to detect the devices, how to find out the memory areas (or ports)? Basically, where to start from??

    I tried doing some googling, but all I found was bunch of cards being sold...

    I know there must be drivers for these cards in Linux, but I have no idea where to start looking for it... You know that theres ~6 000 000 lines of code in linux, and ~1000 new lines is written each day... So there's a bit too much to go through blindly

    So, does anyone have any "wild pointers" for me ?

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    I've setting out to write a driver for an unsupported USB webcam, which I bought cheap on purpose to motivate myself with kernel hacking.

    I also bought a couple of books on the topic ("Linux Device Drivers" and, of course "Essential Linux Device Drivers") because it seemed to me I was going to have to do a lot of reading, one way or another (yep).

    I've only made it thru the first hundred pages in each of them, but here's my "wild pointer" with a quote:
    Quote Originally Posted by Essential Linux Device Drivers
    ISA drivers would have merited a separate chapter several years earlier; but today [they are nearly obsolete...] There are two main bus-specific factors that ISA device drivers have to contend with: 1) ISA does not offer standard interfaces that drivers can use [...] impementing complex probing logic, often leveraging device specific quirks, is an important part
    Which I would take to mean you will spend a lot of time dealing with idiosyncrasies and that whatever you learn there will probably NOT be useful "take away" knowledge that has a more general application.

    The other book doesn't have a chapter on ISA either, but he covers it a little bit under PCI, since apparently those that own a sodering iron can make an ISA device more easily at home...anyway, I am seeing phrases like "causes endless pain to system programmers".

    Re: addressing
    The other great problem with the ISA design is the lack of geographical addressing, which has led to many problems and lengthy unplug-rejumper-plug-test cycles to add new devices
    Which might get the right kind of person excited, who knows. Finally:
    As far as programming is concerned, there's no specific aid in the kernel or the BIOS to ease access to ISA devices [...] The only facilities you can use are the registries of I/O ports and IRQ lines, described in the section "Installing an Interrupt Handler..."
    Which I have not tried installing an interrupt handler yet, but I just read the section in both books yesterday; there are plenty of kernel facilities for that. It seems complex but not too much so; one thing to observe is that there were small changes in this >kernel 2.6.19.

    So if you google around, interrupt handling is what you want.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why Linux, for the average user?
    By Hunter2 in forum A Brief History of
    Replies: 32
    Last Post: 07-07-2006, 02:36 PM
  2. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  3. Writing a driver...
    By Devil Panther in forum C Programming
    Replies: 4
    Last Post: 06-30-2005, 07:55 AM
  4. installing linux for the first time
    By Micko in forum Tech Board
    Replies: 9
    Last Post: 12-06-2004, 05:15 AM
  5. Linux? Windows Xp?
    By VooDoo in forum Linux Programming
    Replies: 15
    Last Post: 07-31-2002, 08:18 AM