31 #define DEBUG_MIXER 16
32 #define DEBUG_TRIGGER 32
36 #include <linux/module.h>
38 #include <linux/slab.h>
39 #include <linux/sched.h>
43 #include <linux/bitops.h>
50 #include <mach/hardware.h>
58 #define SUPPORTED_MIXER_DEVICES (SOUND_MASK_SYNTH |\
113 #ifdef CONFIG_ARCH_NETWINDER
114 signed int slider_vol;
115 unsigned int handset_detect :1;
116 unsigned int telephone_detect:1;
117 unsigned int no_autoselect :1;
118 unsigned int spkr_mute_state :1;
119 unsigned int line_mute_state :1;
120 unsigned int use_slider :1;
133 unsigned char *,
unsigned char *);
146 static int nr_waveartist_devs;
150 #ifndef CONFIG_ARCH_NETWINDER
151 #define machine_is_netwinder() 0
154 static void vnc_configure_mixer(
wavnc_info *devc,
unsigned int input_mask);
155 static int vnc_private_ioctl(
int dev,
unsigned int cmd,
int __user *
arg);
156 static void vnc_slider_tick(
unsigned long data);
164 clear = ~clear &
inb(ctlr_port);
166 outb(clear |
set, ctlr_port);
174 unsigned int ctlr_port = devc->
hw.io_base +
CTLR;
180 outb(old_ctlr, ctlr_port);
196 waveartist_set_ctlr(hw, -1,
RESET);
198 waveartist_set_ctlr(hw,
RESET, 0);
213 if (res != (
unsigned int)-1)
214 printk(
"(res=%04X)", res);
227 int nr_cmd,
unsigned int *
cmd,
228 int nr_resp,
unsigned int *
resp)
231 unsigned int timed_out = 0;
235 printk(
"waveartist_cmd: cmd=");
237 for (i = 0; i < nr_cmd; i++)
243 if (
inb(io_base +
STATR) & CMD_RF) {
249 old_data =
inw(io_base +
CMDR);
252 printk(
"flushed %04X...", old_data);
257 for (i = 0; !timed_out && i < nr_cmd; i++) {
260 for (count = 5000;
count; count--)
270 for (i = 0; !timed_out && i < nr_resp; i++) {
273 for (count = 5000;
count; count--)
285 printk(
"waveartist_cmd: resp=");
287 for (i = 0; i < nr_resp; i++)
292 printk(
"waveartist_cmd: timed out\n");
295 return timed_out ? 1 : 0;
302 waveartist_cmd1(
wavnc_info *devc,
unsigned int cmd)
304 return waveartist_cmd(devc, 1, &cmd, 0,
NULL);
310 static inline unsigned int
311 waveartist_cmd1_r(
wavnc_info *devc,
unsigned int cmd)
315 waveartist_cmd(devc, 1, &cmd, 1, &ret);
325 waveartist_cmd2(
wavnc_info *devc,
unsigned int cmd,
unsigned int arg)
327 unsigned int vals[2];
332 return waveartist_cmd(devc, 2, vals, 1, vals);
339 waveartist_cmd3(
wavnc_info *devc,
unsigned int cmd,
340 unsigned int arg1,
unsigned int arg2)
342 unsigned int vals[3];
348 return waveartist_cmd(devc, 3, vals, 0,
NULL);
354 unsigned int temp[2];
357 waveartist_cmd(devc, 1, &cmd, 2, temp);
359 rev[0] = temp[0] >> 8;
360 rev[1] = temp[0] & 255;
366 static void waveartist_halt_output(
int dev);
367 static void waveartist_halt_input(
int dev);
368 static void waveartist_halt(
int dev);
369 static void waveartist_trigger(
int dev,
int state);
372 waveartist_open(
int dev,
int mode)
386 spin_unlock_irqrestore(&waveartist_lock, flags);
393 waveartist_trigger(dev, 0);
399 spin_unlock_irqrestore(&waveartist_lock, flags);
405 waveartist_close(
int dev)
413 waveartist_halt(dev);
419 spin_unlock_irqrestore(&waveartist_lock, flags);
423 waveartist_output_block(
int dev,
unsigned long buf,
int __count,
int intrflag)
428 unsigned int count = __count;
431 printk(
"waveartist: output block, buf=0x%lx, count=0x%x...\n",
464 spin_unlock_irqrestore(&waveartist_lock, flags);
468 waveartist_start_input(
int dev,
unsigned long buf,
int __count,
int intrflag)
473 unsigned int count = __count;
476 printk(
"waveartist: start input, buf=0x%lx, count=0x%x...\n",
507 spin_unlock_irqrestore(&waveartist_lock, flags);
511 waveartist_ioctl(
int dev,
unsigned int cmd,
void __user *
arg)
524 if (portc->
speed == 8000)
526 else if (portc->
speed == 11025)
528 else if (portc->
speed == 22050)
530 else if (portc->
speed == 44100)
536 speed = portc->
speed << 16;
538 speed = (speed / 44100) & 65535;
560 waveartist_prepare_for_input(
int dev,
int bsize,
int bcount)
565 unsigned int speed,
bits;
570 speed = waveartist_get_speed(portc);
571 bits = waveartist_get_bits(portc);
581 "to %d channels\n", portc->
channels);
588 "speed to %dHz.\n", portc->
speed);
592 "data path to 0x%X\n", 1);
599 spin_unlock_irqrestore(&waveartist_lock, flags);
600 waveartist_halt_input(dev);
603 printk(
"WA CTLR reg: 0x%02X.\n",
605 printk(
"WA STAT reg: 0x%02X.\n",
607 printk(
"WA IRQS reg: 0x%02X.\n",
615 waveartist_prepare_for_output(
int dev,
int bsize,
int bcount)
620 unsigned int speed,
bits;
625 speed = waveartist_get_speed(portc);
626 bits = waveartist_get_bits(portc);
633 "speed to %dHz.\n", portc->
speed);
637 "to %d channels\n", portc->
channels);
641 "data path to 0x%X\n", 0);
648 spin_unlock_irqrestore(&waveartist_lock, flags);
649 waveartist_halt_output(dev);
661 waveartist_halt(
int dev)
667 waveartist_halt_output(dev);
670 waveartist_halt_input(dev);
677 waveartist_halt_input(
int dev)
696 waveartist_iack(devc);
700 spin_unlock_irqrestore(&waveartist_lock, flags);
704 waveartist_halt_output(
int dev)
720 waveartist_iack(devc);
724 spin_unlock_irqrestore(&waveartist_lock, flags);
728 waveartist_trigger(
int dev,
int state)
735 printk(
"wavnc: audio trigger ");
748 state & PCM_ENABLE_INPUT)
761 spin_unlock_irqrestore(&waveartist_lock, flags);
765 waveartist_set_speed(
int dev,
int arg)
783 waveartist_set_channels(
int dev,
short arg)
787 if (arg != 1 && arg != 2)
795 waveartist_set_bits(
int dev,
unsigned int arg)
812 .open = waveartist_open,
813 .close = waveartist_close,
814 .output_block = waveartist_output_block,
815 .start_input = waveartist_start_input,
816 .ioctl = waveartist_ioctl,
817 .prepare_for_input = waveartist_prepare_for_input,
818 .prepare_for_output = waveartist_prepare_for_output,
819 .halt_io = waveartist_halt,
820 .halt_input = waveartist_halt_input,
821 .halt_output = waveartist_halt_output,
822 .trigger = waveartist_trigger,
823 .set_speed = waveartist_set_speed,
824 .set_bits = waveartist_set_bits,
825 .set_channels = waveartist_set_channels
830 waveartist_intr(
int irq,
void *
dev_id)
835 spin_lock(&waveartist_lock);
840 printk(
"waveartist_intr: stat=%02x, irqstat=%02x\n",
844 waveartist_iack(devc);
848 if (irqstatus & 0x01) {
867 spin_unlock(&waveartist_lock);
915 waveartist_mixer_update(
wavnc_info *devc,
int whichDev)
917 unsigned int lev_left, lev_right;
919 lev_left = devc->
levels[whichDev] & 0xff;
920 lev_right = devc->
levels[whichDev] >> 8;
927 #define SCALE(lev,max) ((lev) * (max) / 100)
932 if (mix_devs[whichDev].
reg_l || mix_devs[whichDev].
reg_r) {
933 const struct mix_ent *
mix = mix_devs + whichDev;
948 left = (left & ~mask) | (lev_left & mask);
949 right = (right & ~mask) | (lev_right & mask);
957 SCALE(lev_left, 32767),
958 SCALE(lev_right, 32767));
963 SCALE(lev_left, 32767),
964 SCALE(lev_right, 32767));
976 waveartist_set_adc_mux(
wavnc_info *devc,
char left_dev,
char right_dev)
978 unsigned int reg_08, reg_09;
983 reg_08 = (reg_08 & ~0x3f) | right_dev << 3 | left_dev;
999 waveartist_select_input(
wavnc_info *devc,
unsigned int recmask,
1000 unsigned char *dev_l,
unsigned char *dev_r)
1021 *dev_l = *dev_r = recdev;
1027 waveartist_decode_mixer(
wavnc_info *devc,
int dev,
unsigned char lev_l,
1028 unsigned char lev_r)
1053 static int waveartist_get_mixer(
wavnc_info *devc,
int dev)
1061 SOUND_MASK_LINE1 | SOUND_MASK_LINE2 |
1065 .select_input = waveartist_select_input,
1066 .decode_mixer = waveartist_decode_mixer,
1067 .get_mixer = waveartist_get_mixer,
1071 waveartist_set_recmask(
wavnc_info *devc,
unsigned int recmask)
1073 unsigned char dev_l, dev_r;
1075 recmask &= devc->
mix->recording_devs;
1088 devc->
recmask = devc->
mix->select_input(devc, recmask,
1091 waveartist_set_adc_mux(devc, dev_l, dev_r);
1097 unsigned int lev_left = level & 0x00ff;
1098 unsigned int lev_right = (level & 0xff00) >> 8;
1102 if (lev_right > 100)
1109 if (!(devc->
mix->stereo_devs & (1 << dev)))
1110 lev_right = lev_left;
1112 dev = devc->
mix->decode_mixer(devc, dev, lev_left, lev_right);
1115 waveartist_mixer_update(devc, dev);
1117 return dev < 0 ? dev : 0;
1121 waveartist_mixer_ioctl(
int dev,
unsigned int cmd,
void __user * arg)
1129 if (((cmd >> 8) & 255) !=
'M')
1132 #ifdef CONFIG_ARCH_NETWINDER
1134 ret = vnc_private_ioctl(dev, cmd, arg);
1150 waveartist_set_recmask(devc,
val);
1156 devc->
mix->supported_devs & (1 << nr))
1157 ret = waveartist_set_mixer(devc, nr,
val);
1170 ret = devc->
mix->supported_devs;
1174 ret = devc->
mix->stereo_devs;
1178 ret = devc->
mix->recording_devs;
1187 ret = devc->
mix->get_mixer(devc, nr);
1202 .name =
"WaveArtist",
1203 .ioctl = waveartist_mixer_ioctl
1212 printk(
"%s: mixer_reset\n", devc->
hw.name);
1238 waveartist_set_recmask(devc, 0);
1241 waveartist_mixer_update(devc, i);
1247 char rev[3], dev_name[64];
1250 if (waveartist_reset(devc))
1255 if (waveartist_getrev(devc, rev)) {
1256 strcat(dev_name,
" rev. ");
1262 devc->
hw.dma, devc->
hw.dma2);
1271 devc, devc->
hw.dma, devc->
hw.dma2);
1278 waveartist_mixer_reset(devc);
1283 waveartist_iack(devc);
1285 if (
request_irq(devc->
hw.irq, waveartist_intr, 0, devc->
hw.name, devc) < 0) {
1287 devc->
hw.name, devc->
hw.irq);
1293 devc->
hw.name, devc->
hw.dma);
1297 if (devc->
hw.dma != devc->
hw.dma2 && devc->
hw.dma2 !=
NO_DMA)
1300 devc->
hw.name, devc->
hw.dma2);
1309 &waveartist_mixer_operations,
1333 wavnc_info *devc = &adev_info[nr_waveartist_devs];
1345 if (hw_config->
irq > 15 || hw_config->
irq < 0) {
1352 if (hw_config->
dma != 3) {
1359 hw_config->
name =
"WaveArtist";
1360 devc->
hw = *hw_config;
1370 wavnc_info *devc = &adev_info[nr_waveartist_devs];
1378 devc->
hw.irq = (hw->
irq > 0) ? hw->
irq : 0;
1389 devc->
dev_no = waveartist_init(devc);
1394 #ifdef CONFIG_ARCH_NETWINDER
1397 vnc_timer.function = vnc_slider_tick;
1399 vnc_timer.data = nr_waveartist_devs;
1402 vnc_configure_mixer(devc, 0);
1404 devc->no_autoselect = 1;
1407 nr_waveartist_devs += 1;
1416 for (i = 0; i < nr_waveartist_devs; i++)
1417 if (hw->
io_base == adev_info[i].
hw.io_base) {
1418 devc = adev_info +
i;
1425 #ifdef CONFIG_ARCH_NETWINDER
1434 if (devc->
hw.irq >= 0)
1439 if (devc->
hw.dma != devc->
hw.dma2 &&
1451 nr_waveartist_devs -= 1;
1453 for (; i < nr_waveartist_devs; i++)
1454 adev_info[i] = adev_info[i + 1];
1460 #ifdef CONFIG_ARCH_NETWINDER
1468 #define VNC_TIMER_PERIOD (HZ/4) //check slider 4 times/sec
1470 #define MIXER_PRIVATE3_RESET 0x53570000
1471 #define MIXER_PRIVATE3_READ 0x53570001
1472 #define MIXER_PRIVATE3_WRITE 0x53570002
1474 #define VNC_MUTE_INTERNAL_SPKR 0x01 //the sw mute on/off control bit
1475 #define VNC_MUTE_LINE_OUT 0x10
1476 #define VNC_PHONE_DETECT 0x20
1477 #define VNC_HANDSET_DETECT 0x40
1478 #define VNC_DISABLE_AUTOSWITCH 0x80
1483 unsigned long flags;
1498 if (devc->line_mute_state) {
1512 static signed int old_slider_volume;
1513 unsigned long flags;
1523 while (volume && (
inb(0x201) & 0x01))
1528 spin_unlock_irqrestore(&waveartist_lock,flags);
1534 volume = 150 - (volume >> 5);
1536 volume = (volume >> 6) - 25;
1548 if (
abs(volume - old_slider_volume) > 7) {
1549 old_slider_volume =
volume;
1555 return old_slider_volume;
1570 netwinder_select_input(
wavnc_info *devc,
unsigned int recmask,
1571 unsigned char *dev_l,
unsigned char *dev_r)
1575 if (recmask & SOUND_MASK_IMIX) {
1579 }
else if (recmask & SOUND_MASK_LINE) {
1583 }
else if (recmask & SOUND_MASK_LINE1) {
1607 netwinder_decode_mixer(
wavnc_info *devc,
int dev,
unsigned char lev_l,
1608 unsigned char lev_r)
1646 static int netwinder_get_mixer(
wavnc_info *devc,
int dev)
1661 levels |= levels << 8;
1666 levels |= levels << 8;
1671 levels |= levels << 8;
1688 SOUND_MASK_IMIX | SOUND_MASK_LINE1 |
1693 SOUND_MASK_IMIX | SOUND_MASK_LINE1 |
1700 .select_input = netwinder_select_input,
1701 .decode_mixer = netwinder_decode_mixer,
1702 .get_mixer = netwinder_get_mixer,
1706 vnc_configure_mixer(
wavnc_info *devc,
unsigned int recmask)
1708 if (!devc->no_autoselect) {
1709 if (devc->handset_detect) {
1711 devc->spkr_mute_state = devc->line_mute_state = 1;
1712 }
else if (devc->telephone_detect) {
1714 devc->spkr_mute_state = devc->line_mute_state = 1;
1719 if ((devc->
recmask & SOUND_MASK_LINE) == 0)
1721 devc->spkr_mute_state = devc->line_mute_state = 0;
1723 vnc_mute_spkr(devc);
1724 vnc_mute_lout(devc);
1727 waveartist_set_recmask(devc, recmask);
1734 signed int slider_volume;
1735 unsigned int temp, old_hs, old_td;
1744 old_hs = devc->handset_detect;
1745 old_td = devc->telephone_detect;
1747 devc->handset_detect = !(temp & 0x10);
1748 devc->telephone_detect = !!(temp & 0x20);
1750 if (!devc->no_autoselect &&
1751 (old_hs != devc->handset_detect ||
1752 old_td != devc->telephone_detect))
1753 vnc_configure_mixer(devc, devc->
recmask);
1755 slider_volume = vnc_volume_slider(devc);
1762 if (
abs(devc->slider_vol - slider_volume) > 20)
1763 devc->use_slider = 1;
1770 if (slider_volume != temp && devc->use_slider) {
1771 devc->slider_vol = slider_volume;
1774 slider_volume | slider_volume << 8);
1783 vnc_slider_tick(
unsigned long data)
1787 if (vnc_slider(adev_info + data))
1790 next_timeout = VNC_TIMER_PERIOD;
1792 mod_timer(&vnc_timer, jiffies + next_timeout);
1796 vnc_private_ioctl(
int dev,
unsigned int cmd,
int __user * arg)
1804 u_int prev_spkr_mute, prev_line_mute, prev_auto_state;
1811 if (val & ~(VNC_MUTE_INTERNAL_SPKR |
1813 VNC_DISABLE_AUTOSWITCH))
1816 prev_auto_state = devc->no_autoselect;
1817 prev_spkr_mute = devc->spkr_mute_state;
1818 prev_line_mute = devc->line_mute_state;
1820 devc->no_autoselect = (val & VNC_DISABLE_AUTOSWITCH) ? 1 : 0;
1821 devc->spkr_mute_state = (val & VNC_MUTE_INTERNAL_SPKR) ? 1 : 0;
1822 devc->line_mute_state = (val & VNC_MUTE_LINE_OUT) ? 1 : 0;
1824 if (prev_spkr_mute != devc->spkr_mute_state)
1825 vnc_mute_spkr(devc);
1827 if (prev_line_mute != devc->line_mute_state)
1828 vnc_mute_lout(devc);
1830 if (prev_auto_state != devc->no_autoselect)
1831 vnc_configure_mixer(devc, devc->
recmask);
1841 #define VNC_SOUND_PAUSE 0x53 //to pause the DSP
1842 #define VNC_SOUND_RESUME 0x57 //to unpause the DSP
1843 case VNC_SOUND_PAUSE:
1844 waveartist_cmd1(devc, 0x16);
1847 case VNC_SOUND_RESUME:
1848 waveartist_cmd1(devc, 0x18);
1859 unsigned long flags;
1860 int mixer_reg[15],
i,
val;
1867 switch (mixer_reg[14]) {
1868 case MIXER_PRIVATE3_RESET:
1869 waveartist_mixer_reset(devc);
1872 case MIXER_PRIVATE3_WRITE:
1883 case MIXER_PRIVATE3_READ:
1886 for (i = 0x30; i < 14 << 8; i += 1 << 8)
1887 waveartist_cmd(devc, 1, &i, 1, mixer_reg + (i >> 8));
1889 spin_unlock_irqrestore(&waveartist_lock, flags);
1891 if (
copy_to_user((
void *)val, mixer_reg,
sizeof(mixer_reg)))
1903 val = (devc->spkr_mute_state ? VNC_MUTE_INTERNAL_SPKR : 0) |
1904 (devc->line_mute_state ? VNC_MUTE_LINE_OUT : 0) |
1905 (devc->handset_detect ? VNC_HANDSET_DETECT : 0) |
1906 (devc->telephone_detect ? VNC_PHONE_DETECT : 0) |
1907 (devc->no_autoselect ? VNC_DISABLE_AUTOSWITCH : 0);
1922 devc->use_slider = 0;
1926 unsigned int val,
l,
r;
1932 r = (val & 0x7f00) >> 8;
1935 devc->spkr_mute_state = (val <= 50);
1936 vnc_mute_spkr(devc);
1948 static int attached;
1956 static int __init init_waveartist(
void)
1972 mix = &waveartist_mixer;
1973 #ifdef CONFIG_ARCH_NETWINDER
1975 mix = &netwinder_mixer;
1983 if (!probe_waveartist(&
cfg))
1986 attach_waveartist(&
cfg, mix);
1992 static void __exit cleanup_waveartist(
void)
1995 unload_waveartist(&
cfg);
2002 static int __init setup_waveartist(
char *
str)
2016 __setup(
"waveartist=", setup_waveartist);