From: Yu Tu <yu.tu@amlogic.com>
To: <linux-clk@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-amlogic@lists.infradead.org>,
<linux-kernel@vger.kernel.org>,
"Neil Armstrong" <neil.armstrong@linaro.org>,
Jerome Brunet <jbrunet@baylibre.com>,
Kevin Hilman <khilman@baylibre.com>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
"Martin Blumenstingl" <martin.blumenstingl@googlemail.com>
Cc: <kelvin.zhang@amlogic.com>, <qi.duan@amlogic.com>,
Yu Tu <yu.tu@amlogic.com>
Subject: [PATCH V2] clk: meson: vid-pll-div: added meson_vid_pll_div_ops support
Date: Mon, 20 Mar 2023 19:34:45 +0800 [thread overview]
Message-ID: <20230320113445.17260-1-yu.tu@amlogic.com> (raw)
Since the previous code only provides "ro_ops" for the vid_pll_div
clock. In fact, the clock can be set. So add "ops" that can set the
clock, especially for later chips like S4 SOC and so on.
Signed-off-by: Yu Tu <yu.tu@amlogic.com>
---
drivers/clk/meson/vid-pll-div.c | 67 +++++++++++++++++++++++++++++++++
drivers/clk/meson/vid-pll-div.h | 3 ++
2 files changed, 70 insertions(+)
diff --git a/drivers/clk/meson/vid-pll-div.c b/drivers/clk/meson/vid-pll-div.c
index daff235bc763..3c9015944f24 100644
--- a/drivers/clk/meson/vid-pll-div.c
+++ b/drivers/clk/meson/vid-pll-div.c
@@ -89,6 +89,73 @@ static unsigned long meson_vid_pll_div_recalc_rate(struct clk_hw *hw,
return DIV_ROUND_UP_ULL(parent_rate * div->multiplier, div->divider);
}
+static int meson_vid_pll_div_determine_rate(struct clk_hw *hw,
+ struct clk_rate_request *req)
+{
+ unsigned long parent_rate, best = 0, now = 0, rate;
+ unsigned long parent_rate_saved = req->best_parent_rate;
+ unsigned int i, best_i = 0;
+
+ for (i = 0 ; i < VID_PLL_DIV_TABLE_SIZE; ++i) {
+ rate = DIV_ROUND_CLOSEST_ULL(req->rate * vid_pll_div_table[i].divider,
+ vid_pll_div_table[i].multiplier);
+ if (parent_rate_saved == rate) {
+ req->best_parent_rate = parent_rate_saved;
+ best_i = i;
+ break;
+ }
+
+ parent_rate = clk_hw_round_rate(req->best_parent_hw, rate);
+ now = DIV_ROUND_CLOSEST_ULL(parent_rate *
+ vid_pll_div_table[i].multiplier,
+ vid_pll_div_table[i].divider);
+ if (abs(now - req->rate) < abs(best - req->rate)) {
+ best = now;
+ best_i = i;
+ req->best_parent_rate = parent_rate;
+ }
+ }
+
+ req->rate = DIV_ROUND_CLOSEST_ULL(req->best_parent_rate *
+ vid_pll_div_table[best_i].multiplier,
+ vid_pll_div_table[best_i].divider);
+
+ return 0;
+}
+
+static int meson_vid_pll_div_set_rate(struct clk_hw *hw, unsigned long rate,
+ unsigned long parent_rate)
+{
+ struct clk_regmap *clk = to_clk_regmap(hw);
+ struct meson_vid_pll_div_data *pll_div = meson_vid_pll_div_data(clk);
+ unsigned long best = 0, now = 0;
+ unsigned int i, best_i = 0;
+
+ for (i = 0 ; i < VID_PLL_DIV_TABLE_SIZE; ++i) {
+ now = DIV_ROUND_CLOSEST_ULL(parent_rate * vid_pll_div_table[i].multiplier,
+ vid_pll_div_table[i].divider);
+ if (now == rate) {
+ best_i = i;
+ break;
+ } else if (abs(now - rate) < abs(best - rate)) {
+ best = now;
+ best_i = i;
+ }
+ }
+
+ meson_parm_write(clk->map, &pll_div->val, vid_pll_div_table[best_i].shift_val);
+ meson_parm_write(clk->map, &pll_div->sel, vid_pll_div_table[best_i].shift_sel);
+
+ return 0;
+}
+
+const struct clk_ops meson_vid_pll_div_ops = {
+ .recalc_rate = meson_vid_pll_div_recalc_rate,
+ .determine_rate = meson_vid_pll_div_determine_rate,
+ .set_rate = meson_vid_pll_div_set_rate,
+};
+EXPORT_SYMBOL_GPL(meson_vid_pll_div_ops);
+
const struct clk_ops meson_vid_pll_div_ro_ops = {
.recalc_rate = meson_vid_pll_div_recalc_rate,
};
diff --git a/drivers/clk/meson/vid-pll-div.h b/drivers/clk/meson/vid-pll-div.h
index c0128e33ccf9..bbccab340910 100644
--- a/drivers/clk/meson/vid-pll-div.h
+++ b/drivers/clk/meson/vid-pll-div.h
@@ -10,11 +10,14 @@
#include <linux/clk-provider.h>
#include "parm.h"
+#define VID_PLL_DIV_TABLE_SIZE 14
+
struct meson_vid_pll_div_data {
struct parm val;
struct parm sel;
};
extern const struct clk_ops meson_vid_pll_div_ro_ops;
+extern const struct clk_ops meson_vid_pll_div_ops;
#endif /* __MESON_VID_PLL_DIV_H */
--
2.33.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
next reply other threads:[~2023-03-20 11:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-20 11:34 Yu Tu [this message]
2023-03-20 15:35 ` [PATCH V2] clk: meson: vid-pll-div: added meson_vid_pll_div_ops support Martin Blumenstingl
2023-03-21 2:29 ` Yu Tu
2023-03-21 9:41 ` Jerome Brunet
2023-03-22 7:46 ` Yu Tu
2023-03-22 8:41 ` Jerome Brunet
2023-04-07 10:08 ` Yu Tu
2023-04-11 7:02 ` Jerome Brunet
2023-04-13 9:01 ` Yu Tu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230320113445.17260-1-yu.tu@amlogic.com \
--to=yu.tu@amlogic.com \
--cc=jbrunet@baylibre.com \
--cc=kelvin.zhang@amlogic.com \
--cc=khilman@baylibre.com \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=mturquette@baylibre.com \
--cc=neil.armstrong@linaro.org \
--cc=qi.duan@amlogic.com \
--cc=sboyd@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox