162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *  Copyright (c) by James Courtier-Dutton <James@superbug.demon.co.uk>
462306a36Sopenharmony_ci *  Driver p16v chips
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci *  This code was initially based on code from ALSA's emu10k1x.c which is:
762306a36Sopenharmony_ci *  Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci/********************************************************************************************************/
1162306a36Sopenharmony_ci/* Audigy2 P16V pointer-offset register set, accessed through the PTR2 and DATA2 registers              */
1262306a36Sopenharmony_ci/********************************************************************************************************/
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/* The sample rate of the SPDIF outputs is set by modifying a register in the EMU10K2 PTR register A_SPDIF_SAMPLERATE.
1562306a36Sopenharmony_ci * The sample rate is also controlled by the same registers that control the rate of the EMU10K2 sample rate converters.
1662306a36Sopenharmony_ci */
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci/* Initially all registers from 0x00 to 0x3f have zero contents. */
1962306a36Sopenharmony_ci#define PLAYBACK_LIST_ADDR	0x00		/* Base DMA address of a list of pointers to each period/size */
2062306a36Sopenharmony_ci						/* One list entry: 4 bytes for DMA address,
2162306a36Sopenharmony_ci						 * 4 bytes for period_size << 16.
2262306a36Sopenharmony_ci						 * One list entry is 8 bytes long.
2362306a36Sopenharmony_ci						 * One list entry for each period in the buffer.
2462306a36Sopenharmony_ci						 */
2562306a36Sopenharmony_ci#define PLAYBACK_LIST_SIZE	0x01		/* Size of list in bytes << 16. E.g. 8 periods -> 0x00380000  */
2662306a36Sopenharmony_ci#define PLAYBACK_LIST_PTR	0x02		/* Pointer to the current period being played */
2762306a36Sopenharmony_ci#define PLAYBACK_UNKNOWN3	0x03		/* Not used */
2862306a36Sopenharmony_ci#define PLAYBACK_DMA_ADDR	0x04		/* Playback DMA address */
2962306a36Sopenharmony_ci#define PLAYBACK_PERIOD_SIZE	0x05		/* Playback period size. win2000 uses 0x04000000 */
3062306a36Sopenharmony_ci#define PLAYBACK_POINTER	0x06		/* Playback period pointer. Used with PLAYBACK_LIST_PTR to determine buffer position currently in DAC */
3162306a36Sopenharmony_ci#define PLAYBACK_FIFO_END_ADDRESS	0x07		/* Playback FIFO end address */
3262306a36Sopenharmony_ci#define PLAYBACK_FIFO_POINTER	0x08		/* Playback FIFO pointer and number of valid sound samples in cache */
3362306a36Sopenharmony_ci#define PLAYBACK_UNKNOWN9	0x09		/* Not used */
3462306a36Sopenharmony_ci#define CAPTURE_DMA_ADDR	0x10		/* Capture DMA address */
3562306a36Sopenharmony_ci#define CAPTURE_BUFFER_SIZE	0x11		/* Capture buffer size */
3662306a36Sopenharmony_ci#define CAPTURE_POINTER		0x12		/* Capture buffer pointer. Sample currently in ADC */
3762306a36Sopenharmony_ci#define CAPTURE_FIFO_POINTER	0x13		/* Capture FIFO pointer and number of valid sound samples in cache */
3862306a36Sopenharmony_ci#define CAPTURE_P16V_VOLUME1	0x14		/* Low: Capture volume 0xXXXX3030 */
3962306a36Sopenharmony_ci#define CAPTURE_P16V_VOLUME2	0x15		/* High:Has no effect on capture volume */
4062306a36Sopenharmony_ci#define CAPTURE_P16V_SOURCE     0x16            /* P16V source select. Set to 0x0700E4E5 for AC97 CAPTURE */
4162306a36Sopenharmony_ci						/* [0:1] Capture input 0 channel select. 0 = Capture output 0.
4262306a36Sopenharmony_ci						 *                                       1 = Capture output 1.
4362306a36Sopenharmony_ci						 *                                       2 = Capture output 2.
4462306a36Sopenharmony_ci						 *                                       3 = Capture output 3.
4562306a36Sopenharmony_ci						 * [3:2] Capture input 1 channel select. 0 = Capture output 0.
4662306a36Sopenharmony_ci						 *                                       1 = Capture output 1.
4762306a36Sopenharmony_ci						 *                                       2 = Capture output 2.
4862306a36Sopenharmony_ci						 *                                       3 = Capture output 3.
4962306a36Sopenharmony_ci						 * [5:4] Capture input 2 channel select. 0 = Capture output 0.
5062306a36Sopenharmony_ci						 *                                       1 = Capture output 1.
5162306a36Sopenharmony_ci						 *                                       2 = Capture output 2.
5262306a36Sopenharmony_ci						 *                                       3 = Capture output 3.
5362306a36Sopenharmony_ci						 * [7:6] Capture input 3 channel select. 0 = Capture output 0.
5462306a36Sopenharmony_ci						 *                                       1 = Capture output 1.
5562306a36Sopenharmony_ci						 *                                       2 = Capture output 2.
5662306a36Sopenharmony_ci						 *                                       3 = Capture output 3.
5762306a36Sopenharmony_ci						 * [9:8] Playback input 0 channel select. 0 = Play output 0.
5862306a36Sopenharmony_ci						 *                                        1 = Play output 1.
5962306a36Sopenharmony_ci						 *                                        2 = Play output 2.
6062306a36Sopenharmony_ci						 *                                        3 = Play output 3.
6162306a36Sopenharmony_ci						 * [11:10] Playback input 1 channel select. 0 = Play output 0.
6262306a36Sopenharmony_ci						 *                                          1 = Play output 1.
6362306a36Sopenharmony_ci						 *                                          2 = Play output 2.
6462306a36Sopenharmony_ci						 *                                          3 = Play output 3.
6562306a36Sopenharmony_ci						 * [13:12] Playback input 2 channel select. 0 = Play output 0.
6662306a36Sopenharmony_ci						 *                                          1 = Play output 1.
6762306a36Sopenharmony_ci						 *                                          2 = Play output 2.
6862306a36Sopenharmony_ci						 *                                          3 = Play output 3.
6962306a36Sopenharmony_ci						 * [15:14] Playback input 3 channel select. 0 = Play output 0.
7062306a36Sopenharmony_ci						 *                                          1 = Play output 1.
7162306a36Sopenharmony_ci						 *                                          2 = Play output 2.
7262306a36Sopenharmony_ci						 *                                          3 = Play output 3.
7362306a36Sopenharmony_ci						 * [19:16] Playback mixer output enable. 1 bit per channel.
7462306a36Sopenharmony_ci						 * [23:20] Capture mixer output enable. 1 bit per channel.
7562306a36Sopenharmony_ci						 * [26:24] FX engine channel capture 0 = 0x60-0x67.
7662306a36Sopenharmony_ci						 *                                   1 = 0x68-0x6f.
7762306a36Sopenharmony_ci						 *                                   2 = 0x70-0x77.
7862306a36Sopenharmony_ci						 *                                   3 = 0x78-0x7f.
7962306a36Sopenharmony_ci						 *                                   4 = 0x80-0x87.
8062306a36Sopenharmony_ci						 *                                   5 = 0x88-0x8f.
8162306a36Sopenharmony_ci						 *                                   6 = 0x90-0x97.
8262306a36Sopenharmony_ci						 *                                   7 = 0x98-0x9f.
8362306a36Sopenharmony_ci						 * [31:27] Not used.
8462306a36Sopenharmony_ci						 */
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci						/* 0x1 = capture on.
8762306a36Sopenharmony_ci						 * 0x100 = capture off.
8862306a36Sopenharmony_ci						 * 0x200 = capture off.
8962306a36Sopenharmony_ci						 * 0x1000 = capture off.
9062306a36Sopenharmony_ci						 */
9162306a36Sopenharmony_ci#define CAPTURE_RATE_STATUS		0x17		/* Capture sample rate. Read only */
9262306a36Sopenharmony_ci						/* [15:0] Not used.
9362306a36Sopenharmony_ci						 * [18:16] Channel 0 Detected sample rate. 0 - 44.1khz
9462306a36Sopenharmony_ci						 *                               1 - 48 khz
9562306a36Sopenharmony_ci						 *                               2 - 96 khz
9662306a36Sopenharmony_ci						 *                               3 - 192 khz
9762306a36Sopenharmony_ci						 *                               7 - undefined rate.
9862306a36Sopenharmony_ci						 * [19] Channel 0. 1 - Valid, 0 - Not Valid.
9962306a36Sopenharmony_ci						 * [22:20] Channel 1 Detected sample rate.
10062306a36Sopenharmony_ci						 * [23] Channel 1. 1 - Valid, 0 - Not Valid.
10162306a36Sopenharmony_ci						 * [26:24] Channel 2 Detected sample rate.
10262306a36Sopenharmony_ci						 * [27] Channel 2. 1 - Valid, 0 - Not Valid.
10362306a36Sopenharmony_ci						 * [30:28] Channel 3 Detected sample rate.
10462306a36Sopenharmony_ci						 * [31] Channel 3. 1 - Valid, 0 - Not Valid.
10562306a36Sopenharmony_ci						 */
10662306a36Sopenharmony_ci/* 0x18 - 0x1f unused */
10762306a36Sopenharmony_ci#define PLAYBACK_LAST_SAMPLE    0x20		/* The sample currently being played. Read only */
10862306a36Sopenharmony_ci/* 0x21 - 0x3f unused */
10962306a36Sopenharmony_ci#define BASIC_INTERRUPT         0x40		/* Used by both playback and capture interrupt handler */
11062306a36Sopenharmony_ci						/* Playback (0x1<<channel_id) Don't touch high 16bits. */
11162306a36Sopenharmony_ci						/* Capture  (0x100<<channel_id). not tested */
11262306a36Sopenharmony_ci						/* Start Playback [3:0] (one bit per channel)
11362306a36Sopenharmony_ci						 * Start Capture [11:8] (one bit per channel)
11462306a36Sopenharmony_ci						 * Record source select for channel 0 [18:16]
11562306a36Sopenharmony_ci						 * Record source select for channel 1 [22:20]
11662306a36Sopenharmony_ci						 * Record source select for channel 2 [26:24]
11762306a36Sopenharmony_ci						 * Record source select for channel 3 [30:28]
11862306a36Sopenharmony_ci						 * 0 - SPDIF channel.
11962306a36Sopenharmony_ci						 * 1 - I2S channel.
12062306a36Sopenharmony_ci						 * 2 - SRC48 channel.
12162306a36Sopenharmony_ci						 * 3 - SRCMulti_SPDIF channel.
12262306a36Sopenharmony_ci						 * 4 - SRCMulti_I2S channel.
12362306a36Sopenharmony_ci						 * 5 - SPDIF channel.
12462306a36Sopenharmony_ci						 * 6 - fxengine capture.
12562306a36Sopenharmony_ci						 * 7 - AC97 capture.
12662306a36Sopenharmony_ci						 */
12762306a36Sopenharmony_ci						/* Default 41110000.
12862306a36Sopenharmony_ci						 * Writing 0xffffffff hangs the PC.
12962306a36Sopenharmony_ci						 * Writing 0xffff0000 -> 77770000 so it must be some sort of route.
13062306a36Sopenharmony_ci						 * bit 0x1 starts DMA playback on channel_id 0
13162306a36Sopenharmony_ci						 */
13262306a36Sopenharmony_ci/* 0x41,42 take values from 0 - 0xffffffff, but have no effect on playback */
13362306a36Sopenharmony_ci/* 0x43,0x48 do not remember settings */
13462306a36Sopenharmony_ci/* 0x41-45 unused */
13562306a36Sopenharmony_ci#define WATERMARK            0x46		/* Test bit to indicate cache level usage */
13662306a36Sopenharmony_ci						/* Values it can have while playing on channel 0.
13762306a36Sopenharmony_ci						 * 0000f000, 0000f004, 0000f008, 0000f00c.
13862306a36Sopenharmony_ci						 * Readonly.
13962306a36Sopenharmony_ci						 */
14062306a36Sopenharmony_ci/* 0x47-0x4f unused */
14162306a36Sopenharmony_ci/* 0x50-0x5f Capture cache data */
14262306a36Sopenharmony_ci#define SRCSel			0x60            /* SRCSel. Default 0x4. Bypass P16V 0x14 */
14362306a36Sopenharmony_ci						/* [0] 0 = 10K2 audio, 1 = SRC48 mixer output.
14462306a36Sopenharmony_ci						 * [2] 0 = 10K2 audio, 1 = SRCMulti SPDIF mixer output.
14562306a36Sopenharmony_ci						 * [4] 0 = 10K2 audio, 1 = SRCMulti I2S mixer output.
14662306a36Sopenharmony_ci						 */
14762306a36Sopenharmony_ci						/* SRC48 converts samples rates 44.1, 48, 96, 192 to 48 khz. */
14862306a36Sopenharmony_ci						/* SRCMulti converts 48khz samples rates to 44.1, 48, 96, 192 to 48. */
14962306a36Sopenharmony_ci						/* SRC48 and SRCMULTI sample rate select and output select. */
15062306a36Sopenharmony_ci						/* 0xffffffff -> 0xC0000015
15162306a36Sopenharmony_ci						 * 0xXXXXXXX4 = Enable Front Left/Right
15262306a36Sopenharmony_ci						 * Enable PCMs
15362306a36Sopenharmony_ci						 */
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci/* 0x61 -> 0x6c are Volume controls */
15662306a36Sopenharmony_ci#define PLAYBACK_VOLUME_MIXER1  0x61		/* SRC48 Low to mixer input volume control. */
15762306a36Sopenharmony_ci#define PLAYBACK_VOLUME_MIXER2  0x62		/* SRC48 High to mixer input volume control. */
15862306a36Sopenharmony_ci#define PLAYBACK_VOLUME_MIXER3  0x63		/* SRCMULTI SPDIF Low to mixer input volume control. */
15962306a36Sopenharmony_ci#define PLAYBACK_VOLUME_MIXER4  0x64		/* SRCMULTI SPDIF High to mixer input volume control. */
16062306a36Sopenharmony_ci#define PLAYBACK_VOLUME_MIXER5  0x65		/* SRCMULTI I2S Low to mixer input volume control. */
16162306a36Sopenharmony_ci#define PLAYBACK_VOLUME_MIXER6  0x66		/* SRCMULTI I2S High to mixer input volume control. */
16262306a36Sopenharmony_ci#define PLAYBACK_VOLUME_MIXER7  0x67		/* P16V Low to SRCMULTI SPDIF mixer input volume control. */
16362306a36Sopenharmony_ci#define PLAYBACK_VOLUME_MIXER8  0x68		/* P16V High to SRCMULTI SPDIF mixer input volume control. */
16462306a36Sopenharmony_ci#define PLAYBACK_VOLUME_MIXER9  0x69		/* P16V Low to SRCMULTI I2S mixer input volume control. */
16562306a36Sopenharmony_ci						/* 0xXXXX3030 = PCM0 Volume (Front).
16662306a36Sopenharmony_ci						 * 0x3030XXXX = PCM1 Volume (Center)
16762306a36Sopenharmony_ci						 */
16862306a36Sopenharmony_ci#define PLAYBACK_VOLUME_MIXER10  0x6a		/* P16V High to SRCMULTI I2S mixer input volume control. */
16962306a36Sopenharmony_ci						/* 0x3030XXXX = PCM3 Volume (Rear). */
17062306a36Sopenharmony_ci#define PLAYBACK_VOLUME_MIXER11  0x6b		/* E10K2 Low to SRC48 mixer input volume control. */
17162306a36Sopenharmony_ci#define PLAYBACK_VOLUME_MIXER12 0x6c		/* E10K2 High to SRC48 mixer input volume control. */
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci#define SRC48_ENABLE            0x6d            /* SRC48 input audio enable */
17462306a36Sopenharmony_ci						/* SRC48 converts samples rates 44.1, 48, 96, 192 to 48 khz. */
17562306a36Sopenharmony_ci						/* [23:16] The corresponding P16V channel to SRC48 enabled if == 1.
17662306a36Sopenharmony_ci						 * [31:24] The corresponding E10K2 channel to SRC48 enabled.
17762306a36Sopenharmony_ci						 */
17862306a36Sopenharmony_ci#define SRCMULTI_ENABLE         0x6e            /* SRCMulti input audio enable. Default 0xffffffff */
17962306a36Sopenharmony_ci						/* SRCMulti converts 48khz samples rates to 44.1, 48, 96, 192 to 48. */
18062306a36Sopenharmony_ci						/* [7:0] The corresponding P16V channel to SRCMulti_I2S enabled if == 1.
18162306a36Sopenharmony_ci						 * [15:8] The corresponding E10K2 channel to SRCMulti I2S enabled.
18262306a36Sopenharmony_ci						 * [23:16] The corresponding P16V channel to SRCMulti SPDIF enabled.
18362306a36Sopenharmony_ci						 * [31:24] The corresponding E10K2 channel to SRCMulti SPDIF enabled.
18462306a36Sopenharmony_ci						 */
18562306a36Sopenharmony_ci						/* Bypass P16V 0xff00ff00
18662306a36Sopenharmony_ci						 * Bitmap. 0 = Off, 1 = On.
18762306a36Sopenharmony_ci						 * P16V playback outputs:
18862306a36Sopenharmony_ci						 * 0xXXXXXXX1 = PCM0 Left. (Front)
18962306a36Sopenharmony_ci						 * 0xXXXXXXX2 = PCM0 Right.
19062306a36Sopenharmony_ci						 * 0xXXXXXXX4 = PCM1 Left. (Center/LFE)
19162306a36Sopenharmony_ci						 * 0xXXXXXXX8 = PCM1 Right.
19262306a36Sopenharmony_ci						 * 0xXXXXXX1X = PCM2 Left. (Unknown)
19362306a36Sopenharmony_ci						 * 0xXXXXXX2X = PCM2 Right.
19462306a36Sopenharmony_ci						 * 0xXXXXXX4X = PCM3 Left. (Rear)
19562306a36Sopenharmony_ci						 * 0xXXXXXX8X = PCM3 Right.
19662306a36Sopenharmony_ci						 */
19762306a36Sopenharmony_ci#define AUDIO_OUT_ENABLE        0x6f            /* Default: 000100FF */
19862306a36Sopenharmony_ci						/* [3:0] Does something, but not documented. Probably capture enable.
19962306a36Sopenharmony_ci						 * [7:4] Playback channels enable. not documented.
20062306a36Sopenharmony_ci						 * [16] AC97 output enable if == 1
20162306a36Sopenharmony_ci						 * [30] 0 = SRCMulti_I2S input from fxengine 0x68-0x6f.
20262306a36Sopenharmony_ci						 *      1 = SRCMulti_I2S input from SRC48 output.
20362306a36Sopenharmony_ci						 * [31] 0 = SRCMulti_SPDIF input from fxengine 0x60-0x67.
20462306a36Sopenharmony_ci						 *      1 = SRCMulti_SPDIF input from SRC48 output.
20562306a36Sopenharmony_ci						 */
20662306a36Sopenharmony_ci						/* 0xffffffff -> C00100FF */
20762306a36Sopenharmony_ci						/* 0 -> Not playback sound, irq still running */
20862306a36Sopenharmony_ci						/* 0xXXXXXX10 = PCM0 Left/Right On. (Front)
20962306a36Sopenharmony_ci						 * 0xXXXXXX20 = PCM1 Left/Right On. (Center/LFE)
21062306a36Sopenharmony_ci						 * 0xXXXXXX40 = PCM2 Left/Right On. (Unknown)
21162306a36Sopenharmony_ci						 * 0xXXXXXX80 = PCM3 Left/Right On. (Rear)
21262306a36Sopenharmony_ci						 */
21362306a36Sopenharmony_ci#define PLAYBACK_SPDIF_SELECT     0x70          /* Default: 12030F00 */
21462306a36Sopenharmony_ci						/* 0xffffffff -> 3FF30FFF */
21562306a36Sopenharmony_ci						/* 0x00000001 pauses stream/irq fail. */
21662306a36Sopenharmony_ci						/* All other bits do not effect playback */
21762306a36Sopenharmony_ci#define PLAYBACK_SPDIF_SRC_SELECT 0x71          /* Default: 0000E4E4 */
21862306a36Sopenharmony_ci						/* 0xffffffff -> F33FFFFF */
21962306a36Sopenharmony_ci						/* All bits do not effect playback */
22062306a36Sopenharmony_ci#define PLAYBACK_SPDIF_USER_DATA0 0x72		/* SPDIF out user data 0 */
22162306a36Sopenharmony_ci#define PLAYBACK_SPDIF_USER_DATA1 0x73		/* SPDIF out user data 1 */
22262306a36Sopenharmony_ci/* 0x74-0x75 unknown */
22362306a36Sopenharmony_ci#define CAPTURE_SPDIF_CONTROL	0x76		/* SPDIF in control setting */
22462306a36Sopenharmony_ci#define CAPTURE_SPDIF_STATUS	0x77		/* SPDIF in status */
22562306a36Sopenharmony_ci#define CAPURE_SPDIF_USER_DATA0 0x78		/* SPDIF in user data 0 */
22662306a36Sopenharmony_ci#define CAPURE_SPDIF_USER_DATA1 0x79		/* SPDIF in user data 1 */
22762306a36Sopenharmony_ci#define CAPURE_SPDIF_USER_DATA2 0x7a		/* SPDIF in user data 2 */
22862306a36Sopenharmony_ci
229