Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Udit Kumar <u-kumar1@ti.com>
To: <nm@ti.com>, <kristo@kernel.org>, <ssantosh@kernel.org>
Cc: <vigneshr@ti.com>, <mturquette@baylibre.com>, <sboyd@kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <linux-clk@vger.kernel.org>,
	Udit Kumar <u-kumar1@ti.com>
Subject: [PATCH v1] clk: keystone: sci-clk: Adding support for non contiguous clocks
Date: Mon, 5 Feb 2024 10:15:58 +0530	[thread overview]
Message-ID: <20240205044557.3340848-1-u-kumar1@ti.com> (raw)

Most of clocks and their parents are defined in contiguous range,
But in few cases, there is gap in clock numbers[0].

Driver assumes clocks to be in contiguous range, and assigns
accordingly.

New firmware started returning error in case of
non-available clock id.  Therefore drivers throws error while
re-calculate and other functions.

In this fix, before assigning and adding clock in list,
driver checks if given clock is valid or not.

Fixes: 3c13933c6033 ("clk: keystone: sci-clk: add support for dynamically probing clocks")

[0] https://software-dl.ti.com/tisci/esd/latest/5_soc_doc/j7200/clocks.html
Section Clocks for NAVSS0_CPTS_0 Device,
clock id 12-15 and 18-19 not present

Signed-off-by: Udit Kumar <u-kumar1@ti.com>
---
Original logs
https://gist.github.com/uditkumarti/de4b36b21247fb36725ad909ce4812f6#file-original-logs
Line 2630 for error

Logs with fix
https://gist.github.com/uditkumarti/de4b36b21247fb36725ad909ce4812f6#file-with-fix
Line 2594 

 drivers/clk/keystone/sci-clk.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/keystone/sci-clk.c b/drivers/clk/keystone/sci-clk.c
index 35fe197dd303..d417ec018d82 100644
--- a/drivers/clk/keystone/sci-clk.c
+++ b/drivers/clk/keystone/sci-clk.c
@@ -517,6 +517,8 @@ static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider)
 	int num_clks = 0;
 	int num_parents;
 	int clk_id;
+	int max_clk_id;
+	u64 freq;
 	const char * const clk_names[] = {
 		"clocks", "assigned-clocks", "assigned-clock-parents", NULL
 	};
@@ -584,6 +586,7 @@ static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider)
 				}
 
 				clk_id = args.args[1] + 1;
+				max_clk_id = clk_id + num_parents;
 
 				while (num_parents--) {
 					sci_clk = devm_kzalloc(dev,
@@ -592,11 +595,20 @@ static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider)
 					if (!sci_clk)
 						return -ENOMEM;
 					sci_clk->dev_id = args.args[0];
-					sci_clk->clk_id = clk_id++;
-					sci_clk->provider = provider;
-					list_add_tail(&sci_clk->node, &clks);
+					/* check if given clock id is valid by calling get_freq */
+					/* loop over max possible ids */
+					do {
+						sci_clk->clk_id = clk_id++;
 
-					num_clks++;
+						ret = provider->ops->get_freq(provider->sci,
+							   sci_clk->dev_id, sci_clk->clk_id, &freq);
+					} while (ret != 0 && clk_id < max_clk_id);
+
+					sci_clk->provider = provider;
+					if (ret == 0) {
+						list_add_tail(&sci_clk->node, &clks);
+						num_clks++;
+					}
 				}
 			}
 
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2024-02-05  4:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-05  4:45 Udit Kumar [this message]
2024-02-05 14:04 ` [PATCH v1] clk: keystone: sci-clk: Adding support for non contiguous clocks Nishanth Menon
2024-02-05 17:43   ` Kumar, Udit

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=20240205044557.3340848-1-u-kumar1@ti.com \
    --to=u-kumar1@ti.com \
    --cc=kristo@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=nm@ti.com \
    --cc=sboyd@kernel.org \
    --cc=ssantosh@kernel.org \
    --cc=vigneshr@ti.com \
    /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