Esempio n. 1
0
void fsa9480_force_sleep(void)
{
    struct fsa9480_usbsw *usbsw = chip;
    struct i2c_client *client = usbsw->client;
    u8 value = 0;

    //wake_unlock(&JIGConnect_idle_wake);
    wake_unlock(&JIGConnect_suspend_wake);
#ifdef CONFIG_KONA_PI_MGR
    pi_mgr_qos_request_update(&qos_node, PI_MGR_QOS_DEFAULT_VALUE);
#endif
    if(muic_type==muicTypeFSA880)
    {
        fsa9480_read_reg(client, FSA9480_REG_MANSW2, &value);
        fsa9480_write_reg(client, FSA9480_REG_MANSW2, 0x00);

        fsa9480_read_reg(client, FSA9480_REG_CTRL, &value);
        fsa9480_write_reg(client, FSA9480_REG_CTRL, 0x00);
    }
    else
    {
        fsa9480_read_reg(client, FSA9480_REG_CTRL, &value);
        value &= ~MANUAL_SWITCH;
        fsa9480_write_reg(client, FSA9480_REG_CTRL, value);

        fsa9480_read_reg(client, FSA9480_REG_MANSW2, &value);
        value &= ~MANSW2_JIG;
        fsa9480_write_reg(client, FSA9480_REG_MANSW2, value);
    }
}
Esempio n. 2
0
static void TSU8111_Charger_Enable(void)
{
	u8 val1,dev1;
	int ret = 0;
	struct i2c_client *client = chip->client;
	pr_info("%s\n",__func__);

	fsa9480_write_reg(client, FSA9480_REG_CHG_CTRL2, 0x89); // set EOC current 130mA, Full 4.18V

	fsa9480_read_reg(client, FSA9480_REG_DEV_T1, &dev1);

	if( (dev1 & (FSA9480_DEV_T1_CHARGER_MASK|DEV_USB_CHG)) || (dev1==DEV_VBUS))
		fsa9480_write_reg(client, FSA9480_REG_CHG_CTRL3, 0xD9); // 650mA
	else
		fsa9480_write_reg(client, FSA9480_REG_CHG_CTRL3, 0xD5); // 450mA
	
	fsa9480_read_reg(client, FSA9480_REG_CHG_CTRL1, &val1);
	val1 &= ~CH_DIS;
	val1 |= FCMEN;
	
	// Set Fast Charge Timer 6 Hour
	val1 &= ~0x03; val1 |= 0x01;
	
	pr_info("%s. Register(%d) = (0x%X)\n", __func__, FSA9480_REG_CHG_CTRL1, val1);
	ret = fsa9480_write_reg(client, FSA9480_REG_CHG_CTRL1, val1);
	if (ret < 0) {
		printk("[FSA9480] I2C write fail\n");
	}
		
	return ;
}
Esempio n. 3
0
int get_real_usbic_state(void)
{
       struct fsa9480_usbsw *usbsw = chip;
       int ret = MICROUSBIC_NO_DEVICE ;
       u8 val1 = 0;
       u8 val2 = 0;

       /* read real usb ic state
       val1 = chip->dev1;
       val2 = chip->dev2;
       */
       struct i2c_client *client = usbsw->client;
       fsa9480_read_reg(client, FSA9480_REG_DEV_T1, &val1);
       fsa9480_read_reg(client, FSA9480_REG_DEV_T2, &val2);

       if (val1 & FSA9480_DEV_T1_USB_MASK)
               ret = MICROUSBIC_USB_CABLE;
       else if (val1 & FSA9480_DEV_T1_CHARGER_MASK)
               ret = MICROUSBIC_USB_CHARGER;
       else if (val1 & FSA9480_DEV_T1_UART_MASK)
               ret = MICROUSBIC_USB_CHARGER;
	   else if (val1 & FSA9480_DEV_T1_HOST_MASK)
		   	   ret = MICROUSBIC_HOST;

       if (ret ==  MICROUSBIC_NO_DEVICE) {
               if (val2 & DEV_JIG_USB_ON)
				   ret = MICROUSBIC_JIG_USB_ON;
			   else if (val2 & FSA9480_DEV_T2_MHL_MASK)
				   ret = MICROUSBIC_MHL_CHARGER;
       }

       return ret;
}
Esempio n. 4
0
static void TSU8111_Charger_BackCHG_Enable(void)
{
	u8 val1,dev1;
	int ret = 0;
	struct i2c_client *client = chip->client;
	pr_info("%s\n",__func__);

	fsa9480_write_reg(client, FSA9480_REG_CHG_CTRL2, 0x19); // set EOC current 60mA, Full 4.18V

	fsa9480_read_reg(client, FSA9480_REG_DEV_T1, &dev1);

	if( dev1 & FSA9480_DEV_T1_CHARGER_MASK)
		fsa9480_write_reg(client, FSA9480_REG_CHG_CTRL3, 0xD9); // 650mA
	else
		fsa9480_write_reg(client, FSA9480_REG_CHG_CTRL3, 0xD5); // 450mA
	
	fsa9480_read_reg(client, FSA9480_REG_CHG_CTRL1, &val1);
	val1 &= ~CH_DIS;
	val1 |= FCMEN;
	pr_info("%s. Register(%d) = (0x%X)\n", __func__, FSA9480_REG_CHG_CTRL1, val1);
	ret = fsa9480_write_reg(client, FSA9480_REG_CHG_CTRL1, val1);
	if (ret < 0) {
		printk("[FSA9480] I2C write fail\n");
	}
		
	return ;
}
Esempio n. 5
0
static void tsu8111_check_ovp()
{
	 struct i2c_client *client = chip->client;
	u8 val1,chg_status;
	
	msleep(300);	
       fsa9480_read_reg(client, FSA9480_REG_DEV_T1, &val1);
   	fsa9480_read_reg(client, FSA9480_REG_CHG_STATUS, &chg_status);
	
  	printk("check ovp: dev1: 0x%x, chg_status: 0x%x\n",val1, chg_status);		
		
	if( (val1 & DEV_VBUS) && (chg_status & (CH_FAULT|CH_IDLE)) ){
		ovp_status = 1;
#if defined(CONFIG_BATTERY_D2083)
		if(spa_external_event)
			spa_external_event(D2083_CATEGORY_BATTERY, D2083_EVENT_OVP_CHARGE_STOP);
#endif		
		pr_info("%s: OVP Chg Stop\n",__func__);
	}
	else if( ovp_status==1 ){

		if( chg_status & (CH_FC|CH_CV) ){
			ovp_status = 0;
#if defined(CONFIG_BATTERY_D2083)
			if(spa_external_event)
				spa_external_event(D2083_CATEGORY_BATTERY, D2083_EVENT_OVP_CHARGE_RESTART);
#endif		
			pr_info("%s: OVP Chg Restart\n",__func__);
		}
	}
}
Esempio n. 6
0
static ssize_t fsa9480_show_device(struct device *dev,
				   struct device_attribute *attr,
				   char *buf)
{
	struct fsa9480_usbsw *usbsw = dev_get_drvdata(dev);
	struct i2c_client *client = usbsw->client;
	int dev1, dev2;

	dev1 = fsa9480_read_reg(client, FSA9480_REG_DEV_T1);
	dev2 = fsa9480_read_reg(client, FSA9480_REG_DEV_T2);

	if (!dev1 && !dev2)
		return sprintf(buf, "NONE\n");

	/* USB */
	if (dev1 & DEV_T1_USB_MASK || dev2 & DEV_T2_USB_MASK)
		return sprintf(buf, "USB\n");

	/* UART */
	if (dev1 & DEV_T1_UART_MASK || dev2 & DEV_T2_UART_MASK)
		return sprintf(buf, "UART\n");

	/* CHARGER */
	if (dev1 & DEV_T1_CHARGER_MASK)
		return sprintf(buf, "CHARGER\n");

	/* JIG */
	if (dev2 & DEV_T2_JIG_MASK)
		return sprintf(buf, "JIG\n");

	return sprintf(buf, "UNKNOWN\n");
}
Esempio n. 7
0
static int fsa9480_resume(struct i2c_client *client) 
{ 
       struct fsa9480_usbsw *usbsw = i2c_get_clientdata(client); 
       int dev1, dev2; 
 
       dev1 = fsa9480_read_reg(client, FSA9480_REG_DEV_T1); 
       dev2 = fsa9480_read_reg(client, FSA9480_REG_DEV_T2); 
 
       /* device detection */ 
       fsa9480_detect_dev(usbsw, (dev1 || dev2) ? INT_ATTACH : INT_DETACH); 
 
       return 0; 
} 
Esempio n. 8
0
int get_usb_cable_state(void)
{ //Xmister
	struct fsa9480_usbsw *usbsw = chip; 
       struct i2c_client *client = usbsw->client; 
       int dev1, dev2; 
 
       dev1 = fsa9480_read_reg(client, FSA9480_REG_DEV_T1); 
       dev2 = fsa9480_read_reg(client, FSA9480_REG_DEV_T2); 
 
       if (!dev1 && !dev2) 
               return 0;
 
       return (dev2 << 8) | (dev1 << 0);
}
Esempio n. 9
0
static void EnableFSA9480Interrupts(void)
{
	struct fsa9480_usbsw *usbsw = chip;
	struct i2c_client *client = usbsw->client;
	u8 intr, intr2;

	printk ("EnableFSA9480Interrupts\n");

     /*clear interrupts*/
     fsa9480_read_reg(client, FSA9480_REG_INT1, &intr);
     fsa9480_read_reg(client, FSA9480_REG_INT2, &intr2);
	 
     fsa9480_write_reg(client, FSA9480_REG_INT1_MASK, 0x00);
     fsa9480_write_reg(client, FSA9480_REG_INT2_MASK, 0x00);

} //EnableFSA9480Interrupts()
Esempio n. 10
0
static void fsa9480_set_switch(const char *buf)
{
	struct fsa9480_usbsw *usbsw = chip;
	struct i2c_client *client = usbsw->client;
	unsigned int value;
	unsigned int path = 0;

	value = fsa9480_read_reg(client, FSA9480_REG_CTRL);

	if (!strncmp(buf, "VAUDIO", 6)) {
		path = SW_VAUDIO;
		value &= ~CON_MANUAL_SW;
	} else if (!strncmp(buf, "UART", 4)) {
		path = SW_UART;
		value &= ~CON_MANUAL_SW;
	} else if (!strncmp(buf, "AUDIO", 5)) {
		path = SW_AUDIO;
		value &= ~CON_MANUAL_SW;
	} else if (!strncmp(buf, "DHOST", 5)) {
		path = SW_DHOST;
		value &= ~CON_MANUAL_SW;
	} else if (!strncmp(buf, "AUTO", 4)) {
		path = SW_AUTO;
		value |= CON_MANUAL_SW;
	} else {
		printk(KERN_ERR "Wrong command\n");
		return;
	}

	usbsw->mansw = path;
	fsa9480_write_reg(client, FSA9480_REG_MANSW1, path);
	fsa9480_write_reg(client, FSA9480_REG_CTRL, value);
}
Esempio n. 11
0
static void fsa9480_read_adc_value(void)
{
	u8 adc=0;
    struct fsa9480_usbsw *usbsw = chip;
    struct i2c_client *client = usbsw->client;
	
	fsa9480_read_reg(client, FSA9480_REG_ADC, &adc);
	printk("[FSA9480] %s: adc is 0x%x\n",__func__,adc);
}
Esempio n. 12
0
static ssize_t fsa9480_set_syssleep(struct device *dev,
                                   struct device_attribute *attr,
                                   const char *buf, size_t count)
{
	struct fsa9480_usbsw *usbsw = chip;
	struct i2c_client *client = usbsw->client;
	u8 value = 0;

	if (!strncmp(buf, "1", 1))
	{
		//wake_unlock(&JIGConnect_idle_wake);
		wake_unlock(&JIGConnect_suspend_wake);
#ifdef CONFIG_KONA_PI_MGR
		pi_mgr_qos_request_update(&qos_node, PI_MGR_QOS_DEFAULT_VALUE);
#endif
		if(muic_type==muicTypeFSA880)
		{
			fsa9480_read_reg(client, FSA9480_REG_MANSW2, &value);
			fsa9480_write_reg(client, FSA9480_REG_MANSW2, 0x00);

			fsa9480_read_reg(client, FSA9480_REG_CTRL, &value);
			fsa9480_write_reg(client, FSA9480_REG_CTRL, 0x00);
		}
		else
		{
			fsa9480_read_reg(client, FSA9480_REG_CTRL, &value);
			value &= ~MANUAL_SWITCH;
			fsa9480_write_reg(client, FSA9480_REG_CTRL, value);
		
			fsa9480_read_reg(client, FSA9480_REG_MANSW2, &value);
			value &= ~MANSW2_JIG;
			fsa9480_write_reg(client, FSA9480_REG_MANSW2, value);
		}
		//isManual=1;
	}
	else
	{
		fsa9480_read_reg(client, FSA9480_REG_CTRL, &value);
		value |= MANUAL_SWITCH;
		fsa9480_write_reg(client, FSA9480_REG_CTRL, value);
	}
	return count;
}
Esempio n. 13
0
static int fsa9480_resume(struct i2c_client *client)
{
	struct fsa9480_usbsw *usbsw = i2c_get_clientdata(client);
	int dev1, dev2;

	if (device_may_wakeup(&client->dev) && client->irq)
		disable_irq_wake(client->irq);

	/*
	 * Clear Pending interrupt. Note that detect_dev does what
	 * the interrupt handler does. So, we don't miss pending and
	 * we reenable interrupt if there is one.
	 */
	fsa9480_read_reg(client, FSA9480_REG_INT1);
	fsa9480_read_reg(client, FSA9480_REG_INT2);

	dev1 = fsa9480_read_reg(client, FSA9480_REG_DEV_T1);
	dev2 = fsa9480_read_reg(client, FSA9480_REG_DEV_T2);

	/* device detection */
	fsa9480_detect_dev(usbsw, (dev1 || dev2) ? INT_ATTACH : INT_DETACH);

	return 0;
}
Esempio n. 14
0
int fsa9480_read_charge_current(u8 *val)
{
	u8 val1;
	int ret = 0;
	struct i2c_client *client = chip->client;

	ret = fsa9480_read_reg(client, FSA9480_REG_CHG_CTRL3, &val1);
	if(ret < 0)
		ret = -EIO;
	else {
		*val = val1;
	}

	return ret;
}
Esempio n. 15
0
static void TSU8111_Charger_Disable(void)
{
	u8 val1;
	int ret = 0;
	struct i2c_client *client = chip->client;
	pr_info("%s\n",__func__);

	fsa9480_read_reg(client, FSA9480_REG_CHG_CTRL1, &val1);
	val1 |= CH_DIS;
	pr_info("%s. Register(%d) = (0x%X)\n", __func__, FSA9480_REG_CHG_CTRL1, val1);
	ret = fsa9480_write_reg(client, FSA9480_REG_CHG_CTRL1, val1);
	if (ret < 0) {
		printk("[FSA9480] I2C write fail\n");
	}

	return ;
}
Esempio n. 16
0
int fsa9480_is_back_chg()
{
	u8 val1;
	int ret = 0;

	struct i2c_client *client = chip->client;

	ret = fsa9480_read_reg(client, FSA9480_REG_CHG_CTRL2, &val1);
	if(ret < 0)
		ret = -EIO;

	if( val1==0x19)	// 0x19 // set EOC current 60mA, Full 4.18V
		return 1;
	else
		return 0;
	
}
Esempio n. 17
0
static ssize_t fsa9480_get_switch(char *buf)
{
	struct fsa9480_usbsw *usbsw = chip;
	struct i2c_client *client = usbsw->client;
	unsigned int value;

	value = fsa9480_read_reg(client, FSA9480_REG_MANSW1);

	if (value == SW_VAUDIO)
		return sprintf(buf, "VAUDIO\n");
	else if (value == SW_UART)
		return sprintf(buf, "UART\n");
	else if (value == SW_AUDIO)
		return sprintf(buf, "AUDIO\n");
	else if (value == SW_DHOST)
		return sprintf(buf, "DHOST\n");
	else if (value == SW_AUTO)
		return sprintf(buf, "AUTO\n");
	else
		return sprintf(buf, "%x", value);
}
Esempio n. 18
0
ssize_t fsa9480_get_switch(char *buf)
{
struct fsa9480_usbsw *usbsw = chip;
       struct i2c_client *client = usbsw->client;
       u8 value;

       fsa9480_read_reg(client, FSA9480_REG_MANSW1, &value);

       if (value == VAUDIO)
               return sprintf(buf, "VAUDIO\n");
       else if (value == UART)
               return sprintf(buf, "UART\n");
       else if (value == AUDIO)
               return sprintf(buf, "AUDIO\n");
       else if (value == DHOST)
               return sprintf(buf, "DHOST\n");
       else if (value == AUTO)
               return sprintf(buf, "AUTO\n");
       else
               return sprintf(buf, "%x", value);
}
Esempio n. 19
0
static int fsa9480_irq_init(struct fsa9480_usbsw *usbsw)
{
	struct fsa9480_platform_data *pdata = usbsw->pdata;
	struct i2c_client *client = usbsw->client;
	int ret;
	int intr;
	unsigned int ctrl = CON_MASK;

	/* clear interrupt */
	fsa9480_read_irq(client, &intr);

	/* unmask interrupt (attach/detach only) */
	fsa9480_write_reg(client, FSA9480_REG_INT1_MASK, 0xfc);
	fsa9480_write_reg(client, FSA9480_REG_INT2_MASK, 0x1f);

	usbsw->mansw = fsa9480_read_reg(client, FSA9480_REG_MANSW1);

	if (usbsw->mansw)
		ctrl &= ~CON_MANUAL_SW;	/* Manual Switching Mode */

	fsa9480_write_reg(client, FSA9480_REG_CTRL, ctrl);

	if (pdata && pdata->cfg_gpio)
		pdata->cfg_gpio();

	if (client->irq) {
		ret = request_threaded_irq(client->irq, NULL,
				fsa9480_irq_handler,
				IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
				"fsa9480 micro USB", usbsw);
		if (ret) {
			dev_err(&client->dev, "failed to reqeust IRQ\n");
			return ret;
		}

		device_init_wakeup(&client->dev, pdata->wakeup);
	}

	return 0;
}
Esempio n. 20
0
void fsa9480_set_switch(const char *buf)
{
       struct fsa9480_usbsw *usbsw = chip;
       struct i2c_client *client = usbsw->client;
       u8 value = 0;
       unsigned int path = 0;

       fsa9480_read_reg(client, FSA9480_REG_CTRL, &value);

       if (!strncmp(buf, "VAUDIO", 6)) {
	   	       if(usbsw->id == 0)
			   	path = VAUDIO_9485;
			   else
			   	path = VAUDIO;
               value &= ~MANUAL_SWITCH;
       } else if (!strncmp(buf, "UART", 4)) {
               path = UART;
               value &= ~MANUAL_SWITCH;
       } else if (!strncmp(buf, "AUDIO", 5)) {
               if(usbsw->id == 0)
			   	path = AUDIO_9485;
			   else
                path = AUDIO;
               value &= ~MANUAL_SWITCH;
       } else if (!strncmp(buf, "DHOST", 5)) {
               path = DHOST;
               value &= ~MANUAL_SWITCH;
       } else if (!strncmp(buf, "AUTO", 4)) {
               path = AUTO;
               value |= MANUAL_SWITCH;
       } else {
               printk(KERN_ERR "Wrong command\n");
               return;
       }

       usbsw->mansw = path;
       fsa9480_write_reg(client, FSA9480_REG_MANSW1, path);
       fsa9480_write_reg(client, FSA9480_REG_CTRL, value);
}
Esempio n. 21
0
static void fsa9480_detect_dev(struct fsa9480_usbsw *usbsw, int intr)
{
	int val1, val2, ctrl;
	struct fsa9480_platform_data *pdata = usbsw->pdata;
	struct i2c_client *client = usbsw->client;

	val1 = fsa9480_read_reg(client, FSA9480_REG_DEV_T1);
	val2 = fsa9480_read_reg(client, FSA9480_REG_DEV_T2);
	ctrl = fsa9480_read_reg(client, FSA9480_REG_CTRL);

	dev_info(&client->dev, "intr: 0x%x, dev1: 0x%x, dev2: 0x%x\n",
			intr, val1, val2);

	if (!intr)
		goto out;

	if (intr & INT_ATTACH) {	/* Attached */
		/* USB */
		if (val1 & DEV_T1_USB_MASK || val2 & DEV_T2_USB_MASK) {
			if (pdata->usb_cb)
				pdata->usb_cb(FSA9480_ATTACHED);

			if (usbsw->mansw) {
				fsa9480_write_reg(client,
					FSA9480_REG_MANSW1, usbsw->mansw);
			}
		}

		/* UART */
		if (val1 & DEV_T1_UART_MASK || val2 & DEV_T2_UART_MASK) {
			if (pdata->uart_cb)
				pdata->uart_cb(FSA9480_ATTACHED);

			if (!(ctrl & CON_MANUAL_SW)) {
				fsa9480_write_reg(client,
					FSA9480_REG_MANSW1, SW_UART);
			}
		}

		/* CHARGER */
		if (val1 & DEV_T1_CHARGER_MASK) {
			if (pdata->charger_cb)
				pdata->charger_cb(FSA9480_ATTACHED);
		}

		/* JIG */
		if (val2 & DEV_T2_JIG_MASK) {
			if (pdata->jig_cb)
				pdata->jig_cb(FSA9480_ATTACHED);
		}
	} else if (intr & INT_DETACH) {	/* Detached */
		/* USB */
		if (usbsw->dev1 & DEV_T1_USB_MASK ||
			usbsw->dev2 & DEV_T2_USB_MASK) {
			if (pdata->usb_cb)
				pdata->usb_cb(FSA9480_DETACHED);
		}

		/* UART */
		if (usbsw->dev1 & DEV_T1_UART_MASK ||
			usbsw->dev2 & DEV_T2_UART_MASK) {
			if (pdata->uart_cb)
				pdata->uart_cb(FSA9480_DETACHED);
		}

		/* CHARGER */
		if (usbsw->dev1 & DEV_T1_CHARGER_MASK) {
			if (pdata->charger_cb)
				pdata->charger_cb(FSA9480_DETACHED);
		}

		/* JIG */
		if (usbsw->dev2 & DEV_T2_JIG_MASK) {
			if (pdata->jig_cb)
				pdata->jig_cb(FSA9480_DETACHED);
		}
	}

	usbsw->dev1 = val1;
	usbsw->dev2 = val2;

out:
	ctrl &= ~CON_INT_MASK;
	fsa9480_write_reg(client, FSA9480_REG_CTRL, ctrl);
}
Esempio n. 22
0
static void fsa9480_work_cb(struct work_struct *work)
{
	u8 intr, intr2, intr3;
	struct fsa9480_usbsw *usbsw = container_of(work, struct fsa9480_usbsw, work);
	struct i2c_client *client = usbsw->client;

	wake_lock_timeout(&mUSB_suspend_wake,1*HZ);
	
       /* clear interrupt */
	if(muic_type==muicTypeTI6111)
	{
		msleep(200);
	
		fsa9480_read_reg(client, FSA9480_REG_INT1, &intr);
		fsa9480_read_reg(client, FSA9480_REG_INT2, &intr2);	
		fsa9480_read_reg(client, FSA9480_REG_CHG_INT, &intr3);
		printk("[FSA9480] %s: intr=0x%x, intr2 = 0x%X, chg_intr=0x%x \n",__func__,intr,intr2, intr3);


	}
	else
	{
		fsa9480_read_reg(client, FSA9480_REG_INT1, &intr);
		fsa9480_read_reg(client, FSA9480_REG_INT2, &intr2);	
		printk("[FSA9480] %s: intr=0x%x, intr2=0x%x \n",__func__,intr,intr2);
	}

	if(intr3 & CH_DONE) //EOC disable charger // Luke 
	{
		//msleep(500);	 // Test only

		//fsa9480_read_reg(client, FSA9480_REG_DEV_T1, &val1);
		//if(val1&=DEV_VBUS) // Check if VBUS is valid //Luke
		//{
#if defined(CONFIG_BATTERY_D2083)
			if(spa_external_event)
			{
				pr_info("%s. Send D2083_EVENT_CHARGE_FULL event\n", __func__);
				spa_external_event(D2083_CATEGORY_BATTERY, D2083_EVENT_CHARGE_FULL);
			}
		//}
#endif
	}

	intr &= 0xffff;

	/* device detection */
	fsa9480_detect_dev(usbsw, intr);

	if((intr== 0x00) && (intr3 == 0))
	{	
		printk("[FSA9480] (intr== 0x00) in work_cb !!!!!\n");
		fsa9480_read_adc_value();
		#if 0	// TODO: 
		if(muic_type==muicTypeTI6111)
			TI_SWreset(usbsw);
		#endif
		
		return;
	}

	if(!(intr3 & CH_DONE))
		tsu8111_check_ovp();
	
	if( intr==0x03) // INT error case
		fsa9480_reset_ic();
	
}
Esempio n. 23
0
static int __devinit fsa9480_probe(struct i2c_client *client,
                        const struct i2c_device_id *id)
{
	//struct regulator *regulator;
	struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
	struct fsa9480_platform_data *pdata = client->dev.platform_data;
	struct fsa9480_usbsw *usbsw;
	struct pm860x_vbus_info *vbus;
#if 0	// TODO: 
	struct pxa_vbus_info info;
#endif
	unsigned int data;
	int ret = 0;
	u8 devID;
	
	u8 intr, intr2, intr_chg;
	u8 mansw1;
	unsigned int ctrl = CTRL_MASK;

	printk("[FSA9480] PROBE ......\n");
	if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
		return -EIO;	   
	isProbe = 1;
	   
	//add for AT Command 
	//wake_lock_init(&JIGConnect_idle_wake, WAKE_LOCK_IDLE, "jig_connect_idle_wake");
	wake_lock_init(&JIGConnect_suspend_wake, WAKE_LOCK_SUSPEND, "jig_connect_suspend_wake");
	wake_lock_init(&mUSB_suspend_wake, WAKE_LOCK_SUSPEND, "mUSB_detect");

#ifdef CONFIG_KONA_PI_MGR
	ret=pi_mgr_qos_add_request(&qos_node, "fsa9480", PI_MGR_PI_ID_ARM_SUB_SYSTEM,
			       PI_MGR_QOS_DEFAULT_VALUE);
	if (ret)
	{
		pr_err("%s: failed to add fsa9480 to qos\n",__func__);
		return -1;
	}
#endif

	usbsw = kzalloc(sizeof(struct fsa9480_usbsw), GFP_KERNEL);
	if (!usbsw) {
		dev_err(&client->dev, "failed to allocate driver data\n");
		return -ENOMEM;
	}

	usbsw->client = client;
	usbsw->pdata = client->dev.platform_data;

	chip = usbsw;

	i2c_set_clientdata(client, usbsw);

#if defined (VBUS_DETECT) /* Init vbus for pxa(MARVELL) */
//	chip->pdata = pm860x_pdata->vbus;
	vbus = kzalloc(sizeof(struct pm860x_vbus_info), GFP_KERNEL);
	if (!vbus) {
		ret = -ENOMEM;
		goto out_mem;
	}
	dev_set_drvdata(&client->dev, vbus);
	
	vbus->res = kzalloc(sizeof(struct resource), GFP_KERNEL);
	if (!vbus->res) {
		ret = -ENOMEM;
		goto out_mem2;
	}
	vbus->res->start = pdata->vbus->reg_base;
	vbus->res->end = pdata ->vbus->reg_end;

	memset(&info,0,sizeof(struct pxa_vbus_info));
	info.dev = &client->dev;
	info.res = vbus->res;

	pxa_vbus_init(&info);

	data = VBUS_A_VALID | VBUS_A_SESSION_VALID | VBUS_B_SESSION_VALID | VBUS_B_SESSION_END | VBUS_ID;
	pxa_unmask_vbus(data);
#endif

#if defined(CONFIG_SPA)
	spa_external_event = spa_get_external_event_handler();
#elif defined(CONFIG_BATTERY_D2083)
	ret = d2083_register_enable_charge(TSU8111_Charger_Enable);
	if(ret < 0) {
		pr_err("%s. fail to register enable charge function\n", __func__);
		goto out_charger_enable;
	}
	ret = d2083_register_enable_back_charge(TSU8111_Charger_BackCHG_Enable);
	if(ret < 0) {
		pr_err("%s. fail to register enable charge function\n", __func__);
		goto out_charger_enable;
	}	
	ret = d2083_register_disable_charge(TSU8111_Charger_Disable);
	if(ret < 0) {
		pr_err("%s. fail to register disable charge function\n", __func__);
		goto out_charger_disable;
	}
	spa_external_event = d2083_get_external_event_handler();
#endif

	/* clear interrupt */
	fsa9480_read_reg(client, FSA9480_REG_INT1, &intr);

	fsa9480_read_reg(client, FSA9480_REG_DEVID, &devID);
	if(devID==0x0a || devID==0x5A)
		muic_type=muicTypeTI6111;
	else if(devID==0x00)
		muic_type=muicTypeFSA880;
	else
		muic_type=muicTypeFSA;

	if(muic_type==muicTypeFSA880)
	{
		intr &= 0xffff;
		/* set control register */
		fsa9480_write_reg(client, FSA9480_REG_CTRL, 0x04);
	}
	else if(muic_type==muicTypeTI6111)
	{
		intr &= 0xffff;

		/* clear interrupt */
		fsa9480_read_reg(client, FSA9480_REG_INT2, &intr2);
		fsa9480_read_reg(client, FSA9480_REG_CHG_INT, &intr_chg);

		/* unmask interrupt (attach/detach only) */
		ret = fsa9480_write_reg(client, FSA9480_REG_INT1_MASK, 0x00);
		if (ret < 0)
			return ret;

#if 0/*FSA9480's Interrupt Mask init setting*/
	   //ret = fsa9480_write_reg(client, FSA9480_REG_INT2_MASK, 0x00);
#endif
		/*TI USB : not to get Connect Interrupt : no more double interrupt*/
		ret = fsa9480_write_reg(client, FSA9480_REG_INT1_MASK, 0x40);
		if (ret < 0)
			return ret;

		ret = fsa9480_write_reg(client, FSA9480_REG_INT2_MASK, 0x20);
		if (ret < 0)
			return ret;

		ret = fsa9480_write_reg(client, FSA9480_REG_CHG_INT_MASK, 0xc0);
		if (ret < 0)
			return ret;


	   fsa9480_read_reg(client, FSA9480_REG_MANSW1, &mansw1);
	   usbsw->mansw = mansw1;

		ctrl &= ~INT_MASK;			  /* Unmask Interrupt */
		if (usbsw->mansw)
			ctrl &= ~MANUAL_SWITCH; /* Manual Switching Mode */
	   
		fsa9480_write_reg(client, FSA9480_REG_CTRL, ctrl);
	}
	else
	   printk("[FSA9480] Error!!!! No Type. Check dev ID(0x01 addr) ......\n");

   ret = fsa9480_irq_init(usbsw);
   if (ret)
           goto fsa9480_probe_fail;

   ret = sysfs_create_group(&client->dev.kobj, &fsa9480_group);
   if (ret) {
           dev_err(&client->dev,
                           "[FSA9480] Creating fsa9480 attribute group failed");
           goto fsa9480_probe_fail2;
   }

	/* device detection */
	fsa9480_detect_dev(usbsw, 1);
	isProbe = 0;
	tsu8111_check_ovp();

	/*reset UIC*/
	if(muic_type==muicTypeFSA880)
		fsa9480_write_reg(client, FSA9480_REG_CTRL, 0x04);
	else
	{
		fsa9480_write_reg(client, FSA9480_REG_CTRL, 0x1E);
		/*set timing1 to 100ms*/
//		fsa9480_write_reg(client, FSA9480_REG_TIMING1, 0x1);
	}	   

#ifdef CONFIG_KONA_PI_MGR
	//ret=pi_mgr_qos_request_update(&qos_node, 0);
	//if (ret)
	//{
	//	pr_err("%s: failed to request update qos_node\n",__func__);
	//}
#endif


       printk("[FSA9480] PROBE Done.\n");
       return 0;

out_mem:
	return ret;
#if defined(CONFIG_BATTERY_D2083)
out_charger_enable:
out_charger_disable:
#endif /* CONFIG_BATTERY_D2083 */
out_mem2:
	kfree(vbus);
fsa9480_probe_fail2:
   if (client->irq)
       free_irq(client->irq, NULL);
fsa9480_probe_fail:
	i2c_set_clientdata(client, NULL);
	kfree(usbsw);
	return ret;
}
Esempio n. 24
0
 //extern void mv_usb_connect_change(int status); // khMa
