From patchwork Mon Jun 20 13:43:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 9187441 X-Patchwork-Delegate: sboyd@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 468266075F for ; Mon, 20 Jun 2016 13:45:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 312F122B1F for ; Mon, 20 Jun 2016 13:45:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 247BE2780C; Mon, 20 Jun 2016 13:45:04 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 A532D22B1F for ; Mon, 20 Jun 2016 13:45:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754619AbcFTNo4 (ORCPT ); Mon, 20 Jun 2016 09:44:56 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:35991 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754599AbcFTNou (ORCPT ); Mon, 20 Jun 2016 09:44:50 -0400 Received: by mail-lf0-f65.google.com with SMTP id a2so5508770lfe.3; Mon, 20 Jun 2016 06:43:49 -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=lmLeYhRawUS9N7eMykZT1S2+zi9GyugoGamfzQ4VfPU=; b=siH2Gz6RDDrApX0jmmvqlksNlLgUwj2jlo7vzprKE9ZkVaM8qp9Inw1MyQBhwNkEfu LqtQm5aNRPM4h/kUBQzdf6RBgB12/W04bW9IdGLHsVE0j51rqsr+Vna8y5sZclMPadBh 1k1Qncgwrk2LMLaQLw5zBEB/KTNaQfank+1veqJxbrncqqNbKy60uIZq28ovIOSxGBkv aSAtacgTaCJoHUY3WaoT1WOx1yoAkK1eMMQ1ppuQB4go/SLWFii5Mtm7STPKysUAm6dw z5EdT/J/xWLDEyT52ZYJsP+oBEe9c6yaOigiSSGjo4sMkFeR0MXEJstG2Rbvq2ySqNH9 yXZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lmLeYhRawUS9N7eMykZT1S2+zi9GyugoGamfzQ4VfPU=; b=gmcQz/jVBMlkjspmL8bxTFd6JqpzJCy+Yx90/UN8WV1giSK4Oj33i16IRaHCBVyqVy hA3mBnHNvjX5FDKdn0fUSMmajbXRXtL++o+hhvZACU/Zt0U7Eyaw18Y4V+wEwBzy7i0S g4/tXlEKFeNinVZWthxZm9qI+5YlE1XYnE0kkMgdN8Skyoc6mActmgLOVrTEiDORq4K9 Trm9PmFYmxTmxf35htKz3pnmS21MDJJTjnRRsDZ6qFMAe/jhPvQ0ObpMJCJatowFqdJT GaVE78KqwksjhbkU8qAzRaobUWpwgNAQvw4qt1i3Eh3HgEdXzZGPkiZLH3oxb5cp5NEZ gVIw== X-Gm-Message-State: ALyK8tKqo+iUUSo6Y+aLrtr3Iy1c6VZ4r+9g6pLWnhBAtDUwSmjp+RoS3PyYIo0TDLLZRg== X-Received: by 10.25.150.204 with SMTP id y195mr4425008lfd.168.1466430223857; Mon, 20 Jun 2016 06:43:43 -0700 (PDT) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id p10sm3452594lbr.22.2016.06.20.06.43.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jun 2016 06:43:42 -0700 (PDT) From: Ricardo Ribalda Delgado To: Stephen Boyd , Michael Turquette , s.hauer@pengutronix.de, jeremy.kerr@canonical.com, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Delgado Subject: [PATCH v2 2/3] clk: fixed-factor: Convert into a module platform driver Date: Mon, 20 Jun 2016 15:43:37 +0200 Message-Id: <1466430218-6561-3-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1466430218-6561-1-git-send-email-ricardo.ribalda@gmail.com> References: <1466430218-6561-1-git-send-email-ricardo.ribalda@gmail.com> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Adds support for fixed-factor clock providers which have not been enabled via of_clk_init(). This is required by Device trees overlays that introduce clocks providers. Signed-off-by: Ricardo Ribalda Delgado --- v2: Changes proposed by: Stephen Boyd -Add error check -CodeStyle on of_device_ide -Use builtin_platform_driver() drivers/clk/clk-fixed-factor.c | 75 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c index 75cd6c792cb8..73e7c1267bb6 100644 --- a/drivers/clk/clk-fixed-factor.c +++ b/drivers/clk/clk-fixed-factor.c @@ -12,6 +12,7 @@ #include #include #include +#include /* * DOC: basic fixed multiplier and divider clock that cannot gate @@ -145,23 +146,24 @@ EXPORT_SYMBOL_GPL(clk_hw_unregister_fixed_factor); /** * of_fixed_factor_clk_setup() - Setup function for simple fixed factor clock */ -void __init of_fixed_factor_clk_setup(struct device_node *node) +struct clk *_of_fixed_factor_clk_setup(struct device_node *node) { struct clk *clk; const char *clk_name = node->name; const char *parent_name; u32 div, mult; + int ret; if (of_property_read_u32(node, "clock-div", &div)) { pr_err("%s Fixed factor clock <%s> must have a clock-div property\n", __func__, node->name); - return; + return ERR_PTR(-EIO); } if (of_property_read_u32(node, "clock-mult", &mult)) { pr_err("%s Fixed factor clock <%s> must have a clock-mult property\n", __func__, node->name); - return; + return ERR_PTR(-EIO); } of_property_read_string(node, "clock-output-names", &clk_name); @@ -169,10 +171,73 @@ void __init of_fixed_factor_clk_setup(struct device_node *node) clk = clk_register_fixed_factor(NULL, clk_name, parent_name, 0, mult, div); - if (!IS_ERR(clk)) - of_clk_add_provider(node, of_clk_src_simple_get, clk); + if (IS_ERR(clk)) + return clk; + + ret = of_clk_add_provider(node, of_clk_src_simple_get, clk); + if (ret) { + clk_unregister(clk); + return ERR_PTR(ret); + } + + return clk; +} + +void __init of_fixed_factor_clk_setup(struct device_node *node) +{ + _of_fixed_factor_clk_setup(node); + return; } EXPORT_SYMBOL_GPL(of_fixed_factor_clk_setup); CLK_OF_DECLARE(fixed_factor_clk, "fixed-factor-clock", of_fixed_factor_clk_setup); + +static int of_fixed_factor_clk_remove(struct platform_device *pdev) +{ + struct clk *clk = platform_get_drvdata(pdev); + + if (clk) + clk_unregister_fixed_factor(clk); + + return 0; +} + +static int of_fixed_factor_clk_probe(struct platform_device *pdev) +{ + struct clk *clk; + + /* + * Don't do anything if of_clk_init() has already + * added this clock to the provider list + */ + if (of_clk_is_provider(pdev->dev.of_node)) + return 0; + + clk = _of_fixed_factor_clk_setup(pdev->dev.of_node); + + if (IS_ERR(clk)) + return PTR_ERR(clk); + + platform_set_drvdata(pdev, clk); + + return 0; +} + +static const struct of_device_id of_fixed_factor_clk_ids[] = { + { .compatible = "fixed-factor-clock" }, + { }, +}; +MODULE_DEVICE_TABLE(of, of_fixed_factor_clk_ids); + +static struct platform_driver of_fixed_factor_clk_driver = { + .driver = { + .name = "of_fixed_factor_clk", + .of_match_table = of_fixed_factor_clk_ids, + }, + .probe = of_fixed_factor_clk_probe, + .remove = of_fixed_factor_clk_remove, +}; + +builtin_platform_driver(of_fixed_factor_clk_driver); + #endif