1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Constructor</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Writing an ALSA Driver"><link rel="up" href="midi-interface.html" title="Chapter&#160;8.&#160;MIDI (MPU401-UART) Interface"><link rel="prev" href="midi-interface.html" title="Chapter&#160;8.&#160;MIDI (MPU401-UART) Interface"><link rel="next" href="midi-interface-interrupt-handler.html" title="Interrupt Handler"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Constructor</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="midi-interface.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;8.&#160;MIDI (MPU401-UART) Interface</th><td width="20%" align="right">&#160;<a accesskey="n" href="midi-interface-interrupt-handler.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="midi-interface-constructor"></a>Constructor</h2></div></div></div><p>
2        To create a rawmidi object, call
3      <code class="function">snd_mpu401_uart_new()</code>. 
4
5        </p><div class="informalexample"><pre class="programlisting">
6
7  struct snd_rawmidi *rmidi;
8  snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, port, info_flags,
9                      irq, &amp;rmidi);
10
11          </pre></div><p>
12      </p><p>
13        The first argument is the card pointer, and the second is the
14      index of this component. You can create up to 8 rawmidi
15      devices. 
16      </p><p>
17        The third argument is the type of the hardware,
18      <code class="constant">MPU401_HW_XXX</code>. If it's not a special one,
19      you can use <code class="constant">MPU401_HW_MPU401</code>. 
20      </p><p>
21        The 4th argument is the I/O port address. Many
22      backward-compatible MPU401 have an I/O port such as 0x330. Or, it
23      might be a part of its own PCI I/O region. It depends on the
24      chip design. 
25      </p><p>
26	The 5th argument is a bitflag for additional information.
27        When the I/O port address above is part of the PCI I/O
28      region, the MPU401 I/O port might have been already allocated
29      (reserved) by the driver itself. In such a case, pass a bit flag
30      <code class="constant">MPU401_INFO_INTEGRATED</code>,
31      and the mpu401-uart layer will allocate the I/O ports by itself. 
32      </p><p>
33	When the controller supports only the input or output MIDI stream,
34	pass the <code class="constant">MPU401_INFO_INPUT</code> or
35	<code class="constant">MPU401_INFO_OUTPUT</code> bitflag, respectively.
36	Then the rawmidi instance is created as a single stream.
37	</p><p>
38	<code class="constant">MPU401_INFO_MMIO</code> bitflag is used to change
39	the access method to MMIO (via readb and writeb) instead of
40	iob and outb. In this case, you have to pass the iomapped address
41	to <code class="function">snd_mpu401_uart_new()</code>.
42	</p><p>
43	When <code class="constant">MPU401_INFO_TX_IRQ</code> is set, the output
44	stream isn't checked in the default interrupt handler.  The driver
45	needs to call <code class="function">snd_mpu401_uart_interrupt_tx()</code>
46	by itself to start processing the output stream in the irq handler.
47	</p><p>
48	If the MPU-401 interface shares its interrupt with the other logical
49	devices on the card, set <code class="constant">MPU401_INFO_IRQ_HOOK</code>
50	(see <a class="link" href="midi-interface-interrupt-handler.html" title="Interrupt Handler"><em class="citetitle">
51	below</em></a>).
52	</p><p>
53        Usually, the port address corresponds to the command port and
54        port + 1 corresponds to the data port. If not, you may change
55        the <em class="structfield"><code>cport</code></em> field of
56        struct <span class="structname">snd_mpu401</span> manually 
57        afterward. However, <span class="structname">snd_mpu401</span> pointer is not
58        returned explicitly by
59        <code class="function">snd_mpu401_uart_new()</code>. You need to cast
60        rmidi-&gt;private_data to
61        <span class="structname">snd_mpu401</span> explicitly, 
62
63        </p><div class="informalexample"><pre class="programlisting">
64
65  struct snd_mpu401 *mpu;
66  mpu = rmidi-&gt;private_data;
67
68          </pre></div><p>
69
70        and reset the cport as you like:
71
72        </p><div class="informalexample"><pre class="programlisting">
73
74  mpu-&gt;cport = my_own_control_port;
75
76          </pre></div><p>
77      </p><p>
78	The 6th argument specifies the ISA irq number that will be
79	allocated.  If no interrupt is to be allocated (because your
80	code is already allocating a shared interrupt, or because the
81	device does not use interrupts), pass -1 instead.
82	For a MPU-401 device without an interrupt, a polling timer
83	will be used instead.
84      </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="midi-interface.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="midi-interface.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="midi-interface-interrupt-handler.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&#160;8.&#160;MIDI (MPU401-UART) Interface&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Interrupt Handler</td></tr></table></div></body></html>
85