From patchwork Fri Sep 4 19:18:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 11758431 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DBDD092C for ; Fri, 4 Sep 2020 19:20:35 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9AA6B206B8 for ; Fri, 4 Sep 2020 19:20:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="eK9XLPNZ"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="Ub8eFJOc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9AA6B206B8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/Bbx3jE/GLcCAjC7Y0cWacLuWeS+m0U63vG0mZxv0+A=; b=eK9XLPNZp3k6eupnHYo13hTxl RkN4QljafnAW5DLDoWHrM7M4tc43oTgDltu6tyW52bPs1tVg6Mb7dvex5URlbDyMIqI/lfRWGPmdu x47GFJ70emGglJ7rFaLeDYvLvkrGa0LSlWkfzhJCr5nQI+3071X6zAE4Ut+IqruR1PulysvFAQ6HQ B+MlxfLgUxzEQ06Hh57S5rV5SvbnxwOv0IxQqy35CNeStgt6MT3KpBGHqY1NOlQUDgPkz9GYGfGsx LaFqOJXhRG/JAu74QAJeAzKBA1XUd+c3OeEBzRLDvc8yZUonrGAZ1ysTokjUXGzomPgZEbSh+L6Nj Grb0j8NOQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kEHEn-00055N-DZ; Fri, 04 Sep 2020 19:19:05 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kEHEd-00051D-5g for linux-arm-kernel@lists.infradead.org; Fri, 04 Sep 2020 19:18:57 +0000 Received: by mail-pf1-x42c.google.com with SMTP id v196so5148487pfc.1 for ; Fri, 04 Sep 2020 12:18:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+o1kTnhnkf8evW6DjpPlTqc5IbDQ2l+8IQNKfObPRcg=; b=Ub8eFJOcHhnkBjBNAVs7WoqcLH2R/3NwLdwwS0gTm/e8FHPJTcm9PdMr4xtQq687OW 1kMyPGFLWm3aht89kYBy3SpWUepnRBWyzL84ZpVd2XD3P6ypNmxOLfHd32/Fz8mI2q18 sFram9TXrekM5y0v7M3eFwJtFfjsjd6QIYsVU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+o1kTnhnkf8evW6DjpPlTqc5IbDQ2l+8IQNKfObPRcg=; b=UBEnMqtBn7gSA4VmAALY71Laz/GNXENAO5vIAs5o31DBWpeHI36Xb/RonLqjD3+WWq 20EgIqP6wpAn4JBQql21z3vTdCMtLVsharOxLlVwAQdrgjMdoaTQLSZotc68zJCFskTP 2RuGvUh5/Rfg4OOzWg0ZMMZ/QpHZHtZ6rQKG6VMNwkC3PDFWRYm+elw+MjmYGCIx79fN oHavUkwsnV58E4+ukg0zl1Kl2G0/0OzWCCn78XP02hTmopCYFjDmP69wNlEtSGDcfjMT yCKuEinjmfgwZ3LNtjNvS7iFwBf9QvAefDK71EC9TVxZ6uh5aI7eLu5s5G17Apd1+VCq ARfw== X-Gm-Message-State: AOAM533vZvINTs/I6wF+JXnfyT3C2UyFcbvU2bZ18g4DQx3+hJlG0VwC UOyPOGkrQnpf7TnP/tOxOe1MilWgJJxfCg== X-Google-Smtp-Source: ABdhPJxeupP/Y8O6Ovq4KCzOQMOefBkJ1+gUf8zE0vGCTLY0jHVuKQCOd0weoS9P60yGUbzIS2mn/w== X-Received: by 2002:a62:406:: with SMTP id 6mr10016207pfe.193.1599247132975; Fri, 04 Sep 2020 12:18:52 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:b9ea:24bf:6b2b:1eee]) by smtp.gmail.com with ESMTPSA id t4sm5986001pje.56.2020.09.04.12.18.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 12:18:52 -0700 (PDT) From: Jagan Teki To: MyungJoo Ham , Chanwoo Choi , Rob Herring , Heiko Stuebner Subject: [PATCH 1/3] dt-bindings: extcon: Document Type-C Virtual PD driver Date: Sat, 5 Sep 2020 00:48:28 +0530 Message-Id: <20200904191830.387296-2-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200904191830.387296-1-jagan@amarulasolutions.com> References: <20200904191830.387296-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200904_151855_286866_37C7CB3D X-CRM114-Status: GOOD ( 16.39 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42c listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Tom Cubie , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Jagan Teki , linux-amarula@amarulasolutions.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org USB Type-C protocol supports various modes of operations includes PD, USB3, and Altmode. If the platform design supports a Type-C connector then configuring these modes can be done via enumeration. However, there are some platforms that design these modes of operations as separate protocol connectors like design Display Port from on-chip USB3 controller. So accessing Type-C Altmode Display Port via onboard Display Port connector instead of a Type-C connector. These kinds of platforms require an explicit extcon driver in order to handle Power Delivery and Port Detection. Document dt-bindings for it. Signed-off-by: Jagan Teki --- .../extcon/extcon-usbc-virtual-pd.yaml | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usbc-virtual-pd.yaml diff --git a/Documentation/devicetree/bindings/extcon/extcon-usbc-virtual-pd.yaml b/Documentation/devicetree/bindings/extcon/extcon-usbc-virtual-pd.yaml new file mode 100644 index 000000000000..8110fbe2ddc2 --- /dev/null +++ b/Documentation/devicetree/bindings/extcon/extcon-usbc-virtual-pd.yaml @@ -0,0 +1,66 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/extcon/extcon-usbc-virtual-pd.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Type-C Virtual PD extcon + +maintainers: + - Jagan Teki + +description: | + USB Type-C protocol supports various modes of operations includes PD, + USB3, and Altmode. If the platform design supports a Type-C connector + then configuring these modes can be done via enumeration. + + However, there are some platforms that design these modes as separate + protocol connectors like design Display Port from on-chip USB3 controller. + So we can access Type-C Altmode Display Port via onboard Display Port + connector instead of a Type-C connector. These kinds of platforms require + an explicit extcon driver in order to handle Power Delivery and + Port Detection. + +properties: + compatible: + const: linux,extcon-usbc-virtual-pd + + det-gpios: + description: Detect GPIO pin. Pin can be Display Port Detect or USB ID. + maxItems: 1 + + vpd-polarity: + description: USB Type-C Polarity. false for Normal and true for Flip. + type: boolean + + vpd-super-speed: + description: USB Super Speed. false for USB2 and true for USB3. + type: boolean + + vpd-data-role: + description: USB Data roles for Virtual Type-C. + $ref: /schemas/types.yaml#definitions/string + + enum: + - host + - device + - display-port + +required: + - compatible + - det-gpios + - vpd-data-role + +additionalProperties: false + +examples: + - | + #include + #include + + virtual_pd: virtual-pd { + compatible = "linux,extcon-usbc-virtual-pd"; + det-gpios = <&gpio4 RK_PD1 GPIO_ACTIVE_LOW>; + vpd-data-role = "display-port"; + vpd-super-speed; + }; From patchwork Fri Sep 4 19:18:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 11758435 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 22AF2618 for ; Fri, 4 Sep 2020 19:20:49 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D2069206B8 for ; Fri, 4 Sep 2020 19:20:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="AaVNvu4k"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="Js+dMC2y" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D2069206B8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zbOTAIcvA9XOlCvVVhL9Rnniu8t6k29h8Qtjtpm51do=; b=AaVNvu4kEA2bT2xtAJ0aOoop2 i2y8Q9uzq76oa+zbF+csqsUmrNNEzVKFvIQ3PwY4gdVK5Loap1KSuqGDzmLPyq1/tWxcGHhl0Xh9E DZaZlG+BBtS4KySG1lrCUsmqvoMBiIvo7nBg0PO0XLGLDGU6zHeCmzVwd1+ES947FV1CM7JMzbuWx +OIHoZNMSm81hVca7JvpHtvT5B5BYHWxKzNHvc36j1iDDw5wFMfF03sPNFph50Ey3aRTuFq0x6I0K hKWJ7F1C5eVv3Pmg4qW2UGrh+q1J6wbPM5rUbrgOb1GeVu7yGU7CZqwbl1F/utRFsZ+6QYgXdnZB4 gM1MyS6+Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kEHEz-00058q-HQ; Fri, 04 Sep 2020 19:19:17 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kEHEh-000530-3n for linux-arm-kernel@lists.infradead.org; Fri, 04 Sep 2020 19:19:06 +0000 Received: by mail-pf1-x442.google.com with SMTP id w7so5141030pfi.4 for ; Fri, 04 Sep 2020 12:18:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+0r4W9mwB3hElBdfBrvtjd4X0q5DQJLDeKjMbcplMDU=; b=Js+dMC2y6bJOPfgi+dpPWCdzalyDqvjHxyFNDwMUi825KGhHDJI1Ytib81Zz86k6fH QK6do1e81kvyEHJvPtSMRRA6NEoB51cFZHAzoUMfgMZwIi9++wQiqIPG4ONZluvE3hPf zIV0UTmQ9bHzSJk31E9ibifexitYDo7hzHx98= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+0r4W9mwB3hElBdfBrvtjd4X0q5DQJLDeKjMbcplMDU=; b=KBbyhx3mWSl+iP3OJs8tMvcvwkUyBTr4peqDib0LiJS2Yl48zNv3AgyTbGX0o0tE4F m+Fojvv+6wFsW5Zk++JNME1tASVx8cSOv57O6fUz3ChCbpHsrgifgUcXVVmuxb4hYae2 1+4RiR0KNExt64DxHl1rPvJUNKH0XKnoIk+sW4NxIqbRC0979rAXaVc1m0vz1O+mJw5V +7gAPCwBQEWquHmA/lztvkSDMc6BijZxO9WlKvG80H+MrJURdjS1Sz4vyxRzKKriA2Hl KLPsW+4DUUW9lRNdrLA6wsiJEuMUrq7Tk5QiSwH5hlDqpHWBistT5F37/8lf7LGb5FhO LqkQ== X-Gm-Message-State: AOAM532EFzTHGouWaz4wmMArhNnqDUqbDPoNRXvyta0/bmsaM21S5/2H V0/X5KXA8AQzohYjsj6e70Xmog== X-Google-Smtp-Source: ABdhPJwPFAeSEqozQ2oq/5q8jmzdSVhlRwP56anlVHCYZpX7bRboVFg0gwDr5Qiwv41Zg6sEsTBtew== X-Received: by 2002:a63:6fc6:: with SMTP id k189mr8132738pgc.165.1599247136913; Fri, 04 Sep 2020 12:18:56 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:b9ea:24bf:6b2b:1eee]) by smtp.gmail.com with ESMTPSA id t4sm5986001pje.56.2020.09.04.12.18.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 12:18:56 -0700 (PDT) From: Jagan Teki To: MyungJoo Ham , Chanwoo Choi , Rob Herring , Heiko Stuebner Subject: [PATCH 2/3] extcon: Add Type-C Virtual PD driver Date: Sat, 5 Sep 2020 00:48:29 +0530 Message-Id: <20200904191830.387296-3-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200904191830.387296-1-jagan@amarulasolutions.com> References: <20200904191830.387296-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200904_151859_533790_A69497A0 X-CRM114-Status: GOOD ( 26.92 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:442 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Tom Cubie , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Jagan Teki , linux-amarula@amarulasolutions.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org USB Type-C protocol supports various modes of operations includes PD, USB3, and Altmode. If the platform design supports a Type-C connector then configuring these modes can be done via enumeration. However, there are some platforms that design these modes of operations as separate protocol connectors like design Display Port from on-chip USB3 controller. So accessing Type-C Altmode Display Port via onboard Display Port connector instead of a Type-C connector. These kinds of platforms require an explicit extcon driver in order to handle Power Delivery and Port Detection. Add extcon driver for it. Signed-off-by: Jagan Teki --- MAINTAINERS | 6 + drivers/extcon/Kconfig | 10 + drivers/extcon/Makefile | 1 + drivers/extcon/extcon-usbc-virtual-pd.c | 285 ++++++++++++++++++++++++ 4 files changed, 302 insertions(+) create mode 100644 drivers/extcon/extcon-usbc-virtual-pd.c diff --git a/MAINTAINERS b/MAINTAINERS index 68f21d46614c..aeb161b19dae 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -6466,6 +6466,12 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git F: Documentation/filesystems/ext4/ F: fs/ext4/ +EXTCON DRIVER FOR TYPE-C VIRTUAL PD +M: Jagan Teki +S: Maintained +F: Documentation/devicetree/bindings/extcon/extcon-usbc-virtual-pd.yaml +F: drivers/extcon/extcon-usbc-virtual-pd.c + Extended Verification Module (EVM) M: Mimi Zohar L: linux-integrity@vger.kernel.org diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index aac507bff135..edd6c3c52699 100644 --- a/drivers/extcon/Kconfig +++ b/drivers/extcon/Kconfig @@ -186,4 +186,14 @@ config EXTCON_USBC_CROS_EC Say Y here to enable USB Type C cable detection extcon support when using Chrome OS EC based USB Type-C ports. +config EXTCON_USBC_VIRTUAL_PD + tristate "Virtual Type-C PD EXTCON support" + depends on GPIOLIB || COMPILE_TEST + help + Say Y here to enable Virtual Type-C PD extcon driver support, if + hardware platform designed Type-C modes separately. + + Example, of designing Display Port separately from Type-C Altmode + instead of accessing Altmode Display Port in Type-C connector. + endif diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile index 52096fd8a216..c35191eef0e1 100644 --- a/drivers/extcon/Makefile +++ b/drivers/extcon/Makefile @@ -25,3 +25,4 @@ obj-$(CONFIG_EXTCON_RT8973A) += extcon-rt8973a.o obj-$(CONFIG_EXTCON_SM5502) += extcon-sm5502.o obj-$(CONFIG_EXTCON_USB_GPIO) += extcon-usb-gpio.o obj-$(CONFIG_EXTCON_USBC_CROS_EC) += extcon-usbc-cros-ec.o +obj-$(CONFIG_EXTCON_USBC_VIRTUAL_PD) += extcon-usbc-virtual-pd.o diff --git a/drivers/extcon/extcon-usbc-virtual-pd.c b/drivers/extcon/extcon-usbc-virtual-pd.c new file mode 100644 index 000000000000..e0713670e33d --- /dev/null +++ b/drivers/extcon/extcon-usbc-virtual-pd.c @@ -0,0 +1,285 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Type-C Virtual PD Extcon driver + * + * Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd + * Copyright (c) 2019 Radxa Limited + * Copyright (c) 2019 Amarula Solutions(India) + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const unsigned int vpd_cable[] = { + EXTCON_USB, + EXTCON_USB_HOST, + EXTCON_DISP_DP, + EXTCON_NONE, +}; + +enum vpd_data_role { + DR_NONE, + DR_HOST, + DR_DEVICE, + DR_DISPLAY_PORT, +}; + +enum vpd_polarity { + POLARITY_NORMAL, + POLARITY_FLIP, +}; + +enum vpd_usb_ss { + USB_SS_USB2, + USB_SS_USB3, +}; + +struct vpd_extcon { + struct device *dev; + struct extcon_dev *extcon; + struct gpio_desc *det_gpio; + + u8 polarity; + u8 usb_ss; + enum vpd_data_role data_role; + + int irq; + bool enable_irq; + struct work_struct work; + struct delayed_work irq_work; +}; + +static void vpd_extcon_irq_work(struct work_struct *work) +{ + struct vpd_extcon *vpd = container_of(work, struct vpd_extcon, irq_work.work); + bool host_connected = false, device_connected = false, dp_connected = false; + union extcon_property_value property; + int det; + + det = vpd->det_gpio ? gpiod_get_raw_value(vpd->det_gpio) : 0; + if (det) { + device_connected = (vpd->data_role == DR_DEVICE) ? true : false; + host_connected = (vpd->data_role == DR_HOST) ? true : false; + dp_connected = (vpd->data_role == DR_DISPLAY_PORT) ? true : false; + } + + extcon_set_state(vpd->extcon, EXTCON_USB, host_connected); + extcon_set_state(vpd->extcon, EXTCON_USB_HOST, device_connected); + extcon_set_state(vpd->extcon, EXTCON_DISP_DP, dp_connected); + + property.intval = vpd->polarity; + extcon_set_property(vpd->extcon, EXTCON_USB, + EXTCON_PROP_USB_TYPEC_POLARITY, property); + extcon_set_property(vpd->extcon, EXTCON_USB_HOST, + EXTCON_PROP_USB_TYPEC_POLARITY, property); + extcon_set_property(vpd->extcon, EXTCON_DISP_DP, + EXTCON_PROP_USB_TYPEC_POLARITY, property); + + property.intval = vpd->usb_ss; + extcon_set_property(vpd->extcon, EXTCON_USB, + EXTCON_PROP_USB_SS, property); + extcon_set_property(vpd->extcon, EXTCON_USB_HOST, + EXTCON_PROP_USB_SS, property); + extcon_set_property(vpd->extcon, EXTCON_DISP_DP, + EXTCON_PROP_USB_SS, property); + + extcon_sync(vpd->extcon, EXTCON_USB); + extcon_sync(vpd->extcon, EXTCON_USB_HOST); + extcon_sync(vpd->extcon, EXTCON_DISP_DP); +} + +static irqreturn_t vpd_extcon_irq_handler(int irq, void *dev_id) +{ + struct vpd_extcon *vpd = dev_id; + + schedule_delayed_work(&vpd->irq_work, msecs_to_jiffies(10)); + + return IRQ_HANDLED; +} + +static enum vpd_data_role vpd_extcon_data_role(struct vpd_extcon *vpd) +{ + const char *const data_roles[] = { + [DR_NONE] = "NONE", + [DR_HOST] = "host", + [DR_DEVICE] = "device", + [DR_DISPLAY_PORT] = "display-port", + }; + struct device *dev = vpd->dev; + int ret; + const char *dr; + + ret = device_property_read_string(dev, "vpd-data-role", &dr); + if (ret < 0) + return DR_NONE; + + ret = match_string(data_roles, ARRAY_SIZE(data_roles), dr); + + return (ret < 0) ? DR_NONE : ret; +} + +static int vpd_extcon_parse_dts(struct vpd_extcon *vpd) +{ + struct device *dev = vpd->dev; + bool val = false; + int ret; + + val = device_property_read_bool(dev, "vpd-polarity"); + if (val) + vpd->polarity = POLARITY_FLIP; + else + vpd->polarity = POLARITY_NORMAL; + + val = device_property_read_bool(dev, "vpd-super-speed"); + if (val) + vpd->usb_ss = USB_SS_USB3; + else + vpd->usb_ss = USB_SS_USB2; + + vpd->data_role = vpd_extcon_data_role(vpd); + + vpd->det_gpio = devm_gpiod_get_optional(dev, "det", GPIOD_OUT_LOW); + if (IS_ERR(vpd->det_gpio)) { + ret = PTR_ERR(vpd->det_gpio); + dev_warn(dev, "failed to get det gpio: %d\n", ret); + return ret; + } + + vpd->irq = gpiod_to_irq(vpd->det_gpio); + if (vpd->irq < 0) { + dev_err(dev, "failed to get irq for gpio: %d\n", vpd->irq); + return vpd->irq; + } + + ret = devm_request_threaded_irq(dev, vpd->irq, NULL, + vpd_extcon_irq_handler, + IRQF_TRIGGER_FALLING | + IRQF_TRIGGER_RISING | IRQF_ONESHOT, + NULL, vpd); + if (ret) + dev_err(dev, "failed to request gpio irq\n"); + + return ret; +} + +static int vpd_extcon_probe(struct platform_device *pdev) +{ + struct vpd_extcon *vpd; + struct device *dev = &pdev->dev; + int ret; + + vpd = devm_kzalloc(dev, sizeof(*vpd), GFP_KERNEL); + if (!vpd) + return -ENOMEM; + + vpd->dev = dev; + ret = vpd_extcon_parse_dts(vpd); + if (ret) + return ret; + + INIT_DELAYED_WORK(&vpd->irq_work, vpd_extcon_irq_work); + + vpd->extcon = devm_extcon_dev_allocate(dev, vpd_cable); + if (IS_ERR(vpd->extcon)) { + dev_err(dev, "allocat extcon failed\n"); + return PTR_ERR(vpd->extcon); + } + + ret = devm_extcon_dev_register(dev, vpd->extcon); + if (ret) { + dev_err(dev, "register extcon failed: %d\n", ret); + return ret; + } + + extcon_set_property_capability(vpd->extcon, EXTCON_USB, + EXTCON_PROP_USB_VBUS); + extcon_set_property_capability(vpd->extcon, EXTCON_USB_HOST, + EXTCON_PROP_USB_VBUS); + + extcon_set_property_capability(vpd->extcon, EXTCON_USB, + EXTCON_PROP_USB_TYPEC_POLARITY); + extcon_set_property_capability(vpd->extcon, EXTCON_USB_HOST, + EXTCON_PROP_USB_TYPEC_POLARITY); + extcon_set_property_capability(vpd->extcon, EXTCON_USB, + EXTCON_PROP_USB_SS); + extcon_set_property_capability(vpd->extcon, EXTCON_USB_HOST, + EXTCON_PROP_USB_SS); + + extcon_set_property_capability(vpd->extcon, EXTCON_DISP_DP, + EXTCON_PROP_USB_SS); + extcon_set_property_capability(vpd->extcon, EXTCON_DISP_DP, + EXTCON_PROP_USB_TYPEC_POLARITY); + + platform_set_drvdata(pdev, vpd); + + vpd_extcon_irq_work(&vpd->irq_work.work); + + return 0; +} + +static int vpd_extcon_remove(struct platform_device *pdev) +{ + struct vpd_extcon *vpd = platform_get_drvdata(pdev); + + cancel_delayed_work_sync(&vpd->irq_work); + + return 0; +} + +#ifdef CONFIG_PM_SLEEP +static int vpd_extcon_suspend(struct device *dev) +{ + struct vpd_extcon *vpd = dev_get_drvdata(dev); + + if (!vpd->enable_irq) { + disable_irq_nosync(vpd->irq); + vpd->enable_irq = true; + } + + return 0; +} + +static int vpd_extcon_resume(struct device *dev) +{ + struct vpd_extcon *vpd = dev_get_drvdata(dev); + + if (vpd->enable_irq) { + enable_irq(vpd->irq); + vpd->enable_irq = false; + } + + return 0; +} +#endif + +static SIMPLE_DEV_PM_OPS(vpd_extcon_pm_ops, + vpd_extcon_suspend, vpd_extcon_resume); + +static const struct of_device_id vpd_extcon_dt_match[] = { + { .compatible = "linux,extcon-usbc-virtual-pd", }, + { /* sentinel */ } +}; + +static struct platform_driver vpd_extcon_driver = { + .probe = vpd_extcon_probe, + .remove = vpd_extcon_remove, + .driver = { + .name = "extcon-usbc-virtual-pd", + .pm = &vpd_extcon_pm_ops, + .of_match_table = vpd_extcon_dt_match, + }, +}; + +module_platform_driver(vpd_extcon_driver); + +MODULE_AUTHOR("Jagan Teki "); +MODULE_DESCRIPTION("Type-C Virtual PD extcon driver"); +MODULE_LICENSE("GPL v2"); From patchwork Fri Sep 4 19:18:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 11758433 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C955392C for ; Fri, 4 Sep 2020 19:20:45 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 980D7206B8 for ; Fri, 4 Sep 2020 19:20:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="emPzxVTI"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="eEwr7rjO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 980D7206B8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Fp8sE+L1J1aL3g//nMuSOYVstEFP1SQSXPyVebp0u78=; b=emPzxVTI6AtdCTpZMZ0WR4feb MSgQzCpyOtjYgOzb2GASwUtwXniun0eV3QcdZauCBgRlNTmQep62nx/pHB8/TmutEkxi6BypeX0pl xRazIFtCHCYSdELko5Za797nz7V9No/et+Kcck1+xn0VkJl4n5hO2gmvT4x2aEVuLeME35HjWgu6b BkkmALYQ/Jh2P3dqP8Ey6E7Am10dp58znpgW3Uc7/OQauk5IR406rBsiiAYddYydUSzZ73tncywdZ QaZymiZ6AEeh1d5tNSyhldZa9Y9xZdoItfy//ZEJiE/Vj5kJAyNnsiEgfuTgTVxftE2ED/Yo5gx2S 3hwimQ0vw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kEHF5-0005CY-PL; Fri, 04 Sep 2020 19:19:23 +0000 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kEHEl-00054J-4k for linux-arm-kernel@lists.infradead.org; Fri, 04 Sep 2020 19:19:08 +0000 Received: by mail-pj1-x1041.google.com with SMTP id n3so5553200pjq.1 for ; Fri, 04 Sep 2020 12:19:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qRMPP9LxKZUNiuhnbNUkYFs55rCgA//jb+vd/Rx6Ht0=; b=eEwr7rjOHjYc90SI75Z6Ut+MR+UIR8SjsReg4Nh+bkkNtf3q6mhsZe/DOfXcHbnOjz drKjfYKMQUPR1vGqcPN3Bl+y6ed/X+LsPKZVQsSpKrtVddmpMBN0zhjmooYpjO8cxUyh k3zKOVzfP8YdEHI1VaORIAtYLL2AQ6r2WUqAs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qRMPP9LxKZUNiuhnbNUkYFs55rCgA//jb+vd/Rx6Ht0=; b=dV5HuPZRZWrsMk1GhV1nBKu6o2rBTw2luOa0OTm4dIihBHFh9Uy2w2zZI1vEv5Hicl P9uh6eLWmbqZd0kaabM5gtP9Q0YWSKdZWZ8fYlEgtBKYsCimbFbAGBhywPHHnp9BUsHD A4t9naQnKOIamtA5iG9ionosENCkhgeJyH5OuB6pvhcnsHG5w4rbrtE8zAA3BNh+pQ+0 RvSEHWdDAJSvDbl+xSDRxjhjOErd6qED7psMNQi8LKIJ+kWXlwXps+wn3bjZ6uKSx4wM DDepNx4iU6HnzTFhxFEGp33T2LrESolQVR6b3Oo8E0CPyXFnrT/I4ouludOQNsSUZKjJ fRSQ== X-Gm-Message-State: AOAM531uYpuS/wnsXY5OFTwof0jEqfdzOAjWdlxQG4OxOpk2LOYe0KMx ESBeOSmTNeCaupkU/JLk/CpwtQ== X-Google-Smtp-Source: ABdhPJzUuILtE+Lwd5POY+0Lfp6RXonJmBryQBkbG0RS+y2jdm+w1JLUsyQMiNXyvqjHmoi1pWFsZg== X-Received: by 2002:a17:902:be08:b029:d0:5c75:38da with SMTP id r8-20020a170902be08b02900d05c7538damr9927728pls.1.1599247140913; Fri, 04 Sep 2020 12:19:00 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:b9ea:24bf:6b2b:1eee]) by smtp.gmail.com with ESMTPSA id t4sm5986001pje.56.2020.09.04.12.18.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 12:19:00 -0700 (PDT) From: Jagan Teki To: MyungJoo Ham , Chanwoo Choi , Rob Herring , Heiko Stuebner Subject: [PATCH 3/3] arm64: dts: rk3399-rock-pi-4c: Enable Display Port Date: Sat, 5 Sep 2020 00:48:30 +0530 Message-Id: <20200904191830.387296-4-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200904191830.387296-1-jagan@amarulasolutions.com> References: <20200904191830.387296-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200904_151903_294193_844F950A X-CRM114-Status: GOOD ( 13.39 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1041 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Tom Cubie , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Jagan Teki , linux-amarula@amarulasolutions.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Enable Display Port on ROCK Pi 4C board. Unlike, other RK3399 platforms with accessing DP Altmode via Type-C connector, the display Port on ROCK Pi 4C is accessible via physical display port connector by means of Type-C Virtual PD extcon configuration. Enable support for it. Signed-off-by: Jagan Teki --- .../boot/dts/rockchip/rk3399-rock-pi-4c.dts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/arm64/boot/dts/rockchip/rk3399-rock-pi-4c.dts b/arch/arm64/boot/dts/rockchip/rk3399-rock-pi-4c.dts index 4c7ebb1c5d2d..19a648add355 100644 --- a/arch/arm64/boot/dts/rockchip/rk3399-rock-pi-4c.dts +++ b/arch/arm64/boot/dts/rockchip/rk3399-rock-pi-4c.dts @@ -11,6 +11,22 @@ / { model = "Radxa ROCK Pi 4C"; compatible = "radxa,rockpi4c", "radxa,rockpi4", "rockchip,rk3399"; + + virtual_pd: virtual-pd { + compatible = "linux,extcon-usbc-virtual-pd"; + det-gpios = <&gpio4 RK_PD1 GPIO_ACTIVE_LOW>; /* DP_HPD */ + vpd-data-role = "display-port"; + vpd-super-speed; + }; +}; + +&cdn_dp { + extcon = <&virtual_pd>; + status = "okay"; +}; + +&tcphy0 { + extcon = <&virtual_pd>; }; &sdio0 {