s32 muic_ts5usba33402_detect_accessory(s32 upon_irq)
{
	s32 ret = 0;

	u8 int_stat_value;

	muic_mdelay(70);
		
	/* Read INT_STAT */
	ret = muic_i2c_read_byte(INT_STAT, &int_stat_value);
	printk("[MUIC] muic_ts5usba33402_detect_accessory, int_stat_value:0x%02x \n", int_stat_value);
	
	if (ret < 0) {
		printk(KERN_INFO "[MUIC] INT_STAT reading failed\n");
		muic_path = MUIC_UNKNOWN;
		charging_mode = muic_path;
		//set_muic_charger_detected();

		return ret;
	}

	/* Branch according to the previous muic_path */
	switch (muic_path) {
	/* 
	 * MUIC_UNKNOWN is reached in two cases both do not have nothing to do with IRQ.
	 * First, at the initialization time where the muic_path is not available yet.
	 * Second, whenever the current muic_path detection is failed.
	 */
	case MUIC_UNKNOWN :

	/*
	 * If the previous muic_path was MUIC_NONE,
	 * the only possible condition for a MUIC IRQ is plugging in an accessory.
	 */
	case MUIC_NONE :
		set_ts5usba33402_muic_path(int_stat_value);
		break;

	/* 
	 * If the previous muic_path was MUIC_NA_TA, MUIC_LG_TA, MUIC_TA_1A, MUIC_INVALID_CHG,
	 * MUIC_AP_UART, MUIC_CP_UART, MUIC_AP_USB, MUIC_OTG, or MUIC_CP_USB,
	 * the only possible condition for a MUIC IRQ is plugging out the accessory.
	 * 
	 * In this case, initialize MUIC and wait an IRQ.
	 * We don't need to wait 250msec because this is not an erronous case
	 * (we need to reset the facility to set STATUS for an erronous case and
	 * have to wait 250msec) and, if this is not an erronous case, the facility
	 * was already initialized at the system booting.
	 */
	case MUIC_AP_UART :
	case MUIC_CP_UART :
		if ((int_stat_value & IDNO) == IDNO_1011) {	        
			muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);	
	        muic_path = MUIC_NONE;
			charging_mode = CHARGING_NONE;
	    }       
		break;
		
	case MUIC_NA_TA :
	case MUIC_LG_TA :
	case MUIC_TA_1A :
	case MUIC_INVALID_CHG :
		if (((int_stat_value & VBUS) == 0) || ((int_stat_value & CHGDET) == 0)) {	         
	        muic_path = MUIC_NONE;
			charging_mode = CHARGING_NONE;
        }
		break;
		
	case MUIC_AP_USB :
	case MUIC_CP_USB :
		if ((int_stat_value & VBUS) == 0) {         
      		/* USB host removed */
      		muic_path = MUIC_NONE;
			charging_mode = CHARGING_NONE;
    	}
		break;

#if defined (CONFIG_CX2_MHL_TX_SII9244) 
	case MUIC_MHL :
		printk(KERN_WARNING "[MUIC] Detect step3  mhl \n");
		if ((int_stat_value & VBUS) == 0) {    
			MHL_On(0);
			muic_path = MUIC_NONE;
		}
		break;
#endif

		
	default :
		printk(KERN_WARNING "[MUIC] Failed to detect an accessory. Try again!");
		muic_path = MUIC_UNKNOWN;
		charging_mode = CHARGING_NONE;
		ret = -1;
	}	

	printk(KERN_WARNING "[MUIC] muic_ts5usba33402_detect_accessory, muic_path = %s\n", muic_path_str[muic_path]);

	if (muic_path == MUIC_UNKNOWN || muic_path == MUIC_NONE){
		muic_init_ts5usba33402(RESET);
		gpio_set_value(IFX_USB_VBUS_EN_GPIO, 0);
        printk(KERN_INFO "[MUIC] charging_ic_deactive()\n");
    }
	//set_muic_charger_detected();
	
	return ret;
} 
Ejemplo n.º 2
0
s32 muic_ts5usba33402_detect_accessory(s32 upon_irq)
{
	s32 ret = 0;

	u8 int_stat_value;
	
	/*
	 * Upon an MUIC IRQ (MUIC_INT_N falls),
	 * wait 70ms before reading INT_STAT and STATUS.
	 * After the reads, MUIC_INT_N returns to high
	 * (but the INT_STAT and STATUS contents will be held).
	 *
	 * Do this only if muic_ts5usba33402_detect_accessory() was called upon IRQ. 
	 */
	//if (upon_irq) {
		muic_mdelay(70);
	//}	

	
	/* Read INT_STAT */
	ret = muic_i2c_read_byte(INT_STAT, &int_stat_value);
	printk("[MUIC] muic_ts5usba33402_detect_accessory, int_stat_value:0x%02x \n", int_stat_value);

	if (ret < 0) {
		printk(KERN_INFO "[MUIC] INT_STAT reading failed\n");
		muic_mode = MUIC_UNKNOWN;
		charging_mode = CHARGING_UNKNOWN;
		//                                                                                 
		//set_muic_charger_detected();

		return ret;
	}
   // muic_set_device_none_detect(int_stat_value); 		  

	/* Branch according to the previous muic_mode */
	switch (muic_mode) {

	/* 
	 * MUIC_UNKNOWN is reached in two cases both do not have nothing to do with IRQ.
	 * First, at the initialization time where the muic_mode is not available yet.
	 * Second, whenever the current muic_mode detection is failed.
	 */
	case MUIC_UNKNOWN :

	/*
	 * If the previous muic_mode was MUIC_NONE,
	 * the only possible condition for a MUIC IRQ is plugging in an accessory.
	 */
	case MUIC_NONE :
		set_ts5usba33402_muic_mode(int_stat_value);
		break;

	/* 
	 * If the previous muic_mode was MUIC_NA_TA, MUIC_LG_TA, MUIC_TA_1A, MUIC_INVALID_CHG,
	 * MUIC_AP_UART, MUIC_CP_UART, MUIC_AP_USB, MUIC_OTG, or MUIC_CP_USB,
	 * the only possible condition for a MUIC IRQ is plugging out the accessory.
	 * 
	 * In this case, initialize MUIC and wait an IRQ.
	 * We don't need to wait 250msec because this is not an erronous case
	 * (we need to reset the facility to set STATUS for an erronous case and
	 * have to wait 250msec) and, if this is not an erronous case, the facility
	 * was already initialized at the system booting.
	 */
	case MUIC_AP_UART :
	case MUIC_CP_UART :
		if ((int_stat_value & IDNO) == IDNO_1011) {	        
			muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);
	        muic_mode = MUIC_NONE;			
			charging_mode = CHARGING_NONE;
	    }       

		break;
		
	case MUIC_NA_TA :
	case MUIC_LG_TA :
	case MUIC_TA_1A :
	case MUIC_INVALID_CHG :
		if (((int_stat_value & V_VBUS) == 0) || ((int_stat_value & CHGDET) == 0)) {	         
	        muic_mode = MUIC_NONE;				
			charging_mode = CHARGING_NONE;
        }

		break;
		
	case MUIC_AP_USB :
	case MUIC_CP_USB :
		/* 
		 * Check if V_VBUS == 0 && IDNO == 0x1011 (open).
		 * If so, it's MUIC_NONE.
		 * Otherwise, it's an erronous situation. MUIC_UNKNOWN.
		 */

        if((int_stat_value & IDNO) == IDNO_0010)
        {
            muic_mode = MUIC_CP_USB;
        }
        else if ((int_stat_value & IDNO) == IDNO_0100)
        {
            muic_mode = MUIC_CP_UART;
        }
		else if ((int_stat_value & V_VBUS) == 0) {         
      		/* USB Host Removed */
      		muic_mode = MUIC_NONE;				
			charging_mode = CHARGING_NONE;
    	}
		break;
#if defined(CONFIG_MHL_TX_SII9244)
	case MUIC_MHL :
			printk(KERN_WARNING "[MUIC] Detect step3  MHL \n");
			if ((int_stat_value & V_VBUS) == 0) {    
					MHL_On(0);
			muic_mode = MUIC_NONE;
			charging_mode = CHARGING_NONE;
		}
			break;
#endif
		
	default:
		printk(KERN_WARNING "[MUIC] Failed to detect an accessory. Try again!");
		muic_mode = MUIC_UNKNOWN;
		charging_mode = CHARGING_NONE;
		ret = -1;
		break;
	}	

	if(muic_mode == MUIC_UNKNOWN || muic_mode == MUIC_NONE){
		muic_init_ts5usba33402(RESET);
		gpio_set_value(IFX_USB_VBUS_EN_GPIO, 0);
        printk(KERN_INFO "[MUIC] charging_ic_deactive()\n");
    }
	//                                           
	//                                                                                                   

	printk( "[MUIC] muic_ts5usba33402_detect_accessory, muic_mode = %s (%d) \n", muic_mode_str[muic_mode], muic_mode);
	return ret;
}