From patchwork Wed Feb 14 18:30:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 201092 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1417109dyb; Wed, 14 Feb 2024 10:34:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVs6p+D3AjeJlwVzMJND28PI/wAOSoIS/5X9w3Mm+uYBJEQjPiz/73pECqv7wPAmZAxme7ArEQC2Z4NoMeoynLQOo6jng== X-Google-Smtp-Source: AGHT+IGY2fYkA3p65jThlll3IAPxvw8eEH0eKFfgU7kYsHL1NpuOCZ72boX9g55mAw/pInM2PpLv X-Received: by 2002:a05:6402:4311:b0:563:7db2:4fd8 with SMTP id m17-20020a056402431100b005637db24fd8mr2206209edc.35.1707935650255; Wed, 14 Feb 2024 10:34:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707935650; cv=pass; d=google.com; s=arc-20160816; b=kDe9fM90giwiy34nDMSQcKrd7FN1rJZXkdQoRMpkj6ZIV4X9TuqPUjF6ecDPPNcLNS omGh9fzmW9b2CBbBHebDY+dlHDTgqQMgsogfqfVwycv2Mau/uo2ooRhOxSxQsS2yTBFE V17KnvhOJwsX/PgGwGtx+9QHxdY7kR1KCtc0xowcwDinhLd0bN1lP8T6Wg+2fBNqUB7H GIWmUnmyB7uurYHW7yV2w2LQPfcTbnhqUtHnnlzvqKPQsi87qDKrdm74DZtEw4m3Ey5g IE75k1tNa37ubLfkbRlEq6FSGa79moPsmongVi3Ts4VoYrDgnUfpAVUzIRJYB+2ouim6 CbSQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=+Z4d3J4drSWQlGkJPtH7vnS43bJdAAIsYDpWVLX2/Dg=; fh=Bj3tRJ3rz+dXVC+KPZk3YICQmSj2b03AHCMKMP29vE8=; b=gEs/I/T4fdC1vKget3PnOITe78Jsqn9gEpDXNAaRjttizIkd0Dk9QYSK7M+GkZ5NAZ gxqv4V7trAi/yREUYMy1I1fW/vnefaJfSeomAi4NeLKm4Bdno9ZCj2YbPZ6WYLwSIYdn nr4J/fSMynB+Eylr8SlD+WfvpqMWQ7gL3k76vg1Zy/ZeAJjag1HIkhw2QP31pEX6A7F7 MAYph+1V8PPgDLzBlKkSgUzpxmfWZKzdgRUZUIZRAAAlYlJWWqAQeKaJs8CfwqMo2ZtI 9LhETC9iHX03ZPrjr+CmpZgJag/D8+vzI2mdMS+vbpzKv8YWMaevY2Dp4Dl1q25myMOJ 03ww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-65811-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65811-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVTSSeKkXYO6JNxDaetrv/4dKTHSGj6v4MG3QVBPztvPg921IOyNx7ig4wKJdhZViVYnaX6L7nBUDVb95Pcx5+nkMMrig== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h7-20020a05640250c700b0056175cde48csi4882915edb.532.2024.02.14.10.34.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 10:34:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65811-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-65811-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65811-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 765631F2B528 for ; Wed, 14 Feb 2024 18:32:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF6E812F599; Wed, 14 Feb 2024 18:30:48 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C270412EBFB; Wed, 14 Feb 2024 18:30:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935447; cv=none; b=o63yIyBWFqCrx08kbAqijk9srrW2klSPNWfKpyJUtN9QfIooqvd3Ek2I9rFERAwkJjm4W2AmJBf3+6b9yfBjYCH03a87XSh/E6zWdMasY+rlgEbQO+o9Cm/VEGILIKyxr6N1lvDLK8OrMBZOn8dJBYEf0Zj051uO+lGqAI7UPe8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935447; c=relaxed/simple; bh=WYEne98DDgqD6wOMHk6cJ+Hy4mmBoGUxdY4E2T7jmSo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hVS4eoL602I4gi4Cqc8urm0eL2PWMEDOnU0oI3PLteoHzmepv+bKkB1eMd5nNS6ys3MRYGKuGW9EC0y124YIBUbt7wyq1g5V6uOUhE5Q63FgjEQWAe+zW3lHJ6J+D2CN20ruRmLXPUsJF09ufZZlJ4sxrPOjomdHSB2bCP0f2lE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 28EA7DA7; Wed, 14 Feb 2024 10:31:26 -0800 (PST) Received: from pluto.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 20E533F7B4; Wed, 14 Feb 2024 10:30:43 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, quic_nkela@quicinc.com, souvik.chakravarty@arm.com, Cristian Marussi , Michael Turquette , Stephen Boyd , linux-clk@vger.kernel.org Subject: [PATCH 7/7] clk: scmi: Support get/set duty_cycle operations Date: Wed, 14 Feb 2024 18:30:06 +0000 Message-ID: <20240214183006.3403207-8-cristian.marussi@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214183006.3403207-1-cristian.marussi@arm.com> References: <20240214183006.3403207-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790900332353168805 X-GMAIL-MSGID: 1790900332353168805 Provide the CLK framework callbacks related to get/set clock duty cycle if the relared SCMI clock supports OEM extended configurations. CC: Michael Turquette CC: Stephen Boyd CC: linux-clk@vger.kernel.org Signed-off-by: Cristian Marussi Acked-by: Stephen Boyd --- drivers/clk/clk-scmi.c | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/clk/clk-scmi.c b/drivers/clk/clk-scmi.c index b91a0dbd2fe0..9d3b1e749226 100644 --- a/drivers/clk/clk-scmi.c +++ b/drivers/clk/clk-scmi.c @@ -158,6 +158,45 @@ static int scmi_clk_atomic_is_enabled(struct clk_hw *hw) return !!enabled; } +static int scmi_clk_get_duty_cycle(struct clk_hw *hw, struct clk_duty *duty) +{ + int ret; + u32 val; + struct scmi_clk *clk = to_scmi_clk(hw); + + ret = scmi_proto_clk_ops->config_oem_get(clk->ph, clk->id, + SCMI_CLOCK_CFG_DUTY_CYCLE, + &val, NULL, false); + if (!ret) { + duty->num = val; + duty->den = 100; + } else { + dev_warn(clk->dev, + "Failed to get duty cycle for clock ID %d\n", clk->id); + } + + return ret; +} + +static int scmi_clk_set_duty_cycle(struct clk_hw *hw, struct clk_duty *duty) +{ + int ret; + u32 val; + struct scmi_clk *clk = to_scmi_clk(hw); + + /* SCMI OEM Duty Cycle is expressed as a percentage */ + val = (duty->num * 100) / duty->den; + ret = scmi_proto_clk_ops->config_oem_set(clk->ph, clk->id, + SCMI_CLOCK_CFG_DUTY_CYCLE, + val, false); + if (ret) + dev_warn(clk->dev, + "Failed to set duty cycle(%u/%u) for clock ID %d\n", + duty->num, duty->den, clk->id); + + return ret; +} + static int scmi_clk_ops_init(struct device *dev, struct scmi_clk *sclk, const struct clk_ops *scmi_ops) { @@ -256,6 +295,12 @@ scmi_clk_ops_alloc(struct scmi_clk *sclk, bool atomic_capable, if (!ci->parent_ctrl_forbidden) ops->set_parent = scmi_clk_set_parent; + /* Duty cycle */ + if (ci->extended_config) { + ops->get_duty_cycle = scmi_clk_get_duty_cycle; + ops->set_duty_cycle = scmi_clk_set_duty_cycle; + } + return ops; }