mt6359-accdet.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2021 MediaTek Inc.
  4. * Author: Argus Lin <[email protected]>
  5. */
  6. #ifndef _ACCDET_H_
  7. #define _ACCDET_H_
  8. #include <linux/ctype.h>
  9. #include <linux/string.h>
  10. #define ACCDET_DEVNAME "accdet"
  11. #define HEADSET_MODE_1 (1)
  12. #define HEADSET_MODE_2 (2)
  13. #define HEADSET_MODE_6 (6)
  14. #define MT6359_ACCDET_NUM_BUTTONS 4
  15. #define MT6359_ACCDET_JACK_MASK (SND_JACK_HEADPHONE | \
  16. SND_JACK_HEADSET | \
  17. SND_JACK_BTN_0 | \
  18. SND_JACK_BTN_1 | \
  19. SND_JACK_BTN_2 | \
  20. SND_JACK_BTN_3)
  21. #define MT6359_ACCDET_BTN_MASK (SND_JACK_BTN_0 | \
  22. SND_JACK_BTN_1 | \
  23. SND_JACK_BTN_2 | \
  24. SND_JACK_BTN_3)
  25. enum eint_moisture_status {
  26. M_PLUG_IN = 0,
  27. M_WATER_IN = 1,
  28. M_HP_PLUG_IN = 2,
  29. M_PLUG_OUT = 3,
  30. M_NO_ACT = 4,
  31. M_UNKNOWN = 5,
  32. };
  33. enum {
  34. accdet_state000 = 0,
  35. accdet_state001,
  36. accdet_state010,
  37. accdet_state011,
  38. accdet_auxadc,
  39. eint_state000,
  40. eint_state001,
  41. eint_state010,
  42. eint_state011,
  43. eint_inverter_state000,
  44. };
  45. struct three_key_threshold {
  46. unsigned int mid;
  47. unsigned int up;
  48. unsigned int down;
  49. };
  50. struct four_key_threshold {
  51. unsigned int mid;
  52. unsigned int voice;
  53. unsigned int up;
  54. unsigned int down;
  55. };
  56. struct pwm_deb_settings {
  57. unsigned int pwm_width;
  58. unsigned int pwm_thresh;
  59. unsigned int fall_delay;
  60. unsigned int rise_delay;
  61. unsigned int debounce0;
  62. unsigned int debounce1;
  63. unsigned int debounce3;
  64. unsigned int debounce4;
  65. unsigned int eint_pwm_width;
  66. unsigned int eint_pwm_thresh;
  67. unsigned int eint_debounce0;
  68. unsigned int eint_debounce1;
  69. unsigned int eint_debounce2;
  70. unsigned int eint_debounce3;
  71. unsigned int eint_inverter_debounce;
  72. };
  73. struct dts_data {
  74. unsigned int mic_vol;
  75. unsigned int mic_mode;
  76. unsigned int plugout_deb;
  77. unsigned int eint_pol;
  78. struct pwm_deb_settings *pwm_deb;
  79. struct three_key_threshold three_key;
  80. struct four_key_threshold four_key;
  81. unsigned int moisture_detect_enable;
  82. unsigned int eint_detect_mode;
  83. unsigned int eint_use_ext_res;
  84. unsigned int eint_comp_vth;
  85. unsigned int moisture_detect_mode;
  86. unsigned int moisture_comp_vth;
  87. unsigned int moisture_comp_vref2;
  88. unsigned int moisture_use_ext_res;
  89. };
  90. struct mt6359_accdet {
  91. struct snd_soc_jack *jack;
  92. struct device *dev;
  93. struct regmap *regmap;
  94. struct dts_data *data;
  95. unsigned int caps;
  96. int accdet_irq;
  97. int accdet_eint0;
  98. int accdet_eint1;
  99. struct mutex res_lock; /* lock protection */
  100. bool jack_plugged;
  101. unsigned int jack_type;
  102. unsigned int btn_type;
  103. unsigned int accdet_status;
  104. unsigned int pre_accdet_status;
  105. unsigned int cali_voltage;
  106. unsigned int jd_sts;
  107. struct work_struct accdet_work;
  108. struct workqueue_struct *accdet_workqueue;
  109. struct work_struct jd_work;
  110. struct workqueue_struct *jd_workqueue;
  111. };
  112. int mt6359_accdet_enable_jack_detect(struct snd_soc_component *component,
  113. struct snd_soc_jack *jack);
  114. #endif