/*
 * driver/ccic/ccic_alternate.c - S2MM005 USB CCIC Alternate mode driver
 *
 * Copyright (C) 2016 Samsung Electronics
 * Author: Wookwang Lee <wookwang.lee@samsung.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 */
#include <linux/ccic/s2mm005.h>
#include <linux/ccic/s2mm005_ext.h>
#include <linux/ccic/ccic_alternate.h>
#include <asm/byteorder.h>
#include "ccic_misc.h"
#if defined(CONFIG_USB_HOST_NOTIFY)
#include <linux/usb_notify.h>
#endif
/* switch device header */
#if defined(CONFIG_SWITCH)
#include <linux/switch.h>
#else
#error "ERROR: CONFIG_SWITCH is not set."
#endif /* CONFIG_SWITCH */
/********************************************
 *
 * s2mm005_cc.c called s2mm005_alternate.c
 *
 ********************************************
*/
#if defined(CONFIG_CCIC_ALTERNATE_MODE)
extern struct device *ccic_device;
#if defined(CONFIG_SWITCH)
static struct switch_dev switch_dock = {
	.name = "ccic_dock",
};
#endif /* CONFIG_SWITCH */

static char VDM_MSG_IRQ_State_Print[9][40] =
{
    {"bFLAG_Vdm_Reserve_b0"},
    {"bFLAG_Vdm_Discover_ID"},
    {"bFLAG_Vdm_Discover_SVIDs"},
    {"bFLAG_Vdm_Discover_MODEs"},
    {"bFLAG_Vdm_Enter_Mode"},
    {"bFLAG_Vdm_Exit_Mode"},
    {"bFLAG_Vdm_Attention"},
    {"bFlag_Vdm_DP_Status_Update"},
    {"bFlag_Vdm_DP_Configure"},
};

static char DP_Pin_Assignment_Print[7][40] =
{
    {"DP_Pin_Assignment_None"},
    {"DP_Pin_Assignment_A"},
    {"DP_Pin_Assignment_B"},
    {"DP_Pin_Assignment_C"},
    {"DP_Pin_Assignment_D"},
    {"DP_Pin_Assignment_E"},
    {"DP_Pin_Assignment_F"},

};
/*
*********************************************
*
*  Alternate mode processing
*
*********************************************
*/
int ccic_register_switch_device(int mode)
{
#ifdef CONFIG_SWITCH
	int ret = 0;

	if (mode) {
		ret = switch_dev_register(&switch_dock);
		if (ret < 0) {
			pr_err("%s: Failed to register dock switch(%d)\n",
			       __func__, ret);
			return -ENODEV;
		}
	} else {
		switch_dev_unregister(&switch_dock);
	}
#endif /* CONFIG_SWITCH */
	return 0;
}

static void ccic_send_dock_intent(int type)
{
	pr_info("%s: CCIC dock type(%d)\n", __func__, type);
#ifdef CONFIG_SWITCH
	switch_set_state(&switch_dock, type);
#endif /* CONFIG_SWITCH */
}

void ccic_send_dock_uevent(u32 vid, u32 pid, int state)
{
	char switch_string[32];
	char pd_ids_string[32];
	char *envp[3] = { switch_string, pd_ids_string, NULL };

	pr_info("%s: CCIC dock : USBPD_IPS=%04x:%04x SWITCH_STATE=%d\n",
			__func__,
			le16_to_cpu(vid),
			le16_to_cpu(pid),
			state);

	if (IS_ERR(ccic_device)) {
		pr_err("%s CCIC ERROR: Failed to send a dock uevent!\n",
				__func__);
		return;
	}

	snprintf(switch_string, 32, "SWITCH_STATE=%d", state);
	snprintf(pd_ids_string, 32, "USBPD_IDS=%04x:%04x",
			le16_to_cpu(vid),
			le16_to_cpu(pid));
	kobject_uevent_env(&ccic_device->kobj, KOBJ_CHANGE, envp);
}

void acc_detach_check(struct work_struct *wk)
{
	struct delayed_work *delay_work =
		container_of(wk, struct delayed_work, work);
	struct s2mm005_data *usbpd_data =
		container_of(delay_work, struct s2mm005_data, acc_detach_work);

	pr_info("%s: usbpd_data->pd_state : %d\n", __func__,
		usbpd_data->pd_state);
	if (usbpd_data->pd_state == State_PE_Initial_detach) {
		if (usbpd_data->acc_type != CCIC_DOCK_DETACHED) {
			if (usbpd_data->acc_type != CCIC_DOCK_NEW)
				ccic_send_dock_intent(CCIC_DOCK_DETACHED);
			ccic_send_dock_uevent(usbpd_data->Vendor_ID,
					usbpd_data->Product_ID,
					CCIC_DOCK_DETACHED);
			usbpd_data->acc_type = CCIC_DOCK_DETACHED;
			usbpd_data->Vendor_ID = 0;
			usbpd_data->Product_ID = 0;
		}
	}
}

void set_enable_powernego(int mode)
{
	struct s2mm005_data *usbpd_data;
	u8 W_DATA[2];

	if (!ccic_device)
		return;
	usbpd_data = dev_get_drvdata(ccic_device);
	if (!usbpd_data)
		return;

	if (mode) {
		W_DATA[0] = 0x3;
		W_DATA[1] = 0x42;
		s2mm005_write_byte(usbpd_data->i2c, 0x10, &W_DATA[0], 2);
		pr_info("%s : Power nego start\n", __func__);
	} else
		pr_info("%s : Power nego stop\n", __func__);
}

void set_enable_alternate_mode(int mode)
{
	struct s2mm005_data *usbpd_data;
	static int check_is_driver_loaded = 0;
	static int prev_alternate_mode = 0;
	u8 W_DATA[2];

	if (!ccic_device)
		return;
	usbpd_data = dev_get_drvdata(ccic_device);
	if (!usbpd_data)
		return;

#ifdef CONFIG_USB_NOTIFY_PROC_LOG
	store_usblog_notify(NOTIFY_ALTERNATEMODE, (void *)&mode, NULL);
#endif
	if ((mode & ALTERNATE_MODE_NOT_READY) &&
	    (mode & ALTERNATE_MODE_READY)) {
		pr_info("%s : mode is invalid!\n", __func__);
		return;
	}
	if ((mode & ALTERNATE_MODE_START) && (mode & ALTERNATE_MODE_STOP)) {
		pr_info("%s : mode is invalid!\n", __func__);
		return;
	}
	if (mode & ALTERNATE_MODE_RESET) {
		pr_info("%s : mode is reset! check_is_driver_loaded=%d, prev_alternate_mode=%d\n",
			__func__, check_is_driver_loaded, prev_alternate_mode);
		if (check_is_driver_loaded &&
		    (prev_alternate_mode == ALTERNATE_MODE_START)) {
			W_DATA[0] = 0x3;
			W_DATA[1] = 0x31;
			s2mm005_write_byte(usbpd_data->i2c, 0x10, &W_DATA[0], 2);
			pr_info("%s : alternate mode is reset as start!\n",
				__func__);
			prev_alternate_mode = ALTERNATE_MODE_START;
		} else if (check_is_driver_loaded &&
			   (prev_alternate_mode == ALTERNATE_MODE_STOP)) {
			W_DATA[0] = 0x3;
			W_DATA[1] = 0x33;
			s2mm005_write_byte(usbpd_data->i2c, 0x10, &W_DATA[0], 2);
			pr_info("%s : alternate mode is reset as stop!\n",
				__func__);
			prev_alternate_mode = ALTERNATE_MODE_STOP;
		} else
			;
	} else {
		if (mode & ALTERNATE_MODE_NOT_READY) {
			check_is_driver_loaded = 0;
			pr_info("%s : alternate mode is not ready!\n", __func__);
		} else if (mode & ALTERNATE_MODE_READY) {
			check_is_driver_loaded = 1;
			pr_info("%s : alternate mode is ready!\n", __func__);
		} else
			;

		if (check_is_driver_loaded) {
			if (mode & ALTERNATE_MODE_START) {
				W_DATA[0] = 0x3;
				W_DATA[1] = 0x31;
				s2mm005_write_byte(usbpd_data->i2c, 0x10,
						   &W_DATA[0], 2);
				pr_info("%s : alternate mode is started!\n",
					__func__);
				prev_alternate_mode = ALTERNATE_MODE_START;
				set_enable_powernego(1);
			} else if (mode & ALTERNATE_MODE_STOP) {
				W_DATA[0] = 0x3;
				W_DATA[1] = 0x33;
				s2mm005_write_byte(usbpd_data->i2c, 0x10,
						   &W_DATA[0], 2);
				pr_info("%s : alternate mode is stopped!\n",
					__func__);
				prev_alternate_mode = ALTERNATE_MODE_STOP;
			}
		}
	}
}

void set_clear_discover_mode(void)
{
	struct s2mm005_data *usbpd_data;
	u8 W_DATA[2];

	if (!ccic_device)
		return;
	usbpd_data = dev_get_drvdata(ccic_device);
	if (!usbpd_data)
		return;

	W_DATA[0] = 0x3;
	W_DATA[1] = 0x32;

	s2mm005_write_byte(usbpd_data->i2c, 0x10, &W_DATA[0], 2);

	pr_info("%s : clear discover mode!\n", __func__);
}

void set_host_turn_on_event(int mode)
{
	struct s2mm005_data *usbpd_data;

	if (!ccic_device)
		return;
	usbpd_data = dev_get_drvdata(ccic_device);
	if (!usbpd_data)
		return;

	pr_info("%s : current_set is %d!\n", __func__, mode);
	if (mode) {
		usbpd_data->host_turn_on_event = 1;
		wake_up_interruptible(&usbpd_data->host_turn_on_wait_q);
	} else {
		usbpd_data->host_turn_on_event = 0;
	}
}

