[COMMON] usb: add typec driver for VTS test
authortaehyun.cho <taehyun.cho@samsung.com>
Tue, 29 May 2018 06:10:20 +0000 (15:10 +0900)
committerTaekki Kim <taekki.kim@samsung.com>
Mon, 25 Jun 2018 13:40:08 +0000 (22:40 +0900)
Change-Id: I24f9a351bdde65d4e6cbe32487c499f562d3385f
Signed-off-by: taehyun.cho <taehyun.cho@samsung.com>
drivers/usb/dwc3/Kconfig
drivers/usb/dwc3/dwc3-exynos.c

index 4c9e56d8776a1f17b8c64cc811a82b1d5479381c..ee895c6de8373d5b4f8f76a226b834fe5e1c60bc 100644 (file)
@@ -64,6 +64,7 @@ config USB_DWC3_EXYNOS
        tristate "Samsung Exynos Platform"
        depends on (ARCH_EXYNOS || COMPILE_TEST) && OF
        default USB_DWC3
+       select TYPEC
        help
          Recent Exynos5 SoCs ship with one DesignWare Core USB3 IP inside,
          say 'Y' or 'M' if you have one such device.
index d2fb09da3e40998ba871f44e465f87def5f42d20..7e46b654720450d8f2aa1e5b0ce9b124a5fb261b 100644 (file)
@@ -30,6 +30,9 @@
 #include <linux/of_platform.h>
 #include <linux/regulator/consumer.h>
 #include <linux/workqueue.h>
+#if defined(CONFIG_TYPEC)
+#include <linux/usb/typec.h>
+#endif
 
 #include <linux/io.h>
 #include <linux/usb/otg-fsm.h>
@@ -45,6 +48,16 @@ struct dwc3_exynos_rsw {
        struct work_struct      work;
 };
 
+#if defined(CONFIG_TYPEC)
+struct intf_typec {
+       /* struct mutex lock; */ /* device lock */
+       struct device *dev;
+       struct typec_port *port;
+       struct typec_capability cap;
+       struct typec_partner *partner;
+};
+#endif
+
 struct dwc3_exynos {
        struct platform_device  *usb2_phy;
        struct platform_device  *usb3_phy;
@@ -58,6 +71,9 @@ struct dwc3_exynos {
        int                     idle_ip_index;
 
        struct dwc3_exynos_rsw  rsw;
+#if defined(CONFIG_TYPEC)
+       struct intf_typec       *typec;
+#endif
 };
 
 void dwc3_otg_run_sm(struct otg_fsm *fsm);
@@ -407,8 +423,10 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
        struct dwc3_exynos      *exynos;
        struct device           *dev = &pdev->dev;
        struct device_node      *node = dev->of_node;
-
        int                     ret;
+#if defined(CONFIG_TYPEC)
+       struct intf_typec       *typec;
+#endif
 
        pr_info("%s: +++\n", __func__);
        exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
@@ -491,6 +509,28 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
                goto populate_err;
        }
 
+#if defined(CONFIG_TYPEC)
+       typec = devm_kzalloc(dev, sizeof(*typec), GFP_KERNEL);
+       if (!typec)
+               return -ENOMEM;
+
+       /* mutex_init(&md05->lock); */
+       typec->dev = dev;
+
+       typec->cap.type = TYPEC_PORT_DRP;
+       typec->cap.revision = USB_TYPEC_REV_1_1;
+       typec->cap.prefer_role = TYPEC_NO_PREFERRED_ROLE;
+
+       typec->port = typec_register_port(dev, &typec->cap);
+       if (!typec->port)
+               return -ENODEV;
+
+       typec_set_data_role(typec->port, TYPEC_DEVICE);
+       typec_set_pwr_role(typec->port, TYPEC_SINK);
+       typec_set_pwr_opmode(typec->port, TYPEC_PWR_MODE_USB);
+       exynos->typec = typec;
+#endif
+
        pr_info("%s: ---\n", __func__);
        return 0;
 
@@ -532,6 +572,11 @@ static int dwc3_exynos_remove(struct platform_device *pdev)
        if (exynos->vdd10)
                regulator_disable(exynos->vdd10);
 
+#if defined(CONFIG_TYPEC)
+       typec_unregister_partner(exynos->typec->partner);
+       typec_unregister_port(exynos->typec->port);
+#endif
+
        return 0;
 }