drm/msm/dp: move parity calculation to dp_utils
authorPaloma Arellano <quic_parellan@quicinc.com>
Thu, 22 Feb 2024 19:39:57 +0000 (11:39 -0800)
committerDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Mon, 4 Mar 2024 09:35:05 +0000 (11:35 +0200)
Parity calculation is necessary for VSC SDP implementation. Therefore
create new files dp_utils.c and dp_utils.h and move the parity
calculating functions here. This ensures that they are usable by SDP
programming in both dp_catalog.c and dp_audio.c

Changes in v3:
- Change ordering of the header byte macros

Changes in v2:
- Create new files dp_utils.c and dp_utils.h
- Move the parity calculation to these new files instead of
  having them in dp_catalog.c and dp_catalog.h

Signed-off-by: Paloma Arellano <quic_parellan@quicinc.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Patchwork: https://patchwork.freedesktop.org/patch/579617/
Link: https://lore.kernel.org/r/20240222194025.25329-13-quic_parellan@quicinc.com
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
drivers/gpu/drm/msm/Makefile
drivers/gpu/drm/msm/dp/dp_audio.c
drivers/gpu/drm/msm/dp/dp_utils.c [new file with mode: 0644]
drivers/gpu/drm/msm/dp/dp_utils.h [new file with mode: 0644]

index 543e04fa72e3b2e95b92db8c365ff8462731ff84..b21ae2880c7159fc1b6e39ff003f07db4496095e 100644 (file)
@@ -127,7 +127,8 @@ msm-$(CONFIG_DRM_MSM_DP)+= dp/dp_aux.o \
        dp/dp_drm.o \
        dp/dp_link.o \
        dp/dp_panel.o \
-       dp/dp_audio.o
+       dp/dp_audio.o \
+       dp/dp_utils.o
 
 msm-$(CONFIG_DRM_FBDEV_EMULATION) += msm_fbdev.o
 
index 4a2e479723a852f10ff226231192b791a42ac691..7634e4b742084171218ac06d20a2c3929211ff5b 100644 (file)
 #include "dp_audio.h"
 #include "dp_panel.h"
 #include "dp_display.h"
-
-#define HEADER_BYTE_2_BIT       0
-#define PARITY_BYTE_2_BIT       8
-#define HEADER_BYTE_1_BIT      16
-#define PARITY_BYTE_1_BIT      24
-#define HEADER_BYTE_3_BIT      16
-#define PARITY_BYTE_3_BIT      24
+#include "dp_utils.h"
 
 struct dp_audio_private {
        struct platform_device *audio_pdev;
@@ -36,71 +30,6 @@ struct dp_audio_private {
        struct dp_audio dp_audio;
 };
 
-static u8 dp_audio_get_g0_value(u8 data)
-{
-       u8 c[4];
-       u8 g[4];
-       u8 ret_data = 0;
-       u8 i;
-
-       for (i = 0; i < 4; i++)
-               c[i] = (data >> i) & 0x01;
-
-       g[0] = c[3];
-       g[1] = c[0] ^ c[3];
-       g[2] = c[1];
-       g[3] = c[2];
-
-       for (i = 0; i < 4; i++)
-               ret_data = ((g[i] & 0x01) << i) | ret_data;
-
-       return ret_data;
-}
-
-static u8 dp_audio_get_g1_value(u8 data)
-{
-       u8 c[4];
-       u8 g[4];
-       u8 ret_data = 0;
-       u8 i;
-
-       for (i = 0; i < 4; i++)
-               c[i] = (data >> i) & 0x01;
-
-       g[0] = c[0] ^ c[3];
-       g[1] = c[0] ^ c[1] ^ c[3];
-       g[2] = c[1] ^ c[2];
-       g[3] = c[2] ^ c[3];
-
-       for (i = 0; i < 4; i++)
-               ret_data = ((g[i] & 0x01) << i) | ret_data;
-
-       return ret_data;
-}
-
-static u8 dp_audio_calculate_parity(u32 data)
-{
-       u8 x0 = 0;
-       u8 x1 = 0;
-       u8 ci = 0;
-       u8 iData = 0;
-       u8 i = 0;
-       u8 parity_byte;
-       u8 num_byte = (data & 0xFF00) > 0 ? 8 : 2;
-
-       for (i = 0; i < num_byte; i++) {
-               iData = (data >> i*4) & 0xF;
-
-               ci = iData ^ x1;
-               x1 = x0 ^ dp_audio_get_g1_value(ci);
-               x0 = dp_audio_get_g0_value(ci);
-       }
-
-       parity_byte = x1 | (x0 << 4);
-
-       return parity_byte;
-}
-
 static u32 dp_audio_get_header(struct dp_catalog *catalog,
                enum dp_catalog_audio_sdp_type sdp,
                enum dp_catalog_audio_header_type header)
@@ -134,7 +63,7 @@ static void dp_audio_stream_sdp(struct dp_audio_private *audio)
                        DP_AUDIO_SDP_STREAM, DP_AUDIO_SDP_HEADER_1);
 
        new_value = 0x02;
