/*
 * muic_manager.c
 *
 * Copyright (C) 2020 Samsung Electronics
 * Thomas Ryu <smilesr.ryu@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
 *
 */
#define pr_fmt(fmt)	"[MUIC] " fmt

#include <linux/gpio.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
#include <linux/platform_device.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/host_notify.h>
#include <linux/string.h>
#if defined(CONFIG_OF)
#include <linux/of_device.h>
#include <linux/of_gpio.h>
#endif

#include <linux/muic/muic.h>
#if defined(CONFIG_IFCONN_NOTIFIER)
#include <linux/ifconn/ifconn_notifier.h>
#endif
#if defined(CONFIG_MUIC_NOTIFIER)
#include <linux/muic/muic_notifier.h>
#endif
#include <linux/muic/muic_interface.h>

#if defined(CONFIG_CCIC_NOTIFIER)
#include <linux/usb/typec/pdic_notifier.h>
#endif

#if defined(CONFIG_USB_TYPEC_MANAGER_NOTIFIER)
#include <linux/usb/typec/usb_typec_manager_notifier.h>
#endif
#if defined(CONFIG_BATTERY_SAMSUNG_V2)
#include "../battery_v2/include/sec_charging_common.h"
#elif defined(CONFIG_BATTERY_SAMSUNG_LEGO_STYLE)
#include "../battery/common/include/sec_charging_common.h"
#else
#include <linux/battery/sec_charging_common.h>
#endif

#define MUIC_CCIC_NOTI_ATTACH (1)
#define MUIC_CCIC_NOTI_DETACH (-1)
#define MUIC_CCIC_NOTI_UNDEFINED (0)

static struct ccic_rid_desc_t ccic_rid_tbl[] = {
	[CCIC_RID_UNDEFINED] = {"UNDEFINED", ATTACHED_DEV_NONE_MUIC},
	[CCIC_RID_000K] = {"000K", ATTACHED_DEV_OTG_MUIC},
	[CCIC_RID_001K] = {"001K", ATTACHED_DEV_MHL_MUIC},
	[CCIC_RID_255K] = {"255K", ATTACHED_DEV_JIG_USB_OFF_MUIC},
	[CCIC_RID_301K] = {"301K", ATTACHED_DEV_JIG_USB_ON_MUIC},
	[CCIC_RID_523K] = {"523K", ATTACHED_DEV_JIG_UART_OFF_MUIC},
	[CCIC_RID_619K] = {"619K", ATTACHED_DEV_JIG_UART_ON_MUIC},
	[CCIC_RID_OPEN] = {"OPEN", ATTACHED_DEV_NONE_MUIC},
};

static void _muic_manager_switch_uart_path(struct muic_interface_t *muic_if, int path)
{
	if (muic_if->pdata->gpio_uart_sel)
		muic_if->set_gpio_uart_sel(muic_if->muic_data, path);

	if (muic_if->set_switch_to_uart)
		muic_if->set_switch_to_uart(muic_if->muic_data);
	else
		pr_err("%s:function not set!\n", __func__);
}

static void _muic_manager_switch_usb_path(struct muic_interface_t *muic_if, int path)
{
	if (muic_if->pdata->gpio_usb_sel)
		muic_if->set_gpio_usb_sel(muic_if->muic_data, path);

	if (muic_if->set_switch_to_usb)
		muic_if->set_switch_to_usb(muic_if->muic_data);
	else
		pr_err("%s:function not set!\n", __func__);
}

static int muic_manager_switch_path(struct muic_interface_t *muic_if, int path)
{
	switch (path) {
	case MUIC_PATH_OPEN:
		if (muic_if->set_com_to_open)
			muic_if->set_com_to_open(muic_if->muic_data);
		break;

	case MUIC_PATH_USB_AP:
	case MUIC_PATH_USB_CP:
		_muic_manager_switch_usb_path(muic_if, muic_if->pdata->usb_path);
		break;
	case MUIC_PATH_UART_AP:
	case MUIC_PATH_UART_CP:
		_muic_manager_switch_uart_path(muic_if, muic_if->pdata->uart_path);
		break;

	default:
		pr_err("%s:A wrong com path!\n", __func__);
		return -1;
	}

	return 0;
}

static int muic_manager_get_vbus(struct muic_interface_t *muic_if)
{
	int ret = 0;

	if (muic_if->get_vbus)
		ret = muic_if->get_vbus(muic_if->muic_data);

	return ret;
}

static bool muic_manager_is_supported_dev(int attached_dev)
{
	switch (attached_dev) {
	case ATTACHED_DEV_USB_MUIC:
	case ATTACHED_DEV_CDP_MUIC:
	case ATTACHED_DEV_TA_MUIC:
	case ATTACHED_DEV_JIG_UART_OFF_MUIC:
	case ATTACHED_DEV_JIG_UART_OFF_VB_MUIC:
	case ATTACHED_DEV_JIG_UART_ON_MUIC:
	case ATTACHED_DEV_JIG_UART_ON_VB_MUIC:
	case ATTACHED_DEV_JIG_USB_OFF_MUIC:
	case ATTACHED_DEV_JIG_USB_ON_MUIC:
	case ATTACHED_DEV_OTG_MUIC:
	case ATTACHED_DEV_AFC_CHARGER_5V_MUIC:
	case ATTACHED_DEV_AFC_CHARGER_9V_MUIC:
	case ATTACHED_DEV_AFC_CHARGER_DISABLED_MUIC:
	case ATTACHED_DEV_QC_CHARGER_5V_MUIC:
	case ATTACHED_DEV_QC_CHARGER_9V_MUIC:
		return true;
	default:
		break;
	}

	return false;
}

