aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/riptide
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2009-05-26 06:58:58 -0400
committerTakashi Iwai <tiwai@suse.de>2009-05-26 06:58:58 -0400
commita693a26fe0807c3c406d6b5295d222b646677288 (patch)
treed90852059f1cd1615b13c5dc4f6cb98643876717 /sound/pci/riptide
parent59a3759d0fe8d969888c741bb33f4946e4d3750d (diff)
ALSA: riptide - Code clean up
A code clean up, coding style fixes. The firmware loading routine is split to an own function to improve the readability. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/riptide')
-rw-r--r--sound/pci/riptide/riptide.c286
1 files changed, 134 insertions, 152 deletions
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c
index e51a5ef1954d..460be038f9c7 100644
--- a/sound/pci/riptide/riptide.c
+++ b/sound/pci/riptide/riptide.c
@@ -507,41 +507,19 @@ static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip);
507 */ 507 */
508 508
509static struct pci_device_id snd_riptide_ids[] = { 509static struct pci_device_id snd_riptide_ids[] = {
510 { 510 { PCI_DEVICE(0x127a, 0x4310) },
511 .vendor = 0x127a,.device = 0x4310, 511 { PCI_DEVICE(0x127a, 0x4320) },
512 .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 512 { PCI_DEVICE(0x127a, 0x4330) },
513 }, 513 { PCI_DEVICE(0x127a, 0x4340) },
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 },
526 {0,}, 514 {0,},
527}; 515};
528 516
529#ifdef SUPPORT_JOYSTICK 517#ifdef SUPPORT_JOYSTICK
530static struct pci_device_id snd_riptide_joystick_ids[] __devinitdata = { 518static struct pci_device_id snd_riptide_joystick_ids[] __devinitdata = {
531 { 519 { PCI_DEVICE(0x127a, 0x4312) },
532 .vendor = 0x127a,.device = 0x4312, 520 { PCI_DEVICE(0x127a, 0x4322) },
533 .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 521 { PCI_DEVICE(0x127a, 0x4332) },
534 }, 522 { PCI_DEVICE(0x127a, 0x4342) },
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 },
545 {0,}, 523 {0,},
546}; 524};
547#endif 525#endif
@@ -1209,12 +1187,79 @@ static int riptide_resume(struct pci_dev *pci)
1209} 1187}
1210#endif 1188#endif
1211 1189
1190static 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
1212static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip) 1259static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip)
1213{ 1260{
1214 int timeout, tries;
1215 union cmdret rptr = CMDRET_ZERO; 1261 union cmdret rptr = CMDRET_ZERO;
1216 union firmware_version firmware; 1262 int err, tries;
1217 int i, j, err, has_firmware;
1218 1263
1219 if (!cif) 1264 if (!cif)
1220 return -EINVAL; 1265 return -EINVAL;
@@ -1227,75 +1272,11 @@ static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip)
1227 cif->is_reset = 0; 1272 cif->is_reset = 0;
1228 1273
1229 tries = RESET_TRIES; 1274 tries = RESET_TRIES;
1230 has_firmware = 0; 1275 do {
1231 while (has_firmware == 0 && tries-- > 0) { 1276 err = try_to_load_firmware(cif, chip);
1232 for (i = 0; i < 2; i++) { 1277 if (err < 0)
1233 WRITE_PORT_ULONG(cif->hwport->port[i].data1, 0); 1278 return err;
1234 WRITE_PORT_ULONG(cif->hwport->port[i].data2, 0); 1279 } while (!err && --tries);
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 }
1299 1280
1300 SEND_SACR(cif, 0, AC97_RESET); 1281 SEND_SACR(cif, 0, AC97_RESET);
1301 SEND_RACR(cif, AC97_RESET, &rptr); 1282 SEND_RACR(cif, AC97_RESET, &rptr);
@@ -1337,11 +1318,6 @@ static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip)
1337 SET_AIE(cif->hwport); 1318 SET_AIE(cif->hwport);
1338 SET_AIACK(cif->hwport); 1319 SET_AIACK(cif->hwport);
1339 cif->is_reset = 1; 1320 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 }
1345 1321
1346 return 0; 1322 return 0;
1347} 1323}
@@ -2094,8 +2070,8 @@ snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2094 static int dev; 2070 static int dev;
2095 struct snd_card *card; 2071 struct snd_card *card;
2096 struct snd_riptide *chip; 2072 struct snd_riptide *chip;
2097 unsigned short addr; 2073 unsigned short val;
2098 int err = 0; 2074 int err;
2099 2075
2100 if (dev >= SNDRV_CARDS) 2076 if (dev >= SNDRV_CARDS)
2101 return -ENODEV; 2077 return -ENODEV;
@@ -2107,60 +2083,63 @@ snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2107 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 2083 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2108 if (err < 0) 2084 if (err < 0)
2109 return err; 2085 return err;
2110 if ((err = snd_riptide_create(card, pci, &chip)) < 0) { 2086 err = snd_riptide_create(card, pci, &chip);
2111 snd_card_free(card); 2087 if (err < 0)
2112 return err; 2088 goto error;
2113 }
2114 card->private_data = chip; 2089 card->private_data = chip;
2115 if ((err = snd_riptide_pcm(chip, 0, NULL)) < 0) { 2090 err = snd_riptide_pcm(chip, 0, NULL);
2116 snd_card_free(card); 2091 if (err < 0)
2117 return err; 2092 goto error;
2118 } 2093 err = snd_riptide_mixer(chip);
2119 if ((err = snd_riptide_mixer(chip)) < 0) { 2094 if (err < 0)
2120 snd_card_free(card); 2095 goto error;
2121 return err; 2096
2122 } 2097 val = LEGACY_ENABLE_ALL;
2123 pci_write_config_word(chip->pci, PCI_EXT_Legacy_Mask, LEGACY_ENABLE_ALL 2098 if (opl3_port[dev])
2124 | (opl3_port[dev] ? LEGACY_ENABLE_FM : 0) 2099 val |= LEGACY_ENABLE_FM;
2125#ifdef SUPPORT_JOYSTICK 2100#ifdef SUPPORT_JOYSTICK
2126 | (joystick_port[dev] ? LEGACY_ENABLE_GAMEPORT : 2101 if (joystick_port[dev])
2127 0) 2102 val |= LEGACY_ENABLE_GAMEPORT;
2128#endif 2103#endif
2129 | (mpu_port[dev] 2104 if (mpu_port[dev])
2130 ? (LEGACY_ENABLE_MPU_INT | LEGACY_ENABLE_MPU) : 2105 val |= LEGACY_ENABLE_MPU_INT | LEGACY_ENABLE_MPU;
2131 0) 2106 val |= (chip->irq << 4) & 0xf0;
2132 | ((chip->irq << 4) & 0xF0)); 2107 pci_write_config_word(chip->pci, PCI_EXT_Legacy_Mask, val);
2133 if ((addr = mpu_port[dev]) != 0) { 2108 if (mpu_port[dev]) {
2134 pci_write_config_word(chip->pci, PCI_EXT_MPU_Base, addr); 2109 val = mpu_port[dev];
2135 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_RIPTIDE, 2110 pci_write_config_word(chip->pci, PCI_EXT_MPU_Base, val);
2136 addr, 0, chip->irq, 0, 2111 err = snd_mpu401_uart_new(card, 0, MPU401_HW_RIPTIDE,
2137 &chip->rmidi)) < 0) 2112 val, 0, chip->irq, 0,
2113 &chip->rmidi);
2114 if (err < 0)
2138 snd_printk(KERN_WARNING 2115 snd_printk(KERN_WARNING
2139 "Riptide: Can't Allocate MPU at 0x%x\n", 2116 "Riptide: Can't Allocate MPU at 0x%x\n",
2140 addr); 2117 val);
2141 else 2118 else
2142 chip->mpuaddr = addr; 2119 chip->mpuaddr = val;
2143 } 2120 }
2144 if ((addr = opl3_port[dev]) != 0) { 2121 if (opl3_port[dev]) {
2145 pci_write_config_word(chip->pci, PCI_EXT_FM_Base, addr); 2122 val = opl3_port[dev];
2146 if ((err = snd_opl3_create(card, addr, addr + 2, 2123 pci_write_config_word(chip->pci, PCI_EXT_FM_Base, val);
2147 OPL3_HW_RIPTIDE, 0, 2124 err = snd_opl3_create(card, val, val + 2,
2148 &chip->opl3)) < 0) 2125 OPL3_HW_RIPTIDE, 0, &chip->opl3);
2126 if (err < 0)
2149 snd_printk(KERN_WARNING 2127 snd_printk(KERN_WARNING
2150 "Riptide: Can't Allocate OPL3 at 0x%x\n", 2128 "Riptide: Can't Allocate OPL3 at 0x%x\n",
2151 addr); 2129 val);
2152 else { 2130 else {
2153 chip->opladdr = addr; 2131 chip->opladdr = val;
2154 if ((err = 2132 err = snd_opl3_hwdep_new(chip->opl3, 0, 1, NULL);
2155 snd_opl3_hwdep_new(chip->opl3, 0, 1, NULL)) < 0) 2133 if (err < 0)
2156 snd_printk(KERN_WARNING 2134 snd_printk(KERN_WARNING
2157 "Riptide: Can't Allocate OPL3-HWDEP\n"); 2135 "Riptide: Can't Allocate OPL3-HWDEP\n");
2158 } 2136 }
2159 } 2137 }
2160#ifdef SUPPORT_JOYSTICK 2138#ifdef SUPPORT_JOYSTICK
2161 if ((addr = joystick_port[dev]) != 0) { 2139 if (joystick_port[dev]) {
2162 pci_write_config_word(chip->pci, PCI_EXT_Game_Base, addr); 2140 val = joystick_port[dev];
2163 chip->gameaddr = addr; 2141 pci_write_config_word(chip->pci, PCI_EXT_Game_Base, val);
2142 chip->gameaddr = val;
2164 } 2143 }
2165#endif 2144#endif
2166 2145
@@ -2178,13 +2157,16 @@ snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2178 chip->opladdr); 2157 chip->opladdr);
2179#endif 2158#endif
2180 snd_riptide_proc_init(chip); 2159 snd_riptide_proc_init(chip);
2181 if ((err = snd_card_register(card)) < 0) { 2160 err = snd_card_register(card);
2182 snd_card_free(card); 2161 if (err < 0)
2183 return err; 2162 goto error;
2184 }
2185 pci_set_drvdata(pci, card); 2163 pci_set_drvdata(pci, card);
2186 dev++; 2164 dev++;
2187 return 0; 2165 return 0;
2166
2167 error:
2168 snd_card_free(card);
2169 return err;
2188} 2170}
2189 2171
2190static void __devexit snd_card_riptide_remove(struct pci_dev *pci) 2172static void __devexit snd_card_riptide_remove(struct pci_dev *pci)