static int hi6402_read_saradc_value_detect(struct hi6402_mbhc_platform_data *pdata) { int retry = 3; int reg_value = 0; BUG_ON(NULL == pdata->p_irq); mutex_lock(&pdata->saradc_mutex); /* saradc on */ hi6402_reg_clr_bit(pdata->p_irq, HI6402_ANA_REG60, HI6402_SARADC_PD_BIT); /* start saradc */ hi6402_reg_set_bit(pdata->p_irq, HI6402_ANA_REG60, HI6402_SAR_START_BIT); while(retry--) { usleep_range(1000, 1100); if (check_saradc_value_ready_detect(pdata)) { reg_value = hi6402_irq_read(pdata->p_irq, HI6402_SARADC_VALUE_REG); pr_info("%s : saradc value is %#x\n", __FUNCTION__, reg_value); break; } } if (0 > retry) pr_err("%s : get saradc value err, set as 0\n", __FUNCTION__); /* end saradc */ hi6402_reg_clr_bit(pdata->p_irq, HI6402_ANA_REG60, HI6402_SAR_START_BIT); /* saradc pd */ hi6402_reg_set_bit(pdata->p_irq, HI6402_ANA_REG60, HI6402_SARADC_PD_BIT); mutex_unlock(&pdata->saradc_mutex); return GET_VOLTAGE(reg_value); }
static irqreturn_t hi6402_plugout_handler(int irq, void *data) { struct hi6402_mbhc_platform_data *pdata = (struct hi6402_mbhc_platform_data *)data; BUG_ON(NULL == pdata); if (check_headset_pluged_in(pdata)) { pr_info("%s : hs still plugin \n", __FUNCTION__); return IRQ_HANDLED; } mutex_lock(&pdata->plug_mutex); hi6402_irq_cancel_delay_work(pdata->p_irq); hi6402_irq_mask_btn_irqs(pdata->p_irq); //stop charge first anc_hs_stop_charge(); /* eco off */ hi6402_reg_clr_bit(pdata->p_irq, HI6402_MICBIAS_ECO_REG, HI6402_MICBIAS_ECO_ON_BIT); mutex_lock(&pdata->p_irq->hs_micbias_mutex); /* hs micbias off */ pdata->p_irq->mbhc_micbias_work = false; pdata->p_irq->dapm_micbias_work = false; mutex_unlock(&pdata->p_irq->hs_micbias_mutex); hi6402_irq_hs_micbias_enable(pdata->p_irq, false); hi6402_irq_clr_btn_irqs(pdata->p_irq); hi6402_irq_mask_btn_irqs(pdata->p_irq); /* eco off */ hi6402_reg_clr_bit(pdata->p_irq, HI6402_MICBIAS_ECO_REG, HI6402_MICBIAS_ECO_ON_BIT); pr_info("%s : eco disable \n", __FUNCTION__); /* vref off */ hi6402_reg_set_bit(pdata->p_irq, HI6402_MBHC_VREF_REG, HI6402_MBHC_VREF_BIT); /* mbhc cmp off */ hi6402_reg_set_bit(pdata->p_irq, HI6402_ANA_REG60, HI6402_MBHC_ON_BIT); mutex_lock(&pdata->status_mutex); pdata->hs_status = HISI_JACK_NONE; pdata->btn_report = 0; mutex_unlock(&pdata->status_mutex); hi6402_jack_report(pdata); hi6402_mbhc_enable_ldo8(pdata, false); mutex_unlock(&pdata->plug_mutex); return IRQ_HANDLED; }
void hi6402_plug_out_workfunc(struct work_struct *work) { struct hi6402_mbhc_platform_data *pdata = container_of(work, struct hi6402_mbhc_platform_data, headset_plug_out_delay_work.work); pr_info("%s : hs pluged out\n", __FUNCTION__); BUG_ON(NULL == pdata); wake_lock(&pdata->wake_lock); mutex_lock(&pdata->plug_mutex); mask_irq(pdata->irq[HI6402_IRQ_BTNDOWN_COMP1], true); mask_irq(pdata->irq[HI6402_IRQ_BTNUP_COMP1], true); mask_irq(pdata->irq[HI6402_IRQ_BTNDOWN_ECO], true); /* todo */ hi6402_reg_clr_bit(pdata->p_irq, HI6402_MICBIAS_ECO_REG, 0); hi6402_reg_set_bit(pdata->p_irq, HI6402_MBHC_VREF_REG, 7); mutex_lock(&pdata->status_mutex); pdata->hs_status = HISI_JACK_NONE; pdata->btn_report = 0; mutex_unlock(&pdata->status_mutex); hi6402_jack_report(pdata); mutex_unlock(&pdata->plug_mutex); wake_unlock(&pdata->wake_lock); /* unmask plugin interrupt */ mask_irq(pdata->irq[HI6402_IRQ_PLUGIN], false); }
void hi6402_plug_in_detect(struct hi6402_mbhc_platform_data *pdata) { if (!check_headset_pluged_in(pdata)) return; wake_lock(&pdata->wake_lock); mutex_lock(&pdata->plug_mutex); mutex_lock(&pdata->status_mutex); /* todo : btn_report 4-pole headset only now */ pdata->hs_status = HISI_JACK_HEADSET; pdata->btn_report = SND_JACK_HEADSET; mutex_unlock(&pdata->status_mutex); hi6402_jack_report(pdata); /* todo */ hi6402_reg_clr_bit(pdata->p_irq, HI6402_MBHC_VREF_REG, 7); hi6402_reg_set_bit(pdata->p_irq, HI6402_MICBIAS_ECO_REG, 0); /* unmask btn down irq */ mask_irq(pdata->irq[HI6402_IRQ_BTNDOWN_COMP1], false); mask_irq(pdata->irq[HI6402_IRQ_BTNDOWN_ECO], false); mutex_unlock(&pdata->plug_mutex); wake_unlock(&pdata->wake_lock); }
static irqreturn_t hi6402_pll_unlock_handler(int irq, void *data) { struct hi6402_mbhc_platform_data *pdata = (struct hi6402_mbhc_platform_data *)data; BUG_ON(NULL == pdata); unsigned int i = 0; mutex_lock(&pdata->p_irq->pll_mutex); if (0 != (hi6402_irq_read(pdata->p_irq, HI6402_PLL_PD_FLAG_REG) & PLL_PD_VALUE) || 0 != (hi6402_irq_read(pdata->p_irq, HI6402_PLL_LOCK_FLAG_REG) & PLL_LOCK_VALUE)){ pr_info("%s(%u): pll pd, ignore pll unlock irq! \n", __FUNCTION__, __LINE__); /* mask pll unlock irq */ mutex_lock(&pdata->p_irq->irq_lock); hi6402_reg_set_bit(pdata->p_irq, HI6402_MASK_IRQ_REG_2, HI6402_MASK_PLL_UNLOCK_BIT); pdata->p_irq->mask2 |= 0x10; mutex_unlock(&pdata->p_irq->irq_lock); } else { pr_info("%s(%u): pll unlock irq! \n", __FUNCTION__, __LINE__); if (!dsm_client_ocuppy(dsm_audio_client)) { dsm_client_record(dsm_audio_client, "DSM_HI6402_PLL_UNLOCK\n"); dsm_client_notify(dsm_audio_client, DSM_HI6402_PLL_UNLOCK); } for (i = PLL_UNLOCK_REG_START; i<= PLL_UNLOCK_REG_END; i++) { pr_err("%s(%u): %x is %x \n", __FUNCTION__, __LINE__, i, hi6402_irq_read(pdata->p_irq, i)); } pdata->p_irq->pll_status = HI6402_PLL_RST; hi6402_irq_set_pll_mode(pdata->p_irq); } mutex_unlock(&pdata->p_irq->pll_mutex); return IRQ_HANDLED; }
static int hi6402_mbhc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct hi6402_mbhc_platform_data *pdata = NULL; const struct of_device_id *match = NULL; int ret = 0; pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); if (NULL == pdata) { dev_err(dev, "cannot allocate hisi 6421 spk platform data\n"); return -ENOMEM; } match = of_match_device(hi6402_mbhc_of_match, dev); if (!match) { pr_err("get device info err\n"); return -ENOENT; } else { struct device_node *node = dev->of_node; int temp; /* get board defination */ if (!of_property_read_u32(node, "hisilicon,hi6402_hs_det_inv", &temp)) pdata->hs_det_inv = temp; else pdata->hs_det_inv = 0; if (!of_property_read_u32(node, "hisilicon,hs_3_pole_min_voltage", &temp)) pdata->hs_3_pole_min_voltage = temp; else pdata->hs_3_pole_min_voltage = 0; if (!of_property_read_u32(node, "hisilicon,hs_3_pole_max_voltage", &temp)) pdata->hs_3_pole_max_voltage = temp; else pdata->hs_3_pole_max_voltage = 0; if (!of_property_read_u32(node, "hisilicon,hs_4_pole_min_voltage", &temp)) pdata->hs_4_pole_min_voltage = temp; else pdata->hs_4_pole_min_voltage = 0; if (!of_property_read_u32(node, "hisilicon,hs_4_pole_max_voltage", &temp)) pdata->hs_4_pole_max_voltage = temp; else pdata->hs_4_pole_max_voltage = 0; if (!of_property_read_u32(node, "hisilicon,btn_play_min_voltage", &temp)) pdata->btn_play_min_voltage = temp; else pdata->btn_play_min_voltage = 0; if (!of_property_read_u32(node, "hisilicon,btn_play_max_voltage", &temp)) pdata->btn_play_max_voltage = temp; else pdata->btn_play_max_voltage = 0; if (!of_property_read_u32(node, "hisilicon,btn_volume_up_min_voltage", &temp)) pdata->btn_volume_up_min_voltage = temp; else pdata->btn_volume_up_min_voltage = 0; if (!of_property_read_u32(node, "hisilicon,btn_volume_up_max_voltage", &temp)) pdata->btn_volume_up_max_voltage = temp; else pdata->btn_volume_up_max_voltage = 0; if (!of_property_read_u32(node, "hisilicon,btn_volume_down_min_voltage", &temp)) pdata->btn_volume_down_min_voltage = temp; else pdata->btn_volume_down_min_voltage = 0; if (!of_property_read_u32(node, "hisilicon,btn_volume_down_max_voltage", &temp)) pdata->btn_volume_down_max_voltage = temp; else pdata->btn_volume_down_max_voltage = 0; } pdata->p_irq = dev_get_drvdata(pdev->dev.parent); if (!pdata->p_irq) { dev_err(dev, "get parend device error\n"); return -ENOENT; } #ifdef CONFIG_SWITCH pdata->sdev.name = "h2w"; ret = switch_dev_register(&pdata->sdev); if (ret) { pr_err("%s : error registering switch device %d\n", __FUNCTION__, ret); return ret; } #endif /* get irqs */ pdata->irq[HI6402_IRQ_PLL_UNLOCK] = platform_get_irq_byname(pdev, "pll_unlock"); if (0 > pdata->irq[HI6402_IRQ_PLL_UNLOCK]) { pr_err("get pll unlock error"); return -ENOENT; } pdata->irq[HI6402_IRQ_SOUND_TRIGER] = platform_get_irq_byname(pdev, "sound_triger"); if (0 > pdata->irq[HI6402_IRQ_SOUND_TRIGER]) { pr_err("get sound triger error"); return -ENOENT; } pdata->irq[HI6402_IRQ_PLUGOUT] = platform_get_irq_byname(pdev, "plugout"); if (0 > pdata->irq[HI6402_IRQ_PLUGOUT]) { pr_err("get plug out irq num error"); return -ENOENT; } pdata->irq[HI6402_IRQ_PLUGIN] = platform_get_irq_byname(pdev, "plugin"); if (0 > pdata->irq[HI6402_IRQ_PLUGIN]) { pr_err("get plug in irq num error"); return -ENOENT; } pdata->irq[HI6402_IRQ_BTNDOWN_ECO] = platform_get_irq_byname(pdev, "btndown_eco"); if (0 > pdata->irq[HI6402_IRQ_BTNDOWN_ECO]) { pr_err("get btn down eco irq num error"); return -ENOENT; } pdata->irq[HI6402_IRQ_BTNUP_ECO] = platform_get_irq_byname(pdev, "btnup_eco"); if (0 > pdata->irq[HI6402_IRQ_BTNUP_ECO]) { pr_err("get btn up eco irq num error"); return -ENOENT; } pdata->irq[HI6402_IRQ_BTNDOWN_COMP1] = platform_get_irq_byname(pdev, "btndown"); if (0 > pdata->irq[HI6402_IRQ_BTNDOWN_COMP1]) { pr_err("get btn down irq num error"); return -ENOENT; } pdata->irq[HI6402_IRQ_BTNUP_COMP1] = platform_get_irq_byname(pdev, "btnup"); if (0 > pdata->irq[HI6402_IRQ_BTNUP_COMP1]) { pr_err("get btn up irq num error"); return -ENOENT; } wake_lock_init(&pdata->wake_lock, WAKE_LOCK_SUSPEND, "hisi-6402-mbhc"); wake_lock_init(&pdata->soundtrigger_wake_lock, WAKE_LOCK_SUSPEND, "hisi-6402-soundtrigger"); mutex_init(&pdata->plug_mutex); mutex_init(&pdata->status_mutex); mutex_init(&pdata->saradc_mutex); /* irq request : pll unlock */ ret = devm_request_threaded_irq(dev, pdata->irq[HI6402_IRQ_PLL_UNLOCK], NULL, hi6402_pll_unlock_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT, "pll_unlock", pdata); if (0 > ret) { pr_err("request irq for pll unlock err\n"); goto pll_unlock_err; } mutex_lock(&pdata->p_irq->irq_lock); hi6402_reg_set_bit(pdata->p_irq, HI6402_MASK_IRQ_REG_2, HI6402_MASK_PLL_UNLOCK_BIT); pdata->p_irq->mask2 |= 0x10; mutex_unlock(&pdata->p_irq->irq_lock); /* irq request : sound triger */ ret = devm_request_threaded_irq(dev, pdata->irq[HI6402_IRQ_SOUND_TRIGER], NULL, hi6402_sound_triger_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT, "sound_triger", pdata); if (0 > ret) { pr_err("request irq for sound triger err\n"); goto sound_triger_err; } /* irq request : plugout */ ret = devm_request_threaded_irq(dev, pdata->irq[HI6402_IRQ_PLUGOUT], NULL, hi6402_plugout_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT, "plugout", pdata); if (0 > ret) { pr_err("request irq for plugout err\n"); goto plugout_err; } /* irq request : plugin */ ret = devm_request_threaded_irq(dev, pdata->irq[HI6402_IRQ_PLUGIN], NULL, hi6402_plugin_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT, "plugin", pdata); if (0 > ret) { pr_err("request irq for plugin err\n"); goto plugin_err; } /* irq request : button up(eco mode) */ ret = devm_request_threaded_irq(dev, pdata->irq[HI6402_IRQ_BTNUP_ECO], NULL, hi6402_btnup_eco_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT, "btnup_eco", pdata); if (0 > ret) { pr_err("request irq for btnup eco err\n"); goto btnup_eco_err; } /* irq request : button down(eco mode) */ ret = devm_request_threaded_irq(dev, pdata->irq[HI6402_IRQ_BTNDOWN_ECO], NULL, hi6402_btndown_eco_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT, "btndown_eco", pdata); if (0 > ret) { pr_err("request irq for btndown eco err\n"); goto btndown_eco_err; } /* irq request : button down */ ret = devm_request_threaded_irq(dev, pdata->irq[HI6402_IRQ_BTNDOWN_COMP1], NULL, hi6402_btndown_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT, "btndown_comp1", pdata); if (0 > ret) { pr_err("request irq for btndown comp1 err\n"); goto btndown_comp1_err; } /* irq request : button up */ ret = devm_request_threaded_irq(dev, pdata->irq[HI6402_IRQ_BTNUP_COMP1], NULL, hi6402_btnup_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT, "btnup_comp1", pdata); if (0 > ret) { pr_err("request irq for btnup comp1 err\n"); goto btnup_comp1_err; } hi6402_irq_mask_btn_irqs(pdata->p_irq); hi6402_irq_clr_btn_irqs(pdata->p_irq); /* enable hsdet */ hi6402_irq_write(pdata->p_irq, HI6402_REG_HSDET_CTRL, 0x19); hi6402_irq_write(pdata->p_irq, HI6402_MBHC_VREF_REG, 0x8E); //register anc hs first anc_hs_dev_register(&anc_dev, pdata); //register soundtrigger input device. ret = soundtrigger_input_init(dev); if(ret) pr_err("input registor failed: %d\n", ret); #if 0 /* check jack at first time */ if (check_headset_pluged_in(pdata)) hi6402_plug_in_detect(pdata); #endif pdata->miscdev.minor = MISC_DYNAMIC_MINOR; pdata->miscdev.name = "hi6402_mbhc"; ret = misc_register(&pdata->miscdev); if (ret) { loge("%s : hisi 6421 spk_device register failed", __FUNCTION__); goto btnup_comp1_err; } if (!dsm_audio_client) { dsm_audio_client = dsm_register_client(&dsm_audio); } pr_info("%s : hi6402 mbhc probe ok \n", __FUNCTION__); return ret; btnup_comp1_err: free_irq(pdata->irq[HI6402_IRQ_BTNDOWN_COMP1], pdata); btndown_comp1_err: free_irq(pdata->irq[HI6402_IRQ_BTNDOWN_ECO], pdata); btndown_eco_err: free_irq(pdata->irq[HI6402_IRQ_BTNUP_ECO], pdata); btnup_eco_err: free_irq(pdata->irq[HI6402_IRQ_PLUGIN], pdata); plugin_err: free_irq(pdata->irq[HI6402_IRQ_PLUGOUT], pdata); plugout_err: free_irq(pdata->irq[HI6402_IRQ_SOUND_TRIGER], pdata); sound_triger_err: free_irq(pdata->irq[HI6402_IRQ_PLL_UNLOCK], pdata); pll_unlock_err: wake_lock_destroy(&pdata->soundtrigger_wake_lock); wake_lock_destroy(&pdata->wake_lock); mutex_destroy(&pdata->plug_mutex); mutex_destroy(&pdata->status_mutex); return ret; }