From patchwork Sat Apr 2 05:24:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Liu Ying X-Patchwork-Id: 12798989 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 B89B1C433F5 for ; Sat, 2 Apr 2022 05:38:56 +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=cgZm9NFlXy/fnG1BTXkevVWNXO4XrXy8aWS53QfrzS4=; b=PZMavbI7BSh0H5 Kj4B1TJWScRx/6+8GaKX9UAkAaJIlOqd0z1O8Al5Ra/fMsmg5TKhj/G5SsvnPimRlStErCkeano4w H6hbeXkoHXhkSSfRBB9ShEEWA2ocCNexYSA9qzqJaGg8vRcNa1VAsNOHFkOwMtIIaqEtiJeu1fOX7 tYCihRlF/3r9ZaX2yHlUo/GLW8SE0IMzSFf9lfBgW2uQHXRwd4lc/z2JwndFrc7/7pzDwrO5cDZdU vm/v3k+x6b3kuOQUi+5HuFQlWQO991Z1JHJ7UHvDGF+WSDDLh9oiE60HBFOG4buJV1S4Kx878Knoz E4focJhAKL9uhQa/Lk/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1naWTQ-0087IA-4Y; Sat, 02 Apr 2022 05:38:56 +0000 Received: from mail-he1eur01on062b.outbound.protection.outlook.com ([2a01:111:f400:fe1e::62b] helo=EUR01-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1naWTM-0087HY-He; Sat, 02 Apr 2022 05:38:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bI1v0qaM3KhgOKCX28Psb5jHBtW+EdJzfAuUyVCXz+TyXJwadZVOLpXOH0j817fnuGEqeoE3/zgRhn1DPIAFku9MxOp+fdu5PsDniz0oC6ECZvhQjjo71omYQnN5j+eesP27omhKNaTzkPBzG+puajaUoUAG6tRqfJ4h59g9OSZuvBYWEfjmVYs5lrJGDnwjdg5SDcMRyAEWCug1H2PZpJ6B4EPcE/LJfBzYf4Ou1frkZE6fH35sBkW71Z8GikupJ7yyTMphkt8RO3jNoGQ0WSfiQi1BTSBRHq6gvGwPGVrEDEm5PVr5lHaSBk7iKEIUOt4czCxTjkZh1Ko9KdwewQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=z23oGthQQVatgNiHhq/oRsg65W52HNMSx8ap0xPZR4U=; b=S+Ea326d8hh3h8ZVewqHqb41v7kZX/rv5VkeldgeVPJd8WVvNeBW+BYc0Y6fPggLgFzYjg3zBBBac/zI7LmbB4g5+hVnesF9tq45FpNKZHa0h5tcjQYXGe4Y7aTVmLriCaOEecck3iDf1m/GFPLFH6GnvmQCJjX4Twqg9qEUsFqBfJERWgCLpeXfaeYVt/ZReZoFcxtHKaJeh6cr1CayP7LoJdu2ZD7lBOrlYGy8ldZgvBFaXlxvmSvcd/1Me2ilYv4cuOTDy5xUFI9IbofpjHj0i5iBC++1S8FtqEKA9su0w8d4My9rExh6qx+OeUOpuHbmo932NSPs/NBhDU+Z3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=z23oGthQQVatgNiHhq/oRsg65W52HNMSx8ap0xPZR4U=; b=lzgjOlFackcCQE1NQ+ktGzjsEFA77B/55cIqZVL1PWO93dK5ri3PTJeeGNdTqhaulG/UdMwVMVS76ICQnt3GcwB1X340afbWSTdpgTPwT6lTcOOGfyzsfUR9AWpDtm5XuCYUvGgZVKEwPwhPOhYZBy0+9Rdw/FZKHGTGWy5f3WQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7046.eurprd04.prod.outlook.com (2603:10a6:20b:113::22) by AM7PR04MB6776.eurprd04.prod.outlook.com (2603:10a6:20b:103::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.25; Sat, 2 Apr 2022 05:23:50 +0000 Received: from AM7PR04MB7046.eurprd04.prod.outlook.com ([fe80::b09c:8ffe:8e02:7387]) by AM7PR04MB7046.eurprd04.prod.outlook.com ([fe80::b09c:8ffe:8e02:7387%9]) with mapi id 15.20.5123.030; Sat, 2 Apr 2022 05:23:50 +0000 From: Liu Ying To: linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org Cc: kishon@ti.com, vkoul@kernel.org, robh+dt@kernel.org, andrzej.hajda@intel.com, narmstrong@baylibre.com, Laurent.pinchart@ideasonboard.com, jonas@kwiboo.se, jernej.skrabec@gmail.com, airlied@linux.ie, daniel@ffwll.ch, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, agx@sigxcpu.org, robert.chiras@nxp.com, martin.kepplinger@puri.sm, robert.foss@linaro.org Subject: [PATCH v6 resend 5/5] phy: freescale: phy-fsl-imx8-mipi-dphy: Add i.MX8qxp LVDS PHY mode support Date: Sat, 2 Apr 2022 13:24:51 +0800 Message-Id: <20220402052451.2517469-6-victor.liu@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220402052451.2517469-1-victor.liu@nxp.com> References: <20220402052451.2517469-1-victor.liu@nxp.com> X-ClientProxiedBy: SI2P153CA0008.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::19) To AM7PR04MB7046.eurprd04.prod.outlook.com (2603:10a6:20b:113::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f17bc912-c9ad-4142-b3b3-08da1468f86c X-MS-TrafficTypeDiagnostic: AM7PR04MB6776:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: A/KZ0eYp2tS5elt5hPBQC6Tdhfx+a0NbRx1K1oNfeC+EyafljFkpfxRbWuhIozO2OOoppgR3A5moYC12Ce5whUhk5J+h90aWVQNKih//eQUbdyCdbWkBbRH4rJHLShh8CfITEbWerrG581JY6nreZxA8JEU77aY3UkqAK2aS/yqTq8qrOt1pccUJO451vAI3L7sz7srlitsptwTzsRfS97nGkIc3uetyaKRdj98xs0Gyy/KGYch27pT0LjLe9bDKOkcYcU6XKU9H/pg5Z1dy6SjV0upDarKRO+ysEFHj0meIxyUff5EBLGIQjAS9yDZSiOZKCxPuPcOeRpixldwouOan+MNMeZ5585v3n5s+xtiZCmSLORwOoFzCoWUAyyqt1Z37gwMZQN2f1FDu+EaLJDg+/Zp0aBv7YMYZ8tJt56NjB2fhLwCoqBAlrvRXVgEXJIUadXogFcoaiXgGhSOupbuS6LH7BMDfXjmccPT0+cM2Qvocp7WuRC/9bWuVejksZkK8M8I8g0plp7BgQpKREKx3EJxOSD700u3V75KWtbIVDc8oLKRANMIQbPhHRh5bzd8FcRmZJRJYcAbIQQJbBa3DLHgTwD41n/9cQgBpaQ4+eAK3ksZrTJVKvMSFnR85j+gegk5lGBgDuTRwiPGVJ/9NCbUnhLUCKXGaH1x0qGir/BsQDKpOZQrS41agaEKZwi3W40b8+xddRmDmM1OrkA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR04MB7046.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(1076003)(30864003)(8936002)(7416002)(186003)(66556008)(26005)(2616005)(316002)(66946007)(8676002)(66476007)(5660300002)(4326008)(86362001)(66574015)(83380400001)(36756003)(2906002)(52116002)(6486002)(508600001)(38350700002)(6512007)(38100700002)(6506007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?4vu8dIN5iKM9XD1bPHWWdukU1RIV?= =?utf-8?q?UkPSuCVzFFm1bwjfrwvvLLP68Nwgund1Vr+Fu46QO1kb78/ELwPgzgVTwOBN5HLee?= =?utf-8?q?DkoJopy4XgLaNCv78C+YoNqwEzz63Pj0ejJOMLzYbijEiyy89TfQ3iq/OXEan0Aua?= =?utf-8?q?YKKmWEbyfKveCP/h2NHP64bFyxwzGi2h77JWh76qo9cKGkc+USN6STB1wVqWQPg+8?= =?utf-8?q?R99EFX1nQUS+IbJAP1yGgarf1jbPL+WVhc7jGknnjIB+oq+5k2V0m3H9fex+BTRRz?= =?utf-8?q?ILkXHHOEHABFHG8BqPuabmpPD1fAc8W6KG+eTQRYrV8mkinFo7WKFHhq1GHF4MGuH?= =?utf-8?q?r0h+PJM8KInwbksouThTkybtWGwsvBEUULnrRUH5lbo39CNwU1vwGyFXnBfK55zmT?= =?utf-8?q?MyyrxP2oy38zuzwv9EEsieXYJ3zJn3Qxrry32rXVDKeAwGAnRceRg5EPFHDQjasSU?= =?utf-8?q?796IOUCqv6ik2JQlzmFuqtAWlEksrr2bH59DLedX4XpPEakZOTy/5vniD7HmRyZsO?= =?utf-8?q?zz1L4ri7qNfmoPEOfYbmupEr1D5Idwc5EFUul8VQgAMgAstDiYlJQ2HbrYE+XlYQn?= =?utf-8?q?JyVqmlfBKydNOOLUx0J0KDsmbM206Pd04CxQky94pgIZG32uCTO4bUHS1YXYvCtEz?= =?utf-8?q?GB953rtmX0iATYKXMFeyoANGhLNx+3qIDkzWxtUqew7V1vZ86R7ZYOz21FfbB1axf?= =?utf-8?q?ImXXDg2CR2kILkKe9sAm5CguDfwSib/Iwy1OeQ1pYtcSy06l7+hT6tnBKOdHLgVsk?= =?utf-8?q?N4uwbD/KqWKwXW6NsTUUGbWHoo55VuMJB4vopGodOeg+FB5FGYGdZMdTnhlUKB705?= =?utf-8?q?6hzCr6IE0TFBw7RCCewFHBLG+qjtIYDE8XIgQKv38Ye+DErLEVMFHQsWlhdlVajAb?= =?utf-8?q?2tx4jggcn6v+CAh9BKyppLWmdFYPL5CRag/lakPxQXmHbTwvGfPhSCnL7mT6bYR6T?= =?utf-8?q?Ci2XyHCJKXRNmSDa3w82PHBeiF9KZNELK+AC7NVzb46wc6pYHaM0VXqI0A99kdguo?= =?utf-8?q?BwInXm/SZukzQ/PycXFsvtmBZwdrJGw2S5u3lpmgyJSELMWLNxA8pne8LYALvQLtj?= =?utf-8?q?tl9pz/wbOfjY5uVuXe4Eh7s5vs9eLMv8uj3XYbO8WmUPeIyQqSFxVde+r5WkgZDXo?= =?utf-8?q?4a8ftMIGk5hh0IJySVQb+yi5J4ahWEhQRpZVNoaOK4pViTt6GlgD0jEAP4OQbz6tm?= =?utf-8?q?hUVidZdHUxJyFfvxUehfwBr4gV2UfyZ6HpwtA38+JCW5yabDR/xO2AG7obti1c7JQ?= =?utf-8?q?sw8tG3kFAgWks1yvUO0pEiDII72hE4mJq9KAerE4LV15/YIkZ/M4RiQ0vde+++Ru8?= =?utf-8?q?7BwtxJsZ3fTufvBp3lx2691kSNbOoy1MGNNpCTzKcRutqTQedo7S7C6NJ+Ba5OomD?= =?utf-8?q?Vrgh+LSP71OaY09e1m4dB5j7iDBylD75dQxmmtK53TxP7PKpp1BVjD15r5lnCNJyR?= =?utf-8?q?lHGJnmFkZ70FnTno1/2PcWXQfPzytVhM8LgBQh+Vb4gnEEBixW58WDbhHMiGf/peu?= =?utf-8?q?Cn19PyJsqmxo4F3V4e8EUUNybexhpAizsC0y51V80+E+b9AkYyWGeshgZmSYtwVb3?= =?utf-8?q?p4acpWnx0oeF3hoWzfMHiBheUIgruc+ipSBcN1rXheOM9VYDlYtUXr3cPZ1KDb0dg?= =?utf-8?q?NNJwUtPUgGL3+dz0fKWZYwMOdnoiI8+A=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f17bc912-c9ad-4142-b3b3-08da1468f86c X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7046.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2022 05:23:50.6186 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zO3k9VOd1Qc+5c7RLDars4IDWhJ7gVJSTdcZMNz2lmZ6SBmGotfyb19GgifEsDCzDHrj4aN5A0wyPU59CDvQKQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB6776 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220401_223852_790916_62DD9370 X-CRM114-Status: GOOD ( 21.90 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org i.MX8qxp SoC embeds a Mixel MIPI DPHY + LVDS PHY combo which supports either a MIPI DSI display or a LVDS display. The PHY mode is controlled by SCU firmware and the driver would call a SCU firmware function to configure the PHY mode. The single LVDS PHY has 4 data lanes to support a LVDS display. Also, with a master LVDS PHY and a slave LVDS PHY, they may work together to support a LVDS display with 8 data lanes(usually, dual LVDS link display). Note that this patch supports the LVDS PHY mode only for the i.MX8qxp Mixel combo PHY, i.e., the MIPI DPHY mode is yet to be supported, so for now error would be returned from ->set_mode() if MIPI DPHY mode is passed over to it for the combo PHY. Cc: Guido Günther Cc: Robert Chiras Cc: Kishon Vijay Abraham I Cc: Vinod Koul Cc: Shawn Guo Cc: Sascha Hauer Cc: Pengutronix Kernel Team Cc: Fabio Estevam Cc: NXP Linux Team Reviewed-by: Guido Günther Signed-off-by: Liu Ying --- v5->v6: * No change. v4->v5: * No change. v3->v4: * Add Guido's R-b tag. v2->v3: * Improve readability of mixel_dphy_set_mode(). (Guido) v1->v2: * Print invalid PHY mode in dmesg. (Guido) .../phy/freescale/phy-fsl-imx8-mipi-dphy.c | 269 +++++++++++++++++- 1 file changed, 258 insertions(+), 11 deletions(-) diff --git a/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c b/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c index a95572b397ca..af1ecda091c7 100644 --- a/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c +++ b/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c @@ -4,17 +4,31 @@ * Copyright 2019 Purism SPC */ +#include #include #include #include +#include +#include #include #include +#include #include #include #include #include #include #include +#include + +/* Control and Status Registers(CSR) */ +#define PHY_CTRL 0x00 +#define CCM_MASK GENMASK(7, 5) +#define CCM(n) FIELD_PREP(CCM_MASK, (n)) +#define CA_MASK GENMASK(4, 2) +#define CA(n) FIELD_PREP(CA_MASK, (n)) +#define RFB BIT(1) +#define LVDS_EN BIT(0) /* DPHY registers */ #define DPHY_PD_DPHY 0x00 @@ -55,8 +69,15 @@ #define PWR_ON 0 #define PWR_OFF 1 +#define MIN_VCO_FREQ 640000000 +#define MAX_VCO_FREQ 1500000000 + +#define MIN_LVDS_REFCLK_FREQ 24000000 +#define MAX_LVDS_REFCLK_FREQ 150000000 + enum mixel_dphy_devtype { MIXEL_IMX8MQ, + MIXEL_IMX8QXP, }; struct mixel_dphy_devdata { @@ -65,6 +86,7 @@ struct mixel_dphy_devdata { u8 reg_rxlprp; u8 reg_rxcdrp; u8 reg_rxhs_settle; + bool is_combo; /* MIPI DPHY and LVDS PHY combo */ }; static const struct mixel_dphy_devdata mixel_dphy_devdata[] = { @@ -74,6 +96,10 @@ static const struct mixel_dphy_devdata mixel_dphy_devdata[] = { .reg_rxlprp = 0x40, .reg_rxcdrp = 0x44, .reg_rxhs_settle = 0x48, + .is_combo = false, + }, + [MIXEL_IMX8QXP] = { + .is_combo = true, }, }; @@ -95,8 +121,12 @@ struct mixel_dphy_cfg { struct mixel_dphy_priv { struct mixel_dphy_cfg cfg; struct regmap *regmap; + struct regmap *lvds_regmap; struct clk *phy_ref_clk; const struct mixel_dphy_devdata *devdata; + struct imx_sc_ipc *ipc_handle; + bool is_slave; + int id; }; static const struct regmap_config mixel_dphy_regmap_config = { @@ -317,7 +347,8 @@ static int mixel_dphy_set_pll_params(struct phy *phy) return 0; } -static int mixel_dphy_configure(struct phy *phy, union phy_configure_opts *opts) +static int +mixel_dphy_configure_mipi_dphy(struct phy *phy, union phy_configure_opts *opts) { struct mixel_dphy_priv *priv = phy_get_drvdata(phy); struct mixel_dphy_cfg cfg = { 0 }; @@ -345,15 +376,121 @@ static int mixel_dphy_configure(struct phy *phy, union phy_configure_opts *opts) return 0; } +static int +mixel_dphy_configure_lvds_phy(struct phy *phy, union phy_configure_opts *opts) +{ + struct mixel_dphy_priv *priv = phy_get_drvdata(phy); + struct phy_configure_opts_lvds *lvds_opts = &opts->lvds; + unsigned long data_rate; + unsigned long fvco; + u32 rsc; + u32 co; + int ret; + + priv->is_slave = lvds_opts->is_slave; + + /* LVDS interface pins */ + regmap_write(priv->lvds_regmap, PHY_CTRL, CCM(0x5) | CA(0x4) | RFB); + + /* enable MODE8 only for slave LVDS PHY */ + rsc = priv->id ? IMX_SC_R_MIPI_1 : IMX_SC_R_MIPI_0; + ret = imx_sc_misc_set_control(priv->ipc_handle, rsc, IMX_SC_C_DUAL_MODE, + lvds_opts->is_slave); + if (ret) { + dev_err(&phy->dev, "Failed to configure MODE8: %d\n", ret); + return ret; + } + + /* + * Choose an appropriate divider ratio to meet the requirement of + * PLL VCO frequency range. + * + * ----- 640MHz ~ 1500MHz ------------ --------------- + * | VCO | ----------------> | CO divider | -> | LVDS data rate| + * ----- FVCO ------------ --------------- + * 1/2/4/8 div 7 * differential_clk_rate + */ + data_rate = 7 * lvds_opts->differential_clk_rate; + for (co = 1; co <= 8; co *= 2) { + fvco = data_rate * co; + + if (fvco >= MIN_VCO_FREQ) + break; + } + + if (fvco < MIN_VCO_FREQ || fvco > MAX_VCO_FREQ) { + dev_err(&phy->dev, "VCO frequency %lu is out of range\n", fvco); + return -ERANGE; + } + + /* + * CO is configurable, while CN and CM are not, + * as fixed ratios 1 and 7 are applied respectively. + */ + phy_write(phy, __ffs(co), DPHY_CO); + + /* set reference clock rate */ + clk_set_rate(priv->phy_ref_clk, lvds_opts->differential_clk_rate); + + return ret; +} + +static int mixel_dphy_configure(struct phy *phy, union phy_configure_opts *opts) +{ + if (phy->attrs.mode == PHY_MODE_MIPI_DPHY) + return mixel_dphy_configure_mipi_dphy(phy, opts); + else if (phy->attrs.mode == PHY_MODE_LVDS) + return mixel_dphy_configure_lvds_phy(phy, opts); + + dev_err(&phy->dev, + "Failed to configure PHY with invalid PHY mode: %d\n", + phy->attrs.mode); + return -EINVAL; +} + +static int +mixel_dphy_validate_lvds_phy(struct phy *phy, union phy_configure_opts *opts) +{ + struct phy_configure_opts_lvds *lvds_cfg = &opts->lvds; + + if (lvds_cfg->bits_per_lane_and_dclk_cycle != 7) { + dev_err(&phy->dev, "Invalid bits per LVDS data lane: %u\n", + lvds_cfg->bits_per_lane_and_dclk_cycle); + return -EINVAL; + } + + if (lvds_cfg->lanes != 4) { + dev_err(&phy->dev, "Invalid LVDS data lanes: %u\n", + lvds_cfg->lanes); + return -EINVAL; + } + + if (lvds_cfg->differential_clk_rate < MIN_LVDS_REFCLK_FREQ || + lvds_cfg->differential_clk_rate > MAX_LVDS_REFCLK_FREQ) { + dev_err(&phy->dev, + "Invalid LVDS differential clock rate: %lu\n", + lvds_cfg->differential_clk_rate); + return -EINVAL; + } + + return 0; +} + static int mixel_dphy_validate(struct phy *phy, enum phy_mode mode, int submode, union phy_configure_opts *opts) { - struct mixel_dphy_cfg cfg = { 0 }; + if (mode == PHY_MODE_MIPI_DPHY) { + struct mixel_dphy_cfg mipi_dphy_cfg = { 0 }; - if (mode != PHY_MODE_MIPI_DPHY) - return -EINVAL; + return mixel_dphy_config_from_opts(phy, &opts->mipi_dphy, + &mipi_dphy_cfg); + } else if (mode == PHY_MODE_LVDS) { + return mixel_dphy_validate_lvds_phy(phy, opts); + } - return mixel_dphy_config_from_opts(phy, &opts->mipi_dphy, &cfg); + dev_err(&phy->dev, + "Failed to validate PHY with invalid PHY mode: %d\n", mode); + return -EINVAL; } static int mixel_dphy_init(struct phy *phy) @@ -373,26 +510,74 @@ static int mixel_dphy_exit(struct phy *phy) return 0; } -static int mixel_dphy_power_on(struct phy *phy) +static int mixel_dphy_power_on_mipi_dphy(struct phy *phy) { struct mixel_dphy_priv *priv = phy_get_drvdata(phy); u32 locked; int ret; - ret = clk_prepare_enable(priv->phy_ref_clk); - if (ret < 0) - return ret; - phy_write(phy, PWR_ON, DPHY_PD_PLL); ret = regmap_read_poll_timeout(priv->regmap, DPHY_LOCK, locked, locked, PLL_LOCK_SLEEP, PLL_LOCK_TIMEOUT); if (ret < 0) { dev_err(&phy->dev, "Could not get DPHY lock (%d)!\n", ret); - goto clock_disable; + return ret; } phy_write(phy, PWR_ON, DPHY_PD_DPHY); + return 0; +} + +static int mixel_dphy_power_on_lvds_phy(struct phy *phy) +{ + struct mixel_dphy_priv *priv = phy_get_drvdata(phy); + u32 locked; + int ret; + + regmap_update_bits(priv->lvds_regmap, PHY_CTRL, LVDS_EN, LVDS_EN); + + phy_write(phy, PWR_ON, DPHY_PD_DPHY); + phy_write(phy, PWR_ON, DPHY_PD_PLL); + + /* do not wait for slave LVDS PHY being locked */ + if (priv->is_slave) + return 0; + + ret = regmap_read_poll_timeout(priv->regmap, DPHY_LOCK, locked, + locked, PLL_LOCK_SLEEP, + PLL_LOCK_TIMEOUT); + if (ret < 0) { + dev_err(&phy->dev, "Could not get LVDS PHY lock (%d)!\n", ret); + return ret; + } + + return 0; +} + +static int mixel_dphy_power_on(struct phy *phy) +{ + struct mixel_dphy_priv *priv = phy_get_drvdata(phy); + int ret; + + ret = clk_prepare_enable(priv->phy_ref_clk); + if (ret < 0) + return ret; + + if (phy->attrs.mode == PHY_MODE_MIPI_DPHY) { + ret = mixel_dphy_power_on_mipi_dphy(phy); + } else if (phy->attrs.mode == PHY_MODE_LVDS) { + ret = mixel_dphy_power_on_lvds_phy(phy); + } else { + dev_err(&phy->dev, + "Failed to power on PHY with invalid PHY mode: %d\n", + phy->attrs.mode); + ret = -EINVAL; + } + + if (ret) + goto clock_disable; + return 0; clock_disable: clk_disable_unprepare(priv->phy_ref_clk); @@ -406,16 +591,51 @@ static int mixel_dphy_power_off(struct phy *phy) phy_write(phy, PWR_OFF, DPHY_PD_PLL); phy_write(phy, PWR_OFF, DPHY_PD_DPHY); + if (phy->attrs.mode == PHY_MODE_LVDS) + regmap_update_bits(priv->lvds_regmap, PHY_CTRL, LVDS_EN, 0); + clk_disable_unprepare(priv->phy_ref_clk); return 0; } +static int mixel_dphy_set_mode(struct phy *phy, enum phy_mode mode, int submode) +{ + struct mixel_dphy_priv *priv = phy_get_drvdata(phy); + int ret; + + if (priv->devdata->is_combo && mode != PHY_MODE_LVDS) { + dev_err(&phy->dev, "Failed to set PHY mode for combo PHY\n"); + return -EINVAL; + } + + if (!priv->devdata->is_combo && mode != PHY_MODE_MIPI_DPHY) { + dev_err(&phy->dev, "Failed to set PHY mode to MIPI DPHY\n"); + return -EINVAL; + } + + if (priv->devdata->is_combo) { + u32 rsc = priv->id ? IMX_SC_R_MIPI_1 : IMX_SC_R_MIPI_0; + + ret = imx_sc_misc_set_control(priv->ipc_handle, + rsc, IMX_SC_C_MODE, + mode == PHY_MODE_LVDS); + if (ret) { + dev_err(&phy->dev, + "Failed to set PHY mode via SCU ipc: %d\n", ret); + return ret; + } + } + + return 0; +} + static const struct phy_ops mixel_dphy_phy_ops = { .init = mixel_dphy_init, .exit = mixel_dphy_exit, .power_on = mixel_dphy_power_on, .power_off = mixel_dphy_power_off, + .set_mode = mixel_dphy_set_mode, .configure = mixel_dphy_configure, .validate = mixel_dphy_validate, .owner = THIS_MODULE, @@ -424,6 +644,8 @@ static const struct phy_ops mixel_dphy_phy_ops = { static const struct of_device_id mixel_dphy_of_match[] = { { .compatible = "fsl,imx8mq-mipi-dphy", .data = &mixel_dphy_devdata[MIXEL_IMX8MQ] }, + { .compatible = "fsl,imx8qxp-mipi-dphy", + .data = &mixel_dphy_devdata[MIXEL_IMX8QXP] }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(of, mixel_dphy_of_match); @@ -436,6 +658,7 @@ static int mixel_dphy_probe(struct platform_device *pdev) struct mixel_dphy_priv *priv; struct phy *phy; void __iomem *base; + int ret; if (!np) return -ENODEV; @@ -467,6 +690,30 @@ static int mixel_dphy_probe(struct platform_device *pdev) dev_dbg(dev, "phy_ref clock rate: %lu\n", clk_get_rate(priv->phy_ref_clk)); + if (priv->devdata->is_combo) { + priv->lvds_regmap = + syscon_regmap_lookup_by_phandle(np, "fsl,syscon"); + if (IS_ERR(priv->lvds_regmap)) { + ret = PTR_ERR(priv->lvds_regmap); + dev_err_probe(dev, ret, "Failed to get LVDS regmap\n"); + return ret; + } + + priv->id = of_alias_get_id(np, "mipi_dphy"); + if (priv->id < 0) { + dev_err(dev, "Failed to get phy node alias id: %d\n", + priv->id); + return priv->id; + } + + ret = imx_scu_get_handle(&priv->ipc_handle); + if (ret) { + dev_err_probe(dev, ret, + "Failed to get SCU ipc handle\n"); + return ret; + } + } + dev_set_drvdata(dev, priv); phy = devm_phy_create(dev, np, &mixel_dphy_phy_ops);