media: ti-vpe: cal: add camerarx enable/disable refcounting
authorTomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Mon, 14 Jun 2021 11:23:43 +0000 (13:23 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Mon, 12 Jul 2021 12:22:11 +0000 (14:22 +0200)
The following patches add multistream support and we will have multiple
video devices using the same camerarx instances. Thus we need
enable/disable refcounting for the camerarx.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/platform/ti-vpe/cal-camerarx.c
drivers/media/platform/ti-vpe/cal.h

index f799047..79ebad1 100644 (file)
@@ -285,6 +285,11 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
        u32 val;
        int ret;
 
+       if (phy->enable_count > 0) {
+               phy->enable_count++;
+               return 0;
+       }
+
        link_freq = cal_camerarx_get_ext_link_freq(phy);
        if (link_freq < 0)
                return link_freq;
@@ -409,6 +414,8 @@ static int cal_camerarx_start(struct cal_camerarx *phy)
        /* Finally, enable the PHY Protocol Interface (PPI). */
        cal_camerarx_ppi_enable(phy);
 
+       phy->enable_count++;
+
        return 0;
 }
 
@@ -416,6 +423,9 @@ static void cal_camerarx_stop(struct cal_camerarx *phy)
 {
        int ret;
 
+       if (--phy->enable_count > 0)
+               return;
+
        cal_camerarx_ppi_disable(phy);
 
        cal_camerarx_disable_irqs(phy);
index cf0b8f5..006374b 100644 (file)
@@ -167,8 +167,11 @@ struct cal_camerarx {
        /*
         * Lock for camerarx ops. Protects:
         * - formats
+        * - enable_count
         */
        struct mutex            mutex;
+
+       unsigned int            enable_count;
 };
 
 struct cal_dev {