int muic_manager_is_ccic_supported_dev(muic_attached_dev_t new_dev)
{
	switch (new_dev) {
	/* Legacy TA/USB. Noti. will be sent when ATTACH is received from CCIC. */
	case ATTACHED_DEV_USB_MUIC:
	case ATTACHED_DEV_CDP_MUIC:
	case ATTACHED_DEV_TA_MUIC:
	case ATTACHED_DEV_TIMEOUT_OPEN_MUIC:
		return 1;
	default:
		break;
	}

	return 0;
}

void muic_manager_handle_ccic_detach_always(struct muic_interface_t *muic_if)
{
#if defined(CONFIG_MUIC_SUPPORT_PRSWAP)
	if (muic_if->set_chg_det)
		muic_if->set_chg_det(muic_if->muic_data, true);
#endif
#if defined(CONFIG_HV_MUIC_S2MU004_AFC) || defined(CONFIG_MUIC_HV)
	muic_if->is_afc_pdic_ready = false;
#endif
	muic_if->is_ccic_attached = false;
}

void muic_manager_handle_ccic_detach(struct muic_interface_t *muic_if)
{
	struct ccic_desc_t *ccic = muic_if->ccic;
	struct muic_platform_data *pdata = muic_if->pdata;
	int vbus = muic_manager_get_vbus(muic_if);

	pr_info("%s\n", __func__);

	if (ccic->ccic_evt_rprd) {
		/* FIXME : pvendor
		* if (pvendor && pvendor->enable_chgdet)
		* pvendor->enable_chgdet(muic_if->regmaccic, 1);
		*/
	}

	if (vbus == false) {
		if (muic_if->set_cable_state)
			muic_if->set_cable_state(muic_if->muic_data, ATTACHED_DEV_NONE_MUIC);

		muic_manager_switch_path(muic_if, MUIC_PATH_OPEN);
		if (muic_manager_is_supported_dev(ccic->attached_dev)) {
			MUIC_SEND_NOTI_DETACH(ccic->attached_dev);
		} else if (muic_if->legacy_dev != ATTACHED_DEV_NONE_MUIC) {
#ifdef CONFIG_SEC_FACTORY
			mdelay(150);
#endif
			MUIC_SEND_NOTI_DETACH(muic_if->legacy_dev);
		}
	}

	if (pdata->jig_uart_cb)
		pdata->jig_uart_cb(0);

	/* Reset status & flags */
	ccic->attached_dev = 0;
	ccic->ccic_evt_rid = 0;
	ccic->ccic_evt_rprd = 0;
	ccic->ccic_evt_roleswap = 0;
#ifndef CONFIG_MUIC_SKIP_INCOMPLETE_INSERT
	ccic->ccic_evt_dcdcnt = 0;
#endif
	ccic->ccic_evt_attached = MUIC_CCIC_NOTI_UNDEFINED;

	muic_if->legacy_dev = 0;
	muic_if->attached_dev = 0;
	muic_if->is_dcdtmr_intr = false;
#if defined(CONFIG_MUIC_SUPPORT_PRSWAP)
	muic_if->prswap_status = MUIC_PRSWAP_UNDIFINED;
#endif
}

#ifndef CONFIG_SEC_FACTORY
void muic_manager_handle_ccic_rid_open(struct muic_interface_t *muic_if)
{
	struct ccic_desc_t *ccic = muic_if->ccic;
	struct muic_platform_data *pdata = muic_if->pdata;

	pr_info("%s\n", __func__);

	if (muic_if->set_cable_state)
		muic_if->set_cable_state(muic_if->muic_data, ATTACHED_DEV_NONE_MUIC);

	muic_manager_switch_path(muic_if, MUIC_PATH_OPEN);
	if (muic_manager_is_supported_dev(ccic->attached_dev))
		MUIC_SEND_NOTI_DETACH(ccic->attached_dev);
	else if (muic_if->legacy_dev != ATTACHED_DEV_NONE_MUIC)
		MUIC_SEND_NOTI_DETACH(muic_if->legacy_dev);

	if (pdata->jig_uart_cb)
		pdata->jig_uart_cb(0);

	muic_if->legacy_dev = 0;
	muic_if->attached_dev = 0;
#ifndef CONFIG_MUIC_SKIP_INCOMPLETE_INSERT
	muic_if->is_dcdtmr_intr = false;
#endif
}
#endif

void muic_manager_set_legacy_dev(struct muic_interface_t *muic_if, int new_dev)
{
	pr_info("%s: %d->%d\n", __func__, muic_if->legacy_dev, new_dev);

	muic_if->legacy_dev = new_dev;
}

/* Get the charger type from muic interrupt or by reading the register directly */
int muic_manager_get_legacy_dev(struct muic_interface_t *muic_if)
{
	return muic_if->legacy_dev;
}