static void fsa9480_detect_dev(struct fsa9480_usbsw *usbsw, u8 intr)
{
       u8 val1, val2;// , ctrl,temp;
       //struct fsa9480_platform_data *pdata = usbsw->pdata;
       struct i2c_client *client = usbsw->client;
	   printk("[FSA9480] fsa9480_detect_dev !!!!!\n");

#if 0 // Not for TI
       /*reset except CP USB and AV dock*/
	   if ((usbsw->mansw != AUDIO) && (usbsw->mansw != AUDIO_9485)
	   	   && (usbsw->mansw != VAUDIO) && (usbsw->mansw != VAUDIO_9485))
       	{
		  /*reset UIC when mansw is not set*/
		  printk("[FSA9480] %s: reset UIC mansw is 0x%x\n",__func__,usbsw->mansw);
          fsa9480_write_reg(client, FSA9480_REG_CTRL, 0x1E);
		  usbsw->mansw = AUTO;
       	} 
#endif

       fsa9480_read_reg(client, FSA9480_REG_DEV_T1, &val1);
       fsa9480_read_reg(client, FSA9480_REG_DEV_T2, &val2);
       printk("intr: 0x%x, dev1: 0x%x, dev2: 0x%x\n",intr, val1, val2);

#if 0//Not for TI	   
       fsa9480_read_reg(client, FSA9480_REG_CTRL, &ctrl);

       dev_info(&client->dev, "intr: 0x%x, dev1: 0x%x, dev2: 0x%x, ctrl: 0x%x\n",
                       intr, val1, val2,ctrl);
#endif

	if((intr==0x01) &&(val1==0x00) && (val2==0x00) && (isProbe == 0))
	{
		printk("[FSA9480] (intr==0x01) &&(val1==0x00) && (val2==0x00) !!!!!\n");
		fsa9480_read_adc_value();
		if(muic_type==muicTypeTI6111)
		{
			msleep(50);

			fsa9480_read_reg(client, FSA9480_REG_DEV_T1, &val1);
			fsa9480_read_reg(client, FSA9480_REG_DEV_T2, &val2);

			//TI_SWreset(usbsw);
			//return;
		}
	}
	else if(intr==0x03)
	{
		printk("[FSA9480] error read INT register !!!!!\n");
		intr = (1 << 1); // change to DETACH
	}

	/* Attached */
	if (intr & (1 << 0)) 
	{
		if (val1 & FSA9480_DEV_T1_USB_MASK ) {
			printk("[FSA9480] FSA9480_USB ATTACHED*****\n");

#if defined (VBUS_DETECT) /* Enable clock to AP USB block */
			pxa_vbus_handler(VBUS_HIGH);
#endif			
#if defined(CONFIG_SPA)
			if(spa_external_event)
			{
				spa_external_event(SPA_CATEGORY_DEVICE, SPA_DEVICE_EVENT_USB_ATTACHED);
			}
#elif defined(CONFIG_BATTERY_D2083)
			if(spa_external_event)
			{
				spa_external_event(D2083_CATEGORY_DEVICE, D2083_EVENT_USB_ATTACHED);
			}
#endif
	                send_usb_attach_event();
		}

		if (val1 & FSA9480_DEV_T1_UART_MASK || val2 & FSA9480_DEV_T2_UART_MASK) {
			//if (pdata->uart_cb)
			//        pdata->uart_cb(FSA9480_ATTACHED);				   
		}

		if (val1 & FSA9480_DEV_T1_CHARGER_MASK || val1==DEV_VBUS || val2 & DEV_JIG_USB_OFF) {
			printk("[FSA9480] Charger ATTACHED*****\n");
#if defined(CONFIG_SPA)
			if(spa_external_event)
			{
				spa_external_event(SPA_CATEGORY_DEVICE, SPA_DEVICE_EVENT_TA_ATTACHED);
			}
#elif defined(CONFIG_BATTERY_D2083)
			if(spa_external_event)
			{
				spa_external_event(D2083_CATEGORY_DEVICE, D2083_EVENT_TA_ATTACHED);
			}
#endif
		}

		if (val2 & FSA9480_DEV_T2_JIG_MASK) {
			printk("[FSA9480] JIG ATTACHED*****\n"); 			   
			//wake_lock(&JIGConnect_idle_wake);
			wake_lock(&JIGConnect_suspend_wake);
#ifdef CONFIG_KONA_PI_MGR
			pi_mgr_qos_request_update(&qos_node, 0);
#endif

#if defined(CONFIG_SPA)
			if(spa_external_event)
			{
				spa_external_event(SPA_CATEGORY_DEVICE, SPA_DEVICE_EVENT_JIG_ATTACHED);
			}
#elif defined(CONFIG_BATTERY_D2083)
			if(spa_external_event)
			{
				spa_external_event(D2083_CATEGORY_DEVICE, D2083_EVENT_JIG_ATTACHED);
			}
#endif
		}
	} 
	else if (intr & (1 << 1)) 
	{    /* DETACH */
		if(usbsw->dev1 & FSA9480_DEV_T1_USB_MASK) {
				printk("[FSA9480] FSA9480_USB Detached*****\n");
#if defined (VBUS_DETECT) /* Disable clock to AP USB block */
			pxa_vbus_handler(VBUS_LOW);
#endif			
#if defined(CONFIG_SPA)
			if(spa_external_event)
			{
				spa_external_event(SPA_CATEGORY_DEVICE, SPA_DEVICE_EVENT_USB_DETACHED);
			}
#elif defined(CONFIG_BATTERY_D2083)
			if(spa_external_event)
			{
				spa_external_event(D2083_CATEGORY_DEVICE, D2083_EVENT_USB_DETACHED);
			}
#endif
			send_usb_detach_event();
		}

		if (usbsw->dev1 & FSA9480_DEV_T1_UART_MASK ||
                       usbsw->dev2 & FSA9480_DEV_T2_UART_MASK) {
			//if (pdata->uart_cb)
			//     pdata->uart_cb(FSA9480_DETACHED);
		}

		if (usbsw->dev1 & FSA9480_DEV_T1_CHARGER_MASK || usbsw->dev1==DEV_VBUS || usbsw->dev2 & DEV_JIG_USB_OFF) {
			printk("[FSA9480] Charger Detached*****\n");
#if defined(CONFIG_SPA)
			if(spa_external_event)
			{
				spa_external_event(SPA_CATEGORY_DEVICE, SPA_DEVICE_EVENT_TA_DETACHED);
			}
#elif defined(CONFIG_BATTERY_D2083)
			if(spa_external_event)
			{
				spa_external_event(D2083_CATEGORY_DEVICE, D2083_EVENT_TA_DETACHED);
			}
#endif
		}

		if (usbsw->dev2 & FSA9480_DEV_T2_JIG_MASK) {      
			printk("[FSA9480] JIG Detached*****\n");			   	
			//wake_unlock(&JIGConnect_idle_wake);
			wake_unlock(&JIGConnect_suspend_wake);
#ifdef CONFIG_KONA_PI_MGR
			pi_mgr_qos_request_update(&qos_node, PI_MGR_QOS_DEFAULT_VALUE);
#endif

#if defined(CONFIG_SPA)
			if(spa_external_event)
			{
				spa_external_event(SPA_CATEGORY_DEVICE, SPA_DEVICE_EVENT_JIG_DETACHED);
			}
#elif defined(CONFIG_BATTERY_D2083)
			if(spa_external_event)
			{
				spa_external_event(D2083_CATEGORY_DEVICE, D2083_EVENT_JIG_DETACHED);
			}
#endif
			if(muic_type==muicTypeTI6111)
			{
				/*SW RESET for TI USB:To fix no USB recog problem after jig attach&detach*/
				//TI_SWreset(usbsw);
			}
		}
	}

	if( intr ){
		usbsw->dev1 = val1;
		usbsw->dev2 = val2;

		chip->dev1 = val1;
		chip->dev2 = val2;
	}
#if 0 // Not for TI
	fsa9480_read_reg(client, FSA9480_REG_CTRL, &ctrl);
	ctrl &= ~INT_MASK;
	fsa9480_write_reg(client, FSA9480_REG_CTRL, ctrl);

	fsa9480_read_reg(client, FSA9480_REG_MANSW1, &temp); //khMa	   
#endif
}
Esempio n. 25
0
static ssize_t fsa9480_show_status(struct device *dev,
                                  struct device_attribute *attr,
                                  char *buf)
{
       struct fsa9480_usbsw *usbsw = dev_get_drvdata(dev);
       struct i2c_client *client = usbsw->client;
       u8 devid, ctrl, adc, dev1, dev2, intr;
       u8 intmask1, intmask2, time1, time2, mansw1;

       fsa9480_read_reg(client, FSA9480_REG_DEVID, &devid);
       fsa9480_read_reg(client, FSA9480_REG_CTRL, &ctrl);
       fsa9480_read_reg(client, FSA9480_REG_ADC, &adc);
       fsa9480_read_reg(client, FSA9480_REG_INT1_MASK, &intmask1);
       fsa9480_read_reg(client, FSA9480_REG_INT2_MASK, &intmask2);
       fsa9480_read_reg(client, FSA9480_REG_DEV_T1, &dev1);
       fsa9480_read_reg(client, FSA9480_REG_DEV_T2, &dev2);
       fsa9480_read_reg(client, FSA9480_REG_TIMING1, &time1);
       fsa9480_read_reg(client, FSA9480_REG_TIMING2, &time2);
       fsa9480_read_reg(client, FSA9480_REG_MANSW1, &mansw1);

       fsa9480_read_reg(client, FSA9480_REG_INT1, &intr);
       intr &= 0xffff;

       return sprintf(buf, "Device ID(%02x), CTRL(%02x)\n"
                       "ADC(%02x), DEV_T1(%02x), DEV_T2(%02x)\n"
                       "INT(%04x), INTMASK(%02x, %02x)\n"
                       "TIMING(%02x, %02x), MANSW1(%02x)\n",
                       devid, ctrl, adc, dev1, dev2, intr,
                       intmask1, intmask2, time1, time2, mansw1);
}