Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Mark Brown | 2159ad93 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2 | /* |
| 3 | * wm_adsp.h -- Wolfson ADSP support |
| 4 | * |
| 5 | * Copyright 2012 Wolfson Microelectronics plc |
| 6 | * |
| 7 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
Mark Brown | 2159ad93 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #ifndef __WM_ADSP_H |
| 11 | #define __WM_ADSP_H |
| 12 | |
Simon Trimmer | f6bc909 | 2021-09-13 17:00:57 +0100 | [diff] [blame] | 13 | #include <linux/firmware/cirrus/cs_dsp.h> |
| 14 | #include <linux/firmware/cirrus/wmfw.h> |
| 15 | |
Mark Brown | 2159ad93 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 16 | #include <sound/soc.h> |
| 17 | #include <sound/soc-dapm.h> |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 18 | #include <sound/compress_driver.h> |
Mark Brown | 2159ad93 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 19 | |
Charles Keepax | 20b7f7c | 2016-05-13 16:45:17 +0100 | [diff] [blame] | 20 | /* 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 Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 24 | struct wm_adsp_compr; |
Charles Keepax | 2cd19bd | 2015-12-15 11:29:46 +0000 | [diff] [blame] | 25 | struct wm_adsp_compr_buf; |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 26 | |
Simon Trimmer | e146820 | 2021-09-13 17:00:55 +0100 | [diff] [blame] | 27 | struct 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 Brown | 2159ad93 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | #define WM_ADSP1(wname, num) \ |
Lars-Peter Clausen | f9eeae9 | 2013-06-19 19:34:02 +0200 | [diff] [blame] | 47 | 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 Brown | 2159ad93 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 49 | |
Charles Keepax | af813a6 | 2017-01-06 14:24:41 +0000 | [diff] [blame] | 50 | #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 Keepax | d82d767 | 2016-01-21 17:53:02 +0000 | [diff] [blame] | 54 | #define WM_ADSP2(wname, num, event_fn) \ |
Charles Keepax | af813a6 | 2017-01-06 14:24:41 +0000 | [diff] [blame] | 55 | SND_SOC_DAPM_SPK(wname " Preload", NULL), \ |
Charles Keepax | 5ca7e17 | 2016-09-20 13:52:31 +0100 | [diff] [blame] | 56 | { .id = snd_soc_dapm_supply, .name = wname " Preloader", \ |
Richard Fitzgerald | 81ac58b | 2015-06-02 11:53:34 +0100 | [diff] [blame] | 57 | .reg = SND_SOC_NOPM, .shift = num, .event = event_fn, \ |
Charles Keepax | 57a60cc | 2016-09-26 10:15:24 +0100 | [diff] [blame] | 58 | .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD, \ |
Charles Keepax | 5ca7e17 | 2016-09-20 13:52:31 +0100 | [diff] [blame] | 59 | .subseq = 100, /* Ensure we run after SYSCLK supply widget */ }, \ |
Charles Keepax | 12db5ed | 2014-01-08 17:42:19 +0000 | [diff] [blame] | 60 | { .id = snd_soc_dapm_out_drv, .name = wname, \ |
Charles Keepax | 4e08d50 | 2019-03-19 11:52:12 +0000 | [diff] [blame] | 61 | .reg = SND_SOC_NOPM, .shift = num, .event = wm_adsp_event, \ |
Charles Keepax | 12db5ed | 2014-01-08 17:42:19 +0000 | [diff] [blame] | 62 | .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD } |
Mark Brown | 2159ad93 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 63 | |
Richard Fitzgerald | 0a047f0 | 2018-08-08 17:13:38 +0100 | [diff] [blame] | 64 | #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 | |
| 68 | extern const struct soc_enum wm_adsp_fw_enum[]; |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 69 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 70 | int wm_adsp1_init(struct wm_adsp *dsp); |
Richard Fitzgerald | 81ac58b | 2015-06-02 11:53:34 +0100 | [diff] [blame] | 71 | int wm_adsp2_init(struct wm_adsp *dsp); |
Richard Fitzgerald | 66225e9 | 2016-04-27 14:58:27 +0100 | [diff] [blame] | 72 | void wm_adsp2_remove(struct wm_adsp *dsp); |
Kuninori Morimoto | 0fe1daa | 2018-02-13 02:03:12 +0000 | [diff] [blame] | 73 | int wm_adsp2_component_probe(struct wm_adsp *dsp, struct snd_soc_component *component); |
| 74 | int wm_adsp2_component_remove(struct wm_adsp *dsp, struct snd_soc_component *component); |
Wen Shi | 170b1e1 | 2019-03-19 11:52:13 +0000 | [diff] [blame] | 75 | int wm_halo_init(struct wm_adsp *dsp); |
| 76 | |
Mark Brown | 2159ad93 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 77 | int wm_adsp1_event(struct snd_soc_dapm_widget *w, |
| 78 | struct snd_kcontrol *kcontrol, int event); |
Richard Fitzgerald | b9070df | 2019-03-19 11:52:09 +0000 | [diff] [blame] | 79 | |
Charles Keepax | 4e08d50 | 2019-03-19 11:52:12 +0000 | [diff] [blame] | 80 | int wm_adsp_early_event(struct snd_soc_dapm_widget *w, |
| 81 | struct snd_kcontrol *kcontrol, int event); |
Mayuresh Kulkarni | 51a2c94 | 2017-04-05 11:08:00 +0100 | [diff] [blame] | 82 | |
Charles Keepax | 01ec57a | 2019-07-25 17:39:29 +0100 | [diff] [blame] | 83 | irqreturn_t wm_adsp2_bus_error(int irq, void *data); |
| 84 | irqreturn_t wm_halo_bus_error(int irq, void *data); |
Stuart Henderson | 8bc144f | 2019-03-19 11:52:15 +0000 | [diff] [blame] | 85 | irqreturn_t wm_halo_wdt_expire(int irq, void *data); |
Mayuresh Kulkarni | 51a2c94 | 2017-04-05 11:08:00 +0100 | [diff] [blame] | 86 | |
Charles Keepax | 4e08d50 | 2019-03-19 11:52:12 +0000 | [diff] [blame] | 87 | int wm_adsp_event(struct snd_soc_dapm_widget *w, |
| 88 | struct snd_kcontrol *kcontrol, int event); |
Mark Brown | 2159ad93 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 89 | |
Richard Fitzgerald | b9070df | 2019-03-19 11:52:09 +0000 | [diff] [blame] | 90 | int wm_adsp2_set_dspclk(struct snd_soc_dapm_widget *w, unsigned int freq); |
| 91 | |
Charles Keepax | af813a6 | 2017-01-06 14:24:41 +0000 | [diff] [blame] | 92 | int wm_adsp2_preloader_get(struct snd_kcontrol *kcontrol, |
| 93 | struct snd_ctl_elem_value *ucontrol); |
| 94 | int wm_adsp2_preloader_put(struct snd_kcontrol *kcontrol, |
| 95 | struct snd_ctl_elem_value *ucontrol); |
Richard Fitzgerald | 0a047f0 | 2018-08-08 17:13:38 +0100 | [diff] [blame] | 96 | int wm_adsp_fw_get(struct snd_kcontrol *kcontrol, |
| 97 | struct snd_ctl_elem_value *ucontrol); |
| 98 | int wm_adsp_fw_put(struct snd_kcontrol *kcontrol, |
| 99 | struct snd_ctl_elem_value *ucontrol); |
Charles Keepax | af813a6 | 2017-01-06 14:24:41 +0000 | [diff] [blame] | 100 | |
Charles Keepax | 63079b6 | 2016-11-29 10:46:21 +0000 | [diff] [blame] | 101 | int wm_adsp_compr_open(struct wm_adsp *dsp, struct snd_compr_stream *stream); |
Kuninori Morimoto | 3a5ccf2 | 2020-04-20 16:08:13 +0900 | [diff] [blame] | 102 | int wm_adsp_compr_free(struct snd_soc_component *component, |
| 103 | struct snd_compr_stream *stream); |
| 104 | int wm_adsp_compr_set_params(struct snd_soc_component *component, |
| 105 | struct snd_compr_stream *stream, |
Charles Keepax | 63079b6 | 2016-11-29 10:46:21 +0000 | [diff] [blame] | 106 | struct snd_compr_params *params); |
Kuninori Morimoto | 3a5ccf2 | 2020-04-20 16:08:13 +0900 | [diff] [blame] | 107 | int wm_adsp_compr_get_caps(struct snd_soc_component *component, |
| 108 | struct snd_compr_stream *stream, |
Charles Keepax | 63079b6 | 2016-11-29 10:46:21 +0000 | [diff] [blame] | 109 | struct snd_compr_caps *caps); |
Kuninori Morimoto | 3a5ccf2 | 2020-04-20 16:08:13 +0900 | [diff] [blame] | 110 | int wm_adsp_compr_trigger(struct snd_soc_component *component, |
| 111 | struct snd_compr_stream *stream, int cmd); |
Charles Keepax | 63079b6 | 2016-11-29 10:46:21 +0000 | [diff] [blame] | 112 | int wm_adsp_compr_handle_irq(struct wm_adsp *dsp); |
Kuninori Morimoto | 3a5ccf2 | 2020-04-20 16:08:13 +0900 | [diff] [blame] | 113 | int wm_adsp_compr_pointer(struct snd_soc_component *component, |
| 114 | struct snd_compr_stream *stream, |
Charles Keepax | 63079b6 | 2016-11-29 10:46:21 +0000 | [diff] [blame] | 115 | struct snd_compr_tstamp *tstamp); |
Kuninori Morimoto | 3a5ccf2 | 2020-04-20 16:08:13 +0900 | [diff] [blame] | 116 | int wm_adsp_compr_copy(struct snd_soc_component *component, |
| 117 | struct snd_compr_stream *stream, |
Charles Keepax | 63079b6 | 2016-11-29 10:46:21 +0000 | [diff] [blame] | 118 | char __user *buf, size_t count); |
Li Xu | eb65ccd | 2019-11-15 13:54:13 -0600 | [diff] [blame] | 119 | int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type, |
| 120 | unsigned int alg, void *buf, size_t len); |
| 121 | int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type, |
| 122 | unsigned int alg, void *buf, size_t len); |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 123 | |
Mark Brown | 2159ad93 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 124 | #endif |