From patchwork Wed Nov 13 21:50:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hogan X-Patchwork-Id: 3179721 Return-Path: X-Original-To: patchwork-linux-arm@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 D3BFEC045B for ; Wed, 13 Nov 2013 21:52:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A762F208EE for ; Wed, 13 Nov 2013 21:52:42 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 82989208E8 for ; Wed, 13 Nov 2013 21:52:41 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VgiMW-00052m-FT; Wed, 13 Nov 2013 21:52:36 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VgiMU-0006P7-0F; Wed, 13 Nov 2013 21:52:34 +0000 Received: from multi.imgtec.com ([194.200.65.239]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VgiMO-0006Nv-2S for linux-arm-kernel@lists.infradead.org; Wed, 13 Nov 2013 21:52:31 +0000 From: James Hogan To: Mike Turquette , Subject: [PATCH v2 2/2] clk-fixed-rate: support specified-clock binding Date: Wed, 13 Nov 2013 21:50:00 +0000 Message-ID: <1384379400-24776-3-git-send-email-james.hogan@imgtec.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1384379400-24776-1-git-send-email-james.hogan@imgtec.com> References: <1384379400-24776-1-git-send-email-james.hogan@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [192.168.154.65] X-SEF-Processed: 7_3_0_01192__2013_11_13_21_52_05 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131113_165228_285704_DBF714CE X-CRM114-Status: GOOD ( 14.07 ) X-Spam-Score: -1.9 (-) Cc: Mark Rutland , devicetree@vger.kernel.org, James Hogan , Pawel Moll , Stephen Warren , Ian Campbell , Tomasz Figa , Rob Herring , linux-kernel@vger.kernel.org, linux-metag@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Implement the new specified-clock DT binding which uses a table to look up the fixed frequency based on the value in a register. The discovery is done entirely within of_specified_clk_setup() since the clock rate is still fixed so there's no need to dynamically rediscover the rate. The register is iomapped, read, and iounmapped, then the field value is extracted and used to look up the clock frequency in the table property. Signed-off-by: James Hogan Cc: Mike Turquette Cc: linux-arm-kernel@lists.infradead.org --- Changes in v2: * Rewrite to use a fixed clock instead of an entirely new clock type. --- drivers/clk/clk-fixed-rate.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/clk-provider.h | 1 + 2 files changed, 52 insertions(+) diff --git a/drivers/clk/clk-fixed-rate.c b/drivers/clk/clk-fixed-rate.c index 1ed591ab8b1d..7d7ec4094961 100644 --- a/drivers/clk/clk-fixed-rate.c +++ b/drivers/clk/clk-fixed-rate.c @@ -9,12 +9,14 @@ * Fixed rate clock implementation */ +#include #include #include #include #include #include #include +#include /* * DOC: basic fixed-rate clock that cannot gate @@ -103,4 +105,53 @@ void of_fixed_clk_setup(struct device_node *node) } EXPORT_SYMBOL_GPL(of_fixed_clk_setup); CLK_OF_DECLARE(fixed_clk, "fixed-clock", of_fixed_clk_setup); + +/** + * of_specified_clk_setup() - Setup function for discoverable fixed rate clock + */ +void of_specified_clk_setup(struct device_node *node) +{ + struct clk *clk; + const char *clk_name = node->name; + u32 shift, mask, rate, reg_val, val; + void __iomem *reg; + struct property *prop; + const __be32 *p; + + /* Iomap and read the configuration register */ + reg = of_iomap(node, 0); + if (!reg) + return; + reg_val = readl(reg); + iounmap(reg); + + /* Apply bit-mask */ + if (of_property_read_u32(node, "bit-mask", &mask)) + return; + reg_val &= mask; + /* Apply bit-shift */ + if (of_property_read_u32(node, "bit-shift", &shift)) + shift = ffs(mask) - 1; + reg_val >>= shift; + + /* Look through the mapping for a matching frequency */ + of_property_for_each_u32(node, "table", prop, p, val) { + p = of_prop_next_u32(prop, p, &rate); + if (!p) + break; + if (val == reg_val) + goto found_rate; + } + /* No match found */ + return; +found_rate: + + of_property_read_string(node, "clock-output-names", &clk_name); + + clk = clk_register_fixed_rate(NULL, clk_name, NULL, CLK_IS_ROOT, rate); + if (!IS_ERR(clk)) + of_clk_add_provider(node, of_clk_src_simple_get, clk); +} +EXPORT_SYMBOL_GPL(of_specified_clk_setup); +CLK_OF_DECLARE(specified_clk, "specified-clock", of_specified_clk_setup); #endif diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 7e59253b8603..0e1312504da9 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -203,6 +203,7 @@ struct clk *clk_register_fixed_rate(struct device *dev, const char *name, unsigned long fixed_rate); void of_fixed_clk_setup(struct device_node *np); +void of_specified_clk_setup(struct device_node *np); /** * struct clk_gate - gating clock