144 #include <linux/module.h>
148 #include <linux/wait.h>
151 #include <linux/slab.h>
163 static int shut_up = 1;
169 static void dbgassert(
const char *fcn,
int line,
const char *
expr)
172 panic(
"ASSERTION FAILED IN INTERRUPT, %s:%s:%d %s\n",
173 __FILE__, fcn, line, expr);
177 __FILE__, fcn, line, expr);
178 x = * (
volatile int *) 0;
198 #define ASSERT(e) ((e) ? (void) 0 : dbgassert(__func__, __LINE__, #e))
200 #define DBGX(fmt, args...) (in_interrupt() ? 0 : printk(KERN_ERR fmt, ##args))
201 #define DBGP(fmt, args...) (DBGX("%s: " fmt, __func__ , ##args))
202 #define DBGE(fmt, args...) (DBGX("%s" fmt, __func__ , ##args))
203 #define DBGC(rtn) (DBGP("calling %s\n", rtn))
204 #define DBGR() (DBGP("returning\n"))
205 #define DBGXV(fmt, args...) (shut_up ? 0 : DBGX(fmt, ##args))
206 #define DBGPV(fmt, args...) (shut_up ? 0 : DBGP(fmt, ##args))
207 #define DBGEV(fmt, args...) (shut_up ? 0 : DBGE(fmt, ##args))
208 #define DBGCV(rtn) (shut_up ? 0 : DBGC(rtn))
209 #define DBGRV() (shut_up ? 0 : DBGR())
213 #define ASSERT(e) ((void) 0)
215 #define DBGX(fmt, args...) ((void) 0)
216 #define DBGP(fmt, args...) ((void) 0)
217 #define DBGE(fmt, args...) ((void) 0)
218 #define DBGC(rtn) ((void) 0)
219 #define DBGR() ((void) 0)
220 #define DBGPV(fmt, args...) ((void) 0)
221 #define DBGXV(fmt, args...) ((void) 0)
222 #define DBGEV(fmt, args...) ((void) 0)
223 #define DBGCV(rtn) ((void) 0)
224 #define DBGRV() ((void) 0)
296 return * (
volatile unsigned long *) (lith->
page0 + off);
301 return * (
volatile unsigned char *) (lith->
page0 + off);
306 * (
volatile unsigned long *) (lith->
page0 + off) =
val;
311 * (
volatile unsigned char *) (lith->
page0 + off) =
val;
367 #define LI_HOST_CONTROLLER 0x000
368 # define LI_HC_RESET 0x00008000
369 # define LI_HC_LINK_ENABLE 0x00004000
370 # define LI_HC_LINK_FAILURE 0x00000004
371 # define LI_HC_LINK_CODEC 0x00000002
372 # define LI_HC_LINK_READY 0x00000001
374 #define LI_INTR_STATUS 0x010
375 #define LI_INTR_MASK 0x014
376 # define LI_INTR_LINK_ERR 0x00008000
377 # define LI_INTR_COMM2_TRIG 0x00000008
378 # define LI_INTR_COMM2_UNDERFLOW 0x00000004
379 # define LI_INTR_COMM1_TRIG 0x00000002
380 # define LI_INTR_COMM1_OVERFLOW 0x00000001
382 #define LI_CODEC_COMMAND 0x018
383 # define LI_CC_BUSY 0x00008000
384 # define LI_CC_DIR 0x00000080
385 # define LI_CC_DIR_RD LI_CC_DIR
386 # define LI_CC_DIR_WR (!LI_CC_DIR)
387 # define LI_CC_ADDR_MASK 0x0000007F
389 #define LI_CODEC_DATA 0x01C
391 #define LI_COMM1_BASE 0x100
392 #define LI_COMM1_CTL 0x104
393 # define LI_CCTL_RESET 0x80000000
394 # define LI_CCTL_SIZE 0x70000000
395 # define LI_CCTL_DMA_ENABLE 0x08000000
396 # define LI_CCTL_TMASK 0x07000000
397 # define LI_CCTL_TPTR 0x00FF0000
398 # define LI_CCTL_RPTR 0x0000FF00
399 # define LI_CCTL_WPTR 0x000000FF
400 #define LI_COMM1_CFG 0x108
401 # define LI_CCFG_LOCK 0x00008000
402 # define LI_CCFG_SLOT 0x00000070
403 # define LI_CCFG_DIRECTION 0x00000008
404 # define LI_CCFG_DIR_IN (!LI_CCFG_DIRECTION)
405 # define LI_CCFG_DIR_OUT LI_CCFG_DIRECTION
406 # define LI_CCFG_MODE 0x00000004
407 # define LI_CCFG_MODE_MONO (!LI_CCFG_MODE)
408 # define LI_CCFG_MODE_STEREO LI_CCFG_MODE
409 # define LI_CCFG_FORMAT 0x00000003
410 # define LI_CCFG_FMT_8BIT 0x00000000
411 # define LI_CCFG_FMT_16BIT 0x00000001
412 #define LI_COMM2_BASE 0x10C
413 #define LI_COMM2_CTL 0x110
415 #define LI_COMM2_CFG 0x114
418 #define LI_UST_LOW 0x200
419 #define LI_UST_HIGH 0x204
421 #define LI_AUDIO1_UST 0x300
422 #define LI_AUDIO1_MSC 0x304
423 #define LI_AUDIO2_UST 0x308
424 #define LI_AUDIO2_MSC 0x30C
431 #define DMACHUNK_SHIFT 5
432 #define DMACHUNK_SIZE (1 << DMACHUNK_SHIFT)
433 #define BYTES_TO_CHUNKS(bytes) ((bytes) >> DMACHUNK_SHIFT)
434 #define CHUNKS_TO_BYTES(chunks) ((chunks) << DMACHUNK_SHIFT)
444 #define SHIFT_FIELD(val, mask) (((val) * ((mask) & -(mask))) & (mask))
445 #define UNSHIFT_FIELD(val, mask) (((val) & (mask)) / ((mask) & -(mask)))
530 static int li_ad1843_wait(
lithium_t *lith)
532 unsigned long later =
jiffies + 2;
550 spin_lock(&lith->
lock);
552 val = li_ad1843_wait(lith);
555 val = li_ad1843_wait(lith);
560 spin_unlock(&lith->
lock);
562 DBGXV(
"li_read_ad1843_reg(lith=0x%p, reg=%d) returns 0x%04x\n",
572 static void li_write_ad1843_reg(
lithium_t *lith,
int reg,
int newval)
574 spin_lock(&lith->
lock);
576 if (li_ad1843_wait(lith) == 0) {
581 spin_unlock(&lith->
lock);
592 unsigned long buffer_paddr,
599 unsigned long size, tmask;
601 DBGEV(
"(chan=0x%p, desc=0x%p, lith=0x%p, buffer_paddr=0x%lx, "
602 "bufshift=%d, fragshift=%d, channels=%d, sampsize=%d)\n",
603 chan, desc, lith, buffer_paddr,
604 bufshift, fragshift, channels, sampsize);
610 ASSERT(channels == 1 || channels == 2);
615 ASSERT(sampsize == 1 || sampsize == 2);
629 ASSERT(!(buffer_paddr & 0xFF));
630 chan->
baseval = (buffer_paddr >> 8) | 1 << (37 - 8);
639 tmask = 13 - fragshift;
640 ASSERT(size >= 2 && size <= 7);
641 ASSERT(tmask >= 1 && tmask <= 7);
662 void * lith1 = lith->
page1;
664 DBGEV(
"(chan=0x%p)\n", chan);
682 * (
volatile unsigned long *) (lith1 + 0x500) = 0;
698 static void li_deactivate_dma(
dma_chan_t *chan)
701 void * lith2 = lith->
page2;
719 * (
volatile unsigned long *) (lith2 + 0x98) = 0;
720 * (
volatile unsigned long *) (lith2 + 0x9C) = 0;
757 unsigned long now_low, now_high0, now_high1, chan_ust;
759 spin_lock(&lith->
lock);
776 ustmsc->
msc = li_readl(lith, desc->
mscreg);
777 chan_ust = li_readl(lith, desc->
ustreg);
780 }
while (now_high0 != now_high1);
782 spin_unlock(&lith->
lock);
783 ustmsc->
ust = ((
unsigned long long) now_high0 << 32 | chan_ust);
786 static void li_enable_interrupts(
lithium_t *lith,
unsigned int mask)
788 DBGEV(
"(lith=0x%p, mask=0x%x)\n", lith, mask);
800 static void li_disable_interrupts(
lithium_t *lith,
unsigned int mask)
802 unsigned int keepmask;
804 DBGEV(
"(lith=0x%p, mask=0x%x)\n", lith, mask);
818 static unsigned int li_get_clear_intr_status(
lithium_t *lith)
865 ad1843_PDNO = { 0, 14, 1 },
866 ad1843_INIT = { 0, 15, 1 },
867 ad1843_RIG = { 2, 0, 4 },
868 ad1843_RMGE = { 2, 4, 1 },
869 ad1843_RSS = { 2, 5, 3 },
870 ad1843_LIG = { 2, 8, 4 },
871 ad1843_LMGE = { 2, 12, 1 },
872 ad1843_LSS = { 2, 13, 3 },
873 ad1843_RX1M = { 4, 0, 5 },
874 ad1843_RX1MM = { 4, 7, 1 },
875 ad1843_LX1M = { 4, 8, 5 },
876 ad1843_LX1MM = { 4, 15, 1 },
877 ad1843_RX2M = { 5, 0, 5 },
878 ad1843_RX2MM = { 5, 7, 1 },
879 ad1843_LX2M = { 5, 8, 5 },
880 ad1843_LX2MM = { 5, 15, 1 },
881 ad1843_RMCM = { 7, 0, 5 },
882 ad1843_RMCMM = { 7, 7, 1 },
883 ad1843_LMCM = { 7, 8, 5 },
884 ad1843_LMCMM = { 7, 15, 1 },
885 ad1843_HPOS = { 8, 4, 1 },
886 ad1843_HPOM = { 8, 5, 1 },
887 ad1843_RDA1G = { 9, 0, 6 },
888 ad1843_RDA1GM = { 9, 7, 1 },
889 ad1843_LDA1G = { 9, 8, 6 },
890 ad1843_LDA1GM = { 9, 15, 1 },
891 ad1843_RDA1AM = { 11, 7, 1 },
892 ad1843_LDA1AM = { 11, 15, 1 },
893 ad1843_ADLC = { 15, 0, 2 },
894 ad1843_ADRC = { 15, 2, 2 },
895 ad1843_DA1C = { 15, 8, 2 },
896 ad1843_C1C = { 17, 0, 16 },
897 ad1843_C2C = { 20, 0, 16 },
898 ad1843_DAADL = { 25, 4, 2 },
899 ad1843_DAADR = { 25, 6, 2 },
900 ad1843_DRSFLT = { 25, 15, 1 },
901 ad1843_ADLF = { 26, 0, 2 },
902 ad1843_ADRF = { 26, 2, 2 },
903 ad1843_ADTLK = { 26, 4, 1 },
904 ad1843_SCF = { 26, 7, 1 },
905 ad1843_DA1F = { 26, 8, 2 },
906 ad1843_DA1SM = { 26, 14, 1 },
907 ad1843_ADLEN = { 27, 0, 1 },
908 ad1843_ADREN = { 27, 1, 1 },
909 ad1843_AAMEN = { 27, 4, 1 },
910 ad1843_ANAEN = { 27, 7, 1 },
911 ad1843_DA1EN = { 27, 8, 1 },
912 ad1843_DA2EN = { 27, 9, 1 },
913 ad1843_C1EN = { 28, 11, 1 },
914 ad1843_C2EN = { 28, 12, 1 },
915 ad1843_PDNI = { 28, 15, 1 };
932 = { 0, &ad1843_LIG, &ad1843_RIG };
934 = { 1, &ad1843_LX1M, &ad1843_RX1M };
936 = { 1, &ad1843_LX2M, &ad1843_RX2M };
938 = { 1, &ad1843_LMCM, &ad1843_RMCM };
940 = { 1, &ad1843_LDA1G, &ad1843_RDA1G };
946 int w = li_read_ad1843_reg(lith, field->
reg);
947 int val = w >> field->
lo_bit & ((1 << field->
nbits) - 1);
949 DBGXV(
"ad1843_read_bits(lith=0x%p, field->{%d %d %d}) returns 0x%x\n",
959 static int ad1843_write_bits(
lithium_t *lith,
963 int w = li_read_ad1843_reg(lith, field->
reg);
964 int mask = ((1 << field->
nbits) - 1) << field->
lo_bit;
966 int newbits = (newval << field->
lo_bit) &
mask;
967 w = (w & ~mask) | newbits;
968 (
void) li_write_ad1843_reg(lith, field->
reg, w);
970 DBGXV(
"ad1843_write_bits(lith=0x%p, field->{%d %d %d}, val=0x%x) "
991 static void ad1843_read_multi(
lithium_t *lith,
int argcount, ...)
998 while (--argcount >= 0) {
1000 value =
va_arg(ap,
int *);
1003 w = li_read_ad1843_reg(lith, reg);
1006 mask = (1 << fp->
nbits) - 1;
1023 static void ad1843_write_multi(
lithium_t *lith,
int argcount, ...)
1036 while (--argcount >= 0) {
1044 bits |= (value << fp->
lo_bit) & m;
1049 w = li_read_ad1843_reg(lith, reg);
1052 w = (w & ~mask) | bits;
1053 (
void) li_write_ad1843_reg(lith, reg, w);
1064 unsigned short mask = (1 << gp->
lfield->nbits) - 1;
1066 ad1843_read_multi(lith, 2, gp->
lfield, &lg, gp->
rfield, &rg);
1071 lg = (lg * 100 + (mask >> 1)) /
mask;
1072 rg = (rg * 100 + (mask >> 1)) /
mask;
1073 return lg << 0 | rg << 8;
1087 unsigned short mask = (1 << gp->
lfield->nbits) - 1;
1089 int lg = newval >> 0 & 0xFF;
1090 int rg = newval >> 8;
1091 if (lg < 0 || lg > 100 || rg < 0 || rg > 100)
1093 lg = (lg * mask + (mask >> 1)) / 100;
1094 rg = (rg * mask + (mask >> 1)) / 100;
1099 ad1843_write_multi(lith, 2, gp->
lfield, lg, gp->
rfield, rg);
1107 int ls = ad1843_read_bits(lith, &ad1843_LSS);
1142 int save_da1 = li_read_ad1843_reg(lith, 9);
1145 ad1843_write_multi(lith, 4,
1152 ASSERT(onoff == 0 || onoff == 1);
1153 ad1843_write_bits(lith, &ad1843_DRSFLT, onoff);
1156 ad1843_write_multi(lith, 3,
1162 li_write_ad1843_reg(lith, 9, save_da1);
1200 oldbits = ad1843_read_bits(lith, &ad1843_LSS);
1202 DBGP(
"enabling digital resample mode\n");
1203 ad1843_set_resample_mode(lith, 1);
1204 ad1843_write_multi(lith, 2,
1208 DBGP(
"disabling digital resample mode\n");
1209 ad1843_set_resample_mode(lith, 0);
1210 ad1843_write_multi(lith, 2,
1214 ad1843_write_multi(lith, 2, &ad1843_LSS, bits, &ad1843_RSS, bits);
1222 static int ad1843_get_outsrc(
lithium_t *lith)
1226 pcm = ad1843_read_bits(lith, &ad1843_LDA1GM) ? 0 :
SOUND_MASK_PCM;
1228 cd = ad1843_read_bits(lith, &ad1843_LX2MM) ? 0 :
SOUND_MASK_CD;
1229 mic = ad1843_read_bits(lith, &ad1843_LMCMM) ? 0 :
SOUND_MASK_MIC;
1231 return pcm | line | cd |
mic;
1240 static int ad1843_set_outsrc(
lithium_t *lith,
int mask)
1252 ad1843_write_multi(lith, 2, &ad1843_LDA1GM, pcm, &ad1843_RDA1GM, pcm);
1253 ad1843_write_multi(lith, 2, &ad1843_LX1MM, line, &ad1843_RX1MM, line);
1254 ad1843_write_multi(lith, 2, &ad1843_LX2MM, cd, &ad1843_RX2MM, cd);
1255 ad1843_write_multi(lith, 2, &ad1843_LMCMM, mic, &ad1843_RMCMM, mic);
1267 int ad_fmt = 0, ad_mode = 0;
1269 DBGEV(
"(lith=0x%p, framerate=%d, fmt=%d, channels=%d)\n",
1270 lith, framerate, fmt, channels);
1273 case AFMT_S8: ad_fmt = 1;
break;
1274 case AFMT_U8: ad_fmt = 1;
break;
1282 case 2: ad_mode = 0;
break;
1283 case 1: ad_mode = 1;
break;
1287 DBGPV(
"ad_mode = %d, ad_fmt = %d\n", ad_mode, ad_fmt);
1288 ASSERT(framerate >= 4000 && framerate <= 49000);
1289 ad1843_write_bits(lith, &ad1843_C1C, framerate);
1290 ad1843_write_multi(lith, 2,
1291 &ad1843_DA1SM, ad_mode, &ad1843_DA1F, ad_fmt);
1296 ad1843_write_bits(lith, &ad1843_DA1F, 1);
1303 DBGEV(
"(lith=0x%p, framerate=%d, fmt=%d, channels=%d)\n",
1304 lith, framerate, fmt, channels);
1307 case AFMT_S8: da_fmt = 1;
break;
1308 case AFMT_U8: da_fmt = 1;
break;
1315 DBGPV(
"da_fmt = %d\n", da_fmt);
1316 ASSERT(framerate >= 4000 && framerate <= 49000);
1317 ad1843_write_bits(lith, &ad1843_C2C, framerate);
1318 ad1843_write_multi(lith, 2,
1319 &ad1843_ADLF, da_fmt, &ad1843_ADRF, da_fmt);
1337 unsigned long later;
1340 err = li_init(lith);
1344 if (ad1843_read_bits(lith, &ad1843_INIT) != 0) {
1349 ad1843_write_bits(lith, &ad1843_SCF, 1);
1353 ad1843_write_bits(lith, &ad1843_PDNI, 0);
1356 while (ad1843_read_bits(lith, &ad1843_PDNO)) {
1359 "vwsnd audio: AD1843 won't power up\n");
1368 ad1843_write_multi(lith, 2, &ad1843_C1EN, 1, &ad1843_C2EN, 1);
1374 ad1843_write_multi(lith, 3,
1381 ad1843_write_bits(lith, &ad1843_ADTLK, 1);
1382 ad1843_write_multi(lith, 5,
1391 ad1843_write_bits(lith, &ad1843_DA1C, 1);
1395 ad1843_set_outsrc(lith,
1398 ad1843_write_multi(lith, 2, &ad1843_LDA1AM, 0, &ad1843_RDA1AM, 0);
1405 ad1843_write_multi(lith, 2, &ad1843_LMGE, 1, &ad1843_RMGE, 1);
1409 ad1843_write_multi(lith, 2, &ad1843_HPOS, 1, &ad1843_HPOM, 0);
1417 #define READ_INTR_MASK (LI_INTR_COMM1_TRIG | LI_INTR_COMM1_OVERFLOW)
1418 #define WRITE_INTR_MASK (LI_INTR_COMM2_TRIG | LI_INTR_COMM2_UNDERFLOW)
1526 # define INC_USE_COUNT (atomic_inc(&vwsnd_use_count))
1527 # define DEC_USE_COUNT (atomic_dec(&vwsnd_use_count))
1528 # define IN_USE (atomic_read(&vwsnd_use_count) != 0)
1543 #define HWBUF_SHIFT 13
1544 #define HWBUF_SIZE (1 << HWBUF_SHIFT)
1545 # define HBO (HWBUF_SHIFT > PAGE_SHIFT ? HWBUF_SHIFT - PAGE_SHIFT : 0)
1546 # define HWBUF_ORDER (HBO + 1)
1547 #define MIN_SPEED 4000
1548 #define MAX_SPEED 49000
1550 #define MIN_FRAGSHIFT (DMACHUNK_SHIFT + 1)
1551 #define MAX_FRAGSHIFT (PAGE_SHIFT)
1552 #define MIN_FRAGSIZE (1 << MIN_FRAGSHIFT)
1553 #define MAX_FRAGSIZE (1 << MAX_FRAGSHIFT)
1554 #define MIN_FRAGCOUNT(fragsize) 3
1555 #define MAX_FRAGCOUNT(fragsize) (32 * PAGE_SIZE / (fragsize))
1556 #define DEFAULT_FRAGSHIFT 12
1557 #define DEFAULT_FRAGCOUNT 16
1558 #define DEFAULT_SUBDIVSHIFT 0
1596 unsigned long flags;
1601 ret = __swb_inc_u(port, inc);
1603 spin_unlock_irqrestore(&port->
lock, flags);
1620 unsigned long flags;
1625 ret = __swb_inc_i(port, inc);
1627 spin_unlock_irqrestore(&port->
lock, flags);
1647 unsigned int zero_word;
1649 DBGEV(
"(devc=0x%p, rport=0x%p, wport=0x%p)\n", devc, rport, wport);
1657 zero_word = 0xFFFFFFFF ^ 0x80808080;
1662 zero_word = 0xD5D5D5D5 ^ 0x80808080;
1667 zero_word = 0x80808080;
1672 zero_word = 0x00000000;
1677 zero_word = 0x00000000;
1696 int hwfrags, swfrags;
1703 DBGPV(
"hwfrags = %d, swfrags = %d\n", hwfrags, swfrags);
1704 DBGPV(
"read hwbuf_max = %d, swbuf_size = %d\n",
1708 int hwfrags, swfrags;
1714 DBGPV(
"hwfrags = %d\n", hwfrags);
1719 DBGPV(
"hwfrags = %d, swfrags = %d\n", hwfrags, swfrags);
1720 DBGPV(
"write hwbuf_max = %d, swbuf_size = %d\n",
1740 if (rport && wport) {
1745 if (!wport->
swbuf) {
1766 li_setup_dma(&rport->
chan,
1782 li_activate_dma(&rport->
chan);
1783 li_read_USTMSC(&rport->
chan, &ustmsc);
1794 li_setup_dma(&wport->
chan,
1821 unsigned long flags;
1833 spin_unlock_irqrestore(&aport->
lock, flags);
1840 li_disable_interrupts(&devc->
lith, mask);
1841 if (aport == &devc->
rport)
1845 li_shutdown_dma(&aport->
chan);
1860 DBGEV(
"(devc=0x%p, rport=0x%p, wport=0x%p)\n", devc, rport, wport);
1862 if (rport && rport->
swbuf) {
1863 DBGPV(
"shutting down rport\n");
1866 if (wport && wport->
swbuf) {
1867 DBGPV(
"shutting down wport\n");
1873 static void pcm_copy_in(
vwsnd_port_t *rport,
int swidx,
int hwidx,
int nb)
1879 DBGPV(
"swidx = %d, hwidx = %d\n", swidx, hwidx);
1882 ASSERT(nb > 0 && (nb % 32) == 0);
1883 ASSERT(swidx % 32 == 0 && hwidx % 32 == 0);
1884 ASSERT(swidx >= 0 && swidx + nb <= rport->swbuf_size);
1885 ASSERT(hwidx >= 0 && hwidx + nb <= rport->hwbuf_size);
1891 char *
end = src + nb;
1893 *dst++ = *src++ ^ 0x80;
1898 static void pcm_copy_out(
vwsnd_port_t *wport,
int swidx,
int hwidx,
int nb)
1900 char *src = wport->
swbuf + swidx;
1901 char *dst = wport->
hwbuf + hwidx;
1904 ASSERT(nb > 0 && (nb % 32) == 0);
1907 ASSERT(swidx % 32 == 0 && hwidx % 32 == 0);
1908 ASSERT(swidx >= 0 && swidx + nb <= wport->swbuf_size);
1909 ASSERT(hwidx >= 0 && hwidx + nb <= wport->hwbuf_size);
1914 char *
end = src + nb;
1916 *dst++ = *src++ ^ 0x80;
1940 static void pcm_output(
vwsnd_dev_t *devc,
int erflown,
int nb)
1947 unsigned long iflags;
1949 DBGEV(
"(devc=0x%p, erflown=%d, nb=%d)\n", devc, erflown, nb);
1953 (
void) __swb_inc_u(wport, nb);
1955 spin_unlock_irqrestore(&wport->
lock, iflags);
1956 DBGPV(
"returning: HW BUSY\n");
1960 spin_unlock_irqrestore(&wport->
lock, iflags);
1961 DBGPV(
"returning: DISABLED\n");
1966 int swptr, hwptr, hw_avail, sw_avail, swidx;
1972 hwptr = li_read_hwptr(&wport->
chan);
1973 swptr = li_read_swptr(&wport->
chan);
1974 hw_unavail = (swptr - hwptr + hwsize) % hwsize;
1975 hw_avail = (hwmax - hw_unavail) & -fragsize;
1977 if (sw_avail && swstate ==
SW_RUN) {
1986 DBGP(
"stopping. hwstate = %d\n", hwstate);
1988 li_deactivate_dma(&wport->
chan);
1994 if (!sw_avail || !hw_avail)
1996 spin_unlock_irqrestore(&wport->
lock, iflags);
2008 if (nb > hwsize - swptr)
2009 nb = hwsize - swptr;
2010 if (nb > swsize - swidx)
2011 nb = swsize - swidx;
2013 if (nb % fragsize) {
2014 DBGP(
"nb = %d, fragsize = %d\n", nb, fragsize);
2015 DBGP(
"hw_avail = %d\n", hw_avail);
2016 DBGP(
"sw_avail = %d\n", sw_avail);
2017 DBGP(
"hwsize = %d, swptr = %d\n", hwsize, swptr);
2018 DBGP(
"swsize = %d, swidx = %d\n", swsize, swidx);
2020 ASSERT(!(nb % fragsize));
2021 DBGPV(
"copying swb[%d..%d] to hwb[%d..%d]\n",
2022 swidx, swidx + nb, swptr, swptr + nb);
2023 pcm_copy_out(wport, swidx, swptr, nb);
2024 li_write_swptr(&wport->
chan, (swptr + nb) % hwsize);
2027 DBGPV(
"starting\n");
2028 li_activate_dma(&wport->
chan);
2030 li_read_USTMSC(&wport->
chan, &ustmsc);
2034 __swb_inc_i(wport, nb);
2037 ASSERT(nb % fragsize == 0);
2041 spin_unlock_irqrestore(&wport->
lock, iflags);
2064 static void pcm_input(
vwsnd_dev_t *devc,
int erflown,
int nb)
2071 unsigned long iflags;
2073 DBGEV(
"(devc=0x%p, erflown=%d, nb=%d)\n", devc, erflown, nb);
2078 (
void) __swb_inc_u(rport, nb);
2080 spin_unlock_irqrestore(&rport->
lock, iflags);
2081 DBGPV(
"returning: HW BUSY or !swbuf\n");
2085 spin_unlock_irqrestore(&rport->
lock, iflags);
2086 DBGPV(
"returning: DISABLED\n");
2091 int swptr, hwptr, hw_avail, sw_avail, swidx;
2095 hwptr = li_read_hwptr(&rport->
chan);
2096 swptr = li_read_swptr(&rport->
chan);
2097 hw_avail = (hwptr - swptr + hwsize) % hwsize & -fragsize;
2098 if (hw_avail > hwmax)
2102 DBGP(
"stopping. hwstate = %d\n", hwstate);
2104 li_deactivate_dma(&rport->
chan);
2110 if (!sw_avail || !hw_avail)
2112 spin_unlock_irqrestore(&rport->
lock, iflags);
2124 if (nb > hwsize - swptr)
2125 nb = hwsize - swptr;
2126 if (nb > swsize - swidx)
2127 nb = swsize - swidx;
2129 if (nb % fragsize) {
2130 DBGP(
"nb = %d, fragsize = %d\n", nb, fragsize);
2131 DBGP(
"hw_avail = %d\n", hw_avail);
2132 DBGP(
"sw_avail = %d\n", sw_avail);
2133 DBGP(
"hwsize = %d, swptr = %d\n", hwsize, swptr);
2134 DBGP(
"swsize = %d, swidx = %d\n", swsize, swidx);
2136 ASSERT(!(nb % fragsize));
2137 DBGPV(
"copying hwb[%d..%d] to swb[%d..%d]\n",
2138 swptr, swptr + nb, swidx, swidx + nb);
2139 pcm_copy_in(rport, swidx, swptr, nb);
2140 li_write_swptr(&rport->
chan, (swptr + nb) % hwsize);
2142 __swb_inc_i(rport, nb);
2145 ASSERT(nb % fragsize == 0);
2149 spin_unlock_irqrestore(&rport->
lock, iflags);
2171 DBGPV(
"clearing %d bytes\n", nb);
2177 pcm_output(devc, 0, nb);
2192 unsigned long flags;
2195 DBGEV(
"(devc=0x%p)\n", devc);
2203 spin_unlock_irqrestore(&wport->
lock, flags);
2226 pcm_input(devc, overflown, 0);
2229 static void vwsnd_audio_write_intr(
vwsnd_dev_t *devc,
unsigned int status)
2234 pcm_output(devc, underflown, 0);
2242 DBGEV(
"(irq=%d, dev_id=0x%p)\n", irq, dev_id);
2244 status = li_get_clear_intr_status(&devc->
lith);
2245 vwsnd_audio_read_intr(devc, status);
2246 vwsnd_audio_write_intr(devc, status);
2260 DBGEV(
"(file=0x%p, buffer=0x%p, count=%d, ppos=0x%p)\n",
2261 file, buffer, count, ppos);
2269 ret = pcm_setup(devc, rport, wport);
2280 while ((nb = swb_inc_u(rport, 0)) == 0) {
2281 DBGPV(
"blocking\n");
2287 return ret ? ret : -
EAGAIN;
2290 if (signal_pending(
current)) {
2298 pcm_input(devc, 0, 0);
2302 DBGPV(
"nb = %d\n", nb);
2305 (
void) swb_inc_u(rport, nb);
2310 DBGPV(
"returning %d\n", ret);
2314 static ssize_t vwsnd_audio_read(
struct file *file,
2323 ret = vwsnd_audio_do_read(file, buffer, count, ppos);
2328 static ssize_t vwsnd_audio_do_write(
struct file *file,
2338 DBGEV(
"(file=0x%p, buffer=0x%p, count=%d, ppos=0x%p)\n",
2339 file, buffer, count, ppos);
2347 ret = pcm_setup(devc, rport, wport);
2357 while ((nb = swb_inc_u(wport, 0)) == 0) {
2363 return ret ? ret : -
EAGAIN;
2366 if (signal_pending(
current)) {
2377 DBGPV(
"nb = %d\n", nb);
2380 pcm_output(devc, 0, nb);
2385 DBGPV(
"returning %d\n", ret);
2389 static ssize_t vwsnd_audio_write(
struct file *file,
2398 ret = vwsnd_audio_do_write(file, buffer, count, ppos);
2404 static unsigned int vwsnd_audio_poll(
struct file *file,
2412 unsigned int mask = 0;
2414 DBGEV(
"(file=0x%p, wait=0x%p)\n", file, wait);
2418 poll_wait(file, &rport->
queue, wait);
2419 if (swb_inc_u(rport, 0))
2423 poll_wait(file, &wport->
queue, wait);
2424 if (wport->
swbuf ==
NULL || swb_inc_u(wport, 0))
2428 DBGPV(
"returning 0x%x\n", mask);
2432 static int vwsnd_audio_do_ioctl(
struct file *file,
2444 unsigned long flags;
2448 DBGEV(
"(file=0x%p, cmd=0x%x, arg=0x%lx)\n",
2452 DBGX(
"OSS_GETVERSION\n");
2454 return put_user(ival, (
int *) arg);
2457 DBGX(
"SNDCTL_DSP_GETCAPS\n");
2459 return put_user(ival, (
int *) arg);
2462 DBGX(
"SNDCTL_DSP_GETFMTS\n");
2465 return put_user(ival, (
int *) arg);
2469 DBGX(
"SOUND_PCM_READ_RATE\n");
2471 return put_user(ival, (
int *) arg);
2474 DBGX(
"SOUND_PCM_READ_CHANNELS\n");
2476 return put_user(ival, (
int *) arg);
2481 DBGX(
"SNDCTL_DSP_SPEED %d\n", ival);
2484 DBGX(
"SNDCTL_DSP_SPEED failed: swstate = %d\n",
2498 return put_user(ival, (
int *) arg);
2503 DBGX(
"SNDCTL_DSP_STEREO %d\n", ival);
2504 if (ival != 0 && ival != 1)
2512 return put_user(ival, (
int *) arg);
2517 DBGX(
"SNDCTL_DSP_CHANNELS %d\n", ival);
2518 if (ival != 1 && ival != 2)
2526 return put_user(ival, (
int *) arg);
2529 ival = pcm_setup(devc, rport, wport);
2531 DBGX(
"SNDCTL_DSP_GETBLKSIZE failed, errno %d\n", ival);
2535 DBGX(
"SNDCTL_DSP_GETBLKSIZE returning %d\n", ival);
2536 return put_user(ival, (
int *) arg);
2541 DBGX(
"SNDCTL_DSP_SETFRAGMENT %d:%d\n",
2542 ival >> 16, ival & 0xFFFF);
2546 int sw_fragshift = ival & 0xFFFF;
2548 int hw_fragshift = sw_fragshift - sw_subdivshift;
2549 int sw_fragcount = (ival >> 16) & 0xFFFF;
2556 hw_fragsize = 1 << hw_fragshift;
2561 DBGPV(
"sw_fragshift = %d\n", sw_fragshift);
2562 DBGPV(
"rport = 0x%p, wport = 0x%p\n", rport, wport);
2571 ival = sw_fragcount << 16 | sw_fragshift;
2573 DBGX(
"SNDCTL_DSP_SETFRAGMENT returns %d:%d\n",
2574 ival >> 16, ival & 0xFFFF);
2575 return put_user(ival, (
int *) arg);
2580 DBGX(
"SNDCTL_DSP_SUBDIVIDE %d\n", ival);
2585 int hw_fragshift, hw_fragsize, hw_fragcount;
2587 case 1: subdivshift = 0;
break;
2588 case 2: subdivshift = 1;
break;
2589 case 4: subdivshift = 2;
break;
2596 hw_fragsize = 1 << hw_fragshift;
2611 DBGX(
"SNDCTL_DSP_SETFMT %d\n", ival);
2614 DBGP(
"SETFMT failed, swstate = %d\n",
2634 return put_user(ival, (
int *) arg);
2637 DBGXV(
"SNDCTL_DSP_GETOSPACE\n");
2640 ival = pcm_setup(devc, rport, wport);
2643 ival = swb_inc_u(wport, 0);
2648 DBGXV(
"SNDCTL_DSP_GETOSPACE returns { %d %d %d %d }\n",
2656 DBGX(
"SNDCTL_DSP_GETISPACE\n");
2659 ival = pcm_setup(devc, rport, wport);
2662 ival = swb_inc_u(rport, 0);
2667 DBGX(
"SNDCTL_DSP_GETISPACE returns { %d %d %d %d }\n",
2675 DBGX(
"SNDCTL_DSP_NONBLOCK\n");
2676 spin_lock(&file->
f_lock);
2678 spin_unlock(&file->
f_lock);
2682 DBGX(
"SNDCTL_DSP_RESET\n");
2688 if (wport && wport->
swbuf) {
2690 pcm_output(devc, 0, 0);
2691 pcm_write_sync(devc);
2693 pcm_shutdown(devc, rport, wport);
2697 DBGX(
"SNDCTL_DSP_SYNC\n");
2699 pcm_flush_frag(devc);
2700 pcm_write_sync(devc);
2702 pcm_shutdown(devc, rport, wport);
2706 DBGX(
"SNDCTL_DSP_POST\n");
2709 pcm_flush_frag(devc);
2713 DBGX(
"SNDCTL_DSP_GETIPTR\n");
2721 li_read_USTMSC(&rport->
chan, &ustmsc);
2731 spin_unlock_irqrestore(&rport->
lock, flags);
2737 DBGX(
"SNDCTL_DSP_GETOPTR\n");
2745 li_read_USTMSC(&wport->
chan, &ustmsc);
2755 spin_unlock_irqrestore(&wport->
lock, flags);
2761 DBGX(
"SNDCTL_DSP_GETODELAY\n");
2769 int swptr, hwptr, hwframes, hwbytes, hwsize;
2774 swptr = li_read_swptr(&wport->
chan);
2775 li_read_USTMSC(&wport->
chan, &ustmsc);
2777 totalhwbytes = hwframes * fsize;
2778 hwptr = totalhwbytes % hwsize;
2779 hwbytes = (swptr - hwptr + hwsize) % hwsize;
2780 ival += hwbytes / fsize;
2783 spin_unlock_irqrestore(&wport->
lock, flags);
2784 return put_user(ival, (
int *) arg);
2787 DBGX(
"SNDCTL_DSP_PROFILE\n");
2807 DBGX(
"SNDCTL_DSP_GETTRIGGER\n");
2815 spin_unlock_irqrestore(&rport->
lock, flags);
2823 spin_unlock_irqrestore(&wport->
lock, flags);
2825 return put_user(ival, (
int *) arg);
2830 DBGX(
"SNDCTL_DSP_SETTRIGGER %d\n", ival);
2847 if (ival & PCM_ENABLE_INPUT)
2852 spin_unlock_irqrestore(&rport->
lock, flags);
2853 if (hwstate !=
HW_RUNNING && ival & PCM_ENABLE_INPUT) {
2856 pcm_setup(devc, rport, wport);
2858 li_activate_dma(&rport->
chan);
2865 pflags = wport->
flags;
2866 if (ival & PCM_ENABLE_OUTPUT)
2871 spin_unlock_irqrestore(&wport->
lock, flags);
2872 if (pflags &
DISABLED && ival & PCM_ENABLE_OUTPUT) {
2874 pcm_output(devc, 0, 0);
2880 DBGP(
"unknown ioctl 0x%x\n", cmd);
2883 DBGP(
"unimplemented ioctl 0x%x\n", cmd);
2887 static long vwsnd_audio_ioctl(
struct file *file,
2896 ret = vwsnd_audio_do_ioctl(file, cmd, arg);
2905 static int vwsnd_audio_mmap(
struct file *file,
struct vm_area_struct *vma)
2907 DBGE(
"(file=0x%p, vma=0x%p)\n", file, vma);
2917 static int vwsnd_audio_open(
struct inode *
inode,
struct file *file)
2920 int minor = iminor(inode);
2923 DBGE(
"(inode=0x%p, file=0x%p)\n", inode, file);
2927 for (devc = vwsnd_dev_list; devc; devc = devc->
next_dev)
2928 if ((devc->
audio_minor & ~0x0F) == (minor & ~0x0F))
2946 if (signal_pending(
current)) {
3009 static int vwsnd_audio_release(
struct inode *inode,
struct file *file)
3018 DBGEV(
"(inode=0x%p, file=0x%p)\n", inode, file);
3021 rport = &devc->
rport;
3023 wport = &devc->
wport;
3024 pcm_flush_frag(devc);
3025 pcm_write_sync(devc);
3027 pcm_shutdown(devc, rport, wport);
3050 .read = vwsnd_audio_read,
3051 .write = vwsnd_audio_write,
3052 .poll = vwsnd_audio_poll,
3053 .unlocked_ioctl = vwsnd_audio_ioctl,
3054 .mmap = vwsnd_audio_mmap,
3055 .open = vwsnd_audio_open,
3056 .release = vwsnd_audio_release,
3064 static int vwsnd_mixer_open(
struct inode *inode,
struct file *file)
3068 DBGEV(
"(inode=0x%p, file=0x%p)\n", inode, file);
3072 for (devc = vwsnd_dev_list; devc; devc = devc->
next_dev)
3088 static int vwsnd_mixer_release(
struct inode *inode,
struct file *file)
3090 DBGEV(
"(inode=0x%p, file=0x%p)\n", inode, file);
3097 static int mixer_read_ioctl(
vwsnd_dev_t *devc,
unsigned int nr,
void __user *arg)
3101 DBGEV(
"(devc=0x%p, nr=0x%x, arg=0x%p)\n", devc, nr, arg);
3153 val = ad1843_get_outsrc(&devc->
lith);
3159 return put_user(val, (
int __user *) arg);
3164 static int mixer_write_ioctl(
vwsnd_dev_t *devc,
unsigned int nr,
void __user *arg)
3169 DBGEV(
"(devc=0x%p, nr=0x%x, arg=0x%p)\n", devc, nr, arg);
3171 err =
get_user(val, (
int __user *) arg);
3202 val = ad1843_set_outsrc(&devc->
lith, val);
3210 return put_user(val, (
int __user *) arg);
3215 static long vwsnd_mixer_ioctl(
struct file *file,
3221 const unsigned int nr = (cmd & nrmask) >>
_IOC_NRSHIFT;
3224 DBGEV(
"(devc=0x%p, cmd=0x%x, arg=0x%lx)\n", devc, cmd, arg);
3230 retval = mixer_read_ioctl(devc, nr, (
void __user *) arg);
3232 retval = mixer_write_ioctl(devc, nr, (
void __user *) arg);
3244 .unlocked_ioctl = vwsnd_mixer_ioctl,
3245 .open = vwsnd_mixer_open,
3246 .release = vwsnd_mixer_release,
3258 unsigned long later;
3260 DBGEV(
"(hw_config=0x%p)\n", hw_config);
3264 if (li_create(&lith, hw_config->
io_base) != 0) {
3276 DBGPV(
"HC = 0x%04x\n", w);
3312 DBGEV(
"(hw_config=0x%p)\n", hw_config);
3363 err =
request_irq(hw_config->
irq, vwsnd_audio_intr, 0,
"vwsnd", devc);
3372 "attach_vwsnd: register_sound_dsp error %d\n",
3380 "attach_vwsnd: register_sound_mixer error %d\n",
3411 vwsnd_dev_list = devc;
3426 li_destroy(&devc->
lith);
3439 devcp = &vwsnd_dev_list;
3440 while ((devc = *devcp)) {
3456 li_destroy(&devc->
lith);
3474 static int __init init_vwsnd(
void)
3479 DBGXV(
"sound::vwsnd::init_module()\n");
3481 if (!probe_vwsnd(&the_hw_config))
3484 err = attach_vwsnd(&the_hw_config);
3490 static void __exit cleanup_vwsnd(
void)
3492 DBGX(
"sound::vwsnd::cleanup_module()\n");
3494 unload_vwsnd(&the_hw_config);