1 From 4c64053e0646f66463bded712d7e6975757cf4c2 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Tue, 20 Sep 2022 13:49:10 +0200
4 Subject: [PATCH] firmware: raspberrypi: Provide a helper to query a
7 The firmware allows to query for its clocks the operating range of a
8 given clock. We'll need this for some drivers (KMS, in particular) to
9 infer the state of some configuration options, so let's create a
12 Acked-by: Stephen Boyd <sboyd@kernel.org>
13 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
14 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
16 drivers/firmware/raspberrypi.c | 20 +++++++++++++++++
17 include/soc/bcm2835/raspberrypi-firmware.h | 26 ++++++++++++++++++++++
18 2 files changed, 46 insertions(+)
20 --- a/drivers/firmware/raspberrypi.c
21 +++ b/drivers/firmware/raspberrypi.c
22 @@ -343,6 +343,26 @@ static void rpi_register_clk_driver(stru
26 +unsigned int rpi_firmware_clk_get_max_rate(struct rpi_firmware *fw, unsigned int id)
28 + struct rpi_firmware_clk_rate_request msg =
29 + RPI_FIRMWARE_CLK_RATE_REQUEST(id);
32 + ret = rpi_firmware_property(fw, RPI_FIRMWARE_GET_MAX_CLOCK_RATE,
36 + * If our firmware doesn't support that operation, or fails, we
37 + * assume the maximum clock rate is absolute maximum we can
38 + * store over our type.
42 + return le32_to_cpu(msg.rate);
44 +EXPORT_SYMBOL_GPL(rpi_firmware_clk_get_max_rate);
46 static void rpi_firmware_delete(struct kref *kref)
48 struct rpi_firmware *fw = container_of(kref, struct rpi_firmware,
49 --- a/include/soc/bcm2835/raspberrypi-firmware.h
50 +++ b/include/soc/bcm2835/raspberrypi-firmware.h
51 @@ -181,12 +181,32 @@ enum rpi_firmware_clk_id {
53 #define GET_DISPLAY_SETTINGS_PAYLOAD_SIZE 64
56 + * struct rpi_firmware_clk_rate_request - Firmware Request for a rate
57 + * @id: ID of the clock being queried
58 + * @rate: Rate in Hertz. Set by the firmware.
60 + * Used by @RPI_FIRMWARE_GET_CLOCK_RATE, @RPI_FIRMWARE_GET_CLOCK_MEASURED,
61 + * @RPI_FIRMWARE_GET_MAX_CLOCK_RATE and @RPI_FIRMWARE_GET_MIN_CLOCK_RATE.
63 +struct rpi_firmware_clk_rate_request {
68 +#define RPI_FIRMWARE_CLK_RATE_REQUEST(_id) \
73 #if IS_ENABLED(CONFIG_RASPBERRYPI_FIRMWARE)
74 int rpi_firmware_property(struct rpi_firmware *fw,
75 u32 tag, void *data, size_t len);
76 int rpi_firmware_property_list(struct rpi_firmware *fw,
77 void *data, size_t tag_size);
78 void rpi_firmware_put(struct rpi_firmware *fw);
79 +unsigned int rpi_firmware_clk_get_max_rate(struct rpi_firmware *fw,
81 struct device_node *rpi_firmware_find_node(void);
82 struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node);
83 struct rpi_firmware *devm_rpi_firmware_get(struct device *dev,
84 @@ -206,6 +226,12 @@ static inline int rpi_firmware_property_
86 static inline void rpi_firmware_put(struct rpi_firmware *fw) { }
88 +static inline unsigned int rpi_firmware_clk_get_max_rate(struct rpi_firmware *fw,
94 static inline struct device_node *rpi_firmware_find_node(void)