static void check_acc_dock(struct acc_con_info *acc)
{
	if (gpio_get_value(acc->pdata->accessory_irq_gpio)) {
		if (acc->current_dock == DOCK_NONE)
			return;
		ACC_CONDEV_DBG("docking station detached!!!");
		switch_set_state(&acc->dock_switch, UEVENT_DOCK_NONE);
#ifdef CONFIG_SEC_KEYBOARD_DOCK
		acc->pdata->check_keyboard(false);
#endif
#if defined(CONFIG_VIDEO_MHL_TAB_V2)
		/*call MHL deinit */
		mhl_onoff_ex(false);
#endif
		acc_dock_check(acc, false);
	} else {
		ACC_CONDEV_DBG("docking station attached!!!");

		switch_set_state(&acc->dock_switch, UEVENT_DOCK_CONNECTED);
		msleep(100);
		wake_lock(&acc->wake_lock);

#ifdef CONFIG_SEC_KEYBOARD_DOCK
		if (acc->pdata->check_keyboard(true)) {
			acc->current_dock = DOCK_KEYBOARD;
			ACC_CONDEV_DBG("[30PIN] keyboard dock "
				"station attached!!!");
			switch_set_state(&acc->dock_switch,
				UEVENT_DOCK_KEYBOARD);
		} else
#endif /* CONFIG_SEC_KEYBOARD_DOCK */
		{
			switch_set_state(&acc->dock_switch, UEVENT_DOCK_DESK);
			acc->current_dock = DOCK_DESK;
		}
#if defined(CONFIG_VIDEO_MHL_TAB_V2)
		mhl_onoff_ex(true);
#endif

		acc_dock_check(acc, true);

		wake_unlock(&acc->wake_lock);

	}
}
/*extern void MHL_On(bool on);*/
void max77693_muic_mhl_cb(int attached)
{
	pr_info("MUIC attached:%d\n", attached);
	if (attached == MAX77693_MUIC_ATTACHED) {
		/*MHL_On(1);*/ /* GPIO_LEVEL_HIGH */
		pr_info("MHL Attached !!\n");
#ifdef CONFIG_SAMSUNG_MHL
#ifdef CONFIG_MACH_MIDAS
		sii9234_wake_lock();
#endif
		mhl_onoff_ex(1);
#endif
	} else {
		/*MHL_On(0);*/ /* GPIO_LEVEL_LOW */
		pr_info("MHL Detached !!\n");
#ifdef CONFIG_SAMSUNG_MHL
		mhl_onoff_ex(false);
#ifdef CONFIG_MACH_MIDAS
		sii9234_wake_unlock();
#endif
#endif
	}
}
Exemplo n.º 3
0
static int fsa9485_detect_dev(struct fsa9485_usbsw *usbsw)
{
	int device_type, ret;
	unsigned int val1, val2, adc;
	struct fsa9485_platform_data *pdata = usbsw->pdata;
	struct i2c_client *client = usbsw->client;
#if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
	u8 mhl_ret = 0;
#endif
	device_type = i2c_smbus_read_word_data(client, FSA9485_REG_DEV_T1);
	if (device_type < 0) {
		dev_err(&client->dev, "%s: err %d\n", __func__, device_type);
		return device_type;
	}
	val1 = device_type & 0xff;
	val2 = device_type >> 8;
	adc = i2c_smbus_read_byte_data(client, FSA9485_REG_ADC);

	if (usbsw->dock_attached)
		pdata->dock_cb(FSA9485_DETACHED_DOCK);

	if (adc == 0x10)
		val2 = DEV_SMARTDOCK;
	else if (adc == 0x12)
		val2 = DEV_AUDIO_DOCK;

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

	/* Attached */
	if (val1 || val2) {
		/* USB */
		if (val1 & DEV_USB || val2 & DEV_T2_USB_MASK) {
			dev_info(&client->dev, "usb connect\n");

		if (pdata->usb_cb) {
				if (force_fast_charge != 0) {
				  dev_info(&client->dev, "[imoseyon] fastcharge\n");
				  pdata->charger_cb(FSA9485_ATTACHED);
				} else pdata->usb_cb(FSA9485_ATTACHED);
			}

			if (usbsw->mansw) {
				ret = i2c_smbus_write_byte_data(client,
				FSA9485_REG_MANSW1, usbsw->mansw);

				if (ret < 0)
					dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
			}
		/* USB_CDP */
		} else if (val1 & DEV_USB_CHG) {
			dev_info(&client->dev, "usb_cdp connect\n");

			if (pdata->usb_cdp_cb)
				pdata->usb_cdp_cb(FSA9485_ATTACHED);
			if (usbsw->mansw) {
				ret = i2c_smbus_write_byte_data(client,
				FSA9485_REG_MANSW1, usbsw->mansw);

				if (ret < 0)
					dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
			}

		/* UART */
		} else if (val1 & DEV_T1_UART_MASK || val2 & DEV_T2_UART_MASK) {
			uart_connecting = 1;
			dev_info(&client->dev, "uart connect\n");
			i2c_smbus_write_byte_data(client,
						FSA9485_REG_CTRL, 0x1E);
			if (pdata->uart_cb)
				pdata->uart_cb(FSA9485_ATTACHED);

			if (usbsw->mansw) {
				ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_MANSW1, SW_UART);

				if (ret < 0)
					dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
			}
		/* CHARGER */
		} else if (val1 & DEV_T1_CHARGER_MASK) {
			dev_info(&client->dev, "charger connect\n");

			if (pdata->charger_cb)
				pdata->charger_cb(FSA9485_ATTACHED);
		/* for SAMSUNG OTG */
		} else if (val1 & DEV_USB_OTG) {
			dev_info(&client->dev, "otg connect\n");
			if (pdata->otg_cb)
				pdata->otg_cb(FSA9485_ATTACHED);
			i2c_smbus_write_byte_data(client,
						FSA9485_REG_MANSW1, 0x27);
			i2c_smbus_write_byte_data(client,
						FSA9485_REG_MANSW2, 0x02);
			msleep(50);
			i2c_smbus_write_byte_data(client,
						FSA9485_REG_CTRL, 0x1a);
		/* JIG */
		} else if (val2 & DEV_T2_JIG_MASK) {
			dev_info(&client->dev, "jig connect\n");

			if (pdata->jig_cb)
				pdata->jig_cb(FSA9485_ATTACHED);
		/* Desk Dock */
		} else if (val2 & DEV_AV) {
			if ((adc & 0x1F) == ADC_DESKDOCK) {
				pr_info("FSA Deskdock Attach\n");
				FSA9485_CheckAndHookAudioDock(1);
				usbsw->deskdock = 1;
#if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
				isDeskdockconnected = 1;
#endif
				i2c_smbus_write_byte_data(client,
						FSA9485_REG_RESERVED_20, 0x08);
			} else {
				pr_info("FSA MHL Attach\n");
				i2c_smbus_write_byte_data(client,
						FSA9485_REG_RESERVED_20, 0x08);
#if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
				DisableFSA9480Interrupts();
				if (!isDeskdockconnected)
					mhl_ret = mhl_onoff_ex(1);

				if (mhl_ret != MHL_DEVICE &&
						(adc & 0x1F) == 0x1A) {
					FSA9485_CheckAndHookAudioDock(1);
					isDeskdockconnected = 1;
				}
				EnableFSA9480Interrupts();
#else
				pr_info("FSA mhl attach, but not support MHL feature!\n");
#endif
			}
		/* Car Dock */
		} else if (val2 & DEV_JIG_UART_ON) {
			if (pdata->dock_cb)
				pdata->dock_cb(FSA9485_ATTACHED_CAR_DOCK);
			ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_MANSW1, SW_AUDIO);

			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_read_byte_data(client,
					FSA9485_REG_CTRL);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_CTRL, ret & ~CON_MANUAL_SW);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
			usbsw->dock_attached = FSA9485_ATTACHED;
		/* SmartDock */
		} else if (val2 & DEV_SMARTDOCK) {
			usbsw->adc = adc;
			dev_info(&client->dev, "smart dock connect\n");

			usbsw->mansw = SW_DHOST;
			ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_MANSW1, SW_DHOST);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
			ret = i2c_smbus_read_byte_data(client,
					FSA9485_REG_CTRL);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
			ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_CTRL, ret & ~CON_MANUAL_SW);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);

			if (pdata->smartdock_cb)
				pdata->smartdock_cb(FSA9485_ATTACHED);
#if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
			mhl_onoff_ex(1);
#endif
		} else if (val2 & DEV_AUDIO_DOCK) {
			usbsw->adc = adc;
			dev_info(&client->dev, "audio dock connect\n");

			usbsw->mansw = SW_DHOST;
			ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_MANSW1, SW_DHOST);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
			ret = i2c_smbus_read_byte_data(client,
					FSA9485_REG_CTRL);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
			ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_CTRL, ret & ~CON_MANUAL_SW);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);

			if (pdata->smartdock_cb)
				pdata->audio_dock_cb(FSA9485_ATTACHED);
		}
	/* Detached */
	} else {
		/* USB */
		if (usbsw->dev1 & DEV_USB ||
				usbsw->dev2 & DEV_T2_USB_MASK) {
			if (pdata->usb_cb)
				pdata->usb_cb(FSA9485_DETACHED);
		} else if (usbsw->dev1 & DEV_USB_CHG) {
			if (pdata->usb_cdp_cb)
				pdata->usb_cdp_cb(FSA9485_DETACHED);

		/* UART */
		} else if (usbsw->dev1 & DEV_T1_UART_MASK ||
				usbsw->dev2 & DEV_T2_UART_MASK) {
			if (pdata->uart_cb)
				pdata->uart_cb(FSA9485_DETACHED);
			uart_connecting = 0;
			dev_info(&client->dev, "[FSA9485] uart disconnect\n");

		/* CHARGER */
		} else if (usbsw->dev1 & DEV_T1_CHARGER_MASK) {
			if (pdata->charger_cb)
				pdata->charger_cb(FSA9485_DETACHED);
		/* for SAMSUNG OTG */
		} else if (usbsw->dev1 & DEV_USB_OTG) {
			i2c_smbus_write_byte_data(client,
						FSA9485_REG_CTRL, 0x1E);
		/* JIG */
		} else if (usbsw->dev2 & DEV_T2_JIG_MASK) {
			if (pdata->jig_cb)
				pdata->jig_cb(FSA9485_DETACHED);
		/* Desk Dock */
		} else if (usbsw->dev2 & DEV_AV) {

			pr_info("FSA MHL Detach\n");
			i2c_smbus_write_byte_data(client,
					FSA9485_REG_RESERVED_20, 0x04);
#if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
			if (isDeskdockconnected)
				FSA9485_CheckAndHookAudioDock(0);
#if defined CONFIG_MHL_D3_SUPPORT
			mhl_onoff_ex(false);
			detached_status = 1;
#endif
			isDeskdockconnected = 0;
#else
			if (usbsw->deskdock) {
				FSA9485_CheckAndHookAudioDock(0);
				usbsw->deskdock = 0;
			} else {
				pr_info("FSA detach mhl cable, but not support MHL feature\n");
			}
#endif
		/* Car Dock */
		} else if (usbsw->dev2 & DEV_JIG_UART_ON) {
			if (pdata->dock_cb)
				pdata->dock_cb(FSA9485_DETACHED_DOCK);
				ret = i2c_smbus_read_byte_data(client,
						FSA9485_REG_CTRL);
				if (ret < 0)
					dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);

				ret = i2c_smbus_write_byte_data(client,
						FSA9485_REG_CTRL,
						ret | CON_MANUAL_SW);
				if (ret < 0)
					dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
				usbsw->dock_attached = FSA9485_DETACHED;
		} else if (usbsw->adc == 0x10) {
			dev_info(&client->dev, "smart dock disconnect\n");

			ret = i2c_smbus_read_byte_data(client,
						FSA9485_REG_CTRL);
				if (ret < 0)
					dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
				ret = i2c_smbus_write_byte_data(client,
						FSA9485_REG_CTRL,
						ret | CON_MANUAL_SW);
				if (ret < 0)
					dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);

			if (pdata->smartdock_cb)
				pdata->smartdock_cb(FSA9485_DETACHED);
			usbsw->adc = 0;
#if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
			mhl_onoff_ex(false);
