From patchwork Tue Jun 21 09:01:28 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: 9190013 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 CAE0C60756 for ; Tue, 21 Jun 2016 09:19:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B809F27FA3 for ; Tue, 21 Jun 2016 09:19:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC2B827FE4; Tue, 21 Jun 2016 09:19:08 +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 29D6227FA3 for ; Tue, 21 Jun 2016 09:19:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751002AbcFUJTH (ORCPT ); Tue, 21 Jun 2016 05:19:07 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:36489 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750907AbcFUJTC (ORCPT ); Tue, 21 Jun 2016 05:19:02 -0400 Received: by mail-lf0-f67.google.com with SMTP id a2so2092986lfe.3 for ; Tue, 21 Jun 2016 02:19:01 -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=LX3LA0UJALMSDXlEB1MwfC5f8/Ixh7GeDzRvKgnn6L8=; b=bgaH6ioSzkBDOn5QpGvW40+M4wAR3NzRUSJSbZA/XylLO96kZfSEA/ygCyIVoYZ8m9 rmRcIH+tccoiL1q3DifQu5Dak4gFKd1B/KPWSiibL+JBUPH7LRt5uRX2w7ixPxGlL1K7 V76SvDnfsCDYASIRaZgJZlquQcZdl64lm83uS/x4771UT8mCke/tPe8ENO3Qd7vQ8yWi 7KBYCYwzWn8PIU0i4ESnminY4IVt+svM95EBj3C5yn9eVFNog1Vu5IyYaqPALt6O26mJ fuDVJz92rlSVZkbxkD00PytnZFfAGX83Ma3g7s5sQ6/0m7LxYRA69jcv9/d1RErAlnl+ PQWA== 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=LX3LA0UJALMSDXlEB1MwfC5f8/Ixh7GeDzRvKgnn6L8=; b=aWZyWK/Tii+EH7J8GnMzIUfRvrV0sF4KFaZX/j9lxtbWYVIOGFXsQkyw3Y2z6zTsFv WyoDQaRKavLFcm+Z0xMhB2pz+P1F+l2830DCKjSloJP15ZTY6BJsG2FjEgY/yj5SrBRy SvnQJaVLb5TjisB1mpAGoDDWSLysp2i7w1H36gUG7I+1dA8nwdwTMatzGoKO0aJA5vWY vKlQMu5f8sywMDmt1yuPsbsq9k9YqqpWuB08kt4QoNSWxDfjIwZTzzyKPe2Ag3tpM0gc N1JdHaCjNItZAPYumjBRABny8ozgSZj8BqMtg0qr2ZDPqNKdGTqkCWnIaXRXVdZsARTk SJyQ== X-Gm-Message-State: ALyK8tIuxR8j6zBJbnJiBQdpsDDywFDxivqLOtZwcIGdkeyJT8yYuI9PcB/uMflMIaW9lg== X-Received: by 10.46.0.78 with SMTP id 75mr5662245lja.48.1466499693056; Tue, 21 Jun 2016 02:01:33 -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.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jun 2016 02:01:31 -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 2/2] clk: fixed-rate: Convert into a module platform driver Date: Tue, 21 Jun 2016 11:01:28 +0200 Message-Id: <1466499688-28625-2-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1466499688-28625-1-git-send-email-ricardo.ribalda@gmail.com> References: <1466499688-28625-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-rate 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-rate.c | 70 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/drivers/clk/clk-fixed-rate.c b/drivers/clk/clk-fixed-rate.c index 8e4453eb54e8..d5f9aa086acc 100644 --- a/drivers/clk/clk-fixed-rate.c +++ b/drivers/clk/clk-fixed-rate.c @@ -15,6 +15,7 @@ #include #include #include +#include /* * DOC: basic fixed-rate clock that cannot gate @@ -149,15 +150,16 @@ EXPORT_SYMBOL_GPL(clk_unregister_fixed_rate); /** * of_fixed_clk_setup() - Setup function for simple fixed rate clock */ -void of_fixed_clk_setup(struct device_node *node) +struct clk *_of_fixed_clk_setup(struct device_node *node) { struct clk *clk; const char *clk_name = node->name; u32 rate; u32 accuracy = 0; + int ret; if (of_property_read_u32(node, "clock-frequency", &rate)) - return; + return ERR_PTR(-EIO); of_property_read_u32(node, "clock-accuracy", &accuracy); @@ -165,9 +167,69 @@ void of_fixed_clk_setup(struct device_node *node) clk = clk_register_fixed_rate_with_accuracy(NULL, clk_name, NULL, 0, rate, accuracy); - 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 of_fixed_clk_setup(struct device_node *node) +{ + if (!_of_fixed_clk_setup(node)) + of_node_set_flag(node, OF_POPULATED); } EXPORT_SYMBOL_GPL(of_fixed_clk_setup); CLK_OF_DECLARE(fixed_clk, "fixed-clock", of_fixed_clk_setup); + +static int of_fixed_clk_remove(struct platform_device *pdev) +{ + struct clk *clk = platform_get_drvdata(pdev); + + if (clk) + clk_unregister_fixed_rate(clk); + + return 0; +} + +static int of_fixed_clk_probe(struct platform_device *pdev) +{ + struct clk *clk; + + /* + * This function is not executed when of_fixed_clk_setup + * succeeded. + */ + + clk = _of_fixed_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_clk_ids[] = { + { .compatible = "fixed-clock" }, + { }, +}; +MODULE_DEVICE_TABLE(of, of_fixed_clk_ids); + +static struct platform_driver of_fixed_clk_driver = { + .driver = { + .name = "of_fixed_clk", + .of_match_table = of_fixed_clk_ids, + }, + .probe = of_fixed_clk_probe, + .remove = of_fixed_clk_remove, +}; + +builtin_platform_driver(of_fixed_clk_driver); #endif