static int fsa9485_detect_dev(struct fsa9485_usbsw *usbsw)
{
	int device_type, ret;
	unsigned int dev1, dev2, dev3, 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
	pr_info("%s", __func__);

	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;
	}
	dev1 = device_type & 0xff;
	dev2 = device_type >> 8;

	jig_state = (dev2 & DEV_T2_JIG_MASK) ? 1 : 0;

	adc = i2c_smbus_read_byte_data(client, FSA9485_REG_ADC);

/* remove for right perform for lanhub / defence code for factory */
#if 0
	if (usbsw->dock_attached && usbsw->previous_dock == FSA9485_NONE)
		pdata->dock_cb(FSA9485_DETACHED_DOCK);
#endif

	if (local_usbsw->dock_ready == 1) {
		if (adc == 0x0f)
			dev2 = DEV_INCOMPATIBLE;
		else if (adc == 0x10)
			dev2 = DEV_SMARTDOCK;
		else if (adc == 0x12)
			dev2 = DEV_AUDIO_DOCK;
#ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
		else if (adc == 0x13)
			dev2 = DEV_LANHUB;
#endif
		else if (adc == 0x14)
			dev2 = DEV_CHARGING_CABLE;
		else if (adc == 0x15){
			dev2 = DEV_MMDOCK;
			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);
			mmdock_connect = 1;
		}
	}

	dev3 = i2c_smbus_read_byte_data(client,
			FSA9485_REG_RESERVED_1D);
	if(dev3 < 0) {
		dev_err(&client->dev, "%s: err %d\n", __func__, dev3);
		return dev3;
	}
	dev3 = dev3 & 0x02;
	dev_info(&client->dev, "dev1: 0x%02x, dev2: 0x%02x,dev3: 0x%02x, adc: 0x%02x\n",
		dev1, dev2, dev3, adc);

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

			if (pdata->usb_cb)
				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 (dev1 & 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 (dev1 & DEV_T1_UART_MASK || dev2 & 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 (dev1 & 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 (dev1 & DEV_USB_OTG) {
#ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
			/* Enable RAWDATA Interrupts */
			fsa9485_enable_rawdataInterrupts();
#endif
			usbsw->dock_attached = FSA9485_ATTACHED;
#ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
			usbsw->previous_dock = ADC_GND;
#endif
			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);
		/* JIG */
		} else if (dev2 & DEV_T2_JIG_MASK) {
			dev_info(&client->dev, "jig connect\n");

			if (pdata->jig_cb)
				pdata->jig_cb(FSA9485_ATTACHED);
		/* Desk Dock */
		} else if (dev2 & DEV_AV) {
			if ((adc & 0x1F) == ADC_DESKDOCK) {
				dev_info(&client->dev, "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 {
				dev_info(&client->dev, "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)
				DisableFSA9485Interrupts();

				if (isMhlAttached != MHL_ATTACHED) {
					isMhlAttached = MHL_ATTACHED;
					schedule_delayed_work(&usbsw->mhl_work, msecs_to_jiffies(100));
				} else {
					dev_info(&client->dev, "FSA mhl is initializing... bypass\n");
				}

				EnableFSA9485Interrupts();
#else
				dev_info(&client->dev, "FSA mhl attach, but not support MHL feature!\n");
#endif
			}
		/* Car Dock */
		} else if (dev2 & DEV_JIG_UART_ON) {
#if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
			if (usbsw->is_factory_start) {
#endif
				dev_info(&client->dev, "car dock connect\n");

				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;
#if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
			} else {
				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);
				}
			}
#endif /* !CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK */
		} else if (dev2 & DEV_INCOMPATIBLE) {
			usbsw->adc = adc;
			dev_info(&client->dev, "Inompatible CHARGER connect\n");

			if (pdata->in_charger_cb)
				pdata->in_charger_cb(FSA9485_ATTACHED);
		/* SmartDock */
		} else if (dev2 & 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
		/*MMDock*/
		} else if ((dev2 & DEV_MMDOCK) && (dev3 & 0x02)) {
			if(mmdock_flag == 0)
				fsa9485_mmdock_attach();

		} else if (dev2 & 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->audio_dock_cb)
				pdata->audio_dock_cb(FSA9485_ATTACHED);
#ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
		/* LANHUB */
		} else if (dev2 & DEV_LANHUB) {
			/* Enable RAWDATA Interrupts */
			fsa9485_enable_rawdataInterrupts();

			usbsw->adc = adc;
			dev_info(&client->dev, "lanhub connect\n");

			usbsw->dock_attached = FSA9485_ATTACHED;
			usbsw->previous_dock = ADC_LANHUB;
			usbsw->lanhub_ta_status=1;

			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->lanhub_cb)
				pdata->lanhub_cb(FSA9485_ATTACHED);
#endif
		/* CHARGING CABLE */
		} else if (dev2 & DEV_CHARGING_CABLE) {
			dev_info(&client->dev, "charging cable connect\n");
			usbsw->dock_attached = FSA9485_ATTACHED;
			usbsw->adc = adc;

			if (pdata->charge_cb)
				pdata->charge_cb(FSA9485_ATTACHED);
		/* Incompatible */
		} else if (dev3 & DEV_VBUS_DEBOUNCE) {
			dev_info(&client->dev,
					"Unsupported ADC, VBUS is valid = CHARGER\n");
			if (pdata->charger_cb)
				pdata->charger_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) {
#ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
			/* Disable RAWDATA Interrupts */
			fsa9485_disable_rawdataInterrupts();
			dev_info(&client->dev, "%s:lanhub_ta_status(%d)\n",
					__func__, usbsw->lanhub_ta_status);
			if (pdata->otg_cb && usbsw->lanhub_ta_status == 0)
				pdata->otg_cb(FSA9485_DETACHED);
			else if (pdata->lanhub_cb && usbsw->lanhub_ta_status == 1)
				pdata->lanhub_cb(FSA9485_DETACHED);

			usbsw->dock_attached = FSA9485_DETACHED;
			usbsw->lanhub_ta_status=0;
#else
			if (pdata->otg_cb)
				pdata->otg_cb(FSA9485_DETACHED);
			usbsw->dock_attached = FSA9485_DETACHED;
#endif
			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);

			isMhlAttached = MHL_DETACHED;
			cancel_delayed_work(&usbsw->mhl_work);
			schedule_delayed_work(&usbsw->mhl_work, msecs_to_jiffies(10));

			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 !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
			if (usbsw->is_factory_start) {
#endif
				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;
#if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
			} else {
				if (pdata->uart_cb)
					pdata->uart_cb(FSA9485_DETACHED);
				uart_connecting = 0;
				dev_info(&client->dev, "[FSA9485] uart disconnect\n");
			}
