Revert last change. Bug noticed by Linus.
[linux-2.6/linux-mips.git] / drivers / sound / nm256.h
blobc640b88ce7e16dca2390f02d3fae1503c045b85a
1 #ifndef _NM256_H_
2 #define _NM256_H_
4 #include "ac97.h"
6 /* The revisions that we currently handle. */
7 enum nm256rev {
8 REV_NM256AV, REV_NM256ZX
9 };
11 /* Per-card structure. */
12 struct nm256_info
14 /* Magic number used to verify that this struct is valid. */
15 #define NM_MAGIC_SIG 0x55aa00ff
16 int magsig;
18 /* Revision number */
19 enum nm256rev rev;
21 struct ac97_hwint mdev;
23 /* Our audio device numbers. */
24 int dev[2];
26 /* The # of times each device has been opened. (Should only be
27 0 or 1). */
28 int opencnt[2];
30 /* We use two devices, because we can do simultaneous play and record.
31 This keeps track of which device is being used for what purpose;
32 these are the actual device numbers. */
33 int dev_for_play;
34 int dev_for_record;
36 /* The mixer device. */
37 int mixer_oss_dev;
39 /*
40 * Can only be opened once for each operation. These aren't set
41 * until an actual I/O operation is performed; this allows one
42 * device to be open for read/write without inhibiting I/O to
43 * the other device.
45 int is_open_play;
46 int is_open_record;
48 /* Non-zero if we're currently playing a sample. */
49 int playing;
50 /* Ditto for recording a sample. */
51 int recording;
53 /* The two memory ports. */
54 struct nm256_ports {
55 /* Physical address of the port. */
56 u32 physaddr;
57 /* Our mapped-in pointer. */
58 char *ptr;
59 /* PTR's offset within the physical port. */
60 u32 start_offset;
61 /* And the offset of the end of the buffer. */
62 u32 end_offset;
63 } port[2];
65 /* The following are offsets within memory port 1. */
66 u32 coeffBuf;
67 u32 allCoeffBuf;
69 /* Record and playback buffers. */
70 u32 abuf1, abuf2;
72 /* Offset of the AC97 mixer in memory port 2. */
73 u32 mixer;
75 /* Offset of the mixer status register in memory port 2. */
76 u32 mixer_status_offset;
78 /* Non-zero if we have written initial values to the mixer. */
79 u8 mixer_values_init;
81 /*
82 * Status mask bit; (*mixer_status_loc & mixer_status_mask) == 0 means
83 * it's ready.
85 u16 mixer_status_mask;
87 /* The sizes of the playback and record ring buffers. */
88 u32 playbackBufferSize;
89 u32 recordBufferSize;
91 /* Are the coefficient values in the memory cache current? */
92 u8 coeffsCurrent;
94 /* For writes, the amount we last wrote. */
95 u32 requested_amt;
96 /* The start of the block currently playing. */
97 u32 curPlayPos;
99 /* The amount of data we were requested to record. */
100 u32 requestedRecAmt;
101 /* The offset of the currently-recording block. */
102 u32 curRecPos;
103 /* The destination buffer. */
104 char *recBuf;
106 /* Our IRQ number. */
107 int irq;
109 /* A flag indicating how many times we've grabbed the IRQ. */
110 int has_irq;
112 /* The card interrupt service routine. */
113 void (*introutine) (int, void *, struct pt_regs *);
115 /* Current audio config, cached. */
116 struct sinfo {
117 u32 samplerate;
118 u8 bits;
119 u8 stereo;
120 } sinfo[2]; /* goes with each device */
122 /* The cards are stored in a chain; this is the next card. */
123 struct nm256_info *next_card;
126 /* Debug flag--bigger numbers mean more output. */
127 extern int nm256_debug;
129 /* The BIOS signature. */
130 #define NM_SIGNATURE 0x4e4d0000
131 /* Signature mask. */
132 #define NM_SIG_MASK 0xffff0000
134 /* Size of the second memory area. */
135 #define NM_PORT2_SIZE 4096
137 /* The base offset of the mixer in the second memory area. */
138 #define NM_MIXER_OFFSET 0x600
140 /* The maximum size of a coefficient entry. */
141 #define NM_MAX_COEFFICIENT 0x5000
143 /* The interrupt register. */
144 #define NM_INT_REG 0xa04
145 /* And its bits. */
146 #define NM_PLAYBACK_INT 0x40
147 #define NM_RECORD_INT 0x100
148 #define NM_MISC_INT_1 0x4000
149 #define NM_MISC_INT_2 0x1
150 #define NM_ACK_INT(CARD, X) nm256_writePort16((CARD), 2, NM_INT_REG, (X) << 1)
152 /* The AV's "mixer ready" status bit and location. */
153 #define NM_MIXER_STATUS_OFFSET 0xa04
154 #define NM_MIXER_READY_MASK 0x0800
155 #define NM_MIXER_PRESENCE 0xa06
156 #define NM_PRESENCE_MASK 0x0050
157 #define NM_PRESENCE_VALUE 0x0040
160 * For the ZX. It uses the same interrupt register, but it holds 32
161 * bits instead of 16.
163 #define NM2_PLAYBACK_INT 0x10000
164 #define NM2_RECORD_INT 0x80000
165 #define NM2_MISC_INT_1 0x8
166 #define NM2_MISC_INT_2 0x2
167 #define NM2_ACK_INT(CARD, X) nm256_writePort32((CARD), 2, NM_INT_REG, (X))
169 /* The ZX's "mixer ready" status bit and location. */
170 #define NM2_MIXER_STATUS_OFFSET 0xa06
171 #define NM2_MIXER_READY_MASK 0x0800
173 /* The playback registers start from here. */
174 #define NM_PLAYBACK_REG_OFFSET 0x0
175 /* The record registers start from here. */
176 #define NM_RECORD_REG_OFFSET 0x200
178 /* The rate register is located 2 bytes from the start of the register area. */
179 #define NM_RATE_REG_OFFSET 2
181 /* Mono/stereo flag, number of bits on playback, and rate mask. */
182 #define NM_RATE_STEREO 1
183 #define NM_RATE_BITS_16 2
184 #define NM_RATE_MASK 0xf0
186 /* Playback enable register. */
187 #define NM_PLAYBACK_ENABLE_REG (NM_PLAYBACK_REG_OFFSET + 0x1)
188 #define NM_PLAYBACK_ENABLE_FLAG 1
189 #define NM_PLAYBACK_ONESHOT 2
190 #define NM_PLAYBACK_FREERUN 4
192 /* Mutes the audio output. */
193 #define NM_AUDIO_MUTE_REG (NM_PLAYBACK_REG_OFFSET + 0x18)
194 #define NM_AUDIO_MUTE_LEFT 0x8000
195 #define NM_AUDIO_MUTE_RIGHT 0x0080
197 /* Recording enable register. */
198 #define NM_RECORD_ENABLE_REG (NM_RECORD_REG_OFFSET + 0)
199 #define NM_RECORD_ENABLE_FLAG 1
200 #define NM_RECORD_FREERUN 2
202 #define NM_RBUFFER_START (NM_RECORD_REG_OFFSET + 0x4)
203 #define NM_RBUFFER_END (NM_RECORD_REG_OFFSET + 0x10)
204 #define NM_RBUFFER_WMARK (NM_RECORD_REG_OFFSET + 0xc)
205 #define NM_RBUFFER_CURRP (NM_RECORD_REG_OFFSET + 0x8)
207 #define NM_PBUFFER_START (NM_PLAYBACK_REG_OFFSET + 0x4)
208 #define NM_PBUFFER_END (NM_PLAYBACK_REG_OFFSET + 0x14)
209 #define NM_PBUFFER_WMARK (NM_PLAYBACK_REG_OFFSET + 0xc)
210 #define NM_PBUFFER_CURRP (NM_PLAYBACK_REG_OFFSET + 0x8)
212 /* A few trivial routines to make it easier to work with the registers
213 on the chip. */
215 /* This is a common code portion used to fix up the port offsets. */
216 #define NM_FIX_PORT \
217 if (port < 1 || port > 2 || card == NULL) \
218 return -1; \
220 if (offset < card->port[port - 1].start_offset \
221 || offset >= card->port[port - 1].end_offset) { \
222 printk (KERN_ERR "Bad access: port %d, offset 0x%x\n", port, offset); \
223 return -1; \
225 offset -= card->port[port - 1].start_offset;
227 #define DEFwritePortX(X, func) \
228 static inline int nm256_writePort##X (struct nm256_info *card,\
229 int port, int offset, int value)\
231 u##X *addr;\
233 if (nm256_debug > 1)\
234 printk (KERN_DEBUG "Writing 0x%x to %d:0x%x\n", value, port, offset);\
236 NM_FIX_PORT;\
238 addr = (u##X *)(card->port[port - 1].ptr + offset);\
239 func (value, addr);\
240 return 0;\
243 DEFwritePortX (8, writeb)
244 DEFwritePortX (16, writew)
245 DEFwritePortX (32, writel)
247 #define DEFreadPortX(X, func) \
248 static inline u##X nm256_readPort##X (struct nm256_info *card,\
249 int port, int offset)\
251 u##X *addr;\
253 NM_FIX_PORT\
255 addr = (u##X *)(card->port[port - 1].ptr + offset);\
256 return func(addr);\
259 DEFreadPortX (8, readb)
260 DEFreadPortX (16, readw)
261 DEFreadPortX (32, readl)
263 static inline int
264 nm256_writeBuffer8 (struct nm256_info *card, u8 *src, int port, int offset,
265 int amt)
267 NM_FIX_PORT;
268 memcpy_toio (card->port[port - 1].ptr + offset, src, amt);
269 return 0;
272 static inline int
273 nm256_readBuffer8 (struct nm256_info *card, u8 *dst, int port, int offset,
274 int amt)
276 NM_FIX_PORT;
277 memcpy_fromio (dst, card->port[port - 1].ptr + offset, amt);
278 return 0;
281 /* Returns a non-zero value if we should use the coefficient cache. */
282 extern int nm256_cachedCoefficients (struct nm256_info *card);
284 #endif
287 * Local variables:
288 * c-basic-offset: 4
289 * End: