From patchwork Tue Dec 4 19:48:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 10712561 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 541C7109C for ; Tue, 4 Dec 2018 19:48:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41DE428F2C for ; Tue, 4 Dec 2018 19:48:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 338CE2A13B; Tue, 4 Dec 2018 19:48:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD81528F2C for ; Tue, 4 Dec 2018 19:48:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725880AbeLDTs0 (ORCPT ); Tue, 4 Dec 2018 14:48:26 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:41759 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725859AbeLDTs0 (ORCPT ); Tue, 4 Dec 2018 14:48:26 -0500 Received: by mail-lj1-f196.google.com with SMTP id z80-v6so16050164ljb.8 for ; Tue, 04 Dec 2018 11:48:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cogentembedded-com.20150623.gappssmtp.com; s=20150623; h=subject:from:to:references:organization:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=sc8MvtQxCmVpiClgDNU/2M1d/NPNsLLlA1tVvSdzAag=; b=rjj9veCXkRUrVeqNHxRo34F/aPmBy/We/ZCRXteBPUmtYl1UNztwCqLO2mzdzBSw3D 9fZCCbRHvRPzpTz9IpLJnYSGjsZ853cWBvQmEVBAgqWcb8820v0NczssMntnP5MJ1dwF E2FFizQtMEm9XC2/ViehOY2mTkL01KeZ+CNAUFxgCsz1MSyQBGkn1Fp2MBteFVG83Ork jgWwSrq7c+6gFiwI5MjBLMSGwlViBW7INluY0ql3xyrmMRKtnYZb9Sj3xWOLjHzUMgHq S+Gk8gA0AhBt44mjRtQcRyqHpYQsw2UE++lnfWBUaY7+EnnGKV+alOWgA6gDpOlVptdW C8Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=sc8MvtQxCmVpiClgDNU/2M1d/NPNsLLlA1tVvSdzAag=; b=kty9gIfZqDR3F79bsju9/eSymw9bMCjvILy7SoP9E+5CRnqlAiTS9fwSAXzFPSMKKA IvRJqpuaTwoDBDsAZsTW2hoE2wf24dfLJT/mUeZao2fealnlM7slsi1qRsdOCRknllzk vSjrWAj6PDouzyRbgzUCxEoImVZmhCwEH+6Pvci3AMvkJHIRyDbiIvHcWQ5HikT+wEeh X8ZSwgg9LFpx8nGOwu4dVm+E7gDSLDrhMQ1YSjXxT493fcCv7165NPB2pb9ttYH9XvVJ 6xZZNQCKFisR+sD52HEFC3aw+QPFmD1ybPwmTagPj2EiE4d6RizVGoxq0y5ec6lZxKoA br3Q== X-Gm-Message-State: AA+aEWaJmAZ5tIkwUOSfj2+3SA96oxmYYQKMnHtwjxzhqW5PeUt5y8Ey JnKA+x/tNI9XsOQ1eQ5x3b3acA== X-Google-Smtp-Source: AFSGD/VDbw7BWIUxmITAeKl8Pc+RNZ5enmRmpe1xQwH9PkFIyWq1MdbhCksO2yaRH8p0DYRLHFtmbw== X-Received: by 2002:a2e:9107:: with SMTP id m7-v6mr13831958ljg.23.1543952903309; Tue, 04 Dec 2018 11:48:23 -0800 (PST) Received: from wasted.cogentembedded.com ([31.173.84.250]) by smtp.gmail.com with ESMTPSA id u15-v6sm3595917lja.63.2018.12.04.11.48.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Dec 2018 11:48:22 -0800 (PST) Subject: [PATCH v2 1/4] clk: renesas: rcar-gen3-cpg: factor out cpg_reg_modify() From: Sergei Shtylyov To: linux-renesas-soc@vger.kernel.org, Michael Turquette , Stephen Boyd , Geert Uytterhoeven , linux-clk@vger.kernel.org References: Organization: Cogent Embedded Message-ID: <8d3bd6b4-61eb-ceef-dc99-eb26c83f9e03@cogentembedded.com> Date: Tue, 4 Dec 2018 22:48:21 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-MW Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There's quite often repeated sequence of a CPG register read-modify-write, so it seems worth factoring it out into a function -- this saves 68 bytes of the object code (AArch64 gcc 4.8.5) and simplifies protecting all such sequences with a spinlock in the next patch... Signed-off-by: Sergei Shtylyov Reviewed-by: Simon Horman Reviewed-by: Geert Uytterhoeven --- Changes in version 2: - moved the readl() call from the initializer in cpg_reg_modify(); - adjusted the patch description. drivers/clk/renesas/rcar-gen3-cpg.c | 38 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) Index: renesas-drivers/drivers/clk/renesas/rcar-gen3-cpg.c =================================================================== --- renesas-drivers.orig/drivers/clk/renesas/rcar-gen3-cpg.c +++ renesas-drivers/drivers/clk/renesas/rcar-gen3-cpg.c @@ -30,6 +30,16 @@ #define CPG_RCKCR_CKSEL BIT(15) /* RCLK Clock Source Select */ +static void cpg_reg_modify(void __iomem *reg, u32 clear, u32 set) +{ + u32 val; + + val = readl(reg); + val &= ~clear; + val |= set; + writel(val, reg); +}; + struct cpg_simple_notifier { struct notifier_block nb; void __iomem *reg; @@ -118,7 +128,6 @@ static int cpg_z_clk_set_rate(struct clk struct cpg_z_clk *zclk = to_z_clk(hw); unsigned int mult; unsigned int i; - u32 val, kick; /* Factor of 2 is for fixed divider */ mult = DIV_ROUND_CLOSEST_ULL(rate * 32ULL * 2, parent_rate); @@ -127,17 +136,14 @@ static int cpg_z_clk_set_rate(struct clk if (readl(zclk->kick_reg) & CPG_FRQCRB_KICK) return -EBUSY; - val = readl(zclk->reg) & ~zclk->mask; - val |= ((32 - mult) << __ffs(zclk->mask)) & zclk->mask; - writel(val, zclk->reg); + cpg_reg_modify(zclk->reg, zclk->mask, + ((32 - mult) << __ffs(zclk->mask)) & zclk->mask); /* * Set KICK bit in FRQCRB to update hardware setting and wait for * clock change completion. */ - kick = readl(zclk->kick_reg); - kick |= CPG_FRQCRB_KICK; - writel(kick, zclk->kick_reg); + cpg_reg_modify(zclk->kick_reg, 0, CPG_FRQCRB_KICK); /* * Note: There is no HW information about the worst case latency. @@ -262,12 +268,10 @@ static const struct sd_div_table cpg_sd_ static int cpg_sd_clock_enable(struct clk_hw *hw) { struct sd_clock *clock = to_sd_clock(hw); - u32 val = readl(clock->csn.reg); - - val &= ~(CPG_SD_STP_MASK); - val |= clock->div_table[clock->cur_div_idx].val & CPG_SD_STP_MASK; - writel(val, clock->csn.reg); + cpg_reg_modify(clock->csn.reg, CPG_SD_STP_MASK, + clock->div_table[clock->cur_div_idx].val & + CPG_SD_STP_MASK); return 0; } @@ -276,7 +280,7 @@ static void cpg_sd_clock_disable(struct { struct sd_clock *clock = to_sd_clock(hw); - writel(readl(clock->csn.reg) | CPG_SD_STP_MASK, clock->csn.reg); + cpg_reg_modify(clock->csn.reg, 0, CPG_SD_STP_MASK); } static int cpg_sd_clock_is_enabled(struct clk_hw *hw) @@ -323,7 +327,6 @@ static int cpg_sd_clock_set_rate(struct { struct sd_clock *clock = to_sd_clock(hw); unsigned int div = cpg_sd_clock_calc_div(clock, rate, parent_rate); - u32 val; unsigned int i; for (i = 0; i < clock->div_num; i++) @@ -335,10 +338,9 @@ static int cpg_sd_clock_set_rate(struct clock->cur_div_idx = i; - val = readl(clock->csn.reg); - val &= ~(CPG_SD_STP_MASK | CPG_SD_FC_MASK); - val |= clock->div_table[i].val & (CPG_SD_STP_MASK | CPG_SD_FC_MASK); - writel(val, clock->csn.reg); + cpg_reg_modify(clock->csn.reg, CPG_SD_STP_MASK | CPG_SD_FC_MASK, + clock->div_table[i].val & + (CPG_SD_STP_MASK | CPG_SD_FC_MASK)); return 0; }