18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * AMD ALSA SoC PDM Driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2020 Advanced Micro Devices, Inc. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include "rn_chip_offset_byte.h" 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#define ACP_DEVS 3 118c2ecf20Sopenharmony_ci#define ACP_PHY_BASE_ADDRESS 0x1240000 128c2ecf20Sopenharmony_ci#define ACP_REG_START 0x1240000 138c2ecf20Sopenharmony_ci#define ACP_REG_END 0x1250200 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define ACP_DEVICE_ID 0x15E2 168c2ecf20Sopenharmony_ci#define ACP_POWER_ON 0x00 178c2ecf20Sopenharmony_ci#define ACP_POWER_ON_IN_PROGRESS 0x01 188c2ecf20Sopenharmony_ci#define ACP_POWER_OFF 0x02 198c2ecf20Sopenharmony_ci#define ACP_POWER_OFF_IN_PROGRESS 0x03 208c2ecf20Sopenharmony_ci#define ACP_SOFT_RESET_SOFTRESET_AUDDONE_MASK 0x00010001 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define ACP_PGFSM_CNTL_POWER_ON_MASK 0x01 238c2ecf20Sopenharmony_ci#define ACP_PGFSM_CNTL_POWER_OFF_MASK 0x00 248c2ecf20Sopenharmony_ci#define ACP_PGFSM_STATUS_MASK 0x03 258c2ecf20Sopenharmony_ci#define ACP_POWERED_ON 0x00 268c2ecf20Sopenharmony_ci#define ACP_POWER_ON_IN_PROGRESS 0x01 278c2ecf20Sopenharmony_ci#define ACP_POWERED_OFF 0x02 288c2ecf20Sopenharmony_ci#define ACP_POWER_OFF_IN_PROGRESS 0x03 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define ACP_ERROR_MASK 0x20000000 318c2ecf20Sopenharmony_ci#define ACP_EXT_INTR_STAT_CLEAR_MASK 0xFFFFFFFF 328c2ecf20Sopenharmony_ci#define PDM_DMA_STAT 0x10 338c2ecf20Sopenharmony_ci#define PDM_DMA_INTR_MASK 0x10000 348c2ecf20Sopenharmony_ci#define ACP_ERROR_STAT 29 358c2ecf20Sopenharmony_ci#define PDM_DECIMATION_FACTOR 0x2 368c2ecf20Sopenharmony_ci#define ACP_PDM_CLK_FREQ_MASK 0x07 378c2ecf20Sopenharmony_ci#define ACP_WOV_MISC_CTRL_MASK 0x10 388c2ecf20Sopenharmony_ci#define ACP_PDM_ENABLE 0x01 398c2ecf20Sopenharmony_ci#define ACP_PDM_DISABLE 0x00 408c2ecf20Sopenharmony_ci#define ACP_PDM_DMA_EN_STATUS 0x02 418c2ecf20Sopenharmony_ci#define TWO_CH 0x02 428c2ecf20Sopenharmony_ci#define DELAY_US 5 438c2ecf20Sopenharmony_ci#define ACP_COUNTER 20000 448c2ecf20Sopenharmony_ci/* time in ms for runtime suspend delay */ 458c2ecf20Sopenharmony_ci#define ACP_SUSPEND_DELAY_MS 2000 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define ACP_SRAM_PTE_OFFSET 0x02050000 488c2ecf20Sopenharmony_ci#define PAGE_SIZE_4K_ENABLE 0x2 498c2ecf20Sopenharmony_ci#define MEM_WINDOW_START 0x4000000 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#define CAPTURE_MIN_NUM_PERIODS 4 528c2ecf20Sopenharmony_ci#define CAPTURE_MAX_NUM_PERIODS 4 538c2ecf20Sopenharmony_ci#define CAPTURE_MAX_PERIOD_SIZE 8192 548c2ecf20Sopenharmony_ci#define CAPTURE_MIN_PERIOD_SIZE 4096 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define MAX_BUFFER (CAPTURE_MAX_PERIOD_SIZE * CAPTURE_MAX_NUM_PERIODS) 578c2ecf20Sopenharmony_ci#define MIN_BUFFER MAX_BUFFER 588c2ecf20Sopenharmony_ci#define ACP_DMIC_AUTO -1 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cistruct pdm_dev_data { 618c2ecf20Sopenharmony_ci u32 pdm_irq; 628c2ecf20Sopenharmony_ci void __iomem *acp_base; 638c2ecf20Sopenharmony_ci struct snd_pcm_substream *capture_stream; 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistruct pdm_stream_instance { 678c2ecf20Sopenharmony_ci u16 num_pages; 688c2ecf20Sopenharmony_ci u16 channels; 698c2ecf20Sopenharmony_ci dma_addr_t dma_addr; 708c2ecf20Sopenharmony_ci u64 bytescount; 718c2ecf20Sopenharmony_ci void __iomem *acp_base; 728c2ecf20Sopenharmony_ci}; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ciunion acp_pdm_dma_count { 758c2ecf20Sopenharmony_ci struct { 768c2ecf20Sopenharmony_ci u32 low; 778c2ecf20Sopenharmony_ci u32 high; 788c2ecf20Sopenharmony_ci } bcount; 798c2ecf20Sopenharmony_ci u64 bytescount; 808c2ecf20Sopenharmony_ci}; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_cistatic inline u32 rn_readl(void __iomem *base_addr) 838c2ecf20Sopenharmony_ci{ 848c2ecf20Sopenharmony_ci return readl(base_addr - ACP_PHY_BASE_ADDRESS); 858c2ecf20Sopenharmony_ci} 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_cistatic inline void rn_writel(u32 val, void __iomem *base_addr) 888c2ecf20Sopenharmony_ci{ 898c2ecf20Sopenharmony_ci writel(val, base_addr - ACP_PHY_BASE_ADDRESS); 908c2ecf20Sopenharmony_ci} 91