static int process_check_accessory(void *data)
{
	struct s2mm005_data *usbpd_data = data;
#if defined(CONFIG_USB_HW_PARAM)
	struct otg_notify *o_notify = get_otg_notify();
#endif
	uint16_t vid = usbpd_data->Vendor_ID;
	uint16_t pid = usbpd_data->Product_ID;
	uint16_t acc_type = CCIC_DOCK_DETACHED;

	/* detect Gear VR */
	if (usbpd_data->acc_type == CCIC_DOCK_DETACHED) {
		if (vid == SAMSUNG_VENDOR_ID) {
			switch (pid) {
			/* GearVR: Reserved GearVR PID+6 */
			case GEARVR_PRODUCT_ID:
			case GEARVR_PRODUCT_ID_1:
			case GEARVR_PRODUCT_ID_2:
			case GEARVR_PRODUCT_ID_3:
			case GEARVR_PRODUCT_ID_4:
			case GEARVR_PRODUCT_ID_5:
				acc_type = CCIC_DOCK_HMT;
				pr_info("%s : Samsung Gear VR connected.\n",
					__func__);
#if defined(CONFIG_USB_HW_PARAM)
				if (o_notify)
					inc_hw_param(o_notify,
						     USB_CCIC_VR_USE_COUNT);
#endif
				break;
			case DEXDOCK_PRODUCT_ID:
				acc_type = CCIC_DOCK_DEX;
				pr_info("%s : Samsung DEX connected.\n",
					__func__);
#if defined(CONFIG_USB_HW_PARAM)
				if (o_notify)
					inc_hw_param(o_notify,
						     USB_CCIC_DEX_USE_COUNT);
#endif
				break;
			case DEXPAD_PRODUCT_ID:
				acc_type = CCIC_DOCK_DEXPAD;
				pr_info("%s : Samsung DEX PADconnected.\n", __func__);
#if defined(CONFIG_USB_HOST_NOTIFY) && defined(CONFIG_USB_HW_PARAM)
				if (o_notify)
					inc_hw_param(o_notify, USB_CCIC_DEX_USE_COUNT);
#endif
				break;
			case HDMI_PRODUCT_ID:
				acc_type = CCIC_DOCK_HDMI;
				pr_info("%s : Samsung HDMI connected.\n",
					__func__);
				break;
			case UVDM_PROTOCOL_ID:
				acc_type = CCIC_DOCK_UVDM;
				pr_info("%s : Samsung UVDM device connected.\n",
					__func__);
			default:
				acc_type = CCIC_DOCK_NEW;
				pr_info("%s : default device connected.\n",
					__func__);
				break;
			}
		} else if (vid == SAMSUNG_MPA_VENDOR_ID) {
			switch (pid) {
			case MPA_PRODUCT_ID:
				acc_type = CCIC_DOCK_MPA;
				pr_info("%s : Samsung MPA connected.\n",
					__func__);
				break;
			default:
				acc_type = CCIC_DOCK_NEW;
				pr_info("%s : default device connected.\n",
					__func__);
				break;
			}
		}
		usbpd_data->acc_type = acc_type;
	} else
		acc_type = usbpd_data->acc_type;

	if (acc_type != CCIC_DOCK_NEW)
		ccic_send_dock_intent(acc_type);
	
	ccic_send_dock_uevent(vid, pid, acc_type);
	return 1;
}

static int process_discover_identity(void *data)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_RX_DIS_ID;
	uint8_t ReadMSG[32] = {0,};
	int ret = 0;

	/* Message Type Definition */
	U_DATA_MSG_ID_HEADER_Type *DATA_MSG_ID =
		(U_DATA_MSG_ID_HEADER_Type *)&ReadMSG[8];
	U_PRODUCT_VDO_Type *DATA_MSG_PRODUCT =
		(U_PRODUCT_VDO_Type *)&ReadMSG[16];

	ret = s2mm005_read_byte(i2c, REG_ADD, ReadMSG, 32);
	if (ret < 0) {
		dev_err(&i2c->dev, "%s has i2c error.\n", __func__);
		return ret;
	}

	usbpd_data->is_sent_pin_configuration = 0;
	usbpd_data->is_samsung_accessory_enter_mode = 0;
	usbpd_data->Vendor_ID = DATA_MSG_ID->BITS.USB_Vendor_ID;
	usbpd_data->Product_ID = DATA_MSG_PRODUCT->BITS.Product_ID;
	usbpd_data->Device_Version = DATA_MSG_PRODUCT->BITS.Device_Version;

	dev_info(&i2c->dev, "%s Vendor_ID : 0x%X, Product_ID : 0x%X Device Version 0x%X\n",
		 __func__, usbpd_data->Vendor_ID, usbpd_data->Product_ID,
		 usbpd_data->Device_Version);
	if (process_check_accessory(usbpd_data))
		dev_info(&i2c->dev, "%s : Samsung Accessory Connected.\n",
			 __func__);
	return 0;
}
#define MAX_INPUT_DATA (255)

static int process_discover_svids(void *data)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_RX_DIS_SVID;
	uint8_t ReadMSG[32] = {0,};
	int ret = 0;
	int timeleft = 0;
#if defined(CONFIG_USB_HOST_NOTIFY)
	struct otg_notify *o_notify = get_otg_notify();
#endif
	/* Message Type Definition */
	U_VDO1_Type  *DATA_MSG_VDO1 = (U_VDO1_Type *)&ReadMSG[8];

	ret = s2mm005_read_byte(i2c, REG_ADD, ReadMSG, 32);
	if (ret < 0) {
		dev_err(&i2c->dev, "%s has i2c error.\n", __func__);
		return ret;
	}

	usbpd_data->SVID_0 = DATA_MSG_VDO1->BITS.SVID_0;
	usbpd_data->SVID_1 = DATA_MSG_VDO1->BITS.SVID_1;

	if (usbpd_data->SVID_0 == TypeC_DP_SUPPORT) {
		if (usbpd_data->is_client == CLIENT_ON) {
			ccic_event_work(usbpd_data,
				CCIC_NOTIFY_DEV_MUIC,
				CCIC_NOTIFY_ID_ATTACH, 0, 0, 0);
#if defined(CONFIG_DUAL_ROLE_USB_INTF)
			usbpd_data->power_role = DUAL_ROLE_PROP_PR_NONE;
#endif
			ccic_event_work(usbpd_data,
				CCIC_NOTIFY_DEV_USB, CCIC_NOTIFY_ID_USB,
				0, USB_STATUS_NOTIFY_DETACH, 0);
			usbpd_data->is_client = CLIENT_OFF;
		}

		if (usbpd_data->is_host == HOST_OFF) {
			/* muic */
			ccic_event_work(usbpd_data,
				CCIC_NOTIFY_DEV_MUIC,
				CCIC_NOTIFY_ID_ATTACH, 1, 1, 0);
			/* otg */
			usbpd_data->is_host = HOST_ON_BY_RD;
#if defined(CONFIG_DUAL_ROLE_USB_INTF)
			if (usbpd_data->func_state & (0x1 << 25)) {
				usbpd_data->power_role = DUAL_ROLE_PROP_PR_SRC;
				/* add to turn on external 5V */
#if defined(CONFIG_USB_HOST_NOTIFY)
				if (!is_blocked(o_notify,
						NOTIFY_BLOCK_TYPE_HOST))
#endif
					vbus_turn_on_ctrl(1);
			} else {
				usbpd_data->power_role = DUAL_ROLE_PROP_PR_SNK;
			}
#endif
			ccic_event_work(usbpd_data,
				CCIC_NOTIFY_DEV_USB, CCIC_NOTIFY_ID_USB,
				1, USB_STATUS_NOTIFY_ATTACH_DFP, 0);
		}
		usbpd_data->dp_is_connect = 1;
		/*
		 * If you want to support USB SuperSpeed when you connect
		 * Display port dongle, You should change dp_hs_connect depend
		 * on Pin assignment.If DP use 4lane(Pin Assignment C,E,A),
		 * dp_hs_connect is 1. USB can support HS.If DP use 2lane(Pin Assigment B,D,F), dp_hs_connect is 0. USB
		 * can support SS
		 */
		 usbpd_data->dp_hs_connect = 1;

		ccic_event_work(usbpd_data,
				CCIC_NOTIFY_DEV_DP, CCIC_NOTIFY_ID_DP_CONNECT,
				CCIC_NOTIFY_ATTACH, usbpd_data->Vendor_ID,
				usbpd_data->Product_ID);
#if defined(CONFIG_USB_HW_PARAM)
		if (o_notify)
			inc_hw_param(o_notify, USB_CCIC_DP_USE_COUNT);
#endif
		timeleft = wait_event_interruptible_timeout(
				usbpd_data->host_turn_on_wait_q,
				usbpd_data->host_turn_on_event,
				(usbpd_data->host_turn_on_wait_time)*HZ);

		dev_info(&i2c->dev, "%s host turn on wait = %d\n",
			 __func__, timeleft);

		ccic_event_work(usbpd_data, CCIC_NOTIFY_DEV_USB_DP,
			CCIC_NOTIFY_ID_USB_DP, usbpd_data->dp_is_connect,
			usbpd_data->dp_hs_connect, 0);
	}

	dev_info(&i2c->dev, "%s SVID_0 : 0x%X, SVID_1 : 0x%X\n",
		__func__, usbpd_data->SVID_0, usbpd_data->SVID_1);
	return 0;
}

