xref: /openbmc/linux/sound/x86/intel_hdmi_audio.h (revision 82a60352)
15dab11d8SJerome Anand /*
25dab11d8SJerome Anand  * Copyright (C) 2016 Intel Corporation
35dab11d8SJerome Anand  *  Authors:	Sailaja Bandarupalli <sailaja.bandarupalli@intel.com>
45dab11d8SJerome Anand  *		Ramesh Babu K V	<ramesh.babu@intel.com>
55dab11d8SJerome Anand  *		Vaibhav Agarwal <vaibhav.agarwal@intel.com>
65dab11d8SJerome Anand  *		Jerome Anand <jerome.anand@intel.com>
75dab11d8SJerome Anand  *
85dab11d8SJerome Anand  * Permission is hereby granted, free of charge, to any person obtaining
95dab11d8SJerome Anand  * a copy of this software and associated documentation files
105dab11d8SJerome Anand  * (the "Software"), to deal in the Software without restriction,
115dab11d8SJerome Anand  * including without limitation the rights to use, copy, modify, merge,
125dab11d8SJerome Anand  * publish, distribute, sublicense, and/or sell copies of the Software,
135dab11d8SJerome Anand  * and to permit persons to whom the Software is furnished to do so,
145dab11d8SJerome Anand  * subject to the following conditions:
155dab11d8SJerome Anand  *
165dab11d8SJerome Anand  * The above copyright notice and this permission notice (including the
175dab11d8SJerome Anand  * next paragraph) shall be included in all copies or substantial
185dab11d8SJerome Anand  * portions of the Software.
195dab11d8SJerome Anand  *
205dab11d8SJerome Anand  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
215dab11d8SJerome Anand  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
225dab11d8SJerome Anand  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
235dab11d8SJerome Anand  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
245dab11d8SJerome Anand  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
255dab11d8SJerome Anand  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
265dab11d8SJerome Anand  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
275dab11d8SJerome Anand  * SOFTWARE.
285dab11d8SJerome Anand  */
295dab11d8SJerome Anand 
305dab11d8SJerome Anand #ifndef _INTEL_HDMI_AUDIO_H_
315dab11d8SJerome Anand #define _INTEL_HDMI_AUDIO_H_
325dab11d8SJerome Anand 
335dab11d8SJerome Anand #include "intel_hdmi_lpe_audio.h"
345dab11d8SJerome Anand 
355dab11d8SJerome Anand #define MAX_PB_STREAMS		1
365dab11d8SJerome Anand #define MAX_CAP_STREAMS		0
375dab11d8SJerome Anand #define BYTES_PER_WORD		0x4
3877531beeSTakashi Iwai #define INTEL_HAD		"HdmiLpeAudio"
395dab11d8SJerome Anand 
4077531beeSTakashi Iwai /*
4177531beeSTakashi Iwai  *	CEA speaker placement:
4277531beeSTakashi Iwai  *
4377531beeSTakashi Iwai  *	FL  FLC   FC   FRC   FR
4477531beeSTakashi Iwai  *
4577531beeSTakashi Iwai  *						LFE
4677531beeSTakashi Iwai  *
4777531beeSTakashi Iwai  *	RL  RLC   RC   RRC   RR
4877531beeSTakashi Iwai  *
4977531beeSTakashi Iwai  *	The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M
5077531beeSTakashi Iwai  *	corresponds to CEA RL/RR; The SMPTE channel _assignment_ C/LFE is
5177531beeSTakashi Iwai  *	swapped to CEA LFE/FC.
5277531beeSTakashi Iwai  */
5377531beeSTakashi Iwai enum cea_speaker_placement {
5477531beeSTakashi Iwai 	FL  = (1 <<  0),        /* Front Left           */
5577531beeSTakashi Iwai 	FC  = (1 <<  1),        /* Front Center         */
5677531beeSTakashi Iwai 	FR  = (1 <<  2),        /* Front Right          */
5777531beeSTakashi Iwai 	FLC = (1 <<  3),        /* Front Left Center    */
5877531beeSTakashi Iwai 	FRC = (1 <<  4),        /* Front Right Center   */
5977531beeSTakashi Iwai 	RL  = (1 <<  5),        /* Rear Left            */
6077531beeSTakashi Iwai 	RC  = (1 <<  6),        /* Rear Center          */
6177531beeSTakashi Iwai 	RR  = (1 <<  7),        /* Rear Right           */
6277531beeSTakashi Iwai 	RLC = (1 <<  8),        /* Rear Left Center     */
6377531beeSTakashi Iwai 	RRC = (1 <<  9),        /* Rear Right Center    */
6477531beeSTakashi Iwai 	LFE = (1 << 10),        /* Low Frequency Effect */
6577531beeSTakashi Iwai };
665dab11d8SJerome Anand 
6777531beeSTakashi Iwai struct cea_channel_speaker_allocation {
6877531beeSTakashi Iwai 	int ca_index;
6977531beeSTakashi Iwai 	int speakers[8];
7077531beeSTakashi Iwai 
7177531beeSTakashi Iwai 	/* derived values, just for convenience */
7277531beeSTakashi Iwai 	int channels;
7377531beeSTakashi Iwai 	int spk_mask;
7477531beeSTakashi Iwai };
7577531beeSTakashi Iwai 
7677531beeSTakashi Iwai struct channel_map_table {
7777531beeSTakashi Iwai 	unsigned char map;              /* ALSA API channel map position */
7877531beeSTakashi Iwai 	unsigned char cea_slot;         /* CEA slot value */
7977531beeSTakashi Iwai 	int spk_mask;                   /* speaker position bit mask */
8077531beeSTakashi Iwai };
815dab11d8SJerome Anand 
825dab11d8SJerome Anand struct pcm_stream_info {
83313d9f28STakashi Iwai 	struct snd_pcm_substream *substream;
84313d9f28STakashi Iwai 	int substream_refcount;
855dab11d8SJerome Anand };
865dab11d8SJerome Anand 
8703c34377STakashi Iwai /*
885dab11d8SJerome Anand  * struct snd_intelhad - intelhad driver structure
895dab11d8SJerome Anand  *
905dab11d8SJerome Anand  * @card: ptr to hold card details
9191b0cb0cSTakashi Iwai  * @connected: the monitor connection status
925dab11d8SJerome Anand  * @stream_info: stream information
93da864809STakashi Iwai  * @eld: holds ELD info
945dab11d8SJerome Anand  * @curr_buf: pointer to hold current active ring buf
955dab11d8SJerome Anand  * @valid_buf_cnt: ring buffer count for stream
965dab11d8SJerome Anand  * @had_spinlock: driver lock
975dab11d8SJerome Anand  * @aes_bits: IEC958 status bits
985dab11d8SJerome Anand  * @buff_done: id of current buffer done intr
99*1d7a0395Sgushengxian  * @dev: platform device handle
1005dab11d8SJerome Anand  * @chmap: holds channel map info
1015dab11d8SJerome Anand  */
1025dab11d8SJerome Anand struct snd_intelhad {
103b4eb0d52SVille Syrjälä 	struct snd_intelhad_card *card_ctx;
10491b0cb0cSTakashi Iwai 	bool		connected;
1055dab11d8SJerome Anand 	struct		pcm_stream_info stream_info;
106df0435dbSTakashi Iwai 	unsigned char	eld[HDMI_MAX_ELD_BYTES];
107964ca808SPierre-Louis Bossart 	bool dp_output;
1085dab11d8SJerome Anand 	unsigned int	aes_bits;
1095dab11d8SJerome Anand 	spinlock_t had_spinlock;
1105dab11d8SJerome Anand 	struct device *dev;
1115dab11d8SJerome Anand 	struct snd_pcm_chmap *chmap;
112da864809STakashi Iwai 	int tmds_clock_speed;
113da864809STakashi Iwai 	int link_rate;
1148a2d6ae1SVille Syrjälä 	int port; /* fixed */
1158a2d6ae1SVille Syrjälä 	int pipe; /* can change dynamically */
116da864809STakashi Iwai 
117e1b239f3STakashi Iwai 	/* ring buffer (BD) position index */
118e1b239f3STakashi Iwai 	unsigned int bd_head;
119e1b239f3STakashi Iwai 	/* PCM buffer position indices */
120e1b239f3STakashi Iwai 	unsigned int pcmbuf_head;	/* being processed */
121e1b239f3STakashi Iwai 	unsigned int pcmbuf_filled;	/* to be filled */
122e1b239f3STakashi Iwai 
123e1b239f3STakashi Iwai 	unsigned int num_bds;		/* number of BDs */
124e1b239f3STakashi Iwai 	unsigned int period_bytes;	/* PCM period size in bytes */
125e1b239f3STakashi Iwai 
126da864809STakashi Iwai 	/* internal stuff */
12740ce4b5dSTakashi Iwai 	union aud_cfg aud_config;	/* AUD_CONFIG reg value cache */
128da864809STakashi Iwai 	struct work_struct hdmi_audio_wq;
1290e9c67d7STakashi Iwai 	struct mutex mutex; /* for protecting chmap and eld */
130b9bacf27STakashi Iwai 	struct snd_jack *jack;
1315dab11d8SJerome Anand };
1325dab11d8SJerome Anand 
133b4eb0d52SVille Syrjälä struct snd_intelhad_card {
134b4eb0d52SVille Syrjälä 	struct snd_card	*card;
135b4eb0d52SVille Syrjälä 	struct device *dev;
136b4eb0d52SVille Syrjälä 
137b4eb0d52SVille Syrjälä 	/* internal stuff */
138b4eb0d52SVille Syrjälä 	int irq;
139b4eb0d52SVille Syrjälä 	void __iomem *mmio_start;
1408a2d6ae1SVille Syrjälä 	int num_pipes;
141b4eb0d52SVille Syrjälä 	int num_ports;
1428a2d6ae1SVille Syrjälä 	struct snd_intelhad pcm_ctx[3]; /* one for each port */
143b4eb0d52SVille Syrjälä };
144b4eb0d52SVille Syrjälä 
1455dab11d8SJerome Anand #endif /* _INTEL_HDMI_AUDIO_ */
146