39 #include <linux/slab.h>
40 #include <linux/time.h>
41 #include <linux/wait.h>
43 #include <linux/module.h>
83 #define NAME "harmony"
86 static unsigned int snd_harmony_rates[] = {
87 5512, 6615, 8000, 9600,
88 11025, 16000, 18900, 22050,
89 27428, 32000, 33075, 37800,
93 static unsigned int rate_bits[14] = {
103 .list = snd_harmony_rates,
107 static inline unsigned long
137 harmony_wait_for_control(h);
147 harmony_wait_for_control(h);
159 harmony_wait_for_control(h);
161 spin_unlock_irqrestore(&h->
mixer_lock, flags);
170 harmony_wait_for_control(h);
172 spin_unlock_irqrestore(&h->
mixer_lock, flags);
184 (h->
st.format << 6) |
185 (h->
st.stereo << 5) |
188 harmony_wait_for_control(h);
191 spin_unlock_irqrestore(&h->
lock, flags);
195 snd_harmony_interrupt(
int irq,
void *
dev)
201 harmony_disable_interrupts(h);
202 harmony_wait_for_control(h);
204 spin_unlock(&h->
lock);
207 if (h->
psubs && h->
st.playing) {
214 h->
stats.play_intr++;
215 spin_unlock(&h->
lock);
220 h->
stats.silence_intr++;
221 spin_unlock(&h->
lock);
226 if (h->
csubs && h->
st.capturing) {
234 spin_unlock(&h->
lock);
239 h->
stats.graveyard_intr++;
240 spin_unlock(&h->
lock);
245 harmony_enable_interrupts(h);
246 spin_unlock(&h->
lock);
252 snd_harmony_rate_bits(
int rate)
256 for (i = 0; i <
ARRAY_SIZE(snd_harmony_rates); i++)
257 if (snd_harmony_rates[i] == rate)
320 harmony_enable_interrupts(h);
326 harmony_disable_interrupts(h);
332 spin_unlock(&h->
lock);
336 spin_unlock(&h->
lock);
356 harmony_enable_interrupts(h);
362 harmony_disable_interrupts(h);
368 spin_unlock(&h->
lock);
372 spin_unlock(&h->
lock);
380 int o = h->
st.format;
398 if (force || o != n) {
416 h->
pbuf.size = snd_pcm_lib_buffer_bytes(ss);
417 h->
pbuf.count = snd_pcm_lib_period_bytes(ss);
422 h->
st.rate = snd_harmony_rate_bits(rt->
rate);
423 h->
st.format = snd_harmony_set_data_format(h, rt->
format, 0);
430 harmony_set_control(h);
446 h->
cbuf.size = snd_pcm_lib_buffer_bytes(ss);
447 h->
cbuf.count = snd_pcm_lib_period_bytes(ss);
452 h->
st.rate = snd_harmony_rate_bits(rt->
rate);
453 h->
st.format = snd_harmony_set_data_format(h, rt->
format, 0);
460 harmony_set_control(h);
472 unsigned long pcuradd;
473 unsigned long played;
478 if ((h->
pbuf.addr == 0) || (h->
pbuf.size == 0))
482 played = pcuradd - h->
pbuf.addr;
486 pcuradd, h->
pbuf.addr, played);
489 if (pcuradd > h->
pbuf.addr + h->
pbuf.size) {
493 return bytes_to_frames(rt, played);
501 unsigned long rcuradd;
502 unsigned long caught;
507 if ((h->
cbuf.addr == 0) || (h->
cbuf.size == 0))
511 caught = rcuradd - h->
cbuf.addr;
515 rcuradd, h->
cbuf.addr, caught);
518 if (rcuradd > h->
cbuf.addr + h->
cbuf.size) {
522 return bytes_to_frames(rt, caught);
533 rt->
hw = snd_harmony_playback;
535 &hw_constraint_rates);
552 rt->
hw = snd_harmony_capture;
554 &hw_constraint_rates);
599 static struct snd_pcm_ops snd_harmony_playback_ops = {
600 .open = snd_harmony_playback_open,
601 .close = snd_harmony_playback_close,
603 .hw_params = snd_harmony_hw_params,
604 .hw_free = snd_harmony_hw_free,
605 .prepare = snd_harmony_playback_prepare,
606 .trigger = snd_harmony_playback_trigger,
607 .pointer = snd_harmony_playback_pointer,
610 static struct snd_pcm_ops snd_harmony_capture_ops = {
611 .open = snd_harmony_capture_open,
612 .close = snd_harmony_capture_close,
614 .hw_params = snd_harmony_hw_params,
615 .hw_free = snd_harmony_hw_free,
616 .prepare = snd_harmony_capture_prepare,
617 .trigger = snd_harmony_capture_trigger,
618 .pointer = snd_harmony_capture_pointer,
630 harmony_disable_interrupts(h);
637 &snd_harmony_playback_ops);
639 &snd_harmony_capture_ops);
651 h->
dma.dev = &h->
dev->dev;
681 h->
st.format = snd_harmony_set_data_format(h,
690 harmony_wait_for_control(h);
704 uinfo->
count = left_shift == right_shift ? 1 : 2;
724 left = (h->
st.gain >> shift_left) & mask;
728 right = mask -
right;
732 if (shift_left != shift_right)
750 int old_gain = h->
st.gain;
754 left = ucontrol->
value.integer.value[0] &
mask;
757 h->
st.gain &= ~( (mask << shift_left ) );
758 h->
st.gain |= (left << shift_left);
760 if (shift_left != shift_right) {
761 right = ucontrol->
value.integer.value[1] &
mask;
763 right = mask -
right;
768 snd_harmony_set_new_gain(h);
772 return h->
st.gain != old_gain;
779 static char *texts[2] = {
"Line",
"Mic" };
813 int old_gain = h->
st.gain;
817 value = ucontrol->
value.enumerated.item[0] & 1;
821 snd_harmony_set_new_gain(h);
825 return h->
st.gain != old_gain;
828 #define HARMONY_CONTROLS ARRAY_SIZE(snd_harmony_controls)
830 #define HARMONY_VOLUME(xname, left_shift, right_shift, mask, invert) \
831 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
832 .info = snd_harmony_mixercontrol_info, \
833 .get = snd_harmony_volume_get, .put = snd_harmony_volume_put, \
834 .private_value = ((left_shift) | ((right_shift) << 8) | \
835 ((mask) << 16) | ((invert) << 24)) }
846 .name =
"Input Route",
847 .info = snd_harmony_captureroute_info,
848 .get = snd_harmony_captureroute_get,
849 .put = snd_harmony_captureroute_put
886 snd_harmony_mixer_reset(h);
905 parisc_set_drvdata(h->
dev,
NULL);
915 return snd_harmony_free(h);
919 snd_harmony_create(
struct snd_card *card,
926 .dev_free = snd_harmony_dev_free,
935 h->
hpa = padev->
hpa.start;
942 (
unsigned long)padev->
hpa.start);
986 err = snd_harmony_create(card, padev, &h);
990 err = snd_harmony_pcm_init(h);
994 err = snd_harmony_mixer_init(h);
1007 parisc_set_drvdata(padev, card);
1019 parisc_set_drvdata(padev,
NULL);
1025 .id_table = snd_harmony_devtable,
1026 .probe = snd_harmony_probe,
1031 alsa_harmony_init(
void)
1037 alsa_harmony_fini(
void)