Lines Matching +full:internal +full:- +full:bias +full:- +full:resistor

1 // SPDX-License-Identifier: GPL-2.0
3 // mt6359-accdet.c -- ALSA SoC mt6359 accdet driver
27 #include "mt6359-accdet.h"
31 #define REGISTER_VAL(x) ((x) - 1)
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()
95 /*select 500k, use internal resistor */ in adjust_eint_analog_setting()
96 regmap_update_bits(priv->regmap, in adjust_eint_analog_setting()
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()
137 if (priv->jd_sts == M_PLUG_IN) { in mt6359_accdet_jd_setting()
142 } else if (priv->jd_sts == M_PLUG_OUT) { 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()
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()
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()
225 if (priv->jd_sts == M_PLUG_OUT) { in recover_eint_setting()
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()
256 priv->data->pwm_deb->debounce0); in mt6359_accdet_recover_jd_setting()
258 priv->data->pwm_deb->debounce1); 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()
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()
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()
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()
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()
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()
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()
385 priv->jack_type = SND_JACK_HEADSET; in check_jack_btn_type()
391 priv->jack_type = 0; in check_jack_btn_type()
401 mutex_lock(&priv->res_lock); in mt6359_accdet_work()
402 priv->pre_accdet_status = priv->accdet_status; 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()
408 mutex_unlock(&priv->res_lock); in mt6359_accdet_work()
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()
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()
451 if (priv->caps & ACCDET_PMIC_EINT_IRQ) in mt6359_accdet_jd_work()
453 mutex_unlock(&priv->res_lock); in mt6359_accdet_jd_work()
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()
541 queue_work(priv->jd_workqueue, &priv->jd_work); in mt6359_accdet_irq()
543 mutex_unlock(&priv->res_lock); in mt6359_accdet_irq()
551 struct device *dev = priv->dev; in mt6359_accdet_parse_dt()
556 node = of_get_child_by_name(dev->parent->of_node, "accdet"); in mt6359_accdet_parse_dt()
558 return -EINVAL; in mt6359_accdet_parse_dt()
560 ret = of_property_read_u32(node, "mediatek,mic-vol", 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()
565 ret = of_property_read_u32(node, "mediatek,plugout-debounce", 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()
570 ret = of_property_read_u32(node, "mediatek,mic-mode", 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()
575 ret = of_property_read_u32_array(node, "mediatek,pwm-deb-setting", in mt6359_accdet_parse_dt()
579 memcpy(priv->data->pwm_deb, pwm_deb, sizeof(pwm_deb)); in mt6359_accdet_parse_dt()
581 ret = of_property_read_u32(node, "mediatek,eint-level-pol", 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()
586 ret = of_property_read_u32(node, "mediatek,eint-use-ap", &tmp); 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()
594 ret = of_property_read_u32(node, "mediatek,eint-detect-mode", 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()
601 ret = of_property_read_u32(node, "mediatek,eint-num", &tmp); 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()
611 ret = of_property_read_u32(node, "mediatek,eint-trig-mode", 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()
620 ret = of_property_read_u32(node, "mediatek,eint-use-ext-res", in mt6359_accdet_parse_dt()
621 &priv->data->eint_use_ext_res); in mt6359_accdet_parse_dt()
623 /* eint use internal resister */ in mt6359_accdet_parse_dt()
624 priv->data->eint_use_ext_res = 0x0; in mt6359_accdet_parse_dt()
627 ret = of_property_read_u32(node, "mediatek,eint-comp-vth", 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()
632 ret = of_property_read_u32(node, "mediatek,key-mode", &tmp); in mt6359_accdet_parse_dt()
638 priv->caps |= ACCDET_THREE_KEY; in mt6359_accdet_parse_dt()
640 "mediatek,three-key-thr", 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()
651 "mediatek,four-key-thr", 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()
659 "accdet no 4-key-thrsh dts, use efuse\n"); in mt6359_accdet_parse_dt()
664 priv->caps |= ACCDET_TRI_KEY_CDD; in mt6359_accdet_parse_dt()
666 "mediatek,tri-key-cdd-thr", 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()
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()
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()
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()
808 priv->data->pwm_deb->debounce0); in mt6359_accdet_init()
810 priv->data->pwm_deb->debounce1); in mt6359_accdet_init()
812 priv->data->pwm_deb->debounce3); in mt6359_accdet_init()
814 priv->data->pwm_deb->debounce4); in mt6359_accdet_init()
817 priv->data->pwm_deb->eint_debounce0); in mt6359_accdet_init()
819 priv->data->pwm_deb->eint_debounce1); in mt6359_accdet_init()
821 priv->data->pwm_deb->eint_debounce3); 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()
875 /* DCC mode Low cost mode without internal bias */ 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()
883 /* DCC mode Low cost mode with internal bias, in mt6359_accdet_init()
884 * bit8 = 1 to use internal bias 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()
909 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); in mt6359_accdet_enable_jack_detect()
910 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEDOWN); in mt6359_accdet_enable_jack_detect()
911 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); in mt6359_accdet_enable_jack_detect()
912 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); in mt6359_accdet_enable_jack_detect()
914 priv->jack = jack; in mt6359_accdet_enable_jack_detect()
925 struct mt6397_chip *mt6397 = dev_get_drvdata(pdev->dev.parent); in mt6359_accdet_probe()
928 dev_dbg(&pdev->dev, "%s(), dev name %s\n", in mt6359_accdet_probe()
929 __func__, dev_name(&pdev->dev)); in mt6359_accdet_probe()
931 priv = devm_kzalloc(&pdev->dev, sizeof(struct mt6359_accdet), in mt6359_accdet_probe()
934 return -ENOMEM; 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()
939 return -ENOMEM; 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()
945 return -ENOMEM; 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()
950 dev_err(&pdev->dev, "Failed to allocate register map: %d\n", in mt6359_accdet_probe()
954 priv->dev = &pdev->dev; in mt6359_accdet_probe()
958 dev_err(&pdev->dev, "Failed to parse dts\n"); 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()
970 dev_err(&pdev->dev, 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()
979 ret = devm_request_threaded_irq(&pdev->dev, in mt6359_accdet_probe()
980 priv->accdet_eint0, in mt6359_accdet_probe()
985 dev_err(&pdev->dev, 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()
994 ret = devm_request_threaded_irq(&pdev->dev, in mt6359_accdet_probe()
995 priv->accdet_eint1, in mt6359_accdet_probe()
1000 dev_err(&pdev->dev, 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()
1011 dev_err(&pdev->dev, "Failed to create accdet workqueue\n"); in mt6359_accdet_probe()
1012 ret = -1; 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()
1019 dev_err(&pdev->dev, "Failed to create jack detect workqueue\n"); in mt6359_accdet_probe()
1020 ret = -1; in mt6359_accdet_probe()
1025 ret = devm_snd_soc_register_component(&pdev->dev, in mt6359_accdet_probe()
1029 dev_err(&pdev->dev, "Failed to register component\n"); 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()
1044 destroy_workqueue(priv->accdet_workqueue); in mt6359_accdet_probe()
1046 dev_err(&pdev->dev, "%s error. now exit.!\n", __func__); in mt6359_accdet_probe()
1052 .name = "pmic-codec-accdet",