From eb19a39e0f43f47509ad77186625e23a0bb1da36 Mon Sep 17 00:00:00 2001 From: HOYOUNG SEO Date: Thu, 2 May 2019 14:11:33 +0900 Subject: [PATCH] [ERD][NEUS7920-190] [9610] usb: notify: add otg_sw_switch Change-Id: I405315c4ee28d0006c5c6c01f286affb7f2936d5 Signed-off-by: HOYOUNG SEO --- drivers/usb/notify/Kconfig | 4 +++ drivers/usb/notify/usb_notifier.c | 58 ++++++++++++++++++++++++++++++- include/linux/usb_notify.h | 3 ++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/drivers/usb/notify/Kconfig b/drivers/usb/notify/Kconfig index 44dac2fc77d0..3b8fe282bf96 100644 --- a/drivers/usb/notify/Kconfig +++ b/drivers/usb/notify/Kconfig @@ -82,3 +82,7 @@ config USB_HW_PARAM help Added USB H/W Parameter for DQA Agent. You need more works for USB PDIC driver. + +config USB_OTG_SW_SWITCH + boolean "USB Host S/W Switch" + depends on USB diff --git a/drivers/usb/notify/usb_notifier.c b/drivers/usb/notify/usb_notifier.c index cbcff2725657..1f66d62f5a38 100644 --- a/drivers/usb/notify/usb_notifier.c +++ b/drivers/usb/notify/usb_notifier.c @@ -806,6 +806,14 @@ static int set_online(int event, int state) static int exynos_set_host(bool enable) { +#if defined(CONFIG_USB_OTG_SW_SWITCH) + struct otg_notify *o_notify = get_otg_notify(); + + if (!o_notify->muic_sw_switch) { + pr_info("%s: OTG Switch Disabled\n", __func__); + return 0; + } +#endif if (!enable) { pr_info("%s USB_HOST_DETACHED\n", __func__); #ifdef CONFIG_OF @@ -913,6 +921,52 @@ static struct otg_notify dwc_lsi_notify = { #endif }; +#if defined(CONFIG_USB_OTG_SW_SWITCH) +static ssize_t otg_host_mode_enable_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + char value[32]; + struct otg_notify *o_notify = get_otg_notify(); + + if (!o_notify) + return -ENODEV; + + if (sscanf(buf, "%s", value) != 1) + return -EINVAL; + + if (!strncmp(value, "enabled", 6)) { + pr_info("%s: otg switch enabled\n", __func__); + o_notify->muic_sw_switch = true; + } else if (!strncmp(value, "disabled", 6)) { + pr_info("%s: otg switch disabled\n", __func__); + o_notify->muic_sw_switch = false; + } else { + return -EINVAL; + } + + return size; +} + +static ssize_t otg_host_mode_enable_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct otg_notify *o_notify = get_otg_notify(); + ssize_t size; + + if (!o_notify) + return -ENODEV; + + if (o_notify->muic_sw_switch) + size = snprintf(buf, PAGE_SIZE, "%s", "enabled\n"); + else + size = snprintf(buf, PAGE_SIZE, "%s", "disabled\n"); + + return size; +} + +static DEVICE_ATTR(host_mode, S_IRUGO | S_IWUSR, otg_host_mode_enable_show, otg_host_mode_enable_store); +#endif + static int usb_notifier_probe(struct platform_device *pdev) { struct usb_notifier_platform_data *pdata = NULL; @@ -977,7 +1031,9 @@ static int usb_notifier_probe(struct platform_device *pdev) VBUS_NOTIFY_DEV_MANAGER); #endif #endif - +#if defined(CONFIG_USB_OTG_SW_SWITCH) + device_create_file(&pdev->dev, &dev_attr_host_mode); +#endif dev_info(&pdev->dev, "usb notifier probe\n"); return 0; } diff --git a/include/linux/usb_notify.h b/include/linux/usb_notify.h index d354cbec2450..e8a0b34e8f6d 100644 --- a/include/linux/usb_notify.h +++ b/include/linux/usb_notify.h @@ -130,6 +130,9 @@ struct otg_notify { #if defined(CONFIG_IFCONN_NOTIFIER) int charger_detect; int usb_noti_done; +#endif +#if defined(CONFIG_USB_OTG_SW_SWITCH) + int muic_sw_switch; #endif const char *muic_name; int (*pre_gpio)(int gpio, int use); -- 2.20.1