xref: /OK3568_Linux_fs/kernel/include/sound/sof/dai-intel.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * This file is provided under a dual BSD/GPLv2 license.  When using or
4*4882a593Smuzhiyun  * redistributing this file, you may do so under either license.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright(c) 2018 Intel Corporation. All rights reserved.
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef __INCLUDE_SOUND_SOF_DAI_INTEL_H__
10*4882a593Smuzhiyun #define __INCLUDE_SOUND_SOF_DAI_INTEL_H__
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <sound/sof/header.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun  /* ssc1: TINTE */
15*4882a593Smuzhiyun #define SOF_DAI_INTEL_SSP_QUIRK_TINTE		(1 << 0)
16*4882a593Smuzhiyun  /* ssc1: PINTE */
17*4882a593Smuzhiyun #define SOF_DAI_INTEL_SSP_QUIRK_PINTE		(1 << 1)
18*4882a593Smuzhiyun  /* ssc2: SMTATF */
19*4882a593Smuzhiyun #define SOF_DAI_INTEL_SSP_QUIRK_SMTATF		(1 << 2)
20*4882a593Smuzhiyun  /* ssc2: MMRATF */
21*4882a593Smuzhiyun #define SOF_DAI_INTEL_SSP_QUIRK_MMRATF		(1 << 3)
22*4882a593Smuzhiyun  /* ssc2: PSPSTWFDFD */
23*4882a593Smuzhiyun #define SOF_DAI_INTEL_SSP_QUIRK_PSPSTWFDFD	(1 << 4)
24*4882a593Smuzhiyun  /* ssc2: PSPSRWFDFD */
25*4882a593Smuzhiyun #define SOF_DAI_INTEL_SSP_QUIRK_PSPSRWFDFD	(1 << 5)
26*4882a593Smuzhiyun /* ssc1: LBM */
27*4882a593Smuzhiyun #define SOF_DAI_INTEL_SSP_QUIRK_LBM		(1 << 6)
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun  /* here is the possibility to define others aux macros */
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #define SOF_DAI_INTEL_SSP_FRAME_PULSE_WIDTH_MAX		38
32*4882a593Smuzhiyun #define SOF_DAI_INTEL_SSP_SLOT_PADDING_MAX		31
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /* SSP clocks control settings
35*4882a593Smuzhiyun  *
36*4882a593Smuzhiyun  * Macros for clks_control field in sof_ipc_dai_ssp_params struct.
37*4882a593Smuzhiyun  */
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /* mclk 0 disable */
40*4882a593Smuzhiyun #define SOF_DAI_INTEL_SSP_MCLK_0_DISABLE		BIT(0)
41*4882a593Smuzhiyun /* mclk 1 disable */
42*4882a593Smuzhiyun #define SOF_DAI_INTEL_SSP_MCLK_1_DISABLE		BIT(1)
43*4882a593Smuzhiyun /* mclk keep active */
44*4882a593Smuzhiyun #define SOF_DAI_INTEL_SSP_CLKCTRL_MCLK_KA		BIT(2)
45*4882a593Smuzhiyun /* bclk keep active */
46*4882a593Smuzhiyun #define SOF_DAI_INTEL_SSP_CLKCTRL_BCLK_KA		BIT(3)
47*4882a593Smuzhiyun /* fs keep active */
48*4882a593Smuzhiyun #define SOF_DAI_INTEL_SSP_CLKCTRL_FS_KA			BIT(4)
49*4882a593Smuzhiyun /* bclk idle */
50*4882a593Smuzhiyun #define SOF_DAI_INTEL_SSP_CLKCTRL_BCLK_IDLE_HIGH	BIT(5)
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun /* DMIC max. four controllers for eight microphone channels */
53*4882a593Smuzhiyun #define SOF_DAI_INTEL_DMIC_NUM_CTRL			4
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun /* SSP Configuration Request - SOF_IPC_DAI_SSP_CONFIG */
56*4882a593Smuzhiyun struct sof_ipc_dai_ssp_params {
57*4882a593Smuzhiyun 	struct sof_ipc_hdr hdr;
58*4882a593Smuzhiyun 	uint16_t reserved1;
59*4882a593Smuzhiyun 	uint16_t mclk_id;
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 	uint32_t mclk_rate;	/* mclk frequency in Hz */
62*4882a593Smuzhiyun 	uint32_t fsync_rate;	/* fsync frequency in Hz */
63*4882a593Smuzhiyun 	uint32_t bclk_rate;	/* bclk frequency in Hz */
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun 	/* TDM */
66*4882a593Smuzhiyun 	uint32_t tdm_slots;
67*4882a593Smuzhiyun 	uint32_t rx_slots;
68*4882a593Smuzhiyun 	uint32_t tx_slots;
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun 	/* data */
71*4882a593Smuzhiyun 	uint32_t sample_valid_bits;
72*4882a593Smuzhiyun 	uint16_t tdm_slot_width;
73*4882a593Smuzhiyun 	uint16_t reserved2;	/* alignment */
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun 	/* MCLK */
76*4882a593Smuzhiyun 	uint32_t mclk_direction;
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun 	uint16_t frame_pulse_width;
79*4882a593Smuzhiyun 	uint16_t tdm_per_slot_padding_flag;
80*4882a593Smuzhiyun 	uint32_t clks_control;
81*4882a593Smuzhiyun 	uint32_t quirks;
82*4882a593Smuzhiyun 	uint32_t bclk_delay;	/* guaranteed time (ms) for which BCLK
83*4882a593Smuzhiyun 				 * will be driven, before sending data
84*4882a593Smuzhiyun 				 */
85*4882a593Smuzhiyun } __packed;
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun /* HDA Configuration Request - SOF_IPC_DAI_HDA_CONFIG */
88*4882a593Smuzhiyun struct sof_ipc_dai_hda_params {
89*4882a593Smuzhiyun 	struct sof_ipc_hdr hdr;
90*4882a593Smuzhiyun 	uint32_t link_dma_ch;
91*4882a593Smuzhiyun 	uint32_t rate;
92*4882a593Smuzhiyun 	uint32_t channels;
93*4882a593Smuzhiyun } __packed;
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun /* ALH Configuration Request - SOF_IPC_DAI_ALH_CONFIG */
96*4882a593Smuzhiyun struct sof_ipc_dai_alh_params {
97*4882a593Smuzhiyun 	struct sof_ipc_hdr hdr;
98*4882a593Smuzhiyun 	uint32_t stream_id;
99*4882a593Smuzhiyun 	uint32_t rate;
100*4882a593Smuzhiyun 	uint32_t channels;
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun 	/* reserved for future use */
103*4882a593Smuzhiyun 	uint32_t reserved[13];
104*4882a593Smuzhiyun } __packed;
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun /* DMIC Configuration Request - SOF_IPC_DAI_DMIC_CONFIG */
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun /* This struct is defined per 2ch PDM controller available in the platform.
109*4882a593Smuzhiyun  * Normally it is sufficient to set the used microphone specific enables to 1
110*4882a593Smuzhiyun  * and keep other parameters as zero. The customizations are:
111*4882a593Smuzhiyun  *
112*4882a593Smuzhiyun  * 1. If a device mixes different microphones types with different polarity
113*4882a593Smuzhiyun  * and/or the absolute polarity matters the PCM signal from a microphone
114*4882a593Smuzhiyun  * can be inverted with the controls.
115*4882a593Smuzhiyun  *
116*4882a593Smuzhiyun  * 2. If the microphones in a stereo pair do not appear in captured stream
117*4882a593Smuzhiyun  * in desired order due to board schematics choises they can be swapped with
118*4882a593Smuzhiyun  * the clk_edge parameter.
119*4882a593Smuzhiyun  *
120*4882a593Smuzhiyun  * 3. If PDM bit errors are seen in capture (poor quality) the skew parameter
121*4882a593Smuzhiyun  * that delays the sampling time of data by half cycles of DMIC source clock
122*4882a593Smuzhiyun  * can be tried for improvement. However there is no guarantee for this to fix
123*4882a593Smuzhiyun  * data integrity problems.
124*4882a593Smuzhiyun  */
125*4882a593Smuzhiyun struct sof_ipc_dai_dmic_pdm_ctrl {
126*4882a593Smuzhiyun 	struct sof_ipc_hdr hdr;
127*4882a593Smuzhiyun 	uint16_t id;		/**< PDM controller ID */
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun 	uint16_t enable_mic_a;	/**< Use A (left) channel mic (0 or 1)*/
130*4882a593Smuzhiyun 	uint16_t enable_mic_b;	/**< Use B (right) channel mic (0 or 1)*/
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun 	uint16_t polarity_mic_a; /**< Optionally invert mic A signal (0 or 1) */
133*4882a593Smuzhiyun 	uint16_t polarity_mic_b; /**< Optionally invert mic B signal (0 or 1) */
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun 	uint16_t clk_edge;	/**< Optionally swap data clock edge (0 or 1) */
136*4882a593Smuzhiyun 	uint16_t skew;		/**< Adjust PDM data sampling vs. clock (0..15) */
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun 	uint16_t reserved[3];	/**< Make sure the total size is 4 bytes aligned */
139*4882a593Smuzhiyun } __packed;
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun /* This struct contains the global settings for all 2ch PDM controllers. The
142*4882a593Smuzhiyun  * version number used in configuration data is checked vs. version used by
143*4882a593Smuzhiyun  * device driver src/drivers/dmic.c need to match. It is incremented from
144*4882a593Smuzhiyun  * initial value 1 if updates done for the to driver would alter the operation
145*4882a593Smuzhiyun  * of the microphone.
146*4882a593Smuzhiyun  *
147*4882a593Smuzhiyun  * Note: The microphone clock (pdmclk_min, pdmclk_max, duty_min, duty_max)
148*4882a593Smuzhiyun  * parameters need to be set as defined in microphone data sheet. E.g. clock
149*4882a593Smuzhiyun  * range 1.0 - 3.2 MHz is usually supported microphones. Some microphones are
150*4882a593Smuzhiyun  * multi-mode capable and there may be denied mic clock frequencies between
151*4882a593Smuzhiyun  * the modes. In such case set the clock range limits of the desired mode to
152*4882a593Smuzhiyun  * avoid the driver to set clock to an illegal rate.
153*4882a593Smuzhiyun  *
154*4882a593Smuzhiyun  * The duty cycle could be set to 48-52% if not known. Generally these
155*4882a593Smuzhiyun  * parameters can be altered within data sheet specified limits to match
156*4882a593Smuzhiyun  * required audio application performance power.
157*4882a593Smuzhiyun  *
158*4882a593Smuzhiyun  * The microphone clock needs to be usually about 50-80 times the used audio
159*4882a593Smuzhiyun  * sample rate. With highest sample rates above 48 kHz this can relaxed
160*4882a593Smuzhiyun  * somewhat.
161*4882a593Smuzhiyun  *
162*4882a593Smuzhiyun  * The parameter wake_up_time describes how long time the microphone needs
163*4882a593Smuzhiyun  * for the data line to produce valid output from mic clock start. The driver
164*4882a593Smuzhiyun  * will mute the captured audio for the given time. The min_clock_on_time
165*4882a593Smuzhiyun  * parameter is used to prevent too short clock bursts to happen. The driver
166*4882a593Smuzhiyun  * will keep the clock active after capture stop if this time is not yet
167*4882a593Smuzhiyun  * met. The unit for both is microseconds (us). Exceed of 100 ms will be
168*4882a593Smuzhiyun  * treated as an error.
169*4882a593Smuzhiyun  */
170*4882a593Smuzhiyun struct sof_ipc_dai_dmic_params {
171*4882a593Smuzhiyun 	struct sof_ipc_hdr hdr;
172*4882a593Smuzhiyun 	uint32_t driver_ipc_version;	/**< Version (1..N) */
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun 	uint32_t pdmclk_min;	/**< Minimum microphone clock in Hz (100000..N) */
175*4882a593Smuzhiyun 	uint32_t pdmclk_max;	/**< Maximum microphone clock in Hz (min...N) */
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun 	uint32_t fifo_fs;	/**< FIFO sample rate in Hz (8000..96000) */
178*4882a593Smuzhiyun 	uint32_t reserved_1;	/**< Reserved */
179*4882a593Smuzhiyun 	uint16_t fifo_bits;	/**< FIFO word length (16 or 32) */
180*4882a593Smuzhiyun 	uint16_t fifo_bits_b;	/**< Deprecated since firmware ABI 3.0.1 */
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun 	uint16_t duty_min;	/**< Min. mic clock duty cycle in % (20..80) */
183*4882a593Smuzhiyun 	uint16_t duty_max;	/**< Max. mic clock duty cycle in % (min..80) */
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun 	uint32_t num_pdm_active; /**< Number of active pdm controllers. */
186*4882a593Smuzhiyun 				 /**< Range is 1..SOF_DAI_INTEL_DMIC_NUM_CTRL */
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun 	uint32_t wake_up_time;      /**< Time from clock start to data (us) */
189*4882a593Smuzhiyun 	uint32_t min_clock_on_time; /**< Min. time that clk is kept on (us) */
190*4882a593Smuzhiyun 	uint32_t unmute_ramp_time;  /**< Length of logarithmic gain ramp (ms) */
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun 	/* reserved for future use */
193*4882a593Smuzhiyun 	uint32_t reserved[5];
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun 	/**< PDM controllers configuration */
196*4882a593Smuzhiyun 	struct sof_ipc_dai_dmic_pdm_ctrl pdm[SOF_DAI_INTEL_DMIC_NUM_CTRL];
197*4882a593Smuzhiyun } __packed;
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun #endif
200