From mboxrd@z Thu Jan 1 00:00:00 1970 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 D5E361088E70 for ; Thu, 19 Mar 2026 03:48:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2702310E87C; Thu, 19 Mar 2026 03:48:42 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.b="gNFIUstj"; dkim=pass (2048-bit key; unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="GQ/bip5t"; dkim-atps=neutral Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8E15410E876 for ; Thu, 19 Mar 2026 03:48:38 +0000 (UTC) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62J3Vh2c3228348 for ; Thu, 19 Mar 2026 03:48:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= wDBPPvYq2j/jCgog8uT3xSk3NYgGgEFWNJmXZ+Bx7qg=; b=gNFIUstjYrJyYZQg qnELYtIDLEte8PEbyjWMr4lLUsdeIAlORlUlDb7pGc3NtBB6L3/zVbFTpLsd7CJD 2pDKMTl6KjLwhPSZSQogWn63uJxIDCwQwuqIH81eK/1fw9s06faAocqC+wQi2UCS DBj3P0n239GQQ3zyZwJDDHaWQtH7g8RhOOfsXkv/lIDwYCDk1rUTqydcPgeTZnXt J5/RnO1sFHYKAGpAqS9W4l1phTaYt26NSCnbxgZRQNUbQbF7RxPLr6Q5VOee+qLu jjLT8X+6tSodlKwWSBcPO8G/Y9Y+s+1GT4X5CIs6fwktypmDELmSyLA1tKT/Z/l2 jpLa/w== Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4d00eg9n6v-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 19 Mar 2026 03:48:38 +0000 (GMT) Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-5093787e2fdso71041211cf.2 for ; Wed, 18 Mar 2026 20:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1773892117; x=1774496917; darn=lists.freedesktop.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=wDBPPvYq2j/jCgog8uT3xSk3NYgGgEFWNJmXZ+Bx7qg=; b=GQ/bip5tkX+ReMV44UucHz4TAk08Ji+OslrVkb6V0DonUZfkuZn95XrplFTOjhcR/J 3WaJW/NuxWvWSF9w9wFUIAd/uU2PavfLSfQJVKYZWVd5RgaXIA/M9Z8glLatmwNXcbwe cKO4aRjyg87y6wcTaHpKgW7s2o9D8uyjuM6poHOX8aqheFzQr2RLKw1HyIB+/ZueArMs kQLadY6/SXPw8HSiKMNLuCOpTULemb0itwfWwny5Eq/5eB2Mfkkydg891k8I0McbgMtz nU9hQqxOXIeMs6iu3aH51RpWpsw+ujA3nBgK8QZOVduxBA3B9t8Lad4HPVoJy/aEe/4b QytQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773892117; x=1774496917; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=wDBPPvYq2j/jCgog8uT3xSk3NYgGgEFWNJmXZ+Bx7qg=; b=MdbxRKVvMQ+hf6SAyssHenbeRYxpWoS6ChfDnMlGiw49qs0q8ypzVACdZLsxewAbLA dzw8OTMf6VPlWu/1JsK+eeDN54+pbmvcdpCcNQki4IG/aTsEt5lxhAKSnHD5AX/dcqKw B2QtYS5k/OGa3WGVJE2g4nLPR1qyXiHklakwI2E9XlvXE0jcvOcCMMOfq6C4BOt7zplv CDNJETr25cINLngh4Yx6YgKutJUghXzWl0YBBxEBOhOiYK14qWC5cvFaEwQAFkAVozWF KGtSo2YXbf11BxQ3r3WEx0be0ObNssyNV8X7wkaCYwq/nX2Qe9aIfF3NrNGddl7PqQVg qOJw== X-Forwarded-Encrypted: i=1; AJvYcCWm8UMTCbsVRqAfRZYWRBf750vsXlEWRdBXGmpG+yjRuoirN4AJFxTs2hIDd0rPbf+jxA22jsFXh24=@lists.freedesktop.org X-Gm-Message-State: AOJu0YxCZC/45nf6urS2VEbnRVQjKNFcPInsr/AKZH6Q4m7sGOwjLZSm TJcYwhVtG8GL0uE2RPvhwbEeY5Z45uGxIGPAjqOiXeNEW6P5d+ksGSrGKx9uDPqxcO6TUabu6ub ehOjbLLqe4QCuul4OMOtI/0hJjXaZ0p6hM8BBgvMTutSc+8JVlcZtSDEeIXIQvR+Btrfh4I0= X-Gm-Gg: ATEYQzwSwwMSg20hH8JeLXoNZIFd8o4/9q7XwQ/dSwwFcyt58KGyS03GMkNXWcrwMeQ 2/5geEkT1dvSYBlK1LhBrxV0Qhwmz4o2Ps3cBgOzPgFLa5uVs8655kaM4wpM4vq4qYhKe20xvOb LP6XOW3TmBnvTm0btbDRyA0j2tGuKeHwYyL1R82l2Zy/vokIXHpRgefEnbASUlkKpkgH7wO4xe1 lQWpFeMPgWgX6gzepsOJFKWJs5X1ErxUokO+g6vG1Wp+jwUdX0tFjQG4ke3GXl1NiZLCcbskjzz ffcr07Z22XNmqsZGJnfZInB8ey/EPyANRxYbJE1/us48i/wAHXyQ8RTgig6euN7+EYImi2Bpjs7 2HPdomW0vqxnJ2ErSZTrFPGIYOrwnDf8ElwNI1QfdvfYHM36Q3ITMoluOx1raQQfpucQc75uXNc lEJvO0LGTY7t5O1cpKEpT7NkymwKpIr5Y1D1Y= X-Received: by 2002:ac8:1205:0:b0:50b:1ecb:36ff with SMTP id d75a77b69052e-50b1ecb3a94mr37619901cf.49.1773892116964; Wed, 18 Mar 2026 20:48:36 -0700 (PDT) X-Received: by 2002:ac8:1205:0:b0:50b:1ecb:36ff with SMTP id d75a77b69052e-50b1ecb3a94mr37619491cf.49.1773892116389; Wed, 18 Mar 2026 20:48:36 -0700 (PDT) Received: from umbar.lan (2001-14ba-a073-af00-264b-feff-fe8b-be8a.rev.dnainternet.fi. [2001:14ba:a073:af00:264b:feff:fe8b:be8a]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5a279c79442sm907649e87.70.2026.03.18.20.48.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 20:48:34 -0700 (PDT) From: Dmitry Baryshkov Date: Thu, 19 Mar 2026 05:48:21 +0200 Subject: [PATCH v6 4/4] phy: qualcomm: add MSM8974 HDMI PHY support MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260319-fd-hdmi-phy-v6-4-cefc08a55470@oss.qualcomm.com> References: <20260319-fd-hdmi-phy-v6-0-cefc08a55470@oss.qualcomm.com> In-Reply-To: <20260319-fd-hdmi-phy-v6-0-cefc08a55470@oss.qualcomm.com> To: Rob Clark , Dmitry Baryshkov , Abhinav Kumar , Jessica Zhang , Sean Paul , Marijn Suijten , David Airlie , Simona Vetter , Vinod Koul , Neil Armstrong Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-phy@lists.infradead.org, Dmitry Baryshkov X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=11097; i=dmitry.baryshkov@oss.qualcomm.com; h=from:subject:message-id; bh=+6TT0HzC8JVHRnXbDt/bC4Ub9fZ4l5VDYK4/IEbL+bk=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBpu3IDa0O14mQgb+ucRWajLeyngJERT0Z5H+UCM hsgfP9QohqJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCabtyAwAKCRCLPIo+Aiko 1emKCACK2boafJDM19nTwoHfN6wmwf0FjGm3x0TQfFIJ0T23ofh4B+yif/5Hu8hDf5OI3Rn+Llq HuFHB0OAy9ZKckzDhAuvEhzLRIfrePZcHrYpJ3Qq7rSW+XTERsPZ0pHt88T7lJI80wIlXpvzS5M 0Xgm7iCghOm1dcQhhvJQPGz5dg+Zu2gdA+aQu4b/yDU9ex3jW6pd+rUHL8tCVcsGdaG/mSO0uGJ CZKGnmtXqAyezZ4nn0FHRJFh2oIC1x/mNqbnJfx6KjLS5sYKAJSsS9vVlDKqwj5kYeTj45sLvYQ +JtMlNvlCAvEiouq6MkXdI/eay2/0oovgNDpWRDCa1l19xkB X-Developer-Key: i=dmitry.baryshkov@oss.qualcomm.com; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-Authority-Analysis: v=2.4 cv=MMNtWcZl c=1 sm=1 tr=0 ts=69bb7216 cx=c_pps a=EVbN6Ke/fEF3bsl7X48z0g==:117 a=xqWC_Br6kY4A:10 a=IkcTkHD0fZMA:10 a=Yq5XynenixoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=KKAkSRfTAAAA:8 a=EUspDBNiAAAA:8 a=pGLkceISAAAA:8 a=dsWykBgmCtsaRUozUgwA:9 a=QEXdDO2ut3YA:10 a=a_PwQJl-kcHnX1M80qC6:22 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-ORIG-GUID: GfaZEL10Uv6NbuA_Jk_t2r1S4MxQuFyU X-Proofpoint-GUID: GfaZEL10Uv6NbuA_Jk_t2r1S4MxQuFyU X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzE5MDAyNiBTYWx0ZWRfX5eGjIdjqPakX EsE/drns07iBpXPiE/QiOfPRrY+VdOt8J2FxDF1Lo4g3rdEyst/ZpUnSFraQLcO5W+uLacbMwba OdXfrbskV2bf0A9yxeC6MNCPPg7V2z8s96L0TxuZK1Ob8L10+UMdmA1TbU/QuBbN3g0hXawBZ8T YnMiGuqf1Q1xLFEDwRA+XgJf083ha9Pyh2iZvxdtTCCvcXcYbzY4D0FjGQRdS5W6ohbFUtY5DSF N5UvDkxLiGzgNqlYauocMOqKScabyN4cwRYgZ8uIhcZZS9zV8SQ8dLm9sMn4tW35oixEgcQJ4cZ 5DXDebSm+AQlIyi7DunHW7lKvV6PHTJGZwvHK5S1W3NnlNUmjn1Ier/XjRFAXsCyTMdmzub/R3D HWY/lu7pR0xv2g7m+vNV12g3s+yk0l/xFodHi33JT58JEY3DXDs6qzowkZTRUsPikjJejG0GXGI uSIyVyoPrlmFUFK25FA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-18_02,2026-03-17_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 clxscore=1015 impostorscore=0 lowpriorityscore=0 malwarescore=0 adultscore=0 phishscore=0 priorityscore=1501 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603190026 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Dmitry Baryshkov Add support for HDMI PHY on Qualcomm MSM8974 / APQ8074 platforms. Signed-off-by: Dmitry Baryshkov Signed-off-by: Dmitry Baryshkov --- drivers/phy/qualcomm/phy-qcom-hdmi-28hpm.c | 299 ++++++++++++++++++++++++++++- 1 file changed, 290 insertions(+), 9 deletions(-) diff --git a/drivers/phy/qualcomm/phy-qcom-hdmi-28hpm.c b/drivers/phy/qualcomm/phy-qcom-hdmi-28hpm.c index db7fa2df1a36..f48f81403de5 100644 --- a/drivers/phy/qualcomm/phy-qcom-hdmi-28hpm.c +++ b/drivers/phy/qualcomm/phy-qcom-hdmi-28hpm.c @@ -6,10 +6,12 @@ * Author: Rob Clark */ +#include #include #include #include "phy-qcom-hdmi-preqmp.h" +#include "phy-qcom-uniphy.h" #define REG_HDMI_8x74_ANA_CFG0 0x00000000 #define REG_HDMI_8x74_ANA_CFG1 0x00000004 @@ -31,23 +33,301 @@ #define REG_HDMI_8x74_BIST_PATN3 0x00000048 #define REG_HDMI_8x74_STATUS 0x0000005c +#define HDMI_8974_VCO_MAX_FREQ 1800000000UL +#define HDMI_8974_VCO_MIN_FREQ 600000000UL + +#define HDMI_8974_COMMON_DIV 5 + +static inline void write16(u16 val, void __iomem *reg) +{ + writel(val & 0xff, reg); + writel(val >> 8, reg + 4); +} + +static inline void write24(u32 val, void __iomem *reg) +{ + writel(val & 0xff, reg); + writel((val >> 8) & 0xff, reg + 4); + writel(val >> 16, reg + 8); +} + +static inline u32 read24(void __iomem *reg) +{ + u32 val = readl(reg); + + val |= readl(reg + 4) << 8; + val |= readl(reg + 8) << 16; + + return val; +} + +static void qcom_uniphy_setup(void __iomem *base, unsigned int ref_freq, + bool sdm_mode, + bool ref_freq_mult_2, + bool dither, + unsigned int refclk_div, + unsigned int vco_freq) +{ + unsigned int int_ref_freq = ref_freq * (ref_freq_mult_2 ? 2 : 1); + unsigned int div_in_freq = vco_freq / refclk_div; + unsigned int dc_offset = div_in_freq / int_ref_freq - 1; + unsigned int sdm_freq_seed; + unsigned int val; + unsigned int remain = div_in_freq - (dc_offset + 1) * int_ref_freq; + + sdm_freq_seed = mult_frac(remain, 0x10000, int_ref_freq); + + val = FIELD_PREP(UNIPHY_PLL_REFCLK_DBLR, ref_freq_mult_2) | + FIELD_PREP(UNIPHY_PLL_REFCLK_DIV, refclk_div - 1); + writel(val, base + UNIPHY_PLL_REFCLK_CFG); + + if (sdm_mode) { + writel(0, base + UNIPHY_PLL_SDM_CFG0); + writel(FIELD_PREP(UNIPHY_PLL_SDM_DITHER_EN, dither) | dc_offset, + base + UNIPHY_PLL_SDM_CFG1); + write24(sdm_freq_seed, base + UNIPHY_PLL_SDM_CFG2); + } else { + writel(UNIPHY_PLL_SDM_BYP | dc_offset, base + UNIPHY_PLL_SDM_CFG0); + writel(0, base + UNIPHY_PLL_SDM_CFG1); + write24(0, base + UNIPHY_PLL_SDM_CFG2); + } + + write16(mult_frac(ref_freq, 5, 1000), base + UNIPHY_PLL_CAL_CFG8); + write16(vco_freq / 16, base + UNIPHY_PLL_CAL_CFG10); +} + +static unsigned long qcom_uniphy_recalc(void __iomem *base, unsigned long parent_rate) +{ + unsigned long rate; + u32 refclk_cfg; + u32 dc_offset; + u64 fraq_n; + u32 val; + + refclk_cfg = readl(base + UNIPHY_PLL_REFCLK_CFG); + if (refclk_cfg & UNIPHY_PLL_REFCLK_DBLR) + parent_rate *= 2; + + val = readl(base + UNIPHY_PLL_SDM_CFG0); + if (FIELD_GET(UNIPHY_PLL_SDM_BYP, val)) { + dc_offset = FIELD_GET(UNIPHY_PLL_SDM_BYP_DIV, val); + fraq_n = 0; + } else { + dc_offset = FIELD_GET(UNIPHY_PLL_SDM_DC_OFFSET, + readl(base + UNIPHY_PLL_SDM_CFG1)); + fraq_n = read24(base + UNIPHY_PLL_SDM_CFG2); + } + + rate = (dc_offset + 1) * parent_rate; + rate += mult_frac(fraq_n, parent_rate, 0x10000); + + rate *= FIELD_GET(UNIPHY_PLL_REFCLK_DIV, refclk_cfg) + 1; + + return rate; +} + +static const unsigned int qcom_hdmi_8974_divs[] = {1, 2, 4, 6}; + +static unsigned long qcom_hdmi_8974_pll_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct qcom_hdmi_preqmp_phy *hdmi_phy = hw_clk_to_phy(hw); + u32 div_idx = readl(hdmi_phy->pll_reg + UNIPHY_PLL_POSTDIV1_CFG); + unsigned long rate = qcom_uniphy_recalc(hdmi_phy->pll_reg, parent_rate); + + return rate / HDMI_8974_COMMON_DIV / qcom_hdmi_8974_divs[div_idx & 0x3]; +} + +static int qcom_hdmi_8974_pll_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + unsigned long min_freq = HDMI_8974_VCO_MIN_FREQ / HDMI_8974_COMMON_DIV; + unsigned long max_freq = HDMI_8974_VCO_MAX_FREQ / HDMI_8974_COMMON_DIV; + + req->rate = clamp(req->rate, min_freq / 6, max_freq); + + return 0; +} + +static const struct clk_ops qcom_hdmi_8974_pll_ops = { + .recalc_rate = qcom_hdmi_8974_pll_recalc_rate, + .determine_rate = qcom_hdmi_8974_pll_determine_rate, +}; + +static int qcom_hdmi_msm8974_phy_find_div(unsigned long long pixclk) +{ + unsigned long long min_freq = HDMI_8974_VCO_MIN_FREQ / HDMI_8974_COMMON_DIV; + int i; + + if (pixclk > HDMI_8974_VCO_MAX_FREQ / HDMI_8974_COMMON_DIV) + return -EINVAL; + + for (i = 0; i < ARRAY_SIZE(qcom_hdmi_8974_divs); i++) { + if (pixclk >= min_freq / qcom_hdmi_8974_divs[i]) + return i; + } + + return -EINVAL; +} + +static int qcom_hdmi_msm8974_phy_pll_set_rate(struct qcom_hdmi_preqmp_phy *hdmi_phy) +{ + unsigned long long pixclk = hdmi_phy->hdmi_opts.tmds_char_rate; + unsigned long vco_rate; + unsigned int div; + int div_idx = 0; + + div_idx = qcom_hdmi_msm8974_phy_find_div(pixclk); + if (WARN_ON(div_idx < 0)) + return div_idx; + + div = qcom_hdmi_8974_divs[div_idx]; + vco_rate = pixclk * HDMI_8974_COMMON_DIV * div; + + writel(0x81, hdmi_phy->phy_reg + REG_HDMI_8x74_GLB_CFG); + + writel(0x01, hdmi_phy->pll_reg + UNIPHY_PLL_GLB_CFG); + writel(0x19, hdmi_phy->pll_reg + UNIPHY_PLL_VCOLPF_CFG); + writel(0x0e, hdmi_phy->pll_reg + UNIPHY_PLL_LPFR_CFG); + writel(0x20, hdmi_phy->pll_reg + UNIPHY_PLL_LPFC1_CFG); + writel(0x0d, hdmi_phy->pll_reg + UNIPHY_PLL_LPFC2_CFG); + + qcom_uniphy_setup(hdmi_phy->pll_reg, 19200000, true, true, true, 1, vco_rate); + + writel(0x10, hdmi_phy->pll_reg + UNIPHY_PLL_LKDET_CFG0); + writel(0x1a, hdmi_phy->pll_reg + UNIPHY_PLL_LKDET_CFG1); + writel(0x05, hdmi_phy->pll_reg + UNIPHY_PLL_LKDET_CFG2); + + writel(div_idx, + hdmi_phy->pll_reg + UNIPHY_PLL_POSTDIV1_CFG); + + writel(0x00, hdmi_phy->pll_reg + UNIPHY_PLL_POSTDIV2_CFG); + writel(0x00, hdmi_phy->pll_reg + UNIPHY_PLL_POSTDIV3_CFG); + writel(0x01, hdmi_phy->pll_reg + UNIPHY_PLL_CAL_CFG2); + + writel(0x1f, hdmi_phy->phy_reg + REG_HDMI_8x74_PD_CTRL0); + udelay(50); + + writel(0x0f, hdmi_phy->pll_reg + UNIPHY_PLL_GLB_CFG); + + writel(0x00, hdmi_phy->phy_reg + REG_HDMI_8x74_PD_CTRL1); + writel(0x10, hdmi_phy->phy_reg + REG_HDMI_8x74_ANA_CFG2); + writel(0xdb, hdmi_phy->phy_reg + REG_HDMI_8x74_ANA_CFG0); + writel(0x43, hdmi_phy->phy_reg + REG_HDMI_8x74_ANA_CFG1); + if (pixclk == 297000) { + writel(0x06, hdmi_phy->phy_reg + REG_HDMI_8x74_ANA_CFG2); + writel(0x03, hdmi_phy->phy_reg + REG_HDMI_8x74_ANA_CFG3); + } else if (pixclk == 268500) { + writel(0x05, hdmi_phy->phy_reg + REG_HDMI_8x74_ANA_CFG2); + writel(0x00, hdmi_phy->phy_reg + REG_HDMI_8x74_ANA_CFG3); + } else { + writel(0x02, hdmi_phy->phy_reg + REG_HDMI_8x74_ANA_CFG2); + writel(0x00, hdmi_phy->phy_reg + REG_HDMI_8x74_ANA_CFG3); + } + + writel(0x04, hdmi_phy->pll_reg + UNIPHY_PLL_VREG_CFG); + + writel(0xd0, hdmi_phy->phy_reg + REG_HDMI_8x74_DCC_CFG0); + writel(0x1a, hdmi_phy->phy_reg + REG_HDMI_8x74_DCC_CFG1); + writel(0x00, hdmi_phy->phy_reg + REG_HDMI_8x74_TXCAL_CFG0); + writel(0x00, hdmi_phy->phy_reg + REG_HDMI_8x74_TXCAL_CFG1); + + if (pixclk == 268500) + writel(0x11, hdmi_phy->phy_reg + REG_HDMI_8x74_TXCAL_CFG2); + else + writel(0x02, hdmi_phy->phy_reg + REG_HDMI_8x74_TXCAL_CFG2); + + writel(0x05, hdmi_phy->phy_reg + REG_HDMI_8x74_TXCAL_CFG3); + udelay(200); + + return 0; +} + +static int qcom_hdmi_msm8974_phy_pll_enable(struct qcom_hdmi_preqmp_phy *hdmi_phy) +{ + int ret; + unsigned long status; + + /* Global enable */ + writel(0x81, hdmi_phy->phy_reg + REG_HDMI_8x74_GLB_CFG); + + /* Power up power gen */ + writel(0x00, hdmi_phy->phy_reg + REG_HDMI_8x74_PD_CTRL0); + udelay(350); + + /* PLL power up */ + writel(0x01, hdmi_phy->pll_reg + UNIPHY_PLL_GLB_CFG); + udelay(5); + + /* Power up PLL LDO */ + writel(0x03, hdmi_phy->pll_reg + UNIPHY_PLL_GLB_CFG); + udelay(350); + + /* PLL power up */ + writel(0x0f, hdmi_phy->pll_reg + UNIPHY_PLL_GLB_CFG); + udelay(350); + + /* Poll for PLL ready status */ + ret = readl_poll_timeout(hdmi_phy->pll_reg + UNIPHY_PLL_STATUS, + status, status & BIT(0), + 100, 2000); + if (ret) { + dev_warn(hdmi_phy->dev, "HDMI PLL not ready\n"); + goto err; + } + + udelay(350); + + /* Poll for PHY ready status */ + ret = readl_poll_timeout(hdmi_phy->phy_reg + REG_HDMI_8x74_STATUS, + status, status & BIT(0), + 100, 2000); + if (ret) { + dev_warn(hdmi_phy->dev, "HDMI PHY not ready\n"); + goto err; + } + + return 0; + +err: + writel(0, hdmi_phy->pll_reg + UNIPHY_PLL_GLB_CFG); + udelay(5); + writel(0, hdmi_phy->phy_reg + REG_HDMI_8x74_GLB_CFG); + + return ret; +} + static int qcom_hdmi_msm8974_phy_power_on(struct qcom_hdmi_preqmp_phy *hdmi_phy) { - hdmi_phy_write(hdmi_phy, REG_HDMI_8x74_ANA_CFG0, 0x1b); - hdmi_phy_write(hdmi_phy, REG_HDMI_8x74_ANA_CFG1, 0xf2); - hdmi_phy_write(hdmi_phy, REG_HDMI_8x74_BIST_CFG0, 0x0); - hdmi_phy_write(hdmi_phy, REG_HDMI_8x74_BIST_PATN0, 0x0); - hdmi_phy_write(hdmi_phy, REG_HDMI_8x74_BIST_PATN1, 0x0); - hdmi_phy_write(hdmi_phy, REG_HDMI_8x74_BIST_PATN2, 0x0); - hdmi_phy_write(hdmi_phy, REG_HDMI_8x74_BIST_PATN3, 0x0); - hdmi_phy_write(hdmi_phy, REG_HDMI_8x74_PD_CTRL1, 0x20); + int ret; + + ret = qcom_hdmi_msm8974_phy_pll_set_rate(hdmi_phy); + if (ret) + return ret; + + ret = qcom_hdmi_msm8974_phy_pll_enable(hdmi_phy); + if (ret) + return ret; + + writel(0x1b, hdmi_phy->phy_reg + REG_HDMI_8x74_ANA_CFG0); + writel(0xf2, hdmi_phy->phy_reg + REG_HDMI_8x74_ANA_CFG1); + writel(0x0, hdmi_phy->phy_reg + REG_HDMI_8x74_BIST_CFG0); + writel(0x0, hdmi_phy->phy_reg + REG_HDMI_8x74_BIST_PATN0); + writel(0x0, hdmi_phy->phy_reg + REG_HDMI_8x74_BIST_PATN1); + writel(0x0, hdmi_phy->phy_reg + REG_HDMI_8x74_BIST_PATN2); + writel(0x0, hdmi_phy->phy_reg + REG_HDMI_8x74_BIST_PATN3); + writel(0x20, hdmi_phy->phy_reg + REG_HDMI_8x74_PD_CTRL1); return 0; } static int qcom_hdmi_msm8974_phy_power_off(struct qcom_hdmi_preqmp_phy *hdmi_phy) { - hdmi_phy_write(hdmi_phy, REG_HDMI_8x74_PD_CTRL0, 0x7f); + writel(0x7f, hdmi_phy->phy_reg + REG_HDMI_8x74_PD_CTRL0); + + writel(0, hdmi_phy->pll_reg + UNIPHY_PLL_GLB_CFG); + udelay(5); + writel(0, hdmi_phy->phy_reg + REG_HDMI_8x74_GLB_CFG); return 0; } @@ -67,5 +347,6 @@ const struct qcom_hdmi_preqmp_cfg msm8974_hdmi_phy_cfg = { .power_on = qcom_hdmi_msm8974_phy_power_on, .power_off = qcom_hdmi_msm8974_phy_power_off, + .pll_ops = &qcom_hdmi_8974_pll_ops, .pll_parent = &msm8974_hdmi_pll_parent, }; -- 2.47.3