dbrivar.h revision 1.16 1 1.16 isaki /* $NetBSD: dbrivar.h,v 1.16 2019/05/08 13:40:19 isaki Exp $ */
2 1.1 macallan
3 1.1 macallan /*
4 1.2 macallan * Copyright (C) 1997 Rudolf Koenig (rfkoenig (at) immd4.informatik.uni-erlangen.de)
5 1.2 macallan * Copyright (c) 1998, 1999 Brent Baccala (baccala (at) freesoft.org)
6 1.2 macallan * Copyright (c) 2001, 2002 Jared D. McNeill <jmcneill (at) netbsd.org>
7 1.2 macallan * Copyright (c) 2005 Michael Lorenz <macallan (at) netbsd.org>
8 1.1 macallan * All rights reserved.
9 1.1 macallan *
10 1.2 macallan * This driver is losely based on a Linux driver written by Rudolf Koenig and
11 1.2 macallan * Brent Baccala who kindly gave their permission to use their code in a
12 1.2 macallan * BSD-licensed driver.
13 1.2 macallan *
14 1.1 macallan * Redistribution and use in source and binary forms, with or without
15 1.1 macallan * modification, are permitted provided that the following conditions
16 1.1 macallan * are met:
17 1.1 macallan * 1. Redistributions of source code must retain the above copyright
18 1.1 macallan * notice, this list of conditions and the following disclaimer.
19 1.1 macallan * 2. Redistributions in binary form must reproduce the above copyright
20 1.1 macallan * notice, this list of conditions and the following disclaimer in the
21 1.1 macallan * documentation and/or other materials provided with the distribution.
22 1.1 macallan *
23 1.9 macallan * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
24 1.9 macallan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.9 macallan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.9 macallan * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.9 macallan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 1.9 macallan * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
29 1.9 macallan * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.9 macallan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.9 macallan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.9 macallan * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.1 macallan *
34 1.1 macallan */
35 1.1 macallan
36 1.4 macallan #ifndef DBRI_VAR_H
37 1.4 macallan #define DBRI_VAR_H
38 1.2 macallan
39 1.1 macallan #define DBRI_NUM_COMMANDS 64
40 1.7 macallan #define DBRI_NUM_DESCRIPTORS 32
41 1.1 macallan #define DBRI_INT_BLOCKS 64
42 1.1 macallan
43 1.1 macallan #define DBRI_PIPE_MAX 32
44 1.1 macallan
45 1.16 isaki struct dbri_softc;
46 1.16 isaki
47 1.1 macallan enum direction {
48 1.1 macallan in,
49 1.1 macallan out
50 1.1 macallan };
51 1.1 macallan
52 1.1 macallan /* DBRI DMA transmit descriptor */
53 1.7 macallan struct dbri_xmit {
54 1.4 macallan volatile uint32_t flags;
55 1.1 macallan #define TX_EOF 0x80000000 /* End of frame marker */
56 1.1 macallan #define TX_BCNT(x) ((x&0x3fff)<<16)
57 1.1 macallan #define TX_BINT 0x00008000 /* interrupt when EOF */
58 1.1 macallan #define TX_MINT 0x00004000 /* marker interrupt */
59 1.1 macallan #define TX_IDLE 0x00002000 /* send idles after data */
60 1.1 macallan #define TX_FCNT(x) (x&0x1fff)
61 1.1 macallan
62 1.4 macallan volatile uint32_t ba; /* tx/rx buffer address */
63 1.4 macallan volatile uint32_t nda; /* next descriptor address */
64 1.4 macallan volatile uint32_t status;
65 1.1 macallan #define TS_OK 0x0001 /* transmission completed */
66 1.1 macallan #define TS_ABORT 0x0004 /* transmission aborted */
67 1.1 macallan #define TS_UNDERRUN 0x0008 /* DMA underrun */
68 1.1 macallan };
69 1.1 macallan
70 1.7 macallan struct dbri_recv {
71 1.7 macallan volatile uint32_t status;
72 1.7 macallan #define RX_EOF 0x80000000
73 1.7 macallan #define RX_COMPLETED 0x40000000
74 1.7 macallan #define RX_BCNT(x) ((x & 0x3fff) << 16)
75 1.7 macallan #define RX_CRCERROR 0x00000080
76 1.7 macallan #define RX_BBC 0x00000040 /* bad byte count */
77 1.7 macallan #define RX_ABORT 0x00000020
78 1.7 macallan #define RX_OVERRUN 0x00000008
79 1.7 macallan volatile uint32_t ba;
80 1.7 macallan volatile uint32_t nda;
81 1.7 macallan volatile uint32_t flags;
82 1.7 macallan #define RX_BSIZE(x) (x & 0x3fff)
83 1.7 macallan #define RX_FINAL 0x00008000
84 1.7 macallan #define RX_MARKER 0x00004000
85 1.7 macallan };
86 1.7 macallan
87 1.1 macallan struct dbri_pipe {
88 1.4 macallan uint32_t sdp; /* SDP command word */
89 1.1 macallan enum direction direction;
90 1.1 macallan int next; /* next pipe in linked list */
91 1.1 macallan int prev; /* previous pipe in linked list */
92 1.1 macallan int cycle; /* offset of timeslot (bits) */
93 1.1 macallan int length; /* length of timeslot (bits) */
94 1.1 macallan int desc; /* index of active descriptor */
95 1.4 macallan volatile uint32_t *prec; /* pointer to received fixed data */
96 1.1 macallan };
97 1.1 macallan
98 1.1 macallan struct dbri_desc {
99 1.1 macallan int busy;
100 1.5 christos void * buf; /* cpu view of buffer */
101 1.5 christos void * buf_dvma; /* device view */
102 1.1 macallan bus_addr_t dmabase;
103 1.1 macallan bus_dma_segment_t dmaseg;
104 1.1 macallan bus_dmamap_t dmamap;
105 1.1 macallan size_t len;
106 1.1 macallan void (*callback)(void *);
107 1.1 macallan void *callback_args;
108 1.8 ad void *softint;
109 1.16 isaki struct dbri_softc *sc;
110 1.1 macallan };
111 1.1 macallan
112 1.1 macallan struct dbri_dma {
113 1.4 macallan volatile uint32_t command[DBRI_NUM_COMMANDS];
114 1.1 macallan volatile int32_t intr[DBRI_INT_BLOCKS];
115 1.7 macallan struct dbri_xmit xmit[DBRI_NUM_DESCRIPTORS];
116 1.7 macallan struct dbri_recv recv[DBRI_NUM_DESCRIPTORS];
117 1.1 macallan };
118 1.1 macallan
119 1.1 macallan struct dbri_softc {
120 1.10 macallan device_t sc_dev; /* base device */
121 1.1 macallan
122 1.1 macallan bus_space_handle_t sc_ioh;
123 1.1 macallan bus_space_tag_t sc_iot;
124 1.7 macallan /* DMA buffer for sending commands to the chip */
125 1.1 macallan bus_dma_tag_t sc_dmat;
126 1.1 macallan bus_dmamap_t sc_dmamap;
127 1.1 macallan bus_dma_segment_t sc_dmaseg;
128 1.4 macallan
129 1.4 macallan int sc_have_powerctl;
130 1.12 macallan int sc_init_done;
131 1.6 macallan int sc_powerstate; /* DBRI's powered up or not */
132 1.6 macallan int sc_pmgrstate; /* PWR_RESUME etc. */
133 1.1 macallan int sc_burst; /* DVMA burst size in effect */
134 1.1 macallan
135 1.1 macallan bus_addr_t sc_dmabase; /* VA of buffer we provide */
136 1.5 christos void * sc_membase;
137 1.1 macallan int sc_bufsiz; /* size of the buffer */
138 1.1 macallan int sc_locked;
139 1.1 macallan int sc_irqp;
140 1.1 macallan
141 1.1 macallan int sc_waitseen;
142 1.1 macallan
143 1.7 macallan int sc_refcount;
144 1.6 macallan int sc_playing;
145 1.7 macallan int sc_recording;
146 1.1 macallan
147 1.1 macallan int sc_liu_state;
148 1.1 macallan void (*sc_liu)(void *);
149 1.1 macallan void *sc_liu_args;
150 1.1 macallan
151 1.1 macallan struct dbri_pipe sc_pipe[DBRI_PIPE_MAX];
152 1.1 macallan struct dbri_desc sc_desc[DBRI_NUM_DESCRIPTORS];
153 1.1 macallan
154 1.1 macallan struct cs4215_state sc_mm;
155 1.6 macallan int sc_latt, sc_ratt; /* output attenuation */
156 1.6 macallan int sc_linp, sc_rinp; /* input volume */
157 1.6 macallan int sc_monitor; /* monitor volume */
158 1.6 macallan int sc_input; /* 0 - line, 1 - mic */
159 1.15 macallan int sc_whack_codec; /* 1 - codec needs control mode */
160 1.6 macallan
161 1.1 macallan int sc_ctl_mode;
162 1.1 macallan
163 1.4 macallan uint32_t sc_version;
164 1.1 macallan int sc_chi_pipe_in;
165 1.1 macallan int sc_chi_pipe_out;
166 1.1 macallan int sc_chi_bpf;
167 1.1 macallan
168 1.1 macallan int sc_desc_used;
169 1.1 macallan
170 1.1 macallan struct audio_params sc_params;
171 1.1 macallan
172 1.1 macallan struct dbri_dma *sc_dma;
173 1.13 jmcneill
174 1.13 jmcneill kmutex_t sc_lock;
175 1.13 jmcneill kmutex_t sc_intr_lock;
176 1.14 mrg #ifndef DBRI_SPIN
177 1.14 mrg kcondvar_t sc_cv;
178 1.14 mrg #endif
179 1.1 macallan };
180 1.1 macallan
181 1.1 macallan #define dbri_dma_off(member, elem) \
182 1.4 macallan ((uint32_t)(unsigned long) \
183 1.1 macallan (&(((struct dbri_dma *)0)->member[elem])))
184 1.1 macallan
185 1.1 macallan #if 1
186 1.1 macallan #define DBRI_CMD(cmd, intr, value) ((cmd << 28) | (intr << 27) | value)
187 1.1 macallan #else
188 1.1 macallan #define DBRI_CMD(cmd, intr, value) ((cmd << 28) | (1 << 27) | value)
189 1.1 macallan #endif
190 1.1 macallan #define DBRI_INTR_GETCHAN(v) (((v) >> 24) & 0x3f)
191 1.1 macallan #define DBRI_INTR_GETCODE(v) (((v) >> 20) & 0xf)
192 1.1 macallan #define DBRI_INTR_GETCMD(v) (((v) >> 16) & 0xf)
193 1.1 macallan #define DBRI_INTR_GETVAL(v) ((v) & 0xffff)
194 1.1 macallan #define DBRI_INTR_GETRVAL(v) ((v) & 0xfffff)
195 1.1 macallan
196 1.1 macallan #define DBRI_SDP_MODE(v) ((v) & (7 << 13))
197 1.1 macallan #define DBRI_PIPE(v) ((v) << 0)
198 1.4 macallan
199 1.4 macallan #endif /* DBRI_VAR_H */
200