static ssize_t muic_set_reg_sel(struct device *dev,
					  struct device_attribute *attr,
					  const char *buf, size_t count)
{
	muic_data_t *pmuic = dev_get_drvdata(dev);
	int len = strlen(buf);
	unsigned int reg_base = 0, reg_num = 0;
	int ret = -EINVAL, i = 0;

#if 0 /* For the compatibility in 64 bit */
	pr_info("%s:%s -> %s(%d, %d)\n", MUIC_DEV_NAME, __func__,
		buf, count, len);
#endif
	if (len < 6) {
		ret = kstrtoint(buf, 0, &reg_base);
		if (ret) {
			pr_err("%s: Undefined Regs\n", __func__);
			goto err;
		}
		reg_num = 1;
	} else if (len < 10) {
		char *ptr;
		char reg_buf[8];

		strcpy(reg_buf, buf);
		ptr = strstr(reg_buf, "++");
		*ptr = 0x00;
		ret = kstrtoint(reg_buf, 0, &reg_base);
		if (ret) {
			pr_err("%s: Undefined Regs\n", __func__);
			goto err;
		}
		ret = kstrtoint(ptr + 2, 0, &reg_num);
		if (ret) {
			pr_err("%s: Undefined Regs\n", __func__);
			goto err;
		}
	} else {
		pr_err("%s: Undefined Regs\n", __func__);
		goto err;
	}

	pr_info(" (reg_base,reg_num) = (0x%02x,%d)\n", reg_base, reg_num);

	memset(reg_dump_buf, 0x00, sizeof(reg_dump_buf));

	while (reg_num--) {
		mutex_lock(&pmuic->muic_mutex);
		ret = muic_i2c_read_byte(pmuic->i2c, reg_base + i);
		mutex_unlock(&pmuic->muic_mutex);
		if (ret < 0) {
			pr_err("%s:%s err read %d\n", MUIC_DEV_NAME, __func__,
					reg_base);
			goto err;
		}
		pr_info(" [%02x] : %02x\n", reg_base, ret);

		sprintf(reg_dump_buf + strlen(reg_dump_buf),
			" [%02x] : %02x\n", reg_base + i++, ret);
	}

err:
	return count;
}
Пример #2
0
int muic_set_device_none_detect(struct i2c_client *client,
		unsigned char int_stat_value)
{
//	s32 loop = 0;
	unsigned char charger_value = 0;

	unsigned char stat_value = 0;
//	unsigned char Accessory_value = 0;
//	unsigned char orginal_value = 0;
	unsigned char id_register_value = 0;

//	int i;

	id_register_value = 0x0f & int_stat_value;

	dev_info(&client->dev, "muic: %s, muic_retain_mode:%d, Int_Status:%d, INT_STATUS:0x%2x\n",
		__func__,muic_retain_mode, Int_Status, int_stat_value);


	if(int_stat_value & VBUS) {// VBUS  = High
		dev_info(&client->dev, "muic: %s: VBUS is High....\n", __func__);

		if(muic_process_retention_mode(client))
			return 0;


		if(Second_Int == tsu5611_process_reset_muic(client))
			return 0;


		if( (int_stat_value & CHGDET) || (charger_value & CHPORT))
		{
			dev_info(&client->dev, "muic: Charger detection....\n");
			muic_i2c_write_byte(client, CONTROL_2, 0x02);

			mdelay(250); // if charger type then waiting 250ms

			muic_i2c_read_byte(client, STATUS, &charger_value); // 06H register read
			muic_i2c_read_byte(client, INT_STATUS1, &stat_value);
			dev_info(&client->dev, "muic: STATUS register:0x%x, INT_STATUS1 register:0x%x\n",
				charger_value, stat_value);

			muic_set_charger_mode(client, charger_value);
//			Int_Status = First_Int;
		}else if((id_register_value == IDNO_0010) // 56k + VBUS
			|| (id_register_value == IDNO_1010) // 910k + VBUS
			|| (id_register_value == IDNO_1001)) // 620k + VBUS
		{
			muic_set_mode(MUIC_CP_USB);
		}else if(id_register_value == IDNO_0100){
			muic_set_mode(MUIC_CP_UART);
		}else if(IDNO_0000 ==id_register_value){
			muic_set_mode(MUIC_MHL);

#if 0
		}else if(0){
			muic_set_mode(MUIC_AP_UART);
#endif
		}else{
			muic_set_mode(MUIC_AP_USB);
#if 0
		}else{
Пример #3
0
int muic_set_device_none_detect(struct i2c_client *client,unsigned char int_stat_value)
{
//	s32 loop = 0;
	unsigned char charger_value = 0;

//	unsigned char stat_value = 0;
//	unsigned char Accessory_value = 0;
//	unsigned char orginal_value = 0;
	unsigned char id_register_value = 0;

//	int i;

	id_register_value = 0x0f & int_stat_value;

	dev_info(&client->dev, "muic: %s, muic_retain_mode:%d, Int_Status:%d, INT_STATUS:0x%2x\n",
		__func__,muic_retain_mode, Int_Status, int_stat_value);


	if(int_stat_value & VBUS) 
	{// VBUS  = High
		dev_info(&client->dev, "muic: %s: VBUS is High.... id_register_value:%d\n", __func__,id_register_value);

		if(muic_process_retention_mode(client))
			return 0;

		//if(Second_Int == max14526_process_reset_muic(client))
			//return 0;

		if(id_register_value == IDNO_0010 /*56k + VBUS*/)
		{
			muic_set_mode(MUIC_CP_USB);
		}
		else if(id_register_value == IDNO_1010 /*910k + VBUS*/)
		{
			muic_set_mode(MUIC_CP_USB);
		}
		else if(id_register_value == IDNO_1001 /*620k + VBUS*/)
		{
			muic_set_mode(MUIC_CP_USB);
		}
		else if(id_register_value == IDNO_0100)/*130k + VBUS*/
		{
			muic_set_mode(MUIC_CP_UART);
		}
#if defined(CONFIG_MHL)	
		else if(id_register_value==IDNO_0000)
		{
			muic_set_mode(MUIC_MHL);
		}
#endif
		else if(id_register_value == IDNO_0101)/*180k + VBUS LG proprietary TA Detected*/
		{
			//muic_set_mode(MUIC_LG_TA);
			muic_set_mode(MUIC_AP_USB);//lg usb calble\C0\C7 int_stat_value =0x15 \B7\CE \B5\BF\C0۵Ǿ\EE, \C0Ϲ\DD usb cable\B7\CE \BC\F6\C1\A4 \C7\D4.
		}
		else// if(charger_value & CHPORT)
		{
			dev_info(&client->dev, "muic: Charger detection....\n");
			
			muic_i2c_write_byte(client,SW_CONTROL, COMP2_TO_HZ | COMN1_TO_C1COMP);
			//muic_mdelay(2);//mdelay(250); // if charger type then waiting 250ms
			//muic_i2c_read_byte(client, INT_STAT, &stat_value);
			muic_i2c_read_byte(client,STATUS, &charger_value);
			dev_info(&client->dev, "muic: charger_value :0x%x\n",charger_value);
			//muic_set_charger_mode(client, charger_value);

			//else if( (stat_value & CHGDET)&&((id_register_value & IDNO) == IDNO_1011))//stat_value==0x9B \C0Ϲ\DD \C3\E6\C0\FC\B1\E2
#ifdef CONFIG_FORCE_FAST_CHARGE
			if((int_stat_value & CHGDET) || (force_fast_charge != 0))
			{
				muic_i2c_write_byte(client,SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);
				muic_set_mode(MUIC_LG_TA);
			}
#else
			if(int_stat_value & CHGDET)
			{
				muic_i2c_write_byte(client,SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);
				muic_set_mode(MUIC_LG_TA);
			}
#endif
			else if (charger_value & DCPORT)
			{
				/* Not used actually. Special TA for North America.*/
				muic_i2c_write_byte(client,SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);
				muic_set_mode(MUIC_NA_TA);
			} 
			else if (charger_value & CHPORT)
			{
				//muic_i2c_write_byte(client,SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);
				muic_set_mode(MUIC_AP_USB);
			}
			else if (charger_value & C1COMP) 
			{//MUIC_LG_TA , CHARGING_LG_TA
				muic_i2c_write_byte(client,SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);
				muic_set_mode(MUIC_LG_TA);
				//muic_path = MUIC_LG_TA;
				//charging_mode = CHARGING_LG_TA;
			}
			else //stat_value==0x1B \C0Ϲ\DD UBS\C4\C9\C0̺\ED
			{
				//set_max14526_ap_usb_mode();
				muic_set_mode(MUIC_AP_USB);
				//muic_path = MUIC_AP_USB;
				//charging_mode = CHARGING_USB;
			}
		}
	}
	else
	{
		muic_set_mode(MUIC_NONE);
	}

	return 0;
}
Пример #4
0
s32 muic_max14526_detect_accessory(struct i2c_client *client, s32 upon_irq)
{
	s32 ret = 0;
	s32 loop = 0;
	u8 int_stat_value=0;
	
	TYPE_MUIC_MODE muic_mode = muic_get_mode();
	struct ts5usb_device *dev = i2c_get_clientdata(client);
	/*
	 * Upon an MUIC IRQ (MUIC_INT_N falls),
	 * wait 70ms before reading INT_STATUS1 and STATUS.
	 * After the reads, MUIC_INT_N returns to high
	 * (but the INT_STATUS1 and STATUS contents will be held).
	 *
	 * Do this only if muic_max14526_detect_accessory() was called upon IRQ.
	 */
	if (upon_irq) {
		mdelay(70);
	}

	/* Read INT_STATUS1 */
	ret = muic_i2c_read_byte(client, INT_STAT, &int_stat_value);
	dev_info(&client->dev, "muic: %s: int_stat_value:0x%x :%d\n", __func__,	int_stat_value, muic_mode);

	if (ret < 0) {
		dev_info(&client->dev, "muic: INT_STATUS1 reading failed\n");
		muic_set_mode(MUIC_UNKNOWN);

		return ret;
	}

	switch (muic_mode) 
	{/* Branch according to the previous muic_mode */
		case MUIC_UNKNOWN :
		case MUIC_NONE :
			muic_set_device_none_detect(client, int_stat_value);
			break;

		case MUIC_AP_UART :
		case MUIC_CP_UART :
			dev_info(&client->dev, "muic: MUIC_AP_UART || MUIC_CP_UART\n");
			if(!(int_stat_value & VBUS)&&(IDNO_0010 == (int_stat_value & 0x0f)))
			{
				muic_set_mode(MUIC_CP_USB);
			} 
			else if (!(int_stat_value & VBUS))
			{
				muic_i2c_write_byte(client, SW_CONTROL, DP_UART | DM_UART);
				muic_set_mode(MUIC_NONE);
			}
			else
			{
				dev_info(&client->dev, "UART is not removed\n");
			}
			break;

		case MUIC_NA_TA :
		case MUIC_LG_TA :
		case MUIC_TA_1A :
		case MUIC_INVALID_CHG :
			dev_info(&client->dev, "muic: Detect step2\n");
			if (((int_stat_value & VBUS) == 0) ||((int_stat_value & CHGDET) == 0)) 
			{
				muic_set_mode(MUIC_NONE);
			}
			else
			{
				dev_info(&client->dev, "TA is not removed\n");
			}
			break;

		case MUIC_AP_USB :
			/* USB Host Removed */
			if((int_stat_value & VBUS) == 0)
			{
			android_USB_disconnect();// for usb disconnect event
			muic_set_mode(MUIC_NONE);
			}
			else
			{
				dev_info(&client->dev, "AP USB is not removed\n");
			}
			break;
			
		case MUIC_CP_USB :
			if((int_stat_value & VBUS) == 0)
			{
				muic_set_mode(MUIC_NONE);
			}
			else
			{
				dev_info(&client->dev, "CP USB is not removed\n");
			}
			break;
			
#if defined(CONFIG_MHL_TX_SII9244) || defined(CONFIG_MHL_TX_SII9244_LEGACY)
		case MUIC_MHL :
			dev_info(&client->dev, "muic: Detect step3  mhl \n");
			if ((int_stat_value & VBUS) == 0) {
				//MHL_On(0);
				muic_set_mode(MUIC_NONE);
			}
			break;
#endif
		default:
			dev_info(&client->dev, "muic: Failed to detect an accessory. Try again!");
			muic_set_mode(MUIC_UNKNOWN);
			ret = -1;
			break;
	}

	muic_mode = muic_get_mode();
	dev_info(&client->dev, "muic: muic_detection_mode=%d \n", muic_mode);

	if (muic_mode == MUIC_UNKNOWN || muic_mode == MUIC_NONE) {
#if defined(CONFIG_MHL) && defined(CONFIG_MHL_TX_MUIC_BUG_FIX)
		/* SJIT 2012-01-27 [[email protected]] P940 GB
		 * max14526 300ms delay side effect bug fixed test code
		 */
		if (Int_Status == Second_Int) {
			if (!gpio_get_value(dev->gpio_mhl)) {
				dev_info(&client->dev, "muic: wait for mhl switch completed\n");
				muic_init_max14526(client, DEFAULT);
				gpio_set_value(dev->gpio_ifx_vbus, 0);
			}
			else {
				dev_info(&client->dev, "muic: mhl switch not completed\n");
				while (!gpio_get_value(dev->gpio_mhl)) {
					udelay(500);
					muic_set_mode(MUIC_MHL);
//					MHL_On(0);
				}
				dev_info(&client->dev, "muic: mhl switch completed\n");
				muic_init_max14526(client, DEFAULT);
				gpio_set_value(dev->gpio_ifx_vbus, 0);
			}
		}
		else {
			muic_init_max14526(client, DEFAULT);
			gpio_set_value(dev->gpio_ifx_vbus, 0);
		}
#else
		muic_init_max14526(client, RESET);
		gpio_set_value(IFX_USB_VBUS_EN_GPIO, 0);
		//charging_ic_deactive();
		dev_info(&client->dev, "muic: charging_ic_deactive()\n");
#endif
	}

// LGE_CHANGES_S [[email protected]] 2012-03-19
#if defined(CONFIG_MAX8971_CHARGER)
	        if(muic_mode == MUIC_NA_TA || muic_mode == MUIC_LG_TA || muic_mode == MUIC_TA_1A)
		{
		        printk("[MUIC] max8971_start_charging TA\n");
		        max8971_start_charging(900);
									         }
		else if(muic_mode == MUIC_AP_USB)
		{
		        printk("[MUIC]max8971_start_charging USB\n");
		        max8971_start_charging(500);
										        }
		/* else if( muic_mode == MUIC_CP_USB || muic_mode ==  MUIC_CP_UART)
		{
		        printk("[MUIC] max8971_start_charging Factory\n");
		        max8971_start_charging(1550);
		}
		  */
		else if( muic_mode == MUIC_CP_USB )
		{
		 //printk("[MUIC] max8971_stop due to MUIC_CP_USB mode \n");
		        printk("[MUIC] max8971_start_charging Factory MUIC_CP_USB \n");
		        // max8971_start_charging(1550);
		        // max8971_stop_charging();
		        max8971_start_Factory_charging();
		}
		else if(  muic_mode ==  MUIC_CP_UART)
		{
		         printk("[MUIC] max8971_start_charging Factory MUIC_CP_UART \n");
	                //printk("[MUIC] max8971_stop due to MUIC_CP_UART mode \n");
	                // max8971_stop_charging();
	                // max8971_start_charging(1550);
	                 max8971_start_Factory_charging();
	        }
	        else if( muic_mode == MUIC_MHL)
	        {
	                printk("[MUIC] max8971_start_charging MHL\n");
	                max8971_start_charging(400);
	        }
	        else if( muic_mode == MUIC_NONE)
	        {
	                printk("[MUIC] max8971_stop_charging\n");
	                max8971_stop_charging();
		}
		else
		       printk("[MUIC] can not open muic mode\n");
		// LGE_CHANGES_E [[email protected]] 2012-03-19
#endif
	return ret;
}
Пример #5
0
s32 muic_max14526_detect_accessory(s32 upon_irq)
{
	s32 ret = 0;
	int loop = 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_max14526_detect_accessory() was called upon IRQ. */
	if (upon_irq) { 
		for (; loop < 250; loop++)
			muic_udelay(1000);
	}
	
	/* Reads INT_STAT */
	ret = muic_i2c_read_byte(INT_STAT, &int_stat_value);
	
	if (ret < 0) {
		printk(KERN_INFO "[chahee.kim] INT_STAT reading failed\n");
		muic_mode = MUIC_UNKNOWN;
		return ret;
	}
	
    printk(KERN_INFO "[chahee.kim] IDNO = %d\n", (int_stat_value & IDNO));
  
  	muic_mode = int_stat_value & IDNO;
	/* Branches 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_max14526_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_NA_TA:
	case MUIC_TA_1A:
	case MUIC_INVALID_CHG :
		if ((int_stat_value & VBUS) == 0) {		
			// Exit Charger Mode
			muic_mode = MUIC_NONE;
		}else{		
  		     set_max14526_muic_mode(int_stat_value);           
		}
		
		break;
		
	case MUIC_LG_TA :
		printk(KERN_WARNING "[chahee.kim] LG_TA");
		if ((int_stat_value & CHGDET) == 0) {		
			muic_mode = MUIC_NONE;				
		}
		else {		
  		     set_max14526_muic_mode(int_stat_value);           
		}
	
	
		break;
		
	case MUIC_AP_UART :
		if ((int_stat_value & IDNO) == IDNO_1011) {								
			/* Exit Factory Mode */
			muic_mode = MUIC_NONE;
		}
		else {
  		     set_max14526_muic_mode(int_stat_value);           
		}
		break;	
	case MUIC_AP_USB :
		if ((int_stat_value & VBUS) == 0) {
			/* USB Host Removed */
			muic_mode = MUIC_NONE;		
		}else{		
  		     set_max14526_muic_mode(int_stat_value);           
		}
		break;
		
	default:
		printk(KERN_WARNING "[chahee.kim] Failed to detect an accessory. Try again!\n");
#ifndef CHARGER_TEST
		lge_charger_disable();
#endif
		muic_mode = MUIC_UNKNOWN;
		ret = -1;
		break;
	}	

	
	printk(KERN_WARNING "[chahee.kim] muic_max14526_detect_accessory, muic_mode = %d \n", muic_mode );

	//if (muic_mode == MUIC_UNKNOWN || muic_mode == MUIC_NONE) {
	//	muic_init_max14526(DEFAULT);
       // printk(KERN_INFO "[chahee.kim] charging_ic_deactive()\n");
    //}

	return ret;
}
Пример #6
0
s32 muic_max14526_detect_accessory(s32 upon_irq)
{
	s32 ret = 0;

	u8 int_stat_value;

	/* For detecting time */
	muic_mdelay(250);
		
	/* Reads INT_STAT */
	ret = muic_i2c_read_byte(muic_client,INT_STAT, &int_stat_value);
	printk(KERN_WARNING "[MUIC] muic_max14526_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 = CHARGING_UNKNOWN;
		//LGE_CHANGE_S [[email protected]]  let charger know muic detected charger type..
		//set_muic_charger_detected();
		return ret;
	}
	
    /* Branches 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_max14526_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_NA_TA:
	case MUIC_TA_1A:
	case MUIC_INVALID_CHG :
	case MUIC_LG_TA :
	case MUIC_AP_UART :
	case MUIC_CP_UART :
	case MUIC_AP_USB :
	case MUIC_CP_USB :
		if ((int_stat_value & VBUS) != 0) {
			set_max14526_muic_path(int_stat_value);
		} else if ((int_stat_value & IDNO) == IDNO_1011) {
			charging_mode = CHARGING_NONE;
			muic_path = MUIC_NONE;
		} else
			set_max14526_muic_path(int_stat_value);
		break;
		
	default :
		printk(KERN_WARNING "[MUIC] Failed to detect an accessory. Try again!");
		muic_path = MUIC_UNKNOWN;
		charging_mode = CHARGING_UNKNOWN;
		ret = -1;
	}	
	
	printk(KERN_WARNING "[MUIC] muic_max14526_detect_accessory, muic_path = %s, charing = %s\n", 
		   muic_path_str[muic_path], charging_mode_str[charging_mode]);

	if (muic_path == MUIC_UNKNOWN || muic_path == MUIC_NONE) {
		muic_init_max14526(RESET);
		gpio_set_value(IFX_USB_VBUS_EN_GPIO, 0);
        printk(KERN_INFO "[MUIC] charging_ic_deactive()\n");
    }
	
	//LGE_CHANGE_S [[email protected]]  let charger know muic detected charger type..
	//set_muic_charger_detected();
	return ret;
}
Пример #7
0
s32 muic_max14526_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_max14526_detect_accessory() was called upon IRQ. */
	muic_mdelay(250);
	
	/* Reads INT_STAT */
	ret = muic_i2c_read_byte(INT_STAT, &int_stat_value);
	printk(KERN_WARNING "[MUIC] muic_max14526_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;
		return ret;
	}
    	//ret = muic_i2c_write_byte(CONTROL_2, 0x00); //interrupt masked by [email protected] for debugging
  	//muic_mode = int_stat_value & IDNO;

	//set_max14526_device_none_detect(int_stat_value);		   

	/* Branches 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_max14526_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_NA_TA:
	case MUIC_TA_1A:
	case MUIC_INVALID_CHG :
	case MUIC_LG_TA :
	case MUIC_AP_UART :
	case MUIC_CP_UART :
	case MUIC_AP_USB :
	case MUIC_CP_USB :
		if ((int_stat_value & V_VBUS) != 0) {					// V_VBUS == 1
			set_max14526_muic_mode(int_stat_value);
		} else if ((int_stat_value & IDNO) == IDNO_1011) {	// V_VBUS == 0
			charging_mode = CHARGING_NONE;
			muic_mode = MUIC_NONE;
#ifdef COFIG_MACH_STAR_SU660
			printk(KERN_INFO "[******MUIC*********] VBUS NONE UNPLUG\n");
#endif
		} else
			set_max14526_muic_mode(int_stat_value);
		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_UNKNOWN;
		ret = -1;
		break;
	}	

	
	printk(KERN_WARNING "[MUIC] muic_max14526_detect_accessory, muic_mode = %s (%d) \n", muic_mode_str[muic_mode], muic_mode );

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

	// LGE_UPDATE [email protected] [[ 4 charger
	//muic_send_cable_type(muic_mode);	//[[email protected]] - charger type is now sent by muic.c part.

	return ret;
}
Пример #8
0
void set_max14526_muic_mode(unsigned char int_stat_value)
{
	unsigned char reg_value;
	
	printk(KERN_WARNING "[chahee.kim] set_max14526_muic_mode, "
			"int_stat_value = %x \n", int_stat_value);

	if (int_stat_value & CHGDET) {
		set_max14526_charger_mode(int_stat_value);
#ifndef CHARGER_TEST
		lge_charger_ta_mode_enable();
#endif
	} 
	else if (int_stat_value & VBUS) {
		if ((int_stat_value & IDNO) == IDNO_0101) {
			set_max14526_ap_usb_mode();
#ifndef CHARGER_TEST
			lge_charger_usb_mode_enable();
#endif
		} 
		else {
			/* Standard USB Host Detected (0x03=0x23) */
			muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_C1COMP);

			muic_udelay(1000);

			/* Read Status Reigster(0x05) */
			muic_i2c_read_byte(STATUS, &reg_value);

			if (reg_value & C1COMP) {
				/* Charger Detected COMP2/COMN1 to H-Z (0x03=0x24) */
				muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);
				/* Dedicated Charger(TA) Detected */
				muic_mode = MUIC_NA_TA;
			} 
			else {
				/* Turn on USB switches */
				set_max14526_ap_usb_mode();
#ifndef CHARGER_TEST
				lge_charger_usb_mode_enable();
#endif
			}
		}
	} 
	else if ((int_stat_value & IDNO) == IDNO_0010) {
		//set_max14526_cp_usb_mode();
		set_max14526_ap_uart_mode();
#ifndef CHARGER_TEST
		lge_charger_disable();
#endif
	}
	else if ((int_stat_value & IDNO) == IDNO_0101) {
		set_max14526_ap_uart_mode();
#ifndef CHARGER_TEST
		lge_charger_disable();
#endif
	} 
	else {
		/* Accessory Not Supported */
		muic_mode = MUIC_NONE;
		muic_init_max14526(DEFAULT);
#ifndef CHARGER_TEST
		lge_charger_disable();
#endif
	}
}
Пример #9
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;
} 
Пример #10
0
void set_max14526_muic_mode(unsigned char int_stat_value)
{
	unsigned char reg_value;
	
	printk(KERN_WARNING "[MUIC] set_max14526_muic_mode, int_stat_value = 0x%02x \n", int_stat_value);

	//[[email protected]] - Cosmo MUIC detection code
	if (int_stat_value & V_VBUS) {
#if 0
		if ((int_stat_value & IDNO) == IDNO_0010 || 
			(int_stat_value & IDNO) == IDNO_1001 ||
			(int_stat_value & IDNO) == IDNO_1010) {
			set_max14526_cp_usb_mode();
			muic_mode = MUIC_CP_USB;
			charging_mode = CHARGING_FACTORY;
		} 
#else
        if ((int_stat_value & IDNO) == IDNO_1001 || 
			(int_stat_value & IDNO) == IDNO_1010) {
			set_max14526_cp_usb_mode();
			muic_mode = MUIC_CP_USB;
			charging_mode = CHARGING_FACTORY;
		} else if ((int_stat_value & IDNO) == IDNO_0010) {
#ifdef V56K_CONVERT_CP_USB_TO_AP_UART		
			set_max14526_ap_uart_mode();
			muic_mode = MUIC_AP_UART;
#else
			set_max14526_cp_usb_mode();
			muic_mode = MUIC_CP_USB;
#endif
			charging_mode = CHARGING_FACTORY;
		}
#endif
        else if ((int_stat_value & IDNO) == IDNO_0100) {
			set_max14526_cp_uart_mode();
			muic_mode = MUIC_CP_UART;
			charging_mode = CHARGING_FACTORY;
#if defined(CONFIG_MHL_TX_SII9244)
		} else if ((int_stat_value & IDNO) == IDNO_0000) {	//[[email protected]] - added MHL to Cosmo base
			muic_set_mhl_mode_detect();
			muic_mode = MUIC_MHL;
			charging_mode = CHARGING_USB;
#endif
		} else if (int_stat_value & CHGDET) {
#ifdef CONFIG_MACH_STAR_SU660
			printk("[****MUIC****] Detect Charger CHGDET!!!!");
			muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);
			
			muic_i2c_write_byte(CONTROL_1,ID_200 | ADC_EN  | CP_EN );
#else
			muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);
#endif
			muic_mode = MUIC_LG_TA;
			charging_mode = CHARGING_LG_TA;
		} else {
			muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_C1COMP);

			muic_mdelay(2);

			muic_i2c_read_byte(STATUS, &reg_value);

			if (reg_value & C1COMP) {
#ifdef CONFIG_MACH_STAR_SU660
				printk("[****MUIC****] Detect Charger C1COMP!!!!");
					muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);
				
				muic_i2c_write_byte(CONTROL_1,ID_200 | ADC_EN  | CP_EN );
				muic_i2c_write_byte(CONTROL_2, INT_EN);				
