static enum hrtimer_restart button_event_timer_func(struct hrtimer *data)
{
	H2W_DBG("");
	
    if (switch_get_state(&hi->sdev) == HEADSET) {
       	if (gpio_get_value(hi->cable_in2) == BTN_STATE_RELEASED) {  /* FIH-SW2-MM-AY-TAP_headset_00 */
       		if (hi->ignore_btn)
                    hi->ignore_btn = 0;
       	else {
       		if (bn_state)
                    button_released();
       		else {
       		    if (!hi->ignore_btn) { /* FIH-SW2-MM-AY-TAP_headset_01 */
       		        button_pressed();
       		        button_released();
       		    } /* FIH-SW2-MM-AY-TAP_headset_01 */
       		}
       	}
    } else {
       	if (!hi->ignore_btn)
       		button_pressed();
       	}
    }

    return HRTIMER_NORESTART;
}
static void remove_headset(void)
{
	unsigned long irq_flags;

	H2W_DBG("");
	
	/*Report Headset State*/
	input_report_switch(hi->input, SW_HEADPHONE_INSERT, 0);
	switch_set_state(&hi->sdev, BIT_NO_DEVICE);
	input_sync(hi->input);

	/* Disable button */
	if(hi->enable_btn_irq)
	{
	local_irq_save(irq_flags);
		disable_irq_nosync(hi->irq_btn);
		irq_set_irq_wake(hi->irq_btn, 0);
		hi->enable_btn_irq = 0;
	local_irq_restore(irq_flags);
	}
	/*Check Button State*/
	if (atomic_read(&hi->btn_state))
		button_released();

//bc	gpio_set_value(hi->gpio_mic_mode, 0);
/* LGE_CHANGE_S: 2012-04-03, [email protected] Description: 500ms -> 250ms */
	hi->debounce_time = ktime_set(0, 250000000);  /* 500ms */
/* LGE_CHANGE_E: 500ms -> 250ms */
}
Beispiel #3
0
static void remove_headset(void)
{
#ifdef FEATURE_AUD_HOOK_BTN	
	unsigned long irq_flags;
#endif

    H2W_DBG("");
    hi->ignore_btn = 1;  /* FIH-SW2-MM-AY-TAP_Tapioca-00746_00 */
    pmic_hsed_enable(PM_HSED_CONTROLLER_0, PM_HSED_ENABLE_OFF); /* FIH-SW2-MM-AY-TAP-ControlHSED_BIAS1-01 */
	switch_set_state(&hi->sdev, NO_DEVICE);
		
  	input_sync(hi->hs_input);
#ifdef FEATURE_AUD_HOOK_BTN

	mHeadphone = false;

	if (bn_irq_enable) {
		
		local_irq_save(irq_flags);
		
		disable_irq(hi->irq_btn);

		local_irq_restore(irq_flags);
		
		bn_irq_enable=0;

		irq_set_irq_wake(hi->irq_btn, 0);
	}
	
	if (atomic_read(&hi->btn_state))
		button_released();
#endif
}
static void remove_headset(struct hsd_info *hi)
{
    HSD_DBG("remove_headset");

    gpio_set_value_cansleep(hi->gpio_mic_en, 0);
    if (hi->set_headset_mic_bias) hi->set_headset_mic_bias(FALSE);

    atomic_set(&hi->is_3_pole_or_not, 1);
    mutex_lock(&hi->mutex_lock);
    switch_set_state(&hi->sdev, NO_DEVICE);
    mutex_unlock(&hi->mutex_lock);

    if (atomic_read(&hi->irq_key_enabled)) {
        unsigned long irq_flags;

        local_irq_save(irq_flags);
        disable_irq(hi->irq_key);
        local_irq_restore(irq_flags);
        atomic_set(&hi->irq_key_enabled, FALSE);
    }

    if (atomic_read(&hi->btn_state))
        button_released(hi);

}
void headset_button_event(int is_press, int type)
{
	HS_DBG();

	if (hi->hs_35mm_type == HEADSET_UNPLUG &&
	    hi->h2w_35mm_type == HEADSET_UNPLUG) {
		HS_LOG("IGNORE key %d (HEADSET_UNPLUG)", type);
		return;
	}

	if (!hs_hpin_stable()) {
		HS_LOG("IGNORE key %d (Unstable HPIN)", type);
		return;
	}

	if (!get_mic_state()) {
		HS_LOG("IGNORE key %d (Not support MIC)", type);
		return;
	}

	if (!is_press)
		button_released(type);
	else if (!atomic_read(&hi->btn_state))
		button_pressed(type);
}
static void remove_35mm_do_work(struct work_struct *work)
{
	int state;

	if (hi->is_wake_lock_ready)
		wake_lock_timeout(&hi->headset_wake_lock, 2.5*HZ);

	H2W_DBG("");
	/*To solve the insert, remove, insert headset problem*/
	if (time_before_eq(jiffies, hi->insert_jiffies))
		msleep(800);
	if (hi->is_ext_insert) {
		H2WI("Skip 3.5mm headset plug out!!!");
		return;
	}

	printk(KERN_INFO "3.5mm_headset plug out\n");
	mutex_lock(&hi->mutex_lock);
	state = switch_get_state(&hi->sdev);

	if (hi->mic_bias_state) {
		turn_mic_bias_on(0);
		hi->mic_bias_state = 0;
	}

	/* For HW Metrico lab test */
	if (hi->metrico_status)
		enable_metrico_headset(0);

	microp_notify_unplug_mic();

	if (atomic_read(&hi->btn_state))
		button_released(atomic_read(&hi->btn_state));
	hi->ext_35mm_status = HTC_35MM_UNPLUG;

	if (hi->key_int_shutdown_gpio)
		gpio_set_value(hi->key_int_shutdown_gpio, 0);

	if (hi->ext_mic_sel)
		gpio_direction_output(hi->ext_mic_sel, 0);

	if (hi->h2w_dev_type == H2W_TVOUT) {
		state &= ~(BIT_HEADSET | BIT_35MM_HEADSET);
		state |= BIT_HEADSET_NO_MIC;
		switch_set_state(&hi->sdev, state);
	} else if (hi->cable_in1 && !gpio_get_value(hi->cable_in1)) {
		state &= ~BIT_35MM_HEADSET;
		switch_set_state(&hi->sdev, state);
		queue_delayed_work(detect_wq, &detect_h2w_work, H2W_NO_DELAY);
	} else {
		state &= ~(BIT_HEADSET | BIT_HEADSET_NO_MIC |
			BIT_35MM_HEADSET);
		switch_set_state(&hi->sdev, state);
	}

	mutex_unlock(&hi->mutex_lock);
}
static void remove_h2w_35mm(void)
{
	HS_LOG_TIME("Remove H2W 3.5mm headset");

	set_35mm_hw_state(0);

	if (atomic_read(&hi->btn_state))
		button_released(atomic_read(&hi->btn_state));
	hi->h2w_35mm_type = HEADSET_UNPLUG;
}
Beispiel #8
0
static void remove_detect_work_func(struct work_struct *work)
{
    int state;

    wake_lock_timeout(&hi->hs_wake_lock, HS_WAKE_LOCK_TIMEOUT);

    HS_DBG();

    if (time_before_eq(jiffies, hi->insert_jiffies + HZ)) {
        HS_LOG("Waiting for HPIN stable");
        msleep(HS_DELAY_SEC - HS_DELAY_REMOVE);
    }

    if (hi->is_ext_insert) {
        HS_LOG("Headset has been inserted");
        return;
    }

    set_35mm_hw_state(0);

    if (hi->metrico_status)
        enable_metrico_headset(0);

    if (atomic_read(&hi->btn_state))
        button_released(atomic_read(&hi->btn_state));
    hi->ext_35mm_status = HTC_35MM_UNPLUG;

    mutex_lock(&hi->mutex_lock);

    state = switch_get_state(&hi->sdev);
    if (!(state & MASK_35MM_HEADSET)) {
        HS_LOG("Headset has been removed");
        mutex_unlock(&hi->mutex_lock);
        return;
    }

#if 0
    if (hi->cable_in1 && !gpio_get_value(hi->cable_in1)) {
        state &= ~BIT_35MM_HEADSET;
        switch_set_state(&hi->sdev, state);
        queue_delayed_work(detect_wq, &detect_h2w_work,
                           HS_DELAY_ZERO_JIFFIES);
    } else {
        state &= ~(MASK_35MM_HEADSET | MASK_FM_ATTRIBUTE);
        switch_set_state(&hi->sdev, state);
    }
#else
    state &= ~(MASK_35MM_HEADSET | MASK_FM_ATTRIBUTE);
    switch_set_state(&hi->sdev, state);
#endif

    HS_LOG_TIME("Remove 3.5mm headset");

    mutex_unlock(&hi->mutex_lock);
}
static irqreturn_t button_irq_handler(int irq, void *dev_id)
{
    struct hsd_info *hi = (struct hsd_info *) dev_id;
    int value = 0;
    int fp = read_file(EARJACK_FILENAME);

    if(fp < 0)
    {


        HSD_DBG("button_irq_handler");

        value = gpio_get_value_cansleep(hi->gpio_key);

        if (value) button_pressed(hi);
        else button_released(hi);

        return IRQ_HANDLED;
    }
    else
    {
        if(fp)
        {

            HSD_DBG("button_irq_handler");

            value = gpio_get_value_cansleep(hi->gpio_key);

            if (value) button_pressed(hi);
            else button_released(hi);

            return IRQ_HANDLED;
        }
        else
        {

            return IRQ_NONE;
        }
    }

    return IRQ_NONE;
}
Beispiel #10
0
void check_hook_key_state_work_func(struct work_struct *work)
{
	int hook_key_status = 0;
	int rc = 0;
	unsigned long irq_flags;

	HEADSET_DBG("");
	if ( HSD_HEADSET != g_headset_type )
	{
		HEADSET_INFO("Headset remove!! or may ear phone noise !!");
		
		return;
	}
	hook_key_status = gpio_get_value(headset_data.hook_gpio);
	if ( 1 == hook_key_status )
	{
		
		button_pressed();
		atomic_set(&headset_data.is_button_press, 1);
		
		
		rc = set_irq_type(headset_data.hook_irq, IRQF_TRIGGER_LOW);
		if (rc)
			HEADSET_ERR( "change hook key detection type as low fail!!");

	}
	else
	{
		if ( 1 == atomic_read(&headset_data.is_button_press))
		{
			
			button_released();
			atomic_set(&headset_data.is_button_press, 0);
			
			
			rc = set_irq_type(headset_data.hook_irq, IRQF_TRIGGER_HIGH);
			HEADSET_DBG("Hook Key release change hook key detection type as high");
			if (rc)
				HEADSET_ERR("change hook key detection type as high fail!!");
		}
	}
	
	if ( HSD_IRQ_DISABLE == headset_data.hook_irq_status)
	{
		local_irq_save(irq_flags);
		
		enable_irq(headset_data.hook_irq);
		headset_data.hook_irq_status = HSD_IRQ_ENABLE;
		set_irq_wake(headset_data.hook_irq, 1);
		local_irq_restore(irq_flags);

	}
}
static enum hrtimer_restart button_35mm_event_timer_func(struct hrtimer *data)
{
	printk(KERN_INFO "%s\n", __func__);
	if (gpio_get_value(hi->gpio_headset_mic)) {
		button_pressed();
		hi->btn35mm_debounce_time = ktime_set(0, 200 * 1000 * 1000);
	} else {
		button_released();
		hi->btn35mm_debounce_time = ktime_set(0, 500 * 1000 * 1000);
	}

