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@xxxxxxxxxx> diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c index 182e8817eac2..b81da5b1dd1e 100644 --- a/drivers/clk/bcm/clk-raspberrypi.c +++ b/drivers/clk/bcm/clk-raspberrypi.c @@ -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, diff --git a/include/soc/bcm2835/raspberrypi-clocks.h b/include/soc/bcm2835/raspberrypi-clocks.h index ff0b608b51a8..627535877964 100644 --- a/include/soc/bcm2835/raspberrypi-clocks.h +++ b/include/soc/bcm2835/raspberrypi-clocks.h @@ -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__ */ -- b4 0.10.0-dev-a76f5