Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp258915pxb; Thu, 14 Jan 2021 05:23:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJz2r+06XJoEqi1HmGu3B56+KjOnSyWHIthuAi4oI/78Cboft89Ut3mFmaE7wElxS9h9gPTU X-Received: by 2002:a05:6402:a53:: with SMTP id bt19mr5834674edb.104.1610630592514; Thu, 14 Jan 2021 05:23:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610630592; cv=none; d=google.com; s=arc-20160816; b=blf1Xm0gVrL+C4pfr9HR/VG8SLlCDABmzT9qxg/bFxW8zriPowvDnt5sTQ6HBKZxpl 5NDVhvpvJGvVoRn5pI/u70ClXwN6ldprvvS86AKCnKW8Xr3go3CxSHJlgXDIdHP+eqqi FqP2H94J7lcH1zxWgstTEO0M6CdBo23qnXAYjJF/wzF4Q4xXWwkqtmp29cl6OQmWrmk6 Nt19WGaBG3tDZDB9rUKqSqHZSGLKcgB6ZZpnUML8mQe3GHZdxUsX1bmNxEsXmxDHD8OV DnTuiwTb0BzAwntKPxq6ZpRLbiWs6EOt/R1ByGYZCk5Gh7QZKgcGADc7dKfkQeWOiwtj yF3g== 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=hcNZRFOzq6H7J/oQHaMSzlGN+cenzib5DvTngxIzX78=; b=TVBtMNAncpduBCaKxqFb8WafrBds3jCAqjE0Kpqpwq9kEUHuLb1Aps0w5mJdOcMZwm qZAru3AUzEkuhhghTW1xwCc21JAy8kIMAX1NG7OBELaWeGalijjCLVi6iDt5R41asVVn J1ZFldM5HqgVFsnJ/7PSn7EA3GFb2BfG2ePrCzjAPD1pmonPg38vno57Uq3H/BgxjoCA x51+JE2tjoa7ROdDr8ialepdOMzZZvfsJ50qQmZao5PZm+32ijUGaYRK/6h06idBeNoQ gh9LNb4oG/T6da7UBuRdclnCFeIn79ztfv17QcqWhvhOkgmH2MDcGjA3xhq42r5qzYO2 lapQ== 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 k27si2245198ejg.317.2021.01.14.05.22.47; Thu, 14 Jan 2021 05:23:12 -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 S1728252AbhANNSp (ORCPT + 99 others); Thu, 14 Jan 2021 08:18:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728873AbhANNSp (ORCPT ); Thu, 14 Jan 2021 08:18:45 -0500 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80D14C061575 for ; Thu, 14 Jan 2021 05:18:03 -0800 (PST) Received: from ramsan.of.borg ([84.195.186.194]) by laurent.telenet-ops.be with bizsmtp id GdHy2400u4C55Sk01dHy0g; Thu, 14 Jan 2021 14:18:01 +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 1l02Vi-003YpD-AT; Thu, 14 Jan 2021 14:17:58 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1l02Vh-009NeQ-SO; Thu, 14 Jan 2021 14:17:57 +0100 From: Geert Uytterhoeven To: Daniel Lezcano , Thomas Gleixner Cc: Magnus Damm , linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven , =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCH v2] clocksource/drivers/sh_cmt: Make sure channel clock supply is enabled Date: Thu, 14 Jan 2021 14:17:56 +0100 Message-Id: <20210114131756.2235821-1-geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 Reviewed-by: Niklas Söderlund --- Tested on R-Mobile APE6, R-Car M2-W, and R-Car H3 ES2.0. v2: - Add Reviewed-by. --- 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