static int process_discover_modes(void *data)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_RX_MODE;
	uint8_t ReadMSG[32] = {0,};
	uint8_t W_DATA[3] = {0,};
	int ret = 0;
	DIS_MODE_DP_CAPA_Type *pDP_DIS_MODE =
		(DIS_MODE_DP_CAPA_Type *)&ReadMSG[0];
	U_DATA_MSG_VDM_HEADER_Type *DATA_MSG_VDM =
		(U_DATA_MSG_VDM_HEADER_Type *)&ReadMSG[4];

	ret = s2mm005_read_byte(i2c, REG_ADD, ReadMSG, 32);
	if (ret < 0) {
		dev_err(&i2c->dev, "%s has i2c error.\n", __func__);
		return ret;
	}

	dev_info(&i2c->dev, "%s : vendor_id = 0x%04x , svid_1 = 0x%04x\n",
		 __func__, DATA_MSG_VDM->BITS.Standard_Vendor_ID,
		 usbpd_data->SVID_1);
	if (DATA_MSG_VDM->BITS.Standard_Vendor_ID == TypeC_DP_SUPPORT && usbpd_data->SVID_0 == TypeC_DP_SUPPORT) {
		/* pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS. */
		dev_info(&i2c->dev, "pDP_DIS_MODE->MSG_HEADER.DATA = 0x%08X\n\r", pDP_DIS_MODE->MSG_HEADER.DATA);
		dev_info(&i2c->dev, "pDP_DIS_MODE->DATA_MSG_VDM_HEADER.DATA = 0x%08X\n\r", pDP_DIS_MODE->DATA_MSG_VDM_HEADER.DATA);
		dev_info(&i2c->dev, "pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.DATA = 0x%08X\n\r", pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.DATA);

		if (pDP_DIS_MODE->MSG_HEADER.BITS.Number_of_obj > 1) {
			if (((pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS.Port_Capability == num_UFP_D_Capable)
			     && (pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS.Receptacle_Indication == num_USB_TYPE_C_Receptacle))
			    || ((pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS.Port_Capability == num_DFP_D_Capable)
			       && (pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS.Receptacle_Indication == num_USB_TYPE_C_PLUG))) {
				usbpd_data->pin_assignment =
					pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS.UFP_D_Pin_Assignments;
				dev_info(&i2c->dev, "%s support UFP_D 0x%08x\n",
					 __func__, usbpd_data->pin_assignment);
			} else if (((pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS.Port_Capability == num_DFP_D_Capable)
				     && (pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS.Receptacle_Indication == num_USB_TYPE_C_Receptacle))
				   || ((pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS.Port_Capability == num_UFP_D_Capable)
					 && (pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS.Receptacle_Indication == num_USB_TYPE_C_PLUG))) {

				usbpd_data->pin_assignment = pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS.DFP_D_Pin_Assignments;
				dev_info(&i2c->dev, "%s support DFP_D 0x%08x\n",
					 __func__, usbpd_data->pin_assignment);
			} else if (pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS.Port_Capability == num_DFP_D_and_UFP_D_Capable) {
				if (pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS.Receptacle_Indication == num_USB_TYPE_C_PLUG) {
					usbpd_data->pin_assignment = pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS.DFP_D_Pin_Assignments;
					dev_info(&i2c->dev, "%s support DFP_D 0x%08x\n", __func__, usbpd_data->pin_assignment);
				} else {
					usbpd_data->pin_assignment = pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS.UFP_D_Pin_Assignments;
					dev_info(&i2c->dev, "%s support UFP_D 0x%08x\n", __func__, usbpd_data->pin_assignment);
				}
			} else {
				usbpd_data->pin_assignment = DP_PIN_ASSIGNMENT_NODE;
				dev_info(&i2c->dev, "%s there is not valid object information!!!\n", __func__);
			}
		}
	}

	if (DATA_MSG_VDM->BITS.Standard_Vendor_ID == SAMSUNG_VENDOR_ID) {
		dev_info(&i2c->dev, "%s : dex mode discover_mode ack status!\n",
			 __func__);
		/* pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.BITS.*/
		dev_info(&i2c->dev, "pDP_DIS_MODE->MSG_HEADER.DATA = 0x%08X\n\r", pDP_DIS_MODE->MSG_HEADER.DATA);
		dev_info(&i2c->dev, "pDP_DIS_MODE->DATA_MSG_VDM_HEADER.DATA = 0x%08X\n\r", pDP_DIS_MODE->DATA_MSG_VDM_HEADER.DATA);
		dev_info(&i2c->dev, "pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.DATA = 0x%08X\n\r", pDP_DIS_MODE->DATA_MSG_MODE_VDO_DP.DATA);

		REG_ADD = REG_I2C_SLV_CMD;
		W_DATA[0] = MODE_INTERFACE;	/* Mode Interface */
		W_DATA[1] = PD_NEXT_STATE;	/* Select mode as pd next state*/
		W_DATA[2] = 89;			/* PD next state*/
		ret = s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 3);
		if (ret < 0) {
			dev_err(&i2c->dev, "%s has i2c write error.\n",
				__func__);
			return ret;
		}
	}

	dev_info(&i2c->dev, "%s\n", __func__);
	set_clear_discover_mode();
	return 0;
}

static int process_enter_mode(void *data)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD;
	uint8_t ReadMSG[32] = {0,};
	int ret = 0;

	U_DATA_MSG_VDM_HEADER_Type *DATA_MSG_VDM =
		(U_DATA_MSG_VDM_HEADER_Type *)&ReadMSG[4];

	dev_info(&i2c->dev, "%s\n", __func__);

	REG_ADD = REG_RX_ENTER_MODE;
	/* Message Type Definition */
	DATA_MSG_VDM = (U_DATA_MSG_VDM_HEADER_Type *)&ReadMSG[4];
	ret = s2mm005_read_byte(i2c, REG_ADD, ReadMSG, 32);
	if (ret < 0) {
		dev_err(&i2c->dev, "%s has i2c read error.\n", __func__);
		return ret;
	}

	if (DATA_MSG_VDM->BITS.VDM_command_type == 1) {
		dev_info(&i2c->dev, "%s : EnterMode ACK.\n", __func__);
		if (DATA_MSG_VDM->BITS.Standard_Vendor_ID == SAMSUNG_VENDOR_ID) {
			usbpd_data->is_samsung_accessory_enter_mode = 1;
			dev_info(&i2c->dev, "%s : dex mode enter_mode ack status!\n", __func__);
		}
	} else
		dev_info(&i2c->dev, "%s : EnterMode NAK.\n", __func__);

	return 0;
}

static int process_attention(void *data)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_RX_DIS_ATTENTION;
	uint8_t ReadMSG[32] = {0,};
	uint8_t W_DATA[3] = {0,};
	int ret = 0;
	int i;
	int hpd = 0;
	int hpdirq = 0;
	int pin_assignment = 0;

	VDO_MESSAGE_Type *VDO_MSG;
	DIS_ATTENTION_MESSAGE_DP_STATUS_Type *DP_ATTENTION;
	u8 multi_func_preference = 0;

	pr_info("%s\n", __func__);
	ret = s2mm005_read_byte(i2c, REG_ADD, ReadMSG, 32);
	if (ret < 0) {
		dev_err(&i2c->dev, "%s has i2c error.\n", __func__);
		return ret;
	}

	if (usbpd_data->SVID_0 == TypeC_DP_SUPPORT) {
		DP_ATTENTION = (DIS_ATTENTION_MESSAGE_DP_STATUS_Type *)&ReadMSG[0];

		dev_info(&i2c->dev, "%s DP_ATTENTION = 0x%08X\n", __func__,
			 DP_ATTENTION->DATA_MSG_DP_STATUS.DATA);
		if (usbpd_data->is_sent_pin_configuration == 0) {
			/* 1. Pin Assignment */
			REG_ADD = 0x10;
			W_DATA[0] = MODE_INTERFACE;	/* Mode Interface */
			W_DATA[1] = DP_ALT_MODE_REQ;   /* DP Alternate Mode Request */
			W_DATA[2] = 0;	/* DP Pin Assign select */


			multi_func_preference =
				DP_ATTENTION->DATA_MSG_DP_STATUS.BITS.Multi_Function_Preference;
			if (multi_func_preference == 1) {
				if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_D) {
					W_DATA[2] = DP_PIN_ASSIGNMENT_D;
					pin_assignment = CCIC_NOTIFY_DP_PIN_D;
				} else if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_B) {
					W_DATA[2] = DP_PIN_ASSIGNMENT_B;
					pin_assignment = CCIC_NOTIFY_DP_PIN_B;
				} else if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_F) {
					W_DATA[2] = DP_PIN_ASSIGNMENT_F;
					pin_assignment = CCIC_NOTIFY_DP_PIN_F;
				} else {
					pin_assignment = CCIC_NOTIFY_DP_PIN_UNKNOWN;
					pr_info("wrong pin assignment value\n");
				}
			} else {
				if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_C) {
					W_DATA[2] = DP_PIN_ASSIGNMENT_C;
					pin_assignment = CCIC_NOTIFY_DP_PIN_C;
				} else if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_E) {
					W_DATA[2] = DP_PIN_ASSIGNMENT_E;
					pin_assignment = CCIC_NOTIFY_DP_PIN_E;
				} else if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_A) {
					W_DATA[2] = DP_PIN_ASSIGNMENT_A;
					pin_assignment = CCIC_NOTIFY_DP_PIN_A;
				} else if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_D) {
					W_DATA[2] = DP_PIN_ASSIGNMENT_D;
					pin_assignment = CCIC_NOTIFY_DP_PIN_D;
				} else if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_B) {
					W_DATA[2] = DP_PIN_ASSIGNMENT_B;
					pin_assignment = CCIC_NOTIFY_DP_PIN_B;
				} else if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_F) {
					W_DATA[2] = DP_PIN_ASSIGNMENT_F;
					pin_assignment = CCIC_NOTIFY_DP_PIN_F;
				} else {
					pin_assignment = CCIC_NOTIFY_DP_PIN_UNKNOWN;
					pr_info("wrong pin assignment value\n");
				}
			}
			usbpd_data->dp_selected_pin = pin_assignment;

			dev_info(&i2c->dev, "%s multi_func_preference %d  %s\n",
				 __func__, multi_func_preference,
				 DP_Pin_Assignment_Print[pin_assignment]);
			ret = s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 3);
			if (ret < 0) {
				dev_err(&i2c->dev, "%s has i2c write error.\n",
					__func__);
						return ret;
					}
		usbpd_data->is_sent_pin_configuration = 1;
		} else
			dev_info(&i2c->dev, "%s : pin configuration is already sent as %s!\n", __func__,
				DP_Pin_Assignment_Print[usbpd_data->dp_selected_pin]);

		if (DP_ATTENTION->DATA_MSG_DP_STATUS.BITS.HPD_State == 1)
			hpd = CCIC_NOTIFY_HIGH;
		else if (DP_ATTENTION->DATA_MSG_DP_STATUS.BITS.HPD_State == 0)
			hpd = CCIC_NOTIFY_LOW;
		if (DP_ATTENTION->DATA_MSG_DP_STATUS.BITS.HPD_Interrupt == 1)
			hpdirq = CCIC_NOTIFY_IRQ;

		ccic_event_work(usbpd_data,
			CCIC_NOTIFY_DEV_DP, CCIC_NOTIFY_ID_DP_HPD,
			hpd, hpdirq, 0);
	} else {
		VDO_MSG = (VDO_MESSAGE_Type *)&ReadMSG[8];

		for (i = 0; i < 6; i++)
			dev_info(&i2c->dev, "%s : VDO_%d : %d\n", __func__,
				 i+1, VDO_MSG->VDO[i]);
	}
	return 0;

}

