From patchwork Mon Dec 25 09:38:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Kochetkov X-Patchwork-Id: 10132441 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 BEDBA60594 for ; Mon, 25 Dec 2017 09:38:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9AD92A60B for ; Mon, 25 Dec 2017 09:38:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E5FF2A617; Mon, 25 Dec 2017 09:38:37 +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=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2114C2A60B for ; Mon, 25 Dec 2017 09:38:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:References:Message-Id:Date: In-Reply-To:From:Subject:Mime-Version:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CxjTaujYcgw2gN8nNgkYZmae+D7M9pDmi3FxtGoQE7M=; b=IuU2SAc7gn6kSN nGZfszK95BIAZCEHcxYYvssVel5zlK4fFmFTqkq0GAkH5oqNC42dlQgycWUAfKTJez8eX3+7LUS1N WJSUEpVV78asDzo7+Kq7QX7yXiYY/SWooLyFNKg5m0GUW524AAEXvtylknWMFLRojJC3WW2mVKbBz LSTZAwg6A2BjhY5WJnNAddIf/sBQJO6oMOYgRROZOYZQV7Dmy6Dh8l0ys+xH4cSAYKUUh0gyOJmco lQh/+7baNv8hdsCrDnMLLYF9WJP6JxalJ1PLa0x4Cyyx1tK3UZud4bXpnc/+JdaV+g5qHUaP3ybAA 81sfRf62kH5MaZ53UAtw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eTPDM-00066K-3Z; Mon, 25 Dec 2017 09:38:32 +0000 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eTPDH-00065O-Cq; Mon, 25 Dec 2017 09:38:29 +0000 Received: by mail-lf0-x241.google.com with SMTP id w196so19338744lff.5; Mon, 25 Dec 2017 01:38:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=2xChJsDWTbubHXUM9u2JdV0ryecY5k1fOI8rU6/LVMY=; b=VFpn+FRAfpoSKUPEuslwXzISWYmGdLWHyhUyH2gxNd75/GVRkriRTCMr8/kD24A/TZ ip4laGlwzPM8Zq//3I6cfW9WorxiK3lFr+qRbWQJHus4DrqCaLNEgHGNFPAxbTQ+K+FA o1TNrwEJ6qzImU3dxotQqFMet1RRgpAJk52ndDMUmVFf/Zvu1lzyBlY1YJ3SYtYdrgne 6TKifnZPMF4k6MM1hSU1CxNSFyEEfE3rZsEoGUMkcdz0SU1b3161Wav543B3U23GHY28 sAtAq9n1BUbuA3ZntsZrLAHYL1AF9rMP8KICrPYWuam1jW3gxcMnWmqr0JThWLW5MaCz koww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=2xChJsDWTbubHXUM9u2JdV0ryecY5k1fOI8rU6/LVMY=; b=G5NlmMo3i3byIuw3RnF/OTX9ocylzo5UZmJoM65Gf1TXWNcKd1ZCwevrh1AZBYVdqD Tb9I0qgPVyXtx/R0N8UkBgia7oSjsh+xZBZHaMmyWU7TpTPIeZpHN/jy2pKvzrpgdNHw HMQEmGSYey1akZjoUMyK4yVLDMMyVNRyu71uNMIO52/HES5C0eqxa0BdOhc1dhsfcHlN qOOysU/J2GJLDDDvk6KJ8Nkc4mZPnKCfwhR3jSzWKM0seUHtfUr11ezHjBeHEe36WE4X 9Va4hKnXHU51xKSxjY2B1cSfkeVWMDr4GJnLj3QSBxEzKMUPWl4S3dgQlHg1aeN/HhWY 19jg== X-Gm-Message-State: AKGB3mIYTxm56I6UpmMiYGSKrfwG2e/dr6PEEobvXmrUOusC4jHOK0Il Dg73mMoe5Ieh40aku2lNNMc= X-Google-Smtp-Source: ACJfBosS+xVzjob0aTxD/Mx+45OAWDYy2PeB4UjXICb640X/ER6wNkPvjXX15bTfjmfbz9nlNHkVig== X-Received: by 10.25.219.78 with SMTP id s75mr3528902lfg.141.1514194693040; Mon, 25 Dec 2017 01:38:13 -0800 (PST) Received: from [192.168.1.38] ([185.35.119.87]) by smtp.gmail.com with ESMTPSA id a15sm5625312ljb.11.2017.12.25.01.38.11 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Dec 2017 01:38:12 -0800 (PST) Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: [PATCH 1/2] clk: rename clk_core_get_boundaries() to clk_hw_get_boundaries() and expose From: Alexander Kochetkov In-Reply-To: <20171221200743.GM7997@codeaurora.org> Date: Mon, 25 Dec 2017 12:38:10 +0300 Message-Id: <8EC4D15B-4A89-43FA-953E-95AF81417067@gmail.com> References: <1513872282-5370-1-git-send-email-al.kochet@gmail.com> <1513872282-5370-2-git-send-email-al.kochet@gmail.com> <20171221200743.GM7997@codeaurora.org> To: Stephen Boyd X-Mailer: Apple Mail (2.3124) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171225_013827_557342_D89E07FB X-CRM114-Status: GOOD ( 14.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , Michael Turquette , Elaine Zhang , LKML , linux-rockchip@lists.infradead.org, linux-clk@vger.kernel.org, LAK Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP > 21 дек. 2017 г., в 23:07, Stephen Boyd написал(а): > > Can you convert to the determine_rate op instead of round_rate? > That function should tell you the min/max limits so that you > don't need to query that information from the core. I converted rockchip_fractional_approximation() to rockchip_determine_rate() (see the patch attached). If it increase parent’s clock for out of limits value, than clock request will fail with -EINVAL, like with round_rate() approach. The problem is that min/max limits provided to determine_rate() is for clock for which the determine_rate() was called. While rockchip_determine_rate() (rockchip_fractional_approximation()) requires information about parent clock limits. How can I know parents clock limits for current clock? Implement determine_rate() for each parent clocks the same way I did for this one clock? Regards, Alexander. diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c index 3c1fb0d..1e0c701 100644 --- a/drivers/clk/rockchip/clk.c +++ b/drivers/clk/rockchip/clk.c @@ -174,23 +174,9 @@ static void rockchip_fractional_approximation(struct clk_hw *hw, unsigned long *m, unsigned long *n) { struct clk_fractional_divider *fd = to_clk_fd(hw); - unsigned long p_rate, p_parent_rate; - unsigned long min_rate = 0, max_rate = 0; - struct clk_hw *p_parent; unsigned long scale; - - p_rate = clk_hw_get_rate(clk_hw_get_parent(hw)); - if ((rate * 20 > p_rate) && (p_rate % rate != 0)) { - p_parent = clk_hw_get_parent(clk_hw_get_parent(hw)); - p_parent_rate = clk_hw_get_rate(p_parent); - clk_hw_get_boundaries(clk_hw_get_parent(hw), - &min_rate, &max_rate); - if (p_parent_rate < min_rate) - p_parent_rate = min_rate; - if (p_parent_rate > max_rate) - p_parent_rate = max_rate; - *parent_rate = p_parent_rate; - } + unsigned long rate_orig = rate; + unsigned long parent_rate_orig = *parent_rate; /* * Get rate closer to *parent_rate to guarantee there is no overflow @@ -204,8 +190,36 @@ static void rockchip_fractional_approximation(struct clk_hw *hw, rational_best_approximation(rate, *parent_rate, GENMASK(fd->mwidth - 1, 0), GENMASK(fd->nwidth - 1, 0), m, n); + + pr_info("%s: %s: rate:%lu -> %lu parent_rate:%lu -> %lu m:%lu n:%lu\n", + __func__, clk_hw_get_name(hw), rate_orig, rate, + parent_rate_orig, *parent_rate, + *m, *n); } +static int rockchip_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + unsigned long p_rate, p_parent_rate; + struct clk_hw *p_parent; + unsigned long best_parent_rate = req->best_parent_rate; + + p_rate = clk_hw_get_rate(clk_hw_get_parent(hw)); + if ((req->rate * 20 > p_rate) && (p_rate % req->rate != 0)) { + p_parent = clk_hw_get_parent(clk_hw_get_parent(hw)); + p_parent_rate = clk_hw_get_rate(p_parent); + req->best_parent_rate = p_parent_rate; + } + + pr_info("%s: %s: rate:%lu min_rate:%lu max_rate:%lu best_parent_rate:%lu -> %lu best_parent_hw:%s\n", + __func__, clk_hw_get_name(hw), req->rate, req->min_rate, req->max_rate, best_parent_rate, req->best_parent_rate, + req->best_parent_hw ? clk_hw_get_name(req->best_parent_hw) : ""); + + return 0; +} + +static struct clk_ops rockchip_clk_fractional_divider_ops; + static struct clk *rockchip_clk_register_frac_branch( struct rockchip_clk_provider *ctx, const char *name, const char *const *parent_names, u8 num_parents, @@ -253,7 +267,8 @@ static struct clk *rockchip_clk_register_frac_branch( div->nmask = GENMASK(div->nwidth - 1, 0) << div->nshift; div->lock = lock; div->approximation = rockchip_fractional_approximation; - div_ops = &clk_fractional_divider_ops; + div_ops = &rockchip_clk_fractional_divider_ops; + clk = clk_register_composite(NULL, name, parent_names, num_parents, NULL, NULL, @@ -392,6 +407,9 @@ struct rockchip_clk_provider * __init rockchip_clk_init(struct device_node *np, ctx->grf = syscon_regmap_lookup_by_phandle(ctx->cru_node, "rockchip,grf"); + rockchip_clk_fractional_divider_ops = clk_fractional_divider_ops; + rockchip_clk_fractional_divider_ops.determine_rate = rockchip_determine_rate; + return ctx; err_free: