Exemple #1
0
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);
	}
}
Exemple #2
0
static ssize_t muic_proc_write(struct file *filp, const char *buf, size_t len, loff_t *off)
{
#if defined (CONFIG_MACH_BSSQ)|| defined (CONFIG_MACH_STAR)
	char nv_msg[1];
#endif 
#if 0 //[email protected] for Fixed
	char cmd;
	char nv_msg[1];

	len = sscanf(buf, "%c", &cmd/*, &dummy*/);	//[[email protected]] - what is dummy ?
#else
    char messages[10];
    s8 reg, val;
	char cmd;

    if (len > 12)
        len = 12;

    if (copy_from_user(messages, buf, len))
        return -EFAULT;

    sscanf(buf, "%c %x %x", &cmd, &reg, &val);
#endif
#if defined(CONFIG_LU6500)
    //port open for TI
	gpio_set_value(GPIO_CP_UART_SW, 0);
	gpio_set_value(GPIO_CP_USB_VBUS_EN, 0);

	muic_i2c_write_byte(SW_CONTROL, DP_OPEN | DM_OPEN);
	muic_i2c_write_byte(CONTROL_1, ID_200 | SEMREN | CP_EN);

	mdelay(1);
#endif
	switch (cmd) {
		/* AP_UART mode*/
		case '6' :
		retain_mode = RETAIN_AP_UART;
			muic_proc_set_ap_uart();
			break;

			/* CP_UART mode*/
		case '7' :
		retain_mode = RETAIN_CP_UART;
			muic_proc_set_cp_uart();
			break;

			/* AP_USB mode*/
		case '8' :
		retain_mode = RETAIN_AP_USB;
                boot_retain_mode = RETAIN_NO;
			muic_proc_set_ap_usb();
			break;

			/* CP_USB mode*/
		case '9' :
		retain_mode = RETAIN_CP_USB;
			muic_proc_set_cp_usb();
			mdelay(20);
			break;

#ifndef CP_RESET_TEST
			/* CP_DOWNLOAD mode*/
	case '0' :
		retain_mode = RETAIN_CP_USB;
		case 'c' :
			muic_proc_set_cp_usb();
			mdelay(1000);
			muic_cp_reset();
			//mdelay(400);
			break;
		case 'q' :
			muic_cp_request();
			break;
		case 'r' :
			muic_cp_reset();
			break;
#endif//		

#if defined(CONFIG_MUIC_RETAIN)
			/* Rebooting should be performed by HiddenMenu Application. */
		case '1':
		retain_mode = RETAIN_NO;
			/* NO retain mode after reboot */
			//set_misc_msg(msg_type_muic_path,retain_mode_str[NO_RETAIN], RETAIN_MODE_STR_LENGTH+1);
			nv_msg[0] = RETAIN_NO;
#ifdef CONFIG_MACH_STAR
                        lge_nvdata_write(LGE_NVDATA_MUIC_RETENTION_OFFSET, nv_msg, 1);
#else
			lge_nvdata_write(LGE_NVDATA_MUIC_PATH_STR_OFFSET, "muic-path-none", 32);
#endif
			break;

		case 'a' :
			/* AP USB retain mode after reboot */
			//set_misc_msg(msg_type_muic_path,retain_mode_str[BOOT_AP_USB], RETAIN_MODE_STR_LENGTH+1);
			nv_msg[0] = RETAIN_AP_USB;
#ifdef CONFIG_MACH_STAR
                        lge_nvdata_write(LGE_NVDATA_MUIC_RETENTION_OFFSET, nv_msg, 1);
#else
			lge_nvdata_write(LGE_NVDATA_MUIC_PATH_STR_OFFSET, "muic-path-ap", 32);
#endif
			break;

		case 'b' :
			/* CP USB retain mode after reboot */
			//set_misc_msg(msg_type_muic_path,retain_mode_str[BOOT_CP_USB], RETAIN_MODE_STR_LENGTH+1);
			nv_msg[0] = RETAIN_CP_USB;
#ifdef CONFIG_MACH_STAR
                        lge_nvdata_write(LGE_NVDATA_MUIC_RETENTION_OFFSET, nv_msg, 1);
#else
			lge_nvdata_write(LGE_NVDATA_MUIC_PATH_STR_OFFSET,"muic-path-cp", 32);
#endif
			break;
#endif//

#if defined (MUIC_SLEEP)
	        case 'u':
		        /* Just unlock the wakelock ! */
		        wake_lock_enable = 0;
	         	muic_wakeup_lock();
         		break;
	        case 'l':
         		/* Just lock the wakelock ! */
        		wake_lock_enable = 1;
        		muic_wakeup_lock();
        		break;
#endif		
	
#ifdef CONFIG_MACH_STAR
#if defined (CONFIG_USIF)
			case 'y':
					//NvOdmGpioSetState(s_hMuicHandle.hGpio, s_hMuicHandle.h_USIF1_SW, DISABLE);
				printk("AP <==> CP uart connection\n");
				gpio_set_value(USIF_IN_1_GPIO, 0);

				break;
			case 'x':
				//NvOdmGpioSetState(s_hMuicHandle.hGpio, s_hMuicHandle.h_USIF1_SW, ENABLE);
				printk("AP =\\= CP uart disconnection\n");
				gpio_set_value(USIF_IN_1_GPIO, 1);
				break;
#endif				
			case 'n':
				printk("TA <==> DEVICE charger connection [%d] [%d]\n",g_half_charging_control,charging_mode);
					switch (g_half_charging_control) {
							case CHARGING_USB:
								charger_ic_set_mode_for_muic(CHARGER_USB500); 
								break;

							case CHARGING_NA_TA:
							case CHARGING_LG_TA:
							case CHARGING_TA_1A:
								charger_ic_set_mode_for_muic(CHARGER_ISET);
								break;

							case CHARGING_FACTORY:
								//	charger_ic_set_mode(CHARGER_FACTORY);
								break;

							case CHARGING_NONE:
								charger_ic_disable_for_muic();
								break;

							default:
								charger_ic_disable_for_muic();
								break;
						}				
				break;		
			case 'd':
				printk("TA =\\=  DEVICE charger disconnection %d\n",charging_mode);
				g_half_charging_control=charging_mode;
				charger_ic_disable_for_muic();
				break;	

			case 'k':
				printk("######[MUIC] Boot complete check charger cable and update charging_mode %d\n",charging_mode);
				muic_send_charger_type(charging_mode);
				break;
#endif
		default : 
			DBG("[MUIC] LGE: ap20 MUIC invalid command: [cmd=%c] 6=AP_UART, 7=CP_UART, 8=AP_USB, 9=CP_USB\n", cmd);
			break;
	}
	check_charging_mode();	//check the charging mode, but NOT send to charger !!!

	return len;
}
Exemple #3
0
/*
 * muic_probe() is called in the middle of booting sequence due to '__init'.
 * '__init' causes muic_probe() to be released after the booting.
 */
static s32 __devinit muic_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	s32 ret = 0;
	muic_client = client;

	DBG("[MUIC] LG muic_probe() Begin\n");
#if defined (CONFIG_USIF)
	/* 
	 * Initializes gpio_165 (USIF1_SW).
	 * Checks if other driver already occupied it.
	 */
	ret = gpio_request(USIF_IN_1_GPIO, "USIF switch control GPIO");
	if (ret < 0) {
		DBG("[MUIC] GPIO 165 USIF1_SW is already occupied by other driver!\n");
		/*
		 * We know board_cosmo.c:ifx_n721_configure_gpio() performs a gpio_request on this pin first.
		 * Because the prior gpio_request is also for the analog switch control, this is not a confliction.
		 */
		return -ENOSYS;
	}
#if 0
	ret = gpio_direction_output(USIF_IN_1_GPIO, 0); // USIF_IN_1 ==> GPIO_PU3 not use in P999
#else
     ret = gpio_direction_output(USIF_IN_1_GPIO, 1);
#endif
	if (ret < 0) {
		DBG("[MUIC] gpio_16 USIF_IN_1_GPIO direction initialization failed!\n");
		return -ENOSYS;
	}
	tegra_gpio_enable(USIF_IN_1_GPIO);
#endif	//

#if defined (CONFIG_LGE_MUIC_DP3T)
	/*
	 * Initializes gpio_11 (OMAP_UART_SW) and gpio_12 (IFX_UART_SW).
	 * Checks if other driver already occupied them.
	 */
	ret = gpio_request(DP3T_IN_1_GPIO, "DP3T switch control 1 GPIO");
	if (ret < 0) {
		DBG("[MUIC] GPIO 11 DP3T_IN_1_GPIO is already occupied by other driver!\n");
		return -ENOSYS;
	}

	ret = gpio_direction_output(DP3T_IN_1_GPIO, 0);
	if (ret < 0) {
		DBG("[MUIC] gpio_11 DP3T_IN_1_GPIO direction initialization failed!\n");
		return -ENOSYS;
	}
	tegra_gpio_enable(DP3T_IN_1_GPIO);


	DBG("[MUIC] Old REV_D has AP_UART --- initalizing DP3T_IN_2_GPIO\n");
	ret = gpio_request(DP3T_IN_2_GPIO, "DP3T switch control 2 GPIO");
	if (ret < 0) {
		DBG("[MUIC] gpio_12 DP3T_IN_2_GPIO is already occupied by other driver!\n");
		return -ENOSYS;
	}

	ret = gpio_direction_output(DP3T_IN_2_GPIO, 0);
	if (ret < 0) {
		DBG("[MUIC] gpio_12 DP3T_IN_2_GPIO direction initialization failed!\n");
		return -ENOSYS;
	}
	tegra_gpio_enable(DP3T_IN_2_GPIO);


	ret = gpio_request(IFX_USB_VBUS_EN_GPIO, "DP3T switch control 2 GPIO");
	if (ret < 0) {
		DBG("[MUIC] gpio_55 IFX_USB_VBUS_EN_GPIO is already occupied by other driver!\n");
		return -ENOSYS;
	}

	ret = gpio_direction_output(IFX_USB_VBUS_EN_GPIO, 0);
	if (ret < 0) {
		DBG("[MUIC] gpio_55 IFX_USB_VBUS_EN_GPIO direction initialization failed!\n");
		return -ENOSYS;
	}
	tegra_gpio_enable(IFX_USB_VBUS_EN_GPIO);
#endif//

#if defined (CONFIG_MACH_BSSQ)

#if defined(CONFIG_LU6500)
  if(get_lge_pcb_revision() > REV_D)
    muic_intr_gpio = GPIO_MUIC_INT_N_REV_E;
#endif
	printk("[kdh] config_mach_bssq\n");
	gpio_request(muic_intr_gpio, "muic_int_n");
	tegra_gpio_enable(muic_intr_gpio);
	gpio_direction_input(muic_intr_gpio);

	gpio_request(GPIO_CP_UART_SW, "uart_sw");
	tegra_gpio_enable(GPIO_CP_UART_SW);
	gpio_direction_output(GPIO_CP_UART_SW, 0);

	gpio_request(GPIO_CP_USB_VBUS_EN, "mdm_usb_vbus_en");
	tegra_gpio_enable(GPIO_CP_USB_VBUS_EN);
	gpio_direction_output(GPIO_CP_USB_VBUS_EN, 0);
#else
	ret = gpio_request(MUIC_GPIO, "pu0");

	if (ret < 0)
	{
		DBG("[MUIC] MUIC_GPIO is already occupied by other driver!\n");
		return -ENOSYS;
	}

	ret=gpio_direction_input(MUIC_GPIO);
	if (ret < 0)
	{
		DBG("[MUIC] MUIC_GPIO direction initialization failed!\n");
		gpio_free(MUIC_GPIO);
		return -ENOSYS;
	}
	else
		tegra_gpio_enable(MUIC_GPIO);
#endif

#if defined (MUIC_SLEEP)
	wake_lock_init(&muic_wake_lock, WAKE_LOCK_SUSPEND, "muic_lock");
