18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license.  When using or
48c2ecf20Sopenharmony_ci * redistributing this file, you may do so under either license.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright(c) 2018 Intel Corporation. All rights reserved.
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef __INCLUDE_SOUND_SOF_DAI_INTEL_H__
108c2ecf20Sopenharmony_ci#define __INCLUDE_SOUND_SOF_DAI_INTEL_H__
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <sound/sof/header.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci /* ssc1: TINTE */
158c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_SSP_QUIRK_TINTE		(1 << 0)
168c2ecf20Sopenharmony_ci /* ssc1: PINTE */
178c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_SSP_QUIRK_PINTE		(1 << 1)
188c2ecf20Sopenharmony_ci /* ssc2: SMTATF */
198c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_SSP_QUIRK_SMTATF		(1 << 2)
208c2ecf20Sopenharmony_ci /* ssc2: MMRATF */
218c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_SSP_QUIRK_MMRATF		(1 << 3)
228c2ecf20Sopenharmony_ci /* ssc2: PSPSTWFDFD */
238c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_SSP_QUIRK_PSPSTWFDFD	(1 << 4)
248c2ecf20Sopenharmony_ci /* ssc2: PSPSRWFDFD */
258c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_SSP_QUIRK_PSPSRWFDFD	(1 << 5)
268c2ecf20Sopenharmony_ci/* ssc1: LBM */
278c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_SSP_QUIRK_LBM		(1 << 6)
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci /* here is the possibility to define others aux macros */
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_SSP_FRAME_PULSE_WIDTH_MAX		38
328c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_SSP_SLOT_PADDING_MAX		31
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* SSP clocks control settings
358c2ecf20Sopenharmony_ci *
368c2ecf20Sopenharmony_ci * Macros for clks_control field in sof_ipc_dai_ssp_params struct.
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* mclk 0 disable */
408c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_SSP_MCLK_0_DISABLE		BIT(0)
418c2ecf20Sopenharmony_ci/* mclk 1 disable */
428c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_SSP_MCLK_1_DISABLE		BIT(1)
438c2ecf20Sopenharmony_ci/* mclk keep active */
448c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_SSP_CLKCTRL_MCLK_KA		BIT(2)
458c2ecf20Sopenharmony_ci/* bclk keep active */
468c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_SSP_CLKCTRL_BCLK_KA		BIT(3)
478c2ecf20Sopenharmony_ci/* fs keep active */
488c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_SSP_CLKCTRL_FS_KA			BIT(4)
498c2ecf20Sopenharmony_ci/* bclk idle */
508c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_SSP_CLKCTRL_BCLK_IDLE_HIGH	BIT(5)
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/* DMIC max. four controllers for eight microphone channels */
538c2ecf20Sopenharmony_ci#define SOF_DAI_INTEL_DMIC_NUM_CTRL			4
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/* SSP Configuration Request - SOF_IPC_DAI_SSP_CONFIG */
568c2ecf20Sopenharmony_cistruct sof_ipc_dai_ssp_params {
578c2ecf20Sopenharmony_ci	struct sof_ipc_hdr hdr;
588c2ecf20Sopenharmony_ci	uint16_t reserved1;
598c2ecf20Sopenharmony_ci	uint16_t mclk_id;
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	uint32_t mclk_rate;	/* mclk frequency in Hz */
628c2ecf20Sopenharmony_ci	uint32_t fsync_rate;	/* fsync frequency in Hz */
638c2ecf20Sopenharmony_ci	uint32_t bclk_rate;	/* bclk frequency in Hz */
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	/* TDM */
668c2ecf20Sopenharmony_ci	uint32_t tdm_slots;
678c2ecf20Sopenharmony_ci	uint32_t rx_slots;
688c2ecf20Sopenharmony_ci	uint32_t tx_slots;
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	/* data */
718c2ecf20Sopenharmony_ci	uint32_t sample_valid_bits;
728c2ecf20Sopenharmony_ci	uint16_t tdm_slot_width;
738c2ecf20Sopenharmony_ci	uint16_t reserved2;	/* alignment */
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	/* MCLK */
768c2ecf20Sopenharmony_ci	uint32_t mclk_direction;
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	uint16_t frame_pulse_width;
798c2ecf20Sopenharmony_ci	uint16_t tdm_per_slot_padding_flag;
808c2ecf20Sopenharmony_ci	uint32_t clks_control;
818c2ecf20Sopenharmony_ci	uint32_t quirks;
828c2ecf20Sopenharmony_ci	uint32_t bclk_delay;	/* guaranteed time (ms) for which BCLK
838c2ecf20Sopenharmony_ci				 * will be driven, before sending data
848c2ecf20Sopenharmony_ci				 */
858c2ecf20Sopenharmony_ci} __packed;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci/* HDA Configuration Request - SOF_IPC_DAI_HDA_CONFIG */
888c2ecf20Sopenharmony_cistruct sof_ipc_dai_hda_params {
898c2ecf20Sopenharmony_ci	struct sof_ipc_hdr hdr;
908c2ecf20Sopenharmony_ci	uint32_t link_dma_ch;
918c2ecf20Sopenharmony_ci	uint32_t rate;
928c2ecf20Sopenharmony_ci	uint32_t channels;
938c2ecf20Sopenharmony_ci} __packed;
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci/* ALH Configuration Request - SOF_IPC_DAI_ALH_CONFIG */
968c2ecf20Sopenharmony_cistruct sof_ipc_dai_alh_params {
978c2ecf20Sopenharmony_ci	struct sof_ipc_hdr hdr;
988c2ecf20Sopenharmony_ci	uint32_t stream_id;
998c2ecf20Sopenharmony_ci	uint32_t rate;
1008c2ecf20Sopenharmony_ci	uint32_t channels;
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci	/* reserved for future use */
1038c2ecf20Sopenharmony_ci	uint32_t reserved[13];
1048c2ecf20Sopenharmony_ci} __packed;
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci/* DMIC Configuration Request - SOF_IPC_DAI_DMIC_CONFIG */
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/* This struct is defined per 2ch PDM controller available in the platform.
1098c2ecf20Sopenharmony_ci * Normally it is sufficient to set the used microphone specific enables to 1
1108c2ecf20Sopenharmony_ci * and keep other parameters as zero. The customizations are:
1118c2ecf20Sopenharmony_ci *
1128c2ecf20Sopenharmony_ci * 1. If a device mixes different microphones types with different polarity
1138c2ecf20Sopenharmony_ci * and/or the absolute polarity matters the PCM signal from a microphone
1148c2ecf20Sopenharmony_ci * can be inverted with the controls.
1158c2ecf20Sopenharmony_ci *
1168c2ecf20Sopenharmony_ci * 2. If the microphones in a stereo pair do not appear in captured stream
1178c2ecf20Sopenharmony_ci * in desired order due to board schematics choises they can be swapped with
1188c2ecf20Sopenharmony_ci * the clk_edge parameter.
1198c2ecf20Sopenharmony_ci *
1208c2ecf20Sopenharmony_ci * 3. If PDM bit errors are seen in capture (poor quality) the skew parameter
1218c2ecf20Sopenharmony_ci * that delays the sampling time of data by half cycles of DMIC source clock
1228c2ecf20Sopenharmony_ci * can be tried for improvement. However there is no guarantee for this to fix
1238c2ecf20Sopenharmony_ci * data integrity problems.
1248c2ecf20Sopenharmony_ci */
1258c2ecf20Sopenharmony_cistruct sof_ipc_dai_dmic_pdm_ctrl {
1268c2ecf20Sopenharmony_ci	struct sof_ipc_hdr hdr;
1278c2ecf20Sopenharmony_ci	uint16_t id;		/**< PDM controller ID */
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	uint16_t enable_mic_a;	/**< Use A (left) channel mic (0 or 1)*/
1308c2ecf20Sopenharmony_ci	uint16_t enable_mic_b;	/**< Use B (right) channel mic (0 or 1)*/
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	uint16_t polarity_mic_a; /**< Optionally invert mic A signal (0 or 1) */
1338c2ecf20Sopenharmony_ci	uint16_t polarity_mic_b; /**< Optionally invert mic B signal (0 or 1) */
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	uint16_t clk_edge;	/**< Optionally swap data clock edge (0 or 1) */
1368c2ecf20Sopenharmony_ci	uint16_t skew;		/**< Adjust PDM data sampling vs. clock (0..15) */
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	uint16_t reserved[3];	/**< Make sure the total size is 4 bytes aligned */
1398c2ecf20Sopenharmony_ci} __packed;
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci/* This struct contains the global settings for all 2ch PDM controllers. The
1428c2ecf20Sopenharmony_ci * version number used in configuration data is checked vs. version used by
1438c2ecf20Sopenharmony_ci * device driver src/drivers/dmic.c need to match. It is incremented from
1448c2ecf20Sopenharmony_ci * initial value 1 if updates done for the to driver would alter the operation
1458c2ecf20Sopenharmony_ci * of the microphone.
1468c2ecf20Sopenharmony_ci *
1478c2ecf20Sopenharmony_ci * Note: The microphone clock (pdmclk_min, pdmclk_max, duty_min, duty_max)
1488c2ecf20Sopenharmony_ci * parameters need to be set as defined in microphone data sheet. E.g. clock
1498c2ecf20Sopenharmony_ci * range 1.0 - 3.2 MHz is usually supported microphones. Some microphones are
1508c2ecf20Sopenharmony_ci * multi-mode capable and there may be denied mic clock frequencies between
1518c2ecf20Sopenharmony_ci * the modes. In such case set the clock range limits of the desired mode to
1528c2ecf20Sopenharmony_ci * avoid the driver to set clock to an illegal rate.
1538c2ecf20Sopenharmony_ci *
1548c2ecf20Sopenharmony_ci * The duty cycle could be set to 48-52% if not known. Generally these
1558c2ecf20Sopenharmony_ci * parameters can be altered within data sheet specified limits to match
1568c2ecf20Sopenharmony_ci * required audio application performance power.
1578c2ecf20Sopenharmony_ci *
1588c2ecf20Sopenharmony_ci * The microphone clock needs to be usually about 50-80 times the used audio
1598c2ecf20Sopenharmony_ci * sample rate. With highest sample rates above 48 kHz this can relaxed
1608c2ecf20Sopenharmony_ci * somewhat.
1618c2ecf20Sopenharmony_ci *
1628c2ecf20Sopenharmony_ci * The parameter wake_up_time describes how long time the microphone needs
1638c2ecf20Sopenharmony_ci * for the data line to produce valid output from mic clock start. The driver
1648c2ecf20Sopenharmony_ci * will mute the captured audio for the given time. The min_clock_on_time
1658c2ecf20Sopenharmony_ci * parameter is used to prevent too short clock bursts to happen. The driver
1668c2ecf20Sopenharmony_ci * will keep the clock active after capture stop if this time is not yet
1678c2ecf20Sopenharmony_ci * met. The unit for both is microseconds (us). Exceed of 100 ms will be
1688c2ecf20Sopenharmony_ci * treated as an error.
1698c2ecf20Sopenharmony_ci */
1708c2ecf20Sopenharmony_cistruct sof_ipc_dai_dmic_params {
1718c2ecf20Sopenharmony_ci	struct sof_ipc_hdr hdr;
1728c2ecf20Sopenharmony_ci	uint32_t driver_ipc_version;	/**< Version (1..N) */
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	uint32_t pdmclk_min;	/**< Minimum microphone clock in Hz (100000..N) */
1758c2ecf20Sopenharmony_ci	uint32_t pdmclk_max;	/**< Maximum microphone clock in Hz (min...N) */
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci	uint32_t fifo_fs;	/**< FIFO sample rate in Hz (8000..96000) */
1788c2ecf20Sopenharmony_ci	uint32_t reserved_1;	/**< Reserved */
1798c2ecf20Sopenharmony_ci	uint16_t fifo_bits;	/**< FIFO word length (16 or 32) */
1808c2ecf20Sopenharmony_ci	uint16_t fifo_bits_b;	/**< Deprecated since firmware ABI 3.0.1 */
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	uint16_t duty_min;	/**< Min. mic clock duty cycle in % (20..80) */
1838c2ecf20Sopenharmony_ci	uint16_t duty_max;	/**< Max. mic clock duty cycle in % (min..80) */
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci	uint32_t num_pdm_active; /**< Number of active pdm controllers. */
1868c2ecf20Sopenharmony_ci				 /**< Range is 1..SOF_DAI_INTEL_DMIC_NUM_CTRL */
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	uint32_t wake_up_time;      /**< Time from clock start to data (us) */
1898c2ecf20Sopenharmony_ci	uint32_t min_clock_on_time; /**< Min. time that clk is kept on (us) */
1908c2ecf20Sopenharmony_ci	uint32_t unmute_ramp_time;  /**< Length of logarithmic gain ramp (ms) */
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	/* reserved for future use */
1938c2ecf20Sopenharmony_ci	uint32_t reserved[5];
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci	/**< PDM controllers configuration */
1968c2ecf20Sopenharmony_ci	struct sof_ipc_dai_dmic_pdm_ctrl pdm[SOF_DAI_INTEL_DMIC_NUM_CTRL];
1978c2ecf20Sopenharmony_ci} __packed;
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci#endif
200