Ejemplo n.º 1
0
void set_charging_current_sub(void)
{
#ifdef CONFIG_LGE_BLOCK_CHARGING_MODE
	if ( 0 == get_block_charging_state() ) {
		printk(KERN_INFO "%s: Block Charging State\n", __func__);
		return ;
	}
#endif

	switch( get_ext_pwr_type() ) {
		case NO_CABLE:
			charging_ic_active_default();
			break;
		case LT_CABLE_56K:
		case LT_CABLE_130K:
		case LT_CABLE_910K:
			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;
		case USB_CABLE:
		case ABNORMAL_USB_100MA:
		case ABNORMAL_USB_400MA:
			charging_ic_set_usb_mode();
			break;
	}
	printk("[charging_msg] %s, External Power Type %d, charging_ic_status %d \n", __FUNCTION__, get_ext_pwr_type(), charging_ic_status);
	return ;
}
Ejemplo n.º 2
0
ssize_t charging_ic_store_status(struct device *dev,
			  struct device_attribute *attr,
			  const char *buf,
			  size_t count)
{
	if(buf[0] == '0') {
		charging_ic_deactive();
	} else if(buf[0] == '1') {
		charging_ic_set_ta_mode();
	}
	return count;
}
Ejemplo n.º 3
0
void setting_for_factory_mode_hw_req(void)
{
#if 0 /* XXX_mbk */
	/* Battery FET OFF */
	lge_battery_fet_onoff(0);
#else
	/* HW요청사항...Battery가 있으면...2A가 아닌 960mA로 충전하도록
	   Charger IC가 2A로 충전을 계속하게 되면 버티지 못함. */
	if( check_battery_present() ) {
		printk(KERN_INFO "%s, Charger Current Setting TA mode from Factory Mode\n", __FUNCTION__);
		charging_ic_set_ta_mode();
	}
#endif
}
Ejemplo n.º 4
0
void setting_for_factory_mode_hw_req(void)
{
#if 0 /* XXX_mbk */
	/* Battery FET OFF */
	lge_battery_fet_onoff(0);
#else
	extern void dp3t_switch_ctrl(TYPE_DP3T_MODE mode);
	
	/* HW요청사항...Battery가 있으면...2A가 아닌 960mA로 충전하도록
	   Charger IC가 2A로 충전을 계속하게 되면 버티지 못함. */
	if( check_battery_present() ) {
		printk(KERN_INFO "%s, Charger Current Setting TA mode from Factory Mode\n", __FUNCTION__);
		charging_ic_set_ta_mode();
	}
#endif

	/* USB Switch to CP */
	dp3t_switch_ctrl(DP3T_CP_USB);
}
Ejemplo n.º 5
0
void rt9536_charging_enable(unsigned int set_current, unsigned int enable)
{
    if (enable)
    {
        if ( set_current == AC_CHARGER_CURRENT )
            charging_ic_set_ta_mode();
        else if ( set_current == USB_CHARGER_CURRENT )
            charging_ic_set_usb_mode();
        else
            charging_ic_active_default();

        printk("[charger_rt9536] :: %s, current(%d), enable(%d)\n", __func__, set_current, enable);
    }
    else
    {
        charging_ic_deactive();
        printk("[charger_rt9536] :: %s, enable(%d)\n", __func__, enable);        
    }
    
}
Ejemplo n.º 6
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 ;
}
Ejemplo n.º 7
0
/* LGE_UPDATE_S [[email protected]] 2010-12-01, modify detection scheme */
static void muic_device_none_detect(void)
{
	u8 reg_value;

    if ((key_col == 1) && (key_row == 1)) // Volume up
        key_was_pressed = 1;
    else if ((key_col == 1) && (key_row == 2)) // 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();
	}
	else 
/* LGE_CHANGE_E [[email protected]] 2011-01-06, CP retain mode */
#elif defined(USB_RETAIN) /* 2012.05.15, [email protected], USB retain mode. */
	if (usb_retained == CP_RETAINED)
	{
		muic_CP_USB_set();
	}
	else if (usb_retained == AP_RETAINED)
	{
		muic_AP_USB_set();
	}
    else 
#endif
	// IDNO=0100? 130Kohm :: CP UART MODE
	if(((int_stat_val & MIDNO) == 0x04)
			// LGE_CHANGE_S [[email protected]] 2011-02-08 for 130K and 100K and 300K ?�??? CP UART�??�정 {
			|| ((int_stat_val & MIDNO) == 0x03)
			|| ((int_stat_val & MIDNO) == 0x07)
			// LGE_CHANGE_E [[email protected]] 2011-02-08 }
			|| (hidden_menu_switching == 7)) {
		muic_CP_UART_set();
	}
	// 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();
		else
		{
			// START [email protected] 2011/04/03 LAB1_FW : STOP_ENTERING_EARLYSUSPEND_STATE for factory test {
			if( usb_swiched_thru_factory_cmd ) {
				printk(KERN_INFO "[MUIC] AP_USB because usb_swiched_thru_factory_cmd==1\n");
				muic_AP_USB_set();
			} 
			else 
			// END [email protected] 2011/04/03 LAB1_FW }
			{
				muic_CP_USB_set();
			}
		}
	}
	// 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();
	}
	else if ((int_stat_val & MIDNO ) == 0x09) {
		muic_CP_USB_set();
	}
