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 #define ACP3x_ITER_IRER_SAMP_LEN_MASK 0x38
81 struct acp3x_platform_info
{
82 u16 play_i2s_instance
;
93 void __iomem
*acp3x_base
;
94 struct snd_pcm_substream
*play_stream
;
95 struct snd_pcm_substream
*capture_stream
;
96 struct snd_pcm_substream
*i2ssp_play_stream
;
97 struct snd_pcm_substream
*i2ssp_capture_stream
;
100 struct i2s_stream_instance
{
110 void __iomem
*acp3x_base
;
113 static inline u32
rv_readl(void __iomem
*base_addr
)
115 return readl(base_addr
- ACP3x_PHY_BASE_ADDRESS
);
118 static inline void rv_writel(u32 val
, void __iomem
*base_addr
)
120 writel(val
, base_addr
- ACP3x_PHY_BASE_ADDRESS
);
123 static inline u64
acp_get_byte_count(struct i2s_stream_instance
*rtd
,
128 if (direction
== SNDRV_PCM_STREAM_PLAYBACK
) {
129 switch (rtd
->i2s_instance
) {
130 case I2S_BT_INSTANCE
:
131 byte_count
= rv_readl(rtd
->acp3x_base
+
132 mmACP_BT_TX_LINEARPOSITIONCNTR_HIGH
);
133 byte_count
|= rv_readl(rtd
->acp3x_base
+
134 mmACP_BT_TX_LINEARPOSITIONCNTR_LOW
);
136 case I2S_SP_INSTANCE
:
138 byte_count
= rv_readl(rtd
->acp3x_base
+
139 mmACP_I2S_TX_LINEARPOSITIONCNTR_HIGH
);
140 byte_count
|= rv_readl(rtd
->acp3x_base
+
141 mmACP_I2S_TX_LINEARPOSITIONCNTR_LOW
);
145 switch (rtd
->i2s_instance
) {
146 case I2S_BT_INSTANCE
:
147 byte_count
= rv_readl(rtd
->acp3x_base
+
148 mmACP_BT_RX_LINEARPOSITIONCNTR_HIGH
);
149 byte_count
|= rv_readl(rtd
->acp3x_base
+
150 mmACP_BT_RX_LINEARPOSITIONCNTR_LOW
);
152 case I2S_SP_INSTANCE
:
154 byte_count
= rv_readl(rtd
->acp3x_base
+
155 mmACP_I2S_RX_LINEARPOSITIONCNTR_HIGH
);
156 byte_count
|= rv_readl(rtd
->acp3x_base
+
157 mmACP_I2S_RX_LINEARPOSITIONCNTR_LOW
);