1 |
1275 |
phoenix |
/*****************************************************************************/
|
2 |
|
|
|
3 |
|
|
/*
|
4 |
|
|
* es1370.c -- Ensoniq ES1370/Asahi Kasei AK4531 audio driver.
|
5 |
|
|
*
|
6 |
|
|
* Copyright (C) 1998-2001, 2003 Thomas Sailer (t.sailer@alumni.ethz.ch)
|
7 |
|
|
*
|
8 |
|
|
* This program is free software; you can redistribute it and/or modify
|
9 |
|
|
* it under the terms of the GNU General Public License as published by
|
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
11 |
|
|
* (at your option) any later version.
|
12 |
|
|
*
|
13 |
|
|
* This program is distributed in the hope that it will be useful,
|
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
* GNU General Public License for more details.
|
17 |
|
|
*
|
18 |
|
|
* You should have received a copy of the GNU General Public License
|
19 |
|
|
* along with this program; if not, write to the Free Software
|
20 |
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
21 |
|
|
*
|
22 |
|
|
* Special thanks to David C. Niemi
|
23 |
|
|
*
|
24 |
|
|
*
|
25 |
|
|
* Module command line parameters:
|
26 |
|
|
* joystick if 1 enables the joystick interface on the card; but it still
|
27 |
|
|
* needs a driver for joysticks connected to a standard IBM-PC
|
28 |
|
|
* joyport. It is tested with the joy-analog driver. This
|
29 |
|
|
* module must be loaded before the joystick driver. Kmod will
|
30 |
|
|
* not ensure that.
|
31 |
|
|
* lineout if 1 the LINE jack is used as an output instead of an input.
|
32 |
|
|
* LINE then contains the unmixed dsp output. This can be used
|
33 |
|
|
* to make the card a four channel one: use dsp to output two
|
34 |
|
|
* channels to LINE and dac to output the other two channels to
|
35 |
|
|
* SPKR. Set the mixer to only output synth to SPKR.
|
36 |
|
|
* micbias sets the +5V bias to the mic if using an electretmic.
|
37 |
|
|
*
|
38 |
|
|
*
|
39 |
|
|
* Note: sync mode is not yet supported (i.e. running dsp and dac from the same
|
40 |
|
|
* clock source)
|
41 |
|
|
*
|
42 |
|
|
* Supported devices:
|
43 |
|
|
* /dev/dsp standard /dev/dsp device, (mostly) OSS compatible
|
44 |
|
|
* /dev/mixer standard /dev/mixer device, (mostly) OSS compatible
|
45 |
|
|
* /dev/dsp1 additional DAC, like /dev/dsp, but output only,
|
46 |
|
|
* only 5512, 11025, 22050 and 44100 samples/s,
|
47 |
|
|
* outputs to mixer "SYNTH" setting
|
48 |
|
|
* /dev/midi simple MIDI UART interface, no ioctl
|
49 |
|
|
*
|
50 |
|
|
* NOTE: the card does not have any FM/Wavetable synthesizer, it is supposed
|
51 |
|
|
* to be done in software. That is what /dev/dac is for. By now (Q2 1998)
|
52 |
|
|
* there are several MIDI to PCM (WAV) packages, one of them is timidity.
|
53 |
|
|
*
|
54 |
|
|
* Revision history
|
55 |
|
|
* 26.03.1998 0.1 Initial release
|
56 |
|
|
* 31.03.1998 0.2 Fix bug in GETOSPACE
|
57 |
|
|
* 04.04.1998 0.3 Make it work (again) under 2.0.33
|
58 |
|
|
* Fix mixer write operation not returning the actual
|
59 |
|
|
* settings
|
60 |
|
|
* 05.04.1998 0.4 First attempt at using the new PCI stuff
|
61 |
|
|
* 29.04.1998 0.5 Fix hang when ^C is pressed on amp
|
62 |
|
|
* 07.05.1998 0.6 Don't double lock around stop_*() in *_release()
|
63 |
|
|
* 10.05.1998 0.7 First stab at a simple midi interface (no bells&whistles)
|
64 |
|
|
* 14.05.1998 0.8 Don't allow excessive interrupt rates
|
65 |
|
|
* 08.06.1998 0.9 First release using Alan Cox' soundcore instead of
|
66 |
|
|
* miscdevice
|
67 |
|
|
* 05.07.1998 0.10 Fixed the driver to correctly maintin OSS style volume
|
68 |
|
|
* settings (not sure if this should be standard)
|
69 |
|
|
* Fixed many references: f_flags should be f_mode
|
70 |
|
|
* -- Gerald Britton <gbritton@mit.edu>
|
71 |
|
|
* 03.08.1998 0.11 Now mixer behaviour can basically be selected between
|
72 |
|
|
* "OSS documented" and "OSS actual" behaviour
|
73 |
|
|
* Fixed mixer table thanks to Hakan.Lennestal@lu.erisoft.se
|
74 |
|
|
* On module startup, set DAC2 to 11kSPS instead of 5.5kSPS,
|
75 |
|
|
* as it produces an annoying ssssh in the lower sampling rate
|
76 |
|
|
* Do not include modversions.h
|
77 |
|
|
* 22.08.1998 0.12 Mixer registers actually have 5 instead of 4 bits
|
78 |
|
|
* pointed out by Itai Nahshon
|
79 |
|
|
* 31.08.1998 0.13 Fix realplayer problems - dac.count issues
|
80 |
|
|
* 08.10.1998 0.14 Joystick support fixed
|
81 |
|
|
* -- Oliver Neukum <c188@org.chemie.uni-muenchen.de>
|
82 |
|
|
* 10.12.1998 0.15 Fix drain_dac trying to wait on not yet initialized DMA
|
83 |
|
|
* 16.12.1998 0.16 Don't wake up app until there are fragsize bytes to read/write
|
84 |
|
|
* 06.01.1999 0.17 remove the silly SA_INTERRUPT flag.
|
85 |
|
|
* hopefully killed the egcs section type conflict
|
86 |
|
|
* 12.03.1999 0.18 cinfo.blocks should be reset after GETxPTR ioctl.
|
87 |
|
|
* reported by Johan Maes <joma@telindus.be>
|
88 |
|
|
* 22.03.1999 0.19 return EAGAIN instead of EBUSY when O_NONBLOCK
|
89 |
|
|
* read/write cannot be executed
|
90 |
|
|
* 07.04.1999 0.20 implemented the following ioctl's: SOUND_PCM_READ_RATE,
|
91 |
|
|
* SOUND_PCM_READ_CHANNELS, SOUND_PCM_READ_BITS;
|
92 |
|
|
* Alpha fixes reported by Peter Jones <pjones@redhat.com>
|
93 |
|
|
* Note: joystick address handling might still be wrong on archs
|
94 |
|
|
* other than i386
|
95 |
|
|
* 10.05.1999 0.21 Added support for an electret mic for SB PCI64
|
96 |
|
|
* to the Linux kernel sound driver. This mod also straighten
|
97 |
|
|
* out the question marks around the mic impedance setting
|
98 |
|
|
* (micz). From Kim.Berts@fisub.mail.abb.com
|
99 |
|
|
* 11.05.1999 0.22 Implemented the IMIX call to mute recording monitor.
|
100 |
|
|
* Guenter Geiger <geiger@epy.co.at>
|
101 |
|
|
* 15.06.1999 0.23 Fix bad allocation bug.
|
102 |
|
|
* Thanks to Deti Fliegl <fliegl@in.tum.de>
|
103 |
|
|
* 28.06.1999 0.24 Add pci_set_master
|
104 |
|
|
* 02.08.1999 0.25 Added workaround for the "phantom write" bug first
|
105 |
|
|
* documented by Dave Sharpless from Anchor Games
|
106 |
|
|
* 03.08.1999 0.26 adapt to Linus' new __setup/__initcall
|
107 |
|
|
* added kernel command line option "es1370=joystick[,lineout[,micbias]]"
|
108 |
|
|
* removed CONFIG_SOUND_ES1370_JOYPORT_BOOT kludge
|
109 |
|
|
* 12.08.1999 0.27 module_init/__setup fixes
|
110 |
|
|
* 19.08.1999 0.28 SOUND_MIXER_IMIX fixes, reported by Gianluca <gialluca@mail.tiscalinet.it>
|
111 |
|
|
* 31.08.1999 0.29 add spin_lock_init
|
112 |
|
|
* replaced current->state = x with set_current_state(x)
|
113 |
|
|
* 03.09.1999 0.30 change read semantics for MIDI to match
|
114 |
|
|
* OSS more closely; remove possible wakeup race
|
115 |
|
|
* 28.10.1999 0.31 More waitqueue races fixed
|
116 |
|
|
* 08.01.2000 0.32 Prevent some ioctl's from returning bad count values on underrun/overrun;
|
117 |
|
|
* Tim Janik's BSE (Bedevilled Sound Engine) found this
|
118 |
|
|
* 07.02.2000 0.33 Use pci_alloc_consistent and pci_register_driver
|
119 |
|
|
* 21.11.2000 0.34 Initialize dma buffers in poll, otherwise poll may return a bogus mask
|
120 |
|
|
* 12.12.2000 0.35 More dma buffer initializations, patch from
|
121 |
|
|
* Tjeerd Mulder <tjeerd.mulder@fujitsu-siemens.com>
|
122 |
|
|
* 07.01.2001 0.36 Timeout change in wrcodec as requested by Frank Klemm <pfk@fuchs.offl.uni-jena.de>
|
123 |
|
|
* 31.01.2001 0.37 Register/Unregister gameport
|
124 |
|
|
* Fix SETTRIGGER non OSS API conformity
|
125 |
|
|
* 03.01.2003 0.38 open_mode fixes from Georg Acher <acher@in.tum.de>
|
126 |
|
|
*
|
127 |
|
|
* some important things missing in Ensoniq documentation:
|
128 |
|
|
*
|
129 |
|
|
* Experimental PCLKDIV results: play the same waveforms on both DAC1 and DAC2
|
130 |
|
|
* and vary PCLKDIV to obtain zero beat.
|
131 |
|
|
* 5512sps: 254
|
132 |
|
|
* 44100sps: 30
|
133 |
|
|
* seems to be fs = 1411200/(PCLKDIV+2)
|
134 |
|
|
*
|
135 |
|
|
* should find out when curr_sample_ct is cleared and
|
136 |
|
|
* where exactly the CCB fetches data
|
137 |
|
|
*
|
138 |
|
|
* The card uses a 22.5792 MHz crystal.
|
139 |
|
|
* The LINEIN jack may be converted to an AOUT jack by
|
140 |
|
|
* setting pin 47 (XCTL0) of the ES1370 to high.
|
141 |
|
|
* Pin 48 (XCTL1) of the ES1370 sets the +5V bias for an electretmic
|
142 |
|
|
*
|
143 |
|
|
*
|
144 |
|
|
*/
|
145 |
|
|
|
146 |
|
|
/*****************************************************************************/
|
147 |
|
|
|
148 |
|
|
#include <linux/version.h>
|
149 |
|
|
#include <linux/module.h>
|
150 |
|
|
#include <linux/string.h>
|
151 |
|
|
#include <linux/ioport.h>
|
152 |
|
|
#include <linux/sched.h>
|
153 |
|
|
#include <linux/delay.h>
|
154 |
|
|
#include <linux/sound.h>
|
155 |
|
|
#include <linux/slab.h>
|
156 |
|
|
#include <linux/soundcard.h>
|
157 |
|
|
#include <linux/pci.h>
|
158 |
|
|
#include <linux/smp_lock.h>
|
159 |
|
|
#include <linux/wrapper.h>
|
160 |
|
|
#include <asm/io.h>
|
161 |
|
|
#include <asm/dma.h>
|
162 |
|
|
#include <linux/init.h>
|
163 |
|
|
#include <linux/poll.h>
|
164 |
|
|
#include <linux/spinlock.h>
|
165 |
|
|
#include <asm/uaccess.h>
|
166 |
|
|
#include <asm/hardirq.h>
|
167 |
|
|
#include <linux/gameport.h>
|
168 |
|
|
|
169 |
|
|
/* --------------------------------------------------------------------- */
|
170 |
|
|
|
171 |
|
|
#undef OSS_DOCUMENTED_MIXER_SEMANTICS
|
172 |
|
|
#define DBG(x) {}
|
173 |
|
|
/*#define DBG(x) {x}*/
|
174 |
|
|
|
175 |
|
|
/* --------------------------------------------------------------------- */
|
176 |
|
|
|
177 |
|
|
#ifndef PCI_VENDOR_ID_ENSONIQ
|
178 |
|
|
#define PCI_VENDOR_ID_ENSONIQ 0x1274
|
179 |
|
|
#endif
|
180 |
|
|
|
181 |
|
|
#ifndef PCI_DEVICE_ID_ENSONIQ_ES1370
|
182 |
|
|
#define PCI_DEVICE_ID_ENSONIQ_ES1370 0x5000
|
183 |
|
|
#endif
|
184 |
|
|
|
185 |
|
|
#define ES1370_MAGIC ((PCI_VENDOR_ID_ENSONIQ<<16)|PCI_DEVICE_ID_ENSONIQ_ES1370)
|
186 |
|
|
|
187 |
|
|
#define ES1370_EXTENT 0x40
|
188 |
|
|
#define JOY_EXTENT 8
|
189 |
|
|
|
190 |
|
|
#define ES1370_REG_CONTROL 0x00
|
191 |
|
|
#define ES1370_REG_STATUS 0x04
|
192 |
|
|
#define ES1370_REG_UART_DATA 0x08
|
193 |
|
|
#define ES1370_REG_UART_STATUS 0x09
|
194 |
|
|
#define ES1370_REG_UART_CONTROL 0x09
|
195 |
|
|
#define ES1370_REG_UART_TEST 0x0a
|
196 |
|
|
#define ES1370_REG_MEMPAGE 0x0c
|
197 |
|
|
#define ES1370_REG_CODEC 0x10
|
198 |
|
|
#define ES1370_REG_SERIAL_CONTROL 0x20
|
199 |
|
|
#define ES1370_REG_DAC1_SCOUNT 0x24
|
200 |
|
|
#define ES1370_REG_DAC2_SCOUNT 0x28
|
201 |
|
|
#define ES1370_REG_ADC_SCOUNT 0x2c
|
202 |
|
|
|
203 |
|
|
#define ES1370_REG_DAC1_FRAMEADR 0xc30
|
204 |
|
|
#define ES1370_REG_DAC1_FRAMECNT 0xc34
|
205 |
|
|
#define ES1370_REG_DAC2_FRAMEADR 0xc38
|
206 |
|
|
#define ES1370_REG_DAC2_FRAMECNT 0xc3c
|
207 |
|
|
#define ES1370_REG_ADC_FRAMEADR 0xd30
|
208 |
|
|
#define ES1370_REG_ADC_FRAMECNT 0xd34
|
209 |
|
|
#define ES1370_REG_PHANTOM_FRAMEADR 0xd38
|
210 |
|
|
#define ES1370_REG_PHANTOM_FRAMECNT 0xd3c
|
211 |
|
|
|
212 |
|
|
#define ES1370_FMT_U8_MONO 0
|
213 |
|
|
#define ES1370_FMT_U8_STEREO 1
|
214 |
|
|
#define ES1370_FMT_S16_MONO 2
|
215 |
|
|
#define ES1370_FMT_S16_STEREO 3
|
216 |
|
|
#define ES1370_FMT_STEREO 1
|
217 |
|
|
#define ES1370_FMT_S16 2
|
218 |
|
|
#define ES1370_FMT_MASK 3
|
219 |
|
|
|
220 |
|
|
static const unsigned sample_size[] = { 1, 2, 2, 4 };
|
221 |
|
|
static const unsigned sample_shift[] = { 0, 1, 1, 2 };
|
222 |
|
|
|
223 |
|
|
static const unsigned dac1_samplerate[] = { 5512, 11025, 22050, 44100 };
|
224 |
|
|
|
225 |
|
|
#define DAC2_SRTODIV(x) (((1411200+(x)/2)/(x))-2)
|
226 |
|
|
#define DAC2_DIVTOSR(x) (1411200/((x)+2))
|
227 |
|
|
|
228 |
|
|
#define CTRL_ADC_STOP 0x80000000 /* 1 = ADC stopped */
|
229 |
|
|
#define CTRL_XCTL1 0x40000000 /* electret mic bias */
|
230 |
|
|
#define CTRL_OPEN 0x20000000 /* no function, can be read and written */
|
231 |
|
|
#define CTRL_PCLKDIV 0x1fff0000 /* ADC/DAC2 clock divider */
|
232 |
|
|
#define CTRL_SH_PCLKDIV 16
|
233 |
|
|
#define CTRL_MSFMTSEL 0x00008000 /* MPEG serial data fmt: 0 = Sony, 1 = I2S */
|
234 |
|
|
#define CTRL_M_SBB 0x00004000 /* DAC2 clock: 0 = PCLKDIV, 1 = MPEG */
|
235 |
|
|
#define CTRL_WTSRSEL 0x00003000 /* DAC1 clock freq: 0=5512, 1=11025, 2=22050, 3=44100 */
|
236 |
|
|
#define CTRL_SH_WTSRSEL 12
|
237 |
|
|
#define CTRL_DAC_SYNC 0x00000800 /* 1 = DAC2 runs off DAC1 clock */
|
238 |
|
|
#define CTRL_CCB_INTRM 0x00000400 /* 1 = CCB "voice" ints enabled */
|
239 |
|
|
#define CTRL_M_CB 0x00000200 /* recording source: 0 = ADC, 1 = MPEG */
|
240 |
|
|
#define CTRL_XCTL0 0x00000100 /* 0 = Line in, 1 = Line out */
|
241 |
|
|
#define CTRL_BREQ 0x00000080 /* 1 = test mode (internal mem test) */
|
242 |
|
|
#define CTRL_DAC1_EN 0x00000040 /* enable DAC1 */
|
243 |
|
|
#define CTRL_DAC2_EN 0x00000020 /* enable DAC2 */
|
244 |
|
|
#define CTRL_ADC_EN 0x00000010 /* enable ADC */
|
245 |
|
|
#define CTRL_UART_EN 0x00000008 /* enable MIDI uart */
|
246 |
|
|
#define CTRL_JYSTK_EN 0x00000004 /* enable Joystick port (presumably at address 0x200) */
|
247 |
|
|
#define CTRL_CDC_EN 0x00000002 /* enable serial (CODEC) interface */
|
248 |
|
|
#define CTRL_SERR_DIS 0x00000001 /* 1 = disable PCI SERR signal */
|
249 |
|
|
|
250 |
|
|
#define STAT_INTR 0x80000000 /* wired or of all interrupt bits */
|
251 |
|
|
#define STAT_CSTAT 0x00000400 /* 1 = codec busy or codec write in progress */
|
252 |
|
|
#define STAT_CBUSY 0x00000200 /* 1 = codec busy */
|
253 |
|
|
#define STAT_CWRIP 0x00000100 /* 1 = codec write in progress */
|
254 |
|
|
#define STAT_VC 0x00000060 /* CCB int source, 0=DAC1, 1=DAC2, 2=ADC, 3=undef */
|
255 |
|
|
#define STAT_SH_VC 5
|
256 |
|
|
#define STAT_MCCB 0x00000010 /* CCB int pending */
|
257 |
|
|
#define STAT_UART 0x00000008 /* UART int pending */
|
258 |
|
|
#define STAT_DAC1 0x00000004 /* DAC1 int pending */
|
259 |
|
|
#define STAT_DAC2 0x00000002 /* DAC2 int pending */
|
260 |
|
|
#define STAT_ADC 0x00000001 /* ADC int pending */
|
261 |
|
|
|
262 |
|
|
#define USTAT_RXINT 0x80 /* UART rx int pending */
|
263 |
|
|
#define USTAT_TXINT 0x04 /* UART tx int pending */
|
264 |
|
|
#define USTAT_TXRDY 0x02 /* UART tx ready */
|
265 |
|
|
#define USTAT_RXRDY 0x01 /* UART rx ready */
|
266 |
|
|
|
267 |
|
|
#define UCTRL_RXINTEN 0x80 /* 1 = enable RX ints */
|
268 |
|
|
#define UCTRL_TXINTEN 0x60 /* TX int enable field mask */
|
269 |
|
|
#define UCTRL_ENA_TXINT 0x20 /* enable TX int */
|
270 |
|
|
#define UCTRL_CNTRL 0x03 /* control field */
|
271 |
|
|
#define UCTRL_CNTRL_SWR 0x03 /* software reset command */
|
272 |
|
|
|
273 |
|
|
#define SCTRL_P2ENDINC 0x00380000 /* */
|
274 |
|
|
#define SCTRL_SH_P2ENDINC 19
|
275 |
|
|
#define SCTRL_P2STINC 0x00070000 /* */
|
276 |
|
|
#define SCTRL_SH_P2STINC 16
|
277 |
|
|
#define SCTRL_R1LOOPSEL 0x00008000 /* 0 = loop mode */
|
278 |
|
|
#define SCTRL_P2LOOPSEL 0x00004000 /* 0 = loop mode */
|
279 |
|
|
#define SCTRL_P1LOOPSEL 0x00002000 /* 0 = loop mode */
|
280 |
|
|
#define SCTRL_P2PAUSE 0x00001000 /* 1 = pause mode */
|
281 |
|
|
#define SCTRL_P1PAUSE 0x00000800 /* 1 = pause mode */
|
282 |
|
|
#define SCTRL_R1INTEN 0x00000400 /* enable interrupt */
|
283 |
|
|
#define SCTRL_P2INTEN 0x00000200 /* enable interrupt */
|
284 |
|
|
#define SCTRL_P1INTEN 0x00000100 /* enable interrupt */
|
285 |
|
|
#define SCTRL_P1SCTRLD 0x00000080 /* reload sample count register for DAC1 */
|
286 |
|
|
#define SCTRL_P2DACSEN 0x00000040 /* 1 = DAC2 play back last sample when disabled */
|
287 |
|
|
#define SCTRL_R1SEB 0x00000020 /* 1 = 16bit */
|
288 |
|
|
#define SCTRL_R1SMB 0x00000010 /* 1 = stereo */
|
289 |
|
|
#define SCTRL_R1FMT 0x00000030 /* format mask */
|
290 |
|
|
#define SCTRL_SH_R1FMT 4
|
291 |
|
|
#define SCTRL_P2SEB 0x00000008 /* 1 = 16bit */
|
292 |
|
|
#define SCTRL_P2SMB 0x00000004 /* 1 = stereo */
|
293 |
|
|
#define SCTRL_P2FMT 0x0000000c /* format mask */
|
294 |
|
|
#define SCTRL_SH_P2FMT 2
|
295 |
|
|
#define SCTRL_P1SEB 0x00000002 /* 1 = 16bit */
|
296 |
|
|
#define SCTRL_P1SMB 0x00000001 /* 1 = stereo */
|
297 |
|
|
#define SCTRL_P1FMT 0x00000003 /* format mask */
|
298 |
|
|
#define SCTRL_SH_P1FMT 0
|
299 |
|
|
|
300 |
|
|
/* misc stuff */
|
301 |
|
|
|
302 |
|
|
#define FMODE_DAC 4 /* slight misuse of mode_t */
|
303 |
|
|
|
304 |
|
|
/* MIDI buffer sizes */
|
305 |
|
|
|
306 |
|
|
#define MIDIINBUF 256
|
307 |
|
|
#define MIDIOUTBUF 256
|
308 |
|
|
|
309 |
|
|
#define FMODE_MIDI_SHIFT 3
|
310 |
|
|
#define FMODE_MIDI_READ (FMODE_READ << FMODE_MIDI_SHIFT)
|
311 |
|
|
#define FMODE_MIDI_WRITE (FMODE_WRITE << FMODE_MIDI_SHIFT)
|
312 |
|
|
|
313 |
|
|
/* --------------------------------------------------------------------- */
|
314 |
|
|
|
315 |
|
|
struct es1370_state {
|
316 |
|
|
/* magic */
|
317 |
|
|
unsigned int magic;
|
318 |
|
|
|
319 |
|
|
/* list of es1370 devices */
|
320 |
|
|
struct list_head devs;
|
321 |
|
|
|
322 |
|
|
/* the corresponding pci_dev structure */
|
323 |
|
|
struct pci_dev *dev;
|
324 |
|
|
|
325 |
|
|
/* soundcore stuff */
|
326 |
|
|
int dev_audio;
|
327 |
|
|
int dev_mixer;
|
328 |
|
|
int dev_dac;
|
329 |
|
|
int dev_midi;
|
330 |
|
|
|
331 |
|
|
/* hardware resources */
|
332 |
|
|
unsigned long io; /* long for SPARC */
|
333 |
|
|
unsigned int irq;
|
334 |
|
|
|
335 |
|
|
/* mixer registers; there is no HW readback */
|
336 |
|
|
struct {
|
337 |
|
|
unsigned short vol[10];
|
338 |
|
|
unsigned int recsrc;
|
339 |
|
|
unsigned int modcnt;
|
340 |
|
|
unsigned short micpreamp;
|
341 |
|
|
unsigned int imix;
|
342 |
|
|
} mix;
|
343 |
|
|
|
344 |
|
|
/* wave stuff */
|
345 |
|
|
unsigned ctrl;
|
346 |
|
|
unsigned sctrl;
|
347 |
|
|
|
348 |
|
|
spinlock_t lock;
|
349 |
|
|
struct semaphore open_sem;
|
350 |
|
|
mode_t open_mode;
|
351 |
|
|
wait_queue_head_t open_wait;
|
352 |
|
|
|
353 |
|
|
struct dmabuf {
|
354 |
|
|
void *rawbuf;
|
355 |
|
|
dma_addr_t dmaaddr;
|
356 |
|
|
unsigned buforder;
|
357 |
|
|
unsigned numfrag;
|
358 |
|
|
unsigned fragshift;
|
359 |
|
|
unsigned hwptr, swptr;
|
360 |
|
|
unsigned total_bytes;
|
361 |
|
|
int count;
|
362 |
|
|
unsigned error; /* over/underrun */
|
363 |
|
|
wait_queue_head_t wait;
|
364 |
|
|
/* redundant, but makes calculations easier */
|
365 |
|
|
unsigned fragsize;
|
366 |
|
|
unsigned dmasize;
|
367 |
|
|
unsigned fragsamples;
|
368 |
|
|
/* OSS stuff */
|
369 |
|
|
unsigned mapped:1;
|
370 |
|
|
unsigned ready:1;
|
371 |
|
|
unsigned endcleared:1;
|
372 |
|
|
unsigned enabled:1;
|
373 |
|
|
unsigned ossfragshift;
|
374 |
|
|
int ossmaxfrags;
|
375 |
|
|
unsigned subdivision;
|
376 |
|
|
} dma_dac1, dma_dac2, dma_adc;
|
377 |
|
|
|
378 |
|
|
/* midi stuff */
|
379 |
|
|
struct {
|
380 |
|
|
unsigned ird, iwr, icnt;
|
381 |
|
|
unsigned ord, owr, ocnt;
|
382 |
|
|
wait_queue_head_t iwait;
|
383 |
|
|
wait_queue_head_t owait;
|
384 |
|
|
unsigned char ibuf[MIDIINBUF];
|
385 |
|
|
unsigned char obuf[MIDIOUTBUF];
|
386 |
|
|
} midi;
|
387 |
|
|
|
388 |
|
|
struct gameport gameport;
|
389 |
|
|
struct semaphore sem;
|
390 |
|
|
};
|
391 |
|
|
|
392 |
|
|
/* --------------------------------------------------------------------- */
|
393 |
|
|
|
394 |
|
|
static LIST_HEAD(devs);
|
395 |
|
|
|
396 |
|
|
/*
|
397 |
|
|
* The following buffer is used to point the phantom write channel to,
|
398 |
|
|
* so that it cannot wreak havoc. The attribute makes sure it doesn't
|
399 |
|
|
* cross a page boundary and ensures dword alignment for the DMA engine
|
400 |
|
|
*/
|
401 |
|
|
static unsigned char *bugbuf; // [16] __attribute__ ((aligned (16)));
|
402 |
|
|
|
403 |
|
|
/* --------------------------------------------------------------------- */
|
404 |
|
|
|
405 |
|
|
static inline unsigned ld2(unsigned int x)
|
406 |
|
|
{
|
407 |
|
|
unsigned r = 0;
|
408 |
|
|
|
409 |
|
|
if (x >= 0x10000) {
|
410 |
|
|
x >>= 16;
|
411 |
|
|
r += 16;
|
412 |
|
|
}
|
413 |
|
|
if (x >= 0x100) {
|
414 |
|
|
x >>= 8;
|
415 |
|
|
r += 8;
|
416 |
|
|
}
|
417 |
|
|
if (x >= 0x10) {
|
418 |
|
|
x >>= 4;
|
419 |
|
|
r += 4;
|
420 |
|
|
}
|
421 |
|
|
if (x >= 4) {
|
422 |
|
|
x >>= 2;
|
423 |
|
|
r += 2;
|
424 |
|
|
}
|
425 |
|
|
if (x >= 2)
|
426 |
|
|
r++;
|
427 |
|
|
return r;
|
428 |
|
|
}
|
429 |
|
|
|
430 |
|
|
/* --------------------------------------------------------------------- */
|
431 |
|
|
|
432 |
|
|
static void wrcodec(struct es1370_state *s, unsigned char idx, unsigned char data)
|
433 |
|
|
{
|
434 |
|
|
unsigned long tmo = jiffies + HZ/10, j;
|
435 |
|
|
|
436 |
|
|
do {
|
437 |
|
|
j = jiffies;
|
438 |
|
|
if (!(inl(s->io+ES1370_REG_STATUS) & STAT_CSTAT)) {
|
439 |
|
|
outw((((unsigned short)idx)<<8)|data, s->io+ES1370_REG_CODEC);
|
440 |
|
|
return;
|
441 |
|
|
}
|
442 |
|
|
schedule();
|
443 |
|
|
} while ((signed)(tmo-j) > 0);
|
444 |
|
|
printk(KERN_ERR "es1370: write to codec register timeout\n");
|
445 |
|
|
}
|
446 |
|
|
|
447 |
|
|
/* --------------------------------------------------------------------- */
|
448 |
|
|
|
449 |
|
|
static inline void stop_adc(struct es1370_state *s)
|
450 |
|
|
{
|
451 |
|
|
unsigned long flags;
|
452 |
|
|
|
453 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
454 |
|
|
s->ctrl &= ~CTRL_ADC_EN;
|
455 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
456 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
457 |
|
|
}
|
458 |
|
|
|
459 |
|
|
static inline void stop_dac1(struct es1370_state *s)
|
460 |
|
|
{
|
461 |
|
|
unsigned long flags;
|
462 |
|
|
|
463 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
464 |
|
|
s->ctrl &= ~CTRL_DAC1_EN;
|
465 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
466 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
467 |
|
|
}
|
468 |
|
|
|
469 |
|
|
static inline void stop_dac2(struct es1370_state *s)
|
470 |
|
|
{
|
471 |
|
|
unsigned long flags;
|
472 |
|
|
|
473 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
474 |
|
|
s->ctrl &= ~CTRL_DAC2_EN;
|
475 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
476 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
477 |
|
|
}
|
478 |
|
|
|
479 |
|
|
static void start_dac1(struct es1370_state *s)
|
480 |
|
|
{
|
481 |
|
|
unsigned long flags;
|
482 |
|
|
unsigned fragremain, fshift;
|
483 |
|
|
|
484 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
485 |
|
|
if (!(s->ctrl & CTRL_DAC1_EN) && (s->dma_dac1.mapped || s->dma_dac1.count > 0)
|
486 |
|
|
&& s->dma_dac1.ready) {
|
487 |
|
|
s->ctrl |= CTRL_DAC1_EN;
|
488 |
|
|
s->sctrl = (s->sctrl & ~(SCTRL_P1LOOPSEL | SCTRL_P1PAUSE | SCTRL_P1SCTRLD)) | SCTRL_P1INTEN;
|
489 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
490 |
|
|
fragremain = ((- s->dma_dac1.hwptr) & (s->dma_dac1.fragsize-1));
|
491 |
|
|
fshift = sample_shift[(s->sctrl & SCTRL_P1FMT) >> SCTRL_SH_P1FMT];
|
492 |
|
|
if (fragremain < 2*fshift)
|
493 |
|
|
fragremain = s->dma_dac1.fragsize;
|
494 |
|
|
outl((fragremain >> fshift) - 1, s->io+ES1370_REG_DAC1_SCOUNT);
|
495 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
496 |
|
|
outl((s->dma_dac1.fragsize >> fshift) - 1, s->io+ES1370_REG_DAC1_SCOUNT);
|
497 |
|
|
}
|
498 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
499 |
|
|
}
|
500 |
|
|
|
501 |
|
|
static void start_dac2(struct es1370_state *s)
|
502 |
|
|
{
|
503 |
|
|
unsigned long flags;
|
504 |
|
|
unsigned fragremain, fshift;
|
505 |
|
|
|
506 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
507 |
|
|
if (!(s->ctrl & CTRL_DAC2_EN) && (s->dma_dac2.mapped || s->dma_dac2.count > 0)
|
508 |
|
|
&& s->dma_dac2.ready) {
|
509 |
|
|
s->ctrl |= CTRL_DAC2_EN;
|
510 |
|
|
s->sctrl = (s->sctrl & ~(SCTRL_P2LOOPSEL | SCTRL_P2PAUSE | SCTRL_P2DACSEN |
|
511 |
|
|
SCTRL_P2ENDINC | SCTRL_P2STINC)) | SCTRL_P2INTEN |
|
512 |
|
|
(((s->sctrl & SCTRL_P2FMT) ? 2 : 1) << SCTRL_SH_P2ENDINC) |
|
513 |
|
|
(0 << SCTRL_SH_P2STINC);
|
514 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
515 |
|
|
fragremain = ((- s->dma_dac2.hwptr) & (s->dma_dac2.fragsize-1));
|
516 |
|
|
fshift = sample_shift[(s->sctrl & SCTRL_P2FMT) >> SCTRL_SH_P2FMT];
|
517 |
|
|
if (fragremain < 2*fshift)
|
518 |
|
|
fragremain = s->dma_dac2.fragsize;
|
519 |
|
|
outl((fragremain >> fshift) - 1, s->io+ES1370_REG_DAC2_SCOUNT);
|
520 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
521 |
|
|
outl((s->dma_dac2.fragsize >> fshift) - 1, s->io+ES1370_REG_DAC2_SCOUNT);
|
522 |
|
|
}
|
523 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
524 |
|
|
}
|
525 |
|
|
|
526 |
|
|
static void start_adc(struct es1370_state *s)
|
527 |
|
|
{
|
528 |
|
|
unsigned long flags;
|
529 |
|
|
unsigned fragremain, fshift;
|
530 |
|
|
|
531 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
532 |
|
|
if (!(s->ctrl & CTRL_ADC_EN) && (s->dma_adc.mapped || s->dma_adc.count < (signed)(s->dma_adc.dmasize - 2*s->dma_adc.fragsize))
|
533 |
|
|
&& s->dma_adc.ready) {
|
534 |
|
|
s->ctrl |= CTRL_ADC_EN;
|
535 |
|
|
s->sctrl = (s->sctrl & ~SCTRL_R1LOOPSEL) | SCTRL_R1INTEN;
|
536 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
537 |
|
|
fragremain = ((- s->dma_adc.hwptr) & (s->dma_adc.fragsize-1));
|
538 |
|
|
fshift = sample_shift[(s->sctrl & SCTRL_R1FMT) >> SCTRL_SH_R1FMT];
|
539 |
|
|
if (fragremain < 2*fshift)
|
540 |
|
|
fragremain = s->dma_adc.fragsize;
|
541 |
|
|
outl((fragremain >> fshift) - 1, s->io+ES1370_REG_ADC_SCOUNT);
|
542 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
543 |
|
|
outl((s->dma_adc.fragsize >> fshift) - 1, s->io+ES1370_REG_ADC_SCOUNT);
|
544 |
|
|
}
|
545 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
546 |
|
|
}
|
547 |
|
|
|
548 |
|
|
/* --------------------------------------------------------------------- */
|
549 |
|
|
|
550 |
|
|
#define DMABUF_DEFAULTORDER (17-PAGE_SHIFT)
|
551 |
|
|
#define DMABUF_MINORDER 1
|
552 |
|
|
|
553 |
|
|
static inline void dealloc_dmabuf(struct es1370_state *s, struct dmabuf *db)
|
554 |
|
|
{
|
555 |
|
|
struct page *page, *pend;
|
556 |
|
|
|
557 |
|
|
if (db->rawbuf) {
|
558 |
|
|
/* undo marking the pages as reserved */
|
559 |
|
|
pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
|
560 |
|
|
for (page = virt_to_page(db->rawbuf); page <= pend; page++)
|
561 |
|
|
mem_map_unreserve(page);
|
562 |
|
|
pci_free_consistent(s->dev, PAGE_SIZE << db->buforder, db->rawbuf, db->dmaaddr);
|
563 |
|
|
}
|
564 |
|
|
db->rawbuf = NULL;
|
565 |
|
|
db->mapped = db->ready = 0;
|
566 |
|
|
}
|
567 |
|
|
|
568 |
|
|
static int prog_dmabuf(struct es1370_state *s, struct dmabuf *db, unsigned rate, unsigned fmt, unsigned reg)
|
569 |
|
|
{
|
570 |
|
|
int order;
|
571 |
|
|
unsigned bytepersec;
|
572 |
|
|
unsigned bufs;
|
573 |
|
|
struct page *page, *pend;
|
574 |
|
|
|
575 |
|
|
db->hwptr = db->swptr = db->total_bytes = db->count = db->error = db->endcleared = 0;
|
576 |
|
|
if (!db->rawbuf) {
|
577 |
|
|
db->ready = db->mapped = 0;
|
578 |
|
|
for (order = DMABUF_DEFAULTORDER; order >= DMABUF_MINORDER; order--)
|
579 |
|
|
if ((db->rawbuf = pci_alloc_consistent(s->dev, PAGE_SIZE << order, &db->dmaaddr)))
|
580 |
|
|
break;
|
581 |
|
|
if (!db->rawbuf)
|
582 |
|
|
return -ENOMEM;
|
583 |
|
|
db->buforder = order;
|
584 |
|
|
/* now mark the pages as reserved; otherwise remap_page_range doesn't do what we want */
|
585 |
|
|
pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
|
586 |
|
|
for (page = virt_to_page(db->rawbuf); page <= pend; page++)
|
587 |
|
|
mem_map_reserve(page);
|
588 |
|
|
}
|
589 |
|
|
fmt &= ES1370_FMT_MASK;
|
590 |
|
|
bytepersec = rate << sample_shift[fmt];
|
591 |
|
|
bufs = PAGE_SIZE << db->buforder;
|
592 |
|
|
if (db->ossfragshift) {
|
593 |
|
|
if ((1000 << db->ossfragshift) < bytepersec)
|
594 |
|
|
db->fragshift = ld2(bytepersec/1000);
|
595 |
|
|
else
|
596 |
|
|
db->fragshift = db->ossfragshift;
|
597 |
|
|
} else {
|
598 |
|
|
db->fragshift = ld2(bytepersec/100/(db->subdivision ? db->subdivision : 1));
|
599 |
|
|
if (db->fragshift < 3)
|
600 |
|
|
db->fragshift = 3;
|
601 |
|
|
}
|
602 |
|
|
db->numfrag = bufs >> db->fragshift;
|
603 |
|
|
while (db->numfrag < 4 && db->fragshift > 3) {
|
604 |
|
|
db->fragshift--;
|
605 |
|
|
db->numfrag = bufs >> db->fragshift;
|
606 |
|
|
}
|
607 |
|
|
db->fragsize = 1 << db->fragshift;
|
608 |
|
|
if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
|
609 |
|
|
db->numfrag = db->ossmaxfrags;
|
610 |
|
|
db->fragsamples = db->fragsize >> sample_shift[fmt];
|
611 |
|
|
db->dmasize = db->numfrag << db->fragshift;
|
612 |
|
|
memset(db->rawbuf, (fmt & ES1370_FMT_S16) ? 0 : 0x80, db->dmasize);
|
613 |
|
|
outl((reg >> 8) & 15, s->io+ES1370_REG_MEMPAGE);
|
614 |
|
|
outl(db->dmaaddr, s->io+(reg & 0xff));
|
615 |
|
|
outl((db->dmasize >> 2)-1, s->io+((reg + 4) & 0xff));
|
616 |
|
|
db->enabled = 1;
|
617 |
|
|
db->ready = 1;
|
618 |
|
|
return 0;
|
619 |
|
|
}
|
620 |
|
|
|
621 |
|
|
static inline int prog_dmabuf_adc(struct es1370_state *s)
|
622 |
|
|
{
|
623 |
|
|
stop_adc(s);
|
624 |
|
|
return prog_dmabuf(s, &s->dma_adc, DAC2_DIVTOSR((s->ctrl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV),
|
625 |
|
|
(s->sctrl >> SCTRL_SH_R1FMT) & ES1370_FMT_MASK, ES1370_REG_ADC_FRAMEADR);
|
626 |
|
|
}
|
627 |
|
|
|
628 |
|
|
static inline int prog_dmabuf_dac2(struct es1370_state *s)
|
629 |
|
|
{
|
630 |
|
|
stop_dac2(s);
|
631 |
|
|
return prog_dmabuf(s, &s->dma_dac2, DAC2_DIVTOSR((s->ctrl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV),
|
632 |
|
|
(s->sctrl >> SCTRL_SH_P2FMT) & ES1370_FMT_MASK, ES1370_REG_DAC2_FRAMEADR);
|
633 |
|
|
}
|
634 |
|
|
|
635 |
|
|
static inline int prog_dmabuf_dac1(struct es1370_state *s)
|
636 |
|
|
{
|
637 |
|
|
stop_dac1(s);
|
638 |
|
|
return prog_dmabuf(s, &s->dma_dac1, dac1_samplerate[(s->ctrl & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL],
|
639 |
|
|
(s->sctrl >> SCTRL_SH_P1FMT) & ES1370_FMT_MASK, ES1370_REG_DAC1_FRAMEADR);
|
640 |
|
|
}
|
641 |
|
|
|
642 |
|
|
static inline unsigned get_hwptr(struct es1370_state *s, struct dmabuf *db, unsigned reg)
|
643 |
|
|
{
|
644 |
|
|
unsigned hwptr, diff;
|
645 |
|
|
|
646 |
|
|
outl((reg >> 8) & 15, s->io+ES1370_REG_MEMPAGE);
|
647 |
|
|
hwptr = (inl(s->io+(reg & 0xff)) >> 14) & 0x3fffc;
|
648 |
|
|
diff = (db->dmasize + hwptr - db->hwptr) % db->dmasize;
|
649 |
|
|
db->hwptr = hwptr;
|
650 |
|
|
return diff;
|
651 |
|
|
}
|
652 |
|
|
|
653 |
|
|
static inline void clear_advance(void *buf, unsigned bsize, unsigned bptr, unsigned len, unsigned char c)
|
654 |
|
|
{
|
655 |
|
|
if (bptr + len > bsize) {
|
656 |
|
|
unsigned x = bsize - bptr;
|
657 |
|
|
memset(((char *)buf) + bptr, c, x);
|
658 |
|
|
bptr = 0;
|
659 |
|
|
len -= x;
|
660 |
|
|
}
|
661 |
|
|
memset(((char *)buf) + bptr, c, len);
|
662 |
|
|
}
|
663 |
|
|
|
664 |
|
|
/* call with spinlock held! */
|
665 |
|
|
static void es1370_update_ptr(struct es1370_state *s)
|
666 |
|
|
{
|
667 |
|
|
int diff;
|
668 |
|
|
|
669 |
|
|
/* update ADC pointer */
|
670 |
|
|
if (s->ctrl & CTRL_ADC_EN) {
|
671 |
|
|
diff = get_hwptr(s, &s->dma_adc, ES1370_REG_ADC_FRAMECNT);
|
672 |
|
|
s->dma_adc.total_bytes += diff;
|
673 |
|
|
s->dma_adc.count += diff;
|
674 |
|
|
if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
|
675 |
|
|
wake_up(&s->dma_adc.wait);
|
676 |
|
|
if (!s->dma_adc.mapped) {
|
677 |
|
|
if (s->dma_adc.count > (signed)(s->dma_adc.dmasize - ((3 * s->dma_adc.fragsize) >> 1))) {
|
678 |
|
|
s->ctrl &= ~CTRL_ADC_EN;
|
679 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
680 |
|
|
s->dma_adc.error++;
|
681 |
|
|
}
|
682 |
|
|
}
|
683 |
|
|
}
|
684 |
|
|
/* update DAC1 pointer */
|
685 |
|
|
if (s->ctrl & CTRL_DAC1_EN) {
|
686 |
|
|
diff = get_hwptr(s, &s->dma_dac1, ES1370_REG_DAC1_FRAMECNT);
|
687 |
|
|
s->dma_dac1.total_bytes += diff;
|
688 |
|
|
if (s->dma_dac1.mapped) {
|
689 |
|
|
s->dma_dac1.count += diff;
|
690 |
|
|
if (s->dma_dac1.count >= (signed)s->dma_dac1.fragsize)
|
691 |
|
|
wake_up(&s->dma_dac1.wait);
|
692 |
|
|
} else {
|
693 |
|
|
s->dma_dac1.count -= diff;
|
694 |
|
|
if (s->dma_dac1.count <= 0) {
|
695 |
|
|
s->ctrl &= ~CTRL_DAC1_EN;
|
696 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
697 |
|
|
s->dma_dac1.error++;
|
698 |
|
|
} else if (s->dma_dac1.count <= (signed)s->dma_dac1.fragsize && !s->dma_dac1.endcleared) {
|
699 |
|
|
clear_advance(s->dma_dac1.rawbuf, s->dma_dac1.dmasize, s->dma_dac1.swptr,
|
700 |
|
|
s->dma_dac1.fragsize, (s->sctrl & SCTRL_P1SEB) ? 0 : 0x80);
|
701 |
|
|
s->dma_dac1.endcleared = 1;
|
702 |
|
|
}
|
703 |
|
|
if (s->dma_dac1.count + (signed)s->dma_dac1.fragsize <= (signed)s->dma_dac1.dmasize)
|
704 |
|
|
wake_up(&s->dma_dac1.wait);
|
705 |
|
|
}
|
706 |
|
|
}
|
707 |
|
|
/* update DAC2 pointer */
|
708 |
|
|
if (s->ctrl & CTRL_DAC2_EN) {
|
709 |
|
|
diff = get_hwptr(s, &s->dma_dac2, ES1370_REG_DAC2_FRAMECNT);
|
710 |
|
|
s->dma_dac2.total_bytes += diff;
|
711 |
|
|
if (s->dma_dac2.mapped) {
|
712 |
|
|
s->dma_dac2.count += diff;
|
713 |
|
|
if (s->dma_dac2.count >= (signed)s->dma_dac2.fragsize)
|
714 |
|
|
wake_up(&s->dma_dac2.wait);
|
715 |
|
|
} else {
|
716 |
|
|
s->dma_dac2.count -= diff;
|
717 |
|
|
if (s->dma_dac2.count <= 0) {
|
718 |
|
|
s->ctrl &= ~CTRL_DAC2_EN;
|
719 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
720 |
|
|
s->dma_dac2.error++;
|
721 |
|
|
} else if (s->dma_dac2.count <= (signed)s->dma_dac2.fragsize && !s->dma_dac2.endcleared) {
|
722 |
|
|
clear_advance(s->dma_dac2.rawbuf, s->dma_dac2.dmasize, s->dma_dac2.swptr,
|
723 |
|
|
s->dma_dac2.fragsize, (s->sctrl & SCTRL_P2SEB) ? 0 : 0x80);
|
724 |
|
|
s->dma_dac2.endcleared = 1;
|
725 |
|
|
}
|
726 |
|
|
if (s->dma_dac2.count + (signed)s->dma_dac2.fragsize <= (signed)s->dma_dac2.dmasize)
|
727 |
|
|
wake_up(&s->dma_dac2.wait);
|
728 |
|
|
}
|
729 |
|
|
}
|
730 |
|
|
}
|
731 |
|
|
|
732 |
|
|
/* hold spinlock for the following! */
|
733 |
|
|
static void es1370_handle_midi(struct es1370_state *s)
|
734 |
|
|
{
|
735 |
|
|
unsigned char ch;
|
736 |
|
|
int wake;
|
737 |
|
|
|
738 |
|
|
if (!(s->ctrl & CTRL_UART_EN))
|
739 |
|
|
return;
|
740 |
|
|
wake = 0;
|
741 |
|
|
while (inb(s->io+ES1370_REG_UART_STATUS) & USTAT_RXRDY) {
|
742 |
|
|
ch = inb(s->io+ES1370_REG_UART_DATA);
|
743 |
|
|
if (s->midi.icnt < MIDIINBUF) {
|
744 |
|
|
s->midi.ibuf[s->midi.iwr] = ch;
|
745 |
|
|
s->midi.iwr = (s->midi.iwr + 1) % MIDIINBUF;
|
746 |
|
|
s->midi.icnt++;
|
747 |
|
|
}
|
748 |
|
|
wake = 1;
|
749 |
|
|
}
|
750 |
|
|
if (wake)
|
751 |
|
|
wake_up(&s->midi.iwait);
|
752 |
|
|
wake = 0;
|
753 |
|
|
while ((inb(s->io+ES1370_REG_UART_STATUS) & USTAT_TXRDY) && s->midi.ocnt > 0) {
|
754 |
|
|
outb(s->midi.obuf[s->midi.ord], s->io+ES1370_REG_UART_DATA);
|
755 |
|
|
s->midi.ord = (s->midi.ord + 1) % MIDIOUTBUF;
|
756 |
|
|
s->midi.ocnt--;
|
757 |
|
|
if (s->midi.ocnt < MIDIOUTBUF-16)
|
758 |
|
|
wake = 1;
|
759 |
|
|
}
|
760 |
|
|
if (wake)
|
761 |
|
|
wake_up(&s->midi.owait);
|
762 |
|
|
outb((s->midi.ocnt > 0) ? UCTRL_RXINTEN | UCTRL_ENA_TXINT : UCTRL_RXINTEN, s->io+ES1370_REG_UART_CONTROL);
|
763 |
|
|
}
|
764 |
|
|
|
765 |
|
|
static void es1370_interrupt(int irq, void *dev_id, struct pt_regs *regs)
|
766 |
|
|
{
|
767 |
|
|
struct es1370_state *s = (struct es1370_state *)dev_id;
|
768 |
|
|
unsigned int intsrc, sctl;
|
769 |
|
|
|
770 |
|
|
/* fastpath out, to ease interrupt sharing */
|
771 |
|
|
intsrc = inl(s->io+ES1370_REG_STATUS);
|
772 |
|
|
if (!(intsrc & 0x80000000))
|
773 |
|
|
return;
|
774 |
|
|
spin_lock(&s->lock);
|
775 |
|
|
/* clear audio interrupts first */
|
776 |
|
|
sctl = s->sctrl;
|
777 |
|
|
if (intsrc & STAT_ADC)
|
778 |
|
|
sctl &= ~SCTRL_R1INTEN;
|
779 |
|
|
if (intsrc & STAT_DAC1)
|
780 |
|
|
sctl &= ~SCTRL_P1INTEN;
|
781 |
|
|
if (intsrc & STAT_DAC2)
|
782 |
|
|
sctl &= ~SCTRL_P2INTEN;
|
783 |
|
|
outl(sctl, s->io+ES1370_REG_SERIAL_CONTROL);
|
784 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
785 |
|
|
es1370_update_ptr(s);
|
786 |
|
|
es1370_handle_midi(s);
|
787 |
|
|
spin_unlock(&s->lock);
|
788 |
|
|
}
|
789 |
|
|
|
790 |
|
|
/* --------------------------------------------------------------------- */
|
791 |
|
|
|
792 |
|
|
static const char invalid_magic[] = KERN_CRIT "es1370: invalid magic value\n";
|
793 |
|
|
|
794 |
|
|
#define VALIDATE_STATE(s) \
|
795 |
|
|
({ \
|
796 |
|
|
if (!(s) || (s)->magic != ES1370_MAGIC) { \
|
797 |
|
|
printk(invalid_magic); \
|
798 |
|
|
return -ENXIO; \
|
799 |
|
|
} \
|
800 |
|
|
})
|
801 |
|
|
|
802 |
|
|
/* --------------------------------------------------------------------- */
|
803 |
|
|
|
804 |
|
|
static const struct {
|
805 |
|
|
unsigned volidx:4;
|
806 |
|
|
unsigned left:4;
|
807 |
|
|
unsigned right:4;
|
808 |
|
|
unsigned stereo:1;
|
809 |
|
|
unsigned recmask:13;
|
810 |
|
|
unsigned avail:1;
|
811 |
|
|
} mixtable[SOUND_MIXER_NRDEVICES] = {
|
812 |
|
|
[SOUND_MIXER_VOLUME] = { 0, 0x0, 0x1, 1, 0x0000, 1 }, /* master */
|
813 |
|
|
[SOUND_MIXER_PCM] = { 1, 0x2, 0x3, 1, 0x0400, 1 }, /* voice */
|
814 |
|
|
[SOUND_MIXER_SYNTH] = { 2, 0x4, 0x5, 1, 0x0060, 1 }, /* FM */
|
815 |
|
|
[SOUND_MIXER_CD] = { 3, 0x6, 0x7, 1, 0x0006, 1 }, /* CD */
|
816 |
|
|
[SOUND_MIXER_LINE] = { 4, 0x8, 0x9, 1, 0x0018, 1 }, /* Line */
|
817 |
|
|
[SOUND_MIXER_LINE1] = { 5, 0xa, 0xb, 1, 0x1800, 1 }, /* AUX */
|
818 |
|
|
[SOUND_MIXER_LINE2] = { 6, 0xc, 0x0, 0, 0x0100, 1 }, /* Mono1 */
|
819 |
|
|
[SOUND_MIXER_LINE3] = { 7, 0xd, 0x0, 0, 0x0200, 1 }, /* Mono2 */
|
820 |
|
|
[SOUND_MIXER_MIC] = { 8, 0xe, 0x0, 0, 0x0001, 1 }, /* Mic */
|
821 |
|
|
[SOUND_MIXER_OGAIN] = { 9, 0xf, 0x0, 0, 0x0000, 1 } /* mono out */
|
822 |
|
|
};
|
823 |
|
|
|
824 |
|
|
static void set_recsrc(struct es1370_state *s, unsigned int val)
|
825 |
|
|
{
|
826 |
|
|
unsigned int i, j;
|
827 |
|
|
|
828 |
|
|
for (j = i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
|
829 |
|
|
if (!(val & (1 << i)))
|
830 |
|
|
continue;
|
831 |
|
|
if (!mixtable[i].recmask) {
|
832 |
|
|
val &= ~(1 << i);
|
833 |
|
|
continue;
|
834 |
|
|
}
|
835 |
|
|
j |= mixtable[i].recmask;
|
836 |
|
|
}
|
837 |
|
|
s->mix.recsrc = val;
|
838 |
|
|
wrcodec(s, 0x12, j & 0xd5);
|
839 |
|
|
wrcodec(s, 0x13, j & 0xaa);
|
840 |
|
|
wrcodec(s, 0x14, (j >> 8) & 0x17);
|
841 |
|
|
wrcodec(s, 0x15, (j >> 8) & 0x0f);
|
842 |
|
|
i = (j & 0x37f) | ((j << 1) & 0x3000) | 0xc60;
|
843 |
|
|
if (!s->mix.imix) {
|
844 |
|
|
i &= 0xff60; /* mute record and line monitor */
|
845 |
|
|
}
|
846 |
|
|
wrcodec(s, 0x10, i);
|
847 |
|
|
wrcodec(s, 0x11, i >> 8);
|
848 |
|
|
}
|
849 |
|
|
|
850 |
|
|
static int mixer_ioctl(struct es1370_state *s, unsigned int cmd, unsigned long arg)
|
851 |
|
|
{
|
852 |
|
|
unsigned long flags;
|
853 |
|
|
int i, val;
|
854 |
|
|
unsigned char l, r, rl, rr;
|
855 |
|
|
|
856 |
|
|
VALIDATE_STATE(s);
|
857 |
|
|
if (cmd == SOUND_MIXER_PRIVATE1) {
|
858 |
|
|
/* enable/disable/query mixer preamp */
|
859 |
|
|
if (get_user(val, (int *)arg))
|
860 |
|
|
return -EFAULT;
|
861 |
|
|
if (val != -1) {
|
862 |
|
|
s->mix.micpreamp = !!val;
|
863 |
|
|
wrcodec(s, 0x19, s->mix.micpreamp);
|
864 |
|
|
}
|
865 |
|
|
return put_user(s->mix.micpreamp, (int *)arg);
|
866 |
|
|
}
|
867 |
|
|
if (cmd == SOUND_MIXER_PRIVATE2) {
|
868 |
|
|
/* enable/disable/query use of linein as second lineout */
|
869 |
|
|
if (get_user(val, (int *)arg))
|
870 |
|
|
return -EFAULT;
|
871 |
|
|
if (val != -1) {
|
872 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
873 |
|
|
if (val)
|
874 |
|
|
s->ctrl |= CTRL_XCTL0;
|
875 |
|
|
else
|
876 |
|
|
s->ctrl &= ~CTRL_XCTL0;
|
877 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
878 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
879 |
|
|
}
|
880 |
|
|
return put_user((s->ctrl & CTRL_XCTL0) ? 1 : 0, (int *)arg);
|
881 |
|
|
}
|
882 |
|
|
if (cmd == SOUND_MIXER_PRIVATE3) {
|
883 |
|
|
/* enable/disable/query microphone impedance setting */
|
884 |
|
|
if (get_user(val, (int *)arg))
|
885 |
|
|
return -EFAULT;
|
886 |
|
|
if (val != -1) {
|
887 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
888 |
|
|
if (val)
|
889 |
|
|
s->ctrl |= CTRL_XCTL1;
|
890 |
|
|
else
|
891 |
|
|
s->ctrl &= ~CTRL_XCTL1;
|
892 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
893 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
894 |
|
|
}
|
895 |
|
|
return put_user((s->ctrl & CTRL_XCTL1) ? 1 : 0, (int *)arg);
|
896 |
|
|
}
|
897 |
|
|
if (cmd == SOUND_MIXER_INFO) {
|
898 |
|
|
mixer_info info;
|
899 |
|
|
strncpy(info.id, "ES1370", sizeof(info.id));
|
900 |
|
|
strncpy(info.name, "Ensoniq ES1370", sizeof(info.name));
|
901 |
|
|
info.modify_counter = s->mix.modcnt;
|
902 |
|
|
if (copy_to_user((void *)arg, &info, sizeof(info)))
|
903 |
|
|
return -EFAULT;
|
904 |
|
|
return 0;
|
905 |
|
|
}
|
906 |
|
|
if (cmd == SOUND_OLD_MIXER_INFO) {
|
907 |
|
|
_old_mixer_info info;
|
908 |
|
|
strncpy(info.id, "ES1370", sizeof(info.id));
|
909 |
|
|
strncpy(info.name, "Ensoniq ES1370", sizeof(info.name));
|
910 |
|
|
if (copy_to_user((void *)arg, &info, sizeof(info)))
|
911 |
|
|
return -EFAULT;
|
912 |
|
|
return 0;
|
913 |
|
|
}
|
914 |
|
|
if (cmd == OSS_GETVERSION)
|
915 |
|
|
return put_user(SOUND_VERSION, (int *)arg);
|
916 |
|
|
if (_IOC_TYPE(cmd) != 'M' || _SIOC_SIZE(cmd) != sizeof(int))
|
917 |
|
|
return -EINVAL;
|
918 |
|
|
if (_SIOC_DIR(cmd) == _SIOC_READ) {
|
919 |
|
|
switch (_IOC_NR(cmd)) {
|
920 |
|
|
case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
|
921 |
|
|
return put_user(s->mix.recsrc, (int *)arg);
|
922 |
|
|
|
923 |
|
|
case SOUND_MIXER_DEVMASK: /* Arg contains a bit for each supported device */
|
924 |
|
|
val = SOUND_MASK_IMIX;
|
925 |
|
|
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
|
926 |
|
|
if (mixtable[i].avail)
|
927 |
|
|
val |= 1 << i;
|
928 |
|
|
return put_user(val, (int *)arg);
|
929 |
|
|
|
930 |
|
|
case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */
|
931 |
|
|
for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
|
932 |
|
|
if (mixtable[i].recmask)
|
933 |
|
|
val |= 1 << i;
|
934 |
|
|
return put_user(val, (int *)arg);
|
935 |
|
|
|
936 |
|
|
case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */
|
937 |
|
|
for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
|
938 |
|
|
if (mixtable[i].stereo)
|
939 |
|
|
val |= 1 << i;
|
940 |
|
|
return put_user(val, (int *)arg);
|
941 |
|
|
|
942 |
|
|
case SOUND_MIXER_CAPS:
|
943 |
|
|
return put_user(0, (int *)arg);
|
944 |
|
|
|
945 |
|
|
case SOUND_MIXER_IMIX:
|
946 |
|
|
return put_user(s->mix.imix, (int *)arg);
|
947 |
|
|
|
948 |
|
|
default:
|
949 |
|
|
i = _IOC_NR(cmd);
|
950 |
|
|
if (i >= SOUND_MIXER_NRDEVICES || !mixtable[i].avail)
|
951 |
|
|
return -EINVAL;
|
952 |
|
|
return put_user(s->mix.vol[mixtable[i].volidx], (int *)arg);
|
953 |
|
|
}
|
954 |
|
|
}
|
955 |
|
|
if (_SIOC_DIR(cmd) != (_SIOC_READ|_SIOC_WRITE))
|
956 |
|
|
return -EINVAL;
|
957 |
|
|
s->mix.modcnt++;
|
958 |
|
|
switch (_IOC_NR(cmd)) {
|
959 |
|
|
|
960 |
|
|
case SOUND_MIXER_IMIX:
|
961 |
|
|
if (get_user(s->mix.imix, (int *)arg))
|
962 |
|
|
return -EFAULT;
|
963 |
|
|
set_recsrc(s, s->mix.recsrc);
|
964 |
|
|
return 0;
|
965 |
|
|
|
966 |
|
|
case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
|
967 |
|
|
if (get_user(val, (int *)arg))
|
968 |
|
|
return -EFAULT;
|
969 |
|
|
set_recsrc(s, val);
|
970 |
|
|
return 0;
|
971 |
|
|
|
972 |
|
|
default:
|
973 |
|
|
i = _IOC_NR(cmd);
|
974 |
|
|
if (i >= SOUND_MIXER_NRDEVICES || !mixtable[i].avail)
|
975 |
|
|
return -EINVAL;
|
976 |
|
|
if (get_user(val, (int *)arg))
|
977 |
|
|
return -EFAULT;
|
978 |
|
|
l = val & 0xff;
|
979 |
|
|
if (l > 100)
|
980 |
|
|
l = 100;
|
981 |
|
|
if (mixtable[i].stereo) {
|
982 |
|
|
r = (val >> 8) & 0xff;
|
983 |
|
|
if (r > 100)
|
984 |
|
|
r = 100;
|
985 |
|
|
if (l < 7) {
|
986 |
|
|
rl = 0x80;
|
987 |
|
|
l = 0;
|
988 |
|
|
} else {
|
989 |
|
|
rl = 31 - ((l - 7) / 3);
|
990 |
|
|
l = (31 - rl) * 3 + 7;
|
991 |
|
|
}
|
992 |
|
|
if (r < 7) {
|
993 |
|
|
rr = 0x80;
|
994 |
|
|
r = 0;
|
995 |
|
|
} else {
|
996 |
|
|
rr = 31 - ((r - 7) / 3);
|
997 |
|
|
r = (31 - rr) * 3 + 7;
|
998 |
|
|
}
|
999 |
|
|
wrcodec(s, mixtable[i].right, rr);
|
1000 |
|
|
} else {
|
1001 |
|
|
if (mixtable[i].left == 15) {
|
1002 |
|
|
if (l < 2) {
|
1003 |
|
|
rr = rl = 0x80;
|
1004 |
|
|
r = l = 0;
|
1005 |
|
|
} else {
|
1006 |
|
|
rl = 7 - ((l - 2) / 14);
|
1007 |
|
|
r = l = (7 - rl) * 14 + 2;
|
1008 |
|
|
}
|
1009 |
|
|
} else {
|
1010 |
|
|
if (l < 7) {
|
1011 |
|
|
rl = 0x80;
|
1012 |
|
|
r = l = 0;
|
1013 |
|
|
} else {
|
1014 |
|
|
rl = 31 - ((l - 7) / 3);
|
1015 |
|
|
r = l = (31 - rl) * 3 + 7;
|
1016 |
|
|
}
|
1017 |
|
|
}
|
1018 |
|
|
}
|
1019 |
|
|
wrcodec(s, mixtable[i].left, rl);
|
1020 |
|
|
#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
|
1021 |
|
|
s->mix.vol[mixtable[i].volidx] = ((unsigned int)r << 8) | l;
|
1022 |
|
|
#else
|
1023 |
|
|
s->mix.vol[mixtable[i].volidx] = val;
|
1024 |
|
|
#endif
|
1025 |
|
|
return put_user(s->mix.vol[mixtable[i].volidx], (int *)arg);
|
1026 |
|
|
}
|
1027 |
|
|
}
|
1028 |
|
|
|
1029 |
|
|
/* --------------------------------------------------------------------- */
|
1030 |
|
|
|
1031 |
|
|
static int es1370_open_mixdev(struct inode *inode, struct file *file)
|
1032 |
|
|
{
|
1033 |
|
|
int minor = MINOR(inode->i_rdev);
|
1034 |
|
|
struct list_head *list;
|
1035 |
|
|
struct es1370_state *s;
|
1036 |
|
|
|
1037 |
|
|
for (list = devs.next; ; list = list->next) {
|
1038 |
|
|
if (list == &devs)
|
1039 |
|
|
return -ENODEV;
|
1040 |
|
|
s = list_entry(list, struct es1370_state, devs);
|
1041 |
|
|
if (s->dev_mixer == minor)
|
1042 |
|
|
break;
|
1043 |
|
|
}
|
1044 |
|
|
VALIDATE_STATE(s);
|
1045 |
|
|
file->private_data = s;
|
1046 |
|
|
return 0;
|
1047 |
|
|
}
|
1048 |
|
|
|
1049 |
|
|
static int es1370_release_mixdev(struct inode *inode, struct file *file)
|
1050 |
|
|
{
|
1051 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
1052 |
|
|
|
1053 |
|
|
VALIDATE_STATE(s);
|
1054 |
|
|
return 0;
|
1055 |
|
|
}
|
1056 |
|
|
|
1057 |
|
|
static int es1370_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
|
1058 |
|
|
{
|
1059 |
|
|
return mixer_ioctl((struct es1370_state *)file->private_data, cmd, arg);
|
1060 |
|
|
}
|
1061 |
|
|
|
1062 |
|
|
static /*const*/ struct file_operations es1370_mixer_fops = {
|
1063 |
|
|
owner: THIS_MODULE,
|
1064 |
|
|
llseek: no_llseek,
|
1065 |
|
|
ioctl: es1370_ioctl_mixdev,
|
1066 |
|
|
open: es1370_open_mixdev,
|
1067 |
|
|
release: es1370_release_mixdev,
|
1068 |
|
|
};
|
1069 |
|
|
|
1070 |
|
|
/* --------------------------------------------------------------------- */
|
1071 |
|
|
|
1072 |
|
|
static int drain_dac1(struct es1370_state *s, int nonblock)
|
1073 |
|
|
{
|
1074 |
|
|
DECLARE_WAITQUEUE(wait, current);
|
1075 |
|
|
unsigned long flags;
|
1076 |
|
|
int count, tmo;
|
1077 |
|
|
|
1078 |
|
|
if (s->dma_dac1.mapped || !s->dma_dac1.ready)
|
1079 |
|
|
return 0;
|
1080 |
|
|
add_wait_queue(&s->dma_dac1.wait, &wait);
|
1081 |
|
|
for (;;) {
|
1082 |
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
1083 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1084 |
|
|
count = s->dma_dac1.count;
|
1085 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1086 |
|
|
if (count <= 0)
|
1087 |
|
|
break;
|
1088 |
|
|
if (signal_pending(current))
|
1089 |
|
|
break;
|
1090 |
|
|
if (nonblock) {
|
1091 |
|
|
remove_wait_queue(&s->dma_dac1.wait, &wait);
|
1092 |
|
|
set_current_state(TASK_RUNNING);
|
1093 |
|
|
return -EBUSY;
|
1094 |
|
|
}
|
1095 |
|
|
tmo = 3 * HZ * (count + s->dma_dac1.fragsize) / 2
|
1096 |
|
|
/ dac1_samplerate[(s->ctrl & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL];
|
1097 |
|
|
tmo >>= sample_shift[(s->sctrl & SCTRL_P1FMT) >> SCTRL_SH_P1FMT];
|
1098 |
|
|
if (!schedule_timeout(tmo + 1))
|
1099 |
|
|
DBG(printk(KERN_DEBUG "es1370: dma timed out??\n");)
|
1100 |
|
|
}
|
1101 |
|
|
remove_wait_queue(&s->dma_dac1.wait, &wait);
|
1102 |
|
|
set_current_state(TASK_RUNNING);
|
1103 |
|
|
if (signal_pending(current))
|
1104 |
|
|
return -ERESTARTSYS;
|
1105 |
|
|
return 0;
|
1106 |
|
|
}
|
1107 |
|
|
|
1108 |
|
|
static int drain_dac2(struct es1370_state *s, int nonblock)
|
1109 |
|
|
{
|
1110 |
|
|
DECLARE_WAITQUEUE(wait, current);
|
1111 |
|
|
unsigned long flags;
|
1112 |
|
|
int count, tmo;
|
1113 |
|
|
|
1114 |
|
|
if (s->dma_dac2.mapped || !s->dma_dac2.ready)
|
1115 |
|
|
return 0;
|
1116 |
|
|
add_wait_queue(&s->dma_dac2.wait, &wait);
|
1117 |
|
|
for (;;) {
|
1118 |
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
1119 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1120 |
|
|
count = s->dma_dac2.count;
|
1121 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1122 |
|
|
if (count <= 0)
|
1123 |
|
|
break;
|
1124 |
|
|
if (signal_pending(current))
|
1125 |
|
|
break;
|
1126 |
|
|
if (nonblock) {
|
1127 |
|
|
remove_wait_queue(&s->dma_dac2.wait, &wait);
|
1128 |
|
|
set_current_state(TASK_RUNNING);
|
1129 |
|
|
return -EBUSY;
|
1130 |
|
|
}
|
1131 |
|
|
tmo = 3 * HZ * (count + s->dma_dac2.fragsize) / 2
|
1132 |
|
|
/ DAC2_DIVTOSR((s->ctrl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV);
|
1133 |
|
|
tmo >>= sample_shift[(s->sctrl & SCTRL_P2FMT) >> SCTRL_SH_P2FMT];
|
1134 |
|
|
if (!schedule_timeout(tmo + 1))
|
1135 |
|
|
DBG(printk(KERN_DEBUG "es1370: dma timed out??\n");)
|
1136 |
|
|
}
|
1137 |
|
|
remove_wait_queue(&s->dma_dac2.wait, &wait);
|
1138 |
|
|
set_current_state(TASK_RUNNING);
|
1139 |
|
|
if (signal_pending(current))
|
1140 |
|
|
return -ERESTARTSYS;
|
1141 |
|
|
return 0;
|
1142 |
|
|
}
|
1143 |
|
|
|
1144 |
|
|
/* --------------------------------------------------------------------- */
|
1145 |
|
|
|
1146 |
|
|
static ssize_t es1370_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
|
1147 |
|
|
{
|
1148 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
1149 |
|
|
DECLARE_WAITQUEUE(wait, current);
|
1150 |
|
|
ssize_t ret = 0;
|
1151 |
|
|
unsigned long flags;
|
1152 |
|
|
unsigned swptr;
|
1153 |
|
|
int cnt;
|
1154 |
|
|
|
1155 |
|
|
VALIDATE_STATE(s);
|
1156 |
|
|
if (ppos != &file->f_pos)
|
1157 |
|
|
return -ESPIPE;
|
1158 |
|
|
if (s->dma_adc.mapped)
|
1159 |
|
|
return -ENXIO;
|
1160 |
|
|
if (!access_ok(VERIFY_WRITE, buffer, count))
|
1161 |
|
|
return -EFAULT;
|
1162 |
|
|
down(&s->sem);
|
1163 |
|
|
if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s)))
|
1164 |
|
|
goto out;
|
1165 |
|
|
|
1166 |
|
|
add_wait_queue(&s->dma_adc.wait, &wait);
|
1167 |
|
|
while (count > 0) {
|
1168 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1169 |
|
|
swptr = s->dma_adc.swptr;
|
1170 |
|
|
cnt = s->dma_adc.dmasize-swptr;
|
1171 |
|
|
if (s->dma_adc.count < cnt)
|
1172 |
|
|
cnt = s->dma_adc.count;
|
1173 |
|
|
if (cnt <= 0)
|
1174 |
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
1175 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1176 |
|
|
if (cnt > count)
|
1177 |
|
|
cnt = count;
|
1178 |
|
|
if (cnt <= 0) {
|
1179 |
|
|
if (s->dma_adc.enabled)
|
1180 |
|
|
start_adc(s);
|
1181 |
|
|
if (file->f_flags & O_NONBLOCK) {
|
1182 |
|
|
if (!ret)
|
1183 |
|
|
ret = -EAGAIN;
|
1184 |
|
|
goto out;
|
1185 |
|
|
}
|
1186 |
|
|
up(&s->sem);
|
1187 |
|
|
schedule();
|
1188 |
|
|
if (signal_pending(current)) {
|
1189 |
|
|
if (!ret)
|
1190 |
|
|
ret = -ERESTARTSYS;
|
1191 |
|
|
goto out;
|
1192 |
|
|
}
|
1193 |
|
|
down(&s->sem);
|
1194 |
|
|
if (s->dma_adc.mapped)
|
1195 |
|
|
{
|
1196 |
|
|
ret = -ENXIO;
|
1197 |
|
|
goto out;
|
1198 |
|
|
}
|
1199 |
|
|
continue;
|
1200 |
|
|
}
|
1201 |
|
|
if (copy_to_user(buffer, s->dma_adc.rawbuf + swptr, cnt)) {
|
1202 |
|
|
if (!ret)
|
1203 |
|
|
ret = -EFAULT;
|
1204 |
|
|
goto out;
|
1205 |
|
|
}
|
1206 |
|
|
swptr = (swptr + cnt) % s->dma_adc.dmasize;
|
1207 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1208 |
|
|
s->dma_adc.swptr = swptr;
|
1209 |
|
|
s->dma_adc.count -= cnt;
|
1210 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1211 |
|
|
count -= cnt;
|
1212 |
|
|
buffer += cnt;
|
1213 |
|
|
ret += cnt;
|
1214 |
|
|
if (s->dma_adc.enabled)
|
1215 |
|
|
start_adc(s);
|
1216 |
|
|
}
|
1217 |
|
|
out:
|
1218 |
|
|
up(&s->sem);
|
1219 |
|
|
remove_wait_queue(&s->dma_adc.wait, &wait);
|
1220 |
|
|
set_current_state(TASK_RUNNING);
|
1221 |
|
|
return ret;
|
1222 |
|
|
}
|
1223 |
|
|
|
1224 |
|
|
static ssize_t es1370_write(struct file *file, const char *buffer, size_t count, loff_t *ppos)
|
1225 |
|
|
{
|
1226 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
1227 |
|
|
DECLARE_WAITQUEUE(wait, current);
|
1228 |
|
|
ssize_t ret = 0;
|
1229 |
|
|
unsigned long flags;
|
1230 |
|
|
unsigned swptr;
|
1231 |
|
|
int cnt;
|
1232 |
|
|
|
1233 |
|
|
VALIDATE_STATE(s);
|
1234 |
|
|
if (ppos != &file->f_pos)
|
1235 |
|
|
return -ESPIPE;
|
1236 |
|
|
if (s->dma_dac2.mapped)
|
1237 |
|
|
return -ENXIO;
|
1238 |
|
|
if (!access_ok(VERIFY_READ, buffer, count))
|
1239 |
|
|
return -EFAULT;
|
1240 |
|
|
down(&s->sem);
|
1241 |
|
|
if (!s->dma_dac2.ready && (ret = prog_dmabuf_dac2(s)))
|
1242 |
|
|
goto out;
|
1243 |
|
|
ret = 0;
|
1244 |
|
|
add_wait_queue(&s->dma_dac2.wait, &wait);
|
1245 |
|
|
while (count > 0) {
|
1246 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1247 |
|
|
if (s->dma_dac2.count < 0) {
|
1248 |
|
|
s->dma_dac2.count = 0;
|
1249 |
|
|
s->dma_dac2.swptr = s->dma_dac2.hwptr;
|
1250 |
|
|
}
|
1251 |
|
|
swptr = s->dma_dac2.swptr;
|
1252 |
|
|
cnt = s->dma_dac2.dmasize-swptr;
|
1253 |
|
|
if (s->dma_dac2.count + cnt > s->dma_dac2.dmasize)
|
1254 |
|
|
cnt = s->dma_dac2.dmasize - s->dma_dac2.count;
|
1255 |
|
|
if (cnt <= 0)
|
1256 |
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
1257 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1258 |
|
|
if (cnt > count)
|
1259 |
|
|
cnt = count;
|
1260 |
|
|
if (cnt <= 0) {
|
1261 |
|
|
if (s->dma_dac2.enabled)
|
1262 |
|
|
start_dac2(s);
|
1263 |
|
|
if (file->f_flags & O_NONBLOCK) {
|
1264 |
|
|
if (!ret)
|
1265 |
|
|
ret = -EAGAIN;
|
1266 |
|
|
goto out;
|
1267 |
|
|
}
|
1268 |
|
|
up(&s->sem);
|
1269 |
|
|
schedule();
|
1270 |
|
|
if (signal_pending(current)) {
|
1271 |
|
|
if (!ret)
|
1272 |
|
|
ret = -ERESTARTSYS;
|
1273 |
|
|
goto out;
|
1274 |
|
|
}
|
1275 |
|
|
down(&s->sem);
|
1276 |
|
|
if (s->dma_dac2.mapped)
|
1277 |
|
|
{
|
1278 |
|
|
ret = -ENXIO;
|
1279 |
|
|
goto out;
|
1280 |
|
|
}
|
1281 |
|
|
continue;
|
1282 |
|
|
}
|
1283 |
|
|
if (copy_from_user(s->dma_dac2.rawbuf + swptr, buffer, cnt)) {
|
1284 |
|
|
if (!ret)
|
1285 |
|
|
ret = -EFAULT;
|
1286 |
|
|
goto out;
|
1287 |
|
|
}
|
1288 |
|
|
swptr = (swptr + cnt) % s->dma_dac2.dmasize;
|
1289 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1290 |
|
|
s->dma_dac2.swptr = swptr;
|
1291 |
|
|
s->dma_dac2.count += cnt;
|
1292 |
|
|
s->dma_dac2.endcleared = 0;
|
1293 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1294 |
|
|
count -= cnt;
|
1295 |
|
|
buffer += cnt;
|
1296 |
|
|
ret += cnt;
|
1297 |
|
|
if (s->dma_dac2.enabled)
|
1298 |
|
|
start_dac2(s);
|
1299 |
|
|
}
|
1300 |
|
|
out:
|
1301 |
|
|
up(&s->sem);
|
1302 |
|
|
remove_wait_queue(&s->dma_dac2.wait, &wait);
|
1303 |
|
|
set_current_state(TASK_RUNNING);
|
1304 |
|
|
return ret;
|
1305 |
|
|
}
|
1306 |
|
|
|
1307 |
|
|
/* No kernel lock - we have our own spinlock */
|
1308 |
|
|
static unsigned int es1370_poll(struct file *file, struct poll_table_struct *wait)
|
1309 |
|
|
{
|
1310 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
1311 |
|
|
unsigned long flags;
|
1312 |
|
|
unsigned int mask = 0;
|
1313 |
|
|
|
1314 |
|
|
VALIDATE_STATE(s);
|
1315 |
|
|
if (file->f_mode & FMODE_WRITE) {
|
1316 |
|
|
if (!s->dma_dac2.ready && prog_dmabuf_dac2(s))
|
1317 |
|
|
return 0;
|
1318 |
|
|
poll_wait(file, &s->dma_dac2.wait, wait);
|
1319 |
|
|
}
|
1320 |
|
|
if (file->f_mode & FMODE_READ) {
|
1321 |
|
|
if (!s->dma_adc.ready && prog_dmabuf_adc(s))
|
1322 |
|
|
return 0;
|
1323 |
|
|
poll_wait(file, &s->dma_adc.wait, wait);
|
1324 |
|
|
}
|
1325 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1326 |
|
|
es1370_update_ptr(s);
|
1327 |
|
|
if (file->f_mode & FMODE_READ) {
|
1328 |
|
|
if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
|
1329 |
|
|
mask |= POLLIN | POLLRDNORM;
|
1330 |
|
|
}
|
1331 |
|
|
if (file->f_mode & FMODE_WRITE) {
|
1332 |
|
|
if (s->dma_dac2.mapped) {
|
1333 |
|
|
if (s->dma_dac2.count >= (signed)s->dma_dac2.fragsize)
|
1334 |
|
|
mask |= POLLOUT | POLLWRNORM;
|
1335 |
|
|
} else {
|
1336 |
|
|
if ((signed)s->dma_dac2.dmasize >= s->dma_dac2.count + (signed)s->dma_dac2.fragsize)
|
1337 |
|
|
mask |= POLLOUT | POLLWRNORM;
|
1338 |
|
|
}
|
1339 |
|
|
}
|
1340 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1341 |
|
|
return mask;
|
1342 |
|
|
}
|
1343 |
|
|
|
1344 |
|
|
static int es1370_mmap(struct file *file, struct vm_area_struct *vma)
|
1345 |
|
|
{
|
1346 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
1347 |
|
|
struct dmabuf *db;
|
1348 |
|
|
int ret = 0;
|
1349 |
|
|
unsigned long size;
|
1350 |
|
|
|
1351 |
|
|
VALIDATE_STATE(s);
|
1352 |
|
|
lock_kernel();
|
1353 |
|
|
down(&s->sem);
|
1354 |
|
|
if (vma->vm_flags & VM_WRITE) {
|
1355 |
|
|
if ((ret = prog_dmabuf_dac2(s)) != 0) {
|
1356 |
|
|
goto out;
|
1357 |
|
|
}
|
1358 |
|
|
db = &s->dma_dac2;
|
1359 |
|
|
} else if (vma->vm_flags & VM_READ) {
|
1360 |
|
|
if ((ret = prog_dmabuf_adc(s)) != 0) {
|
1361 |
|
|
goto out;
|
1362 |
|
|
}
|
1363 |
|
|
db = &s->dma_adc;
|
1364 |
|
|
} else {
|
1365 |
|
|
ret = -EINVAL;
|
1366 |
|
|
goto out;
|
1367 |
|
|
}
|
1368 |
|
|
if (vma->vm_pgoff != 0) {
|
1369 |
|
|
ret = -EINVAL;
|
1370 |
|
|
goto out;
|
1371 |
|
|
}
|
1372 |
|
|
size = vma->vm_end - vma->vm_start;
|
1373 |
|
|
if (size > (PAGE_SIZE << db->buforder)) {
|
1374 |
|
|
ret = -EINVAL;
|
1375 |
|
|
goto out;
|
1376 |
|
|
}
|
1377 |
|
|
if (remap_page_range(vma->vm_start, virt_to_phys(db->rawbuf), size, vma->vm_page_prot)) {
|
1378 |
|
|
ret = -EAGAIN;
|
1379 |
|
|
goto out;
|
1380 |
|
|
}
|
1381 |
|
|
db->mapped = 1;
|
1382 |
|
|
out:
|
1383 |
|
|
up(&s->sem);
|
1384 |
|
|
unlock_kernel();
|
1385 |
|
|
return ret;
|
1386 |
|
|
}
|
1387 |
|
|
|
1388 |
|
|
static int es1370_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
|
1389 |
|
|
{
|
1390 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
1391 |
|
|
unsigned long flags;
|
1392 |
|
|
audio_buf_info abinfo;
|
1393 |
|
|
count_info cinfo;
|
1394 |
|
|
int count;
|
1395 |
|
|
int val, mapped, ret;
|
1396 |
|
|
|
1397 |
|
|
VALIDATE_STATE(s);
|
1398 |
|
|
mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac2.mapped) ||
|
1399 |
|
|
((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
|
1400 |
|
|
switch (cmd) {
|
1401 |
|
|
case OSS_GETVERSION:
|
1402 |
|
|
return put_user(SOUND_VERSION, (int *)arg);
|
1403 |
|
|
|
1404 |
|
|
case SNDCTL_DSP_SYNC:
|
1405 |
|
|
if (file->f_mode & FMODE_WRITE)
|
1406 |
|
|
return drain_dac2(s, 0/*file->f_flags & O_NONBLOCK*/);
|
1407 |
|
|
return 0;
|
1408 |
|
|
|
1409 |
|
|
case SNDCTL_DSP_SETDUPLEX:
|
1410 |
|
|
return 0;
|
1411 |
|
|
|
1412 |
|
|
case SNDCTL_DSP_GETCAPS:
|
1413 |
|
|
return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP, (int *)arg);
|
1414 |
|
|
|
1415 |
|
|
case SNDCTL_DSP_RESET:
|
1416 |
|
|
if (file->f_mode & FMODE_WRITE) {
|
1417 |
|
|
stop_dac2(s);
|
1418 |
|
|
synchronize_irq();
|
1419 |
|
|
s->dma_dac2.swptr = s->dma_dac2.hwptr = s->dma_dac2.count = s->dma_dac2.total_bytes = 0;
|
1420 |
|
|
}
|
1421 |
|
|
if (file->f_mode & FMODE_READ) {
|
1422 |
|
|
stop_adc(s);
|
1423 |
|
|
synchronize_irq();
|
1424 |
|
|
s->dma_adc.swptr = s->dma_adc.hwptr = s->dma_adc.count = s->dma_adc.total_bytes = 0;
|
1425 |
|
|
}
|
1426 |
|
|
return 0;
|
1427 |
|
|
|
1428 |
|
|
case SNDCTL_DSP_SPEED:
|
1429 |
|
|
if (get_user(val, (int *)arg))
|
1430 |
|
|
return -EFAULT;
|
1431 |
|
|
if (val >= 0) {
|
1432 |
|
|
if (s->open_mode & (~file->f_mode) & (FMODE_READ|FMODE_WRITE))
|
1433 |
|
|
return -EINVAL;
|
1434 |
|
|
if (val < 4000)
|
1435 |
|
|
val = 4000;
|
1436 |
|
|
if (val > 50000)
|
1437 |
|
|
val = 50000;
|
1438 |
|
|
stop_adc(s);
|
1439 |
|
|
stop_dac2(s);
|
1440 |
|
|
s->dma_adc.ready = s->dma_dac2.ready = 0;
|
1441 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1442 |
|
|
s->ctrl = (s->ctrl & ~CTRL_PCLKDIV) | (DAC2_SRTODIV(val) << CTRL_SH_PCLKDIV);
|
1443 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
1444 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1445 |
|
|
}
|
1446 |
|
|
return put_user(DAC2_DIVTOSR((s->ctrl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV), (int *)arg);
|
1447 |
|
|
|
1448 |
|
|
case SNDCTL_DSP_STEREO:
|
1449 |
|
|
if (get_user(val, (int *)arg))
|
1450 |
|
|
return -EFAULT;
|
1451 |
|
|
if (file->f_mode & FMODE_READ) {
|
1452 |
|
|
stop_adc(s);
|
1453 |
|
|
s->dma_adc.ready = 0;
|
1454 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1455 |
|
|
if (val)
|
1456 |
|
|
s->sctrl |= SCTRL_R1SMB;
|
1457 |
|
|
else
|
1458 |
|
|
s->sctrl &= ~SCTRL_R1SMB;
|
1459 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
1460 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1461 |
|
|
}
|
1462 |
|
|
if (file->f_mode & FMODE_WRITE) {
|
1463 |
|
|
stop_dac2(s);
|
1464 |
|
|
s->dma_dac2.ready = 0;
|
1465 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1466 |
|
|
if (val)
|
1467 |
|
|
s->sctrl |= SCTRL_P2SMB;
|
1468 |
|
|
else
|
1469 |
|
|
s->sctrl &= ~SCTRL_P2SMB;
|
1470 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
1471 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1472 |
|
|
}
|
1473 |
|
|
return 0;
|
1474 |
|
|
|
1475 |
|
|
case SNDCTL_DSP_CHANNELS:
|
1476 |
|
|
if (get_user(val, (int *)arg))
|
1477 |
|
|
return -EFAULT;
|
1478 |
|
|
if (val != 0) {
|
1479 |
|
|
if (file->f_mode & FMODE_READ) {
|
1480 |
|
|
stop_adc(s);
|
1481 |
|
|
s->dma_adc.ready = 0;
|
1482 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1483 |
|
|
if (val >= 2)
|
1484 |
|
|
s->sctrl |= SCTRL_R1SMB;
|
1485 |
|
|
else
|
1486 |
|
|
s->sctrl &= ~SCTRL_R1SMB;
|
1487 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
1488 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1489 |
|
|
}
|
1490 |
|
|
if (file->f_mode & FMODE_WRITE) {
|
1491 |
|
|
stop_dac2(s);
|
1492 |
|
|
s->dma_dac2.ready = 0;
|
1493 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1494 |
|
|
if (val >= 2)
|
1495 |
|
|
s->sctrl |= SCTRL_P2SMB;
|
1496 |
|
|
else
|
1497 |
|
|
s->sctrl &= ~SCTRL_P2SMB;
|
1498 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
1499 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1500 |
|
|
}
|
1501 |
|
|
}
|
1502 |
|
|
return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SMB : SCTRL_P2SMB)) ? 2 : 1, (int *)arg);
|
1503 |
|
|
|
1504 |
|
|
case SNDCTL_DSP_GETFMTS: /* Returns a mask */
|
1505 |
|
|
return put_user(AFMT_S16_LE|AFMT_U8, (int *)arg);
|
1506 |
|
|
|
1507 |
|
|
case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
|
1508 |
|
|
if (get_user(val, (int *)arg))
|
1509 |
|
|
return -EFAULT;
|
1510 |
|
|
if (val != AFMT_QUERY) {
|
1511 |
|
|
if (file->f_mode & FMODE_READ) {
|
1512 |
|
|
stop_adc(s);
|
1513 |
|
|
s->dma_adc.ready = 0;
|
1514 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1515 |
|
|
if (val == AFMT_S16_LE)
|
1516 |
|
|
s->sctrl |= SCTRL_R1SEB;
|
1517 |
|
|
else
|
1518 |
|
|
s->sctrl &= ~SCTRL_R1SEB;
|
1519 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
1520 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1521 |
|
|
}
|
1522 |
|
|
if (file->f_mode & FMODE_WRITE) {
|
1523 |
|
|
stop_dac2(s);
|
1524 |
|
|
s->dma_dac2.ready = 0;
|
1525 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1526 |
|
|
if (val == AFMT_S16_LE)
|
1527 |
|
|
s->sctrl |= SCTRL_P2SEB;
|
1528 |
|
|
else
|
1529 |
|
|
s->sctrl &= ~SCTRL_P2SEB;
|
1530 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
1531 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1532 |
|
|
}
|
1533 |
|
|
}
|
1534 |
|
|
return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SEB : SCTRL_P2SEB)) ?
|
1535 |
|
|
AFMT_S16_LE : AFMT_U8, (int *)arg);
|
1536 |
|
|
|
1537 |
|
|
case SNDCTL_DSP_POST:
|
1538 |
|
|
return 0;
|
1539 |
|
|
|
1540 |
|
|
case SNDCTL_DSP_GETTRIGGER:
|
1541 |
|
|
val = 0;
|
1542 |
|
|
if (file->f_mode & FMODE_READ && s->ctrl & CTRL_ADC_EN)
|
1543 |
|
|
val |= PCM_ENABLE_INPUT;
|
1544 |
|
|
if (file->f_mode & FMODE_WRITE && s->ctrl & CTRL_DAC2_EN)
|
1545 |
|
|
val |= PCM_ENABLE_OUTPUT;
|
1546 |
|
|
return put_user(val, (int *)arg);
|
1547 |
|
|
|
1548 |
|
|
case SNDCTL_DSP_SETTRIGGER:
|
1549 |
|
|
if (get_user(val, (int *)arg))
|
1550 |
|
|
return -EFAULT;
|
1551 |
|
|
if (file->f_mode & FMODE_READ) {
|
1552 |
|
|
if (val & PCM_ENABLE_INPUT) {
|
1553 |
|
|
if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s)))
|
1554 |
|
|
return ret;
|
1555 |
|
|
s->dma_adc.enabled = 1;
|
1556 |
|
|
start_adc(s);
|
1557 |
|
|
} else {
|
1558 |
|
|
s->dma_adc.enabled = 0;
|
1559 |
|
|
stop_adc(s);
|
1560 |
|
|
}
|
1561 |
|
|
}
|
1562 |
|
|
if (file->f_mode & FMODE_WRITE) {
|
1563 |
|
|
if (val & PCM_ENABLE_OUTPUT) {
|
1564 |
|
|
if (!s->dma_dac2.ready && (ret = prog_dmabuf_dac2(s)))
|
1565 |
|
|
return ret;
|
1566 |
|
|
s->dma_dac2.enabled = 1;
|
1567 |
|
|
start_dac2(s);
|
1568 |
|
|
} else {
|
1569 |
|
|
s->dma_dac2.enabled = 0;
|
1570 |
|
|
stop_dac2(s);
|
1571 |
|
|
}
|
1572 |
|
|
}
|
1573 |
|
|
return 0;
|
1574 |
|
|
|
1575 |
|
|
case SNDCTL_DSP_GETOSPACE:
|
1576 |
|
|
if (!(file->f_mode & FMODE_WRITE))
|
1577 |
|
|
return -EINVAL;
|
1578 |
|
|
if (!s->dma_dac2.ready && (val = prog_dmabuf_dac2(s)) != 0)
|
1579 |
|
|
return val;
|
1580 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1581 |
|
|
es1370_update_ptr(s);
|
1582 |
|
|
abinfo.fragsize = s->dma_dac2.fragsize;
|
1583 |
|
|
count = s->dma_dac2.count;
|
1584 |
|
|
if (count < 0)
|
1585 |
|
|
count = 0;
|
1586 |
|
|
abinfo.bytes = s->dma_dac2.dmasize - count;
|
1587 |
|
|
abinfo.fragstotal = s->dma_dac2.numfrag;
|
1588 |
|
|
abinfo.fragments = abinfo.bytes >> s->dma_dac2.fragshift;
|
1589 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1590 |
|
|
return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
|
1591 |
|
|
|
1592 |
|
|
case SNDCTL_DSP_GETISPACE:
|
1593 |
|
|
if (!(file->f_mode & FMODE_READ))
|
1594 |
|
|
return -EINVAL;
|
1595 |
|
|
if (!s->dma_adc.ready && (val = prog_dmabuf_adc(s)) != 0)
|
1596 |
|
|
return val;
|
1597 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1598 |
|
|
es1370_update_ptr(s);
|
1599 |
|
|
abinfo.fragsize = s->dma_adc.fragsize;
|
1600 |
|
|
count = s->dma_adc.count;
|
1601 |
|
|
if (count < 0)
|
1602 |
|
|
count = 0;
|
1603 |
|
|
abinfo.bytes = count;
|
1604 |
|
|
abinfo.fragstotal = s->dma_adc.numfrag;
|
1605 |
|
|
abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;
|
1606 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1607 |
|
|
return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
|
1608 |
|
|
|
1609 |
|
|
case SNDCTL_DSP_NONBLOCK:
|
1610 |
|
|
file->f_flags |= O_NONBLOCK;
|
1611 |
|
|
return 0;
|
1612 |
|
|
|
1613 |
|
|
case SNDCTL_DSP_GETODELAY:
|
1614 |
|
|
if (!(file->f_mode & FMODE_WRITE))
|
1615 |
|
|
return -EINVAL;
|
1616 |
|
|
if (!s->dma_dac2.ready && (val = prog_dmabuf_dac2(s)) != 0)
|
1617 |
|
|
return val;
|
1618 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1619 |
|
|
es1370_update_ptr(s);
|
1620 |
|
|
count = s->dma_dac2.count;
|
1621 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1622 |
|
|
if (count < 0)
|
1623 |
|
|
count = 0;
|
1624 |
|
|
return put_user(count, (int *)arg);
|
1625 |
|
|
|
1626 |
|
|
case SNDCTL_DSP_GETIPTR:
|
1627 |
|
|
if (!(file->f_mode & FMODE_READ))
|
1628 |
|
|
return -EINVAL;
|
1629 |
|
|
if (!s->dma_adc.ready && (val = prog_dmabuf_adc(s)) != 0)
|
1630 |
|
|
return val;
|
1631 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1632 |
|
|
es1370_update_ptr(s);
|
1633 |
|
|
cinfo.bytes = s->dma_adc.total_bytes;
|
1634 |
|
|
count = s->dma_adc.count;
|
1635 |
|
|
if (count < 0)
|
1636 |
|
|
count = 0;
|
1637 |
|
|
cinfo.blocks = count >> s->dma_adc.fragshift;
|
1638 |
|
|
cinfo.ptr = s->dma_adc.hwptr;
|
1639 |
|
|
if (s->dma_adc.mapped)
|
1640 |
|
|
s->dma_adc.count &= s->dma_adc.fragsize-1;
|
1641 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1642 |
|
|
return copy_to_user((void *)arg, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
|
1643 |
|
|
|
1644 |
|
|
case SNDCTL_DSP_GETOPTR:
|
1645 |
|
|
if (!(file->f_mode & FMODE_WRITE))
|
1646 |
|
|
return -EINVAL;
|
1647 |
|
|
if (!s->dma_dac2.ready && (val = prog_dmabuf_dac2(s)) != 0)
|
1648 |
|
|
return val;
|
1649 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1650 |
|
|
es1370_update_ptr(s);
|
1651 |
|
|
cinfo.bytes = s->dma_dac2.total_bytes;
|
1652 |
|
|
count = s->dma_dac2.count;
|
1653 |
|
|
if (count < 0)
|
1654 |
|
|
count = 0;
|
1655 |
|
|
cinfo.blocks = count >> s->dma_dac2.fragshift;
|
1656 |
|
|
cinfo.ptr = s->dma_dac2.hwptr;
|
1657 |
|
|
if (s->dma_dac2.mapped)
|
1658 |
|
|
s->dma_dac2.count &= s->dma_dac2.fragsize-1;
|
1659 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1660 |
|
|
return copy_to_user((void *)arg, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
|
1661 |
|
|
|
1662 |
|
|
case SNDCTL_DSP_GETBLKSIZE:
|
1663 |
|
|
if (file->f_mode & FMODE_WRITE) {
|
1664 |
|
|
if ((val = prog_dmabuf_dac2(s)))
|
1665 |
|
|
return val;
|
1666 |
|
|
return put_user(s->dma_dac2.fragsize, (int *)arg);
|
1667 |
|
|
}
|
1668 |
|
|
if ((val = prog_dmabuf_adc(s)))
|
1669 |
|
|
return val;
|
1670 |
|
|
return put_user(s->dma_adc.fragsize, (int *)arg);
|
1671 |
|
|
|
1672 |
|
|
case SNDCTL_DSP_SETFRAGMENT:
|
1673 |
|
|
if (get_user(val, (int *)arg))
|
1674 |
|
|
return -EFAULT;
|
1675 |
|
|
if (file->f_mode & FMODE_READ) {
|
1676 |
|
|
s->dma_adc.ossfragshift = val & 0xffff;
|
1677 |
|
|
s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff;
|
1678 |
|
|
if (s->dma_adc.ossfragshift < 4)
|
1679 |
|
|
s->dma_adc.ossfragshift = 4;
|
1680 |
|
|
if (s->dma_adc.ossfragshift > 15)
|
1681 |
|
|
s->dma_adc.ossfragshift = 15;
|
1682 |
|
|
if (s->dma_adc.ossmaxfrags < 4)
|
1683 |
|
|
s->dma_adc.ossmaxfrags = 4;
|
1684 |
|
|
}
|
1685 |
|
|
if (file->f_mode & FMODE_WRITE) {
|
1686 |
|
|
s->dma_dac2.ossfragshift = val & 0xffff;
|
1687 |
|
|
s->dma_dac2.ossmaxfrags = (val >> 16) & 0xffff;
|
1688 |
|
|
if (s->dma_dac2.ossfragshift < 4)
|
1689 |
|
|
s->dma_dac2.ossfragshift = 4;
|
1690 |
|
|
if (s->dma_dac2.ossfragshift > 15)
|
1691 |
|
|
s->dma_dac2.ossfragshift = 15;
|
1692 |
|
|
if (s->dma_dac2.ossmaxfrags < 4)
|
1693 |
|
|
s->dma_dac2.ossmaxfrags = 4;
|
1694 |
|
|
}
|
1695 |
|
|
return 0;
|
1696 |
|
|
|
1697 |
|
|
case SNDCTL_DSP_SUBDIVIDE:
|
1698 |
|
|
if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
|
1699 |
|
|
(file->f_mode & FMODE_WRITE && s->dma_dac2.subdivision))
|
1700 |
|
|
return -EINVAL;
|
1701 |
|
|
if (get_user(val, (int *)arg))
|
1702 |
|
|
return -EFAULT;
|
1703 |
|
|
if (val != 1 && val != 2 && val != 4)
|
1704 |
|
|
return -EINVAL;
|
1705 |
|
|
if (file->f_mode & FMODE_READ)
|
1706 |
|
|
s->dma_adc.subdivision = val;
|
1707 |
|
|
if (file->f_mode & FMODE_WRITE)
|
1708 |
|
|
s->dma_dac2.subdivision = val;
|
1709 |
|
|
return 0;
|
1710 |
|
|
|
1711 |
|
|
case SOUND_PCM_READ_RATE:
|
1712 |
|
|
return put_user(DAC2_DIVTOSR((s->ctrl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV), (int *)arg);
|
1713 |
|
|
|
1714 |
|
|
case SOUND_PCM_READ_CHANNELS:
|
1715 |
|
|
return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SMB : SCTRL_P2SMB)) ?
|
1716 |
|
|
2 : 1, (int *)arg);
|
1717 |
|
|
|
1718 |
|
|
case SOUND_PCM_READ_BITS:
|
1719 |
|
|
return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SEB : SCTRL_P2SEB)) ?
|
1720 |
|
|
16 : 8, (int *)arg);
|
1721 |
|
|
|
1722 |
|
|
case SOUND_PCM_WRITE_FILTER:
|
1723 |
|
|
case SNDCTL_DSP_SETSYNCRO:
|
1724 |
|
|
case SOUND_PCM_READ_FILTER:
|
1725 |
|
|
return -EINVAL;
|
1726 |
|
|
|
1727 |
|
|
}
|
1728 |
|
|
return mixer_ioctl(s, cmd, arg);
|
1729 |
|
|
}
|
1730 |
|
|
|
1731 |
|
|
static int es1370_open(struct inode *inode, struct file *file)
|
1732 |
|
|
{
|
1733 |
|
|
int minor = MINOR(inode->i_rdev);
|
1734 |
|
|
DECLARE_WAITQUEUE(wait, current);
|
1735 |
|
|
unsigned long flags;
|
1736 |
|
|
struct list_head *list;
|
1737 |
|
|
struct es1370_state *s;
|
1738 |
|
|
|
1739 |
|
|
for (list = devs.next; ; list = list->next) {
|
1740 |
|
|
if (list == &devs)
|
1741 |
|
|
return -ENODEV;
|
1742 |
|
|
s = list_entry(list, struct es1370_state, devs);
|
1743 |
|
|
if (!((s->dev_audio ^ minor) & ~0xf))
|
1744 |
|
|
break;
|
1745 |
|
|
}
|
1746 |
|
|
VALIDATE_STATE(s);
|
1747 |
|
|
file->private_data = s;
|
1748 |
|
|
/* wait for device to become free */
|
1749 |
|
|
down(&s->open_sem);
|
1750 |
|
|
while (s->open_mode & file->f_mode) {
|
1751 |
|
|
if (file->f_flags & O_NONBLOCK) {
|
1752 |
|
|
up(&s->open_sem);
|
1753 |
|
|
return -EBUSY;
|
1754 |
|
|
}
|
1755 |
|
|
add_wait_queue(&s->open_wait, &wait);
|
1756 |
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
1757 |
|
|
up(&s->open_sem);
|
1758 |
|
|
schedule();
|
1759 |
|
|
remove_wait_queue(&s->open_wait, &wait);
|
1760 |
|
|
set_current_state(TASK_RUNNING);
|
1761 |
|
|
if (signal_pending(current))
|
1762 |
|
|
return -ERESTARTSYS;
|
1763 |
|
|
down(&s->open_sem);
|
1764 |
|
|
}
|
1765 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1766 |
|
|
if (!(s->open_mode & (FMODE_READ|FMODE_WRITE)))
|
1767 |
|
|
s->ctrl = (s->ctrl & ~CTRL_PCLKDIV) | (DAC2_SRTODIV(8000) << CTRL_SH_PCLKDIV);
|
1768 |
|
|
if (file->f_mode & FMODE_READ) {
|
1769 |
|
|
s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags = s->dma_adc.subdivision = 0;
|
1770 |
|
|
s->dma_adc.enabled = 1;
|
1771 |
|
|
s->sctrl &= ~SCTRL_R1FMT;
|
1772 |
|
|
if ((minor & 0xf) == SND_DEV_DSP16)
|
1773 |
|
|
s->sctrl |= ES1370_FMT_S16_MONO << SCTRL_SH_R1FMT;
|
1774 |
|
|
else
|
1775 |
|
|
s->sctrl |= ES1370_FMT_U8_MONO << SCTRL_SH_R1FMT;
|
1776 |
|
|
}
|
1777 |
|
|
if (file->f_mode & FMODE_WRITE) {
|
1778 |
|
|
s->dma_dac2.ossfragshift = s->dma_dac2.ossmaxfrags = s->dma_dac2.subdivision = 0;
|
1779 |
|
|
s->dma_dac2.enabled = 1;
|
1780 |
|
|
s->sctrl &= ~SCTRL_P2FMT;
|
1781 |
|
|
if ((minor & 0xf) == SND_DEV_DSP16)
|
1782 |
|
|
s->sctrl |= ES1370_FMT_S16_MONO << SCTRL_SH_P2FMT;
|
1783 |
|
|
else
|
1784 |
|
|
s->sctrl |= ES1370_FMT_U8_MONO << SCTRL_SH_P2FMT;
|
1785 |
|
|
}
|
1786 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
1787 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
1788 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1789 |
|
|
s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
|
1790 |
|
|
up(&s->open_sem);
|
1791 |
|
|
init_MUTEX(&s->sem);
|
1792 |
|
|
return 0;
|
1793 |
|
|
}
|
1794 |
|
|
|
1795 |
|
|
static int es1370_release(struct inode *inode, struct file *file)
|
1796 |
|
|
{
|
1797 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
1798 |
|
|
|
1799 |
|
|
VALIDATE_STATE(s);
|
1800 |
|
|
lock_kernel();
|
1801 |
|
|
if (file->f_mode & FMODE_WRITE)
|
1802 |
|
|
drain_dac2(s, file->f_flags & O_NONBLOCK);
|
1803 |
|
|
down(&s->open_sem);
|
1804 |
|
|
if (file->f_mode & FMODE_WRITE) {
|
1805 |
|
|
stop_dac2(s);
|
1806 |
|
|
synchronize_irq();
|
1807 |
|
|
dealloc_dmabuf(s, &s->dma_dac2);
|
1808 |
|
|
}
|
1809 |
|
|
if (file->f_mode & FMODE_READ) {
|
1810 |
|
|
stop_adc(s);
|
1811 |
|
|
dealloc_dmabuf(s, &s->dma_adc);
|
1812 |
|
|
}
|
1813 |
|
|
s->open_mode &= ~(file->f_mode & (FMODE_READ|FMODE_WRITE));
|
1814 |
|
|
wake_up(&s->open_wait);
|
1815 |
|
|
up(&s->open_sem);
|
1816 |
|
|
unlock_kernel();
|
1817 |
|
|
return 0;
|
1818 |
|
|
}
|
1819 |
|
|
|
1820 |
|
|
static /*const*/ struct file_operations es1370_audio_fops = {
|
1821 |
|
|
owner: THIS_MODULE,
|
1822 |
|
|
llseek: no_llseek,
|
1823 |
|
|
read: es1370_read,
|
1824 |
|
|
write: es1370_write,
|
1825 |
|
|
poll: es1370_poll,
|
1826 |
|
|
ioctl: es1370_ioctl,
|
1827 |
|
|
mmap: es1370_mmap,
|
1828 |
|
|
open: es1370_open,
|
1829 |
|
|
release: es1370_release,
|
1830 |
|
|
};
|
1831 |
|
|
|
1832 |
|
|
/* --------------------------------------------------------------------- */
|
1833 |
|
|
|
1834 |
|
|
static ssize_t es1370_write_dac(struct file *file, const char *buffer, size_t count, loff_t *ppos)
|
1835 |
|
|
{
|
1836 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
1837 |
|
|
DECLARE_WAITQUEUE(wait, current);
|
1838 |
|
|
ssize_t ret = 0;
|
1839 |
|
|
unsigned long flags;
|
1840 |
|
|
unsigned swptr;
|
1841 |
|
|
int cnt;
|
1842 |
|
|
|
1843 |
|
|
VALIDATE_STATE(s);
|
1844 |
|
|
if (ppos != &file->f_pos)
|
1845 |
|
|
return -ESPIPE;
|
1846 |
|
|
if (s->dma_dac1.mapped)
|
1847 |
|
|
return -ENXIO;
|
1848 |
|
|
if (!s->dma_dac1.ready && (ret = prog_dmabuf_dac1(s)))
|
1849 |
|
|
return ret;
|
1850 |
|
|
if (!access_ok(VERIFY_READ, buffer, count))
|
1851 |
|
|
return -EFAULT;
|
1852 |
|
|
add_wait_queue(&s->dma_dac1.wait, &wait);
|
1853 |
|
|
while (count > 0) {
|
1854 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1855 |
|
|
if (s->dma_dac1.count < 0) {
|
1856 |
|
|
s->dma_dac1.count = 0;
|
1857 |
|
|
s->dma_dac1.swptr = s->dma_dac1.hwptr;
|
1858 |
|
|
}
|
1859 |
|
|
swptr = s->dma_dac1.swptr;
|
1860 |
|
|
cnt = s->dma_dac1.dmasize-swptr;
|
1861 |
|
|
if (s->dma_dac1.count + cnt > s->dma_dac1.dmasize)
|
1862 |
|
|
cnt = s->dma_dac1.dmasize - s->dma_dac1.count;
|
1863 |
|
|
if (cnt <= 0)
|
1864 |
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
1865 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1866 |
|
|
if (cnt > count)
|
1867 |
|
|
cnt = count;
|
1868 |
|
|
if (cnt <= 0) {
|
1869 |
|
|
if (s->dma_dac1.enabled)
|
1870 |
|
|
start_dac1(s);
|
1871 |
|
|
if (file->f_flags & O_NONBLOCK) {
|
1872 |
|
|
if (!ret)
|
1873 |
|
|
ret = -EAGAIN;
|
1874 |
|
|
break;
|
1875 |
|
|
}
|
1876 |
|
|
schedule();
|
1877 |
|
|
if (signal_pending(current)) {
|
1878 |
|
|
if (!ret)
|
1879 |
|
|
ret = -ERESTARTSYS;
|
1880 |
|
|
break;
|
1881 |
|
|
}
|
1882 |
|
|
continue;
|
1883 |
|
|
}
|
1884 |
|
|
if (copy_from_user(s->dma_dac1.rawbuf + swptr, buffer, cnt)) {
|
1885 |
|
|
if (!ret)
|
1886 |
|
|
ret = -EFAULT;
|
1887 |
|
|
break;
|
1888 |
|
|
}
|
1889 |
|
|
swptr = (swptr + cnt) % s->dma_dac1.dmasize;
|
1890 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1891 |
|
|
s->dma_dac1.swptr = swptr;
|
1892 |
|
|
s->dma_dac1.count += cnt;
|
1893 |
|
|
s->dma_dac1.endcleared = 0;
|
1894 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1895 |
|
|
count -= cnt;
|
1896 |
|
|
buffer += cnt;
|
1897 |
|
|
ret += cnt;
|
1898 |
|
|
if (s->dma_dac1.enabled)
|
1899 |
|
|
start_dac1(s);
|
1900 |
|
|
}
|
1901 |
|
|
remove_wait_queue(&s->dma_dac1.wait, &wait);
|
1902 |
|
|
set_current_state(TASK_RUNNING);
|
1903 |
|
|
return ret;
|
1904 |
|
|
}
|
1905 |
|
|
|
1906 |
|
|
/* No kernel lock - we have our own spinlock */
|
1907 |
|
|
static unsigned int es1370_poll_dac(struct file *file, struct poll_table_struct *wait)
|
1908 |
|
|
{
|
1909 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
1910 |
|
|
unsigned long flags;
|
1911 |
|
|
unsigned int mask = 0;
|
1912 |
|
|
|
1913 |
|
|
VALIDATE_STATE(s);
|
1914 |
|
|
if (!s->dma_dac1.ready && prog_dmabuf_dac1(s))
|
1915 |
|
|
return 0;
|
1916 |
|
|
poll_wait(file, &s->dma_dac1.wait, wait);
|
1917 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1918 |
|
|
es1370_update_ptr(s);
|
1919 |
|
|
if (s->dma_dac1.mapped) {
|
1920 |
|
|
if (s->dma_dac1.count >= (signed)s->dma_dac1.fragsize)
|
1921 |
|
|
mask |= POLLOUT | POLLWRNORM;
|
1922 |
|
|
} else {
|
1923 |
|
|
if ((signed)s->dma_dac1.dmasize >= s->dma_dac1.count + (signed)s->dma_dac1.fragsize)
|
1924 |
|
|
mask |= POLLOUT | POLLWRNORM;
|
1925 |
|
|
}
|
1926 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
1927 |
|
|
return mask;
|
1928 |
|
|
}
|
1929 |
|
|
|
1930 |
|
|
static int es1370_mmap_dac(struct file *file, struct vm_area_struct *vma)
|
1931 |
|
|
{
|
1932 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
1933 |
|
|
int ret;
|
1934 |
|
|
unsigned long size;
|
1935 |
|
|
|
1936 |
|
|
VALIDATE_STATE(s);
|
1937 |
|
|
if (!(vma->vm_flags & VM_WRITE))
|
1938 |
|
|
return -EINVAL;
|
1939 |
|
|
lock_kernel();
|
1940 |
|
|
if ((ret = prog_dmabuf_dac1(s)) != 0)
|
1941 |
|
|
goto out;
|
1942 |
|
|
ret = -EINVAL;
|
1943 |
|
|
if (vma->vm_pgoff != 0)
|
1944 |
|
|
goto out;
|
1945 |
|
|
size = vma->vm_end - vma->vm_start;
|
1946 |
|
|
if (size > (PAGE_SIZE << s->dma_dac1.buforder))
|
1947 |
|
|
goto out;
|
1948 |
|
|
ret = -EAGAIN;
|
1949 |
|
|
if (remap_page_range(vma->vm_start, virt_to_phys(s->dma_dac1.rawbuf), size, vma->vm_page_prot))
|
1950 |
|
|
goto out;
|
1951 |
|
|
s->dma_dac1.mapped = 1;
|
1952 |
|
|
ret = 0;
|
1953 |
|
|
out:
|
1954 |
|
|
unlock_kernel();
|
1955 |
|
|
return ret;
|
1956 |
|
|
}
|
1957 |
|
|
|
1958 |
|
|
static int es1370_ioctl_dac(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
|
1959 |
|
|
{
|
1960 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
1961 |
|
|
unsigned long flags;
|
1962 |
|
|
audio_buf_info abinfo;
|
1963 |
|
|
count_info cinfo;
|
1964 |
|
|
int count;
|
1965 |
|
|
unsigned ctrl;
|
1966 |
|
|
int val, ret;
|
1967 |
|
|
|
1968 |
|
|
VALIDATE_STATE(s);
|
1969 |
|
|
switch (cmd) {
|
1970 |
|
|
case OSS_GETVERSION:
|
1971 |
|
|
return put_user(SOUND_VERSION, (int *)arg);
|
1972 |
|
|
|
1973 |
|
|
case SNDCTL_DSP_SYNC:
|
1974 |
|
|
return drain_dac1(s, 0/*file->f_flags & O_NONBLOCK*/);
|
1975 |
|
|
|
1976 |
|
|
case SNDCTL_DSP_SETDUPLEX:
|
1977 |
|
|
return -EINVAL;
|
1978 |
|
|
|
1979 |
|
|
case SNDCTL_DSP_GETCAPS:
|
1980 |
|
|
return put_user(DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP, (int *)arg);
|
1981 |
|
|
|
1982 |
|
|
case SNDCTL_DSP_RESET:
|
1983 |
|
|
stop_dac1(s);
|
1984 |
|
|
synchronize_irq();
|
1985 |
|
|
s->dma_dac1.swptr = s->dma_dac1.hwptr = s->dma_dac1.count = s->dma_dac1.total_bytes = 0;
|
1986 |
|
|
return 0;
|
1987 |
|
|
|
1988 |
|
|
case SNDCTL_DSP_SPEED:
|
1989 |
|
|
if (get_user(val, (int *)arg))
|
1990 |
|
|
return -EFAULT;
|
1991 |
|
|
if (val >= 0) {
|
1992 |
|
|
stop_dac1(s);
|
1993 |
|
|
s->dma_dac1.ready = 0;
|
1994 |
|
|
for (ctrl = 0; ctrl <= 2; ctrl++)
|
1995 |
|
|
if (val < (dac1_samplerate[ctrl] + dac1_samplerate[ctrl+1]) / 2)
|
1996 |
|
|
break;
|
1997 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
1998 |
|
|
s->ctrl = (s->ctrl & ~CTRL_WTSRSEL) | (ctrl << CTRL_SH_WTSRSEL);
|
1999 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
2000 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2001 |
|
|
}
|
2002 |
|
|
return put_user(dac1_samplerate[(s->ctrl & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL], (int *)arg);
|
2003 |
|
|
|
2004 |
|
|
case SNDCTL_DSP_STEREO:
|
2005 |
|
|
if (get_user(val, (int *)arg))
|
2006 |
|
|
return -EFAULT;
|
2007 |
|
|
stop_dac1(s);
|
2008 |
|
|
s->dma_dac1.ready = 0;
|
2009 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2010 |
|
|
if (val)
|
2011 |
|
|
s->sctrl |= SCTRL_P1SMB;
|
2012 |
|
|
else
|
2013 |
|
|
s->sctrl &= ~SCTRL_P1SMB;
|
2014 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
2015 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2016 |
|
|
return 0;
|
2017 |
|
|
|
2018 |
|
|
case SNDCTL_DSP_CHANNELS:
|
2019 |
|
|
if (get_user(val, (int *)arg))
|
2020 |
|
|
return -EFAULT;
|
2021 |
|
|
if (val != 0) {
|
2022 |
|
|
if (s->dma_dac1.mapped)
|
2023 |
|
|
return -EINVAL;
|
2024 |
|
|
stop_dac1(s);
|
2025 |
|
|
s->dma_dac1.ready = 0;
|
2026 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2027 |
|
|
if (val >= 2)
|
2028 |
|
|
s->sctrl |= SCTRL_P1SMB;
|
2029 |
|
|
else
|
2030 |
|
|
s->sctrl &= ~SCTRL_P1SMB;
|
2031 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
2032 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2033 |
|
|
}
|
2034 |
|
|
return put_user((s->sctrl & SCTRL_P1SMB) ? 2 : 1, (int *)arg);
|
2035 |
|
|
|
2036 |
|
|
case SNDCTL_DSP_GETFMTS: /* Returns a mask */
|
2037 |
|
|
return put_user(AFMT_S16_LE|AFMT_U8, (int *)arg);
|
2038 |
|
|
|
2039 |
|
|
case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
|
2040 |
|
|
if (get_user(val, (int *)arg))
|
2041 |
|
|
return -EFAULT;
|
2042 |
|
|
if (val != AFMT_QUERY) {
|
2043 |
|
|
stop_dac1(s);
|
2044 |
|
|
s->dma_dac1.ready = 0;
|
2045 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2046 |
|
|
if (val == AFMT_S16_LE)
|
2047 |
|
|
s->sctrl |= SCTRL_P1SEB;
|
2048 |
|
|
else
|
2049 |
|
|
s->sctrl &= ~SCTRL_P1SEB;
|
2050 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
2051 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2052 |
|
|
}
|
2053 |
|
|
return put_user((s->sctrl & SCTRL_P1SEB) ? AFMT_S16_LE : AFMT_U8, (int *)arg);
|
2054 |
|
|
|
2055 |
|
|
case SNDCTL_DSP_POST:
|
2056 |
|
|
return 0;
|
2057 |
|
|
|
2058 |
|
|
case SNDCTL_DSP_GETTRIGGER:
|
2059 |
|
|
return put_user((s->ctrl & CTRL_DAC1_EN) ? PCM_ENABLE_OUTPUT : 0, (int *)arg);
|
2060 |
|
|
|
2061 |
|
|
case SNDCTL_DSP_SETTRIGGER:
|
2062 |
|
|
if (get_user(val, (int *)arg))
|
2063 |
|
|
return -EFAULT;
|
2064 |
|
|
if (val & PCM_ENABLE_OUTPUT) {
|
2065 |
|
|
if (!s->dma_dac1.ready && (ret = prog_dmabuf_dac1(s)))
|
2066 |
|
|
return ret;
|
2067 |
|
|
s->dma_dac1.enabled = 1;
|
2068 |
|
|
start_dac1(s);
|
2069 |
|
|
} else {
|
2070 |
|
|
s->dma_dac1.enabled = 0;
|
2071 |
|
|
stop_dac1(s);
|
2072 |
|
|
}
|
2073 |
|
|
return 0;
|
2074 |
|
|
|
2075 |
|
|
case SNDCTL_DSP_GETOSPACE:
|
2076 |
|
|
if (!s->dma_dac1.ready && (val = prog_dmabuf_dac1(s)) != 0)
|
2077 |
|
|
return val;
|
2078 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2079 |
|
|
es1370_update_ptr(s);
|
2080 |
|
|
abinfo.fragsize = s->dma_dac1.fragsize;
|
2081 |
|
|
count = s->dma_dac1.count;
|
2082 |
|
|
if (count < 0)
|
2083 |
|
|
count = 0;
|
2084 |
|
|
abinfo.bytes = s->dma_dac1.dmasize - count;
|
2085 |
|
|
abinfo.fragstotal = s->dma_dac1.numfrag;
|
2086 |
|
|
abinfo.fragments = abinfo.bytes >> s->dma_dac1.fragshift;
|
2087 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2088 |
|
|
return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
|
2089 |
|
|
|
2090 |
|
|
case SNDCTL_DSP_NONBLOCK:
|
2091 |
|
|
file->f_flags |= O_NONBLOCK;
|
2092 |
|
|
return 0;
|
2093 |
|
|
|
2094 |
|
|
case SNDCTL_DSP_GETODELAY:
|
2095 |
|
|
if (!s->dma_dac1.ready && (val = prog_dmabuf_dac1(s)) != 0)
|
2096 |
|
|
return val;
|
2097 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2098 |
|
|
es1370_update_ptr(s);
|
2099 |
|
|
count = s->dma_dac1.count;
|
2100 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2101 |
|
|
if (count < 0)
|
2102 |
|
|
count = 0;
|
2103 |
|
|
return put_user(count, (int *)arg);
|
2104 |
|
|
|
2105 |
|
|
case SNDCTL_DSP_GETOPTR:
|
2106 |
|
|
if (!s->dma_dac1.ready && (val = prog_dmabuf_dac1(s)) != 0)
|
2107 |
|
|
return val;
|
2108 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2109 |
|
|
es1370_update_ptr(s);
|
2110 |
|
|
cinfo.bytes = s->dma_dac1.total_bytes;
|
2111 |
|
|
count = s->dma_dac1.count;
|
2112 |
|
|
if (count < 0)
|
2113 |
|
|
count = 0;
|
2114 |
|
|
cinfo.blocks = count >> s->dma_dac1.fragshift;
|
2115 |
|
|
cinfo.ptr = s->dma_dac1.hwptr;
|
2116 |
|
|
if (s->dma_dac1.mapped)
|
2117 |
|
|
s->dma_dac1.count &= s->dma_dac1.fragsize-1;
|
2118 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2119 |
|
|
return copy_to_user((void *)arg, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
|
2120 |
|
|
|
2121 |
|
|
case SNDCTL_DSP_GETBLKSIZE:
|
2122 |
|
|
if ((val = prog_dmabuf_dac1(s)))
|
2123 |
|
|
return val;
|
2124 |
|
|
return put_user(s->dma_dac1.fragsize, (int *)arg);
|
2125 |
|
|
|
2126 |
|
|
case SNDCTL_DSP_SETFRAGMENT:
|
2127 |
|
|
if (get_user(val, (int *)arg))
|
2128 |
|
|
return -EFAULT;
|
2129 |
|
|
s->dma_dac1.ossfragshift = val & 0xffff;
|
2130 |
|
|
s->dma_dac1.ossmaxfrags = (val >> 16) & 0xffff;
|
2131 |
|
|
if (s->dma_dac1.ossfragshift < 4)
|
2132 |
|
|
s->dma_dac1.ossfragshift = 4;
|
2133 |
|
|
if (s->dma_dac1.ossfragshift > 15)
|
2134 |
|
|
s->dma_dac1.ossfragshift = 15;
|
2135 |
|
|
if (s->dma_dac1.ossmaxfrags < 4)
|
2136 |
|
|
s->dma_dac1.ossmaxfrags = 4;
|
2137 |
|
|
return 0;
|
2138 |
|
|
|
2139 |
|
|
case SNDCTL_DSP_SUBDIVIDE:
|
2140 |
|
|
if (s->dma_dac1.subdivision)
|
2141 |
|
|
return -EINVAL;
|
2142 |
|
|
if (get_user(val, (int *)arg))
|
2143 |
|
|
return -EFAULT;
|
2144 |
|
|
if (val != 1 && val != 2 && val != 4)
|
2145 |
|
|
return -EINVAL;
|
2146 |
|
|
s->dma_dac1.subdivision = val;
|
2147 |
|
|
return 0;
|
2148 |
|
|
|
2149 |
|
|
case SOUND_PCM_READ_RATE:
|
2150 |
|
|
return put_user(dac1_samplerate[(s->ctrl & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL], (int *)arg);
|
2151 |
|
|
|
2152 |
|
|
case SOUND_PCM_READ_CHANNELS:
|
2153 |
|
|
return put_user((s->sctrl & SCTRL_P1SMB) ? 2 : 1, (int *)arg);
|
2154 |
|
|
|
2155 |
|
|
case SOUND_PCM_READ_BITS:
|
2156 |
|
|
return put_user((s->sctrl & SCTRL_P1SEB) ? 16 : 8, (int *)arg);
|
2157 |
|
|
|
2158 |
|
|
case SOUND_PCM_WRITE_FILTER:
|
2159 |
|
|
case SNDCTL_DSP_SETSYNCRO:
|
2160 |
|
|
case SOUND_PCM_READ_FILTER:
|
2161 |
|
|
return -EINVAL;
|
2162 |
|
|
|
2163 |
|
|
}
|
2164 |
|
|
return mixer_ioctl(s, cmd, arg);
|
2165 |
|
|
}
|
2166 |
|
|
|
2167 |
|
|
static int es1370_open_dac(struct inode *inode, struct file *file)
|
2168 |
|
|
{
|
2169 |
|
|
int minor = MINOR(inode->i_rdev);
|
2170 |
|
|
DECLARE_WAITQUEUE(wait, current);
|
2171 |
|
|
unsigned long flags;
|
2172 |
|
|
struct list_head *list;
|
2173 |
|
|
struct es1370_state *s;
|
2174 |
|
|
|
2175 |
|
|
for (list = devs.next; ; list = list->next) {
|
2176 |
|
|
if (list == &devs)
|
2177 |
|
|
return -ENODEV;
|
2178 |
|
|
s = list_entry(list, struct es1370_state, devs);
|
2179 |
|
|
if (!((s->dev_dac ^ minor) & ~0xf))
|
2180 |
|
|
break;
|
2181 |
|
|
}
|
2182 |
|
|
VALIDATE_STATE(s);
|
2183 |
|
|
/* we allow opening with O_RDWR, most programs do it although they will only write */
|
2184 |
|
|
#if 0
|
2185 |
|
|
if (file->f_mode & FMODE_READ)
|
2186 |
|
|
return -EPERM;
|
2187 |
|
|
#endif
|
2188 |
|
|
if (!(file->f_mode & FMODE_WRITE))
|
2189 |
|
|
return -EINVAL;
|
2190 |
|
|
file->private_data = s;
|
2191 |
|
|
/* wait for device to become free */
|
2192 |
|
|
down(&s->open_sem);
|
2193 |
|
|
while (s->open_mode & FMODE_DAC) {
|
2194 |
|
|
if (file->f_flags & O_NONBLOCK) {
|
2195 |
|
|
up(&s->open_sem);
|
2196 |
|
|
return -EBUSY;
|
2197 |
|
|
}
|
2198 |
|
|
add_wait_queue(&s->open_wait, &wait);
|
2199 |
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
2200 |
|
|
up(&s->open_sem);
|
2201 |
|
|
schedule();
|
2202 |
|
|
remove_wait_queue(&s->open_wait, &wait);
|
2203 |
|
|
set_current_state(TASK_RUNNING);
|
2204 |
|
|
if (signal_pending(current))
|
2205 |
|
|
return -ERESTARTSYS;
|
2206 |
|
|
down(&s->open_sem);
|
2207 |
|
|
}
|
2208 |
|
|
s->dma_dac1.ossfragshift = s->dma_dac1.ossmaxfrags = s->dma_dac1.subdivision = 0;
|
2209 |
|
|
s->dma_dac1.enabled = 1;
|
2210 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2211 |
|
|
s->ctrl = (s->ctrl & ~CTRL_WTSRSEL) | (1 << CTRL_SH_WTSRSEL);
|
2212 |
|
|
s->sctrl &= ~SCTRL_P1FMT;
|
2213 |
|
|
if ((minor & 0xf) == SND_DEV_DSP16)
|
2214 |
|
|
s->sctrl |= ES1370_FMT_S16_MONO << SCTRL_SH_P1FMT;
|
2215 |
|
|
else
|
2216 |
|
|
s->sctrl |= ES1370_FMT_U8_MONO << SCTRL_SH_P1FMT;
|
2217 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
2218 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
2219 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2220 |
|
|
s->open_mode |= FMODE_DAC;
|
2221 |
|
|
up(&s->open_sem);
|
2222 |
|
|
return 0;
|
2223 |
|
|
}
|
2224 |
|
|
|
2225 |
|
|
static int es1370_release_dac(struct inode *inode, struct file *file)
|
2226 |
|
|
{
|
2227 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
2228 |
|
|
|
2229 |
|
|
VALIDATE_STATE(s);
|
2230 |
|
|
lock_kernel();
|
2231 |
|
|
drain_dac1(s, file->f_flags & O_NONBLOCK);
|
2232 |
|
|
down(&s->open_sem);
|
2233 |
|
|
stop_dac1(s);
|
2234 |
|
|
dealloc_dmabuf(s, &s->dma_dac1);
|
2235 |
|
|
s->open_mode &= ~FMODE_DAC;
|
2236 |
|
|
wake_up(&s->open_wait);
|
2237 |
|
|
up(&s->open_sem);
|
2238 |
|
|
unlock_kernel();
|
2239 |
|
|
return 0;
|
2240 |
|
|
}
|
2241 |
|
|
|
2242 |
|
|
static /*const*/ struct file_operations es1370_dac_fops = {
|
2243 |
|
|
owner: THIS_MODULE,
|
2244 |
|
|
llseek: no_llseek,
|
2245 |
|
|
write: es1370_write_dac,
|
2246 |
|
|
poll: es1370_poll_dac,
|
2247 |
|
|
ioctl: es1370_ioctl_dac,
|
2248 |
|
|
mmap: es1370_mmap_dac,
|
2249 |
|
|
open: es1370_open_dac,
|
2250 |
|
|
release: es1370_release_dac,
|
2251 |
|
|
};
|
2252 |
|
|
|
2253 |
|
|
/* --------------------------------------------------------------------- */
|
2254 |
|
|
|
2255 |
|
|
static ssize_t es1370_midi_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
|
2256 |
|
|
{
|
2257 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
2258 |
|
|
DECLARE_WAITQUEUE(wait, current);
|
2259 |
|
|
ssize_t ret;
|
2260 |
|
|
unsigned long flags;
|
2261 |
|
|
unsigned ptr;
|
2262 |
|
|
int cnt;
|
2263 |
|
|
|
2264 |
|
|
VALIDATE_STATE(s);
|
2265 |
|
|
if (ppos != &file->f_pos)
|
2266 |
|
|
return -ESPIPE;
|
2267 |
|
|
if (!access_ok(VERIFY_WRITE, buffer, count))
|
2268 |
|
|
return -EFAULT;
|
2269 |
|
|
if (count == 0)
|
2270 |
|
|
return 0;
|
2271 |
|
|
ret = 0;
|
2272 |
|
|
add_wait_queue(&s->midi.iwait, &wait);
|
2273 |
|
|
while (count > 0) {
|
2274 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2275 |
|
|
ptr = s->midi.ird;
|
2276 |
|
|
cnt = MIDIINBUF - ptr;
|
2277 |
|
|
if (s->midi.icnt < cnt)
|
2278 |
|
|
cnt = s->midi.icnt;
|
2279 |
|
|
if (cnt <= 0)
|
2280 |
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
2281 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2282 |
|
|
if (cnt > count)
|
2283 |
|
|
cnt = count;
|
2284 |
|
|
if (cnt <= 0) {
|
2285 |
|
|
if (file->f_flags & O_NONBLOCK) {
|
2286 |
|
|
if (!ret)
|
2287 |
|
|
ret = -EAGAIN;
|
2288 |
|
|
break;
|
2289 |
|
|
}
|
2290 |
|
|
schedule();
|
2291 |
|
|
if (signal_pending(current)) {
|
2292 |
|
|
if (!ret)
|
2293 |
|
|
ret = -ERESTARTSYS;
|
2294 |
|
|
break;
|
2295 |
|
|
}
|
2296 |
|
|
continue;
|
2297 |
|
|
}
|
2298 |
|
|
if (copy_to_user(buffer, s->midi.ibuf + ptr, cnt)) {
|
2299 |
|
|
if (!ret)
|
2300 |
|
|
ret = -EFAULT;
|
2301 |
|
|
break;
|
2302 |
|
|
}
|
2303 |
|
|
ptr = (ptr + cnt) % MIDIINBUF;
|
2304 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2305 |
|
|
s->midi.ird = ptr;
|
2306 |
|
|
s->midi.icnt -= cnt;
|
2307 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2308 |
|
|
count -= cnt;
|
2309 |
|
|
buffer += cnt;
|
2310 |
|
|
ret += cnt;
|
2311 |
|
|
break;
|
2312 |
|
|
}
|
2313 |
|
|
__set_current_state(TASK_RUNNING);
|
2314 |
|
|
remove_wait_queue(&s->midi.iwait, &wait);
|
2315 |
|
|
return ret;
|
2316 |
|
|
}
|
2317 |
|
|
|
2318 |
|
|
static ssize_t es1370_midi_write(struct file *file, const char *buffer, size_t count, loff_t *ppos)
|
2319 |
|
|
{
|
2320 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
2321 |
|
|
DECLARE_WAITQUEUE(wait, current);
|
2322 |
|
|
ssize_t ret;
|
2323 |
|
|
unsigned long flags;
|
2324 |
|
|
unsigned ptr;
|
2325 |
|
|
int cnt;
|
2326 |
|
|
|
2327 |
|
|
VALIDATE_STATE(s);
|
2328 |
|
|
if (ppos != &file->f_pos)
|
2329 |
|
|
return -ESPIPE;
|
2330 |
|
|
if (!access_ok(VERIFY_READ, buffer, count))
|
2331 |
|
|
return -EFAULT;
|
2332 |
|
|
if (count == 0)
|
2333 |
|
|
return 0;
|
2334 |
|
|
ret = 0;
|
2335 |
|
|
add_wait_queue(&s->midi.owait, &wait);
|
2336 |
|
|
while (count > 0) {
|
2337 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2338 |
|
|
ptr = s->midi.owr;
|
2339 |
|
|
cnt = MIDIOUTBUF - ptr;
|
2340 |
|
|
if (s->midi.ocnt + cnt > MIDIOUTBUF)
|
2341 |
|
|
cnt = MIDIOUTBUF - s->midi.ocnt;
|
2342 |
|
|
if (cnt <= 0) {
|
2343 |
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
2344 |
|
|
es1370_handle_midi(s);
|
2345 |
|
|
}
|
2346 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2347 |
|
|
if (cnt > count)
|
2348 |
|
|
cnt = count;
|
2349 |
|
|
if (cnt <= 0) {
|
2350 |
|
|
if (file->f_flags & O_NONBLOCK) {
|
2351 |
|
|
if (!ret)
|
2352 |
|
|
ret = -EAGAIN;
|
2353 |
|
|
break;
|
2354 |
|
|
}
|
2355 |
|
|
schedule();
|
2356 |
|
|
if (signal_pending(current)) {
|
2357 |
|
|
if (!ret)
|
2358 |
|
|
ret = -ERESTARTSYS;
|
2359 |
|
|
break;
|
2360 |
|
|
}
|
2361 |
|
|
continue;
|
2362 |
|
|
}
|
2363 |
|
|
if (copy_from_user(s->midi.obuf + ptr, buffer, cnt)) {
|
2364 |
|
|
if (!ret)
|
2365 |
|
|
ret = -EFAULT;
|
2366 |
|
|
break;
|
2367 |
|
|
}
|
2368 |
|
|
ptr = (ptr + cnt) % MIDIOUTBUF;
|
2369 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2370 |
|
|
s->midi.owr = ptr;
|
2371 |
|
|
s->midi.ocnt += cnt;
|
2372 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2373 |
|
|
count -= cnt;
|
2374 |
|
|
buffer += cnt;
|
2375 |
|
|
ret += cnt;
|
2376 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2377 |
|
|
es1370_handle_midi(s);
|
2378 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2379 |
|
|
}
|
2380 |
|
|
__set_current_state(TASK_RUNNING);
|
2381 |
|
|
remove_wait_queue(&s->midi.owait, &wait);
|
2382 |
|
|
return ret;
|
2383 |
|
|
}
|
2384 |
|
|
|
2385 |
|
|
/* No kernel lock - we have our own spinlock */
|
2386 |
|
|
static unsigned int es1370_midi_poll(struct file *file, struct poll_table_struct *wait)
|
2387 |
|
|
{
|
2388 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
2389 |
|
|
unsigned long flags;
|
2390 |
|
|
unsigned int mask = 0;
|
2391 |
|
|
|
2392 |
|
|
VALIDATE_STATE(s);
|
2393 |
|
|
if (file->f_mode & FMODE_WRITE)
|
2394 |
|
|
poll_wait(file, &s->midi.owait, wait);
|
2395 |
|
|
if (file->f_mode & FMODE_READ)
|
2396 |
|
|
poll_wait(file, &s->midi.iwait, wait);
|
2397 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2398 |
|
|
if (file->f_mode & FMODE_READ) {
|
2399 |
|
|
if (s->midi.icnt > 0)
|
2400 |
|
|
mask |= POLLIN | POLLRDNORM;
|
2401 |
|
|
}
|
2402 |
|
|
if (file->f_mode & FMODE_WRITE) {
|
2403 |
|
|
if (s->midi.ocnt < MIDIOUTBUF)
|
2404 |
|
|
mask |= POLLOUT | POLLWRNORM;
|
2405 |
|
|
}
|
2406 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2407 |
|
|
return mask;
|
2408 |
|
|
}
|
2409 |
|
|
|
2410 |
|
|
static int es1370_midi_open(struct inode *inode, struct file *file)
|
2411 |
|
|
{
|
2412 |
|
|
int minor = MINOR(inode->i_rdev);
|
2413 |
|
|
DECLARE_WAITQUEUE(wait, current);
|
2414 |
|
|
unsigned long flags;
|
2415 |
|
|
struct list_head *list;
|
2416 |
|
|
struct es1370_state *s;
|
2417 |
|
|
|
2418 |
|
|
for (list = devs.next; ; list = list->next) {
|
2419 |
|
|
if (list == &devs)
|
2420 |
|
|
return -ENODEV;
|
2421 |
|
|
s = list_entry(list, struct es1370_state, devs);
|
2422 |
|
|
if (s->dev_midi == minor)
|
2423 |
|
|
break;
|
2424 |
|
|
}
|
2425 |
|
|
VALIDATE_STATE(s);
|
2426 |
|
|
file->private_data = s;
|
2427 |
|
|
/* wait for device to become free */
|
2428 |
|
|
down(&s->open_sem);
|
2429 |
|
|
while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
|
2430 |
|
|
if (file->f_flags & O_NONBLOCK) {
|
2431 |
|
|
up(&s->open_sem);
|
2432 |
|
|
return -EBUSY;
|
2433 |
|
|
}
|
2434 |
|
|
add_wait_queue(&s->open_wait, &wait);
|
2435 |
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
2436 |
|
|
up(&s->open_sem);
|
2437 |
|
|
schedule();
|
2438 |
|
|
remove_wait_queue(&s->open_wait, &wait);
|
2439 |
|
|
set_current_state(TASK_RUNNING);
|
2440 |
|
|
if (signal_pending(current))
|
2441 |
|
|
return -ERESTARTSYS;
|
2442 |
|
|
down(&s->open_sem);
|
2443 |
|
|
}
|
2444 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2445 |
|
|
if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
|
2446 |
|
|
s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
|
2447 |
|
|
s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
|
2448 |
|
|
outb(UCTRL_CNTRL_SWR, s->io+ES1370_REG_UART_CONTROL);
|
2449 |
|
|
outb(0, s->io+ES1370_REG_UART_CONTROL);
|
2450 |
|
|
outb(0, s->io+ES1370_REG_UART_TEST);
|
2451 |
|
|
}
|
2452 |
|
|
if (file->f_mode & FMODE_READ) {
|
2453 |
|
|
s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
|
2454 |
|
|
}
|
2455 |
|
|
if (file->f_mode & FMODE_WRITE) {
|
2456 |
|
|
s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
|
2457 |
|
|
}
|
2458 |
|
|
s->ctrl |= CTRL_UART_EN;
|
2459 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
2460 |
|
|
es1370_handle_midi(s);
|
2461 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2462 |
|
|
s->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE);
|
2463 |
|
|
up(&s->open_sem);
|
2464 |
|
|
return 0;
|
2465 |
|
|
}
|
2466 |
|
|
|
2467 |
|
|
static int es1370_midi_release(struct inode *inode, struct file *file)
|
2468 |
|
|
{
|
2469 |
|
|
struct es1370_state *s = (struct es1370_state *)file->private_data;
|
2470 |
|
|
DECLARE_WAITQUEUE(wait, current);
|
2471 |
|
|
unsigned long flags;
|
2472 |
|
|
unsigned count, tmo;
|
2473 |
|
|
|
2474 |
|
|
VALIDATE_STATE(s);
|
2475 |
|
|
|
2476 |
|
|
lock_kernel();
|
2477 |
|
|
if (file->f_mode & FMODE_WRITE) {
|
2478 |
|
|
add_wait_queue(&s->midi.owait, &wait);
|
2479 |
|
|
for (;;) {
|
2480 |
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
2481 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2482 |
|
|
count = s->midi.ocnt;
|
2483 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2484 |
|
|
if (count <= 0)
|
2485 |
|
|
break;
|
2486 |
|
|
if (signal_pending(current))
|
2487 |
|
|
break;
|
2488 |
|
|
if (file->f_flags & O_NONBLOCK)
|
2489 |
|
|
break;
|
2490 |
|
|
tmo = (count * HZ) / 3100;
|
2491 |
|
|
if (!schedule_timeout(tmo ? : 1) && tmo)
|
2492 |
|
|
DBG(printk(KERN_DEBUG "es1370: midi timed out??\n");)
|
2493 |
|
|
}
|
2494 |
|
|
remove_wait_queue(&s->midi.owait, &wait);
|
2495 |
|
|
set_current_state(TASK_RUNNING);
|
2496 |
|
|
}
|
2497 |
|
|
down(&s->open_sem);
|
2498 |
|
|
s->open_mode &= ~((file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ|FMODE_MIDI_WRITE));
|
2499 |
|
|
spin_lock_irqsave(&s->lock, flags);
|
2500 |
|
|
if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
|
2501 |
|
|
s->ctrl &= ~CTRL_UART_EN;
|
2502 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
2503 |
|
|
}
|
2504 |
|
|
spin_unlock_irqrestore(&s->lock, flags);
|
2505 |
|
|
wake_up(&s->open_wait);
|
2506 |
|
|
up(&s->open_sem);
|
2507 |
|
|
unlock_kernel();
|
2508 |
|
|
return 0;
|
2509 |
|
|
}
|
2510 |
|
|
|
2511 |
|
|
static /*const*/ struct file_operations es1370_midi_fops = {
|
2512 |
|
|
owner: THIS_MODULE,
|
2513 |
|
|
llseek: no_llseek,
|
2514 |
|
|
read: es1370_midi_read,
|
2515 |
|
|
write: es1370_midi_write,
|
2516 |
|
|
poll: es1370_midi_poll,
|
2517 |
|
|
open: es1370_midi_open,
|
2518 |
|
|
release: es1370_midi_release,
|
2519 |
|
|
};
|
2520 |
|
|
|
2521 |
|
|
/* --------------------------------------------------------------------- */
|
2522 |
|
|
|
2523 |
|
|
/* maximum number of devices; only used for command line params */
|
2524 |
|
|
#define NR_DEVICE 5
|
2525 |
|
|
|
2526 |
|
|
static int joystick[NR_DEVICE] = { 0, };
|
2527 |
|
|
static int lineout[NR_DEVICE] = { 0, };
|
2528 |
|
|
static int micbias[NR_DEVICE] = { 0, };
|
2529 |
|
|
|
2530 |
|
|
static unsigned int devindex = 0;
|
2531 |
|
|
|
2532 |
|
|
MODULE_PARM(joystick, "1-" __MODULE_STRING(NR_DEVICE) "i");
|
2533 |
|
|
MODULE_PARM_DESC(joystick, "if 1 enables joystick interface (still need separate driver)");
|
2534 |
|
|
MODULE_PARM(lineout, "1-" __MODULE_STRING(NR_DEVICE) "i");
|
2535 |
|
|
MODULE_PARM_DESC(lineout, "if 1 the LINE input is converted to LINE out");
|
2536 |
|
|
MODULE_PARM(micbias, "1-" __MODULE_STRING(NR_DEVICE) "i");
|
2537 |
|
|
MODULE_PARM_DESC(micbias, "sets the +5V bias for an electret microphone");
|
2538 |
|
|
|
2539 |
|
|
MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu");
|
2540 |
|
|
MODULE_DESCRIPTION("ES1370 AudioPCI Driver");
|
2541 |
|
|
MODULE_LICENSE("GPL");
|
2542 |
|
|
|
2543 |
|
|
|
2544 |
|
|
/* --------------------------------------------------------------------- */
|
2545 |
|
|
|
2546 |
|
|
static struct initvol {
|
2547 |
|
|
int mixch;
|
2548 |
|
|
int vol;
|
2549 |
|
|
} initvol[] __initdata = {
|
2550 |
|
|
{ SOUND_MIXER_WRITE_VOLUME, 0x4040 },
|
2551 |
|
|
{ SOUND_MIXER_WRITE_PCM, 0x4040 },
|
2552 |
|
|
{ SOUND_MIXER_WRITE_SYNTH, 0x4040 },
|
2553 |
|
|
{ SOUND_MIXER_WRITE_CD, 0x4040 },
|
2554 |
|
|
{ SOUND_MIXER_WRITE_LINE, 0x4040 },
|
2555 |
|
|
{ SOUND_MIXER_WRITE_LINE1, 0x4040 },
|
2556 |
|
|
{ SOUND_MIXER_WRITE_LINE2, 0x4040 },
|
2557 |
|
|
{ SOUND_MIXER_WRITE_LINE3, 0x4040 },
|
2558 |
|
|
{ SOUND_MIXER_WRITE_MIC, 0x4040 },
|
2559 |
|
|
{ SOUND_MIXER_WRITE_OGAIN, 0x4040 }
|
2560 |
|
|
};
|
2561 |
|
|
|
2562 |
|
|
static int __devinit es1370_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid)
|
2563 |
|
|
{
|
2564 |
|
|
struct es1370_state *s;
|
2565 |
|
|
mm_segment_t fs;
|
2566 |
|
|
int i, val, ret;
|
2567 |
|
|
|
2568 |
|
|
if (bugbuf == NULL)
|
2569 |
|
|
bugbuf = kmalloc(16, GFP_KERNEL);
|
2570 |
|
|
if (bugbuf == NULL)
|
2571 |
|
|
return -ENOMEM;
|
2572 |
|
|
|
2573 |
|
|
if ((ret=pci_enable_device(pcidev)))
|
2574 |
|
|
return ret;
|
2575 |
|
|
|
2576 |
|
|
if ( !(pci_resource_flags(pcidev, 0) & IORESOURCE_IO) ||
|
2577 |
|
|
!pci_resource_start(pcidev, 0)
|
2578 |
|
|
)
|
2579 |
|
|
return -ENODEV;
|
2580 |
|
|
if (pcidev->irq == 0)
|
2581 |
|
|
return -ENODEV;
|
2582 |
|
|
i = pci_set_dma_mask(pcidev, 0xffffffff);
|
2583 |
|
|
if (i) {
|
2584 |
|
|
printk(KERN_WARNING "es1370: architecture does not support 32bit PCI busmaster DMA\n");
|
2585 |
|
|
return i;
|
2586 |
|
|
}
|
2587 |
|
|
if (!(s = kmalloc(sizeof(struct es1370_state), GFP_KERNEL))) {
|
2588 |
|
|
printk(KERN_WARNING "es1370: out of memory\n");
|
2589 |
|
|
return -ENOMEM;
|
2590 |
|
|
}
|
2591 |
|
|
memset(s, 0, sizeof(struct es1370_state));
|
2592 |
|
|
init_waitqueue_head(&s->dma_adc.wait);
|
2593 |
|
|
init_waitqueue_head(&s->dma_dac1.wait);
|
2594 |
|
|
init_waitqueue_head(&s->dma_dac2.wait);
|
2595 |
|
|
init_waitqueue_head(&s->open_wait);
|
2596 |
|
|
init_waitqueue_head(&s->midi.iwait);
|
2597 |
|
|
init_waitqueue_head(&s->midi.owait);
|
2598 |
|
|
init_MUTEX(&s->open_sem);
|
2599 |
|
|
spin_lock_init(&s->lock);
|
2600 |
|
|
s->magic = ES1370_MAGIC;
|
2601 |
|
|
s->dev = pcidev;
|
2602 |
|
|
s->io = pci_resource_start(pcidev, 0);
|
2603 |
|
|
s->irq = pcidev->irq;
|
2604 |
|
|
if (!request_region(s->io, ES1370_EXTENT, "es1370")) {
|
2605 |
|
|
printk(KERN_ERR "es1370: io ports %#lx-%#lx in use\n", s->io, s->io+ES1370_EXTENT-1);
|
2606 |
|
|
ret = -EBUSY;
|
2607 |
|
|
goto err_region;
|
2608 |
|
|
}
|
2609 |
|
|
if ((ret=request_irq(s->irq, es1370_interrupt, SA_SHIRQ, "es1370",s))) {
|
2610 |
|
|
printk(KERN_ERR "es1370: irq %u in use\n", s->irq);
|
2611 |
|
|
goto err_irq;
|
2612 |
|
|
}
|
2613 |
|
|
|
2614 |
|
|
/* initialize codec registers */
|
2615 |
|
|
/* note: setting CTRL_SERR_DIS is reported to break
|
2616 |
|
|
* mic bias setting (by Kim.Berts@fisub.mail.abb.com) */
|
2617 |
|
|
s->ctrl = CTRL_CDC_EN | (DAC2_SRTODIV(8000) << CTRL_SH_PCLKDIV) | (1 << CTRL_SH_WTSRSEL);
|
2618 |
|
|
s->gameport.io = 0;
|
2619 |
|
|
if (joystick[devindex]) {
|
2620 |
|
|
if (!request_region(0x200, JOY_EXTENT, "es1370"))
|
2621 |
|
|
printk(KERN_ERR "es1370: joystick io port 0x200 in use\n");
|
2622 |
|
|
else {
|
2623 |
|
|
s->ctrl |= CTRL_JYSTK_EN;
|
2624 |
|
|
s->gameport.io = 0x200;
|
2625 |
|
|
}
|
2626 |
|
|
}
|
2627 |
|
|
if (lineout[devindex])
|
2628 |
|
|
s->ctrl |= CTRL_XCTL0;
|
2629 |
|
|
if (micbias[devindex])
|
2630 |
|
|
s->ctrl |= CTRL_XCTL1;
|
2631 |
|
|
s->sctrl = 0;
|
2632 |
|
|
printk(KERN_INFO "es1370: found adapter at io %#lx irq %u\n"
|
2633 |
|
|
KERN_INFO "es1370: features: joystick %s, line %s, mic impedance %s\n",
|
2634 |
|
|
s->io, s->irq, (s->ctrl & CTRL_JYSTK_EN) ? "on" : "off",
|
2635 |
|
|
(s->ctrl & CTRL_XCTL0) ? "out" : "in",
|
2636 |
|
|
(s->ctrl & CTRL_XCTL1) ? "1" : "0");
|
2637 |
|
|
/* register devices */
|
2638 |
|
|
if ((s->dev_audio = register_sound_dsp(&es1370_audio_fops, -1)) < 0) {
|
2639 |
|
|
ret = s->dev_audio;
|
2640 |
|
|
goto err_dev1;
|
2641 |
|
|
}
|
2642 |
|
|
if ((s->dev_mixer = register_sound_mixer(&es1370_mixer_fops, -1)) < 0) {
|
2643 |
|
|
ret = s->dev_mixer;
|
2644 |
|
|
goto err_dev2;
|
2645 |
|
|
}
|
2646 |
|
|
if ((s->dev_dac = register_sound_dsp(&es1370_dac_fops, -1)) < 0) {
|
2647 |
|
|
ret = s->dev_dac;
|
2648 |
|
|
goto err_dev3;
|
2649 |
|
|
}
|
2650 |
|
|
if ((s->dev_midi = register_sound_midi(&es1370_midi_fops, -1)) < 0) {
|
2651 |
|
|
ret = s->dev_midi;
|
2652 |
|
|
goto err_dev4;
|
2653 |
|
|
}
|
2654 |
|
|
/* initialize the chips */
|
2655 |
|
|
outl(s->ctrl, s->io+ES1370_REG_CONTROL);
|
2656 |
|
|
outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
|
2657 |
|
|
/* point phantom write channel to "bugbuf" */
|
2658 |
|
|
outl((ES1370_REG_PHANTOM_FRAMEADR >> 8) & 15, s->io+ES1370_REG_MEMPAGE);
|
2659 |
|
|
outl(virt_to_bus(bugbuf), s->io+(ES1370_REG_PHANTOM_FRAMEADR & 0xff));
|
2660 |
|
|
outl(0, s->io+(ES1370_REG_PHANTOM_FRAMECNT & 0xff));
|
2661 |
|
|
pci_set_master(pcidev); /* enable bus mastering */
|
2662 |
|
|
wrcodec(s, 0x16, 3); /* no RST, PD */
|
2663 |
|
|
wrcodec(s, 0x17, 0); /* CODEC ADC and CODEC DAC use {LR,B}CLK2 and run off the LRCLK2 PLL; program DAC_SYNC=0!! */
|
2664 |
|
|
wrcodec(s, 0x18, 0); /* recording source is mixer */
|
2665 |
|
|
wrcodec(s, 0x19, s->mix.micpreamp = 1); /* turn on MIC preamp */
|
2666 |
|
|
s->mix.imix = 1;
|
2667 |
|
|
fs = get_fs();
|
2668 |
|
|
set_fs(KERNEL_DS);
|
2669 |
|
|
val = SOUND_MASK_LINE|SOUND_MASK_SYNTH|SOUND_MASK_CD;
|
2670 |
|
|
mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long)&val);
|
2671 |
|
|
for (i = 0; i < sizeof(initvol)/sizeof(initvol[0]); i++) {
|
2672 |
|
|
val = initvol[i].vol;
|
2673 |
|
|
mixer_ioctl(s, initvol[i].mixch, (unsigned long)&val);
|
2674 |
|
|
}
|
2675 |
|
|
set_fs(fs);
|
2676 |
|
|
/* register gameport */
|
2677 |
|
|
if(s->gameport.io)
|
2678 |
|
|
gameport_register_port(&s->gameport);
|
2679 |
|
|
|
2680 |
|
|
/* store it in the driver field */
|
2681 |
|
|
pci_set_drvdata(pcidev, s);
|
2682 |
|
|
/* put it into driver list */
|
2683 |
|
|
list_add_tail(&s->devs, &devs);
|
2684 |
|
|
/* increment devindex */
|
2685 |
|
|
if (devindex < NR_DEVICE-1)
|
2686 |
|
|
devindex++;
|
2687 |
|
|
return 0;
|
2688 |
|
|
|
2689 |
|
|
err_dev4:
|
2690 |
|
|
unregister_sound_dsp(s->dev_dac);
|
2691 |
|
|
err_dev3:
|
2692 |
|
|
unregister_sound_mixer(s->dev_mixer);
|
2693 |
|
|
err_dev2:
|
2694 |
|
|
unregister_sound_dsp(s->dev_audio);
|
2695 |
|
|
err_dev1:
|
2696 |
|
|
printk(KERN_ERR "es1370: cannot register misc device\n");
|
2697 |
|
|
free_irq(s->irq, s);
|
2698 |
|
|
if (s->gameport.io)
|
2699 |
|
|
release_region(s->gameport.io, JOY_EXTENT);
|
2700 |
|
|
err_irq:
|
2701 |
|
|
release_region(s->io, ES1370_EXTENT);
|
2702 |
|
|
err_region:
|
2703 |
|
|
kfree(s);
|
2704 |
|
|
return ret;
|
2705 |
|
|
}
|
2706 |
|
|
|
2707 |
|
|
static void __devinit es1370_remove(struct pci_dev *dev)
|
2708 |
|
|
{
|
2709 |
|
|
struct es1370_state *s = pci_get_drvdata(dev);
|
2710 |
|
|
|
2711 |
|
|
if (!s)
|
2712 |
|
|
return;
|
2713 |
|
|
list_del(&s->devs);
|
2714 |
|
|
outl(CTRL_SERR_DIS | (1 << CTRL_SH_WTSRSEL), s->io+ES1370_REG_CONTROL); /* switch everything off */
|
2715 |
|
|
outl(0, s->io+ES1370_REG_SERIAL_CONTROL); /* clear serial interrupts */
|
2716 |
|
|
synchronize_irq();
|
2717 |
|
|
free_irq(s->irq, s);
|
2718 |
|
|
if (s->gameport.io) {
|
2719 |
|
|
gameport_unregister_port(&s->gameport);
|
2720 |
|
|
release_region(s->gameport.io, JOY_EXTENT);
|
2721 |
|
|
}
|
2722 |
|
|
release_region(s->io, ES1370_EXTENT);
|
2723 |
|
|
unregister_sound_dsp(s->dev_audio);
|
2724 |
|
|
unregister_sound_mixer(s->dev_mixer);
|
2725 |
|
|
unregister_sound_dsp(s->dev_dac);
|
2726 |
|
|
unregister_sound_midi(s->dev_midi);
|
2727 |
|
|
kfree(s);
|
2728 |
|
|
pci_set_drvdata(dev, NULL);
|
2729 |
|
|
}
|
2730 |
|
|
|
2731 |
|
|
static struct pci_device_id id_table[] __devinitdata = {
|
2732 |
|
|
{ PCI_VENDOR_ID_ENSONIQ, PCI_DEVICE_ID_ENSONIQ_ES1370, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
|
2733 |
|
|
{ 0, }
|
2734 |
|
|
};
|
2735 |
|
|
|
2736 |
|
|
MODULE_DEVICE_TABLE(pci, id_table);
|
2737 |
|
|
|
2738 |
|
|
static struct pci_driver es1370_driver = {
|
2739 |
|
|
name: "es1370",
|
2740 |
|
|
id_table: id_table,
|
2741 |
|
|
probe: es1370_probe,
|
2742 |
|
|
remove: es1370_remove
|
2743 |
|
|
};
|
2744 |
|
|
|
2745 |
|
|
static int __init init_es1370(void)
|
2746 |
|
|
{
|
2747 |
|
|
if (!pci_present()) /* No PCI bus in this machine! */
|
2748 |
|
|
return -ENODEV;
|
2749 |
|
|
printk(KERN_INFO "es1370: version v0.38 time " __TIME__ " " __DATE__ "\n");
|
2750 |
|
|
return pci_module_init(&es1370_driver);
|
2751 |
|
|
}
|
2752 |
|
|
|
2753 |
|
|
static void __exit cleanup_es1370(void)
|
2754 |
|
|
{
|
2755 |
|
|
printk(KERN_INFO "es1370: unloading\n");
|
2756 |
|
|
pci_unregister_driver(&es1370_driver);
|
2757 |
|
|
if(bugbuf)
|
2758 |
|
|
kfree(bugbuf);
|
2759 |
|
|
}
|
2760 |
|
|
|
2761 |
|
|
module_init(init_es1370);
|
2762 |
|
|
module_exit(cleanup_es1370);
|
2763 |
|
|
|
2764 |
|
|
/* --------------------------------------------------------------------- */
|
2765 |
|
|
|
2766 |
|
|
#ifndef MODULE
|
2767 |
|
|
|
2768 |
|
|
/* format is: es1370=[joystick[,lineout[,micbias]]] */
|
2769 |
|
|
|
2770 |
|
|
static int __init es1370_setup(char *str)
|
2771 |
|
|
{
|
2772 |
|
|
static unsigned __initdata nr_dev = 0;
|
2773 |
|
|
|
2774 |
|
|
if (nr_dev >= NR_DEVICE)
|
2775 |
|
|
return 0;
|
2776 |
|
|
|
2777 |
|
|
(void)
|
2778 |
|
|
( (get_option(&str,&joystick[nr_dev]) == 2)
|
2779 |
|
|
&& (get_option(&str,&lineout [nr_dev]) == 2)
|
2780 |
|
|
&& get_option(&str,&micbias [nr_dev])
|
2781 |
|
|
);
|
2782 |
|
|
|
2783 |
|
|
nr_dev++;
|
2784 |
|
|
return 1;
|
2785 |
|
|
}
|
2786 |
|
|
|
2787 |
|
|
__setup("es1370=", es1370_setup);
|
2788 |
|
|
|
2789 |
|
|
#endif /* MODULE */
|