162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci#ifndef __SOUND_YMFPCI_H
362306a36Sopenharmony_ci#define __SOUND_YMFPCI_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci/*
662306a36Sopenharmony_ci *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
762306a36Sopenharmony_ci *  Definitions for Yahama YMF724/740/744/754 chips
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <sound/pcm.h>
1162306a36Sopenharmony_ci#include <sound/rawmidi.h>
1262306a36Sopenharmony_ci#include <sound/ac97_codec.h>
1362306a36Sopenharmony_ci#include <sound/timer.h>
1462306a36Sopenharmony_ci#include <linux/gameport.h>
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci/*
1762306a36Sopenharmony_ci *  Direct registers
1862306a36Sopenharmony_ci */
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#define YMFREG(chip, reg)		(chip->port + YDSXGR_##reg)
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#define	YDSXGR_INTFLAG			0x0004
2362306a36Sopenharmony_ci#define	YDSXGR_ACTIVITY			0x0006
2462306a36Sopenharmony_ci#define	YDSXGR_GLOBALCTRL		0x0008
2562306a36Sopenharmony_ci#define	YDSXGR_ZVCTRL			0x000A
2662306a36Sopenharmony_ci#define	YDSXGR_TIMERCTRL		0x0010
2762306a36Sopenharmony_ci#define	YDSXGR_TIMERCOUNT		0x0012
2862306a36Sopenharmony_ci#define	YDSXGR_SPDIFOUTCTRL		0x0018
2962306a36Sopenharmony_ci#define	YDSXGR_SPDIFOUTSTATUS		0x001C
3062306a36Sopenharmony_ci#define	YDSXGR_EEPROMCTRL		0x0020
3162306a36Sopenharmony_ci#define	YDSXGR_SPDIFINCTRL		0x0034
3262306a36Sopenharmony_ci#define	YDSXGR_SPDIFINSTATUS		0x0038
3362306a36Sopenharmony_ci#define	YDSXGR_DSPPROGRAMDL		0x0048
3462306a36Sopenharmony_ci#define	YDSXGR_DLCNTRL			0x004C
3562306a36Sopenharmony_ci#define	YDSXGR_GPIOININTFLAG		0x0050
3662306a36Sopenharmony_ci#define	YDSXGR_GPIOININTENABLE		0x0052
3762306a36Sopenharmony_ci#define	YDSXGR_GPIOINSTATUS		0x0054
3862306a36Sopenharmony_ci#define	YDSXGR_GPIOOUTCTRL		0x0056
3962306a36Sopenharmony_ci#define	YDSXGR_GPIOFUNCENABLE		0x0058
4062306a36Sopenharmony_ci#define	YDSXGR_GPIOTYPECONFIG		0x005A
4162306a36Sopenharmony_ci#define	YDSXGR_AC97CMDDATA		0x0060
4262306a36Sopenharmony_ci#define	YDSXGR_AC97CMDADR		0x0062
4362306a36Sopenharmony_ci#define	YDSXGR_PRISTATUSDATA		0x0064
4462306a36Sopenharmony_ci#define	YDSXGR_PRISTATUSADR		0x0066
4562306a36Sopenharmony_ci#define	YDSXGR_SECSTATUSDATA		0x0068
4662306a36Sopenharmony_ci#define	YDSXGR_SECSTATUSADR		0x006A
4762306a36Sopenharmony_ci#define	YDSXGR_SECCONFIG		0x0070
4862306a36Sopenharmony_ci#define	YDSXGR_LEGACYOUTVOL		0x0080
4962306a36Sopenharmony_ci#define	YDSXGR_LEGACYOUTVOLL		0x0080
5062306a36Sopenharmony_ci#define	YDSXGR_LEGACYOUTVOLR		0x0082
5162306a36Sopenharmony_ci#define	YDSXGR_NATIVEDACOUTVOL		0x0084
5262306a36Sopenharmony_ci#define	YDSXGR_NATIVEDACOUTVOLL		0x0084
5362306a36Sopenharmony_ci#define	YDSXGR_NATIVEDACOUTVOLR		0x0086
5462306a36Sopenharmony_ci#define	YDSXGR_ZVOUTVOL			0x0088
5562306a36Sopenharmony_ci#define	YDSXGR_ZVOUTVOLL		0x0088
5662306a36Sopenharmony_ci#define	YDSXGR_ZVOUTVOLR		0x008A
5762306a36Sopenharmony_ci#define	YDSXGR_SECADCOUTVOL		0x008C
5862306a36Sopenharmony_ci#define	YDSXGR_SECADCOUTVOLL		0x008C
5962306a36Sopenharmony_ci#define	YDSXGR_SECADCOUTVOLR		0x008E
6062306a36Sopenharmony_ci#define	YDSXGR_PRIADCOUTVOL		0x0090
6162306a36Sopenharmony_ci#define	YDSXGR_PRIADCOUTVOLL		0x0090
6262306a36Sopenharmony_ci#define	YDSXGR_PRIADCOUTVOLR		0x0092
6362306a36Sopenharmony_ci#define	YDSXGR_LEGACYLOOPVOL		0x0094
6462306a36Sopenharmony_ci#define	YDSXGR_LEGACYLOOPVOLL		0x0094
6562306a36Sopenharmony_ci#define	YDSXGR_LEGACYLOOPVOLR		0x0096
6662306a36Sopenharmony_ci#define	YDSXGR_NATIVEDACLOOPVOL		0x0098
6762306a36Sopenharmony_ci#define	YDSXGR_NATIVEDACLOOPVOLL	0x0098
6862306a36Sopenharmony_ci#define	YDSXGR_NATIVEDACLOOPVOLR	0x009A
6962306a36Sopenharmony_ci#define	YDSXGR_ZVLOOPVOL		0x009C
7062306a36Sopenharmony_ci#define	YDSXGR_ZVLOOPVOLL		0x009E
7162306a36Sopenharmony_ci#define	YDSXGR_ZVLOOPVOLR		0x009E
7262306a36Sopenharmony_ci#define	YDSXGR_SECADCLOOPVOL		0x00A0
7362306a36Sopenharmony_ci#define	YDSXGR_SECADCLOOPVOLL		0x00A0
7462306a36Sopenharmony_ci#define	YDSXGR_SECADCLOOPVOLR		0x00A2
7562306a36Sopenharmony_ci#define	YDSXGR_PRIADCLOOPVOL		0x00A4
7662306a36Sopenharmony_ci#define	YDSXGR_PRIADCLOOPVOLL		0x00A4
7762306a36Sopenharmony_ci#define	YDSXGR_PRIADCLOOPVOLR		0x00A6
7862306a36Sopenharmony_ci#define	YDSXGR_NATIVEADCINVOL		0x00A8
7962306a36Sopenharmony_ci#define	YDSXGR_NATIVEADCINVOLL		0x00A8
8062306a36Sopenharmony_ci#define	YDSXGR_NATIVEADCINVOLR		0x00AA
8162306a36Sopenharmony_ci#define	YDSXGR_NATIVEDACINVOL		0x00AC
8262306a36Sopenharmony_ci#define	YDSXGR_NATIVEDACINVOLL		0x00AC
8362306a36Sopenharmony_ci#define	YDSXGR_NATIVEDACINVOLR		0x00AE
8462306a36Sopenharmony_ci#define	YDSXGR_BUF441OUTVOL		0x00B0
8562306a36Sopenharmony_ci#define	YDSXGR_BUF441OUTVOLL		0x00B0
8662306a36Sopenharmony_ci#define	YDSXGR_BUF441OUTVOLR		0x00B2
8762306a36Sopenharmony_ci#define	YDSXGR_BUF441LOOPVOL		0x00B4
8862306a36Sopenharmony_ci#define	YDSXGR_BUF441LOOPVOLL		0x00B4
8962306a36Sopenharmony_ci#define	YDSXGR_BUF441LOOPVOLR		0x00B6
9062306a36Sopenharmony_ci#define	YDSXGR_SPDIFOUTVOL		0x00B8
9162306a36Sopenharmony_ci#define	YDSXGR_SPDIFOUTVOLL		0x00B8
9262306a36Sopenharmony_ci#define	YDSXGR_SPDIFOUTVOLR		0x00BA
9362306a36Sopenharmony_ci#define	YDSXGR_SPDIFLOOPVOL		0x00BC
9462306a36Sopenharmony_ci#define	YDSXGR_SPDIFLOOPVOLL		0x00BC
9562306a36Sopenharmony_ci#define	YDSXGR_SPDIFLOOPVOLR		0x00BE
9662306a36Sopenharmony_ci#define	YDSXGR_ADCSLOTSR		0x00C0
9762306a36Sopenharmony_ci#define	YDSXGR_RECSLOTSR		0x00C4
9862306a36Sopenharmony_ci#define	YDSXGR_ADCFORMAT		0x00C8
9962306a36Sopenharmony_ci#define	YDSXGR_RECFORMAT		0x00CC
10062306a36Sopenharmony_ci#define	YDSXGR_P44SLOTSR		0x00D0
10162306a36Sopenharmony_ci#define	YDSXGR_STATUS			0x0100
10262306a36Sopenharmony_ci#define	YDSXGR_CTRLSELECT		0x0104
10362306a36Sopenharmony_ci#define	YDSXGR_MODE			0x0108
10462306a36Sopenharmony_ci#define	YDSXGR_SAMPLECOUNT		0x010C
10562306a36Sopenharmony_ci#define	YDSXGR_NUMOFSAMPLES		0x0110
10662306a36Sopenharmony_ci#define	YDSXGR_CONFIG			0x0114
10762306a36Sopenharmony_ci#define	YDSXGR_PLAYCTRLSIZE		0x0140
10862306a36Sopenharmony_ci#define	YDSXGR_RECCTRLSIZE		0x0144
10962306a36Sopenharmony_ci#define	YDSXGR_EFFCTRLSIZE		0x0148
11062306a36Sopenharmony_ci#define	YDSXGR_WORKSIZE			0x014C
11162306a36Sopenharmony_ci#define	YDSXGR_MAPOFREC			0x0150
11262306a36Sopenharmony_ci#define	YDSXGR_MAPOFEFFECT		0x0154
11362306a36Sopenharmony_ci#define	YDSXGR_PLAYCTRLBASE		0x0158
11462306a36Sopenharmony_ci#define	YDSXGR_RECCTRLBASE		0x015C
11562306a36Sopenharmony_ci#define	YDSXGR_EFFCTRLBASE		0x0160
11662306a36Sopenharmony_ci#define	YDSXGR_WORKBASE			0x0164
11762306a36Sopenharmony_ci#define	YDSXGR_DSPINSTRAM		0x1000
11862306a36Sopenharmony_ci#define	YDSXGR_CTRLINSTRAM		0x4000
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci#define YDSXG_AC97READCMD		0x8000
12162306a36Sopenharmony_ci#define YDSXG_AC97WRITECMD		0x0000
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci#define PCIR_DSXG_LEGACY		0x40
12462306a36Sopenharmony_ci#define PCIR_DSXG_ELEGACY		0x42
12562306a36Sopenharmony_ci#define PCIR_DSXG_CTRL			0x48
12662306a36Sopenharmony_ci#define PCIR_DSXG_PWRCTRL1		0x4a
12762306a36Sopenharmony_ci#define PCIR_DSXG_PWRCTRL2		0x4e
12862306a36Sopenharmony_ci#define PCIR_DSXG_FMBASE		0x60
12962306a36Sopenharmony_ci#define PCIR_DSXG_SBBASE		0x62
13062306a36Sopenharmony_ci#define PCIR_DSXG_MPU401BASE		0x64
13162306a36Sopenharmony_ci#define PCIR_DSXG_JOYBASE		0x66
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci#define YDSXG_DSPLENGTH			0x0080
13462306a36Sopenharmony_ci#define YDSXG_CTRLLENGTH		0x3000
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci#define YDSXG_DEFAULT_WORK_SIZE		0x0400
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci#define YDSXG_PLAYBACK_VOICES		64
13962306a36Sopenharmony_ci#define YDSXG_CAPTURE_VOICES		2
14062306a36Sopenharmony_ci#define YDSXG_EFFECT_VOICES		5
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci#define YMFPCI_LEGACY_SBEN	(1 << 0)	/* soundblaster enable */
14362306a36Sopenharmony_ci#define YMFPCI_LEGACY_FMEN	(1 << 1)	/* OPL3 enable */
14462306a36Sopenharmony_ci#define YMFPCI_LEGACY_JPEN	(1 << 2)	/* joystick enable */
14562306a36Sopenharmony_ci#define YMFPCI_LEGACY_MEN	(1 << 3)	/* MPU401 enable */
14662306a36Sopenharmony_ci#define YMFPCI_LEGACY_MIEN	(1 << 4)	/* MPU RX irq enable */
14762306a36Sopenharmony_ci#define YMFPCI_LEGACY_IOBITS	(1 << 5)	/* i/o bits range, 0 = 16bit, 1 =10bit */
14862306a36Sopenharmony_ci#define YMFPCI_LEGACY_SDMA	(3 << 6)	/* SB DMA select */
14962306a36Sopenharmony_ci#define YMFPCI_LEGACY_SBIRQ	(7 << 8)	/* SB IRQ select */
15062306a36Sopenharmony_ci#define YMFPCI_LEGACY_MPUIRQ	(7 << 11)	/* MPU IRQ select */
15162306a36Sopenharmony_ci#define YMFPCI_LEGACY_SIEN	(1 << 14)	/* serialized IRQ */
15262306a36Sopenharmony_ci#define YMFPCI_LEGACY_LAD	(1 << 15)	/* legacy audio disable */
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci#define YMFPCI_LEGACY2_FMIO	(3 << 0)	/* OPL3 i/o address (724/740) */
15562306a36Sopenharmony_ci#define YMFPCI_LEGACY2_SBIO	(3 << 2)	/* SB i/o address (724/740) */
15662306a36Sopenharmony_ci#define YMFPCI_LEGACY2_MPUIO	(3 << 4)	/* MPU401 i/o address (724/740) */
15762306a36Sopenharmony_ci#define YMFPCI_LEGACY2_JSIO	(3 << 6)	/* joystick i/o address (724/740) */
15862306a36Sopenharmony_ci#define YMFPCI_LEGACY2_MAIM	(1 << 8)	/* MPU401 ack intr mask */
15962306a36Sopenharmony_ci#define YMFPCI_LEGACY2_SMOD	(3 << 11)	/* SB DMA mode */
16062306a36Sopenharmony_ci#define YMFPCI_LEGACY2_SBVER	(3 << 13)	/* SB version select */
16162306a36Sopenharmony_ci#define YMFPCI_LEGACY2_IMOD	(1 << 15)	/* legacy IRQ mode */
16262306a36Sopenharmony_ci/* SIEN:IMOD 0:0 = legacy irq, 0:1 = INTA, 1:0 = serialized IRQ */
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci#if IS_REACHABLE(CONFIG_GAMEPORT)
16562306a36Sopenharmony_ci#define SUPPORT_JOYSTICK
16662306a36Sopenharmony_ci#endif
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ci/*
16962306a36Sopenharmony_ci *
17062306a36Sopenharmony_ci */
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_cistruct snd_ymfpci_playback_bank {
17362306a36Sopenharmony_ci	__le32 format;
17462306a36Sopenharmony_ci	__le32 loop_default;
17562306a36Sopenharmony_ci	__le32 base;			/* 32-bit address */
17662306a36Sopenharmony_ci	__le32 loop_start;		/* 32-bit offset */
17762306a36Sopenharmony_ci	__le32 loop_end;		/* 32-bit offset */
17862306a36Sopenharmony_ci	__le32 loop_frac;		/* 8-bit fraction - loop_start */
17962306a36Sopenharmony_ci	__le32 delta_end;		/* pitch delta end */
18062306a36Sopenharmony_ci	__le32 lpfK_end;
18162306a36Sopenharmony_ci	__le32 eg_gain_end;
18262306a36Sopenharmony_ci	__le32 left_gain_end;
18362306a36Sopenharmony_ci	__le32 right_gain_end;
18462306a36Sopenharmony_ci	__le32 eff1_gain_end;
18562306a36Sopenharmony_ci	__le32 eff2_gain_end;
18662306a36Sopenharmony_ci	__le32 eff3_gain_end;
18762306a36Sopenharmony_ci	__le32 lpfQ;
18862306a36Sopenharmony_ci	__le32 status;
18962306a36Sopenharmony_ci	__le32 num_of_frames;
19062306a36Sopenharmony_ci	__le32 loop_count;
19162306a36Sopenharmony_ci	__le32 start;
19262306a36Sopenharmony_ci	__le32 start_frac;
19362306a36Sopenharmony_ci	__le32 delta;
19462306a36Sopenharmony_ci	__le32 lpfK;
19562306a36Sopenharmony_ci	__le32 eg_gain;
19662306a36Sopenharmony_ci	__le32 left_gain;
19762306a36Sopenharmony_ci	__le32 right_gain;
19862306a36Sopenharmony_ci	__le32 eff1_gain;
19962306a36Sopenharmony_ci	__le32 eff2_gain;
20062306a36Sopenharmony_ci	__le32 eff3_gain;
20162306a36Sopenharmony_ci	__le32 lpfD1;
20262306a36Sopenharmony_ci	__le32 lpfD2;
20362306a36Sopenharmony_ci };
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_cistruct snd_ymfpci_capture_bank {
20662306a36Sopenharmony_ci	__le32 base;			/* 32-bit address */
20762306a36Sopenharmony_ci	__le32 loop_end;		/* 32-bit offset */
20862306a36Sopenharmony_ci	__le32 start;			/* 32-bit offset */
20962306a36Sopenharmony_ci	__le32 num_of_loops;		/* counter */
21062306a36Sopenharmony_ci};
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_cistruct snd_ymfpci_effect_bank {
21362306a36Sopenharmony_ci	__le32 base;			/* 32-bit address */
21462306a36Sopenharmony_ci	__le32 loop_end;		/* 32-bit offset */
21562306a36Sopenharmony_ci	__le32 start;			/* 32-bit offset */
21662306a36Sopenharmony_ci	__le32 temp;
21762306a36Sopenharmony_ci};
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_cistruct snd_ymfpci_pcm;
22062306a36Sopenharmony_cistruct snd_ymfpci;
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_cienum snd_ymfpci_voice_type {
22362306a36Sopenharmony_ci	YMFPCI_PCM,
22462306a36Sopenharmony_ci	YMFPCI_SYNTH,
22562306a36Sopenharmony_ci	YMFPCI_MIDI
22662306a36Sopenharmony_ci};
22762306a36Sopenharmony_ci
22862306a36Sopenharmony_cistruct snd_ymfpci_voice {
22962306a36Sopenharmony_ci	struct snd_ymfpci *chip;
23062306a36Sopenharmony_ci	int number;
23162306a36Sopenharmony_ci	unsigned int use: 1,
23262306a36Sopenharmony_ci	    pcm: 1,
23362306a36Sopenharmony_ci	    synth: 1,
23462306a36Sopenharmony_ci	    midi: 1;
23562306a36Sopenharmony_ci	struct snd_ymfpci_playback_bank *bank;
23662306a36Sopenharmony_ci	dma_addr_t bank_addr;
23762306a36Sopenharmony_ci	void (*interrupt)(struct snd_ymfpci *chip, struct snd_ymfpci_voice *voice);
23862306a36Sopenharmony_ci	struct snd_ymfpci_pcm *ypcm;
23962306a36Sopenharmony_ci};
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_cienum snd_ymfpci_pcm_type {
24262306a36Sopenharmony_ci	PLAYBACK_VOICE,
24362306a36Sopenharmony_ci	CAPTURE_REC,
24462306a36Sopenharmony_ci	CAPTURE_AC97,
24562306a36Sopenharmony_ci	EFFECT_DRY_LEFT,
24662306a36Sopenharmony_ci	EFFECT_DRY_RIGHT,
24762306a36Sopenharmony_ci	EFFECT_EFF1,
24862306a36Sopenharmony_ci	EFFECT_EFF2,
24962306a36Sopenharmony_ci	EFFECT_EFF3
25062306a36Sopenharmony_ci};
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_cistruct snd_ymfpci_pcm {
25362306a36Sopenharmony_ci	struct snd_ymfpci *chip;
25462306a36Sopenharmony_ci	enum snd_ymfpci_pcm_type type;
25562306a36Sopenharmony_ci	struct snd_pcm_substream *substream;
25662306a36Sopenharmony_ci	struct snd_ymfpci_voice *voices[2];	/* playback only */
25762306a36Sopenharmony_ci	unsigned int running: 1,
25862306a36Sopenharmony_ci		     use_441_slot: 1,
25962306a36Sopenharmony_ci	             output_front: 1,
26062306a36Sopenharmony_ci	             output_rear: 1,
26162306a36Sopenharmony_ci	             swap_rear: 1;
26262306a36Sopenharmony_ci	unsigned int update_pcm_vol;
26362306a36Sopenharmony_ci	u32 period_size;		/* cached from runtime->period_size */
26462306a36Sopenharmony_ci	u32 buffer_size;		/* cached from runtime->buffer_size */
26562306a36Sopenharmony_ci	u32 period_pos;
26662306a36Sopenharmony_ci	u32 last_pos;
26762306a36Sopenharmony_ci	u32 capture_bank_number;
26862306a36Sopenharmony_ci	u32 shift;
26962306a36Sopenharmony_ci};
27062306a36Sopenharmony_ci
27162306a36Sopenharmony_cistatic const int saved_regs_index[] = {
27262306a36Sopenharmony_ci	/* spdif */
27362306a36Sopenharmony_ci	YDSXGR_SPDIFOUTCTRL,
27462306a36Sopenharmony_ci	YDSXGR_SPDIFOUTSTATUS,
27562306a36Sopenharmony_ci	YDSXGR_SPDIFINCTRL,
27662306a36Sopenharmony_ci	/* volumes */
27762306a36Sopenharmony_ci	YDSXGR_PRIADCLOOPVOL,
27862306a36Sopenharmony_ci	YDSXGR_NATIVEDACINVOL,
27962306a36Sopenharmony_ci	YDSXGR_NATIVEDACOUTVOL,
28062306a36Sopenharmony_ci	YDSXGR_BUF441OUTVOL,
28162306a36Sopenharmony_ci	YDSXGR_NATIVEADCINVOL,
28262306a36Sopenharmony_ci	YDSXGR_SPDIFLOOPVOL,
28362306a36Sopenharmony_ci	YDSXGR_SPDIFOUTVOL,
28462306a36Sopenharmony_ci	YDSXGR_ZVOUTVOL,
28562306a36Sopenharmony_ci	YDSXGR_LEGACYOUTVOL,
28662306a36Sopenharmony_ci	/* address bases */
28762306a36Sopenharmony_ci	YDSXGR_PLAYCTRLBASE,
28862306a36Sopenharmony_ci	YDSXGR_RECCTRLBASE,
28962306a36Sopenharmony_ci	YDSXGR_EFFCTRLBASE,
29062306a36Sopenharmony_ci	YDSXGR_WORKBASE,
29162306a36Sopenharmony_ci	/* capture set up */
29262306a36Sopenharmony_ci	YDSXGR_MAPOFREC,
29362306a36Sopenharmony_ci	YDSXGR_RECFORMAT,
29462306a36Sopenharmony_ci	YDSXGR_RECSLOTSR,
29562306a36Sopenharmony_ci	YDSXGR_ADCFORMAT,
29662306a36Sopenharmony_ci	YDSXGR_ADCSLOTSR,
29762306a36Sopenharmony_ci};
29862306a36Sopenharmony_ci#define YDSXGR_NUM_SAVED_REGS	ARRAY_SIZE(saved_regs_index)
29962306a36Sopenharmony_ci
30062306a36Sopenharmony_cistatic const int pci_saved_regs_index[] = {
30162306a36Sopenharmony_ci	/* All Chips */
30262306a36Sopenharmony_ci	PCIR_DSXG_LEGACY,
30362306a36Sopenharmony_ci	PCIR_DSXG_ELEGACY,
30462306a36Sopenharmony_ci	/* YMF 744/754 */
30562306a36Sopenharmony_ci	PCIR_DSXG_FMBASE,
30662306a36Sopenharmony_ci	PCIR_DSXG_SBBASE,
30762306a36Sopenharmony_ci	PCIR_DSXG_MPU401BASE,
30862306a36Sopenharmony_ci	PCIR_DSXG_JOYBASE,
30962306a36Sopenharmony_ci};
31062306a36Sopenharmony_ci#define DSXG_PCI_NUM_SAVED_REGS	ARRAY_SIZE(pci_saved_regs_index)
31162306a36Sopenharmony_ci#define DSXG_PCI_NUM_SAVED_LEGACY_REGS	2
31262306a36Sopenharmony_cistatic_assert(DSXG_PCI_NUM_SAVED_LEGACY_REGS <= DSXG_PCI_NUM_SAVED_REGS);
31362306a36Sopenharmony_ci
31462306a36Sopenharmony_cistruct snd_ymfpci {
31562306a36Sopenharmony_ci	int irq;
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_ci	unsigned int device_id;	/* PCI device ID */
31862306a36Sopenharmony_ci	unsigned char rev;	/* PCI revision */
31962306a36Sopenharmony_ci	unsigned long reg_area_phys;
32062306a36Sopenharmony_ci	void __iomem *reg_area_virt;
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_ci	u16 old_legacy_ctrl;
32362306a36Sopenharmony_ci#ifdef SUPPORT_JOYSTICK
32462306a36Sopenharmony_ci	struct gameport *gameport;
32562306a36Sopenharmony_ci#endif
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci	struct snd_dma_buffer *work_ptr;
32862306a36Sopenharmony_ci
32962306a36Sopenharmony_ci	unsigned int bank_size_playback;
33062306a36Sopenharmony_ci	unsigned int bank_size_capture;
33162306a36Sopenharmony_ci	unsigned int bank_size_effect;
33262306a36Sopenharmony_ci	unsigned int work_size;
33362306a36Sopenharmony_ci
33462306a36Sopenharmony_ci	void *bank_base_playback;
33562306a36Sopenharmony_ci	void *bank_base_capture;
33662306a36Sopenharmony_ci	void *bank_base_effect;
33762306a36Sopenharmony_ci	void *work_base;
33862306a36Sopenharmony_ci	dma_addr_t bank_base_playback_addr;
33962306a36Sopenharmony_ci	dma_addr_t bank_base_capture_addr;
34062306a36Sopenharmony_ci	dma_addr_t bank_base_effect_addr;
34162306a36Sopenharmony_ci	dma_addr_t work_base_addr;
34262306a36Sopenharmony_ci	struct snd_dma_buffer ac3_tmp_base;
34362306a36Sopenharmony_ci
34462306a36Sopenharmony_ci	__le32 *ctrl_playback;
34562306a36Sopenharmony_ci	struct snd_ymfpci_playback_bank *bank_playback[YDSXG_PLAYBACK_VOICES][2];
34662306a36Sopenharmony_ci	struct snd_ymfpci_capture_bank *bank_capture[YDSXG_CAPTURE_VOICES][2];
34762306a36Sopenharmony_ci	struct snd_ymfpci_effect_bank *bank_effect[YDSXG_EFFECT_VOICES][2];
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_ci	int start_count;
35062306a36Sopenharmony_ci
35162306a36Sopenharmony_ci	u32 active_bank;
35262306a36Sopenharmony_ci	struct snd_ymfpci_voice voices[64];
35362306a36Sopenharmony_ci	int src441_used;
35462306a36Sopenharmony_ci
35562306a36Sopenharmony_ci	struct snd_ac97_bus *ac97_bus;
35662306a36Sopenharmony_ci	struct snd_ac97 *ac97;
35762306a36Sopenharmony_ci	struct snd_rawmidi *rawmidi;
35862306a36Sopenharmony_ci	struct snd_timer *timer;
35962306a36Sopenharmony_ci	unsigned int timer_ticks;
36062306a36Sopenharmony_ci
36162306a36Sopenharmony_ci	struct pci_dev *pci;
36262306a36Sopenharmony_ci	struct snd_card *card;
36362306a36Sopenharmony_ci	struct snd_pcm *pcm;
36462306a36Sopenharmony_ci	struct snd_pcm *pcm2;
36562306a36Sopenharmony_ci	struct snd_pcm *pcm_spdif;
36662306a36Sopenharmony_ci	struct snd_pcm *pcm_4ch;
36762306a36Sopenharmony_ci	struct snd_pcm_substream *capture_substream[YDSXG_CAPTURE_VOICES];
36862306a36Sopenharmony_ci	struct snd_pcm_substream *effect_substream[YDSXG_EFFECT_VOICES];
36962306a36Sopenharmony_ci	struct snd_kcontrol *ctl_vol_recsrc;
37062306a36Sopenharmony_ci	struct snd_kcontrol *ctl_vol_adcrec;
37162306a36Sopenharmony_ci	struct snd_kcontrol *ctl_vol_spdifrec;
37262306a36Sopenharmony_ci	unsigned short spdif_bits, spdif_pcm_bits;
37362306a36Sopenharmony_ci	struct snd_kcontrol *spdif_pcm_ctl;
37462306a36Sopenharmony_ci	int mode_dup4ch;
37562306a36Sopenharmony_ci	int rear_opened;
37662306a36Sopenharmony_ci	int spdif_opened;
37762306a36Sopenharmony_ci	struct snd_ymfpci_pcm_mixer {
37862306a36Sopenharmony_ci		u16 left;
37962306a36Sopenharmony_ci		u16 right;
38062306a36Sopenharmony_ci		struct snd_kcontrol *ctl;
38162306a36Sopenharmony_ci	} pcm_mixer[32];
38262306a36Sopenharmony_ci
38362306a36Sopenharmony_ci	spinlock_t reg_lock;
38462306a36Sopenharmony_ci	spinlock_t voice_lock;
38562306a36Sopenharmony_ci	wait_queue_head_t interrupt_sleep;
38662306a36Sopenharmony_ci	atomic_t interrupt_sleep_count;
38762306a36Sopenharmony_ci	struct snd_info_entry *proc_entry;
38862306a36Sopenharmony_ci	const struct firmware *dsp_microcode;
38962306a36Sopenharmony_ci	const struct firmware *controller_microcode;
39062306a36Sopenharmony_ci
39162306a36Sopenharmony_ci	u32 saved_regs[YDSXGR_NUM_SAVED_REGS];
39262306a36Sopenharmony_ci	u32 saved_ydsxgr_mode;
39362306a36Sopenharmony_ci	u16 saved_dsxg_pci_regs[DSXG_PCI_NUM_SAVED_REGS];
39462306a36Sopenharmony_ci};
39562306a36Sopenharmony_ci
39662306a36Sopenharmony_ciint snd_ymfpci_create(struct snd_card *card,
39762306a36Sopenharmony_ci		      struct pci_dev *pci,
39862306a36Sopenharmony_ci		      u16 old_legacy_ctrl);
39962306a36Sopenharmony_civoid snd_ymfpci_free_gameport(struct snd_ymfpci *chip);
40062306a36Sopenharmony_ci
40162306a36Sopenharmony_ciextern const struct dev_pm_ops snd_ymfpci_pm;
40262306a36Sopenharmony_ci
40362306a36Sopenharmony_ciint snd_ymfpci_pcm(struct snd_ymfpci *chip, int device);
40462306a36Sopenharmony_ciint snd_ymfpci_pcm2(struct snd_ymfpci *chip, int device);
40562306a36Sopenharmony_ciint snd_ymfpci_pcm_spdif(struct snd_ymfpci *chip, int device);
40662306a36Sopenharmony_ciint snd_ymfpci_pcm_4ch(struct snd_ymfpci *chip, int device);
40762306a36Sopenharmony_ciint snd_ymfpci_mixer(struct snd_ymfpci *chip, int rear_switch);
40862306a36Sopenharmony_ciint snd_ymfpci_timer(struct snd_ymfpci *chip, int device);
40962306a36Sopenharmony_ci
41062306a36Sopenharmony_ci#endif /* __SOUND_YMFPCI_H */
411