source: GPL/trunk/alsa-kernel/pci/maestro3.c@ 135

Last change on this file since 135 was 135, checked in by stevenhl, 18 years ago

Get rid of spurious warnings

File size: 104.5 KB
Line 
1/*
2 * Driver for ESS Maestro3/Allegro (ES1988) soundcards.
3 * Copyright (c) 2000 by Zach Brown <zab@zabbo.net>
4 * Takashi Iwai <tiwai@suse.de>
5 *
6 * Most of the hardware init stuffs are based on maestro3 driver for
7 * OSS/Free by Zach Brown. Many thanks to Zach!
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 *
24 * ChangeLog:
25 * Aug. 27, 2001
26 * - Fixed deadlock on capture
27 * - Added Canyon3D-2 support by Rob Riggs <rob@pangalactic.org>
28 *
29 */
30
31#define CARD_NAME "ESS Maestro3/Allegro/Canyon3D-2"
32#define DRIVER_NAME "Maestro3"
33
34#include <sound/driver.h>
35#include <sound/info.h>
36#include <sound/control.h>
37#include <sound/pcm.h>
38#include <sound/ac97_codec.h>
39#define SNDRV_GET_ID
40#include <sound/initval.h>
41
42MODULE_AUTHOR("Zach Brown <zab@zabbo.net>, Takashi Iwai <tiwai@suse.de>");
43MODULE_DESCRIPTION("ESS Maestro3 PCI");
44MODULE_CLASSES("{sound}");
45MODULE_DEVICES("{{ESS,Maestro3 PCI},"
46 "{ESS,ES1988},"
47 "{ESS,Allegro PCI},"
48 "{ESS,Allegro-1 PCI},"
49 "{ESS,Canyon3D-2/LE PCI}}");
50
51static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
52static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
53static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* all enabled */
54static int external_amp[SNDRV_CARDS] = {REPEAT_SNDRV(1)};
55static int amp_gpio[SNDRV_CARDS] = {REPEAT_SNDRV(-1)};
56
57MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
58MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
59MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
60MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
61MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
62MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
63MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
64MODULE_PARM_DESC(enable, "Enable this soundcard.");
65MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
66MODULE_PARM(external_amp, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
67MODULE_PARM_DESC(external_amp, "Enable external amp for " CARD_NAME " soundcard.");
68MODULE_PARM_SYNTAX(external_amp, SNDRV_ENABLED "," SNDRV_BOOLEAN_TRUE_DESC);
69MODULE_PARM(amp_gpio, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
70MODULE_PARM_DESC(amp_gpio, "GPIO pin number for external amp. (default = -1)");
71MODULE_PARM_SYNTAX(amp_gpio, SNDRV_ENABLED);
72
73#define MAX_PLAYBACKS 2
74#define MAX_CAPTURES 1
75#define NR_DSPS (MAX_PLAYBACKS + MAX_CAPTURES)
76
77
78/*
79 * maestro3 registers
80 */
81
82/* Allegro PCI configuration registers */
83#define PCI_LEGACY_AUDIO_CTRL 0x40
84#define SOUND_BLASTER_ENABLE 0x00000001
85#define FM_SYNTHESIS_ENABLE 0x00000002
86#define GAME_PORT_ENABLE 0x00000004
87#define MPU401_IO_ENABLE 0x00000008
88#define MPU401_IRQ_ENABLE 0x00000010
89#define ALIAS_10BIT_IO 0x00000020
90#define SB_DMA_MASK 0x000000C0
91#define SB_DMA_0 0x00000040
92#define SB_DMA_1 0x00000040
93#define SB_DMA_R 0x00000080
94#define SB_DMA_3 0x000000C0
95#define SB_IRQ_MASK 0x00000700
96#define SB_IRQ_5 0x00000000
97#define SB_IRQ_7 0x00000100
98#define SB_IRQ_9 0x00000200
99#define SB_IRQ_10 0x00000300
100#define MIDI_IRQ_MASK 0x00003800
101#define SERIAL_IRQ_ENABLE 0x00004000
102#define DISABLE_LEGACY 0x00008000
103
104#define PCI_ALLEGRO_CONFIG 0x50
105#define SB_ADDR_240 0x00000004
106#define MPU_ADDR_MASK 0x00000018
107#define MPU_ADDR_330 0x00000000
108#define MPU_ADDR_300 0x00000008
109#define MPU_ADDR_320 0x00000010
110#define MPU_ADDR_340 0x00000018
111#define USE_PCI_TIMING 0x00000040
112#define POSTED_WRITE_ENABLE 0x00000080
113#define DMA_POLICY_MASK 0x00000700
114#define DMA_DDMA 0x00000000
115#define DMA_TDMA 0x00000100
116#define DMA_PCPCI 0x00000200
117#define DMA_WBDMA16 0x00000400
118#define DMA_WBDMA4 0x00000500
119#define DMA_WBDMA2 0x00000600
120#define DMA_WBDMA1 0x00000700
121#define DMA_SAFE_GUARD 0x00000800
122#define HI_PERF_GP_ENABLE 0x00001000
123#define PIC_SNOOP_MODE_0 0x00002000
124#define PIC_SNOOP_MODE_1 0x00004000
125#define SOUNDBLASTER_IRQ_MASK 0x00008000
126#define RING_IN_ENABLE 0x00010000
127#define SPDIF_TEST_MODE 0x00020000
128#define CLK_MULT_MODE_SELECT_2 0x00040000
129#define EEPROM_WRITE_ENABLE 0x00080000
130#define CODEC_DIR_IN 0x00100000
131#define HV_BUTTON_FROM_GD 0x00200000
132#define REDUCED_DEBOUNCE 0x00400000
133#define HV_CTRL_ENABLE 0x00800000
134#define SPDIF_ENABLE 0x01000000
135#define CLK_DIV_SELECT 0x06000000
136#define CLK_DIV_BY_48 0x00000000
137#define CLK_DIV_BY_49 0x02000000
138#define CLK_DIV_BY_50 0x04000000
139#define CLK_DIV_RESERVED 0x06000000
140#define PM_CTRL_ENABLE 0x08000000
141#define CLK_MULT_MODE_SELECT 0x30000000
142#define CLK_MULT_MODE_SHIFT 28
143#define CLK_MULT_MODE_0 0x00000000
144#define CLK_MULT_MODE_1 0x10000000
145#define CLK_MULT_MODE_2 0x20000000
146#define CLK_MULT_MODE_3 0x30000000
147#define INT_CLK_SELECT 0x40000000
148#define INT_CLK_MULT_RESET 0x80000000
149
150/* M3 */
151#define INT_CLK_SRC_NOT_PCI 0x00100000
152#define INT_CLK_MULT_ENABLE 0x80000000
153
154#define PCI_ACPI_CONTROL 0x54
155#define PCI_ACPI_D0 0x00000000
156#define PCI_ACPI_D1 0xB4F70000
157#define PCI_ACPI_D2 0xB4F7B4F7
158
159#define PCI_USER_CONFIG 0x58
160#define EXT_PCI_MASTER_ENABLE 0x00000001
161#define SPDIF_OUT_SELECT 0x00000002
162#define TEST_PIN_DIR_CTRL 0x00000004
163#define AC97_CODEC_TEST 0x00000020
164#define TRI_STATE_BUFFER 0x00000080
165#define IN_CLK_12MHZ_SELECT 0x00000100
166#define MULTI_FUNC_DISABLE 0x00000200
167#define EXT_MASTER_PAIR_SEL 0x00000400
168#define PCI_MASTER_SUPPORT 0x00000800
169#define STOP_CLOCK_ENABLE 0x00001000
170#define EAPD_DRIVE_ENABLE 0x00002000
171#define REQ_TRI_STATE_ENABLE 0x00004000
172#define REQ_LOW_ENABLE 0x00008000
173#define MIDI_1_ENABLE 0x00010000
174#define MIDI_2_ENABLE 0x00020000
175#define SB_AUDIO_SYNC 0x00040000
176#define HV_CTRL_TEST 0x00100000
177#define SOUNDBLASTER_TEST 0x00400000
178
179#define PCI_USER_CONFIG_C 0x5C
180
181#define PCI_DDMA_CTRL 0x60
182#define DDMA_ENABLE 0x00000001
183
184
185/* Allegro registers */
186#define HOST_INT_CTRL 0x18
187#define SB_INT_ENABLE 0x0001
188#define MPU401_INT_ENABLE 0x0002
189#define ASSP_INT_ENABLE 0x0010
190#define RING_INT_ENABLE 0x0020
191#define HV_INT_ENABLE 0x0040
192#define CLKRUN_GEN_ENABLE 0x0100
193#define HV_CTRL_TO_PME 0x0400
194#define SOFTWARE_RESET_ENABLE 0x8000
195
196/*
197 * should be using the above defines, probably.
198 */
199#define REGB_ENABLE_RESET 0x01
200#define REGB_STOP_CLOCK 0x10
201
202#define HOST_INT_STATUS 0x1A
203#define SB_INT_PENDING 0x01
204#define MPU401_INT_PENDING 0x02
205#define ASSP_INT_PENDING 0x10
206#define RING_INT_PENDING 0x20
207#define HV_INT_PENDING 0x40
208
209#define HARDWARE_VOL_CTRL 0x1B
210#define SHADOW_MIX_REG_VOICE 0x1C
211#define HW_VOL_COUNTER_VOICE 0x1D
212#define SHADOW_MIX_REG_MASTER 0x1E
213#define HW_VOL_COUNTER_MASTER 0x1F
214
215#define CODEC_COMMAND 0x30
216#define CODEC_READ_B 0x80
217
218#define CODEC_STATUS 0x30
219#define CODEC_BUSY_B 0x01
220
221#define CODEC_DATA 0x32
222
223#define RING_BUS_CTRL_A 0x36
224#define RAC_PME_ENABLE 0x0100
225#define RAC_SDFS_ENABLE 0x0200
226#define LAC_PME_ENABLE 0x0400
227#define LAC_SDFS_ENABLE 0x0800
228#define SERIAL_AC_LINK_ENABLE 0x1000
229#define IO_SRAM_ENABLE 0x2000
230#define IIS_INPUT_ENABLE 0x8000
231
232#define RING_BUS_CTRL_B 0x38
233#define SECOND_CODEC_ID_MASK 0x0003
234#define SPDIF_FUNC_ENABLE 0x0010
235#define SECOND_AC_ENABLE 0x0020
236#define SB_MODULE_INTF_ENABLE 0x0040
237#define SSPE_ENABLE 0x0040
238#define M3I_DOCK_ENABLE 0x0080
239
240#define SDO_OUT_DEST_CTRL 0x3A
241#define COMMAND_ADDR_OUT 0x0003
242#define PCM_LR_OUT_LOCAL 0x0000
243#define PCM_LR_OUT_REMOTE 0x0004
244#define PCM_LR_OUT_MUTE 0x0008
245#define PCM_LR_OUT_BOTH 0x000C
246#define LINE1_DAC_OUT_LOCAL 0x0000
247#define LINE1_DAC_OUT_REMOTE 0x0010
248#define LINE1_DAC_OUT_MUTE 0x0020
249#define LINE1_DAC_OUT_BOTH 0x0030
250#define PCM_CLS_OUT_LOCAL 0x0000
251#define PCM_CLS_OUT_REMOTE 0x0040
252#define PCM_CLS_OUT_MUTE 0x0080
253#define PCM_CLS_OUT_BOTH 0x00C0
254#define PCM_RLF_OUT_LOCAL 0x0000
255#define PCM_RLF_OUT_REMOTE 0x0100
256#define PCM_RLF_OUT_MUTE 0x0200
257#define PCM_RLF_OUT_BOTH 0x0300
258#define LINE2_DAC_OUT_LOCAL 0x0000
259#define LINE2_DAC_OUT_REMOTE 0x0400
260#define LINE2_DAC_OUT_MUTE 0x0800
261#define LINE2_DAC_OUT_BOTH 0x0C00
262#define HANDSET_OUT_LOCAL 0x0000
263#define HANDSET_OUT_REMOTE 0x1000
264#define HANDSET_OUT_MUTE 0x2000
265#define HANDSET_OUT_BOTH 0x3000
266#define IO_CTRL_OUT_LOCAL 0x0000
267#define IO_CTRL_OUT_REMOTE 0x4000
268#define IO_CTRL_OUT_MUTE 0x8000
269#define IO_CTRL_OUT_BOTH 0xC000
270
271#define SDO_IN_DEST_CTRL 0x3C
272#define STATUS_ADDR_IN 0x0003
273#define PCM_LR_IN_LOCAL 0x0000
274#define PCM_LR_IN_REMOTE 0x0004
275#define PCM_LR_RESERVED 0x0008
276#define PCM_LR_IN_BOTH 0x000C
277#define LINE1_ADC_IN_LOCAL 0x0000
278#define LINE1_ADC_IN_REMOTE 0x0010
279#define LINE1_ADC_IN_MUTE 0x0020
280#define MIC_ADC_IN_LOCAL 0x0000
281#define MIC_ADC_IN_REMOTE 0x0040
282#define MIC_ADC_IN_MUTE 0x0080
283#define LINE2_DAC_IN_LOCAL 0x0000
284#define LINE2_DAC_IN_REMOTE 0x0400
285#define LINE2_DAC_IN_MUTE 0x0800
286#define HANDSET_IN_LOCAL 0x0000
287#define HANDSET_IN_REMOTE 0x1000
288#define HANDSET_IN_MUTE 0x2000
289#define IO_STATUS_IN_LOCAL 0x0000
290#define IO_STATUS_IN_REMOTE 0x4000
291
292#define SPDIF_IN_CTRL 0x3E
293#define SPDIF_IN_ENABLE 0x0001
294
295#define GPIO_DATA 0x60
296#define GPIO_DATA_MASK 0x0FFF
297#define GPIO_HV_STATUS 0x3000
298#define GPIO_PME_STATUS 0x4000
299
300#define GPIO_MASK 0x64
301#define GPIO_DIRECTION 0x68
302#define GPO_PRIMARY_AC97 0x0001
303#define GPI_LINEOUT_SENSE 0x0004
304#define GPO_SECONDARY_AC97 0x0008
305#define GPI_VOL_DOWN 0x0010
306#define GPI_VOL_UP 0x0020
307#define GPI_IIS_CLK 0x0040
308#define GPI_IIS_LRCLK 0x0080
309#define GPI_IIS_DATA 0x0100
310#define GPI_DOCKING_STATUS 0x0100
311#define GPI_HEADPHONE_SENSE 0x0200
312#define GPO_EXT_AMP_SHUTDOWN 0x1000
313
314#define GPO_EXT_AMP_M3 1 /* default m3 amp */
315#define GPO_EXT_AMP_ALLEGRO 8 /* default allegro amp */
316
317/* M3 */
318#define GPO_M3_EXT_AMP_SHUTDN 0x0002
319
320#define ASSP_INDEX_PORT 0x80
321#define ASSP_MEMORY_PORT 0x82
322#define ASSP_DATA_PORT 0x84
323
324#define MPU401_DATA_PORT 0x98
325#define MPU401_STATUS_PORT 0x99
326
327#define CLK_MULT_DATA_PORT 0x9C
328
329#define ASSP_CONTROL_A 0xA2
330#define ASSP_0_WS_ENABLE 0x01
331#define ASSP_CTRL_A_RESERVED1 0x02
332#define ASSP_CTRL_A_RESERVED2 0x04
333#define ASSP_CLK_49MHZ_SELECT 0x08
334#define FAST_PLU_ENABLE 0x10
335#define ASSP_CTRL_A_RESERVED3 0x20
336#define DSP_CLK_36MHZ_SELECT 0x40
337
338#define ASSP_CONTROL_B 0xA4
339#define RESET_ASSP 0x00
340#define RUN_ASSP 0x01
341#define ENABLE_ASSP_CLOCK 0x00
342#define STOP_ASSP_CLOCK 0x10
343#define RESET_TOGGLE 0x40
344
345#define ASSP_CONTROL_C 0xA6
346#define ASSP_HOST_INT_ENABLE 0x01
347#define FM_ADDR_REMAP_DISABLE 0x02
348#define HOST_WRITE_PORT_ENABLE 0x08
349
350#define ASSP_HOST_INT_STATUS 0xAC
351#define DSP2HOST_REQ_PIORECORD 0x01
352#define DSP2HOST_REQ_I2SRATE 0x02
353#define DSP2HOST_REQ_TIMER 0x04
354
355/* AC97 registers */
356/* XXX fix this crap up */
357/*#define AC97_RESET 0x00*/
358
359#define AC97_VOL_MUTE_B 0x8000
360#define AC97_VOL_M 0x1F
361#define AC97_LEFT_VOL_S 8
362
363#define AC97_MASTER_VOL 0x02
364#define AC97_LINE_LEVEL_VOL 0x04
365#define AC97_MASTER_MONO_VOL 0x06
366#define AC97_PC_BEEP_VOL 0x0A
367#define AC97_PC_BEEP_VOL_M 0x0F
368#define AC97_SROUND_MASTER_VOL 0x38
369#define AC97_PC_BEEP_VOL_S 1
370
371/*#define AC97_PHONE_VOL 0x0C
372 #define AC97_MIC_VOL 0x0E*/
373#define AC97_MIC_20DB_ENABLE 0x40
374
375/*#define AC97_LINEIN_VOL 0x10
376 #define AC97_CD_VOL 0x12
377 #define AC97_VIDEO_VOL 0x14
378 #define AC97_AUX_VOL 0x16*/
379#define AC97_PCM_OUT_VOL 0x18
380/*#define AC97_RECORD_SELECT 0x1A*/
381#define AC97_RECORD_MIC 0x00
382#define AC97_RECORD_CD 0x01
383#define AC97_RECORD_VIDEO 0x02
384#define AC97_RECORD_AUX 0x03
385#define AC97_RECORD_MONO_MUX 0x02
386#define AC97_RECORD_DIGITAL 0x03
387#define AC97_RECORD_LINE 0x04
388#define AC97_RECORD_STEREO 0x05
389#define AC97_RECORD_MONO 0x06
390#define AC97_RECORD_PHONE 0x07
391
392/*#define AC97_RECORD_GAIN 0x1C*/
393#define AC97_RECORD_VOL_M 0x0F
394
395/*#define AC97_GENERAL_PURPOSE 0x20*/
396#define AC97_POWER_DOWN_CTRL 0x26
397#define AC97_ADC_READY 0x0001
398#define AC97_DAC_READY 0x0002
399#define AC97_ANALOG_READY 0x0004
400#define AC97_VREF_ON 0x0008
401#define AC97_PR0 0x0100
402#define AC97_PR1 0x0200
403#define AC97_PR2 0x0400
404#define AC97_PR3 0x0800
405#define AC97_PR4 0x1000
406
407#define AC97_RESERVED1 0x28
408
409#define AC97_VENDOR_TEST 0x5A
410
411#define AC97_CLOCK_DELAY 0x5C
412#define AC97_LINEOUT_MUX_SEL 0x0001
413#define AC97_MONO_MUX_SEL 0x0002
414#define AC97_CLOCK_DELAY_SEL 0x1F
415#define AC97_DAC_CDS_SHIFT 6
416#define AC97_ADC_CDS_SHIFT 11
417
418#define AC97_MULTI_CHANNEL_SEL 0x74
419
420/*#define AC97_VENDOR_ID1 0x7C
421 #define AC97_VENDOR_ID2 0x7E*/
422
423/*
424 * ASSP control regs
425 */
426#define DSP_PORT_TIMER_COUNT 0x06
427
428#define DSP_PORT_MEMORY_INDEX 0x80
429
430#define DSP_PORT_MEMORY_TYPE 0x82
431#define MEMTYPE_INTERNAL_CODE 0x0002
432#define MEMTYPE_INTERNAL_DATA 0x0003
433#define MEMTYPE_MASK 0x0003
434
435#define DSP_PORT_MEMORY_DATA 0x84
436
437#define DSP_PORT_CONTROL_REG_A 0xA2
438#define DSP_PORT_CONTROL_REG_B 0xA4
439#define DSP_PORT_CONTROL_REG_C 0xA6
440
441#define REV_A_CODE_MEMORY_BEGIN 0x0000
442#define REV_A_CODE_MEMORY_END 0x0FFF
443#define REV_A_CODE_MEMORY_UNIT_LENGTH 0x0040
444#define REV_A_CODE_MEMORY_LENGTH (REV_A_CODE_MEMORY_END - REV_A_CODE_MEMORY_BEGIN + 1)
445
446#define REV_B_CODE_MEMORY_BEGIN 0x0000
447#define REV_B_CODE_MEMORY_END 0x0BFF
448#define REV_B_CODE_MEMORY_UNIT_LENGTH 0x0040
449#define REV_B_CODE_MEMORY_LENGTH (REV_B_CODE_MEMORY_END - REV_B_CODE_MEMORY_BEGIN + 1)
450
451#define REV_A_DATA_MEMORY_BEGIN 0x1000
452#define REV_A_DATA_MEMORY_END 0x2FFF
453#define REV_A_DATA_MEMORY_UNIT_LENGTH 0x0080
454#define REV_A_DATA_MEMORY_LENGTH (REV_A_DATA_MEMORY_END - REV_A_DATA_MEMORY_BEGIN + 1)
455
456#define REV_B_DATA_MEMORY_BEGIN 0x1000
457#define REV_B_DATA_MEMORY_END 0x2BFF
458#define REV_B_DATA_MEMORY_UNIT_LENGTH 0x0080
459#define REV_B_DATA_MEMORY_LENGTH (REV_B_DATA_MEMORY_END - REV_B_DATA_MEMORY_BEGIN + 1)
460
461
462#define NUM_UNITS_KERNEL_CODE 16
463#define NUM_UNITS_KERNEL_DATA 2
464
465#define NUM_UNITS_KERNEL_CODE_WITH_HSP 16
466#define NUM_UNITS_KERNEL_DATA_WITH_HSP 5
467
468/*
469 * Kernel data layout
470 */
471
472#define DP_SHIFT_COUNT 7
473
474#define KDATA_BASE_ADDR 0x1000
475#define KDATA_BASE_ADDR2 0x1080
476
477#define KDATA_TASK0 (KDATA_BASE_ADDR + 0x0000)
478#define KDATA_TASK1 (KDATA_BASE_ADDR + 0x0001)
479#define KDATA_TASK2 (KDATA_BASE_ADDR + 0x0002)
480#define KDATA_TASK3 (KDATA_BASE_ADDR + 0x0003)
481#define KDATA_TASK4 (KDATA_BASE_ADDR + 0x0004)
482#define KDATA_TASK5 (KDATA_BASE_ADDR + 0x0005)
483#define KDATA_TASK6 (KDATA_BASE_ADDR + 0x0006)
484#define KDATA_TASK7 (KDATA_BASE_ADDR + 0x0007)
485#define KDATA_TASK_ENDMARK (KDATA_BASE_ADDR + 0x0008)
486
487#define KDATA_CURRENT_TASK (KDATA_BASE_ADDR + 0x0009)
488#define KDATA_TASK_SWITCH (KDATA_BASE_ADDR + 0x000A)
489
490#define KDATA_INSTANCE0_POS3D (KDATA_BASE_ADDR + 0x000B)
491#define KDATA_INSTANCE1_POS3D (KDATA_BASE_ADDR + 0x000C)
492#define KDATA_INSTANCE2_POS3D (KDATA_BASE_ADDR + 0x000D)
493#define KDATA_INSTANCE3_POS3D (KDATA_BASE_ADDR + 0x000E)
494#define KDATA_INSTANCE4_POS3D (KDATA_BASE_ADDR + 0x000F)
495#define KDATA_INSTANCE5_POS3D (KDATA_BASE_ADDR + 0x0010)
496#define KDATA_INSTANCE6_POS3D (KDATA_BASE_ADDR + 0x0011)
497#define KDATA_INSTANCE7_POS3D (KDATA_BASE_ADDR + 0x0012)
498#define KDATA_INSTANCE8_POS3D (KDATA_BASE_ADDR + 0x0013)
499#define KDATA_INSTANCE_POS3D_ENDMARK (KDATA_BASE_ADDR + 0x0014)
500
501#define KDATA_INSTANCE0_SPKVIRT (KDATA_BASE_ADDR + 0x0015)
502#define KDATA_INSTANCE_SPKVIRT_ENDMARK (KDATA_BASE_ADDR + 0x0016)
503
504#define KDATA_INSTANCE0_SPDIF (KDATA_BASE_ADDR + 0x0017)
505#define KDATA_INSTANCE_SPDIF_ENDMARK (KDATA_BASE_ADDR + 0x0018)
506
507#define KDATA_INSTANCE0_MODEM (KDATA_BASE_ADDR + 0x0019)
508#define KDATA_INSTANCE_MODEM_ENDMARK (KDATA_BASE_ADDR + 0x001A)
509
510#define KDATA_INSTANCE0_SRC (KDATA_BASE_ADDR + 0x001B)
511#define KDATA_INSTANCE1_SRC (KDATA_BASE_ADDR + 0x001C)
512#define KDATA_INSTANCE_SRC_ENDMARK (KDATA_BASE_ADDR + 0x001D)
513
514#define KDATA_INSTANCE0_MINISRC (KDATA_BASE_ADDR + 0x001E)
515#define KDATA_INSTANCE1_MINISRC (KDATA_BASE_ADDR + 0x001F)
516#define KDATA_INSTANCE2_MINISRC (KDATA_BASE_ADDR + 0x0020)
517#define KDATA_INSTANCE3_MINISRC (KDATA_BASE_ADDR + 0x0021)
518#define KDATA_INSTANCE_MINISRC_ENDMARK (KDATA_BASE_ADDR + 0x0022)
519
520#define KDATA_INSTANCE0_CPYTHRU (KDATA_BASE_ADDR + 0x0023)
521#define KDATA_INSTANCE1_CPYTHRU (KDATA_BASE_ADDR + 0x0024)
522#define KDATA_INSTANCE_CPYTHRU_ENDMARK (KDATA_BASE_ADDR + 0x0025)
523
524#define KDATA_CURRENT_DMA (KDATA_BASE_ADDR + 0x0026)
525#define KDATA_DMA_SWITCH (KDATA_BASE_ADDR + 0x0027)
526#define KDATA_DMA_ACTIVE (KDATA_BASE_ADDR + 0x0028)
527
528#define KDATA_DMA_XFER0 (KDATA_BASE_ADDR + 0x0029)
529#define KDATA_DMA_XFER1 (KDATA_BASE_ADDR + 0x002A)
530#define KDATA_DMA_XFER2 (KDATA_BASE_ADDR + 0x002B)
531#define KDATA_DMA_XFER3 (KDATA_BASE_ADDR + 0x002C)
532#define KDATA_DMA_XFER4 (KDATA_BASE_ADDR + 0x002D)
533#define KDATA_DMA_XFER5 (KDATA_BASE_ADDR + 0x002E)
534#define KDATA_DMA_XFER6 (KDATA_BASE_ADDR + 0x002F)
535#define KDATA_DMA_XFER7 (KDATA_BASE_ADDR + 0x0030)
536#define KDATA_DMA_XFER8 (KDATA_BASE_ADDR + 0x0031)
537#define KDATA_DMA_XFER_ENDMARK (KDATA_BASE_ADDR + 0x0032)
538
539#define KDATA_I2S_SAMPLE_COUNT (KDATA_BASE_ADDR + 0x0033)
540#define KDATA_I2S_INT_METER (KDATA_BASE_ADDR + 0x0034)
541#define KDATA_I2S_ACTIVE (KDATA_BASE_ADDR + 0x0035)
542
543#define KDATA_TIMER_COUNT_RELOAD (KDATA_BASE_ADDR + 0x0036)
544#define KDATA_TIMER_COUNT_CURRENT (KDATA_BASE_ADDR + 0x0037)
545
546#define KDATA_HALT_SYNCH_CLIENT (KDATA_BASE_ADDR + 0x0038)
547#define KDATA_HALT_SYNCH_DMA (KDATA_BASE_ADDR + 0x0039)
548#define KDATA_HALT_ACKNOWLEDGE (KDATA_BASE_ADDR + 0x003A)
549
550#define KDATA_ADC1_XFER0 (KDATA_BASE_ADDR + 0x003B)
551#define KDATA_ADC1_XFER_ENDMARK (KDATA_BASE_ADDR + 0x003C)
552#define KDATA_ADC1_LEFT_VOLUME (KDATA_BASE_ADDR + 0x003D)
553#define KDATA_ADC1_RIGHT_VOLUME (KDATA_BASE_ADDR + 0x003E)
554#define KDATA_ADC1_LEFT_SUR_VOL (KDATA_BASE_ADDR + 0x003F)
555#define KDATA_ADC1_RIGHT_SUR_VOL (KDATA_BASE_ADDR + 0x0040)
556
557#define KDATA_ADC2_XFER0 (KDATA_BASE_ADDR + 0x0041)
558#define KDATA_ADC2_XFER_ENDMARK (KDATA_BASE_ADDR + 0x0042)
559#define KDATA_ADC2_LEFT_VOLUME (KDATA_BASE_ADDR + 0x0043)
560#define KDATA_ADC2_RIGHT_VOLUME (KDATA_BASE_ADDR + 0x0044)
561#define KDATA_ADC2_LEFT_SUR_VOL (KDATA_BASE_ADDR + 0x0045)
562#define KDATA_ADC2_RIGHT_SUR_VOL (KDATA_BASE_ADDR + 0x0046)
563
564#define KDATA_CD_XFER0 (KDATA_BASE_ADDR + 0x0047)
565#define KDATA_CD_XFER_ENDMARK (KDATA_BASE_ADDR + 0x0048)
566#define KDATA_CD_LEFT_VOLUME (KDATA_BASE_ADDR + 0x0049)
567#define KDATA_CD_RIGHT_VOLUME (KDATA_BASE_ADDR + 0x004A)
568#define KDATA_CD_LEFT_SUR_VOL (KDATA_BASE_ADDR + 0x004B)
569#define KDATA_CD_RIGHT_SUR_VOL (KDATA_BASE_ADDR + 0x004C)
570
571#define KDATA_MIC_XFER0 (KDATA_BASE_ADDR + 0x004D)
572#define KDATA_MIC_XFER_ENDMARK (KDATA_BASE_ADDR + 0x004E)
573#define KDATA_MIC_VOLUME (KDATA_BASE_ADDR + 0x004F)
574#define KDATA_MIC_SUR_VOL (KDATA_BASE_ADDR + 0x0050)
575
576#define KDATA_I2S_XFER0 (KDATA_BASE_ADDR + 0x0051)
577#define KDATA_I2S_XFER_ENDMARK (KDATA_BASE_ADDR + 0x0052)
578
579#define KDATA_CHI_XFER0 (KDATA_BASE_ADDR + 0x0053)
580#define KDATA_CHI_XFER_ENDMARK (KDATA_BASE_ADDR + 0x0054)
581
582#define KDATA_SPDIF_XFER (KDATA_BASE_ADDR + 0x0055)
583#define KDATA_SPDIF_CURRENT_FRAME (KDATA_BASE_ADDR + 0x0056)
584#define KDATA_SPDIF_FRAME0 (KDATA_BASE_ADDR + 0x0057)
585#define KDATA_SPDIF_FRAME1 (KDATA_BASE_ADDR + 0x0058)
586#define KDATA_SPDIF_FRAME2 (KDATA_BASE_ADDR + 0x0059)
587
588#define KDATA_SPDIF_REQUEST (KDATA_BASE_ADDR + 0x005A)
589#define KDATA_SPDIF_TEMP (KDATA_BASE_ADDR + 0x005B)
590
591#define KDATA_SPDIFIN_XFER0 (KDATA_BASE_ADDR + 0x005C)
592#define KDATA_SPDIFIN_XFER_ENDMARK (KDATA_BASE_ADDR + 0x005D)
593#define KDATA_SPDIFIN_INT_METER (KDATA_BASE_ADDR + 0x005E)
594
595#define KDATA_DSP_RESET_COUNT (KDATA_BASE_ADDR + 0x005F)
596#define KDATA_DEBUG_OUTPUT (KDATA_BASE_ADDR + 0x0060)
597
598#define KDATA_KERNEL_ISR_LIST (KDATA_BASE_ADDR + 0x0061)
599
600#define KDATA_KERNEL_ISR_CBSR1 (KDATA_BASE_ADDR + 0x0062)
601#define KDATA_KERNEL_ISR_CBER1 (KDATA_BASE_ADDR + 0x0063)
602#define KDATA_KERNEL_ISR_CBCR (KDATA_BASE_ADDR + 0x0064)
603#define KDATA_KERNEL_ISR_AR0 (KDATA_BASE_ADDR + 0x0065)
604#define KDATA_KERNEL_ISR_AR1 (KDATA_BASE_ADDR + 0x0066)
605#define KDATA_KERNEL_ISR_AR2 (KDATA_BASE_ADDR + 0x0067)
606#define KDATA_KERNEL_ISR_AR3 (KDATA_BASE_ADDR + 0x0068)
607#define KDATA_KERNEL_ISR_AR4 (KDATA_BASE_ADDR + 0x0069)
608#define KDATA_KERNEL_ISR_AR5 (KDATA_BASE_ADDR + 0x006A)
609#define KDATA_KERNEL_ISR_BRCR (KDATA_BASE_ADDR + 0x006B)
610#define KDATA_KERNEL_ISR_PASR (KDATA_BASE_ADDR + 0x006C)
611#define KDATA_KERNEL_ISR_PAER (KDATA_BASE_ADDR + 0x006D)
612
613#define KDATA_CLIENT_SCRATCH0 (KDATA_BASE_ADDR + 0x006E)
614#define KDATA_CLIENT_SCRATCH1 (KDATA_BASE_ADDR + 0x006F)
615#define KDATA_KERNEL_SCRATCH (KDATA_BASE_ADDR + 0x0070)
616#define KDATA_KERNEL_ISR_SCRATCH (KDATA_BASE_ADDR + 0x0071)
617
618#define KDATA_OUEUE_LEFT (KDATA_BASE_ADDR + 0x0072)
619#define KDATA_QUEUE_RIGHT (KDATA_BASE_ADDR + 0x0073)
620
621#define KDATA_ADC1_REQUEST (KDATA_BASE_ADDR + 0x0074)
622#define KDATA_ADC2_REQUEST (KDATA_BASE_ADDR + 0x0075)
623#define KDATA_CD_REQUEST (KDATA_BASE_ADDR + 0x0076)
624#define KDATA_MIC_REQUEST (KDATA_BASE_ADDR + 0x0077)
625
626#define KDATA_ADC1_MIXER_REQUEST (KDATA_BASE_ADDR + 0x0078)
627#define KDATA_ADC2_MIXER_REQUEST (KDATA_BASE_ADDR + 0x0079)
628#define KDATA_CD_MIXER_REQUEST (KDATA_BASE_ADDR + 0x007A)
629#define KDATA_MIC_MIXER_REQUEST (KDATA_BASE_ADDR + 0x007B)
630#define KDATA_MIC_SYNC_COUNTER (KDATA_BASE_ADDR + 0x007C)
631
632/*
633 * second 'segment' (?) reserved for mixer
634 * buffers..
635 */
636
637#define KDATA_MIXER_WORD0 (KDATA_BASE_ADDR2 + 0x0000)
638#define KDATA_MIXER_WORD1 (KDATA_BASE_ADDR2 + 0x0001)
639#define KDATA_MIXER_WORD2 (KDATA_BASE_ADDR2 + 0x0002)
640#define KDATA_MIXER_WORD3 (KDATA_BASE_ADDR2 + 0x0003)
641#define KDATA_MIXER_WORD4 (KDATA_BASE_ADDR2 + 0x0004)
642#define KDATA_MIXER_WORD5 (KDATA_BASE_ADDR2 + 0x0005)
643#define KDATA_MIXER_WORD6 (KDATA_BASE_ADDR2 + 0x0006)
644#define KDATA_MIXER_WORD7 (KDATA_BASE_ADDR2 + 0x0007)
645#define KDATA_MIXER_WORD8 (KDATA_BASE_ADDR2 + 0x0008)
646#define KDATA_MIXER_WORD9 (KDATA_BASE_ADDR2 + 0x0009)
647#define KDATA_MIXER_WORDA (KDATA_BASE_ADDR2 + 0x000A)
648#define KDATA_MIXER_WORDB (KDATA_BASE_ADDR2 + 0x000B)
649#define KDATA_MIXER_WORDC (KDATA_BASE_ADDR2 + 0x000C)
650#define KDATA_MIXER_WORDD (KDATA_BASE_ADDR2 + 0x000D)
651#define KDATA_MIXER_WORDE (KDATA_BASE_ADDR2 + 0x000E)
652#define KDATA_MIXER_WORDF (KDATA_BASE_ADDR2 + 0x000F)
653
654#define KDATA_MIXER_XFER0 (KDATA_BASE_ADDR2 + 0x0010)
655#define KDATA_MIXER_XFER1 (KDATA_BASE_ADDR2 + 0x0011)
656#define KDATA_MIXER_XFER2 (KDATA_BASE_ADDR2 + 0x0012)
657#define KDATA_MIXER_XFER3 (KDATA_BASE_ADDR2 + 0x0013)
658#define KDATA_MIXER_XFER4 (KDATA_BASE_ADDR2 + 0x0014)
659#define KDATA_MIXER_XFER5 (KDATA_BASE_ADDR2 + 0x0015)
660#define KDATA_MIXER_XFER6 (KDATA_BASE_ADDR2 + 0x0016)
661#define KDATA_MIXER_XFER7 (KDATA_BASE_ADDR2 + 0x0017)
662#define KDATA_MIXER_XFER8 (KDATA_BASE_ADDR2 + 0x0018)
663#define KDATA_MIXER_XFER9 (KDATA_BASE_ADDR2 + 0x0019)
664#define KDATA_MIXER_XFER_ENDMARK (KDATA_BASE_ADDR2 + 0x001A)
665
666#define KDATA_MIXER_TASK_NUMBER (KDATA_BASE_ADDR2 + 0x001B)
667#define KDATA_CURRENT_MIXER (KDATA_BASE_ADDR2 + 0x001C)
668#define KDATA_MIXER_ACTIVE (KDATA_BASE_ADDR2 + 0x001D)
669#define KDATA_MIXER_BANK_STATUS (KDATA_BASE_ADDR2 + 0x001E)
670#define KDATA_DAC_LEFT_VOLUME (KDATA_BASE_ADDR2 + 0x001F)
671#define KDATA_DAC_RIGHT_VOLUME (KDATA_BASE_ADDR2 + 0x0020)
672
673#define MAX_INSTANCE_MINISRC (KDATA_INSTANCE_MINISRC_ENDMARK - KDATA_INSTANCE0_MINISRC)
674#define MAX_VIRTUAL_DMA_CHANNELS (KDATA_DMA_XFER_ENDMARK - KDATA_DMA_XFER0)
675#define MAX_VIRTUAL_MIXER_CHANNELS (KDATA_MIXER_XFER_ENDMARK - KDATA_MIXER_XFER0)
676#define MAX_VIRTUAL_ADC1_CHANNELS (KDATA_ADC1_XFER_ENDMARK - KDATA_ADC1_XFER0)
677
678/*
679 * client data area offsets
680 */
681#define CDATA_INSTANCE_READY 0x00
682
683#define CDATA_HOST_SRC_ADDRL 0x01
684#define CDATA_HOST_SRC_ADDRH 0x02
685#define CDATA_HOST_SRC_END_PLUS_1L 0x03
686#define CDATA_HOST_SRC_END_PLUS_1H 0x04
687#define CDATA_HOST_SRC_CURRENTL 0x05
688#define CDATA_HOST_SRC_CURRENTH 0x06
689
690#define CDATA_IN_BUF_CONNECT 0x07
691#define CDATA_OUT_BUF_CONNECT 0x08
692
693#define CDATA_IN_BUF_BEGIN 0x09
694#define CDATA_IN_BUF_END_PLUS_1 0x0A
695#define CDATA_IN_BUF_HEAD 0x0B
696#define CDATA_IN_BUF_TAIL 0x0C
697#define CDATA_OUT_BUF_BEGIN 0x0D
698#define CDATA_OUT_BUF_END_PLUS_1 0x0E
699#define CDATA_OUT_BUF_HEAD 0x0F
700#define CDATA_OUT_BUF_TAIL 0x10
701
702#define CDATA_DMA_CONTROL 0x11
703#define CDATA_RESERVED 0x12
704
705#define CDATA_FREQUENCY 0x13
706#define CDATA_LEFT_VOLUME 0x14
707#define CDATA_RIGHT_VOLUME 0x15
708#define CDATA_LEFT_SUR_VOL 0x16
709#define CDATA_RIGHT_SUR_VOL 0x17
710
711#define CDATA_HEADER_LEN 0x18
712
713#define SRC3_DIRECTION_OFFSET CDATA_HEADER_LEN
714#define SRC3_MODE_OFFSET (CDATA_HEADER_LEN + 1)
715#define SRC3_WORD_LENGTH_OFFSET (CDATA_HEADER_LEN + 2)
716#define SRC3_PARAMETER_OFFSET (CDATA_HEADER_LEN + 3)
717#define SRC3_COEFF_ADDR_OFFSET (CDATA_HEADER_LEN + 8)
718#define SRC3_FILTAP_ADDR_OFFSET (CDATA_HEADER_LEN + 10)
719#define SRC3_TEMP_INBUF_ADDR_OFFSET (CDATA_HEADER_LEN + 16)
720#define SRC3_TEMP_OUTBUF_ADDR_OFFSET (CDATA_HEADER_LEN + 17)
721
722#define MINISRC_IN_BUFFER_SIZE ( 0x50 * 2 )
723#define MINISRC_OUT_BUFFER_SIZE ( 0x50 * 2 * 2)
724#define MINISRC_OUT_BUFFER_SIZE ( 0x50 * 2 * 2)
725#define MINISRC_TMP_BUFFER_SIZE ( 112 + ( MINISRC_BIQUAD_STAGE * 3 + 4 ) * 2 * 2 )
726#define MINISRC_BIQUAD_STAGE 2
727#define MINISRC_COEF_LOC 0x175
728
729#define DMACONTROL_BLOCK_MASK 0x000F
730#define DMAC_BLOCK0_SELECTOR 0x0000
731#define DMAC_BLOCK1_SELECTOR 0x0001
732#define DMAC_BLOCK2_SELECTOR 0x0002
733#define DMAC_BLOCK3_SELECTOR 0x0003
734#define DMAC_BLOCK4_SELECTOR 0x0004
735#define DMAC_BLOCK5_SELECTOR 0x0005
736#define DMAC_BLOCK6_SELECTOR 0x0006
737#define DMAC_BLOCK7_SELECTOR 0x0007
738#define DMAC_BLOCK8_SELECTOR 0x0008
739#define DMAC_BLOCK9_SELECTOR 0x0009
740#define DMAC_BLOCKA_SELECTOR 0x000A
741#define DMAC_BLOCKB_SELECTOR 0x000B
742#define DMAC_BLOCKC_SELECTOR 0x000C
743#define DMAC_BLOCKD_SELECTOR 0x000D
744#define DMAC_BLOCKE_SELECTOR 0x000E
745#define DMAC_BLOCKF_SELECTOR 0x000F
746#define DMACONTROL_PAGE_MASK 0x00F0
747#define DMAC_PAGE0_SELECTOR 0x0030
748#define DMAC_PAGE1_SELECTOR 0x0020
749#define DMAC_PAGE2_SELECTOR 0x0010
750#define DMAC_PAGE3_SELECTOR 0x0000
751#define DMACONTROL_AUTOREPEAT 0x1000
752#define DMACONTROL_STOPPED 0x2000
753#define DMACONTROL_DIRECTION 0x0100
754
755/*
756 * an arbitrary volume we set the internal
757 * volume settings to so that the ac97 volume
758 * range is a little less insane. 0x7fff is
759 * max.
760 */
761#define ARB_VOLUME ( 0x6800 )
762
763/*
764 */
765
766typedef struct snd_m3_dma m3_dma_t;
767typedef struct snd_m3 m3_t;
768
769/* quirk lists */
770struct m3_quirk {
771 const char *name; /* device name */
772 u16 vendor, device; /* subsystem ids */
773 int amp_gpio; /* gpio pin # for external amp, -1 = default */
774 int irda_workaround; /* non-zero if avoid to touch 0x10 on GPIO_DIRECTION
775 (e.g. for IrDA on Dell Inspirons) */
776};
777
778struct m3_hv_quirk {
779 u16 vendor, device, subsystem_vendor, subsystem_device;
780 u32 config; /* ALLEGRO_CONFIG hardware volume bits */
781 int is_omnibook; /* Do HP OmniBook GPIO magic? */
782};
783
784struct m3_list {
785 int curlen;
786 int mem_addr;
787 int max;
788};
789
790struct snd_m3_dma {
791
792 int number;
793 m3_t *chip;
794 snd_pcm_substream_t *substream;
795
796 struct assp_instance {
797 unsigned short code, data;
798 } inst;
799
800 int running;
801 int opened;
802
803 unsigned long buffer_addr;
804 int dma_size;
805 int period_size;
806 unsigned int hwptr;
807 int count;
808
809 int index[3];
810 struct m3_list *index_list[3];
811
812 int in_lists;
813
814 struct list_head list;
815
816};
817
818struct snd_m3 {
819
820 snd_card_t *card;
821
822 unsigned long iobase;
823
824 int irq;
825 unsigned int allegro_flag: 1;
826
827 ac97_t *ac97;
828
829 snd_pcm_t *pcm;
830
831 struct pci_dev *pci;
832 const struct m3_quirk *quirk;
833 const struct m3_hv_quirk *hv_quirk;
834
835 int dacs_active;
836 int timer_users;
837
838 struct m3_list msrc_list;
839 struct m3_list mixer_list;
840 struct m3_list adc1_list;
841 struct m3_list dma_list;
842
843 /* for storing reset state..*/
844 u8 reset_state;
845
846 int external_amp;
847 int amp_gpio;
848
849 /* midi */
850 snd_rawmidi_t *rmidi;
851
852 /* pcm streams */
853 int num_substreams;
854 m3_dma_t *substreams;
855
856 spinlock_t reg_lock;
857 spinlock_t ac97_lock;
858
859 snd_kcontrol_t *master_switch;
860 snd_kcontrol_t *master_volume;
861 struct tasklet_struct hwvol_tq;
862#ifdef CONFIG_PM
863 u16 *suspend_mem;
864#endif
865};
866
867/*
868 * pci ids
869 */
870
871#ifndef PCI_VENDOR_ID_ESS
872#define PCI_VENDOR_ID_ESS 0x125D
873#endif
874#ifndef PCI_DEVICE_ID_ESS_ALLEGRO_1
875#define PCI_DEVICE_ID_ESS_ALLEGRO_1 0x1988
876#endif
877#ifndef PCI_DEVICE_ID_ESS_ALLEGRO
878#define PCI_DEVICE_ID_ESS_ALLEGRO 0x1989
879#endif
880#ifndef PCI_DEVICE_ID_ESS_CANYON3D_2LE
881#define PCI_DEVICE_ID_ESS_CANYON3D_2LE 0x1990
882#endif
883#ifndef PCI_DEVICE_ID_ESS_CANYON3D_2
884#define PCI_DEVICE_ID_ESS_CANYON3D_2 0x1992
885#endif
886#ifndef PCI_DEVICE_ID_ESS_MAESTRO3
887#define PCI_DEVICE_ID_ESS_MAESTRO3 0x1998
888#endif
889#ifndef PCI_DEVICE_ID_ESS_MAESTRO3_1
890#define PCI_DEVICE_ID_ESS_MAESTRO3_1 0x1999
891#endif
892#ifndef PCI_DEVICE_ID_ESS_MAESTRO3_HW
893#define PCI_DEVICE_ID_ESS_MAESTRO3_HW 0x199a
894#endif
895#ifndef PCI_DEVICE_ID_ESS_MAESTRO3_2
896#define PCI_DEVICE_ID_ESS_MAESTRO3_2 0x199b
897#endif
898
899static struct pci_device_id snd_m3_ids[] = {
900 {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ALLEGRO_1, PCI_ANY_ID, PCI_ANY_ID,
901 PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
902 // {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ALLEGRO, PCI_ANY_ID, PCI_ANY_ID,
903 // PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
904 {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_CANYON3D_2LE, PCI_ANY_ID, PCI_ANY_ID,
905 PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
906 {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_CANYON3D_2, PCI_ANY_ID, PCI_ANY_ID,
907 PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
908 {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_MAESTRO3, PCI_ANY_ID, PCI_ANY_ID,
909 PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
910 {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_MAESTRO3_1, PCI_ANY_ID, PCI_ANY_ID,
911 PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
912 {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_MAESTRO3_HW, PCI_ANY_ID, PCI_ANY_ID,
913 PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
914 {PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_MAESTRO3_2, PCI_ANY_ID, PCI_ANY_ID,
915 PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0},
916 {0,},
917};
918
919MODULE_DEVICE_TABLE(pci, snd_m3_ids);
920
921static const struct m3_quirk m3_quirk_list[] = {
922 /* panasonic CF-28 "toughbook" */
923 {
924 .name = "Panasonic CF-28",
925 .vendor = 0x10f7,
926 .device = 0x833e,
927 .amp_gpio = 0x0d,
928 },
929 /* panasonic CF-72 "toughbook" */
930 {
931 .name = "Panasonic CF-72",
932 .vendor = 0x10f7,
933 .device = 0x833d,
934 .amp_gpio = 0x0d,
935 },
936 /* Dell Inspiron 4000 */
937 {
938 .name = "Dell Inspiron 4000",
939 .vendor = 0x1028,
940 .device = 0x00b0,
941 .amp_gpio = -1,
942 .irda_workaround = 1,
943 },
944 /* Dell Inspiron 8000 */
945 {
946 .name = "Dell Inspiron 8000",
947 .vendor = 0x1028,
948 .device = 0x00a4,
949 .amp_gpio = -1,
950 .irda_workaround = 1,
951 },
952 /* Dell Inspiron 8100 */
953 {
954 .name = "Dell Inspiron 8100",
955 .vendor = 0x1028,
956 .device = 0x00e6,
957 .amp_gpio = -1,
958 .irda_workaround = 1,
959 },
960 /* NEC LM800J/7 */
961 {
962 .name = "NEC LM800J/7",
963 .vendor = 0x1033,
964 .device = 0x80f1,
965 .amp_gpio = 0x03,
966 },
967 /* LEGEND ZhaoYang 3100CF */
968 {
969 .name = "LEGEND ZhaoYang 3100CF",
970 .vendor = 0x1509,
971 .device = 0x1740,
972 .amp_gpio = 0x03,
973 },
974 /* END */
975 { NULL }
976};
977
978/* These values came from the Windows driver. */
979static const struct m3_hv_quirk m3_hv_quirk_list[] = {
980 /* Allegro chips */
981 { 0x125D, 0x1988, 0x0E11, 0x002E, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
982 { 0x125D, 0x1988, 0x0E11, 0x0094, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
983 { 0x125D, 0x1988, 0x0E11, 0xB112, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
984 { 0x125D, 0x1988, 0x0E11, 0xB114, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
985 { 0x125D, 0x1988, 0x103C, 0x0012, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
986 { 0x125D, 0x1988, 0x103C, 0x0018, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
987 { 0x125D, 0x1988, 0x103C, 0x001C, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
988 { 0x125D, 0x1988, 0x103C, 0x001D, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
989 { 0x125D, 0x1988, 0x103C, 0x001E, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
990 { 0x125D, 0x1988, 0x107B, 0x3350, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
991 { 0x125D, 0x1988, 0x10F7, 0x8338, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
992 { 0x125D, 0x1988, 0x10F7, 0x833C, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
993 { 0x125D, 0x1988, 0x10F7, 0x833D, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
994 { 0x125D, 0x1988, 0x10F7, 0x833E, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
995 { 0x125D, 0x1988, 0x10F7, 0x833F, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
996 { 0x125D, 0x1988, 0x13BD, 0x1018, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
997 { 0x125D, 0x1988, 0x13BD, 0x1019, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
998 { 0x125D, 0x1988, 0x13BD, 0x101A, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
999 { 0x125D, 0x1988, 0x14FF, 0x0F03, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
1000 { 0x125D, 0x1988, 0x14FF, 0x0F04, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
1001 { 0x125D, 0x1988, 0x14FF, 0x0F05, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
1002 { 0x125D, 0x1988, 0x156D, 0xB400, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
1003 { 0x125D, 0x1988, 0x156D, 0xB795, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
1004 { 0x125D, 0x1988, 0x156D, 0xB797, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
1005 { 0x125D, 0x1988, 0x156D, 0xC700, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 },
1006 { 0x125D, 0x1988, 0x1033, 0x80F1, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE, 0 },
1007 { 0x125D, 0x1988, 0x103C, 0x001A, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE, 0 }, /* HP OmniBook 6100 */
1008 { 0x125D, 0x1988, 0x107B, 0x340A, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE, 0 },
1009 { 0x125D, 0x1988, 0x107B, 0x3450, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE, 0 },
1010 { 0x125D, 0x1988, 0x109F, 0x3134, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE, 0 },
1011 { 0x125D, 0x1988, 0x109F, 0x3161, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE, 0 },
1012 { 0x125D, 0x1988, 0x144D, 0x3280, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE, 0 },
1013 { 0x125D, 0x1988, 0x144D, 0x3281, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE, 0 },
1014 { 0x125D, 0x1988, 0x144D, 0xC002, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE, 0 },
1015 { 0x125D, 0x1988, 0x144D, 0xC003, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE, 0 },
1016 { 0x125D, 0x1988, 0x1509, 0x1740, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE, 0 },
1017 { 0x125D, 0x1988, 0x1610, 0x0010, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD | REDUCED_DEBOUNCE, 0 },
1018 { 0x125D, 0x1988, 0x1042, 0x1042, HV_CTRL_ENABLE, 0 },
1019 { 0x125D, 0x1988, 0x107B, 0x9500, HV_CTRL_ENABLE, 0 },
1020 { 0x125D, 0x1988, 0x14FF, 0x0F06, HV_CTRL_ENABLE, 0 },
1021 { 0x125D, 0x1988, 0x1558, 0x8586, HV_CTRL_ENABLE, 0 },
1022 { 0x125D, 0x1988, 0x161F, 0x2011, HV_CTRL_ENABLE, 0 },
1023 /* Maestro3 chips */
1024 { 0x125D, 0x1998, 0x103C, 0x000E, HV_CTRL_ENABLE, 0 },
1025 { 0x125D, 0x1998, 0x103C, 0x0010, HV_CTRL_ENABLE, 1 }, /* HP OmniBook 6000 */
1026 { 0x125D, 0x1998, 0x103C, 0x0011, HV_CTRL_ENABLE, 1 }, /* HP OmniBook 500 */
1027 { 0x125D, 0x1998, 0x103C, 0x001B, HV_CTRL_ENABLE, 0 },
1028 { 0x125D, 0x1998, 0x104D, 0x80A6, HV_CTRL_ENABLE, 0 },
1029 { 0x125D, 0x1998, 0x104D, 0x80AA, HV_CTRL_ENABLE, 0 },
1030 { 0x125D, 0x1998, 0x107B, 0x5300, HV_CTRL_ENABLE, 0 },
1031 { 0x125D, 0x1998, 0x110A, 0x1998, HV_CTRL_ENABLE, 0 },
1032 { 0x125D, 0x1998, 0x13BD, 0x1015, HV_CTRL_ENABLE, 0 },
1033 { 0x125D, 0x1998, 0x13BD, 0x101C, HV_CTRL_ENABLE, 0 },
1034 { 0x125D, 0x1998, 0x13BD, 0x1802, HV_CTRL_ENABLE, 0 },
1035 { 0x125D, 0x1998, 0x1599, 0x0715, HV_CTRL_ENABLE, 0 },
1036 { 0x125D, 0x1998, 0x5643, 0x5643, HV_CTRL_ENABLE, 0 },
1037 { 0x125D, 0x199A, 0x144D, 0x3260, HV_CTRL_ENABLE | REDUCED_DEBOUNCE, 0 },
1038 { 0x125D, 0x199A, 0x144D, 0x3261, HV_CTRL_ENABLE | REDUCED_DEBOUNCE, 0 },
1039 { 0x125D, 0x199A, 0x144D, 0xC000, HV_CTRL_ENABLE | REDUCED_DEBOUNCE, 0 },
1040 { 0x125D, 0x199A, 0x144D, 0xC001, HV_CTRL_ENABLE | REDUCED_DEBOUNCE, 0 },
1041 { 0 }
1042};
1043
1044/*
1045 * lowlevel functions
1046 */
1047
1048inline static void snd_m3_outw(m3_t *chip, u16 value, unsigned long reg)
1049{
1050 outw(value, chip->iobase + reg);
1051}
1052
1053inline static u16 snd_m3_inw(m3_t *chip, unsigned long reg)
1054{
1055 return inw(chip->iobase + reg);
1056}
1057
1058inline static void snd_m3_outb(m3_t *chip, u8 value, unsigned long reg)
1059{
1060 outb(value, chip->iobase + reg);
1061}
1062
1063inline static u8 snd_m3_inb(m3_t *chip, unsigned long reg)
1064{
1065 return inb(chip->iobase + reg);
1066}
1067
1068/*
1069 * access 16bit words to the code or data regions of the dsp's memory.
1070 * index addresses 16bit words.
1071 */
1072static u16 snd_m3_assp_read(m3_t *chip, u16 region, u16 index)
1073{
1074 snd_m3_outw(chip, region & MEMTYPE_MASK, DSP_PORT_MEMORY_TYPE);
1075 snd_m3_outw(chip, index, DSP_PORT_MEMORY_INDEX);
1076 return snd_m3_inw(chip, DSP_PORT_MEMORY_DATA);
1077}
1078
1079static void snd_m3_assp_write(m3_t *chip, u16 region, u16 index, u16 data)
1080{
1081 snd_m3_outw(chip, region & MEMTYPE_MASK, DSP_PORT_MEMORY_TYPE);
1082 snd_m3_outw(chip, index, DSP_PORT_MEMORY_INDEX);
1083 snd_m3_outw(chip, data, DSP_PORT_MEMORY_DATA);
1084}
1085
1086static void snd_m3_assp_halt(m3_t *chip)
1087{
1088 chip->reset_state = snd_m3_inb(chip, DSP_PORT_CONTROL_REG_B) & ~REGB_STOP_CLOCK;
1089 msleep(10);
1090 snd_m3_outb(chip, chip->reset_state & ~REGB_ENABLE_RESET, DSP_PORT_CONTROL_REG_B);
1091}
1092
1093static void snd_m3_assp_continue(m3_t *chip)
1094{
1095 snd_m3_outb(chip, chip->reset_state | REGB_ENABLE_RESET, DSP_PORT_CONTROL_REG_B);
1096}
1097
1098
1099/*
1100 * This makes me sad. the maestro3 has lists
1101 * internally that must be packed.. 0 terminates,
1102 * apparently, or maybe all unused entries have
1103 * to be 0, the lists have static lengths set
1104 * by the binary code images.
1105 */
1106
1107static int snd_m3_add_list(m3_t *chip, struct m3_list *list, u16 val)
1108{
1109 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1110 list->mem_addr + list->curlen,
1111 val);
1112 return list->curlen++;
1113}
1114
1115static void snd_m3_remove_list(m3_t *chip, struct m3_list *list, int index)
1116{
1117 u16 val;
1118 int lastindex = list->curlen - 1;
1119
1120 if (index != lastindex) {
1121 val = snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA,
1122 list->mem_addr + lastindex);
1123 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1124 list->mem_addr + index,
1125 val);
1126 }
1127
1128 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1129 list->mem_addr + lastindex,
1130 0);
1131
1132 list->curlen--;
1133}
1134
1135static void snd_m3_inc_timer_users(m3_t *chip)
1136{
1137 chip->timer_users++;
1138 if (chip->timer_users != 1)
1139 return;
1140
1141 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1142 KDATA_TIMER_COUNT_RELOAD,
1143 240);
1144
1145 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1146 KDATA_TIMER_COUNT_CURRENT,
1147 240);
1148
1149 snd_m3_outw(chip,
1150 snd_m3_inw(chip, HOST_INT_CTRL) | CLKRUN_GEN_ENABLE,
1151 HOST_INT_CTRL);
1152}
1153
1154static void snd_m3_dec_timer_users(m3_t *chip)
1155{
1156 chip->timer_users--;
1157 if (chip->timer_users > 0)
1158 return;
1159
1160 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1161 KDATA_TIMER_COUNT_RELOAD,
1162 0);
1163
1164 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1165 KDATA_TIMER_COUNT_CURRENT,
1166 0);
1167
1168 snd_m3_outw(chip,
1169 snd_m3_inw(chip, HOST_INT_CTRL) & ~CLKRUN_GEN_ENABLE,
1170 HOST_INT_CTRL);
1171}
1172
1173/*
1174 * start/stop
1175 */
1176
1177/* spinlock held! */
1178static int snd_m3_pcm_start(m3_t *chip, m3_dma_t *s, snd_pcm_substream_t *subs)
1179{
1180 if (! s || ! subs)
1181 return -EINVAL;
1182
1183 snd_m3_inc_timer_users(chip);
1184 switch (subs->stream) {
1185 case SNDRV_PCM_STREAM_PLAYBACK:
1186 chip->dacs_active++;
1187 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1188 s->inst.data + CDATA_INSTANCE_READY, 1);
1189 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1190 KDATA_MIXER_TASK_NUMBER,
1191 chip->dacs_active);
1192 break;
1193 case SNDRV_PCM_STREAM_CAPTURE:
1194 snd_m3_assp_write(s->chip, MEMTYPE_INTERNAL_DATA,
1195 KDATA_ADC1_REQUEST, 1);
1196 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1197 s->inst.data + CDATA_INSTANCE_READY, 1);
1198 break;
1199 }
1200 return 0;
1201}
1202
1203/* spinlock held! */
1204static int snd_m3_pcm_stop(m3_t *chip, m3_dma_t *s, snd_pcm_substream_t *subs)
1205{
1206 if (! s || ! subs)
1207 return -EINVAL;
1208
1209 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1210 s->inst.data + CDATA_INSTANCE_READY, 0);
1211 snd_m3_dec_timer_users(chip);
1212 switch (subs->stream) {
1213 case SNDRV_PCM_STREAM_PLAYBACK:
1214 chip->dacs_active--;
1215 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1216 KDATA_MIXER_TASK_NUMBER,
1217 chip->dacs_active);
1218 break;
1219 case SNDRV_PCM_STREAM_CAPTURE:
1220 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1221 KDATA_ADC1_REQUEST, 0);
1222 break;
1223 }
1224 return 0;
1225}
1226
1227static int
1228snd_m3_pcm_trigger(snd_pcm_substream_t *subs, int cmd)
1229{
1230 m3_t *chip = snd_pcm_substream_chip(subs);
1231 m3_dma_t *s = (m3_dma_t*)subs->runtime->private_data;
1232 int err = -EINVAL;
1233
1234 snd_assert(s != NULL, return -ENXIO);
1235
1236 spin_lock(&chip->reg_lock);
1237 switch (cmd) {
1238 case SNDRV_PCM_TRIGGER_START:
1239 case SNDRV_PCM_TRIGGER_RESUME:
1240 if (s->running)
1241 err = -EBUSY;
1242 else {
1243 s->running = 1;
1244 err = snd_m3_pcm_start(chip, s, subs);
1245 }
1246 break;
1247 case SNDRV_PCM_TRIGGER_STOP:
1248 case SNDRV_PCM_TRIGGER_SUSPEND:
1249 if (! s->running)
1250 err = 0; /* should return error? */
1251 else {
1252 s->running = 0;
1253 err = snd_m3_pcm_stop(chip, s, subs);
1254 }
1255 break;
1256 }
1257 spin_unlock(&chip->reg_lock);
1258 return err;
1259}
1260
1261/*
1262 * setup
1263 */
1264static void
1265snd_m3_pcm_setup1(m3_t *chip, m3_dma_t *s, snd_pcm_substream_t *subs)
1266{
1267 int dsp_in_size, dsp_out_size, dsp_in_buffer, dsp_out_buffer;
1268 snd_pcm_runtime_t *runtime = subs->runtime;
1269
1270 if (subs->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1271 dsp_in_size = MINISRC_IN_BUFFER_SIZE - (0x20 * 2);
1272 dsp_out_size = MINISRC_OUT_BUFFER_SIZE - (0x20 * 2);
1273 } else {
1274 dsp_in_size = MINISRC_IN_BUFFER_SIZE - (0x10 * 2);
1275 dsp_out_size = MINISRC_OUT_BUFFER_SIZE - (0x10 * 2);
1276 }
1277 dsp_in_buffer = s->inst.data + (MINISRC_TMP_BUFFER_SIZE / 2);
1278 dsp_out_buffer = dsp_in_buffer + (dsp_in_size / 2) + 1;
1279
1280 s->dma_size = frames_to_bytes(runtime, runtime->buffer_size);
1281 s->period_size = frames_to_bytes(runtime, runtime->period_size);
1282 s->hwptr = 0;
1283 s->count = 0;
1284
1285#define LO(x) ((x) & 0xffff)
1286#define HI(x) LO((x) >> 16)
1287
1288 /* host dma buffer pointers */
1289 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1290 s->inst.data + CDATA_HOST_SRC_ADDRL,
1291 LO(s->buffer_addr));
1292
1293 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1294 s->inst.data + CDATA_HOST_SRC_ADDRH,
1295 HI(s->buffer_addr));
1296
1297 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1298 s->inst.data + CDATA_HOST_SRC_END_PLUS_1L,
1299 LO(s->buffer_addr + s->dma_size));
1300
1301 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1302 s->inst.data + CDATA_HOST_SRC_END_PLUS_1H,
1303 HI(s->buffer_addr + s->dma_size));
1304
1305 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1306 s->inst.data + CDATA_HOST_SRC_CURRENTL,
1307 LO(s->buffer_addr));
1308
1309 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1310 s->inst.data + CDATA_HOST_SRC_CURRENTH,
1311 HI(s->buffer_addr));
1312#undef LO
1313#undef HI
1314
1315 /* dsp buffers */
1316
1317 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1318 s->inst.data + CDATA_IN_BUF_BEGIN,
1319 dsp_in_buffer);
1320
1321 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1322 s->inst.data + CDATA_IN_BUF_END_PLUS_1,
1323 dsp_in_buffer + (dsp_in_size / 2));
1324
1325 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1326 s->inst.data + CDATA_IN_BUF_HEAD,
1327 dsp_in_buffer);
1328
1329 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1330 s->inst.data + CDATA_IN_BUF_TAIL,
1331 dsp_in_buffer);
1332
1333 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1334 s->inst.data + CDATA_OUT_BUF_BEGIN,
1335 dsp_out_buffer);
1336
1337 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1338 s->inst.data + CDATA_OUT_BUF_END_PLUS_1,
1339 dsp_out_buffer + (dsp_out_size / 2));
1340
1341 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1342 s->inst.data + CDATA_OUT_BUF_HEAD,
1343 dsp_out_buffer);
1344
1345 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1346 s->inst.data + CDATA_OUT_BUF_TAIL,
1347 dsp_out_buffer);
1348}
1349
1350static void snd_m3_pcm_setup2(m3_t *chip, m3_dma_t *s, snd_pcm_runtime_t *runtime)
1351{
1352 u32 freq;
1353
1354 /*
1355 * put us in the lists if we're not already there
1356 */
1357 if (! s->in_lists) {
1358 s->index[0] = snd_m3_add_list(chip, s->index_list[0],
1359 s->inst.data >> DP_SHIFT_COUNT);
1360 s->index[1] = snd_m3_add_list(chip, s->index_list[1],
1361 s->inst.data >> DP_SHIFT_COUNT);
1362 s->index[2] = snd_m3_add_list(chip, s->index_list[2],
1363 s->inst.data >> DP_SHIFT_COUNT);
1364 s->in_lists = 1;
1365 }
1366
1367 /* write to 'mono' word */
1368 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1369 s->inst.data + SRC3_DIRECTION_OFFSET + 1,
1370 runtime->channels == 2 ? 0 : 1);
1371 /* write to '8bit' word */
1372 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1373 s->inst.data + SRC3_DIRECTION_OFFSET + 2,
1374 snd_pcm_format_width(runtime->format) == 16 ? 0 : 1);
1375
1376 /* set up dac/adc rate */
1377 freq = ((runtime->rate << 15) + 24000 ) / 48000;
1378 if (freq)
1379 freq--;
1380 printk("set rate: %i, freq: %i\n",runtime->rate,freq);
1381 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1382 s->inst.data + CDATA_FREQUENCY,
1383 freq);
1384}
1385
1386static const struct play_vals {
1387 u16 addr, val;
1388} pv[] = {
1389 {CDATA_LEFT_VOLUME, ARB_VOLUME},
1390 {CDATA_RIGHT_VOLUME, ARB_VOLUME},
1391 {SRC3_DIRECTION_OFFSET, 0} ,
1392 /* +1, +2 are stereo/16 bit */
1393 {SRC3_DIRECTION_OFFSET + 3, 0x0000}, /* fraction? */
1394 {SRC3_DIRECTION_OFFSET + 4, 0}, /* first l */
1395 {SRC3_DIRECTION_OFFSET + 5, 0}, /* first r */
1396 {SRC3_DIRECTION_OFFSET + 6, 0}, /* second l */
1397 {SRC3_DIRECTION_OFFSET + 7, 0}, /* second r */
1398 {SRC3_DIRECTION_OFFSET + 8, 0}, /* delta l */
1399 {SRC3_DIRECTION_OFFSET + 9, 0}, /* delta r */
1400 {SRC3_DIRECTION_OFFSET + 10, 0x8000}, /* round */
1401 {SRC3_DIRECTION_OFFSET + 11, 0xFF00}, /* higher bute mark */
1402 {SRC3_DIRECTION_OFFSET + 13, 0}, /* temp0 */
1403 {SRC3_DIRECTION_OFFSET + 14, 0}, /* c fraction */
1404 {SRC3_DIRECTION_OFFSET + 15, 0}, /* counter */
1405 {SRC3_DIRECTION_OFFSET + 16, 8}, /* numin */
1406 {SRC3_DIRECTION_OFFSET + 17, 50*2}, /* numout */
1407 {SRC3_DIRECTION_OFFSET + 18, MINISRC_BIQUAD_STAGE - 1}, /* numstage */
1408 {SRC3_DIRECTION_OFFSET + 20, 0}, /* filtertap */
1409 {SRC3_DIRECTION_OFFSET + 21, 0} /* booster */
1410};
1411
1412
1413/* the mode passed should be already shifted and masked */
1414static void
1415snd_m3_playback_setup(m3_t *chip, m3_dma_t *s, snd_pcm_substream_t *subs)
1416{
1417 unsigned int i;
1418
1419 /*
1420 * some per client initializers
1421 */
1422
1423 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1424 s->inst.data + SRC3_DIRECTION_OFFSET + 12,
1425 s->inst.data + 40 + 8);
1426
1427 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1428 s->inst.data + SRC3_DIRECTION_OFFSET + 19,
1429 s->inst.code + MINISRC_COEF_LOC);
1430
1431 /* enable or disable low pass filter? */
1432 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1433 s->inst.data + SRC3_DIRECTION_OFFSET + 22,
1434 subs->runtime->rate > 45000 ? 0xff : 0);
1435
1436 /* tell it which way dma is going? */
1437 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1438 s->inst.data + CDATA_DMA_CONTROL,
1439 DMACONTROL_AUTOREPEAT + DMAC_PAGE3_SELECTOR + DMAC_BLOCKF_SELECTOR);
1440
1441 /*
1442 * set an armload of static initializers
1443 */
1444 for (i = 0; i < ARRAY_SIZE(pv); i++)
1445 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1446 s->inst.data + pv[i].addr, pv[i].val);
1447}
1448
1449/*
1450 * Native record driver
1451 */
1452static const struct rec_vals {
1453 u16 addr, val;
1454} rv[] = {
1455 {CDATA_LEFT_VOLUME, ARB_VOLUME},
1456 {CDATA_RIGHT_VOLUME, ARB_VOLUME},
1457 {SRC3_DIRECTION_OFFSET, 1} ,
1458 /* +1, +2 are stereo/16 bit */
1459 {SRC3_DIRECTION_OFFSET + 3, 0x0000}, /* fraction? */
1460 {SRC3_DIRECTION_OFFSET + 4, 0}, /* first l */
1461 {SRC3_DIRECTION_OFFSET + 5, 0}, /* first r */
1462 {SRC3_DIRECTION_OFFSET + 6, 0}, /* second l */
1463 {SRC3_DIRECTION_OFFSET + 7, 0}, /* second r */
1464 {SRC3_DIRECTION_OFFSET + 8, 0}, /* delta l */
1465 {SRC3_DIRECTION_OFFSET + 9, 0}, /* delta r */
1466 {SRC3_DIRECTION_OFFSET + 10, 0x8000}, /* round */
1467 {SRC3_DIRECTION_OFFSET + 11, 0xFF00}, /* higher bute mark */
1468 {SRC3_DIRECTION_OFFSET + 13, 0}, /* temp0 */
1469 {SRC3_DIRECTION_OFFSET + 14, 0}, /* c fraction */
1470 {SRC3_DIRECTION_OFFSET + 15, 0}, /* counter */
1471 {SRC3_DIRECTION_OFFSET + 16, 50},/* numin */
1472 {SRC3_DIRECTION_OFFSET + 17, 8}, /* numout */
1473 {SRC3_DIRECTION_OFFSET + 18, 0}, /* numstage */
1474 {SRC3_DIRECTION_OFFSET + 19, 0}, /* coef */
1475 {SRC3_DIRECTION_OFFSET + 20, 0}, /* filtertap */
1476 {SRC3_DIRECTION_OFFSET + 21, 0}, /* booster */
1477 {SRC3_DIRECTION_OFFSET + 22, 0xff} /* skip lpf */
1478};
1479
1480static void
1481snd_m3_capture_setup(m3_t *chip, m3_dma_t *s, snd_pcm_substream_t *subs)
1482{
1483 unsigned int i;
1484
1485 /*
1486 * some per client initializers
1487 */
1488
1489 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1490 s->inst.data + SRC3_DIRECTION_OFFSET + 12,
1491 s->inst.data + 40 + 8);
1492
1493 /* tell it which way dma is going? */
1494 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1495 s->inst.data + CDATA_DMA_CONTROL,
1496 DMACONTROL_DIRECTION + DMACONTROL_AUTOREPEAT +
1497 DMAC_PAGE3_SELECTOR + DMAC_BLOCKF_SELECTOR);
1498
1499 /*
1500 * set an armload of static initializers
1501 */
1502 for (i = 0; i < ARRAY_SIZE(rv); i++)
1503 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
1504 s->inst.data + rv[i].addr, rv[i].val);
1505}
1506
1507static int snd_m3_pcm_hw_params(snd_pcm_substream_t * substream,
1508 snd_pcm_hw_params_t * hw_params)
1509{
1510 m3_dma_t *s = (m3_dma_t*) substream->runtime->private_data;
1511 int err;
1512
1513 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
1514 return err;
1515 /* set buffer address */
1516 s->buffer_addr = substream->runtime->dma_addr;
1517 if (s->buffer_addr & 0x3) {
1518 snd_printk("oh my, not aligned\n");
1519 s->buffer_addr = s->buffer_addr & ~0x3;
1520 }
1521 return 0;
1522}
1523
1524static int snd_m3_pcm_hw_free(snd_pcm_substream_t * substream)
1525{
1526 m3_dma_t *s;
1527
1528 if (substream->runtime->private_data == NULL)
1529 return 0;
1530 s = (m3_dma_t*) substream->runtime->private_data;
1531 snd_pcm_lib_free_pages(substream);
1532 s->buffer_addr = 0;
1533 return 0;
1534}
1535
1536static int
1537snd_m3_pcm_prepare(snd_pcm_substream_t *subs)
1538{
1539 m3_t *chip = snd_pcm_substream_chip(subs);
1540 snd_pcm_runtime_t *runtime = subs->runtime;
1541 m3_dma_t *s = (m3_dma_t*)runtime->private_data;
1542
1543 snd_assert(s != NULL, return -ENXIO);
1544
1545 if (runtime->format != SNDRV_PCM_FORMAT_U8 &&
1546 runtime->format != SNDRV_PCM_FORMAT_S16_LE)
1547 return -EINVAL;
1548 if (runtime->rate > 48000 ||
1549 runtime->rate < 8000)
1550 return -EINVAL;
1551
1552 spin_lock_irq(&chip->reg_lock);
1553
1554 snd_m3_pcm_setup1(chip, s, subs);
1555
1556 if (subs->stream == SNDRV_PCM_STREAM_PLAYBACK)
1557 snd_m3_playback_setup(chip, s, subs);
1558 else
1559 snd_m3_capture_setup(chip, s, subs);
1560
1561 snd_m3_pcm_setup2(chip, s, runtime);
1562
1563 spin_unlock_irq(&chip->reg_lock);
1564
1565 return 0;
1566}
1567
1568/*
1569 * get current pointer
1570 */
1571static unsigned int
1572snd_m3_get_pointer(m3_t *chip, m3_dma_t *s, snd_pcm_substream_t *subs)
1573{
1574 u16 hi = 0, lo = 0;
1575 int retry = 10;
1576 u32 addr;
1577
1578 /*
1579 * try and get a valid answer
1580 */
1581 while (retry--) {
1582 hi = snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA,
1583 s->inst.data + CDATA_HOST_SRC_CURRENTH);
1584
1585 lo = snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA,
1586 s->inst.data + CDATA_HOST_SRC_CURRENTL);
1587
1588 if (hi == snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA,
1589 s->inst.data + CDATA_HOST_SRC_CURRENTH))
1590 break;
1591 }
1592 addr = lo | ((u32)hi<<16);
1593 return (unsigned int)(addr - s->buffer_addr);
1594}
1595
1596static snd_pcm_uframes_t
1597snd_m3_pcm_pointer(snd_pcm_substream_t * subs)
1598{
1599 m3_t *chip = snd_pcm_substream_chip(subs);
1600 unsigned int ptr;
1601 m3_dma_t *s = (m3_dma_t*)subs->runtime->private_data;
1602 snd_assert(s != NULL, return 0);
1603
1604 spin_lock(&chip->reg_lock);
1605 ptr = snd_m3_get_pointer(chip, s, subs);
1606 spin_unlock(&chip->reg_lock);
1607 return bytes_to_frames(subs->runtime, ptr);
1608}
1609
1610
1611/* update pointer */
1612/* spinlock held! */
1613static void snd_m3_update_ptr(m3_t *chip, m3_dma_t *s)
1614{
1615 snd_pcm_substream_t *subs = s->substream;
1616 unsigned int hwptr;
1617 int diff;
1618
1619 if (! s->running)
1620 return;
1621
1622 hwptr = snd_m3_get_pointer(chip, s, subs);
1623 /* try to avoid expensive modulo divisions */
1624 if (hwptr >= s->dma_size)
1625 hwptr %= s->dma_size;
1626
1627 diff = s->dma_size + hwptr - s->hwptr;
1628 if (diff >= s->dma_size)
1629 diff %= s->dma_size;
1630
1631 s->hwptr = hwptr;
1632 s->count += diff;
1633
1634 if (s->count >= (signed)s->period_size) {
1635 if (s->count < 2 * (signed)s->period_size)
1636 s->count -= (signed)s->period_size;
1637 else
1638 s->count %= s->period_size;
1639
1640 spin_unlock(&chip->reg_lock);
1641 snd_pcm_period_elapsed(subs);
1642 spin_lock(&chip->reg_lock);
1643 }
1644}
1645
1646static void snd_m3_update_hw_volume(unsigned long private_data)
1647{
1648 m3_t *chip = (m3_t *) private_data;
1649 int x, val;
1650 unsigned long flags;
1651
1652 /* Figure out which volume control button was pushed,
1653 based on differences from the default register
1654 values. */
1655 x = inb(chip->iobase + SHADOW_MIX_REG_VOICE) & 0xee;
1656
1657 /* Reset the volume control registers. */
1658 outb(0x88, chip->iobase + SHADOW_MIX_REG_VOICE);
1659 outb(0x88, chip->iobase + HW_VOL_COUNTER_VOICE);
1660 outb(0x88, chip->iobase + SHADOW_MIX_REG_MASTER);
1661 outb(0x88, chip->iobase + HW_VOL_COUNTER_MASTER);
1662
1663 if (!chip->master_switch || !chip->master_volume)
1664 return;
1665
1666 /* FIXME: we can't call snd_ac97_* functions since here is in tasklet. */
1667 spin_lock_irqsave(&chip->ac97_lock, flags);
1668
1669 val = chip->ac97->regs[AC97_MASTER_VOL];
1670 switch (x) {
1671 case 0x88:
1672 /* mute */
1673 val ^= 0x8000;
1674 chip->ac97->regs[AC97_MASTER_VOL] = val;
1675 outw(val, chip->iobase + CODEC_DATA);
1676 outb(AC97_MASTER_VOL, chip->iobase + CODEC_COMMAND);
1677 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
1678 &chip->master_switch->id);
1679 break;
1680 case 0xaa:
1681 /* volume up */
1682 if ((val & 0x7f) > 0)
1683 val--;
1684 if ((val & 0x7f00) > 0)
1685 val -= 0x0100;
1686 chip->ac97->regs[AC97_MASTER_VOL] = val;
1687 outw(val, chip->iobase + CODEC_DATA);
1688 outb(AC97_MASTER_VOL, chip->iobase + CODEC_COMMAND);
1689 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
1690 &chip->master_volume->id);
1691 break;
1692 case 0x66:
1693 /* volume down */
1694 if ((val & 0x7f) < 0x1f)
1695 val++;
1696 if ((val & 0x7f00) < 0x1f00)
1697 val += 0x0100;
1698 chip->ac97->regs[AC97_MASTER_VOL] = val;
1699 outw(val, chip->iobase + CODEC_DATA);
1700 outb(AC97_MASTER_VOL, chip->iobase + CODEC_COMMAND);
1701 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
1702 &chip->master_volume->id);
1703 break;
1704 }
1705 spin_unlock_irqrestore(&chip->ac97_lock, flags);
1706}
1707
1708static irqreturn_t
1709snd_m3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1710{
1711 m3_t *chip = dev_id;
1712 u8 status;
1713 int i;
1714
1715 status = inb(chip->iobase + HOST_INT_STATUS);
1716
1717 if (status == 0xff)
1718 return IRQ_NONE;
1719
1720 if (status & HV_INT_PENDING)
1721 tasklet_hi_schedule(&chip->hwvol_tq);
1722 /*
1723 * ack an assp int if its running
1724 * and has an int pending
1725 */
1726 if (status & ASSP_INT_PENDING) {
1727 u8 ctl;
1728 ctl = inb(chip->iobase + ASSP_CONTROL_B);
1729 if (!(ctl & STOP_ASSP_CLOCK)) {
1730 ctl = inb(chip->iobase + ASSP_HOST_INT_STATUS);
1731 if (ctl & DSP2HOST_REQ_TIMER) {
1732 outb(DSP2HOST_REQ_TIMER, chip->iobase + ASSP_HOST_INT_STATUS);
1733 /* update adc/dac info if it was a timer int */
1734 spin_lock(&chip->reg_lock);
1735 for (i = 0; i < chip->num_substreams; i++) {
1736 m3_dma_t *s = &chip->substreams[i];
1737 if (s->running)
1738 snd_m3_update_ptr(chip, s);
1739 }
1740 spin_unlock(&chip->reg_lock);
1741 }
1742 }
1743 }
1744
1745#if 0 /* TODO: not supported yet */
1746 if ((status & MPU401_INT_PENDING) && chip->rmidi)
1747 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
1748#endif
1749
1750 /* ack ints */
1751 outb(status, chip->iobase + HOST_INT_STATUS);
1752 return IRQ_HANDLED;
1753}
1754
1755
1756/*
1757 */
1758
1759static snd_pcm_hardware_t snd_m3_playback =
1760{
1761 /* info: */ (SNDRV_PCM_INFO_MMAP |
1762 SNDRV_PCM_INFO_INTERLEAVED |
1763 SNDRV_PCM_INFO_MMAP_VALID |
1764 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1765 /*SNDRV_PCM_INFO_PAUSE |*/
1766 SNDRV_PCM_INFO_RESUME),
1767 /* formats: */ SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
1768 /* rates: */ SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
1769 /* rate_min: */ 8000,
1770 /* rate_max: */ 48000,
1771 /* channels_min: */ 1,
1772 /* channels_max: */ 2,
1773 /* buffer_bytes_max: */ (512*1024),
1774 /* period_bytes_min: */ 64,
1775 /* period_bytes_max: */ (512*1024),
1776 /* periods_min: */ 1,
1777 /* periods_max: */ 1024,
1778 0
1779};
1780
1781static snd_pcm_hardware_t snd_m3_capture =
1782{
1783 /* info: */ (SNDRV_PCM_INFO_MMAP |
1784 SNDRV_PCM_INFO_INTERLEAVED |
1785 SNDRV_PCM_INFO_MMAP_VALID |
1786 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1787 /*SNDRV_PCM_INFO_PAUSE |*/
1788 SNDRV_PCM_INFO_RESUME),
1789 /* formats: */ SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
1790 /* rates: */ SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
1791 /* rate_min: */ 8000,
1792 /* rate_max: */ 48000,
1793 /* channels_min: */ 1,
1794 /* channels_max: */ 2,
1795 /* buffer_bytes_max: */ (512*1024),
1796 /* period_bytes_min: */ 64,
1797 /* period_bytes_max: */ (512*1024),
1798 /* periods_min: */ 1,
1799 /* periods_max: */ 1024,
1800 0
1801};
1802
1803/*
1804 */
1805
1806static int
1807snd_m3_substream_open(m3_t *chip, snd_pcm_substream_t *subs)
1808{
1809 int i;
1810 m3_dma_t *s;
1811
1812 spin_lock_irq(&chip->reg_lock);
1813 for (i = 0; i < chip->num_substreams; i++) {
1814 s = &chip->substreams[i];
1815 if (! s->opened)
1816 goto __found;
1817 }
1818 spin_unlock_irq(&chip->reg_lock);
1819 return -ENOMEM;
1820__found:
1821 s->opened = 1;
1822 s->running = 0;
1823 spin_unlock_irq(&chip->reg_lock);
1824
1825 subs->runtime->private_data = s;
1826 s->substream = subs;
1827
1828 /* set list owners */
1829 if (subs->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1830 s->index_list[0] = &chip->mixer_list;
1831 } else
1832 s->index_list[0] = &chip->adc1_list;
1833 s->index_list[1] = &chip->msrc_list;
1834 s->index_list[2] = &chip->dma_list;
1835
1836 return 0;
1837}
1838
1839static void
1840snd_m3_substream_close(m3_t *chip, snd_pcm_substream_t *subs)
1841{
1842 m3_dma_t *s = (m3_dma_t*) subs->runtime->private_data;
1843
1844 if (s == NULL)
1845 return; /* not opened properly */
1846
1847 spin_lock_irq(&chip->reg_lock);
1848 if (s->substream && s->running)
1849 snd_m3_pcm_stop(chip, s, s->substream); /* does this happen? */
1850 if (s->in_lists) {
1851 snd_m3_remove_list(chip, s->index_list[0], s->index[0]);
1852 snd_m3_remove_list(chip, s->index_list[1], s->index[1]);
1853 snd_m3_remove_list(chip, s->index_list[2], s->index[2]);
1854 s->in_lists = 0;
1855 }
1856 s->running = 0;
1857 s->opened = 0;
1858 spin_unlock_irq(&chip->reg_lock);
1859}
1860
1861static int
1862snd_m3_playback_open(snd_pcm_substream_t *subs)
1863{
1864 m3_t *chip = snd_pcm_substream_chip(subs);
1865 snd_pcm_runtime_t *runtime = subs->runtime;
1866 int err;
1867
1868 if ((err = snd_m3_substream_open(chip, subs)) < 0)
1869 return err;
1870
1871 runtime->hw = snd_m3_playback;
1872 snd_pcm_set_sync(subs);
1873
1874 return 0;
1875}
1876
1877static int
1878snd_m3_playback_close(snd_pcm_substream_t *subs)
1879{
1880 m3_t *chip = snd_pcm_substream_chip(subs);
1881
1882 snd_m3_substream_close(chip, subs);
1883 return 0;
1884}
1885
1886static int
1887snd_m3_capture_open(snd_pcm_substream_t *subs)
1888{
1889 m3_t *chip = snd_pcm_substream_chip(subs);
1890 snd_pcm_runtime_t *runtime = subs->runtime;
1891 int err;
1892
1893 if ((err = snd_m3_substream_open(chip, subs)) < 0)
1894 return err;
1895
1896 runtime->hw = snd_m3_capture;
1897 snd_pcm_set_sync(subs);
1898
1899 return 0;
1900}
1901
1902static int
1903snd_m3_capture_close(snd_pcm_substream_t *subs)
1904{
1905 m3_t *chip = snd_pcm_substream_chip(subs);
1906
1907 snd_m3_substream_close(chip, subs);
1908 return 0;
1909}
1910
1911/*
1912 * create pcm instance
1913 */
1914
1915static snd_pcm_ops_t snd_m3_playback_ops = {
1916 snd_m3_playback_open,
1917 snd_m3_playback_close,
1918 snd_pcm_lib_ioctl,
1919 snd_m3_pcm_hw_params,
1920 snd_m3_pcm_hw_free,
1921 snd_m3_pcm_prepare,
1922 snd_m3_pcm_trigger,
1923 snd_m3_pcm_pointer,0,0
1924};
1925
1926static snd_pcm_ops_t snd_m3_capture_ops = {
1927 snd_m3_capture_open,
1928 snd_m3_capture_close,
1929 snd_pcm_lib_ioctl,
1930 snd_m3_pcm_hw_params,
1931 snd_m3_pcm_hw_free,
1932 snd_m3_pcm_prepare,
1933 snd_m3_pcm_trigger,
1934 snd_m3_pcm_pointer,0,0
1935};
1936
1937static int __devinit
1938snd_m3_pcm(m3_t * chip, int device)
1939{
1940 snd_pcm_t *pcm;
1941 int err;
1942
1943 err = snd_pcm_new(chip->card, chip->card->driver, device,
1944 MAX_PLAYBACKS, MAX_CAPTURES, &pcm);
1945 if (err < 0)
1946 return err;
1947
1948 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_m3_playback_ops);
1949 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_m3_capture_ops);
1950
1951 pcm->private_data = chip;
1952 pcm->info_flags = 0;
1953 strcpy(pcm->name, chip->card->driver);
1954 chip->pcm = pcm;
1955
1956 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1957 snd_dma_pci_data(chip->pci), 64*1024, 64*1024);
1958
1959 return 0;
1960}
1961
1962
1963/*
1964 * ac97 interface
1965 */
1966
1967/*
1968 * Wait for the ac97 serial bus to be free.
1969 * return nonzero if the bus is still busy.
1970 */
1971static int snd_m3_ac97_wait(m3_t *chip)
1972{
1973 int i = 10000;
1974
1975 do {
1976 if (! (snd_m3_inb(chip, 0x30) & 1))
1977 return 0;
1978 cpu_relax();
1979 } while (i-- > 0);
1980
1981 snd_printk("ac97 serial bus busy\n");
1982 return 1;
1983}
1984
1985static unsigned short
1986snd_m3_ac97_read(ac97_t *ac97, unsigned short reg)
1987{
1988 m3_t *chip = ac97->private_data;
1989 unsigned long flags;
1990 unsigned short data = 0xffff;
1991
1992 if (snd_m3_ac97_wait(chip))
1993 goto fail;
1994 spin_lock_irqsave(&chip->ac97_lock, flags);
1995 snd_m3_outb(chip, 0x80 | (reg & 0x7f), CODEC_COMMAND);
1996 if (snd_m3_ac97_wait(chip))
1997 goto fail_unlock;
1998 data = snd_m3_inw(chip, CODEC_DATA);
1999fail_unlock:
2000 spin_unlock_irqrestore(&chip->ac97_lock, flags);
2001fail:
2002 return data;
2003}
2004
2005static void
2006snd_m3_ac97_write(ac97_t *ac97, unsigned short reg, unsigned short val)
2007{
2008 m3_t *chip = ac97->private_data;
2009 unsigned long flags;
2010
2011 if (snd_m3_ac97_wait(chip))
2012 return;
2013 spin_lock_irqsave(&chip->ac97_lock, flags);
2014 snd_m3_outw(chip, val, CODEC_DATA);
2015 snd_m3_outb(chip, reg & 0x7f, CODEC_COMMAND);
2016 spin_unlock_irqrestore(&chip->ac97_lock, flags);
2017}
2018
2019
2020static void snd_m3_remote_codec_config(int io, int isremote)
2021{
2022 isremote = isremote ? 1 : 0;
2023
2024 outw((inw(io + RING_BUS_CTRL_B) & ~SECOND_CODEC_ID_MASK) | isremote,
2025 io + RING_BUS_CTRL_B);
2026 outw((inw(io + SDO_OUT_DEST_CTRL) & ~COMMAND_ADDR_OUT) | isremote,
2027 io + SDO_OUT_DEST_CTRL);
2028 outw((inw(io + SDO_IN_DEST_CTRL) & ~STATUS_ADDR_IN) | isremote,
2029 io + SDO_IN_DEST_CTRL);
2030}
2031
2032/*
2033 * hack, returns non zero on err
2034 */
2035static int snd_m3_try_read_vendor(m3_t *chip)
2036{
2037 u16 ret;
2038
2039 if (snd_m3_ac97_wait(chip))
2040 return 1;
2041
2042 snd_m3_outb(chip, 0x80 | (AC97_VENDOR_ID1 & 0x7f), 0x30);
2043
2044 if (snd_m3_ac97_wait(chip))
2045 return 1;
2046
2047 ret = snd_m3_inw(chip, 0x32);
2048
2049 return (ret == 0) || (ret == 0xffff);
2050}
2051
2052static void snd_m3_ac97_reset(m3_t *chip)
2053{
2054 u16 dir;
2055 int delay1 = 0, delay2 = 0, i;
2056 int io = chip->iobase;
2057
2058 if (chip->allegro_flag) {
2059 /*
2060 * the onboard codec on the allegro seems
2061 * to want to wait a very long time before
2062 * coming back to life
2063 */
2064 delay1 = 50;
2065 delay2 = 800;
2066 } else {
2067 /* maestro3 */
2068 delay1 = 20;
2069 delay2 = 500;
2070 }
2071
2072 for (i = 0; i < 5; i++) {
2073 dir = inw(io + GPIO_DIRECTION);
2074 if (! chip->quirk || ! chip->quirk->irda_workaround)
2075 dir |= 0x10; /* assuming pci bus master? */
2076
2077 snd_m3_remote_codec_config(io, 0);
2078
2079 outw(IO_SRAM_ENABLE, io + RING_BUS_CTRL_A);
2080 udelay(20);
2081
2082 outw(dir & ~GPO_PRIMARY_AC97 , io + GPIO_DIRECTION);
2083 outw(~GPO_PRIMARY_AC97 , io + GPIO_MASK);
2084 outw(0, io + GPIO_DATA);
2085 outw(dir | GPO_PRIMARY_AC97, io + GPIO_DIRECTION);
2086
2087 set_current_state(TASK_UNINTERRUPTIBLE);
2088 schedule_timeout((delay1 * HZ) / 1000);
2089
2090 outw(GPO_PRIMARY_AC97, io + GPIO_DATA);
2091 udelay(5);
2092 /* ok, bring back the ac-link */
2093 outw(IO_SRAM_ENABLE | SERIAL_AC_LINK_ENABLE, io + RING_BUS_CTRL_A);
2094 outw(~0, io + GPIO_MASK);
2095
2096 set_current_state(TASK_UNINTERRUPTIBLE);
2097 schedule_timeout((delay2 * HZ) / 1000);
2098
2099 if (! snd_m3_try_read_vendor(chip))
2100 break;
2101
2102 delay1 += 10;
2103 delay2 += 100;
2104
2105 snd_printd("maestro3: retrying codec reset with delays of %d and %d ms\n",
2106 delay1, delay2);
2107 }
2108
2109#if 0
2110 /* more gung-ho reset that doesn't
2111 * seem to work anywhere :)
2112 */
2113 tmp = inw(io + RING_BUS_CTRL_A);
2114 outw(RAC_SDFS_ENABLE|LAC_SDFS_ENABLE, io + RING_BUS_CTRL_A);
2115 msleep(20);
2116 outw(tmp, io + RING_BUS_CTRL_A);
2117 msleep(50);
2118#endif
2119}
2120
2121static int __devinit snd_m3_mixer(m3_t *chip)
2122{
2123 ac97_bus_t *pbus;
2124 ac97_template_t ac97;
2125 snd_ctl_elem_id_t id;
2126 int err;
2127 static ac97_bus_ops_t ops = {
2128 .write = snd_m3_ac97_write,
2129 .read = snd_m3_ac97_read
2130 };
2131
2132 if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0)
2133 return err;
2134
2135 memset(&ac97, 0, sizeof(ac97));
2136 ac97.private_data = chip;
2137 if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97)) < 0)
2138 return err;
2139
2140 /* seems ac97 PCM needs initialization.. hack hack.. */
2141 snd_ac97_write(chip->ac97, AC97_PCM, 0x8000 | (15 << 8) | 15);
2142 set_current_state(TASK_UNINTERRUPTIBLE);
2143 schedule_timeout(HZ / 10);
2144 snd_ac97_write(chip->ac97, AC97_PCM, 0);
2145
2146 memset(&id, 0, sizeof(id));
2147 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2148 strcpy(id.name, "Master Playback Switch");
2149 chip->master_switch = snd_ctl_find_id(chip->card, &id);
2150 memset(&id, 0, sizeof(id));
2151 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2152 strcpy(id.name, "Master Playback Volume");
2153 chip->master_volume = snd_ctl_find_id(chip->card, &id);
2154
2155 return 0;
2156}
2157
2158
2159/*
2160 * DSP Code images
2161 */
2162
2163static const u16 assp_kernel_image[] __devinitdata = {
2164 0x7980, 0x0030, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x00FB, 0x7980, 0x00DD, 0x7980, 0x03B4,
2165 0x7980, 0x0332, 0x7980, 0x0287, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x03B4,
2166 0x7980, 0x031A, 0x7980, 0x03B4, 0x7980, 0x022F, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x03B4,
2167 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x0063, 0x7980, 0x006B, 0x7980, 0x03B4, 0x7980, 0x03B4,
2168 0xBF80, 0x2C7C, 0x8806, 0x8804, 0xBE40, 0xBC20, 0xAE09, 0x1000, 0xAE0A, 0x0001, 0x6938, 0xEB08,
2169 0x0053, 0x695A, 0xEB08, 0x00D6, 0x0009, 0x8B88, 0x6980, 0xE388, 0x0036, 0xBE30, 0xBC20, 0x6909,
2170 0xB801, 0x9009, 0xBE41, 0xBE41, 0x6928, 0xEB88, 0x0078, 0xBE41, 0xBE40, 0x7980, 0x0038, 0xBE41,
2171 0xBE41, 0x903A, 0x6938, 0xE308, 0x0056, 0x903A, 0xBE41, 0xBE40, 0xEF00, 0x903A, 0x6939, 0xE308,
2172 0x005E, 0x903A, 0xEF00, 0x690B, 0x660C, 0xEF8C, 0x690A, 0x660C, 0x620B, 0x6609, 0xEF00, 0x6910,
2173 0x660F, 0xEF04, 0xE388, 0x0075, 0x690E, 0x660F, 0x6210, 0x660D, 0xEF00, 0x690E, 0x660D, 0xEF00,
2174 0xAE70, 0x0001, 0xBC20, 0xAE27, 0x0001, 0x6939, 0xEB08, 0x005D, 0x6926, 0xB801, 0x9026, 0x0026,
2175 0x8B88, 0x6980, 0xE388, 0x00CB, 0x9028, 0x0D28, 0x4211, 0xE100, 0x007A, 0x4711, 0xE100, 0x00A0,
2176 0x7A80, 0x0063, 0xB811, 0x660A, 0x6209, 0xE304, 0x007A, 0x0C0B, 0x4005, 0x100A, 0xBA01, 0x9012,
2177 0x0C12, 0x4002, 0x7980, 0x00AF, 0x7A80, 0x006B, 0xBE02, 0x620E, 0x660D, 0xBA10, 0xE344, 0x007A,
2178 0x0C10, 0x4005, 0x100E, 0xBA01, 0x9012, 0x0C12, 0x4002, 0x1003, 0xBA02, 0x9012, 0x0C12, 0x4000,
2179 0x1003, 0xE388, 0x00BA, 0x1004, 0x7980, 0x00BC, 0x1004, 0xBA01, 0x9012, 0x0C12, 0x4001, 0x0C05,
2180 0x4003, 0x0C06, 0x4004, 0x1011, 0xBFB0, 0x01FF, 0x9012, 0x0C12, 0x4006, 0xBC20, 0xEF00, 0xAE26,
2181 0x1028, 0x6970, 0xBFD0, 0x0001, 0x9070, 0xE388, 0x007A, 0xAE28, 0x0000, 0xEF00, 0xAE70, 0x0300,
2182 0x0C70, 0xB00C, 0xAE5A, 0x0000, 0xEF00, 0x7A80, 0x038A, 0x697F, 0xB801, 0x907F, 0x0056, 0x8B88,
2183 0x0CA0, 0xB008, 0xAF71, 0xB000, 0x4E71, 0xE200, 0x00F3, 0xAE56, 0x1057, 0x0056, 0x0CA0, 0xB008,
2184 0x8056, 0x7980, 0x03A1, 0x0810, 0xBFA0, 0x1059, 0xE304, 0x03A1, 0x8056, 0x7980, 0x03A1, 0x7A80,
2185 0x038A, 0xBF01, 0xBE43, 0xBE59, 0x907C, 0x6937, 0xE388, 0x010D, 0xBA01, 0xE308, 0x010C, 0xAE71,
2186 0x0004, 0x0C71, 0x5000, 0x6936, 0x9037, 0xBF0A, 0x109E, 0x8B8A, 0xAF80, 0x8014, 0x4C80, 0xBF0A,
2187 0x0560, 0xF500, 0xBF0A, 0x0520, 0xB900, 0xBB17, 0x90A0, 0x6917, 0xE388, 0x0148, 0x0D17, 0xE100,
2188 0x0127, 0xBF0C, 0x0578, 0xBF0D, 0x057C, 0x7980, 0x012B, 0xBF0C, 0x0538, 0xBF0D, 0x053C, 0x6900,
2189 0xE308, 0x0135, 0x8B8C, 0xBE59, 0xBB07, 0x90A0, 0xBC20, 0x7980, 0x0157, 0x030C, 0x8B8B, 0xB903,
2190 0x8809, 0xBEC6, 0x013E, 0x69AC, 0x90AB, 0x69AD, 0x90AB, 0x0813, 0x660A, 0xE344, 0x0144, 0x0309,
2191 0x830C, 0xBC20, 0x7980, 0x0157, 0x6955, 0xE388, 0x0157, 0x7C38, 0xBF0B, 0x0578, 0xF500, 0xBF0B,
2192 0x0538, 0xB907, 0x8809, 0xBEC6, 0x0156, 0x10AB, 0x90AA, 0x6974, 0xE388, 0x0163, 0xAE72, 0x0540,
2193 0xF500, 0xAE72, 0x0500, 0xAE61, 0x103B, 0x7A80, 0x02F6, 0x6978, 0xE388, 0x0182, 0x8B8C, 0xBF0C,
2194 0x0560, 0xE500, 0x7C40, 0x0814, 0xBA20, 0x8812, 0x733D, 0x7A80, 0x0380, 0x733E, 0x7A80, 0x0380,
2195 0x8B8C, 0xBF0C, 0x056C, 0xE500, 0x7C40, 0x0814, 0xBA2C, 0x8812, 0x733F, 0x7A80, 0x0380, 0x7340,
2196 0x7A80, 0x0380, 0x6975, 0xE388, 0x018E, 0xAE72, 0x0548, 0xF500, 0xAE72, 0x0508, 0xAE61, 0x1041,
2197 0x7A80, 0x02F6, 0x6979, 0xE388, 0x01AD, 0x8B8C, 0xBF0C, 0x0560, 0xE500, 0x7C40, 0x0814, 0xBA18,
2198 0x8812, 0x7343, 0x7A80, 0x0380, 0x7344, 0x7A80, 0x0380, 0x8B8C, 0xBF0C, 0x056C, 0xE500, 0x7C40,
2199 0x0814, 0xBA24, 0x8812, 0x7345, 0x7A80, 0x0380, 0x7346, 0x7A80, 0x0380, 0x6976, 0xE388, 0x01B9,
2200 0xAE72, 0x0558, 0xF500, 0xAE72, 0x0518, 0xAE61, 0x1047, 0x7A80, 0x02F6, 0x697A, 0xE388, 0x01D8,
2201 0x8B8C, 0xBF0C, 0x0560, 0xE500, 0x7C40, 0x0814, 0xBA08, 0x8812, 0x7349, 0x7A80, 0x0380, 0x734A,
2202 0x7A80, 0x0380, 0x8B8C, 0xBF0C, 0x056C, 0xE500, 0x7C40, 0x0814, 0xBA14, 0x8812, 0x734B, 0x7A80,
2203 0x0380, 0x734C, 0x7A80, 0x0380, 0xBC21, 0xAE1C, 0x1090, 0x8B8A, 0xBF0A, 0x0560, 0xE500, 0x7C40,
2204 0x0812, 0xB804, 0x8813, 0x8B8D, 0xBF0D, 0x056C, 0xE500, 0x7C40, 0x0815, 0xB804, 0x8811, 0x7A80,
2205 0x034A, 0x8B8A, 0xBF0A, 0x0560, 0xE500, 0x7C40, 0x731F, 0xB903, 0x8809, 0xBEC6, 0x01F9, 0x548A,
2206 0xBE03, 0x98A0, 0x7320, 0xB903, 0x8809, 0xBEC6, 0x0201, 0x548A, 0xBE03, 0x98A0, 0x1F20, 0x2F1F,
2207 0x9826, 0xBC20, 0x6935, 0xE388, 0x03A1, 0x6933, 0xB801, 0x9033, 0xBFA0, 0x02EE, 0xE308, 0x03A1,
2208 0x9033, 0xBF00, 0x6951, 0xE388, 0x021F, 0x7334, 0xBE80, 0x5760, 0xBE03, 0x9F7E, 0xBE59, 0x9034,
2209 0x697E, 0x0D51, 0x9013, 0xBC20, 0x695C, 0xE388, 0x03A1, 0x735E, 0xBE80, 0x5760, 0xBE03, 0x9F7E,
2210 0xBE59, 0x905E, 0x697E, 0x0D5C, 0x9013, 0x7980, 0x03A1, 0x7A80, 0x038A, 0xBF01, 0xBE43, 0x6977,
2211 0xE388, 0x024E, 0xAE61, 0x104D, 0x0061, 0x8B88, 0x6980, 0xE388, 0x024E, 0x9071, 0x0D71, 0x000B,
2212 0xAFA0, 0x8010, 0xAFA0, 0x8010, 0x0810, 0x660A, 0xE308, 0x0249, 0x0009, 0x0810, 0x660C, 0xE388,
2213 0x024E, 0x800B, 0xBC20, 0x697B, 0xE388, 0x03A1, 0xBF0A, 0x109E, 0x8B8A, 0xAF80, 0x8014, 0x4C80,
2214 0xE100, 0x0266, 0x697C, 0xBF90, 0x0560, 0x9072, 0x0372, 0x697C, 0xBF90, 0x0564, 0x9073, 0x0473,
2215 0x7980, 0x0270, 0x697C, 0xBF90, 0x0520, 0x9072, 0x0372, 0x697C, 0xBF90, 0x0524, 0x9073, 0x0473,
2216 0x697C, 0xB801, 0x907C, 0xBF0A, 0x10FD, 0x8B8A, 0xAF80, 0x8010, 0x734F, 0x548A, 0xBE03, 0x9880,
2217 0xBC21, 0x7326, 0x548B, 0xBE03, 0x618B, 0x988C, 0xBE03, 0x6180, 0x9880, 0x7980, 0x03A1, 0x7A80,
2218 0x038A, 0x0D28, 0x4711, 0xE100, 0x02BE, 0xAF12, 0x4006, 0x6912, 0xBFB0, 0x0C00, 0xE388, 0x02B6,
2219 0xBFA0, 0x0800, 0xE388, 0x02B2, 0x6912, 0xBFB0, 0x0C00, 0xBFA0, 0x0400, 0xE388, 0x02A3, 0x6909,
2220 0x900B, 0x7980, 0x02A5, 0xAF0B, 0x4005, 0x6901, 0x9005, 0x6902, 0x9006, 0x4311, 0xE100, 0x02ED,
2221 0x6911, 0xBFC0, 0x2000, 0x9011, 0x7980, 0x02ED, 0x6909, 0x900B, 0x7980, 0x02B8, 0xAF0B, 0x4005,
2222 0xAF05, 0x4003, 0xAF06, 0x4004, 0x7980, 0x02ED, 0xAF12, 0x4006, 0x6912, 0xBFB0, 0x0C00, 0xE388,
2223 0x02E7, 0xBFA0, 0x0800, 0xE388, 0x02E3, 0x6912, 0xBFB0, 0x0C00, 0xBFA0, 0x0400, 0xE388, 0x02D4,
2224 0x690D, 0x9010, 0x7980, 0x02D6, 0xAF10, 0x4005, 0x6901, 0x9005, 0x6902, 0x9006, 0x4311, 0xE100,
2225 0x02ED, 0x6911, 0xBFC0, 0x2000, 0x9011, 0x7980, 0x02ED, 0x690D, 0x9010, 0x7980, 0x02E9, 0xAF10,
2226 0x4005, 0xAF05, 0x4003, 0xAF06, 0x4004, 0xBC20, 0x6970, 0x9071, 0x7A80, 0x0078, 0x6971, 0x9070,
2227 0x7980, 0x03A1, 0xBC20, 0x0361, 0x8B8B, 0x6980, 0xEF88, 0x0272, 0x0372, 0x7804, 0x9071, 0x0D71,
2228 0x8B8A, 0x000B, 0xB903, 0x8809, 0xBEC6, 0x0309, 0x69A8, 0x90AB, 0x69A8, 0x90AA, 0x0810, 0x660A,
2229 0xE344, 0x030F, 0x0009, 0x0810, 0x660C, 0xE388, 0x0314, 0x800B, 0xBC20, 0x6961, 0xB801, 0x9061,
2230 0x7980, 0x02F7, 0x7A80, 0x038A, 0x5D35, 0x0001, 0x6934, 0xB801, 0x9034, 0xBF0A, 0x109E, 0x8B8A,
2231 0xAF80, 0x8014, 0x4880, 0xAE72, 0x0550, 0xF500, 0xAE72, 0x0510, 0xAE61, 0x1051, 0x7A80, 0x02F6,
2232 0x7980, 0x03A1, 0x7A80, 0x038A, 0x5D35, 0x0002, 0x695E, 0xB801, 0x905E, 0xBF0A, 0x109E, 0x8B8A,
2233 0xAF80, 0x8014, 0x4780, 0xAE72, 0x0558, 0xF500, 0xAE72, 0x0518, 0xAE61, 0x105C, 0x7A80, 0x02F6,
2234 0x7980, 0x03A1, 0x001C, 0x8B88, 0x6980, 0xEF88, 0x901D, 0x0D1D, 0x100F, 0x6610, 0xE38C, 0x0358,
2235 0x690E, 0x6610, 0x620F, 0x660D, 0xBA0F, 0xE301, 0x037A, 0x0410, 0x8B8A, 0xB903, 0x8809, 0xBEC6,
2236 0x036C, 0x6A8C, 0x61AA, 0x98AB, 0x6A8C, 0x61AB, 0x98AD, 0x6A8C, 0x61AD, 0x98A9, 0x6A8C, 0x61A9,
2237 0x98AA, 0x7C04, 0x8B8B, 0x7C04, 0x8B8D, 0x7C04, 0x8B89, 0x7C04, 0x0814, 0x660E, 0xE308, 0x0379,
2238 0x040D, 0x8410, 0xBC21, 0x691C, 0xB801, 0x901C, 0x7980, 0x034A, 0xB903, 0x8809, 0x8B8A, 0xBEC6,
2239 0x0388, 0x54AC, 0xBE03, 0x618C, 0x98AA, 0xEF00, 0xBC20, 0xBE46, 0x0809, 0x906B, 0x080A, 0x906C,
2240 0x080B, 0x906D, 0x081A, 0x9062, 0x081B, 0x9063, 0x081E, 0x9064, 0xBE59, 0x881E, 0x8065, 0x8166,
2241 0x8267, 0x8368, 0x8469, 0x856A, 0xEF00, 0xBC20, 0x696B, 0x8809, 0x696C, 0x880A, 0x696D, 0x880B,
2242 0x6962, 0x881A, 0x6963, 0x881B, 0x6964, 0x881E, 0x0065, 0x0166, 0x0267, 0x0368, 0x0469, 0x056A,
2243 0xBE3A,
2244};
2245
2246/*
2247 * Mini sample rate converter code image
2248 * that is to be loaded at 0x400 on the DSP.
2249 */
2250static const u16 assp_minisrc_image[] __devinitdata = {
2251
2252 0xBF80, 0x101E, 0x906E, 0x006E, 0x8B88, 0x6980, 0xEF88, 0x906F, 0x0D6F, 0x6900, 0xEB08, 0x0412,
2253 0xBC20, 0x696E, 0xB801, 0x906E, 0x7980, 0x0403, 0xB90E, 0x8807, 0xBE43, 0xBF01, 0xBE47, 0xBE41,
2254 0x7A80, 0x002A, 0xBE40, 0x3029, 0xEFCC, 0xBE41, 0x7A80, 0x0028, 0xBE40, 0x3028, 0xEFCC, 0x6907,
2255 0xE308, 0x042A, 0x6909, 0x902C, 0x7980, 0x042C, 0x690D, 0x902C, 0x1009, 0x881A, 0x100A, 0xBA01,
2256 0x881B, 0x100D, 0x881C, 0x100E, 0xBA01, 0x881D, 0xBF80, 0x00ED, 0x881E, 0x050C, 0x0124, 0xB904,
2257 0x9027, 0x6918, 0xE308, 0x04B3, 0x902D, 0x6913, 0xBFA0, 0x7598, 0xF704, 0xAE2D, 0x00FF, 0x8B8D,
2258 0x6919, 0xE308, 0x0463, 0x691A, 0xE308, 0x0456, 0xB907, 0x8809, 0xBEC6, 0x0453, 0x10A9, 0x90AD,
2259 0x7980, 0x047C, 0xB903, 0x8809, 0xBEC6, 0x0460, 0x1889, 0x6C22, 0x90AD, 0x10A9, 0x6E23, 0x6C22,
2260 0x90AD, 0x7980, 0x047C, 0x101A, 0xE308, 0x046F, 0xB903, 0x8809, 0xBEC6, 0x046C, 0x10A9, 0x90A0,
2261 0x90AD, 0x7980, 0x047C, 0xB901, 0x8809, 0xBEC6, 0x047B, 0x1889, 0x6C22, 0x90A0, 0x90AD, 0x10A9,
2262 0x6E23, 0x6C22, 0x90A0, 0x90AD, 0x692D, 0xE308, 0x049C, 0x0124, 0xB703, 0xB902, 0x8818, 0x8B89,
2263 0x022C, 0x108A, 0x7C04, 0x90A0, 0x692B, 0x881F, 0x7E80, 0x055B, 0x692A, 0x8809, 0x8B89, 0x99A0,
2264 0x108A, 0x90A0, 0x692B, 0x881F, 0x7E80, 0x055B, 0x692A, 0x8809, 0x8B89, 0x99AF, 0x7B99, 0x0484,
2265 0x0124, 0x060F, 0x101B, 0x2013, 0x901B, 0xBFA0, 0x7FFF, 0xE344, 0x04AC, 0x901B, 0x8B89, 0x7A80,
2266 0x051A, 0x6927, 0xBA01, 0x9027, 0x7A80, 0x0523, 0x6927, 0xE308, 0x049E, 0x7980, 0x050F, 0x0624,
2267 0x1026, 0x2013, 0x9026, 0xBFA0, 0x7FFF, 0xE304, 0x04C0, 0x8B8D, 0x7A80, 0x051A, 0x7980, 0x04B4,
2268 0x9026, 0x1013, 0x3026, 0x901B, 0x8B8D, 0x7A80, 0x051A, 0x7A80, 0x0523, 0x1027, 0xBA01, 0x9027,
2269 0xE308, 0x04B4, 0x0124, 0x060F, 0x8B89, 0x691A, 0xE308, 0x04EA, 0x6919, 0xE388, 0x04E0, 0xB903,
2270 0x8809, 0xBEC6, 0x04DD, 0x1FA0, 0x2FAE, 0x98A9, 0x7980, 0x050F, 0xB901, 0x8818, 0xB907, 0x8809,
2271 0xBEC6, 0x04E7, 0x10EE, 0x90A9, 0x7980, 0x050F, 0x6919, 0xE308, 0x04FE, 0xB903, 0x8809, 0xBE46,
2272 0xBEC6, 0x04FA, 0x17A0, 0xBE1E, 0x1FAE, 0xBFBF, 0xFF00, 0xBE13, 0xBFDF, 0x8080, 0x99A9, 0xBE47,
2273 0x7980, 0x050F, 0xB901, 0x8809, 0xBEC6, 0x050E, 0x16A0, 0x26A0, 0xBFB7, 0xFF00, 0xBE1E, 0x1EA0,
2274 0x2EAE, 0xBFBF, 0xFF00, 0xBE13, 0xBFDF, 0x8080, 0x99A9, 0x850C, 0x860F, 0x6907, 0xE388, 0x0516,
2275 0x0D07, 0x8510, 0xBE59, 0x881E, 0xBE4A, 0xEF00, 0x101E, 0x901C, 0x101F, 0x901D, 0x10A0, 0x901E,
2276 0x10A0, 0x901F, 0xEF00, 0x101E, 0x301C, 0x9020, 0x731B, 0x5420, 0xBE03, 0x9825, 0x1025, 0x201C,
2277 0x9025, 0x7325, 0x5414, 0xBE03, 0x8B8E, 0x9880, 0x692F, 0xE388, 0x0539, 0xBE59, 0xBB07, 0x6180,
2278 0x9880, 0x8BA0, 0x101F, 0x301D, 0x9021, 0x731B, 0x5421, 0xBE03, 0x982E, 0x102E, 0x201D, 0x902E,
2279 0x732E, 0x5415, 0xBE03, 0x9880, 0x692F, 0xE388, 0x054F, 0xBE59, 0xBB07, 0x6180, 0x9880, 0x8BA0,
2280 0x6918, 0xEF08, 0x7325, 0x5416, 0xBE03, 0x98A0, 0x732E, 0x5417, 0xBE03, 0x98A0, 0xEF00, 0x8BA0,
2281 0xBEC6, 0x056B, 0xBE59, 0xBB04, 0xAA90, 0xBE04, 0xBE1E, 0x99E0, 0x8BE0, 0x69A0, 0x90D0, 0x69A0,
2282 0x90D0, 0x081F, 0xB805, 0x881F, 0x8B90, 0x69A0, 0x90D0, 0x69A0, 0x9090, 0x8BD0, 0x8BD8, 0xBE1F,
2283 0xEF00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
2284 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
2285};
2286
2287
2288/*
2289 * initialize ASSP
2290 */
2291
2292#define MINISRC_LPF_LEN 10
2293static const u16 minisrc_lpf[MINISRC_LPF_LEN] __devinitdata = {
2294 0X0743, 0X1104, 0X0A4C, 0XF88D, 0X242C,
2295 0X1023, 0X1AA9, 0X0B60, 0XEFDD, 0X186F
2296};
2297
2298static void __devinit snd_m3_assp_init(m3_t *chip)
2299{
2300 unsigned int i;
2301
2302 /* zero kernel data */
2303 for (i = 0; i < (REV_B_DATA_MEMORY_UNIT_LENGTH * NUM_UNITS_KERNEL_DATA) / 2; i++)
2304 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
2305 KDATA_BASE_ADDR + i, 0);
2306
2307 /* zero mixer data? */
2308 for (i = 0; i < (REV_B_DATA_MEMORY_UNIT_LENGTH * NUM_UNITS_KERNEL_DATA) / 2; i++)
2309 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
2310 KDATA_BASE_ADDR2 + i, 0);
2311
2312 /* init dma pointer */
2313 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
2314 KDATA_CURRENT_DMA,
2315 KDATA_DMA_XFER0);
2316
2317 /* write kernel into code memory.. */
2318 for (i = 0 ; i < sizeof(assp_kernel_image) / 2; i++) {
2319 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE,
2320 REV_B_CODE_MEMORY_BEGIN + i,
2321 assp_kernel_image[i]);
2322 }
2323
2324 /*
2325 * We only have this one client and we know that 0x400
2326 * is free in our kernel's mem map, so lets just
2327 * drop it there. It seems that the minisrc doesn't
2328 * need vectors, so we won't bother with them..
2329 */
2330 for (i = 0; i < sizeof(assp_minisrc_image) / 2; i++) {
2331 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE,
2332 0x400 + i,
2333 assp_minisrc_image[i]);
2334 }
2335
2336 /*
2337 * write the coefficients for the low pass filter?
2338 */
2339 for (i = 0; i < MINISRC_LPF_LEN ; i++) {
2340 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE,
2341 0x400 + MINISRC_COEF_LOC + i,
2342 minisrc_lpf[i]);
2343 }
2344
2345 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE,
2346 0x400 + MINISRC_COEF_LOC + MINISRC_LPF_LEN,
2347 0x8000);
2348
2349 /*
2350 * the minisrc is the only thing on
2351 * our task list..
2352 */
2353 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
2354 KDATA_TASK0,
2355 0x400);
2356
2357 /*
2358 * init the mixer number..
2359 */
2360
2361 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
2362 KDATA_MIXER_TASK_NUMBER,0);
2363
2364 /*
2365 * EXTREME KERNEL MASTER VOLUME
2366 */
2367 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
2368 KDATA_DAC_LEFT_VOLUME, ARB_VOLUME);
2369 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
2370 KDATA_DAC_RIGHT_VOLUME, ARB_VOLUME);
2371
2372 chip->mixer_list.curlen = 0;
2373 chip->mixer_list.mem_addr = KDATA_MIXER_XFER0;
2374 chip->mixer_list.max = MAX_VIRTUAL_MIXER_CHANNELS;
2375 chip->adc1_list.curlen = 0;
2376 chip->adc1_list.mem_addr = KDATA_ADC1_XFER0;
2377 chip->adc1_list.max = MAX_VIRTUAL_ADC1_CHANNELS;
2378 chip->dma_list.curlen = 0;
2379 chip->dma_list.mem_addr = KDATA_DMA_XFER0;
2380 chip->dma_list.max = MAX_VIRTUAL_DMA_CHANNELS;
2381 chip->msrc_list.curlen = 0;
2382 chip->msrc_list.mem_addr = KDATA_INSTANCE0_MINISRC;
2383 chip->msrc_list.max = MAX_INSTANCE_MINISRC;
2384}
2385
2386
2387static int __devinit snd_m3_assp_client_init(m3_t *chip, m3_dma_t *s, int index)
2388{
2389 int data_bytes = 2 * ( MINISRC_TMP_BUFFER_SIZE / 2 +
2390 MINISRC_IN_BUFFER_SIZE / 2 +
2391 1 + MINISRC_OUT_BUFFER_SIZE / 2 + 1 );
2392 int address, i;
2393
2394 /*
2395 * the revb memory map has 0x1100 through 0x1c00
2396 * free.
2397 */
2398
2399 /*
2400 * align instance address to 256 bytes so that its
2401 * shifted list address is aligned.
2402 * list address = (mem address >> 1) >> 7;
2403 */
2404 data_bytes = (data_bytes + 255) & ~255;
2405 address = 0x1100 + ((data_bytes/2) * index);
2406
2407 if ((address + (data_bytes/2)) >= 0x1c00) {
2408 snd_printk("no memory for %d bytes at ind %d (addr 0x%x)\n",
2409 data_bytes, index, address);
2410 return -ENOMEM;
2411 }
2412
2413 s->number = index;
2414 s->inst.code = 0x400;
2415 s->inst.data = address;
2416
2417 for (i = data_bytes / 2; i > 0; address++, i--) {
2418 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
2419 address, 0);
2420 }
2421
2422 return 0;
2423}
2424
2425
2426/*
2427 * this works for the reference board, have to find
2428 * out about others
2429 *
2430 * this needs more magic for 4 speaker, but..
2431 */
2432static void
2433snd_m3_amp_enable(m3_t *chip, int enable)
2434{
2435 int io = chip->iobase;
2436 u16 gpo, polarity;
2437
2438 if (! chip->external_amp)
2439 return;
2440
2441 polarity = enable ? 0 : 1;
2442 polarity = polarity << chip->amp_gpio;
2443 gpo = 1 << chip->amp_gpio;
2444
2445 outw(~gpo, io + GPIO_MASK);
2446
2447 outw(inw(io + GPIO_DIRECTION) | gpo,
2448 io + GPIO_DIRECTION);
2449
2450 outw((GPO_SECONDARY_AC97 | GPO_PRIMARY_AC97 | polarity),
2451 io + GPIO_DATA);
2452
2453 outw(0xffff, io + GPIO_MASK);
2454}
2455
2456static int
2457snd_m3_chip_init(m3_t *chip)
2458{
2459 struct pci_dev *pcidev = chip->pci;
2460 unsigned long io = chip->iobase;
2461 u32 n;
2462 u16 w;
2463 u8 t; /* makes as much sense as 'n', no? */
2464
2465 pci_read_config_word(pcidev, PCI_LEGACY_AUDIO_CTRL, &w);
2466 w &= ~(SOUND_BLASTER_ENABLE|FM_SYNTHESIS_ENABLE|
2467 MPU401_IO_ENABLE|MPU401_IRQ_ENABLE|ALIAS_10BIT_IO|
2468 DISABLE_LEGACY);
2469 pci_write_config_word(pcidev, PCI_LEGACY_AUDIO_CTRL, w);
2470
2471 if (chip->hv_quirk && chip->hv_quirk->is_omnibook) {
2472 /*
2473 * Volume buttons on some HP OmniBook laptops don't work
2474 * correctly. This makes them work for the most part.
2475 *
2476 * Volume up and down buttons on the laptop side work.
2477 * Fn+cursor_up (volme up) works.
2478 * Fn+cursor_down (volume down) doesn't work.
2479 * Fn+F7 (mute) works acts as volume up.
2480 */
2481 outw(~(GPI_VOL_DOWN|GPI_VOL_UP), io + GPIO_MASK);
2482 outw(inw(io + GPIO_DIRECTION) & ~(GPI_VOL_DOWN|GPI_VOL_UP), io + GPIO_DIRECTION);
2483 outw((GPI_VOL_DOWN|GPI_VOL_UP), io + GPIO_DATA);
2484 outw(0xffff, io + GPIO_MASK);
2485 }
2486 pci_read_config_dword(pcidev, PCI_ALLEGRO_CONFIG, &n);
2487 n &= ~(HV_CTRL_ENABLE | REDUCED_DEBOUNCE | HV_BUTTON_FROM_GD);
2488 if (chip->hv_quirk)
2489 n |= chip->hv_quirk->config;
2490 /* For some reason we must always use reduced debounce. */
2491 n |= REDUCED_DEBOUNCE;
2492 n |= PM_CTRL_ENABLE | CLK_DIV_BY_49 | USE_PCI_TIMING;
2493 pci_write_config_dword(pcidev, PCI_ALLEGRO_CONFIG, n);
2494
2495 outb(RESET_ASSP, chip->iobase + ASSP_CONTROL_B);
2496 pci_read_config_dword(pcidev, PCI_ALLEGRO_CONFIG, &n);
2497 n &= ~INT_CLK_SELECT;
2498 if (!chip->allegro_flag) {
2499 n &= ~INT_CLK_MULT_ENABLE;
2500 n |= INT_CLK_SRC_NOT_PCI;
2501 }
2502 n &= ~( CLK_MULT_MODE_SELECT | CLK_MULT_MODE_SELECT_2 );
2503 pci_write_config_dword(pcidev, PCI_ALLEGRO_CONFIG, n);
2504
2505 if (chip->allegro_flag) {
2506 pci_read_config_dword(pcidev, PCI_USER_CONFIG, &n);
2507 n |= IN_CLK_12MHZ_SELECT;
2508 pci_write_config_dword(pcidev, PCI_USER_CONFIG, n);
2509 }
2510
2511 t = inb(chip->iobase + ASSP_CONTROL_A);
2512 t &= ~( DSP_CLK_36MHZ_SELECT | ASSP_CLK_49MHZ_SELECT);
2513 t |= ASSP_CLK_49MHZ_SELECT;
2514 t |= ASSP_0_WS_ENABLE;
2515 outb(t, chip->iobase + ASSP_CONTROL_A);
2516
2517 snd_m3_assp_init(chip); /* download DSP code before starting ASSP below */
2518 outb(RUN_ASSP, chip->iobase + ASSP_CONTROL_B);
2519 outb(0x00, io + HARDWARE_VOL_CTRL);
2520 outb(0x88, io + SHADOW_MIX_REG_VOICE);
2521 outb(0x88, io + HW_VOL_COUNTER_VOICE);
2522 outb(0x88, io + SHADOW_MIX_REG_MASTER);
2523 outb(0x88, io + HW_VOL_COUNTER_MASTER);
2524 return 0;
2525}
2526
2527static void
2528snd_m3_enable_ints(m3_t *chip)
2529{
2530 unsigned long io = chip->iobase;
2531 unsigned short val;
2532
2533 /* TODO: MPU401 not supported yet */
2534 val = ASSP_INT_ENABLE /*| MPU401_INT_ENABLE*/;
2535 if (chip->hv_quirk && (chip->hv_quirk->config & HV_CTRL_ENABLE))
2536 val |= HV_INT_ENABLE;
2537 outw(val, io + HOST_INT_CTRL);
2538 outb(inb(io + ASSP_CONTROL_C) | ASSP_HOST_INT_ENABLE,
2539 io + ASSP_CONTROL_C);
2540}
2541
2542
2543/*
2544 */
2545
2546static int snd_m3_free(m3_t *chip)
2547{
2548 m3_dma_t *s;
2549 int i;
2550
2551 if (chip->substreams) {
2552 spin_lock_irq(&chip->reg_lock);
2553 for (i = 0; i < chip->num_substreams; i++) {
2554 s = &chip->substreams[i];
2555 /* check surviving pcms; this should not happen though.. */
2556 if (s->substream && s->running)
2557 snd_m3_pcm_stop(chip, s, s->substream);
2558 }
2559 spin_unlock_irq(&chip->reg_lock);
2560 kfree(chip->substreams);
2561 }
2562 if (chip->iobase) {
2563 outw(0, chip->iobase + HOST_INT_CTRL); /* disable ints */
2564 }
2565
2566#ifdef CONFIG_PM
2567 if (chip->suspend_mem)
2568 vfree(chip->suspend_mem);
2569#endif
2570
2571 if (chip->irq >= 0) {
2572 synchronize_irq(chip->irq);
2573 free_irq(chip->irq, (void *)chip);
2574 }
2575 if (chip->iobase)
2576 pci_release_regions(chip->pci);
2577 kfree(chip);
2578 return 0;
2579}
2580
2581
2582/*
2583 * APM support
2584 */
2585#ifdef CONFIG_PM
2586
2587static int m3_suspend(snd_card_t *card, unsigned int state)
2588{
2589 m3_t *chip = card->pm_private_data;
2590 int i, index;
2591
2592 if (chip->suspend_mem == NULL)
2593 return 0;
2594
2595 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
2596 snd_pcm_suspend_all(chip->pcm);
2597 snd_ac97_suspend(chip->ac97);
2598
2599 msleep(10); /* give the assp a chance to idle.. */
2600
2601 snd_m3_assp_halt(chip);
2602
2603 /* save dsp image */
2604 index = 0;
2605 for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++)
2606 chip->suspend_mem[index++] =
2607 snd_m3_assp_read(chip, MEMTYPE_INTERNAL_CODE, i);
2608 for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++)
2609 chip->suspend_mem[index++] =
2610 snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA, i);
2611
2612 /* power down apci registers */
2613 snd_m3_outw(chip, 0xffff, 0x54);
2614 snd_m3_outw(chip, 0xffff, 0x56);
2615 pci_disable_device(chip->pci);
2616 pci_save_state(chip->pci);
2617 return 0;
2618}
2619
2620static int m3_resume(snd_card_t *card, unsigned int state)
2621{
2622 m3_t *chip = card->pm_private_data;
2623 int i, index;
2624
2625 if (chip->suspend_mem == NULL)
2626 return 0;
2627
2628 pci_restore_state(chip->pci);
2629 pci_enable_device(chip->pci);
2630 pci_set_master(chip->pci);
2631
2632 /* first lets just bring everything back. .*/
2633 snd_m3_outw(chip, 0, 0x54);
2634 snd_m3_outw(chip, 0, 0x56);
2635
2636 snd_m3_chip_init(chip);
2637 snd_m3_assp_halt(chip);
2638 snd_m3_ac97_reset(chip);
2639
2640 /* restore dsp image */
2641 index = 0;
2642 for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++)
2643 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE, i,
2644 chip->suspend_mem[index++]);
2645 for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++)
2646 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, i,
2647 chip->suspend_mem[index++]);
2648
2649 /* tell the dma engine to restart itself */
2650 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
2651 KDATA_DMA_ACTIVE, 0);
2652
2653 /* restore ac97 registers */
2654 snd_ac97_resume(chip->ac97);
2655
2656 snd_m3_assp_continue(chip);
2657 snd_m3_enable_ints(chip);
2658 snd_m3_amp_enable(chip, 1);
2659
2660 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
2661 return 0;
2662}
2663#endif /* CONFIG_PM */
2664
2665
2666/*
2667 */
2668
2669static int snd_m3_dev_free(snd_device_t *device)
2670{
2671 m3_t *chip = device->device_data;
2672 return snd_m3_free(chip);
2673}
2674
2675static int __devinit
2676snd_m3_create(snd_card_t *card, struct pci_dev *pci,
2677 int enable_amp,
2678 int amp_gpio,
2679 m3_t **chip_ret)
2680{
2681 m3_t *chip;
2682 int i, err;
2683 const struct m3_quirk *quirk;
2684 const struct m3_hv_quirk *hv_quirk;
2685 static struct snd_device_ops ops = {
2686 .dev_free = snd_m3_dev_free,
2687 };
2688
2689 *chip_ret = NULL;
2690
2691 if (pci_enable_device(pci))
2692 return -EIO;
2693
2694 /* check, if we can restrict PCI DMA transfers to 28 bits */
2695 if (!pci_dma_supported(pci, 0x0fffffff)) {
2696 snd_printk("architecture does not support 28bit PCI busmaster DMA\n");
2697 return -ENXIO;
2698 }
2699 pci_set_consistent_dma_mask(pci, 0x0fffffff);
2700
2701 chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
2702 if (chip == NULL)
2703 return -ENOMEM;
2704
2705 spin_lock_init(&chip->reg_lock);
2706 spin_lock_init(&chip->ac97_lock);
2707
2708 switch (pci->device) {
2709 case PCI_DEVICE_ID_ESS_ALLEGRO:
2710 case PCI_DEVICE_ID_ESS_ALLEGRO_1:
2711 case PCI_DEVICE_ID_ESS_CANYON3D_2LE:
2712 case PCI_DEVICE_ID_ESS_CANYON3D_2:
2713 chip->allegro_flag = 1;
2714 break;
2715 }
2716
2717 chip->card = card;
2718 chip->pci = pci;
2719 chip->irq = -1;
2720
2721 for (quirk = m3_quirk_list; quirk->vendor; quirk++) {
2722 if (pci->subsystem_vendor == quirk->vendor &&
2723 pci->subsystem_device == quirk->device) {
2724 snd_printk("maestro3: enabled hack for '%s'\n", quirk->name);
2725 chip->quirk = quirk;
2726 break;
2727 }
2728 }
2729
2730 for (hv_quirk = m3_hv_quirk_list; hv_quirk->vendor; hv_quirk++) {
2731 if (pci->vendor == hv_quirk->vendor &&
2732 pci->device == hv_quirk->device &&
2733 pci->subsystem_vendor == hv_quirk->subsystem_vendor &&
2734 pci->subsystem_device == hv_quirk->subsystem_device) {
2735 chip->hv_quirk = hv_quirk;
2736 break;
2737 }
2738 }
2739
2740 chip->external_amp = enable_amp;
2741 if (amp_gpio >= 0 && amp_gpio <= 0x0f)
2742 chip->amp_gpio = amp_gpio;
2743 else if (chip->quirk && chip->quirk->amp_gpio >= 0)
2744 chip->amp_gpio = chip->quirk->amp_gpio;
2745 else if (chip->allegro_flag)
2746 chip->amp_gpio = GPO_EXT_AMP_ALLEGRO;
2747 else /* presumably this is for all 'maestro3's.. */
2748 chip->amp_gpio = GPO_EXT_AMP_M3;
2749
2750 chip->num_substreams = NR_DSPS;
2751 chip->substreams = kmalloc(sizeof(m3_dma_t) * chip->num_substreams, GFP_KERNEL);
2752 if (chip->substreams == NULL) {
2753 kfree(chip);
2754 return -ENOMEM;
2755 }
2756 memset(chip->substreams, 0, sizeof(m3_dma_t) * chip->num_substreams);
2757
2758 if ((err = pci_request_regions(pci, card->driver)) < 0) {
2759 snd_m3_free(chip);
2760 return err;
2761 }
2762 chip->iobase = pci_resource_start(pci, 0);
2763
2764 /* just to be sure */
2765 pci_set_master(pci);
2766
2767 snd_m3_chip_init(chip);
2768 snd_m3_assp_halt(chip);
2769
2770 snd_m3_ac97_reset(chip);
2771
2772 snd_m3_amp_enable(chip, 1);
2773
2774 if ((err = snd_m3_mixer(chip)) < 0) {
2775 snd_m3_free(chip);
2776 return err;
2777 }
2778
2779 for (i = 0; i < chip->num_substreams; i++) {
2780 m3_dma_t *s = &chip->substreams[i];
2781 s->chip = chip;
2782 if ((err = snd_m3_assp_client_init(chip, s, i)) < 0) {
2783 snd_m3_free(chip);
2784 return err;
2785 }
2786 }
2787
2788 if ((err = snd_m3_pcm(chip, 0)) < 0) {
2789 snd_m3_free(chip);
2790 return err;
2791 }
2792
2793 tasklet_init(&chip->hwvol_tq, snd_m3_update_hw_volume, (unsigned long)chip);
2794
2795 if (request_irq(pci->irq, snd_m3_interrupt, SA_INTERRUPT|SA_SHIRQ,
2796 card->driver, (void *)chip)) {
2797 snd_printk("unable to grab IRQ %d\n", pci->irq);
2798 snd_m3_free(chip);
2799 return -ENOMEM;
2800 }
2801 chip->irq = pci->irq;
2802
2803#ifdef CONFIG_PM
2804 chip->suspend_mem = vmalloc(sizeof(u16) * (REV_B_CODE_MEMORY_LENGTH + REV_B_DATA_MEMORY_LENGTH));
2805 if (chip->suspend_mem == NULL)
2806 snd_printk("can't allocate apm buffer\n");
2807#endif
2808
2809 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
2810 snd_m3_free(chip);
2811 return err;
2812 }
2813
2814 snd_m3_enable_ints(chip);
2815 snd_m3_assp_continue(chip);
2816
2817 *chip_ret = chip;
2818
2819 return 0;
2820}
2821
2822/*
2823 */
2824static int __devinit
2825snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2826{
2827 static int dev;
2828 snd_card_t *card;
2829 m3_t *chip;
2830 int err;
2831
2832 pci_read_config_dword(pci, PCI_CLASS_REVISION, &pci->_class);
2833
2834#if 0 // os/2 doesnt pickup classes
2835 /* don't pick up modems */
2836#ifdef TARGET_OS2
2837 if (((pci->_class >> 8) & 0xffff) != PCI_CLASS_MULTIMEDIA_AUDIO)
2838#else
2839 if (((pci->class >> 8) & 0xffff) != PCI_CLASS_MULTIMEDIA_AUDIO)
2840#endif
2841 return -ENODEV;
2842#endif // 0
2843
2844 if (dev >= SNDRV_CARDS)
2845 return -ENODEV;
2846 if (!enable[dev]) {
2847 dev++;
2848 return -ENOENT;
2849 }
2850 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2851 if (card == NULL)
2852 return -ENOMEM;
2853
2854 switch (pci->device) {
2855 case PCI_DEVICE_ID_ESS_ALLEGRO:
2856 case PCI_DEVICE_ID_ESS_ALLEGRO_1:
2857 strcpy(card->driver, "Allegro");
2858 break;
2859 case PCI_DEVICE_ID_ESS_CANYON3D_2LE:
2860 case PCI_DEVICE_ID_ESS_CANYON3D_2:
2861 strcpy(card->driver, "Canyon3D-2");
2862 break;
2863 default:
2864 strcpy(card->driver, "Maestro3");
2865 break;
2866 }
2867
2868 if ((err = snd_m3_create(card, pci,
2869 external_amp[dev],
2870 amp_gpio[dev],
2871 &chip)) < 0) {
2872 snd_card_free(card);
2873 return err;
2874 }
2875#ifdef DEBUG
2876 dprintf(("m3_probe: create passed"));
2877#endif
2878
2879 sprintf(card->shortname, "ESS %s PCI", card->driver);
2880 sprintf(card->longname, "%s at 0x%lx, irq %d",
2881 card->shortname, chip->iobase, chip->irq);
2882
2883 if ((err = snd_card_register(card)) < 0) {
2884 snd_card_free(card);
2885 return err;
2886 }
2887
2888#if 0 /* TODO: not supported yet */
2889 /* TODO enable MIDI IRQ and I/O */
2890 err = snd_mpu401_uart_new(chip->card, 0, MPU401_HW_MPU401,
2891 chip->iobase + MPU401_DATA_PORT,
2892 MPU401_INFO_INTEGRATED,
2893 chip->irq, 0, &chip->rmidi);
2894 if (err < 0)
2895 printk(KERN_WARNING "maestro3: no MIDI support.\n");
2896#endif
2897
2898 pci_set_drvdata(pci, card);
2899 dev++;
2900 return 0;
2901}
2902
2903static void __devexit snd_m3_remove(struct pci_dev *pci)
2904{
2905 snd_card_free(pci_get_drvdata(pci));
2906 pci_set_drvdata(pci, NULL);
2907}
2908
2909static struct pci_driver driver = {
2910 .name = "Maestro3",
2911 .id_table = snd_m3_ids,
2912 .probe = snd_m3_probe,
2913 .remove = __devexit_p(snd_m3_remove),
2914#ifdef CONFIG_PM
2915 .suspend = m3_suspend,
2916 .resume = m3_resume,
2917#endif
2918};
2919
2920static int __init alsa_card_m3_init(void)
2921{
2922 int err;
2923
2924 if ((err = pci_module_init(&driver)) < 0) {
2925#ifdef MODULE
2926 // snd_printk("Maestro3/Allegro soundcard not found or device busy\n");
2927#endif
2928 return err;
2929 }
2930 return 0;
2931}
2932
2933static void __exit alsa_card_m3_exit(void)
2934{
2935 pci_unregister_driver(&driver);
2936}
2937
2938module_init(alsa_card_m3_init)
2939module_exit(alsa_card_m3_exit)
2940
2941#ifndef MODULE
2942
2943/* format is: snd-maestro3=enable,index,id,external_amp,amp_gpio */
2944
2945static int __init alsa_card_maestro3_setup(char *str)
2946{
2947 static unsigned __initdata nr_dev = 0;
2948
2949 if (nr_dev >= SNDRV_CARDS)
2950 return 0;
2951 (void)(get_option(&str,&enable[nr_dev]) == 2 &&
2952 get_option(&str,&index[nr_dev]) == 2 &&
2953 get_id(&str,&id[nr_dev]) == 2 &&
2954 get_option(&str,&external_amp[nr_dev]) == 2 &&
2955 get_option(&str,&amp_gpio[nr_dev]) == 2);
2956 nr_dev++;
2957 return 1;
2958}
2959
2960__setup("snd-maestro3=", alsa_card_maestro3_setup);
2961
2962#endif /* ifndef MODULE */
Note: See TracBrowser for help on using the repository browser.