xref: /linux/sound/pci/mixart/mixart.h (revision f2a852d3)
11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * Driver for Digigram miXart soundcards
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * main header file
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  * Copyright (c) 2003 by Digigram <alsa@digigram.com>
81da177e4SLinus Torvalds  */
91da177e4SLinus Torvalds 
101da177e4SLinus Torvalds #ifndef __SOUND_MIXART_H
111da177e4SLinus Torvalds #define __SOUND_MIXART_H
121da177e4SLinus Torvalds 
131da177e4SLinus Torvalds #include <linux/interrupt.h>
1462932df8SIngo Molnar #include <linux/mutex.h>
151da177e4SLinus Torvalds #include <sound/pcm.h>
161da177e4SLinus Torvalds 
171da177e4SLinus Torvalds #define MIXART_DRIVER_VERSION	0x000100	/* 0.1.0 */
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds /*
211da177e4SLinus Torvalds  */
221da177e4SLinus Torvalds 
2367b48b88STakashi Iwai struct mixart_uid {
241da177e4SLinus Torvalds 	u32 object_id;
251da177e4SLinus Torvalds 	u32 desc;
261da177e4SLinus Torvalds };
271da177e4SLinus Torvalds 
281da177e4SLinus Torvalds struct mem_area {
291da177e4SLinus Torvalds 	unsigned long phys;
301da177e4SLinus Torvalds 	void __iomem *virt;
311da177e4SLinus Torvalds 	struct resource *res;
321da177e4SLinus Torvalds };
331da177e4SLinus Torvalds 
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds struct mixart_route {
361da177e4SLinus Torvalds 	unsigned char connected;
371da177e4SLinus Torvalds 	unsigned char phase_inv;
381da177e4SLinus Torvalds 	int volume;
391da177e4SLinus Torvalds };
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds 
421da177e4SLinus Torvalds /* firmware status codes  */
431da177e4SLinus Torvalds #define MIXART_MOTHERBOARD_XLX_INDEX  0
441da177e4SLinus Torvalds #define MIXART_MOTHERBOARD_ELF_INDEX  1
451da177e4SLinus Torvalds #define MIXART_AESEBUBOARD_XLX_INDEX  2
461da177e4SLinus Torvalds #define MIXART_HARDW_FILES_MAX_INDEX  3  /* xilinx, elf, AESEBU xilinx */
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds #define MIXART_MAX_CARDS	4
491da177e4SLinus Torvalds #define MSG_FIFO_SIZE           16
501da177e4SLinus Torvalds 
511da177e4SLinus Torvalds #define MIXART_MAX_PHYS_CONNECTORS  (MIXART_MAX_CARDS * 2 * 2) /* 4 * stereo * (analog+digital) */
521da177e4SLinus Torvalds 
5367b48b88STakashi Iwai struct mixart_mgr {
541da177e4SLinus Torvalds 	unsigned int num_cards;
5567b48b88STakashi Iwai 	struct snd_mixart *chip[MIXART_MAX_CARDS];
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds 	struct pci_dev *pci;
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds 	int irq;
601da177e4SLinus Torvalds 
611da177e4SLinus Torvalds 	/* memory-maps */
621da177e4SLinus Torvalds 	struct mem_area mem[2];
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds 	/* one and only blocking message or notification may be pending  */
651da177e4SLinus Torvalds 	u32 pending_event;
661da177e4SLinus Torvalds 	wait_queue_head_t msg_sleep;
671da177e4SLinus Torvalds 
688d3a8b5cSTakashi Iwai 	/* messages fifo */
691da177e4SLinus Torvalds 	u32 msg_fifo[MSG_FIFO_SIZE];
701da177e4SLinus Torvalds 	int msg_fifo_readptr;
711da177e4SLinus Torvalds 	int msg_fifo_writeptr;
72*f2a852d3STakashi Iwai 	atomic_t msg_processed;       /* number of messages to be processed in irq thread */
731da177e4SLinus Torvalds 
748d3a8b5cSTakashi Iwai 	struct mutex lock;              /* interrupt lock */
758d3a8b5cSTakashi Iwai 	struct mutex msg_lock;		/* mailbox lock */
761da177e4SLinus Torvalds 
7762932df8SIngo Molnar 	struct mutex setup_mutex; /* mutex used in hw_params, open and close */
781da177e4SLinus Torvalds 
791da177e4SLinus Torvalds 	/* hardware interface */
801da177e4SLinus Torvalds 	unsigned int dsp_loaded;      /* bit flags of loaded dsp indices */
811da177e4SLinus Torvalds 	unsigned int board_type;      /* read from embedded once elf file is loaded, 250 = miXart8, 251 = with AES, 252 = with Cobranet */
821da177e4SLinus Torvalds 
831da177e4SLinus Torvalds 	struct snd_dma_buffer flowinfo;
841da177e4SLinus Torvalds 	struct snd_dma_buffer bufferinfo;
851da177e4SLinus Torvalds 
8667b48b88STakashi Iwai 	struct mixart_uid         uid_console_manager;
871da177e4SLinus Torvalds 	int sample_rate;
881da177e4SLinus Torvalds 	int ref_count_rate;
891da177e4SLinus Torvalds 
9062932df8SIngo Molnar 	struct mutex mixer_mutex; /* mutex for mixer */
911da177e4SLinus Torvalds 
921da177e4SLinus Torvalds };
931da177e4SLinus Torvalds 
941da177e4SLinus Torvalds 
951da177e4SLinus Torvalds #define MIXART_STREAM_STATUS_FREE	0
961da177e4SLinus Torvalds #define MIXART_STREAM_STATUS_OPEN	1
971da177e4SLinus Torvalds #define MIXART_STREAM_STATUS_RUNNING	2
981da177e4SLinus Torvalds #define MIXART_STREAM_STATUS_DRAINING	3
991da177e4SLinus Torvalds #define MIXART_STREAM_STATUS_PAUSE	4
1001da177e4SLinus Torvalds 
1011da177e4SLinus Torvalds #define MIXART_PLAYBACK_STREAMS		4
1021da177e4SLinus Torvalds #define MIXART_CAPTURE_STREAMS		1
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds #define MIXART_PCM_ANALOG		0
1051da177e4SLinus Torvalds #define MIXART_PCM_DIGITAL		1
1061da177e4SLinus Torvalds #define MIXART_PCM_TOTAL		2
1071da177e4SLinus Torvalds 
1081da177e4SLinus Torvalds #define MIXART_MAX_STREAM_PER_CARD  (MIXART_PCM_TOTAL * (MIXART_PLAYBACK_STREAMS + MIXART_CAPTURE_STREAMS) )
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds #define MIXART_NOTIFY_CARD_MASK		0xF000
1121da177e4SLinus Torvalds #define MIXART_NOTIFY_CARD_OFFSET	12
1131da177e4SLinus Torvalds #define MIXART_NOTIFY_PCM_MASK		0x0F00
1141da177e4SLinus Torvalds #define MIXART_NOTIFY_PCM_OFFSET	8
1151da177e4SLinus Torvalds #define MIXART_NOTIFY_CAPT_MASK		0x0080
1161da177e4SLinus Torvalds #define MIXART_NOTIFY_SUBS_MASK		0x007F
1171da177e4SLinus Torvalds 
1181da177e4SLinus Torvalds 
11967b48b88STakashi Iwai struct mixart_stream {
12067b48b88STakashi Iwai 	struct snd_pcm_substream *substream;
12167b48b88STakashi Iwai 	struct mixart_pipe *pipe;
1221da177e4SLinus Torvalds 	int pcm_number;
1231da177e4SLinus Torvalds 
1241da177e4SLinus Torvalds 	int status;      /* nothing, running, draining */
1251da177e4SLinus Torvalds 
1261da177e4SLinus Torvalds 	u64  abs_period_elapsed;  /* last absolute stream position where period_elapsed was called (multiple of runtime->period_size) */
1271da177e4SLinus Torvalds 	u32  buf_periods;         /* periods counter in the buffer (< runtime->periods) */
1281da177e4SLinus Torvalds 	u32  buf_period_frag;     /* defines with buf_period_pos the exact position in the buffer (< runtime->period_size) */
1291da177e4SLinus Torvalds 
1301da177e4SLinus Torvalds 	int channels;
1311da177e4SLinus Torvalds };
1321da177e4SLinus Torvalds 
1331da177e4SLinus Torvalds 
1341da177e4SLinus Torvalds enum mixart_pipe_status {
1351da177e4SLinus Torvalds 	PIPE_UNDEFINED,
1361da177e4SLinus Torvalds 	PIPE_STOPPED,
1371da177e4SLinus Torvalds 	PIPE_RUNNING,
1381da177e4SLinus Torvalds 	PIPE_CLOCK_SET
1391da177e4SLinus Torvalds };
1401da177e4SLinus Torvalds 
14167b48b88STakashi Iwai struct mixart_pipe {
14267b48b88STakashi Iwai 	struct mixart_uid group_uid;			/* id of the pipe, as returned by embedded */
1431da177e4SLinus Torvalds 	int          stream_count;
14467b48b88STakashi Iwai 	struct mixart_uid uid_left_connector;	/* UID's for the audio connectors */
14567b48b88STakashi Iwai 	struct mixart_uid uid_right_connector;
1461da177e4SLinus Torvalds 	enum mixart_pipe_status status;
1471da177e4SLinus Torvalds 	int references;             /* number of subs openned */
1481da177e4SLinus Torvalds 	int monitoring;             /* pipe used for monitoring issue */
1491da177e4SLinus Torvalds };
1501da177e4SLinus Torvalds 
1511da177e4SLinus Torvalds 
1521da177e4SLinus Torvalds struct snd_mixart {
15367b48b88STakashi Iwai 	struct snd_card *card;
15467b48b88STakashi Iwai 	struct mixart_mgr *mgr;
1551da177e4SLinus Torvalds 	int chip_idx;               /* zero based */
15667b48b88STakashi Iwai 	struct snd_hwdep *hwdep;	    /* DSP loader, only for the first card */
1571da177e4SLinus Torvalds 
15867b48b88STakashi Iwai 	struct snd_pcm *pcm;             /* PCM analog i/o */
15967b48b88STakashi Iwai 	struct snd_pcm *pcm_dig;         /* PCM digital i/o */
1601da177e4SLinus Torvalds 
1611da177e4SLinus Torvalds 	/* allocate stereo pipe for instance */
16267b48b88STakashi Iwai 	struct mixart_pipe pipe_in_ana;
16367b48b88STakashi Iwai 	struct mixart_pipe pipe_out_ana;
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds 	/* if AES/EBU daughter board is available, additional pipes possible on pcm_dig */
16667b48b88STakashi Iwai 	struct mixart_pipe pipe_in_dig;
16767b48b88STakashi Iwai 	struct mixart_pipe pipe_out_dig;
1681da177e4SLinus Torvalds 
16967b48b88STakashi Iwai 	struct mixart_stream playback_stream[MIXART_PCM_TOTAL][MIXART_PLAYBACK_STREAMS]; /* 0 = pcm, 1 = pcm_dig */
17067b48b88STakashi Iwai 	struct mixart_stream capture_stream[MIXART_PCM_TOTAL];                           /* 0 = pcm, 1 = pcm_dig */
1711da177e4SLinus Torvalds 
1721da177e4SLinus Torvalds 	/* UID's for the physical io's */
17367b48b88STakashi Iwai 	struct mixart_uid uid_out_analog_physio;
17467b48b88STakashi Iwai 	struct mixart_uid uid_in_analog_physio;
1751da177e4SLinus Torvalds 
1761da177e4SLinus Torvalds 	int analog_playback_active[2];		/* Mixer : Master Playback active (!mute) */
1771da177e4SLinus Torvalds 	int analog_playback_volume[2];		/* Mixer : Master Playback Volume */
1781da177e4SLinus Torvalds 	int analog_capture_volume[2];		/* Mixer : Master Capture Volume */
1791da177e4SLinus Torvalds 	int digital_playback_active[2*MIXART_PLAYBACK_STREAMS][2];	/* Mixer : Digital Playback Active [(analog+AES output)*streams][stereo]*/
1801da177e4SLinus Torvalds 	int digital_playback_volume[2*MIXART_PLAYBACK_STREAMS][2];	/* Mixer : Digital Playback Volume [(analog+AES output)*streams][stereo]*/
1811da177e4SLinus Torvalds 	int digital_capture_volume[2][2];	/* Mixer : Digital Capture Volume [analog+AES output][stereo] */
1821da177e4SLinus Torvalds 	int monitoring_active[2];		/* Mixer : Monitoring Active */
1831da177e4SLinus Torvalds 	int monitoring_volume[2];		/* Mixer : Monitoring Volume */
1841da177e4SLinus Torvalds };
1851da177e4SLinus Torvalds 
1861da177e4SLinus Torvalds struct mixart_bufferinfo
1871da177e4SLinus Torvalds {
1881da177e4SLinus Torvalds 	u32 buffer_address;
1891da177e4SLinus Torvalds 	u32 reserved[5];
1901da177e4SLinus Torvalds 	u32 available_length;
1911da177e4SLinus Torvalds 	u32 buffer_id;
1921da177e4SLinus Torvalds };
1931da177e4SLinus Torvalds 
1941da177e4SLinus Torvalds struct mixart_flowinfo
1951da177e4SLinus Torvalds {
1961da177e4SLinus Torvalds 	u32 bufferinfo_array_phy_address;
1971da177e4SLinus Torvalds 	u32 reserved[11];
1981da177e4SLinus Torvalds 	u32 bufferinfo_count;
1991da177e4SLinus Torvalds 	u32 capture;
2001da177e4SLinus Torvalds };
2011da177e4SLinus Torvalds 
2021da177e4SLinus Torvalds /* exported */
20367b48b88STakashi Iwai int snd_mixart_create_pcm(struct snd_mixart * chip);
20467b48b88STakashi Iwai struct mixart_pipe *snd_mixart_add_ref_pipe(struct snd_mixart *chip, int pcm_number, int capture, int monitoring);
20567b48b88STakashi Iwai int snd_mixart_kill_ref_pipe(struct mixart_mgr *mgr, struct mixart_pipe *pipe, int monitoring);
2061da177e4SLinus Torvalds 
2071da177e4SLinus Torvalds #endif /* __SOUND_MIXART_H */
208