static s32 muic_proc_set_ap_usb(void) { s32 ret; #if defined (CONFIG_MACH_BSSQ) #else ret = muic_i2c_write_byte(SW_CONTROL, OPEN); dp3t_switch_ctrl(DP3T_NC); muic_mdelay(100); /* Connect CP UART signals to AP */ usif_switch_ctrl(USIF_AP); /* AP USB does not pass through DP3T. * Just connect AP UART to MUIC UART. */ dp3t_switch_ctrl(DP3T_AP_UART); //dp3t_switch_ctrl(DP3T_NC); //[[email protected]] - Changed to X3 Code. CP USB OFF is only thing. #endif /* Connect DP, DM to USB_DP, USB_DM */ ret = muic_i2c_write_byte(SW_CONTROL, DP_USB | DM_USB); muic_mode = MUIC_AP_USB; charging_mode = CHARGING_USB; DBG("[MUIC] muic_proc_set_ap_usb(): AP_USB\n"); return ret; }
void set_ts5usba33402_charger_mode(unsigned char int_stat_value) { s32 ret = 0; unsigned char reg_value; if (((int_stat_value & IDNO) == IDNO_0101) || ((int_stat_value & IDNO) == IDNO_1011)) { /*LG Proprietary TA Detected 180K ohm on ID */ muic_path = MUIC_LG_TA; } else if ((int_stat_value & IDNO) == IDNO_0110) { /* 1A charger detected */ muic_path = MUIC_TA_1A; } else { /* Enable interrpt and charger type detection (0x02=0x42) */ muic_i2c_write_byte(CONTROL_2, INT_EN | CHG_TYPE); muic_mdelay(2); /* Read INT_STAT */ ret = muic_i2c_read_byte(INT_STAT, ®_value); ret = muic_i2c_read_byte(STATUS, ®_value); if (reg_value & DCPORT) { muic_path = MUIC_NA_TA; } else set_ts5usba33402_ap_usb_mode(); } }
static s32 muic_proc_set_cp_usb(void) { s32 ret; #if defined (CONFIG_MACH_BSSQ) gpio_set_value(GPIO_CP_USB_VBUS_EN, 1); #else ret = muic_i2c_write_byte(SW_CONTROL, OPEN); dp3t_switch_ctrl(DP3T_NC); muic_mdelay(100); /* Connect CP UART signals to AP */ usif_switch_ctrl(USIF_AP);//usif_switch_ctrl(USIF_DP3T); //[[email protected]] - Changed to X3 code. /* Connect CP USB to MUIC UART */ dp3t_switch_ctrl(DP3T_CP_USB); /* Enables 200K, Charger Pump, and ADC (0x01=0x13) */ // muic_i2c_write_byte(CONTROL_1, ID_200 |ADC_EN | CP_EN ); //13 //[[email protected]] - disabled because NOT in Cosmo Code // muic_i2c_write_byte(CONTROL_1, ID_200 | SEMREN | CP_EN); //15 // muic_i2c_write_byte(CONTROL_1, ID_2P2 | SEMREN );//44 #endif /* Enable USB Path (0x03=0x00) --- Connect DP, DM to UART_TX, UART_RX */ ret = muic_i2c_write_byte(SW_CONTROL, COMP2_TO_U2 | COMN1_TO_U1); muic_mode = MUIC_CP_USB; charging_mode = CHARGING_USB; DBG("[MUIC] muic_proc_set_cp_usb(): CP_USB\n"); return ret; }
static void muic_wq_func(struct work_struct *muic_wq) #endif { s32 ret = 0; DBG("[MUIC] muic_wq_func(): retain_mode = %s (%d)", retain_mode_str[retain_mode], retain_mode); if (retain_mode == RETAIN_NO) { ret = muic_detect_accessory(UPON_IRQ); set_muic_charger_detected(); // [[email protected]] DBG("[MUIC] muic_detect_accessory(UPON_IRQ) result: muic_mode = %s (%d), charing = %s (%d)", muic_mode_str[muic_mode], muic_mode, charging_mode_str[charging_mode], charging_mode); } else { muic_mdelay(250); ret = i2c_smbus_read_byte_data(muic_client, INT_STAT); if (muic_mode == MUIC_CP_USB) muic_proc_set_cp_usb(); check_charging_mode(); set_muic_charger_detected(); DBG("[MUIC] Now...path retain mode, muic_mode = %s (%d), charing = %s (%d)\n", muic_mode_str[muic_mode], muic_mode, charging_mode_str[charging_mode], charging_mode); } }
int muic_set_cp_usb_mode(struct muic_client_device *mcdev)// (struct i2c_client *client) { struct i2c_client *client = max14526; //to_i2c_client(%mcdev->dev);// i2c_verify_client(&mcdev->dev); if(!client) { printk("muic %s, client : %ld", __func__, (long)client); return -1; } dev_info(&client->dev, "muic: %s entry.\n", __func__); muic_i2c_write_byte(client,SW_CONTROL, OPEN); dp3t_switch_ctrl(DP3T_NC); muic_mdelay(100); /* Connect CP UART signals to AP */ usif_switch_ctrl(USIF_AP); /* Connect CP USB to MUIC UART */ dp3t_switch_ctrl(DP3T_CP_USB); /* Connect DP, DM to UART_TX, UART_RX */ muic_i2c_write_byte(client,SW_CONTROL, DP_UART | DM_UART); //muic_path = MUIC_CP_USB; //charging_mode = CHARGING_USB; printk("[MUIC] muic_set_cp_usb_mode(): CP_USB\n"); return 0; }
int muic_set_ap_usb_mode(struct muic_client_device *mcdev)// (struct i2c_client *client) { struct i2c_client *client = max14526; //to_i2c_client(%mcdev->dev);// i2c_verify_client(&mcdev->dev); if(!client) { printk("muic %s, client : %d", __func__, client); return -1; } dev_info(&client->dev, "muic: %s entry.\n", __func__); muic_i2c_write_byte(client,SW_CONTROL, OPEN); dp3t_switch_ctrl(DP3T_NC); muic_mdelay(100); /* Connect CP UART signals to AP */ usif_switch_ctrl(USIF_AP); /* AP USB does not pass through DP3T. * Just connect AP UART to MUIC UART. */ dp3t_switch_ctrl(DP3T_AP_UART); /* Connect DP, DM to USB_DP, USB_DM */ muic_i2c_write_byte(client,SW_CONTROL, DP_USB | DM_USB); //muic_path = MUIC_AP_USB; //charging_mode = CHARGING_USB; printk("[MUIC] muic_set_ap_usb_mode(): AP_USB\n"); return 0; }
void set_max14526_muic_path(unsigned char int_stat_value) { unsigned char reg_value; printk(KERN_WARNING "[MUIC] set_max14526_muic_path, int_stat_value = 0x%02x \n", int_stat_value); if (int_stat_value & 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_path = MUIC_CP_USB; charging_mode = CHARGING_FACTORY; } else if ((int_stat_value & IDNO) == IDNO_0100) { set_max14526_cp_uart_mode(); muic_path = MUIC_CP_UART; charging_mode = CHARGING_FACTORY; } else if (int_stat_value & CHGDET) { muic_i2c_write_byte(muic_client,SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ); muic_path = MUIC_LG_TA; charging_mode = CHARGING_LG_TA; } else { muic_i2c_write_byte(muic_client,SW_CONTROL, COMP2_TO_HZ | COMN1_TO_C1COMP); muic_mdelay(2); muic_i2c_read_byte(muic_client,STATUS, ®_value); if (reg_value & C1COMP) { muic_i2c_write_byte(muic_client,SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ); muic_path = MUIC_LG_TA; charging_mode = CHARGING_LG_TA; } else { set_max14526_ap_usb_mode(); muic_path = MUIC_AP_USB; charging_mode = CHARGING_USB; } } } else { if ((int_stat_value & IDNO) == IDNO_0010) { set_max14526_ap_uart_mode(); muic_path = MUIC_AP_UART; charging_mode = CHARGING_NONE; } else if ((int_stat_value & IDNO) == IDNO_0100) { set_max14526_cp_uart_mode(); muic_path = MUIC_CP_UART; charging_mode = CHARGING_NONE; } else { muic_path = MUIC_UNKNOWN; charging_mode = CHARGING_NONE; } } }
/* * Initialize MUIC, i.e., the CONTROL_1,2 and SW_CONTROL registers. * 1) Prepare to sense INT_STAT and STATUS bits. * 2) Open MUIC paths. -> To keep the path from uboot setting, remove this stage. */ void muic_init_ts5usba33402(TYPE_RESET reset) { printk(KERN_INFO "[MUIC] muic_init_ts5usba33402()\n"); if (reset == RESET) { /* Clear default switch position (0x03=0x24) */ muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ); } /* * Iniialize ts5usba33402 for detection of accessories * Enable 200K pull-up and ADC (0x01=0x12) * Enable interrupt and set AUD Click/Pop resistor (0x02=0x50) */ muic_i2c_write_byte(SW_CONTROL, 0x3F); muic_i2c_write_byte(CONTROL_1, ID_200 | SEMREN | CP_EN); // muic_i2c_write_byte(CONTROL_2, INT_EN); muic_mdelay(300); return; }
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; }
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_ts5usba33402_detect_accessory(s32 upon_irq) { s32 ret = 0; u8 int_stat_value; muic_mdelay(70); /* Read INT_STAT */ ret = muic_i2c_read_byte(INT_STAT, &int_stat_value); printk("[MUIC] muic_ts5usba33402_detect_accessory, int_stat_value:0x%02x \n", int_stat_value); if (ret < 0) { printk(KERN_INFO "[MUIC] INT_STAT reading failed\n"); muic_path = MUIC_UNKNOWN; charging_mode = muic_path; //set_muic_charger_detected(); return ret; } /* Branch according to the previous muic_path */ switch (muic_path) { /* * MUIC_UNKNOWN is reached in two cases both do not have nothing to do with IRQ. * First, at the initialization time where the muic_path is not available yet. * Second, whenever the current muic_path detection is failed. */ case MUIC_UNKNOWN : /* * If the previous muic_path was MUIC_NONE, * the only possible condition for a MUIC IRQ is plugging in an accessory. */ case MUIC_NONE : set_ts5usba33402_muic_path(int_stat_value); break; /* * If the previous muic_path 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_AP_UART : case MUIC_CP_UART : if ((int_stat_value & IDNO) == IDNO_1011) { muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ); muic_path = MUIC_NONE; charging_mode = CHARGING_NONE; } break; case MUIC_NA_TA : case MUIC_LG_TA : case MUIC_TA_1A : case MUIC_INVALID_CHG : if (((int_stat_value & VBUS) == 0) || ((int_stat_value & CHGDET) == 0)) { muic_path = MUIC_NONE; charging_mode = CHARGING_NONE; } break; case MUIC_AP_USB : case MUIC_CP_USB : if ((int_stat_value & VBUS) == 0) { /* USB host removed */ muic_path = MUIC_NONE; charging_mode = CHARGING_NONE; } break; #if defined (CONFIG_CX2_MHL_TX_SII9244) case MUIC_MHL : printk(KERN_WARNING "[MUIC] Detect step3 mhl \n"); if ((int_stat_value & VBUS) == 0) { MHL_On(0); muic_path = MUIC_NONE; } break; #endif default : printk(KERN_WARNING "[MUIC] Failed to detect an accessory. Try again!"); muic_path = MUIC_UNKNOWN; charging_mode = CHARGING_NONE; ret = -1; } printk(KERN_WARNING "[MUIC] muic_ts5usba33402_detect_accessory, muic_path = %s\n", muic_path_str[muic_path]); if (muic_path == MUIC_UNKNOWN || muic_path == MUIC_NONE){ muic_init_ts5usba33402(RESET); gpio_set_value(IFX_USB_VBUS_EN_GPIO, 0); printk(KERN_INFO "[MUIC] charging_ic_deactive()\n"); } //set_muic_charger_detected(); return ret; }
s32 muic_max14526_detect_accessory(s32 upon_irq) { s32 ret = 0; u8 int_stat_value; /* For detecting time */ muic_mdelay(250); /* Reads INT_STAT */ ret = muic_i2c_read_byte(muic_client,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_path = MUIC_UNKNOWN; charging_mode = CHARGING_UNKNOWN; //LGE_CHANGE_S [[email protected]] let charger know muic detected charger type.. //set_muic_charger_detected(); return ret; } /* Branches according to the previous muic_path */ switch (muic_path) { /* MUIC_UNKNOWN is reached in two cases both do not have nothing to do with IRQ. * First, at the initialization time where the muic_path is not available yet. * Second, whenever the current muic_path detection is failed. */ case MUIC_UNKNOWN : /* If the previous muic_path was MUIC_NONE, * the only possible condition for a MUIC IRQ is plugging in an accessory. */ case MUIC_NONE : set_max14526_muic_path(int_stat_value); break; /* If the previous muic_path 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 & VBUS) != 0) { set_max14526_muic_path(int_stat_value); } else if ((int_stat_value & IDNO) == IDNO_1011) { charging_mode = CHARGING_NONE; muic_path = MUIC_NONE; } else set_max14526_muic_path(int_stat_value); break; default : printk(KERN_WARNING "[MUIC] Failed to detect an accessory. Try again!"); muic_path = MUIC_UNKNOWN; charging_mode = CHARGING_UNKNOWN; ret = -1; } printk(KERN_WARNING "[MUIC] muic_max14526_detect_accessory, muic_path = %s, charing = %s\n", muic_path_str[muic_path], charging_mode_str[charging_mode]); if (muic_path == MUIC_UNKNOWN || muic_path == MUIC_NONE) { muic_init_max14526(RESET); gpio_set_value(IFX_USB_VBUS_EN_GPIO, 0); printk(KERN_INFO "[MUIC] charging_ic_deactive()\n"); } //LGE_CHANGE_S [[email protected]] let charger know muic detected charger type.. //set_muic_charger_detected(); return ret; }
s32 muic_ts5usba33402_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_ts5usba33402_detect_accessory() was called upon IRQ. */ //if (upon_irq) { muic_mdelay(70); //} /* Read INT_STAT */ ret = muic_i2c_read_byte(INT_STAT, &int_stat_value); printk("[MUIC] muic_ts5usba33402_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; // //set_muic_charger_detected(); return ret; } // muic_set_device_none_detect(int_stat_value); /* Branch 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_ts5usba33402_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_AP_UART : case MUIC_CP_UART : if ((int_stat_value & IDNO) == IDNO_1011) { muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ); muic_mode = MUIC_NONE; charging_mode = CHARGING_NONE; } break; case MUIC_NA_TA : case MUIC_LG_TA : case MUIC_TA_1A : case MUIC_INVALID_CHG : if (((int_stat_value & V_VBUS) == 0) || ((int_stat_value & CHGDET) == 0)) { muic_mode = MUIC_NONE; charging_mode = CHARGING_NONE; } break; case MUIC_AP_USB : case MUIC_CP_USB : /* * Check if V_VBUS == 0 && IDNO == 0x1011 (open). * If so, it's MUIC_NONE. * Otherwise, it's an erronous situation. MUIC_UNKNOWN. */ if((int_stat_value & IDNO) == IDNO_0010) { muic_mode = MUIC_CP_USB; } else if ((int_stat_value & IDNO) == IDNO_0100) { muic_mode = MUIC_CP_UART; } else if ((int_stat_value & V_VBUS) == 0) { /* USB Host Removed */ muic_mode = MUIC_NONE; charging_mode = CHARGING_NONE; } 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; } break; #endif default: printk(KERN_WARNING "[MUIC] Failed to detect an accessory. Try again!"); muic_mode = MUIC_UNKNOWN; charging_mode = CHARGING_NONE; ret = -1; break; } if(muic_mode == MUIC_UNKNOWN || muic_mode == MUIC_NONE){ muic_init_ts5usba33402(RESET); gpio_set_value(IFX_USB_VBUS_EN_GPIO, 0); printk(KERN_INFO "[MUIC] charging_ic_deactive()\n"); } // // printk( "[MUIC] muic_ts5usba33402_detect_accessory, muic_mode = %s (%d) \n", muic_mode_str[muic_mode], muic_mode); return ret; }
void set_ts5usba33402_muic_mode(unsigned char int_stat_value) { gpio_set_value(GPIO_CP_UART_SW, 0); gpio_set_value(GPIO_CP_USB_VBUS_EN, 0); #if defined(CONFIG_LU6500) muic_i2c_write_byte(SW_CONTROL, DP_OPEN | DM_OPEN); #else muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ); #endif muic_i2c_write_byte(CONTROL_1, ID_200 | SEMREN | CP_EN); muic_mdelay(10); 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_ts5usba33402_cp_usb_mode(); muic_mode = MUIC_CP_USB; charging_mode = CHARGING_FACTORY; } else if ((int_stat_value & IDNO) == IDNO_0100) { set_ts5usba33402_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_USB; #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 { set_ts5usba33402_ap_usb_mode(); muic_mode = MUIC_AP_USB; charging_mode = CHARGING_USB; } } else { if ((int_stat_value & IDNO) == IDNO_0010) { set_ts5usba33402_ap_uart_mode(); muic_mode = MUIC_AP_UART; charging_mode = CHARGING_NONE; } else if ((int_stat_value & IDNO) == IDNO_0100) { set_ts5usba33402_cp_uart_mode(); muic_mode = MUIC_CP_UART; charging_mode = CHARGING_NONE; } else { muic_mode = MUIC_UNKNOWN; charging_mode = CHARGING_NONE; } } #if 0 // unsigned char reg_value; s32 ret = 0; printk(KERN_INFO "[MUIC] %s : int_stat_value = 0x%x \n" ,__func__ ,int_stat_value); /*if(retain_mode == BOOT_CP_USB){ muic_set_develop_mode_detect(); }else */if (int_stat_value & CHGDET) { printk(KERN_INFO "[MUIC] %s : muic_mode is CHGDET (%d) \n" ,__func__ ,muic_mode); muic_set_charger_detect(int_stat_value); } else if((int_stat_value & IDNO) == IDNO_0100 ) { printk(KERN_INFO "[MUIC] %s : muic_mode is 130Kohm CP_UART (%d) \n" ,__func__ ,muic_mode); /* IDNO=0100? 130Kohm :: CP_UART */ muic_set_factory_mode_detect(IDNO_0100); } else if((int_stat_value & IDNO) == IDNO_1010) { printk(KERN_INFO "[MUIC] %s : muic_mode is 910KOhm AP_USB (%d) \n" ,__func__ ,muic_mode); /* IDNO=0100? 910KOhm :: CP_USB */ muic_set_factory_mode_detect(IDNO_1010); } else if ((int_stat_value & IDNO) == IDNO_0010) { /* IDNO=0010? 56Kohm :: USB_MODE */ muic_set_develop_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 == 0x30) || (int_stat_value == 0x11) || (int_stat_value == 0x10)) { muic_set_special_test_mode_detect(); #endif// } else if (int_stat_value & V_VBUS) { /* Standard USB Host Detected (0x03=0x23) */ /* Read a status reigster(0x05) */ ret = muic_i2c_read_byte(STATUS, ®_value); if (reg_value & DCPORT || reg_value & CHPORT) { /* Charger Detected*/ /* COMP2/COMN1 to H-Z (0x03=0x24) */ muic_i2c_write_byte(SW_CONTROL, COMP2_TO_HZ | COMN1_TO_HZ); muic_mode = MUIC_NA_TA; } else { #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) */ muic_set_usb_mode_detect(); // Turn on USB switches muic_mode = MUIC_AP_USB; } #else ///* Standard USB Host Detected (0x03=0x23) */ muic_set_usb_mode_detect(); // Turn on USB switches muic_mode = MUIC_AP_USB; #endif } } else if ((int_stat_value & IDNO ) == IDNO_0001) { /* Vidoe Cable 24k registor Detected - No TV Attached */ //current_device = DEVICE_VIDEO_CABLE_NO_LOAD; } else if ((int_stat_value & IDNO) == IDNO_0000 ) { //Set_MUIC_Other_Mode_Detect(); } else { /* Accessory Not Supported */ muic_mode = MUIC_NONE; } #endif }