From patchwork Sat Mar 16 13:09:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Hesselbarth X-Patchwork-Id: 2282051 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 16CCBDF5B1 for ; Sat, 16 Mar 2013 13:13:16 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UGqsJ-00015c-2F; Sat, 16 Mar 2013 13:10:15 +0000 Received: from mail-bk0-x236.google.com ([2a00:1450:4008:c01::236]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UGqsF-00015E-2d for linux-arm-kernel@lists.infradead.org; Sat, 16 Mar 2013 13:10:12 +0000 Received: by mail-bk0-f54.google.com with SMTP id w5so1911742bku.27 for ; Sat, 16 Mar 2013 06:10:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=VO5n4WbnlivM2vc5Zy0OvAYo1a0FfPG5GUG5st7s8W4=; b=b8yUsgyWTLAnrK55DPoR18jG3xGBylDdV7tmrA9ElvoWpK5ajjJATseC4m5VPSD+ZS Lg2jUca6sRYYaEJymqL+FQIqfwWZF2Vi01C9+NKYHSKwf8hZBsQcU8Oa7V+9OhC7PMnz aWZNjcd6kQWALxrjILZI85RWJvXUPDiGh55LIWVss7SbR8D73jKsUmAoDoIPc+bLb00g xhaNd+7k1DaqCrgHolau8Mcwi+QxhJcCMmI+CXSGVyPoDd1axs5jEoib1pzpOGJaAmIt VIeNJC+amAjyAD6hDzfrgfLyeSf76etww7ybi3c5Vd1W7UQ3k39fiMkaRRmLWyiNEyBI 3vnQ== X-Received: by 10.205.39.3 with SMTP id tk3mr4464276bkb.113.1363439408331; Sat, 16 Mar 2013 06:10:08 -0700 (PDT) Received: from nijin.lan (dslc-082-083-243-143.pools.arcor-ip.net. [82.83.243.143]) by mx.google.com with ESMTPS id b21sm2401798bkw.12.2013.03.16.06.09.54 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 16 Mar 2013 06:10:07 -0700 (PDT) From: Sebastian Hesselbarth To: Sebastian Hesselbarth Subject: [PATCH] clk: add DT test clock consumer driver Date: Sat, 16 Mar 2013 14:09:36 +0100 Message-Id: <1363439376-21294-1-git-send-email-sebastian.hesselbarth@gmail.com> X-Mailer: git-send-email 1.7.10.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130316_091011_538610_AEB84DD6 X-CRM114-Status: GOOD ( 21.20 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (sebastian.hesselbarth[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Mike Turquette , Arnd Bergmann , linux-doc@vger.kernel.org, Linus Walleij , linux-kernel@vger.kernel.org, Rob Herring , Grant Likely , Rob Landley , Andrew Morton , devicetree-discuss@lists.ozlabs.org, linux-arm-kernel@lists.infradead.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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This driver adds a DT test clock consumer that exposes debugfs files to enable/disable and set/get rate of the attached programmable clock. During development of a i2c-attached clock generator I found it useful to debug the clock generator's internal pll settings by enforcing clock rates through debugfs. Signed-off-by: Sebastian Hesselbarth --- Cc: Grant Likely Cc: Rob Herring Cc: Rob Landley Cc: Mike Turquette Cc: Linus Walleij Cc: Arnd Bergmann Cc: Andrew Morton Cc: devicetree-discuss@lists.ozlabs.org Cc: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org --- .../bindings/clock/test-clock-consumer.txt | 19 ++ drivers/clk/Kconfig | 6 + drivers/clk/Makefile | 3 + drivers/clk/clk-test.c | 183 ++++++++++++++++++++ 4 files changed, 211 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/test-clock-consumer.txt create mode 100644 drivers/clk/clk-test.c diff --git a/Documentation/devicetree/bindings/clock/test-clock-consumer.txt b/Documentation/devicetree/bindings/clock/test-clock-consumer.txt new file mode 100644 index 0000000..3e228ed --- /dev/null +++ b/Documentation/devicetree/bindings/clock/test-clock-consumer.txt @@ -0,0 +1,19 @@ +* Test Clock Consumer + +The test clock consumer allows to debug clock providers by exposing +debugfs files to enable/disable and set/get rate of attached clock +respectively. It is especially useful for checking programmable clock +generators, e.g. enforcing target clock rates to debug clock generator's +pll settings. Currently, there is only one clock per test clock consumer +supported but more than one test clock consumer can be added. + +Required properties: +- compatible : shall be "test-clock-consumer" +- clocks : phandle of the clock to debug + +Example: + +clock-consumer { + compatible = "test-clock-consumer"; + clocks = <&programmable_clock>; +}; diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig index a47e6ee..e23e471 100644 --- a/drivers/clk/Kconfig +++ b/drivers/clk/Kconfig @@ -33,6 +33,12 @@ config COMMON_CLK_DEBUG clk_flags, clk_prepare_count, clk_enable_count & clk_notifier_count. +config COMMON_CLK_TEST_CONSUMER + tristate "Clock consumer test driver" + ---help--- + This is a clock consumer test driver to allow testing clock + provider through user space. + config COMMON_CLK_WM831X tristate "Clock driver for WM831x/2x PMICs" depends on MFD_WM831X diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index 300d477..095899e 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -34,3 +34,6 @@ obj-$(CONFIG_X86) += x86/ obj-$(CONFIG_COMMON_CLK_WM831X) += clk-wm831x.o obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o obj-$(CONFIG_CLK_TWL6040) += clk-twl6040.o + +# Debug drivers +obj-$(CONFIG_COMMON_CLK_TEST_CONSUMER) += clk-test.o diff --git a/drivers/clk/clk-test.c b/drivers/clk/clk-test.c new file mode 100644 index 0000000..08dd66b --- /dev/null +++ b/drivers/clk/clk-test.c @@ -0,0 +1,183 @@ +/* + * clk-test.c: Common Clock Framework Test Clock Consumer + * + * (c) 2012 Sebastian Hesselbarth + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct clock_consumer_data { + struct clk *clk; + struct dentry *clkdir; + const char *name; + unsigned int enabled; +}; + +static struct dentry *rootdir; + +static int clock_consumer_debug_rate_set(void *data, u64 val) +{ + struct clock_consumer_data *ccdata = (struct clock_consumer_data *)data; + + if (!ccdata->enabled) + return -EBUSY; + + return clk_set_rate(ccdata->clk, (unsigned long)val); +} + +static int clock_consumer_debug_rate_get(void *data, u64 *val) +{ + struct clock_consumer_data *ccdata = (struct clock_consumer_data *)data; + + if (!ccdata->enabled) + return -EBUSY; + + *val = clk_get_rate(ccdata->clk); + + return 0; +} + +static int clock_consumer_debug_enable_set(void *data, u64 val) +{ + struct clock_consumer_data *ccdata = (struct clock_consumer_data *)data; + + if ((val == ccdata->enabled) || (!val && !ccdata->enabled)) + return 0; + + ccdata->enabled = (val) ? 1 : 0; + + if (ccdata->enabled) + return clk_prepare_enable(ccdata->clk); + + clk_disable_unprepare(ccdata->clk); + return 0; +} + +static int clock_consumer_debug_enable_get(void *data, u64 *val) +{ + struct clock_consumer_data *ccdata = (struct clock_consumer_data *)data; + *val = ccdata->enabled; + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(clock_consumer_debug_ops_enable, + clock_consumer_debug_enable_get, + clock_consumer_debug_enable_set, "%llu\n"); +DEFINE_SIMPLE_ATTRIBUTE(clock_consumer_debug_ops_rate, + clock_consumer_debug_rate_get, + clock_consumer_debug_rate_set, "%llu\n"); + +static int clock_consumer_debug_create_one(struct platform_device *pdev) +{ + struct clock_consumer_data *ccdata = platform_get_drvdata(pdev); + struct dentry *d; + + if (!rootdir) { + rootdir = debugfs_create_dir("clk_consumer", NULL); + if (WARN_ON(IS_ERR_OR_NULL(rootdir))) + return -ENOMEM; + } + + ccdata->clkdir = debugfs_create_dir(ccdata->name, rootdir); + if (WARN_ON(IS_ERR_OR_NULL(ccdata->clkdir))) + return -ENOMEM; + + d = debugfs_create_file("enable", S_IRUGO | S_IWUGO, ccdata->clkdir, + ccdata, &clock_consumer_debug_ops_enable); + if (WARN_ON(IS_ERR_OR_NULL(d))) + goto err_out; + + d = debugfs_create_file("rate", S_IRUGO | S_IWUGO, ccdata->clkdir, + ccdata, &clock_consumer_debug_ops_rate); + if (WARN_ON(IS_ERR_OR_NULL(d))) + goto err_out; + + return 0; + +err_out: + debugfs_remove(ccdata->clkdir); + return -ENOMEM; +} + +static struct of_device_id clock_consumer_of_match[] = { + { .compatible = "test-clock-consumer", }, + { } +}; + +static int clock_consumer_probe(struct platform_device *pdev) +{ + struct clock_consumer_data *ccdata; + int ret; + + ccdata = devm_kzalloc(&pdev->dev, sizeof(struct clock_consumer_data), + GFP_KERNEL); + if (WARN_ON(!ccdata)) + return -ENOMEM; + + ccdata->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(ccdata->clk)) { + dev_err(&pdev->dev, "unable to get parent clock"); + return PTR_RET(ccdata->clk); + } + + platform_set_drvdata(pdev, ccdata); + ccdata->name = pdev->dev.of_node->name; + + ret = clock_consumer_debug_create_one(pdev); + if (ret) + return ret; + + dev_info(&pdev->dev, "installed clock consumer %s\n", + ccdata->name); + + return 0; +} + +static int clock_consumer_remove(struct platform_device *pdev) +{ + struct clock_consumer_data *ccdata = platform_get_drvdata(pdev); + + if (!ccdata || !ccdata->clkdir) + return 0; + + debugfs_remove_recursive(ccdata->clkdir); + if (!IS_ERR(ccdata->clk) && ccdata->enabled) + clk_disable_unprepare(ccdata->clk); + + dev_info(&pdev->dev, "removed clock consumer %s\n", ccdata->name); + + if (rootdir && list_empty(&rootdir->d_subdirs)) + debugfs_remove_recursive(rootdir); + + platform_set_drvdata(pdev, NULL); + + return 0; +} + +static struct platform_driver clock_consumer_driver = { + .driver = { + .name = "clock-consumer", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(clock_consumer_of_match), + }, + .probe = clock_consumer_probe, + .remove = clock_consumer_remove, +}; + +module_platform_driver(clock_consumer_driver); + +MODULE_AUTHOR("Sebastian Hesselbarth "); +MODULE_DESCRIPTION("Common clock framwork test clock consumer driver"); +MODULE_LICENSE("GPL v2");