xref: /netbsd-src/sys/dev/pci/cs428x.h (revision 181254a7b1bdde6873432bffef2d2decc4b5c22f)
1 /*	$NetBSD: cs428x.h,v 1.17 2019/05/08 13:40:18 isaki Exp $	*/
2 
3 /*
4  * Copyright (c) 2000 Tatoku Ogaito.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by Tatoku Ogaito
17  *	for the NetBSD Project.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /* Common functions and variables for CS4280 and CS4281 */
34 
35 #ifndef _CS428X_H_
36 #define _CS428X_H_
37 
38 #define PCI_BA0		      (0x10)
39 #define PCI_BA1		      (0x14)
40 
41 #define CS428X_SAVE_REG_MAX   (0x10)
42 #define TYPE_CS4280	      (0x4280)
43 #define TYPE_CS4281	      (0x4281)
44 
45 #define BA0READ4(sc, r) bus_space_read_4((sc)->ba0t, (sc)->ba0h, (r))
46 #define BA0WRITE4(sc, r, x) bus_space_write_4((sc)->ba0t, (sc)->ba0h, (r), (x))
47 
48 /* DMA */
49 struct cs428x_dma {
50 	bus_dmamap_t map;
51 	void *addr;		/* real DMA buffer */
52 	void *dum;		/* dummy buffer for audio driver */
53 	bus_dma_segment_t segs[1];
54 	int nsegs;
55 	size_t size;
56 	struct cs428x_dma *next;
57 };
58 #define DMAADDR(p) ((p)->map->dm_segs[0].ds_addr)
59 #define KERNADDR(p) ((void *)((p)->addr)) /* buffer for real DMA */
60 #define BUFADDR(p)  ((void *)((p)->dum))  /* buffer for audio driver */
61 
62 /*
63  * Flags (currently used only for CS4280)
64  */
65 enum cs428x_flags {
66 	CS428X_FLAG_NONE	= 0x0,
67 	CS428X_FLAG_INVAC97EAMP	= 0x1,	/* inverted AC97 external amp */
68 	CS428X_FLAG_CLKRUNHACK	= 0x2	/* needs CLKRUN hack */
69 };
70 
71 /*
72  * Software state
73  */
74 struct cs428x_softc {
75 	device_t	      sc_dev;
76 	kmutex_t              sc_lock;
77 	kmutex_t              sc_intr_lock;
78 
79 	pci_chipset_tag_t sc_pc;
80 	pcitag_t sc_pt;
81 	pci_intr_handle_t *   sc_ih;
82 	pci_intr_handle_t intrh;
83 
84 	/* I/O (BA0) */
85 	bus_space_tag_t	      ba0t;
86 	bus_space_handle_t    ba0h;
87 
88 	/* BA1 */
89 	bus_space_tag_t	      ba1t;
90 	bus_space_handle_t    ba1h;
91 
92 	/* DMA */
93 	bus_dma_tag_t	 sc_dmatag;
94 	struct cs428x_dma *sc_dmas;
95 	size_t dma_size;
96 	size_t dma_align;
97 
98 	int	hw_blocksize;
99 	int	type;
100 
101 	/* playback */
102 	void	(*sc_pintr)(void *);	/* DMA completion intr handler */
103 	void	*sc_parg;		/* arg for sc_intr() */
104 	char	*sc_ps, *sc_pe, *sc_pn;
105 	int	sc_pcount;
106 	int	sc_pi;
107 	struct	cs428x_dma *sc_pdma;
108 	char	*sc_pbuf;
109 	int	(*halt_output)(void *);
110 	char	sc_prun;		/* playback status */
111 	int	sc_prate;		/* playback sample rate */
112 
113 	/* capturing */
114 	void	(*sc_rintr)(void *);	/* DMA completion intr handler */
115 	void	*sc_rarg;		/* arg for sc_intr() */
116 	char	*sc_rs, *sc_re, *sc_rn;
117 	int	sc_rcount;
118 	int	sc_ri;
119 	struct	cs428x_dma *sc_rdma;
120 	char	*sc_rbuf;
121 	int	(*halt_input)(void *);
122 	char	sc_rrun;		/* recording status */
123 	int	sc_rrate;		/* recording sample rate */
124 
125 	/* Although cs4281 does not support midi (yet),
126 	 * don't remove these definition.
127 	 */
128 	void	(*sc_iintr)(void *, int); /* midi input ready handler */
129 	void	(*sc_ointr)(void *);	  /* midi output ready handler */
130 	void	*sc_arg;
131 
132 	/*
133 	 * XXX
134 	 * Actually these 3 variables are needed only for CS4280.
135 	 */
136 	enum cs428x_flags sc_flags;
137 	uint32_t pctl;
138 	uint32_t cctl;
139 
140 	/* AC97 CODEC */
141 	struct ac97_codec_if *codec_if;
142 	struct ac97_host_if host_if;
143 
144 	/* Power Management */
145 	union {
146 		struct {
147 			uint32_t pctl;
148 			uint32_t pba;
149 			uint32_t pfie;
150 			uint32_t pdtc;
151 			uint32_t cctl;
152 			uint32_t cba;
153 			uint32_t cie;
154 		} cs4280;
155 		struct {
156 			uint32_t dba0;
157 			uint32_t dbc0;
158 			uint32_t dmr0;
159 			uint32_t dcr0;
160 			uint32_t dba1;
161 			uint32_t dbc1;
162 			uint32_t dmr1;
163 			uint32_t dcr1;
164 		} cs4281;
165 	} sc_suspend_state;
166 
167 	/* CLKRUN hack (CS428X_FLAG_CLKRUN), only for CS4280 */
168 	int sc_active;
169 	bus_space_tag_t    sc_pm_iot;
170 	bus_space_handle_t sc_pm_ioh;
171 };
172 
173 
174 int  cs428x_round_blocksize(void *, int, int, const audio_params_t *);
175 int  cs428x_get_props(void *);
176 int  cs428x_attach_codec(void *, struct ac97_codec_if *);
177 int  cs428x_read_codec(void *, u_int8_t, u_int16_t *);
178 int  cs428x_write_codec(void *, u_int8_t, u_int16_t);
179 
180 int  cs428x_mixer_set_port(void *, mixer_ctrl_t *);
181 int  cs428x_mixer_get_port(void *, mixer_ctrl_t *);
182 int  cs428x_query_devinfo(void *, mixer_devinfo_t *);
183 void *cs428x_malloc(void *, int, size_t);
184 size_t cs428x_round_buffersize(void *, int, size_t);
185 void cs428x_free(void *, void *, size_t);
186 void cs428x_get_locks(void *, kmutex_t **, kmutex_t **);
187 
188 /* internal functions */
189 int cs428x_allocmem(struct cs428x_softc *, size_t, struct cs428x_dma *);
190 int cs428x_src_wait(struct cs428x_softc *);
191 
192 
193 /* DEBUG */
194 /* #define CS4280_DEBUG */
195 /* #define CS4281_DEBUG */
196 
197 #if defined(CS4280_DEBUG) || defined(CS4281_DEBUG)
198 #define DPRINTF(x)	    if (cs428x_debug) printf x
199 #define DPRINTFN(n,x)	    if (cs428x_debug>(n)) printf x
200 extern int cs428x_debug;
201 #if CS4280_DEBUG + 0 == 0
202 #undef CS4280_DEBUG
203 #define CS4280_DEBUG 0
204 #endif
205 #else
206 #define DPRINTF(x)
207 #define DPRINTFN(n,x)
208 #endif
209 
210 #endif /* _CS428X_H_ */
211