Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3251237rwo; Fri, 4 Aug 2023 01:39:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTdVbTHQ5TRa8zuguwe2URcCki63jUyONQEFGaLp+Kn3Daece7TpMo4++01XOxD9m0hIH9 X-Received: by 2002:a05:6402:50d0:b0:51e:2c4b:6f1e with SMTP id h16-20020a05640250d000b0051e2c4b6f1emr1382048edb.14.1691138394937; Fri, 04 Aug 2023 01:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691138394; cv=none; d=google.com; s=arc-20160816; b=kk7ewKlK8LRCMNto2/pk9hBQ3RhExmSFylnT/VEq+vPCO1gmuXKeem+41CCNxxht+y YwJqFjK4QPUi9Ewv5acBDe8hw6fEX5e/rRWnwEG5XJa/k0O3AnvvIg3Goik1qmLc/QP6 pq7d7t3k0VJoa2ppdZ44jb1B3iYCd7MvRddhUEAJpYGqgu0rYJQzyGfVaAZll67I8zyB 1iexGE+5vJw5ZXtcoIYfO4Cf0hdjWCgf0wWNGbhqb8/vZzQ56o4Vkp2SAwWiVU6Snnc9 cM5uJ1VSb0nNVVM4pBJY5nnWLx8nLEdsX7wlvfUXb+K65phUqRCkSJJmen0ogG8KaRnk K7Gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:dkim-signature; bh=fjxFinBxb4fV1ij6n7gKBVvXzD01CF3vgozZrKOB0SE=; fh=f/Kncm+X8u3RbIty+aBZsmDmMXhq0otoR+XYiCgM4LI=; b=KuLvYmzsNJu9GTf1zN2UVW46wrsChCr+87g8dInigGGkCD3Wha4ALI17tzQtpYqcwd sq6+vd/dDHDroBV/EoDtZ9+LTIoJMkeGdn9U53AoVd+0Pm/+bTbKbHye0Aw6QBZh8tNb E35uzEEstYCNJpcvO69b3qTzNTrvMWZESPaPJ5vk/BVgDLhvZIIBEl+ECbsnlwW8UNWq d9BQQgpA49KzwL0fvtZVXo2V5aSUY7CIbMPzC2kjRjb3NFyAai+fz+XJSjzesjA7CBmt aS3jzY2NJEZJOC0IMtkB8mBdO2yYbPh9CyMmmcJxyLtQKfWW1GCYV0mFs+ArdaAvzGNA TMbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=h+NLbZA0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t8-20020aa7d708000000b00522394947c9si1329942edq.632.2023.08.04.01.39.30; Fri, 04 Aug 2023 01:39:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20221208.gappssmtp.com header.s=20221208 header.b=h+NLbZA0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231950AbjHDHis (ORCPT + 99 others); Fri, 4 Aug 2023 03:38:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230011AbjHDHiq (ORCPT ); Fri, 4 Aug 2023 03:38:46 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FCE23AA6 for ; Fri, 4 Aug 2023 00:38:43 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fe490c05c9so1541165e9.0 for ; Fri, 04 Aug 2023 00:38:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1691134722; x=1691739522; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=fjxFinBxb4fV1ij6n7gKBVvXzD01CF3vgozZrKOB0SE=; b=h+NLbZA0tsAFL0P0PKK1oTtDPfbOx8shpPl1Lou6ZSyZexm+zeAy3QF6iK4xeb0569 VPBIBtHIcr/qYGN5r6213rM2j3Q+1TB7y31V0g/3w0fHUl3PSYI50VUMceaAyEwFCSKy req9TM2xckPClNduez1E3gwuczNHP6KN+2LdJ1UMD32c1qiQKPl4EmAlan+5E1fJoc7S 2hEfBKhXCG76Cb06Z2U87bkjr2tAsg7Uf7bQe1wHf+czTaZH4dAHT8ibD1GikmqLW44c 47kRBdUFl1UIXH3HdnILXuaiO9NQbd18H5s0iMlSongqwXwspCc5rIjomIyYG43EkuU/ KSRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691134722; x=1691739522; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=fjxFinBxb4fV1ij6n7gKBVvXzD01CF3vgozZrKOB0SE=; b=h7xSI5vRpchzyNSNy4zG3sF7PRFjfFPtgWkx89S9TcTfBqTKTFPZCa6uyJJZlTJ3u4 Du07zqHt9xnvIk1NFZuGZfHregWLSP+2iY1GHRJNFIIAfLip7O9YhkcHZNdnVyln/zsL BHgpUlHvr+TazYjN0MQGoLTnFIlrpLgmjseCLjjlCKfMNQ/1RbPK4dKiEtcos8QwPcYR I2sxRqubkeAvKYbur6UZA2z3lxg2asjYn0PG45dp+UbYZRF0jCXCPiixIvccB9ypIrSO IA6S/JtCqsz/ak6JdPfxji2hW7Y2dhVe+vX1GBm4o/fj0/D7D+AKvEpu9PMOEyTQHAg/ HNeQ== X-Gm-Message-State: AOJu0YzjJg3FnOFZVbAXjaNe+LHFoxxLZIfK8uI81Gpwx2r52N2dHTU/ CFAKQvJ72PioGmsOCqg057XAGg== X-Received: by 2002:adf:ea43:0:b0:317:5efa:c46a with SMTP id j3-20020adfea43000000b003175efac46amr924802wrn.27.1691134721650; Fri, 04 Aug 2023 00:38:41 -0700 (PDT) Received: from localhost ([2a01:e0a:3c5:5fb1:aeaf:609a:5eef:39a8]) by smtp.gmail.com with ESMTPSA id t6-20020a5d6a46000000b003142e438e8csm1792101wrw.26.2023.08.04.00.38.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 00:38:41 -0700 (PDT) References: <20230803-amlogic-v6-4-upstream-dsi-ccf-vim3-v7-0-762219fc5b28@linaro.org> <20230803-amlogic-v6-4-upstream-dsi-ccf-vim3-v7-3-762219fc5b28@linaro.org> User-agent: mu4e 1.8.13; emacs 28.2 From: Jerome Brunet To: Neil Armstrong , Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Kevin Hilman , Martin Blumenstingl , David Airlie , Daniel Vetter , Jagan Teki , Nicolas Belin Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org Subject: Re: [PATCH v7 3/9] clk: meson: add vclk driver Date: Fri, 04 Aug 2023 09:33:36 +0200 In-reply-to: <20230803-amlogic-v6-4-upstream-dsi-ccf-vim3-v7-3-762219fc5b28@linaro.org> Message-ID: <1j5y5vp88v.fsf@starbuckisacylon.baylibre.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 03 Aug 2023 at 14:03, Neil Armstrong wrote: > The VCLK and VCLK_DIV clocks have supplementary bits. > > The VCLK has a "SOFT RESET" bit to toggle after the whole > VCLK sub-tree rate has been set, this is implemented in > the gate enable callback. > > The VCLK_DIV clocks as enable and reset bits used to disable > and reset the divider, associated with CLK_SET_RATE_GATE it ensures > the rate is set while the divider is disabled and in reset mode. > > The VCLK_DIV enable bit isn't implemented as a gate since it's part > of the divider logic and vendor does this exact sequence to ensure > the divider is correctly set. Unless there is reason, I'd prefer if this driver was using 'struct parm', like the rest of amlogic custom clock drivers, for consistency. > > Signed-off-by: Neil Armstrong > --- > drivers/clk/meson/Kconfig | 5 ++ > drivers/clk/meson/Makefile | 1 + > drivers/clk/meson/vclk.c | 146 +++++++++++++++++++++++++++++++++++++++++++++ > drivers/clk/meson/vclk.h | 68 +++++++++++++++++++++ > 4 files changed, 220 insertions(+) > > diff --git a/drivers/clk/meson/Kconfig b/drivers/clk/meson/Kconfig > index 135da8f2d0b1..83f629515e96 100644 > --- a/drivers/clk/meson/Kconfig > +++ b/drivers/clk/meson/Kconfig > @@ -30,6 +30,10 @@ config COMMON_CLK_MESON_VID_PLL_DIV > tristate > select COMMON_CLK_MESON_REGMAP > > +config COMMON_CLK_MESON_VCLK > + tristate > + select COMMON_CLK_MESON_REGMAP > + > config COMMON_CLK_MESON_CLKC_UTILS > tristate > > @@ -140,6 +144,7 @@ config COMMON_CLK_G12A > select COMMON_CLK_MESON_EE_CLKC > select COMMON_CLK_MESON_CPU_DYNDIV > select COMMON_CLK_MESON_VID_PLL_DIV > + select COMMON_CLK_MESON_VCLK > select MFD_SYSCON > help > Support for the clock controller on Amlogic S905D2, S905X2 and S905Y2 > diff --git a/drivers/clk/meson/Makefile b/drivers/clk/meson/Makefile > index cd961cc4f4db..6efeb8c7bd2a 100644 > --- a/drivers/clk/meson/Makefile > +++ b/drivers/clk/meson/Makefile > @@ -12,6 +12,7 @@ obj-$(CONFIG_COMMON_CLK_MESON_PLL) += clk-pll.o > obj-$(CONFIG_COMMON_CLK_MESON_REGMAP) += clk-regmap.o > obj-$(CONFIG_COMMON_CLK_MESON_SCLK_DIV) += sclk-div.o > obj-$(CONFIG_COMMON_CLK_MESON_VID_PLL_DIV) += vid-pll-div.o > +obj-$(CONFIG_COMMON_CLK_MESON_VCLK) += vclk.o > > # Amlogic Clock controllers > > diff --git a/drivers/clk/meson/vclk.c b/drivers/clk/meson/vclk.c > new file mode 100644 > index 000000000000..0df84403b17f > --- /dev/null > +++ b/drivers/clk/meson/vclk.c > @@ -0,0 +1,146 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (c) 2023 Neil Armstrong > + */ > + > +#include > +#include "vclk.h" > + > +/* The VCLK gate has a supplementary reset bit to pulse after ungating */ > + > +static int clk_regmap_vclk_enable(struct clk_hw *hw) > +{ > + struct clk_regmap *clk = to_clk_regmap(hw); > + struct clk_regmap_vclk_data *vclk = clk_get_regmap_vclk_data(clk); > + > + regmap_set_bits(clk->map, vclk->offset, BIT(vclk->enable_bit_idx)); > + > + /* Do a reset pulse */ > + regmap_set_bits(clk->map, vclk->offset, BIT(vclk->reset_bit_idx)); > + regmap_clear_bits(clk->map, vclk->offset, BIT(vclk->reset_bit_idx)); > + > + return 0; > +} > + > +static void clk_regmap_vclk_disable(struct clk_hw *hw) > +{ > + struct clk_regmap *clk = to_clk_regmap(hw); > + struct clk_regmap_vclk_data *vclk = clk_get_regmap_vclk_data(clk); > + > + regmap_clear_bits(clk->map, vclk->offset, BIT(vclk->enable_bit_idx)); > +} > + > +static int clk_regmap_vclk_is_enabled(struct clk_hw *hw) > +{ > + struct clk_regmap *clk = to_clk_regmap(hw); > + struct clk_regmap_vclk_data *vclk = clk_get_regmap_vclk_data(clk); > + unsigned int val; > + > + regmap_read(clk->map, vclk->offset, &val); > + > + return val & BIT(vclk->enable_bit_idx) ? 1 : 0; > +} > + > +const struct clk_ops clk_regmap_vclk_ops = { > + .enable = clk_regmap_vclk_enable, > + .disable = clk_regmap_vclk_disable, > + .is_enabled = clk_regmap_vclk_is_enabled, > +}; > +EXPORT_SYMBOL_GPL(clk_regmap_vclk_ops); > + > +/* The VCLK Divider has supplementary reset & enable bits */ > + > +static unsigned long clk_regmap_vclk_div_recalc_rate(struct clk_hw *hw, > + unsigned long prate) > +{ > + struct clk_regmap *clk = to_clk_regmap(hw); > + struct clk_regmap_vclk_div_data *vclk = clk_get_regmap_vclk_div_data(clk); > + unsigned int val; > + int ret; > + > + ret = regmap_read(clk->map, vclk->offset, &val); > + if (ret) > + /* Gives a hint that something is wrong */ > + return 0; > + > + val >>= vclk->shift; > + val &= clk_div_mask(vclk->width); > + > + return divider_recalc_rate(hw, prate, val, vclk->table, vclk->flags, > + vclk->width); > +} > + > +static int clk_regmap_vclk_div_determine_rate(struct clk_hw *hw, > + struct clk_rate_request *req) > +{ > + struct clk_regmap *clk = to_clk_regmap(hw); > + struct clk_regmap_vclk_div_data *vclk = clk_get_regmap_vclk_div_data(clk); > + > + return divider_determine_rate(hw, req, vclk->table, vclk->width, > + vclk->flags); > +} > + > +static int clk_regmap_vclk_div_set_rate(struct clk_hw *hw, unsigned long rate, > + unsigned long parent_rate) > +{ > + struct clk_regmap *clk = to_clk_regmap(hw); > + struct clk_regmap_vclk_div_data *vclk = clk_get_regmap_vclk_div_data(clk); > + unsigned int val; > + int ret; > + > + ret = divider_get_val(rate, parent_rate, vclk->table, vclk->width, > + vclk->flags); > + if (ret < 0) > + return ret; > + > + val = (unsigned int)ret << vclk->shift; > + return regmap_update_bits(clk->map, vclk->offset, > + clk_div_mask(vclk->width) << vclk->shift, val); > +}; > + > +static int clk_regmap_vclk_div_enable(struct clk_hw *hw) > +{ > + struct clk_regmap *clk = to_clk_regmap(hw); > + struct clk_regmap_vclk_div_data *vclk = clk_get_regmap_vclk_div_data(clk); > + > + /* Unreset the divider when ungating */ > + regmap_clear_bits(clk->map, vclk->offset, BIT(vclk->reset_bit_idx)); > + > + return regmap_set_bits(clk->map, vclk->offset, BIT(vclk->enable_bit_idx)); > +} > + > +static void clk_regmap_vclk_div_disable(struct clk_hw *hw) > +{ > + struct clk_regmap *clk = to_clk_regmap(hw); > + struct clk_regmap_vclk_div_data *vclk = clk_get_regmap_vclk_div_data(clk); > + > + /* Reset the divider when gating */ > + regmap_clear_bits(clk->map, vclk->offset, BIT(vclk->enable_bit_idx)); > + > + regmap_set_bits(clk->map, vclk->offset, BIT(vclk->reset_bit_idx)); > +} > + > +static int clk_regmap_vclk_div_is_enabled(struct clk_hw *hw) > +{ > + struct clk_regmap *clk = to_clk_regmap(hw); > + struct clk_regmap_vclk_div_data *vclk = clk_get_regmap_vclk_div_data(clk); > + unsigned int val; > + > + regmap_read(clk->map, vclk->offset, &val); > + > + return val & BIT(vclk->enable_bit_idx) ? 1 : 0; > +} > + > +const struct clk_ops clk_regmap_vclk_div_ops = { > + .recalc_rate = clk_regmap_vclk_div_recalc_rate, > + .determine_rate = clk_regmap_vclk_div_determine_rate, > + .set_rate = clk_regmap_vclk_div_set_rate, > + .enable = clk_regmap_vclk_div_enable, > + .disable = clk_regmap_vclk_div_disable, > + .is_enabled = clk_regmap_vclk_div_is_enabled, > +}; > +EXPORT_SYMBOL_GPL(clk_regmap_vclk_div_ops); > + > +MODULE_DESCRIPTION("Amlogic vclk clock driver"); > +MODULE_AUTHOR("Neil Armstrong "); > +MODULE_LICENSE("GPL v2"); > diff --git a/drivers/clk/meson/vclk.h b/drivers/clk/meson/vclk.h > new file mode 100644 > index 000000000000..90786552a7f3 > --- /dev/null > +++ b/drivers/clk/meson/vclk.h > @@ -0,0 +1,68 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Copyright (c) 2023 Neil Armstrong > + */ > + > +#ifndef __VCLK_H > +#define __VCLK_H > + > +#include "clk-regmap.h" > + > +/** > + * struct clk_regmap_vclk_data - vclk regmap backed specific data > + * > + * @offset: offset of the register controlling gate > + * @enable_bit_idx: single bit controlling vclk enable > + * @reset_bit_idx: single bit controlling vclk reset > + * @flags: hardware-specific flags > + * > + * Flags: > + * Same as clk_gate except CLK_GATE_HIWORD_MASK which is ignored > + */ > +struct clk_regmap_vclk_data { > + unsigned int offset; > + u8 enable_bit_idx; > + u8 reset_bit_idx; > + u8 flags; > +}; > + > +static inline struct clk_regmap_vclk_data * > +clk_get_regmap_vclk_data(struct clk_regmap *clk) > +{ > + return (struct clk_regmap_vclk_data *)clk->data; > +} > + > +extern const struct clk_ops clk_regmap_vclk_ops; > + > +/** > + * struct clk_regmap_vclk_div_data - vclk_div regmap back specific data > + * > + * @offset: offset of the register controlling the divider > + * @shift: shift to the divider bit field > + * @width: width of the divider bit field > + * @enable_bit_idx: single bit controlling vclk divider enable > + * @reset_bit_idx: single bit controlling vclk divider reset > + * @table: array of value/divider pairs, last entry should have div = 0 > + * > + * Flags: > + * Same as clk_divider except CLK_DIVIDER_HIWORD_MASK which is ignored > + */ > +struct clk_regmap_vclk_div_data { > + unsigned int offset; > + u8 shift; > + u8 width; > + u8 enable_bit_idx; > + u8 reset_bit_idx; > + const struct clk_div_table *table; > + u8 flags; > +}; > + > +static inline struct clk_regmap_vclk_div_data * > +clk_get_regmap_vclk_div_data(struct clk_regmap *clk) > +{ > + return (struct clk_regmap_vclk_div_data *)clk->data; > +} > + > +extern const struct clk_ops clk_regmap_vclk_div_ops; > + > +#endif /* __VCLK_H */