Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2291504pxf; Sat, 13 Mar 2021 15:02:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzqc6dultMk4gan8oWChpYnbkpqIP8I5V1JvpcpbLRqg/DRWOaYaL6ATJXESG5Jxmgy+rhU X-Received: by 2002:aa7:de8b:: with SMTP id j11mr22121645edv.363.1615676527760; Sat, 13 Mar 2021 15:02:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615676527; cv=none; d=google.com; s=arc-20160816; b=FXHneC7UI2VExAFRhEXrFJ3neafr8FoA7tsk1RCH8wr8d5ZpJYMKRv2NHed9l4ujkT PZWvd+RiQcR5GY2l2btt78RODiPZ0n1JDg6mfftDZQWBu4AJcLI2ZPICF43/q/RK6QfX L44EktEPbPs4/7hUfOzkfqxIJiVCj67LT7HSIB+NzLxm9W8gha7O05H78c01SNu3tkGw wx0H7bCeqJxXv5J73igA3/HPQqK3FnYas/9vzvFccBiSur4t7jpqMXBzz+f/WuFIKITG 2fmzirLhmp6CzHrSenwIPQFLRNjRfsoEN0XhHhzSXszFH/IZtH2Uh1xl3fbKVFDsEibB KAYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:date:to:cc:from:subject :references:in-reply-to:content-transfer-encoding:mime-version :dkim-signature; bh=l3PgDSW+c5LMXdIC+UzBzFPOB2cl8sOuBXLi5N1wF0I=; b=PXFypBssj8k/P5Zs0IpsbDNxdDUl/XT8c684QwAoHsIXZZgigck1VF46gyoARwmgUT 8aDO/X/nVVBPtJZJMj3PlIzcX/IfHRF5Yoima1TLvFHoGmYpKnbaMpz8HEzMuWOfStBl z0R9aDnlI01isl0+DjkG6kdT0PynRpNLQtwdVdpRH6XO20g4+AwC8/kK7ad0ZgzkIhfK 9pHNG+nKJ+3YWWScfxJHAeauEBCxRePabkLbpDJpbRjNevupebf3e4vh/5xHLat7nuzh RC4cjUMDnaa10pdI+c1/xiA0Gg3a1BML/cB4fvFwey+Vzx4D1WlMpt2R9hUcPABOqrW6 GBHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=adaM4hqQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u12si8780719eda.121.2021.03.13.15.01.42; Sat, 13 Mar 2021 15:02:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=adaM4hqQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233634AbhCMXAB (ORCPT + 99 others); Sat, 13 Mar 2021 18:00:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:57592 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231756AbhCMXAA (ORCPT ); Sat, 13 Mar 2021 18:00:00 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2090064E87; Sat, 13 Mar 2021 23:00:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615676400; bh=JvN2gE2cwHT9RI41PHOKMwum4FYziRMG+R+kWsNa02Q=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=adaM4hqQBNnRAXFMA3Hm8KSklIkDvXedtL+Au187klkwYnhUZiuqCvdE1DHaAhjMx 0vn1iOC2Jnfpd0SRTQkE+pm5uywSq4IiJIMJZ8sT6CvRANwav485wnRiUsLAomrS1n ooKAbs9K/MBgGcIHWtqqm4oNYubE98kcX1I06e/9J1GS+lAooGomuphgo7ze8YproS 4eefVSwS3oUgXiTSJ8rNUcFO5XXYrvbpsvtrx8nXFhDcNMhs4tCQzu7YXCR1Yg3pdD bapyZVYlkGoBal16GPZww8YyitD94D764PKG37LQc6Sz2PKt+YLRTCPiuZkULNefzJ C6MtWf5i3GYuQ== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <1615467092-6982-1-git-send-email-tdas@codeaurora.org> References: <1615467092-6982-1-git-send-email-tdas@codeaurora.org> Subject: Re: [PATCH v2] clk: qcom: clk-rcg2: Add support for duty-cycle for RCG From: Stephen Boyd Cc: Rajendra Nayak , linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Taniya Das To: Michael Turquette , Taniya Das Date: Sat, 13 Mar 2021 14:59:58 -0800 Message-ID: <161567639878.1478170.18101287599042992816@swboyd.mtv.corp.google.com> User-Agent: alot/0.9.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Taniya Das (2021-03-11 04:51:32) > The root clock generators with MND divider has the capability to support > change in duty-cycle by updating the 'D'. Add the clock ops which would > check all the boundary conditions and enable setting the desired duty-cyc= le > as per the consumer. >=20 > Signed-off-by: Taniya Das > --- > drivers/clk/qcom/clk-rcg2.c | 42 +++++++++++++++++++++++++++++++++++++++= +++ > 1 file changed, 42 insertions(+) >=20 > diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c > index 42f13a2..aac6893 100644 > --- a/drivers/clk/qcom/clk-rcg2.c > +++ b/drivers/clk/qcom/clk-rcg2.c > @@ -357,6 +357,46 @@ static int clk_rcg2_set_floor_rate_and_parent(struct= clk_hw *hw, > return __clk_rcg2_set_rate(hw, rate, FLOOR); > } >=20 > +static int clk_rcg2_set_duty_cycle(struct clk_hw *hw, struct clk_duty *d= uty) > +{ > + struct clk_rcg2 *rcg =3D to_clk_rcg2(hw); > + u32 notn_m_val, n_val, m_val, d_val, not2d_val, mask, duty_per; > + int ret; > + > + if (!rcg->mnd_width) > + return 0; Shouldn't we fail this call if the duty cycle can't be changed? Or have another set of clk ops that doesn't support this clk op if the mnd=20 isn't present. > + > + mask =3D BIT(rcg->mnd_width) - 1; > + > + regmap_read(rcg->clkr.regmap, RCG_N_OFFSET(rcg), ¬n_m_val); > + regmap_read(rcg->clkr.regmap, RCG_M_OFFSET(rcg), &m_val); > + > + n_val =3D (~(notn_m_val) + m_val) & mask; > + > + duty_per =3D (duty->num * 100) / duty->den; > + > + /* Calculate 2d value */ > + d_val =3D DIV_ROUND_CLOSEST(n_val * duty_per * 2, 100); > + > + /* Check BIT WIDTHS OF 2d. If D is too big reduce Duty cycle. */ Why is BIT WIDTHS capitalized? And Duty? > + if (d_val > mask) > + d_val =3D mask; > + > + if ((d_val / 2) > (n_val - m_val)) > + d_val =3D (n_val - m_val) * 2; > + else if ((d_val / 2) < (m_val / 2)) > + d_val =3D m_val; > + > + not2d_val =3D ~d_val & mask; > + > + ret =3D regmap_update_bits(rcg->clkr.regmap, RCG_D_OFFSET(rcg), m= ask, > + not2d_val); > + if (ret) > + return ret; > + > + return update_config(rcg); > +} > + > const struct clk_ops clk_rcg2_ops =3D { > .is_enabled =3D clk_rcg2_is_enabled, > .get_parent =3D clk_rcg2_get_parent, > @@ -365,6 +405,7 @@ const struct clk_ops clk_rcg2_ops =3D { > .determine_rate =3D clk_rcg2_determine_rate, > .set_rate =3D clk_rcg2_set_rate, > .set_rate_and_parent =3D clk_rcg2_set_rate_and_parent, > + .set_duty_cycle =3D clk_rcg2_set_duty_cycle, Can you also implement get_duty_cycle? > }; > EXPORT_SYMBOL_GPL(clk_rcg2_ops); >