Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: bcm: rpi: Create helper to retrieve private data

The RaspberryPi firmware clocks driver uses in several instances a
container_of to retrieve the struct raspberrypi_clk_data from a pointer
to struct clk_hw. Let's create a small function to avoid duplicating it
all over the place.

Acked-by: Stephen Boyd <sboyd@kernel.org>
Signed-off-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Link: https://lore.kernel.org/r/20250116-bcm2712-clk-updates-v1-4-10bc92ffbf41@raspberrypi.com
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Maxime Ripard and committed by
Stephen Boyd
4af2cfc2 4d85abb0

+10 -8
+10 -8
drivers/clk/bcm/clk-raspberrypi.c
··· 56 56 struct raspberrypi_clk *rpi; 57 57 }; 58 58 59 + static inline 60 + const struct raspberrypi_clk_data *clk_hw_to_data(const struct clk_hw *hw) 61 + { 62 + return container_of(hw, struct raspberrypi_clk_data, hw); 63 + } 64 + 59 65 struct raspberrypi_clk_variant { 60 66 bool export; 61 67 char *clkdev; ··· 182 176 183 177 static int raspberrypi_fw_is_prepared(struct clk_hw *hw) 184 178 { 185 - struct raspberrypi_clk_data *data = 186 - container_of(hw, struct raspberrypi_clk_data, hw); 179 + const struct raspberrypi_clk_data *data = clk_hw_to_data(hw); 187 180 struct raspberrypi_clk *rpi = data->rpi; 188 181 u32 val = 0; 189 182 int ret; ··· 199 194 static unsigned long raspberrypi_fw_get_rate(struct clk_hw *hw, 200 195 unsigned long parent_rate) 201 196 { 202 - struct raspberrypi_clk_data *data = 203 - container_of(hw, struct raspberrypi_clk_data, hw); 197 + const struct raspberrypi_clk_data *data = clk_hw_to_data(hw); 204 198 struct raspberrypi_clk *rpi = data->rpi; 205 199 u32 val = 0; 206 200 int ret; ··· 215 211 static int raspberrypi_fw_set_rate(struct clk_hw *hw, unsigned long rate, 216 212 unsigned long parent_rate) 217 213 { 218 - struct raspberrypi_clk_data *data = 219 - container_of(hw, struct raspberrypi_clk_data, hw); 214 + const struct raspberrypi_clk_data *data = clk_hw_to_data(hw); 220 215 struct raspberrypi_clk *rpi = data->rpi; 221 216 u32 _rate = rate; 222 217 int ret; ··· 232 229 static int raspberrypi_fw_dumb_determine_rate(struct clk_hw *hw, 233 230 struct clk_rate_request *req) 234 231 { 235 - struct raspberrypi_clk_data *data = 236 - container_of(hw, struct raspberrypi_clk_data, hw); 232 + const struct raspberrypi_clk_data *data = clk_hw_to_data(hw); 237 233 struct raspberrypi_clk_variant *variant = data->variant; 238 234 239 235 /*