Skip to content

Commit 4af2cfc

Browse files
mripardbebarino
authored andcommitted
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>
1 parent 4d85abb commit 4af2cfc

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

drivers/clk/bcm/clk-raspberrypi.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ struct raspberrypi_clk_data {
5656
struct raspberrypi_clk *rpi;
5757
};
5858

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+
5965
struct raspberrypi_clk_variant {
6066
bool export;
6167
char *clkdev;
@@ -176,8 +182,7 @@ static int raspberrypi_clock_property(struct rpi_firmware *firmware,
176182

177183
static int raspberrypi_fw_is_prepared(struct clk_hw *hw)
178184
{
179-
struct raspberrypi_clk_data *data =
180-
container_of(hw, struct raspberrypi_clk_data, hw);
185+
const struct raspberrypi_clk_data *data = clk_hw_to_data(hw);
181186
struct raspberrypi_clk *rpi = data->rpi;
182187
u32 val = 0;
183188
int ret;
@@ -194,8 +199,7 @@ static int raspberrypi_fw_is_prepared(struct clk_hw *hw)
194199
static unsigned long raspberrypi_fw_get_rate(struct clk_hw *hw,
195200
unsigned long parent_rate)
196201
{
197-
struct raspberrypi_clk_data *data =
198-
container_of(hw, struct raspberrypi_clk_data, hw);
202+
const struct raspberrypi_clk_data *data = clk_hw_to_data(hw);
199203
struct raspberrypi_clk *rpi = data->rpi;
200204
u32 val = 0;
201205
int ret;
@@ -211,8 +215,7 @@ static unsigned long raspberrypi_fw_get_rate(struct clk_hw *hw,
211215
static int raspberrypi_fw_set_rate(struct clk_hw *hw, unsigned long rate,
212216
unsigned long parent_rate)
213217
{
214-
struct raspberrypi_clk_data *data =
215-
container_of(hw, struct raspberrypi_clk_data, hw);
218+
const struct raspberrypi_clk_data *data = clk_hw_to_data(hw);
216219
struct raspberrypi_clk *rpi = data->rpi;
217220
u32 _rate = rate;
218221
int ret;
@@ -229,8 +232,7 @@ static int raspberrypi_fw_set_rate(struct clk_hw *hw, unsigned long rate,
229232
static int raspberrypi_fw_dumb_determine_rate(struct clk_hw *hw,
230233
struct clk_rate_request *req)
231234
{
232-
struct raspberrypi_clk_data *data =
233-
container_of(hw, struct raspberrypi_clk_data, hw);
235+
const struct raspberrypi_clk_data *data = clk_hw_to_data(hw);
234236
struct raspberrypi_clk_variant *variant = data->variant;
235237

236238
/*

0 commit comments

Comments
 (0)