Esempio n. 1
0
int muic_process_retention_mode(struct i2c_client *client)
{
	if(muic_retain_mode <0 ){
		printk(KERN_ERR "muic: %s, muic_retain_mode:%d is wrong state\n",
			__func__, muic_retain_mode);
		muic_retain_mode = 0;

		return -EINVAL;
	}

	if (BOOT_CP_USB == muic_retain_mode) {
		//dev_info(&client->dev, "muic: USB is CP retain\n");
		muic_set_mode(MUIC_CP_USB);
		//muic_set_develop_mode_detect(client);
	}
	else if (BOOT_AP_USB == muic_retain_mode) {
		//dev_info(&client->dev, "muic: USB is AP retain\n");
		muic_set_mode(MUIC_AP_USB);
		//muic_set_usb_mode_detect(client);
#if defined(CONFIG_MHL) //nthyunjin.yang 120511 temp add for build error.
	}else if (BOOT_MHL == muic_retain_mode){
		muic_set_mode(MUIC_MHL);
	}else if (BOOT_MHL == muic_retain_mode){
		muic_set_mode(MUIC_CP_UART);
#endif
	}

	return muic_retain_mode;
}
Esempio n. 2
0
int muic_process_retention_mode(struct i2c_client *client)
{
	if(muic_retain_mode <0 ){
		printk(KERN_ERR "muic: %s, muic_retain_mode:%d is wrong state\n",
			__func__, muic_retain_mode);
		muic_retain_mode = 0;

		return -EINVAL;
	}

	if (BOOT_CP_USB == muic_retain_mode) {
		//dev_info(&client->dev, "muic: USB is CP retain\n");
		muic_set_mode(MUIC_CP_USB);
		//muic_set_develop_mode_detect(client);
	}
	else if (BOOT_AP_USB == muic_retain_mode) {
		//dev_info(&client->dev, "muic: USB is AP retain\n");
		muic_set_mode(MUIC_AP_USB);
		//muic_set_usb_mode_detect(client);
	}else if (BOOT_MHL == muic_retain_mode){
		muic_set_mode(MUIC_MHL);
	}else if (BOOT_MHL == muic_retain_mode){
		muic_set_mode(MUIC_CP_UART);
	}

	return muic_retain_mode;
}
Esempio n. 3
0
static ssize_t state_store(struct device *dev, struct device_attribute *attr,
		const char *buf, size_t count)
{
	int i	= MUIC_MODE_NO;
	int set_mode = -1;
	char *p;
	int len;

	p = memchr(buf, '\n', count);
	len = p ? p - buf : count;

	dev_info(dev, "muic %s: %s, count:%d, sizeof:%d, len:%d\n", 
		__func__, buf, count, sizeof(buf), len);

	if(len > 7){ // max value is 7
		printk(KERN_WARNING "%s, wrong command\n", __func__);
		return -EINVAL;		
	}

	do{
		i--;

		if(NULL != state[i]){
			if(!strncmp(buf, state[i], len)){
				dev_info(dev, "%s, store muic mode:%s\n", __func__,  state[i]);
				set_mode = i;
			}
		}		
	} while((set_mode < 0) && (i > 0));

	if(set_mode < 0){
		printk(KERN_WARNING "%s, wrong command\n", __func__);
		return -EINVAL;
	}

#if 0
	if((_mdev->mode != MUIC_NONE)&&(_mdev->mode != MUIC_UNKNOWN)) {
		dev_info(dev, "%s, MUIC_NONE before set_mode\n", __func__);
		muic_set_mode(MUIC_NONE);
		mdelay(2);
	}
#endif

	muic_set_mode(set_mode);
	dev_info(dev, "%s, end\n", __func__);
	
	return count;
}
Esempio n. 4
0
void muic_set_charger_mode(struct i2c_client *client,
		unsigned char int_stat_value)
{
	s32 ret = 0;
  	unsigned char reg_value;

	dev_info(&client->dev, "muic: Charger ID = 0x%x\n", int_stat_value);

  	if (((int_stat_value & IDNO) == IDNO_0101) ||
	    ((int_stat_value & IDNO) == IDNO_1011)) {
		/*LG Proprietary TA Detected 180K ohm on ID */
		muic_i2c_write_byte(client, CONTROL_1, ID_200 | SEMREN);
		muic_i2c_write_byte(client, CONTROL_2, INT_EN);
		muic_set_mode(MUIC_LG_TA);
	} else if ((int_stat_value & IDNO) == IDNO_0110) {
		/* 1A charger detected */
		muic_set_mode(MUIC_TA_1A);
	} else {
		dev_info(&client->dev, "muic: Charger ID11111\n");
		/* Enable interrpt and charger type detection (0x02=0x42) */
		muic_i2c_write_byte(client, CONTROL_2, INT_EN | CHG_TYPE);

		/* Read INT_STATUS1 */
		ret = muic_i2c_read_byte(client, INT_STATUS1, &reg_value);
		ret = muic_i2c_read_byte(client, STATUS, &reg_value);

		if (reg_value & DCPORT) {
			printk("Charger ID22222\n");
			muic_i2c_write_byte(client, CONTROL_1, ID_200 | SEMREN);
			muic_i2c_write_byte(client, CONTROL_2, INT_EN);
			muic_set_mode(MUIC_NA_TA);
		} else {
			printk("Charger ID33333\n");
			muic_set_mode(MUIC_AP_USB);
//			muic_set_usb_mode_detect(client);
		}
  	}
}
Esempio n. 5
0
static ssize_t state_store(struct device *dev, struct device_attribute *attr,
                           const char *buf, size_t count)
{
    int i	= MUIC_MODE_NO;
    int set_mode = -1;
    char *p;
    int len;
    int error = -EINVAL;

    p = memchr(buf, '\n', count);
    len = p ? p - buf : count;

    dev_info(dev, "muic %s: %s, count:%d, sizeof:%d, len:%d\n",
             __func__, buf, count, sizeof(buf), len);

    if(len > 7) { // max value is 7
        printk(KERN_WARNING "%s, wrong command\n", __func__);
        return -EINVAL;
    }

    do {
        i--;
#if 0
        dev_info(dev,"muic %s, buf: %s, state[%d]: %s, size: %d, \n",
                 __func__, buf, i, state[i], sizeof(state[i]) );
#endif
        if(NULL != state[i]) {
            if(!strncmp(buf, state[i], len)) { //  min(len, sizeof(state[i])))){
                dev_info(dev, "%s, store muic mode:%s\n", __func__,  state[i]);
                set_mode = i;
            }
        }
    } while((set_mode<0) && (i>0));

    if(set_mode<0) {
        printk(KERN_WARNING "%s, wrong command\n", __func__);
        return -EINVAL;
    }

    muic_set_mode(set_mode);
    dev_info(dev, "%s, end\n", __func__);

    return count;
}
Esempio n. 6
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);
}
Esempio n. 7
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;
		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
		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;
		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;
}
Esempio n. 8
0
static ssize_t muic_proc_write(struct file *filp, const char *buf, size_t len, loff_t *off){
	char messages[12];
	u32 val;
	u32 reg;
	s32 err;
	char cmd;

	if(len > 12)
		len = 12;

	if(copy_from_user(messages, buf, len))
		return -EFAULT;

	sscanf(buf, "%c 0x%x 0x%x", &cmd, &reg, &val);

	printk(KERN_INFO "[MUIC] LGE: MUIC_proc_write \n");

	switch(cmd){

// LGE_UPDATE 20110311 [[email protected]] add CP Image Downloadfor Hidden Menu - AP CP USB Swithcing
		/* CP Image Download */
		case '3':
                        //muic_CP_USB_set();
                        muic_set_mode(MUIC_CP_USB);	// [email protected]
                        gpio_set_value(26, 0);
			mdelay(100);
                        gpio_set_value(26, 1);
                        break;
// LGE_UPDATE 20110311 [[email protected]] add CP Image Downloadfor Hidden Menu - AP CP USB Swithcing

		/* AP_UART mode*/
		case '6':
			//muic_AP_UART_set();
			muic_set_mode(MUIC_AP_UART);	// [email protected]
			break;
/* LGE_CHANGE_S [[email protected]] 2011-01-06, CP retain mode and Hidden Menu AP CP Switching Retain */
		/* CP_UART mode*/
		case '7':
			//muic_CP_UART_set();
			muic_set_mode(MUIC_CP_UART);	// [email protected]
			hidden_menu_switching = 7;
			break;

		/* AP_USB mode*/
		case '8':
			//muic_AP_USB_set();
			muic_set_mode(MUIC_AP_USB);	// [email protected]
			hidden_menu_switching = 8;
			break;

		/* CP_USB mode*/
		case '9':
			//muic_CP_USB_set();
			muic_set_mode(MUIC_CP_USB);	// [email protected]
			hidden_menu_switching = 9;
			break;

		case 'w':
			err = i2c_smbus_write_byte_data(muic_client, reg, val);
			printk(KERN_INFO "[MUIC] LGE: Hub MUIC Write Reg. = 0x%X, Value 0x%X\n", reg, val);
			break;

		default :
			printk(KERN_INFO "[MUIC] LGE: Hub MUIC invalid command\n");
			printk(KERN_INFO "[MUIC] 6: AP_UART, 7: CP_UART, 8: AP_USB, 9: CP_USB\n");
			printk(KERN_INFO "[MUIC] or \"w address value\"\n");
			break;
	}
	return len;
}
Esempio n. 9
0
// [email protected] section mismatch error fix
//static s32 __init muic_probe(struct i2c_client *client, const struct i2c_device_id *id){
static s32 muic_probe(struct i2c_client *client, const struct i2c_device_id *id){

	s32 ret = 0;
	u32 retry_no = 0;
/* B-Prj Power off charging [[email protected]] 2010-12-15 */
	int err = 0;
/* B-Prj Power off charging [[email protected]] 2010-12-15 */

// [email protected] 20120502 MUIC re-work
	struct hub_muic_device *dev = NULL;
	struct muic_platform_data *pdata = client->dev.platform_data;

	dev_info(&client->dev, "muic: %s()\n", __func__);

	if (!pdata) {
		dev_err(&client->dev, "muic: %s: no platform data\n", __func__);
		return -EINVAL;
	}

	dev = kzalloc(sizeof(struct hub_muic_device), GFP_KERNEL);
	if (!dev) {
		dev_err(&client->dev, "muic: %s: no memory\n", __func__);
		return -ENOMEM;
	}

	dev->client = client;
// [email protected] 20120502 MUIC re-work

	muic_client = client;

	/* wake lock for usb connection */
	wake_lock_init(&the_wlock.wake_lock, WAKE_LOCK_SUSPEND, "usb_connection");
	the_wlock.wake_lock_on=0;

	/* GPIO initialization */
	omap_mux_init_gpio(MUIC_INT_GPIO, OMAP_PIN_INPUT_PULLUP | OMAP_PIN_OFF_WAKEUPENABLE);
	omap_mux_init_gpio(GPIO_DP3T_IN_1, OMAP_PIN_OUTPUT);
	omap_mux_init_gpio(GPIO_DP3T_IN_2, OMAP_PIN_OUTPUT);
	omap_mux_init_gpio(GPIO_USIF_IN_1, OMAP_PIN_OUTPUT);		// USIF_IN_1_GPIO -> GPIO_USIF_IN_1
	omap_mux_init_gpio(GPIO_IFX_USB_VBUS_EN, OMAP_PIN_OUTPUT);

//[email protected] 20120502 MUIC re-work	start
	ret = muic_device_register(&muic_dev, NULL);
	if (ret < 0) {
		dev_err(&client->dev, "muic: %s: muic_device_register failed\n",
				__func__);
		goto err_gpio_request;
	}

	i2c_set_clientdata(client, dev);
	
	printk("%s, registering ops\n", __func__);
	muic_client_dev_register(dev->client->name, dev, &hub_muic_ops);
//[email protected] 20120502 MUIC re-work end

	/* Initialize GPIO direction before use.
	 * Check if other driver already occupied it.
	 */
//[email protected] 20120502 MUIC re-work	start
	//if (gpio_request(GPIO_USIF_IN_1, "USIF switch control GPIO") < 0) {
	//	printk(KERN_INFO "[MUIC] GPIO %d USIF1_SW is already occupied by other driver!\n", GPIO_USIF_IN_1);
	//	/* We know board_hub.c:ifx_n721_configure_gpio() performs a gpio_request on this pin first.
	//	 * Because the prior gpio_request is also for the analog switch control, this is not a confliction.*/
	//	ret = -ENOSYS;
	//	goto err_gpio_request;
	//}

	//if (gpio_request(GPIO_DP3T_IN_1, "DP3T switch control 1 GPIO") < 0) {
	//	printk(KERN_INFO "[MUIC] GPIO %d GPIO_DP3T_IN_1 is already occupied by other driver!\n", GPIO_DP3T_IN_1);
	//	ret = -ENOSYS;
	//	goto err_gpio_request;
	//}

	//if (gpio_request(GPIO_DP3T_IN_2, "DP3T switch control 2 GPIO") < 0) {
	//	printk(KERN_INFO "[MUIC] GPIO %d GPIO_DP3T_IN_2 is already occupied by other driver!\n", GPIO_DP3T_IN_2);
	//	ret = -ENOSYS;
	//	goto err_gpio_request;
	//}

	//if (gpio_request(GPIO_IFX_USB_VBUS_EN, "IFX VBUS EN") < 0) {
	//	printk(KERN_INFO "[MUIC] GPIO %d GPIO_IFX_USB_VBUS_EN is already occupied by other driver!\n", GPIO_IFX_USB_VBUS_EN);
	//	ret = -ENOSYS;
	//	goto err_gpio_request;
	//}
//[email protected] 20120502 MUIC re-work end

	/* Initialize GPIO 40 (MUIC_INT_N).
	 * Check if other driver already occupied it.
	 */
	if (gpio_request(MUIC_INT_GPIO, "MUIC IRQ GPIO") < 0) {
		printk(KERN_INFO "[MUIC] GPIO %d MUIC_INT_N is already occupied by other driver!\n", MUIC_INT_GPIO);
		ret = -ENOSYS;
		goto err_gpio_request;
	}

	/* Initialize GPIO direction before use or IRQ setting */
	if (gpio_direction_input(MUIC_INT_GPIO) < 0) {
		printk(KERN_INFO "[MUIC] GPIO %d MUIC_INT_N direction initialization failed!\n", MUIC_INT_GPIO);
		ret = -ENOSYS;
		goto err_gpio_request;
	}
//[[UBIQUIX_CHANGE_START, 0120419, [email protected], For AP/CP switching
	//gpio_direction_output(GPIO_DP3T_IN_1, 0);
	//gpio_direction_output(GPIO_DP3T_IN_2, 0);
	//gpio_direction_output(GPIO_USIF_IN_1, 0);
	//gpio_direction_output(GPIO_IFX_USB_VBUS_EN, 0);
//UBIQUIX_CHANGE_START, 0120419, [email protected], For AP/CP switching]]

	/* Register MUIC work queue function */
	INIT_DELAYED_WORK(&muic_wq, muic_wq_func);

	/* Set up an IRQ line and enable the involved interrupt handler.
	 * From this point, a MUIC_INT_N can invoke muic_interrupt_handler().
	 * muic_interrupt_handler merely calls schedule_work() with muic_wq_func().
	 * muic_wq_func() actually performs the accessory detection.
	 */
	if (request_irq(gpio_to_irq(MUIC_INT_GPIO),
			  muic_interrupt_handler,
			  IRQF_TRIGGER_FALLING,
			  "muic_irq",
			  &client->dev) < 0) {
		printk(KERN_INFO "[MUIC] GPIO %d MUIC_INT_N IRQ line set up failed!\n", MUIC_INT_GPIO);
		free_irq(gpio_to_irq(MUIC_INT_GPIO), &client->dev);
		ret = -ENOSYS;
		goto err_gpio_request;		
	}

	/* Make the interrupt on MUIC INT wake up OMAP which is in suspend mode */
	if (enable_irq_wake(gpio_to_irq(MUIC_INT_GPIO)) < 0) {
		printk(KERN_INFO "[MUIC] GPIO %d MUIC_INT_N wake up source setting failed!\n", MUIC_INT_GPIO);
		disable_irq_wake(gpio_to_irq(MUIC_INT_GPIO));
		ret = -ENOSYS;
		goto err_gpio_request;
	}


	/* Prepare a human accessible method to control MUIC */
	create_hub_muic_proc_file();

/* B-Prj Power off charging [[email protected]] 2010-12-15 */
	err = device_create_file(&client->dev, &dev_attr_wake_lock);
	err = device_create_file(&client->dev, &dev_attr_charging_mode);
/* B-Prj Power off charging [[email protected]] 2010-12-15 */

	/* Initialize MUIC - Finally MUIC INT becomes enabled */

/* LGE_CHANGE_START 2011-03-16 [email protected] patch for Adb offline set and Mass Storage Driver detecting fail */    
	 muic_init_done = 1; //20110113 [email protected] check muic driver init. state
/* LGE_CHANGE_END 2011-03-16 [email protected] */
	muic_initialize(RESET);

	muic_set_mode(MUIC_NONE);


	mdelay(70);
	ret = muic_device_detection(NOT_UPON_IRQ);

	/* If an erronous situation occurs, try again */
	while(ret < 0 && retry_no < 3){
		printk(KERN_INFO "[MUIC] muic_probe(): muic_device_detection() failed %d times\n", ++retry_no);
		ret = muic_device_detection(NOT_UPON_IRQ);
	}

	printk(KERN_INFO "[MUIC] muic_probe(): done!\n");

	return ret;
	
err_muic_device_register:
	free_irq(gpio_to_irq(MUIC_INT_GPIO), dev);
err_gpio_request:
	kfree(dev);

	return ret;
}
Esempio n. 10
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{
Esempio 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;
}
Esempio n. 12
0
static int __devinit max14526_probe(struct i2c_client *client,
		const struct i2c_device_id *id)
{
	int ret = 0;
	TYPE_MUIC_MODE muic_mode;
	struct ts5usb_device *dev = NULL;
	struct muic_platform_data *pdata = client->dev.platform_data;

	dev_info(&client->dev, "muic: %s()\n", __func__);

	if (!pdata) {
		dev_err(&client->dev, "muic: %s: no platform data\n", __func__);
		return -EINVAL;
	}

	dev = kzalloc(sizeof(struct ts5usb_device), GFP_KERNEL);
	if (!dev) {
		dev_err(&client->dev, "muic: %s: no memory\n", __func__);
		return -ENOMEM;
	}

	dev->client = client;
	dev->gpio_int = pdata->gpio_int;
#if defined(CONFIG_MHL)
	dev->gpio_mhl = pdata->gpio_mhl;
	dev->gpio_ifx_vbus = pdata->gpio_ifx_vbus;
#endif
	dev->irq = client->irq;

	max14526 = client;

	/* Initializes gpio_165 (USIF1_SW). */
	ret = gpio_request(USIF_IN_1_GPIO, "USIF switch control GPIO");
	if (ret < 0) {
		printk(KERN_INFO "[MUIC] GPIO 165 USIF1_SW is already occupied by other driver!\n");
		/*
		 * We know board_cosmo.c:ifx_n721_configure_gpio() performs a gpio_request on this pin first.
		 * Because the prior gpio_request is also for the analog switch control, this is not a confliction.
		 */
		return -ENOSYS;
	}

	ret = gpio_direction_output(USIF_IN_1_GPIO, 0);
	if (ret < 0) {
		printk(KERN_INFO "[MUIC] gpio_16 USIF_IN_1_GPIO direction initialization failed!\n");
		return -ENOSYS;
	}

	/*  Initializes gpio_11 (OMAP_UART_SW) and gpio_12 (IFX_UART_SW) */
	ret = gpio_request(DP3T_IN_1_GPIO, "DP3T switch control 1 GPIO");
	if (ret < 0) {
		printk(KERN_INFO "[MUIC] GPIO 11 DP3T_IN_1_GPIO is already occupied by other driver!\n");
		return -ENOSYS;
	}

	ret = gpio_direction_output(DP3T_IN_1_GPIO, 0);
	if (ret < 0) {
		printk(KERN_INFO "[MUIC] gpio_11 DP3T_IN_1_GPIO direction initialization failed!\n");
		return -ENOSYS;
	}

	ret = gpio_request(DP3T_IN_2_GPIO, "DP3T switch control 2 GPIO");
	if (ret < 0) {
		printk(KERN_INFO "[MUIC] gpio_12 DP3T_IN_2_GPIO is already occupied by other driver!\n");
		return -ENOSYS;
	}

	ret = gpio_direction_output(DP3T_IN_2_GPIO, 0);
	if (ret < 0) {
		printk(KERN_INFO "[MUIC] gpio_12 DP3T_IN_2_GPIO direction initialization failed!\n");
		return -ENOSYS;
	}

	ret = gpio_request(IFX_USB_VBUS_EN_GPIO, "DP3T switch control 2 GPIO");
	if (ret < 0) {
		printk(KERN_INFO "[MUIC] gpio_55 IFX_USB_VBUS_EN_GPIO is already occupied by other driver!\n");
		return -ENOSYS;
	}

	ret = gpio_direction_output(IFX_USB_VBUS_EN_GPIO, 0);
	if (ret < 0) {
		printk(KERN_INFO "[MUIC] gpio_55 IFX_USB_VBUS_EN_GPIO direction initialization failed!\n");
		return -ENOSYS;
	}

	/*
	 * Initializes gpio_wk8 (MUIC_INT_N).
	 * Checks if other driver already occupied it.
	 */
	ret = gpio_request(dev->gpio_int, "MUIC IRQ GPIO");
	if (ret < 0) {
		dev_err(&client->dev, "muic: GPIO %d is already used\n",	dev->gpio_int);
		ret = -ENOSYS;
		goto err_gpio_request;
	}
	/* Initializes GPIO direction before use or IRQ setting */
	gpio_direction_input(dev->gpio_int);

	/* Registers MUIC work queue function */
	INIT_WORK(&dev->muic_wq, max14526_wq_func);

	/*
	 * Set up an IRQ line and enable the involved interrupt handler.
	 * From this point, a MUIC_INT_N can invoke muic_interrupt_handler().
	 * muic_interrupt_handler merely calls schedule_work() with muic_wq_func().
	 * muic_wq_func() actually performs the accessory detection.
	 */
	ret = request_irq(dev->irq, max14526_interrupt_handler,IRQF_TRIGGER_FALLING, "muic_irq", dev);
	if (ret < 0) 
	{
		dev_err(&client->dev, "muic: %s: request_irq failed!\n",__func__);
		goto err_request_irq;
	}

	//disable_irq_wake(gpio_to_irq(MUIC_INT));

	/* Prepares a human accessible method to control MUIC */
	//create_cosmo_muic_proc_file();

	/* Selects one of the possible muic chips */
	//muic_detect_device();

	wake_lock_init(&dev->muic_wake_lock, WAKE_LOCK_SUSPEND,"muic_wake_lock");

	ret = muic_device_register(&muic_dev, NULL);
	if (ret < 0) {
		dev_err(&client->dev, "muic: %s: muic_device_register failed\n",__func__);
		goto err_muic_device_register;
	}

	i2c_set_clientdata(client, dev);

	// hunsoo.lee
	printk("%s, registering ops\n", __func__);
	muic_client_dev_register(dev->client->name, dev, &max14526_ops);

	/* Initializes MUIC - Finally MUIC INT becomes enabled */
	if (BOOT_RECOVERY == muic_retain_mode) 
	{ /* Recovery mode */
		muic_mode = MUIC_CP_UART;
		muic_init_max14526(client, BOOTUP);
		dev_info(&client->dev, "muic: %s: first boot\n", __func__);
	}
	else 
	{
		muic_init_max14526(client, RESET);
		muic_max14526_detect_accessory(client, NOT_UPON_IRQ);
		muic_mode = muic_get_mode();
	}
	muic_set_mode(muic_mode);

	/* Makes the interrupt on MUIC INT wake up OMAP which is in suspend mode */
	ret = enable_irq_wake(dev->irq);
	if (ret < 0) {
		dev_err(&client->dev, "muic: GPIO %d wake up source setting failed!\n", dev->gpio_int);
		disable_irq_wake(dev->irq);
		goto err_irq_wake;
	}

	dev_info(&client->dev, "muic: muic_probe()\n");

	return ret;

err_irq_wake:
	muic_device_unregister(&muic_dev);
err_muic_device_register:
	wake_lock_destroy(&dev->muic_wake_lock);
	free_irq(dev->irq, dev);
err_request_irq:
	gpio_free(dev->gpio_int);
err_gpio_request:
	kfree(dev);

	return ret;
}
Esempio n. 13
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;
}
Esempio n. 14
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;
}
Esempio n. 15
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;
}
Esempio n. 16
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:
		android_USB_disconnect(); // for usb disconnect event

		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:
	case MUIC_CP_USB:
		android_USB_disconnect(); // for usb disconnect event

		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;
}