Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1 | /* |
| 2 | * AMD ALSA SoC PCM Driver for ACP 2.x |
| 3 | * |
| 4 | * Copyright 2014-2015 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/delay.h> |
Guenter Roeck | 7cb1dc8 | 2016-01-11 02:41:05 -0800 | [diff] [blame] | 18 | #include <linux/io.h> |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 19 | #include <linux/sizes.h> |
Maruthi Srinivas Bayyavarapu | 1927da9 | 2016-01-08 18:22:10 -0500 | [diff] [blame] | 20 | #include <linux/pm_runtime.h> |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 21 | |
| 22 | #include <sound/soc.h> |
Vijendar Mukunda | 607b39e | 2017-10-18 12:13:57 -0400 | [diff] [blame] | 23 | #include <drm/amd_asic_type.h> |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 24 | #include "acp.h" |
| 25 | |
Kuninori Morimoto | a1042a4 | 2018-01-29 02:44:23 +0000 | [diff] [blame] | 26 | #define DRV_NAME "acp_audio_dma" |
| 27 | |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 28 | #define PLAYBACK_MIN_NUM_PERIODS 2 |
| 29 | #define PLAYBACK_MAX_NUM_PERIODS 2 |
| 30 | #define PLAYBACK_MAX_PERIOD_SIZE 16384 |
| 31 | #define PLAYBACK_MIN_PERIOD_SIZE 1024 |
| 32 | #define CAPTURE_MIN_NUM_PERIODS 2 |
| 33 | #define CAPTURE_MAX_NUM_PERIODS 2 |
| 34 | #define CAPTURE_MAX_PERIOD_SIZE 16384 |
| 35 | #define CAPTURE_MIN_PERIOD_SIZE 1024 |
| 36 | |
| 37 | #define MAX_BUFFER (PLAYBACK_MAX_PERIOD_SIZE * PLAYBACK_MAX_NUM_PERIODS) |
| 38 | #define MIN_BUFFER MAX_BUFFER |
| 39 | |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 40 | #define ST_PLAYBACK_MAX_PERIOD_SIZE 4096 |
Vijendar Mukunda | 9c7d6fa | 2017-10-18 12:13:59 -0400 | [diff] [blame] | 41 | #define ST_CAPTURE_MAX_PERIOD_SIZE ST_PLAYBACK_MAX_PERIOD_SIZE |
| 42 | #define ST_MAX_BUFFER (ST_PLAYBACK_MAX_PERIOD_SIZE * PLAYBACK_MAX_NUM_PERIODS) |
| 43 | #define ST_MIN_BUFFER ST_MAX_BUFFER |
| 44 | |
Akshu Agrawal | bdd2a85 | 2017-11-08 12:24:02 -0500 | [diff] [blame] | 45 | #define DRV_NAME "acp_audio_dma" |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 46 | bool bt_uart_enable = true; |
| 47 | EXPORT_SYMBOL(bt_uart_enable); |
Akshu Agrawal | bdd2a85 | 2017-11-08 12:24:02 -0500 | [diff] [blame] | 48 | |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 49 | static const struct snd_pcm_hardware acp_pcm_hardware_playback = { |
| 50 | .info = SNDRV_PCM_INFO_INTERLEAVED | |
| 51 | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP | |
| 52 | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BATCH | |
| 53 | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME, |
| 54 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 55 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE, |
| 56 | .channels_min = 1, |
| 57 | .channels_max = 8, |
| 58 | .rates = SNDRV_PCM_RATE_8000_96000, |
| 59 | .rate_min = 8000, |
| 60 | .rate_max = 96000, |
| 61 | .buffer_bytes_max = PLAYBACK_MAX_NUM_PERIODS * PLAYBACK_MAX_PERIOD_SIZE, |
| 62 | .period_bytes_min = PLAYBACK_MIN_PERIOD_SIZE, |
| 63 | .period_bytes_max = PLAYBACK_MAX_PERIOD_SIZE, |
| 64 | .periods_min = PLAYBACK_MIN_NUM_PERIODS, |
| 65 | .periods_max = PLAYBACK_MAX_NUM_PERIODS, |
| 66 | }; |
| 67 | |
| 68 | static const struct snd_pcm_hardware acp_pcm_hardware_capture = { |
| 69 | .info = SNDRV_PCM_INFO_INTERLEAVED | |
| 70 | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP | |
| 71 | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BATCH | |
| 72 | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME, |
| 73 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 74 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE, |
| 75 | .channels_min = 1, |
| 76 | .channels_max = 2, |
| 77 | .rates = SNDRV_PCM_RATE_8000_48000, |
| 78 | .rate_min = 8000, |
| 79 | .rate_max = 48000, |
| 80 | .buffer_bytes_max = CAPTURE_MAX_NUM_PERIODS * CAPTURE_MAX_PERIOD_SIZE, |
| 81 | .period_bytes_min = CAPTURE_MIN_PERIOD_SIZE, |
| 82 | .period_bytes_max = CAPTURE_MAX_PERIOD_SIZE, |
| 83 | .periods_min = CAPTURE_MIN_NUM_PERIODS, |
| 84 | .periods_max = CAPTURE_MAX_NUM_PERIODS, |
| 85 | }; |
| 86 | |
Vijendar Mukunda | 9c7d6fa | 2017-10-18 12:13:59 -0400 | [diff] [blame] | 87 | static const struct snd_pcm_hardware acp_st_pcm_hardware_playback = { |
| 88 | .info = SNDRV_PCM_INFO_INTERLEAVED | |
| 89 | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP | |
| 90 | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BATCH | |
| 91 | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME, |
| 92 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 93 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE, |
| 94 | .channels_min = 1, |
| 95 | .channels_max = 8, |
| 96 | .rates = SNDRV_PCM_RATE_8000_96000, |
| 97 | .rate_min = 8000, |
| 98 | .rate_max = 96000, |
| 99 | .buffer_bytes_max = ST_MAX_BUFFER, |
| 100 | .period_bytes_min = PLAYBACK_MIN_PERIOD_SIZE, |
| 101 | .period_bytes_max = ST_PLAYBACK_MAX_PERIOD_SIZE, |
| 102 | .periods_min = PLAYBACK_MIN_NUM_PERIODS, |
| 103 | .periods_max = PLAYBACK_MAX_NUM_PERIODS, |
| 104 | }; |
| 105 | |
| 106 | static const struct snd_pcm_hardware acp_st_pcm_hardware_capture = { |
| 107 | .info = SNDRV_PCM_INFO_INTERLEAVED | |
| 108 | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP | |
| 109 | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BATCH | |
| 110 | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME, |
| 111 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 112 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE, |
| 113 | .channels_min = 1, |
| 114 | .channels_max = 2, |
| 115 | .rates = SNDRV_PCM_RATE_8000_48000, |
| 116 | .rate_min = 8000, |
| 117 | .rate_max = 48000, |
| 118 | .buffer_bytes_max = ST_MAX_BUFFER, |
| 119 | .period_bytes_min = CAPTURE_MIN_PERIOD_SIZE, |
| 120 | .period_bytes_max = ST_CAPTURE_MAX_PERIOD_SIZE, |
| 121 | .periods_min = CAPTURE_MIN_NUM_PERIODS, |
| 122 | .periods_max = CAPTURE_MAX_NUM_PERIODS, |
| 123 | }; |
| 124 | |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 125 | static u32 acp_reg_read(void __iomem *acp_mmio, u32 reg) |
| 126 | { |
| 127 | return readl(acp_mmio + (reg * 4)); |
| 128 | } |
| 129 | |
| 130 | static void acp_reg_write(u32 val, void __iomem *acp_mmio, u32 reg) |
| 131 | { |
| 132 | writel(val, acp_mmio + (reg * 4)); |
| 133 | } |
| 134 | |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 135 | /* |
| 136 | * Configure a given dma channel parameters - enable/disable, |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 137 | * number of descriptors, priority |
| 138 | */ |
| 139 | static void config_acp_dma_channel(void __iomem *acp_mmio, u8 ch_num, |
| 140 | u16 dscr_strt_idx, u16 num_dscrs, |
| 141 | enum acp_dma_priority_level priority_level) |
| 142 | { |
| 143 | u32 dma_ctrl; |
| 144 | |
| 145 | /* disable the channel run field */ |
| 146 | dma_ctrl = acp_reg_read(acp_mmio, mmACP_DMA_CNTL_0 + ch_num); |
| 147 | dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChRun_MASK; |
| 148 | acp_reg_write(dma_ctrl, acp_mmio, mmACP_DMA_CNTL_0 + ch_num); |
| 149 | |
| 150 | /* program a DMA channel with first descriptor to be processed. */ |
| 151 | acp_reg_write((ACP_DMA_DSCR_STRT_IDX_0__DMAChDscrStrtIdx_MASK |
| 152 | & dscr_strt_idx), |
| 153 | acp_mmio, mmACP_DMA_DSCR_STRT_IDX_0 + ch_num); |
| 154 | |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 155 | /* |
| 156 | * program a DMA channel with the number of descriptors to be |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 157 | * processed in the transfer |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 158 | */ |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 159 | acp_reg_write(ACP_DMA_DSCR_CNT_0__DMAChDscrCnt_MASK & num_dscrs, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 160 | acp_mmio, mmACP_DMA_DSCR_CNT_0 + ch_num); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 161 | |
| 162 | /* set DMA channel priority */ |
| 163 | acp_reg_write(priority_level, acp_mmio, mmACP_DMA_PRIO_0 + ch_num); |
| 164 | } |
| 165 | |
| 166 | /* Initialize a dma descriptor in SRAM based on descritor information passed */ |
| 167 | static void config_dma_descriptor_in_sram(void __iomem *acp_mmio, |
| 168 | u16 descr_idx, |
| 169 | acp_dma_dscr_transfer_t *descr_info) |
| 170 | { |
| 171 | u32 sram_offset; |
| 172 | |
| 173 | sram_offset = (descr_idx * sizeof(acp_dma_dscr_transfer_t)); |
| 174 | |
| 175 | /* program the source base address. */ |
| 176 | acp_reg_write(sram_offset, acp_mmio, mmACP_SRBM_Targ_Idx_Addr); |
| 177 | acp_reg_write(descr_info->src, acp_mmio, mmACP_SRBM_Targ_Idx_Data); |
| 178 | /* program the destination base address. */ |
| 179 | acp_reg_write(sram_offset + 4, acp_mmio, mmACP_SRBM_Targ_Idx_Addr); |
| 180 | acp_reg_write(descr_info->dest, acp_mmio, mmACP_SRBM_Targ_Idx_Data); |
| 181 | |
| 182 | /* program the number of bytes to be transferred for this descriptor. */ |
| 183 | acp_reg_write(sram_offset + 8, acp_mmio, mmACP_SRBM_Targ_Idx_Addr); |
| 184 | acp_reg_write(descr_info->xfer_val, acp_mmio, mmACP_SRBM_Targ_Idx_Data); |
| 185 | } |
| 186 | |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 187 | /* |
| 188 | * Initialize the DMA descriptor information for transfer between |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 189 | * system memory <-> ACP SRAM |
| 190 | */ |
| 191 | static void set_acp_sysmem_dma_descriptors(void __iomem *acp_mmio, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 192 | u32 size, int direction, |
| 193 | u32 pte_offset, u16 ch, |
| 194 | u32 sram_bank, u16 dma_dscr_idx, |
| 195 | u32 asic_type) |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 196 | { |
| 197 | u16 i; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 198 | acp_dma_dscr_transfer_t dmadscr[NUM_DSCRS_PER_CHANNEL]; |
| 199 | |
| 200 | for (i = 0; i < NUM_DSCRS_PER_CHANNEL; i++) { |
| 201 | dmadscr[i].xfer_val = 0; |
| 202 | if (direction == SNDRV_PCM_STREAM_PLAYBACK) { |
Mukunda, Vijendar | 4376a86 | 2018-02-16 13:03:47 +0530 | [diff] [blame] | 203 | dma_dscr_idx = dma_dscr_idx + i; |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 204 | dmadscr[i].dest = sram_bank + (i * (size / 2)); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 205 | dmadscr[i].src = ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 206 | + (pte_offset * SZ_4K) + (i * (size / 2)); |
Vijendar Mukunda | aac8974 | 2017-10-18 12:13:58 -0400 | [diff] [blame] | 207 | switch (asic_type) { |
| 208 | case CHIP_STONEY: |
| 209 | dmadscr[i].xfer_val |= |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 210 | (ACP_DMA_ATTR_DAGB_GARLIC_TO_SHAREDMEM << 16) | |
Vijendar Mukunda | aac8974 | 2017-10-18 12:13:58 -0400 | [diff] [blame] | 211 | (size / 2); |
| 212 | break; |
| 213 | default: |
| 214 | dmadscr[i].xfer_val |= |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 215 | (ACP_DMA_ATTR_DAGB_ONION_TO_SHAREDMEM << 16) | |
Vijendar Mukunda | aac8974 | 2017-10-18 12:13:58 -0400 | [diff] [blame] | 216 | (size / 2); |
| 217 | } |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 218 | } else { |
Mukunda, Vijendar | 4376a86 | 2018-02-16 13:03:47 +0530 | [diff] [blame] | 219 | dma_dscr_idx = dma_dscr_idx + i; |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 220 | dmadscr[i].src = sram_bank + (i * (size / 2)); |
Mukunda, Vijendar | 4376a86 | 2018-02-16 13:03:47 +0530 | [diff] [blame] | 221 | dmadscr[i].dest = |
| 222 | ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS + |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 223 | (pte_offset * SZ_4K) + (i * (size / 2)); |
Vijendar Mukunda | aac8974 | 2017-10-18 12:13:58 -0400 | [diff] [blame] | 224 | switch (asic_type) { |
| 225 | case CHIP_STONEY: |
Vijendar Mukunda | aac8974 | 2017-10-18 12:13:58 -0400 | [diff] [blame] | 226 | dmadscr[i].xfer_val |= |
| 227 | BIT(22) | |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 228 | (ACP_DMA_ATTR_SHARED_MEM_TO_DAGB_GARLIC << 16) | |
Vijendar Mukunda | aac8974 | 2017-10-18 12:13:58 -0400 | [diff] [blame] | 229 | (size / 2); |
| 230 | break; |
| 231 | default: |
Vijendar Mukunda | aac8974 | 2017-10-18 12:13:58 -0400 | [diff] [blame] | 232 | dmadscr[i].xfer_val |= |
| 233 | BIT(22) | |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 234 | (ACP_DMA_ATTR_SHAREDMEM_TO_DAGB_ONION << 16) | |
Vijendar Mukunda | aac8974 | 2017-10-18 12:13:58 -0400 | [diff] [blame] | 235 | (size / 2); |
| 236 | } |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 237 | } |
| 238 | config_dma_descriptor_in_sram(acp_mmio, dma_dscr_idx, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 239 | &dmadscr[i]); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 240 | } |
Mukunda, Vijendar | 4376a86 | 2018-02-16 13:03:47 +0530 | [diff] [blame] | 241 | config_acp_dma_channel(acp_mmio, ch, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 242 | dma_dscr_idx - 1, |
| 243 | NUM_DSCRS_PER_CHANNEL, |
| 244 | ACP_DMA_PRIORITY_LEVEL_NORMAL); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 245 | } |
| 246 | |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 247 | /* |
| 248 | * Initialize the DMA descriptor information for transfer between |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 249 | * ACP SRAM <-> I2S |
| 250 | */ |
Mukunda, Vijendar | 4376a86 | 2018-02-16 13:03:47 +0530 | [diff] [blame] | 251 | static void set_acp_to_i2s_dma_descriptors(void __iomem *acp_mmio, u32 size, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 252 | int direction, u32 sram_bank, |
| 253 | u16 destination, u16 ch, |
| 254 | u16 dma_dscr_idx, u32 asic_type) |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 255 | { |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 256 | u16 i; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 257 | acp_dma_dscr_transfer_t dmadscr[NUM_DSCRS_PER_CHANNEL]; |
| 258 | |
| 259 | for (i = 0; i < NUM_DSCRS_PER_CHANNEL; i++) { |
| 260 | dmadscr[i].xfer_val = 0; |
| 261 | if (direction == SNDRV_PCM_STREAM_PLAYBACK) { |
Mukunda, Vijendar | 4376a86 | 2018-02-16 13:03:47 +0530 | [diff] [blame] | 262 | dma_dscr_idx = dma_dscr_idx + i; |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 263 | dmadscr[i].src = sram_bank + (i * (size / 2)); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 264 | /* dmadscr[i].dest is unused by hardware. */ |
| 265 | dmadscr[i].dest = 0; |
Mukunda, Vijendar | 4376a86 | 2018-02-16 13:03:47 +0530 | [diff] [blame] | 266 | dmadscr[i].xfer_val |= BIT(22) | (destination << 16) | |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 267 | (size / 2); |
| 268 | } else { |
Mukunda, Vijendar | 4376a86 | 2018-02-16 13:03:47 +0530 | [diff] [blame] | 269 | dma_dscr_idx = dma_dscr_idx + i; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 270 | /* dmadscr[i].src is unused by hardware. */ |
| 271 | dmadscr[i].src = 0; |
Mukunda, Vijendar | 4376a86 | 2018-02-16 13:03:47 +0530 | [diff] [blame] | 272 | dmadscr[i].dest = |
| 273 | sram_bank + (i * (size / 2)); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 274 | dmadscr[i].xfer_val |= BIT(22) | |
Mukunda, Vijendar | 4376a86 | 2018-02-16 13:03:47 +0530 | [diff] [blame] | 275 | (destination << 16) | (size / 2); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 276 | } |
| 277 | config_dma_descriptor_in_sram(acp_mmio, dma_dscr_idx, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 278 | &dmadscr[i]); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 279 | } |
| 280 | /* Configure the DMA channel with the above descriptore */ |
Mukunda, Vijendar | 4376a86 | 2018-02-16 13:03:47 +0530 | [diff] [blame] | 281 | config_acp_dma_channel(acp_mmio, ch, dma_dscr_idx - 1, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 282 | NUM_DSCRS_PER_CHANNEL, |
| 283 | ACP_DMA_PRIORITY_LEVEL_NORMAL); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | /* Create page table entries in ACP SRAM for the allocated memory */ |
| 287 | static void acp_pte_config(void __iomem *acp_mmio, struct page *pg, |
| 288 | u16 num_of_pages, u32 pte_offset) |
| 289 | { |
| 290 | u16 page_idx; |
| 291 | u64 addr; |
| 292 | u32 low; |
| 293 | u32 high; |
| 294 | u32 offset; |
| 295 | |
| 296 | offset = ACP_DAGB_GRP_SRBM_SRAM_BASE_OFFSET + (pte_offset * 8); |
| 297 | for (page_idx = 0; page_idx < (num_of_pages); page_idx++) { |
| 298 | /* Load the low address of page int ACP SRAM through SRBM */ |
| 299 | acp_reg_write((offset + (page_idx * 8)), |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 300 | acp_mmio, mmACP_SRBM_Targ_Idx_Addr); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 301 | addr = page_to_phys(pg); |
| 302 | |
| 303 | low = lower_32_bits(addr); |
| 304 | high = upper_32_bits(addr); |
| 305 | |
| 306 | acp_reg_write(low, acp_mmio, mmACP_SRBM_Targ_Idx_Data); |
| 307 | |
| 308 | /* Load the High address of page int ACP SRAM through SRBM */ |
| 309 | acp_reg_write((offset + (page_idx * 8) + 4), |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 310 | acp_mmio, mmACP_SRBM_Targ_Idx_Addr); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 311 | |
| 312 | /* page enable in ACP */ |
| 313 | high |= BIT(31); |
| 314 | acp_reg_write(high, acp_mmio, mmACP_SRBM_Targ_Idx_Data); |
| 315 | |
| 316 | /* Move to next physically contiguos page */ |
| 317 | pg++; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | static void config_acp_dma(void __iomem *acp_mmio, |
Mukunda, Vijendar | 8349b7f | 2018-04-26 16:45:47 +0530 | [diff] [blame] | 322 | struct audio_substream_data *rtd, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 323 | u32 asic_type) |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 324 | { |
Mukunda, Vijendar | 8349b7f | 2018-04-26 16:45:47 +0530 | [diff] [blame] | 325 | acp_pte_config(acp_mmio, rtd->pg, rtd->num_of_pages, |
Mukunda, Vijendar | e188c52 | 2018-05-08 10:17:47 +0530 | [diff] [blame] | 326 | rtd->pte_offset); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 327 | /* Configure System memory <-> ACP SRAM DMA descriptors */ |
Mukunda, Vijendar | 8349b7f | 2018-04-26 16:45:47 +0530 | [diff] [blame] | 328 | set_acp_sysmem_dma_descriptors(acp_mmio, rtd->size, |
Mukunda, Vijendar | e188c52 | 2018-05-08 10:17:47 +0530 | [diff] [blame] | 329 | rtd->direction, rtd->pte_offset, |
Mukunda, Vijendar | 18e8a40 | 2018-05-08 10:17:48 +0530 | [diff] [blame] | 330 | rtd->ch1, rtd->sram_bank, |
Vijendar Mukunda | 8769bb5 | 2018-05-08 10:17:44 +0530 | [diff] [blame] | 331 | rtd->dma_dscr_idx_1, asic_type); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 332 | /* Configure ACP SRAM <-> I2S DMA descriptors */ |
Mukunda, Vijendar | 8349b7f | 2018-04-26 16:45:47 +0530 | [diff] [blame] | 333 | set_acp_to_i2s_dma_descriptors(acp_mmio, rtd->size, |
Mukunda, Vijendar | 18e8a40 | 2018-05-08 10:17:48 +0530 | [diff] [blame] | 334 | rtd->direction, rtd->sram_bank, |
Vijendar Mukunda | 8769bb5 | 2018-05-08 10:17:44 +0530 | [diff] [blame] | 335 | rtd->destination, rtd->ch2, |
| 336 | rtd->dma_dscr_idx_2, asic_type); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 337 | } |
| 338 | |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame^] | 339 | static void acp_dma_cap_channel_enable(void __iomem *acp_mmio, |
| 340 | u16 cap_channel) |
| 341 | { |
| 342 | u32 val, ch_reg, imr_reg, res_reg; |
| 343 | |
| 344 | switch (cap_channel) { |
| 345 | case CAP_CHANNEL1: |
| 346 | ch_reg = mmACP_I2SMICSP_RER1; |
| 347 | res_reg = mmACP_I2SMICSP_RCR1; |
| 348 | imr_reg = mmACP_I2SMICSP_IMR1; |
| 349 | break; |
| 350 | case CAP_CHANNEL0: |
| 351 | default: |
| 352 | ch_reg = mmACP_I2SMICSP_RER0; |
| 353 | res_reg = mmACP_I2SMICSP_RCR0; |
| 354 | imr_reg = mmACP_I2SMICSP_IMR0; |
| 355 | break; |
| 356 | } |
| 357 | val = acp_reg_read(acp_mmio, |
| 358 | mmACP_I2S_16BIT_RESOLUTION_EN); |
| 359 | if (val & ACP_I2S_MIC_16BIT_RESOLUTION_EN) { |
| 360 | acp_reg_write(0x0, acp_mmio, ch_reg); |
| 361 | /* Set 16bit resolution on capture */ |
| 362 | acp_reg_write(0x2, acp_mmio, res_reg); |
| 363 | } |
| 364 | val = acp_reg_read(acp_mmio, imr_reg); |
| 365 | val &= ~ACP_I2SMICSP_IMR1__I2SMICSP_RXDAM_MASK; |
| 366 | val &= ~ACP_I2SMICSP_IMR1__I2SMICSP_RXFOM_MASK; |
| 367 | acp_reg_write(val, acp_mmio, imr_reg); |
| 368 | acp_reg_write(0x1, acp_mmio, ch_reg); |
| 369 | } |
| 370 | |
| 371 | static void acp_dma_cap_channel_disable(void __iomem *acp_mmio, |
| 372 | u16 cap_channel) |
| 373 | { |
| 374 | u32 val, ch_reg, imr_reg; |
| 375 | |
| 376 | switch (cap_channel) { |
| 377 | case CAP_CHANNEL1: |
| 378 | imr_reg = mmACP_I2SMICSP_IMR1; |
| 379 | ch_reg = mmACP_I2SMICSP_RER1; |
| 380 | break; |
| 381 | case CAP_CHANNEL0: |
| 382 | default: |
| 383 | imr_reg = mmACP_I2SMICSP_IMR0; |
| 384 | ch_reg = mmACP_I2SMICSP_RER0; |
| 385 | break; |
| 386 | } |
| 387 | val = acp_reg_read(acp_mmio, imr_reg); |
| 388 | val |= ACP_I2SMICSP_IMR1__I2SMICSP_RXDAM_MASK; |
| 389 | val |= ACP_I2SMICSP_IMR1__I2SMICSP_RXFOM_MASK; |
| 390 | acp_reg_write(val, acp_mmio, imr_reg); |
| 391 | acp_reg_write(0x0, acp_mmio, ch_reg); |
| 392 | } |
| 393 | |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 394 | /* Start a given DMA channel transfer */ |
Agrawal, Akshu | 6b116df | 2018-05-28 11:48:22 +0800 | [diff] [blame] | 395 | static void acp_dma_start(void __iomem *acp_mmio, u16 ch_num) |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 396 | { |
| 397 | u32 dma_ctrl; |
| 398 | |
| 399 | /* read the dma control register and disable the channel run field */ |
| 400 | dma_ctrl = acp_reg_read(acp_mmio, mmACP_DMA_CNTL_0 + ch_num); |
| 401 | |
| 402 | /* Invalidating the DAGB cache */ |
| 403 | acp_reg_write(1, acp_mmio, mmACP_DAGB_ATU_CTRL); |
| 404 | |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 405 | /* |
| 406 | * configure the DMA channel and start the DMA transfer |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 407 | * set dmachrun bit to start the transfer and enable the |
| 408 | * interrupt on completion of the dma transfer |
| 409 | */ |
| 410 | dma_ctrl |= ACP_DMA_CNTL_0__DMAChRun_MASK; |
| 411 | |
| 412 | switch (ch_num) { |
| 413 | case ACP_TO_I2S_DMA_CH_NUM: |
| 414 | case ACP_TO_SYSRAM_CH_NUM: |
| 415 | case I2S_TO_ACP_DMA_CH_NUM: |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 416 | case ACP_TO_I2S_DMA_BT_INSTANCE_CH_NUM: |
| 417 | case ACP_TO_SYSRAM_BT_INSTANCE_CH_NUM: |
| 418 | case I2S_TO_ACP_DMA_BT_INSTANCE_CH_NUM: |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 419 | dma_ctrl |= ACP_DMA_CNTL_0__DMAChIOCEn_MASK; |
| 420 | break; |
| 421 | default: |
| 422 | dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChIOCEn_MASK; |
| 423 | break; |
| 424 | } |
| 425 | |
Agrawal, Akshu | 6b116df | 2018-05-28 11:48:22 +0800 | [diff] [blame] | 426 | /* circular for both DMA channel */ |
| 427 | dma_ctrl |= ACP_DMA_CNTL_0__Circular_DMA_En_MASK; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 428 | |
| 429 | acp_reg_write(dma_ctrl, acp_mmio, mmACP_DMA_CNTL_0 + ch_num); |
| 430 | } |
| 431 | |
| 432 | /* Stop a given DMA channel transfer */ |
| 433 | static int acp_dma_stop(void __iomem *acp_mmio, u8 ch_num) |
| 434 | { |
| 435 | u32 dma_ctrl; |
| 436 | u32 dma_ch_sts; |
| 437 | u32 count = ACP_DMA_RESET_TIME; |
| 438 | |
| 439 | dma_ctrl = acp_reg_read(acp_mmio, mmACP_DMA_CNTL_0 + ch_num); |
| 440 | |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 441 | /* |
| 442 | * clear the dma control register fields before writing zero |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 443 | * in reset bit |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 444 | */ |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 445 | dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChRun_MASK; |
| 446 | dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChIOCEn_MASK; |
| 447 | |
| 448 | acp_reg_write(dma_ctrl, acp_mmio, mmACP_DMA_CNTL_0 + ch_num); |
| 449 | dma_ch_sts = acp_reg_read(acp_mmio, mmACP_DMA_CH_STS); |
| 450 | |
| 451 | if (dma_ch_sts & BIT(ch_num)) { |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 452 | /* |
| 453 | * set the reset bit for this channel to stop the dma |
| 454 | * transfer |
| 455 | */ |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 456 | dma_ctrl |= ACP_DMA_CNTL_0__DMAChRst_MASK; |
| 457 | acp_reg_write(dma_ctrl, acp_mmio, mmACP_DMA_CNTL_0 + ch_num); |
| 458 | } |
| 459 | |
| 460 | /* check the channel status bit for some time and return the status */ |
| 461 | while (true) { |
| 462 | dma_ch_sts = acp_reg_read(acp_mmio, mmACP_DMA_CH_STS); |
| 463 | if (!(dma_ch_sts & BIT(ch_num))) { |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 464 | /* |
| 465 | * clear the reset flag after successfully stopping |
| 466 | * the dma transfer and break from the loop |
| 467 | */ |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 468 | dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChRst_MASK; |
| 469 | |
| 470 | acp_reg_write(dma_ctrl, acp_mmio, mmACP_DMA_CNTL_0 |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 471 | + ch_num); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 472 | break; |
| 473 | } |
| 474 | if (--count == 0) { |
| 475 | pr_err("Failed to stop ACP DMA channel : %d\n", ch_num); |
| 476 | return -ETIMEDOUT; |
| 477 | } |
| 478 | udelay(100); |
| 479 | } |
| 480 | return 0; |
| 481 | } |
| 482 | |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 483 | static void acp_set_sram_bank_state(void __iomem *acp_mmio, u16 bank, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 484 | bool power_on) |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 485 | { |
| 486 | u32 val, req_reg, sts_reg, sts_reg_mask; |
| 487 | u32 loops = 1000; |
| 488 | |
| 489 | if (bank < 32) { |
| 490 | req_reg = mmACP_MEM_SHUT_DOWN_REQ_LO; |
| 491 | sts_reg = mmACP_MEM_SHUT_DOWN_STS_LO; |
| 492 | sts_reg_mask = 0xFFFFFFFF; |
| 493 | |
| 494 | } else { |
| 495 | bank -= 32; |
| 496 | req_reg = mmACP_MEM_SHUT_DOWN_REQ_HI; |
| 497 | sts_reg = mmACP_MEM_SHUT_DOWN_STS_HI; |
| 498 | sts_reg_mask = 0x0000FFFF; |
| 499 | } |
| 500 | |
| 501 | val = acp_reg_read(acp_mmio, req_reg); |
| 502 | if (val & (1 << bank)) { |
| 503 | /* bank is in off state */ |
| 504 | if (power_on == true) |
| 505 | /* request to on */ |
| 506 | val &= ~(1 << bank); |
| 507 | else |
| 508 | /* request to off */ |
| 509 | return; |
| 510 | } else { |
| 511 | /* bank is in on state */ |
| 512 | if (power_on == false) |
| 513 | /* request to off */ |
| 514 | val |= 1 << bank; |
| 515 | else |
| 516 | /* request to on */ |
| 517 | return; |
| 518 | } |
| 519 | acp_reg_write(val, acp_mmio, req_reg); |
| 520 | |
| 521 | while (acp_reg_read(acp_mmio, sts_reg) != sts_reg_mask) { |
| 522 | if (!loops--) { |
| 523 | pr_err("ACP SRAM bank %d state change failed\n", bank); |
| 524 | break; |
| 525 | } |
| 526 | cpu_relax(); |
| 527 | } |
| 528 | } |
| 529 | |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 530 | /* Initialize and bring ACP hardware to default state. */ |
Vijendar Mukunda | 607b39e | 2017-10-18 12:13:57 -0400 | [diff] [blame] | 531 | static int acp_init(void __iomem *acp_mmio, u32 asic_type) |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 532 | { |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 533 | u16 bank; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 534 | u32 val, count, sram_pte_offset; |
| 535 | |
| 536 | /* Assert Soft reset of ACP */ |
| 537 | val = acp_reg_read(acp_mmio, mmACP_SOFT_RESET); |
| 538 | |
| 539 | val |= ACP_SOFT_RESET__SoftResetAud_MASK; |
| 540 | acp_reg_write(val, acp_mmio, mmACP_SOFT_RESET); |
| 541 | |
| 542 | count = ACP_SOFT_RESET_DONE_TIME_OUT_VALUE; |
| 543 | while (true) { |
| 544 | val = acp_reg_read(acp_mmio, mmACP_SOFT_RESET); |
| 545 | if (ACP_SOFT_RESET__SoftResetAudDone_MASK == |
| 546 | (val & ACP_SOFT_RESET__SoftResetAudDone_MASK)) |
| 547 | break; |
| 548 | if (--count == 0) { |
| 549 | pr_err("Failed to reset ACP\n"); |
| 550 | return -ETIMEDOUT; |
| 551 | } |
| 552 | udelay(100); |
| 553 | } |
| 554 | |
| 555 | /* Enable clock to ACP and wait until the clock is enabled */ |
| 556 | val = acp_reg_read(acp_mmio, mmACP_CONTROL); |
| 557 | val = val | ACP_CONTROL__ClkEn_MASK; |
| 558 | acp_reg_write(val, acp_mmio, mmACP_CONTROL); |
| 559 | |
| 560 | count = ACP_CLOCK_EN_TIME_OUT_VALUE; |
| 561 | |
| 562 | while (true) { |
| 563 | val = acp_reg_read(acp_mmio, mmACP_STATUS); |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 564 | if (val & (u32)0x1) |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 565 | break; |
| 566 | if (--count == 0) { |
| 567 | pr_err("Failed to reset ACP\n"); |
| 568 | return -ETIMEDOUT; |
| 569 | } |
| 570 | udelay(100); |
| 571 | } |
| 572 | |
| 573 | /* Deassert the SOFT RESET flags */ |
| 574 | val = acp_reg_read(acp_mmio, mmACP_SOFT_RESET); |
| 575 | val &= ~ACP_SOFT_RESET__SoftResetAud_MASK; |
| 576 | acp_reg_write(val, acp_mmio, mmACP_SOFT_RESET); |
| 577 | |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 578 | /* For BT instance change pins from UART to BT */ |
| 579 | if (!bt_uart_enable) { |
| 580 | val = acp_reg_read(acp_mmio, mmACP_BT_UART_PAD_SEL); |
| 581 | val |= ACP_BT_UART_PAD_SELECT_MASK; |
| 582 | acp_reg_write(val, acp_mmio, mmACP_BT_UART_PAD_SEL); |
| 583 | } |
| 584 | |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 585 | /* initiailize Onion control DAGB register */ |
| 586 | acp_reg_write(ACP_ONION_CNTL_DEFAULT, acp_mmio, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 587 | mmACP_AXI2DAGB_ONION_CNTL); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 588 | |
| 589 | /* initiailize Garlic control DAGB registers */ |
| 590 | acp_reg_write(ACP_GARLIC_CNTL_DEFAULT, acp_mmio, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 591 | mmACP_AXI2DAGB_GARLIC_CNTL); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 592 | |
| 593 | sram_pte_offset = ACP_DAGB_GRP_SRAM_BASE_ADDRESS | |
| 594 | ACP_DAGB_BASE_ADDR_GRP_1__AXI2DAGBSnoopSel_MASK | |
| 595 | ACP_DAGB_BASE_ADDR_GRP_1__AXI2DAGBTargetMemSel_MASK | |
| 596 | ACP_DAGB_BASE_ADDR_GRP_1__AXI2DAGBGrpEnable_MASK; |
| 597 | acp_reg_write(sram_pte_offset, acp_mmio, mmACP_DAGB_BASE_ADDR_GRP_1); |
| 598 | acp_reg_write(ACP_PAGE_SIZE_4K_ENABLE, acp_mmio, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 599 | mmACP_DAGB_PAGE_SIZE_GRP_1); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 600 | |
| 601 | acp_reg_write(ACP_SRAM_BASE_ADDRESS, acp_mmio, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 602 | mmACP_DMA_DESC_BASE_ADDR); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 603 | |
| 604 | /* Num of descriptiors in SRAM 0x4, means 256 descriptors;(64 * 4) */ |
| 605 | acp_reg_write(0x4, acp_mmio, mmACP_DMA_DESC_MAX_NUM_DSCR); |
| 606 | acp_reg_write(ACP_EXTERNAL_INTR_CNTL__DMAIOCMask_MASK, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 607 | acp_mmio, mmACP_EXTERNAL_INTR_CNTL); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 608 | |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 609 | /* |
| 610 | * When ACP_TILE_P1 is turned on, all SRAM banks get turned on. |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 611 | * Now, turn off all of them. This can't be done in 'poweron' of |
| 612 | * ACP pm domain, as this requires ACP to be initialized. |
Vijendar Mukunda | 607b39e | 2017-10-18 12:13:57 -0400 | [diff] [blame] | 613 | * For Stoney, Memory gating is disabled,i.e SRAM Banks |
| 614 | * won't be turned off. The default state for SRAM banks is ON. |
| 615 | * Setting SRAM bank state code skipped for STONEY platform. |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 616 | */ |
Vijendar Mukunda | 607b39e | 2017-10-18 12:13:57 -0400 | [diff] [blame] | 617 | if (asic_type != CHIP_STONEY) { |
| 618 | for (bank = 1; bank < 48; bank++) |
| 619 | acp_set_sram_bank_state(acp_mmio, bank, false); |
| 620 | } |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 621 | return 0; |
| 622 | } |
| 623 | |
Masahiro Yamada | 1cce200 | 2017-02-27 14:29:45 -0800 | [diff] [blame] | 624 | /* Deinitialize ACP */ |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 625 | static int acp_deinit(void __iomem *acp_mmio) |
| 626 | { |
| 627 | u32 val; |
| 628 | u32 count; |
| 629 | |
| 630 | /* Assert Soft reset of ACP */ |
| 631 | val = acp_reg_read(acp_mmio, mmACP_SOFT_RESET); |
| 632 | |
| 633 | val |= ACP_SOFT_RESET__SoftResetAud_MASK; |
| 634 | acp_reg_write(val, acp_mmio, mmACP_SOFT_RESET); |
| 635 | |
| 636 | count = ACP_SOFT_RESET_DONE_TIME_OUT_VALUE; |
| 637 | while (true) { |
| 638 | val = acp_reg_read(acp_mmio, mmACP_SOFT_RESET); |
| 639 | if (ACP_SOFT_RESET__SoftResetAudDone_MASK == |
| 640 | (val & ACP_SOFT_RESET__SoftResetAudDone_MASK)) |
| 641 | break; |
| 642 | if (--count == 0) { |
| 643 | pr_err("Failed to reset ACP\n"); |
| 644 | return -ETIMEDOUT; |
| 645 | } |
| 646 | udelay(100); |
| 647 | } |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 648 | /* Disable ACP clock */ |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 649 | val = acp_reg_read(acp_mmio, mmACP_CONTROL); |
| 650 | val &= ~ACP_CONTROL__ClkEn_MASK; |
| 651 | acp_reg_write(val, acp_mmio, mmACP_CONTROL); |
| 652 | |
| 653 | count = ACP_CLOCK_EN_TIME_OUT_VALUE; |
| 654 | |
| 655 | while (true) { |
| 656 | val = acp_reg_read(acp_mmio, mmACP_STATUS); |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 657 | if (!(val & (u32)0x1)) |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 658 | break; |
| 659 | if (--count == 0) { |
| 660 | pr_err("Failed to reset ACP\n"); |
| 661 | return -ETIMEDOUT; |
| 662 | } |
| 663 | udelay(100); |
| 664 | } |
| 665 | return 0; |
| 666 | } |
| 667 | |
| 668 | /* ACP DMA irq handler routine for playback, capture usecases */ |
| 669 | static irqreturn_t dma_irq_handler(int irq, void *arg) |
| 670 | { |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 671 | u32 intr_flag, ext_intr_status; |
| 672 | struct audio_drv_data *irq_data; |
| 673 | void __iomem *acp_mmio; |
| 674 | struct device *dev = arg; |
| 675 | bool valid_irq = false; |
| 676 | |
| 677 | irq_data = dev_get_drvdata(dev); |
| 678 | acp_mmio = irq_data->acp_mmio; |
| 679 | |
| 680 | ext_intr_status = acp_reg_read(acp_mmio, mmACP_EXTERNAL_INTR_STAT); |
| 681 | intr_flag = (((ext_intr_status & |
| 682 | ACP_EXTERNAL_INTR_STAT__DMAIOCStat_MASK) >> |
| 683 | ACP_EXTERNAL_INTR_STAT__DMAIOCStat__SHIFT)); |
| 684 | |
| 685 | if ((intr_flag & BIT(ACP_TO_I2S_DMA_CH_NUM)) != 0) { |
| 686 | valid_irq = true; |
Mukunda, Vijendar | e21358c | 2018-02-16 13:03:46 +0530 | [diff] [blame] | 687 | snd_pcm_period_elapsed(irq_data->play_i2ssp_stream); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 688 | acp_reg_write((intr_flag & BIT(ACP_TO_I2S_DMA_CH_NUM)) << 16, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 689 | acp_mmio, mmACP_EXTERNAL_INTR_STAT); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 690 | } |
| 691 | |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 692 | if ((intr_flag & BIT(ACP_TO_I2S_DMA_BT_INSTANCE_CH_NUM)) != 0) { |
| 693 | valid_irq = true; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 694 | snd_pcm_period_elapsed(irq_data->play_i2sbt_stream); |
| 695 | acp_reg_write((intr_flag & |
| 696 | BIT(ACP_TO_I2S_DMA_BT_INSTANCE_CH_NUM)) << 16, |
| 697 | acp_mmio, mmACP_EXTERNAL_INTR_STAT); |
| 698 | } |
| 699 | |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 700 | if ((intr_flag & BIT(I2S_TO_ACP_DMA_CH_NUM)) != 0) { |
| 701 | valid_irq = true; |
Agrawal, Akshu | 6b116df | 2018-05-28 11:48:22 +0800 | [diff] [blame] | 702 | snd_pcm_period_elapsed(irq_data->capture_i2ssp_stream); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 703 | acp_reg_write((intr_flag & BIT(I2S_TO_ACP_DMA_CH_NUM)) << 16, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 704 | acp_mmio, mmACP_EXTERNAL_INTR_STAT); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | if ((intr_flag & BIT(ACP_TO_SYSRAM_CH_NUM)) != 0) { |
| 708 | valid_irq = true; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 709 | acp_reg_write((intr_flag & BIT(ACP_TO_SYSRAM_CH_NUM)) << 16, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 710 | acp_mmio, mmACP_EXTERNAL_INTR_STAT); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 711 | } |
| 712 | |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 713 | if ((intr_flag & BIT(I2S_TO_ACP_DMA_BT_INSTANCE_CH_NUM)) != 0) { |
| 714 | valid_irq = true; |
Agrawal, Akshu | 6b116df | 2018-05-28 11:48:22 +0800 | [diff] [blame] | 715 | snd_pcm_period_elapsed(irq_data->capture_i2sbt_stream); |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 716 | acp_reg_write((intr_flag & |
| 717 | BIT(I2S_TO_ACP_DMA_BT_INSTANCE_CH_NUM)) << 16, |
| 718 | acp_mmio, mmACP_EXTERNAL_INTR_STAT); |
| 719 | } |
| 720 | |
| 721 | if ((intr_flag & BIT(ACP_TO_SYSRAM_BT_INSTANCE_CH_NUM)) != 0) { |
| 722 | valid_irq = true; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 723 | acp_reg_write((intr_flag & |
| 724 | BIT(ACP_TO_SYSRAM_BT_INSTANCE_CH_NUM)) << 16, |
| 725 | acp_mmio, mmACP_EXTERNAL_INTR_STAT); |
| 726 | } |
| 727 | |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 728 | if (valid_irq) |
| 729 | return IRQ_HANDLED; |
| 730 | else |
| 731 | return IRQ_NONE; |
| 732 | } |
| 733 | |
| 734 | static int acp_dma_open(struct snd_pcm_substream *substream) |
| 735 | { |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 736 | u16 bank; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 737 | int ret = 0; |
| 738 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 739 | struct snd_soc_pcm_runtime *prtd = substream->private_data; |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 740 | struct snd_soc_component *component = snd_soc_rtdcom_lookup(prtd, |
| 741 | DRV_NAME); |
Kuninori Morimoto | a1042a4 | 2018-01-29 02:44:23 +0000 | [diff] [blame] | 742 | struct audio_drv_data *intr_data = dev_get_drvdata(component->dev); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 743 | struct audio_substream_data *adata = |
| 744 | kzalloc(sizeof(struct audio_substream_data), GFP_KERNEL); |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 745 | if (!adata) |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 746 | return -ENOMEM; |
| 747 | |
Vijendar Mukunda | 9c7d6fa | 2017-10-18 12:13:59 -0400 | [diff] [blame] | 748 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 749 | switch (intr_data->asic_type) { |
| 750 | case CHIP_STONEY: |
| 751 | runtime->hw = acp_st_pcm_hardware_playback; |
| 752 | break; |
| 753 | default: |
| 754 | runtime->hw = acp_pcm_hardware_playback; |
| 755 | } |
| 756 | } else { |
| 757 | switch (intr_data->asic_type) { |
| 758 | case CHIP_STONEY: |
| 759 | runtime->hw = acp_st_pcm_hardware_capture; |
| 760 | break; |
| 761 | default: |
| 762 | runtime->hw = acp_pcm_hardware_capture; |
| 763 | } |
| 764 | } |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 765 | |
| 766 | ret = snd_pcm_hw_constraint_integer(runtime, |
| 767 | SNDRV_PCM_HW_PARAM_PERIODS); |
| 768 | if (ret < 0) { |
Kuninori Morimoto | a1042a4 | 2018-01-29 02:44:23 +0000 | [diff] [blame] | 769 | dev_err(component->dev, "set integer constraint failed\n"); |
Dan Carpenter | cde6bcd | 2016-01-13 15:20:02 +0300 | [diff] [blame] | 770 | kfree(adata); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 771 | return ret; |
| 772 | } |
| 773 | |
| 774 | adata->acp_mmio = intr_data->acp_mmio; |
| 775 | runtime->private_data = adata; |
| 776 | |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 777 | /* |
| 778 | * Enable ACP irq, when neither playback or capture streams are |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 779 | * active by the time when a new stream is being opened. |
| 780 | * This enablement is not required for another stream, if current |
| 781 | * stream is not closed |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 782 | */ |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 783 | if (!intr_data->play_i2ssp_stream && !intr_data->capture_i2ssp_stream && |
| 784 | !intr_data->play_i2sbt_stream && !intr_data->capture_i2sbt_stream) |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 785 | acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); |
| 786 | |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 787 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 788 | /* |
| 789 | * For Stoney, Memory gating is disabled,i.e SRAM Banks |
Vijendar Mukunda | 607b39e | 2017-10-18 12:13:57 -0400 | [diff] [blame] | 790 | * won't be turned off. The default state for SRAM banks is ON. |
| 791 | * Setting SRAM bank state code skipped for STONEY platform. |
| 792 | */ |
| 793 | if (intr_data->asic_type != CHIP_STONEY) { |
| 794 | for (bank = 1; bank <= 4; bank++) |
| 795 | acp_set_sram_bank_state(intr_data->acp_mmio, |
| 796 | bank, true); |
| 797 | } |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 798 | } else { |
Vijendar Mukunda | 607b39e | 2017-10-18 12:13:57 -0400 | [diff] [blame] | 799 | if (intr_data->asic_type != CHIP_STONEY) { |
| 800 | for (bank = 5; bank <= 8; bank++) |
| 801 | acp_set_sram_bank_state(intr_data->acp_mmio, |
| 802 | bank, true); |
| 803 | } |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 804 | } |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 805 | |
| 806 | return 0; |
| 807 | } |
| 808 | |
| 809 | static int acp_dma_hw_params(struct snd_pcm_substream *substream, |
| 810 | struct snd_pcm_hw_params *params) |
| 811 | { |
| 812 | int status; |
| 813 | uint64_t size; |
Vijendar Mukunda | a37d48e | 2018-03-09 21:13:02 +0530 | [diff] [blame] | 814 | u32 val = 0; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 815 | struct page *pg; |
| 816 | struct snd_pcm_runtime *runtime; |
| 817 | struct audio_substream_data *rtd; |
Vijendar Mukunda | aac8974 | 2017-10-18 12:13:58 -0400 | [diff] [blame] | 818 | struct snd_soc_pcm_runtime *prtd = substream->private_data; |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 819 | struct snd_soc_component *component = snd_soc_rtdcom_lookup(prtd, |
| 820 | DRV_NAME); |
Kuninori Morimoto | a1042a4 | 2018-01-29 02:44:23 +0000 | [diff] [blame] | 821 | struct audio_drv_data *adata = dev_get_drvdata(component->dev); |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 822 | struct snd_soc_card *card = prtd->card; |
| 823 | struct acp_platform_info *pinfo = snd_soc_card_get_drvdata(card); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 824 | |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 825 | runtime = substream->runtime; |
| 826 | rtd = runtime->private_data; |
| 827 | |
| 828 | if (WARN_ON(!rtd)) |
| 829 | return -EINVAL; |
| 830 | |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame^] | 831 | if (pinfo) { |
Agrawal, Akshu | 6e56e5d | 2018-06-07 14:48:43 +0800 | [diff] [blame] | 832 | rtd->i2s_instance = pinfo->i2s_instance; |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame^] | 833 | rtd->capture_channel = pinfo->capture_channel; |
| 834 | } |
Vijendar Mukunda | a37d48e | 2018-03-09 21:13:02 +0530 | [diff] [blame] | 835 | if (adata->asic_type == CHIP_STONEY) { |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 836 | val = acp_reg_read(adata->acp_mmio, |
| 837 | mmACP_I2S_16BIT_RESOLUTION_EN); |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 838 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 839 | switch (rtd->i2s_instance) { |
| 840 | case I2S_BT_INSTANCE: |
| 841 | val |= ACP_I2S_BT_16BIT_RESOLUTION_EN; |
| 842 | break; |
| 843 | case I2S_SP_INSTANCE: |
| 844 | default: |
| 845 | val |= ACP_I2S_SP_16BIT_RESOLUTION_EN; |
| 846 | } |
| 847 | } else { |
| 848 | switch (rtd->i2s_instance) { |
| 849 | case I2S_BT_INSTANCE: |
| 850 | val |= ACP_I2S_BT_16BIT_RESOLUTION_EN; |
| 851 | break; |
| 852 | case I2S_SP_INSTANCE: |
| 853 | default: |
| 854 | val |= ACP_I2S_MIC_16BIT_RESOLUTION_EN; |
| 855 | } |
| 856 | } |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 857 | acp_reg_write(val, adata->acp_mmio, |
| 858 | mmACP_I2S_16BIT_RESOLUTION_EN); |
Vijendar Mukunda | a37d48e | 2018-03-09 21:13:02 +0530 | [diff] [blame] | 859 | } |
Vijendar Mukunda | 8769bb5 | 2018-05-08 10:17:44 +0530 | [diff] [blame] | 860 | |
| 861 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 862 | switch (rtd->i2s_instance) { |
| 863 | case I2S_BT_INSTANCE: |
| 864 | rtd->pte_offset = ACP_ST_BT_PLAYBACK_PTE_OFFSET; |
| 865 | rtd->ch1 = SYSRAM_TO_ACP_BT_INSTANCE_CH_NUM; |
| 866 | rtd->ch2 = ACP_TO_I2S_DMA_BT_INSTANCE_CH_NUM; |
| 867 | rtd->sram_bank = ACP_SRAM_BANK_3_ADDRESS; |
| 868 | rtd->destination = TO_BLUETOOTH; |
| 869 | rtd->dma_dscr_idx_1 = PLAYBACK_START_DMA_DESCR_CH8; |
| 870 | rtd->dma_dscr_idx_2 = PLAYBACK_START_DMA_DESCR_CH9; |
| 871 | rtd->byte_cnt_high_reg_offset = |
| 872 | mmACP_I2S_BT_TRANSMIT_BYTE_CNT_HIGH; |
| 873 | rtd->byte_cnt_low_reg_offset = |
| 874 | mmACP_I2S_BT_TRANSMIT_BYTE_CNT_LOW; |
| 875 | adata->play_i2sbt_stream = substream; |
Mukunda, Vijendar | e188c52 | 2018-05-08 10:17:47 +0530 | [diff] [blame] | 876 | break; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 877 | case I2S_SP_INSTANCE: |
Mukunda, Vijendar | e188c52 | 2018-05-08 10:17:47 +0530 | [diff] [blame] | 878 | default: |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 879 | switch (adata->asic_type) { |
| 880 | case CHIP_STONEY: |
| 881 | rtd->pte_offset = ACP_ST_PLAYBACK_PTE_OFFSET; |
| 882 | break; |
| 883 | default: |
| 884 | rtd->pte_offset = ACP_PLAYBACK_PTE_OFFSET; |
| 885 | } |
| 886 | rtd->ch1 = SYSRAM_TO_ACP_CH_NUM; |
| 887 | rtd->ch2 = ACP_TO_I2S_DMA_CH_NUM; |
| 888 | rtd->sram_bank = ACP_SRAM_BANK_1_ADDRESS; |
| 889 | rtd->destination = TO_ACP_I2S_1; |
| 890 | rtd->dma_dscr_idx_1 = PLAYBACK_START_DMA_DESCR_CH12; |
| 891 | rtd->dma_dscr_idx_2 = PLAYBACK_START_DMA_DESCR_CH13; |
| 892 | rtd->byte_cnt_high_reg_offset = |
| 893 | mmACP_I2S_TRANSMIT_BYTE_CNT_HIGH; |
| 894 | rtd->byte_cnt_low_reg_offset = |
| 895 | mmACP_I2S_TRANSMIT_BYTE_CNT_LOW; |
| 896 | adata->play_i2ssp_stream = substream; |
Mukunda, Vijendar | e188c52 | 2018-05-08 10:17:47 +0530 | [diff] [blame] | 897 | } |
Vijendar Mukunda | 8769bb5 | 2018-05-08 10:17:44 +0530 | [diff] [blame] | 898 | } else { |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 899 | switch (rtd->i2s_instance) { |
| 900 | case I2S_BT_INSTANCE: |
| 901 | rtd->pte_offset = ACP_ST_BT_CAPTURE_PTE_OFFSET; |
| 902 | rtd->ch1 = ACP_TO_SYSRAM_BT_INSTANCE_CH_NUM; |
| 903 | rtd->ch2 = I2S_TO_ACP_DMA_BT_INSTANCE_CH_NUM; |
| 904 | rtd->sram_bank = ACP_SRAM_BANK_4_ADDRESS; |
| 905 | rtd->destination = FROM_BLUETOOTH; |
| 906 | rtd->dma_dscr_idx_1 = CAPTURE_START_DMA_DESCR_CH10; |
| 907 | rtd->dma_dscr_idx_2 = CAPTURE_START_DMA_DESCR_CH11; |
| 908 | rtd->byte_cnt_high_reg_offset = |
| 909 | mmACP_I2S_BT_RECEIVE_BYTE_CNT_HIGH; |
| 910 | rtd->byte_cnt_low_reg_offset = |
| 911 | mmACP_I2S_BT_RECEIVE_BYTE_CNT_LOW; |
| 912 | adata->capture_i2sbt_stream = substream; |
Mukunda, Vijendar | e188c52 | 2018-05-08 10:17:47 +0530 | [diff] [blame] | 913 | break; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 914 | case I2S_SP_INSTANCE: |
Mukunda, Vijendar | e188c52 | 2018-05-08 10:17:47 +0530 | [diff] [blame] | 915 | default: |
| 916 | rtd->pte_offset = ACP_CAPTURE_PTE_OFFSET; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 917 | rtd->ch1 = ACP_TO_SYSRAM_CH_NUM; |
| 918 | rtd->ch2 = I2S_TO_ACP_DMA_CH_NUM; |
| 919 | switch (adata->asic_type) { |
| 920 | case CHIP_STONEY: |
| 921 | rtd->pte_offset = ACP_ST_CAPTURE_PTE_OFFSET; |
| 922 | rtd->sram_bank = ACP_SRAM_BANK_2_ADDRESS; |
| 923 | break; |
| 924 | default: |
| 925 | rtd->pte_offset = ACP_CAPTURE_PTE_OFFSET; |
| 926 | rtd->sram_bank = ACP_SRAM_BANK_5_ADDRESS; |
| 927 | } |
| 928 | rtd->destination = FROM_ACP_I2S_1; |
| 929 | rtd->dma_dscr_idx_1 = CAPTURE_START_DMA_DESCR_CH14; |
| 930 | rtd->dma_dscr_idx_2 = CAPTURE_START_DMA_DESCR_CH15; |
| 931 | rtd->byte_cnt_high_reg_offset = |
| 932 | mmACP_I2S_RECEIVED_BYTE_CNT_HIGH; |
| 933 | rtd->byte_cnt_low_reg_offset = |
| 934 | mmACP_I2S_RECEIVED_BYTE_CNT_LOW; |
| 935 | adata->capture_i2ssp_stream = substream; |
Mukunda, Vijendar | e188c52 | 2018-05-08 10:17:47 +0530 | [diff] [blame] | 936 | } |
Vijendar Mukunda | 8769bb5 | 2018-05-08 10:17:44 +0530 | [diff] [blame] | 937 | } |
| 938 | |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 939 | size = params_buffer_bytes(params); |
| 940 | status = snd_pcm_lib_malloc_pages(substream, size); |
| 941 | if (status < 0) |
| 942 | return status; |
| 943 | |
| 944 | memset(substream->runtime->dma_area, 0, params_buffer_bytes(params)); |
| 945 | pg = virt_to_page(substream->dma_buffer.area); |
| 946 | |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 947 | if (pg) { |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 948 | acp_set_sram_bank_state(rtd->acp_mmio, 0, true); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 949 | /* Save for runtime private data */ |
| 950 | rtd->pg = pg; |
| 951 | rtd->order = get_order(size); |
| 952 | |
| 953 | /* Fill the page table entries in ACP SRAM */ |
| 954 | rtd->pg = pg; |
| 955 | rtd->size = size; |
| 956 | rtd->num_of_pages = PAGE_ALIGN(size) >> PAGE_SHIFT; |
| 957 | rtd->direction = substream->stream; |
| 958 | |
Vijendar Mukunda | aac8974 | 2017-10-18 12:13:58 -0400 | [diff] [blame] | 959 | config_acp_dma(rtd->acp_mmio, rtd, adata->asic_type); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 960 | status = 0; |
| 961 | } else { |
| 962 | status = -ENOMEM; |
| 963 | } |
| 964 | return status; |
| 965 | } |
| 966 | |
| 967 | static int acp_dma_hw_free(struct snd_pcm_substream *substream) |
| 968 | { |
| 969 | return snd_pcm_lib_free_pages(substream); |
| 970 | } |
| 971 | |
Vijendar Mukunda | 7f00484 | 2018-05-08 10:17:45 +0530 | [diff] [blame] | 972 | static u64 acp_get_byte_count(struct audio_substream_data *rtd) |
Vijendar Mukunda | 61add81 | 2017-11-03 16:35:43 -0400 | [diff] [blame] | 973 | { |
Vijendar Mukunda | 7f00484 | 2018-05-08 10:17:45 +0530 | [diff] [blame] | 974 | union acp_dma_count byte_count; |
Vijendar Mukunda | 61add81 | 2017-11-03 16:35:43 -0400 | [diff] [blame] | 975 | |
Vijendar Mukunda | 7f00484 | 2018-05-08 10:17:45 +0530 | [diff] [blame] | 976 | byte_count.bcount.high = acp_reg_read(rtd->acp_mmio, |
| 977 | rtd->byte_cnt_high_reg_offset); |
| 978 | byte_count.bcount.low = acp_reg_read(rtd->acp_mmio, |
| 979 | rtd->byte_cnt_low_reg_offset); |
| 980 | return byte_count.bytescount; |
Vijendar Mukunda | 61add81 | 2017-11-03 16:35:43 -0400 | [diff] [blame] | 981 | } |
| 982 | |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 983 | static snd_pcm_uframes_t acp_dma_pointer(struct snd_pcm_substream *substream) |
| 984 | { |
Vijendar Mukunda | 61add81 | 2017-11-03 16:35:43 -0400 | [diff] [blame] | 985 | u32 buffersize; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 986 | u32 pos = 0; |
Vijendar Mukunda | 61add81 | 2017-11-03 16:35:43 -0400 | [diff] [blame] | 987 | u64 bytescount = 0; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 988 | |
| 989 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 990 | struct audio_substream_data *rtd = runtime->private_data; |
| 991 | |
Mukunda, Vijendar | 7afa535 | 2017-12-04 20:46:24 +0530 | [diff] [blame] | 992 | if (!rtd) |
| 993 | return -EINVAL; |
| 994 | |
Vijendar Mukunda | 61add81 | 2017-11-03 16:35:43 -0400 | [diff] [blame] | 995 | buffersize = frames_to_bytes(runtime, runtime->buffer_size); |
Vijendar Mukunda | 7f00484 | 2018-05-08 10:17:45 +0530 | [diff] [blame] | 996 | bytescount = acp_get_byte_count(rtd); |
Vijendar Mukunda | 61add81 | 2017-11-03 16:35:43 -0400 | [diff] [blame] | 997 | |
Vijendar Mukunda | 9af8937 | 2018-05-08 10:17:46 +0530 | [diff] [blame] | 998 | if (bytescount > rtd->bytescount) |
| 999 | bytescount -= rtd->bytescount; |
Guenter Roeck | 7db08b2 | 2017-11-08 16:34:54 -0500 | [diff] [blame] | 1000 | pos = do_div(bytescount, buffersize); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1001 | return bytes_to_frames(runtime, pos); |
| 1002 | } |
| 1003 | |
| 1004 | static int acp_dma_mmap(struct snd_pcm_substream *substream, |
| 1005 | struct vm_area_struct *vma) |
| 1006 | { |
| 1007 | return snd_pcm_lib_default_mmap(substream, vma); |
| 1008 | } |
| 1009 | |
| 1010 | static int acp_dma_prepare(struct snd_pcm_substream *substream) |
| 1011 | { |
| 1012 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1013 | struct audio_substream_data *rtd = runtime->private_data; |
| 1014 | |
Mukunda, Vijendar | 7afa535 | 2017-12-04 20:46:24 +0530 | [diff] [blame] | 1015 | if (!rtd) |
| 1016 | return -EINVAL; |
Vijendar Mukunda | 8769bb5 | 2018-05-08 10:17:44 +0530 | [diff] [blame] | 1017 | |
| 1018 | config_acp_dma_channel(rtd->acp_mmio, |
| 1019 | rtd->ch1, |
| 1020 | rtd->dma_dscr_idx_1, |
| 1021 | NUM_DSCRS_PER_CHANNEL, 0); |
| 1022 | config_acp_dma_channel(rtd->acp_mmio, |
| 1023 | rtd->ch2, |
| 1024 | rtd->dma_dscr_idx_2, |
| 1025 | NUM_DSCRS_PER_CHANNEL, 0); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1026 | return 0; |
| 1027 | } |
| 1028 | |
| 1029 | static int acp_dma_trigger(struct snd_pcm_substream *substream, int cmd) |
| 1030 | { |
| 1031 | int ret; |
Vijendar Mukunda | 61add81 | 2017-11-03 16:35:43 -0400 | [diff] [blame] | 1032 | u64 bytescount = 0; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1033 | |
| 1034 | struct snd_pcm_runtime *runtime = substream->runtime; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1035 | struct audio_substream_data *rtd = runtime->private_data; |
| 1036 | |
| 1037 | if (!rtd) |
| 1038 | return -EINVAL; |
| 1039 | switch (cmd) { |
| 1040 | case SNDRV_PCM_TRIGGER_START: |
| 1041 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 1042 | case SNDRV_PCM_TRIGGER_RESUME: |
Vijendar Mukunda | 7f00484 | 2018-05-08 10:17:45 +0530 | [diff] [blame] | 1043 | bytescount = acp_get_byte_count(rtd); |
Vijendar Mukunda | 9af8937 | 2018-05-08 10:17:46 +0530 | [diff] [blame] | 1044 | if (rtd->bytescount == 0) |
| 1045 | rtd->bytescount = bytescount; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1046 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Agrawal, Akshu | 6b116df | 2018-05-28 11:48:22 +0800 | [diff] [blame] | 1047 | acp_dma_start(rtd->acp_mmio, rtd->ch1); |
| 1048 | acp_dma_start(rtd->acp_mmio, rtd->ch2); |
| 1049 | } else { |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame^] | 1050 | if (rtd->capture_channel == CAP_CHANNEL0) { |
| 1051 | acp_dma_cap_channel_disable(rtd->acp_mmio, |
| 1052 | CAP_CHANNEL1); |
| 1053 | acp_dma_cap_channel_enable(rtd->acp_mmio, |
| 1054 | CAP_CHANNEL0); |
| 1055 | } |
| 1056 | if (rtd->capture_channel == CAP_CHANNEL1) { |
| 1057 | acp_dma_cap_channel_disable(rtd->acp_mmio, |
| 1058 | CAP_CHANNEL0); |
| 1059 | acp_dma_cap_channel_enable(rtd->acp_mmio, |
| 1060 | CAP_CHANNEL1); |
| 1061 | } |
Agrawal, Akshu | 6b116df | 2018-05-28 11:48:22 +0800 | [diff] [blame] | 1062 | acp_dma_start(rtd->acp_mmio, rtd->ch2); |
| 1063 | acp_dma_start(rtd->acp_mmio, rtd->ch1); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1064 | } |
| 1065 | ret = 0; |
| 1066 | break; |
| 1067 | case SNDRV_PCM_TRIGGER_STOP: |
| 1068 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 1069 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Vijendar Mukunda | 8769bb5 | 2018-05-08 10:17:44 +0530 | [diff] [blame] | 1070 | /* For playback, non circular dma should be stopped first |
| 1071 | * i.e Sysram to acp dma transfer channel(rtd->ch1) should be |
| 1072 | * stopped before stopping cirular dma which is acp sram to i2s |
| 1073 | * fifo dma transfer channel(rtd->ch2). Where as in Capture |
| 1074 | * scenario, i2s fifo to acp sram dma channel(rtd->ch2) stopped |
| 1075 | * first before stopping acp sram to sysram which is circular |
| 1076 | * dma(rtd->ch1). |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1077 | */ |
Vijendar Mukunda | 61add81 | 2017-11-03 16:35:43 -0400 | [diff] [blame] | 1078 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Vijendar Mukunda | 8769bb5 | 2018-05-08 10:17:44 +0530 | [diff] [blame] | 1079 | acp_dma_stop(rtd->acp_mmio, rtd->ch1); |
| 1080 | ret = acp_dma_stop(rtd->acp_mmio, rtd->ch2); |
Vijendar Mukunda | 61add81 | 2017-11-03 16:35:43 -0400 | [diff] [blame] | 1081 | } else { |
Vijendar Mukunda | 8769bb5 | 2018-05-08 10:17:44 +0530 | [diff] [blame] | 1082 | acp_dma_stop(rtd->acp_mmio, rtd->ch2); |
| 1083 | ret = acp_dma_stop(rtd->acp_mmio, rtd->ch1); |
Vijendar Mukunda | 61add81 | 2017-11-03 16:35:43 -0400 | [diff] [blame] | 1084 | } |
Vijendar Mukunda | 9af8937 | 2018-05-08 10:17:46 +0530 | [diff] [blame] | 1085 | rtd->bytescount = 0; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1086 | break; |
| 1087 | default: |
| 1088 | ret = -EINVAL; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1089 | } |
| 1090 | return ret; |
| 1091 | } |
| 1092 | |
| 1093 | static int acp_dma_new(struct snd_soc_pcm_runtime *rtd) |
| 1094 | { |
Vijendar Mukunda | 9c7d6fa | 2017-10-18 12:13:59 -0400 | [diff] [blame] | 1095 | int ret; |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 1096 | struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, |
| 1097 | DRV_NAME); |
Kuninori Morimoto | a1042a4 | 2018-01-29 02:44:23 +0000 | [diff] [blame] | 1098 | struct audio_drv_data *adata = dev_get_drvdata(component->dev); |
Vijendar Mukunda | 9c7d6fa | 2017-10-18 12:13:59 -0400 | [diff] [blame] | 1099 | |
| 1100 | switch (adata->asic_type) { |
| 1101 | case CHIP_STONEY: |
| 1102 | ret = snd_pcm_lib_preallocate_pages_for_all(rtd->pcm, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 1103 | SNDRV_DMA_TYPE_DEV, |
| 1104 | NULL, ST_MIN_BUFFER, |
| 1105 | ST_MAX_BUFFER); |
Vijendar Mukunda | 9c7d6fa | 2017-10-18 12:13:59 -0400 | [diff] [blame] | 1106 | break; |
| 1107 | default: |
| 1108 | ret = snd_pcm_lib_preallocate_pages_for_all(rtd->pcm, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 1109 | SNDRV_DMA_TYPE_DEV, |
| 1110 | NULL, MIN_BUFFER, |
| 1111 | MAX_BUFFER); |
Vijendar Mukunda | 9c7d6fa | 2017-10-18 12:13:59 -0400 | [diff] [blame] | 1112 | break; |
| 1113 | } |
| 1114 | if (ret < 0) |
Kuninori Morimoto | a1042a4 | 2018-01-29 02:44:23 +0000 | [diff] [blame] | 1115 | dev_err(component->dev, |
Colin Ian King | 9e6a469 | 2018-05-01 09:20:01 +0100 | [diff] [blame] | 1116 | "buffer preallocation failure error:%d\n", ret); |
Vijendar Mukunda | 9c7d6fa | 2017-10-18 12:13:59 -0400 | [diff] [blame] | 1117 | return ret; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | static int acp_dma_close(struct snd_pcm_substream *substream) |
| 1121 | { |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 1122 | u16 bank; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1123 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1124 | struct audio_substream_data *rtd = runtime->private_data; |
| 1125 | struct snd_soc_pcm_runtime *prtd = substream->private_data; |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 1126 | struct snd_soc_component *component = snd_soc_rtdcom_lookup(prtd, |
| 1127 | DRV_NAME); |
Kuninori Morimoto | a1042a4 | 2018-01-29 02:44:23 +0000 | [diff] [blame] | 1128 | struct audio_drv_data *adata = dev_get_drvdata(component->dev); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1129 | |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 1130 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 1131 | switch (rtd->i2s_instance) { |
| 1132 | case I2S_BT_INSTANCE: |
| 1133 | adata->play_i2sbt_stream = NULL; |
| 1134 | break; |
| 1135 | case I2S_SP_INSTANCE: |
| 1136 | default: |
| 1137 | adata->play_i2ssp_stream = NULL; |
| 1138 | /* |
| 1139 | * For Stoney, Memory gating is disabled,i.e SRAM Banks |
| 1140 | * won't be turned off. The default state for SRAM banks |
| 1141 | * is ON.Setting SRAM bank state code skipped for STONEY |
| 1142 | * platform. Added condition checks for Carrizo platform |
| 1143 | * only. |
| 1144 | */ |
| 1145 | if (adata->asic_type != CHIP_STONEY) { |
| 1146 | for (bank = 1; bank <= 4; bank++) |
| 1147 | acp_set_sram_bank_state(adata->acp_mmio, |
| 1148 | bank, false); |
| 1149 | } |
Vijendar Mukunda | 607b39e | 2017-10-18 12:13:57 -0400 | [diff] [blame] | 1150 | } |
| 1151 | } else { |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 1152 | switch (rtd->i2s_instance) { |
| 1153 | case I2S_BT_INSTANCE: |
| 1154 | adata->capture_i2sbt_stream = NULL; |
| 1155 | break; |
| 1156 | case I2S_SP_INSTANCE: |
| 1157 | default: |
| 1158 | adata->capture_i2ssp_stream = NULL; |
| 1159 | if (adata->asic_type != CHIP_STONEY) { |
| 1160 | for (bank = 5; bank <= 8; bank++) |
| 1161 | acp_set_sram_bank_state(adata->acp_mmio, |
| 1162 | bank, false); |
| 1163 | } |
Vijendar Mukunda | 607b39e | 2017-10-18 12:13:57 -0400 | [diff] [blame] | 1164 | } |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 1165 | } |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1166 | |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 1167 | /* |
| 1168 | * Disable ACP irq, when the current stream is being closed and |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1169 | * another stream is also not active. |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 1170 | */ |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 1171 | if (!adata->play_i2ssp_stream && !adata->capture_i2ssp_stream && |
| 1172 | !adata->play_i2sbt_stream && !adata->capture_i2sbt_stream) |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1173 | acp_reg_write(0, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); |
Mukunda, Vijendar | cac6f59 | 2018-05-08 10:17:49 +0530 | [diff] [blame] | 1174 | kfree(rtd); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1175 | return 0; |
| 1176 | } |
| 1177 | |
Julia Lawall | 115c725 | 2016-09-08 02:35:23 +0200 | [diff] [blame] | 1178 | static const struct snd_pcm_ops acp_dma_ops = { |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1179 | .open = acp_dma_open, |
| 1180 | .close = acp_dma_close, |
| 1181 | .ioctl = snd_pcm_lib_ioctl, |
| 1182 | .hw_params = acp_dma_hw_params, |
| 1183 | .hw_free = acp_dma_hw_free, |
| 1184 | .trigger = acp_dma_trigger, |
| 1185 | .pointer = acp_dma_pointer, |
| 1186 | .mmap = acp_dma_mmap, |
| 1187 | .prepare = acp_dma_prepare, |
| 1188 | }; |
| 1189 | |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 1190 | static const struct snd_soc_component_driver acp_asoc_platform = { |
Kuninori Morimoto | a1042a4 | 2018-01-29 02:44:23 +0000 | [diff] [blame] | 1191 | .name = DRV_NAME, |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1192 | .ops = &acp_dma_ops, |
| 1193 | .pcm_new = acp_dma_new, |
| 1194 | }; |
| 1195 | |
| 1196 | static int acp_audio_probe(struct platform_device *pdev) |
| 1197 | { |
| 1198 | int status; |
| 1199 | struct audio_drv_data *audio_drv_data; |
| 1200 | struct resource *res; |
Vijendar Mukunda | a1b16aa | 2017-10-09 16:36:08 -0400 | [diff] [blame] | 1201 | const u32 *pdata = pdev->dev.platform_data; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1202 | |
Guenter Roeck | fdaa451 | 2017-11-20 20:27:56 -0800 | [diff] [blame] | 1203 | if (!pdata) { |
| 1204 | dev_err(&pdev->dev, "Missing platform data\n"); |
| 1205 | return -ENODEV; |
| 1206 | } |
| 1207 | |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1208 | audio_drv_data = devm_kzalloc(&pdev->dev, sizeof(struct audio_drv_data), |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 1209 | GFP_KERNEL); |
| 1210 | if (!audio_drv_data) |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1211 | return -ENOMEM; |
| 1212 | |
| 1213 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1214 | audio_drv_data->acp_mmio = devm_ioremap_resource(&pdev->dev, res); |
Guenter Roeck | fdaa451 | 2017-11-20 20:27:56 -0800 | [diff] [blame] | 1215 | if (IS_ERR(audio_drv_data->acp_mmio)) |
| 1216 | return PTR_ERR(audio_drv_data->acp_mmio); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1217 | |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 1218 | /* |
| 1219 | * The following members gets populated in device 'open' |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1220 | * function. Till then interrupts are disabled in 'acp_init' |
| 1221 | * and device doesn't generate any interrupts. |
| 1222 | */ |
| 1223 | |
Mukunda, Vijendar | e21358c | 2018-02-16 13:03:46 +0530 | [diff] [blame] | 1224 | audio_drv_data->play_i2ssp_stream = NULL; |
| 1225 | audio_drv_data->capture_i2ssp_stream = NULL; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 1226 | audio_drv_data->play_i2sbt_stream = NULL; |
| 1227 | audio_drv_data->capture_i2sbt_stream = NULL; |
Mukunda, Vijendar | e21358c | 2018-02-16 13:03:46 +0530 | [diff] [blame] | 1228 | |
Vijendar Mukunda | a1b16aa | 2017-10-09 16:36:08 -0400 | [diff] [blame] | 1229 | audio_drv_data->asic_type = *pdata; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1230 | |
| 1231 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 1232 | if (!res) { |
| 1233 | dev_err(&pdev->dev, "IORESOURCE_IRQ FAILED\n"); |
| 1234 | return -ENODEV; |
| 1235 | } |
| 1236 | |
| 1237 | status = devm_request_irq(&pdev->dev, res->start, dma_irq_handler, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 1238 | 0, "ACP_IRQ", &pdev->dev); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1239 | if (status) { |
| 1240 | dev_err(&pdev->dev, "ACP IRQ request failed\n"); |
| 1241 | return status; |
| 1242 | } |
| 1243 | |
| 1244 | dev_set_drvdata(&pdev->dev, audio_drv_data); |
| 1245 | |
| 1246 | /* Initialize the ACP */ |
Mukunda, Vijendar | 7afa535 | 2017-12-04 20:46:24 +0530 | [diff] [blame] | 1247 | status = acp_init(audio_drv_data->acp_mmio, audio_drv_data->asic_type); |
| 1248 | if (status) { |
| 1249 | dev_err(&pdev->dev, "ACP Init failed status:%d\n", status); |
| 1250 | return status; |
| 1251 | } |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1252 | |
Kuninori Morimoto | a1042a4 | 2018-01-29 02:44:23 +0000 | [diff] [blame] | 1253 | status = devm_snd_soc_register_component(&pdev->dev, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 1254 | &acp_asoc_platform, NULL, 0); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1255 | if (status != 0) { |
| 1256 | dev_err(&pdev->dev, "Fail to register ALSA platform device\n"); |
| 1257 | return status; |
| 1258 | } |
| 1259 | |
Maruthi Srinivas Bayyavarapu | 1927da9 | 2016-01-08 18:22:10 -0500 | [diff] [blame] | 1260 | pm_runtime_set_autosuspend_delay(&pdev->dev, 10000); |
| 1261 | pm_runtime_use_autosuspend(&pdev->dev); |
| 1262 | pm_runtime_enable(&pdev->dev); |
| 1263 | |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1264 | return status; |
| 1265 | } |
| 1266 | |
| 1267 | static int acp_audio_remove(struct platform_device *pdev) |
| 1268 | { |
Mukunda, Vijendar | 7afa535 | 2017-12-04 20:46:24 +0530 | [diff] [blame] | 1269 | int status; |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1270 | struct audio_drv_data *adata = dev_get_drvdata(&pdev->dev); |
| 1271 | |
Mukunda, Vijendar | 7afa535 | 2017-12-04 20:46:24 +0530 | [diff] [blame] | 1272 | status = acp_deinit(adata->acp_mmio); |
| 1273 | if (status) |
| 1274 | dev_err(&pdev->dev, "ACP Deinit failed status:%d\n", status); |
Maruthi Srinivas Bayyavarapu | 1927da9 | 2016-01-08 18:22:10 -0500 | [diff] [blame] | 1275 | pm_runtime_disable(&pdev->dev); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1276 | |
| 1277 | return 0; |
| 1278 | } |
| 1279 | |
Maruthi Srinivas Bayyavarapu | 1927da9 | 2016-01-08 18:22:10 -0500 | [diff] [blame] | 1280 | static int acp_pcm_resume(struct device *dev) |
| 1281 | { |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 1282 | u16 bank; |
Mukunda, Vijendar | 7afa535 | 2017-12-04 20:46:24 +0530 | [diff] [blame] | 1283 | int status; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 1284 | struct audio_substream_data *rtd; |
Maruthi Srinivas Bayyavarapu | 1927da9 | 2016-01-08 18:22:10 -0500 | [diff] [blame] | 1285 | struct audio_drv_data *adata = dev_get_drvdata(dev); |
| 1286 | |
Mukunda, Vijendar | 7afa535 | 2017-12-04 20:46:24 +0530 | [diff] [blame] | 1287 | status = acp_init(adata->acp_mmio, adata->asic_type); |
| 1288 | if (status) { |
| 1289 | dev_err(dev, "ACP Init failed status:%d\n", status); |
| 1290 | return status; |
| 1291 | } |
Maruthi Srinivas Bayyavarapu | 1927da9 | 2016-01-08 18:22:10 -0500 | [diff] [blame] | 1292 | |
Mukunda, Vijendar | e21358c | 2018-02-16 13:03:46 +0530 | [diff] [blame] | 1293 | if (adata->play_i2ssp_stream && adata->play_i2ssp_stream->runtime) { |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 1294 | /* |
| 1295 | * For Stoney, Memory gating is disabled,i.e SRAM Banks |
Vijendar Mukunda | 607b39e | 2017-10-18 12:13:57 -0400 | [diff] [blame] | 1296 | * won't be turned off. The default state for SRAM banks is ON. |
| 1297 | * Setting SRAM bank state code skipped for STONEY platform. |
| 1298 | */ |
| 1299 | if (adata->asic_type != CHIP_STONEY) { |
| 1300 | for (bank = 1; bank <= 4; bank++) |
| 1301 | acp_set_sram_bank_state(adata->acp_mmio, bank, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 1302 | true); |
Vijendar Mukunda | 607b39e | 2017-10-18 12:13:57 -0400 | [diff] [blame] | 1303 | } |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 1304 | rtd = adata->play_i2ssp_stream->runtime->private_data; |
| 1305 | config_acp_dma(adata->acp_mmio, rtd, adata->asic_type); |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 1306 | } |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 1307 | if (adata->capture_i2ssp_stream && |
| 1308 | adata->capture_i2ssp_stream->runtime) { |
Vijendar Mukunda | 607b39e | 2017-10-18 12:13:57 -0400 | [diff] [blame] | 1309 | if (adata->asic_type != CHIP_STONEY) { |
| 1310 | for (bank = 5; bank <= 8; bank++) |
| 1311 | acp_set_sram_bank_state(adata->acp_mmio, bank, |
Mukunda, Vijendar | 13838c1 | 2018-04-17 10:29:52 +0530 | [diff] [blame] | 1312 | true); |
Vijendar Mukunda | 607b39e | 2017-10-18 12:13:57 -0400 | [diff] [blame] | 1313 | } |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 1314 | rtd = adata->capture_i2ssp_stream->runtime->private_data; |
| 1315 | config_acp_dma(adata->acp_mmio, rtd, adata->asic_type); |
| 1316 | } |
| 1317 | if (adata->asic_type != CHIP_CARRIZO) { |
| 1318 | if (adata->play_i2sbt_stream && |
| 1319 | adata->play_i2sbt_stream->runtime) { |
| 1320 | rtd = adata->play_i2sbt_stream->runtime->private_data; |
| 1321 | config_acp_dma(adata->acp_mmio, rtd, adata->asic_type); |
| 1322 | } |
| 1323 | if (adata->capture_i2sbt_stream && |
| 1324 | adata->capture_i2sbt_stream->runtime) { |
| 1325 | rtd = adata->capture_i2sbt_stream->runtime->private_data; |
| 1326 | config_acp_dma(adata->acp_mmio, rtd, adata->asic_type); |
| 1327 | } |
Maruthi Srinivas Bayyavarapu | c36d9b3 | 2016-01-08 18:22:11 -0500 | [diff] [blame] | 1328 | } |
Maruthi Srinivas Bayyavarapu | 1927da9 | 2016-01-08 18:22:10 -0500 | [diff] [blame] | 1329 | acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); |
| 1330 | return 0; |
| 1331 | } |
| 1332 | |
| 1333 | static int acp_pcm_runtime_suspend(struct device *dev) |
| 1334 | { |
Mukunda, Vijendar | 7afa535 | 2017-12-04 20:46:24 +0530 | [diff] [blame] | 1335 | int status; |
Maruthi Srinivas Bayyavarapu | 1927da9 | 2016-01-08 18:22:10 -0500 | [diff] [blame] | 1336 | struct audio_drv_data *adata = dev_get_drvdata(dev); |
| 1337 | |
Mukunda, Vijendar | 7afa535 | 2017-12-04 20:46:24 +0530 | [diff] [blame] | 1338 | status = acp_deinit(adata->acp_mmio); |
| 1339 | if (status) |
| 1340 | dev_err(dev, "ACP Deinit failed status:%d\n", status); |
Maruthi Srinivas Bayyavarapu | 1927da9 | 2016-01-08 18:22:10 -0500 | [diff] [blame] | 1341 | acp_reg_write(0, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); |
| 1342 | return 0; |
| 1343 | } |
| 1344 | |
| 1345 | static int acp_pcm_runtime_resume(struct device *dev) |
| 1346 | { |
Mukunda, Vijendar | 7afa535 | 2017-12-04 20:46:24 +0530 | [diff] [blame] | 1347 | int status; |
Maruthi Srinivas Bayyavarapu | 1927da9 | 2016-01-08 18:22:10 -0500 | [diff] [blame] | 1348 | struct audio_drv_data *adata = dev_get_drvdata(dev); |
| 1349 | |
Mukunda, Vijendar | 7afa535 | 2017-12-04 20:46:24 +0530 | [diff] [blame] | 1350 | status = acp_init(adata->acp_mmio, adata->asic_type); |
| 1351 | if (status) { |
| 1352 | dev_err(dev, "ACP Init failed status:%d\n", status); |
| 1353 | return status; |
| 1354 | } |
Maruthi Srinivas Bayyavarapu | 1927da9 | 2016-01-08 18:22:10 -0500 | [diff] [blame] | 1355 | acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); |
| 1356 | return 0; |
| 1357 | } |
| 1358 | |
| 1359 | static const struct dev_pm_ops acp_pm_ops = { |
| 1360 | .resume = acp_pcm_resume, |
| 1361 | .runtime_suspend = acp_pcm_runtime_suspend, |
| 1362 | .runtime_resume = acp_pcm_runtime_resume, |
| 1363 | }; |
| 1364 | |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1365 | static struct platform_driver acp_dma_driver = { |
| 1366 | .probe = acp_audio_probe, |
| 1367 | .remove = acp_audio_remove, |
| 1368 | .driver = { |
Akshu Agrawal | bdd2a85 | 2017-11-08 12:24:02 -0500 | [diff] [blame] | 1369 | .name = DRV_NAME, |
Maruthi Srinivas Bayyavarapu | 1927da9 | 2016-01-08 18:22:10 -0500 | [diff] [blame] | 1370 | .pm = &acp_pm_ops, |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1371 | }, |
| 1372 | }; |
| 1373 | |
| 1374 | module_platform_driver(acp_dma_driver); |
| 1375 | |
Vijendar Mukunda | 607b39e | 2017-10-18 12:13:57 -0400 | [diff] [blame] | 1376 | MODULE_AUTHOR("Vijendar.Mukunda@amd.com"); |
Maruthi Srinivas Bayyavarapu | 7c31335 | 2016-01-08 18:22:09 -0500 | [diff] [blame] | 1377 | MODULE_AUTHOR("Maruthi.Bayyavarapu@amd.com"); |
| 1378 | MODULE_DESCRIPTION("AMD ACP PCM Driver"); |
| 1379 | MODULE_LICENSE("GPL v2"); |
Akshu Agrawal | bdd2a85 | 2017-11-08 12:24:02 -0500 | [diff] [blame] | 1380 | MODULE_ALIAS("platform:"DRV_NAME); |