From patchwork Mon May 15 09:05:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Stephan X-Patchwork-Id: 13241263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 959F2C7EE22 for ; Mon, 15 May 2023 10:45:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YLZCFIrTsQDEXMJlY6amXZan08MGZ8c71Qc7JpoNzVg=; b=gGyEDoKPZCtma8 oBxj1/cePHfv8xR1lT1YXGMXqWfwCWUX/hW/vR126lrd4bi21eKKNGSmE81DNYujP4UKbIryQv6Ck oxZ0Hh4rgGeFQPLUdD1qRH74X+tPmyoEj3AmqvbkSeN+1zeDyIz3M2i1PFKD2ekKYtaflpbnLTwg7 NexkGYRPLBNVDyMEp2tYx4U6uFQLJUDl4yW4HgJJDg0DjNrfR4ouUvPuHshXhWeW6vXUFfK90Hq7h UFiSfICYDSNwMQwsJQewAHHsWmixpJX/dAzOS8Hgp7pMBxUfAh8akmeehYpDocQtwGdLbTQgg2Cjv 8LxKw1NxVMGzYwdKthbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pyVhb-001srT-26; Mon, 15 May 2023 10:45:15 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pyUcW-001Zv8-2Z for linux-arm-kernel@lists.infradead.org; Mon, 15 May 2023 09:35:59 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3f42c865534so66586085e9.2 for ; Mon, 15 May 2023 02:35:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1684143355; x=1686735355; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i1U5d4MLxOVRGxYrIG94ORc3atBG6AwDIhORaNjU7E8=; b=0I7No2h2vVPxZmELHElkO+DCMmo/7h06fCuFCt9VWkpo8/xiz0U4nvQr+oP9mcYZtf FX4pXi+9qn6fWaFgnuy9ee8GlUrAvc8uOIPfMUmMy7ACNpBV4nfERAdFfCntOoJ20RN9 zoQsNqlbnxRL3Gg+Kxjq+LQr44RsWRr1z+XR6KwIl47cS1kUp2xFQg0lQLdiHdPsWGRR eAA0GQQjkW/1ExWten9k75ga4J8zLaqeB3zjT9+EgCjfS4qgaI50Zsg4keJHUZPEA3V1 XL1tbgpzyYuCd+brFvK8S14n9y8WsypZnjmYhBHTwpgto1VIDsbN7OmbxQm3QCNaUEas mfAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684143355; x=1686735355; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i1U5d4MLxOVRGxYrIG94ORc3atBG6AwDIhORaNjU7E8=; b=S9DgXjlOC0o4TYr25S0HZ1NW9EN1q/OG0Tf2jzmutx0MDNfJxbj4HhBefnchC0TnDZ aY9LFdpd7iXuWzfDog7pzlo9Z7Yb+7agu8HFb5Q99hukxgXuvTvwoGx9SyrbzZe5PVB7 XpAQSE3KR1T5FsFy0fEiP6lw/ry0fsOyQUCxGOkSlXFRAhlKVTpZWtXH/tHkHofXMeoa 2rRdY7mvJNq43Qr4c+sVDehrtUqQSqf18P/7HtmObyCOm7aJcvUK0iNT8s6JVj/oDcG3 QaGTRhod8RlAPxtB2gwdx7/EiWMBYV4adr6YoPhYCn+NTB65AMpVD8tmpO+DmxWz8Ntz pFvg== X-Gm-Message-State: AC+VfDxQliOuFyArSWI+d0K5+M9Gbo7zT+nyEDePLc60XG4SS1HYUbh8 Jff2PLSxdgm5b5BFgjQ29sIdrA== X-Google-Smtp-Source: ACHHUZ7+Cb+vH+WpGUTIuorFy/U4TAkpqUMxuly4awYN+dmnigKVjCrRjrsxKfKFu1bnpDBzyacmPA== X-Received: by 2002:a1c:cc0e:0:b0:3ef:622c:26d3 with SMTP id h14-20020a1ccc0e000000b003ef622c26d3mr26682092wmb.35.1684143354910; Mon, 15 May 2023 02:35:54 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:55f:21e0:fd3b:9fed:e621:cc8f]) by smtp.gmail.com with ESMTPSA id z22-20020a7bc7d6000000b003f42813b315sm21035451wmk.32.2023.05.15.02.35.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 02:35:54 -0700 (PDT) From: Julien Stephan To: Cc: krzysztof.kozlowski@linaro.org, robh@kernel.org, chunkuang.hu@kernel.org, linux-mediatek@lists.infradead.org, Florian Sylvestre , Julien Stephan , Chunfeng Yun , Andy Hsieh , Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Matthias Brugger , AngeloGioacchino Del Regno , linux-arm-kernel@lists.infradead.org (moderated list:ARM/Mediatek USB3 PHY DRIVER), linux-phy@lists.infradead.org (open list:GENERIC PHY FRAMEWORK), devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 1/2] dt-bindings: phy: add mediatek mipi csi driver v 0.5 Date: Mon, 15 May 2023 11:05:50 +0200 Message-Id: <20230515090551.1251389-2-jstephan@baylibre.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230515090551.1251389-1-jstephan@baylibre.com> References: <20230515090551.1251389-1-jstephan@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230515_023556_840070_8382DBC9 X-CRM114-Status: GOOD ( 18.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Florian Sylvestre This adds the bindings, for the MIPI CD-PHY module v 0.5 embedded in some Mediatek soc, such as the mt8365 Signed-off-by: Florian Sylvestre Signed-off-by: Julien Stephan --- .../phy/mediatek,phy-mipi-csi-0-5.yaml | 62 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 68 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/mediatek,phy-mipi-csi-0-5.yaml diff --git a/Documentation/devicetree/bindings/phy/mediatek,phy-mipi-csi-0-5.yaml b/Documentation/devicetree/bindings/phy/mediatek,phy-mipi-csi-0-5.yaml new file mode 100644 index 000000000000..5aa8c0b41cdf --- /dev/null +++ b/Documentation/devicetree/bindings/phy/mediatek,phy-mipi-csi-0-5.yaml @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: (GPL-2.0-Only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/mediatek,phy-mipi-csi-0-5.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Mediatek Sensor Interface MIPI CSI CD-PHY + +maintainers: + - Julien Stephan + - Andy Hsieh + +description: + The SENINF CD-PHY is a set of CD-PHY connected to the SENINF CSI-2 + receivers. The number of PHYs depends on the SoC model. + Depending on the soc model, each PHYs can support CDPHY or DPHY only + +properties: + compatible: + enum: + - mediatek,phy-mipi-csi-0-5 + + reg: + maxItems: 1 + + '#phy-cells': + const: 0 + + mediatek,is_cdphy: + description: + Specify if the current phy support CDPHY configuration + type: boolean + +required: + - compatible + - reg + - '#phy-cells' + +additionalProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + mipi_rx_csi0: mipi_rx_csi0@11c10000 { + compatible = "mediatek,phy-mipi-csi-0-5"; + reg = <0 0x11C10000 0 0x2000>; + status = "okay"; + mediatek,is_cdphy; + #phy-cells = <0>; + }; + + mipi_rx_csi1: mipi-rx-csi1@11c12000 { + compatible = "mediatek,phy-mipi-csi-0-5"; + reg = <0 0x11C12000 0 0x2000>; + status = "disabled"; + #phy-cells = <0>; + }; + }; +... diff --git a/MAINTAINERS b/MAINTAINERS index 6d54f3193075..44f0ff11e984 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13098,6 +13098,12 @@ F: Documentation/devicetree/bindings/media/mediatek-vpu.txt F: drivers/media/platform/mediatek/vcodec/ F: drivers/media/platform/mediatek/vpu/ +MEDIATEK MIPI-CSI CDPHY DRIVER +M: Julien Stephan +M: Andy Hsieh +S: Supported +F: Documentation/devicetree/bindings/phy/mediatek,phy-mipi-csi-0-5.yaml + MEDIATEK MMC/SD/SDIO DRIVER M: Chaotian Jing S: Maintained From patchwork Mon May 15 09:05:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Stephan X-Patchwork-Id: 13241264 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CCB50C7EE25 for ; Mon, 15 May 2023 10:45:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iOX1ig6VqrJiGegUOXdPG+COB/o+bhJGS72RvzdvGKg=; b=21EyMjSl2KGS2k NYVQBRkOGXtW91ZKj0H4HIeZ6ev0s4V8XK+dkmk5aEEE3lJbpDoxBubtoAhfk045y5wBGNEI2+A/2 3rtMwyUOKX21p8eMxWXZvSrINcA5wDVS72cNd1YOgtfoJmz34Fpw1BOrmcHA6y7I2hJEKXBTMhlWA h9XA4GFVAksTLOYsOq9Be9OTjCpFcuwv7AOpwHuP/aDgOUI5tuzEUx+3ye0m5yewKS/uhfwHyV31m jpmOyy0JxvM8fcuq03V2ta8KN/a+1iyHeiSCTFbYd5H3HNr2gNmNKKMh0NFP4/CLWpDV7TA5CreKc QK2xXUjkR8tE+LGeA9ng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pyVhc-001ssV-2b; Mon, 15 May 2023 10:45:16 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pyUcb-001ZyQ-2l for linux-arm-kernel@lists.infradead.org; Mon, 15 May 2023 09:36:05 +0000 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3062db220a3so8049246f8f.0 for ; Mon, 15 May 2023 02:36:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1684143359; x=1686735359; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=N97Vk4nuEZlmrW0JyiHDyQvQiT5eAYuTdYKWLmRd1tc=; b=afLFR4tkKbPOPuWSXBCkfyTJh6jL4j8Kv0wY7dOWD+VQXzr4Gl+d14zurwTW1qbryG g7ESimKQhzsRoEXcaC2U45SJZqt+yAXwlVlF8SUjODvl3PhuvI21PT/aedcR4vZq70Ic 7KVbhMdLBL7VwR/I5BvS9kl1kDWCzQknhe9A6FwkkzJWiiA7IX0I1ff26cjHGkhDJV6C zOtyZ2oPUlkbrLi3Zov3MCPTh42V+W/AUd6e0OpPW6/V2/JIAX53M5bfjs4Z9ts5kWkf 3iPcil56x+074twzPyHol4UUXmg/amimJyuWOyc74T1QSHZ5GusxFl8Wj1kaRX0+1lpr L3Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684143359; x=1686735359; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N97Vk4nuEZlmrW0JyiHDyQvQiT5eAYuTdYKWLmRd1tc=; b=l5tAqhrGVo5QVq9By8BwJH0QwMjJ2w8h7NbvO7PoaNj5XjWAJ7owpo8n/sciIfx1t+ hLx/zHos4WVOMgSpLfJvcE+ghhrt7fEIv19+ss9KmgsAIa1/PhC/RUnmQ6ZHZv8EyZnD ExNWkZwWG36ruDnVlXKJrzCJmxTSQZnsdKHV76Skwbm+BNe8TZatx6hXbJPKEz4kT2ik 9YIqM5DbuQ9+0j2BCxOpDse47nVgMHaiAaHDuOoPvANbtp7pzA8guJNlewlcMRt0HbGP nqtvkinx1Kx43vDHM/bVrMeQrEe7Uo/3yQJy/Yb9ibtd//LJ43fwqfBQ5FBVCQ0O5u90 qFRw== X-Gm-Message-State: AC+VfDxMznQn19XAUCDY9tFKmh9GtpMfo7Sa9XL0qRTQZne/6BcfwPl1 hYUh1t9fOE160AsqXmcxjK1zOw== X-Google-Smtp-Source: ACHHUZ6GmUfRbmphiJGmS1MuVhUgvcKJEzO43Qic6xC/RbBMs33YqX7gwAuIxqtXzl+8bsCedxgZ8Q== X-Received: by 2002:adf:e2c3:0:b0:307:9b66:f512 with SMTP id d3-20020adfe2c3000000b003079b66f512mr15451744wrj.19.1684143359690; Mon, 15 May 2023 02:35:59 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:55f:21e0:fd3b:9fed:e621:cc8f]) by smtp.gmail.com with ESMTPSA id z22-20020a7bc7d6000000b003f42813b315sm21035451wmk.32.2023.05.15.02.35.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 02:35:59 -0700 (PDT) From: Julien Stephan To: Cc: krzysztof.kozlowski@linaro.org, robh@kernel.org, chunkuang.hu@kernel.org, linux-mediatek@lists.infradead.org, Phi-bang Nguyen , Louis Kuo , Julien Stephan , Chunfeng Yun , Vinod Koul , Kishon Vijay Abraham I , Andy Hsieh , Philipp Zabel , Matthias Brugger , AngeloGioacchino Del Regno , linux-kernel@vger.kernel.org (open list), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Mediatek USB3 PHY DRIVER), linux-phy@lists.infradead.org (open list:GENERIC PHY FRAMEWORK), dri-devel@lists.freedesktop.org (open list:DRM DRIVERS FOR MEDIATEK) Subject: [PATCH v2 2/2] phy: mtk-mipi-csi: add driver for CSI phy Date: Mon, 15 May 2023 11:05:51 +0200 Message-Id: <20230515090551.1251389-3-jstephan@baylibre.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230515090551.1251389-1-jstephan@baylibre.com> References: <20230515090551.1251389-1-jstephan@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230515_023601_927656_A44A964F X-CRM114-Status: GOOD ( 22.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Phi-bang Nguyen This is a new driver that supports the MIPI CSI CD-PHY version 0.5 The number of PHYs depend on the soc. Signed-off-by: Louis Kuo Signed-off-by: Phi-bang Nguyen [Julien Stephan: use GENMASK] [Julien Stephan: refactor code] [Julien Stephan: update device tree support and probe function] Co-developed-by: Julien Stephan Signed-off-by: Julien Stephan --- MAINTAINERS | 1 + drivers/phy/mediatek/Kconfig | 8 + drivers/phy/mediatek/Makefile | 2 + .../mediatek/phy-mtk-mipi-csi-0-5-rx-reg.h | 58 ++++ drivers/phy/mediatek/phy-mtk-mipi-csi-0-5.c | 257 ++++++++++++++++++ 5 files changed, 326 insertions(+) create mode 100644 drivers/phy/mediatek/phy-mtk-mipi-csi-0-5-rx-reg.h create mode 100644 drivers/phy/mediatek/phy-mtk-mipi-csi-0-5.c diff --git a/MAINTAINERS b/MAINTAINERS index 44f0ff11e984..fc2766cb50d3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13103,6 +13103,7 @@ M: Julien Stephan M: Andy Hsieh S: Supported F: Documentation/devicetree/bindings/phy/mediatek,phy-mipi-csi-0-5.yaml +F: drivers/phy/mediatek/phy-mtk-mipi-csi-0-5* MEDIATEK MMC/SD/SDIO DRIVER M: Chaotian Jing diff --git a/drivers/phy/mediatek/Kconfig b/drivers/phy/mediatek/Kconfig index 3125ecb5d119..452bc7ac5ce5 100644 --- a/drivers/phy/mediatek/Kconfig +++ b/drivers/phy/mediatek/Kconfig @@ -74,3 +74,11 @@ config PHY_MTK_DP select GENERIC_PHY help Support DisplayPort PHY for MediaTek SoCs. + +config PHY_MTK_MIPI_CSI_0_5 + tristate "MediaTek CSI CD-PHY v 0.5 Driver" + depends on ARCH_MEDIATEK && OF + select GENERIC_PHY + help + Enable this to support the MIPI CSI CD-PHY receiver version 0.5. + The driver supports multiple CSI cdphy ports simultaneously. diff --git a/drivers/phy/mediatek/Makefile b/drivers/phy/mediatek/Makefile index fb1f8edaffa7..8eb7b8747c67 100644 --- a/drivers/phy/mediatek/Makefile +++ b/drivers/phy/mediatek/Makefile @@ -18,3 +18,5 @@ phy-mtk-mipi-dsi-drv-y := phy-mtk-mipi-dsi.o phy-mtk-mipi-dsi-drv-y += phy-mtk-mipi-dsi-mt8173.o phy-mtk-mipi-dsi-drv-y += phy-mtk-mipi-dsi-mt8183.o obj-$(CONFIG_PHY_MTK_MIPI_DSI) += phy-mtk-mipi-dsi-drv.o + +obj-$(CONFIG_PHY_MTK_MIPI_CSI_0_5) += phy-mtk-mipi-csi-0-5.o diff --git a/drivers/phy/mediatek/phy-mtk-mipi-csi-0-5-rx-reg.h b/drivers/phy/mediatek/phy-mtk-mipi-csi-0-5-rx-reg.h new file mode 100644 index 000000000000..e9a7f1ab3e2f --- /dev/null +++ b/drivers/phy/mediatek/phy-mtk-mipi-csi-0-5-rx-reg.h @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __PHY_MTK__MIPI_CSI__C_0_5_RX_REG_H__ +#define __PHY_MTK__MIPI_CSI__C_0_5_RX_REG_H__ + +/* + * CSI1 and CSI2 are identical, and similar to CSI0. All CSIx macros are + * applicable to the three PHYs. Where differences exist, they are denoted by + * macro names using CSI0 and CSI1, the latter being applicable to CSI1 and + * CSI2 alike. + */ + +#define MIPI_RX_ANA00_CSIxA 0x0000 +#define RG_CSI0A_CPHY_EN BIT(0) +#define RG_CSIxA_EQ_PROTECT_EN BIT(1) +#define RG_CSIxA_BG_LPF_EN BIT(2) +#define RG_CSIxA_BG_CORE_EN BIT(3) +#define RG_CSIxA_DPHY_L0_CKMODE_EN BIT(5) +#define RG_CSIxA_DPHY_L0_CKSEL BIT(6) +#define RG_CSIxA_DPHY_L1_CKMODE_EN BIT(8) +#define RG_CSIxA_DPHY_L1_CKSEL BIT(9) +#define RG_CSIxA_DPHY_L2_CKMODE_EN BIT(11) +#define RG_CSIxA_DPHY_L2_CKSEL BIT(12) + +#define MIPI_RX_ANA18_CSIxA 0x0018 +#define RG_CSI0A_L0_T0AB_EQ_IS GENMASK(5, 4) +#define RG_CSI0A_L0_T0AB_EQ_BW GENMASK(7, 6) +#define RG_CSI0A_L1_T1AB_EQ_IS GENMASK(21, 20) +#define RG_CSI0A_L1_T1AB_EQ_BW GENMASK(23, 22) +#define RG_CSI0A_L2_T1BC_EQ_IS GENMASK(21, 20) +#define RG_CSI0A_L2_T1BC_EQ_BW GENMASK(23, 22) +#define RG_CSI1A_L0_EQ_IS GENMASK(5, 4) +#define RG_CSI1A_L0_EQ_BW GENMASK(7, 6) +#define RG_CSI1A_L1_EQ_IS GENMASK(21, 20) +#define RG_CSI1A_L1_EQ_BW GENMASK(23, 22) +#define RG_CSI1A_L2_EQ_IS GENMASK(5, 4) +#define RG_CSI1A_L2_EQ_BW GENMASK(7, 6) + +#define MIPI_RX_ANA1C_CSIxA 0x001c +#define MIPI_RX_ANA20_CSI0A 0x0020 + +#define MIPI_RX_ANA24_CSIxA 0x0024 +#define RG_CSIxA_RESERVE GENMASK(31, 24) + +#define MIPI_RX_ANA40_CSIxA 0x0040 +#define RG_CSIxA_CPHY_FMCK_SEL GENMASK(1, 0) +#define RG_CSIxA_ASYNC_OPTION GENMASK(7, 4) +#define RG_CSIxA_CPHY_SPARE GENMASK(31, 16) + +#define MIPI_RX_WRAPPER80_CSIxA 0x0080 +#define CSR_CSI_RST_MODE GENMASK(17, 16) + +#define MIPI_RX_ANAA8_CSIxA 0x00a8 +#define RG_CSIxA_CDPHY_L0_T0_BYTECK_INVERT BIT(0) +#define RG_CSIxA_DPHY_L1_BYTECK_INVERT BIT(1) +#define RG_CSIxA_CDPHY_L2_T1_BYTECK_INVERT BIT(2) + +#endif diff --git a/drivers/phy/mediatek/phy-mtk-mipi-csi-0-5.c b/drivers/phy/mediatek/phy-mtk-mipi-csi-0-5.c new file mode 100644 index 000000000000..ae2d3dc9631d --- /dev/null +++ b/drivers/phy/mediatek/phy-mtk-mipi-csi-0-5.c @@ -0,0 +1,257 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "phy-mtk-io.h" +#include "phy-mtk-mipi-csi-0-5-rx-reg.h" + +#define CSIxB_OFFSET 0x1000 + +struct mtk_mipi_dphy; + +struct mtk_mipi_dphy_port { + struct device *dev; + void __iomem *base; + struct phy *phy; + bool is_cdphy; +}; + +static int mtk_mipi_phy_power_on(struct phy *phy) +{ + struct mtk_mipi_dphy_port *port = phy_get_drvdata(phy); + void __iomem *base = port->base; + + /* + * Only DPHY is supported for now, + * so set analog phy mode to DPHY in CDPHY compatible PHYs + */ + if (port->is_cdphy) { + mtk_phy_update_field(base + MIPI_RX_ANA00_CSIxA, + RG_CSI0A_CPHY_EN, 0); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA00_CSIxA, + RG_CSI0A_CPHY_EN, 0); + } + + /* + * Lane configuration: + * + * Only 4 data + 1 clock is supported for now with the following mapping: + * + * CSIxA_LNR0 --> D2 + * CSIxA_LNR1 --> D0 + * CSIxA_LNR2 --> C + * CSIxB_LNR0 --> D1 + * CSIxB_LNR1 --> D3 + */ + mtk_phy_update_field(base + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_DPHY_L0_CKMODE_EN, 0); + mtk_phy_update_field(base + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_DPHY_L0_CKSEL, 1); + mtk_phy_update_field(base + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_DPHY_L1_CKMODE_EN, 0); + mtk_phy_update_field(base + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_DPHY_L1_CKSEL, 1); + mtk_phy_update_field(base + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_DPHY_L2_CKMODE_EN, 1); + mtk_phy_update_field(base + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_DPHY_L2_CKSEL, 1); + + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_DPHY_L0_CKMODE_EN, 0); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_DPHY_L0_CKSEL, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_DPHY_L1_CKMODE_EN, 0); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_DPHY_L1_CKSEL, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_DPHY_L2_CKMODE_EN, 0); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_DPHY_L2_CKSEL, 1); + + /* Byte clock invert */ + mtk_phy_update_field(base + MIPI_RX_ANAA8_CSIxA, + RG_CSIxA_CDPHY_L0_T0_BYTECK_INVERT, 1); + mtk_phy_update_field(base + MIPI_RX_ANAA8_CSIxA, + RG_CSIxA_DPHY_L1_BYTECK_INVERT, 1); + mtk_phy_update_field(base + MIPI_RX_ANAA8_CSIxA, + RG_CSIxA_CDPHY_L2_T1_BYTECK_INVERT, 1); + + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANAA8_CSIxA, + RG_CSIxA_CDPHY_L0_T0_BYTECK_INVERT, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANAA8_CSIxA, + RG_CSIxA_DPHY_L1_BYTECK_INVERT, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANAA8_CSIxA, + RG_CSIxA_CDPHY_L2_T1_BYTECK_INVERT, 1); + + /* Start ANA EQ tuning */ + if (port->is_cdphy) { + mtk_phy_update_field(base + MIPI_RX_ANA18_CSIxA, + RG_CSI0A_L0_T0AB_EQ_IS, 1); + mtk_phy_update_field(base + MIPI_RX_ANA18_CSIxA, + RG_CSI0A_L0_T0AB_EQ_BW, 1); + mtk_phy_update_field(base + MIPI_RX_ANA1C_CSIxA, + RG_CSI0A_L1_T1AB_EQ_IS, 1); + mtk_phy_update_field(base + MIPI_RX_ANA1C_CSIxA, + RG_CSI0A_L1_T1AB_EQ_BW, 1); + mtk_phy_update_field(base + MIPI_RX_ANA20_CSI0A, + RG_CSI0A_L2_T1BC_EQ_IS, 1); + mtk_phy_update_field(base + MIPI_RX_ANA20_CSI0A, + RG_CSI0A_L2_T1BC_EQ_BW, 1); + + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA18_CSIxA, + RG_CSI0A_L0_T0AB_EQ_IS, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA18_CSIxA, + RG_CSI0A_L0_T0AB_EQ_BW, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA1C_CSIxA, + RG_CSI0A_L1_T1AB_EQ_IS, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA1C_CSIxA, + RG_CSI0A_L1_T1AB_EQ_BW, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA20_CSI0A, + RG_CSI0A_L2_T1BC_EQ_IS, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA20_CSI0A, + RG_CSI0A_L2_T1BC_EQ_BW, 1); + } else { + mtk_phy_update_field(base + MIPI_RX_ANA18_CSIxA, + RG_CSI1A_L0_EQ_IS, 1); + mtk_phy_update_field(base + MIPI_RX_ANA18_CSIxA, + RG_CSI1A_L0_EQ_BW, 1); + mtk_phy_update_field(base + MIPI_RX_ANA18_CSIxA, + RG_CSI1A_L1_EQ_IS, 1); + mtk_phy_update_field(base + MIPI_RX_ANA18_CSIxA, + RG_CSI1A_L1_EQ_BW, 1); + mtk_phy_update_field(base + MIPI_RX_ANA1C_CSIxA, + RG_CSI1A_L2_EQ_IS, 1); + mtk_phy_update_field(base + MIPI_RX_ANA1C_CSIxA, + RG_CSI1A_L2_EQ_BW, 1); + + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA18_CSIxA, + RG_CSI1A_L0_EQ_IS, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA18_CSIxA, + RG_CSI1A_L0_EQ_BW, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA18_CSIxA, + RG_CSI1A_L1_EQ_IS, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA18_CSIxA, + RG_CSI1A_L1_EQ_BW, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA1C_CSIxA, + RG_CSI1A_L2_EQ_IS, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA1C_CSIxA, + RG_CSI1A_L2_EQ_BW, 1); + } + + /* End ANA EQ tuning */ + mtk_phy_set_bits(base + MIPI_RX_ANA40_CSIxA, 0x90); + + mtk_phy_update_field(base + MIPI_RX_ANA24_CSIxA, + RG_CSIxA_RESERVE, 0x40); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA24_CSIxA, + RG_CSIxA_RESERVE, 0x40); + mtk_phy_update_field(base + MIPI_RX_WRAPPER80_CSIxA, + CSR_CSI_RST_MODE, 0); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_WRAPPER80_CSIxA, + CSR_CSI_RST_MODE, 0); + /* ANA power on */ + mtk_phy_update_field(base + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_BG_CORE_EN, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_BG_CORE_EN, 1); + usleep_range(20, 40); + mtk_phy_update_field(base + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_BG_LPF_EN, 1); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_BG_LPF_EN, 1); + + return 0; +} + +static int mtk_mipi_phy_power_off(struct phy *phy) +{ + struct mtk_mipi_dphy_port *port = phy_get_drvdata(phy); + void __iomem *base = port->base; + + /* Disable MIPI BG. */ + mtk_phy_update_field(base + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_BG_CORE_EN, 0); + mtk_phy_update_field(base + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_BG_LPF_EN, 0); + + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_BG_CORE_EN, 0); + mtk_phy_update_field(base + CSIxB_OFFSET + MIPI_RX_ANA00_CSIxA, + RG_CSIxA_BG_LPF_EN, 0); + + return 0; +} + +static const struct phy_ops mtk_dphy_ops = { + .power_on = mtk_mipi_phy_power_on, + .power_off = mtk_mipi_phy_power_off, + .owner = THIS_MODULE, +}; + +static int mtk_mipi_dphy_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct phy_provider *phy_provider; + struct mtk_mipi_dphy_port *port; + struct phy *phy; + + port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + if (!port) + return -ENOMEM; + + dev_set_drvdata(dev, port); + + port->dev = dev; + + port->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(port->base)) + return PTR_ERR(port->base); + + port->is_cdphy = of_property_read_bool(dev->of_node, "mediatek,is_cdphy"); + + phy = devm_phy_create(dev, NULL, &mtk_dphy_ops); + if (IS_ERR(phy)) { + dev_err(dev, "Failed to create PHY: %ld\n", PTR_ERR(phy)); + return PTR_ERR(phy); + } + + port->phy = phy; + phy_set_drvdata(phy, port); + + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + if (IS_ERR(phy_provider)) { + dev_err(dev, "Failed to register PHY provider: %ld\n", + PTR_ERR(phy_provider)); + return PTR_ERR(phy_provider); + } + + return 0; +} + +static const struct of_device_id mtk_mipi_dphy_of_match[] = { + {.compatible = "mediatek,phy-mipi-csi-0-5"}, + {}, +}; +MODULE_DEVICE_TABLE(of, mtk_mipi_dphy_of_match); + +static struct platform_driver mipi_dphy_pdrv = { + .probe = mtk_mipi_dphy_probe, + .driver = { + .name = "mtk-mipi-csi-0-5", + .of_match_table = mtk_mipi_dphy_of_match, + }, +}; + +module_platform_driver(mipi_dphy_pdrv); + +MODULE_DESCRIPTION("MTK mipi csi cdphy driver"); +MODULE_AUTHOR("Louis Kuo "); +MODULE_LICENSE("GPL");