Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3211908rdh; Mon, 27 Nov 2023 08:42:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfXgIUstDDKFnVknpxwjkidSFK1m3n/MgR+awY3Kwct7xj6txOSKUOXQih/onT+OLhFk1i X-Received: by 2002:a17:90b:4b4c:b0:285:9833:d1af with SMTP id mi12-20020a17090b4b4c00b002859833d1afmr12977244pjb.26.1701103323911; Mon, 27 Nov 2023 08:42:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701103323; cv=none; d=google.com; s=arc-20160816; b=iMGLJSL4zI7ZkWrj8mG1fYgBgKtfFMxnlPdEzhzJeP5S1puCnUfZN8Q1TJKmuFeioL 1792UQV9mghBLsOY6goOctedQiEKjsmLLDW7ACs41bRCFkm8d5esRXj7LOgo9/1VjWz5 BS2GHIUKRRvHPfQGCr4+S2la7o4SScjqQ2WOB9sZQHvwmKbut8HoB3G3ZeBJZwrXy3Jw UdW5vVBE4MRl3fST6UqwnPrjJoNlCb+/2CxMvwWhpvy8j+jXjBAsssF+zBWa5fdxY12l 9ybjdPJlWOvlyuFeUzXP7uv4P5F0FVeudRLoQ3xFcel1tdwmooA1Qv0ptr4NL5PyELnu zSKA== 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=/Icj54IjZp5B4hkXeCz67YIlN6i5tKQ8M88cBBrEKK4=; fh=A7ubwtImesXWewLx/yJ9QvYtfUQQ9f5zRcxd60o8BnI=; b=WHS3QZVGzxsXSLC5Wb6NJ/TGuGdjvO0rbePAU+68EMXK1unsLI7s8GTaThVNiYUDLj 12A/sVIrlucol106p2xVw6c7e/Q25OmGNRUoPkwUqZ3+tOA2tm6LEBvikBzvcLPXZIAd ZHAXsCqDGRhawgfeoCNNroQqIpQ1fy/YHI8x74C1gqZE9H5yebVwQKeOn4hSTlsDznD1 M05BLom9M7Q5EQo9UHXssdZM4qCWFEFbCXFPpJ3YPWboR4xT97fFBFmxM6ddA/lGY5PD 9TxwekghHRGsnwyjjEa5aEl+0PW6a2zKi75vg4Hv+w6v/WtqWuJIgWvjXY9r70aV+3gq 4+MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=wwuA9No9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id i13-20020a17090acf8d00b002858d558cd7si8168928pju.82.2023.11.27.08.42.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 08:42:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=wwuA9No9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 5AF4B8157DF9; Mon, 27 Nov 2023 08:42:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231709AbjK0Qll (ORCPT + 99 others); Mon, 27 Nov 2023 11:41:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230504AbjK0Qlj (ORCPT ); Mon, 27 Nov 2023 11:41:39 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40CD9D2 for ; Mon, 27 Nov 2023 08:41:44 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-40b27726369so31139195e9.0 for ; Mon, 27 Nov 2023 08:41:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1701103302; x=1701708102; darn=vger.kernel.org; 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=/Icj54IjZp5B4hkXeCz67YIlN6i5tKQ8M88cBBrEKK4=; b=wwuA9No9YaegRxG0DK4kIdjjnIvATJlZaGmDcCLpkc6nY7jF7evUlCp7B7ytJR65eY n7vLeeIy8ZT+X/LRMUxxUeHTEXauXKbw2gGzO9Delibb26hhfL2ZL9mo7NTWtmgoq7KS AMizAWRhcpUTPRvvkPshtCfRbJdM313vHYcbssZPtIOiid5TR647RWADWUbVl4dqJ602 aMUtwEzLFWINKY7lqygcPtCWVlqlwtddIuBVqHTSQp77QF/pxr77xrwZGcbTz/Rha8s3 0ySSSsr9QQrzxJulkWpFsRZdgyRKrDVJoVkzmeyfLl44T4Yd0PEDSEllgHvaimJJN+3c 4LCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701103302; x=1701708102; 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=/Icj54IjZp5B4hkXeCz67YIlN6i5tKQ8M88cBBrEKK4=; b=K3UKY8EJ4KrPkHkxuW+180RQep+naSnVGLFNegExcjXXcJmogDl05kPWGSO+VzDYra Ml03GMcovzE157JGqt0UNLie/z9qd4kAfxQEb6DJujFbVD9bvEURhWG5EzYUQdU9N6L1 2To69lnXu13IKatppMgazEBzU3EcrnWLxnYa4T0Wztv35qbA7NRS77c20cYaqrB9TsAE kozfPD3ypjjYnG+HUOw/m7UZL1m5AMj/4yihxbUIDwn628JBl4WA7DiNZ31VXtKoujqt 3avSCOlJ2g66O2GVvZIqJx5+jOwoy84tOXvGTZywMAKfwV4DoQOJD93yl8G7bAVUVWPA Bi3g== X-Gm-Message-State: AOJu0YxBA6kmjoN6bJ0bL9wmsL+whv+3mZIg7rWrGbBDM/AL/0j5UZQh bjWBV/9KA0LPI3CdQclFB+mEhw== X-Received: by 2002:a5d:52ca:0:b0:332:fa1b:9f66 with SMTP id r10-20020a5d52ca000000b00332fa1b9f66mr3648641wrv.59.1701103302575; Mon, 27 Nov 2023 08:41:42 -0800 (PST) Received: from localhost ([2a01:e0a:3c5:5fb1:3675:e2e8:2f93:3d3b]) by smtp.gmail.com with ESMTPSA id c14-20020a056000104e00b00332f95ab44esm5864136wrx.57.2023.11.27.08.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 08:41:42 -0800 (PST) References: <20231124-amlogic-v6-4-upstream-dsi-ccf-vim3-v9-0-95256ed139e6@linaro.org> <20231124-amlogic-v6-4-upstream-dsi-ccf-vim3-v9-7-95256ed139e6@linaro.org> <1j7cm7dx1b.fsf@starbuckisacylon.baylibre.com> <4e5e33c1-45d5-4c83-b647-bfb603347156@linaro.org> User-agent: mu4e 1.10.8; emacs 29.1 From: Jerome Brunet To: neil.armstrong@linaro.org Cc: Jerome Brunet , Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Kevin Hilman , Martin Blumenstingl , David Airlie , Daniel Vetter , Jagan Teki , Nicolas Belin , Vinod Koul , Kishon Vijay Abraham I , Remi Pommarel , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , 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, linux-phy@lists.infradead.org, Rob Herring Subject: Re: [PATCH v9 07/12] clk: meson: add vclk driver Date: Mon, 27 Nov 2023 17:24:03 +0100 In-reply-to: <4e5e33c1-45d5-4c83-b647-bfb603347156@linaro.org> Message-ID: <1jfs0rywqi.fsf@starbuckisacylon.baylibre.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 27 Nov 2023 08:42:00 -0800 (PST) On Mon 27 Nov 2023 at 17:14, Neil Armstrong wrote: > On 24/11/2023 15:41, Jerome Brunet wrote: >> On Fri 24 Nov 2023 at 09:41, 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. >>> >>> Signed-off-by: Neil Armstrong >>> --- >>> drivers/clk/meson/Kconfig | 5 ++ >>> drivers/clk/meson/Makefile | 1 + >>> drivers/clk/meson/vclk.c | 141 +++++++++++++++++++++++++++++++++++++++++++++ >>> drivers/clk/meson/vclk.h | 51 ++++++++++++++++ >>> 4 files changed, 198 insertions(+) >>> >>> diff --git a/drivers/clk/meson/Kconfig b/drivers/clk/meson/Kconfig >>> index 29ffd14d267b..59a40a49f8e1 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 >> This particular line belong in the next patch >> >>> 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 9ee4b954c896..9ba43fe7a07a 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..47f08a52b49f >>> --- /dev/null >>> +++ b/drivers/clk/meson/vclk.c >>> @@ -0,0 +1,141 @@ >>> +// 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 inline struct clk_regmap_vclk_data * >>> +clk_get_regmap_vclk_data(struct clk_regmap *clk) >>> +{ >>> + return (struct clk_regmap_vclk_data *)clk->data; >>> +} >>> + >>> +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); >>> + >>> + meson_parm_write(clk->map, &vclk->enable, 1); >>> + >>> + /* Do a reset pulse */ >>> + meson_parm_write(clk->map, &vclk->reset, 1); >>> + meson_parm_write(clk->map, &vclk->reset, 0); >>> + >>> + 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); >>> + >>> + meson_parm_write(clk->map, &vclk->enable, 0); >>> +} >>> + >>> +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); >>> + >>> + return meson_parm_read(clk->map, &vclk->enable); >>> +} >>> + >>> +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); >> s/clk_regmap_vclk/meson_vclk at least for what is exported, ideally most >> all the code. >> I get clk_regmap_ comes from code copied from clk_regmap.c. >> The reason the this part is different (and not using parm) if that when >> I converted amlogic to regmap, I hope we could make this generic, >> possibly converging between aml and qcom (which was the only other >> platform using regmap for clock at the time). This is why clk_regmap.c >> is a bit different from the other driver. >> For the aml specific drivers, best to look at the mpll or cpu-dyndiv one. >> >>> + >>> +/* The VCLK Divider has supplementary reset & enable bits */ >>> + >>> +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; >>> +} >>> + >>> +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); >>> + >>> + return divider_recalc_rate(hw, prate, meson_parm_read(clk->map, &vclk->div), >>> + vclk->table, vclk->flags, vclk->div.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->div.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); >>> + int ret; >>> + >>> + ret = divider_get_val(rate, parent_rate, vclk->table, vclk->div.width, >>> + vclk->flags); >>> + if (ret < 0) >>> + return ret; >>> + >>> + meson_parm_write(clk->map, &vclk->div, ret); >>> + >>> + return 0; >>> +}; >>> + >>> +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 */ >>> + meson_parm_write(clk->map, &vclk->reset, 0); >>> + meson_parm_write(clk->map, &vclk->enable, 1); >>> + >>> + return 0; >>> +} >>> + >>> +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 */ >>> + meson_parm_write(clk->map, &vclk->enable, 0); >>> + meson_parm_write(clk->map, &vclk->reset, 1); >>> +} >>> + >>> +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); >>> + >>> + return meson_parm_read(clk->map, &vclk->enable); >>> +} >>> + >>> +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..4f25d7ad2717 >>> --- /dev/null >>> +++ b/drivers/clk/meson/vclk.h > > Is vclk.c/h ok ? clk-vclk doesn't look pretty, but I can switch to it to > keep files organized. I don't have a strong opinion about it. I would have suggested vclk-div.c/h - like sclk ... but you do have gate ops in there, so ... :/ This made me realize that one does not really go without the other. It is more a coherent block, isn't it ? Would it make more sense to have these 2 merged in a single clk_ops ? It's bit late to point this out, sorry about that. I let you decide whether to merge the ops or not and which name to pick. If you keep them separated, meson_vclk_gate_ops instead of just meson_vclk_ops, to make things clear. > > Neil > >>> @@ -0,0 +1,51 @@ >>> +/* SPDX-License-Identifier: GPL-2.0 */ >>> +/* >>> + * Copyright (c) 2023 Neil Armstrong >>> + */ >>> + >>> +#ifndef __VCLK_H >>> +#define __VCLK_H >> This is too generic. >> Please add the MESON prefix like the other clock driver please. >> >>> + >>> +#include "clk-regmap.h" >>> +#include "parm.h" >>> + >>> +/** >>> + * struct clk_regmap_vclk_data - vclk regmap backed specific data >>> + * >>> + * @enable: vclk enable field >>> + * @reset: vclk reset field >>> + * @flags: hardware-specific flags >>> + * >>> + * Flags: >>> + * Same as clk_gate except CLK_GATE_HIWORD_MASK which is ignored >>> + */ >>> +struct clk_regmap_vclk_data { >>> + struct parm enable; >>> + struct parm reset; >>> + u8 flags; >>> +}; >>> + >>> +extern const struct clk_ops clk_regmap_vclk_ops; >>> + >>> +/** >>> + * struct clk_regmap_vclk_div_data - vclk_div regmap back specific data >>> + * >>> + * @div: divider field >>> + * @enable: vclk divider enable field >>> + * @reset: vclk divider reset field >>> + * @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 { >>> + struct parm div; >>> + struct parm enable; >>> + struct parm reset; >>> + const struct clk_div_table *table; >>> + u8 flags; >>> +}; >>> + >>> +extern const struct clk_ops clk_regmap_vclk_div_ops; >>> + >>> +#endif /* __VCLK_H */ >> -- Jerome