#if defined(CONFIG_CCIC_NOTIFIER)
static void muic_manager_show_status(struct muic_interface_t *muic_if)
{
	struct ccic_desc_t *ccic = muic_if->ccic;

	pr_info("%s: attached_dev:%d rid:%d rprd:%d attached:%d legacy_dev:%d\n", __func__,
			ccic->attached_dev, ccic->ccic_evt_rid, ccic->ccic_evt_rprd,
			ccic->ccic_evt_attached, muic_if->legacy_dev);
}
#endif
#ifndef CONFIG_MUIC_SKIP_INCOMPLETE_INSERT
int muic_manager_dcd_rescan(struct muic_interface_t *muic_if)
{
	struct ccic_desc_t *ccic = muic_if->ccic;
	int vbus = muic_manager_get_vbus(muic_if);

	pr_info("%s : ccic_evt_attached(%d), is_dcdtmr_intr(%d), ccic_evt_dcdcnt(%d)\n",
			__func__, ccic->ccic_evt_attached, muic_if->is_dcdtmr_intr, ccic->ccic_evt_dcdcnt);

	if (!(muic_if->opmode & OPMODE_CCIC)) {
		pr_info("%s : it's SMD board, skip rescan", __func__);
		goto SKIP_RESCAN;
	}

	/* W/A for Incomplete insertion case */
	if (muic_if->is_dcdtmr_intr && vbus && ccic->ccic_evt_dcdcnt < 1) {
		pr_info("%s: Incomplete insertion. Do chgdet again\n", __func__);
		ccic->ccic_evt_dcdcnt++;

		if (muic_if->set_dcd_rescan != NULL)
			muic_if->set_dcd_rescan(muic_if->muic_data);

		return 0;
	}

SKIP_RESCAN:
	return 1;
}
#endif

#if defined(CONFIG_CCIC_NOTIFIER)
static int muic_manager_handle_legacy_dev(struct muic_interface_t *muic_if)
{
	struct ccic_desc_t *ccic = muic_if->ccic;
	int attached_dev = 0;

	pr_info("%s: vbvolt:%d legacy_dev:%d\n", __func__,
			muic_if->vps.t.vbvolt, muic_if->legacy_dev);

	/* 1. Run a charger detection algorithm manually if necessary. */
	msleep(200);

	/* 2. Get the result by polling or via an interrupt */
	attached_dev = muic_manager_get_legacy_dev(muic_if);
	pr_info("%s: detected legacy_dev=%d\n", __func__, attached_dev);

	/* 3. Noti. if supported. */
	if (!muic_manager_is_ccic_supported_dev(attached_dev)) {
		pr_info("%s: Unsupported legacy_dev=%d\n", __func__, attached_dev);
		return 0;
	}

	if (muic_manager_is_supported_dev(ccic->attached_dev)) {
		MUIC_SEND_NOTI_DETACH(ccic->attached_dev);
		ccic->attached_dev = 0;
	} else if (muic_if->legacy_dev != ATTACHED_DEV_NONE_MUIC) {
		MUIC_SEND_NOTI_DETACH(muic_if->legacy_dev);
		muic_if->legacy_dev = 0;
	}

	ccic->attached_dev = attached_dev;
	MUIC_SEND_NOTI_ATTACH(attached_dev);

	return 0;
}
#endif

void muic_manager_init_dev_desc(struct muic_interface_t *muic_if)
{
	struct ccic_desc_t *ccic = muic_if->ccic;

	pr_info("%s\n", __func__);
	ccic->attached_dev = 0;
	ccic->ccic_evt_rid = 0;
	ccic->ccic_evt_rprd = 0;
	ccic->ccic_evt_roleswap = 0;
#ifndef CONFIG_MUIC_SKIP_INCOMPLETE_INSERT
	ccic->ccic_evt_dcdcnt = 0;
#endif
	ccic->ccic_evt_attached = MUIC_CCIC_NOTI_UNDEFINED;
}

#if defined(CONFIG_CCIC_NOTIFIER)
static int muic_manager_conv_rid_to_dev(struct muic_interface_t *muic_if, int rid, int vbus)
{
	int attached_dev = 0;

	if (rid < 0 || rid >  CCIC_RID_OPEN) {
		pr_err("%s:Out of RID range: %d\n", __func__, rid);
		return 0;
	}

	if ((rid == CCIC_RID_619K) && vbus)
		attached_dev = ATTACHED_DEV_JIG_UART_ON_VB_MUIC;
	else if ((rid == CCIC_RID_523K) && vbus)
		attached_dev = ATTACHED_DEV_JIG_UART_OFF_VB_MUIC;
	else
		attached_dev = muic_if->ccic->rid_desc[rid].attached_dev;

	return attached_dev;
}

static bool muic_manager_is_valid_rid_open(struct muic_interface_t *muic_if, int vbus)
{
	int i, retry = 5;

	if (vbus)
		return true;

	for (i = 0; i < retry; i++) {
		pr_info("%s: %dth ...\n", __func__, i);
		msleep(20);
		if (muic_manager_get_vbus(muic_if))
			return 1;
	}

	return 0;
}

