rpivid: Convert to new clock rate API
authorMaxime Ripard <maxime@cerno.tech>
Mon, 24 Oct 2022 11:24:03 +0000 (13:24 +0200)
committerPhil Elwell <8911409+pelwell@users.noreply.github.com>
Sat, 5 Nov 2022 12:31:07 +0000 (12:31 +0000)
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
drivers/staging/media/rpivid/rpivid.h
drivers/staging/media/rpivid/rpivid_hw.c
drivers/staging/media/rpivid/rpivid_video.c

index dbe496a..9d6c2ad 100644 (file)
@@ -185,6 +185,7 @@ struct rpivid_dev {
        void __iomem            *base_h265;
 
        struct clk              *clock;
+       unsigned long           max_clock_rate;
 
        int                     cache_align;
 
index e7d1793..1026fa6 100644 (file)
@@ -25,6 +25,8 @@
 #include <media/videobuf2-core.h>
 #include <media/v4l2-mem2mem.h>
 
+#include <soc/bcm2835/raspberrypi-firmware.h>
+
 #include "rpivid.h"
 #include "rpivid_hw.h"
 
@@ -303,6 +305,8 @@ void rpivid_hw_irq_active2_irq(struct rpivid_dev *dev,
 
 int rpivid_hw_probe(struct rpivid_dev *dev)
 {
+       struct rpi_firmware *firmware;
+       struct device_node *node;
        struct resource *res;
        __u32 irq_stat;
        int irq_dec;
@@ -331,6 +335,19 @@ int rpivid_hw_probe(struct rpivid_dev *dev)
        if (IS_ERR(dev->clock))
                return PTR_ERR(dev->clock);
 
+       node = rpi_firmware_find_node();
+       if (!node)
+               return -EINVAL;
+
+       firmware = rpi_firmware_get(node);
+       of_node_put(node);
+       if (!firmware)
+               return -EPROBE_DEFER;
+
+       dev->max_clock_rate = rpi_firmware_clk_get_max_rate(firmware,
+                                                           RPI_FIRMWARE_HEVC_CLK_ID);
+       rpi_firmware_put(firmware);
+
        dev->cache_align = dma_get_cache_alignment();
 
        // Disable IRQs & reset anything pending
index bab3ed3..37144a6 100644 (file)
@@ -555,12 +555,9 @@ static void stop_clock(struct rpivid_dev *dev, struct rpivid_ctx *ctx)
 /* Always starts the clock if it isn't already on this ctx */
 static int start_clock(struct rpivid_dev *dev, struct rpivid_ctx *ctx)
 {
-       long max_hevc_clock;
        int rv;
 
-       max_hevc_clock = clk_get_max_rate(dev->clock);
-
-       rv = clk_set_min_rate(dev->clock, max_hevc_clock);
+       rv = clk_set_min_rate(dev->clock, dev->max_clock_rate);
        if (rv) {
                dev_err(dev->dev, "Failed to set clock rate\n");
                return rv;