#endif

	/* Registers MUIC work queue function */
#if 0//def CONFIG_MACH_STAR_SU660
	INIT_WORK(&muic_work, muic_work_func);
#else
	INIT_WORK(&muic_wq, muic_wq_func);
#endif
	/* 
	 * Set up an IRQ line and enable the involved interrupt handler.
	 * From this point, a MUIC_INT_N can invoke muic_interrupt_handler().
	 * muic_interrupt_handler merely calls schedule_work() with muic_wq_func().
	 * muic_wq_func() actually performs the accessory detection.
	 */
#if defined (CONFIG_MACH_BSSQ)
	muic_gpio_irq = gpio_to_irq(muic_intr_gpio);
	ret = request_irq(muic_gpio_irq, (irq_handler_t)muic_interrupt_handler,IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, client->name, &client->dev);
#else
	muic_gpio_irq = gpio_to_irq(MUIC_GPIO);
	ret = request_irq(muic_gpio_irq, (irq_handler_t)muic_interrupt_handler, IRQF_TRIGGER_FALLING  , client->name, &client->dev);
#endif
	if (ret < 0) {
		DBG("[MUIC] MUIC_GPIO IRQ line set up failed!\n");
		free_irq(muic_gpio_irq, &client->dev);
		return -ENOSYS;
	}
	//disable_irq_wake(MUIC_GPIO);
//#if defined(CONFIG_LU6500)
//  if(get_lge_pcb_revision() > REV_D)  
//  enable_irq_wake(gpio_to_irq(muic_intr_gpio)); 
//#endif

	/* Prepares a human accessible method to control MUIC */
	create_lg_muic_proc_file();

	/* Selects one of the possible muic chips */
	muic_detect_device();

#if defined (CONFIG_MACH_BSSQ)
	if(muic_boot_keeping == TRUE)
	{
		if(muic_boot_path == PORT_SETTING_CP_USB)
			retain_mode = RETAIN_CP_USB;
		else if(muic_boot_path == PORT_SETTING_AP_USB)
			retain_mode = RETAIN_AP_USB;
	}
	printk("[KDH] muic keeping %d boot_path %d\n", muic_boot_keeping,muic_boot_path);
#endif

	/* Initializes MUIC - Finally MUIC INT becomes enabled */
	if (retain_mode == RETAIN_AP_USB) {
		muic_proc_set_ap_usb();	//[[email protected]] was not in cosmo code.
		muic_mode = MUIC_AP_USB;
		muic_init_device(DEFAULT);
		check_charging_mode();
		DBG("[MUIC] muic_init_device... retain mode = AP_USB\n");
	} else if (retain_mode == RETAIN_CP_USB) {
		muic_proc_set_cp_usb();
		muic_mode = MUIC_CP_USB;
		muic_init_device(DEFAULT);
		check_charging_mode();
		DBG("[MUIC] muic_detect_accessory... retain mode = CP_USB\n");
	} else {

		if (muic_init_device)
			muic_init_device(DEFAULT);	//[[email protected]] default is OK(already initialized at bootloader)
		else
			DBG("[MUIC] You should add codes for new MUIC chip");
		if (muic_detect_accessory)
			muic_detect_accessory(NOT_UPON_IRQ);
		else
			DBG("[MUIC] You should add codes for new MUIC chip");
	}

	//[[email protected]]
	set_muic_charger_detected();

	/* Makes the interrupt on MUIC_GPIO INT wake up AP which is in suspend mode */
#if 0
	ret = enable_irq_wake(gpio_to_irq(MUIC_GPIO));
	if (ret < 0) {
		DBG("[MUIC] MUIC_GPIO wake up source setting failed!\n");
		disable_irq_wake(gpio_to_irq(MUIC_GPIO));
		return -ENOSYS;
	}
