xref: /linux/sound/soc/amd/acp-pcm-dma.c (revision 6b116dfb4633a7efce7f96355c2d272d8b16f0fb)
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 |=
227aac89748SVijendar Mukunda 				BIT(22) |
22813838c11SMukunda, Vijendar 				(ACP_DMA_ATTR_SHARED_MEM_TO_DAGB_GARLIC << 16) |
229aac89748SVijendar Mukunda 				(size / 2);
230aac89748SVijendar Mukunda 				break;
231aac89748SVijendar Mukunda 			default:
2327c31335aSMaruthi Srinivas Bayyavarapu 				dmadscr[i].xfer_val |=
2337c31335aSMaruthi Srinivas Bayyavarapu 				BIT(22) |
23413838c11SMukunda, Vijendar 				(ACP_DMA_ATTR_SHAREDMEM_TO_DAGB_ONION << 16) |
2357c31335aSMaruthi Srinivas Bayyavarapu 				(size / 2);
2367c31335aSMaruthi Srinivas Bayyavarapu 			}
237aac89748SVijendar Mukunda 		}
2387c31335aSMaruthi Srinivas Bayyavarapu 		config_dma_descriptor_in_sram(acp_mmio, dma_dscr_idx,
2397c31335aSMaruthi Srinivas Bayyavarapu 					      &dmadscr[i]);
2407c31335aSMaruthi Srinivas Bayyavarapu 	}
2414376a86cSMukunda, Vijendar 	config_acp_dma_channel(acp_mmio, ch,
2424376a86cSMukunda, Vijendar 			       dma_dscr_idx - 1,
2437c31335aSMaruthi Srinivas Bayyavarapu 			       NUM_DSCRS_PER_CHANNEL,
2447c31335aSMaruthi Srinivas Bayyavarapu 			       ACP_DMA_PRIORITY_LEVEL_NORMAL);
2457c31335aSMaruthi Srinivas Bayyavarapu }
2467c31335aSMaruthi Srinivas Bayyavarapu 
24713838c11SMukunda, Vijendar /*
24813838c11SMukunda, Vijendar  * Initialize the DMA descriptor information for transfer between
2497c31335aSMaruthi Srinivas Bayyavarapu  * ACP SRAM <-> I2S
2507c31335aSMaruthi Srinivas Bayyavarapu  */
2514376a86cSMukunda, Vijendar static void set_acp_to_i2s_dma_descriptors(void __iomem *acp_mmio, u32 size,
2524376a86cSMukunda, Vijendar 					   int direction, u32 sram_bank,
2534376a86cSMukunda, Vijendar 					   u16 destination, u16 ch,
2544376a86cSMukunda, Vijendar 					   u16 dma_dscr_idx, u32 asic_type)
2557c31335aSMaruthi Srinivas Bayyavarapu {
2567c31335aSMaruthi Srinivas Bayyavarapu 	u16 i;
2577c31335aSMaruthi Srinivas Bayyavarapu 	acp_dma_dscr_transfer_t dmadscr[NUM_DSCRS_PER_CHANNEL];
2587c31335aSMaruthi Srinivas Bayyavarapu 
2597c31335aSMaruthi Srinivas Bayyavarapu 	for (i = 0; i < NUM_DSCRS_PER_CHANNEL; i++) {
2607c31335aSMaruthi Srinivas Bayyavarapu 		dmadscr[i].xfer_val = 0;
2617c31335aSMaruthi Srinivas Bayyavarapu 		if (direction == SNDRV_PCM_STREAM_PLAYBACK) {
2624376a86cSMukunda, Vijendar 			dma_dscr_idx = dma_dscr_idx + i;
2634376a86cSMukunda, Vijendar 			dmadscr[i].src = sram_bank  + (i * (size / 2));
2647c31335aSMaruthi Srinivas Bayyavarapu 			/* dmadscr[i].dest is unused by hardware. */
2657c31335aSMaruthi Srinivas Bayyavarapu 			dmadscr[i].dest = 0;
2664376a86cSMukunda, Vijendar 			dmadscr[i].xfer_val |= BIT(22) | (destination << 16) |
2677c31335aSMaruthi Srinivas Bayyavarapu 						(size / 2);
2687c31335aSMaruthi Srinivas Bayyavarapu 		} else {
2694376a86cSMukunda, Vijendar 			dma_dscr_idx = dma_dscr_idx + i;
2707c31335aSMaruthi Srinivas Bayyavarapu 			/* dmadscr[i].src is unused by hardware. */
2717c31335aSMaruthi Srinivas Bayyavarapu 			dmadscr[i].src = 0;
272aac89748SVijendar Mukunda 			dmadscr[i].dest =
2734376a86cSMukunda, Vijendar 				 sram_bank + (i * (size / 2));
2747c31335aSMaruthi Srinivas Bayyavarapu 			dmadscr[i].xfer_val |= BIT(22) |
2754376a86cSMukunda, Vijendar 				(destination << 16) | (size / 2);
2767c31335aSMaruthi Srinivas Bayyavarapu 		}
2777c31335aSMaruthi Srinivas Bayyavarapu 		config_dma_descriptor_in_sram(acp_mmio, dma_dscr_idx,
2787c31335aSMaruthi Srinivas Bayyavarapu 					      &dmadscr[i]);
2797c31335aSMaruthi Srinivas Bayyavarapu 	}
2807c31335aSMaruthi Srinivas Bayyavarapu 	/* Configure the DMA channel with the above descriptore */
2814376a86cSMukunda, Vijendar 	config_acp_dma_channel(acp_mmio, ch, dma_dscr_idx - 1,
2827c31335aSMaruthi Srinivas Bayyavarapu 			       NUM_DSCRS_PER_CHANNEL,
2837c31335aSMaruthi Srinivas Bayyavarapu 			       ACP_DMA_PRIORITY_LEVEL_NORMAL);
2847c31335aSMaruthi Srinivas Bayyavarapu }
2857c31335aSMaruthi Srinivas Bayyavarapu 
2867c31335aSMaruthi Srinivas Bayyavarapu /* Create page table entries in ACP SRAM for the allocated memory */
2877c31335aSMaruthi Srinivas Bayyavarapu static void acp_pte_config(void __iomem *acp_mmio, struct page *pg,
2887c31335aSMaruthi Srinivas Bayyavarapu 			   u16 num_of_pages, u32 pte_offset)
2897c31335aSMaruthi Srinivas Bayyavarapu {
2907c31335aSMaruthi Srinivas Bayyavarapu 	u16 page_idx;
2917c31335aSMaruthi Srinivas Bayyavarapu 	u64 addr;
2927c31335aSMaruthi Srinivas Bayyavarapu 	u32 low;
2937c31335aSMaruthi Srinivas Bayyavarapu 	u32 high;
2947c31335aSMaruthi Srinivas Bayyavarapu 	u32 offset;
2957c31335aSMaruthi Srinivas Bayyavarapu 
2967c31335aSMaruthi Srinivas Bayyavarapu 	offset	= ACP_DAGB_GRP_SRBM_SRAM_BASE_OFFSET + (pte_offset * 8);
2977c31335aSMaruthi Srinivas Bayyavarapu 	for (page_idx = 0; page_idx < (num_of_pages); page_idx++) {
2987c31335aSMaruthi Srinivas Bayyavarapu 		/* Load the low address of page int ACP SRAM through SRBM */
2997c31335aSMaruthi Srinivas Bayyavarapu 		acp_reg_write((offset + (page_idx * 8)),
3007c31335aSMaruthi Srinivas Bayyavarapu 			      acp_mmio, mmACP_SRBM_Targ_Idx_Addr);
3017c31335aSMaruthi Srinivas Bayyavarapu 		addr = page_to_phys(pg);
3027c31335aSMaruthi Srinivas Bayyavarapu 
3037c31335aSMaruthi Srinivas Bayyavarapu 		low = lower_32_bits(addr);
3047c31335aSMaruthi Srinivas Bayyavarapu 		high = upper_32_bits(addr);
3057c31335aSMaruthi Srinivas Bayyavarapu 
3067c31335aSMaruthi Srinivas Bayyavarapu 		acp_reg_write(low, acp_mmio, mmACP_SRBM_Targ_Idx_Data);
3077c31335aSMaruthi Srinivas Bayyavarapu 
3087c31335aSMaruthi Srinivas Bayyavarapu 		/* Load the High address of page int ACP SRAM through SRBM */
3097c31335aSMaruthi Srinivas Bayyavarapu 		acp_reg_write((offset + (page_idx * 8) + 4),
3107c31335aSMaruthi Srinivas Bayyavarapu 			      acp_mmio, mmACP_SRBM_Targ_Idx_Addr);
3117c31335aSMaruthi Srinivas Bayyavarapu 
3127c31335aSMaruthi Srinivas Bayyavarapu 		/* page enable in ACP */
3137c31335aSMaruthi Srinivas Bayyavarapu 		high |= BIT(31);
3147c31335aSMaruthi Srinivas Bayyavarapu 		acp_reg_write(high, acp_mmio, mmACP_SRBM_Targ_Idx_Data);
3157c31335aSMaruthi Srinivas Bayyavarapu 
3167c31335aSMaruthi Srinivas Bayyavarapu 		/* Move to next physically contiguos page */
3177c31335aSMaruthi Srinivas Bayyavarapu 		pg++;
3187c31335aSMaruthi Srinivas Bayyavarapu 	}
3197c31335aSMaruthi Srinivas Bayyavarapu }
3207c31335aSMaruthi Srinivas Bayyavarapu 
3217c31335aSMaruthi Srinivas Bayyavarapu static void config_acp_dma(void __iomem *acp_mmio,
3228349b7f5SMukunda, Vijendar 			   struct audio_substream_data *rtd,
323aac89748SVijendar Mukunda 			   u32 asic_type)
3247c31335aSMaruthi Srinivas Bayyavarapu {
3258349b7f5SMukunda, Vijendar 	acp_pte_config(acp_mmio, rtd->pg, rtd->num_of_pages,
326e188c525SMukunda, Vijendar 		       rtd->pte_offset);
3277c31335aSMaruthi Srinivas Bayyavarapu 	/* Configure System memory <-> ACP SRAM DMA descriptors */
3288349b7f5SMukunda, Vijendar 	set_acp_sysmem_dma_descriptors(acp_mmio, rtd->size,
329e188c525SMukunda, Vijendar 				       rtd->direction, rtd->pte_offset,
33018e8a40dSMukunda, Vijendar 				       rtd->ch1, rtd->sram_bank,
3318769bb55SVijendar Mukunda 				       rtd->dma_dscr_idx_1, asic_type);
3327c31335aSMaruthi Srinivas Bayyavarapu 	/* Configure ACP SRAM <-> I2S DMA descriptors */
3338349b7f5SMukunda, Vijendar 	set_acp_to_i2s_dma_descriptors(acp_mmio, rtd->size,
33418e8a40dSMukunda, Vijendar 				       rtd->direction, rtd->sram_bank,
3358769bb55SVijendar Mukunda 				       rtd->destination, rtd->ch2,
3368769bb55SVijendar Mukunda 				       rtd->dma_dscr_idx_2, asic_type);
3377c31335aSMaruthi Srinivas Bayyavarapu }
3387c31335aSMaruthi Srinivas Bayyavarapu 
3397c31335aSMaruthi Srinivas Bayyavarapu /* Start a given DMA channel transfer */
340*6b116dfbSAgrawal, Akshu static void acp_dma_start(void __iomem *acp_mmio, u16 ch_num)
3417c31335aSMaruthi Srinivas Bayyavarapu {
3427c31335aSMaruthi Srinivas Bayyavarapu 	u32 dma_ctrl;
3437c31335aSMaruthi Srinivas Bayyavarapu 
3447c31335aSMaruthi Srinivas Bayyavarapu 	/* read the dma control register and disable the channel run field */
3457c31335aSMaruthi Srinivas Bayyavarapu 	dma_ctrl = acp_reg_read(acp_mmio, mmACP_DMA_CNTL_0 + ch_num);
3467c31335aSMaruthi Srinivas Bayyavarapu 
3477c31335aSMaruthi Srinivas Bayyavarapu 	/* Invalidating the DAGB cache */
3487c31335aSMaruthi Srinivas Bayyavarapu 	acp_reg_write(1, acp_mmio, mmACP_DAGB_ATU_CTRL);
3497c31335aSMaruthi Srinivas Bayyavarapu 
35013838c11SMukunda, Vijendar 	/*
35113838c11SMukunda, Vijendar 	 * configure the DMA channel and start the DMA transfer
3527c31335aSMaruthi Srinivas Bayyavarapu 	 * set dmachrun bit to start the transfer and enable the
3537c31335aSMaruthi Srinivas Bayyavarapu 	 * interrupt on completion of the dma transfer
3547c31335aSMaruthi Srinivas Bayyavarapu 	 */
3557c31335aSMaruthi Srinivas Bayyavarapu 	dma_ctrl |= ACP_DMA_CNTL_0__DMAChRun_MASK;
3567c31335aSMaruthi Srinivas Bayyavarapu 
3577c31335aSMaruthi Srinivas Bayyavarapu 	switch (ch_num) {
3587c31335aSMaruthi Srinivas Bayyavarapu 	case ACP_TO_I2S_DMA_CH_NUM:
3597c31335aSMaruthi Srinivas Bayyavarapu 	case ACP_TO_SYSRAM_CH_NUM:
3607c31335aSMaruthi Srinivas Bayyavarapu 	case I2S_TO_ACP_DMA_CH_NUM:
361ccfbb4f5SMukunda, Vijendar 	case ACP_TO_I2S_DMA_BT_INSTANCE_CH_NUM:
362ccfbb4f5SMukunda, Vijendar 	case ACP_TO_SYSRAM_BT_INSTANCE_CH_NUM:
363ccfbb4f5SMukunda, Vijendar 	case I2S_TO_ACP_DMA_BT_INSTANCE_CH_NUM:
3647c31335aSMaruthi Srinivas Bayyavarapu 		dma_ctrl |= ACP_DMA_CNTL_0__DMAChIOCEn_MASK;
3657c31335aSMaruthi Srinivas Bayyavarapu 		break;
3667c31335aSMaruthi Srinivas Bayyavarapu 	default:
3677c31335aSMaruthi Srinivas Bayyavarapu 		dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChIOCEn_MASK;
3687c31335aSMaruthi Srinivas Bayyavarapu 		break;
3697c31335aSMaruthi Srinivas Bayyavarapu 	}
3707c31335aSMaruthi Srinivas Bayyavarapu 
371*6b116dfbSAgrawal, Akshu 	/* circular for both DMA channel */
3727c31335aSMaruthi Srinivas Bayyavarapu 	dma_ctrl |= ACP_DMA_CNTL_0__Circular_DMA_En_MASK;
3737c31335aSMaruthi Srinivas Bayyavarapu 
3747c31335aSMaruthi Srinivas Bayyavarapu 	acp_reg_write(dma_ctrl, acp_mmio, mmACP_DMA_CNTL_0 + ch_num);
3757c31335aSMaruthi Srinivas Bayyavarapu }
3767c31335aSMaruthi Srinivas Bayyavarapu 
3777c31335aSMaruthi Srinivas Bayyavarapu /* Stop a given DMA channel transfer */
3787c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_stop(void __iomem *acp_mmio, u8 ch_num)
3797c31335aSMaruthi Srinivas Bayyavarapu {
3807c31335aSMaruthi Srinivas Bayyavarapu 	u32 dma_ctrl;
3817c31335aSMaruthi Srinivas Bayyavarapu 	u32 dma_ch_sts;
3827c31335aSMaruthi Srinivas Bayyavarapu 	u32 count = ACP_DMA_RESET_TIME;
3837c31335aSMaruthi Srinivas Bayyavarapu 
3847c31335aSMaruthi Srinivas Bayyavarapu 	dma_ctrl = acp_reg_read(acp_mmio, mmACP_DMA_CNTL_0 + ch_num);
3857c31335aSMaruthi Srinivas Bayyavarapu 
38613838c11SMukunda, Vijendar 	/*
38713838c11SMukunda, Vijendar 	 * clear the dma control register fields before writing zero
3887c31335aSMaruthi Srinivas Bayyavarapu 	 * in reset bit
3897c31335aSMaruthi Srinivas Bayyavarapu 	 */
3907c31335aSMaruthi Srinivas Bayyavarapu 	dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChRun_MASK;
3917c31335aSMaruthi Srinivas Bayyavarapu 	dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChIOCEn_MASK;
3927c31335aSMaruthi Srinivas Bayyavarapu 
3937c31335aSMaruthi Srinivas Bayyavarapu 	acp_reg_write(dma_ctrl, acp_mmio, mmACP_DMA_CNTL_0 + ch_num);
3947c31335aSMaruthi Srinivas Bayyavarapu 	dma_ch_sts = acp_reg_read(acp_mmio, mmACP_DMA_CH_STS);
3957c31335aSMaruthi Srinivas Bayyavarapu 
3967c31335aSMaruthi Srinivas Bayyavarapu 	if (dma_ch_sts & BIT(ch_num)) {
39713838c11SMukunda, Vijendar 		/*
39813838c11SMukunda, Vijendar 		 * set the reset bit for this channel to stop the dma
3997c31335aSMaruthi Srinivas Bayyavarapu 		 *  transfer
4007c31335aSMaruthi Srinivas Bayyavarapu 		 */
4017c31335aSMaruthi Srinivas Bayyavarapu 		dma_ctrl |= ACP_DMA_CNTL_0__DMAChRst_MASK;
4027c31335aSMaruthi Srinivas Bayyavarapu 		acp_reg_write(dma_ctrl, acp_mmio, mmACP_DMA_CNTL_0 + ch_num);
4037c31335aSMaruthi Srinivas Bayyavarapu 	}
4047c31335aSMaruthi Srinivas Bayyavarapu 
4057c31335aSMaruthi Srinivas Bayyavarapu 	/* check the channel status bit for some time and return the status */
4067c31335aSMaruthi Srinivas Bayyavarapu 	while (true) {
4077c31335aSMaruthi Srinivas Bayyavarapu 		dma_ch_sts = acp_reg_read(acp_mmio, mmACP_DMA_CH_STS);
4087c31335aSMaruthi Srinivas Bayyavarapu 		if (!(dma_ch_sts & BIT(ch_num))) {
40913838c11SMukunda, Vijendar 			/*
41013838c11SMukunda, Vijendar 			 * clear the reset flag after successfully stopping
4117c31335aSMaruthi Srinivas Bayyavarapu 			 * the dma transfer and break from the loop
4127c31335aSMaruthi Srinivas Bayyavarapu 			 */
4137c31335aSMaruthi Srinivas Bayyavarapu 			dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChRst_MASK;
4147c31335aSMaruthi Srinivas Bayyavarapu 
4157c31335aSMaruthi Srinivas Bayyavarapu 			acp_reg_write(dma_ctrl, acp_mmio, mmACP_DMA_CNTL_0
4167c31335aSMaruthi Srinivas Bayyavarapu 				      + ch_num);
4177c31335aSMaruthi Srinivas Bayyavarapu 			break;
4187c31335aSMaruthi Srinivas Bayyavarapu 		}
4197c31335aSMaruthi Srinivas Bayyavarapu 		if (--count == 0) {
4207c31335aSMaruthi Srinivas Bayyavarapu 			pr_err("Failed to stop ACP DMA channel : %d\n", ch_num);
4217c31335aSMaruthi Srinivas Bayyavarapu 			return -ETIMEDOUT;
4227c31335aSMaruthi Srinivas Bayyavarapu 		}
4237c31335aSMaruthi Srinivas Bayyavarapu 		udelay(100);
4247c31335aSMaruthi Srinivas Bayyavarapu 	}
4257c31335aSMaruthi Srinivas Bayyavarapu 	return 0;
4267c31335aSMaruthi Srinivas Bayyavarapu }
4277c31335aSMaruthi Srinivas Bayyavarapu 
428c36d9b3fSMaruthi Srinivas Bayyavarapu static void acp_set_sram_bank_state(void __iomem *acp_mmio, u16 bank,
429c36d9b3fSMaruthi Srinivas Bayyavarapu 				    bool power_on)
430c36d9b3fSMaruthi Srinivas Bayyavarapu {
431c36d9b3fSMaruthi Srinivas Bayyavarapu 	u32 val, req_reg, sts_reg, sts_reg_mask;
432c36d9b3fSMaruthi Srinivas Bayyavarapu 	u32 loops = 1000;
433c36d9b3fSMaruthi Srinivas Bayyavarapu 
434c36d9b3fSMaruthi Srinivas Bayyavarapu 	if (bank < 32) {
435c36d9b3fSMaruthi Srinivas Bayyavarapu 		req_reg = mmACP_MEM_SHUT_DOWN_REQ_LO;
436c36d9b3fSMaruthi Srinivas Bayyavarapu 		sts_reg = mmACP_MEM_SHUT_DOWN_STS_LO;
437c36d9b3fSMaruthi Srinivas Bayyavarapu 		sts_reg_mask = 0xFFFFFFFF;
438c36d9b3fSMaruthi Srinivas Bayyavarapu 
439c36d9b3fSMaruthi Srinivas Bayyavarapu 	} else {
440c36d9b3fSMaruthi Srinivas Bayyavarapu 		bank -= 32;
441c36d9b3fSMaruthi Srinivas Bayyavarapu 		req_reg = mmACP_MEM_SHUT_DOWN_REQ_HI;
442c36d9b3fSMaruthi Srinivas Bayyavarapu 		sts_reg = mmACP_MEM_SHUT_DOWN_STS_HI;
443c36d9b3fSMaruthi Srinivas Bayyavarapu 		sts_reg_mask = 0x0000FFFF;
444c36d9b3fSMaruthi Srinivas Bayyavarapu 	}
445c36d9b3fSMaruthi Srinivas Bayyavarapu 
446c36d9b3fSMaruthi Srinivas Bayyavarapu 	val = acp_reg_read(acp_mmio, req_reg);
447c36d9b3fSMaruthi Srinivas Bayyavarapu 	if (val & (1 << bank)) {
448c36d9b3fSMaruthi Srinivas Bayyavarapu 		/* bank is in off state */
449c36d9b3fSMaruthi Srinivas Bayyavarapu 		if (power_on == true)
450c36d9b3fSMaruthi Srinivas Bayyavarapu 			/* request to on */
451c36d9b3fSMaruthi Srinivas Bayyavarapu 			val &= ~(1 << bank);
452c36d9b3fSMaruthi Srinivas Bayyavarapu 		else
453c36d9b3fSMaruthi Srinivas Bayyavarapu 			/* request to off */
454c36d9b3fSMaruthi Srinivas Bayyavarapu 			return;
455c36d9b3fSMaruthi Srinivas Bayyavarapu 	} else {
456c36d9b3fSMaruthi Srinivas Bayyavarapu 		/* bank is in on state */
457c36d9b3fSMaruthi Srinivas Bayyavarapu 		if (power_on == false)
458c36d9b3fSMaruthi Srinivas Bayyavarapu 			/* request to off */
459c36d9b3fSMaruthi Srinivas Bayyavarapu 			val |= 1 << bank;
460c36d9b3fSMaruthi Srinivas Bayyavarapu 		else
461c36d9b3fSMaruthi Srinivas Bayyavarapu 			/* request to on */
462c36d9b3fSMaruthi Srinivas Bayyavarapu 			return;
463c36d9b3fSMaruthi Srinivas Bayyavarapu 	}
464c36d9b3fSMaruthi Srinivas Bayyavarapu 	acp_reg_write(val, acp_mmio, req_reg);
465c36d9b3fSMaruthi Srinivas Bayyavarapu 
466c36d9b3fSMaruthi Srinivas Bayyavarapu 	while (acp_reg_read(acp_mmio, sts_reg) != sts_reg_mask) {
467c36d9b3fSMaruthi Srinivas Bayyavarapu 		if (!loops--) {
468c36d9b3fSMaruthi Srinivas Bayyavarapu 			pr_err("ACP SRAM bank %d state change failed\n", bank);
469c36d9b3fSMaruthi Srinivas Bayyavarapu 			break;
470c36d9b3fSMaruthi Srinivas Bayyavarapu 		}
471c36d9b3fSMaruthi Srinivas Bayyavarapu 		cpu_relax();
472c36d9b3fSMaruthi Srinivas Bayyavarapu 	}
473c36d9b3fSMaruthi Srinivas Bayyavarapu }
474c36d9b3fSMaruthi Srinivas Bayyavarapu 
4757c31335aSMaruthi Srinivas Bayyavarapu /* Initialize and bring ACP hardware to default state. */
476607b39efSVijendar Mukunda static int acp_init(void __iomem *acp_mmio, u32 asic_type)
4777c31335aSMaruthi Srinivas Bayyavarapu {
478c36d9b3fSMaruthi Srinivas Bayyavarapu 	u16 bank;
4797c31335aSMaruthi Srinivas Bayyavarapu 	u32 val, count, sram_pte_offset;
4807c31335aSMaruthi Srinivas Bayyavarapu 
4817c31335aSMaruthi Srinivas Bayyavarapu 	/* Assert Soft reset of ACP */
4827c31335aSMaruthi Srinivas Bayyavarapu 	val = acp_reg_read(acp_mmio, mmACP_SOFT_RESET);
4837c31335aSMaruthi Srinivas Bayyavarapu 
4847c31335aSMaruthi Srinivas Bayyavarapu 	val |= ACP_SOFT_RESET__SoftResetAud_MASK;
4857c31335aSMaruthi Srinivas Bayyavarapu 	acp_reg_write(val, acp_mmio, mmACP_SOFT_RESET);
4867c31335aSMaruthi Srinivas Bayyavarapu 
4877c31335aSMaruthi Srinivas Bayyavarapu 	count = ACP_SOFT_RESET_DONE_TIME_OUT_VALUE;
4887c31335aSMaruthi Srinivas Bayyavarapu 	while (true) {
4897c31335aSMaruthi Srinivas Bayyavarapu 		val = acp_reg_read(acp_mmio, mmACP_SOFT_RESET);
4907c31335aSMaruthi Srinivas Bayyavarapu 		if (ACP_SOFT_RESET__SoftResetAudDone_MASK ==
4917c31335aSMaruthi Srinivas Bayyavarapu 		    (val & ACP_SOFT_RESET__SoftResetAudDone_MASK))
4927c31335aSMaruthi Srinivas Bayyavarapu 			break;
4937c31335aSMaruthi Srinivas Bayyavarapu 		if (--count == 0) {
4947c31335aSMaruthi Srinivas Bayyavarapu 			pr_err("Failed to reset ACP\n");
4957c31335aSMaruthi Srinivas Bayyavarapu 			return -ETIMEDOUT;
4967c31335aSMaruthi Srinivas Bayyavarapu 		}
4977c31335aSMaruthi Srinivas Bayyavarapu 		udelay(100);
4987c31335aSMaruthi Srinivas Bayyavarapu 	}
4997c31335aSMaruthi Srinivas Bayyavarapu 
5007c31335aSMaruthi Srinivas Bayyavarapu 	/* Enable clock to ACP and wait until the clock is enabled */
5017c31335aSMaruthi Srinivas Bayyavarapu 	val = acp_reg_read(acp_mmio, mmACP_CONTROL);
5027c31335aSMaruthi Srinivas Bayyavarapu 	val = val | ACP_CONTROL__ClkEn_MASK;
5037c31335aSMaruthi Srinivas Bayyavarapu 	acp_reg_write(val, acp_mmio, mmACP_CONTROL);
5047c31335aSMaruthi Srinivas Bayyavarapu 
5057c31335aSMaruthi Srinivas Bayyavarapu 	count = ACP_CLOCK_EN_TIME_OUT_VALUE;
5067c31335aSMaruthi Srinivas Bayyavarapu 
5077c31335aSMaruthi Srinivas Bayyavarapu 	while (true) {
5087c31335aSMaruthi Srinivas Bayyavarapu 		val = acp_reg_read(acp_mmio, mmACP_STATUS);
5097c31335aSMaruthi Srinivas Bayyavarapu 		if (val & (u32)0x1)
5107c31335aSMaruthi Srinivas Bayyavarapu 			break;
5117c31335aSMaruthi Srinivas Bayyavarapu 		if (--count == 0) {
5127c31335aSMaruthi Srinivas Bayyavarapu 			pr_err("Failed to reset ACP\n");
5137c31335aSMaruthi Srinivas Bayyavarapu 			return -ETIMEDOUT;
5147c31335aSMaruthi Srinivas Bayyavarapu 		}
5157c31335aSMaruthi Srinivas Bayyavarapu 		udelay(100);
5167c31335aSMaruthi Srinivas Bayyavarapu 	}
5177c31335aSMaruthi Srinivas Bayyavarapu 
5187c31335aSMaruthi Srinivas Bayyavarapu 	/* Deassert the SOFT RESET flags */
5197c31335aSMaruthi Srinivas Bayyavarapu 	val = acp_reg_read(acp_mmio, mmACP_SOFT_RESET);
5207c31335aSMaruthi Srinivas Bayyavarapu 	val &= ~ACP_SOFT_RESET__SoftResetAud_MASK;
5217c31335aSMaruthi Srinivas Bayyavarapu 	acp_reg_write(val, acp_mmio, mmACP_SOFT_RESET);
5227c31335aSMaruthi Srinivas Bayyavarapu 
523ccfbb4f5SMukunda, Vijendar 	/* For BT instance change pins from UART to BT */
524ccfbb4f5SMukunda, Vijendar 	if (!bt_uart_enable) {
525ccfbb4f5SMukunda, Vijendar 		val = acp_reg_read(acp_mmio, mmACP_BT_UART_PAD_SEL);
526ccfbb4f5SMukunda, Vijendar 		val |= ACP_BT_UART_PAD_SELECT_MASK;
527ccfbb4f5SMukunda, Vijendar 		acp_reg_write(val, acp_mmio, mmACP_BT_UART_PAD_SEL);
528ccfbb4f5SMukunda, Vijendar 	}
529ccfbb4f5SMukunda, Vijendar 
5307c31335aSMaruthi Srinivas Bayyavarapu 	/* initiailize Onion control DAGB register */
5317c31335aSMaruthi Srinivas Bayyavarapu 	acp_reg_write(ACP_ONION_CNTL_DEFAULT, acp_mmio,
5327c31335aSMaruthi Srinivas Bayyavarapu 		      mmACP_AXI2DAGB_ONION_CNTL);
5337c31335aSMaruthi Srinivas Bayyavarapu 
5347c31335aSMaruthi Srinivas Bayyavarapu 	/* initiailize Garlic control DAGB registers */
5357c31335aSMaruthi Srinivas Bayyavarapu 	acp_reg_write(ACP_GARLIC_CNTL_DEFAULT, acp_mmio,
5367c31335aSMaruthi Srinivas Bayyavarapu 		      mmACP_AXI2DAGB_GARLIC_CNTL);
5377c31335aSMaruthi Srinivas Bayyavarapu 
5387c31335aSMaruthi Srinivas Bayyavarapu 	sram_pte_offset = ACP_DAGB_GRP_SRAM_BASE_ADDRESS |
5397c31335aSMaruthi Srinivas Bayyavarapu 			ACP_DAGB_BASE_ADDR_GRP_1__AXI2DAGBSnoopSel_MASK |
5407c31335aSMaruthi Srinivas Bayyavarapu 			ACP_DAGB_BASE_ADDR_GRP_1__AXI2DAGBTargetMemSel_MASK |
5417c31335aSMaruthi Srinivas Bayyavarapu 			ACP_DAGB_BASE_ADDR_GRP_1__AXI2DAGBGrpEnable_MASK;
5427c31335aSMaruthi Srinivas Bayyavarapu 	acp_reg_write(sram_pte_offset,  acp_mmio, mmACP_DAGB_BASE_ADDR_GRP_1);
5437c31335aSMaruthi Srinivas Bayyavarapu 	acp_reg_write(ACP_PAGE_SIZE_4K_ENABLE, acp_mmio,
5447c31335aSMaruthi Srinivas Bayyavarapu 		      mmACP_DAGB_PAGE_SIZE_GRP_1);
5457c31335aSMaruthi Srinivas Bayyavarapu 
5467c31335aSMaruthi Srinivas Bayyavarapu 	acp_reg_write(ACP_SRAM_BASE_ADDRESS, acp_mmio,
5477c31335aSMaruthi Srinivas Bayyavarapu 		      mmACP_DMA_DESC_BASE_ADDR);
5487c31335aSMaruthi Srinivas Bayyavarapu 
5497c31335aSMaruthi Srinivas Bayyavarapu 	/* Num of descriptiors in SRAM 0x4, means 256 descriptors;(64 * 4) */
5507c31335aSMaruthi Srinivas Bayyavarapu 	acp_reg_write(0x4, acp_mmio, mmACP_DMA_DESC_MAX_NUM_DSCR);
5517c31335aSMaruthi Srinivas Bayyavarapu 	acp_reg_write(ACP_EXTERNAL_INTR_CNTL__DMAIOCMask_MASK,
5527c31335aSMaruthi Srinivas Bayyavarapu 		      acp_mmio, mmACP_EXTERNAL_INTR_CNTL);
5537c31335aSMaruthi Srinivas Bayyavarapu 
55413838c11SMukunda, Vijendar        /*
55513838c11SMukunda, Vijendar 	* When ACP_TILE_P1 is turned on, all SRAM banks get turned on.
556c36d9b3fSMaruthi Srinivas Bayyavarapu 	* Now, turn off all of them. This can't be done in 'poweron' of
557c36d9b3fSMaruthi Srinivas Bayyavarapu 	* ACP pm domain, as this requires ACP to be initialized.
558607b39efSVijendar Mukunda 	* For Stoney, Memory gating is disabled,i.e SRAM Banks
559607b39efSVijendar Mukunda 	* won't be turned off. The default state for SRAM banks is ON.
560607b39efSVijendar Mukunda 	* Setting SRAM bank state code skipped for STONEY platform.
561c36d9b3fSMaruthi Srinivas Bayyavarapu 	*/
562607b39efSVijendar Mukunda 	if (asic_type != CHIP_STONEY) {
563c36d9b3fSMaruthi Srinivas Bayyavarapu 		for (bank = 1; bank < 48; bank++)
564c36d9b3fSMaruthi Srinivas Bayyavarapu 			acp_set_sram_bank_state(acp_mmio, bank, false);
565607b39efSVijendar Mukunda 	}
5667c31335aSMaruthi Srinivas Bayyavarapu 	return 0;
5677c31335aSMaruthi Srinivas Bayyavarapu }
5687c31335aSMaruthi Srinivas Bayyavarapu 
5691cce2000SMasahiro Yamada /* Deinitialize ACP */
5707c31335aSMaruthi Srinivas Bayyavarapu static int acp_deinit(void __iomem *acp_mmio)
5717c31335aSMaruthi Srinivas Bayyavarapu {
5727c31335aSMaruthi Srinivas Bayyavarapu 	u32 val;
5737c31335aSMaruthi Srinivas Bayyavarapu 	u32 count;
5747c31335aSMaruthi Srinivas Bayyavarapu 
5757c31335aSMaruthi Srinivas Bayyavarapu 	/* Assert Soft reset of ACP */
5767c31335aSMaruthi Srinivas Bayyavarapu 	val = acp_reg_read(acp_mmio, mmACP_SOFT_RESET);
5777c31335aSMaruthi Srinivas Bayyavarapu 
5787c31335aSMaruthi Srinivas Bayyavarapu 	val |= ACP_SOFT_RESET__SoftResetAud_MASK;
5797c31335aSMaruthi Srinivas Bayyavarapu 	acp_reg_write(val, acp_mmio, mmACP_SOFT_RESET);
5807c31335aSMaruthi Srinivas Bayyavarapu 
5817c31335aSMaruthi Srinivas Bayyavarapu 	count = ACP_SOFT_RESET_DONE_TIME_OUT_VALUE;
5827c31335aSMaruthi Srinivas Bayyavarapu 	while (true) {
5837c31335aSMaruthi Srinivas Bayyavarapu 		val = acp_reg_read(acp_mmio, mmACP_SOFT_RESET);
5847c31335aSMaruthi Srinivas Bayyavarapu 		if (ACP_SOFT_RESET__SoftResetAudDone_MASK ==
5857c31335aSMaruthi Srinivas Bayyavarapu 		    (val & ACP_SOFT_RESET__SoftResetAudDone_MASK))
5867c31335aSMaruthi Srinivas Bayyavarapu 			break;
5877c31335aSMaruthi Srinivas Bayyavarapu 		if (--count == 0) {
5887c31335aSMaruthi Srinivas Bayyavarapu 			pr_err("Failed to reset ACP\n");
5897c31335aSMaruthi Srinivas Bayyavarapu 			return -ETIMEDOUT;
5907c31335aSMaruthi Srinivas Bayyavarapu 		}
5917c31335aSMaruthi Srinivas Bayyavarapu 		udelay(100);
5927c31335aSMaruthi Srinivas Bayyavarapu 	}
59313838c11SMukunda, Vijendar 	/* Disable ACP clock */
5947c31335aSMaruthi Srinivas Bayyavarapu 	val = acp_reg_read(acp_mmio, mmACP_CONTROL);
5957c31335aSMaruthi Srinivas Bayyavarapu 	val &= ~ACP_CONTROL__ClkEn_MASK;
5967c31335aSMaruthi Srinivas Bayyavarapu 	acp_reg_write(val, acp_mmio, mmACP_CONTROL);
5977c31335aSMaruthi Srinivas Bayyavarapu 
5987c31335aSMaruthi Srinivas Bayyavarapu 	count = ACP_CLOCK_EN_TIME_OUT_VALUE;
5997c31335aSMaruthi Srinivas Bayyavarapu 
6007c31335aSMaruthi Srinivas Bayyavarapu 	while (true) {
6017c31335aSMaruthi Srinivas Bayyavarapu 		val = acp_reg_read(acp_mmio, mmACP_STATUS);
6027c31335aSMaruthi Srinivas Bayyavarapu 		if (!(val & (u32)0x1))
6037c31335aSMaruthi Srinivas Bayyavarapu 			break;
6047c31335aSMaruthi Srinivas Bayyavarapu 		if (--count == 0) {
6057c31335aSMaruthi Srinivas Bayyavarapu 			pr_err("Failed to reset ACP\n");
6067c31335aSMaruthi Srinivas Bayyavarapu 			return -ETIMEDOUT;
6077c31335aSMaruthi Srinivas Bayyavarapu 		}
6087c31335aSMaruthi Srinivas Bayyavarapu 		udelay(100);
6097c31335aSMaruthi Srinivas Bayyavarapu 	}
6107c31335aSMaruthi Srinivas Bayyavarapu 	return 0;
6117c31335aSMaruthi Srinivas Bayyavarapu }
6127c31335aSMaruthi Srinivas Bayyavarapu 
6137c31335aSMaruthi Srinivas Bayyavarapu /* ACP DMA irq handler routine for playback, capture usecases */
6147c31335aSMaruthi Srinivas Bayyavarapu static irqreturn_t dma_irq_handler(int irq, void *arg)
6157c31335aSMaruthi Srinivas Bayyavarapu {
6167c31335aSMaruthi Srinivas Bayyavarapu 	u32 intr_flag, ext_intr_status;
6177c31335aSMaruthi Srinivas Bayyavarapu 	struct audio_drv_data *irq_data;
6187c31335aSMaruthi Srinivas Bayyavarapu 	void __iomem *acp_mmio;
6197c31335aSMaruthi Srinivas Bayyavarapu 	struct device *dev = arg;
6207c31335aSMaruthi Srinivas Bayyavarapu 	bool valid_irq = false;
6217c31335aSMaruthi Srinivas Bayyavarapu 
6227c31335aSMaruthi Srinivas Bayyavarapu 	irq_data = dev_get_drvdata(dev);
6237c31335aSMaruthi Srinivas Bayyavarapu 	acp_mmio = irq_data->acp_mmio;
6247c31335aSMaruthi Srinivas Bayyavarapu 
6257c31335aSMaruthi Srinivas Bayyavarapu 	ext_intr_status = acp_reg_read(acp_mmio, mmACP_EXTERNAL_INTR_STAT);
6267c31335aSMaruthi Srinivas Bayyavarapu 	intr_flag = (((ext_intr_status &
6277c31335aSMaruthi Srinivas Bayyavarapu 		      ACP_EXTERNAL_INTR_STAT__DMAIOCStat_MASK) >>
6287c31335aSMaruthi Srinivas Bayyavarapu 		     ACP_EXTERNAL_INTR_STAT__DMAIOCStat__SHIFT));
6297c31335aSMaruthi Srinivas Bayyavarapu 
6307c31335aSMaruthi Srinivas Bayyavarapu 	if ((intr_flag & BIT(ACP_TO_I2S_DMA_CH_NUM)) != 0) {
6317c31335aSMaruthi Srinivas Bayyavarapu 		valid_irq = true;
632e21358c4SMukunda, Vijendar 		snd_pcm_period_elapsed(irq_data->play_i2ssp_stream);
6337c31335aSMaruthi Srinivas Bayyavarapu 		acp_reg_write((intr_flag & BIT(ACP_TO_I2S_DMA_CH_NUM)) << 16,
6347c31335aSMaruthi Srinivas Bayyavarapu 			      acp_mmio, mmACP_EXTERNAL_INTR_STAT);
6357c31335aSMaruthi Srinivas Bayyavarapu 	}
6367c31335aSMaruthi Srinivas Bayyavarapu 
637ccfbb4f5SMukunda, Vijendar 	if ((intr_flag & BIT(ACP_TO_I2S_DMA_BT_INSTANCE_CH_NUM)) != 0) {
638ccfbb4f5SMukunda, Vijendar 		valid_irq = true;
639ccfbb4f5SMukunda, Vijendar 		snd_pcm_period_elapsed(irq_data->play_i2sbt_stream);
640ccfbb4f5SMukunda, Vijendar 		acp_reg_write((intr_flag &
641ccfbb4f5SMukunda, Vijendar 			      BIT(ACP_TO_I2S_DMA_BT_INSTANCE_CH_NUM)) << 16,
642ccfbb4f5SMukunda, Vijendar 			      acp_mmio, mmACP_EXTERNAL_INTR_STAT);
643ccfbb4f5SMukunda, Vijendar 	}
644ccfbb4f5SMukunda, Vijendar 
6457c31335aSMaruthi Srinivas Bayyavarapu 	if ((intr_flag & BIT(I2S_TO_ACP_DMA_CH_NUM)) != 0) {
6467c31335aSMaruthi Srinivas Bayyavarapu 		valid_irq = true;
647*6b116dfbSAgrawal, Akshu 		snd_pcm_period_elapsed(irq_data->capture_i2ssp_stream);
6487c31335aSMaruthi Srinivas Bayyavarapu 		acp_reg_write((intr_flag & BIT(I2S_TO_ACP_DMA_CH_NUM)) << 16,
6497c31335aSMaruthi Srinivas Bayyavarapu 			      acp_mmio, mmACP_EXTERNAL_INTR_STAT);
6507c31335aSMaruthi Srinivas Bayyavarapu 	}
6517c31335aSMaruthi Srinivas Bayyavarapu 
6527c31335aSMaruthi Srinivas Bayyavarapu 	if ((intr_flag & BIT(ACP_TO_SYSRAM_CH_NUM)) != 0) {
6537c31335aSMaruthi Srinivas Bayyavarapu 		valid_irq = true;
6547c31335aSMaruthi Srinivas Bayyavarapu 		acp_reg_write((intr_flag & BIT(ACP_TO_SYSRAM_CH_NUM)) << 16,
6557c31335aSMaruthi Srinivas Bayyavarapu 			      acp_mmio, mmACP_EXTERNAL_INTR_STAT);
6567c31335aSMaruthi Srinivas Bayyavarapu 	}
6577c31335aSMaruthi Srinivas Bayyavarapu 
658ccfbb4f5SMukunda, Vijendar 	if ((intr_flag & BIT(I2S_TO_ACP_DMA_BT_INSTANCE_CH_NUM)) != 0) {
659ccfbb4f5SMukunda, Vijendar 		valid_irq = true;
660*6b116dfbSAgrawal, Akshu 		snd_pcm_period_elapsed(irq_data->capture_i2sbt_stream);
661ccfbb4f5SMukunda, Vijendar 		acp_reg_write((intr_flag &
662ccfbb4f5SMukunda, Vijendar 			      BIT(I2S_TO_ACP_DMA_BT_INSTANCE_CH_NUM)) << 16,
663ccfbb4f5SMukunda, Vijendar 			      acp_mmio, mmACP_EXTERNAL_INTR_STAT);
664ccfbb4f5SMukunda, Vijendar 	}
665ccfbb4f5SMukunda, Vijendar 
666ccfbb4f5SMukunda, Vijendar 	if ((intr_flag & BIT(ACP_TO_SYSRAM_BT_INSTANCE_CH_NUM)) != 0) {
667ccfbb4f5SMukunda, Vijendar 		valid_irq = true;
668ccfbb4f5SMukunda, Vijendar 		acp_reg_write((intr_flag &
669ccfbb4f5SMukunda, Vijendar 			      BIT(ACP_TO_SYSRAM_BT_INSTANCE_CH_NUM)) << 16,
670ccfbb4f5SMukunda, Vijendar 			      acp_mmio, mmACP_EXTERNAL_INTR_STAT);
671ccfbb4f5SMukunda, Vijendar 	}
672ccfbb4f5SMukunda, Vijendar 
6737c31335aSMaruthi Srinivas Bayyavarapu 	if (valid_irq)
6747c31335aSMaruthi Srinivas Bayyavarapu 		return IRQ_HANDLED;
6757c31335aSMaruthi Srinivas Bayyavarapu 	else
6767c31335aSMaruthi Srinivas Bayyavarapu 		return IRQ_NONE;
6777c31335aSMaruthi Srinivas Bayyavarapu }
6787c31335aSMaruthi Srinivas Bayyavarapu 
6797c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_open(struct snd_pcm_substream *substream)
6807c31335aSMaruthi Srinivas Bayyavarapu {
681c36d9b3fSMaruthi Srinivas Bayyavarapu 	u16 bank;
6827c31335aSMaruthi Srinivas Bayyavarapu 	int ret = 0;
6837c31335aSMaruthi Srinivas Bayyavarapu 	struct snd_pcm_runtime *runtime = substream->runtime;
6847c31335aSMaruthi Srinivas Bayyavarapu 	struct snd_soc_pcm_runtime *prtd = substream->private_data;
68513838c11SMukunda, Vijendar 	struct snd_soc_component *component = snd_soc_rtdcom_lookup(prtd,
68613838c11SMukunda, Vijendar 								    DRV_NAME);
687a1042a42SKuninori Morimoto 	struct audio_drv_data *intr_data = dev_get_drvdata(component->dev);
6887c31335aSMaruthi Srinivas Bayyavarapu 	struct audio_substream_data *adata =
6897c31335aSMaruthi Srinivas Bayyavarapu 		kzalloc(sizeof(struct audio_substream_data), GFP_KERNEL);
69013838c11SMukunda, Vijendar 	if (!adata)
6917c31335aSMaruthi Srinivas Bayyavarapu 		return -ENOMEM;
6927c31335aSMaruthi Srinivas Bayyavarapu 
6939c7d6fabSVijendar Mukunda 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
6949c7d6fabSVijendar Mukunda 		switch (intr_data->asic_type) {
6959c7d6fabSVijendar Mukunda 		case CHIP_STONEY:
6969c7d6fabSVijendar Mukunda 			runtime->hw = acp_st_pcm_hardware_playback;
6979c7d6fabSVijendar Mukunda 			break;
6989c7d6fabSVijendar Mukunda 		default:
6997c31335aSMaruthi Srinivas Bayyavarapu 			runtime->hw = acp_pcm_hardware_playback;
7009c7d6fabSVijendar Mukunda 		}
7019c7d6fabSVijendar Mukunda 	} else {
7029c7d6fabSVijendar Mukunda 		switch (intr_data->asic_type) {
7039c7d6fabSVijendar Mukunda 		case CHIP_STONEY:
7049c7d6fabSVijendar Mukunda 			runtime->hw = acp_st_pcm_hardware_capture;
7059c7d6fabSVijendar Mukunda 			break;
7069c7d6fabSVijendar Mukunda 		default:
7077c31335aSMaruthi Srinivas Bayyavarapu 			runtime->hw = acp_pcm_hardware_capture;
7089c7d6fabSVijendar Mukunda 		}
7099c7d6fabSVijendar Mukunda 	}
7107c31335aSMaruthi Srinivas Bayyavarapu 
7117c31335aSMaruthi Srinivas Bayyavarapu 	ret = snd_pcm_hw_constraint_integer(runtime,
7127c31335aSMaruthi Srinivas Bayyavarapu 					    SNDRV_PCM_HW_PARAM_PERIODS);
7137c31335aSMaruthi Srinivas Bayyavarapu 	if (ret < 0) {
714a1042a42SKuninori Morimoto 		dev_err(component->dev, "set integer constraint failed\n");
715cde6bcd5SDan Carpenter 		kfree(adata);
7167c31335aSMaruthi Srinivas Bayyavarapu 		return ret;
7177c31335aSMaruthi Srinivas Bayyavarapu 	}
7187c31335aSMaruthi Srinivas Bayyavarapu 
7197c31335aSMaruthi Srinivas Bayyavarapu 	adata->acp_mmio = intr_data->acp_mmio;
7207c31335aSMaruthi Srinivas Bayyavarapu 	runtime->private_data = adata;
7217c31335aSMaruthi Srinivas Bayyavarapu 
72213838c11SMukunda, Vijendar 	/*
72313838c11SMukunda, Vijendar 	 * Enable ACP irq, when neither playback or capture streams are
7247c31335aSMaruthi Srinivas Bayyavarapu 	 * active by the time when a new stream is being opened.
7257c31335aSMaruthi Srinivas Bayyavarapu 	 * This enablement is not required for another stream, if current
7267c31335aSMaruthi Srinivas Bayyavarapu 	 * stream is not closed
7277c31335aSMaruthi Srinivas Bayyavarapu 	 */
728ccfbb4f5SMukunda, Vijendar 	if (!intr_data->play_i2ssp_stream && !intr_data->capture_i2ssp_stream &&
729ccfbb4f5SMukunda, Vijendar 	    !intr_data->play_i2sbt_stream && !intr_data->capture_i2sbt_stream)
7307c31335aSMaruthi Srinivas Bayyavarapu 		acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB);
7317c31335aSMaruthi Srinivas Bayyavarapu 
732c36d9b3fSMaruthi Srinivas Bayyavarapu 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
73313838c11SMukunda, Vijendar 		/*
73413838c11SMukunda, Vijendar 		 * For Stoney, Memory gating is disabled,i.e SRAM Banks
735607b39efSVijendar Mukunda 		 * won't be turned off. The default state for SRAM banks is ON.
736607b39efSVijendar Mukunda 		 * Setting SRAM bank state code skipped for STONEY platform.
737607b39efSVijendar Mukunda 		 */
738607b39efSVijendar Mukunda 		if (intr_data->asic_type != CHIP_STONEY) {
739c36d9b3fSMaruthi Srinivas Bayyavarapu 			for (bank = 1; bank <= 4; bank++)
740607b39efSVijendar Mukunda 				acp_set_sram_bank_state(intr_data->acp_mmio,
741607b39efSVijendar Mukunda 							bank, true);
742607b39efSVijendar Mukunda 		}
743c36d9b3fSMaruthi Srinivas Bayyavarapu 	} else {
744607b39efSVijendar Mukunda 		if (intr_data->asic_type != CHIP_STONEY) {
745c36d9b3fSMaruthi Srinivas Bayyavarapu 			for (bank = 5; bank <= 8; bank++)
746607b39efSVijendar Mukunda 				acp_set_sram_bank_state(intr_data->acp_mmio,
747607b39efSVijendar Mukunda 							bank, true);
748607b39efSVijendar Mukunda 		}
749c36d9b3fSMaruthi Srinivas Bayyavarapu 	}
7507c31335aSMaruthi Srinivas Bayyavarapu 
7517c31335aSMaruthi Srinivas Bayyavarapu 	return 0;
7527c31335aSMaruthi Srinivas Bayyavarapu }
7537c31335aSMaruthi Srinivas Bayyavarapu 
7547c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_hw_params(struct snd_pcm_substream *substream,
7557c31335aSMaruthi Srinivas Bayyavarapu 			     struct snd_pcm_hw_params *params)
7567c31335aSMaruthi Srinivas Bayyavarapu {
7577c31335aSMaruthi Srinivas Bayyavarapu 	int status;
7587c31335aSMaruthi Srinivas Bayyavarapu 	uint64_t size;
759a37d48e3SVijendar Mukunda 	u32 val = 0;
7607c31335aSMaruthi Srinivas Bayyavarapu 	struct page *pg;
7617c31335aSMaruthi Srinivas Bayyavarapu 	struct snd_pcm_runtime *runtime;
7627c31335aSMaruthi Srinivas Bayyavarapu 	struct audio_substream_data *rtd;
763aac89748SVijendar Mukunda 	struct snd_soc_pcm_runtime *prtd = substream->private_data;
76413838c11SMukunda, Vijendar 	struct snd_soc_component *component = snd_soc_rtdcom_lookup(prtd,
76513838c11SMukunda, Vijendar 								    DRV_NAME);
766a1042a42SKuninori Morimoto 	struct audio_drv_data *adata = dev_get_drvdata(component->dev);
767ccfbb4f5SMukunda, Vijendar 	struct snd_soc_card *card = prtd->card;
768ccfbb4f5SMukunda, Vijendar 	struct acp_platform_info *pinfo = snd_soc_card_get_drvdata(card);
7697c31335aSMaruthi Srinivas Bayyavarapu 
7707c31335aSMaruthi Srinivas Bayyavarapu 	runtime = substream->runtime;
7717c31335aSMaruthi Srinivas Bayyavarapu 	rtd = runtime->private_data;
7727c31335aSMaruthi Srinivas Bayyavarapu 
7737c31335aSMaruthi Srinivas Bayyavarapu 	if (WARN_ON(!rtd))
7747c31335aSMaruthi Srinivas Bayyavarapu 		return -EINVAL;
7757c31335aSMaruthi Srinivas Bayyavarapu 
776ccfbb4f5SMukunda, Vijendar 	rtd->i2s_instance = pinfo->i2s_instance;
777a37d48e3SVijendar Mukunda 	if (adata->asic_type == CHIP_STONEY) {
77813838c11SMukunda, Vijendar 		val = acp_reg_read(adata->acp_mmio,
77913838c11SMukunda, Vijendar 				   mmACP_I2S_16BIT_RESOLUTION_EN);
780ccfbb4f5SMukunda, Vijendar 		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
781ccfbb4f5SMukunda, Vijendar 			switch (rtd->i2s_instance) {
782ccfbb4f5SMukunda, Vijendar 			case I2S_BT_INSTANCE:
783ccfbb4f5SMukunda, Vijendar 				val |= ACP_I2S_BT_16BIT_RESOLUTION_EN;
784ccfbb4f5SMukunda, Vijendar 				break;
785ccfbb4f5SMukunda, Vijendar 			case I2S_SP_INSTANCE:
786ccfbb4f5SMukunda, Vijendar 			default:
787a37d48e3SVijendar Mukunda 				val |= ACP_I2S_SP_16BIT_RESOLUTION_EN;
788ccfbb4f5SMukunda, Vijendar 			}
789ccfbb4f5SMukunda, Vijendar 		} else {
790ccfbb4f5SMukunda, Vijendar 			switch (rtd->i2s_instance) {
791ccfbb4f5SMukunda, Vijendar 			case I2S_BT_INSTANCE:
792ccfbb4f5SMukunda, Vijendar 				val |= ACP_I2S_BT_16BIT_RESOLUTION_EN;
793ccfbb4f5SMukunda, Vijendar 				break;
794ccfbb4f5SMukunda, Vijendar 			case I2S_SP_INSTANCE:
795ccfbb4f5SMukunda, Vijendar 			default:
796a37d48e3SVijendar Mukunda 				val |= ACP_I2S_MIC_16BIT_RESOLUTION_EN;
797ccfbb4f5SMukunda, Vijendar 			}
798ccfbb4f5SMukunda, Vijendar 		}
79913838c11SMukunda, Vijendar 		acp_reg_write(val, adata->acp_mmio,
80013838c11SMukunda, Vijendar 			      mmACP_I2S_16BIT_RESOLUTION_EN);
801a37d48e3SVijendar Mukunda 	}
8028769bb55SVijendar Mukunda 
8038769bb55SVijendar Mukunda 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
804ccfbb4f5SMukunda, Vijendar 		switch (rtd->i2s_instance) {
805ccfbb4f5SMukunda, Vijendar 		case I2S_BT_INSTANCE:
806ccfbb4f5SMukunda, Vijendar 			rtd->pte_offset = ACP_ST_BT_PLAYBACK_PTE_OFFSET;
807ccfbb4f5SMukunda, Vijendar 			rtd->ch1 = SYSRAM_TO_ACP_BT_INSTANCE_CH_NUM;
808ccfbb4f5SMukunda, Vijendar 			rtd->ch2 = ACP_TO_I2S_DMA_BT_INSTANCE_CH_NUM;
809ccfbb4f5SMukunda, Vijendar 			rtd->sram_bank = ACP_SRAM_BANK_3_ADDRESS;
810ccfbb4f5SMukunda, Vijendar 			rtd->destination = TO_BLUETOOTH;
811ccfbb4f5SMukunda, Vijendar 			rtd->dma_dscr_idx_1 = PLAYBACK_START_DMA_DESCR_CH8;
812ccfbb4f5SMukunda, Vijendar 			rtd->dma_dscr_idx_2 = PLAYBACK_START_DMA_DESCR_CH9;
813ccfbb4f5SMukunda, Vijendar 			rtd->byte_cnt_high_reg_offset =
814ccfbb4f5SMukunda, Vijendar 					mmACP_I2S_BT_TRANSMIT_BYTE_CNT_HIGH;
815ccfbb4f5SMukunda, Vijendar 			rtd->byte_cnt_low_reg_offset =
816ccfbb4f5SMukunda, Vijendar 					mmACP_I2S_BT_TRANSMIT_BYTE_CNT_LOW;
817ccfbb4f5SMukunda, Vijendar 			adata->play_i2sbt_stream = substream;
818ccfbb4f5SMukunda, Vijendar 			break;
819ccfbb4f5SMukunda, Vijendar 		case I2S_SP_INSTANCE:
820ccfbb4f5SMukunda, Vijendar 		default:
821e188c525SMukunda, Vijendar 			switch (adata->asic_type) {
822e188c525SMukunda, Vijendar 			case CHIP_STONEY:
823e188c525SMukunda, Vijendar 				rtd->pte_offset = ACP_ST_PLAYBACK_PTE_OFFSET;
824e188c525SMukunda, Vijendar 				break;
825e188c525SMukunda, Vijendar 			default:
826e188c525SMukunda, Vijendar 				rtd->pte_offset = ACP_PLAYBACK_PTE_OFFSET;
827e188c525SMukunda, Vijendar 			}
8288769bb55SVijendar Mukunda 			rtd->ch1 = SYSRAM_TO_ACP_CH_NUM;
8298769bb55SVijendar Mukunda 			rtd->ch2 = ACP_TO_I2S_DMA_CH_NUM;
83018e8a40dSMukunda, Vijendar 			rtd->sram_bank = ACP_SRAM_BANK_1_ADDRESS;
8318769bb55SVijendar Mukunda 			rtd->destination = TO_ACP_I2S_1;
8328769bb55SVijendar Mukunda 			rtd->dma_dscr_idx_1 = PLAYBACK_START_DMA_DESCR_CH12;
8338769bb55SVijendar Mukunda 			rtd->dma_dscr_idx_2 = PLAYBACK_START_DMA_DESCR_CH13;
8347f004847SVijendar Mukunda 			rtd->byte_cnt_high_reg_offset =
8357f004847SVijendar Mukunda 					mmACP_I2S_TRANSMIT_BYTE_CNT_HIGH;
836ccfbb4f5SMukunda, Vijendar 			rtd->byte_cnt_low_reg_offset =
837ccfbb4f5SMukunda, Vijendar 					mmACP_I2S_TRANSMIT_BYTE_CNT_LOW;
838ccfbb4f5SMukunda, Vijendar 			adata->play_i2ssp_stream = substream;
839ccfbb4f5SMukunda, Vijendar 		}
8408769bb55SVijendar Mukunda 	} else {
841ccfbb4f5SMukunda, Vijendar 		switch (rtd->i2s_instance) {
842ccfbb4f5SMukunda, Vijendar 		case I2S_BT_INSTANCE:
843ccfbb4f5SMukunda, Vijendar 			rtd->pte_offset = ACP_ST_BT_CAPTURE_PTE_OFFSET;
844ccfbb4f5SMukunda, Vijendar 			rtd->ch1 = ACP_TO_SYSRAM_BT_INSTANCE_CH_NUM;
845ccfbb4f5SMukunda, Vijendar 			rtd->ch2 = I2S_TO_ACP_DMA_BT_INSTANCE_CH_NUM;
846ccfbb4f5SMukunda, Vijendar 			rtd->sram_bank = ACP_SRAM_BANK_4_ADDRESS;
847ccfbb4f5SMukunda, Vijendar 			rtd->destination = FROM_BLUETOOTH;
848ccfbb4f5SMukunda, Vijendar 			rtd->dma_dscr_idx_1 = CAPTURE_START_DMA_DESCR_CH10;
849ccfbb4f5SMukunda, Vijendar 			rtd->dma_dscr_idx_2 = CAPTURE_START_DMA_DESCR_CH11;
850ccfbb4f5SMukunda, Vijendar 			rtd->byte_cnt_high_reg_offset =
851ccfbb4f5SMukunda, Vijendar 					mmACP_I2S_BT_RECEIVE_BYTE_CNT_HIGH;
852ccfbb4f5SMukunda, Vijendar 			rtd->byte_cnt_low_reg_offset =
853ccfbb4f5SMukunda, Vijendar 					mmACP_I2S_BT_RECEIVE_BYTE_CNT_LOW;
854ccfbb4f5SMukunda, Vijendar 			adata->capture_i2sbt_stream = substream;
855ccfbb4f5SMukunda, Vijendar 			break;
856ccfbb4f5SMukunda, Vijendar 		case I2S_SP_INSTANCE:
857ccfbb4f5SMukunda, Vijendar 		default:
858ccfbb4f5SMukunda, Vijendar 			rtd->pte_offset = ACP_CAPTURE_PTE_OFFSET;
859ccfbb4f5SMukunda, Vijendar 			rtd->ch1 = ACP_TO_SYSRAM_CH_NUM;
860ccfbb4f5SMukunda, Vijendar 			rtd->ch2 = I2S_TO_ACP_DMA_CH_NUM;
861e188c525SMukunda, Vijendar 			switch (adata->asic_type) {
862e188c525SMukunda, Vijendar 			case CHIP_STONEY:
863e188c525SMukunda, Vijendar 				rtd->pte_offset = ACP_ST_CAPTURE_PTE_OFFSET;
86418e8a40dSMukunda, Vijendar 				rtd->sram_bank = ACP_SRAM_BANK_2_ADDRESS;
865e188c525SMukunda, Vijendar 				break;
866e188c525SMukunda, Vijendar 			default:
867e188c525SMukunda, Vijendar 				rtd->pte_offset = ACP_CAPTURE_PTE_OFFSET;
86818e8a40dSMukunda, Vijendar 				rtd->sram_bank = ACP_SRAM_BANK_5_ADDRESS;
869e188c525SMukunda, Vijendar 			}
8708769bb55SVijendar Mukunda 			rtd->destination = FROM_ACP_I2S_1;
8718769bb55SVijendar Mukunda 			rtd->dma_dscr_idx_1 = CAPTURE_START_DMA_DESCR_CH14;
8728769bb55SVijendar Mukunda 			rtd->dma_dscr_idx_2 = CAPTURE_START_DMA_DESCR_CH15;
8737f004847SVijendar Mukunda 			rtd->byte_cnt_high_reg_offset =
8747f004847SVijendar Mukunda 					mmACP_I2S_RECEIVED_BYTE_CNT_HIGH;
875ccfbb4f5SMukunda, Vijendar 			rtd->byte_cnt_low_reg_offset =
876ccfbb4f5SMukunda, Vijendar 					mmACP_I2S_RECEIVED_BYTE_CNT_LOW;
877ccfbb4f5SMukunda, Vijendar 			adata->capture_i2ssp_stream = substream;
878ccfbb4f5SMukunda, Vijendar 		}
8798769bb55SVijendar Mukunda 	}
8808769bb55SVijendar Mukunda 
8817c31335aSMaruthi Srinivas Bayyavarapu 	size = params_buffer_bytes(params);
8827c31335aSMaruthi Srinivas Bayyavarapu 	status = snd_pcm_lib_malloc_pages(substream, size);
8837c31335aSMaruthi Srinivas Bayyavarapu 	if (status < 0)
8847c31335aSMaruthi Srinivas Bayyavarapu 		return status;
8857c31335aSMaruthi Srinivas Bayyavarapu 
8867c31335aSMaruthi Srinivas Bayyavarapu 	memset(substream->runtime->dma_area, 0, params_buffer_bytes(params));
8877c31335aSMaruthi Srinivas Bayyavarapu 	pg = virt_to_page(substream->dma_buffer.area);
8887c31335aSMaruthi Srinivas Bayyavarapu 
88913838c11SMukunda, Vijendar 	if (pg) {
890c36d9b3fSMaruthi Srinivas Bayyavarapu 		acp_set_sram_bank_state(rtd->acp_mmio, 0, true);
8917c31335aSMaruthi Srinivas Bayyavarapu 		/* Save for runtime private data */
8927c31335aSMaruthi Srinivas Bayyavarapu 		rtd->pg = pg;
8937c31335aSMaruthi Srinivas Bayyavarapu 		rtd->order = get_order(size);
8947c31335aSMaruthi Srinivas Bayyavarapu 
8957c31335aSMaruthi Srinivas Bayyavarapu 		/* Fill the page table entries in ACP SRAM */
8967c31335aSMaruthi Srinivas Bayyavarapu 		rtd->pg = pg;
8977c31335aSMaruthi Srinivas Bayyavarapu 		rtd->size = size;
8987c31335aSMaruthi Srinivas Bayyavarapu 		rtd->num_of_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
8997c31335aSMaruthi Srinivas Bayyavarapu 		rtd->direction = substream->stream;
9007c31335aSMaruthi Srinivas Bayyavarapu 
901aac89748SVijendar Mukunda 		config_acp_dma(rtd->acp_mmio, rtd, adata->asic_type);
9027c31335aSMaruthi Srinivas Bayyavarapu 		status = 0;
9037c31335aSMaruthi Srinivas Bayyavarapu 	} else {
9047c31335aSMaruthi Srinivas Bayyavarapu 		status = -ENOMEM;
9057c31335aSMaruthi Srinivas Bayyavarapu 	}
9067c31335aSMaruthi Srinivas Bayyavarapu 	return status;
9077c31335aSMaruthi Srinivas Bayyavarapu }
9087c31335aSMaruthi Srinivas Bayyavarapu 
9097c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_hw_free(struct snd_pcm_substream *substream)
9107c31335aSMaruthi Srinivas Bayyavarapu {
9117c31335aSMaruthi Srinivas Bayyavarapu 	return snd_pcm_lib_free_pages(substream);
9127c31335aSMaruthi Srinivas Bayyavarapu }
9137c31335aSMaruthi Srinivas Bayyavarapu 
9147f004847SVijendar Mukunda static u64 acp_get_byte_count(struct audio_substream_data *rtd)
91561add814SVijendar Mukunda {
9167f004847SVijendar Mukunda 	union acp_dma_count byte_count;
91761add814SVijendar Mukunda 
9187f004847SVijendar Mukunda 	byte_count.bcount.high = acp_reg_read(rtd->acp_mmio,
9197f004847SVijendar Mukunda 					      rtd->byte_cnt_high_reg_offset);
9207f004847SVijendar Mukunda 	byte_count.bcount.low  = acp_reg_read(rtd->acp_mmio,
9217f004847SVijendar Mukunda 					      rtd->byte_cnt_low_reg_offset);
9227f004847SVijendar Mukunda 	return byte_count.bytescount;
92361add814SVijendar Mukunda }
92461add814SVijendar Mukunda 
9257c31335aSMaruthi Srinivas Bayyavarapu static snd_pcm_uframes_t acp_dma_pointer(struct snd_pcm_substream *substream)
9267c31335aSMaruthi Srinivas Bayyavarapu {
92761add814SVijendar Mukunda 	u32 buffersize;
9287c31335aSMaruthi Srinivas Bayyavarapu 	u32 pos = 0;
92961add814SVijendar Mukunda 	u64 bytescount = 0;
9307c31335aSMaruthi Srinivas Bayyavarapu 
9317c31335aSMaruthi Srinivas Bayyavarapu 	struct snd_pcm_runtime *runtime = substream->runtime;
9327c31335aSMaruthi Srinivas Bayyavarapu 	struct audio_substream_data *rtd = runtime->private_data;
9337c31335aSMaruthi Srinivas Bayyavarapu 
9347afa535eSMukunda, Vijendar 	if (!rtd)
9357afa535eSMukunda, Vijendar 		return -EINVAL;
9367afa535eSMukunda, Vijendar 
93761add814SVijendar Mukunda 	buffersize = frames_to_bytes(runtime, runtime->buffer_size);
9387f004847SVijendar Mukunda 	bytescount = acp_get_byte_count(rtd);
93961add814SVijendar Mukunda 
9409af8937eSVijendar Mukunda 	if (bytescount > rtd->bytescount)
9419af8937eSVijendar Mukunda 		bytescount -= rtd->bytescount;
9427db08b2cSGuenter Roeck 	pos = do_div(bytescount, buffersize);
9437c31335aSMaruthi Srinivas Bayyavarapu 	return bytes_to_frames(runtime, pos);
9447c31335aSMaruthi Srinivas Bayyavarapu }
9457c31335aSMaruthi Srinivas Bayyavarapu 
9467c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_mmap(struct snd_pcm_substream *substream,
9477c31335aSMaruthi Srinivas Bayyavarapu 			struct vm_area_struct *vma)
9487c31335aSMaruthi Srinivas Bayyavarapu {
9497c31335aSMaruthi Srinivas Bayyavarapu 	return snd_pcm_lib_default_mmap(substream, vma);
9507c31335aSMaruthi Srinivas Bayyavarapu }
9517c31335aSMaruthi Srinivas Bayyavarapu 
9527c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_prepare(struct snd_pcm_substream *substream)
9537c31335aSMaruthi Srinivas Bayyavarapu {
9547c31335aSMaruthi Srinivas Bayyavarapu 	struct snd_pcm_runtime *runtime = substream->runtime;
9557c31335aSMaruthi Srinivas Bayyavarapu 	struct audio_substream_data *rtd = runtime->private_data;
9567c31335aSMaruthi Srinivas Bayyavarapu 
9577afa535eSMukunda, Vijendar 	if (!rtd)
9587afa535eSMukunda, Vijendar 		return -EINVAL;
9598769bb55SVijendar Mukunda 
9608769bb55SVijendar Mukunda 	config_acp_dma_channel(rtd->acp_mmio,
9618769bb55SVijendar Mukunda 			       rtd->ch1,
9628769bb55SVijendar Mukunda 			       rtd->dma_dscr_idx_1,
9637c31335aSMaruthi Srinivas Bayyavarapu 			       NUM_DSCRS_PER_CHANNEL, 0);
9648769bb55SVijendar Mukunda 	config_acp_dma_channel(rtd->acp_mmio,
9658769bb55SVijendar Mukunda 			       rtd->ch2,
9668769bb55SVijendar Mukunda 			       rtd->dma_dscr_idx_2,
9677c31335aSMaruthi Srinivas Bayyavarapu 			       NUM_DSCRS_PER_CHANNEL, 0);
9687c31335aSMaruthi Srinivas Bayyavarapu 	return 0;
9697c31335aSMaruthi Srinivas Bayyavarapu }
9707c31335aSMaruthi Srinivas Bayyavarapu 
9717c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_trigger(struct snd_pcm_substream *substream, int cmd)
9727c31335aSMaruthi Srinivas Bayyavarapu {
9737c31335aSMaruthi Srinivas Bayyavarapu 	int ret;
97461add814SVijendar Mukunda 	u64 bytescount = 0;
9757c31335aSMaruthi Srinivas Bayyavarapu 
9767c31335aSMaruthi Srinivas Bayyavarapu 	struct snd_pcm_runtime *runtime = substream->runtime;
9777c31335aSMaruthi Srinivas Bayyavarapu 	struct audio_substream_data *rtd = runtime->private_data;
9787c31335aSMaruthi Srinivas Bayyavarapu 
9797c31335aSMaruthi Srinivas Bayyavarapu 	if (!rtd)
9807c31335aSMaruthi Srinivas Bayyavarapu 		return -EINVAL;
9817c31335aSMaruthi Srinivas Bayyavarapu 	switch (cmd) {
9827c31335aSMaruthi Srinivas Bayyavarapu 	case SNDRV_PCM_TRIGGER_START:
9837c31335aSMaruthi Srinivas Bayyavarapu 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
9847c31335aSMaruthi Srinivas Bayyavarapu 	case SNDRV_PCM_TRIGGER_RESUME:
9857f004847SVijendar Mukunda 		bytescount = acp_get_byte_count(rtd);
9869af8937eSVijendar Mukunda 		if (rtd->bytescount == 0)
9879af8937eSVijendar Mukunda 			rtd->bytescount = bytescount;
9887c31335aSMaruthi Srinivas Bayyavarapu 		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
989*6b116dfbSAgrawal, Akshu 			acp_dma_start(rtd->acp_mmio, rtd->ch1);
990*6b116dfbSAgrawal, Akshu 			acp_dma_start(rtd->acp_mmio, rtd->ch2);
991*6b116dfbSAgrawal, Akshu 		} else {
992*6b116dfbSAgrawal, Akshu 			acp_dma_start(rtd->acp_mmio, rtd->ch2);
993*6b116dfbSAgrawal, Akshu 			acp_dma_start(rtd->acp_mmio, rtd->ch1);
9947c31335aSMaruthi Srinivas Bayyavarapu 		}
9957c31335aSMaruthi Srinivas Bayyavarapu 		ret = 0;
9967c31335aSMaruthi Srinivas Bayyavarapu 		break;
9977c31335aSMaruthi Srinivas Bayyavarapu 	case SNDRV_PCM_TRIGGER_STOP:
9987c31335aSMaruthi Srinivas Bayyavarapu 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
9997c31335aSMaruthi Srinivas Bayyavarapu 	case SNDRV_PCM_TRIGGER_SUSPEND:
10008769bb55SVijendar Mukunda 		/* For playback, non circular dma should be stopped first
10018769bb55SVijendar Mukunda 		 * i.e Sysram to acp dma transfer channel(rtd->ch1) should be
10028769bb55SVijendar Mukunda 		 * stopped before stopping cirular dma which is acp sram to i2s
10038769bb55SVijendar Mukunda 		 * fifo dma transfer channel(rtd->ch2). Where as in Capture
10048769bb55SVijendar Mukunda 		 * scenario, i2s fifo to acp sram dma channel(rtd->ch2) stopped
10058769bb55SVijendar Mukunda 		 * first before stopping acp sram to sysram which is circular
10068769bb55SVijendar Mukunda 		 * dma(rtd->ch1).
10077c31335aSMaruthi Srinivas Bayyavarapu 		 */
100861add814SVijendar Mukunda 		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
10098769bb55SVijendar Mukunda 			acp_dma_stop(rtd->acp_mmio, rtd->ch1);
10108769bb55SVijendar Mukunda 			ret =  acp_dma_stop(rtd->acp_mmio, rtd->ch2);
101161add814SVijendar Mukunda 		} else {
10128769bb55SVijendar Mukunda 			acp_dma_stop(rtd->acp_mmio, rtd->ch2);
10138769bb55SVijendar Mukunda 			ret = acp_dma_stop(rtd->acp_mmio, rtd->ch1);
101461add814SVijendar Mukunda 		}
10159af8937eSVijendar Mukunda 		rtd->bytescount = 0;
10167c31335aSMaruthi Srinivas Bayyavarapu 		break;
10177c31335aSMaruthi Srinivas Bayyavarapu 	default:
10187c31335aSMaruthi Srinivas Bayyavarapu 		ret = -EINVAL;
10197c31335aSMaruthi Srinivas Bayyavarapu 	}
10207c31335aSMaruthi Srinivas Bayyavarapu 	return ret;
10217c31335aSMaruthi Srinivas Bayyavarapu }
10227c31335aSMaruthi Srinivas Bayyavarapu 
10237c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_new(struct snd_soc_pcm_runtime *rtd)
10247c31335aSMaruthi Srinivas Bayyavarapu {
10259c7d6fabSVijendar Mukunda 	int ret;
102613838c11SMukunda, Vijendar 	struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd,
102713838c11SMukunda, Vijendar 								    DRV_NAME);
1028a1042a42SKuninori Morimoto 	struct audio_drv_data *adata = dev_get_drvdata(component->dev);
10299c7d6fabSVijendar Mukunda 
10309c7d6fabSVijendar Mukunda 	switch (adata->asic_type) {
10319c7d6fabSVijendar Mukunda 	case CHIP_STONEY:
10329c7d6fabSVijendar Mukunda 		ret = snd_pcm_lib_preallocate_pages_for_all(rtd->pcm,
10339c7d6fabSVijendar Mukunda 							    SNDRV_DMA_TYPE_DEV,
10349c7d6fabSVijendar Mukunda 							    NULL, ST_MIN_BUFFER,
10359c7d6fabSVijendar Mukunda 							    ST_MAX_BUFFER);
10369c7d6fabSVijendar Mukunda 		break;
10379c7d6fabSVijendar Mukunda 	default:
10389c7d6fabSVijendar Mukunda 		ret = snd_pcm_lib_preallocate_pages_for_all(rtd->pcm,
10397c31335aSMaruthi Srinivas Bayyavarapu 							    SNDRV_DMA_TYPE_DEV,
10407c31335aSMaruthi Srinivas Bayyavarapu 							    NULL, MIN_BUFFER,
10417c31335aSMaruthi Srinivas Bayyavarapu 							    MAX_BUFFER);
10429c7d6fabSVijendar Mukunda 		break;
10439c7d6fabSVijendar Mukunda 	}
10449c7d6fabSVijendar Mukunda 	if (ret < 0)
1045a1042a42SKuninori Morimoto 		dev_err(component->dev,
10469e6a469eSColin Ian King 			"buffer preallocation failure error:%d\n", ret);
10479c7d6fabSVijendar Mukunda 	return ret;
10487c31335aSMaruthi Srinivas Bayyavarapu }
10497c31335aSMaruthi Srinivas Bayyavarapu 
10507c31335aSMaruthi Srinivas Bayyavarapu static int acp_dma_close(struct snd_pcm_substream *substream)
10517c31335aSMaruthi Srinivas Bayyavarapu {
1052c36d9b3fSMaruthi Srinivas Bayyavarapu 	u16 bank;
10537c31335aSMaruthi Srinivas Bayyavarapu 	struct snd_pcm_runtime *runtime = substream->runtime;
10547c31335aSMaruthi Srinivas Bayyavarapu 	struct audio_substream_data *rtd = runtime->private_data;
10557c31335aSMaruthi Srinivas Bayyavarapu 	struct snd_soc_pcm_runtime *prtd = substream->private_data;
105613838c11SMukunda, Vijendar 	struct snd_soc_component *component = snd_soc_rtdcom_lookup(prtd,
105713838c11SMukunda, Vijendar 								    DRV_NAME);
1058a1042a42SKuninori Morimoto 	struct audio_drv_data *adata = dev_get_drvdata(component->dev);
10597c31335aSMaruthi Srinivas Bayyavarapu 
1060c36d9b3fSMaruthi Srinivas Bayyavarapu 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1061ccfbb4f5SMukunda, Vijendar 		switch (rtd->i2s_instance) {
1062ccfbb4f5SMukunda, Vijendar 		case I2S_BT_INSTANCE:
1063ccfbb4f5SMukunda, Vijendar 			adata->play_i2sbt_stream = NULL;
1064ccfbb4f5SMukunda, Vijendar 			break;
1065ccfbb4f5SMukunda, Vijendar 		case I2S_SP_INSTANCE:
1066ccfbb4f5SMukunda, Vijendar 		default:
1067e21358c4SMukunda, Vijendar 			adata->play_i2ssp_stream = NULL;
106813838c11SMukunda, Vijendar 			/*
106913838c11SMukunda, Vijendar 			 * For Stoney, Memory gating is disabled,i.e SRAM Banks
1070ccfbb4f5SMukunda, Vijendar 			 * won't be turned off. The default state for SRAM banks
1071ccfbb4f5SMukunda, Vijendar 			 * is ON.Setting SRAM bank state code skipped for STONEY
1072ccfbb4f5SMukunda, Vijendar 			 * platform. Added condition checks for Carrizo platform
1073ccfbb4f5SMukunda, Vijendar 			 * only.
1074607b39efSVijendar Mukunda 			 */
1075607b39efSVijendar Mukunda 			if (adata->asic_type != CHIP_STONEY) {
1076c36d9b3fSMaruthi Srinivas Bayyavarapu 				for (bank = 1; bank <= 4; bank++)
1077ccfbb4f5SMukunda, Vijendar 					acp_set_sram_bank_state(adata->acp_mmio,
1078ccfbb4f5SMukunda, Vijendar 								bank, false);
1079ccfbb4f5SMukunda, Vijendar 			}
1080607b39efSVijendar Mukunda 		}
1081c36d9b3fSMaruthi Srinivas Bayyavarapu 	} else  {
1082ccfbb4f5SMukunda, Vijendar 		switch (rtd->i2s_instance) {
1083ccfbb4f5SMukunda, Vijendar 		case I2S_BT_INSTANCE:
1084ccfbb4f5SMukunda, Vijendar 			adata->capture_i2sbt_stream = NULL;
1085ccfbb4f5SMukunda, Vijendar 			break;
1086ccfbb4f5SMukunda, Vijendar 		case I2S_SP_INSTANCE:
1087ccfbb4f5SMukunda, Vijendar 		default:
1088e21358c4SMukunda, Vijendar 			adata->capture_i2ssp_stream = NULL;
1089607b39efSVijendar Mukunda 			if (adata->asic_type != CHIP_STONEY) {
1090c36d9b3fSMaruthi Srinivas Bayyavarapu 				for (bank = 5; bank <= 8; bank++)
1091ccfbb4f5SMukunda, Vijendar 					acp_set_sram_bank_state(adata->acp_mmio,
1092ccfbb4f5SMukunda, Vijendar 								bank, false);
1093ccfbb4f5SMukunda, Vijendar 			}
1094c36d9b3fSMaruthi Srinivas Bayyavarapu 		}
1095607b39efSVijendar Mukunda 	}
10967c31335aSMaruthi Srinivas Bayyavarapu 
109713838c11SMukunda, Vijendar 	/*
109813838c11SMukunda, Vijendar 	 * Disable ACP irq, when the current stream is being closed and
10997c31335aSMaruthi Srinivas Bayyavarapu 	 * another stream is also not active.
11007c31335aSMaruthi Srinivas Bayyavarapu 	 */
1101ccfbb4f5SMukunda, Vijendar 	if (!adata->play_i2ssp_stream && !adata->capture_i2ssp_stream &&
1102ccfbb4f5SMukunda, Vijendar 	    !adata->play_i2sbt_stream && !adata->capture_i2sbt_stream)
11037c31335aSMaruthi Srinivas Bayyavarapu 		acp_reg_write(0, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB);
1104cac6f597SMukunda, Vijendar 	kfree(rtd);
11057c31335aSMaruthi Srinivas Bayyavarapu 	return 0;
11067c31335aSMaruthi Srinivas Bayyavarapu }
11077c31335aSMaruthi Srinivas Bayyavarapu 
1108115c7254SJulia Lawall static const struct snd_pcm_ops acp_dma_ops = {
11097c31335aSMaruthi Srinivas Bayyavarapu 	.open = acp_dma_open,
11107c31335aSMaruthi Srinivas Bayyavarapu 	.close = acp_dma_close,
11117c31335aSMaruthi Srinivas Bayyavarapu 	.ioctl = snd_pcm_lib_ioctl,
11127c31335aSMaruthi Srinivas Bayyavarapu 	.hw_params = acp_dma_hw_params,
11137c31335aSMaruthi Srinivas Bayyavarapu 	.hw_free = acp_dma_hw_free,
11147c31335aSMaruthi Srinivas Bayyavarapu 	.trigger = acp_dma_trigger,
11157c31335aSMaruthi Srinivas Bayyavarapu 	.pointer = acp_dma_pointer,
11167c31335aSMaruthi Srinivas Bayyavarapu 	.mmap = acp_dma_mmap,
11177c31335aSMaruthi Srinivas Bayyavarapu 	.prepare = acp_dma_prepare,
11187c31335aSMaruthi Srinivas Bayyavarapu };
11197c31335aSMaruthi Srinivas Bayyavarapu 
112013838c11SMukunda, Vijendar static const struct snd_soc_component_driver acp_asoc_platform = {
1121a1042a42SKuninori Morimoto 	.name = DRV_NAME,
11227c31335aSMaruthi Srinivas Bayyavarapu 	.ops = &acp_dma_ops,
11237c31335aSMaruthi Srinivas Bayyavarapu 	.pcm_new = acp_dma_new,
11247c31335aSMaruthi Srinivas Bayyavarapu };
11257c31335aSMaruthi Srinivas Bayyavarapu 
11267c31335aSMaruthi Srinivas Bayyavarapu static int acp_audio_probe(struct platform_device *pdev)
11277c31335aSMaruthi Srinivas Bayyavarapu {
11287c31335aSMaruthi Srinivas Bayyavarapu 	int status;
11297c31335aSMaruthi Srinivas Bayyavarapu 	struct audio_drv_data *audio_drv_data;
11307c31335aSMaruthi Srinivas Bayyavarapu 	struct resource *res;
1131a1b16aaaSVijendar Mukunda 	const u32 *pdata = pdev->dev.platform_data;
11327c31335aSMaruthi Srinivas Bayyavarapu 
1133fdaa4511SGuenter Roeck 	if (!pdata) {
1134fdaa4511SGuenter Roeck 		dev_err(&pdev->dev, "Missing platform data\n");
1135fdaa4511SGuenter Roeck 		return -ENODEV;
1136fdaa4511SGuenter Roeck 	}
1137fdaa4511SGuenter Roeck 
11387c31335aSMaruthi Srinivas Bayyavarapu 	audio_drv_data = devm_kzalloc(&pdev->dev, sizeof(struct audio_drv_data),
11397c31335aSMaruthi Srinivas Bayyavarapu 				      GFP_KERNEL);
114013838c11SMukunda, Vijendar 	if (!audio_drv_data)
11417c31335aSMaruthi Srinivas Bayyavarapu 		return -ENOMEM;
11427c31335aSMaruthi Srinivas Bayyavarapu 
11437c31335aSMaruthi Srinivas Bayyavarapu 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
11447c31335aSMaruthi Srinivas Bayyavarapu 	audio_drv_data->acp_mmio = devm_ioremap_resource(&pdev->dev, res);
1145fdaa4511SGuenter Roeck 	if (IS_ERR(audio_drv_data->acp_mmio))
1146fdaa4511SGuenter Roeck 		return PTR_ERR(audio_drv_data->acp_mmio);
11477c31335aSMaruthi Srinivas Bayyavarapu 
114813838c11SMukunda, Vijendar 	/*
114913838c11SMukunda, Vijendar 	 * The following members gets populated in device 'open'
11507c31335aSMaruthi Srinivas Bayyavarapu 	 * function. Till then interrupts are disabled in 'acp_init'
11517c31335aSMaruthi Srinivas Bayyavarapu 	 * and device doesn't generate any interrupts.
11527c31335aSMaruthi Srinivas Bayyavarapu 	 */
11537c31335aSMaruthi Srinivas Bayyavarapu 
1154e21358c4SMukunda, Vijendar 	audio_drv_data->play_i2ssp_stream = NULL;
1155e21358c4SMukunda, Vijendar 	audio_drv_data->capture_i2ssp_stream = NULL;
1156ccfbb4f5SMukunda, Vijendar 	audio_drv_data->play_i2sbt_stream = NULL;
1157ccfbb4f5SMukunda, Vijendar 	audio_drv_data->capture_i2sbt_stream = NULL;
1158e21358c4SMukunda, Vijendar 
1159a1b16aaaSVijendar Mukunda 	audio_drv_data->asic_type =  *pdata;
11607c31335aSMaruthi Srinivas Bayyavarapu 
11617c31335aSMaruthi Srinivas Bayyavarapu 	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
11627c31335aSMaruthi Srinivas Bayyavarapu 	if (!res) {
11637c31335aSMaruthi Srinivas Bayyavarapu 		dev_err(&pdev->dev, "IORESOURCE_IRQ FAILED\n");
11647c31335aSMaruthi Srinivas Bayyavarapu 		return -ENODEV;
11657c31335aSMaruthi Srinivas Bayyavarapu 	}
11667c31335aSMaruthi Srinivas Bayyavarapu 
11677c31335aSMaruthi Srinivas Bayyavarapu 	status = devm_request_irq(&pdev->dev, res->start, dma_irq_handler,
11687c31335aSMaruthi Srinivas Bayyavarapu 				  0, "ACP_IRQ", &pdev->dev);
11697c31335aSMaruthi Srinivas Bayyavarapu 	if (status) {
11707c31335aSMaruthi Srinivas Bayyavarapu 		dev_err(&pdev->dev, "ACP IRQ request failed\n");
11717c31335aSMaruthi Srinivas Bayyavarapu 		return status;
11727c31335aSMaruthi Srinivas Bayyavarapu 	}
11737c31335aSMaruthi Srinivas Bayyavarapu 
11747c31335aSMaruthi Srinivas Bayyavarapu 	dev_set_drvdata(&pdev->dev, audio_drv_data);
11757c31335aSMaruthi Srinivas Bayyavarapu 
11767c31335aSMaruthi Srinivas Bayyavarapu 	/* Initialize the ACP */
11777afa535eSMukunda, Vijendar 	status = acp_init(audio_drv_data->acp_mmio, audio_drv_data->asic_type);
11787afa535eSMukunda, Vijendar 	if (status) {
11797afa535eSMukunda, Vijendar 		dev_err(&pdev->dev, "ACP Init failed status:%d\n", status);
11807afa535eSMukunda, Vijendar 		return status;
11817afa535eSMukunda, Vijendar 	}
11827c31335aSMaruthi Srinivas Bayyavarapu 
1183a1042a42SKuninori Morimoto 	status = devm_snd_soc_register_component(&pdev->dev,
1184a1042a42SKuninori Morimoto 						 &acp_asoc_platform, NULL, 0);
11857c31335aSMaruthi Srinivas Bayyavarapu 	if (status != 0) {
11867c31335aSMaruthi Srinivas Bayyavarapu 		dev_err(&pdev->dev, "Fail to register ALSA platform device\n");
11877c31335aSMaruthi Srinivas Bayyavarapu 		return status;
11887c31335aSMaruthi Srinivas Bayyavarapu 	}
11897c31335aSMaruthi Srinivas Bayyavarapu 
11901927da93SMaruthi Srinivas Bayyavarapu 	pm_runtime_set_autosuspend_delay(&pdev->dev, 10000);
11911927da93SMaruthi Srinivas Bayyavarapu 	pm_runtime_use_autosuspend(&pdev->dev);
11921927da93SMaruthi Srinivas Bayyavarapu 	pm_runtime_enable(&pdev->dev);
11931927da93SMaruthi Srinivas Bayyavarapu 
11947c31335aSMaruthi Srinivas Bayyavarapu 	return status;
11957c31335aSMaruthi Srinivas Bayyavarapu }
11967c31335aSMaruthi Srinivas Bayyavarapu 
11977c31335aSMaruthi Srinivas Bayyavarapu static int acp_audio_remove(struct platform_device *pdev)
11987c31335aSMaruthi Srinivas Bayyavarapu {
11997afa535eSMukunda, Vijendar 	int status;
12007c31335aSMaruthi Srinivas Bayyavarapu 	struct audio_drv_data *adata = dev_get_drvdata(&pdev->dev);
12017c31335aSMaruthi Srinivas Bayyavarapu 
12027afa535eSMukunda, Vijendar 	status = acp_deinit(adata->acp_mmio);
12037afa535eSMukunda, Vijendar 	if (status)
12047afa535eSMukunda, Vijendar 		dev_err(&pdev->dev, "ACP Deinit failed status:%d\n", status);
12051927da93SMaruthi Srinivas Bayyavarapu 	pm_runtime_disable(&pdev->dev);
12067c31335aSMaruthi Srinivas Bayyavarapu 
12077c31335aSMaruthi Srinivas Bayyavarapu 	return 0;
12087c31335aSMaruthi Srinivas Bayyavarapu }
12097c31335aSMaruthi Srinivas Bayyavarapu 
12101927da93SMaruthi Srinivas Bayyavarapu static int acp_pcm_resume(struct device *dev)
12111927da93SMaruthi Srinivas Bayyavarapu {
1212c36d9b3fSMaruthi Srinivas Bayyavarapu 	u16 bank;
12137afa535eSMukunda, Vijendar 	int status;
1214ccfbb4f5SMukunda, Vijendar 	struct audio_substream_data *rtd;
12151927da93SMaruthi Srinivas Bayyavarapu 	struct audio_drv_data *adata = dev_get_drvdata(dev);
12161927da93SMaruthi Srinivas Bayyavarapu 
12177afa535eSMukunda, Vijendar 	status = acp_init(adata->acp_mmio, adata->asic_type);
12187afa535eSMukunda, Vijendar 	if (status) {
12197afa535eSMukunda, Vijendar 		dev_err(dev, "ACP Init failed status:%d\n", status);
12207afa535eSMukunda, Vijendar 		return status;
12217afa535eSMukunda, Vijendar 	}
12221927da93SMaruthi Srinivas Bayyavarapu 
1223e21358c4SMukunda, Vijendar 	if (adata->play_i2ssp_stream && adata->play_i2ssp_stream->runtime) {
122413838c11SMukunda, Vijendar 		/*
122513838c11SMukunda, Vijendar 		 * For Stoney, Memory gating is disabled,i.e SRAM Banks
1226607b39efSVijendar Mukunda 		 * won't be turned off. The default state for SRAM banks is ON.
1227607b39efSVijendar Mukunda 		 * Setting SRAM bank state code skipped for STONEY platform.
1228607b39efSVijendar Mukunda 		 */
1229607b39efSVijendar Mukunda 		if (adata->asic_type != CHIP_STONEY) {
1230c36d9b3fSMaruthi Srinivas Bayyavarapu 			for (bank = 1; bank <= 4; bank++)
1231c36d9b3fSMaruthi Srinivas Bayyavarapu 				acp_set_sram_bank_state(adata->acp_mmio, bank,
1232c36d9b3fSMaruthi Srinivas Bayyavarapu 							true);
1233607b39efSVijendar Mukunda 		}
1234ccfbb4f5SMukunda, Vijendar 		rtd = adata->play_i2ssp_stream->runtime->private_data;
1235ccfbb4f5SMukunda, Vijendar 		config_acp_dma(adata->acp_mmio, rtd, adata->asic_type);
1236c36d9b3fSMaruthi Srinivas Bayyavarapu 	}
123713838c11SMukunda, Vijendar 	if (adata->capture_i2ssp_stream &&
123813838c11SMukunda, Vijendar 	    adata->capture_i2ssp_stream->runtime) {
1239607b39efSVijendar Mukunda 		if (adata->asic_type != CHIP_STONEY) {
1240c36d9b3fSMaruthi Srinivas Bayyavarapu 			for (bank = 5; bank <= 8; bank++)
1241c36d9b3fSMaruthi Srinivas Bayyavarapu 				acp_set_sram_bank_state(adata->acp_mmio, bank,
1242c36d9b3fSMaruthi Srinivas Bayyavarapu 							true);
1243607b39efSVijendar Mukunda 		}
1244ccfbb4f5SMukunda, Vijendar 		rtd =  adata->capture_i2ssp_stream->runtime->private_data;
1245ccfbb4f5SMukunda, Vijendar 		config_acp_dma(adata->acp_mmio, rtd, adata->asic_type);
1246ccfbb4f5SMukunda, Vijendar 	}
1247ccfbb4f5SMukunda, Vijendar 	if (adata->asic_type != CHIP_CARRIZO) {
1248ccfbb4f5SMukunda, Vijendar 		if (adata->play_i2sbt_stream &&
1249ccfbb4f5SMukunda, Vijendar 		    adata->play_i2sbt_stream->runtime) {
1250ccfbb4f5SMukunda, Vijendar 			rtd = adata->play_i2sbt_stream->runtime->private_data;
1251ccfbb4f5SMukunda, Vijendar 			config_acp_dma(adata->acp_mmio, rtd, adata->asic_type);
1252ccfbb4f5SMukunda, Vijendar 		}
1253ccfbb4f5SMukunda, Vijendar 		if (adata->capture_i2sbt_stream &&
1254ccfbb4f5SMukunda, Vijendar 		    adata->capture_i2sbt_stream->runtime) {
1255ccfbb4f5SMukunda, Vijendar 			rtd = adata->capture_i2sbt_stream->runtime->private_data;
1256ccfbb4f5SMukunda, Vijendar 			config_acp_dma(adata->acp_mmio, rtd, adata->asic_type);
1257ccfbb4f5SMukunda, Vijendar 		}
1258c36d9b3fSMaruthi Srinivas Bayyavarapu 	}
12591927da93SMaruthi Srinivas Bayyavarapu 	acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB);
12601927da93SMaruthi Srinivas Bayyavarapu 	return 0;
12611927da93SMaruthi Srinivas Bayyavarapu }
12621927da93SMaruthi Srinivas Bayyavarapu 
12631927da93SMaruthi Srinivas Bayyavarapu static int acp_pcm_runtime_suspend(struct device *dev)
12641927da93SMaruthi Srinivas Bayyavarapu {
12657afa535eSMukunda, Vijendar 	int status;
12661927da93SMaruthi Srinivas Bayyavarapu 	struct audio_drv_data *adata = dev_get_drvdata(dev);
12671927da93SMaruthi Srinivas Bayyavarapu 
12687afa535eSMukunda, Vijendar 	status = acp_deinit(adata->acp_mmio);
12697afa535eSMukunda, Vijendar 	if (status)
12707afa535eSMukunda, Vijendar 		dev_err(dev, "ACP Deinit failed status:%d\n", status);
12711927da93SMaruthi Srinivas Bayyavarapu 	acp_reg_write(0, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB);
12721927da93SMaruthi Srinivas Bayyavarapu 	return 0;
12731927da93SMaruthi Srinivas Bayyavarapu }
12741927da93SMaruthi Srinivas Bayyavarapu 
12751927da93SMaruthi Srinivas Bayyavarapu static int acp_pcm_runtime_resume(struct device *dev)
12761927da93SMaruthi Srinivas Bayyavarapu {
12777afa535eSMukunda, Vijendar 	int status;
12781927da93SMaruthi Srinivas Bayyavarapu 	struct audio_drv_data *adata = dev_get_drvdata(dev);
12791927da93SMaruthi Srinivas Bayyavarapu 
12807afa535eSMukunda, Vijendar 	status = acp_init(adata->acp_mmio, adata->asic_type);
12817afa535eSMukunda, Vijendar 	if (status) {
12827afa535eSMukunda, Vijendar 		dev_err(dev, "ACP Init failed status:%d\n", status);
12837afa535eSMukunda, Vijendar 		return status;
12847afa535eSMukunda, Vijendar 	}
12851927da93SMaruthi Srinivas Bayyavarapu 	acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB);
12861927da93SMaruthi Srinivas Bayyavarapu 	return 0;
12871927da93SMaruthi Srinivas Bayyavarapu }
12881927da93SMaruthi Srinivas Bayyavarapu 
12891927da93SMaruthi Srinivas Bayyavarapu static const struct dev_pm_ops acp_pm_ops = {
12901927da93SMaruthi Srinivas Bayyavarapu 	.resume = acp_pcm_resume,
12911927da93SMaruthi Srinivas Bayyavarapu 	.runtime_suspend = acp_pcm_runtime_suspend,
12921927da93SMaruthi Srinivas Bayyavarapu 	.runtime_resume = acp_pcm_runtime_resume,
12931927da93SMaruthi Srinivas Bayyavarapu };
12941927da93SMaruthi Srinivas Bayyavarapu 
12957c31335aSMaruthi Srinivas Bayyavarapu static struct platform_driver acp_dma_driver = {
12967c31335aSMaruthi Srinivas Bayyavarapu 	.probe = acp_audio_probe,
12977c31335aSMaruthi Srinivas Bayyavarapu 	.remove = acp_audio_remove,
12987c31335aSMaruthi Srinivas Bayyavarapu 	.driver = {
1299bdd2a858SAkshu Agrawal 		.name = DRV_NAME,
13001927da93SMaruthi Srinivas Bayyavarapu 		.pm = &acp_pm_ops,
13017c31335aSMaruthi Srinivas Bayyavarapu 	},
13027c31335aSMaruthi Srinivas Bayyavarapu };
13037c31335aSMaruthi Srinivas Bayyavarapu 
13047c31335aSMaruthi Srinivas Bayyavarapu module_platform_driver(acp_dma_driver);
13057c31335aSMaruthi Srinivas Bayyavarapu 
1306607b39efSVijendar Mukunda MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
13077c31335aSMaruthi Srinivas Bayyavarapu MODULE_AUTHOR("Maruthi.Bayyavarapu@amd.com");
13087c31335aSMaruthi Srinivas Bayyavarapu MODULE_DESCRIPTION("AMD ACP PCM Driver");
13097c31335aSMaruthi Srinivas Bayyavarapu MODULE_LICENSE("GPL v2");
1310bdd2a858SAkshu Agrawal MODULE_ALIAS("platform:"DRV_NAME);
1311