static int muic_manager_handle_ccic_attach(struct muic_interface_t *muic_if, void *data)
{
	struct ccic_desc_t *ccic = muic_if->ccic;
#ifdef CONFIG_IFCONN_NOTIFIER
	struct ifconn_notifier_template *pnoti = (struct ifconn_notifier_template *)data;
#else
	CC_NOTI_ATTACH_TYPEDEF *pnoti = (CC_NOTI_ATTACH_TYPEDEF *)data;
#endif
	struct muic_platform_data *pdata = muic_if->pdata;
	int vbus = muic_manager_get_vbus(muic_if);

	pr_info("%s: src:%d dest:%d id:%d attach:%d cable_type:%d rprd:%d\n", __func__,
		pnoti->src, pnoti->dest, pnoti->id, pnoti->attach, pnoti->cable_type, pnoti->rprd);

	ccic->ccic_evt_attached = pnoti->attach ?
		MUIC_CCIC_NOTI_ATTACH : MUIC_CCIC_NOTI_DETACH;

	/* Attached */
	if (ccic->ccic_evt_attached == MUIC_CCIC_NOTI_ATTACH) {
		pr_info("%s: Attach\n", __func__);
		muic_if->is_ccic_attached = true;

		if (ccic->ccic_evt_roleswap) {
			pr_info("%s: roleswap event, attach USB\n", __func__);
			ccic->ccic_evt_roleswap = 0;
			if (muic_manager_get_vbus(muic_if)) {
				ccic->attached_dev = ATTACHED_DEV_USB_MUIC;
				if (muic_if->set_cable_state)
					muic_if->set_cable_state(muic_if->muic_data, ccic->attached_dev);
				muic_manager_switch_path(muic_if, MUIC_PATH_USB_AP);
				MUIC_SEND_NOTI_ATTACH(ccic->attached_dev);
			}
			return 0;
		}

		if (pnoti->rprd) {
			pr_info("%s: RPRD\n", __func__);
			ccic->ccic_evt_rprd = 1;
			ccic->attached_dev = ATTACHED_DEV_OTG_MUIC;
#if defined(CONFIG_MUIC_HV)
			if (muic_if->hv_reset)
				muic_if->hv_reset(muic_if->muic_data);
#endif
			if (muic_if->set_cable_state)
				muic_if->set_cable_state(muic_if->muic_data, ccic->attached_dev);
			muic_manager_switch_path(muic_if, MUIC_PATH_USB_AP);
			return 0;
		}
#ifndef CONFIG_MUIC_SKIP_INCOMPLETE_INSERT

#if defined(CONFIG_HV_MUIC_S2MU004_AFC)
		if (muic_if->is_afc_reset) {
			pr_info("%s: DCD RESCAN after afc reset\n", __func__);
			muic_if->is_afc_reset = false;
			if (muic_if->set_dcd_rescan != NULL && !muic_if->is_dcp_charger)
				muic_if->set_dcd_rescan(muic_if->muic_data);
		}
#endif
#endif

		if (muic_manager_is_valid_rid_open(muic_if, vbus))
			pr_info("%s: Valid VBUS-> handled in irq handler\n", __func__);
		else
			pr_info("%s: No VBUS-> doing nothing.\n", __func__);

		/* CCIC ATTACH means NO WATER */
		if (muic_if->afc_water_disable) {
			pr_info("%s: Water is not detected, AFC Enable\n", __func__);
			muic_if->afc_water_disable = false;
		}
#ifndef CONFIG_MUIC_SKIP_INCOMPLETE_INSERT
		/* W/A for Incomplete insertion case */
		ccic->ccic_evt_dcdcnt = 0;
		if (muic_if->is_dcdtmr_intr && vbus) {
			if (muic_if->vps.t.chgdetrun) {
				pr_info("%s: Incomplete insertion. Chgdet runnung\n", __func__);
				return 0;
			}
			pr_info("%s: Incomplete insertion. Do chgdet again\n", __func__);
			muic_if->is_dcdtmr_intr = false;

			if (muic_if->set_dcd_rescan != NULL)
				muic_if->set_dcd_rescan(muic_if->muic_data);
		}
#endif
	} else {
		muic_manager_handle_ccic_detach_always(muic_if);
		if (pnoti->rprd) {
			/* Role swap detach: attached=0, rprd=1 */
			pr_info("%s: role swap event\n", __func__);
			ccic->ccic_evt_roleswap = 1;
		} else if (vbus && !muic_core_get_ccic_cable_state(pdata)) {
			pr_info("%s: Valid VBUS, return\n", __func__);
#ifndef CONFIG_MUIC_SKIP_INCOMPLETE_INSERT
			if (muic_if->is_dcp_charger) {
				pr_info("%s: reset afc\n", __func__);
#if defined(CONFIG_HV_MUIC_S2MU004_AFC) || defined(CONFIG_MUIC_HV)
				if (muic_if->set_afc_reset)
					muic_if->set_afc_reset(muic_if->muic_data);
#endif
			}
#endif
		} else {
			/* Detached */
			muic_manager_handle_ccic_detach(muic_if);
		}
	}

	return 0;
}