#else
				muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);
#endif
				muic_mode = MUIC_LG_TA;
				charging_mode = CHARGING_LG_TA;
			} else {
				set_max14526_ap_usb_mode();
				muic_mode = MUIC_AP_USB;
				charging_mode = CHARGING_USB;
			}
		}
	} else {
		if ((int_stat_value & IDNO) == IDNO_0010) {
			set_max14526_ap_uart_mode();
			muic_mode = MUIC_AP_UART;
			charging_mode = CHARGING_NONE;
		} else if ((int_stat_value & IDNO) == IDNO_0100) {
			set_max14526_cp_uart_mode();
			muic_mode = MUIC_CP_UART;
			charging_mode = CHARGING_NONE;
		} else {
			muic_mode = MUIC_UNKNOWN;
			charging_mode = CHARGING_NONE;
		}
	}
#if 0 //[[email protected]] - X3 original code
		if(retain_mode  == BOOT_CP_USB){
			set_max14526_cp_usb_mode_detect();
		}if ((int_stat_value & IDNO) == IDNO_0100 || (int_stat_value == 0x11)) { /* 0x11 for Special Test with MIC */  
			/* IDNO=0100? 130Kohm :: UART_MODE */
			set_max14526_cp_uart_mode_detect();
		} else if ((int_stat_value & IDNO ) == IDNO_0010) {
			/* IDNO=0010? 56Kohm  :: USB_MODE */
			set_max14526_ap_uart_mode_detect();
	#if defined(CONFIG_MHL_TX_SII9244)
		} else if (int_stat_value == 0x10) {
			/* IDNO=0000? 0Kohm  :: MHL_MODE */
			muic_set_mhl_mode_detect();    
	#else		
		} else if ((int_stat_value == 0x11) || (int_stat_value == 0x10)) {
	    	//Set_MAX14526_SpecialTest_Mode_Detect();
	#endif//
		} else if ((int_stat_value & IDNO) == IDNO_1010) {
			set_max14526_cp_usb_mode_detect();
		} else if (int_stat_value & CHGDET) {
			/* CHGDET=1? */
			set_max14526_charger_detect(int_stat_value);
		} else if (int_stat_value & V_VBUS) {
			/* V_VBUS=1? */

			/* Standard USB Host Detected (0x03=0x23) */
			muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_C1COMP);

			muic_udelay(1000);

			/* Read Status Reigster(0x05) */
			muic_i2c_read_byte(STATUS, &reg_value);

			if (reg_value & C1COMP) {
				/* Charger Detected COMP2/COMN1 to H-Z (0x03=0x24) */
				muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);
				/* Dedicated Charger(TA) Detected */
				muic_mode = MUIC_NA_TA;
			} else {
				/* Turn on USB switches */
	#if defined(CONFIG_MHL_TX_SII9244)
				if ((int_stat_value & IDNO ) == IDNO_0000) {
						muic_set_mhl_mode_detect(); 					
				} else {
						///* Standard USB Host Detected (0x03=0x23) */							
				set_max14526_ap_usb_mode_detect();
				muic_mode = MUIC_AP_USB;
			}
	#else
	            set_max14526_ap_usb_mode_detect();
				muic_mode = MUIC_AP_USB;
	#endif//
			}
		} else if ((int_stat_value & IDNO) == IDNO_0001) { 
			/* Vidoe Cable 24k registor Detected - No TV Attached */
			//muic_mode = DEVICE_VIDEO_CABLE_NO_LOAD;
		} else if ((int_stat_value & IDNO) == IDNO_0000 ) {
				muic_mode = MUIC_NONE;
		} else {
			/* Accessory Not Supported */
			muic_mode = MUIC_NONE;
		}
