cs428x.h revision 1.1 1 /* $NetBSD: cs428x.h,v 1.1 2001/01/22 01:34:42 augustss Exp $ */
2 /* $Tera: cs428x.h,v 1.1 2000/12/22 07:07:58 tacha Exp $ */
3
4 /*
5 * Copyright (c) 2000 Tatoku Ogaito. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Tatoku Ogaito
18 * for the NetBSD Project.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /* Common functions and variables for CS4280 and CS4281 */
35
36 #ifndef _CS428X_H_
37 #define _CS428X_H_
38
39 #define PCI_BA0 (0x10)
40 #define PCI_BA1 (0x14)
41
42 #define CS428X_SAVE_REG_MAX (0x10)
43 #define TYPE_CS4280 (0x4280)
44 #define TYPE_CS4281 (0x4281)
45
46 #define BA0READ4(sc, r) bus_space_read_4((sc)->ba0t, (sc)->ba0h, (r))
47 #define BA0WRITE4(sc, r, x) bus_space_write_4((sc)->ba0t, (sc)->ba0h, (r), (x))
48
49 /* DMA */
50 struct cs428x_dma {
51 bus_dmamap_t map;
52 caddr_t addr; /* real dma buffer */
53 caddr_t dum; /* dummy buffer for audio driver */
54 bus_dma_segment_t segs[1];
55 int nsegs;
56 size_t size;
57 struct cs428x_dma *next;
58 };
59 #define DMAADDR(p) ((p)->map->dm_segs[0].ds_addr)
60 #define KERNADDR(p) ((void *)((p)->addr)) /* buffer for real dma */
61 #define BUFADDR(p) ((void *)((p)->dum)) /* buffer for audio driver */
62
63 /*
64 * Software state
65 */
66 struct cs428x_softc {
67 struct device sc_dev;
68
69 pci_intr_handle_t * sc_ih;
70
71 /* I/O (BA0) */
72 bus_space_tag_t ba0t;
73 bus_space_handle_t ba0h;
74
75 /* BA1 */
76 bus_space_tag_t ba1t;
77 bus_space_handle_t ba1h;
78
79 /* DMA */
80 bus_dma_tag_t sc_dmatag;
81 struct cs428x_dma *sc_dmas;
82 size_t dma_size;
83 size_t dma_align;
84
85 int hw_blocksize;
86 int type;
87
88 /* playback */
89 void (*sc_pintr)(void *); /* dma completion intr handler */
90 void *sc_parg; /* arg for sc_intr() */
91 char *sc_ps, *sc_pe, *sc_pn;
92 int sc_pcount;
93 int sc_pi;
94 struct cs428x_dma *sc_pdma;
95 char *sc_pbuf;
96 int (*halt_output)__P((void *));
97 #ifdef DIAGNOSTIC
98 char sc_prun;
99 #endif
100
101 /* capturing */
102 void (*sc_rintr)(void *); /* dma completion intr handler */
103 void *sc_rarg; /* arg for sc_intr() */
104 char *sc_rs, *sc_re, *sc_rn;
105 int sc_rcount;
106 int sc_ri;
107 struct cs428x_dma *sc_rdma;
108 char *sc_rbuf;
109 int sc_rparam; /* record format */
110 int (*halt_input)__P((void *));
111 #ifdef DIAGNOSTIC
112 char sc_rrun;
113 #endif
114
115 #if NMIDI > 0
116 void (*sc_iintr)(void *, int); /* midi input ready handler */
117 void (*sc_ointr)(void *); /* midi output ready handler */
118 void *sc_arg;
119 #endif
120
121 /*
122 * XXX
123 * Actually thease 2 variables are needed only for CS4280.
124 */
125 u_int32_t pctl;
126 u_int32_t cctl;
127
128 /* AC97 CODEC */
129 struct ac97_codec_if *codec_if;
130 struct ac97_host_if host_if;
131
132 /* Power Management */
133 char sc_suspend;
134 void *sc_powerhook; /* Power Hook */
135 u_int16_t ac97_reg[CS428X_SAVE_REG_MAX + 1]; /* Save ac97 registers */
136 };
137
138
139 int cs428x_open(void *, int);
140 void cs428x_close(void *);
141 int cs428x_round_blocksize(void *, int);
142 int cs428x_get_props(void *);
143 int cs428x_attach_codec(void *, struct ac97_codec_if *);
144 int cs428x_read_codec(void *, u_int8_t , u_int16_t *);
145 int cs428x_write_codec(void *, u_int8_t, u_int16_t);
146 void cs428x_reset_codec(void *);
147
148 int cs428x_mixer_set_port(void *, mixer_ctrl_t *);
149 int cs428x_mixer_get_port(void *, mixer_ctrl_t *);
150 int cs428x_query_devinfo(void *, mixer_devinfo_t *);
151 void *cs428x_malloc(void *, int, size_t, int, int);
152 size_t cs428x_round_buffersize(void *, int, size_t);
153 void cs428x_free(void *, void *, int);
154 paddr_t cs428x_mappage(void *, void *, off_t, int);
155
156 /* internal functions */
157 int cs428x_allocmem(struct cs428x_softc*, size_t, int, int, struct cs428x_dma *);
158 int cs428x_src_wait(struct cs428x_softc *);
159
160
161 /* DEBUG */
162 /*#define CS4280_DEBUG*/
163 /*#define CS4281_DEBUG*/
164
165 #if defined(CS4280_DEBUG) || defined(CS4281_DEBUG)
166 #define DPRINTF(x) if (cs428x_debug) printf x
167 #define DPRINTFN(n,x) if (cs428x_debug>(n)) printf x
168 extern int cs428x_debug;
169 #if CS4280_DEBUG + 0 == 0
170 #undef CS4280_DEBUG
171 #define CS4280_DEBUG 0
172 #endif
173 #else
174 #define DPRINTF(x)
175 #define DPRINTFN(n,x)
176 #endif
177
178 #endif /* _CS428X_H_ */
179