Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp516071pxf; Wed, 10 Mar 2021 10:45:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwFoei/T4kBgHo77LQwGfVW3D4ha4A+lcaiH8LFgHVh71KmNtT0MH2vXn157F8s3LHGgvMD X-Received: by 2002:aa7:da04:: with SMTP id r4mr4878919eds.343.1615401957263; Wed, 10 Mar 2021 10:45:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615401957; cv=none; d=google.com; s=arc-20160816; b=JJxVIEZqfJPkdiaYLdUCUyFdqtHv0KjnDv2t+L1/Zp6Zm8xf5acISvcASh9Euqvu1S zAdJu2NrDJPg1UHRUEXSZP4D1sPRiLi000kuQdMAOT8s2omHlOMyMLQHlZhI1I/48nJF j4dDq+h190fFKYFDP3IQlGeMz6fNc9IYAK6ISiD46b9j5CE6W/0IaxfUYSbY91iWpaYL QU5QYAi/R2NngAqZ8ps3nBpNfkg/iiDt1z5pEpQQtCtCcG1s0may6seo6JN6xSypZpOL 9uBh1wSVsT+gGsWRd6C14xkAXI/Bb1U3KdH2SmcJbsH5KPJqYGwFXpwkz45aB/pQ3PWV AnIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:dmarc-filter :sender:dkim-signature; bh=F2JTvsNlkIMMJh2BTm0uaQtaxygT/jOeBnJgSyPDleU=; b=rD+g7v08Li4YV03igv7k07nU2JDgi8OpO0Ue40OrO63JshGzvV5N94I3+Ss0b99Lz6 Y4S+8UJIIfo5MV3XVDH5qk1zpbNlv6rGBDLBnVgIcacrWB1ljdMIGCZRVNSbt5iUx28u 3fm7PPgpgAth72fz/t05upsR9dOc0zawjFWVyNa5UIf6EsQxQgwZnjw2e0rVd0/5nAzy R5c4pYgXUb9JgpR+JXgHvzC3+wdBMZ5hv3ahz4iU2Qz7b8elI4jpeubieKujmQxa9XuP gh0qBh5AvuEoGwPGA4v76qDrX+YJyLgzl5xYnM/vfhGwkjzEaotkfsx37mAqBGNHI93I uvKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=TBciUygV; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d1si132475ejz.282.2021.03.10.10.45.34; Wed, 10 Mar 2021 10:45:57 -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=@mg.codeaurora.org header.s=smtp header.b=TBciUygV; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233475AbhCJSo1 (ORCPT + 99 others); Wed, 10 Mar 2021 13:44:27 -0500 Received: from z11.mailgun.us ([104.130.96.11]:41926 "EHLO z11.mailgun.us" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233209AbhCJSoW (ORCPT ); Wed, 10 Mar 2021 13:44:22 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1615401862; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=F2JTvsNlkIMMJh2BTm0uaQtaxygT/jOeBnJgSyPDleU=; b=TBciUygVvJpcgAkjWa+2OBuqXs4XGj86S43np4Xf4BXTgVRFuPo25gFL2xWBev1fCaumFNHE 6o4rXCSPjq1cePAbH1Ty5+z123x5eOoj0bsB/SGzfkVL+mc2nnbXIYQ9raSfyiV9ua97lh5l hfAgPEw81+4rQUF9ZlCq/0F0UMU= X-Mailgun-Sending-Ip: 104.130.96.11 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n01.prod.us-west-2.postgun.com with SMTP id 60491378fa6ebd85e8008ec1 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 10 Mar 2021 18:44:08 GMT Sender: tdas=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 8BCA8C433CA; Wed, 10 Mar 2021 18:44:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00,SPF_FAIL, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from tdas-linux.qualcomm.com (unknown [202.46.22.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: tdas) by smtp.codeaurora.org (Postfix) with ESMTPSA id E526BC433C6; Wed, 10 Mar 2021 18:44:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org E526BC433C6 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=tdas@codeaurora.org From: Taniya Das To: Stephen Boyd , =?UTF-8?q?Michael=20Turquette=20=C2=A0?= 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 Subject: [PATCH v1] clk: qcom: clk-rcg2: Add support for duty-cycle for RCG Date: Thu, 11 Mar 2021 00:13:48 +0530 Message-Id: <1615401828-6905-1-git-send-email-tdas@codeaurora.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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-cycle as per the consumer. Signed-off-by: Taniya Das --- drivers/clk/qcom/clk-rcg2.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c index 42f13a2..e070f1a 100644 --- a/drivers/clk/qcom/clk-rcg2.c +++ b/drivers/clk/qcom/clk-rcg2.c @@ -357,6 +357,44 @@ static int clk_rcg2_set_floor_rate_and_parent(struct clk_hw *hw, return __clk_rcg2_set_rate(hw, rate, FLOOR); } +static int clk_rcg2_set_duty_cycle(struct clk_hw *hw, struct clk_duty *duty) +{ + struct clk_rcg2 *rcg = 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; + + mask = 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 = (~(notn_m_val) + m_val) & mask; + + /* Calculate 2d value */ + d_val = DIV_ROUND_CLOSEST(n_val * duty_per * 2, 100); + + /* Check BIT WIDTHS OF 2d. If D is too big reduce Duty cycle. */ + if (d_val > mask) + d_val = mask; + + if ((d_val / 2) > (n_val - m_val)) + d_val = (n_val - m_val) * 2; + else if ((d_val / 2) < (m_val / 2)) + d_val = m_val; + + not2d_val = ~d_val & mask; + + ret = regmap_update_bits(rcg->clkr.regmap, RCG_D_OFFSET(rcg), mask, + not2d_val); + if (ret) + return ret; + + return update_config(rcg); +} + const struct clk_ops clk_rcg2_ops = { .is_enabled = clk_rcg2_is_enabled, .get_parent = clk_rcg2_get_parent, @@ -365,6 +403,7 @@ const struct clk_ops clk_rcg2_ops = { .determine_rate = clk_rcg2_determine_rate, .set_rate = clk_rcg2_set_rate, .set_rate_and_parent = clk_rcg2_set_rate_and_parent, + .set_duty_cycle = clk_rcg2_set_duty_cycle, }; EXPORT_SYMBOL_GPL(clk_rcg2_ops); @@ -376,6 +415,7 @@ const struct clk_ops clk_rcg2_floor_ops = { .determine_rate = clk_rcg2_determine_floor_rate, .set_rate = clk_rcg2_set_floor_rate, .set_rate_and_parent = clk_rcg2_set_floor_rate_and_parent, + .set_duty_cycle = clk_rcg2_set_duty_cycle, }; EXPORT_SYMBOL_GPL(clk_rcg2_floor_ops); -- Qualcomm INDIA, on behalf of Qualcomm Innovation Center, Inc.is a member of the Code Aurora Forum, hosted by the Linux Foundation.