d5ac2e941fee9b3d87c6a1c7563225f90336c6e2
[openwrt/staging/jow.git] /
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
5 clock max rate
6
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
10 function to do so.
11
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>
15 ---
16 drivers/firmware/raspberrypi.c | 20 +++++++++++++++++
17 include/soc/bcm2835/raspberrypi-firmware.h | 26 ++++++++++++++++++++++
18 2 files changed, 46 insertions(+)
19
20 --- a/drivers/firmware/raspberrypi.c
21 +++ b/drivers/firmware/raspberrypi.c
22 @@ -343,6 +343,26 @@ static void rpi_register_clk_driver(stru
23 -1, NULL, 0);
24 }
25
26 +unsigned int rpi_firmware_clk_get_max_rate(struct rpi_firmware *fw, unsigned int id)
27 +{
28 + struct rpi_firmware_clk_rate_request msg =
29 + RPI_FIRMWARE_CLK_RATE_REQUEST(id);
30 + int ret;
31 +
32 + ret = rpi_firmware_property(fw, RPI_FIRMWARE_GET_MAX_CLOCK_RATE,
33 + &msg, sizeof(msg));
34 + if (ret)
35 + /*
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.
39 + */
40 + return UINT_MAX;
41 +
42 + return le32_to_cpu(msg.rate);
43 +}
44 +EXPORT_SYMBOL_GPL(rpi_firmware_clk_get_max_rate);
45 +
46 static void rpi_firmware_delete(struct kref *kref)
47 {
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 {
52
53 #define GET_DISPLAY_SETTINGS_PAYLOAD_SIZE 64
54
55 +/**
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.
59 + *
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.
62 + */
63 +struct rpi_firmware_clk_rate_request {
64 + __le32 id;
65 + __le32 rate;
66 +} __packed;
67 +
68 +#define RPI_FIRMWARE_CLK_RATE_REQUEST(_id) \
69 + { \
70 + .id = _id, \
71 + }
72 +
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,
80 + unsigned int id);
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_
85
86 static inline void rpi_firmware_put(struct rpi_firmware *fw) { }
87
88 +static inline unsigned int rpi_firmware_clk_get_max_rate(struct rpi_firmware *fw,
89 + unsigned int id)
90 +{
91 + return UINT_MAX;
92 +}
93 +
94 static inline struct device_node *rpi_firmware_find_node(void)
95 {
96 return NULL;