Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Driver for Digigram miXart soundcards |
| 4 | * |
| 5 | * main header file |
| 6 | * |
| 7 | * Copyright (c) 2003 by Digigram <alsa@digigram.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #ifndef __SOUND_MIXART_H |
| 11 | #define __SOUND_MIXART_H |
| 12 | |
| 13 | #include <linux/interrupt.h> |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 14 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <sound/pcm.h> |
| 16 | |
| 17 | #define MIXART_DRIVER_VERSION 0x000100 /* 0.1.0 */ |
| 18 | |
| 19 | |
| 20 | /* |
| 21 | */ |
| 22 | |
Takashi Iwai | 67b48b8 | 2005-11-17 15:01:08 +0100 | [diff] [blame] | 23 | struct mixart_uid { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | u32 object_id; |
| 25 | u32 desc; |
| 26 | }; |
| 27 | |
| 28 | struct mem_area { |
| 29 | unsigned long phys; |
| 30 | void __iomem *virt; |
| 31 | struct resource *res; |
| 32 | }; |
| 33 | |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | struct mixart_route { |
| 36 | unsigned char connected; |
| 37 | unsigned char phase_inv; |
| 38 | int volume; |
| 39 | }; |
| 40 | |
| 41 | |
| 42 | /* firmware status codes */ |
| 43 | #define MIXART_MOTHERBOARD_XLX_INDEX 0 |
| 44 | #define MIXART_MOTHERBOARD_ELF_INDEX 1 |
| 45 | #define MIXART_AESEBUBOARD_XLX_INDEX 2 |
| 46 | #define MIXART_HARDW_FILES_MAX_INDEX 3 /* xilinx, elf, AESEBU xilinx */ |
| 47 | |
| 48 | #define MIXART_MAX_CARDS 4 |
| 49 | #define MSG_FIFO_SIZE 16 |
| 50 | |
| 51 | #define MIXART_MAX_PHYS_CONNECTORS (MIXART_MAX_CARDS * 2 * 2) /* 4 * stereo * (analog+digital) */ |
| 52 | |
Takashi Iwai | 67b48b8 | 2005-11-17 15:01:08 +0100 | [diff] [blame] | 53 | struct mixart_mgr { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | unsigned int num_cards; |
Takashi Iwai | 67b48b8 | 2005-11-17 15:01:08 +0100 | [diff] [blame] | 55 | struct snd_mixart *chip[MIXART_MAX_CARDS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | struct pci_dev *pci; |
| 58 | |
| 59 | int irq; |
| 60 | |
| 61 | /* memory-maps */ |
| 62 | struct mem_area mem[2]; |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | /* one and only blocking message or notification may be pending */ |
| 65 | u32 pending_event; |
| 66 | wait_queue_head_t msg_sleep; |
| 67 | |
Takashi Iwai | 8d3a8b5 | 2014-09-10 11:48:07 +0200 | [diff] [blame] | 68 | /* messages fifo */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | u32 msg_fifo[MSG_FIFO_SIZE]; |
| 70 | int msg_fifo_readptr; |
| 71 | int msg_fifo_writeptr; |
Geliang Tang | 1c623c2 | 2016-12-24 23:28:34 +0800 | [diff] [blame] | 72 | atomic_t msg_processed; /* number of messages to be processed in tasklet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Takashi Iwai | 8d3a8b5 | 2014-09-10 11:48:07 +0200 | [diff] [blame] | 74 | struct mutex lock; /* interrupt lock */ |
| 75 | struct mutex msg_lock; /* mailbox lock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 77 | struct mutex setup_mutex; /* mutex used in hw_params, open and close */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | /* hardware interface */ |
| 80 | unsigned int dsp_loaded; /* bit flags of loaded dsp indices */ |
| 81 | unsigned int board_type; /* read from embedded once elf file is loaded, 250 = miXart8, 251 = with AES, 252 = with Cobranet */ |
| 82 | |
| 83 | struct snd_dma_buffer flowinfo; |
| 84 | struct snd_dma_buffer bufferinfo; |
| 85 | |
Takashi Iwai | 67b48b8 | 2005-11-17 15:01:08 +0100 | [diff] [blame] | 86 | struct mixart_uid uid_console_manager; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | int sample_rate; |
| 88 | int ref_count_rate; |
| 89 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 90 | struct mutex mixer_mutex; /* mutex for mixer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | }; |
| 93 | |
| 94 | |
| 95 | #define MIXART_STREAM_STATUS_FREE 0 |
| 96 | #define MIXART_STREAM_STATUS_OPEN 1 |
| 97 | #define MIXART_STREAM_STATUS_RUNNING 2 |
| 98 | #define MIXART_STREAM_STATUS_DRAINING 3 |
| 99 | #define MIXART_STREAM_STATUS_PAUSE 4 |
| 100 | |
| 101 | #define MIXART_PLAYBACK_STREAMS 4 |
| 102 | #define MIXART_CAPTURE_STREAMS 1 |
| 103 | |
| 104 | #define MIXART_PCM_ANALOG 0 |
| 105 | #define MIXART_PCM_DIGITAL 1 |
| 106 | #define MIXART_PCM_TOTAL 2 |
| 107 | |
| 108 | #define MIXART_MAX_STREAM_PER_CARD (MIXART_PCM_TOTAL * (MIXART_PLAYBACK_STREAMS + MIXART_CAPTURE_STREAMS) ) |
| 109 | |
| 110 | |
| 111 | #define MIXART_NOTIFY_CARD_MASK 0xF000 |
| 112 | #define MIXART_NOTIFY_CARD_OFFSET 12 |
| 113 | #define MIXART_NOTIFY_PCM_MASK 0x0F00 |
| 114 | #define MIXART_NOTIFY_PCM_OFFSET 8 |
| 115 | #define MIXART_NOTIFY_CAPT_MASK 0x0080 |
| 116 | #define MIXART_NOTIFY_SUBS_MASK 0x007F |
| 117 | |
| 118 | |
Takashi Iwai | 67b48b8 | 2005-11-17 15:01:08 +0100 | [diff] [blame] | 119 | struct mixart_stream { |
| 120 | struct snd_pcm_substream *substream; |
| 121 | struct mixart_pipe *pipe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | int pcm_number; |
| 123 | |
| 124 | int status; /* nothing, running, draining */ |
| 125 | |
| 126 | u64 abs_period_elapsed; /* last absolute stream position where period_elapsed was called (multiple of runtime->period_size) */ |
| 127 | u32 buf_periods; /* periods counter in the buffer (< runtime->periods) */ |
| 128 | u32 buf_period_frag; /* defines with buf_period_pos the exact position in the buffer (< runtime->period_size) */ |
| 129 | |
| 130 | int channels; |
| 131 | }; |
| 132 | |
| 133 | |
| 134 | enum mixart_pipe_status { |
| 135 | PIPE_UNDEFINED, |
| 136 | PIPE_STOPPED, |
| 137 | PIPE_RUNNING, |
| 138 | PIPE_CLOCK_SET |
| 139 | }; |
| 140 | |
Takashi Iwai | 67b48b8 | 2005-11-17 15:01:08 +0100 | [diff] [blame] | 141 | struct mixart_pipe { |
| 142 | struct mixart_uid group_uid; /* id of the pipe, as returned by embedded */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | int stream_count; |
Takashi Iwai | 67b48b8 | 2005-11-17 15:01:08 +0100 | [diff] [blame] | 144 | struct mixart_uid uid_left_connector; /* UID's for the audio connectors */ |
| 145 | struct mixart_uid uid_right_connector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | enum mixart_pipe_status status; |
| 147 | int references; /* number of subs openned */ |
| 148 | int monitoring; /* pipe used for monitoring issue */ |
| 149 | }; |
| 150 | |
| 151 | |
| 152 | struct snd_mixart { |
Takashi Iwai | 67b48b8 | 2005-11-17 15:01:08 +0100 | [diff] [blame] | 153 | struct snd_card *card; |
| 154 | struct mixart_mgr *mgr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | int chip_idx; /* zero based */ |
Takashi Iwai | 67b48b8 | 2005-11-17 15:01:08 +0100 | [diff] [blame] | 156 | struct snd_hwdep *hwdep; /* DSP loader, only for the first card */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Takashi Iwai | 67b48b8 | 2005-11-17 15:01:08 +0100 | [diff] [blame] | 158 | struct snd_pcm *pcm; /* PCM analog i/o */ |
| 159 | struct snd_pcm *pcm_dig; /* PCM digital i/o */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | /* allocate stereo pipe for instance */ |
Takashi Iwai | 67b48b8 | 2005-11-17 15:01:08 +0100 | [diff] [blame] | 162 | struct mixart_pipe pipe_in_ana; |
| 163 | struct mixart_pipe pipe_out_ana; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | /* if AES/EBU daughter board is available, additional pipes possible on pcm_dig */ |
Takashi Iwai | 67b48b8 | 2005-11-17 15:01:08 +0100 | [diff] [blame] | 166 | struct mixart_pipe pipe_in_dig; |
| 167 | struct mixart_pipe pipe_out_dig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
Takashi Iwai | 67b48b8 | 2005-11-17 15:01:08 +0100 | [diff] [blame] | 169 | struct mixart_stream playback_stream[MIXART_PCM_TOTAL][MIXART_PLAYBACK_STREAMS]; /* 0 = pcm, 1 = pcm_dig */ |
| 170 | struct mixart_stream capture_stream[MIXART_PCM_TOTAL]; /* 0 = pcm, 1 = pcm_dig */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | /* UID's for the physical io's */ |
Takashi Iwai | 67b48b8 | 2005-11-17 15:01:08 +0100 | [diff] [blame] | 173 | struct mixart_uid uid_out_analog_physio; |
| 174 | struct mixart_uid uid_in_analog_physio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | int analog_playback_active[2]; /* Mixer : Master Playback active (!mute) */ |
| 177 | int analog_playback_volume[2]; /* Mixer : Master Playback Volume */ |
| 178 | int analog_capture_volume[2]; /* Mixer : Master Capture Volume */ |
| 179 | int digital_playback_active[2*MIXART_PLAYBACK_STREAMS][2]; /* Mixer : Digital Playback Active [(analog+AES output)*streams][stereo]*/ |
| 180 | int digital_playback_volume[2*MIXART_PLAYBACK_STREAMS][2]; /* Mixer : Digital Playback Volume [(analog+AES output)*streams][stereo]*/ |
| 181 | int digital_capture_volume[2][2]; /* Mixer : Digital Capture Volume [analog+AES output][stereo] */ |
| 182 | int monitoring_active[2]; /* Mixer : Monitoring Active */ |
| 183 | int monitoring_volume[2]; /* Mixer : Monitoring Volume */ |
| 184 | }; |
| 185 | |
| 186 | struct mixart_bufferinfo |
| 187 | { |
| 188 | u32 buffer_address; |
| 189 | u32 reserved[5]; |
| 190 | u32 available_length; |
| 191 | u32 buffer_id; |
| 192 | }; |
| 193 | |
| 194 | struct mixart_flowinfo |
| 195 | { |
| 196 | u32 bufferinfo_array_phy_address; |
| 197 | u32 reserved[11]; |
| 198 | u32 bufferinfo_count; |
| 199 | u32 capture; |
| 200 | }; |
| 201 | |
| 202 | /* exported */ |
Takashi Iwai | 67b48b8 | 2005-11-17 15:01:08 +0100 | [diff] [blame] | 203 | int snd_mixart_create_pcm(struct snd_mixart * chip); |
| 204 | struct mixart_pipe *snd_mixart_add_ref_pipe(struct snd_mixart *chip, int pcm_number, int capture, int monitoring); |
| 205 | int snd_mixart_kill_ref_pipe(struct mixart_mgr *mgr, struct mixart_pipe *pipe, int monitoring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
| 207 | #endif /* __SOUND_MIXART_H */ |