#endif
}
Пример #11
0
void set_ts5usba33402_muic_mode(unsigned char int_stat_value)
{
	gpio_set_value(GPIO_CP_UART_SW, 0);
	gpio_set_value(GPIO_CP_USB_VBUS_EN, 0);
#if defined(CONFIG_LU6500)
	muic_i2c_write_byte(SW_CONTROL, DP_OPEN | DM_OPEN);
#else
	muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);
#endif	
	muic_i2c_write_byte(CONTROL_1, ID_200 | SEMREN | CP_EN);

	muic_mdelay(10);

	if (int_stat_value & V_VBUS) {
		if ((int_stat_value & IDNO) == IDNO_0010 || 
			(int_stat_value & IDNO) == IDNO_1001 ||
			(int_stat_value & IDNO) == IDNO_1010) {
			set_ts5usba33402_cp_usb_mode();
			muic_mode = MUIC_CP_USB;
			charging_mode = CHARGING_FACTORY;
		} else if ((int_stat_value & IDNO) == IDNO_0100) {
			set_ts5usba33402_cp_uart_mode();
			muic_mode = MUIC_CP_UART;
			charging_mode = CHARGING_FACTORY;
#if defined(CONFIG_MHL_TX_SII9244)
		} else if ((int_stat_value & IDNO) == IDNO_0000) {	//                                               
			muic_set_mhl_mode_detect();
			muic_mode = MUIC_MHL;
			charging_mode = CHARGING_USB;
#endif
		} else if (int_stat_value & CHGDET) {
			muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);
			muic_mode = MUIC_LG_TA;
			charging_mode = CHARGING_LG_TA;
		} else {
			set_ts5usba33402_ap_usb_mode();
			muic_mode = MUIC_AP_USB;
			charging_mode = CHARGING_USB;
		}
	} else {
		if ((int_stat_value & IDNO) == IDNO_0010) {
			set_ts5usba33402_ap_uart_mode();
			muic_mode = MUIC_AP_UART;
			charging_mode = CHARGING_NONE;
		} else if ((int_stat_value & IDNO) == IDNO_0100) {
			set_ts5usba33402_cp_uart_mode();
			muic_mode = MUIC_CP_UART;
			charging_mode = CHARGING_NONE;
		} else {
			muic_mode = MUIC_UNKNOWN;
			charging_mode = CHARGING_NONE;
		}
	}

