From patchwork Tue Sep 20 12:50:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 12982096 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 BFDB3ECAAD8 for ; Tue, 20 Sep 2022 12:54:43 +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=W4ws0wM/CaTbM1A+z/VUE4khoDBvC+AUUpA/IumtjF8=; b=CortVgaQ01bdWM fGZID+2O2V0pebgxSO7QGCP6fZs2jI/amN51xU6erKITWST57d1/2EEXvuW2AAH7Oi7uEKzLTk5lq ScZ6HF5y4pv6rejcr0moJgMzG7AkaCtKxrg45Uqfl/WfEUcrcVT6NBoPGz8CMRHcJwvBWzP4xHFtQ bwNnk5b5a4f7RxY/nwkce97zOfjoXNwesmlc+g1Wnuh/cxg88dvvyCbNI1KRsBDebtDjPhcqBvYxf YFBSAThvxtGtTjRrep7L9okmAeqQfBQwUglVq82TRFzjbcg7rXeOA7VaGUo9Yr2a9yiC8qk7gNqRs 8uBkwShCUpiMeLD72c8Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oackv-003qB9-IN; Tue, 20 Sep 2022 12:53:42 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oackM-003psg-Dx; Tue, 20 Sep 2022 12:53:07 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 734EA3200A22; Tue, 20 Sep 2022 08:53:04 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 20 Sep 2022 08:53:05 -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=fm2; t=1663678383; x= 1663764783; bh=Oiy8kIrWntAe9Yt5cwgH+aW2cgmJxqz4HocKaGGRcNk=; b=E tkMWkXgpBxKlSbUPsQdMtUQkgHXbrfmVUzOzgUsXr3G/U3+V+fqnIh/aplPBbnDS VLcF10RAHeEpSUqSNvGc49/Nr1rjIf2GVdweXmr8DeRmUQj+TQQ1b4vf/tFwyUUT 6If//qhRUHQqhUMhgUWkpbbSI35uEbB136zoeF7u8VYThjhyX+iLYLgJW2YLpbkh Y10DRcXEPf+FPg9uH6VUvubWCcuaGt8GlRLyaVC8sF4SXSPOS603vT4ik/XIrQww LOcwHlDsWAXnd504rQxNJhePvi/QRTvA2jXhST8Rap9xOAbWiwawuLJT4sWUI340 KfUFdnENO84RyfVwxlrrg== 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=fm2; t=1663678383; x= 1663764783; bh=Oiy8kIrWntAe9Yt5cwgH+aW2cgmJxqz4HocKaGGRcNk=; b=o kuWE/2f+d5a8axPLZGdphHCAsCZAibP0zhA604Ws1qeI0zobNK2SHDfhgEqn88t1 oNLHU11GnGCl31eZHH1Awnm2CVMx1T6mzkX9Va6hNvmWgWGxCjszRXpeDVR8RnYf cAq+AwSZJO295NyZz5OiFUAxg5J/XV6EWBR1YpWQ6OFmH6DmFytyiTvJn3EMHYKu pLqdxZ+Eafzocs6FYe3PO9310ifSZL9tZ6C6BktjO87uzxrzZ7TuIrzPdiN9DLoW +d/CWwc0NhBrxtFv3I+IXunCdmQcQptvr8lGpG3fHr0Luohr1gEGQth4eoglR+zH e1lvAJxTJUGL+npPIqeLg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfedvledgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephfffufggtgfgkfhfjgfvvefosehtkeertdertdejnecuhfhrohhmpeforgig ihhmvgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrf grthhtvghrnhepudduudfhveejteefgedvffdvvedvjedugedukeejhedtlefhffevtefh jeeltdevnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epmhgrgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 20 Sep 2022 08:53:02 -0400 (EDT) From: Maxime Ripard Date: Tue, 20 Sep 2022 14:50:22 +0200 Subject: [PATCH v2 3/7] firmware: raspberrypi: Provide a helper to query a clock max rate MIME-Version: 1.0 Message-Id: <20220815-rpi-fix-4k-60-v2-3-983276b83f62@cerno.tech> References: <20220815-rpi-fix-4k-60-v2-0-983276b83f62@cerno.tech> In-Reply-To: <20220815-rpi-fix-4k-60-v2-0-983276b83f62@cerno.tech> To: Daniel Vetter , Florian Fainelli , David Airlie , Broadcom internal kernel review list , Michael Turquette , Scott Branden , Stephen Boyd , Emma Anholt , Ray Jui , Maxime Ripard Cc: linux-rpi-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Dom Cobley , dri-devel@lists.freedesktop.org, Maxime Ripard , linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.10.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2942; i=maxime@cerno.tech; h=from:subject:message-id; bh=JMjc9vTvD3H2O1YtnTvuBs8PHnlojILED71Z9PcUCZo=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDMma2/ncKlKnsvlVbvHoLpr69asJ88cXN/68mjtF7o39cre1 s8z+dJSyMIhxMciKKbLECJsviTs163UnG988mDmsTCBDGLg4BWAil4MYGTZXnd5UHKNXUhTSuGGO+Q R/t84VDr+ik/VsD9W0yXsWtTAy9CTdmbzNV6I8Kvh2pvrljQ1B/451nfkdtfhZQvepSQ0fmAE= 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-20220920_055306_563656_63716FA0 X-CRM114-Status: GOOD ( 12.29 ) 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. Signed-off-by: Maxime Ripard Acked-by: Stephen Boyd diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c index b916e1e171f8..c4b9ea70f5a7 100644 --- a/drivers/firmware/raspberrypi.c +++ b/drivers/firmware/raspberrypi.c @@ -228,6 +228,21 @@ 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) + return 0; + + 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;