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
31 #include "mt6359-accdet.h"
35 #define REGISTER_VAL(x) ((x) - 1)
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()
99 /*select 500k, use internal resistor */ in adjust_eint_analog_setting()
100 regmap_update_bits(priv->regmap, in adjust_eint_analog_setting()
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()
141 if (priv->jd_sts == M_PLUG_IN) { in mt6359_accdet_jd_setting()
146 } else if (priv->jd_sts == M_PLUG_OUT) { 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()
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()
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()
229 if (priv->jd_sts == M_PLUG_OUT) { in recover_eint_setting()
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()
260 priv->data->pwm_deb->debounce0); in mt6359_accdet_recover_jd_setting()
262 priv->data->pwm_deb->debounce1); 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()
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()
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()
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()
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()
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()
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()
389 priv->jack_type = SND_JACK_HEADSET; in check_jack_btn_type()
395 priv->jack_type = 0; in check_jack_btn_type()
405 mutex_lock(&priv->res_lock); in mt6359_accdet_work()
406 priv->pre_accdet_status = priv->accdet_status; 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()
412 mutex_unlock(&priv->res_lock); in mt6359_accdet_work()
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()
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()
455 if (priv->caps & ACCDET_PMIC_EINT_IRQ) in mt6359_accdet_jd_work()
457 mutex_unlock(&priv->res_lock); in mt6359_accdet_jd_work()
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()
545 queue_work(priv->jd_workqueue, &priv->jd_work); in mt6359_accdet_irq()
547 mutex_unlock(&priv->res_lock); in mt6359_accdet_irq()
555 struct device *dev = priv->dev; in mt6359_accdet_parse_dt()
560 node = of_get_child_by_name(dev->parent->of_node, "accdet"); in mt6359_accdet_parse_dt()
562 return -EINVAL; in mt6359_accdet_parse_dt()
564 ret = of_property_read_u32(node, "mediatek,mic-vol", 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()
569 ret = of_property_read_u32(node, "mediatek,plugout-debounce", 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()
574 ret = of_property_read_u32(node, "mediatek,mic-mode", 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()
579 ret = of_property_read_u32_array(node, "mediatek,pwm-deb-setting", in mt6359_accdet_parse_dt()
583 memcpy(priv->data->pwm_deb, pwm_deb, sizeof(pwm_deb)); in mt6359_accdet_parse_dt()
585 ret = of_property_read_u32(node, "mediatek,eint-level-pol", 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()
590 ret = of_property_read_u32(node, "mediatek,eint-use-ap", &tmp); 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()
598 ret = of_property_read_u32(node, "mediatek,eint-detect-mode", 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()
605 ret = of_property_read_u32(node, "mediatek,eint-num", &tmp); 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()
615 ret = of_property_read_u32(node, "mediatek,eint-trig-mode", 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()
624 ret = of_property_read_u32(node, "mediatek,eint-use-ext-res", in mt6359_accdet_parse_dt()
625 &priv->data->eint_use_ext_res); in mt6359_accdet_parse_dt()
627 /* eint use internal resister */ in mt6359_accdet_parse_dt()
628 priv->data->eint_use_ext_res = 0x0; in mt6359_accdet_parse_dt()
631 ret = of_property_read_u32(node, "mediatek,eint-comp-vth", 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()
636 ret = of_property_read_u32(node, "mediatek,key-mode", &tmp); in mt6359_accdet_parse_dt()
642 priv->caps |= ACCDET_THREE_KEY; in mt6359_accdet_parse_dt()
644 "mediatek,three-key-thr", 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()
655 "mediatek,four-key-thr", 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()
663 "accdet no 4-key-thrsh dts, use efuse\n"); in mt6359_accdet_parse_dt()
668 priv->caps |= ACCDET_TRI_KEY_CDD; in mt6359_accdet_parse_dt()
670 "mediatek,tri-key-cdd-thr", in mt6359_accdet_parse_dt()
674 memcpy(&priv->data->three_key, three_key + 1, in mt6359_accdet_parse_dt()
679 dev_warn(priv->dev, "accdet caps=%x\n", priv->caps); in mt6359_accdet_parse_dt()
687 regmap_write(priv->regmap, ACCDET_EINT_CMPMEN_PWM_THRESH_ADDR, in config_digital_init_by_mode()
688 (priv->data->pwm_deb->eint_pwm_width << 4 | in config_digital_init_by_mode()
689 priv->data->pwm_deb->eint_pwm_thresh)); in config_digital_init_by_mode()
691 if (priv->caps & ACCDET_PMIC_EINT0) { in config_digital_init_by_mode()
692 regmap_write(priv->regmap, ACCDET_DA_STABLE_ADDR, in config_digital_init_by_mode()
694 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_digital_init_by_mode()
695 regmap_write(priv->regmap, ACCDET_DA_STABLE_ADDR, in config_digital_init_by_mode()
699 regmap_update_bits(priv->regmap, ACCDET_EINT_M_PLUG_IN_NUM_ADDR, in config_digital_init_by_mode()
706 regmap_write(priv->regmap, ACCDET_HWMODE_EN_ADDR, 0x100); in config_digital_init_by_mode()
708 regmap_update_bits(priv->regmap, ACCDET_EINT_M_DETECT_EN_ADDR, in config_digital_init_by_mode()
712 regmap_write(priv->regmap, ACCDET_CMP_PWM_EN_ADDR, 0x67); in config_digital_init_by_mode()
714 if (priv->data->eint_detect_mode == 0x1) { in config_digital_init_by_mode()
716 if (priv->caps & ACCDET_PMIC_EINT0) { in config_digital_init_by_mode()
717 regmap_update_bits(priv->regmap, in config_digital_init_by_mode()
721 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_digital_init_by_mode()
722 regmap_update_bits(priv->regmap, in config_digital_init_by_mode()
728 if (priv->caps & ACCDET_PMIC_EINT0) { in config_digital_init_by_mode()
729 regmap_update_bits(priv->regmap, in config_digital_init_by_mode()
733 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_digital_init_by_mode()
734 regmap_update_bits(priv->regmap, in config_digital_init_by_mode()
746 if (priv->caps & ACCDET_PMIC_EINT0) { in config_eint_init_by_mode()
747 regmap_update_bits(priv->regmap, RG_EINT0EN_ADDR, in config_eint_init_by_mode()
749 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_eint_init_by_mode()
750 regmap_update_bits(priv->regmap, RG_EINT1EN_ADDR, in config_eint_init_by_mode()
754 regmap_update_bits(priv->regmap, RG_ACCDETSPARE_ADDR, in config_eint_init_by_mode()
757 regmap_update_bits(priv->regmap, RG_NCP_PDDIS_EN_ADDR, in config_eint_init_by_mode()
760 if (priv->data->eint_detect_mode == 0x1 || in config_eint_init_by_mode()
761 priv->data->eint_detect_mode == 0x2 || in config_eint_init_by_mode()
762 priv->data->eint_detect_mode == 0x3) { in config_eint_init_by_mode()
763 if (priv->data->eint_use_ext_res == 0x1) { in config_eint_init_by_mode()
764 if (priv->caps & ACCDET_PMIC_EINT0) { in config_eint_init_by_mode()
765 regmap_update_bits(priv->regmap, in config_eint_init_by_mode()
769 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_eint_init_by_mode()
770 regmap_update_bits(priv->regmap, in config_eint_init_by_mode()
776 if (priv->caps & ACCDET_PMIC_EINT0) { in config_eint_init_by_mode()
777 regmap_update_bits(priv->regmap, in config_eint_init_by_mode()
781 } else if (priv->caps & ACCDET_PMIC_EINT1) { in config_eint_init_by_mode()
782 regmap_update_bits(priv->regmap, in config_eint_init_by_mode()
790 if (priv->data->eint_detect_mode != 0x1) { in config_eint_init_by_mode()
792 regmap_update_bits(priv->regmap, RG_ACCDETSPARE_ADDR, in config_eint_init_by_mode()
796 regmap_write(priv->regmap, RG_EINTCOMPVTH_ADDR, in config_eint_init_by_mode()
797 val | priv->data->eint_comp_vth << RG_EINTCOMPVTH_SFT); in config_eint_init_by_mode()
804 regmap_update_bits(priv->regmap, ACCDET_SEQ_INIT_ADDR, in mt6359_accdet_init()
807 regmap_update_bits(priv->regmap, ACCDET_SEQ_INIT_ADDR, in mt6359_accdet_init()
812 priv->data->pwm_deb->debounce0); in mt6359_accdet_init()
814 priv->data->pwm_deb->debounce1); in mt6359_accdet_init()
816 priv->data->pwm_deb->debounce3); in mt6359_accdet_init()
818 priv->data->pwm_deb->debounce4); in mt6359_accdet_init()
821 priv->data->pwm_deb->eint_debounce0); in mt6359_accdet_init()
823 priv->data->pwm_deb->eint_debounce1); in mt6359_accdet_init()
825 priv->data->pwm_deb->eint_debounce3); in mt6359_accdet_init()
827 priv->data->pwm_deb->eint_inverter_debounce); in mt6359_accdet_init()
829 regmap_update_bits(priv->regmap, RG_ACCDET_RST_ADDR, in mt6359_accdet_init()
831 regmap_update_bits(priv->regmap, RG_ACCDET_RST_ADDR, in mt6359_accdet_init()
835 regmap_update_bits(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
837 regmap_update_bits(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
841 regmap_write(priv->regmap, ACCDET_PWM_WIDTH_ADDR, in mt6359_accdet_init()
842 REGISTER_VAL(priv->data->pwm_deb->pwm_width)); in mt6359_accdet_init()
843 regmap_write(priv->regmap, ACCDET_PWM_THRESH_ADDR, in mt6359_accdet_init()
844 REGISTER_VAL(priv->data->pwm_deb->pwm_thresh)); in mt6359_accdet_init()
845 regmap_write(priv->regmap, ACCDET_RISE_DELAY_ADDR, in mt6359_accdet_init()
846 (priv->data->pwm_deb->fall_delay << 15 | in mt6359_accdet_init()
847 priv->data->pwm_deb->rise_delay)); in mt6359_accdet_init()
849 regmap_read(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, ®); in mt6359_accdet_init()
850 if (priv->data->mic_vol <= 7) { in mt6359_accdet_init()
852 regmap_write(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
853 reg | (priv->data->mic_vol << RG_AUDMICBIAS1VREF_SFT) | in mt6359_accdet_init()
855 } else if (priv->data->mic_vol == 8) { in mt6359_accdet_init()
857 regmap_write(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
860 } else if (priv->data->mic_vol == 9) { in mt6359_accdet_init()
862 regmap_write(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
867 regmap_read(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR, ®); in mt6359_accdet_init()
868 if (priv->data->mic_mode == HEADSET_MODE_1) { in mt6359_accdet_init()
870 regmap_write(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR, in mt6359_accdet_init()
873 regmap_update_bits(priv->regmap, RG_ANALOGFDEN_ADDR, in mt6359_accdet_init()
876 regmap_update_bits(priv->regmap, RG_ACCDETSPARE_ADDR, in mt6359_accdet_init()
878 } else if (priv->data->mic_mode == HEADSET_MODE_2) { in mt6359_accdet_init()
879 /* DCC mode Low cost mode without internal bias */ in mt6359_accdet_init()
880 regmap_write(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR, in mt6359_accdet_init()
883 regmap_update_bits(priv->regmap, RG_ANALOGFDEN_ADDR, in mt6359_accdet_init()
886 } else if (priv->data->mic_mode == HEADSET_MODE_6) { in mt6359_accdet_init()
887 /* DCC mode Low cost mode with internal bias, in mt6359_accdet_init()
888 * bit8 = 1 to use internal bias in mt6359_accdet_init()
890 regmap_write(priv->regmap, RG_AUDACCDETMICBIAS0PULLLOW_ADDR, in mt6359_accdet_init()
892 regmap_update_bits(priv->regmap, RG_AUDPWDBMICBIAS1_ADDR, in mt6359_accdet_init()
896 regmap_update_bits(priv->regmap, RG_ANALOGFDEN_ADDR, in mt6359_accdet_init()
901 if (priv->caps & ACCDET_PMIC_EINT_IRQ) { in mt6359_accdet_init()
913 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); in mt6359_accdet_enable_jack_detect()
914 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEDOWN); in mt6359_accdet_enable_jack_detect()
915 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); in mt6359_accdet_enable_jack_detect()
916 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); in mt6359_accdet_enable_jack_detect()
918 priv->jack = jack; in mt6359_accdet_enable_jack_detect()
929 struct mt6397_chip *mt6397 = dev_get_drvdata(pdev->dev.parent); in mt6359_accdet_probe()
932 dev_dbg(&pdev->dev, "%s(), dev name %s\n", in mt6359_accdet_probe()
933 __func__, dev_name(&pdev->dev)); in mt6359_accdet_probe()
935 priv = devm_kzalloc(&pdev->dev, sizeof(struct mt6359_accdet), in mt6359_accdet_probe()
938 return -ENOMEM; in mt6359_accdet_probe()
940 priv->data = devm_kzalloc(&pdev->dev, sizeof(struct dts_data), in mt6359_accdet_probe()
942 if (!priv->data) in mt6359_accdet_probe()
943 return -ENOMEM; in mt6359_accdet_probe()
945 priv->data->pwm_deb = devm_kzalloc(&pdev->dev, in mt6359_accdet_probe()
948 if (!priv->data->pwm_deb) in mt6359_accdet_probe()
949 return -ENOMEM; in mt6359_accdet_probe()
951 priv->regmap = mt6397->regmap; in mt6359_accdet_probe()
952 if (IS_ERR(priv->regmap)) { in mt6359_accdet_probe()
953 ret = PTR_ERR(priv->regmap); in mt6359_accdet_probe()
954 dev_err(&pdev->dev, "Failed to allocate register map: %d\n", in mt6359_accdet_probe()
958 priv->dev = &pdev->dev; in mt6359_accdet_probe()
962 dev_err(&pdev->dev, "Failed to parse dts\n"); in mt6359_accdet_probe()
965 mutex_init(&priv->res_lock); in mt6359_accdet_probe()
967 priv->accdet_irq = platform_get_irq(pdev, 0); in mt6359_accdet_probe()
968 if (priv->accdet_irq >= 0) { in mt6359_accdet_probe()
969 ret = devm_request_threaded_irq(&pdev->dev, priv->accdet_irq, in mt6359_accdet_probe()
974 dev_err(&pdev->dev, in mt6359_accdet_probe()
980 if (priv->caps & ACCDET_PMIC_EINT0) { in mt6359_accdet_probe()
981 priv->accdet_eint0 = platform_get_irq(pdev, 1); in mt6359_accdet_probe()
982 if (priv->accdet_eint0 >= 0) { in mt6359_accdet_probe()
983 ret = devm_request_threaded_irq(&pdev->dev, in mt6359_accdet_probe()
984 priv->accdet_eint0, in mt6359_accdet_probe()
989 dev_err(&pdev->dev, in mt6359_accdet_probe()
995 } else if (priv->caps & ACCDET_PMIC_EINT1) { in mt6359_accdet_probe()
996 priv->accdet_eint1 = platform_get_irq(pdev, 2); in mt6359_accdet_probe()
997 if (priv->accdet_eint1 >= 0) { in mt6359_accdet_probe()
998 ret = devm_request_threaded_irq(&pdev->dev, in mt6359_accdet_probe()
999 priv->accdet_eint1, in mt6359_accdet_probe()
1004 dev_err(&pdev->dev, in mt6359_accdet_probe()
1012 priv->accdet_workqueue = create_singlethread_workqueue("accdet"); in mt6359_accdet_probe()
1013 INIT_WORK(&priv->accdet_work, mt6359_accdet_work); in mt6359_accdet_probe()
1014 if (!priv->accdet_workqueue) { in mt6359_accdet_probe()
1015 dev_err(&pdev->dev, "Failed to create accdet workqueue\n"); in mt6359_accdet_probe()
1016 ret = -1; in mt6359_accdet_probe()
1020 priv->jd_workqueue = create_singlethread_workqueue("mt6359_accdet_jd"); in mt6359_accdet_probe()
1021 INIT_WORK(&priv->jd_work, mt6359_accdet_jd_work); in mt6359_accdet_probe()
1022 if (!priv->jd_workqueue) { in mt6359_accdet_probe()
1023 dev_err(&pdev->dev, "Failed to create jack detect workqueue\n"); in mt6359_accdet_probe()
1024 ret = -1; in mt6359_accdet_probe()
1029 ret = devm_snd_soc_register_component(&pdev->dev, in mt6359_accdet_probe()
1033 dev_err(&pdev->dev, "Failed to register component\n"); in mt6359_accdet_probe()
1037 priv->jd_sts = M_PLUG_OUT; in mt6359_accdet_probe()
1038 priv->jack_type = 0; in mt6359_accdet_probe()
1039 priv->btn_type = 0; in mt6359_accdet_probe()
1040 priv->accdet_status = 0x3; in mt6359_accdet_probe()
1048 destroy_workqueue(priv->accdet_workqueue); in mt6359_accdet_probe()
1050 dev_err(&pdev->dev, "%s error. now exit.!\n", __func__); in mt6359_accdet_probe()
1056 .name = "pmic-codec-accdet",