From patchwork Tue May 6 14:23:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Hecht X-Patchwork-Id: 4122161 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E87CABFF02 for ; Tue, 6 May 2014 14:23:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F027C20204 for ; Tue, 6 May 2014 14:23:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A2F24201FB for ; Tue, 6 May 2014 14:23:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755577AbaEFOXi (ORCPT ); Tue, 6 May 2014 10:23:38 -0400 Received: from mail-ee0-f45.google.com ([74.125.83.45]:41720 "EHLO mail-ee0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752540AbaEFOXi (ORCPT ); Tue, 6 May 2014 10:23:38 -0400 Received: by mail-ee0-f45.google.com with SMTP id d49so2448824eek.32 for ; Tue, 06 May 2014 07:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=e6xI9bWJf4PTHMbCt5hyFUsVYvW31Kkk6WeqR0cdeEg=; b=mIXa1YanC1ibp9DrQk4EJChMytnWMFBzyx6rugtIyfsWNsu/5NGAzT8C1lD4Bpp0kx oZzgcRk1+7uXKYeaaDAC8ufDaWv8w75tHBhN8MQR0lAPB+ecWAOhK9qZEvQvOmDoquN6 fDO/Z3qtN0EGEOZfqGeeBRoEESK277IH4aWfE4VR1wSfpJmKunsgLDZ7VTNIk1nHqRkk xL9ZNvlSgtx6LS+vcOdx1Z8XBYqhZl7qAEtHquCWWTeez5bGgWZv2B3lR+B1zzWgMG1B paxFS7Kh+X0utdtBuBnRm/khok5Xn8Jqk6tPfW/vDc6wBQyL6DuXXXq/pKR+q0k9bfIX y9Pg== X-Received: by 10.15.21.2 with SMTP id c2mr9939027eeu.78.1399386217142; Tue, 06 May 2014 07:23:37 -0700 (PDT) Received: from groucho.site (tsn85-159-236-209.dyn.nltelcom.net. [85.159.236.209]) by mx.google.com with ESMTPSA id m44sm12615505eeh.14.2014.05.06.07.23.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 May 2014 07:23:36 -0700 (PDT) X-Google-Original-From: Ulrich Hecht From: Ulrich Hecht To: linux-sh@vger.kernel.org, laurent.pinchart@ideasonboard.com, horms@verge.net.au Cc: magnus.damm@gmail.com, Ulrich Hecht , Ulrich Hecht Subject: [PATCH 3/6] clk: shmobile: div6: support selectable-input clocks Date: Tue, 6 May 2014 16:23:50 +0200 Message-Id: <1399386233-11928-4-git-send-email-ulrich.hecht+renesas@gmail.com> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1399386233-11928-1-git-send-email-ulrich.hecht+renesas@gmail.com> References: <1399386233-11928-1-git-send-email-ulrich.hecht+renesas@gmail.com> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ulrich Hecht Adds support for DIV6 clocks with selectable parents as found in the r8a7740, sh73a0, and other SoCs. Signed-off-by: Ulrich Hecht --- .../bindings/clock/renesas,cpg-div6-clocks.txt | 11 +++++++- drivers/clk/shmobile/clk-div6.c | 32 ++++++++++++++++++---- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Documentation/devicetree/bindings/clock/renesas,cpg-div6-clocks.txt b/Documentation/devicetree/bindings/clock/renesas,cpg-div6-clocks.txt index 952e373..d8c6577 100644 --- a/Documentation/devicetree/bindings/clock/renesas,cpg-div6-clocks.txt +++ b/Documentation/devicetree/bindings/clock/renesas,cpg-div6-clocks.txt @@ -7,14 +7,23 @@ to 64. Required Properties: - compatible: Must be one of the following + - "renesas,r8a7740-div6-clock" for R8A7740 DIV6 clocks - "renesas,r8a7790-div6-clock" for R8A7790 (R-Car H2) DIV6 clocks - "renesas,r8a7791-div6-clock" for R8A7791 (R-Car M2) DIV6 clocks + - "renesas,sh73a0-div6-clock" for SH73A0 (SH-MobileAG5) DIV6 clocks - "renesas,cpg-div6-clock" for generic DIV6 clocks - reg: Base address and length of the memory resource used by the DIV6 clock - - clocks: Reference to the parent clock + - clocks: Reference to the parent clock(s) - #clock-cells: Must be 0 - clock-output-names: The name of the clock as a free-form string +Optional Properties: + + - renesas,src-shift: Bit position of the input clock selector (default: + fixed input clock) + - renesas,src-width: Bit width of the input clock selector (default: fixed + input clock) + Example ------- diff --git a/drivers/clk/shmobile/clk-div6.c b/drivers/clk/shmobile/clk-div6.c index f065f69..fbd1c31 100644 --- a/drivers/clk/shmobile/clk-div6.c +++ b/drivers/clk/shmobile/clk-div6.c @@ -38,9 +38,12 @@ struct div6_clock { static int cpg_div6_clock_enable(struct clk_hw *hw) { + unsigned int val; struct div6_clock *clock = to_div6_clock(hw); - clk_writel(CPG_DIV6_DIV(clock->div - 1), clock->reg); + val = (clk_readl(clock->reg) & ~(CPG_DIV6_DIV_MASK | CPG_DIV6_CKSTP)) + | CPG_DIV6_DIV(clock->div - 1); + clk_writel(val, clock->reg); return 0; } @@ -52,8 +55,8 @@ static void cpg_div6_clock_disable(struct clk_hw *hw) /* DIV6 clocks require the divisor field to be non-zero when stopping * the clock. */ - clk_writel(CPG_DIV6_CKSTP | CPG_DIV6_DIV(CPG_DIV6_DIV_MASK), - clock->reg); + clk_writel(clk_readl(clock->reg) | CPG_DIV6_CKSTP | CPG_DIV6_DIV_MASK, + clock->reg); } static int cpg_div6_clock_is_enabled(struct clk_hw *hw) @@ -94,12 +97,14 @@ static int cpg_div6_clock_set_rate(struct clk_hw *hw, unsigned long rate, { struct div6_clock *clock = to_div6_clock(hw); unsigned int div = cpg_div6_clock_calc_div(rate, parent_rate); + unsigned int val; clock->div = div; + val = clk_readl(clock->reg) & ~CPG_DIV6_DIV_MASK; /* Only program the new divisor if the clock isn't stopped. */ - if (!(clk_readl(clock->reg) & CPG_DIV6_CKSTP)) - clk_writel(CPG_DIV6_DIV(clock->div - 1), clock->reg); + if (!(val & CPG_DIV6_CKSTP)) + clk_writel(val | CPG_DIV6_DIV(clock->div - 1), clock->reg); return 0; } @@ -121,6 +126,7 @@ static void __init cpg_div6_clock_init(struct device_node *np) const char *name; struct clk *clk; int ret; + u32 src_shift, src_width; clock = kzalloc(sizeof(*clock), GFP_KERNEL); if (!clock) { @@ -150,7 +156,21 @@ static void __init cpg_div6_clock_init(struct device_node *np) goto error; } - parent_name = of_clk_get_parent_name(np, 0); + if (!of_property_read_u32(np, "renesas,src-shift", &src_shift)) { + if (!of_property_read_u32(np, "renesas,src-width", + &src_width)) { + unsigned int parent_idx = + (clk_readl(clock->reg) >> src_shift) & + (BIT(src_width) - 1); + parent_name = of_clk_get_parent_name(np, parent_idx); + } else { + pr_err("%s: renesas,src-shift without renesas," + "src-width in %s\n", __func__, np->name); + goto error; + } + } else + parent_name = of_clk_get_parent_name(np, 0); + if (parent_name == NULL) { pr_err("%s: failed to get %s DIV6 clock parent name\n", __func__, np->name);