Skip to content

Commit 2ea023a

Browse files
UPSTREAM: drm/edid: detect SCDC support in HF-VSDB
This patch does following: - Adds a new structure (drm_hdmi_info) in drm_display_info. This structure will be used to save and indicate if sink supports advanced HDMI 2.0 features - Adds another structure drm_scdc within drm_hdmi_info, to reflect scdc support and capabilities in connected HDMI 2.0 sink. - Checks the HF-VSDB block for presence of SCDC, and marks it in scdc structure - If SCDC is present, checks if sink is capable of generating SCDC read request, and marks it in scdc structure. V2: Addressed review comments Thierry: - Fix typos in commit message and make abbreviation consistent across the commit message. - Change structure object name from hdmi_info -> hdmi - Fix typos and abbreviations in description of structure drm_hdmi_info end the description with a full stop. - Create a structure drm_scdc, and keep all information related to SCDC register set (supported, read request supported) etc in it. Ville: - Change rr -> read_request - Call drm_detect_scrambling function drm_parse_hf_vsdb so that all of HF-VSDB parsing can be kept in same function, in incremental patches. V3: Rebase. V4: Rebase. V5: Rebase. V6: Addressed review comments from Ville - Add clock rate calculations for 1/10 and 1/40 ratios - Remove leftovers from old patchset V7: Added R-B from Jose. V8: Rebase. V9: Rebase. V10: Rebase. Change-Id: I14d2a5585a528b7195170a4202be87199eb858c6 Signed-off-by: Shashank Sharma <shashank.sharma@intel.com> Reviewed-by: Thierry Reding <treding@nvidia.com> Reviewed-by: Jose Abreu <joabreu@synopsys.com> Signed-off-by: Jani Nikula <jani.nikula@intel.com> Link: http://patchwork.freedesktop.org/patch/msgid/1489404244-16608-5-git-send-email-shashank.sharma@intel.com Signed-off-by: Zheng Yang <zhengyang@rock-chips.com> (cherry picked from 62c58af)
1 parent 96aa175 commit 2ea023a

4 files changed

Lines changed: 199 additions & 1 deletion

File tree

drivers/gpu/drm/drm_edid.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <drm/drmP.h>
3636
#include <drm/drm_edid.h>
3737
#include <drm/drm_displayid.h>
38+
#include <drm/drm_scdc_helper.h>
3839

3940
#define version_greater(edid, maj, min) \
4041
(((edid)->version > (maj)) || \
@@ -4087,13 +4088,43 @@ EXPORT_SYMBOL(drm_rgb_quant_range_selectable);
40874088
static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
40884089
const u8 *hf_vsdb)
40894090
{
4090-
struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
4091+
struct drm_display_info *display = &connector->display_info;
4092+
struct drm_hdmi_info *hdmi = &display->hdmi;
40914093

40924094
if (hf_vsdb[6] & 0x80) {
40934095
hdmi->scdc.supported = true;
40944096
if (hf_vsdb[6] & 0x40)
40954097
hdmi->scdc.read_request = true;
40964098
}
4099+
4100+
/*
4101+
* All HDMI 2.0 monitors must support scrambling at rates > 340 MHz.
4102+
* And as per the spec, three factors confirm this:
4103+
* * Availability of a HF-VSDB block in EDID (check)
4104+
* * Non zero Max_TMDS_Char_Rate filed in HF-VSDB (let's check)
4105+
* * SCDC support available (let's check)
4106+
* Lets check it out.
4107+
*/
4108+
4109+
if (hf_vsdb[5]) {
4110+
/* max clock is 5000 KHz times block value */
4111+
u32 max_tmds_clock = hf_vsdb[5] * 5000;
4112+
struct drm_scdc *scdc = &hdmi->scdc;
4113+
4114+
if (max_tmds_clock > 340000) {
4115+
display->max_tmds_clock = max_tmds_clock;
4116+
DRM_DEBUG_KMS("HF-VSDB: max TMDS clock %d kHz\n",
4117+
display->max_tmds_clock);
4118+
}
4119+
4120+
if (scdc->supported) {
4121+
scdc->scrambling.supported = true;
4122+
4123+
/* Few sinks support scrambling for cloks < 340M */
4124+
if ((hf_vsdb[6] & 0x8))
4125+
scdc->scrambling.low_rates = true;
4126+
}
4127+
}
40974128
}
40984129