static int process_dp_status_update(void *data)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_RX_DIS_DP_STATUS_UPDATE;
	uint8_t ReadMSG[32] = {0,};
	uint8_t W_DATA[3] = {0,};
	int ret = 0;
	int i;
	u8 multi_func_preference = 0;
	int pin_assignment = 0;
	int hpd = 0;
	int hpdirq = 0;
	VDO_MESSAGE_Type *VDO_MSG;
	DP_STATUS_UPDATE_Type *DP_STATUS;

	pr_info("%s\n", __func__);
	ret = s2mm005_read_byte(i2c, REG_ADD, ReadMSG, 32);
	if (ret < 0) {
		dev_err(&i2c->dev, "%s has i2c error.\n", __func__);
		return ret;
	}

	if (usbpd_data->SVID_0 == TypeC_DP_SUPPORT) {
		DP_STATUS = (DP_STATUS_UPDATE_Type *)&ReadMSG[0];

		dev_info(&i2c->dev, "%s DP_STATUS_UPDATE = 0x%08X\n", __func__,
			 DP_STATUS->DATA_DP_STATUS_UPDATE.DATA);

		if (DP_STATUS->DATA_DP_STATUS_UPDATE.BITS.Port_Connected == 0x00) {
			dev_info(&i2c->dev, "%s : port disconnected!\n",
				 __func__);
		} else {
			if (usbpd_data->is_sent_pin_configuration == 0) {
				/* 1. Pin Assignment */
				REG_ADD = 0x10;
				W_DATA[0] = MODE_INTERFACE;	/* Mode Interface */
				W_DATA[1] = DP_ALT_MODE_REQ;   /* DP Alternate Mode Request */
				W_DATA[2] = 0;	/* DP Pin Assign select */


				multi_func_preference =
					DP_STATUS->DATA_DP_STATUS_UPDATE.BITS.Multi_Function_Preference;
				if (multi_func_preference == 1) {
					if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_D) {
						W_DATA[2] = DP_PIN_ASSIGNMENT_D;
						pin_assignment = CCIC_NOTIFY_DP_PIN_D;
					} else if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_B) {
						W_DATA[2] = DP_PIN_ASSIGNMENT_B;
						pin_assignment = CCIC_NOTIFY_DP_PIN_B;
					} else if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_F) {
						W_DATA[2] = DP_PIN_ASSIGNMENT_F;
						pin_assignment = CCIC_NOTIFY_DP_PIN_F;
					} else {
						pr_info("wrong pin assignment value\n");
					}
				} else {
					if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_C) {
						W_DATA[2] = DP_PIN_ASSIGNMENT_C;
						pin_assignment = CCIC_NOTIFY_DP_PIN_C;
					} else if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_E) {
						W_DATA[2] = DP_PIN_ASSIGNMENT_E;
						pin_assignment = CCIC_NOTIFY_DP_PIN_E;
					} else if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_A) {
						W_DATA[2] = DP_PIN_ASSIGNMENT_A;
						pin_assignment = CCIC_NOTIFY_DP_PIN_A;
					} else if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_D) {
						W_DATA[2] = DP_PIN_ASSIGNMENT_D;
						pin_assignment = CCIC_NOTIFY_DP_PIN_D;
					} else if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_B) {
						W_DATA[2] = DP_PIN_ASSIGNMENT_B;
						pin_assignment = CCIC_NOTIFY_DP_PIN_B;
					} else if (usbpd_data->pin_assignment & DP_PIN_ASSIGNMENT_F) {
						W_DATA[2] = DP_PIN_ASSIGNMENT_F;
						pin_assignment = CCIC_NOTIFY_DP_PIN_F;
					} else {
						pr_info("wrong pin assignment value\n");
					}
				}
				usbpd_data->dp_selected_pin = pin_assignment;

				dev_info(&i2c->dev, "%s multi_func_preference %d  %s\n", __func__,
					 multi_func_preference, DP_Pin_Assignment_Print[pin_assignment]);
				ret = s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 3);
				if (ret < 0) {
					dev_err(&i2c->dev, "%s has i2c write error.\n",
						__func__);
					return ret;
				}
				usbpd_data->is_sent_pin_configuration = 1;
			} else {
				dev_info(&i2c->dev, "%s : pin configuration is already sent as %s!\n", __func__,
					 DP_Pin_Assignment_Print[usbpd_data->dp_selected_pin]);
			}
		}

		if (DP_STATUS->DATA_DP_STATUS_UPDATE.BITS.HPD_State == 1)
			hpd = CCIC_NOTIFY_HIGH;
		else if (DP_STATUS->DATA_DP_STATUS_UPDATE.BITS.HPD_State == 0)
			hpd = CCIC_NOTIFY_LOW;

		if (DP_STATUS->DATA_DP_STATUS_UPDATE.BITS.HPD_Interrupt == 1)
			hpdirq = CCIC_NOTIFY_IRQ;

		ccic_event_work(usbpd_data,
				CCIC_NOTIFY_DEV_DP, CCIC_NOTIFY_ID_DP_HPD,
				hpd, hpdirq, 0);
	} else {
		VDO_MSG = (VDO_MESSAGE_Type *)&ReadMSG[8];

		for (i = 0; i < 6; i++)
			dev_info(&i2c->dev, "%s : VDO_%d : %d\n", __func__,
				 i+1, VDO_MSG->VDO[i]);
	}
	return 0;
}

static int process_dp_configure(void *data)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_RX_DIS_DP_CONFIGURE;
	uint8_t ReadMSG[32] = {0,};
	uint8_t W_DATA[3] = {0,};
	int ret = 0;
	U_DATA_MSG_VDM_HEADER_Type *DATA_MSG_VDM = (U_DATA_MSG_VDM_HEADER_Type *)&ReadMSG[4];

	dev_info(&i2c->dev, "%s\n", __func__);

	ret = s2mm005_read_byte(i2c, REG_ADD, ReadMSG, 32);
	if (ret < 0) {
		dev_err(&i2c->dev, "%s has i2c error.\n", __func__);
		return ret;
	}

	dev_info(&i2c->dev, "%s : vendor_id = 0x%04x , svid_1 = 0x%04x\n",
		 __func__, DATA_MSG_VDM->BITS.Standard_Vendor_ID, usbpd_data->SVID_1);
	if (usbpd_data->SVID_0 == TypeC_DP_SUPPORT) {
		ccic_event_work(usbpd_data, CCIC_NOTIFY_DEV_DP,
			CCIC_NOTIFY_ID_DP_LINK_CONF,
			usbpd_data->dp_selected_pin, 0, 0);
	}
	if (DATA_MSG_VDM->BITS.Standard_Vendor_ID == TypeC_DP_SUPPORT &&
	     usbpd_data->SVID_1 == SAMSUNG_VENDOR_ID) {
		/* write s2mm005 with TypeC_Dex_SUPPORT SVID */
		/* It will start discover mode with that svid */
		dev_info(&i2c->dev, "%s : svid 1 is dex station\n", __func__);
		REG_ADD = REG_I2C_SLV_CMD;
		W_DATA[0] = MODE_INTERFACE;	/* Mode Interface */
		W_DATA[1] = SVID_SELECT;   /* SVID select*/
		W_DATA[2] = 1;	/* SVID select with Samsung vendor ID*/
		ret = s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 3);
		if (ret < 0) {
			dev_err(&i2c->dev, "%s has i2c write error.\n",
				__func__);
			return ret;
		}
	}

	return 0;
}

static void process_alternate_mode(void *data)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint32_t mode = usbpd_data->alternate_state;
	int	ret = 0;
#if defined(CONFIG_USB_HOST_NOTIFY)
	struct otg_notify *o_notify = get_otg_notify();
#endif
	if (mode) {
		dev_info(&i2c->dev, "%s, mode : 0x%x\n", __func__, mode);

#if defined(CONFIG_USB_HOST_NOTIFY)
		if (o_notify != NULL && is_blocked(o_notify, NOTIFY_BLOCK_TYPE_HOST)) {
			dev_info(&i2c->dev, "%s, host is blocked, skip all the alternate mode.\n", __func__);
			goto process_error;
		}
#endif
		if (mode & VDM_DISCOVER_ID)
			ret = process_discover_identity(usbpd_data);
		if (ret)
			goto process_error;
		if (mode & VDM_DISCOVER_SVIDS)
			ret = process_discover_svids(usbpd_data);
		if (ret)
			goto process_error;
		if (mode & VDM_DISCOVER_MODES)
			ret = process_discover_modes(usbpd_data);
		if (ret)
			goto process_error;
		if (mode & VDM_ENTER_MODE)
			ret = process_enter_mode(usbpd_data);
		if (ret)
			goto process_error;
		if (mode & VDM_DP_STATUS_UPDATE)
			ret = process_dp_status_update(usbpd_data);
		if (ret)
			goto process_error;
		if (mode & VDM_DP_CONFIGURE)
			ret = process_dp_configure(usbpd_data);
		if (ret)
			goto process_error;
		if (mode & VDM_ATTENTION)
			ret = process_attention(usbpd_data);
process_error:
		usbpd_data->alternate_state = 0;
	}
}

void send_alternate_message(void *data, int cmd)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_VDM_MSG_REQ;
	u8 mode = (u8)cmd;

	dev_info(&i2c->dev, "%s : %s\n", __func__,
		 &VDM_MSG_IRQ_State_Print[cmd][0]);
	s2mm005_write_byte(i2c, REG_ADD, &mode, 1);
}