	return HRTIMER_NORESTART;
}
void headset_button_event(int is_press, int type)
{
	HS_DBG();

	if (!hs_hpin_stable()) {
		HS_LOG("The HPIN is unstable, SKIP THE BUTTON EVENT.");
		return;
	}

	if (!is_press)
		button_released(type);
	else if (!atomic_read(&hi->btn_state))
		button_pressed(type);
}
static void remove_11pin_35mm(void)
{
	if (hi->mic_bias_state) {
		turn_mic_bias_on(0);
		hi->mic_bias_state = 0;
		msleep(300);
	}

	microp_notify_unplug_mic();
	if (atomic_read(&hi->btn_state))
		button_released(atomic_read(&hi->btn_state));
	hi->h2w_35mm_status = HTC_35MM_UNPLUG;
	if (hi->key_int_shutdown_gpio)
		gpio_set_value(hi->key_int_shutdown_gpio, 0);
	printk(KERN_INFO "remove 11pin 3.5mm headset\n");
}
Beispiel #14
0
static void remove_headset(void)
{
	int rc = 0;
	unsigned long irq_flags;

	
	if (HSD_HEADSET == g_headset_type)
	{
		
		gpio_set_value(AUDIO_HEADSET_MIC_SHTDWN_N, 1);
		HEADSET_INFO("Turn off mic en");

		
		PM_LOG_EVENT(PM_LOG_OFF, PM_LOG_AUTIO_MIC);
		

		if ( 1 == atomic_read(&headset_data.is_button_press))
		{
			
			button_released();
			atomic_set(&headset_data.is_button_press, 0);
		}
		if ( HSD_IRQ_ENABLE == headset_data.hook_irq_status)
		{
			local_irq_save(irq_flags);
			
			
			disable_irq_nosync(headset_data.hook_irq);
			headset_data.hook_irq_status = HSD_IRQ_DISABLE;
			set_irq_wake(headset_data.hook_irq, 0);
			local_irq_restore(irq_flags);
		}
	}
	g_headset_type = HSD_NONE;
	
	rc = set_irq_type(headset_data.jack_irq, IRQF_TRIGGER_LOW);
	if (rc)
		HEADSET_ERR("change IRQ detection type as low fail!!");
	
	headset_data.recover_chk_times = RECOVER_CHK_HEADSET_TYPE_TIMES;

	HEADSET_INFO("Headset remove, jack_irq active LOW");


}
static enum hrtimer_restart button_event_timer_func(struct hrtimer *data)
{
	H2W_DBG("");

