<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <HTML ><HEAD ><TITLE >Module Wrapper</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Video4Linux Programming" HREF="book1.html"><LINK REL="UP" TITLE="Radio Devices" HREF="c24.html"><LINK REL="PREVIOUS" TITLE="The Ioctl Interface" HREF="x73.html"><LINK REL="NEXT" TITLE="Video Capture Devices" HREF="c261.html"></HEAD ><BODY CLASS="SECT1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Video4Linux Programming</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="x73.html" ACCESSKEY="P" ><<< Previous</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Radio Devices</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="c261.html" ACCESSKEY="N" >Next >>></A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="MODRADIO" ></A >Module Wrapper</H1 ><P > Finally we add in the usual module wrapping and the driver is done. </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" > #ifndef MODULE static int io = 0x300; #else static int io = -1; MODULE_AUTHOR("Alan Cox"); MODULE_DESCRIPTION("A driver for an imaginary radio card."); MODULE_PARM(io, "i"); MODULE_PARM_DESC(io, "I/O address of the card."); EXPORT_NO_SYMBOLS; int init_module(void) { if(io==-1) { printk(KERN_ERR "You must set an I/O address with io=0x???\n"); return -EINVAL; } return myradio_init(NULL); } void cleanup_module(void) { video_unregister_device(&my_radio); release_region(io, MY_IO_SIZE); } #endif </PRE ></TD ></TR ></TABLE ><P > In this example we set the IO base by default if the driver is compiled into the kernel where you cannot pass a parameter. For the module we require the user sets the parameter. We set io to a nonsense port (-1) so that we can tell if the user supplied an io parameter or not. </P ><P > We use MODULE_ defines to give an author for the card driver and a description. We also use them to declare that io is an integer and it is the address of the card. </P ><P > The clean-up routine unregisters the video_device we registered, and frees up the I/O space. Note that the unregister takes the actual video_device structure as its argument. Unlike the file operations structure which can be shared by all instances of a device a video_device structure as an actual instance of the device. If you are registering multiple radio devices you need to fill in one structure per device (most likely by setting up a template and copying it to each of the actual device structures). </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="x73.html" ACCESSKEY="P" ><<< Previous</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="book1.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="c261.html" ACCESSKEY="N" >Next >>></A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >The Ioctl Interface</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="c24.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Video Capture Devices</TD ></TR ></TABLE ></DIV ></BODY ></HTML >