162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright(c) 2020 Intel Corporation. All rights reserved.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Author: Cezary Rojewski <cezary.rojewski@intel.com>
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef __SND_SOC_INTEL_CATPT_REGS_H
962306a36Sopenharmony_ci#define __SND_SOC_INTEL_CATPT_REGS_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <linux/bitops.h>
1262306a36Sopenharmony_ci#include <linux/iopoll.h>
1362306a36Sopenharmony_ci#include <uapi/linux/pci_regs.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#define CATPT_SHIM_REGS_SIZE	4096
1662306a36Sopenharmony_ci#define CATPT_DMA_REGS_SIZE	1024
1762306a36Sopenharmony_ci#define CATPT_DMA_COUNT		2
1862306a36Sopenharmony_ci#define CATPT_SSP_REGS_SIZE	512
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/* DSP Shim registers */
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#define CATPT_SHIM_CS1		0x00
2362306a36Sopenharmony_ci#define CATPT_SHIM_ISC		0x18
2462306a36Sopenharmony_ci#define CATPT_SHIM_ISD		0x20
2562306a36Sopenharmony_ci#define CATPT_SHIM_IMC		0x28
2662306a36Sopenharmony_ci#define CATPT_SHIM_IMD		0x30
2762306a36Sopenharmony_ci#define CATPT_SHIM_IPCC		0x38
2862306a36Sopenharmony_ci#define CATPT_SHIM_IPCD		0x40
2962306a36Sopenharmony_ci#define CATPT_SHIM_CLKCTL	0x78
3062306a36Sopenharmony_ci#define CATPT_SHIM_CS2		0x80
3162306a36Sopenharmony_ci#define CATPT_SHIM_LTRC		0xE0
3262306a36Sopenharmony_ci#define CATPT_SHIM_HMDC		0xE8
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#define CATPT_CS_LPCS		BIT(31)
3562306a36Sopenharmony_ci#define CATPT_CS_SFCR(ssp)	BIT(27 + (ssp))
3662306a36Sopenharmony_ci#define CATPT_CS_S1IOCS		BIT(23)
3762306a36Sopenharmony_ci#define CATPT_CS_S0IOCS		BIT(21)
3862306a36Sopenharmony_ci#define CATPT_CS_PCE		BIT(15)
3962306a36Sopenharmony_ci#define CATPT_CS_SDPM(ssp)	BIT(11 + (ssp))
4062306a36Sopenharmony_ci#define CATPT_CS_STALL		BIT(10)
4162306a36Sopenharmony_ci#define CATPT_CS_DCS		GENMASK(6, 4)
4262306a36Sopenharmony_ci/* b100 DSP core & audio fabric high clock */
4362306a36Sopenharmony_ci#define CATPT_CS_DCS_HIGH	(0x4 << 4)
4462306a36Sopenharmony_ci#define CATPT_CS_SBCS(ssp)	BIT(2 + (ssp))
4562306a36Sopenharmony_ci#define CATPT_CS_RST		BIT(1)
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci#define CATPT_ISC_IPCDB		BIT(1)
4862306a36Sopenharmony_ci#define CATPT_ISC_IPCCD		BIT(0)
4962306a36Sopenharmony_ci#define CATPT_ISD_DCPWM		BIT(31)
5062306a36Sopenharmony_ci#define CATPT_ISD_IPCCB		BIT(1)
5162306a36Sopenharmony_ci#define CATPT_ISD_IPCDD		BIT(0)
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci#define CATPT_IMC_IPCDB		BIT(1)
5462306a36Sopenharmony_ci#define CATPT_IMC_IPCCD		BIT(0)
5562306a36Sopenharmony_ci#define CATPT_IMD_IPCCB		BIT(1)
5662306a36Sopenharmony_ci#define CATPT_IMD_IPCDD		BIT(0)
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci#define CATPT_IPCC_BUSY		BIT(31)
5962306a36Sopenharmony_ci#define CATPT_IPCC_DONE		BIT(30)
6062306a36Sopenharmony_ci#define CATPT_IPCD_BUSY		BIT(31)
6162306a36Sopenharmony_ci#define CATPT_IPCD_DONE		BIT(30)
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define CATPT_CLKCTL_CFCIP	BIT(31)
6462306a36Sopenharmony_ci#define CATPT_CLKCTL_SMOS	GENMASK(25, 24)
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci#define CATPT_HMDC_HDDA(e, ch)	BIT(8 * (e) + (ch))
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/* defaults to reset SHIM registers to after each power cycle */
6962306a36Sopenharmony_ci#define CATPT_CS_DEFAULT	0x8480040E
7062306a36Sopenharmony_ci#define CATPT_ISC_DEFAULT	0x0
7162306a36Sopenharmony_ci#define CATPT_ISD_DEFAULT	0x0
7262306a36Sopenharmony_ci#define CATPT_IMC_DEFAULT	0x7FFF0003
7362306a36Sopenharmony_ci#define CATPT_IMD_DEFAULT	0x7FFF0003
7462306a36Sopenharmony_ci#define CATPT_IPCC_DEFAULT	0x0
7562306a36Sopenharmony_ci#define CATPT_IPCD_DEFAULT	0x0
7662306a36Sopenharmony_ci#define CATPT_CLKCTL_DEFAULT	0x7FF
7762306a36Sopenharmony_ci#define CATPT_CS2_DEFAULT	0x0
7862306a36Sopenharmony_ci#define CATPT_LTRC_DEFAULT	0x0
7962306a36Sopenharmony_ci#define CATPT_HMDC_DEFAULT	0x0
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci/* PCI Configuration registers */
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci#define CATPT_PCI_PMCAPID	0x80
8462306a36Sopenharmony_ci#define CATPT_PCI_PMCS		(CATPT_PCI_PMCAPID + PCI_PM_CTRL)
8562306a36Sopenharmony_ci#define CATPT_PCI_VDRTCTL0	0xA0
8662306a36Sopenharmony_ci#define CATPT_PCI_VDRTCTL2	0xA8
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci#define CATPT_VDRTCTL2_DTCGE	BIT(10)
8962306a36Sopenharmony_ci#define CATPT_VDRTCTL2_DCLCGE	BIT(1)
9062306a36Sopenharmony_ci#define CATPT_VDRTCTL2_CGEALL	0xF7F
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci/* LPT PCI Configuration bits */
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci#define LPT_VDRTCTL0_DSRAMPGE(b)	BIT(16 + (b))
9562306a36Sopenharmony_ci#define LPT_VDRTCTL0_DSRAMPGE_MASK	GENMASK(31, 16)
9662306a36Sopenharmony_ci#define LPT_VDRTCTL0_ISRAMPGE(b)	BIT(6 + (b))
9762306a36Sopenharmony_ci#define LPT_VDRTCTL0_ISRAMPGE_MASK	GENMASK(15, 6)
9862306a36Sopenharmony_ci#define LPT_VDRTCTL0_D3SRAMPGD		BIT(2)
9962306a36Sopenharmony_ci#define LPT_VDRTCTL0_D3PGD		BIT(1)
10062306a36Sopenharmony_ci#define LPT_VDRTCTL0_APLLSE		BIT(0)
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci/* WPT PCI Configuration bits */
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci#define WPT_VDRTCTL0_DSRAMPGE(b)	BIT(12 + (b))
10562306a36Sopenharmony_ci#define WPT_VDRTCTL0_DSRAMPGE_MASK	GENMASK(31, 12)
10662306a36Sopenharmony_ci#define WPT_VDRTCTL0_ISRAMPGE(b)	BIT(2 + (b))
10762306a36Sopenharmony_ci#define WPT_VDRTCTL0_ISRAMPGE_MASK	GENMASK(11, 2)
10862306a36Sopenharmony_ci#define WPT_VDRTCTL0_D3SRAMPGD		BIT(1)
10962306a36Sopenharmony_ci#define WPT_VDRTCTL0_D3PGD		BIT(0)
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci#define WPT_VDRTCTL2_APLLSE		BIT(31)
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci/* defaults to reset SSP registers to after each power cycle */
11462306a36Sopenharmony_ci#define CATPT_SSC0_DEFAULT		0x0
11562306a36Sopenharmony_ci#define CATPT_SSC1_DEFAULT		0x0
11662306a36Sopenharmony_ci#define CATPT_SSS_DEFAULT		0xF004
11762306a36Sopenharmony_ci#define CATPT_SSIT_DEFAULT		0x0
11862306a36Sopenharmony_ci#define CATPT_SSD_DEFAULT		0xC43893A3
11962306a36Sopenharmony_ci#define CATPT_SSTO_DEFAULT		0x0
12062306a36Sopenharmony_ci#define CATPT_SSPSP_DEFAULT		0x0
12162306a36Sopenharmony_ci#define CATPT_SSTSA_DEFAULT		0x0
12262306a36Sopenharmony_ci#define CATPT_SSRSA_DEFAULT		0x0
12362306a36Sopenharmony_ci#define CATPT_SSTSS_DEFAULT		0x0
12462306a36Sopenharmony_ci#define CATPT_SSCR2_DEFAULT		0x0
12562306a36Sopenharmony_ci#define CATPT_SSPSP2_DEFAULT		0x0
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci/* Physically the same block, access address differs between host and dsp */
12862306a36Sopenharmony_ci#define CATPT_DSP_DRAM_OFFSET		0x400000
12962306a36Sopenharmony_ci#define catpt_to_host_offset(offset)	((offset) & ~(CATPT_DSP_DRAM_OFFSET))
13062306a36Sopenharmony_ci#define catpt_to_dsp_offset(offset)	((offset) | CATPT_DSP_DRAM_OFFSET)
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci#define CATPT_MEMBLOCK_SIZE	0x8000
13362306a36Sopenharmony_ci#define catpt_num_dram(cdev)	(hweight_long((cdev)->spec->dram_mask))
13462306a36Sopenharmony_ci#define catpt_num_iram(cdev)	(hweight_long((cdev)->spec->iram_mask))
13562306a36Sopenharmony_ci#define catpt_dram_size(cdev)	(catpt_num_dram(cdev) * CATPT_MEMBLOCK_SIZE)
13662306a36Sopenharmony_ci#define catpt_iram_size(cdev)	(catpt_num_iram(cdev) * CATPT_MEMBLOCK_SIZE)
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci/* registry I/O helpers */
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci#define catpt_shim_addr(cdev) \
14162306a36Sopenharmony_ci	((cdev)->lpe_ba + (cdev)->spec->host_shim_offset)
14262306a36Sopenharmony_ci#define catpt_dma_addr(cdev, dma) \
14362306a36Sopenharmony_ci	((cdev)->lpe_ba + (cdev)->spec->host_dma_offset[dma])
14462306a36Sopenharmony_ci#define catpt_ssp_addr(cdev, ssp) \
14562306a36Sopenharmony_ci	((cdev)->lpe_ba + (cdev)->spec->host_ssp_offset[ssp])
14662306a36Sopenharmony_ci#define catpt_inbox_addr(cdev) \
14762306a36Sopenharmony_ci	((cdev)->lpe_ba + (cdev)->ipc.config.inbox_offset)
14862306a36Sopenharmony_ci#define catpt_outbox_addr(cdev) \
14962306a36Sopenharmony_ci	((cdev)->lpe_ba + (cdev)->ipc.config.outbox_offset)
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci#define catpt_writel_ssp(cdev, ssp, reg, val) \
15262306a36Sopenharmony_ci	writel(val, catpt_ssp_addr(cdev, ssp) + (reg))
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci#define catpt_readl_shim(cdev, reg) \
15562306a36Sopenharmony_ci	readl(catpt_shim_addr(cdev) + CATPT_SHIM_##reg)
15662306a36Sopenharmony_ci#define catpt_writel_shim(cdev, reg, val) \
15762306a36Sopenharmony_ci	writel(val, catpt_shim_addr(cdev) + CATPT_SHIM_##reg)
15862306a36Sopenharmony_ci#define catpt_updatel_shim(cdev, reg, mask, val) \
15962306a36Sopenharmony_ci	catpt_writel_shim(cdev, reg, \
16062306a36Sopenharmony_ci			  (catpt_readl_shim(cdev, reg) & ~(mask)) | (val))
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ci#define catpt_readl_poll_shim(cdev, reg, val, cond, delay_us, timeout_us) \
16362306a36Sopenharmony_ci	readl_poll_timeout(catpt_shim_addr(cdev) + CATPT_SHIM_##reg, \
16462306a36Sopenharmony_ci			   val, cond, delay_us, timeout_us)
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci#define catpt_readl_pci(cdev, reg) \
16762306a36Sopenharmony_ci	readl(cdev->pci_ba + CATPT_PCI_##reg)
16862306a36Sopenharmony_ci#define catpt_writel_pci(cdev, reg, val) \
16962306a36Sopenharmony_ci	writel(val, cdev->pci_ba + CATPT_PCI_##reg)
17062306a36Sopenharmony_ci#define catpt_updatel_pci(cdev, reg, mask, val) \
17162306a36Sopenharmony_ci	catpt_writel_pci(cdev, reg, \
17262306a36Sopenharmony_ci			 (catpt_readl_pci(cdev, reg) & ~(mask)) | (val))
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci#define catpt_readl_poll_pci(cdev, reg, val, cond, delay_us, timeout_us) \
17562306a36Sopenharmony_ci	readl_poll_timeout((cdev)->pci_ba + CATPT_PCI_##reg, \
17662306a36Sopenharmony_ci			   val, cond, delay_us, timeout_us)
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci#endif
179