#endif	
	// CHGDET=1?  :: HIGH CURRENT USB or TA?
	else if (int_stat_val & MCHGDET) {
		muic_distinguish_charger();
	}
	// 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(SW_CONTROL, 0x23);

			msleep(3);

			// Read STATUS_REG (0x05)
			muic_i2c_read_byte(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(SW_CONTROL, DP_OPEN | DM_OPEN);

				charging_ic_set_ta_mode();

				muic_mode = MUIC_NA_TA;
				printk(KERN_WARNING "[MUIC] Charger detected\n");
			}
			else {
				// USB Detected
				if (key_was_pressed == 2)
					muic_CP_USB_set();
				else
					muic_AP_USB_set();
			}
		}
		else {
			// USB Detected
			if (key_was_pressed == 2)
				muic_CP_USB_set();
			else {
				muic_AP_USB_set();
			}
		}
	}
	else {
		// Accessory Not Supported
		muic_mode = MUIC_NONE;
	}

	key_was_pressed = 0;
}
Ejemplo n.º 8
0
/* Distinguish charger type.
 * This function is called *ONLY IF* INT_STAT's CHGDET == 1, i.e., a charger is detected.
 *
 * Chargers becomes to use the default MUIC setting
 * because the detection always happens only after the MUIC_NONE mode
 * which leads the default MUIC setting.
 * Thus, we don't need to explictly set MUIC registers here.
 */
