From patchwork Tue Sep 14 15:56:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 510945 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1677591jao; Tue, 14 Sep 2021 08:56:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwo6rx98iiG9h2Qzdx+09vPjAQbzk/ZoWr7K0SUlDsj6SNA9YdqCana7DdQUm0sLMVydGEN X-Received: by 2002:a2e:b5d0:: with SMTP id g16mr15838249ljn.349.1631634980826; Tue, 14 Sep 2021 08:56:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631634980; cv=none; d=google.com; s=arc-20160816; b=TJ9TYcwhCU+P0kekHQ2wKyFH2BsrDPQxI8EOGKtEgt2bxYR3Z4/+PDLkK46Z28941o tsqIeYWQzJYxbNYMrqLLbGK5J7E4ENaElTZZK5S19G4FVZjKe5RrXkfhK+0pzkepwKtm CnXHhL6bPqlIZ2NhL2QoK2tbOZnrqNayZZEZjz6uMBQF3Q9jQH5zn2JZfjRy1a4V0Gk/ 47YXUK6ZKTwDpbiCwPHoMgnKG89BCQ9nkGp2I2la9n67WtVnKLjGkWtn/sw4o0PRShwI jHBRvjmKdJ/VMUjykGkRDf8pb+BuiID0Xq02OV405PZMFh8lE+siWQmGUfDdYLpuyl4p zhmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RF1mZx2A0BJwyns60yFc42fN8PngjocR5HugnGLcRUI=; b=uKJEvHBoy4gl6ACKPpkcuBFOmu0DGGDtWGHgf+zPu8APDdBd+51Q9JfXUp8OwfFWgz 4jiXTn7MfAQlifQlwrG0CipkAm5SVIEi+D2GL4pE8AE5ag0W67tnNaIpRVpnQUqc6+YY HOkBeh5rHHTszqArnX/kZ15M40s6kuhd2oUUoOiahI6ppYg5VTsQZDERcCKMmOFKOSdL uw8lXorHdYxlhfzxwXgUOlQXgZomfDogzOMfi8BsjLCWULQJEqyUV0BECjNnFZ5T7sai N370qbN0xd/iaZ2A9sYZoytHEw2xlwhg+pUWEDEPyrL64ILkGCM/6uwi8t9y1itlE3lF MBuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ySa3Ocvk; spf=pass (google.com: domain of linux-samsung-soc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u12si10607783lfs.194.2021.09.14.08.56.18; Tue, 14 Sep 2021 08:56:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-samsung-soc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ySa3Ocvk; spf=pass (google.com: domain of linux-samsung-soc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235070AbhINP5e (ORCPT + 4 others); Tue, 14 Sep 2021 11:57:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234946AbhINP5d (ORCPT ); Tue, 14 Sep 2021 11:57:33 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70899C061762 for ; Tue, 14 Sep 2021 08:56:15 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id k4so29861654lfj.7 for ; Tue, 14 Sep 2021 08:56:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RF1mZx2A0BJwyns60yFc42fN8PngjocR5HugnGLcRUI=; b=ySa3Ocvk2eVZjj671XTmWO5NwX254YRYLMXoE4epqOyiUxNdyJVl5cygyx+2niQI7G G95L63SwNNBM9rz7FfZ/evy4SWX5zTm6j+K3+84TgBYT6Na+rT8x56PXf3NeaE1ZmYLh AEcwX8P19hakB7hvnzisT/peqG7hyNLuCOZh3MEvygFgetrgeawUJJwg3skdP6v5jsPP 7iOcpH1gZFKLUy0Tuv5ChIO8oWGBXSOdmOh0G452+qa5suRnx/J99nP5pvaGSi6DqPSC UwSEOi7+eVYJ9nO7QwOT6c21D1Pd0Lc/4gHtYJBdtmkfdK/bJTH3qhQQUlBeqEf/Qgb1 qfbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RF1mZx2A0BJwyns60yFc42fN8PngjocR5HugnGLcRUI=; b=hIucJfwgzsk1wHNObOk9DdkZkTjCU+Sa5Blz8fo3iP7rFC6iYcoH48k90iVx0wzko0 wxyl5PVfx8qZTc9tCOdPFdaUMvqs/w2debCBurMgss2MvNP8N0ixPBsnf3+R+R5QopmM CZIdDWO2wDcbRyMQbu35f6NFtvvOjdPwOPm7rlNl5tjvB4qpC14Is4pQ9zwl37U1uHOX vVAuxkV8QnwuYw6neLDj3WLmy/ZMqAkUN22jzW0f2hbHdLRI7z/GYhMQ+/+HGx+G7Rvd VG5OWkKgDI2DAF8oM1xnYHkYDkQiOTJHUCwnvxlKAVzHkMnnGcpyzrMafodyBZSo3itd 438w== X-Gm-Message-State: AOAM531qy1RLvXJyzhXglaVgzIS1j2yc2jzOxsrnKHBAA0gPVe88neog URXHeJSYqNFSLeY2/PSR0BaIgQ== X-Received: by 2002:a05:6512:23a5:: with SMTP id c37mr13869294lfv.321.1631634973802; Tue, 14 Sep 2021 08:56:13 -0700 (PDT) Received: from localhost ([31.134.121.151]) by smtp.gmail.com with ESMTPSA id u16sm1472260ljj.0.2021.09.14.08.56.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 08:56:13 -0700 (PDT) From: Sam Protsenko To: Krzysztof Kozlowski , Sylwester Nawrocki , =?utf-8?q?Pawe=C5=82_Chmiel?= , Chanwoo Choi , Tomasz Figa , Rob Herring , Stephen Boyd , Michael Turquette Cc: Ryu Euiyoul , Tom Gall , Sumit Semwal , John Stultz , Amit Pundir , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org Subject: [PATCH 3/6] clk: samsung: clk-pll: Implement pll0831x PLL type Date: Tue, 14 Sep 2021 18:56:04 +0300 Message-Id: <20210914155607.14122-4-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210914155607.14122-1-semen.protsenko@linaro.org> References: <20210914155607.14122-1-semen.protsenko@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org pll0831x PLL is used in Exynos850 SoC for top-level fractional PLLs. The code was derived from very similar pll36xx type, with next differences: 1. Lock time for pll0831x is 500*P_DIV, when for pll36xx it's 3000*P_DIV 2. It's not suggested in Exynos850 TRM that S_DIV change doesn't require performing PLL lock procedure (which is done in pll36xx implementation) 3. The offset from PMS-values register to K-value register is 0x8 for pll0831x, when for pll36xx it's 0x4 When defining pll0831x type, CON3 register offset should be provided as a "con" parameter of PLL() macro, like this: PLL(pll_0831x, 0, "fout_mmc_pll", "oscclk", PLL_LOCKTIME_PLL_MMC, PLL_CON3_PLL_MMC, pll0831x_26mhz_tbl), To define PLL rates table, one can use PLL_36XX_RATE() macro, e.g.: PLL_36XX_RATE(26 * MHZ, 799999877, 31, 1, 0, -15124) as it's completely appropriate for pl0831x type and there is no sense in duplicating that. If bit #1 (MANUAL_PLL_CTRL) is not set in CON1 register, it won't be possible to set new rate, with next error showing in kernel log: Could not lock PLL fout_mmc_pll That can happen for example if bootloader clears that bit beforehand. PLL driver doesn't account for that, so if MANUAL_PLL_CTRL bit was cleared, it's assumed it was done for a reason and it shouldn't be possible to change that PLL's rate at all. Signed-off-by: Sam Protsenko --- drivers/clk/samsung/clk-pll.c | 105 ++++++++++++++++++++++++++++++++++ drivers/clk/samsung/clk-pll.h | 1 + 2 files changed, 106 insertions(+) -- 2.30.2 Reviewed-by: Krzysztof Kozlowski Acked-by: Chanwoo Choi diff --git a/drivers/clk/samsung/clk-pll.c b/drivers/clk/samsung/clk-pll.c index 03131b149c0b..83d1b03647db 100644 --- a/drivers/clk/samsung/clk-pll.c +++ b/drivers/clk/samsung/clk-pll.c @@ -498,6 +498,103 @@ static const struct clk_ops samsung_pll0822x_clk_min_ops = { .recalc_rate = samsung_pll0822x_recalc_rate, }; +/* + * PLL0831x Clock Type + */ +/* Maximum lock time can be 500 * PDIV cycles */ +#define PLL0831X_LOCK_FACTOR (500) + +#define PLL0831X_KDIV_MASK (0xFFFF) +#define PLL0831X_MDIV_MASK (0x1FF) +#define PLL0831X_PDIV_MASK (0x3F) +#define PLL0831X_SDIV_MASK (0x7) +#define PLL0831X_MDIV_SHIFT (16) +#define PLL0831X_PDIV_SHIFT (8) +#define PLL0831X_SDIV_SHIFT (0) +#define PLL0831X_KDIV_SHIFT (0) +#define PLL0831X_LOCK_STAT_SHIFT (29) +#define PLL0831X_ENABLE_SHIFT (31) + +static unsigned long samsung_pll0831x_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct samsung_clk_pll *pll = to_clk_pll(hw); + u32 mdiv, pdiv, sdiv, pll_con3, pll_con5; + s16 kdiv; + u64 fvco = parent_rate; + + pll_con3 = readl_relaxed(pll->con_reg); + pll_con5 = readl_relaxed(pll->con_reg + 8); + mdiv = (pll_con3 >> PLL0831X_MDIV_SHIFT) & PLL0831X_MDIV_MASK; + pdiv = (pll_con3 >> PLL0831X_PDIV_SHIFT) & PLL0831X_PDIV_MASK; + sdiv = (pll_con3 >> PLL0831X_SDIV_SHIFT) & PLL0831X_SDIV_MASK; + kdiv = (s16)((pll_con5 >> PLL0831X_KDIV_SHIFT) & PLL0831X_KDIV_MASK); + + fvco *= (mdiv << 16) + kdiv; + do_div(fvco, (pdiv << sdiv)); + fvco >>= 16; + + return (unsigned long)fvco; +} + +static int samsung_pll0831x_set_rate(struct clk_hw *hw, unsigned long drate, + unsigned long parent_rate) +{ + const struct samsung_pll_rate_table *rate; + struct samsung_clk_pll *pll = to_clk_pll(hw); + u32 pll_con3, pll_con5; + + /* Get required rate settings from table */ + rate = samsung_get_pll_settings(pll, drate); + if (!rate) { + pr_err("%s: Invalid rate : %lu for pll clk %s\n", __func__, + drate, clk_hw_get_name(hw)); + return -EINVAL; + } + + pll_con3 = readl_relaxed(pll->con_reg); + pll_con5 = readl_relaxed(pll->con_reg + 8); + + /* Change PLL PMSK values */ + pll_con3 &= ~((PLL0831X_MDIV_MASK << PLL0831X_MDIV_SHIFT) | + (PLL0831X_PDIV_MASK << PLL0831X_PDIV_SHIFT) | + (PLL0831X_SDIV_MASK << PLL0831X_SDIV_SHIFT)); + pll_con3 |= (rate->mdiv << PLL0831X_MDIV_SHIFT) | + (rate->pdiv << PLL0831X_PDIV_SHIFT) | + (rate->sdiv << PLL0831X_SDIV_SHIFT); + pll_con5 &= ~(PLL0831X_KDIV_MASK << PLL0831X_KDIV_SHIFT); + /* + * kdiv is 16-bit 2's complement (s16), but stored as unsigned int. + * Cast it to u16 to avoid leading 0xffff's in case of negative value. + */ + pll_con5 |= ((u16)rate->kdiv << PLL0831X_KDIV_SHIFT); + + /* Set PLL lock time */ + writel_relaxed(rate->pdiv * PLL0831X_LOCK_FACTOR, pll->lock_reg); + + /* Write PMSK values */ + writel_relaxed(pll_con3, pll->con_reg); + writel_relaxed(pll_con5, pll->con_reg + 8); + + /* Wait for PLL lock if the PLL is enabled */ + if (pll_con3 & BIT(pll->enable_offs)) + return samsung_pll_lock_wait(pll, BIT(pll->lock_offs)); + + return 0; +} + +static const struct clk_ops samsung_pll0831x_clk_ops = { + .recalc_rate = samsung_pll0831x_recalc_rate, + .set_rate = samsung_pll0831x_set_rate, + .round_rate = samsung_pll_round_rate, + .enable = samsung_pll3xxx_enable, + .disable = samsung_pll3xxx_disable, +}; + +static const struct clk_ops samsung_pll0831x_clk_min_ops = { + .recalc_rate = samsung_pll0831x_recalc_rate, +}; + /* * PLL45xx Clock Type */ @@ -1407,6 +1504,14 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx, else init.ops = &samsung_pll36xx_clk_ops; break; + case pll_0831x: + pll->enable_offs = PLL0831X_ENABLE_SHIFT; + pll->lock_offs = PLL0831X_LOCK_STAT_SHIFT; + if (!pll->rate_table) + init.ops = &samsung_pll0831x_clk_min_ops; + else + init.ops = &samsung_pll0831x_clk_ops; + break; case pll_6552: case pll_6552_s3c2416: init.ops = &samsung_pll6552_clk_ops; diff --git a/drivers/clk/samsung/clk-pll.h b/drivers/clk/samsung/clk-pll.h index 213e94a97f23..a739f2b7ae80 100644 --- a/drivers/clk/samsung/clk-pll.h +++ b/drivers/clk/samsung/clk-pll.h @@ -37,6 +37,7 @@ enum samsung_pll_type { pll_1452x, pll_1460x, pll_0822x, + pll_0831x, }; #define PLL_RATE(_fin, _m, _p, _s, _k, _ks) \