Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751567AbbEFQQh (ORCPT ); Wed, 6 May 2015 12:16:37 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:11390 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750989AbbEFQQe (ORCPT ); Wed, 6 May 2015 12:16:34 -0400 X-PGP-Universal: processed; by hqnvupgp08.nvidia.com on Wed, 06 May 2015 09:14:36 -0700 Message-ID: <554A3E61.5040105@nvidia.com> Date: Wed, 6 May 2015 12:16:33 -0400 From: Rhyland Klein User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Thierry Reding CC: Benson Leung , Peter De Schrijver , Mike Turquette , Stephen Warren , Stephen Boyd , Alexandre Courbot , , , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v4 08/20] clk: tegra: pll: Add logic for handling SDM data References: <1430757460-9478-1-git-send-email-rklein@nvidia.com> <1430757460-9478-9-git-send-email-rklein@nvidia.com> <554916F8.2060908@nvidia.com> <20150506135719.GB22098@ulmo.nvidia.com> In-Reply-To: <20150506135719.GB22098@ulmo.nvidia.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3285 Lines: 90 On 5/6/2015 9:57 AM, Thierry Reding wrote: > * PGP Signed by an unknown key > > On Tue, May 05, 2015 at 03:16:08PM -0400, Rhyland Klein wrote: >> On 5/4/2015 7:01 PM, Benson Leung wrote: >>> On Mon, May 4, 2015 at 9:37 AM, Rhyland Klein wrote: >>>> @@ -495,6 +505,28 @@ static int _calc_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg, >>>> return 0; >>>> } >>>> >>>> +static void clk_pll_set_sdm_data(struct clk_hw *hw, >>>> + struct tegra_clk_pll_freq_table *cfg) >>>> +{ >>>> + struct tegra_clk_pll *pll = to_clk_pll(hw); >>>> + u32 val; >>>> + >>>> + if (!pll->params->sdm_din_reg) >>>> + return; >>>> + >>>> + if (cfg->sdm_data) { >>>> + val = pll_readl_sdm_din(pll) & (~sdm_din_mask(pll)); >>>> + val |= sdin_data_to_din(cfg->sdm_data) & sdm_din_mask(pll); >>>> + pll_writel_sdm_din(val, pll); >>>> + } >>>> + >>>> + val = pll_readl_sdm_ctrl(pll); >>>> + if (!cfg->sdm_data != !(val & pll->params->sdm_ctrl_en_mask)) { >>> >>> You can use sdm_en_mask(pll) here. >>> >>> I'm not super clear about what you're trying to accomplish here with >>> !cfg->sdm_data != !(val & mask). >>> Are you just checking if the masked value is different from sdm_data, >>> but accounting for the integer widths being different (u16 vs u32)? >> >> So I got clarification from the downstream author to be sure, and this >> is the answer to what this is checking: >> >> ( AND ) >> OR >> ( AND ) >> >> So the check is correct, just a complicated way of expressing it. > > Can it be rewritten to be less complicated? I hate it when I have to > look at code for several seconds and still not understand what it's > doing. Why not something that is closer to the pseudo code you gave: > > bool enabled = (val & pll->params->sdm_ctrl_en_mask) != 0; > > if ((enabled && cfg->sdm_data == 0) || (!enabled && cfg->sdm_data != 0)) > > ? Also I think this could use some could comments explaining what's > going on. Perhaps this could be simplified even further: > > if (cfg->sdm_data == 0 && enabled) > val &= ~pll->params->sdm_ctrl_en_mask; > > if (cfg->sdm_data != 0 && !enabled) > val |= pll->params->sdm_ctrl_en_mask; > > pll_writel_sdm_ctrl(val, pll); > > Now that I have a /much/ easier time reading and understanding. That may > not even require comments because it's pretty plain what's going on. But > there may be some advantage in adding comments about SDM in general. The > comment could be something like what you have in the commit message, so > that people don't have to go find the commit that added the code to find > out what this is doing. > > Thierry I agree that the original statement was confusing. I'll replace it with a simpler version, and comments never hurt :) -rhyland > > * Unknown Key > * 0x7F3EB3A1 > -- nvpublic -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/