summaryrefslogtreecommitdiff
path: root/sys/arch/luna88k/cbus/nec86hwvar.h
blob: d0c4f4c1a1155657421ee3640b3724324e52fe4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*	$OpenBSD: nec86hwvar.h,v 1.3 2016/09/19 06:46:43 ratchov Exp $	*/
/*	$NecBSD: nec86hwvar.h,v 1.10 1998/03/14 07:04:55 kmatsuda Exp $	*/
/*	$NetBSD$	*/

/*
 * [NetBSD for NEC PC-98 series]
 *  Copyright (c) 1996, 1997, 1998
 *	NetBSD/pc98 porting staff. All rights reserved.
 * 
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *  1. Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *  3. The name of the author may not be used to endorse or promote products
 *     derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * nec86hwvar.h
 *
 * NEC PC-9801-86 SoundBoard PCM driver for NetBSD/pc98.
 * Written by NAGAO Tadaaki, Feb 10, 1996.
 */

#ifndef	_NEC86HWVAR_H_
#define	_NEC86HWVAR_H_

/* types of function which writes to/reads from FIFO buffer */
struct nec86hw_softc;	/* dummy declaration */
typedef int (*func_fifo_output_t) (struct nec86hw_softc *, int);
typedef void (*func_fifo_input_t) (struct nec86hw_softc *, int);


struct nec86hw_softc {
	struct	device sc_dev;		/* base device */

	bus_space_tag_t sc_iot;		/* bus space tag */
	bus_space_handle_t sc_ioh;	/* nec86 core chip space handle */

	u_int	sc_cfgflags;		/* config flags */
#define NEC86HW_RATE_TYPE(flags)	((flags) & 1)
#define NEC86HW_NRATE_TYPE		2

	u_short	sc_open;		/* reference count of open calls */

	u_long	sc_irate;		/* sample rate for input */
	u_long	sc_orate;		/* sample rate for output */

	u_long	hw_irate;		/* hardware rate for input */
	u_char	hw_irate_bits;
	u_long	hw_orate;		/* hardware rate for output */
	u_char	hw_orate_bits;

	u_int	encoding;		/* ulaw / linear */
	u_int	precision;		/* 8/16 bits */
	int	channels;		/* monoral(1) / stereo(2) */

	int	in_port;		/* Just keep track of it */
#define NEC86HW_INPUT_MIXER	0
	int	out_port;		/* Just keep track of it */
#define NEC86HW_OUTPUT_MIXER	0

	int 	model;			/* board identification number */

	/* linear interpolation */
	u_long	conv_acc;
	u_short	conv_last0;
	u_short	conv_last0_l;
	u_short	conv_last0_r;
	u_short	conv_last1;
	u_short	conv_last1_l;
	u_short	conv_last1_r;

	void	(*sc_intr)(void *);	/* DMA completion intr handler */
	void	*sc_arg;		/* arg for sc_intr() */

	char	intr_busy;		/* whether the hardware running */

	/* pseudo-DMA */
	u_char	*pdma_ptr;		/* pointer to the data buffer */
	int	pdma_count;		/* size of the data in frames */
	int	pdma_nchunk;		/* number of chunks to do with */
	int	pdma_watermark;		/* interrupt trigger level */
	char	pdma_padded;		/* the buffer is padded out with
					   dummy zero's */
	char	pdma_mode;		/* input/output indicator */
#define PDMA_MODE_NONE		0
#define PDMA_MODE_OUTPUT	1
#define PDMA_MODE_INPUT		2

	/* function which writes to/reads from FIFO buffer */
	func_fifo_output_t	func_fifo_output;
	func_fifo_input_t	func_fifo_input;
};

struct nec86hw_functable_entry {
	int	precision;
	int	channels;

	func_fifo_output_t 	func_fifo_output_direct;
	func_fifo_input_t	func_fifo_input_direct;
	func_fifo_output_t	func_fifo_output_resamp;
	func_fifo_input_t	func_fifo_input_resamp;
};

/*
 * Interrupt watermarks for the FIFO ring buffer on the hardware.
 *
 * These values must satisfy:
 *	0 < WATERMARK_RATIO_OUT <= WATERMARK_MAX_RATIO
 *	0 < WATERMARK_RATIO_IN  <= WATERMARK_MAX_RATIO.
 * (For more details, see also nec86hw_pdma_output() and nec86hw_pdma_input()
 *  in nec86hw.c)
 */