void receive_alternate_message(void *data, VDM_MSG_IRQ_STATUS_Type *VDM_MSG_IRQ_State)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;

	if (VDM_MSG_IRQ_State->BITS.Vdm_Flag_Discover_ID) {
		dev_info(&i2c->dev, "%s : %s\n", __func__,
			 &VDM_MSG_IRQ_State_Print[1][0]);
		usbpd_data->alternate_state |= VDM_DISCOVER_ID;
	}
	if (VDM_MSG_IRQ_State->BITS.Vdm_Flag_Discover_SVIDs) {
		dev_info(&i2c->dev, "%s : %s\n", __func__,
			 &VDM_MSG_IRQ_State_Print[2][0]);
		usbpd_data->alternate_state |= VDM_DISCOVER_SVIDS;
	}
	if (VDM_MSG_IRQ_State->BITS.Vdm_Flag_Discover_MODEs) {
		dev_info(&i2c->dev, "%s : %s\n", __func__,
			 &VDM_MSG_IRQ_State_Print[3][0]);
		usbpd_data->alternate_state |= VDM_DISCOVER_MODES;
	}
	if (VDM_MSG_IRQ_State->BITS.Vdm_Flag_Enter_Mode) {
		dev_info(&i2c->dev, "%s : %s\n", __func__,
			 &VDM_MSG_IRQ_State_Print[4][0]);
		usbpd_data->alternate_state |= VDM_ENTER_MODE;
	}
	if (VDM_MSG_IRQ_State->BITS.Vdm_Flag_Exit_Mode) {
		dev_info(&i2c->dev, "%s : %s\n", __func__,
			 &VDM_MSG_IRQ_State_Print[5][0]);
		usbpd_data->alternate_state |= VDM_EXIT_MODE;
	}
	if (VDM_MSG_IRQ_State->BITS.Vdm_Flag_Attention) {
		dev_info(&i2c->dev, "%s : %s\n", __func__,
			 &VDM_MSG_IRQ_State_Print[6][0]);
		usbpd_data->alternate_state |= VDM_ATTENTION;
	}
	if (VDM_MSG_IRQ_State->BITS.Vdm_Flag_DP_Status_Update) {
		dev_info(&i2c->dev, "%s : %s\n", __func__,
			 &VDM_MSG_IRQ_State_Print[7][0]);
		usbpd_data->alternate_state |= VDM_DP_STATUS_UPDATE;
	}
	if (VDM_MSG_IRQ_State->BITS.Vdm_Flag_DP_Configure) {
		dev_info(&i2c->dev, "%s : %s\n", __func__,
			 &VDM_MSG_IRQ_State_Print[8][0]);
		usbpd_data->alternate_state |= VDM_DP_CONFIGURE;
	}

	process_alternate_mode(usbpd_data);
}

void set_endian(char *src, char *dest, int size)
{
	int i, j;
	int loop;
	int dest_pos;
	int src_pos;

	loop = size / SAMSUNGUVDM_ALIGN;
	loop += (((size % SAMSUNGUVDM_ALIGN) > 0) ? 1:0);

	for (i = 0 ; i < loop ; i++)
		for (j = 0 ; j < SAMSUNGUVDM_ALIGN ; j++) {
			src_pos = SAMSUNGUVDM_ALIGN * i + j;
			dest_pos = SAMSUNGUVDM_ALIGN * i + SAMSUNGUVDM_ALIGN - j - 1;
			dest[dest_pos] = src[src_pos];
		}
}

int get_checksum(char *data, int start_addr, int size)
{
	int checksum = 0;
	int i;

	for (i = 0; i < size; i++)
		checksum += data[start_addr+i];

	printk(" %s \n", __func__);
	return checksum;
}

int set_uvdmset_count(int size)
{
	int ret = 0;

	if (size <= SAMSUNGUVDM_MAXDATA_FIRST_UVDMSET)
		ret = 1;
	else {
		ret = ((size-SAMSUNGUVDM_MAXDATA_FIRST_UVDMSET) / SAMSUNGUVDM_MAXDATA_NORMAL_UVDMSET);
		if (((size-SAMSUNGUVDM_MAXDATA_FIRST_UVDMSET) % SAMSUNGUVDM_MAXDATA_NORMAL_UVDMSET) == 0)
			ret += 1;
		else
			ret += 2;
	}
	return ret;
}

void set_msghedader(void *data, int msg_type, int obj_num)
{
	MSG_HEADER_Type *MSG_HDR;
	uint8_t *SendMSG = (uint8_t *)data;

	MSG_HDR = (MSG_HEADER_Type *)&SendMSG[0];
	MSG_HDR->Message_Type = msg_type;
	MSG_HDR->Number_of_obj = obj_num;
	return;
}
int get_writesize(void *data)
{
	MSG_HEADER_Type *MSG_HDR;
	uint8_t *SendMSG = (uint8_t *)data;

	MSG_HDR = (MSG_HEADER_Type *)&SendMSG[0];
	return ((MSG_HDR->Number_of_obj)*4+4);
}

void set_uvdmheader(void *data, int vendor_id, int vdm_type)
{
	U_UNSTRUCTURED_VDM_HEADER_Type	*UVDM_HEADER;
	U_DATA_MSG_VDM_HEADER_Type *VDM_HEADER;
	uint8_t *SendMSG = (uint8_t *)data;

	UVDM_HEADER = (U_UNSTRUCTURED_VDM_HEADER_Type *)&SendMSG[4];
	UVDM_HEADER->BITS.USB_Vendor_ID = vendor_id;
	UVDM_HEADER->BITS.VDM_TYPE = vdm_type;
	UVDM_HEADER->BITS.VENDOR_DEFINED_MESSAGE = SEC_UVDM_UNSTRUCTURED_VDM;
	VDM_HEADER = (U_DATA_MSG_VDM_HEADER_Type *)&SendMSG[4];
	VDM_HEADER->BITS.VDM_command = 4; //s2mm005 only
	return;
}

void set_sec_uvdmheader(void *data, int pid, bool data_type, int cmd_type,
		bool dir, int total_uvdmset_num, uint8_t received_data)
{
	U_SEC_UVDM_HEADER *SEC_VDM_HEADER;
	uint8_t *SendMSG = (uint8_t *)data;

	SEC_VDM_HEADER = (U_SEC_UVDM_HEADER *)&SendMSG[8];
	SEC_VDM_HEADER->BITS.pid = pid;
	SEC_VDM_HEADER->BITS.data_type = data_type;
	SEC_VDM_HEADER->BITS.command_type = cmd_type;
	SEC_VDM_HEADER->BITS.direction = dir;
	if (dir == DIR_OUT)
		SEC_VDM_HEADER->BITS.total_number_of_uvdm_set = total_uvdmset_num;
	if (data_type == TYPE_SHORT)
		SEC_VDM_HEADER->BITS.data = received_data;

	pr_info("%s pid = %d  data_type=%d ,cmd_type =%d,direction= %d, total_num_of_uvdm_set = %d\n",
		 __func__, SEC_VDM_HEADER->BITS.pid,
		SEC_VDM_HEADER->BITS.data_type,
		SEC_VDM_HEADER->BITS.command_type,
		SEC_VDM_HEADER->BITS.direction,
		SEC_VDM_HEADER->BITS.total_number_of_uvdm_set);
	return;
}

int get_datasize_of_currentset (int first_set, int remained_data_size)
{
	int ret = 0;

	if (first_set)
		ret = (remained_data_size <= SAMSUNGUVDM_MAXDATA_FIRST_UVDMSET) ? \
			remained_data_size : SAMSUNGUVDM_MAXDATA_FIRST_UVDMSET;
	 else
		ret = (remained_data_size <= SAMSUNGUVDM_MAXDATA_NORMAL_UVDMSET) ? \
			remained_data_size : SAMSUNGUVDM_MAXDATA_NORMAL_UVDMSET;

	 return ret;
}

void set_sec_uvdm_txdataheader (void *data, int first_set, int cur_uvdmset,
		int total_data_size, int remained_data_size)
{
	U_SEC_TX_DATA_HEADER *SEC_TX_DATA_HEADER;
	uint8_t *SendMSG = (uint8_t *)data;

	if (first_set)
		SEC_TX_DATA_HEADER = (U_SEC_TX_DATA_HEADER *)&SendMSG[12];
	else
		SEC_TX_DATA_HEADER = (U_SEC_TX_DATA_HEADER *)&SendMSG[8];

	SEC_TX_DATA_HEADER->BITS.data_size_of_current_set =\
		get_datasize_of_currentset(first_set, remained_data_size);
	SEC_TX_DATA_HEADER->BITS.total_data_size = total_data_size;
	SEC_TX_DATA_HEADER->BITS.order_of_current_uvdm_set = cur_uvdmset;

	return;
}

void set_sec_uvdm_txdata_tailer(void *data)
{
	U_SEC_TX_DATA_TAILER *SEC_TX_DATA_TAILER;
	uint8_t *SendMSG = (uint8_t *)data;

	SEC_TX_DATA_TAILER = (U_SEC_TX_DATA_TAILER *)&SendMSG[28];
	SEC_TX_DATA_TAILER->BITS.checksum = get_checksum(SendMSG, S2MM005_SECUVDM_START_ADDR,\
			SAMSUNGUVDM_CHECKSUM_DATA_COUNT);
	return;
}

void set_sec_uvdm_rxdata_header(void *data, int cur_uvdmset_num, int cur_uvdmset_data, int ack)
{
	U_SEC_RX_DATA_HEADER *SEC_UVDM_RX_HEADER;
	uint8_t *SendMSG = (uint8_t *)data;

	SEC_UVDM_RX_HEADER = (U_SEC_RX_DATA_HEADER *)&SendMSG[8];
	SEC_UVDM_RX_HEADER->BITS.order_of_current_uvdm_set = cur_uvdmset_num;
	SEC_UVDM_RX_HEADER->BITS.received_data_size_of_current_set = cur_uvdmset_data;
	SEC_UVDM_RX_HEADER->BITS.result_value = ack;

}

