static ssize_t ata_ctx_law(const u_char __user *userPtr, size_t userCount,
u_char frame[], ssize_t *frameUsed,
ssize_t frameLeft)
{ char *table = dmasound.soft.format == AFMT_MU_LAW ? dmasound_ulaw2dma8
: dmasound_alaw2dma8; /* this should help gcc to stuff everything into registers */ long bal = expand_bal; long hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
ssize_t used, usedf;
used = userCount;
usedf = frameLeft; if (!dmasound.soft.stereo) {
u_char *p = &frame[*frameUsed];
u_char data = expand_data; while (frameLeft) {
u_char c; if (bal < 0) { if (!userCount) break; if (get_user(c, userPtr++)) return -EFAULT;
data = table[c];
userCount--;
bal += hSpeed;
}
*p++ = data;
frameLeft--;
bal -= sSpeed;
}
expand_data = data;
} else {
u_short *p = (u_short *)&frame[*frameUsed];
u_short data = expand_data; while (frameLeft >= 2) {
u_char c; if (bal < 0) { if (userCount < 2) break; if (get_user(c, userPtr++)) return -EFAULT;
data = table[c] << 8; if (get_user(c, userPtr++)) return -EFAULT;
data |= table[c];
userCount -= 2;
bal += hSpeed;
}
*p++ = data;
frameLeft -= 2;
bal -= sSpeed;
}
expand_data = data;
}
expand_bal = bal;
used -= userCount;
*frameUsed += usedf-frameLeft; return used;
}
static ssize_t ata_ctx_s8(const u_char __user *userPtr, size_t userCount,
u_char frame[], ssize_t *frameUsed,
ssize_t frameLeft)
{ /* this should help gcc to stuff everything into registers */ long bal = expand_bal; long hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
ssize_t used, usedf;
used = userCount;
usedf = frameLeft; if (!dmasound.soft.stereo) {
u_char *p = &frame[*frameUsed];
u_char data = expand_data; while (frameLeft) { if (bal < 0) { if (!userCount) break; if (get_user(data, userPtr++)) return -EFAULT;
userCount--;
bal += hSpeed;
}
*p++ = data;
frameLeft--;
bal -= sSpeed;
}
expand_data = data;
} else {
u_short *p = (u_short *)&frame[*frameUsed];
u_short data = expand_data; while (frameLeft >= 2) { if (bal < 0) { if (userCount < 2) break; if (get_user(data, (u_short __user *)userPtr)) return -EFAULT;
userPtr += 2;
userCount -= 2;
bal += hSpeed;
}
*p++ = data;
frameLeft -= 2;
bal -= sSpeed;
}
expand_data = data;
}
expand_bal = bal;
used -= userCount;
*frameUsed += usedf-frameLeft; return used;
}
static ssize_t ata_ctx_u8(const u_char __user *userPtr, size_t userCount,
u_char frame[], ssize_t *frameUsed,
ssize_t frameLeft)
{ /* this should help gcc to stuff everything into registers */ long bal = expand_bal; long hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
ssize_t used, usedf;
used = userCount;
usedf = frameLeft; if (!dmasound.soft.stereo) {
u_char *p = &frame[*frameUsed];
u_char data = expand_data; while (frameLeft) { if (bal < 0) { if (!userCount) break; if (get_user(data, userPtr++)) return -EFAULT;
data ^= 0x80;
userCount--;
bal += hSpeed;
}
*p++ = data;
frameLeft--;
bal -= sSpeed;
}
expand_data = data;
} else {
u_short *p = (u_short *)&frame[*frameUsed];
u_short data = expand_data; while (frameLeft >= 2) { if (bal < 0) { if (userCount < 2) break; if (get_user(data, (u_short __user *)userPtr)) return -EFAULT;
userPtr += 2;
data ^= 0x8080;
userCount -= 2;
bal += hSpeed;
}
*p++ = data;
frameLeft -= 2;
bal -= sSpeed;
}
expand_data = data;
}
expand_bal = bal;
used -= userCount;
*frameUsed += usedf-frameLeft; return used;
}
static ssize_t ata_ctx_s16be(const u_char __user *userPtr, size_t userCount,
u_char frame[], ssize_t *frameUsed,
ssize_t frameLeft)
{ /* this should help gcc to stuff everything into registers */ long bal = expand_bal; long hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
ssize_t used, usedf;
used = userCount;
usedf = frameLeft; if (!dmasound.soft.stereo) {
u_short *p = (u_short *)&frame[*frameUsed];
u_short data = expand_data; while (frameLeft >= 4) { if (bal < 0) { if (userCount < 2) break; if (get_user(data, (u_short __user *)userPtr)) return -EFAULT;
userPtr += 2;
userCount -= 2;
bal += hSpeed;
}
*p++ = data;
*p++ = data;
frameLeft -= 4;
bal -= sSpeed;
}
expand_data = data;
} else {
u_long *p = (u_long *)&frame[*frameUsed];
u_long data = expand_data; while (frameLeft >= 4) { if (bal < 0) { if (userCount < 4) break; if (get_user(data, (u_int __user *)userPtr)) return -EFAULT;
userPtr += 4;
userCount -= 4;
bal += hSpeed;
}
*p++ = data;
frameLeft -= 4;
bal -= sSpeed;
}
expand_data = data;
}
expand_bal = bal;
used -= userCount;
*frameUsed += usedf-frameLeft; return used;
}
static ssize_t ata_ctx_u16be(const u_char __user *userPtr, size_t userCount,
u_char frame[], ssize_t *frameUsed,
ssize_t frameLeft)
{ /* this should help gcc to stuff everything into registers */ long bal = expand_bal; long hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
ssize_t used, usedf;
used = userCount;
usedf = frameLeft; if (!dmasound.soft.stereo) {
u_short *p = (u_short *)&frame[*frameUsed];
u_short data = expand_data; while (frameLeft >= 4) { if (bal < 0) { if (userCount < 2) break; if (get_user(data, (u_short __user *)userPtr)) return -EFAULT;
userPtr += 2;
data ^= 0x8000;
userCount -= 2;
bal += hSpeed;
}
*p++ = data;
*p++ = data;
frameLeft -= 4;
bal -= sSpeed;
}
expand_data = data;
} else {
u_long *p = (u_long *)&frame[*frameUsed];
u_long data = expand_data; while (frameLeft >= 4) { if (bal < 0) { if (userCount < 4) break; if (get_user(data, (u_int __user *)userPtr)) return -EFAULT;
userPtr += 4;
data ^= 0x80008000;
userCount -= 4;
bal += hSpeed;
}
*p++ = data;
frameLeft -= 4;
bal -= sSpeed;
}
expand_data = data;
}
expand_bal = bal;
used -= userCount;
*frameUsed += usedf-frameLeft; return used;
}
static ssize_t ata_ctx_s16le(const u_char __user *userPtr, size_t userCount,
u_char frame[], ssize_t *frameUsed,
ssize_t frameLeft)
{ /* this should help gcc to stuff everything into registers */ long bal = expand_bal; long hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
ssize_t used, usedf;
used = userCount;
usedf = frameLeft; if (!dmasound.soft.stereo) {
u_short *p = (u_short *)&frame[*frameUsed];
u_short data = expand_data; while (frameLeft >= 4) { if (bal < 0) { if (userCount < 2) break; if (get_user(data, (u_short __user *)userPtr)) return -EFAULT;
userPtr += 2;
data = le2be16(data);
userCount -= 2;
bal += hSpeed;
}
*p++ = data;
*p++ = data;
frameLeft -= 4;
bal -= sSpeed;
}
expand_data = data;
} else {
u_long *p = (u_long *)&frame[*frameUsed];
u_long data = expand_data; while (frameLeft >= 4) { if (bal < 0) { if (userCount < 4) break; if (get_user(data, (u_int __user *)userPtr)) return -EFAULT;
userPtr += 4;
data = le2be16dbl(data);
userCount -= 4;
bal += hSpeed;
}
*p++ = data;
frameLeft -= 4;
bal -= sSpeed;
}
expand_data = data;
}
expand_bal = bal;
used -= userCount;
*frameUsed += usedf-frameLeft; return used;
}
static ssize_t ata_ctx_u16le(const u_char __user *userPtr, size_t userCount,
u_char frame[], ssize_t *frameUsed,
ssize_t frameLeft)
{ /* this should help gcc to stuff everything into registers */ long bal = expand_bal; long hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
ssize_t used, usedf;
used = userCount;
usedf = frameLeft; if (!dmasound.soft.stereo) {
u_short *p = (u_short *)&frame[*frameUsed];
u_short data = expand_data; while (frameLeft >= 4) { if (bal < 0) { if (userCount < 2) break; if (get_user(data, (u_short __user *)userPtr)) return -EFAULT;
userPtr += 2;
data = le2be16(data) ^ 0x8000;
userCount -= 2;
bal += hSpeed;
}
*p++ = data;
*p++ = data;
frameLeft -= 4;
bal -= sSpeed;
}
expand_data = data;
} else {
u_long *p = (u_long *)&frame[*frameUsed];
u_long data = expand_data; while (frameLeft >= 4) { if (bal < 0) { if (userCount < 4) break; if (get_user(data, (u_int __user *)userPtr)) return -EFAULT;
userPtr += 4;
data = le2be16dbl(data) ^ 0x80008000;
userCount -= 4;
bal += hSpeed;
}
*p++ = data;
frameLeft -= 4;
bal -= sSpeed;
}
expand_data = data;
}
expand_bal = bal;
used -= userCount;
*frameUsed += usedf-frameLeft; return used;
}
staticvoid TTSilence(void)
{
tt_dmasnd.ctrl = DMASND_CTRL_OFF;
atari_microwire_cmd(MW_LM1992_PSG_HIGH); /* mix in PSG signal 1:1 */
}
staticvoid TTInit(void)
{ int mode, i, idx; constint freq[4] = {50066, 25033, 12517, 6258};
/* search a frequency that fits into the allowed error range */
idx = -1; for (i = 0; i < ARRAY_SIZE(freq); i++) /* this isn't as much useful for a TT than for a Falcon, but *thenitdoesn'thurtverymuchtoimplementitforaTTtoo.
*/ if ((100 * abs(dmasound.soft.speed - freq[i]) / freq[i]) < catchRadius)
idx = i; if (idx > -1) {
dmasound.soft.speed = freq[idx];
dmasound.trans_write = &transTTNormal;
} else
dmasound.trans_write = &transTTExpanding;
TTSilence();
dmasound.hard = dmasound.soft;
if (dmasound.hard.speed > 50066) { /* we would need to squeeze the sound, but we won't do that */
dmasound.hard.speed = 50066;
mode = DMASND_MODE_50KHZ;
dmasound.trans_write = &transTTNormal;
} elseif (dmasound.hard.speed > 25033) {
dmasound.hard.speed = 50066;
mode = DMASND_MODE_50KHZ;
} elseif (dmasound.hard.speed > 12517) {
dmasound.hard.speed = 25033;
mode = DMASND_MODE_25KHZ;
} elseif (dmasound.hard.speed > 6258) {
dmasound.hard.speed = 12517;
mode = DMASND_MODE_12KHZ;
} else {
dmasound.hard.speed = 6258;
mode = DMASND_MODE_6KHZ;
}
switch (format) { case AFMT_QUERY: return dmasound.soft.format; case AFMT_MU_LAW: case AFMT_A_LAW: case AFMT_S8: case AFMT_U8: break; default:
format = AFMT_S8;
}
staticint FalconSetFormat(int format)
{ int size; /* Falcon sound DMA supports 8bit and 16bit modes */
switch (format) { case AFMT_QUERY: return dmasound.soft.format; case AFMT_MU_LAW: case AFMT_A_LAW: case AFMT_U8: case AFMT_S8:
size = 8; break; case AFMT_S16_BE: case AFMT_U16_BE: case AFMT_S16_LE: case AFMT_U16_LE:
size = 16; break; default: /* :-) */
size = 8;
format = AFMT_S8;
}
/* used by AtaPlay() if all doubts whether there really is something *tobeplayedarealreadywipedout.
*/
start = write_sq.buffers[write_sq.front];
end = start+((write_sq.count == index) ? write_sq.rear_size
: write_sq.block_size); /* end might not be a legal virtual address. */
DMASNDSetEnd(virt_to_phys(end - 1) + 1);
DMASNDSetBase(virt_to_phys(start)); /* Since only an even number of samples per frame can
be played, we might lose one byte here. (TO DO) */
write_sq.front = (write_sq.front+1) % write_sq.max_count;
write_sq.active++;
tt_dmasnd.ctrl = DMASND_CTRL_ON | DMASND_CTRL_REPEAT;
}
staticvoid AtaPlay(void)
{ /* ++TeSche: Note that write_sq.active is no longer just a flag but *holdsthenumberofframestheDMAiscurrentlyprogrammedfor *instead,maybe0,1(currentlybeingplayed)or2(pre-programmed). * *Changesdonetowrite_sq.countandwrite_sq.activeareabitmore *subtleagainsonowImustadmitIalsopreferdisablingtheirq *hereratherthanconsideringallpossiblesituations.Butthepoint *isthatdisablingtheirqdoesn'thaveanybadinfluenceonthis *versionofthedriveraswebenefitfromhavingpre-programmedthe *DMAwhereverpossible:There'snoneedtoreloadtheDMAatthe *exacttimeofaninterruptbutonlyatsometimewhilethe *pre-programmedframeisplaying!
*/
atari_disable_irq(IRQ_MFP_TIMA);
if (write_sq.active == 2 || /* DMA is 'full' */
write_sq.count <= 0) { /* nothing to do */
atari_enable_irq(IRQ_MFP_TIMA); return;
}
if (write_sq.active == 0) { /* looks like there's nothing 'in' the DMA yet, so try *toputtwoframesintoit(atleastoneisavailable).
*/ if (write_sq.count == 1 &&
write_sq.rear_size < write_sq.block_size &&
!write_sq.syncing) { /* hmmm, the only existing frame is not *yetfilledandwe'renotsyncing?
*/
atari_enable_irq(IRQ_MFP_TIMA); return;
}
AtaPlayNextFrame(1); if (write_sq.count == 1) { /* no more frames */
atari_enable_irq(IRQ_MFP_TIMA); return;
} if (write_sq.count == 2 &&
write_sq.rear_size < write_sq.block_size &&
!write_sq.syncing) { /* hmmm, there were two frames, but the second *oneisnotyetfilledandwe'renotsyncing?
*/
atari_enable_irq(IRQ_MFP_TIMA); return;
}
AtaPlayNextFrame(2);
} else { /* there's already a frame being played so we may only stuff *onenewintotheDMA,butevenifthismaybethelast *frameexistingthepreviousoneisstillonwrite_sq.count.
*/ if (write_sq.count == 2 &&
write_sq.rear_size < write_sq.block_size &&
!write_sq.syncing) { /* hmmm, the only existing frame is not *yetfilledandwe'renotsyncing?
*/
atari_enable_irq(IRQ_MFP_TIMA); return;
}
AtaPlayNextFrame(2);
}
atari_enable_irq(IRQ_MFP_TIMA);
}
static irqreturn_t AtaInterrupt(int irq, void *dummy)
{ #if0 /* ++TeSche: if you should want to test this... */ staticint cnt; if (write_sq.active == 2) if (++cnt == 10) { /* simulate losing an interrupt */
cnt = 0; return IRQ_HANDLED;
} #endif
spin_lock(&dmasound.lock); if (write_sq_ignore_int && is_falcon) { /* ++TeSche: Falcon only: ignore first irq because it comes *immediatelyafterstartingaframe.afterthat,irqscome *(almost)likeontheTT.
*/
write_sq_ignore_int = 0; goto out;
}
if (!write_sq.active) { /* playing was interrupted and sq_reset() has already cleared *thesqvariables,sobetterdon'tdoanythinghere.
*/
WAKE_UP(write_sq.sync_queue); goto out;
}
/* Probably ;) one frame is finished. Well, in fact it may be that a *pre-programmedoneisalsofinishedbecausetherehasbeenalong *delayininterruptdeliveryandwe'vecompletelylostone,but *there'snowaytodetectsuchasituation.Insuchacasethelast *framewillbeplayedmorethanonceandthesituationwillrecover *assoonastheirqgetsthrough.
*/
write_sq.count--;
write_sq.active--;
if (!write_sq.active) {
tt_dmasnd.ctrl = DMASND_CTRL_OFF;
write_sq_ignore_int = 1;
}
WAKE_UP(write_sq.action_queue); /* At least one block of the queue is free now sowakeupawritingprocessblockedbecause
of a full queue. */
if ((write_sq.active != 1) || (write_sq.count != 1)) /* We must be a bit carefully here: write_sq.count indicates the *numberofbuffersusedandnotthenumberofframestobe *played.Ifwrite_sq.count==1andwrite_sq.active==1that *meanstheonlyremainingframewasalreadyprogrammed *earlier(andiscurrentlyrunning)sowemustn'tcall *AtaPlay()here,otherwisewe'llplayoneframetoomuch.
*/
AtaPlay();
if (!write_sq.active) WAKE_UP(write_sq.sync_queue); /* We are not playing after AtaPlay(), so there isnothingtoplayanymore.Wakeupaprocess
waiting for audio output to drain. */
out:
spin_unlock(&dmasound.lock); return IRQ_HANDLED;
}
staticint TTStateInfo(char *buffer, size_t space)
{ int len = 0;
len += sprintf(buffer+len, "\tvol left %ddB [-40... 0]\n",
dmasound.volume_left);
len += sprintf(buffer+len, "\tvol right %ddB [-40... 0]\n",
dmasound.volume_right);
len += sprintf(buffer+len, "\tbass %ddB [-12...+12]\n",
dmasound.bass);
len += sprintf(buffer+len, "\ttreble %ddB [-12...+12]\n",
dmasound.treble); if (len >= space) {
printk(KERN_ERR "dmasound_atari: overflowed state buffer alloc.\n") ;
len = space ;
} return len;
}
staticint FalconStateInfo(char *buffer, size_t space)
{ int len = 0;
len += sprintf(buffer+len, "\tvol left %ddB [-22.5 ... 0]\n",
dmasound.volume_left);
len += sprintf(buffer+len, "\tvol right %ddB [-22.5 ... 0]\n",
dmasound.volume_right); if (len >= space) {
printk(KERN_ERR "dmasound_atari: overflowed state buffer alloc.\n") ;
len = space ;
} return len;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.