blob: 0e2f113bd34222d8581198792a1ff657a314cef8 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Mark Brown2159ad932012-10-11 11:54:02 +09002/*
3 * wm_adsp.h -- Wolfson ADSP support
4 *
5 * Copyright 2012 Wolfson Microelectronics plc
6 *
7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
Mark Brown2159ad932012-10-11 11:54:02 +09008 */
9
10#ifndef __WM_ADSP_H
11#define __WM_ADSP_H
12
Simon Trimmerf6bc9092021-09-13 17:00:57 +010013#include <linux/firmware/cirrus/cs_dsp.h>
14#include <linux/firmware/cirrus/wmfw.h>
15
Mark Brown2159ad932012-10-11 11:54:02 +090016#include <sound/soc.h>
17#include <sound/soc-dapm.h>
Charles Keepax406abc92015-12-15 11:29:45 +000018#include <sound/compress_driver.h>
Mark Brown2159ad932012-10-11 11:54:02 +090019
Charles Keepax20b7f7c2016-05-13 16:45:17 +010020/* Return values for wm_adsp_compr_handle_irq */
21#define WM_ADSP_COMPR_OK 0
22#define WM_ADSP_COMPR_VOICE_TRIGGER 1
23
Charles Keepax406abc92015-12-15 11:29:45 +000024struct wm_adsp_compr;
Charles Keepax2cd19bd2015-12-15 11:29:46 +000025struct wm_adsp_compr_buf;
Richard Fitzgeraldf9f55e32015-06-11 11:32:32 +010026
Simon Trimmere1468202021-09-13 17:00:55 +010027struct wm_adsp {
28 struct cs_dsp cs_dsp;
29 const char *part;
30 const char *fwf_name;
31 struct snd_soc_component *component;
32
33 unsigned int sys_config_size;
34
35 int fw;
36
37 struct work_struct boot_work;
38
39 bool preloaded;
40 bool fatal_error;
41
42 struct list_head compr_list;
43 struct list_head buffer_list;
Mark Brown2159ad932012-10-11 11:54:02 +090044};
45
46#define WM_ADSP1(wname, num) \
Lars-Peter Clausenf9eeae92013-06-19 19:34:02 +020047 SND_SOC_DAPM_PGA_E(wname, SND_SOC_NOPM, num, 0, NULL, 0, \
48 wm_adsp1_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD)
Mark Brown2159ad932012-10-11 11:54:02 +090049
Charles Keepaxaf813a62017-01-06 14:24:41 +000050#define WM_ADSP2_PRELOAD_SWITCH(wname, num) \
51 SOC_SINGLE_EXT(wname " Preload Switch", SND_SOC_NOPM, num, 1, 0, \
52 wm_adsp2_preloader_get, wm_adsp2_preloader_put)
53
Charles Keepaxd82d7672016-01-21 17:53:02 +000054#define WM_ADSP2(wname, num, event_fn) \
Charles Keepaxaf813a62017-01-06 14:24:41 +000055 SND_SOC_DAPM_SPK(wname " Preload", NULL), \
Charles Keepax5ca7e172016-09-20 13:52:31 +010056{ .id = snd_soc_dapm_supply, .name = wname " Preloader", \
Richard Fitzgerald81ac58b2015-06-02 11:53:34 +010057 .reg = SND_SOC_NOPM, .shift = num, .event = event_fn, \
Charles Keepax57a60cc2016-09-26 10:15:24 +010058 .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD, \
Charles Keepax5ca7e172016-09-20 13:52:31 +010059 .subseq = 100, /* Ensure we run after SYSCLK supply widget */ }, \
Charles Keepax12db5ed2014-01-08 17:42:19 +000060{ .id = snd_soc_dapm_out_drv, .name = wname, \
Charles Keepax4e08d502019-03-19 11:52:12 +000061 .reg = SND_SOC_NOPM, .shift = num, .event = wm_adsp_event, \
Charles Keepax12db5ed2014-01-08 17:42:19 +000062 .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD }
Mark Brown2159ad932012-10-11 11:54:02 +090063
Richard Fitzgerald0a047f02018-08-08 17:13:38 +010064#define WM_ADSP_FW_CONTROL(dspname, num) \
65 SOC_ENUM_EXT(dspname " Firmware", wm_adsp_fw_enum[num], \
66 wm_adsp_fw_get, wm_adsp_fw_put)
67
68extern const struct soc_enum wm_adsp_fw_enum[];
Mark Brown1023dbd2013-01-11 22:58:28 +000069
Charles Keepax3809f002015-04-13 13:27:54 +010070int wm_adsp1_init(struct wm_adsp *dsp);
Richard Fitzgerald81ac58b2015-06-02 11:53:34 +010071int wm_adsp2_init(struct wm_adsp *dsp);
Richard Fitzgerald66225e92016-04-27 14:58:27 +010072void wm_adsp2_remove(struct wm_adsp *dsp);
Kuninori Morimoto0fe1daa2018-02-13 02:03:12 +000073int wm_adsp2_component_probe(struct wm_adsp *dsp, struct snd_soc_component *component);
74int wm_adsp2_component_remove(struct wm_adsp *dsp, struct snd_soc_component *component);
Wen Shi170b1e12019-03-19 11:52:13 +000075int wm_halo_init(struct wm_adsp *dsp);
76
Mark Brown2159ad932012-10-11 11:54:02 +090077int wm_adsp1_event(struct snd_soc_dapm_widget *w,
78 struct snd_kcontrol *kcontrol, int event);
Richard Fitzgeraldb9070df2019-03-19 11:52:09 +000079
Charles Keepax4e08d502019-03-19 11:52:12 +000080int wm_adsp_early_event(struct snd_soc_dapm_widget *w,
81 struct snd_kcontrol *kcontrol, int event);
Mayuresh Kulkarni51a2c942017-04-05 11:08:00 +010082
Charles Keepax01ec57a2019-07-25 17:39:29 +010083irqreturn_t wm_adsp2_bus_error(int irq, void *data);
84irqreturn_t wm_halo_bus_error(int irq, void *data);
Stuart Henderson8bc144f2019-03-19 11:52:15 +000085irqreturn_t wm_halo_wdt_expire(int irq, void *data);
Mayuresh Kulkarni51a2c942017-04-05 11:08:00 +010086
Charles Keepax4e08d502019-03-19 11:52:12 +000087int wm_adsp_event(struct snd_soc_dapm_widget *w,
88 struct snd_kcontrol *kcontrol, int event);
Mark Brown2159ad932012-10-11 11:54:02 +090089
Richard Fitzgeraldb9070df2019-03-19 11:52:09 +000090int wm_adsp2_set_dspclk(struct snd_soc_dapm_widget *w, unsigned int freq);
91
Charles Keepaxaf813a62017-01-06 14:24:41 +000092int wm_adsp2_preloader_get(struct snd_kcontrol *kcontrol,
93 struct snd_ctl_elem_value *ucontrol);
94int wm_adsp2_preloader_put(struct snd_kcontrol *kcontrol,
95 struct snd_ctl_elem_value *ucontrol);
Richard Fitzgerald0a047f02018-08-08 17:13:38 +010096int wm_adsp_fw_get(struct snd_kcontrol *kcontrol,
97 struct snd_ctl_elem_value *ucontrol);
98int wm_adsp_fw_put(struct snd_kcontrol *kcontrol,
99 struct snd_ctl_elem_value *ucontrol);
Charles Keepaxaf813a62017-01-06 14:24:41 +0000100
Charles Keepax63079b62016-11-29 10:46:21 +0000101int wm_adsp_compr_open(struct wm_adsp *dsp, struct snd_compr_stream *stream);
Kuninori Morimoto3a5ccf22020-04-20 16:08:13 +0900102int wm_adsp_compr_free(struct snd_soc_component *component,
103 struct snd_compr_stream *stream);
104int wm_adsp_compr_set_params(struct snd_soc_component *component,
105 struct snd_compr_stream *stream,
Charles Keepax63079b62016-11-29 10:46:21 +0000106 struct snd_compr_params *params);
Kuninori Morimoto3a5ccf22020-04-20 16:08:13 +0900107int wm_adsp_compr_get_caps(struct snd_soc_component *component,
108 struct snd_compr_stream *stream,
Charles Keepax63079b62016-11-29 10:46:21 +0000109 struct snd_compr_caps *caps);
Kuninori Morimoto3a5ccf22020-04-20 16:08:13 +0900110int wm_adsp_compr_trigger(struct snd_soc_component *component,
111 struct snd_compr_stream *stream, int cmd);
Charles Keepax63079b62016-11-29 10:46:21 +0000112int wm_adsp_compr_handle_irq(struct wm_adsp *dsp);
Kuninori Morimoto3a5ccf22020-04-20 16:08:13 +0900113int wm_adsp_compr_pointer(struct snd_soc_component *component,
114 struct snd_compr_stream *stream,
Charles Keepax63079b62016-11-29 10:46:21 +0000115 struct snd_compr_tstamp *tstamp);
Kuninori Morimoto3a5ccf22020-04-20 16:08:13 +0900116int wm_adsp_compr_copy(struct snd_soc_component *component,
117 struct snd_compr_stream *stream,
Charles Keepax63079b62016-11-29 10:46:21 +0000118 char __user *buf, size_t count);
Li Xueb65ccd2019-11-15 13:54:13 -0600119int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type,
120 unsigned int alg, void *buf, size_t len);
121int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,
122 unsigned int alg, void *buf, size_t len);
Charles Keepax406abc92015-12-15 11:29:45 +0000123
Mark Brown2159ad932012-10-11 11:54:02 +0900124#endif