162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Intel KeemBay Platform driver 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2020 Intel Corporation. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci */ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#ifndef KMB_PLATFORM_H_ 1062306a36Sopenharmony_ci#define KMB_PLATFORM_H_ 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include <linux/bits.h> 1362306a36Sopenharmony_ci#include <linux/bitfield.h> 1462306a36Sopenharmony_ci#include <linux/types.h> 1562306a36Sopenharmony_ci#include <sound/dmaengine_pcm.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci/* Register values with reference to KMB databook v1.1 */ 1862306a36Sopenharmony_ci/* common register for all channel */ 1962306a36Sopenharmony_ci#define IER 0x000 2062306a36Sopenharmony_ci#define IRER 0x004 2162306a36Sopenharmony_ci#define ITER 0x008 2262306a36Sopenharmony_ci#define CER 0x00C 2362306a36Sopenharmony_ci#define CCR 0x010 2462306a36Sopenharmony_ci#define RXFFR 0x014 2562306a36Sopenharmony_ci#define TXFFR 0x018 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* Interrupt status register fields */ 2862306a36Sopenharmony_ci#define ISR_TXFO BIT(5) 2962306a36Sopenharmony_ci#define ISR_TXFE BIT(4) 3062306a36Sopenharmony_ci#define ISR_RXFO BIT(1) 3162306a36Sopenharmony_ci#define ISR_RXDA BIT(0) 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci/* I2S Tx Rx Registers for all channels */ 3462306a36Sopenharmony_ci#define LRBR_LTHR(x) (0x40 * (x) + 0x020) 3562306a36Sopenharmony_ci#define RRBR_RTHR(x) (0x40 * (x) + 0x024) 3662306a36Sopenharmony_ci#define RER(x) (0x40 * (x) + 0x028) 3762306a36Sopenharmony_ci#define TER(x) (0x40 * (x) + 0x02C) 3862306a36Sopenharmony_ci#define RCR(x) (0x40 * (x) + 0x030) 3962306a36Sopenharmony_ci#define TCR(x) (0x40 * (x) + 0x034) 4062306a36Sopenharmony_ci#define ISR(x) (0x40 * (x) + 0x038) 4162306a36Sopenharmony_ci#define IMR(x) (0x40 * (x) + 0x03C) 4262306a36Sopenharmony_ci#define ROR(x) (0x40 * (x) + 0x040) 4362306a36Sopenharmony_ci#define TOR(x) (0x40 * (x) + 0x044) 4462306a36Sopenharmony_ci#define RFCR(x) (0x40 * (x) + 0x048) 4562306a36Sopenharmony_ci#define TFCR(x) (0x40 * (x) + 0x04C) 4662306a36Sopenharmony_ci#define RFF(x) (0x40 * (x) + 0x050) 4762306a36Sopenharmony_ci#define TFF(x) (0x40 * (x) + 0x054) 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci/* I2S COMP Registers */ 5062306a36Sopenharmony_ci#define I2S_COMP_PARAM_2 0x01F0 5162306a36Sopenharmony_ci#define I2S_COMP_PARAM_1 0x01F4 5262306a36Sopenharmony_ci#define I2S_COMP_VERSION 0x01F8 5362306a36Sopenharmony_ci#define I2S_COMP_TYPE 0x01FC 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci/* PSS_GEN_CTRL_I2S_GEN_CFG_0 Registers */ 5662306a36Sopenharmony_ci#define I2S_GEN_CFG_0 0x000 5762306a36Sopenharmony_ci#define PSS_CPR_RST_EN 0x010 5862306a36Sopenharmony_ci#define PSS_CPR_RST_SET 0x014 5962306a36Sopenharmony_ci#define PSS_CPR_CLK_CLR 0x000 6062306a36Sopenharmony_ci#define PSS_CPR_AUX_RST_EN 0x070 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci#define CLOCK_PROVIDER_MODE BIT(13) 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci/* Interrupt Flag */ 6562306a36Sopenharmony_ci#define TX_INT_FLAG GENMASK(5, 4) 6662306a36Sopenharmony_ci#define RX_INT_FLAG GENMASK(1, 0) 6762306a36Sopenharmony_ci/* 6862306a36Sopenharmony_ci * Component parameter register fields - define the I2S block's 6962306a36Sopenharmony_ci * configuration. 7062306a36Sopenharmony_ci */ 7162306a36Sopenharmony_ci#define COMP1_TX_WORDSIZE_3(r) FIELD_GET(GENMASK(27, 25), (r)) 7262306a36Sopenharmony_ci#define COMP1_TX_WORDSIZE_2(r) FIELD_GET(GENMASK(24, 22), (r)) 7362306a36Sopenharmony_ci#define COMP1_TX_WORDSIZE_1(r) FIELD_GET(GENMASK(21, 19), (r)) 7462306a36Sopenharmony_ci#define COMP1_TX_WORDSIZE_0(r) FIELD_GET(GENMASK(18, 16), (r)) 7562306a36Sopenharmony_ci#define COMP1_RX_ENABLED(r) FIELD_GET(BIT(6), (r)) 7662306a36Sopenharmony_ci#define COMP1_TX_ENABLED(r) FIELD_GET(BIT(5), (r)) 7762306a36Sopenharmony_ci#define COMP1_MODE_EN(r) FIELD_GET(BIT(4), (r)) 7862306a36Sopenharmony_ci#define COMP1_APB_DATA_WIDTH(r) FIELD_GET(GENMASK(1, 0), (r)) 7962306a36Sopenharmony_ci#define COMP2_RX_WORDSIZE_3(r) FIELD_GET(GENMASK(12, 10), (r)) 8062306a36Sopenharmony_ci#define COMP2_RX_WORDSIZE_2(r) FIELD_GET(GENMASK(9, 7), (r)) 8162306a36Sopenharmony_ci#define COMP2_RX_WORDSIZE_1(r) FIELD_GET(GENMASK(5, 3), (r)) 8262306a36Sopenharmony_ci#define COMP2_RX_WORDSIZE_0(r) FIELD_GET(GENMASK(2, 0), (r)) 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci/* Add 1 to the below registers to indicate the actual size */ 8562306a36Sopenharmony_ci#define COMP1_TX_CHANNELS(r) (FIELD_GET(GENMASK(10, 9), (r)) + 1) 8662306a36Sopenharmony_ci#define COMP1_RX_CHANNELS(r) (FIELD_GET(GENMASK(8, 7), (r)) + 1) 8762306a36Sopenharmony_ci#define COMP1_FIFO_DEPTH(r) (FIELD_GET(GENMASK(3, 2), (r)) + 1) 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci/* Number of entries in WORDSIZE and DATA_WIDTH parameter registers */ 9062306a36Sopenharmony_ci#define COMP_MAX_WORDSIZE 8 /* 3 bits register width */ 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci#define MAX_CHANNEL_NUM 8 9362306a36Sopenharmony_ci#define MIN_CHANNEL_NUM 2 9462306a36Sopenharmony_ci#define MAX_ISR 4 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci#define TWO_CHANNEL_SUPPORT 2 /* up to 2.0 */ 9762306a36Sopenharmony_ci#define FOUR_CHANNEL_SUPPORT 4 /* up to 3.1 */ 9862306a36Sopenharmony_ci#define SIX_CHANNEL_SUPPORT 6 /* up to 5.1 */ 9962306a36Sopenharmony_ci#define EIGHT_CHANNEL_SUPPORT 8 /* up to 7.1 */ 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci#define DWC_I2S_PLAY BIT(0) 10262306a36Sopenharmony_ci#define DWC_I2S_RECORD BIT(1) 10362306a36Sopenharmony_ci#define DW_I2S_CONSUMER BIT(2) 10462306a36Sopenharmony_ci#define DW_I2S_PROVIDER BIT(3) 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci#define I2S_RXDMA 0x01C0 10762306a36Sopenharmony_ci#define I2S_RRXDMA 0x01C4 10862306a36Sopenharmony_ci#define I2S_TXDMA 0x01C8 10962306a36Sopenharmony_ci#define I2S_RTXDMA 0x01CC 11062306a36Sopenharmony_ci#define I2S_DMACR 0x0200 11162306a36Sopenharmony_ci#define I2S_DMAEN_RXBLOCK (1 << 16) 11262306a36Sopenharmony_ci#define I2S_DMAEN_TXBLOCK (1 << 17) 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci/* 11562306a36Sopenharmony_ci * struct i2s_clk_config_data - represent i2s clk configuration data 11662306a36Sopenharmony_ci * @chan_nr: number of channel 11762306a36Sopenharmony_ci * @data_width: number of bits per sample (8/16/24/32 bit) 11862306a36Sopenharmony_ci * @sample_rate: sampling frequency (8Khz, 16Khz, 48Khz) 11962306a36Sopenharmony_ci */ 12062306a36Sopenharmony_cistruct i2s_clk_config_data { 12162306a36Sopenharmony_ci int chan_nr; 12262306a36Sopenharmony_ci u32 data_width; 12362306a36Sopenharmony_ci u32 sample_rate; 12462306a36Sopenharmony_ci}; 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_cistruct kmb_i2s_info { 12762306a36Sopenharmony_ci void __iomem *i2s_base; 12862306a36Sopenharmony_ci void __iomem *pss_base; 12962306a36Sopenharmony_ci struct clk *clk_i2s; 13062306a36Sopenharmony_ci struct clk *clk_apb; 13162306a36Sopenharmony_ci int active; 13262306a36Sopenharmony_ci unsigned int capability; 13362306a36Sopenharmony_ci unsigned int i2s_reg_comp1; 13462306a36Sopenharmony_ci unsigned int i2s_reg_comp2; 13562306a36Sopenharmony_ci struct device *dev; 13662306a36Sopenharmony_ci u32 ccr; 13762306a36Sopenharmony_ci u32 xfer_resolution; 13862306a36Sopenharmony_ci u32 fifo_th; 13962306a36Sopenharmony_ci bool clock_provider; 14062306a36Sopenharmony_ci /* data related to DMA transfers b/w i2s and DMAC */ 14162306a36Sopenharmony_ci struct snd_dmaengine_dai_dma_data play_dma_data; 14262306a36Sopenharmony_ci struct snd_dmaengine_dai_dma_data capture_dma_data; 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci struct i2s_clk_config_data config; 14562306a36Sopenharmony_ci int (*i2s_clk_cfg)(struct i2s_clk_config_data *config); 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci /* data related to PIO transfers */ 14862306a36Sopenharmony_ci bool use_pio; 14962306a36Sopenharmony_ci struct snd_pcm_substream *tx_substream; 15062306a36Sopenharmony_ci struct snd_pcm_substream *rx_substream; 15162306a36Sopenharmony_ci unsigned int tx_ptr; 15262306a36Sopenharmony_ci unsigned int rx_ptr; 15362306a36Sopenharmony_ci bool iec958_fmt; 15462306a36Sopenharmony_ci}; 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci#endif /* KMB_PLATFORM_H_ */ 157