18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Driver for Digigram miXart soundcards 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * main header file 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (c) 2003 by Digigram <alsa@digigram.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef __SOUND_MIXART_H 118c2ecf20Sopenharmony_ci#define __SOUND_MIXART_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 148c2ecf20Sopenharmony_ci#include <linux/mutex.h> 158c2ecf20Sopenharmony_ci#include <sound/pcm.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define MIXART_DRIVER_VERSION 0x000100 /* 0.1.0 */ 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci/* 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistruct mixart_uid { 248c2ecf20Sopenharmony_ci u32 object_id; 258c2ecf20Sopenharmony_ci u32 desc; 268c2ecf20Sopenharmony_ci}; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_cistruct mem_area { 298c2ecf20Sopenharmony_ci unsigned long phys; 308c2ecf20Sopenharmony_ci void __iomem *virt; 318c2ecf20Sopenharmony_ci struct resource *res; 328c2ecf20Sopenharmony_ci}; 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_cistruct mixart_route { 368c2ecf20Sopenharmony_ci unsigned char connected; 378c2ecf20Sopenharmony_ci unsigned char phase_inv; 388c2ecf20Sopenharmony_ci int volume; 398c2ecf20Sopenharmony_ci}; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/* firmware status codes */ 438c2ecf20Sopenharmony_ci#define MIXART_MOTHERBOARD_XLX_INDEX 0 448c2ecf20Sopenharmony_ci#define MIXART_MOTHERBOARD_ELF_INDEX 1 458c2ecf20Sopenharmony_ci#define MIXART_AESEBUBOARD_XLX_INDEX 2 468c2ecf20Sopenharmony_ci#define MIXART_HARDW_FILES_MAX_INDEX 3 /* xilinx, elf, AESEBU xilinx */ 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define MIXART_MAX_CARDS 4 498c2ecf20Sopenharmony_ci#define MSG_FIFO_SIZE 16 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#define MIXART_MAX_PHYS_CONNECTORS (MIXART_MAX_CARDS * 2 * 2) /* 4 * stereo * (analog+digital) */ 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cistruct mixart_mgr { 548c2ecf20Sopenharmony_ci unsigned int num_cards; 558c2ecf20Sopenharmony_ci struct snd_mixart *chip[MIXART_MAX_CARDS]; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci struct pci_dev *pci; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci int irq; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci /* memory-maps */ 628c2ecf20Sopenharmony_ci struct mem_area mem[2]; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci /* one and only blocking message or notification may be pending */ 658c2ecf20Sopenharmony_ci u32 pending_event; 668c2ecf20Sopenharmony_ci wait_queue_head_t msg_sleep; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci /* messages fifo */ 698c2ecf20Sopenharmony_ci u32 msg_fifo[MSG_FIFO_SIZE]; 708c2ecf20Sopenharmony_ci int msg_fifo_readptr; 718c2ecf20Sopenharmony_ci int msg_fifo_writeptr; 728c2ecf20Sopenharmony_ci atomic_t msg_processed; /* number of messages to be processed in irq thread */ 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci struct mutex lock; /* interrupt lock */ 758c2ecf20Sopenharmony_ci struct mutex msg_lock; /* mailbox lock */ 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci struct mutex setup_mutex; /* mutex used in hw_params, open and close */ 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci /* hardware interface */ 808c2ecf20Sopenharmony_ci unsigned int dsp_loaded; /* bit flags of loaded dsp indices */ 818c2ecf20Sopenharmony_ci unsigned int board_type; /* read from embedded once elf file is loaded, 250 = miXart8, 251 = with AES, 252 = with Cobranet */ 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci struct snd_dma_buffer flowinfo; 848c2ecf20Sopenharmony_ci struct snd_dma_buffer bufferinfo; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci struct mixart_uid uid_console_manager; 878c2ecf20Sopenharmony_ci int sample_rate; 888c2ecf20Sopenharmony_ci int ref_count_rate; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci struct mutex mixer_mutex; /* mutex for mixer */ 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci}; 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci#define MIXART_STREAM_STATUS_FREE 0 968c2ecf20Sopenharmony_ci#define MIXART_STREAM_STATUS_OPEN 1 978c2ecf20Sopenharmony_ci#define MIXART_STREAM_STATUS_RUNNING 2 988c2ecf20Sopenharmony_ci#define MIXART_STREAM_STATUS_DRAINING 3 998c2ecf20Sopenharmony_ci#define MIXART_STREAM_STATUS_PAUSE 4 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci#define MIXART_PLAYBACK_STREAMS 4 1028c2ecf20Sopenharmony_ci#define MIXART_CAPTURE_STREAMS 1 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci#define MIXART_PCM_ANALOG 0 1058c2ecf20Sopenharmony_ci#define MIXART_PCM_DIGITAL 1 1068c2ecf20Sopenharmony_ci#define MIXART_PCM_TOTAL 2 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci#define MIXART_MAX_STREAM_PER_CARD (MIXART_PCM_TOTAL * (MIXART_PLAYBACK_STREAMS + MIXART_CAPTURE_STREAMS) ) 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#define MIXART_NOTIFY_CARD_MASK 0xF000 1128c2ecf20Sopenharmony_ci#define MIXART_NOTIFY_CARD_OFFSET 12 1138c2ecf20Sopenharmony_ci#define MIXART_NOTIFY_PCM_MASK 0x0F00 1148c2ecf20Sopenharmony_ci#define MIXART_NOTIFY_PCM_OFFSET 8 1158c2ecf20Sopenharmony_ci#define MIXART_NOTIFY_CAPT_MASK 0x0080 1168c2ecf20Sopenharmony_ci#define MIXART_NOTIFY_SUBS_MASK 0x007F 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistruct mixart_stream { 1208c2ecf20Sopenharmony_ci struct snd_pcm_substream *substream; 1218c2ecf20Sopenharmony_ci struct mixart_pipe *pipe; 1228c2ecf20Sopenharmony_ci int pcm_number; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci int status; /* nothing, running, draining */ 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci u64 abs_period_elapsed; /* last absolute stream position where period_elapsed was called (multiple of runtime->period_size) */ 1278c2ecf20Sopenharmony_ci u32 buf_periods; /* periods counter in the buffer (< runtime->periods) */ 1288c2ecf20Sopenharmony_ci u32 buf_period_frag; /* defines with buf_period_pos the exact position in the buffer (< runtime->period_size) */ 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci int channels; 1318c2ecf20Sopenharmony_ci}; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_cienum mixart_pipe_status { 1358c2ecf20Sopenharmony_ci PIPE_UNDEFINED, 1368c2ecf20Sopenharmony_ci PIPE_STOPPED, 1378c2ecf20Sopenharmony_ci PIPE_RUNNING, 1388c2ecf20Sopenharmony_ci PIPE_CLOCK_SET 1398c2ecf20Sopenharmony_ci}; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_cistruct mixart_pipe { 1428c2ecf20Sopenharmony_ci struct mixart_uid group_uid; /* id of the pipe, as returned by embedded */ 1438c2ecf20Sopenharmony_ci int stream_count; 1448c2ecf20Sopenharmony_ci struct mixart_uid uid_left_connector; /* UID's for the audio connectors */ 1458c2ecf20Sopenharmony_ci struct mixart_uid uid_right_connector; 1468c2ecf20Sopenharmony_ci enum mixart_pipe_status status; 1478c2ecf20Sopenharmony_ci int references; /* number of subs openned */ 1488c2ecf20Sopenharmony_ci int monitoring; /* pipe used for monitoring issue */ 1498c2ecf20Sopenharmony_ci}; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_cistruct snd_mixart { 1538c2ecf20Sopenharmony_ci struct snd_card *card; 1548c2ecf20Sopenharmony_ci struct mixart_mgr *mgr; 1558c2ecf20Sopenharmony_ci int chip_idx; /* zero based */ 1568c2ecf20Sopenharmony_ci struct snd_hwdep *hwdep; /* DSP loader, only for the first card */ 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci struct snd_pcm *pcm; /* PCM analog i/o */ 1598c2ecf20Sopenharmony_ci struct snd_pcm *pcm_dig; /* PCM digital i/o */ 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci /* allocate stereo pipe for instance */ 1628c2ecf20Sopenharmony_ci struct mixart_pipe pipe_in_ana; 1638c2ecf20Sopenharmony_ci struct mixart_pipe pipe_out_ana; 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci /* if AES/EBU daughter board is available, additional pipes possible on pcm_dig */ 1668c2ecf20Sopenharmony_ci struct mixart_pipe pipe_in_dig; 1678c2ecf20Sopenharmony_ci struct mixart_pipe pipe_out_dig; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci struct mixart_stream playback_stream[MIXART_PCM_TOTAL][MIXART_PLAYBACK_STREAMS]; /* 0 = pcm, 1 = pcm_dig */ 1708c2ecf20Sopenharmony_ci struct mixart_stream capture_stream[MIXART_PCM_TOTAL]; /* 0 = pcm, 1 = pcm_dig */ 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci /* UID's for the physical io's */ 1738c2ecf20Sopenharmony_ci struct mixart_uid uid_out_analog_physio; 1748c2ecf20Sopenharmony_ci struct mixart_uid uid_in_analog_physio; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci int analog_playback_active[2]; /* Mixer : Master Playback active (!mute) */ 1778c2ecf20Sopenharmony_ci int analog_playback_volume[2]; /* Mixer : Master Playback Volume */ 1788c2ecf20Sopenharmony_ci int analog_capture_volume[2]; /* Mixer : Master Capture Volume */ 1798c2ecf20Sopenharmony_ci int digital_playback_active[2*MIXART_PLAYBACK_STREAMS][2]; /* Mixer : Digital Playback Active [(analog+AES output)*streams][stereo]*/ 1808c2ecf20Sopenharmony_ci int digital_playback_volume[2*MIXART_PLAYBACK_STREAMS][2]; /* Mixer : Digital Playback Volume [(analog+AES output)*streams][stereo]*/ 1818c2ecf20Sopenharmony_ci int digital_capture_volume[2][2]; /* Mixer : Digital Capture Volume [analog+AES output][stereo] */ 1828c2ecf20Sopenharmony_ci int monitoring_active[2]; /* Mixer : Monitoring Active */ 1838c2ecf20Sopenharmony_ci int monitoring_volume[2]; /* Mixer : Monitoring Volume */ 1848c2ecf20Sopenharmony_ci}; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_cistruct mixart_bufferinfo 1878c2ecf20Sopenharmony_ci{ 1888c2ecf20Sopenharmony_ci u32 buffer_address; 1898c2ecf20Sopenharmony_ci u32 reserved[5]; 1908c2ecf20Sopenharmony_ci u32 available_length; 1918c2ecf20Sopenharmony_ci u32 buffer_id; 1928c2ecf20Sopenharmony_ci}; 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_cistruct mixart_flowinfo 1958c2ecf20Sopenharmony_ci{ 1968c2ecf20Sopenharmony_ci u32 bufferinfo_array_phy_address; 1978c2ecf20Sopenharmony_ci u32 reserved[11]; 1988c2ecf20Sopenharmony_ci u32 bufferinfo_count; 1998c2ecf20Sopenharmony_ci u32 capture; 2008c2ecf20Sopenharmony_ci}; 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci/* exported */ 2038c2ecf20Sopenharmony_ciint snd_mixart_create_pcm(struct snd_mixart * chip); 2048c2ecf20Sopenharmony_cistruct mixart_pipe *snd_mixart_add_ref_pipe(struct snd_mixart *chip, int pcm_number, int capture, int monitoring); 2058c2ecf20Sopenharmony_ciint snd_mixart_kill_ref_pipe(struct mixart_mgr *mgr, struct mixart_pipe *pipe, int monitoring); 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci#endif /* __SOUND_MIXART_H */ 208