Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795951455; b=XFdcDPnmqwnu/L6hJYs7vHWGzx1F9p7f16PBdrJFt+fLUqT/BDUt2rAfCeQEToPCTU3h w3O11ioG0x61JmPaC2pWJKCIe+KPXkzmYGP/xtKMOjiK1yBiqy8r/Tf7UeFUmCyq61bOD 1u/96FsGd1W2EM2k+ETOnuzEYyov/nkFya96XRbSKjH9tQyNxkUd3QuZ+oCr79UV1reOB 9plWpJb9yCcWBzCr/3/FTLWQyAz7wdDIW8Jl5QYsNtPxEFU+Gl+pgov1IWC5wb4jFyxov N1CC3US9c3A0JM0yOjECbJJIY45ftao9C16Vc9d/1cPIqa8wUcwRELtfY1S+Tja3vxQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795951455; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=J9E5sBti+zDo39yn2Js7ISohtwXpuu0PQJPv3wlMj8Q=; b=4uWOUYe4bxO2I+/n+h2QDI+rNsZFjBuRW+eLGkC/BEK3dy8yfV+fG6Pdq2GDkEXwRmNx yo1UViunEmtkhMq+BzXvIByUt3C0PCoV/RoWk1O+ibRp9l5qfzUp9Wr752hyQKNNXOcxT UdmBVNv/WtFv3cmxqAwQmEoaLWAIQ5khAd5aEVm9A1gIIhAvjnjPQHRo/Pt0GsvMOQNZk HUbs+ntldEwMmWO3whq5d57CxLQYUz+kbFi1a3tb36msXfxMWh8M+abbA6LqbHq6WRMi5 5isdrGmlvaFD0LxrlZNpKL7hlCBd778pNQNLwJRMNB7LS1Cnw25/wyN1ItJZTs+fmAg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=is6hZg8h; arc=none smtp.remote-ip=209.85.128.51 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 824CA606A325 for ; Sun, 29 Nov 2026 11:24:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 824CA606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=is6hZg8h Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4bba5e17cbeso38968385e9.1 for ; Sun, 29 Nov 2026 03:24:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795951453; x=1796556253; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=J9E5sBti+zDo39yn2Js7ISohtwXpuu0PQJPv3wlMj8Q=; b=is6hZg8hBTncs4y0IHWpJxjvw9qsxrbuiFg5tUjb7f5rhPRAOrUeiyCmtF5nb02jtL 4AIL/jk4X6ERcwKh2gfMWOyeceZipWJv3bksIGBuKkq6gok4Uw0U31w+Dpp/T7k8KSDL DbRsUayqm7Dl+Azpw5m0thtpQc5Np+vui7qoeJT+DnVV49amodlLd/FsPVL+JQfVsnFl ZTiMyL8RXO1q0anE6XsJwuy94l5upnWHI1uni8sLO+zSxFRIh1T7FKjKLPwYLgWj98rZ /dJUVxUMW5uundOy97W1328MZLGTum67sXWu/79KzOOGUQ3ZQw7uSPFO/LBzOn7oq8WI pSEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795951453; x=1796556253; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=J9E5sBti+zDo39yn2Js7ISohtwXpuu0PQJPv3wlMj8Q=; b=LXeqfVyMIPv9XBzIL1G80QBSTRcdT9E4o8MzOhGM/NIr6+uGBC8ke0shhVwVhIzxVE OhM/e8L/P9wNVNKY7Df8LDjKSmVoOKDhl49jgWTLW5TtFSrRFjQVjoIqu+/uRzO8F95E DbrwaJhmcOtJGC1yw2xexfuOLQQwgnPqU6zYWMNGym3IkjG9TCMnxB94jmiSfD1PJMr0 sdMccL1gXhi2HVX3GWQ0eENMz4JstbEoLAI9YFYMr4CN+cicWRA+moYs4wTyE4lBHqOu X4Uddq6e0IxuRtx6rTRTP4X3/rkGT4rxNo4GWo9UyMZ+WQ0nymgNBCtgRHXLkLgONamW tzKw== X-Forwarded-Encrypted: i=1; AL+hErFeuJwK/AoI+Tpm17tLNIOu8CXoTggwm4ceuOuMBZIPLuLMQvP7VwVHLiEAvYM+2lQYve4kb8ANCDFkua3V@vger.kernel.org X-Gm-Message-State: APuU4Z83gCyySgXTdqcV+23AiqaWaEP8agB3/D5srX+52A3+DSR6uv3z J+XmtrHMFYhF/VDD8odM5R5IuJHmJkFAtNI1Xkxtd7rs/dtfPQgdJrsL X-Gm-Gg: AZFdTZdsh7YbMUv0tbEp0S9QwVSf7XaAqdL9jxoD2tU3J8KVwsF+Jt9b+UIS3/8btWx TQU+FnpMcf6INaFbdFawXVFhYwz2tWO78DlQ5vADt1p8N9P6v1YvrwdPFwp1XFmAI2Noj6hxkx7 DdiiZiJ5t6KNQzCsp6dcGgojakNsbQ5Q82xp1bn679+kaCfMJ+34CRWt6alo2i5BbR/JNoWiwzS j2HDhydb8YFGbpZ/2s+WvEkuofXamXcwEIXuqliTmqOc77wwFs8Ss9UKx4nn1ujpRGP8+lOqhqs PpSchI4RQ+bCxDWg7CY7CSz98ghyNiAYL6TeVxLKwgJ8sGCebZhw1PkCtTBEjbfeWID9nDY/HV1 gZr1KuYeNLqXl0r3sPNR+XgyicnqF+hHMknN6rvGUue5BRPnpVYo18e2AgrnmxMlxc2GkHFTRJ6 0A/s8D53ayCvVEptMsV4KRpm1SrkLr26RB6erzFWJQcw97CC+MQAJuKQ3Oq+JftulhL2WNaZLW5 0heXMqV2GmpXefMQwwttIBkwCDzf6IfDDRLVQ9rykKDPuYE4wzZ59kL6EY1GzQgaeYrMR0pZm0c Tb9dYz0ekYR6k8AN3SHMZVCUMx2zLYGv5DzrDHGMvJyjg9usJVjx0krT8Jx9ZrwO4xaSoEnKzCh Lemv6jXQ0l8QRpYFf/RJT X-Received: by 2002:a05:600d:12:b0:4bb:8143:e182 with SMTP id 5b1f17b1804b1-4bb88800168mr476166955e9.5.1795951452692; Sun, 29 Nov 2026 03:24:12 -0800 (PST) Received: from vlw-PC.. (static.18.103.245.188.clients.your-server.de. [188.245.103.18]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb905f1489sm570402995e9.0.2026.11.29.03.24.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 03:24:11 -0800 (PST) From: Vladimir Bely To: Rob Clark , Dmitry Baryshkov Cc: Abhinav Kumar , Jessica Zhang , Sean Paul , Marijn Suijten , David Airlie , Simona Vetter , Kavan Smith , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org, Vladimir Bely , stable@vger.kernel.org Subject: [PATCH v2] drm/msm/dsi: phy_28nm: return exact PLL-achievable VCO rate in determine_rate Date: Sun, 29 Nov 2026 14:24:08 +0300 Message-ID: <20261129112408.533583-1-vlwwwwww@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Commit 6cd33b6f4155 ("drm/msm/dsi: round 6G byte clock rate to the PLL-achievable value") relies on clk_round_rate(byte_clk) returning the rate the DSI PHY PLL actually achieves so later link_clk_set_rate() calls from msm_dsi_host_xfer_prepare() become no-ops in the clock framework and do not re-lock the live PLL during video scanout. However, dsi_pll_28nm_clk_determine_rate() only clamps req->rate to [min_pll_rate, max_pll_rate] without quantizing it to the PLL's SDM fractional-N grid, while dsi_pll_28nm_clk_set_rate() truncates the multiplier via a 1/1000 intermediate step. For example, on MSM8916 with the Samsung AMS452EF01 panel (requested byte clock 57741000 Hz, VCO 461928000 Hz), clk_round_rate() still returns 57741000 Hz whereas recalc_rate() reads back 57739160 Hz (VCO 461913281 Hz). Every runtime DCS command (such as backlight updates) therefore still sees a rate mismatch and re-programs the live 28nm PLL, producing visible scanout corruption. Compute the 16-bit fractional-N divider and resulting VCO rate in a shared helper dsi_pll_28nm_calc_vco_rate() used by both determine_rate() and set_rate(), matching the exact mult_frac() formula in recalc_rate(). Quantize downward (largest frac whose truncated mult_frac() does not exceed the requested remainder) so the PLL never returns a rate above the request, which would otherwise cause clk_byte2_determine_rate() to jump from 1:1 bypass to a 1.5x divider or POSTDIV3 to step up and fail clk_pixel_determine_rate(). Also propagate the integer-division remainder (rate * div + div - 1) through the 28nm byte-clock dividers (analog_postdiv, indirect_path_div2, and dsiNpllbyte) so clk_round_rate(byte_clk, ...) is idempotent under downward truncation instead of stepping down by one SDM increment on each call. Tested on Samsung Galaxy A3 (SM-A300F, MSM8916, AMS452EF01): byte clock settles at 57740991 Hz (VCO 461927929 Hz) with zero drift across repeated backlight updates and no scanout corruption. Fixes: 6cd33b6f4155 ("drm/msm/dsi: round 6G byte clock rate to the PLL-achievable value") Cc: stable@vger.kernel.org Signed-off-by: Vladimir Bely --- Changes in v2: - Quantize frac downward in dsi_pll_28nm_calc_vco_rate() instead of using DIV_ROUND_CLOSEST_ULL(), and drop CLK_DIVIDER_ROUND_CLOSEST / CLK_MUX_ROUND_CLOSEST so dsiNpllbyte never exceeds the requested rate (preventing clk_byte2_determine_rate() from picking a 1.5x divider and POSTDIV3 from stepping up and failing clk_pixel_determine_rate()). - Replace the generic fixed-factor/divider ops on the 28nm byte-clock path (analog_postdiv, indirect_path_div2, dsiNpllbyte) with floor-exact determine_rate() callbacks that pass (rate * div + div - 1) upstream so clk_round_rate() remains idempotent without downward drift. drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c | 305 +++++++++++++++++---- 1 file changed, 257 insertions(+), 48 deletions(-) diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c index d00e415b9..61258f76a 100644 --- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c +++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include "dsi_phy.h" #include "dsi.xml.h" @@ -67,8 +69,21 @@ struct pll_28nm_cached_state { u8 byte_mux; }; +struct dsi_pll_28nm_fixed_div { + struct clk_hw hw; + u32 div; +}; + +struct dsi_pll_28nm_postdiv1 { + struct clk_hw hw; + void __iomem *reg; +}; + struct dsi_pll_28nm { struct clk_hw clk_hw; + struct dsi_pll_28nm_postdiv1 postdiv1; + struct dsi_pll_28nm_fixed_div indirect_div2; + struct dsi_pll_28nm_fixed_div pllbyte; struct msm_dsi_phy *phy; @@ -76,6 +91,8 @@ struct dsi_pll_28nm { }; #define to_pll_28nm(x) container_of(x, struct dsi_pll_28nm, clk_hw) +#define to_pll_28nm_fixed_div(x) container_of(x, struct dsi_pll_28nm_fixed_div, hw) +#define to_pll_28nm_postdiv1(x) container_of(x, struct dsi_pll_28nm_postdiv1, hw) static bool pll_28nm_poll_for_ready(struct dsi_pll_28nm *pll_28nm, u32 nb_tries, u32 timeout_us) @@ -114,31 +131,98 @@ static void pll_28nm_software_reset(struct dsi_pll_28nm *pll_28nm) /* * Clock Callbacks */ +static unsigned long dsi_pll_28nm_calc_vco_rate(struct dsi_pll_28nm *pll_28nm, + unsigned long rate, + u32 *div_fb, u32 *frac_n, + bool *frac_n_mode) +{ + unsigned long min_rate = pll_28nm->phy->cfg->min_pll_rate; + unsigned long max_rate = pll_28nm->phy->cfg->max_pll_rate; + unsigned long actual; + u32 ref_clk, div, rem, frac; + + rate = clamp_t(unsigned long, rate, min_rate, max_rate); + + if (rate % VCO_REF_CLK_RATE == 0) { + if (frac_n_mode) + *frac_n_mode = false; + if (div_fb) + *div_fb = rate / VCO_REF_CLK_RATE; + if (frac_n) + *frac_n = 0; + return rate; + } + + ref_clk = VCO_REF_CLK_RATE * 2; + div = rate / ref_clk; + rem = rate % ref_clk; + /* + * Largest frac whose truncated mult_frac() does not exceed rem, + * keeping calc_vco_rate() idempotent without rounding above rate. + */ + frac = div_u64(((u64)(rem + 1) << 16) - 1, ref_clk); + if (frac >= BIT(16)) { + div++; + frac = 0; + } + + actual = ref_clk * div + mult_frac((unsigned long)ref_clk, frac, BIT(16)); + if (actual < min_rate) { + frac++; + if (frac >= BIT(16)) { + div++; + frac = 0; + } + actual = ref_clk * div + mult_frac((unsigned long)ref_clk, frac, BIT(16)); + } + + if (frac == 0) { + if (frac_n_mode) + *frac_n_mode = false; + if (div_fb) + *div_fb = actual / VCO_REF_CLK_RATE; + if (frac_n) + *frac_n = 0; + return actual; + } + + if (frac_n_mode) + *frac_n_mode = true; + if (div_fb) + *div_fb = div; + if (frac_n) + *frac_n = frac; + return actual; +} + static int dsi_pll_28nm_clk_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct dsi_pll_28nm *pll_28nm = to_pll_28nm(hw); struct device *dev = &pll_28nm->phy->pdev->dev; void __iomem *base = pll_28nm->phy->pll_base; - unsigned long div_fbx1000, gen_vco_clk; - u32 refclk_cfg, frac_n_mode, frac_n_value; + unsigned long gen_vco_clk; + bool frac_n_mode; + u32 refclk_cfg, div_fb, frac_n_value; u32 sdm_cfg0, sdm_cfg1, sdm_cfg2, sdm_cfg3; u32 cal_cfg10, cal_cfg11; - u32 rem; int i; VERB("rate=%lu, parent's=%lu", rate, parent_rate); + gen_vco_clk = dsi_pll_28nm_calc_vco_rate(pll_28nm, rate, &div_fb, + &frac_n_value, &frac_n_mode); + /* Force postdiv2 to be div-4 */ writel(3, base + REG_DSI_28nm_PHY_PLL_POSTDIV2_CFG); /* Configure the Loop filter resistance */ for (i = 0; i < LPFR_LUT_SIZE; i++) - if (rate <= lpfr_lut[i].vco_rate) + if (gen_vco_clk <= lpfr_lut[i].vco_rate) break; if (i == LPFR_LUT_SIZE) { DRM_DEV_ERROR(dev, "unable to get loop filter resistance. vco=%lu\n", - rate); + gen_vco_clk); return -EINVAL; } writel(lpfr_lut[i].resistance, base + REG_DSI_28nm_PHY_PLL_LPFR_CFG); @@ -147,42 +231,26 @@ static int dsi_pll_28nm_clk_set_rate(struct clk_hw *hw, unsigned long rate, writel(0x70, base + REG_DSI_28nm_PHY_PLL_LPFC1_CFG); writel(0x15, base + REG_DSI_28nm_PHY_PLL_LPFC2_CFG); - rem = rate % VCO_REF_CLK_RATE; - if (rem) { - refclk_cfg = DSI_28nm_PHY_PLL_REFCLK_CFG_DBLR; - frac_n_mode = 1; - div_fbx1000 = rate / (VCO_REF_CLK_RATE / 500); - gen_vco_clk = div_fbx1000 * (VCO_REF_CLK_RATE / 500); - } else { - refclk_cfg = 0x0; - frac_n_mode = 0; - div_fbx1000 = rate / (VCO_REF_CLK_RATE / 1000); - gen_vco_clk = div_fbx1000 * (VCO_REF_CLK_RATE / 1000); - } + refclk_cfg = frac_n_mode ? DSI_28nm_PHY_PLL_REFCLK_CFG_DBLR : 0x0; DBG("refclk_cfg = %d", refclk_cfg); - - rem = div_fbx1000 % 1000; - frac_n_value = (rem << 16) / 1000; - - DBG("div_fb = %lu", div_fbx1000); - DBG("frac_n_value = %d", frac_n_value); - + DBG("div_fb = %u", div_fb); + DBG("frac_n_value = %u", frac_n_value); DBG("Generated VCO Clock: %lu", gen_vco_clk); - rem = 0; + sdm_cfg1 = readl(base + REG_DSI_28nm_PHY_PLL_SDM_CFG1); sdm_cfg1 &= ~DSI_28nm_PHY_PLL_SDM_CFG1_DC_OFFSET__MASK; if (frac_n_mode) { sdm_cfg0 = 0x0; sdm_cfg0 |= DSI_28nm_PHY_PLL_SDM_CFG0_BYP_DIV(0); sdm_cfg1 |= DSI_28nm_PHY_PLL_SDM_CFG1_DC_OFFSET( - (u32)(((div_fbx1000 / 1000) & 0x3f) - 1)); + (div_fb & 0x3f) - 1); sdm_cfg3 = frac_n_value >> 8; sdm_cfg2 = frac_n_value & 0xff; } else { sdm_cfg0 = DSI_28nm_PHY_PLL_SDM_CFG0_BYP; sdm_cfg0 |= DSI_28nm_PHY_PLL_SDM_CFG0_BYP_DIV( - (u32)(((div_fbx1000 / 1000) & 0x3f) - 1)); + (div_fb & 0x3f) - 1); sdm_cfg1 |= DSI_28nm_PHY_PLL_SDM_CFG1_DC_OFFSET(0); sdm_cfg2 = 0; sdm_cfg3 = 0; @@ -538,9 +606,8 @@ static int dsi_pll_28nm_clk_determine_rate(struct clk_hw *hw, { struct dsi_pll_28nm *pll_28nm = to_pll_28nm(hw); - req->rate = clamp_t(unsigned long, req->rate, - pll_28nm->phy->cfg->min_pll_rate, - pll_28nm->phy->cfg->max_pll_rate); + req->rate = dsi_pll_28nm_calc_vco_rate(pll_28nm, req->rate, + NULL, NULL, NULL); return 0; } @@ -615,6 +682,121 @@ static int dsi_28nm_pll_restore_state(struct msm_dsi_phy *phy) return 0; } +static unsigned long dsi_pll_28nm_fixed_div_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct dsi_pll_28nm_fixed_div *fdiv = to_pll_28nm_fixed_div(hw); + + return parent_rate / fdiv->div; +} + +static int dsi_pll_28nm_fixed_div_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + struct dsi_pll_28nm_fixed_div *fdiv = to_pll_28nm_fixed_div(hw); + struct clk_hw *parent = clk_hw_get_parent(hw); + unsigned long parent_req; + + if (!parent) + return -EINVAL; + + /* Include remainder so floor(parent / div) stays idempotent */ + if (req->rate > (ULONG_MAX - (fdiv->div - 1)) / fdiv->div) + parent_req = ULONG_MAX; + else + parent_req = req->rate * fdiv->div + fdiv->div - 1; + + req->best_parent_rate = clk_hw_round_rate(parent, parent_req); + req->rate = req->best_parent_rate / fdiv->div; + + return 0; +} + +static int dsi_pll_28nm_fixed_div_set_rate(struct clk_hw *hw, + unsigned long rate, + unsigned long parent_rate) +{ + return 0; +} + +static const struct clk_ops dsi_pll_28nm_fixed_div_ops = { + .recalc_rate = dsi_pll_28nm_fixed_div_recalc_rate, + .determine_rate = dsi_pll_28nm_fixed_div_determine_rate, + .set_rate = dsi_pll_28nm_fixed_div_set_rate, +}; + +static unsigned long dsi_pll_28nm_postdiv1_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct dsi_pll_28nm_postdiv1 *pdiv = to_pll_28nm_postdiv1(hw); + u32 div = (readl(pdiv->reg) & 0xf) + 1; + + return parent_rate / div; +} + +static int dsi_pll_28nm_postdiv1_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + struct clk_hw *parent = clk_hw_get_parent(hw); + unsigned long best_rate = 0, best_parent = 0; + unsigned long rate = req->rate ?: 1; + u32 d; + + if (!parent) + return -EINVAL; + + for (d = 1; d <= 16; d++) { + unsigned long parent_req, p_rate, now; + + if (rate > (ULONG_MAX - (d - 1)) / d) + parent_req = ULONG_MAX; + else + parent_req = rate * d + d - 1; + + p_rate = clk_hw_round_rate(parent, parent_req); + now = p_rate / d; + if (now <= rate && now > best_rate) { + best_rate = now; + best_parent = p_rate; + } + } + + if (!best_rate) { + best_parent = clk_hw_round_rate(parent, 0); + best_rate = best_parent / 16; + } + + req->best_parent_rate = best_parent; + req->rate = best_rate; + + return 0; +} + +static int dsi_pll_28nm_postdiv1_set_rate(struct clk_hw *hw, + unsigned long rate, + unsigned long parent_rate) +{ + struct dsi_pll_28nm_postdiv1 *pdiv = to_pll_28nm_postdiv1(hw); + u32 val, div; + + if (!rate) + return -EINVAL; + + div = clamp_t(unsigned long, parent_rate / rate, 1, 16); + val = readl(pdiv->reg); + val &= ~0xf; + val |= div - 1; + writel(val, pdiv->reg); + + return 0; +} + +static const struct clk_ops dsi_pll_28nm_postdiv1_ops = { + .recalc_rate = dsi_pll_28nm_postdiv1_recalc_rate, + .determine_rate = dsi_pll_28nm_postdiv1_determine_rate, + .set_rate = dsi_pll_28nm_postdiv1_set_rate, +}; + static int pll_28nm_register(struct dsi_pll_28nm *pll_28nm, struct clk_hw **provided_clocks) { char clk_name[32]; @@ -626,8 +808,26 @@ static int pll_28nm_register(struct dsi_pll_28nm *pll_28nm, struct clk_hw **prov .name = clk_name, .flags = CLK_IGNORE_UNUSED, }; + struct clk_init_data postdiv1_init = { + .parent_hws = (const struct clk_hw *[]) { + &pll_28nm->clk_hw, + }, + .num_parents = 1, + .name = clk_name, + .ops = &dsi_pll_28nm_postdiv1_ops, + .flags = CLK_SET_RATE_PARENT, + }; + struct clk_init_data div2_init = { + .parent_hws = (const struct clk_hw *[]) { + &pll_28nm->postdiv1.hw, + }, + .num_parents = 1, + .name = clk_name, + .ops = &dsi_pll_28nm_fixed_div_ops, + .flags = CLK_SET_RATE_PARENT, + }; struct device *dev = &pll_28nm->phy->pdev->dev; - struct clk_hw *hw, *analog_postdiv, *indirect_path_div2, *byte_mux; + struct clk_hw *hw, *byte_mux; int ret; DBG("%d", pll_28nm->phy->id); @@ -646,19 +846,19 @@ static int pll_28nm_register(struct dsi_pll_28nm *pll_28nm, struct clk_hw **prov return ret; snprintf(clk_name, sizeof(clk_name), "dsi%danalog_postdiv_clk", pll_28nm->phy->id); - analog_postdiv = devm_clk_hw_register_divider_parent_hw(dev, clk_name, - &pll_28nm->clk_hw, CLK_SET_RATE_PARENT, - pll_28nm->phy->pll_base + - REG_DSI_28nm_PHY_PLL_POSTDIV1_CFG, - 0, 4, 0, NULL); - if (IS_ERR(analog_postdiv)) - return PTR_ERR(analog_postdiv); + pll_28nm->postdiv1.reg = pll_28nm->phy->pll_base + + REG_DSI_28nm_PHY_PLL_POSTDIV1_CFG; + pll_28nm->postdiv1.hw.init = &postdiv1_init; + ret = devm_clk_hw_register(dev, &pll_28nm->postdiv1.hw); + if (ret) + return ret; snprintf(clk_name, sizeof(clk_name), "dsi%dindirect_path_div2_clk", pll_28nm->phy->id); - indirect_path_div2 = devm_clk_hw_register_fixed_factor_parent_hw(dev, - clk_name, analog_postdiv, CLK_SET_RATE_PARENT, 1, 2); - if (IS_ERR(indirect_path_div2)) - return PTR_ERR(indirect_path_div2); + pll_28nm->indirect_div2.div = 2; + pll_28nm->indirect_div2.hw.init = &div2_init; + ret = devm_clk_hw_register(dev, &pll_28nm->indirect_div2.hw); + if (ret) + return ret; snprintf(clk_name, sizeof(clk_name), "dsi%dpll", pll_28nm->phy->id); hw = devm_clk_hw_register_divider_parent_hw(dev, clk_name, @@ -673,18 +873,27 @@ static int pll_28nm_register(struct dsi_pll_28nm *pll_28nm, struct clk_hw **prov byte_mux = devm_clk_hw_register_mux_parent_hws(dev, clk_name, ((const struct clk_hw *[]){ &pll_28nm->clk_hw, - indirect_path_div2, + &pll_28nm->indirect_div2.hw, }), 2, CLK_SET_RATE_PARENT, pll_28nm->phy->pll_base + REG_DSI_28nm_PHY_PLL_VREG_CFG, 1, 1, 0, NULL); if (IS_ERR(byte_mux)) return PTR_ERR(byte_mux); snprintf(clk_name, sizeof(clk_name), "dsi%dpllbyte", pll_28nm->phy->id); - hw = devm_clk_hw_register_fixed_factor_parent_hw(dev, clk_name, - byte_mux, CLK_SET_RATE_PARENT, 1, 4); - if (IS_ERR(hw)) - return PTR_ERR(hw); - provided_clocks[DSI_BYTE_PLL_CLK] = hw; + pll_28nm->pllbyte.div = 4; + pll_28nm->pllbyte.hw.init = &(const struct clk_init_data) { + .parent_hws = (const struct clk_hw *[]) { + byte_mux, + }, + .num_parents = 1, + .name = clk_name, + .ops = &dsi_pll_28nm_fixed_div_ops, + .flags = CLK_SET_RATE_PARENT, + }; + ret = devm_clk_hw_register(dev, &pll_28nm->pllbyte.hw); + if (ret) + return ret; + provided_clocks[DSI_BYTE_PLL_CLK] = &pll_28nm->pllbyte.hw; return 0; } base-commit: dca2f1b25860f8caa0406f858e76a3a21671a012 -- 2.43.0