17c31335aSMaruthi Srinivas Bayyavarapu /* 27c31335aSMaruthi Srinivas Bayyavarapu * AMD ALSA SoC PCM Driver for ACP 2.x 37c31335aSMaruthi Srinivas Bayyavarapu * 47c31335aSMaruthi Srinivas Bayyavarapu * Copyright 2014-2015 Advanced Micro Devices, Inc. 57c31335aSMaruthi Srinivas Bayyavarapu * 67c31335aSMaruthi Srinivas Bayyavarapu * This program is free software; you can redistribute it and/or modify it 77c31335aSMaruthi Srinivas Bayyavarapu * under the terms and conditions of the GNU General Public License, 87c31335aSMaruthi Srinivas Bayyavarapu * version 2, as published by the Free Software Foundation. 97c31335aSMaruthi Srinivas Bayyavarapu * 107c31335aSMaruthi Srinivas Bayyavarapu * This program is distributed in the hope it will be useful, but WITHOUT 117c31335aSMaruthi Srinivas Bayyavarapu * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 127c31335aSMaruthi Srinivas Bayyavarapu * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 137c31335aSMaruthi Srinivas Bayyavarapu * more details. 147c31335aSMaruthi Srinivas Bayyavarapu */ 157c31335aSMaruthi Srinivas Bayyavarapu 167c31335aSMaruthi Srinivas Bayyavarapu #include <linux/module.h> 177c31335aSMaruthi Srinivas Bayyavarapu #include <linux/delay.h> 187cb1dc81SGuenter Roeck #include <linux/io.h> 197c31335aSMaruthi Srinivas Bayyavarapu #include <linux/sizes.h> 201927da93SMaruthi Srinivas Bayyavarapu #include <linux/pm_runtime.h> 217c31335aSMaruthi Srinivas Bayyavarapu 227c31335aSMaruthi Srinivas Bayyavarapu #include <sound/soc.h> 23607b39efSVijendar Mukunda #include <drm/amd_asic_type.h> 247c31335aSMaruthi Srinivas Bayyavarapu #include "acp.h" 257c31335aSMaruthi Srinivas Bayyavarapu 26a1042a42SKuninori Morimoto #define DRV_NAME "acp_audio_dma" 27a1042a42SKuninori Morimoto 287c31335aSMaruthi Srinivas Bayyavarapu #define PLAYBACK_MIN_NUM_PERIODS 2 297c31335aSMaruthi Srinivas Bayyavarapu #define PLAYBACK_MAX_NUM_PERIODS 2 307c31335aSMaruthi Srinivas Bayyavarapu #define PLAYBACK_MAX_PERIOD_SIZE 16384 317c31335aSMaruthi Srinivas Bayyavarapu #define PLAYBACK_MIN_PERIOD_SIZE 1024 327c31335aSMaruthi Srinivas Bayyavarapu #define CAPTURE_MIN_NUM_PERIODS 2 337c31335aSMaruthi Srinivas Bayyavarapu #define CAPTURE_MAX_NUM_PERIODS 2 347c31335aSMaruthi Srinivas Bayyavarapu #define CAPTURE_MAX_PERIOD_SIZE 16384 357c31335aSMaruthi Srinivas Bayyavarapu #define CAPTURE_MIN_PERIOD_SIZE 1024 367c31335aSMaruthi Srinivas Bayyavarapu 377c31335aSMaruthi Srinivas Bayyavarapu #define MAX_BUFFER (PLAYBACK_MAX_PERIOD_SIZE * PLAYBACK_MAX_NUM_PERIODS) 387c31335aSMaruthi Srinivas Bayyavarapu #define MIN_BUFFER MAX_BUFFER 397c31335aSMaruthi Srinivas Bayyavarapu 40ccfbb4f5SMukunda, Vijendar #define ST_PLAYBACK_MAX_PERIOD_SIZE 4096 419c7d6fabSVijendar Mukunda #define ST_CAPTURE_MAX_PERIOD_SIZE ST_PLAYBACK_MAX_PERIOD_SIZE 429c7d6fabSVijendar Mukunda #define ST_MAX_BUFFER (ST_PLAYBACK_MAX_PERIOD_SIZE * PLAYBACK_MAX_NUM_PERIODS) 439c7d6fabSVijendar Mukunda #define ST_MIN_BUFFER ST_MAX_BUFFER 449c7d6fabSVijendar Mukunda 45bdd2a858SAkshu Agrawal #define DRV_NAME "acp_audio_dma" 46ccfbb4f5SMukunda, Vijendar bool bt_uart_enable = true; 47ccfbb4f5SMukunda, Vijendar EXPORT_SYMBOL(bt_uart_enable); 48bdd2a858SAkshu Agrawal 497c31335aSMaruthi Srinivas Bayyavarapu static const struct snd_pcm_hardware acp_pcm_hardware_playback = { 507c31335aSMaruthi Srinivas Bayyavarapu .info = SNDRV_PCM_INFO_INTERLEAVED | 517c31335aSMaruthi Srinivas Bayyavarapu SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP | 527c31335aSMaruthi Srinivas Bayyavarapu SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BATCH | 537c31335aSMaruthi Srinivas Bayyavarapu SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME, 547c31335aSMaruthi Srinivas Bayyavarapu .formats = SNDRV_PCM_FMTBIT_S16_LE | 557c31335aSMaruthi Srinivas Bayyavarapu SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE, 567c31335aSMaruthi Srinivas Bayyavarapu .channels_min = 1, 577c31335aSMaruthi Srinivas Bayyavarapu .channels_max = 8, 587c31335aSMaruthi Srinivas Bayyavarapu .rates = SNDRV_PCM_RATE_8000_96000, 597c31335aSMaruthi Srinivas Bayyavarapu .rate_min = 8000, 607c31335aSMaruthi Srinivas Bayyavarapu .rate_max = 96000, 617c31335aSMaruthi Srinivas Bayyavarapu .buffer_bytes_max = PLAYBACK_MAX_NUM_PERIODS * PLAYBACK_MAX_PERIOD_SIZE, 627c31335aSMaruthi Srinivas Bayyavarapu .period_bytes_min = PLAYBACK_MIN_PERIOD_SIZE, 637c31335aSMaruthi Srinivas Bayyavarapu .period_bytes_max = PLAYBACK_MAX_PERIOD_SIZE, 647c31335aSMaruthi Srinivas Bayyavarapu .periods_min = PLAYBACK_MIN_NUM_PERIODS, 657c31335aSMaruthi Srinivas Bayyavarapu .periods_max = PLAYBACK_MAX_NUM_PERIODS, 667c31335aSMaruthi Srinivas Bayyavarapu }; 677c31335aSMaruthi Srinivas Bayyavarapu 687c31335aSMaruthi Srinivas Bayyavarapu static const struct snd_pcm_hardware acp_pcm_hardware_capture = { 697c31335aSMaruthi Srinivas Bayyavarapu .info = SNDRV_PCM_INFO_INTERLEAVED | 707c31335aSMaruthi Srinivas Bayyavarapu SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP | 717c31335aSMaruthi Srinivas Bayyavarapu SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BATCH | 727c31335aSMaruthi Srinivas Bayyavarapu SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME, 737c31335aSMaruthi Srinivas Bayyavarapu .formats = SNDRV_PCM_FMTBIT_S16_LE | 747c31335aSMaruthi Srinivas Bayyavarapu SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE, 757c31335aSMaruthi Srinivas Bayyavarapu .channels_min = 1, 767c31335aSMaruthi Srinivas Bayyavarapu .channels_max = 2, 777c31335aSMaruthi Srinivas Bayyavarapu .rates = SNDRV_PCM_RATE_8000_48000, 787c31335aSMaruthi Srinivas Bayyavarapu .rate_min = 8000, 797c31335aSMaruthi Srinivas Bayyavarapu .rate_max = 48000, 807c31335aSMaruthi Srinivas Bayyavarapu .buffer_bytes_max = CAPTURE_MAX_NUM_PERIODS * CAPTURE_MAX_PERIOD_SIZE, 817c31335aSMaruthi Srinivas Bayyavarapu .period_bytes_min = CAPTURE_MIN_PERIOD_SIZE, 827c31335aSMaruthi Srinivas Bayyavarapu .period_bytes_max = CAPTURE_MAX_PERIOD_SIZE, 837c31335aSMaruthi Srinivas Bayyavarapu .periods_min = CAPTURE_MIN_NUM_PERIODS, 847c31335aSMaruthi Srinivas Bayyavarapu .periods_max = CAPTURE_MAX_NUM_PERIODS, 857c31335aSMaruthi Srinivas Bayyavarapu }; 867c31335aSMaruthi Srinivas Bayyavarapu 879c7d6fabSVijendar Mukunda static const struct snd_pcm_hardware acp_st_pcm_hardware_playback = { 889c7d6fabSVijendar Mukunda .info = SNDRV_PCM_INFO_INTERLEAVED | 899c7d6fabSVijendar Mukunda SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP | 909c7d6fabSVijendar Mukunda SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BATCH | 919c7d6fabSVijendar Mukunda SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME, 929c7d6fabSVijendar Mukunda .formats = SNDRV_PCM_FMTBIT_S16_LE | 939c7d6fabSVijendar Mukunda SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE, 949c7d6fabSVijendar Mukunda .channels_min = 1, 959c7d6fabSVijendar Mukunda .channels_max = 8, 969c7d6fabSVijendar Mukunda .rates = SNDRV_PCM_RATE_8000_96000, 979c7d6fabSVijendar Mukunda .rate_min = 8000, 989c7d6fabSVijendar Mukunda .rate_max = 96000, 999c7d6fabSVijendar Mukunda .buffer_bytes_max = ST_MAX_BUFFER, 1009c7d6fabSVijendar Mukunda .period_bytes_min = PLAYBACK_MIN_PERIOD_SIZE, 1019c7d6fabSVijendar Mukunda .period_bytes_max = ST_PLAYBACK_MAX_PERIOD_SIZE, 1029c7d6fabSVijendar Mukunda .periods_min = PLAYBACK_MIN_NUM_PERIODS, 1039c7d6fabSVijendar Mukunda .periods_max = PLAYBACK_MAX_NUM_PERIODS, 1049c7d6fabSVijendar Mukunda }; 1059c7d6fabSVijendar Mukunda 1069c7d6fabSVijendar Mukunda static const struct snd_pcm_hardware acp_st_pcm_hardware_capture = { 1079c7d6fabSVijendar Mukunda .info = SNDRV_PCM_INFO_INTERLEAVED | 1089c7d6fabSVijendar Mukunda SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP | 1099c7d6fabSVijendar Mukunda SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BATCH | 1109c7d6fabSVijendar Mukunda SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME, 1119c7d6fabSVijendar Mukunda .formats = SNDRV_PCM_FMTBIT_S16_LE | 1129c7d6fabSVijendar Mukunda SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE, 1139c7d6fabSVijendar Mukunda .channels_min = 1, 1149c7d6fabSVijendar Mukunda .channels_max = 2, 1159c7d6fabSVijendar Mukunda .rates = SNDRV_PCM_RATE_8000_48000, 1169c7d6fabSVijendar Mukunda .rate_min = 8000, 1179c7d6fabSVijendar Mukunda .rate_max = 48000, 1189c7d6fabSVijendar Mukunda .buffer_bytes_max = ST_MAX_BUFFER, 1199c7d6fabSVijendar Mukunda .period_bytes_min = CAPTURE_MIN_PERIOD_SIZE, 1209c7d6fabSVijendar Mukunda .period_bytes_max = ST_CAPTURE_MAX_PERIOD_SIZE, 1219c7d6fabSVijendar Mukunda .periods_min = CAPTURE_MIN_NUM_PERIODS, 1229c7d6fabSVijendar Mukunda .periods_max = CAPTURE_MAX_NUM_PERIODS, 1239c7d6fabSVijendar Mukunda }; 1249c7d6fabSVijendar Mukunda 1257c31335aSMaruthi Srinivas Bayyavarapu static u32 acp_reg_read(void __iomem *acp_mmio, u32 reg) 1267c31335aSMaruthi Srinivas Bayyavarapu { 1277c31335aSMaruthi Srinivas Bayyavarapu return readl(acp_mmio + (reg * 4)); 1287c31335aSMaruthi Srinivas Bayyavarapu } 1297c31335aSMaruthi Srinivas Bayyavarapu 1307c31335aSMaruthi Srinivas Bayyavarapu static void acp_reg_write(u32 val, void __iomem *acp_mmio, u32 reg) 1317c31335aSMaruthi Srinivas Bayyavarapu { 1327c31335aSMaruthi Srinivas Bayyavarapu writel(val, acp_mmio + (reg * 4)); 1337c31335aSMaruthi Srinivas Bayyavarapu } 1347c31335aSMaruthi Srinivas Bayyavarapu 13513838c11SMukunda, Vijendar /* 13613838c11SMukunda, Vijendar * Configure a given dma channel parameters - enable/disable, 1377c31335aSMaruthi Srinivas Bayyavarapu * number of descriptors, priority 1387c31335aSMaruthi Srinivas Bayyavarapu */ 1397c31335aSMaruthi Srinivas Bayyavarapu static void config_acp_dma_channel(void __iomem *acp_mmio, u8 ch_num, 1407c31335aSMaruthi Srinivas Bayyavarapu u16 dscr_strt_idx, u16 num_dscrs, 1417c31335aSMaruthi Srinivas Bayyavarapu enum acp_dma_priority_level priority_level) 1427c31335aSMaruthi Srinivas Bayyavarapu { 1437c31335aSMaruthi Srinivas Bayyavarapu u32 dma_ctrl; 1447c31335aSMaruthi Srinivas Bayyavarapu 1457c31335aSMaruthi Srinivas Bayyavarapu /* disable the channel run field */ 1467c31335aSMaruthi Srinivas Bayyavarapu dma_ctrl = acp_reg_read(acp_mmio, mmACP_DMA_CNTL_0 + ch_num); 1477c31335aSMaruthi Srinivas Bayyavarapu dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChRun_MASK; 1487c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(dma_ctrl, acp_mmio, mmACP_DMA_CNTL_0 + ch_num); 1497c31335aSMaruthi Srinivas Bayyavarapu 1507c31335aSMaruthi Srinivas Bayyavarapu /* program a DMA channel with first descriptor to be processed. */ 1517c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write((ACP_DMA_DSCR_STRT_IDX_0__DMAChDscrStrtIdx_MASK 1527c31335aSMaruthi Srinivas Bayyavarapu & dscr_strt_idx), 1537c31335aSMaruthi Srinivas Bayyavarapu acp_mmio, mmACP_DMA_DSCR_STRT_IDX_0 + ch_num); 1547c31335aSMaruthi Srinivas Bayyavarapu 15513838c11SMukunda, Vijendar /* 15613838c11SMukunda, Vijendar * program a DMA channel with the number of descriptors to be 1577c31335aSMaruthi Srinivas Bayyavarapu * processed in the transfer 1587c31335aSMaruthi Srinivas Bayyavarapu */ 1597c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(ACP_DMA_DSCR_CNT_0__DMAChDscrCnt_MASK & num_dscrs, 1607c31335aSMaruthi Srinivas Bayyavarapu acp_mmio, mmACP_DMA_DSCR_CNT_0 + ch_num); 1617c31335aSMaruthi Srinivas Bayyavarapu 1627c31335aSMaruthi Srinivas Bayyavarapu /* set DMA channel priority */ 1637c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(priority_level, acp_mmio, mmACP_DMA_PRIO_0 + ch_num); 1647c31335aSMaruthi Srinivas Bayyavarapu } 1657c31335aSMaruthi Srinivas Bayyavarapu 1667c31335aSMaruthi Srinivas Bayyavarapu /* Initialize a dma descriptor in SRAM based on descritor information passed */ 1677c31335aSMaruthi Srinivas Bayyavarapu static void config_dma_descriptor_in_sram(void __iomem *acp_mmio, 1687c31335aSMaruthi Srinivas Bayyavarapu u16 descr_idx, 1697c31335aSMaruthi Srinivas Bayyavarapu acp_dma_dscr_transfer_t *descr_info) 1707c31335aSMaruthi Srinivas Bayyavarapu { 1717c31335aSMaruthi Srinivas Bayyavarapu u32 sram_offset; 1727c31335aSMaruthi Srinivas Bayyavarapu 1737c31335aSMaruthi Srinivas Bayyavarapu sram_offset = (descr_idx * sizeof(acp_dma_dscr_transfer_t)); 1747c31335aSMaruthi Srinivas Bayyavarapu 1757c31335aSMaruthi Srinivas Bayyavarapu /* program the source base address. */ 1767c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(sram_offset, acp_mmio, mmACP_SRBM_Targ_Idx_Addr); 1777c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(descr_info->src, acp_mmio, mmACP_SRBM_Targ_Idx_Data); 1787c31335aSMaruthi Srinivas Bayyavarapu /* program the destination base address. */ 1797c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(sram_offset + 4, acp_mmio, mmACP_SRBM_Targ_Idx_Addr); 1807c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(descr_info->dest, acp_mmio, mmACP_SRBM_Targ_Idx_Data); 1817c31335aSMaruthi Srinivas Bayyavarapu 1827c31335aSMaruthi Srinivas Bayyavarapu /* program the number of bytes to be transferred for this descriptor. */ 1837c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(sram_offset + 8, acp_mmio, mmACP_SRBM_Targ_Idx_Addr); 1847c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(descr_info->xfer_val, acp_mmio, mmACP_SRBM_Targ_Idx_Data); 1857c31335aSMaruthi Srinivas Bayyavarapu } 1867c31335aSMaruthi Srinivas Bayyavarapu 18713838c11SMukunda, Vijendar /* 18813838c11SMukunda, Vijendar * Initialize the DMA descriptor information for transfer between 1897c31335aSMaruthi Srinivas Bayyavarapu * system memory <-> ACP SRAM 1907c31335aSMaruthi Srinivas Bayyavarapu */ 1917c31335aSMaruthi Srinivas Bayyavarapu static void set_acp_sysmem_dma_descriptors(void __iomem *acp_mmio, 19213838c11SMukunda, Vijendar u32 size, int direction, 19313838c11SMukunda, Vijendar u32 pte_offset, u16 ch, 19413838c11SMukunda, Vijendar u32 sram_bank, u16 dma_dscr_idx, 19513838c11SMukunda, Vijendar u32 asic_type) 1967c31335aSMaruthi Srinivas Bayyavarapu { 1977c31335aSMaruthi Srinivas Bayyavarapu u16 i; 1987c31335aSMaruthi Srinivas Bayyavarapu acp_dma_dscr_transfer_t dmadscr[NUM_DSCRS_PER_CHANNEL]; 1997c31335aSMaruthi Srinivas Bayyavarapu 2007c31335aSMaruthi Srinivas Bayyavarapu for (i = 0; i < NUM_DSCRS_PER_CHANNEL; i++) { 2017c31335aSMaruthi Srinivas Bayyavarapu dmadscr[i].xfer_val = 0; 2027c31335aSMaruthi Srinivas Bayyavarapu if (direction == SNDRV_PCM_STREAM_PLAYBACK) { 2034376a86cSMukunda, Vijendar dma_dscr_idx = dma_dscr_idx + i; 2044376a86cSMukunda, Vijendar dmadscr[i].dest = sram_bank + (i * (size / 2)); 2057c31335aSMaruthi Srinivas Bayyavarapu dmadscr[i].src = ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS 2067c31335aSMaruthi Srinivas Bayyavarapu + (pte_offset * SZ_4K) + (i * (size / 2)); 207aac89748SVijendar Mukunda switch (asic_type) { 208aac89748SVijendar Mukunda case CHIP_STONEY: 209aac89748SVijendar Mukunda dmadscr[i].xfer_val |= 21013838c11SMukunda, Vijendar (ACP_DMA_ATTR_DAGB_GARLIC_TO_SHAREDMEM << 16) | 211aac89748SVijendar Mukunda (size / 2); 212aac89748SVijendar Mukunda break; 213aac89748SVijendar Mukunda default: 2147c31335aSMaruthi Srinivas Bayyavarapu dmadscr[i].xfer_val |= 21513838c11SMukunda, Vijendar (ACP_DMA_ATTR_DAGB_ONION_TO_SHAREDMEM << 16) | 2167c31335aSMaruthi Srinivas Bayyavarapu (size / 2); 217aac89748SVijendar Mukunda } 2187c31335aSMaruthi Srinivas Bayyavarapu } else { 2194376a86cSMukunda, Vijendar dma_dscr_idx = dma_dscr_idx + i; 2204376a86cSMukunda, Vijendar dmadscr[i].src = sram_bank + (i * (size / 2)); 221aac89748SVijendar Mukunda dmadscr[i].dest = 222aac89748SVijendar Mukunda ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS + 223aac89748SVijendar Mukunda (pte_offset * SZ_4K) + (i * (size / 2)); 2244376a86cSMukunda, Vijendar switch (asic_type) { 2254376a86cSMukunda, Vijendar case CHIP_STONEY: 226aac89748SVijendar Mukunda dmadscr[i].xfer_val |= 22713838c11SMukunda, Vijendar (ACP_DMA_ATTR_SHARED_MEM_TO_DAGB_GARLIC << 16) | 228aac89748SVijendar Mukunda (size / 2); 229aac89748SVijendar Mukunda break; 230aac89748SVijendar Mukunda default: 2317c31335aSMaruthi Srinivas Bayyavarapu dmadscr[i].xfer_val |= 23213838c11SMukunda, Vijendar (ACP_DMA_ATTR_SHAREDMEM_TO_DAGB_ONION << 16) | 2337c31335aSMaruthi Srinivas Bayyavarapu (size / 2); 2347c31335aSMaruthi Srinivas Bayyavarapu } 235aac89748SVijendar Mukunda } 2367c31335aSMaruthi Srinivas Bayyavarapu config_dma_descriptor_in_sram(acp_mmio, dma_dscr_idx, 2377c31335aSMaruthi Srinivas Bayyavarapu &dmadscr[i]); 2387c31335aSMaruthi Srinivas Bayyavarapu } 2394376a86cSMukunda, Vijendar config_acp_dma_channel(acp_mmio, ch, 2404376a86cSMukunda, Vijendar dma_dscr_idx - 1, 2417c31335aSMaruthi Srinivas Bayyavarapu NUM_DSCRS_PER_CHANNEL, 2427c31335aSMaruthi Srinivas Bayyavarapu ACP_DMA_PRIORITY_LEVEL_NORMAL); 2437c31335aSMaruthi Srinivas Bayyavarapu } 2447c31335aSMaruthi Srinivas Bayyavarapu 24513838c11SMukunda, Vijendar /* 24613838c11SMukunda, Vijendar * Initialize the DMA descriptor information for transfer between 2477c31335aSMaruthi Srinivas Bayyavarapu * ACP SRAM <-> I2S 2487c31335aSMaruthi Srinivas Bayyavarapu */ 2494376a86cSMukunda, Vijendar static void set_acp_to_i2s_dma_descriptors(void __iomem *acp_mmio, u32 size, 2504376a86cSMukunda, Vijendar int direction, u32 sram_bank, 2514376a86cSMukunda, Vijendar u16 destination, u16 ch, 2524376a86cSMukunda, Vijendar u16 dma_dscr_idx, u32 asic_type) 2537c31335aSMaruthi Srinivas Bayyavarapu { 2547c31335aSMaruthi Srinivas Bayyavarapu u16 i; 2557c31335aSMaruthi Srinivas Bayyavarapu acp_dma_dscr_transfer_t dmadscr[NUM_DSCRS_PER_CHANNEL]; 2567c31335aSMaruthi Srinivas Bayyavarapu 2577c31335aSMaruthi Srinivas Bayyavarapu for (i = 0; i < NUM_DSCRS_PER_CHANNEL; i++) { 2587c31335aSMaruthi Srinivas Bayyavarapu dmadscr[i].xfer_val = 0; 2597c31335aSMaruthi Srinivas Bayyavarapu if (direction == SNDRV_PCM_STREAM_PLAYBACK) { 2604376a86cSMukunda, Vijendar dma_dscr_idx = dma_dscr_idx + i; 2614376a86cSMukunda, Vijendar dmadscr[i].src = sram_bank + (i * (size / 2)); 2627c31335aSMaruthi Srinivas Bayyavarapu /* dmadscr[i].dest is unused by hardware. */ 2637c31335aSMaruthi Srinivas Bayyavarapu dmadscr[i].dest = 0; 2644376a86cSMukunda, Vijendar dmadscr[i].xfer_val |= BIT(22) | (destination << 16) | 2657c31335aSMaruthi Srinivas Bayyavarapu (size / 2); 2667c31335aSMaruthi Srinivas Bayyavarapu } else { 2674376a86cSMukunda, Vijendar dma_dscr_idx = dma_dscr_idx + i; 2687c31335aSMaruthi Srinivas Bayyavarapu /* dmadscr[i].src is unused by hardware. */ 2697c31335aSMaruthi Srinivas Bayyavarapu dmadscr[i].src = 0; 270aac89748SVijendar Mukunda dmadscr[i].dest = 2714376a86cSMukunda, Vijendar sram_bank + (i * (size / 2)); 2727c31335aSMaruthi Srinivas Bayyavarapu dmadscr[i].xfer_val |= BIT(22) | 2734376a86cSMukunda, Vijendar (destination << 16) | (size / 2); 2747c31335aSMaruthi Srinivas Bayyavarapu } 2757c31335aSMaruthi Srinivas Bayyavarapu config_dma_descriptor_in_sram(acp_mmio, dma_dscr_idx, 2767c31335aSMaruthi Srinivas Bayyavarapu &dmadscr[i]); 2777c31335aSMaruthi Srinivas Bayyavarapu } 2787c31335aSMaruthi Srinivas Bayyavarapu /* Configure the DMA channel with the above descriptore */ 2794376a86cSMukunda, Vijendar config_acp_dma_channel(acp_mmio, ch, dma_dscr_idx - 1, 2807c31335aSMaruthi Srinivas Bayyavarapu NUM_DSCRS_PER_CHANNEL, 2817c31335aSMaruthi Srinivas Bayyavarapu ACP_DMA_PRIORITY_LEVEL_NORMAL); 2827c31335aSMaruthi Srinivas Bayyavarapu } 2837c31335aSMaruthi Srinivas Bayyavarapu 2847c31335aSMaruthi Srinivas Bayyavarapu /* Create page table entries in ACP SRAM for the allocated memory */ 2857c31335aSMaruthi Srinivas Bayyavarapu static void acp_pte_config(void __iomem *acp_mmio, struct page *pg, 2867c31335aSMaruthi Srinivas Bayyavarapu u16 num_of_pages, u32 pte_offset) 2877c31335aSMaruthi Srinivas Bayyavarapu { 2887c31335aSMaruthi Srinivas Bayyavarapu u16 page_idx; 2897c31335aSMaruthi Srinivas Bayyavarapu u64 addr; 2907c31335aSMaruthi Srinivas Bayyavarapu u32 low; 2917c31335aSMaruthi Srinivas Bayyavarapu u32 high; 2927c31335aSMaruthi Srinivas Bayyavarapu u32 offset; 2937c31335aSMaruthi Srinivas Bayyavarapu 2947c31335aSMaruthi Srinivas Bayyavarapu offset = ACP_DAGB_GRP_SRBM_SRAM_BASE_OFFSET + (pte_offset * 8); 2957c31335aSMaruthi Srinivas Bayyavarapu for (page_idx = 0; page_idx < (num_of_pages); page_idx++) { 2967c31335aSMaruthi Srinivas Bayyavarapu /* Load the low address of page int ACP SRAM through SRBM */ 2977c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write((offset + (page_idx * 8)), 2987c31335aSMaruthi Srinivas Bayyavarapu acp_mmio, mmACP_SRBM_Targ_Idx_Addr); 2997c31335aSMaruthi Srinivas Bayyavarapu addr = page_to_phys(pg); 3007c31335aSMaruthi Srinivas Bayyavarapu 3017c31335aSMaruthi Srinivas Bayyavarapu low = lower_32_bits(addr); 3027c31335aSMaruthi Srinivas Bayyavarapu high = upper_32_bits(addr); 3037c31335aSMaruthi Srinivas Bayyavarapu 3047c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(low, acp_mmio, mmACP_SRBM_Targ_Idx_Data); 3057c31335aSMaruthi Srinivas Bayyavarapu 3067c31335aSMaruthi Srinivas Bayyavarapu /* Load the High address of page int ACP SRAM through SRBM */ 3077c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write((offset + (page_idx * 8) + 4), 3087c31335aSMaruthi Srinivas Bayyavarapu acp_mmio, mmACP_SRBM_Targ_Idx_Addr); 3097c31335aSMaruthi Srinivas Bayyavarapu 3107c31335aSMaruthi Srinivas Bayyavarapu /* page enable in ACP */ 3117c31335aSMaruthi Srinivas Bayyavarapu high |= BIT(31); 3127c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(high, acp_mmio, mmACP_SRBM_Targ_Idx_Data); 3137c31335aSMaruthi Srinivas Bayyavarapu 3147c31335aSMaruthi Srinivas Bayyavarapu /* Move to next physically contiguos page */ 3157c31335aSMaruthi Srinivas Bayyavarapu pg++; 3167c31335aSMaruthi Srinivas Bayyavarapu } 3177c31335aSMaruthi Srinivas Bayyavarapu } 3187c31335aSMaruthi Srinivas Bayyavarapu 3197c31335aSMaruthi Srinivas Bayyavarapu static void config_acp_dma(void __iomem *acp_mmio, 3208349b7f5SMukunda, Vijendar struct audio_substream_data *rtd, 321aac89748SVijendar Mukunda u32 asic_type) 3227c31335aSMaruthi Srinivas Bayyavarapu { 323fa9d2f17SAgrawal, Akshu u16 ch_acp_sysmem, ch_acp_i2s; 324fa9d2f17SAgrawal, Akshu 3258349b7f5SMukunda, Vijendar acp_pte_config(acp_mmio, rtd->pg, rtd->num_of_pages, 326e188c525SMukunda, Vijendar rtd->pte_offset); 327fa9d2f17SAgrawal, Akshu 328fa9d2f17SAgrawal, Akshu if (rtd->direction == SNDRV_PCM_STREAM_PLAYBACK) { 329fa9d2f17SAgrawal, Akshu ch_acp_sysmem = rtd->ch1; 330fa9d2f17SAgrawal, Akshu ch_acp_i2s = rtd->ch2; 331fa9d2f17SAgrawal, Akshu } else { 332fa9d2f17SAgrawal, Akshu ch_acp_i2s = rtd->ch1; 333fa9d2f17SAgrawal, Akshu ch_acp_sysmem = rtd->ch2; 334fa9d2f17SAgrawal, Akshu } 3357c31335aSMaruthi Srinivas Bayyavarapu /* Configure System memory <-> ACP SRAM DMA descriptors */ 3368349b7f5SMukunda, Vijendar set_acp_sysmem_dma_descriptors(acp_mmio, rtd->size, 337e188c525SMukunda, Vijendar rtd->direction, rtd->pte_offset, 338fa9d2f17SAgrawal, Akshu ch_acp_sysmem, rtd->sram_bank, 3398769bb55SVijendar Mukunda rtd->dma_dscr_idx_1, asic_type); 3407c31335aSMaruthi Srinivas Bayyavarapu /* Configure ACP SRAM <-> I2S DMA descriptors */ 3418349b7f5SMukunda, Vijendar set_acp_to_i2s_dma_descriptors(acp_mmio, rtd->size, 34218e8a40dSMukunda, Vijendar rtd->direction, rtd->sram_bank, 343fa9d2f17SAgrawal, Akshu rtd->destination, ch_acp_i2s, 3448769bb55SVijendar Mukunda rtd->dma_dscr_idx_2, asic_type); 3457c31335aSMaruthi Srinivas Bayyavarapu } 3467c31335aSMaruthi Srinivas Bayyavarapu 3472718c89aSAkshu Agrawal static void acp_dma_cap_channel_enable(void __iomem *acp_mmio, 3482718c89aSAkshu Agrawal u16 cap_channel) 3492718c89aSAkshu Agrawal { 3502718c89aSAkshu Agrawal u32 val, ch_reg, imr_reg, res_reg; 3512718c89aSAkshu Agrawal 3522718c89aSAkshu Agrawal switch (cap_channel) { 3532718c89aSAkshu Agrawal case CAP_CHANNEL1: 3542718c89aSAkshu Agrawal ch_reg = mmACP_I2SMICSP_RER1; 3552718c89aSAkshu Agrawal res_reg = mmACP_I2SMICSP_RCR1; 3562718c89aSAkshu Agrawal imr_reg = mmACP_I2SMICSP_IMR1; 3572718c89aSAkshu Agrawal break; 3582718c89aSAkshu Agrawal case CAP_CHANNEL0: 3592718c89aSAkshu Agrawal default: 3602718c89aSAkshu Agrawal ch_reg = mmACP_I2SMICSP_RER0; 3612718c89aSAkshu Agrawal res_reg = mmACP_I2SMICSP_RCR0; 3622718c89aSAkshu Agrawal imr_reg = mmACP_I2SMICSP_IMR0; 3632718c89aSAkshu Agrawal break; 3642718c89aSAkshu Agrawal } 3652718c89aSAkshu Agrawal val = acp_reg_read(acp_mmio, 3662718c89aSAkshu Agrawal mmACP_I2S_16BIT_RESOLUTION_EN); 3672718c89aSAkshu Agrawal if (val & ACP_I2S_MIC_16BIT_RESOLUTION_EN) { 3682718c89aSAkshu Agrawal acp_reg_write(0x0, acp_mmio, ch_reg); 3692718c89aSAkshu Agrawal /* Set 16bit resolution on capture */ 3702718c89aSAkshu Agrawal acp_reg_write(0x2, acp_mmio, res_reg); 3712718c89aSAkshu Agrawal } 3722718c89aSAkshu Agrawal val = acp_reg_read(acp_mmio, imr_reg); 3732718c89aSAkshu Agrawal val &= ~ACP_I2SMICSP_IMR1__I2SMICSP_RXDAM_MASK; 3742718c89aSAkshu Agrawal val &= ~ACP_I2SMICSP_IMR1__I2SMICSP_RXFOM_MASK; 3752718c89aSAkshu Agrawal acp_reg_write(val, acp_mmio, imr_reg); 3762718c89aSAkshu Agrawal acp_reg_write(0x1, acp_mmio, ch_reg); 3772718c89aSAkshu Agrawal } 3782718c89aSAkshu Agrawal 3792718c89aSAkshu Agrawal static void acp_dma_cap_channel_disable(void __iomem *acp_mmio, 3802718c89aSAkshu Agrawal u16 cap_channel) 3812718c89aSAkshu Agrawal { 3822718c89aSAkshu Agrawal u32 val, ch_reg, imr_reg; 3832718c89aSAkshu Agrawal 3842718c89aSAkshu Agrawal switch (cap_channel) { 3852718c89aSAkshu Agrawal case CAP_CHANNEL1: 3862718c89aSAkshu Agrawal imr_reg = mmACP_I2SMICSP_IMR1; 3872718c89aSAkshu Agrawal ch_reg = mmACP_I2SMICSP_RER1; 3882718c89aSAkshu Agrawal break; 3892718c89aSAkshu Agrawal case CAP_CHANNEL0: 3902718c89aSAkshu Agrawal default: 3912718c89aSAkshu Agrawal imr_reg = mmACP_I2SMICSP_IMR0; 3922718c89aSAkshu Agrawal ch_reg = mmACP_I2SMICSP_RER0; 3932718c89aSAkshu Agrawal break; 3942718c89aSAkshu Agrawal } 3952718c89aSAkshu Agrawal val = acp_reg_read(acp_mmio, imr_reg); 3962718c89aSAkshu Agrawal val |= ACP_I2SMICSP_IMR1__I2SMICSP_RXDAM_MASK; 3972718c89aSAkshu Agrawal val |= ACP_I2SMICSP_IMR1__I2SMICSP_RXFOM_MASK; 3982718c89aSAkshu Agrawal acp_reg_write(val, acp_mmio, imr_reg); 3992718c89aSAkshu Agrawal acp_reg_write(0x0, acp_mmio, ch_reg); 4002718c89aSAkshu Agrawal } 4012718c89aSAkshu Agrawal 4027c31335aSMaruthi Srinivas Bayyavarapu /* Start a given DMA channel transfer */ 403*bbdb7012SAkshu Agrawal static void acp_dma_start(void __iomem *acp_mmio, u16 ch_num, bool is_circular) 4047c31335aSMaruthi Srinivas Bayyavarapu { 4057c31335aSMaruthi Srinivas Bayyavarapu u32 dma_ctrl; 4067c31335aSMaruthi Srinivas Bayyavarapu 4077c31335aSMaruthi Srinivas Bayyavarapu /* read the dma control register and disable the channel run field */ 4087c31335aSMaruthi Srinivas Bayyavarapu dma_ctrl = acp_reg_read(acp_mmio, mmACP_DMA_CNTL_0 + ch_num); 4097c31335aSMaruthi Srinivas Bayyavarapu 4107c31335aSMaruthi Srinivas Bayyavarapu /* Invalidating the DAGB cache */ 4117c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(1, acp_mmio, mmACP_DAGB_ATU_CTRL); 4127c31335aSMaruthi Srinivas Bayyavarapu 41313838c11SMukunda, Vijendar /* 41413838c11SMukunda, Vijendar * configure the DMA channel and start the DMA transfer 4157c31335aSMaruthi Srinivas Bayyavarapu * set dmachrun bit to start the transfer and enable the 4167c31335aSMaruthi Srinivas Bayyavarapu * interrupt on completion of the dma transfer 4177c31335aSMaruthi Srinivas Bayyavarapu */ 4187c31335aSMaruthi Srinivas Bayyavarapu dma_ctrl |= ACP_DMA_CNTL_0__DMAChRun_MASK; 4197c31335aSMaruthi Srinivas Bayyavarapu 4207c31335aSMaruthi Srinivas Bayyavarapu switch (ch_num) { 4217c31335aSMaruthi Srinivas Bayyavarapu case ACP_TO_I2S_DMA_CH_NUM: 42219e023e3SAgrawal, Akshu case I2S_TO_ACP_DMA_CH_NUM: 423ccfbb4f5SMukunda, Vijendar case ACP_TO_I2S_DMA_BT_INSTANCE_CH_NUM: 42419e023e3SAgrawal, Akshu case I2S_TO_ACP_DMA_BT_INSTANCE_CH_NUM: 4257c31335aSMaruthi Srinivas Bayyavarapu dma_ctrl |= ACP_DMA_CNTL_0__DMAChIOCEn_MASK; 4267c31335aSMaruthi Srinivas Bayyavarapu break; 4277c31335aSMaruthi Srinivas Bayyavarapu default: 4287c31335aSMaruthi Srinivas Bayyavarapu dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChIOCEn_MASK; 4297c31335aSMaruthi Srinivas Bayyavarapu break; 4307c31335aSMaruthi Srinivas Bayyavarapu } 4317c31335aSMaruthi Srinivas Bayyavarapu 432*bbdb7012SAkshu Agrawal /* enable for ACP to SRAM DMA channel */ 433*bbdb7012SAkshu Agrawal if (is_circular == true) 4347c31335aSMaruthi Srinivas Bayyavarapu dma_ctrl |= ACP_DMA_CNTL_0__Circular_DMA_En_MASK; 435*bbdb7012SAkshu Agrawal else 436*bbdb7012SAkshu Agrawal dma_ctrl &= ~ACP_DMA_CNTL_0__Circular_DMA_En_MASK; 4377c31335aSMaruthi Srinivas Bayyavarapu 4387c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(dma_ctrl, acp_mmio, mmACP_DMA_CNTL_0 + ch_num); 4397c31335aSMaruthi Srinivas Bayyavarapu } 4407c31335aSMaruthi Srinivas Bayyavarapu 4417c31335aSMaruthi Srinivas Bayyavarapu /* Stop a given DMA channel transfer */ 4427c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_stop(void __iomem *acp_mmio, u8 ch_num) 4437c31335aSMaruthi Srinivas Bayyavarapu { 4447c31335aSMaruthi Srinivas Bayyavarapu u32 dma_ctrl; 4457c31335aSMaruthi Srinivas Bayyavarapu u32 dma_ch_sts; 4467c31335aSMaruthi Srinivas Bayyavarapu u32 count = ACP_DMA_RESET_TIME; 4477c31335aSMaruthi Srinivas Bayyavarapu 4487c31335aSMaruthi Srinivas Bayyavarapu dma_ctrl = acp_reg_read(acp_mmio, mmACP_DMA_CNTL_0 + ch_num); 4497c31335aSMaruthi Srinivas Bayyavarapu 45013838c11SMukunda, Vijendar /* 45113838c11SMukunda, Vijendar * clear the dma control register fields before writing zero 4527c31335aSMaruthi Srinivas Bayyavarapu * in reset bit 4537c31335aSMaruthi Srinivas Bayyavarapu */ 4547c31335aSMaruthi Srinivas Bayyavarapu dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChRun_MASK; 4557c31335aSMaruthi Srinivas Bayyavarapu dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChIOCEn_MASK; 4567c31335aSMaruthi Srinivas Bayyavarapu 4577c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(dma_ctrl, acp_mmio, mmACP_DMA_CNTL_0 + ch_num); 4587c31335aSMaruthi Srinivas Bayyavarapu dma_ch_sts = acp_reg_read(acp_mmio, mmACP_DMA_CH_STS); 4597c31335aSMaruthi Srinivas Bayyavarapu 4607c31335aSMaruthi Srinivas Bayyavarapu if (dma_ch_sts & BIT(ch_num)) { 46113838c11SMukunda, Vijendar /* 46213838c11SMukunda, Vijendar * set the reset bit for this channel to stop the dma 4637c31335aSMaruthi Srinivas Bayyavarapu * transfer 4647c31335aSMaruthi Srinivas Bayyavarapu */ 4657c31335aSMaruthi Srinivas Bayyavarapu dma_ctrl |= ACP_DMA_CNTL_0__DMAChRst_MASK; 4667c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(dma_ctrl, acp_mmio, mmACP_DMA_CNTL_0 + ch_num); 4677c31335aSMaruthi Srinivas Bayyavarapu } 4687c31335aSMaruthi Srinivas Bayyavarapu 4697c31335aSMaruthi Srinivas Bayyavarapu /* check the channel status bit for some time and return the status */ 4707c31335aSMaruthi Srinivas Bayyavarapu while (true) { 4717c31335aSMaruthi Srinivas Bayyavarapu dma_ch_sts = acp_reg_read(acp_mmio, mmACP_DMA_CH_STS); 4727c31335aSMaruthi Srinivas Bayyavarapu if (!(dma_ch_sts & BIT(ch_num))) { 47313838c11SMukunda, Vijendar /* 47413838c11SMukunda, Vijendar * clear the reset flag after successfully stopping 4757c31335aSMaruthi Srinivas Bayyavarapu * the dma transfer and break from the loop 4767c31335aSMaruthi Srinivas Bayyavarapu */ 4777c31335aSMaruthi Srinivas Bayyavarapu dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChRst_MASK; 4787c31335aSMaruthi Srinivas Bayyavarapu 4797c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(dma_ctrl, acp_mmio, mmACP_DMA_CNTL_0 4807c31335aSMaruthi Srinivas Bayyavarapu + ch_num); 4817c31335aSMaruthi Srinivas Bayyavarapu break; 4827c31335aSMaruthi Srinivas Bayyavarapu } 4837c31335aSMaruthi Srinivas Bayyavarapu if (--count == 0) { 4847c31335aSMaruthi Srinivas Bayyavarapu pr_err("Failed to stop ACP DMA channel : %d\n", ch_num); 4857c31335aSMaruthi Srinivas Bayyavarapu return -ETIMEDOUT; 4867c31335aSMaruthi Srinivas Bayyavarapu } 4877c31335aSMaruthi Srinivas Bayyavarapu udelay(100); 4887c31335aSMaruthi Srinivas Bayyavarapu } 4897c31335aSMaruthi Srinivas Bayyavarapu return 0; 4907c31335aSMaruthi Srinivas Bayyavarapu } 4917c31335aSMaruthi Srinivas Bayyavarapu 492c36d9b3fSMaruthi Srinivas Bayyavarapu static void acp_set_sram_bank_state(void __iomem *acp_mmio, u16 bank, 493c36d9b3fSMaruthi Srinivas Bayyavarapu bool power_on) 494c36d9b3fSMaruthi Srinivas Bayyavarapu { 495c36d9b3fSMaruthi Srinivas Bayyavarapu u32 val, req_reg, sts_reg, sts_reg_mask; 496c36d9b3fSMaruthi Srinivas Bayyavarapu u32 loops = 1000; 497c36d9b3fSMaruthi Srinivas Bayyavarapu 498c36d9b3fSMaruthi Srinivas Bayyavarapu if (bank < 32) { 499c36d9b3fSMaruthi Srinivas Bayyavarapu req_reg = mmACP_MEM_SHUT_DOWN_REQ_LO; 500c36d9b3fSMaruthi Srinivas Bayyavarapu sts_reg = mmACP_MEM_SHUT_DOWN_STS_LO; 501c36d9b3fSMaruthi Srinivas Bayyavarapu sts_reg_mask = 0xFFFFFFFF; 502c36d9b3fSMaruthi Srinivas Bayyavarapu 503c36d9b3fSMaruthi Srinivas Bayyavarapu } else { 504c36d9b3fSMaruthi Srinivas Bayyavarapu bank -= 32; 505c36d9b3fSMaruthi Srinivas Bayyavarapu req_reg = mmACP_MEM_SHUT_DOWN_REQ_HI; 506c36d9b3fSMaruthi Srinivas Bayyavarapu sts_reg = mmACP_MEM_SHUT_DOWN_STS_HI; 507c36d9b3fSMaruthi Srinivas Bayyavarapu sts_reg_mask = 0x0000FFFF; 508c36d9b3fSMaruthi Srinivas Bayyavarapu } 509c36d9b3fSMaruthi Srinivas Bayyavarapu 510c36d9b3fSMaruthi Srinivas Bayyavarapu val = acp_reg_read(acp_mmio, req_reg); 511c36d9b3fSMaruthi Srinivas Bayyavarapu if (val & (1 << bank)) { 512c36d9b3fSMaruthi Srinivas Bayyavarapu /* bank is in off state */ 513c36d9b3fSMaruthi Srinivas Bayyavarapu if (power_on == true) 514c36d9b3fSMaruthi Srinivas Bayyavarapu /* request to on */ 515c36d9b3fSMaruthi Srinivas Bayyavarapu val &= ~(1 << bank); 516c36d9b3fSMaruthi Srinivas Bayyavarapu else 517c36d9b3fSMaruthi Srinivas Bayyavarapu /* request to off */ 518c36d9b3fSMaruthi Srinivas Bayyavarapu return; 519c36d9b3fSMaruthi Srinivas Bayyavarapu } else { 520c36d9b3fSMaruthi Srinivas Bayyavarapu /* bank is in on state */ 521c36d9b3fSMaruthi Srinivas Bayyavarapu if (power_on == false) 522c36d9b3fSMaruthi Srinivas Bayyavarapu /* request to off */ 523c36d9b3fSMaruthi Srinivas Bayyavarapu val |= 1 << bank; 524c36d9b3fSMaruthi Srinivas Bayyavarapu else 525c36d9b3fSMaruthi Srinivas Bayyavarapu /* request to on */ 526c36d9b3fSMaruthi Srinivas Bayyavarapu return; 527c36d9b3fSMaruthi Srinivas Bayyavarapu } 528c36d9b3fSMaruthi Srinivas Bayyavarapu acp_reg_write(val, acp_mmio, req_reg); 529c36d9b3fSMaruthi Srinivas Bayyavarapu 530c36d9b3fSMaruthi Srinivas Bayyavarapu while (acp_reg_read(acp_mmio, sts_reg) != sts_reg_mask) { 531c36d9b3fSMaruthi Srinivas Bayyavarapu if (!loops--) { 532c36d9b3fSMaruthi Srinivas Bayyavarapu pr_err("ACP SRAM bank %d state change failed\n", bank); 533c36d9b3fSMaruthi Srinivas Bayyavarapu break; 534c36d9b3fSMaruthi Srinivas Bayyavarapu } 535c36d9b3fSMaruthi Srinivas Bayyavarapu cpu_relax(); 536c36d9b3fSMaruthi Srinivas Bayyavarapu } 537c36d9b3fSMaruthi Srinivas Bayyavarapu } 538c36d9b3fSMaruthi Srinivas Bayyavarapu 5397c31335aSMaruthi Srinivas Bayyavarapu /* Initialize and bring ACP hardware to default state. */ 540607b39efSVijendar Mukunda static int acp_init(void __iomem *acp_mmio, u32 asic_type) 5417c31335aSMaruthi Srinivas Bayyavarapu { 542c36d9b3fSMaruthi Srinivas Bayyavarapu u16 bank; 5437c31335aSMaruthi Srinivas Bayyavarapu u32 val, count, sram_pte_offset; 5447c31335aSMaruthi Srinivas Bayyavarapu 5457c31335aSMaruthi Srinivas Bayyavarapu /* Assert Soft reset of ACP */ 5467c31335aSMaruthi Srinivas Bayyavarapu val = acp_reg_read(acp_mmio, mmACP_SOFT_RESET); 5477c31335aSMaruthi Srinivas Bayyavarapu 5487c31335aSMaruthi Srinivas Bayyavarapu val |= ACP_SOFT_RESET__SoftResetAud_MASK; 5497c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(val, acp_mmio, mmACP_SOFT_RESET); 5507c31335aSMaruthi Srinivas Bayyavarapu 5517c31335aSMaruthi Srinivas Bayyavarapu count = ACP_SOFT_RESET_DONE_TIME_OUT_VALUE; 5527c31335aSMaruthi Srinivas Bayyavarapu while (true) { 5537c31335aSMaruthi Srinivas Bayyavarapu val = acp_reg_read(acp_mmio, mmACP_SOFT_RESET); 5547c31335aSMaruthi Srinivas Bayyavarapu if (ACP_SOFT_RESET__SoftResetAudDone_MASK == 5557c31335aSMaruthi Srinivas Bayyavarapu (val & ACP_SOFT_RESET__SoftResetAudDone_MASK)) 5567c31335aSMaruthi Srinivas Bayyavarapu break; 5577c31335aSMaruthi Srinivas Bayyavarapu if (--count == 0) { 5587c31335aSMaruthi Srinivas Bayyavarapu pr_err("Failed to reset ACP\n"); 5597c31335aSMaruthi Srinivas Bayyavarapu return -ETIMEDOUT; 5607c31335aSMaruthi Srinivas Bayyavarapu } 5617c31335aSMaruthi Srinivas Bayyavarapu udelay(100); 5627c31335aSMaruthi Srinivas Bayyavarapu } 5637c31335aSMaruthi Srinivas Bayyavarapu 5647c31335aSMaruthi Srinivas Bayyavarapu /* Enable clock to ACP and wait until the clock is enabled */ 5657c31335aSMaruthi Srinivas Bayyavarapu val = acp_reg_read(acp_mmio, mmACP_CONTROL); 5667c31335aSMaruthi Srinivas Bayyavarapu val = val | ACP_CONTROL__ClkEn_MASK; 5677c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(val, acp_mmio, mmACP_CONTROL); 5687c31335aSMaruthi Srinivas Bayyavarapu 5697c31335aSMaruthi Srinivas Bayyavarapu count = ACP_CLOCK_EN_TIME_OUT_VALUE; 5707c31335aSMaruthi Srinivas Bayyavarapu 5717c31335aSMaruthi Srinivas Bayyavarapu while (true) { 5727c31335aSMaruthi Srinivas Bayyavarapu val = acp_reg_read(acp_mmio, mmACP_STATUS); 5737c31335aSMaruthi Srinivas Bayyavarapu if (val & (u32)0x1) 5747c31335aSMaruthi Srinivas Bayyavarapu break; 5757c31335aSMaruthi Srinivas Bayyavarapu if (--count == 0) { 5767c31335aSMaruthi Srinivas Bayyavarapu pr_err("Failed to reset ACP\n"); 5777c31335aSMaruthi Srinivas Bayyavarapu return -ETIMEDOUT; 5787c31335aSMaruthi Srinivas Bayyavarapu } 5797c31335aSMaruthi Srinivas Bayyavarapu udelay(100); 5807c31335aSMaruthi Srinivas Bayyavarapu } 5817c31335aSMaruthi Srinivas Bayyavarapu 5827c31335aSMaruthi Srinivas Bayyavarapu /* Deassert the SOFT RESET flags */ 5837c31335aSMaruthi Srinivas Bayyavarapu val = acp_reg_read(acp_mmio, mmACP_SOFT_RESET); 5847c31335aSMaruthi Srinivas Bayyavarapu val &= ~ACP_SOFT_RESET__SoftResetAud_MASK; 5857c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(val, acp_mmio, mmACP_SOFT_RESET); 5867c31335aSMaruthi Srinivas Bayyavarapu 587ccfbb4f5SMukunda, Vijendar /* For BT instance change pins from UART to BT */ 588ccfbb4f5SMukunda, Vijendar if (!bt_uart_enable) { 589ccfbb4f5SMukunda, Vijendar val = acp_reg_read(acp_mmio, mmACP_BT_UART_PAD_SEL); 590ccfbb4f5SMukunda, Vijendar val |= ACP_BT_UART_PAD_SELECT_MASK; 591ccfbb4f5SMukunda, Vijendar acp_reg_write(val, acp_mmio, mmACP_BT_UART_PAD_SEL); 592ccfbb4f5SMukunda, Vijendar } 593ccfbb4f5SMukunda, Vijendar 5947c31335aSMaruthi Srinivas Bayyavarapu /* initiailize Onion control DAGB register */ 5957c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(ACP_ONION_CNTL_DEFAULT, acp_mmio, 5967c31335aSMaruthi Srinivas Bayyavarapu mmACP_AXI2DAGB_ONION_CNTL); 5977c31335aSMaruthi Srinivas Bayyavarapu 5987c31335aSMaruthi Srinivas Bayyavarapu /* initiailize Garlic control DAGB registers */ 5997c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(ACP_GARLIC_CNTL_DEFAULT, acp_mmio, 6007c31335aSMaruthi Srinivas Bayyavarapu mmACP_AXI2DAGB_GARLIC_CNTL); 6017c31335aSMaruthi Srinivas Bayyavarapu 6027c31335aSMaruthi Srinivas Bayyavarapu sram_pte_offset = ACP_DAGB_GRP_SRAM_BASE_ADDRESS | 6037c31335aSMaruthi Srinivas Bayyavarapu ACP_DAGB_BASE_ADDR_GRP_1__AXI2DAGBSnoopSel_MASK | 6047c31335aSMaruthi Srinivas Bayyavarapu ACP_DAGB_BASE_ADDR_GRP_1__AXI2DAGBTargetMemSel_MASK | 6057c31335aSMaruthi Srinivas Bayyavarapu ACP_DAGB_BASE_ADDR_GRP_1__AXI2DAGBGrpEnable_MASK; 6067c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(sram_pte_offset, acp_mmio, mmACP_DAGB_BASE_ADDR_GRP_1); 6077c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(ACP_PAGE_SIZE_4K_ENABLE, acp_mmio, 6087c31335aSMaruthi Srinivas Bayyavarapu mmACP_DAGB_PAGE_SIZE_GRP_1); 6097c31335aSMaruthi Srinivas Bayyavarapu 6107c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(ACP_SRAM_BASE_ADDRESS, acp_mmio, 6117c31335aSMaruthi Srinivas Bayyavarapu mmACP_DMA_DESC_BASE_ADDR); 6127c31335aSMaruthi Srinivas Bayyavarapu 6137c31335aSMaruthi Srinivas Bayyavarapu /* Num of descriptiors in SRAM 0x4, means 256 descriptors;(64 * 4) */ 6147c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(0x4, acp_mmio, mmACP_DMA_DESC_MAX_NUM_DSCR); 6157c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(ACP_EXTERNAL_INTR_CNTL__DMAIOCMask_MASK, 6167c31335aSMaruthi Srinivas Bayyavarapu acp_mmio, mmACP_EXTERNAL_INTR_CNTL); 6177c31335aSMaruthi Srinivas Bayyavarapu 61813838c11SMukunda, Vijendar /* 61913838c11SMukunda, Vijendar * When ACP_TILE_P1 is turned on, all SRAM banks get turned on. 620c36d9b3fSMaruthi Srinivas Bayyavarapu * Now, turn off all of them. This can't be done in 'poweron' of 621c36d9b3fSMaruthi Srinivas Bayyavarapu * ACP pm domain, as this requires ACP to be initialized. 622607b39efSVijendar Mukunda * For Stoney, Memory gating is disabled,i.e SRAM Banks 623607b39efSVijendar Mukunda * won't be turned off. The default state for SRAM banks is ON. 624607b39efSVijendar Mukunda * Setting SRAM bank state code skipped for STONEY platform. 625c36d9b3fSMaruthi Srinivas Bayyavarapu */ 626607b39efSVijendar Mukunda if (asic_type != CHIP_STONEY) { 627c36d9b3fSMaruthi Srinivas Bayyavarapu for (bank = 1; bank < 48; bank++) 628c36d9b3fSMaruthi Srinivas Bayyavarapu acp_set_sram_bank_state(acp_mmio, bank, false); 629607b39efSVijendar Mukunda } 6307c31335aSMaruthi Srinivas Bayyavarapu return 0; 6317c31335aSMaruthi Srinivas Bayyavarapu } 6327c31335aSMaruthi Srinivas Bayyavarapu 6331cce2000SMasahiro Yamada /* Deinitialize ACP */ 6347c31335aSMaruthi Srinivas Bayyavarapu static int acp_deinit(void __iomem *acp_mmio) 6357c31335aSMaruthi Srinivas Bayyavarapu { 6367c31335aSMaruthi Srinivas Bayyavarapu u32 val; 6377c31335aSMaruthi Srinivas Bayyavarapu u32 count; 6387c31335aSMaruthi Srinivas Bayyavarapu 6397c31335aSMaruthi Srinivas Bayyavarapu /* Assert Soft reset of ACP */ 6407c31335aSMaruthi Srinivas Bayyavarapu val = acp_reg_read(acp_mmio, mmACP_SOFT_RESET); 6417c31335aSMaruthi Srinivas Bayyavarapu 6427c31335aSMaruthi Srinivas Bayyavarapu val |= ACP_SOFT_RESET__SoftResetAud_MASK; 6437c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(val, acp_mmio, mmACP_SOFT_RESET); 6447c31335aSMaruthi Srinivas Bayyavarapu 6457c31335aSMaruthi Srinivas Bayyavarapu count = ACP_SOFT_RESET_DONE_TIME_OUT_VALUE; 6467c31335aSMaruthi Srinivas Bayyavarapu while (true) { 6477c31335aSMaruthi Srinivas Bayyavarapu val = acp_reg_read(acp_mmio, mmACP_SOFT_RESET); 6487c31335aSMaruthi Srinivas Bayyavarapu if (ACP_SOFT_RESET__SoftResetAudDone_MASK == 6497c31335aSMaruthi Srinivas Bayyavarapu (val & ACP_SOFT_RESET__SoftResetAudDone_MASK)) 6507c31335aSMaruthi Srinivas Bayyavarapu break; 6517c31335aSMaruthi Srinivas Bayyavarapu if (--count == 0) { 6527c31335aSMaruthi Srinivas Bayyavarapu pr_err("Failed to reset ACP\n"); 6537c31335aSMaruthi Srinivas Bayyavarapu return -ETIMEDOUT; 6547c31335aSMaruthi Srinivas Bayyavarapu } 6557c31335aSMaruthi Srinivas Bayyavarapu udelay(100); 6567c31335aSMaruthi Srinivas Bayyavarapu } 65713838c11SMukunda, Vijendar /* Disable ACP clock */ 6587c31335aSMaruthi Srinivas Bayyavarapu val = acp_reg_read(acp_mmio, mmACP_CONTROL); 6597c31335aSMaruthi Srinivas Bayyavarapu val &= ~ACP_CONTROL__ClkEn_MASK; 6607c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(val, acp_mmio, mmACP_CONTROL); 6617c31335aSMaruthi Srinivas Bayyavarapu 6627c31335aSMaruthi Srinivas Bayyavarapu count = ACP_CLOCK_EN_TIME_OUT_VALUE; 6637c31335aSMaruthi Srinivas Bayyavarapu 6647c31335aSMaruthi Srinivas Bayyavarapu while (true) { 6657c31335aSMaruthi Srinivas Bayyavarapu val = acp_reg_read(acp_mmio, mmACP_STATUS); 6667c31335aSMaruthi Srinivas Bayyavarapu if (!(val & (u32)0x1)) 6677c31335aSMaruthi Srinivas Bayyavarapu break; 6687c31335aSMaruthi Srinivas Bayyavarapu if (--count == 0) { 6697c31335aSMaruthi Srinivas Bayyavarapu pr_err("Failed to reset ACP\n"); 6707c31335aSMaruthi Srinivas Bayyavarapu return -ETIMEDOUT; 6717c31335aSMaruthi Srinivas Bayyavarapu } 6727c31335aSMaruthi Srinivas Bayyavarapu udelay(100); 6737c31335aSMaruthi Srinivas Bayyavarapu } 6747c31335aSMaruthi Srinivas Bayyavarapu return 0; 6757c31335aSMaruthi Srinivas Bayyavarapu } 6767c31335aSMaruthi Srinivas Bayyavarapu 6777c31335aSMaruthi Srinivas Bayyavarapu /* ACP DMA irq handler routine for playback, capture usecases */ 6787c31335aSMaruthi Srinivas Bayyavarapu static irqreturn_t dma_irq_handler(int irq, void *arg) 6797c31335aSMaruthi Srinivas Bayyavarapu { 680*bbdb7012SAkshu Agrawal u16 dscr_idx; 6817c31335aSMaruthi Srinivas Bayyavarapu u32 intr_flag, ext_intr_status; 6827c31335aSMaruthi Srinivas Bayyavarapu struct audio_drv_data *irq_data; 6837c31335aSMaruthi Srinivas Bayyavarapu void __iomem *acp_mmio; 6847c31335aSMaruthi Srinivas Bayyavarapu struct device *dev = arg; 6857c31335aSMaruthi Srinivas Bayyavarapu bool valid_irq = false; 6867c31335aSMaruthi Srinivas Bayyavarapu 6877c31335aSMaruthi Srinivas Bayyavarapu irq_data = dev_get_drvdata(dev); 6887c31335aSMaruthi Srinivas Bayyavarapu acp_mmio = irq_data->acp_mmio; 6897c31335aSMaruthi Srinivas Bayyavarapu 6907c31335aSMaruthi Srinivas Bayyavarapu ext_intr_status = acp_reg_read(acp_mmio, mmACP_EXTERNAL_INTR_STAT); 6917c31335aSMaruthi Srinivas Bayyavarapu intr_flag = (((ext_intr_status & 6927c31335aSMaruthi Srinivas Bayyavarapu ACP_EXTERNAL_INTR_STAT__DMAIOCStat_MASK) >> 6937c31335aSMaruthi Srinivas Bayyavarapu ACP_EXTERNAL_INTR_STAT__DMAIOCStat__SHIFT)); 6947c31335aSMaruthi Srinivas Bayyavarapu 6957c31335aSMaruthi Srinivas Bayyavarapu if ((intr_flag & BIT(ACP_TO_I2S_DMA_CH_NUM)) != 0) { 6967c31335aSMaruthi Srinivas Bayyavarapu valid_irq = true; 697e21358c4SMukunda, Vijendar snd_pcm_period_elapsed(irq_data->play_i2ssp_stream); 6987c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write((intr_flag & BIT(ACP_TO_I2S_DMA_CH_NUM)) << 16, 6997c31335aSMaruthi Srinivas Bayyavarapu acp_mmio, mmACP_EXTERNAL_INTR_STAT); 7007c31335aSMaruthi Srinivas Bayyavarapu } 7017c31335aSMaruthi Srinivas Bayyavarapu 702ccfbb4f5SMukunda, Vijendar if ((intr_flag & BIT(ACP_TO_I2S_DMA_BT_INSTANCE_CH_NUM)) != 0) { 703ccfbb4f5SMukunda, Vijendar valid_irq = true; 704ccfbb4f5SMukunda, Vijendar snd_pcm_period_elapsed(irq_data->play_i2sbt_stream); 705ccfbb4f5SMukunda, Vijendar acp_reg_write((intr_flag & 706ccfbb4f5SMukunda, Vijendar BIT(ACP_TO_I2S_DMA_BT_INSTANCE_CH_NUM)) << 16, 707ccfbb4f5SMukunda, Vijendar acp_mmio, mmACP_EXTERNAL_INTR_STAT); 708ccfbb4f5SMukunda, Vijendar } 709ccfbb4f5SMukunda, Vijendar 71019e023e3SAgrawal, Akshu if ((intr_flag & BIT(I2S_TO_ACP_DMA_CH_NUM)) != 0) { 7117c31335aSMaruthi Srinivas Bayyavarapu valid_irq = true; 712*bbdb7012SAkshu Agrawal if (acp_reg_read(acp_mmio, mmACP_DMA_CUR_DSCR_14) == 713*bbdb7012SAkshu Agrawal CAPTURE_START_DMA_DESCR_CH15) 714*bbdb7012SAkshu Agrawal dscr_idx = CAPTURE_END_DMA_DESCR_CH14; 715*bbdb7012SAkshu Agrawal else 716*bbdb7012SAkshu Agrawal dscr_idx = CAPTURE_START_DMA_DESCR_CH14; 717*bbdb7012SAkshu Agrawal config_acp_dma_channel(acp_mmio, ACP_TO_SYSRAM_CH_NUM, dscr_idx, 718*bbdb7012SAkshu Agrawal 1, 0); 719*bbdb7012SAkshu Agrawal acp_dma_start(acp_mmio, ACP_TO_SYSRAM_CH_NUM, false); 720*bbdb7012SAkshu Agrawal 72155af49acSDaniel Kurtz snd_pcm_period_elapsed(irq_data->capture_i2ssp_stream); 72219e023e3SAgrawal, Akshu acp_reg_write((intr_flag & BIT(I2S_TO_ACP_DMA_CH_NUM)) << 16, 7237c31335aSMaruthi Srinivas Bayyavarapu acp_mmio, mmACP_EXTERNAL_INTR_STAT); 7247c31335aSMaruthi Srinivas Bayyavarapu } 7257c31335aSMaruthi Srinivas Bayyavarapu 72619e023e3SAgrawal, Akshu if ((intr_flag & BIT(I2S_TO_ACP_DMA_BT_INSTANCE_CH_NUM)) != 0) { 727ccfbb4f5SMukunda, Vijendar valid_irq = true; 728*bbdb7012SAkshu Agrawal if (acp_reg_read(acp_mmio, mmACP_DMA_CUR_DSCR_10) == 729*bbdb7012SAkshu Agrawal CAPTURE_START_DMA_DESCR_CH11) 730*bbdb7012SAkshu Agrawal dscr_idx = CAPTURE_END_DMA_DESCR_CH10; 731*bbdb7012SAkshu Agrawal else 732*bbdb7012SAkshu Agrawal dscr_idx = CAPTURE_START_DMA_DESCR_CH10; 733*bbdb7012SAkshu Agrawal config_acp_dma_channel(acp_mmio, 734*bbdb7012SAkshu Agrawal ACP_TO_SYSRAM_BT_INSTANCE_CH_NUM, 735*bbdb7012SAkshu Agrawal dscr_idx, 1, 0); 736*bbdb7012SAkshu Agrawal acp_dma_start(acp_mmio, ACP_TO_SYSRAM_BT_INSTANCE_CH_NUM, 737*bbdb7012SAkshu Agrawal false); 738*bbdb7012SAkshu Agrawal 73955af49acSDaniel Kurtz snd_pcm_period_elapsed(irq_data->capture_i2sbt_stream); 740ccfbb4f5SMukunda, Vijendar acp_reg_write((intr_flag & 74119e023e3SAgrawal, Akshu BIT(I2S_TO_ACP_DMA_BT_INSTANCE_CH_NUM)) << 16, 742ccfbb4f5SMukunda, Vijendar acp_mmio, mmACP_EXTERNAL_INTR_STAT); 743ccfbb4f5SMukunda, Vijendar } 744ccfbb4f5SMukunda, Vijendar 7457c31335aSMaruthi Srinivas Bayyavarapu if (valid_irq) 7467c31335aSMaruthi Srinivas Bayyavarapu return IRQ_HANDLED; 7477c31335aSMaruthi Srinivas Bayyavarapu else 7487c31335aSMaruthi Srinivas Bayyavarapu return IRQ_NONE; 7497c31335aSMaruthi Srinivas Bayyavarapu } 7507c31335aSMaruthi Srinivas Bayyavarapu 7517c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_open(struct snd_pcm_substream *substream) 7527c31335aSMaruthi Srinivas Bayyavarapu { 753c36d9b3fSMaruthi Srinivas Bayyavarapu u16 bank; 7547c31335aSMaruthi Srinivas Bayyavarapu int ret = 0; 7557c31335aSMaruthi Srinivas Bayyavarapu struct snd_pcm_runtime *runtime = substream->runtime; 7567c31335aSMaruthi Srinivas Bayyavarapu struct snd_soc_pcm_runtime *prtd = substream->private_data; 75713838c11SMukunda, Vijendar struct snd_soc_component *component = snd_soc_rtdcom_lookup(prtd, 75813838c11SMukunda, Vijendar DRV_NAME); 759a1042a42SKuninori Morimoto struct audio_drv_data *intr_data = dev_get_drvdata(component->dev); 7607c31335aSMaruthi Srinivas Bayyavarapu struct audio_substream_data *adata = 7617c31335aSMaruthi Srinivas Bayyavarapu kzalloc(sizeof(struct audio_substream_data), GFP_KERNEL); 76213838c11SMukunda, Vijendar if (!adata) 7637c31335aSMaruthi Srinivas Bayyavarapu return -ENOMEM; 7647c31335aSMaruthi Srinivas Bayyavarapu 7659c7d6fabSVijendar Mukunda if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 7669c7d6fabSVijendar Mukunda switch (intr_data->asic_type) { 7679c7d6fabSVijendar Mukunda case CHIP_STONEY: 7689c7d6fabSVijendar Mukunda runtime->hw = acp_st_pcm_hardware_playback; 7699c7d6fabSVijendar Mukunda break; 7709c7d6fabSVijendar Mukunda default: 7717c31335aSMaruthi Srinivas Bayyavarapu runtime->hw = acp_pcm_hardware_playback; 7729c7d6fabSVijendar Mukunda } 7739c7d6fabSVijendar Mukunda } else { 7749c7d6fabSVijendar Mukunda switch (intr_data->asic_type) { 7759c7d6fabSVijendar Mukunda case CHIP_STONEY: 7769c7d6fabSVijendar Mukunda runtime->hw = acp_st_pcm_hardware_capture; 7779c7d6fabSVijendar Mukunda break; 7789c7d6fabSVijendar Mukunda default: 7797c31335aSMaruthi Srinivas Bayyavarapu runtime->hw = acp_pcm_hardware_capture; 7809c7d6fabSVijendar Mukunda } 7819c7d6fabSVijendar Mukunda } 7827c31335aSMaruthi Srinivas Bayyavarapu 7837c31335aSMaruthi Srinivas Bayyavarapu ret = snd_pcm_hw_constraint_integer(runtime, 7847c31335aSMaruthi Srinivas Bayyavarapu SNDRV_PCM_HW_PARAM_PERIODS); 7857c31335aSMaruthi Srinivas Bayyavarapu if (ret < 0) { 786a1042a42SKuninori Morimoto dev_err(component->dev, "set integer constraint failed\n"); 787cde6bcd5SDan Carpenter kfree(adata); 7887c31335aSMaruthi Srinivas Bayyavarapu return ret; 7897c31335aSMaruthi Srinivas Bayyavarapu } 7907c31335aSMaruthi Srinivas Bayyavarapu 7917c31335aSMaruthi Srinivas Bayyavarapu adata->acp_mmio = intr_data->acp_mmio; 7927c31335aSMaruthi Srinivas Bayyavarapu runtime->private_data = adata; 7937c31335aSMaruthi Srinivas Bayyavarapu 79413838c11SMukunda, Vijendar /* 79513838c11SMukunda, Vijendar * Enable ACP irq, when neither playback or capture streams are 7967c31335aSMaruthi Srinivas Bayyavarapu * active by the time when a new stream is being opened. 7977c31335aSMaruthi Srinivas Bayyavarapu * This enablement is not required for another stream, if current 7987c31335aSMaruthi Srinivas Bayyavarapu * stream is not closed 7997c31335aSMaruthi Srinivas Bayyavarapu */ 800ccfbb4f5SMukunda, Vijendar if (!intr_data->play_i2ssp_stream && !intr_data->capture_i2ssp_stream && 801ccfbb4f5SMukunda, Vijendar !intr_data->play_i2sbt_stream && !intr_data->capture_i2sbt_stream) 8027c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); 8037c31335aSMaruthi Srinivas Bayyavarapu 804c36d9b3fSMaruthi Srinivas Bayyavarapu if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 80513838c11SMukunda, Vijendar /* 80613838c11SMukunda, Vijendar * For Stoney, Memory gating is disabled,i.e SRAM Banks 807607b39efSVijendar Mukunda * won't be turned off. The default state for SRAM banks is ON. 808607b39efSVijendar Mukunda * Setting SRAM bank state code skipped for STONEY platform. 809607b39efSVijendar Mukunda */ 810607b39efSVijendar Mukunda if (intr_data->asic_type != CHIP_STONEY) { 811c36d9b3fSMaruthi Srinivas Bayyavarapu for (bank = 1; bank <= 4; bank++) 812607b39efSVijendar Mukunda acp_set_sram_bank_state(intr_data->acp_mmio, 813607b39efSVijendar Mukunda bank, true); 814607b39efSVijendar Mukunda } 815c36d9b3fSMaruthi Srinivas Bayyavarapu } else { 816607b39efSVijendar Mukunda if (intr_data->asic_type != CHIP_STONEY) { 817c36d9b3fSMaruthi Srinivas Bayyavarapu for (bank = 5; bank <= 8; bank++) 818607b39efSVijendar Mukunda acp_set_sram_bank_state(intr_data->acp_mmio, 819607b39efSVijendar Mukunda bank, true); 820607b39efSVijendar Mukunda } 821c36d9b3fSMaruthi Srinivas Bayyavarapu } 8227c31335aSMaruthi Srinivas Bayyavarapu 8237c31335aSMaruthi Srinivas Bayyavarapu return 0; 8247c31335aSMaruthi Srinivas Bayyavarapu } 8257c31335aSMaruthi Srinivas Bayyavarapu 8267c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_hw_params(struct snd_pcm_substream *substream, 8277c31335aSMaruthi Srinivas Bayyavarapu struct snd_pcm_hw_params *params) 8287c31335aSMaruthi Srinivas Bayyavarapu { 8297c31335aSMaruthi Srinivas Bayyavarapu int status; 8307c31335aSMaruthi Srinivas Bayyavarapu uint64_t size; 831a37d48e3SVijendar Mukunda u32 val = 0; 8327c31335aSMaruthi Srinivas Bayyavarapu struct page *pg; 8337c31335aSMaruthi Srinivas Bayyavarapu struct snd_pcm_runtime *runtime; 8347c31335aSMaruthi Srinivas Bayyavarapu struct audio_substream_data *rtd; 835aac89748SVijendar Mukunda struct snd_soc_pcm_runtime *prtd = substream->private_data; 83613838c11SMukunda, Vijendar struct snd_soc_component *component = snd_soc_rtdcom_lookup(prtd, 83713838c11SMukunda, Vijendar DRV_NAME); 838a1042a42SKuninori Morimoto struct audio_drv_data *adata = dev_get_drvdata(component->dev); 839ccfbb4f5SMukunda, Vijendar struct snd_soc_card *card = prtd->card; 840ccfbb4f5SMukunda, Vijendar struct acp_platform_info *pinfo = snd_soc_card_get_drvdata(card); 8417c31335aSMaruthi Srinivas Bayyavarapu 8427c31335aSMaruthi Srinivas Bayyavarapu runtime = substream->runtime; 8437c31335aSMaruthi Srinivas Bayyavarapu rtd = runtime->private_data; 8447c31335aSMaruthi Srinivas Bayyavarapu 8457c31335aSMaruthi Srinivas Bayyavarapu if (WARN_ON(!rtd)) 8467c31335aSMaruthi Srinivas Bayyavarapu return -EINVAL; 8477c31335aSMaruthi Srinivas Bayyavarapu 8482718c89aSAkshu Agrawal if (pinfo) { 849ccfbb4f5SMukunda, Vijendar rtd->i2s_instance = pinfo->i2s_instance; 8502718c89aSAkshu Agrawal rtd->capture_channel = pinfo->capture_channel; 8512718c89aSAkshu Agrawal } 852a37d48e3SVijendar Mukunda if (adata->asic_type == CHIP_STONEY) { 85313838c11SMukunda, Vijendar val = acp_reg_read(adata->acp_mmio, 85413838c11SMukunda, Vijendar mmACP_I2S_16BIT_RESOLUTION_EN); 855ccfbb4f5SMukunda, Vijendar if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 856ccfbb4f5SMukunda, Vijendar switch (rtd->i2s_instance) { 857ccfbb4f5SMukunda, Vijendar case I2S_BT_INSTANCE: 858ccfbb4f5SMukunda, Vijendar val |= ACP_I2S_BT_16BIT_RESOLUTION_EN; 859ccfbb4f5SMukunda, Vijendar break; 860ccfbb4f5SMukunda, Vijendar case I2S_SP_INSTANCE: 861ccfbb4f5SMukunda, Vijendar default: 862a37d48e3SVijendar Mukunda val |= ACP_I2S_SP_16BIT_RESOLUTION_EN; 863ccfbb4f5SMukunda, Vijendar } 864ccfbb4f5SMukunda, Vijendar } else { 865ccfbb4f5SMukunda, Vijendar switch (rtd->i2s_instance) { 866ccfbb4f5SMukunda, Vijendar case I2S_BT_INSTANCE: 867ccfbb4f5SMukunda, Vijendar val |= ACP_I2S_BT_16BIT_RESOLUTION_EN; 868ccfbb4f5SMukunda, Vijendar break; 869ccfbb4f5SMukunda, Vijendar case I2S_SP_INSTANCE: 870ccfbb4f5SMukunda, Vijendar default: 871a37d48e3SVijendar Mukunda val |= ACP_I2S_MIC_16BIT_RESOLUTION_EN; 872ccfbb4f5SMukunda, Vijendar } 873ccfbb4f5SMukunda, Vijendar } 87413838c11SMukunda, Vijendar acp_reg_write(val, adata->acp_mmio, 87513838c11SMukunda, Vijendar mmACP_I2S_16BIT_RESOLUTION_EN); 876a37d48e3SVijendar Mukunda } 8778769bb55SVijendar Mukunda 8788769bb55SVijendar Mukunda if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 879ccfbb4f5SMukunda, Vijendar switch (rtd->i2s_instance) { 880ccfbb4f5SMukunda, Vijendar case I2S_BT_INSTANCE: 881ccfbb4f5SMukunda, Vijendar rtd->pte_offset = ACP_ST_BT_PLAYBACK_PTE_OFFSET; 882ccfbb4f5SMukunda, Vijendar rtd->ch1 = SYSRAM_TO_ACP_BT_INSTANCE_CH_NUM; 883ccfbb4f5SMukunda, Vijendar rtd->ch2 = ACP_TO_I2S_DMA_BT_INSTANCE_CH_NUM; 884ccfbb4f5SMukunda, Vijendar rtd->sram_bank = ACP_SRAM_BANK_3_ADDRESS; 885ccfbb4f5SMukunda, Vijendar rtd->destination = TO_BLUETOOTH; 886ccfbb4f5SMukunda, Vijendar rtd->dma_dscr_idx_1 = PLAYBACK_START_DMA_DESCR_CH8; 887ccfbb4f5SMukunda, Vijendar rtd->dma_dscr_idx_2 = PLAYBACK_START_DMA_DESCR_CH9; 888ccfbb4f5SMukunda, Vijendar rtd->byte_cnt_high_reg_offset = 889ccfbb4f5SMukunda, Vijendar mmACP_I2S_BT_TRANSMIT_BYTE_CNT_HIGH; 890ccfbb4f5SMukunda, Vijendar rtd->byte_cnt_low_reg_offset = 891ccfbb4f5SMukunda, Vijendar mmACP_I2S_BT_TRANSMIT_BYTE_CNT_LOW; 892ccfbb4f5SMukunda, Vijendar adata->play_i2sbt_stream = substream; 893ccfbb4f5SMukunda, Vijendar break; 894ccfbb4f5SMukunda, Vijendar case I2S_SP_INSTANCE: 895ccfbb4f5SMukunda, Vijendar default: 896e188c525SMukunda, Vijendar switch (adata->asic_type) { 897e188c525SMukunda, Vijendar case CHIP_STONEY: 898e188c525SMukunda, Vijendar rtd->pte_offset = ACP_ST_PLAYBACK_PTE_OFFSET; 899e188c525SMukunda, Vijendar break; 900e188c525SMukunda, Vijendar default: 901e188c525SMukunda, Vijendar rtd->pte_offset = ACP_PLAYBACK_PTE_OFFSET; 902e188c525SMukunda, Vijendar } 9038769bb55SVijendar Mukunda rtd->ch1 = SYSRAM_TO_ACP_CH_NUM; 9048769bb55SVijendar Mukunda rtd->ch2 = ACP_TO_I2S_DMA_CH_NUM; 90518e8a40dSMukunda, Vijendar rtd->sram_bank = ACP_SRAM_BANK_1_ADDRESS; 9068769bb55SVijendar Mukunda rtd->destination = TO_ACP_I2S_1; 9078769bb55SVijendar Mukunda rtd->dma_dscr_idx_1 = PLAYBACK_START_DMA_DESCR_CH12; 9088769bb55SVijendar Mukunda rtd->dma_dscr_idx_2 = PLAYBACK_START_DMA_DESCR_CH13; 9097f004847SVijendar Mukunda rtd->byte_cnt_high_reg_offset = 9107f004847SVijendar Mukunda mmACP_I2S_TRANSMIT_BYTE_CNT_HIGH; 911ccfbb4f5SMukunda, Vijendar rtd->byte_cnt_low_reg_offset = 912ccfbb4f5SMukunda, Vijendar mmACP_I2S_TRANSMIT_BYTE_CNT_LOW; 913ccfbb4f5SMukunda, Vijendar adata->play_i2ssp_stream = substream; 914ccfbb4f5SMukunda, Vijendar } 9158769bb55SVijendar Mukunda } else { 916ccfbb4f5SMukunda, Vijendar switch (rtd->i2s_instance) { 917ccfbb4f5SMukunda, Vijendar case I2S_BT_INSTANCE: 918ccfbb4f5SMukunda, Vijendar rtd->pte_offset = ACP_ST_BT_CAPTURE_PTE_OFFSET; 91955af49acSDaniel Kurtz rtd->ch1 = I2S_TO_ACP_DMA_BT_INSTANCE_CH_NUM; 92055af49acSDaniel Kurtz rtd->ch2 = ACP_TO_SYSRAM_BT_INSTANCE_CH_NUM; 921ccfbb4f5SMukunda, Vijendar rtd->sram_bank = ACP_SRAM_BANK_4_ADDRESS; 922ccfbb4f5SMukunda, Vijendar rtd->destination = FROM_BLUETOOTH; 923ccfbb4f5SMukunda, Vijendar rtd->dma_dscr_idx_1 = CAPTURE_START_DMA_DESCR_CH10; 924ccfbb4f5SMukunda, Vijendar rtd->dma_dscr_idx_2 = CAPTURE_START_DMA_DESCR_CH11; 925ccfbb4f5SMukunda, Vijendar rtd->byte_cnt_high_reg_offset = 926ccfbb4f5SMukunda, Vijendar mmACP_I2S_BT_RECEIVE_BYTE_CNT_HIGH; 927ccfbb4f5SMukunda, Vijendar rtd->byte_cnt_low_reg_offset = 928ccfbb4f5SMukunda, Vijendar mmACP_I2S_BT_RECEIVE_BYTE_CNT_LOW; 929ccfbb4f5SMukunda, Vijendar adata->capture_i2sbt_stream = substream; 930ccfbb4f5SMukunda, Vijendar break; 931ccfbb4f5SMukunda, Vijendar case I2S_SP_INSTANCE: 932ccfbb4f5SMukunda, Vijendar default: 933ccfbb4f5SMukunda, Vijendar rtd->pte_offset = ACP_CAPTURE_PTE_OFFSET; 93455af49acSDaniel Kurtz rtd->ch1 = I2S_TO_ACP_DMA_CH_NUM; 93555af49acSDaniel Kurtz rtd->ch2 = ACP_TO_SYSRAM_CH_NUM; 936e188c525SMukunda, Vijendar switch (adata->asic_type) { 937e188c525SMukunda, Vijendar case CHIP_STONEY: 938e188c525SMukunda, Vijendar rtd->pte_offset = ACP_ST_CAPTURE_PTE_OFFSET; 93918e8a40dSMukunda, Vijendar rtd->sram_bank = ACP_SRAM_BANK_2_ADDRESS; 940e188c525SMukunda, Vijendar break; 941e188c525SMukunda, Vijendar default: 942e188c525SMukunda, Vijendar rtd->pte_offset = ACP_CAPTURE_PTE_OFFSET; 94318e8a40dSMukunda, Vijendar rtd->sram_bank = ACP_SRAM_BANK_5_ADDRESS; 944e188c525SMukunda, Vijendar } 9458769bb55SVijendar Mukunda rtd->destination = FROM_ACP_I2S_1; 9468769bb55SVijendar Mukunda rtd->dma_dscr_idx_1 = CAPTURE_START_DMA_DESCR_CH14; 9478769bb55SVijendar Mukunda rtd->dma_dscr_idx_2 = CAPTURE_START_DMA_DESCR_CH15; 9487f004847SVijendar Mukunda rtd->byte_cnt_high_reg_offset = 9497f004847SVijendar Mukunda mmACP_I2S_RECEIVED_BYTE_CNT_HIGH; 950ccfbb4f5SMukunda, Vijendar rtd->byte_cnt_low_reg_offset = 951ccfbb4f5SMukunda, Vijendar mmACP_I2S_RECEIVED_BYTE_CNT_LOW; 952ccfbb4f5SMukunda, Vijendar adata->capture_i2ssp_stream = substream; 953ccfbb4f5SMukunda, Vijendar } 9548769bb55SVijendar Mukunda } 9558769bb55SVijendar Mukunda 9567c31335aSMaruthi Srinivas Bayyavarapu size = params_buffer_bytes(params); 9577c31335aSMaruthi Srinivas Bayyavarapu status = snd_pcm_lib_malloc_pages(substream, size); 9587c31335aSMaruthi Srinivas Bayyavarapu if (status < 0) 9597c31335aSMaruthi Srinivas Bayyavarapu return status; 9607c31335aSMaruthi Srinivas Bayyavarapu 9617c31335aSMaruthi Srinivas Bayyavarapu memset(substream->runtime->dma_area, 0, params_buffer_bytes(params)); 9627c31335aSMaruthi Srinivas Bayyavarapu pg = virt_to_page(substream->dma_buffer.area); 9637c31335aSMaruthi Srinivas Bayyavarapu 96413838c11SMukunda, Vijendar if (pg) { 965c36d9b3fSMaruthi Srinivas Bayyavarapu acp_set_sram_bank_state(rtd->acp_mmio, 0, true); 9667c31335aSMaruthi Srinivas Bayyavarapu /* Save for runtime private data */ 9677c31335aSMaruthi Srinivas Bayyavarapu rtd->pg = pg; 9687c31335aSMaruthi Srinivas Bayyavarapu rtd->order = get_order(size); 9697c31335aSMaruthi Srinivas Bayyavarapu 9707c31335aSMaruthi Srinivas Bayyavarapu /* Fill the page table entries in ACP SRAM */ 9717c31335aSMaruthi Srinivas Bayyavarapu rtd->pg = pg; 9727c31335aSMaruthi Srinivas Bayyavarapu rtd->size = size; 9737c31335aSMaruthi Srinivas Bayyavarapu rtd->num_of_pages = PAGE_ALIGN(size) >> PAGE_SHIFT; 9747c31335aSMaruthi Srinivas Bayyavarapu rtd->direction = substream->stream; 9757c31335aSMaruthi Srinivas Bayyavarapu 976aac89748SVijendar Mukunda config_acp_dma(rtd->acp_mmio, rtd, adata->asic_type); 9777c31335aSMaruthi Srinivas Bayyavarapu status = 0; 9787c31335aSMaruthi Srinivas Bayyavarapu } else { 9797c31335aSMaruthi Srinivas Bayyavarapu status = -ENOMEM; 9807c31335aSMaruthi Srinivas Bayyavarapu } 9817c31335aSMaruthi Srinivas Bayyavarapu return status; 9827c31335aSMaruthi Srinivas Bayyavarapu } 9837c31335aSMaruthi Srinivas Bayyavarapu 9847c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_hw_free(struct snd_pcm_substream *substream) 9857c31335aSMaruthi Srinivas Bayyavarapu { 9867c31335aSMaruthi Srinivas Bayyavarapu return snd_pcm_lib_free_pages(substream); 9877c31335aSMaruthi Srinivas Bayyavarapu } 9887c31335aSMaruthi Srinivas Bayyavarapu 9897f004847SVijendar Mukunda static u64 acp_get_byte_count(struct audio_substream_data *rtd) 99061add814SVijendar Mukunda { 9917f004847SVijendar Mukunda union acp_dma_count byte_count; 99261add814SVijendar Mukunda 9937f004847SVijendar Mukunda byte_count.bcount.high = acp_reg_read(rtd->acp_mmio, 9947f004847SVijendar Mukunda rtd->byte_cnt_high_reg_offset); 9957f004847SVijendar Mukunda byte_count.bcount.low = acp_reg_read(rtd->acp_mmio, 9967f004847SVijendar Mukunda rtd->byte_cnt_low_reg_offset); 9977f004847SVijendar Mukunda return byte_count.bytescount; 99861add814SVijendar Mukunda } 99961add814SVijendar Mukunda 10007c31335aSMaruthi Srinivas Bayyavarapu static snd_pcm_uframes_t acp_dma_pointer(struct snd_pcm_substream *substream) 10017c31335aSMaruthi Srinivas Bayyavarapu { 100261add814SVijendar Mukunda u32 buffersize; 10037c31335aSMaruthi Srinivas Bayyavarapu u32 pos = 0; 100461add814SVijendar Mukunda u64 bytescount = 0; 10057c31335aSMaruthi Srinivas Bayyavarapu 10067c31335aSMaruthi Srinivas Bayyavarapu struct snd_pcm_runtime *runtime = substream->runtime; 10077c31335aSMaruthi Srinivas Bayyavarapu struct audio_substream_data *rtd = runtime->private_data; 10087c31335aSMaruthi Srinivas Bayyavarapu 10097afa535eSMukunda, Vijendar if (!rtd) 10107afa535eSMukunda, Vijendar return -EINVAL; 10117afa535eSMukunda, Vijendar 101261add814SVijendar Mukunda buffersize = frames_to_bytes(runtime, runtime->buffer_size); 10137f004847SVijendar Mukunda bytescount = acp_get_byte_count(rtd); 101461add814SVijendar Mukunda 10159af8937eSVijendar Mukunda bytescount -= rtd->bytescount; 10167db08b2cSGuenter Roeck pos = do_div(bytescount, buffersize); 10177c31335aSMaruthi Srinivas Bayyavarapu return bytes_to_frames(runtime, pos); 10187c31335aSMaruthi Srinivas Bayyavarapu } 10197c31335aSMaruthi Srinivas Bayyavarapu 10207c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_mmap(struct snd_pcm_substream *substream, 10217c31335aSMaruthi Srinivas Bayyavarapu struct vm_area_struct *vma) 10227c31335aSMaruthi Srinivas Bayyavarapu { 10237c31335aSMaruthi Srinivas Bayyavarapu return snd_pcm_lib_default_mmap(substream, vma); 10247c31335aSMaruthi Srinivas Bayyavarapu } 10257c31335aSMaruthi Srinivas Bayyavarapu 10267c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_prepare(struct snd_pcm_substream *substream) 10277c31335aSMaruthi Srinivas Bayyavarapu { 10287c31335aSMaruthi Srinivas Bayyavarapu struct snd_pcm_runtime *runtime = substream->runtime; 10297c31335aSMaruthi Srinivas Bayyavarapu struct audio_substream_data *rtd = runtime->private_data; 1030fa9d2f17SAgrawal, Akshu u16 ch_acp_sysmem, ch_acp_i2s; 10317c31335aSMaruthi Srinivas Bayyavarapu 10327afa535eSMukunda, Vijendar if (!rtd) 10337afa535eSMukunda, Vijendar return -EINVAL; 10348769bb55SVijendar Mukunda 1035fa9d2f17SAgrawal, Akshu if (rtd->direction == SNDRV_PCM_STREAM_PLAYBACK) { 1036fa9d2f17SAgrawal, Akshu ch_acp_sysmem = rtd->ch1; 1037fa9d2f17SAgrawal, Akshu ch_acp_i2s = rtd->ch2; 1038fa9d2f17SAgrawal, Akshu } else { 1039fa9d2f17SAgrawal, Akshu ch_acp_i2s = rtd->ch1; 1040fa9d2f17SAgrawal, Akshu ch_acp_sysmem = rtd->ch2; 1041fa9d2f17SAgrawal, Akshu } 10428769bb55SVijendar Mukunda config_acp_dma_channel(rtd->acp_mmio, 1043fa9d2f17SAgrawal, Akshu ch_acp_sysmem, 10448769bb55SVijendar Mukunda rtd->dma_dscr_idx_1, 10457c31335aSMaruthi Srinivas Bayyavarapu NUM_DSCRS_PER_CHANNEL, 0); 10468769bb55SVijendar Mukunda config_acp_dma_channel(rtd->acp_mmio, 1047fa9d2f17SAgrawal, Akshu ch_acp_i2s, 10488769bb55SVijendar Mukunda rtd->dma_dscr_idx_2, 10497c31335aSMaruthi Srinivas Bayyavarapu NUM_DSCRS_PER_CHANNEL, 0); 10507c31335aSMaruthi Srinivas Bayyavarapu return 0; 10517c31335aSMaruthi Srinivas Bayyavarapu } 10527c31335aSMaruthi Srinivas Bayyavarapu 10537c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_trigger(struct snd_pcm_substream *substream, int cmd) 10547c31335aSMaruthi Srinivas Bayyavarapu { 10557c31335aSMaruthi Srinivas Bayyavarapu int ret; 10567c31335aSMaruthi Srinivas Bayyavarapu 10577c31335aSMaruthi Srinivas Bayyavarapu struct snd_pcm_runtime *runtime = substream->runtime; 10587c31335aSMaruthi Srinivas Bayyavarapu struct audio_substream_data *rtd = runtime->private_data; 10597c31335aSMaruthi Srinivas Bayyavarapu 10607c31335aSMaruthi Srinivas Bayyavarapu if (!rtd) 10617c31335aSMaruthi Srinivas Bayyavarapu return -EINVAL; 10627c31335aSMaruthi Srinivas Bayyavarapu switch (cmd) { 10637c31335aSMaruthi Srinivas Bayyavarapu case SNDRV_PCM_TRIGGER_START: 10647c31335aSMaruthi Srinivas Bayyavarapu case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 10657c31335aSMaruthi Srinivas Bayyavarapu case SNDRV_PCM_TRIGGER_RESUME: 10661a337a1eSDaniel Kurtz rtd->bytescount = acp_get_byte_count(rtd); 1067df61f9f7SDaniel Kurtz if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { 10682718c89aSAkshu Agrawal if (rtd->capture_channel == CAP_CHANNEL0) { 10692718c89aSAkshu Agrawal acp_dma_cap_channel_disable(rtd->acp_mmio, 10702718c89aSAkshu Agrawal CAP_CHANNEL1); 10712718c89aSAkshu Agrawal acp_dma_cap_channel_enable(rtd->acp_mmio, 10722718c89aSAkshu Agrawal CAP_CHANNEL0); 10732718c89aSAkshu Agrawal } 10742718c89aSAkshu Agrawal if (rtd->capture_channel == CAP_CHANNEL1) { 10752718c89aSAkshu Agrawal acp_dma_cap_channel_disable(rtd->acp_mmio, 10762718c89aSAkshu Agrawal CAP_CHANNEL0); 10772718c89aSAkshu Agrawal acp_dma_cap_channel_enable(rtd->acp_mmio, 10782718c89aSAkshu Agrawal CAP_CHANNEL1); 10792718c89aSAkshu Agrawal } 1080*bbdb7012SAkshu Agrawal acp_dma_start(rtd->acp_mmio, rtd->ch1, true); 1081*bbdb7012SAkshu Agrawal } else { 1082*bbdb7012SAkshu Agrawal acp_dma_start(rtd->acp_mmio, rtd->ch1, true); 1083*bbdb7012SAkshu Agrawal acp_dma_start(rtd->acp_mmio, rtd->ch2, true); 10847c31335aSMaruthi Srinivas Bayyavarapu } 10857c31335aSMaruthi Srinivas Bayyavarapu ret = 0; 10867c31335aSMaruthi Srinivas Bayyavarapu break; 10877c31335aSMaruthi Srinivas Bayyavarapu case SNDRV_PCM_TRIGGER_STOP: 10887c31335aSMaruthi Srinivas Bayyavarapu case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 10897c31335aSMaruthi Srinivas Bayyavarapu case SNDRV_PCM_TRIGGER_SUSPEND: 10908769bb55SVijendar Mukunda acp_dma_stop(rtd->acp_mmio, rtd->ch2); 10918769bb55SVijendar Mukunda ret = acp_dma_stop(rtd->acp_mmio, rtd->ch1); 10927c31335aSMaruthi Srinivas Bayyavarapu break; 10937c31335aSMaruthi Srinivas Bayyavarapu default: 10947c31335aSMaruthi Srinivas Bayyavarapu ret = -EINVAL; 10957c31335aSMaruthi Srinivas Bayyavarapu } 10967c31335aSMaruthi Srinivas Bayyavarapu return ret; 10977c31335aSMaruthi Srinivas Bayyavarapu } 10987c31335aSMaruthi Srinivas Bayyavarapu 10997c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_new(struct snd_soc_pcm_runtime *rtd) 11007c31335aSMaruthi Srinivas Bayyavarapu { 11019c7d6fabSVijendar Mukunda int ret; 110213838c11SMukunda, Vijendar struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, 110313838c11SMukunda, Vijendar DRV_NAME); 1104a1042a42SKuninori Morimoto struct audio_drv_data *adata = dev_get_drvdata(component->dev); 11059c7d6fabSVijendar Mukunda 11069c7d6fabSVijendar Mukunda switch (adata->asic_type) { 11079c7d6fabSVijendar Mukunda case CHIP_STONEY: 11089c7d6fabSVijendar Mukunda ret = snd_pcm_lib_preallocate_pages_for_all(rtd->pcm, 11099c7d6fabSVijendar Mukunda SNDRV_DMA_TYPE_DEV, 11109c7d6fabSVijendar Mukunda NULL, ST_MIN_BUFFER, 11119c7d6fabSVijendar Mukunda ST_MAX_BUFFER); 11129c7d6fabSVijendar Mukunda break; 11139c7d6fabSVijendar Mukunda default: 11149c7d6fabSVijendar Mukunda ret = snd_pcm_lib_preallocate_pages_for_all(rtd->pcm, 11157c31335aSMaruthi Srinivas Bayyavarapu SNDRV_DMA_TYPE_DEV, 11167c31335aSMaruthi Srinivas Bayyavarapu NULL, MIN_BUFFER, 11177c31335aSMaruthi Srinivas Bayyavarapu MAX_BUFFER); 11189c7d6fabSVijendar Mukunda break; 11199c7d6fabSVijendar Mukunda } 11209c7d6fabSVijendar Mukunda if (ret < 0) 1121a1042a42SKuninori Morimoto dev_err(component->dev, 11229e6a469eSColin Ian King "buffer preallocation failure error:%d\n", ret); 11239c7d6fabSVijendar Mukunda return ret; 11247c31335aSMaruthi Srinivas Bayyavarapu } 11257c31335aSMaruthi Srinivas Bayyavarapu 11267c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_close(struct snd_pcm_substream *substream) 11277c31335aSMaruthi Srinivas Bayyavarapu { 1128c36d9b3fSMaruthi Srinivas Bayyavarapu u16 bank; 11297c31335aSMaruthi Srinivas Bayyavarapu struct snd_pcm_runtime *runtime = substream->runtime; 11307c31335aSMaruthi Srinivas Bayyavarapu struct audio_substream_data *rtd = runtime->private_data; 11317c31335aSMaruthi Srinivas Bayyavarapu struct snd_soc_pcm_runtime *prtd = substream->private_data; 113213838c11SMukunda, Vijendar struct snd_soc_component *component = snd_soc_rtdcom_lookup(prtd, 113313838c11SMukunda, Vijendar DRV_NAME); 1134a1042a42SKuninori Morimoto struct audio_drv_data *adata = dev_get_drvdata(component->dev); 11357c31335aSMaruthi Srinivas Bayyavarapu 1136c36d9b3fSMaruthi Srinivas Bayyavarapu if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 1137ccfbb4f5SMukunda, Vijendar switch (rtd->i2s_instance) { 1138ccfbb4f5SMukunda, Vijendar case I2S_BT_INSTANCE: 1139ccfbb4f5SMukunda, Vijendar adata->play_i2sbt_stream = NULL; 1140ccfbb4f5SMukunda, Vijendar break; 1141ccfbb4f5SMukunda, Vijendar case I2S_SP_INSTANCE: 1142ccfbb4f5SMukunda, Vijendar default: 1143e21358c4SMukunda, Vijendar adata->play_i2ssp_stream = NULL; 114413838c11SMukunda, Vijendar /* 114513838c11SMukunda, Vijendar * For Stoney, Memory gating is disabled,i.e SRAM Banks 1146ccfbb4f5SMukunda, Vijendar * won't be turned off. The default state for SRAM banks 1147ccfbb4f5SMukunda, Vijendar * is ON.Setting SRAM bank state code skipped for STONEY 1148ccfbb4f5SMukunda, Vijendar * platform. Added condition checks for Carrizo platform 1149ccfbb4f5SMukunda, Vijendar * only. 1150607b39efSVijendar Mukunda */ 1151607b39efSVijendar Mukunda if (adata->asic_type != CHIP_STONEY) { 1152c36d9b3fSMaruthi Srinivas Bayyavarapu for (bank = 1; bank <= 4; bank++) 1153ccfbb4f5SMukunda, Vijendar acp_set_sram_bank_state(adata->acp_mmio, 1154ccfbb4f5SMukunda, Vijendar bank, false); 1155ccfbb4f5SMukunda, Vijendar } 1156607b39efSVijendar Mukunda } 1157c36d9b3fSMaruthi Srinivas Bayyavarapu } else { 1158ccfbb4f5SMukunda, Vijendar switch (rtd->i2s_instance) { 1159ccfbb4f5SMukunda, Vijendar case I2S_BT_INSTANCE: 1160ccfbb4f5SMukunda, Vijendar adata->capture_i2sbt_stream = NULL; 1161ccfbb4f5SMukunda, Vijendar break; 1162ccfbb4f5SMukunda, Vijendar case I2S_SP_INSTANCE: 1163ccfbb4f5SMukunda, Vijendar default: 1164e21358c4SMukunda, Vijendar adata->capture_i2ssp_stream = NULL; 1165607b39efSVijendar Mukunda if (adata->asic_type != CHIP_STONEY) { 1166c36d9b3fSMaruthi Srinivas Bayyavarapu for (bank = 5; bank <= 8; bank++) 1167ccfbb4f5SMukunda, Vijendar acp_set_sram_bank_state(adata->acp_mmio, 1168ccfbb4f5SMukunda, Vijendar bank, false); 1169ccfbb4f5SMukunda, Vijendar } 1170c36d9b3fSMaruthi Srinivas Bayyavarapu } 1171607b39efSVijendar Mukunda } 11727c31335aSMaruthi Srinivas Bayyavarapu 117313838c11SMukunda, Vijendar /* 117413838c11SMukunda, Vijendar * Disable ACP irq, when the current stream is being closed and 11757c31335aSMaruthi Srinivas Bayyavarapu * another stream is also not active. 11767c31335aSMaruthi Srinivas Bayyavarapu */ 1177ccfbb4f5SMukunda, Vijendar if (!adata->play_i2ssp_stream && !adata->capture_i2ssp_stream && 1178ccfbb4f5SMukunda, Vijendar !adata->play_i2sbt_stream && !adata->capture_i2sbt_stream) 11797c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(0, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); 1180cac6f597SMukunda, Vijendar kfree(rtd); 11817c31335aSMaruthi Srinivas Bayyavarapu return 0; 11827c31335aSMaruthi Srinivas Bayyavarapu } 11837c31335aSMaruthi Srinivas Bayyavarapu 1184115c7254SJulia Lawall static const struct snd_pcm_ops acp_dma_ops = { 11857c31335aSMaruthi Srinivas Bayyavarapu .open = acp_dma_open, 11867c31335aSMaruthi Srinivas Bayyavarapu .close = acp_dma_close, 11877c31335aSMaruthi Srinivas Bayyavarapu .ioctl = snd_pcm_lib_ioctl, 11887c31335aSMaruthi Srinivas Bayyavarapu .hw_params = acp_dma_hw_params, 11897c31335aSMaruthi Srinivas Bayyavarapu .hw_free = acp_dma_hw_free, 11907c31335aSMaruthi Srinivas Bayyavarapu .trigger = acp_dma_trigger, 11917c31335aSMaruthi Srinivas Bayyavarapu .pointer = acp_dma_pointer, 11927c31335aSMaruthi Srinivas Bayyavarapu .mmap = acp_dma_mmap, 11937c31335aSMaruthi Srinivas Bayyavarapu .prepare = acp_dma_prepare, 11947c31335aSMaruthi Srinivas Bayyavarapu }; 11957c31335aSMaruthi Srinivas Bayyavarapu 119613838c11SMukunda, Vijendar static const struct snd_soc_component_driver acp_asoc_platform = { 1197a1042a42SKuninori Morimoto .name = DRV_NAME, 11987c31335aSMaruthi Srinivas Bayyavarapu .ops = &acp_dma_ops, 11997c31335aSMaruthi Srinivas Bayyavarapu .pcm_new = acp_dma_new, 12007c31335aSMaruthi Srinivas Bayyavarapu }; 12017c31335aSMaruthi Srinivas Bayyavarapu 12027c31335aSMaruthi Srinivas Bayyavarapu static int acp_audio_probe(struct platform_device *pdev) 12037c31335aSMaruthi Srinivas Bayyavarapu { 12047c31335aSMaruthi Srinivas Bayyavarapu int status; 12057c31335aSMaruthi Srinivas Bayyavarapu struct audio_drv_data *audio_drv_data; 12067c31335aSMaruthi Srinivas Bayyavarapu struct resource *res; 1207a1b16aaaSVijendar Mukunda const u32 *pdata = pdev->dev.platform_data; 12087c31335aSMaruthi Srinivas Bayyavarapu 1209fdaa4511SGuenter Roeck if (!pdata) { 1210fdaa4511SGuenter Roeck dev_err(&pdev->dev, "Missing platform data\n"); 1211fdaa4511SGuenter Roeck return -ENODEV; 1212fdaa4511SGuenter Roeck } 1213fdaa4511SGuenter Roeck 12147c31335aSMaruthi Srinivas Bayyavarapu audio_drv_data = devm_kzalloc(&pdev->dev, sizeof(struct audio_drv_data), 12157c31335aSMaruthi Srinivas Bayyavarapu GFP_KERNEL); 121613838c11SMukunda, Vijendar if (!audio_drv_data) 12177c31335aSMaruthi Srinivas Bayyavarapu return -ENOMEM; 12187c31335aSMaruthi Srinivas Bayyavarapu 12197c31335aSMaruthi Srinivas Bayyavarapu res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 12207c31335aSMaruthi Srinivas Bayyavarapu audio_drv_data->acp_mmio = devm_ioremap_resource(&pdev->dev, res); 1221fdaa4511SGuenter Roeck if (IS_ERR(audio_drv_data->acp_mmio)) 1222fdaa4511SGuenter Roeck return PTR_ERR(audio_drv_data->acp_mmio); 12237c31335aSMaruthi Srinivas Bayyavarapu 122413838c11SMukunda, Vijendar /* 122513838c11SMukunda, Vijendar * The following members gets populated in device 'open' 12267c31335aSMaruthi Srinivas Bayyavarapu * function. Till then interrupts are disabled in 'acp_init' 12277c31335aSMaruthi Srinivas Bayyavarapu * and device doesn't generate any interrupts. 12287c31335aSMaruthi Srinivas Bayyavarapu */ 12297c31335aSMaruthi Srinivas Bayyavarapu 1230e21358c4SMukunda, Vijendar audio_drv_data->play_i2ssp_stream = NULL; 1231e21358c4SMukunda, Vijendar audio_drv_data->capture_i2ssp_stream = NULL; 1232ccfbb4f5SMukunda, Vijendar audio_drv_data->play_i2sbt_stream = NULL; 1233ccfbb4f5SMukunda, Vijendar audio_drv_data->capture_i2sbt_stream = NULL; 1234e21358c4SMukunda, Vijendar 1235a1b16aaaSVijendar Mukunda audio_drv_data->asic_type = *pdata; 12367c31335aSMaruthi Srinivas Bayyavarapu 12377c31335aSMaruthi Srinivas Bayyavarapu res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 12387c31335aSMaruthi Srinivas Bayyavarapu if (!res) { 12397c31335aSMaruthi Srinivas Bayyavarapu dev_err(&pdev->dev, "IORESOURCE_IRQ FAILED\n"); 12407c31335aSMaruthi Srinivas Bayyavarapu return -ENODEV; 12417c31335aSMaruthi Srinivas Bayyavarapu } 12427c31335aSMaruthi Srinivas Bayyavarapu 12437c31335aSMaruthi Srinivas Bayyavarapu status = devm_request_irq(&pdev->dev, res->start, dma_irq_handler, 12447c31335aSMaruthi Srinivas Bayyavarapu 0, "ACP_IRQ", &pdev->dev); 12457c31335aSMaruthi Srinivas Bayyavarapu if (status) { 12467c31335aSMaruthi Srinivas Bayyavarapu dev_err(&pdev->dev, "ACP IRQ request failed\n"); 12477c31335aSMaruthi Srinivas Bayyavarapu return status; 12487c31335aSMaruthi Srinivas Bayyavarapu } 12497c31335aSMaruthi Srinivas Bayyavarapu 12507c31335aSMaruthi Srinivas Bayyavarapu dev_set_drvdata(&pdev->dev, audio_drv_data); 12517c31335aSMaruthi Srinivas Bayyavarapu 12527c31335aSMaruthi Srinivas Bayyavarapu /* Initialize the ACP */ 12537afa535eSMukunda, Vijendar status = acp_init(audio_drv_data->acp_mmio, audio_drv_data->asic_type); 12547afa535eSMukunda, Vijendar if (status) { 12557afa535eSMukunda, Vijendar dev_err(&pdev->dev, "ACP Init failed status:%d\n", status); 12567afa535eSMukunda, Vijendar return status; 12577afa535eSMukunda, Vijendar } 12587c31335aSMaruthi Srinivas Bayyavarapu 1259a1042a42SKuninori Morimoto status = devm_snd_soc_register_component(&pdev->dev, 1260a1042a42SKuninori Morimoto &acp_asoc_platform, NULL, 0); 12617c31335aSMaruthi Srinivas Bayyavarapu if (status != 0) { 12627c31335aSMaruthi Srinivas Bayyavarapu dev_err(&pdev->dev, "Fail to register ALSA platform device\n"); 12637c31335aSMaruthi Srinivas Bayyavarapu return status; 12647c31335aSMaruthi Srinivas Bayyavarapu } 12657c31335aSMaruthi Srinivas Bayyavarapu 12661927da93SMaruthi Srinivas Bayyavarapu pm_runtime_set_autosuspend_delay(&pdev->dev, 10000); 12671927da93SMaruthi Srinivas Bayyavarapu pm_runtime_use_autosuspend(&pdev->dev); 12681927da93SMaruthi Srinivas Bayyavarapu pm_runtime_enable(&pdev->dev); 12691927da93SMaruthi Srinivas Bayyavarapu 12707c31335aSMaruthi Srinivas Bayyavarapu return status; 12717c31335aSMaruthi Srinivas Bayyavarapu } 12727c31335aSMaruthi Srinivas Bayyavarapu 12737c31335aSMaruthi Srinivas Bayyavarapu static int acp_audio_remove(struct platform_device *pdev) 12747c31335aSMaruthi Srinivas Bayyavarapu { 12757afa535eSMukunda, Vijendar int status; 12767c31335aSMaruthi Srinivas Bayyavarapu struct audio_drv_data *adata = dev_get_drvdata(&pdev->dev); 12777c31335aSMaruthi Srinivas Bayyavarapu 12787afa535eSMukunda, Vijendar status = acp_deinit(adata->acp_mmio); 12797afa535eSMukunda, Vijendar if (status) 12807afa535eSMukunda, Vijendar dev_err(&pdev->dev, "ACP Deinit failed status:%d\n", status); 12811927da93SMaruthi Srinivas Bayyavarapu pm_runtime_disable(&pdev->dev); 12827c31335aSMaruthi Srinivas Bayyavarapu 12837c31335aSMaruthi Srinivas Bayyavarapu return 0; 12847c31335aSMaruthi Srinivas Bayyavarapu } 12857c31335aSMaruthi Srinivas Bayyavarapu 12861927da93SMaruthi Srinivas Bayyavarapu static int acp_pcm_resume(struct device *dev) 12871927da93SMaruthi Srinivas Bayyavarapu { 1288c36d9b3fSMaruthi Srinivas Bayyavarapu u16 bank; 12897afa535eSMukunda, Vijendar int status; 1290ccfbb4f5SMukunda, Vijendar struct audio_substream_data *rtd; 12911927da93SMaruthi Srinivas Bayyavarapu struct audio_drv_data *adata = dev_get_drvdata(dev); 12921927da93SMaruthi Srinivas Bayyavarapu 12937afa535eSMukunda, Vijendar status = acp_init(adata->acp_mmio, adata->asic_type); 12947afa535eSMukunda, Vijendar if (status) { 12957afa535eSMukunda, Vijendar dev_err(dev, "ACP Init failed status:%d\n", status); 12967afa535eSMukunda, Vijendar return status; 12977afa535eSMukunda, Vijendar } 12981927da93SMaruthi Srinivas Bayyavarapu 1299e21358c4SMukunda, Vijendar if (adata->play_i2ssp_stream && adata->play_i2ssp_stream->runtime) { 130013838c11SMukunda, Vijendar /* 130113838c11SMukunda, Vijendar * For Stoney, Memory gating is disabled,i.e SRAM Banks 1302607b39efSVijendar Mukunda * won't be turned off. The default state for SRAM banks is ON. 1303607b39efSVijendar Mukunda * Setting SRAM bank state code skipped for STONEY platform. 1304607b39efSVijendar Mukunda */ 1305607b39efSVijendar Mukunda if (adata->asic_type != CHIP_STONEY) { 1306c36d9b3fSMaruthi Srinivas Bayyavarapu for (bank = 1; bank <= 4; bank++) 1307c36d9b3fSMaruthi Srinivas Bayyavarapu acp_set_sram_bank_state(adata->acp_mmio, bank, 1308c36d9b3fSMaruthi Srinivas Bayyavarapu true); 1309607b39efSVijendar Mukunda } 1310ccfbb4f5SMukunda, Vijendar rtd = adata->play_i2ssp_stream->runtime->private_data; 1311ccfbb4f5SMukunda, Vijendar config_acp_dma(adata->acp_mmio, rtd, adata->asic_type); 1312c36d9b3fSMaruthi Srinivas Bayyavarapu } 131313838c11SMukunda, Vijendar if (adata->capture_i2ssp_stream && 131413838c11SMukunda, Vijendar adata->capture_i2ssp_stream->runtime) { 1315607b39efSVijendar Mukunda if (adata->asic_type != CHIP_STONEY) { 1316c36d9b3fSMaruthi Srinivas Bayyavarapu for (bank = 5; bank <= 8; bank++) 1317c36d9b3fSMaruthi Srinivas Bayyavarapu acp_set_sram_bank_state(adata->acp_mmio, bank, 1318c36d9b3fSMaruthi Srinivas Bayyavarapu true); 1319607b39efSVijendar Mukunda } 1320ccfbb4f5SMukunda, Vijendar rtd = adata->capture_i2ssp_stream->runtime->private_data; 1321ccfbb4f5SMukunda, Vijendar config_acp_dma(adata->acp_mmio, rtd, adata->asic_type); 1322ccfbb4f5SMukunda, Vijendar } 1323ccfbb4f5SMukunda, Vijendar if (adata->asic_type != CHIP_CARRIZO) { 1324ccfbb4f5SMukunda, Vijendar if (adata->play_i2sbt_stream && 1325ccfbb4f5SMukunda, Vijendar adata->play_i2sbt_stream->runtime) { 1326ccfbb4f5SMukunda, Vijendar rtd = adata->play_i2sbt_stream->runtime->private_data; 1327ccfbb4f5SMukunda, Vijendar config_acp_dma(adata->acp_mmio, rtd, adata->asic_type); 1328ccfbb4f5SMukunda, Vijendar } 1329ccfbb4f5SMukunda, Vijendar if (adata->capture_i2sbt_stream && 1330ccfbb4f5SMukunda, Vijendar adata->capture_i2sbt_stream->runtime) { 1331ccfbb4f5SMukunda, Vijendar rtd = adata->capture_i2sbt_stream->runtime->private_data; 1332ccfbb4f5SMukunda, Vijendar config_acp_dma(adata->acp_mmio, rtd, adata->asic_type); 1333ccfbb4f5SMukunda, Vijendar } 1334c36d9b3fSMaruthi Srinivas Bayyavarapu } 13351927da93SMaruthi Srinivas Bayyavarapu acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); 13361927da93SMaruthi Srinivas Bayyavarapu return 0; 13371927da93SMaruthi Srinivas Bayyavarapu } 13381927da93SMaruthi Srinivas Bayyavarapu 13391927da93SMaruthi Srinivas Bayyavarapu static int acp_pcm_runtime_suspend(struct device *dev) 13401927da93SMaruthi Srinivas Bayyavarapu { 13417afa535eSMukunda, Vijendar int status; 13421927da93SMaruthi Srinivas Bayyavarapu struct audio_drv_data *adata = dev_get_drvdata(dev); 13431927da93SMaruthi Srinivas Bayyavarapu 13447afa535eSMukunda, Vijendar status = acp_deinit(adata->acp_mmio); 13457afa535eSMukunda, Vijendar if (status) 13467afa535eSMukunda, Vijendar dev_err(dev, "ACP Deinit failed status:%d\n", status); 13471927da93SMaruthi Srinivas Bayyavarapu acp_reg_write(0, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); 13481927da93SMaruthi Srinivas Bayyavarapu return 0; 13491927da93SMaruthi Srinivas Bayyavarapu } 13501927da93SMaruthi Srinivas Bayyavarapu 13511927da93SMaruthi Srinivas Bayyavarapu static int acp_pcm_runtime_resume(struct device *dev) 13521927da93SMaruthi Srinivas Bayyavarapu { 13537afa535eSMukunda, Vijendar int status; 13541927da93SMaruthi Srinivas Bayyavarapu struct audio_drv_data *adata = dev_get_drvdata(dev); 13551927da93SMaruthi Srinivas Bayyavarapu 13567afa535eSMukunda, Vijendar status = acp_init(adata->acp_mmio, adata->asic_type); 13577afa535eSMukunda, Vijendar if (status) { 13587afa535eSMukunda, Vijendar dev_err(dev, "ACP Init failed status:%d\n", status); 13597afa535eSMukunda, Vijendar return status; 13607afa535eSMukunda, Vijendar } 13611927da93SMaruthi Srinivas Bayyavarapu acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); 13621927da93SMaruthi Srinivas Bayyavarapu return 0; 13631927da93SMaruthi Srinivas Bayyavarapu } 13641927da93SMaruthi Srinivas Bayyavarapu 13651927da93SMaruthi Srinivas Bayyavarapu static const struct dev_pm_ops acp_pm_ops = { 13661927da93SMaruthi Srinivas Bayyavarapu .resume = acp_pcm_resume, 13671927da93SMaruthi Srinivas Bayyavarapu .runtime_suspend = acp_pcm_runtime_suspend, 13681927da93SMaruthi Srinivas Bayyavarapu .runtime_resume = acp_pcm_runtime_resume, 13691927da93SMaruthi Srinivas Bayyavarapu }; 13701927da93SMaruthi Srinivas Bayyavarapu 13717c31335aSMaruthi Srinivas Bayyavarapu static struct platform_driver acp_dma_driver = { 13727c31335aSMaruthi Srinivas Bayyavarapu .probe = acp_audio_probe, 13737c31335aSMaruthi Srinivas Bayyavarapu .remove = acp_audio_remove, 13747c31335aSMaruthi Srinivas Bayyavarapu .driver = { 1375bdd2a858SAkshu Agrawal .name = DRV_NAME, 13761927da93SMaruthi Srinivas Bayyavarapu .pm = &acp_pm_ops, 13777c31335aSMaruthi Srinivas Bayyavarapu }, 13787c31335aSMaruthi Srinivas Bayyavarapu }; 13797c31335aSMaruthi Srinivas Bayyavarapu 13807c31335aSMaruthi Srinivas Bayyavarapu module_platform_driver(acp_dma_driver); 13817c31335aSMaruthi Srinivas Bayyavarapu 1382607b39efSVijendar Mukunda MODULE_AUTHOR("Vijendar.Mukunda@amd.com"); 13837c31335aSMaruthi Srinivas Bayyavarapu MODULE_AUTHOR("Maruthi.Bayyavarapu@amd.com"); 13847c31335aSMaruthi Srinivas Bayyavarapu MODULE_DESCRIPTION("AMD ACP PCM Driver"); 13857c31335aSMaruthi Srinivas Bayyavarapu MODULE_LICENSE("GPL v2"); 1386bdd2a858SAkshu Agrawal MODULE_ALIAS("platform:"DRV_NAME); 1387