93 #include <linux/pci.h>
94 #include <linux/slab.h>
106 #define SET_CHANNEL 0
107 #define PCM_FRONT_CHANNEL 0
108 #define PCM_REAR_CHANNEL 1
109 #define PCM_CENTER_LFE_CHANNEL 2
110 #define PCM_SIDE_CHANNEL 3
111 #define CONTROL_FRONT_CHANNEL 0
112 #define CONTROL_REAR_CHANNEL 3
113 #define CONTROL_CENTER_LFE_CHANNEL 1
114 #define CONTROL_SIDE_CHANNEL 2
138 .buffer_bytes_max = ((65536 - 64) * 8),
139 .period_bytes_min = 64,
140 .period_bytes_max = (65536 - 64),
159 .period_bytes_min = 64,
160 .period_bytes_max = (65536 - 128) >> 1,
166 static void snd_p16v_pcm_free_substream(
struct snd_pcm_runtime *runtime)
177 static int snd_p16v_pcm_open_playback_channel(
struct snd_pcm_substream *substream,
int channel_id)
180 struct snd_emu10k1_voice *
channel = &(emu->p16v_voices[channel_id]);
191 epcm->substream = substream;
199 runtime->
hw = snd_p16v_playback_hw;
202 channel->number = channel_id;
207 "p16v: open channel_id=%d, channel=%p, use=0x%x\n",
208 channel_id, channel, channel->use);
210 channel_id,
chip, channel);
213 channel->epcm = epcm;
217 runtime->
sync.
id32[0] = substream->
pcm->card->number;
225 static int snd_p16v_pcm_open_capture_channel(
struct snd_pcm_substream *substream,
int channel_id)
228 struct snd_emu10k1_voice *
channel = &(emu->p16v_capture_voice);
239 epcm->substream = substream;
247 runtime->
hw = snd_p16v_capture_hw;
250 channel->number = channel_id;
255 "p16v: open channel_id=%d, channel=%p, use=0x%x\n",
256 channel_id, channel, channel->use);
258 channel_id,
chip, channel);
261 channel->epcm = epcm;
275 emu->p16v_voices[substream->
pcm->device - emu->p16v_device_offset].use = 0;
286 emu->p16v_capture_voice.use = 0;
299 return snd_p16v_pcm_open_capture_channel(substream, 0);
345 int channel = substream->
pcm->device - emu->p16v_device_offset;
346 u32 *table_base = (
u32 *)(emu->p16v_buffer.area+(8*16*channel));
347 u32 period_size_bytes = frames_to_bytes(runtime, runtime->
period_size);
353 "format=0x%x, channels=%d, buffer_size=%ld, "
354 "period_size=%ld, periods=%u, frames_to_bytes=%d\n",
357 runtime->
periods, frames_to_bytes(runtime, 1));
361 emu->p16v_buffer.addr, emu->p16v_buffer.area,
362 emu->p16v_buffer.bytes);
365 switch (runtime->
rate) {
381 for(i = 0; i < runtime->
periods; i++) {
382 table_base[i*2]=runtime->
dma_addr+(i*period_size_bytes);
383 table_base[(i*2)+1]=period_size_bytes<<16;
404 int channel = substream->
pcm->device - emu->p16v_device_offset;
416 switch (runtime->
rate) {
442 static void snd_p16v_intr_enable(
struct snd_emu10k1 *
emu,
unsigned int intrenb)
448 enable =
inl(emu->port + INTE2) | intrenb;
449 outl(enable, emu->port + INTE2);
450 spin_unlock_irqrestore(&emu->emu_lock, flags);
453 static void snd_p16v_intr_disable(
struct snd_emu10k1 *emu,
unsigned int intrenb)
459 disable =
inl(emu->port + INTE2) & (~intrenb);
460 outl(disable, emu->port + INTE2);
461 spin_unlock_irqrestore(&emu->emu_lock, flags);
493 channel = substream->
pcm->device-emu->p16v_device_offset;
495 epcm->running = running;
497 inte |= (INTE2_PLAYBACK_CH_0_LOOP<<
channel);
498 snd_pcm_trigger_done(s, substream);
504 snd_p16v_intr_enable(emu, inte);
509 snd_p16v_intr_disable(emu, inte);
527 u32 inte = INTE2_CAPTURE_CH_0_LOOP | INTE2_CAPTURE_CH_0_HALF_LOOP;
531 snd_p16v_intr_enable(emu, inte);
537 snd_p16v_intr_disable(emu, inte);
556 int channel = substream->
pcm->device - emu->p16v_device_offset;
564 ptr2 = bytes_to_frames(runtime, ptr1);
587 ptr2 = bytes_to_frames(runtime, ptr1);
604 static struct snd_pcm_ops snd_p16v_playback_front_ops = {
605 .
open = snd_p16v_pcm_open_playback_front,
606 .close = snd_p16v_pcm_close_playback,
608 .hw_params = snd_p16v_pcm_hw_params_playback,
609 .hw_free = snd_p16v_pcm_hw_free_playback,
610 .prepare = snd_p16v_pcm_prepare_playback,
611 .trigger = snd_p16v_pcm_trigger_playback,
612 .pointer = snd_p16v_pcm_pointer_playback,
616 .
open = snd_p16v_pcm_open_capture,
617 .close = snd_p16v_pcm_close_capture,
619 .hw_params = snd_p16v_pcm_hw_params_capture,
620 .hw_free = snd_p16v_pcm_hw_free_capture,
621 .prepare = snd_p16v_pcm_prepare_capture,
622 .trigger = snd_p16v_pcm_trigger_capture,
623 .pointer = snd_p16v_pcm_pointer_capture,
630 if (chip->p16v_buffer.area) {
648 emu->p16v_device_offset = device;
652 if ((err =
snd_pcm_new(emu->card,
"p16v", device, 1, capture, &pcm)) < 0)
668 substream = substream->
next) {
672 ((65536 - 64) * 8), ((65536 - 64) * 8))) < 0)
682 substream = substream->
next) {
686 65536 - 64, 65536 - 64)) < 0)
700 static int snd_p16v_volume_info(
struct snd_kcontrol *kcontrol,
710 static int snd_p16v_volume_get(
struct snd_kcontrol *kcontrol,
720 ucontrol->
value.integer.value[0] = 0xff - ((value >> 24) & 0xff);
721 ucontrol->
value.integer.value[1] = 0xff - ((value >> 16) & 0xff);
723 ucontrol->
value.integer.value[0] = 0xff - ((value >> 8) & 0xff);
724 ucontrol->
value.integer.value[1] = 0xff - ((value >> 0) & 0xff);
729 static int snd_p16v_volume_put(
struct snd_kcontrol *kcontrol,
740 value |= ((0xff - ucontrol->
value.integer.value[0]) << 24) |
741 ((0xff - ucontrol->
value.integer.value[1]) << 16);
744 value |= ((0xff - ucontrol->
value.integer.value[0]) << 8) |
745 ((0xff - ucontrol->
value.integer.value[1]) );
754 static int snd_p16v_capture_source_info(
struct snd_kcontrol *kcontrol,
757 static char *texts[8] = {
758 "SPDIF",
"I2S",
"SRC48",
"SRCMulti_SPDIF",
"SRCMulti_I2S",
771 static int snd_p16v_capture_source_get(
struct snd_kcontrol *kcontrol,
776 ucontrol->
value.enumerated.item[0] = emu->p16v_capture_source;
780 static int snd_p16v_capture_source_put(
struct snd_kcontrol *kcontrol,
789 val = ucontrol->
value.enumerated.item[0] ;
792 change = (emu->p16v_capture_source !=
val);
794 emu->p16v_capture_source =
val;
795 source = (val << 28) | (val << 24) | (val << 20) | (val << 16);
802 static int snd_p16v_capture_channel_info(
struct snd_kcontrol *kcontrol,
805 static char *texts[4] = {
"0",
"1",
"2",
"3", };
816 static int snd_p16v_capture_channel_get(
struct snd_kcontrol *kcontrol,
821 ucontrol->
value.enumerated.item[0] = emu->p16v_capture_channel;
825 static int snd_p16v_capture_channel_put(
struct snd_kcontrol *kcontrol,
833 val = ucontrol->
value.enumerated.item[0] ;
836 change = (emu->p16v_capture_channel !=
val);
838 emu->p16v_capture_channel =
val;
846 #define P16V_VOL(xname,xreg,xhl) { \
847 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
848 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
849 SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
850 .info = snd_p16v_volume_info, \
851 .get = snd_p16v_volume_get, \
852 .put = snd_p16v_volume_put, \
853 .tlv = { .p = snd_p16v_db_scale1 }, \
854 .private_value = ((xreg) | ((xhl) << 8)) \
868 .name =
"HD source Capture",
869 .info = snd_p16v_capture_source_info,
870 .get = snd_p16v_capture_source_get,
871 .put = snd_p16v_capture_source_put
875 .name =
"HD channel Capture",
876 .info = snd_p16v_capture_channel_info,
877 .get = snd_p16v_capture_channel_get,
878 .put = snd_p16v_capture_channel_put
888 for (i = 0; i <
ARRAY_SIZE(p16v_mixer_controls); i++) {
896 #ifdef CONFIG_PM_SLEEP
900 int __devinit snd_p16v_alloc_pm_buffer(
struct snd_emu10k1 *emu)
902 emu->p16v_saved =
vmalloc(NUM_CHS * 4 * 0x80);
903 if (! emu->p16v_saved)
908 void snd_p16v_free_pm_buffer(
struct snd_emu10k1 *emu)
910 vfree(emu->p16v_saved);
913 void snd_p16v_suspend(
struct snd_emu10k1 *emu)
918 val = emu->p16v_saved;
919 for (ch = 0; ch < NUM_CHS; ch++)
920 for (i = 0; i < 0x80; i++, val++)
924 void snd_p16v_resume(
struct snd_emu10k1 *emu)
929 val = emu->p16v_saved;
930 for (ch = 0; ch < NUM_CHS; ch++)
931 for (i = 0; i < 0x80; i++, val++)