Merge tag 'drm-misc-next-2020-06-19' of git://anongit.freedesktop.org/drm/drm-misc...
[sfrench/cifs-2.6.git] / drivers / video / hdmi.c
index f693076f2e5fc04804175d30e44da85f67c50dce..b7a1d6fae90d8e864db6be336b2606b5d0e7a946 100644 (file)
@@ -1768,20 +1768,21 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
 }
 
 /**
- * hdmi_drm_infoframe_unpack() - unpack binary buffer to a HDMI DRM infoframe
+ * hdmi_drm_infoframe_unpack_only() - unpack binary buffer of CTA-861-G DRM
+ *                                    infoframe DataBytes to a HDMI DRM
+ *                                    infoframe
  * @frame: HDMI DRM infoframe
  * @buffer: source buffer
  * @size: size of buffer
  *
- * Unpacks the information contained in binary @buffer into a structured
- * @frame of the HDMI Dynamic Range and Mastering (DRM) information frame.
- * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
- * specification.
+ * Unpacks CTA-861-G DRM infoframe DataBytes contained in the binary @buffer
+ * into a structured @frame of the HDMI Dynamic Range and Mastering (DRM)
+ * infoframe.
  *
  * Returns 0 on success or a negative error code on failure.
  */
-static int hdmi_drm_infoframe_unpack(struct hdmi_drm_infoframe *frame,
-                                    const void *buffer, size_t size)
+int hdmi_drm_infoframe_unpack_only(struct hdmi_drm_infoframe *frame,
+                                  const void *buffer, size_t size)
 {
        const u8 *ptr = buffer;
        const u8 *temp;
@@ -1790,23 +1791,13 @@ static int hdmi_drm_infoframe_unpack(struct hdmi_drm_infoframe *frame,
        int ret;
        int i;
 
-       if (size < HDMI_INFOFRAME_SIZE(DRM))
-               return -EINVAL;
-
-       if (ptr[0] != HDMI_INFOFRAME_TYPE_DRM ||
-           ptr[1] != 1 ||
-           ptr[2] != HDMI_DRM_INFOFRAME_SIZE)
-               return -EINVAL;
-
-       if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(DRM)) != 0)
+       if (size < HDMI_DRM_INFOFRAME_SIZE)
                return -EINVAL;
 
        ret = hdmi_drm_infoframe_init(frame);
        if (ret)
                return ret;
 
-       ptr += HDMI_INFOFRAME_HEADER_SIZE;
-
        frame->eotf = ptr[0] & 0x7;
        frame->metadata_type = ptr[1] & 0x7;
 
@@ -1814,7 +1805,7 @@ static int hdmi_drm_infoframe_unpack(struct hdmi_drm_infoframe *frame,
        for (i = 0; i < 3; i++) {
                x_lsb = *temp++;
                x_msb = *temp++;
-               frame->display_primaries[i].x =  (x_msb << 8) | x_lsb;
+               frame->display_primaries[i].x = (x_msb << 8) | x_lsb;
                y_lsb = *temp++;
                y_msb = *temp++;
                frame->display_primaries[i].y = (y_msb << 8) | y_lsb;
@@ -1830,6 +1821,42 @@ static int hdmi_drm_infoframe_unpack(struct hdmi_drm_infoframe *frame,
 
        return 0;
 }
+EXPORT_SYMBOL(hdmi_drm_infoframe_unpack_only);
+
+/**
+ * hdmi_drm_infoframe_unpack() - unpack binary buffer to a HDMI DRM infoframe
+ * @frame: HDMI DRM infoframe
+ * @buffer: source buffer
+ * @size: size of buffer
+ *
+ * Unpacks the CTA-861-G DRM infoframe contained in the binary @buffer into
+ * a structured @frame of the HDMI Dynamic Range and Mastering (DRM)
+ * infoframe. It also verifies the checksum as required by section 5.3.5 of
+ * the HDMI 1.4 specification.
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+static int hdmi_drm_infoframe_unpack(struct hdmi_drm_infoframe *frame,
+                                    const void *buffer, size_t size)
+{
+       const u8 *ptr = buffer;
+       int ret;
+
+       if (size < HDMI_INFOFRAME_SIZE(DRM))
+               return -EINVAL;
+
+       if (ptr[0] != HDMI_INFOFRAME_TYPE_DRM ||
+           ptr[1] != 1 ||
+           ptr[2] != HDMI_DRM_INFOFRAME_SIZE)
+               return -EINVAL;
+
+       if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(DRM)) != 0)
+               return -EINVAL;
+
+       ret = hdmi_drm_infoframe_unpack_only(frame, ptr + HDMI_INFOFRAME_HEADER_SIZE,
+                                            size - HDMI_INFOFRAME_HEADER_SIZE);
+       return ret;
+}
 
 /**
  * hdmi_infoframe_unpack() - unpack binary buffer to a HDMI infoframe