	if (switch_get_state(&hi->sdev) == HTC_HEADSET) {
		if (gpio_get_value(SAPPHIRE_GPIO_CABLE_IN2)) {
			if (hi->ignore_btn)
				hi->ignore_btn = 0;
			else if (atomic_read(&hi->btn_state))
				button_released();
		} else {
			if (!hi->ignore_btn && !atomic_read(&hi->btn_state))
				button_pressed();
		}
	}

	return HRTIMER_NORESTART;
}
static void remove_headset(void)
{
	unsigned long irq_flags;

	H2W_DBG("");

	switch_set_state(&hi->sdev, NO_DEVICE);
	configure_cpld(UART3);

	/*                */
	local_irq_save(irq_flags);
	disable_irq(hi->irq_btn);
	local_irq_restore(irq_flags);

	if (atomic_read(&hi->btn_state))
		button_released();

	hi->debounce_time = ktime_set(0, 100000000);  /*        */
}
static void remove_headset(void)
{
	HDS_DBG("");

	mutex_lock(&hi->mutex_lock);
	switch_set_state(&hi->sdev, switch_get_state(&hi->sdev) &
			~(BIT_HEADSET | BIT_HEADSET_NO_MIC));
	mutex_unlock(&hi->mutex_lock);

	if (hi->btn_11pin_35mm_flag) {
		disable_irq(hi->irq_btn_35mm);
		//turn_mic_bias_on(0);
		hi->btn_11pin_35mm_flag = 0;
		if (atomic_read(&hi->btn_state))
			button_released();
	}
	HDS_DBG("removed 3.5mm headset\n");

	hi->debounce_time = ktime_set(0, 100000000);  /* 100 ms */
}
void headset_button_event(int is_press, int type)
{
    HS_DBG();

    if (hi->hs_35mm_type == HEADSET_UNPLUG &&
            hi->h2w_35mm_type == HEADSET_UNPLUG) {
        HS_LOG("IGNORE key %d (HEADSET_UNPLUG)", type);
        return;
    }

    if (!hs_hpin_stable()) {
        HS_LOG("The HPIN is unstable, SKIP THE BUTTON EVENT.");
        return;
    }

    if (!is_press)
        button_released(type);
    else if (!atomic_read(&hi->btn_state))
        button_pressed(type);
}
Beispiel #19
0
void simulate_hs_report(struct snd_soc_jack *jack, int status, int mask)
{
    struct snd_soc_codec *codec;
    int oldstatus;

    if (!jack)
        return;
    pr_info("%s: id=[%s]; name=[%s]\n",
            __func__, jack->jack->id, jack->jack->name);
    codec = jack->codec;
    /* delet by youjin to avaid deadlock 2012-11-19
    mutex_lock(&codec->mutex);
    */

    oldstatus = jack->status;
    jack->status &= ~mask;
    jack->status |= status & mask;
    if (mask && (jack->status == oldstatus))
        return;

    if (!strncmp("Headset Jack", jack->jack->id, sizeof("Headset Jack"))) {
        pr_debug("[%s] oldstatus:%d, newstatus:%d\n",
                 jack->jack->id, oldstatus, jack->status);
        if (jack->status)
            insert_headset();
        else
            remove_headset();
    } else if (!strncmp("Button Jack",
                        jack->jack->id, sizeof("Button Jack"))) {
        pr_debug("[%s] oldstatus:%d, newstatus:%d\n",
                 jack->jack->id, oldstatus, jack->status);
        if (jack->status)
            button_pressed();
        else
            button_released();
    }
    /*delet by youjin to avaid deadlock 2012-11-19
    out:
    	mutex_unlock(&codec->mutex);
    */
}
static enum hrtimer_restart button_event_timer_func(struct hrtimer *data)
{
	H2W_DBG("");

