<?xml version="1.0" encoding="ANSI_X3.4-1968" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968" /><title>parport_register_device</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><link rel="home" href="index.html" title="Linux Device Drivers" /><link rel="up" href="ch03.html" title="Chapter 3. Parallel Port Devices" /><link rel="prev" href="re290.html" title="parport_remove_port" /><link rel="next" href="re292.html" title="parport_unregister_device" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"><span>parport_register_device</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="re290.html">Prev</a> </td><th width="60%" align="center">Chapter 3. Parallel Port Devices</th><td width="20%" align="right"> <a accesskey="n" href="re292.html">Next</a></td></tr></table><hr /></div><div class="refentry" title="parport_register_device"><a id="API-parport-register-device"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>parport_register_device — register a device on a parallel port </p></div><div class="refsynopsisdiv" title="Synopsis"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" class="funcprototype-table"><tr><td><code class="funcdef">struct pardevice * <b class="fsfunc">parport_register_device </b>(</code></td><td>struct parport * <var class="pdparam">port</var>, </td></tr><tr><td> </td><td>const char * <var class="pdparam">name</var>, </td></tr><tr><td> </td><td>int (*<var class="pdparam">pf</var>) <code>(</code>void *<code>)</code>, </td></tr><tr><td> </td><td>void (*<var class="pdparam">kf</var>) <code>(</code>void *<code>)</code>, </td></tr><tr><td> </td><td>void (*<var class="pdparam">irq_func</var>) <code>(</code>void *<code>)</code>, </td></tr><tr><td> </td><td>int <var class="pdparam">flags</var>, </td></tr><tr><td> </td><td>void * <var class="pdparam">handle</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1" title="Arguments"><a id="id2636557"></a><h2>Arguments</h2><div class="variablelist"><dl><dt><span class="term"><em class="parameter"><code>port</code></em></span></dt><dd><p> port to which the device is attached </p></dd><dt><span class="term"><em class="parameter"><code>name</code></em></span></dt><dd><p> a name to refer to the device </p></dd><dt><span class="term"><em class="parameter"><code>pf</code></em></span></dt><dd><p> preemption callback </p></dd><dt><span class="term"><em class="parameter"><code>kf</code></em></span></dt><dd><p> kick callback (wake-up) </p></dd><dt><span class="term"><em class="parameter"><code>irq_func</code></em></span></dt><dd><p> interrupt handler </p></dd><dt><span class="term"><em class="parameter"><code>flags</code></em></span></dt><dd><p> registration flags </p></dd><dt><span class="term"><em class="parameter"><code>handle</code></em></span></dt><dd><p> data for callback functions </p></dd></dl></div></div><div class="refsect1" title="Description"><a id="id2636687"></a><h2>Description</h2><p> This function, called by parallel port device drivers, declares that a device is connected to a port, and tells the system all it needs to know. </p><p> The <em class="parameter"><code>name</code></em> is allocated by the caller and must not be deallocated until the caller calls <em class="parameter"><code>parport_unregister_device</code></em> for that device. </p><p> The preemption callback function, <em class="parameter"><code>pf</code></em>, is called when this device driver has claimed access to the port but another device driver wants to use it. It is given <em class="parameter"><code>handle</code></em> as its parameter, and should return zero if it is willing for the system to release the port to another driver on its behalf. If it wants to keep control of the port it should return non-zero, and no action will be taken. It is good manners for the driver to try to release the port at the earliest opportunity after its preemption callback rejects a preemption attempt. Note that if a preemption callback is happy for preemption to go ahead, there is no need to release the port; it is done automatically. This function may not block, as it may be called from interrupt context. If the device driver does not support preemption, <em class="parameter"><code>pf</code></em> can be <code class="constant">NULL</code>. </p><p> The wake-up (<span class="quote">“<span class="quote">kick</span>”</span>) callback function, <em class="parameter"><code>kf</code></em>, is called when the port is available to be claimed for exclusive access; that is, <code class="function">parport_claim</code> is guaranteed to succeed when called from inside the wake-up callback function. If the driver wants to claim the port it should do so; otherwise, it need not take any action. This function may not block, as it may be called from interrupt context. If the device driver does not want to be explicitly invited to claim the port in this way, <em class="parameter"><code>kf</code></em> can be <code class="constant">NULL</code>. </p><p> The interrupt handler, <em class="parameter"><code>irq_func</code></em>, is called when an interrupt arrives from the parallel port. Note that if a device driver wants to use interrupts it should use <code class="function">parport_enable_irq</code>, and can also check the irq member of the parport structure representing the port. </p><p> The parallel port (lowlevel) driver is the one that has called <code class="function">request_irq</code> and whose interrupt handler is called first. This handler does whatever needs to be done to the hardware to acknowledge the interrupt (for PC-style ports there is nothing special to be done). It then tells the IEEE 1284 code about the interrupt, which may involve reacting to an IEEE 1284 event depending on the current IEEE 1284 phase. After this, it calls <em class="parameter"><code>irq_func</code></em>. Needless to say, <em class="parameter"><code>irq_func</code></em> will be called from interrupt context, and may not block. </p><p> The <code class="constant">PARPORT_DEV_EXCL</code> flag is for preventing port sharing, and so should only be used when sharing the port with other device drivers is impossible and would lead to incorrect behaviour. Use it sparingly! Normally, <em class="parameter"><code>flags</code></em> will be zero. </p><p> This function returns a pointer to a structure that represents the device on the port, or <code class="constant">NULL</code> if there is not enough memory to allocate space for that structure. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="re290.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="re292.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span>parport_remove_port</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span>parport_unregister_device</span></td></tr></table></div></body></html>