s32 muic_distinguish_charger(void){

	s32 ret = 0;

	/* Enable charger IC in TA mode */
	charging_ic_set_ta_mode();

	/* Connect AP UART to MUIC UART */
	dp3t_switch_ctrl(DP3T_AP_UART);

	/* 
	 *	LGE_UPDATE 20110425 [[email protected]] change IDNO for detecting LG_TA
	 *
	 *	IDNO == 0x05(0101) 180 KOhm. LG TA : Standard usb cable
	 *	IDNO == 0x06(0110) 240 KOhm. LG TA : Docomo accessaary usb cable
	 *	IDNO == 0x0b(1011) OPEN. TA charger
	 *	There is no ADC value of MUIC table for 220KOhm
	 * 	so, we need to double check 180 KOhm and 220 KOhm
	 */
	if ((int_stat_val & MIDNO) == 0x05 || (int_stat_val & MIDNO) == 0x06 || (int_stat_val & MIDNO) == 0x0b) {
		muic_mode = MUIC_LG_TA;
		printk(KERN_WARNING "[MUIC] muic_distinguish_charger(): MUIC_LG_TA\n");
		set_wakelock(0);
		return ret;
	}

	if (muic_device == MAX14526) {
		/* Prepare for reading charger type */
		ret = muic_i2c_write_byte(CONTROL_2, MINT_EN | MCHG_TYP);
		/* LGE_UPDATE_S [[email protected]] 2010-12-01, interrupt clear in TA detection */
		msleep(70);
		ret = muic_i2c_read_byte(INT_STAT, &status_val);
		/* LGE_UPDATE_E [[email protected]] 2010-12-01, interrupt clear in TA detection */
	}

	/* Read STATUS */
	ret = muic_i2c_read_byte(STATUS, &status_val);
	if (ret < 0) {
		printk(KERN_INFO "[MUIC] STATUS reading failed\n");
		muic_mode = MUIC_UNKNOWN;
		key_was_pressed = 0; // from HUB 
		set_wakelock(0);
		return ret;
	}

	printk(KERN_INFO "[MUIC] STATUS = %x\n", status_val);

	/* DCPORT == 1. Dedicated Charger */
	if ((status_val & MDCPORT) != 0) {
		muic_mode = MUIC_NA_TA;
		printk(KERN_WARNING "[MUIC] muic_distinguish_charger(): MUIC_NA_TA\n");
	}
	/* CHPORT == 1. HCHH */
	else if ((status_val & MCHPORT) != 0) {
		muic_mode = MUIC_HCHH;
		printk(KERN_WARNING "[MUIC] muic_distinguish_charger(): MUIC_HCHH\n");
	}
	/* DCPORT == 0 && CHPORT == 0. Definitely INVALID_CHG */
	else {
		muic_mode = MUIC_INVALID_CHG;
		printk(KERN_WARNING "[MUIC] muic_distinguish_charger(): MUIC_INVALID_CHG\n");
	}

	set_wakelock(0);
	return ret;
}
Ejemplo n.º 9
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);
}
Ejemplo n.º 10
0
static int set_battery_charging(struct twl4030_bci_device_info *di)
{
	int trickle_chg_max, trickle_chg_min, trickle_chg_timer_start;
	max8922_status chr_ic_status = get_charging_ic_status();
	
	if(di->battery_present == 0 || 						// No Battery State
		di->charge_rsoc == POWER_SUPPLY_TYPE_BATTERY) {	// No Charging Source
		start_monitor = 0;
		set_end_of_charge(0);
		set_charging_timer(0);
		return 0;
	}
	
	/*
	 * Recharging algorithm
     *  - High Temperature : up to 4.0V
     *  - Normal : up to 4.2V
     */
    // Set maximum charging voltage
    if((di->temp_C < TEMP_CRITICAL_LOWER ||
	   di->temp_C > TEMP_CRITICAL_UPPER) && // Critical Temperature! Must stop charging
	   di->temp_control != UNLIMITED_TEMP_VAL){ // 20120725, [email protected], Enable charging by fake mode.
		start_monitor = 0;
		set_end_of_charge(0);
		set_charging_timer(0);
		if (di->battery_present == 1)
        	charging_ic_deactive();
        return 0;
    } else if(di->temp_C < TEMP_LIMIT_LOWER ||
              di->temp_C > TEMP_LIMIT_UPPER) {	// Charging Limit
		trickle_chg_max = 4000;
		trickle_chg_timer_start = 3950;
		trickle_chg_min = 3900;
	} else {									// Normal Charging
		trickle_chg_max = 4220;					// to unintentional charging stop
		trickle_chg_timer_start = 4197;
		trickle_chg_min = 4140;
		if((di->previous_temp_C < TEMP_LIMIT_LOWER ||
		   di->previous_temp_C > TEMP_LIMIT_UPPER) &&
		   di->temp_control != UNLIMITED_TEMP_VAL) { // 20120725, [email protected], Enable charging by fake mode.
			start_monitor = 0;
			set_end_of_charge(0);
			set_charging_timer(0);
		}
	}

	// Deactive charger for protect overcharge & monitoring
	if(chr_ic_status != CHARGING_IC_DEACTIVE) {
		if(/*di->voltage_uV >= trickle_chg_max ||*/ charging_timeout() || end_of_charge) {
			// Battery Full Charged Once. Entering Trickle Charging Mode
			if(!charging_timeout())		// Do not stop charging when timeout occured
				charging_ic_deactive();	// It's not actually charged full.
			set_charging_timer(0);
			set_end_of_charge(0);
			if(start_monitor == 0) {
				printk(KERN_DEBUG "[Battery] Trickle Charging Start!\n");
				start_monitor = 1;
			}
		} else if(di->voltage_uV >= trickle_chg_timer_start) {
			set_charging_timer(1);
		}
	} else if(di->voltage_uV < trickle_chg_min) {	// active charger for recharging
		switch(di->charge_rsoc) {
			case POWER_SUPPLY_TYPE_MAINS:
				charging_ic_set_ta_mode();
				break;
			case POWER_SUPPLY_TYPE_USB:
				charging_ic_set_usb_mode();
				break;
			case POWER_SUPPLY_TYPE_UPS:
				charging_ic_set_factory_mode();
				break;
			default:
				break;
		}
	}
	return 0;
}
Ejemplo n.º 11
0
/* Distinguish charger type.
 * This function is called *ONLY IF* INT_STAT's CHGDET == 1, i.e., a charger is detected.
 *
 * Chargers becomes to use the default MUIC setting
 * because the detection always happens only after the MUIC_NONE mode
 * which leads the default MUIC setting.
 * Thus, we don't need to explictly set MUIC registers here.
 */
