From patchwork Wed Feb 27 18:56:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1049103 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="ci4LRAF0"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 448lP01bH9z9sBR for ; Thu, 28 Feb 2019 06:00:04 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id D8626C21D9A; Wed, 27 Feb 2019 18:58:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 05B18C21C29; Wed, 27 Feb 2019 18:57:59 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D4C71C21C57; Wed, 27 Feb 2019 18:57:41 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by lists.denx.de (Postfix) with ESMTPS id 653E1C21DFB for ; Wed, 27 Feb 2019 18:57:37 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id a3so8421236pff.11 for ; Wed, 27 Feb 2019 10:57:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jGO2O8OOoioGSQgGYW8XYDD3DHEM2FB2KAw6BqjhaK4=; b=ci4LRAF0Jke0eZ94q4yppaFr/kiJF94udV3olM4ld5+8y19ltgsCd0JILke6XKlZKJ jRCee4hhOf3gFT0UaoKu7h9hI3q1MlWqPXjeoV2P8jtY4Sh/qGSrcyIROiKsgMQF9GnX 0TQs6KWNzhFh1ACyn2JrY4sCZXmIILqJgckjo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jGO2O8OOoioGSQgGYW8XYDD3DHEM2FB2KAw6BqjhaK4=; b=a4TbVJJnrBE+zhFOHFrGriZ6L56pavuiTJmy5N5mFsNFbClZJ4zdFM2L1vuYuhO+K7 vGZXIAltbp0x7voRzjB++qJJsjDCPEC4ANRg/8+TsQin4gbe+0QoZ74Qti+z3n/61dHM CRaQgX9VStKyVeODZ7fJi7rG/ClWvhYjtnlUrCWRSMUTxzmp3bB6Ur5cnjrroOB92nYb lc6/bEnNWQEBrxwWwXxJNDRxb5JzD5BX2aZbeJlQs2K4Qzc6LFu2gvMZyWlok++QbmZz LAv37zMW5RIvCjWVadqeYCjnf5gN/O2bYz/1U2CQqJEM+ShwI0WY9A46jLSP7ELBaTx0 CtNw== X-Gm-Message-State: AHQUAubqQuj/zqzV1MSkhWU2bHDuzWQXDJRSYQS/CNsmXDi3ItpEzaBQ IKPpFbFJ4uIP2Gv5cK1n9UCm3w== X-Google-Smtp-Source: AHgI3IaeKzblWfwmCMnggcY8CnEncJz9b7xfqGF3HiLcJaL5d5aqNwtO24S0OQuU084BIj5+K2yoFw== X-Received: by 2002:a63:d158:: with SMTP id c24mr4363780pgj.34.1551293855971; Wed, 27 Feb 2019 10:57:35 -0800 (PST) Received: from localhost.localdomain ([115.97.184.151]) by smtp.gmail.com with ESMTPSA id z6sm22020802pgo.31.2019.02.27.10.57.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Feb 2019 10:57:34 -0800 (PST) From: Jagan Teki To: =?utf-8?q?Andr=C3=A9_Przywara?= , Maxime Ripard , Chen-Yu Tsai Date: Thu, 28 Feb 2019 00:26:52 +0530 Message-Id: <20190227185701.15545-5-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20190227185701.15545-1-jagan@amarulasolutions.com> References: <20190227185701.15545-1-jagan@amarulasolutions.com> MIME-Version: 1.0 Cc: u-boot@lists.denx.de, linux-sunxi@googlegroups.com, Stephen Warren Subject: [U-Boot] [PATCH v3 04/13] clk: Get the CLK by index without device X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Getting a CLK by index with device is not straight forward for some use-cases like handling clock operations for child node in parent driver. So we need to process the child node in parent probe via ofnode and process CLK operation for child without udevice but with ofnode. So add clk_get_by_index_nodev() and move the common code in clk_get_by_index_tail() to use for clk_get_by_index() Cc: Stephen Warren Signed-off-by: Jagan Teki Reviewed-by: Simon Glass --- drivers/clk/clk-uclass.c | 61 +++++++++++++++++++++++++++++++++++++++- include/clk.h | 15 ++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index 844b87cc33..d9236c5b51 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -54,6 +54,46 @@ static int clk_of_xlate_default(struct clk *clk, return 0; } +static int clk_get_by_index_tail(int ret, ofnode node, + struct ofnode_phandle_args *args, + const char *list_name, int index, + struct clk *clk) +{ + struct udevice *dev_clk; + const struct clk_ops *ops; + + assert(clk); + clk->dev = NULL; + if (ret) + goto err; + + ret = uclass_get_device_by_ofnode(UCLASS_CLK, args->node, &dev_clk); + if (ret) { + debug("%s: uclass_get_device_by_of_offset failed: err=%d\n", + __func__, ret); + return ret; + } + + clk->dev = dev_clk; + + ops = clk_dev_ops(dev_clk); + + if (ops->of_xlate) + ret = ops->of_xlate(clk, args); + else + ret = clk_of_xlate_default(clk, args); + if (ret) { + debug("of_xlate() failed: %d\n", ret); + return ret; + } + + return clk_request(dev_clk, clk); +err: + debug("%s: Node '%s', property '%s', failed to request CLK index %d: %d\n", + __func__, ofnode_get_name(node), list_name, index, ret); + return ret; +} + static int clk_get_by_indexed_prop(struct udevice *dev, const char *prop_name, int index, struct clk *clk) { @@ -100,7 +140,26 @@ static int clk_get_by_indexed_prop(struct udevice *dev, const char *prop_name, int clk_get_by_index(struct udevice *dev, int index, struct clk *clk) { - return clk_get_by_indexed_prop(dev, "clocks", index, clk); + struct ofnode_phandle_args args; + int ret; + + ret = dev_read_phandle_with_args(dev, "clocks", "#clock-cells", 0, + index, &args); + + return clk_get_by_index_tail(ret, dev_ofnode(dev), &args, "clocks", + index > 0, clk); +} + +int clk_get_by_index_nodev(ofnode node, int index, struct clk *clk) +{ + struct ofnode_phandle_args args; + int ret; + + ret = ofnode_parse_phandle_with_args(node, "clocks", "#clock-cells", 0, + index > 0, &args); + + return clk_get_by_index_tail(ret, node, &args, "clocks", + index > 0, clk); } int clk_get_bulk(struct udevice *dev, struct clk_bulk *bulk) diff --git a/include/clk.h b/include/clk.h index 8e366163f9..d24e99713a 100644 --- a/include/clk.h +++ b/include/clk.h @@ -8,6 +8,7 @@ #ifndef _CLK_H_ #define _CLK_H_ +#include #include #include @@ -100,6 +101,20 @@ int clk_get_by_index_platdata(struct udevice *dev, int index, */ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk); +/** + * clock_get_by_index_nodev - Get/request a clock by integer index + * without a device. + * + * This is a version of clk_get_by_index() that does not use a device. + * + * @node: The client ofnode. + * @index: The index of the clock to request, within the client's list of + * clocks. + * @clock A pointer to a clock struct to initialize. + * @return 0 if OK, or a negative error code. + */ +int clk_get_by_index_nodev(ofnode node, int index, struct clk *clk); + /** * clock_get_bulk - Get/request all clocks of a device. *