From patchwork Thu Oct 20 09:12:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 6070 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp150393wrs; Thu, 20 Oct 2022 02:18:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5AB/DC1b1fOkcEzYkOl5mPtxZUB372MaQXDZ+Y16w+/xLuPSgVH3FHZ/NrUCjwYjgiiA3F X-Received: by 2002:a05:6a00:4214:b0:562:67d0:77e7 with SMTP id cd20-20020a056a00421400b0056267d077e7mr13474247pfb.62.1666257539541; Thu, 20 Oct 2022 02:18:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666257539; cv=none; d=google.com; s=arc-20160816; b=Jzh0okTqjG/NQqo6jTBpDIVB8wmKvTh7av6QlrM1O1a98CfTCOwISK9AODEG024OI6 0zNV8+vKQxSyP+I0lFugNS5C8PeocZGGwN0T+uwEGoPObiLG3o5WZpNauphFfvslhgyO nBoarcgcDFJPu/jXY3gycLByZ7mBqvxUBdLiV/yn96w94pWQMjZX468hhv0NO6YymJsY DbBZYJymD8sAPj2Pc3KeH2Phr3A8BASXdEzIPzdVbKqSwjeLnha/qH/cbYY2mBxvrGt1 kjNN3n6Jmq8MFKiPBJh/KZv1RY482kplPPkfJ+gjXme9cHhZX9fs3/irq6Gwh3KZ+Fs0 aiGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :feedback-id:dkim-signature:dkim-signature; bh=CXd9oRopfbOxK5QPR9Spj+UXGsDItKKcc5F0wWKHw/k=; b=J9BF+qa4Vsc7t1kmjgL3Afi2/gSwGbCSneNfqTAAaZEgLy2If3girHrQyCmj8aZGN1 tkupZuTlSxnNvHYygmelW+Iw5bF3l4Xs9oyFbRR/L4Lk3jltQjhsuvnjsY9hORepiq+V wW1s3EHRpF9eFpQR1JKSRQvGtXrrXwc5kvZxnScZxFgbKvh1bdxigCPQblfvifIRQPXT NbK4hqcDq0CcUJpVeP1tso4HHHeuVkLr9slwAEh+feQxN8Rq89zqRaoj4294vhaW6po3 ai78z5qFVDP+PirO8GGRaZoYU1N9f1wXVnCHe0vuayc/XVBvlR2QPHmmSvea8jqNy23B FlIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm3 header.b=i6UJC1IG; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=Y0NizKBv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y16-20020a17090aa41000b0020d5c7ae3cbsi2545335pjp.38.2022.10.20.02.18.46; Thu, 20 Oct 2022 02:18:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm3 header.b=i6UJC1IG; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=Y0NizKBv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229962AbiJTJNr (ORCPT + 99 others); Thu, 20 Oct 2022 05:13:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231193AbiJTJNm (ORCPT ); Thu, 20 Oct 2022 05:13:42 -0400 Received: from wnew2-smtp.messagingengine.com (wnew2-smtp.messagingengine.com [64.147.123.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3DC21ACA87; Thu, 20 Oct 2022 02:13:37 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.west.internal (Postfix) with ESMTP id DE29E2B05D99; Thu, 20 Oct 2022 05:13:34 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 20 Oct 2022 05:13:37 -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=1666257214; x= 1666264414; bh=CXd9oRopfbOxK5QPR9Spj+UXGsDItKKcc5F0wWKHw/k=; b=i 6UJC1IG+XOUa9o3Z1Vw95D+pejwL0gY2pexQQMTA7Eq9YMcldKUGo8TjKesqgp26 98cYnbAJCUiFZDZMsDx2V4SjKHIgTz/6sIgU6JLmvAWGWf7Zl8Vl3F3m3tOuIBwF UM0ymR33IlnCHyKcYwjq6lcUVz4wi9KiFs0ZJc8rBrZNOfjG59HoINNF8SfutbFt aNSbiTUFgp4szOmktYP9kTTs8q5WtxuvafypzFNLlb3rNs243VfvjxmvO4BNKB3W /0JsJ87DlA8EVmuTG5P1Aw2+GOqEF3+/fcveTL/8SFKv7uGQQqzdOfhAc6HZWQ7l HUjAoqtYh5m1goW1gPggA== 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=1666257214; x= 1666264414; bh=CXd9oRopfbOxK5QPR9Spj+UXGsDItKKcc5F0wWKHw/k=; b=Y 0NizKBvjNJtcGdf1cm/4cCM54ku0hv+ZinYWysg9mf3Jc3aU/AKtnE/60pLwap8M sRXJqoY7zzPo+a8RK58KDKlrLw6GISd+TYsToWJC+rzABn/9l7PvACbR7rgq5Kzl AazX1aqBd5Cm+5PKpNlPWk3hct7DVLSzNgGFu/WxRcZSJpa5d8TFDIuZFxUd12lg CTKSN6IDRS2XwfwHfBHItNbSwpLq7pRaR17ZG/Lsu7Qpe0ALq/rrpJCBg2u6OwX9 cWjFrA7JuPzwbv2IAF+l6al7GZCAjE5XtanKkbk9wormIeDdN8w40yLPRwOixZvz jLaGIUkA4kcIkjRK8sLoQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeeliedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephfffufggtgfgkfhfjgfvvefosehtkeertdertdejnecuhfhrohhmpehmrgig ihhmvgestggvrhhnohdrthgvtghhnecuggftrfgrthhtvghrnhepfeduhfegveehhfeftd euveeuleduuddttedutddvvdegkeehleevhfetkeetiefhnecuvehluhhsthgvrhfuihii vgepudenucfrrghrrghmpehmrghilhhfrhhomhepmhgrgihimhgvsegtvghrnhhordhtvg gthh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 20 Oct 2022 05:13:33 -0400 (EDT) From: maxime@cerno.tech Date: Thu, 20 Oct 2022 11:12:11 +0200 Subject: [PATCH v4 3/7] firmware: raspberrypi: Provide a helper to query a clock max rate MIME-Version: 1.0 Message-Id: <20220815-rpi-fix-4k-60-v4-3-a1b40526df3e@cerno.tech> References: <20220815-rpi-fix-4k-60-v4-0-a1b40526df3e@cerno.tech> In-Reply-To: <20220815-rpi-fix-4k-60-v4-0-a1b40526df3e@cerno.tech> To: Daniel Vetter , Emma Anholt , Michael Turquette , Stephen Boyd , Maxime Ripard , Ray Jui , Florian Fainelli , David Airlie , Broadcom internal kernel review list , Scott Branden Cc: Stefan Wahren , Maxime Ripard , linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Dom Cobley , linux-rpi-kernel@lists.infradead.org X-Mailer: b4 0.10.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3411; i=maxime@cerno.tech; h=from:subject:message-id; bh=c1P+fLFDaTroanhyem4W+5lau6usqj5h7iESMD9wvPc=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDMmBAq/2iy4PNzHUl5oysXL242N/5zbPjHNcZszZ4+pU/sM1 r/BjRykLgxgXg6yYIkuMsPmSuFOzXney8c2DmcPKBDKEgYtTACay4zEjw2etxqTMY95Tw4zbDz7UOb JA64rryVXxSUJSEecipm1b6c7IcHQ2Y1XpM7uHR+KZJjXtfvth1/513Cw1jZLb7M9/fmXzmBcA X-Developer-Key: i=maxime@cerno.tech; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747197665563298378?= X-GMAIL-MSGID: =?utf-8?q?1747197665563298378?= 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 Reviewed-by: Florian Fainelli Signed-off-by: Maxime Ripard --- 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 932a8bef22fb..b15aa6fce0e9 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 9b1db12d013f..ab955591cb72 100644 --- a/include/soc/bcm2835/raspberrypi-firmware.h +++ b/include/soc/bcm2835/raspberrypi-firmware.h @@ -155,12 +155,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, @@ -180,6 +200,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;