1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2021 MediaTek Inc.
4 * Author: Argus Lin <argus.lin@mediatek.com>
10 #include <linux/ctype.h>
11 #include <linux/string.h>
13 #define ACCDET_DEVNAME "accdet"
15 #define HEADSET_MODE_1 (1)
16 #define HEADSET_MODE_2 (2)
17 #define HEADSET_MODE_6 (6)
19 #define MT6359_ACCDET_NUM_BUTTONS 4
20 #define MT6359_ACCDET_JACK_MASK (SND_JACK_HEADPHONE | \
26 #define MT6359_ACCDET_BTN_MASK (SND_JACK_BTN_0 | \
31 enum eint_moisture_status {
50 eint_inverter_state000,
53 struct three_key_threshold {
59 struct four_key_threshold {
66 struct pwm_deb_settings {
67 unsigned int pwm_width;
68 unsigned int pwm_thresh;
69 unsigned int fall_delay;
70 unsigned int rise_delay;
71 unsigned int debounce0;
72 unsigned int debounce1;
73 unsigned int debounce3;
74 unsigned int debounce4;
75 unsigned int eint_pwm_width;
76 unsigned int eint_pwm_thresh;
77 unsigned int eint_debounce0;
78 unsigned int eint_debounce1;
79 unsigned int eint_debounce2;
80 unsigned int eint_debounce3;
81 unsigned int eint_inverter_debounce;
87 unsigned int mic_mode;
88 unsigned int plugout_deb;
89 unsigned int eint_pol;
90 struct pwm_deb_settings *pwm_deb;
91 struct three_key_threshold three_key;
92 struct four_key_threshold four_key;
93 unsigned int moisture_detect_enable;
94 unsigned int eint_detect_mode;
95 unsigned int eint_use_ext_res;
96 unsigned int eint_comp_vth;
97 unsigned int moisture_detect_mode;
98 unsigned int moisture_comp_vth;
99 unsigned int moisture_comp_vref2;
100 unsigned int moisture_use_ext_res;
103 struct mt6359_accdet {
104 struct snd_soc_jack *jack;
106 struct regmap *regmap;
107 struct dts_data *data;
112 struct mutex res_lock; /* lock protection */
114 unsigned int jack_type;
115 unsigned int btn_type;
116 unsigned int accdet_status;
117 unsigned int pre_accdet_status;
118 unsigned int cali_voltage;
120 struct work_struct accdet_work;
121 struct workqueue_struct *accdet_workqueue;
122 struct work_struct jd_work;
123 struct workqueue_struct *jd_workqueue;
126 int mt6359_accdet_enable_jack_detect(struct snd_soc_component *component,
127 struct snd_soc_jack *jack);