Merge branch 'CR_1843_515_I2S_vol_Xingyu.Wu' into 'jh7110-5.15.y-devel'
[platform/kernel/linux-starfive.git] / sound / soc / dwc / i2srx-master.h
1 /*
2  * Copyright (ST) 2012 Rajeev Kumar (rajeevkumar.linux@gmail.com)
3  *
4  * This file is licensed under the terms of the GNU General Public
5  * License version 2. This program is licensed "as is" without any
6  * warranty of any kind, whether express or implied.
7  */
8
9 #ifndef __DESIGNWARE_LOCAL_H
10 #define __DESIGNWARE_LOCAL_H
11
12 #include <linux/clk.h>
13 #include <linux/device.h>
14 #include <linux/types.h>
15 #include <sound/dmaengine_pcm.h>
16 #include <sound/pcm.h>
17 #include <sound/designware_i2s.h>
18
19 /* common register for all channel */
20 #define IER             0x000
21 #define IRER            0x004
22 #define ITER            0x008
23 #define CER             0x00C
24 #define CCR             0x010
25 #define RXFFR           0x014
26 #define TXFFR           0x018
27
28 /* Interrupt status register fields */
29 #define ISR_TXFO        BIT(5)
30 #define ISR_TXFE        BIT(4)
31 #define ISR_RXFO        BIT(1)
32 #define ISR_RXDA        BIT(0)
33
34 /* I2STxRxRegisters for all channels */
35 #define LRBR_LTHR(x)    (0x40 * x + 0x020)
36 #define RRBR_RTHR(x)    (0x40 * x + 0x024)
37 #define RER(x)          (0x40 * x + 0x028)
38 #define TER(x)          (0x40 * x + 0x02C)
39 #define RCR(x)          (0x40 * x + 0x030)
40 #define TCR(x)          (0x40 * x + 0x034)
41 #define ISR(x)          (0x40 * x + 0x038)
42 #define IMR(x)          (0x40 * x + 0x03C)
43 #define ROR(x)          (0x40 * x + 0x040)
44 #define TOR(x)          (0x40 * x + 0x044)
45 #define RFCR(x)         (0x40 * x + 0x048)
46 #define TFCR(x)         (0x40 * x + 0x04C)
47 #define RFF(x)          (0x40 * x + 0x050)
48 #define TFF(x)          (0x40 * x + 0x054)
49
50 /* I2SCOMPRegisters */
51 #define I2S_COMP_PARAM_2        0x01F0
52 #define I2S_COMP_PARAM_1        0x01F4
53 #define I2S_COMP_VERSION        0x01F8
54 #define I2S_COMP_TYPE           0x01FC
55
56 /*
57  * Component parameter register fields - define the I2S block's
58  * configuration.
59  */
60 #define COMP1_TX_WORDSIZE_3(r)  (((r) & GENMASK(27, 25)) >> 25)
61 #define COMP1_TX_WORDSIZE_2(r)  (((r) & GENMASK(24, 22)) >> 22)
62 #define COMP1_TX_WORDSIZE_1(r)  (((r) & GENMASK(21, 19)) >> 19)
63 #define COMP1_TX_WORDSIZE_0(r)  (((r) & GENMASK(18, 16)) >> 16)
64 #define COMP1_TX_CHANNELS(r)    (((r) & GENMASK(10, 9)) >> 9)
65 #define COMP1_RX_CHANNELS(r)    (((r) & GENMASK(8, 7)) >> 7)
66 #define COMP1_RX_ENABLED(r)     (((r) & BIT(6)) >> 6)
67 #define COMP1_TX_ENABLED(r)     (((r) & BIT(5)) >> 5)
68 #define COMP1_MODE_EN(r)        (((r) & BIT(4)) >> 4)
69 #define COMP1_FIFO_DEPTH_GLOBAL(r)      (((r) & GENMASK(3, 2)) >> 2)
70 #define COMP1_APB_DATA_WIDTH(r) (((r) & GENMASK(1, 0)) >> 0)
71
72 #define COMP2_RX_WORDSIZE_3(r)  (((r) & GENMASK(12, 10)) >> 10)
73 #define COMP2_RX_WORDSIZE_2(r)  (((r) & GENMASK(9, 7)) >> 7)
74 #define COMP2_RX_WORDSIZE_1(r)  (((r) & GENMASK(5, 3)) >> 3)
75 #define COMP2_RX_WORDSIZE_0(r)  (((r) & GENMASK(2, 0)) >> 0)
76
77 /* Number of entries in WORDSIZE and DATA_WIDTH parameter registers */
78 #define COMP_MAX_WORDSIZE       (1 << 3)
79 #define COMP_MAX_DATA_WIDTH     (1 << 2)
80
81 #define MAX_CHANNEL_NUM         8
82 #define MIN_CHANNEL_NUM         2
83
84 /* SYSCON Registers */
85 #define I2SRX_3CH_ADC_MASK      0x2
86 #define I2SRX_3CH_ADC_EN        BIT(1)
87 #define AUDIO_SDIN_MUX_MASK     0x3FC00
88 #define I2SRX_DATA_SRC_PDM      (0x91 << 10)
89
90 union dw_i2s_snd_dma_data {
91         struct i2s_dma_data pd;
92         struct snd_dmaengine_dai_dma_data dt;
93 };
94
95 struct dw_i2s_dev {
96         void __iomem *i2s_base;
97         struct regmap *syscon_base;
98         int active;
99         unsigned int capability;
100         unsigned int quirks;
101         unsigned int i2s_reg_comp1;
102         unsigned int i2s_reg_comp2;
103         struct device *dev;
104         u32 ccr;
105         u32 xfer_resolution;
106         u32 fifo_th;
107         u32 syscon_offset_18;
108         u32 syscon_offset_34;
109
110         struct clk *clk_apb0;
111         struct clk *clk_i2srx_apb;
112         struct clk *clk_i2srx_bclk_mst;
113         struct clk *clk_i2srx_lrck_mst;
114         struct clk *clk_i2srx_bclk;
115         struct clk *clk_i2srx_lrck;
116         struct reset_control *rst_i2srx_apb;
117         struct reset_control *rst_i2srx_bclk;
118
119         /* data related to DMA transfers b/w i2s and DMAC */
120         union dw_i2s_snd_dma_data play_dma_data;
121         union dw_i2s_snd_dma_data capture_dma_data;
122         struct i2s_clk_config_data config;
123         int (*i2s_clk_cfg)(struct i2s_clk_config_data *config);
124
125         /* data related to PIO transfers */
126         bool use_pio;
127         struct snd_pcm_substream __rcu *tx_substream;
128         struct snd_pcm_substream __rcu *rx_substream;
129         unsigned int (*tx_fn)(struct dw_i2s_dev *dev,
130                         struct snd_pcm_runtime *runtime, unsigned int tx_ptr,
131                         bool *period_elapsed);
132         unsigned int (*rx_fn)(struct dw_i2s_dev *dev,
133                         struct snd_pcm_runtime *runtime, unsigned int rx_ptr,
134                         bool *period_elapsed);
135         unsigned int tx_ptr;
136         unsigned int rx_ptr;
137 };
138
139 #if IS_ENABLED(CONFIG_SND_DESIGNWARE_PCM)
140 void dw_pcm_push_tx(struct dw_i2s_dev *dev);
141 void dw_pcm_pop_rx(struct dw_i2s_dev *dev);
142 int dw_pcm_register(struct platform_device *pdev);
143 #else
144 static inline void dw_pcm_push_tx(struct dw_i2s_dev *dev) { }
145 static inline void dw_pcm_pop_rx(struct dw_i2s_dev *dev) { }
146 static inline int dw_pcm_register(struct platform_device *pdev)
147 {
148         return -EINVAL;
149 }
150 #endif
151
152 #endif