]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
media: qcom: camss: csid: Move common code into csid core
authorDepeng Shao <quic_depengs@quicinc.com>
Mon, 13 Jan 2025 04:31:24 +0000 (10:01 +0530)
committerHans Verkuil <hverkuil@xs4all.nl>
Thu, 6 Feb 2025 12:49:31 +0000 (13:49 +0100)
The get hw version and src pad code functions can be common code in csid
core file, then the csid driver of different hw version can reuse them,
rather than adding duplicate code in csid driver for each version.

Suggested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Depeng Shao <quic_depengs@quicinc.com>
Reviewed-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
drivers/media/platform/qcom/camss/camss-csid-4-1.c
drivers/media/platform/qcom/camss/camss-csid-4-7.c
drivers/media/platform/qcom/camss/camss-csid-gen2.c
drivers/media/platform/qcom/camss/camss-csid.c
drivers/media/platform/qcom/camss/camss-csid.h

index c95861420502916816b4ab0a460c147abe4a49c3..6998e1c52895c0e65ef1a983cef6f8962104fa5a 100644 (file)
@@ -17,7 +17,6 @@
 #include "camss-csid-gen1.h"
 #include "camss.h"
 
-#define CAMSS_CSID_HW_VERSION          0x0
 #define CAMSS_CSID_CORE_CTRL_0         0x004
 #define CAMSS_CSID_CORE_CTRL_1         0x008
 #define CAMSS_CSID_RST_CMD             0x00c
@@ -139,15 +138,6 @@ static int csid_configure_testgen_pattern(struct csid_device *csid, s32 val)
        return 0;
 }
 
-static u32 csid_hw_version(struct csid_device *csid)
-{
-       u32 hw_version = readl_relaxed(csid->base + CAMSS_CSID_HW_VERSION);
-
-       dev_dbg(csid->camss->dev, "CSID HW Version = 0x%08x\n", hw_version);
-
-       return hw_version;
-}
-
 static irqreturn_t csid_isr(int irq, void *dev)
 {
        struct csid_device *csid = dev;
@@ -180,15 +170,6 @@ static int csid_reset(struct csid_device *csid)
        return 0;
 }
 
-static u32 csid_src_pad_code(struct csid_device *csid, u32 sink_code,
-                            unsigned int match_format_idx, u32 match_code)
-{
-       if (match_format_idx > 0)
-               return 0;
-
-       return sink_code;
-}
-
 static void csid_subdev_init(struct csid_device *csid)
 {
        csid->testgen.modes = csid_testgen_modes;
index 08578a1436885b2c0062395b6ac76a009dd20545..66054d4872e699e9b5d6257726177c1447fa4e8a 100644 (file)
@@ -16,7 +16,6 @@
 #include "camss-csid-gen1.h"
 #include "camss.h"
 
-#define CAMSS_CSID_HW_VERSION          0x0
 #define CAMSS_CSID_CORE_CTRL_0         0x004
 #define CAMSS_CSID_CORE_CTRL_1         0x008
 #define CAMSS_CSID_RST_CMD             0x010
@@ -151,15 +150,6 @@ static int csid_configure_testgen_pattern(struct csid_device *csid, s32 val)
        return 0;
 }
 
