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; }
/* 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, ®_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); }
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; }