From patchwork Tue Jun 21 09:01:27 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: 9190003 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 EAA5260756 for ; Tue, 21 Jun 2016 09:15:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D79F727DB3 for ; Tue, 21 Jun 2016 09:15:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBFBF27FA3; Tue, 21 Jun 2016 09:15:28 +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=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 6277E27DB3 for ; Tue, 21 Jun 2016 09:15:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750978AbcFUJP1 (ORCPT ); Tue, 21 Jun 2016 05:15:27 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:33609 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751713AbcFUJPY (ORCPT ); Tue, 21 Jun 2016 05:15:24 -0400 Received: by mail-lf0-f68.google.com with SMTP id l188so2098878lfe.0 for ; Tue, 21 Jun 2016 02:15:23 -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; bh=wpfDkSUjNKRulQdIApBfAkEgehOGGc7Z9JVdmrGFfOk=; b=Sh4ebzAhAb09+slxAcfQY05ECAN/wmO5aAcbKxIS2Iy8Fl27TCGt3duJ4GOJFDuj19 g650vRHQPnYhAz8tS9A5MD12yZNDI7zl8gREpHfKwTxrPM8X2Acx5QJok7tPm4Pk4tcg t1y44CNpfnjZ4bpKJRijw2/DzFAWHLeaNQmi09gYe+8Lig4q3pUNUVP3laur6CZwK1vv FXoWsC4wG5CvBXW3nQAmQ5gaoKcuc7gy+u7PwUPLKTi9sZ5WKKz1jfvHUWl7JFkQIYQJ 32VM/l++v8DQseHflVmAnTJAl9ofSnzuklZySm9UlFdmxegdlepCnwq86e6L8wbxwB7F 0yxA== 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; bh=wpfDkSUjNKRulQdIApBfAkEgehOGGc7Z9JVdmrGFfOk=; b=PO2TeQmtvnkZch40vh/8D87tOcUXDtBYDpoMlarF0qnlCAoIttaZ6yFbItecbJIgdj iGL1i0RYGO9XdnxzmZnavBEdWp1sI2DTCR99jeaXWUUfrxGbbRyBdny4tT0MDSDluaEp npb6uZOveLfxLXk3la+LASUWc4DP7PEfpMXHsBPr5GzcaD/CXceKQY6qW4mrRqpcrFtQ 3GaMOetTMgmuUw3+kTSq5/tnq35AsePWCPK6x1SN4g3F7C7vuqrIVTQrwh87QtkwBUZq BzONfiB1qv/+mzsrsn++p5G3MTyM+f2LcDVLeZZL3kNxyWlmiMkQYuxOECZTakeMKtBN j6Uw== X-Gm-Message-State: ALyK8tLjVjHlRkqVF0zLL3e9jBXoR9iQuNMkPJaYwJrLTd081zF3/xMvxFF7I5BKrAWONg== X-Received: by 10.46.1.100 with SMTP id 97mr5663597ljb.26.1466499690887; Tue, 21 Jun 2016 02:01:30 -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 e41sm6412881lji.42.2016.06.21.02.01.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jun 2016 02:01:29 -0700 (PDT) From: Ricardo Ribalda Delgado To: Michael Turquette , Stephen Boyd , s.hauer@pengutronix.de, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Delgado Subject: [PATCH v3 1/2] clk: fixed-factor: Convert into a module platform driver Date: Tue, 21 Jun 2016 11:01:27 +0200 Message-Id: <1466499688-28625-1-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.8.1 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 --- v3: Changes proposed by: Stephen Boyd -Use OF_POPULATED flag v2: Changes proposed by: Stephen Boyd -Add error check -CodeStyle on of_device_ide -Use builtin_platform_driver() drivers/clk/clk-fixed-factor.c | 73 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c index 75cd6c792cb8..80b9e440f2c3 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,71 @@ 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) +{ + if (!_of_fixed_factor_clk_setup(node)) + of_node_set_flag(node, OF_POPULATED); } 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; + + /* + * This function is not executed when of_fixed_factor_clk_setup + * succeeded. + */ + + 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