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; }
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; } /* 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; } 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; } if( ((int_stat_value & V_VBUS) != 0) && (!gpio_get_value(GPIO_MHL_SEL)) && ((int_stat_value & IDNO) == IDNO_0000) ) { MHL_On(1); //re-enable MHL muic_mode = MUIC_MHL; charging_mode = CHARGING_USB; } 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"); } return ret; }
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; }