Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2944817lqp; Mon, 25 Mar 2024 14:02:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUaTEuBYJobWw/shesy24LN3lyVH/18Nrn9XrX24TaF4zVxJxTIZLOSWgRdppoImzKkgoVJxDXT7LNW1Gk8cYuCj1dc4xWmRkd/PgArtw== X-Google-Smtp-Source: AGHT+IGV7pzXQiAoGvUl4l6dNduv40sUNkaAc7UgZptVx/giNhPMHAxEUYXKKzamCK38c/sMBKor X-Received: by 2002:a05:6a00:2347:b0:6e6:9560:f113 with SMTP id j7-20020a056a00234700b006e69560f113mr8877213pfj.3.1711400551443; Mon, 25 Mar 2024 14:02:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711400551; cv=pass; d=google.com; s=arc-20160816; b=QrqqRbggocnay8vWIfx35SkD+1JiH5cGqZt/UGTZVa4n0QEECflWHM23EAc8uKLE06 5YHD/CB7F3jgYU+gRe2uyg4CeGx9Z556mHgG17zYO2T3USKq/5AYqdAc0hTFbFDhJlOh YhHXhFE50k9LgL+bWLf0jUmHGdEw5wSTTRVzJejr/zGgM6h7/FEB+GvqBQOupNsuUVzK 4POpwEXpDh7ZtV+AjIFGUvnjgJCa06wbni1AQWJr1B7brfhqPQbSDYiZCtUaS+7EX1F7 QZ6snAp0uKNuksZsgsAUBBjE/kvV1fmWxPRsfZIlbQPbWdI9gZGjkRq0ETHQF5Jrrv2Q cKAg== 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=OX/AXgBEcMR88MNm4mKoDG4GeSLl0A+qTE6l/p2Nb4M=; fh=mWEa8kD57fMXkUdPHBEJD6cIWPe6iYGLhbK4K2UH3fw=; b=He3d+FpGSNjyxBAnqGiLkfNzWrO7E07RxT2l4NE03Pyl/PMonZQ2IF5ajnim4R32yx Vjbcu7NlTM2gWXtUanuBH9bB3FjpwI0cQ2dIMa7Atrew8XitQC3KJ//AZLF4f/ejbSyv TqP7Rzxr8aIxKkpXKU9x7OqganpqAN77UKVa3Iy0rKduN7i9pTlEGx2bW4ct7YPBFr0r uii7WH+fXUZK1mRU5kWzKEzbZBQChFxIlcpJPxRnGHmcFKXLcWhNsRFABOy0MDV0zLcf 5pkvur2/tLNWXiw0coS5fP4tMD9ZuMgQBqYzu3oF5EplYpf6X6IU4TeBlO+q7PbLOfgC UgUw==; 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-118004-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118004-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id lm7-20020a056a003c8700b006e7a2f9a89dsi491230pfb.381.2024.03.25.14.02.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 14:02:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-118004-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-118004-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118004-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1E3682E2E15 for ; Mon, 25 Mar 2024 21:02:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC86A5C612; Mon, 25 Mar 2024 21:01:02 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DEFFC71732; Mon, 25 Mar 2024 21:01:00 +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=1711400462; cv=none; b=YvWdkIaN83GL3jLu5Yqk9S2Zw2rmhoH8iTGrAu1T9YamB5VRJd9gSbNQ2sIPP4hVA1lw3cWtDtWmmqaIhF7fm+3dBNbH4ZDVaqgGotRTzfhMXR9ipjeovqVwDv+E3Bmxx8hUWc0NdtT3/tYhILKF+SdLI7Y7l/odxc/G6rhDu9U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711400462; c=relaxed/simple; bh=Kh7/2pNWHN+bMKCPsHFaHNTHCq1l8WYfgz9x9QJkawU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y35Tnfp15D/R7VrQx+VgUhUSf1WX3DlTzMlskqNizi+5IOtyuDxiFNBJTjz0/772ec0ZfsWmNYxPz61jLzGScHjZ56TFimDEiLfgV9zkixYOOmWkT2rT0kfec5uZ7c37jDH/yhGbvwVJX3yNb/c1jEImxY8XQLWNLKko+CbXPQw= 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 E35EC2F4; Mon, 25 Mar 2024 14:01:33 -0700 (PDT) Received: from pluto.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 496C23F694; Mon, 25 Mar 2024 14:00:58 -0700 (PDT) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.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, mturquette@baylibre.com, sboyd@kernel.org, Cristian Marussi Subject: [PATCH v2 5/5] clk: scmi: Add support for get/set duty_cycle operations Date: Mon, 25 Mar 2024 21:00:25 +0000 Message-ID: <20240325210025.1448717-6-cristian.marussi@arm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240325210025.1448717-1-cristian.marussi@arm.com> References: <20240325210025.1448717-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 Content-Transfer-Encoding: 8bit Provide the CLK framework callbacks related to get/set clock duty cycle if the related SCMI clock supports OEM extended configurations. CC: Michael Turquette CC: Stephen Boyd CC: linux-clk@vger.kernel.org Signed-off-by: Cristian Marussi --- drivers/clk/clk-scmi.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/clk/clk-scmi.c b/drivers/clk/clk-scmi.c index 87e968b6c095..86ef7c553ddd 100644 --- a/drivers/clk/clk-scmi.c +++ b/drivers/clk/clk-scmi.c @@ -21,6 +21,7 @@ enum scmi_clk_feats { SCMI_CLK_STATE_CTRL_FORBIDDEN, SCMI_CLK_RATE_CTRL_FORBIDDEN, SCMI_CLK_PARENT_CTRL_FORBIDDEN, + SCMI_CLK_DUTY_CYCLE_SUPPORTED, SCMI_CLK_MAX_FEATS }; @@ -169,6 +170,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) { @@ -258,6 +298,12 @@ scmi_clk_ops_alloc(struct device *dev, unsigned long feats_key) if (!(feats_key & BIT(SCMI_CLK_PARENT_CTRL_FORBIDDEN))) ops->set_parent = scmi_clk_set_parent; + /* Duty cycle */ + if (feats_key & BIT(SCMI_CLK_DUTY_CYCLE_SUPPORTED)) { + ops->get_duty_cycle = scmi_clk_get_duty_cycle; + ops->set_duty_cycle = scmi_clk_set_duty_cycle; + } + return ops; } @@ -306,6 +352,9 @@ scmi_clk_ops_select(struct scmi_clk *sclk, bool atomic_capable, if (ci->parent_ctrl_forbidden) feats_key |= BIT(SCMI_CLK_PARENT_CTRL_FORBIDDEN); + if (ci->extended_config) + feats_key |= BIT(SCMI_CLK_DUTY_CYCLE_SUPPORTED); + /* Lookup previously allocated ops */ ops = clk_ops_db[feats_key]; if (!ops) { -- 2.44.0