18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * STM32 ALSA SoC Digital Audio Interface (SAI) driver.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2016, STMicroelectronics - All Rights Reserved
68c2ecf20Sopenharmony_ci * Author(s): Olivier Moysan <olivier.moysan@st.com> for STMicroelectronics.
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/bitfield.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/******************** SAI Register Map **************************************/
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* Global configuration register */
148c2ecf20Sopenharmony_ci#define STM_SAI_GCR		0x00
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/* Sub-block A&B registers offsets, relative to A&B sub-block addresses */
178c2ecf20Sopenharmony_ci#define STM_SAI_CR1_REGX	0x00	/* A offset: 0x04. B offset: 0x24 */
188c2ecf20Sopenharmony_ci#define STM_SAI_CR2_REGX	0x04
198c2ecf20Sopenharmony_ci#define STM_SAI_FRCR_REGX	0x08
208c2ecf20Sopenharmony_ci#define STM_SAI_SLOTR_REGX	0x0C
218c2ecf20Sopenharmony_ci#define STM_SAI_IMR_REGX	0x10
228c2ecf20Sopenharmony_ci#define STM_SAI_SR_REGX		0x14
238c2ecf20Sopenharmony_ci#define STM_SAI_CLRFR_REGX	0x18
248c2ecf20Sopenharmony_ci#define STM_SAI_DR_REGX		0x1C
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/* Sub-block A registers, relative to sub-block A address */
278c2ecf20Sopenharmony_ci#define STM_SAI_PDMCR_REGX	0x40
288c2ecf20Sopenharmony_ci#define STM_SAI_PDMLY_REGX	0x44
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* Hardware configuration registers */
318c2ecf20Sopenharmony_ci#define STM_SAI_HWCFGR		0x3F0
328c2ecf20Sopenharmony_ci#define STM_SAI_VERR		0x3F4
338c2ecf20Sopenharmony_ci#define STM_SAI_IDR		0x3F8
348c2ecf20Sopenharmony_ci#define STM_SAI_SIDR		0x3FC
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/******************** Bit definition for SAI_GCR register *******************/
378c2ecf20Sopenharmony_ci#define SAI_GCR_SYNCIN_SHIFT	0
388c2ecf20Sopenharmony_ci#define SAI_GCR_SYNCIN_WDTH	2
398c2ecf20Sopenharmony_ci#define SAI_GCR_SYNCIN_MASK	GENMASK(1, SAI_GCR_SYNCIN_SHIFT)
408c2ecf20Sopenharmony_ci#define SAI_GCR_SYNCIN_MAX	FIELD_GET(SAI_GCR_SYNCIN_MASK,\
418c2ecf20Sopenharmony_ci				SAI_GCR_SYNCIN_MASK)
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define SAI_GCR_SYNCOUT_SHIFT	4
448c2ecf20Sopenharmony_ci#define SAI_GCR_SYNCOUT_MASK	GENMASK(5, SAI_GCR_SYNCOUT_SHIFT)
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci/******************* Bit definition for SAI_XCR1 register *******************/
478c2ecf20Sopenharmony_ci#define SAI_XCR1_RX_TX_SHIFT	0
488c2ecf20Sopenharmony_ci#define SAI_XCR1_RX_TX		BIT(SAI_XCR1_RX_TX_SHIFT)
498c2ecf20Sopenharmony_ci#define SAI_XCR1_SLAVE_SHIFT	1
508c2ecf20Sopenharmony_ci#define SAI_XCR1_SLAVE		BIT(SAI_XCR1_SLAVE_SHIFT)
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define SAI_XCR1_PRTCFG_SHIFT	2
538c2ecf20Sopenharmony_ci#define SAI_XCR1_PRTCFG_MASK	GENMASK(3, SAI_XCR1_PRTCFG_SHIFT)
548c2ecf20Sopenharmony_ci#define SAI_XCR1_PRTCFG_SET(x)	((x) << SAI_XCR1_PRTCFG_SHIFT)
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define SAI_XCR1_DS_SHIFT	5
578c2ecf20Sopenharmony_ci#define SAI_XCR1_DS_MASK	GENMASK(7, SAI_XCR1_DS_SHIFT)
588c2ecf20Sopenharmony_ci#define SAI_XCR1_DS_SET(x)	((x) << SAI_XCR1_DS_SHIFT)
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define SAI_XCR1_LSBFIRST_SHIFT	8
618c2ecf20Sopenharmony_ci#define SAI_XCR1_LSBFIRST	BIT(SAI_XCR1_LSBFIRST_SHIFT)
628c2ecf20Sopenharmony_ci#define SAI_XCR1_CKSTR_SHIFT	9
638c2ecf20Sopenharmony_ci#define SAI_XCR1_CKSTR		BIT(SAI_XCR1_CKSTR_SHIFT)
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define SAI_XCR1_SYNCEN_SHIFT	10
668c2ecf20Sopenharmony_ci#define SAI_XCR1_SYNCEN_MASK	GENMASK(11, SAI_XCR1_SYNCEN_SHIFT)
678c2ecf20Sopenharmony_ci#define SAI_XCR1_SYNCEN_SET(x)	((x) << SAI_XCR1_SYNCEN_SHIFT)
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define SAI_XCR1_MONO_SHIFT	12
708c2ecf20Sopenharmony_ci#define SAI_XCR1_MONO		BIT(SAI_XCR1_MONO_SHIFT)
718c2ecf20Sopenharmony_ci#define SAI_XCR1_OUTDRIV_SHIFT	13
728c2ecf20Sopenharmony_ci#define SAI_XCR1_OUTDRIV	BIT(SAI_XCR1_OUTDRIV_SHIFT)
738c2ecf20Sopenharmony_ci#define SAI_XCR1_SAIEN_SHIFT	16
748c2ecf20Sopenharmony_ci#define SAI_XCR1_SAIEN		BIT(SAI_XCR1_SAIEN_SHIFT)
758c2ecf20Sopenharmony_ci#define SAI_XCR1_DMAEN_SHIFT	17
768c2ecf20Sopenharmony_ci#define SAI_XCR1_DMAEN		BIT(SAI_XCR1_DMAEN_SHIFT)
778c2ecf20Sopenharmony_ci#define SAI_XCR1_NODIV_SHIFT	19
788c2ecf20Sopenharmony_ci#define SAI_XCR1_NODIV		BIT(SAI_XCR1_NODIV_SHIFT)
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci#define SAI_XCR1_MCKDIV_SHIFT	20
818c2ecf20Sopenharmony_ci#define SAI_XCR1_MCKDIV_WIDTH(x)	(((x) == STM_SAI_STM32F4) ? 4 : 6)
828c2ecf20Sopenharmony_ci#define SAI_XCR1_MCKDIV_MASK(x) GENMASK((SAI_XCR1_MCKDIV_SHIFT + (x) - 1),\
838c2ecf20Sopenharmony_ci				SAI_XCR1_MCKDIV_SHIFT)
848c2ecf20Sopenharmony_ci#define SAI_XCR1_MCKDIV_SET(x)	((x) << SAI_XCR1_MCKDIV_SHIFT)
858c2ecf20Sopenharmony_ci#define SAI_XCR1_MCKDIV_MAX(x)	((1 << SAI_XCR1_MCKDIV_WIDTH(x)) - 1)
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define SAI_XCR1_OSR_SHIFT	26
888c2ecf20Sopenharmony_ci#define SAI_XCR1_OSR		BIT(SAI_XCR1_OSR_SHIFT)
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#define SAI_XCR1_MCKEN_SHIFT	27
918c2ecf20Sopenharmony_ci#define SAI_XCR1_MCKEN		BIT(SAI_XCR1_MCKEN_SHIFT)
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/******************* Bit definition for SAI_XCR2 register *******************/
948c2ecf20Sopenharmony_ci#define SAI_XCR2_FTH_SHIFT	0
958c2ecf20Sopenharmony_ci#define SAI_XCR2_FTH_MASK	GENMASK(2, SAI_XCR2_FTH_SHIFT)
968c2ecf20Sopenharmony_ci#define SAI_XCR2_FTH_SET(x)	((x) << SAI_XCR2_FTH_SHIFT)
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#define SAI_XCR2_FFLUSH_SHIFT	3
998c2ecf20Sopenharmony_ci#define SAI_XCR2_FFLUSH		BIT(SAI_XCR2_FFLUSH_SHIFT)
1008c2ecf20Sopenharmony_ci#define SAI_XCR2_TRIS_SHIFT	4
1018c2ecf20Sopenharmony_ci#define SAI_XCR2_TRIS		BIT(SAI_XCR2_TRIS_SHIFT)
1028c2ecf20Sopenharmony_ci#define SAI_XCR2_MUTE_SHIFT	5
1038c2ecf20Sopenharmony_ci#define SAI_XCR2_MUTE		BIT(SAI_XCR2_MUTE_SHIFT)
1048c2ecf20Sopenharmony_ci#define SAI_XCR2_MUTEVAL_SHIFT	6
1058c2ecf20Sopenharmony_ci#define SAI_XCR2_MUTEVAL	BIT(SAI_XCR2_MUTEVAL_SHIFT)
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define SAI_XCR2_MUTECNT_SHIFT	7
1088c2ecf20Sopenharmony_ci#define SAI_XCR2_MUTECNT_MASK	GENMASK(12, SAI_XCR2_MUTECNT_SHIFT)
1098c2ecf20Sopenharmony_ci#define SAI_XCR2_MUTECNT_SET(x)	((x) << SAI_XCR2_MUTECNT_SHIFT)
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci#define SAI_XCR2_CPL_SHIFT	13
1128c2ecf20Sopenharmony_ci#define SAI_XCR2_CPL		BIT(SAI_XCR2_CPL_SHIFT)
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci#define SAI_XCR2_COMP_SHIFT	14
1158c2ecf20Sopenharmony_ci#define SAI_XCR2_COMP_MASK	GENMASK(15, SAI_XCR2_COMP_SHIFT)
1168c2ecf20Sopenharmony_ci#define SAI_XCR2_COMP_SET(x)	((x) << SAI_XCR2_COMP_SHIFT)
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci/****************** Bit definition for SAI_XFRCR register *******************/
1198c2ecf20Sopenharmony_ci#define SAI_XFRCR_FRL_SHIFT	0
1208c2ecf20Sopenharmony_ci#define SAI_XFRCR_FRL_MASK	GENMASK(7, SAI_XFRCR_FRL_SHIFT)
1218c2ecf20Sopenharmony_ci#define SAI_XFRCR_FRL_SET(x)	((x) << SAI_XFRCR_FRL_SHIFT)
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#define SAI_XFRCR_FSALL_SHIFT	8
1248c2ecf20Sopenharmony_ci#define SAI_XFRCR_FSALL_MASK	GENMASK(14, SAI_XFRCR_FSALL_SHIFT)
1258c2ecf20Sopenharmony_ci#define SAI_XFRCR_FSALL_SET(x)	((x) << SAI_XFRCR_FSALL_SHIFT)
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci#define SAI_XFRCR_FSDEF_SHIFT	16
1288c2ecf20Sopenharmony_ci#define SAI_XFRCR_FSDEF		BIT(SAI_XFRCR_FSDEF_SHIFT)
1298c2ecf20Sopenharmony_ci#define SAI_XFRCR_FSPOL_SHIFT	17
1308c2ecf20Sopenharmony_ci#define SAI_XFRCR_FSPOL		BIT(SAI_XFRCR_FSPOL_SHIFT)
1318c2ecf20Sopenharmony_ci#define SAI_XFRCR_FSOFF_SHIFT	18
1328c2ecf20Sopenharmony_ci#define SAI_XFRCR_FSOFF		BIT(SAI_XFRCR_FSOFF_SHIFT)
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci/****************** Bit definition for SAI_XSLOTR register ******************/
1358c2ecf20Sopenharmony_ci#define SAI_XSLOTR_FBOFF_SHIFT	0
1368c2ecf20Sopenharmony_ci#define SAI_XSLOTR_FBOFF_MASK	GENMASK(4, SAI_XSLOTR_FBOFF_SHIFT)
1378c2ecf20Sopenharmony_ci#define SAI_XSLOTR_FBOFF_SET(x)	((x) << SAI_XSLOTR_FBOFF_SHIFT)
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci#define SAI_XSLOTR_SLOTSZ_SHIFT	6
1408c2ecf20Sopenharmony_ci#define SAI_XSLOTR_SLOTSZ_MASK	GENMASK(7, SAI_XSLOTR_SLOTSZ_SHIFT)
1418c2ecf20Sopenharmony_ci#define SAI_XSLOTR_SLOTSZ_SET(x)	((x) << SAI_XSLOTR_SLOTSZ_SHIFT)
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci#define SAI_XSLOTR_NBSLOT_SHIFT 8
1448c2ecf20Sopenharmony_ci#define SAI_XSLOTR_NBSLOT_MASK	GENMASK(11, SAI_XSLOTR_NBSLOT_SHIFT)
1458c2ecf20Sopenharmony_ci#define SAI_XSLOTR_NBSLOT_SET(x) ((x) << SAI_XSLOTR_NBSLOT_SHIFT)
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci#define SAI_XSLOTR_SLOTEN_SHIFT	16
1488c2ecf20Sopenharmony_ci#define SAI_XSLOTR_SLOTEN_WIDTH	16
1498c2ecf20Sopenharmony_ci#define SAI_XSLOTR_SLOTEN_MASK	GENMASK(31, SAI_XSLOTR_SLOTEN_SHIFT)
1508c2ecf20Sopenharmony_ci#define SAI_XSLOTR_SLOTEN_SET(x) ((x) << SAI_XSLOTR_SLOTEN_SHIFT)
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/******************* Bit definition for SAI_XIMR register *******************/
1538c2ecf20Sopenharmony_ci#define SAI_XIMR_OVRUDRIE	BIT(0)
1548c2ecf20Sopenharmony_ci#define SAI_XIMR_MUTEDETIE	BIT(1)
1558c2ecf20Sopenharmony_ci#define SAI_XIMR_WCKCFGIE	BIT(2)
1568c2ecf20Sopenharmony_ci#define SAI_XIMR_FREQIE		BIT(3)
1578c2ecf20Sopenharmony_ci#define SAI_XIMR_CNRDYIE	BIT(4)
1588c2ecf20Sopenharmony_ci#define SAI_XIMR_AFSDETIE	BIT(5)
1598c2ecf20Sopenharmony_ci#define SAI_XIMR_LFSDETIE	BIT(6)
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci#define SAI_XIMR_SHIFT	0
1628c2ecf20Sopenharmony_ci#define SAI_XIMR_MASK		GENMASK(6, SAI_XIMR_SHIFT)
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci/******************** Bit definition for SAI_XSR register *******************/
1658c2ecf20Sopenharmony_ci#define SAI_XSR_OVRUDR		BIT(0)
1668c2ecf20Sopenharmony_ci#define SAI_XSR_MUTEDET		BIT(1)
1678c2ecf20Sopenharmony_ci#define SAI_XSR_WCKCFG		BIT(2)
1688c2ecf20Sopenharmony_ci#define SAI_XSR_FREQ		BIT(3)
1698c2ecf20Sopenharmony_ci#define SAI_XSR_CNRDY		BIT(4)
1708c2ecf20Sopenharmony_ci#define SAI_XSR_AFSDET		BIT(5)
1718c2ecf20Sopenharmony_ci#define SAI_XSR_LFSDET		BIT(6)
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci#define SAI_XSR_SHIFT	0
1748c2ecf20Sopenharmony_ci#define SAI_XSR_MASK		GENMASK(6, SAI_XSR_SHIFT)
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci/****************** Bit definition for SAI_XCLRFR register ******************/
1778c2ecf20Sopenharmony_ci#define SAI_XCLRFR_COVRUDR	BIT(0)
1788c2ecf20Sopenharmony_ci#define SAI_XCLRFR_CMUTEDET	BIT(1)
1798c2ecf20Sopenharmony_ci#define SAI_XCLRFR_CWCKCFG	BIT(2)
1808c2ecf20Sopenharmony_ci#define SAI_XCLRFR_CFREQ	BIT(3)
1818c2ecf20Sopenharmony_ci#define SAI_XCLRFR_CCNRDY	BIT(4)
1828c2ecf20Sopenharmony_ci#define SAI_XCLRFR_CAFSDET	BIT(5)
1838c2ecf20Sopenharmony_ci#define SAI_XCLRFR_CLFSDET	BIT(6)
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci#define SAI_XCLRFR_SHIFT	0
1868c2ecf20Sopenharmony_ci#define SAI_XCLRFR_MASK		GENMASK(6, SAI_XCLRFR_SHIFT)
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci/****************** Bit definition for SAI_PDMCR register ******************/
1898c2ecf20Sopenharmony_ci#define SAI_PDMCR_PDMEN		BIT(0)
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci#define SAI_PDMCR_MICNBR_SHIFT	4
1928c2ecf20Sopenharmony_ci#define SAI_PDMCR_MICNBR_MASK	GENMASK(5, SAI_PDMCR_MICNBR_SHIFT)
1938c2ecf20Sopenharmony_ci#define SAI_PDMCR_MICNBR_SET(x)	((x) << SAI_PDMCR_MICNBR_SHIFT)
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci#define SAI_PDMCR_CKEN1		BIT(8)
1968c2ecf20Sopenharmony_ci#define SAI_PDMCR_CKEN2		BIT(9)
1978c2ecf20Sopenharmony_ci#define SAI_PDMCR_CKEN3		BIT(10)
1988c2ecf20Sopenharmony_ci#define SAI_PDMCR_CKEN4		BIT(11)
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci/****************** Bit definition for (SAI_PDMDLY register ****************/
2018c2ecf20Sopenharmony_ci#define SAI_PDMDLY_1L_SHIFT	0
2028c2ecf20Sopenharmony_ci#define SAI_PDMDLY_1L_MASK	GENMASK(2, SAI_PDMDLY_1L_SHIFT)
2038c2ecf20Sopenharmony_ci#define SAI_PDMDLY_1L_WIDTH	3
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci#define SAI_PDMDLY_1R_SHIFT	4
2068c2ecf20Sopenharmony_ci#define SAI_PDMDLY_1R_MASK	GENMASK(6, SAI_PDMDLY_1R_SHIFT)
2078c2ecf20Sopenharmony_ci#define SAI_PDMDLY_1R_WIDTH	3
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci#define SAI_PDMDLY_2L_SHIFT	8
2108c2ecf20Sopenharmony_ci#define SAI_PDMDLY_2L_MASK	GENMASK(10, SAI_PDMDLY_2L_SHIFT)
2118c2ecf20Sopenharmony_ci#define SAI_PDMDLY_2L_WIDTH	3
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci#define SAI_PDMDLY_2R_SHIFT	12
2148c2ecf20Sopenharmony_ci#define SAI_PDMDLY_2R_MASK	GENMASK(14, SAI_PDMDLY_2R_SHIFT)
2158c2ecf20Sopenharmony_ci#define SAI_PDMDLY_2R_WIDTH	3
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci#define SAI_PDMDLY_3L_SHIFT	16
2188c2ecf20Sopenharmony_ci#define SAI_PDMDLY_3L_MASK	GENMASK(18, SAI_PDMDLY_3L_SHIFT)
2198c2ecf20Sopenharmony_ci#define SAI_PDMDLY_3L_WIDTH	3
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci#define SAI_PDMDLY_3R_SHIFT	20
2228c2ecf20Sopenharmony_ci#define SAI_PDMDLY_3R_MASK	GENMASK(22, SAI_PDMDLY_3R_SHIFT)
2238c2ecf20Sopenharmony_ci#define SAI_PDMDLY_3R_WIDTH	3
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci#define SAI_PDMDLY_4L_SHIFT	24
2268c2ecf20Sopenharmony_ci#define SAI_PDMDLY_4L_MASK	GENMASK(26, SAI_PDMDLY_4L_SHIFT)
2278c2ecf20Sopenharmony_ci#define SAI_PDMDLY_4L_WIDTH	3
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci#define SAI_PDMDLY_4R_SHIFT	28
2308c2ecf20Sopenharmony_ci#define SAI_PDMDLY_4R_MASK	GENMASK(30, SAI_PDMDLY_4R_SHIFT)
2318c2ecf20Sopenharmony_ci#define SAI_PDMDLY_4R_WIDTH	3
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci/* Registers below apply to SAI version 2.1 and more */
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci/* Bit definition for SAI_HWCFGR register */
2368c2ecf20Sopenharmony_ci#define SAI_HWCFGR_FIFO_SIZE	GENMASK(7, 0)
2378c2ecf20Sopenharmony_ci#define SAI_HWCFGR_SPDIF_PDM	GENMASK(11, 8)
2388c2ecf20Sopenharmony_ci#define SAI_HWCFGR_REGOUT	GENMASK(19, 12)
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci/* Bit definition for SAI_VERR register */
2418c2ecf20Sopenharmony_ci#define SAI_VERR_MIN_MASK	GENMASK(3, 0)
2428c2ecf20Sopenharmony_ci#define SAI_VERR_MAJ_MASK	GENMASK(7, 4)
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci/* Bit definition for SAI_IDR register */
2458c2ecf20Sopenharmony_ci#define SAI_IDR_ID_MASK		GENMASK(31, 0)
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci/* Bit definition for SAI_SIDR register */
2488c2ecf20Sopenharmony_ci#define SAI_SIDR_ID_MASK	GENMASK(31, 0)
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci#define SAI_IPIDR_NUMBER	0x00130031
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci/* SAI version numbers are 1.x for F4. Major version number set to 1 for F4 */
2538c2ecf20Sopenharmony_ci#define STM_SAI_STM32F4		BIT(4)
2548c2ecf20Sopenharmony_ci/* Dummy version number for H7 socs and next */
2558c2ecf20Sopenharmony_ci#define STM_SAI_STM32H7		0x0
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci#define STM_SAI_IS_F4(ip)	((ip)->conf.version == STM_SAI_STM32F4)
2588c2ecf20Sopenharmony_ci#define STM_SAI_HAS_SPDIF_PDM(ip)\
2598c2ecf20Sopenharmony_ci				((ip)->pdata->conf.has_spdif_pdm)
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_cienum stm32_sai_syncout {
2628c2ecf20Sopenharmony_ci	STM_SAI_SYNC_OUT_NONE,
2638c2ecf20Sopenharmony_ci	STM_SAI_SYNC_OUT_A,
2648c2ecf20Sopenharmony_ci	STM_SAI_SYNC_OUT_B,
2658c2ecf20Sopenharmony_ci};
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci/**
2688c2ecf20Sopenharmony_ci * struct stm32_sai_conf - SAI configuration
2698c2ecf20Sopenharmony_ci * @version: SAI version
2708c2ecf20Sopenharmony_ci * @fifo_size: SAI fifo size as words number
2718c2ecf20Sopenharmony_ci * @has_spdif_pdm: SAI S/PDIF and PDM features support flag
2728c2ecf20Sopenharmony_ci */
2738c2ecf20Sopenharmony_cistruct stm32_sai_conf {
2748c2ecf20Sopenharmony_ci	u32 version;
2758c2ecf20Sopenharmony_ci	u32 fifo_size;
2768c2ecf20Sopenharmony_ci	bool has_spdif_pdm;
2778c2ecf20Sopenharmony_ci};
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci/**
2808c2ecf20Sopenharmony_ci * struct stm32_sai_data - private data of SAI instance driver
2818c2ecf20Sopenharmony_ci * @pdev: device data pointer
2828c2ecf20Sopenharmony_ci * @base: common register bank virtual base address
2838c2ecf20Sopenharmony_ci * @pclk: SAI bus clock
2848c2ecf20Sopenharmony_ci * @clk_x8k: SAI parent clock for sampling frequencies multiple of 8kHz
2858c2ecf20Sopenharmony_ci * @clk_x11k: SAI parent clock for sampling frequencies multiple of 11kHz
2868c2ecf20Sopenharmony_ci * @conf: SAI hardware capabitilites
2878c2ecf20Sopenharmony_ci * @irq: SAI interrupt line
2888c2ecf20Sopenharmony_ci * @set_sync: pointer to synchro mode configuration callback
2898c2ecf20Sopenharmony_ci * @gcr: SAI Global Configuration Register
2908c2ecf20Sopenharmony_ci */
2918c2ecf20Sopenharmony_cistruct stm32_sai_data {
2928c2ecf20Sopenharmony_ci	struct platform_device *pdev;
2938c2ecf20Sopenharmony_ci	void __iomem *base;
2948c2ecf20Sopenharmony_ci	struct clk *pclk;
2958c2ecf20Sopenharmony_ci	struct clk *clk_x8k;
2968c2ecf20Sopenharmony_ci	struct clk *clk_x11k;
2978c2ecf20Sopenharmony_ci	struct stm32_sai_conf conf;
2988c2ecf20Sopenharmony_ci	int irq;
2998c2ecf20Sopenharmony_ci	int (*set_sync)(struct stm32_sai_data *sai,
3008c2ecf20Sopenharmony_ci			struct device_node *np_provider, int synco, int synci);
3018c2ecf20Sopenharmony_ci	u32 gcr;
3028c2ecf20Sopenharmony_ci};
303