wm_adsp.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 <[email protected]>
  8. */
  9. #ifndef __WM_ADSP_H
  10. #define __WM_ADSP_H
  11. #include <linux/firmware/cirrus/cs_dsp.h>
  12. #include <linux/firmware/cirrus/wmfw.h>
  13. #include <sound/soc.h>
  14. #include <sound/soc-dapm.h>
  15. #include <sound/compress_driver.h>
  16. /* Return values for wm_adsp_compr_handle_irq */
  17. #define WM_ADSP_COMPR_OK 0
  18. #define WM_ADSP_COMPR_VOICE_TRIGGER 1
  19. struct wm_adsp_compr;
  20. struct wm_adsp_compr_buf;
  21. struct wm_adsp {
  22. struct cs_dsp cs_dsp;
  23. const char *part;
  24. const char *fwf_name;
  25. const char *system_name;
  26. struct snd_soc_component *component;
  27. unsigned int sys_config_size;
  28. int fw;
  29. struct work_struct boot_work;
  30. bool preloaded;
  31. bool fatal_error;
  32. bool hibernate;
  33. struct list_head compr_list;
  34. struct list_head buffer_list;
  35. /*
  36. * Flag indicating the preloader widget only needs power toggled
  37. * on state change rather than held on for the duration of the
  38. * preload, useful for devices that can retain firmware memory
  39. * across power down.
  40. */
  41. bool toggle_preload;
  42. };
  43. #define WM_ADSP1(wname, num) \
  44. SND_SOC_DAPM_PGA_E(wname, SND_SOC_NOPM, num, 0, NULL, 0, \
  45. wm_adsp1_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD)
  46. #define WM_ADSP2_PRELOAD_SWITCH(wname, num) \
  47. SOC_SINGLE_EXT(wname " Preload Switch", SND_SOC_NOPM, num, 1, 0, \
  48. wm_adsp2_preloader_get, wm_adsp2_preloader_put)
  49. #define WM_ADSP2(wname, num, event_fn) \
  50. SND_SOC_DAPM_SPK(wname " Preload", NULL), \
  51. { .id = snd_soc_dapm_supply, .name = wname " Preloader", \
  52. .reg = SND_SOC_NOPM, .shift = num, .event = event_fn, \
  53. .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD, \
  54. .subseq = 100, /* Ensure we run after SYSCLK supply widget */ }, \
  55. { .id = snd_soc_dapm_out_drv, .name = wname, \
  56. .reg = SND_SOC_NOPM, .shift = num, .event = wm_adsp_event, \
  57. .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD }
  58. #define WM_ADSP_FW_CONTROL(dspname, num) \
  59. SOC_ENUM_EXT(dspname " Firmware", wm_adsp_fw_enum[num], \
  60. wm_adsp_fw_get, wm_adsp_fw_put)
  61. extern const struct soc_enum wm_adsp_fw_enum[];
  62. int wm_adsp1_init(struct wm_adsp *dsp);
  63. int wm_adsp2_init(struct wm_adsp *dsp);
  64. void wm_adsp2_remove(struct wm_adsp *dsp);
  65. int wm_adsp2_component_probe(struct wm_adsp *dsp, struct snd_soc_component *component);
  66. int wm_adsp2_component_remove(struct wm_adsp *dsp, struct snd_soc_component *component);
  67. int wm_halo_init(struct wm_adsp *dsp);
  68. int wm_adsp1_event(struct snd_soc_dapm_widget *w,
  69. struct snd_kcontrol *kcontrol, int event);
  70. int wm_adsp_early_event(struct snd_soc_dapm_widget *w,
  71. struct snd_kcontrol *kcontrol, int event);
  72. irqreturn_t wm_adsp2_bus_error(int irq, void *data);
  73. irqreturn_t wm_halo_bus_error(int irq, void *data);
  74. irqreturn_t wm_halo_wdt_expire(int irq, void *data);
  75. int wm_adsp_event(struct snd_soc_dapm_widget *w,
  76. struct snd_kcontrol *kcontrol, int event);
  77. int wm_adsp2_set_dspclk(struct snd_soc_dapm_widget *w, unsigned int freq);
  78. int wm_adsp2_preloader_get(struct snd_kcontrol *kcontrol,
  79. struct snd_ctl_elem_value *ucontrol);
  80. int wm_adsp2_preloader_put(struct snd_kcontrol *kcontrol,
  81. struct snd_ctl_elem_value *ucontrol);
  82. int wm_adsp_fw_get(struct snd_kcontrol *kcontrol,
  83. struct snd_ctl_elem_value *ucontrol);
  84. int wm_adsp_fw_put(struct snd_kcontrol *kcontrol,
  85. struct snd_ctl_elem_value *ucontrol);
  86. int wm_adsp_compr_open(struct wm_adsp *dsp, struct snd_compr_stream *stream);
  87. int wm_adsp_compr_free(struct snd_soc_component *component,
  88. struct snd_compr_stream *stream);
  89. int wm_adsp_compr_set_params(struct snd_soc_component *component,
  90. struct snd_compr_stream *stream,
  91. struct snd_compr_params *params);
  92. int wm_adsp_compr_get_caps(struct snd_soc_component *component,
  93. struct snd_compr_stream *stream,
  94. struct snd_compr_caps *caps);
  95. int wm_adsp_compr_trigger(struct snd_soc_component *component,
  96. struct snd_compr_stream *stream, int cmd);
  97. int wm_adsp_compr_handle_irq(struct wm_adsp *dsp);
  98. int wm_adsp_compr_pointer(struct snd_soc_component *component,
  99. struct snd_compr_stream *stream,
  100. struct snd_compr_tstamp *tstamp);
  101. int wm_adsp_compr_copy(struct snd_soc_component *component,
  102. struct snd_compr_stream *stream,
  103. char __user *buf, size_t count);
  104. int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type,
  105. unsigned int alg, void *buf, size_t len);
  106. int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,
  107. unsigned int alg, void *buf, size_t len);
  108. #endif