1109a9638SPeter Gruber /* 2109a9638SPeter Gruber * Driver for the Conexant Riptide Soundchip 3109a9638SPeter Gruber * 4109a9638SPeter Gruber * Copyright (c) 2004 Peter Gruber <nokos@gmx.net> 5109a9638SPeter Gruber * 6109a9638SPeter Gruber * This program is free software; you can redistribute it and/or modify 7109a9638SPeter Gruber * it under the terms of the GNU General Public License as published by 8109a9638SPeter Gruber * the Free Software Foundation; either version 2 of the License, or 9109a9638SPeter Gruber * (at your option) any later version. 10109a9638SPeter Gruber * 11109a9638SPeter Gruber * This program is distributed in the hope that it will be useful, 12109a9638SPeter Gruber * but WITHOUT ANY WARRANTY; without even the implied warranty of 13109a9638SPeter Gruber * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14109a9638SPeter Gruber * GNU General Public License for more details. 15109a9638SPeter Gruber * 16109a9638SPeter Gruber * You should have received a copy of the GNU General Public License 17109a9638SPeter Gruber * along with this program; if not, write to the Free Software 18109a9638SPeter Gruber * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19109a9638SPeter Gruber * 20109a9638SPeter Gruber */ 21109a9638SPeter Gruber /* 22109a9638SPeter Gruber History: 23109a9638SPeter Gruber - 02/15/2004 first release 24109a9638SPeter Gruber 25109a9638SPeter Gruber This Driver is based on the OSS Driver version from Linuxant (riptide-0.6lnxtbeta03111100) 26109a9638SPeter Gruber credits from the original files: 27109a9638SPeter Gruber 28109a9638SPeter Gruber MODULE NAME: cnxt_rt.h 29109a9638SPeter Gruber AUTHOR: K. Lazarev (Transcribed by KNL) 30109a9638SPeter Gruber HISTORY: Major Revision Date By 31109a9638SPeter Gruber ----------------------------- -------- ----- 32109a9638SPeter Gruber Created 02/1/2000 KNL 33109a9638SPeter Gruber 34109a9638SPeter Gruber MODULE NAME: int_mdl.c 35109a9638SPeter Gruber AUTHOR: Konstantin Lazarev (Transcribed by KNL) 36109a9638SPeter Gruber HISTORY: Major Revision Date By 37109a9638SPeter Gruber ----------------------------- -------- ----- 38109a9638SPeter Gruber Created 10/01/99 KNL 39109a9638SPeter Gruber 40109a9638SPeter Gruber MODULE NAME: riptide.h 41109a9638SPeter Gruber AUTHOR: O. Druzhinin (Transcribed by OLD) 42109a9638SPeter Gruber HISTORY: Major Revision Date By 43109a9638SPeter Gruber ----------------------------- -------- ----- 44109a9638SPeter Gruber Created 10/16/97 OLD 45109a9638SPeter Gruber 46109a9638SPeter Gruber MODULE NAME: Rp_Cmdif.cpp 47109a9638SPeter Gruber AUTHOR: O. Druzhinin (Transcribed by OLD) 48109a9638SPeter Gruber K. Lazarev (Transcribed by KNL) 49109a9638SPeter Gruber HISTORY: Major Revision Date By 50109a9638SPeter Gruber ----------------------------- -------- ----- 51109a9638SPeter Gruber Adopted from NT4 driver 6/22/99 OLD 52109a9638SPeter Gruber Ported to Linux 9/01/99 KNL 53109a9638SPeter Gruber 54109a9638SPeter Gruber MODULE NAME: rt_hw.c 55109a9638SPeter Gruber AUTHOR: O. Druzhinin (Transcribed by OLD) 56109a9638SPeter Gruber C. Lazarev (Transcribed by CNL) 57109a9638SPeter Gruber HISTORY: Major Revision Date By 58109a9638SPeter Gruber ----------------------------- -------- ----- 59109a9638SPeter Gruber Created 11/18/97 OLD 60109a9638SPeter Gruber Hardware functions for RipTide 11/24/97 CNL 61109a9638SPeter Gruber (ES1) are coded 62109a9638SPeter Gruber Hardware functions for RipTide 12/24/97 CNL 63109a9638SPeter Gruber (A0) are coded 64109a9638SPeter Gruber Hardware functions for RipTide 03/20/98 CNL 65109a9638SPeter Gruber (A1) are coded 66109a9638SPeter Gruber Boot loader is included 05/07/98 CNL 67109a9638SPeter Gruber Redesigned for WDM 07/27/98 CNL 68109a9638SPeter Gruber Redesigned for Linux 09/01/99 CNL 69109a9638SPeter Gruber 70109a9638SPeter Gruber MODULE NAME: rt_hw.h 71109a9638SPeter Gruber AUTHOR: C. Lazarev (Transcribed by CNL) 72109a9638SPeter Gruber HISTORY: Major Revision Date By 73109a9638SPeter Gruber ----------------------------- -------- ----- 74109a9638SPeter Gruber Created 11/18/97 CNL 75109a9638SPeter Gruber 76109a9638SPeter Gruber MODULE NAME: rt_mdl.c 77109a9638SPeter Gruber AUTHOR: Konstantin Lazarev (Transcribed by KNL) 78109a9638SPeter Gruber HISTORY: Major Revision Date By 79109a9638SPeter Gruber ----------------------------- -------- ----- 80109a9638SPeter Gruber Created 10/01/99 KNL 81109a9638SPeter Gruber 82109a9638SPeter Gruber MODULE NAME: mixer.h 83109a9638SPeter Gruber AUTHOR: K. Kenney 84109a9638SPeter Gruber HISTORY: Major Revision Date By 85109a9638SPeter Gruber ----------------------------- -------- ----- 86109a9638SPeter Gruber Created from MS W95 Sample 11/28/95 KRS 87109a9638SPeter Gruber RipTide 10/15/97 KRS 88109a9638SPeter Gruber Adopted for Windows NT driver 01/20/98 CNL 89109a9638SPeter Gruber */ 90109a9638SPeter Gruber 91109a9638SPeter Gruber #include <sound/driver.h> 92109a9638SPeter Gruber #include <linux/delay.h> 93109a9638SPeter Gruber #include <linux/init.h> 94109a9638SPeter Gruber #include <linux/interrupt.h> 95109a9638SPeter Gruber #include <linux/pci.h> 96109a9638SPeter Gruber #include <linux/slab.h> 97109a9638SPeter Gruber #include <linux/wait.h> 98109a9638SPeter Gruber #include <linux/gameport.h> 99109a9638SPeter Gruber #include <linux/device.h> 100109a9638SPeter Gruber #include <linux/firmware.h> 101109a9638SPeter Gruber #include <asm/io.h> 102109a9638SPeter Gruber #include <sound/core.h> 103109a9638SPeter Gruber #include <sound/info.h> 104109a9638SPeter Gruber #include <sound/control.h> 105109a9638SPeter Gruber #include <sound/pcm.h> 106109a9638SPeter Gruber #include <sound/pcm_params.h> 107109a9638SPeter Gruber #include <sound/ac97_codec.h> 108109a9638SPeter Gruber #include <sound/mpu401.h> 109109a9638SPeter Gruber #include <sound/opl3.h> 110109a9638SPeter Gruber #include <sound/initval.h> 111109a9638SPeter Gruber 112109a9638SPeter Gruber #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE)) 113109a9638SPeter Gruber #define SUPPORT_JOYSTICK 1 114109a9638SPeter Gruber #endif 115109a9638SPeter Gruber 116109a9638SPeter Gruber MODULE_AUTHOR("Peter Gruber <nokos@gmx.net>"); 117109a9638SPeter Gruber MODULE_DESCRIPTION("riptide"); 118109a9638SPeter Gruber MODULE_LICENSE("GPL"); 119109a9638SPeter Gruber MODULE_SUPPORTED_DEVICE("{{Conexant,Riptide}}"); 120*7e0af29dSClemens Ladisch MODULE_FIRMWARE("riptide.hex"); 121109a9638SPeter Gruber 122109a9638SPeter Gruber static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 123109a9638SPeter Gruber static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 124109a9638SPeter Gruber static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; 125109a9638SPeter Gruber 126109a9638SPeter Gruber #ifdef SUPPORT_JOYSTICK 127109a9638SPeter Gruber static int joystick_port[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS - 1)] = 0x200 }; 128109a9638SPeter Gruber #endif 129109a9638SPeter Gruber static int mpu_port[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS - 1)] = 0x330 }; 130109a9638SPeter Gruber static int opl3_port[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS - 1)] = 0x388 }; 131109a9638SPeter Gruber 132109a9638SPeter Gruber module_param_array(index, int, NULL, 0444); 133109a9638SPeter Gruber MODULE_PARM_DESC(index, "Index value for Riptide soundcard."); 134109a9638SPeter Gruber module_param_array(id, charp, NULL, 0444); 135109a9638SPeter Gruber MODULE_PARM_DESC(id, "ID string for Riptide soundcard."); 136109a9638SPeter Gruber module_param_array(enable, bool, NULL, 0444); 137109a9638SPeter Gruber MODULE_PARM_DESC(enable, "Enable Riptide soundcard."); 138109a9638SPeter Gruber #ifdef SUPPORT_JOYSTICK 139109a9638SPeter Gruber module_param_array(joystick_port, int, NULL, 0444); 140109a9638SPeter Gruber MODULE_PARM_DESC(joystick_port, "Joystick port # for Riptide soundcard."); 141109a9638SPeter Gruber #endif 142109a9638SPeter Gruber module_param_array(mpu_port, int, NULL, 0444); 143109a9638SPeter Gruber MODULE_PARM_DESC(mpu_port, "MPU401 port # for Riptide driver."); 144109a9638SPeter Gruber module_param_array(opl3_port, int, NULL, 0444); 145109a9638SPeter Gruber MODULE_PARM_DESC(opl3_port, "OPL3 port # for Riptide driver."); 146109a9638SPeter Gruber 147109a9638SPeter Gruber /* 148109a9638SPeter Gruber */ 149109a9638SPeter Gruber 150109a9638SPeter Gruber #define MPU401_HW_RIPTIDE MPU401_HW_MPU401 151109a9638SPeter Gruber #define OPL3_HW_RIPTIDE OPL3_HW_OPL3 152109a9638SPeter Gruber 153109a9638SPeter Gruber #define PCI_EXT_CapId 0x40 154109a9638SPeter Gruber #define PCI_EXT_NextCapPrt 0x41 155109a9638SPeter Gruber #define PCI_EXT_PWMC 0x42 156109a9638SPeter Gruber #define PCI_EXT_PWSCR 0x44 157109a9638SPeter Gruber #define PCI_EXT_Data00 0x46 158109a9638SPeter Gruber #define PCI_EXT_PMSCR_BSE 0x47 159109a9638SPeter Gruber #define PCI_EXT_SB_Base 0x48 160109a9638SPeter Gruber #define PCI_EXT_FM_Base 0x4a 161109a9638SPeter Gruber #define PCI_EXT_MPU_Base 0x4C 162109a9638SPeter Gruber #define PCI_EXT_Game_Base 0x4E 163109a9638SPeter Gruber #define PCI_EXT_Legacy_Mask 0x50 164109a9638SPeter Gruber #define PCI_EXT_AsicRev 0x52 165109a9638SPeter Gruber #define PCI_EXT_Reserved3 0x53 166109a9638SPeter Gruber 167109a9638SPeter Gruber #define LEGACY_ENABLE_ALL 0x8000 /* legacy device options */ 168109a9638SPeter Gruber #define LEGACY_ENABLE_SB 0x4000 169109a9638SPeter Gruber #define LEGACY_ENABLE_FM 0x2000 170109a9638SPeter Gruber #define LEGACY_ENABLE_MPU_INT 0x1000 171109a9638SPeter Gruber #define LEGACY_ENABLE_MPU 0x0800 172109a9638SPeter Gruber #define LEGACY_ENABLE_GAMEPORT 0x0400 173109a9638SPeter Gruber 174109a9638SPeter Gruber #define MAX_WRITE_RETRY 10 /* cmd interface limits */ 175109a9638SPeter Gruber #define MAX_ERROR_COUNT 10 176109a9638SPeter Gruber #define CMDIF_TIMEOUT 500000 177109a9638SPeter Gruber #define RESET_TRIES 5 178109a9638SPeter Gruber 179109a9638SPeter Gruber #define READ_PORT_ULONG(p) inl((unsigned long)&(p)) 180109a9638SPeter Gruber #define WRITE_PORT_ULONG(p,x) outl(x,(unsigned long)&(p)) 181109a9638SPeter Gruber 182109a9638SPeter Gruber #define READ_AUDIO_CONTROL(p) READ_PORT_ULONG(p->audio_control) 183109a9638SPeter Gruber #define WRITE_AUDIO_CONTROL(p,x) WRITE_PORT_ULONG(p->audio_control,x) 184109a9638SPeter Gruber #define UMASK_AUDIO_CONTROL(p,x) WRITE_PORT_ULONG(p->audio_control,READ_PORT_ULONG(p->audio_control)|x) 185109a9638SPeter Gruber #define MASK_AUDIO_CONTROL(p,x) WRITE_PORT_ULONG(p->audio_control,READ_PORT_ULONG(p->audio_control)&x) 186109a9638SPeter Gruber #define READ_AUDIO_STATUS(p) READ_PORT_ULONG(p->audio_status) 187109a9638SPeter Gruber 188109a9638SPeter Gruber #define SET_GRESET(p) UMASK_AUDIO_CONTROL(p,0x0001) /* global reset switch */ 189109a9638SPeter Gruber #define UNSET_GRESET(p) MASK_AUDIO_CONTROL(p,~0x0001) 190109a9638SPeter Gruber #define SET_AIE(p) UMASK_AUDIO_CONTROL(p,0x0004) /* interrupt enable */ 191109a9638SPeter Gruber #define UNSET_AIE(p) MASK_AUDIO_CONTROL(p,~0x0004) 192109a9638SPeter Gruber #define SET_AIACK(p) UMASK_AUDIO_CONTROL(p,0x0008) /* interrupt acknowledge */ 193109a9638SPeter Gruber #define UNSET_AIACKT(p) MASKAUDIO_CONTROL(p,~0x0008) 194109a9638SPeter Gruber #define SET_ECMDAE(p) UMASK_AUDIO_CONTROL(p,0x0010) 195109a9638SPeter Gruber #define UNSET_ECMDAE(p) MASK_AUDIO_CONTROL(p,~0x0010) 196109a9638SPeter Gruber #define SET_ECMDBE(p) UMASK_AUDIO_CONTROL(p,0x0020) 197109a9638SPeter Gruber #define UNSET_ECMDBE(p) MASK_AUDIO_CONTROL(p,~0x0020) 198109a9638SPeter Gruber #define SET_EDATAF(p) UMASK_AUDIO_CONTROL(p,0x0040) 199109a9638SPeter Gruber #define UNSET_EDATAF(p) MASK_AUDIO_CONTROL(p,~0x0040) 200109a9638SPeter Gruber #define SET_EDATBF(p) UMASK_AUDIO_CONTROL(p,0x0080) 201109a9638SPeter Gruber #define UNSET_EDATBF(p) MASK_AUDIO_CONTROL(p,~0x0080) 202109a9638SPeter Gruber #define SET_ESBIRQON(p) UMASK_AUDIO_CONTROL(p,0x0100) 203109a9638SPeter Gruber #define UNSET_ESBIRQON(p) MASK_AUDIO_CONTROL(p,~0x0100) 204109a9638SPeter Gruber #define SET_EMPUIRQ(p) UMASK_AUDIO_CONTROL(p,0x0200) 205109a9638SPeter Gruber #define UNSET_EMPUIRQ(p) MASK_AUDIO_CONTROL(p,~0x0200) 206109a9638SPeter Gruber #define IS_CMDE(a) (READ_PORT_ULONG(a->stat)&0x1) /* cmd empty */ 207109a9638SPeter Gruber #define IS_DATF(a) (READ_PORT_ULONG(a->stat)&0x2) /* data filled */ 208109a9638SPeter Gruber #define IS_READY(p) (READ_AUDIO_STATUS(p)&0x0001) 209109a9638SPeter Gruber #define IS_DLREADY(p) (READ_AUDIO_STATUS(p)&0x0002) 210109a9638SPeter Gruber #define IS_DLERR(p) (READ_AUDIO_STATUS(p)&0x0004) 211109a9638SPeter Gruber #define IS_GERR(p) (READ_AUDIO_STATUS(p)&0x0008) /* error ! */ 212109a9638SPeter Gruber #define IS_CMDAEIRQ(p) (READ_AUDIO_STATUS(p)&0x0010) 213109a9638SPeter Gruber #define IS_CMDBEIRQ(p) (READ_AUDIO_STATUS(p)&0x0020) 214109a9638SPeter Gruber #define IS_DATAFIRQ(p) (READ_AUDIO_STATUS(p)&0x0040) 215109a9638SPeter Gruber #define IS_DATBFIRQ(p) (READ_AUDIO_STATUS(p)&0x0080) 216109a9638SPeter Gruber #define IS_EOBIRQ(p) (READ_AUDIO_STATUS(p)&0x0100) /* interrupt status */ 217109a9638SPeter Gruber #define IS_EOSIRQ(p) (READ_AUDIO_STATUS(p)&0x0200) 218109a9638SPeter Gruber #define IS_EOCIRQ(p) (READ_AUDIO_STATUS(p)&0x0400) 219109a9638SPeter Gruber #define IS_UNSLIRQ(p) (READ_AUDIO_STATUS(p)&0x0800) 220109a9638SPeter Gruber #define IS_SBIRQ(p) (READ_AUDIO_STATUS(p)&0x1000) 221109a9638SPeter Gruber #define IS_MPUIRQ(p) (READ_AUDIO_STATUS(p)&0x2000) 222109a9638SPeter Gruber 223109a9638SPeter Gruber #define RESP 0x00000001 /* command flags */ 224109a9638SPeter Gruber #define PARM 0x00000002 225109a9638SPeter Gruber #define CMDA 0x00000004 226109a9638SPeter Gruber #define CMDB 0x00000008 227109a9638SPeter Gruber #define NILL 0x00000000 228109a9638SPeter Gruber 229109a9638SPeter Gruber #define LONG0(a) ((u32)a) /* shifts and masks */ 230109a9638SPeter Gruber #define BYTE0(a) (LONG0(a)&0xff) 231109a9638SPeter Gruber #define BYTE1(a) (BYTE0(a)<<8) 232109a9638SPeter Gruber #define BYTE2(a) (BYTE0(a)<<16) 233109a9638SPeter Gruber #define BYTE3(a) (BYTE0(a)<<24) 234109a9638SPeter Gruber #define WORD0(a) (LONG0(a)&0xffff) 235109a9638SPeter Gruber #define WORD1(a) (WORD0(a)<<8) 236109a9638SPeter Gruber #define WORD2(a) (WORD0(a)<<16) 237109a9638SPeter Gruber #define TRINIB0(a) (LONG0(a)&0xffffff) 238109a9638SPeter Gruber #define TRINIB1(a) (TRINIB0(a)<<8) 239109a9638SPeter Gruber 240109a9638SPeter Gruber #define RET(a) ((union cmdret *)(a)) 241109a9638SPeter Gruber 242109a9638SPeter Gruber #define SEND_GETV(p,b) sendcmd(p,RESP,GETV,0,RET(b)) /* get version */ 243109a9638SPeter Gruber #define SEND_GETC(p,b,c) sendcmd(p,PARM|RESP,GETC,c,RET(b)) 244109a9638SPeter Gruber #define SEND_GUNS(p,b) sendcmd(p,RESP,GUNS,0,RET(b)) 245109a9638SPeter Gruber #define SEND_SCID(p,b) sendcmd(p,RESP,SCID,0,RET(b)) 246109a9638SPeter Gruber #define SEND_RMEM(p,b,c,d) sendcmd(p,PARM|RESP,RMEM|BYTE1(b),LONG0(c),RET(d)) /* memory access for firmware write */ 247109a9638SPeter Gruber #define SEND_SMEM(p,b,c) sendcmd(p,PARM,SMEM|BYTE1(b),LONG0(c),RET(0)) /* memory access for firmware write */ 248109a9638SPeter Gruber #define SEND_WMEM(p,b,c) sendcmd(p,PARM,WMEM|BYTE1(b),LONG0(c),RET(0)) /* memory access for firmware write */ 249109a9638SPeter Gruber #define SEND_SDTM(p,b,c) sendcmd(p,PARM|RESP,SDTM|TRINIB1(b),0,RET(c)) /* memory access for firmware write */ 250109a9638SPeter Gruber #define SEND_GOTO(p,b) sendcmd(p,PARM,GOTO,LONG0(b),RET(0)) /* memory access for firmware write */ 251109a9638SPeter Gruber #define SEND_SETDPLL(p) sendcmd(p,0,ARM_SETDPLL,0,RET(0)) 252109a9638SPeter Gruber #define SEND_SSTR(p,b,c) sendcmd(p,PARM,SSTR|BYTE3(b),LONG0(c),RET(0)) /* start stream */ 253109a9638SPeter Gruber #define SEND_PSTR(p,b) sendcmd(p,PARM,PSTR,BYTE3(b),RET(0)) /* pause stream */ 254109a9638SPeter Gruber #define SEND_KSTR(p,b) sendcmd(p,PARM,KSTR,BYTE3(b),RET(0)) /* stop stream */ 255109a9638SPeter Gruber #define SEND_KDMA(p) sendcmd(p,0,KDMA,0,RET(0)) /* stop all dma */ 256109a9638SPeter Gruber #define SEND_GPOS(p,b,c,d) sendcmd(p,PARM|RESP,GPOS,BYTE3(c)|BYTE2(b),RET(d)) /* get position in dma */ 257109a9638SPeter Gruber #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 */ 258109a9638SPeter Gruber #define SEND_GSTS(p,b,c,d) sendcmd(p,PARM|RESP,GSTS,BYTE3(c)|BYTE2(b),RET(d)) 259109a9638SPeter Gruber #define SEND_NGPOS(p,b,c,d) sendcmd(p,PARM|RESP,NGPOS,BYTE3(c)|BYTE2(b),RET(d)) 260109a9638SPeter Gruber #define SEND_PSEL(p,b,c) sendcmd(p,PARM,PSEL,BYTE2(b)|BYTE3(c),RET(0)) /* activate lbus path */ 261109a9638SPeter Gruber #define SEND_PCLR(p,b,c) sendcmd(p,PARM,PCLR,BYTE2(b)|BYTE3(c),RET(0)) /* deactivate lbus path */ 262109a9638SPeter Gruber #define SEND_PLST(p,b) sendcmd(p,PARM,PLST,BYTE3(b),RET(0)) 263109a9638SPeter Gruber #define SEND_RSSV(p,b,c,d) sendcmd(p,PARM|RESP,RSSV,BYTE2(b)|BYTE3(c),RET(d)) 264109a9638SPeter Gruber #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 */ 265109a9638SPeter Gruber #define SEND_SSRC(p,b,c,d,e) sendcmd(p,PARM,SSRC|BYTE1(b)|WORD2(c),WORD0(d)|WORD2(e),RET(0)) /* configure source */ 266109a9638SPeter Gruber #define SEND_SLST(p,b) sendcmd(p,PARM,SLST,BYTE3(b),RET(0)) 267109a9638SPeter Gruber #define SEND_RSRC(p,b,c) sendcmd(p,RESP,RSRC|BYTE1(b),0,RET(c)) /* read source config */ 268109a9638SPeter Gruber #define SEND_SSRB(p,b,c) sendcmd(p,PARM,SSRB|BYTE1(b),WORD2(c),RET(0)) 269109a9638SPeter Gruber #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 */ 270109a9638SPeter Gruber #define SEND_RDGV(p,b,c,d) sendcmd(p,PARM|RESP,RDGV|BYTE2(b)|BYTE3(c),0,RET(d)) /* read digital mixer */ 271109a9638SPeter Gruber #define SEND_DLST(p,b) sendcmd(p,PARM,DLST,BYTE3(b),RET(0)) 272109a9638SPeter Gruber #define SEND_SACR(p,b,c) sendcmd(p,PARM,SACR,WORD0(b)|WORD2(c),RET(0)) /* set AC97 register */ 273109a9638SPeter Gruber #define SEND_RACR(p,b,c) sendcmd(p,PARM|RESP,RACR,WORD2(b),RET(c)) /* get AC97 register */ 274109a9638SPeter Gruber #define SEND_ALST(p,b) sendcmd(p,PARM,ALST,BYTE3(b),RET(0)) 275109a9638SPeter Gruber #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)) 276109a9638SPeter Gruber #define SEND_RXAC(p,b,c,d) sendcmd(p,PARM|RESP,RXAC,BYTE2(b)|BYTE3(c),RET(d)) 277109a9638SPeter Gruber #define SEND_SI2S(p,b) sendcmd(p,PARM,SI2S,WORD2(b),RET(0)) 278109a9638SPeter Gruber 279109a9638SPeter Gruber #define EOB_STATUS 0x80000000 /* status flags : block boundary */ 280109a9638SPeter Gruber #define EOS_STATUS 0x40000000 /* : stoppped */ 281109a9638SPeter Gruber #define EOC_STATUS 0x20000000 /* : stream end */ 282109a9638SPeter Gruber #define ERR_STATUS 0x10000000 283109a9638SPeter Gruber #define EMPTY_STATUS 0x08000000 284109a9638SPeter Gruber 285109a9638SPeter Gruber #define IEOB_ENABLE 0x1 /* enable interrupts for status notification above */ 286109a9638SPeter Gruber #define IEOS_ENABLE 0x2 287109a9638SPeter Gruber #define IEOC_ENABLE 0x4 288109a9638SPeter Gruber #define RDONCE 0x8 289109a9638SPeter Gruber #define DESC_MAX_MASK 0xff 290109a9638SPeter Gruber 291109a9638SPeter Gruber #define ST_PLAY 0x1 /* stream states */ 292109a9638SPeter Gruber #define ST_STOP 0x2 293109a9638SPeter Gruber #define ST_PAUSE 0x4 294109a9638SPeter Gruber 295109a9638SPeter Gruber #define I2S_INTDEC 3 /* config for I2S link */ 296109a9638SPeter Gruber #define I2S_MERGER 0 297109a9638SPeter Gruber #define I2S_SPLITTER 0 298109a9638SPeter Gruber #define I2S_MIXER 7 299109a9638SPeter Gruber #define I2S_RATE 44100 300109a9638SPeter Gruber 301109a9638SPeter Gruber #define MODEM_INTDEC 4 /* config for modem link */ 302109a9638SPeter Gruber #define MODEM_MERGER 3 303109a9638SPeter Gruber #define MODEM_SPLITTER 0 304109a9638SPeter Gruber #define MODEM_MIXER 11 305109a9638SPeter Gruber 306109a9638SPeter Gruber #define FM_INTDEC 3 /* config for FM/OPL3 link */ 307109a9638SPeter Gruber #define FM_MERGER 0 308109a9638SPeter Gruber #define FM_SPLITTER 0 309109a9638SPeter Gruber #define FM_MIXER 9 310109a9638SPeter Gruber 311109a9638SPeter Gruber #define SPLIT_PATH 0x80 /* path splitting flag */ 312109a9638SPeter Gruber 313109a9638SPeter Gruber enum FIRMWARE { 314109a9638SPeter Gruber DATA_REC = 0, EXT_END_OF_FILE, EXT_SEG_ADDR_REC, EXT_GOTO_CMD_REC, 315109a9638SPeter Gruber EXT_LIN_ADDR_REC, 316109a9638SPeter Gruber }; 317109a9638SPeter Gruber 318109a9638SPeter Gruber enum CMDS { 319109a9638SPeter Gruber GETV = 0x00, GETC, GUNS, SCID, RMEM = 320109a9638SPeter Gruber 0x10, SMEM, WMEM, SDTM, GOTO, SSTR = 321109a9638SPeter Gruber 0x20, PSTR, KSTR, KDMA, GPOS, SETF, GSTS, NGPOS, PSEL = 322109a9638SPeter Gruber 0x30, PCLR, PLST, RSSV, LSEL, SSRC = 0x40, SLST, RSRC, SSRB, SDGV = 323109a9638SPeter Gruber 0x50, RDGV, DLST, SACR = 0x60, RACR, ALST, TXAC, RXAC, SI2S = 324109a9638SPeter Gruber 0x70, ARM_SETDPLL = 0x72, 325109a9638SPeter Gruber }; 326109a9638SPeter Gruber 327109a9638SPeter Gruber enum E1SOURCE { 328109a9638SPeter Gruber ARM2LBUS_FIFO0 = 0, ARM2LBUS_FIFO1, ARM2LBUS_FIFO2, ARM2LBUS_FIFO3, 329109a9638SPeter Gruber ARM2LBUS_FIFO4, ARM2LBUS_FIFO5, ARM2LBUS_FIFO6, ARM2LBUS_FIFO7, 330109a9638SPeter Gruber ARM2LBUS_FIFO8, ARM2LBUS_FIFO9, ARM2LBUS_FIFO10, ARM2LBUS_FIFO11, 331109a9638SPeter Gruber ARM2LBUS_FIFO12, ARM2LBUS_FIFO13, ARM2LBUS_FIFO14, ARM2LBUS_FIFO15, 332109a9638SPeter Gruber INTER0_OUT, INTER1_OUT, INTER2_OUT, INTER3_OUT, INTER4_OUT, 333109a9638SPeter Gruber INTERM0_OUT, INTERM1_OUT, INTERM2_OUT, INTERM3_OUT, INTERM4_OUT, 334109a9638SPeter Gruber INTERM5_OUT, INTERM6_OUT, DECIMM0_OUT, DECIMM1_OUT, DECIMM2_OUT, 335109a9638SPeter Gruber DECIMM3_OUT, DECIM0_OUT, SR3_4_OUT, OPL3_SAMPLE, ASRC0, ASRC1, 336109a9638SPeter Gruber ACLNK2PADC, ACLNK2MODEM0RX, ACLNK2MIC, ACLNK2MODEM1RX, ACLNK2HNDMIC, 337109a9638SPeter Gruber DIGITAL_MIXER_OUT0, GAINFUNC0_OUT, GAINFUNC1_OUT, GAINFUNC2_OUT, 338109a9638SPeter Gruber GAINFUNC3_OUT, GAINFUNC4_OUT, SOFTMODEMTX, SPLITTER0_OUTL, 339109a9638SPeter Gruber SPLITTER0_OUTR, SPLITTER1_OUTL, SPLITTER1_OUTR, SPLITTER2_OUTL, 340109a9638SPeter Gruber SPLITTER2_OUTR, SPLITTER3_OUTL, SPLITTER3_OUTR, MERGER0_OUT, 341109a9638SPeter Gruber MERGER1_OUT, MERGER2_OUT, MERGER3_OUT, ARM2LBUS_FIFO_DIRECT, NO_OUT 342109a9638SPeter Gruber }; 343109a9638SPeter Gruber 344109a9638SPeter Gruber enum E2SINK { 345109a9638SPeter Gruber LBUS2ARM_FIFO0 = 0, LBUS2ARM_FIFO1, LBUS2ARM_FIFO2, LBUS2ARM_FIFO3, 346109a9638SPeter Gruber LBUS2ARM_FIFO4, LBUS2ARM_FIFO5, LBUS2ARM_FIFO6, LBUS2ARM_FIFO7, 347109a9638SPeter Gruber INTER0_IN, INTER1_IN, INTER2_IN, INTER3_IN, INTER4_IN, INTERM0_IN, 348109a9638SPeter Gruber INTERM1_IN, INTERM2_IN, INTERM3_IN, INTERM4_IN, INTERM5_IN, INTERM6_IN, 349109a9638SPeter Gruber DECIMM0_IN, DECIMM1_IN, DECIMM2_IN, DECIMM3_IN, DECIM0_IN, SR3_4_IN, 350109a9638SPeter Gruber PDAC2ACLNK, MODEM0TX2ACLNK, MODEM1TX2ACLNK, HNDSPK2ACLNK, 351109a9638SPeter Gruber DIGITAL_MIXER_IN0, DIGITAL_MIXER_IN1, DIGITAL_MIXER_IN2, 352109a9638SPeter Gruber DIGITAL_MIXER_IN3, DIGITAL_MIXER_IN4, DIGITAL_MIXER_IN5, 353109a9638SPeter Gruber DIGITAL_MIXER_IN6, DIGITAL_MIXER_IN7, DIGITAL_MIXER_IN8, 354109a9638SPeter Gruber DIGITAL_MIXER_IN9, DIGITAL_MIXER_IN10, DIGITAL_MIXER_IN11, 355109a9638SPeter Gruber GAINFUNC0_IN, GAINFUNC1_IN, GAINFUNC2_IN, GAINFUNC3_IN, GAINFUNC4_IN, 356109a9638SPeter Gruber SOFTMODEMRX, SPLITTER0_IN, SPLITTER1_IN, SPLITTER2_IN, SPLITTER3_IN, 357109a9638SPeter Gruber MERGER0_INL, MERGER0_INR, MERGER1_INL, MERGER1_INR, MERGER2_INL, 358109a9638SPeter Gruber MERGER2_INR, MERGER3_INL, MERGER3_INR, E2SINK_MAX 359109a9638SPeter Gruber }; 360109a9638SPeter Gruber 361109a9638SPeter Gruber enum LBUS_SINK { 362109a9638SPeter Gruber LS_SRC_INTERPOLATOR = 0, LS_SRC_INTERPOLATORM, LS_SRC_DECIMATOR, 363109a9638SPeter Gruber LS_SRC_DECIMATORM, LS_MIXER_IN, LS_MIXER_GAIN_FUNCTION, 364109a9638SPeter Gruber LS_SRC_SPLITTER, LS_SRC_MERGER, LS_NONE1, LS_NONE2, 365109a9638SPeter Gruber }; 366109a9638SPeter Gruber 367109a9638SPeter Gruber enum RT_CHANNEL_IDS { 368109a9638SPeter Gruber M0TX = 0, M1TX, TAMTX, HSSPKR, PDAC, DSNDTX0, DSNDTX1, DSNDTX2, 369109a9638SPeter Gruber DSNDTX3, DSNDTX4, DSNDTX5, DSNDTX6, DSNDTX7, WVSTRTX, COP3DTX, SPARE, 370109a9638SPeter Gruber M0RX, HSMIC, M1RX, CLEANRX, MICADC, PADC, COPRX1, COPRX2, 371109a9638SPeter Gruber CHANNEL_ID_COUNTER 372109a9638SPeter Gruber }; 373109a9638SPeter Gruber 374109a9638SPeter Gruber enum { SB_CMD = 0, MODEM_CMD, I2S_CMD0, I2S_CMD1, FM_CMD, MAX_CMD }; 375109a9638SPeter Gruber 376109a9638SPeter Gruber struct lbuspath { 377109a9638SPeter Gruber unsigned char *noconv; 378109a9638SPeter Gruber unsigned char *stereo; 379109a9638SPeter Gruber unsigned char *mono; 380109a9638SPeter Gruber }; 381109a9638SPeter Gruber 382109a9638SPeter Gruber struct cmdport { 383109a9638SPeter Gruber u32 data1; /* cmd,param */ 384109a9638SPeter Gruber u32 data2; /* param */ 385109a9638SPeter Gruber u32 stat; /* status */ 386109a9638SPeter Gruber u32 pad[5]; 387109a9638SPeter Gruber }; 388109a9638SPeter Gruber 389109a9638SPeter Gruber struct riptideport { 390109a9638SPeter Gruber u32 audio_control; /* status registers */ 391109a9638SPeter Gruber u32 audio_status; 392109a9638SPeter Gruber u32 pad[2]; 393109a9638SPeter Gruber struct cmdport port[2]; /* command ports */ 394109a9638SPeter Gruber }; 395109a9638SPeter Gruber 396109a9638SPeter Gruber struct cmdif { 397109a9638SPeter Gruber struct riptideport *hwport; 398109a9638SPeter Gruber spinlock_t lock; 399109a9638SPeter Gruber unsigned int cmdcnt; /* cmd statistics */ 400109a9638SPeter Gruber unsigned int cmdtime; 401109a9638SPeter Gruber unsigned int cmdtimemax; 402109a9638SPeter Gruber unsigned int cmdtimemin; 403109a9638SPeter Gruber unsigned int errcnt; 404109a9638SPeter Gruber int is_reset; 405109a9638SPeter Gruber }; 406109a9638SPeter Gruber 407109a9638SPeter Gruber struct riptide_firmware { 408109a9638SPeter Gruber u16 ASIC; 409109a9638SPeter Gruber u16 CODEC; 410109a9638SPeter Gruber u16 AUXDSP; 411109a9638SPeter Gruber u16 PROG; 412109a9638SPeter Gruber }; 413109a9638SPeter Gruber 414109a9638SPeter Gruber union cmdret { 415109a9638SPeter Gruber u8 retbytes[8]; 416109a9638SPeter Gruber u16 retwords[4]; 417109a9638SPeter Gruber u32 retlongs[2]; 418109a9638SPeter Gruber }; 419109a9638SPeter Gruber 420109a9638SPeter Gruber union firmware_version { 421109a9638SPeter Gruber union cmdret ret; 422109a9638SPeter Gruber struct riptide_firmware firmware; 423109a9638SPeter Gruber }; 424109a9638SPeter Gruber 425109a9638SPeter Gruber #define get_pcmhwdev(substream) (struct pcmhw *)(substream->runtime->private_data) 426109a9638SPeter Gruber 427109a9638SPeter Gruber #define PLAYBACK_SUBSTREAMS 3 428109a9638SPeter Gruber struct snd_riptide { 429109a9638SPeter Gruber struct snd_card *card; 430109a9638SPeter Gruber struct pci_dev *pci; 431109a9638SPeter Gruber const struct firmware *fw_entry; 432109a9638SPeter Gruber 433109a9638SPeter Gruber struct cmdif *cif; 434109a9638SPeter Gruber 435109a9638SPeter Gruber struct snd_pcm *pcm; 436109a9638SPeter Gruber struct snd_pcm *pcm_i2s; 437109a9638SPeter Gruber struct snd_rawmidi *rmidi; 438109a9638SPeter Gruber struct snd_opl3 *opl3; 439109a9638SPeter Gruber struct snd_ac97 *ac97; 440109a9638SPeter Gruber struct snd_ac97_bus *ac97_bus; 441109a9638SPeter Gruber 442109a9638SPeter Gruber struct snd_pcm_substream *playback_substream[PLAYBACK_SUBSTREAMS]; 443109a9638SPeter Gruber struct snd_pcm_substream *capture_substream; 444109a9638SPeter Gruber 445109a9638SPeter Gruber int openstreams; 446109a9638SPeter Gruber 447109a9638SPeter Gruber int irq; 448109a9638SPeter Gruber unsigned long port; 449109a9638SPeter Gruber unsigned short mpuaddr; 450109a9638SPeter Gruber unsigned short opladdr; 451109a9638SPeter Gruber #ifdef SUPPORT_JOYSTICK 452109a9638SPeter Gruber unsigned short gameaddr; 453109a9638SPeter Gruber #endif 454109a9638SPeter Gruber struct resource *res_port; 455109a9638SPeter Gruber 456109a9638SPeter Gruber unsigned short device_id; 457109a9638SPeter Gruber 458109a9638SPeter Gruber union firmware_version firmware; 459109a9638SPeter Gruber 460109a9638SPeter Gruber spinlock_t lock; 461109a9638SPeter Gruber struct tasklet_struct riptide_tq; 462109a9638SPeter Gruber struct snd_info_entry *proc_entry; 463109a9638SPeter Gruber 464109a9638SPeter Gruber unsigned long received_irqs; 465109a9638SPeter Gruber unsigned long handled_irqs; 466109a9638SPeter Gruber #ifdef CONFIG_PM 467109a9638SPeter Gruber int in_suspend; 468109a9638SPeter Gruber #endif 469109a9638SPeter Gruber }; 470109a9638SPeter Gruber 471109a9638SPeter Gruber struct sgd { /* scatter gather desriptor */ 472109a9638SPeter Gruber u32 dwNextLink; 473109a9638SPeter Gruber u32 dwSegPtrPhys; 474109a9638SPeter Gruber u32 dwSegLen; 475109a9638SPeter Gruber u32 dwStat_Ctl; 476109a9638SPeter Gruber }; 477109a9638SPeter Gruber 478109a9638SPeter Gruber struct pcmhw { /* pcm descriptor */ 479109a9638SPeter Gruber struct lbuspath paths; 480109a9638SPeter Gruber unsigned char *lbuspath; 481109a9638SPeter Gruber unsigned char source; 482109a9638SPeter Gruber unsigned char intdec[2]; 483109a9638SPeter Gruber unsigned char mixer; 484109a9638SPeter Gruber unsigned char id; 485109a9638SPeter Gruber unsigned char state; 486109a9638SPeter Gruber unsigned int rate; 487109a9638SPeter Gruber unsigned int channels; 488109a9638SPeter Gruber snd_pcm_format_t format; 489109a9638SPeter Gruber struct snd_dma_buffer sgdlist; 490109a9638SPeter Gruber struct sgd *sgdbuf; 491109a9638SPeter Gruber unsigned int size; 492109a9638SPeter Gruber unsigned int pages; 493109a9638SPeter Gruber unsigned int oldpos; 494109a9638SPeter Gruber unsigned int pointer; 495109a9638SPeter Gruber }; 496109a9638SPeter Gruber 497109a9638SPeter Gruber #define CMDRET_ZERO (union cmdret){{(u32)0, (u32) 0}} 498109a9638SPeter Gruber 499109a9638SPeter Gruber static int sendcmd(struct cmdif *cif, u32 flags, u32 cmd, u32 parm, 500109a9638SPeter Gruber union cmdret *ret); 501109a9638SPeter Gruber static int getsourcesink(struct cmdif *cif, unsigned char source, 502109a9638SPeter Gruber unsigned char sink, unsigned char *a, 503109a9638SPeter Gruber unsigned char *b); 504109a9638SPeter Gruber static int snd_riptide_initialize(struct snd_riptide *chip); 505109a9638SPeter Gruber static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip); 506109a9638SPeter Gruber 507109a9638SPeter Gruber /* 508109a9638SPeter Gruber */ 509109a9638SPeter Gruber 510f40b6890STakashi Iwai static struct pci_device_id snd_riptide_ids[] = { 511109a9638SPeter Gruber { 512109a9638SPeter Gruber .vendor = 0x127a,.device = 0x4310, 513109a9638SPeter Gruber .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 514109a9638SPeter Gruber }, 515109a9638SPeter Gruber { 516109a9638SPeter Gruber .vendor = 0x127a,.device = 0x4320, 517109a9638SPeter Gruber .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 518109a9638SPeter Gruber }, 519109a9638SPeter Gruber { 520109a9638SPeter Gruber .vendor = 0x127a,.device = 0x4330, 521109a9638SPeter Gruber .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 522109a9638SPeter Gruber }, 523109a9638SPeter Gruber { 524109a9638SPeter Gruber .vendor = 0x127a,.device = 0x4340, 525109a9638SPeter Gruber .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 526109a9638SPeter Gruber }, 527109a9638SPeter Gruber {0,}, 528109a9638SPeter Gruber }; 529109a9638SPeter Gruber 530109a9638SPeter Gruber #ifdef SUPPORT_JOYSTICK 531396c9b92SHenrik Kretzschmar static struct pci_device_id snd_riptide_joystick_ids[] __devinitdata = { 532109a9638SPeter Gruber { 533109a9638SPeter Gruber .vendor = 0x127a,.device = 0x4312, 534109a9638SPeter Gruber .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 535109a9638SPeter Gruber }, 536109a9638SPeter Gruber { 537109a9638SPeter Gruber .vendor = 0x127a,.device = 0x4322, 538109a9638SPeter Gruber .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 539109a9638SPeter Gruber }, 540109a9638SPeter Gruber {.vendor = 0x127a,.device = 0x4332, 541109a9638SPeter Gruber .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 542109a9638SPeter Gruber }, 543109a9638SPeter Gruber {.vendor = 0x127a,.device = 0x4342, 544109a9638SPeter Gruber .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 545109a9638SPeter Gruber }, 546109a9638SPeter Gruber {0,}, 547109a9638SPeter Gruber }; 548109a9638SPeter Gruber #endif 549109a9638SPeter Gruber 550109a9638SPeter Gruber MODULE_DEVICE_TABLE(pci, snd_riptide_ids); 551109a9638SPeter Gruber 552109a9638SPeter Gruber /* 553109a9638SPeter Gruber */ 554109a9638SPeter Gruber 555109a9638SPeter Gruber static unsigned char lbusin2out[E2SINK_MAX + 1][2] = { 556109a9638SPeter Gruber {NO_OUT, LS_NONE1}, {NO_OUT, LS_NONE2}, {NO_OUT, LS_NONE1}, {NO_OUT, 557109a9638SPeter Gruber LS_NONE2}, 558109a9638SPeter Gruber {NO_OUT, LS_NONE1}, {NO_OUT, LS_NONE2}, {NO_OUT, LS_NONE1}, {NO_OUT, 559109a9638SPeter Gruber LS_NONE2}, 560109a9638SPeter Gruber {INTER0_OUT, LS_SRC_INTERPOLATOR}, {INTER1_OUT, LS_SRC_INTERPOLATOR}, 561109a9638SPeter Gruber {INTER2_OUT, LS_SRC_INTERPOLATOR}, {INTER3_OUT, LS_SRC_INTERPOLATOR}, 562109a9638SPeter Gruber {INTER4_OUT, LS_SRC_INTERPOLATOR}, {INTERM0_OUT, LS_SRC_INTERPOLATORM}, 563109a9638SPeter Gruber {INTERM1_OUT, LS_SRC_INTERPOLATORM}, {INTERM2_OUT, 564109a9638SPeter Gruber LS_SRC_INTERPOLATORM}, 565109a9638SPeter Gruber {INTERM3_OUT, LS_SRC_INTERPOLATORM}, {INTERM4_OUT, 566109a9638SPeter Gruber LS_SRC_INTERPOLATORM}, 567109a9638SPeter Gruber {INTERM5_OUT, LS_SRC_INTERPOLATORM}, {INTERM6_OUT, 568109a9638SPeter Gruber LS_SRC_INTERPOLATORM}, 569109a9638SPeter Gruber {DECIMM0_OUT, LS_SRC_DECIMATORM}, {DECIMM1_OUT, LS_SRC_DECIMATORM}, 570109a9638SPeter Gruber {DECIMM2_OUT, LS_SRC_DECIMATORM}, {DECIMM3_OUT, LS_SRC_DECIMATORM}, 571109a9638SPeter Gruber {DECIM0_OUT, LS_SRC_DECIMATOR}, {SR3_4_OUT, LS_NONE1}, {NO_OUT, 572109a9638SPeter Gruber LS_NONE2}, 573109a9638SPeter Gruber {NO_OUT, LS_NONE1}, {NO_OUT, LS_NONE2}, {NO_OUT, LS_NONE1}, 574109a9638SPeter Gruber {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, 575109a9638SPeter Gruber {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, 576109a9638SPeter Gruber {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, 577109a9638SPeter Gruber {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, 578109a9638SPeter Gruber {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, 579109a9638SPeter Gruber {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, 580109a9638SPeter Gruber {GAINFUNC0_OUT, LS_MIXER_GAIN_FUNCTION}, {GAINFUNC1_OUT, 581109a9638SPeter Gruber LS_MIXER_GAIN_FUNCTION}, 582109a9638SPeter Gruber {GAINFUNC2_OUT, LS_MIXER_GAIN_FUNCTION}, {GAINFUNC3_OUT, 583109a9638SPeter Gruber LS_MIXER_GAIN_FUNCTION}, 584109a9638SPeter Gruber {GAINFUNC4_OUT, LS_MIXER_GAIN_FUNCTION}, {SOFTMODEMTX, LS_NONE1}, 585109a9638SPeter Gruber {SPLITTER0_OUTL, LS_SRC_SPLITTER}, {SPLITTER1_OUTL, LS_SRC_SPLITTER}, 586109a9638SPeter Gruber {SPLITTER2_OUTL, LS_SRC_SPLITTER}, {SPLITTER3_OUTL, LS_SRC_SPLITTER}, 587109a9638SPeter Gruber {MERGER0_OUT, LS_SRC_MERGER}, {MERGER0_OUT, LS_SRC_MERGER}, 588109a9638SPeter Gruber {MERGER1_OUT, LS_SRC_MERGER}, 589109a9638SPeter Gruber {MERGER1_OUT, LS_SRC_MERGER}, {MERGER2_OUT, LS_SRC_MERGER}, 590109a9638SPeter Gruber {MERGER2_OUT, LS_SRC_MERGER}, 591109a9638SPeter Gruber {MERGER3_OUT, LS_SRC_MERGER}, {MERGER3_OUT, LS_SRC_MERGER}, {NO_OUT, 592109a9638SPeter Gruber LS_NONE2}, 593109a9638SPeter Gruber }; 594109a9638SPeter Gruber 595109a9638SPeter Gruber static unsigned char lbus_play_opl3[] = { 596109a9638SPeter Gruber DIGITAL_MIXER_IN0 + FM_MIXER, 0xff 597109a9638SPeter Gruber }; 598109a9638SPeter Gruber static unsigned char lbus_play_modem[] = { 599109a9638SPeter Gruber DIGITAL_MIXER_IN0 + MODEM_MIXER, 0xff 600109a9638SPeter Gruber }; 601109a9638SPeter Gruber static unsigned char lbus_play_i2s[] = { 602109a9638SPeter Gruber INTER0_IN + I2S_INTDEC, DIGITAL_MIXER_IN0 + I2S_MIXER, 0xff 603109a9638SPeter Gruber }; 604109a9638SPeter Gruber static unsigned char lbus_play_out[] = { 605109a9638SPeter Gruber PDAC2ACLNK, 0xff 606109a9638SPeter Gruber }; 607109a9638SPeter Gruber static unsigned char lbus_play_outhp[] = { 608109a9638SPeter Gruber HNDSPK2ACLNK, 0xff 609109a9638SPeter Gruber }; 610109a9638SPeter Gruber static unsigned char lbus_play_noconv1[] = { 611109a9638SPeter Gruber DIGITAL_MIXER_IN0, 0xff 612109a9638SPeter Gruber }; 613109a9638SPeter Gruber static unsigned char lbus_play_stereo1[] = { 614109a9638SPeter Gruber INTER0_IN, DIGITAL_MIXER_IN0, 0xff 615109a9638SPeter Gruber }; 616109a9638SPeter Gruber static unsigned char lbus_play_mono1[] = { 617109a9638SPeter Gruber INTERM0_IN, DIGITAL_MIXER_IN0, 0xff 618109a9638SPeter Gruber }; 619109a9638SPeter Gruber static unsigned char lbus_play_noconv2[] = { 620109a9638SPeter Gruber DIGITAL_MIXER_IN1, 0xff 621109a9638SPeter Gruber }; 622109a9638SPeter Gruber static unsigned char lbus_play_stereo2[] = { 623109a9638SPeter Gruber INTER1_IN, DIGITAL_MIXER_IN1, 0xff 624109a9638SPeter Gruber }; 625109a9638SPeter Gruber static unsigned char lbus_play_mono2[] = { 626109a9638SPeter Gruber INTERM1_IN, DIGITAL_MIXER_IN1, 0xff 627109a9638SPeter Gruber }; 628109a9638SPeter Gruber static unsigned char lbus_play_noconv3[] = { 629109a9638SPeter Gruber DIGITAL_MIXER_IN2, 0xff 630109a9638SPeter Gruber }; 631109a9638SPeter Gruber static unsigned char lbus_play_stereo3[] = { 632109a9638SPeter Gruber INTER2_IN, DIGITAL_MIXER_IN2, 0xff 633109a9638SPeter Gruber }; 634109a9638SPeter Gruber static unsigned char lbus_play_mono3[] = { 635109a9638SPeter Gruber INTERM2_IN, DIGITAL_MIXER_IN2, 0xff 636109a9638SPeter Gruber }; 637109a9638SPeter Gruber static unsigned char lbus_rec_noconv1[] = { 638109a9638SPeter Gruber LBUS2ARM_FIFO5, 0xff 639109a9638SPeter Gruber }; 640109a9638SPeter Gruber static unsigned char lbus_rec_stereo1[] = { 641109a9638SPeter Gruber DECIM0_IN, LBUS2ARM_FIFO5, 0xff 642109a9638SPeter Gruber }; 643109a9638SPeter Gruber static unsigned char lbus_rec_mono1[] = { 644109a9638SPeter Gruber DECIMM3_IN, LBUS2ARM_FIFO5, 0xff 645109a9638SPeter Gruber }; 646109a9638SPeter Gruber 647109a9638SPeter Gruber static unsigned char play_ids[] = { 4, 1, 2, }; 648109a9638SPeter Gruber static unsigned char play_sources[] = { 649109a9638SPeter Gruber ARM2LBUS_FIFO4, ARM2LBUS_FIFO1, ARM2LBUS_FIFO2, 650109a9638SPeter Gruber }; 651109a9638SPeter Gruber static struct lbuspath lbus_play_paths[] = { 652109a9638SPeter Gruber { 653109a9638SPeter Gruber .noconv = lbus_play_noconv1, 654109a9638SPeter Gruber .stereo = lbus_play_stereo1, 655109a9638SPeter Gruber .mono = lbus_play_mono1, 656109a9638SPeter Gruber }, 657109a9638SPeter Gruber { 658109a9638SPeter Gruber .noconv = lbus_play_noconv2, 659109a9638SPeter Gruber .stereo = lbus_play_stereo2, 660109a9638SPeter Gruber .mono = lbus_play_mono2, 661109a9638SPeter Gruber }, 662109a9638SPeter Gruber { 663109a9638SPeter Gruber .noconv = lbus_play_noconv3, 664109a9638SPeter Gruber .stereo = lbus_play_stereo3, 665109a9638SPeter Gruber .mono = lbus_play_mono3, 666109a9638SPeter Gruber }, 667109a9638SPeter Gruber }; 668109a9638SPeter Gruber static struct lbuspath lbus_rec_path = { 669109a9638SPeter Gruber .noconv = lbus_rec_noconv1, 670109a9638SPeter Gruber .stereo = lbus_rec_stereo1, 671109a9638SPeter Gruber .mono = lbus_rec_mono1, 672109a9638SPeter Gruber }; 673109a9638SPeter Gruber 674109a9638SPeter Gruber #define FIRMWARE_VERSIONS 1 675109a9638SPeter Gruber static union firmware_version firmware_versions[] = { 676109a9638SPeter Gruber { 677adf75dcaSClemens Ladisch .firmware = { 678adf75dcaSClemens Ladisch .ASIC = 3, 679adf75dcaSClemens Ladisch .CODEC = 2, 680adf75dcaSClemens Ladisch .AUXDSP = 3, 681adf75dcaSClemens Ladisch .PROG = 773, 682adf75dcaSClemens Ladisch }, 683109a9638SPeter Gruber }, 684109a9638SPeter Gruber }; 685109a9638SPeter Gruber 686109a9638SPeter Gruber static u32 atoh(unsigned char *in, unsigned int len) 687109a9638SPeter Gruber { 688109a9638SPeter Gruber u32 sum = 0; 689109a9638SPeter Gruber unsigned int mult = 1; 690109a9638SPeter Gruber unsigned char c; 691109a9638SPeter Gruber 692109a9638SPeter Gruber while (len) { 693109a9638SPeter Gruber c = in[len - 1]; 694109a9638SPeter Gruber if ((c >= '0') && (c <= '9')) 695109a9638SPeter Gruber sum += mult * (c - '0'); 696109a9638SPeter Gruber else if ((c >= 'A') && (c <= 'F')) 697109a9638SPeter Gruber sum += mult * (c - ('A' - 10)); 698109a9638SPeter Gruber else if ((c >= 'a') && (c <= 'f')) 699109a9638SPeter Gruber sum += mult * (c - ('a' - 10)); 700109a9638SPeter Gruber mult *= 16; 701109a9638SPeter Gruber --len; 702109a9638SPeter Gruber } 703109a9638SPeter Gruber return sum; 704109a9638SPeter Gruber } 705109a9638SPeter Gruber 706109a9638SPeter Gruber static int senddata(struct cmdif *cif, unsigned char *in, u32 offset) 707109a9638SPeter Gruber { 708109a9638SPeter Gruber u32 addr; 709109a9638SPeter Gruber u32 data; 710109a9638SPeter Gruber u32 i; 711109a9638SPeter Gruber unsigned char *p; 712109a9638SPeter Gruber 713109a9638SPeter Gruber i = atoh(&in[1], 2); 714109a9638SPeter Gruber addr = offset + atoh(&in[3], 4); 715109a9638SPeter Gruber if (SEND_SMEM(cif, 0, addr) != 0) 716109a9638SPeter Gruber return -EACCES; 717109a9638SPeter Gruber p = in + 9; 718109a9638SPeter Gruber while (i) { 719109a9638SPeter Gruber data = atoh(p, 8); 720109a9638SPeter Gruber if (SEND_WMEM(cif, 2, 721109a9638SPeter Gruber ((data & 0x0f0f0f0f) << 4) | ((data & 0xf0f0f0f0) 722109a9638SPeter Gruber >> 4))) 723109a9638SPeter Gruber return -EACCES; 724109a9638SPeter Gruber i -= 4; 725109a9638SPeter Gruber p += 8; 726109a9638SPeter Gruber } 727109a9638SPeter Gruber return 0; 728109a9638SPeter Gruber } 729109a9638SPeter Gruber 730109a9638SPeter Gruber static int loadfirmware(struct cmdif *cif, unsigned char *img, 731109a9638SPeter Gruber unsigned int size) 732109a9638SPeter Gruber { 733109a9638SPeter Gruber unsigned char *in; 734109a9638SPeter Gruber u32 laddr, saddr, t, val; 735109a9638SPeter Gruber int err = 0; 736109a9638SPeter Gruber 737109a9638SPeter Gruber laddr = saddr = 0; 738109a9638SPeter Gruber while (size > 0 && err == 0) { 739109a9638SPeter Gruber in = img; 740109a9638SPeter Gruber if (in[0] == ':') { 741109a9638SPeter Gruber t = atoh(&in[7], 2); 742109a9638SPeter Gruber switch (t) { 743109a9638SPeter Gruber case DATA_REC: 744109a9638SPeter Gruber err = senddata(cif, in, laddr + saddr); 745109a9638SPeter Gruber break; 746109a9638SPeter Gruber case EXT_SEG_ADDR_REC: 747109a9638SPeter Gruber saddr = atoh(&in[9], 4) << 4; 748109a9638SPeter Gruber break; 749109a9638SPeter Gruber case EXT_LIN_ADDR_REC: 750109a9638SPeter Gruber laddr = atoh(&in[9], 4) << 16; 751109a9638SPeter Gruber break; 752109a9638SPeter Gruber case EXT_GOTO_CMD_REC: 753109a9638SPeter Gruber val = atoh(&in[9], 8); 754109a9638SPeter Gruber if (SEND_GOTO(cif, val) != 0) 755109a9638SPeter Gruber err = -EACCES; 756109a9638SPeter Gruber break; 757109a9638SPeter Gruber case EXT_END_OF_FILE: 758109a9638SPeter Gruber size = 0; 759109a9638SPeter Gruber break; 760109a9638SPeter Gruber default: 761109a9638SPeter Gruber break; 762109a9638SPeter Gruber } 763109a9638SPeter Gruber while (size > 0) { 764109a9638SPeter Gruber size--; 765109a9638SPeter Gruber if (*img++ == '\n') 766109a9638SPeter Gruber break; 767109a9638SPeter Gruber } 768109a9638SPeter Gruber } 769109a9638SPeter Gruber } 770109a9638SPeter Gruber snd_printdd("load firmware return %d\n", err); 771109a9638SPeter Gruber return err; 772109a9638SPeter Gruber } 773109a9638SPeter Gruber 774109a9638SPeter Gruber static void 775109a9638SPeter Gruber alloclbuspath(struct cmdif *cif, unsigned char source, 776109a9638SPeter Gruber unsigned char *path, unsigned char *mixer, unsigned char *s) 777109a9638SPeter Gruber { 778109a9638SPeter Gruber while (*path != 0xff) { 779109a9638SPeter Gruber unsigned char sink, type; 780109a9638SPeter Gruber 781109a9638SPeter Gruber sink = *path & (~SPLIT_PATH); 782109a9638SPeter Gruber if (sink != E2SINK_MAX) { 783109a9638SPeter Gruber snd_printdd("alloc path 0x%x->0x%x\n", source, sink); 784109a9638SPeter Gruber SEND_PSEL(cif, source, sink); 785109a9638SPeter Gruber source = lbusin2out[sink][0]; 786109a9638SPeter Gruber type = lbusin2out[sink][1]; 787109a9638SPeter Gruber if (type == LS_MIXER_IN) { 788109a9638SPeter Gruber if (mixer) 789109a9638SPeter Gruber *mixer = sink - DIGITAL_MIXER_IN0; 790109a9638SPeter Gruber } 791109a9638SPeter Gruber if (type == LS_SRC_DECIMATORM || 792109a9638SPeter Gruber type == LS_SRC_DECIMATOR || 793109a9638SPeter Gruber type == LS_SRC_INTERPOLATORM || 794109a9638SPeter Gruber type == LS_SRC_INTERPOLATOR) { 795109a9638SPeter Gruber if (s) { 796109a9638SPeter Gruber if (s[0] != 0xff) 797109a9638SPeter Gruber s[1] = sink; 798109a9638SPeter Gruber else 799109a9638SPeter Gruber s[0] = sink; 800109a9638SPeter Gruber } 801109a9638SPeter Gruber } 802109a9638SPeter Gruber } 803109a9638SPeter Gruber if (*path++ & SPLIT_PATH) { 804109a9638SPeter Gruber unsigned char *npath = path; 805109a9638SPeter Gruber 806109a9638SPeter Gruber while (*npath != 0xff) 807109a9638SPeter Gruber npath++; 808109a9638SPeter Gruber alloclbuspath(cif, source + 1, ++npath, mixer, s); 809109a9638SPeter Gruber } 810109a9638SPeter Gruber } 811109a9638SPeter Gruber } 812109a9638SPeter Gruber 813109a9638SPeter Gruber static void 814109a9638SPeter Gruber freelbuspath(struct cmdif *cif, unsigned char source, unsigned char *path) 815109a9638SPeter Gruber { 816109a9638SPeter Gruber while (*path != 0xff) { 817109a9638SPeter Gruber unsigned char sink; 818109a9638SPeter Gruber 819109a9638SPeter Gruber sink = *path & (~SPLIT_PATH); 820109a9638SPeter Gruber if (sink != E2SINK_MAX) { 821109a9638SPeter Gruber snd_printdd("free path 0x%x->0x%x\n", source, sink); 822109a9638SPeter Gruber SEND_PCLR(cif, source, sink); 823109a9638SPeter Gruber source = lbusin2out[sink][0]; 824109a9638SPeter Gruber } 825109a9638SPeter Gruber if (*path++ & SPLIT_PATH) { 826109a9638SPeter Gruber unsigned char *npath = path; 827109a9638SPeter Gruber 828109a9638SPeter Gruber while (*npath != 0xff) 829109a9638SPeter Gruber npath++; 830109a9638SPeter Gruber freelbuspath(cif, source + 1, ++npath); 831109a9638SPeter Gruber } 832109a9638SPeter Gruber } 833109a9638SPeter Gruber } 834109a9638SPeter Gruber 835109a9638SPeter Gruber static int writearm(struct cmdif *cif, u32 addr, u32 data, u32 mask) 836109a9638SPeter Gruber { 837109a9638SPeter Gruber union cmdret rptr = CMDRET_ZERO; 838109a9638SPeter Gruber unsigned int i = MAX_WRITE_RETRY; 839109a9638SPeter Gruber int flag = 1; 840109a9638SPeter Gruber 841109a9638SPeter Gruber SEND_RMEM(cif, 0x02, addr, &rptr); 842109a9638SPeter Gruber rptr.retlongs[0] &= (~mask); 843109a9638SPeter Gruber 844109a9638SPeter Gruber while (--i) { 845109a9638SPeter Gruber SEND_SMEM(cif, 0x01, addr); 846109a9638SPeter Gruber SEND_WMEM(cif, 0x02, (rptr.retlongs[0] | data)); 847109a9638SPeter Gruber SEND_RMEM(cif, 0x02, addr, &rptr); 848109a9638SPeter Gruber if ((rptr.retlongs[0] & data) == data) { 849109a9638SPeter Gruber flag = 0; 850109a9638SPeter Gruber break; 851109a9638SPeter Gruber } else 852109a9638SPeter Gruber rptr.retlongs[0] &= ~mask; 853109a9638SPeter Gruber } 854109a9638SPeter Gruber snd_printdd("send arm 0x%x 0x%x 0x%x return %d\n", addr, data, mask, 855109a9638SPeter Gruber flag); 856109a9638SPeter Gruber return flag; 857109a9638SPeter Gruber } 858109a9638SPeter Gruber 859109a9638SPeter Gruber static int sendcmd(struct cmdif *cif, u32 flags, u32 cmd, u32 parm, 860109a9638SPeter Gruber union cmdret *ret) 861109a9638SPeter Gruber { 862109a9638SPeter Gruber int i, j; 863109a9638SPeter Gruber int err; 864109a9638SPeter Gruber unsigned int time = 0; 865109a9638SPeter Gruber unsigned long irqflags; 866109a9638SPeter Gruber struct riptideport *hwport; 867109a9638SPeter Gruber struct cmdport *cmdport = NULL; 868109a9638SPeter Gruber 869109a9638SPeter Gruber snd_assert(cif, return -EINVAL); 870109a9638SPeter Gruber 871109a9638SPeter Gruber hwport = cif->hwport; 872109a9638SPeter Gruber if (cif->errcnt > MAX_ERROR_COUNT) { 873109a9638SPeter Gruber if (cif->is_reset) { 874109a9638SPeter Gruber snd_printk(KERN_ERR 875109a9638SPeter Gruber "Riptide: Too many failed cmds, reinitializing\n"); 876109a9638SPeter Gruber if (riptide_reset(cif, NULL) == 0) { 877109a9638SPeter Gruber cif->errcnt = 0; 878109a9638SPeter Gruber return -EIO; 879109a9638SPeter Gruber } 880109a9638SPeter Gruber } 881109a9638SPeter Gruber snd_printk(KERN_ERR "Riptide: Initialization failed.\n"); 882109a9638SPeter Gruber return -EINVAL; 883109a9638SPeter Gruber } 884109a9638SPeter Gruber if (ret) { 885109a9638SPeter Gruber ret->retlongs[0] = 0; 886109a9638SPeter Gruber ret->retlongs[1] = 0; 887109a9638SPeter Gruber } 888109a9638SPeter Gruber i = 0; 889109a9638SPeter Gruber spin_lock_irqsave(&cif->lock, irqflags); 890109a9638SPeter Gruber while (i++ < CMDIF_TIMEOUT && !IS_READY(cif->hwport)) 891109a9638SPeter Gruber udelay(10); 892109a9638SPeter Gruber if (i >= CMDIF_TIMEOUT) { 893109a9638SPeter Gruber err = -EBUSY; 894109a9638SPeter Gruber goto errout; 895109a9638SPeter Gruber } 896109a9638SPeter Gruber 897109a9638SPeter Gruber err = 0; 898109a9638SPeter Gruber for (j = 0, time = 0; time < CMDIF_TIMEOUT; j++, time += 2) { 899109a9638SPeter Gruber cmdport = &(hwport->port[j % 2]); 900109a9638SPeter Gruber if (IS_DATF(cmdport)) { /* free pending data */ 901109a9638SPeter Gruber READ_PORT_ULONG(cmdport->data1); 902109a9638SPeter Gruber READ_PORT_ULONG(cmdport->data2); 903109a9638SPeter Gruber } 904109a9638SPeter Gruber if (IS_CMDE(cmdport)) { 905109a9638SPeter Gruber if (flags & PARM) /* put data */ 906109a9638SPeter Gruber WRITE_PORT_ULONG(cmdport->data2, parm); 907109a9638SPeter Gruber WRITE_PORT_ULONG(cmdport->data1, cmd); /* write cmd */ 908109a9638SPeter Gruber if ((flags & RESP) && ret) { 909109a9638SPeter Gruber while (!IS_DATF(cmdport) && 910109a9638SPeter Gruber time++ < CMDIF_TIMEOUT) 911109a9638SPeter Gruber udelay(10); 912109a9638SPeter Gruber if (time < CMDIF_TIMEOUT) { /* read response */ 913109a9638SPeter Gruber ret->retlongs[0] = 914109a9638SPeter Gruber READ_PORT_ULONG(cmdport->data1); 915109a9638SPeter Gruber ret->retlongs[1] = 916109a9638SPeter Gruber READ_PORT_ULONG(cmdport->data2); 917109a9638SPeter Gruber } else { 918109a9638SPeter Gruber err = -ENOSYS; 919109a9638SPeter Gruber goto errout; 920109a9638SPeter Gruber } 921109a9638SPeter Gruber } 922109a9638SPeter Gruber break; 923109a9638SPeter Gruber } 924109a9638SPeter Gruber udelay(20); 925109a9638SPeter Gruber } 926109a9638SPeter Gruber if (time == CMDIF_TIMEOUT) { 927109a9638SPeter Gruber err = -ENODATA; 928109a9638SPeter Gruber goto errout; 929109a9638SPeter Gruber } 930109a9638SPeter Gruber spin_unlock_irqrestore(&cif->lock, irqflags); 931109a9638SPeter Gruber 932109a9638SPeter Gruber cif->cmdcnt++; /* update command statistics */ 933109a9638SPeter Gruber cif->cmdtime += time; 934109a9638SPeter Gruber if (time > cif->cmdtimemax) 935109a9638SPeter Gruber cif->cmdtimemax = time; 936109a9638SPeter Gruber if (time < cif->cmdtimemin) 937109a9638SPeter Gruber cif->cmdtimemin = time; 938109a9638SPeter Gruber if ((cif->cmdcnt) % 1000 == 0) 939109a9638SPeter Gruber snd_printdd 940109a9638SPeter Gruber ("send cmd %d time: %d mintime: %d maxtime %d err: %d\n", 941109a9638SPeter Gruber cif->cmdcnt, cif->cmdtime, cif->cmdtimemin, 942109a9638SPeter Gruber cif->cmdtimemax, cif->errcnt); 943109a9638SPeter Gruber return 0; 944109a9638SPeter Gruber 945109a9638SPeter Gruber errout: 946109a9638SPeter Gruber cif->errcnt++; 947109a9638SPeter Gruber spin_unlock_irqrestore(&cif->lock, irqflags); 948109a9638SPeter Gruber snd_printdd 949109a9638SPeter Gruber ("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", 950109a9638SPeter Gruber cif->cmdcnt, (int)((void *)&(cmdport->stat) - (void *)hwport), 951109a9638SPeter Gruber flags, cmd, parm, ret ? ret->retlongs[0] : 0, 952109a9638SPeter Gruber ret ? ret->retlongs[1] : 0, IS_CMDE(cmdport), IS_DATF(cmdport), 953109a9638SPeter Gruber err); 954109a9638SPeter Gruber return err; 955109a9638SPeter Gruber } 956109a9638SPeter Gruber 957109a9638SPeter Gruber static int 958109a9638SPeter Gruber setmixer(struct cmdif *cif, short num, unsigned short rval, unsigned short lval) 959109a9638SPeter Gruber { 960109a9638SPeter Gruber union cmdret rptr = CMDRET_ZERO; 961109a9638SPeter Gruber int i = 0; 962109a9638SPeter Gruber 963109a9638SPeter Gruber snd_printdd("sent mixer %d: 0x%d 0x%d\n", num, rval, lval); 964109a9638SPeter Gruber do { 965109a9638SPeter Gruber SEND_SDGV(cif, num, num, rval, lval); 966109a9638SPeter Gruber SEND_RDGV(cif, num, num, &rptr); 967109a9638SPeter Gruber if (rptr.retwords[0] == lval && rptr.retwords[1] == rval) 968109a9638SPeter Gruber return 0; 969109a9638SPeter Gruber } while (i++ < MAX_WRITE_RETRY); 970109a9638SPeter Gruber snd_printdd("sent mixer failed\n"); 971109a9638SPeter Gruber return -EIO; 972109a9638SPeter Gruber } 973109a9638SPeter Gruber 974109a9638SPeter Gruber static int getpaths(struct cmdif *cif, unsigned char *o) 975109a9638SPeter Gruber { 976109a9638SPeter Gruber unsigned char src[E2SINK_MAX]; 977109a9638SPeter Gruber unsigned char sink[E2SINK_MAX]; 978109a9638SPeter Gruber int i, j = 0; 979109a9638SPeter Gruber 980109a9638SPeter Gruber for (i = 0; i < E2SINK_MAX; i++) { 981109a9638SPeter Gruber getsourcesink(cif, i, i, &src[i], &sink[i]); 982109a9638SPeter Gruber if (sink[i] < E2SINK_MAX) { 983109a9638SPeter Gruber o[j++] = sink[i]; 984109a9638SPeter Gruber o[j++] = i; 985109a9638SPeter Gruber } 986109a9638SPeter Gruber } 987109a9638SPeter Gruber return j; 988109a9638SPeter Gruber } 989109a9638SPeter Gruber 990109a9638SPeter Gruber static int 991109a9638SPeter Gruber getsourcesink(struct cmdif *cif, unsigned char source, unsigned char sink, 992109a9638SPeter Gruber unsigned char *a, unsigned char *b) 993109a9638SPeter Gruber { 994109a9638SPeter Gruber union cmdret rptr = CMDRET_ZERO; 995109a9638SPeter Gruber 996109a9638SPeter Gruber if (SEND_RSSV(cif, source, sink, &rptr) && 997109a9638SPeter Gruber SEND_RSSV(cif, source, sink, &rptr)) 998109a9638SPeter Gruber return -EIO; 999109a9638SPeter Gruber *a = rptr.retbytes[0]; 1000109a9638SPeter Gruber *b = rptr.retbytes[1]; 1001109a9638SPeter Gruber snd_printdd("getsourcesink 0x%x 0x%x\n", *a, *b); 1002109a9638SPeter Gruber return 0; 1003109a9638SPeter Gruber } 1004109a9638SPeter Gruber 1005109a9638SPeter Gruber static int 1006109a9638SPeter Gruber getsamplerate(struct cmdif *cif, unsigned char *intdec, unsigned int *rate) 1007109a9638SPeter Gruber { 1008109a9638SPeter Gruber unsigned char *s; 1009109a9638SPeter Gruber unsigned int p[2] = { 0, 0 }; 1010109a9638SPeter Gruber int i; 1011109a9638SPeter Gruber union cmdret rptr = CMDRET_ZERO; 1012109a9638SPeter Gruber 1013109a9638SPeter Gruber s = intdec; 1014109a9638SPeter Gruber for (i = 0; i < 2; i++) { 1015109a9638SPeter Gruber if (*s != 0xff) { 1016109a9638SPeter Gruber if (SEND_RSRC(cif, *s, &rptr) && 1017109a9638SPeter Gruber SEND_RSRC(cif, *s, &rptr)) 1018109a9638SPeter Gruber return -EIO; 1019109a9638SPeter Gruber p[i] += rptr.retwords[1]; 1020109a9638SPeter Gruber p[i] *= rptr.retwords[2]; 1021109a9638SPeter Gruber p[i] += rptr.retwords[3]; 1022109a9638SPeter Gruber p[i] /= 65536; 1023109a9638SPeter Gruber } 1024109a9638SPeter Gruber s++; 1025109a9638SPeter Gruber } 1026109a9638SPeter Gruber if (p[0]) { 1027109a9638SPeter Gruber if (p[1] != p[0]) 1028109a9638SPeter Gruber snd_printdd("rates differ %d %d\n", p[0], p[1]); 1029109a9638SPeter Gruber *rate = (unsigned int)p[0]; 1030109a9638SPeter Gruber } else 1031109a9638SPeter Gruber *rate = (unsigned int)p[1]; 1032109a9638SPeter Gruber snd_printdd("getsampleformat %d %d %d\n", intdec[0], intdec[1], *rate); 1033109a9638SPeter Gruber return 0; 1034109a9638SPeter Gruber } 1035109a9638SPeter Gruber 1036109a9638SPeter Gruber static int 1037109a9638SPeter Gruber setsampleformat(struct cmdif *cif, 1038109a9638SPeter Gruber unsigned char mixer, unsigned char id, 1039109a9638SPeter Gruber unsigned char channels, unsigned char format) 1040109a9638SPeter Gruber { 1041109a9638SPeter Gruber unsigned char w, ch, sig, order; 1042109a9638SPeter Gruber 1043109a9638SPeter Gruber snd_printdd 1044109a9638SPeter Gruber ("setsampleformat mixer: %d id: %d channels: %d format: %d\n", 1045109a9638SPeter Gruber mixer, id, channels, format); 1046109a9638SPeter Gruber ch = channels == 1; 1047109a9638SPeter Gruber w = snd_pcm_format_width(format) == 8; 1048109a9638SPeter Gruber sig = snd_pcm_format_unsigned(format) != 0; 1049109a9638SPeter Gruber order = snd_pcm_format_big_endian(format) != 0; 1050109a9638SPeter Gruber 1051109a9638SPeter Gruber if (SEND_SETF(cif, mixer, w, ch, order, sig, id) && 1052109a9638SPeter Gruber SEND_SETF(cif, mixer, w, ch, order, sig, id)) { 1053109a9638SPeter Gruber snd_printdd("setsampleformat failed\n"); 1054109a9638SPeter Gruber return -EIO; 1055109a9638SPeter Gruber } 1056109a9638SPeter Gruber return 0; 1057109a9638SPeter Gruber } 1058109a9638SPeter Gruber 1059109a9638SPeter Gruber static int 1060109a9638SPeter Gruber setsamplerate(struct cmdif *cif, unsigned char *intdec, unsigned int rate) 1061109a9638SPeter Gruber { 1062109a9638SPeter Gruber u32 D, M, N; 1063109a9638SPeter Gruber union cmdret rptr = CMDRET_ZERO; 1064109a9638SPeter Gruber int i; 1065109a9638SPeter Gruber 1066109a9638SPeter Gruber snd_printdd("setsamplerate intdec: %d,%d rate: %d\n", intdec[0], 1067109a9638SPeter Gruber intdec[1], rate); 1068109a9638SPeter Gruber D = 48000; 1069109a9638SPeter Gruber M = ((rate == 48000) ? 47999 : rate) * 65536; 1070109a9638SPeter Gruber N = M % D; 1071109a9638SPeter Gruber M /= D; 1072109a9638SPeter Gruber for (i = 0; i < 2; i++) { 1073109a9638SPeter Gruber if (*intdec != 0xff) { 1074109a9638SPeter Gruber do { 1075109a9638SPeter Gruber SEND_SSRC(cif, *intdec, D, M, N); 1076109a9638SPeter Gruber SEND_RSRC(cif, *intdec, &rptr); 1077109a9638SPeter Gruber } while (rptr.retwords[1] != D && 1078109a9638SPeter Gruber rptr.retwords[2] != M && 1079109a9638SPeter Gruber rptr.retwords[3] != N && 1080109a9638SPeter Gruber i++ < MAX_WRITE_RETRY); 1081109a9638SPeter Gruber if (i == MAX_WRITE_RETRY) { 1082109a9638SPeter Gruber snd_printdd("sent samplerate %d: %d failed\n", 1083109a9638SPeter Gruber *intdec, rate); 1084109a9638SPeter Gruber return -EIO; 1085109a9638SPeter Gruber } 1086109a9638SPeter Gruber } 1087109a9638SPeter Gruber intdec++; 1088109a9638SPeter Gruber } 1089109a9638SPeter Gruber return 0; 1090109a9638SPeter Gruber } 1091109a9638SPeter Gruber 1092109a9638SPeter Gruber static int 1093109a9638SPeter Gruber getmixer(struct cmdif *cif, short num, unsigned short *rval, 1094109a9638SPeter Gruber unsigned short *lval) 1095109a9638SPeter Gruber { 1096109a9638SPeter Gruber union cmdret rptr = CMDRET_ZERO; 1097109a9638SPeter Gruber 1098109a9638SPeter Gruber if (SEND_RDGV(cif, num, num, &rptr) && SEND_RDGV(cif, num, num, &rptr)) 1099109a9638SPeter Gruber return -EIO; 1100109a9638SPeter Gruber *rval = rptr.retwords[0]; 1101109a9638SPeter Gruber *lval = rptr.retwords[1]; 1102109a9638SPeter Gruber snd_printdd("got mixer %d: 0x%d 0x%d\n", num, *rval, *lval); 1103109a9638SPeter Gruber return 0; 1104109a9638SPeter Gruber } 1105109a9638SPeter Gruber 1106109a9638SPeter Gruber static void riptide_handleirq(unsigned long dev_id) 1107109a9638SPeter Gruber { 1108109a9638SPeter Gruber struct snd_riptide *chip = (void *)dev_id; 1109109a9638SPeter Gruber struct cmdif *cif = chip->cif; 1110109a9638SPeter Gruber struct snd_pcm_substream *substream[PLAYBACK_SUBSTREAMS + 1]; 1111109a9638SPeter Gruber struct snd_pcm_runtime *runtime; 1112109a9638SPeter Gruber struct pcmhw *data = NULL; 1113109a9638SPeter Gruber unsigned int pos, period_bytes; 1114109a9638SPeter Gruber struct sgd *c; 1115109a9638SPeter Gruber int i, j; 1116109a9638SPeter Gruber unsigned int flag; 1117109a9638SPeter Gruber 1118109a9638SPeter Gruber if (!cif) 1119109a9638SPeter Gruber return; 1120109a9638SPeter Gruber 1121109a9638SPeter Gruber for (i = 0; i < PLAYBACK_SUBSTREAMS; i++) 1122109a9638SPeter Gruber substream[i] = chip->playback_substream[i]; 1123109a9638SPeter Gruber substream[i] = chip->capture_substream; 1124109a9638SPeter Gruber for (i = 0; i < PLAYBACK_SUBSTREAMS + 1; i++) { 1125109a9638SPeter Gruber if (substream[i] && 1126109a9638SPeter Gruber (runtime = substream[i]->runtime) && 1127109a9638SPeter Gruber (data = runtime->private_data) && data->state != ST_STOP) { 1128109a9638SPeter Gruber pos = 0; 1129109a9638SPeter Gruber for (j = 0; j < data->pages; j++) { 1130109a9638SPeter Gruber c = &data->sgdbuf[j]; 1131109a9638SPeter Gruber flag = le32_to_cpu(c->dwStat_Ctl); 1132109a9638SPeter Gruber if (flag & EOB_STATUS) 1133109a9638SPeter Gruber pos += le32_to_cpu(c->dwSegLen); 1134109a9638SPeter Gruber if (flag & EOC_STATUS) 1135109a9638SPeter Gruber pos += le32_to_cpu(c->dwSegLen); 1136109a9638SPeter Gruber if ((flag & EOS_STATUS) 1137109a9638SPeter Gruber && (data->state == ST_PLAY)) { 1138109a9638SPeter Gruber data->state = ST_STOP; 1139109a9638SPeter Gruber snd_printk(KERN_ERR 1140109a9638SPeter Gruber "Riptide: DMA stopped unexpectedly\n"); 1141109a9638SPeter Gruber } 1142109a9638SPeter Gruber c->dwStat_Ctl = 1143109a9638SPeter Gruber cpu_to_le32(flag & 1144109a9638SPeter Gruber ~(EOS_STATUS | EOB_STATUS | 1145109a9638SPeter Gruber EOC_STATUS)); 1146109a9638SPeter Gruber } 1147109a9638SPeter Gruber data->pointer += pos; 1148109a9638SPeter Gruber pos += data->oldpos; 1149109a9638SPeter Gruber if (data->state != ST_STOP) { 1150109a9638SPeter Gruber period_bytes = 1151109a9638SPeter Gruber frames_to_bytes(runtime, 1152109a9638SPeter Gruber runtime->period_size); 1153109a9638SPeter Gruber snd_printdd 1154109a9638SPeter Gruber ("interrupt 0x%x after 0x%lx of 0x%lx frames in period\n", 1155109a9638SPeter Gruber READ_AUDIO_STATUS(cif->hwport), 1156109a9638SPeter Gruber bytes_to_frames(runtime, pos), 1157109a9638SPeter Gruber runtime->period_size); 1158109a9638SPeter Gruber j = 0; 1159109a9638SPeter Gruber if (pos >= period_bytes) { 1160109a9638SPeter Gruber j++; 1161109a9638SPeter Gruber while (pos >= period_bytes) 1162109a9638SPeter Gruber pos -= period_bytes; 1163109a9638SPeter Gruber } 1164109a9638SPeter Gruber data->oldpos = pos; 1165109a9638SPeter Gruber if (j > 0) 1166109a9638SPeter Gruber snd_pcm_period_elapsed(substream[i]); 1167109a9638SPeter Gruber } 1168109a9638SPeter Gruber } 1169109a9638SPeter Gruber } 1170109a9638SPeter Gruber } 1171109a9638SPeter Gruber 1172109a9638SPeter Gruber #ifdef CONFIG_PM 1173109a9638SPeter Gruber static int riptide_suspend(struct pci_dev *pci, pm_message_t state) 1174109a9638SPeter Gruber { 1175109a9638SPeter Gruber struct snd_card *card = pci_get_drvdata(pci); 1176109a9638SPeter Gruber struct snd_riptide *chip = card->private_data; 1177109a9638SPeter Gruber 1178109a9638SPeter Gruber chip->in_suspend = 1; 1179109a9638SPeter Gruber snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 1180109a9638SPeter Gruber snd_pcm_suspend_all(chip->pcm); 1181109a9638SPeter Gruber snd_ac97_suspend(chip->ac97); 1182109a9638SPeter Gruber pci_disable_device(pci); 1183109a9638SPeter Gruber pci_save_state(pci); 118430b35399STakashi Iwai pci_set_power_state(pci, pci_choose_state(pci, state)); 1185109a9638SPeter Gruber return 0; 1186109a9638SPeter Gruber } 1187109a9638SPeter Gruber 1188109a9638SPeter Gruber static int riptide_resume(struct pci_dev *pci) 1189109a9638SPeter Gruber { 1190109a9638SPeter Gruber struct snd_card *card = pci_get_drvdata(pci); 1191109a9638SPeter Gruber struct snd_riptide *chip = card->private_data; 1192109a9638SPeter Gruber 1193109a9638SPeter Gruber pci_set_power_state(pci, PCI_D0); 119430b35399STakashi Iwai pci_restore_state(pci); 119530b35399STakashi Iwai if (pci_enable_device(pci) < 0) { 119630b35399STakashi Iwai printk(KERN_ERR "riptide: pci_enable_device failed, " 119730b35399STakashi Iwai "disabling device\n"); 119830b35399STakashi Iwai snd_card_disconnect(card); 119930b35399STakashi Iwai return -EIO; 120030b35399STakashi Iwai } 1201109a9638SPeter Gruber pci_set_master(pci); 1202109a9638SPeter Gruber snd_riptide_initialize(chip); 1203109a9638SPeter Gruber snd_ac97_resume(chip->ac97); 1204109a9638SPeter Gruber snd_power_change_state(card, SNDRV_CTL_POWER_D0); 1205109a9638SPeter Gruber chip->in_suspend = 0; 1206109a9638SPeter Gruber return 0; 1207109a9638SPeter Gruber } 1208109a9638SPeter Gruber #endif 1209109a9638SPeter Gruber 1210109a9638SPeter Gruber static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip) 1211109a9638SPeter Gruber { 1212109a9638SPeter Gruber int timeout, tries; 1213109a9638SPeter Gruber union cmdret rptr = CMDRET_ZERO; 1214109a9638SPeter Gruber union firmware_version firmware; 1215109a9638SPeter Gruber int i, j, err, has_firmware; 1216109a9638SPeter Gruber 1217109a9638SPeter Gruber if (!cif) 1218109a9638SPeter Gruber return -EINVAL; 1219109a9638SPeter Gruber 1220109a9638SPeter Gruber cif->cmdcnt = 0; 1221109a9638SPeter Gruber cif->cmdtime = 0; 1222109a9638SPeter Gruber cif->cmdtimemax = 0; 1223109a9638SPeter Gruber cif->cmdtimemin = 0xffffffff; 1224109a9638SPeter Gruber cif->errcnt = 0; 1225109a9638SPeter Gruber cif->is_reset = 0; 1226109a9638SPeter Gruber 1227109a9638SPeter Gruber tries = RESET_TRIES; 1228109a9638SPeter Gruber has_firmware = 0; 1229109a9638SPeter Gruber while (has_firmware == 0 && tries-- > 0) { 1230109a9638SPeter Gruber for (i = 0; i < 2; i++) { 1231109a9638SPeter Gruber WRITE_PORT_ULONG(cif->hwport->port[i].data1, 0); 1232109a9638SPeter Gruber WRITE_PORT_ULONG(cif->hwport->port[i].data2, 0); 1233109a9638SPeter Gruber } 1234109a9638SPeter Gruber SET_GRESET(cif->hwport); 1235109a9638SPeter Gruber udelay(100); 1236109a9638SPeter Gruber UNSET_GRESET(cif->hwport); 1237109a9638SPeter Gruber udelay(100); 1238109a9638SPeter Gruber 1239109a9638SPeter Gruber for (timeout = 100000; --timeout; udelay(10)) { 1240109a9638SPeter Gruber if (IS_READY(cif->hwport) && !IS_GERR(cif->hwport)) 1241109a9638SPeter Gruber break; 1242109a9638SPeter Gruber } 1243109a9638SPeter Gruber if (timeout == 0) { 1244109a9638SPeter Gruber snd_printk(KERN_ERR 1245109a9638SPeter Gruber "Riptide: device not ready, audio status: 0x%x ready: %d gerr: %d\n", 1246109a9638SPeter Gruber READ_AUDIO_STATUS(cif->hwport), 1247109a9638SPeter Gruber IS_READY(cif->hwport), IS_GERR(cif->hwport)); 1248109a9638SPeter Gruber return -EIO; 1249109a9638SPeter Gruber } else { 1250109a9638SPeter Gruber snd_printdd 1251109a9638SPeter Gruber ("Riptide: audio status: 0x%x ready: %d gerr: %d\n", 1252109a9638SPeter Gruber READ_AUDIO_STATUS(cif->hwport), 1253109a9638SPeter Gruber IS_READY(cif->hwport), IS_GERR(cif->hwport)); 1254109a9638SPeter Gruber } 1255109a9638SPeter Gruber 1256109a9638SPeter Gruber SEND_GETV(cif, &rptr); 1257109a9638SPeter Gruber for (i = 0; i < 4; i++) 1258109a9638SPeter Gruber firmware.ret.retwords[i] = rptr.retwords[i]; 1259109a9638SPeter Gruber 1260109a9638SPeter Gruber snd_printdd 1261109a9638SPeter Gruber ("Firmware version: ASIC: %d CODEC %d AUXDSP %d PROG %d\n", 1262109a9638SPeter Gruber firmware.firmware.ASIC, firmware.firmware.CODEC, 1263109a9638SPeter Gruber firmware.firmware.AUXDSP, firmware.firmware.PROG); 1264109a9638SPeter Gruber 1265109a9638SPeter Gruber for (j = 0; j < FIRMWARE_VERSIONS; j++) { 1266109a9638SPeter Gruber has_firmware = 1; 1267109a9638SPeter Gruber for (i = 0; i < 4; i++) { 1268109a9638SPeter Gruber if (firmware_versions[j].ret.retwords[i] != 1269109a9638SPeter Gruber firmware.ret.retwords[i]) 1270109a9638SPeter Gruber has_firmware = 0; 1271109a9638SPeter Gruber } 1272109a9638SPeter Gruber if (has_firmware) 1273109a9638SPeter Gruber break; 1274109a9638SPeter Gruber } 1275109a9638SPeter Gruber 1276109a9638SPeter Gruber if (chip != NULL && has_firmware == 0) { 1277109a9638SPeter Gruber snd_printdd("Writing Firmware\n"); 1278109a9638SPeter Gruber if (!chip->fw_entry) { 1279109a9638SPeter Gruber if ((err = 1280109a9638SPeter Gruber request_firmware(&chip->fw_entry, 1281109a9638SPeter Gruber "riptide.hex", 1282109a9638SPeter Gruber &chip->pci->dev)) != 0) { 1283109a9638SPeter Gruber snd_printk(KERN_ERR 1284109a9638SPeter Gruber "Riptide: Firmware not available %d\n", 1285109a9638SPeter Gruber err); 1286109a9638SPeter Gruber return -EIO; 1287109a9638SPeter Gruber } 1288109a9638SPeter Gruber } 1289109a9638SPeter Gruber err = loadfirmware(cif, chip->fw_entry->data, 1290109a9638SPeter Gruber chip->fw_entry->size); 1291109a9638SPeter Gruber if (err) 1292109a9638SPeter Gruber snd_printk(KERN_ERR 1293109a9638SPeter Gruber "Riptide: Could not load firmware %d\n", 1294109a9638SPeter Gruber err); 1295109a9638SPeter Gruber } 1296109a9638SPeter Gruber } 1297109a9638SPeter Gruber 1298109a9638SPeter Gruber SEND_SACR(cif, 0, AC97_RESET); 1299109a9638SPeter Gruber SEND_RACR(cif, AC97_RESET, &rptr); 1300109a9638SPeter Gruber snd_printdd("AC97: 0x%x 0x%x\n", rptr.retlongs[0], rptr.retlongs[1]); 1301109a9638SPeter Gruber 1302109a9638SPeter Gruber SEND_PLST(cif, 0); 1303109a9638SPeter Gruber SEND_SLST(cif, 0); 1304109a9638SPeter Gruber SEND_DLST(cif, 0); 1305109a9638SPeter Gruber SEND_ALST(cif, 0); 1306109a9638SPeter Gruber SEND_KDMA(cif); 1307109a9638SPeter Gruber 1308109a9638SPeter Gruber writearm(cif, 0x301F8, 1, 1); 1309109a9638SPeter Gruber writearm(cif, 0x301F4, 1, 1); 1310109a9638SPeter Gruber 1311109a9638SPeter Gruber SEND_LSEL(cif, MODEM_CMD, 0, 0, MODEM_INTDEC, MODEM_MERGER, 1312109a9638SPeter Gruber MODEM_SPLITTER, MODEM_MIXER); 1313109a9638SPeter Gruber setmixer(cif, MODEM_MIXER, 0x7fff, 0x7fff); 1314109a9638SPeter Gruber alloclbuspath(cif, ARM2LBUS_FIFO13, lbus_play_modem, NULL, NULL); 1315109a9638SPeter Gruber 1316109a9638SPeter Gruber SEND_LSEL(cif, FM_CMD, 0, 0, FM_INTDEC, FM_MERGER, FM_SPLITTER, 1317109a9638SPeter Gruber FM_MIXER); 1318109a9638SPeter Gruber setmixer(cif, FM_MIXER, 0x7fff, 0x7fff); 1319109a9638SPeter Gruber writearm(cif, 0x30648 + FM_MIXER * 4, 0x01, 0x00000005); 1320109a9638SPeter Gruber writearm(cif, 0x301A8, 0x02, 0x00000002); 1321109a9638SPeter Gruber writearm(cif, 0x30264, 0x08, 0xffffffff); 1322109a9638SPeter Gruber alloclbuspath(cif, OPL3_SAMPLE, lbus_play_opl3, NULL, NULL); 1323109a9638SPeter Gruber 1324109a9638SPeter Gruber SEND_SSRC(cif, I2S_INTDEC, 48000, 1325109a9638SPeter Gruber ((u32) I2S_RATE * 65536) / 48000, 1326109a9638SPeter Gruber ((u32) I2S_RATE * 65536) % 48000); 1327109a9638SPeter Gruber SEND_LSEL(cif, I2S_CMD0, 0, 0, I2S_INTDEC, I2S_MERGER, I2S_SPLITTER, 1328109a9638SPeter Gruber I2S_MIXER); 1329109a9638SPeter Gruber SEND_SI2S(cif, 1); 1330109a9638SPeter Gruber alloclbuspath(cif, ARM2LBUS_FIFO0, lbus_play_i2s, NULL, NULL); 1331109a9638SPeter Gruber alloclbuspath(cif, DIGITAL_MIXER_OUT0, lbus_play_out, NULL, NULL); 1332109a9638SPeter Gruber alloclbuspath(cif, DIGITAL_MIXER_OUT0, lbus_play_outhp, NULL, NULL); 1333109a9638SPeter Gruber 1334109a9638SPeter Gruber SET_AIACK(cif->hwport); 1335109a9638SPeter Gruber SET_AIE(cif->hwport); 1336109a9638SPeter Gruber SET_AIACK(cif->hwport); 1337109a9638SPeter Gruber cif->is_reset = 1; 1338109a9638SPeter Gruber if (chip) { 1339109a9638SPeter Gruber for (i = 0; i < 4; i++) 1340109a9638SPeter Gruber chip->firmware.ret.retwords[i] = 1341109a9638SPeter Gruber firmware.ret.retwords[i]; 1342109a9638SPeter Gruber } 1343109a9638SPeter Gruber 1344109a9638SPeter Gruber return 0; 1345109a9638SPeter Gruber } 1346109a9638SPeter Gruber 1347109a9638SPeter Gruber static struct snd_pcm_hardware snd_riptide_playback = { 1348109a9638SPeter Gruber .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 1349109a9638SPeter Gruber SNDRV_PCM_INFO_BLOCK_TRANSFER | 1350109a9638SPeter Gruber SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID), 1351109a9638SPeter Gruber .formats = 1352109a9638SPeter Gruber SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 1353109a9638SPeter Gruber | SNDRV_PCM_FMTBIT_U16_LE, 1354109a9638SPeter Gruber .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000, 1355109a9638SPeter Gruber .rate_min = 5500, 1356109a9638SPeter Gruber .rate_max = 48000, 1357109a9638SPeter Gruber .channels_min = 1, 1358109a9638SPeter Gruber .channels_max = 2, 1359109a9638SPeter Gruber .buffer_bytes_max = (64 * 1024), 1360109a9638SPeter Gruber .period_bytes_min = PAGE_SIZE >> 1, 1361109a9638SPeter Gruber .period_bytes_max = PAGE_SIZE << 8, 1362109a9638SPeter Gruber .periods_min = 2, 1363109a9638SPeter Gruber .periods_max = 64, 1364109a9638SPeter Gruber .fifo_size = 0, 1365109a9638SPeter Gruber }; 1366109a9638SPeter Gruber static struct snd_pcm_hardware snd_riptide_capture = { 1367109a9638SPeter Gruber .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 1368109a9638SPeter Gruber SNDRV_PCM_INFO_BLOCK_TRANSFER | 1369109a9638SPeter Gruber SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID), 1370109a9638SPeter Gruber .formats = 1371109a9638SPeter Gruber SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 1372109a9638SPeter Gruber | SNDRV_PCM_FMTBIT_U16_LE, 1373109a9638SPeter Gruber .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000, 1374109a9638SPeter Gruber .rate_min = 5500, 1375109a9638SPeter Gruber .rate_max = 48000, 1376109a9638SPeter Gruber .channels_min = 1, 1377109a9638SPeter Gruber .channels_max = 2, 1378109a9638SPeter Gruber .buffer_bytes_max = (64 * 1024), 1379109a9638SPeter Gruber .period_bytes_min = PAGE_SIZE >> 1, 1380109a9638SPeter Gruber .period_bytes_max = PAGE_SIZE << 3, 1381109a9638SPeter Gruber .periods_min = 2, 1382109a9638SPeter Gruber .periods_max = 64, 1383109a9638SPeter Gruber .fifo_size = 0, 1384109a9638SPeter Gruber }; 1385109a9638SPeter Gruber 1386109a9638SPeter Gruber static snd_pcm_uframes_t snd_riptide_pointer(struct snd_pcm_substream 1387109a9638SPeter Gruber *substream) 1388109a9638SPeter Gruber { 1389109a9638SPeter Gruber struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1390109a9638SPeter Gruber struct snd_pcm_runtime *runtime = substream->runtime; 1391109a9638SPeter Gruber struct pcmhw *data = get_pcmhwdev(substream); 1392109a9638SPeter Gruber struct cmdif *cif = chip->cif; 1393109a9638SPeter Gruber union cmdret rptr = CMDRET_ZERO; 1394109a9638SPeter Gruber snd_pcm_uframes_t ret; 1395109a9638SPeter Gruber 1396109a9638SPeter Gruber SEND_GPOS(cif, 0, data->id, &rptr); 1397109a9638SPeter Gruber if (data->size && runtime->period_size) { 1398109a9638SPeter Gruber snd_printdd 1399109a9638SPeter Gruber ("pointer stream %d position 0x%x(0x%x in buffer) bytes 0x%lx(0x%lx in period) frames\n", 1400109a9638SPeter Gruber data->id, rptr.retlongs[1], rptr.retlongs[1] % data->size, 1401109a9638SPeter Gruber bytes_to_frames(runtime, rptr.retlongs[1]), 1402109a9638SPeter Gruber bytes_to_frames(runtime, 1403109a9638SPeter Gruber rptr.retlongs[1]) % runtime->period_size); 1404109a9638SPeter Gruber if (rptr.retlongs[1] > data->pointer) 1405109a9638SPeter Gruber ret = 1406109a9638SPeter Gruber bytes_to_frames(runtime, 1407109a9638SPeter Gruber rptr.retlongs[1] % data->size); 1408109a9638SPeter Gruber else 1409109a9638SPeter Gruber ret = 1410109a9638SPeter Gruber bytes_to_frames(runtime, 1411109a9638SPeter Gruber data->pointer % data->size); 1412109a9638SPeter Gruber } else { 1413109a9638SPeter Gruber snd_printdd("stream not started or strange parms (%d %ld)\n", 1414109a9638SPeter Gruber data->size, runtime->period_size); 1415109a9638SPeter Gruber ret = bytes_to_frames(runtime, 0); 1416109a9638SPeter Gruber } 1417109a9638SPeter Gruber return ret; 1418109a9638SPeter Gruber } 1419109a9638SPeter Gruber 1420109a9638SPeter Gruber static int snd_riptide_trigger(struct snd_pcm_substream *substream, int cmd) 1421109a9638SPeter Gruber { 1422109a9638SPeter Gruber int i, j; 1423109a9638SPeter Gruber struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1424109a9638SPeter Gruber struct pcmhw *data = get_pcmhwdev(substream); 1425109a9638SPeter Gruber struct cmdif *cif = chip->cif; 1426109a9638SPeter Gruber union cmdret rptr = CMDRET_ZERO; 1427109a9638SPeter Gruber 1428109a9638SPeter Gruber spin_lock(&chip->lock); 1429109a9638SPeter Gruber switch (cmd) { 1430109a9638SPeter Gruber case SNDRV_PCM_TRIGGER_START: 1431109a9638SPeter Gruber case SNDRV_PCM_TRIGGER_RESUME: 1432109a9638SPeter Gruber if (!(data->state & ST_PLAY)) { 1433109a9638SPeter Gruber SEND_SSTR(cif, data->id, data->sgdlist.addr); 1434109a9638SPeter Gruber SET_AIE(cif->hwport); 1435109a9638SPeter Gruber data->state = ST_PLAY; 1436109a9638SPeter Gruber if (data->mixer != 0xff) 1437109a9638SPeter Gruber setmixer(cif, data->mixer, 0x7fff, 0x7fff); 1438109a9638SPeter Gruber chip->openstreams++; 1439109a9638SPeter Gruber data->oldpos = 0; 1440109a9638SPeter Gruber data->pointer = 0; 1441109a9638SPeter Gruber } 1442109a9638SPeter Gruber break; 1443109a9638SPeter Gruber case SNDRV_PCM_TRIGGER_STOP: 1444109a9638SPeter Gruber case SNDRV_PCM_TRIGGER_SUSPEND: 1445109a9638SPeter Gruber if (data->mixer != 0xff) 1446109a9638SPeter Gruber setmixer(cif, data->mixer, 0, 0); 1447109a9638SPeter Gruber setmixer(cif, data->mixer, 0, 0); 1448109a9638SPeter Gruber SEND_KSTR(cif, data->id); 1449109a9638SPeter Gruber data->state = ST_STOP; 1450109a9638SPeter Gruber chip->openstreams--; 1451109a9638SPeter Gruber j = 0; 1452109a9638SPeter Gruber do { 1453109a9638SPeter Gruber i = rptr.retlongs[1]; 1454109a9638SPeter Gruber SEND_GPOS(cif, 0, data->id, &rptr); 1455109a9638SPeter Gruber udelay(1); 1456109a9638SPeter Gruber } while (i != rptr.retlongs[1] && j++ < MAX_WRITE_RETRY); 1457109a9638SPeter Gruber if (j >= MAX_WRITE_RETRY) 1458109a9638SPeter Gruber snd_printk(KERN_ERR "Riptide: Could not stop stream!"); 1459109a9638SPeter Gruber break; 1460109a9638SPeter Gruber case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 1461109a9638SPeter Gruber if (!(data->state & ST_PAUSE)) { 1462109a9638SPeter Gruber SEND_PSTR(cif, data->id); 1463109a9638SPeter Gruber data->state |= ST_PAUSE; 1464109a9638SPeter Gruber chip->openstreams--; 1465109a9638SPeter Gruber } 1466109a9638SPeter Gruber break; 1467109a9638SPeter Gruber case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 1468109a9638SPeter Gruber if (data->state & ST_PAUSE) { 1469109a9638SPeter Gruber SEND_SSTR(cif, data->id, data->sgdlist.addr); 1470109a9638SPeter Gruber data->state &= ~ST_PAUSE; 1471109a9638SPeter Gruber chip->openstreams++; 1472109a9638SPeter Gruber } 1473109a9638SPeter Gruber break; 1474109a9638SPeter Gruber default: 1475109a9638SPeter Gruber spin_unlock(&chip->lock); 1476109a9638SPeter Gruber return -EINVAL; 1477109a9638SPeter Gruber } 1478109a9638SPeter Gruber spin_unlock(&chip->lock); 1479109a9638SPeter Gruber return 0; 1480109a9638SPeter Gruber } 1481109a9638SPeter Gruber 1482109a9638SPeter Gruber static int snd_riptide_prepare(struct snd_pcm_substream *substream) 1483109a9638SPeter Gruber { 1484109a9638SPeter Gruber struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1485109a9638SPeter Gruber struct snd_pcm_runtime *runtime = substream->runtime; 1486109a9638SPeter Gruber struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream); 1487109a9638SPeter Gruber struct pcmhw *data = get_pcmhwdev(substream); 1488109a9638SPeter Gruber struct cmdif *cif = chip->cif; 1489109a9638SPeter Gruber unsigned char *lbuspath = NULL; 1490109a9638SPeter Gruber unsigned int rate, channels; 1491109a9638SPeter Gruber int err = 0; 1492109a9638SPeter Gruber snd_pcm_format_t format; 1493109a9638SPeter Gruber 1494109a9638SPeter Gruber snd_assert(cif && data, return -EINVAL); 1495109a9638SPeter Gruber 1496109a9638SPeter Gruber snd_printdd("prepare id %d ch: %d f:0x%x r:%d\n", data->id, 1497109a9638SPeter Gruber runtime->channels, runtime->format, runtime->rate); 1498109a9638SPeter Gruber 1499109a9638SPeter Gruber spin_lock_irq(&chip->lock); 1500109a9638SPeter Gruber channels = runtime->channels; 1501109a9638SPeter Gruber format = runtime->format; 1502109a9638SPeter Gruber rate = runtime->rate; 1503109a9638SPeter Gruber switch (channels) { 1504109a9638SPeter Gruber case 1: 1505109a9638SPeter Gruber if (rate == 48000 && format == SNDRV_PCM_FORMAT_S16_LE) 1506109a9638SPeter Gruber lbuspath = data->paths.noconv; 1507109a9638SPeter Gruber else 1508109a9638SPeter Gruber lbuspath = data->paths.mono; 1509109a9638SPeter Gruber break; 1510109a9638SPeter Gruber case 2: 1511109a9638SPeter Gruber if (rate == 48000 && format == SNDRV_PCM_FORMAT_S16_LE) 1512109a9638SPeter Gruber lbuspath = data->paths.noconv; 1513109a9638SPeter Gruber else 1514109a9638SPeter Gruber lbuspath = data->paths.stereo; 1515109a9638SPeter Gruber break; 1516109a9638SPeter Gruber } 1517109a9638SPeter Gruber snd_printdd("use sgdlist at 0x%p and buffer at 0x%p\n", 1518109a9638SPeter Gruber data->sgdlist.area, sgbuf); 1519109a9638SPeter Gruber if (data->sgdlist.area && sgbuf) { 1520109a9638SPeter Gruber unsigned int i, j, size, pages, f, pt, period; 1521109a9638SPeter Gruber struct sgd *c, *p = NULL; 1522109a9638SPeter Gruber 1523109a9638SPeter Gruber size = frames_to_bytes(runtime, runtime->buffer_size); 1524109a9638SPeter Gruber period = frames_to_bytes(runtime, runtime->period_size); 1525109a9638SPeter Gruber f = PAGE_SIZE; 1526109a9638SPeter Gruber while ((size + (f >> 1) - 1) <= (f << 7) && (f << 1) > period) 1527109a9638SPeter Gruber f = f >> 1; 1528109a9638SPeter Gruber pages = (size + f - 1) / f; 1529109a9638SPeter Gruber data->size = size; 1530109a9638SPeter Gruber data->pages = pages; 1531109a9638SPeter Gruber snd_printdd 1532109a9638SPeter Gruber ("create sgd size: 0x%x pages %d of size 0x%x for period 0x%x\n", 1533109a9638SPeter Gruber size, pages, f, period); 1534109a9638SPeter Gruber pt = 0; 1535109a9638SPeter Gruber j = 0; 1536109a9638SPeter Gruber for (i = 0; i < pages; i++) { 1537109a9638SPeter Gruber c = &data->sgdbuf[i]; 1538109a9638SPeter Gruber if (p) 1539109a9638SPeter Gruber p->dwNextLink = cpu_to_le32(data->sgdlist.addr + 1540109a9638SPeter Gruber (i * 1541109a9638SPeter Gruber sizeof(struct 1542109a9638SPeter Gruber sgd))); 1543109a9638SPeter Gruber c->dwNextLink = cpu_to_le32(data->sgdlist.addr); 1544109a9638SPeter Gruber c->dwSegPtrPhys = 1545109a9638SPeter Gruber cpu_to_le32(sgbuf->table[j].addr + pt); 1546109a9638SPeter Gruber pt = (pt + f) % PAGE_SIZE; 1547109a9638SPeter Gruber if (pt == 0) 1548109a9638SPeter Gruber j++; 1549109a9638SPeter Gruber c->dwSegLen = cpu_to_le32(f); 1550109a9638SPeter Gruber c->dwStat_Ctl = 1551109a9638SPeter Gruber cpu_to_le32(IEOB_ENABLE | IEOS_ENABLE | 1552109a9638SPeter Gruber IEOC_ENABLE); 1553109a9638SPeter Gruber p = c; 1554109a9638SPeter Gruber size -= f; 1555109a9638SPeter Gruber } 1556109a9638SPeter Gruber data->sgdbuf[i].dwSegLen = cpu_to_le32(size); 1557109a9638SPeter Gruber } 1558109a9638SPeter Gruber if (lbuspath && lbuspath != data->lbuspath) { 1559109a9638SPeter Gruber if (data->lbuspath) 1560109a9638SPeter Gruber freelbuspath(cif, data->source, data->lbuspath); 1561109a9638SPeter Gruber alloclbuspath(cif, data->source, lbuspath, 1562109a9638SPeter Gruber &data->mixer, data->intdec); 1563109a9638SPeter Gruber data->lbuspath = lbuspath; 1564109a9638SPeter Gruber data->rate = 0; 1565109a9638SPeter Gruber } 1566109a9638SPeter Gruber if (data->rate != rate || data->format != format || 1567109a9638SPeter Gruber data->channels != channels) { 1568109a9638SPeter Gruber data->rate = rate; 1569109a9638SPeter Gruber data->format = format; 1570109a9638SPeter Gruber data->channels = channels; 1571109a9638SPeter Gruber if (setsampleformat 1572109a9638SPeter Gruber (cif, data->mixer, data->id, channels, format) 1573109a9638SPeter Gruber || setsamplerate(cif, data->intdec, rate)) 1574109a9638SPeter Gruber err = -EIO; 1575109a9638SPeter Gruber } 1576109a9638SPeter Gruber spin_unlock_irq(&chip->lock); 1577109a9638SPeter Gruber return err; 1578109a9638SPeter Gruber } 1579109a9638SPeter Gruber 1580109a9638SPeter Gruber static int 1581109a9638SPeter Gruber snd_riptide_hw_params(struct snd_pcm_substream *substream, 1582109a9638SPeter Gruber struct snd_pcm_hw_params *hw_params) 1583109a9638SPeter Gruber { 1584109a9638SPeter Gruber struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1585109a9638SPeter Gruber struct pcmhw *data = get_pcmhwdev(substream); 1586109a9638SPeter Gruber struct snd_dma_buffer *sgdlist = &data->sgdlist; 1587109a9638SPeter Gruber int err; 1588109a9638SPeter Gruber 1589109a9638SPeter Gruber snd_printdd("hw params id %d (sgdlist: 0x%p 0x%lx %d)\n", data->id, 1590109a9638SPeter Gruber sgdlist->area, (unsigned long)sgdlist->addr, 1591109a9638SPeter Gruber (int)sgdlist->bytes); 1592109a9638SPeter Gruber if (sgdlist->area) 1593109a9638SPeter Gruber snd_dma_free_pages(sgdlist); 1594109a9638SPeter Gruber if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, 1595109a9638SPeter Gruber snd_dma_pci_data(chip->pci), 1596109a9638SPeter Gruber sizeof(struct sgd) * (DESC_MAX_MASK + 1), 1597109a9638SPeter Gruber sgdlist)) < 0) { 1598109a9638SPeter Gruber snd_printk(KERN_ERR "Riptide: failed to alloc %d dma bytes\n", 1599109a9638SPeter Gruber (int)sizeof(struct sgd) * (DESC_MAX_MASK + 1)); 1600109a9638SPeter Gruber return err; 1601109a9638SPeter Gruber } 1602109a9638SPeter Gruber data->sgdbuf = (struct sgd *)sgdlist->area; 1603109a9638SPeter Gruber return snd_pcm_lib_malloc_pages(substream, 1604109a9638SPeter Gruber params_buffer_bytes(hw_params)); 1605109a9638SPeter Gruber } 1606109a9638SPeter Gruber 1607109a9638SPeter Gruber static int snd_riptide_hw_free(struct snd_pcm_substream *substream) 1608109a9638SPeter Gruber { 1609109a9638SPeter Gruber struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1610109a9638SPeter Gruber struct pcmhw *data = get_pcmhwdev(substream); 1611109a9638SPeter Gruber struct cmdif *cif = chip->cif; 1612109a9638SPeter Gruber 1613109a9638SPeter Gruber if (cif && data) { 1614109a9638SPeter Gruber if (data->lbuspath) 1615109a9638SPeter Gruber freelbuspath(cif, data->source, data->lbuspath); 1616109a9638SPeter Gruber data->lbuspath = NULL; 1617109a9638SPeter Gruber data->source = 0xff; 1618109a9638SPeter Gruber data->intdec[0] = 0xff; 1619109a9638SPeter Gruber data->intdec[1] = 0xff; 1620109a9638SPeter Gruber 1621109a9638SPeter Gruber if (data->sgdlist.area) { 1622109a9638SPeter Gruber snd_dma_free_pages(&data->sgdlist); 1623109a9638SPeter Gruber data->sgdlist.area = NULL; 1624109a9638SPeter Gruber } 1625109a9638SPeter Gruber } 1626109a9638SPeter Gruber return snd_pcm_lib_free_pages(substream); 1627109a9638SPeter Gruber } 1628109a9638SPeter Gruber 1629109a9638SPeter Gruber static int snd_riptide_playback_open(struct snd_pcm_substream *substream) 1630109a9638SPeter Gruber { 1631109a9638SPeter Gruber struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1632109a9638SPeter Gruber struct snd_pcm_runtime *runtime = substream->runtime; 1633109a9638SPeter Gruber struct pcmhw *data; 1634109a9638SPeter Gruber int index = substream->number; 1635109a9638SPeter Gruber 1636109a9638SPeter Gruber chip->playback_substream[index] = substream; 1637109a9638SPeter Gruber runtime->hw = snd_riptide_playback; 1638109a9638SPeter Gruber data = kzalloc(sizeof(struct pcmhw), GFP_KERNEL); 1639109a9638SPeter Gruber data->paths = lbus_play_paths[index]; 1640109a9638SPeter Gruber data->id = play_ids[index]; 1641109a9638SPeter Gruber data->source = play_sources[index]; 1642109a9638SPeter Gruber data->intdec[0] = 0xff; 1643109a9638SPeter Gruber data->intdec[1] = 0xff; 1644109a9638SPeter Gruber data->state = ST_STOP; 1645109a9638SPeter Gruber runtime->private_data = data; 1646109a9638SPeter Gruber return snd_pcm_hw_constraint_integer(runtime, 1647109a9638SPeter Gruber SNDRV_PCM_HW_PARAM_PERIODS); 1648109a9638SPeter Gruber } 1649109a9638SPeter Gruber 1650109a9638SPeter Gruber static int snd_riptide_capture_open(struct snd_pcm_substream *substream) 1651109a9638SPeter Gruber { 1652109a9638SPeter Gruber struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1653109a9638SPeter Gruber struct snd_pcm_runtime *runtime = substream->runtime; 1654109a9638SPeter Gruber struct pcmhw *data; 1655109a9638SPeter Gruber 1656109a9638SPeter Gruber chip->capture_substream = substream; 1657109a9638SPeter Gruber runtime->hw = snd_riptide_capture; 1658109a9638SPeter Gruber data = kzalloc(sizeof(struct pcmhw), GFP_KERNEL); 1659109a9638SPeter Gruber data->paths = lbus_rec_path; 1660109a9638SPeter Gruber data->id = PADC; 1661109a9638SPeter Gruber data->source = ACLNK2PADC; 1662109a9638SPeter Gruber data->intdec[0] = 0xff; 1663109a9638SPeter Gruber data->intdec[1] = 0xff; 1664109a9638SPeter Gruber data->state = ST_STOP; 1665109a9638SPeter Gruber runtime->private_data = data; 1666109a9638SPeter Gruber return snd_pcm_hw_constraint_integer(runtime, 1667109a9638SPeter Gruber SNDRV_PCM_HW_PARAM_PERIODS); 1668109a9638SPeter Gruber } 1669109a9638SPeter Gruber 1670109a9638SPeter Gruber static int snd_riptide_playback_close(struct snd_pcm_substream *substream) 1671109a9638SPeter Gruber { 1672109a9638SPeter Gruber struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1673109a9638SPeter Gruber struct pcmhw *data = get_pcmhwdev(substream); 1674109a9638SPeter Gruber int index = substream->number; 1675109a9638SPeter Gruber 1676109a9638SPeter Gruber substream->runtime->private_data = NULL; 1677109a9638SPeter Gruber chip->playback_substream[index] = NULL; 1678109a9638SPeter Gruber kfree(data); 1679109a9638SPeter Gruber return 0; 1680109a9638SPeter Gruber } 1681109a9638SPeter Gruber 1682109a9638SPeter Gruber static int snd_riptide_capture_close(struct snd_pcm_substream *substream) 1683109a9638SPeter Gruber { 1684109a9638SPeter Gruber struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1685109a9638SPeter Gruber struct pcmhw *data = get_pcmhwdev(substream); 1686109a9638SPeter Gruber 1687109a9638SPeter Gruber substream->runtime->private_data = NULL; 1688109a9638SPeter Gruber chip->capture_substream = NULL; 1689109a9638SPeter Gruber kfree(data); 1690109a9638SPeter Gruber return 0; 1691109a9638SPeter Gruber } 1692109a9638SPeter Gruber 1693109a9638SPeter Gruber static struct snd_pcm_ops snd_riptide_playback_ops = { 1694109a9638SPeter Gruber .open = snd_riptide_playback_open, 1695109a9638SPeter Gruber .close = snd_riptide_playback_close, 1696109a9638SPeter Gruber .ioctl = snd_pcm_lib_ioctl, 1697109a9638SPeter Gruber .hw_params = snd_riptide_hw_params, 1698109a9638SPeter Gruber .hw_free = snd_riptide_hw_free, 1699109a9638SPeter Gruber .prepare = snd_riptide_prepare, 1700109a9638SPeter Gruber .page = snd_pcm_sgbuf_ops_page, 1701109a9638SPeter Gruber .trigger = snd_riptide_trigger, 1702109a9638SPeter Gruber .pointer = snd_riptide_pointer, 1703109a9638SPeter Gruber }; 1704109a9638SPeter Gruber static struct snd_pcm_ops snd_riptide_capture_ops = { 1705109a9638SPeter Gruber .open = snd_riptide_capture_open, 1706109a9638SPeter Gruber .close = snd_riptide_capture_close, 1707109a9638SPeter Gruber .ioctl = snd_pcm_lib_ioctl, 1708109a9638SPeter Gruber .hw_params = snd_riptide_hw_params, 1709109a9638SPeter Gruber .hw_free = snd_riptide_hw_free, 1710109a9638SPeter Gruber .prepare = snd_riptide_prepare, 1711109a9638SPeter Gruber .page = snd_pcm_sgbuf_ops_page, 1712109a9638SPeter Gruber .trigger = snd_riptide_trigger, 1713109a9638SPeter Gruber .pointer = snd_riptide_pointer, 1714109a9638SPeter Gruber }; 1715109a9638SPeter Gruber 1716109a9638SPeter Gruber static int __devinit 1717109a9638SPeter Gruber snd_riptide_pcm(struct snd_riptide *chip, int device, struct snd_pcm **rpcm) 1718109a9638SPeter Gruber { 1719109a9638SPeter Gruber struct snd_pcm *pcm; 1720109a9638SPeter Gruber int err; 1721109a9638SPeter Gruber 1722109a9638SPeter Gruber if (rpcm) 1723109a9638SPeter Gruber *rpcm = NULL; 1724109a9638SPeter Gruber if ((err = 1725109a9638SPeter Gruber snd_pcm_new(chip->card, "RIPTIDE", device, PLAYBACK_SUBSTREAMS, 1, 1726109a9638SPeter Gruber &pcm)) < 0) 1727109a9638SPeter Gruber return err; 1728109a9638SPeter Gruber snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, 1729109a9638SPeter Gruber &snd_riptide_playback_ops); 1730109a9638SPeter Gruber snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 1731109a9638SPeter Gruber &snd_riptide_capture_ops); 1732109a9638SPeter Gruber pcm->private_data = chip; 1733109a9638SPeter Gruber pcm->info_flags = 0; 1734109a9638SPeter Gruber strcpy(pcm->name, "RIPTIDE"); 1735109a9638SPeter Gruber chip->pcm = pcm; 1736109a9638SPeter Gruber snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1737109a9638SPeter Gruber snd_dma_pci_data(chip->pci), 1738109a9638SPeter Gruber 64 * 1024, 128 * 1024); 1739109a9638SPeter Gruber if (rpcm) 1740109a9638SPeter Gruber *rpcm = pcm; 1741109a9638SPeter Gruber return 0; 1742109a9638SPeter Gruber } 1743109a9638SPeter Gruber 1744109a9638SPeter Gruber static irqreturn_t 17457d12e780SDavid Howells snd_riptide_interrupt(int irq, void *dev_id) 1746109a9638SPeter Gruber { 1747109a9638SPeter Gruber struct snd_riptide *chip = dev_id; 1748109a9638SPeter Gruber struct cmdif *cif = chip->cif; 1749109a9638SPeter Gruber 1750109a9638SPeter Gruber if (cif) { 1751109a9638SPeter Gruber chip->received_irqs++; 1752109a9638SPeter Gruber if (IS_EOBIRQ(cif->hwport) || IS_EOSIRQ(cif->hwport) || 1753109a9638SPeter Gruber IS_EOCIRQ(cif->hwport)) { 1754109a9638SPeter Gruber chip->handled_irqs++; 1755109a9638SPeter Gruber tasklet_hi_schedule(&chip->riptide_tq); 1756109a9638SPeter Gruber } 1757109a9638SPeter Gruber if (chip->rmidi && IS_MPUIRQ(cif->hwport)) { 1758109a9638SPeter Gruber chip->handled_irqs++; 1759109a9638SPeter Gruber snd_mpu401_uart_interrupt(irq, 17607d12e780SDavid Howells chip->rmidi->private_data); 1761109a9638SPeter Gruber } 1762109a9638SPeter Gruber SET_AIACK(cif->hwport); 1763109a9638SPeter Gruber } 1764109a9638SPeter Gruber return IRQ_HANDLED; 1765109a9638SPeter Gruber } 1766109a9638SPeter Gruber 1767109a9638SPeter Gruber static void 1768109a9638SPeter Gruber snd_riptide_codec_write(struct snd_ac97 *ac97, unsigned short reg, 1769109a9638SPeter Gruber unsigned short val) 1770109a9638SPeter Gruber { 1771109a9638SPeter Gruber struct snd_riptide *chip = ac97->private_data; 1772109a9638SPeter Gruber struct cmdif *cif = chip->cif; 1773109a9638SPeter Gruber union cmdret rptr = CMDRET_ZERO; 1774109a9638SPeter Gruber int i = 0; 1775109a9638SPeter Gruber 1776109a9638SPeter Gruber snd_assert(cif, return); 1777109a9638SPeter Gruber 1778109a9638SPeter Gruber snd_printdd("Write AC97 reg 0x%x 0x%x\n", reg, val); 1779109a9638SPeter Gruber do { 1780109a9638SPeter Gruber SEND_SACR(cif, val, reg); 1781109a9638SPeter Gruber SEND_RACR(cif, reg, &rptr); 1782109a9638SPeter Gruber } while (rptr.retwords[1] != val && i++ < MAX_WRITE_RETRY); 1783109a9638SPeter Gruber if (i == MAX_WRITE_RETRY) 1784109a9638SPeter Gruber snd_printdd("Write AC97 reg failed\n"); 1785109a9638SPeter Gruber } 1786109a9638SPeter Gruber 1787109a9638SPeter Gruber static unsigned short snd_riptide_codec_read(struct snd_ac97 *ac97, 1788109a9638SPeter Gruber unsigned short reg) 1789109a9638SPeter Gruber { 1790109a9638SPeter Gruber struct snd_riptide *chip = ac97->private_data; 1791109a9638SPeter Gruber struct cmdif *cif = chip->cif; 1792109a9638SPeter Gruber union cmdret rptr = CMDRET_ZERO; 1793109a9638SPeter Gruber 1794109a9638SPeter Gruber snd_assert(cif, return 0); 1795109a9638SPeter Gruber 1796109a9638SPeter Gruber if (SEND_RACR(cif, reg, &rptr) != 0) 1797109a9638SPeter Gruber SEND_RACR(cif, reg, &rptr); 1798109a9638SPeter Gruber snd_printdd("Read AC97 reg 0x%x got 0x%x\n", reg, rptr.retwords[1]); 1799109a9638SPeter Gruber return rptr.retwords[1]; 1800109a9638SPeter Gruber } 1801109a9638SPeter Gruber 1802109a9638SPeter Gruber static int snd_riptide_initialize(struct snd_riptide *chip) 1803109a9638SPeter Gruber { 1804109a9638SPeter Gruber struct cmdif *cif; 1805109a9638SPeter Gruber unsigned int device_id; 1806109a9638SPeter Gruber int err; 1807109a9638SPeter Gruber 1808109a9638SPeter Gruber snd_assert(chip, return -EINVAL); 1809109a9638SPeter Gruber 1810109a9638SPeter Gruber cif = chip->cif; 1811109a9638SPeter Gruber if (!cif) { 1812109a9638SPeter Gruber if ((cif = kzalloc(sizeof(struct cmdif), GFP_KERNEL)) == NULL) 1813109a9638SPeter Gruber return -ENOMEM; 1814109a9638SPeter Gruber cif->hwport = (struct riptideport *)chip->port; 1815109a9638SPeter Gruber spin_lock_init(&cif->lock); 1816109a9638SPeter Gruber chip->cif = cif; 1817109a9638SPeter Gruber } 1818109a9638SPeter Gruber cif->is_reset = 0; 1819109a9638SPeter Gruber if ((err = riptide_reset(cif, chip)) != 0) 1820109a9638SPeter Gruber return err; 1821109a9638SPeter Gruber device_id = chip->device_id; 1822109a9638SPeter Gruber switch (device_id) { 1823109a9638SPeter Gruber case 0x4310: 1824109a9638SPeter Gruber case 0x4320: 1825109a9638SPeter Gruber case 0x4330: 1826109a9638SPeter Gruber snd_printdd("Modem enable?\n"); 1827109a9638SPeter Gruber SEND_SETDPLL(cif); 1828109a9638SPeter Gruber break; 1829109a9638SPeter Gruber } 1830109a9638SPeter Gruber snd_printdd("Enabling MPU IRQs\n"); 1831109a9638SPeter Gruber if (chip->rmidi) 1832109a9638SPeter Gruber SET_EMPUIRQ(cif->hwport); 1833109a9638SPeter Gruber return err; 1834109a9638SPeter Gruber } 1835109a9638SPeter Gruber 1836109a9638SPeter Gruber static int snd_riptide_free(struct snd_riptide *chip) 1837109a9638SPeter Gruber { 1838109a9638SPeter Gruber struct cmdif *cif; 1839109a9638SPeter Gruber 1840109a9638SPeter Gruber snd_assert(chip, return 0); 1841109a9638SPeter Gruber 1842109a9638SPeter Gruber if ((cif = chip->cif)) { 1843109a9638SPeter Gruber SET_GRESET(cif->hwport); 1844109a9638SPeter Gruber udelay(100); 1845109a9638SPeter Gruber UNSET_GRESET(cif->hwport); 1846109a9638SPeter Gruber kfree(chip->cif); 1847109a9638SPeter Gruber } 18480a50d2b2STakashi Iwai if (chip->irq >= 0) 18490a50d2b2STakashi Iwai free_irq(chip->irq, chip); 1850109a9638SPeter Gruber if (chip->fw_entry) 1851109a9638SPeter Gruber release_firmware(chip->fw_entry); 185243560116STakashi Iwai release_and_free_resource(chip->res_port); 1853109a9638SPeter Gruber kfree(chip); 1854109a9638SPeter Gruber return 0; 1855109a9638SPeter Gruber } 1856109a9638SPeter Gruber 1857109a9638SPeter Gruber static int snd_riptide_dev_free(struct snd_device *device) 1858109a9638SPeter Gruber { 1859109a9638SPeter Gruber struct snd_riptide *chip = device->device_data; 1860109a9638SPeter Gruber 1861109a9638SPeter Gruber return snd_riptide_free(chip); 1862109a9638SPeter Gruber } 1863109a9638SPeter Gruber 1864109a9638SPeter Gruber static int __devinit 1865109a9638SPeter Gruber snd_riptide_create(struct snd_card *card, struct pci_dev *pci, 1866109a9638SPeter Gruber struct snd_riptide **rchip) 1867109a9638SPeter Gruber { 1868109a9638SPeter Gruber struct snd_riptide *chip; 1869109a9638SPeter Gruber struct riptideport *hwport; 1870109a9638SPeter Gruber int err; 1871109a9638SPeter Gruber static struct snd_device_ops ops = { 1872109a9638SPeter Gruber .dev_free = snd_riptide_dev_free, 1873109a9638SPeter Gruber }; 1874109a9638SPeter Gruber 1875109a9638SPeter Gruber *rchip = NULL; 1876109a9638SPeter Gruber if ((err = pci_enable_device(pci)) < 0) 1877109a9638SPeter Gruber return err; 1878109a9638SPeter Gruber if (!(chip = kzalloc(sizeof(struct snd_riptide), GFP_KERNEL))) 1879109a9638SPeter Gruber return -ENOMEM; 1880109a9638SPeter Gruber 1881109a9638SPeter Gruber spin_lock_init(&chip->lock); 1882109a9638SPeter Gruber chip->card = card; 1883109a9638SPeter Gruber chip->pci = pci; 1884109a9638SPeter Gruber chip->irq = -1; 1885109a9638SPeter Gruber chip->openstreams = 0; 1886109a9638SPeter Gruber chip->port = pci_resource_start(pci, 0); 1887109a9638SPeter Gruber chip->received_irqs = 0; 1888109a9638SPeter Gruber chip->handled_irqs = 0; 1889109a9638SPeter Gruber chip->cif = NULL; 1890109a9638SPeter Gruber tasklet_init(&chip->riptide_tq, riptide_handleirq, (unsigned long)chip); 1891109a9638SPeter Gruber 1892109a9638SPeter Gruber if ((chip->res_port = 1893109a9638SPeter Gruber request_region(chip->port, 64, "RIPTIDE")) == NULL) { 1894109a9638SPeter Gruber snd_printk(KERN_ERR 1895109a9638SPeter Gruber "Riptide: unable to grab region 0x%lx-0x%lx\n", 1896109a9638SPeter Gruber chip->port, chip->port + 64 - 1); 1897109a9638SPeter Gruber snd_riptide_free(chip); 1898109a9638SPeter Gruber return -EBUSY; 1899109a9638SPeter Gruber } 1900109a9638SPeter Gruber hwport = (struct riptideport *)chip->port; 1901109a9638SPeter Gruber UNSET_AIE(hwport); 1902109a9638SPeter Gruber 1903437a5a46STakashi Iwai if (request_irq(pci->irq, snd_riptide_interrupt, IRQF_SHARED, 1904109a9638SPeter Gruber "RIPTIDE", chip)) { 1905109a9638SPeter Gruber snd_printk(KERN_ERR "Riptide: unable to grab IRQ %d\n", 1906109a9638SPeter Gruber pci->irq); 1907109a9638SPeter Gruber snd_riptide_free(chip); 1908109a9638SPeter Gruber return -EBUSY; 1909109a9638SPeter Gruber } 1910109a9638SPeter Gruber chip->irq = pci->irq; 1911109a9638SPeter Gruber chip->device_id = pci->device; 1912109a9638SPeter Gruber pci_set_master(pci); 1913109a9638SPeter Gruber if ((err = snd_riptide_initialize(chip)) < 0) { 1914109a9638SPeter Gruber snd_riptide_free(chip); 1915109a9638SPeter Gruber return err; 1916109a9638SPeter Gruber } 1917109a9638SPeter Gruber 1918109a9638SPeter Gruber if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 1919109a9638SPeter Gruber snd_riptide_free(chip); 1920109a9638SPeter Gruber return err; 1921109a9638SPeter Gruber } 1922109a9638SPeter Gruber 1923c187c041STakashi Iwai snd_card_set_dev(card, &pci->dev); 1924c187c041STakashi Iwai 1925109a9638SPeter Gruber *rchip = chip; 1926109a9638SPeter Gruber return 0; 1927109a9638SPeter Gruber } 1928109a9638SPeter Gruber 1929109a9638SPeter Gruber static void 1930109a9638SPeter Gruber snd_riptide_proc_read(struct snd_info_entry *entry, 1931109a9638SPeter Gruber struct snd_info_buffer *buffer) 1932109a9638SPeter Gruber { 1933109a9638SPeter Gruber struct snd_riptide *chip = entry->private_data; 1934109a9638SPeter Gruber struct pcmhw *data; 1935109a9638SPeter Gruber int i; 1936109a9638SPeter Gruber struct cmdif *cif = NULL; 1937109a9638SPeter Gruber unsigned char p[256]; 1938109a9638SPeter Gruber unsigned short rval = 0, lval = 0; 1939109a9638SPeter Gruber unsigned int rate; 1940109a9638SPeter Gruber 1941109a9638SPeter Gruber if (!chip) 1942109a9638SPeter Gruber return; 1943109a9638SPeter Gruber 1944109a9638SPeter Gruber snd_iprintf(buffer, "%s\n\n", chip->card->longname); 1945109a9638SPeter Gruber snd_iprintf(buffer, "Device ID: 0x%x\nReceived IRQs: (%ld)%ld\nPorts:", 1946109a9638SPeter Gruber chip->device_id, chip->handled_irqs, chip->received_irqs); 1947109a9638SPeter Gruber for (i = 0; i < 64; i += 4) 1948109a9638SPeter Gruber snd_iprintf(buffer, "%c%02x: %08x", 1949109a9638SPeter Gruber (i % 16) ? ' ' : '\n', i, inl(chip->port + i)); 1950109a9638SPeter Gruber if ((cif = chip->cif)) { 1951109a9638SPeter Gruber snd_iprintf(buffer, 1952109a9638SPeter Gruber "\nVersion: ASIC: %d CODEC: %d AUXDSP: %d PROG: %d", 1953109a9638SPeter Gruber chip->firmware.firmware.ASIC, 1954109a9638SPeter Gruber chip->firmware.firmware.CODEC, 1955109a9638SPeter Gruber chip->firmware.firmware.AUXDSP, 1956109a9638SPeter Gruber chip->firmware.firmware.PROG); 1957109a9638SPeter Gruber snd_iprintf(buffer, "\nDigital mixer:"); 1958109a9638SPeter Gruber for (i = 0; i < 12; i++) { 1959109a9638SPeter Gruber getmixer(cif, i, &rval, &lval); 1960109a9638SPeter Gruber snd_iprintf(buffer, "\n %d: %d %d", i, rval, lval); 1961109a9638SPeter Gruber } 1962109a9638SPeter Gruber snd_iprintf(buffer, 1963109a9638SPeter Gruber "\nARM Commands num: %d failed: %d time: %d max: %d min: %d", 1964109a9638SPeter Gruber cif->cmdcnt, cif->errcnt, 1965109a9638SPeter Gruber cif->cmdtime, cif->cmdtimemax, cif->cmdtimemin); 1966109a9638SPeter Gruber } 1967109a9638SPeter Gruber snd_iprintf(buffer, "\nOpen streams %d:\n", chip->openstreams); 1968109a9638SPeter Gruber for (i = 0; i < PLAYBACK_SUBSTREAMS; i++) { 1969109a9638SPeter Gruber if (chip->playback_substream[i] 1970109a9638SPeter Gruber && chip->playback_substream[i]->runtime 1971109a9638SPeter Gruber && (data = 1972109a9638SPeter Gruber chip->playback_substream[i]->runtime->private_data)) { 1973109a9638SPeter Gruber snd_iprintf(buffer, 1974109a9638SPeter Gruber "stream: %d mixer: %d source: %d (%d,%d)\n", 1975109a9638SPeter Gruber data->id, data->mixer, data->source, 1976109a9638SPeter Gruber data->intdec[0], data->intdec[1]); 1977109a9638SPeter Gruber if (!(getsamplerate(cif, data->intdec, &rate))) 1978109a9638SPeter Gruber snd_iprintf(buffer, "rate: %d\n", rate); 1979109a9638SPeter Gruber } 1980109a9638SPeter Gruber } 1981109a9638SPeter Gruber if (chip->capture_substream 1982109a9638SPeter Gruber && chip->capture_substream->runtime 1983109a9638SPeter Gruber && (data = chip->capture_substream->runtime->private_data)) { 1984109a9638SPeter Gruber snd_iprintf(buffer, 1985109a9638SPeter Gruber "stream: %d mixer: %d source: %d (%d,%d)\n", 1986109a9638SPeter Gruber data->id, data->mixer, 1987109a9638SPeter Gruber data->source, data->intdec[0], data->intdec[1]); 1988109a9638SPeter Gruber if (!(getsamplerate(cif, data->intdec, &rate))) 1989109a9638SPeter Gruber snd_iprintf(buffer, "rate: %d\n", rate); 1990109a9638SPeter Gruber } 1991109a9638SPeter Gruber snd_iprintf(buffer, "Paths:\n"); 1992109a9638SPeter Gruber i = getpaths(cif, p); 1993109a9638SPeter Gruber while (i--) { 1994109a9638SPeter Gruber snd_iprintf(buffer, "%x->%x ", p[i - 1], p[i]); 1995109a9638SPeter Gruber i--; 1996109a9638SPeter Gruber } 1997109a9638SPeter Gruber snd_iprintf(buffer, "\n"); 1998109a9638SPeter Gruber } 1999109a9638SPeter Gruber 2000109a9638SPeter Gruber static void __devinit snd_riptide_proc_init(struct snd_riptide *chip) 2001109a9638SPeter Gruber { 2002109a9638SPeter Gruber struct snd_info_entry *entry; 2003109a9638SPeter Gruber 2004109a9638SPeter Gruber if (!snd_card_proc_new(chip->card, "riptide", &entry)) 2005bf850204STakashi Iwai snd_info_set_text_ops(entry, chip, snd_riptide_proc_read); 2006109a9638SPeter Gruber } 2007109a9638SPeter Gruber 2008109a9638SPeter Gruber static int __devinit snd_riptide_mixer(struct snd_riptide *chip) 2009109a9638SPeter Gruber { 2010109a9638SPeter Gruber struct snd_ac97_bus *pbus; 2011109a9638SPeter Gruber struct snd_ac97_template ac97; 2012109a9638SPeter Gruber int err = 0; 2013109a9638SPeter Gruber static struct snd_ac97_bus_ops ops = { 2014109a9638SPeter Gruber .write = snd_riptide_codec_write, 2015109a9638SPeter Gruber .read = snd_riptide_codec_read, 2016109a9638SPeter Gruber }; 2017109a9638SPeter Gruber 2018109a9638SPeter Gruber memset(&ac97, 0, sizeof(ac97)); 2019109a9638SPeter Gruber ac97.private_data = chip; 2020109a9638SPeter Gruber ac97.scaps = AC97_SCAP_SKIP_MODEM; 2021109a9638SPeter Gruber 2022109a9638SPeter Gruber if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0) 2023109a9638SPeter Gruber return err; 2024109a9638SPeter Gruber 2025109a9638SPeter Gruber chip->ac97_bus = pbus; 2026109a9638SPeter Gruber ac97.pci = chip->pci; 2027109a9638SPeter Gruber if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97)) < 0) 2028109a9638SPeter Gruber return err; 2029109a9638SPeter Gruber return err; 2030109a9638SPeter Gruber } 2031109a9638SPeter Gruber 2032109a9638SPeter Gruber #ifdef SUPPORT_JOYSTICK 2033109a9638SPeter Gruber static int have_joystick; 2034109a9638SPeter Gruber static struct pci_dev *riptide_gameport_pci; 2035109a9638SPeter Gruber static struct gameport *riptide_gameport; 2036109a9638SPeter Gruber 2037109a9638SPeter Gruber static int __devinit 2038109a9638SPeter Gruber snd_riptide_joystick_probe(struct pci_dev *pci, const struct pci_device_id *id) 2039109a9638SPeter Gruber { 2040109a9638SPeter Gruber static int dev; 2041109a9638SPeter Gruber 2042109a9638SPeter Gruber if (dev >= SNDRV_CARDS) 2043109a9638SPeter Gruber return -ENODEV; 2044109a9638SPeter Gruber if (!enable[dev]) { 2045109a9638SPeter Gruber dev++; 2046109a9638SPeter Gruber return -ENOENT; 2047109a9638SPeter Gruber } 2048109a9638SPeter Gruber 2049109a9638SPeter Gruber if (joystick_port[dev]) { 2050109a9638SPeter Gruber riptide_gameport = gameport_allocate_port(); 2051109a9638SPeter Gruber if (riptide_gameport) { 2052109a9638SPeter Gruber if (!request_region 2053109a9638SPeter Gruber (joystick_port[dev], 8, "Riptide gameport")) { 2054109a9638SPeter Gruber snd_printk(KERN_WARNING 2055109a9638SPeter Gruber "Riptide: cannot grab gameport 0x%x\n", 2056109a9638SPeter Gruber joystick_port[dev]); 2057109a9638SPeter Gruber gameport_free_port(riptide_gameport); 2058109a9638SPeter Gruber riptide_gameport = NULL; 2059109a9638SPeter Gruber } else { 2060109a9638SPeter Gruber riptide_gameport_pci = pci; 2061109a9638SPeter Gruber riptide_gameport->io = joystick_port[dev]; 2062109a9638SPeter Gruber gameport_register_port(riptide_gameport); 2063109a9638SPeter Gruber } 2064109a9638SPeter Gruber } 2065109a9638SPeter Gruber } 2066109a9638SPeter Gruber dev++; 2067109a9638SPeter Gruber return 0; 2068109a9638SPeter Gruber } 2069109a9638SPeter Gruber 2070109a9638SPeter Gruber static void __devexit snd_riptide_joystick_remove(struct pci_dev *pci) 2071109a9638SPeter Gruber { 2072109a9638SPeter Gruber if (riptide_gameport) { 2073109a9638SPeter Gruber if (riptide_gameport_pci == pci) { 2074109a9638SPeter Gruber release_region(riptide_gameport->io, 8); 2075109a9638SPeter Gruber riptide_gameport_pci = NULL; 2076109a9638SPeter Gruber gameport_unregister_port(riptide_gameport); 2077109a9638SPeter Gruber riptide_gameport = NULL; 2078109a9638SPeter Gruber } 2079109a9638SPeter Gruber } 2080109a9638SPeter Gruber } 2081109a9638SPeter Gruber #endif 2082109a9638SPeter Gruber 2083109a9638SPeter Gruber static int __devinit 2084109a9638SPeter Gruber snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) 2085109a9638SPeter Gruber { 2086109a9638SPeter Gruber static int dev; 2087109a9638SPeter Gruber struct snd_card *card; 2088109a9638SPeter Gruber struct snd_riptide *chip; 2089109a9638SPeter Gruber unsigned short addr; 2090109a9638SPeter Gruber int err = 0; 2091109a9638SPeter Gruber 2092109a9638SPeter Gruber if (dev >= SNDRV_CARDS) 2093109a9638SPeter Gruber return -ENODEV; 2094109a9638SPeter Gruber if (!enable[dev]) { 2095109a9638SPeter Gruber dev++; 2096109a9638SPeter Gruber return -ENOENT; 2097109a9638SPeter Gruber } 2098109a9638SPeter Gruber 2099109a9638SPeter Gruber card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 2100109a9638SPeter Gruber if (card == NULL) 2101109a9638SPeter Gruber return -ENOMEM; 2102109a9638SPeter Gruber if ((err = snd_riptide_create(card, pci, &chip)) < 0) { 2103109a9638SPeter Gruber snd_card_free(card); 2104109a9638SPeter Gruber return err; 2105109a9638SPeter Gruber } 2106109a9638SPeter Gruber card->private_data = chip; 2107109a9638SPeter Gruber if ((err = snd_riptide_pcm(chip, 0, NULL)) < 0) { 2108109a9638SPeter Gruber snd_card_free(card); 2109109a9638SPeter Gruber return err; 2110109a9638SPeter Gruber } 2111109a9638SPeter Gruber if ((err = snd_riptide_mixer(chip)) < 0) { 2112109a9638SPeter Gruber snd_card_free(card); 2113109a9638SPeter Gruber return err; 2114109a9638SPeter Gruber } 2115109a9638SPeter Gruber pci_write_config_word(chip->pci, PCI_EXT_Legacy_Mask, LEGACY_ENABLE_ALL 2116109a9638SPeter Gruber | (opl3_port[dev] ? LEGACY_ENABLE_FM : 0) 2117109a9638SPeter Gruber #ifdef SUPPORT_JOYSTICK 2118109a9638SPeter Gruber | (joystick_port[dev] ? LEGACY_ENABLE_GAMEPORT : 2119109a9638SPeter Gruber 0) 2120109a9638SPeter Gruber #endif 2121109a9638SPeter Gruber | (mpu_port[dev] 2122109a9638SPeter Gruber ? (LEGACY_ENABLE_MPU_INT | LEGACY_ENABLE_MPU) : 2123109a9638SPeter Gruber 0) 2124109a9638SPeter Gruber | ((chip->irq << 4) & 0xF0)); 2125109a9638SPeter Gruber if ((addr = mpu_port[dev]) != 0) { 2126109a9638SPeter Gruber pci_write_config_word(chip->pci, PCI_EXT_MPU_Base, addr); 2127109a9638SPeter Gruber if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_RIPTIDE, 2128109a9638SPeter Gruber addr, 0, chip->irq, 0, 2129109a9638SPeter Gruber &chip->rmidi)) < 0) 2130109a9638SPeter Gruber snd_printk(KERN_WARNING 2131109a9638SPeter Gruber "Riptide: Can't Allocate MPU at 0x%x\n", 2132109a9638SPeter Gruber addr); 2133109a9638SPeter Gruber else 2134109a9638SPeter Gruber chip->mpuaddr = addr; 2135109a9638SPeter Gruber } 2136109a9638SPeter Gruber if ((addr = opl3_port[dev]) != 0) { 2137109a9638SPeter Gruber pci_write_config_word(chip->pci, PCI_EXT_FM_Base, addr); 2138109a9638SPeter Gruber if ((err = snd_opl3_create(card, addr, addr + 2, 2139109a9638SPeter Gruber OPL3_HW_RIPTIDE, 0, 2140109a9638SPeter Gruber &chip->opl3)) < 0) 2141109a9638SPeter Gruber snd_printk(KERN_WARNING 2142109a9638SPeter Gruber "Riptide: Can't Allocate OPL3 at 0x%x\n", 2143109a9638SPeter Gruber addr); 2144109a9638SPeter Gruber else { 2145109a9638SPeter Gruber chip->opladdr = addr; 2146109a9638SPeter Gruber if ((err = 2147109a9638SPeter Gruber snd_opl3_hwdep_new(chip->opl3, 0, 1, NULL)) < 0) 2148109a9638SPeter Gruber snd_printk(KERN_WARNING 2149109a9638SPeter Gruber "Riptide: Can't Allocate OPL3-HWDEP\n"); 2150109a9638SPeter Gruber } 2151109a9638SPeter Gruber } 2152109a9638SPeter Gruber #ifdef SUPPORT_JOYSTICK 2153109a9638SPeter Gruber if ((addr = joystick_port[dev]) != 0) { 2154109a9638SPeter Gruber pci_write_config_word(chip->pci, PCI_EXT_Game_Base, addr); 2155109a9638SPeter Gruber chip->gameaddr = addr; 2156109a9638SPeter Gruber } 2157109a9638SPeter Gruber #endif 2158109a9638SPeter Gruber 2159109a9638SPeter Gruber strcpy(card->driver, "RIPTIDE"); 2160109a9638SPeter Gruber strcpy(card->shortname, "Riptide"); 2161109a9638SPeter Gruber #ifdef SUPPORT_JOYSTICK 2162109a9638SPeter Gruber snprintf(card->longname, sizeof(card->longname), 2163109a9638SPeter Gruber "%s at 0x%lx, irq %i mpu 0x%x opl3 0x%x gameport 0x%x", 2164109a9638SPeter Gruber card->shortname, chip->port, chip->irq, chip->mpuaddr, 2165109a9638SPeter Gruber chip->opladdr, chip->gameaddr); 2166109a9638SPeter Gruber #else 2167109a9638SPeter Gruber snprintf(card->longname, sizeof(card->longname), 2168109a9638SPeter Gruber "%s at 0x%lx, irq %i mpu 0x%x opl3 0x%x", 2169109a9638SPeter Gruber card->shortname, chip->port, chip->irq, chip->mpuaddr, 2170109a9638SPeter Gruber chip->opladdr); 2171109a9638SPeter Gruber #endif 2172109a9638SPeter Gruber snd_riptide_proc_init(chip); 2173109a9638SPeter Gruber if ((err = snd_card_register(card)) < 0) { 2174109a9638SPeter Gruber snd_card_free(card); 2175109a9638SPeter Gruber return err; 2176109a9638SPeter Gruber } 2177109a9638SPeter Gruber pci_set_drvdata(pci, card); 2178109a9638SPeter Gruber dev++; 2179109a9638SPeter Gruber return 0; 2180109a9638SPeter Gruber } 2181109a9638SPeter Gruber 2182109a9638SPeter Gruber static void __devexit snd_card_riptide_remove(struct pci_dev *pci) 2183109a9638SPeter Gruber { 2184109a9638SPeter Gruber snd_card_free(pci_get_drvdata(pci)); 2185109a9638SPeter Gruber pci_set_drvdata(pci, NULL); 2186109a9638SPeter Gruber } 2187109a9638SPeter Gruber 2188109a9638SPeter Gruber static struct pci_driver driver = { 2189109a9638SPeter Gruber .name = "RIPTIDE", 2190109a9638SPeter Gruber .id_table = snd_riptide_ids, 2191109a9638SPeter Gruber .probe = snd_card_riptide_probe, 2192109a9638SPeter Gruber .remove = __devexit_p(snd_card_riptide_remove), 2193109a9638SPeter Gruber #ifdef CONFIG_PM 2194109a9638SPeter Gruber .suspend = riptide_suspend, 2195109a9638SPeter Gruber .resume = riptide_resume, 2196109a9638SPeter Gruber #endif 2197109a9638SPeter Gruber }; 2198109a9638SPeter Gruber 2199109a9638SPeter Gruber #ifdef SUPPORT_JOYSTICK 2200109a9638SPeter Gruber static struct pci_driver joystick_driver = { 2201109a9638SPeter Gruber .name = "Riptide Joystick", 2202109a9638SPeter Gruber .id_table = snd_riptide_joystick_ids, 2203109a9638SPeter Gruber .probe = snd_riptide_joystick_probe, 2204109a9638SPeter Gruber .remove = __devexit_p(snd_riptide_joystick_remove), 2205109a9638SPeter Gruber }; 2206109a9638SPeter Gruber #endif 2207109a9638SPeter Gruber 2208109a9638SPeter Gruber static int __init alsa_card_riptide_init(void) 2209109a9638SPeter Gruber { 2210109a9638SPeter Gruber int err; 2211109a9638SPeter Gruber if ((err = pci_register_driver(&driver)) < 0) 2212109a9638SPeter Gruber return err; 2213109a9638SPeter Gruber #if defined(SUPPORT_JOYSTICK) 2214109a9638SPeter Gruber if (pci_register_driver(&joystick_driver) < 0) { 2215109a9638SPeter Gruber have_joystick = 0; 2216109a9638SPeter Gruber snd_printk(KERN_INFO "no joystick found\n"); 2217109a9638SPeter Gruber } else 2218109a9638SPeter Gruber have_joystick = 1; 2219109a9638SPeter Gruber #endif 2220109a9638SPeter Gruber return 0; 2221109a9638SPeter Gruber } 2222109a9638SPeter Gruber 2223109a9638SPeter Gruber static void __exit alsa_card_riptide_exit(void) 2224109a9638SPeter Gruber { 2225109a9638SPeter Gruber pci_unregister_driver(&driver); 2226109a9638SPeter Gruber #if defined(SUPPORT_JOYSTICK) 2227109a9638SPeter Gruber if (have_joystick) 2228109a9638SPeter Gruber pci_unregister_driver(&joystick_driver); 2229109a9638SPeter Gruber #endif 2230109a9638SPeter Gruber } 2231109a9638SPeter Gruber 2232109a9638SPeter Gruber module_init(alsa_card_riptide_init); 2233109a9638SPeter Gruber module_exit(alsa_card_riptide_exit); 2234