13582f9aeSSubhransu S. Prusty /*
23582f9aeSSubhransu S. Prusty  * Skylake SST DSP Support
33582f9aeSSubhransu S. Prusty  *
43582f9aeSSubhransu S. Prusty  * Copyright (C) 2014-15, Intel Corporation.
53582f9aeSSubhransu S. Prusty  *
63582f9aeSSubhransu S. Prusty  * This program is free software; you can redistribute it and/or modify
73582f9aeSSubhransu S. Prusty  * it under the terms of the GNU General Public License as version 2, as
83582f9aeSSubhransu S. Prusty  * published by the Free Software Foundation.
93582f9aeSSubhransu S. Prusty  *
103582f9aeSSubhransu S. Prusty  * This program is distributed in the hope that it will be useful, but
113582f9aeSSubhransu S. Prusty  * WITHOUT ANY WARRANTY; without even the implied warranty of
123582f9aeSSubhransu S. Prusty  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
133582f9aeSSubhransu S. Prusty  * General Public License for more details.
143582f9aeSSubhransu S. Prusty  */
153582f9aeSSubhransu S. Prusty 
163582f9aeSSubhransu S. Prusty #ifndef __SKL_SST_DSP_H__
173582f9aeSSubhransu S. Prusty #define __SKL_SST_DSP_H__
183582f9aeSSubhransu S. Prusty 
19a750ba5fSSubhransu S. Prusty #include <linux/interrupt.h>
20b6626802SSubhransu S. Prusty #include <sound/memalloc.h>
213e40a784SVinod Koul #include "skl-sst-cldma.h"
22ea6b3e94SShreyas NC #include "skl-tplg-interface.h"
23b6626802SSubhransu S. Prusty 
243e40a784SVinod Koul struct sst_dsp;
25a750ba5fSSubhransu S. Prusty struct skl_sst;
26e973e31aSSubhransu S. Prusty struct sst_dsp_device;
27e973e31aSSubhransu S. Prusty 
283582f9aeSSubhransu S. Prusty /* Intel HD Audio General DSP Registers */
293582f9aeSSubhransu S. Prusty #define SKL_ADSP_GEN_BASE		0x0
303582f9aeSSubhransu S. Prusty #define SKL_ADSP_REG_ADSPCS		(SKL_ADSP_GEN_BASE + 0x04)
313582f9aeSSubhransu S. Prusty #define SKL_ADSP_REG_ADSPIC		(SKL_ADSP_GEN_BASE + 0x08)
323582f9aeSSubhransu S. Prusty #define SKL_ADSP_REG_ADSPIS		(SKL_ADSP_GEN_BASE + 0x0C)
333582f9aeSSubhransu S. Prusty #define SKL_ADSP_REG_ADSPIC2		(SKL_ADSP_GEN_BASE + 0x10)
343582f9aeSSubhransu S. Prusty #define SKL_ADSP_REG_ADSPIS2		(SKL_ADSP_GEN_BASE + 0x14)
353582f9aeSSubhransu S. Prusty 
363582f9aeSSubhransu S. Prusty /* Intel HD Audio Inter-Processor Communication Registers */
373582f9aeSSubhransu S. Prusty #define SKL_ADSP_IPC_BASE		0x40
383582f9aeSSubhransu S. Prusty #define SKL_ADSP_REG_HIPCT		(SKL_ADSP_IPC_BASE + 0x00)
393582f9aeSSubhransu S. Prusty #define SKL_ADSP_REG_HIPCTE		(SKL_ADSP_IPC_BASE + 0x04)
403582f9aeSSubhransu S. Prusty #define SKL_ADSP_REG_HIPCI		(SKL_ADSP_IPC_BASE + 0x08)
413582f9aeSSubhransu S. Prusty #define SKL_ADSP_REG_HIPCIE		(SKL_ADSP_IPC_BASE + 0x0C)
423582f9aeSSubhransu S. Prusty #define SKL_ADSP_REG_HIPCCTL		(SKL_ADSP_IPC_BASE + 0x10)
433582f9aeSSubhransu S. Prusty 
443582f9aeSSubhransu S. Prusty /*  HIPCI */
453582f9aeSSubhransu S. Prusty #define SKL_ADSP_REG_HIPCI_BUSY		BIT(31)
463582f9aeSSubhransu S. Prusty 
473582f9aeSSubhransu S. Prusty /* HIPCIE */
483582f9aeSSubhransu S. Prusty #define SKL_ADSP_REG_HIPCIE_DONE	BIT(30)
493582f9aeSSubhransu S. Prusty 
503582f9aeSSubhransu S. Prusty /* HIPCCTL */
513582f9aeSSubhransu S. Prusty #define SKL_ADSP_REG_HIPCCTL_DONE	BIT(1)
523582f9aeSSubhransu S. Prusty #define SKL_ADSP_REG_HIPCCTL_BUSY	BIT(0)
533582f9aeSSubhransu S. Prusty 
543582f9aeSSubhransu S. Prusty /* HIPCT */
553582f9aeSSubhransu S. Prusty #define SKL_ADSP_REG_HIPCT_BUSY		BIT(31)
563582f9aeSSubhransu S. Prusty 
5739fa37d5SVinod Koul /* FW base IDs */
5839fa37d5SVinod Koul #define SKL_INSTANCE_ID			0
5939fa37d5SVinod Koul #define SKL_BASE_FW_MODULE_ID		0
6039fa37d5SVinod Koul 
613582f9aeSSubhransu S. Prusty /* Intel HD Audio SRAM Window 1 */
623582f9aeSSubhransu S. Prusty #define SKL_ADSP_SRAM1_BASE		0xA000
633582f9aeSSubhransu S. Prusty 
643582f9aeSSubhransu S. Prusty #define SKL_ADSP_MMIO_LEN		0x10000
653582f9aeSSubhransu S. Prusty 
66c99b8056SOmair M Abdullah #define SKL_ADSP_W0_STAT_SZ		0x1000
673582f9aeSSubhransu S. Prusty 
68c99b8056SOmair M Abdullah #define SKL_ADSP_W0_UP_SZ		0x1000
693582f9aeSSubhransu S. Prusty 
703582f9aeSSubhransu S. Prusty #define SKL_ADSP_W1_SZ			0x1000
713582f9aeSSubhransu S. Prusty 
72a750ba5fSSubhransu S. Prusty #define SKL_FW_STS_MASK			0xf
73a750ba5fSSubhransu S. Prusty 
74a750ba5fSSubhransu S. Prusty #define SKL_FW_INIT			0x1
75a750ba5fSSubhransu S. Prusty #define SKL_FW_RFW_START		0xf
76a750ba5fSSubhransu S. Prusty 
773582f9aeSSubhransu S. Prusty #define SKL_ADSPIC_IPC			1
783582f9aeSSubhransu S. Prusty #define SKL_ADSPIS_IPC			1
793582f9aeSSubhransu S. Prusty 
80052f103cSJayachandran B /* Core ID of core0 */
81052f103cSJayachandran B #define SKL_DSP_CORE0_ID		0
82052f103cSJayachandran B 
83052f103cSJayachandran B /* Mask for a given core index, c = 0.. number of supported cores - 1 */
84052f103cSJayachandran B #define SKL_DSP_CORE_MASK(c)		BIT(c)
85052f103cSJayachandran B 
86052f103cSJayachandran B /*
87052f103cSJayachandran B  * Core 0 mask = SKL_DSP_CORE_MASK(0); Defined separately
88052f103cSJayachandran B  * since Core0 is primary core and it is used often
89052f103cSJayachandran B  */
90052f103cSJayachandran B #define SKL_DSP_CORE0_MASK		BIT(0)
91052f103cSJayachandran B 
92052f103cSJayachandran B /*
93052f103cSJayachandran B  * Mask for a given number of cores
94052f103cSJayachandran B  * nc = number of supported cores
95052f103cSJayachandran B  */
96052f103cSJayachandran B #define SKL_DSP_CORES_MASK(nc)	GENMASK((nc - 1), 0)
97052f103cSJayachandran B 
98e973e31aSSubhransu S. Prusty /* ADSPCS - Audio DSP Control & Status */
99e973e31aSSubhransu S. Prusty 
100052f103cSJayachandran B /*
101052f103cSJayachandran B  * Core Reset - asserted high
102052f103cSJayachandran B  * CRST Mask for a given core mask pattern, cm
103052f103cSJayachandran B  */
104e973e31aSSubhransu S. Prusty #define SKL_ADSPCS_CRST_SHIFT		0
105052f103cSJayachandran B #define SKL_ADSPCS_CRST_MASK(cm)	((cm) << SKL_ADSPCS_CRST_SHIFT)
106e973e31aSSubhransu S. Prusty 
107052f103cSJayachandran B /*
108052f103cSJayachandran B  * Core run/stall - when set to '1' core is stalled
109052f103cSJayachandran B  * CSTALL Mask for a given core mask pattern, cm
110052f103cSJayachandran B  */
111e973e31aSSubhransu S. Prusty #define SKL_ADSPCS_CSTALL_SHIFT		8
112052f103cSJayachandran B #define SKL_ADSPCS_CSTALL_MASK(cm)	((cm) << SKL_ADSPCS_CSTALL_SHIFT)
113e973e31aSSubhransu S. Prusty 
114052f103cSJayachandran B /*
115052f103cSJayachandran B  * Set Power Active - when set to '1' turn cores on
116052f103cSJayachandran B  * SPA Mask for a given core mask pattern, cm
117052f103cSJayachandran B  */
118e973e31aSSubhransu S. Prusty #define SKL_ADSPCS_SPA_SHIFT		16
119052f103cSJayachandran B #define SKL_ADSPCS_SPA_MASK(cm)		((cm) << SKL_ADSPCS_SPA_SHIFT)
120e973e31aSSubhransu S. Prusty 
121052f103cSJayachandran B /*
122052f103cSJayachandran B  * Current Power Active - power status of cores, set by hardware
123052f103cSJayachandran B  * CPA Mask for a given core mask pattern, cm
124052f103cSJayachandran B  */
125e973e31aSSubhransu S. Prusty #define SKL_ADSPCS_CPA_SHIFT		24
126052f103cSJayachandran B #define SKL_ADSPCS_CPA_MASK(cm)		((cm) << SKL_ADSPCS_CPA_SHIFT)
127e973e31aSSubhransu S. Prusty 
128e973e31aSSubhransu S. Prusty enum skl_dsp_states {
129e973e31aSSubhransu S. Prusty 	SKL_DSP_RUNNING = 1,
130e973e31aSSubhransu S. Prusty 	SKL_DSP_RESET,
131e973e31aSSubhransu S. Prusty };
132e973e31aSSubhransu S. Prusty 
133e973e31aSSubhransu S. Prusty struct skl_dsp_fw_ops {
134e973e31aSSubhransu S. Prusty 	int (*load_fw)(struct sst_dsp  *ctx);
135e973e31aSSubhransu S. Prusty 	/* FW module parser/loader */
136e973e31aSSubhransu S. Prusty 	int (*parse_fw)(struct sst_dsp *ctx);
137052f103cSJayachandran B 	int (*set_state_D0)(struct sst_dsp *ctx, unsigned int core_id);
138052f103cSJayachandran B 	int (*set_state_D3)(struct sst_dsp *ctx, unsigned int core_id);
139a750ba5fSSubhransu S. Prusty 	unsigned int (*get_fw_errcode)(struct sst_dsp *ctx);
14009305da9SShreyas NC 	int (*load_mod)(struct sst_dsp *ctx, u16 mod_id, u8 *mod_name);
1416c5768b3SDharageswari R 	int (*unload_mod)(struct sst_dsp *ctx, u16 mod_id);
1426c5768b3SDharageswari R 
143e973e31aSSubhransu S. Prusty };
144e973e31aSSubhransu S. Prusty 
145b6626802SSubhransu S. Prusty struct skl_dsp_loader_ops {
14692eb4f62SJeeja KP 	int stream_tag;
14792eb4f62SJeeja KP 
148b6626802SSubhransu S. Prusty 	int (*alloc_dma_buf)(struct device *dev,
149b6626802SSubhransu S. Prusty 		struct snd_dma_buffer *dmab, size_t size);
150b6626802SSubhransu S. Prusty 	int (*free_dma_buf)(struct device *dev,
151b6626802SSubhransu S. Prusty 		struct snd_dma_buffer *dmab);
15292eb4f62SJeeja KP 	int (*prepare)(struct device *dev, unsigned int format,
15392eb4f62SJeeja KP 				unsigned int byte_size,
15492eb4f62SJeeja KP 				struct snd_dma_buffer *bufp);
15592eb4f62SJeeja KP 	int (*trigger)(struct device *dev, bool start, int stream_tag);
15692eb4f62SJeeja KP 
15792eb4f62SJeeja KP 	int (*cleanup)(struct device *dev, struct snd_dma_buffer *dmab,
15892eb4f62SJeeja KP 				 int stream_tag);
159b6626802SSubhransu S. Prusty };
160b6626802SSubhransu S. Prusty 
1616c5768b3SDharageswari R struct skl_load_module_info {
1626c5768b3SDharageswari R 	u16 mod_id;
1636c5768b3SDharageswari R 	const struct firmware *fw;
1646c5768b3SDharageswari R };
1656c5768b3SDharageswari R 
1666c5768b3SDharageswari R struct skl_module_table {
1676c5768b3SDharageswari R 	struct skl_load_module_info *mod_info;
1686c5768b3SDharageswari R 	unsigned int usage_cnt;
1696c5768b3SDharageswari R 	struct list_head list;
1706c5768b3SDharageswari R };
1716c5768b3SDharageswari R 
1723e40a784SVinod Koul void skl_cldma_process_intr(struct sst_dsp *ctx);
1733e40a784SVinod Koul void skl_cldma_int_disable(struct sst_dsp *ctx);
1743e40a784SVinod Koul int skl_cldma_prepare(struct sst_dsp *ctx);
1753e40a784SVinod Koul 
176e973e31aSSubhransu S. Prusty void skl_dsp_set_state_locked(struct sst_dsp *ctx, int state);
177e973e31aSSubhransu S. Prusty struct sst_dsp *skl_dsp_ctx_init(struct device *dev,
178e973e31aSSubhransu S. Prusty 		struct sst_dsp_device *sst_dev, int irq);
179e973e31aSSubhransu S. Prusty bool is_skl_dsp_running(struct sst_dsp *ctx);
180052f103cSJayachandran B 
181052f103cSJayachandran B unsigned int skl_dsp_get_enabled_cores(struct sst_dsp *ctx);
182052f103cSJayachandran B void skl_dsp_init_core_state(struct sst_dsp *ctx);
183052f103cSJayachandran B int skl_dsp_enable_core(struct sst_dsp *ctx, unsigned int core_mask);
184052f103cSJayachandran B int skl_dsp_disable_core(struct sst_dsp *ctx, unsigned int core_mask);
185052f103cSJayachandran B int skl_dsp_core_power_up(struct sst_dsp *ctx, unsigned int core_mask);
186052f103cSJayachandran B int skl_dsp_core_power_down(struct sst_dsp *ctx, unsigned int core_mask);
187052f103cSJayachandran B int skl_dsp_core_unset_reset_state(struct sst_dsp *ctx,
188052f103cSJayachandran B 					unsigned int core_mask);
189052f103cSJayachandran B int skl_dsp_start_core(struct sst_dsp *ctx, unsigned int core_mask);
190052f103cSJayachandran B 
191e973e31aSSubhransu S. Prusty irqreturn_t skl_dsp_sst_interrupt(int irq, void *dev_id);
192e973e31aSSubhransu S. Prusty int skl_dsp_wake(struct sst_dsp *ctx);
193e973e31aSSubhransu S. Prusty int skl_dsp_sleep(struct sst_dsp *ctx);
194e973e31aSSubhransu S. Prusty void skl_dsp_free(struct sst_dsp *dsp);
195e973e31aSSubhransu S. Prusty 
196052f103cSJayachandran B int skl_dsp_get_core(struct sst_dsp *ctx, unsigned int core_id);
197052f103cSJayachandran B int skl_dsp_put_core(struct sst_dsp *ctx, unsigned int core_id);
198052f103cSJayachandran B 
199e973e31aSSubhransu S. Prusty int skl_dsp_boot(struct sst_dsp *ctx);
200a750ba5fSSubhransu S. Prusty int skl_sst_dsp_init(struct device *dev, void __iomem *mmio_base, int irq,
201aecf6fd8SVinod Koul 		const char *fw_name, struct skl_dsp_loader_ops dsp_ops,
202aecf6fd8SVinod Koul 		struct skl_sst **dsp);
20392eb4f62SJeeja KP int bxt_sst_dsp_init(struct device *dev, void __iomem *mmio_base, int irq,
20492eb4f62SJeeja KP 		const char *fw_name, struct skl_dsp_loader_ops dsp_ops,
20592eb4f62SJeeja KP 		struct skl_sst **dsp);
20678cdbbdaSVinod Koul int skl_sst_init_fw(struct device *dev, struct skl_sst *ctx);
20778cdbbdaSVinod Koul int bxt_sst_init_fw(struct device *dev, struct skl_sst *ctx);
208a750ba5fSSubhransu S. Prusty void skl_sst_dsp_cleanup(struct device *dev, struct skl_sst *ctx);
20992eb4f62SJeeja KP void bxt_sst_dsp_cleanup(struct device *dev, struct skl_sst *ctx);
210e973e31aSSubhransu S. Prusty 
211ea6b3e94SShreyas NC int snd_skl_get_module_info(struct skl_sst *ctx, u8 *uuid,
212ea6b3e94SShreyas NC 		struct skl_dfw_module *dfw_config);
213a8e2c19eSSenthilnathan Veppur int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw,
214a8e2c19eSSenthilnathan Veppur 		unsigned int offset, int index);
215ea6b3e94SShreyas NC void skl_freeup_uuid_list(struct skl_sst *ctx);
216ea6b3e94SShreyas NC 
2176eee8726SRamesh Babu int skl_dsp_strip_extended_manifest(struct firmware *fw);
2186eee8726SRamesh Babu 
2193582f9aeSSubhransu S. Prusty #endif /*__SKL_SST_DSP_H__*/
220