| 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* |
| 3 | * wm_adsp.h -- Wolfson ADSP support |
| 4 | * |
| 5 | * Copyright 2012 Wolfson Microelectronics plc |
| 6 | * |
| 7 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
| 8 | */ |
| 9 | |
| 10 | #ifndef __WM_ADSP_H |
| 11 | #define __WM_ADSP_H |
| 12 | |
| 13 | #include <linux/firmware/cirrus/cs_dsp.h> |
| 14 | #include <linux/firmware/cirrus/wmfw.h> |
| 15 | |
| 16 | #include <sound/soc.h> |
| 17 | #include <sound/soc-dapm.h> |
| 18 | #include <sound/compress_driver.h> |
| 19 | |
| 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 | |
| 24 | struct wm_adsp_compr; |
| 25 | struct wm_adsp_compr_buf; |
| 26 | |
| 27 | struct wm_adsp { |
| 28 | struct cs_dsp cs_dsp; |
| 29 | const char *part; |
| 30 | const char *fwf_name; |
| 31 | const char *system_name; |
| 32 | const char *fwf_suffix; |
| 33 | struct snd_soc_component *component; |
| 34 | |
| 35 | unsigned int sys_config_size; |
| 36 | |
| 37 | int fw; |
| 38 | bool wmfw_optional; |
| 39 | bool bin_mandatory; |
| 40 | |
| 41 | struct work_struct boot_work; |
| 42 | int (*control_add)(struct wm_adsp *dsp, struct cs_dsp_coeff_ctl *cs_ctl); |
| 43 | int (*pre_run)(struct wm_adsp *dsp); |
| 44 | |
| 45 | bool preloaded; |
| 46 | bool fatal_error; |
| 47 | |
| 48 | struct list_head compr_list; |
| 49 | struct list_head buffer_list; |
| 50 | |
| 51 | /* |
| 52 | * Flag indicating the preloader widget only needs power toggled |
| 53 | * on state change rather than held on for the duration of the |
| 54 | * preload, useful for devices that can retain firmware memory |
| 55 | * across power down. |
| 56 | */ |
| 57 | bool toggle_preload; |
| 58 | }; |
| 59 | |
| 60 | #define WM_ADSP1(wname, num) \ |
| 61 | SND_SOC_DAPM_PGA_E(wname, SND_SOC_NOPM, num, 0, NULL, 0, \ |
| 62 | wm_adsp1_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD) |
| 63 | |
| 64 | #define WM_ADSP2_PRELOAD_SWITCH(wname, num) \ |
| 65 | SOC_SINGLE_EXT(wname " Preload Switch", SND_SOC_NOPM, num, 1, 0, \ |
| 66 | wm_adsp2_preloader_get, wm_adsp2_preloader_put) |
| 67 | |
| 68 | #define WM_ADSP2(wname, num, event_fn) \ |
| 69 | SND_SOC_DAPM_SPK(wname " Preload", NULL), \ |
| 70 | { .id = snd_soc_dapm_supply, .name = wname " Preloader", \ |
| 71 | .reg = SND_SOC_NOPM, .shift = num, .event = event_fn, \ |
| 72 | .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD, \ |
| 73 | .subseq = 100, /* Ensure we run after SYSCLK supply widget */ }, \ |
| 74 | { .id = snd_soc_dapm_out_drv, .name = wname, \ |
| 75 | .reg = SND_SOC_NOPM, .shift = num, .event = wm_adsp_event, \ |
| 76 | .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD } |
| 77 | |
| 78 | #define WM_ADSP_FW_CONTROL(dspname, num) \ |
| 79 | SOC_ENUM_EXT(dspname " Firmware", wm_adsp_fw_enum[num], \ |
| 80 | wm_adsp_fw_get, wm_adsp_fw_put) |
| 81 | |
| 82 | extern const struct soc_enum wm_adsp_fw_enum[]; |
| 83 | |
| 84 | int wm_adsp1_init(struct wm_adsp *dsp); |
| 85 | int wm_adsp2_init(struct wm_adsp *dsp); |
| 86 | void wm_adsp2_remove(struct wm_adsp *dsp); |
| 87 | int wm_adsp2_component_probe(struct wm_adsp *dsp, struct snd_soc_component *component); |
| 88 | int wm_adsp2_component_remove(struct wm_adsp *dsp, struct snd_soc_component *component); |
| 89 | int wm_halo_init(struct wm_adsp *dsp); |
| 90 | |
| 91 | int wm_adsp1_event(struct snd_soc_dapm_widget *w, |
| 92 | struct snd_kcontrol *kcontrol, int event); |
| 93 | |
| 94 | int wm_adsp_early_event(struct snd_soc_dapm_widget *w, |
| 95 | struct snd_kcontrol *kcontrol, int event); |
| 96 | |
| 97 | int wm_adsp_power_up(struct wm_adsp *dsp, bool load_firmware); |
| 98 | void wm_adsp_power_down(struct wm_adsp *dsp); |
| 99 | |
| 100 | irqreturn_t wm_adsp2_bus_error(int irq, void *data); |
| 101 | irqreturn_t wm_halo_bus_error(int irq, void *data); |
| 102 | irqreturn_t wm_halo_wdt_expire(int irq, void *data); |
| 103 | |
| 104 | int wm_adsp_run(struct wm_adsp *dsp); |
| 105 | void wm_adsp_stop(struct wm_adsp *dsp); |
| 106 | int wm_adsp_event(struct snd_soc_dapm_widget *w, |
| 107 | struct snd_kcontrol *kcontrol, int event); |
| 108 | |
| 109 | int wm_adsp2_set_dspclk(struct snd_soc_dapm_widget *w, unsigned int freq); |
| 110 | |
| 111 | int wm_adsp2_preloader_get(struct snd_kcontrol *kcontrol, |
| 112 | struct snd_ctl_elem_value *ucontrol); |
| 113 | int wm_adsp2_preloader_put(struct snd_kcontrol *kcontrol, |
| 114 | struct snd_ctl_elem_value *ucontrol); |
| 115 | int wm_adsp_fw_get(struct snd_kcontrol *kcontrol, |
| 116 | struct snd_ctl_elem_value *ucontrol); |
| 117 | int wm_adsp_fw_put(struct snd_kcontrol *kcontrol, |
| 118 | struct snd_ctl_elem_value *ucontrol); |
| 119 | |
| 120 | int wm_adsp_compr_open(struct wm_adsp *dsp, struct snd_compr_stream *stream); |
| 121 | int wm_adsp_compr_free(struct snd_soc_component *component, |
| 122 | struct snd_compr_stream *stream); |
| 123 | int wm_adsp_compr_set_params(struct snd_soc_component *component, |
| 124 | struct snd_compr_stream *stream, |
| 125 | struct snd_compr_params *params); |
| 126 | int wm_adsp_compr_get_caps(struct snd_soc_component *component, |
| 127 | struct snd_compr_stream *stream, |
| 128 | struct snd_compr_caps *caps); |
| 129 | int wm_adsp_compr_trigger(struct snd_soc_component *component, |
| 130 | struct snd_compr_stream *stream, int cmd); |
| 131 | int wm_adsp_compr_handle_irq(struct wm_adsp *dsp); |
| 132 | int wm_adsp_compr_pointer(struct snd_soc_component *component, |
| 133 | struct snd_compr_stream *stream, |
| 134 | struct snd_compr_tstamp64 *tstamp); |
| 135 | int wm_adsp_compr_copy(struct snd_soc_component *component, |
| 136 | struct snd_compr_stream *stream, |
| 137 | char __user *buf, size_t count); |
| 138 | |
| 139 | int wm_adsp_control_add(struct cs_dsp_coeff_ctl *cs_ctl); |
| 140 | int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type, |
| 141 | unsigned int alg, void *buf, size_t len); |
| 142 | int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type, |
| 143 | unsigned int alg, void *buf, size_t len); |
| 144 | |
| 145 | #endif |
| 146 | |