#if 0 //                                        
	unsigned char reg_value;	
	s32 ret = 0;

	printk(KERN_INFO "[MUIC] %s :  int_stat_value  = 0x%x \n" ,__func__ ,int_stat_value);
	/*if(retain_mode  == BOOT_CP_USB){
		muic_set_develop_mode_detect();
	}else */if (int_stat_value & CHGDET) {
		printk(KERN_INFO "[MUIC] %s :  muic_mode is CHGDET (%d) \n" ,__func__ ,muic_mode);
		muic_set_charger_detect(int_stat_value);
	} else if((int_stat_value & IDNO) == IDNO_0100 ) {
		printk(KERN_INFO "[MUIC] %s :  muic_mode is 130Kohm CP_UART (%d) \n" ,__func__ ,muic_mode);
		/* IDNO=0100? 130Kohm :: CP_UART */
		muic_set_factory_mode_detect(IDNO_0100);	
	} else if((int_stat_value & IDNO) == IDNO_1010) {	
		printk(KERN_INFO "[MUIC] %s :  muic_mode is 910KOhm AP_USB (%d) \n" ,__func__ ,muic_mode);		
		/* IDNO=0100? 910KOhm :: CP_USB */		
		muic_set_factory_mode_detect(IDNO_1010);	
	} else if ((int_stat_value & IDNO) == IDNO_0010) {
		/* IDNO=0010? 56Kohm  :: USB_MODE */
		muic_set_develop_mode_detect();
#if defined(CONFIG_MHL_TX_SII9244)
	} else if (int_stat_value == 0x10) {
		/* IDNO=0000? 0Kohm  :: MHL_MODE */
		muic_set_mhl_mode_detect();    
#else		
	} else if ((int_stat_value == 0x30) || (int_stat_value == 0x11) || (int_stat_value == 0x10)) {
		muic_set_special_test_mode_detect();
#endif//
	} else  if (int_stat_value & V_VBUS) {
		/* Standard USB Host Detected (0x03=0x23) */
		   
		/* Read a status reigster(0x05) */
		ret = muic_i2c_read_byte(STATUS, &reg_value);

		if (reg_value & DCPORT || reg_value & CHPORT) {
			/* Charger Detected*/
			/* COMP2/COMN1 to H-Z (0x03=0x24) */
			muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ);			
			muic_mode = MUIC_NA_TA;
		} else {
#if defined(CONFIG_MHL_TX_SII9244)
			if ((int_stat_value & IDNO ) == IDNO_0000) {
					muic_set_mhl_mode_detect(); 					
			} else {
					///* Standard USB Host Detected (0x03=0x23) */							
					muic_set_usb_mode_detect(); 	// Turn on USB switches 		
					muic_mode = MUIC_AP_USB;
			}
#else
			///* Standard USB Host Detected (0x03=0x23) */							
			muic_set_usb_mode_detect(); 	// Turn on USB switches 		
			muic_mode = MUIC_AP_USB;
#endif
		}			
	} else if ((int_stat_value & IDNO ) == IDNO_0001) {
	/* Vidoe Cable 24k registor Detected - No TV Attached */
	//current_device = DEVICE_VIDEO_CABLE_NO_LOAD;
	} else if ((int_stat_value & IDNO) == IDNO_0000 ) {
		//Set_MUIC_Other_Mode_Detect();
	} else {
		/* Accessory Not Supported */
		muic_mode = MUIC_NONE;
	}