s32 muic_distinguish_charger(void){

	s32 ret = 0;

	/* Enable charger IC in TA mode */
	charging_ic_set_ta_mode();

	/* Connect CP UART signals to AP */
	//usif_switch_ctrl(USIF_DP3T);

	/* Connect AP UART to MUIC UART */
	//dp3t_switch_ctrl(DP3T_AP_UART);			// [email protected]

	/* IDNO == 0x05 180K. LG TA */
	if ((int_stat_val & MIDNO) == 0x05 || (int_stat_val & MIDNO) == 0x0b) {
		muic_mode = MUIC_LG_TA;
		muic_set_mode(MUIC_LG_TA);		// [email protected] 20120502 MUIC re-work
		printk(KERN_WARNING "[MUIC] muic_distinguish_charger(): MUIC_LG_TA\n");
		set_wakelock(0);
		return ret;
	}

	if (muic_device == MAX14526) {
		/* Prepare for reading charger type */
		ret = muic_i2c_write_byte_local(CONTROL_2, MINT_EN | MCHG_TYP);
		/* LGE_UPDATE_S [[email protected]] 2010-12-01, interrupt clear in TA detection */
		msleep(70);
		ret = muic_i2c_read_byte_local(INT_STAT, &status_val);
		/* LGE_UPDATE_E [[email protected]] 2010-12-01, interrupt clear in TA detection */
	}

	/* Read STATUS */
	ret = muic_i2c_read_byte_local(STATUS, &status_val);
	if (ret < 0) {
		printk(KERN_INFO "[MUIC] STATUS reading failed\n");
		muic_mode = MUIC_UNKNOWN;
		muic_set_mode(MUIC_UNKNOWN);		// [email protected] 20120502 MUIC re-work
		set_wakelock(0);
		return ret;
	}

	printk(KERN_INFO "[MUIC] STATUS = %x\n", status_val);

	/* DCPORT == 1. Dedicated Charger */
	if ((status_val & MDCPORT) != 0) {
		muic_mode = MUIC_NA_TA;
		muic_set_mode(MUIC_NA_TA);		// [email protected] 20120502 MUIC re-work
		printk(KERN_WARNING "[MUIC] muic_distinguish_charger(): MUIC_NA_TA\n");
	}
	/* CHPORT == 1. HCHH */
	else if ((status_val & MCHPORT) != 0) {
		muic_mode = MUIC_TA_1A;
		muic_set_mode(MUIC_TA_1A);		// [email protected] 20120502 MUIC re-work
		printk(KERN_WARNING "[MUIC] muic_distinguish_charger(): MUIC_TA_1A\n");
	}
	/* DCPORT == 0 && CHPORT == 0. Definitely INVALID_CHG */
	else {
		muic_mode = MUIC_INVALID_CHG;
		muic_set_mode(MUIC_INVALID_CHG);		// [email protected] 20120502 MUIC re-work
		printk(KERN_WARNING "[MUIC] muic_distinguish_charger(): MUIC_INVALID_CHG\n");
	}

	set_wakelock(0);
	return ret;
}
Ejemplo n.º 12
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 == 1) && (key_row == 1)) // Volume up
        key_was_pressed = 1;
    else if ((key_col == 1) && (key_row == 2)) // 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);
	}
	else 
/* 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);
		}
	}
    else 
#endif
	// IDNO=0100? 130Kohm :: CP UART MODE
	if(((int_stat_val & MIDNO) == 0x04)
			// LGE_CHANGE_S [[email protected]] 2011-02-08 for 130K and 100K and 300K ?�??? CP UART�??�정 {
			|| ((int_stat_val & MIDNO) == 0x03)
			|| ((int_stat_val & MIDNO) == 0x07)
			// LGE_CHANGE_E [[email protected]] 2011-02-08 }
			|| (hidden_menu_switching == 7)) {

		//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
		{
			// START [email protected] 2011/04/03 LAB1_FW : STOP_ENTERING_EARLYSUSPEND_STATE for factory test {
			if( usb_swiched_thru_factory_cmd ) {
				printk(KERN_INFO "[MUIC] AP_USB because usb_swiched_thru_factory_cmd==1\n");
				//muic_AP_USB_set();
                            muic_set_mode(MUIC_AP_USB);
			} 
			else 
			// END [email protected] 2011/04/03 LAB1_FW }
			{
				//muic_CP_USB_set();
				muic_set_mode(MUIC_CP_USB);
			}
		}
	}
	// 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	
	// CHGDET=1?  :: HIGH CURRENT USB or TA?
#if 0 //[120712-start] [email protected] when is high current input usb, for usb connected. 
	else if (int_stat_val & MCHGDET) {
		muic_distinguish_charger();
	}
#endif //[120712-end] [email protected] when is high current input usb, for usb connected. 

	// 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 {
				// USB Detected
				if (key_was_pressed == 2)
					//muic_CP_USB_set();
					muic_set_mode(MUIC_CP_USB);	// [email protected]
				else
					//muic_AP_USB_set();
					muic_set_mode(MUIC_AP_USB);	// [email protected]
			}
		}
		else {
//[120712-start] [email protected] when is high current input usb, for usb connected. 
			// Read STATUS_REG (0x05)
			muic_i2c_read_byte_local(STATUS, &reg_value);

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

			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
				if (key_was_pressed == 2)
						//muic_CP_USB_set();
						muic_set_mode(MUIC_CP_USB);	// [email protected]
				else {
						//muic_AP_USB_set();
						muic_set_mode(MUIC_AP_USB);	// [email protected]
				}
			}
//[120712-end] [email protected] when is high current input usb, for usb connected. 
		}
	}
	else {
		// Accessory Not Supported
		muic_mode = MUIC_NONE;
	}

	key_was_pressed = 0;
}