blob: c73d8a5f4d0b2b10f4552c7147722bd12ad407ce [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef __SOUND_YMFPCI_H
3#define __SOUND_YMFPCI_H
4
5/*
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02006 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Definitions for Yahama YMF724/740/744/754 chips
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
Takashi Iwai81fcb172012-07-02 16:37:05 +020010#include <sound/pcm.h>
11#include <sound/rawmidi.h>
12#include <sound/ac97_codec.h>
13#include <sound/timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/gameport.h>
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016/*
17 * Direct registers
18 */
19
20#define YMFREG(chip, reg) (chip->port + YDSXGR_##reg)
21
22#define YDSXGR_INTFLAG 0x0004
23#define YDSXGR_ACTIVITY 0x0006
24#define YDSXGR_GLOBALCTRL 0x0008
25#define YDSXGR_ZVCTRL 0x000A
26#define YDSXGR_TIMERCTRL 0x0010
27#define YDSXGR_TIMERCOUNT 0x0012
28#define YDSXGR_SPDIFOUTCTRL 0x0018
29#define YDSXGR_SPDIFOUTSTATUS 0x001C
30#define YDSXGR_EEPROMCTRL 0x0020
31#define YDSXGR_SPDIFINCTRL 0x0034
32#define YDSXGR_SPDIFINSTATUS 0x0038
33#define YDSXGR_DSPPROGRAMDL 0x0048
34#define YDSXGR_DLCNTRL 0x004C
35#define YDSXGR_GPIOININTFLAG 0x0050
36#define YDSXGR_GPIOININTENABLE 0x0052
37#define YDSXGR_GPIOINSTATUS 0x0054
38#define YDSXGR_GPIOOUTCTRL 0x0056
39#define YDSXGR_GPIOFUNCENABLE 0x0058
40#define YDSXGR_GPIOTYPECONFIG 0x005A
41#define YDSXGR_AC97CMDDATA 0x0060
42#define YDSXGR_AC97CMDADR 0x0062
43#define YDSXGR_PRISTATUSDATA 0x0064
44#define YDSXGR_PRISTATUSADR 0x0066
45#define YDSXGR_SECSTATUSDATA 0x0068
46#define YDSXGR_SECSTATUSADR 0x006A
47#define YDSXGR_SECCONFIG 0x0070
48#define YDSXGR_LEGACYOUTVOL 0x0080
49#define YDSXGR_LEGACYOUTVOLL 0x0080
50#define YDSXGR_LEGACYOUTVOLR 0x0082
51#define YDSXGR_NATIVEDACOUTVOL 0x0084
52#define YDSXGR_NATIVEDACOUTVOLL 0x0084
53#define YDSXGR_NATIVEDACOUTVOLR 0x0086
54#define YDSXGR_ZVOUTVOL 0x0088
55#define YDSXGR_ZVOUTVOLL 0x0088
56#define YDSXGR_ZVOUTVOLR 0x008A
57#define YDSXGR_SECADCOUTVOL 0x008C
58#define YDSXGR_SECADCOUTVOLL 0x008C
59#define YDSXGR_SECADCOUTVOLR 0x008E
60#define YDSXGR_PRIADCOUTVOL 0x0090
61#define YDSXGR_PRIADCOUTVOLL 0x0090
62#define YDSXGR_PRIADCOUTVOLR 0x0092
63#define YDSXGR_LEGACYLOOPVOL 0x0094
64#define YDSXGR_LEGACYLOOPVOLL 0x0094
65#define YDSXGR_LEGACYLOOPVOLR 0x0096
66#define YDSXGR_NATIVEDACLOOPVOL 0x0098
67#define YDSXGR_NATIVEDACLOOPVOLL 0x0098
68#define YDSXGR_NATIVEDACLOOPVOLR 0x009A
69#define YDSXGR_ZVLOOPVOL 0x009C
70#define YDSXGR_ZVLOOPVOLL 0x009E
71#define YDSXGR_ZVLOOPVOLR 0x009E
72#define YDSXGR_SECADCLOOPVOL 0x00A0
73#define YDSXGR_SECADCLOOPVOLL 0x00A0
74#define YDSXGR_SECADCLOOPVOLR 0x00A2
75#define YDSXGR_PRIADCLOOPVOL 0x00A4
76#define YDSXGR_PRIADCLOOPVOLL 0x00A4
77#define YDSXGR_PRIADCLOOPVOLR 0x00A6
78#define YDSXGR_NATIVEADCINVOL 0x00A8
79#define YDSXGR_NATIVEADCINVOLL 0x00A8
80#define YDSXGR_NATIVEADCINVOLR 0x00AA
81#define YDSXGR_NATIVEDACINVOL 0x00AC
82#define YDSXGR_NATIVEDACINVOLL 0x00AC
83#define YDSXGR_NATIVEDACINVOLR 0x00AE
84#define YDSXGR_BUF441OUTVOL 0x00B0
85#define YDSXGR_BUF441OUTVOLL 0x00B0
86#define YDSXGR_BUF441OUTVOLR 0x00B2
87#define YDSXGR_BUF441LOOPVOL 0x00B4
88#define YDSXGR_BUF441LOOPVOLL 0x00B4
89#define YDSXGR_BUF441LOOPVOLR 0x00B6
90#define YDSXGR_SPDIFOUTVOL 0x00B8
91#define YDSXGR_SPDIFOUTVOLL 0x00B8
92#define YDSXGR_SPDIFOUTVOLR 0x00BA
93#define YDSXGR_SPDIFLOOPVOL 0x00BC
94#define YDSXGR_SPDIFLOOPVOLL 0x00BC
95#define YDSXGR_SPDIFLOOPVOLR 0x00BE
96#define YDSXGR_ADCSLOTSR 0x00C0
97#define YDSXGR_RECSLOTSR 0x00C4
98#define YDSXGR_ADCFORMAT 0x00C8
99#define YDSXGR_RECFORMAT 0x00CC
100#define YDSXGR_P44SLOTSR 0x00D0
101#define YDSXGR_STATUS 0x0100
102#define YDSXGR_CTRLSELECT 0x0104
103#define YDSXGR_MODE 0x0108
104#define YDSXGR_SAMPLECOUNT 0x010C
105#define YDSXGR_NUMOFSAMPLES 0x0110
106#define YDSXGR_CONFIG 0x0114
107#define YDSXGR_PLAYCTRLSIZE 0x0140
108#define YDSXGR_RECCTRLSIZE 0x0144
109#define YDSXGR_EFFCTRLSIZE 0x0148
110#define YDSXGR_WORKSIZE 0x014C
111#define YDSXGR_MAPOFREC 0x0150
112#define YDSXGR_MAPOFEFFECT 0x0154
113#define YDSXGR_PLAYCTRLBASE 0x0158
114#define YDSXGR_RECCTRLBASE 0x015C
115#define YDSXGR_EFFCTRLBASE 0x0160
116#define YDSXGR_WORKBASE 0x0164
117#define YDSXGR_DSPINSTRAM 0x1000
118#define YDSXGR_CTRLINSTRAM 0x4000
119
120#define YDSXG_AC97READCMD 0x8000
121#define YDSXG_AC97WRITECMD 0x0000
122
123#define PCIR_DSXG_LEGACY 0x40
124#define PCIR_DSXG_ELEGACY 0x42
125#define PCIR_DSXG_CTRL 0x48
126#define PCIR_DSXG_PWRCTRL1 0x4a
127#define PCIR_DSXG_PWRCTRL2 0x4e
128#define PCIR_DSXG_FMBASE 0x60
129#define PCIR_DSXG_SBBASE 0x62
130#define PCIR_DSXG_MPU401BASE 0x64
131#define PCIR_DSXG_JOYBASE 0x66
132
133#define YDSXG_DSPLENGTH 0x0080
134#define YDSXG_CTRLLENGTH 0x3000
135
136#define YDSXG_DEFAULT_WORK_SIZE 0x0400
137
138#define YDSXG_PLAYBACK_VOICES 64
139#define YDSXG_CAPTURE_VOICES 2
140#define YDSXG_EFFECT_VOICES 5
141
142#define YMFPCI_LEGACY_SBEN (1 << 0) /* soundblaster enable */
143#define YMFPCI_LEGACY_FMEN (1 << 1) /* OPL3 enable */
144#define YMFPCI_LEGACY_JPEN (1 << 2) /* joystick enable */
145#define YMFPCI_LEGACY_MEN (1 << 3) /* MPU401 enable */
146#define YMFPCI_LEGACY_MIEN (1 << 4) /* MPU RX irq enable */
147#define YMFPCI_LEGACY_IOBITS (1 << 5) /* i/o bits range, 0 = 16bit, 1 =10bit */
148#define YMFPCI_LEGACY_SDMA (3 << 6) /* SB DMA select */
149#define YMFPCI_LEGACY_SBIRQ (7 << 8) /* SB IRQ select */
150#define YMFPCI_LEGACY_MPUIRQ (7 << 11) /* MPU IRQ select */
151#define YMFPCI_LEGACY_SIEN (1 << 14) /* serialized IRQ */
152#define YMFPCI_LEGACY_LAD (1 << 15) /* legacy audio disable */
153
154#define YMFPCI_LEGACY2_FMIO (3 << 0) /* OPL3 i/o address (724/740) */
155#define YMFPCI_LEGACY2_SBIO (3 << 2) /* SB i/o address (724/740) */
156#define YMFPCI_LEGACY2_MPUIO (3 << 4) /* MPU401 i/o address (724/740) */
157#define YMFPCI_LEGACY2_JSIO (3 << 6) /* joystick i/o address (724/740) */
158#define YMFPCI_LEGACY2_MAIM (1 << 8) /* MPU401 ack intr mask */
159#define YMFPCI_LEGACY2_SMOD (3 << 11) /* SB DMA mode */
160#define YMFPCI_LEGACY2_SBVER (3 << 13) /* SB version select */
161#define YMFPCI_LEGACY2_IMOD (1 << 15) /* legacy IRQ mode */
162/* SIEN:IMOD 0:0 = legacy irq, 0:1 = INTA, 1:0 = serialized IRQ */
163
Fabian Frederickb2fac072016-11-12 23:26:41 +0100164#if IS_REACHABLE(CONFIG_GAMEPORT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165#define SUPPORT_JOYSTICK
166#endif
167
168/*
169 *
170 */
171
Takashi Iwai208a1b42005-11-17 14:53:41 +0100172struct snd_ymfpci_playback_bank {
Takashi Iwaid3c63762018-07-25 23:24:01 +0200173 __le32 format;
174 __le32 loop_default;
175 __le32 base; /* 32-bit address */
176 __le32 loop_start; /* 32-bit offset */
177 __le32 loop_end; /* 32-bit offset */
178 __le32 loop_frac; /* 8-bit fraction - loop_start */
179 __le32 delta_end; /* pitch delta end */
180 __le32 lpfK_end;
181 __le32 eg_gain_end;
182 __le32 left_gain_end;
183 __le32 right_gain_end;
184 __le32 eff1_gain_end;
185 __le32 eff2_gain_end;
186 __le32 eff3_gain_end;
187 __le32 lpfQ;
188 __le32 status;
189 __le32 num_of_frames;
190 __le32 loop_count;
191 __le32 start;
192 __le32 start_frac;
193 __le32 delta;
194 __le32 lpfK;
195 __le32 eg_gain;
196 __le32 left_gain;
197 __le32 right_gain;
198 __le32 eff1_gain;
199 __le32 eff2_gain;
200 __le32 eff3_gain;
201 __le32 lpfD1;
202 __le32 lpfD2;
Takashi Iwai208a1b42005-11-17 14:53:41 +0100203 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Takashi Iwai208a1b42005-11-17 14:53:41 +0100205struct snd_ymfpci_capture_bank {
Takashi Iwaid3c63762018-07-25 23:24:01 +0200206 __le32 base; /* 32-bit address */
207 __le32 loop_end; /* 32-bit offset */
208 __le32 start; /* 32-bit offset */
209 __le32 num_of_loops; /* counter */
Takashi Iwai208a1b42005-11-17 14:53:41 +0100210};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Takashi Iwai208a1b42005-11-17 14:53:41 +0100212struct snd_ymfpci_effect_bank {
Takashi Iwaid3c63762018-07-25 23:24:01 +0200213 __le32 base; /* 32-bit address */
214 __le32 loop_end; /* 32-bit offset */
215 __le32 start; /* 32-bit offset */
216 __le32 temp;
Takashi Iwai208a1b42005-11-17 14:53:41 +0100217};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Takashi Iwai208a1b42005-11-17 14:53:41 +0100219struct snd_ymfpci_pcm;
220struct snd_ymfpci;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Takashi Iwai208a1b42005-11-17 14:53:41 +0100222enum snd_ymfpci_voice_type {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 YMFPCI_PCM,
224 YMFPCI_SYNTH,
225 YMFPCI_MIDI
Takashi Iwai208a1b42005-11-17 14:53:41 +0100226};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Takashi Iwai208a1b42005-11-17 14:53:41 +0100228struct snd_ymfpci_voice {
229 struct snd_ymfpci *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 int number;
231 unsigned int use: 1,
232 pcm: 1,
233 synth: 1,
234 midi: 1;
Takashi Iwai208a1b42005-11-17 14:53:41 +0100235 struct snd_ymfpci_playback_bank *bank;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 dma_addr_t bank_addr;
Takashi Iwai208a1b42005-11-17 14:53:41 +0100237 void (*interrupt)(struct snd_ymfpci *chip, struct snd_ymfpci_voice *voice);
238 struct snd_ymfpci_pcm *ypcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239};
240
Takashi Iwai208a1b42005-11-17 14:53:41 +0100241enum snd_ymfpci_pcm_type {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 PLAYBACK_VOICE,
243 CAPTURE_REC,
244 CAPTURE_AC97,
245 EFFECT_DRY_LEFT,
246 EFFECT_DRY_RIGHT,
247 EFFECT_EFF1,
248 EFFECT_EFF2,
249 EFFECT_EFF3
Takashi Iwai208a1b42005-11-17 14:53:41 +0100250};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Takashi Iwai208a1b42005-11-17 14:53:41 +0100252struct snd_ymfpci_pcm {
253 struct snd_ymfpci *chip;
254 enum snd_ymfpci_pcm_type type;
255 struct snd_pcm_substream *substream;
256 struct snd_ymfpci_voice *voices[2]; /* playback only */
Jaroslav Kysela5a25c5c2006-01-18 08:02:24 +0100257 unsigned int running: 1,
Teru KAMOGASHIRA9ed12612006-12-04 18:03:53 +0100258 use_441_slot: 1,
Jaroslav Kysela5a25c5c2006-01-18 08:02:24 +0100259 output_front: 1,
260 output_rear: 1,
261 swap_rear: 1;
Clemens Ladisch9bcf6552005-08-10 10:21:43 +0200262 unsigned int update_pcm_vol;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 u32 period_size; /* cached from runtime->period_size */
264 u32 buffer_size; /* cached from runtime->buffer_size */
265 u32 period_pos;
266 u32 last_pos;
267 u32 capture_bank_number;
268 u32 shift;
269};
270
Takashi Iwai208a1b42005-11-17 14:53:41 +0100271struct snd_ymfpci {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 int irq;
273
274 unsigned int device_id; /* PCI device ID */
Takashi Iwai01f681d2006-11-16 15:39:07 +0100275 unsigned char rev; /* PCI revision */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 unsigned long reg_area_phys;
277 void __iomem *reg_area_virt;
278 struct resource *res_reg_area;
279 struct resource *fm_res;
280 struct resource *mpu_res;
281
282 unsigned short old_legacy_ctrl;
283#ifdef SUPPORT_JOYSTICK
284 struct gameport *gameport;
285#endif
286
287 struct snd_dma_buffer work_ptr;
288
289 unsigned int bank_size_playback;
290 unsigned int bank_size_capture;
291 unsigned int bank_size_effect;
292 unsigned int work_size;
293
294 void *bank_base_playback;
295 void *bank_base_capture;
296 void *bank_base_effect;
297 void *work_base;
298 dma_addr_t bank_base_playback_addr;
299 dma_addr_t bank_base_capture_addr;
300 dma_addr_t bank_base_effect_addr;
301 dma_addr_t work_base_addr;
302 struct snd_dma_buffer ac3_tmp_base;
303
Takashi Iwaid3c63762018-07-25 23:24:01 +0200304 __le32 *ctrl_playback;
Takashi Iwai208a1b42005-11-17 14:53:41 +0100305 struct snd_ymfpci_playback_bank *bank_playback[YDSXG_PLAYBACK_VOICES][2];
306 struct snd_ymfpci_capture_bank *bank_capture[YDSXG_CAPTURE_VOICES][2];
307 struct snd_ymfpci_effect_bank *bank_effect[YDSXG_EFFECT_VOICES][2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309 int start_count;
310
311 u32 active_bank;
Takashi Iwai208a1b42005-11-17 14:53:41 +0100312 struct snd_ymfpci_voice voices[64];
Teru KAMOGASHIRA9ed12612006-12-04 18:03:53 +0100313 int src441_used;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Takashi Iwai208a1b42005-11-17 14:53:41 +0100315 struct snd_ac97_bus *ac97_bus;
316 struct snd_ac97 *ac97;
317 struct snd_rawmidi *rawmidi;
318 struct snd_timer *timer;
Clemens Ladisch6e2efaa2009-08-10 10:06:53 +0200319 unsigned int timer_ticks;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 struct pci_dev *pci;
Takashi Iwai208a1b42005-11-17 14:53:41 +0100322 struct snd_card *card;
323 struct snd_pcm *pcm;
324 struct snd_pcm *pcm2;
325 struct snd_pcm *pcm_spdif;
326 struct snd_pcm *pcm_4ch;
327 struct snd_pcm_substream *capture_substream[YDSXG_CAPTURE_VOICES];
328 struct snd_pcm_substream *effect_substream[YDSXG_EFFECT_VOICES];
329 struct snd_kcontrol *ctl_vol_recsrc;
330 struct snd_kcontrol *ctl_vol_adcrec;
331 struct snd_kcontrol *ctl_vol_spdifrec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 unsigned short spdif_bits, spdif_pcm_bits;
Takashi Iwai208a1b42005-11-17 14:53:41 +0100333 struct snd_kcontrol *spdif_pcm_ctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 int mode_dup4ch;
335 int rear_opened;
336 int spdif_opened;
Teru KAMOGASHIRA9ed12612006-12-04 18:03:53 +0100337 struct snd_ymfpci_pcm_mixer {
Clemens Ladisch9bcf6552005-08-10 10:21:43 +0200338 u16 left;
339 u16 right;
Takashi Iwai208a1b42005-11-17 14:53:41 +0100340 struct snd_kcontrol *ctl;
Clemens Ladisch9bcf6552005-08-10 10:21:43 +0200341 } pcm_mixer[32];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 spinlock_t reg_lock;
344 spinlock_t voice_lock;
345 wait_queue_head_t interrupt_sleep;
346 atomic_t interrupt_sleep_count;
Takashi Iwai208a1b42005-11-17 14:53:41 +0100347 struct snd_info_entry *proc_entry;
Clemens Ladisch102fa902006-10-11 12:05:59 +0200348 const struct firmware *dsp_microcode;
349 const struct firmware *controller_microcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Takashi Iwaic7561cd2012-08-14 18:12:04 +0200351#ifdef CONFIG_PM_SLEEP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 u32 *saved_regs;
353 u32 saved_ydsxgr_mode;
Takashi Iwai28aa1652012-03-13 08:07:41 +0100354 u16 saved_dsxg_legacy;
355 u16 saved_dsxg_elegacy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356#endif
357};
358
Takashi Iwai208a1b42005-11-17 14:53:41 +0100359int snd_ymfpci_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 struct pci_dev *pci,
361 unsigned short old_legacy_ctrl,
Takashi Iwai208a1b42005-11-17 14:53:41 +0100362 struct snd_ymfpci ** rcodec);
363void snd_ymfpci_free_gameport(struct snd_ymfpci *chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200365extern const struct dev_pm_ops snd_ymfpci_pm;
Takashi Iwaided46232005-11-17 16:09:43 +0100366
Lars-Peter Clausen38c47182015-01-02 12:24:55 +0100367int snd_ymfpci_pcm(struct snd_ymfpci *chip, int device);
368int snd_ymfpci_pcm2(struct snd_ymfpci *chip, int device);
369int snd_ymfpci_pcm_spdif(struct snd_ymfpci *chip, int device);
370int snd_ymfpci_pcm_4ch(struct snd_ymfpci *chip, int device);
Glen Masgaid9301262006-10-10 09:27:19 +0200371int snd_ymfpci_mixer(struct snd_ymfpci *chip, int rear_switch);
Takashi Iwai208a1b42005-11-17 14:53:41 +0100372int snd_ymfpci_timer(struct snd_ymfpci *chip, int device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374#endif /* __SOUND_YMFPCI_H */