40994130
static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,

drivers/gpu/drm/drm_scdc_helper.c

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
*/
2323

2424
#include <linux/slab.h>
25+
#include <linux/delay.h>
2526

2627
#include <drm/drm_scdc_helper.h>
28+
#include <drm/drmP.h>
2729

2830
/**
2931
* DOC: scdc helpers
@@ -109,3 +111,122 @@ ssize_t drm_scdc_write(struct i2c_adapter *adapter, u8 offset,
109111
return err;
110112
}
111113
EXPORT_SYMBOL(drm_scdc_write);
114+
115+
/**
116+
* drm_scdc_check_scrambling_status - what is status of scrambling?
117+
* @adapter: I2C adapter for DDC channel
118+
*
119+
* Reads the scrambler status over SCDC, and checks the
120+
* scrambling status.
121+
*
122+
* Returns:
123+
* True if the scrambling is enabled, false otherwise.
124+
*/
125+
126+
bool drm_scdc_get_scrambling_status(struct i2c_adapter *adapter)
127+
{
128+
u8 status;
129+
int ret;
130+
131+
ret = drm_scdc_readb(adapter, SCDC_SCRAMBLER_STATUS, &status);
132+
if (ret < 0) {
133+
DRM_ERROR("Failed to read scrambling status, error %d\n", ret);
134+
return false;
135+
}
136+
137+
return status & SCDC_SCRAMBLING_STATUS;
138+
}
139+
EXPORT_SYMBOL(drm_scdc_get_scrambling_status);
140+
141+
/**
142+
* drm_scdc_set_scrambling - enable scrambling
143+
* @adapter: I2C adapter for DDC channel
144+
* @enable: bool to indicate if scrambling is to be enabled/disabled
145+
*
146+
* Writes the TMDS config register over SCDC channel, and:
147+
* enables scrambling when enable = 1
148+
* disables scrambling when enable = 0
149+
*
150+
* Returns:
151+
* True if scrambling is set/reset successfully, false otherwise.
152+
*/
153+
154+
bool drm_scdc_set_scrambling(struct i2c_adapter *adapter, bool enable)
155+
{
156+
u8 config;
157+
int ret;
158+
159+
ret = drm_scdc_readb(adapter, SCDC_TMDS_CONFIG, &config);
160+
if (ret < 0) {
161+
DRM_ERROR("Failed to read tmds config, err=%d\n", ret);
162+
return false;
163+
}
164+
165+
if (enable)
166+
config |= SCDC_SCRAMBLING_ENABLE;
167+
else
168+
config &= ~SCDC_SCRAMBLING_ENABLE;
169+
170+
ret = drm_scdc_writeb(adapter, SCDC_TMDS_CONFIG, config);
171+
if (ret < 0) {
172+
DRM_ERROR("Failed to enable scrambling, error %d\n", ret);
173+
return false;
174+
}
175+
176+
return true;
177+
}
178+
EXPORT_SYMBOL(drm_scdc_set_scrambling);
179+
180+
/**
181+
* drm_scdc_set_high_tmds_clock_ratio - set TMDS clock ratio
182+
* @adapter: I2C adapter for DDC channel
183+
* @set: ret or reset the high clock ratio
184+
*
185+
* TMDS clock ratio calculations go like this:
186+
* TMDS character = 10 bit TMDS encoded value
187+
* TMDS character rate = The rate at which TMDS characters are transmitted(Mcsc)
188+
* TMDS bit rate = 10x TMDS character rate
189+
* As per the spec:
190+
* TMDS clock rate for pixel clock < 340 MHz = 1x the character rate
191+
* = 1/10 pixel clock rate
192+
* TMDS clock rate for pixel clock > 340 MHz = 0.25x the character rate
193+
* = 1/40 pixel clock rate
194+
*
195+
* Writes to the TMDS config register over SCDC channel, and:
196+
* sets TMDS clock ratio to 1/40 when set = 1
197+
* sets TMDS clock ratio to 1/10 when set = 0
198+
*
199+
* Returns:
200+
* True if write is successful, false otherwise.
201+
*/
202+
bool drm_scdc_set_high_tmds_clock_ratio(struct i2c_adapter *adapter, bool set)
203+
{
204+
u8 config;
205+
int ret;
206+
207+
ret = drm_scdc_readb(adapter, SCDC_TMDS_CONFIG, &config);
208+
if (ret < 0) {
209+
DRM_ERROR("Failed to read tmds config, err=%d\n", ret);
210+
return false;
211+
}
212+
213+
if (set)
214+
config |= SCDC_TMDS_BIT_CLOCK_RATIO_BY_40;
215+
else
216+
config &= ~SCDC_TMDS_BIT_CLOCK_RATIO_BY_40;
217+
218+
ret = drm_scdc_writeb(adapter, SCDC_TMDS_CONFIG, config);
219+
if (ret < 0) {
220+
DRM_ERROR("Failed to set TMDS clock ratio, error %d\n", ret);
221+
return false;
222+
}
223+
224+
/*
225+
* The spec says that a source should wait minimum 1ms and maximum
226+
* 100ms after writing the TMDS config for clock ratio. Lets allow a
227+
* wait of upto 2ms here.
228+
*/
229+
usleep_range(1000, 2000);
230+
return true;
231+
}
232+
EXPORT_SYMBOL(drm_scdc_set_high_tmds_clock_ratio);