	if (switch_get_state(&hi->sdev) == LGE_HEADSET
//kiwone, 2009.12.24, to fix bug
// 4 pole headset eject->button key is detected
      && (0 == gpio_get_value(hi->gpio_detect))
	) {
		if (!gpio_get_value(hi->gpio_button_detect)) {
			if (hi->ignore_btn)
				hi->ignore_btn = 0;
			else if (atomic_read(&hi->btn_state))
				button_released();
		} else {
			if (!hi->ignore_btn && !atomic_read(&hi->btn_state))
				button_pressed();
		}
	}

	return HRTIMER_NORESTART;
}
static void remove_headset(void)
{
	unsigned long irq_flags;

	H2W_DBG("");
	
	input_report_switch(hi->input, SW_HEADPHONE_INSERT, 0);
	switch_set_state(&hi->sdev, NO_DEVICE);
	input_sync(hi->input);

	/* Disable button */
	local_irq_save(irq_flags);
	disable_irq_nosync(hi->irq_btn);
	set_irq_wake(hi->irq_btn, 0);
	local_irq_restore(irq_flags);

	if (atomic_read(&hi->btn_state))
		button_released();
#ifdef CONFIG_LGE_AUDIO_HEADSET_PROTECT
	gpio_set_value(hi->gpio_mic_bias_en, 0);
#endif 
	hi->debounce_time = ktime_set(0, 500000000);  /* VS760 100 ms -> 300ms */
}
Beispiel #22
0
static enum hrtimer_restart button_event_timer_func(struct hrtimer *data)
{
	int headset_in  =0;
	int btn_down  =0;

