arizona.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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 6
  51. #define ARIZONA_MAX_ADSP 4
  52. #define ARIZONA_DVFS_SR1_RQ 0x001
  53. #define ARIZONA_DVFS_ADSP1_RQ 0x100
  54. struct arizona;
  55. struct wm_adsp;
  56. struct arizona_dai_priv {
  57. int clk;
  58. };
  59. struct arizona_priv {
  60. struct wm_adsp adsp[ARIZONA_MAX_ADSP];
  61. struct arizona *arizona;
  62. int sysclk;
  63. int asyncclk;
  64. struct arizona_dai_priv dai[ARIZONA_MAX_DAI];
  65. int num_inputs;
  66. unsigned int in_pending;
  67. unsigned int out_up_pending;
  68. unsigned int out_up_delay;
  69. unsigned int out_down_pending;
  70. unsigned int out_down_delay;
  71. unsigned int spk_ena:2;
  72. unsigned int spk_ena_pending:1;
  73. unsigned int dvfs_reqs;
  74. struct mutex dvfs_lock;
  75. bool dvfs_cached;
  76. };
  77. #define ARIZONA_NUM_MIXER_INPUTS 104
  78. extern const unsigned int arizona_mixer_tlv[];
  79. extern const char *arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS];
  80. extern int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS];
  81. #define ARIZONA_GAINMUX_CONTROLS(name, base) \
  82. SOC_SINGLE_RANGE_TLV(name " Input Volume", base + 1, \
  83. ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
  84. arizona_mixer_tlv)
  85. #define ARIZONA_MIXER_CONTROLS(name, base) \
  86. SOC_SINGLE_RANGE_TLV(name " Input 1 Volume", base + 1, \
  87. ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
  88. arizona_mixer_tlv), \
  89. SOC_SINGLE_RANGE_TLV(name " Input 2 Volume", base + 3, \
  90. ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
  91. arizona_mixer_tlv), \
  92. SOC_SINGLE_RANGE_TLV(name " Input 3 Volume", base + 5, \
  93. ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
  94. arizona_mixer_tlv), \
  95. SOC_SINGLE_RANGE_TLV(name " Input 4 Volume", base + 7, \
  96. ARIZONA_MIXER_VOL_SHIFT, 0x20, 0x50, 0, \
  97. arizona_mixer_tlv)
  98. #define ARIZONA_MUX_ENUM_DECL(name, reg) \
  99. SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL( \
  100. name, reg, 0, 0xff, arizona_mixer_texts, arizona_mixer_values)
  101. #define ARIZONA_MUX_CTL_DECL(name) \
  102. const struct snd_kcontrol_new name##_mux = \
  103. SOC_DAPM_ENUM("Route", name##_enum)
  104. #define ARIZONA_MUX_ENUMS(name, base_reg) \
  105. static ARIZONA_MUX_ENUM_DECL(name##_enum, base_reg); \
  106. static ARIZONA_MUX_CTL_DECL(name)
  107. #define ARIZONA_MIXER_ENUMS(name, base_reg) \
  108. ARIZONA_MUX_ENUMS(name##_in1, base_reg); \
  109. ARIZONA_MUX_ENUMS(name##_in2, base_reg + 2); \
  110. ARIZONA_MUX_ENUMS(name##_in3, base_reg + 4); \
  111. ARIZONA_MUX_ENUMS(name##_in4, base_reg + 6)
  112. #define ARIZONA_DSP_AUX_ENUMS(name, base_reg) \
  113. ARIZONA_MUX_ENUMS(name##_aux1, base_reg); \
  114. ARIZONA_MUX_ENUMS(name##_aux2, base_reg + 8); \
  115. ARIZONA_MUX_ENUMS(name##_aux3, base_reg + 16); \
  116. ARIZONA_MUX_ENUMS(name##_aux4, base_reg + 24); \
  117. ARIZONA_MUX_ENUMS(name##_aux5, base_reg + 32); \
  118. ARIZONA_MUX_ENUMS(name##_aux6, base_reg + 40)
  119. #define ARIZONA_MUX(name, ctrl) \
  120. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, 0, 0, ctrl)
  121. #define ARIZONA_MUX_WIDGETS(name, name_str) \
  122. ARIZONA_MUX(name_str " Input", &name##_mux)
  123. #define ARIZONA_MIXER_WIDGETS(name, name_str) \
  124. ARIZONA_MUX(name_str " Input 1", &name##_in1_mux), \
  125. ARIZONA_MUX(name_str " Input 2", &name##_in2_mux), \
  126. ARIZONA_MUX(name_str " Input 3", &name##_in3_mux), \
  127. ARIZONA_MUX(name_str " Input 4", &name##_in4_mux), \
  128. SND_SOC_DAPM_MIXER(name_str " Mixer", SND_SOC_NOPM, 0, 0, NULL, 0)
  129. #define ARIZONA_DSP_WIDGETS(name, name_str) \
  130. ARIZONA_MIXER_WIDGETS(name##L, name_str "L"), \
  131. ARIZONA_MIXER_WIDGETS(name##R, name_str "R"), \
  132. ARIZONA_MUX(name_str " Aux 1", &name##_aux1_mux), \
  133. ARIZONA_MUX(name_str " Aux 2", &name##_aux2_mux), \
  134. ARIZONA_MUX(name_str " Aux 3", &name##_aux3_mux), \
  135. ARIZONA_MUX(name_str " Aux 4", &name##_aux4_mux), \
  136. ARIZONA_MUX(name_str " Aux 5", &name##_aux5_mux), \
  137. ARIZONA_MUX(name_str " Aux 6", &name##_aux6_mux)
  138. #define ARIZONA_MUX_ROUTES(widget, name) \
  139. { widget, NULL, name " Input" }, \
  140. ARIZONA_MIXER_INPUT_ROUTES(name " Input")
  141. #define ARIZONA_MIXER_ROUTES(widget, name) \
  142. { widget, NULL, name " Mixer" }, \
  143. { name " Mixer", NULL, name " Input 1" }, \
  144. { name " Mixer", NULL, name " Input 2" }, \
  145. { name " Mixer", NULL, name " Input 3" }, \
  146. { name " Mixer", NULL, name " Input 4" }, \
  147. ARIZONA_MIXER_INPUT_ROUTES(name " Input 1"), \
  148. ARIZONA_MIXER_INPUT_ROUTES(name " Input 2"), \
  149. ARIZONA_MIXER_INPUT_ROUTES(name " Input 3"), \
  150. ARIZONA_MIXER_INPUT_ROUTES(name " Input 4")
  151. #define ARIZONA_DSP_ROUTES(name) \
  152. { name, NULL, name " Preloader"}, \
  153. { name " Preloader", NULL, name " Aux 1" }, \
  154. { name " Preloader", NULL, name " Aux 2" }, \
  155. { name " Preloader", NULL, name " Aux 3" }, \
  156. { name " Preloader", NULL, name " Aux 4" }, \
  157. { name " Preloader", NULL, name " Aux 5" }, \
  158. { name " Preloader", NULL, name " Aux 6" }, \
  159. ARIZONA_MIXER_INPUT_ROUTES(name " Aux 1"), \
  160. ARIZONA_MIXER_INPUT_ROUTES(name " Aux 2"), \
  161. ARIZONA_MIXER_INPUT_ROUTES(name " Aux 3"), \
  162. ARIZONA_MIXER_INPUT_ROUTES(name " Aux 4"), \
  163. ARIZONA_MIXER_INPUT_ROUTES(name " Aux 5"), \
  164. ARIZONA_MIXER_INPUT_ROUTES(name " Aux 6"), \
  165. ARIZONA_MIXER_ROUTES(name " Preloader", name "L"), \
  166. ARIZONA_MIXER_ROUTES(name " Preloader", name "R")
  167. #define ARIZONA_EQ_CONTROL(xname, xbase) \
  168. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  169. .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
  170. .put = arizona_eq_coeff_put, .private_value = \
  171. ((unsigned long)&(struct soc_bytes) { .base = xbase, \
  172. .num_regs = 20, .mask = ~ARIZONA_EQ1_B1_MODE }) }
  173. #define ARIZONA_LHPF_CONTROL(xname, xbase) \
  174. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  175. .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
  176. .put = arizona_lhpf_coeff_put, .private_value = \
  177. ((unsigned long)&(struct soc_bytes) { .base = xbase, \
  178. .num_regs = 1 }) }
  179. #define ARIZONA_RATE_ENUM_SIZE 4
  180. #define ARIZONA_SAMPLE_RATE_ENUM_SIZE 14
  181. extern const char *arizona_rate_text[ARIZONA_RATE_ENUM_SIZE];
  182. extern const int arizona_rate_val[ARIZONA_RATE_ENUM_SIZE];
  183. extern const char * const arizona_sample_rate_text[ARIZONA_SAMPLE_RATE_ENUM_SIZE];
  184. extern const unsigned int arizona_sample_rate_val[ARIZONA_SAMPLE_RATE_ENUM_SIZE];
  185. extern const struct soc_enum arizona_isrc_fsl[];
  186. extern const struct soc_enum arizona_isrc_fsh[];
  187. extern const struct soc_enum arizona_asrc_rate1;
  188. extern const struct soc_enum arizona_in_vi_ramp;
  189. extern const struct soc_enum arizona_in_vd_ramp;
  190. extern const struct soc_enum arizona_out_vi_ramp;
  191. extern const struct soc_enum arizona_out_vd_ramp;
  192. extern const struct soc_enum arizona_lhpf1_mode;
  193. extern const struct soc_enum arizona_lhpf2_mode;
  194. extern const struct soc_enum arizona_lhpf3_mode;
  195. extern const struct soc_enum arizona_lhpf4_mode;
  196. extern const struct soc_enum arizona_ng_hold;
  197. extern const struct soc_enum arizona_in_hpf_cut_enum;
  198. extern const struct soc_enum arizona_in_dmic_osr[];
  199. extern const struct snd_kcontrol_new arizona_adsp2_rate_controls[];
  200. extern int arizona_in_ev(struct snd_soc_dapm_widget *w,
  201. struct snd_kcontrol *kcontrol,
  202. int event);
  203. extern int arizona_out_ev(struct snd_soc_dapm_widget *w,
  204. struct snd_kcontrol *kcontrol,
  205. int event);
  206. extern int arizona_hp_ev(struct snd_soc_dapm_widget *w,
  207. struct snd_kcontrol *kcontrol,
  208. int event);
  209. extern int arizona_eq_coeff_put(struct snd_kcontrol *kcontrol,
  210. struct snd_ctl_elem_value *ucontrol);
  211. extern int arizona_lhpf_coeff_put(struct snd_kcontrol *kcontrol,
  212. struct snd_ctl_elem_value *ucontrol);
  213. extern int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id,
  214. int source, unsigned int freq, int dir);
  215. extern const struct snd_soc_dai_ops arizona_dai_ops;
  216. extern const struct snd_soc_dai_ops arizona_simple_dai_ops;
  217. #define ARIZONA_FLL_NAME_LEN 20
  218. struct arizona_fll {
  219. struct arizona *arizona;
  220. int id;
  221. unsigned int base;
  222. unsigned int vco_mult;
  223. unsigned int fout;
  224. int sync_src;
  225. unsigned int sync_freq;
  226. int ref_src;
  227. unsigned int ref_freq;
  228. char lock_name[ARIZONA_FLL_NAME_LEN];
  229. char clock_ok_name[ARIZONA_FLL_NAME_LEN];
  230. };
  231. extern int arizona_dvfs_up(struct snd_soc_codec *codec, unsigned int flags);
  232. extern int arizona_dvfs_down(struct snd_soc_codec *codec, unsigned int flags);
  233. extern int arizona_dvfs_sysclk_ev(struct snd_soc_dapm_widget *w,
  234. struct snd_kcontrol *kcontrol, int event);
  235. extern void arizona_init_dvfs(struct arizona_priv *priv);
  236. extern int arizona_init_fll(struct arizona *arizona, int id, int base,
  237. int lock_irq, int ok_irq, struct arizona_fll *fll);
  238. extern int arizona_set_fll_refclk(struct arizona_fll *fll, int source,
  239. unsigned int Fref, unsigned int Fout);
  240. extern int arizona_set_fll(struct arizona_fll *fll, int source,
  241. unsigned int Fref, unsigned int Fout);
  242. extern int arizona_init_spk(struct snd_soc_codec *codec);
  243. extern int arizona_init_gpio(struct snd_soc_codec *codec);
  244. extern int arizona_init_mono(struct snd_soc_codec *codec);
  245. extern int arizona_init_dai(struct arizona_priv *priv, int dai);
  246. int arizona_set_output_mode(struct snd_soc_codec *codec, int output,
  247. bool diff);
  248. extern bool arizona_input_analog(struct snd_soc_codec *codec, int shift);
  249. extern const char *arizona_sample_rate_val_to_name(unsigned int rate_val);
  250. #endif