Make write_hdmi_infoframe() and clear_infoframe() callbacks
return -EOPNOTSUPP for unsupported InfoFrames and make sure that
atomic_check() callback doesn't allow unsupported InfoFrames to be
enabled.

Signed-off-by: Dmitry Baryshkov <[email protected]>
---
 drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 49 +++++++++++++++++++++++++++++-----
 1 file changed, 43 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c 
b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c
index 
ab0938ba61f7d75dd0bec473807a04a20e1cffbd..219d826d535eb82328260c631e8b41f33a2f4c2f
 100644
--- a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c
+++ b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c
@@ -47,11 +47,8 @@ static int sun4i_hdmi_write_infoframe(struct drm_connector 
*connector,
        struct sun4i_hdmi *hdmi = drm_connector_to_sun4i_hdmi(connector);
        int i;
 
-       if (type != HDMI_INFOFRAME_TYPE_AVI) {
-               drm_err(connector->dev,
-                       "Unsupported infoframe type: %u\n", type);
-               return 0;
-       }
+       if (type != HDMI_INFOFRAME_TYPE_AVI)
+               return -EOPNOTSUPP;
 
        for (i = 0; i < len; i++)
                writeb(buffer[i], hdmi->base + SUN4I_HDMI_AVI_INFOFRAME_REG(i));
@@ -60,6 +57,45 @@ static int sun4i_hdmi_write_infoframe(struct drm_connector 
*connector,
 
 }
 
+static int sun4i_hdmi_clear_infoframe(struct drm_connector *connector,
+                                     enum hdmi_infoframe_type type)
+{
+       if (type != HDMI_INFOFRAME_TYPE_AVI)
+               return -EOPNOTSUPP;
+
+       return 0;
+}
+
+static int sun4i_hdmi_atomic_check(struct drm_connector *connector,
+                                  struct drm_atomic_state *state)
+{
+       struct drm_connector_state *conn_state =
+               drm_atomic_get_new_connector_state(state, connector);
+       int ret;
+
+       ret = drm_atomic_helper_connector_hdmi_check(connector, state);
+       if (ret)
+               return ret;
+
+       /* not supported by the driver */
+       conn_state->hdmi.infoframes.spd.set = false;
+
+       /* FIXME: not supported by the driver */
+       conn_state->hdmi.infoframes.hdmi.set = false;
+
+       /* should not happen, HDR support not enabled */
+       if (drm_WARN_ON_ONCE(connector->dev,
+                            connector->hdmi.infoframes.audio.set))
+               return -EOPNOTSUPP;
+
+       /* should not happen, audio support not enabled */
+       if (drm_WARN_ON_ONCE(connector->dev,
+                            conn_state->hdmi.infoframes.hdr_drm.set))
+               return -EOPNOTSUPP;
+
+       return 0;
+}
+
 static void sun4i_hdmi_disable(struct drm_encoder *encoder,
                               struct drm_atomic_state *state)
 {
@@ -237,10 +273,11 @@ static struct i2c_adapter *sun4i_hdmi_get_ddc(struct 
device *dev)
 static const struct drm_connector_hdmi_funcs sun4i_hdmi_hdmi_connector_funcs = 
{
        .tmds_char_rate_valid   = sun4i_hdmi_connector_clock_valid,
        .write_infoframe        = sun4i_hdmi_write_infoframe,
+       .clear_infoframe        = sun4i_hdmi_clear_infoframe,
 };
 
 static const struct drm_connector_helper_funcs 
sun4i_hdmi_connector_helper_funcs = {
-       .atomic_check   = drm_atomic_helper_connector_hdmi_check,
+       .atomic_check   = sun4i_hdmi_atomic_check,
        .mode_valid     = drm_hdmi_connector_mode_valid,
        .get_modes      = sun4i_hdmi_get_modes,
 };

-- 
2.47.3

Reply via email to