162306a36Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license.  When using or
462306a36Sopenharmony_ci * redistributing this file, you may do so under either license.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright(c) 2018 Intel Corporation. All rights reserved.
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef __INCLUDE_SOUND_SOF_DAI_INTEL_H__
1062306a36Sopenharmony_ci#define __INCLUDE_SOUND_SOF_DAI_INTEL_H__
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <sound/sof/header.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci /* ssc1: TINTE */
1562306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_QUIRK_TINTE		(1 << 0)
1662306a36Sopenharmony_ci /* ssc1: PINTE */
1762306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_QUIRK_PINTE		(1 << 1)
1862306a36Sopenharmony_ci /* ssc2: SMTATF */
1962306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_QUIRK_SMTATF		(1 << 2)
2062306a36Sopenharmony_ci /* ssc2: MMRATF */
2162306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_QUIRK_MMRATF		(1 << 3)
2262306a36Sopenharmony_ci /* ssc2: PSPSTWFDFD */
2362306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_QUIRK_PSPSTWFDFD	(1 << 4)
2462306a36Sopenharmony_ci /* ssc2: PSPSRWFDFD */
2562306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_QUIRK_PSPSRWFDFD	(1 << 5)
2662306a36Sopenharmony_ci/* ssc1: LBM */
2762306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_QUIRK_LBM		(1 << 6)
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci /* here is the possibility to define others aux macros */
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_FRAME_PULSE_WIDTH_MAX		38
3262306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_SLOT_PADDING_MAX		31
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/* SSP clocks control settings
3562306a36Sopenharmony_ci *
3662306a36Sopenharmony_ci * Macros for clks_control field in sof_ipc_dai_ssp_params struct.
3762306a36Sopenharmony_ci */
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci/* mclk 0 disable */
4062306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_MCLK_0_DISABLE		BIT(0)
4162306a36Sopenharmony_ci/* mclk 1 disable */
4262306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_MCLK_1_DISABLE		BIT(1)
4362306a36Sopenharmony_ci/* mclk keep active */
4462306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_CLKCTRL_MCLK_KA		BIT(2)
4562306a36Sopenharmony_ci/* bclk keep active */
4662306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_CLKCTRL_BCLK_KA		BIT(3)
4762306a36Sopenharmony_ci/* fs keep active */
4862306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_CLKCTRL_FS_KA			BIT(4)
4962306a36Sopenharmony_ci/* bclk idle */
5062306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_CLKCTRL_BCLK_IDLE_HIGH	BIT(5)
5162306a36Sopenharmony_ci/* mclk early start */
5262306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_CLKCTRL_MCLK_ES               BIT(6)
5362306a36Sopenharmony_ci/* bclk early start */
5462306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_CLKCTRL_BCLK_ES               BIT(7)
5562306a36Sopenharmony_ci/* mclk always on */
5662306a36Sopenharmony_ci#define SOF_DAI_INTEL_SSP_CLKCTRL_MCLK_AON		BIT(8)
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci/* DMIC max. four controllers for eight microphone channels */
5962306a36Sopenharmony_ci#define SOF_DAI_INTEL_DMIC_NUM_CTRL			4
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci/* SSP Configuration Request - SOF_IPC_DAI_SSP_CONFIG */
6262306a36Sopenharmony_cistruct sof_ipc_dai_ssp_params {
6362306a36Sopenharmony_ci	struct sof_ipc_hdr hdr;
6462306a36Sopenharmony_ci	uint16_t reserved1;
6562306a36Sopenharmony_ci	uint16_t mclk_id;
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci	uint32_t mclk_rate;	/* mclk frequency in Hz */
6862306a36Sopenharmony_ci	uint32_t fsync_rate;	/* fsync frequency in Hz */
6962306a36Sopenharmony_ci	uint32_t bclk_rate;	/* bclk frequency in Hz */
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci	/* TDM */
7262306a36Sopenharmony_ci	uint32_t tdm_slots;
7362306a36Sopenharmony_ci	uint32_t rx_slots;
7462306a36Sopenharmony_ci	uint32_t tx_slots;
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci	/* data */
7762306a36Sopenharmony_ci	uint32_t sample_valid_bits;
7862306a36Sopenharmony_ci	uint16_t tdm_slot_width;
7962306a36Sopenharmony_ci	uint16_t reserved2;	/* alignment */
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci	/* MCLK */
8262306a36Sopenharmony_ci	uint32_t mclk_direction;
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci	uint16_t frame_pulse_width;
8562306a36Sopenharmony_ci	uint16_t tdm_per_slot_padding_flag;
8662306a36Sopenharmony_ci	uint32_t clks_control;
8762306a36Sopenharmony_ci	uint32_t quirks;
8862306a36Sopenharmony_ci	uint32_t bclk_delay;	/* guaranteed time (ms) for which BCLK
8962306a36Sopenharmony_ci				 * will be driven, before sending data
9062306a36Sopenharmony_ci				 */
9162306a36Sopenharmony_ci} __packed;
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci/* HDA Configuration Request - SOF_IPC_DAI_HDA_CONFIG */
9462306a36Sopenharmony_cistruct sof_ipc_dai_hda_params {
9562306a36Sopenharmony_ci	struct sof_ipc_hdr hdr;
9662306a36Sopenharmony_ci	uint32_t link_dma_ch;
9762306a36Sopenharmony_ci	uint32_t rate;
9862306a36Sopenharmony_ci	uint32_t channels;
9962306a36Sopenharmony_ci} __packed;
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci/* ALH Configuration Request - SOF_IPC_DAI_ALH_CONFIG */
10262306a36Sopenharmony_cistruct sof_ipc_dai_alh_params {
10362306a36Sopenharmony_ci	struct sof_ipc_hdr hdr;
10462306a36Sopenharmony_ci	uint32_t stream_id;
10562306a36Sopenharmony_ci	uint32_t rate;
10662306a36Sopenharmony_ci	uint32_t channels;
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci	/* reserved for future use */
10962306a36Sopenharmony_ci	uint32_t reserved[13];
11062306a36Sopenharmony_ci} __packed;
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci/* DMIC Configuration Request - SOF_IPC_DAI_DMIC_CONFIG */
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci/* This struct is defined per 2ch PDM controller available in the platform.
11562306a36Sopenharmony_ci * Normally it is sufficient to set the used microphone specific enables to 1
11662306a36Sopenharmony_ci * and keep other parameters as zero. The customizations are:
11762306a36Sopenharmony_ci *
11862306a36Sopenharmony_ci * 1. If a device mixes different microphones types with different polarity
11962306a36Sopenharmony_ci * and/or the absolute polarity matters the PCM signal from a microphone
12062306a36Sopenharmony_ci * can be inverted with the controls.
12162306a36Sopenharmony_ci *
12262306a36Sopenharmony_ci * 2. If the microphones in a stereo pair do not appear in captured stream
12362306a36Sopenharmony_ci * in desired order due to board schematics choises they can be swapped with
12462306a36Sopenharmony_ci * the clk_edge parameter.
12562306a36Sopenharmony_ci *
12662306a36Sopenharmony_ci * 3. If PDM bit errors are seen in capture (poor quality) the skew parameter
12762306a36Sopenharmony_ci * that delays the sampling time of data by half cycles of DMIC source clock
12862306a36Sopenharmony_ci * can be tried for improvement. However there is no guarantee for this to fix
12962306a36Sopenharmony_ci * data integrity problems.
13062306a36Sopenharmony_ci */
13162306a36Sopenharmony_cistruct sof_ipc_dai_dmic_pdm_ctrl {
13262306a36Sopenharmony_ci	struct sof_ipc_hdr hdr;
13362306a36Sopenharmony_ci	uint16_t id;		/**< PDM controller ID */
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci	uint16_t enable_mic_a;	/**< Use A (left) channel mic (0 or 1)*/
13662306a36Sopenharmony_ci	uint16_t enable_mic_b;	/**< Use B (right) channel mic (0 or 1)*/
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci	uint16_t polarity_mic_a; /**< Optionally invert mic A signal (0 or 1) */
13962306a36Sopenharmony_ci	uint16_t polarity_mic_b; /**< Optionally invert mic B signal (0 or 1) */
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci	uint16_t clk_edge;	/**< Optionally swap data clock edge (0 or 1) */
14262306a36Sopenharmony_ci	uint16_t skew;		/**< Adjust PDM data sampling vs. clock (0..15) */
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci	uint16_t reserved[3];	/**< Make sure the total size is 4 bytes aligned */
14562306a36Sopenharmony_ci} __packed;
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ci/* This struct contains the global settings for all 2ch PDM controllers. The
14862306a36Sopenharmony_ci * version number used in configuration data is checked vs. version used by
14962306a36Sopenharmony_ci * device driver src/drivers/dmic.c need to match. It is incremented from
15062306a36Sopenharmony_ci * initial value 1 if updates done for the to driver would alter the operation
15162306a36Sopenharmony_ci * of the microphone.
15262306a36Sopenharmony_ci *
15362306a36Sopenharmony_ci * Note: The microphone clock (pdmclk_min, pdmclk_max, duty_min, duty_max)
15462306a36Sopenharmony_ci * parameters need to be set as defined in microphone data sheet. E.g. clock
15562306a36Sopenharmony_ci * range 1.0 - 3.2 MHz is usually supported microphones. Some microphones are
15662306a36Sopenharmony_ci * multi-mode capable and there may be denied mic clock frequencies between
15762306a36Sopenharmony_ci * the modes. In such case set the clock range limits of the desired mode to
15862306a36Sopenharmony_ci * avoid the driver to set clock to an illegal rate.
15962306a36Sopenharmony_ci *
16062306a36Sopenharmony_ci * The duty cycle could be set to 48-52% if not known. Generally these
16162306a36Sopenharmony_ci * parameters can be altered within data sheet specified limits to match
16262306a36Sopenharmony_ci * required audio application performance power.
16362306a36Sopenharmony_ci *
16462306a36Sopenharmony_ci * The microphone clock needs to be usually about 50-80 times the used audio
16562306a36Sopenharmony_ci * sample rate. With highest sample rates above 48 kHz this can relaxed
16662306a36Sopenharmony_ci * somewhat.
16762306a36Sopenharmony_ci *
16862306a36Sopenharmony_ci * The parameter wake_up_time describes how long time the microphone needs
16962306a36Sopenharmony_ci * for the data line to produce valid output from mic clock start. The driver
17062306a36Sopenharmony_ci * will mute the captured audio for the given time. The min_clock_on_time
17162306a36Sopenharmony_ci * parameter is used to prevent too short clock bursts to happen. The driver
17262306a36Sopenharmony_ci * will keep the clock active after capture stop if this time is not yet
17362306a36Sopenharmony_ci * met. The unit for both is microseconds (us). Exceed of 100 ms will be
17462306a36Sopenharmony_ci * treated as an error.
17562306a36Sopenharmony_ci */
17662306a36Sopenharmony_cistruct sof_ipc_dai_dmic_params {
17762306a36Sopenharmony_ci	struct sof_ipc_hdr hdr;
17862306a36Sopenharmony_ci	uint32_t driver_ipc_version;	/**< Version (1..N) */
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ci	uint32_t pdmclk_min;	/**< Minimum microphone clock in Hz (100000..N) */
18162306a36Sopenharmony_ci	uint32_t pdmclk_max;	/**< Maximum microphone clock in Hz (min...N) */
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ci	uint32_t fifo_fs;	/**< FIFO sample rate in Hz (8000..96000) */
18462306a36Sopenharmony_ci	uint32_t reserved_1;	/**< Reserved */
18562306a36Sopenharmony_ci	uint16_t fifo_bits;	/**< FIFO word length (16 or 32) */
18662306a36Sopenharmony_ci	uint16_t fifo_bits_b;	/**< Deprecated since firmware ABI 3.0.1 */
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci	uint16_t duty_min;	/**< Min. mic clock duty cycle in % (20..80) */
18962306a36Sopenharmony_ci	uint16_t duty_max;	/**< Max. mic clock duty cycle in % (min..80) */
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ci	uint32_t num_pdm_active; /**< Number of active pdm controllers. */
19262306a36Sopenharmony_ci				 /**< Range is 1..SOF_DAI_INTEL_DMIC_NUM_CTRL */
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci	uint32_t wake_up_time;      /**< Time from clock start to data (us) */
19562306a36Sopenharmony_ci	uint32_t min_clock_on_time; /**< Min. time that clk is kept on (us) */
19662306a36Sopenharmony_ci	uint32_t unmute_ramp_time;  /**< Length of logarithmic gain ramp (ms) */
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ci	/* reserved for future use */
19962306a36Sopenharmony_ci	uint32_t reserved[5];
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci	/**< PDM controllers configuration */
20262306a36Sopenharmony_ci	struct sof_ipc_dai_dmic_pdm_ctrl pdm[SOF_DAI_INTEL_DMIC_NUM_CTRL];
20362306a36Sopenharmony_ci} __packed;
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci#endif
206