#define WATERMARK_MAX_RATIO	100
#define WATERMARK_RATIO_OUT	50	/* 50% of the blocksize */
#define WATERMARK_RATIO_IN	50	/* 50% of NEC86_BUFFSIZE */

/*
 * Declarations of prototypes.
 */
#ifdef _KERNEL
void	nec86hw_attach(struct nec86hw_softc *);

int	nec86hw_open(void *, int);
void	nec86hw_close(void *);

int	nec86hw_set_params(void *, int, int, struct audio_params *,
	    struct audio_params *);

int	nec86hw_round_blocksize(void *, int);

int	nec86hw_set_out_port(void *, int);
int	nec86hw_get_out_port(void *);
int	nec86hw_set_in_port(void *, int);
int	nec86hw_get_in_port(void *);

int	nec86hw_commit_settings(void *);

int	nec86hw_setfd(void *, int);

int	nec86hw_mixer_set_port(void *, mixer_ctrl_t *);
int	nec86hw_mixer_get_port(void *, mixer_ctrl_t *);
int	nec86hw_mixer_query_devinfo(void *, mixer_devinfo_t *);

int	nec86hw_pdma_init_output(void *, void *, int);
int	nec86hw_pdma_init_input(void *, void *, int);
int	nec86hw_pdma_output(void *, void *, int, void (*)(void *), void *);
int	nec86hw_pdma_input(void *, void *, int, void (*)(void *), void *);

int	nec86hw_speaker_ctl(void *, int);

int	nec86hw_halt_pdma(void *);
int	nec86hw_cont_pdma(void *);

u_char	nec86hw_rate_bits(struct nec86hw_softc *, u_long);
int	nec86hw_round_watermark(int);

int	nec86hw_reset(struct nec86hw_softc *);
void	nec86hw_set_mode_playing(struct nec86hw_softc *);
void	nec86hw_set_mode_recording(struct nec86hw_softc *);

void	nec86hw_set_volume(struct nec86hw_softc *, int, u_char);

void	nec86hw_start_fifo(struct nec86hw_softc *);
void	nec86hw_stop_fifo(struct nec86hw_softc *);
void	nec86hw_enable_fifointr(struct nec86hw_softc *);
void	nec86hw_disable_fifointr(struct nec86hw_softc *);
int	nec86hw_seeif_intrflg(struct nec86hw_softc *);
void	nec86hw_clear_intrflg(struct nec86hw_softc *);
void	nec86hw_reset_fifo(struct nec86hw_softc *);
void	nec86hw_set_watermark(struct nec86hw_softc *, int);
void	nec86hw_set_precision_real(struct nec86hw_softc *, u_int);
void	nec86hw_set_rate_real(struct nec86hw_softc *, u_char);

void	nec86hw_output_chunk(struct nec86hw_softc *);
void	nec86hw_input_chunk(struct nec86hw_softc *);

int	nec86fifo_output_mono_8_direct(struct nec86hw_softc *, int);
int	nec86fifo_output_mono_16_direct(struct nec86hw_softc *, int);
int	nec86fifo_output_stereo_8_direct(struct nec86hw_softc *, int);
int	nec86fifo_output_stereo_16_direct(struct nec86hw_softc *, int);
int	nec86fifo_output_mono_8_resamp(struct nec86hw_softc *, int);
int	nec86fifo_output_mono_16_resamp(struct nec86hw_softc *, int);
int	nec86fifo_output_stereo_8_resamp(struct nec86hw_softc *, int);
int	nec86fifo_output_stereo_16_resamp(struct nec86hw_softc *, int);
void	nec86fifo_input_mono_8_direct(struct nec86hw_softc *, int);
void	nec86fifo_input_mono_16_direct(struct nec86hw_softc *, int);
void	nec86fifo_input_stereo_8_direct(struct nec86hw_softc *, int);
void	nec86fifo_input_stereo_16_direct(struct nec86hw_softc *, int);
void	nec86fifo_input_mono_8_resamp(struct nec86hw_softc *, int);
void	nec86fifo_input_mono_16_resamp(struct nec86hw_softc *, int);
void	nec86fifo_input_stereo_8_resamp(struct nec86hw_softc *, int);
void	nec86fifo_input_stereo_16_resamp(struct nec86hw_softc *, int);

void	nec86fifo_padding(struct nec86hw_softc *, int);

int	nec86hw_intr(void *);

int 	nec86_get_props(void *);

#endif	/* _KERNEL */
#endif	/* !_NEC86HWVAR_H_ */