From patchwork Thu Oct 13 09:13:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13005779 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 9B3BCC4332F for ; Thu, 13 Oct 2022 09:14:49 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=N5/fuaN8Yd30hXRymnWFebGUI+C/RnE04dELlVqaLJ0=; b=b1fBvW2PHBOjs4 6qrcnLQ6yQYtWxapyaZalhUEdAKljBRmuZxtK2MPBpwboioPbHhC0CrBUGC167ycpVS/vZJhu5QG5 Gt4u1Nfomi8AXJi+CQIsRvDw+Zj4XcR0+KUhz+H3PMHNuE1geX9FARLCP2rAUGm2C2opkOoN3T3PX APDLSSLt0fIwaQiZJlFc3U+3BbgNqipFMCFro3Ft37/mTLdatN8iAK1mnL3MmUhYqrzOiYoiM/huh e/qhOH6gJdO0LRcvmmaY88RMXlC34UyGZzdZd7WUr+3uq3Cc5QjwfRKsJlwYlXDxGSnasy36gmHwu iei6X3jZWsEZFiI50vPA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oiuHi-00BEYt-4s; Thu, 13 Oct 2022 09:13:46 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oiuHG-00BEPT-DG; Thu, 13 Oct 2022 09:13:19 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id C860C5C00D5; Thu, 13 Oct 2022 05:13:17 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 13 Oct 2022 05:13:17 -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=1665652397; x= 1665738797; bh=NbLfsfDu1Gtr2c9qmTrYb//pcpOFa59Pn2YWUwdR2PQ=; b=v btCpBwB/dRvHJNh0uI58CDkNB68elf0mXaDTcTgRndoUTf0zCIQeMDtwFrxM8um+ XwJWnEdsiC5nq5CzPoHkfY6TVE8y1h0mPbCrY7V+JuH9vFurD0A2K4nzhVt0+vhX waJUsEwzIlRyZVFXyDSTAIcy/3ONewTOagiq8L5ynmvLk3mrTZwlM/eMs7Ah1zSn DJxT7L0b2znlVIRcOmwkOHcmIhwKgWOWo3OZgSL61Q4qMb2qdKmLb8IAE3axLnR6 Q73dP2H2CZsXliafRb+KFYNDx6NQhifboMeKC6Ium3JJ6hltyb8kOIb5wdkSO7KQ imrfWCd8dfcMwFEuvFhSg== 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=fm3; t=1665652397; x= 1665738797; bh=NbLfsfDu1Gtr2c9qmTrYb//pcpOFa59Pn2YWUwdR2PQ=; b=T PWfBqKrIsFE6oum+0YE5rNlNG508+cLK1ooGcDBMdHx7E5NZZmRoYErukFlsi4QP 3xgi1gKoZJR0hcplg0V7HkFSwer8XCiQuMVZjvRw1r5sd3cLExrbQgYoZ9K37y4+ leWarvxWLgtofU0W0xmwzH04Oz+XzjsVgjrASb1R10pVCMwUtsDCoh7IzjYfKpoP H+tBLQjw91xozW5dm01eheXGZtvzVdMORMByvGGi75gECCdgwL2WcNFGPAwXv7pF 1Tqa0ZXQLRqotmapTogf0Xosi7AA8qjAZkvdrTJTOQ+oLoWcu08IuvcQDFsNBEex 4jhJ+o9VfPdbUbG5cjyeA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeektddgudegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephfffufggtgfgkfhfjgfvvefosehtkeertdertdejnecuhfhrohhmpeforgig ihhmvgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrf grthhtvghrnhepudduudfhveejteefgedvffdvvedvjedugedukeejhedtlefhffevtefh jeeltdevnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epmhgrgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 13 Oct 2022 05:13:17 -0400 (EDT) From: Maxime Ripard Date: Thu, 13 Oct 2022 11:13:10 +0200 Subject: [PATCH v3 3/7] firmware: raspberrypi: Provide a helper to query a clock max rate MIME-Version: 1.0 Message-Id: <20220815-rpi-fix-4k-60-v3-3-fc56729d11fe@cerno.tech> References: <20220815-rpi-fix-4k-60-v3-0-fc56729d11fe@cerno.tech> In-Reply-To: <20220815-rpi-fix-4k-60-v3-0-fc56729d11fe@cerno.tech> To: Florian Fainelli , Michael Turquette , Emma Anholt , Stephen Boyd , Ray Jui , Scott Branden , Broadcom internal kernel review list , Daniel Vetter , David Airlie , Maxime Ripard Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Maxime Ripard , Stefan Wahren , linux-clk@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, Dom Cobley , dri-devel@lists.freedesktop.org X-Mailer: b4 0.11.0-dev-7da52 X-Developer-Signature: v=1; a=openpgp-sha256; l=3367; i=maxime@cerno.tech; h=from:subject:message-id; bh=RlOL1ZTsE2adkZajmlAYwbEWoCI8gC05XMJ1fjN2UAo=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDMnu15ZMmB1f+OGOaJ3DD/NDG62OXJho9PnTrrmnjBaasMqU TIxY3FHKwiDGxSArpsgSI2y+JO7UrNedbHzzYOawMoEMYeDiFICJ6D1lZFi6+Gf0ygvPX4Wtlln+eY Lnx/9bRT19U4piEqt+qqocfsnPyNDg1Ovz5+aUr6K1EVMSn5ezSLVI+Bvv+bH/tlxyVIeSNycA 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-20221013_021318_542953_845D8EA8 X-CRM114-Status: GOOD ( 13.45 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The firmware allows to query for its clocks the operating range of a given clock. We'll need this for some drivers (KMS, in particular) to infer the state of some configuration options, so let's create a function to do so. Acked-by: Stephen Boyd Signed-off-by: Maxime Ripard Reviewed-by: Florian Fainelli --- drivers/firmware/raspberrypi.c | 20 ++++++++++++++++++++ include/soc/bcm2835/raspberrypi-firmware.h | 26 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c index b916e1e171f8..1353ec2f9b53 100644 --- a/drivers/firmware/raspberrypi.c +++ b/drivers/firmware/raspberrypi.c @@ -228,6 +228,26 @@ static void rpi_register_clk_driver(struct device *dev) -1, NULL, 0); } +unsigned int rpi_firmware_clk_get_max_rate(struct rpi_firmware *fw, unsigned int id) +{ + struct rpi_firmware_clk_rate_request msg = + RPI_FIRMWARE_CLK_RATE_REQUEST(id); + int ret; + + ret = rpi_firmware_property(fw, RPI_FIRMWARE_GET_MAX_CLOCK_RATE, + &msg, sizeof(msg)); + if (ret) + /* + * If our firmware doesn't support that operation, or fails, we + * assume the maximum clock rate is absolute maximum we can + * store over our type. + */ + return UINT_MAX; + + return le32_to_cpu(msg.rate); +} +EXPORT_SYMBOL_GPL(rpi_firmware_clk_get_max_rate); + static void rpi_firmware_delete(struct kref *kref) { struct rpi_firmware *fw = container_of(kref, struct rpi_firmware, diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h index 74c7bcc1ac2a..10248c370229 100644 --- a/include/soc/bcm2835/raspberrypi-firmware.h +++ b/include/soc/bcm2835/raspberrypi-firmware.h @@ -154,12 +154,32 @@ enum rpi_firmware_clk_id { RPI_FIRMWARE_NUM_CLK_ID, }; +/** + * struct rpi_firmware_clk_rate_request - Firmware Request for a rate + * @id: ID of the clock being queried + * @rate: Rate in Hertz. Set by the firmware. + * + * Used by @RPI_FIRMWARE_GET_CLOCK_RATE, @RPI_FIRMWARE_GET_CLOCK_MEASURED, + * @RPI_FIRMWARE_GET_MAX_CLOCK_RATE and @RPI_FIRMWARE_GET_MIN_CLOCK_RATE. + */ +struct rpi_firmware_clk_rate_request { + __le32 id; + __le32 rate; +} __packed; + +#define RPI_FIRMWARE_CLK_RATE_REQUEST(_id) \ + { \ + .id = _id, \ + } + #if IS_ENABLED(CONFIG_RASPBERRYPI_FIRMWARE) int rpi_firmware_property(struct rpi_firmware *fw, u32 tag, void *data, size_t len); int rpi_firmware_property_list(struct rpi_firmware *fw, void *data, size_t tag_size); void rpi_firmware_put(struct rpi_firmware *fw); +unsigned int rpi_firmware_clk_get_max_rate(struct rpi_firmware *fw, + unsigned int id); struct device_node *rpi_firmware_find_node(void); struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node); struct rpi_firmware *devm_rpi_firmware_get(struct device *dev, @@ -179,6 +199,12 @@ static inline int rpi_firmware_property_list(struct rpi_firmware *fw, static inline void rpi_firmware_put(struct rpi_firmware *fw) { } +static inline unsigned int rpi_firmware_clk_get_max_rate(struct rpi_firmware *fw, + unsigned int id) +{ + return UINT_MAX; +} + static inline struct device_node *rpi_firmware_find_node(void) { return NULL;