-static u32 csid_hw_version(struct csid_device *csid)
-{
-       u32 hw_version = readl_relaxed(csid->base + CAMSS_CSID_HW_VERSION);
-
-       dev_dbg(csid->camss->dev, "CSID HW Version = 0x%08x\n", hw_version);
-
-       return hw_version;
-}
-
 /*
  * isr - CSID module interrupt service routine
  * @irq: Interrupt line
@@ -205,38 +195,6 @@ static int csid_reset(struct csid_device *csid)
        return 0;
 }
 
-static u32 csid_src_pad_code(struct csid_device *csid, u32 sink_code,
-                            unsigned int match_format_idx, u32 match_code)
-{
-       switch (sink_code) {
-       case MEDIA_BUS_FMT_SBGGR10_1X10:
-       {
-               u32 src_code[] = {
-                       MEDIA_BUS_FMT_SBGGR10_1X10,
-                       MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE,
-               };
-
-               return csid_find_code(src_code, ARRAY_SIZE(src_code),
-                                     match_format_idx, match_code);
-       }
-       case MEDIA_BUS_FMT_Y10_1X10:
-       {
-               u32 src_code[] = {
-                       MEDIA_BUS_FMT_Y10_1X10,
-                       MEDIA_BUS_FMT_Y10_2X8_PADHI_LE,
-               };
-
-               return csid_find_code(src_code, ARRAY_SIZE(src_code),
-                                     match_format_idx, match_code);
-       }
-       default:
-               if (match_format_idx > 0)
-                       return 0;
-
-               return sink_code;
-       }
-}
-
 static void csid_subdev_init(struct csid_device *csid)
 {
        csid->testgen.modes = csid_testgen_modes;
index e1c757933e2733a0ec8d6bd068ec295925fd9e21..2a1746dcc1c5b84028dd8bdff7845bd3a912ab8d 100644 (file)
  * alternate register layout.
  */
 
-#define CSID_HW_VERSION                0x0
-#define                HW_VERSION_STEPPING     0
-#define                HW_VERSION_REVISION     16
-#define                HW_VERSION_GENERATION   28
-
 #define CSID_RST_STROBES       0x10
 #define                RST_STROBES     0
 
@@ -351,29 +346,6 @@ static int csid_configure_testgen_pattern(struct csid_device *csid, s32 val)
        return 0;
 }
 
