Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp2082111pxv; Sat, 24 Jul 2021 04:58:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8Wkabdnic2D1IvqoZuvnmt+XOTwFIu8PzI+NiPKElDRUvB5Yo1RR9gpyIOKKsB1TYDwe/ X-Received: by 2002:a50:8d54:: with SMTP id t20mr10414376edt.288.1627127912550; Sat, 24 Jul 2021 04:58:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627127912; cv=none; d=google.com; s=arc-20160816; b=aTfY4g74beBdGM96amP2LfDt/h25diXMYpEAT/jcgx8Bs2HNrpMs6RXL7fBccEDrER SHN4aR0Pr2b6QGoOFCmNgd+FRrkR0foXioZLPQaFHzRzpDoJv0kbdypPjGr5R7a6avkZ rWRG2DWtioWnWImNB+pvhngAQmRR1QiST4gMpfLNMfwLi1488vlk8Hs+d11HA3YLSsD2 2RKJu3bQimeHRHmjKmfEqaCMw4ocRIPDrn7wMVq8V15wlfPKDHbtZooM9JnJAsldY6rx yI5AWOGyPbpTEb75zmLDxfzDXkPVKx8byYtPkORlgZrX4DtQKnOSnkgMcoPulAXi5K/u RIjw== 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 :references:in-reply-to:message-id:cc:to:subject:from:date; bh=l543cUy+CWX4p4uCypUnixth1rMp4gDHDGD7WuejF/c=; b=xMyC61yCwUFJpaj1Q7hyHH5Bcr2N7j8OE3PSSOvHXxc+4dHXN16jwOX+zFYqaVokj0 zVVa+NC5ZoOas3JBBBmghzE+ylk/P6BaqFIjI0aNMZxC9kMwrXsRm9540nljM2HE4G6t 5+yArId+0Nz//G31BRLpxygdE1XvNMJpPZm84HxZ8CSFuH3a27BuHkozt8C9xqQnsXG2 y9F+QordJ8Tun40eAOuqyymLuDVdPCoMr74wJ9Hlkn3ZcmJEOIpNEu3XtCLU3TnZy2dq dD7xcQ/+SPntZCFEH2QEGNKY4QSHS2c4/mF4oci90Oney0X59iMIQR7YydYKwefXioFJ uHXg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gv42si35132942ejc.215.2021.07.24.04.58.06; Sat, 24 Jul 2021 04:58:32 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231965AbhGXLOD convert rfc822-to-8bit (ORCPT + 99 others); Sat, 24 Jul 2021 07:14:03 -0400 Received: from aposti.net ([89.234.176.197]:59196 "EHLO aposti.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231511AbhGXLOD (ORCPT ); Sat, 24 Jul 2021 07:14:03 -0400 Date: Sat, 24 Jul 2021 12:54:24 +0100 From: Paul Cercueil Subject: Re: [PATCH] clocksource: Ingenic: Improve the code. To: =?UTF-8?b?5ZGo55Cw5p2w?= Cc: daniel.lezcano@linaro.org, tglx@linutronix.de, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, dongsheng.qiu@ingenic.com, aric.pzqi@ingenic.com, rick.tyliu@ingenic.com, sihui.liu@ingenic.com, jun.jiang@ingenic.com, sernia.zhou@foxmail.com Message-Id: In-Reply-To: <1627121407-131028-1-git-send-email-zhouyanjie@wanyeetech.com> References: <1627121407-131028-1-git-send-email-zhouyanjie@wanyeetech.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Zhou, Thanks! I actually had a similar patch locally that I was eventually going to send. Le sam., juil. 24 2021 at 18:10:07 +0800, 周琰杰 (Zhou Yanjie) a écrit : > Use "FIELD_GET()" and "FIELD_PREP()" to simplify the code. > > Signed-off-by: 周琰杰 (Zhou Yanjie) > --- > drivers/clocksource/ingenic-sysost.c | 11 +++++------ > 1 file changed, 5 insertions(+), 6 deletions(-) > > diff --git a/drivers/clocksource/ingenic-sysost.c > b/drivers/clocksource/ingenic-sysost.c > index a129840..1fbea59 100644 > --- a/drivers/clocksource/ingenic-sysost.c > +++ b/drivers/clocksource/ingenic-sysost.c > @@ -4,6 +4,7 @@ > * Copyright (c) 2020 周琰杰 (Zhou Yanjie) > > */ > > +#include > #include > #include > #include > @@ -34,8 +35,6 @@ > /* bits within the OSTCCR register */ > #define OSTCCR_PRESCALE1_MASK 0x3 > #define OSTCCR_PRESCALE2_MASK 0xc > -#define OSTCCR_PRESCALE1_LSB 0 > -#define OSTCCR_PRESCALE2_LSB 2 > > /* bits within the OSTCR register */ > #define OSTCR_OST1CLR BIT(0) > @@ -98,7 +97,7 @@ static unsigned long > ingenic_ost_percpu_timer_recalc_rate(struct clk_hw *hw, > > prescale = readl(ost_clk->ost->base + info->ostccr_reg); > > - prescale = (prescale & OSTCCR_PRESCALE1_MASK) >> > OSTCCR_PRESCALE1_LSB; > + prescale = FIELD_GET(OSTCCR_PRESCALE1_MASK, prescale); > > return parent_rate >> (prescale * 2); > } > @@ -112,7 +111,7 @@ static unsigned long > ingenic_ost_global_timer_recalc_rate(struct clk_hw *hw, > > prescale = readl(ost_clk->ost->base + info->ostccr_reg); > > - prescale = (prescale & OSTCCR_PRESCALE2_MASK) >> > OSTCCR_PRESCALE2_LSB; > + prescale = FIELD_GET(OSTCCR_PRESCALE2_MASK, prescale); > > return parent_rate >> (prescale * 2); > } > @@ -151,7 +150,7 @@ static int > ingenic_ost_percpu_timer_set_rate(struct clk_hw *hw, unsigned long re > int val; > > val = readl(ost_clk->ost->base + info->ostccr_reg); > - val = (val & ~OSTCCR_PRESCALE1_MASK) | (prescale << > OSTCCR_PRESCALE1_LSB); > + val = (val & ~OSTCCR_PRESCALE1_MASK) | > FIELD_PREP(OSTCCR_PRESCALE1_MASK, prescale); Just one nitpick, I'd prefer this: val ~= &OSTCCR_PRESCALE1_MASK; val |= FIELD_PREP(OSTCCR_PRESCALE1_MASK, prescale); > writel(val, ost_clk->ost->base + info->ostccr_reg); > > return 0; > @@ -166,7 +165,7 @@ static int > ingenic_ost_global_timer_set_rate(struct clk_hw *hw, unsigned long re > int val; > > val = readl(ost_clk->ost->base + info->ostccr_reg); > - val = (val & ~OSTCCR_PRESCALE2_MASK) | (prescale << > OSTCCR_PRESCALE2_LSB); > + val = (val & ~OSTCCR_PRESCALE2_MASK) | > FIELD_PREP(OSTCCR_PRESCALE2_MASK, prescale); Same here. Cheers, -Paul > writel(val, ost_clk->ost->base + info->ostccr_reg); > > return 0; > -- > 2.7.4 >