ssize_t send_samsung_unstructured_long_uvdm_message(void *data, void *buf, size_t size)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_SSM_MSG_SEND;
	uint8_t SendMSG[32] = {0,};
	u8 W_DATA[2];
	uint8_t *SEC_DATA;

	/* Valuable to calc the uvdm set and each uvdm set's data size*/
	int need_uvdmset_count = 0;
	int cur_uvdmset_data = 0;
	int cur_uvdmset_num = 0;
	int accumulated_data_size = 0;
	int remained_data_size = 0;
	uint8_t received_data[MAX_INPUT_DATA] = {0,};
	int time_left;
	int i;
	int received_data_index;
	int write_size = 0;

	/* 1. Calc the receivced data size and determin the uvdm set count and last data of uvdm set. */
	set_endian(buf, received_data, size);

	need_uvdmset_count = set_uvdmset_count(size);
	dev_info(&i2c->dev, "%s need_uvdmset_count = %d \n", __func__, need_uvdmset_count);

	usbpd_data->is_in_first_sec_uvdm_req = true;
	usbpd_data->is_in_sec_uvdm_out = DIR_OUT;
	cur_uvdmset_num = 1;
	accumulated_data_size = 0;
	remained_data_size = size;
	received_data_index = 0;

	/* 2. Common : Fill the MSGHeader */
	set_msghedader(SendMSG, 15, 7);
	/* 3. Common : Fill the UVDMHeader*/
	set_uvdmheader(SendMSG, SAMSUNG_VENDOR_ID, 0);
	/* 4. Common : Fill the First SEC_VDMHeader*/
	if (usbpd_data->is_in_first_sec_uvdm_req)
		set_sec_uvdmheader(SendMSG, usbpd_data->Product_ID, TYPE_LONG,\
				SEC_UVDM_ININIATOR, DIR_OUT, need_uvdmset_count, 0);

	while (cur_uvdmset_num <= need_uvdmset_count) {
		cur_uvdmset_data = 0;
		time_left = 0;

		set_sec_uvdm_txdataheader(SendMSG, usbpd_data->is_in_first_sec_uvdm_req,\
				cur_uvdmset_num, size, remained_data_size);

		cur_uvdmset_data = get_datasize_of_currentset(usbpd_data->is_in_first_sec_uvdm_req, remained_data_size);

		dev_info(&i2c->dev, "%s data_size_of_current_set = %d ,total_data_size = %ld,\
			order_of_current_uvdm_set = %d\n", __func__, cur_uvdmset_data, size, cur_uvdmset_num);
		/* 6. Common : Fill the DATA */
		if (usbpd_data->is_in_first_sec_uvdm_req) {
			SEC_DATA = (uint8_t *)&SendMSG[S2MM005_SECUVDM_START_ADDR+8];
			for (i = 0; i < SAMSUNGUVDM_MAXDATA_FIRST_UVDMSET; i++)
				SEC_DATA[i] = received_data[received_data_index++];
		} else {
			SEC_DATA = (uint8_t *)&SendMSG[S2MM005_SECUVDM_START_ADDR+4];
			for (i = 0; i < SAMSUNGUVDM_MAXDATA_NORMAL_UVDMSET; i++)
				SEC_DATA[i] = received_data[received_data_index++];
		}

		/* 7. Common : Fill the TX_DATA_Tailer */
		set_sec_uvdm_txdata_tailer(SendMSG);

		/* 8. Send data to PDIC */
		REG_ADD = REG_SSM_MSG_SEND;
		write_size = get_writesize(SendMSG);
		s2mm005_write_byte(i2c, REG_ADD, SendMSG, write_size);
		REG_ADD = REG_I2C_SLV_CMD;
		W_DATA[0] = MODE_INTERFACE;
		W_DATA[1] = SEL_SSM_MSG_REQ;
		s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 2);

		/* 9. Wait Response*/
		reinit_completion(&usbpd_data->uvdm_out_wait);
		time_left =
			wait_for_completion_interruptible_timeout(&usbpd_data->uvdm_out_wait,
							  msecs_to_jiffies(SASMSUNGUVDM_WAIT_MS));
		if (time_left <= 0)
			return -ETIME;

		accumulated_data_size += cur_uvdmset_data;
		remained_data_size -= cur_uvdmset_data;
		if (usbpd_data->is_in_first_sec_uvdm_req)
			usbpd_data->is_in_first_sec_uvdm_req = false;
		cur_uvdmset_num++;
	}

	return size;
}

int check_is_wait_ack_accessroy(int vid, int pid, int svid)
{
	int should_wait = true;
	if (vid == SAMSUNG_VENDOR_ID && pid == DEXDOCK_PRODUCT_ID && svid == TypeC_DP_SUPPORT) {
		pr_info("%s : no need to wait ack response!\n", __func__);
		should_wait = false;
	}
	return should_wait;
}

int send_samsung_unstructured_short_vdm_message(void *data, void *buf, size_t size)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_SSM_MSG_SEND;
	uint8_t SendMSG[32] = {0,};
	u8 W_DATA[2];
	/* Message Type Definition */
	uint8_t received_data = 0;
	int time_left;

	if ((buf == NULL) || size <= 0) {
		dev_info(&i2c->dev, "%s given data is not valid !\n", __func__);
		return -EINVAL;
	}

	if (!usbpd_data->is_samsung_accessory_enter_mode) {
		dev_info(&i2c->dev, "%s - samsung_accessory mode is not ready!\n", __func__);
		return -ENXIO;
	}

	/* 1. Calc the receivced data size and determin the uvdm set count and last data of uvdm set. */
	received_data = *(char *)buf;
	/* 2. Common : Fill the MSGHeader */
	set_msghedader(SendMSG, 15, 2);
	/* 3. Common : Fill the UVDMHeader*/
	set_uvdmheader(SendMSG, SAMSUNG_VENDOR_ID, 0);
	/* 4. Common : Fill the First SEC_VDMHeader*/
	set_sec_uvdmheader(SendMSG, usbpd_data->Product_ID, TYPE_SHORT,\
				SEC_UVDM_ININIATOR, DIR_OUT, 1, received_data);
	usbpd_data->is_in_first_sec_uvdm_req = true;

	dev_info(&i2c->dev, "%s - process short data!\n", __func__);
	s2mm005_write_byte(i2c, REG_ADD, SendMSG, 32);

	/* send uVDM message */
	REG_ADD = REG_I2C_SLV_CMD;
	W_DATA[0] = MODE_INTERFACE;
	W_DATA[1] = SEL_SSM_MSG_REQ;
	s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 2);

	if (check_is_wait_ack_accessroy(usbpd_data->Vendor_ID, usbpd_data->Product_ID, usbpd_data->SVID_0)) {
		reinit_completion(&usbpd_data->uvdm_out_wait);
		/* Wait Response*/
		time_left =
			wait_for_completion_interruptible_timeout(&usbpd_data->uvdm_out_wait,
							  msecs_to_jiffies(SASMSUNGUVDM_WAIT_MS));
		if (time_left <= 0) {
			usbpd_data->is_in_first_sec_uvdm_req = false;
			return -ETIME;
		}
	}

	dev_info(&i2c->dev, "%s - exit : short data transfer complete!\n", __func__);
	usbpd_data->is_in_first_sec_uvdm_req = false;
	return size;
}

int send_samsung_unstructured_vdm_message(void *data, const char *buf, size_t size)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_SSM_MSG_SEND;
	uint8_t SendMSG[32] = {0,};
	u8 W_DATA[2];
	/* Message Type Definition */
	MSG_HEADER_Type *MSG_HDR;
	U_UNSTRUCTURED_VDM_HEADER_Type	*UVDM_HEADER;
	U_SEC_UNSTRUCTURED_VDM_HEADER_Type *SEND_SEC_VDM_HEADER;
	U_SEC_UNSTRUCTURED_VDM_HEADER_Type *RECEIVED_VDM_HEADER;
	int received_data;

	if ((buf == NULL) || (size < sizeof(U_SEC_UNSTRUCTURED_VDM_HEADER_Type))) {
		dev_info(&i2c->dev, "%s given data is not valid !\n", __func__);
		return -EINVAL;
	}

	if (!usbpd_data->is_samsung_accessory_enter_mode) {
		dev_info(&i2c->dev, "%s - samsung_accessory mode is not ready!\n", __func__);
		return -ENXIO;
	}
	sscanf(buf, "%d", &received_data);

	RECEIVED_VDM_HEADER = (U_SEC_UNSTRUCTURED_VDM_HEADER_Type *)&received_data;
	MSG_HDR = (MSG_HEADER_Type *)&SendMSG[0];
	UVDM_HEADER = (U_UNSTRUCTURED_VDM_HEADER_Type *)&SendMSG[4];
	SEND_SEC_VDM_HEADER = (U_SEC_UNSTRUCTURED_VDM_HEADER_Type *)&SendMSG[8];

	/* process common data */
	MSG_HDR->Message_Type = 15; /* send VDM message */
	UVDM_HEADER->BITS.USB_Vendor_ID = SAMSUNG_VENDOR_ID; /* VID */
	UVDM_HEADER->BITS.VENDOR_DEFINED_MESSAGE = SEC_UVDM_UNSTRUCTURED_VDM;

	*SEND_SEC_VDM_HEADER = *RECEIVED_VDM_HEADER;
	if (RECEIVED_VDM_HEADER->BITS.DATA_TYPE == SEC_UVDM_SHORT_DATA) {
		dev_info(&i2c->dev, "%s - process short data!\n", __func__);
		/* process short data */
		/* phase 1. fill message header */
		MSG_HDR->Number_of_obj = 2; /* VDM Header + 6 VDOs = MAX 7 */
		/* phase 2. fill uvdm header (already filled) */
		/* phase 3. fill sec uvdm header */
		SEND_SEC_VDM_HEADER->BITS.TOTAL_NUMBER_OF_UVDM_SET = 1;
	} else {
		dev_info(&i2c->dev, "%s - process long data!\n", __func__);
		/*
		* process long data
		* phase 1. fill message header
		* phase 2. fill uvdm header
		* phase 3. fill sec uvdm header
		* phase 4.5.6.7 fill sec data header , data , sec data tail and so on.
		*/
	}

	s2mm005_write_byte(i2c, REG_ADD, SendMSG, 32);

	/* send uVDM message */
	REG_ADD = REG_I2C_SLV_CMD;
	W_DATA[0] = MODE_INTERFACE;
	W_DATA[1] = SEL_SSM_MSG_REQ;
	s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 2);

	if (RECEIVED_VDM_HEADER->BITS.DATA_TYPE == SEC_UVDM_SHORT_DATA)
		dev_info(&i2c->dev, "%s - exit : short data transfer complete!\n", __func__);

	return 0;
}

