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 */ 403bbdb7012SAkshu 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 432bbdb7012SAkshu Agrawal /* enable for ACP to SRAM DMA channel */ 433bbdb7012SAkshu Agrawal if (is_circular == true) 4347c31335aSMaruthi Srinivas Bayyavarapu dma_ctrl |= ACP_DMA_CNTL_0__Circular_DMA_En_MASK; 435bbdb7012SAkshu Agrawal else 436bbdb7012SAkshu 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 { 680bbdb7012SAkshu 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; 712bbdb7012SAkshu Agrawal if (acp_reg_read(acp_mmio, mmACP_DMA_CUR_DSCR_14) == 713bbdb7012SAkshu Agrawal CAPTURE_START_DMA_DESCR_CH15) 714bbdb7012SAkshu Agrawal dscr_idx = CAPTURE_END_DMA_DESCR_CH14; 715bbdb7012SAkshu Agrawal else 716bbdb7012SAkshu Agrawal dscr_idx = CAPTURE_START_DMA_DESCR_CH14; 717bbdb7012SAkshu Agrawal config_acp_dma_channel(acp_mmio, ACP_TO_SYSRAM_CH_NUM, dscr_idx, 718bbdb7012SAkshu Agrawal 1, 0); 719bbdb7012SAkshu Agrawal acp_dma_start(acp_mmio, ACP_TO_SYSRAM_CH_NUM, false); 720bbdb7012SAkshu 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; 728bbdb7012SAkshu Agrawal if (acp_reg_read(acp_mmio, mmACP_DMA_CUR_DSCR_10) == 729bbdb7012SAkshu Agrawal CAPTURE_START_DMA_DESCR_CH11) 730bbdb7012SAkshu Agrawal dscr_idx = CAPTURE_END_DMA_DESCR_CH10; 731bbdb7012SAkshu Agrawal else 732bbdb7012SAkshu Agrawal dscr_idx = CAPTURE_START_DMA_DESCR_CH10; 733bbdb7012SAkshu Agrawal config_acp_dma_channel(acp_mmio, 734bbdb7012SAkshu Agrawal ACP_TO_SYSRAM_BT_INSTANCE_CH_NUM, 735bbdb7012SAkshu Agrawal dscr_idx, 1, 0); 736bbdb7012SAkshu Agrawal acp_dma_start(acp_mmio, ACP_TO_SYSRAM_BT_INSTANCE_CH_NUM, 737bbdb7012SAkshu Agrawal false); 738bbdb7012SAkshu 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) { 849*8dcb0c90SAkshu Agrawal if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 850*8dcb0c90SAkshu Agrawal rtd->i2s_instance = pinfo->play_i2s_instance; 851*8dcb0c90SAkshu Agrawal } else { 852*8dcb0c90SAkshu Agrawal rtd->i2s_instance = pinfo->cap_i2s_instance; 8532718c89aSAkshu Agrawal rtd->capture_channel = pinfo->capture_channel; 8542718c89aSAkshu Agrawal } 855*8dcb0c90SAkshu Agrawal } 856a37d48e3SVijendar Mukunda if (adata->asic_type == CHIP_STONEY) { 85713838c11SMukunda, Vijendar val = acp_reg_read(adata->acp_mmio, 85813838c11SMukunda, Vijendar mmACP_I2S_16BIT_RESOLUTION_EN); 859ccfbb4f5SMukunda, Vijendar if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 860ccfbb4f5SMukunda, Vijendar switch (rtd->i2s_instance) { 861ccfbb4f5SMukunda, Vijendar case I2S_BT_INSTANCE: 862ccfbb4f5SMukunda, Vijendar val |= ACP_I2S_BT_16BIT_RESOLUTION_EN; 863ccfbb4f5SMukunda, Vijendar break; 864ccfbb4f5SMukunda, Vijendar case I2S_SP_INSTANCE: 865ccfbb4f5SMukunda, Vijendar default: 866a37d48e3SVijendar Mukunda val |= ACP_I2S_SP_16BIT_RESOLUTION_EN; 867ccfbb4f5SMukunda, Vijendar } 868ccfbb4f5SMukunda, Vijendar } else { 869ccfbb4f5SMukunda, Vijendar switch (rtd->i2s_instance) { 870ccfbb4f5SMukunda, Vijendar case I2S_BT_INSTANCE: 871ccfbb4f5SMukunda, Vijendar val |= ACP_I2S_BT_16BIT_RESOLUTION_EN; 872ccfbb4f5SMukunda, Vijendar break; 873ccfbb4f5SMukunda, Vijendar case I2S_SP_INSTANCE: 874ccfbb4f5SMukunda, Vijendar default: 875a37d48e3SVijendar Mukunda val |= ACP_I2S_MIC_16BIT_RESOLUTION_EN; 876ccfbb4f5SMukunda, Vijendar } 877ccfbb4f5SMukunda, Vijendar } 87813838c11SMukunda, Vijendar acp_reg_write(val, adata->acp_mmio, 87913838c11SMukunda, Vijendar mmACP_I2S_16BIT_RESOLUTION_EN); 880a37d48e3SVijendar Mukunda } 8818769bb55SVijendar Mukunda 8828769bb55SVijendar Mukunda if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 883ccfbb4f5SMukunda, Vijendar switch (rtd->i2s_instance) { 884ccfbb4f5SMukunda, Vijendar case I2S_BT_INSTANCE: 885ccfbb4f5SMukunda, Vijendar rtd->pte_offset = ACP_ST_BT_PLAYBACK_PTE_OFFSET; 886ccfbb4f5SMukunda, Vijendar rtd->ch1 = SYSRAM_TO_ACP_BT_INSTANCE_CH_NUM; 887ccfbb4f5SMukunda, Vijendar rtd->ch2 = ACP_TO_I2S_DMA_BT_INSTANCE_CH_NUM; 888ccfbb4f5SMukunda, Vijendar rtd->sram_bank = ACP_SRAM_BANK_3_ADDRESS; 889ccfbb4f5SMukunda, Vijendar rtd->destination = TO_BLUETOOTH; 890ccfbb4f5SMukunda, Vijendar rtd->dma_dscr_idx_1 = PLAYBACK_START_DMA_DESCR_CH8; 891ccfbb4f5SMukunda, Vijendar rtd->dma_dscr_idx_2 = PLAYBACK_START_DMA_DESCR_CH9; 892ccfbb4f5SMukunda, Vijendar rtd->byte_cnt_high_reg_offset = 893ccfbb4f5SMukunda, Vijendar mmACP_I2S_BT_TRANSMIT_BYTE_CNT_HIGH; 894ccfbb4f5SMukunda, Vijendar rtd->byte_cnt_low_reg_offset = 895ccfbb4f5SMukunda, Vijendar mmACP_I2S_BT_TRANSMIT_BYTE_CNT_LOW; 896ccfbb4f5SMukunda, Vijendar adata->play_i2sbt_stream = substream; 897ccfbb4f5SMukunda, Vijendar break; 898ccfbb4f5SMukunda, Vijendar case I2S_SP_INSTANCE: 899ccfbb4f5SMukunda, Vijendar default: 900e188c525SMukunda, Vijendar switch (adata->asic_type) { 901e188c525SMukunda, Vijendar case CHIP_STONEY: 902e188c525SMukunda, Vijendar rtd->pte_offset = ACP_ST_PLAYBACK_PTE_OFFSET; 903e188c525SMukunda, Vijendar break; 904e188c525SMukunda, Vijendar default: 905e188c525SMukunda, Vijendar rtd->pte_offset = ACP_PLAYBACK_PTE_OFFSET; 906e188c525SMukunda, Vijendar } 9078769bb55SVijendar Mukunda rtd->ch1 = SYSRAM_TO_ACP_CH_NUM; 9088769bb55SVijendar Mukunda rtd->ch2 = ACP_TO_I2S_DMA_CH_NUM; 90918e8a40dSMukunda, Vijendar rtd->sram_bank = ACP_SRAM_BANK_1_ADDRESS; 9108769bb55SVijendar Mukunda rtd->destination = TO_ACP_I2S_1; 9118769bb55SVijendar Mukunda rtd->dma_dscr_idx_1 = PLAYBACK_START_DMA_DESCR_CH12; 9128769bb55SVijendar Mukunda rtd->dma_dscr_idx_2 = PLAYBACK_START_DMA_DESCR_CH13; 9137f004847SVijendar Mukunda rtd->byte_cnt_high_reg_offset = 9147f004847SVijendar Mukunda mmACP_I2S_TRANSMIT_BYTE_CNT_HIGH; 915ccfbb4f5SMukunda, Vijendar rtd->byte_cnt_low_reg_offset = 916ccfbb4f5SMukunda, Vijendar mmACP_I2S_TRANSMIT_BYTE_CNT_LOW; 917ccfbb4f5SMukunda, Vijendar adata->play_i2ssp_stream = substream; 918ccfbb4f5SMukunda, Vijendar } 9198769bb55SVijendar Mukunda } else { 920ccfbb4f5SMukunda, Vijendar switch (rtd->i2s_instance) { 921ccfbb4f5SMukunda, Vijendar case I2S_BT_INSTANCE: 922ccfbb4f5SMukunda, Vijendar rtd->pte_offset = ACP_ST_BT_CAPTURE_PTE_OFFSET; 92355af49acSDaniel Kurtz rtd->ch1 = I2S_TO_ACP_DMA_BT_INSTANCE_CH_NUM; 92455af49acSDaniel Kurtz rtd->ch2 = ACP_TO_SYSRAM_BT_INSTANCE_CH_NUM; 925ccfbb4f5SMukunda, Vijendar rtd->sram_bank = ACP_SRAM_BANK_4_ADDRESS; 926ccfbb4f5SMukunda, Vijendar rtd->destination = FROM_BLUETOOTH; 927ccfbb4f5SMukunda, Vijendar rtd->dma_dscr_idx_1 = CAPTURE_START_DMA_DESCR_CH10; 928ccfbb4f5SMukunda, Vijendar rtd->dma_dscr_idx_2 = CAPTURE_START_DMA_DESCR_CH11; 929c21c834aSAkshu Agrawal rtd->byte_cnt_high_reg_offset = 930c21c834aSAkshu Agrawal mmACP_I2S_BT_RECEIVE_BYTE_CNT_HIGH; 931c21c834aSAkshu Agrawal rtd->byte_cnt_low_reg_offset = 932c21c834aSAkshu Agrawal mmACP_I2S_BT_RECEIVE_BYTE_CNT_LOW; 933662fb3efSMukunda, Vijendar rtd->dma_curr_dscr = mmACP_DMA_CUR_DSCR_11; 934ccfbb4f5SMukunda, Vijendar adata->capture_i2sbt_stream = substream; 935ccfbb4f5SMukunda, Vijendar break; 936ccfbb4f5SMukunda, Vijendar case I2S_SP_INSTANCE: 937ccfbb4f5SMukunda, Vijendar default: 938ccfbb4f5SMukunda, Vijendar rtd->pte_offset = ACP_CAPTURE_PTE_OFFSET; 93955af49acSDaniel Kurtz rtd->ch1 = I2S_TO_ACP_DMA_CH_NUM; 94055af49acSDaniel Kurtz rtd->ch2 = ACP_TO_SYSRAM_CH_NUM; 941e188c525SMukunda, Vijendar switch (adata->asic_type) { 942e188c525SMukunda, Vijendar case CHIP_STONEY: 943e188c525SMukunda, Vijendar rtd->pte_offset = ACP_ST_CAPTURE_PTE_OFFSET; 94418e8a40dSMukunda, Vijendar rtd->sram_bank = ACP_SRAM_BANK_2_ADDRESS; 945e188c525SMukunda, Vijendar break; 946e188c525SMukunda, Vijendar default: 947e188c525SMukunda, Vijendar rtd->pte_offset = ACP_CAPTURE_PTE_OFFSET; 94818e8a40dSMukunda, Vijendar rtd->sram_bank = ACP_SRAM_BANK_5_ADDRESS; 949e188c525SMukunda, Vijendar } 9508769bb55SVijendar Mukunda rtd->destination = FROM_ACP_I2S_1; 9518769bb55SVijendar Mukunda rtd->dma_dscr_idx_1 = CAPTURE_START_DMA_DESCR_CH14; 9528769bb55SVijendar Mukunda rtd->dma_dscr_idx_2 = CAPTURE_START_DMA_DESCR_CH15; 953c21c834aSAkshu Agrawal rtd->byte_cnt_high_reg_offset = 954c21c834aSAkshu Agrawal mmACP_I2S_RECEIVED_BYTE_CNT_HIGH; 955c21c834aSAkshu Agrawal rtd->byte_cnt_low_reg_offset = 956c21c834aSAkshu Agrawal mmACP_I2S_RECEIVED_BYTE_CNT_LOW; 957662fb3efSMukunda, Vijendar rtd->dma_curr_dscr = mmACP_DMA_CUR_DSCR_15; 958ccfbb4f5SMukunda, Vijendar adata->capture_i2ssp_stream = substream; 959ccfbb4f5SMukunda, Vijendar } 9608769bb55SVijendar Mukunda } 9618769bb55SVijendar Mukunda 9627c31335aSMaruthi Srinivas Bayyavarapu size = params_buffer_bytes(params); 9637c31335aSMaruthi Srinivas Bayyavarapu status = snd_pcm_lib_malloc_pages(substream, size); 9647c31335aSMaruthi Srinivas Bayyavarapu if (status < 0) 9657c31335aSMaruthi Srinivas Bayyavarapu return status; 9667c31335aSMaruthi Srinivas Bayyavarapu 9677c31335aSMaruthi Srinivas Bayyavarapu memset(substream->runtime->dma_area, 0, params_buffer_bytes(params)); 9687c31335aSMaruthi Srinivas Bayyavarapu pg = virt_to_page(substream->dma_buffer.area); 9697c31335aSMaruthi Srinivas Bayyavarapu 97013838c11SMukunda, Vijendar if (pg) { 971c36d9b3fSMaruthi Srinivas Bayyavarapu acp_set_sram_bank_state(rtd->acp_mmio, 0, true); 9727c31335aSMaruthi Srinivas Bayyavarapu /* Save for runtime private data */ 9737c31335aSMaruthi Srinivas Bayyavarapu rtd->pg = pg; 9747c31335aSMaruthi Srinivas Bayyavarapu rtd->order = get_order(size); 9757c31335aSMaruthi Srinivas Bayyavarapu 9767c31335aSMaruthi Srinivas Bayyavarapu /* Fill the page table entries in ACP SRAM */ 9777c31335aSMaruthi Srinivas Bayyavarapu rtd->pg = pg; 9787c31335aSMaruthi Srinivas Bayyavarapu rtd->size = size; 9797c31335aSMaruthi Srinivas Bayyavarapu rtd->num_of_pages = PAGE_ALIGN(size) >> PAGE_SHIFT; 9807c31335aSMaruthi Srinivas Bayyavarapu rtd->direction = substream->stream; 9817c31335aSMaruthi Srinivas Bayyavarapu 982aac89748SVijendar Mukunda config_acp_dma(rtd->acp_mmio, rtd, adata->asic_type); 9837c31335aSMaruthi Srinivas Bayyavarapu status = 0; 9847c31335aSMaruthi Srinivas Bayyavarapu } else { 9857c31335aSMaruthi Srinivas Bayyavarapu status = -ENOMEM; 9867c31335aSMaruthi Srinivas Bayyavarapu } 9877c31335aSMaruthi Srinivas Bayyavarapu return status; 9887c31335aSMaruthi Srinivas Bayyavarapu } 9897c31335aSMaruthi Srinivas Bayyavarapu 9907c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_hw_free(struct snd_pcm_substream *substream) 9917c31335aSMaruthi Srinivas Bayyavarapu { 9927c31335aSMaruthi Srinivas Bayyavarapu return snd_pcm_lib_free_pages(substream); 9937c31335aSMaruthi Srinivas Bayyavarapu } 9947c31335aSMaruthi Srinivas Bayyavarapu 9957f004847SVijendar Mukunda static u64 acp_get_byte_count(struct audio_substream_data *rtd) 99661add814SVijendar Mukunda { 9977f004847SVijendar Mukunda union acp_dma_count byte_count; 99861add814SVijendar Mukunda 9997f004847SVijendar Mukunda byte_count.bcount.high = acp_reg_read(rtd->acp_mmio, 10007f004847SVijendar Mukunda rtd->byte_cnt_high_reg_offset); 10017f004847SVijendar Mukunda byte_count.bcount.low = acp_reg_read(rtd->acp_mmio, 10027f004847SVijendar Mukunda rtd->byte_cnt_low_reg_offset); 10037f004847SVijendar Mukunda return byte_count.bytescount; 100461add814SVijendar Mukunda } 100561add814SVijendar Mukunda 10067c31335aSMaruthi Srinivas Bayyavarapu static snd_pcm_uframes_t acp_dma_pointer(struct snd_pcm_substream *substream) 10077c31335aSMaruthi Srinivas Bayyavarapu { 100861add814SVijendar Mukunda u32 buffersize; 10097c31335aSMaruthi Srinivas Bayyavarapu u32 pos = 0; 101061add814SVijendar Mukunda u64 bytescount = 0; 1011662fb3efSMukunda, Vijendar u16 dscr; 1012c21c834aSAkshu Agrawal u32 period_bytes, delay; 10137c31335aSMaruthi Srinivas Bayyavarapu 10147c31335aSMaruthi Srinivas Bayyavarapu struct snd_pcm_runtime *runtime = substream->runtime; 10157c31335aSMaruthi Srinivas Bayyavarapu struct audio_substream_data *rtd = runtime->private_data; 10167c31335aSMaruthi Srinivas Bayyavarapu 10177afa535eSMukunda, Vijendar if (!rtd) 10187afa535eSMukunda, Vijendar return -EINVAL; 10197afa535eSMukunda, Vijendar 1020662fb3efSMukunda, Vijendar if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { 1021662fb3efSMukunda, Vijendar period_bytes = frames_to_bytes(runtime, runtime->period_size); 1022662fb3efSMukunda, Vijendar dscr = acp_reg_read(rtd->acp_mmio, rtd->dma_curr_dscr); 1023662fb3efSMukunda, Vijendar if (dscr == rtd->dma_dscr_idx_1) 1024662fb3efSMukunda, Vijendar pos = period_bytes; 1025662fb3efSMukunda, Vijendar else 1026662fb3efSMukunda, Vijendar pos = 0; 1027c21c834aSAkshu Agrawal bytescount = acp_get_byte_count(rtd); 1028c21c834aSAkshu Agrawal if (bytescount > rtd->bytescount) 1029c21c834aSAkshu Agrawal bytescount -= rtd->bytescount; 1030c21c834aSAkshu Agrawal delay = do_div(bytescount, period_bytes); 1031c21c834aSAkshu Agrawal runtime->delay = bytes_to_frames(runtime, delay); 1032662fb3efSMukunda, Vijendar } else { 103361add814SVijendar Mukunda buffersize = frames_to_bytes(runtime, runtime->buffer_size); 10347f004847SVijendar Mukunda bytescount = acp_get_byte_count(rtd); 1035662fb3efSMukunda, Vijendar if (bytescount > rtd->bytescount) 10369af8937eSVijendar Mukunda bytescount -= rtd->bytescount; 10377db08b2cSGuenter Roeck pos = do_div(bytescount, buffersize); 1038662fb3efSMukunda, Vijendar } 10397c31335aSMaruthi Srinivas Bayyavarapu return bytes_to_frames(runtime, pos); 10407c31335aSMaruthi Srinivas Bayyavarapu } 10417c31335aSMaruthi Srinivas Bayyavarapu 10427c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_mmap(struct snd_pcm_substream *substream, 10437c31335aSMaruthi Srinivas Bayyavarapu struct vm_area_struct *vma) 10447c31335aSMaruthi Srinivas Bayyavarapu { 10457c31335aSMaruthi Srinivas Bayyavarapu return snd_pcm_lib_default_mmap(substream, vma); 10467c31335aSMaruthi Srinivas Bayyavarapu } 10477c31335aSMaruthi Srinivas Bayyavarapu 10487c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_prepare(struct snd_pcm_substream *substream) 10497c31335aSMaruthi Srinivas Bayyavarapu { 10507c31335aSMaruthi Srinivas Bayyavarapu struct snd_pcm_runtime *runtime = substream->runtime; 10517c31335aSMaruthi Srinivas Bayyavarapu struct audio_substream_data *rtd = runtime->private_data; 1052fa9d2f17SAgrawal, Akshu u16 ch_acp_sysmem, ch_acp_i2s; 10537c31335aSMaruthi Srinivas Bayyavarapu 10547afa535eSMukunda, Vijendar if (!rtd) 10557afa535eSMukunda, Vijendar return -EINVAL; 10568769bb55SVijendar Mukunda 1057fa9d2f17SAgrawal, Akshu if (rtd->direction == SNDRV_PCM_STREAM_PLAYBACK) { 1058fa9d2f17SAgrawal, Akshu ch_acp_sysmem = rtd->ch1; 1059fa9d2f17SAgrawal, Akshu ch_acp_i2s = rtd->ch2; 1060fa9d2f17SAgrawal, Akshu } else { 1061fa9d2f17SAgrawal, Akshu ch_acp_i2s = rtd->ch1; 1062fa9d2f17SAgrawal, Akshu ch_acp_sysmem = rtd->ch2; 1063fa9d2f17SAgrawal, Akshu } 10648769bb55SVijendar Mukunda config_acp_dma_channel(rtd->acp_mmio, 1065fa9d2f17SAgrawal, Akshu ch_acp_sysmem, 10668769bb55SVijendar Mukunda rtd->dma_dscr_idx_1, 10677c31335aSMaruthi Srinivas Bayyavarapu NUM_DSCRS_PER_CHANNEL, 0); 10688769bb55SVijendar Mukunda config_acp_dma_channel(rtd->acp_mmio, 1069fa9d2f17SAgrawal, Akshu ch_acp_i2s, 10708769bb55SVijendar Mukunda rtd->dma_dscr_idx_2, 10717c31335aSMaruthi Srinivas Bayyavarapu NUM_DSCRS_PER_CHANNEL, 0); 10727c31335aSMaruthi Srinivas Bayyavarapu return 0; 10737c31335aSMaruthi Srinivas Bayyavarapu } 10747c31335aSMaruthi Srinivas Bayyavarapu 10757c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_trigger(struct snd_pcm_substream *substream, int cmd) 10767c31335aSMaruthi Srinivas Bayyavarapu { 10777c31335aSMaruthi Srinivas Bayyavarapu int ret; 10787c31335aSMaruthi Srinivas Bayyavarapu 10797c31335aSMaruthi Srinivas Bayyavarapu struct snd_pcm_runtime *runtime = substream->runtime; 10807c31335aSMaruthi Srinivas Bayyavarapu struct audio_substream_data *rtd = runtime->private_data; 10817c31335aSMaruthi Srinivas Bayyavarapu 10827c31335aSMaruthi Srinivas Bayyavarapu if (!rtd) 10837c31335aSMaruthi Srinivas Bayyavarapu return -EINVAL; 10847c31335aSMaruthi Srinivas Bayyavarapu switch (cmd) { 10857c31335aSMaruthi Srinivas Bayyavarapu case SNDRV_PCM_TRIGGER_START: 10867c31335aSMaruthi Srinivas Bayyavarapu case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 10877c31335aSMaruthi Srinivas Bayyavarapu case SNDRV_PCM_TRIGGER_RESUME: 10881a337a1eSDaniel Kurtz rtd->bytescount = acp_get_byte_count(rtd); 1089df61f9f7SDaniel Kurtz if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { 10902718c89aSAkshu Agrawal if (rtd->capture_channel == CAP_CHANNEL0) { 10912718c89aSAkshu Agrawal acp_dma_cap_channel_disable(rtd->acp_mmio, 10922718c89aSAkshu Agrawal CAP_CHANNEL1); 10932718c89aSAkshu Agrawal acp_dma_cap_channel_enable(rtd->acp_mmio, 10942718c89aSAkshu Agrawal CAP_CHANNEL0); 10952718c89aSAkshu Agrawal } 10962718c89aSAkshu Agrawal if (rtd->capture_channel == CAP_CHANNEL1) { 10972718c89aSAkshu Agrawal acp_dma_cap_channel_disable(rtd->acp_mmio, 10982718c89aSAkshu Agrawal CAP_CHANNEL0); 10992718c89aSAkshu Agrawal acp_dma_cap_channel_enable(rtd->acp_mmio, 11002718c89aSAkshu Agrawal CAP_CHANNEL1); 11012718c89aSAkshu Agrawal } 1102bbdb7012SAkshu Agrawal acp_dma_start(rtd->acp_mmio, rtd->ch1, true); 1103bbdb7012SAkshu Agrawal } else { 1104bbdb7012SAkshu Agrawal acp_dma_start(rtd->acp_mmio, rtd->ch1, true); 1105bbdb7012SAkshu Agrawal acp_dma_start(rtd->acp_mmio, rtd->ch2, true); 11067c31335aSMaruthi Srinivas Bayyavarapu } 11077c31335aSMaruthi Srinivas Bayyavarapu ret = 0; 11087c31335aSMaruthi Srinivas Bayyavarapu break; 11097c31335aSMaruthi Srinivas Bayyavarapu case SNDRV_PCM_TRIGGER_STOP: 11107c31335aSMaruthi Srinivas Bayyavarapu case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 11117c31335aSMaruthi Srinivas Bayyavarapu case SNDRV_PCM_TRIGGER_SUSPEND: 11128769bb55SVijendar Mukunda acp_dma_stop(rtd->acp_mmio, rtd->ch2); 11138769bb55SVijendar Mukunda ret = acp_dma_stop(rtd->acp_mmio, rtd->ch1); 11147c31335aSMaruthi Srinivas Bayyavarapu break; 11157c31335aSMaruthi Srinivas Bayyavarapu default: 11167c31335aSMaruthi Srinivas Bayyavarapu ret = -EINVAL; 11177c31335aSMaruthi Srinivas Bayyavarapu } 11187c31335aSMaruthi Srinivas Bayyavarapu return ret; 11197c31335aSMaruthi Srinivas Bayyavarapu } 11207c31335aSMaruthi Srinivas Bayyavarapu 11217c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_new(struct snd_soc_pcm_runtime *rtd) 11227c31335aSMaruthi Srinivas Bayyavarapu { 11239c7d6fabSVijendar Mukunda int ret; 112413838c11SMukunda, Vijendar struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, 112513838c11SMukunda, Vijendar DRV_NAME); 1126a1042a42SKuninori Morimoto struct audio_drv_data *adata = dev_get_drvdata(component->dev); 11279c7d6fabSVijendar Mukunda 11289c7d6fabSVijendar Mukunda switch (adata->asic_type) { 11299c7d6fabSVijendar Mukunda case CHIP_STONEY: 11309c7d6fabSVijendar Mukunda ret = snd_pcm_lib_preallocate_pages_for_all(rtd->pcm, 11319c7d6fabSVijendar Mukunda SNDRV_DMA_TYPE_DEV, 11329c7d6fabSVijendar Mukunda NULL, ST_MIN_BUFFER, 11339c7d6fabSVijendar Mukunda ST_MAX_BUFFER); 11349c7d6fabSVijendar Mukunda break; 11359c7d6fabSVijendar Mukunda default: 11369c7d6fabSVijendar Mukunda ret = snd_pcm_lib_preallocate_pages_for_all(rtd->pcm, 11377c31335aSMaruthi Srinivas Bayyavarapu SNDRV_DMA_TYPE_DEV, 11387c31335aSMaruthi Srinivas Bayyavarapu NULL, MIN_BUFFER, 11397c31335aSMaruthi Srinivas Bayyavarapu MAX_BUFFER); 11409c7d6fabSVijendar Mukunda break; 11419c7d6fabSVijendar Mukunda } 11429c7d6fabSVijendar Mukunda if (ret < 0) 1143a1042a42SKuninori Morimoto dev_err(component->dev, 11449e6a469eSColin Ian King "buffer preallocation failure error:%d\n", ret); 11459c7d6fabSVijendar Mukunda return ret; 11467c31335aSMaruthi Srinivas Bayyavarapu } 11477c31335aSMaruthi Srinivas Bayyavarapu 11487c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_close(struct snd_pcm_substream *substream) 11497c31335aSMaruthi Srinivas Bayyavarapu { 1150c36d9b3fSMaruthi Srinivas Bayyavarapu u16 bank; 11517c31335aSMaruthi Srinivas Bayyavarapu struct snd_pcm_runtime *runtime = substream->runtime; 11527c31335aSMaruthi Srinivas Bayyavarapu struct audio_substream_data *rtd = runtime->private_data; 11537c31335aSMaruthi Srinivas Bayyavarapu struct snd_soc_pcm_runtime *prtd = substream->private_data; 115413838c11SMukunda, Vijendar struct snd_soc_component *component = snd_soc_rtdcom_lookup(prtd, 115513838c11SMukunda, Vijendar DRV_NAME); 1156a1042a42SKuninori Morimoto struct audio_drv_data *adata = dev_get_drvdata(component->dev); 11577c31335aSMaruthi Srinivas Bayyavarapu 1158c36d9b3fSMaruthi Srinivas Bayyavarapu if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 1159ccfbb4f5SMukunda, Vijendar switch (rtd->i2s_instance) { 1160ccfbb4f5SMukunda, Vijendar case I2S_BT_INSTANCE: 1161ccfbb4f5SMukunda, Vijendar adata->play_i2sbt_stream = NULL; 1162ccfbb4f5SMukunda, Vijendar break; 1163ccfbb4f5SMukunda, Vijendar case I2S_SP_INSTANCE: 1164ccfbb4f5SMukunda, Vijendar default: 1165e21358c4SMukunda, Vijendar adata->play_i2ssp_stream = NULL; 116613838c11SMukunda, Vijendar /* 116713838c11SMukunda, Vijendar * For Stoney, Memory gating is disabled,i.e SRAM Banks 1168ccfbb4f5SMukunda, Vijendar * won't be turned off. The default state for SRAM banks 1169ccfbb4f5SMukunda, Vijendar * is ON.Setting SRAM bank state code skipped for STONEY 1170ccfbb4f5SMukunda, Vijendar * platform. Added condition checks for Carrizo platform 1171ccfbb4f5SMukunda, Vijendar * only. 1172607b39efSVijendar Mukunda */ 1173607b39efSVijendar Mukunda if (adata->asic_type != CHIP_STONEY) { 1174c36d9b3fSMaruthi Srinivas Bayyavarapu for (bank = 1; bank <= 4; bank++) 1175ccfbb4f5SMukunda, Vijendar acp_set_sram_bank_state(adata->acp_mmio, 1176ccfbb4f5SMukunda, Vijendar bank, false); 1177ccfbb4f5SMukunda, Vijendar } 1178607b39efSVijendar Mukunda } 1179c36d9b3fSMaruthi Srinivas Bayyavarapu } else { 1180ccfbb4f5SMukunda, Vijendar switch (rtd->i2s_instance) { 1181ccfbb4f5SMukunda, Vijendar case I2S_BT_INSTANCE: 1182ccfbb4f5SMukunda, Vijendar adata->capture_i2sbt_stream = NULL; 1183ccfbb4f5SMukunda, Vijendar break; 1184ccfbb4f5SMukunda, Vijendar case I2S_SP_INSTANCE: 1185ccfbb4f5SMukunda, Vijendar default: 1186e21358c4SMukunda, Vijendar adata->capture_i2ssp_stream = NULL; 1187607b39efSVijendar Mukunda if (adata->asic_type != CHIP_STONEY) { 1188c36d9b3fSMaruthi Srinivas Bayyavarapu for (bank = 5; bank <= 8; bank++) 1189ccfbb4f5SMukunda, Vijendar acp_set_sram_bank_state(adata->acp_mmio, 1190ccfbb4f5SMukunda, Vijendar bank, false); 1191ccfbb4f5SMukunda, Vijendar } 1192c36d9b3fSMaruthi Srinivas Bayyavarapu } 1193607b39efSVijendar Mukunda } 11947c31335aSMaruthi Srinivas Bayyavarapu 119513838c11SMukunda, Vijendar /* 119613838c11SMukunda, Vijendar * Disable ACP irq, when the current stream is being closed and 11977c31335aSMaruthi Srinivas Bayyavarapu * another stream is also not active. 11987c31335aSMaruthi Srinivas Bayyavarapu */ 1199ccfbb4f5SMukunda, Vijendar if (!adata->play_i2ssp_stream && !adata->capture_i2ssp_stream && 1200ccfbb4f5SMukunda, Vijendar !adata->play_i2sbt_stream && !adata->capture_i2sbt_stream) 12017c31335aSMaruthi Srinivas Bayyavarapu acp_reg_write(0, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); 1202cac6f597SMukunda, Vijendar kfree(rtd); 12037c31335aSMaruthi Srinivas Bayyavarapu return 0; 12047c31335aSMaruthi Srinivas Bayyavarapu } 12057c31335aSMaruthi Srinivas Bayyavarapu 1206115c7254SJulia Lawall static const struct snd_pcm_ops acp_dma_ops = { 12077c31335aSMaruthi Srinivas Bayyavarapu .open = acp_dma_open, 12087c31335aSMaruthi Srinivas Bayyavarapu .close = acp_dma_close, 12097c31335aSMaruthi Srinivas Bayyavarapu .ioctl = snd_pcm_lib_ioctl, 12107c31335aSMaruthi Srinivas Bayyavarapu .hw_params = acp_dma_hw_params, 12117c31335aSMaruthi Srinivas Bayyavarapu .hw_free = acp_dma_hw_free, 12127c31335aSMaruthi Srinivas Bayyavarapu .trigger = acp_dma_trigger, 12137c31335aSMaruthi Srinivas Bayyavarapu .pointer = acp_dma_pointer, 12147c31335aSMaruthi Srinivas Bayyavarapu .mmap = acp_dma_mmap, 12157c31335aSMaruthi Srinivas Bayyavarapu .prepare = acp_dma_prepare, 12167c31335aSMaruthi Srinivas Bayyavarapu }; 12177c31335aSMaruthi Srinivas Bayyavarapu 121813838c11SMukunda, Vijendar static const struct snd_soc_component_driver acp_asoc_platform = { 1219a1042a42SKuninori Morimoto .name = DRV_NAME, 12207c31335aSMaruthi Srinivas Bayyavarapu .ops = &acp_dma_ops, 12217c31335aSMaruthi Srinivas Bayyavarapu .pcm_new = acp_dma_new, 12227c31335aSMaruthi Srinivas Bayyavarapu }; 12237c31335aSMaruthi Srinivas Bayyavarapu 12247c31335aSMaruthi Srinivas Bayyavarapu static int acp_audio_probe(struct platform_device *pdev) 12257c31335aSMaruthi Srinivas Bayyavarapu { 12267c31335aSMaruthi Srinivas Bayyavarapu int status; 12277c31335aSMaruthi Srinivas Bayyavarapu struct audio_drv_data *audio_drv_data; 12287c31335aSMaruthi Srinivas Bayyavarapu struct resource *res; 1229a1b16aaaSVijendar Mukunda const u32 *pdata = pdev->dev.platform_data; 12307c31335aSMaruthi Srinivas Bayyavarapu 1231fdaa4511SGuenter Roeck if (!pdata) { 1232fdaa4511SGuenter Roeck dev_err(&pdev->dev, "Missing platform data\n"); 1233fdaa4511SGuenter Roeck return -ENODEV; 1234fdaa4511SGuenter Roeck } 1235fdaa4511SGuenter Roeck 12367c31335aSMaruthi Srinivas Bayyavarapu audio_drv_data = devm_kzalloc(&pdev->dev, sizeof(struct audio_drv_data), 12377c31335aSMaruthi Srinivas Bayyavarapu GFP_KERNEL); 123813838c11SMukunda, Vijendar if (!audio_drv_data) 12397c31335aSMaruthi Srinivas Bayyavarapu return -ENOMEM; 12407c31335aSMaruthi Srinivas Bayyavarapu 12417c31335aSMaruthi Srinivas Bayyavarapu res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 12427c31335aSMaruthi Srinivas Bayyavarapu audio_drv_data->acp_mmio = devm_ioremap_resource(&pdev->dev, res); 1243fdaa4511SGuenter Roeck if (IS_ERR(audio_drv_data->acp_mmio)) 1244fdaa4511SGuenter Roeck return PTR_ERR(audio_drv_data->acp_mmio); 12457c31335aSMaruthi Srinivas Bayyavarapu 124613838c11SMukunda, Vijendar /* 124713838c11SMukunda, Vijendar * The following members gets populated in device 'open' 12487c31335aSMaruthi Srinivas Bayyavarapu * function. Till then interrupts are disabled in 'acp_init' 12497c31335aSMaruthi Srinivas Bayyavarapu * and device doesn't generate any interrupts. 12507c31335aSMaruthi Srinivas Bayyavarapu */ 12517c31335aSMaruthi Srinivas Bayyavarapu 1252e21358c4SMukunda, Vijendar audio_drv_data->play_i2ssp_stream = NULL; 1253e21358c4SMukunda, Vijendar audio_drv_data->capture_i2ssp_stream = NULL; 1254ccfbb4f5SMukunda, Vijendar audio_drv_data->play_i2sbt_stream = NULL; 1255ccfbb4f5SMukunda, Vijendar audio_drv_data->capture_i2sbt_stream = NULL; 1256e21358c4SMukunda, Vijendar 1257a1b16aaaSVijendar Mukunda audio_drv_data->asic_type = *pdata; 12587c31335aSMaruthi Srinivas Bayyavarapu 12597c31335aSMaruthi Srinivas Bayyavarapu res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 12607c31335aSMaruthi Srinivas Bayyavarapu if (!res) { 12617c31335aSMaruthi Srinivas Bayyavarapu dev_err(&pdev->dev, "IORESOURCE_IRQ FAILED\n"); 12627c31335aSMaruthi Srinivas Bayyavarapu return -ENODEV; 12637c31335aSMaruthi Srinivas Bayyavarapu } 12647c31335aSMaruthi Srinivas Bayyavarapu 12657c31335aSMaruthi Srinivas Bayyavarapu status = devm_request_irq(&pdev->dev, res->start, dma_irq_handler, 12667c31335aSMaruthi Srinivas Bayyavarapu 0, "ACP_IRQ", &pdev->dev); 12677c31335aSMaruthi Srinivas Bayyavarapu if (status) { 12687c31335aSMaruthi Srinivas Bayyavarapu dev_err(&pdev->dev, "ACP IRQ request failed\n"); 12697c31335aSMaruthi Srinivas Bayyavarapu return status; 12707c31335aSMaruthi Srinivas Bayyavarapu } 12717c31335aSMaruthi Srinivas Bayyavarapu 12727c31335aSMaruthi Srinivas Bayyavarapu dev_set_drvdata(&pdev->dev, audio_drv_data); 12737c31335aSMaruthi Srinivas Bayyavarapu 12747c31335aSMaruthi Srinivas Bayyavarapu /* Initialize the ACP */ 12757afa535eSMukunda, Vijendar status = acp_init(audio_drv_data->acp_mmio, audio_drv_data->asic_type); 12767afa535eSMukunda, Vijendar if (status) { 12777afa535eSMukunda, Vijendar dev_err(&pdev->dev, "ACP Init failed status:%d\n", status); 12787afa535eSMukunda, Vijendar return status; 12797afa535eSMukunda, Vijendar } 12807c31335aSMaruthi Srinivas Bayyavarapu 1281a1042a42SKuninori Morimoto status = devm_snd_soc_register_component(&pdev->dev, 1282a1042a42SKuninori Morimoto &acp_asoc_platform, NULL, 0); 12837c31335aSMaruthi Srinivas Bayyavarapu if (status != 0) { 12847c31335aSMaruthi Srinivas Bayyavarapu dev_err(&pdev->dev, "Fail to register ALSA platform device\n"); 12857c31335aSMaruthi Srinivas Bayyavarapu return status; 12867c31335aSMaruthi Srinivas Bayyavarapu } 12877c31335aSMaruthi Srinivas Bayyavarapu 12881927da93SMaruthi Srinivas Bayyavarapu pm_runtime_set_autosuspend_delay(&pdev->dev, 10000); 12891927da93SMaruthi Srinivas Bayyavarapu pm_runtime_use_autosuspend(&pdev->dev); 12901927da93SMaruthi Srinivas Bayyavarapu pm_runtime_enable(&pdev->dev); 12911927da93SMaruthi Srinivas Bayyavarapu 12927c31335aSMaruthi Srinivas Bayyavarapu return status; 12937c31335aSMaruthi Srinivas Bayyavarapu } 12947c31335aSMaruthi Srinivas Bayyavarapu 12957c31335aSMaruthi Srinivas Bayyavarapu static int acp_audio_remove(struct platform_device *pdev) 12967c31335aSMaruthi Srinivas Bayyavarapu { 12977afa535eSMukunda, Vijendar int status; 12987c31335aSMaruthi Srinivas Bayyavarapu struct audio_drv_data *adata = dev_get_drvdata(&pdev->dev); 12997c31335aSMaruthi Srinivas Bayyavarapu 13007afa535eSMukunda, Vijendar status = acp_deinit(adata->acp_mmio); 13017afa535eSMukunda, Vijendar if (status) 13027afa535eSMukunda, Vijendar dev_err(&pdev->dev, "ACP Deinit failed status:%d\n", status); 13031927da93SMaruthi Srinivas Bayyavarapu pm_runtime_disable(&pdev->dev); 13047c31335aSMaruthi Srinivas Bayyavarapu 13057c31335aSMaruthi Srinivas Bayyavarapu return 0; 13067c31335aSMaruthi Srinivas Bayyavarapu } 13077c31335aSMaruthi Srinivas Bayyavarapu 13081927da93SMaruthi Srinivas Bayyavarapu static int acp_pcm_resume(struct device *dev) 13091927da93SMaruthi Srinivas Bayyavarapu { 1310c36d9b3fSMaruthi Srinivas Bayyavarapu u16 bank; 13117afa535eSMukunda, Vijendar int status; 1312ccfbb4f5SMukunda, Vijendar struct audio_substream_data *rtd; 13131927da93SMaruthi Srinivas Bayyavarapu struct audio_drv_data *adata = dev_get_drvdata(dev); 13141927da93SMaruthi Srinivas Bayyavarapu 13157afa535eSMukunda, Vijendar status = acp_init(adata->acp_mmio, adata->asic_type); 13167afa535eSMukunda, Vijendar if (status) { 13177afa535eSMukunda, Vijendar dev_err(dev, "ACP Init failed status:%d\n", status); 13187afa535eSMukunda, Vijendar return status; 13197afa535eSMukunda, Vijendar } 13201927da93SMaruthi Srinivas Bayyavarapu 1321e21358c4SMukunda, Vijendar if (adata->play_i2ssp_stream && adata->play_i2ssp_stream->runtime) { 132213838c11SMukunda, Vijendar /* 132313838c11SMukunda, Vijendar * For Stoney, Memory gating is disabled,i.e SRAM Banks 1324607b39efSVijendar Mukunda * won't be turned off. The default state for SRAM banks is ON. 1325607b39efSVijendar Mukunda * Setting SRAM bank state code skipped for STONEY platform. 1326607b39efSVijendar Mukunda */ 1327607b39efSVijendar Mukunda if (adata->asic_type != CHIP_STONEY) { 1328c36d9b3fSMaruthi Srinivas Bayyavarapu for (bank = 1; bank <= 4; bank++) 1329c36d9b3fSMaruthi Srinivas Bayyavarapu acp_set_sram_bank_state(adata->acp_mmio, bank, 1330c36d9b3fSMaruthi Srinivas Bayyavarapu true); 1331607b39efSVijendar Mukunda } 1332ccfbb4f5SMukunda, Vijendar rtd = adata->play_i2ssp_stream->runtime->private_data; 1333ccfbb4f5SMukunda, Vijendar config_acp_dma(adata->acp_mmio, rtd, adata->asic_type); 1334c36d9b3fSMaruthi Srinivas Bayyavarapu } 133513838c11SMukunda, Vijendar if (adata->capture_i2ssp_stream && 133613838c11SMukunda, Vijendar adata->capture_i2ssp_stream->runtime) { 1337607b39efSVijendar Mukunda if (adata->asic_type != CHIP_STONEY) { 1338c36d9b3fSMaruthi Srinivas Bayyavarapu for (bank = 5; bank <= 8; bank++) 1339c36d9b3fSMaruthi Srinivas Bayyavarapu acp_set_sram_bank_state(adata->acp_mmio, bank, 1340c36d9b3fSMaruthi Srinivas Bayyavarapu true); 1341607b39efSVijendar Mukunda } 1342ccfbb4f5SMukunda, Vijendar rtd = adata->capture_i2ssp_stream->runtime->private_data; 1343ccfbb4f5SMukunda, Vijendar config_acp_dma(adata->acp_mmio, rtd, adata->asic_type); 1344ccfbb4f5SMukunda, Vijendar } 1345ccfbb4f5SMukunda, Vijendar if (adata->asic_type != CHIP_CARRIZO) { 1346ccfbb4f5SMukunda, Vijendar if (adata->play_i2sbt_stream && 1347ccfbb4f5SMukunda, Vijendar adata->play_i2sbt_stream->runtime) { 1348ccfbb4f5SMukunda, Vijendar rtd = adata->play_i2sbt_stream->runtime->private_data; 1349ccfbb4f5SMukunda, Vijendar config_acp_dma(adata->acp_mmio, rtd, adata->asic_type); 1350ccfbb4f5SMukunda, Vijendar } 1351ccfbb4f5SMukunda, Vijendar if (adata->capture_i2sbt_stream && 1352ccfbb4f5SMukunda, Vijendar adata->capture_i2sbt_stream->runtime) { 1353ccfbb4f5SMukunda, Vijendar rtd = adata->capture_i2sbt_stream->runtime->private_data; 1354ccfbb4f5SMukunda, Vijendar config_acp_dma(adata->acp_mmio, rtd, adata->asic_type); 1355ccfbb4f5SMukunda, Vijendar } 1356c36d9b3fSMaruthi Srinivas Bayyavarapu } 13571927da93SMaruthi Srinivas Bayyavarapu acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); 13581927da93SMaruthi Srinivas Bayyavarapu return 0; 13591927da93SMaruthi Srinivas Bayyavarapu } 13601927da93SMaruthi Srinivas Bayyavarapu 13611927da93SMaruthi Srinivas Bayyavarapu static int acp_pcm_runtime_suspend(struct device *dev) 13621927da93SMaruthi Srinivas Bayyavarapu { 13637afa535eSMukunda, Vijendar int status; 13641927da93SMaruthi Srinivas Bayyavarapu struct audio_drv_data *adata = dev_get_drvdata(dev); 13651927da93SMaruthi Srinivas Bayyavarapu 13667afa535eSMukunda, Vijendar status = acp_deinit(adata->acp_mmio); 13677afa535eSMukunda, Vijendar if (status) 13687afa535eSMukunda, Vijendar dev_err(dev, "ACP Deinit failed status:%d\n", status); 13691927da93SMaruthi Srinivas Bayyavarapu acp_reg_write(0, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); 13701927da93SMaruthi Srinivas Bayyavarapu return 0; 13711927da93SMaruthi Srinivas Bayyavarapu } 13721927da93SMaruthi Srinivas Bayyavarapu 13731927da93SMaruthi Srinivas Bayyavarapu static int acp_pcm_runtime_resume(struct device *dev) 13741927da93SMaruthi Srinivas Bayyavarapu { 13757afa535eSMukunda, Vijendar int status; 13761927da93SMaruthi Srinivas Bayyavarapu struct audio_drv_data *adata = dev_get_drvdata(dev); 13771927da93SMaruthi Srinivas Bayyavarapu 13787afa535eSMukunda, Vijendar status = acp_init(adata->acp_mmio, adata->asic_type); 13797afa535eSMukunda, Vijendar if (status) { 13807afa535eSMukunda, Vijendar dev_err(dev, "ACP Init failed status:%d\n", status); 13817afa535eSMukunda, Vijendar return status; 13827afa535eSMukunda, Vijendar } 13831927da93SMaruthi Srinivas Bayyavarapu acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); 13841927da93SMaruthi Srinivas Bayyavarapu return 0; 13851927da93SMaruthi Srinivas Bayyavarapu } 13861927da93SMaruthi Srinivas Bayyavarapu 13871927da93SMaruthi Srinivas Bayyavarapu static const struct dev_pm_ops acp_pm_ops = { 13881927da93SMaruthi Srinivas Bayyavarapu .resume = acp_pcm_resume, 13891927da93SMaruthi Srinivas Bayyavarapu .runtime_suspend = acp_pcm_runtime_suspend, 13901927da93SMaruthi Srinivas Bayyavarapu .runtime_resume = acp_pcm_runtime_resume, 13911927da93SMaruthi Srinivas Bayyavarapu }; 13921927da93SMaruthi Srinivas Bayyavarapu 13937c31335aSMaruthi Srinivas Bayyavarapu static struct platform_driver acp_dma_driver = { 13947c31335aSMaruthi Srinivas Bayyavarapu .probe = acp_audio_probe, 13957c31335aSMaruthi Srinivas Bayyavarapu .remove = acp_audio_remove, 13967c31335aSMaruthi Srinivas Bayyavarapu .driver = { 1397bdd2a858SAkshu Agrawal .name = DRV_NAME, 13981927da93SMaruthi Srinivas Bayyavarapu .pm = &acp_pm_ops, 13997c31335aSMaruthi Srinivas Bayyavarapu }, 14007c31335aSMaruthi Srinivas Bayyavarapu }; 14017c31335aSMaruthi Srinivas Bayyavarapu 14027c31335aSMaruthi Srinivas Bayyavarapu module_platform_driver(acp_dma_driver); 14037c31335aSMaruthi Srinivas Bayyavarapu 1404607b39efSVijendar Mukunda MODULE_AUTHOR("Vijendar.Mukunda@amd.com"); 14057c31335aSMaruthi Srinivas Bayyavarapu MODULE_AUTHOR("Maruthi.Bayyavarapu@amd.com"); 14067c31335aSMaruthi Srinivas Bayyavarapu MODULE_DESCRIPTION("AMD ACP PCM Driver"); 14077c31335aSMaruthi Srinivas Bayyavarapu MODULE_LICENSE("GPL v2"); 1408bdd2a858SAkshu Agrawal MODULE_ALIAS("platform:"DRV_NAME); 1409