Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp7181576pxv; Fri, 30 Jul 2021 12:02:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+/gmAGw9LY7RaU0mMiqYHHZw6fvgbPKPZRBgiWuOeAJhuUizKK/P+ZS87O1Cz+2bVC4+p X-Received: by 2002:a17:907:629c:: with SMTP id nd28mr3960851ejc.403.1627671744658; Fri, 30 Jul 2021 12:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627671744; cv=none; d=google.com; s=arc-20160816; b=z15TevLp5bHLtel5fJcY8xLZu2Esqef46xKzGKEcqOo4WVH5N8HYv43QskQg4MYYh4 jqvrZF5OOqVDpXeO50wT5Ja+4ZBtfbAhBR+A51FG8eva7M5ppVWRSfqRxxwKKYdAFVwh Kdb4Wi2jTncKj1wh6jlOrDIfaEbg6Uaj0cWoJ1AS9npRvvpCWDmAcYF06EsrCzKp11uT +Iba2JLUpr86aJ8XjKfz4r3VGJRnkhDL5FAOhBjuLAW4lyI+BPKWC+LjIBxIj08BtB2A UbT9LaKptKpqOnMx3gp9vJK55e4XHdZqMUUn10m0KNJCjFgFjT+cKQ/6ju9M3E4sIzWN jjxg== 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=E9q7G38IB4hsCBgOWK2y2XXpzyLMTjSEToSI9ejZKtQ=; b=Rg7EfhVxTUNw426J9GyZ2fVh1zbT3+8n2gpJuDa5rHhcX+l6/wkEGa3PZzdzT4KDRo QZK2AGwKTMA37o+IjGRK2OhXG1QsgrdogpXZO8lhrgryolg314xujkBQIwMeT5X5cN6T AG+n9vNDP/dEwfbVG6LPfducocdb9e85dzW84EE5RHQ6DcyvBcsvhF0DIfNLj0TViRoG WBxlmSkSwIimgxEaNHKSDalMyIekbvG/kuEpFbXvWJeEBQ3J0E0HEIZUt7GF+Kkd7hFV 4moCGK9XGLj1BxpYVxNLQ3kcIysFGiD/ebf2JXvQSUDcDTJbY+jcbFZcnpTx8ZCT3kHz c5Lw== 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 s18si2842759eji.591.2021.07.30.12.01.59; Fri, 30 Jul 2021 12:02:24 -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 S230470AbhG3TAh convert rfc822-to-8bit (ORCPT + 99 others); Fri, 30 Jul 2021 15:00:37 -0400 Received: from aposti.net ([89.234.176.197]:54948 "EHLO aposti.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230475AbhG3TA2 (ORCPT ); Fri, 30 Jul 2021 15:00:28 -0400 Date: Fri, 30 Jul 2021 20:00:08 +0100 From: Paul Cercueil Subject: Re: [PATCH v2] 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: <8GN2XQ.MOCZ4R16ZTRH1@crapouillou.net> In-Reply-To: <1627638188-116163-1-git-send-email-zhouyanjie@wanyeetech.com> References: <1627638188-116163-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, Le ven., juil. 30 2021 at 17:43:08 +0800, 周琰杰 (Zhou Yanjie) a écrit : > Use "FIELD_GET()" and "FIELD_PREP()" to simplify the code. > > Signed-off-by: 周琰杰 (Zhou Yanjie) Reviewed-by: Paul Cercueil Thanks! -Paul > --- > > Notes: > v1->v2: > Split "val = (val & ~OSTCCR_PRESCALEx_MASK) | > FIELD_PREP(OSTCCR_PRESCALEx_MASK, prescale)" > into "val &= ~OSTCCR_PRESCALEx_MASK" and "val |= > FIELD_PREP(OSTCCR_PRESCALEx_MASK, prescale)" > as Paul Cercueil's suggestion. > > drivers/clocksource/ingenic-sysost.c | 13 +++++++------ > 1 file changed, 7 insertions(+), 6 deletions(-) > > diff --git a/drivers/clocksource/ingenic-sysost.c > b/drivers/clocksource/ingenic-sysost.c > index a129840..cb6fc2f 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,8 @@ 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 &= ~OSTCCR_PRESCALE1_MASK; > + val |= FIELD_PREP(OSTCCR_PRESCALE1_MASK, prescale); > writel(val, ost_clk->ost->base + info->ostccr_reg); > > return 0; > @@ -166,7 +166,8 @@ 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 &= ~OSTCCR_PRESCALE2_MASK; > + val |= FIELD_PREP(OSTCCR_PRESCALE2_MASK, prescale); > writel(val, ost_clk->ost->base + info->ostccr_reg); > > return 0; > -- > 2.7.4 >