@@ -507,41 +507,19 @@ static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip);
507507 */
508508
509509static struct pci_device_id snd_riptide_ids [] = {
510- {
511- .vendor = 0x127a ,.device = 0x4310 ,
512- .subvendor = PCI_ANY_ID ,.subdevice = PCI_ANY_ID ,
513- },
514- {
515- .vendor = 0x127a ,.device = 0x4320 ,
516- .subvendor = PCI_ANY_ID ,.subdevice = PCI_ANY_ID ,
517- },
518- {
519- .vendor = 0x127a ,.device = 0x4330 ,
520- .subvendor = PCI_ANY_ID ,.subdevice = PCI_ANY_ID ,
521- },
522- {
523- .vendor = 0x127a ,.device = 0x4340 ,
524- .subvendor = PCI_ANY_ID ,.subdevice = PCI_ANY_ID ,
525- },
510+ { PCI_DEVICE (0x127a , 0x4310 ) },
511+ { PCI_DEVICE (0x127a , 0x4320 ) },
512+ { PCI_DEVICE (0x127a , 0x4330 ) },
513+ { PCI_DEVICE (0x127a , 0x4340 ) },
526514 {0 ,},
527515};
528516
529517#ifdef SUPPORT_JOYSTICK
530518static struct pci_device_id snd_riptide_joystick_ids [] __devinitdata = {
531- {
532- .vendor = 0x127a ,.device = 0x4312 ,
533- .subvendor = PCI_ANY_ID ,.subdevice = PCI_ANY_ID ,
534- },
535- {
536- .vendor = 0x127a ,.device = 0x4322 ,
537- .subvendor = PCI_ANY_ID ,.subdevice = PCI_ANY_ID ,
538- },
539- {.vendor = 0x127a ,.device = 0x4332 ,
540- .subvendor = PCI_ANY_ID ,.subdevice = PCI_ANY_ID ,
541- },
542- {.vendor = 0x127a ,.device = 0x4342 ,
543- .subvendor = PCI_ANY_ID ,.subdevice = PCI_ANY_ID ,
544- },
519+ { PCI_DEVICE (0x127a , 0x4312 ) },
520+ { PCI_DEVICE (0x127a , 0x4322 ) },
521+ { PCI_DEVICE (0x127a , 0x4332 ) },
522+ { PCI_DEVICE (0x127a , 0x4342 ) },
545523 {0 ,},
546524};
547525#endif
@@ -1209,12 +1187,79 @@ static int riptide_resume(struct pci_dev *pci)
12091187}
12101188#endif
12111189
1190+ static int try_to_load_firmware (struct cmdif * cif , struct snd_riptide * chip )
1191+ {
1192+ union firmware_version firmware = { .ret = CMDRET_ZERO };
1193+ int i , timeout , err ;
1194+
1195+ for (i = 0 ; i < 2 ; i ++ ) {
1196+ WRITE_PORT_ULONG (cif -> hwport -> port [i ].data1 , 0 );
1197+ WRITE_PORT_ULONG (cif -> hwport -> port [i ].data2 , 0 );
1198+ }
1199+ SET_GRESET (cif -> hwport );
1200+ udelay (100 );
1201+ UNSET_GRESET (cif -> hwport );
1202+ udelay (100 );
1203+
1204+ for (timeout = 100000 ; -- timeout ; udelay (10 )) {
1205+ if (IS_READY (cif -> hwport ) && !IS_GERR (cif -> hwport ))
1206+ break ;
1207+ }
1208+ if (!timeout ) {
1209+ snd_printk (KERN_ERR
1210+ "Riptide: device not ready, audio status: 0x%x "
1211+ "ready: %d gerr: %d\n" ,
1212+ READ_AUDIO_STATUS (cif -> hwport ),
1213+ IS_READY (cif -> hwport ), IS_GERR (cif -> hwport ));
1214+ return - EIO ;
1215+ } else {
1216+ snd_printdd
1217+ ("Riptide: audio status: 0x%x ready: %d gerr: %d\n" ,
1218+ READ_AUDIO_STATUS (cif -> hwport ),
1219+ IS_READY (cif -> hwport ), IS_GERR (cif -> hwport ));
1220+ }
1221+
1222+ SEND_GETV (cif , & firmware .ret );
1223+ snd_printdd ("Firmware version: ASIC: %d CODEC %d AUXDSP %d PROG %d\n" ,
1224+ firmware .firmware .ASIC , firmware .firmware .CODEC ,
1225+ firmware .firmware .AUXDSP , firmware .firmware .PROG );
1226+
1227+ for (i = 0 ; i < FIRMWARE_VERSIONS ; i ++ ) {
1228+ if (!memcmp (& firmware_versions [i ], & firmware , sizeof (firmware )))
1229+ break ;
1230+ }
1231+ if (i >= FIRMWARE_VERSIONS )
1232+ return 0 ; /* no match */
1233+
1234+ if (!chip )
1235+ return 1 ; /* OK */
1236+
1237+ snd_printdd ("Writing Firmware\n" );
1238+ if (!chip -> fw_entry ) {
1239+ err = request_firmware (& chip -> fw_entry , "riptide.hex" ,
1240+ & chip -> pci -> dev );
1241+ if (err ) {
1242+ snd_printk (KERN_ERR
1243+ "Riptide: Firmware not available %d\n" , err );
1244+ return - EIO ;
1245+ }
1246+ }
1247+ err = loadfirmware (cif , chip -> fw_entry -> data , chip -> fw_entry -> size );
1248+ if (err ) {
1249+ snd_printk (KERN_ERR
1250+ "Riptide: Could not load firmware %d\n" , err );
1251+ return err ;
1252+ }
1253+
1254+ chip -> firmware = firmware ;
1255+
1256+ return 1 ; /* OK */
1257+ }
1258+
12121259static int riptide_reset (struct cmdif * cif , struct snd_riptide * chip )
12131260{
1214- int timeout , tries ;
12151261 union cmdret rptr = CMDRET_ZERO ;
1216- union firmware_version firmware ;
1217- int i , j , err , has_firmware ;
1262+ int err , tries ;
12181263
12191264 if (!cif )
12201265 return - EINVAL ;
@@ -1227,75 +1272,11 @@ static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip)
12271272 cif -> is_reset = 0 ;
12281273
12291274 tries = RESET_TRIES ;
1230- has_firmware = 0 ;
1231- while (has_firmware == 0 && tries -- > 0 ) {
1232- for (i = 0 ; i < 2 ; i ++ ) {
1233- WRITE_PORT_ULONG (cif -> hwport -> port [i ].data1 , 0 );
1234- WRITE_PORT_ULONG (cif -> hwport -> port [i ].data2 , 0 );
1235- }
1236- SET_GRESET (cif -> hwport );
1237- udelay (100 );
1238- UNSET_GRESET (cif -> hwport );
1239- udelay (100 );
1240-
1241- for (timeout = 100000 ; -- timeout ; udelay (10 )) {
1242- if (IS_READY (cif -> hwport ) && !IS_GERR (cif -> hwport ))
1243- break ;
1244- }
1245- if (timeout == 0 ) {
1246- snd_printk (KERN_ERR
1247- "Riptide: device not ready, audio status: 0x%x ready: %d gerr: %d\n" ,
1248- READ_AUDIO_STATUS (cif -> hwport ),
1249- IS_READY (cif -> hwport ), IS_GERR (cif -> hwport ));
1250- return - EIO ;
1251- } else {
1252- snd_printdd
1253- ("Riptide: audio status: 0x%x ready: %d gerr: %d\n" ,
1254- READ_AUDIO_STATUS (cif -> hwport ),
1255- IS_READY (cif -> hwport ), IS_GERR (cif -> hwport ));
1256- }
1257-
1258- SEND_GETV (cif , & rptr );
1259- for (i = 0 ; i < 4 ; i ++ )
1260- firmware .ret .retwords [i ] = rptr .retwords [i ];
1261-
1262- snd_printdd
1263- ("Firmware version: ASIC: %d CODEC %d AUXDSP %d PROG %d\n" ,
1264- firmware .firmware .ASIC , firmware .firmware .CODEC ,
1265- firmware .firmware .AUXDSP , firmware .firmware .PROG );
1266-
1267- for (j = 0 ; j < FIRMWARE_VERSIONS ; j ++ ) {
1268- has_firmware = 1 ;
1269- for (i = 0 ; i < 4 ; i ++ ) {
1270- if (firmware_versions [j ].ret .retwords [i ] !=
1271- firmware .ret .retwords [i ])
1272- has_firmware = 0 ;
1273- }
1274- if (has_firmware )
1275- break ;
1276- }
1277-
1278- if (chip != NULL && has_firmware == 0 ) {
1279- snd_printdd ("Writing Firmware\n" );
1280- if (!chip -> fw_entry ) {
1281- if ((err =
1282- request_firmware (& chip -> fw_entry ,
1283- "riptide.hex" ,
1284- & chip -> pci -> dev )) != 0 ) {
1285- snd_printk (KERN_ERR
1286- "Riptide: Firmware not available %d\n" ,
1287- err );
1288- return - EIO ;
1289- }
1290- }
1291- err = loadfirmware (cif , chip -> fw_entry -> data ,
1292- chip -> fw_entry -> size );
1293- if (err )
1294- snd_printk (KERN_ERR
1295- "Riptide: Could not load firmware %d\n" ,
1296- err );
1297- }
1298- }
1275+ do {
1276+ err = try_to_load_firmware (cif , chip );
1277+ if (err < 0 )
1278+ return err ;
1279+ } while (!err && -- tries );
12991280
13001281 SEND_SACR (cif , 0 , AC97_RESET );
13011282 SEND_RACR (cif , AC97_RESET , & rptr );
@@ -1337,11 +1318,6 @@ static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip)
13371318 SET_AIE (cif -> hwport );
13381319 SET_AIACK (cif -> hwport );
13391320 cif -> is_reset = 1 ;
1340- if (chip ) {
1341- for (i = 0 ; i < 4 ; i ++ )
1342- chip -> firmware .ret .retwords [i ] =
1343- firmware .ret .retwords [i ];
1344- }
13451321
13461322 return 0 ;
13471323}
@@ -2094,8 +2070,8 @@ snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
20942070 static int dev ;
20952071 struct snd_card * card ;
20962072 struct snd_riptide * chip ;
2097- unsigned short addr ;
2098- int err = 0 ;
2073+ unsigned short val ;
2074+ int err ;
20992075
21002076 if (dev >= SNDRV_CARDS )
21012077 return - ENODEV ;
@@ -2107,60 +2083,63 @@ snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
21072083 err = snd_card_create (index [dev ], id [dev ], THIS_MODULE , 0 , & card );
21082084 if (err < 0 )
21092085 return err ;
2110- if ((err = snd_riptide_create (card , pci , & chip )) < 0 ) {
2111- snd_card_free (card );
2112- return err ;
2113- }
2086+ err = snd_riptide_create (card , pci , & chip );
2087+ if (err < 0 )
2088+ goto error ;
21142089 card -> private_data = chip ;
2115- if (( err = snd_riptide_pcm (chip , 0 , NULL )) < 0 ) {
2116- snd_card_free ( card );
2117- return err ;
2118- }
2119- if (( err = snd_riptide_mixer ( chip )) < 0 ) {
2120- snd_card_free ( card ) ;
2121- return err ;
2122- }
2123- pci_write_config_word ( chip -> pci , PCI_EXT_Legacy_Mask , LEGACY_ENABLE_ALL
2124- | ( opl3_port [ dev ] ? LEGACY_ENABLE_FM : 0 )
2090+ err = snd_riptide_pcm (chip , 0 , NULL );
2091+ if ( err < 0 )
2092+ goto error ;
2093+ err = snd_riptide_mixer ( chip );
2094+ if (err < 0 )
2095+ goto error ;
2096+
2097+ val = LEGACY_ENABLE_ALL ;
2098+ if ( opl3_port [ dev ])
2099+ val |= LEGACY_ENABLE_FM ;
21252100#ifdef SUPPORT_JOYSTICK
2126- | (joystick_port [dev ] ? LEGACY_ENABLE_GAMEPORT :
2127- 0 )
2101+ if (joystick_port [dev ])
2102+ val |= LEGACY_ENABLE_GAMEPORT ;
21282103#endif
2129- | (mpu_port [dev ]
2130- ? (LEGACY_ENABLE_MPU_INT | LEGACY_ENABLE_MPU ) :
2131- 0 )
2132- | ((chip -> irq << 4 ) & 0xF0 ));
2133- if ((addr = mpu_port [dev ]) != 0 ) {
2134- pci_write_config_word (chip -> pci , PCI_EXT_MPU_Base , addr );
2135- if ((err = snd_mpu401_uart_new (card , 0 , MPU401_HW_RIPTIDE ,
2136- addr , 0 , chip -> irq , 0 ,
2137- & chip -> rmidi )) < 0 )
2104+ if (mpu_port [dev ])
2105+ val |= LEGACY_ENABLE_MPU_INT | LEGACY_ENABLE_MPU ;
2106+ val |= (chip -> irq << 4 ) & 0xf0 ;
2107+ pci_write_config_word (chip -> pci , PCI_EXT_Legacy_Mask , val );
2108+ if (mpu_port [dev ]) {
2109+ val = mpu_port [dev ];
2110+ pci_write_config_word (chip -> pci , PCI_EXT_MPU_Base , val );
2111+ err = snd_mpu401_uart_new (card , 0 , MPU401_HW_RIPTIDE ,
2112+ val , 0 , chip -> irq , 0 ,
2113+ & chip -> rmidi );
2114+ if (err < 0 )
21382115 snd_printk (KERN_WARNING
21392116 "Riptide: Can't Allocate MPU at 0x%x\n" ,
2140- addr );
2117+ val );
21412118 else
2142- chip -> mpuaddr = addr ;
2119+ chip -> mpuaddr = val ;
21432120 }
2144- if ((addr = opl3_port [dev ]) != 0 ) {
2145- pci_write_config_word (chip -> pci , PCI_EXT_FM_Base , addr );
2146- if ((err = snd_opl3_create (card , addr , addr + 2 ,
2147- OPL3_HW_RIPTIDE , 0 ,
2148- & chip -> opl3 )) < 0 )
2121+ if (opl3_port [dev ]) {
2122+ val = opl3_port [dev ];
2123+ pci_write_config_word (chip -> pci , PCI_EXT_FM_Base , val );
2124+ err = snd_opl3_create (card , val , val + 2 ,
2125+ OPL3_HW_RIPTIDE , 0 , & chip -> opl3 );
2126+ if (err < 0 )
21492127 snd_printk (KERN_WARNING
21502128 "Riptide: Can't Allocate OPL3 at 0x%x\n" ,
2151- addr );
2129+ val );
21522130 else {
2153- chip -> opladdr = addr ;
2154- if (( err =
2155- snd_opl3_hwdep_new ( chip -> opl3 , 0 , 1 , NULL )) < 0 )
2131+ chip -> opladdr = val ;
2132+ err = snd_opl3_hwdep_new ( chip -> opl3 , 0 , 1 , NULL );
2133+ if ( err < 0 )
21562134 snd_printk (KERN_WARNING
21572135 "Riptide: Can't Allocate OPL3-HWDEP\n" );
21582136 }
21592137 }
21602138#ifdef SUPPORT_JOYSTICK
2161- if ((addr = joystick_port [dev ]) != 0 ) {
2162- pci_write_config_word (chip -> pci , PCI_EXT_Game_Base , addr );
2163- chip -> gameaddr = addr ;
2139+ if (joystick_port [dev ]) {
2140+ val = joystick_port [dev ];
2141+ pci_write_config_word (chip -> pci , PCI_EXT_Game_Base , val );
2142+ chip -> gameaddr = val ;
21642143 }
21652144#endif
21662145
@@ -2178,13 +2157,16 @@ snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
21782157 chip -> opladdr );
21792158#endif
21802159 snd_riptide_proc_init (chip );
2181- if ((err = snd_card_register (card )) < 0 ) {
2182- snd_card_free (card );
2183- return err ;
2184- }
2160+ err = snd_card_register (card );
2161+ if (err < 0 )
2162+ goto error ;
21852163 pci_set_drvdata (pci , card );
21862164 dev ++ ;
21872165 return 0 ;
2166+
2167+ error :
2168+ snd_card_free (card );
2169+ return err ;
21882170}
21892171
21902172static void __devexit snd_card_riptide_remove (struct pci_dev * pci )
0 commit comments