#endif
		} else if (usbsw->adc == 0x12) {
			dev_info(&client->dev, "audio dock disconnect\n");

			ret = i2c_smbus_read_byte_data(client,
						FSA9485_REG_CTRL);
				if (ret < 0)
					dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
				ret = i2c_smbus_write_byte_data(client,
						FSA9485_REG_CTRL,
						ret | CON_MANUAL_SW);
				if (ret < 0)
					dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);

			if (pdata->smartdock_cb)
				pdata->audio_dock_cb(FSA9485_DETACHED);
			usbsw->adc = 0;
		}

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

	return adc;
}
Exemplo n.º 4
0
void FSA9480_CheckAndHookAudioDock(int value, int onoff)
{
	struct i2c_client *client = local_usbsw->client;
	struct fsa9480_platform_data *pdata = local_usbsw->pdata;
	int ret = 0;
	// unsigned int ctrl = CON_MASK;

	if (onoff)
		local_usbsw->check_watchdog=1;

	if (value == USE_DESK_DOCK)
	{
		if (onoff)
		{
			//skip controlling the sii9234 on lpm mode
			if(!sec_get_lpm_mode())
			{
#if defined(CONFIG_VIDEO_MHL_V1)
				sii9234_cfg_power(0);	//Turn Off power to SiI9234
#elif defined(CONFIG_VIDEO_MHL_V2)
				mhl_onoff_ex(0);		//will call hw_onoff(0)
#endif
				gpio_set_value_cansleep(GPIO_MHL_SEL, 0);
			}

			ret = i2c_smbus_read_byte_data(client,FSA9480_REG_CTRL);

			dev_info(&client->dev, "FSA9480_CheckAndHookAudioDock On ctrl reg: 0x%x\n", ret);

			if (pdata->deskdock_cb)
				pdata->deskdock_cb(FSA9480_ATTACHED);

//#if !defined(CONFIG_USA_MODEL_SGH_I717) && !defined (CONFIG_USA_MODEL_SGH_T769)
			if (!get_sec_det_jack_state()) {
				if (HWversion ==VERSION_FSA9480)
				{
					ret = i2c_smbus_write_byte_data(client,FSA9480_REG_MANSW1,SW_AUDIO);
				}
				else
				{
					ret = i2c_smbus_write_byte_data(client,FSA9480_REG_MANSW1,AUDIO_9485);
				}
			
				if (ret < 0)
					dev_err(&client->dev,"%s: err %d\n", __func__, ret);
			}
			else
				printk("%s: Earjack exist..\n", __func__);
//#endif

			ret = i2c_smbus_read_byte_data(client,FSA9480_REG_CTRL);
			if (ret < 0)
				dev_err(&client->dev,"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_write_byte_data(client,FSA9480_REG_CTRL, ret & ~CON_MANUAL_SW & ~CON_RAW_DATA);
			if (ret < 0)
				dev_err(&client->dev,"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_read_byte_data(client,FSA9480_REG_INT2_MASK);
			if (ret < 0)
				dev_err(&client->dev,"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_write_byte_data(client, FSA9480_REG_INT2_MASK, ret & ~INT_MASK_ADC_CHANGE);
			if (ret < 0)
				dev_err(&client->dev,"%s: err %d\n", __func__, ret);

			usedeskdock= true;
			isDeskdockconnected=1;
			Dockconnected = 1;
		}
		else
		{
			dev_info(&client->dev, "FSA9480_CheckAndHookAudioDock  Off ctrl reg: 0x%x\n", ret);
			if (pdata->deskdock_cb)
				pdata->deskdock_cb(FSA9480_DETACHED);

			ret = i2c_smbus_read_byte_data(client,FSA9480_REG_CTRL);
			if (ret < 0)
				dev_err(&client->dev,"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_write_byte_data(client,FSA9480_REG_CTRL, ret | CON_MANUAL_SW | CON_RAW_DATA);
			if (ret < 0)
				dev_err(&client->dev,"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_read_byte_data(client,FSA9480_REG_INT2_MASK);
			if (ret < 0)
				dev_err(&client->dev,"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_write_byte_data(client, FSA9480_REG_INT2_MASK, ret | INT_MASK_ADC_CHANGE);
			if (ret < 0)
				dev_err(&client->dev,"%s: err %d\n", __func__, ret);

			usedeskdock= false;
			isDeskdockconnected=0;
			Dockconnected = 0;
		}

		EnableFSA9480Interrupts();
	}
	else if (value == USB_HDMI_CABLE)
	{
		if (onoff)
		{	
			if (pdata->mhl_cb)
				pdata->mhl_cb(FSA9480_ATTACHED);
		}
		else
		{
			if (pdata->mhl_cb)
				pdata->mhl_cb(FSA9480_DETACHED);

			if (local_usbsw!=NULL)
				fsa9480_reg_init(local_usbsw);
		}
		usedeskdock= false;	
		isDeskdockconnected=0;		
		Dockconnected = 0;
	} else if (value == USE_VEHICLE_DOCK) {
		if (onoff) {

			ret = i2c_smbus_read_byte_data(client,FSA9480_REG_CTRL);

			dev_info(&client->dev, "FSA9480_CheckAndHookAudioDock On ctrl reg: 0x%x\n", ret);


//#if !defined(CONFIG_USA_MODEL_SGH_I717) && !defined (CONFIG_USA_MODEL_SGH_T769)
			if (!get_sec_det_jack_state()) {
				if (HWversion ==VERSION_FSA9480)
				{
					ret = i2c_smbus_write_byte_data(client,FSA9480_REG_MANSW1,SW_AUDIO);
				}
				else
				{
					ret = i2c_smbus_write_byte_data(client,FSA9480_REG_MANSW1,AUDIO_9485);
				}
			
				if (ret < 0)
					dev_err(&client->dev,"%s: err %d\n", __func__, ret);
			}
			else
				printk("%s: Earjack exist..\n", __func__);
//#endif

			ret = i2c_smbus_read_byte_data(client,FSA9480_REG_CTRL);
			if (ret < 0)
				dev_err(&client->dev,"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_write_byte_data(client,FSA9480_REG_CTRL, ret & ~CON_MANUAL_SW);
			if (ret < 0)
				dev_err(&client->dev,"%s: err %d\n", __func__, ret);

			Dockconnected = 1;
		}
		else
		{
			dev_info(&client->dev, "FSA9480_CheckAndHookAudioDock  Off ctrl reg: 0x%x\n", ret);

			ret = i2c_smbus_read_byte_data(client,FSA9480_REG_CTRL);
			if (ret < 0)
				dev_err(&client->dev,"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_write_byte_data(client,FSA9480_REG_CTRL, ret | CON_MANUAL_SW | CON_RAW_DATA);
			if (ret < 0)
				dev_err(&client->dev,"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_read_byte_data(client,FSA9480_REG_INT2_MASK);
			if (ret < 0)
				dev_err(&client->dev,"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_write_byte_data(client, FSA9480_REG_INT2_MASK, ret | INT_MASK_ADC_CHANGE);
			if (ret < 0)
				dev_err(&client->dev,"%s: err %d\n", __func__, ret);

			Dockconnected = 0;
		}
		
	}
	
}
static int tsu6721_detach_dev(struct tsu6721_usbsw *usbsw)
{
	struct tsu6721_platform_data *pdata = usbsw->pdata;

	/* USB */
	if (usbsw->dev1 & DEV_USB ||
			usbsw->dev2 & DEV_T2_USB_MASK) {
		pr_info("[MUIC] USB Disonnected\n");
		pdata->callback(CABLE_TYPE_USB, TSU6721_DETACHED);
		local_usbsw->last_state.detach = USB_CALL;
	/* CDP */
	} else if (usbsw->dev1 & DEV_USB_CHG) {
		pr_info("[MUIC] CDP Disconnected\n");
		pdata->callback(CABLE_TYPE_CDP, TSU6721_DETACHED);
		local_usbsw->last_state.detach = CDP_CALL;
	/* UART */
	} else if (usbsw->dev1 & DEV_T1_UART_MASK ||
			usbsw->dev2 & DEV_T2_UART_MASK) {
		pr_info("[MUIC] UART Disonnected\n");
#ifndef CONFIG_MACH_LT02
		pdata->callback(CABLE_TYPE_UARTOFF, TSU6721_DETACHED);
#endif
		local_usbsw->last_state.detach = UART_CALL;
		uart_connecting = 0;
	/* CHARGER */
	} else if ((usbsw->dev1 & DEV_T1_CHARGER_MASK) ||
			(usbsw->dev3 & DEV_T3_CHARGER_MASK)) {
		pr_info("[MUIC] Charger Disonnected\n");
		pdata->callback(CABLE_TYPE_AC, TSU6721_DETACHED);
		local_usbsw->last_state.detach = CHARGER_CALL;
#if defined(CONFIG_USB_HOST_NOTIFY)
	/* for SAMSUNG OTG */
	} else if (usbsw->dev1 & DEV_USB_OTG) {
		pr_info("[MUIC] OTG Disonnected\n");
		tsu6721_set_otg(usbsw, TSU6721_DETACHED);
		pdata->callback(CABLE_TYPE_OTG, TSU6721_DETACHED);
		local_usbsw->last_state.detach = OTG_CALL;
#endif
	/* JIG */
	} else if (usbsw->dev2 & DEV_T2_JIG_MASK) {
		pr_info("[MUIC] JIG Disonnected\n");
		pdata->callback(CABLE_TYPE_JIG, TSU6721_DETACHED);
		local_usbsw->last_state.detach = JIG_CALL;
	/* Desk Dock */
	} else if ((usbsw->dev2 & DEV_AV) ||
	(usbsw->dev3 & DEV_AV_VBUS)) {
		pr_info("[MUIC] Deskdock Disonnected\n");
		local_usbsw->dock_attached = TSU6721_DETACHED;
		tsu6721_dock_control(usbsw, CABLE_TYPE_DESK_DOCK,
			TSU6721_DETACHED, SW_ALL_OPEN);
		local_usbsw->last_state.detach = DESKDOCK_CALL;
#if defined(CONFIG_MHL_D3_SUPPORT)
	/* MHL */
	} else if (usbsw->dev3 & DEV_MHL) {
		pr_info("[MUIC] MHL Disonnected\n");
		mhl_onoff_ex(false);
		local_usbsw->last_state.detach = MHL_CALL;
		detached_status = 1;
#endif
	/* Car Dock */
	} else if (usbsw->dev2 & DEV_JIG_UART_ON) {
		pr_info("[MUIC] Cardock Disonnected\n");
		local_usbsw->dock_attached = TSU6721_DETACHED;
		tsu6721_dock_control(usbsw, CABLE_TYPE_CARDOCK,
			TSU6721_DETACHED, SW_ALL_OPEN);
		local_usbsw->last_state.detach = CARDOCK_CALL;
	/* Smart Dock */
	} else if (usbsw->dev2 == DEV_SMARTDOCK) {
		pr_info("[MUIC] Smartdock Disonnected\n");
		tsu6721_dock_control(usbsw, CABLE_TYPE_SMART_DOCK,
			TSU6721_DETACHED, SW_ALL_OPEN);
		local_usbsw->last_state.detach = SMARTDOCK_CALL;
#if defined(CONFIG_VIDEO_MHL_V2)
		mhl_onoff_ex(false);
#endif
#if defined(CONFIG_USB_HOST_NOTIFY)
	/* Audio Dock */
	} else if (usbsw->dev2 == DEV_AUDIO_DOCK) {
		pr_info("[MUIC] Audiodock Disonnected\n");
		tsu6721_dock_control(usbsw, CABLE_TYPE_AUDIO_DOCK,
			TSU6721_DETACHED, SW_ALL_OPEN);
		local_usbsw->last_state.detach = AUDIODOCK_CALL;
#endif
	/*LG cable support*/
	} else if (usbsw->dev2 == DEV_LG_CABLE) {
		pr_info("[MUIC] LG Data Cable Disconnected \n");
		pdata->callback(CABLE_TYPE_USB, TSU6721_DETACHED);
	/* Incompatible */
	} else if (usbsw->dev3 & DEV_VBUS_DEBOUNCE) {
		pr_info("[MUIC] Incompatible Charger Disonnected\n");
		pdata->callback(CABLE_TYPE_INCOMPATIBLE,
				TSU6721_DETACHED);
		local_usbsw->last_state.detach = INCOMPATIBLE_CALL;
	}
	usbsw->dev1 = 0;
	usbsw->dev2 = 0;
	usbsw->dev3 = 0;
	usbsw->adc = 0;

	return 0;

}
static int tsu6721_attach_dev(struct tsu6721_usbsw *usbsw)
{
	int adc;
	int val1, val2, val3;
	struct tsu6721_platform_data *pdata = usbsw->pdata;
	struct i2c_client *client = usbsw->client;
#if defined(CONFIG_VIDEO_MHL_V2)
	u8 mhl_ret = 0;
#endif
	val1 = i2c_smbus_read_byte_data(client, REG_DEVICE_TYPE1);
	if (val1 < 0) {
		dev_err(&client->dev, "%s: err %d\n", __func__, val1);
		return val1;
	}

	val2 = i2c_smbus_read_byte_data(client, REG_DEVICE_TYPE2);
	if (val2 < 0) {
		dev_err(&client->dev, "%s: err %d\n", __func__, val2);
		return val2;
	}
	jig_state =  (val2 & DEV_T2_JIG_ALL_MASK) ? 1 : 0;

	val3 = i2c_smbus_read_byte_data(client, REG_DEVICE_TYPE3);
	if (val3 < 0) {
		dev_err(&client->dev, "%s: err %d\n", __func__, val3);
		return val3;
	}
	adc = i2c_smbus_read_byte_data(client, REG_ADC);

	if (adc == ADC_SMART_DOCK) {
		val2 = DEV_SMARTDOCK;
		val1 = 0;
	}
#if defined(CONFIG_USB_HOST_NOTIFY)
	if (adc == 0x11 || adc == ADC_AUDIO_DOCK) {
		val2 = DEV_AUDIO_DOCK;
		val1 = 0;
	}
#endif
	if (adc == ADC_LG_CABLE) {
		val2 = DEV_LG_CABLE;
		val1 = 0;
	}
	if ((val1 & DEV_USB || val1 & DEV_USB_CHG ||
			val1 & DEV_T1_CHARGER_MASK) &&
			!(val3 & DEV_VBUS_DEBOUNCE)) {
		pr_info("%s Attach USB or Charger but not include VBUS",
				__func__);
		return 0;
	}

	dev_err(&client->dev,
			"dev1: 0x%x, dev2: 0x%x, dev3: 0x%x, ADC: 0x%x Jig:%s\n",
			val1, val2, val3, adc,
			(check_jig_state() ? "ON" : "OFF"));

	if ((val1+val2+val3 != 0)) {
		pr_info("%s Save state\n", __func__);
		local_usbsw->last_state.dev1 = val1;
		local_usbsw->last_state.dev2 = val2;
		local_usbsw->last_state.dev3 = val3;
	}

	/* USB */
	if (val1 & DEV_USB || val2 & DEV_T2_USB_MASK) {
		pr_info("[MUIC] USB Connected\n");
		pdata->callback(CABLE_TYPE_USB, TSU6721_ATTACHED);
		local_usbsw->last_state.attach = USB_CALL;
	/* USB_CDP */
	} else if (val1 & DEV_USB_CHG) {
		pr_info("[MUIC] CDP Connected\n");
		pdata->callback(CABLE_TYPE_CDP, TSU6721_ATTACHED);
		local_usbsw->last_state.attach = CDP_CALL;
	/* UART */
	} else if (val1 & DEV_T1_UART_MASK || val2 & DEV_T2_UART_MASK) {
		uart_connecting = 1;
		pr_info("[MUIC] UART Connected\n");
#ifndef CONFIG_MACH_LT02
		pdata->callback(CABLE_TYPE_UARTOFF, TSU6721_ATTACHED);
#endif
		local_usbsw->last_state.detach = UART_CALL;
	/* CHARGER */
	} else if ((val1 & DEV_T1_CHARGER_MASK) ||
			(val3 & DEV_T3_CHARGER_MASK)) {
		pr_info("[MUIC] Charger Connected\n");
		pdata->callback(CABLE_TYPE_AC, TSU6721_ATTACHED);
		local_usbsw->last_state.attach = CHARGER_CALL;
#if defined(CONFIG_USB_HOST_NOTIFY)
	/* for SAMSUNG OTG */
	} else if (val1 & DEV_USB_OTG) {
		pr_info("[MUIC] OTG Connected\n");
		tsu6721_set_otg(usbsw, TSU6721_ATTACHED);
		pdata->callback(CABLE_TYPE_OTG, TSU6721_ATTACHED);
		local_usbsw->last_state.attach = OTG_CALL;
#endif
	/* JIG */
	} else if (val2 & DEV_T2_JIG_MASK) {
		pr_info("[MUIC] JIG Connected\n");
		pdata->callback(CABLE_TYPE_JIG, TSU6721_ATTACHED);
		local_usbsw->last_state.attach = JIG_CALL;
	/* Desk Dock */
	} else if ((val2 & DEV_AV) || (val3 & DEV_AV_VBUS)) {
		pr_info("[MUIC] Deskdock Connected\n");
		local_usbsw->dock_attached = TSU6721_ATTACHED;
		tsu6721_dock_control(usbsw, CABLE_TYPE_DESK_DOCK,
			TSU6721_ATTACHED, SW_AUDIO);
		local_usbsw->last_state.attach = DESKDOCK_CALL;

#if defined(CONFIG_VIDEO_MHL_V2)
	/* MHL */
	} else if (val3 & DEV_MHL) {
		pr_info("[MUIC] MHL Connected\n");
		tsu6721_disable_interrupt();
		if (!poweroff_charging) {
			mhl_ret = mhl_onoff_ex(1);
			local_usbsw->last_state.attach = MHL_CALL;
		} else
			pr_info("LPM mode, skip MHL sequence\n");
		tsu6721_enable_interrupt();
#endif
	/* Car Dock */
	} else if (val2 & DEV_JIG_UART_ON) {
		pr_info("[MUIC] Cardock Connected\n");
		local_usbsw->dock_attached = TSU6721_ATTACHED;
		tsu6721_dock_control(usbsw, CABLE_TYPE_CARDOCK,
			TSU6721_ATTACHED, SW_AUDIO);
		local_usbsw->last_state.attach = CARDOCK_CALL;
	/* SmartDock */
	} else if (val2 & DEV_SMARTDOCK) {
		pr_info("[MUIC] Smartdock Connected\n");
		tsu6721_dock_control(usbsw, CABLE_TYPE_SMART_DOCK,
			TSU6721_ATTACHED, SW_DHOST);
		local_usbsw->last_state.attach = SMARTDOCK_CALL;
#if defined(CONFIG_VIDEO_MHL_V2)
		mhl_onoff_ex(1);
#endif
#if defined(CONFIG_USB_HOST_NOTIFY)
	/* Audio Dock */
	} else if (val2 & DEV_AUDIO_DOCK) {
		pr_info("[MUIC] Audiodock Connected\n");
		tsu6721_dock_control(usbsw, CABLE_TYPE_AUDIO_DOCK,
			TSU6721_ATTACHED, SW_DHOST);
		local_usbsw->last_state.attach = AUDIODOCK_CALL;
#endif
	/*LG cable support*/
	} else if (val2 & DEV_LG_CABLE) {
		pr_info("[MUIC] LG Data Cable connected \n");
		pdata->callback(CABLE_TYPE_USB, TSU6721_ATTACHED);
	/* Incompatible */
	} else if (val3 & DEV_VBUS_DEBOUNCE) {
		pr_info("[MUIC] Incompatible Charger Connected\n");
		pdata->callback(CABLE_TYPE_INCOMPATIBLE,
				TSU6721_ATTACHED);
		local_usbsw->last_state.attach = INCOMPATIBLE_CALL;
	}
	usbsw->dev1 = val1;
	usbsw->dev2 = val2;
	usbsw->dev3 = val3;
	usbsw->adc = adc;

	return adc;
}
/*extern void MHL_On(bool on);*/
void max77693_muic_mhl_cb(int attached)
{
	pr_info("MUIC attached:%d\n", attached);
	if (attached == MAX77693_MUIC_ATTACHED) {
		/*MHL_On(1);*/ /* GPIO_LEVEL_HIGH */
		pr_info("MHL Attached !!\n");
#ifdef CONFIG_SAMSUNG_MHL
#ifdef CONFIG_MHL_SII8246_VE
		pr_info("[MHL] max77693_muic_mhl_cb (): system_rev  = %d \n", system_rev );
		if(system_rev > 8) {
			sii8246_wake_lock();
			sii8246_mhl_onoff_ex(1);
		}else
#endif
{
#ifdef CONFIG_MACH_MIDAS
		sii9234_wake_lock();
#endif
#ifdef CONFIG_MHL_SII8246_VE
			sii9234_mhl_onoff_ex(1);
#else
			mhl_onoff_ex(1);
#endif
#endif
		}
	} else {
		/*MHL_On(0);*/ /* GPIO_LEVEL_LOW */
		pr_info("MHL Detached !!\n");
#ifdef CONFIG_SAMSUNG_MHL
#ifdef CONFIG_MHL_SII8246_VE
	if(system_rev > 8) {
			sii8246_mhl_onoff_ex(false);
			sii8246_wake_unlock();
	}else
	{
			sii9234_mhl_onoff_ex(false);
#else
	{
			mhl_onoff_ex(false);
#endif
#ifdef CONFIG_MACH_MIDAS
		sii9234_wake_unlock();
#endif
	}
#endif
	}
}

bool max77693_muic_is_mhl_attached(void)
{
	int val;
#ifdef CONFIG_SAMSUNG_USE_11PIN_CONNECTOR
	val = max77693_muic_get_status1_adc1k_value();
	pr_info("%s(1): %d\n", __func__, val);
	return val;
#else
	const int err = -1;
	int ret;

	ret = gpio_request(GPIO_MHL_SEL, "MHL_SEL");
	if (ret) {
			pr_err("fail to request gpio %s\n", "GPIO_MHL_SEL");
			return err;
	}
	val = gpio_get_value(GPIO_MHL_SEL);
	pr_info("%s(2): %d\n", __func__, val);
	gpio_free(GPIO_MHL_SEL);
	return !!val;
#endif
}
Exemplo n.º 8
0
static int fsa9485_detect_dev(struct fsa9485_usbsw *usbsw)
{
	int ret, adc;
	unsigned int val1, val2, val3;
	struct fsa9485_platform_data *pdata = usbsw->pdata;
	struct i2c_client *client = usbsw->client;
#if defined(CONFIG_VIDEO_MHL_V2)
	u8 mhl_ret = 0;
#endif

	val1 = i2c_smbus_read_byte_data(client, FSA9485_REG_DEV_T1);
	if (val1 < 0) {
		dev_err(&client->dev, "%s: err %d\n", __func__, val1);
		return val1;
	}

	val2 = i2c_smbus_read_byte_data(client, FSA9485_REG_DEV_T2);
	if (val2 < 0) {
		dev_err(&client->dev, "%s: err %d\n", __func__, val2);
		return val2;
	}
	jig_state =  (val2 & DEV_T2_JIG_ALL_MASK) ? 1 : 0;

	if (is_ti_muic()) {
		val3 = i2c_smbus_read_byte_data(client, FSA9485_REG_DEV_T3);
		if (val3 < 0) {
			dev_err(&client->dev, "%s: err %d\n", __func__, val3);
			return val3;
		}
	} else {
		val3 = i2c_smbus_read_byte_data(client,
				FSA9485_REG_RESERVED_1D);
		if (val3 < 0) {
			dev_err(&client->dev, "%s: err %d\n", __func__, val3);
			return val3;
		}
		val3 = val3 & 0x02;
	}

	adc = i2c_smbus_read_byte_data(client, FSA9485_REG_ADC);

	if (adc == 0x10)
		val2 = DEV_SMARTDOCK;
	else if (adc == 0x11 || adc == 0x12) {
		val2 = DEV_AUDIO_DOCK;
		dev_err(&client->dev, "adc is audio");
		val1 = 0;
	}
	dev_err(&client->dev,
			"dev1: 0x%x, dev2: 0x%x, dev3: 0x%x, ADC: 0x%x Jig:%s\n",
			val1, val2, val3, adc,
			(check_jig_state() ? "ON" : "OFF"));

	if ((val1+val2+val3 != 0)) {
		pr_info("%s Save state\n", __func__);
		local_usbsw->last_state.dev1 = val1;
		local_usbsw->last_state.dev2 = val2;
		local_usbsw->last_state.dev3 = val3;
	}

	/* Attached */
	if (val1 || val2 || (val3 & ~DEV_VBUS_DEBOUNCE) ||
			((val3 & DEV_VBUS_DEBOUNCE) && (adc != ADC_OPEN))) {
		/* USB */
		if (val1 & DEV_USB || val2 & DEV_T2_USB_MASK) {
			dev_info(&client->dev, "usb connect\n");
			pdata->callback(CABLE_TYPE_USB, FSA9485_ATTACHED);
			local_usbsw->last_state.attach = USB_CALL;

			if (usbsw->mansw) {
				ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_MANSW1, usbsw->mansw);

				if (ret < 0)
					dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
			}
		/* USB_CDP */
		} else if (val1 & DEV_USB_CHG) {
			dev_info(&client->dev, "usb_cdp connect\n");
#ifdef CONFIG_TSU6721_CDP_FIX
			pdata->callback(CABLE_TYPE_CDP, is_ti_muic() ? 
					TSU6721_ATTACHED : FSA9485_ATTACHED);
#else
			pdata->callback(CABLE_TYPE_CDP, FSA9485_ATTACHED);
#endif
			local_usbsw->last_state.attach = CDP_CALL;

			if (usbsw->mansw) {
				ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_MANSW1, usbsw->mansw);

				if (ret < 0)
					dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
			}

		/* UART */
		} else if (val1 & DEV_T1_UART_MASK || val2 & DEV_T2_UART_MASK) {
			uart_connecting = 1;
			dev_info(&client->dev, "uart connect\n");
			i2c_smbus_write_byte_data(client,
						FSA9485_REG_CTRL, 0x1E);
			pdata->callback(CABLE_TYPE_UARTOFF, FSA9485_ATTACHED);
			local_usbsw->last_state.attach = UART_CALL;

			if (usbsw->mansw) {
				ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_MANSW1, SW_UART);

				if (ret < 0)
					dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
			}
		/* CHARGER */
		} else if ((val1 & DEV_T1_CHARGER_MASK) ||
				(val3 & DEV_T3_CHARGER_MASK)) {
			dev_info(&client->dev, "charger connect\n");
			pdata->callback(CABLE_TYPE_AC, FSA9485_ATTACHED);
			local_usbsw->last_state.attach = CHARGER_CALL;
		/* for SAMSUNG OTG */
#if defined(CONFIG_USB_HOST_NOTIFY)
		} else if (val1 & DEV_USB_OTG) {
			dev_info(&client->dev, "otg connect\n");
			pdata->callback(CABLE_TYPE_OTG, FSA9485_ATTACHED);
			local_usbsw->last_state.attach = OTG_CALL;

			i2c_smbus_write_byte_data(client, FSA9485_REG_MANSW1,
					is_ti_muic() ? 0x25 : 0x27);
			i2c_smbus_write_byte_data(client,
						FSA9485_REG_MANSW2, 0x02);
			msleep(50);
			i2c_smbus_write_byte_data(client,
						FSA9485_REG_CTRL, 0x1a);
#endif
		/* JIG */
		} else if (val2 & DEV_T2_JIG_MASK) {
			dev_info(&client->dev, "jig connect\n");
			pdata->callback(CABLE_TYPE_JIG, FSA9485_ATTACHED);
			local_usbsw->last_state.attach = JIG_CALL;
		/* Desk Dock */
		} else if ((val2 & DEV_AV) || (val3 & DEV_MHL) ||
			(val3 & DEV_AV_VBUS)) {
			if ((!is_ti_muic()) && ((adc & 0x1F) == 0x1A)) {
				pr_info("FSA Deskdock Attach\n");
				FSA9485_CheckAndHookAudioDock(1);
#if defined(CONFIG_VIDEO_MHL_V2)
				isDeskdockconnected = 1;
#endif
				i2c_smbus_write_byte_data(client,
					FSA9485_REG_RESERVED_20, 0x08);
			} else if ((is_ti_muic()) && !(val3 & DEV_MHL)) {
				pr_info("TI Deskdock Attach\n");
				FSA9485_CheckAndHookAudioDock(1);
#if defined(CONFIG_VIDEO_MHL_V2)
				isDeskdockconnected = 1;
#endif
			} else {
				pr_info("MHL Attach\n");
				if (!is_ti_muic())
					i2c_smbus_write_byte_data(client,
						FSA9485_REG_RESERVED_20, 0x08);
#if defined(CONFIG_VIDEO_MHL_V2)
				DisableFSA9480Interrupts();
				if (!isDeskdockconnected) {
					if (!poweroff_charging)
						mhl_ret = mhl_onoff_ex(1);
					else
						pr_info("LPM mode, skip MHL sequence\n");
				}
			local_usbsw->last_state.device = MHL_CALL;
				if (mhl_ret != MHL_DEVICE &&
						(adc & 0x1F) == 0x1A) {
					FSA9485_CheckAndHookAudioDock(1);
					isDeskdockconnected = 1;
				}
				EnableFSA9480Interrupts();
#else
				FSA9485_CheckAndHookAudioDock(1);
#endif
			}
		/* Car Dock */
		} else if (val2 & DEV_JIG_UART_ON) {
			pdata->callback(CABLE_TYPE_CARDOCK,
				FSA9485_ATTACHED);
			local_usbsw->last_state.attach = CARDOCK_CALL;
			ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_MANSW1, SW_AUDIO);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_read_byte_data(client,
					FSA9485_REG_CTRL);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_CTRL, ret & ~CON_MANUAL_SW);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
			usbsw->dock_attached = FSA9485_ATTACHED;
		/* SmartDock */
		} else if (val2 & DEV_SMARTDOCK) {
			usbsw->adc = adc;
			dev_info(&client->dev, "smart dock connect\n");

			usbsw->mansw = SW_DHOST;
			ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_MANSW1, SW_DHOST);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
			ret = i2c_smbus_read_byte_data(client,
					FSA9485_REG_CTRL);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
			ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_CTRL, ret & ~CON_MANUAL_SW);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);

			pdata->callback(CABLE_TYPE_SMART_DOCK,
				FSA9485_ATTACHED);
			local_usbsw->last_state.attach = SMARTDOCK_CALL;
#if defined(CONFIG_VIDEO_MHL_V2)
			mhl_onoff_ex(1);
#endif
#if defined(CONFIG_USB_HOST_NOTIFY)
		/* Audio Dock */
		} else if (val2 & DEV_AUDIO_DOCK) {
			usbsw->adc = adc;
			dev_info(&client->dev, "audio dock connect\n");

			usbsw->mansw = SW_DHOST;

			if (is_ti_muic())
				ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_MANSW1, SW_DHOST_TSU);
			else
				ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_MANSW1, SW_DHOST);

			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_read_byte_data(client,
				FSA9485_REG_CTRL);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);
			ret = i2c_smbus_write_byte_data(client,
				FSA9485_REG_CTRL, ret & ~CON_MANUAL_SW);
			if (ret < 0)
				dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);

			pdata->callback(CABLE_TYPE_AUDIO_DOCK,
				FSA9485_ATTACHED);
			local_usbsw->last_state.attach = AUDIODOCK_CALL;
#endif
		/* Incompatible */
		} else if (val3 & DEV_VBUS_DEBOUNCE) {
			dev_info(&client->dev,
					"Incompatible Charger connect\n");
			pdata->callback(CABLE_TYPE_INCOMPATIBLE,
					FSA9485_ATTACHED);
			local_usbsw->last_state.attach = INCOMPATIBLE_CALL;
		}
	/* Detached */
	} else {
		/* USB */
		if (usbsw->dev1 & DEV_USB ||
				usbsw->dev2 & DEV_T2_USB_MASK) {
			pdata->callback(CABLE_TYPE_USB, FSA9485_DETACHED);
			local_usbsw->last_state.detach = USB_CALL;
		} else if (usbsw->dev1 & DEV_USB_CHG) {
			pdata->callback(CABLE_TYPE_CDP, FSA9485_DETACHED);
			local_usbsw->last_state.detach = CDP_CALL;

		/* UART */
		} else if (usbsw->dev1 & DEV_T1_UART_MASK ||
				usbsw->dev2 & DEV_T2_UART_MASK) {
			pdata->callback(CABLE_TYPE_UARTOFF, FSA9485_DETACHED);
			local_usbsw->last_state.detach = UART_CALL;
			uart_connecting = 0;
			dev_info(&client->dev, "[FSA9485] uart disconnect\n");

		/* CHARGER */
		} else if ((usbsw->dev1 & DEV_T1_CHARGER_MASK) ||
				(usbsw->dev3 & DEV_T3_CHARGER_MASK)) {
			pdata->callback(CABLE_TYPE_AC, FSA9485_DETACHED);
			local_usbsw->last_state.detach = CHARGER_CALL;
		/* for SAMSUNG OTG */
		} else if (usbsw->dev1 & DEV_USB_OTG) {
			i2c_smbus_write_byte_data(client,
						FSA9485_REG_CTRL, 0x1E);
		/* JIG */
		} else if (usbsw->dev2 & DEV_T2_JIG_MASK) {
			pdata->callback(CABLE_TYPE_JIG, FSA9485_DETACHED);
			local_usbsw->last_state.detach = JIG_CALL;
		/* Desk Dock */
		} else if ((usbsw->dev2 & DEV_AV) || (usbsw->dev3 & DEV_MHL) ||
				(usbsw->dev3 & DEV_AV_VBUS)) {

			pr_info("Deskdock/MHL Detach\n");

			if (!is_ti_muic())
				i2c_smbus_write_byte_data(client,
					FSA9485_REG_RESERVED_20, 0x04);
#if defined(CONFIG_VIDEO_MHL_V2)
			if (isDeskdockconnected)
				FSA9485_CheckAndHookAudioDock(0);
#if defined CONFIG_MHL_D3_SUPPORT
			mhl_onoff_ex(false);
			detached_status = 1;
#endif
			isDeskdockconnected = 0;
#else
			FSA9485_CheckAndHookAudioDock(0);
#endif
		/* Car Dock */
		} else if (usbsw->dev2 & DEV_JIG_UART_ON) {
			pdata->callback(CABLE_TYPE_CARDOCK,
				FSA9485_DETACHED_DOCK);
			local_usbsw->last_state.detach = CARDOCK_CALL;
			ret = i2c_smbus_read_byte_data(client,
					FSA9485_REG_CTRL);
			if (ret < 0)
				dev_err(&client->dev,
					"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_CTRL,
					ret | CON_MANUAL_SW);
			if (ret < 0)
				dev_err(&client->dev,
					"%s: err %d\n", __func__, ret);
			usbsw->dock_attached = FSA9485_DETACHED;
		} else if (usbsw->adc == 0x10) {
			dev_info(&client->dev, "smart dock disconnect\n");
			ret = i2c_smbus_read_byte_data(client,
						FSA9485_REG_CTRL);
			if (ret < 0)
				dev_err(&client->dev,
					"%s: err %d\n", __func__, ret);

			ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_CTRL,
					ret | CON_MANUAL_SW);
			if (ret < 0)
				dev_err(&client->dev,
					"%s: err %d\n", __func__, ret);

			pdata->callback(CABLE_TYPE_SMART_DOCK,
				FSA9485_DETACHED);
			local_usbsw->last_state.detach = SMARTDOCK_CALL;
			usbsw->adc = 0;
#if defined(CONFIG_VIDEO_MHL_V2)
			mhl_onoff_ex(false);
#endif
		} else if (usbsw->dev2 == DEV_AUDIO_DOCK) {
			dev_info(&client->dev, "audio dock disconnect\n");
			ret = i2c_smbus_read_byte_data(client,
				    FSA9485_REG_CTRL);
			    if (ret < 0)
					dev_err(&client->dev,
					    "%s: err %d\n", __func__, ret);
				ret = i2c_smbus_write_byte_data(client,
						FSA9485_REG_CTRL,
						ret | CON_MANUAL_SW);
			    if (ret < 0)
					dev_err(&client->dev,
						"%s: err %d\n", __func__, ret);

			pdata->callback(CABLE_TYPE_AUDIO_DOCK,
					FSA9485_DETACHED);
			local_usbsw->last_state.detach = AUDIODOCK_CALL;
			usbsw->adc = 0;
		} else if (usbsw->dev3 & DEV_VBUS_DEBOUNCE) {
			dev_info(&client->dev,
					"Incompatible Charger disconnect\n");
			pdata->callback(CABLE_TYPE_INCOMPATIBLE,
					FSA9485_DETACHED);
			local_usbsw->last_state.detach = INCOMPATIBLE_CALL;
		}
	}
	usbsw->dev1 = val1;
	usbsw->dev2 = val2;
	usbsw->dev3 = val3;

	return adc;
}
Exemplo n.º 9
0
static int fsa9485_detach_dev(struct fsa9485_usbsw *usbsw)
{
	int ret;
	struct fsa9485_platform_data *pdata = usbsw->pdata;
	struct i2c_client *client = usbsw->client;
#if defined(CONFIG_VIDEO_MHL_V2)
	u8 mhl_ret = 0;
#endif
	/* USB */
	if (usbsw->dev1 & DEV_USB ||
			usbsw->dev2 & DEV_T2_USB_MASK) {
		pdata->callback(CABLE_TYPE_USB, FSA9485_DETACHED);
		local_usbsw->last_state.detach = USB_CALL;
	} else if (usbsw->dev1 & DEV_USB_CHG) {
		pdata->callback(CABLE_TYPE_CDP, FSA9485_DETACHED);
		local_usbsw->last_state.detach = CDP_CALL;
		/* UART */
	} else if (usbsw->dev1 & DEV_T1_UART_MASK ||
			usbsw->dev2 & DEV_T2_UART_MASK) {
		pdata->callback(CABLE_TYPE_UARTOFF, FSA9485_DETACHED);
		local_usbsw->last_state.detach = UART_CALL;
		uart_connecting = 0;
		dev_info(&client->dev, "[FSA9485] uart disconnect\n");
		/* CHARGER */
	} else if ((usbsw->dev1 & DEV_T1_CHARGER_MASK) ||
			(usbsw->dev3 & DEV_T3_CHARGER_MASK)) {
		pdata->callback(CABLE_TYPE_AC, FSA9485_DETACHED);
		local_usbsw->last_state.detach = CHARGER_CALL;
	/* for SAMSUNG OTG */
	} else if (usbsw->dev1 & DEV_USB_OTG) {
		i2c_smbus_write_byte_data(client,
					FSA9485_REG_CTRL, 0x1E);
	/* JIG */
	} else if (usbsw->dev2 & DEV_T2_JIG_MASK) {
		pdata->callback(CABLE_TYPE_JIG, FSA9485_DETACHED);
		local_usbsw->last_state.detach = JIG_CALL;
	/* Desk Dock */
	} else if ((usbsw->dev2 & DEV_AV) || (usbsw->dev3 & DEV_MHL) ||
			(usbsw->dev3 & DEV_AV_VBUS)) {
			pr_info("Deskdock/MHL Detach\n");
			if (!is_ti_muic())
			i2c_smbus_write_byte_data(client,
				FSA9485_REG_RESERVED_20, 0x04);
#if defined(CONFIG_VIDEO_MHL_V2)
		if (isDeskdockconnected)
			FSA9485_CheckAndHookAudioDock(0);
#if defined CONFIG_MHL_D3_SUPPORT
		mhl_onoff_ex(false);
		detached_status = 1;
#endif
		isDeskdockconnected = 0;
#else
		FSA9485_CheckAndHookAudioDock(0);
#endif
	/* Car Dock */
	} else if (usbsw->dev2 & DEV_JIG_UART_ON) {
		pdata->callback(CABLE_TYPE_CARDOCK,
			FSA9485_DETACHED_DOCK);
		local_usbsw->last_state.detach = CARDOCK_CALL;
		ret = i2c_smbus_read_byte_data(client,
				FSA9485_REG_CTRL);
		if (ret < 0)
			dev_err(&client->dev,
					"%s: err %d\n", __func__, ret);
		ret = i2c_smbus_write_byte_data(client,
				FSA9485_REG_CTRL,
				ret | CON_MANUAL_SW);
		if (ret < 0)
			dev_err(&client->dev,
				"%s: err %d\n", __func__, ret);
		usbsw->dock_attached = FSA9485_DETACHED;
	} else if (usbsw->adc == 0x10) {
		dev_info(&client->dev, "smart dock disconnect\n");
		ret = i2c_smbus_read_byte_data(client,
					FSA9485_REG_CTRL);
		if (ret < 0)
			dev_err(&client->dev,
				"%s: err %d\n", __func__, ret);
			ret = i2c_smbus_write_byte_data(client,
				FSA9485_REG_CTRL,
				ret | CON_MANUAL_SW);
		if (ret < 0)
			dev_err(&client->dev,
				"%s: err %d\n", __func__, ret);
			pdata->callback(CABLE_TYPE_SMART_DOCK,
			FSA9485_DETACHED);
		local_usbsw->last_state.detach = SMARTDOCK_CALL;
		usbsw->adc = 0;
#if defined(CONFIG_VIDEO_MHL_V2)
		mhl_onoff_ex(false);
#endif
	} else if (usbsw->dev2 == DEV_AUDIO_DOCK) {
		dev_info(&client->dev, "audio dock disconnect\n");
		ret = i2c_smbus_read_byte_data(client,
			    FSA9485_REG_CTRL);
		    if (ret < 0)
				dev_err(&client->dev,
				    "%s: err %d\n", __func__, ret);
			ret = i2c_smbus_write_byte_data(client,
					FSA9485_REG_CTRL,
					ret | CON_MANUAL_SW);
		    if (ret < 0)
				dev_err(&client->dev,
					"%s: err %d\n", __func__, ret);
			pdata->callback(CABLE_TYPE_AUDIO_DOCK,
				FSA9485_DETACHED);
		local_usbsw->last_state.detach = AUDIODOCK_CALL;
		usbsw->adc = 0;
	} else if (usbsw->dev3 & DEV_VBUS_DEBOUNCE) {
		dev_info(&client->dev,
				"Incompatible Charger disconnect\n");
		pdata->callback(CABLE_TYPE_INCOMPATIBLE,
				FSA9485_DETACHED);
		local_usbsw->last_state.detach = INCOMPATIBLE_CALL;
	} else
		pr_info("%s cannot detach due to invalid device type",
				__func__);

	usbsw->dev1 = 0;
	usbsw->dev2 = 0;
	usbsw->dev3 = 0;

	return 0;
}