diff mbox series

[RFC,07/12] clocksource: Update sh_tmu of handling.

Message ID 2d323328fba6ac55a1c3cdcefe909fad3ab0d9dc.1693384846.git.ysato@users.sourceforge.jp (mailing list archive)
State New, archived
Headers show
Series Device Tree support for SH7751 based board | expand

Commit Message

Yoshinori Sato Aug. 30, 2023, 8:42 a.m. UTC
Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp>
---
 drivers/clocksource/sh_tmu.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/drivers/clocksource/sh_tmu.c b/drivers/clocksource/sh_tmu.c
index beffff81c00f..de65e1c96780 100644
--- a/drivers/clocksource/sh_tmu.c
+++ b/drivers/clocksource/sh_tmu.c
@@ -420,9 +420,6 @@  static void sh_tmu_register_clockevent(struct sh_tmu_channel *ch,
 	ced->suspend = sh_tmu_clock_event_suspend;
 	ced->resume = sh_tmu_clock_event_resume;
 
-	dev_info(&ch->tmu->pdev->dev, "ch%u: used for clock events\n",
-		 ch->index);
-
 	clockevents_config_and_register(ced, ch->tmu->rate, 0x300, 0xffffffff);
 
 	ret = request_irq(ch->irq, sh_tmu_interrupt,
@@ -500,12 +497,12 @@  static int sh_tmu_parse_dt(struct sh_tmu_device *tmu)
 	tmu->model = SH_TMU;
 	tmu->num_channels = 3;
 
-	of_property_read_u32(np, "#renesas,channels", &tmu->num_channels);
-
-	if (tmu->num_channels != 2 && tmu->num_channels != 3) {
-		dev_err(&tmu->pdev->dev, "invalid number of channels %u\n",
-			tmu->num_channels);
-		return -EINVAL;
+	if (of_property_read_u32(np, "#renesas,channels", &tmu->num_channels)) {
+		if (tmu->num_channels != 2 && tmu->num_channels != 3) {
+			dev_err(&tmu->pdev->dev,
+				"invalid number of channels %u\n", tmu->num_channels);
+			return -EINVAL;
+		}
 	}
 
 	return 0;
@@ -513,7 +510,6 @@  static int sh_tmu_parse_dt(struct sh_tmu_device *tmu)
 
 static int sh_tmu_setup(struct sh_tmu_device *tmu, struct platform_device *pdev)
 {
-	unsigned int i;
 	int ret;
 
 	tmu->pdev = pdev;
@@ -535,6 +531,11 @@  static int sh_tmu_setup(struct sh_tmu_device *tmu, struct platform_device *pdev)
 		return -ENXIO;
 	}
 
+	if (tmu->num_channels < 2) {
+		dev_err(&tmu->pdev->dev, "Invalid channels.\n");
+		return -ENXIO;
+	}
+
 	/* Get hold of clock. */
 	tmu->clk = clk_get(&tmu->pdev->dev, "fck");
 	if (IS_ERR(tmu->clk)) {
@@ -573,12 +574,12 @@  static int sh_tmu_setup(struct sh_tmu_device *tmu, struct platform_device *pdev)
 	 * Use the first channel as a clock event device and the second channel
 	 * as a clock source.
 	 */
-	for (i = 0; i < tmu->num_channels; ++i) {
-		ret = sh_tmu_channel_setup(&tmu->channels[i], i,
-					   i == 0, i == 1, tmu);
-		if (ret < 0)
-			goto err_unmap;
-	}
+	ret = sh_tmu_channel_setup(&tmu->channels[0], 0, false, true, tmu);
+	if (ret < 0)
+		goto err_unmap;
+	ret = sh_tmu_channel_setup(&tmu->channels[1], 1, true, false, tmu);
+	if (ret < 0)
+		goto err_unmap;
 
 	platform_set_drvdata(pdev, tmu);