32 #include <linux/slab.h>
33 #include <linux/module.h>
60 #define AUDIO_CONTROL_RESET BIT(0)
61 #define AUDIO_CONTROL_CODEC_PRESENT BIT(1)
63 #define CODEC_CONTROL_WORD_SHIFT 0
64 #define CODEC_CONTROL_READ BIT(16)
65 #define CODEC_CONTROL_ADDRESS_SHIFT 17
67 #define CHANNEL_CONTROL_RESET BIT(10)
68 #define CHANNEL_DMA_ENABLE BIT(9)
69 #define CHANNEL_INT_THRESHOLD_DISABLED (0 << 5)
70 #define CHANNEL_INT_THRESHOLD_25 (1 << 5)
71 #define CHANNEL_INT_THRESHOLD_50 (2 << 5)
72 #define CHANNEL_INT_THRESHOLD_75 (3 << 5)
73 #define CHANNEL_INT_THRESHOLD_EMPTY (4 << 5)
74 #define CHANNEL_INT_THRESHOLD_NOT_EMPTY (5 << 5)
75 #define CHANNEL_INT_THRESHOLD_FULL (6 << 5)
76 #define CHANNEL_INT_THRESHOLD_NOT_FULL (7 << 5)
78 #define CHANNEL_RING_SHIFT 12
79 #define CHANNEL_RING_SIZE (1 << CHANNEL_RING_SHIFT)
80 #define CHANNEL_RING_MASK (CHANNEL_RING_SIZE - 1)
82 #define CHANNEL_LEFT_SHIFT 40
83 #define CHANNEL_RIGHT_SHIFT 8
116 static int read_ad1843_reg(
void *
priv,
int reg)
127 val =
readq(&
mace->perif.audio.codec_control);
130 val =
readq(&
mace->perif.audio.codec_read);
139 static int write_ad1843_reg(
void *
priv,
int reg,
int word)
149 &
mace->perif.audio.codec_control);
151 val =
readq(&
mace->perif.audio.codec_control);
158 static int sgio2audio_gain_info(
struct snd_kcontrol *kcontrol,
171 static int sgio2audio_gain_get(
struct snd_kcontrol *kcontrol,
179 ucontrol->
value.integer.value[0] = (vol >> 8) & 0xFF;
180 ucontrol->
value.integer.value[1] = vol & 0xFF;
185 static int sgio2audio_gain_put(
struct snd_kcontrol *kcontrol,
192 newvol = (ucontrol->
value.integer.value[0] << 8) |
193 ucontrol->
value.integer.value[1];
198 return newvol != oldvol;
201 static int sgio2audio_source_info(
struct snd_kcontrol *kcontrol,
204 static const char *texts[3] = {
205 "Cam Mic",
"Mic",
"Line"
217 static int sgio2audio_source_get(
struct snd_kcontrol *kcontrol,
226 static int sgio2audio_source_put(
struct snd_kcontrol *kcontrol,
234 ucontrol->
value.enumerated.item[0]);
236 return newsrc != oldsrc;
242 .name =
"PCM Playback Volume",
246 .info = sgio2audio_gain_info,
247 .get = sgio2audio_gain_get,
248 .put = sgio2audio_gain_put,
254 .name =
"PCM Playback Volume",
258 .info = sgio2audio_gain_info,
259 .get = sgio2audio_gain_get,
260 .put = sgio2audio_gain_put,
266 .name =
"Capture Volume",
269 .info = sgio2audio_gain_info,
270 .get = sgio2audio_gain_get,
271 .put = sgio2audio_gain_put,
277 .name =
"Capture Source",
279 .info = sgio2audio_source_info,
280 .get = sgio2audio_source_get,
281 .put = sgio2audio_source_put,
287 .name =
"Line Playback Volume",
291 .info = sgio2audio_gain_info,
292 .get = sgio2audio_gain_get,
293 .put = sgio2audio_gain_put,
299 .name =
"Line Playback Volume",
303 .info = sgio2audio_gain_info,
304 .get = sgio2audio_gain_get,
305 .put = sgio2audio_gain_put,
311 .name =
"Mic Playback Volume",
314 .info = sgio2audio_gain_info,
315 .get = sgio2audio_gain_get,
316 .put = sgio2audio_gain_put,
365 static int snd_sgio2audio_dma_pull_frag(
struct snd_sgio2audio *chip,
366 unsigned int ch,
unsigned int count)
369 unsigned long src_base, src_pos, dst_mask;
370 unsigned char *dst_base;
381 src_pos =
readq(&
mace->perif.audio.chan[ch].read_ptr);
383 dst_pos = chip->
channel[ch].pos;
384 dst_mask = frames_to_bytes(runtime, runtime->
buffer_size) - 1;
387 chip->
channel[ch].size += (count >> 3);
392 src = (
u64 *)(src_base + src_pos);
393 dst = (
s16 *)(dst_base + dst_pos);
400 dst_pos = (dst_pos + 2 *
sizeof(
s16)) & dst_mask;
401 count -=
sizeof(
u64);
404 writeq(src_pos, &
mace->perif.audio.chan[ch].read_ptr);
405 chip->
channel[ch].pos = dst_pos;
407 spin_unlock_irqrestore(&chip->
channel[ch].lock, flags);
413 static int snd_sgio2audio_dma_push_frag(
struct snd_sgio2audio *chip,
414 unsigned int ch,
unsigned int count)
418 unsigned long dst_base, dst_pos, src_mask;
419 unsigned char *src_base;
429 dst_pos =
readq(&
mace->perif.audio.chan[ch].write_ptr);
431 src_pos = chip->
channel[ch].pos;
432 src_mask = frames_to_bytes(runtime, runtime->
buffer_size) - 1;
435 chip->
channel[ch].size += (count >> 3);
440 src = (
s16 *)(src_base + src_pos);
441 dst = (
u64 *)(dst_base + dst_pos);
450 src_pos = (src_pos + 2 *
sizeof(
s16)) & src_mask;
451 count -=
sizeof(
u64);
454 writeq(dst_pos, &
mace->perif.audio.chan[ch].write_ptr);
455 chip->
channel[ch].pos = src_pos;
457 spin_unlock_irqrestore(&chip->
channel[ch].lock, flags);
470 writeq(0, &
mace->perif.audio.chan[ch].control);
478 &
mace->perif.audio.chan[ch].control);
503 readq(&
mace->perif.audio.chan[ch].depth) - 32;
504 if (snd_sgio2audio_dma_pull_frag(chip, ch, count))
510 static irqreturn_t snd_sgio2audio_dma_out_isr(
int irq,
void *dev_id)
522 readq(&
mace->perif.audio.chan[ch].depth) - 32;
523 if (snd_sgio2audio_dma_push_frag(chip, ch, count))
529 static irqreturn_t snd_sgio2audio_error_isr(
int irq,
void *dev_id)
535 snd_sgio2audio_dma_stop(substream);
536 snd_sgio2audio_dma_start(substream);
566 runtime->
hw = snd_sgio2audio_pcm_hw;
576 runtime->
hw = snd_sgio2audio_pcm_hw;
587 runtime->
hw = snd_sgio2audio_pcm_hw;
634 switch (substream->
stream) {
649 spin_unlock_irqrestore(&chip->
channel[ch].lock, flags);
660 snd_sgio2audio_dma_start(substream);
664 snd_sgio2audio_dma_stop(substream);
680 return bytes_to_frames(substream->
runtime,
685 static struct snd_pcm_ops snd_sgio2audio_playback1_ops = {
686 .open = snd_sgio2audio_playback1_open,
687 .close = snd_sgio2audio_pcm_close,
689 .hw_params = snd_sgio2audio_pcm_hw_params,
690 .hw_free = snd_sgio2audio_pcm_hw_free,
691 .prepare = snd_sgio2audio_pcm_prepare,
692 .trigger = snd_sgio2audio_pcm_trigger,
693 .pointer = snd_sgio2audio_pcm_pointer,
698 static struct snd_pcm_ops snd_sgio2audio_playback2_ops = {
699 .open = snd_sgio2audio_playback2_open,
700 .close = snd_sgio2audio_pcm_close,
702 .hw_params = snd_sgio2audio_pcm_hw_params,
703 .hw_free = snd_sgio2audio_pcm_hw_free,
704 .prepare = snd_sgio2audio_pcm_prepare,
705 .trigger = snd_sgio2audio_pcm_trigger,
706 .pointer = snd_sgio2audio_pcm_pointer,
711 static struct snd_pcm_ops snd_sgio2audio_capture_ops = {
712 .open = snd_sgio2audio_capture_open,
713 .close = snd_sgio2audio_pcm_close,
715 .hw_params = snd_sgio2audio_pcm_hw_params,
716 .hw_free = snd_sgio2audio_pcm_hw_free,
717 .prepare = snd_sgio2audio_pcm_prepare,
718 .trigger = snd_sgio2audio_pcm_trigger,
719 .pointer = snd_sgio2audio_pcm_pointer,
744 &snd_sgio2audio_playback1_ops);
746 &snd_sgio2audio_capture_ops);
758 &snd_sgio2audio_playback2_ops);
768 } snd_sgio2_isr_table[] = {
772 .isr = snd_sgio2audio_dma_in_isr,
773 .desc =
"Capture DMA Channel 0"
777 .isr = snd_sgio2audio_error_isr,
778 .desc =
"Capture Overflow"
782 .isr = snd_sgio2audio_dma_out_isr,
783 .desc =
"Playback DMA Channel 1"
787 .isr = snd_sgio2audio_error_isr,
788 .desc =
"Memory Error Channel 1"
792 .isr = snd_sgio2audio_dma_out_isr,
793 .desc =
"Playback DMA Channel 2"
797 .isr = snd_sgio2audio_error_isr,
798 .desc =
"Memory Error Channel 2"
814 for (i = 0; i <
ARRAY_SIZE(snd_sgio2_isr_table); i++)
815 free_irq(snd_sgio2_isr_table[i].irq,
816 &chip->
channel[snd_sgio2_isr_table[i].idx]);
830 return snd_sgio2audio_free(chip);
834 .dev_free = snd_sgio2audio_dev_free,
860 "sgio2audio: could not allocate ring buffers\n");
868 for (i = 0; i < 3; i++) {
874 for (i = 0; i <
ARRAY_SIZE(snd_sgio2_isr_table); i++) {
876 snd_sgio2_isr_table[i].
isr,
878 snd_sgio2_isr_table[i].
desc,
879 &chip->
channel[snd_sgio2_isr_table[i].idx])) {
880 snd_sgio2audio_free(chip);
882 snd_sgio2_isr_table[i].irq);
897 chip->
ad1843.read = read_ad1843_reg;
898 chip->
ad1843.write = write_ad1843_reg;
904 snd_sgio2audio_free(chip);
910 snd_sgio2audio_free(chip);
927 err = snd_sgio2audio_create(card, &chip);
934 err = snd_sgio2audio_new_pcm(chip);
939 err = snd_sgio2audio_new_mixer(chip);
957 platform_set_drvdata(pdev, card);
963 struct snd_card *card = platform_get_drvdata(pdev);
966 platform_set_drvdata(pdev,
NULL);
971 .probe = snd_sgio2audio_probe,
974 .name =
"sgio2audio",