Example #1
0
static void max17040_work(struct work_struct *work)
{
#ifdef MAX17040_ALARM_RTC_ENABLE
    unsigned long flags;
#endif //MAX17040_ALARM_RTC_ENABLE
    int enable;
    static int first_enable = 1;
    dbg_func_in();
    max17040_data.event=NoEvents;
    max17040_data.suspend_event=NoEvents;

#ifndef MAX17040_ALARM_RTC_ENABLE
//	sleep_dbg("MAX17040_WORK CALL.\n");
    //prevent suspend
    max17040_prevent_suspend();
#else
//	sleep_dbg("MAX17040_WORK RTC CALL.\n");
#endif //MAX17040_ALARM_RTC_ENABLE

    //read voltage now
    max17040_get_vcell();

    //read soc
    max17040_get_soc();
#ifdef MAX17040_DEBUG_QUICK
    max17040_quick_get_value();
#endif
    enable = atomic_read(&max17040_data.set_test);
    //save volate now and soc [TEST APPLICATION]
    if(enable)
    {
        if((max17040_data.event)||first_enable) // ps2 team shs : soc is changed
        {
            sleep_dbg("MAX17040 SET TEST.\n");
            sleep_dbg("MAX17040_WORK SOC [%d] prev[%d] : voltage [%d] : charger_state [%d] : i2c state [%d]\n",max17040_data.soc,max17040_data.prev_soc, max17040_data.vcell,charge_state,max17040_data.i2c_state);
            input_report_rel(max17040_data.max17040_input_data, REL_RX, max17040_data.vcell);
            input_report_rel(max17040_data.max17040_input_data, REL_RY, max17040_data.soc);
            input_report_rel(max17040_data.max17040_input_data, REL_RZ, enable);
            input_sync(max17040_data.max17040_input_data);
            if(first_enable)
                first_enable = 0;
        }

    }
    else
        first_enable = 1;
    //ps2 team shs : After you determine the value of voltage and soc If there are changes to the event generates.
    if(max17040_data.slow_poll) //do not call early resume state.
    {
        if(max17040_data.suspend_event)// 15 percent below where they were soc.
        {
            dbg("low battery [%d] percent!!!!!!!\n",max17040_data.soc);
            max17040_power_supply_changed();
            sleep_dbg("[SLEEP_EVENT] 15 percent below Send Event [%d].\n",max17040_data.soc );
        }
        else	//15 percent up where were soc.
        {
            max17040_power_supply_changed();
            sleep_dbg("[SLEEP_EVENT] 15 percent up Send Event [%d].\n",max17040_data.soc );
        }

    }
    else //call early resume state.
    {
        if(max17040_data.event) //Different values soc.
        {
            sleep_dbg("MAX17040_WORK SOC [%d] prev[%d] : voltage [%d] : charger_state [%d] : i2c state [%d]\n",max17040_data.soc,max17040_data.prev_soc, max17040_data.vcell,charge_state,max17040_data.i2c_state);
            max17040_power_supply_changed();
        }
        else	//same values soc.
        {
            dbg("[EVENT] Stop Event.\n");
        }
    }

#if defined(CONFIG_SKY_SMB136S_CHARGER)
    if(max17040_raw_soc != max17040_raw_pre_soc) {
        pr_err("[SOC:%d->%d]\n", max17040_raw_pre_soc, max17040_raw_soc);
        /* if battery is fully charged, charging done*/
        if(sky_get_plug_state() == 1 &&
                (max17040_raw_pre_soc >= (CHARGING_DONE_THRESHOLD-5)
                 && max17040_raw_soc >= CHARGING_DONE_THRESHOLD)) {
            notify_event_charging_done();
        }

        /* if gauge falls below a threshold, recharging */
        if(sky_get_plug_state() == 0 &&
                (max17040_raw_pre_soc >= (RECHARGING_THRESHOLD-5)
                 && max17040_raw_soc <= RECHARGING_THRESHOLD)) {
            notify_event_recharging();
        }
    }
#endif

#ifdef MAX17040_ALARM_RTC_ENABLE
    di->last_poll=alarm_get_elapsed_realtime();
    /* prevent suspend before starting the alarm */
    local_irq_save(flags);
    max17040_schedule();
    max17040_allow_suspend();
    local_irq_restore(flags);
    dbg_func_out();
#else
    max17040_data.slow_poll = Early_resume;
    max17040_allow_suspend();
    schedule_delayed_work(&max17040_data.work, MAX17040_DELAY);
#endif // MAX17040_ALARM_RTC_ENABLE
}
Example #2
0
static void max17040_work(struct work_struct *work)
{
#ifdef MAX17040_ALARM_RTC_ENABLE
	struct max17040_chip *di =
		container_of(work, struct max17040_chip, monitor_work);
#else
	struct max17040_chip *di = container_of(work, struct max17040_chip, work.work);
#endif //MAX17040_ALARM_RTC_ENABLE

#ifdef CONFIG_SKY_SMB136S_CHARGER
	int thermal_time_check_count = 0;
	unsigned long pm_temp = 0;
	unsigned long pm_temp_sum = 0;
	unsigned long current_batt_delta = 0;
	unsigned long pre_batt_delta = 0;
	int batt_delta_sum = 0;
	int batt_delta = 0;
	int chg_type;
#endif

//	unsigned long flags;	
	int enable;	
	dbg_func_in();
	max17040_data.event=NoEvents;
	max17040_data.suspend_event=NoEvents;
	
#ifndef MAX17040_ALARM_RTC_ENABLE	
//	sleep_dbg("MAX17040_WORK CALL.\n");				
	//prevent suspend
	max17040_prevent_suspend();
#else
//	sleep_dbg("MAX17040_WORK RTC CALL.\n");				
#endif //MAX17040_ALARM_RTC_ENABLE

	//read voltage now
	max17040_get_vcell();

	//read soc 
	max17040_get_soc();
#ifdef MAX17040_DEBUG_QUICK	
	max17040_quick_get_value();	
#endif
	enable = atomic_read(&max17040_data.set_test);
	//save volate now and soc [TEST APPLICATION]
	if(enable)
	{	
		if(max17040_data.event) // soc is changed 
		{	
			pr_err("MAX17040 SET TEST.\n");						
			sleep_dbg("MAX17040_WORK SOC [%d] prev[%d] : voltage [%d] : charger_state [%d] : i2c state [%d]\n", 
				max17040_data.soc,max17040_data.prev_soc, max17040_data.vcell,charge_state,max17040_data.i2c_state);							
			input_report_abs(max17040_data.max17040_input_data, ABS_X, max17040_data.vcell);
			input_report_abs(max17040_data.max17040_input_data, ABS_Y, max17040_data.soc);
		    	input_report_abs(max17040_data.max17040_input_data, ABS_WAKE, enable);		
			input_sync(max17040_data.max17040_input_data);	
		}

	}
	
	//After you determine the value of voltage and soc If there are changes to the event generates.
	if(max17040_data.slow_poll) //do not call early resume state.
	{
		if(max17040_data.suspend_event)// 15 percent below where they were soc.
			{
				pr_err("low battery [%d] percent!!!!!!!\n",max17040_data.soc);				
				power_supply_changed(&di->battery);	
				pr_err("[SLEEP_EVENT] 15 percent below Send Event [%d].\n",max17040_data.soc );				
			}
		else	//15 percent up where were soc.
			{	
				power_supply_changed(&di->battery);					
				pr_err("[SLEEP_EVENT] 15 percent up Send Event [%d].\n",max17040_data.soc );				
			}

	}
	else //call early resume state.
	{
		if(max17040_data.event) {	//Different values soc.
			pr_err("MAX17040_WORK SOC [%d] prev[%d] : voltage [%d] : charger_state [%d] : i2c state [%d]\n", 
				max17040_data.soc,max17040_data.prev_soc, max17040_data.vcell,charge_state,max17040_data.i2c_state);	
			power_supply_changed(&di->battery);
		}
		else	 {	//same values soc.
			//pr_err("[EVENT] Stop Event.\n");			
		}
	}

	if(max17040_raw_soc != max17040_raw_pre_soc) {
		pr_err("[SOC:%d->%d]\n", max17040_raw_pre_soc, max17040_raw_soc);
		/* if battery is fully charged, charging done*/
		if(sky_get_plug_state() == 1 && 
			(max17040_raw_pre_soc >= (CHARGING_DONE_THRESHOLD-5) 
			&& max17040_raw_soc >= CHARGING_DONE_THRESHOLD)) {
			notify_event_charging_done();
		}

		/* if gauge falls below a threshold, recharging */
		if(sky_get_plug_state() == 0 && 
			(max17040_raw_pre_soc >= (RECHARGING_THRESHOLD-5) 
			&& max17040_raw_soc <= RECHARGING_THRESHOLD)) {
			notify_event_recharging();
		}
	}
	
#ifdef MAX17040_ALARM_RTC_ENABLE
	di->last_poll=alarm_get_elapsed_realtime();		
	/* prevent suspend before starting the alarm */
	local_irq_save(flags);	
	max17040_schedule();
	max17040_allow_suspend();			
	local_irq_restore(flags);	
	dbg_func_out();	
#else
#ifdef CONFIG_SKY_SMB136S_CHARGER
	chg_type = atomic_read(&smb_charger_state);
        pmic8058_tz_get_temp_charging(&pm_temp);
	if(thermal_time_check_count != 3) { 
		pm_temp_sum = pm_temp_sum + pm_temp;
		current_batt_delta = pm_temp;
		if (pm_temp > pre_batt_delta) {
			batt_delta = pm_temp - pre_batt_delta;
			batt_delta_sum = batt_delta_sum + batt_delta;
		}
		else {
			batt_delta = 0;
			batt_delta_sum = batt_delta_sum + batt_delta;
		}
		pre_batt_delta = current_batt_delta;
		thermal_time_check_count ++;
	}
	else {
		if(chg_type == 0) {
			if(((pm_temp_sum > 114000) || (batt_delta_sum > 600 && pm_temp_sum > 84000)) && max17040_data.set_rcomp_mode == 0) {
				high_current_rcomp_mode = 1;
				max17040_set_rcomp(); 
			}
			else {
			    if(max17040_data.set_rcomp_mode == 1) {
				high_current_rcomp_mode = 0;
				max17040_set_rcomp();
			    }
			}
		}	
		else {
				high_current_rcomp_mode = 0;
				max17040_set_rcomp();
		}
		thermal_time_check_count = 0;
		pm_temp_sum = 0;
		batt_delta_sum = 0;
			
	}
#endif
	max17040_data.slow_poll = Early_resume;
	max17040_allow_suspend();			
	schedule_delayed_work(&max17040_data.work, MAX17040_DELAY);	
#endif // MAX17040_ALARM_RTC_ENABLE
}