/** @brief  To store battery capacity value that is sent via AT command from CP
    @author [email protected]
    @date   2010.0602.
*/
static ssize_t batt_soc_store(struct device *dev, struct device_attribute *attr,
			      const char *buf, size_t count)
{
	int val, batt_raw_cap;
    /* S[, 20111015, [email protected], Fuelgauge workaround on displaying 1%. */
    static cpcap_toolow_cnt = 0;
    /* E], 20111015, [email protected], Fuelgauge workaround on displaying 1%. */

#if 1
	val = simple_strtoul(buf, NULL, 10);
#else
	sscanf(buf, "%d", &val);
#endif

	//batt_raw_cap = ((val * 100) / 95)-1;
	batt_raw_cap = val;

	printk("[BATTERY] write AT+CBC = %d to batt_soc_storei as %d\n", val, batt_raw_cap);

	/* S[, 20111015, [email protected], Fuelgauge workaround on displaying 1%. */
	if (batt_raw_cap < 3 && cpcap_toolow_cnt < 3)
	{
		cpcap_toolow_cnt ++;
	}
	else
	{
		cpcap_toolow_cnt = 0;

		refer_di->justin_capacity = refer_di->battery_capacity = batt_raw_cap;
		charger_state_update_by_other();
	}
	/* E], 20111015, [email protected], Fuelgauge workaround on displaying 1%. */

	return count;
}
Esempio n. 2
0
void set_charging_current(void)
{
	static int old_status = -1;
	int current_status = -1;

	if( !get_madc_probe_done() )
		return ;

	current_status = get_external_power_status();
	if( old_status != current_status ) {

		if( -1 == lge_usb_acc_detect())
			return ;

#ifdef CONFIG_LGE_BATT_THERM_LAB3_SCENARIO
		need_to_batt_therm_sett = 1;
#endif

		set_charging_current_sub();

		old_status = current_status;
	}

	charger_state_update_by_other();
	return ;
}
Esempio n. 3
0
static void charging_ic_work_func(struct work_struct *work)
{
	printk(KERN_INFO "[charging_msg] %s\n", __FUNCTION__);
#if defined(CONFIG_PRODUCT_LGE_LU6800)
	//20101102 [email protected] To support factory cal to prevent to deactive[START_LGE]
	charger_state_update_by_other();
	//20101102 [email protected] To support factory cal to prevent to deactive[END_LGE]
#else
	if(charging_ic_status != CHARGING_IC_DEACTIVE) {
		set_end_of_charge(1);
		//charging_ic_deactive();
		charger_state_update_by_other();
		printk(KERN_INFO "[Battery] Charging IC - EOC\n");
	}
#endif
}
Esempio n. 4
0
static void charging_ic_work_func(struct work_struct *work)
{
	printk(KERN_INFO "[charging_msg] %s\n", __FUNCTION__);
	if(charging_ic_status != CHARGING_IC_DEACTIVE) {
		printk(KERN_INFO "[Battery] Charging IC - EOC\n");
		set_end_of_charge(1);
		charger_state_update_by_other();
	}
	
	if(wake_lock_active(&eoc_handle_lock))
		wake_unlock(&eoc_handle_lock);
}
Esempio n. 5
0
void set_charging_current(void)
{
	static int old_status = -1;
	int current_status = -1;

	if( !get_madc_probe_done() )
		return ;

	current_status = get_external_power_status();
	if( old_status != current_status ) {

		/* mbk_temp */
		lge_usb_acc_detect();

		switch( get_ext_pwr_type() ) {
			case NO_CABLE:
				break;
			case LT_CABLE:
				// if LT_Cable, u-boot already set charing current. in kernel no need to set 
				//charging_ic_set_factory_mode();

				/* mbk_temp HW Request */
				setting_for_factory_mode_hw_req();
				break;
			case TA_CABLE:
			case FORGED_TA_CABLE:
				charging_ic_set_ta_mode();
				break;
		}
		printk("[charging_msg] %s, External Power Type %d \n", __FUNCTION__, get_ext_pwr_type());

		old_status = current_status;
	}

	charger_state_update_by_other();
	return ;
}
Esempio n. 6
0
s32 muic_device_detection(s32 upon_irq)
{
/* LGE_CHANGE_START 2011-03-16 [email protected] patch for Adb offline set and Mass Storage Driver detecting fail */    
	/* 20110113 [email protected] check muic driver init. state [START] */
	if(!muic_init_done){

		printk(KERN_WARNING "[MUIC] MUIC has not been initialized! Nothing will be done!!!.\n");
		return 0;
	}	
    /* 20110113 [email protected] check muic driver init. state [END] */
/* LGE_CHANGE_END 2011-03-16 [email protected] */
	// Read INT_STAT_REG (0x04)
	muic_i2c_read_byte(INT_STAT, &int_stat_val);
	printk(KERN_INFO "[MUIC] INT_STAT = %x\n", int_stat_val);

	switch (muic_mode)
	{
	case MUIC_NONE:
	case MUIC_UNKNOWN:
		muic_device_none_detect();
		break;

	// CP UART Mode
	case MUIC_CP_UART:
	case MUIC_AP_UART:
		if ((int_stat_val & MIDNO) == 0x0b) {
			muic_mode = MUIC_NONE;
		}
		else {
			muic_device_none_detect();
		}
		break;

	// TA Mode
	case MUIC_NA_TA:
	case MUIC_LG_TA:
	case MUIC_HCHH:
	case MUIC_INVALID_CHG:
		if ((int_stat_val & MVBUS) == 0) {
			// Exit Charger Mode
			muic_mode = MUIC_NONE;
		}
		else {
			// Bug fix: charger detect interrupt 2 times
			set_wakelock(0);
		}
		break;

	// USB Mode
	case MUIC_AP_USB:
	case MUIC_CP_USB:
		if ((int_stat_val & MVBUS) == 0){
			// Exit USB Mode
			muic_mode = MUIC_NONE;
		}
		else {
			muic_device_none_detect();
		}
		break;

	default:
		muic_mode = MUIC_NONE;
		break;
	}

	if (muic_mode == MUIC_NONE) {
		muic_initialize(DEFAULT);
		printk(KERN_INFO "[MUIC] muic none\n");
		charging_ic_deactive();
		printk(KERN_INFO "[MUIC] charging_ic_deactive()\n");
	}

	charger_state_update_by_other();

	return 0;
}
Esempio n. 7
0
/* LGE_UPDATE_S [[email protected]] 2010-12-01, modify detection scheme */
static void muic_device_none_detect(void)
{
	u8 reg_value;
	u8 status_value;
	s32 ret;
	
	if ((key_col == 3) && (key_row == 0)) // Volume up
		key_was_pressed = 1;
	else if ((key_col == 3) && (key_row == 1)) // Volume down
		key_was_pressed = 2;

	printk(KERN_WARNING "[MUIC] Device_None_Detect int_stat_val = 0x%x\n",int_stat_val);

/* LGE_CHANGE_S [[email protected]] 2010-12-14, CP retain mode */
#ifdef CP_RETAIN	
	if (is_cp_retained)
	{
		//muic_CP_USB_set();
		muic_set_mode(MUIC_CP_USB);
	}
	// IDNO=0100? 130Kohm :: CP UART MODE
	else if(((int_stat_val & MIDNO) == 0x04)
			|| (hidden_menu_switching == 7)) {
/* LGE_CHANGE_E [[email protected]] 2011-01-06, CP retain mode */
#elif defined(USB_RETAIN) /* 2012.05.15, [email protected], USB retain mode. */
	ret = muic_i2c_read_byte_local(INT_STAT, &status_value);
	if(ret < 0)
		printk("[MUIC] [%s-%d] muic_i2c_read_byte_local Fail [ret = %d]\n", __func__, __LINE__, ret);
	else
		printk("[MUIC] [%s-%d] INT_STAT Value is 0x%x / MVBUS bit is %d\n", __func__, __LINE__, 
																	status_value, ((status_value & MVBUS) >> 4));
	if (usb_retained == CP_RETAINED)
	{
		//muic_CP_USB_set();
		if((status_value & MVBUS)) {
			printk("[MUIC] [%s-%d] muic_set_mode(MUIC_CP_USB)\n", __func__, __LINE__);
			muic_set_mode(MUIC_CP_USB);
		}
	}
	else if (usb_retained == AP_RETAINED)
	{
		//muic_AP_USB_set();
		if((status_value & MVBUS)) {
			printk("[MUIC] [%s-%d] muic_set_mode(MUIC_AP_USB)\n", __func__, __LINE__);
            muic_set_mode(MUIC_AP_USB);
		}
	}
    // IDNO=0100? 130Kohm :: CP UART MODE
    else if(((int_stat_val & MIDNO) == 0x04)
            || (hidden_menu_switching == 7)) {

#else		
	if(((int_stat_val & MIDNO) == 0x04)
			|| (hidden_menu_switching == 7)) {
#endif	
		//muic_CP_UART_set();
		muic_set_mode(MUIC_CP_UART);	// [email protected]
	}
	// IDNO=0010? 56Kohm  :: CP USB MODE
	else if (((int_stat_val & MIDNO ) == 0x02) || (hidden_menu_switching == 9)){
		if (key_was_pressed == 2)
			//muic_AP_UART_set();
			muic_set_mode(MUIC_AP_UART);	// [email protected]
		else
			//muic_CP_USB_set();
			muic_set_mode(MUIC_CP_USB);	// [email protected]
	}
	// LGE_UPDATE_S [[email protected]] 2010-12-12, for 910K factory download
	// IDNO=1010? 910Kohm :: CP USB MODE
#ifdef 	CABLE_DETECT_910K	
	else if ((int_stat_val & MIDNO ) == 0x0a) {
		//muic_CP_USB_set();
		muic_set_mode(MUIC_CP_USB);	// [email protected]
	}
	else if ((int_stat_val & MIDNO ) == 0x09) {
		//muic_CP_USB_set();
		muic_set_mode(MUIC_CP_USB);	// [email protected]
	}
#endif
#if 0
	// CHGDET=1?  :: HIGH CURRENT USB or TA?
	else if (int_stat_val & MCHGDET) {
		muic_distinguish_charger();
	}
#endif
	// VBUS=1?  :: TA or AP USB?
	else if (int_stat_val & MVBUS) {
		if (muic_device == MAX14526) {
			// COMP2 to H-Z / COMN1 to C1COMP (0x03=0x23)
			muic_i2c_write_byte_local(SW_CONTROL, 0x23);

			msleep(3);

			// Read STATUS_REG (0x05)
			muic_i2c_read_byte_local(STATUS, &reg_value);

			if (reg_value & 0x01 ) {
				// Dedicated Charger(TA) Detected
				// COMP2 to H-Z / COMN1 to H-Z (0x03=0x24)
				muic_i2c_write_byte_local(SW_CONTROL, DP_OPEN | DM_OPEN);

				charging_ic_set_ta_mode();

				muic_mode = MUIC_NA_TA;
				muic_set_mode(MUIC_NA_TA);		// [email protected] 20120502 MUIC re-work
				printk(KERN_WARNING "[MUIC] Charger detected\n");
			}
			else if (reg_value & 0x80 ) {
				// Dedicated Charger(TA) Detected
				muic_i2c_write_byte_local(SW_CONTROL, DP_OPEN | DM_OPEN);

				charging_ic_set_ta_mode();

				muic_mode = MUIC_NA_TA;
				muic_set_mode(MUIC_NA_TA);
				printk(KERN_WARNING "[MUIC] NA_TA Charger detected\n");
			}
			else if (reg_value & 0x40 ) {
				// Dedicated Charger(TA) Detected
				muic_i2c_write_byte_local(SW_CONTROL, DP_OPEN | DM_OPEN);

				charging_ic_set_ta_mode();

				muic_mode = MUIC_LG_TA;
				muic_set_mode(MUIC_LG_TA);
				printk(KERN_WARNING "[MUIC] LG_TA Charger detected\n");
			}
			else {	// USB Detected
// LGE_UPDATE_S 20110521 [[email protected]] block CP usb for commercial version
#if 0
				if (key_was_pressed == 2)
					//muic_CP_USB_set();
					muic_set_mode(MUIC_CP_USB);	// [email protected]
				else
#endif /* #if 0 */
// LGE_UPDATE_S 20110521 [[email protected]] block CP usb for commercial version
					//muic_AP_USB_set();
					muic_set_mode(MUIC_AP_USB);	// [email protected]
			}
		}
		else { 	// USB Detected
// LGE_UPDATE_S 20110521 [[email protected]] block CP usb for commercial version
#if 0
			if (key_was_pressed == 2)
				//muic_CP_USB_set();
				muic_set_mode(MUIC_CP_USB);	// [email protected]	
			else
#endif /* #if 0 */
// LGE_UPDATE_S 20110521 [[email protected]] block CP usb for commercial version
				//muic_AP_USB_set();
				muic_set_mode(MUIC_AP_USB);	// [email protected]
		}
	}
	else {
		// Accessory Not Supported
		muic_mode = MUIC_NONE;
	}

	key_was_pressed = 0;
}

s32 muic_device_detection(s32 upon_irq)
{
/* LGE_CHANGE_START 2011-03-16 [email protected] patch for Adb offline set and Mass Storage Driver detecting fail */    
	/* 20110113 [email protected] check muic driver init. state [START] */
	if(!muic_init_done){

		printk(KERN_WARNING "[MUIC] MUIC has not been initialized! Nothing will be done!!!.\n");
		return 0;
	}	
    /* 20110113 [email protected] check muic driver init. state [END] */
/* LGE_CHANGE_END 2011-03-16 [email protected] */
	// Read INT_STAT_REG (0x04)
	muic_i2c_read_byte_local(INT_STAT, &int_stat_val);
	printk(KERN_INFO "[MUIC] INT_STAT = %x\n", int_stat_val);

	switch (muic_mode)
	{
	case MUIC_NONE:
	case MUIC_UNKNOWN:
		muic_device_none_detect();
		break;

	// CP UART Mode
	case MUIC_CP_UART:
	case MUIC_AP_UART:
		if ((int_stat_val & MIDNO) == 0x0b) {
			muic_mode = MUIC_NONE;
		}
		else {
			muic_device_none_detect();
		}
		break;

	// TA Mode
	case MUIC_NA_TA:
	case MUIC_LG_TA:
	case MUIC_TA_1A:
	case MUIC_INVALID_CHG:
		if ((int_stat_val & MVBUS) == 0) {
			// Exit Charger Mode
			muic_mode = MUIC_NONE;
		}
		else {
			// Bug fix: charger detect interrupt 2 times
			set_wakelock(0);
		}
		break;

	// USB Mode
	case MUIC_AP_USB:
			android_USB_disconnect(); // for usb disconnect event
	case MUIC_CP_USB:
		if ((int_stat_val & MVBUS) == 0){
			// Exit USB Mode
			muic_mode = MUIC_NONE;
		}
		else {
			muic_device_none_detect();
		}
		break;

	default:
		muic_mode = MUIC_NONE;
		break;
	}

	if (muic_mode == MUIC_NONE) {
		muic_initialize(DEFAULT);
		printk(KERN_INFO "[MUIC] muic none\n");
		charging_ic_deactive();
		printk(KERN_INFO "[MUIC] charging_ic_deactive()\n");
		muic_set_mode(MUIC_NONE);		// [email protected] 20120502 MUIC re-work
	}

	charger_state_update_by_other();

	return 0;
}
EXPORT_SYMBOL(muic_device_detection);
/* LGE_UPDATE_E [[email protected]] 2010-12-01, modify detection scheme */

static void muic_wq_func(struct work_struct *muic_wq){
	s32 ret = 0;
	printk(KERN_INFO "[MUIC] muic_wq_func()\n");
	ret = muic_device_detection(UPON_IRQ);
}