From nobody Mon Nov 25 03:48:52 2024 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DC191CEEA3; Wed, 30 Oct 2024 18:57:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730314670; cv=none; b=C2eJb+uF2jVIbA7psGTu9oeiiZ5AGiKi1yVMrXPikSN9p2qVbDcgvzcqo2k3hTgoSqBrEQlUTHP6IQKqOW5HnRq3M+6SOPimbSub4+KzuMnaSfpD/uKKkff8cSsVIatHkWjA9stMQMXKhDxwfyoVdoxhaeK0854E9hpmig2q1sY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730314670; c=relaxed/simple; bh=8W/QDRI/pFgdFr7Ezxc1BasTCKDzA984KK3I+7s0VLA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iQ1zAxVShUkwfI06n5CAzj50vbmNJARCVyk1W+4LAUrayzY6tC5MlK8MOwUDr7CcMoUg3MHb8HNTvqYABs/upDHXkej4Uyn9Z976Y8igHhOeIoU/lDed3Qx7DabAxuIk8T3OjGHL5LL3YgjwTIllXqGQHtulZh3YsRu2PWHy4VE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KKFTrraI; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KKFTrraI" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5c94a7239cfso132384a12.3; Wed, 30 Oct 2024 11:57:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730314667; x=1730919467; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=PdlYOoP7yqq2P4oaMQxpOvCFQMzIToOeYQLgC0CJZyo=; b=KKFTrraI+dV8RCSrc/qLyrxYQWLNJ8aCf0wJaFte+jbCQWyFwY65AKMz+tTYrymU5Z q6HbwcuGryib4AqFplJdd0mjqHiclgOnDrdMMhcCUtxsXo5TmfG4j9fRjzZZQF+mhIe3 xlYuHbmH6EZWLyxshmVtEmE/dQ4oQ5a4cm1A2THeUUJmIgwahhdXcGxiL4SWDkyAfc+f AfceYgIlQjI0Y55RUJwNf/7QmaKSfiJ0eVMWNsKQsujgFtAk8O6w44RUKFegZNp9HZKY kAnP3qKl1lHDa262g8TvzJ3E6k722C2jEQjxpNWL7XSfJGtHpBY2B+VJ+34M5zdWfHqS NzJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730314667; x=1730919467; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PdlYOoP7yqq2P4oaMQxpOvCFQMzIToOeYQLgC0CJZyo=; b=qs1GYQZe0QdszRq8Mqc4v9a9IC8hs6mGzLSJYF8cq67HcwB8raLLlJxN9GFHZt4cuc R1hTkG6Z2N/7/HNtTzMKsKhtGHtQSJtpan8F3thnQrH1xhNAR/MENP5AMJ/T8p1PaYoW /ZsSv3tA2zf3ZagRTp24duTKIpBxuMy/3zP0SOi1+9pdiJACcgqScz/f/aP1/FiX/H3Z lhXrJWA3m/Ihx9ojGMvye6rfC5MVSmTHhLCZetbiarnRmlLz+1B3y8hbeFR3njKmSa1R ZYqT9oCrQ/ubSVNxOwEfQmdVCxJXCN8MdHJ6AzNmjwjajIBHRySeGL0GvFH/ZFruRwBw MGAg== X-Forwarded-Encrypted: i=1; AJvYcCWzhPm5+PhOp4joDRBTLMP+ThVHAxG9MxE8OUohLa48vh97DHFPaJiO8qox6jeOEOBWSvAlSMUPwvOw1iif@vger.kernel.org, AJvYcCXRedQqM8EX8ih+ojkohEWEdLKJ//fKB9NADdZxJSHjjp+4YCOlAKyUk9I4RRqhTbwaY0mhj4mW4eY=@vger.kernel.org X-Gm-Message-State: AOJu0YwuBrGvrReYAN9IQW4q2olSzdCrUP4hM+W0YRnk+A+yt3rYpplk efGkXKAB4byn9IkPDyzmKN8IQpz+09v4ssh4yDTDhfsF/L9ef7KoRgi2Ew== X-Google-Smtp-Source: AGHT+IH+Amb+N98Twp+vREgoZ6+xDRqrsrCdorc3RqQEtxrInbzNmNAzrXM8mztj3QOX/Ubkz1nAEw== X-Received: by 2002:a05:6402:1f8f:b0:5c8:8290:47bf with SMTP id 4fb4d7f45d1cf-5cbbf8dec00mr15327907a12.21.1730314666404; Wed, 30 Oct 2024 11:57:46 -0700 (PDT) Received: from [127.0.1.1] (leased-line-46-53-189-50.telecom.by. [46.53.189.50]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cbb62c20dasm4970447a12.46.2024.10.30.11.57.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 11:57:45 -0700 (PDT) From: Dzmitry Sankouski Date: Wed, 30 Oct 2024 21:57:37 +0300 Subject: [PATCH v8 1/3] clk: qcom: clk-rcg2: document calc_rate function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241030-starqltechn_integration_upstream-v8-1-40f8d5e47062@gmail.com> References: <20241030-starqltechn_integration_upstream-v8-0-40f8d5e47062@gmail.com> In-Reply-To: <20241030-starqltechn_integration_upstream-v8-0-40f8d5e47062@gmail.com> To: Bjorn Andersson , Michael Turquette , Stephen Boyd Cc: linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Dzmitry Sankouski X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1730314661; l=1308; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=8W/QDRI/pFgdFr7Ezxc1BasTCKDzA984KK3I+7s0VLA=; b=T4T5W4sJ8sROTHoLDLU8t05+7vbsg7c+PcrQxk5/Fr1JMPN11PLF26EykR2erfK9uOdv3h4cJ XAlrLE+27gABV95WkSE4jVOXSRLxd7hyYiG/WNCX3NEI3Md+0JjMiu0 X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= Update calc_rate docs to reflect, that pre_div is not pure divisor, but a register value, and requires conversion. Signed-off-by: Dzmitry Sankouski --- Changes in v8: - format kernel-doc - test with scripts/kernel-doc --- drivers/clk/qcom/clk-rcg2.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c index bf26c5448f00..b403e4d6dcdd 100644 --- a/drivers/clk/qcom/clk-rcg2.c +++ b/drivers/clk/qcom/clk-rcg2.c @@ -148,12 +148,21 @@ static int clk_rcg2_set_parent(struct clk_hw *hw, u8 = index) return update_config(rcg); } =20 -/* - * Calculate m/n:d rate +/** + * calc_rate() - Calculate rate based on m/n:d values + * + * @rate: Parent rate. + * @m: Multiplier. + * @n: Divisor. + * @mode: Use zero to ignore m/n calculation. + * @hid_div: Pre divisor register value. Pre divisor value + * relates to hid_div as pre_div =3D (hid_div + 1) / 2. + * + * Return calculated rate according to formula: * * parent_rate m * rate =3D ----------- x --- - * hid_div n + * pre_div n */ static unsigned long calc_rate(unsigned long rate, u32 m, u32 n, u32 mode, u32 hid_div) --=20 2.39.2 From nobody Mon Nov 25 03:48:52 2024 Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FC041D0146; Wed, 30 Oct 2024 18:57:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730314673; cv=none; b=V3pcVIwsdHiyHddS08yDNuAFOQLsz0ZzXLYYlsgicnwgkn0nHtsdxjSDpVULtNA5PnSCQv5f7cXJNloHD6WU98qQNNjjF0LVyWgN9ADZZesx4Ttf44efnjowvH8dXP576BMcjWmOocSQE6YlNaoYIfm4sPBLfbOO4cHAir9BYo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730314673; c=relaxed/simple; bh=QVwTe5vkCgC6ZyHfvLeoIbyNzROGNaBzi2ICIXq0Aks=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MJJzmhHmxmf5vli1LQjX+evsN627mm3/6BiP/jVKy3KM402r5CH6HKPgUzmfysmyTJSCdtAl7XK4BhYd3sWYF8UWPI9ClXcwTwcah3BdjDcXUoL+WzzwXvgjSDvmGqo/CsVPUbP6bPVdwYKJdvMmgXhwxdA6U92vMkyuYR6RztU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NTT0l8Gy; arc=none smtp.client-ip=209.85.208.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NTT0l8Gy" Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2fc968b3545so1024301fa.2; Wed, 30 Oct 2024 11:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730314669; x=1730919469; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=DXcDhqCotDtoxjw1woICtBN+aeyeaVd81N8OWUoUUeY=; b=NTT0l8GyGxIpENBMCV19+iaOzHOw4wDa1q0n/Xg2fZVSspp+ETEpCmbcv/LfXNOrNS sa+dkD11X040kzQcWPjPUubqF7y0Pjy6c0/pTC9fkx+63AYqdB9oqkNzPA44l/w3xvuJ Ut1QgDg3SLFst9VsIP7p1xeCsCCkY2xadfGfKgHtRymqknCjD9b6HQs3yNntuOntQDRT G+ZO9VOq5mk4Xg/DD+EQOR4uyHkknGe/IHsXwfsoJD22gAJ1kvPAvxZuFl3LAE0sC8a1 gn3bfnHuIZr3kAgZUJHgX47V90uydHvlPjnnRm7QQQWB03Z886Ln3sQ8MpnGnmwEHfyO feiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730314669; x=1730919469; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DXcDhqCotDtoxjw1woICtBN+aeyeaVd81N8OWUoUUeY=; b=GI1guVm2I7oeqEJnAa5IC7fWjusa3Ua6OlzxYdx27gcX0XWEPdmemHPBN0MeKNn8qu 75uZhS5yfAKt49zTREtavTGEO9sKwKBsNojwZNVqgOI+pO3AEePZTbuLbCLbTFcAHrOx AO1yZkiPuSSl2oG6gc5vVZwXoUTI6xSKb/dXUFulze1gkZMeGOg+k3/VuWvaY0nGQs7X IBtlLBmiKMBWC1J4tlAKyjuwVNTJnUcDKcKCsvROyrmX+fYVjPEsLXJLonckzHgINAXi JX19FF6zFiUE77oifquLIomTY/DXY95p9j+jgZvVJdFBRVjy3hgViuSN5J38y3E1YG7z 2KoA== X-Forwarded-Encrypted: i=1; AJvYcCVs8FeA+AUGTi8EHELSNtbCxrkYQ1vXZSPW0iCT+P7DPTwKmsgbNctiqVfnh10hRLWLs3oBrq/Xl9A=@vger.kernel.org, AJvYcCWX4FryDHwdBYu5qWWM+iFS1eNduNKYQyvcGdLJvCsvlZhRiDjpqC+CbIECfqcjfkyAlcIo6fIymGp+czYl@vger.kernel.org X-Gm-Message-State: AOJu0YytXsLpyxPVR6HOTw+UTa9agwe0wJl+bSkMbSK5BuVB8N8Eeu1l YBIT9BAIi6zkg59cTJDdGZyT52ZCMd1vAcA1wWg3NEmQnziJvCMXxkGfxg== X-Google-Smtp-Source: AGHT+IFS4HqbvAEyQBccb3B/DQpRzIdhA6YrRE9mqVC1Q0vtfOvmwlN7MPRas/rNh5uVXA+lL/S5/A== X-Received: by 2002:a2e:4619:0:b0:2fb:b59:8167 with SMTP id 38308e7fff4ca-2fdecc2a016mr2710331fa.39.1730314668798; Wed, 30 Oct 2024 11:57:48 -0700 (PDT) Received: from [127.0.1.1] (leased-line-46-53-189-50.telecom.by. [46.53.189.50]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cbb62c20dasm4970447a12.46.2024.10.30.11.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 11:57:47 -0700 (PDT) From: Dzmitry Sankouski Date: Wed, 30 Oct 2024 21:57:38 +0300 Subject: [PATCH v8 2/3] clk: qcom: clk-rcg2: split __clk_rcg2_configure function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241030-starqltechn_integration_upstream-v8-2-40f8d5e47062@gmail.com> References: <20241030-starqltechn_integration_upstream-v8-0-40f8d5e47062@gmail.com> In-Reply-To: <20241030-starqltechn_integration_upstream-v8-0-40f8d5e47062@gmail.com> To: Bjorn Andersson , Michael Turquette , Stephen Boyd Cc: linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Dzmitry Sankouski X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1730314661; l=2751; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=QVwTe5vkCgC6ZyHfvLeoIbyNzROGNaBzi2ICIXq0Aks=; b=3jw5m2WKGbv5GxIj0Es3IcK7dcummTxD9aCszeX1Y8Vw5GUfX/+tYNIGvILQVIFDY+VsuVo+0 6wsRagdd9ejAXWCkotTootxrnGI6RwtrmnTQrI03cbkjunRsvsKpFqx X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= __clk_rcg2_configure function does 2 things - configures parent and mnd values. In order to be able to add new clock options, we should split. Move __clk_rcg2_configure logic on 2 functions: - __clk_rcg2_configure_parent which configures clock parent - __clk_rcg2_configure_mnd which configures mnd values __clk_rcg2_configure delegates to mentioned functions. Signed-off-by: Dzmitry Sankouski --- drivers/clk/qcom/clk-rcg2.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c index b403e4d6dcdd..714ab79e11d6 100644 --- a/drivers/clk/qcom/clk-rcg2.c +++ b/drivers/clk/qcom/clk-rcg2.c @@ -402,16 +402,26 @@ static int clk_rcg2_fm_determine_rate(struct clk_hw *= hw, return _freq_tbl_fm_determine_rate(hw, rcg->freq_multi_tbl, req); } =20 -static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tb= l *f, - u32 *_cfg) +static int __clk_rcg2_configure_parent(struct clk_rcg2 *rcg, u8 src, u32 *= _cfg) { - u32 cfg, mask, d_val, not2d_val, n_minus_m; struct clk_hw *hw =3D &rcg->clkr.hw; - int ret, index =3D qcom_find_src_index(hw, rcg->parent_map, f->src); + int index =3D qcom_find_src_index(hw, rcg->parent_map, src); =20 if (index < 0) return index; =20 + *_cfg &=3D ~CFG_SRC_SEL_MASK; + *_cfg |=3D rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT; + + return 0; +} + +static int __clk_rcg2_configure_mnd(struct clk_rcg2 *rcg, const struct fre= q_tbl *f, + u32 *_cfg) +{ + u32 cfg, mask, d_val, not2d_val, n_minus_m; + int ret; + if (rcg->mnd_width && f->n) { mask =3D BIT(rcg->mnd_width) - 1; ret =3D regmap_update_bits(rcg->clkr.regmap, @@ -440,9 +450,8 @@ static int __clk_rcg2_configure(struct clk_rcg2 *rcg, c= onst struct freq_tbl *f, } =20 mask =3D BIT(rcg->hid_width) - 1; - mask |=3D CFG_SRC_SEL_MASK | CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK; + mask |=3D CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK; cfg =3D f->pre_div << CFG_SRC_DIV_SHIFT; - cfg |=3D rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT; if (rcg->mnd_width && f->n && (f->m !=3D f->n)) cfg |=3D CFG_MODE_DUAL_EDGE; if (rcg->hw_clk_ctrl) @@ -454,6 +463,22 @@ static int __clk_rcg2_configure(struct clk_rcg2 *rcg, = const struct freq_tbl *f, return 0; } =20 +static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tb= l *f, + u32 *_cfg) +{ + int ret; + + ret =3D __clk_rcg2_configure_parent(rcg, f->src, _cfg); + if (ret) + return ret; + + ret =3D __clk_rcg2_configure_mnd(rcg, f, _cfg); + if (ret) + return ret; + + return 0; +} + static int clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl = *f) { u32 cfg; --=20 2.39.2 From nobody Mon Nov 25 03:48:52 2024 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F19341D0967; Wed, 30 Oct 2024 18:57:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730314675; cv=none; b=fUhkA/PNLphGyx9l/724AVJC3yb82k+hlE42WQsqUhSqQsuTssSU8SfGaon2yThXVi6W0J5WjY3waDarJwU2IN9TeUD3XE4uHdpZlddhfWN9MdeUEetZtcqLKe8Bhfdw3H5frU7dxCTQQYs+1gD+i+GcoSxlyb2lCnEdW+/RarI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730314675; c=relaxed/simple; bh=TH30VyqA7OU9YqATMjryFauBN4pQYazeqI+zTeF8qaU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dC/1mLx8YIKJutgX4NkEZeDfo+zi6WljeXk+B8aOWVoA9qgzfqs0nCjjckzt6dI2Y+/C7G4rqUXwz6LVWfVQpPo6k5liwhES3vYKSp9TJsqAORRhrlLryPzq8MErA7e8HxZShWCEsXu8N6shxV9SrbkTQldt52nhYcixUhYMabE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MkJUbm6n; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MkJUbm6n" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5c941623a5aso2262302a12.0; Wed, 30 Oct 2024 11:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730314671; x=1730919471; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=YdKa5z3twiIQe8AUFC1Fbj5IBy2mDQVy5MB2Z28mCTw=; b=MkJUbm6nMw2w8qixQ4g1xgRsLDm6s+ng2aFXItWJrHiXO5vEolMXn7gFPUEMqemsD2 9QnS5teEy0RbGRMtmR+P7AIpxpaO+VhgJ9FCFxX3yQUwNUXv+hOxvFGz18hmwTS1DPlR mOSSqca3VfyKEHrsLdiiy01FtLPWKNH6H2z4qJlWusZCfd3sj/f+U5tYjsrVX2qvM2vF mT/ZW7at+rnFSW2gzUkr8amDgbHt6lin5mEL4Xwk9knWw7UK4YwE9tS2Bsy/buIq1mq+ IvUZLmwUw1S1saZMYAfLi/7yH6jnISNKT6Fez3yGWd9thSZ2dtz+A0fD6EH0TklA4qaQ kE9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730314671; x=1730919471; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YdKa5z3twiIQe8AUFC1Fbj5IBy2mDQVy5MB2Z28mCTw=; b=VQSsyl0Qhv9yuKUdvDLjDQKNoc4QwOhd3IZ1fLOFTLqlu/+KWEcEuTMaoIkPgcxjOX ZPo5YQKmbQVOoEqUlg+kQXNFKudLbyDAyFAnPPpD6Q32BcbWNQrSGLI2yfqadlxmz9UW vWr0vHh+0ajPHwEZkT8s9S7y7TYI2af6agU4X61MNVALowKPei+orDjoqL/mkj5pfKBp uFuFJn422IWbePG2UMhFaRbTSXABLfllO9ZJPUCTi+d4nk8/RhcRS4xdZa1O4+xnZFtV Fp6yiw+J6iDNloN/PJ+Kpo4+6UwtZ8L4beZnjqla06vwnToRs6uc9XLvZafCyHBe4TfO AXdg== X-Forwarded-Encrypted: i=1; AJvYcCUx0hVODwWrVN+XmvYMy1pyc4TUjSwtDz4mfR+ecfgsB35ngGyP/yWDNtdX1xCBU767QIqi4e/K6KmjyMyW@vger.kernel.org, AJvYcCVBthQEp4la/m6VWfBfJk5TSOGdfSoG0PJQyxQ9wKk6i9M28ahhY2pcZYbzNLjY9YJL3uTvCHn0XZ4=@vger.kernel.org X-Gm-Message-State: AOJu0YxoUExvZy1Ou7ng14VB7XVloC1teMPR668n3n8NGfrZNWlXTMoY vwMQs2+Ki4yeN+Ah8UvdvUsBcawkMlU27ZfhrZ1dZVpnftd4CY6OUB875g== X-Google-Smtp-Source: AGHT+IEzJVd1GXFUme12ZMJyOhBQig42aLyDkpnyudUaJ4JMJR57bxj/nxnfhL5Si6cnFrkkONsAHg== X-Received: by 2002:a05:6402:50cb:b0:5cb:991d:c51e with SMTP id 4fb4d7f45d1cf-5cd2e35309cmr6145619a12.15.1730314670588; Wed, 30 Oct 2024 11:57:50 -0700 (PDT) Received: from [127.0.1.1] (leased-line-46-53-189-50.telecom.by. [46.53.189.50]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5cbb62c20dasm4970447a12.46.2024.10.30.11.57.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 11:57:50 -0700 (PDT) From: Dzmitry Sankouski Date: Wed, 30 Oct 2024 21:57:39 +0300 Subject: [PATCH v8 3/3] gcc-sdm845: Add general purpose clock ops Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241030-starqltechn_integration_upstream-v8-3-40f8d5e47062@gmail.com> References: <20241030-starqltechn_integration_upstream-v8-0-40f8d5e47062@gmail.com> In-Reply-To: <20241030-starqltechn_integration_upstream-v8-0-40f8d5e47062@gmail.com> To: Bjorn Andersson , Michael Turquette , Stephen Boyd Cc: linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Dzmitry Sankouski X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1730314661; l=9804; i=dsankouski@gmail.com; s=20240619; h=from:subject:message-id; bh=TH30VyqA7OU9YqATMjryFauBN4pQYazeqI+zTeF8qaU=; b=ieSG9DH0e1S1luDrgXGgIInFruF5WdeyD/fjiisyCX4LS3BZbpMS/v36t7aZNMvpZbnpr06Zo VUqnE8kb7S0AB5KRbN8Yexy1Mf2PVpVMvbj7k8hfbI/4m8uSSLTgXgp X-Developer-Key: i=dsankouski@gmail.com; a=ed25519; pk=YJcXFcN1EWrzBYuiE2yi5Mn6WLn6L1H71J+f7X8fMag= SDM845 has "General Purpose" clocks that can be muxed to SoC pins to clock various external devices. Those clocks may be used as e.g. PWM sources for external peripherals. GPCLK can in theory have arbitrary value depending on the use case, so the concept of frequency tables, used in rcg2 clock driver, is not efficient, because it allows only defined frequencies. Introduce clk_rcg2_gp_ops, which automatically calculate clock mnd values for arbitrary clock rate. The calculation done as follows: - upon determine rate request, we calculate m/n/pre_div as follows: - find parent(from our client's assigned-clock-parent) rate - find scaled rates by dividing rates on its greatest common divisor - assign requested scaled rate to m - factorize scaled parent rate, put multipliers to n till max value (determined by mnd_width) - validate calculated values with *_width: - if doesn't fit, delete divisor and multiplier by 2 until fit - return determined rate Limitations: - The driver doesn't select a parent clock (it may be selected by client in device tree with assigned-clocks, assigned-clock-parents properties) Signed-off-by: Dzmitry Sankouski --- Changes in v8: - format kernel-doc - test with scripts/kernel-doc Changes in v7: - split patch on gp and non gp changes - use /**/ comment for kernel doc - clk_rcg2_determine_gp_rate: put freq_tbl to the stack - clk_rcg2_calc_mnd: if impossible to lower scale, return after setting max divisors values Changes in v6: - remove unused count variable - run sparse and smatch Changes in v5: - replace '/' to div64_u64 to fix 32 bit gcc error - fix empty scalar initializer --- drivers/clk/qcom/clk-rcg.h | 1 + drivers/clk/qcom/clk-rcg2.c | 146 ++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++ drivers/clk/qcom/gcc-sdm845.c | 11 +++-------- 3 files changed, 150 insertions(+), 8 deletions(-) diff --git a/drivers/clk/qcom/clk-rcg.h b/drivers/clk/qcom/clk-rcg.h index 8e0f3372dc7a..8817d14bbda4 100644 --- a/drivers/clk/qcom/clk-rcg.h +++ b/drivers/clk/qcom/clk-rcg.h @@ -189,6 +189,7 @@ struct clk_rcg2_gfx3d { container_of(to_clk_rcg2(_hw), struct clk_rcg2_gfx3d, rcg) =20 extern const struct clk_ops clk_rcg2_ops; +extern const struct clk_ops clk_rcg2_gp_ops; extern const struct clk_ops clk_rcg2_floor_ops; extern const struct clk_ops clk_rcg2_fm_ops; extern const struct clk_ops clk_rcg2_mux_closest_ops; diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c index 714ab79e11d6..75617cc8f0c4 100644 --- a/drivers/clk/qcom/clk-rcg2.c +++ b/drivers/clk/qcom/clk-rcg2.c @@ -8,11 +8,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include =20 @@ -32,6 +34,7 @@ =20 #define CFG_REG 0x4 #define CFG_SRC_DIV_SHIFT 0 +#define CFG_SRC_DIV_LENGTH 8 #define CFG_SRC_SEL_SHIFT 8 #define CFG_SRC_SEL_MASK (0x7 << CFG_SRC_SEL_SHIFT) #define CFG_MODE_SHIFT 12 @@ -148,6 +151,17 @@ static int clk_rcg2_set_parent(struct clk_hw *hw, u8 i= ndex) return update_config(rcg); } =20 +/** + * convert_to_reg_val() - Convert divisor values to hardware values. + * + * @f: Frequency table with pure m/n/pre_div parameters. + */ +static void convert_to_reg_val(struct freq_tbl *f) +{ + f->pre_div *=3D 2; + f->pre_div -=3D 1; +} + /** * calc_rate() - Calculate rate based on m/n:d values * @@ -402,6 +416,90 @@ static int clk_rcg2_fm_determine_rate(struct clk_hw *h= w, return _freq_tbl_fm_determine_rate(hw, rcg->freq_multi_tbl, req); } =20 +/** + * clk_rcg2_split_div() - Split multiplier that doesn't fit in n neither i= n pre_div. + * + * @multiplier: Multiplier to split between n and pre_div. + * @pre_div: Pointer to pre divisor value. + * @n: Pointer to n divisor value. + * @pre_div_max: Pre divisor maximum value. + */ +static inline void clk_rcg2_split_div(int multiplier, unsigned int *pre_di= v, + u16 *n, unsigned int pre_div_max) +{ + *n =3D mult_frac(multiplier * *n, *pre_div, pre_div_max); + *pre_div =3D pre_div_max; +} + +static void clk_rcg2_calc_mnd(u64 parent_rate, u64 rate, struct freq_tbl *= f, + unsigned int mnd_max, unsigned int pre_div_max) +{ + int i =3D 2; + unsigned int pre_div =3D 1; + unsigned long rates_gcd, scaled_parent_rate; + u16 m, n =3D 1, n_candidate =3D 1, n_max; + + rates_gcd =3D gcd(parent_rate, rate); + m =3D div64_u64(rate, rates_gcd); + scaled_parent_rate =3D div64_u64(parent_rate, rates_gcd); + while (scaled_parent_rate > (mnd_max + m) * pre_div_max) { + // we're exceeding divisor's range, trying lower scale. + if (m > 1) { + m--; + scaled_parent_rate =3D mult_frac(scaled_parent_rate, m, (m + 1)); + } else { + // cannot lower scale, just set max divisor values. + f->n =3D mnd_max + m; + f->pre_div =3D pre_div_max; + f->m =3D m; + return; + } + } + + n_max =3D m + mnd_max; + + while (scaled_parent_rate > 1) { + while (scaled_parent_rate % i =3D=3D 0) { + n_candidate *=3D i; + if (n_candidate < n_max) + n =3D n_candidate; + else if (pre_div * i < pre_div_max) + pre_div *=3D i; + else + clk_rcg2_split_div(i, &pre_div, &n, pre_div_max); + + scaled_parent_rate /=3D i; + } + i++; + } + + f->m =3D m; + f->n =3D n; + f->pre_div =3D pre_div > 1 ? pre_div : 0; +} + +static int clk_rcg2_determine_gp_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + struct clk_rcg2 *rcg =3D to_clk_rcg2(hw); + struct freq_tbl f_tbl =3D {}, *f =3D &f_tbl; + int mnd_max =3D BIT(rcg->mnd_width) - 1; + int hid_max =3D BIT(rcg->hid_width) - 1; + struct clk_hw *parent; + u64 parent_rate; + + parent =3D clk_hw_get_parent(hw); + parent_rate =3D clk_get_rate(parent->clk); + if (!parent_rate) + return -EINVAL; + + clk_rcg2_calc_mnd(parent_rate, req->rate, f, mnd_max, hid_max / 2); + convert_to_reg_val(f); + req->rate =3D calc_rate(parent_rate, f->m, f->n, f->n, f->pre_div); + + return 0; +} + static int __clk_rcg2_configure_parent(struct clk_rcg2 *rcg, u8 src, u32 *= _cfg) { struct clk_hw *hw =3D &rcg->clkr.hw; @@ -499,6 +597,26 @@ static int clk_rcg2_configure(struct clk_rcg2 *rcg, co= nst struct freq_tbl *f) return update_config(rcg); } =20 +static int clk_rcg2_configure_gp(struct clk_rcg2 *rcg, const struct freq_t= bl *f) +{ + u32 cfg; + int ret; + + ret =3D regmap_read(rcg->clkr.regmap, RCG_CFG_OFFSET(rcg), &cfg); + if (ret) + return ret; + + ret =3D __clk_rcg2_configure_mnd(rcg, f, &cfg); + if (ret) + return ret; + + ret =3D regmap_write(rcg->clkr.regmap, RCG_CFG_OFFSET(rcg), cfg); + if (ret) + return ret; + + return update_config(rcg); +} + static int __clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate, enum freq_policy policy) { @@ -552,6 +670,22 @@ static int clk_rcg2_set_rate(struct clk_hw *hw, unsign= ed long rate, return __clk_rcg2_set_rate(hw, rate, CEIL); } =20 +static int clk_rcg2_set_gp_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct clk_rcg2 *rcg =3D to_clk_rcg2(hw); + int mnd_max =3D BIT(rcg->mnd_width) - 1; + int hid_max =3D BIT(rcg->hid_width) - 1; + struct freq_tbl f_tbl =3D {}, *f =3D &f_tbl; + int ret; + + clk_rcg2_calc_mnd(parent_rate, rate, f, mnd_max, hid_max / 2); + convert_to_reg_val(f); + ret =3D clk_rcg2_configure_gp(rcg, f); + + return ret; +} + static int clk_rcg2_set_floor_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { @@ -679,6 +813,18 @@ const struct clk_ops clk_rcg2_ops =3D { }; EXPORT_SYMBOL_GPL(clk_rcg2_ops); =20 +const struct clk_ops clk_rcg2_gp_ops =3D { + .is_enabled =3D clk_rcg2_is_enabled, + .get_parent =3D clk_rcg2_get_parent, + .set_parent =3D clk_rcg2_set_parent, + .recalc_rate =3D clk_rcg2_recalc_rate, + .determine_rate =3D clk_rcg2_determine_gp_rate, + .set_rate =3D clk_rcg2_set_gp_rate, + .get_duty_cycle =3D clk_rcg2_get_duty_cycle, + .set_duty_cycle =3D clk_rcg2_set_duty_cycle, +}; +EXPORT_SYMBOL_GPL(clk_rcg2_gp_ops); + const struct clk_ops clk_rcg2_floor_ops =3D { .is_enabled =3D clk_rcg2_is_enabled, .get_parent =3D clk_rcg2_get_parent, diff --git a/drivers/clk/qcom/gcc-sdm845.c b/drivers/clk/qcom/gcc-sdm845.c index dc3aa7014c3e..0def0fc0e009 100644 --- a/drivers/clk/qcom/gcc-sdm845.c +++ b/drivers/clk/qcom/gcc-sdm845.c @@ -284,11 +284,6 @@ static struct clk_rcg2 gcc_sdm670_cpuss_rbcpr_clk_src = =3D { }; =20 static const struct freq_tbl ftbl_gcc_gp1_clk_src[] =3D { - F(19200000, P_BI_TCXO, 1, 0, 0), - F(25000000, P_GPLL0_OUT_EVEN, 12, 0, 0), - F(50000000, P_GPLL0_OUT_EVEN, 6, 0, 0), - F(100000000, P_GPLL0_OUT_MAIN, 6, 0, 0), - F(200000000, P_GPLL0_OUT_MAIN, 3, 0, 0), { } }; =20 @@ -302,7 +297,7 @@ static struct clk_rcg2 gcc_gp1_clk_src =3D { .name =3D "gcc_gp1_clk_src", .parent_data =3D gcc_parent_data_1, .num_parents =3D ARRAY_SIZE(gcc_parent_data_1), - .ops =3D &clk_rcg2_ops, + .ops =3D &clk_rcg2_gp_ops, }, }; =20 @@ -316,7 +311,7 @@ static struct clk_rcg2 gcc_gp2_clk_src =3D { .name =3D "gcc_gp2_clk_src", .parent_data =3D gcc_parent_data_1, .num_parents =3D ARRAY_SIZE(gcc_parent_data_1), - .ops =3D &clk_rcg2_ops, + .ops =3D &clk_rcg2_gp_ops, }, }; =20 @@ -330,7 +325,7 @@ static struct clk_rcg2 gcc_gp3_clk_src =3D { .name =3D "gcc_gp3_clk_src", .parent_data =3D gcc_parent_data_1, .num_parents =3D ARRAY_SIZE(gcc_parent_data_1), - .ops =3D &clk_rcg2_ops, + .ops =3D &clk_rcg2_gp_ops, }, }; =20 --=20 2.39.2