36 #include <linux/kernel.h>
37 #include <linux/module.h>
38 #include <linux/types.h>
55 # ifdef CONFIG_MSNDCLAS_HAVE_BOOT
56 # define HAVE_DSPCODEH
59 # define LOGNAME "msnd_classic"
61 # ifdef CONFIG_MSNDPIN_HAVE_BOOT
62 # define HAVE_DSPCODEH
65 # define LOGNAME "msnd_pinnacle"
68 #ifndef CONFIG_MSND_WRITE_NDELAY
69 # define CONFIG_MSND_WRITE_NDELAY 1
72 #define get_play_delay_jiffies(size) ((size) * HZ * \
73 dev.play_sample_size / 8 / \
74 dev.play_sample_rate / \
77 #define get_rec_delay_jiffies(size) ((size) * HZ * \
78 dev.rec_sample_size / 8 / \
79 dev.rec_sample_rate / \
86 static char *dspini, *permini;
87 static int sizeof_dspini, sizeof_permini;
90 static int dsp_full_reset(
void);
91 static void dsp_write_flush(
void);
101 static void reset_play_queue(
void)
122 static void reset_record_queue(
void)
137 spin_unlock_irqrestore(&dev.
lock, flags);
151 static void reset_queues(
void)
159 reset_record_queue();
163 static int dsp_set_format(
struct file *
file,
int val)
195 static int dsp_get_frag_size(
void)
199 if (size > 32 * 1024)
204 static int dsp_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
232 abinfo.
fragsize = dsp_get_frag_size();
236 spin_unlock_irqrestore(&dev.
lock, flags);
243 abinfo.
fragsize = dsp_get_frag_size();
247 spin_unlock_irqrestore(&dev.
lock, flags);
260 tmp = dsp_get_frag_size();
278 : dsp_set_format(file, val);
282 : dsp_set_format(file, val);
376 static int mixer_get(
int d)
398 #define update_volm(a,b) \
399 writew((dev.left_levels[a] >> 1) * \
400 readw(dev.SMA + SMA_wCurrMastVolLeft) / 0xffff, \
401 dev.SMA + SMA_##b##Left); \
402 writew((dev.right_levels[a] >> 1) * \
403 readw(dev.SMA + SMA_wCurrMastVolRight) / 0xffff, \
404 dev.SMA + SMA_##b##Right);
406 #define update_potm(d,s,ar) \
407 writeb((dev.left_levels[d] >> 8) * \
408 readw(dev.SMA + SMA_wCurrMastVolLeft) / 0xffff, \
409 dev.SMA + SMA_##s##Left); \
410 writeb((dev.right_levels[d] >> 8) * \
411 readw(dev.SMA + SMA_wCurrMastVolRight) / 0xffff, \
412 dev.SMA + SMA_##s##Right); \
413 if (msnd_send_word(&dev, 0, 0, ar) == 0) \
414 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
416 #define update_pot(d,s,ar) \
417 writeb(dev.left_levels[d] >> 8, \
418 dev.SMA + SMA_##s##Left); \
419 writeb(dev.right_levels[d] >> 8, \
420 dev.SMA + SMA_##s##Right); \
421 if (msnd_send_word(&dev, 0, 0, ar) == 0) \
422 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
424 static int mixer_set(
int d,
int value)
426 int left = value & 0x000000ff;
427 int right = (value & 0x0000ff00) >> 8;
430 int updatemaster = 0;
435 bLeft = left * 0xff / 100;
436 wLeft = left * 0xffff / 100;
438 bRight = right * 0xff / 100;
439 wRight = right * 0xffff / 100;
496 static void mixer_setup(
void)
508 static unsigned long set_recsrc(
unsigned long recsrc)
513 else if (recsrc == 0)
547 static unsigned long force_recsrc(
unsigned long recsrc)
550 return set_recsrc(recsrc);
553 #define set_mixer_info() \
554 memset(&info, 0, sizeof(info)); \
555 strlcpy(info.id, "MSNDMIXER", sizeof(info.id)); \
556 strlcpy(info.name, "MultiSound Mixer", sizeof(info.name));
558 static int mixer_ioctl(
unsigned int cmd,
unsigned long arg)
577 }
else if (((cmd >> 8) & 0xff) ==
'M') {
581 switch (cmd & 0xff) {
585 val = set_recsrc(val);
591 val = mixer_set(cmd & 0xff, val);
597 switch (cmd & 0xff) {
631 if ((val = mixer_get(cmd & 0xff)) < 0)
643 static long dev_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
650 return put_user(sound_version, (
int __user *)arg);
657 ret = dsp_ioctl(file, cmd, arg);
659 ret = mixer_ioctl(cmd, arg);
665 static void dsp_write_flush(
void)
674 if (!signal_pending(
current)) {
681 static void dsp_halt(
struct file *file)
689 dev.
mode &= ~FMODE_READ;
701 dev.
mode &= ~FMODE_WRITE;
707 static int dsp_release(
struct file *file)
713 static int dsp_open(
struct file *file)
715 if ((file ? file->
f_mode : dev.
mode) & FMODE_WRITE) {
726 if ((file ? file->
f_mode : dev.
mode) & FMODE_READ) {
730 reset_record_queue();
740 static void set_default_play_audio_parameters(
void)
747 static void set_default_rec_audio_parameters(
void)
754 static void set_default_audio_parameters(
void)
756 set_default_play_audio_parameters();
757 set_default_rec_audio_parameters();
762 int minor = iminor(inode);
767 if ((file->
f_mode & FMODE_WRITE &&
769 (file->
f_mode & FMODE_READ &&
775 if ((err = dsp_open(file)) >= 0) {
777 if (file->
f_mode & FMODE_WRITE) {
778 set_default_play_audio_parameters();
784 if (file->
f_mode & FMODE_READ) {
785 set_default_rec_audio_parameters();
799 static int dev_release(
struct inode *inode,
struct file *file)
801 int minor = iminor(inode);
806 err = dsp_release(file);
815 static __inline__ int pack_DARQ_to_DARF(
register int bank)
849 register WORD DAPQ_tail;
867 spin_unlock_irqrestore(&dev.
lock, flags);
896 static int dsp_read(
char __user *
buf,
size_t len)
915 spin_unlock_irqrestore(&dev.
lock, flags);
954 static int dsp_write(
const char __user *buf,
size_t len)
978 spin_unlock_irqrestore(&dev.
lock, flags);
987 if (pack_DAPF_to_DAPQ(1) > 0)
1002 if (signal_pending(
current)) {
1013 static ssize_t dev_read(
struct file *file,
char __user *buf,
size_t count, loff_t *off)
1015 int minor = iminor(file->
f_path.dentry->d_inode);
1017 return dsp_read(buf, count);
1022 static ssize_t dev_write(
struct file *file,
const char __user *buf,
size_t count, loff_t *off)
1024 int minor = iminor(file->
f_path.dentry->d_inode);
1026 return dsp_write(buf, count);
1033 switch (
HIBYTE(wMessage)) {
1039 if (pack_DAPF_to_DAPQ(0) <= 0) {
1063 switch (
LOBYTE(wMessage)) {
1064 #ifndef MSND_CLASSIC
1120 .release = dev_release,
1124 static int reset_dsp(
void)
1130 #ifndef MSND_CLASSIC
1135 while (timeout-- > 0) {
1145 static int __init probe_multisound(
void)
1147 #ifndef MSND_CLASSIC
1149 char *
pin =
"Pinnacle", *fiji =
"Fiji";
1150 char *pinfiji =
"Pinnacle/Fiji";
1158 if (reset_dsp() < 0) {
1164 dev.
name =
"Classic/Tahiti/Monterey";
1167 switch (dev.
info >> 4) {
1168 case 0xf: xv =
"<= 1.15";
break;
1169 case 0x1: xv =
"1.18/1.2";
break;
1170 case 0x2: xv =
"1.3";
break;
1171 case 0x3: xv =
"1.4";
break;
1172 default: xv =
"unknown";
break;
1175 switch (dev.
info & 0x7) {
1176 case 0x0: rev =
"I"; dev.
name = pin;
break;
1177 case 0x1: rev =
"F"; dev.
name = pin;
break;
1178 case 0x2: rev =
"G"; dev.
name = pin;
break;
1179 case 0x3: rev =
"H"; dev.
name = pin;
break;
1180 case 0x4: rev =
"E"; dev.
name = fiji;
break;
1181 case 0x5: rev =
"C"; dev.
name = fiji;
break;
1182 case 0x6: rev =
"D"; dev.
name = fiji;
break;
1184 rev =
"A-B (Fiji) or A-E (Pinnacle)";
1190 "I/O 0x%x-0x%x, IRQ %d, memory mapped to %p-%p\n",
1203 static int init_sma(
void)
1206 WORD mastVolLeft, mastVolRight;
1207 unsigned long flags;
1217 mastVolLeft = mastVolRight = 0;
1225 spin_unlock_irqrestore(&dev.
lock, flags);
1255 #ifndef MSND_CLASSIC
1264 #ifndef MSND_CLASSIC
1295 static int upload_dsp_code(
void)
1300 #ifndef HAVE_DSPCODEH
1320 #ifdef HAVE_DSPCODEH
1327 #ifndef HAVE_DSPCODEH
1336 static void reset_proteus(
void)
1355 if ((err = init_sma()) < 0) {
1360 if ((err = reset_dsp()) < 0)
1363 if ((err = upload_dsp_code()) < 0) {
1382 static int dsp_full_reset(
void)
1394 force_recsrc(dev.
recsrc);
1401 static int __init attach_multisound(
void)
1414 err = dsp_full_reset();
1449 #ifndef MSND_CLASSIC
1456 static void __exit unload_multisound(
void)
1465 #ifndef MSND_CLASSIC
1480 static int __init msnd_write_cfg_io0(
int cfg,
int num,
WORD io)
1491 static int __init msnd_write_cfg_io1(
int cfg,
int num,
WORD io)
1502 static int __init msnd_write_cfg_irq(
int cfg,
int num,
WORD irq)
1513 static int __init msnd_write_cfg_mem(
int cfg,
int num,
int mem)
1531 static int __init msnd_activate_logical(
int cfg,
int num)
1540 static int __init msnd_write_cfg_logical(
int cfg,
int num,
WORD io0,
WORD io1,
WORD irq,
int mem)
1544 if (msnd_write_cfg_io0(cfg, num, io0))
1546 if (msnd_write_cfg_io1(cfg, num, io1))
1548 if (msnd_write_cfg_irq(cfg, num, irq))
1550 if (msnd_write_cfg_mem(cfg, num, mem))
1552 if (msnd_activate_logical(cfg, num))
1569 for (i = 0; i < 4; ++
i)
1570 if (msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0))
1575 for (i = 0; i < 4; ++
i) {
1579 if (!(device[i].io0 && device[i].irq && device[i].mem))
1583 if (!(device[i].io0 && device[i].irq))
1586 ": Configuring MPU to I/O 0x%x IRQ %d\n",
1587 device[i].io0, device[i].irq);
1590 if (!(device[i].io0 && device[i].io1 && device[i].irq))
1593 ": Configuring IDE to I/O 0x%x, 0x%x IRQ %d\n",
1594 device[i].io0, device[i].io1, device[i].irq);
1597 if (!(device[i].io0))
1600 ": Configuring joystick to I/O 0x%x\n",
1606 if (msnd_write_cfg_logical(cfg, i, device[i].io0, device[i].io1, device[i].irq, device[i].mem))
1620 static int irq __initdata = -1;
1621 static int mem __initdata = -1;
1622 static int write_ndelay __initdata = -1;
1624 #ifndef MSND_CLASSIC
1626 static int cfg __initdata = -1;
1629 static int reset __initdata = 0;
1630 static int mpu_io __initdata = 0;
1631 static int mpu_irq __initdata = 0;
1632 static int ide_io0 __initdata = 0;
1633 static int ide_io1 __initdata = 0;
1634 static int ide_irq __initdata = 0;
1635 static int joystick_io __initdata = 0;
1638 static bool digital __initdata =
false;
1642 static int calibrate_signal __initdata = 0;
1646 static int write_ndelay __initdata = -1;
1649 static int io __initdata = CONFIG_MSNDCLAS_IO;
1650 static int irq __initdata = CONFIG_MSNDCLAS_IRQ;
1651 static int mem __initdata = CONFIG_MSNDCLAS_MEM;
1654 static int io __initdata = CONFIG_MSNDPIN_IO;
1655 static int irq __initdata = CONFIG_MSNDPIN_IRQ;
1656 static int mem __initdata = CONFIG_MSNDPIN_MEM;
1659 #ifdef CONFIG_MSNDPIN_NONPNP
1660 # ifndef CONFIG_MSNDPIN_CFG
1661 # define CONFIG_MSNDPIN_CFG 0x250
1664 # ifdef CONFIG_MSNDPIN_CFG
1665 # undef CONFIG_MSNDPIN_CFG
1667 # define CONFIG_MSNDPIN_CFG -1
1674 #ifndef CONFIG_MSNDPIN_MPU_IO
1675 # define CONFIG_MSNDPIN_MPU_IO 0
1679 #ifndef CONFIG_MSNDPIN_MPU_IRQ
1680 # define CONFIG_MSNDPIN_MPU_IRQ 0
1684 #ifndef CONFIG_MSNDPIN_IDE_IO0
1685 # define CONFIG_MSNDPIN_IDE_IO0 0
1689 #ifndef CONFIG_MSNDPIN_IDE_IO1
1690 # define CONFIG_MSNDPIN_IDE_IO1 0
1694 #ifndef CONFIG_MSNDPIN_IDE_IRQ
1695 # define CONFIG_MSNDPIN_IDE_IRQ 0
1699 #ifndef CONFIG_MSNDPIN_JOYSTICK_IO
1700 # define CONFIG_MSNDPIN_JOYSTICK_IO 0
1705 #ifndef CONFIG_MSNDPIN_DIGITAL
1706 # define CONFIG_MSNDPIN_DIGITAL 0
1712 #ifndef CONFIG_MSND_FIFOSIZE
1713 # define CONFIG_MSND_FIFOSIZE DEFFIFOSIZE
1717 #ifndef CONFIG_MSND_CALSIGNAL
1718 # define CONFIG_MSND_CALSIGNAL 0
1730 #ifndef MSND_CLASSIC
1742 static int __init msnd_init(
void)
1745 #ifndef MSND_CLASSIC
1750 VERSION ", Copyright (C) 1998 Andrew Veliath\n");
1752 if (io == -1 || irq == -1 || mem == -1)
1765 printk(
KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, or 0x3E0\n");
1773 printk(
KERN_ERR LOGNAME ": \"io\" - DSP I/O base must within the range 0x100 to 0x3E0 and must be evenly divisible by 0x10\n");
1797 "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or 0xe8000\n");
1822 }
else if (cfg != 0x250 && cfg != 0x260 && cfg != 0x270) {
1829 pinnacle_devs[0].io0 =
io;
1830 pinnacle_devs[0].irq = irq;
1831 pinnacle_devs[0].mem =
mem;
1836 pinnacle_devs[1].io0 = mpu_io;
1837 pinnacle_devs[1].irq = mpu_irq;
1840 pinnacle_devs[2].io0 = ide_io0;
1841 pinnacle_devs[2].io1 = ide_io1;
1842 pinnacle_devs[2].irq = ide_irq;
1845 pinnacle_devs[3].io0 = joystick_io;
1852 if (msnd_pinnacle_cfg_devices(cfg, reset, pinnacle_devs)) {
1864 if (fifosize > 1024)
1867 set_default_audio_parameters();
1869 dev.
type = msndClassic;
1871 dev.
type = msndPinnacle;
1882 if (write_ndelay == -1)
1888 #ifndef MSND_CLASSIC
1910 if ((err = probe_multisound()) < 0) {
1917 if ((err = attach_multisound()) < 0) {
1927 static void __exit msdn_cleanup(
void)
1929 unload_multisound();