arizona.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /*
  2. * arizona.h - Wolfson Arizona class device shared support
  3. *
  4. * Copyright 2012 Wolfson Microelectronics plc
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #ifndef _ASOC_ARIZONA_H
  13. #define _ASOC_ARIZONA_H
  14. #include <linux/completion.h>
  15. #include <sound/soc.h>
  16. #include "wm_adsp.h"
  17. #define ARIZONA_CLK_SYSCLK 1
  18. #define ARIZONA_CLK_ASYNCCLK 2
  19. #define ARIZONA_CLK_OPCLK 3
  20. #define ARIZONA_CLK_ASYNC_OPCLK 4
  21. #define ARIZONA_CLK_SRC_MCLK1 0x0
  22. #define ARIZONA_CLK_SRC_MCLK2 0x1
  23. #define ARIZONA_CLK_SRC_FLL1 0x4
  24. #define ARIZONA_CLK_SRC_FLL2 0x5
  25. #define ARIZONA_CLK_SRC_AIF1BCLK 0x8
  26. #define ARIZONA_CLK_SRC_AIF2BCLK 0x9
  27. #define ARIZONA_CLK_SRC_AIF3BCLK 0xa
  28. #define ARIZONA_FLL_SRC_NONE -1
  29. #define ARIZONA_FLL_SRC_MCLK1 0
  30. #define ARIZONA_FLL_SRC_MCLK2 1
  31. #define ARIZONA_FLL_SRC_SLIMCLK 3
  32. #define ARIZONA_FLL_SRC_FLL1 4
  33. #define ARIZONA_FLL_SRC_FLL2 5
  34. #define ARIZONA_FLL_SRC_AIF1BCLK 8
  35. #define ARIZONA_FLL_SRC_AIF2BCLK 9
  36. #define ARIZONA_FLL_SRC_AIF3BCLK 10
  37. #define ARIZONA_FLL_SRC_AIF1LRCLK 12
  38. #define ARIZONA_FLL_SRC_AIF2LRCLK 13
  39. #define ARIZONA_FLL_SRC_AIF3LRCLK 14
  40. #define ARIZONA_MIXER_VOL_MASK 0x00FE
  41. #define ARIZONA_MIXER_VOL_SHIFT 1
  42. #define ARIZONA_MIXER_VOL_WIDTH 7
  43. #define ARIZONA_CLK_6MHZ 0
  44. #define ARIZONA_CLK_12MHZ 1
  45. #define ARIZONA_CLK_24MHZ 2
  46. #define ARIZONA_CLK_49MHZ 3
  47. #define ARIZONA_CLK_73MHZ 4
  48. #define ARIZONA_CLK_98MHZ 5
  49. #define ARIZONA_CLK_147MHZ 6
  50. #define ARIZONA_MAX_DAI 10
  51. #define ARIZONA_MAX_ADSP 4
  52. #define ARIZONA_DVFS_SR1_RQ 0x001
  53. #define ARIZONA_DVFS_ADSP1_RQ 0x100
  54. /* Notifier events */
  55. #define ARIZONA_NOTIFY_VOICE_TRIGGER 0x1
  56. struct arizona;
  57. struct wm_adsp;
  58. struct arizona_dai_priv {
  59. int clk;
  60. struct snd_pcm_hw_constraint_list constraint;
  61. };
  62. struct arizona_priv {
  63. struct wm_adsp adsp[ARIZONA_MAX_ADSP];
  64. struct arizona *arizona;
  65. int sysclk;
  66. int asyncclk;
  67. struct arizona_dai_priv dai[ARIZONA_MAX_DAI];
  68. int num_inputs;
  69. unsigned int in_pending;
  70. unsigned int out_up_pending;
  71. unsigned int out_up_delay;
  72. unsigned int out_down_pending;
  73. unsigned int out_down_delay;
  74. unsigned int dvfs_reqs;
  75. struct mutex dvfs_lock;
  76. bool dvfs_cached;
  77. };
  78. struct arizona_voice_trigger_info {
  79. int core;
  80. };
  81. #define ARIZONA_NUM_MIXER_INPUTS 104
  82. extern const unsigned int arizona_mixer_tlv[];
  83. extern const char * const arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS];
  84. extern unsigned int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS];
  85. #define ARIZONA_GAINMUX_CONTROLS(name, base) \
  86. SOC_SINGLE_RANGE_TLV(name " Input Volume", base + 1, \
  87. ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
  88. arizona_mixer_tlv)
  89. #define ARIZONA_MIXER_CONTROLS(name, base) \
  90. SOC_SINGLE_RANGE_TLV(name " Input 1 Volume", base + 1, \
  91. ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
  92. arizona_mixer_tlv), \
  93. SOC_SINGLE_RANGE_TLV(name " Input 2 Volume", base + 3, \
  94. ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
  95. arizona_mixer_tlv), \
  96. SOC_SINGLE_RANGE_TLV(name " Input 3 Volume", base + 5, \
  97. ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
  98. arizona_mixer_tlv), \
  99. SOC_SINGLE_RANGE_TLV(name " Input 4 Volume", base + 7, \
  100. ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
  101. arizona_mixer_tlv)
  102. #define ARIZONA_MUX_ENUM_DECL(name, reg) \
  103. SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL( \
  104. name, reg, 0, 0xff, arizona_mixer_texts, arizona_mixer_values)
  105. #define ARIZONA_MUX_CTL_DECL(name) \
  106. const struct snd_kcontrol_new name##_mux = \
  107. SOC_DAPM_ENUM("Route", name##_enum)
  108. #define ARIZONA_MUX_ENUMS(name, base_reg) \
  109. static ARIZONA_MUX_ENUM_DECL(name##_enum, base_reg); \
  110. static ARIZONA_MUX_CTL_DECL(name)
  111. #define ARIZONA_MIXER_ENUMS(name, base_reg) \
  112. ARIZONA_MUX_ENUMS(name##_in1, base_reg); \
  113. ARIZONA_MUX_ENUMS(name##_in2, base_reg + 2); \
  114. ARIZONA_MUX_ENUMS(name##_in3, base_reg + 4); \
  115. ARIZONA_MUX_ENUMS(name##_in4, base_reg + 6)
  116. #define ARIZONA_DSP_AUX_ENUMS(name, base_reg) \
  117. ARIZONA_MUX_ENUMS(name##_aux1, base_reg); \
  118. ARIZONA_MUX_ENUMS(name##_aux2, base_reg + 8); \
  119. ARIZONA_MUX_ENUMS(name##_aux3, base_reg + 16); \
  120. ARIZONA_MUX_ENUMS(name##_aux4, base_reg + 24); \
  121. ARIZONA_MUX_ENUMS(name##_aux5, base_reg + 32); \
  122. ARIZONA_MUX_ENUMS(name##_aux6, base_reg + 40)
  123. #define ARIZONA_MUX(name, ctrl) \
  124. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, 0, 0, ctrl)
  125. #define ARIZONA_MUX_WIDGETS(name, name_str) \
  126. ARIZONA_MUX(name_str " Input", &name##_mux)
  127. #define ARIZONA_MIXER_WIDGETS(name, name_str) \
  128. ARIZONA_MUX(name_str " Input 1", &name##_in1_mux), \
  129. ARIZONA_MUX(name_str " Input 2", &name##_in2_mux), \
  130. ARIZONA_MUX(name_str " Input 3", &name##_in3_mux), \
  131. ARIZONA_MUX(name_str " Input 4", &name##_in4_mux), \
  132. SND_SOC_DAPM_MIXER(name_str " Mixer", SND_SOC_NOPM, 0, 0, NULL, 0)
  133. #define ARIZONA_DSP_WIDGETS(name, name_str) \
  134. ARIZONA_MIXER_WIDGETS(name##L, name_str "L"), \
  135. ARIZONA_MIXER_WIDGETS(name##R, name_str "R"), \
  136. ARIZONA_MUX(name_str " Aux 1", &name##_aux1_mux), \
  137. ARIZONA_MUX(name_str " Aux 2", &name##_aux2_mux), \
  138. ARIZONA_MUX(name_str " Aux 3", &name##_aux3_mux), \
  139. ARIZONA_MUX(name_str " Aux 4", &name##_aux4_mux), \
  140. ARIZONA_MUX(name_str " Aux 5", &name##_aux5_mux), \
  141. ARIZONA_MUX(name_str " Aux 6", &name##_aux6_mux)
  142. #define ARIZONA_MUX_ROUTES(widget, name) \
  143. { widget, NULL, name " Input" }, \
  144. ARIZONA_MIXER_INPUT_ROUTES(name " Input")
  145. #define ARIZONA_MIXER_ROUTES(widget, name) \
  146. { widget, NULL, name " Mixer" }, \
  147. { name " Mixer", NULL, name " Input 1" }, \
  148. { name " Mixer", NULL, name " Input 2" }, \
  149. { name " Mixer", NULL, name " Input 3" }, \
  150. { name " Mixer", NULL, name " Input 4" }, \
  151. ARIZONA_MIXER_INPUT_ROUTES(name " Input 1"), \
  152. ARIZONA_MIXER_INPUT_ROUTES(name " Input 2"), \
  153. ARIZONA_MIXER_INPUT_ROUTES(name " Input 3"), \
  154. ARIZONA_MIXER_INPUT_ROUTES(name " Input 4")
  155. #define ARIZONA_DSP_ROUTES(name) \
  156. { name, NULL, name " Preloader"}, \
  157. { name " Preloader", NULL, "SYSCLK" }, \
  158. { name, NULL, name " Aux 1" }, \
  159. { name, NULL, name " Aux 2" }, \
  160. { name, NULL, name " Aux 3" }, \
  161. { name, NULL, name " Aux 4" }, \
  162. { name, NULL, name " Aux 5" }, \
  163. { name, NULL, name " Aux 6" }, \
  164. ARIZONA_MIXER_INPUT_ROUTES(name " Aux 1"), \
  165. ARIZONA_MIXER_INPUT_ROUTES(name " Aux 2"), \
  166. ARIZONA_MIXER_INPUT_ROUTES(name " Aux 3"), \
  167. ARIZONA_MIXER_INPUT_ROUTES(name " Aux 4"), \
  168. ARIZONA_MIXER_INPUT_ROUTES(name " Aux 5"), \
  169. ARIZONA_MIXER_INPUT_ROUTES(name " Aux 6"), \
  170. ARIZONA_MIXER_ROUTES(name, name "L"), \
  171. ARIZONA_MIXER_ROUTES(name, name "R")
  172. #define ARIZONA_EQ_CONTROL(xname, xbase) \
  173. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  174. .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
  175. .put = arizona_eq_coeff_put, .private_value = \
  176. ((unsigned long)&(struct soc_bytes) { .base = xbase, \
  177. .num_regs = 20, .mask = ~ARIZONA_EQ1_B1_MODE }) }
  178. #define ARIZONA_LHPF_CONTROL(xname, xbase) \
  179. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  180. .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
  181. .put = arizona_lhpf_coeff_put, .private_value = \
  182. ((unsigned long)&(struct soc_bytes) { .base = xbase, \
  183. .num_regs = 1 }) }
  184. #define ARIZONA_RATE_ENUM_SIZE 4
  185. #define ARIZONA_SAMPLE_RATE_ENUM_SIZE 14
  186. extern const char * const arizona_rate_text[ARIZONA_RATE_ENUM_SIZE];
  187. extern const unsigned int arizona_rate_val[ARIZONA_RATE_ENUM_SIZE];
  188. extern const char * const arizona_sample_rate_text[ARIZONA_SAMPLE_RATE_ENUM_SIZE];
  189. extern const unsigned int arizona_sample_rate_val[ARIZONA_SAMPLE_RATE_ENUM_SIZE];
  190. extern const struct soc_enum arizona_isrc_fsl[];
  191. extern const struct soc_enum arizona_isrc_fsh[];
  192. extern const struct soc_enum arizona_asrc_rate1;
  193. extern const struct soc_enum arizona_in_vi_ramp;
  194. extern const struct soc_enum arizona_in_vd_ramp;
  195. extern const struct soc_enum arizona_out_vi_ramp;
  196. extern const struct soc_enum arizona_out_vd_ramp;
  197. extern const struct soc_enum arizona_lhpf1_mode;
  198. extern const struct soc_enum arizona_lhpf2_mode;
  199. extern const struct soc_enum arizona_lhpf3_mode;
  200. extern const struct soc_enum arizona_lhpf4_mode;
  201. extern const struct soc_enum arizona_ng_hold;
  202. extern const struct soc_enum arizona_in_hpf_cut_enum;
  203. extern const struct soc_enum arizona_in_dmic_osr[];
  204. extern const struct snd_kcontrol_new arizona_adsp2_rate_controls[];
  205. extern const struct soc_enum arizona_anc_input_src[];
  206. extern const struct soc_enum arizona_anc_ng_enum;
  207. extern const struct soc_enum arizona_output_anc_src[];
  208. extern const struct snd_kcontrol_new arizona_voice_trigger_switch[];
  209. extern int arizona_in_ev(struct snd_soc_dapm_widget *w,
  210. struct snd_kcontrol *kcontrol,
  211. int event);
  212. extern int arizona_out_ev(struct snd_soc_dapm_widget *w,
  213. struct snd_kcontrol *kcontrol,
  214. int event);
  215. extern int arizona_hp_ev(struct snd_soc_dapm_widget *w,
  216. struct snd_kcontrol *kcontrol,
  217. int event);
  218. extern int arizona_anc_ev(struct snd_soc_dapm_widget *w,
  219. struct snd_kcontrol *kcontrol,
  220. int event);
  221. extern int arizona_eq_coeff_put(struct snd_kcontrol *kcontrol,
  222. struct snd_ctl_elem_value *ucontrol);
  223. extern int arizona_lhpf_coeff_put(struct snd_kcontrol *kcontrol,
  224. struct snd_ctl_elem_value *ucontrol);
  225. extern int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id,
  226. int source, unsigned int freq, int dir);
  227. extern const struct snd_soc_dai_ops arizona_dai_ops;
  228. extern const struct snd_soc_dai_ops arizona_simple_dai_ops;
  229. #define ARIZONA_FLL_NAME_LEN 20
  230. struct arizona_fll {
  231. struct arizona *arizona;
  232. int id;
  233. unsigned int base;
  234. unsigned int vco_mult;
  235. unsigned int fout;
  236. int sync_src;
  237. unsigned int sync_freq;
  238. int ref_src;
  239. unsigned int ref_freq;
  240. char lock_name[ARIZONA_FLL_NAME_LEN];
  241. char clock_ok_name[ARIZONA_FLL_NAME_LEN];
  242. };
  243. extern int arizona_dvfs_up(struct snd_soc_codec *codec, unsigned int flags);
  244. extern int arizona_dvfs_down(struct snd_soc_codec *codec, unsigned int flags);
  245. extern int arizona_dvfs_sysclk_ev(struct snd_soc_dapm_widget *w,
  246. struct snd_kcontrol *kcontrol, int event);
  247. extern void arizona_init_dvfs(struct arizona_priv *priv);
  248. extern int arizona_init_fll(struct arizona *arizona, int id, int base,
  249. int lock_irq, int ok_irq, struct arizona_fll *fll);
  250. extern int arizona_set_fll_refclk(struct arizona_fll *fll, int source,
  251. unsigned int Fref, unsigned int Fout);
  252. extern int arizona_set_fll(struct arizona_fll *fll, int source,
  253. unsigned int Fref, unsigned int Fout);
  254. extern int arizona_init_spk(struct snd_soc_codec *codec);
  255. extern int arizona_init_gpio(struct snd_soc_codec *codec);
  256. extern int arizona_init_mono(struct snd_soc_codec *codec);
  257. extern int arizona_init_notifiers(struct snd_soc_codec *codec);
  258. extern int arizona_free_spk(struct snd_soc_codec *codec);
  259. extern int arizona_init_dai(struct arizona_priv *priv, int dai);
  260. int arizona_set_output_mode(struct snd_soc_codec *codec, int output,
  261. bool diff);
  262. extern bool arizona_input_analog(struct snd_soc_codec *codec, int shift);
  263. extern const char *arizona_sample_rate_val_to_name(unsigned int rate_val);
  264. extern int arizona_register_notifier(struct snd_soc_codec *codec,
  265. struct notifier_block *nb,
  266. int (*notify)(struct notifier_block *nb,
  267. unsigned long action,
  268. void *data));
  269. extern int arizona_unregister_notifier(struct snd_soc_codec *codec,
  270. struct notifier_block *nb);
  271. #endif