162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *  Copyright (c) 2004 James Courtier-Dutton <James@superbug.demon.co.uk>
462306a36Sopenharmony_ci *  Driver CA0106 chips. e.g. Sound Blaster Audigy LS and Live 24bit
562306a36Sopenharmony_ci *  Version: 0.0.22
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci *  FEATURES currently supported:
862306a36Sopenharmony_ci *    See ca0106_main.c for features.
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci *  Changelog:
1162306a36Sopenharmony_ci *    Support interrupts per period.
1262306a36Sopenharmony_ci *    Removed noise from Center/LFE channel when in Analog mode.
1362306a36Sopenharmony_ci *    Rename and remove mixer controls.
1462306a36Sopenharmony_ci *  0.0.6
1562306a36Sopenharmony_ci *    Use separate card based DMA buffer for periods table list.
1662306a36Sopenharmony_ci *  0.0.7
1762306a36Sopenharmony_ci *    Change remove and rename ctrls into lists.
1862306a36Sopenharmony_ci *  0.0.8
1962306a36Sopenharmony_ci *    Try to fix capture sources.
2062306a36Sopenharmony_ci *  0.0.9
2162306a36Sopenharmony_ci *    Fix AC3 output.
2262306a36Sopenharmony_ci *    Enable S32_LE format support.
2362306a36Sopenharmony_ci *  0.0.10
2462306a36Sopenharmony_ci *    Enable playback 48000 and 96000 rates. (Rates other that these do not work, even with "plug:front".)
2562306a36Sopenharmony_ci *  0.0.11
2662306a36Sopenharmony_ci *    Add Model name recognition.
2762306a36Sopenharmony_ci *  0.0.12
2862306a36Sopenharmony_ci *    Correct interrupt timing. interrupt at end of period, instead of in the middle of a playback period.
2962306a36Sopenharmony_ci *    Remove redundent "voice" handling.
3062306a36Sopenharmony_ci *  0.0.13
3162306a36Sopenharmony_ci *    Single trigger call for multi channels.
3262306a36Sopenharmony_ci *  0.0.14
3362306a36Sopenharmony_ci *    Set limits based on what the sound card hardware can do.
3462306a36Sopenharmony_ci *    playback periods_min=2, periods_max=8
3562306a36Sopenharmony_ci *    capture hw constraints require period_size = n * 64 bytes.
3662306a36Sopenharmony_ci *    playback hw constraints require period_size = n * 64 bytes.
3762306a36Sopenharmony_ci *  0.0.15
3862306a36Sopenharmony_ci *    Separated ca0106.c into separate functional .c files.
3962306a36Sopenharmony_ci *  0.0.16
4062306a36Sopenharmony_ci *    Implement 192000 sample rate.
4162306a36Sopenharmony_ci *  0.0.17
4262306a36Sopenharmony_ci *    Add support for SB0410 and SB0413.
4362306a36Sopenharmony_ci *  0.0.18
4462306a36Sopenharmony_ci *    Modified Copyright message.
4562306a36Sopenharmony_ci *  0.0.19
4662306a36Sopenharmony_ci *    Added I2C and SPI registers. Filled in interrupt enable.
4762306a36Sopenharmony_ci *  0.0.20
4862306a36Sopenharmony_ci *    Added GPIO info for SB Live 24bit.
4962306a36Sopenharmony_ci *  0.0.21
5062306a36Sopenharmony_ci *   Implement support for Line-in capture on SB Live 24bit.
5162306a36Sopenharmony_ci *  0.0.22
5262306a36Sopenharmony_ci *    Add support for mute control on SB Live 24bit (cards w/ SPI DAC)
5362306a36Sopenharmony_ci *
5462306a36Sopenharmony_ci *  This code was initially based on code from ALSA's emu10k1x.c which is:
5562306a36Sopenharmony_ci *  Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
5662306a36Sopenharmony_ci */
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci/************************************************************************************************/
5962306a36Sopenharmony_ci/* PCI function 0 registers, address = <val> + PCIBASE0						*/
6062306a36Sopenharmony_ci/************************************************************************************************/
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci#define CA0106_PTR		0x00		/* Indexed register set pointer register	*/
6362306a36Sopenharmony_ci						/* NOTE: The CHANNELNUM and ADDRESS words can	*/
6462306a36Sopenharmony_ci						/* be modified independently of each other.	*/
6562306a36Sopenharmony_ci						/* CNL[1:0], ADDR[27:16]                        */
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci#define CA0106_DATA		0x04		/* Indexed register set data register		*/
6862306a36Sopenharmony_ci						/* DATA[31:0]					*/
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci#define CA0106_IPR		0x08		/* Global interrupt pending register		*/
7162306a36Sopenharmony_ci						/* Clear pending interrupts by writing a 1 to	*/
7262306a36Sopenharmony_ci						/* the relevant bits and zero to the other bits	*/
7362306a36Sopenharmony_ci#define IPR_MIDI_RX_B		0x00020000	/* MIDI UART-B Receive buffer non-empty		*/
7462306a36Sopenharmony_ci#define IPR_MIDI_TX_B		0x00010000	/* MIDI UART-B Transmit buffer empty		*/
7562306a36Sopenharmony_ci#define IPR_SPDIF_IN_USER	0x00004000      /* SPDIF input user data has 16 more bits	*/
7662306a36Sopenharmony_ci#define IPR_SPDIF_OUT_USER	0x00002000      /* SPDIF output user data needs 16 more bits	*/
7762306a36Sopenharmony_ci#define IPR_SPDIF_OUT_FRAME	0x00001000      /* SPDIF frame about to start			*/
7862306a36Sopenharmony_ci#define IPR_SPI			0x00000800      /* SPI transaction completed			*/
7962306a36Sopenharmony_ci#define IPR_I2C_EEPROM		0x00000400      /* I2C EEPROM transaction completed		*/
8062306a36Sopenharmony_ci#define IPR_I2C_DAC		0x00000200      /* I2C DAC transaction completed		*/
8162306a36Sopenharmony_ci#define IPR_AI			0x00000100      /* Audio pending register changed. See PTR reg 0x76	*/
8262306a36Sopenharmony_ci#define IPR_GPI			0x00000080      /* General Purpose input changed		*/
8362306a36Sopenharmony_ci#define IPR_SRC_LOCKED          0x00000040      /* SRC lock status changed			*/
8462306a36Sopenharmony_ci#define IPR_SPDIF_STATUS        0x00000020      /* SPDIF status changed				*/
8562306a36Sopenharmony_ci#define IPR_TIMER2              0x00000010      /* 192000Hz Timer				*/
8662306a36Sopenharmony_ci#define IPR_TIMER1              0x00000008      /* 44100Hz Timer				*/
8762306a36Sopenharmony_ci#define IPR_MIDI_RX_A		0x00000004	/* MIDI UART-A Receive buffer non-empty		*/
8862306a36Sopenharmony_ci#define IPR_MIDI_TX_A		0x00000002	/* MIDI UART-A Transmit buffer empty		*/
8962306a36Sopenharmony_ci#define IPR_PCI			0x00000001	/* PCI Bus error				*/
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci#define CA0106_INTE		0x0c		/* Interrupt enable register			*/
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci#define INTE_MIDI_RX_B		0x00020000	/* MIDI UART-B Receive buffer non-empty		*/
9462306a36Sopenharmony_ci#define INTE_MIDI_TX_B		0x00010000	/* MIDI UART-B Transmit buffer empty		*/
9562306a36Sopenharmony_ci#define INTE_SPDIF_IN_USER	0x00004000      /* SPDIF input user data has 16 more bits	*/
9662306a36Sopenharmony_ci#define INTE_SPDIF_OUT_USER	0x00002000      /* SPDIF output user data needs 16 more bits	*/
9762306a36Sopenharmony_ci#define INTE_SPDIF_OUT_FRAME	0x00001000      /* SPDIF frame about to start			*/
9862306a36Sopenharmony_ci#define INTE_SPI		0x00000800      /* SPI transaction completed			*/
9962306a36Sopenharmony_ci#define INTE_I2C_EEPROM		0x00000400      /* I2C EEPROM transaction completed		*/
10062306a36Sopenharmony_ci#define INTE_I2C_DAC		0x00000200      /* I2C DAC transaction completed		*/
10162306a36Sopenharmony_ci#define INTE_AI			0x00000100      /* Audio pending register changed. See PTR reg 0x75 */
10262306a36Sopenharmony_ci#define INTE_GPI		0x00000080      /* General Purpose input changed		*/
10362306a36Sopenharmony_ci#define INTE_SRC_LOCKED         0x00000040      /* SRC lock status changed			*/
10462306a36Sopenharmony_ci#define INTE_SPDIF_STATUS       0x00000020      /* SPDIF status changed				*/
10562306a36Sopenharmony_ci#define INTE_TIMER2             0x00000010      /* 192000Hz Timer				*/
10662306a36Sopenharmony_ci#define INTE_TIMER1             0x00000008      /* 44100Hz Timer				*/
10762306a36Sopenharmony_ci#define INTE_MIDI_RX_A		0x00000004	/* MIDI UART-A Receive buffer non-empty		*/
10862306a36Sopenharmony_ci#define INTE_MIDI_TX_A		0x00000002	/* MIDI UART-A Transmit buffer empty		*/
10962306a36Sopenharmony_ci#define INTE_PCI		0x00000001	/* PCI Bus error				*/
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci#define CA0106_UNKNOWN10	0x10		/* Unknown ??. Defaults to 0 */
11262306a36Sopenharmony_ci#define CA0106_HCFG		0x14		/* Hardware config register			*/
11362306a36Sopenharmony_ci						/* 0x1000 causes AC3 to fails. It adds a dither bit. */
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci#define HCFG_STAC		0x10000000	/* Special mode for STAC9460 Codec. */
11662306a36Sopenharmony_ci#define HCFG_CAPTURE_I2S_BYPASS	0x08000000	/* 1 = bypass I2S input async SRC. */
11762306a36Sopenharmony_ci#define HCFG_CAPTURE_SPDIF_BYPASS 0x04000000	/* 1 = bypass SPDIF input async SRC. */
11862306a36Sopenharmony_ci#define HCFG_PLAYBACK_I2S_BYPASS 0x02000000	/* 0 = I2S IN mixer output, 1 = I2S IN1. */
11962306a36Sopenharmony_ci#define HCFG_FORCE_LOCK		0x01000000	/* For test only. Force input SRC tracker to lock. */
12062306a36Sopenharmony_ci#define HCFG_PLAYBACK_ATTENUATION 0x00006000	/* Playback attenuation mask. 0 = 0dB, 1 = 6dB, 2 = 12dB, 3 = Mute. */
12162306a36Sopenharmony_ci#define HCFG_PLAYBACK_DITHER	0x00001000	/* 1 = Add dither bit to all playback channels. */
12262306a36Sopenharmony_ci#define HCFG_PLAYBACK_S32_LE	0x00000800	/* 1 = S32_LE, 0 = S16_LE                       */
12362306a36Sopenharmony_ci#define HCFG_CAPTURE_S32_LE	0x00000400	/* 1 = S32_LE, 0 = S16_LE (S32_LE current not working)	*/
12462306a36Sopenharmony_ci#define HCFG_8_CHANNEL_PLAY	0x00000200	/* 1 = 8 channels, 0 = 2 channels per substream.*/
12562306a36Sopenharmony_ci#define HCFG_8_CHANNEL_CAPTURE	0x00000100	/* 1 = 8 channels, 0 = 2 channels per substream.*/
12662306a36Sopenharmony_ci#define HCFG_MONO		0x00000080	/* 1 = I2S Input mono                           */
12762306a36Sopenharmony_ci#define HCFG_I2S_OUTPUT		0x00000010	/* 1 = I2S Output disabled                      */
12862306a36Sopenharmony_ci#define HCFG_AC97		0x00000008	/* 0 = AC97 1.0, 1 = AC97 2.0                   */
12962306a36Sopenharmony_ci#define HCFG_LOCK_PLAYBACK_CACHE 0x00000004	/* 1 = Cancel bustmaster accesses to soundcache */
13062306a36Sopenharmony_ci						/* NOTE: This should generally never be used.  	*/
13162306a36Sopenharmony_ci#define HCFG_LOCK_CAPTURE_CACHE	0x00000002	/* 1 = Cancel bustmaster accesses to soundcache */
13262306a36Sopenharmony_ci						/* NOTE: This should generally never be used.  	*/
13362306a36Sopenharmony_ci#define HCFG_AUDIOENABLE	0x00000001	/* 0 = CODECs transmit zero-valued samples	*/
13462306a36Sopenharmony_ci						/* Should be set to 1 when the EMU10K1 is	*/
13562306a36Sopenharmony_ci						/* completely initialized.			*/
13662306a36Sopenharmony_ci#define CA0106_GPIO		0x18		/* Defaults: 005f03a3-Analog, 005f02a2-SPDIF.   */
13762306a36Sopenharmony_ci						/* Here pins 0,1,2,3,4,,6 are output. 5,7 are input */
13862306a36Sopenharmony_ci						/* For the Audigy LS, pin 0 (or bit 8) controls the SPDIF/Analog jack. */
13962306a36Sopenharmony_ci						/* SB Live 24bit:
14062306a36Sopenharmony_ci						 * bit 8 0 = SPDIF in and out / 1 = Analog (Mic or Line)-in.
14162306a36Sopenharmony_ci						 * bit 9 0 = Mute / 1 = Analog out.
14262306a36Sopenharmony_ci						 * bit 10 0 = Line-in / 1 = Mic-in.
14362306a36Sopenharmony_ci						 * bit 11 0 = ? / 1 = ?
14462306a36Sopenharmony_ci						 * bit 12 0 = 48 Khz / 1 = 96 Khz Analog out on SB Live 24bit.
14562306a36Sopenharmony_ci						 * bit 13 0 = ? / 1 = ?
14662306a36Sopenharmony_ci						 * bit 14 0 = Mute / 1 = Analog out
14762306a36Sopenharmony_ci						 * bit 15 0 = ? / 1 = ?
14862306a36Sopenharmony_ci						 * Both bit 9 and bit 14 have to be set for analog sound to work on the SB Live 24bit.
14962306a36Sopenharmony_ci						 */
15062306a36Sopenharmony_ci						/* 8 general purpose programmable In/Out pins.
15162306a36Sopenharmony_ci						 * GPI [8:0] Read only. Default 0.
15262306a36Sopenharmony_ci						 * GPO [15:8] Default 0x9. (Default to SPDIF jack enabled for SPDIF)
15362306a36Sopenharmony_ci						 * GPO Enable [23:16] Default 0x0f. Setting a bit to 1, causes the pin to be an output pin.
15462306a36Sopenharmony_ci						 */
15562306a36Sopenharmony_ci#define CA0106_AC97DATA		0x1c		/* AC97 register set data register (16 bit)	*/
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci#define CA0106_AC97ADDRESS	0x1e		/* AC97 register set address register (8 bit)	*/
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci/********************************************************************************************************/
16062306a36Sopenharmony_ci/* CA0106 pointer-offset register set, accessed through the PTR and DATA registers                     */
16162306a36Sopenharmony_ci/********************************************************************************************************/
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ci/* Initially all registers from 0x00 to 0x3f have zero contents. */
16462306a36Sopenharmony_ci#define PLAYBACK_LIST_ADDR	0x00		/* Base DMA address of a list of pointers to each period/size */
16562306a36Sopenharmony_ci						/* One list entry: 4 bytes for DMA address,
16662306a36Sopenharmony_ci						 * 4 bytes for period_size << 16.
16762306a36Sopenharmony_ci						 * One list entry is 8 bytes long.
16862306a36Sopenharmony_ci						 * One list entry for each period in the buffer.
16962306a36Sopenharmony_ci						 */
17062306a36Sopenharmony_ci						/* ADDR[31:0], Default: 0x0 */
17162306a36Sopenharmony_ci#define PLAYBACK_LIST_SIZE	0x01		/* Size of list in bytes << 16. E.g. 8 periods -> 0x00380000  */
17262306a36Sopenharmony_ci						/* SIZE[21:16], Default: 0x8 */
17362306a36Sopenharmony_ci#define PLAYBACK_LIST_PTR	0x02		/* Pointer to the current period being played */
17462306a36Sopenharmony_ci						/* PTR[5:0], Default: 0x0 */
17562306a36Sopenharmony_ci#define PLAYBACK_UNKNOWN3	0x03		/* Not used ?? */
17662306a36Sopenharmony_ci#define PLAYBACK_DMA_ADDR	0x04		/* Playback DMA address */
17762306a36Sopenharmony_ci						/* DMA[31:0], Default: 0x0 */
17862306a36Sopenharmony_ci#define PLAYBACK_PERIOD_SIZE	0x05		/* Playback period size. win2000 uses 0x04000000 */
17962306a36Sopenharmony_ci						/* SIZE[31:16], Default: 0x0 */
18062306a36Sopenharmony_ci#define PLAYBACK_POINTER	0x06		/* Playback period pointer. Used with PLAYBACK_LIST_PTR to determine buffer position currently in DAC */
18162306a36Sopenharmony_ci						/* POINTER[15:0], Default: 0x0 */
18262306a36Sopenharmony_ci#define PLAYBACK_PERIOD_END_ADDR 0x07		/* Playback fifo end address */
18362306a36Sopenharmony_ci						/* END_ADDR[15:0], FLAG[16] 0 = don't stop, 1 = stop */
18462306a36Sopenharmony_ci#define PLAYBACK_FIFO_OFFSET_ADDRESS	0x08	/* Current fifo offset address [21:16] */
18562306a36Sopenharmony_ci						/* Cache size valid [5:0] */
18662306a36Sopenharmony_ci#define PLAYBACK_UNKNOWN9	0x09		/* 0x9 to 0xf Unused */
18762306a36Sopenharmony_ci#define CAPTURE_DMA_ADDR	0x10		/* Capture DMA address */
18862306a36Sopenharmony_ci						/* DMA[31:0], Default: 0x0 */
18962306a36Sopenharmony_ci#define CAPTURE_BUFFER_SIZE	0x11		/* Capture buffer size */
19062306a36Sopenharmony_ci						/* SIZE[31:16], Default: 0x0 */
19162306a36Sopenharmony_ci#define CAPTURE_POINTER		0x12		/* Capture buffer pointer. Sample currently in ADC */
19262306a36Sopenharmony_ci						/* POINTER[15:0], Default: 0x0 */
19362306a36Sopenharmony_ci#define CAPTURE_FIFO_OFFSET_ADDRESS	0x13	/* Current fifo offset address [21:16] */
19462306a36Sopenharmony_ci						/* Cache size valid [5:0] */
19562306a36Sopenharmony_ci#define PLAYBACK_LAST_SAMPLE    0x20		/* The sample currently being played */
19662306a36Sopenharmony_ci/* 0x21 - 0x3f unused */
19762306a36Sopenharmony_ci#define BASIC_INTERRUPT         0x40		/* Used by both playback and capture interrupt handler */
19862306a36Sopenharmony_ci						/* Playback (0x1<<channel_id) */
19962306a36Sopenharmony_ci						/* Capture  (0x100<<channel_id) */
20062306a36Sopenharmony_ci						/* Playback sample rate 96000 = 0x20000 */
20162306a36Sopenharmony_ci						/* Start Playback [3:0] (one bit per channel)
20262306a36Sopenharmony_ci						 * Start Capture [11:8] (one bit per channel)
20362306a36Sopenharmony_ci						 * Playback rate [23:16] (2 bits per channel) (0=48kHz, 1=44.1kHz, 2=96kHz, 3=192Khz)
20462306a36Sopenharmony_ci						 * Playback mixer in enable [27:24] (one bit per channel)
20562306a36Sopenharmony_ci						 * Playback mixer out enable [31:28] (one bit per channel)
20662306a36Sopenharmony_ci						 */
20762306a36Sopenharmony_ci/* The Digital out jack is shared with the Center/LFE Analogue output.
20862306a36Sopenharmony_ci * The jack has 4 poles. I will call 1 - Tip, 2 - Next to 1, 3 - Next to 2, 4 - Next to 3
20962306a36Sopenharmony_ci * For Analogue: 1 -> Center Speaker, 2 -> Sub Woofer, 3 -> Ground, 4 -> Ground
21062306a36Sopenharmony_ci * For Digital: 1 -> Front SPDIF, 2 -> Rear SPDIF, 3 -> Center/Subwoofer SPDIF, 4 -> Ground.
21162306a36Sopenharmony_ci * Standard 4 pole Video A/V cable with RCA outputs: 1 -> White, 2 -> Yellow, 3 -> Shield on all three, 4 -> Red.
21262306a36Sopenharmony_ci * So, from this you can see that you cannot use a Standard 4 pole Video A/V cable with the SB Audigy LS card.
21362306a36Sopenharmony_ci */
21462306a36Sopenharmony_ci/* The Front SPDIF PCM gets mixed with samples from the AC97 codec, so can only work for Stereo PCM and not AC3/DTS
21562306a36Sopenharmony_ci * The Rear SPDIF can be used for Stereo PCM and also AC3/DTS
21662306a36Sopenharmony_ci * The Center/LFE SPDIF cannot be used for AC3/DTS, but can be used for Stereo PCM.
21762306a36Sopenharmony_ci * Summary: For ALSA we use the Rear channel for SPDIF Digital AC3/DTS output
21862306a36Sopenharmony_ci */
21962306a36Sopenharmony_ci/* A standard 2 pole mono mini-jack to RCA plug can be used for SPDIF Stereo PCM output from the Front channel.
22062306a36Sopenharmony_ci * A standard 3 pole stereo mini-jack to 2 RCA plugs can be used for SPDIF AC3/DTS and Stereo PCM output utilising the Rear channel and just one of the RCA plugs.
22162306a36Sopenharmony_ci */
22262306a36Sopenharmony_ci#define SPCS0			0x41		/* SPDIF output Channel Status 0 register. For Rear. default=0x02108004, non-audio=0x02108006	*/
22362306a36Sopenharmony_ci#define SPCS1			0x42		/* SPDIF output Channel Status 1 register. For Front */
22462306a36Sopenharmony_ci#define SPCS2			0x43		/* SPDIF output Channel Status 2 register. For Center/LFE */
22562306a36Sopenharmony_ci#define SPCS3			0x44		/* SPDIF output Channel Status 3 register. Unknown */
22662306a36Sopenharmony_ci						/* When Channel set to 0: */
22762306a36Sopenharmony_ci#define SPCS_CLKACCYMASK	0x30000000	/* Clock accuracy				*/
22862306a36Sopenharmony_ci#define SPCS_CLKACCY_1000PPM	0x00000000	/* 1000 parts per million			*/
22962306a36Sopenharmony_ci#define SPCS_CLKACCY_50PPM	0x10000000	/* 50 parts per million				*/
23062306a36Sopenharmony_ci#define SPCS_CLKACCY_VARIABLE	0x20000000	/* Variable accuracy				*/
23162306a36Sopenharmony_ci#define SPCS_SAMPLERATEMASK	0x0f000000	/* Sample rate					*/
23262306a36Sopenharmony_ci#define SPCS_SAMPLERATE_44	0x00000000	/* 44.1kHz sample rate				*/
23362306a36Sopenharmony_ci#define SPCS_SAMPLERATE_48	0x02000000	/* 48kHz sample rate				*/
23462306a36Sopenharmony_ci#define SPCS_SAMPLERATE_32	0x03000000	/* 32kHz sample rate				*/
23562306a36Sopenharmony_ci#define SPCS_CHANNELNUMMASK	0x00f00000	/* Channel number				*/
23662306a36Sopenharmony_ci#define SPCS_CHANNELNUM_UNSPEC	0x00000000	/* Unspecified channel number			*/
23762306a36Sopenharmony_ci#define SPCS_CHANNELNUM_LEFT	0x00100000	/* Left channel					*/
23862306a36Sopenharmony_ci#define SPCS_CHANNELNUM_RIGHT	0x00200000	/* Right channel				*/
23962306a36Sopenharmony_ci#define SPCS_SOURCENUMMASK	0x000f0000	/* Source number				*/
24062306a36Sopenharmony_ci#define SPCS_SOURCENUM_UNSPEC	0x00000000	/* Unspecified source number			*/
24162306a36Sopenharmony_ci#define SPCS_GENERATIONSTATUS	0x00008000	/* Originality flag (see IEC-958 spec)		*/
24262306a36Sopenharmony_ci#define SPCS_CATEGORYCODEMASK	0x00007f00	/* Category code (see IEC-958 spec)		*/
24362306a36Sopenharmony_ci#define SPCS_MODEMASK		0x000000c0	/* Mode (see IEC-958 spec)			*/
24462306a36Sopenharmony_ci#define SPCS_EMPHASISMASK	0x00000038	/* Emphasis					*/
24562306a36Sopenharmony_ci#define SPCS_EMPHASIS_NONE	0x00000000	/* No emphasis					*/
24662306a36Sopenharmony_ci#define SPCS_EMPHASIS_50_15	0x00000008	/* 50/15 usec 2 channel				*/
24762306a36Sopenharmony_ci#define SPCS_COPYRIGHT		0x00000004	/* Copyright asserted flag -- do not modify	*/
24862306a36Sopenharmony_ci#define SPCS_NOTAUDIODATA	0x00000002	/* 0 = Digital audio, 1 = not audio		*/
24962306a36Sopenharmony_ci#define SPCS_PROFESSIONAL	0x00000001	/* 0 = Consumer (IEC-958), 1 = pro (AES3-1992)	*/
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_ci						/* When Channel set to 1: */
25262306a36Sopenharmony_ci#define SPCS_WORD_LENGTH_MASK	0x0000000f	/* Word Length Mask				*/
25362306a36Sopenharmony_ci#define SPCS_WORD_LENGTH_16	0x00000008	/* Word Length 16 bit				*/
25462306a36Sopenharmony_ci#define SPCS_WORD_LENGTH_17	0x00000006	/* Word Length 17 bit				*/
25562306a36Sopenharmony_ci#define SPCS_WORD_LENGTH_18	0x00000004	/* Word Length 18 bit				*/
25662306a36Sopenharmony_ci#define SPCS_WORD_LENGTH_19	0x00000002	/* Word Length 19 bit				*/
25762306a36Sopenharmony_ci#define SPCS_WORD_LENGTH_20A	0x0000000a	/* Word Length 20 bit				*/
25862306a36Sopenharmony_ci#define SPCS_WORD_LENGTH_20	0x00000009	/* Word Length 20 bit (both 0xa and 0x9 are 20 bit) */
25962306a36Sopenharmony_ci#define SPCS_WORD_LENGTH_21	0x00000007	/* Word Length 21 bit				*/
26062306a36Sopenharmony_ci#define SPCS_WORD_LENGTH_22	0x00000005	/* Word Length 22 bit				*/
26162306a36Sopenharmony_ci#define SPCS_WORD_LENGTH_23	0x00000003	/* Word Length 23 bit				*/
26262306a36Sopenharmony_ci#define SPCS_WORD_LENGTH_24	0x0000000b	/* Word Length 24 bit				*/
26362306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_MASK	0x000000f0 /* Original Sample rate			*/
26462306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_NONE	0x00000000 /* Original Sample rate not indicated	*/
26562306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_16000	0x00000010 /* Original Sample rate	*/
26662306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_RES1	0x00000020 /* Original Sample rate	*/
26762306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_32000	0x00000030 /* Original Sample rate	*/
26862306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_12000	0x00000040 /* Original Sample rate	*/
26962306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_11025	0x00000050 /* Original Sample rate	*/
27062306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_8000	0x00000060 /* Original Sample rate	*/
27162306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_RES2	0x00000070 /* Original Sample rate	*/
27262306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_192000 0x00000080 /* Original Sample rate	*/
27362306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_24000	0x00000090 /* Original Sample rate	*/
27462306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_96000	0x000000a0 /* Original Sample rate	*/
27562306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_48000	0x000000b0 /* Original Sample rate	*/
27662306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_176400 0x000000c0 /* Original Sample rate	*/
27762306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_22050	0x000000d0 /* Original Sample rate	*/
27862306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_88200	0x000000e0 /* Original Sample rate	*/
27962306a36Sopenharmony_ci#define SPCS_ORIGINAL_SAMPLE_RATE_44100	0x000000f0 /* Original Sample rate	*/
28062306a36Sopenharmony_ci
28162306a36Sopenharmony_ci#define SPDIF_SELECT1		0x45		/* Enables SPDIF or Analogue outputs 0-SPDIF, 0xf00-Analogue */
28262306a36Sopenharmony_ci						/* 0x100 - Front, 0x800 - Rear, 0x200 - Center/LFE.
28362306a36Sopenharmony_ci						 * But as the jack is shared, use 0xf00.
28462306a36Sopenharmony_ci						 * The Windows2000 driver uses 0x0000000f for both digital and analog.
28562306a36Sopenharmony_ci						 * 0xf00 introduces interesting noises onto the Center/LFE.
28662306a36Sopenharmony_ci						 * If you turn the volume up, you hear computer noise,
28762306a36Sopenharmony_ci						 * e.g. mouse moving, changing between app windows etc.
28862306a36Sopenharmony_ci						 * So, I am going to set this to 0x0000000f all the time now,
28962306a36Sopenharmony_ci						 * same as the windows driver does.
29062306a36Sopenharmony_ci						 * Use register SPDIF_SELECT2(0x72) to switch between SPDIF and Analog.
29162306a36Sopenharmony_ci						 */
29262306a36Sopenharmony_ci						/* When Channel = 0:
29362306a36Sopenharmony_ci						 * Wide SPDIF format [3:0] (one bit for each channel) (0=20bit, 1=24bit)
29462306a36Sopenharmony_ci						 * Tristate SPDIF Output [11:8] (one bit for each channel) (0=Not tristate, 1=Tristate)
29562306a36Sopenharmony_ci						 * SPDIF Bypass enable [19:16] (one bit for each channel) (0=Not bypass, 1=Bypass)
29662306a36Sopenharmony_ci						 */
29762306a36Sopenharmony_ci						/* When Channel = 1:
29862306a36Sopenharmony_ci						 * SPDIF 0 User data [7:0]
29962306a36Sopenharmony_ci						 * SPDIF 1 User data [15:8]
30062306a36Sopenharmony_ci						 * SPDIF 0 User data [23:16]
30162306a36Sopenharmony_ci						 * SPDIF 0 User data [31:24]
30262306a36Sopenharmony_ci						 * User data can be sent by using the SPDIF output frame pending and SPDIF output user bit interrupts.
30362306a36Sopenharmony_ci						 */
30462306a36Sopenharmony_ci#define WATERMARK		0x46		/* Test bit to indicate cache usage level */
30562306a36Sopenharmony_ci#define SPDIF_INPUT_STATUS	0x49		/* SPDIF Input status register. Bits the same as SPCS.
30662306a36Sopenharmony_ci						 * When Channel = 0: Bits the same as SPCS channel 0.
30762306a36Sopenharmony_ci						 * When Channel = 1: Bits the same as SPCS channel 1.
30862306a36Sopenharmony_ci						 * When Channel = 2:
30962306a36Sopenharmony_ci						 * SPDIF Input User data [16:0]
31062306a36Sopenharmony_ci						 * SPDIF Input Frame count [21:16]
31162306a36Sopenharmony_ci						 */
31262306a36Sopenharmony_ci#define CAPTURE_CACHE_DATA	0x50		/* 0x50-0x5f Recorded samples. */
31362306a36Sopenharmony_ci#define CAPTURE_SOURCE          0x60            /* Capture Source 0 = MIC */
31462306a36Sopenharmony_ci#define CAPTURE_SOURCE_CHANNEL0 0xf0000000	/* Mask for selecting the Capture sources */
31562306a36Sopenharmony_ci#define CAPTURE_SOURCE_CHANNEL1 0x0f000000	/* 0 - SPDIF mixer output. */
31662306a36Sopenharmony_ci#define CAPTURE_SOURCE_CHANNEL2 0x00f00000      /* 1 - What you hear or . 2 - ?? */
31762306a36Sopenharmony_ci#define CAPTURE_SOURCE_CHANNEL3 0x000f0000	/* 3 - Mic in, Line in, TAD in, Aux in. */
31862306a36Sopenharmony_ci#define CAPTURE_SOURCE_RECORD_MAP 0x0000ffff	/* Default 0x00e4 */
31962306a36Sopenharmony_ci						/* Record Map [7:0] (2 bits per channel) 0=mapped to channel 0, 1=mapped to channel 1, 2=mapped to channel2, 3=mapped to channel3
32062306a36Sopenharmony_ci						 * Record source select for channel 0 [18:16]
32162306a36Sopenharmony_ci						 * Record source select for channel 1 [22:20]
32262306a36Sopenharmony_ci						 * Record source select for channel 2 [26:24]
32362306a36Sopenharmony_ci						 * Record source select for channel 3 [30:28]
32462306a36Sopenharmony_ci						 * 0 - SPDIF mixer output.
32562306a36Sopenharmony_ci						 * 1 - i2s mixer output.
32662306a36Sopenharmony_ci						 * 2 - SPDIF input.
32762306a36Sopenharmony_ci						 * 3 - i2s input.
32862306a36Sopenharmony_ci						 * 4 - AC97 capture.
32962306a36Sopenharmony_ci						 * 5 - SRC output.
33062306a36Sopenharmony_ci						 */
33162306a36Sopenharmony_ci#define CAPTURE_VOLUME1         0x61            /* Capture  volume per channel 0-3 */
33262306a36Sopenharmony_ci#define CAPTURE_VOLUME2         0x62            /* Capture  volume per channel 4-7 */
33362306a36Sopenharmony_ci
33462306a36Sopenharmony_ci#define PLAYBACK_ROUTING1       0x63            /* Playback routing of channels 0-7. Effects AC3 output. Default 0x32765410 */
33562306a36Sopenharmony_ci#define ROUTING1_REAR           0x77000000      /* Channel_id 0 sends to 10, Channel_id 1 sends to 32 */
33662306a36Sopenharmony_ci#define ROUTING1_NULL           0x00770000      /* Channel_id 2 sends to 54, Channel_id 3 sends to 76 */
33762306a36Sopenharmony_ci#define ROUTING1_CENTER_LFE     0x00007700      /* 0x32765410 means, send Channel_id 0 to FRONT, Channel_id 1 to REAR */
33862306a36Sopenharmony_ci#define ROUTING1_FRONT          0x00000077	/* Channel_id 2 to CENTER_LFE, Channel_id 3 to NULL. */
33962306a36Sopenharmony_ci						/* Channel_id's handle stereo channels. Channel X is a single mono channel */
34062306a36Sopenharmony_ci						/* Host is input from the PCI bus. */
34162306a36Sopenharmony_ci						/* Host channel 0 [2:0] -> SPDIF Mixer/Router channel 0-7.
34262306a36Sopenharmony_ci						 * Host channel 1 [6:4] -> SPDIF Mixer/Router channel 0-7.
34362306a36Sopenharmony_ci						 * Host channel 2 [10:8] -> SPDIF Mixer/Router channel 0-7.
34462306a36Sopenharmony_ci						 * Host channel 3 [14:12] -> SPDIF Mixer/Router channel 0-7.
34562306a36Sopenharmony_ci						 * Host channel 4 [18:16] -> SPDIF Mixer/Router channel 0-7.
34662306a36Sopenharmony_ci						 * Host channel 5 [22:20] -> SPDIF Mixer/Router channel 0-7.
34762306a36Sopenharmony_ci						 * Host channel 6 [26:24] -> SPDIF Mixer/Router channel 0-7.
34862306a36Sopenharmony_ci						 * Host channel 7 [30:28] -> SPDIF Mixer/Router channel 0-7.
34962306a36Sopenharmony_ci						 */
35062306a36Sopenharmony_ci
35162306a36Sopenharmony_ci#define PLAYBACK_ROUTING2       0x64            /* Playback Routing . Feeding Capture channels back into Playback. Effects AC3 output. Default 0x76767676 */
35262306a36Sopenharmony_ci						/* SRC is input from the capture inputs. */
35362306a36Sopenharmony_ci						/* SRC channel 0 [2:0] -> SPDIF Mixer/Router channel 0-7.
35462306a36Sopenharmony_ci						 * SRC channel 1 [6:4] -> SPDIF Mixer/Router channel 0-7.
35562306a36Sopenharmony_ci						 * SRC channel 2 [10:8] -> SPDIF Mixer/Router channel 0-7.
35662306a36Sopenharmony_ci						 * SRC channel 3 [14:12] -> SPDIF Mixer/Router channel 0-7.
35762306a36Sopenharmony_ci						 * SRC channel 4 [18:16] -> SPDIF Mixer/Router channel 0-7.
35862306a36Sopenharmony_ci						 * SRC channel 5 [22:20] -> SPDIF Mixer/Router channel 0-7.
35962306a36Sopenharmony_ci						 * SRC channel 6 [26:24] -> SPDIF Mixer/Router channel 0-7.
36062306a36Sopenharmony_ci						 * SRC channel 7 [30:28] -> SPDIF Mixer/Router channel 0-7.
36162306a36Sopenharmony_ci						 */
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_ci#define PLAYBACK_MUTE           0x65            /* Unknown. While playing 0x0, while silent 0x00fc0000 */
36462306a36Sopenharmony_ci						/* SPDIF Mixer input control:
36562306a36Sopenharmony_ci						 * Invert SRC to SPDIF Mixer [7-0] (One bit per channel)
36662306a36Sopenharmony_ci						 * Invert Host to SPDIF Mixer [15:8] (One bit per channel)
36762306a36Sopenharmony_ci						 * SRC to SPDIF Mixer disable [23:16] (One bit per channel)
36862306a36Sopenharmony_ci						 * Host to SPDIF Mixer disable [31:24] (One bit per channel)
36962306a36Sopenharmony_ci						 */
37062306a36Sopenharmony_ci#define PLAYBACK_VOLUME1        0x66            /* Playback SPDIF volume per channel. Set to the same PLAYBACK_VOLUME(0x6a) */
37162306a36Sopenharmony_ci						/* PLAYBACK_VOLUME1 must be set to 30303030 for SPDIF AC3 Playback */
37262306a36Sopenharmony_ci						/* SPDIF mixer input volume. 0=12dB, 0x30=0dB, 0xFE=-51.5dB, 0xff=Mute */
37362306a36Sopenharmony_ci						/* One register for each of the 4 stereo streams. */
37462306a36Sopenharmony_ci						/* SRC Right volume [7:0]
37562306a36Sopenharmony_ci						 * SRC Left  volume [15:8]
37662306a36Sopenharmony_ci						 * Host Right volume [23:16]
37762306a36Sopenharmony_ci						 * Host Left  volume [31:24]
37862306a36Sopenharmony_ci						 */
37962306a36Sopenharmony_ci#define CAPTURE_ROUTING1        0x67            /* Capture Routing. Default 0x32765410 */
38062306a36Sopenharmony_ci						/* Similar to register 0x63, except that the destination is the I2S mixer instead of the SPDIF mixer. I.E. Outputs to the Analog outputs instead of SPDIF. */
38162306a36Sopenharmony_ci#define CAPTURE_ROUTING2        0x68            /* Unknown Routing. Default 0x76767676 */
38262306a36Sopenharmony_ci						/* Similar to register 0x64, except that the destination is the I2S mixer instead of the SPDIF mixer. I.E. Outputs to the Analog outputs instead of SPDIF. */
38362306a36Sopenharmony_ci#define CAPTURE_MUTE            0x69            /* Unknown. While capturing 0x0, while silent 0x00fc0000 */
38462306a36Sopenharmony_ci						/* Similar to register 0x65, except that the destination is the I2S mixer instead of the SPDIF mixer. I.E. Outputs to the Analog outputs instead of SPDIF. */
38562306a36Sopenharmony_ci#define PLAYBACK_VOLUME2        0x6a            /* Playback Analog volume per channel. Does not effect AC3 output */
38662306a36Sopenharmony_ci						/* Similar to register 0x66, except that the destination is the I2S mixer instead of the SPDIF mixer. I.E. Outputs to the Analog outputs instead of SPDIF. */
38762306a36Sopenharmony_ci#define UNKNOWN6b               0x6b            /* Unknown. Readonly. Default 00400000 00400000 00400000 00400000 */
38862306a36Sopenharmony_ci#define MIDI_UART_A_DATA		0x6c            /* Midi Uart A Data */
38962306a36Sopenharmony_ci#define MIDI_UART_A_CMD		0x6d            /* Midi Uart A Command/Status */
39062306a36Sopenharmony_ci#define MIDI_UART_B_DATA		0x6e            /* Midi Uart B Data (currently unused) */
39162306a36Sopenharmony_ci#define MIDI_UART_B_CMD		0x6f            /* Midi Uart B Command/Status (currently unused) */
39262306a36Sopenharmony_ci
39362306a36Sopenharmony_ci/* unique channel identifier for midi->channel */
39462306a36Sopenharmony_ci
39562306a36Sopenharmony_ci#define CA0106_MIDI_CHAN_A		0x1
39662306a36Sopenharmony_ci#define CA0106_MIDI_CHAN_B		0x2
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_ci/* from mpu401 */
39962306a36Sopenharmony_ci
40062306a36Sopenharmony_ci#define CA0106_MIDI_INPUT_AVAIL 	0x80
40162306a36Sopenharmony_ci#define CA0106_MIDI_OUTPUT_READY	0x40
40262306a36Sopenharmony_ci#define CA0106_MPU401_RESET		0xff
40362306a36Sopenharmony_ci#define CA0106_MPU401_ENTER_UART	0x3f
40462306a36Sopenharmony_ci#define CA0106_MPU401_ACK		0xfe
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ci#define SAMPLE_RATE_TRACKER_STATUS 0x70         /* Readonly. Default 00108000 00108000 00500000 00500000 */
40762306a36Sopenharmony_ci						/* Estimated sample rate [19:0] Relative to 48kHz. 0x8000 =  1.0
40862306a36Sopenharmony_ci						 * Rate Locked [20]
40962306a36Sopenharmony_ci						 * SPDIF Locked [21] For SPDIF channel only.
41062306a36Sopenharmony_ci						 * Valid Audio [22] For SPDIF channel only.
41162306a36Sopenharmony_ci						 */
41262306a36Sopenharmony_ci#define CAPTURE_CONTROL         0x71            /* Some sort of routing. default = 40c81000 30303030 30300000 00700000 */
41362306a36Sopenharmony_ci						/* Channel_id 0: 0x40c81000 must be changed to 0x40c80000 for SPDIF AC3 input or output. */
41462306a36Sopenharmony_ci						/* Channel_id 1: 0xffffffff(mute) 0x30303030(max) controls CAPTURE feedback into PLAYBACK. */
41562306a36Sopenharmony_ci						/* Sample rate output control register Channel=0
41662306a36Sopenharmony_ci						 * Sample output rate [1:0] (0=48kHz, 1=44.1kHz, 2=96kHz, 3=192Khz)
41762306a36Sopenharmony_ci						 * Sample input rate [3:2] (0=48kHz, 1=Not available, 2=96kHz, 3=192Khz)
41862306a36Sopenharmony_ci						 * SRC input source select [4] 0=Audio from digital mixer, 1=Audio from analog source.
41962306a36Sopenharmony_ci						 * Record rate [9:8] (0=48kHz, 1=Not available, 2=96kHz, 3=192Khz)
42062306a36Sopenharmony_ci						 * Record mixer output enable [12:10]
42162306a36Sopenharmony_ci						 * I2S input rate master mode [15:14] (0=48kHz, 1=44.1kHz, 2=96kHz, 3=192Khz)
42262306a36Sopenharmony_ci						 * I2S output rate [17:16] (0=48kHz, 1=44.1kHz, 2=96kHz, 3=192Khz)
42362306a36Sopenharmony_ci						 * I2S output source select [18] (0=Audio from host, 1=Audio from SRC)
42462306a36Sopenharmony_ci						 * Record mixer I2S enable [20:19] (enable/disable i2sin1 and i2sin0)
42562306a36Sopenharmony_ci						 * I2S output master clock select [21] (0=256*I2S output rate, 1=512*I2S output rate.)
42662306a36Sopenharmony_ci						 * I2S input master clock select [22] (0=256*I2S input rate, 1=512*I2S input rate.)
42762306a36Sopenharmony_ci						 * I2S input mode [23] (0=Slave, 1=Master)
42862306a36Sopenharmony_ci						 * SPDIF output rate [25:24] (0=48kHz, 1=44.1kHz, 2=96kHz, 3=192Khz)
42962306a36Sopenharmony_ci						 * SPDIF output source select [26] (0=host, 1=SRC)
43062306a36Sopenharmony_ci						 * Not used [27]
43162306a36Sopenharmony_ci						 * Record Source 0 input [29:28] (0=SPDIF in, 1=I2S in, 2=AC97 Mic, 3=AC97 PCM)
43262306a36Sopenharmony_ci						 * Record Source 1 input [31:30] (0=SPDIF in, 1=I2S in, 2=AC97 Mic, 3=AC97 PCM)
43362306a36Sopenharmony_ci						 */
43462306a36Sopenharmony_ci						/* Sample rate output control register Channel=1
43562306a36Sopenharmony_ci						 * I2S Input 0 volume Right [7:0]
43662306a36Sopenharmony_ci						 * I2S Input 0 volume Left [15:8]
43762306a36Sopenharmony_ci						 * I2S Input 1 volume Right [23:16]
43862306a36Sopenharmony_ci						 * I2S Input 1 volume Left [31:24]
43962306a36Sopenharmony_ci						 */
44062306a36Sopenharmony_ci						/* Sample rate output control register Channel=2
44162306a36Sopenharmony_ci						 * SPDIF Input volume Right [23:16]
44262306a36Sopenharmony_ci						 * SPDIF Input volume Left [31:24]
44362306a36Sopenharmony_ci						 */
44462306a36Sopenharmony_ci						/* Sample rate output control register Channel=3
44562306a36Sopenharmony_ci						 * No used
44662306a36Sopenharmony_ci						 */
44762306a36Sopenharmony_ci#define SPDIF_SELECT2           0x72            /* Some sort of routing. Channel_id 0 only. default = 0x0f0f003f. Analog 0x000b0000, Digital 0x0b000000 */
44862306a36Sopenharmony_ci#define ROUTING2_FRONT_MASK     0x00010000      /* Enable for Front speakers. */
44962306a36Sopenharmony_ci#define ROUTING2_CENTER_LFE_MASK 0x00020000     /* Enable for Center/LFE speakers. */
45062306a36Sopenharmony_ci#define ROUTING2_REAR_MASK      0x00080000      /* Enable for Rear speakers. */
45162306a36Sopenharmony_ci						/* Audio output control
45262306a36Sopenharmony_ci						 * AC97 output enable [5:0]
45362306a36Sopenharmony_ci						 * I2S output enable [19:16]
45462306a36Sopenharmony_ci						 * SPDIF output enable [27:24]
45562306a36Sopenharmony_ci						 */
45662306a36Sopenharmony_ci#define UNKNOWN73               0x73            /* Unknown. Readonly. Default 0x0 */
45762306a36Sopenharmony_ci#define CHIP_VERSION            0x74            /* P17 Chip version. Channel_id 0 only. Default 00000071 */
45862306a36Sopenharmony_ci#define EXTENDED_INT_MASK       0x75            /* Used by both playback and capture interrupt handler */
45962306a36Sopenharmony_ci						/* Sets which Interrupts are enabled. */
46062306a36Sopenharmony_ci						/* 0x00000001 = Half period. Playback.
46162306a36Sopenharmony_ci						 * 0x00000010 = Full period. Playback.
46262306a36Sopenharmony_ci						 * 0x00000100 = Half buffer. Playback.
46362306a36Sopenharmony_ci						 * 0x00001000 = Full buffer. Playback.
46462306a36Sopenharmony_ci						 * 0x00010000 = Half buffer. Capture.
46562306a36Sopenharmony_ci						 * 0x00100000 = Full buffer. Capture.
46662306a36Sopenharmony_ci						 * Capture can only do 2 periods.
46762306a36Sopenharmony_ci						 * 0x01000000 = End audio. Playback.
46862306a36Sopenharmony_ci						 * 0x40000000 = Half buffer Playback,Caputre xrun.
46962306a36Sopenharmony_ci						 * 0x80000000 = Full buffer Playback,Caputre xrun.
47062306a36Sopenharmony_ci						 */
47162306a36Sopenharmony_ci#define EXTENDED_INT            0x76            /* Used by both playback and capture interrupt handler */
47262306a36Sopenharmony_ci						/* Shows which interrupts are active at the moment. */
47362306a36Sopenharmony_ci						/* Same bit layout as EXTENDED_INT_MASK */
47462306a36Sopenharmony_ci#define COUNTER77               0x77		/* Counter range 0 to 0x3fffff, 192000 counts per second. */
47562306a36Sopenharmony_ci#define COUNTER78               0x78		/* Counter range 0 to 0x3fffff, 44100 counts per second. */
47662306a36Sopenharmony_ci#define EXTENDED_INT_TIMER      0x79            /* Channel_id 0 only. Used by both playback and capture interrupt handler */
47762306a36Sopenharmony_ci						/* Causes interrupts based on timer intervals. */
47862306a36Sopenharmony_ci#define SPI			0x7a		/* SPI: Serial Interface Register */
47962306a36Sopenharmony_ci#define I2C_A			0x7b		/* I2C Address. 32 bit */
48062306a36Sopenharmony_ci#define I2C_D0			0x7c		/* I2C Data Port 0. 32 bit */
48162306a36Sopenharmony_ci#define I2C_D1			0x7d		/* I2C Data Port 1. 32 bit */
48262306a36Sopenharmony_ci//I2C values
48362306a36Sopenharmony_ci#define I2C_A_ADC_ADD_MASK	0x000000fe	//The address is a 7 bit address
48462306a36Sopenharmony_ci#define I2C_A_ADC_RW_MASK	0x00000001	//bit mask for R/W
48562306a36Sopenharmony_ci#define I2C_A_ADC_TRANS_MASK	0x00000010  	//Bit mask for I2c address DAC value
48662306a36Sopenharmony_ci#define I2C_A_ADC_ABORT_MASK	0x00000020	//Bit mask for I2C transaction abort flag
48762306a36Sopenharmony_ci#define I2C_A_ADC_LAST_MASK	0x00000040	//Bit mask for Last word transaction
48862306a36Sopenharmony_ci#define I2C_A_ADC_BYTE_MASK	0x00000080	//Bit mask for Byte Mode
48962306a36Sopenharmony_ci
49062306a36Sopenharmony_ci#define I2C_A_ADC_ADD		0x00000034	//This is the Device address for ADC
49162306a36Sopenharmony_ci#define I2C_A_ADC_READ		0x00000001	//To perform a read operation
49262306a36Sopenharmony_ci#define I2C_A_ADC_START		0x00000100	//Start I2C transaction
49362306a36Sopenharmony_ci#define I2C_A_ADC_ABORT		0x00000200	//I2C transaction abort
49462306a36Sopenharmony_ci#define I2C_A_ADC_LAST		0x00000400	//I2C last transaction
49562306a36Sopenharmony_ci#define I2C_A_ADC_BYTE		0x00000800	//I2C one byte mode
49662306a36Sopenharmony_ci
49762306a36Sopenharmony_ci#define I2C_D_ADC_REG_MASK	0xfe000000  	//ADC address register
49862306a36Sopenharmony_ci#define I2C_D_ADC_DAT_MASK	0x01ff0000  	//ADC data register
49962306a36Sopenharmony_ci
50062306a36Sopenharmony_ci#define ADC_TIMEOUT		0x00000007	//ADC Timeout Clock Disable
50162306a36Sopenharmony_ci#define ADC_IFC_CTRL		0x0000000b	//ADC Interface Control
50262306a36Sopenharmony_ci#define ADC_MASTER		0x0000000c	//ADC Master Mode Control
50362306a36Sopenharmony_ci#define ADC_POWER		0x0000000d	//ADC PowerDown Control
50462306a36Sopenharmony_ci#define ADC_ATTEN_ADCL		0x0000000e	//ADC Attenuation ADCL
50562306a36Sopenharmony_ci#define ADC_ATTEN_ADCR		0x0000000f	//ADC Attenuation ADCR
50662306a36Sopenharmony_ci#define ADC_ALC_CTRL1		0x00000010	//ADC ALC Control 1
50762306a36Sopenharmony_ci#define ADC_ALC_CTRL2		0x00000011	//ADC ALC Control 2
50862306a36Sopenharmony_ci#define ADC_ALC_CTRL3		0x00000012	//ADC ALC Control 3
50962306a36Sopenharmony_ci#define ADC_NOISE_CTRL		0x00000013	//ADC Noise Gate Control
51062306a36Sopenharmony_ci#define ADC_LIMIT_CTRL		0x00000014	//ADC Limiter Control
51162306a36Sopenharmony_ci#define ADC_MUX			0x00000015  	//ADC Mux offset
51262306a36Sopenharmony_ci
51362306a36Sopenharmony_ci#if 0
51462306a36Sopenharmony_ci/* FIXME: Not tested yet. */
51562306a36Sopenharmony_ci#define ADC_GAIN_MASK		0x000000ff	//Mask for ADC Gain
51662306a36Sopenharmony_ci#define ADC_ZERODB		0x000000cf	//Value to set ADC to 0dB
51762306a36Sopenharmony_ci#define ADC_MUTE_MASK		0x000000c0	//Mask for ADC mute
51862306a36Sopenharmony_ci#define ADC_MUTE		0x000000c0	//Value to mute ADC
51962306a36Sopenharmony_ci#define ADC_OSR			0x00000008	//Mask for ADC oversample rate select
52062306a36Sopenharmony_ci#define ADC_TIMEOUT_DISABLE	0x00000008	//Value and mask to disable Timeout clock
52162306a36Sopenharmony_ci#define ADC_HPF_DISABLE		0x00000100	//Value and mask to disable High pass filter
52262306a36Sopenharmony_ci#define ADC_TRANWIN_MASK	0x00000070	//Mask for Length of Transient Window
52362306a36Sopenharmony_ci#endif
52462306a36Sopenharmony_ci
52562306a36Sopenharmony_ci#define ADC_MUX_MASK		0x0000000f	//Mask for ADC Mux
52662306a36Sopenharmony_ci#define ADC_MUX_PHONE		0x00000001	//Value to select TAD at ADC Mux (Not used)
52762306a36Sopenharmony_ci#define ADC_MUX_MIC		0x00000002	//Value to select Mic at ADC Mux
52862306a36Sopenharmony_ci#define ADC_MUX_LINEIN		0x00000004	//Value to select LineIn at ADC Mux
52962306a36Sopenharmony_ci#define ADC_MUX_AUX		0x00000008	//Value to select Aux at ADC Mux
53062306a36Sopenharmony_ci
53162306a36Sopenharmony_ci#define SET_CHANNEL 0  /* Testing channel outputs 0=Front, 1=Center/LFE, 2=Unknown, 3=Rear */
53262306a36Sopenharmony_ci#define PCM_FRONT_CHANNEL 0
53362306a36Sopenharmony_ci#define PCM_REAR_CHANNEL 1
53462306a36Sopenharmony_ci#define PCM_CENTER_LFE_CHANNEL 2
53562306a36Sopenharmony_ci#define PCM_UNKNOWN_CHANNEL 3
53662306a36Sopenharmony_ci#define CONTROL_FRONT_CHANNEL 0
53762306a36Sopenharmony_ci#define CONTROL_REAR_CHANNEL 3
53862306a36Sopenharmony_ci#define CONTROL_CENTER_LFE_CHANNEL 1
53962306a36Sopenharmony_ci#define CONTROL_UNKNOWN_CHANNEL 2
54062306a36Sopenharmony_ci
54162306a36Sopenharmony_ci
54262306a36Sopenharmony_ci/* Based on WM8768 Datasheet Rev 4.2 page 32 */
54362306a36Sopenharmony_ci#define SPI_REG_MASK	0x1ff	/* 16-bit SPI writes have a 7-bit address */
54462306a36Sopenharmony_ci#define SPI_REG_SHIFT	9	/* followed by 9 bits of data */
54562306a36Sopenharmony_ci
54662306a36Sopenharmony_ci#define SPI_LDA1_REG		0	/* digital attenuation */
54762306a36Sopenharmony_ci#define SPI_RDA1_REG		1
54862306a36Sopenharmony_ci#define SPI_LDA2_REG		4
54962306a36Sopenharmony_ci#define SPI_RDA2_REG		5
55062306a36Sopenharmony_ci#define SPI_LDA3_REG		6
55162306a36Sopenharmony_ci#define SPI_RDA3_REG		7
55262306a36Sopenharmony_ci#define SPI_LDA4_REG		13
55362306a36Sopenharmony_ci#define SPI_RDA4_REG		14
55462306a36Sopenharmony_ci#define SPI_MASTDA_REG		8
55562306a36Sopenharmony_ci
55662306a36Sopenharmony_ci#define SPI_DA_BIT_UPDATE	(1<<8)	/* update attenuation values */
55762306a36Sopenharmony_ci#define SPI_DA_BIT_0dB		0xff	/* 0 dB */
55862306a36Sopenharmony_ci#define SPI_DA_BIT_infdB	0x00	/* inf dB attenuation (mute) */
55962306a36Sopenharmony_ci
56062306a36Sopenharmony_ci#define SPI_PL_REG		2
56162306a36Sopenharmony_ci#define SPI_PL_BIT_L_M		(0<<5)	/* left channel = mute */
56262306a36Sopenharmony_ci#define SPI_PL_BIT_L_L		(1<<5)	/* left channel = left */
56362306a36Sopenharmony_ci#define SPI_PL_BIT_L_R		(2<<5)	/* left channel = right */
56462306a36Sopenharmony_ci#define SPI_PL_BIT_L_C		(3<<5)	/* left channel = (L+R)/2 */
56562306a36Sopenharmony_ci#define SPI_PL_BIT_R_M		(0<<7)	/* right channel = mute */
56662306a36Sopenharmony_ci#define SPI_PL_BIT_R_L		(1<<7)	/* right channel = left */
56762306a36Sopenharmony_ci#define SPI_PL_BIT_R_R		(2<<7)	/* right channel = right */
56862306a36Sopenharmony_ci#define SPI_PL_BIT_R_C		(3<<7)	/* right channel = (L+R)/2 */
56962306a36Sopenharmony_ci#define SPI_IZD_REG		2
57062306a36Sopenharmony_ci#define SPI_IZD_BIT		(0<<4)	/* infinite zero detect */
57162306a36Sopenharmony_ci
57262306a36Sopenharmony_ci#define SPI_FMT_REG		3
57362306a36Sopenharmony_ci#define SPI_FMT_BIT_RJ		(0<<0)	/* right justified mode */
57462306a36Sopenharmony_ci#define SPI_FMT_BIT_LJ		(1<<0)	/* left justified mode */
57562306a36Sopenharmony_ci#define SPI_FMT_BIT_I2S		(2<<0)	/* I2S mode */
57662306a36Sopenharmony_ci#define SPI_FMT_BIT_DSP		(3<<0)	/* DSP Modes A or B */
57762306a36Sopenharmony_ci#define SPI_LRP_REG		3
57862306a36Sopenharmony_ci#define SPI_LRP_BIT		(1<<2)	/* invert LRCLK polarity */
57962306a36Sopenharmony_ci#define SPI_BCP_REG		3
58062306a36Sopenharmony_ci#define SPI_BCP_BIT		(1<<3)	/* invert BCLK polarity */
58162306a36Sopenharmony_ci#define SPI_IWL_REG		3
58262306a36Sopenharmony_ci#define SPI_IWL_BIT_16		(0<<4)	/* 16-bit world length */
58362306a36Sopenharmony_ci#define SPI_IWL_BIT_20		(1<<4)	/* 20-bit world length */
58462306a36Sopenharmony_ci#define SPI_IWL_BIT_24		(2<<4)	/* 24-bit world length */
58562306a36Sopenharmony_ci#define SPI_IWL_BIT_32		(3<<4)	/* 32-bit world length */
58662306a36Sopenharmony_ci
58762306a36Sopenharmony_ci#define SPI_MS_REG		10
58862306a36Sopenharmony_ci#define SPI_MS_BIT		(1<<5)	/* master mode */
58962306a36Sopenharmony_ci#define SPI_RATE_REG		10	/* only applies in master mode */
59062306a36Sopenharmony_ci#define SPI_RATE_BIT_128	(0<<6)	/* MCLK = LRCLK * 128 */
59162306a36Sopenharmony_ci#define SPI_RATE_BIT_192	(1<<6)
59262306a36Sopenharmony_ci#define SPI_RATE_BIT_256	(2<<6)
59362306a36Sopenharmony_ci#define SPI_RATE_BIT_384	(3<<6)
59462306a36Sopenharmony_ci#define SPI_RATE_BIT_512	(4<<6)
59562306a36Sopenharmony_ci#define SPI_RATE_BIT_768	(5<<6)
59662306a36Sopenharmony_ci
59762306a36Sopenharmony_ci/* They really do label the bit for the 4th channel "4" and not "3" */
59862306a36Sopenharmony_ci#define SPI_DMUTE0_REG		9
59962306a36Sopenharmony_ci#define SPI_DMUTE1_REG		9
60062306a36Sopenharmony_ci#define SPI_DMUTE2_REG		9
60162306a36Sopenharmony_ci#define SPI_DMUTE4_REG		15
60262306a36Sopenharmony_ci#define SPI_DMUTE0_BIT		(1<<3)
60362306a36Sopenharmony_ci#define SPI_DMUTE1_BIT		(1<<4)
60462306a36Sopenharmony_ci#define SPI_DMUTE2_BIT		(1<<5)
60562306a36Sopenharmony_ci#define SPI_DMUTE4_BIT		(1<<2)
60662306a36Sopenharmony_ci
60762306a36Sopenharmony_ci#define SPI_PHASE0_REG		3
60862306a36Sopenharmony_ci#define SPI_PHASE1_REG		3
60962306a36Sopenharmony_ci#define SPI_PHASE2_REG		3
61062306a36Sopenharmony_ci#define SPI_PHASE4_REG		15
61162306a36Sopenharmony_ci#define SPI_PHASE0_BIT		(1<<6)
61262306a36Sopenharmony_ci#define SPI_PHASE1_BIT		(1<<7)
61362306a36Sopenharmony_ci#define SPI_PHASE2_BIT		(1<<8)
61462306a36Sopenharmony_ci#define SPI_PHASE4_BIT		(1<<3)
61562306a36Sopenharmony_ci
61662306a36Sopenharmony_ci#define SPI_PDWN_REG		2	/* power down all DACs */
61762306a36Sopenharmony_ci#define SPI_PDWN_BIT		(1<<2)
61862306a36Sopenharmony_ci#define SPI_DACD0_REG		10	/* power down individual DACs */
61962306a36Sopenharmony_ci#define SPI_DACD1_REG		10
62062306a36Sopenharmony_ci#define SPI_DACD2_REG		10
62162306a36Sopenharmony_ci#define SPI_DACD4_REG		15
62262306a36Sopenharmony_ci#define SPI_DACD0_BIT		(1<<1)
62362306a36Sopenharmony_ci#define SPI_DACD1_BIT		(1<<2)
62462306a36Sopenharmony_ci#define SPI_DACD2_BIT		(1<<3)
62562306a36Sopenharmony_ci#define SPI_DACD4_BIT		(1<<0)	/* datasheet error says it's 1 */
62662306a36Sopenharmony_ci
62762306a36Sopenharmony_ci#define SPI_PWRDNALL_REG	10	/* power down everything */
62862306a36Sopenharmony_ci#define SPI_PWRDNALL_BIT	(1<<4)
62962306a36Sopenharmony_ci
63062306a36Sopenharmony_ci#include "ca_midi.h"
63162306a36Sopenharmony_ci
63262306a36Sopenharmony_cistruct snd_ca0106;
63362306a36Sopenharmony_ci
63462306a36Sopenharmony_cistruct snd_ca0106_channel {
63562306a36Sopenharmony_ci	struct snd_ca0106 *emu;
63662306a36Sopenharmony_ci	int number;
63762306a36Sopenharmony_ci	int use;
63862306a36Sopenharmony_ci	void (*interrupt)(struct snd_ca0106 *emu, struct snd_ca0106_channel *channel);
63962306a36Sopenharmony_ci	struct snd_ca0106_pcm *epcm;
64062306a36Sopenharmony_ci};
64162306a36Sopenharmony_ci
64262306a36Sopenharmony_cistruct snd_ca0106_pcm {
64362306a36Sopenharmony_ci	struct snd_ca0106 *emu;
64462306a36Sopenharmony_ci	struct snd_pcm_substream *substream;
64562306a36Sopenharmony_ci        int channel_id;
64662306a36Sopenharmony_ci	unsigned short running;
64762306a36Sopenharmony_ci};
64862306a36Sopenharmony_ci
64962306a36Sopenharmony_cistruct snd_ca0106_details {
65062306a36Sopenharmony_ci        u32 serial;
65162306a36Sopenharmony_ci        char * name;
65262306a36Sopenharmony_ci	int ac97;	/* ac97 = 0 -> Select MIC, Line in, TAD in, AUX in.
65362306a36Sopenharmony_ci			   ac97 = 1 -> Default to AC97 in. */
65462306a36Sopenharmony_ci	int gpio_type;	/* gpio_type = 1 -> shared mic-in/line-in
65562306a36Sopenharmony_ci			   gpio_type = 2 -> shared side-out/line-in. */
65662306a36Sopenharmony_ci	int i2c_adc;	/* with i2c_adc=1, the driver adds some capture volume
65762306a36Sopenharmony_ci			   controls, phone, mic, line-in and aux. */
65862306a36Sopenharmony_ci	u16 spi_dac;	/* spi_dac = 0 -> no spi interface for DACs
65962306a36Sopenharmony_ci			   spi_dac = 0x<front><rear><center-lfe><side>
66062306a36Sopenharmony_ci			   -> specifies DAC id for each channel pair. */
66162306a36Sopenharmony_ci};
66262306a36Sopenharmony_ci
66362306a36Sopenharmony_ci// definition of the chip-specific record
66462306a36Sopenharmony_cistruct snd_ca0106 {
66562306a36Sopenharmony_ci	struct snd_card *card;
66662306a36Sopenharmony_ci	const struct snd_ca0106_details *details;
66762306a36Sopenharmony_ci	struct pci_dev *pci;
66862306a36Sopenharmony_ci
66962306a36Sopenharmony_ci	unsigned long port;
67062306a36Sopenharmony_ci	int irq;
67162306a36Sopenharmony_ci
67262306a36Sopenharmony_ci	unsigned int serial;            /* serial number */
67362306a36Sopenharmony_ci	unsigned short model;		/* subsystem id */
67462306a36Sopenharmony_ci
67562306a36Sopenharmony_ci	spinlock_t emu_lock;
67662306a36Sopenharmony_ci
67762306a36Sopenharmony_ci	struct snd_ac97 *ac97;
67862306a36Sopenharmony_ci	struct snd_pcm *pcm[4];
67962306a36Sopenharmony_ci
68062306a36Sopenharmony_ci	struct snd_ca0106_channel playback_channels[4];
68162306a36Sopenharmony_ci	struct snd_ca0106_channel capture_channels[4];
68262306a36Sopenharmony_ci	u32 spdif_bits[4];             /* s/pdif out default setup */
68362306a36Sopenharmony_ci	u32 spdif_str_bits[4];         /* s/pdif out per-stream setup */
68462306a36Sopenharmony_ci	int spdif_enable;
68562306a36Sopenharmony_ci	int capture_source;
68662306a36Sopenharmony_ci	int i2c_capture_source;
68762306a36Sopenharmony_ci	u8 i2c_capture_volume[4][2];
68862306a36Sopenharmony_ci	int capture_mic_line_in;
68962306a36Sopenharmony_ci
69062306a36Sopenharmony_ci	struct snd_dma_buffer *buffer;
69162306a36Sopenharmony_ci
69262306a36Sopenharmony_ci	struct snd_ca_midi midi;
69362306a36Sopenharmony_ci	struct snd_ca_midi midi2;
69462306a36Sopenharmony_ci
69562306a36Sopenharmony_ci	u16 spi_dac_reg[16];
69662306a36Sopenharmony_ci
69762306a36Sopenharmony_ci#ifdef CONFIG_PM_SLEEP
69862306a36Sopenharmony_ci#define NUM_SAVED_VOLUMES	9
69962306a36Sopenharmony_ci	unsigned int saved_vol[NUM_SAVED_VOLUMES];
70062306a36Sopenharmony_ci#endif
70162306a36Sopenharmony_ci};
70262306a36Sopenharmony_ci
70362306a36Sopenharmony_ciint snd_ca0106_mixer(struct snd_ca0106 *emu);
70462306a36Sopenharmony_ciint snd_ca0106_proc_init(struct snd_ca0106 * emu);
70562306a36Sopenharmony_ci
70662306a36Sopenharmony_ciunsigned int snd_ca0106_ptr_read(struct snd_ca0106 * emu,
70762306a36Sopenharmony_ci				 unsigned int reg,
70862306a36Sopenharmony_ci				 unsigned int chn);
70962306a36Sopenharmony_ci
71062306a36Sopenharmony_civoid snd_ca0106_ptr_write(struct snd_ca0106 *emu,
71162306a36Sopenharmony_ci			  unsigned int reg,
71262306a36Sopenharmony_ci			  unsigned int chn,
71362306a36Sopenharmony_ci			  unsigned int data);
71462306a36Sopenharmony_ci
71562306a36Sopenharmony_ciint snd_ca0106_i2c_write(struct snd_ca0106 *emu, u32 reg, u32 value);
71662306a36Sopenharmony_ci
71762306a36Sopenharmony_ciint snd_ca0106_spi_write(struct snd_ca0106 * emu,
71862306a36Sopenharmony_ci				   unsigned int data);
71962306a36Sopenharmony_ci
72062306a36Sopenharmony_ci#ifdef CONFIG_PM_SLEEP
72162306a36Sopenharmony_civoid snd_ca0106_mixer_suspend(struct snd_ca0106 *chip);
72262306a36Sopenharmony_civoid snd_ca0106_mixer_resume(struct snd_ca0106 *chip);
72362306a36Sopenharmony_ci#else
72462306a36Sopenharmony_ci#define snd_ca0106_mixer_suspend(chip)	do { } while (0)
72562306a36Sopenharmony_ci#define snd_ca0106_mixer_resume(chip)	do { } while (0)
72662306a36Sopenharmony_ci#endif
727