s32 muic_CP_USB_set(void){ s32 ret; /* 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] */ // LGE_UPDATE_S 20110411 [[email protected]] force D+/D- open in CP side ret = muic_i2c_write_byte_local(SW_CONTROL, DP_OPEN | DM_OPEN); muic_udelay(100000); if(ret < 0) printk(KERN_WARNING "[MUIC] i2c write error for D+/D- open in muic_CP_USB_SET\n"); // LGE_UPDATE_E 20110411 [[email protected]] force D+/D- open in CP side /* Connect CP UART signals to AP */ //usif_switch_ctrl(USIF_AP); /* Connect CP USB to MUIC UART */ //dp3t_switch_ctrl(DP3T_CP_USB); // [email protected] if (muic_device == MAX14526) { /* ID_200, VLDO 2.6V, ADC is auto. * USB 2.0 also needs the charge pump (CP_EN) on.*/ ret = muic_i2c_write_byte_local(CONTROL_1, MID_200 | MADC_EN | MCP_EN); } else { ret = muic_i2c_write_byte_local(SW_CONTROL, DP_OPEN | DM_OPEN); /* ID_200, VLDO 2.6V, SEMREN on. ADC is auto. * USB 2.0 also needs the charge pump (CP_EN) on.*/ ret = muic_i2c_write_byte_local(CONTROL_1, MID_200 | MSEMREN | MCP_EN); } /* Connect DP, DM to UART_TX, UART_RX*/ ret = muic_i2c_write_byte_local(SW_CONTROL, DP_UART | DM_UART); /* Turn on charger IC with FACTORY mode */ charging_ic_set_factory_mode(); muic_mode = MUIC_CP_USB; printk(KERN_ERR "[MUIC] muic_distinguish_vbus_accessory(): CP_USB\n"); /* wake lock for the factory mode */ set_wakelock(1); return ret; }
s32 muic_CP_USB_set(void){ s32 ret; /* 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] */ // LGE_UPDATE_S 20110411 [[email protected]] force D+/D- open in CP side ret = muic_i2c_write_byte(SW_CONTROL, DP_OPEN | DM_OPEN); muic_udelay(100000); if(ret < 0) printk(KERN_WARNING "[MUIC] i2c write error for D+/D- open in muic_CP_USB_SET\n"); // LGE_UPDATE_E 20110411 [[email protected]] force D+/D- open in CP side /* Connect CP UART signals to AP */ /* CP <-> USIF_AP ?�결??CP ?�운로드 Fail 발생 */ usif_switch_ctrl(USIF_DP3T); /* Connect CP USB to MUIC UART */ dp3t_switch_ctrl(DP3T_CP_USB); if (muic_device == MAX14526) { /* ID_200, VLDO 2.6V, ADC is auto. * USB 2.0 also needs the charge pump (CP_EN) on.*/ ret = muic_i2c_write_byte(CONTROL_1, MID_200 | MADC_EN | MCP_EN); } else { if( MUIC_CP_USB != muic_mode ) { /* ID_200, VLDO 2.6V, SEMREN on. ADC is auto. * USB 2.0 also needs the charge pump (CP_EN) on.*/ ret = muic_i2c_write_byte(CONTROL_1, MID_200 | MSEMREN | MCP_EN); } } ret = muic_i2c_write_byte(SW_CONTROL, DP_USB | DM_USB); // S [email protected] ; add for charging mode when CP USB is slected int check_battery_present(); if(check_battery_present()==1) charging_ic_set_usb_mode(); else charging_ic_set_factory_mode(); // E [email protected] ; add for charging mode when CP USB is slected muic_mode = MUIC_CP_USB; printk(KERN_ERR "[MUIC] muic_distinguish_vbus_accessory(): CP_USB\n"); // START [email protected] 2011/03/03 LAB1_FW : WAKELOCK_CASE_AT_CP_USB : Ref from LU3000 { if ( reset_status == 2 /* RESET_GLOBAL_SW_RESET */ ) { // If muic path is CP_USB, Reset cause is SW_RESET then WakeLock AP // wake lock for the factory mode if(0==the_wlock.wake_lock_on){ wake_lock(&the_wlock.wake_lock); the_wlock.wake_lock_on=1; printk(KERN_WARNING "[MUIC] ====^^==== wake_lock_on=1 (locked)\n"); } } else { /* wake lock off for the factory mode */ set_wakelock(0); } // END [email protected] 2011/03/03 LAB1_FW } return ret; }
s32 muic_AP_USB_set(void){ s32 ret; /* 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] */ if(hidden_menu_switching == 8) // if USB mode change AP_USB through Proc filesystem, force D+/D- open { ret = muic_i2c_write_byte(SW_CONTROL, DP_OPEN | DM_OPEN); muic_udelay(100000); if(ret < 0) printk(KERN_WARNING "[MUIC] i2c write error for D+/D- open in muic_CP_USB_SET\n"); } /* Justin?�서 AP_UART�??�정??AP_USB ?�작 ?�함 */ dp3t_switch_ctrl(DP3T_NC); if (muic_device == MAX14526) { /* ID_200, VLDO 2.6V, ADC Enable, * USB 2.0 also needs the charge pump (CP_EN) on.*/ ret = muic_i2c_write_byte(CONTROL_1, MID_200 | MADC_EN | MCP_EN); } else { // START [email protected] 2011/03/10 LAB1_FW { if( MUIC_AP_USB != muic_mode ) { ret = muic_i2c_write_byte(SW_CONTROL, DP_OPEN | DM_OPEN); /* ID_200, VLDO 2.6V, SEMREN on. ADC is auto. * USB 2.0 also needs the charge pump (CP_EN) on.*/ ret = muic_i2c_write_byte(CONTROL_1, MID_200 | MSEMREN | MCP_EN); } // END [email protected] 2011/03/10 LAB1_FW } } /* Connect DP, DM to USB_DP, USB_DM */ ret = muic_i2c_write_byte(SW_CONTROL, DP_USB | DM_USB); /* Turn on charger IC with TA mode */ charging_ic_set_usb_mode(); muic_mode = MUIC_AP_USB; printk(KERN_WARNING "[MUIC] muic_distinguish_vbus_accessory(): AP_USB\n"); /* wake lock for usb connection */ set_wakelock(1); // check_usb_reg(); /* 20111105, [email protected], for stable USB connection. */ return ret; }
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); 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_max14526_cp_usb_mode(); muic_mode = MUIC_CP_USB; charging_mode = CHARGING_FACTORY; } 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) { muic_set_mhl_mode_detect(); muic_mode = MUIC_MHL; charging_mode = CHARGING_MHL; #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 { muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_C1COMP); muic_mdelay(2); muic_i2c_read_byte(STATUS, ®_value); if (reg_value & C1COMP) { muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ); 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 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, ®_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 }
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; }
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; 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; }