[ERD][NEUS7920-190] [9610] usb: notify: add otg_sw_switch
authorHOYOUNG SEO <hy50.seo@samsung.com>
Thu, 2 May 2019 05:11:33 +0000 (14:11 +0900)
committerCosmin Tanislav <demonsingur@gmail.com>
Mon, 22 Apr 2024 17:23:33 +0000 (20:23 +0300)
Change-Id: I405315c4ee28d0006c5c6c01f286affb7f2936d5
Signed-off-by: HOYOUNG SEO <hy50.seo@samsung.com>
drivers/usb/notify/Kconfig
drivers/usb/notify/usb_notifier.c
include/linux/usb_notify.h

index 44dac2fc77d0a9c51123326078d8cc883c888731..3b8fe282bf96fc44bb57625aa8f3788858185e11 100644 (file)
@@ -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
index cbcff2725657cabf7bb5e48e9b6a05217c967849..1f66d62f5a38ca877185f7f017c196711ab73672 100644 (file)
@@ -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;
 }
index d354cbec2450037533792661f2d37a3f4a04b5f7..e8a0b34e8f6d79d22352fc23804bd14dd38ea3a2 100644 (file)
@@ -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);