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