From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 05437C00140 for ; Mon, 15 Aug 2022 15:34:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7tIcg6MwlGRkLC0aAaJifGj7oeZ2opgyr/jjD2LUyr8=; b=fpaJ5QhrjyTilh Jz8oQcvnrK04myzb9LblCmkVl6GAQ12ZSME/E+OePi90bQFlz/tZ8/hjYv618cuKR+q70AbT4XXLT KGBTVY0oMbZEn2BJsBbZCglWJKLbKsI3QZAeN7KpQUV7Tul4NWhxFNocUHFu1oYw3T3TmAqzcdGR+ MhQu8LJVUhCcKwcZHcaydjwUU3lTkkTNqouFnlQY/XAXe8djj9F/pcVDtJ5THwxDEcRudWaBNIO0E 7CvIUxhiXBG+3QhJQtl8wKTKd3VEvBShPrlkIE/IxbKjfj2VI/LkciordZSCFBIuDMiIqp5f99SU5 SCzsUpSzRASeBp5/Gqlw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNc5I-000ubs-Ju; Mon, 15 Aug 2022 15:32:58 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNc4B-000tue-S4; Mon, 15 Aug 2022 15:31:49 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 63C043200657; Mon, 15 Aug 2022 11:31:45 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 15 Aug 2022 11:31:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1660577504; x= 1660663904; bh=zDlYuKttoMMva0k5dTZ+8Vb+jrME1/H4pvpISkPn7Lg=; b=R 7FVtnuK3s2G9UnAjv4Tvy1spq9QYCS+kDbNeymJ9SM4ICGUfu57OJqOJZOur65DG fowYJhI+NffD+F07ktE3h9Z4mTFJb0aH6Y646y0zZ2hNKubL/D04X7YlN/tJcBLM iykLuLavlKa3m5VQS9EeFr0TCvsqSfoPj0zTckws91Ku5zY9S+s4gAIiFpgMcVl9 ss4v/GxcX91tVhlqSjD7jofz70opEeCKlURojelEF7FFz/TlVbnvUZXsGzIUSKAd Umco9tcz5GqXpGkDSks6MnfBPGmUR7nL4MVmdW7KwOTsoVr+76kSHy5RLFTYzFKo 8WVdVb7Y+khT4mVysGjkw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1660577504; x= 1660663904; bh=zDlYuKttoMMva0k5dTZ+8Vb+jrME1/H4pvpISkPn7Lg=; b=5 j+uTraAsefqk6eSBj8rukf/1tDHJ29C0JR7+1o+zJiwU/JO41wRaSRiGye7xzVzN zEVuZD46kXLgpHfd/gSFGeKE63DyAqYr1vkcpHQpG43Sgy9TIKN05if+tdNdFRRM 08XKkTvfDEH5NrCCous39MgsVdpZNkcr1RgTdsiH0ilUuPl+vTfWaVdZ83H9ujpP 3wwCvpATmBqhlVhuzsN9Wo2Mey7O83119WQqgln6ASR0rAkDavgHrU4NUEcR1XHV phtokOuru4ztF+7gw+Mypuc6c+C/MFbcp3HMzsShp7AEoCB2WJOmKMfY2c8MGwRe xHDWhpdGcjN4JZDYQsLZA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdehvddgledtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhggtgfogfesthekredtredtjeenucfhrhhomhepofgr gihimhgvucftihhprghrugcuoehmrgigihhmvgestggvrhhnohdrthgvtghhqeenucggtf frrghtthgvrhhnpefgfffgteffuddulefhveeiffffudelvefggeekueetgfffjeehleel keejfefhjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehmrgigihhmvgestggvrhhnohdrthgvtghh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 15 Aug 2022 11:31:43 -0400 (EDT) From: Maxime Ripard To: Michael Turquette , Ray Jui , Broadcom internal kernel review list , Florian Fainelli , David Airlie , Daniel Vetter , Stephen Boyd , Scott Branden , Maxime Ripard , Emma Anholt Cc: Maxime Ripard , linux-arm-kernel@lists.infradead.org, linux-rpi-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org, Dom Cobley , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/7] clk: bcm: rpi: Add a function to retrieve the maximum Date: Mon, 15 Aug 2022 17:31:24 +0200 Message-Id: <20220815-rpi-fix-4k-60-v1-2-c52bd642f7c6@cerno.tech> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220815-rpi-fix-4k-60-v1-0-c52bd642f7c6@cerno.tech> References: <20220815-rpi-fix-4k-60-v1-0-c52bd642f7c6@cerno.tech> MIME-Version: 1.0 X-Mailer: b4 0.10.0-dev-a76f5 X-Developer-Signature: v=1; a=openpgp-sha256; l=3364; i=maxime@cerno.tech; h=from:subject:message-id; bh=wAQVJMgLbRnifaGUTCUy+ZporTuJb2HjcXq358WgEfw=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDEm/0k7k61kV2XhfO/8gQ3a536KV+bJHJz7kVePKS7D+65rp vnRjRykLgxgXg6yYIkuMsPmSuFOzXney8c2DmcPKBDKEgYtTACZSa8nwT3+X3d6Zs7ROP5R9FyL55V S78UeNhIDPbod21As5/7y0eQrDP3tL2XNdthnvfvzqbnsgqinNciNZLOZGStfU/5sTJzTrsQEA X-Developer-Key: i=maxime@cerno.tech; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220815_083148_077335_9561D0AD X-CRM114-Status: GOOD ( 20.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The RaspberryPi firmware can be configured by the end user using the config.txt file. Some of these options will affect the kernel capabilities, and we thus need to be able to detect it to operate reliably. One of such parameters is the hdmi_enable_4kp60 parameter that will setup the clocks in a way that is suitable to reach the pixel frequencies required by the 4k at 60Hz and higher modes. If the user forgot to enable it, then those modes will simply not work but are still likely to be picked up by the userspace, which is a poor user-experience. The kernel can't access the config.txt file directly, but one of the effect that parameter has is that the core clock frequency maximum will be much higher. Thus we can infer whether it was enabled or not by querying the firmware for that maximum, and if it isn't prevent any of the modes that wouldn't work. The HDMI driver is already doing this, but was relying on a behaviour of clk_round_rate() that got changed recently, and doesn't return the result we would like anymore. We also considered introducing a CCF function to access the maximum of a given struct clk, but that wouldn't work if the clock is further constrained by another user. It was thus suggested to create a small, ad-hoc function to query the RaspberryPi firmware for the maximum rate a given clock has. Suggested-by: Stephen Boyd Signed-off-by: Maxime Ripard diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c index 6c0a0fd6cd79..182e8817eac2 100644 --- a/drivers/clk/bcm/clk-raspberrypi.c +++ b/drivers/clk/bcm/clk-raspberrypi.c @@ -16,6 +16,7 @@ #include #include +#include #include enum rpi_firmware_clk_id { @@ -254,6 +255,33 @@ static int raspberrypi_fw_dumb_determine_rate(struct clk_hw *hw, return 0; } +unsigned long rpi_firmware_clk_get_max_rate(struct clk *clk) +{ + const struct raspberrypi_clk_data *data; + struct raspberrypi_clk *rpi; + struct clk_hw *hw; + u32 max_rate; + int ret; + + if (!clk) + return 0; + + hw = __clk_get_hw(clk); + if (!hw) + return 0; + + data = clk_hw_to_data(hw); + rpi = data->rpi; + ret = raspberrypi_clock_property(rpi->firmware, data, + RPI_FIRMWARE_GET_MAX_CLOCK_RATE, + &max_rate); + if (ret) + return 0; + + return max_rate; +} +EXPORT_SYMBOL_GPL(rpi_firmware_clk_get_max_rate); + static const struct clk_ops raspberrypi_firmware_clk_ops = { .is_prepared = raspberrypi_fw_is_prepared, .recalc_rate = raspberrypi_fw_get_rate, diff --git a/include/soc/bcm2835/raspberrypi-clocks.h b/include/soc/bcm2835/raspberrypi-clocks.h new file mode 100644 index 000000000000..ff0b608b51a8 --- /dev/null +++ b/include/soc/bcm2835/raspberrypi-clocks.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __SOC_RASPBERRY_CLOCKS_H__ +#define __SOC_RASPBERRY_CLOCKS_H__ + +#if IS_ENABLED(CONFIG_CLK_RASPBERRYPI) +unsigned long rpi_firmware_clk_get_max_rate(struct clk *clk); +#else +static inline unsigned long rpi_firmware_clk_get_max_rate(struct clk *clk) +{ + return ULONG_MAX; +} +#endif + +#endif /* __SOC_RASPBERRY_CLOCKS_H__ */ -- b4 0.10.0-dev-a76f5 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel