4 #include <linux/spinlock.h>
5 #include <linux/interrupt.h>
9 /* The revisions that we currently handle. */
11 REV_NM256AV, REV_NM256ZX
14 /* Per-card structure. */
17 /* Magic number used to verify that this struct is valid. */
18 #define NM_MAGIC_SIG 0x55aa00ff
24 struct ac97_hwint mdev;
26 /* Our audio device numbers. */
29 /* The # of times each device has been opened. (Should only be
33 /* We use two devices, because we can do simultaneous play and record.
34 This keeps track of which device is being used for what purpose;
35 these are the actual device numbers. */
41 /* The mixer device. */
45 * Can only be opened once for each operation. These aren't set
46 * until an actual I/O operation is performed; this allows one
47 * device to be open for read/write without inhibiting I/O to
53 /* Non-zero if we're currently playing a sample. */
55 /* Ditto for recording a sample. */
58 /* The two memory ports. */
60 /* Physical address of the port. */
62 /* Our mapped-in pointer. */
64 /* PTR's offset within the physical port. */
66 /* And the offset of the end of the buffer. */
70 /* The following are offsets within memory port 1. */
74 /* Record and playback buffers. */
77 /* Offset of the AC97 mixer in memory port 2. */
80 /* Offset of the mixer status register in memory port 2. */
81 u32 mixer_status_offset;
83 /* Non-zero if we have written initial values to the mixer. */
87 * Status mask bit; (*mixer_status_loc & mixer_status_mask) == 0 means
90 u16 mixer_status_mask;
92 /* The sizes of the playback and record ring buffers. */
93 u32 playbackBufferSize;
96 /* Are the coefficient values in the memory cache current? */
99 /* For writes, the amount we last wrote. */
101 /* The start of the block currently playing. */
104 /* The amount of data we were requested to record. */
106 /* The offset of the currently-recording block. */
108 /* The destination buffer. */
111 /* Our IRQ number. */
114 /* A flag indicating how many times we've grabbed the IRQ. */
117 /* The card interrupt service routine. */
118 irqreturn_t (*introutine) (int, void *, struct pt_regs *);
120 /* Current audio config, cached. */
125 } sinfo[2]; /* goes with each device */
127 /* The cards are stored in a chain; this is the next card. */
128 struct nm256_info *next_card;
131 /* The BIOS signature. */
132 #define NM_SIGNATURE 0x4e4d0000
133 /* Signature mask. */
134 #define NM_SIG_MASK 0xffff0000
136 /* Size of the second memory area. */
137 #define NM_PORT2_SIZE 4096
139 /* The base offset of the mixer in the second memory area. */
140 #define NM_MIXER_OFFSET 0x600
142 /* The maximum size of a coefficient entry. */
143 #define NM_MAX_COEFFICIENT 0x5000
145 /* The interrupt register. */
146 #define NM_INT_REG 0xa04
148 #define NM_PLAYBACK_INT 0x40
149 #define NM_RECORD_INT 0x100
150 #define NM_MISC_INT_1 0x4000
151 #define NM_MISC_INT_2 0x1
152 #define NM_ACK_INT(CARD, X) nm256_writePort16((CARD), 2, NM_INT_REG, (X) << 1)
154 /* The AV's "mixer ready" status bit and location. */
155 #define NM_MIXER_STATUS_OFFSET 0xa04
156 #define NM_MIXER_READY_MASK 0x0800
157 #define NM_MIXER_PRESENCE 0xa06
158 #define NM_PRESENCE_MASK 0x0050
159 #define NM_PRESENCE_VALUE 0x0040
162 * For the ZX. It uses the same interrupt register, but it holds 32
163 * bits instead of 16.
165 #define NM2_PLAYBACK_INT 0x10000
166 #define NM2_RECORD_INT 0x80000
167 #define NM2_MISC_INT_1 0x8
168 #define NM2_MISC_INT_2 0x2
169 #define NM2_ACK_INT(CARD, X) nm256_writePort32((CARD), 2, NM_INT_REG, (X))
171 /* The ZX's "mixer ready" status bit and location. */
172 #define NM2_MIXER_STATUS_OFFSET 0xa06
173 #define NM2_MIXER_READY_MASK 0x0800
175 /* The playback registers start from here. */
176 #define NM_PLAYBACK_REG_OFFSET 0x0
177 /* The record registers start from here. */
178 #define NM_RECORD_REG_OFFSET 0x200
180 /* The rate register is located 2 bytes from the start of the register area. */
181 #define NM_RATE_REG_OFFSET 2
183 /* Mono/stereo flag, number of bits on playback, and rate mask. */
184 #define NM_RATE_STEREO 1
185 #define NM_RATE_BITS_16 2
186 #define NM_RATE_MASK 0xf0
188 /* Playback enable register. */
189 #define NM_PLAYBACK_ENABLE_REG (NM_PLAYBACK_REG_OFFSET + 0x1)
190 #define NM_PLAYBACK_ENABLE_FLAG 1
191 #define NM_PLAYBACK_ONESHOT 2
192 #define NM_PLAYBACK_FREERUN 4
194 /* Mutes the audio output. */
195 #define NM_AUDIO_MUTE_REG (NM_PLAYBACK_REG_OFFSET + 0x18)
196 #define NM_AUDIO_MUTE_LEFT 0x8000
197 #define NM_AUDIO_MUTE_RIGHT 0x0080
199 /* Recording enable register. */
200 #define NM_RECORD_ENABLE_REG (NM_RECORD_REG_OFFSET + 0)
201 #define NM_RECORD_ENABLE_FLAG 1
202 #define NM_RECORD_FREERUN 2
204 #define NM_RBUFFER_START (NM_RECORD_REG_OFFSET + 0x4)
205 #define NM_RBUFFER_END (NM_RECORD_REG_OFFSET + 0x10)
206 #define NM_RBUFFER_WMARK (NM_RECORD_REG_OFFSET + 0xc)
207 #define NM_RBUFFER_CURRP (NM_RECORD_REG_OFFSET + 0x8)
209 #define NM_PBUFFER_START (NM_PLAYBACK_REG_OFFSET + 0x4)
210 #define NM_PBUFFER_END (NM_PLAYBACK_REG_OFFSET + 0x14)
211 #define NM_PBUFFER_WMARK (NM_PLAYBACK_REG_OFFSET + 0xc)
212 #define NM_PBUFFER_CURRP (NM_PLAYBACK_REG_OFFSET + 0x8)
214 /* A few trivial routines to make it easier to work with the registers
217 /* This is a common code portion used to fix up the port offsets. */
218 #define NM_FIX_PORT \
219 if (port < 1 || port > 2 || card == NULL) \
222 if (offset < card->port[port - 1].start_offset \
223 || offset >= card->port[port - 1].end_offset) { \
224 printk (KERN_ERR "Bad access: port %d, offset 0x%x\n", port, offset); \
227 offset -= card->port[port - 1].start_offset;
229 #define DEFwritePortX(X, func) \
230 static inline int nm256_writePort##X (struct nm256_info *card,\
231 int port, int offset, int value)\
235 if (nm256_debug > 1)\
236 printk (KERN_DEBUG "Writing 0x%x to %d:0x%x\n", value, port, offset);\
240 addr = (u##X __iomem *)(card->port[port - 1].ptr + offset);\
245 DEFwritePortX (8, writeb)
246 DEFwritePortX (16, writew)
247 DEFwritePortX (32, writel)
249 #define DEFreadPortX(X, func) \
250 static inline u##X nm256_readPort##X (struct nm256_info *card,\
251 int port, int offset)\
257 addr = (u##X __iomem *)(card->port[port - 1].ptr + offset);\
261 DEFreadPortX (8, readb)
262 DEFreadPortX (16, readw)
263 DEFreadPortX (32, readl)
266 nm256_writeBuffer8 (struct nm256_info *card, u8 *src, int port, int offset,
270 memcpy_toio (card->port[port - 1].ptr + offset, src, amt);
275 nm256_readBuffer8 (struct nm256_info *card, u8 *dst, int port, int offset,
279 memcpy_fromio (dst, card->port[port - 1].ptr + offset, amt);
283 /* Returns a non-zero value if we should use the coefficient cache. */
284 static int nm256_cachedCoefficients (struct nm256_info *card);