#endif /* !CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK */
		} else if (usbsw->adc == 0x0f) {
			dev_info(&client->dev, "Incompatible Charger disconnect\n");

			if (pdata->in_charger_cb)
				pdata->in_charger_cb(FSA9485_DETACHED);
			usbsw->adc = 0;
		} 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->audio_dock_cb)
				pdata->audio_dock_cb(FSA9485_DETACHED);
			usbsw->adc = 0;
#ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
		/* LANHUB */
		} else if (usbsw->adc == 0x13) {
			dev_info(&client->dev, "lanhub disconnect\n");

			/* Disable RAWDATA Interrupts */
			fsa9485_disable_rawdataInterrupts();

			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);
			dev_info(&client->dev, "%s:lanhub_ta_status(%d)\n",
					__func__, usbsw->lanhub_ta_status);
			if (pdata->lanhub_cb && usbsw->lanhub_ta_status==1)
				pdata->lanhub_cb(FSA9485_DETACHED);
			else if (pdata->otg_cb && usbsw->lanhub_ta_status == 0)
				pdata->otg_cb(FSA9485_DETACHED);

			usbsw->dock_attached = FSA9485_DETACHED;
			usbsw->adc = 0;
			usbsw->lanhub_ta_status=0;
#endif
		/* Charging Cable */
		} else if (usbsw->adc == 0x14) {
			dev_info(&client->dev, "charging_cable disconnect\n");
			usbsw->dock_attached = FSA9485_DETACHED;
			usbsw->adc = 0;
			usbsw->dev2 = 0;
			if (pdata->charge_cb)
				pdata->charge_cb(FSA9485_DETACHED);
		/*MM DOCK*/
		}else if (mmdock_connect == 1) {
			mmdock_connect = 0;
			if(mmdock_flag == 1)
				fsa9485_mmdock_detach();

		} else if (usbsw->dev3 & DEV_VBUS_DEBOUNCE) {
			dev_info(&client->dev,
					"Unsupported adc, Charger disconnect\n");
			if (pdata->charger_cb)
				pdata->charger_cb(FSA9485_DETACHED);
		}
		/*	set auto mode	*/
		i2c_smbus_write_byte_data(client,FSA9485_REG_CTRL, 0x1E);
	}
	usbsw->dev1 = dev1;
	usbsw->dev2 = dev2;
	usbsw->dev3 = dev3;

	return adc;
}
Beispiel #2
0
static int fsa9485_detect_dev(struct fsa9485_usbsw *usbsw)
{
	int device_type, ret;
	unsigned int dev1, dev2, 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
	pr_info("%s", __func__);

	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;
	}
	dev1 = device_type & 0xff;
	dev2 = device_type >> 8;
	adc = i2c_smbus_read_byte_data(client, FSA9485_REG_ADC);

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

	if (local_usbsw->dock_ready == 1) {
		if (adc == 0x10)
			dev2 = DEV_SMARTDOCK;
		else if (adc == 0x12)
			dev2 = DEV_AUDIO_DOCK;
	}

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

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

			if (pdata->usb_cb)
				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 (dev1 & 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 (dev1 & DEV_T1_UART_MASK || dev2 & 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 (dev1 & 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 (dev1 & 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 (dev2 & DEV_T2_JIG_MASK) {
			dev_info(&client->dev, "jig connect\n");

			if (pdata->jig_cb)
				pdata->jig_cb(FSA9485_ATTACHED);
		/* Desk Dock */
		} else if (dev2 & DEV_AV) {
			if ((adc & 0x1F) == ADC_DESKDOCK) {
				dev_info(&client->dev, "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 {
				dev_info(&client->dev, "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)
				DisableFSA9485Interrupts();

				isMhlAttached = MHL_ATTACHED;
				schedule_work(&usbsw->mhl_work);

				EnableFSA9485Interrupts();
#else
				dev_info(&client->dev, "FSA mhl attach, but not support MHL feature!\n");
#endif
			}
		/* Car Dock */
		} else if (dev2 & DEV_JIG_UART_ON) {
#if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
			if (usbsw->is_factory_start) {
#endif
				dev_info(&client->dev, "car dock connect\n");

				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;
#if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
			} else {
				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);
				}
			}
#endif /* !CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK */
		/* SmartDock */
		} else if (dev2 & 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 (dev2 & 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->audio_dock_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) {
			if (pdata->otg_cb)
				pdata->otg_cb(FSA9485_DETACHED);
			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);

			isMhlAttached = MHL_DETACHED;
			schedule_work(&usbsw->mhl_work);

			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 !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
			if (usbsw->is_factory_start) {
#endif
				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;
#if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
			} else {
				if (pdata->uart_cb)
					pdata->uart_cb(FSA9485_DETACHED);
				uart_connecting = 0;
				dev_info(&client->dev, "[FSA9485] uart disconnect\n");
			}
#endif /* !CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK */
		} 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->audio_dock_cb)
				pdata->audio_dock_cb(FSA9485_DETACHED);
			usbsw->adc = 0;
		}

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

	return adc;
}