+ DRM_DEBUG_KMS("HF-VSDB: max TMDS clock %d kHz\n",
+ display->max_tmds_clock);
+
+ if (hdmi->scdc_supported) {
+ hdmi->scr_info.supported = true;
+
+ /* Few sinks support scrambling for cloks < 340M */
+ if ((hf_vsdb[6] & 0x8))
+ hdmi->scr_info.low_clocks = true;
+ }
+ }
+}
+
+/**
+ * drm_check_scrambling_status - what is status of scrambling?
+ * @adapter: i2c adapter for SCDC channel
+ *
+ * Read the scrambler status over SCDC channel, and check the
+ * scrambling status.
+ *
+ * Return: True if the scrambling is enabled, false otherwise.
+ */
+
+bool drm_check_scrambling_status(struct i2c_adapter *adapter)
+{
+ u8 status;
+
+ if (drm_scdc_readb(adapter, SCDC_SCRAMBLER_STATUS, &status) < 0) {
+ DRM_ERROR("Failed to read scrambling status\n");
+ return false;
+ }
+
+ status &= SCDC_SCRAMBLING_STATUS;
+ return status != 0;
+}
+
+/**
+ * drm_enable_scrambling - enable scrambling
+ * @connector: target drm_connector
+ * @adapter: i2c adapter for SCDC channel
+ * @force: enable scrambling, even if its already enabled
+ *
+ * Write the TMDS config over SCDC channel, and enable scrambling
+ * Return: True if scrambling is successfully enabled, false otherwise.
+ */
+
+bool drm_enable_scrambling(struct drm_connector *connector,
+ struct i2c_adapter *adapter, bool force)
+{
+ u8 config;
+ struct drm_hdmi_info *hdmi_info = &connector->display_info.hdmi_info;
+
+ if (hdmi_info->scr_info.status && !force) {
+ DRM_DEBUG_KMS("Scrambling already enabled\n");
+ return true;
+ }
+
+ if (drm_scdc_readb(adapter, SCDC_TMDS_CONFIG, &config) < 0) {
+ DRM_ERROR("Failed to read tmds config\n");
+ return false;
+ }
+
+ config |= SCDC_SCRAMBLING_ENABLE;
+
+ if (drm_scdc_writeb(adapter, SCDC_TMDS_CONFIG, config) < 0) {
+ DRM_ERROR("Failed to enable scrambling, write error\n");
+ return false;
+ }
+
+ hdmi_info->scr_info.status = drm_check_scrambling_status(adapter);
+ return hdmi_info->scr_info.status;
+}
+
+/**
+ * drm_disable_scrambling - disable scrambling
+ * @connector: target drm_connector
+ * @adapter: i2c adapter for SCDC channel
+ * @force: disable scrambling, even if its already disabled
+ *
+ * Write the TMDS config over SCDC channel, and disable scrambling
+ * Return: True if scrambling is successfully disabled, false otherwise.
+ */
+bool drm_disable_scrambling(struct drm_connector *connector,
+ struct i2c_adapter *adapter, bool force)
+{
+ u8 config;
+ struct drm_hdmi_info *hdmi_info = &connector->display_info.hdmi_info;
+
+ if (!hdmi_info->scr_info.status && !force) {
+ DRM_DEBUG_KMS("Scrambling already disabled\n");
+ return true;
+ }
+
+ if (drm_scdc_readb(adapter, SCDC_TMDS_CONFIG, &config) < 0) {
+ DRM_ERROR("Failed to read tmds config\n");
+ return false;
+ }
+
+ config &= ~SCDC_SCRAMBLING_ENABLE;
+
+ if (drm_scdc_writeb(adapter, SCDC_TMDS_CONFIG, config) < 0) {
+ DRM_ERROR("Failed to enable scrambling, write error\n");
+ return false;
+ }
+
+ hdmi_info->scr_info.status = drm_check_scrambling_status(adapter);
+ return !hdmi_info->scr_info.status;
+}
+
static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,
const u8 *hdmi)
{
@@ -3928,8 +4055,10 @@ static void drm_parse_cea_ext(struct drm_connector *connector,
if (cea_db_is_hdmi_vsdb(db))
drm_parse_hdmi_vsdb_video(connector, db);
- if (cea_db_is_hdmi_forum_vsdb(db))
+ if (cea_db_is_hdmi_forum_vsdb(db)) {
drm_detect_hdmi_scdc(connector, db);
+ drm_detect_hdmi_scrambling(connector, db);
+ }
}
}
diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
index 2435598..b9735bd 100644
--- a/include/drm/drm_connector.h
+++ b/include/drm/drm_connector.h
@@ -90,6 +90,26 @@ enum subpixel_order {
};
+
+/**
+ * struct scrambling: sink's scrambling support.
+ */
+struct scrambling {
+ /**
+ * @supported: scrambling supported for rates > 340Mhz.
+ */
+ bool supported;
+ /**
+ * @low_clocks: scrambling supported for rates <= 340Mhz.
+ */
+ bool low_clocks;