Lines Matching refs:priv

58 static void accdet_set_debounce(struct mt6359_accdet *priv, int state,
60 static unsigned int adjust_eint_analog_setting(struct mt6359_accdet *priv);
61 static void config_digital_init_by_mode(struct mt6359_accdet *priv);
62 static void config_eint_init_by_mode(struct mt6359_accdet *priv);
63 static inline void mt6359_accdet_init(struct mt6359_accdet *priv);
64 static unsigned int mt6359_accdet_jd_setting(struct mt6359_accdet *priv);
65 static void mt6359_accdet_recover_jd_setting(struct mt6359_accdet *priv);
66 static void mt6359_accdet_jack_report(struct mt6359_accdet *priv);
67 static void recover_eint_analog_setting(struct mt6359_accdet *priv);
68 static void recover_eint_digital_setting(struct mt6359_accdet *priv);
69 static void recover_eint_setting(struct mt6359_accdet *priv);
71 static unsigned int adjust_eint_analog_setting(struct mt6359_accdet *priv) in adjust_eint_analog_setting() argument
73 if (priv->data->eint_detect_mode == 0x3 || in adjust_eint_analog_setting()
74 priv->data->eint_detect_mode == 0x4) { in adjust_eint_analog_setting()
76 regmap_update_bits(priv->regmap, in adjust_eint_analog_setting()
79 if (priv->data->eint_detect_mode == 0x4) { in adjust_eint_analog_setting()
80 if (priv->caps & ACCDET_PMIC_EINT0) { in adjust_eint_analog_setting()
82 regmap_update_bits(priv->regmap, in adjust_eint_analog_setting()
86 } else if (priv->caps & ACCDET_PMIC_EINT1) { in adjust_eint_analog_setting()
88 regmap_update_bits(priv->regmap, in adjust_eint_analog_setting()
93 if (priv->data->eint_use_ext_res == 0x3 || in adjust_eint_analog_setting()
94 priv->data->eint_use_ext_res == 0x4) { in adjust_eint_analog_setting()
96 regmap_update_bits(priv->regmap, in adjust_eint_analog_setting()
105 static unsigned int adjust_eint_digital_setting(struct mt6359_accdet *priv) in adjust_eint_digital_setting() argument
107 if (priv->caps & ACCDET_PMIC_EINT0) { in adjust_eint_digital_setting()
109 regmap_update_bits(priv->regmap, in adjust_eint_digital_setting()
112 } else if (priv->caps & ACCDET_PMIC_EINT1) { in adjust_eint_digital_setting()
114 regmap_update_bits(priv->regmap, in adjust_eint_digital_setting()
119 if (priv->data->eint_detect_mode == 0x4) { in adjust_eint_digital_setting()
120 if (priv->caps & ACCDET_PMIC_EINT0) { in adjust_eint_digital_setting()
122 regmap_update_bits(priv->regmap, in adjust_eint_digital_setting()
125 } else if (priv->caps & ACCDET_PMIC_EINT1) { in adjust_eint_digital_setting()
127 regmap_update_bits(priv->regmap, in adjust_eint_digital_setting()
135 static unsigned int mt6359_accdet_jd_setting(struct mt6359_accdet *priv) in mt6359_accdet_jd_setting() argument
137 if (priv->jd_sts == M_PLUG_IN) { in mt6359_accdet_jd_setting()
139 adjust_eint_digital_setting(priv); in mt6359_accdet_jd_setting()
141 adjust_eint_analog_setting(priv); in mt6359_accdet_jd_setting()
142 } else if (priv->jd_sts == M_PLUG_OUT) { in mt6359_accdet_jd_setting()
144 accdet_set_debounce(priv, eint_state000, in mt6359_accdet_jd_setting()
145 priv->data->pwm_deb->eint_debounce0); in mt6359_accdet_jd_setting()
147 dev_dbg(priv->dev, "should not be here %s()\n", __func__); in mt6359_accdet_jd_setting()
153 static void recover_eint_analog_setting(struct mt6359_accdet *priv) in recover_eint_analog_setting() argument
155 if (priv->data->eint_detect_mode == 0x3 || in recover_eint_analog_setting()
156 priv->data->eint_detect_mode == 0x4) { in recover_eint_analog_setting()
158 regmap_update_bits(priv->regmap, RG_ACCDETSPARE_ADDR, in recover_eint_analog_setting()
161 if (priv->data->eint_detect_mode == 0x4) { in recover_eint_analog_setting()
162 if (priv->caps & ACCDET_PMIC_EINT0) { in recover_eint_analog_setting()
164 regmap_update_bits(priv->regmap, in recover_eint_analog_setting()
167 } else if (priv->caps & ACCDET_PMIC_EINT1) { in recover_eint_analog_setting()
169 regmap_update_bits(priv->regmap, in recover_eint_analog_setting()
173 regmap_update_bits(priv->regmap, RG_EINT0HIRENB_ADDR, in recover_eint_analog_setting()
178 static void recover_eint_digital_setting(struct mt6359_accdet *priv) in recover_eint_digital_setting() argument
180 if (priv->caps & ACCDET_PMIC_EINT0) { in recover_eint_digital_setting()
181 regmap_update_bits(priv->regmap, in recover_eint_digital_setting()
184 } else if (priv->caps & ACCDET_PMIC_EINT1) { in recover_eint_digital_setting()
185 regmap_update_bits(priv->regmap, in recover_eint_digital_setting()
189 if (priv->data->eint_detect_mode == 0x4) { in recover_eint_digital_setting()
191 if (priv->caps & ACCDET_PMIC_EINT0) { in recover_eint_digital_setting()
193 regmap_update_bits(priv->regmap, in recover_eint_digital_setting()
197 } else if (priv->caps & ACCDET_PMIC_EINT1) { in recover_eint_digital_setting()
199 regmap_update_bits(priv->regmap, in recover_eint_digital_setting()
206 if (priv->data->eint_detect_mode != 0x1) { in recover_eint_digital_setting()
207 if (priv->caps & ACCDET_PMIC_EINT0) { in recover_eint_digital_setting()
209 regmap_update_bits(priv->regmap, in recover_eint_digital_setting()
213 } else if (priv->caps & ACCDET_PMIC_EINT1) { in recover_eint_digital_setting()
215 regmap_update_bits(priv->regmap, in recover_eint_digital_setting()
223 static void recover_eint_setting(struct mt6359_accdet *priv) in recover_eint_setting() argument
225 if (priv->jd_sts == M_PLUG_OUT) { in recover_eint_setting()
226 recover_eint_analog_setting(priv); in recover_eint_setting()
227 recover_eint_digital_setting(priv); in recover_eint_setting()
231 static void mt6359_accdet_recover_jd_setting(struct mt6359_accdet *priv) in mt6359_accdet_recover_jd_setting() argument
236 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_recover_jd_setting()
239 ret = regmap_read_poll_timeout(priv->regmap, in mt6359_accdet_recover_jd_setting()
246 dev_warn(priv->dev, "%s(), ret %d\n", __func__, ret); in mt6359_accdet_recover_jd_setting()
248 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_recover_jd_setting()
250 regmap_update_bits(priv->regmap, RG_INT_STATUS_ACCDET_ADDR, in mt6359_accdet_recover_jd_setting()
255 accdet_set_debounce(priv, accdet_state000, in mt6359_accdet_recover_jd_setting()
256 priv->data->pwm_deb->debounce0); in mt6359_accdet_recover_jd_setting()
257 accdet_set_debounce(priv, accdet_state001, in mt6359_accdet_recover_jd_setting()
258 priv->data->pwm_deb->debounce1); in mt6359_accdet_recover_jd_setting()
259 accdet_set_debounce(priv, accdet_state011, in mt6359_accdet_recover_jd_setting()
260 priv->data->pwm_deb->debounce3); in mt6359_accdet_recover_jd_setting()
262 priv->jack_type = 0; in mt6359_accdet_recover_jd_setting()
263 priv->btn_type = 0; in mt6359_accdet_recover_jd_setting()
264 priv->accdet_status = 0x3; in mt6359_accdet_recover_jd_setting()
265 mt6359_accdet_jack_report(priv); in mt6359_accdet_recover_jd_setting()
268 static void accdet_set_debounce(struct mt6359_accdet *priv, int state, in accdet_set_debounce() argument
273 regmap_write(priv->regmap, ACCDET_DEBOUNCE0_ADDR, debounce); in accdet_set_debounce()
276 regmap_write(priv->regmap, ACCDET_DEBOUNCE1_ADDR, debounce); in accdet_set_debounce()
279 regmap_write(priv->regmap, ACCDET_DEBOUNCE2_ADDR, debounce); in accdet_set_debounce()
282 regmap_write(priv->regmap, ACCDET_DEBOUNCE3_ADDR, debounce); in accdet_set_debounce()
285 regmap_write(priv->regmap, in accdet_set_debounce()
289 regmap_update_bits(priv->regmap, ACCDET_EINT_DEBOUNCE0_ADDR, in accdet_set_debounce()
294 regmap_update_bits(priv->regmap, ACCDET_EINT_DEBOUNCE1_ADDR, in accdet_set_debounce()
299 regmap_update_bits(priv->regmap, ACCDET_EINT_DEBOUNCE2_ADDR, in accdet_set_debounce()
304 regmap_update_bits(priv->regmap, ACCDET_EINT_DEBOUNCE3_ADDR, in accdet_set_debounce()
309 regmap_write(priv->regmap, ACCDET_EINT_INVERTER_DEBOUNCE_ADDR, in accdet_set_debounce()
313 dev_warn(priv->dev, "Error: %s error state (%d)\n", __func__, in accdet_set_debounce()
319 static void mt6359_accdet_jack_report(struct mt6359_accdet *priv) in mt6359_accdet_jack_report() argument
323 if (!priv->jack) in mt6359_accdet_jack_report()
326 report = priv->jack_type | priv->btn_type; in mt6359_accdet_jack_report()
327 snd_soc_jack_report(priv->jack, report, MT6359_ACCDET_JACK_MASK); in mt6359_accdet_jack_report()
330 static unsigned int check_button(struct mt6359_accdet *priv, unsigned int v) in check_button() argument
332 if (priv->caps & ACCDET_FOUR_KEY) { in check_button()
333 if (v < priv->data->four_key.down && in check_button()
334 v >= priv->data->four_key.up) in check_button()
335 priv->btn_type = SND_JACK_BTN_1; in check_button()
336 if (v < priv->data->four_key.up && in check_button()
337 v >= priv->data->four_key.voice) in check_button()
338 priv->btn_type = SND_JACK_BTN_2; in check_button()
339 if (v < priv->data->four_key.voice && in check_button()
340 v >= priv->data->four_key.mid) in check_button()
341 priv->btn_type = SND_JACK_BTN_3; in check_button()
342 if (v < priv->data->four_key.mid) in check_button()
343 priv->btn_type = SND_JACK_BTN_0; in check_button()
345 if (v < priv->data->three_key.down && in check_button()
346 v >= priv->data->three_key.up) in check_button()
347 priv->btn_type = SND_JACK_BTN_1; in check_button()
348 if (v < priv->data->three_key.up && in check_button()
349 v >= priv->data->three_key.mid) in check_button()
350 priv->btn_type = SND_JACK_BTN_2; in check_button()
351 if (v < priv->data->three_key.mid) in check_button()
352 priv->btn_type = SND_JACK_BTN_0; in check_button()
357 static void is_key_pressed(struct mt6359_accdet *priv, bool pressed) in is_key_pressed() argument
359 priv->btn_type = priv->jack_type & ~MT6359_ACCDET_BTN_MASK; in is_key_pressed()
362 check_button(priv, priv->cali_voltage); in is_key_pressed()
365 static inline void check_jack_btn_type(struct mt6359_accdet *priv) in check_jack_btn_type() argument
369 regmap_read(priv->regmap, ACCDET_MEM_IN_ADDR, &val); in check_jack_btn_type()
371 priv->accdet_status = in check_jack_btn_type()
374 switch (priv->accdet_status) { in check_jack_btn_type()
376 if (priv->jack_type == SND_JACK_HEADSET) in check_jack_btn_type()
377 is_key_pressed(priv, true); in check_jack_btn_type()
379 priv->jack_type = SND_JACK_HEADPHONE; in check_jack_btn_type()
382 if (priv->jack_type == SND_JACK_HEADSET) { in check_jack_btn_type()
383 is_key_pressed(priv, false); in check_jack_btn_type()
385 priv->jack_type = SND_JACK_HEADSET; in check_jack_btn_type()
386 accdet_set_debounce(priv, eint_state011, 0x1); in check_jack_btn_type()
391 priv->jack_type = 0; in check_jack_btn_type()
398 struct mt6359_accdet *priv = in mt6359_accdet_work() local
401 mutex_lock(&priv->res_lock); in mt6359_accdet_work()
402 priv->pre_accdet_status = priv->accdet_status; in mt6359_accdet_work()
403 check_jack_btn_type(priv); in mt6359_accdet_work()
405 if (priv->jack_plugged && in mt6359_accdet_work()
406 priv->pre_accdet_status != priv->accdet_status) in mt6359_accdet_work()
407 mt6359_accdet_jack_report(priv); in mt6359_accdet_work()
408 mutex_unlock(&priv->res_lock); in mt6359_accdet_work()
416 struct mt6359_accdet *priv = in mt6359_accdet_jd_work() local
419 mutex_lock(&priv->res_lock); in mt6359_accdet_jd_work()
420 if (priv->jd_sts == M_PLUG_IN) { in mt6359_accdet_jd_work()
421 priv->jack_plugged = true; in mt6359_accdet_jd_work()
424 regmap_update_bits(priv->regmap, ACCDET_SEQ_INIT_ADDR, in mt6359_accdet_jd_work()
427 regmap_update_bits(priv->regmap, ACCDET_SEQ_INIT_ADDR, in mt6359_accdet_jd_work()
429 ret = regmap_read_poll_timeout(priv->regmap, in mt6359_accdet_jd_work()
436 dev_err(priv->dev, "%s(), ret %d\n", __func__, ret); in mt6359_accdet_jd_work()
439 regmap_update_bits(priv->regmap, ACCDET_SW_EN_ADDR, in mt6359_accdet_jd_work()
441 } else if (priv->jd_sts == M_PLUG_OUT) { in mt6359_accdet_jd_work()
442 priv->jack_plugged = false; in mt6359_accdet_jd_work()
444 accdet_set_debounce(priv, accdet_state011, in mt6359_accdet_jd_work()
445 priv->data->pwm_deb->debounce3); in mt6359_accdet_jd_work()
446 regmap_update_bits(priv->regmap, ACCDET_SW_EN_ADDR, in mt6359_accdet_jd_work()
448 mt6359_accdet_recover_jd_setting(priv); in mt6359_accdet_jd_work()
451 if (priv->caps & ACCDET_PMIC_EINT_IRQ) in mt6359_accdet_jd_work()
452 recover_eint_setting(priv); in mt6359_accdet_jd_work()
453 mutex_unlock(&priv->res_lock); in mt6359_accdet_jd_work()
458 struct mt6359_accdet *priv = data; in mt6359_accdet_irq() local
462 mutex_lock(&priv->res_lock); in mt6359_accdet_irq()
463 regmap_read(priv->regmap, ACCDET_IRQ_ADDR, &irq_val); in mt6359_accdet_irq()
466 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_irq()
469 ret = regmap_read_poll_timeout(priv->regmap, in mt6359_accdet_irq()
476 dev_err(priv->dev, "%s(), ret %d\n", __func__, ret); in mt6359_accdet_irq()
477 mutex_unlock(&priv->res_lock); in mt6359_accdet_irq()
480 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_irq()
482 regmap_update_bits(priv->regmap, RG_INT_STATUS_ACCDET_ADDR, in mt6359_accdet_irq()
486 queue_work(priv->accdet_workqueue, &priv->accdet_work); in mt6359_accdet_irq()
489 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_irq()
492 ret = regmap_read_poll_timeout(priv->regmap, in mt6359_accdet_irq()
499 dev_err(priv->dev, "%s(), ret %d\n", __func__, in mt6359_accdet_irq()
501 mutex_unlock(&priv->res_lock); in mt6359_accdet_irq()
504 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_irq()
506 regmap_update_bits(priv->regmap, in mt6359_accdet_irq()
512 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_irq()
515 ret = regmap_read_poll_timeout(priv->regmap, in mt6359_accdet_irq()
522 dev_err(priv->dev, "%s(), ret %d\n", __func__, in mt6359_accdet_irq()
524 mutex_unlock(&priv->res_lock); in mt6359_accdet_irq()
527 regmap_update_bits(priv->regmap, ACCDET_IRQ_ADDR, in mt6359_accdet_irq()
529 regmap_update_bits(priv->regmap, in mt6359_accdet_irq()
535 regmap_read(priv->regmap, ACCDET_EINT0_MEM_IN_ADDR, &val); in mt6359_accdet_irq()
536 priv->jd_sts = ((val >> ACCDET_EINT0_MEM_IN_SFT) & in mt6359_accdet_irq()
539 mt6359_accdet_jd_setting(priv); in mt6359_accdet_irq()
541 queue_work(priv->jd_workqueue, &priv->jd_work); in mt6359_accdet_irq()
543 mutex_unlock(&priv->res_lock); in mt6359_accdet_irq()
548 static int mt6359_accdet_parse_dt(struct mt6359_accdet *priv) in mt6359_accdet_parse_dt() argument
551 struct device *dev = priv->dev; in mt6359_accdet_parse_dt()
561 &priv->data->mic_vol); in mt6359_accdet_parse_dt()
563 priv->data->mic_vol = 8; in mt6359_accdet_parse_dt()
566 &priv->data->plugout_deb); in mt6359_accdet_parse_dt()
568 priv->data->plugout_deb = 1; in mt6359_accdet_parse_dt()
571 &priv->data->mic_mode); in mt6359_accdet_parse_dt()
573 priv->data->mic_mode = 2; in mt6359_accdet_parse_dt()
579 memcpy(priv->data->pwm_deb, pwm_deb, sizeof(pwm_deb)); in mt6359_accdet_parse_dt()
582 &priv->data->eint_pol); in mt6359_accdet_parse_dt()
584 priv->data->eint_pol = 8; in mt6359_accdet_parse_dt()
590 priv->caps |= ACCDET_PMIC_EINT_IRQ; in mt6359_accdet_parse_dt()
592 priv->caps |= ACCDET_AP_GPIO_EINT; in mt6359_accdet_parse_dt()
595 &priv->data->eint_detect_mode); in mt6359_accdet_parse_dt()
598 priv->data->eint_detect_mode = 0x4; in mt6359_accdet_parse_dt()
605 priv->caps |= ACCDET_PMIC_EINT0; in mt6359_accdet_parse_dt()
607 priv->caps |= ACCDET_PMIC_EINT1; in mt6359_accdet_parse_dt()
609 priv->caps |= ACCDET_PMIC_BI_EINT; in mt6359_accdet_parse_dt()
616 priv->caps |= ACCDET_PMIC_GPIO_TRIG_EINT; in mt6359_accdet_parse_dt()
618 priv->caps |= ACCDET_PMIC_INVERTER_TRIG_EINT; in mt6359_accdet_parse_dt()
621 &priv->data->eint_use_ext_res); in mt6359_accdet_parse_dt()
624 priv->data->eint_use_ext_res = 0x0; in mt6359_accdet_parse_dt()
628 &priv->data->eint_comp_vth); in mt6359_accdet_parse_dt()
630 priv->data->eint_comp_vth = 0x0; in mt6359_accdet_parse_dt()
638 priv->caps |= ACCDET_THREE_KEY; in mt6359_accdet_parse_dt()
644 memcpy(&priv->data->three_key, three_key + 1, in mt6359_accdet_parse_dt()
649 priv->caps |= ACCDET_FOUR_KEY; in mt6359_accdet_parse_dt()
655 memcpy(&priv->data->four_key, four_key + 1, in mt6359_accdet_parse_dt()
658 dev_warn(priv->dev, in mt6359_accdet_parse_dt()
664 priv->caps |= ACCDET_TRI_KEY_CDD; in mt6359_accdet_parse_dt()
670 memcpy(&priv->data->three_key, three_key + 1, in mt6359_accdet_parse_dt()
675 dev_warn(priv->dev, "accdet caps=%x\n", priv->caps); in mt6359_accdet_parse_dt()
680 static void config_digital_init_by_mode(struct mt6359_accdet *priv) in config_digital_init_by_mode() argument
683 regmap_write(priv->regmap, ACCDET_EINT_CMPMEN_PWM_THRESH_ADDR, in config_digital_init_by_mode()
684 (priv->data->pwm_deb->eint_pwm_width << 4 | in config_digital_init_by_mode()
685 priv->data->pwm_deb->eint_pwm_thresh)); in config_digital_init_by_mode()
687 if (priv->caps & ACCDET_PMIC_EINT0) { in config_digital_init_by_mode()
688 regmap_write(priv->regmap, ACCDET_DA_STABLE_ADDR, in config_digital_init_by_mode()
690 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_digital_init_by_mode()
691 regmap_write(priv->regmap, ACCDET_DA_STABLE_ADDR, in config_digital_init_by_mode()
695 regmap_update_bits(priv->regmap, ACCDET_EINT_M_PLUG_IN_NUM_ADDR, in config_digital_init_by_mode()
702 regmap_write(priv->regmap, ACCDET_HWMODE_EN_ADDR, 0x100); in config_digital_init_by_mode()
704 regmap_update_bits(priv->regmap, ACCDET_EINT_M_DETECT_EN_ADDR, in config_digital_init_by_mode()
708 regmap_write(priv->regmap, ACCDET_CMP_PWM_EN_ADDR, 0x67); in config_digital_init_by_mode()
710 if (priv->data->eint_detect_mode == 0x1) { in config_digital_init_by_mode()
712 if (priv->caps & ACCDET_PMIC_EINT0) { in config_digital_init_by_mode()
713 regmap_update_bits(priv->regmap, in config_digital_init_by_mode()
717 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_digital_init_by_mode()
718 regmap_update_bits(priv->regmap, in config_digital_init_by_mode()
724 if (priv->caps & ACCDET_PMIC_EINT0) { in config_digital_init_by_mode()
725 regmap_update_bits(priv->regmap, in config_digital_init_by_mode()
729 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_digital_init_by_mode()
730 regmap_update_bits(priv->regmap, in config_digital_init_by_mode()
738 static void config_eint_init_by_mode(struct mt6359_accdet *priv) in config_eint_init_by_mode() argument
742 if (priv->caps & ACCDET_PMIC_EINT0) { in config_eint_init_by_mode()
743 regmap_update_bits(priv->regmap, RG_EINT0EN_ADDR, in config_eint_init_by_mode()
745 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_eint_init_by_mode()
746 regmap_update_bits(priv->regmap, RG_EINT1EN_ADDR, in config_eint_init_by_mode()
750 regmap_update_bits(priv->regmap, RG_ACCDETSPARE_ADDR, in config_eint_init_by_mode()
753 regmap_update_bits(priv->regmap, RG_NCP_PDDIS_EN_ADDR, in config_eint_init_by_mode()
756 if (priv->data->eint_detect_mode == 0x1 || in config_eint_init_by_mode()
757 priv->data->eint_detect_mode == 0x2 || in config_eint_init_by_mode()
758 priv->data->eint_detect_mode == 0x3) { in config_eint_init_by_mode()
759 if (priv->data->eint_use_ext_res == 0x1) { in config_eint_init_by_mode()
760 if (priv->caps & ACCDET_PMIC_EINT0) { in config_eint_init_by_mode()
761 regmap_update_bits(priv->regmap, in config_eint_init_by_mode()
765 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_eint_init_by_mode()
766 regmap_update_bits(priv->regmap, in config_eint_init_by_mode()
772 if (priv->caps & ACCDET_PMIC_EINT0) { in config_eint_init_by_mode()
773 regmap_update_bits(priv->regmap, in config_eint_init_by_mode()
777 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_eint_init_by_mode()
778 regmap_update_bits(priv->regmap, in config_eint_init_by_mode()
786 if (priv->data->eint_detect_mode != 0x1) { in config_eint_init_by_mode()
788 regmap_update_bits(priv->regmap, RG_ACCDETSPARE_ADDR, in config_eint_init_by_mode()
792 regmap_write(priv->regmap, RG_EINTCOMPVTH_ADDR, in config_eint_init_by_mode()
793 val | priv->data->eint_comp_vth << RG_EINTCOMPVTH_SFT); in config_eint_init_by_mode()
796 static void mt6359_accdet_init(struct mt6359_accdet *priv) in mt6359_accdet_init() argument
800 regmap_update_bits(priv->regmap, ACCDET_SEQ_INIT_ADDR, in mt6359_accdet_init()
803 regmap_update_bits(priv->regmap, ACCDET_SEQ_INIT_ADDR, in mt6359_accdet_init()
807 accdet_set_debounce(priv, accdet_state000, in mt6359_accdet_init()
808 priv->data->pwm_deb->debounce0); in mt6359_accdet_init()
809 accdet_set_debounce(priv, accdet_state001, in mt6359_accdet_init()
810 priv->data->pwm_deb->debounce1); in mt6359_accdet_init()
811 accdet_set_debounce(priv, accdet_state011, in mt6359_accdet_init()
812 priv->data->pwm_deb->debounce3); in mt6359_accdet_init()
813 accdet_set_debounce(priv, accdet_auxadc, in mt6359_accdet_init()
814 priv->data->pwm_deb->debounce4); in mt6359_accdet_init()
816 accdet_set_debounce(priv, eint_state000, in mt6359_accdet_init()
817 priv->data->pwm_deb->eint_debounce0); in mt6359_accdet_init()
818 accdet_set_debounce(priv, eint_state001, in mt6359_accdet_init()
819 priv->data->pwm_deb->eint_debounce1); in mt6359_accdet_init()
820 accdet_set_debounce(priv, eint_state011, in mt6359_accdet_init()
821 priv->data->pwm_deb->eint_debounce3); in mt6359_accdet_init()
822 accdet_set_debounce(priv, eint_inverter_state000, in mt6359_accdet_init()
823 priv->data->pwm_deb->eint_inverter_debounce); in mt6359_accdet_init()
825 regmap_update_bits(priv->regmap, RG_ACCDET_RST_ADDR, in mt6359_accdet_init()
827 regmap_update_bits(priv->regmap, RG_ACCDET_RST_ADDR, in mt6359_accdet_init()
831 regmap_update_bits(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
833 regmap_update_bits(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
837 regmap_write(priv->regmap, ACCDET_PWM_WIDTH_ADDR, in mt6359_accdet_init()
838 REGISTER_VAL(priv->data->pwm_deb->pwm_width)); in mt6359_accdet_init()
839 regmap_write(priv->regmap, ACCDET_PWM_THRESH_ADDR, in mt6359_accdet_init()
840 REGISTER_VAL(priv->data->pwm_deb->pwm_thresh)); in mt6359_accdet_init()
841 regmap_write(priv->regmap, ACCDET_RISE_DELAY_ADDR, in mt6359_accdet_init()
842 (priv->data->pwm_deb->fall_delay << 15 | in mt6359_accdet_init()
843 priv->data->pwm_deb->rise_delay)); in mt6359_accdet_init()
845 regmap_read(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, &reg); in mt6359_accdet_init()
846 if (priv->data->mic_vol <= 7) { in mt6359_accdet_init()
848 regmap_write(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
849 reg | (priv->data->mic_vol << RG_AUDMICBIAS1VREF_SFT) | in mt6359_accdet_init()
851 } else if (priv->data->mic_vol == 8) { in mt6359_accdet_init()
853 regmap_write(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
856 } else if (priv->data->mic_vol == 9) { in mt6359_accdet_init()
858 regmap_write(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
863 regmap_read(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR, &reg); in mt6359_accdet_init()
864 if (priv->data->mic_mode == HEADSET_MODE_1) { in mt6359_accdet_init()
866 regmap_write(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR, in mt6359_accdet_init()
869 regmap_update_bits(priv->regmap, RG_ANALOGFDEN_ADDR, in mt6359_accdet_init()
872 regmap_update_bits(priv->regmap, RG_ACCDETSPARE_ADDR, in mt6359_accdet_init()
874 } else if (priv->data->mic_mode == HEADSET_MODE_2) { in mt6359_accdet_init()
876 regmap_write(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR, in mt6359_accdet_init()
879 regmap_update_bits(priv->regmap, RG_ANALOGFDEN_ADDR, in mt6359_accdet_init()
882 } else if (priv->data->mic_mode == HEADSET_MODE_6) { in mt6359_accdet_init()
886 regmap_write(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR, in mt6359_accdet_init()
888 regmap_update_bits(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
892 regmap_update_bits(priv->regmap, RG_ANALOGFDEN_ADDR, in mt6359_accdet_init()
897 if (priv->caps & ACCDET_PMIC_EINT_IRQ) { in mt6359_accdet_init()
898 config_eint_init_by_mode(priv); in mt6359_accdet_init()
899 config_digital_init_by_mode(priv); in mt6359_accdet_init()
906 struct mt6359_accdet *priv = in mt6359_accdet_enable_jack_detect() local
914 priv->jack = jack; in mt6359_accdet_enable_jack_detect()
916 mt6359_accdet_jack_report(priv); in mt6359_accdet_enable_jack_detect()
924 struct mt6359_accdet *priv; in mt6359_accdet_probe() local
931 priv = devm_kzalloc(&pdev->dev, sizeof(struct mt6359_accdet), in mt6359_accdet_probe()
933 if (!priv) in mt6359_accdet_probe()
936 priv->data = devm_kzalloc(&pdev->dev, sizeof(struct dts_data), in mt6359_accdet_probe()
938 if (!priv->data) in mt6359_accdet_probe()
941 priv->data->pwm_deb = devm_kzalloc(&pdev->dev, in mt6359_accdet_probe()
944 if (!priv->data->pwm_deb) in mt6359_accdet_probe()
947 priv->regmap = mt6397->regmap; in mt6359_accdet_probe()
948 if (IS_ERR(priv->regmap)) { in mt6359_accdet_probe()
949 ret = PTR_ERR(priv->regmap); in mt6359_accdet_probe()
954 priv->dev = &pdev->dev; in mt6359_accdet_probe()
956 ret = mt6359_accdet_parse_dt(priv); in mt6359_accdet_probe()
961 mutex_init(&priv->res_lock); in mt6359_accdet_probe()
963 priv->accdet_irq = platform_get_irq(pdev, 0); in mt6359_accdet_probe()
964 if (priv->accdet_irq >= 0) { in mt6359_accdet_probe()
965 ret = devm_request_threaded_irq(&pdev->dev, priv->accdet_irq, in mt6359_accdet_probe()
968 "ACCDET_IRQ", priv); in mt6359_accdet_probe()
976 if (priv->caps & ACCDET_PMIC_EINT0) { in mt6359_accdet_probe()
977 priv->accdet_eint0 = platform_get_irq(pdev, 1); in mt6359_accdet_probe()
978 if (priv->accdet_eint0 >= 0) { in mt6359_accdet_probe()
980 priv->accdet_eint0, in mt6359_accdet_probe()
983 "ACCDET_EINT0", priv); in mt6359_accdet_probe()
991 } else if (priv->caps & ACCDET_PMIC_EINT1) { in mt6359_accdet_probe()
992 priv->accdet_eint1 = platform_get_irq(pdev, 2); in mt6359_accdet_probe()
993 if (priv->accdet_eint1 >= 0) { in mt6359_accdet_probe()
995 priv->accdet_eint1, in mt6359_accdet_probe()
998 "ACCDET_EINT1", priv); in mt6359_accdet_probe()
1008 priv->accdet_workqueue = create_singlethread_workqueue("accdet"); in mt6359_accdet_probe()
1009 INIT_WORK(&priv->accdet_work, mt6359_accdet_work); in mt6359_accdet_probe()
1010 if (!priv->accdet_workqueue) { in mt6359_accdet_probe()
1016 priv->jd_workqueue = create_singlethread_workqueue("mt6359_accdet_jd"); in mt6359_accdet_probe()
1017 INIT_WORK(&priv->jd_work, mt6359_accdet_jd_work); in mt6359_accdet_probe()
1018 if (!priv->jd_workqueue) { in mt6359_accdet_probe()
1024 platform_set_drvdata(pdev, priv); in mt6359_accdet_probe()
1033 priv->jd_sts = M_PLUG_OUT; in mt6359_accdet_probe()
1034 priv->jack_type = 0; in mt6359_accdet_probe()
1035 priv->btn_type = 0; in mt6359_accdet_probe()
1036 priv->accdet_status = 0x3; in mt6359_accdet_probe()
1037 mt6359_accdet_init(priv); in mt6359_accdet_probe()
1039 mt6359_accdet_jack_report(priv); in mt6359_accdet_probe()
1044 destroy_workqueue(priv->accdet_workqueue); in mt6359_accdet_probe()