Lines Matching +full:dma +full:- +full:info
1 // SPDX-License-Identifier: GPL-2.0-only
9 * Copyright (C) 1997 Rudolf Koenig (rfkoenig@immd4.informatik.uni-erlangen.de)
15 * - DBRI: AT&T T5900FX Dual Basic Rates ISDN Interface. It is a 32 channel
20 * - "STP 4000SBus Dual Basic Rate ISDN (DBRI) Transceiver" from
22 * - Data sheet of the T7903, a newer but very similar ISA bus equivalent
25 * - https://www.freesoft.org/Linux/DBRI/
26 * - MMCODEC: Crystal Semiconductor CS4215 16 bit Multimedia Audio Codec
31 * memory and a serial device (long pipes, no. 0-15) or between two serial
32 * devices (short pipes, no. 16-31), or simply send a fixed data to a serial
34 * A timeslot defines the bit-offset and no. of bits read from a serial device.
44 * the same CHI bus, so I thought perhaps it is possible to use the on-board
45 * & the speakerbox codec simultaneously, giving 2 (not very independent :-)
53 * dbri_* DBRI high-level stuff
54 * other DBRI low-level stuff
61 #include <linux/dma-mapping.h>
68 #include <sound/info.h>
81 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
128 __u8 data[4]; /* Data mode: Time slots 5-8 */
129 __u8 ctrl[4]; /* Ctrl mode: Time slots 1-4 */
196 #define CS4215_DAD (1<<0) /* 0:Digital-Dig loop, 1:Dig-Analog-Dig loop */
212 /* Time Slot 1-2: Left Channel Data, 2-3: Right Channel Data */
215 #define CS4215_LO(v) v /* Left Output Attenuation 0x3f: -94.5 dB */
220 #define CS4215_RO(v) v /* Right Output Attenuation 0x3f: -94.5 dB */
251 #define DBRI_MAX_PIPE (DBRI_NO_PIPES - 1)
266 /* This structure is in a DMA region where it can accessed by both
277 (&(((struct dbri_dma *)0)->member[elem])))
293 u32 dvma_buffer; /* Device view of ALSA DMA buffer */
294 int size; /* Size of DMA buffer */
304 struct platform_device *op; /* OF device info */
307 struct dbri_dma *dma; /* Pointer to our DMA block */
308 dma_addr_t dma_dvma; /* DBRI visible DMA address */
314 int next_desc[DBRI_NO_DESCS]; /* Index of next desc, or -1 */
320 struct cs4215 mm; /* mmcodec special info */
321 /* per stream (playback/record) info */
328 /* DBRI Reg0 - Status Control Register - defines. (Page 17) */
330 #define D_G (1<<14) /* Allow 4-Word SBus Burst */
331 #define D_S (1<<13) /* Allow 16-Word SBus Burst */
332 #define D_E (1<<12) /* Allow 8-Word SBus Burst */
337 #define D_F (1<<3) /* Force Sanity Timer Time-Out */
342 /* DBRI Reg1 - Mode and Interrupt Register - defines. (Page 18) */
351 /* DBRI Reg2 - Parallel IO Register - defines. (Page 18) */
380 #define D_PIPE(v) ((v)<<0) /* Pipe No.: 0-15 long, 16-21 short */
407 #define D_DTS_VI (1<<17) /* Valid Input Time-Slot Descriptor */
408 #define D_DTS_VO (1<<16) /* Valid Output Time-Slot Descriptor */
423 #define D_TS_NEXT(v) ((v)<<0) /* Pipe no.: 0-15 long, 16-21 short */
460 #define D_TEST_SER 0x7 /* Serial-Controller test */
463 #define D_TEST_RAMBIST 0xa /* RAM Built-In Self Test */
464 #define D_TEST_MCBIST 0xb /* Microcontroller Built-In Self Test */
483 #define D_INTR_SBRI 9 /* BRI status change info */
486 #define D_INTR_COLL 11 /* Unrecoverable D-Channel collision */
490 #define D_INTR_UNDR 15 /* DMA underrun */
549 #define DBRI_TD_MAXCNT ((1 << 13) - 4)
567 (substream->stream == \
572 &dbri->stream_info[DBRI_STREAMNO(substream)]
629 dbri->dma->cmd buffer. After this, the commands can be written to
645 spin_lock_irqsave(&dbri->lock, flags);
646 while ((--maxloops) > 0 && (sbus_readl(dbri->regs + REG0) & D_P)) {
647 spin_unlock_irqrestore(&dbri->lock, flags);
649 spin_lock_irqsave(&dbri->lock, flags);
651 spin_unlock_irqrestore(&dbri->lock, flags);
657 MAXLOOPS - maxloops - 1);
665 u32 dvma_addr = (u32)dbri->dma_dvma;
669 spin_lock(&dbri->cmdlock);
670 if (dbri->cmdptr - dbri->dma->cmd + len < DBRI_NO_CMDS - 2)
671 return dbri->cmdptr + 2;
672 else if (len < sbus_readl(dbri->regs + REG8) - dvma_addr)
673 return dbri->dma->cmd;
690 u32 dvma_addr = (u32)dbri->dma_dvma;
700 addr = dvma_addr + (cmd - len - dbri->dma->cmd) * sizeof(s32);
701 *(dbri->cmdptr+1) = addr;
702 *(dbri->cmdptr) = DBRI_CMD(D_JUMP, 0, 0);
705 if (cmd > dbri->cmdptr) {
708 for (ptr = dbri->cmdptr; ptr < cmd+2; ptr++)
712 s32 *ptr = dbri->cmdptr;
717 for (ptr = dbri->dma->cmd; ptr < cmd+2; ptr++)
724 tmp = sbus_readl(dbri->regs + REG0);
726 sbus_writel(tmp, dbri->regs + REG0);
728 dbri->cmdptr = cmd;
729 spin_unlock(&dbri->cmdlock);
739 sbus_readl(dbri->regs + REG0),
740 sbus_readl(dbri->regs + REG2),
741 sbus_readl(dbri->regs + REG8), sbus_readl(dbri->regs + REG9));
743 sbus_writel(D_R, dbri->regs + REG0); /* Soft Reset */
744 for (i = 0; (sbus_readl(dbri->regs + REG0) & D_R) && i < 64; i++)
747 /* A brute approach - DBRI falls back to working burst size by itself
749 tmp = sbus_readl(dbri->regs + REG0);
752 sbus_writel(tmp, dbri->regs + REG0);
758 u32 dvma_addr = (u32)dbri->dma_dvma;
763 scoped_guard(spinlock_irqsave, &dbri->lock) {
768 dbri->pipes[n].desc = dbri->pipes[n].first_desc = -1;
770 spin_lock_init(&dbri->cmdlock);
775 dbri->dma->intr[0] = dma_addr;
776 dbri->dbri_irqp = 1;
780 scoped_guard(spinlock, &dbri->cmdlock) {
781 cmd = dbri->cmdptr = dbri->dma->cmd;
785 dbri->cmdptr = cmd;
789 sbus_writel(dma_addr, dbri->regs + REG8);
803 and interrupt driven), or long (attached to DMA buffers). These functions
812 return ((pipe >= 0) && (dbri->pipes[pipe].desc != -1));
817 * Called on an in-use pipe to clear anything being transmitted or received
832 sdp = dbri->pipes[pipe].sdp;
845 desc = dbri->pipes[pipe].first_desc;
848 dbri->dma->desc[desc].ba = 0;
849 dbri->dma->desc[desc].nda = 0;
850 desc = dbri->next_desc[desc];
851 } while (desc != -1 && desc != dbri->pipes[pipe].first_desc);
853 dbri->pipes[pipe].desc = -1;
854 dbri->pipes[pipe].first_desc = -1;
881 dbri->pipes[pipe].sdp = sdp;
882 dbri->pipes[pipe].desc = -1;
883 dbri->pipes[pipe].first_desc = -1;
906 if (dbri->pipes[pipe].sdp == 0
907 || dbri->pipes[prevpipe].sdp == 0
908 || dbri->pipes[nextpipe].sdp == 0) {
914 dbri->pipes[prevpipe].nextpipe = pipe;
915 dbri->pipes[pipe].nextpipe = nextpipe;
916 dbri->pipes[pipe].length = length;
920 if (dbri->pipes[pipe].sdp & D_SDP_TO_SER) {
924 * - DBRI data sheet, page 11
927 cycle = dbri->chi_bpf;
986 * Transmit/receive data on a "fixed" pipe - i.e, one whose contents are not
990 * Only short pipes (numbers 16-31) can be used in fixed data mode.
992 * These function operate on a 32-bit field, no matter how large
994 * ordering and alignment. An 8-bit time slot will always end up
995 * in the low-order 8 bits, filled either MSB-first or LSB-first,
1009 if (D_SDP_MODE(dbri->pipes[pipe].sdp) == 0) {
1015 if (D_SDP_MODE(dbri->pipes[pipe].sdp) != D_SDP_FIXED) {
1016 printk(KERN_ERR "DBRI: xmit_fixed: Non-fixed pipe %d\n", pipe);
1020 if (!(dbri->pipes[pipe].sdp & D_SDP_TO_SER)) {
1028 if (dbri->pipes[pipe].sdp & D_SDP_MSB)
1029 data = reverse_bytes(data, dbri->pipes[pipe].length);
1037 scoped_guard(spinlock_irqsave, &dbri->lock) {
1053 if (D_SDP_MODE(dbri->pipes[pipe].sdp) != D_SDP_FIXED) {
1055 "non-fixed pipe %d\n", pipe);
1059 if (dbri->pipes[pipe].sdp & D_SDP_TO_SER) {
1065 dbri->pipes[pipe].recv_fixed_ptr = ptr;
1070 * Setup transmit/receive data on a "long" pipe - i.e, one associated
1071 * with a DMA buffer.
1073 * Only pipe numbers 0-15 can be used in this mode.
1086 struct dbri_streaminfo *info = &dbri->stream_info[streamno];
1087 u32 dvma_addr = (u32)dbri->dma_dvma;
1091 int first_desc = -1;
1092 int last_desc = -1;
1094 if (info->pipe < 0 || info->pipe > 15) {
1096 return -2;
1099 if (dbri->pipes[info->pipe].sdp == 0) {
1101 info->pipe);
1102 return -2;
1105 dvma_buffer = info->dvma_buffer;
1106 len = info->size;
1109 if (!(dbri->pipes[info->pipe].sdp & D_SDP_TO_SER)) {
1111 "Called on receive pipe %d\n", info->pipe);
1112 return -2;
1115 if (dbri->pipes[info->pipe].sdp & D_SDP_TO_SER) {
1118 info->pipe);
1119 return -2;
1124 if (pipe_active(dbri, info->pipe)) {
1126 "Called on active pipe %d\n", info->pipe);
1127 return -2;
1135 desc = dbri->pipes[info->pipe].first_desc;
1138 dbri->dma->desc[desc].ba = 0;
1139 dbri->dma->desc[desc].nda = 0;
1140 desc = dbri->next_desc[desc];
1141 } while (desc != -1 &&
1142 desc != dbri->pipes[info->pipe].first_desc);
1144 dbri->pipes[info->pipe].desc = -1;
1145 dbri->pipes[info->pipe].first_desc = -1;
1152 if (!dbri->dma->desc[desc].ba)
1158 return -1;
1162 mylen = DBRI_TD_MAXCNT; /* 8KB - 4 */
1169 dbri->next_desc[desc] = -1;
1170 dbri->dma->desc[desc].ba = dvma_buffer;
1171 dbri->dma->desc[desc].nda = 0;
1174 dbri->dma->desc[desc].word1 = DBRI_TD_CNT(mylen);
1175 dbri->dma->desc[desc].word4 = 0;
1176 dbri->dma->desc[desc].word1 |= DBRI_TD_F | DBRI_TD_B;
1178 dbri->dma->desc[desc].word1 = 0;
1179 dbri->dma->desc[desc].word4 =
1183 if (first_desc == -1)
1186 dbri->next_desc[last_desc] = desc;
1187 dbri->dma->desc[last_desc].nda =
1193 len -= mylen;
1196 if (first_desc == -1 || last_desc == -1) {
1199 return -1;
1202 dbri->dma->desc[last_desc].nda =
1204 dbri->next_desc[last_desc] = first_desc;
1205 dbri->pipes[info->pipe].first_desc = first_desc;
1206 dbri->pipes[info->pipe].desc = first_desc;
1209 for (desc = first_desc; desc != -1;) {
1212 dbri->dma->desc[desc].word1,
1213 dbri->dma->desc[desc].ba,
1214 dbri->dma->desc[desc].nda, dbri->dma->desc[desc].word4);
1215 desc = dbri->next_desc[desc];
1225 ************************** DBRI - CHI interface ****************************
1228 The CHI is a four-wire (clock, frame sync, data in, data out) time-division
1257 dbri->pipes[16].sdp = 1;
1258 dbri->pipes[16].nextpipe = 16;
1263 /* Setup DBRI for CHI Slave - receive clock, frame sync (FS)
1271 /* Setup DBRI for CHI Master - generate clock, FS
1275 * FD = 1 - drive CHIFS on rising edge of CHICK
1288 dbri->chi_bpf = bits_per_frame;
1292 * RCE = 0 - receive on falling edge of CHICK
1293 * XCE = 1 - transmit on rising edge of CHICK
1294 * XEN = 1 - enable transmitter
1295 * REN = 1 - enable receiver
1318 scoped_guard(spinlock_irqsave, &dbri->lock) {
1321 * Pipe 4: Send timeslots 1-4 (audio data)
1322 * Pipe 20: Send timeslots 5-8 (part of ctrl data)
1323 * Pipe 6: Receive timeslots 1-4 (audio data)
1324 * Pipe 21: Receive timeslots 6-7. We can only receive 20 bits via
1329 * Pipe 17: Send timeslots 1-4 (slots 5-8 are read only)
1352 * Data Time Slot 5-8
1356 mm->data[0] = CS4215_LO(0x20) | CS4215_HE | CS4215_LE;
1357 mm->data[1] = CS4215_RO(0x20) | CS4215_SE;
1358 mm->data[2] = CS4215_LG(0x8) | CS4215_IS | CS4215_PIO0 | CS4215_PIO1;
1359 mm->data[3] = CS4215_RG(0x8) | CS4215_MA(0xf);
1362 * Control Time Slot 1-4
1368 mm->ctrl[0] = CS4215_RSRVD_1 | CS4215_MLB;
1369 mm->ctrl[1] = CS4215_DFR_ULAW | CS4215_FREQ[0].csval;
1370 mm->ctrl[2] = CS4215_XCLK | CS4215_BSEL_128 | CS4215_FREQ[0].xtal;
1371 mm->ctrl[3] = 0;
1373 mm->status = 0;
1374 mm->version = 0xff;
1375 mm->precision = 8; /* For ULAW */
1376 mm->channels = 1;
1384 dbri->mm.data[0] |= 63;
1385 dbri->mm.data[1] |= 63;
1386 dbri->mm.data[2] &= ~15;
1387 dbri->mm.data[3] &= ~15;
1390 struct dbri_streaminfo *info = &dbri->stream_info[DBRI_PLAY];
1391 int left_gain = info->left_gain & 0x3f;
1392 int right_gain = info->right_gain & 0x3f;
1394 dbri->mm.data[0] &= ~0x3f; /* Reset the volume bits */
1395 dbri->mm.data[1] &= ~0x3f;
1396 dbri->mm.data[0] |= (DBRI_MAX_VOLUME - left_gain);
1397 dbri->mm.data[1] |= (DBRI_MAX_VOLUME - right_gain);
1400 info = &dbri->stream_info[DBRI_REC];
1401 left_gain = info->left_gain & 0xf;
1402 right_gain = info->right_gain & 0xf;
1403 dbri->mm.data[2] |= CS4215_LG(left_gain);
1404 dbri->mm.data[3] |= CS4215_RG(right_gain);
1407 xmit_fixed(dbri, 20, *(int *)dbri->mm.data);
1419 dbri->mm.channels, dbri->mm.precision);
1430 * Pipe 4: Send timeslots 1-4 (audio data)
1431 * Pipe 20: Send timeslots 5-8 (part of ctrl data)
1432 * Pipe 6: Receive timeslots 1-4 (audio data)
1433 * Pipe 21: Receive timeslots 6-7. We can only receive 20 bits via
1441 scoped_guard(spinlock_irqsave, &dbri->lock) {
1442 tmp = sbus_readl(dbri->regs + REG0);
1444 sbus_writel(tmp, dbri->regs + REG0);
1446 /* Switch CS4215 to data mode - set PIO3 to 1 */
1448 (dbri->mm.onboard ? D_PIO0 : D_PIO2), dbri->regs + REG2);
1452 /* Note: this next doesn't work for 8-bit stereo, because the two
1456 * DBRI non-contiguous mode would be required to make this work.
1458 data_width = dbri->mm.channels * dbri->mm.precision;
1460 link_time_slot(dbri, 4, 16, 16, data_width, dbri->mm.offset);
1461 link_time_slot(dbri, 20, 4, 16, 32, dbri->mm.offset + 32);
1462 link_time_slot(dbri, 6, 16, 16, data_width, dbri->mm.offset);
1463 link_time_slot(dbri, 21, 6, 16, 16, dbri->mm.offset + 40);
1466 tmp = sbus_readl(dbri->regs + REG0);
1468 sbus_writel(tmp, dbri->regs + REG0);
1482 /* FIXME - let the CPU do something useful during these delays */
1494 val = D_ENPIO | D_PIO1 | (dbri->mm.onboard ? D_PIO0 : D_PIO2);
1495 sbus_writel(val, dbri->regs + REG2);
1514 * done in hardware by a TI 248 that delays the DBRI->4215
1517 scoped_guard(spinlock_irqsave, &dbri->lock) {
1518 tmp = sbus_readl(dbri->regs + REG0);
1520 sbus_writel(tmp, dbri->regs + REG0);
1526 * Pipe 17: Send timeslots 1-4 (slots 5-8 are read only)
1531 link_time_slot(dbri, 17, 16, 16, 32, dbri->mm.offset);
1532 link_time_slot(dbri, 18, 16, 16, 8, dbri->mm.offset);
1533 link_time_slot(dbri, 19, 18, 16, 8, dbri->mm.offset + 48);
1537 dbri->mm.ctrl[0] &= ~CS4215_CLB;
1538 xmit_fixed(dbri, 17, *(int *)dbri->mm.ctrl);
1540 scoped_guard(spinlock_irqsave, &dbri->lock) {
1541 tmp = sbus_readl(dbri->regs + REG0);
1543 sbus_writel(tmp, dbri->regs + REG0);
1546 for (i = 10; ((dbri->mm.status & 0xe4) != 0x20); --i)
1551 dbri->mm.status);
1552 return -1;
1560 /* Terminate CS4215 control mode - data sheet says
1561 * "Set CLB=1 and send two more frames of valid control info"
1563 dbri->mm.ctrl[0] |= CS4215_CLB;
1564 xmit_fixed(dbri, 17, *(int *)dbri->mm.ctrl);
1566 /* Two frames of control info @ 8kHz frame rate = 250 us delay */
1593 return -1;
1598 dbri->mm.ctrl[1] = CS4215_DFR_ULAW;
1599 dbri->mm.precision = 8;
1602 dbri->mm.ctrl[1] = CS4215_DFR_ALAW;
1603 dbri->mm.precision = 8;
1606 dbri->mm.ctrl[1] = CS4215_DFR_LINEAR8;
1607 dbri->mm.precision = 8;
1610 dbri->mm.ctrl[1] = CS4215_DFR_LINEAR16;
1611 dbri->mm.precision = 16;
1615 return -1;
1619 dbri->mm.ctrl[1] |= CS4215_FREQ[freq_idx].csval;
1620 dbri->mm.ctrl[2] = CS4215_XCLK |
1623 dbri->mm.channels = channels;
1625 dbri->mm.ctrl[1] |= CS4215_DFR_STEREO;
1639 u32 reg2 = sbus_readl(dbri->regs + REG2);
1645 dbri->mm.onboard = 1;
1649 dbri->mm.onboard = 0;
1654 sbus_writel(D_ENPIO2, dbri->regs + REG2);
1660 return -EIO;
1664 cs4215_init_data(&dbri->mm);
1667 recv_fixed(dbri, 18, &dbri->mm.status);
1668 recv_fixed(dbri, 19, &dbri->mm.version);
1670 dbri->mm.offset = dbri->mm.onboard ? 0 : 8;
1671 if (cs4215_setctrl(dbri) == -1 || dbri->mm.version == 0xff) {
1673 dbri->mm.offset);
1674 return -EIO;
1676 dprintk(D_MM, "Found CS4215 at offset %d\n", dbri->mm.offset);
1699 * For playback, ALSA has filled the DMA memory with new data (we hope).
1703 struct dbri_streaminfo *info;
1711 dvma_addr = (u32)dbri->dma_dvma;
1712 info = &dbri->stream_info[DBRI_REC];
1713 guard(spinlock_irqsave)(&dbri->lock);
1715 if (info->pipe >= 0) {
1716 first_td = dbri->pipes[info->pipe].first_desc;
1724 dbri->pipes[info->pipe].sdp
1731 dbri->pipes[info->pipe].desc = first_td;
1735 info = &dbri->stream_info[DBRI_PLAY];
1737 if (info->pipe >= 0) {
1738 first_td = dbri->pipes[info->pipe].first_desc;
1746 dbri->pipes[info->pipe].sdp
1753 dbri->pipes[info->pipe].desc = first_td;
1767 * The DMA buffers are not released. They form a ring buffer and
1768 * they are filled by ALSA while others are transmitted by DMA.
1774 struct dbri_streaminfo *info = &dbri->stream_info[DBRI_PLAY];
1775 int td = dbri->pipes[pipe].desc;
1784 status = DBRI_TD_STATUS(dbri->dma->desc[td].word4);
1790 dbri->dma->desc[td].word4 = 0; /* Reset it for next time. */
1791 info->offset += DBRI_RD_CNT(dbri->dma->desc[td].word1);
1793 td = dbri->next_desc[td];
1794 dbri->pipes[pipe].desc = td;
1798 spin_unlock(&dbri->lock);
1799 snd_pcm_period_elapsed(info->substream);
1800 spin_lock(&dbri->lock);
1805 struct dbri_streaminfo *info;
1806 int rd = dbri->pipes[pipe].desc;
1814 dbri->pipes[pipe].desc = dbri->next_desc[rd];
1815 status = dbri->dma->desc[rd].word1;
1816 dbri->dma->desc[rd].word1 = 0; /* Reset it for next time. */
1818 info = &dbri->stream_info[DBRI_REC];
1819 info->offset += DBRI_RD_CNT(status);
1827 spin_unlock(&dbri->lock);
1828 snd_pcm_period_elapsed(info->substream);
1829 spin_lock(&dbri->lock);
1843 dprintk(D_CMD, "INTR: Command: %-5s Value:%d\n",
1863 /* UNDR - Transmission underrun
1872 int td = dbri->pipes[pipe].desc;
1874 dbri->dma->desc[td].word4 = 0;
1877 dbri->pipes[pipe].sdp
1879 *(cmd++) = dbri->dma_dvma + dbri_dma_off(desc, td);
1885 /* FXDT - Fixed data change */
1886 if (dbri->pipes[channel].sdp & D_SDP_MSB)
1887 val = reverse_bytes(val, dbri->pipes[channel].length);
1889 if (dbri->pipes[channel].recv_fixed_ptr)
1890 *(dbri->pipes[channel].recv_fixed_ptr) = val;
1901 * right now). Non-zero words require processing and are handed off
1908 while ((x = dbri->dma->intr[dbri->dbri_irqp]) != 0) {
1909 dbri->dma->intr[dbri->dbri_irqp] = 0;
1910 dbri->dbri_irqp++;
1911 if (dbri->dbri_irqp == DBRI_INT_BLK)
1912 dbri->dbri_irqp = 1;
1926 guard(spinlock)(&dbri->lock);
1931 x = sbus_readl(dbri->regs + REG1);
1952 * to be disabled, so just re-enable and try to keep going.
1963 tmp = sbus_readl(dbri->regs + REG0);
1965 sbus_writel(tmp, dbri->regs + REG0);
1978 .info = SNDRV_PCM_INFO_MMAP |
2008 if (c->min > 1) {
2024 if (!(f->bits[0] & SNDRV_PCM_FMTBIT_S16_BE)) {
2036 struct snd_pcm_runtime *runtime = substream->runtime;
2037 struct dbri_streaminfo *info = DBRI_STREAM(dbri, substream);
2040 runtime->hw = snd_dbri_pcm_hw;
2042 scoped_guard(spinlock_irqsave, &dbri->lock) {
2043 info->substream = substream;
2044 info->offset = 0;
2045 info->dvma_buffer = 0;
2046 info->pipe = -1;
2051 -1);
2055 -1);
2065 struct dbri_streaminfo *info = DBRI_STREAM(dbri, substream);
2068 info->substream = NULL;
2069 info->offset = 0;
2077 struct snd_pcm_runtime *runtime = substream->runtime;
2079 struct dbri_streaminfo *info = DBRI_STREAM(dbri, substream);
2090 /* hw_params can get called multiple times. Only map the DMA once.
2092 if (info->dvma_buffer == 0) {
2098 info->dvma_buffer =
2099 dma_map_single(&dbri->op->dev,
2100 runtime->dma_area,
2107 direction, info->dvma_buffer);
2114 struct dbri_streaminfo *info = DBRI_STREAM(dbri, substream);
2119 /* hw_free can get called multiple times. Only unmap the DMA once.
2121 if (info->dvma_buffer) {
2127 dma_unmap_single(&dbri->op->dev, info->dvma_buffer,
2128 substream->runtime->buffer_size, direction);
2129 info->dvma_buffer = 0;
2131 if (info->pipe != -1) {
2132 reset_pipe(dbri, info->pipe);
2133 info->pipe = -1;
2142 struct dbri_streaminfo *info = DBRI_STREAM(dbri, substream);
2145 info->size = snd_pcm_lib_buffer_bytes(substream);
2147 info->pipe = 4; /* Send pipe */
2149 info->pipe = 6; /* Receive pipe */
2151 guard(spinlock_irq)(&dbri->lock);
2152 info->offset = 0;
2155 * whole DMA buffer.
2160 dprintk(D_USR, "prepare audio output. %d bytes\n", info->size);
2167 struct dbri_streaminfo *info = DBRI_STREAM(dbri, substream);
2174 /* Re-submit the TDs. */
2179 reset_pipe(dbri, info->pipe);
2182 ret = -EINVAL;
2191 struct dbri_streaminfo *info = DBRI_STREAM(dbri, substream);
2194 ret = bytes_to_frames(substream->runtime, info->offset)
2195 % substream->runtime->buffer_size;
2197 ret, substream->runtime->buffer_size);
2227 pcm->private_data = card->private_data;
2228 pcm->info_flags = 0;
2229 strscpy(pcm->name, card->shortname);
2243 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2244 uinfo->count = 2;
2245 uinfo->value.integer.min = 0;
2246 if (kcontrol->private_value == DBRI_PLAY)
2247 uinfo->value.integer.max = DBRI_MAX_VOLUME;
2249 uinfo->value.integer.max = DBRI_MAX_GAIN;
2257 struct dbri_streaminfo *info;
2260 return -EINVAL;
2261 info = &dbri->stream_info[kcontrol->private_value];
2263 ucontrol->value.integer.value[0] = info->left_gain;
2264 ucontrol->value.integer.value[1] = info->right_gain;
2272 struct dbri_streaminfo *info =
2273 &dbri->stream_info[kcontrol->private_value];
2277 vol[0] = ucontrol->value.integer.value[0];
2278 vol[1] = ucontrol->value.integer.value[1];
2279 if (kcontrol->private_value == DBRI_PLAY) {
2281 return -EINVAL;
2284 return -EINVAL;
2287 if (info->left_gain != vol[0]) {
2288 info->left_gain = vol[0];
2291 if (info->right_gain != vol[1]) {
2292 info->right_gain = vol[1];
2309 int mask = (kcontrol->private_value >> 16) & 0xff;
2311 uinfo->type = (mask == 1) ?
2313 uinfo->count = 1;
2314 uinfo->value.integer.min = 0;
2315 uinfo->value.integer.max = mask;
2323 int elem = kcontrol->private_value & 0xff;
2324 int shift = (kcontrol->private_value >> 8) & 0xff;
2325 int mask = (kcontrol->private_value >> 16) & 0xff;
2326 int invert = (kcontrol->private_value >> 24) & 1;
2329 return -EINVAL;
2332 ucontrol->value.integer.value[0] =
2333 (dbri->mm.data[elem] >> shift) & mask;
2335 ucontrol->value.integer.value[0] =
2336 (dbri->mm.ctrl[elem - 4] >> shift) & mask;
2339 ucontrol->value.integer.value[0] =
2340 mask - ucontrol->value.integer.value[0];
2348 int elem = kcontrol->private_value & 0xff;
2349 int shift = (kcontrol->private_value >> 8) & 0xff;
2350 int mask = (kcontrol->private_value >> 16) & 0xff;
2351 int invert = (kcontrol->private_value >> 24) & 1;
2356 return -EINVAL;
2358 val = (ucontrol->value.integer.value[0] & mask);
2360 val = mask - val;
2364 dbri->mm.data[elem] = (dbri->mm.data[elem] &
2366 changed = (val != dbri->mm.data[elem]);
2368 dbri->mm.ctrl[elem - 4] = (dbri->mm.ctrl[elem - 4] &
2370 changed = (val != dbri->mm.ctrl[elem - 4]);
2374 "mixer-value=%ld, mm-value=0x%x\n",
2375 mask, changed, ucontrol->value.integer.value[0],
2376 dbri->mm.data[elem & 3]);
2389 /* Entries 0-3 map to the 4 data timeslots, entries 4-7 map to the 4 control
2395 .info = snd_cs4215_info_single, \
2404 .info = snd_cs4215_info_volume,
2415 .info = snd_cs4215_info_volume,
2432 if (snd_BUG_ON(!card || !card->private_data))
2433 return -EINVAL;
2434 dbri = card->private_data;
2436 strscpy(card->mixername, card->shortname);
2446 dbri->stream_info[idx].left_gain = 0;
2447 dbri->stream_info[idx].right_gain = 0;
2459 struct snd_dbri *dbri = entry->private_data;
2461 snd_iprintf(buffer, "REG0: 0x%x\n", sbus_readl(dbri->regs + REG0));
2462 snd_iprintf(buffer, "REG2: 0x%x\n", sbus_readl(dbri->regs + REG2));
2463 snd_iprintf(buffer, "REG8: 0x%x\n", sbus_readl(dbri->regs + REG8));
2464 snd_iprintf(buffer, "REG9: 0x%x\n", sbus_readl(dbri->regs + REG9));
2471 struct snd_dbri *dbri = entry->private_data;
2477 struct dbri_pipe *pptr = &dbri->pipes[pipe];
2482 (pptr->sdp & D_SDP_TO_SER) ? "output" :
2484 pptr->sdp, pptr->desc,
2485 pptr->length, pptr->nextpipe);
2493 struct snd_dbri *dbri = card->private_data;
2512 struct snd_dbri *dbri = card->private_data;
2515 spin_lock_init(&dbri->lock);
2516 dbri->op = op;
2517 dbri->irq = irq;
2519 dbri->dma = dma_alloc_coherent(&op->dev, sizeof(struct dbri_dma),
2520 &dbri->dma_dvma, GFP_KERNEL);
2521 if (!dbri->dma)
2522 return -ENOMEM;
2524 dprintk(D_GEN, "DMA Cmd Block 0x%p (%pad)\n",
2525 dbri->dma, dbri->dma_dvma);
2528 dbri->regs_size = resource_size(&op->resource[0]);
2529 dbri->regs = of_ioremap(&op->resource[0], 0,
2530 dbri->regs_size, "DBRI Registers");
2531 if (!dbri->regs) {
2533 dma_free_coherent(&op->dev, sizeof(struct dbri_dma),
2534 (void *)dbri->dma, dbri->dma_dvma);
2535 return -EIO;
2538 err = request_irq(dbri->irq, snd_dbri_interrupt, IRQF_SHARED,
2541 printk(KERN_ERR "DBRI: Can't get irq %d\n", dbri->irq);
2542 of_iounmap(&op->resource[0], dbri->regs, dbri->regs_size);
2543 dma_free_coherent(&op->dev, sizeof(struct dbri_dma),
2544 (void *)dbri->dma, dbri->dma_dvma);
2564 if (dbri->irq)
2565 free_irq(dbri->irq, dbri);
2567 if (dbri->regs)
2568 of_iounmap(&dbri->op->resource[0], dbri->regs, dbri->regs_size);
2570 if (dbri->dma)
2571 dma_free_coherent(&dbri->op->dev,
2573 (void *)dbri->dma, dbri->dma_dvma);
2586 return -ENODEV;
2589 return -ENOENT;
2592 irq = op->archdata.irqs[0];
2594 printk(KERN_ERR "DBRI-%d: No IRQ.\n", dev);
2595 return -ENODEV;
2598 err = snd_card_new(&op->dev, index[dev], id[dev], THIS_MODULE,
2603 strscpy(card->driver, "DBRI");
2604 strscpy(card->shortname, "Sun DBRI");
2605 rp = &op->resource[0];
2606 sprintf(card->longname, "%s at 0x%02lx:0x%016llx, irq %d",
2607 card->shortname,
2608 rp->flags & 0xffL, (unsigned long long)rp->start, irq);
2616 dbri = card->private_data;
2627 dev_set_drvdata(&op->dev, card);
2634 dev, dbri->regs,
2635 dbri->irq, op->dev.of_node->name[9], dbri->mm.version);
2648 struct snd_card *card = dev_get_drvdata(&op->dev);
2650 snd_dbri_free(card->private_data);