static int muic_manager_handle_ccic_factory_jig(struct muic_interface_t *muic_if, int rid, int vbus)
{
	struct ccic_desc_t *ccic = muic_if->ccic;
	struct muic_platform_data *pdata = muic_if->pdata;
	int attached_dev = 0;

	pr_info("%s: rid:%d vbus:%d\n", __func__, rid, vbus);

	switch (rid) {
	case CCIC_RID_255K:
	case CCIC_RID_301K:
		if (pdata->jig_uart_cb)
			pdata->jig_uart_cb(1);
		muic_manager_switch_path(muic_if, MUIC_PATH_USB_AP);
		break;
	case CCIC_RID_523K:
	case CCIC_RID_619K:
		if (pdata->jig_uart_cb)
			pdata->jig_uart_cb(1);
		muic_manager_switch_path(muic_if, MUIC_PATH_UART_AP);
		break;
	default:
		pr_info("%s: Unsupported rid\n", __func__);
		return 0;
	}

	attached_dev = muic_manager_conv_rid_to_dev(muic_if, rid, vbus);

	if (attached_dev != ccic->attached_dev) {
		if (muic_manager_is_supported_dev(ccic->attached_dev)) {
			ccic->attached_dev = 0;
		} else if (muic_if->legacy_dev != ATTACHED_DEV_NONE_MUIC) {
			muic_if->legacy_dev = 0;
		}

		ccic->attached_dev = attached_dev;
#if defined(CONFIG_MUIC_HV)
		if (muic_if->hv_reset)
			muic_if->hv_reset(muic_if->muic_data);
#endif
		if (muic_if->set_cable_state)
			muic_if->set_cable_state(muic_if->muic_data, ccic->attached_dev);
		MUIC_SEND_NOTI_ATTACH(attached_dev);
	}

	return 0;
}

static int muic_manager_handle_ccic_rid(struct muic_interface_t *muic_if, void *data)
{
	struct ccic_desc_t *ccic = muic_if->ccic;
	struct muic_platform_data *pdata = muic_if->pdata;
	int rid, vbus;
#ifdef CONFIG_IFCONN_NOTIFIER
	struct ifconn_notifier_template *pnoti = (struct ifconn_notifier_template *)data;
#else
	CC_NOTI_RID_TYPEDEF *pnoti = (CC_NOTI_RID_TYPEDEF *)data;
#endif

	pr_info("%s: src:%d dest:%d id:%d rid:%d sub2:%d sub3:%d\n", __func__,
		pnoti->src, pnoti->dest, pnoti->id, pnoti->rid, pnoti->sub2, pnoti->sub3);

	rid = pnoti->rid;

	if (rid > CCIC_RID_OPEN) {
		pr_info("%s: Out of range of RID\n", __func__);
		return 0;
	}

	if (ccic->ccic_evt_attached != MUIC_CCIC_NOTI_ATTACH) {
		pr_info("%s: RID but No ATTACH->discarded\n", __func__);
		return 0;
	}

	ccic->ccic_evt_rid = rid;

	switch (rid) {
	case CCIC_RID_000K:
		pr_info("%s: OTG -> RID000K\n", __func__);
		muic_manager_switch_path(muic_if, MUIC_PATH_USB_AP);
		vbus = muic_manager_get_vbus(muic_if);
		ccic->attached_dev = muic_manager_conv_rid_to_dev(muic_if, rid, vbus);
		return 0;
	case CCIC_RID_001K:
		pr_info("%s: MHL -> discarded.\n", __func__);
		return 0;
	case CCIC_RID_255K:
	case CCIC_RID_301K:
	case CCIC_RID_523K:
	case CCIC_RID_619K:
		vbus = muic_manager_get_vbus(muic_if);
		if (muic_if->set_jig_state)
			muic_if->set_jig_state(muic_if->muic_data, true);
		muic_manager_handle_ccic_factory_jig(muic_if, rid, vbus);
		break;
	case CCIC_RID_OPEN:
	case CCIC_RID_UNDEFINED:
		vbus = muic_manager_get_vbus(muic_if);
		if (ccic->ccic_evt_attached == MUIC_CCIC_NOTI_ATTACH &&
			muic_manager_is_valid_rid_open(muic_if, vbus)) {
			if (pdata->jig_uart_cb)
				pdata->jig_uart_cb(0);
			/*
			 * USB team's requirement.
			 * Set AP USB for enumerations.
			 */
			muic_manager_switch_path(muic_if, MUIC_PATH_USB_AP);
			muic_manager_handle_legacy_dev(muic_if);
		} else {
			/* RID OPEN + No VBUS = Assume detach */
#ifndef CONFIG_SEC_FACTORY
			muic_manager_handle_ccic_rid_open(muic_if);
#else
			muic_manager_handle_ccic_detach(muic_if);
#endif
		}
		if (muic_if->set_jig_state)
			muic_if->set_jig_state(muic_if->muic_data, false);
		break;
	default:
		pr_err("%s:Undefined RID\n", __func__);
		return 0;
	}

	return 0;
}

static int muic_manager_handle_ccic_water(struct muic_interface_t *muic_if, void *data)
{
#ifdef CONFIG_IFCONN_NOTIFIER
	struct ifconn_notifier_template *pnoti = (struct ifconn_notifier_template *)data;
#else
	CC_NOTI_ATTACH_TYPEDEF *pnoti = (CC_NOTI_ATTACH_TYPEDEF *)data;
#endif

	pr_info("%s: src:%d dest:%d id:%d attach:%d cable_type:%d rprd:%d\n", __func__,
		pnoti->src, pnoti->dest, pnoti->id, pnoti->attach, pnoti->cable_type, pnoti->rprd);

	muic_if->afc_water_disable = pnoti->attach ? true:false;
	if (muic_if->set_water_detect)
		muic_if->set_water_detect(muic_if->muic_data, muic_if->afc_water_disable);

	pr_info("%s: Water detect : %s\n", __func__, pnoti->attach ? "en":"dis");

	return 0;
}