#endif//
        register_reboot_notifier(&muic_reboot_nb);
	DBG();

	return ret;
}
int muic_init(int isFactoryReset)
{
	unsigned int retain_mode = NO_RETAIN;
			
	unsigned char i2c_ret;
	
	unsigned char reg_val;			
	unsigned char muic_device;		
	
	MUIC_MODE_TYPE muic_mode = MUIC_OPEN;

	char cmd_line[256];

	strcpy(cmd_line, getenv("bootargs"));

#if defined(CONFIG_COSMO_EVB_B)  || defined(CONFIG_COSMO_EVB_C)
	printf("muic chip : I2C4\n");
	select_bus(I2C4 , OMAP_I2C_STANDARD);
#else
	printf("muic chip : I2C3\n");
	select_bus(I2C3 , OMAP_I2C_STANDARD);
#endif 

	i2c_init(OMAP_I2C_STANDARD, MUIC_SLAVE_ADDR);

	i2c_ret = muic_i2c_read_byte(DEVICE_ID, &reg_val);
	if ((reg_val & 0xf0) == 0x10) 
		muic_device = TS5USBA33402;		
	else if ((reg_val & 0xf0) == 0x20)
		muic_device = MAX14526;			
	else if ((reg_val & 0xf0) == ANY_VANDOR_ID)
		muic_device = ANY_VANDOR;

	if (downloadkey()){
		write_muic_retain_mode(NO_RETAIN);
		printf("[MUIC] No retain\n");
	} 

	retain_mode = read_muic_retain_mode();
	
	printf("muic_init muic vendor : %d, reg_val:0x%x, retain_mode = %d\n", muic_device, reg_val, retain_mode);
	if (muic_device == TS5USBA33402) {
		printf("muic chip : TS5USBA33402\n");
		if (retain_mode == RETAIN_AP_USB) {
			muic_i2c_write_byte(CONTROL_1, ID_200 | SEMREN | CP_EN);
			muic_i2c_write_byte(SW_CONTROL, USB);		
			
			muic_mode = MUIC_USB;
			check_charging_mode(&muic_mode);

			printf("[MUIC] retain AP_USB\n");
			printf("\n###[MUIC] USB charger may not have enough power to boot up depends on your board condition..... ###\n");
			printf("\n###[MUIC] You'd better to use TA or PIF for power supply. ###\n");

			strcat(cmd_line, " muic=2");
			setenv("bootargs", cmd_line);
		} else if (retain_mode == RETAIN_CP_USB) {
			muic_i2c_write_byte(SW_CONTROL, OPEN);
			dp3t_switch_ctrl(DP3T_NC);
			muic_mode = MUIC_USB;
			check_charging_mode(&muic_mode);

			printf("[MUIC] retain CP_USB\n");

			strcat(cmd_line, " muic=3");
			setenv("bootargs", cmd_line);
		} else
			muic_mode = muic_device_ts5usba33402(isFactoryReset, cmd_line);
		
	} else if (muic_device == MAX14526) {
		printf("muic chip : MAX14526\n");
		if (retain_mode == RETAIN_AP_USB) {
			muic_i2c_write_byte(CONTROL_1, ID_200 | ADC_EN | CP_EN);
			muic_i2c_write_byte(SW_CONTROL, USB);		
			
			muic_mode = MUIC_USB;
			check_charging_mode(&muic_mode);
			
			printf("[MUIC] retain AP_USB\n");
			printf("\n###[MUIC] USB charger may not have enough power to boot up depends on your board condition..... ###\n");
			printf("\n###[MUIC] You'd better to use TA or PIF for power supply. ###\n");

			strcat(cmd_line, " muic=2");
			setenv("bootargs", cmd_line);
		} else if (retain_mode == RETAIN_CP_USB) {
			muic_i2c_write_byte(SW_CONTROL, OPEN);
			dp3t_switch_ctrl(DP3T_NC);
			muic_mode = MUIC_USB;
			check_charging_mode(&muic_mode);
			
			printf("[MUIC] retain CP_USB\n");

			strcat(cmd_line, " muic=3");
			setenv("bootargs", cmd_line);
		} else
			muic_mode = muic_device_max14526(isFactoryReset, cmd_line);
	} else
		printf("[MUIC] ANY VENDOR, Not supported\n");

	select_bus(I2C1, OMAP_I2C_STANDARD); 

	return muic_mode;
}