-/*
- * csid_hw_version - CSID hardware version query
- * @csid: CSID device
- *
- * Return HW version or error
- */
-static u32 csid_hw_version(struct csid_device *csid)
-{
-       u32 hw_version;
-       u32 hw_gen;
-       u32 hw_rev;
-       u32 hw_step;
-
-       hw_version = readl_relaxed(csid->base + CSID_HW_VERSION);
-       hw_gen = (hw_version >> HW_VERSION_GENERATION) & 0xF;
-       hw_rev = (hw_version >> HW_VERSION_REVISION) & 0xFFF;
-       hw_step = (hw_version >> HW_VERSION_STEPPING) & 0xFFFF;
-       dev_dbg(csid->camss->dev, "CSID HW Version = %u.%u.%u\n",
-               hw_gen, hw_rev, hw_step);
-
-       return hw_version;
-}
-
 /*
  * csid_isr - CSID module interrupt service routine
  * @irq: Interrupt line
@@ -443,38 +415,6 @@ static int csid_reset(struct csid_device *csid)
        return 0;
 }
 
-static u32 csid_src_pad_code(struct csid_device *csid, u32 sink_code,
-                            unsigned int match_format_idx, u32 match_code)
-{
-       switch (sink_code) {
-       case MEDIA_BUS_FMT_SBGGR10_1X10:
-       {
-               u32 src_code[] = {
-                       MEDIA_BUS_FMT_SBGGR10_1X10,
-                       MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE,
-               };
-
-               return csid_find_code(src_code, ARRAY_SIZE(src_code),
-                                     match_format_idx, match_code);
-       }
-       case MEDIA_BUS_FMT_Y10_1X10:
-       {
-               u32 src_code[] = {
-                       MEDIA_BUS_FMT_Y10_1X10,
-                       MEDIA_BUS_FMT_Y10_2X8_PADHI_LE,
-               };
-
-               return csid_find_code(src_code, ARRAY_SIZE(src_code),
-                                     match_format_idx, match_code);
-       }
-       default:
-               if (match_format_idx > 0)
-                       return 0;
-
-               return sink_code;
-       }
-}
-
 static void csid_subdev_init(struct csid_device *csid)
 {
        csid->testgen.modes = csid_testgen_modes;
index 858db5d4ca75c370d2fd0deda739c6dcf76c205a..6cf8e434dc05d302077a79b46bfa1233e17bbbe5 100644 (file)
 #define VFE_480_CSID_OFFSET 0x1200
 #define VFE_480_LITE_CSID_OFFSET 0x200
 
+#define CSID_HW_VERSION                0x0
+#define                HW_VERSION_STEPPING     0
+#define                HW_VERSION_REVISION     16
+#define                HW_VERSION_GENERATION   28
+
 #define MSM_CSID_NAME "msm_csid"
 
 const char * const csid_testgen_modes[] = {
@@ -590,6 +595,78 @@ static int csid_set_clock_rates(struct csid_device *csid)
        return 0;
 }
 
+/*
+ * csid_hw_version - CSID hardware version query
+ * @csid: CSID device
+ *
+ * Return HW version or error
+ */
+u32 csid_hw_version(struct csid_device *csid)
+{
+       u32 hw_version;
+       u32 hw_gen;
+       u32 hw_rev;
+       u32 hw_step;
+
+       hw_version = readl_relaxed(csid->base + CSID_HW_VERSION);
+       hw_gen = (hw_version >> HW_VERSION_GENERATION) & 0xF;
+       hw_rev = (hw_version >> HW_VERSION_REVISION) & 0xFFF;
+       hw_step = (hw_version >> HW_VERSION_STEPPING) & 0xFFFF;
+       dev_info(csid->camss->dev, "CSID:%d HW Version = %u.%u.%u\n",
+                csid->id, hw_gen, hw_rev, hw_step);
+
+       return hw_version;
+}
+
+/*
+ * csid_src_pad_code - Pick an output/src format based on the input/sink format
+ * @csid: CSID device
+ * @sink_code: The sink format of the input
+ * @match_format_idx: Request preferred index, as defined by subdevice csid
+ *                    format. Set @match_code to 0 if used.
+ * @match_code: Request preferred code, set @match_format_idx to 0 if used
+ *
+ * Return 0 on failure or src format code otherwise
+ */
+u32 csid_src_pad_code(struct csid_device *csid, u32 sink_code,
+                     unsigned int match_format_idx, u32 match_code)
+{
+       if (csid->camss->res->version == CAMSS_8x16) {
+               if (match_format_idx > 0)
+                       return 0;
+
+               return sink_code;
+       }
+
+       switch (sink_code) {
+       case MEDIA_BUS_FMT_SBGGR10_1X10:
+       {
+               u32 src_code[] = {
+                       MEDIA_BUS_FMT_SBGGR10_1X10,
+                       MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE,
+               };
+
+               return csid_find_code(src_code, ARRAY_SIZE(src_code),
+                                     match_format_idx, match_code);
+       }
+       case MEDIA_BUS_FMT_Y10_1X10:
+       {
+               u32 src_code[] = {
+                       MEDIA_BUS_FMT_Y10_1X10,
+                       MEDIA_BUS_FMT_Y10_2X8_PADHI_LE,
+               };
+
+               return csid_find_code(src_code, ARRAY_SIZE(src_code),
+                                     match_format_idx, match_code);
+       }
+       default:
+               if (match_format_idx > 0)
+                       return 0;
+
+               return sink_code;
+       }
+}
+
 /*
  * csid_set_power - Power on/off CSID module
  * @sd: CSID V4L2 subdevice
index 8cdae98e4dca6d39d9d2c3807dd171aeb5458762..f52209b96583c30cb217667b60b5529f2b5e1bdd 100644 (file)
@@ -237,4 +237,25 @@ extern const struct csid_hw_ops csid_ops_gen2;
  */
 bool csid_is_lite(struct csid_device *csid);
 
+/*
+ * csid_hw_version - CSID hardware version query
+ * @csid: CSID device
+ *
+ * Return HW version or error
+ */
+u32 csid_hw_version(struct csid_device *csid);
+
+/*
+ * csid_src_pad_code - Pick an output/src format based on the input/sink format
+ * @csid: CSID device
+ * @sink_code: The sink format of the input
+ * @match_format_idx: Request preferred index, as defined by subdevice csid
+ *                    format. Set @match_code to 0 if used.
+ * @match_code: Request preferred code, set @match_format_idx to 0 if used
+ *
+ * Return 0 on failure or src format code otherwise
+ */
+u32 csid_src_pad_code(struct csid_device *csid, u32 sink_code,
+                     unsigned int match_format_idx, u32 match_code);
+
 #endif /* QC_MSM_CAMSS_CSID_H */