void send_unstructured_vdm_message(void *data, int cmd)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_SSM_MSG_SEND;
	uint8_t SendMSG[32] = {0,};
	u8 W_DATA[2];
	uint32_t message = (uint32_t)cmd;
	int i;

	/* Message Type Definition */
	MSG_HEADER_Type *MSG_HDR = (MSG_HEADER_Type *)&SendMSG[0];
	U_UNSTRUCTURED_VDM_HEADER_Type	*DATA_MSG_UVDM = (U_UNSTRUCTURED_VDM_HEADER_Type *)&SendMSG[4];
	VDO_MESSAGE_Type *VDO_MSG = (VDO_MESSAGE_Type *)&SendMSG[8];

	/* fill message */
	MSG_HDR->Message_Type = 15; /* send VDM message */
	MSG_HDR->Number_of_obj = 7; /* VDM Header + 6 VDOs = MAX 7 */
	DATA_MSG_UVDM->BITS.USB_Vendor_ID = SAMSUNG_VENDOR_ID; /* VID */

	for (i = 0; i < 6; i++)
		VDO_MSG->VDO[i] = message; /* VD01~VDO6 : Max 24bytes */

	s2mm005_write_byte(i2c, REG_ADD, SendMSG, 32);

	/* send uVDM message */
	REG_ADD = REG_I2C_SLV_CMD;
	W_DATA[0] = MODE_INTERFACE;
	W_DATA[1] = SEL_SSM_MSG_REQ;
	s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 2);

	dev_info(&i2c->dev, "%s - message : 0x%x\n", __func__, message);
}

void receive_unstructured_vdm_message(void *data, SSM_MSG_IRQ_STATUS_Type *SSM_MSG_IRQ_State)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_SSM_MSG_READ;
	uint8_t ReadMSG[32] = {0,};
	u8 W_DATA[1];
	U_SEC_UVDM_RESPONSE_HEADER *SEC_UVDM_RESPONSE_HEADER;
	U_SEC_RX_DATA_HEADER *SEC_UVDM_RX_HEADER;

	if (usbpd_data->is_in_sec_uvdm_out == DIR_OUT) {
		s2mm005_read_byte(i2c, REG_ADD, ReadMSG, 16);
		/* first uvdm req for direction out */
		if (usbpd_data->is_in_first_sec_uvdm_req) {
			SEC_UVDM_RESPONSE_HEADER = (U_SEC_UVDM_RESPONSE_HEADER *)&ReadMSG[8];
			if (SEC_UVDM_RESPONSE_HEADER->BITS.data_type == TYPE_LONG) {
				if (SEC_UVDM_RESPONSE_HEADER->BITS.command_type == SEC_UVDM_RESPONDER_ACK) {
					SEC_UVDM_RX_HEADER = (U_SEC_RX_DATA_HEADER *)&ReadMSG[12];
					if (SEC_UVDM_RX_HEADER->BITS.result_value != SEC_UVDM_RESPONDER_ACK) {
						dev_err(&i2c->dev, "%s Busy or Nak received.\n", __func__);
					}
				} else {
					dev_err(&i2c->dev, "%s Response type is wrong.\n", __func__);
				}
			} else {
				if (SEC_UVDM_RESPONSE_HEADER->BITS.command_type == SEC_UVDM_RESPONDER_ACK)
					dev_info(&i2c->dev, "%s Short packet ack is received\n", __func__);
				else {
					dev_err(&i2c->dev, "%s Short packet Response type is wrong.\n", __func__);
				}
			}
		/* uvdm req for direction out */
		} else {
			SEC_UVDM_RX_HEADER = (U_SEC_RX_DATA_HEADER *)&ReadMSG[8];
			if (SEC_UVDM_RX_HEADER->BITS.result_value != SEC_UVDM_RESPONDER_ACK) {
					dev_err(&i2c->dev, "%s Busy or Nak received.\n", __func__);
			}
		}
		REG_ADD = REG_I2C_SLV_CMD;
		W_DATA[0] = MODE_INT_CLEAR;
		s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 1);
		complete(&usbpd_data->uvdm_out_wait);
	/* In uvdm req */
	} else {
		s2mm005_read_byte(i2c, REG_ADD, ReadMSG, 32);
		/* first uvdm req for direction in */
		if (usbpd_data->is_in_first_sec_uvdm_req) {
			SEC_UVDM_RESPONSE_HEADER = (U_SEC_UVDM_RESPONSE_HEADER *)&ReadMSG[8];
			dev_info(&i2c->dev, "[jj time]%s : data_type = %d , command_type = %d, direction=%d \n", __func__,
				SEC_UVDM_RESPONSE_HEADER->BITS.data_type,
				SEC_UVDM_RESPONSE_HEADER->BITS.command_type,
				SEC_UVDM_RESPONSE_HEADER->BITS.direction);
			/* for long data */
			if (SEC_UVDM_RESPONSE_HEADER->BITS.command_type != SEC_UVDM_RESPONDER_ACK) {
				dev_info(&i2c->dev, "%s :received nak or busy in response  \n", __func__);
				return;
			}
		}
		complete(&usbpd_data->uvdm_longpacket_in_wait);
	}
}

int samsung_uvdm_ready(void)
{
	int uvdm_ready = false;
	struct s2mm005_data *usbpd_data;

	usbpd_data = dev_get_drvdata(ccic_device);
	if (usbpd_data->is_samsung_accessory_enter_mode)
		uvdm_ready =  true;

	pr_info("%s : uvdm ready=%d!\n", __func__, uvdm_ready);
	return uvdm_ready;
}

void samsung_uvdm_close(void)
{
	struct s2mm005_data *usbpd_data;
	pr_info("%s + samsung_uvdm_close success\n", __func__);
	usbpd_data = dev_get_drvdata(ccic_device);
	complete(&usbpd_data->uvdm_out_wait);
	complete(&usbpd_data->uvdm_longpacket_in_wait);
	pr_info("%s - samsung_uvdm_close success\n", __func__);
}

ssize_t samsung_uvdm_out_request_message(void *data, size_t size)
{
	struct s2mm005_data *usbpd_data;
	struct i2c_client *i2c;
	ssize_t ret;
	if (!ccic_device)
		return -ENXIO;

	usbpd_data = dev_get_drvdata(ccic_device);
	if (!usbpd_data)
		return -ENXIO;

	i2c = usbpd_data->i2c;
	if (i2c == NULL) {
		dev_err(&i2c->dev, "%s usbpd_data->i2c is not valid!\n", __func__);
		return -EINVAL;
	}

	if (data == NULL) {
		dev_err(&i2c->dev, "%s given data is not valid !\n", __func__);
		return -EINVAL;
	}

	if (size >= SAMSUNGUVDM_MAX_LONGPACKET_SIZE) {
		dev_err(&i2c->dev, "%s : size %ld is too big to send data\n", __func__, size);
		ret = -EFBIG;
	} else if (size <= SAMSUNGUVDM_MAX_SHORTPACKET_SIZE)
		ret = send_samsung_unstructured_short_vdm_message(usbpd_data, data, size);
	else
		ret = send_samsung_unstructured_long_uvdm_message(usbpd_data, data, size);

	return ret;
}

