~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/codecs/mt6359-accdet.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /sound/soc/codecs/mt6359-accdet.c (Version linux-6.11.5) and /sound/soc/codecs/mt6359-accdet.c (Version linux-5.13.19)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 //                                                  2 //
  3 // mt6359-accdet.c  --  ALSA SoC mt6359 accdet      3 // mt6359-accdet.c  --  ALSA SoC mt6359 accdet driver
  4 //                                                  4 //
  5 // Copyright (C) 2021 MediaTek Inc.                 5 // Copyright (C) 2021 MediaTek Inc.
  6 // Author: Argus Lin <argus.lin@mediatek.com>       6 // Author: Argus Lin <argus.lin@mediatek.com>
  7 //                                                  7 //
  8                                                     8 
                                                   >>   9 #include <linux/of_gpio.h>
  9 #include <linux/of.h>                              10 #include <linux/of.h>
                                                   >>  11 #include <linux/of_irq.h>
                                                   >>  12 #include <linux/of_device.h>
                                                   >>  13 #include <linux/of_address.h>
 10 #include <linux/input.h>                           14 #include <linux/input.h>
 11 #include <linux/kthread.h>                         15 #include <linux/kthread.h>
 12 #include <linux/io.h>                              16 #include <linux/io.h>
 13 #include <linux/sched/clock.h>                     17 #include <linux/sched/clock.h>
 14 #include <linux/workqueue.h>                       18 #include <linux/workqueue.h>
 15 #include <linux/timer.h>                           19 #include <linux/timer.h>
 16 #include <linux/delay.h>                           20 #include <linux/delay.h>
 17 #include <linux/module.h>                          21 #include <linux/module.h>
 18 #include <linux/platform_device.h>                 22 #include <linux/platform_device.h>
 19 #include <linux/init.h>                            23 #include <linux/init.h>
 20 #include <linux/irqdomain.h>                       24 #include <linux/irqdomain.h>
 21 #include <linux/irq.h>                             25 #include <linux/irq.h>
 22 #include <linux/regmap.h>                          26 #include <linux/regmap.h>
 23 #include <sound/soc.h>                             27 #include <sound/soc.h>
 24 #include <sound/jack.h>                            28 #include <sound/jack.h>
 25 #include <linux/mfd/mt6397/core.h>                 29 #include <linux/mfd/mt6397/core.h>
 26                                                    30 
 27 #include "mt6359-accdet.h"                         31 #include "mt6359-accdet.h"
 28 #include "mt6359.h"                                32 #include "mt6359.h"
 29                                                    33 
 30 /* global variable definitions */                  34 /* global variable definitions */
 31 #define REGISTER_VAL(x) ((x) - 1)                  35 #define REGISTER_VAL(x) ((x) - 1)
 32                                                    36 
 33 /* mt6359 accdet capability */                     37 /* mt6359 accdet capability */
 34 #define ACCDET_PMIC_EINT_IRQ            BIT(0)     38 #define ACCDET_PMIC_EINT_IRQ            BIT(0)
 35 #define ACCDET_AP_GPIO_EINT             BIT(1)     39 #define ACCDET_AP_GPIO_EINT             BIT(1)
 36                                                    40 
 37 #define ACCDET_PMIC_EINT0               BIT(2)     41 #define ACCDET_PMIC_EINT0               BIT(2)
 38 #define ACCDET_PMIC_EINT1               BIT(3)     42 #define ACCDET_PMIC_EINT1               BIT(3)
 39 #define ACCDET_PMIC_BI_EINT             BIT(4)     43 #define ACCDET_PMIC_BI_EINT             BIT(4)
 40                                                    44 
 41 #define ACCDET_PMIC_GPIO_TRIG_EINT      BIT(5)     45 #define ACCDET_PMIC_GPIO_TRIG_EINT      BIT(5)
 42 #define ACCDET_PMIC_INVERTER_TRIG_EINT  BIT(6)     46 #define ACCDET_PMIC_INVERTER_TRIG_EINT  BIT(6)
 43 #define ACCDET_PMIC_RSV_EINT            BIT(7)     47 #define ACCDET_PMIC_RSV_EINT            BIT(7)
 44                                                    48 
 45 #define ACCDET_THREE_KEY                BIT(8)     49 #define ACCDET_THREE_KEY                BIT(8)
 46 #define ACCDET_FOUR_KEY                 BIT(9)     50 #define ACCDET_FOUR_KEY                 BIT(9)
 47 #define ACCDET_TRI_KEY_CDD              BIT(10     51 #define ACCDET_TRI_KEY_CDD              BIT(10)
 48 #define ACCDET_RSV_KEY                  BIT(11     52 #define ACCDET_RSV_KEY                  BIT(11)
 49                                                    53 
 50 #define ACCDET_ANALOG_FASTDISCHARGE     BIT(12     54 #define ACCDET_ANALOG_FASTDISCHARGE     BIT(12)
 51 #define ACCDET_DIGITAL_FASTDISCHARGE    BIT(13     55 #define ACCDET_DIGITAL_FASTDISCHARGE    BIT(13)
 52 #define ACCDET_AD_FASTDISCHRAGE         BIT(14     56 #define ACCDET_AD_FASTDISCHRAGE         BIT(14)
 53                                                    57 
 54 static struct platform_driver mt6359_accdet_dr     58 static struct platform_driver mt6359_accdet_driver;
 55 static const struct snd_soc_component_driver m     59 static const struct snd_soc_component_driver mt6359_accdet_soc_driver;
 56                                                    60 
 57 /* local function declaration */                   61 /* local function declaration */
 58 static void accdet_set_debounce(struct mt6359_     62 static void accdet_set_debounce(struct mt6359_accdet *priv, int state,
 59                                 unsigned int d     63                                 unsigned int debounce);
 60 static unsigned int adjust_eint_analog_setting     64 static unsigned int adjust_eint_analog_setting(struct mt6359_accdet *priv);
 61 static void config_digital_init_by_mode(struct     65 static void config_digital_init_by_mode(struct mt6359_accdet *priv);
 62 static void config_eint_init_by_mode(struct mt     66 static void config_eint_init_by_mode(struct mt6359_accdet *priv);
 63 static inline void mt6359_accdet_init(struct m     67 static inline void mt6359_accdet_init(struct mt6359_accdet *priv);
 64 static unsigned int mt6359_accdet_jd_setting(s     68 static unsigned int mt6359_accdet_jd_setting(struct mt6359_accdet *priv);
 65 static void mt6359_accdet_recover_jd_setting(s     69 static void mt6359_accdet_recover_jd_setting(struct mt6359_accdet *priv);
 66 static void mt6359_accdet_jack_report(struct m     70 static void mt6359_accdet_jack_report(struct mt6359_accdet *priv);
 67 static void recover_eint_analog_setting(struct     71 static void recover_eint_analog_setting(struct mt6359_accdet *priv);
 68 static void recover_eint_digital_setting(struc     72 static void recover_eint_digital_setting(struct mt6359_accdet *priv);
 69 static void recover_eint_setting(struct mt6359     73 static void recover_eint_setting(struct mt6359_accdet *priv);
 70                                                    74 
 71 static unsigned int adjust_eint_analog_setting     75 static unsigned int adjust_eint_analog_setting(struct mt6359_accdet *priv)
 72 {                                                  76 {
 73         if (priv->data->eint_detect_mode == 0x     77         if (priv->data->eint_detect_mode == 0x3 ||
 74             priv->data->eint_detect_mode == 0x     78             priv->data->eint_detect_mode == 0x4) {
 75                 /* ESD switches off */             79                 /* ESD switches off */
 76                 regmap_update_bits(priv->regma     80                 regmap_update_bits(priv->regmap,
 77                                    RG_ACCDETSP     81                                    RG_ACCDETSPARE_ADDR, 1 << 8, 0);
 78         }                                          82         }
 79         if (priv->data->eint_detect_mode == 0x     83         if (priv->data->eint_detect_mode == 0x4) {
 80                 if (priv->caps & ACCDET_PMIC_E     84                 if (priv->caps & ACCDET_PMIC_EINT0) {
 81                         /* enable RG_EINT0CONF     85                         /* enable RG_EINT0CONFIGACCDET */
 82                         regmap_update_bits(pri     86                         regmap_update_bits(priv->regmap,
 83                                            RG_     87                                            RG_EINT0CONFIGACCDET_ADDR,
 84                                            RG_     88                                            RG_EINT0CONFIGACCDET_MASK_SFT,
 85                                            BIT     89                                            BIT(RG_EINT0CONFIGACCDET_SFT));
 86                 } else if (priv->caps & ACCDET     90                 } else if (priv->caps & ACCDET_PMIC_EINT1) {
 87                         /* enable RG_EINT1CONF     91                         /* enable RG_EINT1CONFIGACCDET */
 88                         regmap_update_bits(pri     92                         regmap_update_bits(priv->regmap,
 89                                            RG_     93                                            RG_EINT1CONFIGACCDET_ADDR,
 90                                            RG_     94                                            RG_EINT1CONFIGACCDET_MASK_SFT,
 91                                            BIT     95                                            BIT(RG_EINT1CONFIGACCDET_SFT));
 92                 }                                  96                 }
 93                 if (priv->data->eint_use_ext_r     97                 if (priv->data->eint_use_ext_res == 0x3 ||
 94                     priv->data->eint_use_ext_r     98                     priv->data->eint_use_ext_res == 0x4) {
 95                         /*select 500k, use int     99                         /*select 500k, use internal resistor */
 96                         regmap_update_bits(pri    100                         regmap_update_bits(priv->regmap,
 97                                            RG_    101                                            RG_EINT0HIRENB_ADDR,
 98                                            RG_    102                                            RG_EINT0HIRENB_MASK_SFT,
 99                                            BIT    103                                            BIT(RG_EINT0HIRENB_SFT));
100                 }                                 104                 }
101         }                                         105         }
102         return 0;                                 106         return 0;
103 }                                                 107 }
104                                                   108 
105 static unsigned int adjust_eint_digital_settin    109 static unsigned int adjust_eint_digital_setting(struct mt6359_accdet *priv)
106 {                                                 110 {
107         if (priv->caps & ACCDET_PMIC_EINT0) {     111         if (priv->caps & ACCDET_PMIC_EINT0) {
108                 /* disable inverter */            112                 /* disable inverter */
109                 regmap_update_bits(priv->regma    113                 regmap_update_bits(priv->regmap,
110                                    ACCDET_EINT    114                                    ACCDET_EINT0_INVERTER_SW_EN_ADDR,
111                                    ACCDET_EINT    115                                    ACCDET_EINT0_INVERTER_SW_EN_MASK_SFT, 0);
112         } else if (priv->caps & ACCDET_PMIC_EI    116         } else if (priv->caps & ACCDET_PMIC_EINT1) {
113                 /* disable inverter */            117                 /* disable inverter */
114                 regmap_update_bits(priv->regma    118                 regmap_update_bits(priv->regmap,
115                                    ACCDET_EINT    119                                    ACCDET_EINT1_INVERTER_SW_EN_ADDR,
116                                    ACCDET_EINT    120                                    ACCDET_EINT1_INVERTER_SW_EN_MASK_SFT, 0);
117         }                                         121         }
118                                                   122 
119         if (priv->data->eint_detect_mode == 0x    123         if (priv->data->eint_detect_mode == 0x4) {
120                 if (priv->caps & ACCDET_PMIC_E    124                 if (priv->caps & ACCDET_PMIC_EINT0) {
121                         /* set DA stable signa    125                         /* set DA stable signal */
122                         regmap_update_bits(pri    126                         regmap_update_bits(priv->regmap,
123                                            ACC    127                                            ACCDET_DA_STABLE_ADDR,
124                                            ACC    128                                            ACCDET_EINT0_CEN_STABLE_MASK_SFT, 0);
125                 } else if (priv->caps & ACCDET    129                 } else if (priv->caps & ACCDET_PMIC_EINT1) {
126                         /* set DA stable signa    130                         /* set DA stable signal */
127                         regmap_update_bits(pri    131                         regmap_update_bits(priv->regmap,
128                                            ACC    132                                            ACCDET_DA_STABLE_ADDR,
129                                            ACC    133                                            ACCDET_EINT1_CEN_STABLE_MASK_SFT, 0);
130                 }                                 134                 }
131         }                                         135         }
132         return 0;                                 136         return 0;
133 }                                                 137 }
134                                                   138 
135 static unsigned int mt6359_accdet_jd_setting(s    139 static unsigned int mt6359_accdet_jd_setting(struct mt6359_accdet *priv)
136 {                                                 140 {
137         if (priv->jd_sts == M_PLUG_IN) {          141         if (priv->jd_sts == M_PLUG_IN) {
138                 /* adjust digital setting */      142                 /* adjust digital setting */
139                 adjust_eint_digital_setting(pr    143                 adjust_eint_digital_setting(priv);
140                 /* adjust analog setting */       144                 /* adjust analog setting */
141                 adjust_eint_analog_setting(pri    145                 adjust_eint_analog_setting(priv);
142         } else if (priv->jd_sts == M_PLUG_OUT)    146         } else if (priv->jd_sts == M_PLUG_OUT) {
143                 /* set debounce to 1ms */         147                 /* set debounce to 1ms */
144                 accdet_set_debounce(priv, eint    148                 accdet_set_debounce(priv, eint_state000,
145                                     priv->data    149                                     priv->data->pwm_deb->eint_debounce0);
146         } else {                                  150         } else {
147                 dev_dbg(priv->dev, "should not    151                 dev_dbg(priv->dev, "should not be here %s()\n", __func__);
148         }                                         152         }
149                                                   153 
150         return 0;                                 154         return 0;
151 }                                                 155 }
152                                                   156 
153 static void recover_eint_analog_setting(struct    157 static void recover_eint_analog_setting(struct mt6359_accdet *priv)
154 {                                                 158 {
155         if (priv->data->eint_detect_mode == 0x    159         if (priv->data->eint_detect_mode == 0x3 ||
156             priv->data->eint_detect_mode == 0x    160             priv->data->eint_detect_mode == 0x4) {
157                 /* ESD switches on */             161                 /* ESD switches on */
158                 regmap_update_bits(priv->regma    162                 regmap_update_bits(priv->regmap, RG_ACCDETSPARE_ADDR,
159                                    1 << 8, 1 <    163                                    1 << 8, 1 << 8);
160         }                                         164         }
161         if (priv->data->eint_detect_mode == 0x    165         if (priv->data->eint_detect_mode == 0x4) {
162                 if (priv->caps & ACCDET_PMIC_E    166                 if (priv->caps & ACCDET_PMIC_EINT0) {
163                         /* disable RG_EINT0CON    167                         /* disable RG_EINT0CONFIGACCDET */
164                         regmap_update_bits(pri    168                         regmap_update_bits(priv->regmap,
165                                            RG_    169                                            RG_EINT0CONFIGACCDET_ADDR,
166                                            RG_    170                                            RG_EINT0CONFIGACCDET_MASK_SFT, 0);
167                 } else if (priv->caps & ACCDET    171                 } else if (priv->caps & ACCDET_PMIC_EINT1) {
168                         /* disable RG_EINT1CON    172                         /* disable RG_EINT1CONFIGACCDET */
169                         regmap_update_bits(pri    173                         regmap_update_bits(priv->regmap,
170                                            RG_    174                                            RG_EINT1CONFIGACCDET_ADDR,
171                                            RG_    175                                            RG_EINT1CONFIGACCDET_MASK_SFT, 0);
172                 }                                 176                 }
173                 regmap_update_bits(priv->regma    177                 regmap_update_bits(priv->regmap, RG_EINT0HIRENB_ADDR,
174                                    RG_EINT0HIR    178                                    RG_EINT0HIRENB_MASK_SFT, 0);
175         }                                         179         }
176 }                                                 180 }
177                                                   181 
178 static void recover_eint_digital_setting(struc    182 static void recover_eint_digital_setting(struct mt6359_accdet *priv)
179 {                                                 183 {
180         if (priv->caps & ACCDET_PMIC_EINT0) {     184         if (priv->caps & ACCDET_PMIC_EINT0) {
181                 regmap_update_bits(priv->regma    185                 regmap_update_bits(priv->regmap,
182                                    ACCDET_EINT    186                                    ACCDET_EINT0_M_SW_EN_ADDR,
183                                    ACCDET_EINT    187                                    ACCDET_EINT0_M_SW_EN_MASK_SFT, 0);
184         } else if (priv->caps & ACCDET_PMIC_EI    188         } else if (priv->caps & ACCDET_PMIC_EINT1) {
185                 regmap_update_bits(priv->regma    189                 regmap_update_bits(priv->regmap,
186                                    ACCDET_EINT    190                                    ACCDET_EINT1_M_SW_EN_ADDR,
187                                    ACCDET_EINT    191                                    ACCDET_EINT1_M_SW_EN_MASK_SFT, 0);
188         }                                         192         }
189         if (priv->data->eint_detect_mode == 0x    193         if (priv->data->eint_detect_mode == 0x4) {
190                 /* enable eint0cen */             194                 /* enable eint0cen */
191                 if (priv->caps & ACCDET_PMIC_E    195                 if (priv->caps & ACCDET_PMIC_EINT0) {
192                         /* enable eint0cen */     196                         /* enable eint0cen */
193                         regmap_update_bits(pri    197                         regmap_update_bits(priv->regmap,
194                                            ACC    198                                            ACCDET_DA_STABLE_ADDR,
195                                            ACC    199                                            ACCDET_EINT0_CEN_STABLE_MASK_SFT,
196                                            BIT    200                                            BIT(ACCDET_EINT0_CEN_STABLE_SFT));
197                 } else if (priv->caps & ACCDET    201                 } else if (priv->caps & ACCDET_PMIC_EINT1) {
198                         /* enable eint1cen */     202                         /* enable eint1cen */
199                         regmap_update_bits(pri    203                         regmap_update_bits(priv->regmap,
200                                            ACC    204                                            ACCDET_DA_STABLE_ADDR,
201                                            ACC    205                                            ACCDET_EINT1_CEN_STABLE_MASK_SFT,
202                                            BIT    206                                            BIT(ACCDET_EINT1_CEN_STABLE_SFT));
203                 }                                 207                 }
204         }                                         208         }
205                                                   209 
206         if (priv->data->eint_detect_mode != 0x    210         if (priv->data->eint_detect_mode != 0x1) {
207                 if (priv->caps & ACCDET_PMIC_E    211                 if (priv->caps & ACCDET_PMIC_EINT0) {
208                         /* enable inverter */     212                         /* enable inverter */
209                         regmap_update_bits(pri    213                         regmap_update_bits(priv->regmap,
210                                            ACC    214                                            ACCDET_EINT0_INVERTER_SW_EN_ADDR,
211                                            ACC    215                                            ACCDET_EINT0_INVERTER_SW_EN_MASK_SFT,
212                                            BIT    216                                            BIT(ACCDET_EINT0_INVERTER_SW_EN_SFT));
213                 } else if (priv->caps & ACCDET    217                 } else if (priv->caps & ACCDET_PMIC_EINT1) {
214                         /* enable inverter */     218                         /* enable inverter */
215                         regmap_update_bits(pri    219                         regmap_update_bits(priv->regmap,
216                                            ACC    220                                            ACCDET_EINT1_INVERTER_SW_EN_ADDR,
217                                            ACC    221                                            ACCDET_EINT1_INVERTER_SW_EN_MASK_SFT,
218                                            BIT    222                                            BIT(ACCDET_EINT1_INVERTER_SW_EN_SFT));
219                 }                                 223                 }
220         }                                         224         }
221 }                                                 225 }
222                                                   226 
223 static void recover_eint_setting(struct mt6359    227 static void recover_eint_setting(struct mt6359_accdet *priv)
224 {                                                 228 {
225         if (priv->jd_sts == M_PLUG_OUT) {         229         if (priv->jd_sts == M_PLUG_OUT) {
226                 recover_eint_analog_setting(pr    230                 recover_eint_analog_setting(priv);
227                 recover_eint_digital_setting(p    231                 recover_eint_digital_setting(priv);
228         }                                         232         }
229 }                                                 233 }
230                                                   234 
231 static void mt6359_accdet_recover_jd_setting(s    235 static void mt6359_accdet_recover_jd_setting(struct mt6359_accdet *priv)
232 {                                                 236 {
233         int ret;                               !! 237         int ret = 0;
234         unsigned int value = 0;                   238         unsigned int value = 0;
235                                                   239 
236         regmap_update_bits(priv->regmap, ACCDE    240         regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR,
237                            ACCDET_IRQ_CLR_MASK    241                            ACCDET_IRQ_CLR_MASK_SFT, BIT(ACCDET_IRQ_CLR_SFT));
238         usleep_range(200, 300);                   242         usleep_range(200, 300);
239         ret = regmap_read_poll_timeout(priv->r    243         ret = regmap_read_poll_timeout(priv->regmap,
240                                        ACCDET_    244                                        ACCDET_IRQ_ADDR,
241                                        value,     245                                        value,
242                                        (value     246                                        (value & ACCDET_IRQ_MASK_SFT) == 0,
243                                        0,         247                                        0,
244                                        1000);     248                                        1000);
245         if (ret)                                  249         if (ret)
246                 dev_warn(priv->dev, "%s(), ret    250                 dev_warn(priv->dev, "%s(), ret %d\n", __func__, ret);
247         /* clear accdet int, modify  for fix i    251         /* clear accdet int, modify  for fix interrupt trigger twice error */
248         regmap_update_bits(priv->regmap, ACCDE    252         regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR,
249                            ACCDET_IRQ_CLR_MASK    253                            ACCDET_IRQ_CLR_MASK_SFT, 0);
250         regmap_update_bits(priv->regmap, RG_IN    254         regmap_update_bits(priv->regmap, RG_INT_STATUS_ACCDET_ADDR,
251                            RG_INT_STATUS_ACCDE    255                            RG_INT_STATUS_ACCDET_MASK_SFT,
252                            BIT(RG_INT_STATUS_A    256                            BIT(RG_INT_STATUS_ACCDET_SFT));
253                                                   257 
254         /* recover accdet debounce0,3 */          258         /* recover accdet debounce0,3 */
255         accdet_set_debounce(priv, accdet_state    259         accdet_set_debounce(priv, accdet_state000,
256                             priv->data->pwm_de    260                             priv->data->pwm_deb->debounce0);
257         accdet_set_debounce(priv, accdet_state    261         accdet_set_debounce(priv, accdet_state001,
258                             priv->data->pwm_de    262                             priv->data->pwm_deb->debounce1);
259         accdet_set_debounce(priv, accdet_state    263         accdet_set_debounce(priv, accdet_state011,
260                             priv->data->pwm_de    264                             priv->data->pwm_deb->debounce3);
261                                                   265 
262         priv->jack_type = 0;                      266         priv->jack_type = 0;
263         priv->btn_type = 0;                       267         priv->btn_type = 0;
264         priv->accdet_status = 0x3;                268         priv->accdet_status = 0x3;
265         mt6359_accdet_jack_report(priv);          269         mt6359_accdet_jack_report(priv);
266 }                                                 270 }
267                                                   271 
268 static void accdet_set_debounce(struct mt6359_    272 static void accdet_set_debounce(struct mt6359_accdet *priv, int state,
269                                 unsigned int d    273                                 unsigned int debounce)
270 {                                                 274 {
271         switch (state) {                          275         switch (state) {
272         case accdet_state000:                     276         case accdet_state000:
273                 regmap_write(priv->regmap, ACC    277                 regmap_write(priv->regmap, ACCDET_DEBOUNCE0_ADDR, debounce);
274                 break;                            278                 break;
275         case accdet_state001:                     279         case accdet_state001:
276                 regmap_write(priv->regmap, ACC    280                 regmap_write(priv->regmap, ACCDET_DEBOUNCE1_ADDR, debounce);
277                 break;                            281                 break;
278         case accdet_state010:                     282         case accdet_state010:
279                 regmap_write(priv->regmap, ACC    283                 regmap_write(priv->regmap, ACCDET_DEBOUNCE2_ADDR, debounce);
280                 break;                            284                 break;
281         case accdet_state011:                     285         case accdet_state011:
282                 regmap_write(priv->regmap, ACC    286                 regmap_write(priv->regmap, ACCDET_DEBOUNCE3_ADDR, debounce);
283                 break;                            287                 break;
284         case accdet_auxadc:                       288         case accdet_auxadc:
285                 regmap_write(priv->regmap,        289                 regmap_write(priv->regmap,
286                              ACCDET_CONNECT_AU    290                              ACCDET_CONNECT_AUXADC_TIME_DIG_ADDR, debounce);
287                 break;                            291                 break;
288         case eint_state000:                       292         case eint_state000:
289                 regmap_update_bits(priv->regma    293                 regmap_update_bits(priv->regmap, ACCDET_EINT_DEBOUNCE0_ADDR,
290                                    0xF << ACCD    294                                    0xF << ACCDET_EINT_DEBOUNCE0_SFT,
291                                    debounce <<    295                                    debounce << ACCDET_EINT_DEBOUNCE0_SFT);
292                 break;                            296                 break;
293         case eint_state001:                       297         case eint_state001:
294                 regmap_update_bits(priv->regma    298                 regmap_update_bits(priv->regmap, ACCDET_EINT_DEBOUNCE1_ADDR,
295                                    0xF << ACCD    299                                    0xF << ACCDET_EINT_DEBOUNCE1_SFT,
296                                    debounce <<    300                                    debounce << ACCDET_EINT_DEBOUNCE1_SFT);
297                 break;                            301                 break;
298         case eint_state010:                       302         case eint_state010:
299                 regmap_update_bits(priv->regma    303                 regmap_update_bits(priv->regmap, ACCDET_EINT_DEBOUNCE2_ADDR,
300                                    0xF << ACCD    304                                    0xF << ACCDET_EINT_DEBOUNCE2_SFT,
301                                    debounce <<    305                                    debounce << ACCDET_EINT_DEBOUNCE2_SFT);
302                 break;                            306                 break;
303         case eint_state011:                       307         case eint_state011:
304                 regmap_update_bits(priv->regma    308                 regmap_update_bits(priv->regmap, ACCDET_EINT_DEBOUNCE3_ADDR,
305                                    0xF << ACCD    309                                    0xF << ACCDET_EINT_DEBOUNCE3_SFT,
306                                    debounce <<    310                                    debounce << ACCDET_EINT_DEBOUNCE3_SFT);
307                 break;                            311                 break;
308         case eint_inverter_state000:              312         case eint_inverter_state000:
309                 regmap_write(priv->regmap, ACC    313                 regmap_write(priv->regmap, ACCDET_EINT_INVERTER_DEBOUNCE_ADDR,
310                              debounce);           314                              debounce);
311                 break;                            315                 break;
312         default:                                  316         default:
313                 dev_warn(priv->dev, "Error: %s    317                 dev_warn(priv->dev, "Error: %s error state (%d)\n", __func__,
314                          state);                  318                          state);
315                 break;                            319                 break;
316         }                                         320         }
317 }                                                 321 }
318                                                   322 
319 static void mt6359_accdet_jack_report(struct m    323 static void mt6359_accdet_jack_report(struct mt6359_accdet *priv)
320 {                                                 324 {
321         int report = 0;                           325         int report = 0;
322                                                   326 
323         if (!priv->jack)                          327         if (!priv->jack)
324                 return;                           328                 return;
325                                                   329 
326         report = priv->jack_type | priv->btn_t    330         report = priv->jack_type | priv->btn_type;
327         snd_soc_jack_report(priv->jack, report    331         snd_soc_jack_report(priv->jack, report, MT6359_ACCDET_JACK_MASK);
328 }                                                 332 }
329                                                   333 
330 static unsigned int check_button(struct mt6359    334 static unsigned int check_button(struct mt6359_accdet *priv, unsigned int v)
331 {                                                 335 {
332         if (priv->caps & ACCDET_FOUR_KEY) {       336         if (priv->caps & ACCDET_FOUR_KEY) {
333                 if (v < priv->data->four_key.d    337                 if (v < priv->data->four_key.down &&
334                     v >= priv->data->four_key.    338                     v >= priv->data->four_key.up)
335                         priv->btn_type = SND_J    339                         priv->btn_type = SND_JACK_BTN_1;
336                 if (v < priv->data->four_key.u    340                 if (v < priv->data->four_key.up &&
337                     v >= priv->data->four_key.    341                     v >= priv->data->four_key.voice)
338                         priv->btn_type = SND_J    342                         priv->btn_type = SND_JACK_BTN_2;
339                 if (v < priv->data->four_key.v    343                 if (v < priv->data->four_key.voice &&
340                     v >= priv->data->four_key.    344                     v >= priv->data->four_key.mid)
341                         priv->btn_type = SND_J    345                         priv->btn_type = SND_JACK_BTN_3;
342                 if (v < priv->data->four_key.m    346                 if (v < priv->data->four_key.mid)
343                         priv->btn_type = SND_J    347                         priv->btn_type = SND_JACK_BTN_0;
344         } else {                                  348         } else {
345                 if (v < priv->data->three_key.    349                 if (v < priv->data->three_key.down &&
346                     v >= priv->data->three_key    350                     v >= priv->data->three_key.up)
347                         priv->btn_type = SND_J    351                         priv->btn_type = SND_JACK_BTN_1;
348                 if (v < priv->data->three_key.    352                 if (v < priv->data->three_key.up &&
349                     v >= priv->data->three_key    353                     v >= priv->data->three_key.mid)
350                         priv->btn_type = SND_J    354                         priv->btn_type = SND_JACK_BTN_2;
351                 if (v < priv->data->three_key.    355                 if (v < priv->data->three_key.mid)
352                         priv->btn_type = SND_J    356                         priv->btn_type = SND_JACK_BTN_0;
353         }                                         357         }
354         return 0;                                 358         return 0;
355 }                                                 359 }
356                                                   360 
357 static void is_key_pressed(struct mt6359_accde    361 static void is_key_pressed(struct mt6359_accdet *priv, bool pressed)
358 {                                                 362 {
359         priv->btn_type = priv->jack_type & ~MT    363         priv->btn_type = priv->jack_type & ~MT6359_ACCDET_BTN_MASK;
360                                                   364 
361         if (pressed)                              365         if (pressed)
362                 check_button(priv, priv->cali_    366                 check_button(priv, priv->cali_voltage);
363 }                                                 367 }
364                                                   368 
365 static inline void check_jack_btn_type(struct     369 static inline void check_jack_btn_type(struct mt6359_accdet *priv)
366 {                                                 370 {
367         unsigned int val = 0;                     371         unsigned int val = 0;
368                                                   372 
369         regmap_read(priv->regmap, ACCDET_MEM_I    373         regmap_read(priv->regmap, ACCDET_MEM_IN_ADDR, &val);
370                                                   374 
371         priv->accdet_status =                     375         priv->accdet_status =
372                 (val >> ACCDET_STATE_MEM_IN_OF    376                 (val >> ACCDET_STATE_MEM_IN_OFFSET) & ACCDET_STATE_AB_MASK;
373                                                   377 
374         switch (priv->accdet_status) {            378         switch (priv->accdet_status) {
375         case 0:                                   379         case 0:
376                 if (priv->jack_type == SND_JAC    380                 if (priv->jack_type == SND_JACK_HEADSET)
377                         is_key_pressed(priv, t    381                         is_key_pressed(priv, true);
378                 else                              382                 else
379                         priv->jack_type = SND_    383                         priv->jack_type = SND_JACK_HEADPHONE;
380                 break;                            384                 break;
381         case 1:                                   385         case 1:
382                 if (priv->jack_type == SND_JAC    386                 if (priv->jack_type == SND_JACK_HEADSET) {
383                         is_key_pressed(priv, f    387                         is_key_pressed(priv, false);
384                 } else {                          388                 } else {
385                         priv->jack_type = SND_    389                         priv->jack_type = SND_JACK_HEADSET;
386                         accdet_set_debounce(pr    390                         accdet_set_debounce(priv, eint_state011, 0x1);
387                 }                                 391                 }
388                 break;                            392                 break;
389         case 3:                                   393         case 3:
390         default:                                  394         default:
391                 priv->jack_type = 0;              395                 priv->jack_type = 0;
392                 break;                            396                 break;
393         }                                         397         }
394 }                                                 398 }
395                                                   399 
396 static void mt6359_accdet_work(struct work_str    400 static void mt6359_accdet_work(struct work_struct *work)
397 {                                                 401 {
398         struct mt6359_accdet *priv =              402         struct mt6359_accdet *priv =
399                 container_of(work, struct mt63    403                 container_of(work, struct mt6359_accdet, accdet_work);
400                                                   404 
401         mutex_lock(&priv->res_lock);              405         mutex_lock(&priv->res_lock);
402         priv->pre_accdet_status = priv->accdet    406         priv->pre_accdet_status = priv->accdet_status;
403         check_jack_btn_type(priv);                407         check_jack_btn_type(priv);
404                                                   408 
405         if (priv->jack_plugged &&                 409         if (priv->jack_plugged &&
406             priv->pre_accdet_status != priv->a    410             priv->pre_accdet_status != priv->accdet_status)
407                 mt6359_accdet_jack_report(priv    411                 mt6359_accdet_jack_report(priv);
408         mutex_unlock(&priv->res_lock);            412         mutex_unlock(&priv->res_lock);
409 }                                                 413 }
410                                                   414 
411 static void mt6359_accdet_jd_work(struct work_    415 static void mt6359_accdet_jd_work(struct work_struct *work)
412 {                                                 416 {
413         int ret;                               !! 417         int ret = 0;
414         unsigned int value = 0;                   418         unsigned int value = 0;
415                                                   419 
416         struct mt6359_accdet *priv =              420         struct mt6359_accdet *priv =
417                 container_of(work, struct mt63    421                 container_of(work, struct mt6359_accdet, jd_work);
418                                                   422 
419         mutex_lock(&priv->res_lock);              423         mutex_lock(&priv->res_lock);
420         if (priv->jd_sts == M_PLUG_IN) {          424         if (priv->jd_sts == M_PLUG_IN) {
421                 priv->jack_plugged = true;        425                 priv->jack_plugged = true;
422                                                   426 
423                 /* set and clear initial bit e    427                 /* set and clear initial bit every eint interrupt */
424                 regmap_update_bits(priv->regma    428                 regmap_update_bits(priv->regmap, ACCDET_SEQ_INIT_ADDR,
425                                    ACCDET_SEQ_    429                                    ACCDET_SEQ_INIT_MASK_SFT,
426                                    BIT(ACCDET_    430                                    BIT(ACCDET_SEQ_INIT_SFT));
427                 regmap_update_bits(priv->regma    431                 regmap_update_bits(priv->regmap, ACCDET_SEQ_INIT_ADDR,
428                                    ACCDET_SEQ_    432                                    ACCDET_SEQ_INIT_MASK_SFT, 0);
429                 ret = regmap_read_poll_timeout    433                 ret = regmap_read_poll_timeout(priv->regmap,
430                                                   434                                                ACCDET_SEQ_INIT_ADDR,
431                                                   435                                                value,
432                                                   436                                                (value & ACCDET_SEQ_INIT_MASK_SFT) == 0,
433                                                   437                                                0,
434                                                   438                                                1000);
435                 if (ret)                          439                 if (ret)
436                         dev_err(priv->dev, "%s    440                         dev_err(priv->dev, "%s(), ret %d\n", __func__, ret);
437                                                   441 
438                 /* enable ACCDET unit */          442                 /* enable ACCDET unit */
439                 regmap_update_bits(priv->regma    443                 regmap_update_bits(priv->regmap, ACCDET_SW_EN_ADDR,
440                                    ACCDET_SW_E    444                                    ACCDET_SW_EN_MASK_SFT, BIT(ACCDET_SW_EN_SFT));
441         } else if (priv->jd_sts == M_PLUG_OUT)    445         } else if (priv->jd_sts == M_PLUG_OUT) {
442                 priv->jack_plugged = false;       446                 priv->jack_plugged = false;
443                                                   447 
444                 accdet_set_debounce(priv, accd    448                 accdet_set_debounce(priv, accdet_state011,
445                                     priv->data    449                                     priv->data->pwm_deb->debounce3);
446                 regmap_update_bits(priv->regma    450                 regmap_update_bits(priv->regmap, ACCDET_SW_EN_ADDR,
447                                    ACCDET_SW_E    451                                    ACCDET_SW_EN_MASK_SFT, 0);
448                 mt6359_accdet_recover_jd_setti    452                 mt6359_accdet_recover_jd_setting(priv);
449         }                                         453         }
450                                                   454 
451         if (priv->caps & ACCDET_PMIC_EINT_IRQ)    455         if (priv->caps & ACCDET_PMIC_EINT_IRQ)
452                 recover_eint_setting(priv);       456                 recover_eint_setting(priv);
453         mutex_unlock(&priv->res_lock);            457         mutex_unlock(&priv->res_lock);
454 }                                                 458 }
455                                                   459 
456 static irqreturn_t mt6359_accdet_irq(int irq,     460 static irqreturn_t mt6359_accdet_irq(int irq, void *data)
457 {                                                 461 {
458         struct mt6359_accdet *priv = data;        462         struct mt6359_accdet *priv = data;
459         unsigned int irq_val = 0, val = 0, val    463         unsigned int irq_val = 0, val = 0, value = 0;
460         int ret;                               !! 464         int ret = 0;
461                                                   465 
462         mutex_lock(&priv->res_lock);              466         mutex_lock(&priv->res_lock);
463         regmap_read(priv->regmap, ACCDET_IRQ_A    467         regmap_read(priv->regmap, ACCDET_IRQ_ADDR, &irq_val);
464                                                   468 
465         if (irq_val & ACCDET_IRQ_MASK_SFT) {      469         if (irq_val & ACCDET_IRQ_MASK_SFT) {
466                 regmap_update_bits(priv->regma    470                 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR,
467                                    ACCDET_IRQ_    471                                    ACCDET_IRQ_CLR_MASK_SFT,
468                                    BIT(ACCDET_    472                                    BIT(ACCDET_IRQ_CLR_SFT));
469                 ret = regmap_read_poll_timeout    473                 ret = regmap_read_poll_timeout(priv->regmap,
470                                                   474                                                ACCDET_IRQ_ADDR,
471                                                   475                                                value,
472                                                   476                                                (value & ACCDET_IRQ_MASK_SFT) == 0,
473                                                   477                                                0,
474                                                   478                                                1000);
475                 if (ret) {                        479                 if (ret) {
476                         dev_err(priv->dev, "%s    480                         dev_err(priv->dev, "%s(), ret %d\n", __func__, ret);
477                         mutex_unlock(&priv->re    481                         mutex_unlock(&priv->res_lock);
478                         return IRQ_NONE;          482                         return IRQ_NONE;
479                 }                                 483                 }
480                 regmap_update_bits(priv->regma    484                 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR,
481                                    ACCDET_IRQ_    485                                    ACCDET_IRQ_CLR_MASK_SFT, 0);
482                 regmap_update_bits(priv->regma    486                 regmap_update_bits(priv->regmap, RG_INT_STATUS_ACCDET_ADDR,
483                                    RG_INT_STAT    487                                    RG_INT_STATUS_ACCDET_MASK_SFT,
484                                    BIT(RG_INT_    488                                    BIT(RG_INT_STATUS_ACCDET_SFT));
485                                                   489 
486                 queue_work(priv->accdet_workqu    490                 queue_work(priv->accdet_workqueue, &priv->accdet_work);
487         } else {                                  491         } else {
488                 if (irq_val & ACCDET_EINT0_IRQ    492                 if (irq_val & ACCDET_EINT0_IRQ_MASK_SFT) {
489                         regmap_update_bits(pri    493                         regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR,
490                                            ACC    494                                            ACCDET_EINT0_IRQ_CLR_MASK_SFT,
491                                            BIT    495                                            BIT(ACCDET_EINT0_IRQ_CLR_SFT));
492                         ret = regmap_read_poll    496                         ret = regmap_read_poll_timeout(priv->regmap,
493                                                   497                                                        ACCDET_IRQ_ADDR,
494                                                   498                                                        value,
495                                                   499                                                        (value & ACCDET_EINT0_IRQ_MASK_SFT) == 0,
496                                                   500                                                        0,
497                                                   501                                                        1000);
498                         if (ret) {                502                         if (ret) {
499                                 dev_err(priv->    503                                 dev_err(priv->dev, "%s(), ret %d\n", __func__,
500                                         ret);     504                                         ret);
501                                 mutex_unlock(&    505                                 mutex_unlock(&priv->res_lock);
502                                 return IRQ_NON    506                                 return IRQ_NONE;
503                         }                         507                         }
504                         regmap_update_bits(pri    508                         regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR,
505                                            ACC    509                                            ACCDET_EINT0_IRQ_CLR_MASK_SFT, 0);
506                         regmap_update_bits(pri    510                         regmap_update_bits(priv->regmap,
507                                            RG_    511                                            RG_INT_STATUS_ACCDET_ADDR,
508                                            RG_    512                                            RG_INT_STATUS_ACCDET_EINT0_MASK_SFT,
509                                            BIT    513                                            BIT(RG_INT_STATUS_ACCDET_EINT0_SFT));
510                 }                                 514                 }
511                 if (irq_val & ACCDET_EINT1_IRQ    515                 if (irq_val & ACCDET_EINT1_IRQ_MASK_SFT) {
512                         regmap_update_bits(pri    516                         regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR,
513                                            ACC    517                                            ACCDET_EINT1_IRQ_CLR_MASK_SFT,
514                                            BIT    518                                            BIT(ACCDET_EINT1_IRQ_CLR_SFT));
515                         ret = regmap_read_poll    519                         ret = regmap_read_poll_timeout(priv->regmap,
516                                                   520                                                        ACCDET_IRQ_ADDR,
517                                                   521                                                        value,
518                                                   522                                                        (value & ACCDET_EINT1_IRQ_MASK_SFT) == 0,
519                                                   523                                                        0,
520                                                   524                                                        1000);
521                         if (ret) {                525                         if (ret) {
522                                 dev_err(priv->    526                                 dev_err(priv->dev, "%s(), ret %d\n", __func__,
523                                         ret);     527                                         ret);
524                                 mutex_unlock(&    528                                 mutex_unlock(&priv->res_lock);
525                                 return IRQ_NON    529                                 return IRQ_NONE;
526                         }                         530                         }
527                         regmap_update_bits(pri    531                         regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR,
528                                            ACC    532                                            ACCDET_EINT1_IRQ_CLR_MASK_SFT, 0);
529                         regmap_update_bits(pri    533                         regmap_update_bits(priv->regmap,
530                                            RG_    534                                            RG_INT_STATUS_ACCDET_ADDR,
531                                            RG_    535                                            RG_INT_STATUS_ACCDET_EINT1_MASK_SFT,
532                                            BIT    536                                            BIT(RG_INT_STATUS_ACCDET_EINT1_SFT));
533                 }                                 537                 }
534                 /* get jack detection status *    538                 /* get jack detection status */
535                 regmap_read(priv->regmap, ACCD    539                 regmap_read(priv->regmap, ACCDET_EINT0_MEM_IN_ADDR, &val);
536                 priv->jd_sts = ((val >> ACCDET    540                 priv->jd_sts = ((val >> ACCDET_EINT0_MEM_IN_SFT) &
537                                    ACCDET_EINT    541                                    ACCDET_EINT0_MEM_IN_MASK);
538                 /* adjust eint digital/analog     542                 /* adjust eint digital/analog setting */
539                 mt6359_accdet_jd_setting(priv)    543                 mt6359_accdet_jd_setting(priv);
540                                                   544 
541                 queue_work(priv->jd_workqueue,    545                 queue_work(priv->jd_workqueue, &priv->jd_work);
542         }                                         546         }
543         mutex_unlock(&priv->res_lock);            547         mutex_unlock(&priv->res_lock);
544                                                   548 
545         return IRQ_HANDLED;                       549         return IRQ_HANDLED;
546 }                                                 550 }
547                                                   551 
548 static int mt6359_accdet_parse_dt(struct mt635    552 static int mt6359_accdet_parse_dt(struct mt6359_accdet *priv)
549 {                                                 553 {
550         int ret;                               !! 554         int ret = 0;
551         struct device *dev = priv->dev;           555         struct device *dev = priv->dev;
552         struct device_node *node = NULL;          556         struct device_node *node = NULL;
553         int pwm_deb[15] = {0};                    557         int pwm_deb[15] = {0};
554         unsigned int tmp = 0;                     558         unsigned int tmp = 0;
555                                                   559 
556         node = of_get_child_by_name(dev->paren    560         node = of_get_child_by_name(dev->parent->of_node, "accdet");
557         if (!node)                                561         if (!node)
558                 return -EINVAL;                   562                 return -EINVAL;
559                                                   563 
560         ret = of_property_read_u32(node, "medi    564         ret = of_property_read_u32(node, "mediatek,mic-vol",
561                                    &priv->data    565                                    &priv->data->mic_vol);
562         if (ret)                                  566         if (ret)
563                 priv->data->mic_vol = 8;          567                 priv->data->mic_vol = 8;
564                                                   568 
565         ret = of_property_read_u32(node, "medi    569         ret = of_property_read_u32(node, "mediatek,plugout-debounce",
566                                    &priv->data    570                                    &priv->data->plugout_deb);
567         if (ret)                                  571         if (ret)
568                 priv->data->plugout_deb = 1;      572                 priv->data->plugout_deb = 1;
569                                                   573 
570         ret = of_property_read_u32(node, "medi    574         ret = of_property_read_u32(node, "mediatek,mic-mode",
571                                    &priv->data    575                                    &priv->data->mic_mode);
572         if (ret)                                  576         if (ret)
573                 priv->data->mic_mode = 2;         577                 priv->data->mic_mode = 2;
574                                                   578 
575         ret = of_property_read_u32_array(node,    579         ret = of_property_read_u32_array(node, "mediatek,pwm-deb-setting",
576                                          pwm_d    580                                          pwm_deb, ARRAY_SIZE(pwm_deb));
577         /* debounce8(auxadc debounce) is defau    581         /* debounce8(auxadc debounce) is default, needn't get from dts */
578         if (!ret)                                 582         if (!ret)
579                 memcpy(priv->data->pwm_deb, pw    583                 memcpy(priv->data->pwm_deb, pwm_deb, sizeof(pwm_deb));
580                                                   584 
581         ret = of_property_read_u32(node, "medi    585         ret = of_property_read_u32(node, "mediatek,eint-level-pol",
582                                    &priv->data    586                                    &priv->data->eint_pol);
583         if (ret)                                  587         if (ret)
584                 priv->data->eint_pol = 8;         588                 priv->data->eint_pol = 8;
585                                                   589 
586         ret = of_property_read_u32(node, "medi    590         ret = of_property_read_u32(node, "mediatek,eint-use-ap", &tmp);
587         if (ret)                                  591         if (ret)
588                 tmp = 0;                          592                 tmp = 0;
589         if (tmp == 0)                             593         if (tmp == 0)
590                 priv->caps |= ACCDET_PMIC_EINT    594                 priv->caps |= ACCDET_PMIC_EINT_IRQ;
591         else if (tmp == 1)                        595         else if (tmp == 1)
592                 priv->caps |= ACCDET_AP_GPIO_E    596                 priv->caps |= ACCDET_AP_GPIO_EINT;
593                                                   597 
594         ret = of_property_read_u32(node, "medi    598         ret = of_property_read_u32(node, "mediatek,eint-detect-mode",
595                                    &priv->data    599                                    &priv->data->eint_detect_mode);
596         if (ret) {                                600         if (ret) {
597                 /* eint detection mode equals     601                 /* eint detection mode equals to EINT HW Mode */
598                 priv->data->eint_detect_mode =    602                 priv->data->eint_detect_mode = 0x4;
599         }                                         603         }
600                                                   604 
601         ret = of_property_read_u32(node, "medi    605         ret = of_property_read_u32(node, "mediatek,eint-num", &tmp);
602         if (ret)                                  606         if (ret)
603                 tmp = 0;                          607                 tmp = 0;
604         if (tmp == 0)                             608         if (tmp == 0)
605                 priv->caps |= ACCDET_PMIC_EINT    609                 priv->caps |= ACCDET_PMIC_EINT0;
606         else if (tmp == 1)                        610         else if (tmp == 1)
607                 priv->caps |= ACCDET_PMIC_EINT    611                 priv->caps |= ACCDET_PMIC_EINT1;
608         else if (tmp == 2)                        612         else if (tmp == 2)
609                 priv->caps |= ACCDET_PMIC_BI_E    613                 priv->caps |= ACCDET_PMIC_BI_EINT;
610                                                   614 
611         ret = of_property_read_u32(node, "medi    615         ret = of_property_read_u32(node, "mediatek,eint-trig-mode",
612                                    &tmp);         616                                    &tmp);
613         if (ret)                                  617         if (ret)
614                 tmp = 0;                          618                 tmp = 0;
615         if (tmp == 0)                             619         if (tmp == 0)
616                 priv->caps |= ACCDET_PMIC_GPIO    620                 priv->caps |= ACCDET_PMIC_GPIO_TRIG_EINT;
617         else if (tmp == 1)                        621         else if (tmp == 1)
618                 priv->caps |= ACCDET_PMIC_INVE    622                 priv->caps |= ACCDET_PMIC_INVERTER_TRIG_EINT;
619                                                   623 
620         ret = of_property_read_u32(node, "medi    624         ret = of_property_read_u32(node, "mediatek,eint-use-ext-res",
621                                    &priv->data    625                                    &priv->data->eint_use_ext_res);
622         if (ret) {                                626         if (ret) {
623                 /* eint use internal resister     627                 /* eint use internal resister */
624                 priv->data->eint_use_ext_res =    628                 priv->data->eint_use_ext_res = 0x0;
625         }                                         629         }
626                                                   630 
627         ret = of_property_read_u32(node, "medi    631         ret = of_property_read_u32(node, "mediatek,eint-comp-vth",
628                                    &priv->data    632                                    &priv->data->eint_comp_vth);
629         if (ret)                                  633         if (ret)
630                 priv->data->eint_comp_vth = 0x    634                 priv->data->eint_comp_vth = 0x0;
631                                                   635 
632         ret = of_property_read_u32(node, "medi    636         ret = of_property_read_u32(node, "mediatek,key-mode", &tmp);
633         if (ret)                                  637         if (ret)
634                 tmp = 0;                          638                 tmp = 0;
635         if (tmp == 0) {                           639         if (tmp == 0) {
636                 int three_key[4];                 640                 int three_key[4];
637                                                   641 
638                 priv->caps |= ACCDET_THREE_KEY    642                 priv->caps |= ACCDET_THREE_KEY;
639                 ret = of_property_read_u32_arr    643                 ret = of_property_read_u32_array(node,
640                                                   644                                                  "mediatek,three-key-thr",
641                                                   645                                                  three_key,
642                                                   646                                                  ARRAY_SIZE(three_key));
643                 if (!ret)                         647                 if (!ret)
644                         memcpy(&priv->data->th    648                         memcpy(&priv->data->three_key, three_key + 1,
645                                sizeof(struct t    649                                sizeof(struct three_key_threshold));
646         } else if (tmp == 1) {                    650         } else if (tmp == 1) {
647                 int four_key[5];                  651                 int four_key[5];
648                                                   652 
649                 priv->caps |= ACCDET_FOUR_KEY;    653                 priv->caps |= ACCDET_FOUR_KEY;
650                 ret = of_property_read_u32_arr    654                 ret = of_property_read_u32_array(node,
651                                                   655                                                  "mediatek,four-key-thr",
652                                                   656                                                  four_key,
653                                                   657                                                  ARRAY_SIZE(four_key));
654                 if (!ret) {                       658                 if (!ret) {
655                         memcpy(&priv->data->fo    659                         memcpy(&priv->data->four_key, four_key + 1,
656                                sizeof(struct f    660                                sizeof(struct four_key_threshold));
657                 } else {                          661                 } else {
658                         dev_warn(priv->dev,       662                         dev_warn(priv->dev,
659                                  "accdet no 4-    663                                  "accdet no 4-key-thrsh dts, use efuse\n");
660                 }                                 664                 }
661         } else if (tmp == 2) {                    665         } else if (tmp == 2) {
662                 int three_key[4];                 666                 int three_key[4];
663                                                   667 
664                 priv->caps |= ACCDET_TRI_KEY_C    668                 priv->caps |= ACCDET_TRI_KEY_CDD;
665                 ret = of_property_read_u32_arr    669                 ret = of_property_read_u32_array(node,
666                                                   670                                                  "mediatek,tri-key-cdd-thr",
667                                                   671                                                  three_key,
668                                                   672                                                  ARRAY_SIZE(three_key));
669                 if (!ret)                         673                 if (!ret)
670                         memcpy(&priv->data->th    674                         memcpy(&priv->data->three_key, three_key + 1,
671                                sizeof(struct t    675                                sizeof(struct three_key_threshold));
672         }                                         676         }
673                                                   677 
674         of_node_put(node);                     << 
675         dev_warn(priv->dev, "accdet caps=%x\n"    678         dev_warn(priv->dev, "accdet caps=%x\n", priv->caps);
676                                                   679 
677         return 0;                                 680         return 0;
678 }                                                 681 }
679                                                   682 
680 static void config_digital_init_by_mode(struct    683 static void config_digital_init_by_mode(struct mt6359_accdet *priv)
681 {                                                 684 {
682         /* enable eint cmpmem pwm */              685         /* enable eint cmpmem pwm */
683         regmap_write(priv->regmap, ACCDET_EINT    686         regmap_write(priv->regmap, ACCDET_EINT_CMPMEN_PWM_THRESH_ADDR,
684                      (priv->data->pwm_deb->ein    687                      (priv->data->pwm_deb->eint_pwm_width << 4 |
685                      priv->data->pwm_deb->eint    688                      priv->data->pwm_deb->eint_pwm_thresh));
686         /* DA signal stable */                    689         /* DA signal stable */
687         if (priv->caps & ACCDET_PMIC_EINT0) {     690         if (priv->caps & ACCDET_PMIC_EINT0) {
688                 regmap_write(priv->regmap, ACC    691                 regmap_write(priv->regmap, ACCDET_DA_STABLE_ADDR,
689                              ACCDET_EINT0_STAB    692                              ACCDET_EINT0_STABLE_VAL);
690         } else if (priv->caps & ACCDET_PMIC_EI    693         } else if (priv->caps & ACCDET_PMIC_EINT1) {
691                 regmap_write(priv->regmap, ACC    694                 regmap_write(priv->regmap, ACCDET_DA_STABLE_ADDR,
692                              ACCDET_EINT1_STAB    695                              ACCDET_EINT1_STABLE_VAL);
693         }                                         696         }
694         /* after receive n+1 number, interrupt    697         /* after receive n+1 number, interrupt issued. */
695         regmap_update_bits(priv->regmap, ACCDE    698         regmap_update_bits(priv->regmap, ACCDET_EINT_M_PLUG_IN_NUM_ADDR,
696                            ACCDET_EINT_M_PLUG_    699                            ACCDET_EINT_M_PLUG_IN_NUM_MASK_SFT,
697                            BIT(ACCDET_EINT_M_P    700                            BIT(ACCDET_EINT_M_PLUG_IN_NUM_SFT));
698         /* setting HW mode, enable digital fas    701         /* setting HW mode, enable digital fast discharge
699          * if use EINT0 & EINT1 detection, ple    702          * if use EINT0 & EINT1 detection, please modify
700          * ACCDET_HWMODE_EN_ADDR[2:1]             703          * ACCDET_HWMODE_EN_ADDR[2:1]
701          */                                       704          */
702         regmap_write(priv->regmap, ACCDET_HWMO    705         regmap_write(priv->regmap, ACCDET_HWMODE_EN_ADDR, 0x100);
703                                                   706 
704         regmap_update_bits(priv->regmap, ACCDE    707         regmap_update_bits(priv->regmap, ACCDET_EINT_M_DETECT_EN_ADDR,
705                            ACCDET_EINT_M_DETEC    708                            ACCDET_EINT_M_DETECT_EN_MASK_SFT, 0);
706                                                   709 
707         /* enable PWM */                          710         /* enable PWM */
708         regmap_write(priv->regmap, ACCDET_CMP_    711         regmap_write(priv->regmap, ACCDET_CMP_PWM_EN_ADDR, 0x67);
709         /* enable inverter detection */           712         /* enable inverter detection */
710         if (priv->data->eint_detect_mode == 0x    713         if (priv->data->eint_detect_mode == 0x1) {
711                 /* disable inverter detection     714                 /* disable inverter detection */
712                 if (priv->caps & ACCDET_PMIC_E    715                 if (priv->caps & ACCDET_PMIC_EINT0) {
713                         regmap_update_bits(pri    716                         regmap_update_bits(priv->regmap,
714                                            ACC    717                                            ACCDET_EINT0_INVERTER_SW_EN_ADDR,
715                                            ACC    718                                            ACCDET_EINT0_INVERTER_SW_EN_MASK_SFT,
716                                            0);    719                                            0);
717                 } else if (priv->caps & ACCDET    720                 } else if (priv->caps & ACCDET_PMIC_EINT1) {
718                         regmap_update_bits(pri    721                         regmap_update_bits(priv->regmap,
719                                            ACC    722                                            ACCDET_EINT1_INVERTER_SW_EN_ADDR,
720                                            ACC    723                                            ACCDET_EINT1_INVERTER_SW_EN_MASK_SFT,
721                                            0);    724                                            0);
722                 }                                 725                 }
723         } else {                                  726         } else {
724                 if (priv->caps & ACCDET_PMIC_E    727                 if (priv->caps & ACCDET_PMIC_EINT0) {
725                         regmap_update_bits(pri    728                         regmap_update_bits(priv->regmap,
726                                            ACC    729                                            ACCDET_EINT0_INVERTER_SW_EN_ADDR,
727                                            ACC    730                                            ACCDET_EINT0_INVERTER_SW_EN_MASK_SFT,
728                                            BIT    731                                            BIT(ACCDET_EINT0_INVERTER_SW_EN_SFT));
729                 } else if (priv->caps & ACCDET    732                 } else if (priv->caps & ACCDET_PMIC_EINT1) {
730                         regmap_update_bits(pri    733                         regmap_update_bits(priv->regmap,
731                                            ACC    734                                            ACCDET_EINT1_INVERTER_SW_EN_ADDR,
732                                            ACC    735                                            ACCDET_EINT1_INVERTER_SW_EN_MASK_SFT,
733                                            BIT    736                                            BIT(ACCDET_EINT1_INVERTER_SW_EN_SFT));
734                 }                                 737                 }
735         }                                         738         }
736 }                                                 739 }
737                                                   740 
738 static void config_eint_init_by_mode(struct mt    741 static void config_eint_init_by_mode(struct mt6359_accdet *priv)
739 {                                                 742 {
740         unsigned int val = 0;                     743         unsigned int val = 0;
741                                                   744 
742         if (priv->caps & ACCDET_PMIC_EINT0) {     745         if (priv->caps & ACCDET_PMIC_EINT0) {
743                 regmap_update_bits(priv->regma    746                 regmap_update_bits(priv->regmap, RG_EINT0EN_ADDR,
744                                    RG_EINT0EN_    747                                    RG_EINT0EN_MASK_SFT, BIT(RG_EINT0EN_SFT));
745         } else if (priv->caps & ACCDET_PMIC_EI    748         } else if (priv->caps & ACCDET_PMIC_EINT1) {
746                 regmap_update_bits(priv->regma    749                 regmap_update_bits(priv->regmap, RG_EINT1EN_ADDR,
747                                    RG_EINT1EN_    750                                    RG_EINT1EN_MASK_SFT, BIT(RG_EINT1EN_SFT));
748         }                                         751         }
749         /* ESD switches on */                     752         /* ESD switches on */
750         regmap_update_bits(priv->regmap, RG_AC    753         regmap_update_bits(priv->regmap, RG_ACCDETSPARE_ADDR,
751                            1 << 8, 1 << 8);       754                            1 << 8, 1 << 8);
752         /* before playback, set NCP pull low b    755         /* before playback, set NCP pull low before nagative voltage */
753         regmap_update_bits(priv->regmap, RG_NC    756         regmap_update_bits(priv->regmap, RG_NCP_PDDIS_EN_ADDR,
754                            RG_NCP_PDDIS_EN_MAS    757                            RG_NCP_PDDIS_EN_MASK_SFT, BIT(RG_NCP_PDDIS_EN_SFT));
755                                                   758 
756         if (priv->data->eint_detect_mode == 0x    759         if (priv->data->eint_detect_mode == 0x1 ||
757             priv->data->eint_detect_mode == 0x    760             priv->data->eint_detect_mode == 0x2 ||
758             priv->data->eint_detect_mode == 0x    761             priv->data->eint_detect_mode == 0x3) {
759                 if (priv->data->eint_use_ext_r    762                 if (priv->data->eint_use_ext_res == 0x1) {
760                         if (priv->caps & ACCDE    763                         if (priv->caps & ACCDET_PMIC_EINT0) {
761                                 regmap_update_    764                                 regmap_update_bits(priv->regmap,
762                                                   765                                                    RG_EINT0CONFIGACCDET_ADDR,
763                                                   766                                                    RG_EINT0CONFIGACCDET_MASK_SFT,
764                                                   767                                                    0);
765                         } else if (priv->caps     768                         } else if (priv->caps & ACCDET_PMIC_EINT1) {
766                                 regmap_update_    769                                 regmap_update_bits(priv->regmap,
767                                                   770                                                    RG_EINT1CONFIGACCDET_ADDR,
768                                                   771                                                    RG_EINT1CONFIGACCDET_MASK_SFT,
769                                                   772                                                    0);
770                         }                         773                         }
771                 } else {                          774                 } else {
772                         if (priv->caps & ACCDE    775                         if (priv->caps & ACCDET_PMIC_EINT0) {
773                                 regmap_update_    776                                 regmap_update_bits(priv->regmap,
774                                                   777                                                    RG_EINT0CONFIGACCDET_ADDR,
775                                                   778                                                    RG_EINT0CONFIGACCDET_MASK_SFT,
776                                                   779                                                    BIT(RG_EINT0CONFIGACCDET_SFT));
777                         } else if (priv->caps     780                         } else if (priv->caps & ACCDET_PMIC_EINT1) {
778                                 regmap_update_    781                                 regmap_update_bits(priv->regmap,
779                                                   782                                                    RG_EINT1CONFIGACCDET_ADDR,
780                                                   783                                                    RG_EINT1CONFIGACCDET_MASK_SFT,
781                                                   784                                                    BIT(RG_EINT1CONFIGACCDET_SFT));
782                         }                         785                         }
783                 }                                 786                 }
784         }                                         787         }
785                                                   788 
786         if (priv->data->eint_detect_mode != 0x    789         if (priv->data->eint_detect_mode != 0x1) {
787                 /* current detect set 0.25uA *    790                 /* current detect set 0.25uA */
788                 regmap_update_bits(priv->regma    791                 regmap_update_bits(priv->regmap, RG_ACCDETSPARE_ADDR,
789                                    0x3 << RG_A    792                                    0x3 << RG_ACCDETSPARE_SFT,
790                                    0x3 << RG_A    793                                    0x3 << RG_ACCDETSPARE_SFT);
791         }                                         794         }
792         regmap_write(priv->regmap, RG_EINTCOMP    795         regmap_write(priv->regmap, RG_EINTCOMPVTH_ADDR,
793                      val | priv->data->eint_co    796                      val | priv->data->eint_comp_vth << RG_EINTCOMPVTH_SFT);
794 }                                                 797 }
795                                                   798 
796 static void mt6359_accdet_init(struct mt6359_a    799 static void mt6359_accdet_init(struct mt6359_accdet *priv)
797 {                                                 800 {
798         unsigned int reg = 0;                     801         unsigned int reg = 0;
799                                                   802 
800         regmap_update_bits(priv->regmap, ACCDE    803         regmap_update_bits(priv->regmap, ACCDET_SEQ_INIT_ADDR,
801                            ACCDET_SEQ_INIT_MAS    804                            ACCDET_SEQ_INIT_MASK_SFT, BIT(ACCDET_SEQ_INIT_SFT));
802         mdelay(2);                                805         mdelay(2);
803         regmap_update_bits(priv->regmap, ACCDE    806         regmap_update_bits(priv->regmap, ACCDET_SEQ_INIT_ADDR,
804                            ACCDET_SEQ_INIT_MAS    807                            ACCDET_SEQ_INIT_MASK_SFT, 0);
805         mdelay(1);                                808         mdelay(1);
806         /* init the debounce time (debounce/32    809         /* init the debounce time (debounce/32768)sec */
807         accdet_set_debounce(priv, accdet_state    810         accdet_set_debounce(priv, accdet_state000,
808                             priv->data->pwm_de    811                             priv->data->pwm_deb->debounce0);
809         accdet_set_debounce(priv, accdet_state    812         accdet_set_debounce(priv, accdet_state001,
810                             priv->data->pwm_de    813                             priv->data->pwm_deb->debounce1);
811         accdet_set_debounce(priv, accdet_state    814         accdet_set_debounce(priv, accdet_state011,
812                             priv->data->pwm_de    815                             priv->data->pwm_deb->debounce3);
813         accdet_set_debounce(priv, accdet_auxad    816         accdet_set_debounce(priv, accdet_auxadc,
814                             priv->data->pwm_de    817                             priv->data->pwm_deb->debounce4);
815                                                   818 
816         accdet_set_debounce(priv, eint_state00    819         accdet_set_debounce(priv, eint_state000,
817                             priv->data->pwm_de    820                             priv->data->pwm_deb->eint_debounce0);
818         accdet_set_debounce(priv, eint_state00    821         accdet_set_debounce(priv, eint_state001,
819                             priv->data->pwm_de    822                             priv->data->pwm_deb->eint_debounce1);
820         accdet_set_debounce(priv, eint_state01    823         accdet_set_debounce(priv, eint_state011,
821                             priv->data->pwm_de    824                             priv->data->pwm_deb->eint_debounce3);
822         accdet_set_debounce(priv, eint_inverte    825         accdet_set_debounce(priv, eint_inverter_state000,
823                             priv->data->pwm_de    826                             priv->data->pwm_deb->eint_inverter_debounce);
824                                                   827 
825         regmap_update_bits(priv->regmap, RG_AC    828         regmap_update_bits(priv->regmap, RG_ACCDET_RST_ADDR,
826                            RG_ACCDET_RST_MASK_    829                            RG_ACCDET_RST_MASK_SFT, BIT(RG_ACCDET_RST_SFT));
827         regmap_update_bits(priv->regmap, RG_AC    830         regmap_update_bits(priv->regmap, RG_ACCDET_RST_ADDR,
828                            RG_ACCDET_RST_MASK_    831                            RG_ACCDET_RST_MASK_SFT, 0);
829                                                   832 
830         /* clear high micbias1 voltage setting    833         /* clear high micbias1 voltage setting */
831         regmap_update_bits(priv->regmap, RG_AU    834         regmap_update_bits(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR,
832                            0x3 << RG_AUDMICBIA    835                            0x3 << RG_AUDMICBIAS1HVEN_SFT, 0);
833         regmap_update_bits(priv->regmap, RG_AU    836         regmap_update_bits(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR,
834                            0x7 << RG_AUDMICBIA    837                            0x7 << RG_AUDMICBIAS1VREF_SFT, 0);
835                                                   838 
836         /* init pwm frequency, duty & rise/fal    839         /* init pwm frequency, duty & rise/falling delay */
837         regmap_write(priv->regmap, ACCDET_PWM_    840         regmap_write(priv->regmap, ACCDET_PWM_WIDTH_ADDR,
838                      REGISTER_VAL(priv->data->    841                      REGISTER_VAL(priv->data->pwm_deb->pwm_width));
839         regmap_write(priv->regmap, ACCDET_PWM_    842         regmap_write(priv->regmap, ACCDET_PWM_THRESH_ADDR,
840                      REGISTER_VAL(priv->data->    843                      REGISTER_VAL(priv->data->pwm_deb->pwm_thresh));
841         regmap_write(priv->regmap, ACCDET_RISE    844         regmap_write(priv->regmap, ACCDET_RISE_DELAY_ADDR,
842                      (priv->data->pwm_deb->fal    845                      (priv->data->pwm_deb->fall_delay << 15 |
843                       priv->data->pwm_deb->ris    846                       priv->data->pwm_deb->rise_delay));
844                                                   847 
845         regmap_read(priv->regmap, RG_AUDPWDBMI    848         regmap_read(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, &reg);
846         if (priv->data->mic_vol <= 7) {           849         if (priv->data->mic_vol <= 7) {
847                 /* micbias1 <= 2.7V */            850                 /* micbias1 <= 2.7V */
848                 regmap_write(priv->regmap, RG_    851                 regmap_write(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR,
849                              reg | (priv->data    852                              reg | (priv->data->mic_vol << RG_AUDMICBIAS1VREF_SFT) |
850                              RG_AUDMICBIAS1LOW    853                              RG_AUDMICBIAS1LOWPEN_MASK_SFT);
851         } else if (priv->data->mic_vol == 8) {    854         } else if (priv->data->mic_vol == 8) {
852                 /* micbias1 = 2.8v */             855                 /* micbias1 = 2.8v */
853                 regmap_write(priv->regmap, RG_    856                 regmap_write(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR,
854                              reg | (3 << RG_AU    857                              reg | (3 << RG_AUDMICBIAS1HVEN_SFT) |
855                              RG_AUDMICBIAS1LOW    858                              RG_AUDMICBIAS1LOWPEN_MASK_SFT);
856         } else if (priv->data->mic_vol == 9) {    859         } else if (priv->data->mic_vol == 9) {
857                 /* micbias1 = 2.85v */            860                 /* micbias1 = 2.85v */
858                 regmap_write(priv->regmap, RG_    861                 regmap_write(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR,
859                              reg | (1 << RG_AU    862                              reg | (1 << RG_AUDMICBIAS1HVEN_SFT) |
860                              RG_AUDMICBIAS1LOW    863                              RG_AUDMICBIAS1LOWPEN_MASK_SFT);
861         }                                         864         }
862         /* mic mode setting */                    865         /* mic mode setting */
863         regmap_read(priv->regmap, RG_AUDACCDET    866         regmap_read(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR, &reg);
864         if (priv->data->mic_mode == HEADSET_MO    867         if (priv->data->mic_mode == HEADSET_MODE_1) {
865                 /* ACC mode*/                     868                 /* ACC mode*/
866                 regmap_write(priv->regmap, RG_    869                 regmap_write(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR,
867                              reg | RG_ACCDET_M    870                              reg | RG_ACCDET_MODE_ANA11_MODE1);
868                 /* enable analog fast discharg    871                 /* enable analog fast discharge */
869                 regmap_update_bits(priv->regma    872                 regmap_update_bits(priv->regmap, RG_ANALOGFDEN_ADDR,
870                                    RG_ANALOGFD    873                                    RG_ANALOGFDEN_MASK_SFT,
871                                    BIT(RG_ANAL    874                                    BIT(RG_ANALOGFDEN_SFT));
872                 regmap_update_bits(priv->regma    875                 regmap_update_bits(priv->regmap, RG_ACCDETSPARE_ADDR,
873                                    0x3 << 11,     876                                    0x3 << 11, 0x3 << 11);
874         } else if (priv->data->mic_mode == HEA    877         } else if (priv->data->mic_mode == HEADSET_MODE_2) {
875                 /* DCC mode Low cost mode with    878                 /* DCC mode Low cost mode without internal bias */
876                 regmap_write(priv->regmap, RG_    879                 regmap_write(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR,
877                              reg | RG_ACCDET_M    880                              reg | RG_ACCDET_MODE_ANA11_MODE2);
878                 /* enable analog fast discharg    881                 /* enable analog fast discharge */
879                 regmap_update_bits(priv->regma    882                 regmap_update_bits(priv->regmap, RG_ANALOGFDEN_ADDR,
880                                    0x3 << RG_A    883                                    0x3 << RG_ANALOGFDEN_SFT,
881                                    0x3 << RG_A    884                                    0x3 << RG_ANALOGFDEN_SFT);
882         } else if (priv->data->mic_mode == HEA    885         } else if (priv->data->mic_mode == HEADSET_MODE_6) {
883                 /* DCC mode Low cost mode with    886                 /* DCC mode Low cost mode with internal bias,
884                  * bit8 = 1 to use internal bi    887                  * bit8 = 1 to use internal bias
885                  */                               888                  */
886                 regmap_write(priv->regmap, RG_    889                 regmap_write(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR,
887                              reg | RG_ACCDET_M    890                              reg | RG_ACCDET_MODE_ANA11_MODE6);
888                 regmap_update_bits(priv->regma    891                 regmap_update_bits(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR,
889                                    RG_AUDMICBI    892                                    RG_AUDMICBIAS1DCSW1PEN_MASK_SFT,
890                                    BIT(RG_AUDM    893                                    BIT(RG_AUDMICBIAS1DCSW1PEN_SFT));
891                 /* enable analog fast discharg    894                 /* enable analog fast discharge */
892                 regmap_update_bits(priv->regma    895                 regmap_update_bits(priv->regmap, RG_ANALOGFDEN_ADDR,
893                                    0x3 << RG_A    896                                    0x3 << RG_ANALOGFDEN_SFT,
894                                    0x3 << RG_A    897                                    0x3 << RG_ANALOGFDEN_SFT);
895         }                                         898         }
896                                                   899 
897         if (priv->caps & ACCDET_PMIC_EINT_IRQ)    900         if (priv->caps & ACCDET_PMIC_EINT_IRQ) {
898                 config_eint_init_by_mode(priv)    901                 config_eint_init_by_mode(priv);
899                 config_digital_init_by_mode(pr    902                 config_digital_init_by_mode(priv);
900         }                                         903         }
901 }                                                 904 }
902                                                   905 
903 int mt6359_accdet_enable_jack_detect(struct sn    906 int mt6359_accdet_enable_jack_detect(struct snd_soc_component *component,
904                                      struct sn    907                                      struct snd_soc_jack *jack)
905 {                                                 908 {
906         struct mt6359_accdet *priv =              909         struct mt6359_accdet *priv =
907                 snd_soc_component_get_drvdata(    910                 snd_soc_component_get_drvdata(component);
908                                                   911 
909         snd_jack_set_key(jack->jack, SND_JACK_    912         snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
910         snd_jack_set_key(jack->jack, SND_JACK_    913         snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEDOWN);
911         snd_jack_set_key(jack->jack, SND_JACK_    914         snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
912         snd_jack_set_key(jack->jack, SND_JACK_    915         snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
913                                                   916 
914         priv->jack = jack;                        917         priv->jack = jack;
915                                                   918 
916         mt6359_accdet_jack_report(priv);          919         mt6359_accdet_jack_report(priv);
917                                                   920 
918         return 0;                                 921         return 0;
919 }                                                 922 }
920 EXPORT_SYMBOL_GPL(mt6359_accdet_enable_jack_de    923 EXPORT_SYMBOL_GPL(mt6359_accdet_enable_jack_detect);
921                                                   924 
922 static int mt6359_accdet_probe(struct platform    925 static int mt6359_accdet_probe(struct platform_device *pdev)
923 {                                                 926 {
924         struct mt6359_accdet *priv;               927         struct mt6359_accdet *priv;
925         struct mt6397_chip *mt6397 = dev_get_d    928         struct mt6397_chip *mt6397 = dev_get_drvdata(pdev->dev.parent);
926         int ret;                               !! 929         int ret = 0;
927                                                   930 
928         dev_dbg(&pdev->dev, "%s(), dev name %s    931         dev_dbg(&pdev->dev, "%s(), dev name %s\n",
929                 __func__, dev_name(&pdev->dev)    932                 __func__, dev_name(&pdev->dev));
930                                                   933 
931         priv = devm_kzalloc(&pdev->dev, sizeof    934         priv = devm_kzalloc(&pdev->dev, sizeof(struct mt6359_accdet),
932                             GFP_KERNEL);          935                             GFP_KERNEL);
933         if (!priv)                                936         if (!priv)
934                 return -ENOMEM;                   937                 return -ENOMEM;
935                                                   938 
936         priv->data = devm_kzalloc(&pdev->dev,     939         priv->data = devm_kzalloc(&pdev->dev, sizeof(struct dts_data),
937                                   GFP_KERNEL);    940                                   GFP_KERNEL);
938         if (!priv->data)                          941         if (!priv->data)
939                 return -ENOMEM;                   942                 return -ENOMEM;
940                                                   943 
941         priv->data->pwm_deb = devm_kzalloc(&pd    944         priv->data->pwm_deb = devm_kzalloc(&pdev->dev,
942                                            siz    945                                            sizeof(struct pwm_deb_settings),
943                                            GFP    946                                            GFP_KERNEL);
944         if (!priv->data->pwm_deb)                 947         if (!priv->data->pwm_deb)
945                 return -ENOMEM;                   948                 return -ENOMEM;
946                                                   949 
947         priv->regmap = mt6397->regmap;            950         priv->regmap = mt6397->regmap;
948         if (IS_ERR(priv->regmap)) {               951         if (IS_ERR(priv->regmap)) {
949                 ret = PTR_ERR(priv->regmap);      952                 ret = PTR_ERR(priv->regmap);
950                 dev_err(&pdev->dev, "Failed to    953                 dev_err(&pdev->dev, "Failed to allocate register map: %d\n",
951                         ret);                     954                         ret);
952                 return ret;                       955                 return ret;
953         }                                         956         }
954         priv->dev = &pdev->dev;                   957         priv->dev = &pdev->dev;
955                                                   958 
956         ret = mt6359_accdet_parse_dt(priv);       959         ret = mt6359_accdet_parse_dt(priv);
957         if (ret) {                                960         if (ret) {
958                 dev_err(&pdev->dev, "Failed to    961                 dev_err(&pdev->dev, "Failed to parse dts\n");
959                 return ret;                       962                 return ret;
960         }                                         963         }
961         mutex_init(&priv->res_lock);              964         mutex_init(&priv->res_lock);
962                                                   965 
963         priv->accdet_irq = platform_get_irq(pd    966         priv->accdet_irq = platform_get_irq(pdev, 0);
964         if (priv->accdet_irq >= 0) {           !! 967         if (priv->accdet_irq) {
965                 ret = devm_request_threaded_ir    968                 ret = devm_request_threaded_irq(&pdev->dev, priv->accdet_irq,
966                                                   969                                                 NULL, mt6359_accdet_irq,
967                                                   970                                                 IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
968                                                   971                                                 "ACCDET_IRQ", priv);
969                 if (ret) {                        972                 if (ret) {
970                         dev_err(&pdev->dev,       973                         dev_err(&pdev->dev,
971                                 "Failed to req    974                                 "Failed to request IRQ: (%d)\n", ret);
972                         return ret;               975                         return ret;
973                 }                                 976                 }
974         }                                         977         }
975                                                   978 
976         if (priv->caps & ACCDET_PMIC_EINT0) {     979         if (priv->caps & ACCDET_PMIC_EINT0) {
977                 priv->accdet_eint0 = platform_    980                 priv->accdet_eint0 = platform_get_irq(pdev, 1);
978                 if (priv->accdet_eint0 >= 0) { !! 981                 if (priv->accdet_eint0) {
979                         ret = devm_request_thr    982                         ret = devm_request_threaded_irq(&pdev->dev,
980                                                   983                                                         priv->accdet_eint0,
981                                                   984                                                         NULL, mt6359_accdet_irq,
982                                                   985                                                         IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
983                                                   986                                                         "ACCDET_EINT0", priv);
984                         if (ret) {                987                         if (ret) {
985                                 dev_err(&pdev-    988                                 dev_err(&pdev->dev,
986                                         "Faile    989                                         "Failed to request eint0 IRQ (%d)\n",
987                                         ret);     990                                         ret);
988                                 return ret;       991                                 return ret;
989                         }                         992                         }
990                 }                                 993                 }
991         } else if (priv->caps & ACCDET_PMIC_EI    994         } else if (priv->caps & ACCDET_PMIC_EINT1) {
992                 priv->accdet_eint1 = platform_    995                 priv->accdet_eint1 = platform_get_irq(pdev, 2);
993                 if (priv->accdet_eint1 >= 0) { !! 996                 if (priv->accdet_eint1) {
994                         ret = devm_request_thr    997                         ret = devm_request_threaded_irq(&pdev->dev,
995                                                   998                                                         priv->accdet_eint1,
996                                                   999                                                         NULL, mt6359_accdet_irq,
997                                                   1000                                                         IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
998                                                   1001                                                         "ACCDET_EINT1", priv);
999                         if (ret) {                1002                         if (ret) {
1000                                 dev_err(&pdev    1003                                 dev_err(&pdev->dev,
1001                                         "Fail    1004                                         "Failed to request eint1 IRQ (%d)\n",
1002                                         ret);    1005                                         ret);
1003                                 return ret;      1006                                 return ret;
1004                         }                        1007                         }
1005                 }                                1008                 }
1006         }                                        1009         }
1007                                                  1010 
1008         priv->accdet_workqueue = create_singl    1011         priv->accdet_workqueue = create_singlethread_workqueue("accdet");
1009         INIT_WORK(&priv->accdet_work, mt6359_    1012         INIT_WORK(&priv->accdet_work, mt6359_accdet_work);
1010         if (!priv->accdet_workqueue) {           1013         if (!priv->accdet_workqueue) {
1011                 dev_err(&pdev->dev, "Failed t    1014                 dev_err(&pdev->dev, "Failed to create accdet workqueue\n");
1012                 ret = -1;                        1015                 ret = -1;
1013                 goto err_accdet_wq;              1016                 goto err_accdet_wq;
1014         }                                        1017         }
1015                                                  1018 
1016         priv->jd_workqueue = create_singlethr    1019         priv->jd_workqueue = create_singlethread_workqueue("mt6359_accdet_jd");
1017         INIT_WORK(&priv->jd_work, mt6359_accd    1020         INIT_WORK(&priv->jd_work, mt6359_accdet_jd_work);
1018         if (!priv->jd_workqueue) {               1021         if (!priv->jd_workqueue) {
1019                 dev_err(&pdev->dev, "Failed t    1022                 dev_err(&pdev->dev, "Failed to create jack detect workqueue\n");
1020                 ret = -1;                        1023                 ret = -1;
1021                 goto err_eint_wq;                1024                 goto err_eint_wq;
1022         }                                        1025         }
1023                                                  1026 
1024         platform_set_drvdata(pdev, priv);        1027         platform_set_drvdata(pdev, priv);
1025         ret = devm_snd_soc_register_component    1028         ret = devm_snd_soc_register_component(&pdev->dev,
1026                                                  1029                                               &mt6359_accdet_soc_driver,
1027                                                  1030                                               NULL, 0);
1028         if (ret) {                               1031         if (ret) {
1029                 dev_err(&pdev->dev, "Failed t    1032                 dev_err(&pdev->dev, "Failed to register component\n");
1030                 return ret;                      1033                 return ret;
1031         }                                        1034         }
1032                                                  1035 
1033         priv->jd_sts = M_PLUG_OUT;               1036         priv->jd_sts = M_PLUG_OUT;
1034         priv->jack_type = 0;                     1037         priv->jack_type = 0;
1035         priv->btn_type = 0;                      1038         priv->btn_type = 0;
1036         priv->accdet_status = 0x3;               1039         priv->accdet_status = 0x3;
1037         mt6359_accdet_init(priv);                1040         mt6359_accdet_init(priv);
1038                                                  1041 
1039         mt6359_accdet_jack_report(priv);         1042         mt6359_accdet_jack_report(priv);
1040                                                  1043 
1041         return 0;                                1044         return 0;
1042                                                  1045 
1043 err_eint_wq:                                     1046 err_eint_wq:
1044         destroy_workqueue(priv->accdet_workqu    1047         destroy_workqueue(priv->accdet_workqueue);
1045 err_accdet_wq:                                   1048 err_accdet_wq:
1046         dev_err(&pdev->dev, "%s error. now ex    1049         dev_err(&pdev->dev, "%s error. now exit.!\n", __func__);
1047         return ret;                              1050         return ret;
1048 }                                                1051 }
1049                                                  1052 
1050 static struct platform_driver mt6359_accdet_d    1053 static struct platform_driver mt6359_accdet_driver = {
1051         .driver = {                              1054         .driver = {
1052                 .name = "pmic-codec-accdet",     1055                 .name = "pmic-codec-accdet",
1053         },                                       1056         },
1054         .probe = mt6359_accdet_probe,            1057         .probe = mt6359_accdet_probe,
1055 };                                               1058 };
1056                                                  1059 
1057 module_platform_driver(mt6359_accdet_driver)  !! 1060 static int __init mt6359_accdet_driver_init(void)
                                                   >> 1061 {
                                                   >> 1062         int ret = 0;
                                                   >> 1063 
                                                   >> 1064         ret = platform_driver_register(&mt6359_accdet_driver);
                                                   >> 1065         if (ret)
                                                   >> 1066                 return -ENODEV;
                                                   >> 1067         return 0;
                                                   >> 1068 }
                                                   >> 1069 
                                                   >> 1070 static void __exit mt6359_accdet_driver_exit(void)
                                                   >> 1071 {
                                                   >> 1072         platform_driver_unregister(&mt6359_accdet_driver);
                                                   >> 1073 }
                                                   >> 1074 module_init(mt6359_accdet_driver_init);
                                                   >> 1075 module_exit(mt6359_accdet_driver_exit);
1058                                                  1076 
1059 /* Module information */                         1077 /* Module information */
1060 MODULE_DESCRIPTION("MT6359 ALSA SoC codec jac    1078 MODULE_DESCRIPTION("MT6359 ALSA SoC codec jack driver");
1061 MODULE_AUTHOR("Argus Lin <argus.lin@mediatek.    1079 MODULE_AUTHOR("Argus Lin <argus.lin@mediatek.com>");
1062 MODULE_LICENSE("GPL v2");                        1080 MODULE_LICENSE("GPL v2");
1063                                                  1081 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php