#ifndef CONFIG_SEC_FACTORY
static int muic_manager_handle_ccic_water_from_boot(struct muic_interface_t *muic_if, void *data)
{
#ifdef CONFIG_IFCONN_NOTIFIER
	struct ifconn_notifier_template *pnoti = (struct ifconn_notifier_template *)data;
#else
	CC_NOTI_ATTACH_TYPEDEF *pnoti = (CC_NOTI_ATTACH_TYPEDEF *)data;
#endif

	pr_info("%s: src:%d dest:%d id:%d attach:%d cable_type:%d rprd:%d\n", __func__,
		pnoti->src, pnoti->dest, pnoti->id, pnoti->attach, pnoti->cable_type, pnoti->rprd);

	if (muic_if->set_water_detect_from_boot)
		muic_if->set_water_detect_from_boot(muic_if->muic_data, true);
	return 0;
}
#if defined(CONFIG_HV_MUIC_S2MU004_AFC) || defined(CONFIG_MUIC_HV)
static int muic_manager_handle_ccic_TA(struct muic_interface_t *muic_if, void *data)
{
#ifdef CONFIG_IFCONN_NOTIFIER
	struct ifconn_notifier_template *pnoti = (struct ifconn_notifier_template *)data;
#else
	CC_NOTI_ATTACH_TYPEDEF *pnoti = (CC_NOTI_ATTACH_TYPEDEF *)data;
#endif

	pr_info("%s: src:%d dest:%d id:%d attach:%d cable_type:%d rprd:%d\n", __func__,
		pnoti->src, pnoti->dest, pnoti->id, pnoti->attach, pnoti->cable_type, pnoti->rprd);

	muic_if->is_afc_pdic_ready = true;
	if (muic_if->set_afc_ready)
		muic_if->set_afc_ready(muic_if->muic_data, muic_if->is_afc_pdic_ready);

	return 0;
}
#endif
#endif

#if defined(CONFIG_MUIC_SUPPORT_PRSWAP)
static int muic_manager_handle_ccic_role_swap(struct muic_interface_t *muic_if, void *data)
{
	CC_NOTI_TYPEDEF *pnoti = (CC_NOTI_TYPEDEF *)data;
	struct ccic_desc_t *ccic = muic_if->ccic;

	if (ccic->ccic_evt_attached != MUIC_CCIC_NOTI_ATTACH)
		return 0;

	pr_info("%s: src:%d dest:%d sub1:%d\n", __func__, pnoti->src, pnoti->dest,
		pnoti->sub1);

	if (pnoti->sub1 == true) {
		/* sink -> src */
		muic_if->prswap_status = MUIC_PRSWAP_TO_SRC;
	} else {
		/* src -> sink */
		muic_if->prswap_status = MUIC_PRSWAP_TO_SINK;
	}

	return 0;
}
#endif

static int muic_manager_handle_otg(struct muic_interface_t *muic_if, void *data)
{
	int ret = 0;
	struct ccic_desc_t *ccic = muic_if->ccic;
#ifdef CONFIG_IFCONN_NOTIFIER
	struct ifconn_notifier_template *pnoti = (struct ifconn_notifier_template *)data;
#else
	CC_NOTI_TYPEDEF *pnoti = (CC_NOTI_TYPEDEF *)data;
#endif

	pr_info("%s sub1:%d, check_usb_killer:%p, set_cable_state:%p\n", __func__,
		pnoti->sub1, muic_if->check_usb_killer, muic_if->set_cable_state);

	if (pnoti->sub1 == false || muic_if->check_usb_killer == false
			|| muic_if->set_cable_state == false) {
		return 0;
	}

	muic_if->is_ccic_attached = true;
	/* OTG Attach*/
	ret = muic_if->check_usb_killer(muic_if->muic_data);
	if (ret == MUIC_NORMAL_OTG) {
		ccic->attached_dev = ATTACHED_DEV_OTG_MUIC;
		muic_if->set_cable_state(muic_if->muic_data, ccic->attached_dev);
		ccic->ccic_evt_rprd = 1;
		MUIC_SEND_NOTI_ATTACH(ATTACHED_DEV_OTG_MUIC);
		MUIC_SEND_NOTI_TO_CCIC_ATTACH(ATTACHED_DEV_OTG_MUIC);
		muic_manager_switch_path(muic_if, MUIC_PATH_USB_AP);
	} else {
		pr_info("[MUIC] %s USB Killer Detected!!!\n", __func__);
	}

	return 0;
}

