Commit 7befe621 authored by Ville Syrjälä's avatar Ville Syrjälä
Browse files

drm/edid: Abstract away cea_edid_modes[]



We're going to need two cea mode tables (one for VICs < 128,
another one for VICs >= 193). To that end replace the direct
edid_cea_modes[] lookups with a function call. And we'll rename
the array to edid_cea_modes_0[] to indicate how it's to be
indexed.

v2: Fix typos (Tom)
    Drop the pointless NULL checks in the loops (Tom)
    Assign when declaring (Tom)
    Improve the comment for cea_modes_*[] to indicate
    that one should always use cea_mode_for_vic() (Tom)

Cc: Tom Anderson <thomasanderson@google.com>
Cc: Hans Verkuil <hansverk@cisco.com>
Cc: Manasi Navare <manasi.d.navare@intel.com>
Signed-off-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191213174348.27261-2-ville.syrjala@linux.intel.com


Reviewed-by: default avatarThomas Anderson <thomasanderson@google.com>
parent c0967617
Loading
Loading
Loading
Loading
+45 −22
Original line number Diff line number Diff line
@@ -710,12 +710,11 @@ static const struct minimode extra_modes[] = {
};

/*
 * Probably taken from CEA-861 spec.
 * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
 * From CEA/CTA-861 spec.
 *
 * Index using the VIC.
 * Do not access directly, instead always use cea_mode_for_vic().
 */
static const struct drm_display_mode edid_cea_modes[] = {
static const struct drm_display_mode edid_cea_modes_0[] = {
	/* 0 - dummy, VICs start at 1 */
	{ },
	/* 1 - 640x480@60Hz 4:3 */
@@ -3071,6 +3070,25 @@ static u8 *drm_find_cea_extension(const struct edid *edid)
	return cea;
}

static const struct drm_display_mode *cea_mode_for_vic(u8 vic)
{
	if (!vic)
		return NULL;
	if (vic < ARRAY_SIZE(edid_cea_modes_0))
		return &edid_cea_modes_0[vic];
	return NULL;
}

static u8 cea_num_vics(void)
{
	return ARRAY_SIZE(edid_cea_modes_0);
}

static u8 cea_next_vic(u8 vic)
{
	return vic + 1;
}

/*
 * Calculate the alternate clock for the CEA mode
 * (60Hz vs. 59.94Hz etc.)
@@ -3108,14 +3126,14 @@ cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
	 * get the other variants by simply increasing the
	 * vertical front porch length.
	 */
	BUILD_BUG_ON(edid_cea_modes[8].vtotal != 262 ||
		     edid_cea_modes[9].vtotal != 262 ||
		     edid_cea_modes[12].vtotal != 262 ||
		     edid_cea_modes[13].vtotal != 262 ||
		     edid_cea_modes[23].vtotal != 312 ||
		     edid_cea_modes[24].vtotal != 312 ||
		     edid_cea_modes[27].vtotal != 312 ||
		     edid_cea_modes[28].vtotal != 312);
	BUILD_BUG_ON(cea_mode_for_vic(8)->vtotal != 262 ||
		     cea_mode_for_vic(9)->vtotal != 262 ||
		     cea_mode_for_vic(12)->vtotal != 262 ||
		     cea_mode_for_vic(13)->vtotal != 262 ||
		     cea_mode_for_vic(23)->vtotal != 312 ||
		     cea_mode_for_vic(24)->vtotal != 312 ||
		     cea_mode_for_vic(27)->vtotal != 312 ||
		     cea_mode_for_vic(28)->vtotal != 312);

	if (((vic == 8 || vic == 9 ||
	      vic == 12 || vic == 13) && mode->vtotal < 263) ||
@@ -3143,8 +3161,8 @@ static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m
	if (to_match->picture_aspect_ratio)
		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;

	for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
		struct drm_display_mode cea_mode = edid_cea_modes[vic];
	for (vic = 1; vic < cea_num_vics(); vic = cea_next_vic(vic)) {
		struct drm_display_mode cea_mode = *cea_mode_for_vic(vic);
		unsigned int clock1, clock2;

		/* Check both 60Hz and 59.94Hz */
@@ -3182,8 +3200,8 @@ u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
	if (to_match->picture_aspect_ratio)
		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;

	for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
		struct drm_display_mode cea_mode = edid_cea_modes[vic];
	for (vic = 1; vic < cea_num_vics(); vic = cea_next_vic(vic)) {
		struct drm_display_mode cea_mode = *cea_mode_for_vic(vic);
		unsigned int clock1, clock2;

		/* Check both 60Hz and 59.94Hz */
@@ -3206,12 +3224,17 @@ EXPORT_SYMBOL(drm_match_cea_mode);

static bool drm_valid_cea_vic(u8 vic)
{
	return vic > 0 && vic < ARRAY_SIZE(edid_cea_modes);
	return cea_mode_for_vic(vic) != NULL;
}

static enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
{
	return edid_cea_modes[video_code].picture_aspect_ratio;
	const struct drm_display_mode *mode = cea_mode_for_vic(video_code);

	if (mode)
		return mode->picture_aspect_ratio;

	return HDMI_PICTURE_ASPECT_NONE;
}

static enum hdmi_picture_aspect drm_get_hdmi_aspect_ratio(const u8 video_code)
@@ -3323,7 +3346,7 @@ add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
		unsigned int clock1, clock2;

		if (drm_valid_cea_vic(vic)) {
			cea_mode = &edid_cea_modes[vic];
			cea_mode = cea_mode_for_vic(vic);
			clock2 = cea_mode_alternate_clock(cea_mode);
		} else {
			vic = drm_match_hdmi_mode(mode);
@@ -3398,7 +3421,7 @@ drm_display_mode_from_vic_index(struct drm_connector *connector,
	if (!drm_valid_cea_vic(vic))
		return NULL;

	newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
	newmode = drm_mode_duplicate(dev, cea_mode_for_vic(vic));
	if (!newmode)
		return NULL;

@@ -3432,7 +3455,7 @@ static int do_y420vdb_modes(struct drm_connector *connector,
		if (!drm_valid_cea_vic(vic))
			continue;

		newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
		newmode = drm_mode_duplicate(dev, cea_mode_for_vic(vic));
		if (!newmode)
			break;
		bitmap_set(hdmi->y420_vdb_modes, vic, 1);
@@ -4001,7 +4024,7 @@ static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
	vic = drm_match_cea_mode_clock_tolerance(mode, 5);
	if (drm_valid_cea_vic(vic)) {
		type = "CEA";
		cea_mode = &edid_cea_modes[vic];
		cea_mode = cea_mode_for_vic(vic);
		clock1 = cea_mode->clock;
		clock2 = cea_mode_alternate_clock(cea_mode);
	} else {