wcd9304.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /* Copyright (c) 2012, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <sound/soc.h>
  13. #include <linux/mfd/wcd9xxx/wcd9xxx-slimslave.h>
  14. #define SITAR_NUM_REGISTERS 0x400
  15. #define SITAR_MAX_REGISTER (SITAR_NUM_REGISTERS-1)
  16. #define SITAR_CACHE_SIZE SITAR_NUM_REGISTERS
  17. #define SITAR_1_X_ONLY_REGISTERS 3
  18. #define SITAR_2_HIGHER_ONLY_REGISTERS 3
  19. #define SITAR_REG_VAL(reg, val) {reg, 0, val}
  20. #define DEFAULT_DCE_STA_WAIT 55
  21. #define DEFAULT_DCE_WAIT 60000
  22. #define DEFAULT_STA_WAIT 5000
  23. #define STA 0
  24. #define DCE 1
  25. #define SITAR_JACK_BUTTON_MASK (SND_JACK_BTN_0 | SND_JACK_BTN_1 | \
  26. SND_JACK_BTN_2 | SND_JACK_BTN_3 | \
  27. SND_JACK_BTN_4 | SND_JACK_BTN_5 | \
  28. SND_JACK_BTN_6 | SND_JACK_BTN_7)
  29. extern const u8 sitar_reg_readable[SITAR_CACHE_SIZE];
  30. extern const u32 sitar_1_reg_readable[SITAR_1_X_ONLY_REGISTERS];
  31. extern const u32 sitar_2_reg_readable[SITAR_2_HIGHER_ONLY_REGISTERS];
  32. extern const u8 sitar_reg_defaults[SITAR_CACHE_SIZE];
  33. enum sitar_micbias_num {
  34. SITAR_MICBIAS1,
  35. SITAR_MICBIAS2,
  36. SITAR_MICBIAS3,
  37. SITAR_MICBIAS4,
  38. };
  39. enum sitar_pid_current {
  40. SITAR_PID_MIC_2P5_UA,
  41. SITAR_PID_MIC_5_UA,
  42. SITAR_PID_MIC_10_UA,
  43. SITAR_PID_MIC_20_UA,
  44. };
  45. struct sitar_reg_mask_val {
  46. u16 reg;
  47. u8 mask;
  48. u8 val;
  49. };
  50. enum sitar_mbhc_clk_freq {
  51. SITAR_MCLK_12P2MHZ = 0,
  52. SITAR_MCLK_9P6MHZ,
  53. SITAR_NUM_CLK_FREQS,
  54. };
  55. enum sitar_mbhc_analog_pwr_cfg {
  56. SITAR_ANALOG_PWR_COLLAPSED = 0,
  57. SITAR_ANALOG_PWR_ON,
  58. SITAR_NUM_ANALOG_PWR_CONFIGS,
  59. };
  60. enum sitar_mbhc_btn_det_mem {
  61. SITAR_BTN_DET_V_BTN_LOW,
  62. SITAR_BTN_DET_V_BTN_HIGH,
  63. SITAR_BTN_DET_N_READY,
  64. SITAR_BTN_DET_N_CIC,
  65. SITAR_BTN_DET_GAIN
  66. };
  67. struct sitar_mbhc_general_cfg {
  68. u8 t_ldoh;
  69. u8 t_bg_fast_settle;
  70. u8 t_shutdown_plug_rem;
  71. u8 mbhc_nsa;
  72. u8 mbhc_navg;
  73. u8 v_micbias_l;
  74. u8 v_micbias;
  75. u8 mbhc_reserved;
  76. u16 settle_wait;
  77. u16 t_micbias_rampup;
  78. u16 t_micbias_rampdown;
  79. u16 t_supply_bringup;
  80. } __packed;
  81. struct sitar_mbhc_plug_detect_cfg {
  82. u32 mic_current;
  83. u32 hph_current;
  84. u16 t_mic_pid;
  85. u16 t_ins_complete;
  86. u16 t_ins_retry;
  87. u16 v_removal_delta;
  88. u8 micbias_slow_ramp;
  89. u8 reserved0;
  90. u8 reserved1;
  91. u8 reserved2;
  92. } __packed;
  93. struct sitar_mbhc_plug_type_cfg {
  94. u8 av_detect;
  95. u8 mono_detect;
  96. u8 num_ins_tries;
  97. u8 reserved0;
  98. s16 v_no_mic;
  99. s16 v_av_min;
  100. s16 v_av_max;
  101. s16 v_hs_min;
  102. s16 v_hs_max;
  103. u16 reserved1;
  104. } __packed;
  105. struct sitar_mbhc_btn_detect_cfg {
  106. s8 c[8];
  107. u8 nc;
  108. u8 n_meas;
  109. u8 mbhc_nsc;
  110. u8 n_btn_meas;
  111. u8 n_btn_con;
  112. u8 num_btn;
  113. u8 reserved0;
  114. u8 reserved1;
  115. u16 t_poll;
  116. u16 t_bounce_wait;
  117. u16 t_rel_timeout;
  118. s16 v_btn_press_delta_sta;
  119. s16 v_btn_press_delta_cic;
  120. u16 t_btn0_timeout;
  121. s16 _v_btn_low[0]; /* v_btn_low[num_btn] */
  122. s16 _v_btn_high[0]; /* v_btn_high[num_btn] */
  123. u8 _n_ready[SITAR_NUM_CLK_FREQS];
  124. u8 _n_cic[SITAR_NUM_CLK_FREQS];
  125. u8 _gain[SITAR_NUM_CLK_FREQS];
  126. } __packed;
  127. struct sitar_mbhc_imped_detect_cfg {
  128. u8 _hs_imped_detect;
  129. u8 _n_rload;
  130. u8 _hph_keep_on;
  131. u8 _repeat_rload_calc;
  132. u16 _t_dac_ramp_time;
  133. u16 _rhph_high;
  134. u16 _rhph_low;
  135. u16 _rload[0]; /* rload[n_rload] */
  136. u16 _alpha[0]; /* alpha[n_rload] */
  137. u16 _beta[3];
  138. } __packed;
  139. struct sitar_mbhc_config {
  140. struct snd_soc_jack *headset_jack;
  141. struct snd_soc_jack *button_jack;
  142. bool read_fw_bin;
  143. /* void* calibration contains:
  144. * struct tabla_mbhc_general_cfg generic;
  145. * struct tabla_mbhc_plug_detect_cfg plug_det;
  146. * struct tabla_mbhc_plug_type_cfg plug_type;
  147. * struct tabla_mbhc_btn_detect_cfg btn_det;
  148. * struct tabla_mbhc_imped_detect_cfg imped_det;
  149. * Note: various size depends on btn_det->num_btn
  150. */
  151. void *calibration;
  152. enum sitar_micbias_num micbias;
  153. int (*mclk_cb_fn) (struct snd_soc_codec*, int, bool);
  154. unsigned int mclk_rate;
  155. unsigned int gpio;
  156. unsigned int gpio_irq;
  157. int gpio_level_insert;
  158. };
  159. extern int sitar_hs_detect(struct snd_soc_codec *codec,
  160. const struct sitar_mbhc_config *cfg);
  161. #ifndef anc_header_dec
  162. struct anc_header {
  163. u32 reserved[3];
  164. u32 num_anc_slots;
  165. };
  166. #define anc_header_dec
  167. #endif
  168. extern int sitar_mclk_enable(struct snd_soc_codec *codec, int mclk_enable,
  169. bool dapm);
  170. /* Number of input and output Slimbus ports
  171. */
  172. enum {
  173. SITAR_RX1 = 0,
  174. SITAR_RX2,
  175. SITAR_RX3,
  176. SITAR_RX4,
  177. SITAR_RX5,
  178. SITAR_RX_MAX,
  179. };
  180. enum {
  181. SITAR_TX1 = 0,
  182. SITAR_TX2,
  183. SITAR_TX3,
  184. SITAR_TX4,
  185. SITAR_TX5,
  186. SITAR_TX_MAX,
  187. };
  188. extern void *sitar_mbhc_cal_btn_det_mp(const struct sitar_mbhc_btn_detect_cfg
  189. *btn_det,
  190. const enum sitar_mbhc_btn_det_mem mem);
  191. #define SITAR_MBHC_CAL_SIZE(buttons, rload) ( \
  192. sizeof(enum sitar_micbias_num) + \
  193. sizeof(struct sitar_mbhc_general_cfg) + \
  194. sizeof(struct sitar_mbhc_plug_detect_cfg) + \
  195. ((sizeof(s16) + sizeof(s16)) * buttons) + \
  196. sizeof(struct sitar_mbhc_plug_type_cfg) + \
  197. sizeof(struct sitar_mbhc_btn_detect_cfg) + \
  198. sizeof(struct sitar_mbhc_imped_detect_cfg) + \
  199. ((sizeof(u16) + sizeof(u16)) * rload) \
  200. )
  201. #define SITAR_MBHC_CAL_GENERAL_PTR(cali) ( \
  202. (struct sitar_mbhc_general_cfg *) cali)
  203. #define SITAR_MBHC_CAL_PLUG_DET_PTR(cali) ( \
  204. (struct sitar_mbhc_plug_detect_cfg *) \
  205. &(SITAR_MBHC_CAL_GENERAL_PTR(cali)[1]))
  206. #define SITAR_MBHC_CAL_PLUG_TYPE_PTR(cali) ( \
  207. (struct sitar_mbhc_plug_type_cfg *) \
  208. &(SITAR_MBHC_CAL_PLUG_DET_PTR(cali)[1]))
  209. #define SITAR_MBHC_CAL_BTN_DET_PTR(cali) ( \
  210. (struct sitar_mbhc_btn_detect_cfg *) \
  211. &(SITAR_MBHC_CAL_PLUG_TYPE_PTR(cali)[1]))
  212. #define SITAR_MBHC_CAL_IMPED_DET_PTR(cali) ( \
  213. (struct sitar_mbhc_imped_detect_cfg *) \
  214. (((void *)&SITAR_MBHC_CAL_BTN_DET_PTR(cali)[1]) + \
  215. (SITAR_MBHC_CAL_BTN_DET_PTR(cali)->num_btn * \
  216. (sizeof(SITAR_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_low[0]) + \
  217. sizeof(SITAR_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_high[0])))) \
  218. )
  219. /* minimum size of calibration data assuming there is only one button and
  220. * one rload.
  221. */
  222. #define SITAR_MBHC_CAL_MIN_SIZE ( \
  223. sizeof(struct sitar_mbhc_general_cfg) + \
  224. sizeof(struct sitar_mbhc_plug_detect_cfg) + \
  225. sizeof(struct sitar_mbhc_plug_type_cfg) + \
  226. sizeof(struct sitar_mbhc_btn_detect_cfg) + \
  227. sizeof(struct sitar_mbhc_imped_detect_cfg) + \
  228. (sizeof(u16) * 2))
  229. #define SITAR_MBHC_CAL_BTN_SZ(cfg_ptr) ( \
  230. sizeof(struct sitar_mbhc_btn_detect_cfg) + \
  231. (cfg_ptr->num_btn * (sizeof(cfg_ptr->_v_btn_low[0]) + \
  232. sizeof(cfg_ptr->_v_btn_high[0]))))
  233. #define SITAR_MBHC_CAL_IMPED_MIN_SZ ( \
  234. sizeof(struct sitar_mbhc_imped_detect_cfg) + \
  235. sizeof(u16) * 2)
  236. #define SITAR_MBHC_CAL_IMPED_SZ(cfg_ptr) ( \
  237. sizeof(struct sitar_mbhc_imped_detect_cfg) + \
  238. (cfg_ptr->_n_rload * (sizeof(cfg_ptr->_rload[0]) + \
  239. sizeof(cfg_ptr->_alpha[0]))))