162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * fsl_spdif.h - ALSA S/PDIF interface for the Freescale i.MX SoC 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2013 Freescale Semiconductor, Inc. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Author: Nicolin Chen <b42378@freescale.com> 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * Based on fsl_ssi.h 1062306a36Sopenharmony_ci * Author: Timur Tabi <timur@freescale.com> 1162306a36Sopenharmony_ci * Copyright 2007-2008 Freescale Semiconductor, Inc. 1262306a36Sopenharmony_ci */ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#ifndef _FSL_SPDIF_DAI_H 1562306a36Sopenharmony_ci#define _FSL_SPDIF_DAI_H 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci/* S/PDIF Register Map */ 1862306a36Sopenharmony_ci#define REG_SPDIF_SCR 0x0 /* SPDIF Configuration Register */ 1962306a36Sopenharmony_ci#define REG_SPDIF_SRCD 0x4 /* CDText Control Register */ 2062306a36Sopenharmony_ci#define REG_SPDIF_SRPC 0x8 /* PhaseConfig Register */ 2162306a36Sopenharmony_ci#define REG_SPDIF_SIE 0xc /* InterruptEn Register */ 2262306a36Sopenharmony_ci#define REG_SPDIF_SIS 0x10 /* InterruptStat Register */ 2362306a36Sopenharmony_ci#define REG_SPDIF_SIC 0x10 /* InterruptClear Register */ 2462306a36Sopenharmony_ci#define REG_SPDIF_SRL 0x14 /* SPDIFRxLeft Register */ 2562306a36Sopenharmony_ci#define REG_SPDIF_SRR 0x18 /* SPDIFRxRight Register */ 2662306a36Sopenharmony_ci#define REG_SPDIF_SRCSH 0x1c /* SPDIFRxCChannel_h Register */ 2762306a36Sopenharmony_ci#define REG_SPDIF_SRCSL 0x20 /* SPDIFRxCChannel_l Register */ 2862306a36Sopenharmony_ci#define REG_SPDIF_SRU 0x24 /* UchannelRx Register */ 2962306a36Sopenharmony_ci#define REG_SPDIF_SRQ 0x28 /* QchannelRx Register */ 3062306a36Sopenharmony_ci#define REG_SPDIF_STL 0x2C /* SPDIFTxLeft Register */ 3162306a36Sopenharmony_ci#define REG_SPDIF_STR 0x30 /* SPDIFTxRight Register */ 3262306a36Sopenharmony_ci#define REG_SPDIF_STCSCH 0x34 /* SPDIFTxCChannelCons_h Register */ 3362306a36Sopenharmony_ci#define REG_SPDIF_STCSCL 0x38 /* SPDIFTxCChannelCons_l Register */ 3462306a36Sopenharmony_ci#define REG_SPDIF_STCSPH 0x3C /* SPDIFTxCChannel_Prof_h Register */ 3562306a36Sopenharmony_ci#define REG_SPDIF_STCSPL 0x40 /* SPDIFTxCChannel_Prof_l Register */ 3662306a36Sopenharmony_ci#define REG_SPDIF_SRFM 0x44 /* FreqMeas Register */ 3762306a36Sopenharmony_ci#define REG_SPDIF_STC 0x50 /* SPDIFTxClk Register */ 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci#define REG_SPDIF_SRCCA_31_0 0x60 /* SPDIF receive C channel register, bits 31-0 */ 4062306a36Sopenharmony_ci#define REG_SPDIF_SRCCA_63_32 0x64 /* SPDIF receive C channel register, bits 63-32 */ 4162306a36Sopenharmony_ci#define REG_SPDIF_SRCCA_95_64 0x68 /* SPDIF receive C channel register, bits 95-64 */ 4262306a36Sopenharmony_ci#define REG_SPDIF_SRCCA_127_96 0x6C /* SPDIF receive C channel register, bits 127-96 */ 4362306a36Sopenharmony_ci#define REG_SPDIF_SRCCA_159_128 0x70 /* SPDIF receive C channel register, bits 159-128 */ 4462306a36Sopenharmony_ci#define REG_SPDIF_SRCCA_191_160 0x74 /* SPDIF receive C channel register, bits 191-160 */ 4562306a36Sopenharmony_ci#define REG_SPDIF_STCCA_31_0 0x78 /* SPDIF transmit C channel register, bits 31-0 */ 4662306a36Sopenharmony_ci#define REG_SPDIF_STCCA_63_32 0x7C /* SPDIF transmit C channel register, bits 63-32 */ 4762306a36Sopenharmony_ci#define REG_SPDIF_STCCA_95_64 0x80 /* SPDIF transmit C channel register, bits 95-64 */ 4862306a36Sopenharmony_ci#define REG_SPDIF_STCCA_127_96 0x84 /* SPDIF transmit C channel register, bits 127-96 */ 4962306a36Sopenharmony_ci#define REG_SPDIF_STCCA_159_128 0x88 /* SPDIF transmit C channel register, bits 159-128 */ 5062306a36Sopenharmony_ci#define REG_SPDIF_STCCA_191_160 0x8C /* SPDIF transmit C channel register, bits 191-160 */ 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci/* SPDIF Configuration register */ 5362306a36Sopenharmony_ci#define SCR_RXFIFO_CTL_OFFSET 23 5462306a36Sopenharmony_ci#define SCR_RXFIFO_CTL_MASK (1 << SCR_RXFIFO_CTL_OFFSET) 5562306a36Sopenharmony_ci#define SCR_RXFIFO_CTL_ZERO (1 << SCR_RXFIFO_CTL_OFFSET) 5662306a36Sopenharmony_ci#define SCR_RXFIFO_OFF_OFFSET 22 5762306a36Sopenharmony_ci#define SCR_RXFIFO_OFF_MASK (1 << SCR_RXFIFO_OFF_OFFSET) 5862306a36Sopenharmony_ci#define SCR_RXFIFO_OFF (1 << SCR_RXFIFO_OFF_OFFSET) 5962306a36Sopenharmony_ci#define SCR_RXFIFO_RST_OFFSET 21 6062306a36Sopenharmony_ci#define SCR_RXFIFO_RST_MASK (1 << SCR_RXFIFO_RST_OFFSET) 6162306a36Sopenharmony_ci#define SCR_RXFIFO_RST (1 << SCR_RXFIFO_RST_OFFSET) 6262306a36Sopenharmony_ci#define SCR_RXFIFO_FSEL_OFFSET 19 6362306a36Sopenharmony_ci#define SCR_RXFIFO_FSEL_MASK (0x3 << SCR_RXFIFO_FSEL_OFFSET) 6462306a36Sopenharmony_ci#define SCR_RXFIFO_FSEL_IF0 (0x0 << SCR_RXFIFO_FSEL_OFFSET) 6562306a36Sopenharmony_ci#define SCR_RXFIFO_FSEL_IF4 (0x1 << SCR_RXFIFO_FSEL_OFFSET) 6662306a36Sopenharmony_ci#define SCR_RXFIFO_FSEL_IF8 (0x2 << SCR_RXFIFO_FSEL_OFFSET) 6762306a36Sopenharmony_ci#define SCR_RXFIFO_FSEL_IF12 (0x3 << SCR_RXFIFO_FSEL_OFFSET) 6862306a36Sopenharmony_ci#define SCR_RXFIFO_AUTOSYNC_OFFSET 18 6962306a36Sopenharmony_ci#define SCR_RXFIFO_AUTOSYNC_MASK (1 << SCR_RXFIFO_AUTOSYNC_OFFSET) 7062306a36Sopenharmony_ci#define SCR_RXFIFO_AUTOSYNC (1 << SCR_RXFIFO_AUTOSYNC_OFFSET) 7162306a36Sopenharmony_ci#define SCR_TXFIFO_AUTOSYNC_OFFSET 17 7262306a36Sopenharmony_ci#define SCR_TXFIFO_AUTOSYNC_MASK (1 << SCR_TXFIFO_AUTOSYNC_OFFSET) 7362306a36Sopenharmony_ci#define SCR_TXFIFO_AUTOSYNC (1 << SCR_TXFIFO_AUTOSYNC_OFFSET) 7462306a36Sopenharmony_ci#define SCR_TXFIFO_FSEL_OFFSET 15 7562306a36Sopenharmony_ci#define SCR_TXFIFO_FSEL_MASK (0x3 << SCR_TXFIFO_FSEL_OFFSET) 7662306a36Sopenharmony_ci#define SCR_TXFIFO_FSEL_IF0 (0x0 << SCR_TXFIFO_FSEL_OFFSET) 7762306a36Sopenharmony_ci#define SCR_TXFIFO_FSEL_IF4 (0x1 << SCR_TXFIFO_FSEL_OFFSET) 7862306a36Sopenharmony_ci#define SCR_TXFIFO_FSEL_IF8 (0x2 << SCR_TXFIFO_FSEL_OFFSET) 7962306a36Sopenharmony_ci#define SCR_TXFIFO_FSEL_IF12 (0x3 << SCR_TXFIFO_FSEL_OFFSET) 8062306a36Sopenharmony_ci#define SCR_RAW_CAPTURE_MODE BIT(14) 8162306a36Sopenharmony_ci#define SCR_LOW_POWER (1 << 13) 8262306a36Sopenharmony_ci#define SCR_SOFT_RESET (1 << 12) 8362306a36Sopenharmony_ci#define SCR_TXFIFO_CTRL_OFFSET 10 8462306a36Sopenharmony_ci#define SCR_TXFIFO_CTRL_MASK (0x3 << SCR_TXFIFO_CTRL_OFFSET) 8562306a36Sopenharmony_ci#define SCR_TXFIFO_CTRL_ZERO (0x0 << SCR_TXFIFO_CTRL_OFFSET) 8662306a36Sopenharmony_ci#define SCR_TXFIFO_CTRL_NORMAL (0x1 << SCR_TXFIFO_CTRL_OFFSET) 8762306a36Sopenharmony_ci#define SCR_TXFIFO_CTRL_ONESAMPLE (0x2 << SCR_TXFIFO_CTRL_OFFSET) 8862306a36Sopenharmony_ci#define SCR_DMA_RX_EN_OFFSET 9 8962306a36Sopenharmony_ci#define SCR_DMA_RX_EN_MASK (1 << SCR_DMA_RX_EN_OFFSET) 9062306a36Sopenharmony_ci#define SCR_DMA_RX_EN (1 << SCR_DMA_RX_EN_OFFSET) 9162306a36Sopenharmony_ci#define SCR_DMA_TX_EN_OFFSET 8 9262306a36Sopenharmony_ci#define SCR_DMA_TX_EN_MASK (1 << SCR_DMA_TX_EN_OFFSET) 9362306a36Sopenharmony_ci#define SCR_DMA_TX_EN (1 << SCR_DMA_TX_EN_OFFSET) 9462306a36Sopenharmony_ci#define SCR_VAL_OFFSET 5 9562306a36Sopenharmony_ci#define SCR_VAL_MASK (1 << SCR_VAL_OFFSET) 9662306a36Sopenharmony_ci#define SCR_VAL_CLEAR (1 << SCR_VAL_OFFSET) 9762306a36Sopenharmony_ci#define SCR_TXSEL_OFFSET 2 9862306a36Sopenharmony_ci#define SCR_TXSEL_MASK (0x7 << SCR_TXSEL_OFFSET) 9962306a36Sopenharmony_ci#define SCR_TXSEL_OFF (0 << SCR_TXSEL_OFFSET) 10062306a36Sopenharmony_ci#define SCR_TXSEL_RX (1 << SCR_TXSEL_OFFSET) 10162306a36Sopenharmony_ci#define SCR_TXSEL_NORMAL (0x5 << SCR_TXSEL_OFFSET) 10262306a36Sopenharmony_ci#define SCR_USRC_SEL_OFFSET 0x0 10362306a36Sopenharmony_ci#define SCR_USRC_SEL_MASK (0x3 << SCR_USRC_SEL_OFFSET) 10462306a36Sopenharmony_ci#define SCR_USRC_SEL_NONE (0x0 << SCR_USRC_SEL_OFFSET) 10562306a36Sopenharmony_ci#define SCR_USRC_SEL_RECV (0x1 << SCR_USRC_SEL_OFFSET) 10662306a36Sopenharmony_ci#define SCR_USRC_SEL_CHIP (0x3 << SCR_USRC_SEL_OFFSET) 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci#define SCR_DMA_xX_EN(tx) (tx ? SCR_DMA_TX_EN : SCR_DMA_RX_EN) 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci/* SPDIF CDText control */ 11162306a36Sopenharmony_ci#define SRCD_CD_USER_OFFSET 1 11262306a36Sopenharmony_ci#define SRCD_CD_USER (1 << SRCD_CD_USER_OFFSET) 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci/* SPDIF Phase Configuration register */ 11562306a36Sopenharmony_ci#define SRPC_DPLL_LOCKED (1 << 6) 11662306a36Sopenharmony_ci#define SRPC_CLKSRC_SEL_OFFSET 7 11762306a36Sopenharmony_ci#define SRPC_CLKSRC_SEL_MASK (0xf << SRPC_CLKSRC_SEL_OFFSET) 11862306a36Sopenharmony_ci#define SRPC_CLKSRC_SEL_SET(x) ((x << SRPC_CLKSRC_SEL_OFFSET) & SRPC_CLKSRC_SEL_MASK) 11962306a36Sopenharmony_ci#define SRPC_CLKSRC_SEL_LOCKED_OFFSET1 5 12062306a36Sopenharmony_ci#define SRPC_CLKSRC_SEL_LOCKED_OFFSET2 2 12162306a36Sopenharmony_ci#define SRPC_GAINSEL_OFFSET 3 12262306a36Sopenharmony_ci#define SRPC_GAINSEL_MASK (0x7 << SRPC_GAINSEL_OFFSET) 12362306a36Sopenharmony_ci#define SRPC_GAINSEL_SET(x) ((x << SRPC_GAINSEL_OFFSET) & SRPC_GAINSEL_MASK) 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci#define SRPC_CLKSRC_MAX 16 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_cienum spdif_gainsel { 12862306a36Sopenharmony_ci GAINSEL_MULTI_24 = 0, 12962306a36Sopenharmony_ci GAINSEL_MULTI_16, 13062306a36Sopenharmony_ci GAINSEL_MULTI_12, 13162306a36Sopenharmony_ci GAINSEL_MULTI_8, 13262306a36Sopenharmony_ci GAINSEL_MULTI_6, 13362306a36Sopenharmony_ci GAINSEL_MULTI_4, 13462306a36Sopenharmony_ci GAINSEL_MULTI_3, 13562306a36Sopenharmony_ci}; 13662306a36Sopenharmony_ci#define GAINSEL_MULTI_MAX (GAINSEL_MULTI_3 + 1) 13762306a36Sopenharmony_ci#define SPDIF_DEFAULT_GAINSEL GAINSEL_MULTI_8 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci/* SPDIF interrupt mask define */ 14062306a36Sopenharmony_ci#define INT_DPLL_LOCKED (1 << 20) 14162306a36Sopenharmony_ci#define INT_TXFIFO_UNOV (1 << 19) 14262306a36Sopenharmony_ci#define INT_TXFIFO_RESYNC (1 << 18) 14362306a36Sopenharmony_ci#define INT_CNEW (1 << 17) 14462306a36Sopenharmony_ci#define INT_VAL_NOGOOD (1 << 16) 14562306a36Sopenharmony_ci#define INT_SYM_ERR (1 << 15) 14662306a36Sopenharmony_ci#define INT_BIT_ERR (1 << 14) 14762306a36Sopenharmony_ci#define INT_URX_FUL (1 << 10) 14862306a36Sopenharmony_ci#define INT_URX_OV (1 << 9) 14962306a36Sopenharmony_ci#define INT_QRX_FUL (1 << 8) 15062306a36Sopenharmony_ci#define INT_QRX_OV (1 << 7) 15162306a36Sopenharmony_ci#define INT_UQ_SYNC (1 << 6) 15262306a36Sopenharmony_ci#define INT_UQ_ERR (1 << 5) 15362306a36Sopenharmony_ci#define INT_RXFIFO_UNOV (1 << 4) 15462306a36Sopenharmony_ci#define INT_RXFIFO_RESYNC (1 << 3) 15562306a36Sopenharmony_ci#define INT_LOSS_LOCK (1 << 2) 15662306a36Sopenharmony_ci#define INT_TX_EM (1 << 1) 15762306a36Sopenharmony_ci#define INT_RXFIFO_FUL (1 << 0) 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci/* SPDIF Clock register */ 16062306a36Sopenharmony_ci#define STC_SYSCLK_DF_OFFSET 11 16162306a36Sopenharmony_ci#define STC_SYSCLK_DF_MASK (0x1ff << STC_SYSCLK_DF_OFFSET) 16262306a36Sopenharmony_ci#define STC_SYSCLK_DF(x) ((((x) - 1) << STC_SYSCLK_DF_OFFSET) & STC_SYSCLK_DF_MASK) 16362306a36Sopenharmony_ci#define STC_TXCLK_SRC_OFFSET 8 16462306a36Sopenharmony_ci#define STC_TXCLK_SRC_MASK (0x7 << STC_TXCLK_SRC_OFFSET) 16562306a36Sopenharmony_ci#define STC_TXCLK_SRC_SET(x) ((x << STC_TXCLK_SRC_OFFSET) & STC_TXCLK_SRC_MASK) 16662306a36Sopenharmony_ci#define STC_TXCLK_ALL_EN_OFFSET 7 16762306a36Sopenharmony_ci#define STC_TXCLK_ALL_EN_MASK (1 << STC_TXCLK_ALL_EN_OFFSET) 16862306a36Sopenharmony_ci#define STC_TXCLK_ALL_EN (1 << STC_TXCLK_ALL_EN_OFFSET) 16962306a36Sopenharmony_ci#define STC_TXCLK_DF_OFFSET 0 17062306a36Sopenharmony_ci#define STC_TXCLK_DF_MASK (0x7f << STC_TXCLK_DF_OFFSET) 17162306a36Sopenharmony_ci#define STC_TXCLK_DF(x) ((((x) - 1) << STC_TXCLK_DF_OFFSET) & STC_TXCLK_DF_MASK) 17262306a36Sopenharmony_ci#define STC_TXCLK_SRC_MAX 8 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci#define STC_TXCLK_SPDIF_ROOT 1 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci/* SPDIF tx rate */ 17762306a36Sopenharmony_cienum spdif_txrate { 17862306a36Sopenharmony_ci SPDIF_TXRATE_22050 = 0, 17962306a36Sopenharmony_ci SPDIF_TXRATE_32000, 18062306a36Sopenharmony_ci SPDIF_TXRATE_44100, 18162306a36Sopenharmony_ci SPDIF_TXRATE_48000, 18262306a36Sopenharmony_ci SPDIF_TXRATE_88200, 18362306a36Sopenharmony_ci SPDIF_TXRATE_96000, 18462306a36Sopenharmony_ci SPDIF_TXRATE_176400, 18562306a36Sopenharmony_ci SPDIF_TXRATE_192000, 18662306a36Sopenharmony_ci}; 18762306a36Sopenharmony_ci#define SPDIF_TXRATE_MAX (SPDIF_TXRATE_192000 + 1) 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ci#define SPDIF_CSTATUS_BYTE 6 19162306a36Sopenharmony_ci#define SPDIF_UBITS_SIZE 96 19262306a36Sopenharmony_ci#define SPDIF_QSUB_SIZE (SPDIF_UBITS_SIZE / 8) 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci 19562306a36Sopenharmony_ci#define FSL_SPDIF_RATES_PLAYBACK (SNDRV_PCM_RATE_22050 | \ 19662306a36Sopenharmony_ci SNDRV_PCM_RATE_32000 | \ 19762306a36Sopenharmony_ci SNDRV_PCM_RATE_44100 | \ 19862306a36Sopenharmony_ci SNDRV_PCM_RATE_48000 | \ 19962306a36Sopenharmony_ci SNDRV_PCM_RATE_88200 | \ 20062306a36Sopenharmony_ci SNDRV_PCM_RATE_96000 | \ 20162306a36Sopenharmony_ci SNDRV_PCM_RATE_176400 | \ 20262306a36Sopenharmony_ci SNDRV_PCM_RATE_192000) 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_ci#define FSL_SPDIF_RATES_CAPTURE (SNDRV_PCM_RATE_16000 | \ 20562306a36Sopenharmony_ci SNDRV_PCM_RATE_32000 | \ 20662306a36Sopenharmony_ci SNDRV_PCM_RATE_44100 | \ 20762306a36Sopenharmony_ci SNDRV_PCM_RATE_48000 | \ 20862306a36Sopenharmony_ci SNDRV_PCM_RATE_88200 | \ 20962306a36Sopenharmony_ci SNDRV_PCM_RATE_64000 | \ 21062306a36Sopenharmony_ci SNDRV_PCM_RATE_96000 | \ 21162306a36Sopenharmony_ci SNDRV_PCM_RATE_176400 | \ 21262306a36Sopenharmony_ci SNDRV_PCM_RATE_192000) 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ci#define FSL_SPDIF_FORMATS_PLAYBACK (SNDRV_PCM_FMTBIT_S16_LE | \ 21562306a36Sopenharmony_ci SNDRV_PCM_FMTBIT_S20_3LE | \ 21662306a36Sopenharmony_ci SNDRV_PCM_FMTBIT_S24_LE) 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ci#define FSL_SPDIF_FORMATS_CAPTURE (SNDRV_PCM_FMTBIT_S24_LE) 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_ci#endif /* _FSL_SPDIF_DAI_H */ 221