17 #include <linux/module.h>
18 #include <linux/kernel.h>
20 #include <linux/soundcard.h>
25 #include <asm/uaccess.h>
31 #define DMASOUND_ATARI_REVISION 0
32 #define DMASOUND_ATARI_EDITION 3
37 static int write_sq_ignore_int;
39 static int expand_bal;
40 static int expand_data;
70 static ssize_t ata_ct_law(
const u_char __user *userPtr,
size_t userCount,
73 static ssize_t ata_ct_s8(
const u_char __user *userPtr,
size_t userCount,
76 static ssize_t ata_ct_u8(
const u_char __user *userPtr,
size_t userCount,
79 static ssize_t ata_ct_s16be(
const u_char __user *userPtr,
size_t userCount,
82 static ssize_t ata_ct_u16be(
const u_char __user *userPtr,
size_t userCount,
85 static ssize_t ata_ct_s16le(
const u_char __user *userPtr,
size_t userCount,
88 static ssize_t ata_ct_u16le(
const u_char __user *userPtr,
size_t userCount,
91 static ssize_t ata_ctx_law(
const u_char __user *userPtr,
size_t userCount,
94 static ssize_t ata_ctx_s8(
const u_char __user *userPtr,
size_t userCount,
97 static ssize_t ata_ctx_u8(
const u_char __user *userPtr,
size_t userCount,
100 static ssize_t ata_ctx_s16be(
const u_char __user *userPtr,
size_t userCount,
103 static ssize_t ata_ctx_u16be(
const u_char __user *userPtr,
size_t userCount,
106 static ssize_t ata_ctx_s16le(
const u_char __user *userPtr,
size_t userCount,
109 static ssize_t ata_ctx_u16le(
const u_char __user *userPtr,
size_t userCount,
118 static void AtaFree(
void *,
unsigned int size);
119 static int AtaIrqInit(
void);
121 static void AtaIrqCleanUp(
void);
123 static int AtaSetBass(
int bass);
124 static int AtaSetTreble(
int treble);
125 static void TTSilence(
void);
126 static void TTInit(
void);
127 static int TTSetFormat(
int format);
128 static int TTSetVolume(
int volume);
129 static int TTSetGain(
int gain);
130 static void FalconSilence(
void);
131 static void FalconInit(
void);
132 static int FalconSetFormat(
int format);
133 static int FalconSetVolume(
int volume);
134 static void AtaPlayNextFrame(
int index);
135 static void AtaPlay(
void);
140 static void TTMixerInit(
void);
141 static void FalconMixerInit(
void);
145 static int AtaWriteSqSetup(
void);
147 static int TTStateInfo(
char *
buffer,
size_t space);
148 static int FalconStateInfo(
char *
buffer,
size_t space);
154 static ssize_t ata_ct_law(
const u_char __user *userPtr,
size_t userCount,
159 : dmasound_alaw2dma8;
161 u_char *
p = &frame[*frameUsed];
163 count =
min_t(
unsigned long, userCount, frameLeft);
179 static ssize_t ata_ct_s8(
const u_char __user *userPtr,
size_t userCount,
184 void *p = &frame[*frameUsed];
186 count =
min_t(
unsigned long, userCount, frameLeft);
197 static ssize_t ata_ct_u8(
const u_char __user *userPtr,
size_t userCount,
204 u_char *p = &frame[*frameUsed];
205 count =
min_t(
unsigned long, userCount, frameLeft);
216 count =
min_t(
unsigned long, userCount, frameLeft)>>1;
223 *p++ = data ^ 0x8080;
232 static ssize_t ata_ct_s16be(
const u_char __user *userPtr,
size_t userCount,
240 count =
min_t(
unsigned long, userCount, frameLeft)>>1;
251 *frameUsed += used*2;
253 void *p = (
u_short *)&frame[*frameUsed];
254 count =
min_t(
unsigned long, userCount, frameLeft) & ~3;
264 static ssize_t ata_ct_u16be(
const u_char __user *userPtr,
size_t userCount,
272 count =
min_t(
unsigned long, userCount, frameLeft)>>1;
284 *frameUsed += used*2;
287 count =
min_t(
unsigned long, userCount, frameLeft)>>2;
294 *p++ = data ^ 0x80008000;
303 static ssize_t ata_ct_s16le(
const u_char __user *userPtr,
size_t userCount,
312 count =
min_t(
unsigned long, userCount, frameLeft)>>1;
324 *frameUsed += used*2;
327 count =
min_t(
unsigned long, userCount, frameLeft)>>2;
344 static ssize_t ata_ct_u16le(
const u_char __user *userPtr,
size_t userCount,
353 count =
min_t(
unsigned long, userCount, frameLeft)>>1;
364 *frameUsed += used*2;
367 count =
min_t(
unsigned long, userCount, frameLeft)>>2;
384 static ssize_t ata_ctx_law(
const u_char __user *userPtr,
size_t userCount,
389 : dmasound_alaw2dma8;
391 long bal = expand_bal;
398 u_char *p = &frame[*frameUsed];
399 u_char data = expand_data;
419 while (frameLeft >= 2) {
426 data = table[
c] << 8;
441 *frameUsed += usedf-frameLeft;
446 static ssize_t ata_ctx_s8(
const u_char __user *userPtr,
size_t userCount,
451 long bal = expand_bal;
458 u_char *p = &frame[*frameUsed];
459 u_char data = expand_data;
477 while (frameLeft >= 2) {
495 *frameUsed += usedf-frameLeft;
500 static ssize_t ata_ctx_u8(
const u_char __user *userPtr,
size_t userCount,
505 long bal = expand_bal;
512 u_char *p = &frame[*frameUsed];
513 u_char data = expand_data;
532 while (frameLeft >= 2) {
551 *frameUsed += usedf-frameLeft;
556 static ssize_t ata_ctx_s16be(
const u_char __user *userPtr,
size_t userCount,
561 long bal = expand_bal;
570 while (frameLeft >= 4) {
588 u_long data = expand_data;
589 while (frameLeft >= 4) {
607 *frameUsed += usedf-frameLeft;
612 static ssize_t ata_ctx_u16be(
const u_char __user *userPtr,
size_t userCount,
617 long bal = expand_bal;
626 while (frameLeft >= 4) {
645 u_long data = expand_data;
646 while (frameLeft >= 4) {
665 *frameUsed += usedf-frameLeft;
670 static ssize_t ata_ctx_s16le(
const u_char __user *userPtr,
size_t userCount,
675 long bal = expand_bal;
684 while (frameLeft >= 4) {
703 u_long data = expand_data;
704 while (frameLeft >= 4) {
723 *frameUsed += usedf-frameLeft;
728 static ssize_t ata_ctx_u16le(
const u_char __user *userPtr,
size_t userCount,
733 long bal = expand_bal;
742 while (frameLeft >= 4) {
761 u_long data = expand_data;
762 while (frameLeft >= 4) {
781 *frameUsed += usedf-frameLeft;
786 static TRANS transTTNormal = {
788 .ct_alaw = ata_ct_law,
793 static TRANS transTTExpanding = {
795 .ct_alaw = ata_ctx_law,
800 static TRANS transFalconNormal = {
802 .ct_alaw = ata_ct_law,
805 .ct_s16be = ata_ct_s16be,
806 .ct_u16be = ata_ct_u16be,
807 .ct_s16le = ata_ct_s16le,
808 .ct_u16le = ata_ct_u16le
811 static TRANS transFalconExpanding = {
813 .ct_alaw = ata_ctx_law,
816 .ct_s16be = ata_ctx_s16be,
817 .ct_u16be = ata_ctx_u16be,
818 .ct_s16le = ata_ctx_s16le,
819 .ct_u16le = ata_ctx_u16le,
836 static void AtaFree(
void *obj,
unsigned int size)
841 static int __init AtaIrqInit(
void)
863 static void AtaIrqCleanUp(
void)
872 #define TONE_VOXWARE_TO_DB(v) \
873 (((v) < 0) ? -12 : ((v) > 100) ? 12 : ((v) - 50) * 6 / 25)
874 #define TONE_DB_TO_VOXWARE(v) (((v) * 25 + ((v) > 0 ? 5 : -5)) / 6 + 50)
877 static int AtaSetBass(
int bass)
885 static int AtaSetTreble(
int treble)
899 static void TTSilence(
void)
906 static void TTInit(
void)
909 const int freq[4] = {50066, 25033, 12517, 6258};
922 dmasound.trans_write = &transTTNormal;
924 dmasound.trans_write = &transTTExpanding;
933 dmasound.trans_write = &transTTNormal;
934 }
else if (
dmasound.hard.speed > 25033) {
937 }
else if (
dmasound.hard.speed > 12517) {
940 }
else if (
dmasound.hard.speed > 6258) {
956 static int TTSetFormat(
int format)
984 #define VOLUME_VOXWARE_TO_DB(v) \
985 (((v) < 0) ? -40 : ((v) > 100) ? 0 : ((v) * 2) / 5 - 40)
986 #define VOLUME_DB_TO_VOXWARE(v) ((((v) + 40) * 5 + 1) / 2)
989 static int TTSetVolume(
int volume)
1000 #define GAIN_VOXWARE_TO_DB(v) \
1001 (((v) < 0) ? -80 : ((v) > 100) ? 0 : ((v) * 4) / 5 - 80)
1002 #define GAIN_DB_TO_VOXWARE(v) ((((v) + 80) * 5 + 1) / 4)
1004 static int TTSetGain(
int gain)
1018 static void FalconSilence(
void)
1032 static void FalconInit(
void)
1034 int divider,
i,
idx;
1035 const int freq[8] = {49170, 32780, 24585, 19668, 16390, 12292, 9834, 8195};
1049 dmasound.trans_write = &transFalconNormal;
1051 dmasound.trans_write = &transFalconExpanding;
1065 dmasound.trans_write = &transFalconNormal;
1066 }
else if (
dmasound.hard.speed > 32780) {
1069 }
else if (
dmasound.hard.speed > 24585) {
1072 }
else if (
dmasound.hard.speed > 19668) {
1075 }
else if (
dmasound.hard.speed > 16390) {
1078 }
else if (
dmasound.hard.speed > 12292) {
1081 }
else if (
dmasound.hard.speed > 9834) {
1084 }
else if (
dmasound.hard.speed > 8195) {
1112 static int FalconSetFormat(
int format)
1153 #define VOLUME_VOXWARE_TO_ATT(v) \
1154 ((v) < 0 ? 15 : (v) > 100 ? 0 : 15 - (v) * 3 / 20)
1155 #define VOLUME_ATT_TO_VOXWARE(v) (100 - (v) * 20 / 3)
1158 static int FalconSetVolume(
int volume)
1168 static void AtaPlayNextFrame(
int index)
1189 static void AtaPlay(
void)
1225 AtaPlayNextFrame(1);
1240 AtaPlayNextFrame(2);
1255 AtaPlayNextFrame(2);
1274 if (write_sq_ignore_int && is_falcon) {
1279 write_sq_ignore_int = 0;
1303 write_sq_ignore_int = 1;
1338 #define RECLEVEL_VOXWARE_TO_GAIN(v) \
1339 ((v) < 0 ? 0 : (v) > 100 ? 15 : (v) * 3 / 20)
1340 #define RECLEVEL_GAIN_TO_VOXWARE(v) (((v) * 20 + 2) / 3)
1343 static void __init TTMixerInit(
void)
1354 static void __init FalconMixerInit(
void)
1363 unsigned long flags;
1371 spin_unlock_irqrestore(&
dmasound.lock, flags);
1372 return IOCTL_OUT(arg, porta & 0x40 ? 0 : 100);
1377 return IOCTL_OUT(arg, dmasound_set_volume(data));
1384 porta = (
sound_ym.rd_data_reg_sel & ~0x40) |
1385 (data < 50 ? 0x40 : 0);
1387 spin_unlock_irqrestore(&
dmasound.lock, flags);
1388 return IOCTL_OUT(arg, porta & 0x40 ? 0 : 100);
1419 return IOCTL_OUT(arg, dmasound_set_bass(data));
1422 return IOCTL_OUT(arg, dmasound_set_treble(data));
1425 return IOCTL_OUT(arg, dmasound_set_gain(data));
1427 return AtaMixerIoctl(cmd, arg);
1430 static int FalconMixerIoctl(
u_int cmd,
u_long arg)
1457 return AtaMixerIoctl(cmd, arg);
1460 static int AtaWriteSqSetup(
void)
1462 write_sq_ignore_int = 0;
1466 static int AtaSqOpen(
fmode_t mode)
1468 write_sq_ignore_int = 1;
1472 static int TTStateInfo(
char *
buffer,
size_t space)
1475 len +=
sprintf(buffer+len,
"\tvol left %ddB [-40... 0]\n",
1477 len +=
sprintf(buffer+len,
"\tvol right %ddB [-40... 0]\n",
1479 len +=
sprintf(buffer+len,
"\tbass %ddB [-12...+12]\n",
1481 len +=
sprintf(buffer+len,
"\ttreble %ddB [-12...+12]\n",
1484 printk(
KERN_ERR "dmasound_atari: overflowed state buffer alloc.\n") ;
1490 static int FalconStateInfo(
char *buffer,
size_t space)
1493 len +=
sprintf(buffer+len,
"\tvol left %ddB [-22.5 ... 0]\n",
1495 len +=
sprintf(buffer+len,
"\tvol right %ddB [-22.5 ... 0]\n",
1498 printk(
KERN_ERR "dmasound_atari: overflowed state buffer alloc.\n") ;
1507 static SETTINGS def_hard_falcon = {
1532 .dma_alloc = AtaAlloc,
1533 .dma_free = AtaFree,
1534 .irqinit = AtaIrqInit,
1536 .irqcleanup = AtaIrqCleanUp,
1539 .silence = TTSilence,
1540 .setFormat = TTSetFormat,
1541 .setVolume = TTSetVolume,
1542 .setBass = AtaSetBass,
1543 .setTreble = AtaSetTreble,
1544 .setGain = TTSetGain,
1546 .mixer_init = TTMixerInit,
1547 .mixer_ioctl = TTMixerIoctl,
1548 .write_sq_setup = AtaWriteSqSetup,
1549 .sq_open = AtaSqOpen,
1550 .state_info = TTStateInfo,
1551 .min_dsp_speed = 6258,
1560 .dma_alloc = AtaAlloc,
1561 .dma_free = AtaFree,
1562 .irqinit = AtaIrqInit,
1564 .irqcleanup = AtaIrqCleanUp,
1567 .silence = FalconSilence,
1568 .setFormat = FalconSetFormat,
1569 .setVolume = FalconSetVolume,
1570 .setBass = AtaSetBass,
1571 .setTreble = AtaSetTreble,
1573 .mixer_init = FalconMixerInit,
1574 .mixer_ioctl = FalconMixerIoctl,
1575 .write_sq_setup = AtaWriteSqSetup,
1576 .sq_open = AtaSqOpen,
1577 .state_info = FalconStateInfo,
1578 .min_dsp_speed = 8195,
1588 static int __init dmasound_atari_init(
void)
1593 dmasound.mach.default_soft = def_soft ;
1594 dmasound.mach.default_hard = def_hard_falcon ;
1598 dmasound.mach.default_soft = def_soft ;
1599 dmasound.mach.default_hard = def_hard_tt ;
1606 printk(
"DMA sound driver: Timer A interrupt already in use\n");
1613 static void __exit dmasound_atari_cleanup(
void)