include/drm/drm_crtc.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,20 @@ enum subpixel_order {
120120

121121
};
122122

123+
/**
124+
* struct drm_scrambling: sink's scrambling support.
125+
*/
126+
struct drm_scrambling {
127+
/**
128+
* @supported: scrambling supported for rates > 340 Mhz.
129+
*/
130+
bool supported;
131+
/**
132+
* @low_rates: scrambling supported for rates <= 340 Mhz.
133+
*/
134+
bool low_rates;
135+
};
136+
123137
/*
124138
* struct drm_scdc - Information about scdc capabilities of a HDMI 2.0 sink
125139
*
@@ -135,8 +149,13 @@ struct drm_scdc {
135149
* @read_request: sink is capable of generating scdc read request.
136150
*/
137151
bool read_request;
152+
/**
153+
* @scrambling: sink's scrambling capabilities
154+
*/
155+
struct drm_scrambling scrambling;
138156
};
139157

158+
140159
/**
141160
* struct drm_hdmi_info - runtime information about the connected HDMI sink
142161
*

include/drm/drm_scdc_helper.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,31 @@ static inline int drm_scdc_writeb(struct i2c_adapter *adapter, u8 offset,
121121
return drm_scdc_write(adapter, offset, &value, sizeof(value));
122122
}
123123

124+
/**
125+
* drm_scdc_set_scrambling - enable scrambling
126+
* @adapter: I2C adapter for DDC channel
127+
* @enable: bool to indicate if scrambling is to be enabled/disabled
128+
*
129+
* Writes the TMDS config register over SCDC channel, and:
130+
* enables scrambling when enable = 1
131+
* disables scrambling when enable = 0
132+
*
133+
* Returns:
134+
* True if scrambling is set/reset successfully, false otherwise.
135+
*/
136+
bool drm_scdc_set_scrambling(struct i2c_adapter *adapter, bool enable);
137+
138+
/**
139+
* drm_scdc_set_high_tmds_clock_ratio - set TMDS clock ratio
140+
* @adapter: I2C adapter for DDC channel
141+
* @set: ret or reset the high clock ratio
142+
*
143+
* Writes to the TMDS config register over SCDC channel, and:
144+
* sets TMDS clock ratio to 1/40 when set = 1
145+
* sets TMDS clock ratio to 1/10 when set = 0
146+
*
147+
* Returns:
148+
* True if write is successful, false otherwise.
149+
*/
150+
bool drm_scdc_set_high_tmds_clock_ratio(struct i2c_adapter *adapter, bool set);
124151
#endif

0 commit comments

Comments
 (0)