int samsung_uvdm_in_request_message(void *data)
{
	struct s2mm005_data *usbpd_data;
	struct i2c_client *i2c;
	uint16_t REG_ADD = REG_SSM_MSG_SEND;
	uint8_t SendMSG[32] = {0,};
	uint8_t ReadMSG[32] = {0,};
	u8 W_DATA[2];
	uint8_t IN_DATA[MAX_INPUT_DATA] = {0, };

	/* Send Request */
	/* 1  Message Type Definition */
	U_SEC_UVDM_RESPONSE_HEADER	*SEC_RES_HEADER;
	U_SEC_TX_DATA_HEADER		*SEC_UVDM_TX_HEADER;
	U_SEC_TX_DATA_TAILER		*SEC_UVDM_TX_TAILER;

	int cur_uvdmset_data = 0;
	int cur_uvdmset_num = 0;
	int total_uvdmset_num = 0;
	int received_data_size = 0;
	int total_received_data_size = 0;
	int ack = 0;
	int size = 0;
	int time_left = 0;
	int i;
	int write_size = 0;
	int cal_checksum = 0;

	if (!ccic_device)
		return -ENXIO;

	usbpd_data = dev_get_drvdata(ccic_device);
	if (!usbpd_data)
		return -ENXIO;

	i2c = usbpd_data->i2c;
	if (i2c == NULL) {
		dev_err(&i2c->dev, "%s usbpd_data->i2c is not valid!\n", __func__);
		return -EINVAL;
	}

	dev_info(&i2c->dev, "%s\n", __func__);
	usbpd_data->is_in_sec_uvdm_out = DIR_IN;
	usbpd_data->is_in_first_sec_uvdm_req = true;

	/* 2. Common : Fill the MSGHeader */
	set_msghedader(SendMSG, 15, 2);
	/* 3. Common : Fill the UVDMHeader*/
	set_uvdmheader(SendMSG, SAMSUNG_VENDOR_ID, 0);

	/* 4. Common : Fill the First SEC_VDMHeader*/
	if (usbpd_data->is_in_first_sec_uvdm_req)
		set_sec_uvdmheader(SendMSG, usbpd_data->Product_ID, TYPE_LONG,\
				SEC_UVDM_ININIATOR, DIR_IN, 0, 0);

	/* 5. Send data to PDIC */
	write_size = get_writesize(SendMSG);
	s2mm005_write_byte(usbpd_data->i2c, REG_ADD, SendMSG, write_size);

	REG_ADD = REG_I2C_SLV_CMD;
	W_DATA[0] = MODE_INTERFACE;
	W_DATA[1] = SEL_SSM_MSG_REQ;
	s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 2);

	cur_uvdmset_num = 0;
	total_uvdmset_num = 1;

	do {
		reinit_completion(&usbpd_data->uvdm_longpacket_in_wait);
		time_left =
			wait_for_completion_interruptible_timeout(&usbpd_data->uvdm_longpacket_in_wait,
					msecs_to_jiffies(SASMSUNGUVDM_WAIT_MS));
		if (time_left <= 0) {
			dev_err(&i2c->dev, "%s timeout\n", __func__);
			return -ETIME;
		}

		/* read data */
		REG_ADD = REG_SSM_MSG_READ;
		s2mm005_read_byte(i2c, REG_ADD, ReadMSG, 32);

		if (usbpd_data->is_in_first_sec_uvdm_req) {
			SEC_RES_HEADER = (U_SEC_UVDM_RESPONSE_HEADER *)&ReadMSG[8];
			SEC_UVDM_TX_HEADER = (U_SEC_TX_DATA_HEADER *)&ReadMSG[12];

			if (SEC_RES_HEADER->BITS.data_type == TYPE_SHORT) {
				IN_DATA[received_data_size++] = SEC_RES_HEADER->BITS.data;
				return received_data_size;
			} else {
				/* 1. check the data size received */
				size = SEC_UVDM_TX_HEADER->BITS.total_data_size;
				cur_uvdmset_data = SEC_UVDM_TX_HEADER->BITS.data_size_of_current_set;
				cur_uvdmset_num = SEC_UVDM_TX_HEADER->BITS.order_of_current_uvdm_set;
				total_uvdmset_num =
					SEC_RES_HEADER->BITS.total_number_of_uvdm_set;

				usbpd_data->is_in_first_sec_uvdm_req = false;
				/* 2. copy data to buffer */
				for (i = 0; i < SAMSUNGUVDM_MAXDATA_FIRST_UVDMSET; i++)
					IN_DATA[received_data_size++] = ReadMSG[16+i];

				total_received_data_size += cur_uvdmset_data;
				usbpd_data->is_in_first_sec_uvdm_req = false;
			}
		} else {
			SEC_UVDM_TX_HEADER = (U_SEC_TX_DATA_HEADER *)&ReadMSG[8];
			cur_uvdmset_data = SEC_UVDM_TX_HEADER->BITS.data_size_of_current_set;
			cur_uvdmset_num = SEC_UVDM_TX_HEADER->BITS.order_of_current_uvdm_set;
			/* 2. copy data to buffer */
			for (i = 0 ; i < SAMSUNGUVDM_MAXDATA_NORMAL_UVDMSET ; i++)
				IN_DATA[received_data_size++] = ReadMSG[12+i];
			total_received_data_size += cur_uvdmset_data;
		}
		/* 3. Check Checksum */
		SEC_UVDM_TX_TAILER = (U_SEC_TX_DATA_TAILER *)&ReadMSG[28];
		cal_checksum = get_checksum(ReadMSG, 8, SAMSUNGUVDM_CHECKSUM_DATA_COUNT);
		ack = (cal_checksum == SEC_UVDM_TX_TAILER->BITS.checksum) ?
			SEC_UVDM_RX_HEADER_ACK : SEC_UVDM_RX_HEADER_NAK;

		///* 4. clear IRQ */
	REG_ADD = REG_I2C_SLV_CMD;
	W_DATA[0] = MODE_INT_CLEAR;
	s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 1);
		/* 5. Send Ack */
		/* 5-1. Common : Fill the MSGHeader */
		set_msghedader(SendMSG, 15, 2);
		/* 5-2. Common : Fill the UVDMHeader*/
		set_uvdmheader(SendMSG, SAMSUNG_VENDOR_ID, 0);
		/* 5-3. Common : Fill the SEC RXHeader */
		set_sec_uvdm_rxdata_header(SendMSG, cur_uvdmset_num, cur_uvdmset_data, ack);
		/* 5-4. Send data to PDIC */
		REG_ADD = REG_SSM_MSG_SEND;
		write_size = get_writesize(SendMSG);
		s2mm005_write_byte(usbpd_data->i2c, REG_ADD, SendMSG, write_size);
		/* send uVDM message */
		REG_ADD = REG_I2C_SLV_CMD;
		W_DATA[0] = MODE_INTERFACE;
		W_DATA[1] = SEL_SSM_MSG_REQ;
		s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 2);

	} while (cur_uvdmset_num < total_uvdmset_num);

	set_endian(IN_DATA, data, size);

	return size;
}

void send_dna_audio_unstructured_vdm_message(void *data, int cmd)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_SSM_MSG_SEND;
	uint8_t SendMSG[32] = {0,};
	u8 W_DATA[2];
	uint32_t message = (uint32_t)cmd;

	/* Message Type Definition */
	MSG_HEADER_Type *MSG_HDR = (MSG_HEADER_Type *)&SendMSG[0];
	U_UNSTRUCTURED_VDM_HEADER_Type	*DATA_MSG_UVDM = (U_UNSTRUCTURED_VDM_HEADER_Type *)&SendMSG[4];
	VDO_MESSAGE_Type *VDO_MSG = (VDO_MESSAGE_Type *)&SendMSG[8];

	/* fill message */
	MSG_HDR->Message_Type = 15; /* send VDM message */
	MSG_HDR->Number_of_obj = 7; /* VDM Header + 6 VDOs = MAX 7 */

	DATA_MSG_UVDM->BITS.USB_Vendor_ID = SAMSUNG_VENDOR_ID; /* VID */

	VDO_MSG->VDO[0] = message;

	s2mm005_write_byte(i2c, REG_ADD, SendMSG, 32);

	/* send uVDM message */
	REG_ADD = REG_I2C_SLV_CMD;
	W_DATA[0] = MODE_INTERFACE;
	W_DATA[1] = SEL_SSM_MSG_REQ;
	s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 2);

	dev_info(&i2c->dev, "%s - message : 0x%x\n", __func__, message);
}

void send_dex_fan_unstructured_vdm_message(void *data, int cmd)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_SSM_MSG_SEND;
	uint8_t SendMSG[32] = {0,};
	u8 W_DATA[2];
	uint32_t message = (uint32_t)cmd;

	/* Message Type Definitio */
	MSG_HEADER_Type *MSG_HDR = (MSG_HEADER_Type *)&SendMSG[0];
	U_UNSTRUCTURED_VDM_HEADER_Type	*DATA_MSG_UVDM = (U_UNSTRUCTURED_VDM_HEADER_Type *)&SendMSG[4];
	VDO_MESSAGE_Type *VDO_MSG = (VDO_MESSAGE_Type *)&SendMSG[8];

	/* fill message */
	MSG_HDR->Message_Type = 15; /* send VDM message */
	MSG_HDR->Number_of_obj = 2; /* VDM Header + 6 VDOs = MAX 7 */

	DATA_MSG_UVDM->BITS.USB_Vendor_ID = SAMSUNG_VENDOR_ID; /* VID */
	DATA_MSG_UVDM->BITS.VENDOR_DEFINED_MESSAGE = 1;

	VDO_MSG->VDO[0] = message;

	s2mm005_write_byte(i2c, REG_ADD, SendMSG, 32);

	/* send uVDM message */
	REG_ADD = REG_I2C_SLV_CMD;
	W_DATA[0] = MODE_INTERFACE;
	W_DATA[1] = SEL_SSM_MSG_REQ;
	s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 2);

	dev_info(&i2c->dev, "%s - message : 0x%x\n", __func__, message);
}

/*
* send_role_swap_message
* cmd 0 : PR_SWAP, cmd 1 : DR_SWAP
*/
void send_role_swap_message(void *data, int cmd)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_I2C_SLV_CMD;
	u8 mode = (u8)cmd;
	u8 W_DATA[2];

	/* send uVDM message */
	REG_ADD = REG_I2C_SLV_CMD;
	W_DATA[0] = MODE_INTERFACE;
	W_DATA[1] = mode ? REQ_DR_SWAP : REQ_PR_SWAP;
	s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 2);

	dev_info(&i2c->dev, "%s : sent %s message\n", __func__, mode ? "DR_SWAP" : "PR_SWAP");
}

void send_attention_message(void *data, int cmd)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = REG_TX_DIS_ATTENTION_RESPONSE;
	uint8_t SendMSG[32] = {0,};
	u8 W_DATA[3];
	uint32_t message = (uint32_t)cmd;
	int i;

	/* Message Type Definition */
	MSG_HEADER_Type *MSG_HDR = (MSG_HEADER_Type *)&SendMSG[0];
	U_DATA_MSG_VDM_HEADER_Type	  *DATA_MSG_VDM = (U_DATA_MSG_VDM_HEADER_Type *)&SendMSG[4];
	VDO_MESSAGE_Type *VDO_MSG = (VDO_MESSAGE_Type *)&SendMSG[8];

	/* fill message */
	DATA_MSG_VDM->BITS.VDM_command = 6;	/* attention*/
	DATA_MSG_VDM->BITS.VDM_Type = 1;	/* structured VDM */
	DATA_MSG_VDM->BITS.Standard_Vendor_ID = SAMSUNG_VENDOR_ID;

	MSG_HDR->Message_Type = 15;		/* send VDM message */
	MSG_HDR->Number_of_obj = 7;		/* VDM Header + 6 VDOs = MAX 7 */

	for (i = 0; i < 6; i++)
		VDO_MSG->VDO[i] = message;	/* VD01~VDO6 : Max 24bytes */

	s2mm005_write_byte(i2c, REG_ADD, SendMSG, 32);

	REG_ADD = REG_I2C_SLV_CMD;
	W_DATA[0] = MODE_INTERFACE;
	W_DATA[1] = PD_NEXT_STATE;
	W_DATA[2] = 100;
	s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 3);

	dev_info(&i2c->dev, "%s - message : 0x%x\n", __func__, message);
}

void do_alternate_mode_step_by_step(void *data, int cmd)
{
	struct s2mm005_data *usbpd_data = data;
	struct i2c_client *i2c = usbpd_data->i2c;
	uint16_t REG_ADD = 0;
	u8 W_DATA[3];

	REG_ADD = REG_I2C_SLV_CMD;
	W_DATA[0] = MODE_INTERFACE;
	W_DATA[1] = PD_NEXT_STATE;
	switch (cmd) {
	case VDM_DISCOVER_ID:
		W_DATA[2] = 80;
		break;
	case VDM_DISCOVER_SVIDS:
		W_DATA[2] = 83;
		break;
	case VDM_DISCOVER_MODES:
		W_DATA[2] = 86;
		break;
	case VDM_ENTER_MODE:
		W_DATA[2] = 89;
		break;
	case VDM_EXIT_MODE:
		W_DATA[2] = 92;
		break;
	}
	s2mm005_write_byte(i2c, REG_ADD, &W_DATA[0], 3);

	dev_info(&i2c->dev, "%s\n", __func__);
}
#endif