static int muic_manager_handle_notification(struct notifier_block *nb,
				unsigned long action, void *data)
{
#ifdef CONFIG_USB_TYPEC_MANAGER_NOTIFIER
	struct muic_interface_t *muic_if =
		container_of(nb, struct muic_interface_t, manager_nb);
#else
	struct muic_interface_t *muic_if =
		container_of(nb, struct muic_interface_t, ccic_nb);
#endif

#ifdef CONFIG_IFCONN_NOTIFIER
	struct ifconn_notifier_template *pnoti = (struct ifconn_notifier_template *)data;
	int attach = IFCONN_NOTIFY_ID_ATTACH;
	int rid = IFCONN_NOTIFY_ID_RID;
	int water = IFCONN_NOTIFY_ID_WATER;
	int otg = IFCONN_NOTIFY_ID_OTG;
#else
	CC_NOTI_TYPEDEF *pnoti = (CC_NOTI_TYPEDEF *)data;
	int attach = CCIC_NOTIFY_ID_ATTACH;
	int rid = CCIC_NOTIFY_ID_RID;
	int water = CCIC_NOTIFY_ID_WATER;
	int otg = CCIC_NOTIFY_ID_OTG;
	int ta = CCIC_NOTIFY_ID_TA;
#if defined(CONFIG_MUIC_SUPPORT_PRSWAP)
	int role_swap = CCIC_NOTIFY_ID_ROLE_SWAP;
#endif
#ifdef CONFIG_USB_TYPEC_MANAGER_NOTIFIER
	if (pnoti->dest != CCIC_NOTIFY_DEV_MUIC) {
		pr_info("%s destination id is invalid\n", __func__);
		return 0;
	}
#endif
#endif

	pr_info("%s: Rcvd Noti=> action: %d src:%d dest:%d id:%d sub[%d %d %d], muic_if : %p\n", __func__,
		(int)action, pnoti->src, pnoti->dest, pnoti->id, pnoti->sub1, pnoti->sub2, pnoti->sub3, muic_if);

	muic_manager_show_status(muic_if);

	if (pnoti->id == attach) {
		pr_info("%s: NOTIFY_ID_ATTACH: %s\n", __func__,
			pnoti->sub1 ? "Attached" : "Detached");
		muic_manager_handle_ccic_attach(muic_if, data);
	} else if (pnoti->id == rid) {
		pr_info("%s: NOTIFY_ID_RID\n", __func__);
		muic_manager_handle_ccic_rid(muic_if, data);
	} else if (pnoti->id == water) {

#ifndef CONFIG_SEC_FACTORY
		pr_info("%s: NOTIFY_ID_WATER, boot water : %d\n", __func__, pnoti->sub2);
		if (pnoti->sub2)
			muic_manager_handle_ccic_water_from_boot(muic_if, data);
		else
			muic_manager_handle_ccic_water(muic_if, data);
#else
		pr_info("%s: NOTIFY_ID_WATER\n", __func__);
		muic_manager_handle_ccic_water(muic_if, data);
#endif
	} else if (pnoti->id == otg) {
		pr_info("%s: NOTIFY_ID_OTG\n", __func__);
		muic_manager_handle_otg(muic_if, data);
	} else if (pnoti->id == ta) {
		pr_info("%s: NOTIFY_ID_TA\n", __func__);
#ifndef CONFIG_SEC_FACTORY
#if defined(CONFIG_HV_MUIC_S2MU004_AFC) || defined(CONFIG_MUIC_HV)
		muic_manager_handle_ccic_TA(muic_if, data);
#endif
#endif
#if defined(CONFIG_MUIC_SUPPORT_PRSWAP)
	} else if (pnoti->id == role_swap) {
		muic_manager_handle_ccic_role_swap(muic_if, data);
#endif
	} else {
		pr_info("%s: Undefined Noti. ID\n", __func__);
	}

	muic_manager_show_status(muic_if);

	return NOTIFY_DONE;
}

#ifndef CONFIG_IFCONN_NOTIFIER
void _muic_delayed_notifier(struct work_struct *work)
{
	struct muic_interface_t *muic_if;
	int ret = 0;

	pr_info("%s\n", __func__);

	muic_if = container_of(work, struct muic_interface_t, ccic_work.work);

#ifdef CONFIG_USB_TYPEC_MANAGER_NOTIFIER
	ret = manager_notifier_register(&muic_if->manager_nb,
		muic_manager_handle_notification, MANAGER_NOTIFY_CCIC_MUIC);
#else
	ret = ccic_notifier_register(&muic_if->ccic_nb,
		muic_manager_handle_notification, CCIC_NOTIFY_DEV_MUIC);
#endif

	if (ret < 0) {
		pr_info("%s: CCIC Noti. is not ready. Try again in 4sec...\n", __func__);
		schedule_delayed_work(&muic_if->ccic_work, msecs_to_jiffies(4000));
		return;
	}

	pr_info("%s: done.\n", __func__);
}

void muic_manager_register_notifier(struct muic_interface_t *muic_if)
{
	int ret = 0;

	pr_info("%s: Registering CCIC_NOTIFY_DEV_MUIC.\n", __func__);

	muic_manager_init_dev_desc(muic_if);

#ifdef CONFIG_USB_TYPEC_MANAGER_NOTIFIER
	ret = manager_notifier_register(&muic_if->manager_nb,
		muic_manager_handle_notification, MANAGER_NOTIFY_CCIC_MUIC);
#else
	ret = ccic_notifier_register(&muic_if->ccic_nb,
		muic_manager_handle_notification, CCIC_NOTIFY_DEV_MUIC);
#endif

	if (ret < 0) {
		pr_info("%s: CCIC Noti. is not ready. Try again in 8sec...\n", __func__);
		INIT_DELAYED_WORK(&muic_if->ccic_work, _muic_delayed_notifier);
		schedule_delayed_work(&muic_if->ccic_work, msecs_to_jiffies(8000));
		return;
	}

	pr_info("%s: done.\n", __func__);
}
#endif
#endif

struct muic_interface_t *muic_manager_init(void *pdata, void *drv_data)
{
#ifdef CONFIG_IFCONN_NOTIFIER
	int ret;
#endif
	struct muic_interface_t *muic_if;
	struct ccic_desc_t *ccic;

	pr_info("%s\n", __func__);

	muic_if = kzalloc(sizeof(*muic_if), GFP_KERNEL);
	if (unlikely(!muic_if)) {
		pr_err("%s failed to allocate driver data\n", __func__);
		return NULL;
	}

