Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[sfrench/cifs-2.6.git] / sound / pci / mixart / mixart.h
1 /*
2  * Driver for Digigram miXart soundcards
3  *
4  * main header file
5  *
6  * Copyright (c) 2003 by Digigram <alsa@digigram.com>
7  *
8  *   This program is free software; you can redistribute it and/or modify
9  *   it under the terms of the GNU General Public License as published by
10  *   the Free Software Foundation; either version 2 of the License, or
11  *   (at your option) any later version.
12  *
13  *   This program is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with this program; if not, write to the Free Software
20  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  */
22
23 #ifndef __SOUND_MIXART_H
24 #define __SOUND_MIXART_H
25
26 #include <linux/interrupt.h>
27 #include <sound/pcm.h>
28
29 #define MIXART_DRIVER_VERSION   0x000100        /* 0.1.0 */
30
31
32 /*
33  */
34
35 struct mixart_uid {
36         u32 object_id;
37         u32 desc;
38 };
39
40 struct mem_area {
41         unsigned long phys;
42         void __iomem *virt;
43         struct resource *res;
44 };
45
46
47 struct mixart_route {
48         unsigned char connected;
49         unsigned char phase_inv;
50         int volume;
51 };
52
53
54 /* firmware status codes  */
55 #define MIXART_MOTHERBOARD_XLX_INDEX  0
56 #define MIXART_MOTHERBOARD_ELF_INDEX  1
57 #define MIXART_AESEBUBOARD_XLX_INDEX  2
58 #define MIXART_HARDW_FILES_MAX_INDEX  3  /* xilinx, elf, AESEBU xilinx */
59
60 #define MIXART_MAX_CARDS        4
61 #define MSG_FIFO_SIZE           16
62
63 #define MIXART_MAX_PHYS_CONNECTORS  (MIXART_MAX_CARDS * 2 * 2) /* 4 * stereo * (analog+digital) */
64
65 struct mixart_mgr {
66         unsigned int num_cards;
67         struct snd_mixart *chip[MIXART_MAX_CARDS];
68
69         struct pci_dev *pci;
70
71         int irq;
72
73         /* memory-maps */
74         struct mem_area mem[2];
75
76         /* share the name */
77         char shortname[32];         /* short name of this soundcard */
78         char longname[80];          /* name of this soundcard */
79
80         /* message tasklet */
81         struct tasklet_struct msg_taskq;
82
83         /* one and only blocking message or notification may be pending  */
84         u32 pending_event;
85         wait_queue_head_t msg_sleep;
86
87         /* messages stored for tasklet */
88         u32 msg_fifo[MSG_FIFO_SIZE];
89         int msg_fifo_readptr;
90         int msg_fifo_writeptr;
91         atomic_t msg_processed;       /* number of messages to be processed in takslet */
92
93         spinlock_t lock;              /* interrupt spinlock */
94         spinlock_t msg_lock;          /* mailbox spinlock */
95         struct semaphore msg_mutex;   /* mutex for blocking_requests */
96
97         struct semaphore setup_mutex; /* mutex used in hw_params, open and close */
98
99         /* hardware interface */
100         unsigned int dsp_loaded;      /* bit flags of loaded dsp indices */
101         unsigned int board_type;      /* read from embedded once elf file is loaded, 250 = miXart8, 251 = with AES, 252 = with Cobranet */
102
103         struct snd_dma_buffer flowinfo;
104         struct snd_dma_buffer bufferinfo;
105
106         struct mixart_uid         uid_console_manager;
107         int sample_rate;
108         int ref_count_rate;
109
110         struct semaphore mixer_mutex; /* mutex for mixer */
111
112 };
113
114
115 #define MIXART_STREAM_STATUS_FREE       0
116 #define MIXART_STREAM_STATUS_OPEN       1
117 #define MIXART_STREAM_STATUS_RUNNING    2
118 #define MIXART_STREAM_STATUS_DRAINING   3
119 #define MIXART_STREAM_STATUS_PAUSE      4
120
121 #define MIXART_PLAYBACK_STREAMS         4
122 #define MIXART_CAPTURE_STREAMS          1
123
124 #define MIXART_PCM_ANALOG               0
125 #define MIXART_PCM_DIGITAL              1
126 #define MIXART_PCM_TOTAL                2
127
128 #define MIXART_MAX_STREAM_PER_CARD  (MIXART_PCM_TOTAL * (MIXART_PLAYBACK_STREAMS + MIXART_CAPTURE_STREAMS) )
129
130
131 #define MIXART_NOTIFY_CARD_MASK         0xF000
132 #define MIXART_NOTIFY_CARD_OFFSET       12
133 #define MIXART_NOTIFY_PCM_MASK          0x0F00
134 #define MIXART_NOTIFY_PCM_OFFSET        8
135 #define MIXART_NOTIFY_CAPT_MASK         0x0080
136 #define MIXART_NOTIFY_SUBS_MASK         0x007F
137
138
139 struct mixart_stream {
140         struct snd_pcm_substream *substream;
141         struct mixart_pipe *pipe;
142         int pcm_number;
143
144         int status;      /* nothing, running, draining */
145
146         u64  abs_period_elapsed;  /* last absolute stream position where period_elapsed was called (multiple of runtime->period_size) */
147         u32  buf_periods;         /* periods counter in the buffer (< runtime->periods) */
148         u32  buf_period_frag;     /* defines with buf_period_pos the exact position in the buffer (< runtime->period_size) */
149
150         int channels;
151 };
152
153
154 enum mixart_pipe_status {
155         PIPE_UNDEFINED,
156         PIPE_STOPPED,
157         PIPE_RUNNING,
158         PIPE_CLOCK_SET
159 };
160
161 struct mixart_pipe {
162         struct mixart_uid group_uid;                    /* id of the pipe, as returned by embedded */
163         int          stream_count;
164         struct mixart_uid uid_left_connector;   /* UID's for the audio connectors */
165         struct mixart_uid uid_right_connector;
166         enum mixart_pipe_status status;
167         int references;             /* number of subs openned */
168         int monitoring;             /* pipe used for monitoring issue */
169 };
170
171
172 struct snd_mixart {
173         struct snd_card *card;
174         struct mixart_mgr *mgr;
175         int chip_idx;               /* zero based */
176         struct snd_hwdep *hwdep;            /* DSP loader, only for the first card */
177
178         struct snd_pcm *pcm;             /* PCM analog i/o */
179         struct snd_pcm *pcm_dig;         /* PCM digital i/o */
180
181         /* allocate stereo pipe for instance */
182         struct mixart_pipe pipe_in_ana;
183         struct mixart_pipe pipe_out_ana;
184
185         /* if AES/EBU daughter board is available, additional pipes possible on pcm_dig */
186         struct mixart_pipe pipe_in_dig;
187         struct mixart_pipe pipe_out_dig;
188
189         struct mixart_stream playback_stream[MIXART_PCM_TOTAL][MIXART_PLAYBACK_STREAMS]; /* 0 = pcm, 1 = pcm_dig */
190         struct mixart_stream capture_stream[MIXART_PCM_TOTAL];                           /* 0 = pcm, 1 = pcm_dig */
191
192         /* UID's for the physical io's */
193         struct mixart_uid uid_out_analog_physio;
194         struct mixart_uid uid_in_analog_physio;
195
196         int analog_playback_active[2];          /* Mixer : Master Playback active (!mute) */
197         int analog_playback_volume[2];          /* Mixer : Master Playback Volume */
198         int analog_capture_volume[2];           /* Mixer : Master Capture Volume */
199         int digital_playback_active[2*MIXART_PLAYBACK_STREAMS][2];      /* Mixer : Digital Playback Active [(analog+AES output)*streams][stereo]*/
200         int digital_playback_volume[2*MIXART_PLAYBACK_STREAMS][2];      /* Mixer : Digital Playback Volume [(analog+AES output)*streams][stereo]*/
201         int digital_capture_volume[2][2];       /* Mixer : Digital Capture Volume [analog+AES output][stereo] */
202         int monitoring_active[2];               /* Mixer : Monitoring Active */
203         int monitoring_volume[2];               /* Mixer : Monitoring Volume */
204 };
205
206 struct mixart_bufferinfo
207 {
208         u32 buffer_address;
209         u32 reserved[5];
210         u32 available_length;
211         u32 buffer_id;
212 };
213
214 struct mixart_flowinfo
215 {
216         u32 bufferinfo_array_phy_address;
217         u32 reserved[11];
218         u32 bufferinfo_count;
219         u32 capture;
220 };
221
222 /* exported */
223 int snd_mixart_create_pcm(struct snd_mixart * chip);
224 struct mixart_pipe *snd_mixart_add_ref_pipe(struct snd_mixart *chip, int pcm_number, int capture, int monitoring);
225 int snd_mixart_kill_ref_pipe(struct mixart_mgr *mgr, struct mixart_pipe *pipe, int monitoring);
226
227 #endif /* __SOUND_MIXART_H */