2 * Driver for the Conexant Riptide Soundchip
4 * Copyright (c) 2004 Peter Gruber <nokos@gmx.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 - 02/15/2004 first release
25 This Driver is based on the OSS Driver version from Linuxant (riptide-0.6lnxtbeta03111100)
26 credits from the original files:
28 MODULE NAME: cnxt_rt.h
29 AUTHOR: K. Lazarev (Transcribed by KNL)
30 HISTORY: Major Revision Date By
31 ----------------------------- -------- -----
34 MODULE NAME: int_mdl.c
35 AUTHOR: Konstantin Lazarev (Transcribed by KNL)
36 HISTORY: Major Revision Date By
37 ----------------------------- -------- -----
40 MODULE NAME: riptide.h
41 AUTHOR: O. Druzhinin (Transcribed by OLD)
42 HISTORY: Major Revision Date By
43 ----------------------------- -------- -----
46 MODULE NAME: Rp_Cmdif.cpp
47 AUTHOR: O. Druzhinin (Transcribed by OLD)
48 K. Lazarev (Transcribed by KNL)
49 HISTORY: Major Revision Date By
50 ----------------------------- -------- -----
51 Adopted from NT4 driver 6/22/99 OLD
52 Ported to Linux 9/01/99 KNL
55 AUTHOR: O. Druzhinin (Transcribed by OLD)
56 C. Lazarev (Transcribed by CNL)
57 HISTORY: Major Revision Date By
58 ----------------------------- -------- -----
60 Hardware functions for RipTide 11/24/97 CNL
62 Hardware functions for RipTide 12/24/97 CNL
64 Hardware functions for RipTide 03/20/98 CNL
66 Boot loader is included 05/07/98 CNL
67 Redesigned for WDM 07/27/98 CNL
68 Redesigned for Linux 09/01/99 CNL
71 AUTHOR: C. Lazarev (Transcribed by CNL)
72 HISTORY: Major Revision Date By
73 ----------------------------- -------- -----
77 AUTHOR: Konstantin Lazarev (Transcribed by KNL)
78 HISTORY: Major Revision Date By
79 ----------------------------- -------- -----
84 HISTORY: Major Revision Date By
85 ----------------------------- -------- -----
86 Created from MS W95 Sample 11/28/95 KRS
88 Adopted for Windows NT driver 01/20/98 CNL
91 #include <linux/delay.h>
92 #include <linux/init.h>
93 #include <linux/interrupt.h>
94 #include <linux/pci.h>
95 #include <linux/slab.h>
96 #include <linux/wait.h>
97 #include <linux/gameport.h>
98 #include <linux/device.h>
99 #include <linux/firmware.h>
100 #include <linux/kernel.h>
101 #include <linux/module.h>
103 #include <sound/core.h>
104 #include <sound/info.h>
105 #include <sound/control.h>
106 #include <sound/pcm.h>
107 #include <sound/pcm_params.h>
108 #include <sound/ac97_codec.h>
109 #include <sound/mpu401.h>
110 #include <sound/opl3.h>
111 #include <sound/initval.h>
113 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
114 #define SUPPORT_JOYSTICK 1
117 MODULE_AUTHOR("Peter Gruber <nokos@gmx.net>");
118 MODULE_DESCRIPTION("riptide");
119 MODULE_LICENSE("GPL");
120 MODULE_SUPPORTED_DEVICE("{{Conexant,Riptide}}");
121 MODULE_FIRMWARE("riptide.hex");
123 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
124 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
125 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE
;
127 #ifdef SUPPORT_JOYSTICK
128 static int joystick_port
[SNDRV_CARDS
] = { [0 ... (SNDRV_CARDS
- 1)] = 0x200 };
130 static int mpu_port
[SNDRV_CARDS
] = { [0 ... (SNDRV_CARDS
- 1)] = 0x330 };
131 static int opl3_port
[SNDRV_CARDS
] = { [0 ... (SNDRV_CARDS
- 1)] = 0x388 };
133 module_param_array(index
, int, NULL
, 0444);
134 MODULE_PARM_DESC(index
, "Index value for Riptide soundcard.");
135 module_param_array(id
, charp
, NULL
, 0444);
136 MODULE_PARM_DESC(id
, "ID string for Riptide soundcard.");
137 module_param_array(enable
, bool, NULL
, 0444);
138 MODULE_PARM_DESC(enable
, "Enable Riptide soundcard.");
139 #ifdef SUPPORT_JOYSTICK
140 module_param_array(joystick_port
, int, NULL
, 0444);
141 MODULE_PARM_DESC(joystick_port
, "Joystick port # for Riptide soundcard.");
143 module_param_array(mpu_port
, int, NULL
, 0444);
144 MODULE_PARM_DESC(mpu_port
, "MPU401 port # for Riptide driver.");
145 module_param_array(opl3_port
, int, NULL
, 0444);
146 MODULE_PARM_DESC(opl3_port
, "OPL3 port # for Riptide driver.");
151 #define MPU401_HW_RIPTIDE MPU401_HW_MPU401
152 #define OPL3_HW_RIPTIDE OPL3_HW_OPL3
154 #define PCI_EXT_CapId 0x40
155 #define PCI_EXT_NextCapPrt 0x41
156 #define PCI_EXT_PWMC 0x42
157 #define PCI_EXT_PWSCR 0x44
158 #define PCI_EXT_Data00 0x46
159 #define PCI_EXT_PMSCR_BSE 0x47
160 #define PCI_EXT_SB_Base 0x48
161 #define PCI_EXT_FM_Base 0x4a
162 #define PCI_EXT_MPU_Base 0x4C
163 #define PCI_EXT_Game_Base 0x4E
164 #define PCI_EXT_Legacy_Mask 0x50
165 #define PCI_EXT_AsicRev 0x52
166 #define PCI_EXT_Reserved3 0x53
168 #define LEGACY_ENABLE_ALL 0x8000 /* legacy device options */
169 #define LEGACY_ENABLE_SB 0x4000
170 #define LEGACY_ENABLE_FM 0x2000
171 #define LEGACY_ENABLE_MPU_INT 0x1000
172 #define LEGACY_ENABLE_MPU 0x0800
173 #define LEGACY_ENABLE_GAMEPORT 0x0400
175 #define MAX_WRITE_RETRY 10 /* cmd interface limits */
176 #define MAX_ERROR_COUNT 10
177 #define CMDIF_TIMEOUT 50000
178 #define RESET_TRIES 5
180 #define READ_PORT_ULONG(p) inl((unsigned long)&(p))
181 #define WRITE_PORT_ULONG(p,x) outl(x,(unsigned long)&(p))
183 #define READ_AUDIO_CONTROL(p) READ_PORT_ULONG(p->audio_control)
184 #define WRITE_AUDIO_CONTROL(p,x) WRITE_PORT_ULONG(p->audio_control,x)
185 #define UMASK_AUDIO_CONTROL(p,x) WRITE_PORT_ULONG(p->audio_control,READ_PORT_ULONG(p->audio_control)|x)
186 #define MASK_AUDIO_CONTROL(p,x) WRITE_PORT_ULONG(p->audio_control,READ_PORT_ULONG(p->audio_control)&x)
187 #define READ_AUDIO_STATUS(p) READ_PORT_ULONG(p->audio_status)
189 #define SET_GRESET(p) UMASK_AUDIO_CONTROL(p,0x0001) /* global reset switch */
190 #define UNSET_GRESET(p) MASK_AUDIO_CONTROL(p,~0x0001)
191 #define SET_AIE(p) UMASK_AUDIO_CONTROL(p,0x0004) /* interrupt enable */
192 #define UNSET_AIE(p) MASK_AUDIO_CONTROL(p,~0x0004)
193 #define SET_AIACK(p) UMASK_AUDIO_CONTROL(p,0x0008) /* interrupt acknowledge */
194 #define UNSET_AIACKT(p) MASKAUDIO_CONTROL(p,~0x0008)
195 #define SET_ECMDAE(p) UMASK_AUDIO_CONTROL(p,0x0010)
196 #define UNSET_ECMDAE(p) MASK_AUDIO_CONTROL(p,~0x0010)
197 #define SET_ECMDBE(p) UMASK_AUDIO_CONTROL(p,0x0020)
198 #define UNSET_ECMDBE(p) MASK_AUDIO_CONTROL(p,~0x0020)
199 #define SET_EDATAF(p) UMASK_AUDIO_CONTROL(p,0x0040)
200 #define UNSET_EDATAF(p) MASK_AUDIO_CONTROL(p,~0x0040)
201 #define SET_EDATBF(p) UMASK_AUDIO_CONTROL(p,0x0080)
202 #define UNSET_EDATBF(p) MASK_AUDIO_CONTROL(p,~0x0080)
203 #define SET_ESBIRQON(p) UMASK_AUDIO_CONTROL(p,0x0100)
204 #define UNSET_ESBIRQON(p) MASK_AUDIO_CONTROL(p,~0x0100)
205 #define SET_EMPUIRQ(p) UMASK_AUDIO_CONTROL(p,0x0200)
206 #define UNSET_EMPUIRQ(p) MASK_AUDIO_CONTROL(p,~0x0200)
207 #define IS_CMDE(a) (READ_PORT_ULONG(a->stat)&0x1) /* cmd empty */
208 #define IS_DATF(a) (READ_PORT_ULONG(a->stat)&0x2) /* data filled */
209 #define IS_READY(p) (READ_AUDIO_STATUS(p)&0x0001)
210 #define IS_DLREADY(p) (READ_AUDIO_STATUS(p)&0x0002)
211 #define IS_DLERR(p) (READ_AUDIO_STATUS(p)&0x0004)
212 #define IS_GERR(p) (READ_AUDIO_STATUS(p)&0x0008) /* error ! */
213 #define IS_CMDAEIRQ(p) (READ_AUDIO_STATUS(p)&0x0010)
214 #define IS_CMDBEIRQ(p) (READ_AUDIO_STATUS(p)&0x0020)
215 #define IS_DATAFIRQ(p) (READ_AUDIO_STATUS(p)&0x0040)
216 #define IS_DATBFIRQ(p) (READ_AUDIO_STATUS(p)&0x0080)
217 #define IS_EOBIRQ(p) (READ_AUDIO_STATUS(p)&0x0100) /* interrupt status */
218 #define IS_EOSIRQ(p) (READ_AUDIO_STATUS(p)&0x0200)
219 #define IS_EOCIRQ(p) (READ_AUDIO_STATUS(p)&0x0400)
220 #define IS_UNSLIRQ(p) (READ_AUDIO_STATUS(p)&0x0800)
221 #define IS_SBIRQ(p) (READ_AUDIO_STATUS(p)&0x1000)
222 #define IS_MPUIRQ(p) (READ_AUDIO_STATUS(p)&0x2000)
224 #define RESP 0x00000001 /* command flags */
225 #define PARM 0x00000002
226 #define CMDA 0x00000004
227 #define CMDB 0x00000008
228 #define NILL 0x00000000
230 #define LONG0(a) ((u32)a) /* shifts and masks */
231 #define BYTE0(a) (LONG0(a)&0xff)
232 #define BYTE1(a) (BYTE0(a)<<8)
233 #define BYTE2(a) (BYTE0(a)<<16)
234 #define BYTE3(a) (BYTE0(a)<<24)
235 #define WORD0(a) (LONG0(a)&0xffff)
236 #define WORD1(a) (WORD0(a)<<8)
237 #define WORD2(a) (WORD0(a)<<16)
238 #define TRINIB0(a) (LONG0(a)&0xffffff)
239 #define TRINIB1(a) (TRINIB0(a)<<8)
241 #define RET(a) ((union cmdret *)(a))
243 #define SEND_GETV(p,b) sendcmd(p,RESP,GETV,0,RET(b)) /* get version */
244 #define SEND_GETC(p,b,c) sendcmd(p,PARM|RESP,GETC,c,RET(b))
245 #define SEND_GUNS(p,b) sendcmd(p,RESP,GUNS,0,RET(b))
246 #define SEND_SCID(p,b) sendcmd(p,RESP,SCID,0,RET(b))
247 #define SEND_RMEM(p,b,c,d) sendcmd(p,PARM|RESP,RMEM|BYTE1(b),LONG0(c),RET(d)) /* memory access for firmware write */
248 #define SEND_SMEM(p,b,c) sendcmd(p,PARM,SMEM|BYTE1(b),LONG0(c),RET(0)) /* memory access for firmware write */
249 #define SEND_WMEM(p,b,c) sendcmd(p,PARM,WMEM|BYTE1(b),LONG0(c),RET(0)) /* memory access for firmware write */
250 #define SEND_SDTM(p,b,c) sendcmd(p,PARM|RESP,SDTM|TRINIB1(b),0,RET(c)) /* memory access for firmware write */
251 #define SEND_GOTO(p,b) sendcmd(p,PARM,GOTO,LONG0(b),RET(0)) /* memory access for firmware write */
252 #define SEND_SETDPLL(p) sendcmd(p,0,ARM_SETDPLL,0,RET(0))
253 #define SEND_SSTR(p,b,c) sendcmd(p,PARM,SSTR|BYTE3(b),LONG0(c),RET(0)) /* start stream */
254 #define SEND_PSTR(p,b) sendcmd(p,PARM,PSTR,BYTE3(b),RET(0)) /* pause stream */
255 #define SEND_KSTR(p,b) sendcmd(p,PARM,KSTR,BYTE3(b),RET(0)) /* stop stream */
256 #define SEND_KDMA(p) sendcmd(p,0,KDMA,0,RET(0)) /* stop all dma */
257 #define SEND_GPOS(p,b,c,d) sendcmd(p,PARM|RESP,GPOS,BYTE3(c)|BYTE2(b),RET(d)) /* get position in dma */
258 #define SEND_SETF(p,b,c,d,e,f,g) sendcmd(p,PARM,SETF|WORD1(b)|BYTE3(c),d|BYTE1(e)|BYTE2(f)|BYTE3(g),RET(0)) /* set sample format at mixer */
259 #define SEND_GSTS(p,b,c,d) sendcmd(p,PARM|RESP,GSTS,BYTE3(c)|BYTE2(b),RET(d))
260 #define SEND_NGPOS(p,b,c,d) sendcmd(p,PARM|RESP,NGPOS,BYTE3(c)|BYTE2(b),RET(d))
261 #define SEND_PSEL(p,b,c) sendcmd(p,PARM,PSEL,BYTE2(b)|BYTE3(c),RET(0)) /* activate lbus path */
262 #define SEND_PCLR(p,b,c) sendcmd(p,PARM,PCLR,BYTE2(b)|BYTE3(c),RET(0)) /* deactivate lbus path */
263 #define SEND_PLST(p,b) sendcmd(p,PARM,PLST,BYTE3(b),RET(0))
264 #define SEND_RSSV(p,b,c,d) sendcmd(p,PARM|RESP,RSSV,BYTE2(b)|BYTE3(c),RET(d))
265 #define SEND_LSEL(p,b,c,d,e,f,g,h) sendcmd(p,PARM,LSEL|BYTE1(b)|BYTE2(c)|BYTE3(d),BYTE0(e)|BYTE1(f)|BYTE2(g)|BYTE3(h),RET(0)) /* select paths for internal connections */
266 #define SEND_SSRC(p,b,c,d,e) sendcmd(p,PARM,SSRC|BYTE1(b)|WORD2(c),WORD0(d)|WORD2(e),RET(0)) /* configure source */
267 #define SEND_SLST(p,b) sendcmd(p,PARM,SLST,BYTE3(b),RET(0))
268 #define SEND_RSRC(p,b,c) sendcmd(p,RESP,RSRC|BYTE1(b),0,RET(c)) /* read source config */
269 #define SEND_SSRB(p,b,c) sendcmd(p,PARM,SSRB|BYTE1(b),WORD2(c),RET(0))
270 #define SEND_SDGV(p,b,c,d,e) sendcmd(p,PARM,SDGV|BYTE2(b)|BYTE3(c),WORD0(d)|WORD2(e),RET(0)) /* set digital mixer */
271 #define SEND_RDGV(p,b,c,d) sendcmd(p,PARM|RESP,RDGV|BYTE2(b)|BYTE3(c),0,RET(d)) /* read digital mixer */
272 #define SEND_DLST(p,b) sendcmd(p,PARM,DLST,BYTE3(b),RET(0))
273 #define SEND_SACR(p,b,c) sendcmd(p,PARM,SACR,WORD0(b)|WORD2(c),RET(0)) /* set AC97 register */
274 #define SEND_RACR(p,b,c) sendcmd(p,PARM|RESP,RACR,WORD2(b),RET(c)) /* get AC97 register */
275 #define SEND_ALST(p,b) sendcmd(p,PARM,ALST,BYTE3(b),RET(0))
276 #define SEND_TXAC(p,b,c,d,e,f) sendcmd(p,PARM,TXAC|BYTE1(b)|WORD2(c),WORD0(d)|BYTE2(e)|BYTE3(f),RET(0))
277 #define SEND_RXAC(p,b,c,d) sendcmd(p,PARM|RESP,RXAC,BYTE2(b)|BYTE3(c),RET(d))
278 #define SEND_SI2S(p,b) sendcmd(p,PARM,SI2S,WORD2(b),RET(0))
280 #define EOB_STATUS 0x80000000 /* status flags : block boundary */
281 #define EOS_STATUS 0x40000000 /* : stoppped */
282 #define EOC_STATUS 0x20000000 /* : stream end */
283 #define ERR_STATUS 0x10000000
284 #define EMPTY_STATUS 0x08000000
286 #define IEOB_ENABLE 0x1 /* enable interrupts for status notification above */
287 #define IEOS_ENABLE 0x2
288 #define IEOC_ENABLE 0x4
290 #define DESC_MAX_MASK 0xff
292 #define ST_PLAY 0x1 /* stream states */
296 #define I2S_INTDEC 3 /* config for I2S link */
298 #define I2S_SPLITTER 0
300 #define I2S_RATE 44100
302 #define MODEM_INTDEC 4 /* config for modem link */
303 #define MODEM_MERGER 3
304 #define MODEM_SPLITTER 0
305 #define MODEM_MIXER 11
307 #define FM_INTDEC 3 /* config for FM/OPL3 link */
309 #define FM_SPLITTER 0
312 #define SPLIT_PATH 0x80 /* path splitting flag */
315 DATA_REC
= 0, EXT_END_OF_FILE
, EXT_SEG_ADDR_REC
, EXT_GOTO_CMD_REC
,
320 GETV
= 0x00, GETC
, GUNS
, SCID
, RMEM
=
321 0x10, SMEM
, WMEM
, SDTM
, GOTO
, SSTR
=
322 0x20, PSTR
, KSTR
, KDMA
, GPOS
, SETF
, GSTS
, NGPOS
, PSEL
=
323 0x30, PCLR
, PLST
, RSSV
, LSEL
, SSRC
= 0x40, SLST
, RSRC
, SSRB
, SDGV
=
324 0x50, RDGV
, DLST
, SACR
= 0x60, RACR
, ALST
, TXAC
, RXAC
, SI2S
=
325 0x70, ARM_SETDPLL
= 0x72,
329 ARM2LBUS_FIFO0
= 0, ARM2LBUS_FIFO1
, ARM2LBUS_FIFO2
, ARM2LBUS_FIFO3
,
330 ARM2LBUS_FIFO4
, ARM2LBUS_FIFO5
, ARM2LBUS_FIFO6
, ARM2LBUS_FIFO7
,
331 ARM2LBUS_FIFO8
, ARM2LBUS_FIFO9
, ARM2LBUS_FIFO10
, ARM2LBUS_FIFO11
,
332 ARM2LBUS_FIFO12
, ARM2LBUS_FIFO13
, ARM2LBUS_FIFO14
, ARM2LBUS_FIFO15
,
333 INTER0_OUT
, INTER1_OUT
, INTER2_OUT
, INTER3_OUT
, INTER4_OUT
,
334 INTERM0_OUT
, INTERM1_OUT
, INTERM2_OUT
, INTERM3_OUT
, INTERM4_OUT
,
335 INTERM5_OUT
, INTERM6_OUT
, DECIMM0_OUT
, DECIMM1_OUT
, DECIMM2_OUT
,
336 DECIMM3_OUT
, DECIM0_OUT
, SR3_4_OUT
, OPL3_SAMPLE
, ASRC0
, ASRC1
,
337 ACLNK2PADC
, ACLNK2MODEM0RX
, ACLNK2MIC
, ACLNK2MODEM1RX
, ACLNK2HNDMIC
,
338 DIGITAL_MIXER_OUT0
, GAINFUNC0_OUT
, GAINFUNC1_OUT
, GAINFUNC2_OUT
,
339 GAINFUNC3_OUT
, GAINFUNC4_OUT
, SOFTMODEMTX
, SPLITTER0_OUTL
,
340 SPLITTER0_OUTR
, SPLITTER1_OUTL
, SPLITTER1_OUTR
, SPLITTER2_OUTL
,
341 SPLITTER2_OUTR
, SPLITTER3_OUTL
, SPLITTER3_OUTR
, MERGER0_OUT
,
342 MERGER1_OUT
, MERGER2_OUT
, MERGER3_OUT
, ARM2LBUS_FIFO_DIRECT
, NO_OUT
346 LBUS2ARM_FIFO0
= 0, LBUS2ARM_FIFO1
, LBUS2ARM_FIFO2
, LBUS2ARM_FIFO3
,
347 LBUS2ARM_FIFO4
, LBUS2ARM_FIFO5
, LBUS2ARM_FIFO6
, LBUS2ARM_FIFO7
,
348 INTER0_IN
, INTER1_IN
, INTER2_IN
, INTER3_IN
, INTER4_IN
, INTERM0_IN
,
349 INTERM1_IN
, INTERM2_IN
, INTERM3_IN
, INTERM4_IN
, INTERM5_IN
, INTERM6_IN
,
350 DECIMM0_IN
, DECIMM1_IN
, DECIMM2_IN
, DECIMM3_IN
, DECIM0_IN
, SR3_4_IN
,
351 PDAC2ACLNK
, MODEM0TX2ACLNK
, MODEM1TX2ACLNK
, HNDSPK2ACLNK
,
352 DIGITAL_MIXER_IN0
, DIGITAL_MIXER_IN1
, DIGITAL_MIXER_IN2
,
353 DIGITAL_MIXER_IN3
, DIGITAL_MIXER_IN4
, DIGITAL_MIXER_IN5
,
354 DIGITAL_MIXER_IN6
, DIGITAL_MIXER_IN7
, DIGITAL_MIXER_IN8
,
355 DIGITAL_MIXER_IN9
, DIGITAL_MIXER_IN10
, DIGITAL_MIXER_IN11
,
356 GAINFUNC0_IN
, GAINFUNC1_IN
, GAINFUNC2_IN
, GAINFUNC3_IN
, GAINFUNC4_IN
,
357 SOFTMODEMRX
, SPLITTER0_IN
, SPLITTER1_IN
, SPLITTER2_IN
, SPLITTER3_IN
,
358 MERGER0_INL
, MERGER0_INR
, MERGER1_INL
, MERGER1_INR
, MERGER2_INL
,
359 MERGER2_INR
, MERGER3_INL
, MERGER3_INR
, E2SINK_MAX
363 LS_SRC_INTERPOLATOR
= 0, LS_SRC_INTERPOLATORM
, LS_SRC_DECIMATOR
,
364 LS_SRC_DECIMATORM
, LS_MIXER_IN
, LS_MIXER_GAIN_FUNCTION
,
365 LS_SRC_SPLITTER
, LS_SRC_MERGER
, LS_NONE1
, LS_NONE2
,
368 enum RT_CHANNEL_IDS
{
369 M0TX
= 0, M1TX
, TAMTX
, HSSPKR
, PDAC
, DSNDTX0
, DSNDTX1
, DSNDTX2
,
370 DSNDTX3
, DSNDTX4
, DSNDTX5
, DSNDTX6
, DSNDTX7
, WVSTRTX
, COP3DTX
, SPARE
,
371 M0RX
, HSMIC
, M1RX
, CLEANRX
, MICADC
, PADC
, COPRX1
, COPRX2
,
375 enum { SB_CMD
= 0, MODEM_CMD
, I2S_CMD0
, I2S_CMD1
, FM_CMD
, MAX_CMD
};
378 unsigned char *noconv
;
379 unsigned char *stereo
;
384 u32 data1
; /* cmd,param */
385 u32 data2
; /* param */
386 u32 stat
; /* status */
391 u32 audio_control
; /* status registers */
394 struct cmdport port
[2]; /* command ports */
398 struct riptideport
*hwport
;
400 unsigned int cmdcnt
; /* cmd statistics */
401 unsigned int cmdtime
;
402 unsigned int cmdtimemax
;
403 unsigned int cmdtimemin
;
408 struct riptide_firmware
{
421 union firmware_version
{
423 struct riptide_firmware firmware
;
426 #define get_pcmhwdev(substream) (struct pcmhw *)(substream->runtime->private_data)
428 #define PLAYBACK_SUBSTREAMS 3
430 struct snd_card
*card
;
432 const struct firmware
*fw_entry
;
437 struct snd_pcm
*pcm_i2s
;
438 struct snd_rawmidi
*rmidi
;
439 struct snd_opl3
*opl3
;
440 struct snd_ac97
*ac97
;
441 struct snd_ac97_bus
*ac97_bus
;
443 struct snd_pcm_substream
*playback_substream
[PLAYBACK_SUBSTREAMS
];
444 struct snd_pcm_substream
*capture_substream
;
450 unsigned short mpuaddr
;
451 unsigned short opladdr
;
452 #ifdef SUPPORT_JOYSTICK
453 unsigned short gameaddr
;
455 struct resource
*res_port
;
457 unsigned short device_id
;
459 union firmware_version firmware
;
462 struct tasklet_struct riptide_tq
;
463 struct snd_info_entry
*proc_entry
;
465 unsigned long received_irqs
;
466 unsigned long handled_irqs
;
472 struct sgd
{ /* scatter gather desriptor */
479 struct pcmhw
{ /* pcm descriptor */
480 struct lbuspath paths
;
481 unsigned char *lbuspath
;
482 unsigned char source
;
483 unsigned char intdec
[2];
488 unsigned int channels
;
489 snd_pcm_format_t format
;
490 struct snd_dma_buffer sgdlist
;
495 unsigned int pointer
;
498 #define CMDRET_ZERO (union cmdret){{(u32)0, (u32) 0}}
500 static int sendcmd(struct cmdif
*cif
, u32 flags
, u32 cmd
, u32 parm
,
502 static int getsourcesink(struct cmdif
*cif
, unsigned char source
,
503 unsigned char sink
, unsigned char *a
,
505 static int snd_riptide_initialize(struct snd_riptide
*chip
);
506 static int riptide_reset(struct cmdif
*cif
, struct snd_riptide
*chip
);
511 static DEFINE_PCI_DEVICE_TABLE(snd_riptide_ids
) = {
512 { PCI_DEVICE(0x127a, 0x4310) },
513 { PCI_DEVICE(0x127a, 0x4320) },
514 { PCI_DEVICE(0x127a, 0x4330) },
515 { PCI_DEVICE(0x127a, 0x4340) },
519 #ifdef SUPPORT_JOYSTICK
520 static DEFINE_PCI_DEVICE_TABLE(snd_riptide_joystick_ids
) = {
521 { PCI_DEVICE(0x127a, 0x4312) },
522 { PCI_DEVICE(0x127a, 0x4322) },
523 { PCI_DEVICE(0x127a, 0x4332) },
524 { PCI_DEVICE(0x127a, 0x4342) },
529 MODULE_DEVICE_TABLE(pci
, snd_riptide_ids
);
534 static unsigned char lbusin2out
[E2SINK_MAX
+ 1][2] = {
535 {NO_OUT
, LS_NONE1
}, {NO_OUT
, LS_NONE2
}, {NO_OUT
, LS_NONE1
}, {NO_OUT
,
537 {NO_OUT
, LS_NONE1
}, {NO_OUT
, LS_NONE2
}, {NO_OUT
, LS_NONE1
}, {NO_OUT
,
539 {INTER0_OUT
, LS_SRC_INTERPOLATOR
}, {INTER1_OUT
, LS_SRC_INTERPOLATOR
},
540 {INTER2_OUT
, LS_SRC_INTERPOLATOR
}, {INTER3_OUT
, LS_SRC_INTERPOLATOR
},
541 {INTER4_OUT
, LS_SRC_INTERPOLATOR
}, {INTERM0_OUT
, LS_SRC_INTERPOLATORM
},
542 {INTERM1_OUT
, LS_SRC_INTERPOLATORM
}, {INTERM2_OUT
,
543 LS_SRC_INTERPOLATORM
},
544 {INTERM3_OUT
, LS_SRC_INTERPOLATORM
}, {INTERM4_OUT
,
545 LS_SRC_INTERPOLATORM
},
546 {INTERM5_OUT
, LS_SRC_INTERPOLATORM
}, {INTERM6_OUT
,
547 LS_SRC_INTERPOLATORM
},
548 {DECIMM0_OUT
, LS_SRC_DECIMATORM
}, {DECIMM1_OUT
, LS_SRC_DECIMATORM
},
549 {DECIMM2_OUT
, LS_SRC_DECIMATORM
}, {DECIMM3_OUT
, LS_SRC_DECIMATORM
},
550 {DECIM0_OUT
, LS_SRC_DECIMATOR
}, {SR3_4_OUT
, LS_NONE1
}, {NO_OUT
,
552 {NO_OUT
, LS_NONE1
}, {NO_OUT
, LS_NONE2
}, {NO_OUT
, LS_NONE1
},
553 {DIGITAL_MIXER_OUT0
, LS_MIXER_IN
}, {DIGITAL_MIXER_OUT0
, LS_MIXER_IN
},
554 {DIGITAL_MIXER_OUT0
, LS_MIXER_IN
}, {DIGITAL_MIXER_OUT0
, LS_MIXER_IN
},
555 {DIGITAL_MIXER_OUT0
, LS_MIXER_IN
}, {DIGITAL_MIXER_OUT0
, LS_MIXER_IN
},
556 {DIGITAL_MIXER_OUT0
, LS_MIXER_IN
}, {DIGITAL_MIXER_OUT0
, LS_MIXER_IN
},
557 {DIGITAL_MIXER_OUT0
, LS_MIXER_IN
}, {DIGITAL_MIXER_OUT0
, LS_MIXER_IN
},
558 {DIGITAL_MIXER_OUT0
, LS_MIXER_IN
}, {DIGITAL_MIXER_OUT0
, LS_MIXER_IN
},
559 {GAINFUNC0_OUT
, LS_MIXER_GAIN_FUNCTION
}, {GAINFUNC1_OUT
,
560 LS_MIXER_GAIN_FUNCTION
},
561 {GAINFUNC2_OUT
, LS_MIXER_GAIN_FUNCTION
}, {GAINFUNC3_OUT
,
562 LS_MIXER_GAIN_FUNCTION
},
563 {GAINFUNC4_OUT
, LS_MIXER_GAIN_FUNCTION
}, {SOFTMODEMTX
, LS_NONE1
},
564 {SPLITTER0_OUTL
, LS_SRC_SPLITTER
}, {SPLITTER1_OUTL
, LS_SRC_SPLITTER
},
565 {SPLITTER2_OUTL
, LS_SRC_SPLITTER
}, {SPLITTER3_OUTL
, LS_SRC_SPLITTER
},
566 {MERGER0_OUT
, LS_SRC_MERGER
}, {MERGER0_OUT
, LS_SRC_MERGER
},
567 {MERGER1_OUT
, LS_SRC_MERGER
},
568 {MERGER1_OUT
, LS_SRC_MERGER
}, {MERGER2_OUT
, LS_SRC_MERGER
},
569 {MERGER2_OUT
, LS_SRC_MERGER
},
570 {MERGER3_OUT
, LS_SRC_MERGER
}, {MERGER3_OUT
, LS_SRC_MERGER
}, {NO_OUT
,
574 static unsigned char lbus_play_opl3
[] = {
575 DIGITAL_MIXER_IN0
+ FM_MIXER
, 0xff
577 static unsigned char lbus_play_modem
[] = {
578 DIGITAL_MIXER_IN0
+ MODEM_MIXER
, 0xff
580 static unsigned char lbus_play_i2s
[] = {
581 INTER0_IN
+ I2S_INTDEC
, DIGITAL_MIXER_IN0
+ I2S_MIXER
, 0xff
583 static unsigned char lbus_play_out
[] = {
586 static unsigned char lbus_play_outhp
[] = {
589 static unsigned char lbus_play_noconv1
[] = {
590 DIGITAL_MIXER_IN0
, 0xff
592 static unsigned char lbus_play_stereo1
[] = {
593 INTER0_IN
, DIGITAL_MIXER_IN0
, 0xff
595 static unsigned char lbus_play_mono1
[] = {
596 INTERM0_IN
, DIGITAL_MIXER_IN0
, 0xff
598 static unsigned char lbus_play_noconv2
[] = {
599 DIGITAL_MIXER_IN1
, 0xff
601 static unsigned char lbus_play_stereo2
[] = {
602 INTER1_IN
, DIGITAL_MIXER_IN1
, 0xff
604 static unsigned char lbus_play_mono2
[] = {
605 INTERM1_IN
, DIGITAL_MIXER_IN1
, 0xff
607 static unsigned char lbus_play_noconv3
[] = {
608 DIGITAL_MIXER_IN2
, 0xff
610 static unsigned char lbus_play_stereo3
[] = {
611 INTER2_IN
, DIGITAL_MIXER_IN2
, 0xff
613 static unsigned char lbus_play_mono3
[] = {
614 INTERM2_IN
, DIGITAL_MIXER_IN2
, 0xff
616 static unsigned char lbus_rec_noconv1
[] = {
619 static unsigned char lbus_rec_stereo1
[] = {
620 DECIM0_IN
, LBUS2ARM_FIFO5
, 0xff
622 static unsigned char lbus_rec_mono1
[] = {
623 DECIMM3_IN
, LBUS2ARM_FIFO5
, 0xff
626 static unsigned char play_ids
[] = { 4, 1, 2, };
627 static unsigned char play_sources
[] = {
628 ARM2LBUS_FIFO4
, ARM2LBUS_FIFO1
, ARM2LBUS_FIFO2
,
630 static struct lbuspath lbus_play_paths
[] = {
632 .noconv
= lbus_play_noconv1
,
633 .stereo
= lbus_play_stereo1
,
634 .mono
= lbus_play_mono1
,
637 .noconv
= lbus_play_noconv2
,
638 .stereo
= lbus_play_stereo2
,
639 .mono
= lbus_play_mono2
,
642 .noconv
= lbus_play_noconv3
,
643 .stereo
= lbus_play_stereo3
,
644 .mono
= lbus_play_mono3
,
647 static struct lbuspath lbus_rec_path
= {
648 .noconv
= lbus_rec_noconv1
,
649 .stereo
= lbus_rec_stereo1
,
650 .mono
= lbus_rec_mono1
,
653 #define FIRMWARE_VERSIONS 1
654 static union firmware_version firmware_versions
[] = {
665 static u32
atoh(const unsigned char *in
, unsigned int len
)
668 unsigned int mult
= 1;
675 value
= hex_to_bin(c
);
684 static int senddata(struct cmdif
*cif
, const unsigned char *in
, u32 offset
)
689 const unsigned char *p
;
692 addr
= offset
+ atoh(&in
[3], 4);
693 if (SEND_SMEM(cif
, 0, addr
) != 0)
698 if (SEND_WMEM(cif
, 2,
699 ((data
& 0x0f0f0f0f) << 4) | ((data
& 0xf0f0f0f0)
708 static int loadfirmware(struct cmdif
*cif
, const unsigned char *img
,
711 const unsigned char *in
;
712 u32 laddr
, saddr
, t
, val
;
716 while (size
> 0 && err
== 0) {
722 err
= senddata(cif
, in
, laddr
+ saddr
);
724 case EXT_SEG_ADDR_REC
:
725 saddr
= atoh(&in
[9], 4) << 4;
727 case EXT_LIN_ADDR_REC
:
728 laddr
= atoh(&in
[9], 4) << 16;
730 case EXT_GOTO_CMD_REC
:
731 val
= atoh(&in
[9], 8);
732 if (SEND_GOTO(cif
, val
) != 0)
735 case EXT_END_OF_FILE
:
748 snd_printdd("load firmware return %d\n", err
);
753 alloclbuspath(struct cmdif
*cif
, unsigned char source
,
754 unsigned char *path
, unsigned char *mixer
, unsigned char *s
)
756 while (*path
!= 0xff) {
757 unsigned char sink
, type
;
759 sink
= *path
& (~SPLIT_PATH
);
760 if (sink
!= E2SINK_MAX
) {
761 snd_printdd("alloc path 0x%x->0x%x\n", source
, sink
);
762 SEND_PSEL(cif
, source
, sink
);
763 source
= lbusin2out
[sink
][0];
764 type
= lbusin2out
[sink
][1];
765 if (type
== LS_MIXER_IN
) {
767 *mixer
= sink
- DIGITAL_MIXER_IN0
;
769 if (type
== LS_SRC_DECIMATORM
||
770 type
== LS_SRC_DECIMATOR
||
771 type
== LS_SRC_INTERPOLATORM
||
772 type
== LS_SRC_INTERPOLATOR
) {
781 if (*path
++ & SPLIT_PATH
) {
782 unsigned char *npath
= path
;
784 while (*npath
!= 0xff)
786 alloclbuspath(cif
, source
+ 1, ++npath
, mixer
, s
);
792 freelbuspath(struct cmdif
*cif
, unsigned char source
, unsigned char *path
)
794 while (*path
!= 0xff) {
797 sink
= *path
& (~SPLIT_PATH
);
798 if (sink
!= E2SINK_MAX
) {
799 snd_printdd("free path 0x%x->0x%x\n", source
, sink
);
800 SEND_PCLR(cif
, source
, sink
);
801 source
= lbusin2out
[sink
][0];
803 if (*path
++ & SPLIT_PATH
) {
804 unsigned char *npath
= path
;
806 while (*npath
!= 0xff)
808 freelbuspath(cif
, source
+ 1, ++npath
);
813 static int writearm(struct cmdif
*cif
, u32 addr
, u32 data
, u32 mask
)
815 union cmdret rptr
= CMDRET_ZERO
;
816 unsigned int i
= MAX_WRITE_RETRY
;
819 SEND_RMEM(cif
, 0x02, addr
, &rptr
);
820 rptr
.retlongs
[0] &= (~mask
);
823 SEND_SMEM(cif
, 0x01, addr
);
824 SEND_WMEM(cif
, 0x02, (rptr
.retlongs
[0] | data
));
825 SEND_RMEM(cif
, 0x02, addr
, &rptr
);
826 if ((rptr
.retlongs
[0] & data
) == data
) {
830 rptr
.retlongs
[0] &= ~mask
;
832 snd_printdd("send arm 0x%x 0x%x 0x%x return %d\n", addr
, data
, mask
,
837 static int sendcmd(struct cmdif
*cif
, u32 flags
, u32 cmd
, u32 parm
,
842 unsigned int time
= 0;
843 unsigned long irqflags
;
844 struct riptideport
*hwport
;
845 struct cmdport
*cmdport
= NULL
;
847 if (snd_BUG_ON(!cif
))
850 hwport
= cif
->hwport
;
851 if (cif
->errcnt
> MAX_ERROR_COUNT
) {
854 "Riptide: Too many failed cmds, reinitializing\n");
855 if (riptide_reset(cif
, NULL
) == 0) {
860 snd_printk(KERN_ERR
"Riptide: Initialization failed.\n");
864 ret
->retlongs
[0] = 0;
865 ret
->retlongs
[1] = 0;
868 spin_lock_irqsave(&cif
->lock
, irqflags
);
869 while (i
++ < CMDIF_TIMEOUT
&& !IS_READY(cif
->hwport
))
871 if (i
> CMDIF_TIMEOUT
) {
877 for (j
= 0, time
= 0; time
< CMDIF_TIMEOUT
; j
++, time
+= 2) {
878 cmdport
= &(hwport
->port
[j
% 2]);
879 if (IS_DATF(cmdport
)) { /* free pending data */
880 READ_PORT_ULONG(cmdport
->data1
);
881 READ_PORT_ULONG(cmdport
->data2
);
883 if (IS_CMDE(cmdport
)) {
884 if (flags
& PARM
) /* put data */
885 WRITE_PORT_ULONG(cmdport
->data2
, parm
);
886 WRITE_PORT_ULONG(cmdport
->data1
, cmd
); /* write cmd */
887 if ((flags
& RESP
) && ret
) {
888 while (!IS_DATF(cmdport
) &&
889 time
< CMDIF_TIMEOUT
) {
893 if (time
< CMDIF_TIMEOUT
) { /* read response */
895 READ_PORT_ULONG(cmdport
->data1
);
897 READ_PORT_ULONG(cmdport
->data2
);
907 if (time
== CMDIF_TIMEOUT
) {
911 spin_unlock_irqrestore(&cif
->lock
, irqflags
);
913 cif
->cmdcnt
++; /* update command statistics */
914 cif
->cmdtime
+= time
;
915 if (time
> cif
->cmdtimemax
)
916 cif
->cmdtimemax
= time
;
917 if (time
< cif
->cmdtimemin
)
918 cif
->cmdtimemin
= time
;
919 if ((cif
->cmdcnt
) % 1000 == 0)
921 ("send cmd %d time: %d mintime: %d maxtime %d err: %d\n",
922 cif
->cmdcnt
, cif
->cmdtime
, cif
->cmdtimemin
,
923 cif
->cmdtimemax
, cif
->errcnt
);
928 spin_unlock_irqrestore(&cif
->lock
, irqflags
);
930 ("send cmd %d hw: 0x%x flag: 0x%x cmd: 0x%x parm: 0x%x ret: 0x%x 0x%x CMDE: %d DATF: %d failed %d\n",
931 cif
->cmdcnt
, (int)((void *)&(cmdport
->stat
) - (void *)hwport
),
932 flags
, cmd
, parm
, ret
? ret
->retlongs
[0] : 0,
933 ret
? ret
->retlongs
[1] : 0, IS_CMDE(cmdport
), IS_DATF(cmdport
),
939 setmixer(struct cmdif
*cif
, short num
, unsigned short rval
, unsigned short lval
)
941 union cmdret rptr
= CMDRET_ZERO
;
944 snd_printdd("sent mixer %d: 0x%d 0x%d\n", num
, rval
, lval
);
946 SEND_SDGV(cif
, num
, num
, rval
, lval
);
947 SEND_RDGV(cif
, num
, num
, &rptr
);
948 if (rptr
.retwords
[0] == lval
&& rptr
.retwords
[1] == rval
)
950 } while (i
++ < MAX_WRITE_RETRY
);
951 snd_printdd("sent mixer failed\n");
955 static int getpaths(struct cmdif
*cif
, unsigned char *o
)
957 unsigned char src
[E2SINK_MAX
];
958 unsigned char sink
[E2SINK_MAX
];
961 for (i
= 0; i
< E2SINK_MAX
; i
++) {
962 getsourcesink(cif
, i
, i
, &src
[i
], &sink
[i
]);
963 if (sink
[i
] < E2SINK_MAX
) {
972 getsourcesink(struct cmdif
*cif
, unsigned char source
, unsigned char sink
,
973 unsigned char *a
, unsigned char *b
)
975 union cmdret rptr
= CMDRET_ZERO
;
977 if (SEND_RSSV(cif
, source
, sink
, &rptr
) &&
978 SEND_RSSV(cif
, source
, sink
, &rptr
))
980 *a
= rptr
.retbytes
[0];
981 *b
= rptr
.retbytes
[1];
982 snd_printdd("getsourcesink 0x%x 0x%x\n", *a
, *b
);
987 getsamplerate(struct cmdif
*cif
, unsigned char *intdec
, unsigned int *rate
)
990 unsigned int p
[2] = { 0, 0 };
992 union cmdret rptr
= CMDRET_ZERO
;
995 for (i
= 0; i
< 2; i
++) {
997 if (SEND_RSRC(cif
, *s
, &rptr
) &&
998 SEND_RSRC(cif
, *s
, &rptr
))
1000 p
[i
] += rptr
.retwords
[1];
1001 p
[i
] *= rptr
.retwords
[2];
1002 p
[i
] += rptr
.retwords
[3];
1009 snd_printdd("rates differ %d %d\n", p
[0], p
[1]);
1010 *rate
= (unsigned int)p
[0];
1012 *rate
= (unsigned int)p
[1];
1013 snd_printdd("getsampleformat %d %d %d\n", intdec
[0], intdec
[1], *rate
);
1018 setsampleformat(struct cmdif
*cif
,
1019 unsigned char mixer
, unsigned char id
,
1020 unsigned char channels
, unsigned char format
)
1022 unsigned char w
, ch
, sig
, order
;
1025 ("setsampleformat mixer: %d id: %d channels: %d format: %d\n",
1026 mixer
, id
, channels
, format
);
1028 w
= snd_pcm_format_width(format
) == 8;
1029 sig
= snd_pcm_format_unsigned(format
) != 0;
1030 order
= snd_pcm_format_big_endian(format
) != 0;
1032 if (SEND_SETF(cif
, mixer
, w
, ch
, order
, sig
, id
) &&
1033 SEND_SETF(cif
, mixer
, w
, ch
, order
, sig
, id
)) {
1034 snd_printdd("setsampleformat failed\n");
1041 setsamplerate(struct cmdif
*cif
, unsigned char *intdec
, unsigned int rate
)
1044 union cmdret rptr
= CMDRET_ZERO
;
1047 snd_printdd("setsamplerate intdec: %d,%d rate: %d\n", intdec
[0],
1050 M
= ((rate
== 48000) ? 47999 : rate
) * 65536;
1053 for (i
= 0; i
< 2; i
++) {
1054 if (*intdec
!= 0xff) {
1056 SEND_SSRC(cif
, *intdec
, D
, M
, N
);
1057 SEND_RSRC(cif
, *intdec
, &rptr
);
1058 } while (rptr
.retwords
[1] != D
&&
1059 rptr
.retwords
[2] != M
&&
1060 rptr
.retwords
[3] != N
&&
1061 i
++ < MAX_WRITE_RETRY
);
1062 if (i
> MAX_WRITE_RETRY
) {
1063 snd_printdd("sent samplerate %d: %d failed\n",
1074 getmixer(struct cmdif
*cif
, short num
, unsigned short *rval
,
1075 unsigned short *lval
)
1077 union cmdret rptr
= CMDRET_ZERO
;
1079 if (SEND_RDGV(cif
, num
, num
, &rptr
) && SEND_RDGV(cif
, num
, num
, &rptr
))
1081 *rval
= rptr
.retwords
[0];
1082 *lval
= rptr
.retwords
[1];
1083 snd_printdd("got mixer %d: 0x%d 0x%d\n", num
, *rval
, *lval
);
1087 static void riptide_handleirq(unsigned long dev_id
)
1089 struct snd_riptide
*chip
= (void *)dev_id
;
1090 struct cmdif
*cif
= chip
->cif
;
1091 struct snd_pcm_substream
*substream
[PLAYBACK_SUBSTREAMS
+ 1];
1092 struct snd_pcm_runtime
*runtime
;
1093 struct pcmhw
*data
= NULL
;
1094 unsigned int pos
, period_bytes
;
1102 for (i
= 0; i
< PLAYBACK_SUBSTREAMS
; i
++)
1103 substream
[i
] = chip
->playback_substream
[i
];
1104 substream
[i
] = chip
->capture_substream
;
1105 for (i
= 0; i
< PLAYBACK_SUBSTREAMS
+ 1; i
++) {
1107 (runtime
= substream
[i
]->runtime
) &&
1108 (data
= runtime
->private_data
) && data
->state
!= ST_STOP
) {
1110 for (j
= 0; j
< data
->pages
; j
++) {
1111 c
= &data
->sgdbuf
[j
];
1112 flag
= le32_to_cpu(c
->dwStat_Ctl
);
1113 if (flag
& EOB_STATUS
)
1114 pos
+= le32_to_cpu(c
->dwSegLen
);
1115 if (flag
& EOC_STATUS
)
1116 pos
+= le32_to_cpu(c
->dwSegLen
);
1117 if ((flag
& EOS_STATUS
)
1118 && (data
->state
== ST_PLAY
)) {
1119 data
->state
= ST_STOP
;
1121 "Riptide: DMA stopped unexpectedly\n");
1125 ~(EOS_STATUS
| EOB_STATUS
|
1128 data
->pointer
+= pos
;
1129 pos
+= data
->oldpos
;
1130 if (data
->state
!= ST_STOP
) {
1132 frames_to_bytes(runtime
,
1133 runtime
->period_size
);
1135 ("interrupt 0x%x after 0x%lx of 0x%lx frames in period\n",
1136 READ_AUDIO_STATUS(cif
->hwport
),
1137 bytes_to_frames(runtime
, pos
),
1138 runtime
->period_size
);
1140 if (pos
>= period_bytes
) {
1142 while (pos
>= period_bytes
)
1143 pos
-= period_bytes
;
1147 snd_pcm_period_elapsed(substream
[i
]);
1154 static int riptide_suspend(struct pci_dev
*pci
, pm_message_t state
)
1156 struct snd_card
*card
= pci_get_drvdata(pci
);
1157 struct snd_riptide
*chip
= card
->private_data
;
1159 chip
->in_suspend
= 1;
1160 snd_power_change_state(card
, SNDRV_CTL_POWER_D3hot
);
1161 snd_pcm_suspend_all(chip
->pcm
);
1162 snd_ac97_suspend(chip
->ac97
);
1163 pci_disable_device(pci
);
1164 pci_save_state(pci
);
1165 pci_set_power_state(pci
, pci_choose_state(pci
, state
));
1169 static int riptide_resume(struct pci_dev
*pci
)
1171 struct snd_card
*card
= pci_get_drvdata(pci
);
1172 struct snd_riptide
*chip
= card
->private_data
;
1174 pci_set_power_state(pci
, PCI_D0
);
1175 pci_restore_state(pci
);
1176 if (pci_enable_device(pci
) < 0) {
1177 printk(KERN_ERR
"riptide: pci_enable_device failed, "
1178 "disabling device\n");
1179 snd_card_disconnect(card
);
1182 pci_set_master(pci
);
1183 snd_riptide_initialize(chip
);
1184 snd_ac97_resume(chip
->ac97
);
1185 snd_power_change_state(card
, SNDRV_CTL_POWER_D0
);
1186 chip
->in_suspend
= 0;
1191 static int try_to_load_firmware(struct cmdif
*cif
, struct snd_riptide
*chip
)
1193 union firmware_version firmware
= { .ret
= CMDRET_ZERO
};
1194 int i
, timeout
, err
;
1196 for (i
= 0; i
< 2; i
++) {
1197 WRITE_PORT_ULONG(cif
->hwport
->port
[i
].data1
, 0);
1198 WRITE_PORT_ULONG(cif
->hwport
->port
[i
].data2
, 0);
1200 SET_GRESET(cif
->hwport
);
1202 UNSET_GRESET(cif
->hwport
);
1205 for (timeout
= 100000; --timeout
; udelay(10)) {
1206 if (IS_READY(cif
->hwport
) && !IS_GERR(cif
->hwport
))
1211 "Riptide: device not ready, audio status: 0x%x "
1212 "ready: %d gerr: %d\n",
1213 READ_AUDIO_STATUS(cif
->hwport
),
1214 IS_READY(cif
->hwport
), IS_GERR(cif
->hwport
));
1218 ("Riptide: audio status: 0x%x ready: %d gerr: %d\n",
1219 READ_AUDIO_STATUS(cif
->hwport
),
1220 IS_READY(cif
->hwport
), IS_GERR(cif
->hwport
));
1223 SEND_GETV(cif
, &firmware
.ret
);
1224 snd_printdd("Firmware version: ASIC: %d CODEC %d AUXDSP %d PROG %d\n",
1225 firmware
.firmware
.ASIC
, firmware
.firmware
.CODEC
,
1226 firmware
.firmware
.AUXDSP
, firmware
.firmware
.PROG
);
1231 for (i
= 0; i
< FIRMWARE_VERSIONS
; i
++) {
1232 if (!memcmp(&firmware_versions
[i
], &firmware
, sizeof(firmware
)))
1237 snd_printdd("Writing Firmware\n");
1238 if (!chip
->fw_entry
) {
1239 err
= request_firmware(&chip
->fw_entry
, "riptide.hex",
1243 "Riptide: Firmware not available %d\n", err
);
1247 err
= loadfirmware(cif
, chip
->fw_entry
->data
, chip
->fw_entry
->size
);
1250 "Riptide: Could not load firmware %d\n", err
);
1254 chip
->firmware
= firmware
;
1259 static int riptide_reset(struct cmdif
*cif
, struct snd_riptide
*chip
)
1261 union cmdret rptr
= CMDRET_ZERO
;
1269 cif
->cmdtimemax
= 0;
1270 cif
->cmdtimemin
= 0xffffffff;
1274 tries
= RESET_TRIES
;
1276 err
= try_to_load_firmware(cif
, chip
);
1279 } while (!err
&& --tries
);
1281 SEND_SACR(cif
, 0, AC97_RESET
);
1282 SEND_RACR(cif
, AC97_RESET
, &rptr
);
1283 snd_printdd("AC97: 0x%x 0x%x\n", rptr
.retlongs
[0], rptr
.retlongs
[1]);
1291 writearm(cif
, 0x301F8, 1, 1);
1292 writearm(cif
, 0x301F4, 1, 1);
1294 SEND_LSEL(cif
, MODEM_CMD
, 0, 0, MODEM_INTDEC
, MODEM_MERGER
,
1295 MODEM_SPLITTER
, MODEM_MIXER
);
1296 setmixer(cif
, MODEM_MIXER
, 0x7fff, 0x7fff);
1297 alloclbuspath(cif
, ARM2LBUS_FIFO13
, lbus_play_modem
, NULL
, NULL
);
1299 SEND_LSEL(cif
, FM_CMD
, 0, 0, FM_INTDEC
, FM_MERGER
, FM_SPLITTER
,
1301 setmixer(cif
, FM_MIXER
, 0x7fff, 0x7fff);
1302 writearm(cif
, 0x30648 + FM_MIXER
* 4, 0x01, 0x00000005);
1303 writearm(cif
, 0x301A8, 0x02, 0x00000002);
1304 writearm(cif
, 0x30264, 0x08, 0xffffffff);
1305 alloclbuspath(cif
, OPL3_SAMPLE
, lbus_play_opl3
, NULL
, NULL
);
1307 SEND_SSRC(cif
, I2S_INTDEC
, 48000,
1308 ((u32
) I2S_RATE
* 65536) / 48000,
1309 ((u32
) I2S_RATE
* 65536) % 48000);
1310 SEND_LSEL(cif
, I2S_CMD0
, 0, 0, I2S_INTDEC
, I2S_MERGER
, I2S_SPLITTER
,
1313 alloclbuspath(cif
, ARM2LBUS_FIFO0
, lbus_play_i2s
, NULL
, NULL
);
1314 alloclbuspath(cif
, DIGITAL_MIXER_OUT0
, lbus_play_out
, NULL
, NULL
);
1315 alloclbuspath(cif
, DIGITAL_MIXER_OUT0
, lbus_play_outhp
, NULL
, NULL
);
1317 SET_AIACK(cif
->hwport
);
1318 SET_AIE(cif
->hwport
);
1319 SET_AIACK(cif
->hwport
);
1325 static struct snd_pcm_hardware snd_riptide_playback
= {
1326 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1327 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1328 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_MMAP_VALID
),
1330 SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S8
1331 | SNDRV_PCM_FMTBIT_U16_LE
,
1332 .rates
= SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_8000_48000
,
1337 .buffer_bytes_max
= (64 * 1024),
1338 .period_bytes_min
= PAGE_SIZE
>> 1,
1339 .period_bytes_max
= PAGE_SIZE
<< 8,
1344 static struct snd_pcm_hardware snd_riptide_capture
= {
1345 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
1346 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1347 SNDRV_PCM_INFO_PAUSE
| SNDRV_PCM_INFO_MMAP_VALID
),
1349 SNDRV_PCM_FMTBIT_U8
| SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S8
1350 | SNDRV_PCM_FMTBIT_U16_LE
,
1351 .rates
= SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_8000_48000
,
1356 .buffer_bytes_max
= (64 * 1024),
1357 .period_bytes_min
= PAGE_SIZE
>> 1,
1358 .period_bytes_max
= PAGE_SIZE
<< 3,
1364 static snd_pcm_uframes_t
snd_riptide_pointer(struct snd_pcm_substream
1367 struct snd_riptide
*chip
= snd_pcm_substream_chip(substream
);
1368 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1369 struct pcmhw
*data
= get_pcmhwdev(substream
);
1370 struct cmdif
*cif
= chip
->cif
;
1371 union cmdret rptr
= CMDRET_ZERO
;
1372 snd_pcm_uframes_t ret
;
1374 SEND_GPOS(cif
, 0, data
->id
, &rptr
);
1375 if (data
->size
&& runtime
->period_size
) {
1377 ("pointer stream %d position 0x%x(0x%x in buffer) bytes 0x%lx(0x%lx in period) frames\n",
1378 data
->id
, rptr
.retlongs
[1], rptr
.retlongs
[1] % data
->size
,
1379 bytes_to_frames(runtime
, rptr
.retlongs
[1]),
1380 bytes_to_frames(runtime
,
1381 rptr
.retlongs
[1]) % runtime
->period_size
);
1382 if (rptr
.retlongs
[1] > data
->pointer
)
1384 bytes_to_frames(runtime
,
1385 rptr
.retlongs
[1] % data
->size
);
1388 bytes_to_frames(runtime
,
1389 data
->pointer
% data
->size
);
1391 snd_printdd("stream not started or strange parms (%d %ld)\n",
1392 data
->size
, runtime
->period_size
);
1393 ret
= bytes_to_frames(runtime
, 0);
1398 static int snd_riptide_trigger(struct snd_pcm_substream
*substream
, int cmd
)
1401 struct snd_riptide
*chip
= snd_pcm_substream_chip(substream
);
1402 struct pcmhw
*data
= get_pcmhwdev(substream
);
1403 struct cmdif
*cif
= chip
->cif
;
1404 union cmdret rptr
= CMDRET_ZERO
;
1406 spin_lock(&chip
->lock
);
1408 case SNDRV_PCM_TRIGGER_START
:
1409 case SNDRV_PCM_TRIGGER_RESUME
:
1410 if (!(data
->state
& ST_PLAY
)) {
1411 SEND_SSTR(cif
, data
->id
, data
->sgdlist
.addr
);
1412 SET_AIE(cif
->hwport
);
1413 data
->state
= ST_PLAY
;
1414 if (data
->mixer
!= 0xff)
1415 setmixer(cif
, data
->mixer
, 0x7fff, 0x7fff);
1416 chip
->openstreams
++;
1421 case SNDRV_PCM_TRIGGER_STOP
:
1422 case SNDRV_PCM_TRIGGER_SUSPEND
:
1423 if (data
->mixer
!= 0xff)
1424 setmixer(cif
, data
->mixer
, 0, 0);
1425 setmixer(cif
, data
->mixer
, 0, 0);
1426 SEND_KSTR(cif
, data
->id
);
1427 data
->state
= ST_STOP
;
1428 chip
->openstreams
--;
1431 i
= rptr
.retlongs
[1];
1432 SEND_GPOS(cif
, 0, data
->id
, &rptr
);
1434 } while (i
!= rptr
.retlongs
[1] && j
++ < MAX_WRITE_RETRY
);
1435 if (j
> MAX_WRITE_RETRY
)
1436 snd_printk(KERN_ERR
"Riptide: Could not stop stream!");
1438 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1439 if (!(data
->state
& ST_PAUSE
)) {
1440 SEND_PSTR(cif
, data
->id
);
1441 data
->state
|= ST_PAUSE
;
1442 chip
->openstreams
--;
1445 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1446 if (data
->state
& ST_PAUSE
) {
1447 SEND_SSTR(cif
, data
->id
, data
->sgdlist
.addr
);
1448 data
->state
&= ~ST_PAUSE
;
1449 chip
->openstreams
++;
1453 spin_unlock(&chip
->lock
);
1456 spin_unlock(&chip
->lock
);
1460 static int snd_riptide_prepare(struct snd_pcm_substream
*substream
)
1462 struct snd_riptide
*chip
= snd_pcm_substream_chip(substream
);
1463 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1464 struct pcmhw
*data
= get_pcmhwdev(substream
);
1465 struct cmdif
*cif
= chip
->cif
;
1466 unsigned char *lbuspath
= NULL
;
1467 unsigned int rate
, channels
;
1469 snd_pcm_format_t format
;
1471 if (snd_BUG_ON(!cif
|| !data
))
1474 snd_printdd("prepare id %d ch: %d f:0x%x r:%d\n", data
->id
,
1475 runtime
->channels
, runtime
->format
, runtime
->rate
);
1477 spin_lock_irq(&chip
->lock
);
1478 channels
= runtime
->channels
;
1479 format
= runtime
->format
;
1480 rate
= runtime
->rate
;
1483 if (rate
== 48000 && format
== SNDRV_PCM_FORMAT_S16_LE
)
1484 lbuspath
= data
->paths
.noconv
;
1486 lbuspath
= data
->paths
.mono
;
1489 if (rate
== 48000 && format
== SNDRV_PCM_FORMAT_S16_LE
)
1490 lbuspath
= data
->paths
.noconv
;
1492 lbuspath
= data
->paths
.stereo
;
1495 snd_printdd("use sgdlist at 0x%p\n",
1496 data
->sgdlist
.area
);
1497 if (data
->sgdlist
.area
) {
1498 unsigned int i
, j
, size
, pages
, f
, pt
, period
;
1499 struct sgd
*c
, *p
= NULL
;
1501 size
= frames_to_bytes(runtime
, runtime
->buffer_size
);
1502 period
= frames_to_bytes(runtime
, runtime
->period_size
);
1504 while ((size
+ (f
>> 1) - 1) <= (f
<< 7) && (f
<< 1) > period
)
1506 pages
= (size
+ f
- 1) / f
;
1508 data
->pages
= pages
;
1510 ("create sgd size: 0x%x pages %d of size 0x%x for period 0x%x\n",
1511 size
, pages
, f
, period
);
1514 for (i
= 0; i
< pages
; i
++) {
1515 unsigned int ofs
, addr
;
1516 c
= &data
->sgdbuf
[i
];
1518 p
->dwNextLink
= cpu_to_le32(data
->sgdlist
.addr
+
1522 c
->dwNextLink
= cpu_to_le32(data
->sgdlist
.addr
);
1523 ofs
= j
<< PAGE_SHIFT
;
1524 addr
= snd_pcm_sgbuf_get_addr(substream
, ofs
) + pt
;
1525 c
->dwSegPtrPhys
= cpu_to_le32(addr
);
1526 pt
= (pt
+ f
) % PAGE_SIZE
;
1529 c
->dwSegLen
= cpu_to_le32(f
);
1531 cpu_to_le32(IEOB_ENABLE
| IEOS_ENABLE
|
1536 data
->sgdbuf
[i
].dwSegLen
= cpu_to_le32(size
);
1538 if (lbuspath
&& lbuspath
!= data
->lbuspath
) {
1540 freelbuspath(cif
, data
->source
, data
->lbuspath
);
1541 alloclbuspath(cif
, data
->source
, lbuspath
,
1542 &data
->mixer
, data
->intdec
);
1543 data
->lbuspath
= lbuspath
;
1546 if (data
->rate
!= rate
|| data
->format
!= format
||
1547 data
->channels
!= channels
) {
1549 data
->format
= format
;
1550 data
->channels
= channels
;
1552 (cif
, data
->mixer
, data
->id
, channels
, format
)
1553 || setsamplerate(cif
, data
->intdec
, rate
))
1556 spin_unlock_irq(&chip
->lock
);
1561 snd_riptide_hw_params(struct snd_pcm_substream
*substream
,
1562 struct snd_pcm_hw_params
*hw_params
)
1564 struct snd_riptide
*chip
= snd_pcm_substream_chip(substream
);
1565 struct pcmhw
*data
= get_pcmhwdev(substream
);
1566 struct snd_dma_buffer
*sgdlist
= &data
->sgdlist
;
1569 snd_printdd("hw params id %d (sgdlist: 0x%p 0x%lx %d)\n", data
->id
,
1570 sgdlist
->area
, (unsigned long)sgdlist
->addr
,
1571 (int)sgdlist
->bytes
);
1573 snd_dma_free_pages(sgdlist
);
1574 if ((err
= snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
,
1575 snd_dma_pci_data(chip
->pci
),
1576 sizeof(struct sgd
) * (DESC_MAX_MASK
+ 1),
1578 snd_printk(KERN_ERR
"Riptide: failed to alloc %d dma bytes\n",
1579 (int)sizeof(struct sgd
) * (DESC_MAX_MASK
+ 1));
1582 data
->sgdbuf
= (struct sgd
*)sgdlist
->area
;
1583 return snd_pcm_lib_malloc_pages(substream
,
1584 params_buffer_bytes(hw_params
));
1587 static int snd_riptide_hw_free(struct snd_pcm_substream
*substream
)
1589 struct snd_riptide
*chip
= snd_pcm_substream_chip(substream
);
1590 struct pcmhw
*data
= get_pcmhwdev(substream
);
1591 struct cmdif
*cif
= chip
->cif
;
1595 freelbuspath(cif
, data
->source
, data
->lbuspath
);
1596 data
->lbuspath
= NULL
;
1597 data
->source
= 0xff;
1598 data
->intdec
[0] = 0xff;
1599 data
->intdec
[1] = 0xff;
1601 if (data
->sgdlist
.area
) {
1602 snd_dma_free_pages(&data
->sgdlist
);
1603 data
->sgdlist
.area
= NULL
;
1606 return snd_pcm_lib_free_pages(substream
);
1609 static int snd_riptide_playback_open(struct snd_pcm_substream
*substream
)
1611 struct snd_riptide
*chip
= snd_pcm_substream_chip(substream
);
1612 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1614 int sub_num
= substream
->number
;
1616 chip
->playback_substream
[sub_num
] = substream
;
1617 runtime
->hw
= snd_riptide_playback
;
1619 data
= kzalloc(sizeof(struct pcmhw
), GFP_KERNEL
);
1622 data
->paths
= lbus_play_paths
[sub_num
];
1623 data
->id
= play_ids
[sub_num
];
1624 data
->source
= play_sources
[sub_num
];
1625 data
->intdec
[0] = 0xff;
1626 data
->intdec
[1] = 0xff;
1627 data
->state
= ST_STOP
;
1628 runtime
->private_data
= data
;
1629 return snd_pcm_hw_constraint_integer(runtime
,
1630 SNDRV_PCM_HW_PARAM_PERIODS
);
1633 static int snd_riptide_capture_open(struct snd_pcm_substream
*substream
)
1635 struct snd_riptide
*chip
= snd_pcm_substream_chip(substream
);
1636 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1639 chip
->capture_substream
= substream
;
1640 runtime
->hw
= snd_riptide_capture
;
1642 data
= kzalloc(sizeof(struct pcmhw
), GFP_KERNEL
);
1645 data
->paths
= lbus_rec_path
;
1647 data
->source
= ACLNK2PADC
;
1648 data
->intdec
[0] = 0xff;
1649 data
->intdec
[1] = 0xff;
1650 data
->state
= ST_STOP
;
1651 runtime
->private_data
= data
;
1652 return snd_pcm_hw_constraint_integer(runtime
,
1653 SNDRV_PCM_HW_PARAM_PERIODS
);
1656 static int snd_riptide_playback_close(struct snd_pcm_substream
*substream
)
1658 struct snd_riptide
*chip
= snd_pcm_substream_chip(substream
);
1659 struct pcmhw
*data
= get_pcmhwdev(substream
);
1660 int sub_num
= substream
->number
;
1662 substream
->runtime
->private_data
= NULL
;
1663 chip
->playback_substream
[sub_num
] = NULL
;
1668 static int snd_riptide_capture_close(struct snd_pcm_substream
*substream
)
1670 struct snd_riptide
*chip
= snd_pcm_substream_chip(substream
);
1671 struct pcmhw
*data
= get_pcmhwdev(substream
);
1673 substream
->runtime
->private_data
= NULL
;
1674 chip
->capture_substream
= NULL
;
1679 static struct snd_pcm_ops snd_riptide_playback_ops
= {
1680 .open
= snd_riptide_playback_open
,
1681 .close
= snd_riptide_playback_close
,
1682 .ioctl
= snd_pcm_lib_ioctl
,
1683 .hw_params
= snd_riptide_hw_params
,
1684 .hw_free
= snd_riptide_hw_free
,
1685 .prepare
= snd_riptide_prepare
,
1686 .page
= snd_pcm_sgbuf_ops_page
,
1687 .trigger
= snd_riptide_trigger
,
1688 .pointer
= snd_riptide_pointer
,
1690 static struct snd_pcm_ops snd_riptide_capture_ops
= {
1691 .open
= snd_riptide_capture_open
,
1692 .close
= snd_riptide_capture_close
,
1693 .ioctl
= snd_pcm_lib_ioctl
,
1694 .hw_params
= snd_riptide_hw_params
,
1695 .hw_free
= snd_riptide_hw_free
,
1696 .prepare
= snd_riptide_prepare
,
1697 .page
= snd_pcm_sgbuf_ops_page
,
1698 .trigger
= snd_riptide_trigger
,
1699 .pointer
= snd_riptide_pointer
,
1702 static int __devinit
1703 snd_riptide_pcm(struct snd_riptide
*chip
, int device
, struct snd_pcm
**rpcm
)
1705 struct snd_pcm
*pcm
;
1711 snd_pcm_new(chip
->card
, "RIPTIDE", device
, PLAYBACK_SUBSTREAMS
, 1,
1714 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
1715 &snd_riptide_playback_ops
);
1716 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
1717 &snd_riptide_capture_ops
);
1718 pcm
->private_data
= chip
;
1719 pcm
->info_flags
= 0;
1720 strcpy(pcm
->name
, "RIPTIDE");
1722 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV_SG
,
1723 snd_dma_pci_data(chip
->pci
),
1724 64 * 1024, 128 * 1024);
1731 snd_riptide_interrupt(int irq
, void *dev_id
)
1733 struct snd_riptide
*chip
= dev_id
;
1734 struct cmdif
*cif
= chip
->cif
;
1737 chip
->received_irqs
++;
1738 if (IS_EOBIRQ(cif
->hwport
) || IS_EOSIRQ(cif
->hwport
) ||
1739 IS_EOCIRQ(cif
->hwport
)) {
1740 chip
->handled_irqs
++;
1741 tasklet_schedule(&chip
->riptide_tq
);
1743 if (chip
->rmidi
&& IS_MPUIRQ(cif
->hwport
)) {
1744 chip
->handled_irqs
++;
1745 snd_mpu401_uart_interrupt(irq
,
1746 chip
->rmidi
->private_data
);
1748 SET_AIACK(cif
->hwport
);
1754 snd_riptide_codec_write(struct snd_ac97
*ac97
, unsigned short reg
,
1757 struct snd_riptide
*chip
= ac97
->private_data
;
1758 struct cmdif
*cif
= chip
->cif
;
1759 union cmdret rptr
= CMDRET_ZERO
;
1762 if (snd_BUG_ON(!cif
))
1765 snd_printdd("Write AC97 reg 0x%x 0x%x\n", reg
, val
);
1767 SEND_SACR(cif
, val
, reg
);
1768 SEND_RACR(cif
, reg
, &rptr
);
1769 } while (rptr
.retwords
[1] != val
&& i
++ < MAX_WRITE_RETRY
);
1770 if (i
> MAX_WRITE_RETRY
)
1771 snd_printdd("Write AC97 reg failed\n");
1774 static unsigned short snd_riptide_codec_read(struct snd_ac97
*ac97
,
1777 struct snd_riptide
*chip
= ac97
->private_data
;
1778 struct cmdif
*cif
= chip
->cif
;
1779 union cmdret rptr
= CMDRET_ZERO
;
1781 if (snd_BUG_ON(!cif
))
1784 if (SEND_RACR(cif
, reg
, &rptr
) != 0)
1785 SEND_RACR(cif
, reg
, &rptr
);
1786 snd_printdd("Read AC97 reg 0x%x got 0x%x\n", reg
, rptr
.retwords
[1]);
1787 return rptr
.retwords
[1];
1790 static int snd_riptide_initialize(struct snd_riptide
*chip
)
1793 unsigned int device_id
;
1796 if (snd_BUG_ON(!chip
))
1801 if ((cif
= kzalloc(sizeof(struct cmdif
), GFP_KERNEL
)) == NULL
)
1803 cif
->hwport
= (struct riptideport
*)chip
->port
;
1804 spin_lock_init(&cif
->lock
);
1808 if ((err
= riptide_reset(cif
, chip
)) != 0)
1810 device_id
= chip
->device_id
;
1811 switch (device_id
) {
1815 snd_printdd("Modem enable?\n");
1819 snd_printdd("Enabling MPU IRQs\n");
1821 SET_EMPUIRQ(cif
->hwport
);
1825 static int snd_riptide_free(struct snd_riptide
*chip
)
1832 if ((cif
= chip
->cif
)) {
1833 SET_GRESET(cif
->hwport
);
1835 UNSET_GRESET(cif
->hwport
);
1839 free_irq(chip
->irq
, chip
);
1841 release_firmware(chip
->fw_entry
);
1842 release_and_free_resource(chip
->res_port
);
1847 static int snd_riptide_dev_free(struct snd_device
*device
)
1849 struct snd_riptide
*chip
= device
->device_data
;
1851 return snd_riptide_free(chip
);
1854 static int __devinit
1855 snd_riptide_create(struct snd_card
*card
, struct pci_dev
*pci
,
1856 struct snd_riptide
**rchip
)
1858 struct snd_riptide
*chip
;
1859 struct riptideport
*hwport
;
1861 static struct snd_device_ops ops
= {
1862 .dev_free
= snd_riptide_dev_free
,
1866 if ((err
= pci_enable_device(pci
)) < 0)
1868 if (!(chip
= kzalloc(sizeof(struct snd_riptide
), GFP_KERNEL
)))
1871 spin_lock_init(&chip
->lock
);
1875 chip
->openstreams
= 0;
1876 chip
->port
= pci_resource_start(pci
, 0);
1877 chip
->received_irqs
= 0;
1878 chip
->handled_irqs
= 0;
1880 tasklet_init(&chip
->riptide_tq
, riptide_handleirq
, (unsigned long)chip
);
1882 if ((chip
->res_port
=
1883 request_region(chip
->port
, 64, "RIPTIDE")) == NULL
) {
1885 "Riptide: unable to grab region 0x%lx-0x%lx\n",
1886 chip
->port
, chip
->port
+ 64 - 1);
1887 snd_riptide_free(chip
);
1890 hwport
= (struct riptideport
*)chip
->port
;
1893 if (request_irq(pci
->irq
, snd_riptide_interrupt
, IRQF_SHARED
,
1894 KBUILD_MODNAME
, chip
)) {
1895 snd_printk(KERN_ERR
"Riptide: unable to grab IRQ %d\n",
1897 snd_riptide_free(chip
);
1900 chip
->irq
= pci
->irq
;
1901 chip
->device_id
= pci
->device
;
1902 pci_set_master(pci
);
1903 if ((err
= snd_riptide_initialize(chip
)) < 0) {
1904 snd_riptide_free(chip
);
1908 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
)) < 0) {
1909 snd_riptide_free(chip
);
1913 snd_card_set_dev(card
, &pci
->dev
);
1920 snd_riptide_proc_read(struct snd_info_entry
*entry
,
1921 struct snd_info_buffer
*buffer
)
1923 struct snd_riptide
*chip
= entry
->private_data
;
1926 struct cmdif
*cif
= NULL
;
1927 unsigned char p
[256];
1928 unsigned short rval
= 0, lval
= 0;
1934 snd_iprintf(buffer
, "%s\n\n", chip
->card
->longname
);
1935 snd_iprintf(buffer
, "Device ID: 0x%x\nReceived IRQs: (%ld)%ld\nPorts:",
1936 chip
->device_id
, chip
->handled_irqs
, chip
->received_irqs
);
1937 for (i
= 0; i
< 64; i
+= 4)
1938 snd_iprintf(buffer
, "%c%02x: %08x",
1939 (i
% 16) ? ' ' : '\n', i
, inl(chip
->port
+ i
));
1940 if ((cif
= chip
->cif
)) {
1942 "\nVersion: ASIC: %d CODEC: %d AUXDSP: %d PROG: %d",
1943 chip
->firmware
.firmware
.ASIC
,
1944 chip
->firmware
.firmware
.CODEC
,
1945 chip
->firmware
.firmware
.AUXDSP
,
1946 chip
->firmware
.firmware
.PROG
);
1947 snd_iprintf(buffer
, "\nDigital mixer:");
1948 for (i
= 0; i
< 12; i
++) {
1949 getmixer(cif
, i
, &rval
, &lval
);
1950 snd_iprintf(buffer
, "\n %d: %d %d", i
, rval
, lval
);
1953 "\nARM Commands num: %d failed: %d time: %d max: %d min: %d",
1954 cif
->cmdcnt
, cif
->errcnt
,
1955 cif
->cmdtime
, cif
->cmdtimemax
, cif
->cmdtimemin
);
1957 snd_iprintf(buffer
, "\nOpen streams %d:\n", chip
->openstreams
);
1958 for (i
= 0; i
< PLAYBACK_SUBSTREAMS
; i
++) {
1959 if (chip
->playback_substream
[i
]
1960 && chip
->playback_substream
[i
]->runtime
1962 chip
->playback_substream
[i
]->runtime
->private_data
)) {
1964 "stream: %d mixer: %d source: %d (%d,%d)\n",
1965 data
->id
, data
->mixer
, data
->source
,
1966 data
->intdec
[0], data
->intdec
[1]);
1967 if (!(getsamplerate(cif
, data
->intdec
, &rate
)))
1968 snd_iprintf(buffer
, "rate: %d\n", rate
);
1971 if (chip
->capture_substream
1972 && chip
->capture_substream
->runtime
1973 && (data
= chip
->capture_substream
->runtime
->private_data
)) {
1975 "stream: %d mixer: %d source: %d (%d,%d)\n",
1976 data
->id
, data
->mixer
,
1977 data
->source
, data
->intdec
[0], data
->intdec
[1]);
1978 if (!(getsamplerate(cif
, data
->intdec
, &rate
)))
1979 snd_iprintf(buffer
, "rate: %d\n", rate
);
1981 snd_iprintf(buffer
, "Paths:\n");
1982 i
= getpaths(cif
, p
);
1985 snd_iprintf(buffer
, "%x->%x ", p
[i
], p
[i
+ 1]);
1987 snd_iprintf(buffer
, "\n");
1990 static void __devinit
snd_riptide_proc_init(struct snd_riptide
*chip
)
1992 struct snd_info_entry
*entry
;
1994 if (!snd_card_proc_new(chip
->card
, "riptide", &entry
))
1995 snd_info_set_text_ops(entry
, chip
, snd_riptide_proc_read
);
1998 static int __devinit
snd_riptide_mixer(struct snd_riptide
*chip
)
2000 struct snd_ac97_bus
*pbus
;
2001 struct snd_ac97_template ac97
;
2003 static struct snd_ac97_bus_ops ops
= {
2004 .write
= snd_riptide_codec_write
,
2005 .read
= snd_riptide_codec_read
,
2008 memset(&ac97
, 0, sizeof(ac97
));
2009 ac97
.private_data
= chip
;
2010 ac97
.scaps
= AC97_SCAP_SKIP_MODEM
;
2012 if ((err
= snd_ac97_bus(chip
->card
, 0, &ops
, chip
, &pbus
)) < 0)
2015 chip
->ac97_bus
= pbus
;
2016 ac97
.pci
= chip
->pci
;
2017 if ((err
= snd_ac97_mixer(pbus
, &ac97
, &chip
->ac97
)) < 0)
2022 #ifdef SUPPORT_JOYSTICK
2024 static int __devinit
2025 snd_riptide_joystick_probe(struct pci_dev
*pci
, const struct pci_device_id
*id
)
2028 struct gameport
*gameport
;
2030 if (dev
>= SNDRV_CARDS
)
2037 if (!joystick_port
[dev
++])
2040 gameport
= gameport_allocate_port();
2043 if (!request_region(joystick_port
[dev
], 8, "Riptide gameport")) {
2044 snd_printk(KERN_WARNING
2045 "Riptide: cannot grab gameport 0x%x\n",
2046 joystick_port
[dev
]);
2047 gameport_free_port(gameport
);
2051 gameport
->io
= joystick_port
[dev
];
2052 gameport_register_port(gameport
);
2053 pci_set_drvdata(pci
, gameport
);
2057 static void __devexit
snd_riptide_joystick_remove(struct pci_dev
*pci
)
2059 struct gameport
*gameport
= pci_get_drvdata(pci
);
2061 release_region(gameport
->io
, 8);
2062 gameport_unregister_port(gameport
);
2063 pci_set_drvdata(pci
, NULL
);
2068 static int __devinit
2069 snd_card_riptide_probe(struct pci_dev
*pci
, const struct pci_device_id
*pci_id
)
2072 struct snd_card
*card
;
2073 struct snd_riptide
*chip
;
2077 if (dev
>= SNDRV_CARDS
)
2084 err
= snd_card_create(index
[dev
], id
[dev
], THIS_MODULE
, 0, &card
);
2087 err
= snd_riptide_create(card
, pci
, &chip
);
2090 card
->private_data
= chip
;
2091 err
= snd_riptide_pcm(chip
, 0, NULL
);
2094 err
= snd_riptide_mixer(chip
);
2098 val
= LEGACY_ENABLE_ALL
;
2100 val
|= LEGACY_ENABLE_FM
;
2101 #ifdef SUPPORT_JOYSTICK
2102 if (joystick_port
[dev
])
2103 val
|= LEGACY_ENABLE_GAMEPORT
;
2106 val
|= LEGACY_ENABLE_MPU_INT
| LEGACY_ENABLE_MPU
;
2107 val
|= (chip
->irq
<< 4) & 0xf0;
2108 pci_write_config_word(chip
->pci
, PCI_EXT_Legacy_Mask
, val
);
2109 if (mpu_port
[dev
]) {
2110 val
= mpu_port
[dev
];
2111 pci_write_config_word(chip
->pci
, PCI_EXT_MPU_Base
, val
);
2112 err
= snd_mpu401_uart_new(card
, 0, MPU401_HW_RIPTIDE
,
2113 val
, MPU401_INFO_IRQ_HOOK
, -1,
2116 snd_printk(KERN_WARNING
2117 "Riptide: Can't Allocate MPU at 0x%x\n",
2120 chip
->mpuaddr
= val
;
2122 if (opl3_port
[dev
]) {
2123 val
= opl3_port
[dev
];
2124 pci_write_config_word(chip
->pci
, PCI_EXT_FM_Base
, val
);
2125 err
= snd_opl3_create(card
, val
, val
+ 2,
2126 OPL3_HW_RIPTIDE
, 0, &chip
->opl3
);
2128 snd_printk(KERN_WARNING
2129 "Riptide: Can't Allocate OPL3 at 0x%x\n",
2132 chip
->opladdr
= val
;
2133 err
= snd_opl3_hwdep_new(chip
->opl3
, 0, 1, NULL
);
2135 snd_printk(KERN_WARNING
2136 "Riptide: Can't Allocate OPL3-HWDEP\n");
2139 #ifdef SUPPORT_JOYSTICK
2140 if (joystick_port
[dev
]) {
2141 val
= joystick_port
[dev
];
2142 pci_write_config_word(chip
->pci
, PCI_EXT_Game_Base
, val
);
2143 chip
->gameaddr
= val
;
2147 strcpy(card
->driver
, "RIPTIDE");
2148 strcpy(card
->shortname
, "Riptide");
2149 #ifdef SUPPORT_JOYSTICK
2150 snprintf(card
->longname
, sizeof(card
->longname
),
2151 "%s at 0x%lx, irq %i mpu 0x%x opl3 0x%x gameport 0x%x",
2152 card
->shortname
, chip
->port
, chip
->irq
, chip
->mpuaddr
,
2153 chip
->opladdr
, chip
->gameaddr
);
2155 snprintf(card
->longname
, sizeof(card
->longname
),
2156 "%s at 0x%lx, irq %i mpu 0x%x opl3 0x%x",
2157 card
->shortname
, chip
->port
, chip
->irq
, chip
->mpuaddr
,
2160 snd_riptide_proc_init(chip
);
2161 err
= snd_card_register(card
);
2164 pci_set_drvdata(pci
, card
);
2169 snd_card_free(card
);
2173 static void __devexit
snd_card_riptide_remove(struct pci_dev
*pci
)
2175 snd_card_free(pci_get_drvdata(pci
));
2176 pci_set_drvdata(pci
, NULL
);
2179 static struct pci_driver driver
= {
2180 .name
= KBUILD_MODNAME
,
2181 .id_table
= snd_riptide_ids
,
2182 .probe
= snd_card_riptide_probe
,
2183 .remove
= __devexit_p(snd_card_riptide_remove
),
2185 .suspend
= riptide_suspend
,
2186 .resume
= riptide_resume
,
2190 #ifdef SUPPORT_JOYSTICK
2191 static struct pci_driver joystick_driver
= {
2192 .name
= KBUILD_MODNAME
"-joystick",
2193 .id_table
= snd_riptide_joystick_ids
,
2194 .probe
= snd_riptide_joystick_probe
,
2195 .remove
= __devexit_p(snd_riptide_joystick_remove
),
2199 static int __init
alsa_card_riptide_init(void)
2202 err
= pci_register_driver(&driver
);
2205 #if defined(SUPPORT_JOYSTICK)
2206 err
= pci_register_driver(&joystick_driver
);
2207 /* On failure unregister formerly registered audio driver */
2209 pci_unregister_driver(&driver
);
2214 static void __exit
alsa_card_riptide_exit(void)
2216 pci_unregister_driver(&driver
);
2217 #if defined(SUPPORT_JOYSTICK)
2218 pci_unregister_driver(&joystick_driver
);
2222 module_init(alsa_card_riptide_init
);
2223 module_exit(alsa_card_riptide_exit
);