xref: /openbmc/linux/sound/soc/dwc/local.h (revision 52ea7c05)
179361b2bSJose Abreu /*
279361b2bSJose Abreu  * Copyright (ST) 2012 Rajeev Kumar (rajeevkumar.linux@gmail.com)
379361b2bSJose Abreu  *
479361b2bSJose Abreu  * This file is licensed under the terms of the GNU General Public
579361b2bSJose Abreu  * License version 2. This program is licensed "as is" without any
679361b2bSJose Abreu  * warranty of any kind, whether express or implied.
779361b2bSJose Abreu  */
879361b2bSJose Abreu 
979361b2bSJose Abreu #ifndef __DESIGNWARE_LOCAL_H
1079361b2bSJose Abreu #define __DESIGNWARE_LOCAL_H
1179361b2bSJose Abreu 
1279361b2bSJose Abreu #include <linux/clk.h>
1379361b2bSJose Abreu #include <linux/device.h>
1479361b2bSJose Abreu #include <linux/types.h>
1579361b2bSJose Abreu #include <sound/dmaengine_pcm.h>
1679361b2bSJose Abreu #include <sound/pcm.h>
1779361b2bSJose Abreu #include <sound/designware_i2s.h>
1879361b2bSJose Abreu 
1979361b2bSJose Abreu /* common register for all channel */
2079361b2bSJose Abreu #define IER		0x000
2179361b2bSJose Abreu #define IRER		0x004
2279361b2bSJose Abreu #define ITER		0x008
2379361b2bSJose Abreu #define CER		0x00C
2479361b2bSJose Abreu #define CCR		0x010
2579361b2bSJose Abreu #define RXFFR		0x014
2679361b2bSJose Abreu #define TXFFR		0x018
2779361b2bSJose Abreu 
28221acc16SMaxim Kochetkov /* Enable register fields */
29221acc16SMaxim Kochetkov #define IER_TDM_SLOTS_SHIFT	8
30221acc16SMaxim Kochetkov #define IER_FRAME_OFF_SHIFT	5
31221acc16SMaxim Kochetkov #define IER_FRAME_OFF	BIT(5)
32221acc16SMaxim Kochetkov #define IER_INTF_TYPE	BIT(1)
33221acc16SMaxim Kochetkov #define IER_IEN		BIT(0)
34221acc16SMaxim Kochetkov 
3579361b2bSJose Abreu /* Interrupt status register fields */
3679361b2bSJose Abreu #define ISR_TXFO	BIT(5)
3779361b2bSJose Abreu #define ISR_TXFE	BIT(4)
3879361b2bSJose Abreu #define ISR_RXFO	BIT(1)
3979361b2bSJose Abreu #define ISR_RXDA	BIT(0)
4079361b2bSJose Abreu 
4179361b2bSJose Abreu /* I2STxRxRegisters for all channels */
4279361b2bSJose Abreu #define LRBR_LTHR(x)	(0x40 * x + 0x020)
4379361b2bSJose Abreu #define RRBR_RTHR(x)	(0x40 * x + 0x024)
4479361b2bSJose Abreu #define RER(x)		(0x40 * x + 0x028)
4579361b2bSJose Abreu #define TER(x)		(0x40 * x + 0x02C)
4679361b2bSJose Abreu #define RCR(x)		(0x40 * x + 0x030)
4779361b2bSJose Abreu #define TCR(x)		(0x40 * x + 0x034)
4879361b2bSJose Abreu #define ISR(x)		(0x40 * x + 0x038)
4979361b2bSJose Abreu #define IMR(x)		(0x40 * x + 0x03C)
5079361b2bSJose Abreu #define ROR(x)		(0x40 * x + 0x040)
5179361b2bSJose Abreu #define TOR(x)		(0x40 * x + 0x044)
5279361b2bSJose Abreu #define RFCR(x)		(0x40 * x + 0x048)
5379361b2bSJose Abreu #define TFCR(x)		(0x40 * x + 0x04C)
5479361b2bSJose Abreu #define RFF(x)		(0x40 * x + 0x050)
5579361b2bSJose Abreu #define TFF(x)		(0x40 * x + 0x054)
56221acc16SMaxim Kochetkov #define RSLOT_TSLOT(x)	(0x4 * (x) + 0x224)
57221acc16SMaxim Kochetkov 
58221acc16SMaxim Kochetkov /* Receive enable register fields */
59221acc16SMaxim Kochetkov #define RER_RXSLOT_SHIFT	8
60221acc16SMaxim Kochetkov #define RER_RXCHEN	BIT(0)
61221acc16SMaxim Kochetkov 
62221acc16SMaxim Kochetkov /* Transmit enable register fields */
63221acc16SMaxim Kochetkov #define TER_TXSLOT_SHIFT	8
64221acc16SMaxim Kochetkov #define TER_TXCHEN	BIT(0)
6579361b2bSJose Abreu 
6679361b2bSJose Abreu /* I2SCOMPRegisters */
6779361b2bSJose Abreu #define I2S_COMP_PARAM_2	0x01F0
6879361b2bSJose Abreu #define I2S_COMP_PARAM_1	0x01F4
6979361b2bSJose Abreu #define I2S_COMP_VERSION	0x01F8
7079361b2bSJose Abreu #define I2S_COMP_TYPE		0x01FC
7179361b2bSJose Abreu 
72a42e988bSMaxim Kochetkov #define I2S_RRXDMA		0x01C4
73a42e988bSMaxim Kochetkov #define I2S_RTXDMA		0x01CC
74a42e988bSMaxim Kochetkov #define I2S_DMACR		0x0200
75a42e988bSMaxim Kochetkov #define I2S_DMAEN_RXBLOCK	(1 << 16)
76a42e988bSMaxim Kochetkov #define I2S_DMAEN_TXBLOCK	(1 << 17)
77a42e988bSMaxim Kochetkov 
7879361b2bSJose Abreu /*
7979361b2bSJose Abreu  * Component parameter register fields - define the I2S block's
8079361b2bSJose Abreu  * configuration.
8179361b2bSJose Abreu  */
8279361b2bSJose Abreu #define	COMP1_TX_WORDSIZE_3(r)	(((r) & GENMASK(27, 25)) >> 25)
8379361b2bSJose Abreu #define	COMP1_TX_WORDSIZE_2(r)	(((r) & GENMASK(24, 22)) >> 22)
8479361b2bSJose Abreu #define	COMP1_TX_WORDSIZE_1(r)	(((r) & GENMASK(21, 19)) >> 19)
8579361b2bSJose Abreu #define	COMP1_TX_WORDSIZE_0(r)	(((r) & GENMASK(18, 16)) >> 16)
8679361b2bSJose Abreu #define	COMP1_TX_CHANNELS(r)	(((r) & GENMASK(10, 9)) >> 9)
8779361b2bSJose Abreu #define	COMP1_RX_CHANNELS(r)	(((r) & GENMASK(8, 7)) >> 7)
8879361b2bSJose Abreu #define	COMP1_RX_ENABLED(r)	(((r) & BIT(6)) >> 6)
8979361b2bSJose Abreu #define	COMP1_TX_ENABLED(r)	(((r) & BIT(5)) >> 5)
9079361b2bSJose Abreu #define	COMP1_MODE_EN(r)	(((r) & BIT(4)) >> 4)
9179361b2bSJose Abreu #define	COMP1_FIFO_DEPTH_GLOBAL(r)	(((r) & GENMASK(3, 2)) >> 2)
9279361b2bSJose Abreu #define	COMP1_APB_DATA_WIDTH(r)	(((r) & GENMASK(1, 0)) >> 0)
9379361b2bSJose Abreu 
9479361b2bSJose Abreu #define	COMP2_RX_WORDSIZE_3(r)	(((r) & GENMASK(12, 10)) >> 10)
9579361b2bSJose Abreu #define	COMP2_RX_WORDSIZE_2(r)	(((r) & GENMASK(9, 7)) >> 7)
9679361b2bSJose Abreu #define	COMP2_RX_WORDSIZE_1(r)	(((r) & GENMASK(5, 3)) >> 3)
9779361b2bSJose Abreu #define	COMP2_RX_WORDSIZE_0(r)	(((r) & GENMASK(2, 0)) >> 0)
9879361b2bSJose Abreu 
9979361b2bSJose Abreu /* Number of entries in WORDSIZE and DATA_WIDTH parameter registers */
10079361b2bSJose Abreu #define	COMP_MAX_WORDSIZE	(1 << 3)
10179361b2bSJose Abreu #define	COMP_MAX_DATA_WIDTH	(1 << 2)
10279361b2bSJose Abreu 
10379361b2bSJose Abreu #define MAX_CHANNEL_NUM		8
10479361b2bSJose Abreu #define MIN_CHANNEL_NUM		2
10579361b2bSJose Abreu 
10679361b2bSJose Abreu union dw_i2s_snd_dma_data {
10779361b2bSJose Abreu 	struct i2s_dma_data pd;
10879361b2bSJose Abreu 	struct snd_dmaengine_dai_dma_data dt;
10979361b2bSJose Abreu };
11079361b2bSJose Abreu 
11179361b2bSJose Abreu struct dw_i2s_dev {
11279361b2bSJose Abreu 	void __iomem *i2s_base;
11379361b2bSJose Abreu 	struct clk *clk;
114c00018caSMaxim Kochetkov 	struct reset_control *reset;
11579361b2bSJose Abreu 	int active;
11679361b2bSJose Abreu 	unsigned int capability;
11779361b2bSJose Abreu 	unsigned int quirks;
11879361b2bSJose Abreu 	unsigned int i2s_reg_comp1;
11979361b2bSJose Abreu 	unsigned int i2s_reg_comp2;
12079361b2bSJose Abreu 	struct device *dev;
12179361b2bSJose Abreu 	u32 ccr;
12279361b2bSJose Abreu 	u32 xfer_resolution;
12379361b2bSJose Abreu 	u32 fifo_th;
124221acc16SMaxim Kochetkov 	u32 l_reg;
125221acc16SMaxim Kochetkov 	u32 r_reg;
126*52ea7c05SXingyu Wu 	bool is_jh7110; /* Flag for StarFive JH7110 SoC */
12779361b2bSJose Abreu 
12879361b2bSJose Abreu 	/* data related to DMA transfers b/w i2s and DMAC */
12979361b2bSJose Abreu 	union dw_i2s_snd_dma_data play_dma_data;
13079361b2bSJose Abreu 	union dw_i2s_snd_dma_data capture_dma_data;
13179361b2bSJose Abreu 	struct i2s_clk_config_data config;
13279361b2bSJose Abreu 	int (*i2s_clk_cfg)(struct i2s_clk_config_data *config);
13379361b2bSJose Abreu 
134e2f748e0SJose Abreu 	/* data related to PIO transfers */
13579361b2bSJose Abreu 	bool use_pio;
136221acc16SMaxim Kochetkov 
137221acc16SMaxim Kochetkov 	/* data related to TDM mode */
138221acc16SMaxim Kochetkov 	u32 tdm_slots;
139221acc16SMaxim Kochetkov 	u32 tdm_mask;
140221acc16SMaxim Kochetkov 	u32 frame_offset;
141221acc16SMaxim Kochetkov 
14279361b2bSJose Abreu 	struct snd_pcm_substream __rcu *tx_substream;
143e2f748e0SJose Abreu 	struct snd_pcm_substream __rcu *rx_substream;
14479361b2bSJose Abreu 	unsigned int (*tx_fn)(struct dw_i2s_dev *dev,
14579361b2bSJose Abreu 			struct snd_pcm_runtime *runtime, unsigned int tx_ptr,
14679361b2bSJose Abreu 			bool *period_elapsed);
147e2f748e0SJose Abreu 	unsigned int (*rx_fn)(struct dw_i2s_dev *dev,
148e2f748e0SJose Abreu 			struct snd_pcm_runtime *runtime, unsigned int rx_ptr,
149e2f748e0SJose Abreu 			bool *period_elapsed);
15079361b2bSJose Abreu 	unsigned int tx_ptr;
151e2f748e0SJose Abreu 	unsigned int rx_ptr;
15279361b2bSJose Abreu };
15379361b2bSJose Abreu 
15479361b2bSJose Abreu #if IS_ENABLED(CONFIG_SND_DESIGNWARE_PCM)
15579361b2bSJose Abreu void dw_pcm_push_tx(struct dw_i2s_dev *dev);
156e2f748e0SJose Abreu void dw_pcm_pop_rx(struct dw_i2s_dev *dev);
15779361b2bSJose Abreu int dw_pcm_register(struct platform_device *pdev);
15879361b2bSJose Abreu #else
dw_pcm_push_tx(struct dw_i2s_dev * dev)1590803a5cbSYueHaibing static inline void dw_pcm_push_tx(struct dw_i2s_dev *dev) { }
dw_pcm_pop_rx(struct dw_i2s_dev * dev)1600803a5cbSYueHaibing static inline void dw_pcm_pop_rx(struct dw_i2s_dev *dev) { }
dw_pcm_register(struct platform_device * pdev)1610803a5cbSYueHaibing static inline int dw_pcm_register(struct platform_device *pdev)
16279361b2bSJose Abreu {
16379361b2bSJose Abreu 	return -EINVAL;
16479361b2bSJose Abreu }
16579361b2bSJose Abreu #endif
16679361b2bSJose Abreu 
16779361b2bSJose Abreu #endif
168