25 #include <linux/pci.h>
26 #include <linux/time.h>
27 #include <linux/slab.h>
28 #include <linux/module.h>
44 static int codecs = 1;
53 MODULE_PARM_DESC(codecs,
"Set bit to indicate that codec number is expected to be present (default 1)");
83 #define VOICE_IN_USE 1
84 #define VOICE_CAPTURE 2
85 #define VOICE_SSO_TIMING 4
86 #define VOICE_SYNC_TIMING 8
106 #ifdef CONFIG_PM_SLEEP
107 #define SIS_SUSPEND_PAGES 4
109 #define SIS_SUSPEND_PAGES 1
149 #define SIS_PRIMARY_CODEC_PRESENT 0x0001
150 #define SIS_SECONDARY_CODEC_PRESENT 0x0002
151 #define SIS_TERTIARY_CODEC_PRESENT 0x0004
176 .buffer_bytes_max = (0xfff9 * 4),
180 .periods_max = (0xfff9 / 9),
197 .buffer_bytes_max = (0xfff9 * 4),
201 .periods_max = (0xfff9 / 9),
220 static void sis_update_voice(
struct voice *voice)
233 sis_update_sso(voice, voice->
vperiod);
257 sis_update_sso(voice, sync);
282 sis_update_sso(voice, voice->
vperiod);
296 static void sis_voice_irq(
u32 status,
struct voice *voice)
304 sis_update_voice(voice);
331 sis_voice_irq(status, sis->
voices);
337 sis_voice_irq(status, &sis->
voices[32]);
359 static u32 sis_rate_to_delta(
unsigned int rate)
373 else if (rate == 8000)
375 else if (rate == 48000)
378 delta = (((rate << 12) + 24000) / 48000) & 0x0000ffff;
382 static void __sis_map_silence(
struct sis7019 *sis)
392 static void __sis_unmap_silence(
struct sis7019 *sis)
401 static void sis_free_voice(
struct sis7019 *sis,
struct voice *voice)
407 __sis_unmap_silence(sis);
413 spin_unlock_irqrestore(&sis->
voice_lock, flags);
416 static struct voice *__sis_alloc_playback_voice(
struct sis7019 *sis)
422 for (i = 0; i < 64; i++) {
435 static struct voice *sis_alloc_playback_voice(
struct sis7019 *sis)
441 voice = __sis_alloc_playback_voice(sis);
442 spin_unlock_irqrestore(&sis->
voice_lock, flags);
463 needed = (period_size != buffer_size &&
464 period_size != (buffer_size / 2));
466 if (needed && !voice->
timing) {
468 voice->
timing = __sis_alloc_playback_voice(sis);
470 __sis_map_silence(sis);
471 spin_unlock_irqrestore(&sis->
voice_lock, flags);
475 }
else if (!needed && voice->
timing) {
476 sis_free_voice(sis, voice);
489 voice = sis_alloc_playback_voice(sis);
495 runtime->
hw = sis_playback_hw_info;
510 sis_free_voice(sis, voice);
567 delta = sis_rate_to_delta(runtime->
rate);
577 writel(0, wave_base + reg);
601 u32 play[2] = { 0, 0 };
628 voice = s->
runtime->private_data;
630 record |= 1 << voice->
num;
638 play[voice->
num / 32] |= 1 << (voice->
num & 0x1f);
640 snd_pcm_trigger_done(s, substream);
687 spin_unlock_irqrestore(&sis->
voice_lock, flags);
694 runtime->
hw = sis_capture_hw_info;
721 rc = sis_alloc_timing_voice(substream, hw_params);
727 static void sis_prepare_timing_voice(
struct voice *voice,
742 buffer_size = 4096 / runtime->
channels;
759 if (vperiod > period_size) {
761 u16 quarter_period = period_size / 4;
763 if (tail && tail < quarter_period) {
766 tail = quarter_period -
tail;
772 sso = period_size - 1;
808 sso_eso |= timing->
sso << 16;
810 delta = sis_rate_to_delta(runtime->
rate);
820 writel(0, wave_base + reg);
858 sis_prepare_timing_voice(voice, substream);
876 .
open = sis_playback_open,
877 .close = sis_substream_close,
879 .hw_params = sis_playback_hw_params,
880 .hw_free = sis_hw_free,
881 .prepare = sis_pcm_playback_prepare,
882 .trigger = sis_pcm_trigger,
883 .pointer = sis_pcm_pointer,
887 .
open = sis_capture_open,
888 .close = sis_substream_close,
890 .hw_params = sis_capture_hw_params,
891 .hw_free = sis_hw_free,
892 .prepare = sis_pcm_capture_prepare,
893 .trigger = sis_pcm_trigger,
894 .pointer = sis_pcm_pointer,
925 static unsigned short sis_ac97_rw(
struct sis7019 *sis,
int codec,
u32 cmd)
928 unsigned short val = 0xffff;
932 static const u16 codec_ready[3] = {
938 rdy = codec_ready[
codec];
986 dev_err(&sis->
pci->dev,
"ac97 codec %d timeout cmd 0x%08x\n",
996 static const u32 cmd[3] = {
1002 (val << 16) | (reg << 8) | cmd[ac97->
num]);
1005 static unsigned short sis_ac97_read(
struct snd_ac97 *ac97,
unsigned short reg)
1007 static const u32 cmd[3] = {
1013 (reg << 8) | cmd[ac97->
num]);
1021 .
write = sis_ac97_write,
1022 .read = sis_ac97_read,
1026 memset(&ac97, 0,
sizeof(ac97));
1045 static void sis_free_suspend(
struct sis7019 *sis)
1053 static int sis_chip_free(
struct sis7019 *sis)
1073 sis_free_suspend(sis);
1077 static int sis_dev_free(
struct snd_device *dev)
1080 return sis_chip_free(sis);
1083 static int sis_chip_init(
struct sis7019 *sis)
1145 dev_err(&sis->
pci->dev,
"could not find any codecs\n");
1150 dev_warn(&sis->
pci->dev,
"missing codecs, found %0x, expected %0x\n",
1185 for (i = 0; i < 64; i++) {
1211 #ifdef CONFIG_PM_SLEEP
1212 static int sis_suspend(
struct device *dev)
1221 snd_pcm_suspend_all(sis->
pcm);
1223 snd_ac97_suspend(sis->
ac97[0]);
1225 snd_ac97_suspend(sis->
ac97[1]);
1227 snd_ac97_suspend(sis->
ac97[2]);
1231 if (sis->
irq >= 0) {
1238 for (i = 0; i < 4; i++) {
1249 static int sis_resume(
struct device *dev)
1261 dev_err(&pci->
dev,
"unable to re-enable device\n");
1265 if (sis_chip_init(sis)) {
1266 dev_err(&pci->
dev,
"unable to re-init controller\n");
1271 KBUILD_MODNAME, sis)) {
1279 for (i = 0; i < 4; i++) {
1290 snd_ac97_resume(sis->
ac97[0]);
1292 snd_ac97_resume(sis->
ac97[1]);
1294 snd_ac97_resume(sis->
ac97[2]);
1305 #define SIS_PM_OPS &sis_pm
1307 #define SIS_PM_OPS NULL
1310 static int sis_alloc_suspend(
struct sis7019 *sis)
1333 struct voice *voice;
1335 .dev_free = sis_dev_free,
1345 dev_err(&pci->
dev,
"architecture does not support 30-bit PCI busmaster DMA");
1346 goto error_out_enabled;
1349 memset(sis, 0,
sizeof(*sis));
1359 dev_err(&pci->
dev,
"unable request regions\n");
1360 goto error_out_enabled;
1366 dev_err(&pci->
dev,
"unable to remap MMIO, aborting\n");
1367 goto error_out_cleanup;
1370 rc = sis_alloc_suspend(sis);
1372 dev_err(&pci->
dev,
"unable to allocate state storage\n");
1373 goto error_out_cleanup;
1376 rc = sis_chip_init(sis);
1378 goto error_out_cleanup;
1383 dev_err(&pci->
dev,
"unable to allocate irq %d\n", sis->
irq);
1384 goto error_out_cleanup;
1390 for (i = 0; i < 64; i++) {
1404 goto error_out_cleanup;
1448 rc = sis_chip_create(card, pci);
1450 goto card_error_out;
1454 rc = sis_mixer_create(sis);
1456 goto card_error_out;
1458 rc = sis_pcm_create(sis);
1460 goto card_error_out;
1463 "%s Audio Accelerator with %s at 0x%lx, irq %d",
1469 goto card_error_out;
1471 pci_set_drvdata(pci, card);
1484 pci_set_drvdata(pci,
NULL);
1488 .name = KBUILD_MODNAME,
1489 .id_table = snd_sis7019_ids,
1490 .probe = snd_sis7019_probe,