CopyrightMany of the designations used by manufacturers and sellers to distinguish their products are claimed astrademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim,the designations have been printed with initial capital letters or in all capitals.Theauthorandpublisherhavetakencareinthepreparationofthisbook,butmakenoexpressedorimpliedwarranty of anykind and assume no responsibility for errors or omissions.No liability is assumed forincidentalorconsequentialdamages inconnectionwithorarisingoutoftheuseof theinformationorprogramscontainedherein.Thepublisheroffersexcellentdiscountsonthisbookwhenorderedinquantityforbulkpurchasesorspecialsales,whichmay includeelectronic versionsand/or custom coversand contentparticulartoyourbusiness,training goals, marketing focus, and branding interests. For more information, please contact:U.S.Corporate and Government Sales(800)382-3419corpsales@pearsontechgroup.comForsales outsidethe UnitedStates pleasecontact:InternationalSalesinternational@pearson.comVisitusontheWeb:www.informit.com/phLibraryof CongressCataloging-in-PublicationData:Venkateswaran,Sreekrishnan,1972-EssentialLinuxdevicedrivers/SreekrishnanVenkateswaran.--1sted.p.cm.ISBN0-13-239655-6 (hardback :alk.paper)1.Linuxdevicedrivers (Computer programs)I. Title.QA76.76.D49V352008005.4'32--dc222008000249Copyright2008PearsonEducation,IncAll rights reserved.Printed in the United States of America.This publication is protected by copyright,andpermissionmustbeobtainedfromthepublisherpriortoanyprohibited reproduction,storage inaretrievalsystem,ortransmissioninanyformorbyanymeans,electronic,mechanical,photocopying,recording,orlikewise.For information regarding permissions,write to:Pearson Education,IncRightsand ContractsDepartment501BoylstonStreet,Suite900Boston,MA02116Fax(6i7)6713447This material may be distributed only subject to the terms and conditions set forth in the Open PublicationLicense,vl.Oorlater(thelatestversionispresentlyavailableathttp://www.opencontent.org/openpub/)ISBN-13:978-0-132-39655-4
Copyright Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact: U.S. Corporate and Government Sales (800) 382-3419 corpsales@pearsontechgroup.com For sales outside the United States please contact: International Sales international@pearson.com Visit us on the Web: www.informit.com/ph Library of Congress Cataloging-in-Publication Data: Venkateswaran, Sreekrishnan, 1972- Essential Linux device drivers / Sreekrishnan Venkateswaran.- 1st ed. p. cm. ISBN 0-13-239655-6 (hardback : alk. paper) 1. Linux device drivers (Computer programs) I. Title. QA76.76.D49V35 2008 005.4'32-dc22 2008000249 Copyright © 2008 Pearson Education, Inc. All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, write to: Pearson Education, Inc Rights and Contracts Department 501 Boylston Street, Suite 900 Boston, MA 02116 Fax (617) 671 3447 This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). ISBN-13: 978-0-132-39655-4
Text printed in the United States on recycled paperat RRDonnelly in Crawfordsville, IN.First printing March 2008Editor-in-ChiefMark TaubExecutive EditorDebra Williams CauleyManaging EditorGina KanouseProject EditoAnneGoebelCopyEditorKeithClineIndexerErika MillenProofreaderSanDeePhillipsTechnical EditorsVamsiKrishnaJim LiebPublishing CoordinatorHeatherFoxInteriorDesignerLaura RobbinsCover DesignerAlan ClementsCompositorMollySharpDedicationThisbook isdedicatedtothetenmillionvisuallychallenged citizensofIndia.Allauthorproceedswillgototheir cause.4
Text printed in the United States on recycled paper at RR Donnelly in Crawfordsville, IN. First printing March 2008 Editor-in-Chief Mark Taub Executive Editor Debra Williams Cauley Managing Editor Gina Kanouse Project Edito Anne Goebel Copy Editor Keith Cline Indexer Erika Millen Proofreader San Dee Phillips Technical Editors Vamsi Krishna Jim Lieb Publishing Coordinator Heather Fox Interior Designer Laura Robbins Cover Designer Alan Clements Compositor Molly Sharp Dedication This book is dedicated to the ten million visually challenged citizens of India. All author proceeds will go to their cause
PrenticeHallOpenSourceSoftwareDevelopmentSeriesArnoldRobbins,SeriesEditor"Real world code from real world applications"Open Source technology has revolutionized the computing world. Many large-scale projects are in productionuse worldwide, such as Apache, MysQL, and Postgres, with programmers writing applications in a variety oflanguages including Perl, Python, and PHP.These technologies are in use on many different systems, rangingfromproprietarysystems,toLinuxsystems,totraditionalUNiXsystems,tomainframes.ThePrenticeHall OpenSourceSoftwareDevelopmentSeries is designedtobring youthebest of theseOpen Source technologies.Not onlywill you learn how to use them for your projects,but you will learn fromthem.By seeing real code from real applications, you will learn the best practices of Open Source developersthe world over.Titles currently in the series include:Linux Debugging and PerformanceTuningSteveBest0131492470,Paper,2006C++GUIProgrammingwithQt4JasminBlanchette,MarkSummerfield0132354160,Hard,@2008TheDefinitiveGuidetotheXenHypervisorDavid Chisnall013234971X,Hard,@2008UnderstandingAJAXJoshua Eichorn0132216353,Paper,2007The Linux Programmer's ToolboxJohnFusco0132198576,Paper,@2007EmbeddedLinuxPrimerChristopherHallinan0131679848,Paper,2007TheApacheModulesBookNickKew0132409674,Paper,2007SELinuxbyExampleFrank Mayer, David Caplan, Karl MacMillan0131963694,Paper,2007UNIX to Linux? PortingAifredoMendoza,ChakaratSkawratananond,Artis Walker0131871099,Paper,2006
Prentice Hall Open Source Software Development Series Arnold Robbins, Series Editor "Real world code from real world applications" Open Source technology has revolutionized the computing world. Many large-scale projects are in production use worldwide, such as Apache, MySQL, and Postgres, with programmers writing applications in a variety of languages including Perl, Python, and PHP. These technologies are in use on many different systems, ranging from proprietary systems, to Linux systems, to traditional UNIX systems, to mainframes. The Prentice Hall Open Source Software Development Series is designed to bring you the best of these Open Source technologies. Not only will you learn how to use them for your projects, but you will learn from them. By seeing real code from real applications, you will learn the best practices of Open Source developers the world over. Titles currently in the series include: Linux® Debugging and Performance Tuning Steve Best 0131492470, Paper, ©2006 C++ GUI Programming with Qt 4 Jasmin Blanchette, Mark Summerfield 0132354160, Hard, ©2008 The Definitive Guide to the Xen Hypervisor David Chisnall 013234971X, Hard, ©2008 Understanding AJAX Joshua Eichorn 0132216353, Paper, ©2007 The Linux Programmer's Toolbox John Fusco 0132198576, Paper, ©2007 Embedded Linux Primer Christopher Hallinan 0131679848, Paper, ©2007 The Apache Modules Book Nick Kew 0132409674, Paper, © 2007 SELinux by Example Frank Mayer, David Caplan, Karl MacMillan 0131963694, Paper, ©2007 UNIX to Linux® Porting Alfredo Mendoza, Chakarat Skawratananond, Artis Walker 0131871099, Paper, ©2006
Rapid WebApplications withTurboGearsMarkRamm,KevinDangoor,GigiSayfan0132433885,Paper,2007LinuxProgrammingbyExampleArnoldRobbins0131429647,Paper,@2004The LinuxKernel PrimerClaudia Salzberg, Gordon Fischer,Steven Smolski0131181637,Paper,@2006RapidGUIProgrammingwithPythonandQtMarkSummerfield0132354187,Hard,@2008EssentialLinuxDeviceDriversSreekrishnan Venkateswaran0132396556,Hard,2008Newtotheseries:DigitalShortCutsShort Cuts are short, concise, PDF documents designed specifically for busy technical professionals like you.Each Short Cut is tightly focused on a specific technology or technical probiem. Written by industry experts andbest selling authors, Short Cuts are published with you in mind -getting you the technical information that youneed-now.UnderstandingAJAX:ConsumingtheSentDatawithXMLandJSONJoshuaEichorn0132337932,AdobeAcrobatPDF,2007Debugging Embedded LinuxChristopherHallinan0131580132,AdobeAcrobatPDF,2007Using BusyBoxChristopher Hallinan0132335921,AdobeAcrobatPDF,2007A
Rapid Web Applications with TurboGears Mark Ramm, Kevin Dangoor, Gigi Sayfan 0132433885, Paper, © 2007 Linux Programming by Example Arnold Robbins 0131429647, Paper, ©2004 The Linux® Kernel Primer Claudia Salzberg, Gordon Fischer, Steven Smolski 0131181637, Paper, ©2006 Rapid GUI Programming with Python and Qt Mark Summerfield 0132354187, Hard, © 2008 Essential Linux Device Drivers Sreekrishnan Venkateswaran 0132396556, Hard, ©2008 New to the series: Digital Short Cuts Short Cuts are short, concise, PDF documents designed specifically for busy technical professionals like you. Each Short Cut is tightly focused on a specific technology or technical problem. Written by industry experts and best selling authors, Short Cuts are published with you in mind — getting you the technical information that you need — now. Understanding AJAX: Consuming the Sent Data with XML and JSON Joshua Eichorn 0132337932, Adobe Acrobat PDF, © 2007 Debugging Embedded Linux Christopher Hallinan 0131580132, Adobe Acrobat PDF, © 2007 Using BusyBox Christopher Hallinan 0132335921, Adobe Acrobat PDF, © 2007
ForewordIf you're holding this book, you may be asking yourself: Why "yet another" Linux device driver book? Aren'ttherealreadyabunchofthem?Theansweris:Thisbookisaquantumleapaheadoftheothers.First, it is up-to-date, covering recent 2.6 kernels. Second, and more important, this book is thorough. Mostdevice driver books just cover the topics described in standard Unix internals books or operating system books,suchasserial lines,disk drives,andfilesystems,and,ifyou'relucky,thenetworkingstack.This book goes muchfurther; it doesn't shyaway fromthehard stuff that youhaveto deal with on modernPCandembeddedhardware,suchasPCMCIA,USB,I2C,video,audio,flashmemory,wirelesscommunications,andso on.You nameit, if the Linux kerneltalksto it, then this book tells you about it.No stone is left unturned;no dark corner is left unilluminated.Furthermore, the author has earned his stripes: It's a thrill ride just to read his description of putting Linux on awristwatchinthelate1990s!I'mpleasedandexcitedtohavethisbookaspartofthePrenticeHallOpenSourceSoftwareDevelopmentSeries. It is a shining example of the exciting things happening in the Open Source world. I hope that you willfind here what you need for your work on the kernel, and that you will enjoy the process, too!ArnoldRobbinsSeriesEditor
Foreword If you're holding this book, you may be asking yourself: Why "yet another" Linux device driver book? Aren't there already a bunch of them? The answer is: This book is a quantum leap ahead of the others. First, it is up-to-date, covering recent 2.6 kernels. Second, and more important, this book is thorough. Most device driver books just cover the topics described in standard Unix internals books or operating system books, such as serial lines, disk drives, and filesystems, and, if you're lucky, the networking stack. This book goes much further; it doesn't shy away from the hard stuff that you have to deal with on modern PC and embedded hardware, such as PCMCIA, USB, I2C, video, audio, flash memory, wireless communications, and so on. You name it, if the Linux kernel talks to it, then this book tells you about it. No stone is left unturned; no dark corner is left unilluminated. Furthermore, the author has earned his stripes: It's a thrill ride just to read his description of putting Linux on a wristwatch in the late 1990s! I'm pleased and excited to have this book as part of the Prentice Hall Open Source Software Development Series. It is a shining example of the exciting things happening in the Open Source world. I hope that you will find here what you need for your work on the kernel, and that you will enjoy the process, too! Arnold Robbins Series Editor