Skip to content

Commit

Permalink
clk: bcm: rpi: Add a function to retrieve the minimum
Browse files Browse the repository at this point in the history
The RaspberryPi firmware can be configured by the end user using the
config.txt file.

Some of these options will affect the kernel capabilities, and we thus
need to be able to detect it to operate reliably.

One of such parameters is the core_clock parameter that allows users to
setup the clocks in a way that is suitable to reach the pixel
frequencies required by the 4096x2016 resolution at 60Hz and higher
modes.

If the user misconfigured it, then those modes will simply not work
but are still likely to be picked up by the userspace, which is a poor
user-experience.

The kernel can't access the config.txt file directly, but one of the
effect that parameter has is that the core clock frequency minimum will
be raised. Thus we can infer its setup by querying the firmware for that
minimum, and if it isn't ignore any of the modes that wouldn't work.

We had in the past a discussion for the maximum and it was suggested to
create a small, ad-hoc function to query the RaspberryPi firmware for
the minimum rate a given clock has, so let's do the same here.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
  • Loading branch information
mripard authored and popcornmix committed Nov 29, 2022
1 parent f59a335 commit 649d683
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions drivers/clk/bcm/clk-raspberrypi.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,33 @@ unsigned long rpi_firmware_clk_get_max_rate(struct clk *clk)
}
EXPORT_SYMBOL_GPL(rpi_firmware_clk_get_max_rate);

unsigned long rpi_firmware_clk_get_min_rate(struct clk *clk)
{
const struct raspberrypi_clk_data *data;
struct raspberrypi_clk *rpi;
struct clk_hw *hw;
u32 min_rate;
int ret;

if (!clk)
return 0;

hw = __clk_get_hw(clk);
if (!hw)
return 0;

data = clk_hw_to_data(hw);
rpi = data->rpi;
ret = raspberrypi_clock_property(rpi->firmware, data,
RPI_FIRMWARE_GET_MIN_CLOCK_RATE,
&min_rate);
if (ret)
return 0;

return min_rate;
}
EXPORT_SYMBOL_GPL(rpi_firmware_clk_get_min_rate);

static const struct clk_ops raspberrypi_firmware_clk_ops = {
.is_prepared = raspberrypi_fw_is_prepared,
.recalc_rate = raspberrypi_fw_get_rate,
Expand Down
6 changes: 6 additions & 0 deletions include/soc/bcm2835/raspberrypi-clocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@

#if IS_ENABLED(CONFIG_CLK_RASPBERRYPI)
unsigned long rpi_firmware_clk_get_max_rate(struct clk *clk);
unsigned long rpi_firmware_clk_get_min_rate(struct clk *clk);
#else
static inline unsigned long rpi_firmware_clk_get_max_rate(struct clk *clk)
{
return ULONG_MAX;
}

static inline unsigned long rpi_firmware_clk_get_min_rate(struct clk *clk)
{
return 0;
}
#endif

#endif /* __SOC_RASPBERRY_CLOCKS_H__ */

0 comments on commit 649d683

Please sign in to comment.