Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp510320pxu; Fri, 11 Dec 2020 07:33:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxQWI1M4NxYNTbp6vq/kGG3bC3+J4Bk+LoXcC+9X1W2jOFYeORfmDc+VVaIFk+44b3Jrtda X-Received: by 2002:a17:906:145b:: with SMTP id q27mr11708393ejc.86.1607700817897; Fri, 11 Dec 2020 07:33:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607700817; cv=none; d=google.com; s=arc-20160816; b=Uhp9P1oUB1k4tEDBWlJXhOWg++vVrPhufBmG1YPoGjZyO98+Ofm9f3slpohdzCC9px lrJkzaiGZcYe3ZM30LkjkPGKC6SH79rUlbpbs132VC2oVjl87dY0r3wnvwKs3KMzfwiX p6tu3+hl0ACGel9vxylQZcRtFDed2tUyDN7ZKYsHiqqzO7snIEIf0GLEXZLQzgoCzMAG wgWSl6ADUvu7qWKxXkPB9oqqI/deIXjGK2jmp/N2UR1PgExmDfTh9Vv0HW7j/taMEzF1 EMOryJKHlm4vCtrvYbIhsMceK5T2zFbcROthRA3hKrhK6hzCD0Fy4AjTARCz0B0brpSo wbsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=RIyDPIgIgz/S0OaWXOG+o4O3wHTJvtd/CzzDO0mE9J4=; b=M/bzvs/6LMj+glHTdDGlfYM09qT3r8F+MS6uiGY1DEXI8V3lHzFapsuRwwJ3XnPDdm t4/SQOsw3TYZBBImBF+qDnrP6DiZNQhnz605C/8Ishi6/U6DYHYmfVUiyrCXFLKx5BP/ blZSokffaq3q7QTj6Od28R8SrH5oREwpNVp6+ZV3Rq6rvDDiq2/ti5h8ycS//hBj/7wd ZXPRoboIc+sHjuQrUDl1FxXkMDSV22e1SRS1AUW6ioVGLAWgRBWkkRqjlk8oEUmqjO8y JnPI98LaNxFVIn2dG/lrk6bomszirlfpd7fK79GRL0qI4jeVGUcu2NcqcEyqOSaxJQz+ f4Ag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gb31si3367600ejc.669.2020.12.11.07.33.14; Fri, 11 Dec 2020 07:33:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393479AbgLJTrn (ORCPT + 99 others); Thu, 10 Dec 2020 14:47:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393619AbgLJTrn (ORCPT ); Thu, 10 Dec 2020 14:47:43 -0500 Received: from michel.telenet-ops.be (michel.telenet-ops.be [IPv6:2a02:1800:110:4::f00:18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62E2FC0613D6 for ; Thu, 10 Dec 2020 11:46:55 -0800 (PST) Received: from ramsan.of.borg ([84.195.186.194]) by michel.telenet-ops.be with bizsmtp id 2jmq2400G4C55Sk06jmqLb; Thu, 10 Dec 2020 20:46:51 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1knRtq-009VCz-Ga; Thu, 10 Dec 2020 20:46:50 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1knRtp-00CAva-NM; Thu, 10 Dec 2020 20:46:49 +0100 From: Geert Uytterhoeven To: Daniel Lezcano , Thomas Gleixner Cc: =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Magnus Damm , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] clocksource/drivers/sh_cmt: Make sure channel clock supply is enabled Date: Thu, 10 Dec 2020 20:46:48 +0100 Message-Id: <20201210194648.2901899-1-geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The Renesas Compare Match Timer 0 and 1 (CMT0/1) variants have a register to control the clock supply to the individual channels. Currently the driver does not touch this register, and relies on the documented initial value, which has the clock supply enabled for all channels present. However, when Linux starts on the APE6-EVM development board, only the clock supply to the first CMT1 channel is enabled. Hence the first channel (used as a clockevent) works, while the second channel (used as a clocksource) does not. Note that the default system clocksource is the Cortex-A15 architectured timer, and the user needs to manually switch to the CMT1 clocksource to trigger the broken behavior. Fix this by removing the fragile dependency on implicit reset and/or boot loader state, and by enabling the clock supply explicitly for all channels used instead. This requires postponing the clk_disable() call, else the timer's registers cannot be accessed in sh_cmt_setup_channel(). Signed-off-by: Geert Uytterhoeven --- Tested on R-Mobile APE6, R-Car M2-W, and R-Car H3 ES2.0. --- drivers/clocksource/sh_cmt.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index e258230d432c0002..c98f8851fd680454 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c @@ -235,6 +235,8 @@ static const struct sh_cmt_info sh_cmt_info[] = { #define CMCNT 1 /* channel register */ #define CMCOR 2 /* channel register */ +#define CMCLKE 0x1000 /* CLK Enable Register (R-Car Gen2) */ + static inline u32 sh_cmt_read_cmstr(struct sh_cmt_channel *ch) { if (ch->iostart) @@ -853,6 +855,7 @@ static int sh_cmt_setup_channel(struct sh_cmt_channel *ch, unsigned int index, unsigned int hwidx, bool clockevent, bool clocksource, struct sh_cmt_device *cmt) { + u32 value; int ret; /* Skip unused channels. */ @@ -882,6 +885,11 @@ static int sh_cmt_setup_channel(struct sh_cmt_channel *ch, unsigned int index, ch->iostart = cmt->mapbase + ch->hwidx * 0x100; ch->ioctrl = ch->iostart + 0x10; ch->timer_bit = 0; + + /* Enable the clock supply to the channel */ + value = ioread32(cmt->mapbase + CMCLKE); + value |= BIT(hwidx); + iowrite32(value, cmt->mapbase + CMCLKE); break; } @@ -1014,12 +1022,10 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev) else cmt->rate = clk_get_rate(cmt->clk) / 8; - clk_disable(cmt->clk); - /* Map the memory resource(s). */ ret = sh_cmt_map_memory(cmt); if (ret < 0) - goto err_clk_unprepare; + goto err_clk_disable; /* Allocate and setup the channels. */ cmt->num_channels = hweight8(cmt->hw_channels); @@ -1047,6 +1053,8 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev) mask &= ~(1 << hwidx); } + clk_disable(cmt->clk); + platform_set_drvdata(pdev, cmt); return 0; @@ -1054,6 +1062,8 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev) err_unmap: kfree(cmt->channels); iounmap(cmt->mapbase); +err_clk_disable: + clk_disable(cmt->clk); err_clk_unprepare: clk_unprepare(cmt->clk); err_clk_put: -- 2.25.1