162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * STM32 ALSA SoC Digital Audio Interface (SAI) driver. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2016, STMicroelectronics - All Rights Reserved 662306a36Sopenharmony_ci * Author(s): Olivier Moysan <olivier.moysan@st.com> for STMicroelectronics. 762306a36Sopenharmony_ci */ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include <linux/bitfield.h> 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci/******************** SAI Register Map **************************************/ 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci/* Global configuration register */ 1462306a36Sopenharmony_ci#define STM_SAI_GCR 0x00 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci/* Sub-block A&B registers offsets, relative to A&B sub-block addresses */ 1762306a36Sopenharmony_ci#define STM_SAI_CR1_REGX 0x00 /* A offset: 0x04. B offset: 0x24 */ 1862306a36Sopenharmony_ci#define STM_SAI_CR2_REGX 0x04 1962306a36Sopenharmony_ci#define STM_SAI_FRCR_REGX 0x08 2062306a36Sopenharmony_ci#define STM_SAI_SLOTR_REGX 0x0C 2162306a36Sopenharmony_ci#define STM_SAI_IMR_REGX 0x10 2262306a36Sopenharmony_ci#define STM_SAI_SR_REGX 0x14 2362306a36Sopenharmony_ci#define STM_SAI_CLRFR_REGX 0x18 2462306a36Sopenharmony_ci#define STM_SAI_DR_REGX 0x1C 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci/* Sub-block A registers, relative to sub-block A address */ 2762306a36Sopenharmony_ci#define STM_SAI_PDMCR_REGX 0x40 2862306a36Sopenharmony_ci#define STM_SAI_PDMLY_REGX 0x44 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci/* Hardware configuration registers */ 3162306a36Sopenharmony_ci#define STM_SAI_HWCFGR 0x3F0 3262306a36Sopenharmony_ci#define STM_SAI_VERR 0x3F4 3362306a36Sopenharmony_ci#define STM_SAI_IDR 0x3F8 3462306a36Sopenharmony_ci#define STM_SAI_SIDR 0x3FC 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci/******************** Bit definition for SAI_GCR register *******************/ 3762306a36Sopenharmony_ci#define SAI_GCR_SYNCIN_SHIFT 0 3862306a36Sopenharmony_ci#define SAI_GCR_SYNCIN_WDTH 2 3962306a36Sopenharmony_ci#define SAI_GCR_SYNCIN_MASK GENMASK(1, SAI_GCR_SYNCIN_SHIFT) 4062306a36Sopenharmony_ci#define SAI_GCR_SYNCIN_MAX FIELD_GET(SAI_GCR_SYNCIN_MASK,\ 4162306a36Sopenharmony_ci SAI_GCR_SYNCIN_MASK) 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#define SAI_GCR_SYNCOUT_SHIFT 4 4462306a36Sopenharmony_ci#define SAI_GCR_SYNCOUT_MASK GENMASK(5, SAI_GCR_SYNCOUT_SHIFT) 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci/******************* Bit definition for SAI_XCR1 register *******************/ 4762306a36Sopenharmony_ci#define SAI_XCR1_RX_TX_SHIFT 0 4862306a36Sopenharmony_ci#define SAI_XCR1_RX_TX BIT(SAI_XCR1_RX_TX_SHIFT) 4962306a36Sopenharmony_ci#define SAI_XCR1_SLAVE_SHIFT 1 5062306a36Sopenharmony_ci#define SAI_XCR1_SLAVE BIT(SAI_XCR1_SLAVE_SHIFT) 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci#define SAI_XCR1_PRTCFG_SHIFT 2 5362306a36Sopenharmony_ci#define SAI_XCR1_PRTCFG_MASK GENMASK(3, SAI_XCR1_PRTCFG_SHIFT) 5462306a36Sopenharmony_ci#define SAI_XCR1_PRTCFG_SET(x) ((x) << SAI_XCR1_PRTCFG_SHIFT) 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci#define SAI_XCR1_DS_SHIFT 5 5762306a36Sopenharmony_ci#define SAI_XCR1_DS_MASK GENMASK(7, SAI_XCR1_DS_SHIFT) 5862306a36Sopenharmony_ci#define SAI_XCR1_DS_SET(x) ((x) << SAI_XCR1_DS_SHIFT) 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci#define SAI_XCR1_LSBFIRST_SHIFT 8 6162306a36Sopenharmony_ci#define SAI_XCR1_LSBFIRST BIT(SAI_XCR1_LSBFIRST_SHIFT) 6262306a36Sopenharmony_ci#define SAI_XCR1_CKSTR_SHIFT 9 6362306a36Sopenharmony_ci#define SAI_XCR1_CKSTR BIT(SAI_XCR1_CKSTR_SHIFT) 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci#define SAI_XCR1_SYNCEN_SHIFT 10 6662306a36Sopenharmony_ci#define SAI_XCR1_SYNCEN_MASK GENMASK(11, SAI_XCR1_SYNCEN_SHIFT) 6762306a36Sopenharmony_ci#define SAI_XCR1_SYNCEN_SET(x) ((x) << SAI_XCR1_SYNCEN_SHIFT) 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci#define SAI_XCR1_MONO_SHIFT 12 7062306a36Sopenharmony_ci#define SAI_XCR1_MONO BIT(SAI_XCR1_MONO_SHIFT) 7162306a36Sopenharmony_ci#define SAI_XCR1_OUTDRIV_SHIFT 13 7262306a36Sopenharmony_ci#define SAI_XCR1_OUTDRIV BIT(SAI_XCR1_OUTDRIV_SHIFT) 7362306a36Sopenharmony_ci#define SAI_XCR1_SAIEN_SHIFT 16 7462306a36Sopenharmony_ci#define SAI_XCR1_SAIEN BIT(SAI_XCR1_SAIEN_SHIFT) 7562306a36Sopenharmony_ci#define SAI_XCR1_DMAEN_SHIFT 17 7662306a36Sopenharmony_ci#define SAI_XCR1_DMAEN BIT(SAI_XCR1_DMAEN_SHIFT) 7762306a36Sopenharmony_ci#define SAI_XCR1_NODIV_SHIFT 19 7862306a36Sopenharmony_ci#define SAI_XCR1_NODIV BIT(SAI_XCR1_NODIV_SHIFT) 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci#define SAI_XCR1_MCKDIV_SHIFT 20 8162306a36Sopenharmony_ci#define SAI_XCR1_MCKDIV_WIDTH(x) (((x) == STM_SAI_STM32F4) ? 4 : 6) 8262306a36Sopenharmony_ci#define SAI_XCR1_MCKDIV_MASK(x) GENMASK((SAI_XCR1_MCKDIV_SHIFT + (x) - 1),\ 8362306a36Sopenharmony_ci SAI_XCR1_MCKDIV_SHIFT) 8462306a36Sopenharmony_ci#define SAI_XCR1_MCKDIV_SET(x) ((x) << SAI_XCR1_MCKDIV_SHIFT) 8562306a36Sopenharmony_ci#define SAI_XCR1_MCKDIV_MAX(x) ((1 << SAI_XCR1_MCKDIV_WIDTH(x)) - 1) 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci#define SAI_XCR1_OSR_SHIFT 26 8862306a36Sopenharmony_ci#define SAI_XCR1_OSR BIT(SAI_XCR1_OSR_SHIFT) 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci#define SAI_XCR1_MCKEN_SHIFT 27 9162306a36Sopenharmony_ci#define SAI_XCR1_MCKEN BIT(SAI_XCR1_MCKEN_SHIFT) 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci/******************* Bit definition for SAI_XCR2 register *******************/ 9462306a36Sopenharmony_ci#define SAI_XCR2_FTH_SHIFT 0 9562306a36Sopenharmony_ci#define SAI_XCR2_FTH_MASK GENMASK(2, SAI_XCR2_FTH_SHIFT) 9662306a36Sopenharmony_ci#define SAI_XCR2_FTH_SET(x) ((x) << SAI_XCR2_FTH_SHIFT) 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci#define SAI_XCR2_FFLUSH_SHIFT 3 9962306a36Sopenharmony_ci#define SAI_XCR2_FFLUSH BIT(SAI_XCR2_FFLUSH_SHIFT) 10062306a36Sopenharmony_ci#define SAI_XCR2_TRIS_SHIFT 4 10162306a36Sopenharmony_ci#define SAI_XCR2_TRIS BIT(SAI_XCR2_TRIS_SHIFT) 10262306a36Sopenharmony_ci#define SAI_XCR2_MUTE_SHIFT 5 10362306a36Sopenharmony_ci#define SAI_XCR2_MUTE BIT(SAI_XCR2_MUTE_SHIFT) 10462306a36Sopenharmony_ci#define SAI_XCR2_MUTEVAL_SHIFT 6 10562306a36Sopenharmony_ci#define SAI_XCR2_MUTEVAL BIT(SAI_XCR2_MUTEVAL_SHIFT) 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci#define SAI_XCR2_MUTECNT_SHIFT 7 10862306a36Sopenharmony_ci#define SAI_XCR2_MUTECNT_MASK GENMASK(12, SAI_XCR2_MUTECNT_SHIFT) 10962306a36Sopenharmony_ci#define SAI_XCR2_MUTECNT_SET(x) ((x) << SAI_XCR2_MUTECNT_SHIFT) 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci#define SAI_XCR2_CPL_SHIFT 13 11262306a36Sopenharmony_ci#define SAI_XCR2_CPL BIT(SAI_XCR2_CPL_SHIFT) 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci#define SAI_XCR2_COMP_SHIFT 14 11562306a36Sopenharmony_ci#define SAI_XCR2_COMP_MASK GENMASK(15, SAI_XCR2_COMP_SHIFT) 11662306a36Sopenharmony_ci#define SAI_XCR2_COMP_SET(x) ((x) << SAI_XCR2_COMP_SHIFT) 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci/****************** Bit definition for SAI_XFRCR register *******************/ 11962306a36Sopenharmony_ci#define SAI_XFRCR_FRL_SHIFT 0 12062306a36Sopenharmony_ci#define SAI_XFRCR_FRL_MASK GENMASK(7, SAI_XFRCR_FRL_SHIFT) 12162306a36Sopenharmony_ci#define SAI_XFRCR_FRL_SET(x) ((x) << SAI_XFRCR_FRL_SHIFT) 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci#define SAI_XFRCR_FSALL_SHIFT 8 12462306a36Sopenharmony_ci#define SAI_XFRCR_FSALL_MASK GENMASK(14, SAI_XFRCR_FSALL_SHIFT) 12562306a36Sopenharmony_ci#define SAI_XFRCR_FSALL_SET(x) ((x) << SAI_XFRCR_FSALL_SHIFT) 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci#define SAI_XFRCR_FSDEF_SHIFT 16 12862306a36Sopenharmony_ci#define SAI_XFRCR_FSDEF BIT(SAI_XFRCR_FSDEF_SHIFT) 12962306a36Sopenharmony_ci#define SAI_XFRCR_FSPOL_SHIFT 17 13062306a36Sopenharmony_ci#define SAI_XFRCR_FSPOL BIT(SAI_XFRCR_FSPOL_SHIFT) 13162306a36Sopenharmony_ci#define SAI_XFRCR_FSOFF_SHIFT 18 13262306a36Sopenharmony_ci#define SAI_XFRCR_FSOFF BIT(SAI_XFRCR_FSOFF_SHIFT) 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci/****************** Bit definition for SAI_XSLOTR register ******************/ 13562306a36Sopenharmony_ci#define SAI_XSLOTR_FBOFF_SHIFT 0 13662306a36Sopenharmony_ci#define SAI_XSLOTR_FBOFF_MASK GENMASK(4, SAI_XSLOTR_FBOFF_SHIFT) 13762306a36Sopenharmony_ci#define SAI_XSLOTR_FBOFF_SET(x) ((x) << SAI_XSLOTR_FBOFF_SHIFT) 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci#define SAI_XSLOTR_SLOTSZ_SHIFT 6 14062306a36Sopenharmony_ci#define SAI_XSLOTR_SLOTSZ_MASK GENMASK(7, SAI_XSLOTR_SLOTSZ_SHIFT) 14162306a36Sopenharmony_ci#define SAI_XSLOTR_SLOTSZ_SET(x) ((x) << SAI_XSLOTR_SLOTSZ_SHIFT) 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci#define SAI_XSLOTR_NBSLOT_SHIFT 8 14462306a36Sopenharmony_ci#define SAI_XSLOTR_NBSLOT_MASK GENMASK(11, SAI_XSLOTR_NBSLOT_SHIFT) 14562306a36Sopenharmony_ci#define SAI_XSLOTR_NBSLOT_SET(x) ((x) << SAI_XSLOTR_NBSLOT_SHIFT) 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci#define SAI_XSLOTR_SLOTEN_SHIFT 16 14862306a36Sopenharmony_ci#define SAI_XSLOTR_SLOTEN_WIDTH 16 14962306a36Sopenharmony_ci#define SAI_XSLOTR_SLOTEN_MASK GENMASK(31, SAI_XSLOTR_SLOTEN_SHIFT) 15062306a36Sopenharmony_ci#define SAI_XSLOTR_SLOTEN_SET(x) ((x) << SAI_XSLOTR_SLOTEN_SHIFT) 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ci/******************* Bit definition for SAI_XIMR register *******************/ 15362306a36Sopenharmony_ci#define SAI_XIMR_OVRUDRIE BIT(0) 15462306a36Sopenharmony_ci#define SAI_XIMR_MUTEDETIE BIT(1) 15562306a36Sopenharmony_ci#define SAI_XIMR_WCKCFGIE BIT(2) 15662306a36Sopenharmony_ci#define SAI_XIMR_FREQIE BIT(3) 15762306a36Sopenharmony_ci#define SAI_XIMR_CNRDYIE BIT(4) 15862306a36Sopenharmony_ci#define SAI_XIMR_AFSDETIE BIT(5) 15962306a36Sopenharmony_ci#define SAI_XIMR_LFSDETIE BIT(6) 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci#define SAI_XIMR_SHIFT 0 16262306a36Sopenharmony_ci#define SAI_XIMR_MASK GENMASK(6, SAI_XIMR_SHIFT) 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ci/******************** Bit definition for SAI_XSR register *******************/ 16562306a36Sopenharmony_ci#define SAI_XSR_OVRUDR BIT(0) 16662306a36Sopenharmony_ci#define SAI_XSR_MUTEDET BIT(1) 16762306a36Sopenharmony_ci#define SAI_XSR_WCKCFG BIT(2) 16862306a36Sopenharmony_ci#define SAI_XSR_FREQ BIT(3) 16962306a36Sopenharmony_ci#define SAI_XSR_CNRDY BIT(4) 17062306a36Sopenharmony_ci#define SAI_XSR_AFSDET BIT(5) 17162306a36Sopenharmony_ci#define SAI_XSR_LFSDET BIT(6) 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci#define SAI_XSR_SHIFT 0 17462306a36Sopenharmony_ci#define SAI_XSR_MASK GENMASK(6, SAI_XSR_SHIFT) 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci/****************** Bit definition for SAI_XCLRFR register ******************/ 17762306a36Sopenharmony_ci#define SAI_XCLRFR_COVRUDR BIT(0) 17862306a36Sopenharmony_ci#define SAI_XCLRFR_CMUTEDET BIT(1) 17962306a36Sopenharmony_ci#define SAI_XCLRFR_CWCKCFG BIT(2) 18062306a36Sopenharmony_ci#define SAI_XCLRFR_CFREQ BIT(3) 18162306a36Sopenharmony_ci#define SAI_XCLRFR_CCNRDY BIT(4) 18262306a36Sopenharmony_ci#define SAI_XCLRFR_CAFSDET BIT(5) 18362306a36Sopenharmony_ci#define SAI_XCLRFR_CLFSDET BIT(6) 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci#define SAI_XCLRFR_SHIFT 0 18662306a36Sopenharmony_ci#define SAI_XCLRFR_MASK GENMASK(6, SAI_XCLRFR_SHIFT) 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci/****************** Bit definition for SAI_PDMCR register ******************/ 18962306a36Sopenharmony_ci#define SAI_PDMCR_PDMEN BIT(0) 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci#define SAI_PDMCR_MICNBR_SHIFT 4 19262306a36Sopenharmony_ci#define SAI_PDMCR_MICNBR_MASK GENMASK(5, SAI_PDMCR_MICNBR_SHIFT) 19362306a36Sopenharmony_ci#define SAI_PDMCR_MICNBR_SET(x) ((x) << SAI_PDMCR_MICNBR_SHIFT) 19462306a36Sopenharmony_ci 19562306a36Sopenharmony_ci#define SAI_PDMCR_CKEN1 BIT(8) 19662306a36Sopenharmony_ci#define SAI_PDMCR_CKEN2 BIT(9) 19762306a36Sopenharmony_ci#define SAI_PDMCR_CKEN3 BIT(10) 19862306a36Sopenharmony_ci#define SAI_PDMCR_CKEN4 BIT(11) 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci/****************** Bit definition for (SAI_PDMDLY register ****************/ 20162306a36Sopenharmony_ci#define SAI_PDMDLY_1L_SHIFT 0 20262306a36Sopenharmony_ci#define SAI_PDMDLY_1L_MASK GENMASK(2, SAI_PDMDLY_1L_SHIFT) 20362306a36Sopenharmony_ci#define SAI_PDMDLY_1L_WIDTH 3 20462306a36Sopenharmony_ci 20562306a36Sopenharmony_ci#define SAI_PDMDLY_1R_SHIFT 4 20662306a36Sopenharmony_ci#define SAI_PDMDLY_1R_MASK GENMASK(6, SAI_PDMDLY_1R_SHIFT) 20762306a36Sopenharmony_ci#define SAI_PDMDLY_1R_WIDTH 3 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci#define SAI_PDMDLY_2L_SHIFT 8 21062306a36Sopenharmony_ci#define SAI_PDMDLY_2L_MASK GENMASK(10, SAI_PDMDLY_2L_SHIFT) 21162306a36Sopenharmony_ci#define SAI_PDMDLY_2L_WIDTH 3 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_ci#define SAI_PDMDLY_2R_SHIFT 12 21462306a36Sopenharmony_ci#define SAI_PDMDLY_2R_MASK GENMASK(14, SAI_PDMDLY_2R_SHIFT) 21562306a36Sopenharmony_ci#define SAI_PDMDLY_2R_WIDTH 3 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci#define SAI_PDMDLY_3L_SHIFT 16 21862306a36Sopenharmony_ci#define SAI_PDMDLY_3L_MASK GENMASK(18, SAI_PDMDLY_3L_SHIFT) 21962306a36Sopenharmony_ci#define SAI_PDMDLY_3L_WIDTH 3 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ci#define SAI_PDMDLY_3R_SHIFT 20 22262306a36Sopenharmony_ci#define SAI_PDMDLY_3R_MASK GENMASK(22, SAI_PDMDLY_3R_SHIFT) 22362306a36Sopenharmony_ci#define SAI_PDMDLY_3R_WIDTH 3 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci#define SAI_PDMDLY_4L_SHIFT 24 22662306a36Sopenharmony_ci#define SAI_PDMDLY_4L_MASK GENMASK(26, SAI_PDMDLY_4L_SHIFT) 22762306a36Sopenharmony_ci#define SAI_PDMDLY_4L_WIDTH 3 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ci#define SAI_PDMDLY_4R_SHIFT 28 23062306a36Sopenharmony_ci#define SAI_PDMDLY_4R_MASK GENMASK(30, SAI_PDMDLY_4R_SHIFT) 23162306a36Sopenharmony_ci#define SAI_PDMDLY_4R_WIDTH 3 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci/* Registers below apply to SAI version 2.1 and more */ 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_ci/* Bit definition for SAI_HWCFGR register */ 23662306a36Sopenharmony_ci#define SAI_HWCFGR_FIFO_SIZE GENMASK(7, 0) 23762306a36Sopenharmony_ci#define SAI_HWCFGR_SPDIF_PDM GENMASK(11, 8) 23862306a36Sopenharmony_ci#define SAI_HWCFGR_REGOUT GENMASK(19, 12) 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ci/* Bit definition for SAI_VERR register */ 24162306a36Sopenharmony_ci#define SAI_VERR_MIN_MASK GENMASK(3, 0) 24262306a36Sopenharmony_ci#define SAI_VERR_MAJ_MASK GENMASK(7, 4) 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ci/* Bit definition for SAI_IDR register */ 24562306a36Sopenharmony_ci#define SAI_IDR_ID_MASK GENMASK(31, 0) 24662306a36Sopenharmony_ci 24762306a36Sopenharmony_ci/* Bit definition for SAI_SIDR register */ 24862306a36Sopenharmony_ci#define SAI_SIDR_ID_MASK GENMASK(31, 0) 24962306a36Sopenharmony_ci 25062306a36Sopenharmony_ci#define SAI_IPIDR_NUMBER 0x00130031 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_ci/* SAI version numbers are 1.x for F4. Major version number set to 1 for F4 */ 25362306a36Sopenharmony_ci#define STM_SAI_STM32F4 BIT(4) 25462306a36Sopenharmony_ci/* Dummy version number for H7 socs and next */ 25562306a36Sopenharmony_ci#define STM_SAI_STM32H7 0x0 25662306a36Sopenharmony_ci 25762306a36Sopenharmony_ci#define STM_SAI_IS_F4(ip) ((ip)->conf.version == STM_SAI_STM32F4) 25862306a36Sopenharmony_ci#define STM_SAI_HAS_SPDIF_PDM(ip)\ 25962306a36Sopenharmony_ci ((ip)->pdata->conf.has_spdif_pdm) 26062306a36Sopenharmony_ci 26162306a36Sopenharmony_cienum stm32_sai_syncout { 26262306a36Sopenharmony_ci STM_SAI_SYNC_OUT_NONE, 26362306a36Sopenharmony_ci STM_SAI_SYNC_OUT_A, 26462306a36Sopenharmony_ci STM_SAI_SYNC_OUT_B, 26562306a36Sopenharmony_ci}; 26662306a36Sopenharmony_ci 26762306a36Sopenharmony_ci/** 26862306a36Sopenharmony_ci * struct stm32_sai_conf - SAI configuration 26962306a36Sopenharmony_ci * @version: SAI version 27062306a36Sopenharmony_ci * @fifo_size: SAI fifo size as words number 27162306a36Sopenharmony_ci * @has_spdif_pdm: SAI S/PDIF and PDM features support flag 27262306a36Sopenharmony_ci */ 27362306a36Sopenharmony_cistruct stm32_sai_conf { 27462306a36Sopenharmony_ci u32 version; 27562306a36Sopenharmony_ci u32 fifo_size; 27662306a36Sopenharmony_ci bool has_spdif_pdm; 27762306a36Sopenharmony_ci}; 27862306a36Sopenharmony_ci 27962306a36Sopenharmony_ci/** 28062306a36Sopenharmony_ci * struct stm32_sai_data - private data of SAI instance driver 28162306a36Sopenharmony_ci * @pdev: device data pointer 28262306a36Sopenharmony_ci * @base: common register bank virtual base address 28362306a36Sopenharmony_ci * @pclk: SAI bus clock 28462306a36Sopenharmony_ci * @clk_x8k: SAI parent clock for sampling frequencies multiple of 8kHz 28562306a36Sopenharmony_ci * @clk_x11k: SAI parent clock for sampling frequencies multiple of 11kHz 28662306a36Sopenharmony_ci * @conf: SAI hardware capabitilites 28762306a36Sopenharmony_ci * @irq: SAI interrupt line 28862306a36Sopenharmony_ci * @set_sync: pointer to synchro mode configuration callback 28962306a36Sopenharmony_ci * @gcr: SAI Global Configuration Register 29062306a36Sopenharmony_ci */ 29162306a36Sopenharmony_cistruct stm32_sai_data { 29262306a36Sopenharmony_ci struct platform_device *pdev; 29362306a36Sopenharmony_ci void __iomem *base; 29462306a36Sopenharmony_ci struct clk *pclk; 29562306a36Sopenharmony_ci struct clk *clk_x8k; 29662306a36Sopenharmony_ci struct clk *clk_x11k; 29762306a36Sopenharmony_ci struct stm32_sai_conf conf; 29862306a36Sopenharmony_ci int irq; 29962306a36Sopenharmony_ci int (*set_sync)(struct stm32_sai_data *sai, 30062306a36Sopenharmony_ci struct device_node *np_provider, int synco, int synci); 30162306a36Sopenharmony_ci u32 gcr; 30262306a36Sopenharmony_ci}; 303