wm_adsp.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. #ifndef __WM_ADSP_H
  10. #define __WM_ADSP_H
  11. #include <sound/soc.h>
  12. #include <sound/soc-dapm.h>
  13. #include <sound/compress_driver.h>
  14. #include "wmfw.h"
  15. /* Return values for wm_adsp_compr_handle_irq */
  16. #define WM_ADSP_COMPR_OK 0
  17. #define WM_ADSP_COMPR_VOICE_TRIGGER 1
  18. #define WM_ADSP2_REGION_0 BIT(0)
  19. #define WM_ADSP2_REGION_1 BIT(1)
  20. #define WM_ADSP2_REGION_2 BIT(2)
  21. #define WM_ADSP2_REGION_3 BIT(3)
  22. #define WM_ADSP2_REGION_4 BIT(4)
  23. #define WM_ADSP2_REGION_5 BIT(5)
  24. #define WM_ADSP2_REGION_6 BIT(6)
  25. #define WM_ADSP2_REGION_7 BIT(7)
  26. #define WM_ADSP2_REGION_8 BIT(8)
  27. #define WM_ADSP2_REGION_9 BIT(9)
  28. #define WM_ADSP2_REGION_1_9 (WM_ADSP2_REGION_1 | \
  29. WM_ADSP2_REGION_2 | WM_ADSP2_REGION_3 | \
  30. WM_ADSP2_REGION_4 | WM_ADSP2_REGION_5 | \
  31. WM_ADSP2_REGION_6 | WM_ADSP2_REGION_7 | \
  32. WM_ADSP2_REGION_8 | WM_ADSP2_REGION_9)
  33. #define WM_ADSP2_REGION_ALL (WM_ADSP2_REGION_0 | WM_ADSP2_REGION_1_9)
  34. struct wm_adsp_region {
  35. int type;
  36. unsigned int base;
  37. };
  38. struct wm_adsp_alg_region {
  39. struct list_head list;
  40. unsigned int alg;
  41. int type;
  42. unsigned int base;
  43. };
  44. struct wm_adsp_compr;
  45. struct wm_adsp_compr_buf;
  46. struct wm_adsp_ops;
  47. struct wm_adsp {
  48. const char *part;
  49. const char *name;
  50. const char *fwf_name;
  51. int rev;
  52. int num;
  53. int type;
  54. struct device *dev;
  55. struct regmap *regmap;
  56. struct snd_soc_component *component;
  57. struct wm_adsp_ops *ops;
  58. unsigned int base;
  59. unsigned int base_sysinfo;
  60. unsigned int sysclk_reg;
  61. unsigned int sysclk_mask;
  62. unsigned int sysclk_shift;
  63. struct list_head alg_regions;
  64. unsigned int fw_id;
  65. unsigned int fw_id_version;
  66. unsigned int fw_vendor_id;
  67. const struct wm_adsp_region *mem;
  68. int num_mems;
  69. int fw;
  70. int fw_ver;
  71. bool preloaded;
  72. bool booted;
  73. bool running;
  74. bool fatal_error;
  75. struct list_head ctl_list;
  76. struct work_struct boot_work;
  77. struct list_head compr_list;
  78. struct list_head buffer_list;
  79. struct mutex pwr_lock;
  80. unsigned int lock_regions;
  81. #ifdef CONFIG_DEBUG_FS
  82. struct dentry *debugfs_root;
  83. char *wmfw_file_name;
  84. char *bin_file_name;
  85. #endif
  86. };
  87. struct wm_adsp_ops {
  88. unsigned int sys_config_size;
  89. bool (*validate_version)(struct wm_adsp *dsp, unsigned int version);
  90. unsigned int (*parse_sizes)(struct wm_adsp *dsp,
  91. const char * const file,
  92. unsigned int pos,
  93. const struct firmware *firmware);
  94. int (*setup_algs)(struct wm_adsp *dsp);
  95. unsigned int (*region_to_reg)(struct wm_adsp_region const *mem,
  96. unsigned int offset);
  97. void (*show_fw_status)(struct wm_adsp *dsp);
  98. void (*stop_watchdog)(struct wm_adsp *dsp);
  99. int (*enable_memory)(struct wm_adsp *dsp);
  100. void (*disable_memory)(struct wm_adsp *dsp);
  101. int (*lock_memory)(struct wm_adsp *dsp, unsigned int lock_regions);
  102. int (*enable_core)(struct wm_adsp *dsp);
  103. void (*disable_core)(struct wm_adsp *dsp);
  104. int (*start_core)(struct wm_adsp *dsp);
  105. void (*stop_core)(struct wm_adsp *dsp);
  106. };
  107. #define WM_ADSP1(wname, num) \
  108. SND_SOC_DAPM_PGA_E(wname, SND_SOC_NOPM, num, 0, NULL, 0, \
  109. wm_adsp1_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD)
  110. #define WM_ADSP2_PRELOAD_SWITCH(wname, num) \
  111. SOC_SINGLE_EXT(wname " Preload Switch", SND_SOC_NOPM, num, 1, 0, \
  112. wm_adsp2_preloader_get, wm_adsp2_preloader_put)
  113. #define WM_ADSP2(wname, num, event_fn) \
  114. SND_SOC_DAPM_SPK(wname " Preload", NULL), \
  115. { .id = snd_soc_dapm_supply, .name = wname " Preloader", \
  116. .reg = SND_SOC_NOPM, .shift = num, .event = event_fn, \
  117. .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD, \
  118. .subseq = 100, /* Ensure we run after SYSCLK supply widget */ }, \
  119. { .id = snd_soc_dapm_out_drv, .name = wname, \
  120. .reg = SND_SOC_NOPM, .shift = num, .event = wm_adsp_event, \
  121. .event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD }
  122. #define WM_ADSP_FW_CONTROL(dspname, num) \
  123. SOC_ENUM_EXT(dspname " Firmware", wm_adsp_fw_enum[num], \
  124. wm_adsp_fw_get, wm_adsp_fw_put)
  125. extern const struct soc_enum wm_adsp_fw_enum[];
  126. int wm_adsp1_init(struct wm_adsp *dsp);
  127. int wm_adsp2_init(struct wm_adsp *dsp);
  128. void wm_adsp2_remove(struct wm_adsp *dsp);
  129. int wm_adsp2_component_probe(struct wm_adsp *dsp, struct snd_soc_component *component);
  130. int wm_adsp2_component_remove(struct wm_adsp *dsp, struct snd_soc_component *component);
  131. int wm_halo_init(struct wm_adsp *dsp);
  132. int wm_adsp1_event(struct snd_soc_dapm_widget *w,
  133. struct snd_kcontrol *kcontrol, int event);
  134. int wm_adsp_early_event(struct snd_soc_dapm_widget *w,
  135. struct snd_kcontrol *kcontrol, int event);
  136. irqreturn_t wm_adsp2_bus_error(int irq, void *data);
  137. irqreturn_t wm_halo_bus_error(int irq, void *data);
  138. irqreturn_t wm_halo_wdt_expire(int irq, void *data);
  139. int wm_adsp_event(struct snd_soc_dapm_widget *w,
  140. struct snd_kcontrol *kcontrol, int event);
  141. int wm_adsp2_set_dspclk(struct snd_soc_dapm_widget *w, unsigned int freq);
  142. int wm_adsp2_preloader_get(struct snd_kcontrol *kcontrol,
  143. struct snd_ctl_elem_value *ucontrol);
  144. int wm_adsp2_preloader_put(struct snd_kcontrol *kcontrol,
  145. struct snd_ctl_elem_value *ucontrol);
  146. int wm_adsp_fw_get(struct snd_kcontrol *kcontrol,
  147. struct snd_ctl_elem_value *ucontrol);
  148. int wm_adsp_fw_put(struct snd_kcontrol *kcontrol,
  149. struct snd_ctl_elem_value *ucontrol);
  150. int wm_adsp_compr_open(struct wm_adsp *dsp, struct snd_compr_stream *stream);
  151. int wm_adsp_compr_free(struct snd_soc_component *component,
  152. struct snd_compr_stream *stream);
  153. int wm_adsp_compr_set_params(struct snd_soc_component *component,
  154. struct snd_compr_stream *stream,
  155. struct snd_compr_params *params);
  156. int wm_adsp_compr_get_caps(struct snd_soc_component *component,
  157. struct snd_compr_stream *stream,
  158. struct snd_compr_caps *caps);
  159. int wm_adsp_compr_trigger(struct snd_soc_component *component,
  160. struct snd_compr_stream *stream, int cmd);
  161. int wm_adsp_compr_handle_irq(struct wm_adsp *dsp);
  162. int wm_adsp_compr_pointer(struct snd_soc_component *component,
  163. struct snd_compr_stream *stream,
  164. struct snd_compr_tstamp *tstamp);
  165. int wm_adsp_compr_copy(struct snd_soc_component *component,
  166. struct snd_compr_stream *stream,
  167. char __user *buf, size_t count);
  168. int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type,
  169. unsigned int alg, void *buf, size_t len);
  170. int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,
  171. unsigned int alg, void *buf, size_t len);
  172. #endif