From patchwork Wed Feb 10 08:07:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 12080079 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EAACC433E9 for ; Wed, 10 Feb 2021 08:08:08 +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 8CA2F601FF for ; Wed, 10 Feb 2021 08:08:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8CA2F601FF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-amlogic-bounces+linux-amlogic=archiver.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=C+01xDCp5KF61eZwgMz5juA2ETuJaULUVBavQdhnhNU=; b=UaSkPJcR80XLop/9BqaOJgQp1 465ykGaIZaQkzpoc8L7lDs8YirRFXZ/zZ/y/zck7yG6Ai29rC41itJtNtwEBsKCjt5SIvCT27VmNs 91DuO+JeRfebeNacIPibDAaOFEUVE7dBo8mUVCgqd+vtkAhJzPpiVMG12xIuUxvXfAQLsfyflilXh 2dLNYECMUbtXvJQNOK+n1nZu48hS6+KN8hu31n2x7aAmqW1xOPitUx0beeEW8cOc2ih32woKQoEiB vTMKidoZsYf+GBA3Rh4Hna/ZvoMtOy4kgl3qLXjDBJs/fzdLtrDlivpoBQCxOuZ4oTQuMKiQAR4C8 sEPGpOEEw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l9kXS-0001Fm-Mi; Wed, 10 Feb 2021 08:07:54 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l9kXK-0001CC-MA for linux-amlogic@lists.infradead.org; Wed, 10 Feb 2021 08:07:49 +0000 Received: by mail-wr1-x42d.google.com with SMTP id h12so1402737wrw.6 for ; Wed, 10 Feb 2021 00:07:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ADCBKNEvDCsXJjSVMo0gh3Ha9p8ktO5jYuFtRysBMF0=; b=YQjWY+hxJxeD56cqq89+O+y3MDwbuTakyQLYHodtIrzbPq8PcNsRLO5z6jEf4udjmu 9ipNyIapLAnvb6vdPjQRv7+BS25p3zD57IpUiX8gYoEp5j7iIfoASJnaTevZ+VY/cq1U ZZ24OOieq/HVm2ngAm56Gwx9bRCOakIGJ+raObziF0qDxw8VNQKr7JdSmpCY3YXy/1aQ BGtVGf4fxV8sqHgyv3Yx1IYvR3REvuwY0OcN1tSmZmXJo43fJnUfNAR1+72iEAC0328K lRNmzIyQfGkI9im1sO2OwzfnfVhvlcXNjqPSNOIhriQ82XHP6cm9OWv6RIl/TiHG8nMP yhBA== 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=ADCBKNEvDCsXJjSVMo0gh3Ha9p8ktO5jYuFtRysBMF0=; b=PGHznGqondgej5erh+Ng+lEL8wG4qf5yVKOfBufhi0SZH362b0OLVlynEtWmGYTbqm esQ2JXIwXpghmMFGZLxIfZCKSP6lVOgAZK9ZO5FAC8/V98FmeP0Wrjf5/r/wyrmNU6A+ DmOX/P1/wu7T2BKIv0Ap/kB4VvHIKoDjxrG3ZQjjhiS5uHGn2D0r/1DQDOaPoOTjiX/x nANJ2TSRfSQBHV5S6Qf/YjZP31Xw2WRPalkdXYMqOSkB0M/Mk00UHK8lZPliQH5mPNP3 j80R76v53LwfHtbmn6wFiV/NFQgk3Cy6YLBNbFWjb+VZD/fBf4KMHnBo7bKeAl8cvT8B dqzA== X-Gm-Message-State: AOAM531+JYOvWNqitkfU7TJg0KdVAd22JIp08rDom2TaXxua4fN8GuQY 8BMzfbXD2Rx2N7BUJ7EXJDLSIg== X-Google-Smtp-Source: ABdhPJxN7qsejNz3LbGpff6S3f17fETxX5jUqtrZgVWo2AQppiLn4e8WrPCGMJlCsA22dd/fAqA/IQ== X-Received: by 2002:a5d:47af:: with SMTP id 15mr2171896wrb.205.1612944463308; Wed, 10 Feb 2021 00:07:43 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:90c:e290:d403:f5fa:8912:cba5]) by smtp.gmail.com with ESMTPSA id c18sm12856597wmk.0.2021.02.10.00.07.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 00:07:42 -0800 (PST) From: Neil Armstrong To: vkoul@kernel.org, kishon@ti.com, devicetree@vger.kernel.org Subject: [PATCH v2 1/2] dt-bindings: phy: add Amlogic G12A Analog MIPI D-PHY bindings Date: Wed, 10 Feb 2021 09:07:35 +0100 Message-Id: <20210210080736.771803-2-narmstrong@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210210080736.771803-1-narmstrong@baylibre.com> References: <20210210080736.771803-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210210_030746_760364_7ED5940F X-CRM114-Status: GOOD ( 13.38 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Neil Armstrong Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org The Amlogic G12A SoCs embeds an Analog MIPI D-PHY to communicate with DSI panels, this adds the bindings. This Analog D-PHY works with a separate Digital MIPI D-PHY. Signed-off-by: Neil Armstrong --- .../phy/amlogic,g12a-mipi-dphy-analog.yaml | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/amlogic,g12a-mipi-dphy-analog.yaml diff --git a/Documentation/devicetree/bindings/phy/amlogic,g12a-mipi-dphy-analog.yaml b/Documentation/devicetree/bindings/phy/amlogic,g12a-mipi-dphy-analog.yaml new file mode 100644 index 000000000000..14bb8d78a860 --- /dev/null +++ b/Documentation/devicetree/bindings/phy/amlogic,g12a-mipi-dphy-analog.yaml @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/phy/amlogic,g12a-mipi-dphy-analog.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Amlogic G12A MIPI analog PHY + +maintainers: + - Neil Armstrong + +properties: + compatible: + const: amlogic,g12a-mipi-dphy-analog + + "#phy-cells": + const: 0 + + reg: + maxItems: 1 + +required: + - compatible + - reg + - "#phy-cells" + +additionalProperties: false + +examples: + - | + phy@0 { + compatible = "amlogic,g12a-mipi-dphy-analog"; + #phy-cells = <0>; + reg = <0>; + }; From patchwork Wed Feb 10 08:07:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 12080077 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D993EC433E6 for ; Wed, 10 Feb 2021 08:08:07 +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 8CA6464E42 for ; Wed, 10 Feb 2021 08:08:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8CA6464E42 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-amlogic-bounces+linux-amlogic=archiver.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=Cv4ld0a4Sn/6Lct7zGRUJ4sAk8NcHSfoRSYDBkxub08=; b=QJoTsL7HjcHBQH3/UQEYZvAlt qn3wX1lI22HcRczRsf5Wrf2GlUOextpJT4cDtE7iHKrY+78dkrlg44QBsYdnoSYSHR3rAJnpc6Mex qAaTnsncTK5t7FtbsnIwfU2H6FqOHD3lSu7z667OtJlBVD0afGgFsdAoGcFlGX7Cm8GOytSN7uCZK 9o7mb19A2rgq8J0E5+v/CKM/8UHGpmh+x0ZElZoEBeX1CiCLO6VHkSvdS9HR3s3vTLNGdeRrMTBNL lsedghxJ+p9ZgRrfvwPgzBjlQLgLBbiHOObjJjI9uCDRiyGb+ScssmJrMzjGMHBTst28IFyViyI1t OPIC4N8ZA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l9kXY-0001HD-OK; Wed, 10 Feb 2021 08:08:00 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l9kXL-0001CM-W6 for linux-amlogic@lists.infradead.org; Wed, 10 Feb 2021 08:07:49 +0000 Received: by mail-wm1-x32f.google.com with SMTP id f16so1004491wmq.5 for ; Wed, 10 Feb 2021 00:07:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fHWF5TDlNwWGy88TN4XkKblCivGgDwghMb/yRIfXJVc=; b=cinsfMD2U8mM0GToap11SPbtnC99Qfbe+bDzIyZs8ZgtVYwzcyy9ov4Otk+ESVw6W+ enU7QIVLrG26UvZoVOkpQR7ZYeIo0echDDgmZABpzXZ1/jONrJkVazvXpfRbyB4tcS/x RHItnpJglH1r9NTQuB0Q8VsCiPbF5KBV4qCpaj/XFcZ6m/alLzgUxpCJAQIcFIJP8dQP kq5cfw4X9cGevzuSetMbWmZmfXvbZiL3/7OMwJCyGE5VWK8ZANmlu4j/JyJt6itPRv1h KqoD5NY36X70mtsPx21Q4QIXI+Cqhndc2nQS0IB2lZ1CXuo26qMh20ZRQKWEZiQ877bK pLJQ== 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=fHWF5TDlNwWGy88TN4XkKblCivGgDwghMb/yRIfXJVc=; b=fGQ2GpieQ7uNZS44DfsEKjmsYuXc1Ivs0kHm0rHPwMSaaaQwO+gtJTjnrYpEOj8lL3 /mZidVrWnH/lP0/rj/8TAP1qadiwJVLk9+vuth9mHrG5ZZ9quzdL3ud0EGa2pvlT9zMJ qNR5Bj/7HfBvXXpHNPT3atG3mnxhZzfODishGtEzC3n8tsR84AtnUUH48x1P5kpeb6HJ 2rBZP2zyZqy2zQ1O0npC4YcOq4Y3Y7c1f4HhXUBzc1e1bOQe0yEKp/72orukDRphimUV rVG/452NeGg3dbLsxjcGt4E5lCcbiX0RijxKoScTPbCa76N/fknsaQcXeQ1iHDbVwzT+ SneQ== X-Gm-Message-State: AOAM532njhHQ1xjIDa7ZRZYde+jgPszZELESr/TmAGSjH59M9ECyrySC e22a+Wy4XRzVKFxpT2KfTHVEYzgGl5jBcep9 X-Google-Smtp-Source: ABdhPJyvyg0OOoJX/A+h1gkHVGS9Wu4fKqsYe0hXvbtoB5ZO1e+KN/++IwDacRxiYyAOFACphiYfrw== X-Received: by 2002:a05:600c:3589:: with SMTP id p9mr1782867wmq.18.1612944464625; Wed, 10 Feb 2021 00:07:44 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:90c:e290:d403:f5fa:8912:cba5]) by smtp.gmail.com with ESMTPSA id c18sm12856597wmk.0.2021.02.10.00.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 00:07:44 -0800 (PST) From: Neil Armstrong To: vkoul@kernel.org, kishon@ti.com Subject: [PATCH v2 2/2] phy: amlogic: Add G12A Analog MIPI D-PHY driver Date: Wed, 10 Feb 2021 09:07:36 +0100 Message-Id: <20210210080736.771803-3-narmstrong@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210210080736.771803-1-narmstrong@baylibre.com> References: <20210210080736.771803-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210210_030748_056650_8D191029 X-CRM114-Status: GOOD ( 21.89 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Neil Armstrong Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org The Amlogic G12A SoCs embeds an Analog MIPI D-PHY used to communicate with DSI panels. Signed-off-by: Neil Armstrong --- drivers/phy/amlogic/Kconfig | 12 ++ drivers/phy/amlogic/Makefile | 1 + .../amlogic/phy-meson-g12a-mipi-dphy-analog.c | 177 ++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100644 drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c diff --git a/drivers/phy/amlogic/Kconfig b/drivers/phy/amlogic/Kconfig index db5d0cd757e3..ac898a102bcc 100644 --- a/drivers/phy/amlogic/Kconfig +++ b/drivers/phy/amlogic/Kconfig @@ -49,6 +49,18 @@ config PHY_MESON_G12A_USB3_PCIE in Meson G12A SoCs. If unsure, say N. +config PHY_MESON_G12A_MIPI_DPHY_ANALOG + tristate "Meson G12A MIPI Analog DPHY driver" + default ARCH_MESON + depends on OF && (ARCH_MESON || COMPILE_TEST) + select GENERIC_PHY + select REGMAP_MMIO + select GENERIC_PHY_MIPI_DPHY + help + Enable this to support the Meson MIPI Analog DPHY found in Meson G12A + SoCs. + If unsure, say N. + config PHY_MESON_AXG_PCIE tristate "Meson AXG PCIE PHY driver" default ARCH_MESON diff --git a/drivers/phy/amlogic/Makefile b/drivers/phy/amlogic/Makefile index 8fa07fbd0d92..2eada0a683ca 100644 --- a/drivers/phy/amlogic/Makefile +++ b/drivers/phy/amlogic/Makefile @@ -3,6 +3,7 @@ obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o obj-$(CONFIG_PHY_MESON_GXL_USB2) += phy-meson-gxl-usb2.o obj-$(CONFIG_PHY_MESON_G12A_USB2) += phy-meson-g12a-usb2.o obj-$(CONFIG_PHY_MESON_G12A_USB3_PCIE) += phy-meson-g12a-usb3-pcie.o +obj-$(CONFIG_PHY_MESON_G12A_MIPI_DPHY_ANALOG) += phy-meson-g12a-mipi-dphy-analog.o obj-$(CONFIG_PHY_MESON_AXG_PCIE) += phy-meson-axg-pcie.o obj-$(CONFIG_PHY_MESON_AXG_MIPI_PCIE_ANALOG) += phy-meson-axg-mipi-pcie-analog.o obj-$(CONFIG_PHY_MESON_AXG_MIPI_DPHY) += phy-meson-axg-mipi-dphy.o diff --git a/drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c b/drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c new file mode 100644 index 000000000000..6e9d416c0552 --- /dev/null +++ b/drivers/phy/amlogic/phy-meson-g12a-mipi-dphy-analog.c @@ -0,0 +1,177 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Meson G12A MIPI DSI Analog PHY + * + * Copyright (C) 2018 Amlogic, Inc. All rights reserved + * Copyright (C) 2020 BayLibre, SAS + * Author: Neil Armstrong + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define HHI_MIPI_CNTL0 0x00 +#define HHI_MIPI_CNTL0_DIF_REF_CTL1 GENMASK(31, 16) +#define HHI_MIPI_CNTL0_DIF_REF_CTL0 GENMASK(15, 0) + +#define HHI_MIPI_CNTL1 0x04 +#define HHI_MIPI_CNTL1_BANDGAP BIT(16) +#define HHI_MIPI_CNTL2_DIF_REF_CTL2 GENMASK(15, 0) + +#define HHI_MIPI_CNTL2 0x08 +#define HHI_MIPI_CNTL2_DIF_TX_CTL1 GENMASK(31, 16) +#define HHI_MIPI_CNTL2_CH_EN GENMASK(15, 11) +#define HHI_MIPI_CNTL2_DIF_TX_CTL0 GENMASK(10, 0) + +#define DSI_LANE_0 BIT(4) +#define DSI_LANE_1 BIT(3) +#define DSI_LANE_CLK BIT(2) +#define DSI_LANE_2 BIT(1) +#define DSI_LANE_3 BIT(0) + +struct phy_g12a_mipi_dphy_analog_priv { + struct phy *phy; + struct regmap *regmap; + struct phy_configure_opts_mipi_dphy config; +}; + +static int phy_g12a_mipi_dphy_analog_configure(struct phy *phy, + union phy_configure_opts *opts) +{ + struct phy_g12a_mipi_dphy_analog_priv *priv = phy_get_drvdata(phy); + int ret; + + ret = phy_mipi_dphy_config_validate(&opts->mipi_dphy); + if (ret) + return ret; + + memcpy(&priv->config, opts, sizeof(priv->config)); + + return 0; +} + +static int phy_g12a_mipi_dphy_analog_power_on(struct phy *phy) +{ + struct phy_g12a_mipi_dphy_analog_priv *priv = phy_get_drvdata(phy); + unsigned int reg; + + regmap_write(priv->regmap, HHI_MIPI_CNTL0, + FIELD_PREP(HHI_MIPI_CNTL0_DIF_REF_CTL0, 0x8) | + FIELD_PREP(HHI_MIPI_CNTL0_DIF_REF_CTL1, 0xa487)); + + regmap_write(priv->regmap, HHI_MIPI_CNTL1, + FIELD_PREP(HHI_MIPI_CNTL2_DIF_REF_CTL2, 0x2e) | + HHI_MIPI_CNTL1_BANDGAP); + + regmap_write(priv->regmap, HHI_MIPI_CNTL2, + FIELD_PREP(HHI_MIPI_CNTL2_DIF_TX_CTL0, 0x459) | + FIELD_PREP(HHI_MIPI_CNTL2_DIF_TX_CTL1, 0x2680)); + + reg = DSI_LANE_CLK; + switch (priv->config.lanes) { + case 4: + reg |= DSI_LANE_3; + fallthrough; + case 3: + reg |= DSI_LANE_2; + fallthrough; + case 2: + reg |= DSI_LANE_1; + fallthrough; + case 1: + reg |= DSI_LANE_0; + break; + default: + reg = 0; + } + + regmap_update_bits(priv->regmap, HHI_MIPI_CNTL2, + HHI_MIPI_CNTL2_CH_EN, + FIELD_PREP(HHI_MIPI_CNTL2_CH_EN, reg)); + + return 0; +} + +static int phy_g12a_mipi_dphy_analog_power_off(struct phy *phy) +{ + struct phy_g12a_mipi_dphy_analog_priv *priv = phy_get_drvdata(phy); + + regmap_write(priv->regmap, HHI_MIPI_CNTL0, 0); + regmap_write(priv->regmap, HHI_MIPI_CNTL1, 0); + regmap_write(priv->regmap, HHI_MIPI_CNTL2, 0); + + return 0; +} + +static const struct phy_ops phy_g12a_mipi_dphy_analog_ops = { + .configure = phy_g12a_mipi_dphy_analog_configure, + .power_on = phy_g12a_mipi_dphy_analog_power_on, + .power_off = phy_g12a_mipi_dphy_analog_power_off, + .owner = THIS_MODULE, +}; + +static int phy_g12a_mipi_dphy_analog_probe(struct platform_device *pdev) +{ + struct phy_provider *phy; + struct device *dev = &pdev->dev; + struct phy_g12a_mipi_dphy_analog_priv *priv; + struct device_node *np = dev->of_node; + struct regmap *map; + int ret; + + priv = devm_kmalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + /* Get the hhi system controller node */ + map = syscon_node_to_regmap(of_get_parent(dev->of_node)); + if (IS_ERR(map)) { + dev_err(dev, + "failed to get HHI regmap\n"); + return PTR_ERR(map); + } + + priv->regmap = map; + + priv->phy = devm_phy_create(dev, np, &phy_g12a_mipi_dphy_analog_ops); + if (IS_ERR(priv->phy)) { + ret = PTR_ERR(priv->phy); + if (ret != -EPROBE_DEFER) + dev_err(dev, "failed to create PHY\n"); + return ret; + } + + phy_set_drvdata(priv->phy, priv); + dev_set_drvdata(dev, priv); + + phy = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + + return PTR_ERR_OR_ZERO(phy); +} + +static const struct of_device_id phy_g12a_mipi_dphy_analog_of_match[] = { + { + .compatible = "amlogic,g12a-mipi-dphy-analog", + }, + { }, +}; +MODULE_DEVICE_TABLE(of, phy_g12a_mipi_dphy_analog_of_match); + +static struct platform_driver phy_g12a_mipi_dphy_analog_driver = { + .probe = phy_g12a_mipi_dphy_analog_probe, + .driver = { + .name = "phy-meson-g12a-mipi-dphy-analog", + .of_match_table = phy_g12a_mipi_dphy_analog_of_match, + }, +}; +module_platform_driver(phy_g12a_mipi_dphy_analog_driver); + +MODULE_AUTHOR("Neil Armstrong "); +MODULE_DESCRIPTION("Meson G12A MIPI Analog D-PHY driver"); +MODULE_LICENSE("GPL v2");