-       parity_byte = dp_audio_calculate_parity(new_value);
+       parity_byte = dp_utils_calculate_parity(new_value);
        value |= ((new_value << HEADER_BYTE_1_BIT)
                        | (parity_byte << PARITY_BYTE_1_BIT));
        drm_dbg_dp(audio->drm_dev,
@@ -147,7 +76,7 @@ static void dp_audio_stream_sdp(struct dp_audio_private *audio)
        value = dp_audio_get_header(catalog,
                        DP_AUDIO_SDP_STREAM, DP_AUDIO_SDP_HEADER_2);
        new_value = value;
-       parity_byte = dp_audio_calculate_parity(new_value);
+       parity_byte = dp_utils_calculate_parity(new_value);
        value |= ((new_value << HEADER_BYTE_2_BIT)
                        | (parity_byte << PARITY_BYTE_2_BIT));
        drm_dbg_dp(audio->drm_dev,
@@ -162,7 +91,7 @@ static void dp_audio_stream_sdp(struct dp_audio_private *audio)
                        DP_AUDIO_SDP_STREAM, DP_AUDIO_SDP_HEADER_3);
 
        new_value = audio->channels - 1;
-       parity_byte = dp_audio_calculate_parity(new_value);
+       parity_byte = dp_utils_calculate_parity(new_value);
        value |= ((new_value << HEADER_BYTE_3_BIT)
                        | (parity_byte << PARITY_BYTE_3_BIT));
        drm_dbg_dp(audio->drm_dev,
@@ -184,7 +113,7 @@ static void dp_audio_timestamp_sdp(struct dp_audio_private *audio)
                        DP_AUDIO_SDP_TIMESTAMP, DP_AUDIO_SDP_HEADER_1);
 
        new_value = 0x1;
-       parity_byte = dp_audio_calculate_parity(new_value);
+       parity_byte = dp_utils_calculate_parity(new_value);
        value |= ((new_value << HEADER_BYTE_1_BIT)
                        | (parity_byte << PARITY_BYTE_1_BIT));
        drm_dbg_dp(audio->drm_dev,
@@ -198,7 +127,7 @@ static void dp_audio_timestamp_sdp(struct dp_audio_private *audio)
                        DP_AUDIO_SDP_TIMESTAMP, DP_AUDIO_SDP_HEADER_2);
 
        new_value = 0x17;
-       parity_byte = dp_audio_calculate_parity(new_value);
+       parity_byte = dp_utils_calculate_parity(new_value);
        value |= ((new_value << HEADER_BYTE_2_BIT)
                        | (parity_byte << PARITY_BYTE_2_BIT));
        drm_dbg_dp(audio->drm_dev,
@@ -212,7 +141,7 @@ static void dp_audio_timestamp_sdp(struct dp_audio_private *audio)
                        DP_AUDIO_SDP_TIMESTAMP, DP_AUDIO_SDP_HEADER_3);
 
        new_value = (0x0 | (0x11 << 2));
-       parity_byte = dp_audio_calculate_parity(new_value);
+       parity_byte = dp_utils_calculate_parity(new_value);
        value |= ((new_value << HEADER_BYTE_3_BIT)
                        | (parity_byte << PARITY_BYTE_3_BIT));
        drm_dbg_dp(audio->drm_dev,
@@ -233,7 +162,7 @@ static void dp_audio_infoframe_sdp(struct dp_audio_private *audio)
                        DP_AUDIO_SDP_INFOFRAME, DP_AUDIO_SDP_HEADER_1);
 
        new_value = 0x84;
-       parity_byte = dp_audio_calculate_parity(new_value);
+       parity_byte = dp_utils_calculate_parity(new_value);
        value |= ((new_value << HEADER_BYTE_1_BIT)
                        | (parity_byte << PARITY_BYTE_1_BIT));
        drm_dbg_dp(audio->drm_dev,
@@ -247,7 +176,7 @@ static void dp_audio_infoframe_sdp(struct dp_audio_private *audio)
                        DP_AUDIO_SDP_INFOFRAME, DP_AUDIO_SDP_HEADER_2);
 
        new_value = 0x1b;
-       parity_byte = dp_audio_calculate_parity(new_value);
+       parity_byte = dp_utils_calculate_parity(new_value);
        value |= ((new_value << HEADER_BYTE_2_BIT)
                        | (parity_byte << PARITY_BYTE_2_BIT));
        drm_dbg_dp(audio->drm_dev,
@@ -261,7 +190,7 @@ static void dp_audio_infoframe_sdp(struct dp_audio_private *audio)
                        DP_AUDIO_SDP_INFOFRAME, DP_AUDIO_SDP_HEADER_3);
 
        new_value = (0x0 | (0x11 << 2));
-       parity_byte = dp_audio_calculate_parity(new_value);
+       parity_byte = dp_utils_calculate_parity(new_value);
        value |= ((new_value << HEADER_BYTE_3_BIT)
                        | (parity_byte << PARITY_BYTE_3_BIT));
        drm_dbg_dp(audio->drm_dev,
@@ -282,7 +211,7 @@ static void dp_audio_copy_management_sdp(struct dp_audio_private *audio)
                        DP_AUDIO_SDP_COPYMANAGEMENT, DP_AUDIO_SDP_HEADER_1);
 
        new_value = 0x05;
-       parity_byte = dp_audio_calculate_parity(new_value);
+       parity_byte = dp_utils_calculate_parity(new_value);
        value |= ((new_value << HEADER_BYTE_1_BIT)
                        | (parity_byte << PARITY_BYTE_1_BIT));
        drm_dbg_dp(audio->drm_dev,
@@ -296,7 +225,7 @@ static void dp_audio_copy_management_sdp(struct dp_audio_private *audio)
                        DP_AUDIO_SDP_COPYMANAGEMENT, DP_AUDIO_SDP_HEADER_2);
 
        new_value = 0x0F;
-       parity_byte = dp_audio_calculate_parity(new_value);
+       parity_byte = dp_utils_calculate_parity(new_value);
        value |= ((new_value << HEADER_BYTE_2_BIT)
                        | (parity_byte << PARITY_BYTE_2_BIT));
        drm_dbg_dp(audio->drm_dev,
@@ -310,7 +239,7 @@ static void dp_audio_copy_management_sdp(struct dp_audio_private *audio)
                        DP_AUDIO_SDP_COPYMANAGEMENT, DP_AUDIO_SDP_HEADER_3);
 
        new_value = 0x0;
-       parity_byte = dp_audio_calculate_parity(new_value);
+       parity_byte = dp_utils_calculate_parity(new_value);
        value |= ((new_value << HEADER_BYTE_3_BIT)
                        | (parity_byte << PARITY_BYTE_3_BIT));
        drm_dbg_dp(audio->drm_dev,
@@ -331,7 +260,7 @@ static void dp_audio_isrc_sdp(struct dp_audio_private *audio)
                        DP_AUDIO_SDP_ISRC, DP_AUDIO_SDP_HEADER_1);
 
        new_value = 0x06;
-       parity_byte = dp_audio_calculate_parity(new_value);
+       parity_byte = dp_utils_calculate_parity(new_value);
        value |= ((new_value << HEADER_BYTE_1_BIT)
                        | (parity_byte << PARITY_BYTE_1_BIT));
        drm_dbg_dp(audio->drm_dev,
@@ -345,7 +274,7 @@ static void dp_audio_isrc_sdp(struct dp_audio_private *audio)
                        DP_AUDIO_SDP_ISRC, DP_AUDIO_SDP_HEADER_2);
 
        new_value = 0x0F;
-       parity_byte = dp_audio_calculate_parity(new_value);
+       parity_byte = dp_utils_calculate_parity(new_value);
        value |= ((new_value << HEADER_BYTE_2_BIT)
                        | (parity_byte << PARITY_BYTE_2_BIT));
        drm_dbg_dp(audio->drm_dev,
diff --git a/drivers/gpu/drm/msm/dp/dp_utils.c b/drivers/gpu/drm/msm/dp/dp_utils.c
new file mode 100644 (file)
index 0000000..3a44fe7
--- /dev/null
@@ -0,0 +1,73 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2024, The Linux Foundation. All rights reserved.
+ */
+
+#include <linux/types.h>
+
+#include "dp_utils.h"
+
+u8 dp_utils_get_g0_value(u8 data)
+{
+       u8 c[4];
+       u8 g[4];
+       u8 ret_data = 0;
+       u8 i;
+
+       for (i = 0; i < 4; i++)
+               c[i] = (data >> i) & 0x01;
+
+       g[0] = c[3];
+       g[1] = c[0] ^ c[3];
+       g[2] = c[1];
+       g[3] = c[2];
+
+       for (i = 0; i < 4; i++)
+               ret_data = ((g[i] & 0x01) << i) | ret_data;
+
+       return ret_data;
+}
+
+u8 dp_utils_get_g1_value(u8 data)
+{
+       u8 c[4];
+       u8 g[4];
+       u8 ret_data = 0;
+       u8 i;
+
+       for (i = 0; i < 4; i++)
+               c[i] = (data >> i) & 0x01;
+
+       g[0] = c[0] ^ c[3];
+       g[1] = c[0] ^ c[1] ^ c[3];
+       g[2] = c[1] ^ c[2];
+       g[3] = c[2] ^ c[3];
+
+       for (i = 0; i < 4; i++)
+               ret_data = ((g[i] & 0x01) << i) | ret_data;
+
+       return ret_data;
+}
+
+u8 dp_utils_calculate_parity(u32 data)
+{
+       u8 x0 = 0;
+       u8 x1 = 0;
+       u8 ci = 0;
+       u8 iData = 0;
+       u8 i = 0;
+       u8 parity_byte;
+       u8 num_byte = (data & 0xFF00) > 0 ? 8 : 2;
+
+       for (i = 0; i < num_byte; i++) {
+               iData = (data >> i * 4) & 0xF;
+
+               ci = iData ^ x1;
+               x1 = x0 ^ dp_utils_get_g1_value(ci);
+               x0 = dp_utils_get_g0_value(ci);
+       }
+
+       parity_byte = x1 | (x0 << 4);
+
+       return parity_byte;
+}
diff --git a/drivers/gpu/drm/msm/dp/dp_utils.h b/drivers/gpu/drm/msm/dp/dp_utils.h
new file mode 100644 (file)
index 0000000..5a505cb
--- /dev/null
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2024, The Linux Foundation. All rights reserved.
+ */
+
+#ifndef _DP_UTILS_H_
+#define _DP_UTILS_H_
+
+#define HEADER_BYTE_0_BIT       0
+#define PARITY_BYTE_0_BIT       8
+#define HEADER_BYTE_1_BIT      16
+#define PARITY_BYTE_1_BIT      24
+#define HEADER_BYTE_2_BIT       0
+#define PARITY_BYTE_2_BIT       8
+#define HEADER_BYTE_3_BIT      16
+#define PARITY_BYTE_3_BIT      24
+
+u8 dp_utils_get_g0_value(u8 data);
+u8 dp_utils_get_g1_value(u8 data);
+u8 dp_utils_calculate_parity(u32 data);
+
+#endif /* _DP_UTILS_H_ */