From patchwork Mon May 22 11:23:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Gautam X-Patchwork-Id: 9739959 X-Patchwork-Delegate: agross@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 038B6601C2 for ; Mon, 22 May 2017 11:24:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E762828402 for ; Mon, 22 May 2017 11:24:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DAA6F28453; Mon, 22 May 2017 11:24:29 +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_SIGNED, 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 6D11628415 for ; Mon, 22 May 2017 11:24:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759207AbdEVLYQ (ORCPT ); Mon, 22 May 2017 07:24:16 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:38012 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758875AbdEVLYK (ORCPT ); Mon, 22 May 2017 07:24:10 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 1749A60AA8; Mon, 22 May 2017 11:23:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1495452233; bh=pmgVCXDUYTIDE6UICIbhYehhgKBXsQD4Cnr3If0+D7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BWqvbNZqqkl+NUZyNApJM4+w1/1I2zZSx/IW56nD77QTSxPZibqKQbLhBml+dNTr1 /xf8Xfy5ckR9gX6Bak5RpBzg9yyFZ0i3W8PgUWZGi1v49TA02LdB8SOulP56oDxg5k E+L+Om+Lu8kMCM8smYo9BSbLOSuGpTdFgHXG9Soo= Received: from blr-ubuntu-41.ap.qualcomm.com (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.18.19]) (using TLSv1.1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek.gautam@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 4703E60A06; Mon, 22 May 2017 11:23:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1495452232; bh=pmgVCXDUYTIDE6UICIbhYehhgKBXsQD4Cnr3If0+D7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cp/hhGH7e32byQHE4lSsde60ViWg9RzWe3WOpq2qRiWdxiQ4ynw65xJojJ4jWaT/u bEMtzkd5+AwP9Wtqy3Bt1LA+WzLJb+Bxdn1v4bLpi7t91axMLrzEHNAtxLwQhpzo76 IjcpMlYUPo6vYuOteila+bha6aO/BjSGv2wR8eJ4= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 4703E60A06 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=vivek.gautam@codeaurora.org From: Vivek Gautam To: p.zabel@pengutronix.de, linux-kernel@vger.kernel.org Cc: linux-tegra@vger.kernel.org, linux-usb@vger.kernel.org, jonathanh@nvidia.com, balbi@kernel.org, gregkh@linuxfoundation.org, linux-arm-msm@vger.kernel.org, Vivek Gautam , Thierry Reding Subject: [PATCH v4 4/4] soc/tegra: pmc: Use the new reset APIs to manage reset controllers Date: Mon, 22 May 2017 16:53:27 +0530 Message-Id: <1495452207-6129-5-git-send-email-vivek.gautam@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1495452207-6129-1-git-send-email-vivek.gautam@codeaurora.org> References: <1495452207-6129-1-git-send-email-vivek.gautam@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make use of reset_control_array_*() set of APIs to manage an array of reset controllers available with the device. Cc: Jon Hunter Cc: Thierry Reding Cc: Philipp Zabel Signed-off-by: Vivek Gautam Acked-by: Jon Hunter Tested-by: Jon Hunter --- drivers/soc/tegra/pmc.c | 91 +++++++++++++++++-------------------------------- 1 file changed, 31 insertions(+), 60 deletions(-) diff --git a/drivers/soc/tegra/pmc.c b/drivers/soc/tegra/pmc.c index e233dd5dcab3..668f5d3d3635 100644 --- a/drivers/soc/tegra/pmc.c +++ b/drivers/soc/tegra/pmc.c @@ -124,8 +124,8 @@ struct tegra_powergate { unsigned int id; struct clk **clks; unsigned int num_clks; - struct reset_control **resets; - unsigned int num_resets; + struct reset_control *reset; + struct reset_control_array *resets; }; struct tegra_io_pad_soc { @@ -348,32 +348,20 @@ static int tegra_powergate_enable_clocks(struct tegra_powergate *pg) return err; } -static int tegra_powergate_reset_assert(struct tegra_powergate *pg) +static inline int tegra_powergate_reset_assert(struct tegra_powergate *pg) { - unsigned int i; - int err; + if (!IS_ERR_OR_NULL(pg->reset)) + return reset_control_assert(pg->reset); - for (i = 0; i < pg->num_resets; i++) { - err = reset_control_assert(pg->resets[i]); - if (err) - return err; - } - - return 0; + return reset_control_array_assert(pg->resets); } -static int tegra_powergate_reset_deassert(struct tegra_powergate *pg) +static inline int tegra_powergate_reset_deassert(struct tegra_powergate *pg) { - unsigned int i; - int err; + if (!IS_ERR_OR_NULL(pg->reset)) + return reset_control_deassert(pg->reset); - for (i = 0; i < pg->num_resets; i++) { - err = reset_control_deassert(pg->resets[i]); - if (err) - return err; - } - - return 0; + return reset_control_array_deassert(pg->resets); } static int tegra_powergate_power_up(struct tegra_powergate *pg, @@ -566,8 +554,13 @@ int tegra_powergate_sequence_power_up(unsigned int id, struct clk *clk, pg.id = id; pg.clks = &clk; pg.num_clks = 1; - pg.resets = &rst; - pg.num_resets = 1; + + /* + * Handle the reset control passed from the client separately. + * So, the pmc will either have this single reset control, or, + * have a list of reset controls managed by the driver on its own. + */ + pg.reset = rst; err = tegra_powergate_power_up(&pg, false); if (err) @@ -755,45 +748,26 @@ static int tegra_powergate_of_get_clks(struct tegra_powergate *pg, static int tegra_powergate_of_get_resets(struct tegra_powergate *pg, struct device_node *np, bool off) { - struct reset_control *rst; - unsigned int i, count; int err; - count = of_count_phandle_with_args(np, "resets", "#reset-cells"); - if (count == 0) - return -ENODEV; - - pg->resets = kcalloc(count, sizeof(rst), GFP_KERNEL); - if (!pg->resets) - return -ENOMEM; - - for (i = 0; i < count; i++) { - pg->resets[i] = of_reset_control_get_by_index(np, i); - if (IS_ERR(pg->resets[i])) { - err = PTR_ERR(pg->resets[i]); - goto error; - } - - if (off) - err = reset_control_assert(pg->resets[i]); - else - err = reset_control_deassert(pg->resets[i]); - - if (err) { - reset_control_put(pg->resets[i]); - goto error; - } + pg->resets = of_reset_control_array_get_exclusive(np); + if (IS_ERR(pg->resets)) { + pr_err("failed to get device resets\n"); + return PTR_ERR(pg->resets); } - pg->num_resets = count; + if (off) + err = reset_control_array_assert(pg->resets); + else + err = reset_control_array_deassert(pg->resets); - return 0; + if (err) + goto put_reset; -error: - while (i--) - reset_control_put(pg->resets[i]); + return 0; - kfree(pg->resets); +put_reset: + reset_control_array_put(pg->resets); return err; } @@ -885,10 +859,7 @@ static void tegra_powergate_add(struct tegra_pmc *pmc, struct device_node *np) pm_genpd_remove(&pg->genpd); remove_resets: - while (pg->num_resets--) - reset_control_put(pg->resets[pg->num_resets]); - - kfree(pg->resets); + reset_control_array_put(pg->resets); remove_clks: while (pg->num_clks--)