From patchwork Tue Apr 19 01:08:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Liu Ying X-Patchwork-Id: 12817194 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 6F56FC433F5 for ; Tue, 19 Apr 2022 01:07:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D120410E211; Tue, 19 Apr 2022 01:07:50 +0000 (UTC) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2083.outbound.protection.outlook.com [40.107.21.83]) by gabe.freedesktop.org (Postfix) with ESMTPS id 92EBD10E3A4 for ; Tue, 19 Apr 2022 01:07:48 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NlpaOwF5UM0UmcEdDf8E5f/q/Rj9jNKwseuEbfxfCuVbSV/ckd7EMF9m9bgCW556s64e9K1gdvDrNoHbQlY7meIyofyLTV+u3IvbGXBWWIROs3Kms3DdUC4PMvIs2gR83zF8ZcFD+9nGYqsMKAh599owEu7Kk6dTWI3VJguJhVQD409E84xDmt4Ko9zikCwo6rMekdZN8drznxoKWUGayysugiU2ZFVpniCc8TG2vr1RpZ76LhQ/ADH1HK40hZ+Xn+uP9jTmqdkuhjfW8EoIUGB1Ma8o+fdKuj4wXhS4tugeG52/StWr/8rsNp6ol3NgGaRbg5n+q93M+BwzBx5xVQ== 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=0L4vMIUf1mDanswpJo8fhPsQYyiOeSJQ+w6SBa7SJpo=; b=lF4H4NwcMeI4u1gdcgXrSLf5jlaJ9qAzfPDDpUP6SOuV7+xoCeZAkCHWfLjU8yEVqnjuZJeuyTYO68AWs1r6U4RPYW1pQAnov+LtYEdKFXP/8MD/g0EejGppWN7RJLIV4RAVR+3CnHQqSBLVtoIJc/uydIOL1gVUZ4jsfncT99X6KPDXOt8vgw0FNUTl1dYUaZm7yFYbk5zwqwt3sec4xovc7s4wGPIz9wDPSvTywWAJf/jn2lR08MwpsrsWLOXteBeswwZ5D24xfxVPASd69ZGh7vTKBljHKMPRmMPy5rpp4Qz3J26pedkkCgtwUV3IBiuYQpdktHtbGkJ7sNlvzQ== 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=0L4vMIUf1mDanswpJo8fhPsQYyiOeSJQ+w6SBa7SJpo=; b=AKLGjBRCSQ8cykmCCNyuQcOferAfDVjXwowzeFXGtD8b3p4qYFXMvz9ClwV88+3C5qTHh+e3bS12ulMY8JPFZQcztt0VWMPLfPQGengW7J8aJcedGw9Rg30sRsNOu0N66p5VoJT2wY4J9pj9UHHWSj6c3UN/5qKp0HZqkiV8zhU= 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 HE1PR04MB3291.eurprd04.prod.outlook.com (2603:10a6:7:18::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Tue, 19 Apr 2022 01:07:44 +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.5164.026; Tue, 19 Apr 2022 01:07:44 +0000 From: Liu Ying To: linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH resend v8 5/5] phy: freescale: phy-fsl-imx8-mipi-dphy: Add i.MX8qxp LVDS PHY mode support Date: Tue, 19 Apr 2022 09:08:52 +0800 Message-Id: <20220419010852.452169-6-victor.liu@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220419010852.452169-1-victor.liu@nxp.com> References: <20220419010852.452169-1-victor.liu@nxp.com> X-ClientProxiedBy: SI2P153CA0023.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::6) 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: 67e2d418-20ee-44ec-7d9d-08da21a1029d X-MS-TrafficTypeDiagnostic: HE1PR04MB3291: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: ciWidfrM60jLugOepyDo50oKsRxPwV03piEsDtIKK/I7pF7FtOwUSqJHJh/J1pqDDvgy7VWUCAUdpVRiJZW+aCQaqzwrZw4qvkDVkrj/5Sn4yt0v2IxE9nFqvXuXaVFgGxiHszI5kLOhLOsTbtZU6qXZwUlPZ3L9goIyDcSGiW3sCo8e/SnjFQq40U1PIhuGBfDof1yRtAu/X3+p6XBB0lzuwCJTgE6g7bA6QKVs8frcH1VE11iEgAFYbkcZg1g+nnkv9snilYlAshFc/9BCHlxZgE/truh+oncZFkCNXFatnqs7GXWeVRjbLpZQHVtE+pK22FybvjueoiSpjzMxAeorqLHHGBUtkCjNn6zT395gJlDejx91EUReS8uLiK5KXlfnITL4tIKEzmfAxs+nJIboQdWTOZ6Bo3/Epq1ASYUE7222rdfFkCS4ogPwVROnjaCHSyf5WibK2etZG2N0kZ21UDTeBOMYJaUa7h0wkHBGdE3zxJ8//Zi0REDisPBvFmCnYD1JKai7c5DRGIElYiEBcRKYeuN1/3sXI86C10vGypTfMGUasHLIlhrsoqbzv1ciFPn706IPtwYuBDdxtxwHVaU+ftOwXNdLvSDdYfJSQi1MHoFr1SXib6VO4wigwUJlPIWhk1fxzc4e9uF6LRm0FNAoeBHjEwIDezcz8+oxmPcUPtY5JM8Q7O+i4yXiqh5iNCdGu8+3TC/mNCrwgA== 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)(66946007)(508600001)(8676002)(4326008)(66574015)(86362001)(6486002)(36756003)(52116002)(6512007)(6506007)(6666004)(316002)(66556008)(66476007)(2906002)(26005)(186003)(83380400001)(2616005)(1076003)(5660300002)(30864003)(7416002)(8936002)(38100700002)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?cVitUYAZUFor7UWbliJBdYpC1fGl?= =?utf-8?q?RrO88e1g/MHA1AbIsPLlnQyQrYPhNWlPgURNJ7OZxk7KELaHxBsw1lDCJKfp2aNMQ?= =?utf-8?q?U3CPbQ0XhkFvEwrSkINJCv6VCKjmw5ThGmLJcKP2WVvgbBrS1YZo9t9LrVzkfboQm?= =?utf-8?q?onkBHQPvrW2xqLLBrZA0FiSBO0e1TiZ0e84nM5ano6jY7g0Bs2bOZd+VFteSKDFw+?= =?utf-8?q?SLzEIq99s5VgAXhhq2+EVjOQsaz2DSXFsCeJlLVWsC7MPSMxOujUHcDGV6kNsnq3Q?= =?utf-8?q?csh9inyeAWObGZa3/qChMvSejXFuAObX2BWEHBE6fh10I+dyU25ioQzSm/MjYkYqa?= =?utf-8?q?jsiKlDKedJWIZtAZp+QxPaf3CbeB56dLqRlu73izH1jZsaOFM75FWQftwJVYhQkwa?= =?utf-8?q?qC/qqK1tKFmjB3nhuFOivsjcKeBeHRk2DdUcq5a9NBX8WGcUiN1e9iUCtj1LhGd/w?= =?utf-8?q?x5hYT5RkR7CWRHH/YFUZoLGs+7XGyfd/zSYzbdiuUMzQG9Ar56Uaps6xSMT5fN8zW?= =?utf-8?q?wvcZKm5LfZNj0Uf2KC4QkNSuercxPnd8i3M190tDKYSOMKYlHSF9OFYbTyrfm7ZvM?= =?utf-8?q?ORPsMAk2o09vvsXuA8n5IpSgG/gq8e7oQcA8YN5rWe7A/4nZ6gSSWuXGIKfuQzyeh?= =?utf-8?q?FBoObkwGNBYMNdZ6sKWZbkLLkwehsFzHHKX18fQd3qPqhQr13DGEYVbI9LGe1W2b9?= =?utf-8?q?8/gBIWkTAnLLSkogTzWOJV2bnwV+yagojXc2UFfyN+ARNo5HYTPQI50LocFrO8Uhx?= =?utf-8?q?2e0/8EtRbk58kmuHsDZCu0FdzMWY+2/yWEqDr6C/eCDDBFCr5iWncEUwbFeiBgwzS?= =?utf-8?q?qamUy3jhnq5HjLdmqguiW9cZoXLfSQ6rrr09P/9bYS3fXpryB3nKVH9iH3OvTDK8P?= =?utf-8?q?s+rI4VXJQMWqFl9HOPy7Pw+y7dH5LvrY5oCaoa1o3lmwf2ttNVEOg4X1Q4Ike0cEP?= =?utf-8?q?yPhptdSkBjXSqNGWtvGCtmg1y6vfenquDYXPupFeboU6h/kyZ4Q2Fqj798bf76nBl?= =?utf-8?q?TSo6Ut0dB4ddSIpewSe9xuIujjnljqxiT4johDfV/kEcfk/okdiVLvWeAcwIQxVXK?= =?utf-8?q?f9VY1NGvkJHHMJIR5XBKgePfWz3fhsApenKpjfJ0cWaAERUot10CB/DP1KqbQ1p3c?= =?utf-8?q?lLleVIXmghTyKGacVcgk/OuSMmhMvZJdl5toDHFnHk/6WmauBxqaLies33HO9VT+w?= =?utf-8?q?T9eBcMTkre/tbFtr0SICot2qPORdmmpPlInu2uUWR49e1+WDsdb351E5ktxB3VxHR?= =?utf-8?q?72RdUgICr8I7oSFls31YwWyZwnkkHpWFOElmDnzOx/+5s5G1wvcpbY7sZFyjFK1U8?= =?utf-8?q?yTE9osA6G2IUvUA5LrKUS7JRxz696AISfpJ8HR2PAfl+kMps3ktwZd35HCfOdJKf4?= =?utf-8?q?HHJq0r3S1+rOjevFWDIfALHEXtcInt4yRyXYq6rCrNzla9+E9B2OxKkWlTgpTlnuC?= =?utf-8?q?Wu8ZH8NHQXyQupD7agMfVXMXwII9URZsQgrDDu2XULg8+MB8OEW2rBbAuTPyIwQbn?= =?utf-8?q?Gvot8NXNmPSw9rzrzOy6YGSI5+9yDW4/2iqgN76o8cb84XgJHtIcnw4lCfjT7oStR?= =?utf-8?q?66brn5Mw4JJuGqnlrF3d++tGAJ5ggMFDJjAk8S3cnDkbunofD2HZSPz69S2UdISrS?= =?utf-8?q?+fMuV59E8021MctQGHBDWkjJZZpkAQ1g=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 67e2d418-20ee-44ec-7d9d-08da21a1029d X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7046.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2022 01:07:44.6028 (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: e6ftR+U61Br4/ygrcJ3uvkVZoeGHy5BDRhtV4RJKZn1uROFdy8nAwikEFMjvRH/JKkT15b1o292NPZZABoxc5A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR04MB3291 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: martin.kepplinger@puri.sm, agx@sigxcpu.org, jernej.skrabec@gmail.com, narmstrong@baylibre.com, airlied@linux.ie, s.hauer@pengutronix.de, jonas@kwiboo.se, robert.foss@linaro.org, kishon@ti.com, vkoul@kernel.org, robh+dt@kernel.org, Laurent.pinchart@ideasonboard.com, andrzej.hajda@intel.com, robert.chiras@nxp.com, krzk+dt@kernel.org, shawnguo@kernel.org, kernel@pengutronix.de, linux-imx@nxp.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 --- v7->v8: * No change. v6->v7: * Use marco instead of magic number for CCM and CA values. * Suppress 'checkpatch --strict' warnings. * Check !opts in mixel_dphy_configure(). 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 | 276 +++++++++++++++++- 1 file changed, 265 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..e625b32889bf 100644 --- a/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c +++ b/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c @@ -4,17 +4,33 @@ * 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 CCM_1_2V 0x5 +#define CA_MASK GENMASK(4, 2) +#define CA_3_51MA 0x4 +#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 +71,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 +88,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 +98,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 +123,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 +349,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 +378,126 @@ 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(CCM_1_2V) | CA(CA_3_51MA) | 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 (!opts) { + dev_err(&phy->dev, "No configuration options\n"); + return -EINVAL; + } + + 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 +517,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 +598,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 +651,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 +665,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 +697,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);