wcd9310.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /* Copyright (c) 2011-2013, 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 <sound/jack.h>
  14. #include <linux/mfd/wcd9xxx/wcd9xxx-slimslave.h>
  15. #define TABLA_NUM_REGISTERS 0x400
  16. #define TABLA_MAX_REGISTER (TABLA_NUM_REGISTERS-1)
  17. #define TABLA_CACHE_SIZE TABLA_NUM_REGISTERS
  18. #define TABLA_1_X_ONLY_REGISTERS 3
  19. #define TABLA_2_HIGHER_ONLY_REGISTERS 3
  20. #define TABLA_REG_VAL(reg, val) {reg, 0, val}
  21. #define DEFAULT_DCE_STA_WAIT 55
  22. #define DEFAULT_DCE_WAIT 60000
  23. #define DEFAULT_STA_WAIT 5000
  24. #define VDDIO_MICBIAS_MV 1800
  25. #define STA 0
  26. #define DCE 1
  27. #define TABLA_JACK_BUTTON_MASK (SND_JACK_BTN_0 | SND_JACK_BTN_1 | \
  28. SND_JACK_BTN_2 | SND_JACK_BTN_3 | \
  29. SND_JACK_BTN_4 | SND_JACK_BTN_5 | \
  30. SND_JACK_BTN_6 | SND_JACK_BTN_7)
  31. extern const u8 tabla_reg_readable[TABLA_CACHE_SIZE];
  32. extern const u32 tabla_1_reg_readable[TABLA_1_X_ONLY_REGISTERS];
  33. extern const u32 tabla_2_reg_readable[TABLA_2_HIGHER_ONLY_REGISTERS];
  34. extern const u8 tabla_reg_defaults[TABLA_CACHE_SIZE];
  35. enum tabla_micbias_num {
  36. TABLA_MICBIAS1 = 0,
  37. TABLA_MICBIAS2,
  38. TABLA_MICBIAS3,
  39. TABLA_MICBIAS4,
  40. TABLA_NUM_MICBIAS,
  41. };
  42. enum tabla_pid_current {
  43. TABLA_PID_MIC_2P5_UA,
  44. TABLA_PID_MIC_5_UA,
  45. TABLA_PID_MIC_10_UA,
  46. TABLA_PID_MIC_20_UA,
  47. };
  48. struct tabla_reg_mask_val {
  49. u16 reg;
  50. u8 mask;
  51. u8 val;
  52. };
  53. enum tabla_mbhc_clk_freq {
  54. TABLA_MCLK_12P2MHZ = 0,
  55. TABLA_MCLK_9P6MHZ,
  56. TABLA_NUM_CLK_FREQS,
  57. };
  58. enum tabla_mbhc_analog_pwr_cfg {
  59. TABLA_ANALOG_PWR_COLLAPSED = 0,
  60. TABLA_ANALOG_PWR_ON,
  61. TABLA_NUM_ANALOG_PWR_CONFIGS,
  62. };
  63. enum tabla_mbhc_btn_det_mem {
  64. TABLA_BTN_DET_V_BTN_LOW,
  65. TABLA_BTN_DET_V_BTN_HIGH,
  66. TABLA_BTN_DET_N_READY,
  67. TABLA_BTN_DET_N_CIC,
  68. TABLA_BTN_DET_GAIN
  69. };
  70. struct tabla_mbhc_general_cfg {
  71. u8 t_ldoh;
  72. u8 t_bg_fast_settle;
  73. u8 t_shutdown_plug_rem;
  74. u8 mbhc_nsa;
  75. u8 mbhc_navg;
  76. u8 v_micbias_l;
  77. u8 v_micbias;
  78. u8 mbhc_reserved;
  79. u16 settle_wait;
  80. u16 t_micbias_rampup;
  81. u16 t_micbias_rampdown;
  82. u16 t_supply_bringup;
  83. } __packed;
  84. struct tabla_mbhc_plug_detect_cfg {
  85. u32 mic_current;
  86. u32 hph_current;
  87. u16 t_mic_pid;
  88. u16 t_ins_complete;
  89. u16 t_ins_retry;
  90. u16 v_removal_delta;
  91. u8 micbias_slow_ramp;
  92. u8 reserved0;
  93. u8 reserved1;
  94. u8 reserved2;
  95. } __packed;
  96. struct tabla_mbhc_plug_type_cfg {
  97. u8 av_detect;
  98. u8 mono_detect;
  99. u8 num_ins_tries;
  100. u8 reserved0;
  101. s16 v_no_mic;
  102. s16 v_av_min;
  103. s16 v_av_max;
  104. s16 v_hs_min;
  105. s16 v_hs_max;
  106. u16 reserved1;
  107. } __packed;
  108. struct tabla_mbhc_btn_detect_cfg {
  109. s8 c[8];
  110. u8 nc;
  111. u8 n_meas;
  112. u8 mbhc_nsc;
  113. u8 n_btn_meas;
  114. u8 n_btn_con;
  115. u8 num_btn;
  116. u8 reserved0;
  117. u8 reserved1;
  118. u16 t_poll;
  119. u16 t_bounce_wait;
  120. u16 t_rel_timeout;
  121. s16 v_btn_press_delta_sta;
  122. s16 v_btn_press_delta_cic;
  123. u16 t_btn0_timeout;
  124. s16 _v_btn_low[0]; /* v_btn_low[num_btn] */
  125. s16 _v_btn_high[0]; /* v_btn_high[num_btn] */
  126. u8 _n_ready[TABLA_NUM_CLK_FREQS];
  127. u8 _n_cic[TABLA_NUM_CLK_FREQS];
  128. u8 _gain[TABLA_NUM_CLK_FREQS];
  129. } __packed;
  130. struct tabla_mbhc_imped_detect_cfg {
  131. u8 _hs_imped_detect;
  132. u8 _n_rload;
  133. u8 _hph_keep_on;
  134. u8 _repeat_rload_calc;
  135. u16 _t_dac_ramp_time;
  136. u16 _rhph_high;
  137. u16 _rhph_low;
  138. u16 _rload[0]; /* rload[n_rload] */
  139. u16 _alpha[0]; /* alpha[n_rload] */
  140. u16 _beta[3];
  141. } __packed;
  142. struct tabla_mbhc_config {
  143. struct snd_soc_jack *headset_jack;
  144. struct snd_soc_jack *button_jack;
  145. bool read_fw_bin;
  146. /* void* calibration contains:
  147. * struct tabla_mbhc_general_cfg generic;
  148. * struct tabla_mbhc_plug_detect_cfg plug_det;
  149. * struct tabla_mbhc_plug_type_cfg plug_type;
  150. * struct tabla_mbhc_btn_detect_cfg btn_det;
  151. * struct tabla_mbhc_imped_detect_cfg imped_det;
  152. * Note: various size depends on btn_det->num_btn
  153. */
  154. void *calibration;
  155. enum tabla_micbias_num micbias;
  156. int (*mclk_cb_fn) (struct snd_soc_codec*, int, bool);
  157. unsigned int mclk_rate;
  158. unsigned int gpio;
  159. unsigned int gpio_irq;
  160. int gpio_level_insert;
  161. bool detect_extn_cable;
  162. /* swap_gnd_mic returns true if extern GND/MIC swap switch toggled */
  163. bool (*swap_gnd_mic) (struct snd_soc_codec *);
  164. bool micbias_always_on;
  165. };
  166. extern int tabla_hs_detect(struct snd_soc_codec *codec,
  167. const struct tabla_mbhc_config *cfg);
  168. struct anc_header {
  169. u32 reserved[3];
  170. u32 num_anc_slots;
  171. };
  172. extern int tabla_mclk_enable(struct snd_soc_codec *codec, int mclk_enable,
  173. bool dapm);
  174. extern void *tabla_mbhc_cal_btn_det_mp(const struct tabla_mbhc_btn_detect_cfg
  175. *btn_det,
  176. const enum tabla_mbhc_btn_det_mem mem);
  177. #define TABLA_MBHC_CAL_SIZE(buttons, rload) ( \
  178. sizeof(enum tabla_micbias_num) + \
  179. sizeof(struct tabla_mbhc_general_cfg) + \
  180. sizeof(struct tabla_mbhc_plug_detect_cfg) + \
  181. ((sizeof(s16) + sizeof(s16)) * buttons) + \
  182. sizeof(struct tabla_mbhc_plug_type_cfg) + \
  183. sizeof(struct tabla_mbhc_btn_detect_cfg) + \
  184. sizeof(struct tabla_mbhc_imped_detect_cfg) + \
  185. ((sizeof(u16) + sizeof(u16)) * rload) \
  186. )
  187. #define TABLA_MBHC_CAL_GENERAL_PTR(cali) ( \
  188. (struct tabla_mbhc_general_cfg *) cali)
  189. #define TABLA_MBHC_CAL_PLUG_DET_PTR(cali) ( \
  190. (struct tabla_mbhc_plug_detect_cfg *) \
  191. &(TABLA_MBHC_CAL_GENERAL_PTR(cali)[1]))
  192. #define TABLA_MBHC_CAL_PLUG_TYPE_PTR(cali) ( \
  193. (struct tabla_mbhc_plug_type_cfg *) \
  194. &(TABLA_MBHC_CAL_PLUG_DET_PTR(cali)[1]))
  195. #define TABLA_MBHC_CAL_BTN_DET_PTR(cali) ( \
  196. (struct tabla_mbhc_btn_detect_cfg *) \
  197. &(TABLA_MBHC_CAL_PLUG_TYPE_PTR(cali)[1]))
  198. #define TABLA_MBHC_CAL_IMPED_DET_PTR(cali) ( \
  199. (struct tabla_mbhc_imped_detect_cfg *) \
  200. (((void *)&TABLA_MBHC_CAL_BTN_DET_PTR(cali)[1]) + \
  201. (TABLA_MBHC_CAL_BTN_DET_PTR(cali)->num_btn * \
  202. (sizeof(TABLA_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_low[0]) + \
  203. sizeof(TABLA_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_high[0])))) \
  204. )
  205. /* minimum size of calibration data assuming there is only one button and
  206. * one rload.
  207. */
  208. #define TABLA_MBHC_CAL_MIN_SIZE ( \
  209. sizeof(struct tabla_mbhc_general_cfg) + \
  210. sizeof(struct tabla_mbhc_plug_detect_cfg) + \
  211. sizeof(struct tabla_mbhc_plug_type_cfg) + \
  212. sizeof(struct tabla_mbhc_btn_detect_cfg) + \
  213. sizeof(struct tabla_mbhc_imped_detect_cfg) + \
  214. (sizeof(u16) * 2))
  215. #define TABLA_MBHC_CAL_BTN_SZ(cfg_ptr) ( \
  216. sizeof(struct tabla_mbhc_btn_detect_cfg) + \
  217. (cfg_ptr->num_btn * (sizeof(cfg_ptr->_v_btn_low[0]) + \
  218. sizeof(cfg_ptr->_v_btn_high[0]))))
  219. #define TABLA_MBHC_CAL_IMPED_MIN_SZ ( \
  220. sizeof(struct tabla_mbhc_imped_detect_cfg) + \
  221. sizeof(u16) * 2)
  222. #define TABLA_MBHC_CAL_IMPED_SZ(cfg_ptr) ( \
  223. sizeof(struct tabla_mbhc_imped_detect_cfg) + \
  224. (cfg_ptr->_n_rload * (sizeof(cfg_ptr->_rload[0]) + \
  225. sizeof(cfg_ptr->_alpha[0]))))
  226. /* Number of input and output Slimbus port */
  227. enum {
  228. TABLA_RX1 = 0,
  229. TABLA_RX2,
  230. TABLA_RX3,
  231. TABLA_RX4,
  232. TABLA_RX5,
  233. TABLA_RX6,
  234. TABLA_RX7,
  235. TABLA_RX_MAX,
  236. };
  237. enum {
  238. TABLA_TX1 = 0,
  239. TABLA_TX2,
  240. TABLA_TX3,
  241. TABLA_TX4,
  242. TABLA_TX5,
  243. TABLA_TX6,
  244. TABLA_TX7,
  245. TABLA_TX8,
  246. TABLA_TX9,
  247. TABLA_TX10,
  248. TABLA_TX_MAX,
  249. };