From patchwork Tue Jan 22 19:57:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 10776195 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 3726F13B5 for ; Tue, 22 Jan 2019 19:57:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24C8C2B95E for ; Tue, 22 Jan 2019 19:57:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17F192B96C; Tue, 22 Jan 2019 19:57:44 +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 8FC462B960 for ; Tue, 22 Jan 2019 19:57:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726218AbfAVT5n (ORCPT ); Tue, 22 Jan 2019 14:57:43 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:46448 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726015AbfAVT5n (ORCPT ); Tue, 22 Jan 2019 14:57:43 -0500 Received: by mail-lj1-f196.google.com with SMTP id v15-v6so21716785ljh.13 for ; Tue, 22 Jan 2019 11:57:40 -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=y5pD8IiGs3MGHd/hieqN/F+NJHTyJgePEHoUTjzBTFY=; b=JN3V1nIT8+QXSF09xw/u75brDWFUYn65iZ8LRHf6efZNjTCndk+eKQ8khHhIzXrrzc cistc6NBaeSMasq0PAad4rW49F++iNTqEafXy8TW469bBNRJUKOYAM0C4tN8BwOEmcec CGA3ASZ9nx2gHX6s9TvU4/OWI96+gmKSIjyx/Z7O6pUhfoszRHXtM3XZKd9MCeQ82OaN +ChlT+N6Kft4H2s+B+lLLEul1jVJuLbw+pEGliWxaFiCQQVM1CD49YQ1syjEaSM6wfFm M1m68/aQP/SI84zfnd4AAy4Y2aZXjl3Kv9kay+tlNOX6Ku5FGETLq15OoPp+Oij0+hyi InoA== 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=y5pD8IiGs3MGHd/hieqN/F+NJHTyJgePEHoUTjzBTFY=; b=U7XzLpGWEwoeBEgwPsFOTu4eEU8uLy2Ihmr4nmmjeQ+F3Y9wW9UKjYmGK3tyX8lKHZ OiWSLsrpqmEApNvOOAGxVgiqNSBXUNT2GTfqa6OgISyDa5Mcmc9l+rOYEpuvBmlDo78C YsgWj4PRlFZG4KAjP94AWsIgdvUUOiRcT/Cnb11+LLiR2NF8iY1Qyz1x+zIXfn2EpHWU A+e8weXTAjsiTGe2RgH02Vl8R2O681V7FcrWYvz2m+awE6T72vRYJfMbYuaUpC6Eo9BG dWiPfjgxDR0Bo/TkI5kdJDbdsBL86x2j6Z+RqWwvrdTvr/n3Y0kSGUNF7eXZW5ueXem7 cRLA== X-Gm-Message-State: AJcUukfB7BbxT+eT68HkBc8IkEBdnL2AbFWbUslIp/o4RHnvT2VyGDi9 x86yvGr2jYASOll5Iw/zWt1xtw== X-Google-Smtp-Source: ALg8bN5XJtshftwEDXSVFyBk3gLXsVOjty93l0wMCG+VkX5D8hhA6fb3lQoZHkwCu2DfNTl8S3Fy+Q== X-Received: by 2002:a2e:83d7:: with SMTP id s23-v6mr23760996ljh.139.1548187059902; Tue, 22 Jan 2019 11:57:39 -0800 (PST) Received: from wasted.cogentembedded.com ([31.173.82.69]) by smtp.gmail.com with ESMTPSA id k20sm150788lfe.3.2019.01.22.11.57.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jan 2019 11:57:39 -0800 (PST) Subject: [PATCH v3 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: Date: Tue, 22 Jan 2019 22:57:38 +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: Geert Uytterhoeven --- Changes in version 3: - refreshed the patch; - added Geert's tag. 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. @@ -266,12 +272,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; } @@ -280,7 +284,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) @@ -327,7 +331,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++) @@ -339,10 +342,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; } From patchwork Tue Jan 22 19:58:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 10776201 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 9703B13B5 for ; Tue, 22 Jan 2019 19:58:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87C682B95E for ; Tue, 22 Jan 2019 19:58:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BFC22B960; Tue, 22 Jan 2019 19:58:46 +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=unavailable 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 05B652B966 for ; Tue, 22 Jan 2019 19:58:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726009AbfAVT6p (ORCPT ); Tue, 22 Jan 2019 14:58:45 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:40587 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725925AbfAVT6o (ORCPT ); Tue, 22 Jan 2019 14:58:44 -0500 Received: by mail-lf1-f66.google.com with SMTP id v5so19032780lfe.7 for ; Tue, 22 Jan 2019 11:58:42 -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=WPaa9s6qqwjVhXcdKFVgWx7xVGXgDKS5Jm7FG/EZ3tA=; b=n9KghBzWI8PTppkBzsmCk5CHdK/bybGvtVxBBWFhVF8zyuLj91Uu7192wL+Kj4ls/G yNVYt+PxxK9oIxfe8GR6+PvgXCXfDATyn6e92Ja3T9QDVSNg2dpb7eD8OnrHGV0zNz9A YqA6v66IOoW3g8zxCRHXCuRsVid2VJr7O5sUc1qpweS12SDY5rBw8ya0LHOsWnlHjlzM lzZE490f4jmbtddb7cnL62EgqwdBwuIlfZl/BF/FC/dXWO4XUGA6R1DzNhbVah5dAF+e EIahuKWTfka7Rq2DxPLZW08YqrhunmyEVtsHJ3x9Hw0tBTuZZI45WxHQ0I0sQQdgBzDq Ndkg== 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=WPaa9s6qqwjVhXcdKFVgWx7xVGXgDKS5Jm7FG/EZ3tA=; b=hfTyRpKZbzyAdQXo6PV6r2CMD1filPNEgaNhk66goeCNMRNt9/VW2XFTk8XRwz4mK+ KJ7xSae5tsZYsGQ99ME5i1NBK1pBcjkca7C0iXcbXfQbWf3S/2Z5P+i3Lpt6ZxYu/l3z AqSvR+I/MW7TLJ4K/TSFVtppr1Fb7/0SnDWxI+vq/iUuGI1tZps2tOuUfWKRw5nFNdcV hVUamy+aXK0sQxnOZFiR7LbqfSh7Aoha6ilREKvpO5a+xL2ok5cPrs7DX1LSIhCdIe/z npN/yrcrjhJ7b+IPZLcgP951qrk0mEw8Xmu5EX9EySAIgylRrjf8vOUTg3qKPpvGSB3H nJlQ== X-Gm-Message-State: AJcUukcZ/mj3Jm4D/IIWDkqNO2EeHzJkFyvM2NzmRaMNHrEdDd6Z9mee smOy9awCfD4ZZgA83MxLqlvlaw== X-Google-Smtp-Source: ALg8bN7AQg4mcsSp/aQ3IEoygBAGBVYQMebZirolhKa6Zq82rtuGtv4Bf+VpW1N007yuzukgNs5HbA== X-Received: by 2002:a19:8f45:: with SMTP id r66mr23186965lfd.9.1548187120506; Tue, 22 Jan 2019 11:58:40 -0800 (PST) Received: from wasted.cogentembedded.com ([31.173.82.69]) by smtp.gmail.com with ESMTPSA id m13-v6sm147515ljg.56.2019.01.22.11.58.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jan 2019 11:58:39 -0800 (PST) Subject: [PATCH v3 2/4] clk: renesas: rcar-gen3-cpg: add spinlock 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: <8a630f60-c5a1-de98-f80a-40404199d8bd@cogentembedded.com> Date: Tue, 22 Jan 2019 22:58:38 +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 Protect the CPG register read-modify-write sequence with a spinlock. Signed-off-by: Sergei Shtylyov Reviewed-by: Geert Uytterhoeven --- Changes in version 3: - refreshed the patch; - added Geert's tag. Changes in version 2: - new patch. drivers/clk/renesas/rcar-gen3-cpg.c | 8 ++++++++ 1 file changed, 8 insertions(+) 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,14 +30,19 @@ #define CPG_RCKCR_CKSEL BIT(15) /* RCLK Clock Source Select */ +static spinlock_t cpg_lock; + static void cpg_reg_modify(void __iomem *reg, u32 clear, u32 set) { + unsigned long flags; u32 val; + spin_lock_irqsave(&cpg_lock, flags); val = readl(reg); val &= ~clear; val |= set; writel(val, reg); + spin_unlock_irqrestore(&cpg_lock, flags); }; struct cpg_simple_notifier { @@ -615,5 +620,8 @@ int __init rcar_gen3_cpg_init(const stru if (attr) cpg_quirks = (uintptr_t)attr->data; pr_debug("%s: mode = 0x%x quirks = 0x%x\n", __func__, mode, cpg_quirks); + + spin_lock_init(&cpg_lock); + return 0; } From patchwork Tue Jan 22 19:59:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 10776205 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 28E9C1390 for ; Tue, 22 Jan 2019 19:59:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 175C82B6F3 for ; Tue, 22 Jan 2019 19:59:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0ADBC2B883; Tue, 22 Jan 2019 19:59:41 +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 77DFB2B6F3 for ; Tue, 22 Jan 2019 19:59:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726009AbfAVT7k (ORCPT ); Tue, 22 Jan 2019 14:59:40 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:35814 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbfAVT7k (ORCPT ); Tue, 22 Jan 2019 14:59:40 -0500 Received: by mail-lj1-f195.google.com with SMTP id x85-v6so21821869ljb.2 for ; Tue, 22 Jan 2019 11:59:38 -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=jx3qFbaEtJXxaHPqMOOSkAqfrMwSN13MlLYOuyS4TfE=; b=hssDkxBFqKL5R9hiffdUyZMect8HDLjopWFtwF1DUkiqcxw4WHianKsdqsPlIPGjsH N3kle69kkydJ+VEgafJPsUEavecZbmhS7YJ45piX2a5fbxuXDdeUvGGCraH1OQdXDyNi HrUUfgrCMcF6nPWnaQXESlhiNXoYCzQNYtJOdfOFXelXzv/uCylqYh9I2bnj2TO6rj4q H+2GQ6tgxtkJrEv1czgC4ygtM+3Neksd8h0nXDyIh5CvVGPU6rTwM3giy4lTL0PGCwvb xbtttEldWkzZSILsx8dOkEzuQsd1PFdXWSVdE9npvY/v6x/buhWYp5YAfUbPEPxNS6Jk 5ccw== 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=jx3qFbaEtJXxaHPqMOOSkAqfrMwSN13MlLYOuyS4TfE=; b=ccaDtf80cKnco8R1aF5uU/rEtsKR2IkcAabGaDz+1YrhqfuNGf4mrR2ac/S+zn7iFY VK2dgCBL8MZm8872pfJnwUWERkNUZiBcfnwWAGnLjGQazBxpO6p7ntJXnKKJuFPSCA9k w32OgcHlhp8C2xIACpcidm/pP9PnFH1ducpAB62cZPc8G79OzC+4DQYqanjYFHzNr9OL lYCBu8EArXwypvqAOVzkWUNADGRDM6U6Q48YU8EH9cLA7nzRV3X3xp4nxlvpEt0uJTOM 5pYmhr7gZP6640BxrQHKvc70DypSo2GALGI5JPldAE++yofUmSSuvJVtfW5wFJHYvw+7 ewwQ== X-Gm-Message-State: AJcUukc+BNQKjFWGDVy9JyqjJF4PWUjOpg9w5JP3ipHhOJEklH6nXcIm jv4AC8H10QVlzUgGoRdG4z+ODA== X-Google-Smtp-Source: ALg8bN7JuJ98H3l2gVPzjRqiYfuJ+6uMbQ9doV4UKEo7PptakIOFJYJfl8PqM4obxfnG3/EVjt7zLg== X-Received: by 2002:a2e:3218:: with SMTP id y24-v6mr6113870ljy.157.1548187177598; Tue, 22 Jan 2019 11:59:37 -0800 (PST) Received: from wasted.cogentembedded.com ([31.173.82.69]) by smtp.gmail.com with ESMTPSA id z2-v6sm148323ljk.50.2019.01.22.11.59.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jan 2019 11:59:36 -0800 (PST) Subject: [PATCH v3 3/4] clk: renesas: rcar-gen3-cpg: add RPC clocks 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: <5c5dbf41-16a9-9d1a-8a29-997906696045@cogentembedded.com> Date: Tue, 22 Jan 2019 22:59:35 +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 The RPCSRC internal clock is controlled by the RPCCKCR.DIV[4:3] on all the R-Car gen3 SoCs except V3M (R8A77970) but the encoding of this field is different between SoCs; it makes sense to support the most common case of this encoding in the R-Car gen3 CPG driver... After adding the RPCSRC clock, we can add the RPC[D2] clocks derived from it and controlled by the RPCCKCR register on all the R-Car gen3 SoCs except V3M (R8A77970); the composite clock driver seems handy for this task, using the spinlock added in the previous patch... Signed-off-by: Sergei Shtylyov Reviewed-by: Geert Uytterhoeven --- Changes in version 3: - added 'struct rpcd2_clock' embracing both 'struct clk_fixed_factor' and 'struct clk_gate' to reduce the # of kzalloc() calls; - added a comment about the single notifier to 'struct rpc_clock'; - refreshed the patch. Changes in version 2: - merged in the RPCD2 clock support from the next patch; - moved in the RPCSRC clock support from the R8A77980 CPG/MSSR driver patch; - switched the RPC and RPCSD2 clock support to the composite clock driver; - changed the 1st parameter of cpg_rpc[d2]_clk_register(); - rewrote the patch description, renamed the patch. drivers/clk/renesas/rcar-gen3-cpg.c | 99 ++++++++++++++++++++++++++++++++++++ drivers/clk/renesas/rcar-gen3-cpg.h | 4 + 2 files changed, 103 insertions(+) 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 @@ -422,6 +422,90 @@ free_clock: return clk; } +struct rpc_clock { + struct clk_divider div; + struct clk_gate gate; + /* + * One notifier covers both RPC and RPCD2 clocks as they are both + * controlled by the same RPCCKCR register... + */ + struct cpg_simple_notifier csn; +}; + +static const struct clk_div_table cpg_rpcsrc_div_table[] = { + { 2, 5 }, { 3, 6 }, { 0, 0 }, +}; + +static const struct clk_div_table cpg_rpc_div_table[] = { + { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }, { 0, 0 }, +}; + +static struct clk * __init cpg_rpc_clk_register(const char *name, + void __iomem *base, const char *parent_name, + struct raw_notifier_head *notifiers) +{ + struct rpc_clock *rpc; + struct clk *clk; + + rpc = kzalloc(sizeof(*rpc), GFP_KERNEL); + if (!rpc) + return ERR_PTR(-ENOMEM); + + rpc->div.reg = base + CPG_RPCCKCR; + rpc->div.width = 3; + rpc->div.table = cpg_rpc_div_table; + rpc->div.lock = &cpg_lock; + + rpc->gate.reg = base + CPG_RPCCKCR; + rpc->gate.bit_idx = 8; + rpc->gate.flags = CLK_GATE_SET_TO_DISABLE; + rpc->gate.lock = &cpg_lock; + + rpc->csn.reg = base + CPG_RPCCKCR; + + clk = clk_register_composite(NULL, name, &parent_name, 1, NULL, NULL, + &rpc->div.hw, &clk_divider_ops, + &rpc->gate.hw, &clk_gate_ops, 0); + if (IS_ERR(clk)) + kfree(rpc); + + cpg_simple_notifier_register(notifiers, &rpc->csn); + return clk; +} + +struct rpc2_clock { + struct clk_fixed_factor fixed; + struct clk_gate gate; +}; + +static struct clk * __init cpg_rpcd2_clk_register(const char *name, + void __iomem *base, + const char *parent_name) +{ + struct rpc2_clock *rpc2; + struct clk *clk; + + rpc2 = kzalloc(sizeof(*rpc2), GFP_KERNEL); + if (!rpc2) + return ERR_PTR(-ENOMEM); + + rpc2->fixed.mult = 1; + rpc2->fixed.div = 2; + + rpc2->gate.reg = base + CPG_RPCCKCR; + rpc2->gate.bit_idx = 9; + rpc2->gate.flags = CLK_GATE_SET_TO_DISABLE; + rpc2->gate.lock = &cpg_lock; + + clk = clk_register_composite(NULL, name, &parent_name, 1, NULL, NULL, + &rpc2->fixed.hw, &clk_fixed_factor_ops, + &rpc2->gate.hw, &clk_gate_ops, 0); + if (IS_ERR(clk)) + kfree(rpc2); + + return clk; +} + static const struct rcar_gen3_cpg_pll_config *cpg_pll_config __initdata; static unsigned int cpg_clk_extalr __initdata; @@ -600,6 +684,21 @@ struct clk * __init rcar_gen3_cpg_clk_re } break; + case CLK_TYPE_GEN3_RPCSRC: + return clk_register_divider_table(NULL, core->name, + __clk_get_name(parent), 0, + base + CPG_RPCCKCR, 3, 2, 0, + cpg_rpcsrc_div_table, + &cpg_lock); + + case CLK_TYPE_GEN3_RPC: + return cpg_rpc_clk_register(core->name, base, + __clk_get_name(parent), notifiers); + + case CLK_TYPE_GEN3_RPCD2: + return cpg_rpcd2_clk_register(core->name, base, + __clk_get_name(parent)); + default: return ERR_PTR(-EINVAL); } Index: renesas-drivers/drivers/clk/renesas/rcar-gen3-cpg.h =================================================================== --- renesas-drivers.orig/drivers/clk/renesas/rcar-gen3-cpg.h +++ renesas-drivers/drivers/clk/renesas/rcar-gen3-cpg.h @@ -23,6 +23,9 @@ enum rcar_gen3_clk_types { CLK_TYPE_GEN3_Z2, CLK_TYPE_GEN3_OSC, /* OSC EXTAL predivider and fixed divider */ CLK_TYPE_GEN3_RCKSEL, /* Select parent/divider using RCKCR.CKSEL */ + CLK_TYPE_GEN3_RPCSRC, + CLK_TYPE_GEN3_RPC, + CLK_TYPE_GEN3_RPCD2, /* SoC specific definitions start here */ CLK_TYPE_GEN3_SOC_BASE, @@ -57,6 +60,7 @@ struct rcar_gen3_cpg_pll_config { u8 osc_prediv; }; +#define CPG_RPCCKCR 0x238 #define CPG_RCKCR 0x240 struct clk *rcar_gen3_cpg_clk_register(struct device *dev, From patchwork Tue Jan 22 20:01:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 10776213 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 882701390 for ; Tue, 22 Jan 2019 20:01:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 795F02B9E4 for ; Tue, 22 Jan 2019 20:01:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DBE92B97D; Tue, 22 Jan 2019 20:01:14 +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=unavailable 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 4C2A12BA78 for ; Tue, 22 Jan 2019 20:01:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726095AbfAVUBL (ORCPT ); Tue, 22 Jan 2019 15:01:11 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:33227 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726015AbfAVUBL (ORCPT ); Tue, 22 Jan 2019 15:01:11 -0500 Received: by mail-lj1-f193.google.com with SMTP id v1-v6so21831499ljd.0 for ; Tue, 22 Jan 2019 12:01:10 -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=h3UPvFM7S4Lgw6BJPW9b0tY+/sfdOonED1U8LL8rqps=; b=quXVWZUzCvsuLrN6bt3bKhxlyHxDjbp04VHNfle5ocYlHI6/jIjV2EHCzAnP43W0uM GXuCRX0vkk+euPFOpugjZ83Y8RNd8FVF277KeaNZ0FcSyE8EE66NyHmDtN4xmQanaFwj 3Oqw7+BH2eD8q6AzAI9wBOaOqsLU6NI/dv+e/fh7/WxV7Zz+OKt4UcfdiTHz4/3yqwu/ xSwA2AzMsV/tCEckMko1sXakmJKOKQACh6fMIzkNexWKrJwu3aIKER9d7E1DKbRwlrEL wFWiSoo5VRtM8YB2WFA3Iid/pFzp8GZhBu6reKW72uDR5iYzsaO0Q68hvJDl9Bw4jApa wY3Q== 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=h3UPvFM7S4Lgw6BJPW9b0tY+/sfdOonED1U8LL8rqps=; b=WFATzkn7K1OPTG6m8CaA4/7i65czFQGW99O5kMUzEQurMqfMQnzdMYWIrhVP7wuiZ+ NND8OcTspQd8PiQXa7CYGvs7w+xi0IE0mxzL9jr+rTpFeYR3FZ3sycqCl0xqIioCmTqW R57al8ZPb5yhEPGGMqCIPG3Pa7v7WtKnr+mHl85RsUdiQBBXpvrp7iOCSjclLZC3Krpv /BoMzd46Omfe3o0+KpdH7fMnk/8jjCFh0+mHABy6U5xoPP4V/fTLTsAwIsf8mHeQe4GA sZiWeXwfAk3BPM6/+5oce25wRlyoSDcUh65GsbNKc03DytZXer6hZme80+0TO8VYCiqB IvGw== X-Gm-Message-State: AJcUukf3oubxySk3a4/8olKpxR4IEsyBSyZwBj2gWPcuyhxqrluExpR1 hF4ydcvURF5hELAuZ6wQOSDEJw== X-Google-Smtp-Source: ALg8bN4iiT1k1LmA4F311xp8F9amOfwgkDwIbzUU9EK31KWGsy5ahhqLXVwnO2gf0Cn6NAEvaOkTRw== X-Received: by 2002:a2e:4942:: with SMTP id b2-v6mr21072372ljd.168.1548187269159; Tue, 22 Jan 2019 12:01:09 -0800 (PST) Received: from wasted.cogentembedded.com ([31.173.82.69]) by smtp.gmail.com with ESMTPSA id s62sm148972lfg.34.2019.01.22.12.01.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jan 2019 12:01:08 -0800 (PST) Subject: [PATCH v3 4/4] clk: renesas: r8a77980-cpg-mssr: add RPC clocks 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: Date: Tue, 22 Jan 2019 23:01:07 +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 Describe the RPCSRC internal clock and the RPC[D2] clocks derived from it, as well as the RPC-IF module clock, in the R-Car V3H (R8A77980) CPG/MSSR driver. Signed-off-by: Sergei Shtylyov Reviewed-by: Geert Uytterhoeven --- Changes in version 3: - added Geert's tag. Changes in version 2: - moved the RPCSRC clock support to the R-Car gen3 CPG patch adding the RPC clocks; - rewrote the patch description. drivers/clk/renesas/r8a77980-cpg-mssr.c | 8 ++++++++ 1 file changed, 8 insertions(+) Index: renesas-drivers/drivers/clk/renesas/r8a77980-cpg-mssr.c =================================================================== --- renesas-drivers.orig/drivers/clk/renesas/r8a77980-cpg-mssr.c +++ renesas-drivers/drivers/clk/renesas/r8a77980-cpg-mssr.c @@ -41,6 +41,7 @@ enum clk_ids { CLK_S2, CLK_S3, CLK_SDSRC, + CLK_RPCSRC, CLK_OCO, /* Module Clocks */ @@ -65,8 +66,14 @@ static const struct cpg_core_clk r8a7798 DEF_FIXED(".s2", CLK_S2, CLK_PLL1_DIV2, 4, 1), DEF_FIXED(".s3", CLK_S3, CLK_PLL1_DIV2, 6, 1), DEF_FIXED(".sdsrc", CLK_SDSRC, CLK_PLL1_DIV2, 2, 1), + DEF_BASE(".rpcsrc", CLK_RPCSRC, CLK_TYPE_GEN3_RPCSRC, CLK_PLL1), DEF_RATE(".oco", CLK_OCO, 32768), + DEF_BASE("rpc", R8A77980_CLK_RPC, CLK_TYPE_GEN3_RPC, + CLK_RPCSRC), + DEF_BASE("rpcd2", R8A77980_CLK_RPCD2, CLK_TYPE_GEN3_RPCD2, + R8A77980_CLK_RPC), + /* Core Clock Outputs */ DEF_FIXED("ztr", R8A77980_CLK_ZTR, CLK_PLL1_DIV2, 6, 1), DEF_FIXED("ztrd2", R8A77980_CLK_ZTRD2, CLK_PLL1_DIV2, 12, 1), @@ -164,6 +171,7 @@ static const struct mssr_mod_clk r8a7798 DEF_MOD("gpio1", 911, R8A77980_CLK_CP), DEF_MOD("gpio0", 912, R8A77980_CLK_CP), DEF_MOD("can-fd", 914, R8A77980_CLK_S3D2), + DEF_MOD("rpc-if", 917, R8A77980_CLK_RPC), DEF_MOD("i2c4", 927, R8A77980_CLK_S0D6), DEF_MOD("i2c3", 928, R8A77980_CLK_S0D6), DEF_MOD("i2c2", 929, R8A77980_CLK_S3D2),