1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * AMD ALSA SoC PCM Driver
5 * Copyright 2016 Advanced Micro Devices, Inc.
8 #include "chip_offset_byte.h"
10 #define I2S_SP_INSTANCE 0x01
11 #define I2S_BT_INSTANCE 0x02
17 #define ACP3x_PHY_BASE_ADDRESS 0x1240000
18 #define ACP3x_I2S_MODE 0
19 #define ACP3x_REG_START 0x1240000
20 #define ACP3x_REG_END 0x1250200
21 #define ACP3x_I2STDM_REG_START 0x1242400
22 #define ACP3x_I2STDM_REG_END 0x1242410
23 #define ACP3x_BT_TDM_REG_START 0x1242800
24 #define ACP3x_BT_TDM_REG_END 0x1242810
26 #define I2S_RX_THRESHOLD 27
27 #define I2S_TX_THRESHOLD 28
28 #define BT_TX_THRESHOLD 26
29 #define BT_RX_THRESHOLD 25
30 #define ACP_ERR_INTR_MASK 29
31 #define ACP3x_POWER_ON 0x00
32 #define ACP3x_POWER_ON_IN_PROGRESS 0x01
33 #define ACP3x_POWER_OFF 0x02
34 #define ACP3x_POWER_OFF_IN_PROGRESS 0x03
35 #define ACP3x_SOFT_RESET__SoftResetAudDone_MASK 0x00010001
37 #define ACP_SRAM_PTE_OFFSET 0x02050000
38 #define ACP_SRAM_SP_PB_PTE_OFFSET 0x0
39 #define ACP_SRAM_SP_CP_PTE_OFFSET 0x100
40 #define ACP_SRAM_BT_PB_PTE_OFFSET 0x200
41 #define ACP_SRAM_BT_CP_PTE_OFFSET 0x300
42 #define PAGE_SIZE_4K_ENABLE 0x2
43 #define I2S_SP_TX_MEM_WINDOW_START 0x4000000
44 #define I2S_SP_RX_MEM_WINDOW_START 0x4020000
45 #define I2S_BT_TX_MEM_WINDOW_START 0x4040000
46 #define I2S_BT_RX_MEM_WINDOW_START 0x4060000
48 #define SP_PB_FIFO_ADDR_OFFSET 0x500
49 #define SP_CAPT_FIFO_ADDR_OFFSET 0x700
50 #define BT_PB_FIFO_ADDR_OFFSET 0x900
51 #define BT_CAPT_FIFO_ADDR_OFFSET 0xB00
52 #define PLAYBACK_MIN_NUM_PERIODS 2
53 #define PLAYBACK_MAX_NUM_PERIODS 8
54 #define PLAYBACK_MAX_PERIOD_SIZE 8192
55 #define PLAYBACK_MIN_PERIOD_SIZE 1024
56 #define CAPTURE_MIN_NUM_PERIODS 2
57 #define CAPTURE_MAX_NUM_PERIODS 8
58 #define CAPTURE_MAX_PERIOD_SIZE 8192
59 #define CAPTURE_MIN_PERIOD_SIZE 1024
61 #define MAX_BUFFER (PLAYBACK_MAX_PERIOD_SIZE * PLAYBACK_MAX_NUM_PERIODS)
62 #define MIN_BUFFER MAX_BUFFER
63 #define FIFO_SIZE 0x100
67 #define SLOT_WIDTH_8 0x08
68 #define SLOT_WIDTH_16 0x10
69 #define SLOT_WIDTH_24 0x18
70 #define SLOT_WIDTH_32 0x20
71 #define ACP_PGFSM_CNTL_POWER_ON_MASK 0x01
72 #define ACP_PGFSM_CNTL_POWER_OFF_MASK 0x00
73 #define ACP_PGFSM_STATUS_MASK 0x03
74 #define ACP_POWERED_ON 0x00
75 #define ACP_POWER_ON_IN_PROGRESS 0x01
76 #define ACP_POWERED_OFF 0x02
77 #define ACP_POWER_OFF_IN_PROGRESS 0x03
79 struct acp3x_platform_info
{
80 u16 play_i2s_instance
;
91 void __iomem
*acp3x_base
;
92 struct snd_pcm_substream
*play_stream
;
93 struct snd_pcm_substream
*capture_stream
;
94 struct snd_pcm_substream
*i2ssp_play_stream
;
95 struct snd_pcm_substream
*i2ssp_capture_stream
;
98 struct i2s_stream_instance
{
108 void __iomem
*acp3x_base
;
111 static inline u32
rv_readl(void __iomem
*base_addr
)
113 return readl(base_addr
- ACP3x_PHY_BASE_ADDRESS
);
116 static inline void rv_writel(u32 val
, void __iomem
*base_addr
)
118 writel(val
, base_addr
- ACP3x_PHY_BASE_ADDRESS
);
121 static inline u64
acp_get_byte_count(struct i2s_stream_instance
*rtd
,
126 if (direction
== SNDRV_PCM_STREAM_PLAYBACK
) {
127 switch (rtd
->i2s_instance
) {
128 case I2S_BT_INSTANCE
:
129 byte_count
= rv_readl(rtd
->acp3x_base
+
130 mmACP_BT_TX_LINEARPOSITIONCNTR_HIGH
);
131 byte_count
|= rv_readl(rtd
->acp3x_base
+
132 mmACP_BT_TX_LINEARPOSITIONCNTR_LOW
);
134 case I2S_SP_INSTANCE
:
136 byte_count
= rv_readl(rtd
->acp3x_base
+
137 mmACP_I2S_TX_LINEARPOSITIONCNTR_HIGH
);
138 byte_count
|= rv_readl(rtd
->acp3x_base
+
139 mmACP_I2S_TX_LINEARPOSITIONCNTR_LOW
);
143 switch (rtd
->i2s_instance
) {
144 case I2S_BT_INSTANCE
:
145 byte_count
= rv_readl(rtd
->acp3x_base
+
146 mmACP_BT_RX_LINEARPOSITIONCNTR_HIGH
);
147 byte_count
|= rv_readl(rtd
->acp3x_base
+
148 mmACP_BT_RX_LINEARPOSITIONCNTR_LOW
);
150 case I2S_SP_INSTANCE
:
152 byte_count
= rv_readl(rtd
->acp3x_base
+
153 mmACP_I2S_RX_LINEARPOSITIONCNTR_HIGH
);
154 byte_count
|= rv_readl(rtd
->acp3x_base
+
155 mmACP_I2S_RX_LINEARPOSITIONCNTR_LOW
);