Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (C) 2021 MediaTek Inc.
0004  * Author: Argus Lin <argus.lin@mediatek.com>
0005  */
0006 
0007 #ifndef _ACCDET_H_
0008 #define _ACCDET_H_
0009 
0010 #include <linux/ctype.h>
0011 #include <linux/string.h>
0012 
0013 #define ACCDET_DEVNAME "accdet"
0014 
0015 #define HEADSET_MODE_1      (1)
0016 #define HEADSET_MODE_2      (2)
0017 #define HEADSET_MODE_6      (6)
0018 
0019 #define MT6359_ACCDET_NUM_BUTTONS 4
0020 #define MT6359_ACCDET_JACK_MASK (SND_JACK_HEADPHONE | \
0021                 SND_JACK_HEADSET | \
0022                 SND_JACK_BTN_0 | \
0023                 SND_JACK_BTN_1 | \
0024                 SND_JACK_BTN_2 | \
0025                 SND_JACK_BTN_3)
0026 #define MT6359_ACCDET_BTN_MASK (SND_JACK_BTN_0 | \
0027                 SND_JACK_BTN_1 | \
0028                 SND_JACK_BTN_2 | \
0029                 SND_JACK_BTN_3)
0030 
0031 enum eint_moisture_status {
0032     M_PLUG_IN =     0,
0033     M_WATER_IN =        1,
0034     M_HP_PLUG_IN =      2,
0035     M_PLUG_OUT =        3,
0036     M_NO_ACT =      4,
0037     M_UNKNOWN =     5,
0038 };
0039 
0040 enum {
0041     accdet_state000 = 0,
0042     accdet_state001,
0043     accdet_state010,
0044     accdet_state011,
0045     accdet_auxadc,
0046     eint_state000,
0047     eint_state001,
0048     eint_state010,
0049     eint_state011,
0050     eint_inverter_state000,
0051 };
0052 
0053 struct three_key_threshold {
0054     unsigned int mid;
0055     unsigned int up;
0056     unsigned int down;
0057 };
0058 
0059 struct four_key_threshold {
0060     unsigned int mid;
0061     unsigned int voice;
0062     unsigned int up;
0063     unsigned int down;
0064 };
0065 
0066 struct pwm_deb_settings {
0067     unsigned int pwm_width;
0068     unsigned int pwm_thresh;
0069     unsigned int fall_delay;
0070     unsigned int rise_delay;
0071     unsigned int debounce0;
0072     unsigned int debounce1;
0073     unsigned int debounce3;
0074     unsigned int debounce4;
0075     unsigned int eint_pwm_width;
0076     unsigned int eint_pwm_thresh;
0077     unsigned int eint_debounce0;
0078     unsigned int eint_debounce1;
0079     unsigned int eint_debounce2;
0080     unsigned int eint_debounce3;
0081     unsigned int eint_inverter_debounce;
0082 
0083 };
0084 
0085 struct dts_data {
0086     unsigned int mic_vol;
0087     unsigned int mic_mode;
0088     unsigned int plugout_deb;
0089     unsigned int eint_pol;
0090     struct pwm_deb_settings *pwm_deb;
0091     struct three_key_threshold three_key;
0092     struct four_key_threshold four_key;
0093     unsigned int moisture_detect_enable;
0094     unsigned int eint_detect_mode;
0095     unsigned int eint_use_ext_res;
0096     unsigned int eint_comp_vth;
0097     unsigned int moisture_detect_mode;
0098     unsigned int moisture_comp_vth;
0099     unsigned int moisture_comp_vref2;
0100     unsigned int moisture_use_ext_res;
0101 };
0102 
0103 struct mt6359_accdet {
0104     struct snd_soc_jack *jack;
0105     struct device *dev;
0106     struct regmap *regmap;
0107     struct dts_data *data;
0108     unsigned int caps;
0109     int accdet_irq;
0110     int accdet_eint0;
0111     int accdet_eint1;
0112     struct mutex res_lock; /* lock protection */
0113     bool jack_plugged;
0114     unsigned int jack_type;
0115     unsigned int btn_type;
0116     unsigned int accdet_status;
0117     unsigned int pre_accdet_status;
0118     unsigned int cali_voltage;
0119     unsigned int jd_sts;
0120     struct work_struct accdet_work;
0121     struct workqueue_struct *accdet_workqueue;
0122     struct work_struct jd_work;
0123     struct workqueue_struct *jd_workqueue;
0124 };
0125 
0126 int mt6359_accdet_enable_jack_detect(struct snd_soc_component *component,
0127                      struct snd_soc_jack *jack);
0128 #endif