#endif
}
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;
		
	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;
} 
Пример #13
0
int muic_init(int isFactoryReset)
{
	unsigned int retain_mode = NO_RETAIN;
			
	unsigned char i2c_ret;
	
	unsigned char reg_val;			
	unsigned char muic_device;		
	
	MUIC_MODE_TYPE muic_mode = MUIC_OPEN;

	char cmd_line[256];

	strcpy(cmd_line, getenv("bootargs"));

#if defined(CONFIG_COSMO_EVB_B)  || defined(CONFIG_COSMO_EVB_C)
	printf("muic chip : I2C4\n");
	select_bus(I2C4 , OMAP_I2C_STANDARD);
#else
	printf("muic chip : I2C3\n");
	select_bus(I2C3 , OMAP_I2C_STANDARD);
#endif 

	i2c_init(OMAP_I2C_STANDARD, MUIC_SLAVE_ADDR);

	i2c_ret = muic_i2c_read_byte(DEVICE_ID, &reg_val);
	if ((reg_val & 0xf0) == 0x10) 
		muic_device = TS5USBA33402;		
	else if ((reg_val & 0xf0) == 0x20)
		muic_device = MAX14526;			
	else if ((reg_val & 0xf0) == ANY_VANDOR_ID)
		muic_device = ANY_VANDOR;

	if (downloadkey()){
		write_muic_retain_mode(NO_RETAIN);
		printf("[MUIC] No retain\n");
	} 

	retain_mode = read_muic_retain_mode();
	
	printf("muic_init muic vendor : %d, reg_val:0x%x, retain_mode = %d\n", muic_device, reg_val, retain_mode);
	if (muic_device == TS5USBA33402) {
		printf("muic chip : TS5USBA33402\n");
		if (retain_mode == RETAIN_AP_USB) {
			muic_i2c_write_byte(CONTROL_1, ID_200 | SEMREN | CP_EN);
			muic_i2c_write_byte(SW_CONTROL, USB);		
			
			muic_mode = MUIC_USB;
			check_charging_mode(&muic_mode);

			printf("[MUIC] retain AP_USB\n");
			printf("\n###[MUIC] USB charger may not have enough power to boot up depends on your board condition..... ###\n");
			printf("\n###[MUIC] You'd better to use TA or PIF for power supply. ###\n");

			strcat(cmd_line, " muic=2");
			setenv("bootargs", cmd_line);
		} else if (retain_mode == RETAIN_CP_USB) {
			muic_i2c_write_byte(SW_CONTROL, OPEN);
			dp3t_switch_ctrl(DP3T_NC);
			muic_mode = MUIC_USB;
			check_charging_mode(&muic_mode);

			printf("[MUIC] retain CP_USB\n");

			strcat(cmd_line, " muic=3");
			setenv("bootargs", cmd_line);
		} else
			muic_mode = muic_device_ts5usba33402(isFactoryReset, cmd_line);
		
	} else if (muic_device == MAX14526) {
		printf("muic chip : MAX14526\n");
		if (retain_mode == RETAIN_AP_USB) {
			muic_i2c_write_byte(CONTROL_1, ID_200 | ADC_EN | CP_EN);
			muic_i2c_write_byte(SW_CONTROL, USB);		
			
			muic_mode = MUIC_USB;
			check_charging_mode(&muic_mode);
			
			printf("[MUIC] retain AP_USB\n");
			printf("\n###[MUIC] USB charger may not have enough power to boot up depends on your board condition..... ###\n");
			printf("\n###[MUIC] You'd better to use TA or PIF for power supply. ###\n");

			strcat(cmd_line, " muic=2");
			setenv("bootargs", cmd_line);
		} else if (retain_mode == RETAIN_CP_USB) {
			muic_i2c_write_byte(SW_CONTROL, OPEN);
			dp3t_switch_ctrl(DP3T_NC);
			muic_mode = MUIC_USB;
			check_charging_mode(&muic_mode);
			
			printf("[MUIC] retain CP_USB\n");

			strcat(cmd_line, " muic=3");
			setenv("bootargs", cmd_line);
		} else
			muic_mode = muic_device_max14526(isFactoryReset, cmd_line);
	} else
		printf("[MUIC] ANY VENDOR, Not supported\n");

	select_bus(I2C1, OMAP_I2C_STANDARD); 

	return muic_mode;
}
Пример #14
0
static MUIC_MODE_TYPE muic_device_max14526(int _isFactoryRest, char *cmd)
{
	unsigned char i2c_ret;
	unsigned char status_val;			
	unsigned char int_status_val;		

	MUIC_MODE_TYPE muic_mode = MUIC_OPEN;

	i2c_ret = muic_i2c_write_byte(CONTROL_1, ID_200 | ADC_EN);	
	i2c_ret = muic_i2c_write_byte(CONTROL_2, 0x00); 		

	usif1_switch_ctrl(USIF1_UART);

	udelay(70000);		

	i2c_ret = muic_i2c_read_byte(INT_STATUS, &int_status_val);
	printf("INT_STAT = 0x%x\n", int_status_val);

	if ((int_status_val & VBUS) != 0) {
		
		if ((int_status_val & IDNO) == 0x02) {
#ifdef CONFIG_COSMO_SU760
			cable_56K_detect = 1;
#endif
			if (_isFactoryRest) {
				muic_i2c_write_byte(SW_CONTROL, UART);		
				dp3t_switch_ctrl(DP3T_S2_CP_UART);			
				muic_mode = MUIC_FACTORY_MODE;

				strcat(cmd, " muic=1");
				setenv("bootargs", cmd);
				
				printf("[MUIC] first boot, path = CP UART\n");
			} else {
				
				muic_i2c_write_byte(SW_CONTROL, OPEN);
				dp3t_switch_ctrl(DP3T_NC);
				muic_mode = MUIC_FACTORY_MODE;
				printf("CP_USB\n");
			}
		} else if ((int_status_val & IDNO) == 0x04) {
			
			muic_i2c_write_byte(SW_CONTROL, UART);		
			dp3t_switch_ctrl(DP3T_S2_CP_UART);			
			muic_mode = MUIC_FACTORY_MODE;
			printf("CP_UART\n");
		} else if ((int_status_val & IDNO) == 0x0a || (int_status_val & IDNO) == 0x09) {
			
			mmc_init(1);

			cable_910K_detect = 1;
			dload_mode = read_muic_mode_of_dload();
	
			if (dload_mode == NORMAL_MODE) {
				muic_i2c_write_byte(CONTROL_1, ID_200 | ADC_EN | CP_EN);
				muic_i2c_write_byte(SW_CONTROL, USB);
				muic_mode = MUIC_FACTORY_MODE;
				printf("AP_USB is set(910Kohm)\n");
			} else {
				muic_i2c_write_byte(SW_CONTROL, OPEN);
				dp3t_switch_ctrl(DP3T_NC);
				write_muic_mode_of_dload(NORMAL_MODE);
				muic_mode = MUIC_FACTORY_MODE;
				printf("CP_USB is set(910Kohm)\n");
			}
		}else {
			
			muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_C1COMP);
			udelay(2000); 
			i2c_ret = muic_i2c_read_byte(STATUS, &status_val);
			printf("STATUS = 0x%x\n", status_val);

			if (status_val & C1COMP) {
				
				muic_i2c_write_byte(SW_CONTROL, OPEN);
				dp3t_switch_ctrl(DP3T_NC);
				muic_mode = MUIC_CHRGER;
				printf("Charger Detected\n");
			} else {
				muic_i2c_write_byte(CONTROL_1, ID_200 | ADC_EN | CP_EN);
				muic_i2c_write_byte(SW_CONTROL, USB);		
				dp3t_switch_ctrl(DP3T_NC);
				
#ifdef CONFIG_COSMO_SU760
				cable_open_usb_detect = 1;
#endif
				muic_mode = MUIC_USB;

				printf("\n### USB charger may not have enough power to boot up depends on your board condition..... ###\n");
				printf("\n### You'd better to use TA or PIF for power supply. ###\n");
				printf("[MUIC] AP USB\n");
			}
		}	
	} else {
		
		if ((int_status_val & IDNO) == 0x02) {
			muic_i2c_write_byte(CONTROL_1, ID_200 | ADC_EN | CP_EN);
			muic_i2c_write_byte(SW_CONTROL, UART);		
			dp3t_switch_ctrl(DP3T_S1_AP_UART);			
			
			printf("AP_UART\n");
		} else if ((int_status_val & IDNO) == 0x04) {
			
			muic_i2c_write_byte(CONTROL_1, ID_200 | ADC_EN);
			muic_i2c_write_byte(SW_CONTROL, UART);		
			dp3t_switch_ctrl(DP3T_S2_CP_UART);			
			printf("CP_UART\n");
			
		} else {
			muic_i2c_write_byte(SW_CONTROL, OPEN);	
			dp3t_switch_ctrl(DP3T_NC);
			muic_mode = MUIC_OPEN;
			printf("MUIC opened\n");
		}
	}	

	printf("INT_STAT = 0x%x\n", int_status_val);

	return muic_mode;
}
Пример #15
0
s32 muic_max14526_detect_accessory(s32 upon_irq)
{
	s32 ret = 0;
	int loop = 0;

	u8 int_stat_value;
		

	if (upon_irq) { 
		for (; loop < 250; loop++)
			muic_udelay(1000);
	}
	
	/* Reads INT_STAT */
	ret = muic_i2c_read_byte(INT_STAT, &int_stat_value);
	
	if (ret < 0) {
		printk(KERN_INFO "[chahee.kim] INT_STAT reading failed\n");
		muic_mode = MUIC_UNKNOWN;
		return ret;
	}
	
    printk(KERN_INFO "[chahee.kim] IDNO = %d\n", (int_stat_value & IDNO));
  
  	muic_mode = int_stat_value & IDNO;
	/* Branches 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_max14526_muic_mode(int_stat_value);           
		break;

	
	case MUIC_NA_TA:
	case MUIC_TA_1A:
	case MUIC_INVALID_CHG :
		if ((int_stat_value & VBUS) == 0) {		
			
			muic_mode = MUIC_NONE;
		}else{		
  		     set_max14526_muic_mode(int_stat_value);           
		}
		
		break;
		
	case MUIC_LG_TA :
		printk(KERN_WARNING "[chahee.kim] LG_TA");
		if ((int_stat_value & CHGDET) == 0) {		
			muic_mode = MUIC_NONE;				
		}
		else {		
  		     set_max14526_muic_mode(int_stat_value);           
		}
	
	
		break;
		
	case MUIC_AP_UART :
		if ((int_stat_value & IDNO) == IDNO_1011) {								
			/* Exit Factory Mode */
			muic_mode = MUIC_NONE;
		}
		else {
  		     set_max14526_muic_mode(int_stat_value);           
		}
		break;	
	case MUIC_AP_USB :
		if ((int_stat_value & VBUS) == 0) {
			/* USB Host Removed */
			muic_mode = MUIC_NONE;		
		}else{		
  		     set_max14526_muic_mode(int_stat_value);           
		}
		break;
		
	default:
		printk(KERN_WARNING "[chahee.kim] Failed to detect an accessory. Try again!\n");
#ifndef CHARGER_TEST
		lge_charger_disable();
#endif
		muic_mode = MUIC_UNKNOWN;
		ret = -1;
		break;
	}	

	
	printk(KERN_WARNING "[chahee.kim] muic_max14526_detect_accessory, muic_mode = %d \n", muic_mode );

	

	return ret;
}