	ccic = kzalloc(sizeof(*ccic), GFP_KERNEL);
	if (unlikely(!ccic)) {
		pr_err("%s failed to allocate driver data\n", __func__);
		goto err_ccic_alloc;
	}

	muic_if->ccic = ccic;
	muic_if->muic_data = drv_data;
	muic_if->pdata = pdata;
	muic_if->ccic->rid_desc = ccic_rid_tbl;
	muic_if->opmode = get_ccic_info() & 0xF;
#ifndef CONFIG_MUIC_SKIP_INCOMPLETE_INSERT
	muic_if->is_afc_reset = false;
	muic_if->is_dcp_charger = false;
	muic_if->is_dcdtmr_intr = false;
#endif
	muic_if->is_bypass = false;
	muic_if->is_ccic_attached = false;
#if defined(CONFIG_MUIC_SUPPORT_PRSWAP)
	muic_if->prswap_status = MUIC_PRSWAP_UNDIFINED;
#endif
#if defined(CONFIG_CCIC_NOTIFIER)
	muic_if->is_afc_pdic_ready = false;
#ifdef CONFIG_IFCONN_NOTIFIER
	ret = ifconn_notifier_register(&muic_if->nb,
			muic_manager_handle_notification,
			IFCONN_NOTIFY_MUIC,
			IFCONN_NOTIFY_MANAGER);
	if (ret) {
		pr_err("%s failed register ifconn notifier\n", __func__);
		goto err_reg_noti;
	}
#else
	if (muic_if->opmode & OPMODE_CCIC)
		muic_manager_register_notifier(muic_if);
	else
		pr_info("OPMODE_MUIC CCIC NOTIFIER is not used\n");
#endif
#endif
	return muic_if;
#ifdef CONFIG_IFCONN_NOTIFIER
err_reg_noti:
	kfree(ccic);
#endif
err_ccic_alloc:
	kfree(muic_if);
	return NULL;
}

#if defined(CONFIG_MUIC_SUPPORT_POWERMETER)
static enum power_supply_property muic_props[] = {
};

static char *muic_supplied_to[] = {
	"battery",
};

static int muic_manager_get_property(struct power_supply *psy,
		enum power_supply_property psp,
		union power_supply_propval *val)
{
	switch (psp) {
	case POWER_SUPPLY_PROP_AFC_CHARGER_MODE:
		break;
	case POWER_SUPPLY_PROP_PM_VCHGIN:
		break;
	default:
		return -EINVAL;
	}

	return 0;
}

static int muic_manager_set_property(struct power_supply *psy,
		enum power_supply_property psp,
		const union power_supply_propval *val)
{
	struct muic_interface_t *muic_if =
		power_supply_get_drvdata(psy);
	enum power_supply_ext_property ext_psp = (enum power_supply_ext_property) psp;
	int ret;

	switch (psp) {
	case POWER_SUPPLY_PROP_AFC_CHARGER_MODE:
		break;
	case POWER_SUPPLY_PROP_PM_VCHGIN:
		MUIC_PDATA_FUNC_MULTI_PARAM(muic_if->pm_chgin_irq,
			muic_if->muic_data, val->intval, &ret);
		break;
	case POWER_SUPPLY_PROP_PM_FACTORY:
		muic_if->is_bypass = true;
		if (muic_if->set_bypass)
			muic_if->set_bypass(muic_if->muic_data);
		break;
	case POWER_SUPPLY_PROP_MAX ... POWER_SUPPLY_EXT_PROP_MAX:
		switch (ext_psp) {
		case POWER_SUPPLY_EXT_PROP_CURRENT_MEASURE:
			muic_if->is_bypass = true;
			if (muic_if->set_bypass)
				muic_if->set_bypass(muic_if->muic_data);
			break;
		default:
			break;
		}
		break;
	default:
		return -EINVAL;
	}
	return 0;
}

int muic_manager_psy_init(struct muic_interface_t *muic_if, struct device *parent)
{
	struct power_supply_config psy_cfg = {};
	int ret = 0;

	if (muic_if == NULL || parent == NULL) {
		pr_err("%s NULL data\n", __func__);
		return -1;
	}

	muic_if->psy_muic_desc.name           = "muic-manager";
	muic_if->psy_muic_desc.type           = POWER_SUPPLY_TYPE_UNKNOWN;
	muic_if->psy_muic_desc.get_property   = muic_manager_get_property;
	muic_if->psy_muic_desc.set_property   = muic_manager_set_property;
	muic_if->psy_muic_desc.properties     = muic_props;
	muic_if->psy_muic_desc.num_properties = ARRAY_SIZE(muic_props);

	psy_cfg.drv_data = muic_if;
	psy_cfg.supplied_to = muic_supplied_to;
	psy_cfg.num_supplicants = ARRAY_SIZE(muic_supplied_to);

	muic_if->psy_muic = power_supply_register(parent, &muic_if->psy_muic_desc, &psy_cfg);
	if (IS_ERR(muic_if->psy_muic)) {
		ret = (int)PTR_ERR(muic_if->psy_muic);
		pr_err("%s: Failed to Register psy_muic, ret : %d\n", __func__, ret);
	}
	return ret;
}
#endif

void muic_manager_exit(struct muic_interface_t *muic_if)
{
#if defined(CONFIG_MUIC_SUPPORT_POWERMETER)
	power_supply_unregister(muic_if->psy_muic);
#endif
	kfree(muic_if);
}
