Lines Matching refs:priv

62 static void accdet_set_debounce(struct mt6359_accdet *priv, int state,
64 static unsigned int adjust_eint_analog_setting(struct mt6359_accdet *priv);
65 static void config_digital_init_by_mode(struct mt6359_accdet *priv);
66 static void config_eint_init_by_mode(struct mt6359_accdet *priv);
67 static inline void mt6359_accdet_init(struct mt6359_accdet *priv);
68 static unsigned int mt6359_accdet_jd_setting(struct mt6359_accdet *priv);
69 static void mt6359_accdet_recover_jd_setting(struct mt6359_accdet *priv);
70 static void mt6359_accdet_jack_report(struct mt6359_accdet *priv);
71 static void recover_eint_analog_setting(struct mt6359_accdet *priv);
72 static void recover_eint_digital_setting(struct mt6359_accdet *priv);
73 static void recover_eint_setting(struct mt6359_accdet *priv);
75 static unsigned int adjust_eint_analog_setting(struct mt6359_accdet *priv) in adjust_eint_analog_setting() argument
77 if (priv->data->eint_detect_mode == 0x3 || in adjust_eint_analog_setting()
78 priv->data->eint_detect_mode == 0x4) { in adjust_eint_analog_setting()
80 regmap_update_bits(priv->regmap, in adjust_eint_analog_setting()
83 if (priv->data->eint_detect_mode == 0x4) { in adjust_eint_analog_setting()
84 if (priv->caps & ACCDET_PMIC_EINT0) { in adjust_eint_analog_setting()
86 regmap_update_bits(priv->regmap, in adjust_eint_analog_setting()
90 } else if (priv->caps & ACCDET_PMIC_EINT1) { in adjust_eint_analog_setting()
92 regmap_update_bits(priv->regmap, in adjust_eint_analog_setting()
97 if (priv->data->eint_use_ext_res == 0x3 || in adjust_eint_analog_setting()
98 priv->data->eint_use_ext_res == 0x4) { in adjust_eint_analog_setting()
100 regmap_update_bits(priv->regmap, in adjust_eint_analog_setting()
109 static unsigned int adjust_eint_digital_setting(struct mt6359_accdet *priv) in adjust_eint_digital_setting() argument
111 if (priv->caps & ACCDET_PMIC_EINT0) { in adjust_eint_digital_setting()
113 regmap_update_bits(priv->regmap, in adjust_eint_digital_setting()
116 } else if (priv->caps & ACCDET_PMIC_EINT1) { in adjust_eint_digital_setting()
118 regmap_update_bits(priv->regmap, in adjust_eint_digital_setting()
123 if (priv->data->eint_detect_mode == 0x4) { in adjust_eint_digital_setting()
124 if (priv->caps & ACCDET_PMIC_EINT0) { in adjust_eint_digital_setting()
126 regmap_update_bits(priv->regmap, in adjust_eint_digital_setting()
129 } else if (priv->caps & ACCDET_PMIC_EINT1) { in adjust_eint_digital_setting()
131 regmap_update_bits(priv->regmap, in adjust_eint_digital_setting()
139 static unsigned int mt6359_accdet_jd_setting(struct mt6359_accdet *priv) in mt6359_accdet_jd_setting() argument
141 if (priv->jd_sts == M_PLUG_IN) { in mt6359_accdet_jd_setting()
143 adjust_eint_digital_setting(priv); in mt6359_accdet_jd_setting()
145 adjust_eint_analog_setting(priv); in mt6359_accdet_jd_setting()
146 } else if (priv->jd_sts == M_PLUG_OUT) { in mt6359_accdet_jd_setting()
148 accdet_set_debounce(priv, eint_state000, in mt6359_accdet_jd_setting()
149 priv->data->pwm_deb->eint_debounce0); in mt6359_accdet_jd_setting()
151 dev_dbg(priv->dev, "should not be here %s()\n", __func__); in mt6359_accdet_jd_setting()
157 static void recover_eint_analog_setting(struct mt6359_accdet *priv) in recover_eint_analog_setting() argument
159 if (priv->data->eint_detect_mode == 0x3 || in recover_eint_analog_setting()
160 priv->data->eint_detect_mode == 0x4) { in recover_eint_analog_setting()
162 regmap_update_bits(priv->regmap, RG_ACCDETSPARE_ADDR, in recover_eint_analog_setting()
165 if (priv->data->eint_detect_mode == 0x4) { in recover_eint_analog_setting()
166 if (priv->caps & ACCDET_PMIC_EINT0) { in recover_eint_analog_setting()
168 regmap_update_bits(priv->regmap, in recover_eint_analog_setting()
171 } else if (priv->caps & ACCDET_PMIC_EINT1) { in recover_eint_analog_setting()
173 regmap_update_bits(priv->regmap, in recover_eint_analog_setting()
177 regmap_update_bits(priv->regmap, RG_EINT0HIRENB_ADDR, in recover_eint_analog_setting()
182 static void recover_eint_digital_setting(struct mt6359_accdet *priv) in recover_eint_digital_setting() argument
184 if (priv->caps & ACCDET_PMIC_EINT0) { in recover_eint_digital_setting()
185 regmap_update_bits(priv->regmap, in recover_eint_digital_setting()
188 } else if (priv->caps & ACCDET_PMIC_EINT1) { in recover_eint_digital_setting()
189 regmap_update_bits(priv->regmap, in recover_eint_digital_setting()
193 if (priv->data->eint_detect_mode == 0x4) { in recover_eint_digital_setting()
195 if (priv->caps & ACCDET_PMIC_EINT0) { in recover_eint_digital_setting()
197 regmap_update_bits(priv->regmap, in recover_eint_digital_setting()
201 } else if (priv->caps & ACCDET_PMIC_EINT1) { in recover_eint_digital_setting()
203 regmap_update_bits(priv->regmap, in recover_eint_digital_setting()
210 if (priv->data->eint_detect_mode != 0x1) { in recover_eint_digital_setting()
211 if (priv->caps & ACCDET_PMIC_EINT0) { in recover_eint_digital_setting()
213 regmap_update_bits(priv->regmap, in recover_eint_digital_setting()
217 } else if (priv->caps & ACCDET_PMIC_EINT1) { in recover_eint_digital_setting()
219 regmap_update_bits(priv->regmap, in recover_eint_digital_setting()
227 static void recover_eint_setting(struct mt6359_accdet *priv) in recover_eint_setting() argument
229 if (priv->jd_sts == M_PLUG_OUT) { in recover_eint_setting()
230 recover_eint_analog_setting(priv); in recover_eint_setting()
231 recover_eint_digital_setting(priv); in recover_eint_setting()
235 static void mt6359_accdet_recover_jd_setting(struct mt6359_accdet *priv) in mt6359_accdet_recover_jd_setting() argument
240 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_recover_jd_setting()
243 ret = regmap_read_poll_timeout(priv->regmap, in mt6359_accdet_recover_jd_setting()
250 dev_warn(priv->dev, "%s(), ret %d\n", __func__, ret); in mt6359_accdet_recover_jd_setting()
252 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_recover_jd_setting()
254 regmap_update_bits(priv->regmap, RG_INT_STATUS_ACCDET_ADDR, in mt6359_accdet_recover_jd_setting()
259 accdet_set_debounce(priv, accdet_state000, in mt6359_accdet_recover_jd_setting()
260 priv->data->pwm_deb->debounce0); in mt6359_accdet_recover_jd_setting()
261 accdet_set_debounce(priv, accdet_state001, in mt6359_accdet_recover_jd_setting()
262 priv->data->pwm_deb->debounce1); in mt6359_accdet_recover_jd_setting()
263 accdet_set_debounce(priv, accdet_state011, in mt6359_accdet_recover_jd_setting()
264 priv->data->pwm_deb->debounce3); in mt6359_accdet_recover_jd_setting()
266 priv->jack_type = 0; in mt6359_accdet_recover_jd_setting()
267 priv->btn_type = 0; in mt6359_accdet_recover_jd_setting()
268 priv->accdet_status = 0x3; in mt6359_accdet_recover_jd_setting()
269 mt6359_accdet_jack_report(priv); in mt6359_accdet_recover_jd_setting()
272 static void accdet_set_debounce(struct mt6359_accdet *priv, int state, in accdet_set_debounce() argument
277 regmap_write(priv->regmap, ACCDET_DEBOUNCE0_ADDR, debounce); in accdet_set_debounce()
280 regmap_write(priv->regmap, ACCDET_DEBOUNCE1_ADDR, debounce); in accdet_set_debounce()
283 regmap_write(priv->regmap, ACCDET_DEBOUNCE2_ADDR, debounce); in accdet_set_debounce()
286 regmap_write(priv->regmap, ACCDET_DEBOUNCE3_ADDR, debounce); in accdet_set_debounce()
289 regmap_write(priv->regmap, in accdet_set_debounce()
293 regmap_update_bits(priv->regmap, ACCDET_EINT_DEBOUNCE0_ADDR, in accdet_set_debounce()
298 regmap_update_bits(priv->regmap, ACCDET_EINT_DEBOUNCE1_ADDR, in accdet_set_debounce()
303 regmap_update_bits(priv->regmap, ACCDET_EINT_DEBOUNCE2_ADDR, in accdet_set_debounce()
308 regmap_update_bits(priv->regmap, ACCDET_EINT_DEBOUNCE3_ADDR, in accdet_set_debounce()
313 regmap_write(priv->regmap, ACCDET_EINT_INVERTER_DEBOUNCE_ADDR, in accdet_set_debounce()
317 dev_warn(priv->dev, "Error: %s error state (%d)\n", __func__, in accdet_set_debounce()
323 static void mt6359_accdet_jack_report(struct mt6359_accdet *priv) in mt6359_accdet_jack_report() argument
327 if (!priv->jack) in mt6359_accdet_jack_report()
330 report = priv->jack_type | priv->btn_type; in mt6359_accdet_jack_report()
331 snd_soc_jack_report(priv->jack, report, MT6359_ACCDET_JACK_MASK); in mt6359_accdet_jack_report()
334 static unsigned int check_button(struct mt6359_accdet *priv, unsigned int v) in check_button() argument
336 if (priv->caps & ACCDET_FOUR_KEY) { in check_button()
337 if (v < priv->data->four_key.down && in check_button()
338 v >= priv->data->four_key.up) in check_button()
339 priv->btn_type = SND_JACK_BTN_1; in check_button()
340 if (v < priv->data->four_key.up && in check_button()
341 v >= priv->data->four_key.voice) in check_button()
342 priv->btn_type = SND_JACK_BTN_2; in check_button()
343 if (v < priv->data->four_key.voice && in check_button()
344 v >= priv->data->four_key.mid) in check_button()
345 priv->btn_type = SND_JACK_BTN_3; in check_button()
346 if (v < priv->data->four_key.mid) in check_button()
347 priv->btn_type = SND_JACK_BTN_0; in check_button()
349 if (v < priv->data->three_key.down && in check_button()
350 v >= priv->data->three_key.up) in check_button()
351 priv->btn_type = SND_JACK_BTN_1; in check_button()
352 if (v < priv->data->three_key.up && in check_button()
353 v >= priv->data->three_key.mid) in check_button()
354 priv->btn_type = SND_JACK_BTN_2; in check_button()
355 if (v < priv->data->three_key.mid) in check_button()
356 priv->btn_type = SND_JACK_BTN_0; in check_button()
361 static void is_key_pressed(struct mt6359_accdet *priv, bool pressed) in is_key_pressed() argument
363 priv->btn_type = priv->jack_type & ~MT6359_ACCDET_BTN_MASK; in is_key_pressed()
366 check_button(priv, priv->cali_voltage); in is_key_pressed()
369 static inline void check_jack_btn_type(struct mt6359_accdet *priv) in check_jack_btn_type() argument
373 regmap_read(priv->regmap, ACCDET_MEM_IN_ADDR, &val); in check_jack_btn_type()
375 priv->accdet_status = in check_jack_btn_type()
378 switch (priv->accdet_status) { in check_jack_btn_type()
380 if (priv->jack_type == SND_JACK_HEADSET) in check_jack_btn_type()
381 is_key_pressed(priv, true); in check_jack_btn_type()
383 priv->jack_type = SND_JACK_HEADPHONE; in check_jack_btn_type()
386 if (priv->jack_type == SND_JACK_HEADSET) { in check_jack_btn_type()
387 is_key_pressed(priv, false); in check_jack_btn_type()
389 priv->jack_type = SND_JACK_HEADSET; in check_jack_btn_type()
390 accdet_set_debounce(priv, eint_state011, 0x1); in check_jack_btn_type()
395 priv->jack_type = 0; in check_jack_btn_type()
402 struct mt6359_accdet *priv = in mt6359_accdet_work() local
405 mutex_lock(&priv->res_lock); in mt6359_accdet_work()
406 priv->pre_accdet_status = priv->accdet_status; in mt6359_accdet_work()
407 check_jack_btn_type(priv); in mt6359_accdet_work()
409 if (priv->jack_plugged && in mt6359_accdet_work()
410 priv->pre_accdet_status != priv->accdet_status) in mt6359_accdet_work()
411 mt6359_accdet_jack_report(priv); in mt6359_accdet_work()
412 mutex_unlock(&priv->res_lock); in mt6359_accdet_work()
420 struct mt6359_accdet *priv = in mt6359_accdet_jd_work() local
423 mutex_lock(&priv->res_lock); in mt6359_accdet_jd_work()
424 if (priv->jd_sts == M_PLUG_IN) { in mt6359_accdet_jd_work()
425 priv->jack_plugged = true; in mt6359_accdet_jd_work()
428 regmap_update_bits(priv->regmap, ACCDET_SEQ_INIT_ADDR, in mt6359_accdet_jd_work()
431 regmap_update_bits(priv->regmap, ACCDET_SEQ_INIT_ADDR, in mt6359_accdet_jd_work()
433 ret = regmap_read_poll_timeout(priv->regmap, in mt6359_accdet_jd_work()
440 dev_err(priv->dev, "%s(), ret %d\n", __func__, ret); in mt6359_accdet_jd_work()
443 regmap_update_bits(priv->regmap, ACCDET_SW_EN_ADDR, in mt6359_accdet_jd_work()
445 } else if (priv->jd_sts == M_PLUG_OUT) { in mt6359_accdet_jd_work()
446 priv->jack_plugged = false; in mt6359_accdet_jd_work()
448 accdet_set_debounce(priv, accdet_state011, in mt6359_accdet_jd_work()
449 priv->data->pwm_deb->debounce3); in mt6359_accdet_jd_work()
450 regmap_update_bits(priv->regmap, ACCDET_SW_EN_ADDR, in mt6359_accdet_jd_work()
452 mt6359_accdet_recover_jd_setting(priv); in mt6359_accdet_jd_work()
455 if (priv->caps & ACCDET_PMIC_EINT_IRQ) in mt6359_accdet_jd_work()
456 recover_eint_setting(priv); in mt6359_accdet_jd_work()
457 mutex_unlock(&priv->res_lock); in mt6359_accdet_jd_work()
462 struct mt6359_accdet *priv = data; in mt6359_accdet_irq() local
466 mutex_lock(&priv->res_lock); in mt6359_accdet_irq()
467 regmap_read(priv->regmap, ACCDET_IRQ_ADDR, &irq_val); in mt6359_accdet_irq()
470 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_irq()
473 ret = regmap_read_poll_timeout(priv->regmap, in mt6359_accdet_irq()
480 dev_err(priv->dev, "%s(), ret %d\n", __func__, ret); in mt6359_accdet_irq()
481 mutex_unlock(&priv->res_lock); in mt6359_accdet_irq()
484 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_irq()
486 regmap_update_bits(priv->regmap, RG_INT_STATUS_ACCDET_ADDR, in mt6359_accdet_irq()
490 queue_work(priv->accdet_workqueue, &priv->accdet_work); in mt6359_accdet_irq()
493 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_irq()
496 ret = regmap_read_poll_timeout(priv->regmap, in mt6359_accdet_irq()
503 dev_err(priv->dev, "%s(), ret %d\n", __func__, in mt6359_accdet_irq()
505 mutex_unlock(&priv->res_lock); in mt6359_accdet_irq()
508 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_irq()
510 regmap_update_bits(priv->regmap, in mt6359_accdet_irq()
516 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_irq()
519 ret = regmap_read_poll_timeout(priv->regmap, in mt6359_accdet_irq()
526 dev_err(priv->dev, "%s(), ret %d\n", __func__, in mt6359_accdet_irq()
528 mutex_unlock(&priv->res_lock); in mt6359_accdet_irq()
531 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_irq()
533 regmap_update_bits(priv->regmap, in mt6359_accdet_irq()
539 regmap_read(priv->regmap, ACCDET_EINT0_MEM_IN_ADDR, &val); in mt6359_accdet_irq()
540 priv->jd_sts = ((val >> ACCDET_EINT0_MEM_IN_SFT) & in mt6359_accdet_irq()
543 mt6359_accdet_jd_setting(priv); in mt6359_accdet_irq()
545 queue_work(priv->jd_workqueue, &priv->jd_work); in mt6359_accdet_irq()
547 mutex_unlock(&priv->res_lock); in mt6359_accdet_irq()
552 static int mt6359_accdet_parse_dt(struct mt6359_accdet *priv) in mt6359_accdet_parse_dt() argument
555 struct device *dev = priv->dev; in mt6359_accdet_parse_dt()
565 &priv->data->mic_vol); in mt6359_accdet_parse_dt()
567 priv->data->mic_vol = 8; in mt6359_accdet_parse_dt()
570 &priv->data->plugout_deb); in mt6359_accdet_parse_dt()
572 priv->data->plugout_deb = 1; in mt6359_accdet_parse_dt()
575 &priv->data->mic_mode); in mt6359_accdet_parse_dt()
577 priv->data->mic_mode = 2; in mt6359_accdet_parse_dt()
583 memcpy(priv->data->pwm_deb, pwm_deb, sizeof(pwm_deb)); in mt6359_accdet_parse_dt()
586 &priv->data->eint_pol); in mt6359_accdet_parse_dt()
588 priv->data->eint_pol = 8; in mt6359_accdet_parse_dt()
594 priv->caps |= ACCDET_PMIC_EINT_IRQ; in mt6359_accdet_parse_dt()
596 priv->caps |= ACCDET_AP_GPIO_EINT; in mt6359_accdet_parse_dt()
599 &priv->data->eint_detect_mode); in mt6359_accdet_parse_dt()
602 priv->data->eint_detect_mode = 0x4; in mt6359_accdet_parse_dt()
609 priv->caps |= ACCDET_PMIC_EINT0; in mt6359_accdet_parse_dt()
611 priv->caps |= ACCDET_PMIC_EINT1; in mt6359_accdet_parse_dt()
613 priv->caps |= ACCDET_PMIC_BI_EINT; in mt6359_accdet_parse_dt()
620 priv->caps |= ACCDET_PMIC_GPIO_TRIG_EINT; in mt6359_accdet_parse_dt()
622 priv->caps |= ACCDET_PMIC_INVERTER_TRIG_EINT; in mt6359_accdet_parse_dt()
625 &priv->data->eint_use_ext_res); in mt6359_accdet_parse_dt()
628 priv->data->eint_use_ext_res = 0x0; in mt6359_accdet_parse_dt()
632 &priv->data->eint_comp_vth); in mt6359_accdet_parse_dt()
634 priv->data->eint_comp_vth = 0x0; in mt6359_accdet_parse_dt()
642 priv->caps |= ACCDET_THREE_KEY; in mt6359_accdet_parse_dt()
648 memcpy(&priv->data->three_key, three_key + 1, in mt6359_accdet_parse_dt()
653 priv->caps |= ACCDET_FOUR_KEY; in mt6359_accdet_parse_dt()
659 memcpy(&priv->data->four_key, four_key + 1, in mt6359_accdet_parse_dt()
662 dev_warn(priv->dev, in mt6359_accdet_parse_dt()
668 priv->caps |= ACCDET_TRI_KEY_CDD; in mt6359_accdet_parse_dt()
674 memcpy(&priv->data->three_key, three_key + 1, in mt6359_accdet_parse_dt()
678 dev_warn(priv->dev, "accdet caps=%x\n", priv->caps); in mt6359_accdet_parse_dt()
683 static void config_digital_init_by_mode(struct mt6359_accdet *priv) in config_digital_init_by_mode() argument
686 regmap_write(priv->regmap, ACCDET_EINT_CMPMEN_PWM_THRESH_ADDR, in config_digital_init_by_mode()
687 (priv->data->pwm_deb->eint_pwm_width << 4 | in config_digital_init_by_mode()
688 priv->data->pwm_deb->eint_pwm_thresh)); in config_digital_init_by_mode()
690 if (priv->caps & ACCDET_PMIC_EINT0) { in config_digital_init_by_mode()
691 regmap_write(priv->regmap, ACCDET_DA_STABLE_ADDR, in config_digital_init_by_mode()
693 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_digital_init_by_mode()
694 regmap_write(priv->regmap, ACCDET_DA_STABLE_ADDR, in config_digital_init_by_mode()
698 regmap_update_bits(priv->regmap, ACCDET_EINT_M_PLUG_IN_NUM_ADDR, in config_digital_init_by_mode()
705 regmap_write(priv->regmap, ACCDET_HWMODE_EN_ADDR, 0x100); in config_digital_init_by_mode()
707 regmap_update_bits(priv->regmap, ACCDET_EINT_M_DETECT_EN_ADDR, in config_digital_init_by_mode()
711 regmap_write(priv->regmap, ACCDET_CMP_PWM_EN_ADDR, 0x67); in config_digital_init_by_mode()
713 if (priv->data->eint_detect_mode == 0x1) { in config_digital_init_by_mode()
715 if (priv->caps & ACCDET_PMIC_EINT0) { in config_digital_init_by_mode()
716 regmap_update_bits(priv->regmap, in config_digital_init_by_mode()
720 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_digital_init_by_mode()
721 regmap_update_bits(priv->regmap, in config_digital_init_by_mode()
727 if (priv->caps & ACCDET_PMIC_EINT0) { in config_digital_init_by_mode()
728 regmap_update_bits(priv->regmap, in config_digital_init_by_mode()
732 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_digital_init_by_mode()
733 regmap_update_bits(priv->regmap, in config_digital_init_by_mode()
741 static void config_eint_init_by_mode(struct mt6359_accdet *priv) in config_eint_init_by_mode() argument
745 if (priv->caps & ACCDET_PMIC_EINT0) { in config_eint_init_by_mode()
746 regmap_update_bits(priv->regmap, RG_EINT0EN_ADDR, in config_eint_init_by_mode()
748 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_eint_init_by_mode()
749 regmap_update_bits(priv->regmap, RG_EINT1EN_ADDR, in config_eint_init_by_mode()
753 regmap_update_bits(priv->regmap, RG_ACCDETSPARE_ADDR, in config_eint_init_by_mode()
756 regmap_update_bits(priv->regmap, RG_NCP_PDDIS_EN_ADDR, in config_eint_init_by_mode()
759 if (priv->data->eint_detect_mode == 0x1 || in config_eint_init_by_mode()
760 priv->data->eint_detect_mode == 0x2 || in config_eint_init_by_mode()
761 priv->data->eint_detect_mode == 0x3) { in config_eint_init_by_mode()
762 if (priv->data->eint_use_ext_res == 0x1) { in config_eint_init_by_mode()
763 if (priv->caps & ACCDET_PMIC_EINT0) { in config_eint_init_by_mode()
764 regmap_update_bits(priv->regmap, in config_eint_init_by_mode()
768 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_eint_init_by_mode()
769 regmap_update_bits(priv->regmap, in config_eint_init_by_mode()
775 if (priv->caps & ACCDET_PMIC_EINT0) { in config_eint_init_by_mode()
776 regmap_update_bits(priv->regmap, in config_eint_init_by_mode()
780 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_eint_init_by_mode()
781 regmap_update_bits(priv->regmap, in config_eint_init_by_mode()
789 if (priv->data->eint_detect_mode != 0x1) { in config_eint_init_by_mode()
791 regmap_update_bits(priv->regmap, RG_ACCDETSPARE_ADDR, in config_eint_init_by_mode()
795 regmap_write(priv->regmap, RG_EINTCOMPVTH_ADDR, in config_eint_init_by_mode()
796 val | priv->data->eint_comp_vth << RG_EINTCOMPVTH_SFT); in config_eint_init_by_mode()
799 static void mt6359_accdet_init(struct mt6359_accdet *priv) in mt6359_accdet_init() argument
803 regmap_update_bits(priv->regmap, ACCDET_SEQ_INIT_ADDR, in mt6359_accdet_init()
806 regmap_update_bits(priv->regmap, ACCDET_SEQ_INIT_ADDR, in mt6359_accdet_init()
810 accdet_set_debounce(priv, accdet_state000, in mt6359_accdet_init()
811 priv->data->pwm_deb->debounce0); in mt6359_accdet_init()
812 accdet_set_debounce(priv, accdet_state001, in mt6359_accdet_init()
813 priv->data->pwm_deb->debounce1); in mt6359_accdet_init()
814 accdet_set_debounce(priv, accdet_state011, in mt6359_accdet_init()
815 priv->data->pwm_deb->debounce3); in mt6359_accdet_init()
816 accdet_set_debounce(priv, accdet_auxadc, in mt6359_accdet_init()
817 priv->data->pwm_deb->debounce4); in mt6359_accdet_init()
819 accdet_set_debounce(priv, eint_state000, in mt6359_accdet_init()
820 priv->data->pwm_deb->eint_debounce0); in mt6359_accdet_init()
821 accdet_set_debounce(priv, eint_state001, in mt6359_accdet_init()
822 priv->data->pwm_deb->eint_debounce1); in mt6359_accdet_init()
823 accdet_set_debounce(priv, eint_state011, in mt6359_accdet_init()
824 priv->data->pwm_deb->eint_debounce3); in mt6359_accdet_init()
825 accdet_set_debounce(priv, eint_inverter_state000, in mt6359_accdet_init()
826 priv->data->pwm_deb->eint_inverter_debounce); in mt6359_accdet_init()
828 regmap_update_bits(priv->regmap, RG_ACCDET_RST_ADDR, in mt6359_accdet_init()
830 regmap_update_bits(priv->regmap, RG_ACCDET_RST_ADDR, in mt6359_accdet_init()
834 regmap_update_bits(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
836 regmap_update_bits(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
840 regmap_write(priv->regmap, ACCDET_PWM_WIDTH_ADDR, in mt6359_accdet_init()
841 REGISTER_VAL(priv->data->pwm_deb->pwm_width)); in mt6359_accdet_init()
842 regmap_write(priv->regmap, ACCDET_PWM_THRESH_ADDR, in mt6359_accdet_init()
843 REGISTER_VAL(priv->data->pwm_deb->pwm_thresh)); in mt6359_accdet_init()
844 regmap_write(priv->regmap, ACCDET_RISE_DELAY_ADDR, in mt6359_accdet_init()
845 (priv->data->pwm_deb->fall_delay << 15 | in mt6359_accdet_init()
846 priv->data->pwm_deb->rise_delay)); in mt6359_accdet_init()
848 regmap_read(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, &reg); in mt6359_accdet_init()
849 if (priv->data->mic_vol <= 7) { in mt6359_accdet_init()
851 regmap_write(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
852 reg | (priv->data->mic_vol << RG_AUDMICBIAS1VREF_SFT) | in mt6359_accdet_init()
854 } else if (priv->data->mic_vol == 8) { in mt6359_accdet_init()
856 regmap_write(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
859 } else if (priv->data->mic_vol == 9) { in mt6359_accdet_init()
861 regmap_write(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
866 regmap_read(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR, &reg); in mt6359_accdet_init()
867 if (priv->data->mic_mode == HEADSET_MODE_1) { in mt6359_accdet_init()
869 regmap_write(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR, in mt6359_accdet_init()
872 regmap_update_bits(priv->regmap, RG_ANALOGFDEN_ADDR, in mt6359_accdet_init()
875 regmap_update_bits(priv->regmap, RG_ACCDETSPARE_ADDR, in mt6359_accdet_init()
877 } else if (priv->data->mic_mode == HEADSET_MODE_2) { in mt6359_accdet_init()
879 regmap_write(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR, in mt6359_accdet_init()
882 regmap_update_bits(priv->regmap, RG_ANALOGFDEN_ADDR, in mt6359_accdet_init()
885 } else if (priv->data->mic_mode == HEADSET_MODE_6) { in mt6359_accdet_init()
889 regmap_write(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR, in mt6359_accdet_init()
891 regmap_update_bits(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
895 regmap_update_bits(priv->regmap, RG_ANALOGFDEN_ADDR, in mt6359_accdet_init()
900 if (priv->caps & ACCDET_PMIC_EINT_IRQ) { in mt6359_accdet_init()
901 config_eint_init_by_mode(priv); in mt6359_accdet_init()
902 config_digital_init_by_mode(priv); in mt6359_accdet_init()
909 struct mt6359_accdet *priv = in mt6359_accdet_enable_jack_detect() local
917 priv->jack = jack; in mt6359_accdet_enable_jack_detect()
919 mt6359_accdet_jack_report(priv); in mt6359_accdet_enable_jack_detect()
927 struct mt6359_accdet *priv; in mt6359_accdet_probe() local
934 priv = devm_kzalloc(&pdev->dev, sizeof(struct mt6359_accdet), in mt6359_accdet_probe()
936 if (!priv) in mt6359_accdet_probe()
939 priv->data = devm_kzalloc(&pdev->dev, sizeof(struct dts_data), in mt6359_accdet_probe()
941 if (!priv->data) in mt6359_accdet_probe()
944 priv->data->pwm_deb = devm_kzalloc(&pdev->dev, in mt6359_accdet_probe()
947 if (!priv->data->pwm_deb) in mt6359_accdet_probe()
950 priv->regmap = mt6397->regmap; in mt6359_accdet_probe()
951 if (IS_ERR(priv->regmap)) { in mt6359_accdet_probe()
952 ret = PTR_ERR(priv->regmap); in mt6359_accdet_probe()
957 priv->dev = &pdev->dev; in mt6359_accdet_probe()
959 ret = mt6359_accdet_parse_dt(priv); in mt6359_accdet_probe()
964 mutex_init(&priv->res_lock); in mt6359_accdet_probe()
966 priv->accdet_irq = platform_get_irq(pdev, 0); in mt6359_accdet_probe()
967 if (priv->accdet_irq) { in mt6359_accdet_probe()
968 ret = devm_request_threaded_irq(&pdev->dev, priv->accdet_irq, in mt6359_accdet_probe()
971 "ACCDET_IRQ", priv); in mt6359_accdet_probe()
979 if (priv->caps & ACCDET_PMIC_EINT0) { in mt6359_accdet_probe()
980 priv->accdet_eint0 = platform_get_irq(pdev, 1); in mt6359_accdet_probe()
981 if (priv->accdet_eint0) { in mt6359_accdet_probe()
983 priv->accdet_eint0, in mt6359_accdet_probe()
986 "ACCDET_EINT0", priv); in mt6359_accdet_probe()
994 } else if (priv->caps & ACCDET_PMIC_EINT1) { in mt6359_accdet_probe()
995 priv->accdet_eint1 = platform_get_irq(pdev, 2); in mt6359_accdet_probe()
996 if (priv->accdet_eint1) { in mt6359_accdet_probe()
998 priv->accdet_eint1, in mt6359_accdet_probe()
1001 "ACCDET_EINT1", priv); in mt6359_accdet_probe()
1011 priv->accdet_workqueue = create_singlethread_workqueue("accdet"); in mt6359_accdet_probe()
1012 INIT_WORK(&priv->accdet_work, mt6359_accdet_work); in mt6359_accdet_probe()
1013 if (!priv->accdet_workqueue) { in mt6359_accdet_probe()
1019 priv->jd_workqueue = create_singlethread_workqueue("mt6359_accdet_jd"); in mt6359_accdet_probe()
1020 INIT_WORK(&priv->jd_work, mt6359_accdet_jd_work); in mt6359_accdet_probe()
1021 if (!priv->jd_workqueue) { in mt6359_accdet_probe()
1027 platform_set_drvdata(pdev, priv); in mt6359_accdet_probe()
1036 priv->jd_sts = M_PLUG_OUT; in mt6359_accdet_probe()
1037 priv->jack_type = 0; in mt6359_accdet_probe()
1038 priv->btn_type = 0; in mt6359_accdet_probe()
1039 priv->accdet_status = 0x3; in mt6359_accdet_probe()
1040 mt6359_accdet_init(priv); in mt6359_accdet_probe()
1042 mt6359_accdet_jack_report(priv); in mt6359_accdet_probe()
1047 destroy_workqueue(priv->accdet_workqueue); in mt6359_accdet_probe()