18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Skylake SST DSP Support
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2014-15, Intel Corporation.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef __SKL_SST_DSP_H__
98c2ecf20Sopenharmony_ci#define __SKL_SST_DSP_H__
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
128c2ecf20Sopenharmony_ci#include <linux/uuid.h>
138c2ecf20Sopenharmony_ci#include <linux/firmware.h>
148c2ecf20Sopenharmony_ci#include <sound/memalloc.h>
158c2ecf20Sopenharmony_ci#include "skl-sst-cldma.h"
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistruct sst_dsp;
188c2ecf20Sopenharmony_cistruct sst_dsp_device;
198c2ecf20Sopenharmony_cistruct skl_lib_info;
208c2ecf20Sopenharmony_cistruct skl_dev;
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/* Intel HD Audio General DSP Registers */
238c2ecf20Sopenharmony_ci#define SKL_ADSP_GEN_BASE		0x0
248c2ecf20Sopenharmony_ci#define SKL_ADSP_REG_ADSPCS		(SKL_ADSP_GEN_BASE + 0x04)
258c2ecf20Sopenharmony_ci#define SKL_ADSP_REG_ADSPIC		(SKL_ADSP_GEN_BASE + 0x08)
268c2ecf20Sopenharmony_ci#define SKL_ADSP_REG_ADSPIS		(SKL_ADSP_GEN_BASE + 0x0C)
278c2ecf20Sopenharmony_ci#define SKL_ADSP_REG_ADSPIC2		(SKL_ADSP_GEN_BASE + 0x10)
288c2ecf20Sopenharmony_ci#define SKL_ADSP_REG_ADSPIS2		(SKL_ADSP_GEN_BASE + 0x14)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* Intel HD Audio Inter-Processor Communication Registers */
318c2ecf20Sopenharmony_ci#define SKL_ADSP_IPC_BASE		0x40
328c2ecf20Sopenharmony_ci#define SKL_ADSP_REG_HIPCT		(SKL_ADSP_IPC_BASE + 0x00)
338c2ecf20Sopenharmony_ci#define SKL_ADSP_REG_HIPCTE		(SKL_ADSP_IPC_BASE + 0x04)
348c2ecf20Sopenharmony_ci#define SKL_ADSP_REG_HIPCI		(SKL_ADSP_IPC_BASE + 0x08)
358c2ecf20Sopenharmony_ci#define SKL_ADSP_REG_HIPCIE		(SKL_ADSP_IPC_BASE + 0x0C)
368c2ecf20Sopenharmony_ci#define SKL_ADSP_REG_HIPCCTL		(SKL_ADSP_IPC_BASE + 0x10)
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/*  HIPCI */
398c2ecf20Sopenharmony_ci#define SKL_ADSP_REG_HIPCI_BUSY		BIT(31)
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/* HIPCIE */
428c2ecf20Sopenharmony_ci#define SKL_ADSP_REG_HIPCIE_DONE	BIT(30)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/* HIPCCTL */
458c2ecf20Sopenharmony_ci#define SKL_ADSP_REG_HIPCCTL_DONE	BIT(1)
468c2ecf20Sopenharmony_ci#define SKL_ADSP_REG_HIPCCTL_BUSY	BIT(0)
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* HIPCT */
498c2ecf20Sopenharmony_ci#define SKL_ADSP_REG_HIPCT_BUSY		BIT(31)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/* FW base IDs */
528c2ecf20Sopenharmony_ci#define SKL_INSTANCE_ID			0
538c2ecf20Sopenharmony_ci#define SKL_BASE_FW_MODULE_ID		0
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/* Intel HD Audio SRAM Window 1 */
568c2ecf20Sopenharmony_ci#define SKL_ADSP_SRAM1_BASE		0xA000
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#define SKL_ADSP_MMIO_LEN		0x10000
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define SKL_ADSP_W0_STAT_SZ		0x1000
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#define SKL_ADSP_W0_UP_SZ		0x1000
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#define SKL_ADSP_W1_SZ			0x1000
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define SKL_FW_STS_MASK			0xf
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#define SKL_FW_INIT			0x1
698c2ecf20Sopenharmony_ci#define SKL_FW_RFW_START		0xf
708c2ecf20Sopenharmony_ci#define BXT_FW_ROM_INIT_RETRY		3
718c2ecf20Sopenharmony_ci#define BXT_INIT_TIMEOUT		300
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#define SKL_ADSPIC_IPC			1
748c2ecf20Sopenharmony_ci#define SKL_ADSPIS_IPC			1
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci/* Core ID of core0 */
778c2ecf20Sopenharmony_ci#define SKL_DSP_CORE0_ID		0
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci/* Mask for a given core index, c = 0.. number of supported cores - 1 */
808c2ecf20Sopenharmony_ci#define SKL_DSP_CORE_MASK(c)		BIT(c)
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci/*
838c2ecf20Sopenharmony_ci * Core 0 mask = SKL_DSP_CORE_MASK(0); Defined separately
848c2ecf20Sopenharmony_ci * since Core0 is primary core and it is used often
858c2ecf20Sopenharmony_ci */
868c2ecf20Sopenharmony_ci#define SKL_DSP_CORE0_MASK		BIT(0)
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/*
898c2ecf20Sopenharmony_ci * Mask for a given number of cores
908c2ecf20Sopenharmony_ci * nc = number of supported cores
918c2ecf20Sopenharmony_ci */
928c2ecf20Sopenharmony_ci#define SKL_DSP_CORES_MASK(nc)	GENMASK((nc - 1), 0)
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/* ADSPCS - Audio DSP Control & Status */
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/*
978c2ecf20Sopenharmony_ci * Core Reset - asserted high
988c2ecf20Sopenharmony_ci * CRST Mask for a given core mask pattern, cm
998c2ecf20Sopenharmony_ci */
1008c2ecf20Sopenharmony_ci#define SKL_ADSPCS_CRST_SHIFT		0
1018c2ecf20Sopenharmony_ci#define SKL_ADSPCS_CRST_MASK(cm)	((cm) << SKL_ADSPCS_CRST_SHIFT)
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/*
1048c2ecf20Sopenharmony_ci * Core run/stall - when set to '1' core is stalled
1058c2ecf20Sopenharmony_ci * CSTALL Mask for a given core mask pattern, cm
1068c2ecf20Sopenharmony_ci */
1078c2ecf20Sopenharmony_ci#define SKL_ADSPCS_CSTALL_SHIFT		8
1088c2ecf20Sopenharmony_ci#define SKL_ADSPCS_CSTALL_MASK(cm)	((cm) << SKL_ADSPCS_CSTALL_SHIFT)
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci/*
1118c2ecf20Sopenharmony_ci * Set Power Active - when set to '1' turn cores on
1128c2ecf20Sopenharmony_ci * SPA Mask for a given core mask pattern, cm
1138c2ecf20Sopenharmony_ci */
1148c2ecf20Sopenharmony_ci#define SKL_ADSPCS_SPA_SHIFT		16
1158c2ecf20Sopenharmony_ci#define SKL_ADSPCS_SPA_MASK(cm)		((cm) << SKL_ADSPCS_SPA_SHIFT)
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci/*
1188c2ecf20Sopenharmony_ci * Current Power Active - power status of cores, set by hardware
1198c2ecf20Sopenharmony_ci * CPA Mask for a given core mask pattern, cm
1208c2ecf20Sopenharmony_ci */
1218c2ecf20Sopenharmony_ci#define SKL_ADSPCS_CPA_SHIFT		24
1228c2ecf20Sopenharmony_ci#define SKL_ADSPCS_CPA_MASK(cm)		((cm) << SKL_ADSPCS_CPA_SHIFT)
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci/* DSP Core state */
1258c2ecf20Sopenharmony_cienum skl_dsp_states {
1268c2ecf20Sopenharmony_ci	SKL_DSP_RUNNING = 1,
1278c2ecf20Sopenharmony_ci	/* Running in D0i3 state; can be in streaming or non-streaming D0i3 */
1288c2ecf20Sopenharmony_ci	SKL_DSP_RUNNING_D0I3, /* Running in D0i3 state*/
1298c2ecf20Sopenharmony_ci	SKL_DSP_RESET,
1308c2ecf20Sopenharmony_ci};
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci/* D0i3 substates */
1338c2ecf20Sopenharmony_cienum skl_dsp_d0i3_states {
1348c2ecf20Sopenharmony_ci	SKL_DSP_D0I3_NONE = -1, /* No D0i3 */
1358c2ecf20Sopenharmony_ci	SKL_DSP_D0I3_NON_STREAMING = 0,
1368c2ecf20Sopenharmony_ci	SKL_DSP_D0I3_STREAMING = 1,
1378c2ecf20Sopenharmony_ci};
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_cistruct skl_dsp_fw_ops {
1408c2ecf20Sopenharmony_ci	int (*load_fw)(struct sst_dsp  *ctx);
1418c2ecf20Sopenharmony_ci	/* FW module parser/loader */
1428c2ecf20Sopenharmony_ci	int (*load_library)(struct sst_dsp *ctx,
1438c2ecf20Sopenharmony_ci		struct skl_lib_info *linfo, int lib_count);
1448c2ecf20Sopenharmony_ci	int (*parse_fw)(struct sst_dsp *ctx);
1458c2ecf20Sopenharmony_ci	int (*set_state_D0)(struct sst_dsp *ctx, unsigned int core_id);
1468c2ecf20Sopenharmony_ci	int (*set_state_D3)(struct sst_dsp *ctx, unsigned int core_id);
1478c2ecf20Sopenharmony_ci	int (*set_state_D0i3)(struct sst_dsp *ctx);
1488c2ecf20Sopenharmony_ci	int (*set_state_D0i0)(struct sst_dsp *ctx);
1498c2ecf20Sopenharmony_ci	unsigned int (*get_fw_errcode)(struct sst_dsp *ctx);
1508c2ecf20Sopenharmony_ci	int (*load_mod)(struct sst_dsp *ctx, u16 mod_id, u8 *mod_name);
1518c2ecf20Sopenharmony_ci	int (*unload_mod)(struct sst_dsp *ctx, u16 mod_id);
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci};
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_cistruct skl_dsp_loader_ops {
1568c2ecf20Sopenharmony_ci	int stream_tag;
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci	int (*alloc_dma_buf)(struct device *dev,
1598c2ecf20Sopenharmony_ci		struct snd_dma_buffer *dmab, size_t size);
1608c2ecf20Sopenharmony_ci	int (*free_dma_buf)(struct device *dev,
1618c2ecf20Sopenharmony_ci		struct snd_dma_buffer *dmab);
1628c2ecf20Sopenharmony_ci	int (*prepare)(struct device *dev, unsigned int format,
1638c2ecf20Sopenharmony_ci				unsigned int byte_size,
1648c2ecf20Sopenharmony_ci				struct snd_dma_buffer *bufp);
1658c2ecf20Sopenharmony_ci	int (*trigger)(struct device *dev, bool start, int stream_tag);
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci	int (*cleanup)(struct device *dev, struct snd_dma_buffer *dmab,
1688c2ecf20Sopenharmony_ci				 int stream_tag);
1698c2ecf20Sopenharmony_ci};
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci#define MAX_INSTANCE_BUFF 2
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_cistruct uuid_module {
1748c2ecf20Sopenharmony_ci	guid_t uuid;
1758c2ecf20Sopenharmony_ci	int id;
1768c2ecf20Sopenharmony_ci	int is_loadable;
1778c2ecf20Sopenharmony_ci	int max_instance;
1788c2ecf20Sopenharmony_ci	u64 pvt_id[MAX_INSTANCE_BUFF];
1798c2ecf20Sopenharmony_ci	int *instance_id;
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci	struct list_head list;
1828c2ecf20Sopenharmony_ci};
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_cistruct skl_load_module_info {
1858c2ecf20Sopenharmony_ci	u16 mod_id;
1868c2ecf20Sopenharmony_ci	const struct firmware *fw;
1878c2ecf20Sopenharmony_ci};
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_cistruct skl_module_table {
1908c2ecf20Sopenharmony_ci	struct skl_load_module_info *mod_info;
1918c2ecf20Sopenharmony_ci	unsigned int usage_cnt;
1928c2ecf20Sopenharmony_ci	struct list_head list;
1938c2ecf20Sopenharmony_ci};
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_civoid skl_cldma_process_intr(struct sst_dsp *ctx);
1968c2ecf20Sopenharmony_civoid skl_cldma_int_disable(struct sst_dsp *ctx);
1978c2ecf20Sopenharmony_ciint skl_cldma_prepare(struct sst_dsp *ctx);
1988c2ecf20Sopenharmony_ciint skl_cldma_wait_interruptible(struct sst_dsp *ctx);
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_civoid skl_dsp_set_state_locked(struct sst_dsp *ctx, int state);
2018c2ecf20Sopenharmony_cistruct sst_dsp *skl_dsp_ctx_init(struct device *dev,
2028c2ecf20Sopenharmony_ci		struct sst_dsp_device *sst_dev, int irq);
2038c2ecf20Sopenharmony_ciint skl_dsp_acquire_irq(struct sst_dsp *sst);
2048c2ecf20Sopenharmony_cibool is_skl_dsp_running(struct sst_dsp *ctx);
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ciunsigned int skl_dsp_get_enabled_cores(struct sst_dsp *ctx);
2078c2ecf20Sopenharmony_civoid skl_dsp_init_core_state(struct sst_dsp *ctx);
2088c2ecf20Sopenharmony_ciint skl_dsp_enable_core(struct sst_dsp *ctx, unsigned int core_mask);
2098c2ecf20Sopenharmony_ciint skl_dsp_disable_core(struct sst_dsp *ctx, unsigned int core_mask);
2108c2ecf20Sopenharmony_ciint skl_dsp_core_power_up(struct sst_dsp *ctx, unsigned int core_mask);
2118c2ecf20Sopenharmony_ciint skl_dsp_core_power_down(struct sst_dsp *ctx, unsigned int core_mask);
2128c2ecf20Sopenharmony_ciint skl_dsp_core_unset_reset_state(struct sst_dsp *ctx,
2138c2ecf20Sopenharmony_ci					unsigned int core_mask);
2148c2ecf20Sopenharmony_ciint skl_dsp_start_core(struct sst_dsp *ctx, unsigned int core_mask);
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ciirqreturn_t skl_dsp_sst_interrupt(int irq, void *dev_id);
2178c2ecf20Sopenharmony_ciint skl_dsp_wake(struct sst_dsp *ctx);
2188c2ecf20Sopenharmony_ciint skl_dsp_sleep(struct sst_dsp *ctx);
2198c2ecf20Sopenharmony_civoid skl_dsp_free(struct sst_dsp *dsp);
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ciint skl_dsp_get_core(struct sst_dsp *ctx, unsigned int core_id);
2228c2ecf20Sopenharmony_ciint skl_dsp_put_core(struct sst_dsp *ctx, unsigned int core_id);
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ciint skl_dsp_boot(struct sst_dsp *ctx);
2258c2ecf20Sopenharmony_ciint skl_sst_dsp_init(struct device *dev, void __iomem *mmio_base, int irq,
2268c2ecf20Sopenharmony_ci		const char *fw_name, struct skl_dsp_loader_ops dsp_ops,
2278c2ecf20Sopenharmony_ci		struct skl_dev **dsp);
2288c2ecf20Sopenharmony_ciint bxt_sst_dsp_init(struct device *dev, void __iomem *mmio_base, int irq,
2298c2ecf20Sopenharmony_ci		const char *fw_name, struct skl_dsp_loader_ops dsp_ops,
2308c2ecf20Sopenharmony_ci		struct skl_dev **dsp);
2318c2ecf20Sopenharmony_ciint skl_sst_init_fw(struct device *dev, struct skl_dev *skl);
2328c2ecf20Sopenharmony_ciint bxt_sst_init_fw(struct device *dev, struct skl_dev *skl);
2338c2ecf20Sopenharmony_civoid skl_sst_dsp_cleanup(struct device *dev, struct skl_dev *skl);
2348c2ecf20Sopenharmony_civoid bxt_sst_dsp_cleanup(struct device *dev, struct skl_dev *skl);
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ciint snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw,
2378c2ecf20Sopenharmony_ci				unsigned int offset, int index);
2388c2ecf20Sopenharmony_ciint skl_get_pvt_id(struct skl_dev *skl, guid_t *uuid_mod, int instance_id);
2398c2ecf20Sopenharmony_ciint skl_put_pvt_id(struct skl_dev *skl, guid_t *uuid_mod, int *pvt_id);
2408c2ecf20Sopenharmony_ciint skl_get_pvt_instance_id_map(struct skl_dev *skl,
2418c2ecf20Sopenharmony_ci				int module_id, int instance_id);
2428c2ecf20Sopenharmony_civoid skl_freeup_uuid_list(struct skl_dev *skl);
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ciint skl_dsp_strip_extended_manifest(struct firmware *fw);
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_civoid skl_dsp_set_astate_cfg(struct skl_dev *skl, u32 cnt, void *data);
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ciint skl_sst_ctx_init(struct device *dev, int irq, const char *fw_name,
2498c2ecf20Sopenharmony_ci		struct skl_dsp_loader_ops dsp_ops, struct skl_dev **dsp,
2508c2ecf20Sopenharmony_ci		struct sst_dsp_device *skl_dev);
2518c2ecf20Sopenharmony_ciint skl_prepare_lib_load(struct skl_dev *skl, struct skl_lib_info *linfo,
2528c2ecf20Sopenharmony_ci			struct firmware *stripped_fw,
2538c2ecf20Sopenharmony_ci			unsigned int hdr_offset, int index);
2548c2ecf20Sopenharmony_civoid skl_release_library(struct skl_lib_info *linfo, int lib_count);
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci#endif /*__SKL_SST_DSP_H__*/
257