	H2W_DBG("");

	/* Low Detect, Fast Check*/
	/* "button timer < headset detach timer" makes abnormal operation*/
	headset_in	= gpio_get_value(hi->gpio_detect)?0: 1;
	/*Headset button - High Detect*/
	//btn_down	= gpio_get_value(hi->gpio_button_detect)?1 :0; 
	/*Headset button - LOW Detect*/
	btn_down	= gpio_get_value(hi->gpio_button_detect)?0 :1; 
	if(hi->ignore_btn){
		H2W_DBG("ignore_btn");
		return HRTIMER_NORESTART;
	}

	
	if ((switch_get_state(&hi->sdev) == BIT_HEADSET)  && headset_in){
		
		H2W_DBG(" headset in %d btn down %d",headset_in,btn_down);
		if (btn_down){
			if (!atomic_read(&hi->btn_state))
				button_pressed();
			
		} else {
			if (atomic_read(&hi->btn_state))
				button_released();
		}
	}

	H2W_DBG(" No button event");

	return HRTIMER_NORESTART;
}
Beispiel #23
0
static void remove_detect_work_func(struct work_struct *work)
{
	int state;

	wake_lock_timeout(&hi->hs_wake_lock, HS_WAKE_LOCK_TIMEOUT);

	HS_DBG();

/*remove one-wire detection setting if the project support one-wire detection*/
	if(hi->detect_type == HEADSET_1WIRE && hi->pdata.enable_1wire){
		HS_LOG("Disable one-wire detection.");
		closeFile(fp);
		disable_1wire();
		hi->detect_type = HEADSET_ADC;
	}

	if (time_before_eq(jiffies, hi->insert_jiffies + HZ)) {
		HS_LOG("Waiting for HPIN stable");
		msleep(HS_DELAY_SEC - HS_DELAY_REMOVE);
	}

	if (hi->is_ext_insert) {
		HS_LOG("Headset has been inserted");
		return;
	}

	if (hi->hs_35mm_type == HEADSET_INDICATOR &&
	    hs_mgr_notifier.indicator_enable)
		hs_mgr_notifier.indicator_enable(0);

	set_35mm_hw_state(0);
#if defined(CONFIG_FB_MSM_TVOUT) && defined(CONFIG_ARCH_MSM8X60)
	if (hi->hs_35mm_type == HEADSET_TV_OUT && hi->pdata.hptv_sel_gpio) {
		HS_LOG_TIME("Remove 3.5mm TVOUT cable");
		tvout_enable_detection(0);
		gpio_set_value(hi->pdata.hptv_sel_gpio, 0);
	}
#endif
	if (hi->metrico_status)
		enable_metrico_headset(0);

	if (atomic_read(&hi->btn_state))
		button_released(atomic_read(&hi->btn_state));

	mutex_lock(&hi->mutex_lock);

	state = switch_get_state(&hi->sdev);
	if (!(state & MASK_35MM_HEADSET)||hi->hs_35mm_type == HEADSET_UNPLUG) {
		HS_LOG("Headset has been removed");
		mutex_unlock(&hi->mutex_lock);
		return;
	}
	hi->hs_35mm_type = HEADSET_UNPLUG;

#if 0
	if (hi->cable_in1 && !gpio_get_value(hi->cable_in1)) {
		state &= ~BIT_35MM_HEADSET;
		switch_set_state(&hi->sdev, state);
		queue_delayed_work(detect_wq, &detect_h2w_work,
				   HS_DELAY_ZERO_JIFFIES);
	} else {
		state &= ~(MASK_35MM_HEADSET | MASK_FM_ATTRIBUTE);
		switch_set_state(&hi->sdev, state);
	}
#else
	state &= ~(MASK_35MM_HEADSET | MASK_FM_ATTRIBUTE);
	switch_set_state(&hi->sdev, state);
#endif
	hpin_report++;
	HS_LOG_TIME("Remove 3.5mm accessory");

	mutex_unlock(&hi->mutex_lock);
	if ((hi->pdata.eng_cfg == HS_EDE_U) || (hi->pdata.eng_cfg == HS_EDE_TD) || (hi->pdata.eng_cfg == HS_BLE))
	{
		aic3008_set_mic_bias(0);
	}

	if ((hi->pdata.eng_cfg == HS_QUO_F_U))
	{
		regulator = regulator_get(NULL, "v_aud_2v85");
		if (IS_ERR_OR_NULL(regulator)) {
			pr_err("htc_headset_gpio_probe:Couldn't get regulator v_aud_2v85\n");
			regulator = NULL;
			return;
		}
		regulator_disable(regulator);
	}

	/* FIXME */
/*	if (gpio_event_get_quickboot_status())
		HS_LOG("quick_boot_status = 1"); */
}
static void remove_detect_work_func(struct work_struct *work)
{
	int state;

	wake_lock_timeout(&hi->hs_wake_lock, HS_WAKE_LOCK_TIMEOUT);

	HS_DBG();

	if (time_before_eq(jiffies, hi->insert_jiffies + HZ)) {
		HS_LOG("Waiting for HPIN stable");
		if (hi->pdata.driver_flag & DRIVER_HS_MGR_OLD_AJ)
			msleep(HS_DELAY_SEC - HS_DELAY_REMOVE_LONG);
		else
			msleep(HS_DELAY_SEC - HS_DELAY_REMOVE_SHORT);
	}

	if (hi->is_ext_insert) {
		HS_LOG("Headset has been reinserted during debounce time");
		return;
	}

	if (hi->hs_35mm_type == HEADSET_INDICATOR &&
	    hs_mgr_notifier.indicator_enable)
		hs_mgr_notifier.indicator_enable(0);

	set_35mm_hw_state(0);
#if defined(CONFIG_FB_MSM_TVOUT) && defined(CONFIG_ARCH_MSM8X60)
	if (hi->hs_35mm_type == HEADSET_TV_OUT && hi->pdata.hptv_sel_gpio) {
		HS_LOG_TIME("Remove 3.5mm TVOUT cable");
		tvout_enable_detection(0);
		gpio_set_value(hi->pdata.hptv_sel_gpio, 0);
	}
#endif
	if (hi->metrico_status)
		enable_metrico_headset(0);

	if (atomic_read(&hi->btn_state))
		button_released(atomic_read(&hi->btn_state));
	hi->hs_35mm_type = HEADSET_UNPLUG;

	mutex_lock(&hi->mutex_lock);

	state = switch_get_state(&hi->sdev_h2w);
	if (!(state & MASK_35MM_HEADSET)) {
		HS_LOG("Headset has been removed");
		mutex_unlock(&hi->mutex_lock);
		return;
	}

#if 0
	if (hi->cable_in1 && !gpio_get_value(hi->cable_in1)) {
		state &= ~BIT_35MM_HEADSET;
		switch_set_state(&hi->sdev_h2w, state);
		queue_delayed_work(detect_wq, &detect_h2w_work,
				   HS_DELAY_ZERO_JIFFIES);
	} else {
		state &= ~(MASK_35MM_HEADSET | MASK_FM_ATTRIBUTE);
		switch_set_state(&hi->sdev_h2w, state);
	}
#else
	state &= ~(MASK_35MM_HEADSET | MASK_FM_ATTRIBUTE);
	switch_set_state(&hi->sdev_h2w, state);
#endif

	HS_LOG_TIME("Remove 3.5mm accessory");

	mutex_unlock(&hi->mutex_lock);

#ifdef HTC_HEADSET_CONFIG_QUICK_BOOT
	if (gpio_event_get_quickboot_status())
		HS_LOG("quick_boot_status = 1");
#endif
}
Beispiel #25
0
PROCESS_THREAD(hexapush_process, ev, data) {
    
    static struct etimer debounce_timer;

    static uint8_t button_state[8];
    static uint8_t longclick_counter[8];

    PROCESS_BEGIN();

    int i;
    for(i=0;i<8;i++) {
        button_state[i]=0;
        longclick_counter[i]=0;
    }

    hexapush_init();

    etimer_set(&debounce_timer, CLOCK_SECOND * HP_DEBOUNCE_TIME / 1000);
    PRINTF("Hexapush process ready!\n");
   

    while(1) {

         etimer_restart(&debounce_timer);
         int i;

         for(i=0; i<8; i++) {
            if(button_state[i]==HEXAPUSH_NOTPRESSED_STATE) {
                //PRINTF("Hexapush: %d is in state 0\n",i);
                if(((~HEXAPUSH_IN&button_vector)&(1<<i))!=0) {
                    button_state[i]=HEXAPUSH_DEBOUNCE_STATE;
                }
            } else if (button_state[i]==HEXAPUSH_DEBOUNCE_STATE) {
                //PRINTF("Hexapush: %d is in state 1\n",i);
                if(((~HEXAPUSH_IN&button_vector)&(1<<i))!=0) {
                    #if HEXAPUSH_CLICK_ENABLE
                    button_state[i]=HEXAPUSH_CLICK_STATE;
                    #elif HEXAPUSH_PRESS_RELEASE_ENABLE
                    button_pressed(i);
                    button_state[i]=HEXAPUSH_PRESSED_STATE;
                    #else
                    button_state[i]=HEXAPUSH_NOTPRESSED_STATE;
                    #endif
                } else {
                    button_state[i]=HEXAPUSH_NOTPRESSED_STATE;
                }
            } else if (button_state[i]==HEXAPUSH_CLICK_STATE) {
                //PRINTF("Hexapush: %d is in state 2\n",i);
                #if HEXAPUSH_PRESS_RELEASE_ENABLE
                if(((~HEXAPUSH_IN&button_vector)&(1<<i))!=0) {
                    if(longclick_counter[i]<HEXAPUSH_PRESS_DELAY) {
                        longclick_counter[i]++;
                    } else {
                        button_pressed(i);
                        longclick_counter[i]=0;
                        button_state[i]=HEXAPUSH_PRESSED_STATE;
                    }
                } else {
                    button_clicked(i);
                    longclick_counter[i]=0;
                    button_state[i]=HEXAPUSH_NOTPRESSED_STATE;
                }
                #else
                button_clicked(i);
                button_state[i] = HEXAPUSH_PRESSED_STATE;
                #endif

            } else if (button_state[i]==HEXAPUSH_PRESSED_STATE) { //Long click state
                //PRINTF("Hexapush: %d is in state 3\n",i);
                if(((~HEXAPUSH_IN&button_vector)&(1<<i))==0) {
                    #if HEXAPUSH_PRESS_RELEASE_ENABLE
                    button_released(i);
                    #endif
                    button_state[i]=HEXAPUSH_NOTPRESSED_STATE;
                }
            } else {
                PRINTF("Hexapush error: Unknown state\n");
            }
         }
         PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&debounce_timer));
    }

    PROCESS_END();
}